New file |
| | |
| | | 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.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获取") |
| | | 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删除数据成功"); |
| | | } |
| | | } |