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=停用';