package org.dromara.resource.dubbo;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSONObject;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.dromara.common.core.enums.BusRole;
import org.dromara.common.core.enums.SignType;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.resource.api.RemoteDhqService;
import org.dromara.resource.api.domain.RemoteDhq;
import org.dromara.resource.domain.DhqSign;
import org.dromara.resource.service.impl.DhqSignServiceImpl;
import org.dromara.system.api.RemoteConfigService;
import org.dromara.system.api.domain.RemoteSysUnitDomainVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @author sunzexing
 * @version 1.0
 * @title RemoteDhqServiceImpl
 * @description
 * @create 2024-05-20 9:55
 */


@DubboService
@Service
public class RemoteDhqServiceImpl implements RemoteDhqService {


    @Resource
    public DhqSignServiceImpl  dhqSignService;


    @DubboReference
    private RemoteConfigService remoteConfigService;
    @Override
    public String becomeSign(RemoteDhq sign, String domain, SignType signType) throws Exception {
//        RemoteSysUnitDomainVo site = remoteConfigService.queryByDomainName(domain);
//
//        if(site == null || StringUtils.isEmpty(site.getSignConfig())){
//            throw new Exception("未找到该域名的大鸿签签约配置信息");
//        }
//
//        JSONObject signConfig = JSONObject.parseObject(site.getSignConfig());
//
//        sign.setApplicationId(signConfig.getString("appId"));
//        sign.setBusinessId(signConfig.getString("businessId"));
//
//        if(StringUtils.isEmpty(sign.getContractModelNum())){
//            if(1 == signType.getId()){
//                sign.setContractModelNum(signConfig.getString("user_worker_pro"));
//            }else if(2 == signType.getId()){
//                sign.setContractModelNum(signConfig.getString("user_worker_conf"));
//            }
//        }
        DhqSign dhqSign = BeanUtil.copyProperties(sign,DhqSign.class);

        return this.dhqSignService.becomeSign(dhqSign);
    }
}
