k.e.book.ddh.controller.CcProductMergeRuleController 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.CcProductMergeRuleAddDTO;
import k.e.book.ddh.entity.CcProductMergeRuleDO;
import k.e.book.ddh.entity.CcProductMergeRuleQueryDTO;
import k.e.book.ddh.entity.CcProductMergeRuleVO;
import k.e.book.ddh.service.CcProductMergeRuleService;
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 = "CcProductMergeRule相关文档")
@RestController
@RequestMapping("/ccProductMergeRule")
public class CcProductMergeRuleController {
@Resource
private CcProductMergeRuleService ccProductMergeRuleService;
@ApiOperation("分页查询CcProductMergeRule信息")
@PostMapping(value = "/page")
public Result> queryPage(@RequestBody @Valid CcProductMergeRuleQueryDTO dto) {
IPage page = ccProductMergeRuleService.selectProductPage(dto);
List records = page.getRecords();
return Result.success(records.stream().map(CcProductMergeRuleDO::toVO).filter(Objects::nonNull).collect(Collectors.toList()), page.getTotal());
}
@ApiOperation("根据 id 查询CcProductMergeRule信息")
@GetMapping(value = "/get")
public Result getCcProductMergeRuleById(@RequestParam("id") @ApiParam(value = "ccProductMergeRuleD") Long id) {
return Result.success(CcProductMergeRuleDO.toVO(ccProductMergeRuleService.getById(id)));
}
@ApiOperation("新增CcProductMergeRule")
@PostMapping("/add")
public Result addCcProductMergeRule(@RequestBody @Valid CcProductMergeRuleAddDTO dto) {
CcProductMergeRuleDO entity = CcProductMergeRuleDO.toDO(dto);
ccProductMergeRuleService.save(entity);
return getCcProductMergeRuleById(entity.getId());
}
@ApiOperation("删除CcProductMergeRule")
@DeleteMapping("/delete")
public Result deleteCcProductMergeRuleById(@RequestParam("id") @ApiParam(value = "ccProductMergeRuleID") Long id) {
ccProductMergeRuleService.removeById(id);
return Result.success();
}
}