Blame view

src/main/java/com/huaheng/pc/config/materialWarnning/controller/MaterialWarningController.java 15 KB
1
2
3
4
package com.huaheng.pc.config.materialWarnning.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
5
import com.huaheng.common.utils.DateUtils;
周鸿 authored
6
import com.huaheng.common.utils.Wrappers;
7
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
tongzhonghao authored
8
import com.huaheng.common.utils.poi.ExcelUtil;
9
import com.huaheng.common.utils.security.ShiroUtils;
10
11
12
13
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;
14
15
import com.huaheng.pc.config.material.domain.Material;
import com.huaheng.pc.config.material.service.MaterialService;
游杰 authored
16
17
18
19
20
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;
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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;
tongzhonghao authored
37
import org.springframework.web.multipart.MultipartFile;
38
39
import javax.annotation.Resource;
游杰 authored
40
41
import java.math.BigDecimal;
import java.util.*;
42
43
44
45
46
47
48
49

/**
 * 物料报警 信息操作处理
 *
 * @author huaheng
 * @date 2020-07-17
 */
@Controller
lector authored
50
@RequestMapping("/config/materialWarning")
51
public class MaterialWarningController extends BaseController {
lector authored
52
    private String prefix = "config/materialWarning";
53
54
55
    @Resource
    private IMaterialWarningService materialWarningService;
游杰 authored
56
57
58
59
    @Resource
    private InventoryDetailService inventoryDetailService;
    @Resource
    private InventoryMaterialSummaryService inventoryMaterialSummaryService;
60
61
    @Resource
    private MaterialService materialService;
62
63
64
65
66
67

    @RequiresPermissions("config:materialWarning:view")
    @GetMapping()
    public String materialWarning() {
        return prefix + "/materialWarning";
    }
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
    /**
     * 查询物料报警列表
     */
    @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())
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
                .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);
        }
    }
106
107
108
109
110
111
112
113
    /**
     * 新增物料报警
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }
114
115
116
117
118
119
120
121
122
123
124
    /**
     * 新增保存物料报警
     */
    @RequiresPermissions("config:materialWarning:add")
    @Log(title = "物料报警", action = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MaterialWarning materialWarning) {
        return materialWarningService.addSave(materialWarning);
    }
125
126
127
128
129
130
131
132
133
134
    /**
     * 修改物料报警
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap) {
        MaterialWarning materialWarning = materialWarningService.getById(id);
        mmap.put("materialWarning", materialWarning);
        return prefix + "/edit";
    }
135
136
137
138
139
140
141
142
143
    /**
     * 修改保存物料报警
     */
    @RequiresPermissions("config:materialWarning:edit")
    @Log(title = "物料报警", action = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MaterialWarning materialWarning) {
144
145
146
147
148
149
150
        String materialCode = materialWarning.getMaterialCode();
        Material material = materialService.getMaterialByCode(materialCode);
        materialWarning.setMaterialName(material.getName());
        materialWarning.setMaterialSpec(material.getSpec());
        materialWarning.setMaterialUnit(material.getUnit());
        materialWarning.setLastUpdatedBy(ShiroUtils.getLoginName());
        materialWarning.setLastUpdated(DateUtils.getNowDate());
151
152
        return toAjax(materialWarningService.updateById(materialWarning));
    }
153
154
155
156
157
158
159
160
161
162
163
164
165
166
    /**
     * 删除物料报警
     */
    @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))));
    }
167
游杰 authored
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
    @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);
    }
tongzhonghao authored
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

    /**
     * 导出模板
     *
     * @return
     * @throws Exception
     */
    @GetMapping("/importTemplate")
    @ResponseBody
    public AjaxResult importTemplate () {
        ExcelUtil<MaterialWarning> util = new ExcelUtil<>(MaterialWarning.class);
        return util.importTemplateExcel("物料预警添加");
    }

    /**
     * 导入物料预警
     * @param file
     * @return
     * @throws Exception
     */
    @PostMapping("/importData")
    @ResponseBody
    public AjaxResult importData (MultipartFile file) throws Exception {
        ExcelUtil<MaterialWarning> util = new ExcelUtil<>(MaterialWarning.class);
        List<MaterialWarning> list = util.importExcel(file.getInputStream());
        String operName = ShiroUtils.getLoginName();

        String message = materialWarningService.insertExcelData(list, false, operName);

        return AjaxResult.success(message);
    }
318
}