Browse Source

添加打卡亲密度数据

liu 1 năm trước cách đây
mục cha
commit
832ffa47a3

+ 2 - 0
src/main/java/com/template/services/SmartAttendanceService.java

@@ -56,4 +56,6 @@ public interface SmartAttendanceService extends IService<SmartAttendance> {
     Integer deleteDatasByids(List<Integer> ids);
 
     List<SmartAttendance> toDateList(LocalDateTime start, LocalDateTime end);
+
+    List<SmartAttendance> toDateAndPlacelist(LocalDateTime startTime, LocalDateTime endTime, Integer classId);
 }

+ 13 - 0
src/main/java/com/template/services/impl/SmartAttendanceServiceImpl.java

@@ -200,6 +200,19 @@ public class SmartAttendanceServiceImpl extends ServiceImpl<SmartAttendanceMappe
     public List<SmartAttendance> toDateList(LocalDateTime start, LocalDateTime end) {
         LambdaQueryWrapper<SmartAttendance> wrapper=new LambdaQueryWrapper<>();
         wrapper.between(SmartAttendance::getAttendTime,start,end);
+        wrapper.ne(SmartAttendance::getStatus,3)
+                .ne(SmartAttendance::getStatus,6);
+        List<SmartAttendance> list = this.list(wrapper);
+        return list;
+    }
+
+    @Override
+    public List<SmartAttendance> toDateAndPlacelist(LocalDateTime startTime, LocalDateTime endTime, Integer classId) {
+        LambdaQueryWrapper<SmartAttendance> wrapper = new LambdaQueryWrapper<>();
+        wrapper.between(SmartAttendance::getAttendTime, startTime, endTime);
+        wrapper.eq(SmartAttendance::getClassId, classId);
+        wrapper.ne(SmartAttendance::getStatus, 3)
+                .ne(SmartAttendance::getStatus, 6);
         List<SmartAttendance> list = this.list(wrapper);
         return list;
     }

+ 59 - 9
src/main/java/com/template/services/impl/SmartRelationServiceImpl.java

@@ -22,7 +22,9 @@ import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
 import java.time.LocalDateTime;
+import java.time.ZoneId;
 import java.time.format.DateTimeFormatter;
