Commit f515729d72b5861afa52c12b1932ef6b3f6cc4e4

Authored by 房远帅
1 parent 4fa5bea5

销售-入库:买断入库核算单

Showing 24 changed files with 2309 additions and 1 deletions
... ... @@ -136,6 +136,12 @@ public GetXxxBo(Xxx dto) {
136 136 **后果**:页面创建人/更新人显示空白;数据没有操作人追溯;事后补数困难。
137 137 **正确做法**:新建实体时审计字段照抄成熟实体(如 `ProcurementMaterialSettleDetail`)的写法,六个字段逐一检查注解:`createById`+`createBy`+`createTime` 用 `INSERT`,`updateById`+`updateBy`+`updateTime` 用 `INSERT_UPDATE`;写完实体后对照结算详情单实体逐一核对。
138 138
  139 +## 23. 工具类方法名禁止臆造,先 Grep 再用
  140 +
  141 +**坑**:凭空臆造工具方法名(如 lframework 的 `StringUtil.isEqual`),实际该类没有这个方法,编译报"Cannot resolve method"。
  142 +**后果**:编译失败;IDE 诊断若未及时覆盖会带到提交环节才暴露。
  143 +**正确做法**:使用工具类(StringUtil/CollectionUtil/NumberUtil 等)前先 Grep 项目内该方法既有用法确认存在;字符串等值判断项目内用 `java.util.Objects.equals(a, b)`(自带 null 安全),或 Grep StringUtil 源码/既有调用确认真实方法名。
  144 +
139 145 ---
140 146
141 147 ## 回写模板(新增踩坑时复制)
... ...
... ... @@ -2909,3 +2909,83 @@ CREATE TABLE IF NOT EXISTS `procurement_warehouse_receive_order_line`
2909 2909 PRIMARY KEY (`id`),
2910 2910 KEY `idx_pwrwl_receive_order_id` (`receive_order_id`)
2911 2911 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='仓库收料单-明细';
  2912 +
  2913 +-- 入库第六模块:买断入库核算单(原料结算详情单流转,分厂仓库统计员制单;前提:结算详情单下的仓库收料单审核通过)
  2914 +CREATE TABLE IF NOT EXISTS `procurement_buyout_account_order`
  2915 +(
  2916 + `id` varchar(32) NOT NULL COMMENT 'ID',
  2917 + `settle_detail_id` varchar(32) NOT NULL COMMENT '原料结算详情单ID(来源单,一单一结算)',
  2918 + `weighing_ticket_id` varchar(32) DEFAULT NULL COMMENT '过磅码单ID(取自原料结算详情单)',
  2919 + `weighing_ticket_code` varchar(50) DEFAULT NULL COMMENT '码单编号',
  2920 + `incoming_unit` varchar(200) DEFAULT NULL COMMENT '来料单位(原料结算详情单的单位)',
  2921 + `plan_codes` varchar(500) DEFAULT NULL COMMENT '计划编号(取自原料结算详情单,冗余展示)',
  2922 + `plan_ids` varchar(200) DEFAULT NULL COMMENT '计划ID集合(冗余)',
  2923 + `purchase_department_id` varchar(32) DEFAULT NULL COMMENT '采购处ID',
  2924 + `purchase_department_name` varchar(200) DEFAULT NULL COMMENT '采购处名称',
  2925 + `region_id` varchar(32) DEFAULT NULL COMMENT '区域ID',
  2926 + `region_name` varchar(200) DEFAULT NULL COMMENT '区域名称',
  2927 + `workshop_id` varchar(32) DEFAULT NULL COMMENT '分厂ID(取自原料结算详情单)',
  2928 + `workshop_name` varchar(200) DEFAULT NULL COMMENT '分厂名称',
  2929 + `total_buyout_quantity` decimal(12,2) DEFAULT NULL COMMENT '合计-买断数量 kg(前端计算传入)',
  2930 + `total_buyout_amount` decimal(14,2) DEFAULT NULL COMMENT '合计-买断金额(前端计算传入)',
  2931 + `total_instock_quantity` decimal(12,2) DEFAULT NULL COMMENT '合计-入库数量 kg(前端计算传入)',
  2932 + `total_instock_amount` decimal(14,2) DEFAULT NULL COMMENT '合计-入库金额(前端计算传入)',
  2933 + `total_diff_amount` decimal(14,2) DEFAULT NULL COMMENT '合计-差异金额 元(前端计算传入)',
  2934 + `flow_node` varchar(50) DEFAULT NULL COMMENT '流程节点',
  2935 + `approval_status` varchar(50) DEFAULT NULL COMMENT '审核状态 DRAFT-草稿 AUDIT-审核中 PASS-审核通过 REFUSE-已驳回 CANCEL-已取消',
  2936 + `fccktjy_id` varchar(32) DEFAULT NULL COMMENT '分厂仓库统计员审核人ID(审核通过时记录)',
  2937 + `fccktjy_name` varchar(64) DEFAULT NULL COMMENT '分厂仓库统计员审核人',
  2938 + `fcckzg_id` varchar(32) DEFAULT NULL COMMENT '分厂仓库主管审核人ID(审核通过时记录)',
  2939 + `fcckzg_name` varchar(64) DEFAULT NULL COMMENT '分厂仓库主管审核人',
  2940 + `fczlfg_id` varchar(32) DEFAULT NULL COMMENT '分厂质量分管审核人ID(审核通过时记录)',
  2941 + `fczlfg_name` varchar(64) DEFAULT NULL COMMENT '分厂质量分管审核人',
  2942 + `gyglkzg_id` varchar(32) DEFAULT NULL COMMENT '供应管理科主管审核人ID(审核通过时记录)',
  2943 + `gyglkzg_name` varchar(64) DEFAULT NULL COMMENT '供应管理科主管审核人',
  2944 + `fcylkj_id` varchar(32) DEFAULT NULL COMMENT '分厂原料会计审核人ID(审核通过时记录)',
  2945 + `fcylkj_name` varchar(64) DEFAULT NULL COMMENT '分厂原料会计审核人',
  2946 + `fccwkzg_id` varchar(32) DEFAULT NULL COMMENT '分厂财务科主管审核人ID(审核通过时记录)',
  2947 + `fccwkzg_name` varchar(64) DEFAULT NULL COMMENT '分厂财务科主管审核人',
  2948 + `gybzg_id` varchar(32) DEFAULT NULL COMMENT '供应部主管审核人ID(审核通过时记录)',
  2949 + `gybzg_name` varchar(64) DEFAULT NULL COMMENT '供应部主管审核人',
  2950 + `deleted` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否作废 0-有效单 1-作废单(作废单只能查看)',
  2951 + `create_by_id` varchar(32) DEFAULT NULL COMMENT '创建人ID',
  2952 + `create_by` varchar(64) DEFAULT NULL COMMENT '创建人',
  2953 + `update_by_id` varchar(32) DEFAULT NULL COMMENT '更新人ID',
  2954 + `update_by` varchar(64) DEFAULT NULL COMMENT '更新人',
  2955 + `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  2956 + `update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  2957 + PRIMARY KEY (`id`),
  2958 + KEY `idx_pbao_settle_detail_id` (`settle_detail_id`),
  2959 + KEY `idx_pbao_weighing_ticket_id` (`weighing_ticket_id`),
  2960 + KEY `idx_pbao_workshop_id` (`workshop_id`),
  2961 + KEY `idx_pbao_approval_status` (`approval_status`),
  2962 + KEY `idx_pbao_create_time` (`create_time`)
  2963 +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='买断入库核算单';
  2964 +
  2965 +CREATE TABLE IF NOT EXISTS `procurement_buyout_account_order_line`
  2966 +(
  2967 + `id` varchar(32) NOT NULL COMMENT 'ID',
  2968 + `order_id` varchar(32) NOT NULL COMMENT '买断入库核算单主表ID',
  2969 + `settle_line_id` varchar(32) DEFAULT NULL COMMENT '原料结算详情单明细行ID(来源行,数据追溯)',
  2970 + `procurement_plan_id` varchar(32) DEFAULT NULL COMMENT '采购计划ID(来源行计划)',
  2971 + `product_id` varchar(32) DEFAULT NULL COMMENT '品种关系ID(来源行品种)',
  2972 + `buyout_category` varchar(50) DEFAULT NULL COMMENT '买断品种(原料结算详情单类别,品种关系代号)',
  2973 + `buyout_quantity` decimal(12,2) DEFAULT NULL COMMENT '买断数量 kg(原料结算详情单过磅数)',
  2974 + `buyout_price` decimal(12,4) DEFAULT NULL COMMENT '买断单价 元/kg(仓库收料单含税单价)',
  2975 + `buyout_amount` decimal(14,2) DEFAULT NULL COMMENT '买断金额 = 买断单价*买断数量',
  2976 + `instock_quantity` decimal(12,2) DEFAULT NULL COMMENT '入库数量 kg(申请净重-退料-折斤,可修改)',
  2977 + `instock_price` decimal(12,4) DEFAULT NULL COMMENT '入库单价 元/kg(可修改)',
  2978 + `instock_amount` decimal(14,2) DEFAULT NULL COMMENT '入库金额 元(可修改)',
  2979 + `expect_ton_loss` decimal(12,4) DEFAULT NULL COMMENT '预计吨损耗 元/吨(按计划取买断操作申请表)',
  2980 + `actual_ton_loss` decimal(12,4) DEFAULT NULL COMMENT '实际吨损耗 元/吨(可修改)',
  2981 + `ton_loss_diff` decimal(12,4) DEFAULT NULL COMMENT '吨损耗差异 元/吨 = 预计-实际',
  2982 + `diff_amount` decimal(14,2) DEFAULT NULL COMMENT '差异金额 元 = 入库数量*吨损耗差异/1000',
  2983 + `create_by_id` varchar(32) DEFAULT NULL COMMENT '创建人ID',
  2984 + `create_by` varchar(64) DEFAULT NULL COMMENT '创建人',
  2985 + `update_by_id` varchar(32) DEFAULT NULL COMMENT '更新人ID',
  2986 + `update_by` varchar(64) DEFAULT NULL COMMENT '更新人',
  2987 + `create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
  2988 + `update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
  2989 + PRIMARY KEY (`id`),
  2990 + KEY `idx_pbaol_order_id` (`order_id`)
  2991 +) 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 io.swagger.annotations.ApiModelProperty;
  6 +import lombok.Data;
  7 +
  8 +import java.math.BigDecimal;
  9 +import java.time.LocalDateTime;
  10 +import java.util.ArrayList;
  11 +import java.util.List;
  12 +
  13 +/**
  14 + * 买断入库核算单详情(主表 + 明细)
  15 + */
  16 +@Data
  17 +public class GetBuyoutAccountOrderBo {
  18 +
  19 + @ApiModelProperty("ID")
  20 + private String id;
  21 +
  22 + @ApiModelProperty("原料结算详情单ID(来源单)")
  23 + private String settleDetailId;
  24 +
  25 + @ApiModelProperty("过磅码单ID")
  26 + private String weighingTicketId;
  27 +
  28 + @ApiModelProperty("码单编号")
  29 + private String weighingTicketCode;
  30 +
  31 + @ApiModelProperty("来料单位")
  32 + private String incomingUnit;
  33 +
  34 + @ApiModelProperty("计划编号集合")
  35 + private List<String> planCodes = new ArrayList<>();
  36 +
  37 + @ApiModelProperty("采购处ID")
  38 + private String purchaseDepartmentId;
  39 +
  40 + @ApiModelProperty("采购处名称")
  41 + private String purchaseDepartmentName;
  42 +
  43 + @ApiModelProperty("区域ID")
  44 + private String regionId;
  45 +
  46 + @ApiModelProperty("区域名称")
  47 + private String regionName;
  48 +
  49 + @ApiModelProperty("分厂ID")
  50 + private String workshopId;
  51 +
  52 + @ApiModelProperty("分厂名称")
  53 + private String workshopName;
  54 +
  55 + @ApiModelProperty("分厂编号")
  56 + private String workshopCode;
  57 +
  58 + @ApiModelProperty("合计-买断数量 kg")
  59 + private BigDecimal totalBuyoutQuantity;
  60 +
  61 + @ApiModelProperty("合计-买断金额")
  62 + private BigDecimal totalBuyoutAmount;
  63 +
  64 + @ApiModelProperty("合计-入库数量 kg")
  65 + private BigDecimal totalInstockQuantity;
  66 +
  67 + @ApiModelProperty("合计-入库金额")
  68 + private BigDecimal totalInstockAmount;
  69 +
  70 + @ApiModelProperty("合计-差异金额 元")
  71 + private BigDecimal totalDiffAmount;
  72 +
  73 + @ApiModelProperty("流程节点 FCCKTJY/FCCKZG/FCZLFG/GYGLKZG/FCYLKJ/FCCWKZG/GYBZG")
  74 + private String flowNode;
  75 +
  76 + @ApiModelProperty("审核状态 DRAFT/AUDIT/PASS/REFUSE/CANCEL")
  77 + private String approvalStatus;
  78 +
  79 + @ApiModelProperty("分厂仓库统计员审核人ID")
  80 + private String fccktjyId;
  81 +
  82 + @ApiModelProperty("分厂仓库统计员审核人")
  83 + private String fccktjyName;
  84 +
  85 + @ApiModelProperty("分厂仓库主管审核人ID")
  86 + private String fcckzgId;
  87 +
  88 + @ApiModelProperty("分厂仓库主管审核人")
  89 + private String fcckzgName;
  90 +
  91 + @ApiModelProperty("分厂质量分管审核人ID")
  92 + private String fczlfgId;
  93 +
  94 + @ApiModelProperty("分厂质量分管审核人")
  95 + private String fczlfgName;
  96 +
  97 + @ApiModelProperty("供应管理科主管审核人ID")
  98 + private String gyglkzgId;
  99 +
  100 + @ApiModelProperty("供应管理科主管审核人")
  101 + private String gyglkzgName;
  102 +
  103 + @ApiModelProperty("分厂原料会计审核人ID")
  104 + private String fcylkjId;
  105 +
  106 + @ApiModelProperty("分厂原料会计审核人")
  107 + private String fcylkjName;
  108 +
  109 + @ApiModelProperty("分厂财务科主管审核人ID")
  110 + private String fccwkzgId;
  111 +
  112 + @ApiModelProperty("分厂财务科主管审核人")
  113 + private String fccwkzgName;
  114 +
  115 + @ApiModelProperty("供应部主管审核人ID")
  116 + private String gybzgId;
  117 +
  118 + @ApiModelProperty("供应部主管审核人")
  119 + private String gybzgName;
  120 +
  121 + @ApiModelProperty("是否展示审核按钮")
  122 + private Boolean showExamine;
  123 +
  124 + @ApiModelProperty("是否展示审核详情按钮")
  125 + private Boolean showExamineDetail;
  126 +
  127 + @ApiModelProperty("创建人")
  128 + private String createBy;
  129 +
  130 + @ApiModelProperty("创建人ID")
  131 + private String createById;
  132 +
  133 + @ApiModelProperty("创建时间")
  134 + @JsonFormat(pattern = StringPool.DATE_TIME_PATTERN)
  135 + private LocalDateTime createTime;
  136 +
  137 + @ApiModelProperty("明细数据")
  138 + private List<LineBo> lines = new ArrayList<>();
  139 +
  140 + /**
  141 + * 买断入库核算单明细
  142 + */
  143 + @Data
  144 + public static class LineBo {
  145 +
  146 + @ApiModelProperty("ID")
  147 + private String id;
  148 +
  149 + @ApiModelProperty("原料结算详情单明细行ID(来源行)")
  150 + private String settleLineId;
  151 +
  152 + @ApiModelProperty("采购计划ID")
  153 + private String procurementPlanId;
  154 +
  155 + @ApiModelProperty("品种关系ID")
  156 + private String productId;
  157 +
  158 + @ApiModelProperty("买断品种")
  159 + private String buyoutCategory;
  160 +
  161 + @ApiModelProperty("买断数量 kg")
  162 + private BigDecimal buyoutQuantity;
  163 +
  164 + @ApiModelProperty("买断单价 元/kg")
  165 + private BigDecimal buyoutPrice;
  166 +
  167 + @ApiModelProperty("买断金额")
  168 + private BigDecimal buyoutAmount;
  169 +
  170 + @ApiModelProperty("入库数量 kg")
  171 + private BigDecimal instockQuantity;
  172 +
  173 + @ApiModelProperty("入库单价 元/kg")
  174 + private BigDecimal instockPrice;
  175 +
  176 + @ApiModelProperty("入库金额 元")
  177 + private BigDecimal instockAmount;
  178 +
  179 + @ApiModelProperty("预计吨损耗 元/吨")
  180 + private BigDecimal expectTonLoss;
  181 +
  182 + @ApiModelProperty("实际吨损耗 元/吨")
  183 + private BigDecimal actualTonLoss;
  184 +
  185 + @ApiModelProperty("吨损耗差异 元/吨")
  186 + private BigDecimal tonLossDiff;
  187 +
  188 + @ApiModelProperty("差异金额 元")
  189 + private BigDecimal diffAmount;
  190 + }
  191 +}
... ...
  1 +package com.lframework.xingyun.sc.bo.procurement;
  2 +
  3 +import com.lframework.xingyun.sc.procurement.vo.buyoutAccount.BuyoutAccountOrderLineVo;
  4 +import io.swagger.annotations.ApiModelProperty;
  5 +import lombok.Data;
  6 +
  7 +import java.util.ArrayList;
  8 +import java.util.List;
  9 +
  10 +/**
  11 + * 新增买断入库核算单:按原料结算详情单带出数据(分厂仓库统计员制单;
  12 + * 前提:该结算详情单下的仓库收料单审核通过)
  13 + */
  14 +@Data
  15 +public class GetBuyoutSettleDataBo {
  16 +
  17 + @ApiModelProperty("原料结算详情单ID")
  18 + private String settleDetailId;
  19 +
  20 + @ApiModelProperty("过磅码单ID")
  21 + private String weighingTicketId;
  22 +
  23 + @ApiModelProperty("码单编号")
  24 + private String weighingTicketCode;
  25 +
  26 + @ApiModelProperty("来料单位(原料结算详情单的单位)")
  27 + private String incomingUnit;
  28 +
  29 + @ApiModelProperty("计划编号(关联结算详情单的计划编号)")
  30 + private String planCodes;
  31 +
  32 + @ApiModelProperty("采购处ID(第一个采购计划)")
  33 + private String purchaseDepartmentId;
  34 +
  35 + @ApiModelProperty("采购处名称")
  36 + private String purchaseDepartmentName;
  37 +
  38 + @ApiModelProperty("区域ID(第一个采购计划)")
  39 + private String regionId;
  40 +
  41 + @ApiModelProperty("区域名称")
  42 + private String regionName;
  43 +
  44 + @ApiModelProperty("分厂ID")
  45 + private String workshopId;
  46 +
  47 + @ApiModelProperty("分厂名称")
  48 + private String workshopName;
  49 +
  50 + @ApiModelProperty("明细数据(自动带出:买断品种/买断数量/买断单价/入库数量/预计吨损耗等)")
  51 + private List<BuyoutAccountOrderLineVo> lines = new ArrayList<>();
  52 +}
... ...
... ... @@ -20,6 +20,7 @@ import com.lframework.xingyun.sc.entity.*;
20 20 import com.lframework.xingyun.sc.enums.CustomerDevelopStatus;
21 21 import com.lframework.xingyun.sc.procurement.entity.ProcurementDomesticCustomerCredit;
22 22 import com.lframework.xingyun.sc.procurement.entity.ProcurementForeignTradeCredit;
  23 +import com.lframework.xingyun.sc.procurement.service.buyoutAccount.ProcurementBuyoutAccountOrderService;
23 24 import com.lframework.xingyun.sc.procurement.service.change.ProcurementPlanChangeService;
24 25 import com.lframework.xingyun.sc.procurement.service.coordination.CoordinationSummaryApprovalService;
25 26 import com.lframework.xingyun.sc.procurement.service.contract.ProcurementContractService;
... ... @@ -186,6 +187,8 @@ public class BusinessDataHandlerServiceImpl implements BusinessDataHandlerServic
186 187 private ProcurementMaterialSettleDetailService procurementMaterialSettleDetailService;
187 188 @Resource
188 189 private ProcurementWarehouseReceiveOrderService procurementWarehouseReceiveOrderService;
  190 + @Resource
  191 + private ProcurementBuyoutAccountOrderService procurementBuyoutAccountOrderService;
189 192
190 193
191 194
... ... @@ -306,6 +309,9 @@ public class BusinessDataHandlerServiceImpl implements BusinessDataHandlerServic
306 309 case "RECEIVE_ORDER":
307 310 handleWarehouseReceiveOrderData(flowStatus, businessId);
308 311 break;
  312 + case "BUYOUT_ACCOUNT_ORDER":
  313 + handleBuyoutAccountOrderData(flowStatus, businessId);
  314 + break;
309 315 default:
310 316 break;
311 317 }
... ... @@ -1325,4 +1331,15 @@ public class BusinessDataHandlerServiceImpl implements BusinessDataHandlerServic
1325 1331 procurementWarehouseReceiveOrderService.updateApprovalStatus(businessId, "REFUSE");
1326 1332 }
1327 1333 }
  1334 +
  1335 + private void handleBuyoutAccountOrderData(String flowStatus, String businessId) {
  1336 + if (FlowInstanceStatus.APPROVE_PASS.getCode().equals(flowStatus)
  1337 + || FlowInstanceStatus.FINISH.getCode().equals(flowStatus)) {
  1338 + procurementBuyoutAccountOrderService.updateApprovalStatus(businessId, "PASS");
  1339 + } else if (FlowInstanceStatus.REVOKE.getCode().equals(flowStatus)
  1340 + || FlowInstanceStatus.REFUSE.getCode().equals(flowStatus)
  1341 + || FlowInstanceStatus.TERMINATION.getCode().equals(flowStatus)) {
  1342 + procurementBuyoutAccountOrderService.updateApprovalStatus(businessId, "REFUSE");
  1343 + }
  1344 + }
