From 32822b3f6a92db9932beb2277aa9b4a96c72d3d5 Mon Sep 17 00:00:00 2001 From: mashuai Date: Fri, 28 Mar 2025 11:16:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=BA=E5=85=B7=E4=B8=80=E8=A7=88=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/controller/MainController.java | 144 +++++++--- .../main/domain/DemandAndSupplyVo.java | 45 +++ .../material/main/domain/MaTypeHomeVo.java | 102 +++++++ .../material/main/mapper/MainMapper.java | 57 +++- .../material/main/service/MainService.java | 65 +++++ .../main/service/impl/MainServiceImpl.java | 272 +++++++++++++++++- .../RepairAuditDetailsController.java | 24 +- .../impl/RepairAuditDetailsServiceImpl.java | 37 ++- .../material/basic/ComplexQueryMapper.xml | 1 + .../mapper/material/main/MainMapper.xml | 218 +++++++++++--- 10 files changed, 857 insertions(+), 108 deletions(-) create mode 100644 bonus-modules/bonus-material/src/main/java/com/bonus/material/main/domain/MaTypeHomeVo.java 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 index ce28e08f..1d69a816 100644 --- 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 @@ -1,8 +1,8 @@ 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.domain.MaTypeHomeVo; import com.bonus.material.main.service.MainService; import io.swagger.annotations.Api; import lombok.extern.slf4j.Slf4j; @@ -12,8 +12,6 @@ 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; @@ -28,50 +26,112 @@ public class MainController { 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); + try { + //需求量 + 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); + //供应总件数(机具出库数量,不带条件查询) + BigDecimal outNum = mainService.getSuppliedQuantityNum(new DemandAndSupplyVo()); + // 供应总价值 + BigDecimal suppliedQuantityPrice = mainService.getSuppliedQuantityPrice(new DemandAndSupplyVo()); + demandAndSupplyVoRes.setDemandNum(demandNum); + demandAndSupplyVoRes.setDemandIncrease(demandIncrease); + demandAndSupplyVoRes.setSuppliedQuantityNum(suppliedQuantityNum); + demandAndSupplyVoRes.setSuppliedQuantityIncrease(suppliedQuantityIncrease); + demandAndSupplyVoRes.setSuppliedToBeQuantityNum(suppliedToBeQuantityNum); + demandAndSupplyVoRes.setSuppliedToBeQuantityIncrease(suppliedToBeQuantityIncrease); + demandAndSupplyVoRes.setProjectNum(projectNum); + demandAndSupplyVoRes.setSuppliedQuantityAllNum(outNum); + demandAndSupplyVoRes.setSuppliedQuantityPrice(suppliedQuantityPrice); + } catch (Exception e) { + return AjaxResult.error("查询机具需求供应情况失败"); + } return success(demandAndSupplyVoRes); } + + /** + * 查询机具仓储状态首页 + * @param dto + * @return + */ + @GetMapping("/getMaTypeHomeList") + public AjaxResult getMaTypeHome(MaTypeHomeVo dto) { + // 根据时间段查询当前仓储状态详情数据 + try { + return mainService.getInStockNum(dto); + } catch (Exception e) { + return AjaxResult.error("查询机具仓储状态首页失败"); + } + } + + /** + * todo 查询机具状态统计占比饼图(暂时弃用) + * @param dto + * @return + */ + @GetMapping("/getMaTypeStatusTotal") + public AjaxResult getMaTypeStatusTotal(MaTypeHomeVo dto) { + // 根据时间段查询当前仓储状态详情数据 + try { + return mainService.getMaTypeStatusTotal(dto); + } catch (Exception e) { + return AjaxResult.error("查询机具状态统计占比饼图失败"); + } + } + + /** + * 查询机具需求供应情况统计占比饼图 + * @param demandAndSupplyVo + * @return + */ + @GetMapping("/getDemandTotal") + public AjaxResult getDemandTotal(DemandAndSupplyVo demandAndSupplyVo) { + DemandAndSupplyVo vo = null; + try { + vo = new DemandAndSupplyVo(); + //需求量 + BigDecimal demandNum = mainService.getDemandNum(demandAndSupplyVo); + //已供应数量 + BigDecimal suppliedQuantityNum = mainService.getSuppliedQuantityNum(demandAndSupplyVo); + //待供应量 + BigDecimal suppliedToBeQuantityNum = mainService.getSuppliedToBeQuantityNum(demandAndSupplyVo); + vo.setDemandNum(demandNum); + vo.setSuppliedQuantityNum(suppliedQuantityNum); + vo.setSuppliedToBeQuantityNum(suppliedToBeQuantityNum); + } catch (Exception e) { + return AjaxResult.error("查询机具需求供应情况统计占比饼图失败"); + } + return success(vo); + } + + /** + * 查询机具需求供应情况统计柱状图 + * @param demandAndSupplyVo + * @return + */ + @GetMapping("/getDemandList") + public AjaxResult getDemandList(DemandAndSupplyVo demandAndSupplyVo) { + try { + return mainService.getDemandList(demandAndSupplyVo); + } catch (Exception e) { + return AjaxResult.error("查询机具需求供应情况统计柱状图失败"); + } + } } 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 index 1b723ea1..4ca31827 100644 --- 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 @@ -5,6 +5,7 @@ import lombok.Data; import java.math.BigDecimal; import java.time.LocalDate; +import java.util.List; @Data public class DemandAndSupplyVo { @@ -70,4 +71,48 @@ public class DemandAndSupplyVo { * 当前时间 */ private LocalDate currentDate; + + @ApiModelProperty(value = "往来单位id") + private Long unitId; + + @ApiModelProperty(value = "工程id") + private Long projectId; + + @ApiModelProperty(value = "设备单价") + private BigDecimal buyPrice; + + /** + * 设备类型id + */ + private Long typeId; + + /** + * 设备类型名称 + */ + private String typeName; + + /** + * 规格型号 + */ + private String typeModelName; + + /** + * 设备类型名称集合 + */ + private List typeNameList; + + /** + * 需求量集合 + */ + private List demandNumList; + + /** + * 已供应量集合 + */ + private List suppliedQuantityNumList; + + /** + * 待供应量集合 + */ + private List suppliedToBeQuantityNumList; } diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/main/domain/MaTypeHomeVo.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/main/domain/MaTypeHomeVo.java new file mode 100644 index 00000000..6832fb8b --- /dev/null +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/main/domain/MaTypeHomeVo.java @@ -0,0 +1,102 @@ +package com.bonus.material.main.domain; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.math.BigDecimal; + +/** + * 首页仓储状态供应一览表 + * @Author ma_sh + * @create 2025/3/27 14:25 + */ +@Data +public class MaTypeHomeVo { + + /** + * 在库数量 + */ + private BigDecimal inStockNum; + + /** + * 在库增长量 + */ + private BigDecimal inStockIncrease; + + /** + * 在用数量 + */ + private BigDecimal inUseNum; + + /** + * 在用增长量 + */ + private BigDecimal inUseIncrease; + + /** + * 在修数量 + */ + private BigDecimal inRepairNum; + + /** + * 在修增长量 + */ + private BigDecimal inRepairIncrease; + + /** + * 新购待入库量 + */ + private BigDecimal newPurchaseNum; + + /** + * 新购待入库增长量 + */ + private BigDecimal newPurchaseIncrease; + + /** + * 修饰待入库量 + */ + private BigDecimal newRepairNum; + + /** + * 修饰待入库增长量 + */ + private BigDecimal newRepairIncrease; + + /** + * 在库量占比 + */ + private BigDecimal inStockProportion; + + /** + * 在用量占比 + */ + private BigDecimal inUseProportion; + + /** + * 在修量占比 + */ + private BigDecimal inRepairProportion; + + /** + * 新购待入库量占比 + */ + private BigDecimal newPurchaseProportion; + + /** + * 修饰待入库量占比 + */ + private BigDecimal newRepairProportion; + + @ApiModelProperty(value = "开始时间") + private String startTime; + + @ApiModelProperty(value = "结束时间") + private String endTime; + + @ApiModelProperty(value = "往来单位id") + private Long unitId; + + @ApiModelProperty(value = "工程id") + private Long projectId; +} 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 index 93a14109..fbd0b469 100644 --- 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 @@ -2,16 +2,71 @@ package com.bonus.material.main.mapper; import com.bonus.common.biz.domain.lease.LeasePublishInfo; import com.bonus.material.main.domain.DemandAndSupplyVo; +import com.bonus.material.main.domain.MaTypeHomeVo; import java.math.BigDecimal; import java.util.List; public interface MainMapper { - List getPublishList(DemandAndSupplyVo demandAndSupplyVo); + /** + * 获取领料需求数量 + * @param demandAndSupplyVo + * @return + */ + LeasePublishInfo getPublishList(DemandAndSupplyVo demandAndSupplyVo); + /** + * 获取领用发布数量 + * @param demandAndSupplyVo + * @return + */ BigDecimal getPublishListNew(DemandAndSupplyVo demandAndSupplyVo); + /** + * 获取领料已出库数量 + * @param demandAndSupplyVo + * @return + */ BigDecimal getSuppliedQuantityNum(DemandAndSupplyVo demandAndSupplyVo); + /** + * 获取工程总数 + * @return + */ Integer getProjectNum(); + + /** + * 供应总价值 + * @param demandAndSupplyVo + * @return + */ + List getSuppliedQuantityPrice(DemandAndSupplyVo demandAndSupplyVo); + + /** + * 查询领料需求列表 + * @param demandAndSupplyVo + * @return + */ + List getDemandList(DemandAndSupplyVo demandAndSupplyVo); + + /** + * 查询领用需求列表 + * @param demandAndSupplyVo + * @return + */ + List getUseList(DemandAndSupplyVo demandAndSupplyVo); + + /** + * 查询领用已出库列表 + * @param demandAndSupplyVo + * @return + */ + List getSuppliedQuantityList(DemandAndSupplyVo demandAndSupplyVo); + + /** + * 获取所选当前时间数据 + * @param dto + * @return + */ + MaTypeHomeVo getInStockNum(MaTypeHomeVo dto); } 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 index df6d30c7..6e9b7b4e 100644 --- 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 @@ -1,21 +1,86 @@ package com.bonus.material.main.service; +import com.bonus.common.core.web.domain.AjaxResult; import com.bonus.material.main.domain.DemandAndSupplyVo; +import com.bonus.material.main.domain.MaTypeHomeVo; import java.math.BigDecimal; public interface MainService { + /** + * 需求数量 + * @param demandAndSupplyVo + * @return + */ BigDecimal getDemandNum(DemandAndSupplyVo demandAndSupplyVo); + /** + * 需求数量增长量 + * @param demandAndSupplyVo + * @return + */ BigDecimal getDemandIncrease(DemandAndSupplyVo demandAndSupplyVo); + /** + * 已供应数量 + * @param demandAndSupplyVo + * @return + */ BigDecimal getSuppliedQuantityNum(DemandAndSupplyVo demandAndSupplyVo); + /** + * 已供应数量增长量 + * @param demandAndSupplyVo + * @return + */ BigDecimal getSuppliedQuantityIncrease(DemandAndSupplyVo demandAndSupplyVo); + /** + * 待供应数量 + * @param demandAndSupplyVo + * @return + */ BigDecimal getSuppliedToBeQuantityNum(DemandAndSupplyVo demandAndSupplyVo); + /** + * 待供应数量增长量 + * @param demandAndSupplyVo + * @return + */ BigDecimal getSuppliedToBeQuantityIncrease(DemandAndSupplyVo demandAndSupplyVo); + /** + * 未结算工程数量 + * @param demandAndSupplyVo + * @return + */ Integer getProjectNum(DemandAndSupplyVo demandAndSupplyVo); + + /** + * 供应总价值 + * @param demandAndSupplyVo + * @return + */ + BigDecimal getSuppliedQuantityPrice(DemandAndSupplyVo demandAndSupplyVo); + + /** + * 根据时间段查询当前仓储状态详情数据 + * @param dto + * @return + */ + AjaxResult getInStockNum(MaTypeHomeVo dto); + + /** + * 需求列表 + * @param demandAndSupplyVo + * @return + */ + AjaxResult getDemandList(DemandAndSupplyVo demandAndSupplyVo); + + /** + * 查询机具状态统计占比饼图 + * @param dto + * @return + */ + AjaxResult getMaTypeStatusTotal(MaTypeHomeVo dto); } 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 index 29470d29..1961dd33 100644 --- 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 @@ -1,9 +1,9 @@ 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.common.core.web.domain.AjaxResult; import com.bonus.material.main.domain.DemandAndSupplyVo; +import com.bonus.material.main.domain.MaTypeHomeVo; import com.bonus.material.main.mapper.MainMapper; import com.bonus.material.main.service.MainService; import lombok.extern.slf4j.Slf4j; @@ -16,9 +16,11 @@ import java.math.BigDecimal; import java.math.RoundingMode; import java.time.LocalDate; import java.time.format.DateTimeFormatter; -import java.util.List; +import java.util.*; import java.util.stream.Collectors; +import static com.bonus.common.core.web.domain.AjaxResult.success; + @Service @Slf4j public class MainServiceImpl implements MainService { @@ -34,9 +36,8 @@ public class MainServiceImpl implements MainService { @Override public BigDecimal getDemandNum(DemandAndSupplyVo demandAndSupplyVo) { //获取领料的需求数量 - List list = mainMapper.getPublishList(demandAndSupplyVo); - BigDecimal preCountNum = list.stream().map(LeasePublishInfo::getPreCountNum) - .reduce(BigDecimal.ZERO, BigDecimal::add); + LeasePublishInfo leasePublishInfo = mainMapper.getPublishList(demandAndSupplyVo); + BigDecimal preCountNum = leasePublishInfo.getPreCountNum(); //获取领用的需求数量 BigDecimal preCountNumNew = mainMapper.getPublishListNew(demandAndSupplyVo); preCountNum = preCountNum.add(preCountNumNew); @@ -70,9 +71,11 @@ public class MainServiceImpl implements MainService { BigDecimal lastPreCountNum = this.getDemandNum(demandAndSupplyVoNew); //计算增长量 BigDecimal demandIncrease= BigDecimal.ZERO; - if (lastPreCountNum.compareTo(BigDecimal.ZERO)==0){ + if (lastPreCountNum.compareTo(BigDecimal.ZERO)==0 && preCountNum.compareTo(BigDecimal.ZERO) > 0){ demandIncrease = BigDecimal.valueOf(100); - }else { + }else if (preCountNum.compareTo(BigDecimal.ZERO)==0 && lastPreCountNum.compareTo(BigDecimal.ZERO) > 0){ + demandIncrease = BigDecimal.valueOf(-100); + }else if (lastPreCountNum.compareTo(BigDecimal.ZERO) > 0){ demandIncrease = preCountNum.subtract(lastPreCountNum).divide(lastPreCountNum, 4, RoundingMode.HALF_UP); demandIncrease = demandIncrease.multiply(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP); } @@ -88,8 +91,7 @@ public class MainServiceImpl implements MainService { @Override public BigDecimal getSuppliedQuantityNum(DemandAndSupplyVo demandAndSupplyVo) { //已供应量 - BigDecimal suppliedQuantityNum = mainMapper.getSuppliedQuantityNum(demandAndSupplyVo); - return suppliedQuantityNum; + return mainMapper.getSuppliedQuantityNum(demandAndSupplyVo); } /** @@ -119,9 +121,11 @@ public class MainServiceImpl implements MainService { BigDecimal lastSuppliedQuantityNum = this.getSuppliedQuantityNum(demandAndSupplyVoNew); //计算增长量 BigDecimal suppliedQuantityIncrease = BigDecimal.ZERO; - if (lastSuppliedQuantityNum.compareTo(BigDecimal.ZERO)==0){ + if (lastSuppliedQuantityNum.compareTo(BigDecimal.ZERO)==0 && suppliedQuantityNum.compareTo(BigDecimal.ZERO) > 0){ suppliedQuantityIncrease = BigDecimal.valueOf(100); - }else { + }else if (suppliedQuantityNum.compareTo(BigDecimal.ZERO)==0 && lastSuppliedQuantityNum.compareTo(BigDecimal.ZERO) > 0){ + suppliedQuantityIncrease = BigDecimal.valueOf(-100); + } else if (lastSuppliedQuantityNum.compareTo(BigDecimal.ZERO) > 0){ suppliedQuantityIncrease = suppliedQuantityNum.subtract(lastSuppliedQuantityNum).divide(lastSuppliedQuantityNum, 4, RoundingMode.HALF_UP); suppliedQuantityIncrease = suppliedQuantityIncrease.multiply(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP); } @@ -172,9 +176,11 @@ public class MainServiceImpl implements MainService { BigDecimal lastSuppliedToBeQuantityNum = this.getSuppliedToBeQuantityNum(demandAndSupplyVoNew); //计算增长量 BigDecimal suppliedToBeQuantityIncrease = BigDecimal.ZERO; - if (lastSuppliedToBeQuantityNum.compareTo(BigDecimal.ZERO)==0){ + if (lastSuppliedToBeQuantityNum.compareTo(BigDecimal.ZERO)==0 && suppliedToBeQuantityNum.compareTo(BigDecimal.ZERO) > 0){ suppliedToBeQuantityIncrease = BigDecimal.valueOf(100); - }else { + }else if (suppliedToBeQuantityNum.compareTo(BigDecimal.ZERO)==0 && lastSuppliedToBeQuantityNum.compareTo(BigDecimal.ZERO) > 0){ + suppliedToBeQuantityIncrease = BigDecimal.valueOf(-100); + }else if (lastSuppliedToBeQuantityNum.compareTo(BigDecimal.ZERO) > 0){ suppliedToBeQuantityIncrease = suppliedToBeQuantityNum.subtract(lastSuppliedToBeQuantityNum).divide(lastSuppliedToBeQuantityNum, 4, RoundingMode.HALF_UP); suppliedToBeQuantityIncrease = suppliedToBeQuantityIncrease.multiply(BigDecimal.valueOf(100)).setScale(2, RoundingMode.HALF_UP); } @@ -182,7 +188,7 @@ public class MainServiceImpl implements MainService { } /** - * 工程总量 + * 获取未结算工程总数 * @param demandAndSupplyVo * @return */ @@ -190,4 +196,240 @@ public class MainServiceImpl implements MainService { public Integer getProjectNum(DemandAndSupplyVo demandAndSupplyVo) { return mainMapper.getProjectNum(); } + + /** + * 供应总价值 + * @param demandAndSupplyVo + * @return + */ + @Override + public BigDecimal getSuppliedQuantityPrice(DemandAndSupplyVo demandAndSupplyVo) { + BigDecimal supplyPrice = BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP); + List list = mainMapper.getSuppliedQuantityPrice(demandAndSupplyVo); + if (!CollectionUtils.isEmpty(list)) { + for (DemandAndSupplyVo andSupplyVo : list) { + supplyPrice = supplyPrice.add(andSupplyVo.getSuppliedQuantityNum().multiply(andSupplyVo.getBuyPrice())); + } + // 总计算结果换算为万元 + supplyPrice = supplyPrice.divide(BigDecimal.valueOf(10000), 2, RoundingMode.HALF_UP); + } + return supplyPrice; + } + + /** + * 根据时间段查询当前仓储状态详情数据 + * @param dto + * @return + */ + @Override + public AjaxResult getInStockNum(MaTypeHomeVo dto) { + // 根据时间段查询当前仓储状态详情数据 + // 获取所选当前时间数据 + MaTypeHomeVo resultVo = mainMapper.getInStockNum(dto); + + // 根据所选时间段查询上一个月的数据 + if (dto.getStartTime() != null && !dto.getStartTime().isEmpty() && dto.getEndTime() != null && !dto.getEndTime().isEmpty()) { + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + try { + LocalDate startDate = LocalDate.parse(dto.getStartTime(), formatter); + LocalDate endDate = LocalDate.parse(dto.getEndTime(), formatter); + // 获取上月同期开始时间 + LocalDate lastMonthStart = startDate.minusMonths(1); + // 获取上月同期结束时间 + LocalDate lastMonthEnd = endDate.minusMonths(1); + dto.setStartTime(lastMonthStart.format(formatter)); + dto.setEndTime(lastMonthEnd.format(formatter)); + MaTypeHomeVo lastMonthResultVo = mainMapper.getInStockNum(dto); + + // 计算各项增长量 + resultVo.setInStockIncrease(calculateIncrease(resultVo.getInStockNum(), lastMonthResultVo.getInStockNum())); + resultVo.setInUseIncrease(calculateIncrease(resultVo.getInUseNum(), lastMonthResultVo.getInUseNum())); + resultVo.setInRepairIncrease(calculateIncrease(resultVo.getInRepairNum(), lastMonthResultVo.getInRepairNum())); + resultVo.setNewPurchaseIncrease(calculateIncrease(resultVo.getNewPurchaseNum(), lastMonthResultVo.getNewPurchaseNum())); + resultVo.setNewRepairIncrease(calculateIncrease(resultVo.getNewRepairNum(), lastMonthResultVo.getNewRepairNum())); + } catch (Exception e) { + // 处理日期解析异常 + throw new RuntimeException("日期解析出错", e); + } + } + return success(resultVo); + } + + /** + * 获取机具设备状态总数据 + * @param dto + * @return + */ + @Override + public AjaxResult getMaTypeStatusTotal(MaTypeHomeVo dto) { + BigDecimal totalNum = BigDecimal.ZERO.setScale(3, RoundingMode.HALF_UP); + BigDecimal inStockProportion = BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP); + BigDecimal inUseProportion = BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP); + BigDecimal inRepairProportion = BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP); + BigDecimal newPurchaseProportion = BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP); + BigDecimal newRepairProportion = BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP); + // 获取所选当前时间数据 + MaTypeHomeVo resultVo = mainMapper.getInStockNum(dto); + if (resultVo != null) { + totalNum = totalNum.add(resultVo.getInStockNum()).add(resultVo.getInUseNum()).add(resultVo.getInRepairNum()).add(resultVo.getNewPurchaseNum()).add(resultVo.getNewRepairNum()); + // 计算需求量百分占比,结果保留2位小数 + if (totalNum.compareTo(BigDecimal.ZERO) != 0) { + inStockProportion = resultVo.getInStockNum().divide(totalNum, 4, RoundingMode.HALF_UP).multiply(BigDecimal.valueOf(100)); + inUseProportion = resultVo.getInUseNum().divide(totalNum, 4, RoundingMode.HALF_UP) + .multiply(BigDecimal.valueOf(100)); + inRepairProportion = resultVo.getInRepairNum().divide(totalNum, 4, RoundingMode.HALF_UP) + .multiply(BigDecimal.valueOf(100)); + newPurchaseProportion = resultVo.getNewPurchaseNum().divide(totalNum, 4, RoundingMode.HALF_UP) + .multiply(BigDecimal.valueOf(100)); + newRepairProportion = resultVo.getNewRepairNum().divide(totalNum, 4, RoundingMode.HALF_UP) + .multiply(BigDecimal.valueOf(100)); + } + } + resultVo.setInStockProportion(inStockProportion); + resultVo.setInUseProportion(inUseProportion); + resultVo.setInRepairProportion(inRepairProportion); + resultVo.setNewPurchaseProportion(newPurchaseProportion); + resultVo.setNewRepairProportion(newRepairProportion); + return success(resultVo); + } + + /** + * 计算增长量 + * @param currentNum + * @param lastMonthNum + * @return + */ + private BigDecimal calculateIncrease(BigDecimal currentNum, BigDecimal lastMonthNum) { + if (lastMonthNum.compareTo(BigDecimal.ZERO) == 0 && currentNum.compareTo(BigDecimal.ZERO) > 0) { + return BigDecimal.valueOf(100); + } else if (currentNum.compareTo(BigDecimal.ZERO) == 0 && lastMonthNum.compareTo(BigDecimal.ZERO) > 0) { + return BigDecimal.valueOf(-100); + } else if (lastMonthNum.compareTo(BigDecimal.ZERO) > 0) { + return currentNum.subtract(lastMonthNum) + .divide(lastMonthNum, 4, RoundingMode.HALF_UP) + .multiply(BigDecimal.valueOf(100)) + .setScale(2, RoundingMode.HALF_UP); + } + return BigDecimal.ZERO; + } + /** + * 需求列表 + * @param demandAndSupplyVo + * @return + */ + @Override + public AjaxResult getDemandList(DemandAndSupplyVo demandAndSupplyVo) { + DemandAndSupplyVo resultVo = new DemandAndSupplyVo(); + List typeNameList = new ArrayList<>(); + List demandNumList = new ArrayList<>(); + List suppliedQuantityNumList = new ArrayList<>(); + List suppliedToBeQuantityNumList = new ArrayList<>(); + + // 查询列表 + List demandList = mainMapper.getDemandList(demandAndSupplyVo); + List useList = mainMapper.getUseList(demandAndSupplyVo); + List suppliedQuantityList = mainMapper.getSuppliedQuantityList(demandAndSupplyVo); + + // 过滤 suppliedQuantityNum 为 0 的数据 + suppliedQuantityList = filterZeroSuppliedQuantity(suppliedQuantityList); + + // 合并 demandNum + mergeDemandNum(demandList, useList); + + // 提取需求量排名前 10 的数据 + demandList = getTop10DemandList(demandList); + + // 构建结果列表 + buildResultLists(demandList, suppliedQuantityList, typeNameList, demandNumList, suppliedQuantityNumList, suppliedToBeQuantityNumList); + + // 设置结果 + resultVo.setTypeNameList(typeNameList); + resultVo.setDemandNumList(demandNumList); + resultVo.setSuppliedQuantityNumList(suppliedQuantityNumList); + resultVo.setSuppliedToBeQuantityNumList(suppliedToBeQuantityNumList); + + return success(resultVo); + } + + /** + * 过滤数量为0的数据 + * @param suppliedQuantityList + * @return + */ + private static List filterZeroSuppliedQuantity(List suppliedQuantityList) { + return suppliedQuantityList.stream() + .filter(item -> item.getSuppliedQuantityNum().compareTo(BigDecimal.ZERO) != 0) + .collect(Collectors.toList()); + } + + /** + * 合并总需求量 + * @param demandList + * @param useList + */ + private static void mergeDemandNum(List demandList, List useList) { + // 创建一个 Map 用于存储 typeId 对应的 DemandAndSupplyVo 对象 + Map typeIdMap = new HashMap<>(); + // 将 demandList 中的元素放入 Map 中 + for (DemandAndSupplyVo vo : demandList) { + typeIdMap.put(vo.getTypeId(), vo); + } + // 遍历 useList,合并 demandNum + for (DemandAndSupplyVo vo : useList) { + Long typeId = vo.getTypeId(); + if (typeIdMap.containsKey(typeId)) { + // 如果 Map 中已经存在该 typeId,则合并 demandNum + DemandAndSupplyVo existingVo = typeIdMap.get(typeId); + existingVo.setDemandNum(existingVo.getDemandNum().add(vo.getDemandNum())); + } else { + // 如果 Map 中不存在该 typeId,则将该元素添加到 Map 中 + typeIdMap.put(typeId, vo); + } + } + demandList.clear(); + demandList.addAll(typeIdMap.values()); + } + + /** + * 去总数量前10的数据 + * @param demandList + * @return + */ + private static List getTop10DemandList(List demandList) { + return demandList.stream() + .sorted(Comparator.comparing(DemandAndSupplyVo::getDemandNum).reversed()) + .limit(10) + .collect(Collectors.toList()); + } + + /** + * 构建数据 + * @param demandList + * @param suppliedQuantityList + * @param typeNameList + * @param demandNumList + * @param suppliedQuantityNumList + * @param suppliedToBeQuantityNumList + */ + private static void buildResultLists(List demandList, List suppliedQuantityList, + List typeNameList, List demandNumList, + List suppliedQuantityNumList, List suppliedToBeQuantityNumList) { + Map suppliedQuantityMap = suppliedQuantityList.stream() + .collect(Collectors.toMap(DemandAndSupplyVo::getTypeId, vo -> vo, (existing, replacement) -> existing)); + for (DemandAndSupplyVo demandVo : demandList) { + Long typeId = demandVo.getTypeId(); + if (suppliedQuantityMap.containsKey(typeId)) { + DemandAndSupplyVo suppliedQuantityVo = suppliedQuantityMap.get(typeId); + typeNameList.add(demandVo.getTypeName() + demandVo.getTypeModelName()); + demandNumList.add(demandVo.getDemandNum()); + suppliedQuantityNumList.add(suppliedQuantityVo.getSuppliedQuantityNum()); + suppliedToBeQuantityNumList.add(demandVo.getDemandNum().subtract(suppliedQuantityVo.getSuppliedQuantityNum())); + } else { + typeNameList.add(demandVo.getTypeName() + demandVo.getTypeModelName()); + demandNumList.add(demandVo.getDemandNum()); + suppliedQuantityNumList.add(BigDecimal.ZERO); + suppliedToBeQuantityNumList.add(demandVo.getDemandNum()); + } + } + } } diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/repair/controller/RepairAuditDetailsController.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/repair/controller/RepairAuditDetailsController.java index 6d538b18..930fedcb 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/repair/controller/RepairAuditDetailsController.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/repair/controller/RepairAuditDetailsController.java @@ -256,11 +256,15 @@ public class RepairAuditDetailsController extends BaseController { @ApiOperation(value = "查询修饰一览表") @GetMapping("/getRepairHomeList") public AjaxResult getRepairHomeList(RepairHomeInfo dto) { - dto.setIsExport(1); - Integer pageIndex = Convert.toInt(ServletUtils.getParameter("pageNum"), 1); - Integer pageSize = Convert.toInt(ServletUtils.getParameter("pageSize"), 10); - List pageList = repairAuditDetailsService.getRepairHomeList(dto); - return AjaxResult.success(ListPagingUtil.paging(pageIndex, pageSize, pageList)); + try { + dto.setIsExport(1); + Integer pageIndex = Convert.toInt(ServletUtils.getParameter("pageNum"), 1); + Integer pageSize = Convert.toInt(ServletUtils.getParameter("pageSize"), 10); + List pageList = repairAuditDetailsService.getRepairHomeList(dto); + return AjaxResult.success(ListPagingUtil.paging(pageIndex, pageSize, pageList)); + } catch (Exception e) { + return error("查询修饰一览表失败, " + e.getMessage()); + } } /** @@ -271,9 +275,13 @@ public class RepairAuditDetailsController extends BaseController { @ApiOperation(value = "查询修饰一览表总计") @GetMapping("/getRepairHomeTotalList") public AjaxResult getRepairHomeTotalList(RepairHomeInfo dto) { - dto.setIsExport(0); - List pageList = repairAuditDetailsService.getRepairHomeTotalList(dto); - return AjaxResult.success(pageList); + try { + dto.setIsExport(0); + List pageList = repairAuditDetailsService.getRepairHomeTotalList(dto); + return AjaxResult.success(pageList); + } catch (Exception e) { + return error("查询修饰一览表总计失败, " + e.getMessage()); + } } /** diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/repair/service/impl/RepairAuditDetailsServiceImpl.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/repair/service/impl/RepairAuditDetailsServiceImpl.java index 04dd6da4..96b41d0e 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/repair/service/impl/RepairAuditDetailsServiceImpl.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/repair/service/impl/RepairAuditDetailsServiceImpl.java @@ -1061,32 +1061,57 @@ public class RepairAuditDetailsServiceImpl implements IRepairAuditDetailsService info.setIsIncrease(true); infos.add(info); } else if (!CollectionUtils.isEmpty(lastMonthList) && CollectionUtils.isEmpty(repairHomeList)) { - RepairHomeInfo lastMonthInfo = lastMonthList.get(0); RepairHomeInfo info = new RepairHomeInfo(); - info.setBackNum(lastMonthInfo.getBackNum()); + info.setBackNum(BigDecimal.ZERO); info.setIncrease(BigDecimal.valueOf(100)); info.setIsIncrease(false); infos.add(info); info = new RepairHomeInfo(); - info.setRepairedNum(lastMonthInfo.getRepairedNum()); + info.setRepairedNum(BigDecimal.ZERO); info.setIncrease(BigDecimal.valueOf(100)); info.setIsIncrease(false); infos.add(info); info = new RepairHomeInfo(); - info.setRepairingNum(lastMonthInfo.getRepairingNum()); + info.setRepairingNum(BigDecimal.ZERO); info.setIncrease(BigDecimal.valueOf(100)); info.setIsIncrease(false); infos.add(info); info = new RepairHomeInfo(); - info.setScrapNum(lastMonthInfo.getScrapNum()); + info.setScrapNum(BigDecimal.ZERO); info.setIncrease(BigDecimal.valueOf(100)); info.setIsIncrease(false); infos.add(info); info = new RepairHomeInfo(); - info.setTestNum(lastMonthInfo.getTestNum()); + info.setTestNum(BigDecimal.ZERO); info.setIncrease(BigDecimal.valueOf(100)); info.setIsIncrease(false); infos.add(info); + } else { + RepairHomeInfo info = new RepairHomeInfo(); + info.setBackNum(BigDecimal.ZERO); + info.setIncrease(BigDecimal.ZERO); + info.setIsIncrease(true); + infos.add(info); + info = new RepairHomeInfo(); + info.setRepairedNum(BigDecimal.ZERO); + info.setIncrease(BigDecimal.ZERO); + info.setIsIncrease(true); + infos.add(info); + info = new RepairHomeInfo(); + info.setRepairingNum(BigDecimal.ZERO); + info.setIncrease(BigDecimal.ZERO); + info.setIsIncrease(true); + infos.add(info); + info = new RepairHomeInfo(); + info.setScrapNum(BigDecimal.ZERO); + info.setIncrease(BigDecimal.ZERO); + info.setIsIncrease(true); + infos.add(info); + info = new RepairHomeInfo(); + info.setTestNum(BigDecimal.ZERO); + info.setIncrease(BigDecimal.ZERO); + info.setIsIncrease(true); + infos.add(info); } } return infos; diff --git a/bonus-modules/bonus-material/src/main/resources/mapper/material/basic/ComplexQueryMapper.xml b/bonus-modules/bonus-material/src/main/resources/mapper/material/basic/ComplexQueryMapper.xml index ab0ce088..d8669273 100644 --- a/bonus-modules/bonus-material/src/main/resources/mapper/material/basic/ComplexQueryMapper.xml +++ b/bonus-modules/bonus-material/src/main/resources/mapper/material/basic/ComplexQueryMapper.xml @@ -482,6 +482,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" LEFT JOIN ma_type mt3 ON mt3.type_id = mt2.parent_id LEFT JOIN ma_type mt4 ON mt4.type_id = mt3.parent_id LEFT JOIN ma_machine mm ON mm.ma_id = bcd.ma_id + WHERE bcd.is_finished = '1' GROUP BY mt.type_id) AS subquery2 ON subquery1.type_id = subquery2.type_id) AS subquery1 ON mt.type_id = subquery1.type_id 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 index 04bb628d..73958e37 100644 --- 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 @@ -6,67 +6,213 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + + + + + + + + + +