ShippingCombinationController.java
8.71 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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
package com.huaheng.pc.shipment.shippingCombination.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huaheng.common.constant.QuantityConstant;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.controller.BaseController;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.framework.web.page.TableDataInfo;
import com.huaheng.mobile.shipment.Shipment;
import com.huaheng.pc.config.shipmentPreference.service.ShipmentPreferenceService;
import com.huaheng.pc.inventory.inventoryDetail.domain.InventoryDetail;
import com.huaheng.pc.shipment.shipmentContainerDetail.service.ShipmentContainerDetailService;
import com.huaheng.pc.shipment.shipmentContainerHeader.domain.ShipmentCombinationModel;
import com.huaheng.pc.shipment.shipmentContainerHeader.domain.ShipmentContainerHeader;
import com.huaheng.pc.shipment.shipmentContainerHeader.service.ShipmentContainerHeaderService;
import com.huaheng.pc.shipment.shipmentDetail.domain.ShipmentDetail;
import com.huaheng.pc.shipment.shipmentDetail.service.ShipmentDetailServiceImpl;
import com.huaheng.pc.shipment.shipmentHeader.domain.ShipmentHeader;
import com.huaheng.pc.shipment.shipmentHeader.service.ShipmentHeaderService;
import com.huaheng.pc.shipment.shippingCombination.service.ShippingCombinationService;
import com.huaheng.pc.task.taskHeader.domain.ShipmentTaskCreateModel;
import com.huaheng.pc.task.taskHeader.service.ShipmentTaskService;
import com.huaheng.pc.task.taskHeader.service.TaskHeaderService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
@Controller
@RequestMapping("/shipment/shippingCombination")
public class ShippingCombinationController extends BaseController {
private String prefix = "shipment/shippingCombination";
@Autowired
ShipmentDetailServiceImpl shipmentDetailService;
@Autowired
ShippingCombinationService shippingCombinationService;
@Autowired
ShipmentContainerHeaderService shipmentContainerHeaderService;
@Autowired
ShipmentContainerDetailService shipmentContainerDetailService;
@Autowired
ShipmentHeaderService shipmentHeaderService;
@Autowired
ShipmentPreferenceService shipmentPreferenceService;
@Autowired
TaskHeaderService taskHeaderService;
@Resource
private ShipmentTaskService shipmentTaskService;
/**
* 打开出库组盘页面
* @param shipmentCode
* @param map
* @return
*/
@RequiresPermissions("shipment:shippingCombination:view")
@GetMapping()
public String ShippingCombination(String shipmentCode, ModelMap map){
map.put("code", shipmentCode);
return prefix+"/shippingCombination";
}
/**
* 获取单据列表
* @param code
* @return
*/
@GetMapping("/listShipmentDetail")
@ResponseBody
public AjaxResult listShipmentDetail(String code){
if(StringUtils.isEmpty(code)){
return null;
}
LambdaQueryWrapper<ShipmentDetail> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(ShipmentDetail::getShipmentCode,code)
.in(ShipmentDetail::getCompanyCode,ShiroUtils.getCompanyCodeList())
.eq(ShipmentDetail::getWarehouseCode,ShiroUtils.getWarehouseCode());
List<ShipmentDetail> shipmentDetails =shipmentDetailService.list(lambdaQueryWrapper) ;
return AjaxResult.success(shipmentDetails);
}
// /**
// * 获取能出库的库存列表
// * @param code,id
// * @return
// */
// @PostMapping("/getInventory")
// @ResponseBody
// public TableDataInfo getInventory(String code, Integer id){
// //找到主单的账套
// LambdaQueryWrapper<ShipmentHeader> lambdaQueryWrapper = Wrappers.lambdaQuery();
// lambdaQueryWrapper.eq(ShipmentHeader::getCode,code)
// .eq(ShipmentHeader::getWarehouseCode,ShiroUtils.getWarehouseCode());
// ShipmentHeader shipmentHeader=shipmentHeaderService.getOne(lambdaQueryWrapper);
// if(shipmentHeader==null){
// throw new ServiceException("找不到主单");
// }
// //找到子单物料
// ShipmentDetail shipmentDetail=new ShipmentDetail();
// shipmentDetail=shipmentDetailService.getById(id);
// if(shipmentDetail==null){
// throw new ServiceException("找不到子单");
// }
// LambdaQueryWrapper<InventoryDetail> lam = Wrappers.lambdaQuery();
// lam.eq(InventoryDetail::getWarehouseCode,shipmentHeader.getWarehouseCode())
// .eq(InventoryDetail::getCompanyCode,shipmentHeader.getCompanyCode())
// .eq(InventoryDetail::getMaterialCode,shipmentDetail.getMaterialCode());
//
// List<InventoryDetail> list= inventoryDetailService.list(lam);
// return getDataTable(list);
// }
/**
* 获取能出库的库存列表
* @param code,id
* @return
*/
@PostMapping("/getInventory")
@ResponseBody
public TableDataInfo getInventory(String code, Integer id){
//找到主单
LambdaQueryWrapper<ShipmentHeader> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(ShipmentHeader::getCode,code)
.eq(ShipmentHeader::getWarehouseCode,ShiroUtils.getWarehouseCode());
ShipmentHeader shipmentHeader=shipmentHeaderService.getOne(lambdaQueryWrapper);
if(shipmentHeader==null){
throw new ServiceException("找不到主单");
}
//找到子单
ShipmentDetail shipmentDetail=new ShipmentDetail();
shipmentDetail=shipmentDetailService.getById(id);
if(shipmentDetail==null){
throw new ServiceException("找不到子单");
}
List<InventoryDetail> list=shippingCombinationService.getInventorys(shipmentDetail);
if(list.isEmpty()){
throw new ServiceException("该物料没有库存或没有符合出库规则的库存");
}
for(InventoryDetail item : list){
item.setQty(item.getQty().subtract(item.getTaskQty()));
}
//查找分配规则
return getDataTable(list);
}
/**
* 保存组盘
* @param shipmentCombinationModel
* @return
*/
@RequiresPermissions("shipment:shippingCombination:combination")
@PostMapping("/Addcombination")
@ResponseBody
public AjaxResult Addcombination(ShipmentCombinationModel shipmentCombinationModel){
ShipmentContainerHeader shipmentContainerHeader= shipmentContainerHeaderService.combination(shipmentCombinationModel);
ShipmentTaskCreateModel shipmentTask = new ShipmentTaskCreateModel();
shipmentTask.setShipmentContainerHeaderIds(shipmentContainerHeader.getId());
return AjaxResult.success(shipmentContainerHeader.getId());
}
/**
* 自动组盘
* @param shipmentCode
* @return
*/
@RequiresPermissions("shipment:shippingCombination:combination")
@PostMapping("/autoCombination")
@ResponseBody
public AjaxResult autoCombination(String shipmentCode){
AjaxResult ajaxResult = shipmentContainerHeaderService.autoCombination(shipmentCode);
LambdaQueryWrapper<ShipmentContainerHeader> shipmentContainerHeader=Wrappers.lambdaQuery();
shipmentContainerHeader.eq(ShipmentContainerHeader::getStatus, QuantityConstant.SHIPMENT_CONTAINER_BUILD);
List<ShipmentContainerHeader> shipmentContainerHeaders=shipmentContainerHeaderService.list(shipmentContainerHeader);
for(ShipmentContainerHeader item: shipmentContainerHeaders){
ShipmentTaskCreateModel shipmentTask = new ShipmentTaskCreateModel();
shipmentTask.setShipmentContainerHeaderIds(item.getId());
AjaxResult ajaxResults = shipmentTaskService.createTaskFromShipmentContainers(shipmentTask);
if (ajaxResults.hasErr()){
throw new ServiceException("任务生成失败");
}
}
return ajaxResult;
}
/** 取消组盘
*
* @param shipmentContainerDetailIds
* @return
*/
@RequiresPermissions("shipment:shippingCombination:remove")
@PostMapping("/cancelCombination")
@ResponseBody
public AjaxResult cancelCombination(@RequestBody List<Integer> shipmentContainerDetailIds){
return shipmentContainerHeaderService.cancelCombinationDetail(shipmentContainerDetailIds);
}
}