Browse Source

个人学生能力功能

liu 3 years ago
parent
commit
3e0828589e

+ 14 - 4
src/main/java/com/chuanghai/student_portrait/controller/CapacityController.java

@@ -1,19 +1,29 @@
 package com.chuanghai.student_portrait.controller;
 
+import com.chuanghai.student_portrait.response.BaseResponse;
 import com.chuanghai.student_portrait.service.CapacityService;
+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("/capacity")
 public class CapacityController {
     @Autowired
     CapacityService capacityService;
 
-    @GetMapping("/capacity")
-    public void saveHealthCapacity(){
-        capacityService.saveHealthCapacity();
+    @GetMapping("/one/student")
+    @ApiOperation(value = "单个学生能力,参数为该学生序号")
+    public BaseResponse getOneStudent(String id){
+        return capacityService.getOneStudent(id);
     }
+
+    @GetMapping("/all/students")
+    @ApiOperation(value = "全校学生能力")
+    public BaseResponse getAllStudents(){
+        return capacityService.getAllStudents();
+    }
+
 }

+ 1 - 4
src/main/java/com/chuanghai/student_portrait/controller/ForewarningController.java

@@ -24,8 +24,5 @@ public class ForewarningController {
         return forewarningService.getgetForewarning(keyWord, startTime, endTime,page,size);
     }
 
-//    @PostMapping("/add")
-//    public Boolean saveForewarningAccess(){
-//        return forewarningService.saveForewarningAccess();
-//    }
+
 }

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

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

+ 9 - 0
src/main/java/com/chuanghai/student_portrait/entity/dto/CapacityDto.java

@@ -0,0 +1,9 @@
+package com.chuanghai.student_portrait.entity.dto;
+
+import lombok.Data;
+
+@Data
+public class CapacityDto {
+    private String name;
+    private Double max;
+}

+ 6 - 1
src/main/java/com/chuanghai/student_portrait/service/CapacityService.java

@@ -2,7 +2,12 @@ package com.chuanghai.student_portrait.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.chuanghai.student_portrait.entity.Capacity;
+import com.chuanghai.student_portrait.response.BaseResponse;
 
 public interface CapacityService extends IService<Capacity> {
-    void saveHealthCapacity();
+
+    BaseResponse getOneStudent(String id);
+
+    BaseResponse getAllStudents();
+
 }

+ 1 - 1
src/main/java/com/chuanghai/student_portrait/service/ForewarningService.java

@@ -13,5 +13,5 @@ public interface ForewarningService extends IService<Forewarning> {
 
     BaseResponse getgetForewarning(String keyWord, String startTime, String endTime,Integer page, Integer size);
 
-    Boolean saveForewarningAccess();
+
 }

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

@@ -62,8 +62,8 @@ public class AccessServiceImpl extends ServiceImpl<AccessMapper, Access> impleme
     /**
      * 每3小时拉取一次门禁的数据
      */
-//    @Scheduled(cron = "0 0 0/3 * * ? ")
-//    @Scheduled(cron = "0 0/2 * * * ? ")
+    @Scheduled(cron = "0 0 0/3 * * ? ")
+//    @Scheduled(cron = "0 0/3 * * * ? ")
     public void autoQueryOrder() {
         getQRCode();
     }
@@ -182,14 +182,6 @@ public class AccessServiceImpl extends ServiceImpl<AccessMapper, Access> impleme
         return exists;
     }
 
-    public static void main(String[] args) {
-        String s = "墨轩湖大门门禁(10)";
-        String s2 = "墨轩湖大门门禁(1)";
-        int i = Integer.parseInt(s.substring(8, s.length() - 1));
-        System.out.println("i = " + i);
-        String substring1 = s2.substring(8, s2.length() - 1);
-        System.out.println("substring1 = " + substring1);
 
-    }
 
 }

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

@@ -14,7 +14,7 @@ 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 com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Scheduled;
@@ -48,7 +48,7 @@ public class AffinityScoreServiceImpl extends ServiceImpl<AffinityScoreMapper, A
         return BaseResponse.ok(StatusEnum.SUCCESS, list);
     }
 
-    @Scheduled(cron = "0 29 17 * * ? ")
+    @Scheduled(cron = "0 2 23 * * ? ")
     public void saveAndUpdateFaceAffinityScore() {
         DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
         LocalDateTime now = LocalDateTime.now();
@@ -110,7 +110,7 @@ public class AffinityScoreServiceImpl extends ServiceImpl<AffinityScoreMapper, A
 
     }
 
