k.e.book.ddh.controller.CcUserRuleController Maven / Gradle / Ivy
package k.e.book.ddh.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import k.e.book.common.model.Result;
import k.e.book.ddh.entity.CcUserRuleAddDTO;
import k.e.book.ddh.entity.CcUserRuleDO;
import k.e.book.ddh.entity.CcUserRuleQueryDTO;
import k.e.book.ddh.entity.CcUserRuleVO;
import k.e.book.ddh.service.CcUserRuleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* @author kk
* @date 2023-05-21 11:13
*/
@Api(tags = "CcUserRule相关文档")
@RestController
@RequestMapping("/ccUserRule")
public class CcUserRuleController {
@Resource
private CcUserRuleService ccUserRuleService;
@ApiOperation("分页查询CcUserRule信息")
@PostMapping(value = "/page")
public Result> queryPage(@RequestBody @Valid CcUserRuleQueryDTO dto) {
IPage page = ccUserRuleService.selectProductPage(dto);
List records = page.getRecords();
return Result.success(records.stream().map(CcUserRuleDO::toVO).filter(Objects::nonNull).collect(Collectors.toList()), page.getTotal());
}
@ApiOperation("根据 id 查询CcUserRule信息")
@GetMapping(value = "/get")
public Result getCcUserRuleById(@RequestParam("id") @ApiParam(value = "ccUserRuleD") Long id) {
return Result.success(CcUserRuleDO.toVO(ccUserRuleService.getById(id)));
}
@ApiOperation("新增CcUserRule")
@PostMapping("/add")
public Result addCcUserRule(@RequestBody @Valid CcUserRuleAddDTO dto) {
CcUserRuleDO entity = CcUserRuleDO.toDO(dto);
ccUserRuleService.save(entity);
return getCcUserRuleById(entity.getId());
}
@ApiOperation("删除CcUserRule")
@DeleteMapping("/delete")
public Result deleteCcUserRuleById(@RequestParam("id") @ApiParam(value = "ccUserRuleID") Long id) {
ccUserRuleService.removeById(id);
return Result.success();
}
}