package com.zcloud.primeport.command;

import com.alibaba.cola.exception.BizException;
import com.zcloud.primeport.domain.gateway.VehicleApplyGateway;
import com.zcloud.primeport.domain.gateway.VehicleBlackGateway;
import com.zcloud.primeport.domain.gateway.VehicleViolationsGateway;
import com.zcloud.primeport.domain.model.VehicleBlackE;
import com.zcloud.primeport.plan.mjDevice.CarDockUtil;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;


/**
 * web-app
 *
 * @Author makejava
 * @Date 2026-03-05 11:33:27
 */
@Component
@AllArgsConstructor
public class VehicleBlackRemoveExe {
    private final VehicleBlackGateway vehicleBlackGateway;
    private final VehicleApplyGateway vehicleApplyGateway;
    private final VehicleViolationsGateway vehicleViolationsGateway;
    private final CarDockUtil carDockUtil;

    @Transactional(rollbackFor = Exception.class)
    public boolean execute(Long id) {
        VehicleBlackE infoById = vehicleBlackGateway.getInfoById(id);
        boolean res = vehicleBlackGateway.deletedVehicleBlackById(id);
        // 把这个车牌的违规记录变成已处理.
        vehicleViolationsGateway.updateVehicleViolationsStatusByLicenceNo(infoById.getLicenceNo(), 1);
        vehicleApplyGateway.updateEvehicleBlockedByLicenceNo(infoById.getLicenceNo(),2);
        carDockUtil.executeBlackRemove(infoById);
        if (!res) {
            throw new BizException("删除失败");
        }
        return true;
    }

    @Transactional(rollbackFor = Exception.class)
    public boolean execute(Long[] ids) {
        boolean res = vehicleBlackGateway.deletedVehicleBlackByIds(ids);
        if (!res) {
            throw new BizException("删除失败");
        }
        return true;
    }
}