1328 1345 }
... ...
... ... @@ -18,6 +18,7 @@ import com.lframework.xingyun.sc.entity.FundCoordination;
18 18 import com.lframework.xingyun.sc.entity.ProductSampleConfirmationSlip;
19 19 import com.lframework.xingyun.sc.handlers.TransactorHandler;
20 20 import com.lframework.xingyun.sc.procurement.entity.ProcurementPlanChange;
  21 +import com.lframework.xingyun.sc.procurement.service.buyoutAccount.ProcurementBuyoutAccountOrderService;
21 22 import com.lframework.xingyun.sc.procurement.service.change.ProcurementPlanChangeService;
22 23 import com.lframework.xingyun.sc.procurement.service.coordination.CoordinationSummaryApprovalService;
23 24 import com.lframework.xingyun.sc.procurement.service.plan.ProcurementPlanService;
... ... @@ -85,6 +86,8 @@ public class FlowTaskServiceImpl implements FlowTaskService {
85 86 private ProcurementMaterialSettleDetailService procurementMaterialSettleDetailService;
86 87 @Resource
87 88 private ProcurementWarehouseReceiveOrderService procurementWarehouseReceiveOrderService;
  89 + @Resource
  90 + private ProcurementBuyoutAccountOrderService procurementBuyoutAccountOrderService;
88 91
89 92
90 93 @OpLog(type = OtherOpLogType.class, name = "修改客户资信,ID:{}", params = {"#id"})
... ... @@ -514,6 +517,12 @@ public class FlowTaskServiceImpl implements FlowTaskService {
514 517 procurementWarehouseReceiveOrderService.updateNoFlowInstance(map);
515 518 }
516 519
  520 + @Transactional(rollbackFor = Exception.class)
  521 + @Override
  522 + public void updateBuyoutAccountOrderApprovalMap(Map<String, Object> map) {
  523 + procurementBuyoutAccountOrderService.updateNoFlowInstance(map);
  524 + }
  525 +
517 526 @Override
518 527 public Map<String, Object> findById(String s) {
519 528 ProductSampleConfirmationSlip slip = productSampleConfirmationSlipService.findById(s);
... ...
  1 +package com.lframework.xingyun.sc.procurement.controller.buyoutAccount;
  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.GetBuyoutAccountOrderBo;
  10 +import com.lframework.xingyun.sc.bo.procurement.GetBuyoutSettleDataBo;
  11 +import com.lframework.xingyun.sc.procurement.entity.buyoutAccount.ProcurementBuyoutAccountOrder;
  12 +import com.lframework.xingyun.sc.procurement.service.buyoutAccount.ProcurementBuyoutAccountOrderService;
  13 +import com.lframework.xingyun.sc.procurement.vo.buyoutAccount.CreateBuyoutAccountOrderVo;
  14 +import com.lframework.xingyun.sc.procurement.vo.buyoutAccount.QueryBuyoutAccountOrderVo;
  15 +import com.lframework.xingyun.sc.procurement.vo.buyoutAccount.UpdateBuyoutAccountOrderVo;
  16 +import io.swagger.annotations.Api;
  17 +import io.swagger.annotations.ApiImplicitParam;
  18 +import io.swagger.annotations.ApiOperation;
  19 +import java.util.List;
  20 +import java.util.stream.Collectors;
  21 +import javax.annotation.Resource;
  22 +import javax.validation.Valid;
  23 +import javax.validation.constraints.NotBlank;
  24 +import lombok.extern.slf4j.Slf4j;
  25 +import org.springframework.util.CollectionUtils;
  26 +import org.springframework.validation.annotation.Validated;
  27 +import org.springframework.web.bind.annotation.GetMapping;
  28 +import org.springframework.web.bind.annotation.PostMapping;
  29 +import org.springframework.web.bind.annotation.PutMapping;
  30 +import org.springframework.web.bind.annotation.RequestBody;
  31 +import org.springframework.web.bind.annotation.RequestMapping;
  32 +import org.springframework.web.bind.annotation.RestController;
  33 +
  34 +/**
  35 + * 买断入库核算单(入库第六模块,原料结算详情单流转,分厂仓库统计员制单)
  36 + */
  37 +@Api(tags = "买断入库核算单管理")
  38 +@Slf4j
  39 +@Validated
  40 +@RestController
  41 +@RequestMapping("/procurement/buyout/account")
  42 +public class ProcurementBuyoutAccountOrderController extends DefaultBaseController {
  43 +
  44 + @Resource
  45 + private ProcurementBuyoutAccountOrderService buyoutAccountOrderService;
  46 +
  47 + @ApiOperation("分页查询买断入库核算单")
  48 + @HasPermission({"warehouse-manage:outright-purchase:query"})
  49 + @GetMapping("/query")
  50 + public InvokeResult<PageResult<GetBuyoutAccountOrderBo>> query(
  51 + @Valid QueryBuyoutAccountOrderVo vo) {
  52 + PageResult<ProcurementBuyoutAccountOrder> result = buyoutAccountOrderService.query(
  53 + getPageIndex(vo), getPageSize(vo), vo);
  54 +
  55 + List<GetBuyoutAccountOrderBo> results = null;
  56 + if (!CollectionUtils.isEmpty(result.getDatas())) {
  57 + results = result.getDatas().stream().map(order -> {
  58 + GetBuyoutAccountOrderBo bo = new GetBuyoutAccountOrderBo();
  59 + org.springframework.beans.BeanUtils.copyProperties(order, bo);
  60 + bo.setPlanCodes(splitPlanCodes(order.getPlanCodes()));
  61 + return bo;
  62 + }).collect(Collectors.toList());
  63 + }
  64 + return InvokeResultBuilder.success(PageResultUtil.rebuild(result, results));
  65 + }
  66 +
  67 + @ApiOperation("查询买断入库核算单详情")
  68 + @ApiImplicitParam(value = "ID", name = "id", paramType = "query", required = true)
  69 + @HasPermission({"warehouse-manage:outright-purchase:query", "warehouse-manage:outright-purchase:review"})
  70 + @GetMapping("")
  71 + public InvokeResult<GetBuyoutAccountOrderBo> findById(
  72 + @NotBlank(message = "ID不能为空!") String id) {
  73 + return InvokeResultBuilder.success(buyoutAccountOrderService.findDetail(id));
  74 + }
  75 +
  76 + @ApiOperation("可制单的原料结算详情单下拉(审核通过 + 未作废 + 已生成审核通过的仓库收料单 + 未生成过买断入库核算单)")
  77 + @GetMapping("/settleOptions")
  78 + public InvokeResult<List<GetBuyoutSettleDataBo>> getSettleOptions() {
  79 + return InvokeResultBuilder.success(buyoutAccountOrderService.getSettleOptions());
  80 + }
  81 +
  82 + @ApiOperation("新增页:按原料结算详情单带出数据(买断品种/买断数量/买断单价/入库数量/预计吨损耗等)")
  83 + @ApiImplicitParam(value = "原料结算详情单ID", name = "settleDetailId", paramType = "query", required = true)
  84 + @GetMapping("/settleData")
  85 + public InvokeResult<GetBuyoutSettleDataBo> getSettleData(
  86 + @NotBlank(message = "原料结算详情单不能为空!") String settleDetailId) {
  87 + return InvokeResultBuilder.success(buyoutAccountOrderService.getSettleData(settleDetailId));
  88 + }
  89 +
  90 + @ApiOperation("新增买断入库核算单(草稿,分厂仓库统计员)")
  91 + @HasPermission({"warehouse-manage:outright-purchase:add"})
  92 + @PostMapping("")
  93 + public InvokeResult<String> create(@RequestBody @Valid CreateBuyoutAccountOrderVo vo) {
  94 + String id = buyoutAccountOrderService.create(vo);
  95 + return InvokeResultBuilder.success(id);
  96 + }
  97 +
  98 + @ApiOperation("修改买断入库核算单(仅草稿、已驳回可修改)")
  99 + @HasPermission({"warehouse-manage:outright-purchase:modify","warehouse-manage:outright-purchase:approve"})
  100 + @PutMapping("")
  101 + public InvokeResult<Void> update(@RequestBody @Valid UpdateBuyoutAccountOrderVo vo) {
  102 + buyoutAccountOrderService.update(vo);
  103 + return InvokeResultBuilder.success();
  104 + }
  105 +
  106 + @ApiOperation("提交买断入库核算单审核")
  107 + @ApiImplicitParam(value = "ID", name = "id", paramType = "query", required = true)
  108 + @HasPermission({"warehouse-manage:outright-purchase:submit"})
  109 + @PutMapping("/submit")
  110 + public InvokeResult<Void> submit(@NotBlank(message = "ID不能为空!") String id) {
  111 + buyoutAccountOrderService.submit(id);
  112 + return InvokeResultBuilder.success();
  113 + }
  114 +
  115 + @ApiOperation("取消买断入库核算单(草稿、已驳回状态可取消)")
  116 + @ApiImplicitParam(value = "ID", name = "id", paramType = "query", required = true)
  117 + @HasPermission({"warehouse-manage:outright-purchase:cancel"})
  118 + @PutMapping("/cancel")
  119 + public InvokeResult<Void> cancel(@NotBlank(message = "ID不能为空!") String id) {
  120 + buyoutAccountOrderService.cancel(id);
  121 + return InvokeResultBuilder.success();
  122 + }
  123 +
  124 + private List<String> splitPlanCodes(String planCodes) {
  125 + if (planCodes == null || planCodes.isEmpty()) {
  126 + return java.util.Collections.emptyList();
  127 + }
  128 + return java.util.Arrays.stream(planCodes.split("[,,]"))
  129 + .map(String::trim)
  130 + .filter(s -> !s.isEmpty())
  131 + .distinct()
  132 + .collect(Collectors.toList());
  133 + }
  134 +}
... ...
  1 +package com.lframework.xingyun.sc.procurement.entity.buyoutAccount;
  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 + * 分厂仓库统计员 -> 分厂仓库质检员 -> 供应管理科质检员 -> 分厂仓库主管 -> 供应管理科主管 -> 供应部主管
  16 + */
  17 +@Data
  18 +@TableName("procurement_buyout_account_order")
  19 +public class ProcurementBuyoutAccountOrder 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 + * 来料单位(原料结算详情单的单位)
  45 + */
  46 + private String incomingUnit;
  47 +
  48 + /**
  49 + * 计划编号(取自原料结算详情单,冗余展示)
  50 + */
  51 + private String planCodes;
  52 +
  53 + /**
  54 + * 计划ID集合(冗余)
  55 + */
  56 + private String planIds;
  57 +
  58 + /**
  59 + * 采购处ID(第一个采购计划,多个计划需一致)
  60 + */
  61 + private String purchaseDepartmentId;
  62 +
  63 + /**
  64 + * 采购处名称
  65 + */
  66 + private String purchaseDepartmentName;
  67 +
  68 + /**
  69 + * 区域ID(第一个采购计划,多个计划需一致)
  70 + */
  71 + private String regionId;
  72 +
  73 + /**
  74 + * 区域名称
  75 + */
  76 + private String regionName;
  77 +
  78 + /**
  79 + * 分厂ID(取自原料结算详情单)
  80 + */
  81 + private String workshopId;
  82 +
  83 + /**
  84 + * 分厂名称
  85 + */
  86 + private String workshopName;
  87 +
  88 + /**
  89 + * 合计-买断数量 kg(前端计算传入)
  90 + */
  91 + private BigDecimal totalBuyoutQuantity;
  92 +
  93 + /**
  94 + * 合计-买断金额(前端计算传入)
  95 + */
  96 + private BigDecimal totalBuyoutAmount;
  97 +
  98 + /**
  99 + * 合计-入库数量 kg(前端计算传入)
  100 + */
  101 + private BigDecimal totalInstockQuantity;
  102 +
  103 + /**
  104 + * 合计-入库金额(前端计算传入)
  105 + */
  106 + private BigDecimal totalInstockAmount;
  107 +
  108 + /**
  109 + * 合计-差异金额 元(前端计算传入)
  110 + */
  111 + private BigDecimal totalDiffAmount;
  112 +
  113 + /**
  114 + * 流程节点 FCCKTJY-分厂仓库统计员 FCCKZG-分厂仓库主管 FCZLFG-分厂质量分管 GYGLKZG-供应管理科主管 FCYLKJ-分厂原料会计 FCCWKZG-分厂财务科主管 GYBZG-供应部主管
  115 + */
  116 + private String flowNode;
  117 +
  118 + /**
  119 + * 审核状态 DRAFT-草稿 AUDIT-审核中 PASS-审核通过 REFUSE-已驳回 CANCEL-已取消
  120 + */
  121 + private String approvalStatus;
  122 +
  123 + /**
  124 + * 分厂仓库统计员审核人ID(审核通过时记录)
  125 + */
  126 + private String fccktjyId;
  127 +
  128 + /**
  129 + * 分厂仓库统计员审核人
  130 + */
  131 + private String fccktjyName;
  132 +
  133 + /**
  134 + * 分厂仓库主管审核人ID(审核通过时记录)
  135 + */
  136 + private String fcckzgId;
  137 +
  138 + /**
  139 + * 分厂仓库主管审核人
  140 + */
  141 + private String fcckzgName;
  142 +
  143 + /**
  144 + * 分厂质量分管审核人ID(审核通过时记录)
  145 + */
  146 + private String fczlfgId;
  147 +
  148 + /**
  149 + * 分厂质量分管审核人
  150 + */
  151 + private String fczlfgName;
  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 fcylkjId;
  167 +
  168 + /**
  169 + * 分厂原料会计审核人
  170 + */
  171 + private String fcylkjName;
  172 +
  173 + /**
  174 + * 分厂财务科主管审核人ID(审核通过时记录)
  175 + */
  176 + private String fccwkzgId;
  177 +
  178 + /**
  179 + * 分厂财务科主管审核人
  180 + */
  181 + private String fccwkzgName;
  182 +
  183 + /**
  184 + * 供应部主管审核人ID(审核通过时记录)
  185 + */
  186 + private String gybzgId;
  187 +
  188 + /**
  189 + * 供应部主管审核人
  190 + */
  191 + private String gybzgName;
  192 +
  193 + /**
  194 + * 是否作废 0-有效单 1-作废单(作废单只能查看)
  195 + */
  196 + private Boolean deleted;
  197 +
  198 + /**
  199 + * 创建人ID
  200 + */
  201 + @TableField(fill = FieldFill.INSERT)
  202 + private String createById;
  203 +
  204 + /**
  205 + * 创建人
  206 + */
  207 + @TableField(fill = FieldFill.INSERT)
  208 + private String createBy;
  209 +
  210 + /**
  211 + * 更新人ID
  212 + */
  213 + @TableField(fill = FieldFill.INSERT_UPDATE)
  214 + private String updateById;
  215 +
  216 + /**
  217 + * 更新人
  218 + */
  219 + @TableField(fill = FieldFill.INSERT_UPDATE)
  220 + private String updateBy;
  221 +
  222 + /**
  223 + * 创建时间
  224 + */
  225 + @TableField(fill = FieldFill.INSERT)
  226 + private LocalDateTime createTime;
  227 +
  228 + /**
  229 + * 更新时间
  230 + */
  231 + @TableField(fill = FieldFill.INSERT_UPDATE)
  232 + private LocalDateTime updateTime;
  233 +
  234 + /**
  235 + * 分厂编号(联表 base_data_workshop 带出,非数据库字段;分厂审核节点编码 = BUYOUT_ACCOUNT_ORDER_ + 分厂前缀 + 环节缩写)
  236 + */
  237 + @TableField(exist = false)
  238 + private String workshopCode;
  239 +
  240 + /**
  241 + * 审核按钮标记(待办驱动,非数据库字段)
  242 + */
  243 + @TableField(exist = false)
  244 + private Boolean showExamine;
  245 +
  246 + /**
  247 + * 审核详情按钮标记(存在流程实例,非数据库字段)
  248 + */
  249 + @TableField(exist = false)
  250 + private Boolean showExamineDetail;
  251 +}
... ...
  1 +package com.lframework.xingyun.sc.procurement.entity.buyoutAccount;
  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_buyout_account_order_line")
  17 +public class ProcurementBuyoutAccountOrderLine 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 orderId;
  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 buyoutCategory;
  50 +
  51 + /**
  52 + * 买断数量 kg(原料结算详情单过磅数)
  53 + */
  54 + private BigDecimal buyoutQuantity;
  55 +
  56 + /**
  57 + * 买断单价 元/kg(仓库收料单含税单价)
  58 + */
  59 + private BigDecimal buyoutPrice;
  60 +
  61 + /**
  62 + * 买断金额 = 买断单价*买断数量
  63 + */
  64 + private BigDecimal buyoutAmount;
  65 +
  66 + /**
  67 + * 入库数量 kg(申请净重-退料-折斤,可修改)
  68 + */
  69 + private BigDecimal instockQuantity;
  70 +
  71 + /**
  72 + * 入库单价 元/kg(可修改)
  73 + */
  74 + private BigDecimal instockPrice;
  75 +
  76 + /**
  77 + * 入库金额 元(可修改)
  78 + */
  79 + private BigDecimal instockAmount;
  80 +
  81 + /**
  82 + * 预计吨损耗 元/吨(按计划取买断操作申请表)
  83 + */
  84 + private BigDecimal expectTonLoss;
  85 +
  86 + /**
  87 + * 实际吨损耗 元/吨(可修改)
  88 + */
  89 + private BigDecimal actualTonLoss;
  90 +
  91 + /**
  92 + * 吨损耗差异 元/吨 = 预计-实际
  93 + */
  94 + private BigDecimal tonLossDiff;
  95 +
  96 + /**
  97 + * 差异金额 元 = 入库数量*吨损耗差异/1000
  98 + */
  99 + private BigDecimal diffAmount;
  100 +
  101 + /**
  102 + * 创建人ID
  103 + */
  104 + @TableField(fill = FieldFill.INSERT)
  105 + private String createById;
  106 +
  107 + /**
  108 + * 创建人
  109 + */
  110 + @TableField(fill = FieldFill.INSERT)
  111 + private String createBy;
  112 +
  113 + /**
  114 + * 更新人ID
  115 + */
  116 + @TableField(fill = FieldFill.INSERT_UPDATE)
  117 + private String updateById;
  118 +
  119 + /**
  120 + * 更新人
  121 + */
  122 + @TableField(fill = FieldFill.INSERT_UPDATE)
  123 + private String updateBy;
  124 +
  125 + /**
  126 + * 创建时间
  127 + */
  128 + @TableField(fill = FieldFill.INSERT)
  129 + private LocalDateTime createTime;
  130 +
  131 + /**
  132 + * 更新时间
  133 + */
  134 + @TableField(fill = FieldFill.INSERT_UPDATE)
  135 + private LocalDateTime updateTime;
  136 +}
... ...
  1 +package com.lframework.xingyun.sc.procurement.impl.buyoutAccount;
  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.buyoutAccount.ProcurementBuyoutAccountOrderLine;
  6 +import com.lframework.xingyun.sc.procurement.mappers.buyoutAccount.ProcurementBuyoutAccountOrderLineMapper;
  7 +import com.lframework.xingyun.sc.procurement.service.buyoutAccount.ProcurementBuyoutAccountOrderLineService;
  8 +import java.util.List;
  9 +import org.springframework.stereotype.Service;
  10 +
  11 +@Service
  12 +public class ProcurementBuyoutAccountOrderLineServiceImpl
  13 + extends BaseMpServiceImpl<ProcurementBuyoutAccountOrderLineMapper, ProcurementBuyoutAccountOrderLine>
  14 + implements ProcurementBuyoutAccountOrderLineService {
  15 +
  16 + @Override
  17 + public List<ProcurementBuyoutAccountOrderLine> getByOrderId(String orderId) {
  18 + return this.list(Wrappers.lambdaQuery(ProcurementBuyoutAccountOrderLine.class)
  19 + .eq(ProcurementBuyoutAccountOrderLine::getOrderId, orderId));
  20 + }
  21 +
  22 + @Override
  23 + public void deleteByOrderId(String orderId) {
  24 + this.remove(Wrappers.lambdaQuery(ProcurementBuyoutAccountOrderLine.class)
  25 + .eq(ProcurementBuyoutAccountOrderLine::getOrderId, orderId));
  26 + }
  27 +}
