#
Junjie
2025-11-13 1b4fbdb92537036aed4d648967ef7e7ab8842aec
src/main/java/com/zy/asrs/controller/BasMapController.java
@@ -1,5 +1,6 @@
package com.zy.asrs.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
@@ -11,10 +12,15 @@
import com.core.common.BaseRes;
import com.core.common.Cools;
import com.core.common.R;
import com.zy.asrs.utils.MapExcelUtils;
import com.zy.common.utils.RedisUtil;
import com.zy.common.web.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
import java.util.*;
@RestController
@@ -22,6 +28,8 @@
    @Autowired
    private BasMapService basMapService;
    @Autowired
    private RedisUtil redisUtil;
    @RequestMapping(value = "/basMap/{id}/auth")
    @ManagerAuth
@@ -42,6 +50,7 @@
        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));
    }
@@ -77,8 +86,8 @@
    @RequestMapping(value = "/basMap/delete/auth")
    @ManagerAuth
    public R delete(@RequestParam(value="ids[]") Long[] ids){
         for (Long id : ids){
    public R delete(@RequestParam(value="ids[]") Integer[] ids){
         for (Integer id : ids){
            basMapService.deleteById(id);
        }
        return R.ok();
@@ -121,4 +130,84 @@
        return R.ok();
    }
    @GetMapping("/basMap/lev/{lev}/auth")
    @ManagerAuth
    public R getByLev(@PathVariable("lev") Integer lev) {
        BasMap basMap = basMapService.selectOne(new EntityWrapper<BasMap>().eq("lev", lev));
        if (basMap == null){
            return R.error("地图不存在");
        }
        return R.ok().add(basMap.getData());
    }
    @Autowired
    private MapExcelUtils mapExcelUtils;
    @PostMapping("/basMap/crn/upload")
    public R uploadExcel2(@RequestParam("file") MultipartFile file) throws IOException {
        // 保存上传的文件到临时位置
        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);
        List<List<HashMap<String, Object>>> dataList = new ArrayList<>();
        for (Map.Entry<Integer, List<List<HashMap<String, Object>>>> entry : dataMap.entrySet()) {
            Integer key = entry.getKey();
            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 nodeType = map.get("bgColor").toString();
                    if (nodeType.equals("RGB(0,176,80)")) {
                        //货架
                        nodeData.put("type", "shelf");
                    }else if (nodeType.equals("RGB(255,192,0)")) {
                        //堆垛机
                        nodeData.put("type", "crn");
                    }else if (nodeType.equals("RGB(0,112,192)")) {
                        //输送线
                        nodeData.put("type", "devp");
                    }else if (nodeType.equals("RGB(0,176,240)")) {
                        //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("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", 1));
        if (basMap == null){
            basMap = new BasMap();
        }
        basMap.setLev(1);
        basMap.setData(JSON.toJSONString(dataList));
        basMap.setOriginData(JSON.toJSONString(dataList));
        basMap.setCreateTime(new Date());
        basMap.setUpdateTime(new Date());
        basMapService.insertOrUpdate(basMap);
        return R.ok();
    }
}