wang-hao-jie
2022-03-17 6dfd2599d2e52507e018fd4c6b35d38873e48cfb
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
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.DrivingRecord;
import cn.exrick.xboot.your.entity.OrderTask;
import cn.exrick.xboot.your.service.IDrivingRecordService;
import cn.hutool.core.date.DateUtil;
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.Date;
import java.util.List;
 
/**
 * @author zhangzeli
 */
@Slf4j
@RestController
@Api(tags = "行车记录管理接口")
@RequestMapping("/xboot/drivingRecord")
@Transactional
public class DrivingRecordController {
 
    @Autowired
    private IDrivingRecordService iDrivingRecordService;
 
    @RequestMapping(value = "/orderConfirm", method = RequestMethod.POST)
    @ApiOperation(value = "订单确认")
    public Result<DrivingRecord> orderConfirm(DrivingRecord record) {
        if(StrUtil.isEmpty(record.getCarId())){
            return ResultUtil.error("车辆id不能为空");
        }
 
        String format = DateUtil.format(new Date(), "yyyy-MM-dd");
        QueryWrapper<DrivingRecord> wrapper = new QueryWrapper<>();
        wrapper.eq("driving_date",format);
        wrapper.eq("car_id",record.getCarId());
        int count = iDrivingRecordService.count(wrapper);
        if(count>0){
            return ResultUtil.error("今日已核对,请勿重复提交");
        }
 
        record.setDrivingDate(DateUtil.parse(format));
 
        int flag=0;
        if(record.getSanZheng()!=0){
            flag++;
        }else if(record.getSanLiang()!=0){
            flag++;
        }else if(record.getAnQuan()!=0){
            flag++;
        }else if(record.getHouShiJing()!=0){
            flag++;
        }else if(record.getLaBa()!=0){
            flag++;
        }else if(record.getLunTai()!=0){
            flag++;
        }else if(record.getQiTa()!=0){
            flag++;
        }else if(record.getSiDeng()!=0){
            flag++;
        }else if(record.getYiBiao()!=0){
            flag++;
        }else if(record.getYuShuaQi()!=0){
            flag++;
        }
        if(flag>0){
            record.setYinHuan(1);
        }
        iDrivingRecordService.saveOrUpdate(record);
        return ResultUtil.success("操作成功");
    }
 
    @RequestMapping(value = "/updateMileage", method = RequestMethod.POST)
    @ApiOperation(value = "添加行车记录")
    public Result<DrivingRecord> updateMileage(String carId,int mileage,String userId,String inDate) {
        if(StrUtil.isEmpty(userId)){
            return ResultUtil.error("参数不完整");
        }
        if(StrUtil.isEmpty(carId)){
            return ResultUtil.error("参数不完整");
        }
        String format = DateUtil.format(new Date(), "yyyy-MM-dd");
        QueryWrapper<DrivingRecord> wrapper = new QueryWrapper<>();
        wrapper.eq("driving_date",format);
        wrapper.eq("car_id",carId);
        DrivingRecord drivingRecord = iDrivingRecordService.getOne(wrapper);
        if(drivingRecord==null){
            drivingRecord = new DrivingRecord();
        }
        drivingRecord.setMileage(mileage);
        drivingRecord.setInTime(DateUtil.parseDate(inDate));
        drivingRecord.setUserId(userId);
        iDrivingRecordService.saveOrUpdate(drivingRecord);
        return new ResultUtil<DrivingRecord>().setSuccessMsg("添加成功");
    }
 
    @RequestMapping(value = "/get/{id}", method = RequestMethod.GET)
    @ApiOperation(value = "通过id获取")
    public Result<DrivingRecord> get(@PathVariable String id) {
 
        DrivingRecord drivingRecord = iDrivingRecordService.getById(id);
        return new ResultUtil<DrivingRecord>().setData(drivingRecord);
    }
 
    @RequestMapping(value = "/getAll", method = RequestMethod.GET)
    @ApiOperation(value = "获取全部数据")
    public Result<List<DrivingRecord>> getAll() {
 
        List<DrivingRecord> list = iDrivingRecordService.list();
        return new ResultUtil<List<DrivingRecord>>().setData(list);
    }
 
    @RequestMapping(value = "/getByPage", method = RequestMethod.GET)
    @ApiOperation(value = "分页获取")
    public Result<IPage<DrivingRecord>> getByPage(PageVo page,String carNo) {
        QueryWrapper<DrivingRecord> wrapper = new QueryWrapper<>();
        if(!StrUtil.isEmpty(carNo))
            wrapper.like("b.car_no","%"+carNo+"%");
        IPage<DrivingRecord> data = iDrivingRecordService.page2(PageUtil.initMpPage(page),wrapper);
        return new ResultUtil<IPage<DrivingRecord>>().setData(data);
    }
 
    @RequestMapping(value = "/insertOrUpdate", method = RequestMethod.POST)
    @ApiOperation(value = "编辑或更新数据")
    public Result<DrivingRecord> saveOrUpdate(DrivingRecord drivingRecord) {
 
        if (iDrivingRecordService.saveOrUpdate(drivingRecord)) {
            return new ResultUtil<DrivingRecord>().setData(drivingRecord);
        }
        return new ResultUtil<DrivingRecord>().setErrorMsg("操作失败");
    }
 
    @RequestMapping(value = "/delByIds", method = RequestMethod.POST)
    @ApiOperation(value = "批量通过id删除")
    public Result<Object> delAllByIds(@RequestParam String[] ids) {
 
        for (String id : ids) {
            iDrivingRecordService.removeById(id);
        }
        return ResultUtil.success("批量通过id删除数据成功");
    }
}