ContractDetailsRest.java 2.16 KB
package com.thinkgem.jeesite.modules.eci.method;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.utils.JsonUtil;
import com.thinkgem.jeesite.modules.eci.dao.ElecLicenseInfoDao;
import com.thinkgem.jeesite.modules.eci.entity.ContractDetailsResponse;
import com.thinkgem.jeesite.modules.eci.entity.ElecLicenseInfo;
import com.thinkgem.jeesite.modules.eci.utils.EciHttpUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 请求合同详情方法
 */
@Component
public class ContractDetailsRest {

    private static final String DETAILS = "/contract/detail";

    private Logger logger = LoggerFactory.getLogger(ContractDetailsRest.class);

    @Autowired
    ElecLicenseInfoDao licenseInfoDao;

    @Transactional(rollbackFor = Exception.class)
    public void accessDetails() {

        List<ElecLicenseInfo> waitForDetails = licenseInfoDao.getDocumentIdIsNull();

        for (ElecLicenseInfo waitForDetail : waitForDetails) {
            Long contractId = waitForDetail.getContractId();
            String bizId = waitForDetail.getBizId();
            String url = Global.ECI_HOST + DETAILS + "?contractId=" + contractId;
            logger.info("请求合同详情接口url:" + url);
            try {
                String result = null;
                result = EciHttpUtil.doGet(url);
                logger.info("合同详情接口请求结果:" + result);
                ContractDetailsResponse response = JsonUtil.fromJson(result, ContractDetailsResponse.class);

                if (response != null && response.getCode() == 0) {
                    // TODO: 2022/2/15/0015 目前先取文档详情集合第一个
                    Long documentId = response.getContract().getDocuments().get(0).getId();
                    //文档ID入库
                    licenseInfoDao.updateDocumentId(bizId, documentId);
                }

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

}