|
@@ -10,6 +10,8 @@ import com.jpsoft.smart.modules.common.utils.OSSUtil;
|
|
|
import com.jpsoft.smart.modules.common.utils.POIUtils;
|
|
|
import com.jpsoft.smart.modules.common.utils.WechatMessageUtil;
|
|
|
import com.sun.corba.se.spi.orbutil.threadpool.Work;
|
|
|
+import io.jsonwebtoken.Jwts;
|
|
|
+import io.jsonwebtoken.security.Keys;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
@@ -20,6 +22,7 @@ import org.apache.poi.ss.usermodel.WorkbookFactory;
|
|
|
import org.joda.time.DateTime;
|
|
|
import org.joda.time.Days;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.core.io.ClassPathResource;
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
@@ -27,8 +30,11 @@ import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.security.Key;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
+import java.util.Base64;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.UUID;
|
|
@@ -36,6 +42,9 @@ import java.util.UUID;
|
|
|
@Component
|
|
|
@Slf4j
|
|
|
public class UnmeasureTemperatureAlarmTask {
|
|
|
+ @Value("${jwt.secret}")
|
|
|
+ private String jwtSecret;
|
|
|
+
|
|
|
@Autowired
|
|
|
private AlarmConfigService alarmConfigService;
|
|
|
|
|
@@ -57,12 +66,18 @@ public class UnmeasureTemperatureAlarmTask {
|
|
|
@Autowired
|
|
|
private PersonDeviceLogService personDeviceLogService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private PersonInfoService personInfoService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private WxConfig wxConfig;
|
|
|
|
|
|
@Autowired
|
|
|
private OSSConfig ossConfig;
|
|
|
|
|
|
+ @Value("${mobile.unMeasureUrl}")
|
|
|
+ private String unMeasureUrl;
|
|
|
+
|
|
|
public int batchUpdate(String companyId,Date startDate,Date endDate) throws Exception {
|
|
|
DateTime dt1 = new DateTime(startDate);
|
|
|
DateTime dt2 = new DateTime(endDate);
|
|
@@ -333,6 +348,24 @@ public class UnmeasureTemperatureAlarmTask {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private String createToken(Long personId) {
|
|
|
+ //token有效时间2小时
|
|
|
+ byte[] privateKey = Base64.getDecoder().decode(jwtSecret);
|
|
|
+
|
|
|
+ Date now = new Date();
|
|
|
+ long expiration = now.getTime() + 3600 * 6000; //6个小时后,该客户端的token过期
|
|
|
+
|
|
|
+ Key key = Keys.hmacShaKeyFor(privateKey);
|
|
|
+
|
|
|
+ String token = Jwts.builder()
|
|
|
+ .setSubject(personId + "")
|
|
|
+ .signWith(key)
|
|
|
+ .setExpiration(new Date(expiration))
|
|
|
+ .compact();
|
|
|
+
|
|
|
+ return "Bearer " + token;
|
|
|
+ }
|
|
|
+
|
|
|
@Async
|
|
|
public void noticeManager(AlarmConfig alarmConfig, DateTime startTime, DateTime endTime) {
|
|
|
CompanyInfo companyInfo = companyInfoService.get(alarmConfig.getCompanyId());
|
|
@@ -350,19 +383,7 @@ public class UnmeasureTemperatureAlarmTask {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- StringBuilder sb = new StringBuilder();
|
|
|
- int total = 0;
|
|
|
-
|
|
|
- //todo 汇总未测温人
|
|
|
- for (PersonInfo personInfo : unmeasuredList) {
|
|
|
- if (sb.length() != 0) {
|
|
|
- sb.append(",");
|
|
|
- }
|
|
|
-
|
|
|
- sb.append(personInfo.getName());
|
|
|
-
|
|
|
- total++;
|
|
|
- }
|
|
|
+ int total = unmeasuredList.size();
|
|
|
|
|
|
//todo 查询该单位的通知人
|
|
|
List<WarningPusher> pusherList = warningPusherService.findByCompanyId(companyInfo.getId());
|
|
@@ -373,25 +394,32 @@ public class UnmeasureTemperatureAlarmTask {
|
|
|
&& pusher.getMissingNoticeEnabled()!=null && pusher.getMissingNoticeEnabled()) {
|
|
|
String message = "尊敬的" + pusher.getName()
|
|
|
+ ",当天时段" + startTime.toString("HH:mm") + "至" + endTime.toString("HH:mm")
|
|
|
- + ",有" + total + "人未测量体温,具体名单请点击下方【查看详情】下载人员名单";
|
|
|
+ + ",有" + total + "人未测量体温,具体名单请点击下方【查看详情】查看";
|
|
|
|
|
|
//todo 生成未测量人员名单
|
|
|
+ PersonInfo personInfo = personInfoService.findByOpenId(pusher.getOpenId());
|
|
|
+ long personId = 0;
|
|
|
|
|
|
- String url = "";
|
|
|
+ if (personInfo!=null){
|
|
|
+ personId = personInfo.getId();
|
|
|
+ }
|
|
|
|
|
|
try {
|
|
|
- url = createUnMeasureReport(companyInfo, unmeasuredList, startTime, endTime);
|
|
|
+ String url = unMeasureUrl + "?token=" + URLEncoder.encode(createToken(personId), "UTF-8");
|
|
|
+ url += "&companyId=" + alarmConfig.getCompanyId();
|
|
|
+ url += "&queryDate=" + startTime.toString("yyyy-MM-dd");
|
|
|
+ url += "&alarmConfigId=" + alarmConfig.getId();
|
|
|
+
|
|
|
+ WechatMessageUtil.sendUnmeasureAlarmInfo(
|
|
|
+ pusher.getOpenId(),
|
|
|
+ companyInfo.getName(),
|
|
|
+ message,
|
|
|
+ url,
|
|
|
+ wxConfig.getAppId(), wxConfig.getAppSecret());
|
|
|
}
|
|
|
- catch (Exception ex){
|
|
|
+ catch(Exception ex){
|
|
|
log.error(ex.getMessage(),ex);
|
|
|
}
|
|
|
-
|
|
|
- WechatMessageUtil.sendUnmeasureAlarmInfo(
|
|
|
- pusher.getOpenId(),
|
|
|
- companyInfo.getName(),
|
|
|
- String.format(message,url),
|
|
|
- url,
|
|
|
- wxConfig.getAppId(), wxConfig.getAppSecret());
|
|
|
}
|
|
|
}
|
|
|
}
|