|
@@ -0,0 +1,77 @@
|
|
|
|
|
+package com.fdkankan.openApi.service.www.impl;
|
|
|
|
|
+
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
+import com.baomidou.dynamic.datasource.annotation.DS;
|
|
|
|
|
+import com.fdkankan.common.constant.ErrorCode;
|
|
|
|
|
+import com.fdkankan.common.exception.BusinessException;
|
|
|
|
|
+import com.fdkankan.fyun.face.FYunFileServiceInterface;
|
|
|
|
|
+import com.fdkankan.model.constants.UploadFilePath;
|
|
|
|
|
+import com.fdkankan.openApi.bean.www.SceneJsonBean;
|
|
|
|
|
+import com.fdkankan.openApi.entity.www.SceneEditInfo;
|
|
|
|
|
+import com.fdkankan.openApi.entity.www.ScenePlus;
|
|
|
|
|
+import com.fdkankan.openApi.service.www.GaSceneService;
|
|
|
|
|
+import com.fdkankan.openApi.service.www.ISceneEditInfoService;
|
|
|
|
|
+import com.fdkankan.openApi.service.www.IScenePlusService;
|
|
|
|
|
+import com.fdkankan.openApi.vo.www.SaveScenePasswordDto;
|
|
|
|
|
+import com.fdkankan.redis.constant.RedisKey;
|
|
|
|
|
+import com.fdkankan.redis.util.RedisUtil;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
|
+
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
|
+
|
|
|
|
|
+@DS("www")
|
|
|
|
|
+@Service
|
|
|
|
|
+public class GaSceneServiceImpl implements GaSceneService {
|
|
|
|
|
+
|
|
|
|
|
+ private static final String VALID_PATTERN = "^[a-zA-Z0-9]{4}$";
|
|
|
|
|
+ private static final Pattern PATTERN = Pattern.compile(VALID_PATTERN);
|
|
|
|
|
+
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private ISceneEditInfoService sceneEditInfoService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IScenePlusService scenePlusService;
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private FYunFileServiceInterface fYunFileService;
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private RedisUtil redisUtil;
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void saveSceneViewPassword(SaveScenePasswordDto dto) {
|
|
|
|
|
+ String num = dto.getSceneCode();
|
|
|
|
|
+ //校验密码格式是否正确
|
|
|
|
|
+ if(this.validateScenePassword(dto.getPassword())){
|
|
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_3011.code(), "请设置4位数字或英文密码");
|
|
|
|
|
+ }
|
|
|
|
|
+ ScenePlus scenePlus = scenePlusService.getByNum(num);
|
|
|
|
|
+ if(scenePlus == null){
|
|
|
|
|
+ throw new BusinessException(ErrorCode.FAILURE_CODE_5005);
|
|
|
|
|
+ }
|
|
|
|
|
+ SceneEditInfo sceneEditInfo = sceneEditInfoService.getByScenePlusId(scenePlus.getId());
|
|
|
|
|
+ sceneEditInfo.setScenePassword(dto.getPassword());
|
|
|
|
|
+ sceneEditInfo.setUpdateTime(null);
|
|
|
|
|
+ sceneEditInfoService.updateById(sceneEditInfo);
|
|
|
|
|
+
|
|
|
|
|
+ //发布 scenePassword
|
|
|
|
|
+ String sceneJsonPath = String.format(UploadFilePath.DATA_VIEW_PATH, num) + "scene.json";
|
|
|
|
|
+ String sceneJson = fYunFileService.getFileContent(sceneJsonPath);
|
|
|
|
|
+ JSONObject jsonObject = JSON.parseObject(sceneJson);
|
|
|
|
|
+ jsonObject.put("scenePassword", dto.getPassword());
|
|
|
|
|
+ fYunFileService.uploadFile(jsonObject.toJSONString().getBytes(StandardCharsets.UTF_8), sceneJsonPath);
|
|
|
|
|
+ //删除redis缓存
|
|
|
|
|
+ redisUtil.del(String.format(RedisKey.SCENE_JSON, num));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public boolean validateScenePassword(String password) {
|
|
|
|
|
+ // 先判空,再用正则匹配
|
|
|
|
|
+ if (password == null) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 匹配正则表达式
|
|
|
|
|
+ return PATTERN.matcher(password).matches();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+}
|