#
Junjie
1 天以前 9d24c64b9d81ae166f4c150f038793304d7161fa
src/main/java/com/zy/asrs/controller/BasMapController.java
@@ -6,15 +6,21 @@
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.core.common.DateUtils;
import com.zy.asrs.entity.BasDevp;
import com.zy.asrs.entity.BasMap;
import com.zy.asrs.entity.DeviceConfig;
import com.zy.asrs.service.BasDevpService;
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.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;
@@ -28,6 +34,10 @@
    @Autowired
    private BasMapService basMapService;
    @Autowired
    private BasDevpService basDevpService;
    @Autowired
    private DeviceConfigService deviceConfigService;
    @Autowired
    private RedisUtil redisUtil;
@@ -130,20 +140,38 @@
        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/crn/upload")
    public R uploadExcel2(@RequestParam("file") MultipartFile file) throws IOException {
    public R uploadExcel(@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);
        HashMap<Integer, List<StationObjModel>> deviceStationMap = new HashMap<>();
        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++) {
@@ -165,7 +193,16 @@
                    }else if (nodeType.equals("RGB(0,112,192)")) {
                        //输送线
                        nodeData.put("type", "devp");
                        nodeData.put("value", (int) Double.parseDouble(map.get("value").toString()));
                        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"));
                        List<StationObjModel> stationList = deviceStationMap.getOrDefault(deviceNo, new ArrayList<>());
                        stationList.add(stationObjModel);
                        deviceStationMap.put(deviceNo, stationList);
                    }else if (nodeType.equals("RGB(0,176,240)")) {
                        //RGV
                        nodeData.put("type", "rgv");
@@ -186,10 +223,39 @@
                }
                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);
        }
        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);
            }
            basDevp.setStationList(JSON.toJSONString(stationList));
            basDevp.setUpdateTime(new Date());
            basDevpService.insertOrUpdate(basDevp);
        return R.ok().add(JSON.toJSONString(dataList));
            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);
            }
        });
        return R.ok();
    }
}