From ae8560feb7990694f73842a973d0af2698277dd7 Mon Sep 17 00:00:00 2001 From: syruan <321359594@qq.com> Date: Fri, 24 Jan 2025 17:08:03 +0800 Subject: [PATCH] =?UTF-8?q?i=E7=9A=96=E9=80=81=E6=8E=A8=E9=80=81=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/PurchaseCheckInfoServiceImpl.java | 4 +- .../controller/IwsCostPushController.java | 27 ++- .../material/push/domain/IwsCostPushBean.java | 36 ++- .../push/mapper/IwsCostPushMapper.java | 13 +- .../push/service/IwsCostPushService.java | 11 + .../service/impl/IwsCostPushServiceImpl.java | 216 ++++++++++++++++++ .../material/push/IwsCostPushMapper.xml | 51 +++-- 7 files changed, 332 insertions(+), 26 deletions(-) diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/purchase/service/impl/PurchaseCheckInfoServiceImpl.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/purchase/service/impl/PurchaseCheckInfoServiceImpl.java index aeb98292..bd35a526 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/purchase/service/impl/PurchaseCheckInfoServiceImpl.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/purchase/service/impl/PurchaseCheckInfoServiceImpl.java @@ -538,14 +538,14 @@ public class PurchaseCheckInfoServiceImpl implements IPurchaseCheckInfoService { details.setStatus(PurchaseTaskStatusEnum.TO_STORE.getStatus()); } details.setCheckUser(SecurityUtils.getUserId()); - result = purchaseCheckDetailsMapper.updatePurchaseDetails4Check(details) > 0 ? AjaxResult.success("detail验证成功") : AjaxResult.error("details无验证信息"); + result = 0 < purchaseCheckDetailsMapper.updatePurchaseDetails4Check(details) ? AjaxResult.success("验收成功") : AjaxResult.error("details无验证信息"); extractedFile(details); } } else { // 验收驳回处理流程 for (PurchaseCheckDetails details : purchaseVerifyVo.getPurchaseCheckDetailsList()) { details.setStatus(PurchaseTaskStatusEnum.TO_CHECK_AFTER_REJECT.getStatus()); - result = 0 < purchaseCheckDetailsMapper.updatePurchaseDetails4Check(details) ? AjaxResult.success("detail验证驳回成功") : AjaxResult.error("details无验证信息"); + result = 0 < purchaseCheckDetailsMapper.updatePurchaseDetails4Check(details) ? AjaxResult.success("驳回成功") : AjaxResult.error("details无验证信息"); extractedFile(details); } } diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/controller/IwsCostPushController.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/controller/IwsCostPushController.java index b4639789..3b8fc1f3 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/controller/IwsCostPushController.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/controller/IwsCostPushController.java @@ -2,6 +2,7 @@ package com.bonus.material.push.controller; import com.bonus.common.core.utils.poi.ExcelUtil; import com.bonus.common.core.web.controller.BaseController; +import com.bonus.common.core.web.domain.AjaxResult; import com.bonus.common.core.web.page.TableDataInfo; import com.bonus.material.push.domain.IwsCostPushBean; import com.bonus.material.push.service.IwsCostPushService; @@ -13,7 +14,9 @@ import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; import javax.validation.constraints.NotNull; +import java.util.Collections; import java.util.List; +import java.util.Objects; /** * @author : 阮世耀 @@ -54,7 +57,6 @@ public class IwsCostPushController extends BaseController { util.exportExcel(response, list, "协议推送匹配"); } - /** * 查询费用推送审核列表 * @param obj 查询条件 @@ -67,4 +69,27 @@ public class IwsCostPushController extends BaseController { return getDataTable(list); } + /** + * 根据协议ID及月份查询当月租赁费用明细 + * @param obj 查询条件 + * @return 分页数据 + */ + @GetMapping("/getLeaseCostsByAgreementIdAndMonth") + @ApiOperation("根据协议ID及月份查询当月租赁费用明细--分页") + public TableDataInfo getLeaseCostsByAgreementIdAndMonth(IwsCostPushBean obj) { + if (Objects.isNull(obj) || Objects.isNull(obj.getAgreementId()) || Objects.isNull(obj.getMonth())) { + System.err.println("查询信息为空 = " + obj); + return getDataTable(Collections.emptyList()); + } + //startPage(); 取消分页 + List list = iwsCostPushService.getLeaseCostsByAgreementIdAndMonth(obj); + return getDataTable(list); + } + + @PostMapping("/computeTheMonthCost") + @ApiOperation("计算当月费用") + public AjaxResult computeTheMonthCost(@Valid @RequestBody IwsCostPushBean obj) { + return iwsCostPushService.computeTheMonthCost(obj); + } + } diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/domain/IwsCostPushBean.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/domain/IwsCostPushBean.java index 2267b08c..27910e9d 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/domain/IwsCostPushBean.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/domain/IwsCostPushBean.java @@ -8,6 +8,7 @@ import lombok.Data; import javax.validation.constraints.NotBlank; import javax.validation.constraints.Size; import java.io.Serializable; +import java.math.BigDecimal; import java.time.LocalDateTime; import java.util.List; @@ -45,18 +46,33 @@ public class IwsCostPushBean implements Serializable { @Excel(name = "单位名称", sort = 2) private String unitName; + // 物资类型 private String typeName; + // 规格型号 private String modelName; + // 物资类型id + private Integer typeId; + + // 数量 private String num; + // 领用数量 + private BigDecimal leaseNum; + // 领料日期 - private String leaseDate; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private LocalDateTime leaseDate; - private String backDate; + // 领用天数 + private Integer leaseDays; - private String leaseMoney; + // 退料日期 + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private LocalDateTime backDate; + + private BigDecimal leaseMoney; private String lostMoney; @@ -74,6 +90,7 @@ public class IwsCostPushBean implements Serializable { private String type; + // 原值 private String buyPrice; // 是否推送 @@ -90,7 +107,7 @@ public class IwsCostPushBean implements Serializable { // 结算时间 @Excel(name = "结算时间", dateFormat = "yyyy-MM-dd HH:mm:ss", sort = 7) - @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") private LocalDateTime settlementTime; // 是否匹配 @@ -99,8 +116,6 @@ public class IwsCostPushBean implements Serializable { private String userName; - private List ids; - @ApiModelProperty(value = "审核状态") private Byte checkStatus; @@ -108,4 +123,13 @@ public class IwsCostPushBean implements Serializable { private String pushRemark; private String companyId; + + // 开始时间 + private String startTime; + + // 结束时间 + private String endTime; + + // 是否删除 false未删除 true已删除 + private boolean delFlag = false; } diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/mapper/IwsCostPushMapper.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/mapper/IwsCostPushMapper.java index 14324a09..2d7100aa 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/mapper/IwsCostPushMapper.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/mapper/IwsCostPushMapper.java @@ -21,7 +21,7 @@ public interface IwsCostPushMapper { List findAgreement(IwsCostPushBean o); /** - * 更新协议push状态 + * 更新协议信息表的push状态 */ int updateAgreementIsPush(IwsCostPushBean o); @@ -29,4 +29,15 @@ public interface IwsCostPushMapper { * 查询费用推送审核数据列表 */ List getCostPushCheckList(IwsCostPushBean o); + + /** + * 插入Calc表当前月份 + */ + int insertCalcMonthRecord(IwsCostPushBean record); + + /** + * 根据协议ID查询领用物资数据 + * @param record 协议信息及条件 + */ + List getPaidSltBaseInfo(IwsCostPushBean record); } diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/service/IwsCostPushService.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/service/IwsCostPushService.java index 115b512f..56432a4a 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/service/IwsCostPushService.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/service/IwsCostPushService.java @@ -1,5 +1,6 @@ package com.bonus.material.push.service; +import com.bonus.common.core.web.domain.AjaxResult; import com.bonus.material.push.domain.IwsCostPushBean; import java.util.List; @@ -23,4 +24,14 @@ public interface IwsCostPushService { * 查询费用推送审核数据列表 */ List getCostPushCheckList(IwsCostPushBean o); + + /** + * 计算月结费用 + */ + AjaxResult computeTheMonthCost(IwsCostPushBean costDto); + + /** + * 根据协议ID及月份查询当月租赁费用明细 + */ + List getLeaseCostsByAgreementIdAndMonth(IwsCostPushBean record); } diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/service/impl/IwsCostPushServiceImpl.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/service/impl/IwsCostPushServiceImpl.java index 7a94e1c0..6dccb012 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/service/impl/IwsCostPushServiceImpl.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/push/service/impl/IwsCostPushServiceImpl.java @@ -1,13 +1,25 @@ package com.bonus.material.push.service.impl; +import com.alibaba.nacos.common.utils.CollectionUtils; +import com.bonus.common.biz.config.DateTimeHelper; +import com.bonus.common.core.utils.StringUtils; +import com.bonus.common.core.web.domain.AjaxResult; import com.bonus.material.push.domain.IwsCostPushBean; import com.bonus.material.push.mapper.IwsCostPushMapper; import com.bonus.material.push.service.IwsCostPushService; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.math.BigDecimal; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.time.temporal.ChronoUnit; +import java.time.temporal.TemporalAdjusters; +import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Objects; /** * @author : 阮世耀 @@ -41,4 +53,208 @@ public class IwsCostPushServiceImpl implements IwsCostPushService { public List getCostPushCheckList(IwsCostPushBean o) { return iwsCostPushMapper.getCostPushCheckList(o); } + + /** + * 计算月结费用 + * + * @param costDto IwsCostPushBean对象,包含月结费用计算的所需信息 + * @return 返回一个AjaxResult对象,包含月结费用计算的结果 + */ + @Override + public AjaxResult computeTheMonthCost(IwsCostPushBean costDto) { + + // 获取当月第一天的日期和最后一天日期 + String firstDay = DateTimeHelper.getFirstDay(); + String lastDay = DateTimeHelper.getLastDay(); + // 获取当前年月 2025-01 + String month = DateTimeHelper.getNowMonth(); + + costDto.setMonth(month); + costDto.setStartTime(firstDay); + costDto.setEndTime(lastDay); + + // 清除旧的费用计算数据 + // cleanSameMonthOldRecords(record); + + // 插入新的当前月份记录,并生成 + iwsCostPushMapper.insertCalcMonthRecord(costDto); + + String taskId = costDto.getId(); + + // 查询协议信息列表 + List agreementList = iwsCostPushMapper.findAgreement(costDto); + + // 处理数据 + computeMonthInfoDetail(agreementList, costDto, taskId, month); + + // TODO 未完成费用结算 待完善 + return null; + } + + /** + * 根据协议ID及月份查询当月租赁费用明细 + * + * @param record 查询信息 + */ + @Override + public List getLeaseCostsByAgreementIdAndMonth(IwsCostPushBean record) { + if (Objects.isNull(record) || Objects.isNull(record.getMonth()) || Objects.isNull(record.getAgreementId())) { + System.err.println("查询信息为空 = " + record); + return Collections.emptyList(); + } + + // 获取前端传入对应年月的第一天与最后一天的LocalDateTime对象 + LocalDateTime queryStartTime = getFirstDayOfMonth(record.getMonth()); + LocalDateTime queryEndTime = getLastDayOfMonthZ(record.getMonth()); + + List theMonthAgreementLeaseList = iwsCostPushMapper.getPaidSltBaseInfo(record); + if (CollectionUtils.isEmpty(theMonthAgreementLeaseList)) { + return Collections.emptyList(); + } else { + // 过滤异常数据 + theMonthAgreementLeaseList.removeIf(item -> + Objects.isNull(item) || + Objects.isNull(item.getTypeId()) || + Objects.isNull(item.getLeaseNum()) || + Objects.isNull(item.getLeasePrice()) + ); + for (IwsCostPushBean leaseCostInfo : theMonthAgreementLeaseList) { + if (null == leaseCostInfo.getLeaseDate()) { continue; } + if (null == leaseCostInfo.getBackDate()) { leaseCostInfo.setBackDate(queryEndTime); } + + // 校准计算后的日期 + if (leaseCostInfo.getLeaseDate().isBefore(queryStartTime)) { + leaseCostInfo.setLeaseDate(queryStartTime); + } else if (leaseCostInfo.getLeaseDate().isAfter(queryEndTime)) { + leaseCostInfo.setLeaseDays(0); + leaseCostInfo.setDelFlag(true); + continue; + } + if (leaseCostInfo.getBackDate().isAfter(queryEndTime)) { + leaseCostInfo.setBackDate(queryEndTime); + } else if (leaseCostInfo.getBackDate().isBefore(queryStartTime)) { + leaseCostInfo.setLeaseDays(0); + leaseCostInfo.setDelFlag(true); + continue; + } + + // 计算天数 + leaseCostInfo.setLeaseDays(Math.toIntExact(calculateDaysInclusive(leaseCostInfo.getLeaseDate(), leaseCostInfo.getBackDate()))); + // 计算费用 + leaseCostInfo.setLeaseMoney(new BigDecimal(leaseCostInfo.getLeaseDays()) + .multiply(new BigDecimal(leaseCostInfo.getLeasePrice())) + .multiply(leaseCostInfo.getLeaseNum()) + ); + + } + return theMonthAgreementLeaseList; + } + } + + /** + * 计算月结费用详情 + * @param agreementList 协议集合 + * @param costDto 要进行结算的信息 + * @param taskId 任务id + * @param month 月份 + */ + private void computeMonthInfoDetail(List agreementList, IwsCostPushBean costDto, String taskId, String month) { + if (null == agreementList || agreementList.isEmpty()) { + return; + } else { + System.out.println("agreementList = " + agreementList); + for (IwsCostPushBean agreement : agreementList) { + updatePushStatus(agreement); + BigDecimal changeMoney = BigDecimal.ZERO; + IwsCostPushBean bean = new IwsCostPushBean(); + bean.setAgreementId(agreement.getAgreementId()); + + // 查询领料费用 + List baseInfo = iwsCostPushMapper.getPaidSltBaseInfo(bean); + List l = new ArrayList<>(); + + if (null != baseInfo && !baseInfo.isEmpty()) { + l = baseInfo; + } else { + System.err.println("baseInfo为空 = " + baseInfo); + } + + if (!l.isEmpty()) { + // TODO 待完善 + } + } + } + } + + + /** + * 更新协议推送状态 + * + * @param bean IwsCostPushBean对象,包含推送状态更新的信息 + */ + private void updatePushStatus(IwsCostPushBean bean) { + String isPush = checkPush(bean) ? "0" : "1"; + bean.setIsPush(isPush); + iwsCostPushMapper.updateAgreementIsPush(bean); + } + + /** + * 检查是否需要推送,包含大件及机械化的不需要进行push + * return true 需要推送, false 不需要推送 + */ + private boolean checkPush(IwsCostPushBean o) { + return o.getUnitName().contains("大件") || o.getUnitName().contains("机械化") || StringUtils.isEmpty(o.getProjectId()); + } + + /** + * 根据字符串形式的年月获取当月的第一天 + * + * @param yearMonth 字符串形式的年月,格式为 "yyyy-MM" 例如 2024-09 + * @return 当月的第一天的 LocalDateTime 对象,时间部分为 00:00:00 + */ + public static LocalDateTime getFirstDayOfMonth(String yearMonth) { + // 解析字符串为 LocalDate + LocalDate date = LocalDate.parse(yearMonth + "-01", DateTimeFormatter.ofPattern("yyyy-MM-dd")); + // 获取当月的第一天 + LocalDate firstDay = date.with(TemporalAdjusters.firstDayOfMonth()); + // 转换为 LocalDateTime,时间部分为 00:00:00 + return firstDay.atStartOfDay(); + } + + /** + * 根据字符串形式的年月获取当月的最后一天 + * + * @param yearMonth 字符串形式的年月,格式为 "yyyy-MM" 例如 2024-09 + * @return 当月的最后一天的 LocalDateTime 对象,时间部分为 23:59:59 + */ + public static LocalDateTime getLastDayOfMonthZ(String yearMonth) { + // 解析字符串为 LocalDate + LocalDate date = LocalDate.parse(yearMonth + "-01", DateTimeFormatter.ofPattern("yyyy-MM-dd")); + // 获取当月的最后一天 + LocalDate lastDay = date.with(TemporalAdjusters.lastDayOfMonth()); + // 转换为 LocalDateTime,时间部分为 23:59:59 + return lastDay.atTime(23, 59, 59); + } + + /** + * 计算两个 LocalDateTime 之间的天数(当天开始和当天结束的情况也算1天) + * + * @param start 开始时间 + * @param end 结束时间 + * @return 天数差(包括当天) + */ + public static long calculateDaysInclusive(LocalDateTime start, LocalDateTime end) { + // 如果结束时间早于开始时间,交换两者 + if (end.isBefore(start)) { + LocalDateTime temp = start; + start = end; + end = temp; + } + // 计算完整天数差 + long daysBetween = ChronoUnit.DAYS.between(start.toLocalDate(), end.toLocalDate()); + // 如果结束时间的时间部分晚于或等于开始时间的时间部分,则加 1 天 + if (!end.toLocalTime().isBefore(start.toLocalTime())) {daysBetween += 1;} + + return daysBetween; + } } diff --git a/bonus-modules/bonus-material/src/main/resources/mapper/material/push/IwsCostPushMapper.xml b/bonus-modules/bonus-material/src/main/resources/mapper/material/push/IwsCostPushMapper.xml index a9c4a420..c78fd5b4 100644 --- a/bonus-modules/bonus-material/src/main/resources/mapper/material/push/IwsCostPushMapper.xml +++ b/bonus-modules/bonus-material/src/main/resources/mapper/material/push/IwsCostPushMapper.xml @@ -6,14 +6,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - UPDATE bm_agreement_info - SET is_push = #{isPush} - WHERE agreement_id IN - - #{id} - + UPDATE bm_agreement_info SET is_push = #{isPush} WHERE agreement_id = #{agreementId} + + + INSERT INTO calc_project_month (MONTH) + VALUES (#{month}) + + + \ No newline at end of file