|
|
@@ -0,0 +1,89 @@
|
|
|
+package com.smart.reader.controller;
|
|
|
+
|
|
|
+import com.smart.reader.common.Page;
|
|
|
+import com.smart.reader.common.R;
|
|
|
+import com.smart.reader.enums.SuccessResultCode;
|
|
|
+import com.smart.reader.exception.CustomException;
|
|
|
+import com.smart.reader.model.bo.BookInfoAddBo;
|
|
|
+import com.smart.reader.model.bo.BookInfoUpdateBo;
|
|
|
+import com.smart.reader.model.vo.BookInfoVo;
|
|
|
+import com.smart.reader.service.BookInfoService;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiImplicitParam;
|
|
|
+import io.swagger.annotations.ApiImplicitParams;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import javax.validation.Valid;
|
|
|
+import javax.validation.constraints.NotNull;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+@RequestMapping("/api/v1/bookborrowing/bookInfo")
|
|
|
+@RestController
|
|
|
+@Validated
|
|
|
+@Api(tags = "书籍管理", description = "书籍管理相关接口")
|
|
|
+public class BookInfoController {
|
|
|
+ @Resource
|
|
|
+ private BookInfoService bookInfoService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增书籍数据
|
|
|
+ *
|
|
|
+ * @param bookInfo 实例对象
|
|
|
+ * @return 实例对象
|
|
|
+ */
|
|
|
+ @ApiOperation("新增书籍数据")
|
|
|
+ @PostMapping("/add")
|
|
|
+ public R add(@RequestBody @Valid BookInfoAddBo bookInfo) throws CustomException {
|
|
|
+ bookInfoService.add(bookInfo);
|
|
|
+ return R.success(SuccessResultCode.SUCCESS.getCode(), SuccessResultCode.SUCCESS.getMsg());
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation("删除书籍数据")
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "id", value = "书籍ID", required = true)
|
|
|
+ })
|
|
|
+ @DeleteMapping("/delete/{id}")
|
|
|
+ public R delete(@NotNull(message = "书籍ID不能为空") @PathVariable("id") Long id) throws CustomException {
|
|
|
+ bookInfoService.delete(id);
|
|
|
+ return R.fail(SuccessResultCode.SUCCESS.getCode(), SuccessResultCode.SUCCESS.getMsg());
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation("批量删除书籍数据")
|
|
|
+ @DeleteMapping("/batchDelete")
|
|
|
+ public R batchDelete(@RequestBody List<Long> ids) throws CustomException {
|
|
|
+ bookInfoService.batchDelete(ids);
|
|
|
+ return R.success(SuccessResultCode.SUCCESS.getCode(), "批量删除成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation("修改书籍数据")
|
|
|
+ @PutMapping("/edit")
|
|
|
+ public R edit(@RequestBody @Valid BookInfoUpdateBo bookInfo) throws CustomException {
|
|
|
+ System.out.println(bookInfo);
|
|
|
+ bookInfoService.edit(bookInfo);
|
|
|
+ return R.fail(SuccessResultCode.SUCCESS.getCode(), SuccessResultCode.SUCCESS.getMsg());
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("queryInfo")
|
|
|
+ @ApiOperation("获取书籍列表")
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "pageNum", value = "当前页", required = true, dataType = "int", defaultValue = "1"),
|
|
|
+ @ApiImplicitParam(name = "pageSize", value = "页大小", required = true, dataType = "int", defaultValue = "10"),
|
|
|
+ })
|
|
|
+ public R<Page<BookInfoVo>> queryInfo(int pageNum, int pageSize) {
|
|
|
+ Page<BookInfoVo> result = bookInfoService.queryInfo(pageNum, pageSize);
|
|
|
+ return R.success(SuccessResultCode.SUCCESS.getCode(), SuccessResultCode.SUCCESS.getMsg(), result);
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation("根据书籍ID查询书籍详情")
|
|
|
+ @ApiImplicitParams({
|
|
|
+ @ApiImplicitParam(name = "id", value = "书籍ID", required = true)
|
|
|
+ })
|
|
|
+ @GetMapping("/detail/{id}")
|
|
|
+ public R detail(@NotNull(message = "书籍ID不能为空") @PathVariable("id") Long id) {
|
|
|
+ BookInfoVo bookInfoVo = bookInfoService.detail(id);
|
|
|
+ return R.success(SuccessResultCode.SUCCESS.getCode(), SuccessResultCode.SUCCESS.getMsg(), bookInfoVo);
|
|
|
+ }
|
|
|
+}
|