+import java.util.Date;
 import java.util.List;
 
 /**
@@ -58,7 +60,7 @@ public class SmartRelationServiceImpl extends ServiceImpl<SmartRelationMapper, S
 
     @Async
     @Scheduled(cron = "0 20 0 * * ? ")//每天凌晨一点
-//    @Scheduled(cron = "0 10 14 * * ? ")//每天凌晨一点
+//    @Scheduled(cron = "0 6 15 * * ? ")//每天凌晨一点
     public void getAccessSmartRelation() {
         if (scheduleConfig.getIsOpen().equals("1")) {
             DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
@@ -77,7 +79,7 @@ public class SmartRelationServiceImpl extends ServiceImpl<SmartRelationMapper, S
                 Integer userId = smartAccess.getUserId();
                 SmartUser smartUser = smartUserService.getSmartById(userId);
                 String type = smartAccess.getType();
-                List<SmartAccess> accesses = smartAccessService.toDateAndPlacelist(startTime, endTime,type);
+                List<SmartAccess> accesses = smartAccessService.toDateAndPlacelist(startTime, endTime, type);
                 if (ObjectUtils.isNotEmpty(accesses) && accesses.size() > 0) {
 
                     for (SmartAccess access : accesses) {
@@ -121,7 +123,7 @@ public class SmartRelationServiceImpl extends ServiceImpl<SmartRelationMapper, S
     }
 
     @Async
-    @Scheduled(cron = "0 40 2 * * ? ")//每天凌晨两点
+    @Scheduled(cron = "0 30 2 * * ? ")//每天凌晨两点
 //    @Scheduled(cron = "0 25` * * * ? ")//每天凌晨两点
     public void getFaceDiscernListSmartRelation() {
         if (scheduleConfig.getIsOpen().equals("1")) {
@@ -143,7 +145,7 @@ public class SmartRelationServiceImpl extends ServiceImpl<SmartRelationMapper, S
                 Integer userId = faceDiscern.getUserId();
                 SmartUser smartUser = smartUserService.getSmartById(userId);
                 String location = faceDiscern.getLocation();
-                List<SmartFaceDiscern> faceDiscerns = smartFaceDiscernService.toDateAndPlacelist(startTime, endTime,location);
+                List<SmartFaceDiscern> faceDiscerns = smartFaceDiscernService.toDateAndPlacelist(startTime, endTime, location);
                 if (ObjectUtils.isNotEmpty(faceDiscerns) && faceDiscerns.size() > 0) {
 
                     for (SmartFaceDiscern faceDiscern1 : faceDiscerns) {
@@ -185,12 +187,14 @@ public class SmartRelationServiceImpl extends ServiceImpl<SmartRelationMapper, S
         }
     }
 
-//    @Async
-//    @Scheduled(cron = "0 20 3 * * ? ")//每天凌晨一点
+    @Async
+    @Scheduled(cron = "0 30 3 * * ? ")//每天凌晨一点
+//    @Scheduled(cron = "0 38 15 * * ? ")//每天凌晨一点
     public void getAttendanceListSmartRelation() {
         if (scheduleConfig.getIsOpen().equals("1")) {
             DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
             LocalDateTime now = LocalDateTime.now();
+//            LocalDateTime now = LocalDateTime.now().withMonth(6).withDayOfMonth(26);
             LocalDateTime start = now.withHour(0).withMinute(0).withSecond(0).minusDays(1);
             LocalDateTime end = now.withHour(23).withMinute(59).withSecond(59).minusDays(1);
             String format = start.format(pattern);
@@ -198,6 +202,52 @@ public class SmartRelationServiceImpl extends ServiceImpl<SmartRelationMapper, S
 //            找到昨天的所有数据
             List<SmartAttendance> attendanceList = smartAttendanceService.toDateList(start, end);
 
+            for (SmartAttendance smartAttendance : attendanceList) {
+                Date attendTime = smartAttendance.getAttendTime();
+                LocalDateTime date = LocalDateTime.ofInstant(attendTime.toInstant(), ZoneId.systemDefault());
+                LocalDateTime startTime = date.minusSeconds(5);
+                LocalDateTime endTime = date.plusSeconds(5);
+//              获取班级
+                Integer classId = smartAttendance.getClassId();
+                Integer userId = smartAttendance.getUserId();
+//                获取名字
+                String userName = smartAttendance.getXwUserName();
+
+                List<SmartAttendance> attendances = smartAttendanceService.toDateAndPlacelist(startTime, endTime, classId);
+                if (ObjectUtils.isNotEmpty(attendances) && attendances.size() > 0) {
+                    for (SmartAttendance attendance : attendances) {
+                        Integer userId1 = attendance.getUserId();
+                        String userName1 = attendance.getXwUserName();
+                        if (!userId.equals(userId1)) {
+                            //                        判断是否已添加,有的话则加1
+                            LambdaQueryWrapper<SmartRelation> wrapper = new LambdaQueryWrapper<>();
+                            wrapper.eq(SmartRelation::getUserId, userId)
+                                    .eq(SmartRelation::getRelationId, userId1)
+                                    .eq(SmartRelation::getDateTime, format);
+                            SmartRelation one = this.getOne(wrapper);
+                            if (ObjectUtils.isEmpty(one)) {
+                                SmartRelation smartRelation = new SmartRelation();
+                                smartRelation.setUserId(userId);
+                                smartRelation.setRelationId(userId1);
+                                smartRelation.setName(userName);
+                                smartRelation.setRelationName(userName1);
+
+                                smartRelation.setDateTime(format);
+                                smartRelation.setCount(1);
+                                this.save(smartRelation);
+                            } else {
+                                Integer count = one.getCount();
+                                count = count + 1;
+                                one.setCount(count);
+                                this.updateById(one);
+                            }
+                        }
+
+                    }
+                }
+
+
+            }
 
         }
     }
@@ -205,11 +255,11 @@ public class SmartRelationServiceImpl extends ServiceImpl<SmartRelationMapper, S
 
 
     @Override
-    public PageUtils<SmartRelationVo> getList(int currentPage,int pageCount,Integer userId, String startTime, String endTime) {
+    public PageUtils<SmartRelationVo> getList(int currentPage, int pageCount, Integer userId, String startTime, String endTime) {
         Page<SmartRelationVo> page = new Page<>();
         page.setCurrent(currentPage);
         page.setSize(pageCount);
-        IPage<SmartRelationVo> result =smartRelationMapper.getList(page,userId,startTime,endTime);
+        IPage<SmartRelationVo> result = smartRelationMapper.getList(page, userId, startTime, endTime);
 
         return new PageUtils(result);
     }
@@ -219,7 +269,7 @@ public class SmartRelationServiceImpl extends ServiceImpl<SmartRelationMapper, S
         Page<SmartRelationAppVo> page = new Page<>();
         page.setCurrent(currentPage);
         page.setSize(pageCount);
-        IPage<SmartRelationAppVo> result =smartRelationMapper.getAppList(page,userId,startTime,endTime);
+        IPage<SmartRelationAppVo> result = smartRelationMapper.getAppList(page, userId, startTime, endTime);
 
         return new PageUtils(result);
     }