k.e.book.ddh.controller.CcCommandController 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.CcCommandAddDTO;
import k.e.book.ddh.entity.CcCommandDO;
import k.e.book.ddh.entity.CcCommandQueryDTO;
import k.e.book.ddh.entity.CcCommandVO;
import k.e.book.ddh.service.CcCommandService;
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 = "CcCommand相关文档")
@RestController
@RequestMapping("/ccCommand")
public class CcCommandController {
@Resource
private CcCommandService ccCommandService;
@ApiOperation("分页查询CcCommand信息")
@PostMapping(value = "/page")
public Result> queryPage(@RequestBody @Valid CcCommandQueryDTO dto) {
IPage page = ccCommandService.selectProductPage(dto);
List records = page.getRecords();
return Result.success(records.stream().map(CcCommandDO::toVO).filter(Objects::nonNull).collect(Collectors.toList()), page.getTotal());
}
@ApiOperation("根据 id 查询CcCommand信息")
@GetMapping(value = "/get")
public Result getCcCommandById(@RequestParam("id") @ApiParam(value = "ccCommandD") Long id) {
return Result.success(CcCommandDO.toVO(ccCommandService.getById(id)));
}
@ApiOperation("新增CcCommand")
@PostMapping("/add")
public Result addCcCommand(@RequestBody @Valid CcCommandAddDTO dto) {
CcCommandDO entity = CcCommandDO.toDO(dto);
ccCommandService.save(entity);
return getCcCommandById(entity.getId());
}
@ApiOperation("删除CcCommand")
@DeleteMapping("/delete")
public Result deleteCcCommandById(@RequestParam("id") @ApiParam(value = "ccCommandID") Long id) {
ccCommandService.removeById(id);
return Result.success();
}
}