ShippingCombinationController.java
11.4 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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
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.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.pc.config.FilterConfigDetail.domain.FilterConfigDetail;
import com.huaheng.pc.config.FilterConfigDetail.service.FilterConfigDetailService;
import com.huaheng.pc.config.configValue.domain.ConfigValue;
import com.huaheng.pc.config.configValue.service.ConfigValueService;
import com.huaheng.pc.config.material.domain.Material;
import com.huaheng.pc.config.material.service.MaterialServiceImpl;
import com.huaheng.pc.config.shipmentPreference.domain.ShipmentPreference;
import com.huaheng.pc.config.shipmentPreference.service.ShipmentPreferenceService;
import com.huaheng.pc.inventory.inventoryDetail.domain.InventoryDetail;
import com.huaheng.pc.inventory.inventoryDetail.service.InventoryDetailService;
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 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 java.util.ArrayList;
import java.util.List;
@Controller
@RequestMapping("/shipment/shippingCombination")
public class ShippingCombinationController extends BaseController {
private String prefix = "shipment/shippingCombination";
@Autowired
MaterialServiceImpl materialService;
@Autowired
ShipmentDetailServiceImpl shipmentDetailService;
@Autowired
ShippingCombinationService shippingCombinationService;
@Autowired
ShipmentContainerHeaderService shipmentContainerHeaderService;
@Autowired
ShipmentContainerDetailService shipmentContainerDetailService;
@Autowired
ShipmentHeaderService shipmentHeaderService;
@Autowired
InventoryDetailService inventoryDetailService;
@Autowired
ConfigValueService configValueService;
@Autowired
FilterConfigDetailService filterConfigDetailService;
@Autowired
ShipmentPreferenceService shipmentPreferenceService;
/**
* 打开出库组盘页面
* @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=new ArrayList<>();
FilterConfigDetail filterConfigDetail=new FilterConfigDetail();
LambdaQueryWrapper<FilterConfigDetail> filterConfigDetailLambdaQueryWrapper=Wrappers.lambdaQuery();
filterConfigDetailLambdaQueryWrapper.eq(FilterConfigDetail::getWarehouseCode,shipmentDetail.getWarehouseCode());
//出库子单的分配规则有时,优先出库子单的分配规则
if(StringUtils.isNotEmpty(shipmentDetail.getAllocationRule())){
filterConfigDetailLambdaQueryWrapper.eq(FilterConfigDetail::getCode,shipmentDetail.getAllocationRule());
filterConfigDetail=filterConfigDetailService.getOne(filterConfigDetailLambdaQueryWrapper);
if(filterConfigDetail==null){
throw new ServiceException("出库子单出库规则配置不存在");
}
//根据sql查库存
try {
list = inventoryDetailService.selectBysql(filterConfigDetail.getStatement());
}catch (Exception e){
throw new ServiceException("sql错误");
}
return getDataTable(list);
}
//出库子单的分配规则没有时,优先物料的分配规则
LambdaQueryWrapper<Material> materialLambdaQueryWrapper=Wrappers.lambdaQuery();
materialLambdaQueryWrapper.eq(Material::getCode,shipmentDetail.getMaterialCode())
.eq(Material::getWarehouseCode,shipmentDetail.getWarehouseCode());
Material material=materialService.getOne(materialLambdaQueryWrapper);
if(StringUtils.isNotEmpty(material.getAllocationRule())){
filterConfigDetailLambdaQueryWrapper.eq(FilterConfigDetail::getCode,material.getAllocationRule());
filterConfigDetail=filterConfigDetailService.getOne(filterConfigDetailLambdaQueryWrapper);
if(filterConfigDetail==null){
throw new ServiceException("物料出库规则配置不存在");
}
//根据sql查库存
list=inventoryDetailService.selectBysql(filterConfigDetail.getStatement());
return getDataTable(list);
}
//都没有时,默认仓库的分配规则
LambdaQueryWrapper<ConfigValue> configValueLambdaQueryWrapper=Wrappers.lambdaQuery();
configValueLambdaQueryWrapper.eq(ConfigValue::getModuleType,"shipment")
.eq(ConfigValue::getWarehouseCode,shipmentDetail.getWarehouseCode());
ConfigValue configValue=configValueService.getOne(configValueLambdaQueryWrapper);
if(configValue==null){
throw new ServiceException("仓库的出库配置不存在");
}
//查找出库首选项
LambdaQueryWrapper<ShipmentPreference> slam=Wrappers.lambdaQuery();
slam.eq(ShipmentPreference::getCode,configValue.getIdentifier())
.eq(ShipmentPreference::getWarehouseCode,configValue.getWarehouseCode());
ShipmentPreference shipmentPreference=shipmentPreferenceService.getOne(slam);
if(shipmentPreference==null){
throw new ServiceException("仓库的出库配置中出库首选项不存在");
}
//查找分配规则
filterConfigDetailLambdaQueryWrapper.eq(FilterConfigDetail::getCode,shipmentPreference.getAllocationRule());
filterConfigDetail=filterConfigDetailService.getOne(filterConfigDetailLambdaQueryWrapper);
if(filterConfigDetail==null){
throw new ServiceException("出库首选项中出库规则配置不存在");
}
//根据sql查库存
list=inventoryDetailService.selectBysql(filterConfigDetail.getStatement());
return getDataTable(list);
}
/**
* 保存组盘
* @param shipmentCombinationModel
* @return
*/
@RequiresPermissions("shipment:shippingCombination:combination")
@PostMapping("/Addcombination")
@ResponseBody
public AjaxResult Addcombination(ShipmentCombinationModel shipmentCombinationModel){
ShipmentContainerHeader shipmentContainerHeader= shipmentContainerHeaderService.combination(shipmentCombinationModel);
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);
return ajaxResult;
}
/** 取消组盘
*
* @param shipmentContainerDetailIds
* @return
*/
@RequiresPermissions("shipment:shippingCombination:remove")
@PostMapping("/cancelCombination")
@ResponseBody
public AjaxResult cancelCombination(@RequestBody List<Integer> shipmentContainerDetailIds){
return shipmentContainerHeaderService.cancelCombinationDetail(shipmentContainerDetailIds);
}
}