Commit f050b59490341c86190a0e4457bab15317d62827

Authored by pengcheng
1 parent ffe3dd0d

释放波次

src/main/java/com/huaheng/pc/shipment/shipmentContainerHeader/service/ShipmentContainerHeaderServiceImpl.java
... ... @@ -21,6 +21,8 @@ import com.huaheng.pc.shipment.shipmentHeader.domain.ShipmentHeader;
21 21 import com.huaheng.pc.shipment.shipmentHeader.service.ShipmentHeaderService;
22 22 import com.huaheng.pc.shipment.shippingCombination.domain.ShippingSearch;
23 23 import com.huaheng.pc.shipment.shippingCombination.service.ShippingCombinationService;
  24 +import com.huaheng.pc.shipment.wave.domain.Wave;
  25 +import com.huaheng.pc.shipment.wave.service.WaveService;
24 26 import com.huaheng.pc.task.taskDetail.domain.TaskDetail;
25 27 import com.huaheng.pc.task.taskDetail.service.TaskDetailService;
26 28 import com.huaheng.pc.task.taskHeader.domain.ShipmentTaskCreateModel;
... ... @@ -63,6 +65,8 @@ public class ShipmentContainerHeaderServiceImpl extends ServiceImpl<ShipmentCont
63 65 private TaskHeaderService taskHeaderService;
64 66 @Autowired
65 67 private TaskDetailService taskDetailService;
  68 + @Autowired
  69 + private WaveService waveService;
66 70  
67 71  
68 72 @Override
... ... @@ -249,6 +253,7 @@ public class ShipmentContainerHeaderServiceImpl extends ServiceImpl<ShipmentCont
249 253 shipmentContainerDetail.setMaterialSpec(material.getSpec());
250 254 shipmentContainerDetail.setQty(shipmentCombinationModel.getShipQty());
251 255 shipmentContainerDetail.setCreated(null);
  256 + shipmentContainerDetail.setWaveId(shipmentDetail.getWaveId());
