feat(system模块lease): 租赁管理增加停用功能,停用后不参与出租率计算

- LEASE 表新增 status 字段(1=启用,0=停用)
- Lease/LeasePO/LeaseDO/LeaseDTO 新增 status 字段
- LeaseMapper.xml 增加 status 查询字段与过滤条件
- 新增 LeaseApi.updateStatus 接口(PUT /updateStatus/{leaseIds}/{status})
- 出租率计算(shipperLeaseDetails)过滤 status=1,停用租赁不再生成出租率数据
一个SQL文件,增加了一个字段,在测试和生产环境都需要执行
对应需求:仓库出租率 - 租赁管理增加停用功能
This commit is contained in:
rcx
2026-08-11 18:03:09 +08:00
parent 8b4e785de3
commit 6a84abf6dd
9 changed files with 157 additions and 2 deletions
@@ -40,6 +40,14 @@ import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service; 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.math.BigDecimal;
import java.time.LocalDate; import java.time.LocalDate;
@@ -277,7 +285,8 @@ public class LeaseApplicationService {
final Date yesterday = DateUtil.beginOfDay(DateUtil.offsetDay(new Date(), -1)); final Date yesterday = DateUtil.beginOfDay(DateUtil.offsetDay(new Date(), -1));
LeaseDO leaseDO = new LeaseDO(); LeaseDO leaseDO = new LeaseDO();
leaseDO.setTime(yesterday); leaseDO.setTime(yesterday); // 设置查询时间
leaseDO.setStatus(1); // 只查询启用状态的租赁,停用的不参与出租率计算
//查询有效期内的租赁 //查询有效期内的租赁
List<LeasePO> leasePOS = queryList(leaseDO); List<LeasePO> leasePOS = queryList(leaseDO);
List<LeasePO> entireUnit = leasePOS.stream() List<LeasePO> entireUnit = leasePOS.stream()
@@ -494,6 +503,67 @@ public class LeaseApplicationService {
return warehouseOccupancyRatesList; return warehouseOccupancyRatesList;
} }
/**
* 导出仓库出租率及客户租赁明细(单 sheet,明细行带仓库当日汇总列)
* 参数与 /warehouseOccupancyRate、/list 一致
*/
public void exportOccupancyRate(HttpServletResponse response, ShipperLeaseDetailsDO shipperLeaseDetailsDO) throws IOException {
// ===== 1. 查出租率(注意:该方法内部会修改传入的 DO,所以先查它)=====
List<WarehouseOccupancyRate> rateList = warehouseOccupancyRate(shipperLeaseDetailsDO);
// ===== 2. 用副本查明细,避免被上面改过的 DO 影响 =====
ShipperLeaseDetailsDO detailDO = new ShipperLeaseDetailsDO();
BeanUtils.copyProperties(shipperLeaseDetailsDO, detailDO);
List<ShipperLeaseDetailsPO> detailList = shipperLeaseDetailsService.queryList(detailDO);
// ===== 3. 出租率按 (业务日期 + 仓库ID) 建映射,方便明细行查汇总 =====
SimpleDateFormat keySdf = new SimpleDateFormat("yyyy-MM-dd");
Map<String, WarehouseOccupancyRate> rateMap = new HashMap<>();
for (WarehouseOccupancyRate r : rateList) {
String key = (r.getBusinessDate() == null ? "" : keySdf.format(r.getBusinessDate()))
+ "_" + r.getWarehouseId();
rateMap.put(key, r);
}
// ===== 4. 明细为主,每行拼上对应仓库当天的汇总 =====
List<WarehouseLeaseExportVO> 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<WarehouseLeaseExportVO> util = new ExcelUtil<>(WarehouseLeaseExportVO.class);
util.exportExcel(response, exportList, "仓库出租率");
}
/** /**
* 定时任务整租推送到bms * 定时任务整租推送到bms
@@ -581,6 +651,25 @@ public class LeaseApplicationService {
} }
} }
/**
* 启用/停用租赁
* @param leaseIds 租赁ID列表
* @param status 目标状态:1=启用,0=停用
*/
public Boolean updateStatus(List<Long> 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 设置数据字典键值 // * @description 设置数据字典键值
// * @author ZhouGY // * @author ZhouGY
@@ -96,4 +96,7 @@ public class Lease extends BaseVOEntity{
@ApiModelProperty("业务员ID") @ApiModelProperty("业务员ID")
private String salesmanId; private String salesmanId;
@ApiModelProperty("状态:1=正常,0=停用")
private Integer status;
} }
@@ -97,4 +97,7 @@ public class LeasePO extends BaseVOEntity{
@ApiModelProperty("业务员ID") @ApiModelProperty("业务员ID")
private String salesmanId; private String salesmanId;
@ApiModelProperty("状态:1=正常,0=停用")
private Integer status;
} }
@@ -113,4 +113,7 @@ public class LeaseDO extends BaseVOEntity{
@ApiModelProperty("业务员ID") @ApiModelProperty("业务员ID")
private String salesmanId; private String salesmanId;
@ApiModelProperty("状态:1=正常,0=停用")
private Integer status;
} }
@@ -89,4 +89,22 @@ public class LeaseDomainService {
.in(Lease::getId, leaseIds) .in(Lease::getId, leaseIds)
.eq(Lease::getDelFlag, 1)); .eq(Lease::getDelFlag, 1));
} }
/**
* 启用/停用租赁
* @param leaseIds 租赁ID列表
* @param status 目标状态:1=启用,0=停用
* @param updateBy 操作人ID
* @param updateByName 操作人名称
*/
public Boolean updateStatus(List<Long> leaseIds, Integer status, Long updateBy, String updateByName) {
return leaseService.update(new UpdateWrapper<Lease>().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));
}
} }
@@ -110,4 +110,7 @@ public class LeaseDTO extends BaseVOEntity{
@ApiModelProperty("业务员ID") @ApiModelProperty("业务员ID")
private String salesmanId; private String salesmanId;
@ApiModelProperty("状态:1=正常,0=停用")
private Integer status;
} }
@@ -130,4 +130,18 @@ public class LeaseApi extends BaseController{
return AjaxResult.success(); return AjaxResult.success();
} }
/**
* 启用/停用租赁
* @param leaseIds 租赁ID集合
* @param status 目标状态(启用/停用)
* @return 操作结果
*/
@ApiOperation("启用/停用租赁")
@PutMapping("/updateStatus/{leaseIds}/{status}")
public AjaxResult updateStatus(@PathVariable("leaseIds") List<Long> leaseIds,
@PathVariable("status") Integer status)
{
return toAjax(leaseApplicationService.updateStatus(leaseIds, status));
}
} }
@@ -35,6 +35,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="updateBy" column="update_by" /> <result property="updateBy" column="update_by" />
<result property="updateByName" column="update_by_name" /> <result property="updateByName" column="update_by_name" />
<result property="delFlag" column="del_flag" /> <result property="delFlag" column="del_flag" />
<result property="status" column="status" />
</resultMap> </resultMap>
@@ -68,7 +69,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
a.bill_time, a.bill_time,
a.salesman_name, a.salesman_name,
a.settlement_currency, a.settlement_currency,
a.salesman_id a.salesman_id,
a.status
from lease a from lease a
LEFT JOIN warehouse w ON a.warehouse_id = w.warehouse_id AND w.del_flag = 1 LEFT JOIN warehouse w ON a.warehouse_id = w.warehouse_id AND w.del_flag = 1
</sql> </sql>
@@ -136,6 +138,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
AND a.start_date &lt;= #{time} AND a.start_date &lt;= #{time}
AND a.end_date &gt;= #{time} AND a.end_date &gt;= #{time}
</if> </if>
<!-- 停用状态过滤:status 不为空时按状态过滤 -->
<if test="status != null">
AND a.status = #{status}
</if>
<!-- 删除标记 --> <!-- 删除标记 -->
<choose> <choose>
<when test="delFlag != null"> and a.del_flag = #{delFlag} </when> <when test="delFlag != null"> and a.del_flag = #{delFlag} </when>
@@ -0,0 +1,16 @@
-- ============================================================
-- 功能:租赁表新增 status 状态字段(启用/停用)
-- 数据库:达梦(Dameng192.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=停用';