package com.fdkankan.scene.controller; import cn.hutool.core.util.StrUtil; import com.dtflys.forest.annotation.Get; import com.fdkankan.common.constant.ErrorCode; import com.fdkankan.common.exception.BusinessException; import com.fdkankan.scene.entity.Scene3dfamily; import com.fdkankan.scene.entity.ScenePro; import com.fdkankan.scene.service.IScene3dfamilyService; import com.fdkankan.scene.service.ISceneProService; import com.fdkankan.scene.service.IUserService; import com.fdkankan.web.controller.BaseController; import com.fdkankan.web.response.Result; import com.fdkankan.web.user.SSOUser; import java.util.Arrays; import java.util.Date; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.util.ObjectUtils; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; /** * 三维家 */ @RefreshScope @Slf4j @RestController @RequestMapping("/service/scenev3/threefamily") public class Scene3dFamilyController extends BaseController { @Autowired private IScene3dfamilyService scene3dFamilyService; @Autowired private ISceneProService sceneProService; @Autowired private IUserService userService; @Value("${3d.family.keys:#{null}}") private String[] secrets; /** * * 三维家 拉取场景数据,压缩zip包 */ @GetMapping(value = "/scenecpzip") public Result scenecpzip(String sceneNum) throws Exception{ String token = getToken(); if(StringUtils.isEmpty(token)){ throw new BusinessException(ErrorCode.FAILURE_CODE_3004); } SSOUser ssoUser = this.getSsoUserV3(); if(ssoUser == null || ssoUser.getId() == null){ throw new BusinessException(ErrorCode.FAILURE_CODE_3004); } if(StrUtil.isEmpty(sceneNum)){ throw new BusinessException(ErrorCode.FAILURE_CODE_3001); } ScenePro sceneProEntity = sceneProService.findBySceneNum(sceneNum); if(sceneProEntity == null){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } //验证是否在打包 Scene3dfamily scene3dFamilyEntity = scene3dFamilyService.findSceneNumByNum(sceneProEntity.getNum(),0); if(scene3dFamilyEntity != null){ throw new BusinessException(ErrorCode.FAILURE_CODE_5031); } scene3dFamilyService.updateSceneNumByNum(sceneProEntity); //信息入库 scene3dFamilyEntity = new Scene3dfamily(); scene3dFamilyEntity.setSceneNum(sceneNum); scene3dFamilyEntity.setStatus(0); scene3dFamilyEntity.setZipStartTime(new Date()); scene3dFamilyEntity.setCreateUesr(ssoUser.getId()); scene3dFamilyEntity.setUpdateUesr(ssoUser.getId()); scene3dFamilyService.save(scene3dFamilyEntity); scene3dFamilyService.createZip(sceneProEntity, ssoUser.getId()); return Result.success(); } /** * * 三维家 拉取场景数据,压缩zip包 */ @GetMapping(value = "/detail") public Result detail(String sceneNum,String keys) throws Exception{ if (!ObjectUtils.isEmpty(secrets) && Arrays.asList(secrets).contains(keys)){ if(StrUtil.isEmpty(sceneNum)){ throw new BusinessException(ErrorCode.FAILURE_CODE_3001); } ScenePro sceneProEntity = sceneProService.findBySceneNum(sceneNum); if(sceneProEntity == null){ throw new BusinessException(ErrorCode.FAILURE_CODE_5005); } return Result.success(scene3dFamilyService.findSceneNumByNum2(sceneProEntity)); }else{ return Result.failure("身份验证失败!"); } } }