|
|
@@ -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;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
}
|