Bladeren bron

Merge remote-tracking branch 'origin/V1' into V1

xiao547607 5 jaren geleden
bovenliggende
commit
b9006d8b37

+ 1 - 1
common/src/main/resources/mapper/base/CompanyInfo.xml

@@ -112,7 +112,7 @@
         select a.*,b.name_ as parent_name
         from base_company_info a
         left join base_company_info b on a.parent_id = b.id_
-        where a.id_=#{0} and a.del_flag = 0
+        where a.id_=#{0}
     </select>
     <select id="exist" parameterType="string" resultType="int">
         select count(*) from base_company_info where id_=#{0} and del_flag = 0

+ 0 - 1
web/src/main/java/com/jpsoft/smart/SmartCommunityServerApplication.java

@@ -11,7 +11,6 @@ import org.springframework.transaction.annotation.EnableTransactionManagement;
 
 @SpringBootApplication
 @EnableTransactionManagement
-@EnableScheduling
 @EnableAsync
 @MapperScan("com.jpsoft.smart.**.dao")
 public class SmartCommunityServerApplication extends SpringBootServletInitializer {

+ 36 - 0
web/src/main/java/com/jpsoft/smart/config/ScheduleConfig.java

@@ -0,0 +1,36 @@
+package com.jpsoft.smart.config;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.SchedulingConfigurer;
+import org.springframework.scheduling.config.ScheduledTaskRegistrar;
+
+import javax.annotation.PreDestroy;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+
+@Slf4j
+@EnableScheduling
+@Configuration
+public class ScheduleConfig implements SchedulingConfigurer {
+    private ScheduledExecutorService threadPool;
+
+    @Override
+    public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
+        threadPool = Executors.newScheduledThreadPool(10);
+
+        //当然了,这里设置的线程池是corePoolSize也是很关键了,自己根据业务需求设定
+        taskRegistrar.setScheduler(threadPool);
+    }
+
+    @PreDestroy
+    public void shutdown(){
+        log.warn("关闭定时任务线程");
+
+        if(threadPool!=null){
+            threadPool.shutdown();
+            log.warn("关闭定时任务线程成功!");
+        }
+    }
+}

+ 4 - 1
web/src/main/java/com/jpsoft/smart/listener/WebStateListener.java

@@ -4,6 +4,8 @@ import com.jpsoft.smart.config.ElectricityParamConfig;
 import com.jpsoft.smart.config.LapiParamConfig;
 import com.jpsoft.smart.electricity.server.ElectricityTcpServer;
 import com.jpsoft.smart.lapi.LapiTcpServer;
+import lombok.extern.log4j.Log4j;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
@@ -11,6 +13,7 @@ import javax.servlet.ServletContextEvent;
 import javax.servlet.ServletContextListener;
 import javax.servlet.annotation.WebListener;
 
