wjli
2023-05-11 a067fdbf6b1374a1402096c722257575916eab99
xboot-modules/xboot-your/src/main/java/cn/exrick/xboot/your/controller/DrivingRecordController.java
@@ -5,7 +5,9 @@
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;
@@ -16,6 +18,7 @@
import org.springframework.web.bind.annotation.*;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List;
/**
@@ -30,6 +33,78 @@
    @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.setCarId(carId);
        }
        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获取")
@@ -49,9 +124,11 @@
    @RequestMapping(value = "/getByPage", method = RequestMethod.GET)
    @ApiOperation(value = "分页获取")
    public Result<IPage<DrivingRecord>> getByPage(PageVo page) {
        IPage<DrivingRecord> data = iDrivingRecordService.page(PageUtil.initMpPage(page));
    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);
    }