package com.bohuikeji.delivery.backstage.controller.api.courier;


import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bohuikeji.delivery.backstage.entity.TDrivingLicence;
import com.bohuikeji.delivery.backstage.service.TDrivingLicenceService;

import java.util.ArrayList;
import java.util.List;
import com.bohuikeji.frame.module.admin.base.ApiController;
import com.bohuikeji.frame.module.admin.entity.back.APIEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;


/**
 * 订单异常接口
 */
@Api(tags = {"驾驶证接口"})
@RestController
@RequestMapping("/api/driving")
public class TDrivingLicenceApi extends ApiController {
    @Autowired
    private ApplicationContext applicationContext;
    @Autowired
    TDrivingLicenceService tDrivingLicenceService;
    @PostMapping("/save")
    @ApiOperation("驾驶证录入")
    public APIEntity save(@RequestBody TDrivingLicence tDrivingLicence){
        tDrivingLicence.setCreateDate(LocalDateTime.now());
        /* 查询当前派送员是否录入驾照 */
        Integer courierId = tDrivingLicence.getCourierId();
        TDrivingLicence res = tDrivingLicenceService.getOne(new QueryWrapper<TDrivingLicence>().eq("courier_id",courierId));
        if(res != null){
            return APIEntity.fail("您已经录入过驾驶证,请不要重复录入");
        }
        tDrivingLicenceService.save(tDrivingLicence);
        return APIEntity.success("操作成功");
    }
    @ApiOperation("根据派送员查询驾驶证")
    @GetMapping("/getDriving")
    @ApiImplicitParams({
            @ApiImplicitParam(name="courierId",value="派送员登陆id",dataType="Integer", paramType = "query")})
    public APIEntity getVehicle(Integer courierId){
        TDrivingLicence tDrivingLicence = tDrivingLicenceService.getOne(new QueryWrapper<TDrivingLicence>().eq("courier_id",courierId));
        List<TDrivingLicence> list= new ArrayList<>();
        list.add(tDrivingLicence);
        return APIEntity.success(list);
    }
    @PostMapping("/update")
    @ApiOperation("修改驾驶证")
    public APIEntity update(@RequestBody TDrivingLicence tDrivingLicence){
        tDrivingLicenceService.updateById(tDrivingLicence);
        return APIEntity.success("操作成功");
    }
//    @ApiOperation("车辆验证")
//    @GetMapping("/getLicence")
//    public APIEntity getLicence(String licenceType,String vehicleName){
//
//        Map<String,License> resultMap = applicationContext.getBeansOfType(License.class);
//        for (String key : resultMap.keySet()) {
//            License license = resultMap.get(key);
//            if(license.isLicenseType(licenceType)){
//                if (license.isVehicle(vehicleName)){
//                    return APIEntity.success("符合所驾驶车型");
//                }
//                break;
//            }
//        }
//        return APIEntity.fail("与所驾驶车型不符合");
//    }

}