+@Slf4j
 @WebListener
 @Component
 public class WebStateListener implements ServletContextListener {
@@ -29,7 +32,7 @@ public class WebStateListener implements ServletContextListener {
     @Override
     public void contextDestroyed(ServletContextEvent arg0) {
         // TODO Auto-generated method stub
-        System.out.println("web应用销毁");
+        log.warn("web应用销毁");
 
 //        if(electricityTcpServer!=null) {
 //            electricityTcpServer.stop();

+ 4 - 4
web/src/main/java/com/jpsoft/smart/modules/base/controller/PersonInfoController.java

@@ -565,9 +565,6 @@ public class PersonInfoController {
             searchParams.put("relationPersonIds", personDeviceRelation);
         }
 
-
-
-
         Page<PersonInfo> page = personInfoService.pageSearch(searchParams,pageIndex,pageSize,true,sortList);
         Page<PersonInfoDTO> pageDTO = PojoUtils.convertPage(page, PersonInfoDTO.class);
 
@@ -581,7 +578,10 @@ public class PersonInfoController {
             dto.setDeviceName(deviceName);
 
             CompanyInfo personCompany = companyInfoService.get(dto.getCompanyId());
-            dto.setCompanyType(personCompany.getType());
+
+            if(personCompany!=null) {
+                dto.setCompanyType(personCompany.getType());
+            }
         }
 
         msgResult.setResult(true);

+ 2 - 5
web/src/main/java/com/jpsoft/smart/schduled/CheckPersonTask.java

@@ -41,8 +41,8 @@ public class CheckPersonTask {
 
     @Scheduled(cron = "0 59 23 ? * *")
     public  void run() {
-
         log.warn("公司每日过人记录定时任务开始");
+
         Date date = new Date();
         Date startTime = DateUtil.beginOfDay(date);
         Date endTime = DateUtil.endOfDay(date);
@@ -141,9 +141,6 @@ public class CheckPersonTask {
             }
         }
 
-
-
-
-
+        log.warn("公司每日过人记录定时任务结束");
     }
 }

+ 9 - 2
web/src/main/java/com/jpsoft/smart/schduled/CleanVisitorRecordTask.java

@@ -8,6 +8,7 @@ import com.jpsoft.smart.modules.common.utils.OSSUtil;
 import com.jpsoft.smart.modules.sys.entity.SysLog;
 import com.jpsoft.smart.modules.sys.service.SysLogService;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
@@ -33,6 +34,8 @@ public class CleanVisitorRecordTask {
     //每1小时执行一次
     @Scheduled(cron="0 0 0/1 * * ?")
     public void run(){
+        log.warn("删除过期访客记录任务开始");
+
         List<PersonDeviceLog> logList = personDeviceLogService.findExpiredVisitorRecord(100);
 
         int removeImageCount = 0;
@@ -43,8 +46,10 @@ public class CleanVisitorRecordTask {
         for (PersonDeviceLog personDeviceLog : logList) {
             String faceImage = personDeviceLog.getFaceImage();
 
-            if(OSSUtil.deleteFile(ossConfig,faceImage)){
-                removeImageCount++;
+            if(StringUtils.isNotEmpty(faceImage)){
+                if(OSSUtil.deleteFile(ossConfig,faceImage)){
+                    removeImageCount++;
+                }
             }
 
             removeRawCount += personDeviceLogService.delete(personDeviceLog.getId());
@@ -61,5 +66,7 @@ public class CleanVisitorRecordTask {
         sysLog.setCreateTime(new Date());
 
         sysLogService.insert(sysLog);
+
+        log.warn("删除过期访客记录任务结束");
     }
 }

+ 1 - 4
web/src/main/java/com/jpsoft/smart/schduled/HeartbeatDetectionTask.java

@@ -28,7 +28,6 @@ public class HeartbeatDetectionTask {
     //每2分钟执行一次
     @Scheduled(cron = "0 0/2 * * * ?")
     public void run() {
-
         log.warn("设备在线定时任务启动");
         List<DeviceInfo> deviceInfoList = deviceInfoService.listOnline();
 
@@ -55,10 +54,8 @@ public class HeartbeatDetectionTask {
                     }
                 }
             }
-
         }
 
+        log.warn("设备在线定时任务结束");
     }
-
-
 }

+ 55 - 18
web/src/main/java/com/jpsoft/smart/schduled/UnmeasureTemperatureAlarmTask.java

@@ -11,6 +11,8 @@ import com.jpsoft.smart.modules.common.utils.JwtUtil;
 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.jpsoft.smart.modules.sys.entity.SysLog;
+import com.jpsoft.smart.modules.sys.service.SysLogService;
 import com.sun.corba.se.spi.orbutil.threadpool.Work;
 import io.jsonwebtoken.Jwts;
 import io.jsonwebtoken.security.Keys;
@@ -33,6 +35,7 @@ import org.springframework.stereotype.Component;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.net.SocketAddress;
 import java.net.URLEncoder;
 import java.security.Key;
 import java.text.ParseException;
@@ -87,6 +90,9 @@ public class UnmeasureTemperatureAlarmTask {
     @Autowired
     private HolidayInfoService holidayInfoService;
 
+    @Autowired
+    private SysLogService sysLogService;
+
     public int batchUpdate(String companyId,Date startDate,Date endDate) throws Exception {
         DateTime dt1 = new DateTime(startDate);
         DateTime dt2 = new DateTime(endDate);
@@ -185,11 +191,23 @@ public class UnmeasureTemperatureAlarmTask {
         return affectCount;
     }
 
-    //每5分钟执行一次
-    @Scheduled(cron="0 0/5 * * * ?")
+    private void writeDbLog(String remark,String companyId){
+        SysLog sysLog = new SysLog();
+        sysLog.setPointcut("未测体温提醒");
+        sysLog.setUrl(companyId);
+        sysLog.setRemark(remark);
+        sysLog.setCreateTime(new Date());
+        sysLogService.insert(sysLog);
+    }
+
+    //每5分钟执行一次 fixedDelay:表示上一次任务执行完成后多久再次执行,参数类型为long,单位ms
+    @Scheduled(cron="0 0/5 * * * *")
     public void run() {
+        log.warn("测温提醒任务开始");
+
         int intervalMinute = 5;
 
+        //查询所有的考勤时段
         List<AlarmConfig> configList = alarmConfigService.list();
 
         DateTime now = DateTime.now();
@@ -228,6 +246,11 @@ public class UnmeasureTemperatureAlarmTask {
                 //开始时间
                 if (weekdays.indexOf(String.valueOf(weekday)) != -1) {
                     if (now.compareTo(alarmTime)>=0 && now.compareTo(alarmTime.plusMinutes(intervalMinute))<0) {
+                        writeDbLog(String.format("考勤测温提醒:考勤时间:{0},当前时间:{2}",
+                                alarmTime.toString("yyyy-MM-dd HH:mm:ss"),
+                                now.toString("yyyy-MM-dd HH:mm:ss")),
+                                alarmConfig.getCompanyId());
+
                         //todo 通知个人
                         if(alarmConfig.getNeedMeasureTemperature()){
                             noticePerson(alarmConfig,startTime,endTime);
@@ -244,15 +267,15 @@ public class UnmeasureTemperatureAlarmTask {
                             }
                         }
 
-                        //todo 记录考勤
-                        if (alarmConfig.getClassifier().equals(1)) {
-                            //上班时间前打卡算正常上班
+                        //todo 记录考勤 (改在接收门禁数据中执行)
+//                        if (alarmConfig.getClassifier().equals(1)) {
+//                            //上班时间前打卡算正常上班
 //                            recordAttendance(alarmConfig, startTime.toDate(), attendanceTime.toDate(), WorkAttendance.SUCCESS);
-                        }
-                        else{
-                            //下班时间前打卡算早退
+//                        }
+//                        else{
+//                            //下班时间前打卡算早退
 //                            recordAttendance(alarmConfig, startTime.toDate(), attendanceTime.toDate(), WorkAttendance.LEAVE_EARLY);
-                        }
+//                        }
                     }
 
                     //todo 截止时间已到
@@ -264,15 +287,15 @@ public class UnmeasureTemperatureAlarmTask {
                             }
                         }
 
-                        //todo 记录考勤
-                        if (alarmConfig.getClassifier().equals(1)) {
-                            //上班时间后截止时间前打卡算迟到
+                        //todo 记录考勤 (改在接收门禁数据中执行)
+//                        if (alarmConfig.getClassifier().equals(1)) {
+//                            //上班时间后截止时间前打卡算迟到
 //                            recordAttendance(alarmConfig, attendanceTime.toDate(), endTime.toDate(),WorkAttendance.LATE);
-                        }
-                        else{
-                            //下班时间后截止时间前打卡算正常下班
+//                        }
+//                        else{
+//                            //下班时间后截止时间前打卡算正常下班
 //                            recordAttendance(alarmConfig, attendanceTime.toDate(), endTime.toDate(),WorkAttendance.SUCCESS);
-                        }
+//                        }
 
                         //未在开始截止时间内打卡算旷工
                         recordUnAttendance(alarmConfig,startTime.toDate(),attendanceTime.toDate(),endTime.toDate(),WorkAttendance.MISSING);
@@ -283,6 +306,8 @@ public class UnmeasureTemperatureAlarmTask {
                 log.error(ex.getMessage(),ex);
             }
         }
+
+        log.warn("测温提醒任务结束");
     }
 
     /**
@@ -385,11 +410,18 @@ public class UnmeasureTemperatureAlarmTask {
         //todo 查询该单位当前时间段是否有人员未测体温
         List<PersonInfo> unmeasuredList = personDeviceLogService.queryUnAttendanceList(companyCode,startTime.toDate(),endTime.toDate());
 
+        writeDbLog(String.format(
+                    "查询考勤时段:{0}~{1},未考勤人员数量:{2}",
+                    startTime.toString("yyyy-MM-dd HH:mm"),
+                    endTime.toString("yyyy-MM-dd HH:mm"),
+                    unmeasuredList.size()
+                ), alarmConfig.getCompanyId());
+
         if (unmeasuredList.size()==0){
             return;
         }
 
-        //todo 给未测量人推送微信通知
+        //todo 给未测人推送微信通知
         for (PersonInfo personInfo : unmeasuredList) {
             if (personInfo.getWechatNoticeEnabled()!=null
             && personInfo.getWechatNoticeEnabled()
@@ -402,7 +434,7 @@ public class UnmeasureTemperatureAlarmTask {
 //                else{
 //                    message += ",请在" + attendanceTime.toString("HH:mm") + "至" + endTime.toString("HH:mm") + "时间内在单位(校园)内任意打卡点打卡及测温!";
 //                }
-                message +=",请抓紧时间在单位(校园)内任意打卡点打卡和测温!";
+                message +=",请抓紧时间在单位内任意打卡点打卡和测温!";
 
                 JSONObject sendData = new JSONObject();
 
@@ -432,6 +464,8 @@ public class UnmeasureTemperatureAlarmTask {
                 sendData.put("keyword3", keyword3);
                 sendData.put("remark", remark);
 
+                writeDbLog(String.format("向未测温人:{0}发送测温提醒通知",personInfo.getName()),alarmConfig.getCompanyId());
+
                 WechatMessageUtil.sendTemplate(sendData, wxConfig.getAppId(),wxConfig.getAppSecret(),remindTmplCode,personInfo.getOpenId(), null);
             }
         }
@@ -459,6 +493,7 @@ public class UnmeasureTemperatureAlarmTask {
         //todo 查询该单位的通知人
         List<WarningPusher> pusherList = warningPusherService.findByCompanyId(companyInfo.getId());
 
+
         //todo 给单位相关人员推送通知
         for (WarningPusher pusher: pusherList) {
             if (StringUtils.isNotEmpty(pusher.getOpenId())
@@ -476,6 +511,8 @@ public class UnmeasureTemperatureAlarmTask {
                 }
 
                 try {
+                    writeDbLog(String.format("查询单位:{0},测温统计信息接收人:{1},personId={2}",companyInfo.getName(),pusher.getName(),personId),companyInfo.getId());
+
                     SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
 
                     String token = JwtUtil.createToken(jwtSecret,String.valueOf(personId),sdf.parse("2030-01-01"));

+ 2 - 2
web/src/main/java/com/jpsoft/smart/schduled/UpdatePersonDeviceBoundTask.java

@@ -42,11 +42,11 @@ public class UpdatePersonDeviceBoundTask {
     @Autowired
     private DeviceInfoService deviceInfoService;
 
-    @Scheduled(cron = "0 0/10 * * * ?")
+    //已改为实时查询,已不需要执行
+//    @Scheduled(cron = "0 0/10 * * * ?")
     public  void run() {
         log.warn("人员设备绑定关系更新定时任务开始");
 
-
         //200条数据,更新时间要晚于当前时间的前一天
         List<PersonDeviceRelation> personDeviceRelationList = personDeviceRelationService.findByIsBoundAndUpdateTime(DateUtil.offset(new Date(),DateField.DAY_OF_MONTH, -1),200);
         if (personDeviceRelationList.size()>0){