Kaynağa Gözat

1.微信通知未考勤人改为调用页面。

zhengqiang 5 yıl önce
ebeveyn
işleme
c4458559a7

+ 2 - 0
web/src/main/java/com/jpsoft/smart/interceptor/LoginInterceptor.java

@@ -12,6 +12,7 @@ import org.springframework.web.servlet.HandlerInterceptor;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import java.net.URLDecoder;
 import java.security.Key;
 import java.util.Base64;
 
@@ -34,6 +35,7 @@ public class LoginInterceptor implements HandlerInterceptor {
 
         if (StringUtils.isEmpty(token)) {
             token = request.getParameter("token");
+            token = URLDecoder.decode(token,"UTF-8");
         }
 
         boolean result = false;

+ 13 - 9
web/src/main/java/com/jpsoft/smart/modules/mobile/controller/PersonDeviceFilterLogController.java

@@ -167,12 +167,14 @@ public class PersonDeviceFilterLogController {
     @ApiImplicitParams({
             @ApiImplicitParam(name="companyId",value = "公司编号",required = false,paramType = "form"),
             @ApiImplicitParam(name = "queryDate",value = "查询日期(yyyy-MM-dd)",required = true, paramType = "form"),
+            @ApiImplicitParam(name="alarmConfigId",value = "考勤设置编号",required = false,paramType = "form"),
             @ApiImplicitParam(name="token",value = "令牌",required = true,paramType = "form"),
             @ApiImplicitParam(name="subject",value = "目标(不传)",paramType = "form")
     })
     public MessageResult<List> queryUnmeasureGroupList(
             String companyId,
             @DateTimeFormat(pattern = "yyyy-MM-dd") Date queryDate,
+            String alarmConfigId,
             @RequestAttribute String subject,
             String token){
         MessageResult<List> msgResult = new MessageResult<>();
@@ -207,18 +209,20 @@ public class PersonDeviceFilterLogController {
 
             if(configList!=null) {
                 for (AlarmConfig alarmConfig : configList) {
-                    if (alarmConfig.getWeekdays().indexOf(String.valueOf(weekday)) != -1) {
-                        Map<String, Object> map = new HashMap<>();
-                        DateTime startTime = new DateTime(sdf.parse(dateStr + " " + alarmConfig.getStartTime()));
-                        DateTime endTime = new DateTime(sdf.parse(dateStr + " " + alarmConfig.getEndTime()));
+                    if (StringUtils.isEmpty(alarmConfigId) || alarmConfig.getId().equals(alarmConfigId)){
+                        if (alarmConfig.getWeekdays().indexOf(String.valueOf(weekday)) != -1) {
+                            Map<String, Object> map = new HashMap<>();
+                            DateTime startTime = new DateTime(sdf.parse(dateStr + " " + alarmConfig.getStartTime()));
+                            DateTime endTime = new DateTime(sdf.parse(dateStr + " " + alarmConfig.getEndTime()));
 
-                        List<PersonInfo> unmeasuredList = personDeviceLogService.queryUnAttendanceList(companyInfo.getCode() + "%", startTime.toDate(), endTime.toDate());
+                            List<PersonInfo> unmeasuredList = personDeviceLogService.queryUnAttendanceList(companyInfo.getCode() + "%", startTime.toDate(), endTime.toDate());
 
-                        map.put("startTime", alarmConfig.getStartTime());
-                        map.put("endTime", alarmConfig.getEndTime());
-                        map.put("list", unmeasuredList);
+                            map.put("startTime", alarmConfig.getStartTime());
+                            map.put("endTime", alarmConfig.getEndTime());
+                            map.put("list", unmeasuredList);
 
-                        mapList.add(map);
+                            mapList.add(map);
+                        }
                     }
                 }
             }

+ 1 - 2
web/src/main/java/com/jpsoft/smart/modules/mobile/controller/PersonDeviceLogApiController.java

@@ -68,14 +68,13 @@ public class PersonDeviceLogApiController {
         MessageResult<Map> messageResult = new MessageResult<>();
 
         try {
-            PersonInfo admin = personInfoService.get(Long.valueOf(subject));
-
             Map<String, Object> personSearchParam = new HashMap<>();
 
             if (StringUtils.isNotEmpty(companyId) && companyInfoService.exist(companyId)) {
                 personSearchParam.put("companyId", companyId);
             }
             else{
+                PersonInfo admin = personInfoService.get(Long.valueOf(subject));
                 personSearchParam.put("companyId", admin.getCompanyId());
             }
 

+ 52 - 24
web/src/main/java/com/jpsoft/smart/schduled/UnmeasureTemperatureAlarmTask.java

@@ -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());
             }
         }
     }

+ 2 - 0
web/src/main/resources/application.yml

@@ -153,3 +153,5 @@ oss:
   urlPrefix: http://rccs.oss-cn-hangzhou.aliyuncs.com
   objectPre: smart
 
+mobile:
+  unMeasureUrl: http://wisdomhousewechat.sudaonline.net/prevention/adundetect_wx_message.html