MobileShipmentController.java
10.3 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
package com.huaheng.shipment.mobile;
import com.alibaba.fastjson.JSONException;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huaheng.common.core.utils.StringUtils;
import com.huaheng.common.core.web.domain.AjaxResult;
import com.huaheng.common.security.utils.SecurityUtils;
import com.huaheng.config.api.RemoteMaterialService;
import com.huaheng.config.api.domain.Material;
import com.huaheng.shipment.api.domain.ShipmentDetail;
import com.huaheng.shipment.api.domain.ShipmentHeader;
import com.huaheng.shipment.api.domain.ShipmentTaskCreateModel;
import com.huaheng.shipment.shipmentContainer.service.ShipmentContainerHeaderService;
import com.huaheng.shipment.shipmentDetail.service.ShipmentDetailService;
import com.huaheng.shipment.shipmentHeader.mapper.ShipmentHeaderMapper;
import com.huaheng.shipment.shipmentHeader.service.ShipmentHeaderService;
import com.huaheng.task.api.RemoteTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;
/**
*
* @author Enzo Cotter
* @date 2019/12/15
*/
@CrossOrigin
@RestController
@RequestMapping("/mobile")
@Api(tags = {"移动端收货"}, value = "移动端收货MobileBatchReceiptController")
public class MobileShipmentController {
@Resource
private ShipmentHeaderService shipmentHeaderService;
@Resource
private ShipmentHeaderMapper shipmentHeaderMapper;
@Resource
private ShipmentDetailService shipmentDetailService;
@Resource
private RemoteMaterialService materialService;
@Resource
private ShipmentContainerHeaderService shipmentContainerHeaderService;
@PostMapping("/findShipment")
@ApiOperation("移动端查询出库单")
public AjaxResult findShipment(@RequestBody @ApiParam(value = "物料号") Map<String, String> param){
String shipmentCode = param.get("shipmentCode");
List<String> companyCodeList = StringUtils.stringToLIST(param.get("companyCode"));
if (StringUtils.isNull(shipmentCode)){
return AjaxResult.error("上游系统关联单号为空");
} else if (StringUtils.isNull(companyCodeList)){
return AjaxResult.error("公司编码为空");
}
/* 查询入库单,如果数据库中不存在,则调用ERP接口拉取单据,成功后再次查询返回结果*/
LambdaQueryWrapper<ShipmentHeader> shipmentLambdaQueryWrapper = Wrappers.lambdaQuery();
shipmentLambdaQueryWrapper.eq(ShipmentHeader::getCode, shipmentCode)
.in(ShipmentHeader::getCompanyCode, companyCodeList);
ShipmentHeader shipmentHeader = shipmentHeaderService.getOne(shipmentLambdaQueryWrapper);
if(shipmentHeader == null) {
return AjaxResult.error("没有找到出库单");
}
ShipmentDomain shipment = new ShipmentDomain();
shipment.setShipmentHeader(shipmentHeader);
LambdaQueryWrapper<ShipmentDetail> shipmentDetailQueryWrapper = Wrappers.lambdaQuery();
shipmentDetailQueryWrapper.eq(ShipmentDetail::getShipmentId, shipmentHeader.getId());
List<ShipmentDetail> shipmentDetailList = shipmentDetailService.list(shipmentDetailQueryWrapper);
shipment.setShipmentDetails(shipmentDetailList);
return AjaxResult.success(shipment);
}
@PostMapping("/searchShipment")
@ApiOperation("移动端查询出库单")
public AjaxResult searchShipment(@RequestBody @ApiParam(value = "物料号") Map<String, String> param){
List<String> companyCodeList = StringUtils.stringToLIST(param.get("companyCode"));
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String now = df.format(new Date());
Calendar c = Calendar.getInstance();
c.setTime(new Date());
c.add(Calendar.DATE, -7);
Date first = c.getTime();
String start = df.format(first);//前一天
LambdaQueryWrapper<ShipmentHeader> shipmentHeaderQueryWrapper = Wrappers.lambdaQuery();
shipmentHeaderQueryWrapper.in(ShipmentHeader::getCompanyCode, companyCodeList)
.eq(ShipmentHeader::getWarehouseCode, SecurityUtils.getWarehouseCode())
.le(ShipmentHeader::getCreated, now)
.gt(ShipmentHeader::getCreated, start)
.orderByDesc(ShipmentHeader::getCreated);
List<ShipmentHeader> receiptHeaderList = shipmentHeaderService.list(shipmentHeaderQueryWrapper);
return AjaxResult.success(receiptHeaderList);
}
@PostMapping("/searchShipmentInCondition")
@ApiOperation("移动端查询出库单")
public AjaxResult searchShipmentInCondition(@RequestBody @ApiParam(value = "物料号") Map<String, String> param){
List<String> companyCodeList = StringUtils.stringToLIST(param.get("companyCode"));
String code = param.get("code");
String shipmentType = param.get("shipmentType");
String lastStatus = param.get("lastStatus");
String startTime = param.get("startTime");
String endTime = param.get("endTime");
LambdaQueryWrapper<ShipmentHeader> shipmentQueryWrapper = Wrappers.lambdaQuery();
shipmentQueryWrapper.in(ShipmentHeader::getCompanyCode, companyCodeList)
.eq(ShipmentHeader::getWarehouseCode, SecurityUtils.getWarehouseCode())
.like(StringUtils.isNotEmpty(code), ShipmentHeader::getCode, code)
.eq(StringUtils.isNotEmpty(shipmentType), ShipmentHeader::getShipmentType, shipmentType)
.eq(StringUtils.isNotEmpty(lastStatus), ShipmentHeader::getLastStatus, lastStatus)
.gt(StringUtils.isNotEmpty(startTime), ShipmentHeader::getCreated, startTime)
.le(StringUtils.isNotEmpty(endTime), ShipmentHeader::getCreated, endTime)
.orderByDesc(ShipmentHeader::getCreated);
List<ShipmentHeader> shipmentHeaderList = shipmentHeaderService.list(shipmentQueryWrapper);
return AjaxResult.success(shipmentHeaderList);
}
@PostMapping("/createShipmentCode")
@ApiOperation("移动端创建出库单号")
public AjaxResult createShipmentCode(@RequestBody @ApiParam(value = "物料号") Map<String, String> param){
String shipmentType = "ELO";
String code = null;
Date now = new Date();
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
String maxCode = shipmentHeaderMapper.createCode(shipmentType);
//如果指定类型的最后的code存在,并且日期一致。那么 code = 入库单类型 + 年月日 + (排序号 + 1)
if (maxCode != null && maxCode.substring(maxCode.length() - 13, maxCode.length() - 5).equals(df.format(now))) {
Integer Count = Integer.valueOf(maxCode.substring(maxCode.length() - 5, maxCode.length()));
code = shipmentType + df.format(now) + String.format("%05d", Count + 1);
} else {
code = shipmentType + df.format(now) + "00001";
}
return AjaxResult.success("创建出库编码成功",code);
}
@PostMapping("/createShipment")
@ApiOperation("移动端创建出库单")
@Transactional(rollbackFor = Exception.class)
public AjaxResult createShipment(@RequestBody @ApiParam(value = "物料号")List<ShipmentBill> shipmentBills){
String companyCode = shipmentBills.get(0).getCompanyCode();
String shipmentCode = shipmentBills.get(0).getShipmentCode();
String shipmentType = "ELO";
ShipmentHeader shipmentHeader = new ShipmentHeader();
shipmentHeader.setId(null);
shipmentHeader.setCode(shipmentCode);
shipmentHeader.setShipmentType(shipmentType);
shipmentHeader.setWarehouseCode(SecurityUtils.getWarehouseCode());
shipmentHeader.setCreatedBy(SecurityUtils.getUsername());
shipmentHeader.setLastUpdatedBy(SecurityUtils.getUsername());
shipmentHeader.setFirstStatus(200);
shipmentHeader.setLastStatus(200);
shipmentHeader.setCompanyCode(companyCode);
shipmentHeaderService.save(shipmentHeader);
List<Integer> shipmentdetailIds = insertTodayShipmentDetail(shipmentHeader.getId(), shipmentBills, false, companyCode);
shipmentDetailService.updateShipmentHeader(shipmentHeader);
if(shipmentdetailIds != null && shipmentdetailIds.size() > 0) {
return AjaxResult.success("创建出库单成功");
}
return AjaxResult.error("创建出库单失败");
}
public List<Integer> insertTodayShipmentDetail(int headerId, List<ShipmentBill> shipmentBills, boolean isCompletedQty, String companyCode) {
List<Integer> mShipmentDetailIds = new ArrayList<>();
ShipmentHeader shipmentHeader = shipmentHeaderService.getById(headerId);
for (ShipmentBill shipmentBill : shipmentBills) {
ShipmentDetail shipmentDetail = new ShipmentDetail();
shipmentDetail.setId(null);
shipmentDetail.setWarehouseCode(SecurityUtils.getWarehouseCode());
shipmentDetail.setCompanyCode(companyCode);
shipmentDetail.setShipmentId(headerId);
shipmentDetail.setShipmentCode(shipmentHeader.getCode());
shipmentDetail.setMaterialCode(shipmentBill.getMaterialCode());
Material material = materialService.getByCode(shipmentBill.getMaterialCode());
shipmentDetail.setMaterialName(material.getName());
shipmentDetail.setMaterialUnit(material.getUnit());
shipmentDetail.setInventorySts("good");
shipmentDetail.setShipQty(shipmentBill.getQty());
shipmentDetailService.save(shipmentDetail);
mShipmentDetailIds.add(shipmentDetail.getId());
}
return mShipmentDetailIds;
}
/**
* 自动组盘
* @param
* @return
*/
@PostMapping("/autoCombination")
@ResponseBody
public AjaxResult autoCombination(@RequestBody Map<String, String> param){
String shipmentCode = param.get("shipmentCode");
AjaxResult ajaxResult = shipmentContainerHeaderService.autoCombination(shipmentCode);
return ajaxResult;
}
}