Commit 10082e55a471a9cbf2e32ccd8356240f05af3121

Authored by 房远帅
1 parent 3fcc097b

采购-入库:原料结算详情单

Showing 45 changed files with 2568 additions and 15 deletions
... ... @@ -2726,3 +2726,91 @@ CREATE TABLE IF NOT EXISTS `procurement_assay_report_line`
2726 2726 KEY `idx_parl_assay_apply_id` (`assay_apply_id`),
2727 2727 KEY `idx_parl_product_id` (`product_id`)
2728 2728 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='原料化验报告单明细';
  2729 +
  2730 +-- ============================================================
  2731 +-- 原料结算详情单(入库第四个模块)
  2732 +-- 主表 + 申请净重明细子表 + 详情明细子表
  2733 +-- 仓库统计员制单 -> 仓库质检(复核)-> 供应管理科质检员(复核)-> 仓库主管
  2734 +-- 一个原料结算详情单只关联一个过磅码单,码单作废时同步作废本单
  2735 +-- ============================================================
  2736 +
  2737 +CREATE TABLE IF NOT EXISTS `procurement_material_settle_detail`
  2738 +(
  2739 + `id` varchar(32) NOT NULL COMMENT 'ID',
  2740 + `weighing_ticket_id` varchar(32) NOT NULL COMMENT '过磅码单ID(一单只关联一个过磅码单)',
  2741 + `weighing_ticket_code` varchar(50) DEFAULT NULL COMMENT '码单编号(冗余展示)',
  2742 + `ticket_date` date DEFAULT NULL COMMENT '日期(自动带出过磅码单日期)',
  2743 + `supplier_id` varchar(32) DEFAULT NULL COMMENT '供料单位ID(自动带出过磅码单)',
  2744 + `supplier_name` varchar(200) DEFAULT NULL COMMENT '单位(自动带出过磅码单供料单位)',
  2745 + `workshop_id` varchar(32) DEFAULT NULL COMMENT '分厂ID(自动带出过磅码单)',
  2746 + `workshop_name` varchar(200) DEFAULT NULL COMMENT '分厂名称(自动带出过磅码单)',
  2747 + `total_weigh_quantity` decimal(12,2) DEFAULT NULL COMMENT '合计过磅数',
  2748 + `total_fold_weight` decimal(12,2) DEFAULT NULL COMMENT '合计折斤',
  2749 + `total_return_weight` decimal(12,0) DEFAULT NULL COMMENT '合计退料',
  2750 + `total_net_weight` decimal(12,2) DEFAULT NULL COMMENT '合计入库净重',
  2751 + `settle_type` varchar(20) DEFAULT NULL COMMENT '类型 经销/双经销/买断',
  2752 + `remark` varchar(1000) DEFAULT NULL COMMENT '备注',
  2753 + `flow_node` varchar(50) DEFAULT NULL COMMENT '流程节点 CKTJY-仓库统计员 CKZJY-仓库质检 GYGLKZJY-供应管理科质检员 CKZG-仓库主管',
  2754 + `approval_status` varchar(50) DEFAULT NULL COMMENT '审核状态 DRAFT-草稿 AUDIT-审核中 PASS-审核通过 REFUSE-已驳回 CANCEL-已取消',
  2755 + `deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否作废 0-有效单 1-作废单(作废单只能查看)',
  2756 + `create_by_id` varchar(32) DEFAULT NULL COMMENT '创建人ID',
  2757 + `create_by` varchar(64) DEFAULT NULL COMMENT '创建人',
  2758 + `update_by_id` varchar(32) DEFAULT NULL COMMENT '更新人ID',
  2759 + `update_by` varchar(64) DEFAULT NULL COMMENT '更新人',
  2760 + `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  2761 + `update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  2762 + PRIMARY KEY (`id`),
  2763 + KEY `idx_pmsd_weighing_ticket_id` (`weighing_ticket_id`),
  2764 + KEY `idx_pmsd_workshop_id` (`workshop_id`),
  2765 + KEY `idx_pmsd_approval_status` (`approval_status`),
  2766 + KEY `idx_pmsd_flow_node` (`flow_node`),
  2767 + KEY `idx_pmsd_create_time` (`create_time`)
  2768 +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='原料结算详情单';
  2769 +
  2770 +
  2771 +CREATE TABLE IF NOT EXISTS `procurement_material_settle_apply_line`
  2772 +(
  2773 + `id` varchar(32) NOT NULL COMMENT 'ID',
  2774 + `settle_detail_id` varchar(32) NOT NULL COMMENT '原料结算详情单主表ID',
  2775 + `weighing_ticket_apply_line_id` varchar(32) DEFAULT NULL COMMENT '过磅码单申请数量明细ID(来源行主键)',
  2776 + `category` varchar(50) DEFAULT NULL COMMENT '类别(品种代号)',
  2777 + `breed_relationship_id` varchar(32) DEFAULT NULL COMMENT '品种关系表ID',
  2778 + `quantity` decimal(12,2) DEFAULT NULL COMMENT '数量',
  2779 + `order_no` int DEFAULT NULL COMMENT '排序号',
  2780 + `item_id` varchar(32) DEFAULT NULL COMMENT '前端行标识',
  2781 + `create_by_id` varchar(32) DEFAULT NULL COMMENT '创建人ID',
  2782 + `create_by` varchar(64) DEFAULT NULL COMMENT '创建人',
  2783 + `update_by_id` varchar(32) DEFAULT NULL COMMENT '更新人ID',
  2784 + `update_by` varchar(64) DEFAULT NULL COMMENT '更新人',
  2785 + `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  2786 + `update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  2787 + PRIMARY KEY (`id`),
  2788 + KEY `idx_pmsal_settle_detail_id` (`settle_detail_id`)
  2789 +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='原料结算详情单-申请净重明细';
  2790 +CREATE TABLE IF NOT EXISTS `procurement_material_settle_line`
  2791 +(
  2792 + `id` varchar(32) NOT NULL COMMENT 'ID',
  2793 + `settle_detail_id` varchar(32) NOT NULL COMMENT '原料结算详情单主表ID',
  2794 + `procurement_plan_id` varchar(32) DEFAULT NULL COMMENT '采购计划ID',
  2795 + `plan_code` varchar(50) DEFAULT NULL COMMENT '计划编号',
  2796 + `product_id` varchar(32) DEFAULT NULL COMMENT '品种ID(隐藏)',
  2797 + `category` varchar(50) DEFAULT NULL COMMENT '类别(品种代号)',
  2798 + `name` varchar(200) DEFAULT NULL COMMENT '名称(开票品名)',
  2799 + `weigh_quantity` decimal(12,2) DEFAULT NULL COMMENT '过磅数(自动带出,插入行不可改)',
  2800 + `impurity_rate` varchar(50) DEFAULT NULL COMMENT '杂率%',
  2801 + `fold_weight` decimal(12,2) DEFAULT NULL COMMENT '折斤(最多两位小数)',
  2802 + `return_weight` decimal(12,0) DEFAULT NULL COMMENT '退料(整数)',
  2803 + `net_weight` decimal(12,2) DEFAULT NULL COMMENT '入库净重',
  2804 + `remark` varchar(500) DEFAULT NULL COMMENT '备注',
  2805 + `order_no` int DEFAULT NULL COMMENT '排序号',
  2806 + `item_id` varchar(32) DEFAULT NULL COMMENT '前端行标识',
  2807 + `create_by_id` varchar(32) DEFAULT NULL COMMENT '创建人ID',
  2808 + `create_by` varchar(64) DEFAULT NULL COMMENT '创建人',
  2809 + `update_by_id` varchar(32) DEFAULT NULL COMMENT '更新人ID',
  2810 + `update_by` varchar(64) DEFAULT NULL COMMENT '更新人',
  2811 + `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  2812 + `update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  2813 + PRIMARY KEY (`id`),
  2814 + KEY `idx_pmsl_settle_detail_id` (`settle_detail_id`),
  2815 + KEY `idx_pmsl_procurement_plan_id` (`procurement_plan_id`)
  2816 +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='原料结算详情单-详情明细';
... ...
  1 +package com.lframework.xingyun.sc.bo.procurement;
  2 +
  3 +import io.swagger.annotations.ApiModelProperty;
  4 +import lombok.Data;
  5 +
  6 +/**
  7 + * 原料结算:所选计划下的计划明细下拉(选择计划后选择明细)
  8 + */
  9 +@Data
  10 +public class GetMaterialSettlePlanLineOptionBo {
  11 +
  12 + @ApiModelProperty("计划明细行ID")
  13 + private String planLineId;
  14 +
  15 + @ApiModelProperty("品种ID(品种关系表ID)")
  16 + private String productId;
  17 +
  18 + @ApiModelProperty("品种名称")
  19 + private String productName;
  20 +
  21 + @ApiModelProperty("类别(品种关系表代号)")
  22 + private String category;
  23 +
  24 + @ApiModelProperty("名称(开票品名)")
  25 + private String name;
  26 +}
... ...
  1 +package com.lframework.xingyun.sc.bo.procurement;
  2 +
  3 +import io.swagger.annotations.ApiModelProperty;
  4 +import lombok.Data;
  5 +
  6 +/**
  7 + * 原料结算:所选过磅码单下的计划编号下拉(只返回码单计划的补单,补单计划已生成即流程已完成)
  8 + */
  9 +@Data
  10 +public class GetMaterialSettlePlanOptionBo {
  11 +
  12 + @ApiModelProperty("计划ID(补单计划ID)")
  13 + private String planId;
  14 +
  15 + @ApiModelProperty("计划编号(补单编号 = 主计划编号+补)")
  16 + private String planCode;
  17 +}
... ...
  1 +package com.lframework.xingyun.sc.bo.procurement;
  2 +
  3 +import com.fasterxml.jackson.annotation.JsonFormat;
  4 +import com.lframework.starter.common.constants.StringPool;
  5 +import io.swagger.annotations.ApiModelProperty;
  6 +import lombok.Data;
  7 +
  8 +import java.time.LocalDateTime;
  9 +import java.util.List;
  10 +
  11 +/**
  12 + * 原料结算:选择过磅码单弹窗行数据(审核通过且已上传签字凭证且每个过磅品种的化验报告单全部审核通过的码单)
  13 + */
  14 +@Data
  15 +public class GetMaterialSettleSelectableTicketBo {
  16 +
  17 + @ApiModelProperty("过磅码单ID")
  18 + private String id;
  19 +
  20 + @ApiModelProperty("码单编号")
  21 + private String code;
  22 +
  23 + @ApiModelProperty("供料单位名称")
  24 + private String supplierName;
  25 +
  26 + @ApiModelProperty("分厂ID")
  27 + private String workshopId;
  28 +
  29 + @ApiModelProperty("分厂名称")
  30 + private String workshopName;
  31 +
  32 + @ApiModelProperty("完成时间(第一次上传签字凭证时间)")
  33 + @JsonFormat(pattern = StringPool.DATE_TIME_PATTERN)
  34 + private LocalDateTime completeTime;
  35 +
  36 + @ApiModelProperty("创建人")
  37 + private String createBy;
  38 +
  39 + @ApiModelProperty("过磅明细列表")
  40 + private List<GetProcurementWeighingTicketLineBo> weighLines;
  41 +
  42 + @ApiModelProperty("申请数量明细列表")
  43 + private List<GetProcurementWeighingTicketApplyLineBo> applyLines;
  44 +}
... ...
... ... @@ -30,6 +30,9 @@ public class GetProcurementAssayReportBo extends BaseBo<ProcurementAssayReport>
30 30 @ApiModelProperty("分厂名称")
31 31 private String workshopName;
32 32
  33 + @ApiModelProperty("分厂编号")
  34 + private String workshopCode;
  35 +
33 36 @ApiModelProperty("客户名称")
34 37 private String supplierName;
35 38
... ...
  1 +package com.lframework.xingyun.sc.bo.procurement;
  2 +
  3 +import com.fasterxml.jackson.annotation.JsonFormat;
  4 +import com.lframework.starter.common.constants.StringPool;
  5 +import com.lframework.starter.common.utils.StringUtil;
  6 +import com.lframework.starter.web.core.bo.BaseBo;
  7 +import com.lframework.xingyun.sc.procurement.entity.settle.ProcurementMaterialSettleDetail;
  8 +import io.swagger.annotations.ApiModelProperty;
  9 +import lombok.Data;
  10 +
  11 +import java.math.BigDecimal;
  12 +import java.time.LocalDate;
  13 +import java.time.LocalDateTime;
  14 +import java.util.ArrayList;
  15 +import java.util.Arrays;
  16 +import java.util.List;
  17 +import java.util.stream.Collectors;
  18 +
  19 +@Data
  20 +public class GetProcurementMaterialSettleDetailBo extends BaseBo<ProcurementMaterialSettleDetail> {
  21 +
  22 + @ApiModelProperty("ID")
  23 + private String id;
  24 +
  25 + @ApiModelProperty("过磅码单ID")
  26 + private String weighingTicketId;
  27 +
  28 + @ApiModelProperty("码单编号")
  29 + private String weighingTicketCode;
  30 +
  31 + @ApiModelProperty("日期(过磅码单日期)")
  32 + @JsonFormat(pattern = StringPool.DATE_PATTERN)
  33 + private LocalDate ticketDate;
  34 +
  35 + @ApiModelProperty("供料单位ID")
  36 + private String supplierId;
  37 +
  38 + @ApiModelProperty("单位(供料单位名称)")
  39 + private String supplierName;
  40 +
  41 + @ApiModelProperty("分厂ID")
  42 + private String workshopId;
  43 +
  44 + @ApiModelProperty("分厂名称")
  45 + private String workshopName;
  46 +
  47 + @ApiModelProperty("合计过磅数(前端计算,后端存储与展示)")
  48 + private BigDecimal totalWeighQuantity;
  49 +
  50 + @ApiModelProperty("合计折斤(前端计算,后端存储与展示)")
  51 + private BigDecimal totalFoldWeight;
  52 +
  53 + @ApiModelProperty("合计退料(前端计算,后端存储与展示)")
  54 + private BigDecimal totalReturnWeight;
  55 +
  56 + @ApiModelProperty("合计入库净重(前端计算,后端存储与展示)")
  57 + private BigDecimal totalNetWeight;
  58 +
  59 + @ApiModelProperty("类型 经销/双经销/买断")
  60 + private String settleType;
  61 +
  62 + @ApiModelProperty("备注")
  63 + private String remark;
  64 +
  65 + @ApiModelProperty("流程节点 CKTJY/CKZJY/GYGLKZJY/CKZG")
  66 + private String flowNode;
  67 +
  68 + @ApiModelProperty("审核状态 DRAFT/AUDIT/PASS/REFUSE/CANCEL")
  69 + private String approvalStatus;
  70 +
  71 + @ApiModelProperty("计划编号集合(取自过磅码单关联的计划,不可改,列表/详情展示用)")
  72 + private List<String> planCode;
  73 +
  74 + @ApiModelProperty("计划ID集合(取自过磅码单关联的计划,不可改,列表/详情展示用)")
  75 + private List<String> planIds;
  76 +
  77 + @ApiModelProperty("申请净重明细(自动带出过磅码单的申请数量明细)")
  78 + private List<ApplyLineBo> applyLines = new ArrayList<>();
  79 +
  80 + @ApiModelProperty("详情明细(过磅明细,可新增/删除/插入)")
  81 + private List<LineBo> lines = new ArrayList<>();
  82 +
  83 + @ApiModelProperty("是否展示审核按钮")
  84 + private Boolean showExamine;
  85 +
  86 + @ApiModelProperty("是否展示审核详情按钮")
  87 + private Boolean showExamineDetail;
  88 +
  89 + @ApiModelProperty("创建人")
  90 + private String createBy;
  91 +
  92 + @ApiModelProperty("创建人ID")
  93 + private String createById;
  94 +
  95 + @ApiModelProperty("创建时间")
  96 + @JsonFormat(pattern = StringPool.DATE_TIME_PATTERN)
  97 + private LocalDateTime createTime;
  98 +
  99 + public GetProcurementMaterialSettleDetailBo() {
  100 + super();
  101 + }
  102 +
  103 + public GetProcurementMaterialSettleDetailBo(ProcurementMaterialSettleDetail dto) {
  104 + super(dto);
  105 + // 计划编号/ID集合取自过磅码单关联的计划(GROUP_CONCAT 串),拆分为集合展示
  106 + if (dto != null && StringUtil.isNotBlank(dto.getPlanCodes())) {
  107 + this.planCode = Arrays.stream(dto.getPlanCodes().split("[,,]"))
  108 + .map(String::trim).filter(StringUtil::isNotBlank).distinct()
  109 + .collect(Collectors.toList());
  110 + }
  111 + if (dto != null && StringUtil.isNotBlank(dto.getPlanIds())) {
  112 + this.planIds = Arrays.stream(dto.getPlanIds().split("[,,]"))
  113 + .map(String::trim).filter(StringUtil::isNotBlank).distinct()
  114 + .collect(Collectors.toList());
  115 + }
  116 + }
  117 +
  118 + @Data
  119 + public static class ApplyLineBo {
  120 +
  121 + @ApiModelProperty("过磅码单申请数量明细ID(来源行主键,数据追溯)")
  122 + private String weighingTicketApplyLineId;
  123 +
  124 + @ApiModelProperty("类别(品种代号)")
  125 + private String category;
  126 +
  127 + @ApiModelProperty("品种关系表ID")
  128 + private String breedRelationshipId;
  129 +
  130 + @ApiModelProperty("数量")
  131 + private BigDecimal quantity;
  132 + }
  133 +
  134 + @Data
  135 + public static class LineBo {
  136 +
  137 + @ApiModelProperty("采购计划ID")
  138 + private String procurementPlanId;
  139 +
  140 + @ApiModelProperty("计划编号")
  141 + private String planCode;
  142 +
  143 + @ApiModelProperty("品种ID(隐藏)")
  144 + private String productId;
  145 +
  146 + @ApiModelProperty("品种名称")
  147 + private String productName;
  148 +
  149 + @ApiModelProperty("类别(品种代号)")
  150 + private String category;
  151 +
  152 + @ApiModelProperty("名称(开票品名)")
  153 + private String name;
  154 +
  155 + @ApiModelProperty("过磅数")
  156 + private BigDecimal weighQuantity;
  157 +
  158 + @ApiModelProperty("杂率%")
  159 + private String impurityRate;
  160 +
  161 + @ApiModelProperty("折斤")
  162 + private BigDecimal foldWeight;
  163 +
  164 + @ApiModelProperty("退料")
  165 + private BigDecimal returnWeight;
  166 +
  167 + @ApiModelProperty("入库净重")
  168 + private BigDecimal netWeight;
  169 +
  170 + @ApiModelProperty("备注")
  171 + private String remark;
  172 + }
  173 +}
... ...
... ... @@ -25,6 +25,9 @@ public class GetProcurementWeighingTicketLineBo extends BaseBo<ProcurementWeighi
25 25 @ApiModelProperty("过磅品种名称")
26 26 private String productName;
27 27
  28 + @ApiModelProperty("类别(品种关系表代号)")
  29 + private String category;
  30 +
28 31 @ApiModelProperty("开票品名")
29 32 private String invoiceProductName;
30 33
... ...
... ... @@ -29,6 +29,7 @@ import com.lframework.xingyun.sc.procurement.service.plan.ProcurementPlanService
29 29 import com.lframework.xingyun.sc.procurement.service.quotation.SalesmanQuotationService;
30 30 import com.lframework.xingyun.sc.procurement.service.replenish.ProcurementPlanReplenishService;
31 31 import com.lframework.xingyun.sc.procurement.service.weighing.ProcurementAssayApplyService;
  32 +import com.lframework.xingyun.sc.procurement.service.settle.ProcurementMaterialSettleDetailService;
32 33 import com.lframework.xingyun.sc.procurement.service.weighing.ProcurementAssayReportService;
33 34 import com.lframework.xingyun.sc.procurement.service.weighing.ProcurementWeighingTicketService;
34 35 import com.lframework.xingyun.sc.service.contract.ContractDistributorLineService;
... ... @@ -180,6 +181,8 @@ public class BusinessDataHandlerServiceImpl implements BusinessDataHandlerServic
180 181 private ProcurementAssayApplyService procurementAssayApplyService;
181 182 @Resource
182 183 private ProcurementAssayReportService procurementAssayReportService;
  184 + @Resource
  185 + private ProcurementMaterialSettleDetailService procurementMaterialSettleDetailService;
183 186
184 187
185 188
... ... @@ -294,6 +297,9 @@ public class BusinessDataHandlerServiceImpl implements BusinessDataHandlerServic
294 297 case "ASSAY_REPORT":
295 298 handleAssayReportData(flowStatus, businessId);
296 299 break;
  300 + case "MATERIAL_SETTLE_DETAIL":
  301 + handleMaterialSettleDetailData(flowStatus, businessId);
  302 + break;
297 303 default:
298 304 break;
299 305 }
... ... @@ -1288,4 +1294,15 @@ public class BusinessDataHandlerServiceImpl implements BusinessDataHandlerServic
1288 1294 procurementAssayReportService.updateApprovalStatus(businessId, "REFUSE");
1289 1295 }
1290 1296 }
  1297 +
  1298 + private void handleMaterialSettleDetailData(String flowStatus, String businessId) {
  1299 + if (FlowInstanceStatus.APPROVE_PASS.getCode().equals(flowStatus)
  1300 + || FlowInstanceStatus.FINISH.getCode().equals(flowStatus)) {
  1301 + procurementMaterialSettleDetailService.updateApprovalStatus(businessId, "PASS");
  1302 + } else if (FlowInstanceStatus.REVOKE.getCode().equals(flowStatus)
  1303 + || FlowInstanceStatus.REFUSE.getCode().equals(flowStatus)
  1304 + || FlowInstanceStatus.TERMINATION.getCode().equals(flowStatus)) {
  1305 + procurementMaterialSettleDetailService.updateApprovalStatus(businessId, "REFUSE");
  1306 + }
  1307 + }
1291 1308 }
... ...
... ... @@ -22,6 +22,7 @@ import com.lframework.xingyun.sc.procurement.service.change.ProcurementPlanChang
22 22 import com.lframework.xingyun.sc.procurement.service.coordination.CoordinationSummaryApprovalService;
23 23 import com.lframework.xingyun.sc.procurement.service.plan.ProcurementPlanService;
24 24 import com.lframework.xingyun.sc.procurement.service.replenish.ProcurementPlanReplenishService;
  25 +import com.lframework.xingyun.sc.procurement.service.settle.ProcurementMaterialSettleDetailService;
25 26 import com.lframework.xingyun.sc.procurement.service.weighing.ProcurementAssayReportService;
26 27 import com.lframework.xingyun.sc.procurement.service.weighing.ProcurementWeighingTicketService;
27 28 import com.lframework.xingyun.sc.procurement.vo.change.UpdateProcurementPlanChangeVo;
... ... @@ -79,6 +80,8 @@ public class FlowTaskServiceImpl implements FlowTaskService {
79 80 private ProcurementWeighingTicketService procurementWeighingTicketService;
80 81 @Resource
81 82 private ProcurementAssayReportService procurementAssayReportService;
  83 + @Resource
  84 + private ProcurementMaterialSettleDetailService procurementMaterialSettleDetailService;
82 85
83 86
84 87 @OpLog(type = OtherOpLogType.class, name = "修改客户资信,ID:{}", params = {"#id"})
... ... @@ -496,15 +499,11 @@ public class FlowTaskServiceImpl implements FlowTaskService {
496 499 procurementAssayReportService.updateNoFlowInstance(map);
497 500 }
498 501
499   - @Override
500   - public void updateWeighingTicketApprovalMap(Map<String, Object> map) {
501   -
502   - }
503   -
504   - @Override
505   - public void updateAssayReportApprovalMap(Map<String, Object> map) {
506   -
507   - }
  502 +// @Transactional(rollbackFor = Exception.class)
  503 +// @Override
  504 +// public void updateMaterialSettleDetailApprovalMap(Map<String, Object> map) {
  505 +// procurementMaterialSettleDetailService.updateNoFlowInstance(map);
  506 +// }
508 507
509 508 @Override
510 509 public Map<String, Object> findById(String s) {
... ...
  1 +package com.lframework.xingyun.sc.procurement.controller.settle;
  2 +
  3 +import com.lframework.starter.web.core.annotations.security.HasPermission;
  4 +import com.lframework.starter.web.core.components.resp.InvokeResult;
  5 +import com.lframework.starter.web.core.components.resp.InvokeResultBuilder;
  6 +import com.lframework.starter.web.core.components.resp.PageResult;
  7 +import com.lframework.starter.web.core.controller.DefaultBaseController;
  8 +import com.lframework.starter.web.core.utils.PageResultUtil;
  9 +import com.lframework.xingyun.sc.bo.procurement.GetMaterialSettlePlanLineOptionBo;
  10 +import com.lframework.xingyun.sc.bo.procurement.GetMaterialSettlePlanOptionBo;
  11 +import com.lframework.xingyun.sc.bo.procurement.GetMaterialSettleSelectableTicketBo;
  12 +import com.lframework.xingyun.sc.bo.procurement.GetProcurementMaterialSettleDetailBo;
  13 +import com.lframework.xingyun.sc.procurement.entity.settle.ProcurementMaterialSettleDetail;
  14 +import com.lframework.xingyun.sc.procurement.service.settle.ProcurementMaterialSettleDetailService;
  15 +import com.lframework.xingyun.sc.procurement.vo.settle.CreateProcurementMaterialSettleDetailVo;
  16 +import com.lframework.xingyun.sc.procurement.vo.settle.QueryMaterialSettleSelectableTicketVo;
  17 +import com.lframework.xingyun.sc.procurement.vo.settle.QueryProcurementMaterialSettleDetailVo;
  18 +import com.lframework.xingyun.sc.procurement.vo.settle.UpdateProcurementMaterialSettleDetailVo;
  19 +import io.swagger.annotations.Api;
  20 +import io.swagger.annotations.ApiImplicitParam;
  21 +import io.swagger.annotations.ApiOperation;
  22 +import java.util.List;
  23 +import java.util.stream.Collectors;
  24 +import javax.annotation.Resource;
  25 +import javax.validation.Valid;
  26 +import javax.validation.constraints.NotBlank;
  27 +import lombok.extern.slf4j.Slf4j;
  28 +import org.springframework.util.CollectionUtils;
  29 +import org.springframework.validation.annotation.Validated;
  30 +import org.springframework.web.bind.annotation.GetMapping;
  31 +import org.springframework.web.bind.annotation.PostMapping;
  32 +import org.springframework.web.bind.annotation.PutMapping;
  33 +import org.springframework.web.bind.annotation.RequestBody;
  34 +import org.springframework.web.bind.annotation.RequestMapping;
  35 +import org.springframework.web.bind.annotation.RestController;
  36 +
  37 +/**
  38 + * 原料结算详情单
  39 + */
  40 +@Api(tags = "原料结算详情单管理")
  41 +@Slf4j
  42 +@Validated
  43 +@RestController
  44 +@RequestMapping("/procurement/material/settle")
  45 +public class ProcurementMaterialSettleDetailController extends DefaultBaseController {
  46 +
  47 + @Resource
  48 + private ProcurementMaterialSettleDetailService procurementMaterialSettleDetailService;
  49 +
  50 + @ApiOperation("分页查询原料结算详情单")
  51 + @HasPermission({"warehouse-manage:material-settle:query"})
  52 + @GetMapping("/query")
  53 + public InvokeResult<PageResult<GetProcurementMaterialSettleDetailBo>> query(
  54 + @Valid QueryProcurementMaterialSettleDetailVo vo) {
  55 + PageResult<ProcurementMaterialSettleDetail> result = procurementMaterialSettleDetailService.query(
  56 + getPageIndex(vo), getPageSize(vo), vo);
  57 +
  58 + List<GetProcurementMaterialSettleDetailBo> results = null;
  59 + if (!CollectionUtils.isEmpty(result.getDatas())) {
  60 + results = result.getDatas().stream().map(GetProcurementMaterialSettleDetailBo::new)
  61 + .collect(Collectors.toList());
  62 + }
  63 + return InvokeResultBuilder.success(PageResultUtil.rebuild(result, results));
  64 + }
  65 +
  66 + @ApiOperation("查询原料结算详情单详情")
  67 + @ApiImplicitParam(value = "ID", name = "id", paramType = "query", required = true)
  68 + @HasPermission({"warehouse-manage:material-settle:query", "warehouse-manage:material-settle:review"})
  69 + @GetMapping("")
  70 + public InvokeResult<GetProcurementMaterialSettleDetailBo> findById(
  71 + @NotBlank(message = "ID不能为空!") String id) {
  72 + return InvokeResultBuilder.success(procurementMaterialSettleDetailService.findDetail(id));
  73 + }
  74 +
  75 + @ApiOperation("选择码单弹窗:分页查询可制单的过磅码单(审核通过且已上传签字凭证且码单下每个过磅品种的化验报告单全部审核通过)")
  76 + @GetMapping("/ticketPage")
  77 + public InvokeResult<PageResult<GetMaterialSettleSelectableTicketBo>> querySelectableTickets(
  78 + @Valid QueryMaterialSettleSelectableTicketVo vo) {
  79 + return InvokeResultBuilder.success(procurementMaterialSettleDetailService.querySelectableTickets(
  80 + getPageIndex(vo), getPageSize(vo), vo));
  81 + }
  82 +
  83 + @ApiOperation("选择计划:所选码单下的计划编号下拉(只返回码单计划的补单,补单流程已完成即补单计划已生成;码单中已直接关联补单的主计划不再返回)")
  84 + @ApiImplicitParam(value = "过磅码单ID", name = "ticketId", paramType = "query", required = true)
  85 + @GetMapping("/planOptions")
  86 + public InvokeResult<List<GetMaterialSettlePlanOptionBo>> getPlanOptions(
  87 + @NotBlank(message = "过磅码单不能为空!") String ticketId) {
  88 + return InvokeResultBuilder.success(
  89 + procurementMaterialSettleDetailService.getPlanOptions(ticketId));
  90 + }
  91 +
  92 + @ApiOperation("选择明细:所选计划下的计划明细下拉(返回品种ID、品种名称、类别=品种关系表代号、名称=开票品名)")
  93 + @ApiImplicitParam(value = "采购计划ID", name = "planId", paramType = "query", required = true)
  94 + @GetMapping("/planLineOptions")
  95 + public InvokeResult<List<GetMaterialSettlePlanLineOptionBo>> getPlanLineOptions(
  96 + @NotBlank(message = "采购计划不能为空!") String planId) {
  97 + return InvokeResultBuilder.success(
  98 + procurementMaterialSettleDetailService.getPlanLineOptions(planId));
  99 + }
  100 +
  101 + @ApiOperation("新增原料结算详情单(草稿,分厂仓库统计员)")
  102 + @HasPermission({"warehouse-manage:material-settle:add"})
  103 + @PostMapping("")
  104 + public InvokeResult<String> create(@RequestBody @Valid CreateProcurementMaterialSettleDetailVo vo) {
  105 + String id = procurementMaterialSettleDetailService.create(vo);
  106 + return InvokeResultBuilder.success(id);
  107 + }
  108 +
  109 + @ApiOperation("修改原料结算详情单(仅草稿、已驳回可修改)")
  110 + @HasPermission({"warehouse-manage:material-settle:update"})
  111 + @PutMapping("")
  112 + public InvokeResult<Void> update(@RequestBody @Valid UpdateProcurementMaterialSettleDetailVo vo) {
  113 + procurementMaterialSettleDetailService.update(vo);
  114 + return InvokeResultBuilder.success();
  115 + }
  116 +
  117 + @ApiOperation("提交原料结算详情单审核(过磅合计数不等于折斤+退料+入库净重合计数时无法提交)")
  118 + @ApiImplicitParam(value = "ID", name = "id", paramType = "query", required = true)
  119 + @HasPermission({"warehouse-manage:material-settle:submit"})
  120 + @PutMapping("/submit")
  121 + public InvokeResult<Void> submit(@NotBlank(message = "ID不能为空!") String id) {
  122 + procurementMaterialSettleDetailService.submit(id);
  123 + return InvokeResultBuilder.success();
  124 + }
  125 +
  126 + @ApiOperation("退回原料结算详情单至草稿(仓库主管审批通过后可退回,已生成仓库收料单或买断入库核算单的不可退回)")
  127 + @ApiImplicitParam(value = "ID", name = "id", paramType = "query", required = true)
  128 + @HasPermission({"warehouse-manage:material-settle:return"})
  129 + @PutMapping("/returnDraft")
  130 + public InvokeResult<Void> returnDraft(@NotBlank(message = "ID不能为空!") String id) {
  131 + procurementMaterialSettleDetailService.returnDraft(id);
  132 + return InvokeResultBuilder.success();
  133 + }
  134 +
  135 + @ApiOperation("取消原料结算详情单(草稿、已驳回状态可取消)")
  136 + @ApiImplicitParam(value = "ID", name = "id", paramType = "query", required = true)
  137 + @HasPermission({"warehouse-manage:material-settle:cancel"})
  138 + @PutMapping("/cancel")
  139 + public InvokeResult<Void> cancel(@NotBlank(message = "ID不能为空!") String id) {
  140 + procurementMaterialSettleDetailService.cancel(id);
  141 + return InvokeResultBuilder.success();
  142 + }
  143 +}
... ...
  1 +package com.lframework.xingyun.sc.procurement.entity.settle;
  2 +
  3 +import com.baomidou.mybatisplus.annotation.FieldFill;
  4 +import com.baomidou.mybatisplus.annotation.TableField;
  5 +import com.baomidou.mybatisplus.annotation.TableName;
  6 +import com.lframework.starter.web.core.dto.BaseDto;
  7 +import com.lframework.starter.web.core.entity.BaseEntity;
  8 +import lombok.Data;
  9 +
  10 +import java.math.BigDecimal;
  11 +import java.time.LocalDateTime;
  12 +
  13 +/**
  14 + * 原料结算详情单-申请净重明细(自动带出过磅码单的申请数量明细)
  15 + */
  16 +@Data
  17 +@TableName("procurement_material_settle_apply_line")
  18 +public class ProcurementMaterialSettleApplyLine extends BaseEntity implements BaseDto {
  19 +
  20 + private static final long serialVersionUID = 1L;
  21 +
  22 + /**
  23 + * 主键ID
  24 + */
  25 + private String id;
  26 +
  27 + /**
  28 + * 原料结算详情单主表ID
  29 + */
  30 + private String settleDetailId;
  31 +
  32 + /**
  33 + * 过磅码单申请数量明细ID(来源行主键,数据追溯)
  34 + */
  35 + private String weighingTicketApplyLineId;
  36 +
  37 + /**
  38 + * 类别(品种代号)
  39 + */
  40 + private String category;
  41 +
  42 + /**
  43 + * 品种关系表ID
  44 + */
  45 + private String breedRelationshipId;
  46 +
  47 + /**
  48 + * 数量
  49 + */
  50 + private BigDecimal quantity;
  51 +
  52 + /**
  53 + * 排序号
  54 + */
  55 + private Integer orderNo;
  56 +
  57 + /**
  58 + * 前端行标识
  59 + */
  60 + private String itemId;
  61 +
  62 + /**
  63 + * 创建人ID
  64 + */
  65 + @TableField(fill = FieldFill.INSERT)
  66 + private String createById;
  67 +
  68 + /**
  69 + * 创建人
  70 + */
  71 + @TableField(fill = FieldFill.INSERT)
  72 + private String createBy;
  73 +
  74 + /**
  75 + * 更新人ID
  76 + */
  77 + @TableField(fill = FieldFill.INSERT_UPDATE)
  78 + private String updateById;
  79 +
  80 + /**
  81 + * 更新人
  82 + */
  83 + @TableField(fill = FieldFill.INSERT_UPDATE)
  84 + private String updateBy;
  85 +
  86 + /**
  87 + * 创建时间
  88 + */
  89 + @TableField(fill = FieldFill.INSERT)
  90 + private LocalDateTime createTime;
  91 +
  92 + /**
  93 + * 更新时间
  94 + */
  95 + @TableField(fill = FieldFill.INSERT_UPDATE)
  96 + private LocalDateTime updateTime;
  97 +}
... ...
  1 +package com.lframework.xingyun.sc.procurement.entity.settle;
  2 +
  3 +import com.baomidou.mybatisplus.annotation.FieldFill;
  4 +import com.baomidou.mybatisplus.annotation.TableField;
  5 +import com.baomidou.mybatisplus.annotation.TableName;
  6 +import com.lframework.starter.web.core.dto.BaseDto;
  7 +import com.lframework.starter.web.core.entity.BaseEntity;
  8 +import lombok.Data;
  9 +import lombok.EqualsAndHashCode;
  10 +
  11 +import java.math.BigDecimal;
  12 +import java.time.LocalDate;
  13 +import java.time.LocalDateTime;
  14 +
  15 +/**
  16 + * 原料结算详情单(入库第四个模块)
  17 + * 仓库统计员制单 -> 仓库质检(复核)-> 供应管理科质检员(复核)-> 仓库主管
  18 + */
  19 +@Data
  20 +@TableName("procurement_material_settle_detail")
  21 +public class ProcurementMaterialSettleDetail extends BaseEntity implements BaseDto {
  22 +
  23 + private static final long serialVersionUID = 1L;
  24 +
  25 + /**
  26 + * 主键ID
  27 + */
  28 + private String id;
  29 +
  30 + /**
  31 + * 过磅码单ID(一单只关联一个过磅码单)
  32 + */
  33 + private String weighingTicketId;
  34 +
  35 + /**
  36 + * 码单编号(冗余展示)
  37 + */
  38 + private String weighingTicketCode;
  39 +
  40 + /**
  41 + * 日期(自动带出过磅码单日期)
  42 + */
  43 + private LocalDate ticketDate;
  44 +
  45 + /**
  46 + * 供料单位ID(自动带出过磅码单)
  47 + */
  48 + private String supplierId;
  49 +
  50 + /**
  51 + * 单位(自动带出过磅码单供料单位)
  52 + */
  53 + private String supplierName;
  54 +
  55 + /**
  56 + * 分厂ID(自动带出过磅码单)
  57 + */
  58 + private String workshopId;
  59 +
  60 + /**
  61 + * 分厂名称(自动带出过磅码单)
  62 + */
  63 + private String workshopName;
  64 +
  65 + /**
  66 + * 合计过磅数(前端计算,后端存储与展示)
  67 + */
  68 + private BigDecimal totalWeighQuantity;
  69 +
  70 + /**
  71 + * 合计折斤(前端计算,后端存储与展示)
  72 + */
  73 + private BigDecimal totalFoldWeight;
  74 +
  75 + /**
  76 + * 合计退料(前端计算,后端存储与展示)
  77 + */
  78 + private BigDecimal totalReturnWeight;
  79 +
  80 + /**
  81 + * 合计入库净重(前端计算,后端存储与展示)
  82 + */
  83 + private BigDecimal totalNetWeight;
  84 +
  85 + /**
  86 + * 类型 经销/双经销/买断
  87 + */
  88 + private String settleType;
  89 +
  90 + /**
  91 + * 备注
  92 + */
  93 + private String remark;
  94 +
  95 + /**
  96 + * 流程节点 CKTJY-仓库统计员 CKZJY-仓库质检 GYGLKZJY-供应管理科质检员 CKZG-仓库主管
  97 + */
  98 + private String flowNode;
  99 +
  100 + /**
  101 + * 审核状态 DRAFT-草稿 AUDIT-审核中 PASS-审核通过 REFUSE-已驳回 CANCEL-已取消
  102 + */
  103 + private String approvalStatus;
  104 +
  105 + /**
  106 + * 是否作废/删除 0-有效单 1-作废单(作废单只能查看)
  107 + */
  108 + private Boolean deleted;
  109 +
  110 + /**
  111 + * 是否展示审核按钮
  112 + */
  113 + @TableField(exist = false)
  114 + private Boolean showExamine;
  115 +
  116 + /**
  117 + * 是否展示审核详情按钮
  118 + */
  119 + @TableField(exist = false)
  120 + private Boolean showExamineDetail;
  121 +
  122 + /**
  123 + * 计划编号集合(取自过磅码单关联的计划,不可改,列表/详情展示用)
  124 + */
  125 + @TableField(exist = false)
  126 + private String planCodes;
  127 +
  128 + /**
  129 + * 计划ID集合(取自过磅码单关联的计划,不可改,列表/详情展示用)
  130 + */
  131 + @TableField(exist = false)
  132 + private String planIds;
  133 +
  134 + /**
  135 + * 创建人ID
  136 + */
  137 + @TableField(fill = FieldFill.INSERT)
  138 + private String createById;
  139 +
  140 + /**
  141 + * 创建人
  142 + */
  143 + @TableField(exist = false)
  144 + private String createBy;
  145 +
  146 + /**
  147 + * 更新人ID
  148 + */
  149 + @TableField(fill = FieldFill.INSERT_UPDATE)
  150 + private String updateById;
  151 +
  152 + /**
  153 + * 更新人
  154 + */
  155 + @TableField(exist = false)
  156 + private String updateBy;
  157 +
  158 + /**
  159 + * 创建时间
  160 + */
  161 + @TableField(fill = FieldFill.INSERT)
  162 + private LocalDateTime createTime;
  163 +
  164 + /**
  165 + * 更新时间
  166 + */
  167 + @TableField(fill = FieldFill.INSERT_UPDATE)
  168 + private LocalDateTime updateTime;
  169 +}
... ...
  1 +package com.lframework.xingyun.sc.procurement.entity.settle;
  2 +
  3 +import com.baomidou.mybatisplus.annotation.FieldFill;
  4 +import com.baomidou.mybatisplus.annotation.TableField;
  5 +import com.baomidou.mybatisplus.annotation.TableName;
  6 +import com.lframework.starter.web.core.dto.BaseDto;
  7 +import com.lframework.starter.web.core.entity.BaseEntity;
  8 +import lombok.Data;
  9 +
  10 +import java.math.BigDecimal;
  11 +import java.time.LocalDateTime;
  12 +
  13 +/**
  14 + * 原料结算详情单-详情明细(自动带出过磅码单的过磅明细,可新增/删除/插入)
  15 + */
  16 +@Data
  17 +@TableName("procurement_material_settle_line")
  18 +public class ProcurementMaterialSettleLine extends BaseEntity implements BaseDto {
  19 +
  20 + private static final long serialVersionUID = 1L;
  21 +
  22 + /**
  23 + * 主键ID
  24 + */
  25 + private String id;
  26 +
  27 + /**
  28 + * 原料结算详情单主表ID
  29 + */
  30 + private String settleDetailId;
  31 +
  32 + /**
  33 + * 采购计划ID(计划编号及其补单编号)
  34 + */
  35 + private String procurementPlanId;
  36 +
  37 + /**
  38 + * 计划编号
  39 + */
  40 + private String planCode;
  41 +
  42 + /**
  43 + * 品种ID(隐藏)
  44 + */
  45 + private String productId;
  46 +
  47 + /**
  48 + * 品种名称(冗余,JOIN base_data_breed_relationship)
  49 + */
  50 + @TableField(exist = false)
  51 + private String productName;
  52 +
  53 + /**
  54 + * 类别(品种代号)
  55 + */
  56 + private String category;
  57 +
  58 + /**
  59 + * 名称(开票品名)
  60 + */
  61 + private String name;
  62 +
  63 + /**
  64 + * 过磅数(自动带出,插入行不可改)
  65 + */
  66 + private BigDecimal weighQuantity;
  67 +
  68 + /**
  69 + * 杂率%
  70 + */
  71 + private String impurityRate;
  72 +
  73 + /**
  74 + * 折斤(最多两位小数)
  75 + */
  76 + private BigDecimal foldWeight;
  77 +
  78 + /**
  79 + * 退料(整数)
  80 + */
  81 + private BigDecimal returnWeight;
  82 +
  83 + /**
  84 + * 入库净重
  85 + */
  86 + private BigDecimal netWeight;
  87 +
  88 + /**
  89 + * 备注
  90 + */
  91 + private String remark;
  92 +
  93 + /**
  94 + * 排序号
  95 + */
  96 + private Integer orderNo;
  97 +
  98 + /**
  99 + * 前端行标识
  100 + */
  101 + private String itemId;
  102 +
  103 + /**
  104 + * 创建人ID
  105 + */
  106 + @TableField(fill = FieldFill.INSERT)
  107 + private String createById;
  108 +
  109 + /**
  110 + * 创建人
  111 + */
  112 + @TableField(fill = FieldFill.INSERT)
  113 + private String createBy;
  114 +
  115 + /**
  116 + * 更新人ID
  117 + */
  118 + @TableField(fill = FieldFill.INSERT_UPDATE)
  119 + private String updateById;
  120 +
  121 + /**
  122 + * 更新人
  123 + */
  124 + @TableField(fill = FieldFill.INSERT_UPDATE)
  125 + private String updateBy;
  126 +
  127 + /**
  128 + * 创建时间
  129 + */
  130 + @TableField(fill = FieldFill.INSERT)
  131 + private LocalDateTime createTime;
  132 +
  133 + /**
  134 + * 更新时间
  135 + */
  136 + @TableField(fill = FieldFill.INSERT_UPDATE)
  137 + private LocalDateTime updateTime;
  138 +}
... ...
... ... @@ -44,6 +44,12 @@ public class ProcurementAssayReport extends BaseEntity implements BaseDto {
44 44 private String workshopName;
45 45
46 46 /**
  47 + * 分厂编号(联表 base_data_workshop 带出,非数据库字段)
  48 + */
  49 + @TableField(exist = false)
  50 + private String workshopCode;
  51 +
  52 + /**
47 53 * 客户名称(取自过磅码单供料单位)
48 54 */
49 55 private String supplierName;
... ...
... ... @@ -47,6 +47,12 @@ public class ProcurementWeighingTicketLine extends BaseEntity implements BaseDto
47 47 private String productName;
48 48
49 49 /**
  50 + * 类别(品种关系表代号,冗余,JOIN base_data_breed_relationship)
  51 + */
  52 + @TableField(exist = false)
  53 + private String category;
  54 +
  55 + /**
50 56 * 开票品名
51 57 */
52 58 private String invoiceProductName;
... ...
  1 +package com.lframework.xingyun.sc.procurement.impl.settle;
  2 +
  3 +import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  4 +import com.lframework.starter.web.core.impl.BaseMpServiceImpl;
  5 +import com.lframework.xingyun.sc.procurement.entity.settle.ProcurementMaterialSettleApplyLine;
  6 +import com.lframework.xingyun.sc.procurement.mappers.settle.ProcurementMaterialSettleApplyLineMapper;
  7 +import com.lframework.xingyun.sc.procurement.service.settle.ProcurementMaterialSettleApplyLineService;
  8 +import java.util.List;
  9 +import org.springframework.stereotype.Service;
  10 +
  11 +/**
  12 + * 原料结算详情单-申请净重明细
  13 + */
  14 +@Service
  15 +public class ProcurementMaterialSettleApplyLineServiceImpl
  16 + extends BaseMpServiceImpl<ProcurementMaterialSettleApplyLineMapper, ProcurementMaterialSettleApplyLine>
  17 + implements ProcurementMaterialSettleApplyLineService {
  18 +
  19 + @Override
  20 + public List<ProcurementMaterialSettleApplyLine> getBySettleDetailId(String settleDetailId) {
  21 + return this.list(Wrappers.lambdaQuery(ProcurementMaterialSettleApplyLine.class)
  22 + .eq(ProcurementMaterialSettleApplyLine::getSettleDetailId, settleDetailId)
  23 + .orderByAsc(ProcurementMaterialSettleApplyLine::getOrderNo));
  24 + }
  25 +
  26 + @Override
  27 + public void deleteBySettleDetailId(String settleDetailId) {
  28 + this.remove(Wrappers.lambdaQuery(ProcurementMaterialSettleApplyLine.class)
  29 + .eq(ProcurementMaterialSettleApplyLine::getSettleDetailId, settleDetailId));
  30 + }
  31 +}
... ...
  1 +package com.lframework.xingyun.sc.procurement.impl.settle;
  2 +
  3 +import cn.hutool.core.bean.BeanUtil;
  4 +import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  5 +import com.github.pagehelper.PageInfo;
  6 +import com.lframework.starter.bpm.dto.FlowTaskDto;
  7 +import com.lframework.starter.bpm.entity.FlowInstanceWrapper;
  8 +import com.lframework.starter.bpm.mappers.FlowTaskWrapperMapper;
  9 +import com.lframework.starter.bpm.service.FlowInstanceWrapperService;
  10 +import com.lframework.starter.bpm.service.FlowTaskWrapperService;
  11 +import com.lframework.starter.bpm.vo.flow.task.QueryTodoTaskListVo;
  12 +import com.lframework.starter.common.exceptions.impl.DefaultClientException;
  13 +import com.lframework.starter.common.exceptions.impl.InputErrorException;
  14 +import com.lframework.starter.common.utils.Assert;
  15 +import com.lframework.starter.common.utils.CollectionUtil;
  16 +import com.lframework.starter.common.utils.StringUtil;
  17 +import com.lframework.starter.web.core.annotations.oplog.OpLog;
  18 +import com.lframework.starter.web.core.components.resp.PageResult;
  19 +import com.lframework.starter.web.core.components.security.SecurityUtil;
  20 +import com.lframework.starter.web.core.impl.BaseMpServiceImpl;
  21 +import com.lframework.starter.web.core.utils.IdUtil;
  22 +import com.lframework.starter.web.core.utils.OpLogUtil;
  23 +import com.lframework.starter.web.core.utils.PageHelperUtil;
  24 +import com.lframework.starter.web.core.utils.PageResultUtil;
  25 +import com.lframework.starter.web.inner.components.oplog.OtherOpLogType;
  26 +import com.lframework.xingyun.sc.bo.procurement.GetMaterialSettlePlanLineOptionBo;
  27 +import com.lframework.xingyun.sc.bo.procurement.GetMaterialSettlePlanOptionBo;
  28 +import com.lframework.xingyun.sc.bo.procurement.GetMaterialSettleSelectableTicketBo;
  29 +import com.lframework.xingyun.sc.bo.procurement.GetProcurementMaterialSettleDetailBo;
  30 +import com.lframework.xingyun.sc.bo.procurement.GetProcurementWeighingTicketApplyLineBo;
  31 +import com.lframework.xingyun.sc.bo.procurement.GetProcurementWeighingTicketLineBo;
  32 +import com.lframework.xingyun.sc.procurement.entity.ProcurementPlan;
  33 +import com.lframework.xingyun.sc.procurement.entity.settle.ProcurementMaterialSettleApplyLine;
  34 +import com.lframework.xingyun.sc.procurement.entity.settle.ProcurementMaterialSettleDetail;
  35 +import com.lframework.xingyun.sc.procurement.entity.settle.ProcurementMaterialSettleLine;
  36 +import com.lframework.xingyun.sc.procurement.entity.weighing.ProcurementAssayReport;
  37 +import com.lframework.xingyun.sc.procurement.entity.weighing.ProcurementWeighingTicket;
  38 +import com.lframework.xingyun.sc.procurement.entity.weighing.ProcurementWeighingTicketApplyLine;
  39 +import com.lframework.xingyun.sc.procurement.entity.weighing.ProcurementWeighingTicketLine;
  40 +import com.lframework.xingyun.sc.procurement.mappers.settle.ProcurementMaterialSettleDetailMapper;
  41 +import com.lframework.xingyun.sc.procurement.mappers.weighing.ProcurementAssayReportMapper;
  42 +import com.lframework.xingyun.sc.procurement.mappers.weighing.ProcurementWeighingTicketMapper;
  43 +import com.lframework.xingyun.sc.procurement.service.plan.ProcurementPlanService;
  44 +import com.lframework.xingyun.sc.procurement.service.settle.ProcurementMaterialSettleApplyLineService;
  45 +import com.lframework.xingyun.sc.procurement.service.settle.ProcurementMaterialSettleDetailService;
  46 +import com.lframework.xingyun.sc.procurement.service.settle.ProcurementMaterialSettleLineService;
  47 +import com.lframework.xingyun.sc.procurement.service.weighing.ProcurementWeighingTicketApplyLineService;
  48 +import com.lframework.xingyun.sc.procurement.service.weighing.ProcurementWeighingTicketLineService;
  49 +import com.lframework.xingyun.sc.procurement.vo.settle.CreateProcurementMaterialSettleDetailVo;
  50 +import com.lframework.xingyun.sc.procurement.vo.settle.MaterialSettleApplyLineVo;
  51 +import com.lframework.xingyun.sc.procurement.vo.settle.MaterialSettleLineVo;
  52 +import com.lframework.xingyun.sc.procurement.vo.settle.QueryMaterialSettleSelectableTicketVo;
  53 +import com.lframework.xingyun.sc.procurement.vo.settle.QueryProcurementMaterialSettleDetailVo;
  54 +import com.lframework.xingyun.sc.procurement.vo.settle.UpdateProcurementMaterialSettleDetailVo;
  55 +
  56 +import java.math.BigDecimal;
  57 +import java.time.LocalDate;
  58 +import java.util.ArrayList;
  59 +import java.util.Collections;
  60 +import java.util.HashMap;
  61 +import java.util.HashSet;
  62 +import java.util.List;
  63 +import java.util.Map;
  64 +import java.util.Objects;
  65 +import java.util.Set;
  66 +import java.util.stream.Collectors;
  67 +import javax.annotation.Resource;
  68 +
  69 +import lombok.extern.slf4j.Slf4j;
  70 +import org.springframework.stereotype.Service;
  71 +import org.springframework.transaction.annotation.Transactional;
  72 +
  73 +/**
  74 + * 原料结算详情单(入库第四个模块)
  75 + * 仓库统计员制单 -> 仓库质检(复核)-> 供应管理科质检员(复核)-> 仓库主管
  76 + */
  77 +@Slf4j
  78 +@Service
  79 +public class ProcurementMaterialSettleDetailServiceImpl
  80 + extends BaseMpServiceImpl<ProcurementMaterialSettleDetailMapper, ProcurementMaterialSettleDetail>
  81 + implements ProcurementMaterialSettleDetailService {
  82 +
  83 + /**
  84 + * 审核状态-草稿
  85 + */
  86 + private static final String STATUS_DRAFT = "DRAFT";
  87 + /**
  88 + * 审核状态-审核中
  89 + */
  90 + private static final String STATUS_AUDIT = "AUDIT";
  91 + /**
  92 + * 审核状态-审核通过
  93 + */
  94 + private static final String STATUS_PASS = "PASS";
  95 + /**
  96 + * 审核状态-已驳回
  97 + */
  98 + private static final String STATUS_REFUSE = "REFUSE";
  99 + /**
  100 + * 审核状态-已取消
  101 + */
  102 + private static final String STATUS_CANCEL = "CANCEL";
  103 + /**
  104 + * 流程编号(需与流程设计器中的流程编号一致,流程创建后调整)
  105 + */
  106 + private static final String BPM_FLAG = "MATERIAL_SETTLE_DETAIL";
  107 + /**
  108 + * 流程节点编码(大写英文,存 flow_node):
  109 + * 仓库统计员(制单) -> 仓库质检(复核) -> 供应管理科质检员(复核) -> 仓库主管
  110 + */
  111 + private static final String NODE_CKTJY = "CKTJY";
  112 + private static final String NODE_CKZJY = "CKZJY";
  113 + private static final String NODE_GYGLKZJY = "GYGLKZJY";
  114 + private static final String NODE_CKZG = "CKZG";
  115 +
  116 + @Resource
  117 + private ProcurementMaterialSettleDetailMapper settleDetailMapper;
  118 +
  119 + @Resource
  120 + private ProcurementMaterialSettleApplyLineService applyLineService;
  121 +
  122 + @Resource
  123 + private ProcurementMaterialSettleLineService settleLineService;
  124 +
  125 + @Resource
  126 + private ProcurementWeighingTicketMapper weighingTicketMapper;
  127 +
  128 + @Resource
  129 + private ProcurementWeighingTicketLineService weighLineService;
  130 +
  131 + @Resource
  132 + private ProcurementWeighingTicketApplyLineService weighApplyLineService;
  133 +
  134 + @Resource
  135 + private ProcurementAssayReportMapper assayReportMapper;
  136 +
  137 + @Resource
  138 + private ProcurementPlanService procurementPlanService;
  139 +
  140 + @Resource
  141 + private FlowInstanceWrapperService flowInstanceWrapperService;
  142 +
  143 + @Resource
  144 + private FlowTaskWrapperMapper flowTaskWrapperMapper;
  145 +
  146 + @Resource
  147 + private FlowTaskWrapperService flowTaskWrapperService;
  148 +
  149 + @Override
  150 + public PageResult<ProcurementMaterialSettleDetail> query(Integer pageIndex, Integer pageSize,
  151 + QueryProcurementMaterialSettleDetailVo vo) {
  152 + PageHelperUtil.startPage(pageIndex, pageSize);
  153 + List<ProcurementMaterialSettleDetail> datas = settleDetailMapper.query(vo);
  154 + PageResult<ProcurementMaterialSettleDetail> pageResult = PageResultUtil.convert(new PageInfo<>(datas));
  155 +
  156 + fillOperateFlags(pageResult.getDatas());
  157 +
  158 + return pageResult;
  159 + }
  160 +
  161 + @Override
  162 + public PageResult<GetMaterialSettleSelectableTicketBo> querySelectableTickets(Integer pageIndex,
  163 + Integer pageSize, QueryMaterialSettleSelectableTicketVo vo) {
  164 + PageHelperUtil.startPage(pageIndex, pageSize);
  165 + List<GetMaterialSettleSelectableTicketBo> datas = settleDetailMapper.querySelectableTickets(vo);
  166 + PageResult<GetMaterialSettleSelectableTicketBo> pageResult = PageResultUtil.convert(new PageInfo<>(datas));
  167 +
  168 + fillWeighLines(pageResult.getDatas());
  169 +
  170 + return pageResult;
  171 + }
  172 +
  173 + /**
  174 + * 填充可制单码单的过磅明细列表(含类别=品种关系表代号)和申请数量明细列表
  175 + */
  176 + private void fillWeighLines(List<GetMaterialSettleSelectableTicketBo> datas) {
  177 + if (CollectionUtil.isEmpty(datas)) {
  178 + return;
  179 + }
  180 + List<String> ticketIds = datas.stream().map(GetMaterialSettleSelectableTicketBo::getId)
  181 + .distinct().collect(Collectors.toList());
  182 +
  183 + List<ProcurementWeighingTicketLine> weighLines = weighLineService.getByWeighingTicketIds(ticketIds);
  184 + Map<String, List<GetProcurementWeighingTicketLineBo>> weighLineMap = CollectionUtil.isEmpty(weighLines)
  185 + ? new HashMap<>() : weighLines.stream().collect(Collectors.groupingBy(
  186 + ProcurementWeighingTicketLine::getWeighingTicketId,
  187 + Collectors.mapping(GetProcurementWeighingTicketLineBo::new, Collectors.toList())));
  188 +
  189 + List<ProcurementWeighingTicketApplyLine> applyLines = weighApplyLineService.getByWeighingTicketIds(ticketIds);
  190 + Map<String, List<GetProcurementWeighingTicketApplyLineBo>> applyLineMap = CollectionUtil.isEmpty(applyLines)
  191 + ? new HashMap<>() : applyLines.stream().collect(Collectors.groupingBy(
  192 + ProcurementWeighingTicketApplyLine::getWeighingTicketId,
  193 + Collectors.mapping(GetProcurementWeighingTicketApplyLineBo::new, Collectors.toList())));
  194 +
  195 + for (GetMaterialSettleSelectableTicketBo ticket : datas) {
  196 + List<GetProcurementWeighingTicketLineBo> weighList = weighLineMap.get(ticket.getId());
  197 + ticket.setWeighLines(weighList == null ? new ArrayList<>() : weighList);
  198 + List<GetProcurementWeighingTicketApplyLineBo> applyList = applyLineMap.get(ticket.getId());
  199 + ticket.setApplyLines(applyList == null ? new ArrayList<>() : applyList);
  200 + }
  201 + }
  202 +
  203 + @Override
  204 + public List<GetMaterialSettlePlanOptionBo> getPlanOptions(String ticketId) {
  205 + if (StringUtil.isBlank(ticketId)) {
  206 + throw new DefaultClientException("过磅码单不能为空!");
  207 + }
  208 + assertTicketUsable(ticketId);
  209 +
  210 + // 1. 码单计划行:编号带"补"的说明补单已直接关联到过磅码单,不再重复选择;只保留主计划编号
  211 + List<GetMaterialSettlePlanOptionBo> datas = settleDetailMapper.queryTicketPlans(ticketId);
  212 + List<String> mainPlanCodes = datas.stream()
  213 + .filter(item -> item != null && StringUtil.isNotBlank(item.getPlanCode())
  214 + && !item.getPlanCode().endsWith("补"))
  215 + .map(GetMaterialSettlePlanOptionBo::getPlanCode)
  216 + .distinct()
  217 + .collect(Collectors.toList());
  218 + if (CollectionUtil.isEmpty(mainPlanCodes)) {
  219 + return new ArrayList<>();
  220 + }
  221 +
  222 + // 2. 补单计划已生成(即补单流程已完成)的才可选:编号 = 主计划编号+补,计划类型含"补"
  223 + List<ProcurementPlan> replenishPlans = procurementPlanService.list(
  224 + Wrappers.lambdaQuery(ProcurementPlan.class)
  225 + .in(ProcurementPlan::getCode, mainPlanCodes)
  226 + .like(ProcurementPlan::getPlanType, "补")
  227 + .eq(ProcurementPlan::getDeleted, false));
  228 + if (CollectionUtil.isEmpty(replenishPlans)) {
  229 + return new ArrayList<>();
  230 + }
  231 + Map<String, ProcurementPlan> replenishMap = replenishPlans.stream()
  232 + .filter(p -> p != null && StringUtil.isNotBlank(p.getCode()))
  233 + .collect(Collectors.toMap(ProcurementPlan::getCode, p -> p, (v1, v2) -> v1));
  234 +
  235 + // 3. 按码单计划行序输出补单
  236 + List<GetMaterialSettlePlanOptionBo> result = new ArrayList<>();
  237 + Set<String> seenPlanIds = new HashSet<>();
  238 + for (String planCode : mainPlanCodes) {
  239 + ProcurementPlan replenish = replenishMap.get(planCode);
  240 + if (replenish != null && seenPlanIds.add(replenish.getId())) {
  241 + GetMaterialSettlePlanOptionBo bo = new GetMaterialSettlePlanOptionBo();
  242 + bo.setPlanId(replenish.getId());
  243 + bo.setPlanCode(replenish.getCode() + replenish.getPlanType());
  244 + result.add(bo);
  245 + }
  246 + }
  247 + return result;
  248 + }
  249 +
  250 + @Override
  251 + public List<GetMaterialSettlePlanLineOptionBo> getPlanLineOptions(String planId) {
  252 + if (StringUtil.isBlank(planId)) {
  253 + throw new DefaultClientException("采购计划不能为空!");
  254 + }
  255 + ProcurementPlan plan = procurementPlanService.getById(planId);
  256 + if (plan == null || Boolean.TRUE.equals(plan.getDeleted())) {
  257 + throw new DefaultClientException("采购计划不存在!");
  258 + }
  259 + return settleDetailMapper.queryPlanLineOptions(planId);
  260 + }
  261 +
  262 + @Override
  263 + public GetProcurementMaterialSettleDetailBo findDetail(String id) {
  264 + if (StringUtil.isBlank(id)) {
  265 + throw new InputErrorException("ID不能为空!");
  266 + }
  267 +
  268 + ProcurementMaterialSettleDetail entity = this.getById(id);
  269 + if (entity == null) {
  270 + throw new DefaultClientException("原料结算详情单不存在!");
  271 + }
  272 + fillOperateFlags(Collections.singletonList(entity));
  273 +
  274 + GetProcurementMaterialSettleDetailBo bo = new GetProcurementMaterialSettleDetailBo(entity);
  275 + bo.setApplyLines(new ArrayList<>());
  276 + bo.setLines(new ArrayList<>());
  277 + List<ProcurementMaterialSettleApplyLine> applyLines = applyLineService.getBySettleDetailId(id);
  278 + if (CollectionUtil.isNotEmpty(applyLines)) {
  279 + for (ProcurementMaterialSettleApplyLine applyLine : applyLines) {
  280 + bo.getApplyLines().add(BeanUtil.copyProperties(applyLine,
  281 + GetProcurementMaterialSettleDetailBo.ApplyLineBo.class));
  282 + }
  283 + }
  284 + List<ProcurementMaterialSettleLine> lines = settleLineService.getBySettleDetailId(id);
  285 + if (CollectionUtil.isNotEmpty(lines)) {
  286 + for (ProcurementMaterialSettleLine line : lines) {
  287 + bo.getLines().add(BeanUtil.copyProperties(line,
  288 + GetProcurementMaterialSettleDetailBo.LineBo.class));
  289 + }
  290 + }
  291 +
  292 + return bo;
  293 + }
  294 +
  295 + @Override
  296 + @Transactional(rollbackFor = Exception.class)
  297 + @OpLog(type = OtherOpLogType.class, name = "新增原料结算详情单,ID:{}", params = {"#result"})
  298 + public String create(CreateProcurementMaterialSettleDetailVo vo) {
  299 + ProcurementMaterialSettleDetail entity = new ProcurementMaterialSettleDetail();
  300 + entity.setId(IdUtil.getId());
  301 + applyFields(entity, vo);
  302 +
  303 + entity.setApprovalStatus(STATUS_DRAFT);
  304 + // 制单阶段当前节点为仓库统计员
  305 + entity.setFlowNode(NODE_CKTJY);
  306 +
  307 + this.save(entity);
  308 + saveApplyLines(entity.getId(), vo.getApplyLines());
  309 + saveLines(entity.getId(), vo.getLines());
  310 +
  311 + OpLogUtil.setVariable("id", entity.getId());
  312 + OpLogUtil.setExtra(entity);
  313 +
  314 + return entity.getId();
  315 + }
  316 +
  317 + @Override
  318 + @Transactional(rollbackFor = Exception.class)
  319 + @OpLog(type = OtherOpLogType.class, name = "修改原料结算详情单,ID:{}", params = {"#vo.id"})
  320 + public void update(UpdateProcurementMaterialSettleDetailVo vo) {
  321 + Assert.notBlank(vo.getId(), "ID不能为空!");
  322 +
  323 + ProcurementMaterialSettleDetail oldEntity = this.getById(vo.getId());
  324 + if (oldEntity == null) {
  325 + throw new DefaultClientException("原料结算详情单不存在!");
  326 + }
  327 + // 仅草稿、已驳回可修改;审核中、审核通过、已取消不可修改
  328 + assertEditable(oldEntity);
  329 +
  330 + ProcurementMaterialSettleDetail entity = new ProcurementMaterialSettleDetail();
  331 + entity.setId(vo.getId());
  332 + applyFields(entity, vo);
  333 +
  334 + this.updateById(entity);
  335 +
  336 + // 两张子表整体重建
  337 + applyLineService.deleteBySettleDetailId(vo.getId());
  338 + saveApplyLines(vo.getId(), vo.getApplyLines());
  339 + settleLineService.deleteBySettleDetailId(vo.getId());
  340 + saveLines(vo.getId(), vo.getLines());
  341 +
  342 + OpLogUtil.setVariable("id", entity.getId());
  343 + OpLogUtil.setExtra(entity);
  344 + }
  345 +
  346 + @Override
  347 + @Transactional(rollbackFor = Exception.class)
  348 + @OpLog(type = OtherOpLogType.class, name = "提交原料结算详情单审核,ID:{}", params = {"#id"})
  349 + public void submit(String id) {
  350 + Assert.notBlank(id);
  351 +
  352 + ProcurementMaterialSettleDetail entity = this.getById(id);
  353 + if (entity == null) {
  354 + throw new DefaultClientException("原料结算详情单不存在!");
  355 + }
  356 + if (!STATUS_DRAFT.equals(entity.getApprovalStatus())
  357 + && !STATUS_REFUSE.equals(entity.getApprovalStatus())) {
  358 + throw new DefaultClientException("当前单据状态不允许提交审核!");
  359 + }
  360 +
  361 + // 详情明细不能为空
  362 + List<ProcurementMaterialSettleLine> lines = settleLineService.getBySettleDetailId(id);
  363 + if (CollectionUtil.isEmpty(lines)) {
  364 + throw new DefaultClientException("详情明细不能为空!");
  365 + }
  366 +
  367 + // 提交审核校验:过磅合计数不等于 折斤合计数+退料合计数+入库净重合计数 时无法提交
  368 + BigDecimal weighTotal = BigDecimal.ZERO;
  369 + BigDecimal foldTotal = BigDecimal.ZERO;
  370 + BigDecimal returnTotal = BigDecimal.ZERO;
  371 + BigDecimal netTotal = BigDecimal.ZERO;
  372 + for (ProcurementMaterialSettleLine line : lines) {
  373 + weighTotal = weighTotal.add(nvl(line.getWeighQuantity()));
  374 + foldTotal = foldTotal.add(nvl(line.getFoldWeight()));
  375 + returnTotal = returnTotal.add(nvl(line.getReturnWeight()));
  376 + netTotal = netTotal.add(nvl(line.getNetWeight()));
  377 + }
  378 + BigDecimal checkTotal = foldTotal.add(returnTotal).add(netTotal);
  379 + if (weighTotal.compareTo(checkTotal) != 0) {
  380 + throw new DefaultClientException("合计数量不相等(过磅合计 " + weighTotal.stripTrailingZeros().toPlainString()
  381 + + " ≠ 折斤合计 " + foldTotal.stripTrailingZeros().toPlainString()
  382 + + " + 退料合计 " + returnTotal.stripTrailingZeros().toPlainString()
  383 + + " + 入库净重合计 " + netTotal.stripTrailingZeros().toPlainString() + "),无法提交审核!");
  384 + }
  385 +
  386 + this.update(Wrappers.lambdaUpdate(ProcurementMaterialSettleDetail.class)
  387 + .set(ProcurementMaterialSettleDetail::getApprovalStatus, STATUS_AUDIT)
  388 + // 提交审核后流程节点推进到仓库质检
  389 + .set(ProcurementMaterialSettleDetail::getFlowNode, NODE_CKZJY)
  390 + .eq(ProcurementMaterialSettleDetail::getId, id));
  391 +
  392 + flowInstanceWrapperService.startInstance(BPM_FLAG, entity.getId(), BPM_FLAG, entity);
  393 +
  394 + OpLogUtil.setVariable("id", id);
  395 + OpLogUtil.setExtra(entity);
  396 + }
  397 +
  398 + @Override
  399 + @Transactional(rollbackFor = Exception.class)
  400 + @OpLog(type = OtherOpLogType.class, name = "退回原料结算详情单至草稿,ID:{}", params = {"#id"})
  401 + public void returnDraft(String id) {
  402 + Assert.notBlank(id);
  403 +
  404 + ProcurementMaterialSettleDetail entity = this.getById(id);
  405 + if (entity == null) {
  406 + throw new DefaultClientException("原料结算详情单不存在!");
  407 + }
  408 + // 仓库主管审批通过后可退回
  409 + if (!STATUS_PASS.equals(entity.getApprovalStatus())) {
  410 + throw new DefaultClientException("仅审核通过的原料结算详情单可退回!");
  411 + }
  412 + // 已生成仓库收料单或买断入库核算单的不可以退回(两个模块尚未上线,上线后补充校验)
  413 + assertNotReferenced(id);
  414 +
  415 + this.update(Wrappers.lambdaUpdate(ProcurementMaterialSettleDetail.class)
  416 + .set(ProcurementMaterialSettleDetail::getApprovalStatus, STATUS_DRAFT)
  417 + .set(ProcurementMaterialSettleDetail::getFlowNode, NODE_CKTJY)
  418 + .eq(ProcurementMaterialSettleDetail::getId, id));
  419 +
  420 + OpLogUtil.setVariable("id", id);
  421 + OpLogUtil.setExtra(entity);
  422 + }
  423 +
  424 + @Override
  425 + @Transactional(rollbackFor = Exception.class)
  426 + @OpLog(type = OtherOpLogType.class, name = "取消原料结算详情单,ID:{}", params = {"#id"})
  427 + public void cancel(String id) {
  428 + Assert.notBlank(id);
  429 +
  430 + ProcurementMaterialSettleDetail entity = this.getById(id);
  431 + if (entity == null) {
  432 + throw new DefaultClientException("原料结算详情单不存在!");
  433 + }
  434 + // 草稿、已驳回状态可取消
  435 + if (!STATUS_DRAFT.equals(entity.getApprovalStatus())
  436 + && !STATUS_REFUSE.equals(entity.getApprovalStatus())) {
  437 + throw new DefaultClientException("仅草稿、已驳回状态的原料结算详情单可取消!");
  438 + }
  439 +
  440 + this.update(Wrappers.lambdaUpdate(ProcurementMaterialSettleDetail.class)
  441 + .set(ProcurementMaterialSettleDetail::getApprovalStatus, STATUS_CANCEL)
  442 + .set(ProcurementMaterialSettleDetail::getFlowNode, null)
  443 + .eq(ProcurementMaterialSettleDetail::getId, id));
  444 +
  445 + OpLogUtil.setVariable("id", id);
  446 + OpLogUtil.setExtra(entity);
  447 + }
  448 +
  449 + @Override
  450 + @Transactional(rollbackFor = Exception.class)
  451 + public void updateNoFlowInstance(Map<String, Object> map) {
  452 + try {
  453 + // 审核状态
  454 + Object examStatusObj = map.get("examStatus");
  455 + String examStatus = examStatusObj == null ? null : String.valueOf(examStatusObj);
  456 +
  457 + // 刚审核完成的环节编码(material_settle_ + 分厂前缀 + 名称缩写)
  458 + Object nodeObj = map.get("nodeCode");
  459 + String nodeCode = nodeObj == null ? null : String.valueOf(nodeObj);
  460 +
  461 + // 业务ID(兼容 variables 子 map 包裹)
  462 + String bizId = resolveBizId(map);
  463 + if (StringUtil.isBlank(bizId)) {
  464 + throw new DefaultClientException("原料结算详情单审核回调缺少业务ID!");
  465 + }
  466 +
  467 + // 拒绝/撤销/终止:统一回到仓库质检节点
  468 + if (StringUtil.isNotBlank(examStatus) && !"PASS".equals(examStatus)) {
  469 + this.update(Wrappers.lambdaUpdate(ProcurementMaterialSettleDetail.class)
  470 + .set(ProcurementMaterialSettleDetail::getFlowNode, NODE_CKZJY)
  471 + .eq(ProcurementMaterialSettleDetail::getId, bizId));
  472 + return;
  473 + }
  474 +
  475 + // 审核通过:按刚审核完成的环节编码推进到下一节点
  476 + String nextNode = nextFlowNode(nodeCode);
  477 + if (nextNode == null) {
  478 + // 仓库主管环节通过即流程结束,flow_node 由终态回调一并清空
  479 + return;
  480 + }
  481 +
  482 + this.update(Wrappers.lambdaUpdate(ProcurementMaterialSettleDetail.class)
  483 + .set(ProcurementMaterialSettleDetail::getFlowNode, nextNode)
  484 + .eq(ProcurementMaterialSettleDetail::getId, bizId));
  485 + } catch (Exception ex) {
  486 + ex.printStackTrace();
  487 + }
  488 + }
  489 +
  490 + @Override
  491 + @Transactional(rollbackFor = Exception.class)
  492 + public void updateApprovalStatus(String id, String approvalStatus) {
  493 + if (StringUtil.isBlank(id) || StringUtil.isBlank(approvalStatus)) {
  494 + throw new DefaultClientException("原料结算详情单ID、审核状态不能为空!");
  495 + }
  496 +
  497 + ProcurementMaterialSettleDetail entity = this.getById(id);
  498 + if (entity == null) {
  499 + throw new DefaultClientException("原料结算详情单不存在!");
  500 + }
  501 +
  502 + this.update(Wrappers.lambdaUpdate(ProcurementMaterialSettleDetail.class)
  503 + .set(ProcurementMaterialSettleDetail::getApprovalStatus, approvalStatus)
  504 + .set(ProcurementMaterialSettleDetail::getFlowNode, null)
  505 + .eq(ProcurementMaterialSettleDetail::getId, id));
  506 + }
  507 +
  508 + @Override
  509 + @Transactional(rollbackFor = Exception.class)
  510 + public void deleteByWeighingTicketId(String weighingTicketId) {
  511 + if (StringUtil.isBlank(weighingTicketId)) {
  512 + return;
  513 + }
  514 +
  515 + // 该码单下所有未作废的原料结算详情单,联动作废
  516 + List<ProcurementMaterialSettleDetail> details = this.list(
  517 + Wrappers.lambdaQuery(ProcurementMaterialSettleDetail.class)
  518 + .eq(ProcurementMaterialSettleDetail::getWeighingTicketId, weighingTicketId)
  519 + .eq(ProcurementMaterialSettleDetail::getDeleted, false));
  520 + if (CollectionUtil.isEmpty(details)) {
  521 + return;
  522 + }
  523 +
  524 + for (ProcurementMaterialSettleDetail detail : details) {
  525 + // 审核中的先终止流程,再作废
  526 + if (STATUS_AUDIT.equals(detail.getApprovalStatus())) {
  527 + terminateRunningFlow(detail.getId());
  528 + }
  529 + this.update(Wrappers.lambdaUpdate(ProcurementMaterialSettleDetail.class)
  530 + .set(ProcurementMaterialSettleDetail::getDeleted, true)
  531 + .set(STATUS_AUDIT.equals(detail.getApprovalStatus()),
  532 + ProcurementMaterialSettleDetail::getApprovalStatus, STATUS_REFUSE)
  533 + .eq(ProcurementMaterialSettleDetail::getId, detail.getId()));
  534 + }
  535 + }
  536 +
  537 + // ==================== 私有方法 ====================
  538 +
  539 + /**
  540 + * 组装单据字段(新增/修改共用):校验码单可用后回填冗余字段与前端计算的合计数
  541 + */
  542 + private void applyFields(ProcurementMaterialSettleDetail entity,
  543 + CreateProcurementMaterialSettleDetailVo vo) {
  544 + // 1. 校验码单:必须审核通过、已上传签字凭证,且码单下每个过磅品种的化验报告单全部审核通过
  545 + ProcurementWeighingTicket ticket = assertTicketUsable(vo.getWeighingTicketId());
  546 +
  547 + // 2. 回填字段与冗余信息
  548 + entity.setWeighingTicketId(ticket.getId());
  549 + entity.setWeighingTicketCode(ticket.getCode());
  550 + entity.setTicketDate(ticket.getFirstGrossWeightTime() == null
  551 + ? null : ticket.getFirstGrossWeightTime().toLocalDate());
  552 + entity.setSupplierId(ticket.getSupplierId());
  553 + entity.setSupplierName(ticket.getSupplierName());
  554 + entity.setWorkshopId(ticket.getWorkshopId());
  555 + entity.setWorkshopName(ticket.getWorkshopName());
  556 + entity.setTotalWeighQuantity(vo.getTotalWeighQuantity());
  557 + entity.setTotalFoldWeight(vo.getTotalFoldWeight());
  558 + entity.setTotalReturnWeight(vo.getTotalReturnWeight());
  559 + entity.setTotalNetWeight(vo.getTotalNetWeight());
  560 + entity.setSettleType(vo.getSettleType());
  561 + entity.setRemark(vo.getRemark());
  562 + }
  563 +
  564 + /**
  565 + * 码单可用校验:审核通过、已上传签字凭证(完成时间不为空),且码单下每个过磅品种的化验报告单全部审核通过(流程结束)
  566 + */
  567 + private ProcurementWeighingTicket assertTicketUsable(String ticketId) {
  568 + if (StringUtil.isBlank(ticketId)) {
  569 + throw new DefaultClientException("过磅码单不能为空!");
  570 + }
  571 + ProcurementWeighingTicket ticket = weighingTicketMapper.findById(ticketId);
  572 + if (ticket == null) {
  573 + throw new DefaultClientException("过磅码单不存在!");
  574 + }
  575 + if (!STATUS_PASS.equals(ticket.getApprovalStatus())) {
  576 + throw new DefaultClientException("过磅码单必须为审核通过状态,才能制单!");
  577 + }
  578 + if (ticket.getCompleteTime() == null) {
  579 + throw new DefaultClientException("过磅码单未上传签字凭证,不能制单!");
  580 + }
  581 + assertProductsAssayPassed(ticketId);
  582 + return ticket;
  583 + }
  584 +
  585 + /**
  586 + * 校验码单下每个过磅品种对应的原料化验报告单必须都是流程结束(审核通过)的
  587 + */
  588 + private void assertProductsAssayPassed(String ticketId) {
  589 + // 码单下的过磅品种
  590 + Set<String> productIds = weighLineService.getByWeighingTicketId(ticketId).stream()
  591 + .filter(w -> w != null && StringUtil.isNotBlank(w.getProductId()))
  592 + .map(ProcurementWeighingTicketLine::getProductId)
  593 + .collect(Collectors.toSet());
  594 + if (CollectionUtil.isEmpty(productIds)) {
  595 + return;
  596 + }
  597 + // 已有审核通过化验报告单的品种
  598 + Set<String> assayedProductIds = assayReportMapper.selectList(
  599 + Wrappers.lambdaQuery(ProcurementAssayReport.class)
  600 + .eq(ProcurementAssayReport::getWeighingTicketId, ticketId)
  601 + .eq(ProcurementAssayReport::getApprovalStatus, STATUS_PASS)
  602 + .eq(ProcurementAssayReport::getDeleted, false))
  603 + .stream()
  604 + .filter(r -> r != null && StringUtil.isNotBlank(r.getProductId()))
  605 + .map(ProcurementAssayReport::getProductId)
  606 + .collect(Collectors.toSet());
  607 + for (String productId : productIds) {
  608 + if (!assayedProductIds.contains(productId)) {
  609 + throw new DefaultClientException("过磅码单下存在未化验通过的过磅品种,不能制单!");
  610 + }
  611 + }
  612 + }
  613 +
  614 + /**
  615 + * 保存申请净重明细(自动带出过磅码单的申请数量明细)
  616 + */
  617 + private void saveApplyLines(String settleDetailId, List<MaterialSettleApplyLineVo> vos) {
  618 + if (CollectionUtil.isEmpty(vos)) {
  619 + return;
  620 + }
  621 +
  622 + List<ProcurementMaterialSettleApplyLine> lines = new ArrayList<>(vos.size());
  623 + int orderNo = 0;
  624 + for (MaterialSettleApplyLineVo item : vos) {
  625 + if (item == null) {
  626 + continue;
  627 + }
  628 + ProcurementMaterialSettleApplyLine line = BeanUtil.copyProperties(item,
  629 + ProcurementMaterialSettleApplyLine.class);
  630 + line.setId(IdUtil.getId());
  631 + line.setSettleDetailId(settleDetailId);
  632 + line.setOrderNo(++orderNo);
  633 + lines.add(line);
  634 + }
  635 + if (CollectionUtil.isNotEmpty(lines)) {
  636 + applyLineService.saveBatch(lines);
  637 + }
  638 + }
  639 +
  640 + /**
  641 + * 保存详情明细(过磅明细,可新增/删除/插入)
  642 + */
  643 + private void saveLines(String settleDetailId, List<MaterialSettleLineVo> vos) {
  644 + if (CollectionUtil.isEmpty(vos)) {
  645 + throw new DefaultClientException("详情明细不能为空!");
  646 + }
  647 +
  648 + List<ProcurementMaterialSettleLine> lines = new ArrayList<>(vos.size());
  649 + int orderNo = 0;
  650 + for (MaterialSettleLineVo item : vos) {
  651 + if (item == null) {
  652 + continue;
  653 + }
  654 + // 折斤最多两位小数、退料必须为整数
  655 + if (item.getFoldWeight() != null && item.getFoldWeight().stripTrailingZeros().scale() > 2) {
  656 + throw new DefaultClientException("折斤最多两位小数!");
  657 + }
  658 + if (item.getReturnWeight() != null && item.getReturnWeight().stripTrailingZeros().scale() > 0) {
  659 + throw new DefaultClientException("退料必须为整数!");
  660 + }
  661 + ProcurementMaterialSettleLine line = BeanUtil.copyProperties(item,
  662 + ProcurementMaterialSettleLine.class);
  663 + line.setId(IdUtil.getId());
  664 + line.setSettleDetailId(settleDetailId);
  665 + line.setOrderNo(++orderNo);
  666 + lines.add(line);
  667 + }
  668 +
  669 + if (CollectionUtil.isEmpty(lines)) {
  670 + throw new DefaultClientException("详情明细不能为空!");
  671 + }
  672 + settleLineService.saveBatch(lines);
  673 + }
  674 +
  675 + /**
  676 + * 退回校验:已生成仓库收料单或买断入库核算单的不可以退回
  677 + * (仓库收料单、买断入库核算单模块尚未上线,上线后在此补充查询校验)
  678 + */
  679 + private void assertNotReferenced(String settleDetailId) {
  680 + // TODO 仓库收料单、买断入库核算单上线后补充:存在引用则抛出 DefaultClientException("已生成仓库收料单或买断入库核算单,不可以退回!")
  681 + }
  682 +
  683 + /**
  684 + * 编辑校验:仅草稿、已驳回可修改
  685 + */
  686 + private void assertEditable(ProcurementMaterialSettleDetail entity) {
  687 + if (!STATUS_DRAFT.equals(entity.getApprovalStatus())
  688 + && !STATUS_REFUSE.equals(entity.getApprovalStatus())) {
  689 + throw new DefaultClientException("当前单据状态不允许修改!");
  690 + }
  691 + }
  692 +
  693 + /**
  694 + * 按刚审核完成的环节编码(nodeCode 尾部名称缩写,兼容分厂前缀 yfc/efc/sfc/ztfc)推进到下一流程节点;
  695 + * 仓库主管环节通过返回 null(流程结束,flow_node 由终态回调清空)
  696 + */
  697 + private String nextFlowNode(String nodeCode) {
  698 + if (StringUtil.isBlank(nodeCode)) {
  699 + return null;
  700 + }
  701 + if (nodeCode.endsWith("ckzjy")) {
  702 + return NODE_GYGLKZJY;
  703 + }
  704 + if (nodeCode.endsWith("gyglkzjy")) {
  705 + return NODE_CKZG;
  706 + }
  707 + if (nodeCode.endsWith("ckzg")) {
  708 + return null;
  709 + }
  710 + return null;
  711 + }
  712 +
  713 + /**
  714 + * 从回调参数解析业务ID(兼容 variables 子 map 包裹)
  715 + */
  716 + private String resolveBizId(Map<String, Object> map) {
  717 + Object id = map.get("id");
  718 + String bizId = id == null ? null : String.valueOf(id);
  719 + if (StringUtil.isBlank(bizId) || "null".equals(bizId)) {
  720 + Object bizIdObj = map.get("bizId");
  721 + bizId = bizIdObj == null ? null : String.valueOf(bizIdObj);
  722 + }
  723 + if (StringUtil.isBlank(bizId) || "null".equals(bizId)) {
  724 + Object variables = map.get("variables");
  725 + if (variables instanceof Map) {
  726 + Map<?, ?> variablesMap = (Map<?, ?>) variables;
  727 + Object vId = variablesMap.get("id");
  728 + if (vId == null) {
  729 + vId = variablesMap.get("bizId");
  730 + }
  731 + bizId = vId == null ? null : String.valueOf(vId);
  732 + }
  733 + }
  734 + return bizId;
  735 + }
  736 +
  737 + /**
  738 + * 空值转 0
  739 + */
  740 + private BigDecimal nvl(BigDecimal value) {
  741 + return value == null ? BigDecimal.ZERO : value;
  742 + }
  743 +
  744 + /**
  745 + * 终止单据进行中的审核流程(作废审核中的单据前先终止流程)
  746 + */
  747 + private void terminateRunningFlow(String businessId) {
  748 + List<FlowInstanceWrapper> flowList = flowInstanceWrapperService.getFlowByBusinessIdList(
  749 + Collections.singletonList(businessId));
  750 + if (CollectionUtil.isEmpty(flowList)) {
  751 + return;
  752 + }
  753 + flowList.stream()
  754 + .filter(f -> f != null && f.getId() != null)
  755 + .findFirst()
  756 + .ifPresent(flow -> flowTaskWrapperService.termination(flow.getId()));
  757 + }
  758 +
  759 + /**
  760 + * 审核按钮标记:待办驱动(列表 + 详情两条返回路径都要调用)
  761 + */
  762 + private void fillOperateFlags(List<ProcurementMaterialSettleDetail> datas) {
  763 + if (CollectionUtil.isEmpty(datas)) {
  764 + return;
  765 + }
  766 +
  767 + List<String> businessIds = datas.stream()
  768 + .filter(Objects::nonNull)
  769 + .map(ProcurementMaterialSettleDetail::getId)
  770 + .collect(Collectors.toList());
  771 +
  772 + List<FlowInstanceWrapper> flowList = flowInstanceWrapperService.getFlowByBusinessIdList(businessIds);
  773 + Set<String> flowBusinessIdSet = CollectionUtil.isNotEmpty(flowList)
  774 + ? flowList.stream().map(FlowInstanceWrapper::getBusinessId).collect(Collectors.toSet())
  775 + : new HashSet<>();
  776 +
  777 + List<FlowTaskDto> todoFlowTaskList = flowTaskWrapperMapper.queryTodoList(
  778 + new QueryTodoTaskListVo(), SecurityUtil.getCurrentUser().getId());
  779 + Set<String> todoBusinessIdSet = CollectionUtil.isNotEmpty(todoFlowTaskList)
  780 + ? todoFlowTaskList.stream().map(FlowTaskDto::getBusinessId).collect(Collectors.toSet())
  781 + : new HashSet<>();
  782 +
  783 + for (ProcurementMaterialSettleDetail data : datas) {
  784 + if (data == null) {
  785 + continue;
  786 + }
  787 + boolean hasFlow = flowBusinessIdSet.contains(data.getId());
  788 + boolean hasTodo = todoBusinessIdSet.contains(data.getId());
  789 + data.setShowExamine(hasTodo && STATUS_AUDIT.equals(data.getApprovalStatus()));
  790 + data.setShowExamineDetail(hasFlow && StringUtil.isNotBlank(data.getApprovalStatus()));
  791 + }
  792 + }
  793 +}
... ...
  1 +package com.lframework.xingyun.sc.procurement.impl.settle;
  2 +
  3 +import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  4 +import com.lframework.starter.web.core.impl.BaseMpServiceImpl;
  5 +import com.lframework.xingyun.sc.procurement.entity.settle.ProcurementMaterialSettleLine;
  6 +import com.lframework.xingyun.sc.procurement.mappers.settle.ProcurementMaterialSettleLineMapper;
  7 +import com.lframework.xingyun.sc.procurement.service.settle.ProcurementMaterialSettleLineService;
  8 +import java.util.List;
  9 +import org.springframework.stereotype.Service;
  10 +
  11 +/**
  12 + * 原料结算详情单-详情明细
  13 + */
  14 +@Service
  15 +public class ProcurementMaterialSettleLineServiceImpl
  16 + extends BaseMpServiceImpl<ProcurementMaterialSettleLineMapper, ProcurementMaterialSettleLine>
  17 + implements ProcurementMaterialSettleLineService {
  18 +
  19 + @Override
  20 + public List<ProcurementMaterialSettleLine> getBySettleDetailId(String settleDetailId) {
  21 + // 联表带出品种名称,类别/开票品名查本表
  22 + return getBaseMapper().getBySettleDetailId(settleDetailId);
  23 + }
  24 +
  25 + @Override
  26 + public void deleteBySettleDetailId(String settleDetailId) {
  27 + this.remove(Wrappers.lambdaQuery(ProcurementMaterialSettleLine.class)
  28 + .eq(ProcurementMaterialSettleLine::getSettleDetailId, settleDetailId));
  29 + }
  30 +}
... ...
... ... @@ -23,6 +23,8 @@ import com.lframework.starter.web.core.utils.OpLogUtil;
23 23 import com.lframework.starter.web.core.utils.PageHelperUtil;
24 24 import com.lframework.starter.web.core.utils.PageResultUtil;
25 25 import com.lframework.starter.web.inner.components.oplog.OtherOpLogType;
  26 +import com.lframework.xingyun.basedata.entity.Workshop;
  27 +import com.lframework.xingyun.basedata.service.workshop.WorkshopService;
26 28 import com.lframework.xingyun.sc.bo.procurement.GetAssayReportApplyOptionBo;
27 29 import com.lframework.xingyun.sc.bo.procurement.GetAssayReportPlanOptionBo;
28 30 import com.lframework.xingyun.sc.bo.procurement.GetAssayReportProductOptionBo;
... ... @@ -126,6 +128,9 @@ public class ProcurementAssayReportServiceImpl
126 128 private ProcurementWeighingTicketLineService weighLineService;
127 129
128 130 @Resource
  131 + private WorkshopService workshopService;
  132 +
  133 + @Resource
129 134 private FlowInstanceWrapperService flowInstanceWrapperService;
130 135
131 136 @Resource
... ... @@ -164,6 +169,11 @@ public class ProcurementAssayReportServiceImpl
164 169 if (entity == null) {
165 170 throw new DefaultClientException("原料化验报告单不存在!");
166 171 }
  172 + // 分厂编号(非落库字段,按分厂ID带出)
  173 + if (StringUtil.isNotBlank(entity.getWorkshopId())) {
  174 + Workshop workshop = workshopService.findById(entity.getWorkshopId());
  175 + entity.setWorkshopCode(workshop == null ? null : workshop.getCode());
  176 + }
167 177 fillOperateFlags(Collections.singletonList(entity));
168 178
169 179 GetProcurementAssayReportBo bo = new GetProcurementAssayReportBo(entity);
... ... @@ -208,7 +218,7 @@ public class ProcurementAssayReportServiceImpl
208 218 }
209 219 assertTicketUsable(ticketId);
210 220
211   - // 所选计划下的过磅品种,已生成原料化验报告单的品种不查出(同一品种多条过磅明细时取第一条的数据)
  221 + // 所选计划下的过磅品种,已生成未取消的原料化验报告单品种不查出(同一品种多条过磅明细时取第一条的数据)
212 222 List<GetAssayReportProductOptionBo> datas =
213 223 assayReportMapper.queryAssayedProducts(ticketId, planId);
214 224 Set<String> productIdSet = new HashSet<>();
... ... @@ -321,7 +331,7 @@ public class ProcurementAssayReportServiceImpl
321 331 public void submit(String id) {
322 332 Assert.notBlank(id);
323 333
324   - ProcurementAssayReport entity = this.getById(id);
  334 + GetProcurementAssayReportBo entity = findDetail(id);
325 335 if (entity == null) {
326 336 throw new DefaultClientException("原料化验报告单不存在!");
327 337 }
... ... @@ -659,7 +669,7 @@ public class ProcurementAssayReportServiceImpl
659 669 }
660 670
661 671 /**
662   - * 品种占用校验:同一码单同一品种只要生成过报告单(无论状态,含已取消)就不能重复生成
  672 + * 品种占用校验:同一码单同一品种已生成未取消的报告单不能重复生成(已取消的可重新生成)
663 673 */
664 674 private void assertProductNotOccupied(String weighingTicketId, String productId,
665 675 String excludeReportId) {
... ... @@ -667,6 +677,7 @@ public class ProcurementAssayReportServiceImpl
667 677 .eq(ProcurementAssayReport::getWeighingTicketId, weighingTicketId)
668 678 .eq(ProcurementAssayReport::getProductId, productId)
669 679 .eq(ProcurementAssayReport::getDeleted, false)
  680 + .ne(ProcurementAssayReport::getApprovalStatus, STATUS_CANCEL)
670 681 .ne(excludeReportId != null, ProcurementAssayReport::getId, excludeReportId));
671 682 if (count > 0) {
672 683 throw new DefaultClientException("所选过磅品种已生成过原料化验报告单,不能重复生成!");
... ...
... ... @@ -18,6 +18,14 @@ public class ProcurementWeighingTicketApplyLineServiceImpl
18 18 }
19 19
20 20 @Override
  21 + public List<ProcurementWeighingTicketApplyLine> getByWeighingTicketIds(java.util.List<String> weighingTicketIds) {
  22 + if (weighingTicketIds == null || weighingTicketIds.isEmpty()) {
  23 + return new java.util.ArrayList<>();
  24 + }
  25 + return getBaseMapper().getByWeighingTicketIds(weighingTicketIds);
  26 + }
  27 +
  28 + @Override
21 29 public void deleteByWeighingTicketId(String weighingTicketId) {
22 30 getBaseMapper().deleteByWeighingTicketId(weighingTicketId);
23 31 }
... ...
... ... @@ -18,6 +18,14 @@ public class ProcurementWeighingTicketLineServiceImpl
18 18 }
19 19
20 20 @Override
  21 + public List<ProcurementWeighingTicketLine> getByWeighingTicketIds(java.util.List<String> weighingTicketIds) {
  22 + if (weighingTicketIds == null || weighingTicketIds.isEmpty()) {
  23 + return new java.util.ArrayList<>();
  24 + }
  25 + return getBaseMapper().getByWeighingTicketIds(weighingTicketIds);
  26 + }
  27 +
  28 + @Override
21 29 public void deleteByWeighingTicketId(String weighingTicketId) {
22 30 getBaseMapper().deleteByWeighingTicketId(weighingTicketId);
23 31 }
... ...
... ... @@ -38,6 +38,7 @@ import com.lframework.xingyun.sc.procurement.entity.weighing.ProcurementWeighing
38 38 import com.lframework.xingyun.sc.procurement.mappers.weighing.ProcurementWeighingTicketMapper;
39 39 import com.lframework.xingyun.sc.procurement.service.plan.ProcurementPlanLineService;
40 40 import com.lframework.xingyun.sc.procurement.service.plan.ProcurementPlanService;
  41 +import com.lframework.xingyun.sc.procurement.service.settle.ProcurementMaterialSettleDetailService;
41 42 import com.lframework.xingyun.sc.procurement.service.weighing.ProcurementAssayApplyService;
42 43 import com.lframework.xingyun.sc.procurement.service.weighing.ProcurementAssayReportService;
43 44 import com.lframework.xingyun.sc.procurement.service.weighing.ProcurementWeighingTicketApplyLineService;
... ... @@ -117,6 +118,8 @@ public class ProcurementWeighingTicketServiceImpl
117 118 private ProcurementAssayApplyService assayApplyService;
118 119 @Resource
119 120 private ProcurementAssayReportService assayReportService;
  121 + @Resource
  122 + private ProcurementMaterialSettleDetailService materialSettleDetailService;
120 123
121 124 @Override
122 125 public PageResult<ProcurementWeighingTicket> query(Integer pageIndex, Integer pageSize,
... ... @@ -564,6 +567,9 @@ public class ProcurementWeighingTicketServiceImpl
564 567 // 联动作废该码单关联的原料化验报告单(审核中的先终止流程再作废)
565 568 assayReportService.deleteByWeighingTicketId(id);
566 569
  570 + // 联动作废该码单关联的原料结算详情单(审核中的先终止流程再作废)
  571 + materialSettleDetailService.deleteByWeighingTicketId(id);
  572 +
567 573 OpLogUtil.setVariable("id", id);
568 574 OpLogUtil.setExtra(entity);
569 575 }
... ...
  1 +package com.lframework.xingyun.sc.procurement.mappers.settle;
  2 +
  3 +import com.lframework.starter.web.core.mapper.BaseMapper;
  4 +import com.lframework.xingyun.sc.procurement.entity.settle.ProcurementMaterialSettleApplyLine;
  5 +
  6 +public interface ProcurementMaterialSettleApplyLineMapper
  7 + extends BaseMapper<ProcurementMaterialSettleApplyLine> {
  8 +
  9 +}
... ...
  1 +package com.lframework.xingyun.sc.procurement.mappers.settle;
  2 +
  3 +import com.lframework.starter.web.core.annotations.permission.DataPermission;
  4 +import com.lframework.starter.web.core.annotations.permission.DataPermissions;
  5 +import com.lframework.starter.web.core.mapper.BaseMapper;
  6 +import com.lframework.starter.web.inner.components.permission.OrderDataPermissionDataPermissionType;
  7 +import com.lframework.xingyun.sc.bo.procurement.GetMaterialSettlePlanLineOptionBo;
  8 +import com.lframework.xingyun.sc.bo.procurement.GetMaterialSettlePlanOptionBo;
  9 +import com.lframework.xingyun.sc.bo.procurement.GetMaterialSettleSelectableTicketBo;
  10 +import com.lframework.xingyun.sc.procurement.entity.settle.ProcurementMaterialSettleDetail;
  11 +import com.lframework.xingyun.sc.procurement.vo.settle.QueryMaterialSettleSelectableTicketVo;
  12 +import com.lframework.xingyun.sc.procurement.vo.settle.QueryProcurementMaterialSettleDetailVo;
  13 +
  14 +import java.util.List;
  15 +
  16 +import org.apache.ibatis.annotations.Param;
  17 +
  18 +public interface ProcurementMaterialSettleDetailMapper
  19 + extends BaseMapper<ProcurementMaterialSettleDetail> {
  20 +
  21 + @DataPermissions(type = OrderDataPermissionDataPermissionType.class, value = {
  22 + @DataPermission(template = "order", alias = "tb")
  23 + })
  24 + List<ProcurementMaterialSettleDetail> query(
  25 + @Param("vo") QueryProcurementMaterialSettleDetailVo vo);
  26 +
  27 + /**
  28 + * 分页查询可制单的过磅码单(审核通过 + 已上传签字凭证 + 码单下每个过磅品种都要有原料化验报告单且全部审核通过,选择码单弹窗)
  29 + */
  30 + @DataPermissions(type = OrderDataPermissionDataPermissionType.class, value = {
  31 + @DataPermission(template = "order", alias = "tb")
  32 + })
  33 + List<GetMaterialSettleSelectableTicketBo> querySelectableTickets(
  34 + @Param("vo") QueryMaterialSettleSelectableTicketVo vo);
  35 +
  36 + /**
  37 + * 所选码单下的计划编号行(按行序,同一计划多行时由 Service 去重)
  38 + */
  39 + List<GetMaterialSettlePlanOptionBo> queryTicketPlans(@Param("ticketId") String ticketId);
  40 +
  41 + /**
  42 + * 所选计划下的计划明细行(品种ID、品种名称、类别=品种关系表代号、名称=开票品名)
  43 + */
  44 + List<GetMaterialSettlePlanLineOptionBo> queryPlanLineOptions(@Param("planId") String planId);
  45 +}
... ...
  1 +package com.lframework.xingyun.sc.procurement.mappers.settle;
  2 +
  3 +import com.lframework.starter.web.core.mapper.BaseMapper;
  4 +import com.lframework.xingyun.sc.procurement.entity.settle.ProcurementMaterialSettleLine;
  5 +import java.util.List;
  6 +import org.apache.ibatis.annotations.Param;
  7 +
  8 +public interface ProcurementMaterialSettleLineMapper
  9 + extends BaseMapper<ProcurementMaterialSettleLine> {
  10 +
  11 + /**
  12 + * 按原料结算详情单ID查询详情明细(联表带出品种名称,类别/开票品名查本表)
  13 + */
  14 + List<ProcurementMaterialSettleLine> getBySettleDetailId(@Param("settleDetailId") String settleDetailId);
  15 +}
... ...
... ... @@ -9,6 +9,8 @@ public interface ProcurementWeighingTicketApplyLineMapper extends BaseMapper<Pro
9 9
10 10 List<ProcurementWeighingTicketApplyLine> getByWeighingTicketId(@Param("weighingTicketId") String weighingTicketId);
11 11
  12 + List<ProcurementWeighingTicketApplyLine> getByWeighingTicketIds(@Param("weighingTicketIds") List<String> weighingTicketIds);
  13 +
12 14 void deleteByWeighingTicketId(@Param("weighingTicketId") String weighingTicketId);
13 15
14 16 }
... ...
... ... @@ -9,6 +9,8 @@ public interface ProcurementWeighingTicketLineMapper extends BaseMapper<Procurem
9 9
10 10 List<ProcurementWeighingTicketLine> getByWeighingTicketId(@Param("weighingTicketId") String weighingTicketId);
11 11
  12 + List<ProcurementWeighingTicketLine> getByWeighingTicketIds(@Param("weighingTicketIds") List<String> weighingTicketIds);
  13 +
12 14 void deleteByWeighingTicketId(@Param("weighingTicketId") String weighingTicketId);
13 15
14 16 }
... ...
  1 +package com.lframework.xingyun.sc.procurement.service.settle;
  2 +
  3 +import com.lframework.starter.web.core.service.BaseMpService;
  4 +import com.lframework.xingyun.sc.procurement.entity.settle.ProcurementMaterialSettleApplyLine;
  5 +import java.util.List;
  6 +
  7 +/**
  8 + * 原料结算详情单-申请净重明细
  9 + */
  10 +public interface ProcurementMaterialSettleApplyLineService
  11 + extends BaseMpService<ProcurementMaterialSettleApplyLine> {
  12 +
  13 + /**
  14 + * 按结算详情单ID查询明细(排序号升序)
  15 + */
  16 + List<ProcurementMaterialSettleApplyLine> getBySettleDetailId(String settleDetailId);
  17 +
  18 + /**
  19 + * 按结算详情单ID删除明细(修改重建用)
  20 + */
  21 + void deleteBySettleDetailId(String settleDetailId);
  22 +}
... ...
  1 +package com.lframework.xingyun.sc.procurement.service.settle;
  2 +
  3 +import com.lframework.starter.web.core.components.resp.PageResult;
  4 +import com.lframework.starter.web.core.service.BaseMpService;
  5 +import com.lframework.xingyun.sc.bo.procurement.GetMaterialSettlePlanLineOptionBo;
  6 +import com.lframework.xingyun.sc.bo.procurement.GetMaterialSettlePlanOptionBo;
  7 +import com.lframework.xingyun.sc.bo.procurement.GetMaterialSettleSelectableTicketBo;
  8 +import com.lframework.xingyun.sc.bo.procurement.GetProcurementMaterialSettleDetailBo;
  9 +import com.lframework.xingyun.sc.procurement.entity.settle.ProcurementMaterialSettleDetail;
  10 +import com.lframework.xingyun.sc.procurement.vo.settle.CreateProcurementMaterialSettleDetailVo;
  11 +import com.lframework.xingyun.sc.procurement.vo.settle.QueryMaterialSettleSelectableTicketVo;
  12 +import com.lframework.xingyun.sc.procurement.vo.settle.QueryProcurementMaterialSettleDetailVo;
  13 +import com.lframework.xingyun.sc.procurement.vo.settle.UpdateProcurementMaterialSettleDetailVo;
  14 +
  15 +import java.util.List;
  16 +
  17 +public interface ProcurementMaterialSettleDetailService
  18 + extends BaseMpService<ProcurementMaterialSettleDetail> {
  19 +
  20 + /**
  21 + * 分页查询(列表)
  22 + */
  23 + PageResult<ProcurementMaterialSettleDetail> query(Integer pageIndex, Integer pageSize,
  24 + QueryProcurementMaterialSettleDetailVo vo);
  25 +
  26 + /**
  27 + * 分页查询可制单的过磅码单(审核通过 + 已上传签字凭证 + 码单下每个过磅品种都要有原料化验报告单且全部审核通过,选择码单弹窗)
  28 + */
  29 + PageResult<GetMaterialSettleSelectableTicketBo> querySelectableTickets(Integer pageIndex,
  30 + Integer pageSize, QueryMaterialSettleSelectableTicketVo vo);
  31 +
  32 + /**
  33 + * 所选码单下的计划编号下拉(只返回码单计划的补单,补单计划已生成即流程已完成;
  34 + * 码单中已直接关联补单(编号带"补")的主计划不再返回其补单)
  35 + */
  36 + List<GetMaterialSettlePlanOptionBo> getPlanOptions(String ticketId);
  37 +
  38 + /**
  39 + * 所选计划下的计划明细下拉(选择计划后选择明细,返回品种ID、品种名称、类别=品种关系表代号、名称=开票品名)
  40 + */
  41 + List<GetMaterialSettlePlanLineOptionBo> getPlanLineOptions(String planId);
  42 +
  43 + /**
  44 + * 详情(主表 + 申请净重明细 + 详情明细)
  45 + */
  46 + GetProcurementMaterialSettleDetailBo findDetail(String id);
  47 +
  48 + /**
  49 + * 新增(草稿,分厂仓库统计员)
  50 + */
  51 + String create(CreateProcurementMaterialSettleDetailVo vo);
  52 +
  53 + /**
  54 + * 修改(仅草稿、已驳回可修改)
  55 + */
  56 + void update(UpdateProcurementMaterialSettleDetailVo vo);
  57 +
  58 + /**
  59 + * 提交审核(过磅合计数不等于折斤+退料+入库净重合计数时无法提交)
  60 + */
  61 + void submit(String id);
  62 +
  63 + /**
  64 + * 退回草稿(仓库主管审批通过后可退回,仓库统计员重新发起;已生成仓库收料单和买断入库核算单的不可以退回)
  65 + */
  66 + void returnDraft(String id);
  67 +
  68 + /**
  69 + * 取消(草稿、已驳回状态可取消)
  70 + */
  71 + void cancel(String id);
  72 +
  73 + /**
  74 + * 审核流程回调更新审核状态(流程结束时由 BusinessDataHandlerService 调用)
  75 + *
  76 + * @param id 原料结算详情单ID
  77 + * @param approvalStatus 审核结果 PASS/REFUSE
  78 + */
  79 + void updateApprovalStatus(String id, String approvalStatus);
  80 +
  81 + /**
  82 + * 审核过程回调:更新流程节点
  83 + * 审核节点编码:material_settle_ + 分厂前缀(有分厂时 yfc/efc/sfc/ztfc) + 名称缩写,
  84 + * 如 material_settle_yfcckzjy、material_settle_yfcgyglkzjy、material_settle_yfcckzg
  85 + *
  86 + * @param map 回调参数 nodeCode/examStatus/id(bizId),兼容 variables 子 map 包裹
  87 + */
  88 + void updateNoFlowInstance(java.util.Map<String, Object> map);
  89 +
  90 + /**
  91 + * 按过磅码单作废原料结算详情单(码单作废联动,审核中的先终止流程)
  92 + *
  93 + * @param weighingTicketId 过磅码单ID
  94 + */
  95 + void deleteByWeighingTicketId(String weighingTicketId);
  96 +}
... ...
  1 +package com.lframework.xingyun.sc.procurement.service.settle;
  2 +
  3 +import com.lframework.starter.web.core.service.BaseMpService;
  4 +import com.lframework.xingyun.sc.procurement.entity.settle.ProcurementMaterialSettleLine;
  5 +import java.util.List;
  6 +
  7 +/**
  8 + * 原料结算详情单-详情明细
  9 + */
  10 +public interface ProcurementMaterialSettleLineService
  11 + extends BaseMpService<ProcurementMaterialSettleLine> {
  12 +
  13 + /**
  14 + * 按结算详情单ID查询明细(排序号升序)
  15 + */
  16 + List<ProcurementMaterialSettleLine> getBySettleDetailId(String settleDetailId);
  17 +
  18 + /**
  19 + * 按结算详情单ID删除明细(修改重建用)
  20 + */
  21 + void deleteBySettleDetailId(String settleDetailId);
  22 +}
... ...
... ... @@ -44,7 +44,7 @@ public interface ProcurementAssayReportService extends BaseMpService<Procurement
44 44 List<GetAssayReportPlanOptionBo> getPlanOptions(String ticketId);
45 45
46 46 /**
47   - * 新增页级联第三步:所选计划下的过磅品种下拉(已生成原料化验报告单的品种不查出,含过磅数量)
  47 + * 新增页级联第三步:所选计划下的过磅品种下拉(已生成未取消的原料化验报告单品种不查出,含过磅数量)
48 48 */
49 49 List<GetAssayReportProductOptionBo> getAssayedProducts(String ticketId, String planId);
50 50
... ...
... ... @@ -8,5 +8,10 @@ public interface ProcurementWeighingTicketApplyLineService extends BaseMpService
8 8
9 9 List<ProcurementWeighingTicketApplyLine> getByWeighingTicketId(String weighingTicketId);
10 10
  11 + /**
  12 + * 按过磅码单ID集合批量查询申请数量明细行(按码单ID + 排序号排序)
  13 + */
  14 + List<ProcurementWeighingTicketApplyLine> getByWeighingTicketIds(java.util.List<String> weighingTicketIds);
  15 +
11 16 void deleteByWeighingTicketId(String weighingTicketId);
12 17 }
... ...
... ... @@ -8,5 +8,10 @@ public interface ProcurementWeighingTicketLineService extends BaseMpService<Proc
8 8
9 9 List<ProcurementWeighingTicketLine> getByWeighingTicketId(String weighingTicketId);
10 10
  11 + /**
  12 + * 按过磅码单ID集合批量查询过磅明细行(按码单ID + 排序号排序)
  13 + */
  14 + List<ProcurementWeighingTicketLine> getByWeighingTicketIds(java.util.List<String> weighingTicketIds);
  15 +
11 16 void deleteByWeighingTicketId(String weighingTicketId);
12 17 }
... ...
  1 +package com.lframework.xingyun.sc.procurement.vo.settle;
  2 +
  3 +import io.swagger.annotations.ApiModelProperty;
  4 +import lombok.Data;
  5 +
  6 +import javax.validation.Valid;
  7 +import javax.validation.constraints.NotBlank;
  8 +import java.io.Serializable;
  9 +import java.math.BigDecimal;
  10 +import java.util.List;
  11 +
  12 +@Data
  13 +public class CreateProcurementMaterialSettleDetailVo implements Serializable {
  14 +
  15 + private static final long serialVersionUID = 1L;
  16 +
  17 + @ApiModelProperty("过磅码单ID(必须审核通过且已上传签字凭证,码单下每个过磅品种的化验报告单全部审核通过)")
  18 + @NotBlank(message = "过磅码单不能为空!")
  19 + private String weighingTicketId;
  20 +
  21 + @ApiModelProperty("类型 经销/双经销/买断")
  22 + private String settleType;
  23 +
  24 + @ApiModelProperty("合计过磅数(前端计算)")
  25 + private BigDecimal totalWeighQuantity;
  26 +
  27 + @ApiModelProperty("合计折斤(前端计算)")
  28 + private BigDecimal totalFoldWeight;
  29 +
  30 + @ApiModelProperty("合计退料(前端计算)")
  31 + private BigDecimal totalReturnWeight;
  32 +
  33 + @ApiModelProperty("合计入库净重(前端计算)")
  34 + private BigDecimal totalNetWeight;
  35 +
  36 + @ApiModelProperty("备注")
  37 + private String remark;
  38 +
  39 + @ApiModelProperty("申请净重明细(自动带出过磅码单的申请数量明细)")
  40 + @Valid
  41 + private List<MaterialSettleApplyLineVo> applyLines;
  42 +
  43 + @ApiModelProperty("详情明细(自动带出过磅码单的过磅明细,可新增/删除/插入)")
  44 + @Valid
  45 + private List<MaterialSettleLineVo> lines;
  46 +}
... ...
  1 +package com.lframework.xingyun.sc.procurement.vo.settle;
  2 +
  3 +import io.swagger.annotations.ApiModelProperty;
  4 +import lombok.Data;
  5 +
  6 +import java.io.Serializable;
  7 +import java.math.BigDecimal;
  8 +
  9 +@Data
  10 +public class MaterialSettleApplyLineVo implements Serializable {
  11 +
  12 + private static final long serialVersionUID = 1L;
  13 +
  14 + @ApiModelProperty("过磅码单申请数量明细ID(来源行主键,数据追溯)")
  15 + private String weighingTicketApplyLineId;
  16 +
  17 + @ApiModelProperty("类别(品种代号)")
  18 + private String category;
  19 +
  20 + @ApiModelProperty("品种关系表ID")
  21 + private String breedRelationshipId;
  22 +
  23 + @ApiModelProperty("数量")
  24 + private BigDecimal quantity;
  25 +
  26 + @ApiModelProperty("前端行标识")
  27 + private String itemId;
  28 +}
... ...
  1 +package com.lframework.xingyun.sc.procurement.vo.settle;
  2 +
  3 +import io.swagger.annotations.ApiModelProperty;
  4 +import lombok.Data;
  5 +
  6 +import java.io.Serializable;
  7 +import java.math.BigDecimal;
  8 +
  9 +@Data
  10 +public class MaterialSettleLineVo implements Serializable {
  11 +
  12 + private static final long serialVersionUID = 1L;
  13 +
  14 + @ApiModelProperty("采购计划ID(计划编号及其补单编号,非必填)")
  15 + private String procurementPlanId;
  16 +
  17 + @ApiModelProperty("计划编号")
  18 + private String planCode;
  19 +
  20 + @ApiModelProperty("品种ID(隐藏,非必填)")
  21 + private String productId;
  22 +
  23 + @ApiModelProperty("类别(品种代号,非必填)")
  24 + private String category;
  25 +
  26 + @ApiModelProperty("名称(开票品名)")
  27 + private String name;
  28 +
  29 + @ApiModelProperty("过磅数(自动带出,插入行不可改)")
  30 + private BigDecimal weighQuantity;
  31 +
  32 + @ApiModelProperty("杂率%")
  33 + private String impurityRate;
  34 +
  35 + @ApiModelProperty("折斤(最多两位小数)")
  36 + private BigDecimal foldWeight;
  37 +
  38 + @ApiModelProperty("退料(整数)")
  39 + private BigDecimal returnWeight;
  40 +
  41 + @ApiModelProperty("入库净重")
  42 + private BigDecimal netWeight;
  43 +
  44 + @ApiModelProperty("备注")
  45 + private String remark;
  46 +
  47 + @ApiModelProperty("前端行标识")
  48 + private String itemId;
  49 +}
... ...
  1 +package com.lframework.xingyun.sc.procurement.vo.settle;
  2 +
  3 +import com.lframework.starter.web.core.vo.SortPageVo;
  4 +import io.swagger.annotations.ApiModel;
  5 +import io.swagger.annotations.ApiModelProperty;
  6 +import lombok.Data;
  7 +
  8 +import java.io.Serializable;
  9 +
  10 +@Data
  11 +@ApiModel("原料结算:选择过磅码单(审核通过且已上传签字凭证且每个过磅品种的化验报告单全部审核通过)")
  12 +public class QueryMaterialSettleSelectableTicketVo extends SortPageVo implements Serializable {
  13 +
  14 + private static final long serialVersionUID = 1L;
  15 +
  16 + @ApiModelProperty("码单编号(模糊匹配)")
  17 + private String code;
  18 +
  19 + @ApiModelProperty("分厂ID(按分厂划分,可选)")
  20 + private String workshopId;
  21 +}
... ...
  1 +package com.lframework.xingyun.sc.procurement.vo.settle;
  2 +
  3 +import com.fasterxml.jackson.annotation.JsonFormat;
  4 +import com.lframework.starter.common.constants.StringPool;
  5 +import com.lframework.starter.web.core.vo.PageVo;
  6 +import com.lframework.starter.web.core.vo.SortPageVo;
  7 +import io.swagger.annotations.ApiModel;
  8 +import io.swagger.annotations.ApiModelProperty;
  9 +import lombok.Data;
  10 +
  11 +import java.io.Serializable;
  12 +import java.time.LocalDate;
  13 +import java.util.List;
  14 +
  15 +@Data
  16 +@ApiModel("查询原料结算详情单")
  17 +public class QueryProcurementMaterialSettleDetailVo extends SortPageVo implements Serializable {
  18 +
  19 + private static final long serialVersionUID = 1L;
  20 +
  21 + @ApiModelProperty("码单编号(模糊匹配)")
  22 + private String weighingTicketCode;
  23 +
  24 + @ApiModelProperty("日期-开始")
  25 + @JsonFormat(pattern = StringPool.DATE_PATTERN)
  26 + private LocalDate ticketDateStart;
  27 +
  28 + @ApiModelProperty("日期-结束")
  29 + @JsonFormat(pattern = StringPool.DATE_PATTERN)
  30 + private LocalDate ticketDateEnd;
  31 +
  32 + @ApiModelProperty("计划编号(模糊匹配)")
  33 + private String planCode;
  34 +
  35 + @ApiModelProperty("分厂ID")
  36 + private String workshopId;
  37 +
  38 + @ApiModelProperty("流程节点 CKTJY/CKZJY/GYGLKZJY/CKZG")
  39 + private String flowNode;
  40 +
  41 + @ApiModelProperty("审核状态 DRAFT/AUDIT/PASS/REFUSE/CANCEL")
  42 + private String approvalStatus;
  43 +
  44 + @ApiModelProperty("创建人ID集合(数据权限用,后端注入)")
  45 + private List<String> createByIdList;
  46 +}
... ...
  1 +package com.lframework.xingyun.sc.procurement.vo.settle;
  2 +
  3 +import io.swagger.annotations.ApiModelProperty;
  4 +import lombok.Data;
  5 +import lombok.EqualsAndHashCode;
  6 +
  7 +import javax.validation.Valid;
  8 +import javax.validation.constraints.NotBlank;
  9 +import java.io.Serializable;
  10 +import java.util.List;
  11 +
  12 +@Data
  13 +@EqualsAndHashCode(callSuper = true)
  14 +public class UpdateProcurementMaterialSettleDetailVo extends
  15 + CreateProcurementMaterialSettleDetailVo implements Serializable {
  16 +
  17 + private static final long serialVersionUID = 1L;
  18 +
  19 + @ApiModelProperty("ID")
  20 + @NotBlank(message = "ID不能为空!")
  21 + private String id;
  22 +}
... ...
... ... @@ -275,7 +275,8 @@
275 275 </when>
276 276 <when test="vo.queryType == 'REPLENISHMENT'">
277 277 AND pp.process_status IN ('COMPLETED', 'ABORTED')
278   - AND pp.plan_type NOT LIKE '%补%'
  278 + <!-- plan_type 未变更过的主计划为 NULL,需兼容 NULL(NULL NOT LIKE 结果为 UNKNOWN 会被误过滤) -->
  279 + AND (pp.plan_type IS NULL OR pp.plan_type NOT LIKE '%补%')
279 280 AND (pp.replenishment_status = '' OR pp.replenishment_status IS NULL OR pp.replenishment_status
280 281 = 'REPLENISHED')
281 282 AND (pp.change_status = '' OR pp.change_status IS NULL OR pp.change_status = 'CHANGED')
... ...
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<!DOCTYPE mapper
  3 + PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4 + "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5 +<mapper namespace="com.lframework.xingyun.sc.procurement.mappers.settle.ProcurementMaterialSettleDetailMapper">
  6 +
  7 + <resultMap id="ProcurementMaterialSettleDetailResult"
  8 + type="com.lframework.xingyun.sc.procurement.entity.settle.ProcurementMaterialSettleDetail">
  9 + <id column="id" property="id"/>
  10 + <result column="weighing_ticket_id" property="weighingTicketId"/>
  11 + <result column="weighing_ticket_code" property="weighingTicketCode"/>
  12 + <result column="ticket_date" property="ticketDate"/>
  13 + <result column="supplier_id" property="supplierId"/>
  14 + <result column="supplier_name" property="supplierName"/>
  15 + <result column="workshop_id" property="workshopId"/>
  16 + <result column="workshop_name" property="workshopName"/>
  17 + <result column="total_weigh_quantity" property="totalWeighQuantity"/>
  18 + <result column="total_fold_weight" property="totalFoldWeight"/>
  19 + <result column="total_return_weight" property="totalReturnWeight"/>
  20 + <result column="total_net_weight" property="totalNetWeight"/>
  21 + <result column="settle_type" property="settleType"/>
  22 + <result column="remark" property="remark"/>
  23 + <result column="flow_node" property="flowNode"/>
  24 + <result column="approval_status" property="approvalStatus"/>
  25 + <result column="plan_codes" property="planCodes"/>
  26 + <result column="plan_ids" property="planIds"/>
  27 + <result column="create_by_id" property="createById"/>
  28 + <result column="create_by" property="createBy"/>
  29 + <result column="update_by_id" property="updateById"/>
  30 + <result column="update_by" property="updateBy"/>
  31 + <result column="create_time" property="createTime"/>
  32 + <result column="update_time" property="updateTime"/>
  33 + </resultMap>
  34 +
  35 + <sql id="PMSD_sql">
  36 + SELECT
  37 + tb.id,
  38 + tb.weighing_ticket_id,
  39 + tb.weighing_ticket_code,
  40 + tb.ticket_date,
  41 + tb.supplier_id,
  42 + tb.supplier_name,
  43 + tb.workshop_id,
  44 + tb.workshop_name,
  45 + tb.total_weigh_quantity,
  46 + tb.total_fold_weight,
  47 + tb.total_return_weight,
  48 + tb.total_net_weight,
  49 + tb.settle_type,
  50 + tb.remark,
  51 + tb.flow_node,
  52 + tb.approval_status,
  53 + <!-- 计划编号/ID集合取自过磅码单关联的计划(不可改,列表/详情展示用) -->
  54 + (
  55 + SELECT GROUP_CONCAT(DISTINCT pwtp.plan_code ORDER BY pwtp.order_no SEPARATOR ',')
  56 + FROM procurement_weighing_ticket_plan pwtp
  57 + WHERE pwtp.weighing_ticket_id = tb.weighing_ticket_id
  58 + ) AS plan_codes,
  59 + (
  60 + SELECT GROUP_CONCAT(DISTINCT pwtpi.procurement_plan_id SEPARATOR ',')
  61 + FROM procurement_weighing_ticket_plan pwtpi
  62 + WHERE pwtpi.weighing_ticket_id = tb.weighing_ticket_id
  63 + ) AS plan_ids,
  64 + tb.create_by_id,
  65 + tb.create_by,
  66 + tb.update_by_id,
  67 + tb.update_by,
  68 + tb.create_time,
  69 + tb.update_time
  70 + FROM procurement_material_settle_detail AS tb
  71 + </sql>
  72 +
  73 + <select id="query" resultMap="ProcurementMaterialSettleDetailResult">
  74 + <include refid="PMSD_sql"/>
  75 + <where>
  76 + tb.deleted = 0
  77 + <if test="vo.weighingTicketCode != null and vo.weighingTicketCode != ''">
  78 + AND tb.weighing_ticket_code LIKE CONCAT('%', #{vo.weighingTicketCode}, '%')
  79 + </if>
  80 + <if test="vo.ticketDateStart != null">
  81 + AND tb.ticket_date &gt;= #{vo.ticketDateStart}
  82 + </if>
  83 + <if test="vo.ticketDateEnd != null">
  84 + AND tb.ticket_date &lt;= #{vo.ticketDateEnd}
  85 + </if>
  86 + <if test="vo.planCode != null and vo.planCode != ''">
  87 + AND EXISTS (
  88 + SELECT 1 FROM procurement_material_settle_line pmsl
  89 + WHERE pmsl.settle_detail_id = tb.id
  90 + AND pmsl.plan_code LIKE CONCAT('%', #{vo.planCode}, '%')
  91 + )
  92 + </if>
  93 + <if test="vo.workshopId != null and vo.workshopId != ''">
  94 + AND tb.workshop_id = #{vo.workshopId}
  95 + </if>
  96 + <if test="vo.flowNode != null and vo.flowNode != ''">
  97 + AND tb.flow_node = #{vo.flowNode}
  98 + </if>
  99 + <if test="vo.approvalStatus != null and vo.approvalStatus != ''">
  100 + AND tb.approval_status = #{vo.approvalStatus}
  101 + </if>
  102 + <if test="vo.createByIdList != null and vo.createByIdList.size() > 0">
  103 + AND tb.create_by_id IN
  104 + <foreach collection="vo.createByIdList" item="item" open="(" separator="," close=")">
  105 + #{item}
  106 + </foreach>
  107 + </if>
  108 + </where>
  109 + ORDER BY tb.create_time DESC
  110 + </select>
  111 +
  112 + <resultMap id="MaterialSettleSelectableTicketResult"
  113 + type="com.lframework.xingyun.sc.bo.procurement.GetMaterialSettleSelectableTicketBo">
  114 + <id column="id" property="id"/>
  115 + <result column="code" property="code"/>
  116 + <result column="supplier_name" property="supplierName"/>
  117 + <result column="workshop_id" property="workshopId"/>
  118 + <result column="workshop_name" property="workshopName"/>
  119 + <result column="complete_time" property="completeTime"/>
  120 + <result column="create_by" property="createBy"/>
  121 + </resultMap>
  122 +
  123 + <!-- 原料结算制单选择码单弹窗:审核通过 + 已上传签字凭证 + 码单下每个过磅品种都要有原料化验报告单且全部审核通过 -->
  124 + <select id="querySelectableTickets" resultMap="MaterialSettleSelectableTicketResult">
  125 + SELECT
  126 + tb.id,
  127 + tb.code,
  128 + tb.supplier_name,
  129 + tb.workshop_id,
  130 + tb.workshop_name,
  131 + tb.complete_time,
  132 + tb.create_by
  133 + FROM procurement_weighing_ticket AS tb
  134 + WHERE tb.deleted = 0
  135 + AND tb.approval_status = 'PASS'
  136 + AND tb.complete_time IS NOT NULL
  137 + <!-- 每个过磅品种都要有原料化验报告单(不存在没有任何有效化验报告单的过磅品种) -->
  138 + AND NOT EXISTS (
  139 + SELECT 1 FROM procurement_weighing_ticket_line pwtl
  140 + WHERE pwtl.weighing_ticket_id = tb.id
  141 + AND pwtl.product_id IS NOT NULL
  142 + AND NOT EXISTS (
  143 + SELECT 1 FROM procurement_assay_report par
  144 + WHERE par.weighing_ticket_id = tb.id
  145 + AND par.product_id = pwtl.product_id
  146 + AND par.deleted = 0
  147 + )
  148 + )
  149 + <!-- 每个过磅品种的化验报告单必须全部流程结束即审核通过 -->
  150 + AND NOT EXISTS (
  151 + SELECT 1 FROM procurement_weighing_ticket_line pwtl
  152 + WHERE pwtl.weighing_ticket_id = tb.id
  153 + AND pwtl.product_id IS NOT NULL
  154 + AND NOT EXISTS (
  155 + SELECT 1 FROM procurement_assay_report par
  156 + WHERE par.weighing_ticket_id = tb.id
  157 + AND par.product_id = pwtl.product_id
  158 + AND par.deleted = 0
  159 + AND par.approval_status = 'PASS'
  160 + )
  161 + )
  162 + <if test="vo.code != null and vo.code != ''">
  163 + AND tb.code LIKE CONCAT('%', #{vo.code}, '%')
  164 + </if>
  165 + <if test="vo.workshopId != null and vo.workshopId != ''">
  166 + AND tb.workshop_id = #{vo.workshopId}
  167 + </if>
  168 + ORDER BY tb.complete_time DESC, tb.create_time DESC
  169 + </select>
  170 +
  171 + <resultMap id="MaterialSettlePlanOptionResult"
  172 + type="com.lframework.xingyun.sc.bo.procurement.GetMaterialSettlePlanOptionBo">
  173 + <id column="plan_id" property="planId"/>
  174 + <result column="plan_code" property="planCode"/>
  175 + </resultMap>
  176 +
  177 + <!-- 所选码单下的计划编号行(按行序,同一计划多行时由 Service 去重) -->
  178 + <select id="queryTicketPlans" resultMap="MaterialSettlePlanOptionResult">
  179 + SELECT
  180 + pwtp.procurement_plan_id AS plan_id,
  181 + pwtp.plan_code AS plan_code
  182 + FROM procurement_weighing_ticket_plan pwtp
  183 + WHERE pwtp.weighing_ticket_id = #{ticketId}
  184 + AND pwtp.procurement_plan_id IS NOT NULL
  185 + ORDER BY pwtp.order_no
  186 + </select>
  187 +
  188 + <resultMap id="MaterialSettlePlanLineOptionResult"
  189 + type="com.lframework.xingyun.sc.bo.procurement.GetMaterialSettlePlanLineOptionBo">
  190 + <id column="plan_line_id" property="planLineId"/>
  191 + <result column="product_id" property="productId"/>
  192 + <result column="product_name" property="productName"/>
  193 + <result column="category" property="category"/>
  194 + <result column="name" property="name"/>
  195 + </resultMap>
  196 +
  197 + <!-- 所选计划下的计划明细行(品种ID=品种关系表ID,类别取品种关系表代号,名称取开票品名) -->
  198 + <select id="queryPlanLineOptions" resultMap="MaterialSettlePlanLineOptionResult">
  199 + SELECT
  200 + ppl.id AS plan_line_id,
  201 + ppl.product_id,
  202 + br.product_name,
  203 + br.code AS category,
  204 + ppl.invoice_product_name AS `name`
  205 + FROM procurement_plan_line ppl
  206 + LEFT JOIN base_data_breed_relationship br ON br.id = ppl.product_id
  207 + WHERE ppl.procurement_plan_id = #{planId}
  208 + ORDER BY ppl.create_time ASC
  209 + </select>
  210 +</mapper>
... ...
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<!DOCTYPE mapper
  3 + PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4 + "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5 +<mapper namespace="com.lframework.xingyun.sc.procurement.mappers.settle.ProcurementMaterialSettleLineMapper">
  6 +
  7 + <resultMap id="ProcurementMaterialSettleLineResult"
  8 + type="com.lframework.xingyun.sc.procurement.entity.settle.ProcurementMaterialSettleLine">
  9 + <id column="id" property="id"/>
  10 + <result column="settle_detail_id" property="settleDetailId"/>
  11 + <result column="procurement_plan_id" property="procurementPlanId"/>
  12 + <result column="plan_code" property="planCode"/>
  13 + <result column="product_id" property="productId"/>
  14 + <result column="product_name" property="productName"/>
  15 + <result column="category" property="category"/>
  16 + <result column="name" property="name"/>
  17 + <result column="weigh_quantity" property="weighQuantity"/>
  18 + <result column="impurity_rate" property="impurityRate"/>
  19 + <result column="fold_weight" property="foldWeight"/>
  20 + <result column="return_weight" property="returnWeight"/>
  21 + <result column="net_weight" property="netWeight"/>
  22 + <result column="remark" property="remark"/>
  23 + <result column="order_no" property="orderNo"/>
  24 + <result column="item_id" property="itemId"/>
  25 + <result column="create_by_id" property="createById"/>
  26 + <result column="create_by" property="createBy"/>
  27 + <result column="update_by_id" property="updateById"/>
  28 + <result column="update_by" property="updateBy"/>
  29 + <result column="create_time" property="createTime"/>
  30 + <result column="update_time" property="updateTime"/>
  31 + </resultMap>
  32 +
  33 + <sql id="PMSL_sql">
  34 + SELECT
  35 + pmsl.id,
  36 + pmsl.settle_detail_id,
  37 + pmsl.procurement_plan_id,
  38 + pmsl.plan_code,
  39 + pmsl.product_id,
  40 + br.product_name,
  41 + pmsl.category,
  42 + pmsl.name,
  43 + pmsl.weigh_quantity,
  44 + pmsl.impurity_rate,
  45 + pmsl.fold_weight,
  46 + pmsl.return_weight,
  47 + pmsl.net_weight,
  48 + pmsl.remark,
  49 + pmsl.order_no,
  50 + pmsl.item_id,
  51 + pmsl.create_by_id,
  52 + pmsl.create_by,
  53 + pmsl.update_by_id,
  54 + pmsl.update_by,
  55 + pmsl.create_time,
  56 + pmsl.update_time
  57 + FROM procurement_material_settle_line AS pmsl
  58 + LEFT JOIN base_data_breed_relationship br ON br.id = pmsl.product_id
  59 + </sql>
  60 +
  61 + <!-- 按原料结算详情单ID查询详情明细(品种名称联表带出,类别/开票品名查本表) -->
  62 + <select id="getBySettleDetailId" resultMap="ProcurementMaterialSettleLineResult">
  63 + <include refid="PMSL_sql"/>
  64 + WHERE pmsl.settle_detail_id = #{settleDetailId}
  65 + ORDER BY pmsl.order_no ASC
  66 + </select>
  67 +</mapper>
... ...
... ... @@ -8,6 +8,7 @@
8 8 <result column="weighing_ticket_code" property="weighingTicketCode"/>
9 9 <result column="workshop_id" property="workshopId"/>
10 10 <result column="workshop_name" property="workshopName"/>
  11 + <result column="workshop_code" property="workshopCode"/>
11 12 <result column="supplier_name" property="supplierName"/>
12 13 <result column="procurement_plan_id" property="procurementPlanId"/>
13 14 <result column="plan_code" property="planCode"/>
... ... @@ -49,6 +50,7 @@
49 50 tb.weighing_ticket_code,
50 51 tb.workshop_id,
51 52 tb.workshop_name,
  53 + ws.code AS workshop_code,
52 54 tb.supplier_name,
53 55 tb.procurement_plan_id,
54 56 tb.plan_code,
... ... @@ -82,6 +84,7 @@
82 84 tb.create_time,
83 85 tb.update_time
84 86 FROM procurement_assay_report AS tb
  87 + LEFT JOIN base_data_workshop ws ON ws.id = tb.workshop_id
85 88 </sql>
86 89
87 90 <select id="query" resultMap="ProcurementAssayReportResult">
... ... @@ -212,7 +215,7 @@
212 215 ORDER BY pwtl.order_no
213 216 </select>
214 217
215   - <!-- 新增页级联第三步:所选计划下的过磅品种下拉,已生成原料化验报告单的品种不查出(同一品种多条过磅明细时由 Service 按 productId 去重取第一条) -->
  218 + <!-- 新增页级联第三步:所选计划下的过磅品种下拉,已生成原料化验报告单(未取消)的品种不查出(同一品种多条过磅明细时由 Service 按 productId 去重取第一条) -->
216 219 <select id="queryAssayedProducts" resultMap="AssayReportProductOptionResult">
217 220 SELECT
218 221 pwtl.product_id,
... ... @@ -230,6 +233,7 @@
230 233 WHERE par.weighing_ticket_id = pwtl.weighing_ticket_id
231 234 AND par.product_id = pwtl.product_id
232 235 AND par.deleted = 0
  236 + AND par.approval_status != 'CANCEL'
233 237 )
234 238 ORDER BY pwtl.order_no
235 239 </select>
... ...
... ... @@ -42,6 +42,15 @@
42 42 ORDER BY pwta.order_no ASC
43 43 </select>
44 44
  45 + <select id="getByWeighingTicketIds" resultMap="ProcurementWeighingTicketApplyLineResult">
  46 + <include refid="PWTA_sql"/>
  47 + WHERE pwta.weighing_ticket_id IN
  48 + <foreach collection="weighingTicketIds" open="(" separator="," close=")" item="item">
  49 + #{item}
  50 + </foreach>
  51 + ORDER BY pwta.weighing_ticket_id, pwta.order_no ASC
  52 + </select>
  53 +
45 54 <delete id="deleteByWeighingTicketId">
46 55 DELETE FROM procurement_weighing_ticket_apply_line WHERE weighing_ticket_id = #{weighingTicketId}
47 56 </delete>
... ...
... ... @@ -9,6 +9,7 @@
9 9 <result column="plan_code" property="planCode"/>
10 10 <result column="product_id" property="productId"/>
11 11 <result column="product_name" property="productName"/>
  12 + <result column="category" property="category"/>
12 13 <result column="invoice_product_name" property="invoiceProductName"/>
13 14 <result column="quantity" property="quantity"/>
14 15 <result column="order_no" property="orderNo"/>
... ... @@ -29,6 +30,7 @@
29 30 pwtl.plan_code,
30 31 pwtl.product_id,
31 32 br.product_name,
  33 + br.code AS category,
32 34 pwtl.invoice_product_name,
33 35 pwtl.quantity,
34 36 pwtl.order_no,
... ... @@ -49,6 +51,15 @@
49 51 ORDER BY pwtl.order_no ASC
50 52 </select>
51 53
  54 + <select id="getByWeighingTicketIds" resultMap="ProcurementWeighingTicketLineResult">
  55 + <include refid="PWTL_sql"/>
  56 + WHERE pwtl.weighing_ticket_id IN
  57 + <foreach collection="weighingTicketIds" open="(" separator="," close=")" item="item">
  58 + #{item}
  59 + </foreach>
  60 + ORDER BY pwtl.weighing_ticket_id, pwtl.order_no ASC
  61 + </select>
  62 +
52 63 <delete id="deleteByWeighingTicketId">
53 64 DELETE FROM procurement_weighing_ticket_line WHERE weighing_ticket_id = #{weighingTicketId}
54 65 </delete>
... ...