黎星凯
2024-04-15 62b6a7fac3f2acde70b578431147c4a01f19c182
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
package com.consum.base.controller;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
 
import javax.servlet.http.HttpServletResponse;
 
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import com.consum.base.BaseController;
import com.consum.base.core.utils.CommonUtil;
import com.consum.base.core.utils.PageUtil;
import com.consum.base.pojo.excel.InventoryExcelTemplate;
import com.consum.base.pojo.query.LWhFormInventoryQry;
import com.consum.base.pojo.request.FormInventoryParam;
import com.consum.base.pojo.request.LWhFormInventoryParam;
import com.consum.base.pojo.response.FormInventoryDetailVO;
import com.consum.base.pojo.response.FormInventoryGoodsVO;
import com.consum.base.pojo.response.FormInventoryVO;
import com.consum.base.service.FinSysTenantUserService;
import com.consum.base.service.LWhFormInventoryService;
import com.consum.model.po.FinSysTenantUser;
import com.consum.model.po.LWhFormInventory;
import com.iplatform.model.po.S_user_core;
import com.walker.db.page.GenericPager;
import com.walker.infrastructure.utils.CollectionUtils;
import com.walker.infrastructure.utils.DateUtils;
import com.walker.web.ResponseValue;
 
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
 
/**
 * @Description 盘点
 * @Author 卢庆阳
 * @Date 2023/10/23
 */
@Api(value = "盘点", tags = "盘点")
@RestController
@RequestMapping("/pc/l/wh/form/inventory")
public class LWhFormInventoryController extends BaseController {
 
    @Autowired
    private LWhFormInventoryService lWhFormInventoryService;
    @Autowired
    private FinSysTenantUserService finSysTenantUserService;
 
    /**
     * @Description 新增
     * @Author 卢庆阳
     * @Date 2023/10/31
     */
    @ApiOperation(value = "新增盘点", notes = "新增盘点")
    @ApiImplicitParams({@ApiImplicitParam(name = "param", value = "盘点单信息", dataType = "FormInventoryParam")})
    @PostMapping("/add")
    public ResponseValue add() {
 
        FormInventoryParam param = CommonUtil.getObjFromReqBody(FormInventoryParam.class);
        FormInventoryParam formInventoryParam = new FormInventoryParam();
        CommonUtil.copyProperties(param, formInventoryParam);
        param = formInventoryParam;
 
        FinSysTenantUser sysInfo = this.getSysInfo();
        if (sysInfo == null) {
            return ResponseValue.error("登录用户信息不存在");
        }
        // 根据盘点人id查询盘点人
        // 盘点人id为sysUserId字段查询
        FinSysTenantUser finSysTenantUser = new FinSysTenantUser();
        finSysTenantUser.setSysUserId(param.getOperatorUserId());
        FinSysTenantUser operatorUser =
                finSysTenantUserService.select(finSysTenantUser).stream().findFirst().orElse(null);
        // 根据监盘人id查询监盘人
        FinSysTenantUser monitorUserInfo = new FinSysTenantUser();
        monitorUserInfo.setId(param.getMonitorUserId());
        FinSysTenantUser monitorUser = finSysTenantUserService.get(monitorUserInfo);
        int result = lWhFormInventoryService.add(param, this.getSysInfo(), operatorUser, monitorUser);
        if (result > 0) {
            return ResponseValue.success();
        }
        return ResponseValue.error("新增失败!");
    }
 
    /**
     * @Description 盘点单列表查询
     * @Author 卢庆阳
     * @Date 2023/10/31
     */
    @ApiOperation(value = "盘点单列表查询", notes = "盘点单列表查询")
    @ApiImplicitParams({@ApiImplicitParam(name = "param", value = "盘点条件", dataType = "LWhFormInventoryParam",
            required = true, paramType = "query")})
    @GetMapping("/list")
    public ResponseValue queryList() {
        LWhFormInventoryQry param = CommonUtil.getObjFromReq(LWhFormInventoryQry.class);
        LWhFormInventoryQry param2 = new LWhFormInventoryQry();
        CommonUtil.copyProperties(param, param2);
        param = param2;
 
        FinSysTenantUser sysInfo = this.getSysInfo();
        if (sysInfo == null) {
            return ResponseValue.error("登录用户信息不存在");
        }
        GenericPager<LWhFormInventory> pager = lWhFormInventoryService.queryList(param, sysInfo);
        return ResponseValue.success(pager);
    }
 
    /**
     * 查询此账号角色,是否现在还可以增加盘点任务
     *
     * @return
     */
    @ApiOperation(value = "查询此账号角色,是否现在还可以增加盘点任务", notes = "查询此账号角色,是否现在还可以增加盘点任务")
    @ApiImplicitParams({@ApiImplicitParam(name = "param", value = "盘点条件", dataType = "LWhFormInventoryParam",
            required = true, paramType = "query")})
    @GetMapping("/isAddInventory")
    public ResponseValue isAddInventory() {
        LWhFormInventoryQry param = CommonUtil.getObjFromReq(LWhFormInventoryQry.class);
        LWhFormInventoryQry param2 = new LWhFormInventoryQry();
        CommonUtil.copyProperties(param, param2);
        param = param2;
        FinSysTenantUser sysInfo = this.getSysInfo();
        if (sysInfo == null) {
            return ResponseValue.error("登录用户信息不存在");
        }
        Integer res = lWhFormInventoryService.isAddInventory(param, sysInfo);
        return ResponseValue.success(res);
    }
 
