Browse Source

亲密度汇总统计功能

liu 3 years ago
parent
commit
f20530506b

+ 9 - 1
src/main/java/com/chuanghai/student_portrait/controller/AffinityScoreController.java

@@ -1,13 +1,21 @@
 package com.chuanghai.student_portrait.controller;
 
+import com.chuanghai.student_portrait.response.BaseResponse;
 import com.chuanghai.student_portrait.service.AffinityScoreService;
+import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 @RestController
-@RequestMapping
+@RequestMapping("/affinityScore")
 public class AffinityScoreController {
     @Autowired
     AffinityScoreService affinityScoreService;
+    @GetMapping("/get")
+    @ApiOperation(value = "亲密度汇总,id为学生序号")
+    public BaseResponse getAffinityScore(String id){
+        return affinityScoreService.getAffinityScore(id);
+    }
 }

+ 19 - 0
src/main/java/com/chuanghai/student_portrait/controller/CapacityController.java

@@ -0,0 +1,19 @@
+package com.chuanghai.student_portrait.controller;
+
+import com.chuanghai.student_portrait.service.CapacityService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping
+public class CapacityController {
+    @Autowired
+    CapacityService capacityService;
+
+    @GetMapping("/capacity")
+    public void saveHealthCapacity(){
+        capacityService.saveHealthCapacity();
+    }
+}

+ 14 - 0
src/main/java/com/chuanghai/student_portrait/entity/Capacity.java

@@ -0,0 +1,14 @@
+package com.chuanghai.student_portrait.entity;
+
+import lombok.Data;
+
+import java.util.Date;
+
+@Data
+public class Capacity {
+    private Integer id;
+    private String capacityName;
+    private String units;
+    private Date dateTime;
+    private String schooluserId;
+}

+ 1 - 0
src/main/java/com/chuanghai/student_portrait/entity/Forewarning.java

@@ -21,4 +21,5 @@ public class Forewarning {
     private String warningReason;
 //    备注
     private String remark;
+    private String schooluserId;
 }

+ 9 - 0
src/main/java/com/chuanghai/student_portrait/mapper/CapacityMapper.java

@@ -0,0 +1,9 @@
+package com.chuanghai.student_portrait.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.chuanghai.student_portrait.entity.Capacity;
+import org.apache.ibatis.annotations.Mapper;
+
+@Mapper
+public interface CapacityMapper extends BaseMapper<Capacity> {
+}

+ 2 - 0
src/main/java/com/chuanghai/student_portrait/service/AffinityScoreService.java

@@ -2,6 +2,8 @@ package com.chuanghai.student_portrait.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.chuanghai.student_portrait.entity.AffinityScore;
+import com.chuanghai.student_portrait.response.BaseResponse;
 
 public interface AffinityScoreService extends IService<AffinityScore> {
+    BaseResponse getAffinityScore(String id);
 }

+ 8 - 0
src/main/java/com/chuanghai/student_portrait/service/CapacityService.java

@@ -0,0 +1,8 @@
+package com.chuanghai.student_portrait.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.chuanghai.student_portrait.entity.Capacity;
+
+public interface CapacityService extends IService<Capacity> {
+    void saveHealthCapacity();
+}

+ 167 - 0
src/main/java/com/chuanghai/student_portrait/service/impl/AffinityScoreServiceImpl.java

@@ -1,11 +1,178 @@
 package com.chuanghai.student_portrait.service.impl;
 
+
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.chuanghai.student_portrait.entity.AffinityScore;
+import com.chuanghai.student_portrait.entity.Consume;
+import com.chuanghai.student_portrait.entity.FaceDiscern;
+import com.chuanghai.student_portrait.entity.NewSchooluser;
 import com.chuanghai.student_portrait.mapper.AffinityScoreMapper;
+import com.chuanghai.student_portrait.response.BaseResponse;
+import com.chuanghai.student_portrait.response.enums.StatusEnum;
 import com.chuanghai.student_portrait.service.AffinityScoreService;
