ReceiptHeaderServiceImpl.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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
package com.huaheng.pc.receipt.receiptHeader.service;
import com.huaheng.api.SSP.service.OrderAssignApiService;
import com.huaheng.api.U8.domain.ICSReceiptHeader;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.mobile.receipt.ReceiptResult;
import com.huaheng.pc.general.material.domain.Material;
import com.huaheng.pc.general.material.service.IMaterialService;
import com.huaheng.pc.receipt.receiptContainerDetail.domain.ReceiptContainerDetail;
import com.huaheng.pc.receipt.receiptDetail.domain.ReceiptDetail;
import com.huaheng.pc.receipt.receiptDetail.service.IReceiptDetailService;
import com.huaheng.pc.receipt.receiptHeader.domain.ReceiptHeader;
import com.huaheng.pc.receipt.receiptHeader.mapper.ReceiptHeaderMapperAuto;
import com.huaheng.pc.receipt.receiptHeader.mapper.ReceiptHeaderMapper;
import com.huaheng.pc.system.dict.service.IDictDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
/**
* 入库单主 服务层实现
*
* @author huaheng
* @date 2018-08-19
*/
@Service
public class ReceiptHeaderServiceImpl implements IReceiptHeaderService {
@Autowired
IReceiptDetailService receiptDetailService;
@Autowired
IDictDataService dictDataService;
@Resource
private ReceiptHeaderMapperAuto aotuMapper;
@Resource
private ReceiptHeaderMapper receiptHeaderMapper;
@Autowired
private IMaterialService materialService;
@Autowired
IReceiptHeaderService receiptHeaderService;
@Autowired
private OrderAssignApiService orderAssignApiService;
public List<ReceiptHeader> selectListEntityByLike(ReceiptHeader condition) {
return aotuMapper.selectListEntityByLike(condition);
}
public List<ReceiptHeader> selectListEntityByEqual(ReceiptHeader condition) {
return aotuMapper.selectListEntityByEqual(condition);
}
public ReceiptHeader selectFirstEntity(ReceiptHeader condition) {
ReceiptHeader item = aotuMapper.selectFirstEntity(condition);
return item;
}
public ReceiptHeader selectEntityById(Integer id) {
return aotuMapper.selectEntityById(id);
}
public List<Map<String, Object>> selectListMapByEqual(String columns, ReceiptHeader condition) {
return aotuMapper.selectListMapByEqual(columns, condition);
}
public Map<String, Object> selectFirstMap(String columns, ReceiptHeader condition) {
Map<String, Object> item = aotuMapper.selectFirstMap(columns, condition);
return item;
}
public int insert(ReceiptHeader record) {
return aotuMapper.insert(record);
}
public int updateByModel(ReceiptHeader record) {
return aotuMapper.updateByModel(record);
}
public int updateByCondition(ReceiptHeader record, ReceiptHeader condition) {
return aotuMapper.updateByCondition(record, condition);
}
public int deleteById(Integer id) {
return aotuMapper.deleteById(id);
}
public int deleteByCondition(ReceiptHeader condition) {
return aotuMapper.deleteByCondition(condition);
}
public String createCode(String receiptType)
{
String code = null;
Date now = new Date();
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
String maxCode = receiptHeaderMapper.createCode(receiptType);
//如果指定类型的最后的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 = receiptType + df.format(now) + String.format("%05d", Count + 1);
}
else
{
code = receiptType + df.format(now) + "00001";
}
return code;
}
@Override
public AjaxResult<Boolean> insertHeader(ReceiptHeader receiptHeader) {
if(dictDataService.checkConfig("receiptType", receiptHeader.getType()) == false)
{
return AjaxResult.error("没有对应的入库单类型");
}
String code = createCode(receiptHeader.getType());
receiptHeader.setId(null);
receiptHeader.setCode(code);
receiptHeader.setWarehouseId(ShiroUtils.getWarehouseId());
receiptHeader.setWarehouseCode(ShiroUtils.getWarehouseCode());
receiptHeader.setCreated(null);
receiptHeader.setCreatedBy(ShiroUtils.getLoginName());
receiptHeader.setLastUpdated(null);
receiptHeader.setLastUpdatedBy(ShiroUtils.getLoginName());
receiptHeader.setUploadStatus(0);
Integer result = this.insert(receiptHeader);
return AjaxResult.toAjax(result > 0);
}
@Override
public AjaxResult updateHeader(ReceiptHeader receiptHeader) {
ReceiptHeader entity = this.selectEntityById(receiptHeader.getId());
if (entity.getFirstStatus() > 100)
return AjaxResult.error("状态不允许修改!");
receiptHeader.setCode(null);
receiptHeader.setType(null);
receiptHeader.setWarehouseId(null);
receiptHeader.setWarehouseCode(null);
receiptHeader.setFirstStatus(null);
receiptHeader.setLastStatus(null);
receiptHeader.setEnable(receiptHeader.getEnable() == null ? false:receiptHeader.getEnable());
receiptHeader.setLastUpdatedBy(ShiroUtils.getLoginName());
this.updateByModel(receiptHeader);
return AjaxResult.success("修改成功!");
}
@Override
public Integer createTodayHeader(String companyId, String companyCode) {
String receiptType = "PPI";
String code = null;
Date now = new Date();
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
String maxCode = receiptHeaderMapper.createCode(receiptType);
//如果指定类型的最后的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 = receiptType + df.format(now) + String.format("%05d", Count + 1);
// }
// else
// {
code = receiptType + df.format(now) + "00001";
// }
ReceiptHeader receiptHeader = new ReceiptHeader();
receiptHeader.setCode(code);
ReceiptHeader receiptHeader1 = this.selectFirstEntity(receiptHeader);
if(receiptHeader1 != null) {
return receiptHeader1.getId();
}
receiptHeader.setId(null);
receiptHeader.setType(receiptType);
receiptHeader.setWarehouseId(ShiroUtils.getWarehouseId());
receiptHeader.setWarehouseCode(ShiroUtils.getWarehouseCode());
receiptHeader.setCreated(null);
receiptHeader.setCreatedBy(ShiroUtils.getLoginName());
receiptHeader.setLastUpdated(null);
receiptHeader.setLastUpdatedBy(ShiroUtils.getLoginName());
receiptHeader.setUploadStatus(0);
receiptHeader.setFirstStatus((short) 200);
receiptHeader.setLastStatus((short) 200);
receiptHeader.setCompanyId(Integer.parseInt(companyId)); //货主Id
receiptHeader.setCompanyCode(companyCode);
receiptHeader.setSupplierCode("CS0002");
this.insert(receiptHeader);
return receiptHeader.getId();
}
@Override
public ReceiptHeader selectLastOne() {
ReceiptHeader receiptHeader = receiptHeaderMapper.selectLastOne();
return receiptHeader;
}
@Override
public ReceiptHeader getReceipt(ReceiptHeader receiptHeader) {
ReceiptHeader receipt = receiptHeaderMapper.getReceipt(receiptHeader);
return receipt;
}
@Override
public ReceiptHeader selectNosScanSSP(String code) {
return receiptHeaderMapper.selectNosScanSSP(code);
}
@Override
@Transactional
public AjaxResult<Integer> deleteHeaderAndDetail(Integer id) {
ReceiptHeader receiptHeader = this.selectEntityById(id);
if (receiptHeader == null) return AjaxResult.success("成功!");
ReceiptDetail condition = new ReceiptDetail();
condition.setReceiptCode(receiptHeader.getCode());
if (receiptHeader.getFirstStatus() < 100)
{
this.deleteById(id);
receiptDetailService.deleteByCondition(condition);
return AjaxResult.success("成功删除!");
}
else if (receiptHeader.getFirstStatus() < 120)
{
ReceiptHeader headerRecord = new ReceiptHeader();
headerRecord.setId(id);
headerRecord.setDeleted(true);
headerRecord.setLastUpdatedBy(ShiroUtils.getLoginName());
this.updateByModel(headerRecord);
ReceiptDetail detailRecord = new ReceiptDetail();
detailRecord.setDeleted(true);
detailRecord.setLastUpdatedBy(ShiroUtils.getLoginName());
receiptDetailService.updateByCondition(detailRecord, condition);
return AjaxResult.success("成功删除!");
}
else
{
return AjaxResult.error("单据("+ receiptHeader.getCode() +")状态超过120已经不能删除");
}
}
@Override
public AjaxResult<Integer> checkStatus(Integer headerId, Short status){
ReceiptHeader receiptHeader = this.selectEntityById(headerId);
if (receiptHeader == null)
{
throw new ServiceException("数据错误,没有表头!");
}
else if (receiptHeader.getFirstStatus() > status)
{
throw new ServiceException("单据状态超过" + status + "已经不可修改!");
}
else
{
return AjaxResult.success("");
}
}
@Override
public AjaxResult<Integer> checkStatus(String receiptCode, Short status) {
ReceiptHeader condition = new ReceiptHeader();
condition.setCode(receiptCode);
List<ReceiptHeader> receiptHeaders = this.selectListEntityByEqual(condition);
if (receiptHeaders.size() < 1)
{
throw new ServiceException("数据错误,没有表头!");
}
else if (receiptHeaders.get(0).getFirstStatus() > status)
{
throw new ServiceException("单据状态超过" + status + "已经不可修改!");
}
else
{
return AjaxResult.success("");
}
}
/**
* 修改单据状态
* @param receiptId
* @param firstStatus
*/
@Override
public void receiptStatusUpdate(Integer receiptId, Short firstStatus) {
Short lastStatus = receiptHeaderMapper.getLastStatus(receiptId);
receiptHeaderMapper.updateHeaderStatus(receiptId, firstStatus, lastStatus);
}
@Override
public void updateDetailStatus(Integer receiptDetailId, Short status) {
receiptHeaderMapper.updateDetailStatus(receiptDetailId, status);
}
@Override
public AjaxResult receive(String code)
{
AjaxResult ajaxResult=new AjaxResult();
String result=null;
ReceiptDetail receiptDetail=new ReceiptDetail();
receiptDetail.setReceiptCode(code);
HashSet<String> set=new HashSet();
List<ReceiptDetail> list=receiptDetailService.selectListEntityByEqual(receiptDetail);
if(list.size()==0){
ajaxResult.setCode(200);
}else {
for (ReceiptDetail item : list) {
String zc = item.getZoneCode();
if (zc == null) {
zc = "";
}
set.add(zc);
}
if (set.size() == 1 && set.stream().anyMatch(X->X.equals("AGV"))) {
ajaxResult.setCode(300);
}
if (!set.stream().anyMatch(X->X.equals("AGV"))) {
ajaxResult.setCode(200);
}
if (set.size() > 1 && set.stream().anyMatch(X->X.equals("AGV"))) {
ajaxResult.setCode(400);
}
}
if (set.stream().anyMatch(X->X.equals("QG"))) {
ReceiptHeader item = this.selectNosScanSSP(code);
if (item != null ){
AjaxResult ajaxResults=orderAssignApiService.receiptAssign(code);
if(!ajaxResults.hasErr()){
ajaxResult.setMsg("单据下发成功");
}
}else {
ajaxResult.setMsg("单据已下发");
}
}
if (set.stream().anyMatch(X->X.equals(""))) {
ajaxResult.setCode(500);
ajaxResult.setMsg("请先分配库区");
}
return ajaxResult;
}
@Override
public List<ReceiptHeader> selectListByCreated() {
return receiptHeaderMapper.selectListByCreated();
}
}