This commit is contained in:
		
							parent
							
								
									b3e90a6463
								
							
						
					
					
						commit
						3fdb25babe
					
				| 
						 | 
					@ -188,9 +188,36 @@ public class MaterialLeaseInfoController extends BaseController {
 | 
				
			||||||
    @ApiOperation(value = "导出工器具领料出库详情")
 | 
					    @ApiOperation(value = "导出工器具领料出库详情")
 | 
				
			||||||
    @PostMapping("/exportOutDetails")
 | 
					    @PostMapping("/exportOutDetails")
 | 
				
			||||||
    public void exportOutDetails(HttpServletResponse response, MaterialLeaseApplyInfo leaseApplyInfo) {
 | 
					    public void exportOutDetails(HttpServletResponse response, MaterialLeaseApplyInfo leaseApplyInfo) {
 | 
				
			||||||
 | 
					        String fileName = "材料站出库详情";
 | 
				
			||||||
        List<LeaseOutDetailsInfo> list = materialLeaseInfoService.exportOutDetails(leaseApplyInfo);
 | 
					        List<LeaseOutDetailsInfo> list = materialLeaseInfoService.exportOutDetails(leaseApplyInfo);
 | 
				
			||||||
 | 
					        // 根据list集合数,去填充序号
 | 
				
			||||||
 | 
					        for (int i = 0; i < list.size(); i++) {
 | 
				
			||||||
 | 
					            list.get(i).setSerialNumber(i + 1);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
        ExcelUtil<LeaseOutDetailsInfo> util = new ExcelUtil<>(LeaseOutDetailsInfo.class);
 | 
					        ExcelUtil<LeaseOutDetailsInfo> util = new ExcelUtil<>(LeaseOutDetailsInfo.class);
 | 
				
			||||||
        util.exportExcel(response, list, "工器具领料出库详情数据");
 | 
					        // 获取当前年月日时分秒导出时间,用括号拼接在后面
 | 
				
			||||||
 | 
					        String title = "材料站出库详情" + "(" + "导出时间:" + DateUtils.getTime() + ")";
 | 
				
			||||||
 | 
					        util.exportExcel(response, list, fileName, title);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * 工器具领料申请详情
 | 
				
			||||||
 | 
					     * @param response
 | 
				
			||||||
 | 
					     * @param leaseApplyInfo
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    @ApiOperation(value = "导出工器具领料申请详情")
 | 
				
			||||||
 | 
					    @PostMapping("/exportDetails")
 | 
				
			||||||
 | 
					    public void exportDetails(HttpServletResponse response, MaterialLeaseApplyInfo leaseApplyInfo) {
 | 
				
			||||||
 | 
					        String fileName = "班组领料申请详情";
 | 
				
			||||||
 | 
					        List<LeaseDetailsInfo> list = materialLeaseInfoService.exportDetails(leaseApplyInfo);
 | 
				
			||||||
 | 
					        // 根据list集合数,去填充序号
 | 
				
			||||||
 | 
					        for (int i = 0; i < list.size(); i++) {
 | 
				
			||||||
 | 
					            list.get(i).setSerialNumber(i + 1);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        ExcelUtil<LeaseDetailsInfo> util = new ExcelUtil<>(LeaseDetailsInfo.class);
 | 
				
			||||||
 | 
					        // 获取当前年月日时分秒导出时间,用括号拼接在后面
 | 
				
			||||||
 | 
					        String title = "班组领料申请详情" + "(" + "导出时间:" + DateUtils.getTime() + ")";
 | 
				
			||||||
 | 
					        util.exportExcel(response, list, fileName, title);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,161 @@
 | 
				
			||||||
 | 
					package com.bonus.material.clz.domain.lease;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.bonus.common.core.annotation.Excel;
 | 
				
			||||||
 | 
					import com.bonus.material.back.domain.vo.MaCodeVo;
 | 
				
			||||||
 | 
					import io.swagger.annotations.ApiModelProperty;
 | 
				
			||||||
 | 
					import lombok.Data;
 | 
				
			||||||
 | 
					import lombok.ToString;
 | 
				
			||||||
 | 
					import org.apache.poi.ss.usermodel.HorizontalAlignment;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.math.BigDecimal;
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/**
 | 
				
			||||||
 | 
					 * 领料任务详细对象 lease_apply_details
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * @author xsheng
 | 
				
			||||||
 | 
					 * @date 2024-10-16
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					@Data
 | 
				
			||||||
 | 
					@ToString
 | 
				
			||||||
 | 
					public class LeaseDetailsInfo {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private static final long serialVersionUID = 1L;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "序号")
 | 
				
			||||||
 | 
					    @Excel(name = "序号", isSequence = true, sort = 0, width = 5)
 | 
				
			||||||
 | 
					    private Integer serialNumber;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /** ID */
 | 
				
			||||||
 | 
					    private Long id;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /** 任务ID */
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "任务ID")
 | 
				
			||||||
 | 
					    private Long parentId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "机具ID")
 | 
				
			||||||
 | 
					    private Long maId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /** 物资类型 */
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "物资类型名称")
 | 
				
			||||||
 | 
					    @Excel(name = "类型名称")
 | 
				
			||||||
 | 
					    private String maTypeName;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /** 物资类型ids */
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "物资类型ids")
 | 
				
			||||||
 | 
					    private int[] maTypeIds;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private String maTypeIdsStr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private int isManual;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /** 规格型号id */
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "规格型号id")
 | 
				
			||||||
 | 
					    private Long typeId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "规格型号id")
 | 
				
			||||||
 | 
					    private Long newTypeId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "三级id")
 | 
				
			||||||
 | 
					    private Long thirdTypeId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "规格型号id")
 | 
				
			||||||
 | 
					    private Long taskId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /** 规格型号 */
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "规格型号名称")
 | 
				
			||||||
 | 
					    @Excel(name = "规格型号")
 | 
				
			||||||
 | 
					    private String typeName;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "机具编码")
 | 
				
			||||||
 | 
					    private String maCode;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /** 计量单位 */
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "计量单位")
 | 
				
			||||||
 | 
					    @Excel(name = "计量单位")
 | 
				
			||||||
 | 
					    private String unitName;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /** 计量单位数值 */
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "计量单位数值")
 | 
				
			||||||
 | 
					    private String unitValue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /** 库存数量 */
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "库存数量")
 | 
				
			||||||
 | 
					    @Excel(name = "当前库存", cellType = Excel.ColumnType.NUMERIC, align = HorizontalAlignment.RIGHT)
 | 
				
			||||||
 | 
					    private BigDecimal storageNum;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /** 预领料数 */
 | 
				
			||||||
 | 
					    @Excel(name = "预领数量", cellType = Excel.ColumnType.NUMERIC, align = HorizontalAlignment.RIGHT)
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "预领料数")
 | 
				
			||||||
 | 
					    private BigDecimal preNum;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "已发布数量")
 | 
				
			||||||
 | 
					    private BigDecimal publishNum;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "待发布数量")
 | 
				
			||||||
 | 
					    private BigDecimal pendingNum;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "本次发布数量")
 | 
				
			||||||
 | 
					    private BigDecimal num;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /** 审批数量 */
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "审批数量")
 | 
				
			||||||
 | 
					    private BigDecimal auditNum;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * 此数量是剩余需要出库的数量(preNum - alNum)
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "剩余最大出库数量")
 | 
				
			||||||
 | 
					    private BigDecimal outNum;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /** 已领数量 */
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "已领数量")
 | 
				
			||||||
 | 
					    private BigDecimal alNum;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @ApiModelProperty(name = "装备管理方式")
 | 
				
			||||||
 | 
					    private String manageType;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /** 备注 */
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "备注")
 | 
				
			||||||
 | 
					    @Excel(name = "备注")
 | 
				
			||||||
 | 
					    private String remark;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /** 状态(0待审批,1进行中,2已出库) */
 | 
				
			||||||
 | 
					    private String status;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /** 数据所属组织 */
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "数据所属组织")
 | 
				
			||||||
 | 
					    private Long companyId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private String keyword;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "用户ID")
 | 
				
			||||||
 | 
					    private Long userId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "编码类型集合")
 | 
				
			||||||
 | 
					    private List<MaCodeVo> maCodeVoList;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "往来单位id")
 | 
				
			||||||
 | 
					    private Long unitId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "工程id")
 | 
				
			||||||
 | 
					    private Long projectId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "领料人")
 | 
				
			||||||
 | 
					    private String leasePerson;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "联系方式")
 | 
				
			||||||
 | 
					    private String phone;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "任务当月序号 例如:1 插入及查询时请携带任务类型")
 | 
				
			||||||
 | 
					    private Integer monthOrder;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "发布批次")
 | 
				
			||||||
 | 
					    private String publishTask;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "领料单位")
 | 
				
			||||||
 | 
					    private String leaseUnit;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "租赁工程")
 | 
				
			||||||
 | 
					    private String leaseProject;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -5,6 +5,7 @@ import com.bonus.material.back.domain.vo.MaCodeVo;
 | 
				
			||||||