... ...
  1 +package com.lframework.xingyun.sc.procurement.impl.buyoutAccount;
  2 +
  3 +import cn.hutool.core.bean.BeanUtil;
  4 +import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  5 +import com.github.pagehelper.PageInfo;
  6 +import com.lframework.starter.bpm.dto.FlowTaskDto;
  7 +import com.lframework.starter.bpm.entity.FlowInstanceWrapper;
  8 +import com.lframework.starter.bpm.mappers.FlowTaskWrapperMapper;
  9 +import com.lframework.starter.bpm.service.FlowInstanceWrapperService;
  10 +import com.lframework.starter.bpm.service.FlowTaskWrapperService;
  11 +import com.lframework.starter.bpm.vo.flow.task.QueryTodoTaskListVo;
  12 +import com.lframework.starter.common.exceptions.impl.DefaultClientException;
  13 +import com.lframework.starter.common.exceptions.impl.InputErrorException;
  14 +import com.lframework.starter.common.utils.Assert;
  15 +import com.lframework.starter.common.utils.CollectionUtil;
  16 +import com.lframework.starter.common.utils.StringUtil;
  17 +import com.lframework.starter.web.core.annotations.oplog.OpLog;
  18 +import com.lframework.starter.web.core.components.resp.PageResult;
  19 +import com.lframework.starter.web.core.components.security.SecurityUtil;
  20 +import com.lframework.starter.web.core.impl.BaseMpServiceImpl;
  21 +import com.lframework.starter.web.core.utils.IdUtil;
  22 +import com.lframework.starter.web.core.utils.OpLogUtil;
  23 +import com.lframework.starter.web.core.utils.PageHelperUtil;
  24 +import com.lframework.starter.web.core.utils.PageResultUtil;
  25 +import com.lframework.starter.web.inner.components.oplog.OtherOpLogType;
  26 +import com.lframework.starter.web.inner.entity.SysDept;
  27 +import com.lframework.starter.web.inner.service.system.SysDeptService;
  28 +import com.lframework.xingyun.sc.bo.procurement.GetBuyoutAccountOrderBo;
  29 +import com.lframework.xingyun.sc.bo.procurement.GetBuyoutSettleDataBo;
  30 +import com.lframework.xingyun.sc.procurement.entity.ProcurementBuyoutApply;
  31 +import com.lframework.xingyun.sc.procurement.entity.ProcurementBuyoutApplyLine;
  32 +import com.lframework.xingyun.sc.procurement.entity.ProcurementPlan;
  33 +import com.lframework.xingyun.sc.procurement.entity.settle.ProcurementMaterialSettleApplyLine;
  34 +import com.lframework.xingyun.sc.procurement.entity.settle.ProcurementMaterialSettleDetail;
  35 +import com.lframework.xingyun.sc.procurement.entity.settle.ProcurementMaterialSettleLine;
  36 +import com.lframework.xingyun.sc.procurement.entity.receive.ProcurementWarehouseReceiveOrder;
  37 +import com.lframework.xingyun.sc.procurement.entity.receive.ProcurementWarehouseReceiveOrderLine;
  38 +import com.lframework.xingyun.sc.procurement.entity.buyoutAccount.ProcurementBuyoutAccountOrder;
  39 +import com.lframework.xingyun.sc.procurement.entity.buyoutAccount.ProcurementBuyoutAccountOrderLine;
  40 +import com.lframework.xingyun.sc.procurement.mappers.buyoutAccount.ProcurementBuyoutAccountOrderMapper;
  41 +import com.lframework.xingyun.sc.procurement.mappers.receive.ProcurementWarehouseReceiveOrderLineMapper;
  42 +import com.lframework.xingyun.sc.procurement.mappers.receive.ProcurementWarehouseReceiveOrderMapper;
  43 +import com.lframework.xingyun.sc.procurement.mappers.settle.ProcurementMaterialSettleDetailMapper;
  44 +import com.lframework.xingyun.sc.procurement.service.buyout.ProcurementBuyoutApplyLineService;
  45 +import com.lframework.xingyun.sc.procurement.service.buyout.ProcurementBuyoutApplyService;
  46 +import com.lframework.xingyun.sc.procurement.service.buyoutAccount.ProcurementBuyoutAccountOrderLineService;
  47 +import com.lframework.xingyun.sc.procurement.service.buyoutAccount.ProcurementBuyoutAccountOrderService;
  48 +import com.lframework.xingyun.sc.procurement.service.plan.ProcurementPlanService;
  49 +import com.lframework.xingyun.sc.procurement.service.settle.ProcurementMaterialSettleApplyLineService;
  50 +import com.lframework.xingyun.sc.procurement.service.settle.ProcurementMaterialSettleLineService;
  51 +import com.lframework.xingyun.sc.procurement.vo.buyoutAccount.CreateBuyoutAccountOrderVo;
  52 +import com.lframework.xingyun.sc.procurement.vo.buyoutAccount.QueryBuyoutAccountOrderVo;
  53 +import com.lframework.xingyun.sc.procurement.vo.buyoutAccount.UpdateBuyoutAccountOrderVo;
  54 +import com.lframework.xingyun.sc.procurement.vo.buyoutAccount.BuyoutAccountOrderLineVo;
  55 +
  56 +import java.math.BigDecimal;
  57 +import java.time.LocalDate;
  58 +import java.util.*;
  59 +import java.util.stream.Collectors;
  60 +import javax.annotation.Resource;
  61 +
  62 +import lombok.extern.slf4j.Slf4j;
  63 +import org.apache.commons.collections.CollectionUtils;
  64 +import org.springframework.stereotype.Service;
  65 +import org.springframework.transaction.annotation.Transactional;
  66 +
  67 +/**
  68 + * 买断入库核算单(入库第六模块,原料结算详情单流转,分厂仓库统计员制单)
  69 + * 关联原料结算详情单下的仓库收料单必须审核通过
  70 + * 分厂仓库统计员 -> 分厂仓库质检员 -> 供应管理科质检员 -> 分厂仓库主管 -> 供应管理科主管 -> 供应部主管
  71 + */
  72 +@Slf4j
  73 +@Service
  74 +public class ProcurementBuyoutAccountOrderServiceImpl
  75 + extends BaseMpServiceImpl<ProcurementBuyoutAccountOrderMapper, ProcurementBuyoutAccountOrder>
  76 + implements ProcurementBuyoutAccountOrderService {
  77 +
  78 + /**
  79 + * 审核状态-草稿
  80 + */
  81 + private static final String STATUS_DRAFT = "DRAFT";
  82 + /**
  83 + * 审核状态-审核中
  84 + */
  85 + private static final String STATUS_AUDIT = "AUDIT";
  86 + /**
  87 + * 审核状态-审核通过
  88 + */
  89 + private static final String STATUS_PASS = "PASS";
  90 + /**
  91 + * 审核状态-已驳回
  92 + */
  93 + private static final String STATUS_REFUSE = "REFUSE";
  94 + /**
  95 + * 审核状态-已取消
  96 + */
  97 + private static final String STATUS_CANCEL = "CANCEL";
  98 + /**
  99 + * 流程节点(分厂仓库统计员制单 + 六个审核环节,需与流程设计器中的流程编号一致,流程创建后调整)
  100 + */
  101 + private static final String NODE_FCCKTJY = "FCCKTJY";
  102 + private static final String NODE_FCCKZG = "FCCKZG";
  103 + private static final String NODE_FCZLFG = "FCZLFG";
  104 + private static final String NODE_GYGLKZG = "GYGLKZG";
  105 + private static final String NODE_FCYLKJ = "FCYLKJ";
  106 + private static final String NODE_FCCWKZG = "FCCWKZG";
  107 + private static final String NODE_GYBZG = "GYBZG";
  108 + /**
  109 + * 流程编号(需与流程设计器中的流程编号一致,流程创建后调整)
  110 + */
  111 + private static final String BPM_FLAG = "BUYOUT_ACCOUNT_ORDER";
  112 +
  113 + @Resource
  114 + private ProcurementBuyoutAccountOrderMapper buyoutAccountOrderMapper;
  115 + @Resource
  116 + private ProcurementBuyoutAccountOrderLineService orderLineService;
  117 + @Resource
  118 + private ProcurementMaterialSettleDetailMapper settleDetailMapper;
  119 + @Resource
  120 + private ProcurementMaterialSettleLineService settleLineService;
  121 + @Resource
  122 + private ProcurementMaterialSettleApplyLineService settleApplyLineService;
  123 + @Resource
  124 + private ProcurementWarehouseReceiveOrderMapper receiveOrderMapper;
  125 + @Resource
  126 + private ProcurementWarehouseReceiveOrderLineMapper receiveOrderLineMapper;
  127 + @Resource
  128 + private ProcurementPlanService procurementPlanService;
  129 + @Resource
  130 + private ProcurementBuyoutApplyService buyoutApplyService;
  131 + @Resource
  132 + private ProcurementBuyoutApplyLineService buyoutApplyLineService;
  133 + @Resource
  134 + private SysDeptService sysDeptService;
  135 + @Resource
  136 + private FlowInstanceWrapperService flowInstanceWrapperService;
  137 + @Resource
  138 + private FlowTaskWrapperMapper flowTaskWrapperMapper;
  139 + @Resource
  140 + private FlowTaskWrapperService flowTaskWrapperService;
  141 +
  142 + @Override
  143 + public PageResult<ProcurementBuyoutAccountOrder> query(Integer pageIndex, Integer pageSize,
  144 + QueryBuyoutAccountOrderVo vo) {
  145 + PageHelperUtil.startPage(pageIndex, pageSize);
  146 + List<ProcurementBuyoutAccountOrder> datas = buyoutAccountOrderMapper.query(vo);
  147 + PageResult<ProcurementBuyoutAccountOrder> pageResult = PageResultUtil.convert(new PageInfo<>(datas));
  148 +
  149 + fillOperateFlags(pageResult.getDatas());
  150 +
  151 + return pageResult;
  152 + }
  153 +
  154 + @Override
  155 + public GetBuyoutAccountOrderBo findDetail(String id) {
  156 + if (StringUtil.isBlank(id)) {
  157 + throw new InputErrorException("ID不能为空!");
  158 + }
  159 +
  160 + ProcurementBuyoutAccountOrder entity = buyoutAccountOrderMapper.findById(id);
  161 + if (entity == null) {
  162 + throw new DefaultClientException("买断入库核算单不存在!");
  163 + }
  164 + fillOperateFlags(Collections.singletonList(entity));
  165 +
  166 + GetBuyoutAccountOrderBo bo = new GetBuyoutAccountOrderBo();
  167 + BeanUtil.copyProperties(entity, bo);
  168 + bo.setPlanCodes(splitToList(entity.getPlanCodes()));
  169 +
  170 + List<ProcurementBuyoutAccountOrderLine> lines = orderLineService.getByOrderId(id);
  171 + if (CollectionUtil.isNotEmpty(lines)) {
  172 + for (ProcurementBuyoutAccountOrderLine line : lines) {
  173 + bo.getLines().add(BeanUtil.copyProperties(line, GetBuyoutAccountOrderBo.LineBo.class));
  174 + }
  175 + }
  176 +
  177 + return bo;
  178 + }
  179 +
  180 + @Override
  181 + public List<GetBuyoutSettleDataBo> getSettleOptions() {
  182 + // 可制单的原料结算详情单:审核通过 + 未作废 + 未生成过核算单(收料单审核通过的条件在循环内校验)
  183 + List<ProcurementMaterialSettleDetail> settles = settleDetailMapper.selectList(
  184 + Wrappers.lambdaQuery(ProcurementMaterialSettleDetail.class)
  185 + .eq(ProcurementMaterialSettleDetail::getApprovalStatus, STATUS_PASS)
  186 + .eq(ProcurementMaterialSettleDetail::getDeleted, false)
  187 + .orderByDesc(ProcurementMaterialSettleDetail::getCreateTime));
  188 + if (CollectionUtil.isEmpty(settles)) {
  189 + return new ArrayList<>();
  190 + }
  191 +
  192 + Set<String> usedSettleIds = new HashSet<>();
  193 + // 已生成过买断入库核算单的结算详情单ID集合
  194 + List<ProcurementBuyoutAccountOrder> usedOrders = this.list(
  195 + Wrappers.lambdaQuery(ProcurementBuyoutAccountOrder.class)
  196 + .eq(ProcurementBuyoutAccountOrder::getDeleted, false)
  197 + .in(ProcurementBuyoutAccountOrder::getSettleDetailId,
  198 + settles.stream().map(ProcurementMaterialSettleDetail::getId).collect(Collectors.toList())));
  199 + if (CollectionUtil.isNotEmpty(usedOrders)) {
  200 + usedSettleIds = usedOrders.stream()
  201 + .map(ProcurementBuyoutAccountOrder::getSettleDetailId)
  202 + .collect(Collectors.toSet());
  203 + }
  204 +
  205 + List<GetBuyoutSettleDataBo> options = new ArrayList<>();
  206 + for (ProcurementMaterialSettleDetail settle : settles) {
  207 + if (usedSettleIds.contains(settle.getId())) {
  208 + continue;
  209 + }
  210 + // 前提:该结算详情单下的仓库收料单必须审核通过
  211 + if (!warehouseReceiveOrderPassed(settle.getId())) {
  212 + continue;
  213 + }
  214 + // planCodes 为联表字段(exist=false),MP 单表查询带不出,改用 findById
  215 + ProcurementMaterialSettleDetail detail = settleDetailMapper.findById(settle.getId());
  216 + if (detail == null) {
  217 + continue;
  218 + }
  219 + GetBuyoutSettleDataBo option = new GetBuyoutSettleDataBo();
  220 + option.setSettleDetailId(detail.getId());
  221 + option.setWeighingTicketId(detail.getWeighingTicketId());
  222 + option.setWeighingTicketCode(detail.getWeighingTicketCode());
  223 + option.setIncomingUnit(detail.getSupplierName());
  224 + option.setPlanCodes(detail.getPlanCodes());
  225 + option.setWorkshopId(detail.getWorkshopId());
  226 + option.setWorkshopName(detail.getWorkshopName());
  227 + options.add(option);
  228 + }
  229 + return options;
  230 + }
  231 +
  232 + @Override
  233 + public GetBuyoutSettleDataBo getSettleData(String settleDetailId) {
  234 + ProcurementMaterialSettleDetail settle = assertSettleUsable(settleDetailId);
  235 +
  236 + GetBuyoutSettleDataBo bo = new GetBuyoutSettleDataBo();
  237 + bo.setSettleDetailId(settle.getId());
  238 + bo.setWeighingTicketId(settle.getWeighingTicketId());
  239 + bo.setWeighingTicketCode(settle.getWeighingTicketCode());
  240 + bo.setIncomingUnit(settle.getSupplierName());
  241 + bo.setPlanCodes(settle.getPlanCodes());
  242 + bo.setWorkshopId(settle.getWorkshopId());
  243 + bo.setWorkshopName(settle.getWorkshopName());
  244 +
  245 + // 采购处/区域:取第一个采购计划(多个计划的采购处、区域需一致)
  246 + List<ProcurementPlan> plans = listPlans(settle);
  247 + if (CollectionUtil.isNotEmpty(plans)) {
  248 + ProcurementPlan first = plans.get(0);
  249 + bo.setPurchaseDepartmentId(first.getPurchaseDepartment());
  250 + bo.setRegionId(first.getRegion());
  251 + Map<String, String> deptNameMap = getDeptNameMap(plans);
  252 + bo.setPurchaseDepartmentName(deptNameMap.get(first.getPurchaseDepartment()));
  253 + bo.setRegionName(deptNameMap.get(first.getRegion()));
  254 + }
  255 +
  256 + // 明细自动带出
  257 + // 买断单价:仓库收料单明细按来源行(结算明细行ID)匹配含税单价
  258 + Map<String, BigDecimal> receiveTaxPriceMap = getReceiveTaxPriceMap(settle.getId());
  259 + // 入库数量:申请净重(品种关系ID -> 合计申请净重)- 退料 - 折斤
  260 + Map<String, BigDecimal> applyQuantityMap = settleApplyLineService.getBySettleDetailId(settleDetailId)
  261 + .stream()
  262 + .filter(l -> l != null && StringUtil.isNotBlank(l.getBreedRelationshipId()) && l.getQuantity() != null)
  263 + .collect(Collectors.toMap(ProcurementMaterialSettleApplyLine::getBreedRelationshipId,
  264 + ProcurementMaterialSettleApplyLine::getQuantity, BigDecimal::add));
  265 + // 预计吨损耗:按计划+品种取买断操作申请表明细的预计损耗
  266 + Map<String, BigDecimal> expectLossMap = getExpectLossMap(settle);
  267 +
  268 + List<ProcurementMaterialSettleLine> settleLines = settleLineService.getBySettleDetailId(settleDetailId);
  269 + for (ProcurementMaterialSettleLine settleLine : settleLines) {
  270 + if (settleLine == null) {
  271 + continue;
  272 + }
  273 + BuyoutAccountOrderLineVo lineVo = new BuyoutAccountOrderLineVo();
  274 + lineVo.setSettleLineId(settleLine.getId());
  275 + lineVo.setProcurementPlanId(settleLine.getProcurementPlanId());
  276 + lineVo.setProductId(settleLine.getProductId());
  277 + lineVo.setBuyoutCategory(settleLine.getCategory());
  278 + lineVo.setBuyoutQuantity(settleLine.getWeighQuantity());
  279 + lineVo.setBuyoutPrice(receiveTaxPriceMap.get(settleLine.getId()));
  280 + if (lineVo.getBuyoutPrice() != null && lineVo.getBuyoutQuantity() != null) {
  281 + lineVo.setBuyoutAmount(lineVo.getBuyoutPrice().multiply(lineVo.getBuyoutQuantity()));
  282 + }
  283 + lineVo.setInstockQuantity(calcInstockQuantity(settleLine, applyQuantityMap));
  284 + lineVo.setExpectTonLoss(expectLossMap.get(settleLine.getProcurementPlanId() + "|" + settleLine.getProductId()));
  285 + bo.getLines().add(lineVo);
  286 + }
  287 + return bo;
  288 + }
  289 +
  290 + @Override
  291 + @Transactional(rollbackFor = Exception.class)
  292 + @OpLog(type = OtherOpLogType.class, name = "新增买断入库核算单,ID:{}", params = {"#result"})
  293 + public String create(CreateBuyoutAccountOrderVo vo) {
  294 + ProcurementMaterialSettleDetail settle = assertSettleUsable(vo.getSettleDetailId());
  295 +
  296 + ProcurementBuyoutAccountOrder entity = new ProcurementBuyoutAccountOrder();
  297 + entity.setId(IdUtil.getId());
  298 + entity.setSettleDetailId(settle.getId());
  299 + entity.setWeighingTicketId(settle.getWeighingTicketId());
  300 + entity.setWeighingTicketCode(settle.getWeighingTicketCode());
  301 + entity.setIncomingUnit(settle.getSupplierName());
  302 + entity.setPlanCodes(settle.getPlanCodes());
  303 + entity.setPlanIds(settle.getPlanIds());
  304 + entity.setWorkshopId(settle.getWorkshopId());
  305 + entity.setWorkshopName(settle.getWorkshopName());
  306 +
  307 + // 采购处/区域:取第一个采购计划(多个计划的采购处、区域需一致)
  308 + List<ProcurementPlan> plans = listPlans(settle);
  309 + if (CollectionUtil.isNotEmpty(plans)) {
  310 + ProcurementPlan first = plans.get(0);
  311 + entity.setPurchaseDepartmentId(first.getPurchaseDepartment());
  312 + entity.setRegionId(first.getRegion());
  313 + Map<String, String> deptNameMap = getDeptNameMap(plans);
  314 + entity.setPurchaseDepartmentName(deptNameMap.get(first.getPurchaseDepartment()));
  315 + entity.setRegionName(deptNameMap.get(first.getRegion()));
  316 + }
  317 +
  318 + // 合计由前端计算传入,后端保存
  319 + entity.setTotalBuyoutQuantity(vo.getTotalBuyoutQuantity());
  320 + entity.setTotalBuyoutAmount(vo.getTotalBuyoutAmount());
  321 + entity.setTotalInstockQuantity(vo.getTotalInstockQuantity());
  322 + entity.setTotalInstockAmount(vo.getTotalInstockAmount());
  323 + entity.setTotalDiffAmount(vo.getTotalDiffAmount());
  324 + entity.setApprovalStatus(STATUS_DRAFT);
  325 + // 制单阶段当前节点为分厂仓库统计员
  326 + entity.setFlowNode(NODE_FCCKTJY);
  327 +
  328 + this.save(entity);
  329 + saveLines(entity.getId(), vo.getLines());
  330 +
  331 + OpLogUtil.setVariable("id", entity.getId());
  332 + OpLogUtil.setExtra(entity);
  333 +
  334 + return entity.getId();
  335 + }
  336 +
  337 + @Override
  338 + @Transactional(rollbackFor = Exception.class)
  339 + @OpLog(type = OtherOpLogType.class, name = "修改买断入库核算单,ID:{}", params = {"#vo.id"})
  340 + public void update(UpdateBuyoutAccountOrderVo vo) {
  341 + Assert.notBlank(vo.getId(), "ID不能为空!");
  342 +
  343 + ProcurementBuyoutAccountOrder oldEntity = this.getById(vo.getId());
  344 + if (oldEntity == null) {
  345 + throw new DefaultClientException("买断入库核算单不存在!");
  346 + }
  347 + // 作废单只能查看;仅草稿、已驳回可修改
  348 + assertValid(oldEntity);
  349 + assertEditable(oldEntity);
  350 +
  351 + ProcurementBuyoutAccountOrder entity = new ProcurementBuyoutAccountOrder();
  352 + entity.setId(vo.getId());
  353 + // 合计由前端计算传入,后端保存
  354 + entity.setTotalBuyoutQuantity(vo.getTotalBuyoutQuantity());
  355 + entity.setTotalBuyoutAmount(vo.getTotalBuyoutAmount());
  356 + entity.setTotalInstockQuantity(vo.getTotalInstockQuantity());
  357 + entity.setTotalInstockAmount(vo.getTotalInstockAmount());
  358 + entity.setTotalDiffAmount(vo.getTotalDiffAmount());
  359 +
  360 + this.updateById(entity);
  361 +
  362 + // 明细整体重建
  363 + orderLineService.deleteByOrderId(vo.getId());
  364 + saveLines(vo.getId(), vo.getLines());
  365 +
  366 + OpLogUtil.setVariable("id", entity.getId());
  367 + OpLogUtil.setExtra(entity);
  368 + }
  369 +
  370 + @Override
  371 + @Transactional(rollbackFor = Exception.class)
  372 + @OpLog(type = OtherOpLogType.class, name = "提交买断入库核算单审核,ID:{}", params = {"#id"})
  373 + public void submit(String id) {
  374 + Assert.notBlank(id);
  375 +
  376 + // 联表带出分厂编号(分厂审核节点编码 = BUYOUT_ACCOUNT_ORDER_ + 分厂前缀 + 环节缩写,startInstance 传实体时必须带出)
  377 + ProcurementBuyoutAccountOrder entity = buyoutAccountOrderMapper.findById(id);
  378 + if (entity == null) {
  379 + throw new DefaultClientException("买断入库核算单不存在!");
  380 + }
  381 + assertValid(entity);
  382 + if (!STATUS_DRAFT.equals(entity.getApprovalStatus()) && !STATUS_REFUSE.equals(entity.getApprovalStatus())) {
  383 + throw new DefaultClientException("当前单据状态不允许提交审核!");
  384 + }
  385 +
  386 + List<ProcurementBuyoutAccountOrderLine> lines = orderLineService.getByOrderId(id);
  387 + if (CollectionUtil.isEmpty(lines)) {
  388 + throw new DefaultClientException("明细不能为空!");
  389 + }
  390 +
  391 + this.update(Wrappers.lambdaUpdate(ProcurementBuyoutAccountOrder.class)
  392 + .set(ProcurementBuyoutAccountOrder::getApprovalStatus, STATUS_AUDIT)
  393 + // 提交审核后流程节点推进到分厂仓库主管
  394 + .set(ProcurementBuyoutAccountOrder::getFlowNode, NODE_FCCKZG)
  395 + .eq(ProcurementBuyoutAccountOrder::getId, id));
  396 +
  397 + flowInstanceWrapperService.startInstance(BPM_FLAG, entity.getId(), BPM_FLAG, entity);
  398 +
  399 + OpLogUtil.setVariable("id", id);
  400 + OpLogUtil.setExtra(entity);
  401 + }
  402 +
  403 + @Override
  404 + @Transactional(rollbackFor = Exception.class)
  405 + @OpLog(type = OtherOpLogType.class, name = "取消买断入库核算单,ID:{}", params = {"#id"})
  406 + public void cancel(String id) {
  407 + Assert.notBlank(id);
  408 +
  409 + ProcurementBuyoutAccountOrder entity = this.getById(id);
  410 + if (entity == null) {
  411 + throw new DefaultClientException("买断入库核算单不存在!");
  412 + }
  413 + assertValid(entity);
  414 + // 草稿、已驳回状态可取消
  415 + if (!STATUS_DRAFT.equals(entity.getApprovalStatus()) && !STATUS_REFUSE.equals(entity.getApprovalStatus())) {
  416 + throw new DefaultClientException("仅草稿、已驳回状态的买断入库核算单可取消!");
  417 + }
  418 +
  419 + this.update(Wrappers.lambdaUpdate(ProcurementBuyoutAccountOrder.class)
  420 + .set(ProcurementBuyoutAccountOrder::getApprovalStatus, STATUS_CANCEL)
  421 + .set(ProcurementBuyoutAccountOrder::getFlowNode, null)
  422 + .eq(ProcurementBuyoutAccountOrder::getId, id));
  423 +
  424 + OpLogUtil.setVariable("id", id);
  425 + OpLogUtil.setExtra(entity);
  426 + }
  427 +
  428 + @Override
  429 + @Transactional(rollbackFor = Exception.class)
  430 + public void updateApprovalStatus(String id, String approvalStatus) {
  431 + if (StringUtil.isBlank(id) || StringUtil.isBlank(approvalStatus)) {
  432 + throw new DefaultClientException("买断入库核算单ID、审核状态不能为空!");
  433 + }
  434 +
  435 + ProcurementBuyoutAccountOrder entity = this.getById(id);
  436 + if (entity == null) {
  437 + throw new DefaultClientException("买断入库核算单不存在!");
  438 + }
  439 +
  440 + this.update(Wrappers.lambdaUpdate(ProcurementBuyoutAccountOrder.class)
  441 + .set(ProcurementBuyoutAccountOrder::getApprovalStatus, approvalStatus)
  442 + .set(ProcurementBuyoutAccountOrder::getFlowNode, approvalStatus.equals("PASS") ? null : NODE_FCCKTJY)
  443 + .eq(ProcurementBuyoutAccountOrder::getId, id));
  444 + }
  445 +
  446 + @Override
  447 + @Transactional(rollbackFor = Exception.class)
  448 + public void updateNoFlowInstance(Map<String, Object> map) {
  449 + try {
  450 + // 审核状态
  451 + Object examStatusObj = map.get("examStatus");
  452 + String examStatus = examStatusObj == null ? null : String.valueOf(examStatusObj);
  453 +
  454 + // 刚审核完成的环节编码(BUYOUT_ACCOUNT_ORDER_ + 分厂前缀 + 名称缩写)
  455 + Object nodeObj = map.get("nodeCode");
  456 + String nodeCode = nodeObj == null ? null : String.valueOf(nodeObj);
  457 +
  458 + // 业务ID(兼容 variables 子 map 包裹)
  459 + String bizId = resolveBizId(map);
  460 + if (StringUtil.isBlank(bizId)) {
  461 + throw new DefaultClientException("买断入库核算单审核回调缺少业务ID!");
  462 + }
  463 +
  464 + // 各审核环节匹配(nodeCode 尾部名称缩写,兼容分厂前缀 yfc/efc/sfc/ztfc)
  465 + boolean fcckzgNode = nodeCode != null && nodeCode.endsWith("fcckzg");
  466 + boolean fczlfgNode = nodeCode != null && nodeCode.endsWith("fczlfg");
  467 + boolean gyglkzgNode = nodeCode != null && nodeCode.endsWith("gyglkzg");
  468 + boolean fcylkjNode = nodeCode != null && nodeCode.endsWith("fcylkj");
  469 + boolean fccwkzgNode = nodeCode != null && nodeCode.endsWith("fccwkzg");
  470 + boolean gybzgNode = nodeCode != null && nodeCode.endsWith("gybzg");
  471 +
  472 + // 审核通过时记录当前环节审核人(人员ID和名称)
  473 + boolean pass = "PASS".equals(examStatus);
  474 + String userId = null;
  475 + String userName = null;
  476 + if (pass) {
  477 + userId = SecurityUtil.getCurrentUser().getId();
  478 + userName = SecurityUtil.getCurrentUser().getName();
  479 + }
  480 +
  481 + // 拒绝/撤销/终止:统一回到分厂仓库统计员(制单)
  482 + if (StringUtil.isNotBlank(examStatus) && !pass) {
  483 + this.update(Wrappers.lambdaUpdate(ProcurementBuyoutAccountOrder.class)
  484 + .set(ProcurementBuyoutAccountOrder::getFlowNode, NODE_FCCKTJY)
  485 + .eq(ProcurementBuyoutAccountOrder::getId, bizId));
  486 + return;
  487 + }
  488 +
  489 + // 审核通过:按刚审核完成的环节编码推进到下一节点
  490 + // (供应部主管环节通过即流程结束,flow_node 由终态回调一并清空)
  491 + String nextNode = nextFlowNode(nodeCode);
  492 +
  493 + // 未匹配到审核环节且无节点推进,忽略
  494 + if (nextNode == null && !fcckzgNode && !fczlfgNode && !gyglkzgNode && !fcylkjNode
  495 + && !fccwkzgNode && !gybzgNode) {
  496 + return;
  497 + }
  498 +
  499 + this.update(Wrappers.lambdaUpdate(ProcurementBuyoutAccountOrder.class)
  500 + .set(fcckzgNode, ProcurementBuyoutAccountOrder::getFcckzgId, userId)
  501 + .set(fcckzgNode, ProcurementBuyoutAccountOrder::getFcckzgName, userName)
  502 + .set(fczlfgNode, ProcurementBuyoutAccountOrder::getFczlfgId, userId)
  503 + .set(fczlfgNode, ProcurementBuyoutAccountOrder::getFczlfgName, userName)
  504 + .set(gyglkzgNode, ProcurementBuyoutAccountOrder::getGyglkzgId, userId)
  505 + .set(gyglkzgNode, ProcurementBuyoutAccountOrder::getGyglkzgName, userName)
  506 + .set(fcylkjNode, ProcurementBuyoutAccountOrder::getFcylkjId, userId)
  507 + .set(fcylkjNode, ProcurementBuyoutAccountOrder::getFcylkjName, userName)
  508 + .set(fccwkzgNode, ProcurementBuyoutAccountOrder::getFccwkzgId, userId)
  509 + .set(fccwkzgNode, ProcurementBuyoutAccountOrder::getFccwkzgName, userName)
  510 + .set(gybzgNode, ProcurementBuyoutAccountOrder::getGybzgId, userId)
  511 + .set(gybzgNode, ProcurementBuyoutAccountOrder::getGybzgName, userName)
  512 + .set(nextNode != null, ProcurementBuyoutAccountOrder::getFlowNode, nextNode)
  513 + .eq(ProcurementBuyoutAccountOrder::getId, bizId));
  514 + } catch (Exception ex) {
  515 + ex.printStackTrace();
  516 + }
  517 + }
  518 +
  519 + @Override
  520 + @Transactional(rollbackFor = Exception.class)
  521 + public void deleteBySettleDetailId(String settleDetailId) {
  522 + if (StringUtil.isBlank(settleDetailId)) {
  523 + return;
  524 + }
  525 +
  526 + // 该结算详情单下所有未作废的买断入库核算单,联动作废
  527 + List<ProcurementBuyoutAccountOrder> orders = this.list(
  528 + Wrappers.lambdaQuery(ProcurementBuyoutAccountOrder.class)
  529 + .eq(ProcurementBuyoutAccountOrder::getSettleDetailId, settleDetailId)
  530 + .eq(ProcurementBuyoutAccountOrder::getDeleted, false));
  531 + if (CollectionUtil.isEmpty(orders)) {
  532 + return;
  533 + }
  534 +
  535 + for (ProcurementBuyoutAccountOrder order : orders) {
  536 + // 审核中的先终止流程,再作废
  537 + if (STATUS_AUDIT.equals(order.getApprovalStatus())) {
  538 + terminateRunningFlow(order.getId());
  539 + }
  540 + this.update(Wrappers.lambdaUpdate(ProcurementBuyoutAccountOrder.class)
  541 + .set(ProcurementBuyoutAccountOrder::getDeleted, true)
  542 + .set(STATUS_AUDIT.equals(order.getApprovalStatus()),
  543 + ProcurementBuyoutAccountOrder::getApprovalStatus, STATUS_REFUSE)
  544 + .eq(ProcurementBuyoutAccountOrder::getId, order.getId()));
  545 + }
  546 + }
  547 +
  548 + @Override
  549 + @Transactional(rollbackFor = Exception.class)
  550 + public void deleteByWeighingTicketId(String weighingTicketId) {
  551 + if (StringUtil.isBlank(weighingTicketId)) {
  552 + return;
  553 + }
  554 +
  555 + // 该码单下所有未作废的买断入库核算单,联动作废
  556 + List<ProcurementBuyoutAccountOrder> orders = this.list(
  557 + Wrappers.lambdaQuery(ProcurementBuyoutAccountOrder.class)
  558 + .eq(ProcurementBuyoutAccountOrder::getWeighingTicketId, weighingTicketId)
  559 + .eq(ProcurementBuyoutAccountOrder::getDeleted, false));
  560 + if (CollectionUtil.isEmpty(orders)) {
  561 + return;
  562 + }
  563 +
  564 + for (ProcurementBuyoutAccountOrder order : orders) {
  565 + // 审核中的先终止流程,再作废
  566 + if (STATUS_AUDIT.equals(order.getApprovalStatus())) {
  567 + terminateRunningFlow(order.getId());
  568 + }
  569 + this.update(Wrappers.lambdaUpdate(ProcurementBuyoutAccountOrder.class)
  570 + .set(ProcurementBuyoutAccountOrder::getDeleted, true)
  571 + .set(STATUS_AUDIT.equals(order.getApprovalStatus()),
  572 + ProcurementBuyoutAccountOrder::getApprovalStatus, STATUS_REFUSE)
  573 + .eq(ProcurementBuyoutAccountOrder::getId, order.getId()));
  574 + }
  575 + }
  576 +
  577 + @Override
  578 + public boolean existsBySettleDetailId(String settleDetailId) {
  579 + if (StringUtil.isBlank(settleDetailId)) {
  580 + return false;
  581 + }
  582 + return this.count(Wrappers.lambdaQuery(ProcurementBuyoutAccountOrder.class)
  583 + .eq(ProcurementBuyoutAccountOrder::getSettleDetailId, settleDetailId)
  584 + .eq(ProcurementBuyoutAccountOrder::getDeleted, false)
  585 + .ne(ProcurementBuyoutAccountOrder::getApprovalStatus, STATUS_CANCEL)) > 0;
  586 + }
  587 +
  588 + /**
  589 + * 保存明细(数量、单价、金额均由前端计算传入,后端只保存)
  590 + */
  591 + private void saveLines(String orderId, List<BuyoutAccountOrderLineVo> lineVos) {
  592 + if (CollectionUtil.isEmpty(lineVos)) {
  593 + throw new DefaultClientException("明细不能为空!");
  594 + }
  595 + for (BuyoutAccountOrderLineVo lineVo : lineVos) {
  596 + ProcurementBuyoutAccountOrderLine line = new ProcurementBuyoutAccountOrderLine();
  597 + BeanUtil.copyProperties(lineVo, line);
  598 + line.setId(IdUtil.getId());
  599 + line.setOrderId(orderId);
  600 + orderLineService.save(line);
  601 + }
  602 + }
  603 +
  604 + /**
  605 + * 结算详情单可用校验:审核通过、未作废、已生成审核通过的仓库收料单、未生成过买断入库核算单
  606 + * (planCodes/planIds 为联表字段 exist=false,MP 单表查询带不出,必须用 findById)
  607 + */
  608 + private ProcurementMaterialSettleDetail assertSettleUsable(String settleDetailId) {
  609 + if (StringUtil.isBlank(settleDetailId)) {
  610 + throw new DefaultClientException("原料结算详情单不能为空!");
  611 + }
  612 + ProcurementMaterialSettleDetail settle = settleDetailMapper.findById(settleDetailId);
  613 + if (settle == null || Boolean.TRUE.equals(settle.getDeleted())) {
  614 + throw new DefaultClientException("原料结算详情单不存在!");
  615 + }
  616 + if (!STATUS_PASS.equals(settle.getApprovalStatus())) {
  617 + throw new DefaultClientException("仅审核通过的原料结算详情单可生成买断入库核算单!");
  618 + }
  619 + // 前提:该结算详情单下的仓库收料单必须审核通过
  620 + if (!warehouseReceiveOrderPassed(settleDetailId)) {
  621 + throw new DefaultClientException("该原料结算详情单下的仓库收料单未审核通过,不可生成买断入库核算单!");
  622 + }
  623 + if (existsBySettleDetailId(settleDetailId)) {
  624 + throw new DefaultClientException("该原料结算详情单已生成买断入库核算单!");
  625 + }
  626 + return settle;
  627 + }
  628 +
  629 + /**
  630 + * 该结算详情单下的仓库收料单是否审核通过(未作废)
  631 + */
  632 + private boolean warehouseReceiveOrderPassed(String settleDetailId) {
  633 + Integer count = Math.toIntExact(receiveOrderMapper.selectCount(
  634 + Wrappers.lambdaQuery(ProcurementWarehouseReceiveOrder.class)
  635 + .eq(ProcurementWarehouseReceiveOrder::getSettleDetailId, settleDetailId)
  636 + .eq(ProcurementWarehouseReceiveOrder::getDeleted, false)
  637 + .eq(ProcurementWarehouseReceiveOrder::getApprovalStatus, STATUS_PASS)));
  638 + return count != null && count > 0;
  639 + }
  640 +
  641 + /**
  642 + * 计划集合(结算详情单的 planIds 拆分),并校验多个计划的采购处、区域一致性
  643 + */
  644 + private List<ProcurementPlan> listPlans(ProcurementMaterialSettleDetail settle) {
  645 + List<String> planIds = splitIdList(settle.getPlanIds());
  646 + if (CollectionUtil.isEmpty(planIds)) {
  647 + return new ArrayList<>();
  648 + }
  649 + List<ProcurementPlan> plans = procurementPlanService.listByIds(planIds);
  650 + plans.removeIf(Objects::isNull);
  651 + // 多计划一致性:采购处、区域需一致(以第一个为准)
  652 + if (plans.size() > 1) {
  653 + ProcurementPlan first = plans.get(0);
  654 + for (ProcurementPlan plan : plans) {
  655 + if (!Objects.equals(first.getPurchaseDepartment(), plan.getPurchaseDepartment())
  656 + || !Objects.equals(first.getRegion(), plan.getRegion())) {
  657 + throw new DefaultClientException("多个采购计划的采购处、区域不一致,无法生成买断入库核算单!");
  658 + }
  659 + }
  660 + }
  661 + return plans;
  662 + }
  663 +
  664 + /**
  665 + * 批量查询部门名称(采购处/区域)
  666 + */
  667 + private Map<String, String> getDeptNameMap(List<ProcurementPlan> plans) {
  668 + Set<String> deptIds = new HashSet<>();
  669 + for (ProcurementPlan plan : plans) {
  670 + if (StringUtil.isNotBlank(plan.getPurchaseDepartment())) {
  671 + deptIds.add(plan.getPurchaseDepartment());
  672 + }
  673 + if (StringUtil.isNotBlank(plan.getRegion())) {
  674 + deptIds.add(plan.getRegion());
  675 + }
  676 + }
  677 + Map<String, String> nameMap = new HashMap<>();
  678 + if (CollectionUtil.isNotEmpty(deptIds)) {
  679 + for (SysDept dept : sysDeptService.listByIds(deptIds)) {
  680 + if (dept != null) {
  681 + nameMap.put(dept.getId(), dept.getName());
  682 + }
  683 + }
  684 + }
  685 + return nameMap;
  686 + }
  687 +
  688 + /**
  689 + * 收料单明细含税单价:按来源行(结算明细行ID)匹配该结算详情单下仓库收料单的明细行
  690 + */
  691 + private Map<String, BigDecimal> getReceiveTaxPriceMap(String settleDetailId) {
  692 + Map<String, BigDecimal> taxPriceMap = new HashMap<>();
  693 + // 该结算详情单下的仓库收料单(取最新一张)
  694 + List<ProcurementWarehouseReceiveOrder> receiveOrders = receiveOrderMapper.selectList(
  695 + Wrappers.lambdaQuery(ProcurementWarehouseReceiveOrder.class)
  696 + .eq(ProcurementWarehouseReceiveOrder::getSettleDetailId, settleDetailId)
  697 + .eq(ProcurementWarehouseReceiveOrder::getDeleted, false)
  698 + .orderByDesc(ProcurementWarehouseReceiveOrder::getCreateTime));
  699 + if (CollectionUtil.isEmpty(receiveOrders)) {
  700 + return taxPriceMap;
  701 + }
  702 + ProcurementWarehouseReceiveOrder receiveOrder = receiveOrders.get(0);
  703 + List<ProcurementWarehouseReceiveOrderLine> receiveLines = receiveOrderLineMapper.selectList(
  704 + Wrappers.lambdaQuery(ProcurementWarehouseReceiveOrderLine.class)
  705 + .eq(ProcurementWarehouseReceiveOrderLine::getReceiveOrderId, receiveOrder.getId()));
  706 + for (ProcurementWarehouseReceiveOrderLine line : receiveLines) {
  707 + if (line != null && StringUtil.isNotBlank(line.getSettleLineId()) && line.getTaxPrice() != null) {
  708 + taxPriceMap.putIfAbsent(line.getSettleLineId(), line.getTaxPrice());
  709 + }
  710 + }
  711 + return taxPriceMap;
  712 + }
  713 +
  714 + /**
  715 + * 入库数量:申请净重 - 退料 - 折斤(对应关系缺失则为空,有申请净重再计算)
  716 + */
  717 + private BigDecimal calcInstockQuantity(ProcurementMaterialSettleLine settleLine,
  718 + Map<String, BigDecimal> applyQuantityMap) {
  719 + BigDecimal applyQuantity = settleLine.getProductId() == null ? null
  720 + : applyQuantityMap.get(settleLine.getProductId());
  721 + if (applyQuantity == null) {
  722 + return null;
  723 + }
  724 + BigDecimal returnWeight = nvl(settleLine.getReturnWeight());
  725 + BigDecimal foldWeight = nvl(settleLine.getFoldWeight());
  726 + return applyQuantity.subtract(returnWeight).subtract(foldWeight);
  727 + }
  728 +
  729 + /**
  730 + * 预计吨损耗:按计划+品种取买断操作申请表明细的预计损耗(同计划多份申请取最新一份)
  731 + */
  732 + private Map<String, BigDecimal> getExpectLossMap(ProcurementMaterialSettleDetail settle) {
  733 + Map<String, BigDecimal> lossMap = new HashMap<>();
  734 + List<String> planIds = splitIdList(settle.getPlanIds());
  735 + if (CollectionUtil.isEmpty(planIds)) {
  736 + return lossMap;
  737 + }
  738 + // 每个计划取最新一份买断操作申请
  739 + List<ProcurementBuyoutApply> applies = buyoutApplyService.list(
  740 + Wrappers.lambdaQuery(ProcurementBuyoutApply.class)
  741 + .in(ProcurementBuyoutApply::getProcurementPlanId, planIds)
  742 + .orderByDesc(ProcurementBuyoutApply::getCreateTime));
  743 + if (CollectionUtil.isEmpty(applies)) {
  744 + return lossMap;
  745 + }
  746 + Map<String, String> planToApplyMap = new HashMap<>();
  747 + for (ProcurementBuyoutApply apply : applies) {
  748 + planToApplyMap.putIfAbsent(apply.getProcurementPlanId(), apply.getId());
  749 + }
  750 + // 申请明细:申请单ID|品种ID -> 预计损耗
  751 + Map<String, BigDecimal> applyLineLossMap = new HashMap<>();
  752 + List<ProcurementBuyoutApplyLine> applyLines = buyoutApplyLineService.list(
  753 + Wrappers.lambdaQuery(ProcurementBuyoutApplyLine.class)
  754 + .in(ProcurementBuyoutApplyLine::getBuyoutApplyId, planToApplyMap.values()));
  755 + for (ProcurementBuyoutApplyLine line : applyLines) {
  756 + if (line != null && line.getEstimatedLoss() != null) {
  757 + applyLineLossMap.putIfAbsent(line.getBuyoutApplyId() + "|" + line.getProductId(), line.getEstimatedLoss());
  758 + }
  759 + }
  760 + for (Map.Entry<String, String> entry : planToApplyMap.entrySet()) {
  761 + for (Map.Entry<String, BigDecimal> lossEntry : applyLineLossMap.entrySet()) {
  762 + if (lossEntry.getKey().startsWith(entry.getValue() + "|")) {
  763 + lossMap.put(entry.getKey() + "|" + lossEntry.getKey().substring(entry.getValue().length() + 1),
  764 + lossEntry.getValue());
  765 + }
  766 + }
  767 + }
  768 + return lossMap;
  769 + }
  770 +
  771 + /**
  772 + * 按刚审核完成的环节编码(nodeCode 尾部名称缩写,兼容分厂前缀 yfc/efc/sfc/ztfc)推进到下一流程节点;
  773 + * 供应部主管环节通过返回 null(流程结束,flow_node 由终态回调清空)
  774 + */
  775 + private String nextFlowNode(String nodeCode) {
  776 + if (StringUtil.isBlank(nodeCode)) {
  777 + return null;
  778 + }
  779 + if (nodeCode.endsWith("fcckzg")) {
  780 + return NODE_FCZLFG;
  781 + }
  782 + if (nodeCode.endsWith("fczlfg")) {
  783 + return NODE_GYGLKZG;
  784 + }
  785 + if (nodeCode.endsWith("gyglkzg")) {
  786 + return NODE_FCYLKJ;
  787 + }
  788 + if (nodeCode.endsWith("fcylkj")) {
  789 + return NODE_FCCWKZG;
  790 + }
  791 + if (nodeCode.endsWith("fccwkzg")) {
  792 + return NODE_GYBZG;
  793 + }
  794 + if (nodeCode.endsWith("gybzg")) {
  795 + return null;
  796 + }
  797 + return null;
  798 + }
  799 +
  800 + /**
  801 + * 从回调参数解析业务ID(兼容 variables 子 map 包裹)
  802 + */
  803 + private String resolveBizId(Map<String, Object> map) {
  804 + Object id = map.get("id");
  805 + String bizId = id == null ? null : String.valueOf(id);
  806 + if (StringUtil.isBlank(bizId) || "null".equals(bizId)) {
  807 + Object bizIdObj = map.get("bizId");
  808 + bizId = bizIdObj == null ? null : String.valueOf(bizIdObj);
  809 + }
  810 + if (StringUtil.isBlank(bizId) || "null".equals(bizId)) {
  811 + Object variables = map.get("variables");
  812 + if (variables instanceof Map) {
  813 + Map<?, ?> variablesMap = (Map<?, ?>) variables;
  814 + Object vId = variablesMap.get("id");
  815 + if (vId == null) {
  816 + vId = variablesMap.get("bizId");
  817 + }
  818 + bizId = vId == null ? null : String.valueOf(vId);
  819 + }
  820 + }
  821 + return bizId;
  822 + }
  823 +
  824 + /**
  825 + * 终止单据进行中的审核流程(作废审核中的单据前先终止流程)
  826 + */
  827 + private void terminateRunningFlow(String businessId) {
  828 + List<FlowInstanceWrapper> flowList = flowInstanceWrapperService.getFlowByBusinessIdList(
  829 + Collections.singletonList(businessId));
  830 + if (CollectionUtil.isEmpty(flowList)) {
  831 + return;
  832 + }
  833 + flowList.stream()
  834 + .filter(f -> f != null && f.getId() != null)
  835 + .findFirst()
  836 + .ifPresent(flow -> flowTaskWrapperService.termination(flow.getId()));
  837 + }
  838 +
  839 + /**
  840 + * 审核按钮标记:待办驱动(列表 + 详情两条返回路径都要调用)
  841 + */
  842 + private void fillOperateFlags(List<ProcurementBuyoutAccountOrder> datas) {
  843 + if (CollectionUtil.isEmpty(datas)) {
  844 + return;
  845 + }
  846 +
  847 + List<String> businessIds = datas.stream()
  848 + .filter(java.util.Objects::nonNull)
  849 + .map(ProcurementBuyoutAccountOrder::getId)
  850 + .collect(Collectors.toList());
  851 +
  852 + List<FlowInstanceWrapper> flowList = flowInstanceWrapperService.getFlowByBusinessIdList(businessIds);
  853 + Set<String> flowBusinessIdSet = CollectionUtil.isNotEmpty(flowList)
  854 + ? flowList.stream().map(FlowInstanceWrapper::getBusinessId).collect(Collectors.toSet())
  855 + : new HashSet<>();
  856 +
  857 + List<FlowTaskDto> todoFlowTaskList = flowTaskWrapperMapper.queryTodoList(
  858 + new QueryTodoTaskListVo(), SecurityUtil.getCurrentUser().getId());
  859 + Set<String> todoBusinessIdSet = CollectionUtil.isNotEmpty(todoFlowTaskList)
  860 + ? todoFlowTaskList.stream().map(FlowTaskDto::getBusinessId).collect(Collectors.toSet())
  861 + : new HashSet<>();
  862 +
  863 + for (ProcurementBuyoutAccountOrder data : datas) {
  864 + if (data == null) {
  865 + continue;
  866 + }
  867 + boolean hasFlow = flowBusinessIdSet.contains(data.getId());
  868 + boolean hasTodo = todoBusinessIdSet.contains(data.getId());
  869 + data.setShowExamine(hasTodo && STATUS_AUDIT.equals(data.getApprovalStatus()));
  870 + data.setShowExamineDetail(hasFlow && StringUtil.isNotBlank(data.getApprovalStatus()));
  871 + }
  872 + }
  873 +
  874 + /**
  875 + * 作废单校验:作废单只能查看
  876 + */
  877 + private void assertValid(ProcurementBuyoutAccountOrder entity) {
  878 + if (Boolean.TRUE.equals(entity.getDeleted())) {
  879 + throw new DefaultClientException("作废单据只能查看,不允许该操作!");
  880 + }
  881 + }
  882 +
  883 + /**
  884 + * 编辑校验:仅草稿、已驳回可修改
  885 + */
  886 + private void assertEditable(ProcurementBuyoutAccountOrder entity) {
  887 + if (!STATUS_DRAFT.equals(entity.getApprovalStatus()) && !STATUS_REFUSE.equals(entity.getApprovalStatus())) {
  888 + throw new DefaultClientException("当前单据状态不允许修改!");
  889 + }
  890 + }
  891 +
  892 + private BigDecimal nvl(BigDecimal value) {
  893 + return value == null ? BigDecimal.ZERO : value;
  894 + }
  895 +
  896 + /**
  897 + * 计划编号集合展示:plan_codes 拆分(兼容中英文逗号)
  898 + */
  899 + private List<String> splitToList(String planCodes) {
  900 + if (StringUtil.isBlank(planCodes)) {
  901 + return new ArrayList<>();
  902 + }
  903 + List<String> result = new ArrayList<>();
  904 + for (String item : planCodes.split("[,,]")) {
  905 + if (StringUtil.isNotBlank(item)) {
  906 + result.add(item.trim());
  907 + }
  908 + }
  909 + return result;
  910 + }
  911 +
  912 + private List<String> splitIdList(String planIds) {
  913 + if (StringUtil.isBlank(planIds)) {
  914 + return new ArrayList<>();
  915 + }
  916 + List<String> result = new ArrayList<>();
  917 + for (String item : planIds.split("[,,]")) {
  918 + if (StringUtil.isNotBlank(item)) {
  919 + result.add(item.trim());
  920 + }
  921 + }
  922 + return result;
  923 + }
  924 +}
