|
@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSON;
|
5
|
5
|
import com.alibaba.fastjson.TypeReference;
|
6
|
6
|
import com.th.demo.mapping.finance.AccountDetailMapper;
|
7
|
7
|
import com.th.demo.mapping.maint.CargoMapper;
|
|
8
|
+import com.th.demo.mapping.maint.CustomerMapper;
|
8
|
9
|
import com.th.demo.mapping.maint.PriceMapper;
|
9
|
10
|
import com.th.demo.mapping.maint.StackMapper;
|
10
|
11
|
import com.th.demo.mapping.ware.ChangeRecordMapper;
|
|
@@ -46,6 +47,8 @@ public class ChangeServiceImpl implements ChangeService {
|
46
|
47
|
public CargoMapper cargoMapper;
|
47
|
48
|
@Autowired
|
48
|
49
|
public CargoChangeRecordMapper cargoChangeRecordMapper;
|
|
50
|
+ @Autowired
|
|
51
|
+ public CustomerMapper customerMapper;
|
49
|
52
|
|
50
|
53
|
int num = 0;
|
51
|
54
|
String result = Type.FAIL;
|
|
@@ -55,21 +58,23 @@ public class ChangeServiceImpl implements ChangeService {
|
55
|
58
|
@Override
|
56
|
59
|
public String changeCustomer(String json, String customer,String address,String userId, String belongId) throws Exception{
|
57
|
60
|
List<Store> list = JSON.parseObject(json, new TypeReference<List<Store>>() {});
|
58
|
|
- Customer c = JSON.parseObject(customer, new TypeReference<Customer>() {});
|
|
61
|
+ Customer c1 = JSON.parseObject(customer, new TypeReference<Customer>() {});
|
|
62
|
+ Customer c = customerMapper.selectByPrimaryKey(c1.getId());//新货主
|
59
|
63
|
String recordType = "";
|
60
|
64
|
double sum_weight = 0;//可以进行货权转移的重量(货权转移的地方维护的)
|
61
|
65
|
double use_weight = 0;//已经使用的货权转移的重量
|
62
|
66
|
// 增加校验
|
63
|
|
- Cargo cargo = cargoMapper.selectByByFkAndCustomer(list.get(0).getFkComponyId(),c.getId(),belongId);
|
|
67
|
+ Customer fk_cus = customerMapper.selectByPrimaryKey(list.get(0).getCustomer().getId());//老货主
|
|
68
|
+ Cargo cargo = cargoMapper.selectByByFkAndCustomer(fk_cus.getId(),c.getId(),belongId);
|
64
|
69
|
if (cargo == null){
|
65
|
|
- num =10;
|
66
|
|
- return JSONTools.toString(1,"未维护两个单位之间货权转移重量");
|
|
70
|
+ sum_weight=0;
|
67
|
71
|
}else{
|
68
|
72
|
sum_weight = cargo.getSumWeight();
|
69
|
73
|
}
|
70
|
74
|
|
71
|
75
|
for (int i = 0; i < list.size(); i++) {
|
72
|
|
- if((sum_weight-use_weight-list.get(i).getWeight()) < 0){
|
|
76
|
+ //保留可转移重量不为0的情况下,货权转移重量的计算
|
|
77
|
+ if(sum_weight != 0 && (sum_weight-use_weight-list.get(i).getWeight()) < 0){
|
73
|
78
|
num =10;
|
74
|
79
|
return JSONTools.toString(1,"权转移重量不足");
|
75
|
80
|
}
|
|
@@ -83,27 +88,30 @@ public class ChangeServiceImpl implements ChangeService {
|
83
|
88
|
ChangeRecord changeRecord = getChangeRecord(recordType, list.get(i), c, address, userId, belongId);
|
84
|
89
|
num += changeRecordMapper.insert(changeRecord);
|
85
|
90
|
list.get(i).setCustomer(c);
|
86
|
|
- list.get(i).setFkComponyId(c.getId());
|
|
91
|
+ list.get(i).setFkComponyId(fk_cus.getId());
|
87
|
92
|
list.get(i).setReceiveAddress(address);
|
88
|
93
|
num += storeMapper.updateByPrimaryKey(list.get(i));
|
89
|
94
|
use_weight = use_weight + list.get(i).getWeight();
|
90
|
95
|
}
|
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);
|
|
96
|
+ if (sum_weight != 0){
|
|
97
|
+ cargo.setSumWeight(cargo.getSumWeight() - use_weight);
|
|
98
|
+ cargo.setUseWeight(cargo.getUseWeight() + use_weight);
|
|
99
|
+ num = cargoMapper.updateByPrimaryKey(cargo);
|
|
100
|
+ result = Tools.moreThanZeroResultJSON(num);
|
|
101
|
+
|
|
102
|
+ CargoChangeRecord cargoChangeRecord = new CargoChangeRecord();
|
|
103
|
+ cargoChangeRecord.setUperCustomer(cargo.getUperCustomer());
|
|
104
|
+ cargoChangeRecord.setCustomer(cargo.getCustomer());
|
|
105
|
+ cargoChangeRecord.setChangeFrom("货权转移");
|
|
106
|
+ cargoChangeRecord.setWeight(use_weight);
|
|
107
|
+ cargoChangeRecord.setSubStr("减少");
|
|
108
|
+
|
|
109
|
+ cargoChangeRecord.setModifyTime(new Date());
|
|
110
|
+ cargoChangeRecord.setModifyUser(new SysUser(userId));
|
|
111
|
+ num = cargoChangeRecordMapper.insert(cargoChangeRecord);
|
|
112
|
+ result = Tools.moreThanZeroResultJSON(num);
|
|
113
|
+ }
|
|
114
|
+
|
107
|
115
|
|
108
|
116
|
|
109
|
117
|
return Tools.moreThanZeroResultJSON(num);
|