cy
2023-11-29 d6a442fa7c8b9be884870c030968786b8f04b2d6
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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
package com.consum.base.controller;
 
import cn.hutool.core.util.ReflectUtil;
import com.consum.base.BaseController;
import com.consum.base.core.utils.IdUtil;
import com.consum.base.core.utils.MapUtils;
import com.consum.base.core.utils.MapperUtil;
import com.consum.base.pojo.GoodsUseRecordVO;
import com.consum.base.pojo.LWhFormTransferGoodsInfoParam;
import com.consum.base.pojo.RecordUserInfoVO;
import com.consum.base.pojo.UseRecordSkuVO;
import com.consum.base.pojo.dto.UseRecordDTO;
import com.consum.base.pojo.query.TransferQry;
import com.consum.base.pojo.request.LWhFormTransferParam;
import com.consum.base.pojo.request.ProcureModelInfoParam;
import com.consum.base.pojo.response.FormTransferVO;
import com.consum.base.pojo.response.FromTransferTemplateInfoVO;
import com.consum.base.pojo.response.LWHFromTransferExtendVO;
import com.consum.base.pojo.response.TransferInfoVO;
import com.consum.base.service.*;
import com.consum.model.po.*;
import com.consum.model.vo.LWhFormOutputVo;
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 io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.compress.utils.Lists;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.lang.reflect.Field;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * @Description 调拨管理
 * @Author 卢庆阳
 * @Date 2023/10/30
 */
@RestController
@RequestMapping("/pc/l/wh/form/transfer")
@Api(value = "调拨分发管理", tags = "调拨分发管理")
public class LWhFormTransferController extends BaseController {
 
    @Autowired
    private LWhFormTransferServiceImpl lWhFormTransferService;
    @Autowired
    private LWhProcureModelService lWhProcureModelService;
    @Autowired
    private LWhFormTransferCoreService lWhFormTransferCoreService;
    @Autowired
    private LWhProcureModelUserServiceImpl lWhProcureModelUserService;
    @Autowired
    private LWhProcureModelUserRecordServiceImpl lWhProcureModelUserRecordService;
    @Autowired
    private BaseGoodsModelsServiceImpl baseGoodsModelsService;
    @Autowired
    private BaseWarehouseServiceImpl baseWarehouseService;
 
    /**
     * @Description 新增
     */
    @ApiOperation(value = "单据新增", notes = "单据新增")
    @ApiImplicitParam(name = "param", value = "单据新增", required = true, dataType = "LWhFormTransferParam")
    @PostMapping("/add")
    public ResponseValue add(@RequestBody LWhFormTransferParam param) throws Exception {
        S_user_core currentUser = this.getCurrentUser();
        if (currentUser == null) {
            return ResponseValue.error("登录用户信息不存在");
        }
        List<LWhFormTransferGoodsInfoParam> transferGoods = param.getTransferGoods();
        if (CollectionUtils.isEmpty(transferGoods)) {
            return ResponseValue.error("调拨单不能为空");
        }
        int result = this.lWhFormTransferService.add(param, this.getSysInfo());
        if (result > 0) {
            return ResponseValue.success();
        }
        return ResponseValue.error("新增失败!");
    }
 
