cp
2024-10-30 431f88fdade07a22b636714f1690cee3a55668d0
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
package com.zy.asrs.wms.controller;
 
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zy.asrs.common.domain.entity.MatExcel;
import com.zy.asrs.common.domain.entity.WaitPakinExcel;
import com.zy.asrs.common.utils.MatExcelListener;
import com.zy.asrs.common.utils.WaitPakingExcelListener;
import com.zy.asrs.common.wms.entity.Mat;
import com.zy.asrs.common.wms.entity.WaitPakin;
import com.zy.asrs.common.wms.entity.WrkMast;
import com.zy.asrs.common.wms.service.OrderDetlService;
import com.zy.asrs.common.wms.service.WaitPakinService;
import com.zy.asrs.common.wms.service.WrkMastService;
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.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
 
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.*;
 
@RestController
public class WaitPakinController extends BaseController {
 
    @Autowired
    private WaitPakinService waitPakinService;
    @Autowired
    private WrkMastService wrkMastService;
    @Autowired
    private OrderDetlService orderDetlService;
 
    @RequestMapping(value = "/waitPakin/forBarcode/auth")
    @ManagerAuth
    public R forBarcode(@RequestParam("barcode") String barcode) {
        List<WaitPakin> list = waitPakinService.list(new LambdaQueryWrapper<WaitPakin>().eq(WaitPakin::getZpallet, barcode).eq(WaitPakin::getHostId, getHostId()));
        if (Cools.isEmpty(list)){
            return R.error("未找到组托信息");
        }
        return R.ok(list);
    }
    @RequestMapping(value = "/waitPakin/{id}/auth")
    @ManagerAuth
    public R get(@PathVariable("id") String id) {
        return R.ok(waitPakinService.getById(String.valueOf(id)));
    }
 
    @RequestMapping(value = "/waitPakin/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) {
        QueryWrapper<WaitPakin> wrapper = new QueryWrapper<>();
        wrapper.eq("host_id", getHostId());
        convert(param,wrapper);
        if (!Cools.isEmpty(timeRange)) {
            String[] range = timeRange.split(RANGE_TIME_LINK);
            wrapper.ge("appe_time", DateUtils.convert(range[0]));
            wrapper.le("appe_time", DateUtils.convert(range[1]));
        }
        return R.ok(waitPakinService.page(new Page<>(curr, limit), wrapper));
    }
 
    private <T> void convert(Map<String, Object> map, QueryWrapper<T> wrapper){
        for (Map.Entry<String, Object> entry : map.entrySet()){
            if(Cools.eq(entry.getKey(),"curr") || Cools.eq(entry.getKey(),"limit")){
                continue;
            }
            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 {
                if (entry.getKey().equals("locNo")) {
                    wrapper.eq("loc_no", String.valueOf(entry.getValue()));
                } else {
                    wrapper.like(entry.getKey(), String.valueOf(entry.getValue()));
                }
            }
        }
    }
 
 
    @RequestMapping(value = "/waitPakin/add/auth")
    @ManagerAuth
    public R add(WaitPakin waitPakin) {
        waitPakin.setHostId(getHostId());
        waitPakinService.save(waitPakin);
        return R.ok();
    }
 
    @RequestMapping(value = "/waitPakin/update/auth")
    @ManagerAuth
    public R update(WaitPakin waitPakin){
        if (Cools.isEmpty(waitPakin) || null==waitPakin.getId()){
            return R.error();
        }
        waitPakinService.updateById(waitPakin);
        return R.ok();
    }
 
//    @RequestMapping(value = "/waitPakin/delete/auth")
//    @ManagerAuth
//    public R delete(@RequestParam(value="ids[]") Long[] ids){
//         for (Long id : ids){
//            waitPakinService.removeById(id);
//        }
//        return R.ok();
//    }
 
