From 5afdd83eedac64e609654cd8fb10b958c8be9aab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E4=B8=89=E7=82=AE?= <15856818120@163.com> Date: Tue, 25 Mar 2025 18:51:21 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E6=9F=A5=E8=AF=A2=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/controller/MainController.java | 77 +++++++ .../main/domain/DemandAndSupplyVo.java | 73 +++++++ .../material/main/mapper/MainMapper.java | 17 ++ .../material/main/service/MainService.java | 21 ++ .../main/service/impl/MainServiceImpl.java | 193 ++++++++++++++++++ .../mapper/material/main/MainMapper.xml | 72 +++++++ 6 files changed, 453 insertions(+) create mode 100644 bonus-modules/bonus-material/src/main/java/com/bonus/material/main/controller/MainController.java create mode 100644 bonus-modules/bonus-material/src/main/java/com/bonus/material/main/domain/DemandAndSupplyVo.java create mode 100644 bonus-modules/bonus-material/src/main/java/com/bonus/material/main/mapper/MainMapper.java create mode 100644 bonus-modules/bonus-material/src/main/java/com/bonus/material/main/service/MainService.java create mode 100644 bonus-modules/bonus-material/src/main/java/com/bonus/material/main/service/impl/MainServiceImpl.java create mode 100644 bonus-modules/bonus-material/src/main/resources/mapper/material/main/MainMapper.xml diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/main/controller/MainController.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/main/controller/MainController.java new file mode 100644 index 00000000..ce28e08f --- /dev/null +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/main/controller/MainController.java @@ -0,0 +1,77 @@ +package com.bonus.material.main.controller; + +import com.bonus.common.core.web.domain.AjaxResult; +import com.bonus.common.security.utils.SecurityUtils; +import com.bonus.material.main.domain.DemandAndSupplyVo; +import com.bonus.material.main.service.MainService; +import io.swagger.annotations.Api; +import lombok.extern.slf4j.Slf4j; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; +import java.math.BigDecimal; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; + +import static com.bonus.common.core.web.domain.AjaxResult.success; + + +@Api(tags = "机具设备首页接口") +@RestController +@RequestMapping("/mainPage") +@Slf4j +public class MainController { + + @Resource + private MainService mainService; + + /** + * 查询机具设备管理列表 + */ + + @GetMapping("/demandAndSupply") + public AjaxResult demandAndSupply(DemandAndSupplyVo demandAndSupplyVo) + { + //Long userId = SecurityUtils.getUserId(); + //demandAndSupplyVo.setUserId(userId == 0 ? null : userId); + if (demandAndSupplyVo.getStartTime() ==null || demandAndSupplyVo.getStartTime() ==" "){ + // 定义日期格式 + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + //获取当前时间 + LocalDate currentDate = LocalDate.now(); + String currentDateStr = currentDate.format(formatter); + // 获取本月第一天的日期 + LocalDate firstDayOfMonth = currentDate.withDayOfMonth(1); + String firstDayOfMonthStr = firstDayOfMonth.format(formatter); + demandAndSupplyVo.setStartTime(firstDayOfMonthStr); + demandAndSupplyVo.setEndTime(currentDateStr); + } + DemandAndSupplyVo demandAndSupplyVoRes = new DemandAndSupplyVo(); + //需求量 + BigDecimal demandNum = mainService.getDemandNum(demandAndSupplyVo); + //需求增长量 + BigDecimal demandIncrease = mainService.getDemandIncrease(demandAndSupplyVo); + //已供应数量 + BigDecimal suppliedQuantityNum = mainService.getSuppliedQuantityNum(demandAndSupplyVo); + //已供应增长量 + BigDecimal suppliedQuantityIncrease = mainService.getSuppliedQuantityIncrease(demandAndSupplyVo); + //待供应量 + BigDecimal suppliedToBeQuantityNum = mainService.getSuppliedToBeQuantityNum(demandAndSupplyVo); + //待供应量增长量 + BigDecimal suppliedToBeQuantityIncrease = mainService.getSuppliedToBeQuantityIncrease(demandAndSupplyVo); + //工程总数量 + Integer projectNum = mainService.getProjectNum(demandAndSupplyVo); + //供应总件数 + + demandAndSupplyVoRes.setDemandNum(demandNum); + demandAndSupplyVoRes.setDemandIncrease(demandIncrease); + demandAndSupplyVoRes.setSuppliedQuantityNum(suppliedQuantityNum); + demandAndSupplyVoRes.setSuppliedQuantityIncrease(suppliedQuantityIncrease); + demandAndSupplyVoRes.setSuppliedToBeQuantityNum(suppliedToBeQuantityNum); + demandAndSupplyVoRes.setSuppliedToBeQuantityIncrease(suppliedToBeQuantityIncrease); + demandAndSupplyVoRes.setProjectNum(projectNum); + return success(demandAndSupplyVoRes); + } +} diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/main/domain/DemandAndSupplyVo.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/main/domain/DemandAndSupplyVo.java new file mode 100644 index 00000000..1b723ea1 --- /dev/null +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/main/domain/DemandAndSupplyVo.java @@ -0,0 +1,73 @@ +package com.bonus.material.main.domain; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; +import java.time.LocalDate; + +@Data +public class DemandAndSupplyVo { + + + /** + * 需求量 + */ + private BigDecimal demandNum; + + /** + * 需求增长量 + */ + private BigDecimal demandIncrease; + + /** + * 已供应量 + */ + private BigDecimal suppliedQuantityNum; + + /** + * 供应增长量 + */ + private BigDecimal suppliedQuantityIncrease; + + /** + * 待供应量 + */ + private BigDecimal suppliedToBeQuantityNum; + + /** + * 待供应增长量 + */ + private BigDecimal suppliedToBeQuantityIncrease; + + /** + * 工程总数量 + */ + private Integer projectNum; + + /** + * 供应总件数 + */ + private BigDecimal suppliedQuantityAllNum; + + /** + * 供应总价值 + */ + private BigDecimal suppliedQuantityPrice; + + /** + * 用户id + */ + private Long userId; + + @ApiModelProperty(value = "开始时间") + private String startTime; + + @ApiModelProperty(value = "结束时间") + private String endTime; + + /** + * 当前时间 + */ + private LocalDate currentDate; +} diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/main/mapper/MainMapper.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/main/mapper/MainMapper.java new file mode 100644 index 00000000..93a14109 --- /dev/null +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/main/mapper/MainMapper.java @@ -0,0 +1,17 @@ +package com.bonus.material.main.mapper; + +import com.bonus.common.biz.domain.lease.LeasePublishInfo; +import com.bonus.material.main.domain.DemandAndSupplyVo; + +import java.math.BigDecimal; +import java.util.List; + +public interface MainMapper { + List getPublishList(DemandAndSupplyVo demandAndSupplyVo); + + BigDecimal getPublishListNew(DemandAndSupplyVo demandAndSupplyVo); + + BigDecimal getSuppliedQuantityNum(DemandAndSupplyVo demandAndSupplyVo); + + Integer getProjectNum(); +} diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/main/service/MainService.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/main/service/MainService.java new file mode 100644 index 00000000..df6d30c7 --- /dev/null +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/main/service/MainService.java @@ -0,0 +1,21 @@ +package com.bonus.material.main.service; + +import com.bonus.material.main.domain.DemandAndSupplyVo; + +import java.math.BigDecimal; + +public interface MainService { + BigDecimal getDemandNum(DemandAndSupplyVo demandAndSupplyVo); + + BigDecimal getDemandIncrease(DemandAndSupplyVo demandAndSupplyVo); + + BigDecimal getSuppliedQuantityNum(DemandAndSupplyVo demandAndSupplyVo); + + BigDecimal getSuppliedQuantityIncrease(DemandAndSupplyVo demandAndSupplyVo); + + BigDecimal getSuppliedToBeQuantityNum(DemandAndSupplyVo demandAndSupplyVo); + + BigDecimal getSuppliedToBeQuantityIncrease(DemandAndSupplyVo demandAndSupplyVo); + + Integer getProjectNum(DemandAndSupplyVo demandAndSupplyVo); +} diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/main/service/impl/MainServiceImpl.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/main/service/impl/MainServiceImpl.java new file mode 100644 index 00000000..29470d29 --- /dev/null +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/main/service/impl/MainServiceImpl.java @@ -0,0 +1,193 @@ +package com.bonus.material.main.service.impl; + +import com.bonus.common.biz.domain.lease.LeasePublishInfo; +import com.bonus.common.core.utils.StringUtils; +import com.bonus.common.security.utils.SecurityUtils; +import com.bonus.material.main.domain.DemandAndSupplyVo; +import com.bonus.material.main.mapper.MainMapper; +import com.bonus.material.main.service.MainService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.BeanUtils; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; + +import javax.annotation.Resource; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.util.List; +import java.util.stream.Collectors; + +@Service +@Slf4j +public class MainServiceImpl implements MainService { + + @Resource + private MainMapper mainMapper; + + /** + * 需求量 + * @param demandAndSupplyVo + * @return + */ + @Override + public BigDecimal getDemandNum(DemandAndSupplyVo demandAndSupplyVo) { + //获取领料的需求数量 + List list = mainMapper.getPublishList(demandAndSupplyVo); + BigDecimal preCountNum = list.stream().map(LeasePublishInfo::getPreCountNum) + .reduce(BigDecimal.ZERO, BigDecimal::add); + //获取领用的需求数量 + BigDecimal preCountNumNew = mainMapper.getPublishListNew(demandAndSupplyVo); + preCountNum = preCountNum.add(preCountNumNew); + return preCountNum; + } + + /** + * 需求增长量 + * @param demandAndSupplyVo + * @return + */ + @Override + public BigDecimal getDemandIncrease(DemandAndSupplyVo demandAndSupplyVo) { + DemandAndSupplyVo demandAndSupplyVoNew = new DemandAndSupplyVo(); + BeanUtils.copyProperties(demandAndSupplyVo,demandAndSupplyVoNew); + // 定义日期格式 + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + //上个月的开始时间 + LocalDate startTime = LocalDate.parse(demandAndSupplyVo.getStartTime(), formatter); + LocalDate lastStartTime = startTime.minusMonths(1); + String lastStartTimeStr = lastStartTime.format(formatter); + //上个月的结束时间 + LocalDate endTime = LocalDate.parse(demandAndSupplyVo.getEndTime(), formatter); + LocalDate lastEndTime = endTime.minusMonths(1); + String lastEndTimeStr = lastEndTime.format(formatter); + //获取本月的需求数量 + BigDecimal preCountNum= this.getDemandNum(demandAndSupplyVoNew); + //获取上个月需求量 + demandAndSupplyVoNew.setStartTime(lastStartTimeStr); + demandAndSupplyVoNew.setEndTime(lastEndTimeStr); + BigDecimal lastPreCountNum = this.getDemandNum(demandAndSupplyVoNew); + //计算增长量 + BigDecimal demandIncrease= BigDecimal.ZERO; + if (lastPreCountNum.compareTo(BigDecimal.ZERO)==0){ + demandIncrease = BigDecimal.valueOf(100); + }else { + demandIncrease = preCountNum.subtract(lastPreCountNum).divide(lastPreCountNum, 4, RoundingMode.HALF_UP); + demandIncrease = demandIncrease.multiply(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP); + } + + return demandIncrease; + } + + /** + * 已供应量 + * @param demandAndSupplyVo + * @return + */ + @Override + public BigDecimal getSuppliedQuantityNum(DemandAndSupplyVo demandAndSupplyVo) { + //已供应量 + BigDecimal suppliedQuantityNum = mainMapper.getSuppliedQuantityNum(demandAndSupplyVo); + return suppliedQuantityNum; + } + + /** + * 供应增长量 + * @param demandAndSupplyVo + * @return + */ + @Override + public BigDecimal getSuppliedQuantityIncrease(DemandAndSupplyVo demandAndSupplyVo) { + DemandAndSupplyVo demandAndSupplyVoNew = new DemandAndSupplyVo(); + BeanUtils.copyProperties(demandAndSupplyVo,demandAndSupplyVoNew); + // 定义日期格式 + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + //本月以供应量 + BigDecimal suppliedQuantityNum = this.getSuppliedQuantityNum(demandAndSupplyVoNew); + //上个月的开始时间 + LocalDate startTime = LocalDate.parse(demandAndSupplyVo.getStartTime(), formatter); + LocalDate lastStartTime = startTime.minusMonths(1); + String lastStartTimeStr = lastStartTime.format(formatter); + //上个月的结束时间 + LocalDate endTime = LocalDate.parse(demandAndSupplyVo.getEndTime(), formatter); + LocalDate lastEndTime = endTime.minusMonths(1); + String lastEndTimeStr = lastEndTime.format(formatter); + //获取上个月以供应量 + demandAndSupplyVoNew.setStartTime(lastStartTimeStr); + demandAndSupplyVoNew.setEndTime(lastEndTimeStr); + BigDecimal lastSuppliedQuantityNum = this.getSuppliedQuantityNum(demandAndSupplyVoNew); + //计算增长量 + BigDecimal suppliedQuantityIncrease = BigDecimal.ZERO; + if (lastSuppliedQuantityNum.compareTo(BigDecimal.ZERO)==0){ + suppliedQuantityIncrease = BigDecimal.valueOf(100); + }else { + suppliedQuantityIncrease = suppliedQuantityNum.subtract(lastSuppliedQuantityNum).divide(lastSuppliedQuantityNum, 4, RoundingMode.HALF_UP); + suppliedQuantityIncrease = suppliedQuantityIncrease.multiply(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP); + } + return suppliedQuantityIncrease; + } + + /** + * 待供应量 + * @param demandAndSupplyVo + * @return + */ + @Override + public BigDecimal getSuppliedToBeQuantityNum(DemandAndSupplyVo demandAndSupplyVo) { + //需求量 + BigDecimal preCountNum = this.getDemandNum(demandAndSupplyVo); + //以供应量 + BigDecimal suppliedQuantityNum = this.getSuppliedQuantityNum(demandAndSupplyVo); + //待供应量 + BigDecimal suppliedToBeQuantityNum = preCountNum.subtract(suppliedQuantityNum); + + return suppliedToBeQuantityNum; + } + + /** + * 待供应增长量 + * @param demandAndSupplyVo + * @return + */ + @Override + public BigDecimal getSuppliedToBeQuantityIncrease(DemandAndSupplyVo demandAndSupplyVo) { + DemandAndSupplyVo demandAndSupplyVoNew = new DemandAndSupplyVo(); + BeanUtils.copyProperties(demandAndSupplyVo,demandAndSupplyVoNew); + //本月待供应量 + BigDecimal suppliedToBeQuantityNum = this.getSuppliedToBeQuantityNum(demandAndSupplyVoNew); + // 定义日期格式 + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + //上个月的开始时间 + LocalDate startTime = LocalDate.parse(demandAndSupplyVo.getStartTime(), formatter); + LocalDate lastStartTime = startTime.minusMonths(1); + String lastStartTimeStr = lastStartTime.format(formatter); + //上个月的结束时间 + LocalDate endTime = LocalDate.parse(demandAndSupplyVo.getEndTime(), formatter); + LocalDate lastEndTime = endTime.minusMonths(1); + String lastEndTimeStr = lastEndTime.format(formatter); + //获取上个月以供应量 + demandAndSupplyVoNew.setStartTime(lastStartTimeStr); + demandAndSupplyVoNew.setEndTime(lastEndTimeStr); + BigDecimal lastSuppliedToBeQuantityNum = this.getSuppliedToBeQuantityNum(demandAndSupplyVoNew); + //计算增长量 + BigDecimal suppliedToBeQuantityIncrease = BigDecimal.ZERO; + if (lastSuppliedToBeQuantityNum.compareTo(BigDecimal.ZERO)==0){ + suppliedToBeQuantityIncrease = BigDecimal.valueOf(100); + }else { + suppliedToBeQuantityIncrease = suppliedToBeQuantityNum.subtract(lastSuppliedToBeQuantityNum).divide(lastSuppliedToBeQuantityNum, 4, RoundingMode.HALF_UP); + suppliedToBeQuantityIncrease = suppliedToBeQuantityIncrease.multiply(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP); + } + return suppliedToBeQuantityIncrease; + } + + /** + * 工程总量 + * @param demandAndSupplyVo + * @return + */ + @Override + public Integer getProjectNum(DemandAndSupplyVo demandAndSupplyVo) { + return mainMapper.getProjectNum(); + } +} diff --git a/bonus-modules/bonus-material/src/main/resources/mapper/material/main/MainMapper.xml b/bonus-modules/bonus-material/src/main/resources/mapper/material/main/MainMapper.xml new file mode 100644 index 00000000..04bb628d --- /dev/null +++ b/bonus-modules/bonus-material/src/main/resources/mapper/material/main/MainMapper.xml @@ -0,0 +1,72 @@ + + + + + + + + + + +