k.e.book.ddh.controller.CcEmsController 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.CcEmsAddDTO;
import k.e.book.ddh.entity.CcEmsDO;
import k.e.book.ddh.entity.CcEmsQueryDTO;
import k.e.book.ddh.entity.CcEmsVO;
import k.e.book.ddh.service.CcEmsService;
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 = "CcEms相关文档")
@RestController
@RequestMapping("/ccEms")
public class CcEmsController {
@Resource
private CcEmsService ccEmsService;
@ApiOperation("分页查询CcEms信息")
@PostMapping(value = "/page")
public Result> queryPage(@RequestBody @Valid CcEmsQueryDTO dto) {
IPage page = ccEmsService.selectProductPage(dto);
List records = page.getRecords();
return Result.success(records.stream().map(CcEmsDO::toVO).filter(Objects::nonNull).collect(Collectors.toList()), page.getTotal());
}
@ApiOperation("根据 id 查询CcEms信息")
@GetMapping(value = "/get")
public Result getCcEmsById(@RequestParam("id") @ApiParam(value = "ccEmsD") Long id) {
return Result.success(CcEmsDO.toVO(ccEmsService.getById(id)));
}
@ApiOperation("新增CcEms")
@PostMapping("/add")
public Result addCcEms(@RequestBody @Valid CcEmsAddDTO dto) {
CcEmsDO entity = CcEmsDO.toDO(dto);
ccEmsService.save(entity);
return getCcEmsById(entity.getId());
}
@ApiOperation("删除CcEms")
@DeleteMapping("/delete")
public Result deleteCcEmsById(@RequestParam("id") @ApiParam(value = "ccEmsID") Long id) {
ccEmsService.removeById(id);
return Result.success();
}
}