... ...
... ... @@ -694,6 +694,17 @@ public class ProcurementWarehouseReceiveOrderServiceImpl
694 694 .ne(ProcurementWarehouseReceiveOrder::getApprovalStatus, STATUS_CANCEL)) > 0;
695 695 }
696 696
  697 + @Override
  698 + public boolean existsPassedBySettleDetailId(String settleDetailId) {
  699 + if (StringUtil.isBlank(settleDetailId)) {
  700 + return false;
  701 + }
  702 + return this.count(Wrappers.lambdaQuery(ProcurementWarehouseReceiveOrder.class)
  703 + .eq(ProcurementWarehouseReceiveOrder::getSettleDetailId, settleDetailId)
  704 + .eq(ProcurementWarehouseReceiveOrder::getDeleted, false)
  705 + .eq(ProcurementWarehouseReceiveOrder::getApprovalStatus, STATUS_PASS)) > 0;
  706 + }
  707 +
697 708 /**
698 709 * 保存明细(数量、单价、金额均由前端计算传入,后端只保存)
699 710 */
... ...
... ... @@ -41,6 +41,7 @@ import com.lframework.xingyun.sc.procurement.mappers.settle.ProcurementMaterialS
41 41 import com.lframework.xingyun.sc.procurement.mappers.weighing.ProcurementAssayReportMapper;
42 42 import com.lframework.xingyun.sc.procurement.mappers.weighing.ProcurementWeighingTicketMapper;
43 43 import com.lframework.xingyun.sc.procurement.service.plan.ProcurementPlanService;
  44 +import com.lframework.xingyun.sc.procurement.service.buyoutAccount.ProcurementBuyoutAccountOrderService;
