123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- package com.example.civilizedcity.controller;
-
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.baomidou.mybatisplus.core.metadata.IPage;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import com.example.civilizedcity.common.BaseController;
- import com.example.civilizedcity.common.Constants;
- import com.example.civilizedcity.common.ResponseBean;
-
- import java.time.LocalDateTime;
- import java.util.List;
-
- import com.example.civilizedcity.common.StringUtils;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import io.swagger.annotations.ApiParam;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.*;
- import com.example.civilizedcity.entity.TaCheckItem;
- import com.example.civilizedcity.service.TaCheckItemService;
-
- /**
- * 测评点位;(ta_check_item)表控制层
- * @author : http://njyunzhi.com
- * @date : 2022-12-13
- */
- @Api(tags = "测评点位对象功能接口")
- @RestController
- @RequestMapping("/")
- public class TaCheckItemController extends BaseController {
-
- @Autowired
- private TaCheckItemService taCheckItemService;
-
- /**
- * 通过ID查询单条数据
- *
- * @param itemId 主键
- * @return 实例对象
- */
- @ApiOperation("通过ID查询单条数据")
- @GetMapping("/taCheckItem/{id}")
- public ResponseBean queryById(@ApiParam("对象ID") @PathVariable String id) throws Exception {
- return ResponseBean.success(taCheckItemService.getById(id));
- }
-
- /**
- * 通过测评以及点位查询数据
- *
- * @param checkId 测评ID
- * @param typeId 点位ID
- * @return 实例对象
- */
- @ApiOperation("通过测评以及点位查询数据")
- @GetMapping("/taCheck/{checkId}/item/{typeId}")
- public ResponseBean queryByCheckId(@ApiParam("测评ID") @PathVariable String checkId,
- @ApiParam("点位ID") @PathVariable String typeId) throws Exception {
-
- return ResponseBean.success(getByCheckAndType(checkId, typeId));
- }
-
- private TaCheckItem getByCheckAndType(String checkId, String typeId) {
- QueryWrapper<TaCheckItem> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("check_id", checkId);
- queryWrapper.eq("item_type", Constants.CHECK_ITEM_LOC); // 只查点位
- queryWrapper.eq("type_id", typeId);
- queryWrapper.gt("status", Constants.STATUS_DELETE);
-
- return taCheckItemService.getOne(queryWrapper);
- }
-
- /**
- * 分页查询
- *
- * @param pageNum 当前页码
- * @param pageSize 每页条数
- * @return 查询结果
- */
- @ApiOperation("分页查询")
- @GetMapping("/taCheckItem")
- public ResponseBean list(@ApiParam("页码") @RequestParam(value ="pageNum",defaultValue = "1") Integer pageNum,
- @ApiParam("单页数据量") @RequestParam(value ="pageSize",defaultValue = "10") Integer pageSize) throws Exception {
-
- IPage<TaCheckItem> pg = new Page<>(pageNum, pageSize);
- // QueryWrapper<TaCheckItem> queryWrapper = new QueryWrapper<>();
- // queryWrapper.orderByDesc("create_date");
- IPage<TaCheckItem> result = taCheckItemService.page(pg);
-
- return ResponseBean.success(result);
- }
-
- /**
- * 新增数据
- *
- * @param taCheckItem 实例对象
- * @return 实例对象
- */
- @ApiOperation("新增数据")
- @PostMapping("/taCheckItem")
- public ResponseBean add(@ApiParam("对象实体") @RequestBody TaCheckItem taCheckItem) throws Exception {
-
- TaCheckItem origin = getByCheckAndType(taCheckItem.getCheckId(), taCheckItem.getItemId());
- if (null == origin) {
- // 新增
- taCheckItem.setStatus(Constants.STATUS_NORMAL);
- taCheckItem.setCreateDate(LocalDateTime.now());
- taCheckItemService.save(taCheckItem);
- } else {
- // 更新
- taCheckItem.setItemId((origin.getItemId()));
- taCheckItemService.updateById(taCheckItem);
- }
-
- return ResponseBean.success(taCheckItem);
- }
-
- // /**
- // * 更新数据
- // *
- // * @param taCheckItem 实例对象
- // * @return 实例对象
- // */
- // @ApiOperation("更新数据")
- // @PutMapping("/taCheckItem/{id}")
- // public ResponseBean edit(@ApiParam("对象实体") @RequestBody TaCheckItem taCheckItem,
- // @ApiParam("对象ID") @PathVariable String id ) throws Exception {
- // taCheckItemService.updateById(taCheckItem);
- // return ResponseBean.success(taCheckItem);
- // }
-
- /**
- * 通过主键删除数据
- *
- * @param itemId 主键
- * @return 是否成功
- */
- @ApiOperation("通过主键删除数据")
- @DeleteMapping("/taCheckItem/{id}")
- public ResponseBean deleteById(@ApiParam("对象ID") @PathVariable String id){
- taCheckItemService.removeLogicById(id);
- return ResponseBean.success("success");
- }
- }
|