Commit 3469e7172b4c2fc8517bdbdd5d1af85040901732
1 parent
1a713452
调整单,调整单逻辑详细重新整理
Showing
2 changed files
with
161 additions
and
16 deletions
src/main/java/com/huaheng/pc/inventory/adjustDetail/controller/adjustDetailController.java
... | ... | @@ -100,7 +100,9 @@ public class adjustDetailController extends BaseController { |
100 | 100 | } |
101 | 101 | |
102 | 102 | /** |
103 | - * 调整数量 | |
103 | + * 调整, | |
104 | + * 调整数量,调整库存状态 | |
105 | + * 调整插入库存 | |
104 | 106 | */ |
105 | 107 | //@RequiresPermissions("inventory:cyclecountAdjustDetail:addAdjust") |
106 | 108 | @Log(title = "库存-调整单", operating = "调整单调整库存差异,调整数量", action = BusinessType.UPDATE) |
... | ... |
src/main/java/com/huaheng/pc/inventory/adjustDetail/service/AdjustDetailServiceImpl.java
... | ... | @@ -2,9 +2,11 @@ package com.huaheng.pc.inventory.adjustDetail.service; |
2 | 2 | |
3 | 3 | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
4 | 4 | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
5 | +import com.huaheng.common.utils.StringUtils; | |
5 | 6 | import com.huaheng.common.utils.security.ShiroUtils; |
6 | 7 | import com.huaheng.framework.web.domain.AjaxResult; |
7 | 8 | import com.huaheng.pc.config.container.service.ContainerService; |
9 | +import com.huaheng.pc.config.location.domain.Location; | |
8 | 10 | import com.huaheng.pc.config.location.service.LocationService; |
9 | 11 | import com.huaheng.pc.inventory.adjustHeader.domain.AdjustHeader; |
10 | 12 | import com.huaheng.pc.inventory.adjustHeader.service.AdjustHeaderService; |
... | ... | @@ -58,25 +60,80 @@ public class AdjustDetailServiceImpl extends ServiceImpl<AdjustDetailMapper, Adj |
58 | 60 | |
59 | 61 | |
60 | 62 | /** |
61 | - * 调整库存数量 | |
63 | + * 调整库存 | |
64 | + * 调整数量,调整库存状态 | |
65 | + * 调整插入库存 | |
62 | 66 | * @param adjustDetail |
63 | 67 | * @return |
64 | 68 | */ |
65 | 69 | @Transactional |
66 | 70 | @Override |
67 | 71 | public AjaxResult updateAdjustDetail(AdjustDetail adjustDetail) { |
68 | - /*修改库存数量,调整单据状态,写入库存交易*/ | |
69 | 72 | |
70 | - //已调整过不允许修改。 | |
71 | 73 | if(adjustDetail.getStatus() == 1){ |
72 | 74 | AjaxResult.error("该单据已调整,不允许再次调整!" ); |
73 | 75 | } |
74 | 76 | //查询调整的库存明细 |
75 | - InventoryDetail inventoryDetail = inventoryDetailService.getById(adjustDetail.getInventoryDetailId()); | |
77 | + InventoryDetail inventoryDetail = new InventoryDetail(); | |
78 | + //调整单中不带库存明细时不查询 | |
79 | + if(adjustDetail.getInventoryDetailId() != null) { | |
80 | + inventoryDetail = inventoryDetailService.getById(adjustDetail.getInventoryDetailId()); | |
81 | + //验证该条库存是不是正在使用,通过库位是否锁定来判断 | |
82 | + if (!adjustDetail.getLocationCode().equals(inventoryDetail.getLocationCode()) || | |
83 | + !adjustDetail.getContainerCode().equals(inventoryDetail.getContainerCode())) { | |
84 | + throw new SecurityException("调整单和所调整库存的库位容器不符,前检查数据"); | |
85 | + } | |
86 | + Location location = new Location(); | |
87 | + location.setCode(inventoryDetail.getLocationCode()); | |
88 | + location.setWarehouseCode(inventoryDetail.getWarehouseCode()); | |
89 | + LambdaQueryWrapper<Location> lambdaQueryWrapper = Wrappers.lambdaQuery(location); | |
90 | + location = locationService.getOne(lambdaQueryWrapper); | |
91 | + if (!location.getStatus().equals("empty")) { | |
92 | + throw new SecurityException(inventoryDetail.getId() + "库存非空闲,请等待任务完成再进行调整!"); | |
93 | + } | |
94 | + | |
95 | + //判断调整哪一个属性值 | |
96 | + /*以下方法有待验证讨论,BigDecimal传入null,如何避免传入0?*/ | |
97 | + | |
98 | + //把BigDecimal类型转换成String再判断null | |
99 | + | |
100 | + String toQtyString = adjustDetail.getToQty().toString(); //调整后库存 | |
101 | + String gapQtyString = adjustDetail.getGapQty().toString(); //调整变动数量 | |
102 | + if (StringUtils.isNotEmpty(toQtyString) || StringUtils.isNotEmpty(gapQtyString)) { | |
103 | + //调整数量 | |
104 | + updateAdjustDetailNumber(adjustDetail, inventoryDetail); | |
105 | + } | |
106 | + if (StringUtils.isNotEmpty(adjustDetail.getFromInventorySts()) && StringUtils.isNotEmpty(adjustDetail.getToInventorySts())) { | |
107 | + //调整库存状态 | |
108 | + updateAdjustDetailState(adjustDetail, inventoryDetail); | |
109 | + } | |
110 | + } | |
111 | + String fromQtyString = adjustDetail.getFromQty().toString(); //调整前库存数量 | |
112 | + if(StringUtils.isNotEmpty(fromQtyString)){ | |
113 | + //调整插入库存 | |
114 | + updateAdjustDetailInsert(adjustDetail); | |
115 | + } | |
116 | + | |
117 | + //修改调整单明细状态 | |
118 | + adjustDetail.setStatus(1); | |
119 | + adjustDetail.setLastUpdatedBy(ShiroUtils.getLoginName()); | |
120 | + adjustDetail.setLastUpdated(new Date()); | |
121 | + this.saveOrUpdate(adjustDetail); | |
122 | + | |
123 | + return AjaxResult.success("调整库存成功!"); | |
124 | + } | |
125 | + | |
126 | + /** | |
127 | + * 调整修改库存数量 | |
128 | + * @param adjustDetail | |
129 | + */ | |
130 | + @Transactional | |
131 | + public void updateAdjustDetailNumber (AdjustDetail adjustDetail,InventoryDetail inventoryDetail){ | |
132 | + /*修改库存数量,调整单据状态,写入库存交易*/ | |
133 | + | |
76 | 134 | /*调整后的数量写入库存*/ |
77 | 135 | //比较大小可以用 .compareTo()返回值 -1 小于 0 等于 1 大于 |
78 | 136 | //Bigdecimal 自带运算方法.add加法 .subtract减法 |
79 | - | |
80 | 137 | if(adjustDetail.getToQty().compareTo(BigDecimal.ZERO) == 0){ |
81 | 138 | //当调整后数量为0时,直接删除该条库存,并写入库存交易 |
82 | 139 | //删除库存,并查询当前库位还有没有其他物料,没有则删除库存头,恢复容器和库位状态 |
... | ... | @@ -87,13 +144,13 @@ public class AdjustDetailServiceImpl extends ServiceImpl<AdjustDetailMapper, Adj |
87 | 144 | LambdaQueryWrapper<InventoryDetail> lamdDetail = Wrappers.lambdaQuery(inv); |
88 | 145 | List<InventoryDetail> inventoryDetailList = inventoryDetailService.list(lamdDetail); |
89 | 146 | inventoryDetailService.removeById(adjustDetail.getInventoryDetailId());//删除实际库存数量为0的库存明细 |
90 | - if(inventoryDetailList.size() == 0){ | |
147 | + if(inventoryDetailList.size() == 0){ | |
91 | 148 | //恢复库位和容器状态,删除库存头 |
92 | 149 | inventoryHeaderService.removeById(inventoryDetail.getInventoryHeaderId()); |
93 | 150 | locationService.updateContainerCodeAndStatus(inventoryDetail.getLocationCode(),"","empty"); |
94 | 151 | containerService.updateLocationCodeAndStatus(inventoryDetail.getContainerCode(),"","empty"); |
95 | - } | |
96 | - }else{ | |
152 | + } | |
153 | + }else{ | |
97 | 154 | //修改库存 |
98 | 155 | //BigDecimal temp =(adjustDetail.getFromQty()).add(adjustDetail.getGapQty()); |
99 | 156 | inventoryDetail.setQty(adjustDetail.getToQty());//调整后的数量 |
... | ... | @@ -113,7 +170,7 @@ public class AdjustDetailServiceImpl extends ServiceImpl<AdjustDetailMapper, Adj |
113 | 170 | inventoryTransaction.setMaterialName(inventoryDetail.getMaterialName()); |
114 | 171 | inventoryTransaction.setMaterialSpec(inventoryDetail.getMaterialSpec()); |
115 | 172 | inventoryTransaction.setMaterialUnit(inventoryDetail.getMaterialUnit()); |
116 | - inventoryTransaction.setTaskQty(inventoryDetail.getTaskQty()); | |
173 | + inventoryTransaction.setTaskQty(adjustDetail.getGapQty()); | |
117 | 174 | inventoryTransaction.setInventorySts(inventoryDetail.getInventorySts()); |
118 | 175 | inventoryTransaction.setReferCode(inventoryDetail.getReferCode()); |
119 | 176 | inventoryTransaction.setReferDetailId(inventoryDetail.getReferDetailId()); |
... | ... | @@ -142,15 +199,100 @@ public class AdjustDetailServiceImpl extends ServiceImpl<AdjustDetailMapper, Adj |
142 | 199 | inventoryTransaction.setSupplierCode(inventoryDetail.getSupplierCode()); |
143 | 200 | inventoryTransactionService.saveOrUpdate(inventoryTransaction); |
144 | 201 | |
145 | - //修改调整单明细状态 | |
146 | - adjustDetail.setStatus(1); | |
147 | - adjustDetail.setLastUpdatedBy(ShiroUtils.getLoginName()); | |
148 | - adjustDetail.setLastUpdated(new Date()); | |
149 | - this.saveOrUpdate(adjustDetail); | |
202 | + } | |
203 | + | |
204 | + /** | |
205 | + * 调整库存属性 | |
206 | + * @param adjustDetail | |
207 | + */ | |
208 | + @Transactional | |
209 | + public void updateAdjustDetailState (AdjustDetail adjustDetail,InventoryDetail inventoryDetail) { | |
210 | + /*不考虑其他只改变库存状态即可,也需要写入库存交易。*/ | |
211 | + | |
212 | + //修改库存的状态 | |
213 | + inventoryDetail.setInventorySts(adjustDetail.getToInventorySts());//修改为调整库存 | |
214 | + inventoryDetail.setLastUpdatedBy(ShiroUtils.getLoginName()); | |
215 | + inventoryDetail.setLastUpdated(new Date()); | |
216 | + inventoryDetailService.saveOrUpdate(inventoryDetail); | |
217 | + | |
218 | + //写入库存交易,库存交易2条一条出,一条入 | |
219 | + //调整出 | |
220 | + InventoryTransaction inventoryTransaction = new InventoryTransaction(); | |
221 | + inventoryTransaction.setWarehouseCode(inventoryDetail.getWarehouseCode()); | |
222 | + inventoryTransaction.setCompanyCode(inventoryDetail.getCompanyCode()); | |
223 | + inventoryTransaction.setLocationCode(inventoryDetail.getLocationCode()); | |
224 | + inventoryTransaction.setContainerCode(inventoryDetail.getContainerCode()); | |
225 | + inventoryTransaction.setTransactionType(40); | |
226 | + inventoryTransaction.setMaterialCode(inventoryDetail.getMaterialCode()); | |
227 | + inventoryTransaction.setMaterialName(inventoryDetail.getMaterialName()); | |
228 | + inventoryTransaction.setMaterialSpec(inventoryDetail.getMaterialSpec()); | |
229 | + inventoryTransaction.setMaterialUnit(inventoryDetail.getMaterialUnit()); | |
230 | + inventoryTransaction.setTaskQty(null);//数量不变 | |
231 | + inventoryTransaction.setInventorySts(adjustDetail.getFromInventorySts());//状态 | |
232 | + inventoryTransaction.setReferCode(inventoryDetail.getReferCode()); | |
233 | + inventoryTransaction.setReferDetailId(inventoryDetail.getReferDetailId()); | |
234 | + inventoryTransaction.setBatch(inventoryDetail.getBatch()); | |
235 | + inventoryTransaction.setLot(inventoryDetail.getLot()); | |
236 | + inventoryTransaction.setProjectNo(inventoryDetail.getProjectNo()); | |
237 | + inventoryTransaction.setQcCheck(inventoryDetail.getQcCheck()); | |
238 | + inventoryTransaction.setWeight(inventoryDetail.getWeight()); | |
239 | + inventoryTransaction.setManufactureDate(inventoryDetail.getManufactureDate()); | |
240 | + inventoryTransaction.setExpirationDate(inventoryDetail.getExpirationDate()); | |
241 | + inventoryTransaction.setAgingDate(inventoryDetail.getCreated()); | |
242 | + inventoryTransaction.setAttributeId(inventoryDetail.getAttributeId()); | |
243 | + inventoryTransaction.setAttribute1(inventoryDetail.getAttribute1()); | |
244 | + inventoryTransaction.setAttribute2(inventoryDetail.getAttribute2()); | |
245 | + inventoryTransaction.setAttribute3(inventoryDetail.getAttribute3()); | |
246 | + inventoryTransaction.setCreated(new Date()); | |
247 | + inventoryTransaction.setCreatedBy(ShiroUtils.getLoginName()); | |
248 | + inventoryTransaction.setBillDetailId(inventoryDetail.getReceiptDetailId()); | |
249 | + inventoryTransaction.setSupplierCode(inventoryDetail.getSupplierCode()); | |
250 | + inventoryTransactionService.saveOrUpdate(inventoryTransaction); | |
251 | + | |
252 | + //调整入 | |
253 | + InventoryTransaction inventoryTransaction2 = new InventoryTransaction(); | |
254 | + inventoryTransaction2.setWarehouseCode(inventoryDetail.getWarehouseCode()); | |
255 | + inventoryTransaction2.setCompanyCode(inventoryDetail.getCompanyCode()); | |
256 | + inventoryTransaction2.setLocationCode(inventoryDetail.getLocationCode()); | |
257 | + inventoryTransaction2.setContainerCode(inventoryDetail.getContainerCode()); | |
258 | + inventoryTransaction2.setTransactionType(30); | |
259 | + inventoryTransaction2.setMaterialCode(inventoryDetail.getMaterialCode()); | |
260 | + inventoryTransaction2.setMaterialName(inventoryDetail.getMaterialName()); | |
261 | + inventoryTransaction2.setMaterialSpec(inventoryDetail.getMaterialSpec()); | |
262 | + inventoryTransaction2.setMaterialUnit(inventoryDetail.getMaterialUnit()); | |
263 | + inventoryTransaction2.setTaskQty(null);//数量不变 | |
264 | + inventoryTransaction2.setInventorySts(inventoryDetail.getInventorySts());//状态 | |
265 | + inventoryTransaction2.setReferCode(inventoryDetail.getReferCode()); | |
266 | + inventoryTransaction2.setReferDetailId(inventoryDetail.getReferDetailId()); | |
267 | + inventoryTransaction2.setBatch(inventoryDetail.getBatch()); | |
268 | + inventoryTransaction2.setLot(inventoryDetail.getLot()); | |
269 | + inventoryTransaction2.setProjectNo(inventoryDetail.getProjectNo()); | |
270 | + inventoryTransaction2.setQcCheck(inventoryDetail.getQcCheck()); | |
271 | + inventoryTransaction2.setWeight(inventoryDetail.getWeight()); | |
272 | + inventoryTransaction2.setManufactureDate(inventoryDetail.getManufactureDate()); | |
273 | + inventoryTransaction2.setExpirationDate(inventoryDetail.getExpirationDate()); | |
274 | + inventoryTransaction2.setAgingDate(inventoryDetail.getCreated()); | |
275 | + inventoryTransaction2.setAttributeId(inventoryDetail.getAttributeId()); | |
276 | + inventoryTransaction2.setAttribute1(inventoryDetail.getAttribute1()); | |
277 | + inventoryTransaction2.setAttribute2(inventoryDetail.getAttribute2()); | |
278 | + inventoryTransaction2.setAttribute3(inventoryDetail.getAttribute3()); | |
279 | + inventoryTransaction2.setCreated(new Date()); | |
280 | + inventoryTransaction2.setCreatedBy(ShiroUtils.getLoginName()); | |
281 | + inventoryTransaction2.setBillDetailId(inventoryDetail.getReceiptDetailId()); | |
282 | + inventoryTransaction2.setSupplierCode(inventoryDetail.getSupplierCode()); | |
283 | + inventoryTransactionService.saveOrUpdate(inventoryTransaction2); | |
150 | 284 | |
151 | - return AjaxResult.success("调整库存数量成功!"); | |
152 | 285 | } |
153 | 286 | |
287 | + /** | |
288 | + * 调整插入库存 | |
289 | + * @param adjustDetail | |
290 | + */ | |
291 | + @Transactional | |
292 | + public void updateAdjustDetailInsert (AdjustDetail adjustDetail) { | |
293 | + /*当实际库存为0时,调整单触发插入新库存状态*/ | |
294 | + //判断是否存在库存头,没有需要生成,有库存头直接插入库存明细即可 | |
295 | + //新生成库存头时,库位,容器都需要更新数据 | |
154 | 296 | |
155 | 297 | |
156 | 298 | |
... | ... | @@ -159,6 +301,7 @@ public class AdjustDetailServiceImpl extends ServiceImpl<AdjustDetailMapper, Adj |
159 | 301 | |
160 | 302 | |
161 | 303 | |
304 | + } | |
162 | 305 | |
163 | 306 | |
164 | 307 | |
... | ... |