44 45 import com.lframework.xingyun.sc.procurement.service.receive.ProcurementWarehouseReceiveOrderService;
45 46 import com.lframework.xingyun.sc.procurement.service.settle.ProcurementMaterialSettleApplyLineService;
46 47 import com.lframework.xingyun.sc.procurement.service.settle.ProcurementMaterialSettleDetailService;
... ... @@ -127,6 +128,9 @@ public class ProcurementMaterialSettleDetailServiceImpl
127 128
128 129 @Resource
129 130 private ProcurementWarehouseReceiveOrderService warehouseReceiveOrderService;
  131 +
  132 + @Resource
  133 + private ProcurementBuyoutAccountOrderService buyoutAccountOrderService;
130 134 @Resource
131 135 private ProcurementWeighingTicketApplyLineService weighApplyLineService;
132 136 @Resource
... ... @@ -404,7 +408,7 @@ public class ProcurementMaterialSettleDetailServiceImpl
404 408 if (!STATUS_PASS.equals(entity.getApprovalStatus())) {
405 409 throw new DefaultClientException("仅审核通过的原料结算详情单可退回!");
406 410 }
407   - // 已生成有效仓库收料单(非已取消、非已作废)的不可以退回;买断入库核算单模块尚未上线,上线后补充校验
  411 + // 已生成有效仓库收料单(非已取消、非已作废)或有效买断入库核算单的不可以退回
