#
Junjie
1 天以前 fefdabbcd1504a55d8ad10ecf6cfc36cc7b1b1b6
src/main/java/com/zy/asrs/controller/BasMapController.java
@@ -2,28 +2,18 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.core.common.DateUtils;
import com.zy.asrs.entity.BasDevp;
import com.zy.asrs.domain.BasMapEditorDoc;
import com.zy.asrs.entity.BasMap;
import com.zy.asrs.entity.BasStation;
import com.zy.asrs.entity.DeviceConfig;
import com.zy.asrs.service.BasDevpService;
import com.zy.asrs.service.BasMapEditorService;
import com.zy.asrs.service.BasMapService;
import com.core.annotations.ManagerAuth;
import com.core.common.BaseRes;
import com.core.common.Cools;
import com.core.common.R;
import com.zy.asrs.service.BasStationService;
import com.zy.asrs.service.DeviceConfigService;
import com.zy.asrs.utils.MapExcelUtils;
import com.zy.common.utils.RedisUtil;
import com.zy.common.web.BaseController;
import com.zy.core.enums.SlaveType;
import com.zy.core.model.StationObjModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@@ -38,20 +28,12 @@
    @Autowired
    private BasMapService basMapService;
    @Autowired
    private BasDevpService basDevpService;
    @Autowired
    private DeviceConfigService deviceConfigService;
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private MapExcelUtils mapExcelUtils;
    @Autowired
    private BasStationService basStationService;
    private BasMapEditorService basMapEditorService;
    @RequestMapping(value = "/basMap/{id}/auth")
    @ManagerAuth
    public R get(@PathVariable("id") String id) {
        return R.ok(basMapService.selectById(String.valueOf(id)));
        return R.ok(basMapService.getById(String.valueOf(id)));
    }
    @RequestMapping(value = "/basMap/list/auth")
@@ -62,24 +44,25 @@
                  @RequestParam(required = false)String orderByType,
                  @RequestParam(required = false)String condition,
                  @RequestParam Map<String, Object> param){
        EntityWrapper<BasMap> wrapper = new EntityWrapper<>();
        QueryWrapper<BasMap> wrapper = new QueryWrapper<>();
        excludeTrash(param);
        convert(param, wrapper);
        allLike(BasMap.class, param.keySet(), wrapper, condition);
        if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));}
        wrapper.orderBy("lev");
        return R.ok(basMapService.selectPage(new Page<>(curr, limit), wrapper));
        if (!Cools.isEmpty(orderByField)){wrapper.orderBy(true, "asc".equals(orderByType), humpToLine(orderByField));}
        wrapper.orderBy(true, true, "lev");
        return R.ok(basMapService.page(new Page<>(curr, limit), wrapper));
    }
    private <T> void convert(Map<String, Object> map, EntityWrapper<T> wrapper){
    private <T> void convert(Map<String, Object> map, QueryWrapper<T> wrapper){
        for (Map.Entry<String, Object> entry : map.entrySet()){
            String val = String.valueOf(entry.getValue());
            String column = humpToLine(entry.getKey());
            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]));
                wrapper.ge(column, DateUtils.convert(dates[0]));
                wrapper.le(column, DateUtils.convert(dates[1]));
            } else {
                wrapper.like(entry.getKey(), val);
                wrapper.like(column, val);
            }
        }
    }
@@ -87,7 +70,7 @@
    @RequestMapping(value = "/basMap/add/auth")
    @ManagerAuth
    public R add(BasMap basMap) {
        basMapService.insert(basMap);
        basMapService.save(basMap);
        return R.ok();
    }
@@ -105,7 +88,7 @@
    @ManagerAuth
    public R delete(@RequestParam(value="ids[]") Integer[] ids){
         for (Integer id : ids){
            basMapService.deleteById(id);
            basMapService.removeById(id);
        }
        return R.ok();
    }
