|
@@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
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.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.chuanghai.student_portrait.config.TokenConfig;
|
|
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.chuanghai.student_portrait.utils.DateUtils;
|
|
|
import com.fasterxml.jackson.core.type.TypeReference;
|
|
import com.fasterxml.jackson.core.type.TypeReference;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
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.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
@@ -27,6 +31,7 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
@@ -52,6 +57,13 @@ public class ConsumeServicelmpl extends ServiceImpl<ConsumeMapper, Consume> impl
|
|
|
@Autowired
|
|
@Autowired
|
|
|
HotWaterService hotWaterService;
|
|
HotWaterService hotWaterService;
|
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ ColdWaterService coldWaterService;
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ ElectricityService electricityService;
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public BaseResponse getAddress(String startTime, String endTime, String idCard) {
|
|
public BaseResponse getAddress(String startTime, String endTime, String idCard) {
|
|
|
DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
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);
|
|
consumeTotalMoneyDtos.add(consumeTotalMoneyDto);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- return BaseResponse.ok(StatusEnum.SUCCESS,consumeTotalMoneyDtos);
|
|
|
|
|
|
|
+ return BaseResponse.ok(StatusEnum.SUCCESS, consumeTotalMoneyDtos);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
- public BaseResponse personConsum(String id,String startTime,String endTime) {
|
|
|
|
|
|
|
+ public BaseResponse personConsum(String id, String startTime, String endTime) {
|
|
|
// 默认本月,从1号到下一个月1号
|
|
// 默认本月,从1号到下一个月1号
|
|
|
DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
DateTimeFormatter pattern = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
LocalDateTime now = LocalDateTime.now();
|
|
LocalDateTime now = LocalDateTime.now();
|
|
|
if (ObjectUtils.isEmpty(startTime)) {
|
|
if (ObjectUtils.isEmpty(startTime)) {
|
|
|
LocalDateTime start = now.withDayOfMonth(1).withHour(0).withMinute(0).withSecond(0);
|
|
LocalDateTime start = now.withDayOfMonth(1).withHour(0).withMinute(0).withSecond(0);
|
|
|
- startTime=start.format(pattern);
|
|
|
|
|
|
|
+ startTime = start.format(pattern);
|
|
|
}
|
|
}
|
|
|
if (ObjectUtils.isEmpty(endTime)) {
|
|
if (ObjectUtils.isEmpty(endTime)) {
|
|
|
LocalDateTime end = now.withHour(0).withMinute(0).withSecond(0);
|
|
LocalDateTime end = now.withHour(0).withMinute(0).withSecond(0);
|
|
|
endTime = end.plusMonths(1).format(pattern);
|
|
endTime = end.plusMonths(1).format(pattern);
|
|
|
}
|
|
}
|
|
|
if (ObjectUtils.isEmpty(id)) {
|
|
if (ObjectUtils.isEmpty(id)) {
|
|
|
- return BaseResponse.error(StatusEnum.FAIL,"参数异常");
|
|
|
|
|
|
|
+ return BaseResponse.error(StatusEnum.FAIL, "参数异常");
|
|
|
}
|
|
}
|
|
|
ArrayList<PersonConsumDto> dtos = new ArrayList<>();
|
|
ArrayList<PersonConsumDto> dtos = new ArrayList<>();
|
|
|
// 食堂
|
|
// 食堂
|
|
|
List<Consume> list = this.list(Wrappers.<Consume>lambdaQuery().eq(Consume::getIdCard, id).between(Consume::getConsumeTime, startTime, endTime));
|
|
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();
|
|
PersonConsumDto personConsumDto = new PersonConsumDto();
|
|
|
for (Consume consume : list) {
|
|
for (Consume consume : list) {
|
|
|
int i = Integer.parseInt(consume.getConsumeAmount());
|
|
int i = Integer.parseInt(consume.getConsumeAmount());
|
|
|
- consumeMoney=consumeMoney+i;
|
|
|
|
|
|
|
+ consumeMoney = consumeMoney + i;
|
|
|
}
|
|
}
|
|
|
- personConsumDto.setName("食堂");
|
|
|
|
|
|
|
+ personConsumDto.setName("饮食");
|
|
|
personConsumDto.setMoney(consumeMoney);
|
|
personConsumDto.setMoney(consumeMoney);
|
|
|
- dtos.add(personConsumDto);
|
|
|
|
|
|
|
+
|
|
|
// 热水
|
|
// 热水
|
|
|
List<HotWater> list1 = hotWaterService.list(Wrappers.<HotWater>lambdaQuery().eq(HotWater::getCardNumber, id).between(HotWater::getHotwaterTime, startTime, endTime));
|
|
List<HotWater> list1 = hotWaterService.list(Wrappers.<HotWater>lambdaQuery().eq(HotWater::getCardNumber, id).between(HotWater::getHotwaterTime, startTime, endTime));
|
|
|
PersonConsumDto personConsumDto2 = new PersonConsumDto();
|
|
PersonConsumDto personConsumDto2 = new PersonConsumDto();
|
|
|
- Double hotWaterMoney=0.0;
|
|
|
|
|
|
|
+ Double hotWaterMoney = 0.0;
|
|
|
for (HotWater hotWater : list1) {
|
|
for (HotWater hotWater : list1) {
|
|
|
double aDouble = Double.parseDouble(hotWater.getHotwaterAmount());
|
|
double aDouble = Double.parseDouble(hotWater.getHotwaterAmount());
|
|
|
- hotWaterMoney=hotWaterMoney+aDouble;
|
|
|
|
|
|
|
+ hotWaterMoney = hotWaterMoney + aDouble;
|
|
|
}
|
|
}
|
|
|
personConsumDto2.setName("热水");
|
|
personConsumDto2.setName("热水");
|
|
|
personConsumDto2.setMoney(hotWaterMoney);
|
|
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);
|
|
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
|
|
@Autowired
|
|
|
private TokenConfig tokenConfig;
|
|
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 * * * ? ")
|
|
@Scheduled(cron = "0 0/2 * * * ? ")
|
|
|
public void autoQueryOrder() {
|
|
public void autoQueryOrder() {
|
|
|
|
|
|