Browse Source

添加敬然那边的请求接口

zhujinghui 4 years ago
parent
commit
1267038dd5

+ 14 - 0
src/main/java/com/example/demo/controller/SceneStyleController.java

@@ -339,4 +339,18 @@ public class SceneStyleController {
         return Result.success();
         return Result.success();
     }
     }
 
 
+
+    @ApiOperation("全景图渲染版本叠加(给3D同事那边调用)")
+    @RequestMapping(value = "/addStyleVersion", method = RequestMethod.POST)
+    public Result addStyleVersion(@RequestBody RequestSceneLight style){
+        if(style.getStyleNum() == null){
+            return Result.failure(CodeConstant.FAILURE_CODE_3001, CodeConstant.FAILURE_MSG_3001);
+        }
+        int row = sceneStyleService.addVersion(style);
+        if (row == 0) {
+            return Result.failure("控制后台找不到对应渲染记录");
+        }
+        return Result.success();
+    }
+
 }
 }

+ 88 - 0
src/main/java/com/example/demo/exception/GlobalExceptionHandler.java

@@ -0,0 +1,88 @@
+package com.example.demo.exception;
+
+import com.example.demo.util.Result;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.context.support.DefaultMessageSourceResolvable;
+import org.springframework.http.HttpStatus;
+import org.springframework.validation.BindException;
+import org.springframework.web.bind.MethodArgumentNotValidException;
+import org.springframework.web.bind.MissingServletRequestParameterException;
+import org.springframework.web.bind.annotation.ExceptionHandler;
+import org.springframework.web.bind.annotation.ResponseStatus;
+import org.springframework.web.bind.annotation.RestControllerAdvice;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.stream.Collectors;
+
+/**
+ * 全局异常捕获统一返回客户端
+ * @author Admin
+ */
+@Slf4j
+@RestControllerAdvice
+public class GlobalExceptionHandler {
+
+    /**
+     * 处理其他异常
+     * @param e
+     * @return
+     */
+    @ExceptionHandler(value = Exception.class)
+    public Result exceptionHandler(Exception e){
+        log.error("程序错误原因:", e);
+        return Result.failure("服务端异常");
+    }
+
+
+    /**
+     * 处理其他异常
+     * @param e
+     * @return
+     */
+    @ExceptionHandler(value = MissingServletRequestParameterException.class)
+    public Result exceptionHandler(MissingServletRequestParameterException e){
+        log.error("缺少必要参数:", e);
+        return Result.failure(HttpStatus.BAD_REQUEST.value(), "缺少必要参数");
+    }
+
+
+
+    /**
+     * 处理请求参数格式错误 @RequestBody上validate失败后抛出的异常是MethodArgumentNotValidException异常
+     */
+    @ExceptionHandler(MethodArgumentNotValidException.class)
+    public Result MethodArgumentNotValidExceptionHandler(MethodArgumentNotValidException e) {
+        String message = e.getBindingResult().getAllErrors().stream().map(DefaultMessageSourceResolvable::getDefaultMessage).collect(Collectors.joining());
+        //下边ResultCodeEnum.PARAMS_BS_ERROR.getCode()就是你自己自定义的返回code码
+        return Result.failure(HttpStatus.BAD_REQUEST.value(), message);
+    }
+
+    /**
+     * 处理Get请求中 使用@Valid 验证路径中请求实体校验失败后抛出的异常
+     */
+    @ExceptionHandler(BindException.class)
+    public Result BindExceptionHandler(BindException e) {
+        String message = e.getBindingResult().getAllErrors().stream().map(DefaultMessageSourceResolvable::getDefaultMessage).collect(Collectors.joining());
+        return Result.failure(HttpStatus.BAD_REQUEST.value(), message);
+    }
+
+    /**
+     * @link https://www.cnblogs.com/cjyboy/p/11465876.html
+     * 处理请求参数格式错误 @RequestParam上validate失败后抛出的异常是ConstraintViolationException
+     */
+//    @ExceptionHandler(ConstraintViolationException.class)
+//    public ViewResult ConstraintViolationExceptionHandler(ConstraintViolationException e) {
+//        String message = e.getConstraintViolations().stream().map(ConstraintViolation::getMessage).collect(Collectors.joining());
+//        return ViewResult.error(HttpStatus.BAD_REQUEST.value(), message);
+//    }
+
+
+
+    @ExceptionHandler(RuntimeException.class)
+    @ResponseStatus(HttpStatus.OK)
+    public Result runtimeExceptionHandler(HttpServletRequest request, RuntimeException e) {
+        log.error("uri:{},stack trace:",request.getRequestURI(),e);
+        return Result.failure(e.getMessage());
+    }
+
+}

