package com.linghu.controller;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.linghu.mapper.KeywordMapper;
|
import com.linghu.mapper.ReferenceMapper;
|
import com.linghu.model.common.ResponseResult;
|
import com.linghu.model.entity.Keyword;
|
import com.linghu.model.entity.Reference;
|
import com.linghu.model.entity.Type;
|
import com.linghu.model.validator.CreateGroup;
|
import com.linghu.model.validator.UpdateGroup;
|
import com.linghu.service.KeywordService;
|
import com.linghu.service.TypeService;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.validation.annotation.Validated;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.validation.Valid;
|
import java.util.ArrayList;
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Objects;
|
import java.util.stream.Collectors;
|
|
@RestController
|
@RequestMapping("/type")
|
@Api(value = "类型相关接口", tags = "设置-类型")
|
public class TypeController {
|
|
@Autowired
|
private TypeService typeService;
|
|
@PostMapping
|
@ApiOperation(value = "添加类型")
|
public ResponseResult<Type> add(@Validated( CreateGroup.class) @RequestBody Type type) {
|
return typeService.addType(type);
|
}
|
|
|
|
@PostMapping("/batch")
|
@ApiOperation(value = "批量添加类型")
|
public ResponseResult<Void> batchAdd(@Validated(CreateGroup.class) @Valid @RequestBody List<Type> types) {
|
boolean success = typeService.saveBatch(types);
|
if (success) {
|
return ResponseResult.success();
|
}
|
return ResponseResult.error("批量添加类型失败");
|
}
|
|
@DeleteMapping("/{typeId}")
|
@ApiOperation(value = "删除类型")
|
public ResponseResult<Void> delete(@PathVariable Integer typeId) {
|
typeService.removeById(typeId);
|
return ResponseResult.success();
|
}
|
|
@PutMapping
|
@ApiOperation(value = "更新类型")
|
public ResponseResult<Void> update(@Validated(UpdateGroup.class) @RequestBody Type type) {
|
typeService.updateById(type);
|
return ResponseResult.success();
|
}
|
|
@PutMapping("/batch")
|
@ApiOperation(value = "批量更新类型")
|
public ResponseResult<Void> batchUpdate(@Validated(UpdateGroup.class) @RequestBody List<Type> types) {
|
boolean success = typeService.updateBatchById(types);
|
if (success) {
|
return ResponseResult.success();
|
}
|
return ResponseResult.error("批量更新类型失败");
|
}
|
|
@GetMapping("/{typeId}")
|
@ApiOperation(value = "根据ID查询类型")
|
public ResponseResult<Type> getById(@PathVariable Integer typeId) {
|
Type type = typeService.getById(typeId);
|
if (type != null ) {
|
return ResponseResult.success(type);
|
}
|
return ResponseResult.error("类型不存在");
|
}
|
|
@DeleteMapping("/batch")
|
@ApiOperation(value = "批量删除类型")
|
public ResponseResult<Void> batchDelete(@RequestBody List<Integer> typeIds) {
|
return typeService.batchDeleteTypes(typeIds);
|
}
|
|
|
|
|
@GetMapping("/list")
|
@ApiOperation(value = "查询类型列表")
|
public ResponseResult<List<Type>> list(
|
@RequestParam(required = false) Integer keywordId,
|
@RequestParam(required = false) Integer questionId,
|
@RequestParam(required = false) Integer isNow
|
) {
|
return typeService.pageList(keywordId, questionId, isNow);
|
}
|
|
|
}
|