|
@@ -1,2 +1,137 @@
|
|
|
-package com.free.controller;public class HistoryController {
|
|
|
+package com.free.controller;
|
|
|
+
|
|
|
+ import java.util.HashMap;
|
|
|
+ import java.util.List;
|
|
|
+ import java.util.Map;
|
|
|
+
|
|
|
+ import javax.validation.Valid;
|
|
|
+
|
|
|
+ import com.free.entity.system.History;
|
|
|
+ import com.free.service.HistoryService;
|
|
|
+ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+ 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.RequestBody;
|
|
|
+ import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+ import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+ import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+ 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.fasterxml.jackson.core.JsonProcessingException;
|
|
|
+ import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+ import com.fasterxml.jackson.databind.type.CollectionType;
|
|
|
+ import com.free.annotation.PassToken;
|
|
|
+ import com.free.config.CustomizationException;
|
|
|
+ import com.free.config.ExceptionEnum;
|
|
|
+ import com.free.config.ResponseFormat;
|
|
|
+ import com.free.utils.Utils;
|
|
|
+
|
|
|
+ import io.swagger.annotations.Api;
|
|
|
+ import io.swagger.annotations.ApiOperation;
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("/history")
|
|
|
+@Api(tags = "历史记录")
|
|
|
+public class HistoryController {
|
|
|
+ @Autowired
|
|
|
+ private HistoryService service;
|
|
|
+
|
|
|
+ @PassToken
|
|
|
+ /** 创建数据 */
|
|
|
+ @ApiOperation("创建数据")
|
|
|
+ @PostMapping("")
|
|
|
+ public Object save(@RequestBody @Valid History data) {
|
|
|
+ this.service.save(data);
|
|
|
+ QueryWrapper qw = new QueryWrapper<>();
|
|
|
+ qw.eq("id", data.getId());
|
|
|
+ Map returnData = this.service.getMap(qw);
|
|
|
+ return ResponseFormat.success(returnData);
|
|
|
+ // return ResponseFormat.success();
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 修改数据 */
|
|
|
+ @PassToken
|
|
|
+ @ApiOperation("修改数据")
|
|
|
+ @PostMapping("/{id}")
|
|
|
+ public Object update(@PathVariable long id, @RequestBody History data) {
|
|
|
+ QueryWrapper qw = new QueryWrapper<>();
|
|
|
+ qw.eq("id", id);
|
|
|
+ Long num = this.service.count(qw);
|
|
|
+ if (num <= 0) {
|
|
|
+ throw new CustomizationException(ExceptionEnum.NOT_FOUND);
|
|
|
+ }
|
|
|
+ data.setId(id);
|
|
|
+ this.service.updateById(data);
|
|
|
+ Object newData = this.service.getById(id);
|
|
|
+ return ResponseFormat.success(newData);
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 列表查询 */
|
|
|
+ @PassToken
|
|
|
+ @ApiOperation("查询数据列表")
|
|
|
+ @SuppressWarnings({ "unchecked" })
|
|
|
+ @GetMapping()
|
|
|
+ public Object list(@RequestParam Map<String, Object> allParams) {
|
|
|
+ Long skip = null, limit = null;
|
|
|
+ Map map = new HashMap();
|
|
|
+ QueryWrapper qw = new QueryWrapper<>();
|
|
|
+ qw.select("id","title","platform","is_use");
|
|
|
+ /** 参数处理处理 */
|
|
|
+ for (String key : allParams.keySet()) {
|
|
|
+ Object value = allParams.get(key);
|
|
|
+ if (key.equals("skip")) {
|
|
|
+ skip = Long.valueOf(String.valueOf(value));
|
|
|
+ } else if (key.equals("limit")) {
|
|
|
+ limit = Long.valueOf(String.valueOf(value));
|
|
|
+ } else {
|
|
|
+ if(key.equals("title")||key.equals("platform")){
|
|
|
+ qw.like(key,value);
|
|
|
+ } else {
|
|
|
+ // 其他为查询条件
|
|
|
+ qw.eq(key, value);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /** 分页处理 */
|
|
|
+ if (null != skip && null != limit) {
|
|
|
+ IPage page = new Page<>(skip, limit);
|
|
|
+ IPage pageResult = service.page(page, qw);
|
|
|
+ List data = pageResult.getRecords();
|
|
|
+ long total = pageResult.getTotal();
|
|
|
+ map.put("data", data);
|
|
|
+ map.put("total", total);
|
|
|
+ } else {
|
|
|
+ List list = service.list(qw);
|
|
|
+ map.put("data", list);
|
|
|
+ }
|
|
|
+ return ResponseFormat.success(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 根据id查询 */
|
|
|
+ @PassToken
|
|
|
+ @ApiOperation("查询数据")
|
|
|
+ @GetMapping("/{id}")
|
|
|
+ public Object fetch(@PathVariable long id) {
|
|
|
+ Object newData = service.getById(id);
|
|
|
+ return ResponseFormat.success(newData);
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 根据id删除数据 */
|
|
|
+ @PassToken
|
|
|
+ @ApiOperation("删除数据")
|
|
|
+ @DeleteMapping("/{id}")
|
|
|
+ public Object delete(@PathVariable long id) {
|
|
|
+ QueryWrapper qw = new QueryWrapper<>();
|
|
|
+ qw.eq("id", id);
|
|
|
+ Long num = service.count(qw);
|
|
|
+ if (num <= 0) {
|
|
|
+ throw new CustomizationException(ExceptionEnum.NOT_FOUND);
|
|
|
+ }
|
|
|
+ service.removeById(id);
|
|
|
+ return ResponseFormat.success();
|
|
|
+ }
|
|
|
}
|