王佳豪
2021-05-31 bc666cce4e7905e99174195df033bcff1ed799d6
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
package com.zy.asrs.controller;
 
import com.alibaba.excel.EasyExcel;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.core.annotations.ManagerAuth;
import com.core.common.BaseRes;
import com.core.common.Cools;
import com.core.common.DateUtils;
import com.core.common.R;
import com.sun.org.apache.bcel.internal.generic.NEW;
import com.zy.asrs.entity.LocNormal;
import com.zy.asrs.entity.LocNormalReport;
import com.zy.asrs.entity.param.LocNormalParam;
import com.zy.asrs.service.LocNormalReportService;
import com.zy.asrs.service.LocNormalService;
import com.zy.common.utils.excel.locNomal.LocNormalExcel;
import com.zy.common.utils.excel.locNomal.LocNormalExcelListener;
import com.zy.common.utils.excel.matcode.MatCodeExcel;
import com.zy.common.utils.excel.matcode.MatCodeExcelListener;
import com.zy.common.web.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
 
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
 
import static jdk.nashorn.api.scripting.ScriptUtils.convert;
 
@RestController
public class LocNormalController extends BaseController {
    @Autowired
    private LocNormalService locNormalService;
    @Autowired
    private LocNormalReportService locNormalReportService;
 
