luxiaotao1123
2023-12-30 f28b3a9131d2313a889f4a3156dcfabcefce7a84
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
package com.zy.asrs.wms.controller;
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zy.asrs.common.wms.entity.LocDetl;
import com.zy.asrs.common.wms.entity.Mat;
import com.zy.asrs.common.wms.service.LocDetlService;
import com.zy.asrs.common.wms.service.MatService;
import com.zy.asrs.framework.annotations.ManagerAuth;
import com.zy.asrs.framework.common.Cools;
import com.zy.asrs.framework.common.R;
import com.zy.asrs.framework.domain.KeyValueVo;
import com.zy.asrs.framework.common.DateUtils;
import com.zy.asrs.common.web.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.util.*;
 
@RestController
public class LocDetlController extends BaseController {
 
    @Autowired
    private LocDetlService locDetlService;
    @Autowired
    private MatService matService;
 
    @RequestMapping(value = "/locDetl/{id}/auth")
    @ManagerAuth
    public R get(@PathVariable("id") String id) {
        return R.ok(locDetlService.getById(String.valueOf(id)));
    }
 
    @RequestMapping(value = "/locDetl/page/auth")
    @ManagerAuth
    public R page(@RequestParam(defaultValue = "1") Integer curr,
                  @RequestParam(defaultValue = "10") Integer limit,
                  @RequestParam(required = false) String condition,
                  @RequestParam(required = false) String timeRange,
                  @RequestParam Map<String, Object> param) {
        LambdaQueryWrapper<LocDetl> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(LocDetl::getHostId, getHostId());
        if (!Cools.isEmpty(condition)) {
            wrapper.like(LocDetl::getLocNo, condition);
        }
        if (!Cools.isEmpty(timeRange)) {
            String[] range = timeRange.split(RANGE_TIME_LINK);
            wrapper.ge(LocDetl::getAppeTime, DateUtils.convert(range[0]));
            wrapper.le(LocDetl::getAppeTime, DateUtils.convert(range[1]));
        }
        if (!Cools.isEmpty(param.get("loc_no"))) {
            wrapper.eq(LocDetl::getLocNo, param.get("loc_no"));
        }
        return R.ok(locDetlService.page(new Page<>(curr, limit), wrapper));
    }
 
 
    @RequestMapping(value = "/locDetl/add/auth")
    @ManagerAuth
    public R add(LocDetl locDetl) {
        locDetl.setHostId(getHostId());
        locDetlService.save(locDetl);
        return R.ok();
    }
 
    @RequestMapping(value = "/locDetl/update/auth")
    @ManagerAuth
    public R update(LocDetl locDetl){
        if (Cools.isEmpty(locDetl) || null==locDetl.getLocNo()){
            return R.error();
        }
        locDetlService.updateById(locDetl);
        return R.ok();
    }
 
    @RequestMapping(value = "/locDetl/delete/auth")
    @ManagerAuth
    public R delete(@RequestParam(value="ids[]") Long[] ids){
         for (Long id : ids){
            locDetlService.removeById(id);
        }
        return R.ok();
    }
 
    @RequestMapping(value = "/locDetlQuery/auth")
    @ManagerAuth
    public R query(String condition) {
        LambdaQueryWrapper<LocDetl> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(LocDetl::getHostId, getHostId());
        wrapper.like(LocDetl::getLocNo, condition);
        Page<LocDetl> page = locDetlService.page(new Page<>(0, 10), wrapper);
        List<Map<String, Object>> result = new ArrayList<>();
        for (LocDetl locDetl : page.getRecords()){
            Map<String, Object> map = new HashMap<>();
            map.put("id", locDetl.getLocNo());
            map.put("value", locDetl.getLocNo());
            result.add(map);
        }
        return R.ok(result);
    }
 
    @RequestMapping("/locDetl/all/get/kv")
    @ManagerAuth
    public R getDataKV(@RequestParam(required = false) String condition) {
        List<KeyValueVo> vos = new ArrayList<>();
        LambdaQueryWrapper<LocDetl> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(LocDetl::getHostId, getHostId());
        if (!Cools.isEmpty(condition)) {
            wrapper.like(LocDetl::getLocNo, condition);
        }
        locDetlService.page(new Page<>(1, 30), wrapper).getRecords().forEach(item -> vos.add(new KeyValueVo(String.valueOf(item.getLocNo()), Long.parseLong(item.getLocNo()))));
        return R.ok().add(vos);
    }
 
    @RequestMapping(value = "/locDetl/statis/auth")
    @ManagerAuth
    public R statis(@RequestParam(defaultValue = "1")Integer curr,
                    @RequestParam(defaultValue = "10")Integer limit,
                    @RequestParam Map<String, Object> param) {
        IPage<LocDetl> stockStatis = locDetlService.getStockStatis(curr, limit, param);
        for (LocDetl locDetl : stockStatis.getRecords()) {
            Mat mat = matService.getOne(new LambdaQueryWrapper<Mat>()
                    .eq(Mat::getMatnr, locDetl.getMatnr())
                    .eq(Mat::getHostId, getHostId()));
            if (mat != null) {
                locDetl.sync(mat);
            }
        }
        return R.ok().add(stockStatis);
    }
 
    /**
     * 获取库存总数
     * @return
     */
    @RequestMapping("/locDetl/count")
    public R getAllCount(){
        Integer sum = locDetlService.sum();
        return R.ok(sum);
    }
 
    @RequestMapping(value = "/stock/out/list/auth")
    @ManagerAuth
    public R stockOutList(@RequestParam(defaultValue = "1")Integer curr,
                          @RequestParam(defaultValue = "10")Integer limit,
                          @RequestParam Map<String, Object> param){
        if (!Cools.isEmpty(param.get("modi_time"))){
            String val = String.valueOf(param.get("modi_time"));
            if (val.contains(RANGE_TIME_LINK)) {
                String[] dates = val.split(RANGE_TIME_LINK);
                param.put("startTime", DateUtils.convert(dates[0]));
                param.put("endTime", DateUtils.convert(dates[1]));
                param.remove("modi_time");
            }
        }
        param.put("hostId", getHostId());
        return R.ok(locDetlService.getStockOut(curr, limit, param));
    }
 
}