zhang
2025-12-26 9569af2a6abcccc3f312abff0a7e660c0f2be2c8
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
package com.zy.acs.manager.manager.controller.utils;
 
import com.alibaba.excel.EasyExcel;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.google.common.collect.Lists;
import com.zy.acs.common.utils.Utils;
import com.zy.acs.manager.common.annotation.OperationLog;
import com.zy.acs.manager.manager.entity.Code;
import com.zy.acs.manager.manager.entity.Loc;
import com.zy.acs.manager.manager.service.CodeGapService;
import com.zy.acs.manager.manager.service.CodeService;
import com.zy.acs.manager.manager.service.LocService;
import com.zy.acs.manager.manager.service.RouteService;
import com.zy.acs.manager.system.controller.BaseController;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
 
import java.io.IOException;
import java.util.List;
import java.util.Map;
 
/**
 * Created by vincent on 2023/6/12
 */
@Api(tags = "Utils Api")
@RestController
@RequestMapping("/api/file")
public class UtilsController extends BaseController {
 
    @Autowired
    private RouteService routeService;
 
    @Autowired
    private LocService locService;
 
    @Autowired
    private CodeService codeService;
 
    @Autowired
    private CodeGapService codeGapService;
 
    /**
     * 文件上传
     * <p>
     * 1. 创建excel对应的实体对象 参照{@link Map<Integer, String>}
     * <p>
     * 2. 由于默认一行行的读取excel,所以需要创建excel一行一行的回调监听器,参照{@link MapDataListener}
     * <p>
     * 3. 直接读即可
     */
    @RequestMapping("/excel/map/import")
    @ResponseBody
    @OperationLog("import map data")
    public String upload(MultipartFile file) throws IOException {
        EasyExcel.read(file.getInputStream(), new MapDataListener(routeService, codeService, codeGapService)).sheet().doRead();
        return "success";
    }
 
 
    private List<Integer> starts = Lists.newArrayList(7, 62, 126, 182, 237, 292, 347, 436, 525, 614, 793, 882, 970, 1059, 1148, 1324, 1416, 1505);
 
    private int d = 10;
 
    private int d2 = 5;
 
    private List<Integer> starts2 = Lists.newArrayList(389, 478, 567, 745, 835, 923, 1012, 1101, 1190, 1366, 1458, 1547);
 
 
    @RequestMapping("/loc")
    @ResponseBody
    @OperationLog("import map data")
    public String loc() {
        List<Loc> list = locService.list(new LambdaQueryWrapper<Loc>().orderByAsc(Loc::getRow).orderByAsc(Loc::getBay).orderByAsc(Loc::getLev));
        for (Loc loc : list) {
//            if (loc.getBay() <= 24) {
//                Integer i = starts.get((loc.getRow() - 1) / 2);
//                Code cacheByData = codeService.getCacheByData(Utils.zeroFill((loc.getBay()%8 -1+ i + loc.getBay() / 8 * 10) + "", 8));
//                loc.setCode(cacheByData.getId());
//                locService.updateById(loc);
//            }
//            if (loc.getBay() > 24 && loc.getBay() <= 32) {
//                Integer i = starts.get((loc.getRow() - 1)  / 2) + 30;
//                Code cacheByData = codeService.getCacheByData(Utils.zeroFill(((loc.getBay() - 24)%4-1 + i + (loc.getBay() - 24) / 4 * 6) + "", 8));
//                loc.setCode(cacheByData.getId());
//                locService.updateById(loc);
//            }
            if (loc.getBay() > 32) {
                Integer i = starts2.get((loc.getRow() - 13) / 2);
                Code cacheByData = codeService.getCacheByData(Utils.zeroFill((Utils.zeroFill((((loc.getBay()-1) % 8) + i + (((loc.getBay()-1) / 8) - 4) * 10) + "", 8)) + "", 8));
                loc.setCode(cacheByData.getId());
                locService.updateById(loc);
            }
        }
        return "success";
    }
}