    @RequestMapping(value = "/locNomal/list/auth")
    @ManagerAuth
    public R list(@RequestParam(defaultValue = "1") Integer curr,
                  @RequestParam(defaultValue = "10") Integer limit,
                  @RequestParam(required = false) String orderByField,
                  @RequestParam(required = false) String orderByType,
                  @RequestParam(required = false) String condition,
                  @RequestParam Map<String, Object> param) {
        excludeTrash(param);
        EntityWrapper<LocNormal> wrapper = new EntityWrapper<>();
        convert(param, wrapper);
        allLike(LocNormal.class, param.keySet(), wrapper, condition);
        if (!Cools.isEmpty(orderByField)) {
            wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));
        }
        if (Cools.isEmpty(param.get("state"))) {
            wrapper.in("state", "1,2");
        }
        return R.ok(locNormalService.selectPage(new Page<>(curr, limit), wrapper));
    }
 
    private <T> void convert(Map<String, Object> map, EntityWrapper<T> wrapper) {
        for (Map.Entry<String, Object> entry : map.entrySet()) {
            String val = String.valueOf(entry.getValue());
            if (val.contains(RANGE_TIME_LINK)) {
                String[] dates = val.split(RANGE_TIME_LINK);
                wrapper.ge(entry.getKey(), DateUtils.convert(dates[0]));
                wrapper.le(entry.getKey(), DateUtils.convert(dates[1]));
            } else {
                wrapper.like(entry.getKey(), String.valueOf(entry.getValue()));
            }
        }
    }
 
    @RequestMapping(value = "/locNomal/add/auth")
    @ManagerAuth
    public R add(LocNormal locNormalList) {
        // 插入创建信息
        locNormalList.setModiUser(getUserId());
        locNormalList.setModiTime(new Date());
        locNormalList.setAppeUser(getUserId());
        locNormalList.setAppeTime(new Date());
        // 默认新增为已入库
        locNormalList.setState("1");
        locNormalService.insert(locNormalList);
        return R.ok();
    }
 
    @RequestMapping(value = "/matnr/check/column/auth")
    @ManagerAuth
    public R query(@RequestBody JSONObject param) {
        Wrapper<LocNormal> wrapper = new EntityWrapper<LocNormal>().eq(humpToLine(String.valueOf(param.get("key"))), param.get("val"));
        if (null != locNormalService.selectOne(wrapper)) {
            return R.parse(BaseRes.REPEAT).add(getComment(LocNormal.class, String.valueOf(param.get("key"))));
        }
        return R.ok();
    }
 
    @RequestMapping(value = "/locNormal/update/auth")
    @ManagerAuth
    public void updateLocNormal(LocNormal param) {
        Long modiUser = getUserId();
        Date modiTime = new Date();
        locNormalService.updateLocNormal(param.getMatnr(), param.getAnfme(), modiUser, modiTime, param.getId());
    }
 
    @RequestMapping(value = "/locNormal/outLoc/auth")
    @ManagerAuth
    public void outLocNormal(LocNormal param) {
        Long modiUser = getUserId();
        Date modiTime = new Date();
        locNormalService.outLocNormal(param.getMatnr(), modiUser, modiTime, param.getId());
    }
 
    @RequestMapping(value = "/locNormal/removeLoc/auth")
    @ManagerAuth
    public void removeLoc(LocNormal param) {
        Long modiUser = getUserId();
        Date modiTime = new Date();
        locNormalService.removeLocNormal(param.getMatnr(), modiUser, modiTime, param.getId());
    }
 
    /* 导入 */
    @RequestMapping(value = "/locNormal/import/auth")
    @ManagerAuth(memo = "平仓管理导入")
    @Transactional
    public R locNormalImport(MultipartFile file) throws IOException, InterruptedException {
        LocNormalExcelListener listener = new LocNormalExcelListener(getUserId());
        EasyExcel.read(file.getInputStream(), LocNormalExcel.class, listener).sheet().doRead();
        return R.ok("成功导入" + listener.getTotal() + "条物料信息");
    }
 
    /* 平仓入库 */
    @RequestMapping(value = "/locNormal/in")
    @ManagerAuth(memo = "平仓入库")
    @Transactional
    public R locNormalIn(@RequestBody LocNormalParam param) {
        Long userId = getUserId();
        Date timeNow = new Date();
        for (Integer i = 0; i < param.getNormalList().size(); i++) {
            param.getNormalList().get(i).setAppeUser(userId);
            param.getNormalList().get(i).setAppeTime(timeNow);
        }
        locNormalService.locNormalIn(param.getNormalList());
        return R.ok();
    }
 
    /* pda入库 */
    @RequestMapping(value = "/locNormal/pda/in")
    @ManagerAuth(memo = "平仓管理pda入库")
    @Transactional
    public R locNormalPdaIn(@RequestBody LocNormalParam param) {
        Long userId = getUserId();
        Date timeNow = new Date();
        for (Integer i = 0; i < param.getNormalList().size(); i++) {
            param.getNormalList().get(i).setAppeUser(userId);
            param.getNormalList().get(i).setAppeTime(timeNow);
        }
        locNormalService.pdaLocNormalIn(param.getNormalList());
        return R.ok();
    }
 
    /* pda出库查询 */
    @RequestMapping(value = "/locNormal/pda/out/query")
    @ManagerAuth(memo = "pda出库查询")
    @Transactional
    public R locNormalPdaOutQuery(String matnr, String warehouse, String billNo) {
        List<LocNormal> list = new ArrayList<>();
        list  = locNormalService.pdaLocNormalQuery(matnr, warehouse, billNo);
        return R.ok(list);
    }
 
    @RequestMapping(value = "/locNormal/pda/out")
    @ManagerAuth(memo = "pda出库")
    @Transactional
    public R locNormalPdaOut(@RequestBody LocNormalParam param) {
        Long userId = getUserId();
        Date timeNow = new Date();
        List<LocNormal> list = param.getNormalList();
        for (Integer i = 0; i < list.size(); i++) {
            list.get(i).setModiUser(userId);
            list.get(i).setModiTime(timeNow);
        }
        locNormalService.pdaLocNormalOut(list);
        return R.ok();
    }
 
    @RequestMapping(value = "/locNormal/pda/warehouseQuery")
    @ManagerAuth(memo = "pda根据库区查询物料清单")
    @Transactional
    public R locNormalPdaWarehouseQuery(String warehouse, String matnr) {
        List<LocNormal> list = locNormalService.pdaLocNormalWarehouseQuery(warehouse, matnr);
        return R.ok(list);
    }
 
    @RequestMapping(value = "/locNormal/pda/move")
    @ManagerAuth(memo = "pda移库")
    @Transactional
    public R LocNormalPdaMove(@RequestBody LocNormalParam param) {
        Long userId = getUserId();
        Date timeNow = new Date();
        List<LocNormal> list = param.getNormalList();
        for (Integer i = 0; i < list.size(); i++) {
            list.get(i).setModiUser(userId);
            list.get(i).setModiTime(timeNow);
        }
        locNormalService.pdaLocNormalMove(list);
        return R.ok();
    }
 
    @RequestMapping(value = "/locNomal/getInListByDay")
    @ManagerAuth(memo = "平仓日出入库查询")
    public R getInListByDay(@RequestParam(defaultValue = "1") Integer curr,
                  @RequestParam(defaultValue = "10") Integer limit,
                  @RequestParam(required = false) String orderByField,
                  @RequestParam(required = false) String orderByType,
                  @RequestParam(required = false) String condition,
                  @RequestParam Map<String, Object> param) {
        excludeTrash(param);
        EntityWrapper<LocNormalReport> wrapper = new EntityWrapper<>();
        List<String> orderList = new ArrayList<>();
        orderList.add("time");
        wrapper.eq("state", param.get("state").toString()).orderDesc(orderList);
        String timeRange = "";
        String time1 = "";
        String time2 = "";
        if (!Cools.isEmpty(param.get("query_date"))) {
            timeRange = param.get("query_date").toString();
            time1 = timeRange.substring(0, 19);
            time2 = timeRange.substring(21, timeRange.length());
        }
        param.remove("query_date");
        convert(param, wrapper);
        if (time1 != "" && time2 != "") {
            SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date dateTime1 = new Date();
            Date dateTime2 = new Date();
            try {
                dateTime1 = formatter.parse(time1);
                dateTime2 = formatter.parse(time2);
            } catch (Exception e) {
                e.printStackTrace();
            }
            wrapper.ge("time", dateTime1).and().le("time", dateTime2);
        }
        allLike(LocNormalReport.class, param.keySet(), wrapper, condition);
        return R.ok(locNormalReportService.selectPage(new Page<>(curr, limit), wrapper));
    }
}