zhangzeli
2021-10-28 451bcfe3e00e68a3ad32415d06bb4411d11bddfe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package cn.exrick.xboot.your.controller;
 
import cn.exrick.xboot.core.common.utils.PageUtil;
import cn.exrick.xboot.core.common.utils.ResultUtil;
import cn.exrick.xboot.core.common.vo.PageVo;
import cn.exrick.xboot.core.common.vo.Result;
import cn.exrick.xboot.your.entity.Violation;
import cn.exrick.xboot.your.service.IViolationService;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.List;
 
/**
 * @author zhangzeli
 */
@Slf4j
@RestController
@Api(tags = "违章记录管理接口")
@RequestMapping("/xboot/violation")
@Transactional
public class ViolationController {
 
    @Autowired
    private IViolationService iViolationService;
 
    @RequestMapping(value = "/get/{id}", method = RequestMethod.GET)
    @ApiOperation(value = "通过id获取")
    public Result<Violation> get(@PathVariable String id) {
 
        Violation violation = iViolationService.getById(id);
        return new ResultUtil<Violation>().setData(violation);
    }
 
    @RequestMapping(value = "/getAll", method = RequestMethod.GET)
    @ApiOperation(value = "获取全部数据")
    public Result<List<Violation>> getAll() {
 
        List<Violation> list = iViolationService.list();
        return new ResultUtil<List<Violation>>().setData(list);
    }
 
    @RequestMapping(value = "/getByPage", method = RequestMethod.GET)
    @ApiOperation(value = "分页获取")
    public Result<IPage<Violation>> getByPage(PageVo page,String carNo) {
 
        QueryWrapper<Violation> wrapper = new QueryWrapper<>();
        if(!StrUtil.isEmpty(carNo)){
            wrapper.like("b.car_no","%"+carNo+"%");
        }
        IPage<Violation> data = iViolationService.page2(PageUtil.initMpPage(page),wrapper);
        return new ResultUtil<IPage<Violation>>().setData(data);
    }
 
    @RequestMapping(value = "/insertOrUpdate", method = RequestMethod.POST)
    @ApiOperation(value = "编辑或更新数据")
    public Result<Violation> saveOrUpdate(Violation violation) {
 
        if (iViolationService.saveOrUpdate(violation)) {
            return new ResultUtil<Violation>().setData(violation);
        }
        return new ResultUtil<Violation>().setErrorMsg("操作失败");
    }
 
    @RequestMapping(value = "/delByIds", method = RequestMethod.POST)
    @ApiOperation(value = "批量通过id删除")
    public Result<Object> delAllByIds(@RequestParam String[] ids) {
 
        for (String id : ids) {
            iViolationService.removeById(id);
        }
        return ResultUtil.success("批量通过id删除数据成功");
    }
}