Browse Source

增加对销售合同产品明细明细ExceL表的导入校验

胡北宽 2 months ago
parent
commit
150e72fc03

+ 41
- 0
src/main/java/com/example/backend/entity/common/CustCtrl.java View File

@@ -408,6 +408,47 @@ public class CustCtrl {
408 408
     @TableField(exist = false)
409 409
     private String countryName;
410 410
 
411
+    //商品编号
412
+    @TableField(exist = false)
413
+    private String itemno;
414
+
415
+    //中文品名
416
+    @TableField(exist = false)
417
+    private String sdesc;
418
+
419
+    //英文品名
420
+    @TableField(exist = false)
421
+    private String edesc;
422
+
423
+    //单位
424
+    @TableField(exist = false)
425
+    private String ut;
426
+
427
+    //海关编码
428
+    @TableField(exist = false)
429
+    private String hsCode;
430
+
431
+    //海关中文名称
432
+    @TableField(exist = false)
433
+    private String hsNameCn;
434
+
435
+    //海关英文名称
436
+    @TableField(exist = false)
437
+    private String hsNameEn;
438
+
439
+    //增值税率
440
+    @TableField(exist = false)
441
+    private BigDecimal inTaxRate;
442
+
443
+    //退税率
444
+    @TableField(exist = false)
445
+    private BigDecimal reTaxRate;
446
+
447
+    //对人民币税率
448
+    @TableField(exist = false)
449
+    private BigDecimal rate;
450
+
451
+
411 452
 
412 453
 
413 454
 

+ 12
- 12
src/main/java/com/example/backend/excel/SalesDtlExcelDTO.java View File

@@ -33,10 +33,10 @@ public class SalesDtlExcelDTO {
33 33
     @ExcelProperty("规格描述")
34 34
     private String spec;
35 35
 
36
-    @ExcelProperty("水分")
36
+    @ExcelProperty("水分%")
37 37
     private BigDecimal moisture;
38 38
 
39
-    @ExcelProperty("含铁量")
39
+    @ExcelProperty("含铁量%")
40 40
     private BigDecimal ironCont;
41 41
 
42 42
     @ExcelProperty("湿吨数量")
@@ -51,7 +51,7 @@ public class SalesDtlExcelDTO {
51 51
     @ExcelProperty("数量")
52 52
     private BigDecimal qty;
53 53
 
54
-    @ExcelProperty("含税单价")
54
+    @ExcelProperty("销售单价")
55 55
     private BigDecimal soPrice;
56 56
 
57 57
     @ExcelProperty("不含税单价")
@@ -90,7 +90,7 @@ public class SalesDtlExcelDTO {
90 90
     @ExcelProperty("进项税率%")
91 91
     private BigDecimal inTaxRate;
92 92
 
93
-    @ExcelProperty("退税率%")
93
+    @ExcelProperty("退税率 %")
94 94
     private BigDecimal reTaxRate;
95 95
 
96 96
     @ExcelProperty("销项税率%")
@@ -102,7 +102,7 @@ public class SalesDtlExcelDTO {
102 102
     @ExcelProperty("流程实例id")
103 103
     private String processInstanceId;
104 104
 
105
-    @ExcelProperty("单据号")
105
+    @ExcelProperty("销售合同号")
106 106
     private String fno;
107 107
 
108 108
     @ExcelProperty("单据日期")
@@ -165,7 +165,7 @@ public class SalesDtlExcelDTO {
165 165
     @ExcelProperty("合同批次号")
166 166
     private String batchNo;
167 167
 
168
-    @ExcelProperty("销售合同号")
168
+    @ExcelProperty("合同号")
169 169
     private String sono;
170 170
 
171 171
     @ExcelProperty("供应商代码")
@@ -201,10 +201,10 @@ public class SalesDtlExcelDTO {
201 201
     @ExcelProperty("客户名称")
202 202
     private String ctName;
203 203
 
204
-    @ExcelProperty("币种采购")
204
+    @ExcelProperty("采购币种")
205 205
     private String curcyPo;
206 206
 
207
-    @ExcelProperty("汇率采购")
207
+    @ExcelProperty("采购汇率")
208 208
     private BigDecimal ratePo;
209 209
 
210 210
     @ExcelProperty("业务账套")
@@ -303,7 +303,7 @@ public class SalesDtlExcelDTO {
303 303
     @ExcelProperty("H型钢规格")
304 304
     private String ftype2;
305 305
 
306
-    @ExcelProperty("规格")
306
+    @ExcelProperty("规格描述")
307 307
     private String ftype3;
308 308
 
309 309
     @ExcelProperty("计重方式")
@@ -312,7 +312,7 @@ public class SalesDtlExcelDTO {
312 312
     @ExcelProperty("色标")
313 313
     private String ftype5;
314 314
 
315
-    @ExcelProperty("数值预留字段1")
315
+    @ExcelProperty("数")
316 316
     private BigDecimal fnum8;
317 317
 
318 318
     @ExcelProperty("数值预留字段2")
@@ -321,10 +321,10 @@ public class SalesDtlExcelDTO {
321 321
     @ExcelProperty("文本预留字段1")
322 322
     private String ftype6;
323 323
 
324
-    @ExcelProperty("文本预留字段2")
324
+    @ExcelProperty("螺纹规格库")
325 325
     private String ftype7;
326 326
 
327
-    @ExcelProperty("煤焦标准水分")
327
+    @ExcelProperty("煤焦计价水%")
328 328
     private BigDecimal coalMoisture;
329 329
 
330 330
     @ExcelProperty("钢厂资源号")

+ 3
- 1
src/main/java/com/example/backend/mapper/contract/CustCtrlMapper.java View File

@@ -2,7 +2,6 @@ package com.example.backend.mapper.contract;
2 2
 
3 3
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4 4
 import com.example.backend.entity.common.CustCtrl;
5
-import com.example.backend.entity.common.DataDic;
6 5
 import org.apache.ibatis.annotations.Mapper;
7 6
 import org.apache.ibatis.annotations.Param;
8 7
 
@@ -28,8 +27,11 @@ public interface CustCtrlMapper extends BaseMapper<CustCtrl> {
28 27
     List<CustCtrl> selectCommContrNo(@Param("commContrNo") String commContrNo);
29 28
 
30 29
 
30
+    List<CustCtrl> selectByItemno(@Param("itemno") String itemno, @Param("bizProductType") String bizProductType);
31 31
 
32
+    List<CustCtrl> selectByCurcyPo(@Param("curcyPo") String curcyPo);
32 33
 
34
+    List<CustCtrl> selectByResourceNo(@Param("resourceNo") String resourceNo, @Param("bizProductType") String bizProductType);
33 35
 
34 36
 
35 37
 }

+ 1
- 5
src/main/java/com/example/backend/mapper/contract/DicMapper.java View File

@@ -28,10 +28,6 @@ public interface DicMapper extends BaseMapper<DataDic> {
28 28
     List<DataDic> selectBySettIndex(@Param("settIndex") String settIndex);
29 29
 
30 30
 
31
-
32
-
33
-
34
-
35
-
31
+    List<DataDic> selectByPriceMtd(@Param("priceMtd") String priceMtd);
36 32
 
37 33
 }

+ 144
- 11
src/main/java/com/example/backend/service/contract/impl/SalesContractServiceImpl.java View File

@@ -54,7 +54,9 @@ public class SalesContractServiceImpl implements SalesContractService {
54 54
 
55 55
         List<String> errors = new ArrayList<>();  // 用来记录所有错误
56 56
 
57
-        Long contractId = null;
57
+        Long Id = null;
58
+        String bizProductType = null;
59
+        String bizType = null;
58 60
 
59 61
         try {
60 62
             // ================= 主表 =================
@@ -95,7 +97,9 @@ public class SalesContractServiceImpl implements SalesContractService {
95 97
                     if (bizProdictTypeList == null || bizProdictTypeList.isEmpty()) {
96 98
                         errors.add("输入的合同产品类型在数据字典中不存在!");
97 99
                     }
98
-
100
+                    if (bizProdictTypeList != null && !bizProdictTypeList.get(0).getItemValue().isEmpty()) {
101
+                        bizProductType = bizProdictTypeList.get(0).getItemValue();
102
+                    }
99 103
                     if (StringUtils.isEmpty(entity.getBizType())) {
100 104
                         errors.add("合同类型不能为空!");
101 105
                     }
@@ -294,27 +298,27 @@ public class SalesContractServiceImpl implements SalesContractService {
294 298
                     if ("代理-主业进口".equals(entity.getServiceType())) {
295 299
                         if (!StringUtils.isEmpty(entity.getAgentNo())) {
296 300
                             List<CustCtrl> agentNoList = custCtrlMapper.selectByAgentNo(entity.getAgentNo());
297
-                            if(agentNoList==null||agentNoList.isEmpty()){
301
+                            if (agentNoList == null || agentNoList.isEmpty()) {
298 302
                                 errors.add("代理采购协议号有误!");
299 303
                             }
300 304
                         }
301 305
 
302 306
                     }
303 307
 
304
-                    if ("代理-主业进口".equals(entity.getServiceType())||"其他/混合分型".equals(entity.getServiceType())) {
308
+                    if ("代理-主业进口".equals(entity.getServiceType()) || "其他/混合分型".equals(entity.getServiceType())) {
305 309
                         if (!StringUtils.isEmpty(entity.getAgentNo())) {
306 310
                             List<CustCtrl> agentNoSoList = custCtrlMapper.selectByAgentNoSo(entity.getAgentNoSo());
307
-                            if(agentNoSoList==null||agentNoSoList.isEmpty()){
311
+                            if (agentNoSoList == null || agentNoSoList.isEmpty()) {
308 312
                                 errors.add("代理销售协议号 有误!");
309 313
                             }
310 314
                         }
311 315
 
312 316
                     }
313 317
 
314
-                    if ("钢产品".equals(entity.getBizProductType())||"设备备件".equals(entity.getBizProductType())) {
318
+                    if ("钢产品".equals(entity.getBizProductType()) || "设备备件".equals(entity.getBizProductType())) {
315 319
                         if (!StringUtils.isEmpty(entity.getCommContrNo())) {
316 320
                             List<CustCtrl> commContrNoSoList = custCtrlMapper.selectCommContrNo(entity.getCommContrNo());
317
-                            if(commContrNoSoList==null||commContrNoSoList.isEmpty()){
321
+                            if (commContrNoSoList == null || commContrNoSoList.isEmpty()) {
318 322
                                 errors.add("佣金合同号 有误!");
319 323
                             }
320 324
                         }
@@ -324,7 +328,7 @@ public class SalesContractServiceImpl implements SalesContractService {
324 328
                     if ("铁矿石".equals(entity.getBizProductType())) {
325 329
                         if (!StringUtils.isEmpty(entity.getSettIndex())) {
326 330
                             List<DataDic> settIndexList = dicMapper.selectBySettIndex(entity.getSettIndex());
327
-                            if(settIndexList==null||settIndexList.isEmpty()){
331
+                            if (settIndexList == null || settIndexList.isEmpty()) {
328 332
                                 errors.add("结算指标在数据字典中不存在!");
329 333
                             }
330 334
                         }
@@ -333,8 +337,8 @@ public class SalesContractServiceImpl implements SalesContractService {
333 337
 
334 338
 
335 339
                     salesContractMapper.insert(entity);
336
-                    contractId = entity.getId();
337
-                    if (contractId == null) {
340
+                    Id = entity.getId();
341
+                    if (Id == null) {
338 342
                         errors.add("主表ID生成失败(contractId 为 null)!");
339 343
                     }
340 344
                 }
@@ -344,7 +348,7 @@ public class SalesContractServiceImpl implements SalesContractService {
344 348
 
345 349
 
346 350
             // 如果主表ID 都没生成,后面也插不了,但不能中断,要继续执行
347
-            final Long cid = contractId;
351
+            final Long cid = Id;
348 352
 
349 353
 
350 354
             // =================  产品明细 =================
@@ -354,6 +358,135 @@ public class SalesContractServiceImpl implements SalesContractService {
354 358
                     SalesDtlExcelDTO dto = list.size() >= 3 ? list.get(2) : list.get(0);
355 359
                     SalesDtlEntity entity = new SalesDtlEntity();
356 360
                     BeanUtils.copyProperties(dto, entity);
361
+                    //销售合同产品明细校验
362
+                    if (StringUtils.isEmpty(entity.getFno())) {
363
+                        errors.add("销售合同号不能为空! ");
364
+                    }
365
+                    if (StringUtils.isEmpty(entity.getItemno())) {
366
+                        errors.add("商品编号不能为空!");
367
+                    }
368
+                    if (Objects.isNull(entity.getInTaxRate())) {
369
+                        errors.add("增值税率不能为空");
370
+
371
+                    }
372
+                    if (StringUtils.isEmpty(entity.getUt())) {
373
+                        errors.add("单位不能为空");
374
+                    }
375
+                    if (StringUtils.isEmpty(entity.getSdesc())) {
376
+                        errors.add("中文品名不能为空");
377
+                    }
378
+
379
+
380
+                    List<CustCtrl> itemnoList = custCtrlMapper.selectByItemno(entity.getItemno(), bizProductType);
381
+                    if (itemnoList == null || itemnoList.isEmpty()) {
382
+                        errors.add("商品编号有误!");
383
+                    }
384
+
385
+                    if (itemnoList != null && Objects.isNull(itemnoList.get(0).getInTaxRate())) {
386
+                        errors.add("匹配到的增值税率为空!");
387
+                    }
388
+
389
+                    if (itemnoList != null && !Objects.isNull(itemnoList.get(0).getInTaxRate())) {
390
+                        if (!Objects.equals(entity.getInTaxRate(), itemnoList.get(0).getInTaxRate())) {
391
+                            errors.add("输入的增值税率与匹配增值税率不一致!");
392
+                        }
393
+                    }
394
+
395
+                    if (itemnoList != null && !Objects.isNull(itemnoList.get(0).getReTaxRate())) {
396
+                        entity.setReTaxRate(itemnoList.get(0).getReTaxRate());
397
+                    }
398
+
399
+                    if (itemnoList != null && itemnoList.get(0).getUt().isEmpty()) {
400
+                        errors.add("匹配到的单位为空!");
401
+                    }
402
+
403
+                    if (itemnoList != null && !itemnoList.get(0).getUt().isEmpty()) {
404
+                        if (!entity.getUt().equals(itemnoList.get(0).getUt())) {
405
+                            errors.add("输入的单位与匹配单位不一致!");
406
+                        }
407
+                    }
408
+
409
+                    if (itemnoList != null && itemnoList.get(0).getSdesc().isEmpty()) {
410
+                        errors.add("匹配到的中文品名为空!");
411
+                    }
412
+
413
+                    if (itemnoList != null && !itemnoList.get(0).getSdesc().isEmpty()) {
414
+                        if (!entity.getSdesc().equals(itemnoList.get(0).getSdesc())) {
415
+                            errors.add("输入的中文品名与匹配到的中文品名不一致!");
416
+                        }
417
+                    }
418
+
419
+                    if (itemnoList != null && !itemnoList.get(0).getEdesc().isEmpty()) {
420
+                        entity.setEdesc(itemnoList.get(0).getEdesc());
421
+                    }
422
+
423
+                    if (itemnoList != null && !itemnoList.get(0).getHsCode().isEmpty()) {
424
+                        entity.setHsCode(itemnoList.get(0).getHsCode());
425
+                    }
426
+                    if (itemnoList != null && !itemnoList.get(0).getHsNameCn().isEmpty()) {
427
+                        entity.setHsNameCn(itemnoList.get(0).getHsNameCn());
428
+                    }
429
+                    if (itemnoList != null && !itemnoList.get(0).getHsNameEn().isEmpty()) {
430
+                        entity.setHsNameEn(itemnoList.get(0).getHsNameEn());
431
+                    }
432
+
433
+                    if (StringUtils.isEmpty(entity.getCurcyPo())) {
434
+                        errors.add("采购币种不能为空!");
435
+                    }
436
+
437
+                    List<CustCtrl> curcyList = custCtrlMapper.selectByCurcyPo(entity.getCurcyPo());
438
+                    if(curcyList ==null||curcyList.isEmpty()){
439
+                        errors.add("采购币种有误!");
440
+                    }
441
+
442
+                    if(curcyList !=null&&!curcyList.isEmpty()&&!Objects.isNull(curcyList.get(0).getRate())&&!Objects.isNull(entity.getRatePo())){
443
+                        if(Objects.equals(entity.getRatePo(), curcyList.get(0).getRate())){
444
+                            errors.add("采购汇率和匹配到的采购汇率不符!");
445
+                        }
446
+                    }
447
+
448
+
449
+
450
+                    if("铁矿石".equals(bizProductType)){
451
+                        if(Objects.isNull(entity.getIronCont())){
452
+                            errors.add("合同产品类型为铁矿石时,含铁量%不能为空!");
453
+                        }
454
+                    }
455
+
456
+                    if("铁矿石".equals(bizProductType)||"煤炭".equals(bizProductType)){
457
+                        if(Objects.isNull(entity.getMoisture())){
458
+                            errors.add("合同产品类型为铁矿石或煤炭时,水分%不能为空!");
459
+                        }
460
+
461
+                        if(StringUtils.isEmpty(entity.getPriceMtd())){
462
+                            errors.add("合同产品类型为铁矿石或煤炭时,计价方式不能为空!");
463
+                        }
464
+
465
+                        List<DataDic> priceMtdList =   dicMapper.selectByPriceMtd(entity.getPriceMtd());
466
+                        if(priceMtdList==null || priceMtdList.isEmpty()){
467
+                            errors.add("输入的计价方式在数据字典中不存在!");
468
+                        }
469
+                        if(!StringUtils.isEmpty(entity.getResourceNo())){
470
+                           List<CustCtrl> resourceNoList =  custCtrlMapper.selectByResourceNo(entity.getResourceNo(),bizProductType);
471
+                           if(resourceNoList==null || resourceNoList.isEmpty()){
472
+                               errors.add("资源号有误!");
473
+                           }
474
+                        }
475
+
476
+                    }
477
+
478
+                    if(Objects.isNull(entity.getPoprice())){
479
+                        errors.add("采购单价不能为空!");
480
+                    }
481
+                    if(Objects.isNull(entity.getQty())){
482
+                        errors.add("数量不能为空!");
483
+                    }
484
+
485
+
486
+
487
+
488
+
489
+
357 490
 
358 491
                     salesDtlMapper.insert(entity);
359 492
                 }

+ 49
- 0
src/main/resources/mapper/CustCtrlMapper.xml View File

@@ -54,4 +54,53 @@
54 54
         )
55 55
         order by a.fdate desc
56 56
     </select>
57
+    <select id="selectByItemno" resultType="com.example.backend.entity.common.CustCtrl">
58
+        select b.type_name2,
59
+        a.itemno,
60
+        a.sdesc,
61
+        a.edesc,
62
+        a.ut,
63
+        a.hsCode,
64
+        a.hsNameCn,
65
+        a.hsNameEn,
66
+        a.inTaxRate
67
+        from SGGMIIP.invitem a
68
+        left join (select fno, type_name type_name2
69
+        from SGGMIIP.product_category
70
+        where nvl(del_flag, 0) != 1
71
+        and level = 0
72
+        and parent_id = 0) b on SUBSTR(a.itemno, 1, 2) = b.fno
73
+        where ifnull(a.del_flag, 0) != 1
74
+        and b.type_name2 = #{bizProductType}
75
+        and a.itemno = #{itemno}
76
+    </select>
77
+    <select id="selectByCurcyPo" resultType="com.example.backend.entity.common.CustCtrl">
78
+        select a.id
79
+             , a.fname
80
+             , a.fname1
81
+             , (select rate
82
+                from SGGMIIP.curcydtl
83
+                where a.id = rid
84
+                  and targetcode = 'CNY'
85
+                  and del_flag != 1) as rate
86
+             , (select rate
87
+                from SGGMIIP.curcydtl
88
+                where a.id = rid
89
+                  and targetcode = 'USD'
90
+                  and del_flag != 1) as rateUsd
91
+        from SGGMIIP.curcyctrl A
92
+        where ifnull(a.del_flag, 0) != 1
93
+          and ifnull(a.placed, '') = '2'
94
+          and a.fname = #{curcyPo}
95
+        group by a.id, a.fname, a.fname1
96
+    </select>
97
+    <select id="selectByResourceNo" resultType="com.example.backend.entity.common.CustCtrl">
98
+        select a.fno
99
+        from SGGMIIP.resourcectrl a
100
+        where ifnull(a.del_flag, 0) != 1
101
+        and ifnull(a.placed, '')='2'
102
+        and typename=#{bizProductType}
103
+        and a.fno =#{resourceNo}
104
+        order by a.fdate desc,a.fno
105
+    </select>
57 106
 </mapper>

+ 9
- 0
src/main/resources/mapper/DicMapper.xml View File

@@ -39,4 +39,13 @@
39 39
           and i.status = '0'
40 40
           and d.status = '0'
41 41
     </select>
42
+    <select id="selectByPriceMtd" resultType="com.example.backend.entity.common.DataDic">
43
+        select d.dic_name, i.item_value
44
+        from SGGMIIP.data_dic d
45
+                 left join SGGMIIP.data_item i on d.id = i.dic_id
46
+        where i.item_value = #{priceMtd}
47
+          and d.dic_name = '计价方式'
48
+          and i.status = '0'
49
+          and d.status = '0'
50
+    </select>
42 51
 </mapper>

Loading…
Cancel
Save