import io.swagger.annotations.ApiModelProperty;
 | 
					import io.swagger.annotations.ApiModelProperty;
 | 
				
			||||||
import lombok.Data;
 | 
					import lombok.Data;
 | 
				
			||||||
import lombok.ToString;
 | 
					import lombok.ToString;
 | 
				
			||||||
 | 
					import org.apache.poi.ss.usermodel.HorizontalAlignment;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.math.BigDecimal;
 | 
					import java.math.BigDecimal;
 | 
				
			||||||
import java.util.List;
 | 
					import java.util.List;
 | 
				
			||||||
| 
						 | 
					@ -21,6 +22,10 @@ public class LeaseOutDetailsInfo {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private static final long serialVersionUID = 1L;
 | 
					    private static final long serialVersionUID = 1L;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @ApiModelProperty(value = "序号")
 | 
				
			||||||
 | 
					    @Excel(name = "序号", isSequence = true, sort = 0, width = 5)
 | 
				
			||||||
 | 
					    private Integer serialNumber;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /** ID */
 | 
					    /** ID */
 | 
				
			||||||
    private Long id;
 | 
					    private Long id;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -76,11 +81,11 @@ public class LeaseOutDetailsInfo {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /** 库存数量 */
 | 
					    /** 库存数量 */
 | 
				
			||||||
    @ApiModelProperty(value = "库存数量")
 | 
					    @ApiModelProperty(value = "库存数量")
 | 
				
			||||||
    @Excel(name = "当前库存")
 | 
					    @Excel(name = "当前库存", cellType = Excel.ColumnType.NUMERIC, align = HorizontalAlignment.RIGHT)
 | 
				
			||||||
    private BigDecimal storageNum;
 | 
					    private BigDecimal storageNum;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /** 预领料数 */
 | 
					    /** 预领料数 */
 | 
				
			||||||
    @Excel(name = "预领数量")
 | 
					    @Excel(name = "预领数量", cellType = Excel.ColumnType.NUMERIC, align = HorizontalAlignment.RIGHT)
 | 
				
			||||||
    @ApiModelProperty(value = "预领料数")
 | 
					    @ApiModelProperty(value = "预领料数")
 | 
				
			||||||
    private BigDecimal preNum;
 | 
					    private BigDecimal preNum;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -101,7 +106,7 @@ public class LeaseOutDetailsInfo {
 | 
				
			||||||
     * 此数量是剩余需要出库的数量(preNum - alNum)
 | 
					     * 此数量是剩余需要出库的数量(preNum - alNum)
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    @ApiModelProperty(value = "剩余最大出库数量")
 | 
					    @ApiModelProperty(value = "剩余最大出库数量")
 | 
				
			||||||
    @Excel(name = "出库数量")
 | 
					    @Excel(name = "出库数量", cellType = Excel.ColumnType.NUMERIC, align = HorizontalAlignment.RIGHT)
 | 
				
			||||||
    private BigDecimal outNum;
 | 
					    private BigDecimal outNum;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /** 已领数量 */
 | 
					    /** 已领数量 */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -181,4 +181,10 @@ public interface MaterialLeaseInfoService {
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    void queryQrCode(MaterialLeaseApplyDetails bean, HttpServletResponse response);
 | 
					    void queryQrCode(MaterialLeaseApplyDetails bean, HttpServletResponse response);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * 工器具领料申请详情
 | 
				
			||||||
 | 
					     * @param leaseApplyInfo
 | 
				
			||||||
 | 
					     * @return
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    List<LeaseDetailsInfo> exportDetails(MaterialLeaseApplyInfo leaseApplyInfo);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -631,6 +631,47 @@ public class MaterialLeaseInfoServiceImpl implements MaterialLeaseInfoService {
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * 导出设备出库信息
 | 
				
			||||||
 | 
					     * @param leaseApplyInfo
 | 
				
			||||||
 | 
					     * @return
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    @Override
 | 
				
			||||||
 | 
					    public List<LeaseDetailsInfo> exportDetails(MaterialLeaseApplyInfo leaseApplyInfo) {
 | 
				
			||||||
 | 
					        List<LeaseDetailsInfo> leaseOutDetails = new ArrayList<>();
 | 
				
			||||||
 | 
					        Optional<MaterialLeaseApplyInfo> optionalInfo = Optional.ofNullable(materialLeaseInfoMapper.selectLeaseApplyInfoById(leaseApplyInfo));
 | 
				
			||||||
 | 
					        optionalInfo.ifPresent(info -> {
 | 
				
			||||||
 | 
					            // 获取工器具领料出库详情
 | 
				
			||||||
 | 
					            List<MaterialLeaseApplyDetails> details = materialLeaseInfoMapper.getOutDetailsById(leaseApplyInfo);
 | 
				
			||||||
 | 
					            if (!CollectionUtils.isEmpty(details)) {
 | 
				
			||||||
 | 
					                // 步骤4.1: 收集所有typeId,进行批量查询
 | 
				
			||||||
 | 
					                List<Long> typeIds = details.stream()
 | 
				
			||||||
 | 
					                        .map(MaterialLeaseApplyDetails::getTypeId)
 | 
				
			||||||
 | 
					                        .filter(Objects::nonNull)
 | 
				
			||||||
 | 
					                        .distinct()
 | 
				
			||||||
 | 
					                        .collect(Collectors.toList());
 | 
				
			||||||
 | 
					                SelectDto selectDto = new SelectDto();
 | 
				
			||||||
 | 
					                selectDto.setProId(info.getProId());
 | 
				
			||||||
 | 
					                List<AgreementVo> agreementList = mapper.getAgreementInfoBy(selectDto);
 | 
				
			||||||
 | 
					                Map<Long, BigDecimal> storageNumMap = preCalculateStorageNums(info, agreementList, typeIds);
 | 
				
			||||||
 | 
					                for (MaterialLeaseApplyDetails detail : details) {
 | 
				
			||||||
 | 
					                    // 直接从预计算的Map中获取库存数据,避免复杂的嵌套循环
 | 
				
			||||||
 | 
					                    BigDecimal storageNum = storageNumMap.getOrDefault(detail.getTypeId(), BigDecimal.ZERO);
 | 
				
			||||||
 | 
					                    LeaseDetailsInfo lease = new LeaseDetailsInfo();
 | 
				
			||||||
 | 
					                    lease.setMaTypeName(detail.getMaTypeName() == null ? "" : detail.getMaTypeName());
 | 
				
			||||||
 | 
					                    lease.setTypeName(detail.getTypeName() == null ? "" : detail.getTypeName());
 | 
				
			||||||
 | 
					                    lease.setUnitName(detail.getUnitName() == null ? "" : detail.getUnitName());
 | 
				
			||||||
 | 
					                    lease.setPreNum(detail.getPreNum());
 | 
				
			||||||
 | 
					                    lease.setStorageNum(storageNum);
 | 
				
			||||||
 | 
					                    lease.setManageType("0".equals(detail.getManageType()) ? "数量管理" : "编码管理");
 | 
				
			||||||
 | 
					                    lease.setRemark(detail.getRemark() == null ? "" : detail.getRemark());
 | 
				
			||||||
 | 
					                    leaseOutDetails.add(lease);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					        return leaseOutDetails;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /** 简单的文件名清洗(避免非法字符) */
 | 
					    /** 简单的文件名清洗(避免非法字符) */
 | 
				
			||||||
    private String sanitizeFileName(String name) {
 | 
					    private String sanitizeFileName(String name) {
 | 
				
			||||||
        if (name == null) {
 | 
					        if (name == null) {
 | 
				
			||||||
| 
						 | 
					@ -1143,21 +1184,37 @@ public class MaterialLeaseInfoServiceImpl implements MaterialLeaseInfoService {
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public List<LeaseOutDetailsInfo> exportOutDetails(MaterialLeaseApplyInfo leaseApplyInfo) {
 | 
					    public List<LeaseOutDetailsInfo> exportOutDetails(MaterialLeaseApplyInfo leaseApplyInfo) {
 | 
				
			||||||
        List<LeaseOutDetailsInfo> leaseOutDetails = new ArrayList<>();
 | 
					        List<LeaseOutDetailsInfo> leaseOutDetails = new ArrayList<>();
 | 
				
			||||||
        List<MaterialLeaseApplyDetails> details = materialLeaseInfoMapper.getOutDetailsById(leaseApplyInfo);
 | 
					        Optional<MaterialLeaseApplyInfo> optionalInfo = Optional.ofNullable(materialLeaseInfoMapper.selectLeaseApplyInfoById(leaseApplyInfo));
 | 
				
			||||||
        if (!CollectionUtils.isEmpty(details)) {
 | 
					        optionalInfo.ifPresent(info -> {
 | 
				
			||||||
            for (MaterialLeaseApplyDetails detail : details) {
 | 
					            // 获取工器具领料出库详情
 | 
				
			||||||
                LeaseOutDetailsInfo lease = new LeaseOutDetailsInfo();
 | 
					            List<MaterialLeaseApplyDetails> details = materialLeaseInfoMapper.getOutDetailsById(leaseApplyInfo);
 | 
				
			||||||
                lease.setMaTypeName(detail.getMaTypeName() == null ? "" : detail.getMaTypeName());
 | 
					            if (!CollectionUtils.isEmpty(details)) {
 | 
				
			||||||
                lease.setTypeName(detail.getTypeName() == null ? "" : detail.getTypeName());
 | 
					                // 步骤4.1: 收集所有typeId,进行批量查询
 | 
				
			||||||
                lease.setUnitName(detail.getUnitName() == null ? "" : detail.getUnitName());
 | 
					                List<Long> typeIds = details.stream()
 | 
				
			||||||
                lease.setPreNum(detail.getPreNum());
 | 
					                        .map(MaterialLeaseApplyDetails::getTypeId)
 | 
				
			||||||
                lease.setStorageNum(detail.getStorageNum());
 | 
					                        .filter(Objects::nonNull)
 | 
				
			||||||
                lease.setOutNum(detail.getOutNum());
 | 
					                        .distinct()
 | 
				
			||||||
                lease.setManageType("0".equals(detail.getManageType()) ? "数量管理" : "编码管理");
 | 
					                        .collect(Collectors.toList());
 | 
				
			||||||
                lease.setRemark(detail.getRemark() == null ? "" : detail.getRemark());
 | 
					                SelectDto selectDto = new SelectDto();
 | 
				
			||||||
                leaseOutDetails.add(lease);
 | 
					                selectDto.setProId(info.getProId());
 | 
				
			||||||
 | 
					                List<AgreementVo> agreementList = mapper.getAgreementInfoBy(selectDto);
 | 
				
			||||||
 | 
					                Map<Long, BigDecimal> storageNumMap = preCalculateStorageNums(info, agreementList, typeIds);
 | 
				
			||||||
 | 
					                for (MaterialLeaseApplyDetails detail : details) {
 | 
				
			||||||
 | 
					                    // 直接从预计算的Map中获取库存数据,避免复杂的嵌套循环
 | 
				
			||||||
 | 
					                    BigDecimal storageNum = storageNumMap.getOrDefault(detail.getTypeId(), BigDecimal.ZERO);
 | 
				
			||||||
 | 
					                    LeaseOutDetailsInfo lease = new LeaseOutDetailsInfo();
 | 
				
			||||||
 | 
					                    lease.setMaTypeName(detail.getMaTypeName() == null ? "" : detail.getMaTypeName());
 | 
				
			||||||
 | 
					                    lease.setTypeName(detail.getTypeName() == null ? "" : detail.getTypeName());
 | 
				
			||||||
 | 
					                    lease.setUnitName(detail.getUnitName() == null ? "" : detail.getUnitName());
 | 
				
			||||||
 | 
					                    lease.setPreNum(detail.getPreNum());
 | 
				
			||||||
 | 
					                    lease.setStorageNum(storageNum);
 | 
				
			||||||
 | 
					                    lease.setOutNum(detail.getOutNum());
 | 
				
			||||||
 | 
					                    lease.setManageType("0".equals(detail.getManageType()) ? "数量管理" : "编码管理");
 | 
				
			||||||
 | 
					                    lease.setRemark(detail.getRemark() == null ? "" : detail.getRemark());
 | 
				
			||||||
 | 
					                    leaseOutDetails.add(lease);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        });
 | 
				
			||||||
        return leaseOutDetails;
 | 
					        return leaseOutDetails;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue