|
@@ -5,10 +5,7 @@ import cn.hutool.core.util.StrUtil;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
-import com.fdkankan.common.constant.ConstantFilePath;
|
|
|
|
-import com.fdkankan.common.constant.ErrorCode;
|
|
|
|
-import com.fdkankan.common.constant.FileBizType;
|
|
|
|
-import com.fdkankan.common.constant.TbStatus;
|
|
|
|
|
|
+import com.fdkankan.common.constant.*;
|
|
import com.fdkankan.common.exception.BusinessException;
|
|
import com.fdkankan.common.exception.BusinessException;
|
|
import com.fdkankan.common.response.ResultData;
|
|
import com.fdkankan.common.response.ResultData;
|
|
import com.fdkankan.fyun.oss.UploadToOssUtil;
|
|
import com.fdkankan.fyun.oss.UploadToOssUtil;
|
|
@@ -26,8 +23,13 @@ import com.fdkankan.scene.service.ISceneEditInfoService;
|
|
import com.fdkankan.scene.service.ISceneProService;
|
|
import com.fdkankan.scene.service.ISceneProService;
|
|
import com.fdkankan.scene.vo.*;
|
|
import com.fdkankan.scene.vo.*;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
+import java.io.BufferedReader;
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.io.InputStream;
|
|
|
|
+import java.io.InputStreamReader;
|
|
import java.util.Calendar;
|
|
import java.util.Calendar;
|
|
import java.util.Objects;
|
|
import java.util.Objects;
|
|
|
|
|
|
@@ -42,6 +44,8 @@ import java.util.Objects;
|
|
@Service
|
|
@Service
|
|
public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper, SceneEditInfo> implements ISceneEditInfoService {
|
|
public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper, SceneEditInfo> implements ISceneEditInfoService {
|
|
|
|
|
|
|
|
+ @Value("${oss.bucket:4dkankan}")
|
|
|
|
+ private String bucket;
|
|
@Autowired
|
|
@Autowired
|
|
private ISceneEditControlsService sceneEditControlsService;
|
|
private ISceneEditControlsService sceneEditControlsService;
|
|
@Autowired
|
|
@Autowired
|
|
@@ -53,7 +57,7 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
|
|
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public SceneEditInfoVO saveSceneEditInfo(SceneEditInfoParamVO param) {
|
|
|
|
|
|
+ public SceneEditInfoVO saveScene(SceneEditInfoParamVO param) {
|
|
|
|
|
|
ScenePro scenePro = sceneProService.findBySceneNum(param.getNum());
|
|
ScenePro scenePro = sceneProService.findBySceneNum(param.getNum());
|
|
if(Objects.isNull(scenePro)){
|
|
if(Objects.isNull(scenePro)){
|
|
@@ -138,15 +142,29 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public SceneInfoVO getSceneInfo(SceneInfoParamVO param) {
|
|
public SceneInfoVO getSceneInfo(SceneInfoParamVO param) {
|
|
- //如果是查看页面请求,查redis
|
|
|
|
- if(Objects.isNull(param.getReqType()) || param.getReqType() == 2){
|
|
|
|
- String sceneJson = redisUtil.get(String.format(RedisKey.SCENE_JSON, param.getNum()));
|
|
|
|
- SceneInfoVO sceneInfoVO = JSON.parseObject(sceneJson, SceneInfoVO.class);
|
|
|
|
- return sceneInfoVO;
|
|
|
|
|
|
+ SceneInfoReqType sceneInfoReqType = SceneInfoReqType.get(param.getReqType());
|
|
|
|
+ switch (sceneInfoReqType){
|
|
|
|
+ //如果是编辑页面请求,查数据库
|
|
|
|
+ case EDIT:
|
|
|
|
+ return this.getSceneInfo4Edit(param.getNum());
|
|
|
|
+ //如果是查看页面请求,查redis
|
|
|
|
+ case VIEW:
|
|
|
|
+ return this.getSceneInfo4View(param.getNum());
|
|
}
|
|
}
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
|
|
- //如果是编辑页面请求,查数据库
|
|
|
|
- ScenePro scenePro = sceneProService.findBySceneNum(param.getNum());
|
|
|
|
|
|
+ /**
|
|
|
|
+ * <p>
|
|
|
|
+ 编辑页面获取场景详情信息
|
|
|
|
+ * </p>
|
|
|
|
+ * @author dengsixing
|
|
|
|
+ * @date 2022/1/21
|
|
|
|
+ * @param num
|
|
|
|
+ * @return com.fdkankan.scene.vo.SceneInfoVO
|
|
|
|
+ **/
|
|
|
|
+ private SceneInfoVO getSceneInfo4Edit(String num){
|
|
|
|
+ ScenePro scenePro = sceneProService.findBySceneNum(num);
|
|
if(Objects.isNull(scenePro)){
|
|
if(Objects.isNull(scenePro)){
|
|
throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
|
|
throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
|
|
}
|
|
}
|
|
@@ -154,7 +172,46 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
|
|
SceneEditControls sceneEditControls = sceneEditControlsService.getBySceneEditId(sceneEditInfo.getId());
|
|
SceneEditControls sceneEditControls = sceneEditControlsService.getBySceneEditId(sceneEditInfo.getId());
|
|
SceneInfoVO sceneInfoVO = BeanUtil.copyProperties(sceneEditInfo, SceneInfoVO.class);
|
|
SceneInfoVO sceneInfoVO = BeanUtil.copyProperties(sceneEditInfo, SceneInfoVO.class);
|
|
sceneInfoVO.setControls(BeanUtil.copyProperties(sceneEditControls, SceneEditControlsVO.class));
|
|
sceneInfoVO.setControls(BeanUtil.copyProperties(sceneEditControls, SceneEditControlsVO.class));
|
|
- sceneInfoVO.setNum(param.getNum());
|
|
|
|
|
|
+ sceneInfoVO.setNum(num);
|
|
|
|
+
|
|
|
|
+ return sceneInfoVO;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * <p>
|
|
|
|
+ 查看页面获取场景详情信息
|
|
|
|
+ * </p>
|
|
|
|
+ * @author dengsixing
|
|
|
|
+ * @date 2022/1/21
|
|
|
|
+ * @param num
|
|
|
|
+ * @return com.fdkankan.scene.vo.SceneInfoVO
|
|
|
|
+ **/
|
|
|
|
+ private SceneInfoVO getSceneInfo4View(String num){
|
|
|
|
+ String sceneJson = redisUtil.get(String.format(RedisKey.SCENE_JSON, num));
|
|
|
|
+ SceneInfoVO sceneInfoVO = null;
|
|
|
|
+ //先查询redis
|
|
|
|
+ if(StrUtil.isNotEmpty(sceneJson)){
|
|
|
|
+ sceneInfoVO = JSON.parseObject(sceneJson, SceneInfoVO.class);
|
|
|
|
+ return sceneInfoVO;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //如果redis没找到,从scene.json中获取
|
|
|
|
+ String objectName = String.format(ConstantFilePath.SCENE_VIEW_DATA_DATA_SCENEJSON, num);
|
|
|
|
+ InputStream objectContent = uploadToOssUtil.getObjectContent(bucket, objectName);
|
|
|
|
+ if(Objects.isNull(objectContent))
|
|
|
|
+ return null;
|
|
|
|
+ StringBuilder contentJson = new StringBuilder();
|
|
|
|
+ try(BufferedReader reader = new BufferedReader(new InputStreamReader(objectContent))){
|
|
|
|
+ while (true) {
|
|
|
|
+ String line = reader.readLine();
|
|
|
|
+ if (line == null) break;
|
|
|
|
+ contentJson.append(line);
|
|
|
|
+ }
|
|
|
|
+ sceneInfoVO = JSON.parseObject(contentJson.toString(), SceneInfoVO.class);
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ log.error("读取scene.json文件流失败", e);
|
|
|
|
+ throw new BusinessException(ErrorCode.SYSTEM_BUSY);
|
|
|
|
+ }
|
|
|
|
|
|
return sceneInfoVO;
|
|
return sceneInfoVO;
|
|
}
|
|
}
|