+ 9 - 0
src/main/java/com/example/demo/mapper/ISceneStyleMapper.java

@@ -1,8 +1,10 @@
 package com.example.demo.mapper;
 package com.example.demo.mapper;
 
 
 import com.example.demo.entity.SceneStyleEntity;
 import com.example.demo.entity.SceneStyleEntity;
+import com.example.demo.vo.request.RequestSceneLight;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Select;
 import org.apache.ibatis.annotations.Select;
+import org.apache.ibatis.annotations.Update;
 
 
 /**
 /**
  * Created by Hb_zzZ on 2020/7/14.
  * Created by Hb_zzZ on 2020/7/14.
@@ -12,4 +14,11 @@ public interface ISceneStyleMapper extends IBaseMapper<SceneStyleEntity, Long> {
 
 
     @Select("select max(num) from tb_scene_style where scene_num = #{sceneNum}")
     @Select("select max(num) from tb_scene_style where scene_num = #{sceneNum}")
     Integer findLastNum(String sceneNum);
     Integer findLastNum(String sceneNum);
+
+    /**
+     * 版本号+1
+     * @param style
+     */
+    @Update("update tb_scene_style set pano_version = pano_version + 1 where style_num = #{styleNum} and rec_status = 'A'")
+    int addVersion(RequestSceneLight style);
 }
 }

+ 3 - 0
src/main/java/com/example/demo/service/ISceneStyleService.java

@@ -1,6 +1,7 @@
 package com.example.demo.service;
 package com.example.demo.service;
 
 
 import com.example.demo.entity.SceneStyleEntity;
 import com.example.demo.entity.SceneStyleEntity;
+import com.example.demo.vo.request.RequestSceneLight;
 
 
 /**
 /**
  * Created by Hb_zzZ on 2020/7/14.
  * Created by Hb_zzZ on 2020/7/14.
@@ -8,4 +9,6 @@ import com.example.demo.entity.SceneStyleEntity;
 public interface ISceneStyleService extends IBaseService<SceneStyleEntity, Long>{
 public interface ISceneStyleService extends IBaseService<SceneStyleEntity, Long>{
 
 
     Integer findLastNum(String sceneNum);
     Integer findLastNum(String sceneNum);
+
+    int addVersion(RequestSceneLight style);
 }
 }

+ 7 - 1
src/main/java/com/example/demo/service/impl/SceneStyleServiceImpl.java

@@ -4,6 +4,7 @@ import com.example.demo.entity.SceneStyleEntity;
 import com.example.demo.mapper.IBaseMapper;
 import com.example.demo.mapper.IBaseMapper;
 import com.example.demo.mapper.ISceneStyleMapper;
 import com.example.demo.mapper.ISceneStyleMapper;
 import com.example.demo.service.ISceneStyleService;
 import com.example.demo.service.ISceneStyleService;
+import com.example.demo.vo.request.RequestSceneLight;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.annotation.Transactional;
@@ -12,7 +13,6 @@ import org.springframework.transaction.annotation.Transactional;
  * Created by Hb_zzZ on 2020/7/14.
  * Created by Hb_zzZ on 2020/7/14.
  */
  */
 @Service
 @Service
-@Transactional
 public class SceneStyleServiceImpl extends BaseServiceImpl<SceneStyleEntity, Long> implements ISceneStyleService{
 public class SceneStyleServiceImpl extends BaseServiceImpl<SceneStyleEntity, Long> implements ISceneStyleService{
 
 
     @Autowired
     @Autowired
@@ -27,4 +27,10 @@ public class SceneStyleServiceImpl extends BaseServiceImpl<SceneStyleEntity, Lon
     public Integer findLastNum(String sceneNum) {
     public Integer findLastNum(String sceneNum) {
         return mapper.findLastNum(sceneNum);
         return mapper.findLastNum(sceneNum);
     }
     }
+
+    @Override
+    public int addVersion(RequestSceneLight style) {
+        int row = mapper.addVersion(style);
+        return row;
+    }
 }
 }