package com.fdkankan.manage.inner.controller; import cn.hutool.extra.servlet.ServletUtil; import cn.hutool.log.Log; import com.fdkankan.common.util.SecurityUtil; import com.fdkankan.manage.common.CacheUtil; import com.fdkankan.manage.common.ResultCode; import com.fdkankan.manage.common.ResultData; import com.fdkankan.manage.controller.BaseController; import com.fdkankan.manage.entity.RtkAccount; import com.fdkankan.manage.entity.RtkDevice; import com.fdkankan.manage.entity.RtkInfo; import com.fdkankan.manage.entity.RtkUseLog; import com.fdkankan.manage.exception.BusinessException; import com.fdkankan.manage.service.*; import com.fdkankan.manage.util.RsaUtils; import com.fdkankan.manage.vo.request.SceneParam; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import java.util.Date; /** *

* TODO *

* * @author dengsixing * @since 2022/6/7 **/ @RestController @RequestMapping("/service/manage/inner") public class InnerController extends BaseController { @Autowired private ISceneProService sceneProService; @Autowired IServiceUpTipService serviceUpTipService; @PostMapping("/move") public ResultData move(@RequestBody SceneParam param){ if(!checkSign()){ return ResultData.error(-1,"签名错误"); } if(StringUtils.isEmpty(param.getNum()) || StringUtils.isEmpty(param.getSnCode())){ throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS); } sceneProService.move(param); return ResultData.ok(); } @GetMapping("/copyScene") public ResultData copyScene(@RequestParam(required = false) String num){ if(!checkSign()){ return ResultData.error(-1,"签名错误"); } if(StringUtils.isEmpty(num)){ throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS); } sceneProService.copy(num); return ResultData.ok(); } @GetMapping("/getServiceUpTip") public ResultData getServiceUpTip(@RequestParam(required = false) Integer type){ return ResultData.ok( serviceUpTipService.getServiceUpTipByType(type)); } @GetMapping("/rebuildScene") public ResultData rebuild(@RequestParam(required = false) String num,@RequestParam(required = false) String from){ sceneProService.rebuildScene(num,from); return ResultData.ok( ); } @Autowired IRtkInfoService rtkInfoService; @Autowired IRtkAccountService rtkAccountService; @Autowired IRtkDeviceService rtkDeviceService; @Autowired IRtkUseLogService rtkUseLogService; /** * 相机开启rtk获取账号 */ @GetMapping("/info/{rtkSnCode}") public synchronized ResultData info(@PathVariable String rtkSnCode, @RequestParam(value = "cameraSn",required = false) String cameraSn){ if(StringUtils.isBlank(rtkSnCode)){ throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS); } if("aws".equals(CacheUtil.uploadType)){ RtkInfo rtkInfo = rtkInfoService.getByRtkSnCode(rtkSnCode); if(rtkInfo == null || rtkInfo.getStatus() == 1 || rtkInfo.getFailureTime().getTime() <= new Date().getTime()){ throw new BusinessException(ResultCode.RTK_SN_CODE_NOT_EXIT); } String clientIP = ServletUtil.getClientIP(request); rtkUseLogService.saveLog(rtkInfo,clientIP,cameraSn,0); return ResultData.ok(rtkInfo); } RtkDevice rtkDevice = rtkDeviceService.getByRtkSnCode(rtkSnCode); if(rtkDevice == null || rtkDevice.getUseStatus() !=0){ throw new BusinessException(ResultCode.RTK_SN_CODE_NOT_EXIT); } RtkInfo rtkInfo = new RtkInfo(); rtkInfo.setRtkSnCode(rtkSnCode); rtkInfo.setRtkType(rtkDevice.getRtkType()); //rtkDevice.getType() = 0板卡自带账号信息,无需关联 Integer rtkAccountId = null; if(rtkDevice.getRtkType() != 0){ RtkAccount rtkAccount = rtkAccountService.getOneNotUseAccount(rtkSnCode,rtkDevice.getCameraSn()); rtkAccountId = rtkAccount.getId(); BeanUtils.copyProperties(rtkAccount,rtkInfo); } String clientIP = ServletUtil.getClientIP(request); rtkUseLogService.saveLog(rtkInfo,clientIP,rtkAccountId,cameraSn,rtkDevice); return ResultData.ok(rtkInfo); } /** * 相机关闭rtk,回收账号 */ @GetMapping("/stop/{rtkSnCode}") public ResultData stop(@PathVariable String rtkSnCode, @RequestParam(value = "cameraSn",required = false) String cameraSn){ if(StringUtils.isBlank(rtkSnCode)){ throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS); } if("aws".equals(CacheUtil.uploadType)){ RtkInfo rtkInfo = rtkInfoService.getByRtkSnCode(rtkSnCode); if(rtkInfo == null || rtkInfo.getStatus() == 1 || rtkInfo.getFailureTime().getTime() <= new Date().getTime()){ throw new BusinessException(ResultCode.RTK_SN_CODE_NOT_EXIT); } String clientIP = ServletUtil.getClientIP(request); rtkUseLogService.saveLog(rtkInfo,clientIP,cameraSn,1); return ResultData.ok(); } RtkDevice rtkDevice = rtkDeviceService.getByRtkSnCode(rtkSnCode); if(rtkDevice == null){ throw new BusinessException(ResultCode.RTK_SN_CODE_NOT_EXIT); } String clientIP = ServletUtil.getClientIP(request); rtkAccountService.stop(rtkDevice,clientIP,cameraSn); return ResultData.ok(); } }