    @ApiOperation(value = "盘点单物品列表查询", notes = "盘点单物品列表查询", response = FormInventoryVO.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "盘点单id", dataType = "Long", required = true, paramType = "query")})
    @ApiResponse(code = 200, message = "成功", response = FormInventoryVO.class)
    @GetMapping("/query")
    public ResponseValue queryInventBaseGoodTemplate(Long id) {
        FinSysTenantUser sysInfo = this.getSysInfo();
        if (sysInfo == null) {
            return ResponseValue.error("登录用户信息不存在");
        }
        if (id == null) {
            return ResponseValue.error("参数不能为空");
        }
        // 通过机构查询相关的模板信息
        FormInventoryVO formInventoryVO = lWhFormInventoryService.queryInventBaseGoodTemplate(id);
 
        // 保存后返回记录信息
        FormInventoryVO result = lWhFormInventoryService.saveInventory(formInventoryVO, id);
        return ResponseValue.success(result);
    }
 
    /**
     * @Description 编辑
     * @Author 卢庆阳
     * @Date 2023/10/31
     */
    @ApiOperation(value = "编辑盘点", notes = "编辑盘点")
    @ApiImplicitParams({@ApiImplicitParam(name = "param", value = "盘点单信息", dataType = "FormInventoryParam")})
    @PostMapping("/edit")
    public ResponseValue edit() {
        FormInventoryParam param = CommonUtil.getObjFromReqBody(FormInventoryParam.class);
        FormInventoryParam formInventoryParam = new FormInventoryParam();
        CommonUtil.copyProperties(param, formInventoryParam);
        param = formInventoryParam;
 
        LWhFormInventory lWhFormInventory = lWhFormInventoryService.get(new LWhFormInventory(param.getId()));
        if (lWhFormInventory == null) {
            return ResponseValue.error("编辑失败!");
        }
        if (lWhFormInventory.getStates() != 0) {
            return ResponseValue.error("未开始状态才能编辑!");
        }
        int num = lWhFormInventoryService.delete(new LWhFormInventory(param.getId()));
        if (num == 0) {
            return ResponseValue.error("编辑失败!");
        }
 
        // 根据盘点人id查询盘点人
        FinSysTenantUser finSysTenantUser = new FinSysTenantUser();
        finSysTenantUser.setId(param.getOperatorUserId());
        FinSysTenantUser operatorUser = finSysTenantUserService.get(finSysTenantUser);
        // 根据监盘人id查询监盘人
        FinSysTenantUser monitorUserInfo = new FinSysTenantUser();
        monitorUserInfo.setId(param.getMonitorUserId());
        FinSysTenantUser monitorUser = finSysTenantUserService.get(monitorUserInfo);
        int result = lWhFormInventoryService.add(param, this.getSysInfo(), operatorUser, monitorUser);
 
        if (result > 0) {
            return ResponseValue.success();
        }
 
        return ResponseValue.error("编辑失败!");
    }
 
    /**
     * @Description 根据id删除
     */
    @ApiOperation(value = "根据id删除盘点", notes = "根据id删除盘点")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "盘点单id", dataType = "Long", required = true, paramType = "query")})
    @DeleteMapping("/del")
    public ResponseValue delById(Long id) {
        if (id == null) {
            return ResponseValue.error("参数不能为空!");
        }
        LWhFormInventory lWhFormInventory = lWhFormInventoryService.get(new LWhFormInventory(id));
        if (lWhFormInventory == null) {
            return ResponseValue.error("删除失败!");
        }
        if (lWhFormInventory.getStates() != 0) {
            return ResponseValue.error("未开始状态才能删除!");
        }
        int num = lWhFormInventoryService.delete(new LWhFormInventory(id));
        if (num == 0) {
            return ResponseValue.error("删除失败!");
        }
 
        return ResponseValue.success(1);
    }
 
    /**
     * 暂存
     *
     * @author 卢庆阳
     * @date 2023/10/31
     */
    @ApiOperation(value = "盘点暂存", notes = "盘点暂存")
    @ApiImplicitParams({@ApiImplicitParam(name = "param", value = "盘点单信息", dataType = "LWhFormInventoryDto")})
    @PostMapping("/temporary/storage")
    public ResponseValue updateTemporaryStorage() {
        LWhFormInventoryParam param = CommonUtil.getObjFromReqBody(LWhFormInventoryParam.class);
        LWhFormInventoryParam formInventoryParam = new LWhFormInventoryParam();
        CommonUtil.copyProperties(param, formInventoryParam);
        param = formInventoryParam;
 
        if (param == null) {
            return ResponseValue.error("参数错误");
        }
 
        int num = lWhFormInventoryService.updateInventoryInfo(param, 1, null, null);
        return num > 0 ? ResponseValue.success(1) : ResponseValue.error("暂存失败!");
    }
 
    /**
     * 完成盘点
     *
     * @author 卢庆阳
     * @date 2023/10/31
     */
    @ApiOperation(value = "完成盘点", notes = "完成盘点")
    @ApiImplicitParams({@ApiImplicitParam(name = "param", value = "盘点单信息", dataType = "LWhFormInventoryDto")})
    @PostMapping("/finish")
    public ResponseValue updateFinishPd() {
        LWhFormInventoryParam param = CommonUtil.getObjFromReqBody(LWhFormInventoryParam.class);
        LWhFormInventoryParam formInventoryParam = new LWhFormInventoryParam();
        CommonUtil.copyProperties(param, formInventoryParam);
        param = formInventoryParam;
 
        if (param == null) {
            return ResponseValue.error("参数错误");
        }
        S_user_core currentUser = this.getCurrentUser();
        FinSysTenantUser sysInfo = this.getSysInfo();
        int num = lWhFormInventoryService.updateInventoryInfo(param, 2, currentUser, sysInfo);
 
        return num > 0 ? ResponseValue.success(1) : ResponseValue.error("盘点失败!");
    }
 
    /**
     * @Description 异常明细列表查询
     * @Author 卢庆阳
     * @Date 2023/11/1
     */
    @ApiOperation(value = "异常明细列表查询", notes = "异常明细列表查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "param", value = "盘点条件", dataType = "LWhFormInventoryParam", paramType = "query")})
    @GetMapping("/list/PdDetail")
    public ResponseValue queryPdDetailList() {
        LWhFormInventoryQry param = CommonUtil.getObjFromReq(LWhFormInventoryQry.class);
        LWhFormInventoryQry param2 = new LWhFormInventoryQry();
        CommonUtil.copyProperties(param, param2);
        param = param2;
 
        FinSysTenantUser sysInfo = this.getSysInfo();
        if (sysInfo == null) {
            return ResponseValue.error("登录用户信息不存在");
        }
        PageUtil<FormInventoryDetailVO> result = lWhFormInventoryService.queryPdDetailList(param, sysInfo);
        return ResponseValue.success(result);
    }
 
    @ApiOperation(value = "根据id查询盘点物品详细信息", notes = "根据id查询盘点物品详细信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "盘点id", dataType = "Long", required = true, paramType = "query")})
    @GetMapping("/detail")
    public ResponseValue selectDetailById(Long id) {
        FinSysTenantUser sysInfo = this.getSysInfo();
        if (sysInfo == null) {
            return ResponseValue.error("登录用户信息不存在");
        }
        FormInventoryVO formInventoryVO = new FormInventoryVO();
 
        LWhFormInventory lWhFormInventory = new LWhFormInventory();
        lWhFormInventory.setId(id);
        LWhFormInventory item = lWhFormInventoryService.get(lWhFormInventory);
        if (Objects.isNull(item)) {
            return ResponseValue.error("盘点单不存在");
        }
        BeanUtils.copyProperties(item, formInventoryVO);
        List<FormInventoryGoodsVO> formInventoryGoodsVOS = lWhFormInventoryService.selectDetailById(id);
        formInventoryVO.setFormInventoryGoodsList(formInventoryGoodsVOS);
        return ResponseValue.success(formInventoryVO);
    }
 
    @ApiOperation(value = "盘点单导出", notes = "盘点单导出")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "盘点单id", dataType = "Long", required = true, paramType = "query")})
    @GetMapping("/list/export")
    public ResponseValue<String> export(Long id, HttpServletResponse response) throws Exception {
 
        List<InventoryExcelTemplate> exportList = lWhFormInventoryService.getExportList(id);
        if (CollectionUtils.isEmpty(exportList)) {
            throw new RuntimeException("数据为空");
        }
        TemplateExportParams params = new TemplateExportParams("import/低值易耗品盘点表.xls");
        params.setHeadingStartRow(2);
 
        Optional<InventoryExcelTemplate> first = exportList.stream().findFirst();
        InventoryExcelTemplate inventoryExcelTemplate = first.get();
        Long createTime = inventoryExcelTemplate.getCreateTime();
        String operatorName = inventoryExcelTemplate.getOperatorName();
        String monitorName = inventoryExcelTemplate.getMonitorName();
        Long endTime = inventoryExcelTemplate.getEndTime();
 
        Map<String, Object> map = new HashMap<>();
        map.put("date", DateUtils.toShowDate(createTime));
        map.put("endDate", DateUtils.toShowDate(endTime));
        map.put("monitorName", monitorName);
        map.put("name", operatorName);
        Workbook workbook = ExcelExportUtil.exportExcel(params, InventoryExcelTemplate.class, exportList, map);
        String filePath = downLoadExcel("低值易耗品盘点表", workbook);
        return ResponseValue.success("导出成功", filePath);
    }
 
}