    @RequestMapping(value = "/waitPakin/delete/auth")
    @ManagerAuth
    @Transactional
    public R delete(@RequestParam String param){
        List<WaitPakin> list = JSONArray.parseArray(param, WaitPakin.class);
        if (Cools.isEmpty(list)){
            return R.error("数据为空");
        }
        for (WaitPakin entity : list){
            List<WrkMast> wrkMasts = wrkMastService.list(new QueryWrapper<WrkMast>().eq("barcode", entity.getZpallet()));
            if(!Cools.isEmpty(wrkMasts) || wrkMasts.size() > 0){
                return R.error("条码已生成入库工作档,禁止删除");
            }
            waitPakinService.removeById(entity.getId());
            //订单关联,修改订单作业数量
            if (!Cools.isEmpty(entity.getOrderNo())) {
                if (!orderDetlService.decrease(entity.getOrderNo(),entity.getHostId(), entity.getMatnr(), entity.getBatch(), entity.getAnfme())) {
                    return R.error("订单数据回滚失败");
                }
            }
        }
        return R.ok();
    }
 
    @RequestMapping(value = "/waitPakinQuery/auth")
    @ManagerAuth
    public R query(String condition) {
        LambdaQueryWrapper<WaitPakin> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(WaitPakin::getHostId, getHostId());
        wrapper.like(WaitPakin::getId, condition);
        Page<WaitPakin> page = waitPakinService.page(new Page<>(0, 10), wrapper);
        List<Map<String, Object>> result = new ArrayList<>();
        for (WaitPakin waitPakin : page.getRecords()){
            Map<String, Object> map = new HashMap<>();
            map.put("id", waitPakin.getId());
            map.put("value", waitPakin.getId());
            result.add(map);
        }
        return R.ok(result);
    }
 
    @RequestMapping("/waitPakin/all/get/kv")
    @ManagerAuth
    public R getDataKV(@RequestParam(required = false) String condition) {
        List<KeyValueVo> vos = new ArrayList<>();
        LambdaQueryWrapper<WaitPakin> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(WaitPakin::getHostId, getHostId());
        if (!Cools.isEmpty(condition)) {
            wrapper.like(WaitPakin::getId, condition);
        }
        waitPakinService.page(new Page<>(1, 30), wrapper).getRecords().forEach(item -> vos.add(new KeyValueVo(String.valueOf(item.getId()), item.getId())));
        return R.ok().add(vos);
    }
 
    /*************************************** 数据相关 ***********************************************/
 
    /**
     * excel导入模板下载
     */
    @RequestMapping(value = "/waitPakin/excel/import/mould")
    public void matExcelImportMould(HttpServletResponse response) throws IOException {
        List<WaitPakinExcel> excels = new ArrayList<>();
        response.setContentType("application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        String fileName = URLEncoder.encode("入库通知档Excel导入模板", "UTF-8");
        response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
        EasyExcel.write(response.getOutputStream(), WaitPakinExcel.class)
                .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
                .sheet("sheet1")
                .doWrite(excels);
    }
 
//    // excel导入-------判断是否有重复物料
//    @PostMapping(value = "/mat/excel/import/check/auth")
//    @ManagerAuth(memo = "商品档案数据导入")
//    @Transactional
//    public R matExcelImportCheck(MultipartFile file) throws IOException {
//        MatExcelListener listener = new MatExcelListener(getUserId(), getHostId());
//        EasyExcel.read(file.getInputStream(), MatExcel.class, listener).sheet().doRead();
//        return R.ok("成功同步"+listener.getTotal()+"条商品数据");
//    }
 
    // excel导入
    @PostMapping(value = "/waitPakin/excel/import/auth")
    @ManagerAuth(memo = "入库通知档档案数据导入")
    @Transactional
    public R matExcelImport(MultipartFile file) throws IOException {
        WaitPakingExcelListener listener = new WaitPakingExcelListener(getUserId(), getHostId());
        EasyExcel.read(file.getInputStream(), WaitPakinExcel.class, listener).sheet().doRead();
        return R.ok("成功同步"+listener.getTotal()+"条商品数据");
    }
 
}