TaCheckItemController.java 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. package com.example.civilizedcity.controller;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.baomidou.mybatisplus.core.metadata.IPage;
  4. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  5. import com.example.civilizedcity.common.BaseController;
  6. import com.example.civilizedcity.common.Constants;
  7. import com.example.civilizedcity.common.ResponseBean;
  8. import java.time.LocalDateTime;
  9. import java.util.List;
  10. import com.example.civilizedcity.common.StringUtils;
  11. import io.swagger.annotations.Api;
  12. import io.swagger.annotations.ApiOperation;
  13. import io.swagger.annotations.ApiParam;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.web.bind.annotation.*;
  16. import com.example.civilizedcity.entity.TaCheckItem;
  17. import com.example.civilizedcity.service.TaCheckItemService;
  18. /**
  19. * 测评点位;(ta_check_item)表控制层
  20. * @author : http://njyunzhi.com
  21. * @date : 2022-12-13
  22. */
  23. @Api(tags = "测评点位对象功能接口")
  24. @RestController
  25. @RequestMapping("/")
  26. public class TaCheckItemController extends BaseController {
  27. @Autowired
  28. private TaCheckItemService taCheckItemService;
  29. /**
  30. * 通过ID查询单条数据
  31. *
  32. * @param itemId 主键
  33. * @return 实例对象
  34. */
  35. @ApiOperation("通过ID查询单条数据")
  36. @GetMapping("/taCheckItem/{id}")
  37. public ResponseBean queryById(@ApiParam("对象ID") @PathVariable String id) throws Exception {
  38. return ResponseBean.success(taCheckItemService.getById(id));
  39. }
  40. /**
  41. * 通过测评以及点位查询数据
  42. *
  43. * @param checkId 测评ID
  44. * @param typeId 点位ID
  45. * @return 实例对象
  46. */
  47. @ApiOperation("通过测评以及点位查询数据")
  48. @GetMapping("/taCheck/{checkId}/item/{typeId}")
  49. public ResponseBean queryByCheckId(@ApiParam("测评ID") @PathVariable String checkId,
  50. @ApiParam("点位ID") @PathVariable String typeId) throws Exception {
  51. return ResponseBean.success(getByCheckAndType(checkId, typeId));
  52. }
  53. private TaCheckItem getByCheckAndType(String checkId, String typeId) {
  54. QueryWrapper<TaCheckItem> queryWrapper = new QueryWrapper<>();
  55. queryWrapper.eq("check_id", checkId);
  56. queryWrapper.eq("item_type", Constants.CHECK_ITEM_LOC); // 只查点位
  57. queryWrapper.eq("type_id", typeId);
  58. queryWrapper.gt("status", Constants.STATUS_DELETE);
  59. return taCheckItemService.getOne(queryWrapper);
  60. }
  61. /**
  62. * 分页查询
  63. *
  64. * @param pageNum 当前页码
  65. * @param pageSize 每页条数
  66. * @return 查询结果
  67. */
  68. @ApiOperation("分页查询")
  69. @GetMapping("/taCheckItem")
  70. public ResponseBean list(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
  71. @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception {
  72. IPage<TaCheckItem> pg = new Page<>(pageNum, pageSize);
  73. // QueryWrapper<TaCheckItem> queryWrapper = new QueryWrapper<>();
  74. // queryWrapper.orderByDesc("create_date");
  75. IPage<TaCheckItem> result = taCheckItemService.page(pg);
  76. return ResponseBean.success(result);
  77. }
  78. /**
  79. * 新增数据
  80. *
  81. * @param taCheckItem 实例对象
  82. * @return 实例对象
  83. */
  84. @ApiOperation("新增数据")
  85. @PostMapping("/taCheckItem")
  86. public ResponseBean add(@ApiParam("对象实体") @RequestBody TaCheckItem taCheckItem) throws Exception {
  87. TaCheckItem origin = getByCheckAndType(taCheckItem.getCheckId(), taCheckItem.getItemId());
  88. if (null == origin) {
  89. // 新增
  90. taCheckItem.setStatus(Constants.STATUS_NORMAL);
  91. taCheckItem.setCreateDate(LocalDateTime.now());
  92. taCheckItemService.save(taCheckItem);
  93. } else {
  94. // 更新
  95. taCheckItem.setItemId((origin.getItemId()));
  96. taCheckItemService.updateById(taCheckItem);
  97. }
  98. return ResponseBean.success(taCheckItem);
  99. }
  100. // /**
  101. // * 更新数据
  102. // *
  103. // * @param taCheckItem 实例对象
  104. // * @return 实例对象
  105. // */
  106. // @ApiOperation("更新数据")
  107. // @PutMapping("/taCheckItem/{id}")
  108. // public ResponseBean edit(@ApiParam("对象实体") @RequestBody TaCheckItem taCheckItem,
  109. // @ApiParam("对象ID") @PathVariable String id ) throws Exception {
  110. // taCheckItemService.updateById(taCheckItem);
  111. // return ResponseBean.success(taCheckItem);
  112. // }
  113. /**
  114. * 通过主键删除数据
  115. *
  116. * @param itemId 主键
  117. * @return 是否成功
  118. */
  119. @ApiOperation("通过主键删除数据")
  120. @DeleteMapping("/taCheckItem/{id}")
  121. public ResponseBean deleteById(@ApiParam("对象ID") @PathVariable String id){
  122. taCheckItemService.removeLogicById(id);
  123. return ResponseBean.success("success");
  124. }
  125. }