|
@@ -1,14 +1,18 @@
|
1
|
1
|
package com.th.demo.service.impl.ware;
|
2
|
2
|
|
|
3
|
+import com.alibaba.druid.sql.visitor.functions.If;
|
3
|
4
|
import com.alibaba.fastjson.JSON;
|
4
|
5
|
import com.alibaba.fastjson.TypeReference;
|
5
|
6
|
import com.th.demo.mapping.finance.AccountDetailMapper;
|
|
7
|
+import com.th.demo.mapping.maint.CargoMapper;
|
6
|
8
|
import com.th.demo.mapping.maint.PriceMapper;
|
7
|
9
|
import com.th.demo.mapping.maint.StackMapper;
|
8
|
10
|
import com.th.demo.mapping.ware.ChangeRecordMapper;
|
|
11
|
+import com.th.demo.mapping.ware.CargoChangeRecordMapper;
|
9
|
12
|
import com.th.demo.mapping.ware.CombineRecordMapper;
|
10
|
13
|
import com.th.demo.mapping.ware.StoreMapper;
|
11
|
14
|
import com.th.demo.model.finance.AccountDetail;
|
|
15
|
+import com.th.demo.model.maint.Cargo;
|
12
|
16
|
import com.th.demo.model.maint.Customer;
|
13
|
17
|
import com.th.demo.model.maint.Price;
|
14
|
18
|
import com.th.demo.model.maint.Stack;
|
|
@@ -38,6 +42,10 @@ public class ChangeServiceImpl implements ChangeService {
|
38
|
42
|
public PriceMapper priceMapper;
|
39
|
43
|
@Autowired
|
40
|
44
|
public StoreMapper storeMapper;
|
|
45
|
+ @Autowired
|
|
46
|
+ public CargoMapper cargoMapper;
|
|
47
|
+ @Autowired
|
|
48
|
+ public CargoChangeRecordMapper cargoChangeRecordMapper;
|
41
|
49
|
|
42
|
50
|
int num = 0;
|
43
|
51
|
String result = Type.FAIL;
|
|
@@ -46,12 +54,25 @@ public class ChangeServiceImpl implements ChangeService {
|
46
|
54
|
@Transactional(rollbackFor = Exception.class)
|
47
|
55
|
@Override
|
48
|
56
|
public String changeCustomer(String json, String customer,String address,String userId, String belongId) throws Exception{
|
49
|
|
- List<Store> list = JSON.parseObject(json, new TypeReference<List<Store>>() {
|
50
|
|
- });
|
51
|
|
- Customer c = JSON.parseObject(customer, new TypeReference<Customer>() {
|
52
|
|
- });
|
|
57
|
+ List<Store> list = JSON.parseObject(json, new TypeReference<List<Store>>() {});
|
|
58
|
+ Customer c = JSON.parseObject(customer, new TypeReference<Customer>() {});
|
53
|
59
|
String recordType = "";
|
|
60
|
+ double sum_weight = 0;//可以进行货权转移的重量(货权转移的地方维护的)
|
|
61
|
+ double use_weight = 0;//已经使用的货权转移的重量
|
|
62
|
+ // 增加校验
|
|
63
|
+ Cargo cargo = cargoMapper.selectByByFkAndCustomer(list.get(0).getFkComponyId(),c.getId(),belongId);
|
|
64
|
+ if (cargo == null){
|
|
65
|
+ num =10;
|
|
66
|
+ return JSONTools.toString(1,"未维护两个单位之间货权转移重量");
|
|
67
|
+ }else{
|
|
68
|
+ sum_weight = cargo.getSumWeight();
|
|
69
|
+ }
|
|
70
|
+
|
54
|
71
|
for (int i = 0; i < list.size(); i++) {
|
|
72
|
+ if((sum_weight-use_weight-list.get(i).getWeight()) < 0){
|
|
73
|
+ num =10;
|
|
74
|
+ return JSONTools.toString(1,"权转移重量不足");
|
|
75
|
+ }
|
55
|
76
|
if(list.get(i).getCustomer().getName().equals(c.getName())){
|
56
|
77
|
recordType = "0";
|
57
|
78
|
}else {
|
|
@@ -61,12 +82,30 @@ public class ChangeServiceImpl implements ChangeService {
|
61
|
82
|
}
|
62
|
83
|
ChangeRecord changeRecord = getChangeRecord(recordType, list.get(i), c, address, userId, belongId);
|
63
|
84
|
num += changeRecordMapper.insert(changeRecord);
|
64
|
|
-
|
65
|
|
-
|
66
|
85
|
list.get(i).setCustomer(c);
|
|
86
|
+ list.get(i).setFkComponyId(c.getId());
|
67
|
87
|
list.get(i).setReceiveAddress(address);
|
68
|
88
|
num += storeMapper.updateByPrimaryKey(list.get(i));
|
|
89
|
+ use_weight = use_weight + list.get(i).getWeight();
|
69
|
90
|
}
|
|
91
|
+ cargo.setSumWeight(cargo.getSumWeight() - use_weight);
|
|
92
|
+ cargo.setUseWeight(cargo.getUseWeight() + use_weight);
|
|
93
|
+ num = cargoMapper.updateByPrimaryKey(cargo);
|
|
94
|
+ result = Tools.moreThanZeroResultJSON(num);
|
|
95
|
+
|
|
96
|
+ CargoChangeRecord cargoChangeRecord = new CargoChangeRecord();
|
|
97
|
+ cargoChangeRecord.setUperCustomer(cargo.getUperCustomer());
|
|
98
|
+ cargoChangeRecord.setCustomer(cargo.getCustomer());
|
|
99
|
+ cargoChangeRecord.setChangeFrom("货权转移");
|
|
100
|
+ cargoChangeRecord.setWeight(use_weight);
|
|
101
|
+ cargoChangeRecord.setSubStr("减少");
|
|
102
|
+
|
|
103
|
+ cargoChangeRecord.setModifyTime(new Date());
|
|
104
|
+ cargoChangeRecord.setModifyUser(new SysUser(userId));
|
|
105
|
+ num = cargoChangeRecordMapper.insert(cargoChangeRecord);
|
|
106
|
+ result = Tools.moreThanZeroResultJSON(num);
|
|
107
|
+
|
|
108
|
+
|
70
|
109
|
return Tools.moreThanZeroResultJSON(num);
|
71
|
110
|
}
|
72
|
111
|
|