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";
|
}
|
}
|