Commit 724390dee65645b29bc43a1ccae617815cd7b8cd

Authored by 房远帅
1 parent f889c2c7

采购-入库:仓库收料单

Showing 24 changed files with 2456 additions and 6 deletions
@@ -122,7 +122,19 @@ public GetXxxBo(Xxx dto) { @@ -122,7 +122,19 @@ public GetXxxBo(Xxx dto) {
122 122
123 **坑**:分厂相关单据的审核节点编码 = 流程前缀 + 分厂前缀(`base_data_workshop.code`,如 yfc/efc/sfc/ztfc)+ 环节缩写(如 `material_settle_yfcckzg`)。单据实体只有 workshop_id/workshop_name(冗余列),workshopCode 是 `@TableField(exist = false)` 联表字段;`this.getById(id)` 是 MP 单表查询,查出的实体 workshopCode 永远为 null,`startInstance(BPM_FLAG, id, BPM_FLAG, entity)` 传给流程引擎的实体就缺分厂前缀。 123 **坑**:分厂相关单据的审核节点编码 = 流程前缀 + 分厂前缀(`base_data_workshop.code`,如 yfc/efc/sfc/ztfc)+ 环节缩写(如 `material_settle_yfcckzg`)。单据实体只有 workshop_id/workshop_name(冗余列),workshopCode 是 `@TableField(exist = false)` 联表字段;`this.getById(id)` 是 MP 单表查询,查出的实体 workshopCode 永远为 null,`startInstance(BPM_FLAG, id, BPM_FLAG, entity)` 传给流程引擎的实体就缺分厂前缀。
124 **后果**:流程引擎按分厂前缀路由审核节点/角色(material_settle_yfcckzg 等)时匹配不上,审核流向错误或全部落到无分厂节点。 124 **后果**:流程引擎按分厂前缀路由审核节点/角色(material_settle_yfcckzg 等)时匹配不上,审核流向错误或全部落到无分厂节点。
125 -**正确做法**:涉及分厂审核的单据(原料结算详情单等)Mapper XML 提供 `findById`(公共片段 `LEFT JOIN base_data_workshop ws ON ws.id = tb.workshop_id` 带出 `ws.code AS workshop_code`);**提交审核、传实体给流程引擎、以及后续涉及分厂审核路由的取数统一用 `mapper.findById(id)`,不用 `getById`**(参考 `ProcurementMaterialSettleDetailServiceImpl.submit`)。列表查询若要展示编号,同理在列表公共片段里 JOIN 带出。 125 +**正确做法**:涉及分厂审核的单据(原料结算详情单等)Mapper XML 提供 `findById`(公共片段 `LEFT JOIN base_data_workshop ws ON ws.id = tb.workshop_id` 带出 `ws.code AS workshop_code`);**提交审核、传实体给流程引擎、以及后续涉及分厂审核路由的取数统一用 `mapper.findById(id)`,不用 `getById`**(参考 `ProcurementMaterialSettleDetailServiceImpl.submit`)。列表查询若要展示编号,同理在列表公共片段里 JOIN 带出。**读侧同理**:`planCodes`/`planIds` 等公共片段子查询字段(GROUP_CONCAT)也是 exist=false,`selectList`/`selectById`/`getById` 全都带不出(永远 null),需要这些字段的取数(如收料单制单下拉、create 冗余存储)一律换 `mapper.findById`;跨模块取来源单数据时先确认目标字段是不是联表字段。
  126 +
  127 +## 21. 权限编码后缀用 modify 不用 update(照抄同业务模块惯例)
  128 +
  129 +**坑**:新模块 Controller 自创权限编码后缀 `:update`(如 `warehouse-manage:warehouse-receive:update`),而项目权限编码惯例是 `:modify`(原料结算详情单原用 `:update`,后已改回 `:modify`)。
  130 +**后果**:权限编码与系统权限管理里配置的菜单/按钮权限对不上,用户操作报无权限,需要前端菜单、权限初始化 SQL、后端注解三处返工。
  131 +**正确做法**:新增模块写 `@HasPermission` 前先 Grep 同业务模块的既有编码(如 `warehouse-manage:material-settlement:*`)照抄后缀风格:query/add/modify/submit/cancel/review/back/approve/print;修改类操作一律 `:modify`,不用 `:update`。
  132 +
  133 +## 22. 实体审计字段四件套都要带 fill 注解,创建人/更新人不要漏
  134 +
  135 +**坑**:新建实体只给 `createById`/`updateById`/`createTime`/`updateTime` 加了 `@TableField(fill = FieldFill.INSERT / INSERT_UPDATE)`,`createBy`(创建人姓名)和 `updateBy`(更新人姓名)漏加,MP 自动填充(MetaObjectHandler 按 fill 策略匹配字段)不生效,入库后这两列永远为 null,列表"创建人"列空白。四件套 = `createById`、`createBy`、`updateById`、`updateBy`,再加 `createTime`/`updateTime` 共六个,一个不能少。
  136 +**后果**:页面创建人/更新人显示空白;数据没有操作人追溯;事后补数困难。
  137 +**正确做法**:新建实体时审计字段照抄成熟实体(如 `ProcurementMaterialSettleDetail`)的写法,六个字段逐一检查注解:`createById`+`createBy`+`createTime` 用 `INSERT`,`updateById`+`updateBy`+`updateTime` 用 `INSERT_UPDATE`;写完实体后对照结算详情单实体逐一核对。
126 138
127 --- 139 ---
128 140
@@ -2822,3 +2822,81 @@ CREATE TABLE IF NOT EXISTS `procurement_material_settle_line` @@ -2822,3 +2822,81 @@ CREATE TABLE IF NOT EXISTS `procurement_material_settle_line`
2822 KEY `idx_pmsl_settle_detail_id` (`settle_detail_id`), 2822 KEY `idx_pmsl_settle_detail_id` (`settle_detail_id`),
2823 KEY `idx_pmsl_procurement_plan_id` (`procurement_plan_id`) 2823 KEY `idx_pmsl_procurement_plan_id` (`procurement_plan_id`)
2824 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='原料结算详情单-详情明细'; 2824 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='原料结算详情单-详情明细';
  2825 +
  2826 +-- 入库第五模块:仓库收料单(原料结算详情单流转,原料核算岗制单)
  2827 +CREATE TABLE IF NOT EXISTS `procurement_warehouse_receive_order`
  2828 +(
  2829 + `id` varchar(32) NOT NULL COMMENT 'ID',
  2830 + `settle_detail_id` varchar(32) NOT NULL COMMENT '原料结算详情单ID(来源单,一单一结算)',
  2831 + `weighing_ticket_id` varchar(32) DEFAULT NULL COMMENT '过磅码单ID(取自原料结算详情单)',
  2832 + `weighing_ticket_code` varchar(50) DEFAULT NULL COMMENT '码单编号',
  2833 + `ticket_date` date DEFAULT NULL COMMENT '日期(原料结算详情单日期+1天)',
  2834 + `material_source` varchar(200) DEFAULT NULL COMMENT '材料来源(原料结算详情单的单位)',
  2835 + `plan_codes` varchar(500) DEFAULT NULL COMMENT '计划编号(取自原料结算详情单,冗余展示)',
  2836 + `plan_ids` varchar(200) DEFAULT NULL COMMENT '计划ID集合(冗余)',
  2837 + `workshop_id` varchar(32) DEFAULT NULL COMMENT '分厂ID(取自原料结算详情单)',
  2838 + `workshop_name` varchar(200) DEFAULT NULL COMMENT '分厂名称',
  2839 + `remark` varchar(1000) DEFAULT NULL COMMENT '备注(多行文本)',
  2840 + `attachment_file_ids` varchar(1000) DEFAULT NULL COMMENT '附件文件ID集合(多文件,逗号分隔)',
  2841 + `attachment_file_names` varchar(1000) DEFAULT NULL COMMENT '附件文件名称集合',
  2842 + `total_purchase_quantity_cap` varchar(200) DEFAULT NULL COMMENT '合计-采购数大写(中文大写+公斤,后端计算)',
  2843 + `total_actual_quantity` decimal(12,2) DEFAULT NULL COMMENT '合计-实收数 kg',
  2844 + `total_tax_amount` decimal(14,2) DEFAULT NULL COMMENT '合计-含税金额',
  2845 + `flow_node` varchar(50) DEFAULT NULL COMMENT '流程节点 YHGG-原料核算岗 FZCKTJY-分厂仓库统计员 FZCKZJY-分厂仓库质检员 GYGLKZJY-供应管理科质检员 FZCKZG-分厂仓库主管 GYGLKZG-供应管理科主管 GYBZG-供应部主管',
  2846 + `approval_status` varchar(50) DEFAULT NULL COMMENT '审核状态 DRAFT-草稿 AUDIT-审核中 PASS-审核通过 REFUSE-已驳回 CANCEL-已取消',
  2847 + `fzcktjy_id` varchar(32) DEFAULT NULL COMMENT '分厂仓库统计员审核人ID(审核通过时记录)',
  2848 + `fzcktjy_name` varchar(64) DEFAULT NULL COMMENT '分厂仓库统计员审核人',
  2849 + `fzckzjy_id` varchar(32) DEFAULT NULL COMMENT '分厂仓库质检员审核人ID(审核通过时记录)',
  2850 + `fzckzjy_name` varchar(64) DEFAULT NULL COMMENT '分厂仓库质检员审核人',
  2851 + `gyglkzjy_id` varchar(32) DEFAULT NULL COMMENT '供应管理科质检员审核人ID(审核通过时记录)',
  2852 + `gyglkzjy_name` varchar(64) DEFAULT NULL COMMENT '供应管理科质检员审核人',
  2853 + `fzckzg_id` varchar(32) DEFAULT NULL COMMENT '分厂仓库主管审核人ID(审核通过时记录)',
  2854 + `fzckzg_name` varchar(64) DEFAULT NULL COMMENT '分厂仓库主管审核人',
  2855 + `gyglkzg_id` varchar(32) DEFAULT NULL COMMENT '供应管理科主管审核人ID(审核通过时记录)',
  2856 + `gyglkzg_name` varchar(64) DEFAULT NULL COMMENT '供应管理科主管审核人',
  2857 + `gybzg_id` varchar(32) DEFAULT NULL COMMENT '供应部主管审核人ID(审核通过时记录)',
  2858 + `gybzg_name` varchar(64) DEFAULT NULL COMMENT '供应部主管审核人',
  2859 + `deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否作废 0-有效单 1-作废单(作废单只能查看)',
  2860 + `create_by_id` varchar(32) DEFAULT NULL COMMENT '创建人ID',
  2861 + `create_by` varchar(64) DEFAULT NULL COMMENT '创建人',
  2862 + `update_by_id` varchar(32) DEFAULT NULL COMMENT '更新人ID',
  2863 + `update_by` varchar(64) DEFAULT NULL COMMENT '更新人',
  2864 + `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  2865 + `update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  2866 + PRIMARY KEY (`id`),
  2867 + KEY `idx_pwrwo_settle_detail_id` (`settle_detail_id`),
  2868 + KEY `idx_pwrwo_weighing_ticket_id` (`weighing_ticket_id`),
  2869 + KEY `idx_pwrwo_workshop_id` (`workshop_id`),
  2870 + KEY `idx_pwrwo_approval_status` (`approval_status`),
  2871 + KEY `idx_pwrwo_create_time` (`create_time`)
  2872 +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='仓库收料单';
  2873 +
  2874 +CREATE TABLE IF NOT EXISTS `procurement_warehouse_receive_order_line`
  2875 +(
  2876 + `id` varchar(32) NOT NULL COMMENT 'ID',
  2877 + `receive_order_id` varchar(32) NOT NULL COMMENT '仓库收料单主表ID',
  2878 + `settle_line_id` varchar(32) DEFAULT NULL COMMENT '原料结算详情单明细行ID(来源行,数据追溯)',
  2879 + `procurement_plan_id` varchar(32) DEFAULT NULL COMMENT '采购计划ID(来源行计划)',
  2880 + `product_id` varchar(32) DEFAULT NULL COMMENT '品种关系ID(来源行品种)',
  2881 + `category` varchar(50) DEFAULT NULL COMMENT '材料编号(原料结算详情单类别,品种关系代号)',
  2882 + `name` varchar(200) DEFAULT NULL COMMENT '材料名称(原料结算详情单名称,开票品名)',
  2883 + `spec_model` varchar(100) DEFAULT NULL COMMENT '规格型号(品种关系表类型)',
  2884 + `unit` varchar(20) DEFAULT 'kg' COMMENT '单位',
  2885 + `purchase_quantity` decimal(12,2) DEFAULT NULL COMMENT '数量(采购数)kg',
  2886 + `actual_quantity` decimal(12,2) DEFAULT NULL COMMENT '数量(实收数)kg(仅分厂仓库统计员环节可调整)',
  2887 + `tax_price` decimal(12,4) DEFAULT NULL COMMENT '含税价格(单价)元/kg(计划实际采购价/1000)',
  2888 + `tax_amount` decimal(14,2) DEFAULT NULL COMMENT '含税价格(金额)=单价*采购数',
  2889 + `no_tax_price` decimal(12,4) DEFAULT NULL COMMENT '不含税价格(单价)',
  2890 + `no_tax_amount` decimal(14,2) DEFAULT NULL COMMENT '不含税价格(金额)',
  2891 + `settle_type` varchar(20) DEFAULT NULL COMMENT '结算类型 经销/双经销/买断(取自原料结算详情单)',
  2892 + `remark` varchar(500) DEFAULT NULL COMMENT '备注',
  2893 + `order_no` int DEFAULT NULL COMMENT '排序号',
  2894 + `create_by_id` varchar(32) DEFAULT NULL COMMENT '创建人ID',
  2895 + `create_by` varchar(64) DEFAULT NULL COMMENT '创建人',
  2896 + `update_by_id` varchar(32) DEFAULT NULL COMMENT '更新人ID',
  2897 + `update_by` varchar(64) DEFAULT NULL COMMENT '更新人',
  2898 + `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  2899 + `update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  2900 + PRIMARY KEY (`id`),
  2901 + KEY `idx_pwrwl_receive_order_id` (`receive_order_id`)
  2902 +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='仓库收料单-明细';
  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.xingyun.sc.procurement.entity.receive.ProcurementWarehouseReceiveOrder;
  6 +import io.swagger.annotations.ApiModelProperty;
  7 +import lombok.Data;
  8 +
  9 +import java.math.BigDecimal;
  10 +import java.time.LocalDate;
  11 +import java.time.LocalDateTime;
  12 +import java.util.ArrayList;
  13 +import java.util.List;
  14 +
  15 +/**
  16 + * 仓库收料单详情(主表 + 明细 + 台账网价提示)
  17 + */
  18 +@Data
  19 +public class GetWarehouseReceiveOrderBo {
  20 +
  21 + @ApiModelProperty("ID")
  22 + private String id;
  23 +
  24 + @ApiModelProperty("原料结算详情单ID(来源单)")
  25 + private String settleDetailId;
  26 +
  27 + @ApiModelProperty("过磅码单ID")
  28 + private String weighingTicketId;
  29 +
  30 + @ApiModelProperty("码单编号")
  31 + private String weighingTicketCode;
  32 +
  33 + @ApiModelProperty("日期")
  34 + @JsonFormat(pattern = StringPool.DATE_PATTERN)
  35 + private LocalDate ticketDate;
  36 +
  37 + @ApiModelProperty("材料来源")
  38 + private String materialSource;
  39 +
  40 + @ApiModelProperty("计划编号集合")
  41 + private List<String> planCode = new ArrayList<>();
  42 +
  43 + @ApiModelProperty("分厂ID")
  44 + private String workshopId;
  45 +
  46 + @ApiModelProperty("分厂名称")
  47 + private String workshopName;
  48 +
  49 + @ApiModelProperty("分厂编号")
  50 + private String workshopCode;
  51 +
  52 + @ApiModelProperty("备注")
  53 + private String remark;
  54 +
  55 + @ApiModelProperty("附件文件ID集合")
  56 + private String attachmentFileIds;
  57 +
  58 + @ApiModelProperty("附件文件名称集合")
  59 + private String attachmentFileNames;
  60 +
  61 + @ApiModelProperty("合计-采购数大写(中文大写+公斤)")
  62 + private String totalPurchaseQuantityCap;
  63 +
  64 + @ApiModelProperty("合计-实收数 kg")
  65 + private BigDecimal totalActualQuantity;
  66 +
  67 + @ApiModelProperty("合计-含税金额")
  68 + private BigDecimal totalTaxAmount;
  69 +
  70 + @ApiModelProperty("流程节点 YHGG/FZCKTJY/FZCKZJY/GYGLKZJY/FZCKZG/GYGLKZG/GYBZG")
  71 + private String flowNode;
  72 +
  73 + @ApiModelProperty("审核状态 DRAFT/AUDIT/PASS/REFUSE/CANCEL")
  74 + private String approvalStatus;
  75 +
  76 + @ApiModelProperty("分厂仓库统计员审核人ID")
  77 + private String fzcktjyId;
  78 +
  79 + @ApiModelProperty("分厂仓库统计员审核人")
  80 + private String fzcktjyName;
  81 +
  82 + @ApiModelProperty("分厂仓库质检员审核人ID")
  83 + private String fzckzjyId;
  84 +
  85 + @ApiModelProperty("分厂仓库质检员审核人")
  86 + private String fzckzjyName;
  87 +
  88 + @ApiModelProperty("供应管理科质检员审核人ID")
  89 + private String gyglkzjyId;
  90 +
  91 + @ApiModelProperty("供应管理科质检员审核人")
  92 + private String gyglkzjyName;
  93 +
  94 + @ApiModelProperty("分厂仓库主管审核人ID")
  95 + private String fzckzgId;
  96 +
  97 + @ApiModelProperty("分厂仓库主管审核人")
  98 + private String fzckzgName;
  99 +
  100 + @ApiModelProperty("供应管理科主管审核人ID")
  101 + private String gyglkzgId;
  102 +
  103 + @ApiModelProperty("供应管理科主管审核人")
  104 + private String gyglkzgName;
  105 +
  106 + @ApiModelProperty("供应部主管审核人ID")
  107 + private String gybzgId;
  108 +
  109 + @ApiModelProperty("供应部主管审核人")
  110 + private String gybzgName;
  111 +
  112 + @ApiModelProperty("是否展示审核按钮")
  113 + private Boolean showExamine;
  114 +
  115 + @ApiModelProperty("是否展示审核详情按钮")
  116 + private Boolean showExamineDetail;
  117 +
  118 + @ApiModelProperty("创建人")
  119 + private String createBy;
  120 +
  121 + @ApiModelProperty("创建人ID")
  122 + private String createById;
  123 +
  124 + @ApiModelProperty("创建时间")
  125 + @JsonFormat(pattern = StringPool.DATE_TIME_PATTERN)
  126 + private LocalDateTime createTime;
  127 +
  128 + @ApiModelProperty("计划单时间(最早计划的创建时间)")
  129 + @JsonFormat(pattern = StringPool.DATE_TIME_PATTERN)
  130 + private LocalDateTime planTime;
  131 +
  132 + @ApiModelProperty("计划单时间对应的上海有色网1#电铜网价均价")
  133 + private BigDecimal planOnlinePrice;
  134 +
  135 + @ApiModelProperty("过磅码单时间(第一次毛重时间)")
  136 + @JsonFormat(pattern = StringPool.DATE_TIME_PATTERN)
  137 + private LocalDateTime ticketTime;
  138 +
  139 + @ApiModelProperty("过磅码单时间对应的上海有色网1#电铜网价均价")
  140 + private BigDecimal ticketOnlinePrice;
  141 +
  142 + @ApiModelProperty("两日网价均差(码单网价-计划网价)")
  143 + private BigDecimal priceDiff;
  144 +
  145 + @ApiModelProperty("两日价格均差超过800提示(true=红色提醒)")
  146 + private Boolean priceWarn;
  147 +
  148 + @ApiModelProperty("明细数据")
  149 + private List<LineBo> lines = new ArrayList<>();
  150 +
  151 + /**
  152 + * 仓库收料单明细
  153 + */
  154 + @Data
  155 + public static class LineBo {
  156 +
  157 + @ApiModelProperty("ID")
  158 + private String id;
  159 +
  160 + @ApiModelProperty("原料结算详情单明细行ID(来源行)")
  161 + private String settleLineId;
  162 +
  163 + @ApiModelProperty("采购计划ID")
  164 + private String procurementPlanId;
  165 +
  166 + @ApiModelProperty("品种关系ID")
  167 + private String productId;
  168 +
  169 + @ApiModelProperty("材料编号(类别)")
  170 + private String category;
  171 +
  172 + @ApiModelProperty("材料名称(开票品名)")
  173 + private String name;
  174 +
  175 + @ApiModelProperty("规格型号(品种关系表类型)")
  176 + private String specModel;
  177 +
  178 + @ApiModelProperty("单位")
  179 + private String unit;
  180 +
  181 + @ApiModelProperty("数量(采购数)kg")
  182 + private BigDecimal purchaseQuantity;
  183 +
  184 + @ApiModelProperty("数量(实收数)kg")
  185 + private BigDecimal actualQuantity;
  186 +
  187 + @ApiModelProperty("含税价格(单价)元/kg")
  188 + private BigDecimal taxPrice;
  189 +
  190 + @ApiModelProperty("含税价格(金额)=单价*采购数")
  191 + private BigDecimal taxAmount;
  192 +
  193 + @ApiModelProperty("不含税价格(单价)")
  194 + private BigDecimal noTaxPrice;
  195 +
  196 + @ApiModelProperty("不含税价格(金额)")
  197 + private BigDecimal noTaxAmount;
  198 +
  199 + @ApiModelProperty("结算类型 经销/双经销/买断")
  200 + private String settleType;
  201 +
  202 + @ApiModelProperty("备注")
  203 + private String remark;
  204 +
  205 + @ApiModelProperty("排序号")
  206 + private Integer orderNo;
  207 + }
  208 +}
  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.xingyun.sc.procurement.vo.receive.WarehouseReceiveOrderLineVo;
  6 +import io.swagger.annotations.ApiModelProperty;
  7 +import lombok.Data;
  8 +
  9 +import java.time.LocalDate;
  10 +import java.util.ArrayList;
  11 +import java.util.List;
  12 +
  13 +/**
  14 + * 新增仓库收料单:按原料结算详情单带出数据(原料核算岗制单)
  15 + */
  16 +@Data
  17 +public class GetWarehouseReceiveSettleDataBo {
  18 +
  19 + @ApiModelProperty("原料结算详情单ID")
  20 + private String settleDetailId;
  21 +
  22 + @ApiModelProperty("过磅码单ID")
  23 + private String weighingTicketId;
  24 +
  25 + @ApiModelProperty("码单编号")
  26 + private String weighingTicketCode;
  27 +
  28 + @ApiModelProperty("日期(原料结算详情单日期+1天)")
  29 + @JsonFormat(pattern = StringPool.DATE_PATTERN)
  30 + private LocalDate ticketDate;
  31 +
  32 + @ApiModelProperty("材料来源(原料结算详情单的单位)")
  33 + private String materialSource;
  34 +
  35 + @ApiModelProperty("计划编号(关联结算详情单的计划编号)")
  36 + private String planCodes;
  37 +
  38 + @ApiModelProperty("分厂ID")
  39 + private String workshopId;
  40 +
  41 + @ApiModelProperty("分厂名称")
  42 + private String workshopName;
  43 +
  44 + @ApiModelProperty("结算类型 经销/双经销/买断(取自原料结算详情单)")
  45 + private String settleType;
  46 +
  47 + @ApiModelProperty("明细数据(自动带出,category 为空的结算明细行不代入)")
  48 + private List<WarehouseReceiveOrderLineVo> lines = new ArrayList<>();
  49 +}
@@ -29,6 +29,7 @@ import com.lframework.xingyun.sc.procurement.service.plan.ProcurementPlanService @@ -29,6 +29,7 @@ import com.lframework.xingyun.sc.procurement.service.plan.ProcurementPlanService
29 import com.lframework.xingyun.sc.procurement.service.quotation.SalesmanQuotationService; 29 import com.lframework.xingyun.sc.procurement.service.quotation.SalesmanQuotationService;
30 import com.lframework.xingyun.sc.procurement.service.replenish.ProcurementPlanReplenishService; 30 import com.lframework.xingyun.sc.procurement.service.replenish.ProcurementPlanReplenishService;
31 import com.lframework.xingyun.sc.procurement.service.weighing.ProcurementAssayApplyService; 31 import com.lframework.xingyun.sc.procurement.service.weighing.ProcurementAssayApplyService;
  32 +import com.lframework.xingyun.sc.procurement.service.receive.ProcurementWarehouseReceiveOrderService;
32 import com.lframework.xingyun.sc.procurement.service.settle.ProcurementMaterialSettleDetailService; 33 import com.lframework.xingyun.sc.procurement.service.settle.ProcurementMaterialSettleDetailService;
33 import com.lframework.xingyun.sc.procurement.service.weighing.ProcurementAssayReportService; 34 import com.lframework.xingyun.sc.procurement.service.weighing.ProcurementAssayReportService;
34 import com.lframework.xingyun.sc.procurement.service.weighing.ProcurementWeighingTicketService; 35 import com.lframework.xingyun.sc.procurement.service.weighing.ProcurementWeighingTicketService;
@@ -183,6 +184,8 @@ public class BusinessDataHandlerServiceImpl implements BusinessDataHandlerServic @@ -183,6 +184,8 @@ public class BusinessDataHandlerServiceImpl implements BusinessDataHandlerServic
183 private ProcurementAssayReportService procurementAssayReportService; 184 private ProcurementAssayReportService procurementAssayReportService;
184 @Resource 185 @Resource
185 private ProcurementMaterialSettleDetailService procurementMaterialSettleDetailService; 186 private ProcurementMaterialSettleDetailService procurementMaterialSettleDetailService;
  187 + @Resource
  188 + private ProcurementWarehouseReceiveOrderService procurementWarehouseReceiveOrderService;
186 189
187 190
188 191
@@ -297,9 +300,12 @@ public class BusinessDataHandlerServiceImpl implements BusinessDataHandlerServic @@ -297,9 +300,12 @@ public class BusinessDataHandlerServiceImpl implements BusinessDataHandlerServic
297 case "ASSAY_REPORT": 300 case "ASSAY_REPORT":
298 handleAssayReportData(flowStatus, businessId); 301 handleAssayReportData(flowStatus, businessId);
299 break; 302 break;
300 - case "MATERIAL_SETTLE_DETAIL": 303 + case "SETTLE_DETAIL":
301 handleMaterialSettleDetailData(flowStatus, businessId); 304 handleMaterialSettleDetailData(flowStatus, businessId);
302 break; 305 break;
  306 + case "RECEIVE_ORDER":
  307 + handleWarehouseReceiveOrderData(flowStatus, businessId);
  308 + break;
303 default: 309 default:
304 break; 310 break;
305 } 311 }
@@ -1305,4 +1311,18 @@ public class BusinessDataHandlerServiceImpl implements BusinessDataHandlerServic @@ -1305,4 +1311,18 @@ public class BusinessDataHandlerServiceImpl implements BusinessDataHandlerServic
1305 procurementMaterialSettleDetailService.updateApprovalStatus(businessId, "REFUSE"); 1311 procurementMaterialSettleDetailService.updateApprovalStatus(businessId, "REFUSE");
1306 } 1312 }
1307 } 1313 }
  1314 +
  1315 + /**
  1316 + * 仓库收料单业务数据处理(流程结束回调)
  1317 + */
  1318 + private void handleWarehouseReceiveOrderData(String flowStatus, String businessId) {
  1319 + if (FlowInstanceStatus.APPROVE_PASS.getCode().equals(flowStatus)
  1320 + || FlowInstanceStatus.FINISH.getCode().equals(flowStatus)) {
  1321 + procurementWarehouseReceiveOrderService.updateApprovalStatus(businessId, "PASS");
  1322 + } else if (FlowInstanceStatus.REVOKE.getCode().equals(flowStatus)
  1323 + || FlowInstanceStatus.REFUSE.getCode().equals(flowStatus)
  1324 + || FlowInstanceStatus.TERMINATION.getCode().equals(flowStatus)) {
  1325 + procurementWarehouseReceiveOrderService.updateApprovalStatus(businessId, "REFUSE");
  1326 + }
  1327 + }
1308 } 1328 }
@@ -21,6 +21,7 @@ import com.lframework.xingyun.sc.procurement.entity.ProcurementPlanChange; @@ -21,6 +21,7 @@ import com.lframework.xingyun.sc.procurement.entity.ProcurementPlanChange;
21 import com.lframework.xingyun.sc.procurement.service.change.ProcurementPlanChangeService; 21 import com.lframework.xingyun.sc.procurement.service.change.ProcurementPlanChangeService;
22 import com.lframework.xingyun.sc.procurement.service.coordination.CoordinationSummaryApprovalService; 22 import com.lframework.xingyun.sc.procurement.service.coordination.CoordinationSummaryApprovalService;
23 import com.lframework.xingyun.sc.procurement.service.plan.ProcurementPlanService; 23 import com.lframework.xingyun.sc.procurement.service.plan.ProcurementPlanService;
  24 +import com.lframework.xingyun.sc.procurement.service.receive.ProcurementWarehouseReceiveOrderService;
24 import com.lframework.xingyun.sc.procurement.service.replenish.ProcurementPlanReplenishService; 25 import com.lframework.xingyun.sc.procurement.service.replenish.ProcurementPlanReplenishService;
25 import com.lframework.xingyun.sc.procurement.service.settle.ProcurementMaterialSettleDetailService; 26 import com.lframework.xingyun.sc.procurement.service.settle.ProcurementMaterialSettleDetailService;
26 import com.lframework.xingyun.sc.procurement.service.weighing.ProcurementAssayReportService; 27 import com.lframework.xingyun.sc.procurement.service.weighing.ProcurementAssayReportService;
@@ -82,6 +83,8 @@ public class FlowTaskServiceImpl implements FlowTaskService { @@ -82,6 +83,8 @@ public class FlowTaskServiceImpl implements FlowTaskService {
82 private ProcurementAssayReportService procurementAssayReportService; 83 private ProcurementAssayReportService procurementAssayReportService;
83 @Resource 84 @Resource
84 private ProcurementMaterialSettleDetailService procurementMaterialSettleDetailService; 85 private ProcurementMaterialSettleDetailService procurementMaterialSettleDetailService;
  86 + @Resource
  87 + private ProcurementWarehouseReceiveOrderService procurementWarehouseReceiveOrderService;
85 88
86 89
87 @OpLog(type = OtherOpLogType.class, name = "修改客户资信,ID:{}", params = {"#id"}) 90 @OpLog(type = OtherOpLogType.class, name = "修改客户资信,ID:{}", params = {"#id"})
@@ -505,6 +508,12 @@ public class FlowTaskServiceImpl implements FlowTaskService { @@ -505,6 +508,12 @@ public class FlowTaskServiceImpl implements FlowTaskService {
505 procurementMaterialSettleDetailService.updateNoFlowInstance(map); 508 procurementMaterialSettleDetailService.updateNoFlowInstance(map);
506 } 509 }
507 510
  511 + @Transactional(rollbackFor = Exception.class)
  512 + @Override
  513 + public void updateReceiveOrderApprovalMap(Map<String, Object> map) {
  514 + procurementWarehouseReceiveOrderService.updateNoFlowInstance(map);
  515 + }
  516 +
508 @Override 517 @Override
509 public Map<String, Object> findById(String s) { 518 public Map<String, Object> findById(String s) {
510 ProductSampleConfirmationSlip slip = productSampleConfirmationSlipService.findById(s); 519 ProductSampleConfirmationSlip slip = productSampleConfirmationSlipService.findById(s);
  1 +package com.lframework.xingyun.sc.procurement.controller.receive;
  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.GetWarehouseReceiveOrderBo;
  10 +import com.lframework.xingyun.sc.bo.procurement.GetWarehouseReceiveSettleDataBo;
  11 +import com.lframework.xingyun.sc.procurement.entity.receive.ProcurementWarehouseReceiveOrder;
  12 +import com.lframework.xingyun.sc.procurement.service.receive.ProcurementWarehouseReceiveOrderService;
  13 +import com.lframework.xingyun.sc.procurement.vo.receive.CreateWarehouseReceiveOrderVo;
  14 +import com.lframework.xingyun.sc.procurement.vo.receive.QueryWarehouseReceiveOrderVo;
  15 +import com.lframework.xingyun.sc.procurement.vo.receive.UpdateWarehouseReceiveActualQuantityVo;
  16 +import com.lframework.xingyun.sc.procurement.vo.receive.UpdateWarehouseReceiveOrderVo;
  17 +import io.swagger.annotations.Api;
  18 +import io.swagger.annotations.ApiImplicitParam;
  19 +import io.swagger.annotations.ApiOperation;
  20 +import java.util.List;
  21 +import java.util.stream.Collectors;
  22 +import javax.annotation.Resource;
  23 +import javax.validation.Valid;
  24 +import javax.validation.constraints.NotBlank;
  25 +import lombok.extern.slf4j.Slf4j;
  26 +import org.springframework.util.CollectionUtils;
  27 +import org.springframework.validation.annotation.Validated;
  28 +import org.springframework.web.bind.annotation.GetMapping;
  29 +import org.springframework.web.bind.annotation.PostMapping;
  30 +import org.springframework.web.bind.annotation.PutMapping;
  31 +import org.springframework.web.bind.annotation.RequestBody;
  32 +import org.springframework.web.bind.annotation.RequestMapping;
  33 +import org.springframework.web.bind.annotation.RestController;
  34 +
  35 +/**
  36 + * 仓库收料单(入库第五模块,原料结算详情单流转,原料核算岗制单)
  37 + */
  38 +@Api(tags = "仓库收料单管理")
  39 +@Slf4j
  40 +@Validated
  41 +@RestController
  42 +@RequestMapping("/procurement/warehouse/receive")
  43 +public class ProcurementWarehouseReceiveOrderController extends DefaultBaseController {
  44 +
  45 + @Resource
  46 + private ProcurementWarehouseReceiveOrderService warehouseReceiveOrderService;
  47 +
  48 + @ApiOperation("分页查询仓库收料单")
  49 + @HasPermission({"warehouse-manage:warehouse-receive:query"})
  50 + @GetMapping("/query")
  51 + public InvokeResult<PageResult<GetWarehouseReceiveOrderBo>> query(
  52 + @Valid QueryWarehouseReceiveOrderVo vo) {
  53 + PageResult<ProcurementWarehouseReceiveOrder> result = warehouseReceiveOrderService.query(
  54 + getPageIndex(vo), getPageSize(vo), vo);
  55 +
  56 + List<GetWarehouseReceiveOrderBo> results = null;
  57 + if (!CollectionUtils.isEmpty(result.getDatas())) {
  58 + results = result.getDatas().stream().map(order -> {
  59 + GetWarehouseReceiveOrderBo bo = new GetWarehouseReceiveOrderBo();
  60 + org.springframework.beans.BeanUtils.copyProperties(order, bo);
  61 + bo.setPlanCode(splitPlanCodes(order.getPlanCodes()));
  62 + return bo;
  63 + }).collect(Collectors.toList());
  64 + }
  65 + return InvokeResultBuilder.success(PageResultUtil.rebuild(result, results));
  66 + }
  67 +
  68 + @ApiOperation("查询仓库收料单详情")
  69 + @ApiImplicitParam(value = "ID", name = "id", paramType = "query", required = true)
  70 + @HasPermission({"warehouse-manage:warehouse-receive:query", "warehouse-manage:warehouse-receive:review"})
  71 + @GetMapping("")
  72 + public InvokeResult<GetWarehouseReceiveOrderBo> findById(
  73 + @NotBlank(message = "ID不能为空!") String id) {
  74 + return InvokeResultBuilder.success(warehouseReceiveOrderService.findDetail(id));
  75 + }
  76 +
  77 + @ApiOperation("可制单的原料结算详情单下拉(审核通过且未生成过有效仓库收料单,已取消的不占用)")
  78 + @GetMapping("/settleOptions")
  79 + public InvokeResult<List<GetWarehouseReceiveSettleDataBo>> getSettleOptions() {
  80 + return InvokeResultBuilder.success(warehouseReceiveOrderService.getSettleOptions());
  81 + }
  82 +
  83 + @ApiOperation("新增页:按原料结算详情单带出数据(明细自动计算,没有类别的不代入)")
  84 + @ApiImplicitParam(value = "原料结算详情单ID", name = "settleDetailId", paramType = "query", required = true)
  85 + @GetMapping("/settleData")
  86 + public InvokeResult<GetWarehouseReceiveSettleDataBo> getSettleData(
  87 + @NotBlank(message = "原料结算详情单不能为空!") String settleDetailId) {
  88 + return InvokeResultBuilder.success(warehouseReceiveOrderService.getSettleData(settleDetailId));
  89 + }
  90 +
  91 + @ApiOperation("新增仓库收料单(草稿,原料核算岗-供应管理科)")
  92 + @HasPermission({"warehouse-manage:warehouse-receive:add"})
  93 + @PostMapping("")
  94 + public InvokeResult<String> create(@RequestBody @Valid CreateWarehouseReceiveOrderVo vo) {
  95 + String id = warehouseReceiveOrderService.create(vo);
  96 + return InvokeResultBuilder.success(id);
  97 + }
  98 +
  99 + @ApiOperation("修改仓库收料单(仅草稿、已驳回可修改)")
  100 + @HasPermission({"warehouse-manage:warehouse-receive:modify"})
  101 + @PutMapping("")
  102 + public InvokeResult<Void> update(@RequestBody @Valid UpdateWarehouseReceiveOrderVo vo) {
  103 + warehouseReceiveOrderService.update(vo);
  104 + return InvokeResultBuilder.success();
  105 + }
  106 +
  107 + @ApiOperation("提交仓库收料单审核")
  108 + @ApiImplicitParam(value = "ID", name = "id", paramType = "query", required = true)
  109 + @HasPermission({"warehouse-manage:warehouse-receive:submit"})
  110 + @PutMapping("/submit")
  111 + public InvokeResult<Void> submit(@NotBlank(message = "ID不能为空!") String id) {
  112 + warehouseReceiveOrderService.submit(id);
  113 + return InvokeResultBuilder.success();
  114 + }
  115 +
  116 + @ApiOperation("调整实收数(仅审核中且流程节点为分厂仓库统计员环节可调整,合计由前端计算传入)")
  117 + @HasPermission({"warehouse-manage:warehouse-receive:modify"})
  118 + @PutMapping("/actualQuantity")
  119 + public InvokeResult<Void> updateActualQuantity(
  120 + @RequestBody @Valid UpdateWarehouseReceiveActualQuantityVo vo) {
  121 + warehouseReceiveOrderService.updateActualQuantity(vo);
  122 + return InvokeResultBuilder.success();
  123 + }
  124 +
  125 + @ApiOperation("取消仓库收料单(草稿、已驳回状态可取消)")
  126 + @ApiImplicitParam(value = "ID", name = "id", paramType = "query", required = true)
  127 + @HasPermission({"warehouse-manage:warehouse-receive:cancel"})
  128 + @PutMapping("/cancel")
  129 + public InvokeResult<Void> cancel(@NotBlank(message = "ID不能为空!") String id) {
  130 + warehouseReceiveOrderService.cancel(id);
  131 + return InvokeResultBuilder.success();
  132 + }
  133 +
  134 + private List<String> splitPlanCodes(String planCodes) {
  135 + if (planCodes == null || planCodes.isEmpty()) {
  136 + return java.util.Collections.emptyList();
  137 + }
  138 + return java.util.Arrays.stream(planCodes.split("[,,]"))
  139 + .map(String::trim)
  140 + .filter(s -> !s.isEmpty())
  141 + .distinct()
  142 + .collect(Collectors.toList());
  143 + }
  144 +}
@@ -72,7 +72,7 @@ public class ProcurementMaterialSettleDetailController extends DefaultBaseContro @@ -72,7 +72,7 @@ public class ProcurementMaterialSettleDetailController extends DefaultBaseContro
72 return InvokeResultBuilder.success(procurementMaterialSettleDetailService.findDetail(id)); 72 return InvokeResultBuilder.success(procurementMaterialSettleDetailService.findDetail(id));
73 } 73 }
74 74
75 - @ApiOperation("选择码单弹窗:分页查询可制单的过磅码单(审核通过且已上传签字凭证且码单下每个过磅品种的化验报告单全部审核通过)") 75 + @ApiOperation("选择码单弹窗:分页查询可制单的过磅码单(审核通过且已上传签字凭证且码单下每个过磅品种的化验报告单全部审核通过且未生成过有效原料结算详情单)")
76 @GetMapping("/ticketPage") 76 @GetMapping("/ticketPage")
77 public InvokeResult<PageResult<GetMaterialSettleSelectableTicketBo>> querySelectableTickets( 77 public InvokeResult<PageResult<GetMaterialSettleSelectableTicketBo>> querySelectableTickets(
78 @Valid QueryMaterialSettleSelectableTicketVo vo) { 78 @Valid QueryMaterialSettleSelectableTicketVo vo) {
@@ -107,7 +107,7 @@ public class ProcurementMaterialSettleDetailController extends DefaultBaseContro @@ -107,7 +107,7 @@ public class ProcurementMaterialSettleDetailController extends DefaultBaseContro
107 } 107 }
108 108
109 @ApiOperation("修改原料结算详情单(仅草稿、已驳回可修改)") 109 @ApiOperation("修改原料结算详情单(仅草稿、已驳回可修改)")
110 - @HasPermission({"warehouse-manage:material-settlement:update", "warehouse-manage:material-settlement:approve"}) 110 + @HasPermission({"warehouse-manage:material-settlement:modify", "warehouse-manage:material-settlement:approve"})
111 @PutMapping("") 111 @PutMapping("")
112 public InvokeResult<Void> update(@RequestBody @Valid UpdateProcurementMaterialSettleDetailVo vo) { 112 public InvokeResult<Void> update(@RequestBody @Valid UpdateProcurementMaterialSettleDetailVo vo) {
113 procurementMaterialSettleDetailService.update(vo); 113 procurementMaterialSettleDetailService.update(vo);
  1 +package com.lframework.xingyun.sc.procurement.entity.receive;
  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.LocalDate;
  10 +import java.time.LocalDateTime;
  11 +import lombok.Data;
  12 +
  13 +/**
  14 + * 仓库收料单(入库第五模块,原料结算详情单流转,原料核算岗制单)
  15 + * 原料核算岗制单(供应管理科)-> 分厂仓库统计员 -> 分厂仓库质检员 -> 供应管理科质检员 -> 分厂仓库主管 -> 供应管理科主管 -> 供应部主管
  16 + */
  17 +@Data
  18 +@TableName("procurement_warehouse_receive_order")
  19 +public class ProcurementWarehouseReceiveOrder extends BaseEntity implements BaseDto {
  20 +
  21 + private static final long serialVersionUID = 1L;
  22 +
  23 + /**
  24 + * 主键ID
  25 + */
  26 + private String id;
  27 +
  28 + /**
  29 + * 原料结算详情单ID(来源单,一单一结算)
  30 + */
  31 + private String settleDetailId;
  32 +
  33 + /**
  34 + * 过磅码单ID(取自原料结算详情单)
  35 + */
  36 + private String weighingTicketId;
  37 +
  38 + /**
  39 + * 码单编号
  40 + */
  41 + private String weighingTicketCode;
  42 +
  43 + /**
  44 + * 日期(原料结算详情单日期+1天)
  45 + */
  46 + private LocalDate ticketDate;
  47 +
  48 + /**
  49 + * 材料来源(原料结算详情单的单位)
  50 + */
  51 + private String materialSource;
  52 +
  53 + /**
  54 + * 计划编号(取自原料结算详情单,冗余展示)
  55 + */
  56 + private String planCodes;
  57 +
  58 + /**
  59 + * 计划ID集合(冗余)
  60 + */
  61 + private String planIds;
  62 +
  63 + /**
  64 + * 分厂ID(取自原料结算详情单)
  65 + */
  66 + private String workshopId;
  67 +
  68 + /**
  69 + * 分厂名称
  70 + */
  71 + private String workshopName;
  72 +
  73 + /**
  74 + * 备注(多行文本)
  75 + */
  76 + private String remark;
  77 +
  78 + /**
  79 + * 附件文件ID集合(多文件,逗号分隔)
  80 + */
  81 + private String attachmentFileIds;
  82 +
  83 + /**
  84 + * 附件文件名称集合
  85 + */
  86 + private String attachmentFileNames;
  87 +
  88 + /**
  89 + * 合计-采购数大写(中文大写+公斤,后端计算)
  90 + */
  91 + private String totalPurchaseQuantityCap;
  92 +
  93 + /**
  94 + * 合计-实收数 kg
  95 + */
  96 + private BigDecimal totalActualQuantity;
  97 +
  98 + /**
  99 + * 合计-含税金额
  100 + */
  101 + private BigDecimal totalTaxAmount;
  102 +
  103 + /**
  104 + * 流程节点 YHGG-原料核算岗 FZCKTJY-分厂仓库统计员 FZCKZJY-分厂仓库质检员 GYGLKZJY-供应管理科质检员 FZCKZG-分厂仓库主管 GYGLKZG-供应管理科主管 GYBZG-供应部主管
  105 + */
  106 + private String flowNode;
  107 +
  108 + /**
  109 + * 审核状态 DRAFT-草稿 AUDIT-审核中 PASS-审核通过 REFUSE-已驳回 CANCEL-已取消
  110 + */
  111 + private String approvalStatus;
  112 +
  113 + /**
  114 + * 分厂仓库统计员审核人ID(审核通过时记录)
  115 + */
  116 + private String fzcktjyId;
  117 +
  118 + /**
  119 + * 分厂仓库统计员审核人
  120 + */
  121 + private String fzcktjyName;
  122 +
  123 + /**
  124 + * 分厂仓库质检员审核人ID(审核通过时记录)
  125 + */
  126 + private String fzckzjyId;
  127 +
  128 + /**
  129 + * 分厂仓库质检员审核人
  130 + */
  131 + private String fzckzjyName;
  132 +
  133 + /**
  134 + * 供应管理科质检员审核人ID(审核通过时记录)
  135 + */
  136 + private String gyglkzjyId;
  137 +
  138 + /**
  139 + * 供应管理科质检员审核人
  140 + */
  141 + private String gyglkzjyName;
  142 +
  143 + /**
  144 + * 分厂仓库主管审核人ID(审核通过时记录)
  145 + */
  146 + private String fzckzgId;
  147 +
  148 + /**
  149 + * 分厂仓库主管审核人
  150 + */
  151 + private String fzckzgName;
  152 +
  153 + /**
  154 + * 供应管理科主管审核人ID(审核通过时记录)
  155 + */
  156 + private String gyglkzgId;
  157 +
  158 + /**
  159 + * 供应管理科主管审核人
  160 + */
  161 + private String gyglkzgName;
  162 +
  163 + /**
  164 + * 供应部主管审核人ID(审核通过时记录)
  165 + */
  166 + private String gybzgId;
  167 +
  168 + /**
  169 + * 供应部主管审核人
  170 + */
  171 + private String gybzgName;
  172 +
  173 + /**
  174 + * 是否作废 0-有效单 1-作废单(作废单只能查看)
  175 + */
  176 + private Boolean deleted;
  177 +
  178 + /**
  179 + * 创建人ID
  180 + */
  181 + @TableField(fill = FieldFill.INSERT)
  182 + private String createById;
  183 +
  184 + /**
  185 + * 创建人
  186 + */
  187 + @TableField(fill = FieldFill.INSERT)
  188 + private String createBy;
  189 +
  190 + /**
  191 + * 更新人ID
  192 + */
  193 + @TableField(fill = FieldFill.INSERT_UPDATE)
  194 + private String updateById;
  195 +
  196 + /**
  197 + * 更新人
  198 + */
  199 + @TableField(fill = FieldFill.INSERT_UPDATE)
  200 + private String updateBy;
  201 +
  202 + /**
  203 + * 创建时间
  204 + */
  205 + @TableField(fill = FieldFill.INSERT)
  206 + private LocalDateTime createTime;
  207 +
  208 + /**
  209 + * 更新时间
  210 + */
  211 + @TableField(fill = FieldFill.INSERT_UPDATE)
  212 + private LocalDateTime updateTime;
  213 +
  214 + /**
  215 + * 分厂编号(联表 base_data_workshop 带出,非数据库字段;分厂审核节点编码 = WAREHOUSE_RECEIVE_ORDER_ + 分厂前缀 + 环节缩写)
  216 + */
  217 + @TableField(exist = false)
  218 + private String workshopCode;
  219 +
  220 + /**
  221 + * 审核按钮标记(待办驱动,非数据库字段)
  222 + */
  223 + @TableField(exist = false)
  224 + private Boolean showExamine;
  225 +
  226 + /**
  227 + * 审核详情按钮标记(存在流程实例,非数据库字段)
  228 + */
  229 + @TableField(exist = false)
  230 + private Boolean showExamineDetail;
  231 +}
  1 +package com.lframework.xingyun.sc.procurement.entity.receive;
  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_warehouse_receive_order_line")
  17 +public class ProcurementWarehouseReceiveOrderLine 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 receiveOrderId;
  30 +
  31 + /**
  32 + * 原料结算详情单明细行ID(来源行,数据追溯)
  33 + */
  34 + private String settleLineId;
  35 +
  36 + /**
  37 + * 采购计划ID(来源行计划)
  38 + */
  39 + private String procurementPlanId;
  40 +
  41 + /**
  42 + * 品种关系ID(来源行品种)
  43 + */
  44 + private String productId;
  45 +
  46 + /**
  47 + * 材料编号(原料结算详情单类别,品种关系代号)
  48 + */
  49 + private String category;
  50 +
  51 + /**
  52 + * 材料名称(原料结算详情单名称,开票品名)
  53 + */
  54 + private String name;
  55 +
  56 + /**
  57 + * 规格型号(品种关系表类型)
  58 + */
  59 + private String specModel;
  60 +
  61 + /**
  62 + * 单位
  63 + */
  64 + private String unit;
  65 +
  66 + /**
  67 + * 数量(采购数)kg:经销=结算明细入库净重;买断=申请净重-退料-折斤
  68 + */
  69 + private BigDecimal purchaseQuantity;
  70 +
  71 + /**
  72 + * 数量(实收数)kg(仅分厂仓库统计员环节可调整)
  73 + */
  74 + private BigDecimal actualQuantity;
  75 +
  76 + /**
  77 + * 含税价格(单价)元/kg(计划实际采购价/1000)
  78 + */
  79 + private BigDecimal taxPrice;
  80 +
  81 + /**
  82 + * 含税价格(金额)=单价*采购数
  83 + */
  84 + private BigDecimal taxAmount;
  85 +
  86 + /**
  87 + * 不含税价格(单价)
  88 + */
  89 + private BigDecimal noTaxPrice;
  90 +
  91 + /**
  92 + * 不含税价格(金额)
  93 + */
  94 + private BigDecimal noTaxAmount;
  95 +
  96 + /**
  97 + * 结算类型 经销/双经销/买断(取自原料结算详情单)
  98 + */
  99 + private String settleType;
  100 +
  101 + /**
  102 + * 备注
  103 + */
  104 + private String remark;
  105 +
  106 + /**
  107 + * 排序号
  108 + */
  109 + private Integer orderNo;
  110 +
  111 + /**
  112 + * 创建人ID
  113 + */
  114 + @TableField(fill = FieldFill.INSERT)
  115 + private String createById;
  116 +
  117 + /**
  118 + * 创建人
  119 + */
  120 + @TableField(fill = FieldFill.INSERT)
  121 + private String createBy;
  122 +
  123 + /**
  124 + * 更新人ID
  125 + */
  126 + @TableField(fill = FieldFill.INSERT_UPDATE)
  127 + private String updateById;
  128 +
  129 + /**
  130 + * 更新人
  131 + */
  132 + @TableField(fill = FieldFill.INSERT_UPDATE)
  133 + private String updateBy;
  134 +
  135 + /**
  136 + * 创建时间
  137 + */
  138 + @TableField(fill = FieldFill.INSERT)
  139 + private LocalDateTime createTime;
  140 +
  141 + /**
  142 + * 更新时间
  143 + */
  144 + @TableField(fill = FieldFill.INSERT_UPDATE)
  145 + private LocalDateTime updateTime;
  146 +}
  1 +package com.lframework.xingyun.sc.procurement.impl.receive;
  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.receive.ProcurementWarehouseReceiveOrderLine;
  6 +import com.lframework.xingyun.sc.procurement.mappers.receive.ProcurementWarehouseReceiveOrderLineMapper;
  7 +import com.lframework.xingyun.sc.procurement.service.receive.ProcurementWarehouseReceiveOrderLineService;
  8 +import java.util.ArrayList;
  9 +import java.util.List;
  10 +import org.springframework.stereotype.Service;
  11 +
  12 +@Service
  13 +public class ProcurementWarehouseReceiveOrderLineServiceImpl
  14 + extends BaseMpServiceImpl<ProcurementWarehouseReceiveOrderLineMapper, ProcurementWarehouseReceiveOrderLine>
  15 + implements ProcurementWarehouseReceiveOrderLineService {
  16 +
  17 + @Override
  18 + public List<ProcurementWarehouseReceiveOrderLine> getByReceiveOrderId(String receiveOrderId) {
  19 + return this.list(Wrappers.lambdaQuery(ProcurementWarehouseReceiveOrderLine.class)
  20 + .eq(ProcurementWarehouseReceiveOrderLine::getReceiveOrderId, receiveOrderId)
  21 + .orderByAsc(ProcurementWarehouseReceiveOrderLine::getOrderNo));
  22 + }
  23 +
  24 + @Override
  25 + public void deleteByReceiveOrderId(String receiveOrderId) {
  26 + this.remove(Wrappers.lambdaQuery(ProcurementWarehouseReceiveOrderLine.class)
  27 + .eq(ProcurementWarehouseReceiveOrderLine::getReceiveOrderId, receiveOrderId));
  28 + }
  29 +}
  1 +package com.lframework.xingyun.sc.procurement.impl.receive;
  2 +
  3 +import cn.hutool.core.bean.BeanUtil;
  4 +import com.baomidou.mybatisplus.core.conditions.Wrapper;
  5 +import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  6 +import com.github.pagehelper.PageInfo;
  7 +import com.lframework.starter.bpm.dto.FlowTaskDto;
  8 +import com.lframework.starter.bpm.entity.FlowInstanceWrapper;
  9 +import com.lframework.starter.bpm.mappers.FlowTaskWrapperMapper;
  10 +import com.lframework.starter.bpm.service.FlowInstanceWrapperService;
  11 +import com.lframework.starter.bpm.service.FlowTaskWrapperService;
  12 +import com.lframework.starter.bpm.vo.flow.task.QueryTodoTaskListVo;
  13 +import com.lframework.starter.common.exceptions.impl.DefaultClientException;
  14 +import com.lframework.starter.common.exceptions.impl.InputErrorException;
  15 +import com.lframework.starter.common.utils.Assert;
  16 +import com.lframework.starter.common.utils.CollectionUtil;
  17 +import com.lframework.starter.common.utils.StringUtil;
  18 +import com.lframework.starter.web.core.annotations.oplog.OpLog;
  19 +import com.lframework.starter.web.core.components.resp.PageResult;
  20 +import com.lframework.starter.web.core.components.security.SecurityUtil;
  21 +import com.lframework.starter.web.core.impl.BaseMpServiceImpl;
  22 +import com.lframework.starter.web.core.utils.IdUtil;
  23 +import com.lframework.starter.web.core.utils.JsonUtil;
  24 +import com.lframework.starter.web.core.utils.OpLogUtil;
  25 +import com.lframework.starter.web.core.utils.PageHelperUtil;
  26 +import com.lframework.starter.web.core.utils.PageResultUtil;
  27 +import com.lframework.starter.web.inner.components.oplog.OtherOpLogType;
  28 +import com.lframework.starter.web.inner.entity.SysRole;
  29 +import com.lframework.starter.web.inner.service.system.SysRoleService;
  30 +import com.lframework.xingyun.basedata.entity.BreedRelationship;
  31 +import com.lframework.xingyun.basedata.entity.BaseDataOnlinePrice;
  32 +import com.lframework.xingyun.basedata.service.breed.BreedRelationshipService;
  33 +import com.lframework.xingyun.basedata.service.onlinePrice.BaseDataOnlinePriceService;
  34 +import com.lframework.xingyun.sc.bo.procurement.GetWarehouseReceiveOrderBo;
  35 +import com.lframework.xingyun.sc.bo.procurement.GetWarehouseReceiveSettleDataBo;
  36 +import com.lframework.xingyun.sc.procurement.entity.ProcurementPlan;
  37 +import com.lframework.xingyun.sc.procurement.entity.ProcurementPlanLine;
  38 +import com.lframework.xingyun.sc.procurement.entity.settle.ProcurementMaterialSettleApplyLine;
  39 +import com.lframework.xingyun.sc.procurement.entity.settle.ProcurementMaterialSettleDetail;
  40 +import com.lframework.xingyun.sc.procurement.entity.settle.ProcurementMaterialSettleLine;
  41 +import com.lframework.xingyun.sc.procurement.entity.receive.ProcurementWarehouseReceiveOrder;
  42 +import com.lframework.xingyun.sc.procurement.entity.receive.ProcurementWarehouseReceiveOrderLine;
  43 +import com.lframework.xingyun.sc.procurement.entity.weighing.ProcurementWeighingTicket;
  44 +import com.lframework.xingyun.sc.procurement.mappers.receive.ProcurementWarehouseReceiveOrderMapper;
  45 +import com.lframework.xingyun.sc.procurement.mappers.settle.ProcurementMaterialSettleDetailMapper;
  46 +import com.lframework.xingyun.sc.procurement.mappers.weighing.ProcurementWeighingTicketMapper;
  47 +import com.lframework.xingyun.sc.procurement.service.plan.ProcurementPlanLineService;
  48 +import com.lframework.xingyun.sc.procurement.service.plan.ProcurementPlanService;
  49 +import com.lframework.xingyun.sc.procurement.service.receive.ProcurementWarehouseReceiveOrderLineService;
  50 +import com.lframework.xingyun.sc.procurement.service.receive.ProcurementWarehouseReceiveOrderService;
  51 +import com.lframework.xingyun.sc.procurement.service.settle.ProcurementMaterialSettleApplyLineService;
  52 +import com.lframework.xingyun.sc.procurement.service.settle.ProcurementMaterialSettleLineService;
  53 +import com.lframework.xingyun.sc.procurement.vo.receive.CreateWarehouseReceiveOrderVo;
  54 +import com.lframework.xingyun.sc.procurement.vo.receive.QueryWarehouseReceiveOrderVo;
  55 +import com.lframework.xingyun.sc.procurement.vo.receive.UpdateWarehouseReceiveActualQuantityVo;
  56 +import com.lframework.xingyun.sc.procurement.vo.receive.UpdateWarehouseReceiveOrderVo;
  57 +import com.lframework.xingyun.sc.procurement.vo.receive.WarehouseReceiveOrderLineVo;
  58 +
  59 +import java.math.BigDecimal;
  60 +import java.time.LocalDate;
  61 +import java.time.LocalDateTime;
  62 +import java.util.ArrayList;
  63 +import java.util.Collections;
  64 +import java.util.HashMap;
  65 +import java.util.HashSet;
  66 +import java.util.List;
  67 +import java.util.Map;
  68 +import java.util.Set;
  69 +import java.util.stream.Collectors;
  70 +import javax.annotation.Resource;
  71 +
  72 +import lombok.extern.slf4j.Slf4j;
  73 +import org.apache.commons.collections.CollectionUtils;
  74 +import org.springframework.stereotype.Service;
  75 +import org.springframework.transaction.annotation.Transactional;
  76 +
  77 +/**
  78 + * 仓库收料单(入库第五模块,原料结算详情单流转,原料核算岗制单)
  79 + * 原料核算岗制单(供应管理科)-> 分厂仓库统计员 -> 分厂仓库质检员 -> 供应管理科质检员 -> 分厂仓库主管 -> 供应管理科主管 -> 供应部主管
  80 + */
  81 +@Slf4j
  82 +@Service
  83 +public class ProcurementWarehouseReceiveOrderServiceImpl
  84 + extends BaseMpServiceImpl<ProcurementWarehouseReceiveOrderMapper, ProcurementWarehouseReceiveOrder>
  85 + implements ProcurementWarehouseReceiveOrderService {
  86 +
  87 + /**
  88 + * 审核状态-草稿
  89 + */
  90 + private static final String STATUS_DRAFT = "DRAFT";
  91 + /**
  92 + * 审核状态-审核中
  93 + */
  94 + private static final String STATUS_AUDIT = "AUDIT";
  95 + /**
  96 + * 审核状态-审核通过
  97 + */
  98 + private static final String STATUS_PASS = "PASS";
  99 + /**
  100 + * 审核状态-已驳回
  101 + */
  102 + private static final String STATUS_REFUSE = "REFUSE";
  103 + /**
  104 + * 审核状态-已取消
  105 + */
  106 + private static final String STATUS_CANCEL = "CANCEL";
  107 + /**
  108 + * 流程节点(原料核算岗制单 + 六个审核环节,需与流程设计器中的流程编号一致,流程创建后调整)
  109 + */
  110 + private static final String NODE_YLHSG = "YLHSG";
  111 + private static final String NODE_FZCKTJY = "FZCKTJY";
  112 + private static final String NODE_FZCKZJY = "FZCKZJY";
  113 + private static final String NODE_GYGLKZJY = "GYGLKZJY";
  114 + private static final String NODE_FZCKZG = "FZCKZG";
  115 + private static final String NODE_GYGLKZG = "GYGLKZG";
  116 + private static final String NODE_GYBZG = "GYBZG";
  117 + /**
  118 + * 流程编号(需与流程设计器中的流程编号一致,流程创建后调整)
  119 + */
  120 + private static final String BPM_FLAG = "RECEIVE_ORDER";
  121 + /**
  122 + * 结算类型-买断
  123 + */
  124 + private static final String SETTLE_TYPE_BUYOUT = "买断";
  125 + /**
  126 + * 两日网价均差提醒阈值
  127 + */
  128 + private static final BigDecimal PRICE_WARN_THRESHOLD = new BigDecimal("800");
  129 +
  130 + @Resource
  131 + private ProcurementWarehouseReceiveOrderMapper receiveOrderMapper;
  132 +
  133 + @Resource
  134 + private ProcurementWarehouseReceiveOrderLineService receiveLineService;
  135 +
  136 + @Resource
  137 + private ProcurementMaterialSettleDetailMapper settleDetailMapper;
  138 +
  139 + @Resource
  140 + private ProcurementMaterialSettleLineService settleLineService;
  141 +
  142 + @Resource
  143 + private ProcurementMaterialSettleApplyLineService settleApplyLineService;
  144 +
  145 + @Resource
  146 + private ProcurementPlanService procurementPlanService;
  147 +
  148 + @Resource
  149 + private ProcurementPlanLineService procurementPlanLineService;
  150 +
  151 + @Resource
  152 + private ProcurementWeighingTicketMapper weighingTicketMapper;
  153 +
  154 + @Resource
  155 + private BreedRelationshipService breedRelationshipService;
  156 +
  157 + @Resource
  158 + private BaseDataOnlinePriceService baseDataOnlinePriceService;
  159 +
  160 + @Resource
  161 + private FlowInstanceWrapperService flowInstanceWrapperService;
  162 +
  163 + @Resource
  164 + private FlowTaskWrapperMapper flowTaskWrapperMapper;
  165 +
  166 + @Resource
  167 + private FlowTaskWrapperService flowTaskWrapperService;
  168 +
  169 + @Resource
  170 + private SysRoleService sysRoleService;
  171 +
  172 + @Override
  173 + public PageResult<ProcurementWarehouseReceiveOrder> query(Integer pageIndex, Integer pageSize,
  174 + QueryWarehouseReceiveOrderVo vo) {
  175 + // 数据权限:按当前用户角色收集可见分厂代号(多分厂角色为并集,无分厂前缀角色不限制)
  176 + PageHelperUtil.startPage(pageIndex, pageSize);
  177 + List<ProcurementWarehouseReceiveOrder> datas = receiveOrderMapper.query(vo,
  178 + getCurrentUserWorkshopCodes());
  179 + PageResult<ProcurementWarehouseReceiveOrder> pageResult = PageResultUtil.convert(new PageInfo<>(datas));
  180 +
  181 + fillOperateFlags(pageResult.getDatas());
  182 +
  183 + return pageResult;
  184 + }
  185 +
  186 + @Override
  187 + public GetWarehouseReceiveOrderBo findDetail(String id) {
  188 + if (StringUtil.isBlank(id)) {
  189 + throw new InputErrorException("ID不能为空!");
  190 + }
  191 +
  192 + ProcurementWarehouseReceiveOrder entity = receiveOrderMapper.findById(id);
  193 + if (entity == null) {
  194 + throw new DefaultClientException("仓库收料单不存在!");
  195 + }
  196 + fillOperateFlags(Collections.singletonList(entity));
  197 +
  198 + GetWarehouseReceiveOrderBo bo = new GetWarehouseReceiveOrderBo();
  199 + BeanUtil.copyProperties(entity, bo);
  200 + bo.setPlanCode(splitToList(entity.getPlanCodes()));
  201 +
  202 + List<ProcurementWarehouseReceiveOrderLine> lines = receiveLineService.getByReceiveOrderId(id);
  203 + if (CollectionUtil.isNotEmpty(lines)) {
  204 + for (ProcurementWarehouseReceiveOrderLine line : lines) {
  205 + bo.getLines().add(BeanUtil.copyProperties(line, GetWarehouseReceiveOrderBo.LineBo.class));
  206 + }
  207 + }
  208 +
  209 + // 台账网价:计划单时间(最早计划的创建时间)+ 过磅码单时间(第一次毛重时间)对应的上海有色网1#电铜均价
  210 + fillOnlinePriceInfo(bo, entity);
  211 +
  212 + return bo;
  213 + }
  214 +
  215 + @Override
  216 + public List<GetWarehouseReceiveSettleDataBo> getSettleOptions() {
  217 + // 可制单的原料结算详情单:审核通过且未生成过仓库收料单
  218 + List<ProcurementMaterialSettleDetail> settles = settleDetailMapper.selectList(
  219 + Wrappers.lambdaQuery(ProcurementMaterialSettleDetail.class)
  220 + .eq(ProcurementMaterialSettleDetail::getApprovalStatus, STATUS_PASS)
  221 + .eq(ProcurementMaterialSettleDetail::getDeleted, false)
  222 + .orderByDesc(ProcurementMaterialSettleDetail::getCreateTime));
  223 + if (CollectionUtil.isEmpty(settles)) {
  224 + return new ArrayList<>();
  225 + }
  226 +
  227 + Set<String> usedSettleIds = new HashSet<>();
  228 + // 已生成过有效仓库收料单的结算详情单ID集合(已取消的不占用,其结算详情单可重新制单)
  229 + List<ProcurementWarehouseReceiveOrder> usedOrders = this.list(
  230 + Wrappers.lambdaQuery(ProcurementWarehouseReceiveOrder.class)
  231 + .eq(ProcurementWarehouseReceiveOrder::getDeleted, false)
  232 + .ne(ProcurementWarehouseReceiveOrder::getApprovalStatus, STATUS_CANCEL)
  233 + .in(ProcurementWarehouseReceiveOrder::getSettleDetailId,
  234 + settles.stream().map(ProcurementMaterialSettleDetail::getId).collect(Collectors.toList())));
  235 + if (CollectionUtil.isNotEmpty(usedOrders)) {
  236 + usedSettleIds = usedOrders.stream()
  237 + .map(ProcurementWarehouseReceiveOrder::getSettleDetailId)
  238 + .collect(Collectors.toSet());
  239 + }
  240 +
  241 + List<GetWarehouseReceiveSettleDataBo> options = new ArrayList<>();
  242 + for (ProcurementMaterialSettleDetail settle : settles) {
  243 + if (usedSettleIds.contains(settle.getId())) {
  244 + continue;
  245 + }
  246 + // planCodes 为联表字段(exist=false),MP 单表查询带不出,改用 findById
  247 + ProcurementMaterialSettleDetail detail = settleDetailMapper.findById(settle.getId());
  248 + if (detail == null) {
  249 + continue;
  250 + }
  251 + GetWarehouseReceiveSettleDataBo option = new GetWarehouseReceiveSettleDataBo();
  252 + option.setSettleDetailId(detail.getId());
  253 + option.setWeighingTicketId(detail.getWeighingTicketId());
  254 + option.setWeighingTicketCode(detail.getWeighingTicketCode());
  255 + option.setTicketDate(nextDay(detail.getTicketDate()));
  256 + option.setMaterialSource(detail.getSupplierName());
  257 + option.setPlanCodes(detail.getPlanCodes());
  258 + option.setWorkshopId(detail.getWorkshopId());
  259 + option.setWorkshopName(detail.getWorkshopName());
  260 + option.setSettleType(detail.getSettleType());
  261 + options.add(option);
  262 + }
  263 + return options;
  264 + }
  265 +
  266 + @Override
  267 + public GetWarehouseReceiveSettleDataBo getSettleData(String settleDetailId) {
  268 + if (StringUtil.isBlank(settleDetailId)) {
  269 + throw new DefaultClientException("原料结算详情单不能为空!");
  270 + }
  271 + // planCodes/planIds 为联表字段(exist=false),必须用 findById 带出
  272 + ProcurementMaterialSettleDetail settle = settleDetailMapper.findById(settleDetailId);
  273 + if (settle == null || Boolean.TRUE.equals(settle.getDeleted())) {
  274 + throw new DefaultClientException("原料结算详情单不存在!");
  275 + }
  276 + if (!STATUS_PASS.equals(settle.getApprovalStatus())) {
  277 + throw new DefaultClientException("仅审核通过的原料结算详情单可生成仓库收料单!");
  278 + }
  279 +
  280 + GetWarehouseReceiveSettleDataBo bo = new GetWarehouseReceiveSettleDataBo();
  281 + bo.setSettleDetailId(settle.getId());
  282 + bo.setWeighingTicketId(settle.getWeighingTicketId());
  283 + bo.setWeighingTicketCode(settle.getWeighingTicketCode());
  284 + bo.setTicketDate(nextDay(settle.getTicketDate()));
  285 + bo.setMaterialSource(settle.getSupplierName());
  286 + bo.setPlanCodes(settle.getPlanCodes());
  287 + bo.setWorkshopId(settle.getWorkshopId());
  288 + bo.setWorkshopName(settle.getWorkshopName());
  289 + bo.setSettleType(settle.getSettleType());
  290 +
  291 + // 明细自动计算:没有类别(category)的结算明细行不代入
  292 + boolean buyout = settle.getSettleType() != null && settle.getSettleType().contains(SETTLE_TYPE_BUYOUT);
  293 + // 申请净重(品种关系ID -> 合计申请净重),买断采购数 = 申请净重 - 退料 - 折斤
  294 + Map<String, BigDecimal> applyQuantityMap = settleApplyLineService.getBySettleDetailId(settleDetailId)
  295 + .stream()
  296 + .filter(l -> l != null && StringUtil.isNotBlank(l.getBreedRelationshipId()) && l.getQuantity() != null)
  297 + .collect(Collectors.toMap(ProcurementMaterialSettleApplyLine::getBreedRelationshipId,
  298 + ProcurementMaterialSettleApplyLine::getQuantity, BigDecimal::add));
  299 +
  300 + List<ProcurementMaterialSettleLine> settleLines = settleLineService.getBySettleDetailId(settleDetailId);
  301 + for (ProcurementMaterialSettleLine settleLine : settleLines) {
  302 + if (settleLine == null || StringUtil.isBlank(settleLine.getCategory())) {
  303 + // 没有类别的不代入
  304 + continue;
  305 + }
  306 + WarehouseReceiveOrderLineVo lineVo = new WarehouseReceiveOrderLineVo();
  307 + lineVo.setSettleLineId(settleLine.getId());
  308 + lineVo.setProcurementPlanId(settleLine.getProcurementPlanId());
  309 + lineVo.setProductId(settleLine.getProductId());
  310 + lineVo.setCategory(settleLine.getCategory());
  311 + lineVo.setName(settleLine.getName());
  312 + lineVo.setUnit("kg");
  313 + lineVo.setSettleType(settle.getSettleType());
  314 + lineVo.setPurchaseQuantity(calcPurchaseQuantity(buyout, settleLine, applyQuantityMap));
  315 + lineVo.setActualQuantity(settleLine.getNetWeight());
  316 + lineVo.setTaxPrice(resolveTaxPrice(settleLine));
  317 + if (lineVo.getTaxPrice() != null && lineVo.getPurchaseQuantity() != null) {
  318 + lineVo.setTaxAmount(lineVo.getTaxPrice().multiply(lineVo.getPurchaseQuantity()));
  319 + }
  320 + bo.getLines().add(lineVo);
  321 + }
  322 + fillSpecModels(bo.getLines());
  323 + return bo;
  324 + }
  325 +
  326 + @Override
  327 + @Transactional(rollbackFor = Exception.class)
  328 + @OpLog(type = OtherOpLogType.class, name = "新增仓库收料单,ID:{}", params = {"#result"})
  329 + public String create(CreateWarehouseReceiveOrderVo vo) {
  330 + ProcurementMaterialSettleDetail settle = assertSettleUsable(vo.getSettleDetailId());
  331 +
  332 + ProcurementWarehouseReceiveOrder entity = new ProcurementWarehouseReceiveOrder();
  333 + entity.setId(IdUtil.getId());
  334 + entity.setSettleDetailId(settle.getId());
  335 + entity.setWeighingTicketId(settle.getWeighingTicketId());
  336 + entity.setWeighingTicketCode(settle.getWeighingTicketCode());
  337 + entity.setTicketDate(vo.getTicketDate() == null ? nextDay(settle.getTicketDate()) : vo.getTicketDate());
  338 + entity.setMaterialSource(StringUtil.isBlank(vo.getMaterialSource()) ? settle.getSupplierName() : vo.getMaterialSource());
  339 + entity.setPlanCodes(settle.getPlanCodes());
  340 + entity.setPlanIds(settle.getPlanIds());
  341 + entity.setWorkshopId(settle.getWorkshopId());
  342 + entity.setWorkshopName(settle.getWorkshopName());
  343 + entity.setRemark(vo.getRemark());
  344 + entity.setAttachmentFileIds(vo.getAttachmentFileIds());
  345 + entity.setAttachmentFileNames(vo.getAttachmentFileNames());
  346 + // 合计由前端计算传入,后端保存
  347 + entity.setTotalPurchaseQuantityCap(vo.getTotalPurchaseQuantityCap());
  348 + entity.setTotalActualQuantity(vo.getTotalActualQuantity());
  349 + entity.setTotalTaxAmount(vo.getTotalTaxAmount());
  350 + entity.setApprovalStatus(STATUS_DRAFT);
  351 + // 制单阶段当前节点为原料核算岗
  352 + entity.setFlowNode(NODE_YLHSG);
  353 +
  354 + this.save(entity);
  355 + saveLines(entity.getId(), vo.getLines());
  356 +
  357 + OpLogUtil.setVariable("id", entity.getId());
  358 + OpLogUtil.setExtra(entity);
  359 +
  360 + return entity.getId();
  361 + }
  362 +
  363 + @Override
  364 + @Transactional(rollbackFor = Exception.class)
  365 + @OpLog(type = OtherOpLogType.class, name = "修改仓库收料单,ID:{}", params = {"#vo.id"})
  366 + public void update(UpdateWarehouseReceiveOrderVo vo) {
  367 + Assert.notBlank(vo.getId(), "ID不能为空!");
  368 +
  369 + ProcurementWarehouseReceiveOrder oldEntity = this.getById(vo.getId());
  370 + if (oldEntity == null) {
  371 + throw new DefaultClientException("仓库收料单不存在!");
  372 + }
  373 + // 作废单只能查看;仅草稿、已驳回可修改
  374 + assertValid(oldEntity);
  375 + assertEditable(oldEntity);
  376 +
  377 + ProcurementWarehouseReceiveOrder entity = new ProcurementWarehouseReceiveOrder();
  378 + entity.setId(vo.getId());
  379 + entity.setTicketDate(vo.getTicketDate());
  380 + entity.setMaterialSource(vo.getMaterialSource());
  381 + entity.setRemark(vo.getRemark());
  382 + entity.setAttachmentFileIds(vo.getAttachmentFileIds());
  383 + entity.setAttachmentFileNames(vo.getAttachmentFileNames());
  384 + // 合计由前端计算传入,后端保存
  385 + entity.setTotalPurchaseQuantityCap(vo.getTotalPurchaseQuantityCap());
  386 + entity.setTotalActualQuantity(vo.getTotalActualQuantity());
  387 + entity.setTotalTaxAmount(vo.getTotalTaxAmount());
  388 +
  389 + this.updateById(entity);
  390 +
  391 + // 明细整体重建
  392 + receiveLineService.deleteByReceiveOrderId(vo.getId());
  393 + saveLines(vo.getId(), vo.getLines());
  394 +
  395 + OpLogUtil.setVariable("id", entity.getId());
  396 + OpLogUtil.setExtra(entity);
  397 + }
  398 +
  399 + @Override
  400 + @Transactional(rollbackFor = Exception.class)
  401 + @OpLog(type = OtherOpLogType.class, name = "提交仓库收料单审核,ID:{}", params = {"#id"})
  402 + public void submit(String id) {
  403 + Assert.notBlank(id);
  404 +
  405 + // 联表带出分厂编号(分厂审核节点编码 = WAREHOUSE_RECEIVE_ORDER_ + 分厂前缀 + 环节缩写,startInstance 传实体时必须带出)
  406 + ProcurementWarehouseReceiveOrder entity = receiveOrderMapper.findById(id);
  407 + if (entity == null) {
  408 + throw new DefaultClientException("仓库收料单不存在!");
  409 + }
  410 + assertValid(entity);
  411 + if (!STATUS_DRAFT.equals(entity.getApprovalStatus()) && !STATUS_REFUSE.equals(entity.getApprovalStatus())) {
  412 + throw new DefaultClientException("当前单据状态不允许提交审核!");
  413 + }
  414 +
  415 + List<ProcurementWarehouseReceiveOrderLine> lines = receiveLineService.getByReceiveOrderId(id);
  416 + if (CollectionUtil.isEmpty(lines)) {
  417 + throw new DefaultClientException("明细不能为空!");
  418 + }
  419 +
  420 + this.update(Wrappers.lambdaUpdate(ProcurementWarehouseReceiveOrder.class)
  421 + .set(ProcurementWarehouseReceiveOrder::getApprovalStatus, STATUS_AUDIT)
  422 + // 提交审核后流程节点推进到分厂仓库统计员
  423 + .set(ProcurementWarehouseReceiveOrder::getFlowNode, NODE_FZCKTJY)
  424 + .eq(ProcurementWarehouseReceiveOrder::getId, id));
  425 +
  426 + flowInstanceWrapperService.startInstance(BPM_FLAG, entity.getId(), BPM_FLAG, entity);
  427 +
  428 + OpLogUtil.setVariable("id", id);
  429 + OpLogUtil.setExtra(entity);
  430 + }
  431 +
  432 + @Override
  433 + @Transactional(rollbackFor = Exception.class)
  434 + @OpLog(type = OtherOpLogType.class, name = "取消仓库收料单,ID:{}", params = {"#id"})
  435 + public void cancel(String id) {
  436 + Assert.notBlank(id);
  437 +
  438 + ProcurementWarehouseReceiveOrder entity = this.getById(id);
  439 + if (entity == null) {
  440 + throw new DefaultClientException("仓库收料单不存在!");
  441 + }
  442 + assertValid(entity);
  443 + // 草稿、已驳回状态可取消
  444 + if (!STATUS_DRAFT.equals(entity.getApprovalStatus()) && !STATUS_REFUSE.equals(entity.getApprovalStatus())) {
  445 + throw new DefaultClientException("仅草稿、已驳回状态的仓库收料单可取消!");
  446 + }
  447 +
  448 + this.update(Wrappers.lambdaUpdate(ProcurementWarehouseReceiveOrder.class)
  449 + .set(ProcurementWarehouseReceiveOrder::getApprovalStatus, STATUS_CANCEL)
  450 + .set(ProcurementWarehouseReceiveOrder::getFlowNode, null)
  451 + .eq(ProcurementWarehouseReceiveOrder::getId, id));
  452 +
  453 + OpLogUtil.setVariable("id", id);
  454 + OpLogUtil.setExtra(entity);
  455 + }
  456 +
  457 + @Override
  458 + @Transactional(rollbackFor = Exception.class)
  459 + @OpLog(type = OtherOpLogType.class, name = "调整仓库收料单实收数,ID:{}", params = {"#vo.id"})
  460 + public void updateActualQuantity(UpdateWarehouseReceiveActualQuantityVo vo) {
  461 + Assert.notBlank(vo.getId(), "ID不能为空!");
  462 +
  463 + ProcurementWarehouseReceiveOrder entity = this.getById(vo.getId());
  464 + if (entity == null) {
  465 + throw new DefaultClientException("仓库收料单不存在!");
  466 + }
  467 + // 作废单只能查看;仅审核中且流程节点为分厂仓库统计员时可调整实收数,其他审核环节无数据操作权限
  468 + assertValid(entity);
  469 + if (CollectionUtil.isEmpty(vo.getLines())) {
  470 + return;
  471 + }
  472 +
  473 + for (WarehouseReceiveOrderLineVo lineVo : vo.getLines()) {
  474 + if (lineVo == null || StringUtil.isBlank(lineVo.getId())) {
  475 + continue;
  476 + }
  477 + receiveLineService.update(Wrappers.lambdaUpdate(ProcurementWarehouseReceiveOrderLine.class)
  478 + .set(ProcurementWarehouseReceiveOrderLine::getActualQuantity, lineVo.getActualQuantity())
  479 + .eq(ProcurementWarehouseReceiveOrderLine::getId, lineVo.getId())
  480 + .eq(ProcurementWarehouseReceiveOrderLine::getReceiveOrderId, vo.getId()));
  481 + }
  482 +
  483 + // 合计由前端计算传入,后端保存
  484 + this.update(Wrappers.lambdaUpdate(ProcurementWarehouseReceiveOrder.class)
  485 + .set(StringUtil.isNotBlank(vo.getTotalPurchaseQuantityCap()),
  486 + ProcurementWarehouseReceiveOrder::getTotalPurchaseQuantityCap, vo.getTotalPurchaseQuantityCap())
  487 + .set(vo.getTotalActualQuantity() != null,
  488 + ProcurementWarehouseReceiveOrder::getTotalActualQuantity, vo.getTotalActualQuantity())
  489 + .set(vo.getTotalTaxAmount() != null,
  490 + ProcurementWarehouseReceiveOrder::getTotalTaxAmount, vo.getTotalTaxAmount())
  491 + .eq(ProcurementWarehouseReceiveOrder::getId, vo.getId()));
  492 +
  493 + OpLogUtil.setVariable("id", vo.getId());
  494 + OpLogUtil.setExtra(entity);
  495 + }
  496 +
  497 + @Override
  498 + @Transactional(rollbackFor = Exception.class)
  499 + public void updateApprovalStatus(String id, String approvalStatus) {
  500 + if (StringUtil.isBlank(id) || StringUtil.isBlank(approvalStatus)) {
  501 + throw new DefaultClientException("仓库收料单ID、审核状态不能为空!");
  502 + }
  503 +
  504 + ProcurementWarehouseReceiveOrder entity = this.getById(id);
  505 + if (entity == null) {
  506 + throw new DefaultClientException("仓库收料单不存在!");
  507 + }
  508 +
  509 + this.update(Wrappers.lambdaUpdate(ProcurementWarehouseReceiveOrder.class)
  510 + .set(ProcurementWarehouseReceiveOrder::getApprovalStatus, approvalStatus)
  511 + .set(ProcurementWarehouseReceiveOrder::getFlowNode, approvalStatus.equals("PASS") ? null : NODE_YLHSG)
  512 + .eq(ProcurementWarehouseReceiveOrder::getId, id));
  513 + }
  514 +
  515 + @Override
  516 + @Transactional(rollbackFor = Exception.class)
  517 + public void updateNoFlowInstance(Map<String, Object> map) {
  518 + try {
  519 + // 审核状态
  520 + Object examStatusObj = map.get("examStatus");
  521 + String examStatus = examStatusObj == null ? null : String.valueOf(examStatusObj);
  522 +
  523 + // 刚审核完成的环节编码(receive_order_ + 分厂前缀 + 名称缩写)
  524 + Object nodeObj = map.get("nodeCode");
  525 + String nodeCode = nodeObj == null ? null : String.valueOf(nodeObj);
  526 +
  527 + // 业务ID(兼容 variables 子 map 包裹)
  528 + String bizId = resolveBizId(map);
  529 + if (StringUtil.isBlank(bizId)) {
  530 + throw new DefaultClientException("仓库收料单审核回调缺少业务ID!");
  531 + }
  532 +
  533 + // 各审核环节匹配(nodeCode 尾部名称缩写,兼容分厂前缀 yfc/efc/sfc/ztfc)
  534 + boolean fzcktjyNode = nodeCode != null && nodeCode.endsWith("fzcktjy");
  535 + boolean fzckzjyNode = nodeCode != null && nodeCode.endsWith("fzckzjy");
  536 + boolean gyglkzjyNode = nodeCode != null && nodeCode.endsWith("gyglkzjy");
  537 + boolean fzckzgNode = nodeCode != null && nodeCode.endsWith("fzckzg");
  538 + boolean gyglkzgNode = nodeCode != null && nodeCode.endsWith("gyglkzg");
  539 + boolean gybzgNode = nodeCode != null && nodeCode.endsWith("gybzg");
  540 +
  541 + // 审核通过时记录当前环节审核人(人员ID和名称)
  542 + boolean pass = "PASS".equals(examStatus);
  543 + String userId = null;
  544 + String userName = null;
  545 + if (pass) {
  546 + userId = SecurityUtil.getCurrentUser().getId();
  547 + userName = SecurityUtil.getCurrentUser().getName();
  548 + }
  549 +
  550 + // 拒绝/撤销/终止:统一回到原料核算岗(制单)
  551 + if (StringUtil.isNotBlank(examStatus) && !pass) {
  552 + this.update(Wrappers.lambdaUpdate(ProcurementWarehouseReceiveOrder.class)
  553 + .set(ProcurementWarehouseReceiveOrder::getFlowNode, NODE_YLHSG)
  554 + .eq(ProcurementWarehouseReceiveOrder::getId, bizId));
  555 + // 分厂仓库统计员环节拒绝时同样保存审核页调整的实收数
  556 + if (fzcktjyNode) {
  557 + saveActualQuantityFromFlow(bizId, map);
  558 + }
  559 + return;
  560 + }
  561 +
  562 + // 审核通过:按刚审核完成的环节编码推进到下一节点
  563 + // (供应部主管环节通过即流程结束,flow_node 由终态回调一并清空)
  564 + String nextNode = nextFlowNode(nodeCode);
  565 +
  566 + // 未匹配到审核环节且无节点推进,忽略
  567 + if (nextNode == null && !fzcktjyNode && !fzckzjyNode && !gyglkzjyNode
  568 + && !fzckzgNode && !gyglkzgNode && !gybzgNode) {
  569 + return;
  570 + }
  571 +
  572 + this.update(Wrappers.lambdaUpdate(ProcurementWarehouseReceiveOrder.class)
  573 + .set(fzcktjyNode, ProcurementWarehouseReceiveOrder::getFzcktjyId, userId)
  574 + .set(fzcktjyNode, ProcurementWarehouseReceiveOrder::getFzcktjyName, userName)
  575 + .set(fzckzjyNode, ProcurementWarehouseReceiveOrder::getFzckzjyId, userId)
  576 + .set(fzckzjyNode, ProcurementWarehouseReceiveOrder::getFzckzjyName, userName)
  577 + .set(gyglkzjyNode, ProcurementWarehouseReceiveOrder::getGyglkzjyId, userId)
  578 + .set(gyglkzjyNode, ProcurementWarehouseReceiveOrder::getGyglkzjyName, userName)
  579 + .set(fzckzgNode, ProcurementWarehouseReceiveOrder::getFzckzgId, userId)
  580 + .set(fzckzgNode, ProcurementWarehouseReceiveOrder::getFzckzgName, userName)
  581 + .set(gyglkzgNode, ProcurementWarehouseReceiveOrder::getGyglkzgId, userId)
  582 + .set(gyglkzgNode, ProcurementWarehouseReceiveOrder::getGyglkzgName, userName)
  583 + .set(gybzgNode, ProcurementWarehouseReceiveOrder::getGybzgId, userId)
  584 + .set(gybzgNode, ProcurementWarehouseReceiveOrder::getGybzgName, userName)
  585 + .set(nextNode != null, ProcurementWarehouseReceiveOrder::getFlowNode, nextNode)
  586 + .eq(ProcurementWarehouseReceiveOrder::getId, bizId));
  587 +
  588 + // 分厂仓库统计员环节通过时保存审核页调整的实收数
  589 + if (fzcktjyNode) {
  590 + saveActualQuantityFromFlow(bizId, map);
  591 + }
  592 + } catch (Exception ex) {
  593 + ex.printStackTrace();
  594 + }
  595 + }
  596 +
  597 + /**
  598 + * 分厂仓库统计员环节审核回调:解析审核请求携带的明细实收数(兼容 variables 子 map 包裹),
  599 + * 调用 updateActualQuantity 更新(通过/拒绝均需保存)
  600 + */
  601 + private void saveActualQuantityFromFlow(String bizId, Map<String, Object> map) {
  602 + try {
  603 + UpdateWarehouseReceiveActualQuantityVo vo = null;
  604 + // 优先从 variables 子 map 解析(前端审核时业务数据经流程变量回传)
  605 + Object varsObj = map.get("variables");
  606 + if (varsObj instanceof Map) {
  607 + vo = JsonUtil.parseObject(JsonUtil.toJsonString(varsObj),
  608 + UpdateWarehouseReceiveActualQuantityVo.class);
  609 + }
  610 + if (vo == null || CollectionUtil.isEmpty(vo.getLines())) {
  611 + vo = JsonUtil.parseObject(JsonUtil.toJsonString(map),
  612 + UpdateWarehouseReceiveActualQuantityVo.class);
  613 + }
  614 + if (vo == null || CollectionUtil.isEmpty(vo.getLines())) {
  615 + return;
  616 + }
  617 + vo.setId(bizId);
  618 + updateActualQuantity(vo);
  619 + } catch (Exception ex) {
  620 + // 保存实收数失败不影响流程状态推进,仅记录日志
  621 + log.error("分厂仓库统计员环节审核回调保存实收数失败,bizId:{}", bizId, ex);
  622 + }
  623 + }
  624 +
  625 + @Override
  626 + @Transactional(rollbackFor = Exception.class)
  627 + public void deleteBySettleDetailId(String settleDetailId) {
  628 + if (StringUtil.isBlank(settleDetailId)) {
  629 + return;
  630 + }
  631 +
  632 + // 该结算详情单下所有未作废的仓库收料单,联动作废
  633 + List<ProcurementWarehouseReceiveOrder> orders = this.list(
  634 + Wrappers.lambdaQuery(ProcurementWarehouseReceiveOrder.class)
  635 + .eq(ProcurementWarehouseReceiveOrder::getSettleDetailId, settleDetailId)
  636 + .eq(ProcurementWarehouseReceiveOrder::getDeleted, false));
  637 + if (CollectionUtil.isEmpty(orders)) {
  638 + return;
  639 + }
  640 +
  641 + for (ProcurementWarehouseReceiveOrder order : orders) {
  642 + // 审核中的先终止流程,再作废
  643 + if (STATUS_AUDIT.equals(order.getApprovalStatus())) {
  644 + terminateRunningFlow(order.getId());
  645 + }
  646 + this.update(Wrappers.lambdaUpdate(ProcurementWarehouseReceiveOrder.class)
  647 + .set(ProcurementWarehouseReceiveOrder::getDeleted, true)
  648 + .set(STATUS_AUDIT.equals(order.getApprovalStatus()),
  649 + ProcurementWarehouseReceiveOrder::getApprovalStatus, STATUS_REFUSE)
  650 + .eq(ProcurementWarehouseReceiveOrder::getId, order.getId()));
  651 + }
  652 + }
  653 +
  654 + /**
  655 + * 码单下是否存在有效仓库收料单(非已取消、非已作废;结算详情单退回校验/可制单校验用)
  656 + */
  657 + @Override
  658 + public boolean existsBySettleDetailId(String settleDetailId) {
  659 + if (StringUtil.isBlank(settleDetailId)) {
  660 + return false;
  661 + }
  662 + return this.count(Wrappers.lambdaQuery(ProcurementWarehouseReceiveOrder.class)
  663 + .eq(ProcurementWarehouseReceiveOrder::getSettleDetailId, settleDetailId)
  664 + .eq(ProcurementWarehouseReceiveOrder::getDeleted, false)
  665 + .ne(ProcurementWarehouseReceiveOrder::getApprovalStatus, STATUS_CANCEL)) > 0;
  666 + }
  667 +
  668 + /**
  669 + * 保存明细(数量、单价、金额均由前端计算传入,后端只保存)
  670 + */
  671 + private void saveLines(String receiveOrderId, List<WarehouseReceiveOrderLineVo> lineVos) {
  672 + if (CollectionUtil.isEmpty(lineVos)) {
  673 + throw new DefaultClientException("明细不能为空!");
  674 + }
  675 + int orderNo = 1;
  676 + for (WarehouseReceiveOrderLineVo lineVo : lineVos) {
  677 + ProcurementWarehouseReceiveOrderLine line = new ProcurementWarehouseReceiveOrderLine();
  678 + BeanUtil.copyProperties(lineVo, line);
  679 + line.setId(IdUtil.getId());
  680 + line.setReceiveOrderId(receiveOrderId);
  681 + line.setOrderNo(orderNo++);
  682 + receiveLineService.save(line);
  683 + }
  684 + }
  685 +
  686 + /**
  687 + * 结算详情单可用校验:审核通过、未作废、未生成过仓库收料单
  688 + * (planCodes/planIds 为联表字段 exist=false,MP 单表查询带不出,必须用 findById,
  689 + * 否则收料单主表 plan_codes/plan_ids 存 null,详情页计划编号与网价计算失效)
  690 + */
  691 + private ProcurementMaterialSettleDetail assertSettleUsable(String settleDetailId) {
  692 + ProcurementMaterialSettleDetail settle = settleDetailMapper.findById(settleDetailId);
  693 + if (settle == null || Boolean.TRUE.equals(settle.getDeleted())) {
  694 + throw new DefaultClientException("原料结算详情单不存在!");
  695 + }
  696 + if (!STATUS_PASS.equals(settle.getApprovalStatus())) {
  697 + throw new DefaultClientException("仅审核通过的原料结算详情单可生成仓库收料单!");
  698 + }
  699 + if (existsBySettleDetailId(settleDetailId)) {
  700 + throw new DefaultClientException("该原料结算详情单已生成仓库收料单!");
  701 + }
  702 + return settle;
  703 + }
  704 +
  705 + /**
  706 + * 采购数:买断 = 申请净重 - 退料 - 折斤(对应关系缺失则为空);经销 = 入库净重
  707 + */
  708 + private BigDecimal calcPurchaseQuantity(boolean buyout, ProcurementMaterialSettleLine settleLine,
  709 + Map<String, BigDecimal> applyQuantityMap) {
  710 + BigDecimal returnWeight = nvl(settleLine.getReturnWeight());
  711 + BigDecimal foldWeight = nvl(settleLine.getFoldWeight());
  712 + if (buyout) {
  713 + BigDecimal applyQuantity = settleLine.getProductId() == null ? null
  714 + : applyQuantityMap.get(settleLine.getProductId());
  715 + if (applyQuantity == null) {
  716 + return null;
  717 + }
  718 + return applyQuantity.subtract(returnWeight).subtract(foldWeight);
  719 + }
  720 + return settleLine.getNetWeight();
  721 + }
  722 +
  723 + /**
  724 + * 含税单价:计划实际采购价/1000(同一计划多个同一品种、或多个计划同一品种时不带入,为空)
  725 + */
  726 + private BigDecimal resolveTaxPrice(ProcurementMaterialSettleLine settleLine) {
  727 + if (StringUtil.isBlank(settleLine.getProcurementPlanId()) || StringUtil.isBlank(settleLine.getProductId())) {
  728 + return null;
  729 + }
  730 + List<ProcurementPlanLine> planLines = procurementPlanLineService.list(
  731 + Wrappers.lambdaQuery(ProcurementPlanLine.class)
  732 + .eq(ProcurementPlanLine::getProcurementPlanId, settleLine.getProcurementPlanId())
  733 + .eq(ProcurementPlanLine::getProductId, settleLine.getProductId()));
  734 + if (CollectionUtil.isEmpty(planLines) || planLines.size() > 1) {
  735 + return null;
  736 + }
  737 + return planLines.get(0).getActualPurchasePrice() == null ? null
  738 + : planLines.get(0).getActualPurchasePrice().divide(new BigDecimal("1000"));
  739 + }
  740 +
  741 + /**
  742 + * 规格型号:材料编号(品种关系ID)对应品种关系表的类型
  743 + */
  744 + private void fillSpecModels(List<WarehouseReceiveOrderLineVo> lines) {
  745 + if (CollectionUtil.isEmpty(lines)) {
  746 + return;
  747 + }
  748 + List<String> productIds = lines.stream()
  749 + .map(WarehouseReceiveOrderLineVo::getProductId)
  750 + .filter(StringUtil::isNotBlank)
  751 + .distinct()
  752 + .collect(Collectors.toList());
  753 + if (CollectionUtil.isEmpty(productIds)) {
  754 + return;
  755 + }
  756 + Map<String, String> specModelMap = breedRelationshipService.listByIds(productIds).stream()
  757 + .filter(b -> b != null && b.getType() != null)
  758 + .collect(Collectors.toMap(BreedRelationship::getId, BreedRelationship::getType, (v1, v2) -> v1));
  759 + for (WarehouseReceiveOrderLineVo line : lines) {
  760 + line.setSpecModel(specModelMap.get(line.getProductId()));
  761 + }
  762 + }
  763 +
  764 + /**
  765 + * 台账网价:计划单时间(最早计划创建时间)与过磅码单时间(第一次毛重时间)对应的上海有色网1#电铜均价,两日均差超过800提醒
  766 + */
  767 + private void fillOnlinePriceInfo(GetWarehouseReceiveOrderBo bo, ProcurementWarehouseReceiveOrder entity) {
  768 + // 计划单时间:最早计划的创建时间
  769 + LocalDateTime planTime = null;
  770 + List<String> planIds = splitIdList(entity.getPlanIds());
  771 + if (CollectionUtil.isNotEmpty(planIds)) {
  772 + List<ProcurementPlan> plans = procurementPlanService.listByIds(planIds);
  773 + for (ProcurementPlan plan : plans) {
  774 + if (plan != null && plan.getCreateTime() != null
  775 + && (planTime == null || plan.getCreateTime().isBefore(planTime))) {
  776 + planTime = plan.getCreateTime();
  777 + }
  778 + }
  779 + }
  780 + // 过磅码单时间:第一次毛重时间
  781 + LocalDateTime ticketTime = null;
  782 + if (StringUtil.isNotBlank(entity.getWeighingTicketId())) {
  783 + ProcurementWeighingTicket ticket = weighingTicketMapper.findById(entity.getWeighingTicketId());
  784 + if (ticket != null && ticket.getFirstGrossWeightTime() != null) {
  785 + ticketTime = ticket.getFirstGrossWeightTime();
  786 + }
  787 + }
  788 +
  789 + bo.setPlanTime(planTime);
  790 + bo.setTicketTime(ticketTime);
  791 + BigDecimal planPrice = queryOnlinePrice(planTime);
  792 + BigDecimal ticketPrice = queryOnlinePrice(ticketTime);
  793 + bo.setPlanOnlinePrice(planPrice);
  794 + bo.setTicketOnlinePrice(ticketPrice);
  795 + if (planPrice != null && ticketPrice != null) {
  796 + BigDecimal diff = ticketPrice.subtract(planPrice);
  797 + bo.setPriceDiff(diff);
  798 + bo.setPriceWarn(diff.abs().compareTo(PRICE_WARN_THRESHOLD) > 0);
  799 + }
  800 + }
  801 +
  802 + /**
  803 + * 按日期查询上海有色网1#电铜网价均价(无记录返回 null)
  804 + */
  805 + private BigDecimal queryOnlinePrice(LocalDateTime time) {
  806 + if (time == null) {
  807 + return null;
  808 + }
  809 + BaseDataOnlinePrice onlinePrice = baseDataOnlinePriceService.getOne(
  810 + Wrappers.lambdaQuery(BaseDataOnlinePrice.class)
  811 + .eq(BaseDataOnlinePrice::getRecordDate, time.toLocalDate())
  812 + .last("LIMIT 1"));
  813 + return onlinePrice == null ? null : onlinePrice.getShCopper1Avg();
  814 + }
  815 +
  816 + /**
  817 + * 按刚审核完成的环节编码(nodeCode 尾部名称缩写,兼容分厂前缀 yfc/efc/sfc/ztfc)推进到下一流程节点;
  818 + * 供应部主管环节通过返回 null(流程结束,flow_node 由终态回调清空)
  819 + */
  820 + private String nextFlowNode(String nodeCode) {
  821 + if (StringUtil.isBlank(nodeCode)) {
  822 + return null;
  823 + }
  824 + if (nodeCode.endsWith("fzcktjy")) {
  825 + return NODE_FZCKZJY;
  826 + }
  827 + if (nodeCode.endsWith("fzckzjy")) {
  828 + return NODE_GYGLKZJY;
  829 + }
  830 + if (nodeCode.endsWith("gyglkzjy")) {
  831 + return NODE_FZCKZG;
  832 + }
  833 + if (nodeCode.endsWith("fzckzg")) {
  834 + return NODE_GYGLKZG;
  835 + }
  836 + if (nodeCode.endsWith("gyglkzg")) {
  837 + return NODE_GYBZG;
  838 + }
  839 + if (nodeCode.endsWith("gybzg")) {
  840 + return null;
  841 + }
  842 + return null;
  843 + }
  844 +
  845 + /**
  846 + * 从回调参数解析业务ID(兼容 variables 子 map 包裹)
  847 + */
  848 + private String resolveBizId(Map<String, Object> map) {
  849 + Object id = map.get("id");
  850 + String bizId = id == null ? null : String.valueOf(id);
  851 + if (StringUtil.isBlank(bizId) || "null".equals(bizId)) {
  852 + Object bizIdObj = map.get("bizId");
  853 + bizId = bizIdObj == null ? null : String.valueOf(bizIdObj);
  854 + }
  855 + if (StringUtil.isBlank(bizId) || "null".equals(bizId)) {
  856 + Object variables = map.get("variables");
  857 + if (variables instanceof Map) {
  858 + Map<?, ?> variablesMap = (Map<?, ?>) variables;
  859 + Object vId = variablesMap.get("id");
  860 + if (vId == null) {
  861 + vId = variablesMap.get("bizId");
  862 + }
  863 + bizId = vId == null ? null : String.valueOf(vId);
  864 + }
  865 + }
  866 + return bizId;
  867 + }
  868 +
  869 + /**
  870 + * 终止单据进行中的审核流程(作废审核中的单据前先终止流程)
  871 + */
  872 + private void terminateRunningFlow(String businessId) {
  873 + List<FlowInstanceWrapper> flowList = flowInstanceWrapperService.getFlowByBusinessIdList(
  874 + Collections.singletonList(businessId));
  875 + if (CollectionUtil.isEmpty(flowList)) {
  876 + return;
  877 + }
  878 + flowList.stream()
  879 + .filter(f -> f != null && f.getId() != null)
  880 + .findFirst()
  881 + .ifPresent(flow -> flowTaskWrapperService.termination(flow.getId()));
  882 + }
  883 +
  884 + /**
  885 + * 审核按钮标记:待办驱动(列表 + 详情两条返回路径都要调用)
  886 + */
  887 + private void fillOperateFlags(List<ProcurementWarehouseReceiveOrder> datas) {
  888 + if (CollectionUtil.isEmpty(datas)) {
  889 + return;
  890 + }
  891 +
  892 + List<String> businessIds = datas.stream()
  893 + .filter(java.util.Objects::nonNull)
  894 + .map(ProcurementWarehouseReceiveOrder::getId)
  895 + .collect(Collectors.toList());
  896 +
  897 + List<FlowInstanceWrapper> flowList = flowInstanceWrapperService.getFlowByBusinessIdList(businessIds);
  898 + Set<String> flowBusinessIdSet = CollectionUtil.isNotEmpty(flowList)
  899 + ? flowList.stream().map(FlowInstanceWrapper::getBusinessId).collect(Collectors.toSet())
  900 + : new HashSet<>();
  901 +
  902 + List<FlowTaskDto> todoFlowTaskList = flowTaskWrapperMapper.queryTodoList(
  903 + new QueryTodoTaskListVo(), SecurityUtil.getCurrentUser().getId());
  904 + Set<String> todoBusinessIdSet = CollectionUtil.isNotEmpty(todoFlowTaskList)
  905 + ? todoFlowTaskList.stream().map(FlowTaskDto::getBusinessId).collect(Collectors.toSet())
  906 + : new HashSet<>();
  907 +
  908 + for (ProcurementWarehouseReceiveOrder data : datas) {
  909 + if (data == null) {
  910 + continue;
  911 + }
  912 + boolean hasFlow = flowBusinessIdSet.contains(data.getId());
  913 + boolean hasTodo = todoBusinessIdSet.contains(data.getId());
  914 + data.setShowExamine(hasTodo && STATUS_AUDIT.equals(data.getApprovalStatus()));
  915 + data.setShowExamineDetail(hasFlow && StringUtil.isNotBlank(data.getApprovalStatus()));
  916 + }
  917 + }
  918 +
  919 + /**
  920 + * 作废单校验:作废单只能查看
  921 + */
  922 + private void assertValid(ProcurementWarehouseReceiveOrder entity) {
  923 + if (Boolean.TRUE.equals(entity.getDeleted())) {
  924 + throw new DefaultClientException("作废单据只能查看,不允许该操作!");
  925 + }
  926 + }
  927 +
  928 + /**
  929 + * 编辑校验:仅草稿、已驳回可修改
  930 + */
  931 + private void assertEditable(ProcurementWarehouseReceiveOrder entity) {
  932 + if (!STATUS_DRAFT.equals(entity.getApprovalStatus()) && !STATUS_REFUSE.equals(entity.getApprovalStatus())) {
  933 + throw new DefaultClientException("当前单据状态不允许修改!");
  934 + }
  935 + }
  936 +
  937 + /**
  938 + * 当前用户可见分厂代号集合(按角色编码前缀推导,多分厂角色为并集;无分厂前缀角色返回空集合=不限制)
  939 + */
  940 + private List<String> getCurrentUserWorkshopCodes() {
  941 + List<String> workshopCodeList = new ArrayList<>();
  942 + List<SysRole> roleList = sysRoleService.getByUserId(SecurityUtil.getCurrentUser().getId());
  943 + for (SysRole role : roleList) {
  944 + String roleCode = role.getCode();
  945 + if (StringUtil.isBlank(roleCode)) {
  946 + continue;
  947 + }
  948 + String workshopCode = null;
  949 + if (roleCode.startsWith("yfc")) {
  950 + workshopCode = "yfc";
  951 + } else if (roleCode.startsWith("efc")) {
  952 + workshopCode = "efc";
  953 + } else if (roleCode.startsWith("sfc")) {
  954 + workshopCode = "sfc";
  955 + } else if (roleCode.startsWith("ztfc") || roleCode.startsWith("ztc")) {
  956 + workshopCode = "ztfc";
  957 + }
  958 + if (StringUtil.isNotBlank(workshopCode) && !workshopCodeList.contains(workshopCode)) {
  959 + workshopCodeList.add(workshopCode);
  960 + }
  961 + }
  962 + return workshopCodeList;
  963 + }
  964 +
  965 + private BigDecimal nvl(BigDecimal value) {
  966 + return value == null ? BigDecimal.ZERO : value;
  967 + }
  968 +
  969 + private LocalDate nextDay(LocalDate date) {
  970 + return date == null ? null : date.plusDays(1);
  971 + }
  972 +
  973 + /**
  974 + * 计划编号集合展示:plan_codes 拆分(兼容中英文逗号)
  975 + */
  976 + private List<String> splitToList(String planCodes) {
  977 + if (StringUtil.isBlank(planCodes)) {
  978 + return new ArrayList<>();
  979 + }
  980 + List<String> result = new ArrayList<>();
  981 + for (String item : planCodes.split("[,,]")) {
  982 + if (StringUtil.isNotBlank(item)) {
  983 + result.add(item.trim());
  984 + }
  985 + }
  986 + return result;
  987 + }
  988 +
  989 + private List<String> splitIdList(String planIds) {
  990 + if (StringUtil.isBlank(planIds)) {
  991 + return new ArrayList<>();
  992 + }
  993 + List<String> result = new ArrayList<>();
  994 + for (String item : planIds.split("[,,]")) {
  995 + if (StringUtil.isNotBlank(item)) {
  996 + result.add(item.trim());
  997 + }
  998 + }
  999 + return result;
  1000 + }
  1001 +}
@@ -41,6 +41,7 @@ import com.lframework.xingyun.sc.procurement.mappers.settle.ProcurementMaterialS @@ -41,6 +41,7 @@ import com.lframework.xingyun.sc.procurement.mappers.settle.ProcurementMaterialS
41 import com.lframework.xingyun.sc.procurement.mappers.weighing.ProcurementAssayReportMapper; 41 import com.lframework.xingyun.sc.procurement.mappers.weighing.ProcurementAssayReportMapper;
42 import com.lframework.xingyun.sc.procurement.mappers.weighing.ProcurementWeighingTicketMapper; 42 import com.lframework.xingyun.sc.procurement.mappers.weighing.ProcurementWeighingTicketMapper;
43 import com.lframework.xingyun.sc.procurement.service.plan.ProcurementPlanService; 43 import com.lframework.xingyun.sc.procurement.service.plan.ProcurementPlanService;
  44 +import com.lframework.xingyun.sc.procurement.service.receive.ProcurementWarehouseReceiveOrderService;
44 import com.lframework.xingyun.sc.procurement.service.settle.ProcurementMaterialSettleApplyLineService; 45 import com.lframework.xingyun.sc.procurement.service.settle.ProcurementMaterialSettleApplyLineService;
45 import com.lframework.xingyun.sc.procurement.service.settle.ProcurementMaterialSettleDetailService; 46 import com.lframework.xingyun.sc.procurement.service.settle.ProcurementMaterialSettleDetailService;
46 import com.lframework.xingyun.sc.procurement.service.settle.ProcurementMaterialSettleLineService; 47 import com.lframework.xingyun.sc.procurement.service.settle.ProcurementMaterialSettleLineService;
@@ -123,6 +124,9 @@ public class ProcurementMaterialSettleDetailServiceImpl @@ -123,6 +124,9 @@ public class ProcurementMaterialSettleDetailServiceImpl
123 private ProcurementWeighingTicketMapper weighingTicketMapper; 124 private ProcurementWeighingTicketMapper weighingTicketMapper;
124 @Resource 125 @Resource
125 private ProcurementWeighingTicketLineService weighLineService; 126 private ProcurementWeighingTicketLineService weighLineService;
  127 +
  128 + @Resource
  129 + private ProcurementWarehouseReceiveOrderService warehouseReceiveOrderService;
126 @Resource 130 @Resource
127 private ProcurementWeighingTicketApplyLineService weighApplyLineService; 131 private ProcurementWeighingTicketApplyLineService weighApplyLineService;
128 @Resource 132 @Resource
@@ -542,6 +546,8 @@ public class ProcurementMaterialSettleDetailServiceImpl @@ -542,6 +546,8 @@ public class ProcurementMaterialSettleDetailServiceImpl
542 if (STATUS_AUDIT.equals(detail.getApprovalStatus())) { 546 if (STATUS_AUDIT.equals(detail.getApprovalStatus())) {
543 terminateRunningFlow(detail.getId()); 547 terminateRunningFlow(detail.getId());
544 } 548 }
  549 + // 联动作废该结算详情单生成的仓库收料单(审核中的先终止流程再作废)
  550 + warehouseReceiveOrderService.deleteBySettleDetailId(detail.getId());
545 this.update(Wrappers.lambdaUpdate(ProcurementMaterialSettleDetail.class) 551 this.update(Wrappers.lambdaUpdate(ProcurementMaterialSettleDetail.class)
546 .set(ProcurementMaterialSettleDetail::getDeleted, true) 552 .set(ProcurementMaterialSettleDetail::getDeleted, true)
547 .set(STATUS_AUDIT.equals(detail.getApprovalStatus()), 553 .set(STATUS_AUDIT.equals(detail.getApprovalStatus()),
@@ -693,7 +699,10 @@ public class ProcurementMaterialSettleDetailServiceImpl @@ -693,7 +699,10 @@ public class ProcurementMaterialSettleDetailServiceImpl
693 * (仓库收料单、买断入库核算单模块尚未上线,上线后在此补充查询校验) 699 * (仓库收料单、买断入库核算单模块尚未上线,上线后在此补充查询校验)
694 */ 700 */
695 private void assertNotReferenced(String settleDetailId) { 701 private void assertNotReferenced(String settleDetailId) {
696 - // TODO 仓库收料单、买断入库核算单上线后补充:存在引用则抛出 DefaultClientException("已生成仓库收料单或买断入库核算单,不可以退回!") 702 + // 已生成仓库收料单的不可以退回
  703 + if (warehouseReceiveOrderService.existsBySettleDetailId(settleDetailId)) {
  704 + throw new DefaultClientException("已生成仓库收料单,不可以退回!");
  705 + }
697 } 706 }
698 707
699 /** 708 /**
  1 +package com.lframework.xingyun.sc.procurement.mappers.receive;
  2 +
  3 +import com.lframework.starter.web.core.mapper.BaseMapper;
  4 +import com.lframework.xingyun.sc.procurement.entity.receive.ProcurementWarehouseReceiveOrderLine;
  5 +
  6 +public interface ProcurementWarehouseReceiveOrderLineMapper
  7 + extends BaseMapper<ProcurementWarehouseReceiveOrderLine> {
  8 +
  9 +}
  1 +package com.lframework.xingyun.sc.procurement.mappers.receive;
  2 +
  3 +import com.lframework.starter.web.core.mapper.BaseMapper;
  4 +import com.lframework.xingyun.sc.procurement.entity.receive.ProcurementWarehouseReceiveOrder;
  5 +import com.lframework.xingyun.sc.procurement.vo.receive.QueryWarehouseReceiveOrderVo;
  6 +import java.util.List;
  7 +import org.apache.ibatis.annotations.Param;
  8 +
  9 +public interface ProcurementWarehouseReceiveOrderMapper
  10 + extends BaseMapper<ProcurementWarehouseReceiveOrder> {
  11 +
  12 + /**
  13 + * 分页查询仓库收料单(数据权限:workshopCodeList 由 Service 按当前用户角色注入)
  14 + */
  15 + List<ProcurementWarehouseReceiveOrder> query(@Param("vo") QueryWarehouseReceiveOrderVo vo,
  16 + @Param("workshopCodeList") List<String> workshopCodeList);
  17 +
  18 + /**
  19 + * 单条查询(联表带出分厂编号 workshopCode;实体传给流程引擎/分厂审核节点路由前必须用此方法)
  20 + */
  21 + ProcurementWarehouseReceiveOrder findById(@Param("id") String id);
  22 +}
  1 +package com.lframework.xingyun.sc.procurement.service.receive;
  2 +
  3 +import com.lframework.starter.web.core.service.BaseMpService;
  4 +import com.lframework.xingyun.sc.procurement.entity.receive.ProcurementWarehouseReceiveOrderLine;
  5 +import java.util.List;
  6 +
  7 +public interface ProcurementWarehouseReceiveOrderLineService
  8 + extends BaseMpService<ProcurementWarehouseReceiveOrderLine> {
  9 +
  10 + /**
  11 + * 按仓库收料单ID查询明细(按排序号排序)
  12 + */
  13 + List<ProcurementWarehouseReceiveOrderLine> getByReceiveOrderId(String receiveOrderId);
  14 +
  15 + /**
  16 + * 按仓库收料单ID删除明细
  17 + */
  18 + void deleteByReceiveOrderId(String receiveOrderId);
  19 +}
  1 +package com.lframework.xingyun.sc.procurement.service.receive;
  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.GetWarehouseReceiveOrderBo;
  6 +import com.lframework.xingyun.sc.bo.procurement.GetWarehouseReceiveSettleDataBo;
  7 +import com.lframework.xingyun.sc.procurement.entity.receive.ProcurementWarehouseReceiveOrder;
  8 +import com.lframework.xingyun.sc.procurement.vo.receive.CreateWarehouseReceiveOrderVo;
  9 +import com.lframework.xingyun.sc.procurement.vo.receive.QueryWarehouseReceiveOrderVo;
  10 +import com.lframework.xingyun.sc.procurement.vo.receive.UpdateWarehouseReceiveActualQuantityVo;
  11 +import com.lframework.xingyun.sc.procurement.vo.receive.UpdateWarehouseReceiveOrderVo;
  12 +
  13 +import java.util.List;
  14 +import java.util.Map;
  15 +
  16 +public interface ProcurementWarehouseReceiveOrderService
  17 + extends BaseMpService<ProcurementWarehouseReceiveOrder> {
  18 +
  19 + /**
  20 + * 分页查询仓库收料单(列表)
  21 + */
  22 + PageResult<ProcurementWarehouseReceiveOrder> query(Integer pageIndex, Integer pageSize,
  23 + QueryWarehouseReceiveOrderVo vo);
  24 +
  25 + /**
  26 + * 详情(主表 + 明细 + 台账网价提示:计划单时间/过磅码单时间的上海有色网1#电铜均价,两日均差超过800提醒)
  27 + */
  28 + GetWarehouseReceiveOrderBo findDetail(String id);
  29 +
  30 + /**
  31 + * 可制单的原料结算详情单下拉(审核通过且未生成过仓库收料单)
  32 + */
  33 + List<GetWarehouseReceiveSettleDataBo> getSettleOptions();
  34 +
  35 + /**
  36 + * 新增页:按原料结算详情单带出数据(日期+1天、材料来源、计划编号、分厂、明细自动计算;
  37 + * 没有类别(category)的结算明细行不代入;买断采购数=申请净重-退料-折斤,经销采购数=入库净重)
  38 + */
  39 + GetWarehouseReceiveSettleDataBo getSettleData(String settleDetailId);
  40 +
  41 + /**
  42 + * 新增仓库收料单(草稿,原料核算岗-供应管理科)
  43 + */
  44 + String create(CreateWarehouseReceiveOrderVo vo);
  45 +
  46 + /**
  47 + * 修改仓库收料单(仅草稿、已驳回可修改)
  48 + */
  49 + void update(UpdateWarehouseReceiveOrderVo vo);
  50 +
  51 + /**
  52 + * 提交仓库收料单审核(草稿、已驳回可提交)
  53 + */
  54 + void submit(String id);
  55 +
  56 + /**
  57 + * 取消仓库收料单(草稿、已驳回状态可取消)
  58 + */
  59 + void cancel(String id);
  60 +
  61 + /**
  62 + * 调整实收数(仅审核中且流程节点为分厂仓库统计员时可调整,其他审核环节无数据操作权限;合计由前端计算传入保存)
  63 + */
  64 + void updateActualQuantity(UpdateWarehouseReceiveActualQuantityVo vo);
  65 +
  66 + /**
  67 + * 审核流程回调更新审核状态(流程结束时由 BusinessDataHandlerService 调用)
  68 + */
  69 + void updateApprovalStatus(String id, String approvalStatus);
  70 +
  71 + /**
  72 + * 审核过程回调:更新流程节点(nodeCode 尾部环节缩写兼容分厂前缀,拒绝/撤销/终止统一回原料核算岗制单节点)
  73 + */
  74 + void updateNoFlowInstance(Map<String, Object> map);
  75 +
  76 + /**
  77 + * 按原料结算详情单作废仓库收料单(结算详情单退回/作废联动,审核中的先终止流程)
  78 + */
  79 + void deleteBySettleDetailId(String settleDetailId);
  80 +
  81 + /**
  82 + * 是否存在有效仓库收料单(非已取消、非已作废;结算详情单退回校验/可制单校验用)
  83 + */
  84 + boolean existsBySettleDetailId(String settleDetailId);
  85 +}
  1 +package com.lframework.xingyun.sc.procurement.vo.receive;
  2 +
  3 +import com.fasterxml.jackson.annotation.JsonFormat;
  4 +import com.lframework.starter.common.constants.StringPool;
  5 +import io.swagger.annotations.ApiModelProperty;
  6 +import lombok.Data;
  7 +
  8 +import javax.validation.Valid;
  9 +import javax.validation.constraints.NotBlank;
  10 +import javax.validation.constraints.NotEmpty;
  11 +import java.io.Serializable;
  12 +import java.math.BigDecimal;
  13 +import java.time.LocalDate;
  14 +import java.util.List;
  15 +
  16 +@Data
  17 +public class CreateWarehouseReceiveOrderVo implements Serializable {
  18 +
  19 + private static final long serialVersionUID = 1L;
  20 +
  21 + @NotBlank(message = "原料结算详情单不能为空!")
  22 + @ApiModelProperty("原料结算详情单ID(来源单)")
  23 + private String settleDetailId;
  24 +
  25 + @JsonFormat(pattern = StringPool.DATE_PATTERN)
  26 + @ApiModelProperty("日期(默认原料结算详情单日期+1天)")
  27 + private LocalDate ticketDate;
  28 +
  29 + @ApiModelProperty("材料来源(默认原料结算详情单的单位)")
  30 + private String materialSource;
  31 +
  32 + @ApiModelProperty("备注(多行文本)")
  33 + private String remark;
  34 +
  35 + @ApiModelProperty("附件文件ID集合(多文件,逗号分隔)")
  36 + private String attachmentFileIds;
  37 +
  38 + @ApiModelProperty("附件文件名称集合")
  39 + private String attachmentFileNames;
  40 +
  41 + @ApiModelProperty("合计-采购数大写(前端计算传入)")
  42 + private String totalPurchaseQuantityCap;
  43 +
  44 + @ApiModelProperty("合计-实收数 kg(前端计算传入)")
  45 + private BigDecimal totalActualQuantity;
  46 +
  47 + @ApiModelProperty("合计-含税金额(前端计算传入)")
  48 + private BigDecimal totalTaxAmount;
  49 +
  50 + @NotEmpty(message = "明细不能为空!")
  51 + @Valid
  52 + @ApiModelProperty("明细数据")
  53 + private List<WarehouseReceiveOrderLineVo> lines;
  54 +}
  1 +package com.lframework.xingyun.sc.procurement.vo.receive;
  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 +
  13 +@Data
  14 +@ApiModel("查询仓库收料单")
  15 +public class QueryWarehouseReceiveOrderVo extends SortPageVo implements Serializable {
  16 +
  17 + private static final long serialVersionUID = 1L;
  18 +
  19 + @ApiModelProperty("码单编号(模糊匹配)")
  20 + private String weighingTicketCode;
  21 +
  22 + @ApiModelProperty("计划编号(模糊匹配)")
  23 + private String planCode;
  24 +
  25 + @ApiModelProperty("日期-开始")
  26 + @JsonFormat(pattern = StringPool.DATE_PATTERN)
  27 + private LocalDate ticketDateStart;
  28 +
  29 + @ApiModelProperty("日期-结束")
  30 + @JsonFormat(pattern = StringPool.DATE_PATTERN)
  31 + private LocalDate ticketDateEnd;
  32 +
  33 + @ApiModelProperty("客户名称/材料来源(模糊匹配)")
  34 + private String materialSource;
  35 +
  36 + @ApiModelProperty("分厂ID")
  37 + private String workshopId;
  38 +
  39 + @ApiModelProperty("流程节点 YHGG/FZCKTJY/FZCKZJY/GYGLKZJY/FZCKZG/GYGLKZG/GYBZG")
  40 + private String flowNode;
  41 +
  42 + @ApiModelProperty("审核状态 DRAFT/AUDIT/PASS/REFUSE/CANCEL")
  43 + private String approvalStatus;
  44 +
  45 + @ApiModelProperty("是否作废 true-已作废 false-有效单(不传默认查有效单)")
  46 + private Boolean deleted;
  47 +}
  1 +package com.lframework.xingyun.sc.procurement.vo.receive;
  2 +
  3 +import io.swagger.annotations.ApiModelProperty;
  4 +import lombok.Data;
  5 +
  6 +import javax.validation.Valid;
  7 +import javax.validation.constraints.NotBlank;
  8 +import javax.validation.constraints.NotEmpty;
  9 +import java.io.Serializable;
  10 +import java.math.BigDecimal;
  11 +import java.util.List;
  12 +
  13 +/**
  14 + * 调整仓库收料单实收数(仅分厂仓库统计员审核环节,合计由前端计算传入)
  15 + */
  16 +@Data
  17 +public class UpdateWarehouseReceiveActualQuantityVo implements Serializable {
  18 +
  19 + private static final long serialVersionUID = 1L;
  20 +
  21 + @NotBlank(message = "ID不能为空!")
  22 + @ApiModelProperty("仓库收料单ID")
  23 + private String id;
  24 +
  25 + @NotEmpty(message = "明细不能为空!")
  26 + @Valid
  27 + @ApiModelProperty("明细行(行ID + 实收数)")
  28 + private List<WarehouseReceiveOrderLineVo> lines;
  29 +
  30 + @ApiModelProperty("合计-采购数大写(前端计算传入)")
  31 + private String totalPurchaseQuantityCap;
  32 +
  33 + @ApiModelProperty("合计-实收数 kg(前端计算传入)")
  34 + private BigDecimal totalActualQuantity;
  35 +
  36 + @ApiModelProperty("合计-含税金额(前端计算传入)")
  37 + private BigDecimal totalTaxAmount;
  38 +}
  1 +package com.lframework.xingyun.sc.procurement.vo.receive;
  2 +
  3 +import com.fasterxml.jackson.annotation.JsonFormat;
  4 +import com.lframework.starter.common.constants.StringPool;
  5 +import io.swagger.annotations.ApiModelProperty;
  6 +import lombok.Data;
  7 +import lombok.EqualsAndHashCode;
  8 +
  9 +import javax.validation.Valid;
  10 +import javax.validation.constraints.NotBlank;
  11 +import javax.validation.constraints.NotEmpty;
  12 +import java.time.LocalDate;
  13 +import java.util.List;
  14 +
  15 +@Data
  16 +@EqualsAndHashCode(callSuper = true)
  17 +public class UpdateWarehouseReceiveOrderVo extends CreateWarehouseReceiveOrderVo implements
  18 + java.io.Serializable {
  19 +
  20 + private static final long serialVersionUID = 1L;
  21 +
  22 + @NotBlank(message = "ID不能为空!")
  23 + @ApiModelProperty("ID")
  24 + private String id;
  25 +}
  1 +package com.lframework.xingyun.sc.procurement.vo.receive;
  2 +
  3 +import io.swagger.annotations.ApiModelProperty;
  4 +import lombok.Data;
  5 +
  6 +import java.io.Serializable;
  7 +import java.math.BigDecimal;
  8 +
  9 +/**
  10 + * 仓库收料单明细行(新增/修改共用)
  11 + */
  12 +@Data
  13 +public class WarehouseReceiveOrderLineVo implements Serializable {
  14 +
  15 + private static final long serialVersionUID = 1L;
  16 +
  17 + @ApiModelProperty("明细行ID(调整实收数时传)")
  18 + private String id;
  19 +
  20 + @ApiModelProperty("原料结算详情单明细行ID(来源行)")
  21 + private String settleLineId;
  22 +
  23 + @ApiModelProperty("采购计划ID(来源行计划)")
  24 + private String procurementPlanId;
  25 +
  26 + @ApiModelProperty("品种关系ID(来源行品种)")
  27 + private String productId;
  28 +
  29 + @ApiModelProperty("材料编号(原料结算详情单类别)")
  30 + private String category;
  31 +
  32 + @ApiModelProperty("材料名称(原料结算详情单名称,开票品名)")
  33 + private String name;
  34 +
  35 + @ApiModelProperty("规格型号(品种关系表类型)")
  36 + private String specModel;
  37 +
  38 + @ApiModelProperty("单位")
  39 + private String unit;
  40 +
  41 + @ApiModelProperty("数量(采购数)kg")
  42 + private BigDecimal purchaseQuantity;
  43 +
  44 + @ApiModelProperty("数量(实收数)kg")
  45 + private BigDecimal actualQuantity;
  46 +
  47 + @ApiModelProperty("含税价格(单价)元/kg")
  48 + private BigDecimal taxPrice;
  49 +
  50 + @ApiModelProperty("含税价格(金额)=单价*采购数")
  51 + private BigDecimal taxAmount;
  52 +
  53 + @ApiModelProperty("不含税价格(单价)")
  54 + private BigDecimal noTaxPrice;
  55 +
  56 + @ApiModelProperty("不含税价格(金额)")
  57 + private BigDecimal noTaxAmount;
  58 +
  59 + @ApiModelProperty("结算类型 经销/双经销/买断")
  60 + private String settleType;
  61 +
  62 + @ApiModelProperty("备注")
  63 + private String remark;
  64 +}
  1 +<?xml version="1.0" encoding="UTF-8"?>
  2 +<!DOCTYPE mapper
  3 + PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  4 + "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  5 +<mapper namespace="com.lframework.xingyun.sc.procurement.mappers.receive.ProcurementWarehouseReceiveOrderMapper">
  6 +
  7 + <resultMap id="ProcurementWarehouseReceiveOrderResult"
  8 + type="com.lframework.xingyun.sc.procurement.entity.receive.ProcurementWarehouseReceiveOrder">
  9 + <id column="id" property="id"/>
  10 + <result column="settle_detail_id" property="settleDetailId"/>
  11 + <result column="weighing_ticket_id" property="weighingTicketId"/>
  12 + <result column="weighing_ticket_code" property="weighingTicketCode"/>
  13 + <result column="ticket_date" property="ticketDate"/>
  14 + <result column="material_source" property="materialSource"/>
  15 + <result column="plan_codes" property="planCodes"/>
  16 + <result column="plan_ids" property="planIds"/>
  17 + <result column="workshop_id" property="workshopId"/>
  18 + <result column="workshop_name" property="workshopName"/>
  19 + <result column="workshop_code" property="workshopCode"/>
  20 + <result column="remark" property="remark"/>
  21 + <result column="attachment_file_ids" property="attachmentFileIds"/>
  22 + <result column="attachment_file_names" property="attachmentFileNames"/>
  23 + <result column="total_purchase_quantity_cap" property="totalPurchaseQuantityCap"/>
  24 + <result column="total_actual_quantity" property="totalActualQuantity"/>
  25 + <result column="total_tax_amount" property="totalTaxAmount"/>
  26 + <result column="flow_node" property="flowNode"/>
  27 + <result column="approval_status" property="approvalStatus"/>
  28 + <result column="fzcktjy_id" property="fzcktjyId"/>
  29 + <result column="fzcktjy_name" property="fzcktjyName"/>
  30 + <result column="fzckzjy_id" property="fzckzjyId"/>
  31 + <result column="fzckzjy_name" property="fzckzjyName"/>
  32 + <result column="gyglkzjy_id" property="gyglkzjyId"/>
  33 + <result column="gyglkzjy_name" property="gyglkzjyName"/>
  34 + <result column="fzckzg_id" property="fzckzgId"/>
  35 + <result column="fzckzg_name" property="fzckzgName"/>
  36 + <result column="gyglkzg_id" property="gyglkzgId"/>
  37 + <result column="gyglkzg_name" property="gyglkzgName"/>
  38 + <result column="gybzg_id" property="gybzgId"/>
  39 + <result column="gybzg_name" property="gybzgName"/>
  40 + <result column="deleted" property="deleted"/>
  41 + <result column="create_by_id" property="createById"/>
  42 + <result column="create_by" property="createBy"/>
  43 + <result column="update_by_id" property="updateById"/>
  44 + <result column="update_by" property="updateBy"/>
  45 + <result column="create_time" property="createTime"/>
  46 + <result column="update_time" property="updateTime"/>
  47 + </resultMap>
  48 +
  49 + <sql id="PWRWO_sql">
  50 + SELECT
  51 + tb.id,
  52 + tb.settle_detail_id,
  53 + tb.weighing_ticket_id,
  54 + tb.weighing_ticket_code,
  55 + tb.ticket_date,
  56 + tb.material_source,
  57 + tb.plan_codes,
  58 + tb.plan_ids,
  59 + tb.workshop_id,
  60 + tb.workshop_name,
  61 + ws.code AS workshop_code,
  62 + tb.remark,
  63 + tb.attachment_file_ids,
  64 + tb.attachment_file_names,
  65 + tb.total_purchase_quantity_cap,
  66 + tb.total_actual_quantity,
  67 + tb.total_tax_amount,
  68 + tb.flow_node,
  69 + tb.approval_status,
  70 + tb.fzcktjy_id,
  71 + tb.fzcktjy_name,
  72 + tb.fzckzjy_id,
  73 + tb.fzckzjy_name,
  74 + tb.gyglkzjy_id,
  75 + tb.gyglkzjy_name,
  76 + tb.fzckzg_id,
  77 + tb.fzckzg_name,
  78 + tb.gyglkzg_id,
  79 + tb.gyglkzg_name,
  80 + tb.gybzg_id,
  81 + tb.gybzg_name,
  82 + tb.deleted,
  83 + tb.create_by_id,
  84 + tb.create_by,
  85 + tb.update_by_id,
  86 + tb.update_by,
  87 + tb.create_time,
  88 + tb.update_time
  89 + FROM procurement_warehouse_receive_order AS tb
  90 + LEFT JOIN base_data_workshop ws ON ws.id = tb.workshop_id
  91 + </sql>
  92 +
  93 + <select id="query" resultMap="ProcurementWarehouseReceiveOrderResult">
  94 + <include refid="PWRWO_sql"/>
  95 + <where>
  96 + <choose>
  97 + <when test="vo.deleted != null">
  98 + tb.deleted = #{vo.deleted}
  99 + </when>
  100 + <otherwise>
  101 + tb.deleted = 0
  102 + </otherwise>
  103 + </choose>
  104 + <if test="vo.weighingTicketCode != null and vo.weighingTicketCode != ''">
  105 + AND tb.weighing_ticket_code LIKE CONCAT('%', #{vo.weighingTicketCode}, '%')
  106 + </if>
  107 + <if test="vo.planCode != null and vo.planCode != ''">
  108 + AND tb.plan_codes LIKE CONCAT('%', #{vo.planCode}, '%')
  109 + </if>
  110 + <if test="vo.ticketDateStart != null">
  111 + AND tb.ticket_date &gt;= #{vo.ticketDateStart}
  112 + </if>
  113 + <if test="vo.ticketDateEnd != null">
  114 + AND tb.ticket_date &lt;= #{vo.ticketDateEnd}
  115 + </if>
  116 + <if test="vo.materialSource != null and vo.materialSource != ''">
  117 + AND tb.material_source LIKE CONCAT('%', #{vo.materialSource}, '%')
  118 + </if>
  119 + <if test="vo.workshopId != null and vo.workshopId != ''">
  120 + AND tb.workshop_id = #{vo.workshopId}
  121 + </if>
  122 + <!-- 数据权限:可见分厂代号集合由 Service 按当前用户角色注入(多分厂角色为并集,空=不限制) -->
  123 + <if test="workshopCodeList != null and workshopCodeList.size() > 0">
  124 + AND ws.code IN
  125 + <foreach collection="workshopCodeList" open="(" separator="," close=")" item="item">
  126 + #{item}
  127 + </foreach>
  128 + </if>
  129 + <if test="vo.flowNode != null and vo.flowNode != ''">
  130 + AND tb.flow_node = #{vo.flowNode}
  131 + </if>
  132 + <if test="vo.approvalStatus != null and vo.approvalStatus != ''">
  133 + AND tb.approval_status = #{vo.approvalStatus}
  134 + </if>
  135 + </where>
  136 + ORDER BY tb.create_time DESC
  137 + </select>
  138 +
  139 + <!-- 单条查询(联表带出分厂编号;分厂审核节点编码 = WAREHOUSE_RECEIVE_ORDER_ + 分厂前缀 + 环节缩写,实体传给流程引擎前必须带出) -->
  140 + <select id="findById" resultMap="ProcurementWarehouseReceiveOrderResult">
  141 + <include refid="PWRWO_sql"/>
  142 + WHERE tb.id = #{id}
  143 + </select>
  144 +</mapper>
@@ -148,7 +148,7 @@ @@ -148,7 +148,7 @@
148 <result column="create_by" property="createBy"/> 148 <result column="create_by" property="createBy"/>
149 </resultMap> 149 </resultMap>
150 150
151 - <!-- 原料结算制单选择码单弹窗:审核通过 + 已上传签字凭证 + 码单下每个过磅品种都要有原料化验报告单且全部审核通过 --> 151 + <!-- 原料结算制单选择码单弹窗:审核通过 + 已上传签字凭证 + 码单下每个过磅品种都要有原料化验报告单且全部审核通过 + 未生成过有效原料结算详情单 -->
152 <select id="querySelectableTickets" resultMap="MaterialSettleSelectableTicketResult"> 152 <select id="querySelectableTickets" resultMap="MaterialSettleSelectableTicketResult">
153 SELECT 153 SELECT
154 tb.id, 154 tb.id,
@@ -187,6 +187,13 @@ @@ -187,6 +187,13 @@
187 AND par.approval_status = 'PASS' 187 AND par.approval_status = 'PASS'
188 ) 188 )
189 ) 189 )
  190 + <!-- 已生成过有效原料结算详情单(非已取消、非已作废)的码单不能再查出 -->
  191 + AND NOT EXISTS (
  192 + SELECT 1 FROM procurement_material_settle_detail pmsd
  193 + WHERE pmsd.weighing_ticket_id = tb.id
  194 + AND pmsd.deleted = 0
  195 + AND (pmsd.approval_status IS NULL OR pmsd.approval_status != 'CANCEL')
  196 + )
190 <if test="vo.code != null and vo.code != ''"> 197 <if test="vo.code != null and vo.code != ''">
191 AND tb.code LIKE CONCAT('%', #{vo.code}, '%') 198 AND tb.code LIKE CONCAT('%', #{vo.code}, '%')
192 </if> 199 </if>