408 412 assertNotReferenced(id);
409 413
410 414 this.update(Wrappers.lambdaUpdate(ProcurementMaterialSettleDetail.class)
... ... @@ -548,6 +552,9 @@ public class ProcurementMaterialSettleDetailServiceImpl
548 552 }
549 553 // 联动作废该结算详情单生成的仓库收料单(审核中的先终止流程再作废)
550 554 warehouseReceiveOrderService.deleteBySettleDetailId(detail.getId());
  555 +
  556 + // 联动作废该结算详情单生成的买断入库核算单(审核中的先终止流程再作废)
  557 + buyoutAccountOrderService.deleteBySettleDetailId(detail.getId());
551 558 this.update(Wrappers.lambdaUpdate(ProcurementMaterialSettleDetail.class)
552 559 .set(ProcurementMaterialSettleDetail::getDeleted, true)
553 560 .set(STATUS_AUDIT.equals(detail.getApprovalStatus()),
... ... @@ -703,6 +710,10 @@ public class ProcurementMaterialSettleDetailServiceImpl
703 710 if (warehouseReceiveOrderService.existsBySettleDetailId(settleDetailId)) {
704 711 throw new DefaultClientException("已生成仓库收料单,不可以退回!");
705 712 }
  713 + // 已生成有效买断入库核算单的不可以退回
  714 + if (buyoutAccountOrderService.existsBySettleDetailId(settleDetailId)) {
  715 + throw new DefaultClientException("已生成买断入库核算单,不可以退回!");
  716 + }
706 717 }
707 718
708 719 /**
... ...
... ... @@ -40,6 +40,7 @@ import com.lframework.xingyun.sc.procurement.service.plan.ProcurementPlanLineSer
40 40 import com.lframework.xingyun.sc.procurement.service.plan.ProcurementPlanService;
41 41 import com.lframework.xingyun.sc.procurement.service.settle.ProcurementMaterialSettleDetailService;
42 42 import com.lframework.xingyun.sc.procurement.service.receive.ProcurementWarehouseReceiveOrderService;
  43 +import com.lframework.xingyun.sc.procurement.service.buyoutAccount.ProcurementBuyoutAccountOrderService;
43 44 import com.lframework.xingyun.sc.procurement.service.weighing.ProcurementAssayApplyService;
44 45 import com.lframework.xingyun.sc.procurement.service.weighing.ProcurementAssayReportService;
45 46 import com.lframework.xingyun.sc.procurement.service.weighing.ProcurementWeighingTicketApplyLineService;
... ... @@ -123,6 +124,8 @@ public class ProcurementWeighingTicketServiceImpl
123 124 private ProcurementMaterialSettleDetailService materialSettleDetailService;
124 125 @Resource
125 126 private ProcurementWarehouseReceiveOrderService warehouseReceiveOrderService;
  127 + @Resource
  128 + private ProcurementBuyoutAccountOrderService buyoutAccountOrderService;
126 129
127 130 @Override
128 131 public PageResult<ProcurementWeighingTicket> query(Integer pageIndex, Integer pageSize,
... ... @@ -576,6 +579,9 @@ public class ProcurementWeighingTicketServiceImpl
576 579 // 联动作废该码单关联的仓库收料单(审核中的先终止流程再作废)
577 580 warehouseReceiveOrderService.deleteByWeighingTicketId(id);
578 581
  582 + // 联动作废该码单关联的买断入库核算单(审核中的先终止流程再作废)
  583 + buyoutAccountOrderService.deleteByWeighingTicketId(id);
  584 +
579 585 OpLogUtil.setVariable("id", id);
580 586 OpLogUtil.setExtra(entity);
581 587 }
... ...
  1 +package com.lframework.xingyun.sc.procurement.mappers.buyoutAccount;
  2 +
  3 +import com.lframework.starter.web.core.mapper.BaseMapper;
  4 +import com.lframework.xingyun.sc.procurement.entity.buyoutAccount.ProcurementBuyoutAccountOrderLine;
  5 +
  6 +public interface ProcurementBuyoutAccountOrderLineMapper
  7 + extends BaseMapper<ProcurementBuyoutAccountOrderLine> {
  8 +
  9 +}
... ...
  1 +package com.lframework.xingyun.sc.procurement.mappers.buyoutAccount;
  2 +
  3 +import com.lframework.starter.web.core.annotations.permission.DataPermission;
  4 +import com.lframework.starter.web.core.annotations.permission.DataPermissions;
  5 +import com.lframework.starter.web.core.mapper.BaseMapper;
  6 +import com.lframework.starter.web.inner.components.permission.OrderDataPermissionDataPermissionType;
  7 +import com.lframework.xingyun.sc.procurement.entity.buyoutAccount.ProcurementBuyoutAccountOrder;
  8 +import com.lframework.xingyun.sc.procurement.vo.buyoutAccount.QueryBuyoutAccountOrderVo;
  9 +import java.util.List;
  10 +import org.apache.ibatis.annotations.Param;
  11 +
  12 +public interface ProcurementBuyoutAccountOrderMapper
  13 + extends BaseMapper<ProcurementBuyoutAccountOrder> {
  14 +
  15 + /**
  16 + * 分页查询买断入库核算单
  17 + */
  18 + @DataPermissions(type = OrderDataPermissionDataPermissionType.class, value = {
  19 + @DataPermission(template = "order", alias = "tb")
  20 + })
  21 + List<ProcurementBuyoutAccountOrder> query(@Param("vo") QueryBuyoutAccountOrderVo vo);
  22 +
  23 + /**
  24 + * 单条查询(联表带出分厂编号 workshopCode;实体传给流程引擎/分厂审核节点路由前必须用此方法)
  25 + */
  26 + ProcurementBuyoutAccountOrder findById(@Param("id") String id);
  27 +}
... ...
  1 +package com.lframework.xingyun.sc.procurement.service.buyoutAccount;
  2 +
  3 +import com.lframework.starter.web.core.service.BaseMpService;
  4 +import com.lframework.xingyun.sc.procurement.entity.buyoutAccount.ProcurementBuyoutAccountOrderLine;
  5 +import java.util.List;
  6 +
  7 +public interface ProcurementBuyoutAccountOrderLineService
  8 + extends BaseMpService<ProcurementBuyoutAccountOrderLine> {
  9 +
  10 + /**
  11 + * 按买断入库核算单ID查询明细(按排序号排序)
  12 + */
  13 + List<ProcurementBuyoutAccountOrderLine> getByOrderId(String orderId);
  14 +
  15 + /**
  16 + * 按买断入库核算单ID删除明细
  17 + */
  18 + void deleteByOrderId(String orderId);
  19 +}