252 257 shipmentContainerDetail.setCreatedBy(ShiroUtils.getLoginName());
253 258 shipmentContainerDetailService.save(shipmentContainerDetail);
254 259 }
... ... @@ -418,6 +423,9 @@ public class ShipmentContainerHeaderServiceImpl extends ServiceImpl<ShipmentCont
418 423  
419 424 List<InventoryDetail> inventoryList = shippingCombinationService.getInventorys(item);
420 425 if(inventoryList.size() < 1 && item.getWaveId() != 0){
  426 + Wave wave = waveService.getById(item.getWaveId());
  427 + wave.setStatus(999);
  428 + waveService.updateById(wave);
421 429 return AjaxResult.error("主单为"+item.getShipmentCode()+"子单id为"+item.getId() + "的单据没有库存,波次失败");
422 430 }
423 431 if (inventoryList.size() < 1) {
... ...
src/main/java/com/huaheng/pc/shipment/shipmentDetail/service/ShipmentDetailServiceImpl.java
... ... @@ -191,8 +191,10 @@ public class ShipmentDetailServiceImpl extends ServiceImpl&lt;ShipmentDetailMapper,
191 191 if (shipmentDetail.getWaveId() != 0) {
192 192 throw new ServiceException("主单id为" + id + "子单id为" + shipmentDetail.getId() + "的子单已加入波次,不可再加入波次");
193 193 }
194   - shipmentDetailList.add(shipmentDetail);
195   - qty=qty.add(shipmentDetail.getShipQty());
  194 + if(shipmentDetail.getShipQty().compareTo(shipmentDetail.getRequestQty())!=0) {
  195 + shipmentDetailList.add(shipmentDetail);
  196 + qty = qty.add(shipmentDetail.getShipQty().subtract(shipmentDetail.getRequestQty()));
  197 + }
196 198 }
197 199 }
198 200  
... ... @@ -236,7 +238,9 @@ public class ShipmentDetailServiceImpl extends ServiceImpl&lt;ShipmentDetailMapper,
236 238 //修改出库子单,加入波次ID,并修改状态为波次
237 239 for(ShipmentDetail shipmentDetail :shipmentDetailList){
238 240 shipmentDetail.setWaveId(wave.getId());
239   - shipmentDetail.setStatus(200);
  241 + if(shipmentDetail.getStatus()<200) {
  242 + shipmentDetail.setStatus(200);
  243 + }
240 244 }
241 245  
242 246 flag = this.updateBatchById(shipmentDetailList);
... ... @@ -248,7 +252,6 @@ public class ShipmentDetailServiceImpl extends ServiceImpl&lt;ShipmentDetailMapper,
248 252 //修改主单状态
249 253 for (Integer id : Convert.toIntArray(ids)){
250 254 ShipmentHeader shipmentHeader = shipmentHeaderService.getById(id);
251   - shipmentHeader.setFirstStatus(200);
252 255 shipmentHeader.setLastStatus(200);
253 256 shipmentHeaderList.add(shipmentHeader);
254 257 }
... ...
src/main/java/com/huaheng/pc/shipment/wave/controller/WaveController.java
... ... @@ -175,10 +175,10 @@ public class WaveController extends BaseController {
175 175  
176 176  
177 177 /**
178   - * 开始波次
  178 + * 释放
179 179 */
180 180 @RequiresPermissions("shipment:wave:freed")
181   - @Log(title = "出库-波次", operating = "开始波次", action = BusinessType.UPDATE)
  181 + @Log(title = "出库-波次", operating = "波次释放", action = BusinessType.UPDATE)
182 182 @PostMapping("/freed")
183 183 @ResponseBody
184 184 public AjaxResult freed(String ids) {
... ...
src/main/java/com/huaheng/pc/shipment/wave/service/WaveService.java
... ... @@ -10,14 +10,20 @@ import com.huaheng.framework.web.domain.AjaxResult;
10 10 import com.huaheng.pc.shipment.shipmentContainerHeader.service.ShipmentContainerHeaderService;
11 11 import com.huaheng.pc.shipment.shipmentDetail.domain.ShipmentDetail;
12 12 import com.huaheng.pc.shipment.shipmentDetail.service.ShipmentDetailService;
  13 +import com.huaheng.pc.shipment.shipmentHeader.domain.ShipmentHeader;
  14 +import com.huaheng.pc.shipment.shipmentHeader.service.ShipmentHeaderService;
13 15 import com.huaheng.pc.shipment.wave.domain.Wave;
14 16 import com.huaheng.pc.shipment.wave.mapper.WaveMapper;
  17 +import com.huaheng.pc.task.taskDetail.domain.TaskDetail;
  18 +import com.huaheng.pc.task.taskDetail.service.TaskDetailService;
  19 +import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
15 20 import org.springframework.beans.factory.annotation.Autowired;
16 21 import org.springframework.stereotype.Service;
17 22 import org.springframework.transaction.annotation.Transactional;
18 23  
19 24 import java.util.ArrayList;
20 25 import java.util.Arrays;
  26 +import java.util.HashSet;
21 27 import java.util.List;
22 28  
23 29 @Service
... ... @@ -28,6 +34,12 @@ public class WaveService extends ServiceImpl&lt;WaveMapper, Wave&gt; {
28 34 private ShipmentDetailService shipmentDetailService;
29 35 @Autowired
30 36 private ShipmentContainerHeaderService shipmentContainerHeaderService;
  37 + @Autowired
  38 + private TaskDetailService taskDetailService;
  39 + @Autowired
  40 + private TaskHeaderService taskHeaderService;
  41 + @Autowired
  42 + private ShipmentHeaderService shipmentHeaderService;
31 43  
32 44 /**
33 45 * 开始波次,对带有此波次号的单据进行后续的后台操作
... ... @@ -44,14 +56,14 @@ public class WaveService extends ServiceImpl&lt;WaveMapper, Wave&gt; {
44 56 List<ShipmentDetail> list = new ArrayList<>();
45 57 for (Integer id : Convert.toIntArray(ids)) {
46 58  
47   - //查看此波次的状态,状态不为o时,无法开始波次
  59 + //1、查看此波次的状态,状态不为o时,无法开始波次
48 60 Wave wave = this.getById(id);
49 61 if(wave == null || wave.getStatus() != 0){
50 62 return AjaxResult.error("id为"+id+"的波次找不到,或者状态不能做开始操作");
51 63 }
52 64 waves.add(wave);
53 65  
54   - //找到此波次的单据
  66 + //2、找到此波次的单据
55 67 LambdaQueryWrapper<ShipmentDetail> lam = Wrappers.lambdaQuery();
56 68 lam.eq(ShipmentDetail::getWaveId,id)
57 69 .eq(ShipmentDetail::getWarehouseCode, ShiroUtils.getWarehouseCode());
... ... @@ -63,15 +75,16 @@ public class WaveService extends ServiceImpl&lt;WaveMapper, Wave&gt; {
63 75 }
64 76 }
65 77  
66   - //自动组盘
  78 + //3、自动组盘
67 79 AjaxResult ajaxResult=shipmentContainerHeaderService.autoCombination(list);
68 80 if(ajaxResult.getData() != null){
69   - //生成任务
  81 + //4、生成任务
70 82 shipmentContainerHeaderService.createTask(Arrays.asList(Convert.toIntArray(ajaxResult.getData().toString())));
71 83 }
72 84  
  85 + //5、修改波次的状态
73 86 for(Wave wave : waves){
74   - wave.setStatus(400);
  87 + wave.setStatus(300);
75 88 wave.setCurrentWaveStep("生成任务");
76 89 }
77 90 Boolean flag = this.updateBatchById(waves);
... ... @@ -84,12 +97,85 @@ public class WaveService extends ServiceImpl&lt;WaveMapper, Wave&gt; {
84 97  
85 98 /**
86 99 * 释放波次,执行任务
  100 + * 1、查看此波次的状态,是否可以释放波次
  101 + * 2、查看波次的状态,是成功释放还是失败释放
  102 + * 成功释放:1、找到此波次的所有子任务
  103 + * 2、根据子任务选出主任务
  104 + * 3、将这些主任务执行
  105 + * 失败释放:1.找到次波次的所有子单据
  106 + * 2.修改子单据的波次为0
  107 + * 3.修改主子单的状态
87 108 * @param ids
88 109 * @return
89 110 */
90 111 @Transactional
91 112 public AjaxResult freed(String ids) {
  113 + Boolean flag = false;
  114 + List<TaskDetail> taskDetailList = new ArrayList<>();
  115 + for (Integer id : Convert.toIntArray(ids)) {
  116 +
  117 + //1、查看此波次是否可以释放
  118 + Wave wave = this.getById(id);
  119 + if(wave == null || (wave.getStatus()!=300 && wave.getStatus()!=999)){
  120 + return AjaxResult.error(id+"波次不可释放");
  121 + }
  122 +
  123 + //2、查看此波次的状态,看是成功释放还是失败释放
  124 + if(wave.getStatus() == 300) {
  125 + //成功释放——找到此波次的未执行的子任务列表
  126 + LambdaQueryWrapper<TaskDetail> lam = Wrappers.lambdaQuery();
  127 + lam.eq(TaskDetail::getWarehouseCode, ShiroUtils.getWarehouseCode())
  128 + .eq(TaskDetail::getStatus, 0)
  129 + .eq(TaskDetail::getWaveId, id);
  130 + List<TaskDetail> taskDetails = taskDetailService.list(lam);
  131 + if (taskDetails != null) {
  132 + taskDetailList.addAll(taskDetails);
  133 + }
  134 + }else {
  135 + //失败释放——找到次波次的所有子单据
  136 + LambdaQueryWrapper<ShipmentDetail> detailLam = Wrappers.lambdaQuery();
  137 + detailLam.eq(ShipmentDetail::getWarehouseCode,ShiroUtils.getWarehouseCode())
  138 + .eq(ShipmentDetail::getWaveId,wave.getId());
  139 + List<ShipmentDetail> shipmentDetails =shipmentDetailService.list(detailLam);
  140 +
  141 + //2.修改子单据的波次为0
  142 + //3.修改主子单的状态
  143 + HashSet<Integer> set = new HashSet<>();
  144 + for(ShipmentDetail item : shipmentDetails){
  145 + if(item.getShipQty().compareTo(item.getRequestQty())!=0) {
  146 + item.setStatus(0);
  147 + }
  148 + item.setWaveId(0);
  149 + set.add(item.getShipmentId());
  150 + }
  151 + flag = shipmentDetailService.updateBatchById(shipmentDetails);
  152 + if(flag == false){
  153 + throw new ServiceException("修改出库子单状态失败");
  154 + }
  155 + for(Integer shipmentId :set){
  156 + ShipmentHeader shipmentHeader = shipmentHeaderService.getById(shipmentId);
  157 + if(shipmentHeader == null){
  158 + throw new ServiceException("没有对应的出库主单");
  159 + }
  160 + if(shipmentHeader.getFirstStatus()<= 200) {
  161 + shipmentHeader.setFirstStatus(0);
  162 + flag = shipmentHeaderService.updateById(shipmentHeader);
  163 + if (flag == false) {
  164 + throw new ServiceException("修改出库主单失败");
  165 + }
  166 + }
  167 + }
  168 + }
  169 + }
  170 +
  171 + HashSet<Integer> idSet = new HashSet();
  172 + //成功释放——遍历子任务列表,找出主单(distinct)id
  173 + for(TaskDetail item : taskDetailList){
  174 + idSet.add(item.getTaskId());
  175 + }
  176 + //成功释放——将这些主任务执行
  177 + taskHeaderService.sendTaskToWcs(idSet.toArray(new Integer[idSet.size()]));
92 178  
93   - return null;
  179 + return AjaxResult.success("波次释放成功");
94 180 }
95 181 }
... ...
src/main/java/com/huaheng/pc/task/taskHeader/service/TaskHeaderServiceImpl.java
... ... @@ -296,6 +296,7 @@ public class TaskHeaderServiceImpl extends ServiceImpl&lt;TaskHeaderMapper, TaskHea
296 296 taskDetail.setFromLocation(task.getFromLocation());
297 297 taskDetail.setToLocation(task.getToLocation());
298 298 taskDetail.setStatus(0);
  299 + taskDetail.setWaveId(shipmentContainerDetail.getWaveId());
299 300 taskDetail.setInventorySts(shipmentContainerDetail.getInventorySts());
300 301 taskDetail.setTaskType(task.getTaskType());
301 302 taskDetail.setLastUpdatedBy(ShiroUtils.getLoginName());
... ...