MaterialWarningController.java
13.3 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
package com.huaheng.pc.config.materialWarnning.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.page.PageDomain;
import com.huaheng.framework.web.page.TableDataInfo;
import com.huaheng.framework.web.page.TableSupport;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.pc.config.materialWarnning.domain.MaterialSummary;
import com.huaheng.pc.inventory.InventoryMaterialSummary.domain.InventoryMaterialSummary;
import com.huaheng.pc.inventory.InventoryMaterialSummary.service.InventoryMaterialSummaryService;
import com.huaheng.pc.inventory.inventoryDetail.domain.InventoryDetail;
import com.huaheng.pc.inventory.inventoryDetail.service.InventoryDetailService;
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.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.huaheng.framework.aspectj.lang.annotation.Log;
import com.huaheng.framework.aspectj.lang.constant.BusinessType;
import com.huaheng.pc.config.materialWarnning.domain.MaterialWarning;
import com.huaheng.pc.config.materialWarnning.service.IMaterialWarningService;
import com.huaheng.framework.web.controller.BaseController;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.common.support.Convert;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
/**
* 物料报警 信息操作处理
*
* @author huaheng
* @date 2020-07-17
*/
@Controller
@RequestMapping("/config/materialWarning")
public class MaterialWarningController extends BaseController {
private String prefix = "config/materialWarning";
@Resource
private IMaterialWarningService materialWarningService;
@Resource
private InventoryDetailService inventoryDetailService;
@Resource
private InventoryMaterialSummaryService inventoryMaterialSummaryService;
@RequiresPermissions("config:materialWarning:view")
@GetMapping()
public String materialWarning() {
return prefix + "/materialWarning";
}
/**
* 查询物料报警列表
*/
@RequiresPermissions("config:materialWarning:list")
@PostMapping("/list")
@ResponseBody
public TableDataInfo list(MaterialWarning materialWarning) {
LambdaQueryWrapper<MaterialWarning> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper
.eq(StringUtils.isNotEmpty(materialWarning.getAlarmType()), MaterialWarning::getAlarmType, materialWarning.getAlarmType())
.eq(StringUtils.isNotEmpty(materialWarning.getWarehouseCode()), MaterialWarning::getWarehouseCode, ShiroUtils.getWarehouseCode())
.eq(StringUtils.isNotEmpty(materialWarning.getCompanyCode()), MaterialWarning::getCompanyCode, materialWarning.getCompanyCode())
.eq(StringUtils.isNotEmpty(materialWarning.getMaterialCode()), MaterialWarning::getMaterialCode, materialWarning.getMaterialCode())
.like(StringUtils.isNotEmpty(materialWarning.getMaterialName()), MaterialWarning::getMaterialName, materialWarning.getMaterialName())
.eq(StringUtils.isNotEmpty(materialWarning.getMaterialSpec()), MaterialWarning::getMaterialSpec, materialWarning.getMaterialSpec())
.eq(StringUtils.isNotEmpty(materialWarning.getMaterialUnit()), MaterialWarning::getMaterialUnit, materialWarning.getMaterialUnit())
.eq(StringUtils.isNotNull(materialWarning.getMax()), MaterialWarning::getMax, materialWarning.getMax())
.eq(StringUtils.isNotNull(materialWarning.getMin()), MaterialWarning::getMin, materialWarning.getMin())
.eq(StringUtils.isNotNull(materialWarning.getUpper()), MaterialWarning::getUpper, materialWarning.getUpper())
.eq(StringUtils.isNotNull(materialWarning.getLower()), MaterialWarning::getLower, materialWarning.getLower())
.eq(StringUtils.isNotNull(materialWarning.getUserId()), MaterialWarning::getUserId, materialWarning.getUserId())
.like(StringUtils.isNotEmpty(materialWarning.getUserName()), MaterialWarning::getUserName, materialWarning.getUserName())
.eq(StringUtils.isNotEmpty(materialWarning.getEmail()), MaterialWarning::getEmail, materialWarning.getEmail());
PageDomain pageDomain = TableSupport.buildPageRequest();
Integer pageNum = pageDomain.getPageNum();
Integer pageSize = pageDomain.getPageSize();
if (StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize)) {
/*使用分页查询*/
Page<MaterialWarning> page = new Page<>(pageNum, pageSize);
IPage<MaterialWarning> iPage = materialWarningService.page(page, lambdaQueryWrapper);
return getMpDataTable(iPage.getRecords(), iPage.getTotal());
} else {
List<MaterialWarning> list = materialWarningService.list(lambdaQueryWrapper);
return getDataTable(list);
}
}
/**
* 新增物料报警
*/
@GetMapping("/add")
public String add() {
return prefix + "/add";
}
/**
* 新增保存物料报警
*/
@RequiresPermissions("config:materialWarning:add")
@Log(title = "物料报警", action = BusinessType.INSERT)
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(MaterialWarning materialWarning) {
return materialWarningService.addSave(materialWarning);
}
/**
* 修改物料报警
*/
@GetMapping("/edit/{id}")
public String edit(@PathVariable("id") Integer id, ModelMap mmap) {
MaterialWarning materialWarning = materialWarningService.getById(id);
mmap.put("materialWarning", materialWarning);
return prefix + "/edit";
}
/**
* 修改保存物料报警
*/
@RequiresPermissions("config:materialWarning:edit")
@Log(title = "物料报警", action = BusinessType.UPDATE)
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(MaterialWarning materialWarning) {
return toAjax(materialWarningService.updateById(materialWarning));
}
/**
* 删除物料报警
*/
@RequiresPermissions("config:materialWarning:remove")
@Log(title = "物料报警", action = BusinessType.DELETE)
@PostMapping("/remove")
@ResponseBody
public AjaxResult remove(String ids) {
if (StringUtils.isEmpty(ids)) {
return AjaxResult.error("id不能为空");
}
return toAjax(materialWarningService.removeByIds(Arrays.asList(Convert.toIntArray(ids))));
}
@PostMapping("/getMaterialWarningProp")
@ResponseBody
public AjaxResult getMaterialWarningProp() {
List<MaterialWarning> warningList = materialWarningService.list();
if(warningList == null || warningList.size() <= 0) {
return AjaxResult.error("没有配置物料警告");
}
int lowerNum = 0, upperNum = 0;
for(MaterialWarning materialWarning : warningList) {
String materialCode = materialWarning.getMaterialCode();
BigDecimal uppper = materialWarning.getUpper();
BigDecimal lower = materialWarning.getLower();
LambdaQueryWrapper<InventoryMaterialSummary> inventoryDetailLambdaQueryWrapper = Wrappers.lambdaQuery();
inventoryDetailLambdaQueryWrapper.eq(InventoryMaterialSummary::getMaterialCode, materialCode);
List<InventoryMaterialSummary> list = inventoryMaterialSummaryService.list(inventoryDetailLambdaQueryWrapper);
if (list == null) {
list = Collections.emptyList();
}
//筛选库存汇总数据的专用方法
List<InventoryMaterialSummary> details = inventoryMaterialSummaryService.duplicateRemoval(list);
if(details == null || details.size() <= 0) {
if(lower.intValue() > 0) {
lowerNum++;
}
} else {
InventoryMaterialSummary inventoryMaterialSummary = details.get(0);
BigDecimal qty = inventoryMaterialSummary.getQty();
if(uppper.compareTo(qty) < 0) {
upperNum++;
} else if(lower.compareTo(qty) > 0) {
lowerNum++;
}
}
}
MaterialSummary materialSummary = new MaterialSummary();
materialSummary.setLower(lowerNum);
materialSummary.setUpper(upperNum);
return AjaxResult.success(materialSummary);
}
@PostMapping("/getLowerWarning")
@ResponseBody
public AjaxResult getLowerWarning() {
List<MaterialWarning> warningList = materialWarningService.list();
if(warningList == null || warningList.size() <= 0) {
return AjaxResult.error("没有配置物料警告");
}
List<InventoryMaterialSummary> inventoryMaterialSummaryArrayList = new ArrayList<>();
for(MaterialWarning materialWarning : warningList) {
String materialCode = materialWarning.getMaterialCode();
String materialName = materialWarning.getMaterialName();
String materialUnit = materialWarning.getMaterialUnit();
BigDecimal uppper = materialWarning.getUpper();
BigDecimal lower = materialWarning.getLower();
LambdaQueryWrapper<InventoryMaterialSummary> inventoryDetailLambdaQueryWrapper = Wrappers.lambdaQuery();
inventoryDetailLambdaQueryWrapper.eq(InventoryMaterialSummary::getMaterialCode, materialCode);
List<InventoryMaterialSummary> list = inventoryMaterialSummaryService.list(inventoryDetailLambdaQueryWrapper);
if (list == null) {
list = Collections.emptyList();
}
//筛选库存汇总数据的专用方法
List<InventoryMaterialSummary> details = inventoryMaterialSummaryService.duplicateRemoval(list);
if(details == null || details.size() <= 0) {
if(lower.intValue() > 0) {
InventoryMaterialSummary inventoryMaterialSummary = new InventoryMaterialSummary();
inventoryMaterialSummary.setMaterialCode(materialCode);
inventoryMaterialSummary.setUserDef1(String.valueOf(lower));
inventoryMaterialSummary.setMaterialName(materialName);
inventoryMaterialSummary.setMaterialUnit(materialUnit);
inventoryMaterialSummaryArrayList.add(inventoryMaterialSummary);
}
} else {
InventoryMaterialSummary inventoryMaterialSummary = details.get(0);
BigDecimal qty = inventoryMaterialSummary.getQty();
if(lower.compareTo(qty) > 0) {
BigDecimal def1 = lower.subtract(qty);
inventoryMaterialSummary.setUserDef1(String.valueOf(def1.intValue()));
inventoryMaterialSummaryArrayList.add(inventoryMaterialSummary);
}
}
}
return AjaxResult.success(inventoryMaterialSummaryArrayList);
}
@PostMapping("/getUpperWarning")
@ResponseBody
public AjaxResult getUpperWarning() {
List<MaterialWarning> warningList = materialWarningService.list();
if(warningList == null || warningList.size() <= 0) {
return AjaxResult.error("没有配置物料警告");
}
List<InventoryMaterialSummary> inventoryMaterialSummaryArrayList = new ArrayList<>();
for(MaterialWarning materialWarning : warningList) {
String materialCode = materialWarning.getMaterialCode();
BigDecimal uppper = materialWarning.getUpper();
BigDecimal lower = materialWarning.getLower();
LambdaQueryWrapper<InventoryMaterialSummary> inventoryDetailLambdaQueryWrapper = Wrappers.lambdaQuery();
inventoryDetailLambdaQueryWrapper.eq(InventoryMaterialSummary::getMaterialCode, materialCode);
List<InventoryMaterialSummary> list = inventoryMaterialSummaryService.list(inventoryDetailLambdaQueryWrapper);
if (list == null) {
list = Collections.emptyList();
}
//筛选库存汇总数据的专用方法
List<InventoryMaterialSummary> details = inventoryMaterialSummaryService.duplicateRemoval(list);
if(details == null || details.size() <= 0) {
} else {
InventoryMaterialSummary inventoryMaterialSummary = details.get(0);
BigDecimal qty = inventoryMaterialSummary.getQty();
if(uppper.compareTo(qty) < 0) {
BigDecimal def1 = qty.subtract(uppper);
inventoryMaterialSummary.setUserDef1(String.valueOf(def1.intValue()));
inventoryMaterialSummaryArrayList.add(inventoryMaterialSummary);
}
}
}
return AjaxResult.success(inventoryMaterialSummaryArrayList);
}
}