CreateContractRest.java 4.14 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.BdcqzsTemplate;
import com.thinkgem.jeesite.modules.eci.entity.CreateContractRequest;
import com.thinkgem.jeesite.modules.eci.entity.CreateContractResponse;
import com.thinkgem.jeesite.modules.eci.entity.ElecLicenseInfo;
import com.thinkgem.jeesite.modules.eci.utils.EciHttpUtil;
import org.apache.commons.beanutils.BeanUtils;
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.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 请求创建合同方法
 */
@Component
public class CreateContractRest {

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

    private static final String CREATE_BY_CATEGORY = "/contract/createbycategory";

    @Autowired
    ElecLicenseInfoDao licenseInfoDao;


    /**
     * 批量创建
     *
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public void accessCreateContract() {

        String url = Global.ECI_HOST + CREATE_BY_CATEGORY;
        logger.info("http request url:" + url);

        // List<CreateContractRequest> requests = new ArrayList<>();

        List<ElecLicenseInfo> waitForCreateContracts = licenseInfoDao.getContractIdIsNull();
        for (ElecLicenseInfo waitForCreateContract : waitForCreateContracts) {
            String result = null;
            CreateContractRequest request = new CreateContractRequest();
            request.setSubject("不动产合同");
            request.setSn(waitForCreateContract.getYwh());
            String htlx = waitForCreateContract.getHtlx();
            if ("1".equals(htlx) || "2".equals(htlx)) {
                //不动产登记证明和不动产权证书类型使用证照专用章
                request.setCategoryId(Global.ECI_ZZZYZ);
            } else if ("3".equals(htlx)) {
                //不动产查询证明使用档案查询专用章
                request.setCategoryId(Global.ECI_DACXZYZ);
            }
            request.setBizId(waitForCreateContract.getBizId());

            // TODO: 2022/2/14/0014 获取模板参数json字符串,处理方式待定
            String bdcqzsTemplateStr = waitForCreateContract.getDocumentParam();
            BdcqzsTemplate bdcqzsTemplate = JsonUtil.fromJson(bdcqzsTemplateStr, BdcqzsTemplate.class);
            List<BdcqzsTemplate> templates = new ArrayList(){{
                add(bdcqzsTemplate);
            }};
            request.setDocumentParams(templates);

            //提交参数入库
            String tjcs = JsonUtil.toJsonString(request);
            logger.info("提交参数:" + tjcs);
            waitForCreateContract.setTjcs(tjcs);

            try {
                Map map = new HashMap();
                BeanUtils.populate(request, map);
                result = EciHttpUtil.doPost(url, map);
                logger.info("创建合同接口返回结果:" + result);
                CreateContractResponse response = JsonUtil.fromJson(result, CreateContractResponse.class);
                if (response != null) {
                    if (0 == (response.getCode())) {
                        Long contractId = response.getContractId();
                        //合同ID入库
                        waitForCreateContract.setContractId(contractId);
                        //返回结果入库
                        waitForCreateContract.setFhjg(result);
                        //未下载
                        waitForCreateContract.setSfxz("2");
                        //未转换
                        waitForCreateContract.setSfzh("2");
                        licenseInfoDao.updateContractIdAndStatus(waitForCreateContract);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

        }

    }
}