package com.bohuikeji.delivery.backstage.controller.admin;


import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.bohuikeji.delivery.backstage.entity.TCourier;
import com.bohuikeji.delivery.backstage.entity.TNews;
import com.bohuikeji.delivery.backstage.entity.TVehicleInformation;
import com.bohuikeji.delivery.backstage.service.ITCourierService;
import com.bohuikeji.delivery.backstage.service.ITNewsService;
import com.bohuikeji.delivery.backstage.service.ITVehicleInformationService;
import com.bohuikeji.frame.module.admin.annotation.InitLog;
import com.bohuikeji.frame.module.admin.entity.back.APIEntity;
import com.bohuikeji.frame.module.admin.utils.StringUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 车辆信息
 * @author 10552
 */
@RestController
@RequestMapping("/vehicle")
public class VehicleInfoController {
    @Autowired
    RabbitTemplate rabbitTemplate;
    @Autowired
    ITVehicleInformationService vehicleService;
    @Autowired
    ITNewsService newsService;
    @Autowired
    ITCourierService courierService;

    /**
     * 派松员车辆审核通过
     * @return
     */
    @InitLog(value = "派送员车辆审核通过",action = "审核")
    @GetMapping("/courier/check/success")
    @ApiOperation("派松员车辆审核通过")
    public APIEntity checkSuccess(Integer courierId,Integer vehicleId){
        TVehicleInformation car=vehicleService.getById(vehicleId);
        car.setAuthStatus("认证成功");
        if(car.updateById()){
            courierService.update(new UpdateWrapper<TCourier>().eq("courier_id",courierId).set("courier_auth_vehicle","已认证"));
            newsService.pushCourierMsg1(courierId,"车辆认证成功提醒","您的车辆：{0}认证成功。", StringUtils.isBlank(car.getVehicleNumber())?car.getVehicleName():car.getVehicleNumber());
            return APIEntity.success();
        }
        return APIEntity.fail("系统繁忙，请稍后再试~");

    }

    /**
     * 派松员车辆审核不通过
     * @param courierId
     * @param vehicleId
     * @param desc
     * @return
     */
    @InitLog(value = "派送员车辆审核不通过",action = "审核")
    @GetMapping("/courier/check/fail")
    @ApiOperation("派松员车辆审核不通过")
    public APIEntity checkFail(Integer courierId,Integer vehicleId,String desc){
        TVehicleInformation car=vehicleService.getById(vehicleId);
        car.setAuthStatus("认证失败");
        if(car.updateById()){
            newsService.pushCourierMsg1(courierId,"车辆认证失败提醒","您的车辆：{0}认证失败。失败原因：{1}",StringUtils.isBlank(car.getVehicleNumber())?car.getVehicleName():car.getVehicleNumber(),desc);
            return APIEntity.success();
        }
        return APIEntity.fail("系统繁忙，请稍后再试~");

    }

}