-    @Scheduled(cron = "0 34 17 * * ? ")
+    @Scheduled(cron = "0 4 23 * * ? ")
     public void saveAndUpdateConsumeAffinityScore() {
         DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
         LocalDateTime now = LocalDateTime.now();

+ 338 - 15
src/main/java/com/chuanghai/student_portrait/service/impl/CapacityServiceImpl.java

@@ -1,22 +1,24 @@
 package com.chuanghai.student_portrait.service.impl;
 
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 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.entity.*;
+import com.chuanghai.student_portrait.entity.dto.CapacityDto;
 import com.chuanghai.student_portrait.mapper.CapacityMapper;
+import com.chuanghai.student_portrait.response.BaseResponse;
+import com.chuanghai.student_portrait.response.enums.StatusEnum;
 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.scheduling.annotation.Scheduled;
 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;
+import java.util.*;
 
 @Service
 public class CapacityServiceImpl extends ServiceImpl<CapacityMapper, Capacity> implements CapacityService {
@@ -36,8 +38,12 @@ public class CapacityServiceImpl extends ServiceImpl<CapacityMapper, Capacity> i
     @Autowired
     ForewarningService forewarningService;
 
-    @Override
-//    @Transactional(rollbackFor = Exception.class)
+    @Autowired
+    AffinityScoreService affinityScoreService;
+
+    //健康
+    //  一月一次
+    @Scheduled(cron = "0 27 23 2 * ? ")
     public void saveHealthCapacity() {
 //        DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
         String startTime = startTime();
@@ -61,12 +67,13 @@ public class CapacityServiceImpl extends ServiceImpl<CapacityMapper, Capacity> i
 
             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 != "") {
+                if (ObjectUtils.isNotEmpty(idCard)) {
                     String capacityName = "健康";
                     Capacity capacity = getCapacity(idCard, capacityName, startTime);
                     if (ObjectUtils.isNotEmpty(capacity)) {
@@ -94,7 +101,7 @@ public class CapacityServiceImpl extends ServiceImpl<CapacityMapper, Capacity> i
             }
             for (Consume consume : list2) {
                 String idCard = consume.getIdCard();
-                if (idCard != null && idCard != "") {
+                if (ObjectUtils.isNotEmpty(idCard)) {
                     String capacityName = "健康";
                     Capacity capacity = getCapacity(idCard, capacityName, startTime);
                     if (ObjectUtils.isNotEmpty(capacity)) {
@@ -122,7 +129,7 @@ public class CapacityServiceImpl extends ServiceImpl<CapacityMapper, Capacity> i
             }
             for (Consume consume : list3) {
                 String idCard = consume.getIdCard();
-                if (idCard != null && idCard != "") {
+                if (ObjectUtils.isNotEmpty(idCard)) {
                     String capacityName = "健康";
                     Capacity capacity = getCapacity(idCard, capacityName, startTime);
                     if (ObjectUtils.isNotEmpty(capacity)) {
@@ -152,6 +159,216 @@ public class CapacityServiceImpl extends ServiceImpl<CapacityMapper, Capacity> i
 
     }
 
+    //爱动
+    @Scheduled(cron = "0 32 23 2 * ? ")
+    public void saveExerciseCapacity() {
+        String startTime = startTime();
+        String endTime = endTime();
+        List<FaceDiscern> list = faceDiscernService.list(Wrappers.<FaceDiscern>lambdaQuery().between(FaceDiscern::getFacediscernTime, startTime, endTime)
+                .select(FaceDiscern::getShooluserId).groupBy(FaceDiscern::getShooluserId));
+        for (FaceDiscern faceDiscern : list) {
+            String shooluserId = faceDiscern.getShooluserId();
+            int size = faceDiscernService.list(Wrappers.<FaceDiscern>lambdaQuery().between(FaceDiscern::getFacediscernTime, startTime, endTime).eq(FaceDiscern::getShooluserId, shooluserId)).size();
+            if (ObjectUtils.isNotEmpty(shooluserId)) {
+                String capacityName = "爱动";
+                Capacity capacity = getCapacity(shooluserId, capacityName, startTime);
+                if (ObjectUtils.isNotEmpty(capacity)) {
+                    String units = capacity.getUnits();
+                    int i1 = Integer.parseInt(units);
+                    int un = i1 + size;
+                    String s = String.valueOf(un);
+                    capacity.setUnits(s);
+                    this.updateById(capacity);
+                } else {
+                    Capacity capacity1 = new Capacity();
+                    capacity1.setCapacityName(capacityName);
+                    capacity1.setSchooluserId(shooluserId);
+                    Date date = null;
+                    try {
+                        date = DateUtils.stringToDate(startTime);
+                    } catch (Exception e) {
+                        throw new RuntimeException(e);
+                    }
+                    capacity1.setDateTime(date);
+                    capacity1.setUnits(size + "");
+                    this.save(capacity1);
+                }
+            }
+        }
+        List<Access> list1 = accessService.list(Wrappers.<Access>lambdaQuery().between(Access::getAccessTime, startTime, endTime)
+                .select(Access::getCardNumber).groupBy(Access::getCardNumber));
+        for (Access access : list1) {
+            String cardNumber = access.getCardNumber();
+            int size = accessService.list(Wrappers.<Access>lambdaQuery().between(Access::getAccessTime, startTime, endTime).eq(Access::getCardNumber, cardNumber)).size();
+            if (ObjectUtils.isNotEmpty(cardNumber)) {
+                String capacityName = "爱动";
+                Capacity capacity = getCapacity(cardNumber, capacityName, startTime);
+                if (ObjectUtils.isNotEmpty(capacity)) {
+                    String units = capacity.getUnits();
+                    int i1 = Integer.parseInt(units);
+                    int un = i1 + size;
+                    String s = String.valueOf(un);
+                    capacity.setUnits(s);
+                    this.updateById(capacity);
+                } else {
+                    Capacity capacity1 = new Capacity();
+                    capacity1.setCapacityName(capacityName);
+                    capacity1.setSchooluserId(cardNumber);
+                    Date date = null;
+                    try {
+                        date = DateUtils.stringToDate(startTime);
+                    } catch (Exception e) {
+                        throw new RuntimeException(e);
+                    }
+                    capacity1.setDateTime(date);
+                    capacity1.setUnits(size + "");
+                    this.save(capacity1);
+                }
+            }
+        }
+    }
+
+    //安全
+    @Scheduled(cron = "0 34 23 2 * ? ")
+    public void saveSafetyCapacity() {
+        String startTime = startTime();
+        String endTime = endTime();
+        List<Forewarning> list = forewarningService.list(Wrappers.<Forewarning>lambdaQuery().between(Forewarning::getDateTime, startTime, endTime));
+        for (Forewarning forewarning : list) {
+            String schooluserId = forewarning.getSchooluserId();
+            if (ObjectUtils.isNotEmpty(schooluserId)) {
+                String capacityName = "安全";
+                Capacity capacity = getCapacity(schooluserId, 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(schooluserId);
+                    Date date = null;
+                    try {
+                        date = DateUtils.stringToDate(startTime);
+                    } catch (Exception e) {
+                        throw new RuntimeException(e);
+                    }
+                    capacity1.setDateTime(date);
+                    capacity1.setUnits("1");
+                    this.save(capacity1);
+                }
+            }
+        }
+    }
+
+    //消费
+    @Scheduled(cron = "0 40 23 2 * ? ")
+    public void saveConsumeCapacity() {
+        String startTime = startTime();
+        String endTime = endTime();
+        List<Consume> list = consumeService.list(Wrappers.<Consume>lambdaQuery().between(Consume::getConsumeTime, startTime, endTime));
+        for (Consume consume : list) {
+            String consumeAmount = consume.getConsumeAmount();
+            double parseDouble = Double.parseDouble(consumeAmount);
+            String schooluserId = consume.getIdCard();
+            if (ObjectUtils.isNotEmpty(schooluserId)) {
+                String capacityName = "消费";
+                Capacity capacity = getCapacity(schooluserId, capacityName, startTime);
+                if (ObjectUtils.isNotEmpty(capacity)) {
+                    String units = capacity.getUnits();
+                    double parseDouble2 = Double.parseDouble(units);
+                    double un = parseDouble + parseDouble2;
+                    String s = String.valueOf(un);
+                    capacity.setUnits(s);
+                    this.updateById(capacity);
+                } else {
+                    Capacity capacity1 = new Capacity();
+                    capacity1.setCapacityName(capacityName);
+                    capacity1.setSchooluserId(schooluserId);
+                    Date date = null;
+                    try {
+                        date = DateUtils.stringToDate(startTime);
+                    } catch (Exception e) {
+                        throw new RuntimeException(e);
+                    }
+                    capacity1.setDateTime(date);
+                    capacity1.setUnits(consumeAmount);
+                    this.save(capacity1);
+                }
+            }
+        }
+
+        List<HotWater> hotWaters = hotWaterService.list(Wrappers.<HotWater>lambdaQuery().between(HotWater::getHotwaterTime, startTime, endTime));
+        for (HotWater hotWater : hotWaters) {
+            String consumeAmount = hotWater.getHotwaterAmount();
+            double parseDouble = Double.parseDouble(consumeAmount);
+            String schooluserId = hotWater.getCardNumber();
+            if (ObjectUtils.isNotEmpty(schooluserId)) {
+                String capacityName = "消费";
+                Capacity capacity = getCapacity(schooluserId, capacityName, startTime);
+                if (ObjectUtils.isNotEmpty(capacity)) {
+                    String units = capacity.getUnits();
+                    double parseDouble2 = Double.parseDouble(units);
+                    double un = parseDouble + parseDouble2;
+                    String s = String.valueOf(un);
+                    capacity.setUnits(s);
+                    this.updateById(capacity);
+                } else {
+                    Capacity capacity1 = new Capacity();
+                    capacity1.setCapacityName(capacityName);
+                    capacity1.setSchooluserId(schooluserId);
+                    Date date = null;
+                    try {
+                        date = DateUtils.stringToDate(startTime);
+                    } catch (Exception e) {
+                        throw new RuntimeException(e);
+                    }
+                    capacity1.setDateTime(date);
+                    capacity1.setUnits(consumeAmount);
+                    this.save(capacity1);
+                }
+            }
+        }
+
+    }
+
+    //关系
+    @Scheduled(cron = "0 44 23 2 * ? ")
+    public void saveAffinityScoreCapacity() {
+        String startTime = startTime();
+        String endTime = endTime();
+        List<AffinityScore> affinityScores = affinityScoreService.list(Wrappers.<AffinityScore>lambdaQuery().select(AffinityScore::getSchooluserId).groupBy(AffinityScore::getSchooluserId));
+        for (AffinityScore affinityScore : affinityScores) {
+            String schooluserId = affinityScore.getSchooluserId();
+            String capacityName = "关系";
+            Capacity capacity = getCapacity(schooluserId, capacityName, startTime);
+            if (ObjectUtils.isEmpty(capacity)) {
+                Capacity capacity1 = new Capacity();
+                capacity1.setCapacityName(capacityName);
+                capacity1.setSchooluserId(schooluserId);
+                Date date = null;
+                try {
+                    date = DateUtils.stringToDate(startTime);
+                } catch (Exception e) {
+                    throw new RuntimeException(e);
+                }
+                capacity1.setDateTime(date);
+                List<AffinityScore> list = affinityScoreService.list(Wrappers.<AffinityScore>lambdaQuery().eq(AffinityScore::getSchooluserId, schooluserId));
+                int units = 0;
+                for (AffinityScore score : list) {
+                    Integer count = score.getCount();
+                    units = units + count;
+                }
+                capacity1.setUnits(units + "");
+                this.save(capacity1);
+            }
+        }
+    }
+
+
     public static String startTime() {
         DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
         LocalDateTime now = LocalDateTime.now();
@@ -174,13 +391,119 @@ public class CapacityServiceImpl extends ServiceImpl<CapacityMapper, Capacity> i
         return one;
     }
 
+    //    健康,爱动,消费,关系的平均数
+    public CapacityDto getAverage(String name) {
+        String s = startTime();
+
+        CapacityDto capacityDto = new CapacityDto();
+        List<Capacity> list = this.list(Wrappers.<Capacity>lambdaQuery().eq(Capacity::getDateTime, s).eq(Capacity::getCapacityName,name));
+        Double healthAverage = 0.0;
+        for (Capacity capacity : list) {
+            String units = capacity.getUnits();
+            double v = Double.parseDouble(units);
+            healthAverage = healthAverage + v;
+        }
+        capacityDto.setName(name);
+        capacityDto.setMax(Math.ceil(healthAverage / list.size()));
+
+        return capacityDto;
+    }
+
+    public CapacityDto getCapacityDto(String id, String name) {
+        String s = startTime();
+        Capacity capacity = this.getOne(Wrappers.<Capacity>lambdaQuery().eq(Capacity::getSchooluserId, id).eq(Capacity::getDateTime, s).eq(Capacity::getCapacityName, name));
+        CapacityDto capacityDto = new CapacityDto();
+        capacityDto.setName(name);
+        if (ObjectUtils.isNotEmpty(capacity)) {
+            capacityDto.setMax(Double.parseDouble(capacity.getUnits()));
+        } else {
+            capacityDto.setMax(Math.ceil(0));
+        }
+        return capacityDto;
+    }
 
-    public static void main(String[] args) throws Exception {
-        String id = null;
-        if (ObjectUtils.isNotEmpty(id)) {
-            System.out.println(true);
+    @Override
+    public BaseResponse getOneStudent(String id) {
+        if (ObjectUtils.isEmpty(id)) {
+            return BaseResponse.error(StatusEnum.FAIL, "参数异常");
         }
+        String s = startTime();
+        String health = "健康";
+        String exercise = "爱动";
+        String consume = "消费";
+        String affinityScore = "关系";
+        String safety = "安全";
+        List<CapacityDto> averages = new ArrayList<>();
+        CapacityDto average = getAverage(health);
+        CapacityDto average1 = getAverage(exercise);
+        CapacityDto average2 = getAverage(consume);
+        CapacityDto average3 = getAverage(affinityScore);
+
+        CapacityDto average4 = new CapacityDto();
+        average4.setName("安全");
+        average4.setMax(Math.ceil(30.0));
+        averages.add(average);
+        averages.add(average1);
+        averages.add(average2);
+        averages.add(average3);
+        averages.add(average4);
+//健康
+        Double max = average.getMax();
+//        爱动
+        Double max1 = average1.getMax();
+//        安全
+        Double max2 = average4.getMax();
+        CapacityDto capacityDto = new CapacityDto();
+        capacityDto.setName("尽责心");
+        capacityDto.setMax(max+max1+max2);
+        averages.add(capacityDto);
 
+        HashMap<String, Object> map = new HashMap<>();
+        ArrayList<CapacityDto> capacityDtos = new ArrayList<>();
+
+        CapacityDto capacityDto1 = getCapacityDto(id, health);
+        CapacityDto capacityDto2 = getCapacityDto(id, exercise);
+        CapacityDto capacityDto3 = getCapacityDto(id, consume);
+        CapacityDto capacityDto4 = getCapacityDto(id, affinityScore);
+        CapacityDto capacityDto5 = getCapacityDto(id, safety);
+//      健康
+        Double max3 = capacityDto1.getMax();
+
+        if (max3>max) {
+            max3=max;
+        }
+//        爱动
+        Double max4 = capacityDto2.getMax();
+        if (max4>max1) {
+            max4=max1;
+        }
+//        安全
+        Double max5 = capacityDto5.getMax();
+        Double max6=30-max5;
+        if (max6<0) {
+            max6=0.0;
+        }
+        CapacityDto capacityDto6 = new CapacityDto();
+        capacityDto6.setName("尽责心");
+        capacityDto6.setMax(max3+max4+max6);
+
+        capacityDtos.add(capacityDto1);
+        capacityDtos.add(capacityDto2);
+        capacityDtos.add(capacityDto3);
+        capacityDtos.add(capacityDto4);
+        capacityDtos.add(capacityDto5);
+        capacityDtos.add(capacityDto6);
+
+        map.put("average", averages);
+        map.put("list", capacityDtos);
+        return BaseResponse.ok(StatusEnum.SUCCESS, map);
+    }
+
+    @Override
+    public BaseResponse getAllStudents() {
+
+        return null;
     }
 
+
 }

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

@@ -31,12 +31,12 @@ public class ColdWaterServiceImpl extends ServiceImpl<ColdWaterMapper, ColdWater
 
     @Autowired
     DormService dormService;
-    private static String url = "https://jtishfw.ncjti.edu.cn/jxch-smartmp/HotWaters/cwaterMonthlist.action";
+    private static String url = "http://192.168.1.34:8080/HotWaters/cwaterMonthlist.action";
     private Integer page = 1;
     private Integer size = 8;
 
     //    20秒钟运行一次
-//    @Scheduled(cron = "0/20 * * * * ?  ")
+    @Scheduled(cron = "0/20 0 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17 1 * ? ")
     public void autoQueryOrder() {
         Page<Dorm> dormPage = dormService.page(new Page<Dorm>(page, size));
         List<Dorm> records = dormPage.getRecords();

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

@@ -231,7 +231,7 @@ public class ConsumeServicelmpl extends ServiceImpl<ConsumeMapper, Consume> impl
     }
 
 
-    //    @Scheduled(cron = "0 0 0/2 * * ? ")
+//    @Scheduled(cron = "0 0 0/2 * * ? ")
     @Scheduled(cron = "0 0/2 * * * ? ")
     public void autoQueryOrder() {
 

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

@@ -51,7 +51,7 @@ public class ElectricityServiceImpl extends ServiceImpl<ElectricityMapper, Elect
     @Autowired
     ColdWaterService coldWaterService;
 
-    private static String url = "https://jtishfw.ncjti.edu.cn/jxch-smartmp/HotWaters/elMonthlist.action";
+    private static String url = "http://192.168.1.34:8080/HotWaters/elMonthlist.action";
 
     private Integer page = 1;
 
@@ -162,7 +162,7 @@ public class ElectricityServiceImpl extends ServiceImpl<ElectricityMapper, Elect
 
 
 
-//    @Scheduled(cron = "0/30 * * * * ? ")
+    @Scheduled(cron = "0/30 0 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17 1 * ? ")
     public void autoQueryOrder() {
         Page<Dorm> dormPage = dormService.page(new Page<Dorm>(page, size));
         List<Dorm> records = dormPage.getRecords();

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

@@ -19,7 +19,7 @@ import com.chuanghai.student_portrait.utils.*;
 import com.chuanghai.student_portrait.utils.vo.UniviewVO;
 import com.fasterxml.jackson.core.type.TypeReference;
 import com.fasterxml.jackson.databind.ObjectMapper;
-import org.apache.commons.lang3.ObjectUtils;
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.impl.client.HttpClients;
 import org.apache.http.util.EntityUtils;
@@ -208,7 +208,7 @@ public class FaceDiscernServiceImpl extends ServiceImpl<FaceDiscernMapper, FaceD
                     if ("U".equals(faceDiscern.getFacediscernType())) {
                         int e = pictureScene.indexOf("e");
                         String substring = pictureScene.substring(e + 1);
-                        pictureScene="http://192.168.161.207:8085/"+substring;
+                        pictureScene="http://192.168.161.100:8085/"+substring;
                     }
                     dto.setImage(pictureScene);
                 }

+ 121 - 139
src/main/java/com/chuanghai/student_portrait/service/impl/ForewarningServiceImpl.java

@@ -83,32 +83,15 @@ public class ForewarningServiceImpl extends ServiceImpl<ForewarningMapper, Forew
     }
 
 
-    //指定每天3点统一添加(除冷水,电费)
-//    @Scheduled(cron = "0 0 3 * * ? ")
-    @Scheduled(cron = "0 0/2 * * * ? ")
-    public void saveBatchForewarning() {
-        this.addForewarning();
-        this.saveForewarningAccess();
-        saveForewarningHotWater();
-        saveForewarningConsume();
-        saveForewarningDormAccess();
-    }
-
-//    指定每月的第一天
 
-    //    @Scheduled(cron = "0 0 0 1 * ? ")
-//        @Scheduled(cron = "0 0/2 * * * ? ")
-    public void saveBatchForewarningColdWaterAndElecticity() {
-        saveForewarningColdWater();
-        saveForewarningElectricity();
-    }
 
     /**
      * 人脸
      *
      * @return
      */
-    public Boolean addForewarning() {
+    @Scheduled(cron = "0 6 23 ? * ? ")
+    public void addForewarning() {
         DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
         LocalDateTime now = LocalDateTime.now();
         LocalDateTime start = now.withHour(0).withMinute(0).withSecond(0);
@@ -158,27 +141,27 @@ public class ForewarningServiceImpl extends ServiceImpl<ForewarningMapper, Forew
                     forewarning.setClazz(clazz);
 
                     forewarning.setSchooluserId(shooluserId);
-
+                    forewarning.setRemark("异常");
 //                判断该数据是否已添加
                     Boolean exists = queryForewarningExists(name, date, "出校未归");
                     if (!exists) {
-                        forewarnings.add(forewarning);
+                        this.save(forewarning);
                     }
                 }
                 }
             }
         }
-        boolean b = this.saveBatch(forewarnings);
-        return b;
+
     }
 
-    @Override
+
     /**
      * 扫码门禁
      *
      * @return
      */
-    public Boolean saveForewarningAccess() {
+    @Scheduled(cron = "0 8 23 ? * ? ")
+    public void saveForewarningAccess() {
         DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
         LocalDateTime now = LocalDateTime.now();
         LocalDateTime start = now.withHour(0).withMinute(0).withSecond(0);
@@ -229,124 +212,34 @@ public class ForewarningServiceImpl extends ServiceImpl<ForewarningMapper, Forew
                     forewarning.setClazz(clazz);
 
                     forewarning.setSchooluserId(cardNumber);
+                    forewarning.setRemark("异常");
 
 //                判断该数据是否已添加
                     Boolean exists = queryForewarningExists(name, date, "出校未归");
                     if (!exists) {
-                        forewarnings.add(forewarning);
+                        this.save(forewarning);
                     }
                 }
                 }
             }
         }
-        boolean b = this.saveBatch(forewarnings);
-        return b;
-    }
-
-    /**
-     * 冷水消费预警
-     *
-     * @return
-     */
-    public Boolean saveForewarningColdWater() {
-//        获取时间
-        DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM");
-        LocalDateTime now = LocalDateTime.now();
-        String date = now.minusMonths(1).format(pattern);
-//取消费前100条做预警
-        List<ColdWater> coldWaterList = coldWaterService.list(Wrappers.<ColdWater>lambdaQuery()
-                .eq(ColdWater::getDataTime, date)
-                .orderByDesc(ColdWater::getTotalMoney)
-        );
-
-        ArrayList<Forewarning> forewarningList = new ArrayList<>();
-        for (int i = 0; i < 100; i++) {
-            ColdWater coldWater = coldWaterList.get(i);
-
-            Forewarning forewarning = new Forewarning();
-//            获取宿舍号
-            String dom = coldWater.getDom();
-            forewarning.setName(dom);
-
-//            每个月的1号的时间定上个月的水费超额预警时间
-            DateTimeFormatter pattern1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
-            String dateTime = now.withDayOfMonth(1).withHour(1).withMinute(1).withSecond(1).format(pattern1);
-            Date date1;
-            try {
-                date1 = DateUtils.stringToDate(dateTime);
-            } catch (Exception e) {
-                throw new RuntimeException(e);
-            }
-            forewarning.setDateTime(date1);
-            forewarning.setWarningReason("冷水消费异常");
 
-            forewarning.setRemark(coldWater.getTotalPower()+"");
-            Boolean exists = queryForewarningExists(dom, date1, "冷水消费异常");
-            if (!exists) {
-                forewarningList.add(forewarning);
-            }
-        }
-        boolean b = this.saveBatch(forewarningList);
-        return b;
     }
 
-    /**
-     * 电费消费预警
-     *
-     * @return
-     */
-
-    public Boolean saveForewarningElectricity() {
-//        获取时间
-        DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM");
-        LocalDateTime now = LocalDateTime.now();
-        String date = now.minusMonths(1).format(pattern);
-//超过300度电就预警
-        List<Electricity> electricitieList = electricityService.list(Wrappers.<Electricity>lambdaQuery()
-                .eq(Electricity::getDateTime, date)
-                .orderByDesc(Electricity::getTotalMoney)
-        );
-        ArrayList<Forewarning> forewarningList = new ArrayList<>();
-        for (int i = 0; i < 100; i++) {
-            Electricity electricity = electricitieList.get(i);
-            Forewarning forewarning = new Forewarning();
-//            获取宿舍号
-            String dom = electricity.getDom();
-            forewarning.setName(dom);
-
-//            每个月的1号的时间定上个月的水费超额预警时间
-            DateTimeFormatter pattern1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
-            String dateTime = now.withDayOfMonth(1).withHour(1).withMinute(1).withSecond(1).format(pattern1);
-            Date date1;
-            try {
-                date1 = DateUtils.stringToDate(dateTime);
-            } catch (Exception e) {
-                throw new RuntimeException(e);
-            }
-            forewarning.setDateTime(date1);
-            forewarning.setWarningReason("电费消费异常");
-            forewarning.setRemark(electricity.getTotalPower()+"");
-            Boolean exists = queryForewarningExists(dom, date1, "电费消费异常");
-            if (!exists) {
-                forewarningList.add(forewarning);
-            }
-        }
-        boolean b = this.saveBatch(forewarningList);
-        return b;
-    }
 
     /**
      * 热水消费预警
      *
      * @return
      */
-    public Boolean saveForewarningHotWater() {
+    @Scheduled(cron = "0 10 23 ? * ? ")
+    public void saveForewarningHotWater() {
         String startTime = getStartTime();
         String endTime = getEndTime();
 
         List<HotWater> hotWaterList = hotWaterService.list(Wrappers.<HotWater>lambdaQuery()
                 .between(HotWater::getHotwaterTime, startTime, endTime)
-                .ge(HotWater::getHotwaterAmount, 10)
+                .ge(HotWater::getHotwaterAmount, 5)
         );
         ArrayList<Forewarning> forewarnings = new ArrayList<>();
         if (ObjectUtils.isNotEmpty(hotWaterList) && hotWaterList.size() > 0) {
@@ -371,16 +264,15 @@ public class ForewarningServiceImpl extends ServiceImpl<ForewarningMapper, Forew
                 forewarning.setClazz(clazz);
                 forewarning.setDateTime(hotwaterTime);
                 forewarning.setWarningReason("热水消费异常");
-                forewarning.setRemark(hotWater.getHotwaterAmount());
+                forewarning.setRemark(hotWater.getHotwaterAmount()+"元");
                 forewarning.setSchooluserId(cardNumber);
                 Boolean exists = queryForewarningExists(name, hotwaterTime, "热水消费异常");
                 if (!exists) {
-                    forewarnings.add(forewarning);
+                    this.save(forewarning);
                 }
             }
         }
-        boolean b = this.saveBatch(forewarnings);
-        return b;
+
 
     }
 
@@ -390,17 +282,16 @@ public class ForewarningServiceImpl extends ServiceImpl<ForewarningMapper, Forew
      *
      * @return
      */
-    public Boolean saveForewarningConsume() {
+    @Scheduled(cron = "0 12 23 ? * ? ")
+    public void saveForewarningConsume() {
         String startTime = getStartTime();
         String endTime = getEndTime();
 
         List<Consume> consumeList = consumeService.list(Wrappers.<Consume>lambdaQuery()
                 .between(Consume::getConsumeTime, startTime, endTime)
-                .ge(Consume::getConsumeAmount, 50)
+                .ge(Consume::getConsumeAmount, 30)
         );
-        ArrayList<Forewarning> forewarnings = new ArrayList<>();
         if (ObjectUtils.isNotEmpty(consumeList) && consumeList.size() > 0) {
-
             for (Consume consume : consumeList) {
                 String schoolId = consume.getIdCard();
                 NewSchooluser schooluser = newSchooluserService.getById(schoolId);
@@ -422,16 +313,15 @@ public class ForewarningServiceImpl extends ServiceImpl<ForewarningMapper, Forew
                 forewarning.setClazz(clazz);
                 forewarning.setDateTime(consumeTime);
                 forewarning.setWarningReason("食堂消费过高");
-                forewarning.setRemark(consume.getConsumeAmount());
+                forewarning.setRemark(consume.getConsumeAmount()+"元");
                 forewarning.setSchooluserId(schoolId);
                 Boolean exists = queryForewarningExists(name, consumeTime, "食堂消费过高");
                 if (!exists) {
-                    forewarnings.add(forewarning);
+                   this.save(forewarning);
                 }
             }
         }
-        boolean b = this.saveBatch(forewarnings);
-        return b;
+
     }
 
     /**
@@ -439,7 +329,8 @@ public class ForewarningServiceImpl extends ServiceImpl<ForewarningMapper, Forew
      *
      * @return
      */
-    public Boolean saveForewarningDormAccess() {
+    @Scheduled(cron = "0 14 23 ? * ? ")
+    public void saveForewarningDormAccess() {
         String startTime = getStartTime();
         String endTime = getEndTime();
         DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
@@ -452,8 +343,7 @@ public class ForewarningServiceImpl extends ServiceImpl<ForewarningMapper, Forew
         ArrayList<Forewarning> forewarnings = new ArrayList<>();
 //        人脸部分
         List<FaceDiscern> faceDiscerns = faceDiscernService.list(Wrappers.<FaceDiscern>lambdaQuery()
-                .between(FaceDiscern::getFacediscernTime, startTime, endTime)
-                .ge(FaceDiscern::getFacediscernTime, dateTime)
+                .between(FaceDiscern::getFacediscernTime,  dateTime, endTime)
                 .like(FaceDiscern::getFacediscernAddress, "学生")
         );
         if (ObjectUtils.isNotEmpty(forewarnings) && forewarnings.size() > 0) {
@@ -479,9 +369,10 @@ public class ForewarningServiceImpl extends ServiceImpl<ForewarningMapper, Forew
                 forewarning.setDateTime(facediscernTime);
                 forewarning.setWarningReason("归寝异常");
                 forewarning.setSchooluserId(shooluserId);
+                forewarning.setRemark("异常");
                 Boolean exists = queryForewarningExists(name, facediscernTime, "归寝异常");
                 if (!exists) {
-                    forewarnings.add(forewarning);
+                    this.save(forewarning);
                 }
             }
         }
@@ -514,14 +405,105 @@ public class ForewarningServiceImpl extends ServiceImpl<ForewarningMapper, Forew
                 forewarning.setDateTime(accessTime);
                 forewarning.setWarningReason("归寝异常");
                 forewarning.setSchooluserId(shooluserId);
+                forewarning.setRemark("异常");
                 Boolean exists = queryForewarningExists(name, accessTime, "归寝异常");
                 if (!exists) {
-                    forewarnings.add(forewarning);
+                    this.save(forewarning);
                 }
             }
         }
-        boolean b = this.saveBatch(forewarnings);
-        return b;
+
+    }
+
+    /**
+     * 冷水消费预警
+     *一个月一次
+     * @return
+     */
+    @Scheduled(cron = "0 20 23 1 * ? ")
+    public void saveForewarningColdWater() {
+//        获取时间
+        DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM");
+        LocalDateTime now = LocalDateTime.now();
+        String date = now.minusMonths(1).format(pattern);
+//取消费前100条做预警
+        List<ColdWater> coldWaterList = coldWaterService.list(Wrappers.<ColdWater>lambdaQuery()
+                .eq(ColdWater::getDataTime, date)
+                .orderByDesc(ColdWater::getTotalMoney)
+        );
+
+        ArrayList<Forewarning> forewarningList = new ArrayList<>();
+        for (int i = 0; i < 100; i++) {
+            ColdWater coldWater = coldWaterList.get(i);
+
+            Forewarning forewarning = new Forewarning();
+//            获取宿舍号
+            String dom = coldWater.getDom();
+            forewarning.setName(dom);
+
+//            每个月的1号的时间定上个月的水费超额预警时间
+            DateTimeFormatter pattern1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+            String dateTime = now.withDayOfMonth(1).withHour(1).withMinute(1).withSecond(1).format(pattern1);
+            Date date1;
+            try {
+                date1 = DateUtils.stringToDate(dateTime);
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+            forewarning.setDateTime(date1);
+            forewarning.setWarningReason("冷水消费异常");
+
+            forewarning.setRemark(coldWater.getTotalMoney()+"元");
+            Boolean exists = queryForewarningExists(dom, date1, "冷水消费异常");
+            if (!exists) {
+                this.save(forewarning);
+            }
+        }
+
+    }
+
+    /**
+     * 电费消费预警
+     *一个月一次
+     * @return
+     */
+    @Scheduled(cron = "0 25 23 1 * ? ")
+    public void saveForewarningElectricity() {
+//        获取时间
+        DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM");
+        LocalDateTime now = LocalDateTime.now();
+        String date = now.minusMonths(1).format(pattern);
+//超过300度电就预警
+        List<Electricity> electricitieList = electricityService.list(Wrappers.<Electricity>lambdaQuery()
+                .eq(Electricity::getDateTime, date)
+                .orderByDesc(Electricity::getTotalMoney)
+        );
+        ArrayList<Forewarning> forewarningList = new ArrayList<>();
+        for (int i = 0; i < 100; i++) {
+            Electricity electricity = electricitieList.get(i);
+            Forewarning forewarning = new Forewarning();
+//            获取宿舍号
+            String dom = electricity.getDom();
+            forewarning.setName(dom);
+
+//            每个月的1号的时间定上个月的水费超额预警时间
+            DateTimeFormatter pattern1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+            String dateTime = now.withDayOfMonth(1).withHour(1).withMinute(1).withSecond(1).format(pattern1);
+            Date date1;
+            try {
+                date1 = DateUtils.stringToDate(dateTime);
+            } catch (Exception e) {
+                throw new RuntimeException(e);
+            }
+            forewarning.setDateTime(date1);
+            forewarning.setWarningReason("电费消费异常");
+            forewarning.setRemark(electricity.getTotalMoney()+"元");
+            Boolean exists = queryForewarningExists(dom, date1, "电费消费异常");
+            if (!exists) {
+                this.save(forewarning);
+            }
+        }
+
     }
 
     /**

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

@@ -327,28 +327,7 @@ public class HotWaterServiceImpl extends ServiceImpl<HotWaterMapper, HotWater> i
         return gender;
     }
 
-    public static void main(String[] args) {
-        String s = "4#教职工2-102";
-        String[] split = s.split("-");
-        String s3 = split[0];
-        String[] girl = {"1", "2", "3", "4", "5", "6"};
-        String[] boy = {"7", "8", "9", "10", "11", "12", "13", "14", "15"};
-        String gender = "";
-        for (int i = 0; i < girl.length; i++) {
-            if (s3.equals(girl[i])) {
-                gender = "女";
-            }
-        }
-        for (int i = 0; i < boy.length; i++) {
-            if (s3.equals(boy[i])) {
-                gender = "男";
-            }
-        }
-        System.out.println("gender = " + gender);
-        for (int i = 0; i < 5; i++) {
-            System.out.println(getDateTime(i));
-        }
-    }
+
 
     public static String getDateTime(int i) {
         DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
@@ -439,7 +418,7 @@ public class HotWaterServiceImpl extends ServiceImpl<HotWaterMapper, HotWater> i
      * 从0点到点,每30分钟拉取一次热水数据
      */
 //    @Scheduled(cron = "0 0/30 0,1,2,3,4,5,6 * * ? ")
-//    @Scheduled(cron = "0 0/2 * * * ? ")
+    @Scheduled(cron = "0 0/2 * * * ? ")
     public void autoQueryOrder() {
         try {
             DateUtils dateUtils = new DateUtils();

+ 1 - 1
src/main/resources/application.yml

@@ -72,7 +72,7 @@ decisionEngine:
     #二维码的门禁记录服务地址
     qrcode: https://chtech.ncjti.edu.cn/access-control/ncjtEntranceGuard/getTrafficRecordViewPageList
     #热水使用记录
-    waterUrl: https://jtishfw.ncjti.edu.cn/jxch-smartmp/HotWaters/waterfindConsume.action
+    waterUrl: http://192.168.1.34:8080/HotWaters/waterfindConsume.action
   nvr:
     nvrip: 172.22.45.25
     nvrport: 80

+ 1 - 1
target/classes/application.yml

@@ -72,7 +72,7 @@ decisionEngine:
     #二维码的门禁记录服务地址
     qrcode: https://chtech.ncjti.edu.cn/access-control/ncjtEntranceGuard/getTrafficRecordViewPageList
     #热水使用记录
-    waterUrl: https://jtishfw.ncjti.edu.cn/jxch-smartmp/HotWaters/waterfindConsume.action
+    waterUrl: http://192.168.1.34:8080/HotWaters/waterfindConsume.action
   nvr:
     nvrip: 172.22.45.25
     nvrport: 80