/*
 * Author: wangjian
 * 生成controller
 */
package com.tofly.gpsboot.controller.car;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tofly.common.core.entity.ResultRespone;
import com.tofly.common.core.util.DateUtil;
import com.tofly.common.log.annotation.ToFlyAppLog;
import com.tofly.common.oauth.util.SecurityUtils;
import com.tofly.gpsboot.service.car.CarService;
import com.tofly.gpsboot.service.car.CarUserService;
import com.tofly.gpsboot.util.DateTimeUtil;
import com.tofly.pojo.car.CarUser;
import com.tofly.pojo.plan.Car;
import lombok.AllArgsConstructor;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.web.bind.annotation.ModelAttribute;

import java.util.Arrays;
import java.util.Date;

/**
 * 车辆人员绑定信息
 *
 * @author admin
 * @date Thu May 19 00:00:00 CST 2022
 */
//@RestController
//@AllArgsConstructor
//@RequestMapping("/caruser")
//@Api(tags="车辆人员绑定信息接口")
public class CarUserController {

//    private final CarUserService carUserService;
//    private final CarService carService;
//    /**
//    * 分页查询
//    * @param page 分页对象
//    * @param carUser 车辆人员绑定信息
//    * @return
//    */
//    @GetMapping("/page" )
//    @ApiOperation(value = "分页查询")
//    public ResultRespone getCarUserPage(Page page, @ModelAttribute CarUser carUser) {
//      return ResultRespone.success(carUserService.page(page, Wrappers.query(carUser)));
//    }
//
//
//    /**
//     * 通过id查询车辆人员绑定信息
//     * @param id id
//     * @return ResultRespone
//     */
//    @GetMapping("/{id}" )
//    @ApiOperation(value = "通过ID查询")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "BigDecimal")
//    })
//    public ResultRespone getById(@PathVariable("id" ) Long id) {
//      return ResultRespone.success(carUserService.getById(id));
//    }
//
//    /**
//     * 新增车辆人员绑定信息
//     * @param carUser 车辆人员绑定信息
//     * @return ResultRespone
//     */
//    @ToFlyAppLog(title="app新增车辆人员绑定信息" )
//    @ApiOperation(value = "app新增车辆人员绑定信息")
//    @PostMapping
//    public ResultRespone save(@RequestBody CarUser carUser) {
//        //查询车辆在该时间段是否绑定了人员
//        CarUser carUerBind = carUserService.getOne(Wrappers.<CarUser>lambdaQuery()
//                .eq(CarUser::getCarId, carUser.getCarId())
//                .isNull(CarUser::getEndDate)
//                .lt(CarUser::getBeginDate, carUser.getBeginDate())
//        );
//
//        if(carUerBind!=null){
//            return  ResultRespone.failed("该车辆已经被其它人绑定");
//        }
//        //绑定时间从当前时间开始计算  直到签到下班
//        carUser.setBeginDate(new Date());
//
//        return ResultRespone.success(carUserService.save(carUser));
//    }
//
//    /**
//     * 修改车辆人员绑定信息
//     * @param carUser 车辆人员绑定信息
//     * @return ResultRespone
//     */
//    @ToFlyAppLog(title="修改车辆人员绑定信息" )
//    @ApiOperation(value = "修改车辆人员绑定信息")
//    @PutMapping
//    public ResultRespone updateById(@RequestBody CarUser carUser) {
//      return ResultRespone.success(carUserService.updateById(carUser));
//    }
//
//    /**
//     * 通过id删除车辆人员绑定信息
//     * @param id id
//     * @return ResultRespone
//     */
//    @ToFlyAppLog(title="通过id删除车辆人员绑定信息" )
//    @ApiOperation(value = "通过ID删除车辆人员绑定信息")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "id", value = "ID", required = true, dataType = "BigDecimal")
//    })
//    @DeleteMapping("/{id}" )
//    public ResultRespone removeById(@PathVariable Long id) {
//      return ResultRespone.success(carUserService.removeById(id));
//    }
//
//    /**
//     * 通过id批量删除车辆人员绑定信息
//     * @param ids id
//     * @return ResultRespone
//     */
//    @ToFlyAppLog(title="通过id批量删除车辆人员绑定信息" )
//    @ApiOperation(value = "通过ID批量删除车辆人员绑定信息")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "ids", value = "批量删除，多个id以逗号隔开", required = true, dataType = "String")
//    })
//    @DeleteMapping("/deleteByIds" )
//    public ResultRespone removeById(String ids) {
//        return ResultRespone.success(carUserService.removeByIds(Arrays.asList(ids.split(","))));
//    }
//
// //   @ToFlyAppLog(title="通过车辆id删除绑定信息" )
//    @ApiOperation(value = "通过车辆id删除绑定信息")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "carId", value = "carId", required = true, dataType = "Long")
//    })
//    @DeleteMapping("/deleteByCarId/{carId}" )
//    public ResultRespone deleteByCarId(@PathVariable Long carId) {
//        return ResultRespone.success( carUserService.remove(Wrappers.<CarUser>lambdaQuery().eq(CarUser::getCarId,carId)));
//    }
//
//     @GetMapping("/getTodayUserCar")
//     @ApiImplicitParams({
//             @ApiImplicitParam(name = "userId", value = "用户id", required = false, dataType = "Long")
//     })
//     @ApiOperation(value = "获取当天用户绑定的车辆")
//    public ResultRespone getTodayUserCar(@Param("userId") Long userId) {
//        if(userId==null||userId==0l){
//            userId = SecurityUtils.getUserId();
//        }
//         CarUser one = carUserService.getOne(Wrappers.<CarUser>lambdaQuery()
//                 .isNull(CarUser::getEndDate)
//                 .eq(CarUser::getUserId, userId)
//                 .isNull(CarUser::getEndDate)
//                .gt(CarUser::getBeginDate,DateTimeUtil.convertLDTToDate(DateTimeUtil.getTodayBeginTime())));
//           if(one!=null){
//               Car byId = carService.getById(one.getCarId());
//               return ResultRespone.success(byId);
//           }else{
//               return  ResultRespone.success(null);
//         }
//
//     }
}