... ...
  1 +package com.lframework.xingyun.sc.procurement.service.buyoutAccount;
  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.GetBuyoutAccountOrderBo;
  6 +import com.lframework.xingyun.sc.bo.procurement.GetBuyoutSettleDataBo;
  7 +import com.lframework.xingyun.sc.procurement.entity.buyoutAccount.ProcurementBuyoutAccountOrder;
  8 +import com.lframework.xingyun.sc.procurement.vo.buyoutAccount.CreateBuyoutAccountOrderVo;
  9 +import com.lframework.xingyun.sc.procurement.vo.buyoutAccount.QueryBuyoutAccountOrderVo;
  10 +import com.lframework.xingyun.sc.procurement.vo.buyoutAccount.UpdateBuyoutAccountOrderVo;
  11 +
  12 +import java.util.List;
  13 +import java.util.Map;
  14 +
  15 +public interface ProcurementBuyoutAccountOrderService
  16 + extends BaseMpService<ProcurementBuyoutAccountOrder> {
  17 +
  18 + /**
  19 + * 分页查询买断入库核算单(列表)
  20 + */
  21 + PageResult<ProcurementBuyoutAccountOrder> query(Integer pageIndex, Integer pageSize,
  22 + QueryBuyoutAccountOrderVo vo);
  23 +
  24 + /**
  25 + * 详情(主表 + 明细)
  26 + */
  27 + GetBuyoutAccountOrderBo findDetail(String id);
  28 +
  29 + /**
  30 + * 可制单的原料结算详情单下拉(审核通过 + 未作废 + 已生成审核通过的仓库收料单 + 未生成过买断入库核算单)
  31 + */
  32 + List<GetBuyoutSettleDataBo> getSettleOptions();
  33 +
  34 + /**
  35 + * 新增页:按原料结算详情单带出数据(分厂仓库统计员制单)
  36 + */
  37 + GetBuyoutSettleDataBo getSettleData(String settleDetailId);
  38 +
  39 + /**
  40 + * 新增买断入库核算单(草稿)
  41 + */
  42 + String create(CreateBuyoutAccountOrderVo vo);
  43 +
  44 + /**
  45 + * 修改买断入库核算单(仅草稿、已驳回可修改)
  46 + */
  47 + void update(UpdateBuyoutAccountOrderVo vo);
  48 +
  49 + /**
  50 + * 提交买断入库核算单审核(草稿、已驳回可提交)
  51 + */
  52 + void submit(String id);
  53 +
  54 + /**
  55 + * 取消买断入库核算单(草稿、已驳回状态可取消)
  56 + */
  57 + void cancel(String id);
  58 +
  59 + /**
  60 + * 审核流程回调更新审核状态(流程结束时由 BusinessDataHandlerService 调用)
  61 + */
  62 + void updateApprovalStatus(String id, String approvalStatus);
  63 +
  64 + /**
  65 + * 审核过程回调:更新流程节点(nodeCode 尾部环节缩写兼容分厂前缀,拒绝/撤销/终止统一回制单节点)
  66 + */
  67 + void updateNoFlowInstance(Map<String, Object> map);
  68 +
  69 + /**
  70 + * 按原料结算详情单作废买断入库核算单(结算详情单/收料单作废联动,审核中的先终止流程)
  71 + */
  72 + void deleteBySettleDetailId(String settleDetailId);
  73 +
  74 + /**
  75 + * 按过磅码单作废买断入库核算单(码单作废联动,审核中的先终止流程)
  76 + */
  77 + void deleteByWeighingTicketId(String weighingTicketId);
  78 +
  79 + /**
  80 + * 是否存在有效买断入库核算单(非已取消、非已作废;可制单校验用)
  81 + */
  82 + boolean existsBySettleDetailId(String settleDetailId);
  83 +}
... ...
... ... @@ -87,4 +87,9 @@ public interface ProcurementWarehouseReceiveOrderService
87 87 * 是否存在有效仓库收料单(非已取消、非已作废;结算详情单退回校验/可制单校验用)
88 88 */
89 89 boolean existsBySettleDetailId(String settleDetailId);
  90 +
  91 + /**
  92 + * 是否存在审核通过的仓库收料单(未作废;买断入库核算单可制单校验用)
  93 + */
  94 + boolean existsPassedBySettleDetailId(String settleDetailId);
90 95 }
... ...
  1 +package com.lframework.xingyun.sc.procurement.vo.buyoutAccount;
  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 BuyoutAccountOrderLineVo 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 buyoutCategory;
  31 +
  32 + @ApiModelProperty("买断数量 kg(原料结算详情单过磅数)")
  33 + private BigDecimal buyoutQuantity;
  34 +
  35 + @ApiModelProperty("买断单价 元/kg(仓库收料单含税单价)")
  36 + private BigDecimal buyoutPrice;
  37 +
  38 + @ApiModelProperty("买断金额 = 买断单价*买断数量(前端计算传入)")
  39 + private BigDecimal buyoutAmount;
  40 +
  41 + @ApiModelProperty("入库数量 kg(申请净重-退料-折斤,可修改)")
  42 + private BigDecimal instockQuantity;
  43 +
  44 + @ApiModelProperty("入库单价 元/kg(可修改)")
  45 + private BigDecimal instockPrice;
  46 +
  47 + @ApiModelProperty("入库金额 元(可修改)")
  48 + private BigDecimal instockAmount;
  49 +
  50 + @ApiModelProperty("预计吨损耗 元/吨(按计划取买断操作申请表)")
  51 + private BigDecimal expectTonLoss;
  52 +
  53 + @ApiModelProperty("实际吨损耗 元/吨(可修改)")
  54 + private BigDecimal actualTonLoss;
  55 +
  56 + @ApiModelProperty("吨损耗差异 元/吨 = 预计-实际(前端计算传入)")
  57 + private BigDecimal tonLossDiff;
  58 +
  59 + @ApiModelProperty("差异金额 元 = 入库数量*吨损耗差异/1000(前端计算传入)")
  60 + private BigDecimal diffAmount;
  61 +}
... ...
  1 +package com.lframework.xingyun.sc.procurement.vo.buyoutAccount;
  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 +@Data
  14 +public class CreateBuyoutAccountOrderVo implements Serializable {
  15 +
  16 + private static final long serialVersionUID = 1L;
  17 +
  18 + @NotBlank(message = "原料结算详情单不能为空!")
  19 + @ApiModelProperty("原料结算详情单ID(来源单)")
  20 + private String settleDetailId;
  21 +
  22 + @ApiModelProperty("合计-买断数量 kg(前端计算传入)")
  23 + private BigDecimal totalBuyoutQuantity;
  24 +
  25 + @ApiModelProperty("合计-买断金额(前端计算传入)")
  26 + private BigDecimal totalBuyoutAmount;
  27 +
  28 + @ApiModelProperty("合计-入库数量 kg(前端计算传入)")
  29 + private BigDecimal totalInstockQuantity;
  30 +
  31 + @ApiModelProperty("合计-入库金额(前端计算传入)")
  32 + private BigDecimal totalInstockAmount;
  33 +
  34 + @ApiModelProperty("合计-差异金额 元(前端计算传入)")
  35 + private BigDecimal totalDiffAmount;
  36 +
  37 + @NotEmpty(message = "明细不能为空!")
  38 + @Valid
  39 + @ApiModelProperty("明细数据")
  40 + private List<BuyoutAccountOrderLineVo> lines;
  41 +}
... ...
  1 +package com.lframework.xingyun.sc.procurement.vo.buyoutAccount;
  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("查询买断入库核算单Vo")
  15 +public class QueryBuyoutAccountOrderVo 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 createTimeStart;
  28 +
  29 + @ApiModelProperty("创建时间-结束")
  30 + @JsonFormat(pattern = StringPool.DATE_PATTERN)
  31 + private LocalDate createTimeEnd;
  32 +
  33 + @ApiModelProperty("客户名称/来料单位(模糊匹配)")
  34 + private String incomingUnit;
  35 +
  36 + @ApiModelProperty("分厂ID")
  37 + private String workshopId;
  38 +
  39 + @ApiModelProperty("流程节点 FCCKTJY/FCCKZG/FCZLFG/GYGLKZG/FCYLKJ/FCCWKZG/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.buyoutAccount;
  2 +
  3 +import io.swagger.annotations.ApiModelProperty;
  4 +import lombok.Data;
  5 +import lombok.EqualsAndHashCode;
  6 +
  7 +@Data
  8 +@EqualsAndHashCode(callSuper = true)
  9 +public class UpdateBuyoutAccountOrderVo extends CreateBuyoutAccountOrderVo {
  10 +
  11 + private static final long serialVersionUID = 1L;
  12 +
  13 + @ApiModelProperty("买断入库核算单ID")
  14 + private String id;
  15 +}
... ...
  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.buyoutAccount.ProcurementBuyoutAccountOrderMapper">
  6 +
  7 + <resultMap id="ProcurementBuyoutAccountOrderResult"
  8 + type="com.lframework.xingyun.sc.procurement.entity.buyoutAccount.ProcurementBuyoutAccountOrder">
  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="incoming_unit" property="incomingUnit"/>
  14 + <result column="plan_codes" property="planCodes"/>
  15 + <result column="plan_ids" property="planIds"/>
  16 + <result column="purchase_department_id" property="purchaseDepartmentId"/>
  17 + <result column="purchase_department_name" property="purchaseDepartmentName"/>
  18 + <result column="region_id" property="regionId"/>
  19 + <result column="region_name" property="regionName"/>
  20 + <result column="workshop_id" property="workshopId"/>
  21 + <result column="workshop_name" property="workshopName"/>
  22 + <result column="workshop_code" property="workshopCode"/>
  23 + <result column="total_buyout_quantity" property="totalBuyoutQuantity"/>
  24 + <result column="total_buyout_amount" property="totalBuyoutAmount"/>
  25 + <result column="total_instock_quantity" property="totalInstockQuantity"/>
  26 + <result column="total_instock_amount" property="totalInstockAmount"/>
  27 + <result column="total_diff_amount" property="totalDiffAmount"/>
  28 + <result column="flow_node" property="flowNode"/>
  29 + <result column="approval_status" property="approvalStatus"/>
  30 + <result column="fccktjy_id" property="fccktjyId"/>
  31 + <result column="fccktjy_name" property="fccktjyName"/>
  32 + <result column="fcckzg_id" property="fcckzgId"/>
  33 + <result column="fcckzg_name" property="fcckzgName"/>
  34 + <result column="fczlfg_id" property="fczlfgId"/>
  35 + <result column="fczlfg_name" property="fczlfgName"/>
  36 + <result column="gyglkzg_id" property="gyglkzgId"/>
  37 + <result column="gyglkzg_name" property="gyglkzgName"/>
  38 + <result column="fcylkj_id" property="fcylkjId"/>
  39 + <result column="fcylkj_name" property="fcylkjName"/>
  40 + <result column="fccwkzg_id" property="fccwkzgId"/>
  41 + <result column="fccwkzg_name" property="fccwkzgName"/>
  42 + <result column="gybzg_id" property="gybzgId"/>
  43 + <result column="gybzg_name" property="gybzgName"/>
  44 + <result column="deleted" property="deleted"/>
  45 + <result column="create_by_id" property="createById"/>
  46 + <result column="create_by" property="createBy"/>
  47 + <result column="update_by_id" property="updateById"/>
  48 + <result column="update_by" property="updateBy"/>
  49 + <result column="create_time" property="createTime"/>
  50 + <result column="update_time" property="updateTime"/>
  51 + </resultMap>
  52 +
  53 + <sql id="PBAO_sql">
  54 + SELECT
  55 + tb.id,
  56 + tb.settle_detail_id,
  57 + tb.weighing_ticket_id,
  58 + tb.weighing_ticket_code,
  59 + tb.incoming_unit,
  60 + tb.plan_codes,
  61 + tb.plan_ids,
  62 + tb.purchase_department_id,
  63 + tb.purchase_department_name,
  64 + tb.region_id,
  65 + tb.region_name,
  66 + tb.workshop_id,
  67 + tb.workshop_name,
  68 + ws.code AS workshop_code,
  69 + tb.total_buyout_quantity,
  70 + tb.total_buyout_amount,
  71 + tb.total_instock_quantity,
  72 + tb.total_instock_amount,
  73 + tb.total_diff_amount,
  74 + tb.flow_node,
  75 + tb.approval_status,
  76 + tb.fccktjy_id,
  77 + tb.fccktjy_name,
  78 + tb.fcckzg_id,
  79 + tb.fcckzg_name,
  80 + tb.fczlfg_id,
  81 + tb.fczlfg_name,
  82 + tb.gyglkzg_id,
  83 + tb.gyglkzg_name,
  84 + tb.fcylkj_id,
  85 + tb.fcylkj_name,
  86 + tb.fccwkzg_id,
  87 + tb.fccwkzg_name,
  88 + tb.gybzg_id,
  89 + tb.gybzg_name,
  90 + tb.deleted,
  91 + tb.create_by_id,
  92 + tb.create_by,
  93 + tb.update_by_id,
  94 + tb.update_by,
  95 + tb.create_time,
  96 + tb.update_time
  97 + FROM procurement_buyout_account_order AS tb
  98 + LEFT JOIN base_data_workshop ws ON ws.id = tb.workshop_id
  99 + </sql>
  100 +
  101 + <select id="query" resultMap="ProcurementBuyoutAccountOrderResult">
  102 + <include refid="PBAO_sql"/>
  103 + <where>
  104 + <choose>
  105 + <when test="vo.deleted != null">
  106 + tb.deleted = #{vo.deleted}
  107 + </when>
  108 + <otherwise>
  109 + tb.deleted = 0
  110 + </otherwise>
  111 + </choose>
  112 + <if test="vo.weighingTicketCode != null and vo.weighingTicketCode != ''">
  113 + AND tb.weighing_ticket_code LIKE CONCAT('%', #{vo.weighingTicketCode}, '%')
  114 + </if>
  115 + <if test="vo.planCode != null and vo.planCode != ''">
  116 + AND tb.plan_codes LIKE CONCAT('%', #{vo.planCode}, '%')
  117 + </if>
  118 + <!-- 创建时间筛选(结束日期覆盖全天) -->
  119 + <if test="vo.createTimeStart != null">
  120 + AND tb.create_time &gt;= #{vo.createTimeStart}
  121 + </if>
  122 + <if test="vo.createTimeEnd != null">
  123 + AND tb.create_time &lt; DATE_ADD(#{vo.createTimeEnd}, INTERVAL 1 DAY)
  124 + </if>
  125 + <if test="vo.incomingUnit != null and vo.incomingUnit != ''">
  126 + AND tb.incoming_unit LIKE CONCAT('%', #{vo.incomingUnit}, '%')
  127 + </if>
  128 + <if test="vo.workshopId != null and vo.workshopId != ''">
  129 + AND tb.workshop_id = #{vo.workshopId}
  130 + </if>
  131 + <if test="vo.flowNode != null and vo.flowNode != ''">
  132 + AND tb.flow_node = #{vo.flowNode}
  133 + </if>
  134 + <if test="vo.approvalStatus != null and vo.approvalStatus != ''">
  135 + AND tb.approval_status = #{vo.approvalStatus}
  136 + </if>
  137 + </where>
  138 + ORDER BY tb.create_time DESC
  139 + </select>
  140 +
  141 + <!-- 单条查询(联表带出分厂编号;分厂审核节点编码 = BUYOUT_ACCOUNT_ORDER_ + 分厂前缀 + 环节缩写,实体传给流程引擎前必须带出) -->
  142 + <select id="findById" resultMap="ProcurementBuyoutAccountOrderResult">
  143 + <include refid="PBAO_sql"/>
  144 + WHERE tb.id = #{id}
  145 + </select>
  146 +</mapper>
... ...