save@PostMapping("/save")
public ResponseResult save(@RequestBody ChannelDto channelDto){
// 参数判断
if(channelDto == null || StringUtils.isBlank(channelDto.getName())){
return ResponseResult.error(AppHttpCodeEnum.PARAM_REQUIRE);
}
// 对象转换
AdChannel adChannel = BeanHelper.copyProperties(channelDto, AdChannel.class);
boolean b = channelService.save(adChannel);
if(!b){
throw new LeadException(AppHttpCodeEnum.SERVER_ERROR);
}
return ResponseResult.ok();
}
修改
@PutMapping("/update")
public ResponseResult update(@RequestBody ChannelDto channelDto){
// 参数判断
if(channelDto == null || channelDto.getId() == null){
return ResponseResult.error(AppHttpCodeEnum.PARAM_REQUIRE);
}
// 对象转换
AdChannel adChannel = BeanHelper.copyProperties(channelDto, AdChannel.class);
boolean b = channelService.updateById(adChannel);
if(!b){
throw new LeadException(AppHttpCodeEnum.SERVER_ERROR);
}
return ResponseResult.ok();
}
如果当前状态为有效则不能删除
根据id 删除 void delete(Long id);
@Override
public void delete(Long id) {
AdChannel adChannel = this.getById(id);
if(adChannel == null){
throw new LeadException(AppHttpCodeEnum.DATA_NOT_EXIST);
}
if(adChannel.getStatus()){
throw new LeadException(AppHttpCodeEnum.PARAM_INVALID,"只有在无效状态才能删除");
}
boolean b = this.removeById(id);
if(!b){
throw new LeadException(AppHttpCodeEnum.SERVER_ERROR,"删除失败!");
}
}
@DeleteMapping("/del/{id}")
public ResponseResult deleteById(@PathVariable("id") Long id){
channelService.delete(id);
return ResponseResult.ok();
}