Commit df54d84c4a8e2f3bdf1928e80213cbab163eac2e

Authored by 房远帅
1 parent 4de963fd

采购-原料化验报告单:功能

Showing 24 changed files with 2494 additions and 3 deletions
... ... @@ -2640,3 +2640,88 @@ CREATE TABLE IF NOT EXISTS `procurement_assay_apply`
2640 2640 KEY `idx_paa_approval_status` (`approval_status`),
2641 2641 KEY `idx_paa_create_time` (`create_time`)
2642 2642 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='化验送样单';
  2643 +
  2644 +-- 原料化验报告单:分厂工艺科化验员制单,一单关联一个过磅码单、化验其中一个过磅品种(该品种须化验通过,即存在审核通过的化验送样单);一个过磅码单可有多张报告单
  2645 +CREATE TABLE IF NOT EXISTS `procurement_assay_report`
  2646 +(
  2647 + `id` varchar(32) NOT NULL COMMENT 'ID',
  2648 + `weighing_ticket_id` varchar(32) NOT NULL COMMENT '过磅码单ID',
  2649 + `weighing_ticket_code` varchar(50) DEFAULT NULL COMMENT '码单编号(冗余展示)',
  2650 + `workshop_id` varchar(32) DEFAULT NULL COMMENT '分厂ID',
  2651 + `workshop_name` varchar(200) DEFAULT NULL COMMENT '分厂名称',
  2652 + `supplier_name` varchar(200) DEFAULT NULL COMMENT '客户名称',
  2653 + `procurement_plan_id` varchar(32) DEFAULT NULL COMMENT '采购计划ID',
  2654 + `plan_code` varchar(50) DEFAULT NULL COMMENT '计划编号(冗余展示)',
  2655 + `product_id` varchar(32) DEFAULT NULL COMMENT '过磅品种ID',
  2656 + `product_name` varchar(200) DEFAULT NULL COMMENT '品种名称(冗余展示)',
  2657 + `report_date` date DEFAULT NULL COMMENT '制单日期',
  2658 + `has_quality_problem` tinyint(1) DEFAULT NULL COMMENT '是否有质量问题 是-1 否-0(原料质检员填写)',
  2659 + `process_opinion` varchar(1000) DEFAULT NULL COMMENT '处理意见(有质量问题时原料质检员必填)',
  2660 + `continue_approval` tinyint(1) DEFAULT NULL COMMENT '是否继续审批 是-1 否-0(原料质检员填写)',
  2661 + `ckzg_id` varchar(32) DEFAULT NULL COMMENT '仓库主管审核人ID',
  2662 + `ckzg_name` varchar(64) DEFAULT NULL COMMENT '仓库主管审核人姓名',
  2663 + `ckzg_opinion` varchar(500) DEFAULT NULL COMMENT '仓库主管审核意见',
  2664 + `gyglkzg_id` varchar(32) DEFAULT NULL COMMENT '供应管理科主管审核人ID(第一次)',
  2665 + `gyglkzg_name` varchar(64) DEFAULT NULL COMMENT '供应管理科主管审核人姓名(第一次)',
  2666 + `gyglkzg_opinion` varchar(500) DEFAULT NULL COMMENT '供应管理科主管审核意见(第一次)',
  2667 + `gybzg_id` varchar(32) DEFAULT NULL COMMENT '供应部主管审核人ID',
  2668 + `gybzg_name` varchar(64) DEFAULT NULL COMMENT '供应部主管审核人姓名',
  2669 + `gybzg_opinion` varchar(500) DEFAULT NULL COMMENT '供应部主管审核意见',
  2670 + `fczg_id` varchar(32) DEFAULT NULL COMMENT '分厂主管审核人ID',
  2671 + `fczg_name` varchar(64) DEFAULT NULL COMMENT '分厂主管审核人姓名',
  2672 + `fczg_opinion` varchar(500) DEFAULT NULL COMMENT '分厂主管审核意见',
  2673 + `zjl_id` varchar(32) DEFAULT NULL COMMENT '总经理审核人ID',
  2674 + `zjl_name` varchar(64) DEFAULT NULL COMMENT '总经理审核人姓名',
  2675 + `zjl_opinion` varchar(500) DEFAULT NULL COMMENT '总经理审核意见',
  2676 + `flow_node` varchar(50) DEFAULT NULL COMMENT '流程节点',
  2677 + `approval_status` varchar(50) DEFAULT NULL COMMENT '审核状态 DRAFT-草稿 AUDIT-审核中 PASS-审核通过 REFUSE-已驳回 CANCEL-已取消',
  2678 + `deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否作废 0-有效单 1-作废单(作废单只能查看)',
  2679 + `create_by_id` varchar(32) DEFAULT NULL COMMENT '创建人ID',
  2680 + `create_by` varchar(64) DEFAULT NULL COMMENT '创建人',
  2681 + `update_by_id` varchar(32) DEFAULT NULL COMMENT '更新人ID',
  2682 + `update_by` varchar(64) DEFAULT NULL COMMENT '更新人',
  2683 + `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  2684 + `update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  2685 + PRIMARY KEY (`id`),
  2686 + KEY `idx_par_weighing_ticket_id` (`weighing_ticket_id`),
  2687 + KEY `idx_par_procurement_plan_id` (`procurement_plan_id`),
  2688 + KEY `idx_par_product_id` (`product_id`),
  2689 + KEY `idx_par_approval_status` (`approval_status`),
  2690 + KEY `idx_par_flow_node` (`flow_node`),
  2691 + KEY `idx_par_create_time` (`create_time`)
  2692 +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='原料化验报告单';
  2693 +
  2694 +-- 原料化验报告单明细:成分字段为各分厂并集(前端根据分厂显示对应字段,后端统一存一张子表)
  2695 +CREATE TABLE IF NOT EXISTS `procurement_assay_report_line`
  2696 +(
  2697 + `id` varchar(32) NOT NULL COMMENT 'ID',
  2698 + `report_id` varchar(32) NOT NULL COMMENT '原料化验报告单ID',
  2699 + `assay_apply_id` varchar(32) DEFAULT NULL COMMENT '化验送样单ID(一条送样单对应一条明细)',
  2700 + `assay_apply_code` varchar(50) DEFAULT NULL COMMENT '送样编码(冗余展示,取自化验送样单编号)',
  2701 + `product_id` varchar(32) DEFAULT NULL COMMENT '样品:过磅品种ID(品种关系表ID,取自送样单)',
  2702 + `product_name` varchar(200) DEFAULT NULL COMMENT '样品名称(冗余展示,取自送样单)',
  2703 + `quantity` decimal(18,4) DEFAULT NULL COMMENT '数量(自动带出过磅明细,单位公斤,不可修改)',
  2704 + `sample_no` int DEFAULT NULL COMMENT '样号(从1开始)',
  2705 + `cu` decimal(10,4) DEFAULT NULL COMMENT 'Cu 成分%',
  2706 + `zn` decimal(10,4) DEFAULT NULL COMMENT 'Zn 成分%',
  2707 + `pb` decimal(10,4) DEFAULT NULL COMMENT 'Pb 成分%',
  2708 + `fe` decimal(10,4) DEFAULT NULL COMMENT 'Fe 成分%',
  2709 + `p` decimal(10,4) DEFAULT NULL COMMENT 'P 成分%',
  2710 + `sn` decimal(10,4) DEFAULT NULL COMMENT 'Sn 成分%',
  2711 + `ni` decimal(10,4) DEFAULT NULL COMMENT 'Ni 成分%',
  2712 + `al` decimal(10,4) DEFAULT NULL COMMENT 'Al 成分%',
  2713 + `cd` decimal(10,4) DEFAULT NULL COMMENT 'Cd 成分%',
  2714 + `cr6` decimal(10,4) DEFAULT NULL COMMENT 'Cr6+ 成分%',
  2715 + `hg` decimal(10,4) DEFAULT NULL COMMENT 'Hg 成分%',
  2716 + `bi` decimal(10,4) DEFAULT NULL COMMENT 'Bi 成分%',
  2717 + `create_by_id` varchar(32) DEFAULT NULL COMMENT '创建人ID',
  2718 + `create_by` varchar(64) DEFAULT NULL COMMENT '创建人',
  2719 + `update_by_id` varchar(32) DEFAULT NULL COMMENT '更新人ID',
  2720 + `update_by` varchar(64) DEFAULT NULL COMMENT '更新人',
  2721 + `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  2722 + `update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  2723 + PRIMARY KEY (`id`),
  2724 + KEY `idx_parl_report_id` (`report_id`),
  2725 + KEY `idx_parl_assay_apply_id` (`assay_apply_id`),
  2726 + KEY `idx_parl_product_id` (`product_id`)
  2727 +) 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 java.math.BigDecimal;
  5 +import lombok.Data;
  6 +
  7 +/**
  8 + * 原料化验报告制单:所选码单+计划+品种下的化验送样单列表(字段与报告单明细子表对齐,一条送样单对应一条明细)
  9 + */
  10 +@Data
  11 +public class GetAssayReportApplyOptionBo {
  12 +
  13 + @ApiModelProperty("化验送样单ID(一条送样单对应一条明细)")
  14 + private String assayApplyId;
  15 +
  16 + @ApiModelProperty("送样编码(取自化验送样单编号)")
  17 + private String assayApplyCode;
  18 +
  19 + @ApiModelProperty("样品:过磅品种ID(取自送样单)")
  20 + private String productId;
  21 +
  22 + @ApiModelProperty("样品名称(取自送样单)")
  23 + private String productName;
  24 +
  25 + @ApiModelProperty("数量(自动带出过磅明细,单位公斤,不可修改)")
  26 + private BigDecimal quantity;
  27 +}
... ...
  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 GetAssayReportPlanOptionBo {
  11 +
  12 + @ApiModelProperty("采购计划ID")
  13 + private String planId;
  14 +
  15 + @ApiModelProperty("计划编号")
  16 + private String planCode;
  17 +}
... ...
  1 +package com.lframework.xingyun.sc.bo.procurement;
  2 +
  3 +import io.swagger.annotations.ApiModelProperty;
  4 +import java.math.BigDecimal;
  5 +import lombok.Data;
  6 +
  7 +/**
  8 + * 原料化验报告制单:所选码单下化验通过的过磅品种下拉(同一品种多条过磅明细时取第一条的数据)
  9 + */
  10 +@Data
  11 +public class GetAssayReportProductOptionBo {
  12 +
  13 + @ApiModelProperty("过磅品种ID(品种关系表ID)")
  14 + private String productId;
  15 +
  16 + @ApiModelProperty("品种名称")
  17 + private String productName;
  18 +
  19 + @ApiModelProperty("采购计划ID(品种所在计划)")
  20 + private String planId;
  21 +
  22 + @ApiModelProperty("计划编号")
  23 + private String planCode;
  24 +
  25 + @ApiModelProperty("过磅数量(单位公斤,明细行数量自动带出)")
  26 + private BigDecimal quantity;
  27 +}
... ...
  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.web.core.bo.BaseBo;
  6 +import com.lframework.xingyun.sc.procurement.entity.weighing.ProcurementAssayReport;
  7 +import io.swagger.annotations.ApiModelProperty;
  8 +import java.math.BigDecimal;
  9 +import java.time.LocalDate;
  10 +import java.time.LocalDateTime;
  11 +import java.util.ArrayList;
  12 +import java.util.List;
  13 +import lombok.Data;
  14 +
  15 +@Data
  16 +public class GetProcurementAssayReportBo extends BaseBo<ProcurementAssayReport> {
  17 +
  18 + @ApiModelProperty("ID")
  19 + private String id;
  20 +
  21 + @ApiModelProperty("过磅码单ID")
  22 + private String weighingTicketId;
  23 +
  24 + @ApiModelProperty("码单编号")
  25 + private String weighingTicketCode;
  26 +
  27 + @ApiModelProperty("分厂ID")
  28 + private String workshopId;
  29 +
  30 + @ApiModelProperty("分厂名称")
  31 + private String workshopName;
  32 +
  33 + @ApiModelProperty("客户名称")
  34 + private String supplierName;
  35 +
  36 + @ApiModelProperty("采购计划ID")
  37 + private String procurementPlanId;
  38 +
  39 + @ApiModelProperty("计划编号")
  40 + private String planCode;
  41 +
  42 + @ApiModelProperty("过磅品种ID(品种关系表ID)")
  43 + private String productId;
  44 +
  45 + @ApiModelProperty("品种名称")
  46 + private String productName;
  47 +
  48 + @ApiModelProperty("制单日期")
  49 + @JsonFormat(pattern = StringPool.DATE_PATTERN)
  50 + private LocalDate reportDate;
  51 +
  52 + @ApiModelProperty("是否有质量问题(原料质检员填写)")
  53 + private Boolean hasQualityProblem;
  54 +
  55 + @ApiModelProperty("处理意见")
  56 + private String processOpinion;
  57 +
  58 + @ApiModelProperty("是否继续审批(原料质检员填写)")
  59 + private Boolean continueApproval;
  60 +
  61 + @ApiModelProperty("仓库主管审核人ID")
  62 + private String ckzgId;
  63 +
  64 + @ApiModelProperty("仓库主管审核人姓名")
  65 + private String ckzgName;
  66 +
  67 + @ApiModelProperty("仓库主管审核意见")
  68 + private String ckzgOpinion;
  69 +
  70 + @ApiModelProperty("供应管理科主管审核人ID(第一次)")
  71 + private String gyglkzgId;
  72 +
  73 + @ApiModelProperty("供应管理科主管审核人姓名(第一次)")
  74 + private String gyglkzgName;
  75 +
  76 + @ApiModelProperty("供应管理科主管审核意见(第一次)")
  77 + private String gyglkzgOpinion;
  78 +
  79 + @ApiModelProperty("供应部主管审核人ID")
  80 + private String gybzgId;
  81 +
  82 + @ApiModelProperty("供应部主管审核人姓名")
  83 + private String gybzgName;
  84 +
  85 + @ApiModelProperty("供应部主管审核意见")
  86 + private String gybzgOpinion;
  87 +
  88 + @ApiModelProperty("分厂主管审核人ID")
  89 + private String fczgId;
  90 +
  91 + @ApiModelProperty("分厂主管审核人姓名")
  92 + private String fczgName;
  93 +
  94 + @ApiModelProperty("分厂主管审核意见")
  95 + private String fczgOpinion;
  96 +
  97 + @ApiModelProperty("总经理审核人ID")
  98 + private String zjlId;
  99 +
  100 + @ApiModelProperty("总经理审核人姓名")
  101 + private String zjlName;
  102 +
  103 + @ApiModelProperty("总经理审核意见")
  104 + private String zjlOpinion;
  105 +
  106 + @ApiModelProperty("流程节点")
  107 + private String flowNode;
  108 +
  109 + @ApiModelProperty("审核状态 DRAFT/AUDIT/PASS/REFUSE/CANCEL")
  110 + private String approvalStatus;
  111 +
  112 + @ApiModelProperty("化验明细(成分字段为各分厂并集,前端根据分厂显示)")
  113 + private List<LineBo> lines = new ArrayList<>();
  114 +
  115 + @ApiModelProperty("是否展示审核按钮")
  116 + private Boolean showExamine;
  117 +
  118 + @ApiModelProperty("是否展示审核详情按钮")
  119 + private Boolean showExamineDetail;
  120 +
  121 + @ApiModelProperty("创建人")
  122 + private String createBy;
  123 +
  124 + @ApiModelProperty("创建人ID")
  125 + private String createById;
  126 +
  127 + @ApiModelProperty("创建时间")
  128 + @JsonFormat(pattern = StringPool.DATE_TIME_PATTERN)
  129 + private LocalDateTime createTime;
  130 +
  131 + public GetProcurementAssayReportBo() {
  132 + super();
  133 + }
  134 +
  135 + public GetProcurementAssayReportBo(ProcurementAssayReport dto) {
  136 + super(dto);
  137 + }
  138 +
  139 + @Data
  140 + public static class LineBo {
  141 +
  142 + @ApiModelProperty("化验送样单ID")
  143 + private String assayApplyId;
  144 +
  145 + @ApiModelProperty("送样编码")
  146 + private String assayApplyCode;
  147 +
  148 + @ApiModelProperty("样品:过磅品种ID")
  149 + private String productId;
  150 +
  151 + @ApiModelProperty("样品名称")
  152 + private String productName;
  153 +
  154 + @ApiModelProperty("数量(自动带出过磅明细,单位公斤)")
  155 + private BigDecimal quantity;
  156 +
  157 + @ApiModelProperty("样号(从1开始)")
  158 + private Integer sampleNo;
  159 +
  160 + @ApiModelProperty("Cu 成分%")
  161 + private BigDecimal cu;
  162 +
  163 + @ApiModelProperty("Zn 成分%")
  164 + private BigDecimal zn;
  165 +
  166 + @ApiModelProperty("Pb 成分%")
  167 + private BigDecimal pb;
  168 +
  169 + @ApiModelProperty("Fe 成分%")
  170 + private BigDecimal fe;
  171 +
  172 + @ApiModelProperty("P 成分%")
  173 + private BigDecimal p;
  174 +
  175 + @ApiModelProperty("Sn 成分%")
  176 + private BigDecimal sn;
  177 +
  178 + @ApiModelProperty("Ni 成分%")
  179 + private BigDecimal ni;
  180 +
  181 + @ApiModelProperty("Al 成分%")
  182 + private BigDecimal al;
  183 +
  184 + @ApiModelProperty("Cd 成分%")
  185 + private BigDecimal cd;
  186 +
  187 + @ApiModelProperty("Cr6+ 成分%")
  188 + private BigDecimal cr6;
  189 +
  190 + @ApiModelProperty("Hg 成分%")
  191 + private BigDecimal hg;
  192 +
  193 + @ApiModelProperty("Bi 成分%")
  194 + private BigDecimal bi;
  195 + }
  196 +}
... ...
... ... @@ -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.weighing.ProcurementAssayReportService;
32 33 import com.lframework.xingyun.sc.procurement.service.weighing.ProcurementWeighingTicketService;
33 34 import com.lframework.xingyun.sc.service.contract.ContractDistributorLineService;
34 35 import com.lframework.xingyun.sc.service.contract.ContractChangeApplicationService;
... ... @@ -177,6 +178,8 @@ public class BusinessDataHandlerServiceImpl implements BusinessDataHandlerServic
177 178 private ProcurementWeighingTicketService procurementWeighingTicketService;
178 179 @Resource
179 180 private ProcurementAssayApplyService procurementAssayApplyService;
  181 + @Resource
  182 + private ProcurementAssayReportService procurementAssayReportService;
180 183
181 184
182 185
... ... @@ -288,6 +291,9 @@ public class BusinessDataHandlerServiceImpl implements BusinessDataHandlerServic
288 291 case "ASSAY_APPLY":
289 292 handleAssayApplyData(flowStatus, businessId);
290 293 break;
  294 + case "ASSAY_REPORT":
  295 + handleAssayReportData(flowStatus, businessId);
  296 + break;
291 297 default:
292 298 break;
293 299 }
... ... @@ -1265,4 +1271,21 @@ public class BusinessDataHandlerServiceImpl implements BusinessDataHandlerServic
1265 1271 procurementAssayApplyService.updateApprovalStatus(businessId, "REFUSE");
1266 1272 }
1267 1273 }
  1274 +
  1275 + /**
  1276 + * 原料化验报告单审核业务数据处理
  1277 + *
  1278 + * @param flowStatus 审核结果
  1279 + * @param businessId 业务ID
  1280 + */
  1281 + private void handleAssayReportData(String flowStatus, String businessId) {
  1282 + if (FlowInstanceStatus.APPROVE_PASS.getCode().equals(flowStatus)
  1283 + || FlowInstanceStatus.FINISH.getCode().equals(flowStatus)) {
  1284 + procurementAssayReportService.updateApprovalStatus(businessId, "PASS");
  1285 + } else if (FlowInstanceStatus.REVOKE.getCode().equals(flowStatus)
  1286 + || FlowInstanceStatus.REFUSE.getCode().equals(flowStatus)
  1287 + || FlowInstanceStatus.TERMINATION.getCode().equals(flowStatus)) {
  1288 + procurementAssayReportService.updateApprovalStatus(businessId, "REFUSE");
  1289 + }
  1290 + }
1268 1291 }
... ...
... ... @@ -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.weighing.ProcurementAssayReportService;
25 26 import com.lframework.xingyun.sc.procurement.service.weighing.ProcurementWeighingTicketService;
26 27 import com.lframework.xingyun.sc.procurement.vo.change.UpdateProcurementPlanChangeVo;
27 28 import com.lframework.xingyun.sc.service.contract.ContractDistributorStandardService;
... ... @@ -76,6 +77,8 @@ public class FlowTaskServiceImpl implements FlowTaskService {
76 77 private CoordinationSummaryApprovalService coordinationSummaryApprovalService;
77 78 @Resource
78 79 private ProcurementWeighingTicketService procurementWeighingTicketService;
  80 + @Resource
  81 + private ProcurementAssayReportService procurementAssayReportService;
79 82
80 83
81 84 @OpLog(type = OtherOpLogType.class, name = "修改客户资信,ID:{}", params = {"#id"})
... ... @@ -487,6 +490,12 @@ public class FlowTaskServiceImpl implements FlowTaskService {
487 490 procurementWeighingTicketService.updateNoFlowInstance(map);
488 491 }
489 492
  493 + @Transactional(rollbackFor = Exception.class)
  494 + @Override
  495 + public void updateAssayReportApprovalMap(Map<String, Object> map) {
  496 + procurementAssayReportService.updateNoFlowInstance(map);
  497 + }
  498 +
490 499 @Override
491 500 public Map<String, Object> findById(String s) {
492 501 ProductSampleConfirmationSlip slip = productSampleConfirmationSlipService.findById(s);
... ...
  1 +package com.lframework.xingyun.sc.procurement.controller.weighing;
  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.GetAssayReportApplyOptionBo;
  10 +import com.lframework.xingyun.sc.bo.procurement.GetAssayReportPlanOptionBo;
  11 +import com.lframework.xingyun.sc.bo.procurement.GetAssayReportProductOptionBo;
  12 +import com.lframework.xingyun.sc.bo.procurement.GetAssaySelectableTicketBo;
  13 +import com.lframework.xingyun.sc.bo.procurement.GetProcurementAssayReportBo;
  14 +import com.lframework.xingyun.sc.procurement.entity.weighing.ProcurementAssayReport;
  15 +import com.lframework.xingyun.sc.procurement.service.weighing.ProcurementAssayReportService;
  16 +import com.lframework.xingyun.sc.procurement.vo.weighing.CreateProcurementAssayReportVo;
  17 +import com.lframework.xingyun.sc.procurement.vo.weighing.QueryAssaySelectableTicketVo;
  18 +import com.lframework.xingyun.sc.procurement.vo.weighing.QueryProcurementAssayReportVo;
  19 +import com.lframework.xingyun.sc.procurement.vo.weighing.UpdateAssayReportQualityVo;
  20 +import com.lframework.xingyun.sc.procurement.vo.weighing.UpdateProcurementAssayReportVo;
  21 +import io.swagger.annotations.Api;
  22 +import io.swagger.annotations.ApiImplicitParam;
  23 +import io.swagger.annotations.ApiOperation;
  24 +
  25 +import java.util.List;
  26 +import java.util.stream.Collectors;
  27 +import javax.annotation.Resource;
  28 +import javax.validation.Valid;
  29 +import javax.validation.constraints.NotBlank;
  30 +
  31 +import lombok.extern.slf4j.Slf4j;
  32 +import org.springframework.util.CollectionUtils;
  33 +import org.springframework.validation.annotation.Validated;
  34 +import org.springframework.web.bind.annotation.GetMapping;
  35 +import org.springframework.web.bind.annotation.PostMapping;
  36 +import org.springframework.web.bind.annotation.PutMapping;
  37 +import org.springframework.web.bind.annotation.RequestBody;
  38 +import org.springframework.web.bind.annotation.RequestMapping;
  39 +import org.springframework.web.bind.annotation.RestController;
  40 +
  41 +/**
  42 + * 原料化验报告单
  43 + */
  44 +@Api(tags = "原料化验报告单管理")
  45 +@Slf4j
  46 +@Validated
  47 +@RestController
  48 +@RequestMapping("/procurement/assay/report")
  49 +public class ProcurementAssayReportController extends DefaultBaseController {
  50 +
  51 + @Resource
  52 + private ProcurementAssayReportService procurementAssayReportService;
  53 +
  54 + @ApiOperation("分页查询原料化验报告单")
  55 + @HasPermission({"warehouse-manage:material-test:query"})
  56 + @GetMapping("/query")
  57 + public InvokeResult<PageResult<GetProcurementAssayReportBo>> query(
  58 + @Valid QueryProcurementAssayReportVo vo) {
  59 + PageResult<ProcurementAssayReport> result = procurementAssayReportService.query(
  60 + getPageIndex(vo), getPageSize(vo), vo);
  61 +
  62 + List<GetProcurementAssayReportBo> results = null;
  63 + if (!CollectionUtils.isEmpty(result.getDatas())) {
  64 + results = result.getDatas().stream().map(GetProcurementAssayReportBo::new)
  65 + .collect(Collectors.toList());
  66 + }
  67 + return InvokeResultBuilder.success(PageResultUtil.rebuild(result, results));
  68 + }
  69 +
  70 + @ApiOperation("查询原料化验报告单详情")
  71 + @ApiImplicitParam(value = "ID", name = "id", paramType = "query", required = true)
  72 + @HasPermission({"warehouse-manage:material-test:query", "warehouse-manage:material-test:review"})
  73 + @GetMapping("")
  74 + public InvokeResult<GetProcurementAssayReportBo> findById(
  75 + @NotBlank(message = "ID不能为空!") String id) {
  76 + return InvokeResultBuilder.success(procurementAssayReportService.findDetail(id));
  77 + }
  78 +
  79 + @ApiOperation("选择码单弹窗:分页查询可制单的过磅码单(审核通过且已上传签字凭证且每个过磅品种的化验送样单全部审核通过,级联第一步)")
  80 + @GetMapping("/ticketPage")
  81 + public InvokeResult<PageResult<GetAssaySelectableTicketBo>> querySelectableTickets(
  82 + @Valid QueryAssaySelectableTicketVo vo) {
  83 + return InvokeResultBuilder.success(procurementAssayReportService.querySelectableTickets(
  84 + getPageIndex(vo), getPageSize(vo), vo));
  85 + }
  86 +
  87 + @ApiOperation("新增页级联第二步:所选码单下的计划编号下拉")
  88 + @GetMapping("/planOptions")
  89 + public InvokeResult<List<GetAssayReportPlanOptionBo>> getPlanOptions(
  90 + @NotBlank(message = "过磅码单不能为空!") String ticketId) {
  91 + return InvokeResultBuilder.success(
  92 + procurementAssayReportService.getPlanOptions(ticketId));
  93 + }
  94 +
  95 + @ApiOperation("新增页级联第三步:所选计划下的过磅品种下拉(已生成原料化验报告单的品种不查出,含过磅数量)")
  96 + @GetMapping("/productOptions")
  97 + public InvokeResult<List<GetAssayReportProductOptionBo>> getAssayedProducts(
  98 + @NotBlank(message = "过磅码单不能为空!") String ticketId,
  99 + @NotBlank(message = "采购计划不能为空!") String planId) {
  100 + return InvokeResultBuilder.success(
  101 + procurementAssayReportService.getAssayedProducts(ticketId, planId));
  102 + }
  103 +
  104 + @ApiOperation("新增页级联第四步:所选码单+计划+品种下的化验送样单列表(带编号,一条送样单对应报告单一条明细)")
  105 + @GetMapping("/applyOptions")
  106 + public InvokeResult<List<GetAssayReportApplyOptionBo>> getAssayApplies(
  107 + @NotBlank(message = "过磅码单不能为空!") String ticketId,
  108 + @NotBlank(message = "采购计划不能为空!") String planId,
  109 + @NotBlank(message = "过磅品种不能为空!") String productId) {
  110 + return InvokeResultBuilder.success(
  111 + procurementAssayReportService.getAssayApplies(ticketId, planId, productId));
  112 + }
  113 +
  114 + @ApiOperation("新增原料化验报告单(草稿,分厂工艺科化验员)")
  115 + @HasPermission({"warehouse-manage:material-test:add"})
  116 + @PostMapping("")
  117 + public InvokeResult<String> create(@RequestBody @Valid CreateProcurementAssayReportVo vo) {
  118 + String id = procurementAssayReportService.create(vo);
  119 + return InvokeResultBuilder.success(id);
  120 + }
  121 +
  122 + @ApiOperation("修改原料化验报告单")
  123 + @HasPermission({"warehouse-manage:material-test:modify",
  124 + "warehouse-manage:material-test:approve"})
  125 + @PutMapping("")
  126 + public InvokeResult<Void> update(@RequestBody @Valid UpdateProcurementAssayReportVo vo) {
  127 + procurementAssayReportService.update(vo);
  128 + return InvokeResultBuilder.success();
  129 + }
  130 +
  131 + @ApiOperation("提交流转(流程推进到下一环节)")
  132 + @HasPermission({"warehouse-manage:material-test:submit"})
  133 + @ApiImplicitParam(value = "ID", name = "id", paramType = "query", required = true)
  134 + @PutMapping("/approve")
  135 + public InvokeResult<Void> approve(@NotBlank(message = "ID不能为空!") String id) {
  136 + procurementAssayReportService.approve(id);
  137 + return InvokeResultBuilder.success();
  138 + }
  139 +
  140 + @ApiOperation("原料质检员填写质检问题(审核中可填写,有质量问题时处理意见必填)")
  141 + @HasPermission({"warehouse-manage:material-test:updateOption"})
  142 + @PutMapping("/quality")
  143 + public InvokeResult<Void> updateQuality(@RequestBody @Valid UpdateAssayReportQualityVo vo) {
  144 + procurementAssayReportService.updateQuality(vo);
  145 + return InvokeResultBuilder.success();
  146 + }
  147 +
  148 + @ApiOperation("提交原料化验报告单审核")
  149 + @HasPermission({"warehouse-manage:material-test:submitApprove"})
  150 + @ApiImplicitParam(value = "ID", name = "id", paramType = "query", required = true)
  151 + @PutMapping("/submit")
  152 + public InvokeResult<Void> submit(@NotBlank(message = "ID不能为空!") String id) {
  153 + procurementAssayReportService.submit(id);
  154 + return InvokeResultBuilder.success();
  155 + }
  156 +
  157 + @ApiOperation("取消原料化验报告单(已驳回状态可取消)")
  158 + @HasPermission({"warehouse-manage:material-test:cancel"})
  159 + @ApiImplicitParam(value = "ID", name = "id", paramType = "query", required = true)
  160 + @PutMapping("/cancel")
  161 + public InvokeResult<Void> cancel(@NotBlank(message = "ID不能为空!") String id) {
  162 + procurementAssayReportService.cancel(id);
  163 + return InvokeResultBuilder.success();
  164 + }
  165 +
  166 + @ApiOperation("作废原料化验报告单(仅审核通过的报告单可作废,作废后只能查看)")
  167 + @HasPermission({"warehouse-manage:material-test:delete"})
  168 + @ApiImplicitParam(value = "ID", name = "id", paramType = "query", required = true)
  169 + @PutMapping("/delete")
  170 + public InvokeResult<Void> delete(@NotBlank(message = "ID不能为空!") String id) {
  171 + procurementAssayReportService.delete(id);
  172 + return InvokeResultBuilder.success();
  173 + }
  174 +}
... ...
  1 +package com.lframework.xingyun.sc.procurement.entity.weighing;
  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 java.time.LocalDate;
  9 +import java.time.LocalDateTime;
  10 +import lombok.Data;
  11 +
  12 +/**
  13 + * 原料化验报告单
  14 + */
  15 +@Data
  16 +@TableName("procurement_assay_report")
  17 +public class ProcurementAssayReport extends BaseEntity implements BaseDto {
  18 +
  19 + private static final long serialVersionUID = 1L;
  20 +
  21 + /**
  22 + * 主键ID
  23 + */
  24 + private String id;
  25 +
  26 + /**
  27 + * 过磅码单ID
  28 + */
  29 + private String weighingTicketId;
  30 +
  31 + /**
  32 + * 码单编号(冗余展示)
  33 + */
  34 + private String weighingTicketCode;
  35 +
  36 + /**
  37 + * 分厂ID(取自过磅码单)
  38 + */
  39 + private String workshopId;
  40 +
  41 + /**
  42 + * 分厂名称(取自过磅码单)
  43 + */
  44 + private String workshopName;
  45 +
  46 + /**
  47 + * 客户名称(取自过磅码单供料单位)
  48 + */
  49 + private String supplierName;
  50 +
  51 + /**
  52 + * 采购计划ID(所选品种所在计划)
  53 + */
  54 + private String procurementPlanId;
  55 +
  56 + /**
  57 + * 计划编号(冗余展示)
  58 + */
  59 + private String planCode;
  60 +
  61 + /**
  62 + * 过磅品种ID
  63 + */
  64 + private String productId;
  65 +
  66 + /**
  67 + * 品种名称(冗余展示)
  68 + */
  69 + private String productName;
  70 +
  71 + /**
  72 + * 制单日期
  73 + */
  74 + private LocalDate reportDate;
  75 +
  76 + /**
  77 + * 是否有质量问题(原料质检员填写)true-是 false-否
  78 + */
  79 + private Boolean hasQualityProblem;
  80 +
  81 + /**
  82 + * 处理意见(有质量问题时原料质检员必填)
  83 + */
  84 + private String processOpinion;
  85 +
  86 + /**
  87 + * 是否继续审批(原料质检员填写)true-是 false-否
  88 + */
  89 + private Boolean continueApproval;
  90 +
  91 + /**
  92 + * 仓库主管审核人ID
  93 + */
  94 + private String ckzgId;
  95 +
  96 + /**
  97 + * 仓库主管审核人姓名
  98 + */
  99 + private String ckzgName;
  100 +
  101 + /**
  102 + * 仓库主管审核意见
  103 + */
  104 + private String ckzgOpinion;
  105 +
  106 + /**
  107 + * 供应管理科主管审核人ID(第一次)
  108 + */
  109 + private String gyglkzgId;
  110 +
  111 + /**
  112 + * 供应管理科主管审核人姓名(第一次)
  113 + */
  114 + private String gyglkzgName;
  115 +
  116 + /**
  117 + * 供应管理科主管审核意见(第一次)
  118 + */
  119 + private String gyglkzgOpinion;
  120 +
  121 + /**
  122 + * 供应部主管审核人ID
  123 + */
  124 + private String gybzgId;
  125 +
  126 + /**
  127 + * 供应部主管审核人姓名
  128 + */
  129 + private String gybzgName;
  130 +
  131 + /**
  132 + * 供应部主管审核意见
  133 + */
  134 + private String gybzgOpinion;
  135 +
  136 + /**
  137 + * 分厂主管审核人ID
  138 + */
  139 + private String fczgId;
  140 +
  141 + /**
  142 + * 分厂主管审核人姓名
  143 + */
  144 + private String fczgName;
  145 +
  146 + /**
  147 + * 分厂主管审核意见
  148 + */
  149 + private String fczgOpinion;
  150 +
  151 + /**
  152 + * 总经理审核人ID
  153 + */
  154 + private String zjlId;
  155 +
  156 + /**
  157 + * 总经理审核人姓名
  158 + */
  159 + private String zjlName;
  160 +
  161 + /**
  162 + * 总经理审核意见
  163 + */
  164 + private String zjlOpinion;
  165 +
  166 + /**
  167 + * 流程节点
  168 + */
  169 + private String flowNode;
  170 +
  171 + /**
  172 + * 审核状态 DRAFT-草稿 AUDIT-审核中 PASS-审核通过 REFUSE-已驳回 CANCEL-已取消
  173 + */
  174 + private String approvalStatus;
  175 +
  176 + /**
  177 + * 是否作废/删除 0-有效单 1-作废单(作废单只能查看)
  178 + */
  179 + private Boolean deleted;
  180 +
  181 + /**
  182 + * 创建人ID
  183 + */
  184 + @TableField(fill = FieldFill.INSERT)
  185 + private String createById;
  186 +
  187 + /**
  188 + * 创建人
  189 + */
  190 + @TableField(fill = FieldFill.INSERT)
  191 + private String createBy;
  192 +
  193 + /**
  194 + * 更新人ID
  195 + */
  196 + @TableField(fill = FieldFill.INSERT_UPDATE)
  197 + private String updateById;
  198 +
  199 + /**
  200 + * 更新人
  201 + */
  202 + @TableField(fill = FieldFill.INSERT_UPDATE)
  203 + private String updateBy;
  204 +
  205 + /**
  206 + * 创建时间
  207 + */
  208 + @TableField(fill = FieldFill.INSERT)
  209 + private LocalDateTime createTime;
  210 +
  211 + /**
  212 + * 更新时间
  213 + */
  214 + @TableField(fill = FieldFill.INSERT_UPDATE)
  215 + private LocalDateTime updateTime;
  216 +
  217 + /**
  218 + * 审核按钮标记(待办驱动,非数据库字段)
  219 + */
  220 + @TableField(exist = false)
  221 + private Boolean showExamine;
  222 +
  223 + /**
  224 + * 审核详情按钮标记(存在流程实例,非数据库字段)
  225 + */
  226 + @TableField(exist = false)
  227 + private Boolean showExamineDetail;
  228 +}
... ...
  1 +package com.lframework.xingyun.sc.procurement.entity.weighing;
  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 java.math.BigDecimal;
  9 +import java.time.LocalDateTime;
  10 +import lombok.Data;
  11 +
  12 +/**
  13 + * 原料化验报告单明细(成分字段为各分厂并集,前端根据分厂显示对应字段)
  14 + */
  15 +@Data
  16 +@TableName("procurement_assay_report_line")
  17 +public class ProcurementAssayReportLine extends BaseEntity implements BaseDto {
  18 +
  19 + private static final long serialVersionUID = 1L;
  20 +
  21 + /**
  22 + * 主键ID
  23 + */
  24 + private String id;
  25 +
  26 + /**
  27 + * 原料化验报告单主表ID
  28 + */
  29 + private String reportId;
  30 +
  31 + /**
  32 + * 化验送样单ID(一条送样单对应一条明细)
  33 + */
  34 + private String assayApplyId;
  35 +
  36 + /**
  37 + * 送样编码(冗余展示,取自化验送样单编号)
  38 + */
  39 + private String assayApplyCode;
  40 +
  41 + /**
  42 + * 样品:过磅品种ID(取自送样单)
  43 + */
  44 + private String productId;
  45 +
  46 + /**
  47 + * 样品名称(冗余展示,取自送样单)
  48 + */
  49 + private String productName;
  50 +
  51 + /**
  52 + * 数量(自动带出过磅明细,单位公斤,不可修改)
  53 + */
  54 + private BigDecimal quantity;
  55 +
  56 + /**
  57 + * 样号(从1开始)
  58 + */
  59 + private Integer sampleNo;
  60 +
  61 + /**
  62 + * Cu 成分%
  63 + */
  64 + private BigDecimal cu;
  65 +
  66 + /**
  67 + * Zn 成分%
  68 + */
  69 + private BigDecimal zn;
  70 +
  71 + /**
  72 + * Pb 成分%
  73 + */
  74 + private BigDecimal pb;
  75 +
  76 + /**
  77 + * Fe 成分%
  78 + */
  79 + private BigDecimal fe;
  80 +
  81 + /**
  82 + * P 成分%
  83 + */
  84 + private BigDecimal p;
  85 +
  86 + /**
  87 + * Sn 成分%
  88 + */
  89 + private BigDecimal sn;
  90 +
  91 + /**
  92 + * Ni 成分%
  93 + */
  94 + private BigDecimal ni;
  95 +
  96 + /**
  97 + * Al 成分%
  98 + */
  99 + private BigDecimal al;
  100 +
  101 + /**
  102 + * Cd 成分%
  103 + */
  104 + private BigDecimal cd;
  105 +
  106 + /**
  107 + * Cr6+ 成分%
  108 + */
  109 + private BigDecimal cr6;
  110 +
  111 + /**
  112 + * Hg 成分%
  113 + */
  114 + private BigDecimal hg;
  115 +
  116 + /**
  117 + * Bi 成分%
  118 + */
  119 + private BigDecimal bi;
  120 +
  121 + /**
  122 + * 创建人ID
  123 + */
  124 + @TableField(fill = FieldFill.INSERT)
  125 + private String createById;
  126 +
  127 + /**
  128 + * 创建人
  129 + */
  130 + @TableField(fill = FieldFill.INSERT)
  131 + private String createBy;
  132 +
  133 + /**
  134 + * 更新人ID
  135 + */
  136 + @TableField(fill = FieldFill.INSERT_UPDATE)
  137 + private String updateById;
  138 +
  139 + /**
  140 + * 更新人
  141 + */
  142 + @TableField(fill = FieldFill.INSERT_UPDATE)
  143 + private String updateBy;
  144 +
  145 + /**
  146 + * 创建时间
  147 + */
  148 + @TableField(fill = FieldFill.INSERT)
  149 + private LocalDateTime createTime;
  150 +
  151 + /**
  152 + * 更新时间
  153 + */
  154 + @TableField(fill = FieldFill.INSERT_UPDATE)
  155 + private LocalDateTime updateTime;
  156 +}
... ...
... ... @@ -293,9 +293,6 @@ public class ProcurementAssayApplyServiceImpl
293 293 }
294 294 // 作废单只能查看
295 295 assertValid(entity);
296   - if (!STATUS_REFUSE.equals(entity.getApprovalStatus())) {
297   - throw new DefaultClientException("只有已驳回的化验送样单可以取消!");
298   - }
299 296
300 297 this.update(Wrappers.lambdaUpdate(ProcurementAssayApply.class)
301 298 .set(ProcurementAssayApply::getApprovalStatus, STATUS_CANCEL)
... ...
  1 +package com.lframework.xingyun.sc.procurement.impl.weighing;
  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.weighing.ProcurementAssayReportLine;
  6 +import com.lframework.xingyun.sc.procurement.mappers.weighing.ProcurementAssayReportLineMapper;
  7 +import com.lframework.xingyun.sc.procurement.service.weighing.ProcurementAssayReportLineService;
  8 +import java.util.List;
  9 +import org.springframework.stereotype.Service;
  10 +
  11 +/**
  12 + * 原料化验报告单明细
  13 + */
  14 +@Service
  15 +public class ProcurementAssayReportLineServiceImpl
  16 + extends BaseMpServiceImpl<ProcurementAssayReportLineMapper, ProcurementAssayReportLine>
  17 + implements ProcurementAssayReportLineService {
  18 +
  19 + @Override
  20 + public List<ProcurementAssayReportLine> getByReportId(String reportId) {
  21 + return this.list(Wrappers.lambdaQuery(ProcurementAssayReportLine.class)
  22 + .eq(ProcurementAssayReportLine::getReportId, reportId)
  23 + .orderByAsc(ProcurementAssayReportLine::getSampleNo));
  24 + }
  25 +
  26 + @Override
  27 + public void deleteByReportId(String reportId) {
  28 + this.remove(Wrappers.lambdaQuery(ProcurementAssayReportLine.class)
  29 + .eq(ProcurementAssayReportLine::getReportId, reportId));
  30 + }
  31 +}
... ...
  1 +package com.lframework.xingyun.sc.procurement.impl.weighing;
  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.GetAssayReportApplyOptionBo;
  27 +import com.lframework.xingyun.sc.bo.procurement.GetAssayReportPlanOptionBo;
  28 +import com.lframework.xingyun.sc.bo.procurement.GetAssayReportProductOptionBo;
  29 +import com.lframework.xingyun.sc.bo.procurement.GetAssaySelectableTicketBo;
  30 +import com.lframework.xingyun.sc.bo.procurement.GetProcurementAssayReportBo;
  31 +import com.lframework.xingyun.sc.procurement.entity.weighing.ProcurementAssayApply;
  32 +import com.lframework.xingyun.sc.procurement.entity.weighing.ProcurementAssayReport;
  33 +import com.lframework.xingyun.sc.procurement.entity.weighing.ProcurementAssayReportLine;
  34 +import com.lframework.xingyun.sc.procurement.entity.weighing.ProcurementWeighingTicket;
  35 +import com.lframework.xingyun.sc.procurement.entity.weighing.ProcurementWeighingTicketLine;
  36 +import com.lframework.xingyun.sc.procurement.mappers.weighing.ProcurementAssayApplyMapper;
  37 +import com.lframework.xingyun.sc.procurement.mappers.weighing.ProcurementAssayReportMapper;
  38 +import com.lframework.xingyun.sc.procurement.mappers.weighing.ProcurementWeighingTicketMapper;
  39 +import com.lframework.xingyun.sc.procurement.service.weighing.ProcurementAssayReportLineService;
  40 +import com.lframework.xingyun.sc.procurement.service.weighing.ProcurementAssayReportService;
  41 +import com.lframework.xingyun.sc.procurement.service.weighing.ProcurementWeighingTicketLineService;
  42 +import com.lframework.xingyun.sc.procurement.vo.weighing.AssayReportLineVo;
  43 +import com.lframework.xingyun.sc.procurement.vo.weighing.CreateProcurementAssayReportVo;
  44 +import com.lframework.xingyun.sc.procurement.vo.weighing.QueryAssaySelectableTicketVo;
  45 +import com.lframework.xingyun.sc.procurement.vo.weighing.QueryProcurementAssayReportVo;
  46 +import com.lframework.xingyun.sc.procurement.vo.weighing.UpdateAssayReportQualityVo;
  47 +import com.lframework.xingyun.sc.procurement.vo.weighing.UpdateProcurementAssayReportVo;
  48 +
  49 +import java.math.BigDecimal;
  50 +import java.time.LocalDate;
  51 +import java.util.ArrayList;
  52 +import java.util.Arrays;
  53 +import java.util.Collections;
  54 +import java.util.HashSet;
  55 +import java.util.LinkedHashMap;
  56 +import java.util.List;
  57 +import java.util.Map;
  58 +import java.util.Objects;
  59 +import java.util.Set;
  60 +import java.util.stream.Collectors;
  61 +import javax.annotation.Resource;
  62 +
  63 +import lombok.extern.slf4j.Slf4j;
  64 +import org.springframework.stereotype.Service;
  65 +import org.springframework.transaction.annotation.Transactional;
  66 +
  67 +/**
  68 + * 原料化验报告单
  69 + */
  70 +@Slf4j
  71 +@Service
  72 +public class ProcurementAssayReportServiceImpl
  73 + extends BaseMpServiceImpl<ProcurementAssayReportMapper, ProcurementAssayReport>
  74 + implements ProcurementAssayReportService {
  75 +
  76 + /**
  77 + * 审核状态-草稿
  78 + */
  79 + private static final String STATUS_DRAFT = "DRAFT";
  80 + /**
  81 + * 审核状态-审核中
  82 + */
  83 + private static final String STATUS_AUDIT = "AUDIT";
  84 + /**
  85 + * 审核状态-审核通过
  86 + */
  87 + private static final String STATUS_PASS = "PASS";
  88 + /**
  89 + * 审核状态-已驳回
  90 + */
  91 + private static final String STATUS_REFUSE = "REFUSE";
  92 + /**
  93 + * 审核状态-已取消
  94 + */
  95 + private static final String STATUS_CANCEL = "CANCEL";
  96 + /**
  97 + * 流程编号(需与流程设计器中的流程编号一致,流程创建后调整)
  98 + */
  99 + private static final String BPM_FLAG = "ASSAY_REPORT";
  100 + /**
  101 + * 流程节点编码(大写英文,存 flow_node,与系统节点字典一致;后续节点推进依赖流程设计器回调接入):
  102 + * 分厂工艺科化验员(制单) -> 分厂仓库质检员 -> 分厂仓库主管 -> 供应管理科主管 -> 供应部主管
  103 + * -> 分厂主管 -> 总经理
  104 + */
  105 + private static final String NODE_HGY = "GYKHYY";
  106 + private static final String NODE_CKZJY = "CKZJY";
  107 + private static final String NODE_CKZG = "CKZG";
  108 + private static final String NODE_GYGLKZG = "GYGLKZG";
  109 + private static final String NODE_GYBZG = "GYBZG";
  110 + private static final String NODE_FCZG = "FCZG";
  111 + private static final String NODE_ZJL = "ZJL";
  112 +
  113 + @Resource
  114 + private ProcurementAssayReportMapper assayReportMapper;
  115 +
  116 + @Resource
  117 + private ProcurementAssayReportLineService reportLineService;
  118 +
  119 + @Resource
  120 + private ProcurementWeighingTicketMapper weighingTicketMapper;
  121 +
  122 + @Resource
  123 + private ProcurementAssayApplyMapper assayApplyMapper;
  124 +
  125 + @Resource
  126 + private ProcurementWeighingTicketLineService weighLineService;
  127 +
  128 + @Resource
  129 + private FlowInstanceWrapperService flowInstanceWrapperService;
  130 +
  131 + @Resource
  132 + private FlowTaskWrapperMapper flowTaskWrapperMapper;
  133 +
  134 + @Resource
  135 + private FlowTaskWrapperService flowTaskWrapperService;
  136 +
  137 + @Override
  138 + public PageResult<ProcurementAssayReport> query(Integer pageIndex, Integer pageSize,
  139 + QueryProcurementAssayReportVo vo) {
  140 + PageHelperUtil.startPage(pageIndex, pageSize);
  141 + List<ProcurementAssayReport> datas = assayReportMapper.query(vo);
  142 + PageResult<ProcurementAssayReport> pageResult = PageResultUtil.convert(new PageInfo<>(datas));
  143 +
  144 + fillOperateFlags(pageResult.getDatas());
  145 +
  146 + return pageResult;
  147 + }
  148 +
  149 + @Override
  150 + public PageResult<GetAssaySelectableTicketBo> querySelectableTickets(Integer pageIndex,
  151 + Integer pageSize, QueryAssaySelectableTicketVo vo) {
  152 + PageHelperUtil.startPage(pageIndex, pageSize);
  153 + List<GetAssaySelectableTicketBo> datas = assayReportMapper.querySelectableTickets(vo);
  154 + return PageResultUtil.convert(new PageInfo<>(datas));
  155 + }
  156 +
  157 + @Override
  158 + public GetProcurementAssayReportBo findDetail(String id) {
  159 + if (StringUtil.isBlank(id)) {
  160 + throw new InputErrorException("ID不能为空!");
  161 + }
  162 +
  163 + ProcurementAssayReport entity = this.getById(id);
  164 + if (entity == null) {
  165 + throw new DefaultClientException("原料化验报告单不存在!");
  166 + }
  167 + fillOperateFlags(Collections.singletonList(entity));
  168 +
  169 + GetProcurementAssayReportBo bo = new GetProcurementAssayReportBo(entity);
  170 + bo.setLines(new ArrayList<>());
  171 + List<ProcurementAssayReportLine> lines = reportLineService.getByReportId(id);
  172 + if (CollectionUtil.isNotEmpty(lines)) {
  173 + for (ProcurementAssayReportLine line : lines) {
  174 + bo.getLines().add(BeanUtil.copyProperties(line, GetProcurementAssayReportBo.LineBo.class));
  175 + }
  176 + }
  177 +
  178 + return bo;
  179 + }
  180 +
  181 + @Override
  182 + public List<GetAssayReportPlanOptionBo> getPlanOptions(String ticketId) {
  183 + if (StringUtil.isBlank(ticketId)) {
  184 + throw new DefaultClientException("过磅码单不能为空!");
  185 + }
  186 + assertTicketUsable(ticketId);
  187 +
  188 + // 所选码单下的计划编号下拉(同一计划多条过磅明细时取第一条的数据)
  189 + List<GetAssayReportPlanOptionBo> datas = assayReportMapper.queryPlanOptions(ticketId);
  190 + Set<String> planIdSet = new HashSet<>();
  191 + List<GetAssayReportPlanOptionBo> options = new ArrayList<>();
  192 + for (GetAssayReportPlanOptionBo item : datas) {
  193 + if (item != null && StringUtil.isNotBlank(item.getPlanId())
  194 + && planIdSet.add(item.getPlanId())) {
  195 + options.add(item);
  196 + }
  197 + }
  198 + return options;
  199 + }
  200 +
  201 + @Override
  202 + public List<GetAssayReportProductOptionBo> getAssayedProducts(String ticketId, String planId) {
  203 + if (StringUtil.isBlank(ticketId)) {
  204 + throw new DefaultClientException("过磅码单不能为空!");
  205 + }
  206 + if (StringUtil.isBlank(planId)) {
  207 + throw new DefaultClientException("采购计划不能为空!");
  208 + }
  209 + assertTicketUsable(ticketId);
  210 +
  211 + // 所选计划下的过磅品种,已生成原料化验报告单的品种不查出(同一品种多条过磅明细时取第一条的数据)
  212 + List<GetAssayReportProductOptionBo> datas =
  213 + assayReportMapper.queryAssayedProducts(ticketId, planId);
  214 + Set<String> productIdSet = new HashSet<>();
  215 + List<GetAssayReportProductOptionBo> options = new ArrayList<>();
  216 + for (GetAssayReportProductOptionBo item : datas) {
  217 + if (item != null && StringUtil.isNotBlank(item.getProductId())
  218 + && productIdSet.add(item.getProductId())) {
  219 + options.add(item);
  220 + }
  221 + }
  222 + return options;
  223 + }
  224 +
  225 + @Override
  226 + public List<GetAssayReportApplyOptionBo> getAssayApplies(String ticketId, String planId,
  227 + String productId) {
  228 + if (StringUtil.isBlank(ticketId)) {
  229 + throw new DefaultClientException("过磅码单不能为空!");
  230 + }
  231 + if (StringUtil.isBlank(planId)) {
  232 + throw new DefaultClientException("采购计划不能为空!");
  233 + }
  234 + if (StringUtil.isBlank(productId)) {
  235 + throw new DefaultClientException("过磅品种不能为空!");
  236 + }
  237 + assertTicketUsable(ticketId);
  238 +
  239 + // 所选码单+计划+品种下的化验送样单(审核通过且未作废,一条送样单对应报告单一条明细)
  240 + return assayReportMapper.queryAssayApplies(ticketId, planId, productId);
  241 + }
  242 +
  243 + @Override
  244 + @Transactional(rollbackFor = Exception.class)
  245 + @OpLog(type = OtherOpLogType.class, name = "新增原料化验报告单,ID:{}", params = {"#result"})
  246 + public String create(CreateProcurementAssayReportVo vo) {
  247 + ProcurementAssayReport entity = new ProcurementAssayReport();
  248 + entity.setId(IdUtil.getId());
  249 + applyFields(entity, vo.getWeighingTicketId(), vo.getProcurementPlanId(),
  250 + vo.getReportDate(), vo.getProductId(), null);
  251 +
  252 + entity.setApprovalStatus(STATUS_DRAFT);
  253 + // 制单阶段当前节点为工艺科化验员
  254 + entity.setFlowNode(NODE_HGY);
  255 +
  256 + this.save(entity);
  257 + saveLines(entity.getId(), vo.getLines());
  258 +
  259 + OpLogUtil.setVariable("id", entity.getId());
  260 + OpLogUtil.setExtra(entity);
  261 +
  262 + return entity.getId();
  263 + }
  264 +
  265 + @Override
  266 + @Transactional(rollbackFor = Exception.class)
  267 + @OpLog(type = OtherOpLogType.class, name = "修改原料化验报告单,ID:{}", params = {"#vo.id"})
  268 + public void update(UpdateProcurementAssayReportVo vo) {
  269 + Assert.notBlank(vo.getId(), "ID不能为空!");
  270 +
  271 + ProcurementAssayReport oldEntity = this.getById(vo.getId());
  272 + if (oldEntity == null) {
  273 + throw new DefaultClientException("原料化验报告单不存在!");
  274 + }
  275 + // 仅草稿、已驳回可修改;审核中、审核通过、已取消不可修改
  276 + assertEditable(oldEntity);
  277 +
  278 + ProcurementAssayReport entity = new ProcurementAssayReport();
  279 + entity.setId(vo.getId());
  280 + applyFields(entity, vo.getWeighingTicketId(), vo.getProcurementPlanId(),
  281 + vo.getReportDate(), vo.getProductId(), vo.getId());
  282 +
  283 + this.updateById(entity);
  284 +
  285 + // 明细整体重建(质检意见不在修改范围,保留原值)
  286 + reportLineService.deleteByReportId(vo.getId());
  287 + saveLines(vo.getId(), vo.getLines());
  288 +
  289 + OpLogUtil.setVariable("id", entity.getId());
  290 + OpLogUtil.setExtra(entity);
  291 + }
  292 +
  293 + @Override
  294 + @Transactional(rollbackFor = Exception.class)
  295 + @OpLog(type = OtherOpLogType.class, name = "原料质检员填写质检问题,ID:{}", params = {"#vo.id"})
  296 + public void updateQuality(UpdateAssayReportQualityVo vo) {
  297 + Assert.notBlank(vo.getId(), "ID不能为空!");
  298 +
  299 + ProcurementAssayReport entity = this.getById(vo.getId());
  300 + if (entity == null) {
  301 + throw new DefaultClientException("原料化验报告单不存在!");
  302 + }
  303 + // 有质量问题时处理意见必填;无质量问题时清空处理意见
  304 + if (Boolean.TRUE.equals(vo.getHasQualityProblem()) && StringUtil.isBlank(vo.getProcessOpinion())) {
  305 + throw new DefaultClientException("存在质量问题,处理意见不能为空!");
  306 + }
  307 +
  308 + this.update(Wrappers.lambdaUpdate(ProcurementAssayReport.class)
  309 + .set(ProcurementAssayReport::getHasQualityProblem, vo.getHasQualityProblem())
  310 + .set(ProcurementAssayReport::getProcessOpinion,
  311 + Boolean.TRUE.equals(vo.getHasQualityProblem()) ? vo.getProcessOpinion() : null)
  312 + .eq(ProcurementAssayReport::getId, vo.getId()));
  313 +
  314 + OpLogUtil.setVariable("id", vo.getId());
  315 + OpLogUtil.setExtra(entity);
  316 + }
  317 +
  318 + @Override
  319 + @Transactional(rollbackFor = Exception.class)
  320 + @OpLog(type = OtherOpLogType.class, name = "提交原料化验报告单审核,ID:{}", params = {"#id"})
  321 + public void submit(String id) {
  322 + Assert.notBlank(id);
  323 +
  324 + ProcurementAssayReport entity = this.getById(id);
  325 + if (entity == null) {
  326 + throw new DefaultClientException("原料化验报告单不存在!");
  327 + }
  328 + if (!STATUS_DRAFT.equals(entity.getApprovalStatus())
  329 + && !STATUS_REFUSE.equals(entity.getApprovalStatus())) {
  330 + throw new DefaultClientException("当前单据状态不允许提交审核!");
  331 + }
  332 + if (entity.getHasQualityProblem() == null) {
  333 + throw new DefaultClientException("当前单据没有补充是否有质量问题,请先补充完整!");
  334 + }
  335 +
  336 + // 提交前完整性校验(明细在新增时已校验,防历史数据变更后失效)
  337 + long lineCount = reportLineService.count(
  338 + Wrappers.lambdaQuery(ProcurementAssayReportLine.class)
  339 + .eq(ProcurementAssayReportLine::getReportId, id));
  340 + if (lineCount == 0) {
  341 + throw new DefaultClientException("化验明细不能为空!");
  342 + }
  343 +
  344 + this.update(Wrappers.lambdaUpdate(ProcurementAssayReport.class)
  345 + .set(ProcurementAssayReport::getApprovalStatus, STATUS_AUDIT)
  346 + // 提交审核后流程节点推进到仓库主管
  347 + .set(ProcurementAssayReport::getFlowNode, NODE_CKZG)
  348 + .eq(ProcurementAssayReport::getId, id));
  349 +
  350 + flowInstanceWrapperService.startInstance(BPM_FLAG, entity.getId(), BPM_FLAG, entity);
  351 +
  352 + OpLogUtil.setVariable("id", id);
  353 + OpLogUtil.setExtra(entity);
  354 + }
  355 +
  356 + @Override
  357 + @Transactional(rollbackFor = Exception.class)
  358 + @OpLog(type = OtherOpLogType.class, name = "原料化验报告单提交流转,ID:{}", params = {"#id"})
  359 + public void approve(String id) {
  360 + Assert.notBlank(id);
  361 +
  362 + ProcurementAssayReport entity = this.getById(id);
  363 + if (entity == null) {
  364 + throw new DefaultClientException("原料化验报告单不存在!");
  365 + }
  366 +
  367 + this.update(Wrappers.lambdaUpdate(ProcurementAssayReport.class)
  368 + // 提交后流程节点推进到仓库质检员
  369 + .set(ProcurementAssayReport::getFlowNode, NODE_CKZJY)
  370 + .eq(ProcurementAssayReport::getId, id));
  371 +
  372 + OpLogUtil.setVariable("id", id);
  373 + OpLogUtil.setExtra(entity);
  374 + }
  375 +
  376 + @Override
  377 + @Transactional(rollbackFor = Exception.class)
  378 + public void updateNoFlowInstance(Map<String, Object> map) {
  379 + try {
  380 + // 审核状态
  381 + Object examStatusObj = map.get("examStatus");
  382 + String examStatus = examStatusObj == null ? null : String.valueOf(examStatusObj);
  383 +
  384 + // 审核意见
  385 + Object messageObj = map.get("message");
  386 + String message = messageObj == null ? null : String.valueOf(messageObj);
  387 + if ("null".equals(message)) {
  388 + message = null;
  389 + }
  390 +
  391 + // 刚审核完成的环节编码(assay_report_ + 分厂前缀 + 名称缩写)
  392 + Object nodeObj = map.get("nodeCode");
  393 + String nodeCode = nodeObj == null ? null : String.valueOf(nodeObj);
  394 +
  395 + // 业务ID(兼容 variables 子 map 包裹)
  396 + String bizId = resolveBizId(map);
  397 + if (StringUtil.isBlank(bizId)) {
  398 + throw new DefaultClientException("原料化验报告单审核回调缺少业务ID!");
  399 + }
  400 +
  401 + // 各审核环节匹配(nodeCode 尾部名称缩写,兼容分厂前缀 yfc/efc/sfc/ztfc);
  402 + // 第二次供应管理科主管环节(gyglkzg2)只推进节点,不存审核人
  403 + boolean ckzgNode = nodeCode != null && nodeCode.endsWith("fcckzg");
  404 + boolean gyglkzgNode = nodeCode != null && nodeCode.endsWith("gyglkzg");
  405 + boolean gybzgNode = nodeCode != null && nodeCode.endsWith("gybzg");
  406 + boolean fczgNode = nodeCode != null && nodeCode.endsWith("fczg");
  407 + boolean gyglkzg2Node = nodeCode != null && nodeCode.endsWith("gyglkzg2");
  408 + boolean zjlNode = nodeCode != null && nodeCode.endsWith("zjl");
  409 +
  410 + // 无论通过还是拒绝,均回填当前环节审核人与审核意见
  411 + // 审核人
  412 + String userId = SecurityUtil.getCurrentUser().getId();
  413 + String userName = SecurityUtil.getCurrentUser().getName();
  414 +
  415 + // 通过则推进到下一节点;拒绝/撤销/终止统一回到仓库质检员节点
  416 + // (总经理环节通过即流程结束,flow_node 由终态回调一并清空)
  417 + boolean pass = "PASS".equals(examStatus);
  418 + String targetNode = pass ? nextFlowNode(nodeCode) : NODE_CKZJY;
  419 +
  420 + if (!ckzgNode && !gyglkzgNode && !gybzgNode && !fczgNode && !gyglkzg2Node && !zjlNode
  421 + && targetNode == null) {
  422 + // 未匹配到审核环节且无节点推进,忽略
  423 + return;
  424 + }
  425 +
  426 + this.update(Wrappers.lambdaUpdate(ProcurementAssayReport.class)
  427 + .set(ckzgNode, ProcurementAssayReport::getCkzgId, userId)
  428 + .set(ckzgNode, ProcurementAssayReport::getCkzgName, userName)
  429 + .set(ckzgNode, ProcurementAssayReport::getCkzgOpinion, message)
  430 + .set(gyglkzgNode, ProcurementAssayReport::getGyglkzgId, userId)
  431 + .set(gyglkzgNode, ProcurementAssayReport::getGyglkzgName, userName)
  432 + .set(gyglkzgNode, ProcurementAssayReport::getGyglkzgOpinion, message)
  433 + .set(gybzgNode, ProcurementAssayReport::getGybzgId, userId)
  434 + .set(gybzgNode, ProcurementAssayReport::getGybzgName, userName)
  435 + .set(gybzgNode, ProcurementAssayReport::getGybzgOpinion, message)
  436 + .set(fczgNode, ProcurementAssayReport::getFczgId, userId)
  437 + .set(fczgNode, ProcurementAssayReport::getFczgName, userName)
  438 + .set(fczgNode, ProcurementAssayReport::getFczgOpinion, message)
  439 + .set(zjlNode, ProcurementAssayReport::getZjlId, userId)
  440 + .set(zjlNode, ProcurementAssayReport::getZjlName, userName)
  441 + .set(zjlNode, ProcurementAssayReport::getZjlOpinion, message)
  442 + .set(targetNode != null, ProcurementAssayReport::getFlowNode, targetNode)
  443 + .eq(ProcurementAssayReport::getId, bizId));
  444 + } catch (Exception ex) {
  445 + ex.printStackTrace();
  446 + }
  447 + }
  448 +
  449 + /**
  450 + * 从回调参数解析业务ID(兼容 variables 子 map 包裹)
  451 + */
  452 + private String resolveBizId(Map<String, Object> map) {
  453 + Object id = map.get("id");
  454 + String bizId = id == null ? null : String.valueOf(id);
  455 + if (StringUtil.isBlank(bizId) || "null".equals(bizId)) {
  456 + Object bizIdObj = map.get("bizId");
  457 + bizId = bizIdObj == null ? null : String.valueOf(bizIdObj);
  458 + }
  459 + if (StringUtil.isBlank(bizId) || "null".equals(bizId)) {
  460 + Object variables = map.get("variables");
  461 + if (variables instanceof Map) {
  462 + Map<?, ?> variablesMap = (Map<?, ?>) variables;
  463 + Object vId = variablesMap.get("id");
  464 + if (vId == null) {
  465 + vId = variablesMap.get("bizId");
  466 + }
  467 + bizId = vId == null ? null : String.valueOf(vId);
  468 + }
  469 + }
  470 + return bizId;
  471 + }
  472 +
  473 + /**
  474 + * 按刚审核完成的环节编码(nodeCode 尾部名称缩写,兼容分厂前缀 yfc/efc/sfc/ztfc)推进到下一流程节点;
  475 + * 总经理环节通过返回 null(流程结束,flow_node 由终态回调清空)
  476 + */
  477 + private String nextFlowNode(String nodeCode) {
  478 + if (StringUtil.isBlank(nodeCode)) {
  479 + return null;
  480 + }
  481 + if (nodeCode.endsWith("fcckzg")) {
  482 + return NODE_GYGLKZG;
  483 + }
  484 + if (nodeCode.endsWith("gyglkzg")) {
  485 + return NODE_GYBZG;
  486 + }
  487 + if (nodeCode.endsWith("gybzg")) {
  488 + return NODE_FCZG;
  489 + }
  490 + if (nodeCode.endsWith("fczg")) {
  491 + return NODE_GYGLKZG;
  492 + }
  493 + if (nodeCode.endsWith("gyglkzg2")) {
  494 + return NODE_ZJL;
  495 + }
  496 + if (nodeCode.endsWith("zjl")) {
  497 + return null;
  498 + }
  499 + return null;
  500 + }
  501 +
  502 + @Override
  503 + @Transactional(rollbackFor = Exception.class)
  504 + @OpLog(type = OtherOpLogType.class, name = "取消原料化验报告单,ID:{}", params = {"#id"})
  505 + public void cancel(String id) {
  506 + Assert.notBlank(id);
  507 +
  508 + ProcurementAssayReport entity = this.getById(id);
  509 + if (entity == null) {
  510 + throw new DefaultClientException("原料化验报告单不存在!");
  511 + }
  512 +
  513 + this.update(Wrappers.lambdaUpdate(ProcurementAssayReport.class)
  514 + .set(ProcurementAssayReport::getApprovalStatus, STATUS_CANCEL)
  515 + .set(ProcurementAssayReport::getFlowNode, null)
  516 + .eq(ProcurementAssayReport::getId, id));
  517 +
  518 + OpLogUtil.setVariable("id", id);
  519 + OpLogUtil.setExtra(entity);
  520 + }
  521 +
  522 + @Override
  523 + @Transactional(rollbackFor = Exception.class)
  524 + @OpLog(type = OtherOpLogType.class, name = "作废原料化验报告单,ID:{}", params = {"#id"})
  525 + public void delete(String id) {
  526 + Assert.notBlank(id);
  527 +
  528 + ProcurementAssayReport entity = this.getById(id);
  529 + if (entity == null) {
  530 + throw new DefaultClientException("原料化验报告单不存在!");
  531 + }
  532 + //todo 联动结算详情单审核通过不允许作废、不是审核通过的同步作废原料结算详情单
  533 +
  534 + // 手动作废:仅审核通过的报告单可作废
  535 + if (!STATUS_PASS.equals(entity.getApprovalStatus())) {
  536 + throw new DefaultClientException("仅审核通过的原料化验报告单可作废!");
  537 + }
  538 +
  539 + this.update(Wrappers.lambdaUpdate(ProcurementAssayReport.class)
  540 + .set(ProcurementAssayReport::getDeleted, true)
  541 + .eq(ProcurementAssayReport::getId, id));
  542 +
  543 + OpLogUtil.setVariable("id", id);
  544 + OpLogUtil.setExtra(entity);
  545 + }
  546 +
  547 + @Override
  548 + @Transactional(rollbackFor = Exception.class)
  549 + public void deleteByWeighingTicketId(String weighingTicketId) {
  550 + if (StringUtil.isBlank(weighingTicketId)) {
  551 + return;
  552 + }
  553 +
  554 + // 该码单下所有未作废的原料化验报告单,联动作废
  555 + List<ProcurementAssayReport> reports = this.list(
  556 + Wrappers.lambdaQuery(ProcurementAssayReport.class)
  557 + .eq(ProcurementAssayReport::getWeighingTicketId, weighingTicketId)
  558 + .eq(ProcurementAssayReport::getDeleted, false));
  559 + if (CollectionUtil.isEmpty(reports)) {
  560 + return;
  561 + }
  562 +
  563 + for (ProcurementAssayReport report : reports) {
  564 + // 审核中的先终止流程,再作废
  565 + if (STATUS_AUDIT.equals(report.getApprovalStatus())) {
  566 + terminateRunningFlow(report.getId());
  567 + }
  568 + this.update(Wrappers.lambdaUpdate(ProcurementAssayReport.class)
  569 + .set(ProcurementAssayReport::getDeleted, true)
  570 + .set(STATUS_AUDIT.equals(report.getApprovalStatus()),
  571 + ProcurementAssayReport::getApprovalStatus, STATUS_REFUSE)
  572 + .eq(ProcurementAssayReport::getId, report.getId()));
  573 + }
  574 + }
  575 +
  576 + /**
  577 + * 终止单据进行中的审核流程(作废审核中的单据前先终止流程)
  578 + */
  579 + private void terminateRunningFlow(String businessId) {
  580 + List<FlowInstanceWrapper> flowList = flowInstanceWrapperService.getFlowByBusinessIdList(
  581 + Collections.singletonList(businessId));
  582 + if (CollectionUtil.isEmpty(flowList)) {
  583 + return;
  584 + }
  585 + flowList.stream()
  586 + .filter(f -> f != null && f.getId() != null)
  587 + .findFirst()
  588 + .ifPresent(flow -> flowTaskWrapperService.termination(flow.getId()));
  589 + }
  590 +
  591 + @Override
  592 + @Transactional(rollbackFor = Exception.class)
  593 + public void updateApprovalStatus(String id, String approvalStatus) {
  594 + if (StringUtil.isBlank(id) || StringUtil.isBlank(approvalStatus)) {
  595 + throw new DefaultClientException("原料化验报告单ID、审核状态不能为空!");
  596 + }
  597 +
  598 + ProcurementAssayReport entity = this.getById(id);
  599 + if (entity == null) {
  600 + throw new DefaultClientException("原料化验报告单不存在!");
  601 + }
  602 +
  603 + this.update(Wrappers.lambdaUpdate(ProcurementAssayReport.class)
  604 + .set(ProcurementAssayReport::getApprovalStatus, approvalStatus)
  605 + .set(ProcurementAssayReport::getFlowNode, null)
  606 + .eq(ProcurementAssayReport::getId, id));
  607 + }
  608 +
  609 + // ==================== 私有方法 ====================
  610 +
  611 + /**
  612 + * 组装单据字段(新增/修改共用):校验码单、品种合法后回填冗余字段
  613 + */
  614 + private void applyFields(ProcurementAssayReport entity, String weighingTicketId,
  615 + String procurementPlanId, LocalDate reportDate, String productId,
  616 + String excludeReportId) {
  617 + // 1. 校验码单:必须审核通过且已上传签字凭证
  618 + ProcurementWeighingTicket ticket = assertTicketUsable(weighingTicketId);
  619 +
  620 + // 2. 校验计划:必须属于该过磅码单关联的计划
  621 + List<ProcurementWeighingTicketLine> planWeighs = weighLineService
  622 + .getByWeighingTicketId(weighingTicketId).stream()
  623 + .filter(w -> procurementPlanId.equals(w.getProcurementPlanId()))
  624 + .collect(Collectors.toList());
  625 + if (CollectionUtil.isEmpty(planWeighs)) {
  626 + throw new DefaultClientException("所选计划不属于该过磅码单关联的计划!");
  627 + }
  628 +
  629 + // 3. 校验品种:必须化验通过(该码单该计划下存在审核通过的化验送样单)
  630 + Map<String, String> assayedProductNames =
  631 + getAssayedProductNames(weighingTicketId, procurementPlanId);
  632 + if (!assayedProductNames.containsKey(productId)) {
  633 + throw new DefaultClientException("所选品种未化验通过,不能制单!");
  634 + }
  635 +
  636 + // 4. 校验品种未被占用:同一码单同一品种只能生成一张有效报告单
  637 + assertProductNotOccupied(weighingTicketId, productId, excludeReportId);
  638 +
  639 + // 5. 计划编号与品种名称:取该码单+该计划+该品种的第一条过磅明细
  640 + ProcurementWeighingTicketLine firstWeigh = planWeighs.stream()
  641 + .filter(w -> productId.equals(w.getProductId()))
  642 + .findFirst()
  643 + .orElse(null);
  644 + if (firstWeigh == null) {
  645 + throw new DefaultClientException("所选品种不在所选计划的过磅明细中!");
  646 + }
  647 +
  648 + // 6. 回填字段与冗余信息(采购计划以传入值为准)
  649 + entity.setWeighingTicketId(ticket.getId());
  650 + entity.setWeighingTicketCode(ticket.getCode());
  651 + entity.setWorkshopId(ticket.getWorkshopId());
  652 + entity.setWorkshopName(ticket.getWorkshopName());
  653 + entity.setSupplierName(ticket.getSupplierName());
  654 + entity.setProcurementPlanId(procurementPlanId);
  655 + entity.setPlanCode(firstWeigh.getPlanCode());
  656 + entity.setProductId(productId);
  657 + entity.setProductName(assayedProductNames.get(productId));
  658 + entity.setReportDate(reportDate);
  659 + }
  660 +
  661 + /**
  662 + * 品种占用校验:同一码单同一品种只要生成过报告单(无论状态,含已取消)就不能重复生成
  663 + */
  664 + private void assertProductNotOccupied(String weighingTicketId, String productId,
  665 + String excludeReportId) {
  666 + int count = this.count(Wrappers.lambdaQuery(ProcurementAssayReport.class)
  667 + .eq(ProcurementAssayReport::getWeighingTicketId, weighingTicketId)
  668 + .eq(ProcurementAssayReport::getProductId, productId)
  669 + .eq(ProcurementAssayReport::getDeleted, false)
  670 + .ne(excludeReportId != null, ProcurementAssayReport::getId, excludeReportId));
  671 + if (count > 0) {
  672 + throw new DefaultClientException("所选过磅品种已生成过原料化验报告单,不能重复生成!");
  673 + }
  674 + }
  675 +
  676 + /**
  677 + * 保存化验明细:一条送样单对应一条明细(样品/名称取自送样单,数量带出过磅明细,样号按行序从1生成)
  678 + */
  679 + private void saveLines(String reportId, List<AssayReportLineVo> vos) {
  680 + if (CollectionUtil.isEmpty(vos)) {
  681 + throw new DefaultClientException("化验明细不能为空!");
  682 + }
  683 +
  684 + ProcurementAssayReport report = this.getById(reportId);
  685 + String weighingTicketId = report.getWeighingTicketId();
  686 + String procurementPlanId = report.getProcurementPlanId();
  687 + String productId = report.getProductId();
  688 +
  689 + // 该码单该计划该品种审核通过且未作废的送样单:送样单ID -> 送样单(以主表传入计划为准)
  690 + Map<String, ProcurementAssayApply> applyMap = assayApplyMapper.selectList(
  691 + Wrappers.lambdaQuery(ProcurementAssayApply.class)
  692 + .eq(ProcurementAssayApply::getWeighingTicketId, weighingTicketId)
  693 + .eq(ProcurementAssayApply::getProcurementPlanId, procurementPlanId)
  694 + .eq(ProcurementAssayApply::getProductId, productId)
  695 + .eq(ProcurementAssayApply::getApprovalStatus, STATUS_PASS)
  696 + .eq(ProcurementAssayApply::getDeleted, false))
  697 + .stream()
  698 + .filter(a -> a != null && StringUtil.isNotBlank(a.getId()))
  699 + .collect(Collectors.toMap(ProcurementAssayApply::getId, a -> a, (v1, v2) -> v1));
  700 +
  701 + // 该计划该品种过磅明细数量(自动带出,不可修改;同一品种多条过磅明细时取第一条)
  702 + BigDecimal weighQuantity = weighLineService.getByWeighingTicketId(weighingTicketId).stream()
  703 + .filter(w -> procurementPlanId.equals(w.getProcurementPlanId())
  704 + && productId.equals(w.getProductId()) && w.getQuantity() != null)
  705 + .map(ProcurementWeighingTicketLine::getQuantity)
  706 + .findFirst()
  707 + .orElse(BigDecimal.ZERO);
  708 +
  709 + List<ProcurementAssayReportLine> lines = new ArrayList<>(vos.size());
  710 + Set<String> applyIdSet = new HashSet<>();
  711 + int sampleNo = 0;
  712 + for (AssayReportLineVo item : vos) {
  713 + if (item == null || StringUtil.isBlank(item.getAssayApplyId())) {
  714 + continue;
  715 + }
  716 + // 送样单必须属于该码单该品种且审核通过
  717 + ProcurementAssayApply apply = applyMap.get(item.getAssayApplyId());
  718 + if (apply == null) {
  719 + throw new DefaultClientException("明细行对应的化验送样单不存在或不属于该码单该品种(须为审核通过)!");
  720 + }
  721 + // 同一送样单不能重复出现在明细中
  722 + if (!applyIdSet.add(item.getAssayApplyId())) {
  723 + throw new DefaultClientException("明细行存在重复的化验送样单!");
  724 + }
  725 +
  726 + ProcurementAssayReportLine line = BeanUtil.copyProperties(item,
  727 + ProcurementAssayReportLine.class);
  728 + line.setId(IdUtil.getId());
  729 + line.setReportId(reportId);
  730 + line.setAssayApplyId(apply.getId());
  731 + line.setAssayApplyCode(apply.getCode());
  732 + line.setProductId(apply.getProductId());
  733 + line.setProductName(apply.getProductName());
  734 + line.setQuantity(weighQuantity);
  735 + line.setSampleNo(++sampleNo);
  736 + lines.add(line);
  737 + }
  738 +
  739 + if (CollectionUtil.isEmpty(lines)) {
  740 + throw new DefaultClientException("化验明细不能为空!");
  741 + }
  742 + reportLineService.saveBatch(lines);
  743 + }
  744 +
  745 + /**
  746 + * 码单可用校验:审核通过且已上传签字凭证(完成时间不为空)
  747 + */
  748 + private ProcurementWeighingTicket assertTicketUsable(String ticketId) {
  749 + if (StringUtil.isBlank(ticketId)) {
  750 + throw new DefaultClientException("过磅码单不能为空!");
  751 + }
  752 + ProcurementWeighingTicket ticket = weighingTicketMapper.findById(ticketId);
  753 + if (ticket == null) {
  754 + throw new DefaultClientException("过磅码单不存在!");
  755 + }
  756 + if (!STATUS_PASS.equals(ticket.getApprovalStatus())) {
  757 + throw new DefaultClientException("过磅码单必须为审核通过状态,才能制单!");
  758 + }
  759 + if (ticket.getCompleteTime() == null) {
  760 + throw new DefaultClientException("过磅码单未上传签字凭证,不能制单!");
  761 + }
  762 + return ticket;
  763 + }
  764 +
  765 + /**
  766 + * 查询码单下化验通过的品种(存在审核通过且未作废的化验送样单的品种):productId -> 品种名称
  767 + */
  768 + private Map<String, String> getAssayedProductNames(String weighingTicketId,
  769 + String procurementPlanId) {
  770 + List<ProcurementAssayApply> applies = assayApplyMapper.selectList(
  771 + Wrappers.lambdaQuery(ProcurementAssayApply.class)
  772 + .eq(ProcurementAssayApply::getWeighingTicketId, weighingTicketId)
  773 + .eq(ProcurementAssayApply::getProcurementPlanId, procurementPlanId)
  774 + .eq(ProcurementAssayApply::getApprovalStatus, STATUS_PASS)
  775 + .eq(ProcurementAssayApply::getDeleted, false));
  776 + Map<String, String> result = new LinkedHashMap<>();
  777 + if (CollectionUtil.isEmpty(applies)) {
  778 + return result;
  779 + }
  780 + for (ProcurementAssayApply apply : applies) {
  781 + if (apply != null && StringUtil.isNotBlank(apply.getProductId())) {
  782 + result.putIfAbsent(apply.getProductId(), apply.getProductName());
  783 + }
  784 + }
  785 + return result;
  786 + }
  787 +
  788 + /**
  789 + * 编辑校验:仅草稿、已驳回可修改
  790 + */
  791 + private void assertEditable(ProcurementAssayReport entity) {
  792 + if (!STATUS_DRAFT.equals(entity.getApprovalStatus())
  793 + && !STATUS_REFUSE.equals(entity.getApprovalStatus())) {
  794 + throw new DefaultClientException("当前单据状态不允许修改!");
  795 + }
  796 + }
  797 +
  798 + /**
  799 + * 审核按钮标记:待办驱动(列表 + 详情两条返回路径都要调用)
  800 + */
  801 + private void fillOperateFlags(List<ProcurementAssayReport> datas) {
  802 + if (CollectionUtil.isEmpty(datas)) {
  803 + return;
  804 + }
  805 +
  806 + List<String> businessIds = datas.stream()
  807 + .filter(Objects::nonNull)
  808 + .map(ProcurementAssayReport::getId)
  809 + .collect(Collectors.toList());
  810 +
  811 + List<FlowInstanceWrapper> flowList = flowInstanceWrapperService.getFlowByBusinessIdList(businessIds);
  812 + Set<String> flowBusinessIdSet = CollectionUtil.isNotEmpty(flowList)
  813 + ? flowList.stream().map(FlowInstanceWrapper::getBusinessId).collect(Collectors.toSet())
  814 + : new HashSet<>();
  815 +
  816 + List<FlowTaskDto> todoFlowTaskList = flowTaskWrapperMapper.queryTodoList(
  817 + new QueryTodoTaskListVo(), SecurityUtil.getCurrentUser().getId());
  818 + Set<String> todoBusinessIdSet = CollectionUtil.isNotEmpty(todoFlowTaskList)
  819 + ? todoFlowTaskList.stream().map(FlowTaskDto::getBusinessId).collect(Collectors.toSet())
  820 + : new HashSet<>();
  821 +
  822 + for (ProcurementAssayReport data : datas) {
  823 + if (data == null) {
  824 + continue;
  825 + }
  826 + boolean hasFlow = flowBusinessIdSet.contains(data.getId());
  827 + boolean hasTodo = todoBusinessIdSet.contains(data.getId());
  828 + data.setShowExamine(hasTodo && STATUS_AUDIT.equals(data.getApprovalStatus()));
  829 + data.setShowExamineDetail(hasFlow && StringUtil.isNotBlank(data.getApprovalStatus()));
  830 + }
  831 + }
  832 +}
... ...
... ... @@ -39,6 +39,7 @@ import com.lframework.xingyun.sc.procurement.mappers.weighing.ProcurementWeighin
39 39 import com.lframework.xingyun.sc.procurement.service.plan.ProcurementPlanLineService;
40 40 import com.lframework.xingyun.sc.procurement.service.plan.ProcurementPlanService;
41 41 import com.lframework.xingyun.sc.procurement.service.weighing.ProcurementAssayApplyService;
  42 +import com.lframework.xingyun.sc.procurement.service.weighing.ProcurementAssayReportService;
42 43 import com.lframework.xingyun.sc.procurement.service.weighing.ProcurementWeighingTicketApplyLineService;
43 44 import com.lframework.xingyun.sc.procurement.service.weighing.ProcurementWeighingTicketLineService;
44 45 import com.lframework.xingyun.sc.procurement.service.weighing.ProcurementWeighingTicketPlanService;
... ... @@ -114,6 +115,8 @@ public class ProcurementWeighingTicketServiceImpl
114 115 private FlowTaskWrapperMapper flowTaskWrapperMapper;
115 116 @Resource
116 117 private ProcurementAssayApplyService assayApplyService;
  118 + @Resource
  119 + private ProcurementAssayReportService assayReportService;
117 120
118 121 @Override
119 122 public PageResult<ProcurementWeighingTicket> query(Integer pageIndex, Integer pageSize,
... ... @@ -558,6 +561,9 @@ public class ProcurementWeighingTicketServiceImpl
558 561 // 联动作废该码单关联的化验送样单(审核中的先终止流程再作废)
559 562 assayApplyService.deleteByWeighingTicketId(id);
560 563
  564 + // 联动作废该码单关联的原料化验报告单(审核中的先终止流程再作废)
  565 + assayReportService.deleteByWeighingTicketId(id);
  566 +
561 567 OpLogUtil.setVariable("id", id);
562 568 OpLogUtil.setExtra(entity);
563 569 }
... ...
  1 +package com.lframework.xingyun.sc.procurement.mappers.weighing;
  2 +
  3 +import com.lframework.starter.web.core.mapper.BaseMapper;
  4 +import com.lframework.xingyun.sc.procurement.entity.weighing.ProcurementAssayReportLine;
  5 +
  6 +public interface ProcurementAssayReportLineMapper
  7 + extends BaseMapper<ProcurementAssayReportLine> {
  8 +
  9 +}
... ...
  1 +package com.lframework.xingyun.sc.procurement.mappers.weighing;
  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.GetAssayReportApplyOptionBo;
  8 +import com.lframework.xingyun.sc.bo.procurement.GetAssayReportPlanOptionBo;
  9 +import com.lframework.xingyun.sc.bo.procurement.GetAssayReportProductOptionBo;
  10 +import com.lframework.xingyun.sc.bo.procurement.GetAssaySelectableTicketBo;
  11 +import com.lframework.xingyun.sc.procurement.entity.weighing.ProcurementAssayReport;
  12 +import com.lframework.xingyun.sc.procurement.vo.weighing.QueryAssaySelectableTicketVo;
  13 +import com.lframework.xingyun.sc.procurement.vo.weighing.QueryProcurementAssayReportVo;
  14 +
  15 +import java.util.List;
  16 +
  17 +import org.apache.ibatis.annotations.Param;
  18 +
  19 +public interface ProcurementAssayReportMapper extends BaseMapper<ProcurementAssayReport> {
  20 +
  21 + @DataPermissions(type = OrderDataPermissionDataPermissionType.class, value = {
  22 + @DataPermission(template = "order", alias = "tb")
  23 + })
  24 + List<ProcurementAssayReport> query(@Param("vo") QueryProcurementAssayReportVo vo);
  25 +
  26 + /**
  27 + * 分页查询可制单的过磅码单(审核通过 + 已上传签字凭证 + 码单下每个过磅品种都有化验送样单且全部审核通过,选择码单弹窗)
  28 + */
  29 + @DataPermissions(type = OrderDataPermissionDataPermissionType.class, value = {
  30 + @DataPermission(template = "order", alias = "tb")
  31 + })
  32 + List<GetAssaySelectableTicketBo> querySelectableTickets(
  33 + @Param("vo") QueryAssaySelectableTicketVo vo);
  34 +
  35 + /**
  36 + * 新增页:所选码单下的计划编号下拉(同一计划多行时由 Service 去重)
  37 + */
  38 + List<GetAssayReportPlanOptionBo> queryPlanOptions(@Param("ticketId") String ticketId);
  39 +
  40 + /**
  41 + * 新增页级联第三步:所选计划下的过磅品种下拉(已生成原料化验报告单的品种不查出,含过磅数量,同一品种多行时由 Service 去重)
  42 + */
  43 + List<GetAssayReportProductOptionBo> queryAssayedProducts(@Param("ticketId") String ticketId,
  44 + @Param("planId") String planId);
  45 +
  46 + /**
  47 + * 新增页级联第四步:所选码单+计划+品种下的化验送样单列表(一条送样单对应报告单一条明细)
  48 + */
  49 + List<GetAssayReportApplyOptionBo> queryAssayApplies(@Param("ticketId") String ticketId,
  50 + @Param("planId") String planId, @Param("productId") String productId);
  51 +}
... ...
  1 +package com.lframework.xingyun.sc.procurement.service.weighing;
  2 +
  3 +import com.lframework.starter.web.core.service.BaseMpService;
  4 +import com.lframework.xingyun.sc.procurement.entity.weighing.ProcurementAssayReportLine;
  5 +import java.util.List;
  6 +
  7 +/**
  8 + * 原料化验报告单明细
  9 + */
  10 +public interface ProcurementAssayReportLineService
  11 + extends BaseMpService<ProcurementAssayReportLine> {
  12 +
  13 + /**
  14 + * 按报告单ID查询明细(样号升序)
  15 + */
  16 + List<ProcurementAssayReportLine> getByReportId(String reportId);
  17 +
  18 + /**
  19 + * 按报告单ID删除明细(修改重建用)
  20 + */
  21 + void deleteByReportId(String reportId);
  22 +}
... ...
  1 +package com.lframework.xingyun.sc.procurement.service.weighing;
  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.GetAssaySelectableTicketBo;
  6 +import com.lframework.xingyun.sc.bo.procurement.GetAssayReportApplyOptionBo;
  7 +import com.lframework.xingyun.sc.bo.procurement.GetAssayReportPlanOptionBo;
  8 +import com.lframework.xingyun.sc.bo.procurement.GetAssayReportProductOptionBo;
  9 +import com.lframework.xingyun.sc.bo.procurement.GetProcurementAssayReportBo;
  10 +import com.lframework.xingyun.sc.procurement.entity.weighing.ProcurementAssayReport;
  11 +import com.lframework.xingyun.sc.procurement.vo.weighing.CreateProcurementAssayReportVo;
  12 +import com.lframework.xingyun.sc.procurement.vo.weighing.QueryAssaySelectableTicketVo;
  13 +import com.lframework.xingyun.sc.procurement.vo.weighing.QueryProcurementAssayReportVo;
  14 +import com.lframework.xingyun.sc.procurement.vo.weighing.UpdateAssayReportQualityVo;
  15 +import com.lframework.xingyun.sc.procurement.vo.weighing.UpdateProcurementAssayReportVo;
  16 +import java.util.List;
  17 +import java.util.Map;
  18 +
  19 +/**
  20 + * 原料化验报告单
  21 + */
  22 +public interface ProcurementAssayReportService extends BaseMpService<ProcurementAssayReport> {
  23 +
  24 + /**
  25 + * 分页查询原料化验报告单列表
  26 + */
  27 + PageResult<ProcurementAssayReport> query(Integer pageIndex, Integer pageSize,
  28 + QueryProcurementAssayReportVo vo);
  29 +
  30 + /**
  31 + * 分页查询可制单的过磅码单(审核通过 + 已上传签字凭证 + 码单下每个过磅品种都有化验送样单且全部审核通过,选择码单弹窗)
  32 + */
  33 + PageResult<GetAssaySelectableTicketBo> querySelectableTickets(Integer pageIndex,
  34 + Integer pageSize, QueryAssaySelectableTicketVo vo);
  35 +
  36 + /**
  37 + * 查询原料化验报告单详情(含化验明细)
  38 + */
  39 + GetProcurementAssayReportBo findDetail(String id);
  40 +
  41 + /**
  42 + * 新增页级联第二步:所选码单下的计划编号下拉
  43 + */
  44 + List<GetAssayReportPlanOptionBo> getPlanOptions(String ticketId);
  45 +
  46 + /**
  47 + * 新增页级联第三步:所选计划下的过磅品种下拉(已生成原料化验报告单的品种不查出,含过磅数量)
  48 + */
  49 + List<GetAssayReportProductOptionBo> getAssayedProducts(String ticketId, String planId);
  50 +
  51 + /**
  52 + * 新增页级联第四步:所选码单+计划+品种下的化验送样单列表(一条送样单对应报告单一条明细,带编号)
  53 + */
  54 + List<GetAssayReportApplyOptionBo> getAssayApplies(String ticketId, String planId,
  55 + String productId);
  56 +
  57 + /**
  58 + * 新增原料化验报告单(草稿,分厂工艺科化验员;一单关联一个码单、一个品种,一条送样单对应一条明细,品种不能重复生成)
  59 + */
  60 + String create(CreateProcurementAssayReportVo vo);
  61 +
  62 + /**
  63 + * 修改原料化验报告单(仅草稿、已驳回可修改;质检意见不受修改影响)
  64 + */
  65 + void update(UpdateProcurementAssayReportVo vo);
  66 +
  67 + /**
  68 + * 原料质检员填写质检问题(审核中可填写;有质量问题时处理意见必填)
  69 + */
  70 + void updateQuality(UpdateAssayReportQualityVo vo);
  71 +
  72 + /**
  73 + * 提交原料化验报告单审核(草稿、已驳回可提交)
  74 + */
  75 + void submit(String id);
  76 +
  77 + /**
  78 + * 提交流转(流程节点推进到下一环节)
  79 + */
  80 + void approve(String id);
  81 +
  82 + /**
  83 + * BPM 流程审批回调(无流程实例模式,由 FlowTaskService 分发),更新流程节点:
  84 + * PASS-按 nodeCode 推进到下一环节;拒绝/撤销/终止-统一回到仓库质检员节点。
  85 + * 审核节点编码:assay_report_ + 分厂前缀(有分厂时 yfc/efc/sfc/ztfc) + 名称缩写,
  86 + * 如 assay_report_yfcckzg、assay_report_efcckzg、assay_report_gyglkzg
  87 + *
  88 + * @param map 回调参数 nodeCode/examStatus/id(bizId),兼容 variables 子 map 包裹
  89 + */
  90 + void updateNoFlowInstance(Map<String, Object> map);
  91 +
  92 + /**
  93 + * 取消原料化验报告单(已驳回状态可取消,取消后只能查看)
  94 + */
  95 + void cancel(String id);
  96 +
  97 + /**
  98 + * 作废原料化验报告单(仅审核通过的报告单可手动作废,作废后只能查看)
  99 + */
  100 + void delete(String id);
  101 +
  102 + /**
  103 + * 按过磅码单作废原料化验报告单(码单作废联动,审核中的先终止流程再作废)
  104 + *
  105 + * @param weighingTicketId 过磅码单ID
  106 + */
  107 + void deleteByWeighingTicketId(String weighingTicketId);
  108 +
  109 + /**
  110 + * 审核流程回调更新审核状态(流程结束时由 BusinessDataHandlerService 调用)
  111 + *
  112 + * @param id 原料化验报告单ID
  113 + * @param approvalStatus 审核结果 PASS/REFUSE
  114 + */
  115 + void updateApprovalStatus(String id, String approvalStatus);
  116 +}
... ...
  1 +package com.lframework.xingyun.sc.procurement.vo.weighing;
  2 +
  3 +import io.swagger.annotations.ApiModelProperty;
  4 +import java.math.BigDecimal;
  5 +import javax.validation.constraints.NotBlank;
  6 +import lombok.Data;
  7 +
  8 +/**
  9 + * 原料化验报告单明细行(一条送样单对应一条明细;样品、数量、样号由后端按送样单自动带出,前端只填成分字段)
  10 + */
  11 +@Data
  12 +public class AssayReportLineVo {
  13 +
  14 + @ApiModelProperty(value = "化验送样单ID(对应报告单一条明细)", required = true)
  15 + @NotBlank(message = "化验送样单不能为空!")
  16 + private String assayApplyId;
  17 +
  18 + @ApiModelProperty("Cu 成分%")
  19 + private BigDecimal cu;
  20 +
  21 + @ApiModelProperty("Zn 成分%")
  22 + private BigDecimal zn;
  23 +
  24 + @ApiModelProperty("Pb 成分%")
  25 + private BigDecimal pb;
  26 +
  27 + @ApiModelProperty("Fe 成分%")
  28 + private BigDecimal fe;
  29 +
  30 + @ApiModelProperty("P 成分%")
  31 + private BigDecimal p;
  32 +
  33 + @ApiModelProperty("Sn 成分%")
  34 + private BigDecimal sn;
  35 +
  36 + @ApiModelProperty("Ni 成分%")
  37 + private BigDecimal ni;
  38 +
  39 + @ApiModelProperty("Al 成分%")
  40 + private BigDecimal al;
  41 +
  42 + @ApiModelProperty("Cd 成分%")
  43 + private BigDecimal cd;
  44 +
  45 + @ApiModelProperty("Cr6+ 成分%")
  46 + private BigDecimal cr6;
  47 +
  48 + @ApiModelProperty("Hg 成分%")
  49 + private BigDecimal hg;
  50 +
  51 + @ApiModelProperty("Bi 成分%")
  52 + private BigDecimal bi;
  53 +}
... ...
  1 +package com.lframework.xingyun.sc.procurement.vo.weighing;
  2 +
  3 +import com.fasterxml.jackson.annotation.JsonFormat;
  4 +import com.lframework.starter.common.constants.StringPool;
  5 +import io.swagger.annotations.ApiModelProperty;
  6 +import java.time.LocalDate;
  7 +import java.util.List;
  8 +import javax.validation.Valid;
  9 +import javax.validation.constraints.NotBlank;
  10 +import javax.validation.constraints.NotEmpty;
  11 +import javax.validation.constraints.NotNull;
  12 +import lombok.Data;
  13 +
  14 +@Data
  15 +public class CreateProcurementAssayReportVo {
  16 +
  17 + @ApiModelProperty(value = "过磅码单ID(单选,须为审核通过且已上传签字凭证的码单)", required = true)
  18 + @NotBlank(message = "过磅码单不能为空!")
  19 + private String weighingTicketId;
  20 +
  21 + @ApiModelProperty(value = "制单日期", required = true)
  22 + @JsonFormat(pattern = StringPool.DATE_PATTERN)
  23 + @NotNull(message = "制单日期不能为空!")
  24 + private LocalDate reportDate;
  25 +
  26 + @ApiModelProperty(value = "采购计划ID(单选,范围为码单关联计划)", required = true)
  27 + @NotBlank(message = "采购计划不能为空!")
  28 + private String procurementPlanId;
  29 +
  30 + @ApiModelProperty(value = "过磅品种ID(品种关系表ID,单选,范围为所选计划的过磅明细品种)", required = true)
  31 + @NotBlank(message = "品种不能为空!")
  32 + private String productId;
  33 +
  34 + @ApiModelProperty(value = "化验明细(一条送样单对应一条明细,样品/数量/样号自动带出)", required = true)
  35 + @Valid
  36 + @NotEmpty(message = "化验明细不能为空!")
  37 + private List<AssayReportLineVo> lines;
  38 +}
... ...
  1 +package com.lframework.xingyun.sc.procurement.vo.weighing;
  2 +
  3 +import com.fasterxml.jackson.annotation.JsonFormat;
  4 +import com.lframework.starter.common.constants.StringPool;
  5 +import com.lframework.starter.web.core.vo.SortPageVo;
  6 +import io.swagger.annotations.ApiModel;
  7 +import io.swagger.annotations.ApiModelProperty;
  8 +import lombok.Data;
  9 +
  10 +import java.io.Serializable;
  11 +import java.time.LocalDate;
  12 +import java.time.LocalDateTime;
  13 +import java.util.List;
  14 +
  15 +@Data
  16 +@ApiModel("查询原料化验报告单")
  17 +public class QueryProcurementAssayReportVo 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 reportDateStart;
  27 +
  28 + @ApiModelProperty("制单日期-结束")
  29 + @JsonFormat(pattern = StringPool.DATE_PATTERN)
  30 + private LocalDate reportDateEnd;
  31 +
  32 + @ApiModelProperty("客户名称(模糊匹配)")
  33 + private String supplierName;
  34 +
  35 + @ApiModelProperty("分厂ID")
  36 + private String workshopId;
  37 +
  38 + @ApiModelProperty("审核状态 DRAFT/AUDIT/PASS/REFUSE/CANCEL")
  39 + private String approvalStatus;
  40 +
  41 + @ApiModelProperty("流程节点")
  42 + private String flowNode;
  43 +
  44 + @ApiModelProperty("是否作废 true-已作废 false-有效单(不传默认查有效单)")
  45 + private Boolean deleted;
  46 +
  47 + @ApiModelProperty("创建人(模糊匹配)")
  48 + private String createBy;
  49 +
  50 + @ApiModelProperty("创建时间-开始")
  51 + @JsonFormat(pattern = StringPool.DATE_TIME_PATTERN)
  52 + private LocalDateTime startTime;
  53 +
  54 + @ApiModelProperty("创建时间-结束")
  55 + @JsonFormat(pattern = StringPool.DATE_TIME_PATTERN)
  56 + private LocalDateTime endTime;
  57 +
  58 + @ApiModelProperty("创建人ID集合(数据权限用,后端注入)")
  59 + private List<String> createByIdList;
  60 +}
... ...
  1 +package com.lframework.xingyun.sc.procurement.vo.weighing;
  2 +
  3 +import io.swagger.annotations.ApiModelProperty;
  4 +import javax.validation.constraints.NotBlank;
  5 +import javax.validation.constraints.NotNull;
  6 +import lombok.Data;
  7 +
  8 +/**
  9 + * 原料质检员填写质检问题(审核中可填写)
  10 + */
  11 +@Data
  12 +public class UpdateAssayReportQualityVo {
  13 +
  14 + @ApiModelProperty(value = "ID", required = true)
  15 + @NotBlank(message = "ID不能为空!")
  16 + private String id;
  17 +
  18 + @ApiModelProperty(value = "是否有质量问题", required = true)
  19 + @NotNull(message = "是否有质量问题不能为空!")
  20 + private Boolean hasQualityProblem;
  21 +
  22 + @ApiModelProperty("处理意见(有质量问题时必填)")
  23 + private String processOpinion;
  24 +}
... ...
  1 +package com.lframework.xingyun.sc.procurement.vo.weighing;
  2 +
  3 +import com.fasterxml.jackson.annotation.JsonFormat;
  4 +import com.lframework.starter.common.constants.StringPool;
  5 +import io.swagger.annotations.ApiModelProperty;
  6 +import java.time.LocalDate;
  7 +import java.util.List;
  8 +import javax.validation.Valid;
  9 +import javax.validation.constraints.NotBlank;
  10 +import javax.validation.constraints.NotEmpty;
  11 +import javax.validation.constraints.NotNull;
  12 +import lombok.Data;
  13 +
  14 +@Data
  15 +public class UpdateProcurementAssayReportVo {
  16 +
  17 + @ApiModelProperty(value = "ID", required = true)
  18 + @NotBlank(message = "ID不能为空!")
  19 + private String id;
  20 +
  21 + @ApiModelProperty(value = "过磅码单ID(单选,须为审核通过且已上传签字凭证的码单)", required = true)
  22 + @NotBlank(message = "过磅码单不能为空!")
  23 + private String weighingTicketId;
  24 +
  25 + @ApiModelProperty(value = "制单日期", required = true)
  26 + @JsonFormat(pattern = StringPool.DATE_PATTERN)
  27 + @NotNull(message = "制单日期不能为空!")
  28 + private LocalDate reportDate;
  29 +
  30 + @ApiModelProperty(value = "采购计划ID(单选,范围为码单关联计划)", required = true)
  31 + @NotBlank(message = "采购计划不能为空!")
  32 + private String procurementPlanId;
  33 +
  34 + @ApiModelProperty(value = "过磅品种ID(品种关系表ID,单选,范围为所选计划的过磅明细品种)", required = true)
  35 + @NotBlank(message = "品种不能为空!")
  36 + private String productId;
  37 +
  38 + @ApiModelProperty(value = "化验明细(一条送样单对应一条明细,样品/数量/样号自动带出)", required = true)
  39 + @Valid
  40 + @NotEmpty(message = "化验明细不能为空!")
  41 + private List<AssayReportLineVo> lines;
  42 +}
... ...
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3 +<mapper namespace="com.lframework.xingyun.sc.procurement.mappers.weighing.ProcurementAssayReportMapper">
  4 +
  5 + <resultMap id="ProcurementAssayReportResult" type="com.lframework.xingyun.sc.procurement.entity.weighing.ProcurementAssayReport">
  6 + <id column="id" property="id"/>
  7 + <result column="weighing_ticket_id" property="weighingTicketId"/>
  8 + <result column="weighing_ticket_code" property="weighingTicketCode"/>
  9 + <result column="workshop_id" property="workshopId"/>
  10 + <result column="workshop_name" property="workshopName"/>
  11 + <result column="supplier_name" property="supplierName"/>
  12 + <result column="procurement_plan_id" property="procurementPlanId"/>
  13 + <result column="plan_code" property="planCode"/>
  14 + <result column="product_id" property="productId"/>
  15 + <result column="product_name" property="productName"/>
  16 + <result column="report_date" property="reportDate"/>
  17 + <result column="has_quality_problem" property="hasQualityProblem"/>
  18 + <result column="process_opinion" property="processOpinion"/>
  19 + <result column="continue_approval" property="continueApproval"/>
  20 + <result column="ckzg_id" property="ckzgId"/>
  21 + <result column="ckzg_name" property="ckzgName"/>
  22 + <result column="ckzg_opinion" property="ckzgOpinion"/>
  23 + <result column="gyglkzg_id" property="gyglkzgId"/>
  24 + <result column="gyglkzg_name" property="gyglkzgName"/>
  25 + <result column="gyglkzg_opinion" property="gyglkzgOpinion"/>
  26 + <result column="gybzg_id" property="gybzgId"/>
  27 + <result column="gybzg_name" property="gybzgName"/>
  28 + <result column="gybzg_opinion" property="gybzgOpinion"/>
  29 + <result column="fczg_id" property="fczgId"/>
  30 + <result column="fczg_name" property="fczgName"/>
  31 + <result column="fczg_opinion" property="fczgOpinion"/>
  32 + <result column="zjl_id" property="zjlId"/>
  33 + <result column="zjl_name" property="zjlName"/>
  34 + <result column="zjl_opinion" property="zjlOpinion"/>
  35 + <result column="flow_node" property="flowNode"/>
  36 + <result column="approval_status" property="approvalStatus"/>
  37 + <result column="create_by_id" property="createById"/>
  38 + <result column="create_by" property="createBy"/>
  39 + <result column="update_by_id" property="updateById"/>
  40 + <result column="update_by" property="updateBy"/>
  41 + <result column="create_time" property="createTime"/>
  42 + <result column="update_time" property="updateTime"/>
  43 + </resultMap>
  44 +
  45 + <sql id="PAR_sql">
  46 + SELECT
  47 + tb.id,
  48 + tb.weighing_ticket_id,
  49 + tb.weighing_ticket_code,
  50 + tb.workshop_id,
  51 + tb.workshop_name,
  52 + tb.supplier_name,
  53 + tb.procurement_plan_id,
  54 + tb.plan_code,
  55 + tb.product_id,
  56 + tb.product_name,
  57 + tb.report_date,
  58 + tb.has_quality_problem,
  59 + tb.process_opinion,
  60 + tb.continue_approval,
  61 + tb.ckzg_id,
  62 + tb.ckzg_name,
  63 + tb.ckzg_opinion,
  64 + tb.gyglkzg_id,
  65 + tb.gyglkzg_name,
  66 + tb.gyglkzg_opinion,
  67 + tb.gybzg_id,
  68 + tb.gybzg_name,
  69 + tb.gybzg_opinion,
  70 + tb.fczg_id,
  71 + tb.fczg_name,
  72 + tb.fczg_opinion,
  73 + tb.zjl_id,
  74 + tb.zjl_name,
  75 + tb.zjl_opinion,
  76 + tb.flow_node,
  77 + tb.approval_status,
  78 + tb.create_by_id,
  79 + tb.create_by,
  80 + tb.update_by_id,
  81 + tb.update_by,
  82 + tb.create_time,
  83 + tb.update_time
  84 + FROM procurement_assay_report AS tb
  85 + </sql>
  86 +
  87 + <select id="query" resultMap="ProcurementAssayReportResult">
  88 + <include refid="PAR_sql"/>
  89 + <where>
  90 + <choose>
  91 + <when test="vo.deleted != null">
  92 + tb.deleted = #{vo.deleted}
  93 + </when>
  94 + <otherwise>
  95 + tb.deleted = 0
  96 + </otherwise>
  97 + </choose>
  98 + <if test="vo.weighingTicketCode != null and vo.weighingTicketCode != ''">
  99 + AND tb.weighing_ticket_code LIKE CONCAT('%', #{vo.weighingTicketCode}, '%')
  100 + </if>
  101 + <if test="vo.reportDateStart != null">
  102 + AND tb.report_date &gt;= #{vo.reportDateStart}
  103 + </if>
  104 + <if test="vo.reportDateEnd != null">
  105 + AND tb.report_date &lt;= #{vo.reportDateEnd}
  106 + </if>
  107 + <if test="vo.supplierName != null and vo.supplierName != ''">
  108 + AND tb.supplier_name LIKE CONCAT('%', #{vo.supplierName}, '%')
  109 + </if>
  110 + <if test="vo.workshopId != null and vo.workshopId != ''">
  111 + AND tb.workshop_id = #{vo.workshopId}
  112 + </if>
  113 + <if test="vo.approvalStatus != null and vo.approvalStatus != ''">
  114 + AND tb.approval_status = #{vo.approvalStatus}
  115 + </if>
  116 + <if test="vo.flowNode != null and vo.flowNode != ''">
  117 + AND tb.flow_node = #{vo.flowNode}
  118 + </if>
  119 + <if test="vo.createBy != null and vo.createBy != ''">
  120 + AND tb.create_by LIKE CONCAT('%', #{vo.createBy}, '%')
  121 + </if>
  122 + <if test="vo.startTime != null">
  123 + AND tb.create_time &gt;= #{vo.startTime}
  124 + </if>
  125 + <if test="vo.endTime != null">
  126 + AND tb.create_time &lt;= #{vo.endTime}
  127 + </if>
  128 + <if test="vo.createByIdList != null and vo.createByIdList.size() > 0">
  129 + AND tb.create_by_id IN
  130 + <foreach collection="vo.createByIdList" item="item" open="(" separator="," close=")">
  131 + #{item}
  132 + </foreach>
  133 + </if>
  134 + </where>
  135 + ORDER BY tb.create_time DESC
  136 + </select>
  137 +
  138 + <resultMap id="AssayReportSelectableTicketResult" type="com.lframework.xingyun.sc.bo.procurement.GetAssaySelectableTicketBo">
  139 + <id column="id" property="id"/>
  140 + <result column="code" property="code"/>
  141 + <result column="supplier_name" property="supplierName"/>
  142 + <result column="workshop_id" property="workshopId"/>
  143 + <result column="workshop_name" property="workshopName"/>
  144 + <result column="complete_time" property="completeTime"/>
  145 + <result column="create_by" property="createBy"/>
  146 + </resultMap>
  147 +
  148 + <!-- 原料化验报告制单选择码单弹窗:审核通过 + 已上传签字凭证 + 码单下每个过磅品种都有化验送样单且全部审核通过 -->
  149 + <select id="querySelectableTickets" resultMap="AssayReportSelectableTicketResult">
  150 + SELECT
  151 + tb.id,
  152 + tb.code,
  153 + tb.supplier_name,
  154 + tb.workshop_id,
  155 + tb.workshop_name,
  156 + tb.complete_time,
  157 + tb.create_by
  158 + FROM procurement_weighing_ticket AS tb
  159 + WHERE tb.deleted = 0
  160 + AND tb.approval_status = 'PASS'
  161 + AND tb.complete_time IS NOT NULL
  162 + <!-- 不存在未审核通过的送样单(已取消的送样单不影响制单;每个品种的送样单必须全部审核通过) -->
  163 + AND NOT EXISTS (
  164 + SELECT 1 FROM procurement_assay_apply aa
  165 + WHERE aa.weighing_ticket_id = tb.id
  166 + AND aa.deleted = 0
  167 + AND aa.approval_status NOT IN ('PASS', 'CANCEL')
  168 + )
  169 + <!-- 不存在没有有效送样单的过磅品种(每个品种都有化验:存在非取消、未作废的送样单) -->
  170 + AND NOT EXISTS (
  171 + SELECT 1 FROM procurement_weighing_ticket_line pwtl
  172 + WHERE pwtl.weighing_ticket_id = tb.id
  173 + AND pwtl.product_id IS NOT NULL
  174 + AND NOT EXISTS (
  175 + SELECT 1 FROM procurement_assay_apply aa
  176 + WHERE aa.weighing_ticket_id = tb.id
  177 + AND aa.product_id = pwtl.product_id
  178 + AND aa.deleted = 0
  179 + AND aa.approval_status != 'CANCEL'
  180 + )
  181 + )
  182 + <if test="vo.code != null and vo.code != ''">
  183 + AND tb.code LIKE CONCAT('%', #{vo.code}, '%')
  184 + </if>
  185 + <if test="vo.workshopId != null and vo.workshopId != ''">
  186 + AND tb.workshop_id = #{vo.workshopId}
  187 + </if>
  188 + ORDER BY tb.complete_time DESC, tb.create_time DESC
  189 + </select>
  190 +
  191 + <resultMap id="AssayReportProductOptionResult" type="com.lframework.xingyun.sc.bo.procurement.GetAssayReportProductOptionBo">
  192 + <id column="product_id" property="productId"/>
  193 + <result column="product_name" property="productName"/>
  194 + <result column="plan_id" property="planId"/>
  195 + <result column="plan_code" property="planCode"/>
  196 + <result column="quantity" property="quantity"/>
  197 + </resultMap>
  198 +
  199 + <resultMap id="AssayReportPlanOptionResult" type="com.lframework.xingyun.sc.bo.procurement.GetAssayReportPlanOptionBo">
  200 + <id column="plan_id" property="planId"/>
  201 + <result column="plan_code" property="planCode"/>
  202 + </resultMap>
  203 +
  204 + <!-- 新增页级联第二步:所选码单下的计划编号下拉(同一计划多条过磅明细时由 Service 按 planId 去重取第一条) -->
  205 + <select id="queryPlanOptions" resultMap="AssayReportPlanOptionResult">
  206 + SELECT
  207 + pwtl.procurement_plan_id AS plan_id,
  208 + pwtl.plan_code
  209 + FROM procurement_weighing_ticket_line pwtl
  210 + WHERE pwtl.weighing_ticket_id = #{ticketId}
  211 + AND pwtl.procurement_plan_id IS NOT NULL
  212 + ORDER BY pwtl.order_no
  213 + </select>
  214 +
  215 + <!-- 新增页级联第三步:所选计划下的过磅品种下拉,已生成原料化验报告单的品种不查出(同一品种多条过磅明细时由 Service 按 productId 去重取第一条) -->
  216 + <select id="queryAssayedProducts" resultMap="AssayReportProductOptionResult">
  217 + SELECT
  218 + pwtl.product_id,
  219 + br.product_name,
  220 + pwtl.procurement_plan_id AS plan_id,
  221 + pwtl.plan_code,
  222 + pwtl.quantity
  223 + FROM procurement_weighing_ticket_line pwtl
  224 + LEFT JOIN base_data_breed_relationship br ON br.id = pwtl.product_id
  225 + WHERE pwtl.weighing_ticket_id = #{ticketId}
  226 + AND pwtl.procurement_plan_id = #{planId}
  227 + AND pwtl.product_id IS NOT NULL
  228 + AND NOT EXISTS (
  229 + SELECT 1 FROM procurement_assay_report par
  230 + WHERE par.weighing_ticket_id = pwtl.weighing_ticket_id
  231 + AND par.product_id = pwtl.product_id
  232 + AND par.deleted = 0
  233 + )
  234 + ORDER BY pwtl.order_no
  235 + </select>
  236 + <!-- 新增页级联第四步:所选码单+计划+品种下的化验送样单列表(字段与报告单明细子表对齐,一条送样单对应一条明细) -->
  237 + <resultMap id="AssayReportApplyOptionResult" type="com.lframework.xingyun.sc.bo.procurement.GetAssayReportApplyOptionBo">
  238 + <id column="assay_apply_id" property="assayApplyId"/>
  239 + <result column="assay_apply_code" property="assayApplyCode"/>
  240 + <result column="product_id" property="productId"/>
  241 + <result column="product_name" property="productName"/>
  242 + <result column="quantity" property="quantity"/>
  243 + </resultMap>
  244 +
  245 + <select id="queryAssayApplies" resultMap="AssayReportApplyOptionResult">
  246 + SELECT
  247 + aa.id AS assay_apply_id,
  248 + aa.code AS assay_apply_code,
  249 + aa.product_id,
  250 + aa.product_name,
  251 + (
  252 + SELECT pwtl.quantity
  253 + FROM procurement_weighing_ticket_line pwtl
  254 + WHERE pwtl.weighing_ticket_id = aa.weighing_ticket_id
  255 + AND pwtl.product_id = aa.product_id
  256 + AND pwtl.quantity IS NOT NULL
  257 + ORDER BY pwtl.order_no
  258 + LIMIT 1
  259 + ) AS quantity
  260 + FROM procurement_assay_apply aa
  261 + WHERE aa.weighing_ticket_id = #{ticketId}
  262 + AND aa.procurement_plan_id = #{planId}
  263 + AND aa.product_id = #{productId}
  264 + AND aa.approval_status = 'PASS'
  265 + AND aa.deleted = 0
  266 + ORDER BY aa.create_time
  267 + </select>
  268 +</mapper>
... ...