From 6a84abf6dd07714523471538106538184e4b59c4 Mon Sep 17 00:00:00 2001 From: rcx <3084692334@qq.com> Date: Tue, 11 Aug 2026 18:03:09 +0800 Subject: [PATCH] =?UTF-8?q?feat(system=E6=A8=A1=E5=9D=97lease):=20?= =?UTF-8?q?=E7=A7=9F=E8=B5=81=E7=AE=A1=E7=90=86=E5=A2=9E=E5=8A=A0=E5=81=9C?= =?UTF-8?q?=E7=94=A8=E5=8A=9F=E8=83=BD=EF=BC=8C=E5=81=9C=E7=94=A8=E5=90=8E?= =?UTF-8?q?=E4=B8=8D=E5=8F=82=E4=B8=8E=E5=87=BA=E7=A7=9F=E7=8E=87=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=20-=20LEASE=20=E8=A1=A8=E6=96=B0=E5=A2=9E=20status=20?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=EF=BC=881=3D=E5=90=AF=E7=94=A8=EF=BC=8C0=3D?= =?UTF-8?q?=E5=81=9C=E7=94=A8=EF=BC=89=20-=20Lease/LeasePO/LeaseDO/LeaseDT?= =?UTF-8?q?O=20=E6=96=B0=E5=A2=9E=20status=20=E5=AD=97=E6=AE=B5=20-=20Leas?= =?UTF-8?q?eMapper.xml=20=E5=A2=9E=E5=8A=A0=20status=20=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E4=B8=8E=E8=BF=87=E6=BB=A4=E6=9D=A1=E4=BB=B6?= =?UTF-8?q?=20-=20=E6=96=B0=E5=A2=9E=20LeaseApi.updateStatus=20=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=EF=BC=88PUT=20/updateStatus/{leaseIds}/{status}?= =?UTF-8?q?=EF=BC=89=20-=20=E5=87=BA=E7=A7=9F=E7=8E=87=E8=AE=A1=E7=AE=97?= =?UTF-8?q?=EF=BC=88shipperLeaseDetails=EF=BC=89=E8=BF=87=E6=BB=A4=20statu?= =?UTF-8?q?s=3D1=EF=BC=8C=E5=81=9C=E7=94=A8=E7=A7=9F=E8=B5=81=E4=B8=8D?= =?UTF-8?q?=E5=86=8D=E7=94=9F=E6=88=90=E5=87=BA=E7=A7=9F=E7=8E=87=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=20=E4=B8=80=E4=B8=AASQL=E6=96=87=E4=BB=B6=EF=BC=8C?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86=E4=B8=80=E4=B8=AA=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=EF=BC=8C=E5=9C=A8=E6=B5=8B=E8=AF=95=E5=92=8C=E7=94=9F=E4=BA=A7?= =?UTF-8?q?=E7=8E=AF=E5=A2=83=E9=83=BD=E9=9C=80=E8=A6=81=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=20=E5=AF=B9=E5=BA=94=E9=9C=80=E6=B1=82=EF=BC=9A=E4=BB=93?= =?UTF-8?q?=E5=BA=93=E5=87=BA=E7=A7=9F=E7=8E=87=20-=20=E7=A7=9F=E8=B5=81?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=A2=9E=E5=8A=A0=E5=81=9C=E7=94=A8=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Lease/LeaseApplicationService.java | 91 ++++++++++++++++++- .../mhd/basic/domain/lease/entity/Lease.java | 3 + .../domain/lease/repository/po/LeasePO.java | 3 + .../domain/lease/repository/todo/LeaseDO.java | 3 + .../lease/service/LeaseDomainService.java | 18 ++++ .../basic/interfaces/dto/lease/LeaseDTO.java | 3 + .../interfaces/facadeApi/lease/LeaseApi.java | 14 +++ .../mapper/basic/lease/LeaseMapper.xml | 8 +- sql/20260803_alter_table_lease_add_status.sql | 16 ++++ 9 files changed, 157 insertions(+), 2 deletions(-) create mode 100644 sql/20260803_alter_table_lease_add_status.sql diff --git a/mhd-modules/mhd-system/src/main/java/com/mhd/basic/application/service/Lease/LeaseApplicationService.java b/mhd-modules/mhd-system/src/main/java/com/mhd/basic/application/service/Lease/LeaseApplicationService.java index 611298729..0ffbd7612 100644 --- a/mhd-modules/mhd-system/src/main/java/com/mhd/basic/application/service/Lease/LeaseApplicationService.java +++ b/mhd-modules/mhd-system/src/main/java/com/mhd/basic/application/service/Lease/LeaseApplicationService.java @@ -40,6 +40,14 @@ import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; +import com.mhd.basic.interfaces.dto.shipperLeaseDetailsApi.WarehouseLeaseExportVO; +import com.mhd.common.core.utils.poi.ExcelUtil; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.net.URLEncoder; +import java.text.SimpleDateFormat; +import java.util.HashMap; +import java.util.Map; import java.math.BigDecimal; import java.time.LocalDate; @@ -277,7 +285,8 @@ public class LeaseApplicationService { final Date yesterday = DateUtil.beginOfDay(DateUtil.offsetDay(new Date(), -1)); LeaseDO leaseDO = new LeaseDO(); - leaseDO.setTime(yesterday); + leaseDO.setTime(yesterday); // 设置查询时间 + leaseDO.setStatus(1); // 只查询启用状态的租赁,停用的不参与出租率计算 //查询有效期内的租赁 List leasePOS = queryList(leaseDO); List entireUnit = leasePOS.stream() @@ -494,6 +503,67 @@ public class LeaseApplicationService { return warehouseOccupancyRatesList; } + /** + * 导出仓库出租率及客户租赁明细(单 sheet,明细行带仓库当日汇总列) + * 参数与 /warehouseOccupancyRate、/list 一致 + */ + public void exportOccupancyRate(HttpServletResponse response, ShipperLeaseDetailsDO shipperLeaseDetailsDO) throws IOException { + // ===== 1. 查出租率(注意:该方法内部会修改传入的 DO,所以先查它)===== + List rateList = warehouseOccupancyRate(shipperLeaseDetailsDO); + + // ===== 2. 用副本查明细,避免被上面改过的 DO 影响 ===== + ShipperLeaseDetailsDO detailDO = new ShipperLeaseDetailsDO(); + BeanUtils.copyProperties(shipperLeaseDetailsDO, detailDO); + List detailList = shipperLeaseDetailsService.queryList(detailDO); + + // ===== 3. 出租率按 (业务日期 + 仓库ID) 建映射,方便明细行查汇总 ===== + SimpleDateFormat keySdf = new SimpleDateFormat("yyyy-MM-dd"); + Map rateMap = new HashMap<>(); + for (WarehouseOccupancyRate r : rateList) { + String key = (r.getBusinessDate() == null ? "" : keySdf.format(r.getBusinessDate())) + + "_" + r.getWarehouseId(); + rateMap.put(key, r); + } + + // ===== 4. 明细为主,每行拼上对应仓库当天的汇总 ===== + List exportList = new ArrayList<>(); + for (ShipperLeaseDetailsPO d : detailList) { + WarehouseLeaseExportVO vo = new WarehouseLeaseExportVO(); + // 明细列 + vo.setBusinessDate(d.getBusinessDate()); + vo.setOrganizationName(d.getOrganizationName()); + vo.setWarehouseName(d.getWarehouseName()); + vo.setCargoOwnerName(d.getCargoOwnerName()); + vo.setLeaseType(d.getLeaseType()); + vo.setLeaseArea(d.getLeaseArea()); + // 汇总列(从映射取,找不到就留空) + String key = (d.getBusinessDate() == null ? "" : keySdf.format(d.getBusinessDate())) + + "_" + d.getWarehouseId(); + WarehouseOccupancyRate r = rateMap.get(key); + if (r != null) { + vo.setEntireLeaseArea(r.getEntireLeaseArea()); + vo.setFractionalLeaseArea(r.getFractionalLeaseArea()); + vo.setTotalArea(r.getTotalArea()); + vo.setDailyRentalRate(r.getDailyRentalRate()); + } + exportList.add(vo); + } + + // ===== 5. 按业务日期降序排序(null 排最后)===== + exportList.sort(Comparator + .comparing(WarehouseLeaseExportVO::getBusinessDate, Comparator.nullsLast(Comparator.reverseOrder())) + .thenComparing(WarehouseLeaseExportVO::getWarehouseName, Comparator.nullsLast(Comparator.naturalOrder()))); + + // ===== 6. 用 ExcelUtil 导出(项目通用做法,单 sheet)===== + String fileName = URLEncoder.encode("仓库出租率导出", "UTF-8").replaceAll("\\+", "%20"); + response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); + response.setCharacterEncoding("utf-8"); + response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); + + ExcelUtil util = new ExcelUtil<>(WarehouseLeaseExportVO.class); + util.exportExcel(response, exportList, "仓库出租率"); + } + /** * 定时任务整租推送到bms @@ -581,6 +651,25 @@ public class LeaseApplicationService { } } + /** + * 启用/停用租赁 + * @param leaseIds 租赁ID列表 + * @param status 目标状态:1=启用,0=停用 + */ + public Boolean updateStatus(List leaseIds, Integer status) { + LoginUser loginUser = SecurityUtils.getLoginUser(); + Long updateBy = loginUser != null ? loginUser.getUserid() : null; + String updateByName = loginUser != null ? loginUser.getUsername() : null; + if (leaseIds == null || leaseIds.isEmpty()) { + throw new ServiceException("租赁ID不能为空"); + } + if (status == null || (status != 0 && status != 1)) { + throw new ServiceException("状态值无效:1=启用,0=停用"); + } + log.info("启用/停用租赁--结束,leaseIds={},状态={},更新人id={},更新人名称={}",leaseIds,status==0?"停用":"启用",updateBy,updateByName); + return leaseDomainService.updateStatus(leaseIds, status, updateBy, updateByName); + } + // /** // * @description 设置数据字典键值 // * @author ZhouGY diff --git a/mhd-modules/mhd-system/src/main/java/com/mhd/basic/domain/lease/entity/Lease.java b/mhd-modules/mhd-system/src/main/java/com/mhd/basic/domain/lease/entity/Lease.java index 2ebd21a80..55d7175fc 100644 --- a/mhd-modules/mhd-system/src/main/java/com/mhd/basic/domain/lease/entity/Lease.java +++ b/mhd-modules/mhd-system/src/main/java/com/mhd/basic/domain/lease/entity/Lease.java @@ -96,4 +96,7 @@ public class Lease extends BaseVOEntity{ @ApiModelProperty("业务员ID") private String salesmanId; + + @ApiModelProperty("状态:1=正常,0=停用") + private Integer status; } \ No newline at end of file diff --git a/mhd-modules/mhd-system/src/main/java/com/mhd/basic/domain/lease/repository/po/LeasePO.java b/mhd-modules/mhd-system/src/main/java/com/mhd/basic/domain/lease/repository/po/LeasePO.java index 3bf1cef18..0c67573d5 100644 --- a/mhd-modules/mhd-system/src/main/java/com/mhd/basic/domain/lease/repository/po/LeasePO.java +++ b/mhd-modules/mhd-system/src/main/java/com/mhd/basic/domain/lease/repository/po/LeasePO.java @@ -97,4 +97,7 @@ public class LeasePO extends BaseVOEntity{ @ApiModelProperty("业务员ID") private String salesmanId; + + @ApiModelProperty("状态:1=正常,0=停用") + private Integer status; } \ No newline at end of file diff --git a/mhd-modules/mhd-system/src/main/java/com/mhd/basic/domain/lease/repository/todo/LeaseDO.java b/mhd-modules/mhd-system/src/main/java/com/mhd/basic/domain/lease/repository/todo/LeaseDO.java index 27e5621ce..6d20f8f1b 100644 --- a/mhd-modules/mhd-system/src/main/java/com/mhd/basic/domain/lease/repository/todo/LeaseDO.java +++ b/mhd-modules/mhd-system/src/main/java/com/mhd/basic/domain/lease/repository/todo/LeaseDO.java @@ -113,4 +113,7 @@ public class LeaseDO extends BaseVOEntity{ @ApiModelProperty("业务员ID") private String salesmanId; + + @ApiModelProperty("状态:1=正常,0=停用") + private Integer status; } \ No newline at end of file diff --git a/mhd-modules/mhd-system/src/main/java/com/mhd/basic/domain/lease/service/LeaseDomainService.java b/mhd-modules/mhd-system/src/main/java/com/mhd/basic/domain/lease/service/LeaseDomainService.java index 82ade3d75..1b264e189 100644 --- a/mhd-modules/mhd-system/src/main/java/com/mhd/basic/domain/lease/service/LeaseDomainService.java +++ b/mhd-modules/mhd-system/src/main/java/com/mhd/basic/domain/lease/service/LeaseDomainService.java @@ -89,4 +89,22 @@ public class LeaseDomainService { .in(Lease::getId, leaseIds) .eq(Lease::getDelFlag, 1)); } + + /** + * 启用/停用租赁 + * @param leaseIds 租赁ID列表 + * @param status 目标状态:1=启用,0=停用 + * @param updateBy 操作人ID + * @param updateByName 操作人名称 + */ + public Boolean updateStatus(List leaseIds, Integer status, Long updateBy, String updateByName) { + return leaseService.update(new UpdateWrapper().lambda() + .set(Lease::getStatus, status) + .set(Lease::getUpdateBy, updateBy) + .set(Lease::getUpdateByName, updateByName) + .set(Lease::getUpdateTime, new Date()) + .in(Lease::getId, leaseIds) + .eq(Lease::getDelFlag, 1)); + } + } \ No newline at end of file diff --git a/mhd-modules/mhd-system/src/main/java/com/mhd/basic/interfaces/dto/lease/LeaseDTO.java b/mhd-modules/mhd-system/src/main/java/com/mhd/basic/interfaces/dto/lease/LeaseDTO.java index 4d045da4b..926b8201c 100644 --- a/mhd-modules/mhd-system/src/main/java/com/mhd/basic/interfaces/dto/lease/LeaseDTO.java +++ b/mhd-modules/mhd-system/src/main/java/com/mhd/basic/interfaces/dto/lease/LeaseDTO.java @@ -110,4 +110,7 @@ public class LeaseDTO extends BaseVOEntity{ @ApiModelProperty("业务员ID") private String salesmanId; + + @ApiModelProperty("状态:1=正常,0=停用") + private Integer status; } \ No newline at end of file diff --git a/mhd-modules/mhd-system/src/main/java/com/mhd/basic/interfaces/facadeApi/lease/LeaseApi.java b/mhd-modules/mhd-system/src/main/java/com/mhd/basic/interfaces/facadeApi/lease/LeaseApi.java index fe8dc5b3f..a8cd3b53e 100644 --- a/mhd-modules/mhd-system/src/main/java/com/mhd/basic/interfaces/facadeApi/lease/LeaseApi.java +++ b/mhd-modules/mhd-system/src/main/java/com/mhd/basic/interfaces/facadeApi/lease/LeaseApi.java @@ -130,4 +130,18 @@ public class LeaseApi extends BaseController{ return AjaxResult.success(); } + /** + * 启用/停用租赁 + * @param leaseIds 租赁ID集合 + * @param status 目标状态(启用/停用) + * @return 操作结果 + */ + @ApiOperation("启用/停用租赁") + @PutMapping("/updateStatus/{leaseIds}/{status}") + public AjaxResult updateStatus(@PathVariable("leaseIds") List leaseIds, + @PathVariable("status") Integer status) + { + return toAjax(leaseApplicationService.updateStatus(leaseIds, status)); + } + } diff --git a/mhd-modules/mhd-system/src/main/resources/mapper/basic/lease/LeaseMapper.xml b/mhd-modules/mhd-system/src/main/resources/mapper/basic/lease/LeaseMapper.xml index fc99a9216..831005fdf 100644 --- a/mhd-modules/mhd-system/src/main/resources/mapper/basic/lease/LeaseMapper.xml +++ b/mhd-modules/mhd-system/src/main/resources/mapper/basic/lease/LeaseMapper.xml @@ -35,6 +35,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + @@ -68,7 +69,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" a.bill_time, a.salesman_name, a.settlement_currency, - a.salesman_id + a.salesman_id, + a.status from lease a LEFT JOIN warehouse w ON a.warehouse_id = w.warehouse_id AND w.del_flag = 1 @@ -136,6 +138,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" AND a.start_date <= #{time} AND a.end_date >= #{time} + + + AND a.status = #{status} + and a.del_flag = #{delFlag} diff --git a/sql/20260803_alter_table_lease_add_status.sql b/sql/20260803_alter_table_lease_add_status.sql new file mode 100644 index 000000000..c67fbe76b --- /dev/null +++ b/sql/20260803_alter_table_lease_add_status.sql @@ -0,0 +1,16 @@ +-- ============================================================ +-- 功能:租赁表新增 status 状态字段(启用/停用) +-- 数据库:达梦(Dameng)192.168.0.49:5236 +-- 模式:NGWL_TEST_SYSTEM +-- 表名:LEASE +-- 日期:2026-08-03 +-- 说明:status 字段用于控制租赁的启用/停用 +-- 1=启用(参与仓库出租率计算) +-- 0=停用(不参与仓库出租率计算) +-- ============================================================ + +-- 1. 添加字段 +ALTER TABLE NGWL_TEST_SYSTEM.LEASE ADD status TINYINT DEFAULT 1; + +-- 2. 添加注释(达梦必须单独写) +COMMENT ON COLUMN NGWL_TEST_SYSTEM.LEASE.status IS '状态:1=启用,0=停用';