ReceiptDetailController.java
17.2 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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
package com.huaheng.pc.receipt.receiptDetail.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.huaheng.common.utils.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huaheng.common.exception.service.ServiceException;
import com.huaheng.common.support.Convert;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.poi.ExcelUtil;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.aspectj.lang.annotation.Log;
import com.huaheng.framework.aspectj.lang.constant.BusinessType;
import com.huaheng.framework.web.controller.BaseController;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.framework.web.page.PageDomain;
import com.huaheng.framework.web.page.TableDataInfo;
import com.huaheng.framework.web.page.TableSupport;
import com.huaheng.pc.config.company.domain.Company;
import com.huaheng.pc.config.company.service.CompanyService;
import com.huaheng.pc.config.material.domain.Material;
import com.huaheng.pc.config.material.service.MaterialService;
import com.huaheng.pc.inventory.inventoryDetail.domain.InventoryDetail;
import com.huaheng.pc.inventory.inventoryDetail.service.InventoryDetailService;
import com.huaheng.pc.receipt.receiptContainerDetail.service.ReceiptContainerDetailService;
import com.huaheng.pc.receipt.receiptContainerHeader.domain.ReceiptContainerView;
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 io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.ibatis.annotations.Param;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.locks.ReentrantLock;
@Api(tags = "入库明细")
@Controller
@RequestMapping("/receipt/receiptDetail")
public class ReceiptDetailController extends BaseController {
@Resource
private ReceiptDetailService receiptDetailService;
@Resource
private ReceiptHeaderService receiptHeaderService;
@Resource
private MaterialService materialService;
@Resource
private CompanyService companyService;
@Resource
private InventoryDetailService inventoryDetailService;
@Autowired
private ReceiptContainerDetailService receiptContainerDetailService;
private String prefix = "receipt/receiptDetail";
@RequiresPermissions("receipt:receiptDetail:view")
@Log(title = "入库-入库详情列表", operating = "入库详情列表", action = BusinessType.GRANT)
@GetMapping("/list/{id}")
public String list(@PathVariable("id")Integer id, ModelMap mmap) {
ReceiptHeader receiptHeader = receiptHeaderService.getById(id);
mmap.put("receiptId", id);
mmap.put("receiptCode", receiptHeader.getCode());
return prefix+"/receiptDetail";
}
/**
* 查询入库详情
*/
@ApiOperation(value="查看入库详情", notes="根据头表id获取入库单明细信息", httpMethod = "POST")
@RequiresPermissions("receipt:receiptDetail:list")
@Log(title = "入库-入库单明细管理", operating = "查看入库单明细", action = BusinessType.GRANT)
@PostMapping("/list")
@ResponseBody
public TableDataInfo list(@ApiParam(name="receiptDetail",value="入库详情") ReceiptDetail receiptDetail,
@ApiParam(name = "createdBegin", value = "起止时间") String createdBegin,
@ApiParam(name = "createdEnd", value = "结束时间") String createdEnd) {
LambdaQueryWrapper<ReceiptDetail> lambdaQueryWrapper = Wrappers.lambdaQuery();
PageDomain pageDomain = TableSupport.buildPageRequest();
Integer pageNum = pageDomain.getPageNum();
Integer pageSize = pageDomain.getPageSize();
lambdaQueryWrapper.ge(StringUtils.isNotEmpty(createdBegin), ReceiptDetail::getCreated, createdBegin)
.le(StringUtils.isNotEmpty(createdEnd), ReceiptDetail::getCreated, createdEnd)
.eq(StringUtils.isNotNull(receiptDetail.getReceiptId()), ReceiptDetail::getReceiptId, receiptDetail.getReceiptId());
lambdaQueryWrapper.orderByAsc(ReceiptDetail::getMaterialCode);
if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize)){
/*使用分页查询*/
Page<ReceiptDetail> page = new Page<>(pageNum, pageSize);
IPage<ReceiptDetail> iPage = receiptDetailService.page(page, lambdaQueryWrapper);
return getMpDataTable(iPage.getRecords(), iPage.getTotal());
} else {
List<ReceiptDetail> list = receiptDetailService.list(lambdaQueryWrapper);
list.forEach(receiptDetail2 -> {
InventoryDetail inventoryDetail=new InventoryDetail();
inventoryDetail.setMaterialCode(receiptDetail2.getMaterialCode());
inventoryDetail.setInventorySts(receiptDetail2.getInventorySts());
inventoryDetail.setWarehouseCode(receiptDetail2.getWarehouseCode());
BigDecimal sumQty = inventoryDetailService.getSumQty(inventoryDetail);
receiptDetail2.setInventoryQty(sumQty);
});
return getDataTable(list);
}
}
/**
* 新增入库明细
*/
@GetMapping("/add/{id}/{receiptCode}")
public String add(@PathVariable("id") Integer id, @PathVariable("receiptCode") String receiptCode, ModelMap mmap) {
LambdaQueryWrapper<ReceiptHeader> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(ReceiptHeader::getId, id).eq(ReceiptHeader::getCode, receiptCode);
ReceiptHeader receiptHeader = receiptHeaderService.getOne(lambdaQueryWrapper);
mmap.put("receiptId", id);
mmap.put("companyCode", receiptHeader.getCompanyCode());
mmap.put("receiptCode", receiptCode);
return prefix + "/add";
}
/**
* 新增保存入库单
*/
@ApiOperation(value="新增入库单 ", notes="新增入库单 ", httpMethod = "POST")
@RequiresPermissions("receipt:receiptDetail:add")
@Log(title = "入库-入库单 ",operating = "新增入库单 ", action = BusinessType.INSERT)
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(ReceiptDetail receiptDetail) {
return receiptDetailService.saveReceiptDetaial(receiptDetail);
}
/**
* 修改入库明细
*/
@GetMapping("/edit/{id}")
public String edit(@PathVariable("id") Integer id, ModelMap mmap) {
ReceiptDetail receiptDetail = receiptDetailService.getById(id);
mmap.put("receiptDetail", receiptDetail);
return prefix + "/edit";
}
/**
* 修改保存入库单
*/
@ApiOperation(value="修改入库单 ", notes="修改入库单 ", httpMethod = "POST")
@RequiresPermissions("receipt:receiptDetail:add")
@Log(title = "入库-入库单 ",operating = "修改入库单 ", action = BusinessType.INSERT)
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(
@ApiParam(name="receiptDetail",value="入库详情") ReceiptDetail receiptDetail) {
return receiptDetailService.updateReceiptDetaial(receiptDetail);
}
/**
* 删除入库单
*/
@ApiOperation(value="删除入库单 ", notes="删除入库单 ", httpMethod = "POST")
@RequiresPermissions("receipt:receiptDetail:add")
@Log(title = "入库-入库单 ",operating = "修改入库单 ", action = BusinessType.INSERT)
@PostMapping("/remove")
@ResponseBody
public AjaxResult remove(String ids) {
if (StringUtils.isEmpty(ids)){
return AjaxResult.error("id为空");
}
ReceiptDetail receiptDetail = receiptDetailService.getById(ids);
ReceiptHeader receiptHeader = receiptHeaderService.getById(receiptDetail.getReceiptId());
if (receiptDetail.getTaskQty().compareTo(new BigDecimal(0)) != 0) {
return AjaxResult.error("已收数量不为0, 不允许删除");
}
for (Integer id : Convert.toIntArray(ids)){
receiptDetailService.removeById(id);
receiptHeader.setTotalQty(receiptHeader.getTotalQty().subtract(receiptDetail.getTaskQty()));
receiptHeader.setTotalLines(receiptHeader.getTotalLines() - 1);
if (receiptHeaderService.updateById(receiptHeader)) {
List<ReceiptDetail> detailList = receiptDetailService.findByReceiptId(receiptDetail.getReceiptId());
if(detailList.size()<1) {
receiptDetailService.updateReceiptHeaderLastStatus(receiptHeader.getId());
}
} else {
return AjaxResult.error("失败");
}
}
return AjaxResult.success("删除成功!");
}
/**
* 审核入库单
*/
@ApiOperation(value="审核入库单", notes="审核入库单", httpMethod = "POST")
@RequiresPermissions("receipt:receiptDetail:approval")
@Log(title = "入库-入库单 ",operating = "审核入库单 ", action = BusinessType.UPDATE)
@PostMapping("/approval")
@ResponseBody
public AjaxResult approval(@ApiParam(name="id",value="入库明细表id") String ids,
@ApiParam(name="approval",value="审核结果值,10审核驳回,20作废,100审核成功") Integer approval) {
if (StringUtils.isEmpty(ids)){
return AjaxResult.error("id不能为空");
}
if (!(approval == 10 || approval == 20 || approval == 100)){
return AjaxResult.error("传入参数错误");
}
for (Integer id : Convert.toIntArray(ids)) {
ReceiptDetail receiptDetail = new ReceiptDetail();
receiptDetail.setId(id);
receiptDetail.setProcessStamp(String.valueOf(approval));
receiptDetail.setLastUpdatedBy(ShiroUtils.getLoginName());
if (receiptDetailService.updateById(receiptDetail)) {
ReceiptDetail newReceiptDetail = receiptDetailService.getById(id);
//更新入库明细状态
if (!receiptDetailService.updateById(receiptDetailService.queryflow(newReceiptDetail))){
throw new ServiceException("更新入库明细失败");
}
ReceiptHeader receiptHeader = new ReceiptHeader();
receiptHeader.setFirstStatus(approval);
receiptHeader.setId(newReceiptDetail.getReceiptId());
receiptHeaderService.updateById(receiptHeader);
//更新头表尾状态
receiptDetailService.updateReceiptHeaderLastStatus(newReceiptDetail.getReceiptId());
} else {
throw new ServiceException("审核失败");
}
}
return AjaxResult.success("审核成功");
}
/**
* 到货入库单
*/
@ApiOperation(value="入库单到货", notes="入库单到货", httpMethod = "POST")
@RequiresPermissions("receipt:receiptDetail:arrival")
@Log(title = "入库-入库单 ",operating = "入库单到货", action = BusinessType.UPDATE)
@PostMapping("/arrival")
@ResponseBody
public AjaxResult arrival(@ApiParam(name = "id", value = "id字符串")String ids){
if (StringUtils.isEmpty(ids)){
return AjaxResult.error("id为空");
}
for (Integer id : Convert.toIntArray(ids)){
receiptHeaderService.arrival(id);
}
return AjaxResult.success("已到货");
}
@RequiresPermissions("shipment:bill:report")
@Log(title = "入库-入库单", operating = "打印入库单明细报表", action = BusinessType.OTHER)
@GetMapping("/report/{ids}")
public String report(@PathVariable("ids") Integer[] ids, ModelMap mmap) {
List<ReceiptDetail> list = new ArrayList<ReceiptDetail>();
for (Integer id : ids) {
if (id != null) {
ReceiptDetail receiptDetail = receiptDetailService.getById(id);
//获得物料信息
LambdaQueryWrapper<Material> materialLambd = Wrappers.lambdaQuery();
materialLambd.eq(Material::getCode, receiptDetail.getMaterialCode())
.eq(Material::getWarehouseCode, ShiroUtils.getWarehouseCode());
Material material = materialService.getMaterialByCode(receiptDetail.getMaterialCode());
if (material == null) {
throw new ServiceException("系统没有此物料编码" + receiptDetail.getMaterialCode());
}
String name = material.getName();
String spc = material.getSpec();
if(name != null && name.length()> 20){
name = name.substring(0, 20);
}
// if(spc != null && spc.length() > 16){
// spc = spc.substring(0, 16);
// }
receiptDetail.setUserDef1(material.getUserDef1());
receiptDetail.setMaterialSpec(spc);
receiptDetail.setMaterialName(name);
NumberFormat nf = NumberFormat.getInstance();
receiptDetail.setTaskQty(receiptDetail.getTaskQty());
LambdaQueryWrapper<Company> companyLambda = Wrappers.lambdaQuery();
companyLambda.eq(Company::getCode, receiptDetail.getCompanyCode());
Company company = companyService.getOne(companyLambda);
if (company == null) {
throw new ServiceException("系统没有此货主编码" + receiptDetail.getCompanyCode());
}
receiptDetail.setCompanyName(company.getName());
list.add(receiptDetail);
}
mmap.put("receiptDetails", list);
}
return prefix + "/report";
}
@PostMapping("/importData")
@ResponseBody
public AjaxResult importData (MultipartFile file) throws Exception {
ExcelUtil<ReceiptDetail> util = new ExcelUtil<>(ReceiptDetail.class);
List<ReceiptDetail> list = util.importExcel(file.getInputStream());
String operName = ShiroUtils.getLoginName();
String message = receiptDetailService.insertExcelData(list, false, operName);
return AjaxResult.success(message);
}
/**
* 导出模板
*
* @return
* @throws Exception
*/
@GetMapping("/importTemplate")
@ResponseBody
public AjaxResult importTemplate () {
ExcelUtil<ReceiptDetail> util = new ExcelUtil<>(ReceiptDetail.class);
return util.importTemplateExcel("入库详情");
}
//@RequiresPermissions("receipt:bill:list")
@GetMapping("/receiptContainerDetails/{code}")
public String shipmentContainerDetail(@PathVariable("code") String code, ModelMap mmap)
{
mmap.put("receiptCode", code);
return prefix + "/receiptContainerDetail";
}
/**
* 查询入库组盘明细列表
*/
//@RequiresPermissions("receipt:bill:list")
@Log(title ="出库-出库单", operating = "查看出库组盘明细", action = BusinessType.GRANT)
@PostMapping("/receiptContainerDetails")
@ResponseBody
public TableDataInfo list(ReceiptContainerView receiptContainerView)
{
startPage();
receiptContainerView.setWarehouseCode(ShiroUtils.getWarehouseCode());
List<ReceiptContainerView> list = receiptContainerDetailService.selectOfView(receiptContainerView) ;
return getDataTable(list);
}
@RequiresPermissions("receipt:receiptDetail:add")
@ApiOperation(value="批量修改入库详情u8仓库", notes="批量修改入库详情u8仓库", httpMethod = "POST")
@Log(title = "入库-入库详情列表", operating = "修改入库详情u8仓库", action = BusinessType.GRANT)
@GetMapping("/batUWarehouse/{ids}/{companyCode}/{warehouseCode}")
public String batUWarehouse(@PathVariable("ids")String ids,@PathVariable("companyCode")String companyCode,@PathVariable("warehouseCode")String warehouseCode,ModelMap mmap) {
mmap.put("ids", ids);
mmap.put("companyCode", companyCode);
mmap.put("warehouseCode", warehouseCode);
return prefix+"/batUWarehouse";
}
@RequiresPermissions("receipt:receiptDetail:add")
@ApiOperation(value="批量修改入库详情u8仓库", notes="批量修改入库详情u8仓库", httpMethod = "POST")
@Log(title = "入库-入库详情列表", operating = "修改入库详情u8仓库", action = BusinessType.GRANT)
@PostMapping("/batUWarehouse")
@ResponseBody
public AjaxResult batUWarehouse(String ids,String companyCode,String uWarehouseCode,String warehouseCode) {
return receiptDetailService.batUWarehouse(ids,companyCode,uWarehouseCode,warehouseCode);
}
}