+import com.chuanghai.student_portrait.service.ConsumeService;
+import com.chuanghai.student_portrait.service.FaceDiscernService;
+import com.chuanghai.student_portrait.service.NewSchooluserService;
+import org.apache.commons.lang3.ObjectUtils;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Service;
 
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
 @Service
 public class AffinityScoreServiceImpl extends ServiceImpl<AffinityScoreMapper, AffinityScore> implements AffinityScoreService {
+
+    @Autowired
+    FaceDiscernService faceDiscernService;
+
+    @Autowired
+    ConsumeService consumeService;
+
+    @Autowired
+    NewSchooluserService newSchooluserService;
+
+    @Override
+    public BaseResponse getAffinityScore(String id) {
+        if (ObjectUtils.isEmpty(id)) {
+            return BaseResponse.error(StatusEnum.FAIL, "参数异常");
+        }
+        List<AffinityScore> list = this.list(Wrappers.<AffinityScore>lambdaQuery().eq(AffinityScore::getSchooluserId, id).orderByDesc(AffinityScore::getCount));
+
+        return BaseResponse.ok(StatusEnum.SUCCESS, list);
+    }
+
+    @Scheduled(cron = "0 29 17 * * ? ")
+    public void saveAndUpdateFaceAffinityScore() {
+        DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+        LocalDateTime now = LocalDateTime.now();
+
+        LocalDateTime start = now.withHour(0).withMinute(0).withSecond(0);
+        String startTime = start.minusDays(1).format(pattern);
+
+        LocalDateTime end = now.withHour(23).withMinute(59).withSecond(59);
+        String endTime = end.minusDays(1).format(pattern);
+//        ArrayList<AffinityScore> saves = new ArrayList<>();
+//        ArrayList<AffinityScore> updates = new ArrayList<>();
+        List<FaceDiscern> list = faceDiscernService.list(Wrappers.<FaceDiscern>lambdaQuery().between(FaceDiscern::getFacediscernTime, startTime, endTime).orderByAsc(FaceDiscern::getFacediscernTime));
+        if (ObjectUtils.isNotEmpty(list) && list.size() > 0) {
+            for (FaceDiscern faceDiscern : list) {
+                Date facediscernTime = faceDiscern.getFacediscernTime();
+                Date date1 = new Date(facediscernTime.getTime() + 10 * 1000);
+                Date date2 = new Date(facediscernTime.getTime() - 10 * 1000);
+                String shooluserId = faceDiscern.getShooluserId();
+
+                List<FaceDiscern> list1 = faceDiscernService.list(Wrappers.<FaceDiscern>lambdaQuery().between(FaceDiscern::getFacediscernTime, date2, date1));
+                if (ObjectUtils.isNotEmpty(list1) && list1.size() > 0) {
+                    for (FaceDiscern discern : list1) {
+                        String shooluserId1 = discern.getShooluserId();
+                        if (!shooluserId.equals(shooluserId1)) {
+                            AffinityScore one = this.getOne(Wrappers.<AffinityScore>lambdaQuery().eq(AffinityScore::getSchooluserId, shooluserId).eq(AffinityScore::getNameSchooluserId, shooluserId1));
+                            if (ObjectUtils.isEmpty(one)) {
+                                AffinityScore affinityScore = new AffinityScore();
+                                affinityScore.setSchooluserId(shooluserId);
+                                affinityScore.setDateTime(facediscernTime);
+                                affinityScore.setNameSchooluserId(shooluserId1);
+                                NewSchooluser newSchooluser = newSchooluserService.getById(shooluserId1);
+                                affinityScore.setCount(1);
+                                affinityScore.setName(newSchooluser.getName());
+                                affinityScore.setStudentId(newSchooluser.getStudentId());
+                                affinityScore.setProfession(newSchooluser.getProfession());
+                                affinityScore.setClazz(newSchooluser.getClazz());
+                                this.save(affinityScore);
+//                            saves.add(affinityScore);
+                            } else {
+//                                long time = one.getDateTime().getTime();
+//                                long time1 = facediscernTime.getTime();
+//                                if (time1 > time) {
+                                one.setDateTime(facediscernTime);
+                                one.setCount(one.getCount() + 1);
+                                AffinityScore affinityScore = new AffinityScore();
+                                BeanUtils.copyProperties(one, affinityScore);
+//                                updates.add(affinityScore);
+                                this.updateById(affinityScore);
+//                                }
+                            }
+
+                        }
+                    }
+                }
+            }
+        }
+//        this.saveBatch(saves);
+//        this.updateBatchById(updates);
+
+    }
+
+    @Scheduled(cron = "0 34 17 * * ? ")
+    public void saveAndUpdateConsumeAffinityScore() {
+        DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+        LocalDateTime now = LocalDateTime.now();
+
+        LocalDateTime start = now.withHour(0).withMinute(0).withSecond(0);
+        String startTime = start.minusDays(1).format(pattern);
+
+        LocalDateTime end = now.withHour(23).withMinute(59).withSecond(59);
+        String endTime = end.minusDays(1).format(pattern);
+//        ArrayList<AffinityScore> saves = new ArrayList<>();
+//        ArrayList<AffinityScore> updates = new ArrayList<>();
+        List<Consume> list = consumeService.list(Wrappers.<Consume>lambdaQuery().between(Consume::getConsumeTime, startTime, endTime).orderByAsc(Consume::getConsumeTime));
+        if (ObjectUtils.isNotEmpty(list) && list.size() > 0) {
+            for (Consume consume1 : list) {
+                Date consumeTime = consume1.getConsumeTime();
+                Date date1 = new Date(consumeTime.getTime() + 30 * 1000);
+                Date date2 = new Date(consumeTime.getTime() - 30 * 1000);
+                String shooluserId = consume1.getIdCard();
+                if (ObjectUtils.isNotEmpty(shooluserId)) {
+                    List<Consume> list1 = consumeService.list(Wrappers.<Consume>lambdaQuery().between(Consume::getConsumeTime, date2, date1));
+                    if (ObjectUtils.isNotEmpty(list1) && list1.size() > 0) {
+                        for (Consume consume : list1) {
+                            String idCard = consume.getIdCard();
+                            if (ObjectUtils.isNotEmpty(idCard)) {
+                                if (!shooluserId.equals(idCard)) {
+                                    AffinityScore one = this.getOne(Wrappers.<AffinityScore>lambdaQuery().eq(AffinityScore::getSchooluserId, shooluserId).eq(AffinityScore::getNameSchooluserId, idCard));
+                                    if (ObjectUtils.isEmpty(one)) {
+                                        AffinityScore affinityScore = new AffinityScore();
+                                        affinityScore.setSchooluserId(shooluserId);
+                                        affinityScore.setDateTime(consumeTime);
+                                        affinityScore.setNameSchooluserId(idCard);
+                                        NewSchooluser newSchooluser = newSchooluserService.getById(idCard);
+                                        affinityScore.setCount(1);
+                                        affinityScore.setName(newSchooluser.getName());
+                                        affinityScore.setStudentId(newSchooluser.getStudentId());
+                                        affinityScore.setProfession(newSchooluser.getProfession());
+                                        affinityScore.setClazz(newSchooluser.getClazz());
+                                        this.save(affinityScore);
+//                            saves.add(affinityScore);
+                                    } else {
+//                                long time = one.getDateTime().getTime();
+//                                long time1 = consumeTime.getTime();
+//                                if (time1 > time) {
+                                        one.setDateTime(consumeTime);
+                                        one.setCount(one.getCount() + 1);
+                                        AffinityScore affinityScore = new AffinityScore();
+                                        BeanUtils.copyProperties(one, affinityScore);
+//                                updates.add(affinityScore);
+                                        this.updateById(affinityScore);
+//                                }
+                                    }
+
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+//        this.saveBatch(saves);
+//        this.updateBatchById(updates);
+
+    }
+
 }

+ 186 - 0
src/main/java/com/chuanghai/student_portrait/service/impl/CapacityServiceImpl.java

@@ -0,0 +1,186 @@
+package com.chuanghai.student_portrait.service.impl;
+
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.chuanghai.student_portrait.entity.Capacity;
+import com.chuanghai.student_portrait.entity.Consume;
+import com.chuanghai.student_portrait.mapper.CapacityMapper;
+import com.chuanghai.student_portrait.service.*;
+import com.chuanghai.student_portrait.utils.DateUtils;
+import org.apache.commons.lang3.ObjectUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.time.Duration;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.Date;
+import java.util.List;
+
+@Service
+public class CapacityServiceImpl extends ServiceImpl<CapacityMapper, Capacity> implements CapacityService {
+
+    @Autowired
+    ConsumeService consumeService;
+
+    @Autowired
+    FaceDiscernService faceDiscernService;
+
+    @Autowired
+    AccessService accessService;
+
+    @Autowired
+    HotWaterService hotWaterService;
+
+    @Autowired
+    ForewarningService forewarningService;
+
+    @Override
+//    @Transactional(rollbackFor = Exception.class)
+    public void saveHealthCapacity() {
+//        DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+        String startTime = startTime();
+        String endTime = endTime();
+        LocalDateTime start = LocalDateTime.parse(startTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+        LocalDateTime end = LocalDateTime.parse(endTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+//        开始和结束相差的天数
+        Duration duration = Duration.between(start, end);
+        long days = duration.toDays();
+        for (int i = 0; i <= days; i++) {
+//            每次开始时间
+            LocalDateTime time = start.plusDays(i);
+////            每次结束时间
+//            LocalDateTime time2 = start.plusDays(i + 1);
+
+            LocalDateTime localDateTime1 = time.withHour(6).withMinute(0).withSecond(0);
+            LocalDateTime localDateTime2 = time.withHour(10).withMinute(30).withSecond(0);
+
+            LocalDateTime localDateTime3 = time.withHour(11).withMinute(0).withSecond(0);
+            LocalDateTime localDateTime4 = time.withHour(15).withMinute(0).withSecond(0);
+
+            LocalDateTime localDateTime5 = time.withHour(16).withMinute(0).withSecond(0);
+            LocalDateTime localDateTime6 = time.withHour(20).withMinute(0).withSecond(0);
+            List<Consume> list1 = consumeService.list(Wrappers.<Consume>lambdaQuery().select(Consume::getIdCard).between(Consume::getConsumeTime, localDateTime1, localDateTime2).groupBy(Consume::getIdCard));
+            List<Consume> list2 = consumeService.list(Wrappers.<Consume>lambdaQuery().select(Consume::getIdCard).between(Consume::getConsumeTime, localDateTime3, localDateTime4).groupBy(Consume::getIdCard));
+            List<Consume> list3 = consumeService.list(Wrappers.<Consume>lambdaQuery().select(Consume::getIdCard).between(Consume::getConsumeTime, localDateTime5, localDateTime6).groupBy(Consume::getIdCard));
+            for (Consume consume : list1) {
+                String idCard = consume.getIdCard();
+                if (idCard != null && idCard != "") {
+                    String capacityName = "健康";
+                    Capacity capacity = getCapacity(idCard, capacityName, startTime);
+                    if (ObjectUtils.isNotEmpty(capacity)) {
+                        String units = capacity.getUnits();
+                        int i1 = Integer.parseInt(units);
+                        int un = i1 + 1;
+                        String s = String.valueOf(un);
+                        capacity.setUnits(s);
+                        this.updateById(capacity);
+                    } else {
+                        Capacity capacity1 = new Capacity();
+                        capacity1.setCapacityName(capacityName);
+                        capacity1.setSchooluserId(idCard);
+                        Date date = null;
+                        try {
+                            date = DateUtils.stringToDate(startTime);
+                        } catch (Exception e) {
+                            throw new RuntimeException(e);
+                        }
+                        capacity1.setDateTime(date);
+                        capacity1.setUnits("1");
+                        this.save(capacity1);
+                    }
+                }
+            }
+            for (Consume consume : list2) {
+                String idCard = consume.getIdCard();
+                if (idCard != null && idCard != "") {
+                    String capacityName = "健康";
+                    Capacity capacity = getCapacity(idCard, capacityName, startTime);
+                    if (ObjectUtils.isNotEmpty(capacity)) {
+                        String units = capacity.getUnits();
+                        int i1 = Integer.parseInt(units);
+                        int un = i1 + 1;
+                        String s = String.valueOf(un);
+                        capacity.setUnits(s);
+                        this.updateById(capacity);
+                    } else {
+                        Capacity capacity1 = new Capacity();
+                        capacity1.setCapacityName(capacityName);
+                        capacity1.setSchooluserId(idCard);
+                        Date date = null;
+                        try {
+                            date = DateUtils.stringToDate(startTime);
+                        } catch (Exception e) {
+                            throw new RuntimeException(e);
+                        }
+                        capacity1.setDateTime(date);
+                        capacity1.setUnits("1");
+                        this.save(capacity1);
+                    }
+                }
+            }
+            for (Consume consume : list3) {
+                String idCard = consume.getIdCard();
+                if (idCard != null && idCard != "") {
+                    String capacityName = "健康";
+                    Capacity capacity = getCapacity(idCard, capacityName, startTime);
+                    if (ObjectUtils.isNotEmpty(capacity)) {
+                        String units = capacity.getUnits();
+                        int i1 = Integer.parseInt(units);
+                        int un = i1 + 1;
+                        String s = String.valueOf(un);
+                        capacity.setUnits(s);
+                        this.updateById(capacity);
+                    } else {
+                        Capacity capacity1 = new Capacity();
+                        capacity1.setCapacityName(capacityName);
+                        capacity1.setSchooluserId(idCard);
+                        Date date = null;
+                        try {
+                            date = DateUtils.stringToDate(startTime);
+                        } catch (Exception e) {
+                            throw new RuntimeException(e);
+                        }
+                        capacity1.setDateTime(date);
+                        capacity1.setUnits("1");
+                        this.save(capacity1);
+                    }
+                }
+            }
+        }
+
+    }
+
+    public static String startTime() {
+        DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+        LocalDateTime now = LocalDateTime.now();
+        LocalDateTime start = now.withDayOfMonth(1).withHour(0).withMinute(0).withSecond(0);
+        return start.minusMonths(1).format(pattern);
+    }
+
+    public static String endTime() {
+        DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+        LocalDateTime now = LocalDateTime.now();
+        LocalDateTime end = now.withDayOfMonth(1).withHour(23).withMinute(59).withSecond(59);
+        return end.minusDays(1).format(pattern);
+    }
+
+    public Capacity getCapacity(String schooluserId, String capacityName, String startTime) {
+        Capacity one = this.getOne(Wrappers.<Capacity>lambdaQuery()
+                .eq(Capacity::getSchooluserId, schooluserId)
+                .eq(Capacity::getCapacityName, capacityName)
+                .eq(Capacity::getDateTime, startTime));
+        return one;
+    }
+
+
+    public static void main(String[] args) throws Exception {
+        String id = null;
+        if (ObjectUtils.isNotEmpty(id)) {
+            System.out.println(true);
+        }
+
+    }
+
+}

+ 13 - 13
src/main/java/com/chuanghai/student_portrait/service/impl/ConsumeServicelmpl.java

@@ -278,19 +278,19 @@ public class ConsumeServicelmpl extends ServiceImpl<ConsumeMapper, Consume> impl
                     if (ObjectUtils.isNotEmpty(newSchooluser)) {
                         String id = newSchooluser.getId();
                         consume.setIdCard(id);
-                    }
-                    consume.setConsumeAddress(jsonMap.get("mch_name").toString());
-                    consume.setConsumeEvent(jsonMap.get("pay_channel").toString());
-                    String pay_time = jsonMap.get("pay_time").toString();
-                    String deal_amount = jsonMap.get("deal_amount").toString();
-                    String org_name = jsonMap.get("org_name").toString();
-                    deal_amount = String.valueOf(Integer.parseInt(deal_amount) / 100);
-                    consume.setConsumeAmount(deal_amount);
-                    consume.setConsumeTime(DateUtils.stringToDate(pay_time));
-                    consume.setOrgName(org_name);
-                    //通过cardNumber 和活动时间 判断该用户消费活动是否存在于门禁数据库中
-                    if (!chackConsumeActive(consume.getIdCard(), pay_time)) {
-                        this.save(consume);
+                        consume.setConsumeAddress(jsonMap.get("mch_name").toString());
+                        consume.setConsumeEvent(jsonMap.get("pay_channel").toString());
+                        String pay_time = jsonMap.get("pay_time").toString();
+                        String deal_amount = jsonMap.get("deal_amount").toString();
+                        String org_name = jsonMap.get("org_name").toString();
+                        deal_amount = String.valueOf(Integer.parseInt(deal_amount) / 100);
+                        consume.setConsumeAmount(deal_amount);
+                        consume.setConsumeTime(DateUtils.stringToDate(pay_time));
+                        consume.setOrgName(org_name);
+                        //通过cardNumber 和活动时间 判断该用户消费活动是否存在于门禁数据库中
+                        if (!chackConsumeActive(consume.getIdCard(), pay_time)) {
+                            this.save(consume);
+                        }
                     }
                 } catch (Exception e) {
                     e.printStackTrace();

+ 2 - 2
src/main/java/com/chuanghai/student_portrait/service/impl/FaceDiscernServiceImpl.java

@@ -146,7 +146,7 @@ public class FaceDiscernServiceImpl extends ServiceImpl<FaceDiscernMapper, FaceD
         Duration duration = Duration.between(start, end);
         long days = duration.toDays();
 
-//        long day = 3600 * 1000 * 24;
+
 
         for (int i = 0; i <= days; i++) {
             startTime = start.plusDays(i).format(pattern);
@@ -252,7 +252,7 @@ public class FaceDiscernServiceImpl extends ServiceImpl<FaceDiscernMapper, FaceD
                 Stall one = stallService.getOne(Wrappers.<Stall>lambdaQuery().eq(Stall::getAddress, consumeAddress));
                 String name = one.getName();
                 dto.setDateTime(consumeTime);
-                dto.setAffair(name);
+                dto.setAffair(consumeAddress+":"+name);
 
                 Instant instant = consumeTime.toInstant();
                 LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, ZoneId.ofOffset("GMT", ZoneOffset.ofHours(8)));

+ 12 - 2
src/main/java/com/chuanghai/student_portrait/service/impl/ForewarningServiceImpl.java

@@ -156,6 +156,9 @@ public class ForewarningServiceImpl extends ServiceImpl<ForewarningMapper, Forew
 //              班级
                     String clazz = newSchooluser.getClazz();
                     forewarning.setClazz(clazz);
+
+                    forewarning.setSchooluserId(shooluserId);
+
 //                判断该数据是否已添加
                     Boolean exists = queryForewarningExists(name, date, "出校未归");
                     if (!exists) {
@@ -224,6 +227,9 @@ public class ForewarningServiceImpl extends ServiceImpl<ForewarningMapper, Forew
 //              班级
                     String clazz = newSchooluser.getClazz();
                     forewarning.setClazz(clazz);
+
+                    forewarning.setSchooluserId(cardNumber);
+
 //                判断该数据是否已添加
                     Boolean exists = queryForewarningExists(name, date, "出校未归");
                     if (!exists) {
@@ -264,7 +270,7 @@ public class ForewarningServiceImpl extends ServiceImpl<ForewarningMapper, Forew
 
 //            每个月的1号的时间定上个月的水费超额预警时间
             DateTimeFormatter pattern1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
-            String dateTime = now.withDayOfMonth(1).withHour(0).withMinute(0).withSecond(0).format(pattern1);
+            String dateTime = now.withDayOfMonth(1).withHour(1).withMinute(1).withSecond(1).format(pattern1);
             Date date1;
             try {
                 date1 = DateUtils.stringToDate(dateTime);
@@ -310,7 +316,7 @@ public class ForewarningServiceImpl extends ServiceImpl<ForewarningMapper, Forew
 
 //            每个月的1号的时间定上个月的水费超额预警时间
             DateTimeFormatter pattern1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
-            String dateTime = now.withDayOfMonth(1).withHour(0).withMinute(0).withSecond(0).format(pattern1);
+            String dateTime = now.withDayOfMonth(1).withHour(1).withMinute(1).withSecond(1).format(pattern1);
             Date date1;
             try {
                 date1 = DateUtils.stringToDate(dateTime);
@@ -366,6 +372,7 @@ public class ForewarningServiceImpl extends ServiceImpl<ForewarningMapper, Forew
                 forewarning.setDateTime(hotwaterTime);
                 forewarning.setWarningReason("热水消费异常");
                 forewarning.setRemark(hotWater.getHotwaterAmount());
+                forewarning.setSchooluserId(cardNumber);
                 Boolean exists = queryForewarningExists(name, hotwaterTime, "热水消费异常");
                 if (!exists) {
                     forewarnings.add(forewarning);
@@ -416,6 +423,7 @@ public class ForewarningServiceImpl extends ServiceImpl<ForewarningMapper, Forew
                 forewarning.setDateTime(consumeTime);
                 forewarning.setWarningReason("食堂消费过高");
                 forewarning.setRemark(consume.getConsumeAmount());
+                forewarning.setSchooluserId(schoolId);
                 Boolean exists = queryForewarningExists(name, consumeTime, "食堂消费过高");
                 if (!exists) {
                     forewarnings.add(forewarning);
@@ -470,6 +478,7 @@ public class ForewarningServiceImpl extends ServiceImpl<ForewarningMapper, Forew
                 forewarning.setClazz(clazz);
                 forewarning.setDateTime(facediscernTime);
                 forewarning.setWarningReason("归寝异常");
+                forewarning.setSchooluserId(shooluserId);
                 Boolean exists = queryForewarningExists(name, facediscernTime, "归寝异常");
                 if (!exists) {
                     forewarnings.add(forewarning);
@@ -504,6 +513,7 @@ public class ForewarningServiceImpl extends ServiceImpl<ForewarningMapper, Forew
                 forewarning.setClazz(clazz);
                 forewarning.setDateTime(accessTime);
                 forewarning.setWarningReason("归寝异常");
+                forewarning.setSchooluserId(shooluserId);
                 Boolean exists = queryForewarningExists(name, accessTime, "归寝异常");
                 if (!exists) {
                     forewarnings.add(forewarning);