列表展示:
@AutoLog(value = "视频分页列表展示")
@ApiOperation(value = "视频分页列表展示", notes = "视频分页列表展示")
@GetMapping(value = "/pageList")
public Result<IPage<CustPromoteVideoInfo>> pageList(CustPromoteVideoInfo custPromoteVideoInfo,
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
HttpServletRequest req) {
Result<IPage<CustPromoteVideoInfo>> result = new Result<IPage<CustPromoteVideoInfo>>();
QueryWrapper<CustPromoteVideoInfo> queryWrapper = QueryGenerator.initQueryWrapper(custPromoteVideoInfo, req.getParameterMap());
Page<CustPromoteVideoInfo> page = new Page<>(pageNo, pageSize);
IPage<CustPromoteVideoInfo> pageList = custPromoteVideoInfoService.page(page, queryWrapper);
log.debug("查询当前页:"+pageList.getCurrent());
log.debug("查询当前页数量:"+pageList.getSize());
log.debug("查询结果数量:"+pageList.getRecords().size());
log.debug("数据总数:"+pageList.getTotal());
result.setSuccess(true);
result.setResult(pageList);
return result;
}
根据id查询:
@AutoLog(value = "查看视频详细")
@ApiOperation(value = "查看视频详细", notes = "查看视频详细")
@GetMapping("/queryById")
public Result<CustPromoteVideoInfo> queryById(@RequestParam(name = "id")String id){
CustPromoteVideoInfo custPromotePosterInfo =custPromoteVideoInfoService.queryById(id);
return Result.OK("查询成功", custPromotePosterInfo);
}
@Service
@Slf4j
public class CustPromoteVideoInfoServiceImpl extends ServiceImpl<CustPromoteVideoInfoMapper,CustPromoteVideoInfo> implements ICustPromoteVideoInfoService {
@Override
public CustPromoteVideoInfo queryById(String id){
CustPromoteVideoInfo custPromoteVideoInfo = this.getById(id);
log.info("视频详细信息为{}", custPromoteVideoInfo);
if (CommUtils.isEmpty(custPromoteVideoInfo)){
throw new ClmpException("视频不存在");
}
return custPromoteVideoInfo;
}
}
增加:
@PostMapping("add")
@AutoLog(value = "营销管理-视频推广")
@ApiOperation(value = "营销管理-视频推广-新增", notes = "营销管理-视频推广-新增")
public Result<String> add(@RequestBody CustPromoteVideoDto custPromoteVideoDto){
custPromoteVideoInfoService.add(custPromoteVideoDto);
return Result.OK("新增成功");
}
@Override
public boolean add(CustPromoteVideoDto custPromoteVideoDto) {
log.info("视频保入口参数:{}", custPromoteVideoDto);
// 参数校验
String validate = ValidationUtils.validate(custPromoteVideoDto, AddValidateGroup.class);
if (CommUtils.isNotEmpty(validate)){
throw new ClmpException("参数校验失败,原因为:" + validate);
}
CustPromoteVideoInfo custPromoteVideoInfo = BeanUtils.transfer(custPromoteVideoDto, new CustPromoteVideoInfo());
fillDefaultProperty(custPromoteVideoInfo);
return this.save(custPromoteVideoInfo);
}
删除:
@PostMapping("deleteById")
@AutoLog(value = "营销管理-视频推广-删除")
@ApiOperation(value = "营销管理-视频推广-删除", notes = "营销管理-视频推广-删除")
public Result<String> deleteById(@RequestBody CustPromoteVideoDto custPromoteVideoDto){
custPromoteVideoInfoService.deleteById(custPromoteVideoDto);
return Result.OK("删除成功");
}
@Override
public boolean deleteById(CustPromoteVideoDto custPromoteVideoDto) {
String id = custPromoteVideoDto.getId();
log.info("删除主键id为{}", id);
//用notBlank除了可以排除null,还可以排除空字符串
Assert.notBlank(id, "主键id不能为空");
CustPromoteVideoInfo custPromoteVideoInfo = this.getById(id);
delPromoteStatusValid(custPromoteVideoInfo);
return this.removeById(id);
}
private void delPromoteStatusValid(CustPromoteVideoInfo custPromoteVideoInfo) {
if (CommUtils.isEmpty(custPromoteVideoInfo)){
throw new ClmpException("数据不存在");
}
if (AuditStatusEnum.SUCCESS_AUDIT.getValue().equals(custPromoteVideoInfo.getAuditStatus())){
throw new ClmpException("审核通不可删除");
}
}
编辑:
@PostMapping("edit")
@AutoLog(value = "营销管理-视频推广-编辑")
@ApiOperation(value = "营销管理-视频推广-编辑", notes = "营销管理-视频推广-编辑")
public Result<String> edit(@RequestBody CustPromoteVideoDto custPromoteVideoDto){
custPromoteVideoInfoService.edit(custPromoteVideoDto);
return Result.OK("更新状态成功");
}
@Override
public boolean edit(CustPromoteVideoDto custPromoteVideoDto) {
log.info("编辑接口入参为{}", custPromoteVideoDto);
String validate = ValidationUtils.validate(custPromoteVideoDto, AddValidateGroup.class, EditValidateGroup.class);
if (CommUtils.isNotEmpty(validate)){
throw new ClmpException("参数校验失败,原因为:" + validate);
}
CustPromoteVideoInfo custPromoteVideoInfoDB = this.getById(custPromoteVideoDto.getId());
editStatusValid(custPromoteVideoInfoDB);
CustPromoteVideoInfo transfer = BeanUtils.transfer(custPromoteVideoDto, new CustPromoteVideoInfo());
return this.updateById(transfer);
}
private void editStatusValid(CustPromoteVideoInfo custPromoteVideoInfoDB) {
if (CommUtils.isEmpty(custPromoteVideoInfoDB)){
throw new ClmpException("数据不存在");
}
if (!AuditStatusEnum.WAITING_AUDIT.getValue().equals(custPromoteVideoInfoDB.getAuditStatus())){
throw new ClmpException("待审核状态方可修改数据");
}
}
更新状态:
@PostMapping("updatePromoteStatus")
@AutoLog(value = "营销管理-视频推广-更新状态")
@ApiOperation(value = "营销管理-视频推广-更新状态", notes = "营销管理-视频推广-更新状态")
public Result<String> updatePromoteStatus(@RequestBody CustPromoteVideoDto custPromoteVideoDto){
custPromoteVideoInfoService.updatePromoteStatus(custPromoteVideoDto);
return Result.OK("更新状态成功");
}
@Override
public boolean updatePromoteStatus(CustPromoteVideoDto custPromoteVideoDto) {
String status =custPromoteVideoDto.getStatus();
String id = custPromoteVideoDto.getId();
String validate = ValidationUtils.validate(custPromoteVideoDto, AddValidateGroup.class, EditValidateGroup.class);
if (CommUtils.isNotEmpty(validate)){
throw new ClmpException("参数校验失败,原因为:" + validate);
}
//用notBlank除了排除null,还可以排除空字符
Assert.notBlank(id, "主键不能为空");
Assert.notBlank(status, "禁用/启用状态不能为空");
log.info("主键id为{},启用状态为{}", id, status);
CustPromoteVideoInfo custPromoteVideoInfo= this.getById(id);
updateAuditStatusValid(custPromoteVideoInfo);
return this.updateStatusById(id, status);
}
private void updateAuditStatusValid(CustPromoteVideoInfo custPromoteVideoInfo) {
if (CommUtils.isEmpty(custPromoteVideoInfo)){
throw new ClmpException("数据不存在");
}
if (!AuditStatusEnum.SUCCESS_AUDIT.getValue().equals(custPromoteVideoInfo.getAuditStatus())){
throw new ClmpException("审核通过状态可修改启用禁用状态");
}
}
审核
@Override
public boolean audit(CustPromoteVideoDto custPromoteVideoDto) {
log.info("视频审核接口入参为{}", custPromoteVideoDto);
// 参数校验
String validate = ValidationUtils.validate(custPromoteVideoDto, AddValidateGroup.class, AuditValidateGroup.class);
if (CommUtils.isNotEmpty(validate)){
throw new ClmpException("参数校验失败,原因为:" + validate);
}
CustPromoteVideoInfo custPromoteVideoInfo = BeanUtils.transfer(custPromoteVideoDto, new CustPromoteVideoInfo());
fillAuditDefaultProperty(custPromoteVideoInfo);
return this.updateById(custPromoteVideoInfo);
}
private void fillAuditDefaultProperty(CustPromoteVideoInfo custPromoteVideoInfo) {
LoginUser loginUser = SysLoginUtils.getLoginUser();
custPromoteVideoInfo.setUpdateBy(loginUser.getRealname());
custPromoteVideoInfo.setUpdateById(loginUser.getUsername());
custPromoteVideoInfo.setUpdateTime(new Date());
}