UniqueLotService.java
7.04 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
package com.huaheng.pc.sap.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.DateUtils;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.sap.domain.UniqueLot;
import com.huaheng.pc.sap.mapper.UniqueLotMapper;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Service
public class UniqueLotService extends ServiceImpl<UniqueLotMapper, UniqueLot> {
@Resource
private UniqueLotMapper mapper;
/**
* 包含
*/
public boolean isContain(String uniqLot){
UniqueLot uniqueLot = this.getOne(new LambdaQueryWrapper<UniqueLot>()
.eq(UniqueLot::getUniqLot, uniqLot)
.ne(UniqueLot::getStatus, QuantityConstant.UNIQUE_STATUS_CLOSE)
.last("LIMIT 1"));
if(StringUtils.isNull(uniqueLot)){
return false;
}
return true;
}
public UniqueLot getUniqueLot(String uniqLot){
UniqueLot uniqueLot = this.getOne(new LambdaQueryWrapper<UniqueLot>()
.eq(UniqueLot::getUniqLot, uniqLot)
.orderByDesc(UniqueLot::getCreated)
.last("LIMIT 1"));
return uniqueLot;
}
public UniqueLot getUniqueLotByContainerCode(String containerCode){
UniqueLot uniqueLot = this.getOne(new LambdaQueryWrapper<UniqueLot>()
.eq(UniqueLot::getContainerCode, containerCode)
.in(UniqueLot::getStatus,QuantityConstant.UNIQUE_STATUS_LOCK,QuantityConstant.UNIQUE_STATUS_OPEN)
.orderByDesc(UniqueLot::getCreated)
.last("LIMIT 1"));
return uniqueLot;
}
/**
* 是否绑定 绑定后不可进行组盘
*/
public boolean isBind(String uniqLot,String containerCode){
UniqueLot uniqueLot = new UniqueLot();
uniqueLot.setUniqLot(uniqLot);
uniqueLot.setContainerCode(containerCode);
return isBind(uniqueLot);
}
/**
* 是否绑定 绑定后不可进行组盘
*/
public boolean isBind(UniqueLot uniqueLot){
if(StringUtils.isNull(uniqueLot)){
throw new ServiceException("isBind : uniqueLot不能为null");
}
String containerCode = uniqueLot.getContainerCode();
String uniqLot = uniqueLot.getUniqLot();
UniqueLot uniqueLot1 = getUniqueLot(uniqLot);
if(StringUtils.isNull(uniqueLot)){
throw new ServiceException("isBind : uniqueLot不能为null");
}
String status = uniqueLot1.getStatus();
String bindContainerCode = uniqueLot1.getContainerCode();
if(!bindContainerCode.equals(containerCode)){
throw new ServiceException("isBind : 唯一批号["+uniqLot+"]已组盘【"+bindContainerCode+"】容器");
}
if(QuantityConstant.UNIQUE_STATUS_LOCK.equals(status)){
return true;
}
return false;
}
/**
* 是否绑定 绑定后不可进行组盘
*/
public boolean unBind(UniqueLot uniqueLot){
if(StringUtils.isNull(uniqueLot)){
throw new ServiceException("isBind : uniqueLot不能为null");
}
String status = uniqueLot.getStatus();
if(StringUtils.isEmpty(status)){
throw new ServiceException("isBind : status不能为空");
}
if(QuantityConstant.UNIQUE_STATUS_LOCK.equals(status)){
return true;
}
return false;
}
/**
* 解绑
*/
public AjaxResult unBind(String uniqLot){
if(StringUtils.isEmpty(uniqLot)){
throw new ServiceException("unBind : uniqLot不能为空");
}
UniqueLot uniqueLot = getUniqueLot(uniqLot);
uniqueLot.setStatus(QuantityConstant.UNIQUE_STATUS_OPEN);
boolean b = this.updateById(uniqueLot);
return AjaxResult.toAjax(b);
}
/**
* 解绑
*/
public AjaxResult removeUniqLot(String uniqLot){
UniqueLot uniqueLot = getUniqueLot(uniqLot);
String status1 = uniqueLot.getStatus();
if(QuantityConstant.UNIQUE_STATUS_OPEN.equals(status1)){
this.removeById(uniqueLot.getId());
return AjaxResult.success();
}
return AjaxResult.error(uniqueLot.getUniqLot()+" 状态 "+status1+" 不可删除");
}
/**
*
* @param uniqueLot
* @return
*/
public AjaxResult bindContainer(UniqueLot uniqueLot){
if(StringUtils.isNull(uniqueLot)){
return AjaxResult.error("绑定对象不能为null");
}
String containerCode = uniqueLot.getContainerCode();
String uniqLot = uniqueLot.getUniqLot();
if(StringUtils.isEmpty(containerCode)){
return AjaxResult.error("bindContainer : containerCode 不能为空");
}
if(StringUtils.isEmpty(uniqLot)){
return AjaxResult.error("bindContainer : uniqLot 不能为空");
}
uniqueLot.setStatus(QuantityConstant.UNIQUE_STATUS_LOCK);
uniqueLot.setLastUpdatedBy(ShiroUtils.getLoginName());
uniqueLot.setLastUpdated(DateUtils.getNowDate());
boolean b = this.updateById(uniqueLot);
return AjaxResult.toAjax(b);
}
/**
*
* @return
*/
public AjaxResult writeContainer(String uniqLot,String containerCode){
if(StringUtils.isEmpty(uniqLot)){
return AjaxResult.error("writeContainer : uniqLot不能未空");
}
UniqueLot uniqueLot = getUniqueLot(uniqLot);
if(uniqueLot==null){
uniqueLot = new UniqueLot();
uniqueLot.setUniqLot(uniqLot);
uniqueLot.setContainerCode(containerCode);
}else{
if(!QuantityConstant.UNIQUE_STATUS_OPEN.equals(uniqueLot.getStatus())){
return AjaxResult.error("uniqLot【"+uniqueLot.getUniqLot()+"】已经绑定托盘 "+uniqueLot.getContainerCode()+" 。");
}
}
return writeContainer(uniqueLot);
}
/**
*
* @param uniqueLot
* @return
*/
public AjaxResult writeContainer(UniqueLot uniqueLot){
if(StringUtils.isNull(uniqueLot)){
return AjaxResult.error("绑定对象不能为null");
}
String containerCode = uniqueLot.getContainerCode();
String uniqLot = uniqueLot.getUniqLot();
if(StringUtils.isEmpty(containerCode)){
return AjaxResult.error("writeContainer : containerCode 不能为空");
}
if(StringUtils.isEmpty(uniqLot)){
return AjaxResult.error("writeContainer : uniqLot 不能为空");
}
uniqueLot.setStatus(QuantityConstant.UNIQUE_STATUS_OPEN);
uniqueLot.setCreatedBy(ShiroUtils.getLoginName());
boolean save = this.saveOrUpdate(uniqueLot);
return AjaxResult.toAjax(save);
}
}