Merge branch 'refs/heads/dev' into dev_820

This commit is contained in:
王奎兴
2026-08-18 16:36:28 +08:00
73 changed files with 1628 additions and 349 deletions
@@ -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;
@@ -270,14 +278,15 @@ public class LeaseApplicationService {
* 货主租赁明细
* 定时任务:每天凌晨1点执行,计算前一天的货主租赁明细
*/
// @Scheduled(cron = "0 0 1 * * ?")
@Scheduled(cron = "0 0 1 * * ?")
public void shipperLeaseDetails() {
log.info("开始执行货主租赁明细定时任务");
// 计算前一天的日期,将时间设置为当天的0点0分0秒,只保留日期部分
final Date yesterday = DateUtil.beginOfDay(DateUtil.offsetDay(new Date(), -1));
LeaseDO leaseDO = new LeaseDO();
leaseDO.setTime(yesterday);
leaseDO.setTime(yesterday); // 设置查询时间
leaseDO.setStatus(1); // 只查询启用状态的租赁,停用的不参与出租率计算
//查询有效期内的租赁
List<LeasePO> leasePOS = queryList(leaseDO);
List<LeasePO> entireUnit = leasePOS.stream()
@@ -494,6 +503,103 @@ public class LeaseApplicationService {
return warehouseOccupancyRatesList;
}
/**
* 导出仓库出租率及客户租赁明细(单 sheet,明细行带仓库当日汇总列)
* 参数与 /warehouseOccupancyRate、/list 一致
*/
public void exportOccupancyRate(HttpServletResponse response, ShipperLeaseDetailsDO shipperLeaseDetailsDO) throws IOException {
// 注意:本方法不调用 warehouseOccupancyRate(),因为该方法在不传 warehouseId 时
// totalArea 会算成全系统所有仓库库区面积之和(如 6168),导致导出面积/日租率错误。
// 这里自行按 (业务日期 + 仓库) 维度计算,保证多仓库导出时每个仓库的面积/日租率正确。
// ===== 1. 查全部明细(用副本 DO,避免影响外部)=====
ShipperLeaseDetailsDO detailDO = new ShipperLeaseDetailsDO();
BeanUtils.copyProperties(shipperLeaseDetailsDO, detailDO);
List<ShipperLeaseDetailsPO> detailList = shipperLeaseDetailsService.queryList(detailDO);
if (detailList == null) {
detailList = new ArrayList<>();
}
// ===== 2. 预算每个仓库的总面积(启用库区的 storageRegion 累加),建 warehouseId -> totalArea 映射 =====
Set<Long> warehouseIds = detailList.stream()
.map(ShipperLeaseDetailsPO::getWarehouseId)
.filter(Objects::nonNull)
.collect(Collectors.toSet());
Map<Long, BigDecimal> warehouseTotalAreaMap = new HashMap<>();
for (Long wid : warehouseIds) {
StorageSectionDO storageSectionDO = new StorageSectionDO();
storageSectionDO.setWarehouseId(wid);
storageSectionDO.setOpeningUp(1);
List<StorageSectionPO> sections = storageSectionApplicationService.queryList(storageSectionDO);
BigDecimal area = BigDecimal.ZERO;
for (StorageSectionPO s : sections) {
area = area.add(s.getStorageRegion() == null ? BigDecimal.ZERO : s.getStorageRegion());
}
warehouseTotalAreaMap.put(wid, area);
}
// ===== 3. 按 (业务日期 + 仓库ID) 聚合,算每个仓库当天的整租/散租面积 =====
// summaryMap: key -> [整租面积, 散租面积]
SimpleDateFormat keySdf = new SimpleDateFormat("yyyy-MM-dd");
Map<String, BigDecimal[]> summaryMap = new HashMap<>();
for (ShipperLeaseDetailsPO d : detailList) {
String key = (d.getBusinessDate() == null ? "" : keySdf.format(d.getBusinessDate()))
+ "_" + d.getWarehouseId();
BigDecimal[] arr = summaryMap.computeIfAbsent(key, k -> new BigDecimal[]{BigDecimal.ZERO, BigDecimal.ZERO});
BigDecimal leaseArea = d.getLeaseArea() == null ? BigDecimal.ZERO : d.getLeaseArea();
if ("整租".equals(d.getLeaseType())) {
arr[0] = arr[0].add(leaseArea);
} else {
arr[1] = arr[1].add(leaseArea);
}
}
// ===== 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();
BigDecimal[] arr = summaryMap.get(key);
BigDecimal entireLeaseArea = (arr != null) ? arr[0] : BigDecimal.ZERO;
BigDecimal fractionalLeaseArea = (arr != null) ? arr[1] : BigDecimal.ZERO;
vo.setEntireLeaseArea(entireLeaseArea);
vo.setFractionalLeaseArea(fractionalLeaseArea);
// 该仓库的总面积(按仓库单独算,不再用全局总和)
BigDecimal widTotalArea = warehouseTotalAreaMap.getOrDefault(d.getWarehouseId(), BigDecimal.ZERO);
vo.setTotalArea(widTotalArea);
// 日租率 = (整租+散租) / 总面积 × 100,保留2位小数(直接输出百分比值,如 10.00)
BigDecimal leaseSum = entireLeaseArea.add(fractionalLeaseArea);
BigDecimal dailyRate = widTotalArea.compareTo(BigDecimal.ZERO) == 0
? BigDecimal.ZERO
: leaseSum.multiply(new BigDecimal("100")).divide(widTotalArea, 2, BigDecimal.ROUND_HALF_UP);
vo.setDailyRentalRate(dailyRate);
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
@@ -581,6 +687,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 设置数据字典键值
// * @author ZhouGY
@@ -30,11 +30,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -580,6 +576,40 @@ public class ExpenseAccountApplicationService {
return expenseAccountDomainService.getInfoByCode2(subjectCode,topOrganizationId);
}
/**
* 根据编码和组织ID查询
*/
public ExpenseAccountPO getInfoByOrgAndCode(String subjectCode, Long organizationId) {
if(!StringUtils.isNotEmpty(subjectCode)){
throw new ServiceException("费用科目编码不能为空");
}
if(organizationId == null){
throw new ServiceException("组织ID不能为空");
}
ExpenseAccountPO expenseAccountPO = expenseAccountDomainService.getInfoByOrgAndCode(subjectCode, organizationId);
// // 组装计费单位列表:单位-单位英文
// List<String> unit = new ArrayList<>();
// if (expenseAccountPO != null) {
// unit.add(expenseAccountPO.getBillingUnit() + "-" + expenseAccountPO.getBillingUnitEn());
// unit.add(expenseAccountPO.getBillingUnit2() + "-" + expenseAccountPO.getBillingUnitEn2());
// expenseAccountPO.setUnit(unit);
// }
// 组装计费单位列表(数组)
List<Map<String, String>> unit = new ArrayList<>();
if (expenseAccountPO != null) {
Map<String, String> unit1 = new HashMap<>();
unit1.put("unit", expenseAccountPO.getBillingUnit() + "-" + expenseAccountPO.getBillingUnitEn());
unit.add(unit1);
Map<String, String> unit2 = new HashMap<>();
unit2.put("unit", expenseAccountPO.getBillingUnit2() + "-" + expenseAccountPO.getBillingUnitEn2());
unit.add(unit2);
expenseAccountPO.setUnit(unit);
}
return expenseAccountPO;
}
public List<QueryExpenseAccountPO> selectExpenseAccount(SearchExpenseAccountDO searchExpenseAccountDO){
setDataPermissionForSearch(searchExpenseAccountDO);
return expenseAccountDomainService.selectExpenseAccount(searchExpenseAccountDO);
@@ -58,6 +58,11 @@ public interface IExpenseAccountService extends IService<ExpenseAccount>
*/
ExpenseAccountPO getInfoByCode(ExpenseAccountDO expenseAccountDO);
/**
* 根据费用科目code和组织ID查询费用信息
*/
ExpenseAccountPO getInfoByOrgAndCode(ExpenseAccountDO expenseAccountDO);
public List<QueryExpenseAccountPO> selectExpenseAccount(SearchExpenseAccountDO searchExpenseAccountDO);
public List<QueryExpenseAccountPO> selectOtherExpenseAccount(SearchExpenseAccountDO searchExpenseAccountDO);
@@ -39,6 +39,11 @@ public interface ExpenseAccountMapper extends BaseMapper<ExpenseAccount>
*/
ExpenseAccountPO getInfoByCode(@Param("expenseAccountDO") ExpenseAccountDO expenseAccountDO);
/**
* 根据费用科目code和组织ID查询费用信息
*/
ExpenseAccountPO getInfoByOrgAndCode(@Param("expenseAccountDO") ExpenseAccountDO expenseAccountDO);
public List<QueryExpenseAccountPO> selectExpenseAccount(@Param("searchExpenseAccountDO") SearchExpenseAccountDO searchExpenseAccountDO);
public List<QueryExpenseAccountPO> selectOtherExpenseAccount(@Param("searchExpenseAccountDO") SearchExpenseAccountDO searchExpenseAccountDO);
@@ -129,6 +129,11 @@ public class ExpenseAccountImpl extends ServiceImpl<ExpenseAccountMapper, Expens
return expenseAccountMapper.getInfoByCode(expenseAccountDO);
}
@Override
public ExpenseAccountPO getInfoByOrgAndCode(ExpenseAccountDO expenseAccountDO) {
return expenseAccountMapper.getInfoByOrgAndCode(expenseAccountDO);
}
/**
* 系统科目查询
* 社会车辆:service_items_code='SHCL'upper_subject_code='shcl_clyf'society_status=1
@@ -9,6 +9,7 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import com.mhd.common.core.web.domain.BaseVOEntity;
@@ -159,4 +160,8 @@ public class ExpenseAccountPO extends BaseVOEntity{
@ApiModelProperty("nc科目编码")
private String ncSubjectCode;
@ApiModelProperty("计费单位列表(单位-单位英文)")
private List<Map<String, String>> unit;
}
@@ -101,6 +101,16 @@ public class ExpenseAccountDomainService {
expenseAccountDO.setTopOrganizationId(topOrganizationId);
return expenseAccountService.getInfoByCode(expenseAccountDO);
}
/**
* 根据编码和组织ID查询费用科目信息
*/
public ExpenseAccountPO getInfoByOrgAndCode(String subjectCode, Long organizationId) {
ExpenseAccountDO expenseAccountDO = new ExpenseAccountDO();
expenseAccountDO.setSubjectCode(subjectCode);
expenseAccountDO.setOrganizationId(organizationId);
return expenseAccountService.getInfoByOrgAndCode(expenseAccountDO);
}
public List<QueryExpenseAccountPO> selectExpenseAccount(SearchExpenseAccountDO searchExpenseAccountDO){
return expenseAccountService.selectExpenseAccount(searchExpenseAccountDO);
}
@@ -96,4 +96,7 @@ public class Lease extends BaseVOEntity{
@ApiModelProperty("业务员ID")
private String salesmanId;
@ApiModelProperty("状态:1=正常,0=停用")
private Integer status;
}
@@ -97,4 +97,7 @@ public class LeasePO extends BaseVOEntity{
@ApiModelProperty("业务员ID")
private String salesmanId;
@ApiModelProperty("状态:1=正常,0=停用")
private Integer status;
}
@@ -113,4 +113,7 @@ public class LeaseDO extends BaseVOEntity{
@ApiModelProperty("业务员ID")
private String salesmanId;
@ApiModelProperty("状态:1=正常,0=停用")
private Integer status;
}
@@ -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<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));
}
}
@@ -168,9 +168,11 @@ public class WarehouseDomainService {
warehouseLinkagePO.setName(warehousePO.getWarehouseName());
StorageSectionDO storageSectionDO = new StorageSectionDO();
storageSectionDO.setWarehouseId(warehousePO.getWarehouseId());
storageSectionDO.setNullify(1);
List<StorageSectionPO> storageSectionPOList = storageSectionService.queryList(storageSectionDO);
StorageLocationDO storageLocationDO = new StorageLocationDO();
storageLocationDO.setWarehouseId(warehousePO.getWarehouseId());
storageLocationDO.setNullify(1);
List<StorageLocationPO> storageLocationPOList = storageLocationService.queryList(storageLocationDO);
//根据库区唯一标识进行分组
Map<String, List<StorageLocationPO>> storageLocationListMap = storageLocationPOList.stream().collect(Collectors.groupingBy(StorageLocationPO::getStorageCode));
@@ -110,4 +110,7 @@ public class LeaseDTO extends BaseVOEntity{
@ApiModelProperty("业务员ID")
private String salesmanId;
@ApiModelProperty("状态:1=正常,0=停用")
private Integer status;
}
@@ -0,0 +1,65 @@
package com.mhd.basic.interfaces.dto.shipperLeaseDetailsApi;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.mhd.common.core.annotation.Excel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.math.BigDecimal;
import java.util.Date;
/**
* 仓库出租率及客户租赁明细 导出VO(单 sheet)
* 明细为主行,附该仓库当日汇总列
*/
@Data
public class WarehouseLeaseExportVO {
private static final long serialVersionUID = 1L;
@ApiModelProperty("仓库")
@Excel(name = "仓库")
private String warehouseName;
@ApiModelProperty("业务日期")
@Excel(name = "业务日期", width = 20, dateFormat = "yyyy-MM-dd")
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
@DateTimeFormat(pattern = "yyyy-MM-dd")
private Date businessDate;
@ApiModelProperty("整租面积(m²)")
@Excel(name = "整租面积(m²)")
private BigDecimal entireLeaseArea;
@ApiModelProperty("散租面积(m²)")
@Excel(name = "散租面积(m²)")
private BigDecimal fractionalLeaseArea;
@ApiModelProperty("总面积(m²)")
@Excel(name = "总面积(m²)")
private BigDecimal totalArea;
@ApiModelProperty("日租率(%)")
@Excel(name = "日租率(%)")
private BigDecimal dailyRentalRate;
@ApiModelProperty("组织名称")
@Excel(name = "组织名称")
private String organizationName;
@ApiModelProperty("货主名称")
@Excel(name = "货主名称")
private String cargoOwnerName;
@ApiModelProperty("租赁方式")
@Excel(name = "租赁方式")
private String leaseType;
@ApiModelProperty("租赁面积(m²)")
@Excel(name = "租赁面积(m²)")
private BigDecimal leaseArea;
// ===== 以下为仓库当日汇总列(同一仓库同一天的多行会重复,属正常)=====
}
@@ -328,5 +328,13 @@ public class ExpenseAccountApi extends BaseController{
return AjaxResult.success(expenseAccountPO);
}
@ApiOperation("根据code和组织ID获取数据")
@GetMapping(value = "/getInfoByOrgAndCode")
public AjaxResult getInfoByOrgAndCode(@RequestParam("subjectCode") String subjectCode,@RequestParam("organizationId") Long organizationId)
{
ExpenseAccountPO expenseAccountPO = expenseAccountApplicationService.getInfoByOrgAndCode(subjectCode, organizationId);
return AjaxResult.success(expenseAccountPO.getUnit());
}
}
@@ -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<Long> leaseIds,
@PathVariable("status") Integer status)
{
return toAjax(leaseApplicationService.updateStatus(leaseIds, status));
}
}
@@ -20,6 +20,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
@@ -157,5 +159,17 @@ public class ShipperLeaseDetailsApi extends BaseController{
return getDataTable(warehouseOccupancyRates);
}
/**
* 导出仓库出租率及客户租赁明细
* 参数与 /warehouseOccupancyRate、/list 一致
*/
@ApiOperation("导出仓库出租率及客户租赁明细")
@GetMapping(value = "/export", produces = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
public void export(ShipperLeaseDetailsDTO shipperLeaseDetailsDTO, HttpServletResponse response) throws IOException
{
ShipperLeaseDetailsDO shipperLeaseDetailsDO = shipperLeaseDetailsAssembler.toDO(shipperLeaseDetailsDTO);
leaseApplicationService.exportOccupancyRate(response, shipperLeaseDetailsDO);
}
}
@@ -151,6 +151,22 @@
LIMIT 1
</select>
<select id="getInfoByOrgAndCode" resultType="com.mhd.basic.domain.expenseAccount.repository.po.ExpenseAccountPO" parameterType="com.mhd.basic.domain.expenseAccount.repository.todo.ExpenseAccountDO">
SELECT
a.* ,
b.tax_rate,
b.service_items_name,
b.service_items_code
FROM
expense_account a
LEFT JOIN service_items_manage b ON a.service_items_manage_id = b.service_items_manage_id
WHERE
a.del_flag = 1
AND a.organization_id = #{expenseAccountDO.organizationId}
AND a.subject_code = #{expenseAccountDO.subjectCode}
AND a.status = 1
LIMIT 1
</select>
<sql id="common_where_two">
<!-- 数据权限:南光组织(organizationId=2827)查全部,其他组织查自己 -->
@@ -35,6 +35,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="updateBy" column="update_by" />
<result property="updateByName" column="update_by_name" />
<result property="delFlag" column="del_flag" />
<result property="status" column="status" />
</resultMap>
@@ -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
</sql>
@@ -136,6 +138,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
AND a.start_date &lt;= #{time}
AND a.end_date &gt;= #{time}
</if>
<!-- 停用状态过滤:status 不为空时按状态过滤 -->
<if test="status != null">
AND a.status = #{status}
</if>
<!-- 删除标记 -->
<choose>
<when test="delFlag != null"> and a.del_flag = #{delFlag} </when>