@@ -113,20 +96,20 @@
    @RequestMapping(value = "/basMap/export/auth")
    @ManagerAuth
    public R export(@RequestBody JSONObject param){
        EntityWrapper<BasMap> wrapper = new EntityWrapper<>();
        QueryWrapper<BasMap> wrapper = new QueryWrapper<>();
        List<String> fields = JSONObject.parseArray(param.getJSONArray("fields").toJSONString(), String.class);
        Map<String, Object> map = excludeTrash(param.getJSONObject("basMap"));
        convert(map, wrapper);
        List<BasMap> list = basMapService.selectList(wrapper);
        List<BasMap> list = basMapService.list(wrapper);
        return R.ok(exportSupport(list, fields));
    }
    @RequestMapping(value = "/basMapQuery/auth")
    @ManagerAuth
    public R query(String condition) {
        EntityWrapper<BasMap> wrapper = new EntityWrapper<>();
        QueryWrapper<BasMap> wrapper = new QueryWrapper<>();
        wrapper.like("id", condition);
        Page<BasMap> page = basMapService.selectPage(new Page<>(0, 10), wrapper);
        Page<BasMap> page = basMapService.page(new Page<>(0, 10), wrapper);
        List<Map<String, Object>> result = new ArrayList<>();
        for (BasMap basMap : page.getRecords()){
            Map<String, Object> map = new HashMap<>();
@@ -140,8 +123,8 @@
    @RequestMapping(value = "/basMap/check/column/auth")
    @ManagerAuth
    public R query(@RequestBody JSONObject param) {
        Wrapper<BasMap> wrapper = new EntityWrapper<BasMap>().eq(humpToLine(String.valueOf(param.get("key"))), param.get("val"));
        if (null != basMapService.selectOne(wrapper)){
        QueryWrapper<BasMap> wrapper = new QueryWrapper<BasMap>().eq(humpToLine(String.valueOf(param.get("key"))), param.get("val"));
        if (null != basMapService.getOne(wrapper)){
            return R.parse(BaseRes.REPEAT).add(getComment(BasMap.class, String.valueOf(param.get("key"))));
        }
        return R.ok();
@@ -150,7 +133,7 @@
    @GetMapping("/basMap/lev/{lev}/auth")
    @ManagerAuth
    public R getByLev(@PathVariable("lev") Integer lev) {
        BasMap basMap = basMapService.selectOne(new EntityWrapper<BasMap>().eq("lev", lev));
        BasMap basMap = basMapService.getOne(new QueryWrapper<BasMap>().eq("lev", lev));
        if (basMap == null){
            return R.error("地图不存在");
        }
@@ -166,198 +149,66 @@
    @PostMapping("/basMap/crn/upload")
    public R uploadExcel(@RequestParam("file") MultipartFile file) {
        File tempFile = null;
        try {
            // 保存上传的文件到临时位置
            String filePath = System.getProperty("java.io.tmpdir") + file.getOriginalFilename();
            file.transferTo(new File(filePath));
            HashMap<Integer, List<List<HashMap<String, Object>>>> dataMap = mapExcelUtils.readExcel(filePath);
            HashMap<Integer, List<StationObjModel>> deviceStationMap = new HashMap<>();
            HashMap<Integer, List<StationObjModel>> barcodeStationMap = new HashMap<>();
            HashMap<Integer, List<StationObjModel>> inStationMap = new HashMap<>();
            HashMap<Integer, List<StationObjModel>> outStationMap = new HashMap<>();
            HashMap<Integer, List<StationObjModel>> runBlockReassignStationMap = new HashMap<>();
            for (Map.Entry<Integer, List<List<HashMap<String, Object>>>> entry : dataMap.entrySet()) {
                Integer lev = entry.getKey();
                List<List<HashMap<String, Object>>> dataList = new ArrayList<>();
                List<List<HashMap<String, Object>>> list = entry.getValue();
                for (int i = 0; i < list.size(); i++) {
                    List<HashMap<String, Object>> bayList = list.get(i);
                    List<HashMap<String, Object>> arrayList = new ArrayList<>();
                    for (int j = 0; j < bayList.size(); j++) {
                        HashMap<String, Object> map = bayList.get(j);
                        HashMap<String, Object> nodeData = new HashMap<>();
                        nodeData.put("value", map.get("value"));
                        String bgColor = map.get("bgColor").toString();
                        String nodeType = map.get("nodeType").toString();
                        if (nodeType.equals("shelf")) {
                            //货架
                            nodeData.put("type", "shelf");
                        } else if (nodeType.equals("crn")) {
                            //堆垛机
                            nodeData.put("type", "crn");
                        } else if (nodeType.equals("dualCrn")) {
                            //双工位堆垛机
                            nodeData.put("type", "dualCrn");
                        } else if (nodeType.equals("devp")) {
                            //输送线
                            nodeData.put("type", "devp");
                            JSONObject value = JSON.parseObject(String.valueOf(map.get("value")));
                            Integer deviceNo = value.getInteger("deviceNo");
                            StationObjModel stationObjModel = new StationObjModel();
                            stationObjModel.setDeviceNo(deviceNo);
                            stationObjModel.setStationId(value.getInteger("stationId"));
                            stationObjModel.setStationLev(lev);
                            List<StationObjModel> stationList = deviceStationMap.getOrDefault(deviceNo, new ArrayList<>());
                            stationList.add(stationObjModel);
                            deviceStationMap.put(deviceNo, stationList);
                            Integer isBarcodeStation = value.getInteger("isBarcodeStation");
                            if (isBarcodeStation != null && isBarcodeStation == 1) {
                                StationObjModel barcodeStationModel = new StationObjModel();
                                barcodeStationModel.setDeviceNo(deviceNo);
                                barcodeStationModel.setStationId(value.getInteger("stationId"));
                                barcodeStationModel.setBarcodeIdx(value.getInteger("barcodeIdx"));
                                if (value.getInteger("backStation") != null) {
                                    StationObjModel backStation = new StationObjModel();
                                    barcodeStationModel.setBackStation(backStation);
                                    backStation.setDeviceNo(value.getInteger("backStationDeviceNo"));
                                    backStation.setStationId(value.getInteger("backStation"));
                                }
                                List<StationObjModel> barcodeStationList = barcodeStationMap.getOrDefault(deviceNo, new ArrayList<>());
                                barcodeStationList.add(barcodeStationModel);
                                barcodeStationMap.put(deviceNo, barcodeStationList);
                            }
                            Integer isInStation = value.getInteger("isInStation");
                            if (isInStation != null && isInStation == 1) {
                                StationObjModel inStationModel = new StationObjModel();
                                StationObjModel barcodeStation = new StationObjModel();
                                inStationModel.setDeviceNo(deviceNo);
                                inStationModel.setStationId(value.getInteger("stationId"));
                                inStationModel.setBarcodeStation(barcodeStation);
                                barcodeStation.setDeviceNo(value.getInteger("barcodeStationDeviceNo"));
                                barcodeStation.setStationId(value.getInteger("barcodeStation"));
                                List<StationObjModel> inStationList = inStationMap.getOrDefault(deviceNo, new ArrayList<>());
                                inStationList.add(inStationModel);
                                inStationMap.put(deviceNo, inStationList);
                            }
                            Integer isOutStation = value.getInteger("isOutStation");
                            if (isOutStation != null && isOutStation == 1) {
                                List<StationObjModel> outStationList = outStationMap.getOrDefault(deviceNo, new ArrayList<>());
                                outStationList.add(stationObjModel);
                                outStationMap.put(deviceNo, outStationList);
                            }
                            Integer runBlockReassign = value.getInteger("runBlockReassign");
                            if (runBlockReassign != null && runBlockReassign == 1) {
                                List<StationObjModel> runBlockReassignStationList = runBlockReassignStationMap.getOrDefault(deviceNo, new ArrayList<>());
                                runBlockReassignStationList.add(stationObjModel);
                                runBlockReassignStationMap.put(deviceNo, runBlockReassignStationList);
                            }
                        } else if (nodeType.equals("rgv")) {
                            //RGV
                            nodeData.put("type", "rgv");
                        } else if (nodeType.equals("none")) {
                            //空白区域
                            nodeData.put("type", "none");
                        } else if (nodeType.equals("merge")) {
                            //合并区域
                            nodeData.put("type", "merge");
                            nodeData.put("mergeType", map.get("mergeType"));
                        }
                        nodeData.put("cellWidth", map.get("cellWidth"));
                        nodeData.put("cellHeight", map.get("cellHeight"));
                        nodeData.put("rowSpan", map.get("rowSpan"));
                        nodeData.put("colSpan", map.get("colSpan"));
                        arrayList.add(nodeData);
                    }
                    dataList.add(arrayList);
                }
                BasMap basMap = basMapService.selectOne(new EntityWrapper<BasMap>().eq("lev", lev));
                if (basMap == null) {
                    basMap = new BasMap();
                }
                basMap.setData(JSON.toJSONString(dataList));
                basMap.setOriginData(JSON.toJSONString(dataList));
                basMap.setCreateTime(new Date());
                basMap.setUpdateTime(new Date());
                basMap.setLev(lev);
                basMapService.insertOrUpdate(basMap);
            }
            basStationService.delete(new EntityWrapper<>());
            deviceStationMap.forEach((deviceNo, stationList) -> {
                BasDevp basDevp = basDevpService.selectOne(new EntityWrapper<BasDevp>().eq("devp_no", deviceNo));
                if (basDevp == null) {
                    basDevp = new BasDevp();
                    basDevp.setDevpNo(deviceNo);
                    basDevp.setCreateTime(new Date());
                    basDevp.setStatus(1);
                }
                List<StationObjModel> barcodeStationList = barcodeStationMap.get(deviceNo);
                List<StationObjModel> inStationList = inStationMap.get(deviceNo);
                List<StationObjModel> outStationList = outStationMap.get(deviceNo);
                List<StationObjModel> runBlockReassignStationList = runBlockReassignStationMap.get(deviceNo);
                if (barcodeStationList != null) {
                    basDevp.setBarcodeStationList(JSON.toJSONString(barcodeStationList, SerializerFeature.DisableCircularReferenceDetect));
                }
                if (inStationList != null) {
                    basDevp.setInStationList(JSON.toJSONString(inStationList, SerializerFeature.DisableCircularReferenceDetect));
                }
                if (outStationList != null) {
                    basDevp.setOutStationList(JSON.toJSONString(outStationList, SerializerFeature.DisableCircularReferenceDetect));
                }
                if (runBlockReassignStationList != null) {
                    basDevp.setRunBlockReassignLocStationList(JSON.toJSONString(runBlockReassignStationList, SerializerFeature.DisableCircularReferenceDetect));
                }
                basDevp.setStationList(JSON.toJSONString(stationList, SerializerFeature.DisableCircularReferenceDetect));
                basDevp.setUpdateTime(new Date());
                basDevpService.insertOrUpdate(basDevp);
                DeviceConfig deviceConfig = deviceConfigService.selectOne(new EntityWrapper<DeviceConfig>().eq("device_no", deviceNo).eq("device_type", String.valueOf(SlaveType.Devp)));
                if (deviceConfig != null) {
                    deviceConfig.setFakeInitStatus(JSON.toJSONString(stationList));
                    deviceConfigService.updateById(deviceConfig);
                }
                for (StationObjModel stationObjModel : stationList) {
                    BasStation basStation = new BasStation();
                    basStation.setStationId(stationObjModel.getStationId());
                    basStation.setDeviceNo(stationObjModel.getDeviceNo());
                    basStation.setStationLev(stationObjModel.getStationLev());
                    basStation.setCreateTime(new Date());
                    basStation.setStatus(1);
                    basStationService.insert(basStation);
                }
            });
            tempFile = createTempUploadFile(file);
            basMapEditorService.importExcelAndPersist(tempFile.getAbsolutePath());
        } catch (Exception e) {
            e.printStackTrace();
            return R.error(e.getMessage());
        } finally {
            deleteQuietly(tempFile);
        }
        return R.ok();
    }
    @GetMapping("/basMap/editor/{lev}/auth")
    @ManagerAuth
    public R getEditorDoc(@PathVariable("lev") Integer lev) {
        BasMapEditorDoc doc = basMapEditorService.getEditorDoc(lev);
        if (doc == null) {
            return R.error("地图不存在");
        }
        return R.ok().add(doc);
    }
    @PostMapping("/basMap/editor/save/auth")
    @ManagerAuth
    public R saveEditorDoc(@RequestBody BasMapEditorDoc doc) {
        basMapEditorService.saveEditorDoc(doc);
        return R.ok();
    }
    @PostMapping("/basMap/editor/importExcel/auth")
    @ManagerAuth
    public R importExcelToEditor(@RequestParam("file") MultipartFile file) {
        File tempFile = null;
        try {
            tempFile = createTempUploadFile(file);
            return R.ok().add(basMapEditorService.importExcelToEditorDocs(tempFile.getAbsolutePath()));
        } catch (Exception e) {
            e.printStackTrace();
            return R.error(e.getMessage());
        } finally {
            deleteQuietly(tempFile);
        }
    }
    private File createTempUploadFile(MultipartFile file) throws IOException {
        String originalName = file == null ? null : file.getOriginalFilename();
        String suffix = ".xlsx";
        if (!Cools.isEmpty(originalName) && originalName.contains(".")) {
            suffix = originalName.substring(originalName.lastIndexOf('.'));
        }
        File tempFile = File.createTempFile("bas_map_", suffix);
        file.transferTo(tempFile);
        return tempFile;
    }
    private void deleteQuietly(File file) {
        if (file != null && file.exists()) {
            file.delete();
        }
    }
}