package com.zcloud.primeport.command;

import com.alibaba.cola.exception.BizException;
import com.jjb.saas.message.client.message.facede.MessageFacade;
import com.jjb.saas.message.client.message.request.MessageSendCmd;
import com.jjb.saas.message.client.message.request.MessageTargetCmd;
import com.zcloud.gbscommon.utils.UuidUtil;
import com.zcloud.primeport.domain.gateway.VehicleAuditGateway;
import com.zcloud.primeport.domain.model.VehicleAuditE;
import com.zcloud.primeport.dto.VehicleAuditAddCmd;
import lombok.AllArgsConstructor;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.Map;


/**
 * web-app
 *
 * @Author makejava
 * @Date 2026-03-05 11:33:24
 */
@Component
@AllArgsConstructor
public class VehicleAuditAddExe {
    private final VehicleAuditGateway vehicleAuditGateway;
    @DubboReference
    private MessageFacade messageFacade;
    @Transactional(rollbackFor = Exception.class)
    public boolean execute(VehicleAuditAddCmd cmd) {
        VehicleAuditE examTypeE = new VehicleAuditE();
        BeanUtils.copyProperties(cmd, examTypeE);
        boolean res = false;
        try {
            res = vehicleAuditGateway.add(examTypeE);
            //口门车辆新增审批
            MessageSendCmd messageSendCmd = new MessageSendCmd();
            messageSendCmd.setBusinessId(UuidUtil.get32UUID());
            MessageTargetCmd messageTargetCmd = new MessageTargetCmd();
            messageTargetCmd.setUserId(cmd.getAuditUserId());
            messageSendCmd.setTargetCmd(messageTargetCmd);
            messageSendCmd.setNeedTokenEnum(false);
            Map<String, Object> sendParams = new HashMap<String, Object>();
            messageSendCmd.setSourceCode("MS000119");
            sendParams.put("HazardDeferralApplicationNumber", 1);
            sendParams.put("ReformHazardNumber", 1);
            messageSendCmd.setParams(sendParams);
            messageFacade.send(messageSendCmd);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        if (!res) {
            throw new BizException("保存失败");
        }
        return true;
    }
}

