zhongdaoyi@wondertek.com.cn

审片间接口初始化2

... ... @@ -86,6 +86,14 @@
<version>1.1.22</version>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator-annotation-processor</artifactId>
</dependency>
... ...
... ... @@ -2,13 +2,13 @@ package com.wondertek.controller;
import com.wondertek.dto.LMRoomDto;
import com.wondertek.dto.LMRoomParam;
import com.wondertek.service.LiveMonitorRoomService;
import com.wondertek.util.PageBean;
import com.wondertek.util.ResultBean;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
@Slf4j
@RestController
... ... @@ -40,4 +40,24 @@ public class LiveMonitorRoomController {
return liveMonitorRoomService.queryPage(lmRoomDto);
}
@PostMapping("create")
ResultBean create(@RequestBody LMRoomParam lmRoomParam){
return liveMonitorRoomService.create(lmRoomParam);
}
@GetMapping("setStatus")
ResultBean updateStatus(@RequestParam(value = "id",required = true)Long id,
@RequestParam(value = "status",required = true)String status){
return liveMonitorRoomService.updateStatus(id, status);
}
@GetMapping("remove")
ResultBean delete(@RequestParam(value = "id",required = true)Long id ){
return liveMonitorRoomService.delete(id);
}
}
... ...
... ... @@ -5,6 +5,9 @@ import lombok.Data;
@Data
public class CrpDataVo {
private Long id;
/**
* 频道唯一标识
* <p>关联转码平台的频道ID</p>
... ...
package com.wondertek.exception;
/**
* 业务异常类,只用于业务打断。
*/
public class BusinessException extends ErrorCodeException {
private static final long serialVersionUID = -5169960321643614644L;
public BusinessException(String businessErrorCode) {
super(businessErrorCode);
}
public BusinessException(String businessErrorCode, String message, Throwable cause) {
super(businessErrorCode, message, cause);
}
public BusinessException(String businessErrorCode, String message) {
super(businessErrorCode, message);
}
public BusinessException(String businessErrorCode, Throwable cause) {
super(businessErrorCode, cause);
}
public BusinessException(String businessErrorCode, String message, Object result) {
super(businessErrorCode, message, result);
}
@Override
public String getMessage() {
return super.getMessage();
}
}
... ...
package com.wondertek.exception;
/**
* 含错误码的异常类
*
* @author:
* @modify author:修改人 Modify on 修改时间
*/
public class ErrorCodeException extends RuntimeException {
private static final long serialVersionUID = -6862869612441955620L;
/** 错误码 */
private String errorCode;
/** 异常结果返回 */
private Object result;
public ErrorCodeException(String errorCode) {
this(errorCode, null, null);
}
public ErrorCodeException(String errorCode, String message) {
this(errorCode, message, null);
}
public ErrorCodeException(String errorCode, Throwable cause) {
this(errorCode, null, cause);
}
public ErrorCodeException(String errorCode, String message, Throwable cause) {
super(message, cause);
this.errorCode = errorCode;
}
public ErrorCodeException(String errorCode, String message, Object result) {
super(message);
this.errorCode = errorCode;
this.result = result;
}
public String getErrorCode() {
return errorCode;
}
@Override
public String getMessage() {
return super.getMessage();
}
public Object getResult() {
return this.result;
}
}
... ...
package com.wondertek.exception;
import com.wondertek.util.ResultBean;
import jakarta.validation.ConstraintViolation;
import jakarta.validation.ConstraintViolationException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.util.CollectionUtils;
import org.springframework.validation.ObjectError;
import org.springframework.web.HttpRequestMethodNotSupportedException;
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 org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
import java.util.List;
/**
* 异常统一处理类
* @author luyafei
*/
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
private static final String LESS_REQUIRED_PARAM = "缺少必要参数";
private static final String REQUEST_PARAMS_IS_NOT_ILLEGAL = "请求参数不合法";
private static final String REQUEST_PARAMS_IS_NOT_EMPTY = "参数不能为空";
private static final String REQUEST_PARAMS_MISMATCH = "请求参数类型不匹配";
private static final String REQUEST_PARAMS_NUMBER_FORMAT_IS_ERROR = "请求参数数字类型解析异常";
private static final String REQUEST_METHOD_NOT_SUPPORT = "当前requestMethod请求类型不支持";
private static final String UNKNOWN = "未知异常";
@ExceptionHandler(value = Exception.class)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public ResultBean unKnownException(Exception e) {
return responseException(UNKNOWN, e);
}
@ExceptionHandler(value = MethodArgumentNotValidException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public ResultBean methodArgumentNotValidException(MethodArgumentNotValidException e) {
List<ObjectError> allErrors = e.getBindingResult().getAllErrors();
if (!CollectionUtils.isEmpty(allErrors)) {
return responseException(allErrors.get(0).getDefaultMessage(), e);
}
return responseException(LESS_REQUIRED_PARAM, e);
}
@ExceptionHandler(value = ConstraintViolationException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public ResultBean handleValidationException(ConstraintViolationException e) {
for (ConstraintViolation<?> s : e.getConstraintViolations()) {
return responseException(s.getMessage() + " : " + s.getInvalidValue(), e);
}
return ResultBean.error(REQUEST_PARAMS_IS_NOT_ILLEGAL);
}
@ExceptionHandler(value = MissingServletRequestParameterException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public ResultBean handleMissingServletRequestParameterException(MissingServletRequestParameterException e) {
return responseException(e.getParameterName() + REQUEST_PARAMS_IS_NOT_EMPTY, e);
}
@ExceptionHandler(value = MethodArgumentTypeMismatchException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public ResultBean handlerMethodArgumentTypeMismatchException(MethodArgumentTypeMismatchException e) {
return responseException(e.getName() + REQUEST_PARAMS_MISMATCH, e);
}
@ExceptionHandler(value = NumberFormatException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public ResultBean handlerNumberFormatException(NumberFormatException e) {
return responseException(REQUEST_PARAMS_NUMBER_FORMAT_IS_ERROR, e);
}
@ExceptionHandler(value = HttpRequestMethodNotSupportedException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public ResultBean handlerHttpRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException e) {
return responseException(REQUEST_METHOD_NOT_SUPPORT, e);
}
private ResultBean responseException(String msg, Exception e) {
log.info(e.getMessage(), e);
return ResultBean.error(msg);
}
}
... ...
... ... @@ -16,4 +16,11 @@ public interface LiveMonitorRoomService extends IService<LiveMonitorRoom> {
ResultBean create(LMRoomParam lmRoomParam);
ResultBean update(LMRoomParam lmRoomParam);
ResultBean updateStatus(Long id, String status);
ResultBean delete(Long id);
}
... ...
... ... @@ -59,7 +59,42 @@ public class LiveMonitorRoomServiceImpl extends ServiceImpl<LiveMonitorRoomMappe
List<CrpDataVo> dataList = lmRoomParam.getDataList();
//初始化子任务信息
//更新子任务信息
if(!CollectionUtils.isEmpty(dataList)){
dataList.forEach(crpDataVo -> {
Long sId = crpDataVo.getId();
StreamTask streamTask = monitorMarkService.getById(sId);
streamTask.setTaskId(crpDataVo.getTaskId());
streamTask.setChannelId(crpDataVo.getChannelId());
streamTask.setRoomId(roomId);
streamTask.setTaskType(crpDataVo.getTaskType());
streamTask.setCreatedBy("");
streamTask.setCreatedTime(LocalDateTime.now());
monitorMarkService.updateById(streamTask);
});
}
return ResultBean.ok("修改成功");
}
@Override
public ResultBean update(LMRoomParam lmRoomParam) {
Long id = lmRoomParam.getId();
LiveMonitorRoom monitorRoom = getById(id);
if(monitorRoom == null){
return ResultBean.error("房间不存在");
}
monitorRoom.setName(lmRoomParam.getName());
monitorRoom.setLiveName(lmRoomParam.getLiveName());
saveOrUpdate(monitorRoom);
//更新子任务
List<CrpDataVo> dataList = lmRoomParam.getDataList();
if(!CollectionUtils.isEmpty(dataList)){
List<StreamTask> taskList = dataList.stream().map(crpDataVo -> {
StreamTask streamTask = new StreamTask();
... ... @@ -74,6 +109,48 @@ public class LiveMonitorRoomServiceImpl extends ServiceImpl<LiveMonitorRoomMappe
monitorMarkService.saveOrUpdateBatch(taskList);
}
return ResultBean.ok("创建成功");
return null;
}
@Override
public ResultBean updateStatus(Long id, String status) {
LiveMonitorRoom monitorRoom = getById(id);
if(monitorRoom == null){
return ResultBean.error("房间不存在");
}
String brocStatus = monitorRoom.getBrocStatus();
if("0".equals(brocStatus)){
return ResultBean.error("播控中房间不能禁用");
}
monitorRoom.setRoomStatus(status);
monitorRoom.setUpdatedTime(LocalDateTime.now());
saveOrUpdate(monitorRoom);
return ResultBean.ok("修改成功");
}
@Override
public ResultBean delete(Long id) {
LiveMonitorRoom monitorRoom = getById(id);
if(monitorRoom == null){
return ResultBean.error("房间不存在");
}
String roomStatus = monitorRoom.getRoomStatus();
if("0".equals(roomStatus)){
return ResultBean.error("启用的房间不能删除");
}
monitorRoom.setDel("1");
monitorRoom.setUpdatedTime(LocalDateTime.now());
saveOrUpdate(monitorRoom);
return ResultBean.ok("删除成功");
}
}
... ...
... ... @@ -17,6 +17,7 @@
FROM
crp_live_monitor_room`
<where>
`del`=0
<if test="dto.name != null and dto.name != ''">
and `name` like CONCAT('%',#{dto.name},'%')
</if>
... ...