From 32c403c8b55eb3070d4972928085fc2b9c720824 Mon Sep 17 00:00:00 2001 From: bonus <1203338439@qq.com> Date: Mon, 17 Feb 2025 09:01:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=87=8F=E5=85=8D=E6=8E=A5=E5=8F=A3=E5=BC=80?= =?UTF-8?q?=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapper/PurchaseCheckDetailsMapper.java | 16 +- .../SltAgreementReduceController.java | 77 +++++++ .../settlement/domain/SltAgreementReduce.java | 116 +++++++++++ .../mapper/SltAgreementReduceMapper.java | 29 +++ .../service/ISltAgreementReduceService.java | 21 ++ .../impl/SltAgreementReduceServiceImpl.java | 172 ++++++++++++++++ .../material/purchase/PurchaseBindMapper.xml | 3 + .../purchase/PurchaseCheckDetailsMapper.xml | 2 +- .../settlement/SltAgreementReduceMapper.xml | 191 ++++++++++++++++++ pom.xml | 8 + 10 files changed, 626 insertions(+), 9 deletions(-) create mode 100644 bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/controller/SltAgreementReduceController.java create mode 100644 bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/domain/SltAgreementReduce.java create mode 100644 bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/mapper/SltAgreementReduceMapper.java create mode 100644 bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/service/ISltAgreementReduceService.java create mode 100644 bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/service/impl/SltAgreementReduceServiceImpl.java create mode 100644 bonus-modules/bonus-material/src/main/resources/mapper/material/settlement/SltAgreementReduceMapper.xml diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/purchase/mapper/PurchaseCheckDetailsMapper.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/purchase/mapper/PurchaseCheckDetailsMapper.java index 193380d9..a50f18f6 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/purchase/mapper/PurchaseCheckDetailsMapper.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/purchase/mapper/PurchaseCheckDetailsMapper.java @@ -8,7 +8,7 @@ import org.apache.ibatis.annotations.Param; /** * 新购验收任务详细Mapper接口 - * + * * @author xsheng * @date 2024-10-16 */ @@ -27,7 +27,7 @@ public interface PurchaseCheckDetailsMapper { /** * 查询新购验收任务详细 - * + * * @param id 新购验收任务详细主键 * @return 新购验收任务详细 */ @@ -47,7 +47,7 @@ public interface PurchaseCheckDetailsMapper { /** * 查询新购验收任务详细列表 - * + * * @param purchaseCheckDetails 新购验收任务详细 * @return 新购验收任务详细集合 */ @@ -57,7 +57,7 @@ public interface PurchaseCheckDetailsMapper { /** * 新增新购验收任务详细 - * + * * @param purchaseCheckDetails 新购验收任务详细 * @return 结果 */ @@ -71,7 +71,7 @@ public interface PurchaseCheckDetailsMapper { /** * 修改新购验收任务详细 - * + * * @param purchaseCheckDetails 新购验收任务详细 * @return 结果 */ @@ -82,7 +82,7 @@ public interface PurchaseCheckDetailsMapper { * @param taskId 任务id * @param newTaskStatus 新状态 */ - int batchUpdateDetailsTaskStatus(@Param("taskId") Long taskId, @Param("newTaskStatus") Integer newTaskStatus, @Param("checkResult") String checkResult); + int batchUpdateDetailsTaskStatus(@Param("taskId") Long taskId,@Param("newTaskStatus") Integer newTaskStatus, @Param("checkResult") String checkResult); // int updatePurchaseDetails(PurchaseCheckDetails details); @@ -92,7 +92,7 @@ public interface PurchaseCheckDetailsMapper { /** * 删除新购验收任务详细 - * + * * @param id 新购验收任务详细主键 * @return 结果 */ @@ -102,7 +102,7 @@ public interface PurchaseCheckDetailsMapper { /** * 批量删除新购验收任务详细 - * + * * @param ids 需要删除的数据主键集合 * @return 结果 */ diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/controller/SltAgreementReduceController.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/controller/SltAgreementReduceController.java new file mode 100644 index 00000000..e13b9442 --- /dev/null +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/controller/SltAgreementReduceController.java @@ -0,0 +1,77 @@ +package com.bonus.material.settlement.controller; + +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.common.log.annotation.SysLog; +import com.bonus.common.log.enums.OperaType; +import com.bonus.common.security.annotation.RequiresPermissions; +import com.bonus.material.settlement.domain.SltAgreementReduce; +import com.bonus.material.settlement.service.ISltAgreementReduceService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * 结算协议申请Controller + * + * @author xsheng + * @date 2024-10-16 + */ +@Api(tags = "结算协议减免接口") +@RestController +@RequestMapping("/slt_agreement_reduce") +public class SltAgreementReduceController extends BaseController { + @Autowired + private ISltAgreementReduceService sltAgreementReduceService; + + /** + * 查询结算协议减免申请列表 + */ + @ApiOperation(value = "查询结算协议减免申请列表") + @RequiresPermissions("settlement:apply:list") + @GetMapping("/list") + public TableDataInfo list(SltAgreementReduce sltAgreement) { + startPage(); + List list = sltAgreementReduceService.selectSltAgreementReduceList(sltAgreement); + return getDataTable(list); + } + + /** + * 查询协议申请减免明细 + */ + @ApiOperation(value = "查询协议申请减免明细") + // @RequiresPermissions("settlement:apply:list") + @GetMapping("/applyByParam") + public AjaxResult applyByParam(SltAgreementReduce sltAgreement) { + List list = null; + if(sltAgreement!=null){ + if (sltAgreement.getAgreementId()!=null){ + list = sltAgreementReduceService.getApplyReduceList(sltAgreement); + } + + }else{ + + } + + return success(list); + } + + /** + * 查询协议申请减免明细 + */ + @ApiOperation(value = "查询协议申请减免明细") + // @RequiresPermissions("settlement:apply:list") + @SysLog(title = "申请减免", businessType = OperaType.INSERT, logType = 1,module = "结算关联->申请减免") + @PostMapping("/addApply") + public AjaxResult addApply( @RequestBody SltAgreementReduce sltAgreement) { + try { + return sltAgreementReduceService.addApply(sltAgreement); + } catch (Exception e) { + return error("系统错误, " + e.getMessage()); + } + } +} diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/domain/SltAgreementReduce.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/domain/SltAgreementReduce.java new file mode 100644 index 00000000..1a163019 --- /dev/null +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/domain/SltAgreementReduce.java @@ -0,0 +1,116 @@ +package com.bonus.material.settlement.domain; + +import com.bonus.common.biz.domain.BmFileInfo; +import com.bonus.common.core.annotation.Excel; +import com.bonus.common.core.web.domain.BaseEntity; +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.ToString; +import org.apache.poi.hpsf.Decimal; + +import java.math.BigDecimal; +import java.util.Date; +import java.util.List; + +/** + * 结算协议申请对象 slt_agreement_reduce + * + * @author csyue + * @date 2025-10-16 + */ + + +@Data +@ToString +public class SltAgreementReduce extends BaseEntity { + private static final long serialVersionUID = 1L; + + /** $column.columnComment */ + private Long id; + + /** 协议id */ + @ApiModelProperty(value = "协议id") + private Long agreementId; + + /** 结算单号(例如:JM202402-1) */ + @Excel(name = "减免单号", readConverterExp = "例=如:JM202402-1") + private String code; + + /** 创建人 */ + @Excel(name = "创建人") + @ApiModelProperty(value = "创建人") + private String creator; + + /** 状态0未结算1待审核2审核通过3审核驳回 */ + @Excel(name = "状态0未结算1待审核2审核通过3审核驳回") + @ApiModelProperty(value = "状态0未结算1待审核2审核通过3审核驳回") + private String status; + + /** 数据所属 */ + @Excel(name = "数据所属") + @ApiModelProperty(value = "数据所属") + private Long companyId; + + /** 结算总费用 */ + @Excel(name = "结算总费用") + @ApiModelProperty(value = "结算总费用") + private BigDecimal cost; + + @ApiModelProperty(value = "原因") + private String remark; + + @ApiModelProperty(value = "机具规格id") + private String typeId; + + @ApiModelProperty(value = "机具名称") + private String maName; + + @ApiModelProperty(value = "机具规格") + private String maModel; + + @ApiModelProperty(value = "机具单位") + private String maUnit; + + @ApiModelProperty(value = "租赁数量") + private BigDecimal num; + + @ApiModelProperty(value = "租赁单价") + private BigDecimal leasePrice; + + @ApiModelProperty(value = "租赁开始时间") + private Date startTime; + + @ApiModelProperty(value = "租赁结束时间") + private Date endTime; + + @ApiModelProperty(value = "租赁天数") + private Long days; + + @ApiModelProperty(value = "租赁金额") + private BigDecimal leaseMoney; + + + @ApiModelProperty(value = "减免数量") + private BigDecimal reduceNum; + + @ApiModelProperty(value = "减免租赁单价") + private BigDecimal reduceLeasePrice; + + @ApiModelProperty(value = "减免开始时间") + private Date reduceStartTime; + + @ApiModelProperty(value = "减免结束时间") + private Date reduceEndTime; + + @ApiModelProperty(value = "减免租赁费用") + private BigDecimal reduceLeaseMoney; + + + @ApiModelProperty(value = "减免天数") + private Long reduceDays; + + private BmFileInfo file; + + private List detailList; +} diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/mapper/SltAgreementReduceMapper.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/mapper/SltAgreementReduceMapper.java new file mode 100644 index 00000000..9c31bd62 --- /dev/null +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/mapper/SltAgreementReduceMapper.java @@ -0,0 +1,29 @@ +package com.bonus.material.settlement.mapper; + +import com.bonus.material.settlement.domain.SltAgreementReduce; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * 结算协议减免Mapper接口 + * + * @author yuecs + * @date 2025-10-16 + */ +public interface SltAgreementReduceMapper { + + List selectSltAgreementReduceList(SltAgreementReduce sltAgreement); + + List getApplyReduceList(SltAgreementReduce sltAgreement); + + String getMaxCode(String date); + + Long insertReduce(SltAgreementReduce sltAgreement); + + void insertReduceDetail(SltAgreementReduce sltAgreementReduce); + + void insertBatchReduceDetail(@Param("detailList") List detailList); + + List findOverlappingReductions(SltAgreementReduce detail); +} diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/service/ISltAgreementReduceService.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/service/ISltAgreementReduceService.java new file mode 100644 index 00000000..42a02845 --- /dev/null +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/service/ISltAgreementReduceService.java @@ -0,0 +1,21 @@ +package com.bonus.material.settlement.service; + +import com.bonus.common.core.web.domain.AjaxResult; +import com.bonus.material.settlement.domain.SltAgreementReduce; + +import java.util.List; + +/** + * 结算协议减免Service接口 + * + * @author yuecs + * @date 2025-10-16 + */ +public interface ISltAgreementReduceService { + + List selectSltAgreementReduceList(SltAgreementReduce sltAgreement); + + List getApplyReduceList(SltAgreementReduce sltAgreement); + + AjaxResult addApply(SltAgreementReduce sltAgreement); +} diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/service/impl/SltAgreementReduceServiceImpl.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/service/impl/SltAgreementReduceServiceImpl.java new file mode 100644 index 00000000..67699400 --- /dev/null +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/settlement/service/impl/SltAgreementReduceServiceImpl.java @@ -0,0 +1,172 @@ +package com.bonus.material.settlement.service.impl; + +import com.bonus.common.core.web.domain.AjaxResult; +import com.bonus.material.basic.mapper.BmFileInfoMapper; +import com.bonus.material.settlement.domain.SltAgreementReduce; +import com.bonus.material.settlement.mapper.SltAgreementReduceMapper; +import com.bonus.material.settlement.service.ISltAgreementReduceService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.dao.DataAccessException; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.math.BigDecimal; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.stream.Collectors; + +/** + * 结算协议减免Service业务层处理 + * + * @author yuecs + * @date 2025-10-16 + */ +@Service +@Slf4j +public class SltAgreementReduceServiceImpl implements ISltAgreementReduceService { + @Autowired + private SltAgreementReduceMapper sltAgreementRecudceMapper; + @Autowired + private BmFileInfoMapper bmFileInfoMapper; + + @Override + public List selectSltAgreementReduceList(SltAgreementReduce sltAgreement) { + return sltAgreementRecudceMapper.selectSltAgreementReduceList(sltAgreement); + } + + @Override + public List getApplyReduceList(SltAgreementReduce sltAgreement) { + return sltAgreementRecudceMapper.getApplyReduceList(sltAgreement); + } + + @Override + @Transactional(rollbackFor = Exception.class) // 对所有异常回滚 + public AjaxResult addApply(SltAgreementReduce sltAgreement) { + try { + List list = sltAgreement.getDetailList(); + //bmFileInfoMapper.insertBmFileInfo() + // 初始化 SltAgreementReduce 对象 + initSltAgreement(sltAgreement); + + List applyReduction = applyReduction(sltAgreement); + + Long rs = sltAgreementRecudceMapper.insertReduce(sltAgreement); + Long id = sltAgreement.getId(); + if (rs > 0 && list != null) { + // 批量插入明细 + List detailList = list.stream() + .peek(detail -> detail.setId(id)) + .collect(Collectors.toList()); + sltAgreementRecudceMapper.insertBatchReduceDetail(detailList); + } + + return AjaxResult.success(); + } catch (DataAccessException e) { + // 记录详细的数据库操作异常日志 + log.error("数据库操作失败: {}", e.getMessage(), e); + return AjaxResult.error("系统错误, 数据库操作失败"); + } catch (Exception e) { + // 记录其他异常日志 + log.error("系统错误: {}", e.getMessage(), e); + return AjaxResult.error("系统错误, " + e.getMessage()); + } + } + + private void initSltAgreement(SltAgreementReduce sltAgreement) { + sltAgreement.setCode(generateCode()); + sltAgreement.setCreateTime(new Date()); + } + + + public List applyReduction(SltAgreementReduce sltAgreement) { + // 初始化结果列表 + List newReductions = new ArrayList<>(); + + // 遍历申请减免的每个区间 + for (SltAgreementReduce detail : sltAgreement.getDetailList()) { + if (detail.getReduceStartTime() != null && detail.getReduceEndTime() != null) { + // 将当前区间添加到结果列表中 + + // 查询与当前区间有重叠的历史减免记录 + List historyReductions = sltAgreementRecudceMapper.findOverlappingReductions(detail); + + // 对比并去掉重叠部分 + for (SltAgreementReduce history : historyReductions) { + List temp = new ArrayList<>(); + for (SltAgreementReduce current : newReductions) { + // 如果当前区间与历史区间没有重叠,直接保留 + if (current.getEndTime().before(history.getStartTime()) || current.getStartTime().after(history.getEndTime())) { + temp.add(current); + } else { + // 如果有重叠,拆分当前区间 + if (current.getStartTime().before(history.getStartTime())) { + // 生成新的区间:申请开始时间到历史开始时间的前一天 + SltAgreementReduce newReduction = new SltAgreementReduce(); + //计算新的租赁情况 + newReduction.setStartTime(current.getStartTime()); + newReduction.setEndTime(new Date(history.getStartTime().getTime() - 86400000)); + long days = (history.getStartTime().getTime() - current.getStartTime().getTime()) / (24 * 60 * 60 * 1000) +1; + BigDecimal num = current.getNum(); + BigDecimal leasePrice = current.getLeasePrice(); + newReduction.setLeasePrice(leasePrice); + BigDecimal leaseMoney = new BigDecimal(days).multiply(num).multiply(leasePrice); + newReduction.setLeaseMoney(leaseMoney); + temp.add( + newReduction + ); + } + if (current.getEndTime().after(history.getEndTime())) { + // 生成新的区间:历史结束时间的后一天到申请结束时间 + SltAgreementReduce newReduction = new SltAgreementReduce(); + //计算新的租赁情况 + newReduction.setStartTime( new Date(history.getEndTime().getTime() + 86400000)); + newReduction.setEndTime( current.getEndTime()); + long days = (current.getEndTime().getTime() - history.getEndTime().getTime()) / (24 * 60 * 60 * 1000) +1; + BigDecimal num = current.getNum(); + BigDecimal leasePrice = current.getLeasePrice(); + newReduction.setLeasePrice(leasePrice); + BigDecimal leaseMoney = new BigDecimal(days).multiply(num).multiply(leasePrice); + newReduction.setLeaseMoney(leaseMoney); + temp.add( + newReduction + ); + + } + } + } + newReductions = temp; + } + } + } + + return newReductions; + } + + + + public String generateCode() { + // 获取当前日期,格式为 YYYYMMDD + String date = new SimpleDateFormat("yyyyMMdd").format(new Date()); + // 获取当前日期,格式为 YYY-YM-MDD + // 查询当前最大单号 + String maxCode = sltAgreementRecudceMapper.getMaxCode(date); + + // 生成新单号 + String newCode; + if (maxCode == null) { + // 如果当天没有单号,生成第一个单号 + newCode = "JM" + date + "-0001"; + } else { + // 提取序号部分并加 1 + int lastNumber = Integer.parseInt(maxCode.substring(maxCode.length() - 4)); + // 补零到 4 位 + String newNumber = String.format("%04d", lastNumber + 1); + newCode = "JM" + date + "-" + newNumber; + } + + return newCode; + } +} diff --git a/bonus-modules/bonus-material/src/main/resources/mapper/material/purchase/PurchaseBindMapper.xml b/bonus-modules/bonus-material/src/main/resources/mapper/material/purchase/PurchaseBindMapper.xml index a2b5e1be..28fbcf1a 100644 --- a/bonus-modules/bonus-material/src/main/resources/mapper/material/purchase/PurchaseBindMapper.xml +++ b/bonus-modules/bonus-material/src/main/resources/mapper/material/purchase/PurchaseBindMapper.xml @@ -342,6 +342,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" bm_qrcode_info bqi WHERE qr_code = #{qrCode} + + AND bqi.task_id = #{taskId} + + + + and code = #{code} + and creator = #{creator} + and status = #{status} + and company_id = #{companyId} + and cost = #{cost} + + + + + + + + + + + insert into slt_reduce_apply + + code, + creator, + create_time, + agreement_id, + status, + company_id, + cost, + remark, + + + #{code}, + #{creator}, + #{createTime}, + #{agreementId}, + #{status}, + #{companyId}, + #{cost}, + #{remark}, + + + + + + insert into slt_reduce_details + + apply_id, + start_time, + end_time, + type_id, + num, + reduce_num, + r_start_time, + r_end_time, + lease_price, + lease_money, + days, + + + #{id}, + #{startTime}, + #{endTime}, + #{typeId}, + #{num}, + #{reduceNum}, + #{reduceStartTime}, + #{reduceEndTime}, + #{reduceLeasePrice}, + #{reduceLeaseMoney}, + #{reduceDays}, + + + + + INSERT INTO slt_reduce_details + (apply_id, start_time, end_time, type_id, num, reduce_num, r_start_time, r_end_time, lease_price, lease_money, days) + VALUES + + ( + #{item.id}, + #{item.startTime}, + #{item.endTime}, + #{item.typeId}, + #{item.num}, + #{item.reduceNum}, + #{item.reduceStartTime}, + #{item.reduceEndTime}, + #{item.leasePrice}, + #{item.reduceLeaseMoney}, + #{item.reduceDays} + ) + + + + + diff --git a/pom.xml b/pom.xml index 848801ed..2e7eb03b 100644 --- a/pom.xml +++ b/pom.xml @@ -271,6 +271,9 @@ 3.12.0 + + + @@ -288,5 +291,10 @@ + + + + +