package com.tofly.gpsboot.custom.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.common.core.util.StringUtil;
import com.tofly.common.log.annotation.ToFlyAppLog;
import com.tofly.common.oauth.exception.ToflyDeniedException;
import com.tofly.pojo.car.cusom.CarMochaitomList;
import com.tofly.pojo.car.cusom.CarMochaitomSearch;
import com.tofly.gpsboot.custom.mapper.CustomCarMochaitomMapper;
import com.tofly.gpsboot.custom.service.CustomCarMochaitomService;
import com.tofly.gpsboot.service.car.CarMochaitomService;
import com.tofly.pojo.car.CarMochaitom;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;


//@RestController
//@AllArgsConstructor
//@RequestMapping("/carmochaitom")
//@Api(tags = "运维部单车台账记录表接口")
public class CustomCarMochaitomController {
//
//    private final CustomCarMochaitomService customCarMochaitomService;
//    private final CarMochaitomService carMochaitomService;
//    private final CustomCarMochaitomMapper customCarMochaitomMapper;
//
//    @ApiOperation(value = "根据车牌号模糊分页查询")
//    @GetMapping("/numberpage")
//    public ResultRespone pageByCarNumber(Page page, String number) {
//        return ResultRespone.success(customCarMochaitomService.pageByCarNumber(page, number));
//    }
//
//    /**
//     * 新增运维部单车台账记录表
//     *
//     * @param carMochaitom 运维部单车台账记录表
//     * @return ResultRespone
//     */
//    @ToFlyAppLog(title = "新增运维部单车台账记录表")
//    @ApiOperation(value = "新增运维部单车台账记录表")
//    @PostMapping
//    public ResultRespone save(@RequestBody CarMochaitom carMochaitom) {
//       /* List<CarMochaitom> list = carMochaitomService.list(Wrappers.<CarMochaitom>lambdaQuery().eq(CarMochaitom::getUseTime, carMochaitom.getUseTime()).eq(CarMochaitom::getCarId, carMochaitom.getCarId()));
//        list.forEach(k -> {
//            if (carMochaitom.getUseTime().equals(k.getUseTime())) {
//                throw new ToflyDeniedException("该车辆在" + carMochaitom.getUseTime() + "月份已上报台账,仅可进行修改");
//            }
//        });*/
//       int row = customCarMochaitomMapper.hasTime(carMochaitom.getUseTime(),carMochaitom.getCarId());
//       if(row > 0){
//           throw new ToflyDeniedException("该车辆在" + carMochaitom.getUseTime() + "月份已上报台账,仅可对当月其他信息进行修改");
//       }
//        return ResultRespone.success(carMochaitomService.save(carMochaitom));
//    }
//
//    /**
//     * 修改运维部单车台账记录表
//     * @param carMochaitom 运维部单车台账记录表
//     * @return ResultRespone
//     */
//    @ToFlyAppLog(title="修改运维部单车台账记录表" )
//    @ApiOperation(value = "修改运维部单车台账记录表")
//    @PutMapping
//    public ResultRespone updateById(@RequestBody CarMochaitom carMochaitom) {
//        if(StringUtil.isNotEmpty(carMochaitom.getUseTime())){
//            throw new ToflyDeniedException("该车辆在" + carMochaitom.getUseTime() + "月份已上报台账,不能修改上报月份,仅可对当月其他信息进行修改");
//        }
//        return ResultRespone.success(carMochaitomService.updateById(carMochaitom));
//    }
//
//    @ToFlyAppLog(title = "管网运维部车辆费用统计")
//    @ApiOperation(value = "管网运维部车辆费用统计")
//    @GetMapping("/cost")
//    public ResultRespone pageCount(CarMochaitomSearch carMochaitomSearch) throws ParseException {
//        if(!StringUtil.isNotEmpty(carMochaitomSearch.getBeginTime())){
//            throw new ToflyDeniedException("统计的起始时间不能为空");
//        }
//        if(!StringUtil.isNotEmpty(carMochaitomSearch.getEndTime())){
//            throw new ToflyDeniedException("统计的截止时间不能为空");
//        }
//        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM");
//        Date date1 = null;
//        Date date2 = null;
//        try {
//            date1 = simpleDateFormat.parse(carMochaitomSearch.getBeginTime());
//            date2 = simpleDateFormat.parse(carMochaitomSearch.getEndTime());
//        } catch (ParseException e) {
//            e.printStackTrace();
//        }
//        if (date1 != null && date2 != null) {
//            if (date1.after(date2)) {
//                throw new ToflyDeniedException("查询的起始时间不能在结束时间之后");
//            }
//        }
//        return ResultRespone.success(customCarMochaitomService.pageCount(carMochaitomSearch));
//    }
//
//    @ToFlyAppLog(title = "管网运维部单车台账")
//    @ApiOperation(value = "管网运维部单车台账")
//    @GetMapping("/list")
//    public ResultRespone getList(CarMochaitomList carMochaitomList) throws ParseException {
//        if(carMochaitomList.getCarId() == null){
//            throw new ToflyDeniedException("查询的车辆ID不能为空");
//        }
//        return ResultRespone.success(customCarMochaitomService.getList(carMochaitomList));
//    }
}
