Просмотр исходного кода

全校学生能力功能
优化个人能耗统计功能
优化个人基本信息功能

liu 3 лет назад
Родитель
Сommit
b09a959642

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

@@ -33,7 +33,7 @@ public class ConsumeController {
     }
 
     @GetMapping("/person/personConsum")
-    @ApiOperation(value = "个人消费能力,id为学生序号")
+    @ApiOperation(value = "个人消费能力,id为学生序号,时间格式:yyyy-MM-dd HH:mm:ss")
     public BaseResponse personConsum(String id,String startTime,String endTime){
         return consumeService.personConsum(id,startTime,endTime);
     }

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

@@ -28,7 +28,7 @@ public class ForeWarningReportFormController {
     @ApiOperation(value = "报表导出")
     public void downloadReportData(HttpServletResponse response, String start, String end,String keyWord) {
         SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-        String fileName = "预警数据.xls";
+        String fileName = "Forewarning.xls";
         List<ForeWarningEntity> foreWarningEntities = new ArrayList<>();
         List<Forewarning> forewarnings = forewarningService.list(Wrappers.<Forewarning>lambdaQuery()
                 .between(ObjectUtils.isNotEmpty(start) && ObjectUtils.isNotEmpty(end), Forewarning::getDateTime, start, end)

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

@@ -22,7 +22,7 @@ public class HotWaterController {
     }
 
     @GetMapping("person/energy")
-    @ApiOperation(value = "个人热水能耗,参数为该学生序号")
+    @ApiOperation(value = "个人热水和水电能耗,参数为该学生序号")
     public BaseResponse personHotwaterEnergy(String id){
         return hotWaterService.personHotwaterEnergy(id);
     }

+ 5 - 1
src/main/java/com/chuanghai/student_portrait/entity/NewSchooluser.java

@@ -1,6 +1,7 @@
 package com.chuanghai.student_portrait.entity;
 
 import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableName;
 import lombok.Data;
 
 /**
@@ -60,7 +61,10 @@ private String dormNumber;
 //    准考证号
     private String headImage;
 
+    @TableField(exist = false)
+    private String[] label;
 
-
+    @TableField(exist = false)
+    private String[] affinityScoreName;
 
 }

+ 11 - 0
src/main/java/com/chuanghai/student_portrait/entity/dto/CapacityAllDto.java

@@ -0,0 +1,11 @@
+package com.chuanghai.student_portrait.entity.dto;
+
+import lombok.Data;
+
+@Data
+public class CapacityAllDto {
+    private String name;
+    private long threshold;
+    private long truth;
+
+}

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

@@ -6,5 +6,6 @@ import lombok.Data;
 public class PersonConsumDto {
     private String name;
     private Object money;
+    private String percentage;
 }
 

+ 113 - 14
src/main/java/com/chuanghai/student_portrait/service/impl/CapacityServiceImpl.java

@@ -4,6 +4,7 @@ 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.*;
+import com.chuanghai.student_portrait.entity.dto.CapacityAllDto;
 import com.chuanghai.student_portrait.entity.dto.CapacityDto;
 import com.chuanghai.student_portrait.mapper.CapacityMapper;
 import com.chuanghai.student_portrait.response.BaseResponse;
@@ -41,6 +42,9 @@ public class CapacityServiceImpl extends ServiceImpl<CapacityMapper, Capacity> i
     @Autowired
     AffinityScoreService affinityScoreService;
 
+    @Autowired
+    NewSchooluserServiceImpl newSchooluserService;
+
     //健康
     //  一月一次
     @Scheduled(cron = "0 27 23 2 * ? ")
@@ -396,19 +400,32 @@ public class CapacityServiceImpl extends ServiceImpl<CapacityMapper, Capacity> i
         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;
+        List<Capacity> list = this.list(Wrappers.<Capacity>lambdaQuery().eq(Capacity::getDateTime, s).eq(Capacity::getCapacityName, name));
+        Double average = 0.0;
         for (Capacity capacity : list) {
             String units = capacity.getUnits();
             double v = Double.parseDouble(units);
-            healthAverage = healthAverage + v;
+            average = average + v;
         }
         capacityDto.setName(name);
-        capacityDto.setMax(Math.ceil(healthAverage / list.size()));
+        capacityDto.setMax(Math.ceil(average / list.size()));
 
         return capacityDto;
     }
 
+    //    大于等于平均数的人数
+    public long getGeAverageCount(Double average, String name, String dateTime) {
+        long count = this.count(Wrappers.<Capacity>lambdaQuery().eq(Capacity::getCapacityName, name).eq(Capacity::getDateTime, dateTime).ge(Capacity::getUnits, average));
+        return count;
+    }
+
+    //总人数
+    public long getTotalCount(String dateTime, String name) {
+        long count = this.count(Wrappers.<Capacity>lambdaQuery().eq(Capacity::getCapacityName, name).eq(Capacity::getDateTime, dateTime));
+        return count;
+    }
+
+    //    单个学生总数
     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));
@@ -455,7 +472,7 @@ public class CapacityServiceImpl extends ServiceImpl<CapacityMapper, Capacity> i
         Double max2 = average4.getMax();
         CapacityDto capacityDto = new CapacityDto();
         capacityDto.setName("尽责心");
-        capacityDto.setMax(max+max1+max2);
+        capacityDto.setMax(max + max1 + max2);
         averages.add(capacityDto);
 
         HashMap<String, Object> map = new HashMap<>();
@@ -466,26 +483,29 @@ public class CapacityServiceImpl extends ServiceImpl<CapacityMapper, Capacity> i
         CapacityDto capacityDto3 = getCapacityDto(id, consume);
         CapacityDto capacityDto4 = getCapacityDto(id, affinityScore);
         CapacityDto capacityDto5 = getCapacityDto(id, safety);
+
 //      健康
         Double max3 = capacityDto1.getMax();
 
-        if (max3>max) {
-            max3=max;
+        if (max3 > max) {
+            max3 = max;
         }
 //        爱动
         Double max4 = capacityDto2.getMax();
-        if (max4>max1) {
-            max4=max1;
+        if (max4 > max1) {
+            max4 = max1;
         }
 //        安全
         Double max5 = capacityDto5.getMax();
-        Double max6=30-max5;
-        if (max6<0) {
-            max6=0.0;
+        Double max6 = 30 - max5;
+        if (max6 < 0) {
+            max6 = 0.0;
         }
         CapacityDto capacityDto6 = new CapacityDto();
         capacityDto6.setName("尽责心");
-        capacityDto6.setMax(max3+max4+max6);
+        capacityDto6.setMax(max3 + max4 + max6);
+
+        capacityDto5.setMax(max6);
 
         capacityDtos.add(capacityDto1);
         capacityDtos.add(capacityDto2);
@@ -501,8 +521,87 @@ public class CapacityServiceImpl extends ServiceImpl<CapacityMapper, Capacity> i
 
     @Override
     public BaseResponse getAllStudents() {
+        String s = startTime();
+        String health = "健康";
+        String exercise = "爱动";
+        String consume = "消费";
+        String affinityScore = "关系";
+        String safety = "安全";
+        String conscientiousness = "尽责心";
+        ArrayList<CapacityAllDto> list = new ArrayList<>();
+
+//        健康
+        CapacityDto average = getAverage(health);
+        long geAverageCount = getGeAverageCount(average.getMax(), health, s);
+        long totalCount = getTotalCount(s, health);
+        CapacityAllDto capacityAllDto = new CapacityAllDto();
+        capacityAllDto.setName(health);
+        capacityAllDto.setThreshold(totalCount);
+        capacityAllDto.setTruth(geAverageCount);
+        list.add(capacityAllDto);
+
+//        爱动
+        CapacityDto average1 = getAverage(exercise);
+        long geAverageCount1 = getGeAverageCount(average1.getMax(), exercise, s);
+        long totalCount1 = getTotalCount(s, exercise);
+        CapacityAllDto capacityAllDto1 = new CapacityAllDto();
+        capacityAllDto1.setName(exercise);
+        capacityAllDto1.setThreshold(totalCount1);
+        capacityAllDto1.setTruth(geAverageCount1);
+        list.add(capacityAllDto1);
+
+//        消费
+        CapacityDto average2 = getAverage(consume);
+        long geAverageCount2 = getGeAverageCount(average2.getMax(), consume, s);
+        long totalCount2 = getTotalCount(s, consume);
+        CapacityAllDto capacityAllDto2 = new CapacityAllDto();
+        capacityAllDto2.setName(consume);
+        capacityAllDto2.setThreshold(totalCount2);
+        capacityAllDto2.setTruth(geAverageCount2);
+        list.add(capacityAllDto2);
+
+//        关系
+        CapacityDto average3 = getAverage(affinityScore);
+        long geAverageCount3 = getGeAverageCount(average3.getMax(), affinityScore, s);
+        long totalCount3 = getTotalCount(s, affinityScore);
+        CapacityAllDto capacityAllDto3 = new CapacityAllDto();
+        capacityAllDto3.setName(affinityScore);
+        capacityAllDto3.setThreshold(totalCount3);
+        capacityAllDto3.setTruth(geAverageCount3);
+        list.add(capacityAllDto3);
+
+//        安全
+        long geAverageCount4 = getTotalCount(s, safety);
+        long totalCount4 = newSchooluserService.getSchoolUserCount();
+        CapacityAllDto capacityAllDto4 = new CapacityAllDto();
+        capacityAllDto4.setName(safety);
+        capacityAllDto4.setThreshold(totalCount4);
+        capacityAllDto4.setTruth(totalCount4 - geAverageCount4);
+        list.add(capacityAllDto4);
+
+//        健康
+        long totalCount5 = totalCount + totalCount1 + totalCount4;
+        long total = geAverageCount;
+        if (geAverageCount > totalCount) {
+            total = totalCount;
+        }
+        long total1 = geAverageCount1;
+        if (geAverageCount1 > totalCount1) {
+            total1 = totalCount1;
+        }
+        long total4 = totalCount4 - geAverageCount4;
+        if (total4 < 0) {
+            total4 = totalCount4;
+        }
+        long geAverageCount5 = total + total1 + total4;
+        CapacityAllDto capacityAllDto5 = new CapacityAllDto();
+        capacityAllDto5.setName(conscientiousness);
+        capacityAllDto5.setThreshold(totalCount5);
+        capacityAllDto5.setTruth(geAverageCount5);
+        list.add(capacityAllDto5);
+
 
-        return null;
+        return BaseResponse.ok(StatusEnum.SUCCESS, list);
     }
 
 

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

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+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.config.TokenConfig;
@@ -18,7 +19,10 @@ import com.chuanghai.student_portrait.service.*;
 import com.chuanghai.student_portrait.utils.DateUtils;
 import com.fasterxml.jackson.core.type.TypeReference;
 import com.fasterxml.jackson.databind.ObjectMapper;
-import org.apache.commons.lang3.ObjectUtils;
+import com.sun.org.apache.bcel.internal.generic.NEW;
+
+import org.apache.poi.ss.usermodel.DateUtil;
+import org.python.antlr.ast.If;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.ResponseEntity;
 import org.springframework.scheduling.annotation.Scheduled;
@@ -27,6 +31,7 @@ import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.client.RestTemplate;
 
 
+import java.math.BigDecimal;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.util.*;
@@ -52,6 +57,13 @@ public class ConsumeServicelmpl extends ServiceImpl<ConsumeMapper, Consume> impl
     @Autowired
     HotWaterService hotWaterService;
 
+    @Autowired
+    ColdWaterService coldWaterService;
+
+    @Autowired
+    ElectricityService electricityService;
+
+
     @Override
     public BaseResponse getAddress(String startTime, String endTime, String idCard) {
         DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
@@ -173,51 +185,141 @@ public class ConsumeServicelmpl extends ServiceImpl<ConsumeMapper, Consume> impl
                 consumeTotalMoneyDtos.add(consumeTotalMoneyDto);
             }
         }
-        return BaseResponse.ok(StatusEnum.SUCCESS,consumeTotalMoneyDtos);
+        return BaseResponse.ok(StatusEnum.SUCCESS, consumeTotalMoneyDtos);
     }
 
     @Override
-    public BaseResponse personConsum(String id,String startTime,String endTime) {
+    public BaseResponse personConsum(String id, String startTime, String endTime) {
 //        默认本月,从1号到下一个月1号
         DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
         LocalDateTime now = LocalDateTime.now();
         if (ObjectUtils.isEmpty(startTime)) {
             LocalDateTime start = now.withDayOfMonth(1).withHour(0).withMinute(0).withSecond(0);
-            startTime=start.format(pattern);
+            startTime = start.format(pattern);
         }
         if (ObjectUtils.isEmpty(endTime)) {
             LocalDateTime end = now.withHour(0).withMinute(0).withSecond(0);
             endTime = end.plusMonths(1).format(pattern);
         }
         if (ObjectUtils.isEmpty(id)) {
-            return BaseResponse.error(StatusEnum.FAIL,"参数异常");
+            return BaseResponse.error(StatusEnum.FAIL, "参数异常");
         }
         ArrayList<PersonConsumDto> dtos = new ArrayList<>();
 //        食堂
         List<Consume> list = this.list(Wrappers.<Consume>lambdaQuery().eq(Consume::getIdCard, id).between(Consume::getConsumeTime, startTime, endTime));
-        int consumeMoney=0;
+        int consumeMoney = 0;
         PersonConsumDto personConsumDto = new PersonConsumDto();
         for (Consume consume : list) {
             int i = Integer.parseInt(consume.getConsumeAmount());
-            consumeMoney=consumeMoney+i;
+            consumeMoney = consumeMoney + i;
         }
-        personConsumDto.setName("食");
+        personConsumDto.setName("食");
         personConsumDto.setMoney(consumeMoney);
-        dtos.add(personConsumDto);
+
 //        热水
         List<HotWater> list1 = hotWaterService.list(Wrappers.<HotWater>lambdaQuery().eq(HotWater::getCardNumber, id).between(HotWater::getHotwaterTime, startTime, endTime));
         PersonConsumDto personConsumDto2 = new PersonConsumDto();
-        Double hotWaterMoney=0.0;
+        Double hotWaterMoney = 0.0;
         for (HotWater hotWater : list1) {
             double aDouble = Double.parseDouble(hotWater.getHotwaterAmount());
-            hotWaterMoney=hotWaterMoney+aDouble;
+            hotWaterMoney = hotWaterMoney + aDouble;
         }
         personConsumDto2.setName("热水");
         personConsumDto2.setMoney(hotWaterMoney);
+
+
+//        水电
+        PersonConsumDto personConsumDto1 = new PersonConsumDto();
+        personConsumDto1.setName("水电");
+        Double coldWaterAndElectricityMoney = 0.0;
+        NewSchooluser newSchooluser = newSchooluserService.getById(id);
+        String dormNumber = newSchooluser.getDormNumber();
+        if (ObjectUtils.isNotEmpty(dormNumber)) {
+            LocalDateTime parse = LocalDateTime.parse(startTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
+            String format = parse.format(formatter);
+            List<ColdWater> list2 = coldWaterService.list(Wrappers.<ColdWater>lambdaQuery().eq(ColdWater::getDom, dormNumber).eq(ColdWater::getDataTime, format));
+            List<Electricity> list3 = electricityService.list(Wrappers.<Electricity>lambdaQuery().eq(Electricity::getDom, dormNumber).eq(Electricity::getDateTime, format));
+            for (ColdWater coldWater : list2) {
+                Double totalMoney = coldWater.getTotalMoney();
+                BigDecimal b1 = new BigDecimal(totalMoney/4);
+                double f2 = b1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
+                coldWaterAndElectricityMoney = coldWaterAndElectricityMoney + f2;
+            }
+            for (Electricity electricity : list3) {
+                Double totalMoney = electricity.getTotalMoney();
+                BigDecimal b1 = new BigDecimal(totalMoney/4);
+                double f2 = b1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
+                coldWaterAndElectricityMoney = coldWaterAndElectricityMoney + f2;
+            }
+        }
+        personConsumDto1.setMoney(new BigDecimal(coldWaterAndElectricityMoney).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
+
+
+        Double total = consumeMoney + hotWaterMoney + coldWaterAndElectricityMoney;
+        if (total > 0) {
+            if (consumeMoney == 0) {
+                personConsumDto.setPercentage(0 + "%");
+            }
+            BigDecimal b = new BigDecimal(consumeMoney / total);
+            double f1 = b.setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
+            Double v = f1 * 100;
+            personConsumDto.setPercentage(v + "%");
+
+            BigDecimal b1 = new BigDecimal(hotWaterMoney / total);
+            double f2 = b1.setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
+            Double v1 = f2 * 100;
+            String p = "";
+            if (v1 > 100 - v || coldWaterAndElectricityMoney == 0) {
+                BigDecimal bd1 = new BigDecimal(Double.toString(100));
+                BigDecimal bd2 = new BigDecimal(Double.toString(v));
+                v1 = bd1.subtract(bd2).doubleValue();;
+                p = v1 + "" + "%";
+            } else {
+                p = v1 + "" + "%";
+            }
+            personConsumDto2.setPercentage(p);
+
+            Double v2 = 0.0;
+            String p1 = "";
+            if (hotWaterMoney == 0 || v2 > 100 - v) {
+                BigDecimal bd1 = new BigDecimal(Double.toString(100));
+                BigDecimal bd2 = new BigDecimal(Double.toString(v));
+                v2 = bd1.subtract(bd2).doubleValue();;
+                p1 = v2 + "" + "%";
+            } else if (consumeMoney == 0 || v2 > 100 - v1) {
+                BigDecimal bd1 = new BigDecimal(Double.toString(100));
+                BigDecimal bd2 = new BigDecimal(Double.toString(v1));
+                v2 = bd1.subtract(bd2).doubleValue();;
+                p1 = v2 + "" + "%";
+            } else {
+                BigDecimal bd1 = new BigDecimal(Double.toString(100));
+                BigDecimal bd2 = new BigDecimal(Double.toString(v));
+                BigDecimal bd3 = new BigDecimal(Double.toString(v1));
+                v2 = bd1.subtract(bd2).subtract(bd3).doubleValue();;
+                p1 = v2 + "" + "%";
+            }
+            personConsumDto1.setPercentage(p1);
+
+        } else {
+            personConsumDto.setPercentage(0 + "%");
+            personConsumDto2.setPercentage(0 + "%");
+            personConsumDto1.setPercentage(0 + "%");
+        }
+
+        dtos.add(personConsumDto);
         dtos.add(personConsumDto2);
-        return BaseResponse.ok(StatusEnum.SUCCESS,dtos);
+        dtos.add(personConsumDto1);
+        return BaseResponse.ok(StatusEnum.SUCCESS, dtos);
     }
 
+    public static void main(String[] args) {
+        BigDecimal bd1 = new BigDecimal(Double.toString(33.33));
+        BigDecimal bd2 = new BigDecimal(Double.toString(22.191));
+        BigDecimal bd3 = new BigDecimal(Double.toString(9.9999));
+        double v = bd1.subtract(bd2).subtract(bd3).doubleValue();
+        System.out.println("v = " + v);
+    }
 
     @Autowired
     private TokenConfig tokenConfig;
@@ -231,7 +333,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() {
 

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

@@ -227,7 +227,7 @@ public class FaceDiscernServiceImpl extends ServiceImpl<FaceDiscernMapper, FaceD
                 String accessEvent = access.getAccessEvent();
                 String accessAddress = access.getAccessAddress();
                 dto.setAffair(accessEvent + accessAddress);
-                dto.setName(accessEvent);
+                dto.setName("扫码");
                 personalTrackDtos.add(dto);
             }
         }
@@ -292,7 +292,7 @@ public class FaceDiscernServiceImpl extends ServiceImpl<FaceDiscernMapper, FaceD
     private String api_key = "5C78D964F6C534DFA918EAC7854F4529";
 
     //    每2分钟就拉取一次
-    @Scheduled(cron = "0 0/2 * * * ? ")
+    @Scheduled(cron = "0 0 0/2 * * ? ")
     public void autoQueryOnline() {
         if (page > 1) {
             page -= 1;
@@ -449,7 +449,7 @@ public class FaceDiscernServiceImpl extends ServiceImpl<FaceDiscernMapper, FaceD
     /**
      * 2小时拉取一次宇视人脸识别记录
      */
-    @Scheduled(cron = "0 0/2 * * * ? ")
+    @Scheduled(cron = "0 0 0/2 * * ? ")
     public void autoQueryOrder() {
         try {
             DateUtils dateUtils = new DateUtils();

+ 63 - 10
src/main/java/com/chuanghai/student_portrait/service/impl/HotWaterServiceImpl.java

@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+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.*;
@@ -16,7 +17,6 @@ import com.chuanghai.student_portrait.service.*;
 import com.chuanghai.student_portrait.utils.DateUtils;
 import com.fasterxml.jackson.core.type.TypeReference;
 import com.fasterxml.jackson.databind.ObjectMapper;
-import org.apache.commons.lang3.ObjectUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.http.HttpEntity;
@@ -30,6 +30,7 @@ import org.springframework.util.MultiValueMap;
 import org.springframework.web.bind.annotation.PostMapping;
 import org.springframework.web.client.RestTemplate;
 
+import java.math.BigDecimal;
 import java.time.LocalDateTime;
 import java.time.format.DateTimeFormatter;
 import java.util.*;
@@ -51,6 +52,8 @@ public class HotWaterServiceImpl extends ServiceImpl<HotWaterMapper, HotWater> i
     @Autowired
     ColdWaterService coldWaterService;
 
+
+
 //    @Override
 //    public BaseResponse hotWaterEnergy1() {
 //        HashMap<Object, Object> hashMap = new HashMap<>();
@@ -234,19 +237,19 @@ public class HotWaterServiceImpl extends ServiceImpl<HotWaterMapper, HotWater> i
                 double money = Double.parseDouble(hotwaterAmount);
                 if ("女".equals(genderDorm)) {
                     girlTotalHotWaterMoney = girlTotalHotWaterMoney + money;
-                }else if ("男".equals(genderDorm)){
+                } else if ("男".equals(genderDorm)) {
                     boyTotalMoney = boyTotalMoney + money;
                 }
             }
 
- //            热水
+            //            热水
             girlEnergyDtoHotWater.setGenderDrom("女生");
             girlEnergyDtoHotWater.setTotalMoney(girlTotalHotWaterMoney);
             girlEnergyDtoHotWater.setDate(firstMonthDay);
             girlEnergyDtoHotWater.setName("热水");
             hotWaterEnergyDtos.add(girlEnergyDtoHotWater);
 
- //            热水
+            //            热水
             boyEnergyDto.setGenderDrom("男生");
             boyEnergyDto.setTotalMoney(boyTotalMoney);
             boyEnergyDto.setDate(firstMonthDay);
@@ -268,7 +271,7 @@ public class HotWaterServiceImpl extends ServiceImpl<HotWaterMapper, HotWater> i
                 Double money = electricity.getTotalMoney();
                 if ("女".equals(genderDorm)) {
                     girlTotalElectricityAndColdWaterMoney = girlTotalElectricityAndColdWaterMoney + money;
-                }else if ("男".equals(genderDorm)){
+                } else if ("男".equals(genderDorm)) {
                     boyTotalElectricityAndColdWaterMoney = boyTotalElectricityAndColdWaterMoney + money;
                 }
             }
@@ -281,7 +284,7 @@ public class HotWaterServiceImpl extends ServiceImpl<HotWaterMapper, HotWater> i
                 Double money = coldWater.getTotalMoney();
                 if ("女".equals(genderDorm)) {
                     girlTotalElectricityAndColdWaterMoney = girlTotalElectricityAndColdWaterMoney + money;
-                }else if ("男".equals(genderDorm)){
+                } else if ("男".equals(genderDorm)) {
                     boyTotalElectricityAndColdWaterMoney = boyTotalElectricityAndColdWaterMoney + money;
                 }
             }
@@ -328,7 +331,6 @@ public class HotWaterServiceImpl extends ServiceImpl<HotWaterMapper, HotWater> i
     }
 
 
-
     public static String getDateTime(int i) {
         DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM");
         LocalDateTime now = LocalDateTime.now();
@@ -347,7 +349,11 @@ public class HotWaterServiceImpl extends ServiceImpl<HotWaterMapper, HotWater> i
         if (ObjectUtils.isEmpty(newSchooluser)) {
             return BaseResponse.error(StatusEnum.FAIL, "该学生不存在");
         }
-
+        HashMap<Object, Object> hashMap = new HashMap<>();
+        HashMap<Object, Object> map = new HashMap<>();
+        HashMap<Object, Object> map2 = new HashMap<>();
+        map.put("name", "热水");
+        map2.put("name", "水电");
         ArrayList<EnergyDto> hotWaterEnergyDtos = new ArrayList<>();
         for (int i = 1; i <= 5; i++) {
             Date date = new Date();
@@ -369,7 +375,54 @@ public class HotWaterServiceImpl extends ServiceImpl<HotWaterMapper, HotWater> i
             personEnergyDto.setTotalMoney(personMonTotalMoney);
             hotWaterEnergyDtos.add(personEnergyDto);
         }
-        return BaseResponse.ok(StatusEnum.SUCCESS, hotWaterEnergyDtos);
+
+        String dormNumber = newSchooluser.getDormNumber();
+        ArrayList<EnergyDto> electricityAndColdWaterDtos = new ArrayList<>();
+        if (ObjectUtils.isNotEmpty(dormNumber)) {
+            for (int i = 1; i <= 5; i++) {
+                String dateTime = getDateTime(i);
+                EnergyDto personEnergyDto = new EnergyDto();
+                Double electricityAndColdWaterMoney=0.0;
+
+//                电费
+                List<Electricity> electricityList = electricityService.list(Wrappers.<Electricity>lambdaQuery()
+                        .eq(Electricity::getDateTime, dateTime)
+                        .eq(Electricity::getDom,dormNumber)
+                );
+                for (Electricity electricity : electricityList) {
+                    Double totalMoney = electricity.getTotalMoney();
+                    electricityAndColdWaterMoney=electricityAndColdWaterMoney+totalMoney;
+                }
+
+//                水费
+                List<ColdWater> list1 = coldWaterService.list(Wrappers.<ColdWater>lambdaQuery()
+                        .eq(ColdWater::getDataTime, dateTime)
+                        .eq(ColdWater::getDom,dormNumber)
+                );
+                for (ColdWater coldWater : list1) {
+                    Double totalMoney = coldWater.getTotalMoney();
+                    electricityAndColdWaterMoney=electricityAndColdWaterMoney+totalMoney;
+                }
+                BigDecimal b1 = new BigDecimal(electricityAndColdWaterMoney/4);
+                double f2 = b1.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
+                personEnergyDto.setDate(dateTime);
+                personEnergyDto.setTotalMoney(f2);
+                electricityAndColdWaterDtos.add(personEnergyDto);
+            }
+        }else {
+            for (int i = 1; i <= 5; i++) {
+                String dateTime = getDateTime(i);
+                EnergyDto personEnergyDto = new EnergyDto();
+                personEnergyDto.setDate(dateTime);
+                personEnergyDto.setTotalMoney(0.0);
+                electricityAndColdWaterDtos.add(personEnergyDto);
+            }
+        }
+        map.put("list", hotWaterEnergyDtos);
+        map2.put("list", electricityAndColdWaterDtos);
+        hashMap.put("hotWater", map);
+        hashMap.put("electricityAndColdWater", map2);
+        return BaseResponse.ok(StatusEnum.SUCCESS, hashMap);
     }
 
     public static Date getFirstMonthDay(Date dt, int i) {
@@ -418,7 +471,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 0/2 * * ? ")
     public void autoQueryOrder() {
         try {
             DateUtils dateUtils = new DateUtils();

+ 93 - 9
src/main/java/com/chuanghai/student_portrait/service/impl/NewSchooluserServiceImpl.java

@@ -6,13 +6,13 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.chuanghai.student_portrait.controller.GetSchoolUserController;
-import com.chuanghai.student_portrait.entity.Dorm;
-import com.chuanghai.student_portrait.entity.ExamNumbers;
-import com.chuanghai.student_portrait.entity.NewSchooluser;
-import com.chuanghai.student_portrait.entity.OldSchooluser;
+import com.chuanghai.student_portrait.entity.*;
+import com.chuanghai.student_portrait.entity.dto.CapacityDto;
 import com.chuanghai.student_portrait.mapper.NewSchooluserMapper;
 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.CapacityService;
 import com.chuanghai.student_portrait.service.ExamNumbersService;
 import com.chuanghai.student_portrait.service.NewSchooluserService;
 import com.fasterxml.jackson.core.JsonProcessingException;
@@ -26,6 +26,7 @@ import org.springframework.transaction.event.TransactionalEventListener;
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.List;
+import java.util.Map;
 
 
 /**
@@ -43,8 +44,14 @@ public class NewSchooluserServiceImpl extends ServiceImpl<NewSchooluserMapper, N
     @Autowired
     GetSchoolUserController getSchoolUserController;
 
+    @Autowired
+    CapacityService capacityService;
+
+    @Autowired
+    AffinityScoreService affinityScoreService;
+
     @Override
-    public BaseResponse listSchoolUser(Integer page, Integer size,String keyWord) {
+    public BaseResponse listSchoolUser(Integer page, Integer size, String keyWord) {
         if (ObjectUtils.isEmpty(page)) {
             page = 1;
         }
@@ -67,13 +74,13 @@ public class NewSchooluserServiceImpl extends ServiceImpl<NewSchooluserMapper, N
         Page<NewSchooluser> Pg = new Page<>(page, size);
         LambdaQueryWrapper<NewSchooluser> wrapper = new LambdaQueryWrapper<>();
         wrapper.ge(NewSchooluser::getGrade, grade);
-        wrapper.like(ObjectUtils.isNotEmpty(keyWord),NewSchooluser::getName,keyWord)
+        wrapper.like(ObjectUtils.isNotEmpty(keyWord), NewSchooluser::getName, keyWord)
                 .or()
-                .like(ObjectUtils.isNotEmpty(keyWord),NewSchooluser::getStudentId,keyWord)
+                .like(ObjectUtils.isNotEmpty(keyWord), NewSchooluser::getStudentId, keyWord)
                 .or()
-                .like(ObjectUtils.isNotEmpty(keyWord),NewSchooluser::getProfession,keyWord)
+                .like(ObjectUtils.isNotEmpty(keyWord), NewSchooluser::getProfession, keyWord)
                 .or()
-                .like(ObjectUtils.isNotEmpty(keyWord),NewSchooluser::getClazz,keyWord);
+                .like(ObjectUtils.isNotEmpty(keyWord), NewSchooluser::getClazz, keyWord);
         Page<NewSchooluser> page1 = this.page(Pg, wrapper);
 
         return BaseResponse.ok(StatusEnum.SUCCESS, page1);
@@ -94,9 +101,66 @@ public class NewSchooluserServiceImpl extends ServiceImpl<NewSchooluserMapper, N
             throw new RuntimeException(e);
         }
         schooluser.setHeadImage(headImage);
+//      标签
+        BaseResponse oneStudent = capacityService.getOneStudent(id);
+        Map<String, List<CapacityDto>> data1 = (Map<String, List<CapacityDto>>) oneStudent.getData();
+        List<CapacityDto> average = data1.get("average");
+        List<CapacityDto> list = data1.get("list");
+
+        String label = "";
+
+        for (CapacityDto capacityDto : average) {
+//            平均值
+            String name = capacityDto.getName();
+            Double max = capacityDto.getMax();
+            for (CapacityDto dto : list) {
+//                真实值
+                String name1 = dto.getName();
+                Double max1 = dto.getMax();
+                if (name.equals(name1)) {
+                    if (max1 >= max) {
+                        if ("健康".equals(name)) {
+                            label = label + "养生达人,";
+                        } else if ("爱动".equals(name)) {
+                            label = label + "运动健儿,";
+                        } else if ("消费".equals(name)) {
+                            label = label + "氪金达人,";
+                        } else if ("关系".equals(name)) {
+                            label = label + "社交天花板,";
+                        } else if ("安全".equals(name)) {
+                            label = label + "安全感爆棚,";
+                        } else if ("尽责心".equals(name)) {
+                            label = label + "自律,";
+                        }
+                    }
+                }
+            }
+        }
+        String[] split = label.split(",");
+        if (split.length == 6) {
+            label = "六边形战士,";
+        }
+        if ("".equals(label)) {
+            label = " 佛系青年,";
+        }
+        String[] labels = label.split(",");
+        schooluser.setLabel(labels);
+
+        List<AffinityScore> list1 = affinityScoreService.list(Wrappers.<AffinityScore>lambdaQuery().eq(AffinityScore::getSchooluserId, id).orderByDesc(AffinityScore::getCount));
+        AffinityScore affinityScore = list1.get(0);
+        String name = affinityScore.getName();
+        AffinityScore affinityScore1 = list1.get(1);
+        String name1 = affinityScore1.getName();
+        String[] affinityScoreName={name,name1};
+        schooluser.setAffinityScoreName(affinityScoreName);
+
         return BaseResponse.ok(StatusEnum.SUCCESS_SELECT, schooluser);
     }
 
+    public static void main(String[] args) {
+        String[] affinityScoreName={"1","2"};
+        System.out.println("affinityScoreName = " + affinityScoreName);
+    }
     @Override
     public BaseResponse saveStudenNts(Integer page) {
         List<ExamNumbers> examNumbers = examNumbersService.page(new Page<>(page, 1000)).getRecords();
@@ -114,6 +178,26 @@ public class NewSchooluserServiceImpl extends ServiceImpl<NewSchooluserMapper, N
     }
 
 
+    public long getSchoolUserCount() {
+        Calendar calendar = Calendar.getInstance();
+        // 获取当前年
+        int year = calendar.get(Calendar.YEAR);
+// 获取当前月
+        int month = calendar.get(Calendar.MONTH) + 1;
+        int oldYear = 0;
+
+        if (month >= 7) {
+            oldYear = year - 3;
+        } else {
+            oldYear = year - 4;
+        }
+
+        long countSchoolUser = this.count(Wrappers.<NewSchooluser>lambdaQuery()
+                .between(NewSchooluser::getGrade, oldYear, year)
+        );
+        return countSchoolUser;
+    }
+
 
 //    Integer i = 9;
 //

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

@@ -27,7 +27,7 @@ public class StudentSheetServiceImpl extends ServiceImpl<StudentSheetMapper, Stu
     NewSchooluserService newSchooluserService;
 
     int i = 0;
-//todo 5 8
+
 
 //    @Scheduled(cron = "0 0/1 * * * ? ")
     public void xiugai() {
@@ -40,6 +40,7 @@ public class StudentSheetServiceImpl extends ServiceImpl<StudentSheetMapper, Stu
         }
         updateStudent(i);
         System.out.println("i = " + i);
+
     }