|
@@ -0,0 +1,177 @@
|
|
|
+package com.fdkankan.job.job;
|
|
|
+
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.fdkankan.fyun.face.FYunFileServiceInterface;
|
|
|
+import com.fdkankan.job.entity.SceneEditInfo;
|
|
|
+import com.fdkankan.job.entity.ScenePlus;
|
|
|
+import com.fdkankan.job.service.ISceneEditInfoService;
|
|
|
+import com.fdkankan.job.service.IScenePlusExtService;
|
|
|
+import com.fdkankan.job.service.IScenePlusService;
|
|
|
+import com.fdkankan.model.constants.ConstantFilePath;
|
|
|
+import com.fdkankan.model.constants.UploadFilePath;
|
|
|
+import com.fdkankan.model.utils.FloorPlanUserUtil;
|
|
|
+import com.fdkankan.redis.constant.RedisKey;
|
|
|
+import com.fdkankan.redis.util.RedisUtil;
|
|
|
+import com.xxl.job.core.context.XxlJobHelper;
|
|
|
+import com.xxl.job.core.handler.annotation.XxlJob;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * floorplan楼层转换
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author dengsixing
|
|
|
+ * @since 2022/12/16
|
|
|
+ **/
|
|
|
+@Slf4j
|
|
|
+@Component
|
|
|
+public class FloorpanLCHandler {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IScenePlusService scenePlusService;
|
|
|
+ @Autowired
|
|
|
+ private ISceneEditInfoService sceneEditInfoService;
|
|
|
+ @Autowired
|
|
|
+ private FYunFileServiceInterface fYunFileService;
|
|
|
+ @Autowired
|
|
|
+ private RedisUtil redisUtil;
|
|
|
+
|
|
|
+ @XxlJob("floorpanLCHandler")
|
|
|
+ private void floorpanLCHandler(){
|
|
|
+ XxlJobHelper.log("floorpanLCHandler start.....");
|
|
|
+
|
|
|
+ List<String> faildNumList = new ArrayList<>();
|
|
|
+
|
|
|
+ List<String> numList = null;
|
|
|
+ String nums = XxlJobHelper.getJobParam();
|
|
|
+ if(StrUtil.isNotEmpty(nums)){
|
|
|
+ numList = Arrays.asList(nums.split(","));
|
|
|
+ }
|
|
|
+
|
|
|
+ LambdaQueryWrapper<ScenePlus> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ if(CollUtil.isNotEmpty(numList)){
|
|
|
+ queryWrapper.in(ScenePlus::getNum, numList);
|
|
|
+ }
|
|
|
+ List<ScenePlus> list = scenePlusService.list(queryWrapper);
|
|
|
+
|
|
|
+ if(CollUtil.isNotEmpty(list)){
|
|
|
+ list.parallelStream().forEach(plus->{
|
|
|
+ String num = plus.getNum();
|
|
|
+ try {
|
|
|
+ String fileName = "floorplan.json";
|
|
|
+ String backFileName = "floorplan_back.json";
|
|
|
+ boolean check = false;
|
|
|
+ //编辑目录
|
|
|
+ String editPath = String.format(UploadFilePath.USER_EDIT_PATH, num);
|
|
|
+ if(fYunFileService.fileExist(editPath + fileName)){
|
|
|
+ String editJsonStr = fYunFileService.getFileContent(editPath + fileName);
|
|
|
+ JSONObject editJson = JSON.parseObject(editJsonStr);
|
|
|
+ JSONArray editFloors = editJson.getJSONArray("floors");
|
|
|
+ if(this.check(editFloors)){
|
|
|
+ check = true;
|
|
|
+ //转换
|
|
|
+ editJson.put("floors", this.tansfer(editFloors));
|
|
|
+ //备份
|
|
|
+ fYunFileService.copyFileInBucket(editPath + fileName, editPath + backFileName);
|
|
|
+ //上传
|
|
|
+ fYunFileService.uploadFile(editJson.toJSONString().getBytes(), editPath + fileName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //查看目录
|
|
|
+ String viewPath = String.format(UploadFilePath.USER_VIEW_PATH,num);
|
|
|
+ if(fYunFileService.fileExist(viewPath + fileName)){
|
|
|
+ String jsonStr = fYunFileService.getFileContent(viewPath + fileName);
|
|
|
+ JSONObject json = JSON.parseObject(jsonStr);
|
|
|
+ JSONArray floors = json.getJSONArray("floors");
|
|
|
+ if(this.check(floors)){
|
|
|
+ check = true;
|
|
|
+ //转换
|
|
|
+ json.put("floors", this.tansfer(floors));
|
|
|
+ //备份
|
|
|
+ fYunFileService.copyFileInBucket(viewPath + fileName, viewPath + backFileName);
|
|
|
+ //上传
|
|
|
+ fYunFileService.uploadFile(json.toJSONString().getBytes(), viewPath + fileName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //修改版本号
|
|
|
+ if(check){
|
|
|
+ SceneEditInfo sceneEditInfo = sceneEditInfoService.getByScenePlusId(plus.getId());
|
|
|
+ sceneEditInfo.setVersion(sceneEditInfo.getVersion() + 1);
|
|
|
+ sceneEditInfoService.updateById(sceneEditInfo);
|
|
|
+
|
|
|
+ String sceneJsonStr = fYunFileService.getFileContent(String.format(UploadFilePath.DATA_VIEW_PATH, num) + "scene.json");
|
|
|
+ JSONObject sceneJsonObj = JSON.parseObject(sceneJsonStr);
|
|
|
+ sceneJsonObj.put("version", sceneJsonObj.getIntValue("version") + 1);
|
|
|
+ fYunFileService.uploadFile(sceneJsonObj.toJSONString().getBytes(), String.format(UploadFilePath.DATA_VIEW_PATH, num) + "scene.json");
|
|
|
+ redisUtil.del(String.format(RedisKey.SCENE_JSON, num));
|
|
|
+ }
|
|
|
+
|
|
|
+ }catch (Exception e){
|
|
|
+ log.error("floorpanLCHandler失败" + num, e);
|
|
|
+ faildNumList.add(plus.getNum());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ XxlJobHelper.log("floorpanLCHandler end.....");
|
|
|
+ XxlJobHelper.log("floorpanLCHandler失败:" + JSON.toJSONString(faildNumList));
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean check(JSONArray floors){
|
|
|
+ boolean flag = false;//是否需要转换
|
|
|
+ for(int i = 0; i < floors.size(); i++){
|
|
|
+ JSONObject item = (JSONObject) floors.get(i);
|
|
|
+ int subgroup = item.getInteger("subgroup");
|
|
|
+ if(subgroup == i){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ flag = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return flag;
|
|
|
+ }
|
|
|
+
|
|
|
+ private JSONArray tansfer(JSONArray floors){
|
|
|
+ Map<Integer, JSONObject> map = new HashMap<>();
|
|
|
+ for(Integer i = 0; i < floors.size(); i++){
|
|
|
+ JSONObject item = (JSONObject) floors.get(i);
|
|
|
+ map.put(i, item);
|
|
|
+ }
|
|
|
+ JSONArray targetArr = new JSONArray();
|
|
|
+ for(Integer i = 0; i < floors.size(); i++){
|
|
|
+ JSONObject targetObj = new JSONObject();
|
|
|
+ targetArr.add(targetObj);
|
|
|
+ JSONObject obj1 = map.get(i);
|
|
|
+ int subgroup = obj1.getInteger("subgroup");
|
|
|
+ JSONObject obj2 = map.get(subgroup);
|
|
|
+ targetObj.put("id", obj1.getInteger("id"));
|
|
|
+ targetObj.put("name", obj1.getString("name"));
|
|
|
+ targetObj.put("subgroup", obj1.getInteger("subgroup"));
|
|
|
+ targetObj.put("boundingBox", obj2.getJSONObject("boundingBox"));
|
|
|
+ targetObj.put("components", obj2.getJSONObject("components"));
|
|
|
+ targetObj.put("furnitures", obj2.getJSONObject("furnitures"));
|
|
|
+ targetObj.put("rooms", obj2.getJSONArray("rooms"));
|
|
|
+ targetObj.put("walls", obj2.getJSONObject("walls"));
|
|
|
+ targetObj.put("symbols", obj2.getJSONObject("symbols"));
|
|
|
+ targetObj.put("points", obj2.getJSONObject("points"));
|
|
|
+ targetObj.put("tags", obj2.getJSONObject("tags"));
|
|
|
+ }
|
|
|
+ return targetArr;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|