k.e.book.ddh.controller.CcMergeMaterialController 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.CcMergeMaterialAddDTO;
import k.e.book.ddh.entity.CcMergeMaterialDO;
import k.e.book.ddh.entity.CcMergeMaterialQueryDTO;
import k.e.book.ddh.entity.CcMergeMaterialVO;
import k.e.book.ddh.service.CcMergeMaterialService;
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 = "CcMergeMaterial相关文档")
@RestController
@RequestMapping("/ccMergeMaterial")
public class CcMergeMaterialController {
@Resource
private CcMergeMaterialService ccMergeMaterialService;
@ApiOperation("分页查询CcMergeMaterial信息")
@PostMapping(value = "/page")
public Result> queryPage(@RequestBody @Valid CcMergeMaterialQueryDTO dto) {
IPage page = ccMergeMaterialService.selectProductPage(dto);
List records = page.getRecords();
return Result.success(records.stream().map(CcMergeMaterialDO::toVO).filter(Objects::nonNull).collect(Collectors.toList()), page.getTotal());
}
@ApiOperation("根据 id 查询CcMergeMaterial信息")
@GetMapping(value = "/get")
public Result getCcMergeMaterialById(@RequestParam("id") @ApiParam(value = "ccMergeMaterialD") Long id) {
return Result.success(CcMergeMaterialDO.toVO(ccMergeMaterialService.getById(id)));
}
@ApiOperation("新增CcMergeMaterial")
@PostMapping("/add")
public Result addCcMergeMaterial(@RequestBody @Valid CcMergeMaterialAddDTO dto) {
CcMergeMaterialDO entity = CcMergeMaterialDO.toDO(dto);
ccMergeMaterialService.save(entity);
return getCcMergeMaterialById(entity.getId());
}
@ApiOperation("删除CcMergeMaterial")
@DeleteMapping("/delete")
public Result deleteCcMergeMaterialById(@RequestParam("id") @ApiParam(value = "ccMergeMaterialID") Long id) {
ccMergeMaterialService.removeById(id);
return Result.success();
}
}