ReceiptContainerDetailServiceImpl.java
9.31 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
package com.huaheng.pc.receipt.receiptContainerDetail.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
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.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.mobile.receipt.ReceiptBill;
import com.huaheng.pc.config.material.domain.Material;
import com.huaheng.pc.config.material.service.MaterialService;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.receipt.receiptContainerDetail.domain.ReceiptContainerDetail;
import com.huaheng.pc.receipt.receiptContainerDetail.mapper.ReceiptContainerDetailMapper;
import com.huaheng.pc.receipt.receiptContainerHeader.domain.ReceiptContainerHeader;
import com.huaheng.pc.receipt.receiptContainerHeader.service.ReceiptContainerHeaderService;
import com.huaheng.pc.receipt.receiptDetail.domain.ReceiptDetail;
import com.huaheng.pc.receipt.receiptDetail.service.ReceiptDetailService;
import com.huaheng.pc.receipt.receiptHeader.domain.ReceiptHeader;
import com.huaheng.pc.receipt.receiptHeader.service.ReceiptHeaderService;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import com.huaheng.pc.receipt.receiptContainerHeader.domain.ReceiptContainerHeader;
import com.huaheng.pc.receipt.receiptContainerHeader.service.ReceiptContainerHeaderService;
import com.huaheng.pc.receipt.receiptDetail.domain.ReceiptDetail;
import com.huaheng.pc.receipt.receiptDetail.service.ReceiptDetailService;
import com.huaheng.pc.receipt.receiptHeader.domain.ReceiptHeader;
import com.huaheng.pc.receipt.receiptHeader.service.ReceiptHeaderService;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
@Service
public class ReceiptContainerDetailServiceImpl extends ServiceImpl<ReceiptContainerDetailMapper, ReceiptContainerDetail> implements ReceiptContainerDetailService{
@Resource
private ReceiptDetailService receiptDetailService;
@Resource
private ReceiptHeaderService receiptHeaderService;
@Resource
private ReceiptContainerHeaderService receiptContainerHeaderService;
@Resource
private MaterialService materialService;
/**
* 根据入库单编码查询入库组盘明细
* @param receiptCode 入库单编码
* @return AjaxResult
*/
@Override
public AjaxResult<List<Map<String, Object>>> getReceiptInfoByBill(String receiptCode) {
LambdaQueryWrapper<ReceiptContainerDetail> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(ReceiptContainerDetail::getReceiptCode, receiptCode)
.eq(ReceiptContainerDetail::getWarehouseCode, ShiroUtils.getWarehouseCode());
List<Map<String, Object>> detail = this.listMaps(lambdaQueryWrapper);
return AjaxResult.success(detail);
}
/**
* 撤销入库组盘明细
* @param idList
* @return
*/
@Override
public Boolean detailRemove(List<Integer> idList) {
for (Integer id : idList){
ReceiptContainerDetail receiptContainerDetail = this.getById(id);
//如果已生成任务不允许撤销
if (receiptContainerDetail.getStatus() < QuantityConstant.RECEIPT_CONTAINER_TASK){
//回滚入库单明细收货数量
ReceiptDetail receiptDetail = receiptDetailService.getById(receiptContainerDetail.getReceiptDetailId());
receiptDetail.setOpenQty(receiptDetail.getOpenQty().subtract(receiptContainerDetail.getQty()));
//如果为临时容器,则删除
receiptContainerDetail.getContainerCode();
if (!receiptDetailService.updateById(receiptDetail)){throw new SecurityException("回滚入库单明细失败");}
//删除组盘明细
if (!this.removeById(id)){ throw new ServiceException("回滚入库组盘失败");}
LambdaQueryWrapper<ReceiptContainerDetail> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(ReceiptContainerDetail::getReceiptContainerId, receiptContainerDetail.getReceiptContainerId());
List<ReceiptContainerDetail> list = this.list(lambdaQueryWrapper);
if (list.size() == 0){
if (!receiptContainerHeaderService.removeById(receiptContainerDetail.getReceiptContainerId())){
throw new ServiceException("删除入库组盘头失败");
}
}
//查询入库头表
LambdaQueryWrapper<ReceiptContainerDetail> containerDetailLambda = Wrappers.lambdaQuery();
containerDetailLambda.eq(ReceiptContainerDetail::getReceiptId, receiptContainerDetail.getReceiptId());
List<ReceiptContainerDetail> containerDetailList = this.list(containerDetailLambda);
//如果入库组盘没有该入库单的组盘信息,回滚入库单状态
if (containerDetailList.size() == 0){
ReceiptHeader receiptHeader = new ReceiptHeader();
receiptHeader.setId(receiptContainerDetail.getReceiptId());
receiptHeader.setFirstStatus(QuantityConstant.RECEIPT_HEADER_RECEIVING);
receiptHeader.setLastStatus(QuantityConstant.RECEIPT_HEADER_RECEIVING);
receiptHeader.setLastUpdatedBy(ShiroUtils.getLoginName());
if (!receiptHeaderService.updateById(receiptHeader)){ throw new ServiceException("回滚头表状态失败"); }
}
} else {
throw new SecurityException("已生成任务,不允许取消");
}
}
return true;
}
// /**
// * 移动端收货
// *
// * @param code
// * @return
// */
// @Override
// public AjaxResult scanReceiptCode(String code) {
// LambdaQueryWrapper<ReceiptDetail> lambdaQueryWrapper = Wrappers.lambdaQuery();
// lambdaQueryWrapper.eq(ReceiptDetail::getReceiptCode, code);
// List<ReceiptDetail> receiptContainerDetails = list(lambdaQueryWrapper);
// return AjaxResult.success(receiptContainerDetails);
// }
/**保存到组盘详细*/
@Override
public List<Integer> insertTodayReceiptcContainerDetail(int headerId, int receiptId, List<Integer> receiptDetailId, List<ReceiptBill> receiptBills) {
List<Integer> mReceiptContainerIds = new ArrayList<>();
ReceiptHeader receiptHeader = receiptHeaderService.getById(receiptId);
if(receiptHeader == null) {
throw new ServiceException("没有找到入库单表头!");
}
for(int i=0; i<receiptBills.size(); i++) {
ReceiptBill receiptBill = receiptBills.get(i);
Material condition2 = new Material();
condition2.setCode(receiptBill.getMaterialCode());
condition2.setWarehouseCode(ShiroUtils.getWarehouseCode());
condition2.setDeleted(false);
condition2.setEnable(true);
LambdaQueryWrapper<Material> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(Material::getCode, receiptBill.getMaterialCode())
.eq(Material::getWarehouseCode, ShiroUtils.getWarehouseCode());
Material material = materialService.getOne(lambdaQueryWrapper);
ReceiptContainerDetail record = new ReceiptContainerDetail();
record.setReceiptContainerId(headerId);
record.setReceiptCode(receiptHeader.getCode());
record.setReceiptId(receiptId);
record.setReceiptDetailId(receiptDetailId.get(i));
record.setMaterialCode(receiptBill.getMaterialCode());
record.setMaterialName(material.getName());
record.setMaterialSpec(material.getSpec());
record.setQty(receiptBill.getQty());
record.setContainerCode(receiptBills.get(0).getReceiptContainerCode());
if(receiptBill.getWeight() != null) {
record.setWeight(receiptBill.getWeight());
}
record.setCreatedBy(ShiroUtils.getLoginName());
record.setLastUpdatedBy(ShiroUtils.getLoginName());
LambdaQueryWrapper<ReceiptContainerDetail> detailyWrapper = Wrappers.lambdaQuery();
detailyWrapper.eq(ReceiptContainerDetail::getReceiptContainerId, headerId)
.eq(ReceiptContainerDetail::getReceiptCode, receiptHeader.getCode());
ReceiptContainerDetail receiptContainerDetail = getOne(detailyWrapper);
if(receiptContainerDetail == null) {
save(record);
mReceiptContainerIds.add(record.getId());
} else {
mReceiptContainerIds.add(receiptContainerDetail.getId());
}
}
return mReceiptContainerIds;
}
}