    /**
     * @Description 列表查询(调拨明细)
     * @Author 卢庆阳
     * @Date 2023/10/30
     * <p>
     * 1.查询调拨单
     * <p>
     * 2.查询物品型号
     */
    @ApiOperation(value = "单据列表查询", notes = "单据列表查询")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "page", value = "页码", required = true, dataType = "int"),
        @ApiImplicitParam(name = "size", value = "每页条数", required = true, dataType = "int"),
        @ApiImplicitParam(name = "param", value = "条件参数", required = true, dataType = "TransferQry"),
    })
    @GetMapping("/list")
    public ResponseValue queryFormTransferList(TransferQry param) {
        S_user_core currentUser = this.getCurrentUser();
        if (currentUser == null) {
            return ResponseValue.error("登录用户信息不存在");
        }
        /*当前登录人只能看到自己机构下的列表*/
        GenericPager genericPager = lWhFormTransferService.queryFormTransferList(param);
        List<LWhFormTransfer> datas = genericPager.getDatas();
        ArrayList<FormTransferVO> result = new ArrayList<>();
        if (!CollectionUtils.isEmpty(datas)) {
            datas.forEach(item -> {
                FormTransferVO formTransferVO = new FormTransferVO();
                BeanUtils.copyProperties(item, formTransferVO);
 
                List<FromTransferTemplateInfoVO> templateInfoList = Lists.newArrayList();
 
                // 查询型号数量
                String sql = "SELECT bgt.id,bgm.GOODS_TEMPLATES_ID,GOODS_NAME,sum( counts ) count FROM "
                    + "l_wh_procure_model pm LEFT JOIN base_goods_models bgm ON pm.BASE_GOODS_MODELS_ID = bgm.id "
                    + "LEFT JOIN base_goods_template bgt ON bgm.GOODS_TEMPLATES_ID = bgt.id "
                    + "WHERE pm.BUSINESS_ID =:id GROUP BY bgm.GOODS_TEMPLATES_ID";
                Map<String, Object> paramMap = new HashMap<>();
                paramMap.put("id", item.getId());
                List<Map<String, Object>> procureModelList = lWhProcureModelService.select(sql, paramMap, new MapperUtil());
                for (Map<String, Object> map : procureModelList) {
                    FromTransferTemplateInfoVO procureTemplateInfoVO = MapUtils.convertMapToObj(map, FromTransferTemplateInfoVO.class);
                    templateInfoList.add(procureTemplateInfoVO);
                }
                formTransferVO.setFromTransferTemplateInfoList(templateInfoList);
 
                result.add(formTransferVO);
            });
        }
        try {
            Field fieldDatas = GenericPager.class.getDeclaredField("datas");
//            fieldDatas.setAccessible(true);
//            fieldDatas.set(genericPager, result);
            ReflectUtil.setFieldValue(genericPager, fieldDatas, result);
 
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseValue.success(genericPager);
    }
 
    /**
     * @Description 根据id查询详情
     * @Author 卢庆阳
     * @Date 2023/10/30
     */
    @ApiOperation(value = "根据id查询详情", notes = "根据id查询详情")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "调拨单id", required = true, dataType = "Long"),
    })
    @GetMapping("/detail")
    public ResponseValue getById(Long id) {
        if (id == null) {
            return ResponseValue.error("调拨单id为空");
        }
        LWHFromTransferExtendVO vo = this.lWhFormTransferService.getById(id);
        return ResponseValue.success(vo);
    }
 
    @ApiOperation(value = "调拨明细列表", notes = "调拨明细列表")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "param", value = "条件", required = true, dataType = "TransferQry"),
    })
    @GetMapping("/detail/list")
    public ResponseValue queryFormTransferDetailList(TransferQry param) {
        FinSysTenantUser sysInfo = this.getSysInfo();
        if (sysInfo == null) {
            return ResponseValue.error("登录用户信息不存在");
        }
        GenericPager<Map<String, Object>> mapGenericPager = lWhFormTransferService.queryFormTransferDetailList(param);
 
        return ResponseValue.success(mapGenericPager);
    }
 
    /**
     * 撤销
     *
     * @author 卢庆阳
     * @date 2023/10/31
     */
    @ApiOperation(value = "撤销", notes = "撤销")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "调拨单id", required = true, dataType = "Long"),
    })
    @PostMapping("/updStatus")
    public ResponseValue updateStatus(Long id) {
        if (id == null) {
            return ResponseValue.error("参数错误");
        }
 
        int num = this.lWhFormTransferService.updateStatus(id);
        return num > 0 ? ResponseValue.success(1) : ResponseValue.error("修改失败!");
    }
 
    /**
     * @Description 调拨入库
     * @Author 卢庆阳
     * @Date 2023/10/31
     */
    @ApiOperation(value = "调拨入库", notes = "调拨入库")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "调拨单id", required = true, dataType = "Long"),
    })
    @PostMapping("/income")
    public ResponseValue income(Long id) {
        lWhFormTransferCoreService.doTransferInPut(id, getCurrentUser());
        return ResponseValue.success();
    }
 
    /**
     * @Description 调拨出库
     * @Author 卢庆阳
     * @Date 2023/10/31
     */
    @ApiOperation(value = "调拨出库", notes = "调拨出库")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "调拨单id", required = true, dataType = "Long"),
    })
    @PostMapping("/output")
    public ResponseValue output(Long id) {
        // 出库前 设置出库仓库
        FinSysTenantUser sysTenantUser = this.getSysInfo();
        String agencyId = sysTenantUser.getTenantId();
        List<BaseWarehouse> baseWarehouseList = baseWarehouseService.getByAgencyId(Long.valueOf(agencyId), (short) 1, (short) 1);
        if (CollectionUtils.isEmpty(baseWarehouseList)) {
            return ResponseValue.error("机构无默认仓库!");
        }
        BaseWarehouse baseWarehouse = baseWarehouseList.get(0);
        Long wareHouseId = baseWarehouse.getId();
        String warehouseName = baseWarehouse.getWarehouseName();
        LWhFormTransfer lWhFormTransfer = new LWhFormTransfer(id);
        lWhFormTransfer.setOutWarehouseId(wareHouseId);
        lWhFormTransfer.setOutWarehouseName(warehouseName);
        lWhFormTransferService.update(lWhFormTransfer);
        lWhFormTransferCoreService.doTransferOutPut(id, getCurrentUser());
        return ResponseValue.success();
    }
 
    /**
     * @Description 导出调拨出库单
     * @Author 卢庆阳
     * @Date 2023/10/31
     */
    @GetMapping("/export")
    public ResponseValue export(Long id) {
        if (id == null) {
            return ResponseValue.error("调拨单id为空");
        }
        LWhFormOutputVo vo = this.lWhFormTransferService.export(id, this.getCurrentUser());
        return ResponseValue.success(vo);
    }
 
 
    /**
     * 部门物品分发列表明细
     *
     * @param transferQry
     * @return
     */
    @ApiOperation(value = "部门物品分发列表明细", notes = "部门物品分发列表明细")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "transferQryDto", value = "调拨单查询条件", required = true)
    })
    @GetMapping("/department/list")
    public ResponseValue departmentTransferList(TransferQry transferQry) {
 
        S_user_core currentUser = this.getCurrentUser();
        if (currentUser == null) {
            return ResponseValue.error("登录用户信息不存在");
        }
        GenericPager<Map<String, Object>> transferInfoDetailsVoGenericPager = this.lWhFormTransferService.queryTransferInfo(transferQry);
        return ResponseValue.success(transferInfoDetailsVoGenericPager);
    }
 
 
    @ApiOperation(value = "使用人修改", notes = "使用人修改")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "procureModelInfoDto", value = "使用信息", required = true)
    })
    @PostMapping("/useInfo/update")
    public ResponseValue infoUpdate(@RequestBody List<ProcureModelInfoParam> procureModelInfoParam) {
 
        S_user_core currentUser = this.getCurrentUser();
        if (currentUser == null) {
            return ResponseValue.error("登录用户信息不存在");
        }
        if (CollectionUtils.isEmpty(procureModelInfoParam)) {
            return ResponseValue.error("参数错误");
        }
 
        Map<Long, List<ProcureModelInfoParam>> collect = procureModelInfoParam.stream()
            .collect(Collectors.groupingBy(ProcureModelInfoParam::getBaseGoodModelId));
        for (Map.Entry<Long, List<ProcureModelInfoParam>> entry : collect.entrySet()) {
            Long baseGoodModelId = entry.getKey();
 
            List<ProcureModelInfoParam> procureModelInfoList = entry.getValue();
            Optional<ProcureModelInfoParam> first = procureModelInfoList.stream().findFirst();
            ProcureModelInfoParam procureModelInf = first.get();
            Long businessId = procureModelInf.getBusinessId();
            LWhProcureModelUserRecord lWhProcureModelUserRecord = new LWhProcureModelUserRecord();
            lWhProcureModelUserRecord.setId(IdUtil.generateId());
            lWhProcureModelUserRecord.setTransBusinessId(businessId);
            FinSysTenantUser sysInfo = getSysInfo();
            lWhProcureModelUserRecord.setOperatorId(sysInfo.getId());
            lWhProcureModelUserRecord.setOperatorName(sysInfo.getUserName());
            lWhProcureModelUserRecord.setDealTime(DateUtils.getDateTimeNumber(System.currentTimeMillis()));
            lWhProcureModelUserRecordService.insert(lWhProcureModelUserRecord);
 
            List<LWhProcureModelUser> procureModelUserList = Lists.newArrayList();
            if (CollectionUtils.isEmpty(procureModelInfoList)) {
                for (ProcureModelInfoParam item : procureModelInfoList) {
                    LWhProcureModelUser lWhProcureModelUser = new LWhProcureModelUser();
                    lWhProcureModelUser.setId(IdUtil.generateId());
                    lWhProcureModelUser.setTransBusinessId(businessId);
                    lWhProcureModelUser.setProcureModelUserRecordId(lWhProcureModelUserRecord.getId());
                    lWhProcureModelUser.setWhProcureModelId(procureModelInf.getProcureModelId());
                    lWhProcureModelUser.setBaseGoodsModelsId(baseGoodModelId);
                    lWhProcureModelUser.setNowUserPhone(item.getPhone());
                    lWhProcureModelUser.setNowUserName(item.getUserName());
                    lWhProcureModelUser.setGoodsNum(item.getCount());
                    procureModelUserList.add(lWhProcureModelUser);
                }
 
                lWhProcureModelUserService.insert(procureModelUserList);
            }
 
        }
 
        return ResponseValue.success();
    }
 
    /**
     * 部门物品使用记录
     *
     * @param transferOrderId
     * @return
     */
    @ApiOperation(value = "部门物品使用人记录", notes = "部门物品使用人记录")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "transferOrderId", value = "调拨单id", required = true)
    })
    @GetMapping("/use/record")
    public ResponseValue useRecord(Long transferOrderId) {
 
        S_user_core currentUser = this.getCurrentUser();
        if (currentUser == null) {
            return ResponseValue.error("登录用户信息不存在");
        }
        List<UseRecordDTO> useRecordDTOList = lWhProcureModelUserService.selectUseRecord(transferOrderId);
        if (CollectionUtils.isEmpty(useRecordDTOList)) {
            return ResponseValue.error("未查询到使用记录");
        }
        List<GoodsUseRecordVO> result = Lists.newArrayList();
        //分组
        Map<Long, Map<Long, List<UseRecordDTO>>> collect = useRecordDTOList.stream()
            .collect(Collectors.groupingBy(UseRecordDTO::getId, Collectors.groupingBy(UseRecordDTO::getBaseGoodsModelsId)));
        //开始循环collect
        for (Map.Entry<Long, Map<Long, List<UseRecordDTO>>> entry : collect.entrySet()) {
            Long id = entry.getKey();
            Map<Long, List<UseRecordDTO>> value = entry.getValue();
            //开始循环value
            List<UseRecordSkuVO> useRecordSkuList = Lists.newArrayList();
            for (Map.Entry<Long, List<UseRecordDTO>> item : value.entrySet()) {
                List<UseRecordDTO> list = item.getValue();
                List<RecordUserInfoVO> recordUserInfoList = Lists.newArrayList();
                for (UseRecordDTO useRecordDto : list) {
 
                    GoodsUseRecordVO goodsUseRecordVO = new GoodsUseRecordVO();
                    goodsUseRecordVO.setId(id);
                    goodsUseRecordVO.setUpdateUserName(useRecordDto.getUpdateUserName());
                    goodsUseRecordVO.setUpdateTime(useRecordDto.getUpdateTime());
 
                    UseRecordSkuVO useRecordSkuVO = new UseRecordSkuVO();
                    useRecordSkuVO.setBaseGoodModelId(useRecordDto.getBaseGoodsModelsId());
                    useRecordSkuVO.setBaseGoodModelName(useRecordDto.getBaseGoodsModelsName());
                    useRecordSkuVO.setUnit(useRecordDto.getUnit());
                    useRecordSkuVO.setProcureModelId(useRecordDto.getProcureModelId());
 
                    RecordUserInfoVO recordUserInfoVO = new RecordUserInfoVO();
                    recordUserInfoVO.setUseName(useRecordDto.getUseName());
                    recordUserInfoVO.setPhone(useRecordDto.getPhone());
                    recordUserInfoVO.setNum(useRecordDto.getNum());
                    recordUserInfoList.add(recordUserInfoVO);
                    useRecordSkuVO.setRecordUserInfos(recordUserInfoList);
                    useRecordSkuList.add(useRecordSkuVO);
                    goodsUseRecordVO.setRecordSkuDtoList(useRecordSkuList);
                    result.add(goodsUseRecordVO);
                }
            }
        }
        return ResponseValue.success(result);
    }
 
 
    @ApiOperation(value = "查询部门下的分发单", notes = "查询部门下的分发单")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "agencyId", value = "机构id", required = true, dataType = "Long", paramType = "query")
    })
    @GetMapping("/query/detail")
    public ResponseValue queryDepartmentTransferOrder(Long agencyId) {
 
        TransferInfoVO transferInfoVO = new TransferInfoVO();
 
        lWhFormTransferService.queryDepartmentTransferOrder();
        return ResponseValue.success(transferInfoVO);
    }
 
    @ApiOperation(value = "查询部门下的分发单", notes = "查询部门下的分发单")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "agencyId", value = "机构id", required = true, dataType = "Long", paramType = "query")
    })
    @GetMapping("/query/transfList")
    public ResponseValue queryDepartmentTransferOrderList() {
 
        TransferInfoVO transferInfoVO = new TransferInfoVO();
 
        lWhFormTransferService.queryDepartmentTransferOrder();
        return ResponseValue.success(transferInfoVO);
    }
}