|
@@ -0,0 +1,244 @@
|
|
|
+package com.fdkankan.manage.inner.controller;
|
|
|
+
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.extra.servlet.ServletUtil;
|
|
|
+import cn.hutool.log.Log;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
+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.config.ManageConfig;
|
|
|
+import com.fdkankan.manage.controller.BaseController;
|
|
|
+import com.fdkankan.manage.entity.*;
|
|
|
+import com.fdkankan.manage.exception.BusinessException;
|
|
|
+import com.fdkankan.manage.service.*;
|
|
|
+import com.fdkankan.manage.util.RsaUtils;
|
|
|
+import com.fdkankan.manage.vo.request.RtkDeviceInParam;
|
|
|
+import com.fdkankan.manage.vo.request.RtkInfoParam;
|
|
|
+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;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * TODO
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author dengsixing
|
|
|
+ * @since 2022/6/7
|
|
|
+ **/
|
|
|
+@RestController
|
|
|
+@RequestMapping("/service/manage/inner")
|
|
|
+public class InnerController extends BaseController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISceneProService sceneProService;
|
|
|
+ @Autowired
|
|
|
+ IServiceUpTipService serviceUpTipService;
|
|
|
+ @Autowired
|
|
|
+ ManageConfig manageConfig;
|
|
|
+ @Autowired
|
|
|
+ IRtkInfoService rtkInfoService;
|
|
|
+ @Autowired
|
|
|
+ IRtkAccountService rtkAccountService;
|
|
|
+ @Autowired
|
|
|
+ IRtkDeviceService rtkDeviceService;
|
|
|
+ @Autowired
|
|
|
+ IRtkUseLogService rtkUseLogService;
|
|
|
+ @Autowired
|
|
|
+ IRtkUpdateLogService rtkUpdateLogService;
|
|
|
+ @Autowired
|
|
|
+ IAuthorizeRtkService authorizeRtkService;
|
|
|
+
|
|
|
+ @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( );
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 相机开启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);
|
|
|
+ }
|
|
|
+ RtkDevice rtkDevice = rtkDeviceService.getByRtkSnCode(rtkSnCode);
|
|
|
+ if(rtkDevice == null || rtkDevice.getUseStatus() !=0){
|
|
|
+ throw new BusinessException(ResultCode.RTK_SN_CODE_NOT_EXIT);
|
|
|
+ }
|
|
|
+ //2.9.0授权期限相机
|
|
|
+ if(rtkDevice.getAccountType() ==2){
|
|
|
+ List<AuthorizeRtk> authorizeRtks = authorizeRtkService.getByRtkId(rtkDevice.getId());
|
|
|
+ if(authorizeRtks == null || authorizeRtks.isEmpty()){
|
|
|
+ if(new Date().getTime() > DateUtil.parse(manageConfig.getAuthRtkExTime(),"yyyy-MM-dd HH:mm:ss").getTime()){
|
|
|
+ throw new BusinessException(ResultCode.RTK_SN_CODE_NOT_AUTH);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (authorizeRtks !=null && !authorizeRtks.isEmpty()){
|
|
|
+ Boolean flag = false;
|
|
|
+ Date now = new Date();
|
|
|
+ for (AuthorizeRtk authorizeRtk : authorizeRtks) {
|
|
|
+ if(DateUtil.isIn(now,authorizeRtk.getValidStartTime(),authorizeRtk.getValidEndTime())){
|
|
|
+ flag = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(!flag){
|
|
|
+ throw new BusinessException(ResultCode.RTK_SN_CODE_NOT_AUTH);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ //rtkDevice.getType() = 0板卡自带账号信息,无需关联
|
|
|
+ Integer rtkAccountId = null;
|
|
|
+ if(rtkDevice.getRtkType() == 0 && rtkDevice.getFailureTime() != null && rtkDevice.getFailureTime().getTime() <= new Date().getTime()){
|
|
|
+ rtkDevice.setRtkType(1);
|
|
|
+ rtkDeviceService.updateTypeById(rtkDevice.getId(),1);
|
|
|
+ }
|
|
|
+ if(rtkDevice.getRtkType() != 0 && (rtkDevice.getAccountType() == 0 || rtkDevice.getAccountType() == 2)){
|
|
|
+ RtkAccount rtkAccount = rtkAccountService.getOneNotUseAccount(rtkSnCode,rtkDevice.getCameraSn());
|
|
|
+ rtkAccountId = rtkAccount.getId();
|
|
|
+ BeanUtils.copyProperties(rtkAccount,rtkDevice);
|
|
|
+ }
|
|
|
+
|
|
|
+ String clientIP = ServletUtil.getClientIP(request);
|
|
|
+ rtkUseLogService.saveLog(clientIP,rtkAccountId,cameraSn,rtkDevice);
|
|
|
+ return ResultData.ok(rtkDevice);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 相机关闭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);
|
|
|
+ }
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 相机开启rtk获取账号
|
|
|
+ */
|
|
|
+ @GetMapping("/infoByTk/{rtkSnCode}")
|
|
|
+ public synchronized ResultData infoByTk(@PathVariable String rtkSnCode){
|
|
|
+ JSONObject jsonObject = checkRtkSign();
|
|
|
+ if(jsonObject == null){
|
|
|
+ throw new BusinessException(ResultCode.RTK_TOKEN_ERROR);
|
|
|
+ }
|
|
|
+ String string = jsonObject.getString("rtkSnCode");
|
|
|
+ if(!string.equals(rtkSnCode)){
|
|
|
+ throw new BusinessException(ResultCode.RTK_TOKEN_ERROR);
|
|
|
+ }
|
|
|
+ if(StringUtils.isBlank(rtkSnCode)){
|
|
|
+ throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
+ }
|
|
|
+ RtkDevice rtkDevice = rtkDeviceService.getByRtkSnCode(rtkSnCode);
|
|
|
+ if(rtkDevice == null || rtkDevice.getUseStatus() !=0){
|
|
|
+ throw new BusinessException(ResultCode.RTK_SN_CODE_NOT_EXIT);
|
|
|
+ }
|
|
|
+
|
|
|
+ return ResultData.ok(rtkDevice);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @PostMapping("/updateRtkInfo")
|
|
|
+ public ResultData updateRtkInfo(@RequestBody RtkInfo param){
|
|
|
+ if(StringUtils.isBlank(param.getRtkSnCode())){
|
|
|
+ throw new BusinessException(ResultCode.MISSING_REQUIRED_PARAMETERS);
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject jsonObject = checkRtkSign();
|
|
|
+ if(jsonObject == null){
|
|
|
+ throw new BusinessException(ResultCode.RTK_TOKEN_ERROR);
|
|
|
+ }
|
|
|
+ String string = jsonObject.getString("rtkSnCode");
|
|
|
+ if(!string.equals(param.getRtkSnCode())){
|
|
|
+ throw new BusinessException(ResultCode.RTK_TOKEN_ERROR);
|
|
|
+ }
|
|
|
+ String account = jsonObject.getString("account");
|
|
|
+
|
|
|
+ RtkDevice rtkDevice = rtkDeviceService.getByRtkSnCode(param.getRtkSnCode());
|
|
|
+ if(rtkDevice == null){
|
|
|
+ throw new BusinessException(ResultCode.RTK_SN_CODE_NOT_EXIT);
|
|
|
+ }
|
|
|
+ if(rtkDevice.getAccountType() == 0){ //账号池
|
|
|
+ throw new BusinessException(ResultCode.RTK_UPDATE_ERROR);
|
|
|
+ }
|
|
|
+ if(rtkDevice.getCameraType() !=3){ //只有深光能改
|
|
|
+ throw new BusinessException(ResultCode.RTK_UPDATE_ERROR);
|
|
|
+ }
|
|
|
+ if(rtkDevice.getRtkType() !=2){ //只有北云板卡能改
|
|
|
+ throw new BusinessException(ResultCode.RTK_UPDATE_ERROR);
|
|
|
+ }
|
|
|
+ LambdaUpdateWrapper<RtkDevice> wrapper = new LambdaUpdateWrapper<>();
|
|
|
+ wrapper.eq(RtkDevice::getId,rtkDevice.getId());
|
|
|
+ wrapper.set(RtkDevice::getUserName,param.getUserName());
|
|
|
+ wrapper.set(RtkDevice::getPassword,param.getPassword());
|
|
|
+ wrapper.set(RtkDevice::getIpAddr,param.getIpAddr());
|
|
|
+ wrapper.set(RtkDevice::getPort,param.getPort());
|
|
|
+ wrapper.set(RtkDevice::getMountPoint,param.getMountPoint());
|
|
|
+ wrapper.set(RtkDevice::getFailureTime,null);
|
|
|
+ rtkDeviceService.update(wrapper);
|
|
|
+
|
|
|
+ RtkUpdateLog rtkUpdateLog = new RtkUpdateLog();
|
|
|
+ rtkUpdateLog.setRtkSnCode(param.getRtkSnCode());
|
|
|
+ rtkUpdateLog.setFdAccount(account);
|
|
|
+ rtkUpdateLog.setOldJsonData(JSONObject.toJSONString(rtkDevice));
|
|
|
+ rtkUpdateLog.setNewJsonData(JSONObject.toJSONString(rtkDeviceService.getById(rtkDevice.getId())));
|
|
|
+ rtkUpdateLogService.save(rtkUpdateLog);
|
|
|
+ return ResultData.ok();
|
|
|
+ }
|
|
|
+}
|