Showing
9 changed files
with
305 additions
and
5 deletions
| @@ -86,6 +86,14 @@ | @@ -86,6 +86,14 @@ | ||
| 86 | <version>1.1.22</version> | 86 | <version>1.1.22</version> |
| 87 | </dependency> | 87 | </dependency> |
| 88 | 88 | ||
| 89 | + <dependency> | ||
| 90 | + <groupId>org.hibernate.validator</groupId> | ||
| 91 | + <artifactId>hibernate-validator</artifactId> | ||
| 92 | + </dependency> | ||
| 93 | + <dependency> | ||
| 94 | + <groupId>org.hibernate.validator</groupId> | ||
| 95 | + <artifactId>hibernate-validator-annotation-processor</artifactId> | ||
| 96 | + </dependency> | ||
| 89 | 97 | ||
| 90 | 98 | ||
| 91 | 99 |
| @@ -2,13 +2,13 @@ package com.wondertek.controller; | @@ -2,13 +2,13 @@ package com.wondertek.controller; | ||
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | import com.wondertek.dto.LMRoomDto; | 4 | import com.wondertek.dto.LMRoomDto; |
| 5 | +import com.wondertek.dto.LMRoomParam; | ||
| 5 | import com.wondertek.service.LiveMonitorRoomService; | 6 | import com.wondertek.service.LiveMonitorRoomService; |
| 6 | import com.wondertek.util.PageBean; | 7 | import com.wondertek.util.PageBean; |
| 8 | +import com.wondertek.util.ResultBean; | ||
| 7 | import jakarta.annotation.Resource; | 9 | import jakarta.annotation.Resource; |
| 8 | import lombok.extern.slf4j.Slf4j; | 10 | import lombok.extern.slf4j.Slf4j; |
| 9 | -import org.springframework.web.bind.annotation.GetMapping; | ||
| 10 | -import org.springframework.web.bind.annotation.RequestMapping; | ||
| 11 | -import org.springframework.web.bind.annotation.RestController; | 11 | +import org.springframework.web.bind.annotation.*; |
| 12 | 12 | ||
| 13 | @Slf4j | 13 | @Slf4j |
| 14 | @RestController | 14 | @RestController |
| @@ -40,4 +40,24 @@ public class LiveMonitorRoomController { | @@ -40,4 +40,24 @@ public class LiveMonitorRoomController { | ||
| 40 | return liveMonitorRoomService.queryPage(lmRoomDto); | 40 | return liveMonitorRoomService.queryPage(lmRoomDto); |
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | + | ||
| 44 | + @PostMapping("create") | ||
| 45 | + ResultBean create(@RequestBody LMRoomParam lmRoomParam){ | ||
| 46 | + return liveMonitorRoomService.create(lmRoomParam); | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + | ||
| 50 | + @GetMapping("setStatus") | ||
| 51 | + ResultBean updateStatus(@RequestParam(value = "id",required = true)Long id, | ||
| 52 | + @RequestParam(value = "status",required = true)String status){ | ||
| 53 | + return liveMonitorRoomService.updateStatus(id, status); | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + | ||
| 57 | + @GetMapping("remove") | ||
| 58 | + ResultBean delete(@RequestParam(value = "id",required = true)Long id ){ | ||
| 59 | + return liveMonitorRoomService.delete(id); | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + | ||
| 43 | } | 63 | } |
| 1 | +package com.wondertek.exception; | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * 业务异常类,只用于业务打断。 | ||
| 5 | + */ | ||
| 6 | +public class BusinessException extends ErrorCodeException { | ||
| 7 | + | ||
| 8 | + private static final long serialVersionUID = -5169960321643614644L; | ||
| 9 | + | ||
| 10 | + public BusinessException(String businessErrorCode) { | ||
| 11 | + super(businessErrorCode); | ||
| 12 | + } | ||
| 13 | + | ||
| 14 | + public BusinessException(String businessErrorCode, String message, Throwable cause) { | ||
| 15 | + super(businessErrorCode, message, cause); | ||
| 16 | + } | ||
| 17 | + | ||
| 18 | + public BusinessException(String businessErrorCode, String message) { | ||
| 19 | + super(businessErrorCode, message); | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | + public BusinessException(String businessErrorCode, Throwable cause) { | ||
| 23 | + super(businessErrorCode, cause); | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + public BusinessException(String businessErrorCode, String message, Object result) { | ||
| 27 | + super(businessErrorCode, message, result); | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + @Override | ||
| 31 | + public String getMessage() { | ||
| 32 | + return super.getMessage(); | ||
| 33 | + } | ||
| 34 | +} |
| 1 | +package com.wondertek.exception; | ||
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * 含错误码的异常类 | ||
| 5 | + * | ||
| 6 | + * @author: | ||
| 7 | + * @modify author:修改人 Modify on 修改时间 | ||
| 8 | + */ | ||
| 9 | +public class ErrorCodeException extends RuntimeException { | ||
| 10 | + | ||
| 11 | + private static final long serialVersionUID = -6862869612441955620L; | ||
| 12 | + | ||
| 13 | + /** 错误码 */ | ||
| 14 | + private String errorCode; | ||
| 15 | + | ||
| 16 | + /** 异常结果返回 */ | ||
| 17 | + private Object result; | ||
| 18 | + | ||
| 19 | + public ErrorCodeException(String errorCode) { | ||
| 20 | + this(errorCode, null, null); | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + public ErrorCodeException(String errorCode, String message) { | ||
| 24 | + this(errorCode, message, null); | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + public ErrorCodeException(String errorCode, Throwable cause) { | ||
| 28 | + this(errorCode, null, cause); | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + public ErrorCodeException(String errorCode, String message, Throwable cause) { | ||
| 32 | + super(message, cause); | ||
| 33 | + this.errorCode = errorCode; | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + public ErrorCodeException(String errorCode, String message, Object result) { | ||
| 37 | + super(message); | ||
| 38 | + this.errorCode = errorCode; | ||
| 39 | + this.result = result; | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + public String getErrorCode() { | ||
| 43 | + return errorCode; | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + @Override | ||
| 47 | + public String getMessage() { | ||
| 48 | + return super.getMessage(); | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + public Object getResult() { | ||
| 52 | + return this.result; | ||
| 53 | + } | ||
| 54 | +} |
| 1 | +package com.wondertek.exception; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | +import com.wondertek.util.ResultBean; | ||
| 5 | +import jakarta.validation.ConstraintViolation; | ||
| 6 | +import jakarta.validation.ConstraintViolationException; | ||
| 7 | +import lombok.extern.slf4j.Slf4j; | ||
| 8 | +import org.springframework.http.HttpStatus; | ||
| 9 | +import org.springframework.util.CollectionUtils; | ||
| 10 | +import org.springframework.validation.ObjectError; | ||
| 11 | +import org.springframework.web.HttpRequestMethodNotSupportedException; | ||
| 12 | +import org.springframework.web.bind.MethodArgumentNotValidException; | ||
| 13 | +import org.springframework.web.bind.MissingServletRequestParameterException; | ||
| 14 | +import org.springframework.web.bind.annotation.ExceptionHandler; | ||
| 15 | +import org.springframework.web.bind.annotation.ResponseStatus; | ||
| 16 | +import org.springframework.web.bind.annotation.RestControllerAdvice; | ||
| 17 | +import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; | ||
| 18 | + | ||
| 19 | + | ||
| 20 | +import java.util.List; | ||
| 21 | + | ||
| 22 | +/** | ||
| 23 | + * 异常统一处理类 | ||
| 24 | + * @author luyafei | ||
| 25 | + */ | ||
| 26 | +@Slf4j | ||
| 27 | +@RestControllerAdvice | ||
| 28 | +public class GlobalExceptionHandler { | ||
| 29 | + | ||
| 30 | + private static final String LESS_REQUIRED_PARAM = "缺少必要参数"; | ||
| 31 | + private static final String REQUEST_PARAMS_IS_NOT_ILLEGAL = "请求参数不合法"; | ||
| 32 | + private static final String REQUEST_PARAMS_IS_NOT_EMPTY = "参数不能为空"; | ||
| 33 | + private static final String REQUEST_PARAMS_MISMATCH = "请求参数类型不匹配"; | ||
| 34 | + private static final String REQUEST_PARAMS_NUMBER_FORMAT_IS_ERROR = "请求参数数字类型解析异常"; | ||
| 35 | + private static final String REQUEST_METHOD_NOT_SUPPORT = "当前requestMethod请求类型不支持"; | ||
| 36 | + private static final String UNKNOWN = "未知异常"; | ||
| 37 | + | ||
| 38 | + @ExceptionHandler(value = Exception.class) | ||
| 39 | + @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) | ||
| 40 | + public ResultBean unKnownException(Exception e) { | ||
| 41 | + return responseException(UNKNOWN, e); | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + @ExceptionHandler(value = MethodArgumentNotValidException.class) | ||
| 45 | + @ResponseStatus(HttpStatus.BAD_REQUEST) | ||
| 46 | + public ResultBean methodArgumentNotValidException(MethodArgumentNotValidException e) { | ||
| 47 | + List<ObjectError> allErrors = e.getBindingResult().getAllErrors(); | ||
| 48 | + if (!CollectionUtils.isEmpty(allErrors)) { | ||
| 49 | + return responseException(allErrors.get(0).getDefaultMessage(), e); | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + return responseException(LESS_REQUIRED_PARAM, e); | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + @ExceptionHandler(value = ConstraintViolationException.class) | ||
| 56 | + @ResponseStatus(HttpStatus.BAD_REQUEST) | ||
| 57 | + public ResultBean handleValidationException(ConstraintViolationException e) { | ||
| 58 | + for (ConstraintViolation<?> s : e.getConstraintViolations()) { | ||
| 59 | + return responseException(s.getMessage() + " : " + s.getInvalidValue(), e); | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + return ResultBean.error(REQUEST_PARAMS_IS_NOT_ILLEGAL); | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + | ||
| 66 | + | ||
| 67 | + @ExceptionHandler(value = MissingServletRequestParameterException.class) | ||
| 68 | + @ResponseStatus(HttpStatus.BAD_REQUEST) | ||
| 69 | + public ResultBean handleMissingServletRequestParameterException(MissingServletRequestParameterException e) { | ||
| 70 | + return responseException(e.getParameterName() + REQUEST_PARAMS_IS_NOT_EMPTY, e); | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + @ExceptionHandler(value = MethodArgumentTypeMismatchException.class) | ||
| 74 | + @ResponseStatus(HttpStatus.BAD_REQUEST) | ||
| 75 | + public ResultBean handlerMethodArgumentTypeMismatchException(MethodArgumentTypeMismatchException e) { | ||
| 76 | + return responseException(e.getName() + REQUEST_PARAMS_MISMATCH, e); | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + @ExceptionHandler(value = NumberFormatException.class) | ||
| 80 | + @ResponseStatus(HttpStatus.BAD_REQUEST) | ||
| 81 | + public ResultBean handlerNumberFormatException(NumberFormatException e) { | ||
| 82 | + return responseException(REQUEST_PARAMS_NUMBER_FORMAT_IS_ERROR, e); | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + @ExceptionHandler(value = HttpRequestMethodNotSupportedException.class) | ||
| 86 | + @ResponseStatus(HttpStatus.BAD_REQUEST) | ||
| 87 | + public ResultBean handlerHttpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException e) { | ||
| 88 | + return responseException(REQUEST_METHOD_NOT_SUPPORT, e); | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + private ResultBean responseException(String msg, Exception e) { | ||
| 92 | + log.info(e.getMessage(), e); | ||
| 93 | + return ResultBean.error(msg); | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | +} |
| @@ -16,4 +16,11 @@ public interface LiveMonitorRoomService extends IService<LiveMonitorRoom> { | @@ -16,4 +16,11 @@ public interface LiveMonitorRoomService extends IService<LiveMonitorRoom> { | ||
| 16 | 16 | ||
| 17 | ResultBean create(LMRoomParam lmRoomParam); | 17 | ResultBean create(LMRoomParam lmRoomParam); |
| 18 | 18 | ||
| 19 | + | ||
| 20 | + ResultBean update(LMRoomParam lmRoomParam); | ||
| 21 | + | ||
| 22 | + ResultBean updateStatus(Long id, String status); | ||
| 23 | + | ||
| 24 | + ResultBean delete(Long id); | ||
| 25 | + | ||
| 19 | } | 26 | } |
| @@ -59,7 +59,42 @@ public class LiveMonitorRoomServiceImpl extends ServiceImpl<LiveMonitorRoomMappe | @@ -59,7 +59,42 @@ public class LiveMonitorRoomServiceImpl extends ServiceImpl<LiveMonitorRoomMappe | ||
| 59 | 59 | ||
| 60 | List<CrpDataVo> dataList = lmRoomParam.getDataList(); | 60 | List<CrpDataVo> dataList = lmRoomParam.getDataList(); |
| 61 | 61 | ||
| 62 | - //初始化子任务信息 | 62 | + //更新子任务信息 |
| 63 | + if(!CollectionUtils.isEmpty(dataList)){ | ||
| 64 | + dataList.forEach(crpDataVo -> { | ||
| 65 | + Long sId = crpDataVo.getId(); | ||
| 66 | + StreamTask streamTask = monitorMarkService.getById(sId); | ||
| 67 | + streamTask.setTaskId(crpDataVo.getTaskId()); | ||
| 68 | + streamTask.setChannelId(crpDataVo.getChannelId()); | ||
| 69 | + streamTask.setRoomId(roomId); | ||
| 70 | + streamTask.setTaskType(crpDataVo.getTaskType()); | ||
| 71 | + streamTask.setCreatedBy(""); | ||
| 72 | + streamTask.setCreatedTime(LocalDateTime.now()); | ||
| 73 | + monitorMarkService.updateById(streamTask); | ||
| 74 | + }); | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + return ResultBean.ok("修改成功"); | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + @Override | ||
| 81 | + public ResultBean update(LMRoomParam lmRoomParam) { | ||
| 82 | + | ||
| 83 | + Long id = lmRoomParam.getId(); | ||
| 84 | + | ||
| 85 | + LiveMonitorRoom monitorRoom = getById(id); | ||
| 86 | + | ||
| 87 | + if(monitorRoom == null){ | ||
| 88 | + return ResultBean.error("房间不存在"); | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + monitorRoom.setName(lmRoomParam.getName()); | ||
| 92 | + monitorRoom.setLiveName(lmRoomParam.getLiveName()); | ||
| 93 | + saveOrUpdate(monitorRoom); | ||
| 94 | + | ||
| 95 | + //更新子任务 | ||
| 96 | + List<CrpDataVo> dataList = lmRoomParam.getDataList(); | ||
| 97 | + | ||
| 63 | if(!CollectionUtils.isEmpty(dataList)){ | 98 | if(!CollectionUtils.isEmpty(dataList)){ |
| 64 | List<StreamTask> taskList = dataList.stream().map(crpDataVo -> { | 99 | List<StreamTask> taskList = dataList.stream().map(crpDataVo -> { |
| 65 | StreamTask streamTask = new StreamTask(); | 100 | StreamTask streamTask = new StreamTask(); |
| @@ -74,6 +109,48 @@ public class LiveMonitorRoomServiceImpl extends ServiceImpl<LiveMonitorRoomMappe | @@ -74,6 +109,48 @@ public class LiveMonitorRoomServiceImpl extends ServiceImpl<LiveMonitorRoomMappe | ||
| 74 | monitorMarkService.saveOrUpdateBatch(taskList); | 109 | monitorMarkService.saveOrUpdateBatch(taskList); |
| 75 | } | 110 | } |
| 76 | 111 | ||
| 77 | - return ResultBean.ok("创建成功"); | 112 | + |
| 113 | + return null; | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + @Override | ||
| 117 | + public ResultBean updateStatus(Long id, String status) { | ||
| 118 | + | ||
| 119 | + LiveMonitorRoom monitorRoom = getById(id); | ||
| 120 | + | ||
| 121 | + if(monitorRoom == null){ | ||
| 122 | + return ResultBean.error("房间不存在"); | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + String brocStatus = monitorRoom.getBrocStatus(); | ||
| 126 | + | ||
| 127 | + if("0".equals(brocStatus)){ | ||
| 128 | + return ResultBean.error("播控中房间不能禁用"); | ||
| 129 | + } | ||
| 130 | + monitorRoom.setRoomStatus(status); | ||
| 131 | + monitorRoom.setUpdatedTime(LocalDateTime.now()); | ||
| 132 | + saveOrUpdate(monitorRoom); | ||
| 133 | + | ||
| 134 | + return ResultBean.ok("修改成功"); | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + @Override | ||
| 138 | + public ResultBean delete(Long id) { | ||
| 139 | + LiveMonitorRoom monitorRoom = getById(id); | ||
| 140 | + | ||
| 141 | + if(monitorRoom == null){ | ||
| 142 | + return ResultBean.error("房间不存在"); | ||
| 143 | + } | ||
| 144 | + | ||
| 145 | + String roomStatus = monitorRoom.getRoomStatus(); | ||
| 146 | + | ||
| 147 | + if("0".equals(roomStatus)){ | ||
| 148 | + return ResultBean.error("启用的房间不能删除"); | ||
| 149 | + } | ||
| 150 | + monitorRoom.setDel("1"); | ||
| 151 | + monitorRoom.setUpdatedTime(LocalDateTime.now()); | ||
| 152 | + saveOrUpdate(monitorRoom); | ||
| 153 | + | ||
| 154 | + return ResultBean.ok("删除成功"); | ||
| 78 | } | 155 | } |
| 79 | } | 156 | } |
| @@ -17,6 +17,7 @@ | @@ -17,6 +17,7 @@ | ||
| 17 | FROM | 17 | FROM |
| 18 | crp_live_monitor_room` | 18 | crp_live_monitor_room` |
| 19 | <where> | 19 | <where> |
| 20 | + `del`=0 | ||
| 20 | <if test="dto.name != null and dto.name != ''"> | 21 | <if test="dto.name != null and dto.name != ''"> |
| 21 | and `name` like CONCAT('%',#{dto.name},'%') | 22 | and `name` like CONCAT('%',#{dto.name},'%') |
| 22 | </if> | 23 | </if> |
-
Please register or login to post a comment