#
Junjie
4 天以前 517966d4dbed6ef6e5d591720b971af427e6b63a
src/main/java/com/zy/asrs/controller/BasMapController.java
@@ -2,33 +2,24 @@
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.core.common.DateUtils;
import com.zy.asrs.entity.BasMap;
import com.zy.asrs.entity.BasShuttleCharge;
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.BasShuttleChargeService;
import com.zy.asrs.utils.MapExcelUtils;
import com.zy.common.model.MapNode;
import com.zy.common.utils.RedisUtil;
import com.zy.common.web.BaseController;
import com.zy.core.enums.RedisKeyType;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFColor;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
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.FileInputStream;
import java.io.IOException;
import java.util.*;
@@ -37,8 +28,6 @@
    @Autowired
    private BasMapService basMapService;
    @Autowired
    private BasShuttleChargeService basShuttleChargeService;
    @Autowired
    private RedisUtil redisUtil;
@@ -141,40 +130,25 @@
        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());
    }
    @GetMapping("/basMap/getLevList")
    @ManagerAuth
    public R getLevList() {
        List<Integer> levList = basMapService.getLevList();
        return R.ok().add(levList);
    }
    @Autowired
    private MapExcelUtils mapExcelUtils;
    @PostMapping("/basMap/upload")
    public R uploadExcel(@RequestParam("file") MultipartFile file) throws IOException {
        // 保存上传的文件到临时位置
        String tempFilePath = System.getProperty("java.io.tmpdir") + file.getOriginalFilename();
        file.transferTo(new File(tempFilePath));
        HashMap<Integer, List<List<HashMap<String, Object>>>> dataMap = mapExcelUtils.readExcel(tempFilePath);
        HashMap<Integer, List<List<MapNode>>> levMap = mapExcelUtils.processExcelData(dataMap);
        // 删除临时文件
        new File(tempFilePath).delete();
        basMapService.delete(new EntityWrapper<>());
        for (Map.Entry<Integer, List<List<MapNode>>> entry : levMap.entrySet()) {
            Integer lev = entry.getKey();
            List<List<MapNode>> map = entry.getValue();
            Date now = new Date();
            BasMap basMap = new BasMap();
            basMap.setLev(lev);
            basMap.setOriginData(JSON.toJSONString(map, SerializerFeature.DisableCircularReferenceDetect));
            basMap.setCreateTime(now);
            basMap.setUpdateTime(now);
            basMapService.insert(basMap);
            redisUtil.del(RedisKeyType.MAP.key + lev);
        }
        return R.ok();
    }
    @PostMapping("/basMap/crn/upload")
    public R uploadExcel2(@RequestParam("file") MultipartFile file) throws IOException {
@@ -184,9 +158,9 @@
        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();
            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++) {
@@ -208,7 +182,6 @@
                    }else if (nodeType.equals("RGB(0,112,192)")) {
                        //输送线
                        nodeData.put("type", "devp");
                        nodeData.put("value", (int) Double.parseDouble(map.get("value").toString()));
                    }else if (nodeType.equals("RGB(0,176,240)")) {
                        //RGV
                        nodeData.put("type", "rgv");
@@ -229,10 +202,19 @@
                }
                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);
        }
        return R.ok().add(JSON.toJSONString(dataList));
        return R.ok();
    }
}