CrmController.java
13.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
package com.huaheng.api.crm.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.huaheng.api.crm.domain.BatteryCodeList;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.framework.aspectj.lang.annotation.ApiLogger;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.barcode.barcodeDetail.domain.BarCodeDetail;
import com.huaheng.pc.barcode.barcodeDetail.service.BarCodeDetailService;
import com.huaheng.pc.barcode.barcodeHeader.domain.BarCodeHeader;
import com.huaheng.pc.barcode.barcodeHeader.service.BarCodeHeaderService;
import com.huaheng.pc.config.customer.domain.Customer;
import com.huaheng.pc.config.customer.service.CustomerServiceImpl;
import com.huaheng.pc.config.zone.domain.Zone;
import com.huaheng.pc.config.zone.service.ZoneService;
import com.huaheng.pc.inventory.InventoryMaterialSummary.domain.InventoryMaterialSummary;
import com.huaheng.pc.inventory.InventoryMaterialSummary.service.InventoryMaterialSummaryService;
import com.huaheng.pc.inventory.inventoryDetail.domain.InventoryDetail;
import com.huaheng.pc.inventory.inventoryDetail.service.InventoryDetailService;
import com.huaheng.pc.inventory.inventoryTransaction.domain.InventoryTransaction;
import com.huaheng.pc.inventory.inventoryTransaction.service.InventoryTransactionService;
import com.huaheng.pc.receipt.receiptContainerDetail.domain.ReceiptContainerDetail;
import com.huaheng.pc.receipt.receiptContainerDetail.service.ReceiptContainerDetailService;
import com.huaheng.pc.receipt.receiptHeader.domain.ReceiptHeader;
import com.huaheng.pc.receipt.receiptHeader.service.ReceiptHeaderService;
import com.huaheng.pc.shipment.shipmentHeader.domain.ShipmentHeader;
import com.huaheng.pc.shipment.shipmentHeader.service.ShipmentHeaderService;
import com.huaheng.pc.task.taskDetail.domain.TaskDetail;
import com.huaheng.pc.task.taskDetail.service.TaskDetailService;
import com.huaheng.pc.task.taskHeader.domain.TaskHeader;
import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* @author yiwenpeng
* @date 2023/5/8 18:39
*/
@RestController
@RequestMapping("/api/CRM")
public class CrmController {
@Resource
private ReceiptHeaderService receiptHeaderService;
@Resource
private ReceiptContainerDetailService receiptContainerDetailService;
@Resource
private InventoryDetailService inventoryDetailService;
@Resource
private TaskDetailService taskDetailService;
@Resource
private TaskHeaderService taskHeaderService;
@Resource
private ZoneService zoneService;
@Resource
private BarCodeDetailService barCodeDetailService;
@Resource
private BarCodeHeaderService barCodeHeaderService;
@Resource
private ShipmentHeaderService shipmentHeaderService;
@Resource
private CustomerServiceImpl customerServiceImpl;
@Resource
private InventoryTransactionService inventoryTransactionService;
/**
* 通过入库单号查询电池包码列表
*/
@PostMapping("/batteryCodeList")
@ApiLogger(apiName = "通过入库单号查询电池包码列表", from = "CRM")
@ResponseBody
public AjaxResult batteryCodeList(@RequestBody Map<String, String> map) {
String code = map.get("code");
if (StringUtils.isEmpty(code)) {
return AjaxResult.error("编码为空");
}
ReceiptHeader receiptHeader = receiptHeaderService.getOne(new LambdaQueryWrapper<ReceiptHeader>().eq(ReceiptHeader::getReferCode, code));
if (receiptHeader==null) {
return AjaxResult.error("未查询到入库单");
}
List<BatteryCodeList> list = new ArrayList<>();
List<ReceiptContainerDetail> receiptContainerDetailList = receiptContainerDetailService.list(new LambdaQueryWrapper<ReceiptContainerDetail>().eq(ReceiptContainerDetail::getReceiptCode, receiptHeader.getCode()));
if (receiptContainerDetailList.size()==0) {
BatteryCodeList batteryCodeList = new BatteryCodeList();
batteryCodeList.setStatus("未入库");
list.add(batteryCodeList);
}
for (ReceiptContainerDetail detail : receiptContainerDetailList) {
BatteryCodeList batteryCodeList = new BatteryCodeList();
batteryCodeList.setCode(detail.getBatteryPackTwoCode());
if (detail.getStatus()==0 || detail.getStatus()==10) {
batteryCodeList.setStatus("已组盘,未入库");
}else if (detail.getStatus() == 20) {
InventoryDetail inventoryDetail = inventoryDetailService.getOne(new LambdaQueryWrapper<InventoryDetail>().eq(InventoryDetail::getBatteryPackTwoCode, detail.getBatteryPackTwoCode()));
if (inventoryDetail==null) {
batteryCodeList.setStatus("已出库");
}else {
batteryCodeList.setStatus("已入库");
}
}else {
batteryCodeList.setStatus("组盘状态未知,联系WMS处理");
}
list.add(batteryCodeList);
}
return AjaxResult.success(list);
}
/**
* 电池编码溯源
*/
@PostMapping("/batteryCodeTraceability")
@ApiLogger(apiName = "电池编码溯源", from = "CRM")
@ResponseBody
public AjaxResult batteryCodeTraceability(@RequestBody Map<String, String> map) {
String code = map.get("code");
String type = map.get("type");
if (StringUtils.isEmpty(code)) {
return AjaxResult.error("编码为空");
}
if (StringUtils.isEmpty(type)) {
return AjaxResult.error("类型为空");
}
if ("P20".equals(code.substring(0,3))) {
//电池包
if (type.equals("receipt")) {
return batteryCodeReceipt(code);
}else if (type.equals("shipment")){
return batteryCodeShipment(code);
}else{
return AjaxResult.error("类型有误");
}
}else{
if (type.equals("receipt")) {
return productReceipt(code);
}else if (type.equals("shipment")){
return productShipment(code);
}else{
return AjaxResult.error("类型有误");
}
}
}
//电池包入库
private AjaxResult batteryCodeReceipt(String code){
BatteryCodeList batteryCodeList = new BatteryCodeList();
TaskDetail taskDetail = taskDetailService.getOne(new LambdaQueryWrapper<TaskDetail>().eq(TaskDetail::getInternalTaskType,100).eq(TaskDetail::getBatteryPackTwoCode, code));
if (taskDetail!=null) {
TaskHeader taskheader = taskHeaderService.getById(taskDetail.getTaskId());
Zone zone = zoneService.getOne(new LambdaQueryWrapper<Zone>().eq(Zone::getCode, taskheader.getZoneCode()));
batteryCodeList.setReceiptDate(taskheader.getCompleteTime());
batteryCodeList.setReceiptWarehouse(zone.getName());
batteryCodeList.setReceiptBy(taskheader.getLastUpdatedBy());
batteryCodeList.setMaterialGrossWeight(taskDetail.getMaterialGrossWeight());
batteryCodeList.setMaterialNetWeight(taskDetail.getMaterialNetWeight());
batteryCodeList.setMaterialTareWeight(taskDetail.getMaterialTareWeight());
if (StringUtils.isNotEmpty(taskDetail.getBillCode())) {
ReceiptHeader receiptHeader = receiptHeaderService.getOne(new LambdaQueryWrapper<ReceiptHeader>().eq(ReceiptHeader::getCode, taskDetail.getBillCode()));
if (receiptHeader!=null) {
batteryCodeList.setReceiptCode(receiptHeader.getReferCode());
}
}
}
return AjaxResult.success(batteryCodeList);
}
//电池包出库
private AjaxResult batteryCodeShipment(String code){
BatteryCodeList batteryCodeList = new BatteryCodeList();
TaskDetail taskDetail = taskDetailService.getOne(new LambdaQueryWrapper<TaskDetail>().eq(TaskDetail::getInternalTaskType,200).eq(TaskDetail::getBatteryPackTwoCode, code));
if (taskDetail!=null) {
TaskHeader taskheader = taskHeaderService.getById(taskDetail.getTaskId());
Zone zone = zoneService.getOne(new LambdaQueryWrapper<Zone>().eq(Zone::getCode, taskheader.getZoneCode()));
batteryCodeList.setShipmentDate(taskheader.getCompleteTime());
batteryCodeList.setShipmentWarehouse(zone.getName());
batteryCodeList.setShipmentBy(taskheader.getLastUpdatedBy());
if (StringUtils.isNotEmpty(taskDetail.getBillCode())) {
ShipmentHeader shipmentHeader = shipmentHeaderService.getOne(new LambdaQueryWrapper<ShipmentHeader>().eq(ShipmentHeader::getCode, taskDetail.getBillCode()));
if (shipmentHeader!=null) {
batteryCodeList.setShipmentCode(shipmentHeader.getReferCode());
}
}
}
return AjaxResult.success(batteryCodeList);
}
//成品入库
private AjaxResult productReceipt(String code) {
BatteryCodeList batteryCodeList = new BatteryCodeList();
List<InventoryTransaction> inventoryTransactionList = inventoryTransactionService.list(new LambdaQueryWrapper<InventoryTransaction>().eq(InventoryTransaction::getBarMaterialCode, code).eq(InventoryTransaction::getTransactionType, 10));
if (inventoryTransactionList.size() > 0) {
InventoryTransaction inventoryTransaction = inventoryTransactionList.get(0);
TaskDetail taskDetail = taskDetailService.list(new LambdaQueryWrapper<TaskDetail>().eq(TaskDetail::getBillCode,inventoryTransaction.getBillCode())).get(0);
TaskHeader taskheader = taskHeaderService.getById(taskDetail.getTaskId());
Zone zone = zoneService.getOne(new LambdaQueryWrapper<Zone>().eq(Zone::getCode, taskheader.getZoneCode()));
BarCodeDetail barCodeDetail = barCodeDetailService.getOne(new LambdaQueryWrapper<BarCodeDetail>().eq(BarCodeDetail::getCode, code));
BarCodeHeader codeHeader = barCodeHeaderService.getById(barCodeDetail.getReceiptId());
batteryCodeList.setMaterialCode(taskDetail.getMaterialCode());
batteryCodeList.setMaterialName(taskDetail.getMaterialName());
batteryCodeList.setMaterialSpec(taskDetail.getMaterialSpec());
batteryCodeList.setMaterialUnit(taskDetail.getMaterialUnit());
batteryCodeList.setReceiptWarehouse(zone.getName());
batteryCodeList.setReceiptBy(taskheader.getLastUpdatedBy());
batteryCodeList.setReceiptDate(taskheader.getCompleteTime());
batteryCodeList.setWeight(codeHeader.getTotalWeight().toString());
}
return AjaxResult.success(batteryCodeList);
}
//成品出库
private AjaxResult productShipment(String code){
BatteryCodeList batteryCodeList = new BatteryCodeList();
List<InventoryTransaction> inventoryTransactions = inventoryTransactionService.list(new LambdaQueryWrapper<InventoryTransaction>().eq(InventoryTransaction::getBarMaterialCode, code).eq(InventoryTransaction::getTransactionType, 20));
if (inventoryTransactions.size() > 0) {
InventoryTransaction inventoryTransaction = inventoryTransactions.get(0);
ShipmentHeader shipmentHeader = shipmentHeaderService.getOne(new LambdaQueryWrapper<ShipmentHeader>().eq(ShipmentHeader::getCode, inventoryTransaction.getBillCode()));
if (shipmentHeader == null) {
return AjaxResult.error("对应出库单不存在," + inventoryTransaction.getBillCode());
}
TaskDetail taskDetail = taskDetailService.list(new LambdaQueryWrapper<TaskDetail>().eq(TaskDetail::getBillCode, inventoryTransaction.getBillCode())).get(0);
TaskHeader taskheader = taskHeaderService.getById(taskDetail.getTaskId());
Zone zone = zoneService.getOne(new LambdaQueryWrapper<Zone>().eq(Zone::getCode, taskheader.getZoneCode()));
BarCodeDetail barCodeDetail = barCodeDetailService.getOne(new LambdaQueryWrapper<BarCodeDetail>().eq(BarCodeDetail::getCode, code));
BarCodeHeader codeHeader = barCodeHeaderService.getById(barCodeDetail.getReceiptId());
if (StringUtils.isNotEmpty(shipmentHeader.getCustomerCode())) {
Customer customer = customerServiceImpl.getOne(new LambdaQueryWrapper<Customer>().eq(Customer::getCode, shipmentHeader.getCustomerCode()));
batteryCodeList.setCustomerName(customer.getName());
}
batteryCodeList.setMaterialCode(taskDetail.getMaterialCode());
batteryCodeList.setMaterialName(taskDetail.getMaterialName());
batteryCodeList.setMaterialSpec(taskDetail.getMaterialSpec());
batteryCodeList.setMaterialUnit(taskDetail.getMaterialUnit());
batteryCodeList.setShipmentWarehouse(zone.getName());
batteryCodeList.setShipmentBy(taskheader.getLastUpdatedBy());
batteryCodeList.setShipmentDate(taskheader.getCompleteTime());
batteryCodeList.setWeight(codeHeader.getTotalWeight().toString());
}
return AjaxResult.success(batteryCodeList);
}
}