ShipmentHeaderServiceImpl.java
4.88 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
package com.huaheng.pc.shipment.shipmentHeader.service;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.shipment.shipmentContainerHeader.service.ShipmentContainerHeaderService;
import com.huaheng.pc.shipment.shipmentDetail.service.ShipmentDetailService;
import com.huaheng.pc.system.dict.service.IDictDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaheng.pc.shipment.shipmentHeader.domain.ShipmentHeader;
import com.huaheng.pc.shipment.shipmentHeader.mapper.ShipmentHeaderMapper;
import com.huaheng.pc.shipment.shipmentHeader.service.ShipmentHeaderService;
@Service
public class ShipmentHeaderServiceImpl extends ServiceImpl<ShipmentHeaderMapper, ShipmentHeader> implements ShipmentHeaderService{
@Autowired
private IDictDataService dictDataService;
@Resource
private ShipmentHeaderMapper shipmentHeaderMapper;
@Autowired
private ShipmentDetailService shipmentDetailService;
@Autowired
private ShipmentContainerHeaderService shipmentContainerHeaderService;
//新增出库主单
@Override
public AjaxResult<Boolean> saveHeader(ShipmentHeader shipmentHeader) {
if(dictDataService.checkConfig("shipmentType", shipmentHeader.getShipmentType()) == false)
{
return AjaxResult.error("没有对应的出库单类型");
}
String code = createCode(shipmentHeader.getShipmentType());
shipmentHeader.setId(null);
shipmentHeader.setFirstStatus(0);
shipmentHeader.setLastStatus(0);
shipmentHeader.setLastUpdated(null);
shipmentHeader.setLastUpdatedBy(ShiroUtils.getLoginName());
shipmentHeader.setCreated(null);
shipmentHeader.setCreatedBy(ShiroUtils.getLoginName());
shipmentHeader.setWarehouseCode(ShiroUtils.getWarehouseCode());
shipmentHeader.setCode(code);
boolean result = this.save(shipmentHeader);
return AjaxResult.toAjax(result);
}
//根据单据类型建单据号
public String createCode(String shipmentType)
{
String code = null;
Date now = new Date();
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
String maxCode = shipmentHeaderMapper.createCode(shipmentType);
if (maxCode != null && maxCode.length() > 13 && 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 code;
}
/**
* 根据Id更新这个单据的首尾状态
* @param shipmentId
* @return
*/
@Override
public AjaxResult updateShipmentStatus(int shipmentId) {
//获取这个单
ShipmentHeader shipmentHeader = this.getById(shipmentId);
if(shipmentHeader==null){
return AjaxResult.error("单据未找到,Id:"+shipmentId);
}
//查询是否有生成出库货箱,如果有,则返回出库货箱的最高与最低状态
Map<String,Integer> map = shipmentContainerHeaderService.getShipmentContainerMaxAndMinStatusByShipmentID(shipmentId);
if(map==null){
//说明没有货箱,则直接首位均为新建
shipmentHeader.setFirstStatus(0);
shipmentHeader.setLastStatus(0);
this.saveOrUpdate(shipmentHeader);
}else {
int firstStatus = map.get("maxStatus");
int lastStatus = map.get("minStatus");
if(firstStatus<20){
shipmentHeader.setFirstStatus(200);
}
if(firstStatus==20){
shipmentHeader.setFirstStatus(300);
}
if(firstStatus==30){
shipmentHeader.setFirstStatus(500);
}
if(lastStatus<20){
shipmentHeader.setLastStatus(200);
}
if(lastStatus==20){
shipmentHeader.setLastStatus(300);
}
if(lastStatus==30){
shipmentHeader.setLastStatus(500);
}
//是否存在未配盘的数量,如果是,则尾状态为新建
Integer UnCompleted = shipmentDetailService.countUnCompleted(shipmentId);
if(UnCompleted != null && UnCompleted.intValue() > 0){
shipmentHeader.setLastStatus(0);
}
this.saveOrUpdate(shipmentHeader);
}
return AjaxResult.success("");
}
}