package com.artfess.base.controller; import com.artfess.base.annotation.SyncAnnotation; import com.artfess.base.enums.ResponseErrorEnums; import com.artfess.base.manager.BaseManager; import com.artfess.base.model.CommonResult; import com.artfess.base.query.PageList; import com.artfess.base.query.QueryFilter; import com.artfess.base.valid.AddGroup; import com.artfess.base.valid.UpdateGroup; import com.baomidou.mybatisplus.extension.activerecord.Model; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpMethod; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import java.util.Arrays; import java.util.HashMap; /** * 基础的控制器 * * @company 阿特菲斯信息技术有限公司 * @author heyifan * @email heyf@jee-soft.cn * @date 2020年4月6日 */ public class BaseController , T extends Model>{ @Autowired protected M baseService; @SyncAnnotation(httpMethod = "post") @PostMapping("/") @ApiOperation(value = "添加实体的接口") public CommonResult create(@ApiParam(name="model", value="实体信息") @RequestBody @Validated({AddGroup.class}) T t) { boolean result = baseService.save(t); if(!result) { return new CommonResult<>(ResponseErrorEnums.FAIL_OPTION, null); } return new CommonResult<>(); } @PostMapping(value="/query", produces={"application/json; charset=utf-8" }) @ApiOperation("分页查询结果") public PageList query(@ApiParam(name="queryFilter", value="分页查询信息") @RequestBody QueryFilter queryFilter) { return baseService.query(queryFilter); } @GetMapping("/{id}") @ApiOperation("根据id查询实体") public T getById(@ApiParam(name="id", value="实体id") @PathVariable String id) { return baseService.getById(id); } @SyncAnnotation(httpMethod = "put") @PutMapping("/") @ApiOperation("更新实体") public CommonResult updateById(@ApiParam(name="model", value="实体信息") @RequestBody @Validated({UpdateGroup.class}) T t) { boolean result = baseService.updateById(t); if(!result) { return new CommonResult<>(ResponseErrorEnums.FAIL_OPTION, "更新实体失败"); } return new CommonResult<>(); } @SyncAnnotation(httpMethod = "delete") @DeleteMapping("/{id}") @ApiOperation("根据id删除") public CommonResult deleteById(@ApiParam(name="id", value="实体id") @PathVariable String id) { boolean result = baseService.removeById(id); if(!result) { return new CommonResult<>(ResponseErrorEnums.FAIL_OPTION, "删除实体失败"); } return new CommonResult<>(); } @SyncAnnotation(httpMethod = "delete") @DeleteMapping("/") @ApiOperation("根据id集合批量删除") public CommonResult deleteByIds(@ApiParam(name="ids", value="实体集合") @RequestParam String...ids) { boolean result = baseService.removeByIds(Arrays.asList(ids)); if(!result) { return new CommonResult<>(ResponseErrorEnums.FAIL_OPTION, "删除实体失败"); } return new CommonResult<>(); } @SyncAnnotation(httpMethod = "post") @RequestMapping(value = "updateSequence", method = RequestMethod.POST, produces = {"application/json; charset=utf-8"}) @ApiOperation(value = "批量修改排序号", notes = "批量修改排序号") public CommonResult updateSequence(@ApiParam(name = "params", value = "排序参数:Key:ID,Value:排序号") @RequestBody HashMap params) throws Exception { if(!params.isEmpty()){ baseService.updateSequence(params); } return new CommonResult<>(true, "排序完成"); } }