Search in sources :

Example 11 with BusinessLicense

use of com.itrus.portal.db.BusinessLicense in project portal by ixinportal.

the class ImageByBase64 method getImg.

/**
 * 获取图片文件File
 *
 * @param type
 *            类型:0营业执照图片,1组织机构代码图片,2税务登记图片,3授权书图片,4法人图片
 * @param id
 *            营业执照、组织机构代码、税务登记、授权书、法人中的某一项的id
 * @param num
 *            0表示正面,1标识反面图片
 * @return
 */
public File getImg(Long type, Long id, Long num) {
    File imgFile = null;
    String img = null;
    Long enterpriseId = null;
    Long userInfoId = null;
    try {
        if (type == ComNames.BUSINESS_ITEM) {
            BusinessLicense license = sqlsession.selectOne("com.itrus.portal.db.BusinessLicenseMapper.selectByPrimaryKey", id);
            if (license == null) {
                return null;
            }
            img = license.getImgFile();
            enterpriseId = license.getEnterprise();
        } else if (type == ComNames.ORG_CODE_ITEM) {
            OrgCode code = sqlsession.selectOne("com.itrus.portal.db.OrgCodeMapper.selectByPrimaryKey", id);
            if (code == null) {
                return null;
            }
            img = code.getImgFile();
            enterpriseId = code.getEnterprise();
        } else if (type == ComNames.TAX_CERT_ITEM) {
            TaxRegisterCert cert = sqlsession.selectOne("com.itrus.portal.db.TaxRegisterCertMapper.selectByPrimaryKey", id);
            if (cert == null) {
                return null;
            }
            img = cert.getImgFile();
            enterpriseId = cert.getEnterprise();
        } else if (type == ComNames.IDENTITY_CARD_ITEM) {
            IdentityCard card = sqlsession.selectOne("com.itrus.portal.db.IdentityCardMapper.selectByPrimaryKey", id);
            if (card == null) {
                return null;
            }
            if (num == 0) {
                img = card.getFrontImg();
            } else {
                img = card.getBackImg();
            }
            enterpriseId = card.getEnterprise();
        } else if (type == ComNames.PROXY_ITEM) {
            Proxy proxy = sqlsession.selectOne("com.itrus.portal.db.ProxyMapper.selectByPrimaryKey", id);
            if (proxy == null) {
                return null;
            }
            img = proxy.getImgFile();
            // 授权书图片存放在用户唯一标识目录下
            userInfoId = proxy.getUserInfo();
        } else if (type == ComNames.AGENT_ITEM) {
            Agent agent = sqlsession.selectOne("com.itrus.portal.db.AgentMapper.selectByPrimaryKey", id);
            if (agent == null) {
                return null;
            }
            if (num == 0) {
                img = agent.getFrontImg();
            } else {
                img = agent.getBackImg();
            }
            enterpriseId = agent.getEnterprise();
        }
        if (img == null) {
            return null;
        }
        File file = null;
        if (null != enterpriseId) {
            Enterprise enterprise = sqlsession.selectOne("com.itrus.portal.db.EnterpriseMapper.selectByPrimaryKey", enterpriseId);
            file = filePathUtils.getEnterpriseFile(enterprise.getEnterpriseSn());
        } else if (null != userInfoId) {
            // 授权书图片存放在用户唯一标识目录下
            UserInfo userInfo = sqlsession.selectOne("com.itrus.portal.db.UserInfoMapper.selectByPrimaryKey", userInfoId);
            file = filePathUtils.getUserInfoFIle(userInfo.getUniqueId());
        } else {
            return null;
        }
        if (!file.exists()) {
            file.mkdirs();
        }
        imgFile = new File(file, img);
    } catch (IOException e) {
        // 未找到
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return imgFile;
}
Also used : Agent(com.itrus.portal.db.Agent) UserInfo(com.itrus.portal.db.UserInfo) IOException(java.io.IOException) ServiceNullException(com.itrus.portal.exception.ServiceNullException) IOException(java.io.IOException) UserInfoServiceException(com.itrus.portal.exception.UserInfoServiceException) OrgCode(com.itrus.portal.db.OrgCode) BusinessLicense(com.itrus.portal.db.BusinessLicense) Proxy(com.itrus.portal.db.Proxy) Enterprise(com.itrus.portal.db.Enterprise) File(java.io.File) TaxRegisterCert(com.itrus.portal.db.TaxRegisterCert) IdentityCard(com.itrus.portal.db.IdentityCard)

Example 12 with BusinessLicense

use of com.itrus.portal.db.BusinessLicense in project portal by ixinportal.

the class ReviewServiceImpl method queryAudit.

/**
 * 查询送审结果
 *
 * @param appsecret
 * @param appId
 * @param dataid
 * @return
 */
public boolean queryAudit(String appsecret, Long appId, String dataid, Bill bill) throws Exception {
    AuditSystemConfig auditSystemConfig = auditSystemConfigService.getAuditSystemConfig(new AuditSystemConfigExample());
    if (null == auditSystemConfig) {
        // 未配置第三方鉴证信息
        return false;
    }
    Map<String, Object> jsonMap = new HashMap<String, Object>();
    jsonMap.put("appId", appId);
    jsonMap.put("appsecret", appsecret);
    // 待查询的记录id
    jsonMap.put("dataid", dataid);
    String jsonString = jsonTool.writeValueAsString(jsonMap);
    String result = RequestUtils.post(auditSystemConfig.getAuditSystemUrl() + ComNames.QUERYAPIS, jsonString, appsecret);
    JsonNode respNode = jsonTool.readTree(result);
    if (200 == respNode.get("status").asInt()) {
        // 查询成功
        JsonNode statusNode = respNode.get("result");
        // 0是未通过,1是通过,2是审核中
        int auditstatus = statusNode.get("auditstatus").asInt();
        BusinessLicense bl = businessService.getBusinessByBillId(bill.getId(), null);
        OrgCode oc = orgCodeService.getOrgCodeByBillId(bill.getId(), null);
        TaxRegisterCert trc = taxCertService.getTaxRegisterCertByBillId(bill.getId(), null);
        IdentityCard ic = identityCardService.getIdentityCardByBillId(bill.getId(), null);
        Agent at = agentService.getAgentByBillId(bill.getId(), null);
        Proxy p = proxyService.getProxyByBillId(bill.getId());
        // 默认未审核
        Integer itemStatus = 1;
        String reason = null;
        Enterprise enterprise = sqlSession.selectOne("com.itrus.portal.db.EnterpriseMapper.selectByPrimaryKey", bill.getEnterprise());
        if (0 == auditstatus) {
            // 未通过(审核拒绝)
            // 记录未通过原因
            reason = statusNode.get("auditresult").getTextValue();
            // 更新订单状态
            bill.setBillStatus(ComNames.BILL_STATUS_4);
            bill.setCancelReason(reason);
            bill.setCheckTime(new Date(statusNode.get("auditdate").asLong()));
            // 发送短信
            if (sendSmsBySHJJ(bill.getId())) {
                bill.setIsSms(true);
                bill.setSendTime(new Date());
            }
            // 更新认证项状态
            itemStatus = 3;
            // 添加系统日志
            LogUtil.syslog(sqlSession, "单条查询送审", "产品ID" + bill.getProduct() + "企业ID:" + bill.getEnterprise() + ",审核结果:审核拒绝");
        } else if (1 == auditstatus) {
            // 通过
            Product product = sqlSession.selectOne("com.itrus.portal.db.ProductMapper.selectByPrimaryKey", bill.getProduct());
            Product product1 = null;
            Product product2 = null;
            Product product3 = null;
            DigitalCert cert1 = null;
            DigitalCert cert2 = null;
            DigitalCert cert3 = null;
            if (null != bill.getProduct1()) {
                product1 = sqlSession.selectOne("com.itrus.portal.db.ProductMapper.selectByPrimaryKey", bill.getProduct1());
                if (null != product1.getCert()) {
                    cert1 = sqlSession.selectOne("com.itrus.portal.db.DigitalCertMapper.selectByPrimaryKey", product1.getCert());
                }
            }
            if (null != bill.getProduct2()) {
                product2 = sqlSession.selectOne("com.itrus.portal.db.ProductMapper.selectByPrimaryKey", bill.getProduct2());
                if (null != product2.getCert()) {
                    cert2 = sqlSession.selectOne("com.itrus.portal.db.DigitalCertMapper.selectByPrimaryKey", product2.getCert());
                }
            }
            if (null != bill.getProduct3()) {
                product3 = sqlSession.selectOne("com.itrus.portal.db.ProductMapper.selectByPrimaryKey", bill.getProduct3());
                if (null != product3.getCert()) {
                    cert3 = sqlSession.selectOne("com.itrus.portal.db.DigitalCertMapper.selectByPrimaryKey", product3.getCert());
                }
            }
            DigitalCert cert = sqlSession.selectOne("com.itrus.portal.db.DigitalCertMapper.selectByPrimaryKey", product.getCert());
            // 更新企业
            if (respNode.get("source") != null) {
                enterprise.setInfo(respNode.get("source").getTextValue().getBytes());
            }
            enterprise.setReviewTime(new Date());
            enterprise.setAuthenticationLevel(product.getAuthentication());
            // 更新订单状态
            bill.setBillStatus(ComNames.BILL_STATUS_5);
            if (bill.getOldUserCert() != null) {
                bill.setBillStatus(ComNames.BILL_STATUS_12);
            }
            // 数字证书操作方式为用户下载(2)的,订单状态设置为待下载
            if (null != cert && null != cert.getInitBuy() && "2".equals(cert.getInitBuy())) {
                bill.setBillStatus(ComNames.BILL_STATUS_13);
            }
            // 当产品没有配置有数字证书的时候
            if (null == cert && null == cert1 && null == cert2 && null == cert3) {
                // 根据订单判断订单是否需要开票:0标识不需要开票,1需要开纸质发票,2需要开电子发票
                int type = billService.getBillInvoiceType(bill);
                switch(type) {
                    case 0:
                        bill.setBillStatus(ComNames.BILL_STATUS_8);
                        break;
                    case 1:
                        if (null != bill.getIsInvoiced() && bill.getIsInvoiced().equals(1)) {
                            bill.setBillStatus(ComNames.BILL_STATUS_7);
                        } else {
                            bill.setBillStatus(ComNames.BILL_STATUS_6);
                        }
                        break;
                    case 2:
                        if (null != bill.getIsInvoiced() && bill.getIsInvoiced().equals(1)) {
                            bill.setBillStatus(ComNames.BILL_STATUS_8);
                        } else {
                            bill.setBillStatus(ComNames.BILL_STATUS_6);
                        }
                        break;
                    default:
                        break;
                }
            }
            bill.setCheckTime(new Date(statusNode.get("auditdate").asLong()));
            // 更新认证项状态
            itemStatus = 2;
            // 添加系统日志
            LogUtil.syslog(sqlSession, "单条查询送审", "产品ID" + bill.getProduct() + "企业ID:" + bill.getEnterprise() + ",审核结果:审核通过");
        } else if (2 == auditstatus) {
            // 审核中
            throw new UserInfoServiceException(statusNode.get("auditmessage").getTextValue());
        }
        if (null != bl) {
            bl.setItemStatus(itemStatus);
            saveBl(bl, respNode.get("source"));
            enterprise.setHasBl(bl.getId());
        }
        if (null != oc) {
            oc.setItemStatus(itemStatus);
            sqlSession.update("com.itrus.portal.db.OrgCodeMapper.updateByPrimaryKeySelective", oc);
            enterprise.setHasOrgCode(oc.getId());
        }
        if (null != trc) {
            trc.setItemStatus(itemStatus);
            sqlSession.update("com.itrus.portal.db.TaxRegisterCertMapper.updateByPrimaryKeySelective", trc);
            enterprise.setHasTaxCert(trc.getId());
        }
        if (null != ic) {
            ic.setItemStatus(itemStatus);
            sqlSession.update("com.itrus.portal.db.IdentityCardMapper.updateByPrimaryKeySelective", ic);
            enterprise.setHasIdCard(ic.getId());
        }
        if (null != at) {
            at.setItemStatus(itemStatus);
            sqlSession.update("com.itrus.portal.db.AgentMapper.updateByPrimaryKeySelective", at);
            enterprise.setHasAgent(at.getId());
        }
        if (null != p) {
            p.setItemStatus(itemStatus);
        }
        // 更新企业
        sqlSession.update("com.itrus.portal.db.EnterpriseMapper.updateByPrimaryKeyWithBLOBs", enterprise);
        // 更新订单
        sqlSession.update("com.itrus.portal.db.BillMapper.updateByPrimaryKey", bill);
        // 生成鉴证记录
        reviewLogService.saveReviewLog(1, null, auditstatus == 1 ? 1 : 2, reason, bill.getEnterprise(), bill.getId(), bill.getUniqueId(), bl == null ? null : bl.getId(), oc == null ? null : oc.getId(), trc == null ? null : trc.getId(), ic == null ? null : ic.getId(), at == null ? null : at.getId(), p == null ? null : p.getId());
        return true;
    } else if (201 == respNode.get("status").asInt()) {
        // 查询失败
        String message = respNode.get("message").getTextValue();
        throw new UserInfoServiceException(message);
    }
    return false;
}
Also used : Agent(com.itrus.portal.db.Agent) HashMap(java.util.HashMap) AuditSystemConfig(com.itrus.portal.db.AuditSystemConfig) AuditSystemConfigExample(com.itrus.portal.db.AuditSystemConfigExample) Product(com.itrus.portal.db.Product) JsonNode(org.codehaus.jackson.JsonNode) Date(java.util.Date) UserInfoServiceException(com.itrus.portal.exception.UserInfoServiceException) OrgCode(com.itrus.portal.db.OrgCode) DigitalCert(com.itrus.portal.db.DigitalCert) BusinessLicense(com.itrus.portal.db.BusinessLicense) Proxy(com.itrus.portal.db.Proxy) Enterprise(com.itrus.portal.db.Enterprise) JSONObject(com.alibaba.fastjson.JSONObject) TaxRegisterCert(com.itrus.portal.db.TaxRegisterCert) IdentityCard(com.itrus.portal.db.IdentityCard)

Example 13 with BusinessLicense

use of com.itrus.portal.db.BusinessLicense in project portal by ixinportal.

the class SubmitReviewServiceImpl method getAuditJsonParam.

/**
 * 获取单个送审的数据json格式
 *
 * @param bill
 * @return
 */
public String getAuditJsonParam(Bill bill) throws Exception {
    SysConfig sysConfig = cacheCustomer.getSysConfigByType(SystemConfigService.TS_URL);
    if (sysConfig == null || StringUtils.isBlank(sysConfig.getConfig()))
        throw new UserInfoServiceException("缺少终端后台地址配置信息");
    // 查询企业表是是否含有dataid的值
    UserInfo userInfo = sqlSession.selectOne("com.itrus.portal.db.UserInfoMapper.selectByPrimaryKey", bill.getUniqueId());
    Enterprise enterprise = sqlSession.selectOne("com.itrus.portal.db.EnterpriseMapper.selectByPrimaryKey", bill.getEnterprise());
    String dataId = bill.getDataId();
    // 获取产品的认证等级需要认证的项
    Product product = sqlSession.selectOne("com.itrus.portal.db.ProductMapper.selectByPrimaryKey", bill.getProduct());
    Certification certification = sqlSession.selectOne("com.itrus.portal.db.CertificationMapper.selectByPrimaryKey", product.getAuthentication());
    /**
     * 需要认证的项:0营业执照,1组织机构代码,2税务登记证,3授权书,4法定代表人/经营者
     */
    Long[] items = StringTools.getLong(certification.getCertItems());
    BusinessLicense businessLicense = null;
    OrgCode orgCode = null;
    TaxRegisterCert taxRegister = null;
    IdentityCard identityCard = null;
    Proxy proxy = null;
    Agent agent = null;
    for (Long item : items) {
        if (ComNames.BUSINESS_ITEM == item) {
            // 查询订单的营业执照信息
            businessLicense = businessService.getBusinessByBillId(bill.getId(), null);
        } else if (ComNames.ORG_CODE_ITEM == item) {
            // 查询订单的组织机构代码信息
            orgCode = orgCodeService.getOrgCodeByBillId(bill.getId(), null);
        } else if (ComNames.TAX_CERT_ITEM == item) {
            // 查询订单的税务登记证信息
            taxRegister = taxCertService.getTaxRegisterCertByBillId(bill.getId(), null);
        } else if (ComNames.IDENTITY_CARD_ITEM == item) {
            // 查询订单的法人信息
            identityCard = identityCardService.getIdentityCardByBillId(bill.getId(), null);
        } else if (ComNames.PROXY_ITEM == item) {
            // 查询订单的授权书信息
            proxy = proxyService.getProxyByBillId(bill.getId());
        } else if (ComNames.AGENT_ITEM == item) {
            agent = agentService.getAgentByBillId(bill.getId(), null);
        }
    }
    Map<String, Object> jsonMap = new HashMap<String, Object>();
    String appId = product.getAppId().toString();
    String appsecret = product.getAppsecret();
    jsonMap.put("appId", appId);
    jsonMap.put("appsecret", appsecret);
    if (StringUtils.isNotBlank(dataId))
        // 用户查询记录回执id,当审核失败后重新提交时,必填(上一次返回的dataid)
        jsonMap.put("dataid", dataId);
    // 企业信息
    // 企业类型(1为企业;
    jsonMap.put("comptype", enterprise.getEnterpriseNature());
    // 2为个体工商户;3为事业单位/政府机关)
    // 注册省份
    jsonMap.put("compaddress", "");
    // 企业名称
    jsonMap.put("companyname", enterprise.getEnterpriseName());
    // 营业执照信息:当企业类型comptype值为1和2时,必填
    if (null != businessLicense) {
        if (businessLicense.getBusinessType() == 1) {
            // 三证合一企业
            jsonMap.put("businesslicensetype", 1);
        } else {
            // 非三证合一企业
            jsonMap.put("businesslicensetype", 0);
        }
        // 统一社会信用代码/营业执照注册号
        jsonMap.put("compcode", businessLicense.getLicenseNo());
        if (StringUtils.isNotBlank(businessLicense.getImgFile()) && StringUtils.isNotBlank(businessLicense.getImgFileHash())) {
            jsonMap.put("businesslicense", sysConfig.getConfig() + "/reviewWeb/audit/img/0/" + businessLicense.getId() + "/0/" + // 营业执照照片的URL
            businessLicense.getImgFileHash());
        }
    }
    // 组织机构代码信息:当企业类型comptype值为3时,必填
    if (null != orgCode) {
        if (null != orgCode.getOrgCodeType() && orgCode.getOrgCodeType().equals(1)) {
            // 三证合一企业
            jsonMap.put("businesslicensetype", 1);
            if (StringUtils.isNotBlank(orgCode.getImgFile()) && StringUtils.isNotBlank(orgCode.getImgFileHash())) {
                jsonMap.put("businesslicense", sysConfig.getConfig() + "/reviewWeb/audit/img/1/" + orgCode.getId() + "/0/" + // 组织机构代码证照片的URL
                orgCode.getImgFileHash());
            }
            // 统一社会信用代码/营业执照注册号
            jsonMap.put("compcode", orgCode.getOrgCode());
        } else {
            // 组织机构代码(号码)
            jsonMap.put("organizationcode", orgCode.getOrgCode());
            if (StringUtils.isNotBlank(orgCode.getImgFile()) && StringUtils.isNotBlank(orgCode.getImgFileHash())) {
                jsonMap.put("orgcodecertificate", sysConfig.getConfig() + "/reviewWeb/audit/img/1/" + orgCode.getId() + "/0/" + // 组织机构代码证照片的URL
                orgCode.getImgFileHash());
            }
        }
    }
    // 税务登记证信息
    if (null != taxRegister) {
        jsonMap.put("taxregistratno", taxRegister.getCertNo());
        jsonMap.put("taxregcertificate", sysConfig.getConfig() + "/reviewWeb/audit/img/2/" + taxRegister.getId() + "/0/" + // 税务登记证的URL
        taxRegister.getImgFileHash());
    }
    // 授权书信息
    if (null != proxy) {
        jsonMap.put("powerofattorney", // 授权书的URL
        sysConfig.getConfig() + "/reviewWeb/audit/img/3/" + proxy.getId() + "/0/" + proxy.getImgFileHash());
    }
    // 法人信息
    if (null != identityCard) {
        // 法人姓名
        jsonMap.put("legalname", identityCard.getName());
        // 法人证件类型(1为身份证;2为护照;3为其他)
        jsonMap.put("legalnotype", identityCard.getCardType());
        // 法人证件号码
        jsonMap.put("legalidcardno", identityCard.getIdCode());
        jsonMap.put("legalpzmzp", sysConfig.getConfig() + "/reviewWeb/audit/img/4/" + identityCard.getId() + "/0/" + // 法人证件正面照片的URL
        identityCard.getFrontImgHash());
        if (StringUtils.isNotBlank(identityCard.getBackImg()) && StringUtils.isNotBlank(identityCard.getBackImgHash())) {
            jsonMap.put("legalpfmzp", sysConfig.getConfig() + "/reviewWeb/audit/img/4/" + identityCard.getId() + "/1/" + // 法人证件反面照片的URL
            identityCard.getBackImgHash());
        }
    }
    // 代理人信息
    // 代理人姓名
    jsonMap.put("proxyname", userInfo.getRealName());
    // 代理人手机号
    jsonMap.put("proxyphone", userInfo.getmPhone());
    // 代理人座机
    jsonMap.put("proxytele", userInfo.getTelephone());
    // 代理人邮箱
    jsonMap.put("proxyemail", userInfo.getEmail());
    if (null != agent) {
        // 代理人证件类型(1为身份证;2为护照;3为其他)
        jsonMap.put("proxynotype", agent.getCardType());
        // 代理人身份证号
        jsonMap.put("proxypidcardno", agent.getIdCode());
        jsonMap.put("proxypzmzp", sysConfig.getConfig() + "/reviewWeb/audit/img/5/" + agent.getId() + "/0/" + // 代理人身份证正面照片
        agent.getFrontImgHash());
        if (StringUtils.isNotBlank(agent.getBackImg()) && StringUtils.isNotBlank(agent.getBackImgHash())) {
            jsonMap.put("proxypfmzp", sysConfig.getConfig() + "/reviewWeb/audit/img/5/" + agent.getId() + "/1/" + // 代理人身份证反面照片
            agent.getBackImgHash());
        }
    }
    return jsonTool.writeValueAsString(jsonMap);
}
Also used : SysConfig(com.itrus.portal.db.SysConfig) HashMap(java.util.HashMap) Product(com.itrus.portal.db.Product) UserInfo(com.itrus.portal.db.UserInfo) UserInfoServiceException(com.itrus.portal.exception.UserInfoServiceException) Certification(com.itrus.portal.db.Certification) OrgCode(com.itrus.portal.db.OrgCode) BusinessLicense(com.itrus.portal.db.BusinessLicense) Proxy(com.itrus.portal.db.Proxy) Enterprise(com.itrus.portal.db.Enterprise) TaxRegisterCert(com.itrus.portal.db.TaxRegisterCert) IdentityCard(com.itrus.portal.db.IdentityCard)

Example 14 with BusinessLicense

use of com.itrus.portal.db.BusinessLicense in project portal by ixinportal.

the class BaiWangTask method query.

/**
 * 、 CA 申请记录查询接口服务
 *2.1、 请求报文
 *接口说明: 用于第三方开票服务商查看已提交的企业 CA 申请结果信息
 *调用方式: HTTPS 请求方式 POST 请求
 *测试环境 URL:
 *https://ip:port/Entoauth/thirdInviceService?sign=caResult&xml=
 *<REQUEST>
 *<HEAD>
 *<client_id>企业的 client_id</client_id>
 *<access_token>二.1 接口获取到</access_token>
 *<openID>二.2 接口获取到</openID>
 *</HEAD>
 *<BODY>
 *<SQM>代办 CA 授权码</SQM>
 *<TAX_REGISTER_NO>企业证件号码</TAX_REGISTER_NO>
 *</BODY>
 *</REQUEST>
 */
// 2.订单状态
@Scheduled(cron = "0 0/10 * * * ?")
public void query() {
    synchronized (BaiWangTaskLock) {
        // start------------处理双机互斥----------
        if (null == taskFlag) {
            taskFlag = systemConfigService.isTimedTaskHost();
        }
        if (taskFlag.equals(false)) {
            return;
        }
        // end------------处理双机互斥----------
        if (!isConnection() || !isBaiWangDanJiConnection()) {
            initBaiWang();
        }
        List<ExtraProduct> products = new ArrayList<>();
        DefaultTransactionDefinition def = new DefaultTransactionDefinition();
        def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
        TransactionStatus status = null;
        try {
            // 1.先判断有没有该接口类型的产品,没有则返回
            products = extraProductService.getExtraProductBySIN(ComNames.SERVICE_INTERFACE_NAME_BWFPTPT);
            if (null == products || products.isEmpty()) {
                return;
            }
            for (ExtraProduct product : products) {
                // 筛选是该产品,并且订单状态是服务商审核中
                Map<String, Object> paramMap = new HashMap<String, Object>();
                paramMap.put("productId", product.getId());
                paramMap.put("isquery", 1);
                paramMap.put("desc", 1);
                // 2.查找是该产品的订单,并且订单状态是已支付,待服务商审核的订单.然后遍历订单信息
                List<Map<String, Object>> Extrabills = sqlSession.selectList("com.itrus.portal.db.ExtraBillMapper.selectByCondition_BAIWANG", paramMap);
                if (null == Extrabills || Extrabills.isEmpty()) {
                    continue;
                }
                Integer count = 0;
                Integer count_danji = 0;
                Map resultMap = new HashMap<>();
                for (Map<String, Object> bill : Extrabills) {
                    Long id = (Long) bill.get("id");
                    Boolean is_sendfpt = (Boolean) bill.get("is_sendfpt");
                    Boolean is_passfpt = (Boolean) bill.get("is_passfpt");
                    Boolean is_senddj = (Boolean) bill.get("is_senddj");
                    Boolean is_passdj = (Boolean) bill.get("is_passdj");
                    // 其他附加信息
                    // 营业执照
                    BusinessLicense businessLicense = businessService.getBusinessByExtraBillId(id, null);
                    // 企业信息
                    Enterprise enterprise = enterpriseService.getEnterpriseById((Long) bill.get("enterprise"));
                    // 开户行信息
                    OpenBankInfo openBankInfo = openBankInfoService.getOpenBankInfoByExtraBillId(id, null);
                    // 税务登记
                    TaxRegisterCert taxRegisterCert = taxCertService.getTaxRegisterCertByExtraBillId(id, null);
                    // 0:税号 1:信用代码号
                    Integer credentialsType = null;
                    if (null != businessLicense && businessLicense.getBusinessType().equals(1)) {
                        credentialsType = 1;
                    } else if (null != taxRegisterCert) {
                        credentialsType = 0;
                    }
                    String TAX_REGISTER_NO = credentialsType == 1 ? businessLicense.getLicenseNo() : taxRegisterCert.getCertNo();
                    String param2 = "";
                    try {
                        if (null != is_sendfpt && is_sendfpt.equals(true) && ((null == is_passfpt || is_passfpt.equals(false)))) {
                            /**
                             * 、 CA 申请记录查询接口服务
                             *							2.1、 请求报文
                             *							接口说明: 用于第三方开票服务商查看已提交的企业 CA 申请结果信息
                             *							调用方式: HTTPS 请求方式 POST 请求
                             *							测试环境 URL:
                             *							https://ip:port/Entoauth/thirdInviceService?sign=caResult&xml=
                             *							<REQUEST>
                             *							<HEAD>
                             *							<client_id>企业的 client_id</client_id>
                             *							<access_token>二.1 接口获取到</access_token>
                             *							<openID>二.2 接口获取到</openID>
                             *							</HEAD>
                             *							<BODY>
                             *							<SQM>代办 CA 授权码</SQM>
                             *							<TAX_REGISTER_NO>企业证件号码</TAX_REGISTER_NO>
                             *							</BODY>
                             *							</REQUEST>
                             */
                            param2 = "<REQUEST><HEAD>" + "<client_id>" + client_id + "</client_id>" + "<access_token>" + access_token + "</access_token>" + "<openID>" + openID + "</openID>" + "</HEAD>" + "<BODY>" + "<SQM>" + SQM + "</SQM>" + "<TAX_REGISTER_NO>" + TAX_REGISTER_NO + "</TAX_REGISTER_NO>" + "</BODY>" + "</REQUEST>";
                            String param = URLEncoder.encode(new String(Base64.encode(param2.getBytes())), "UTF-8");
                            LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<String, Object>();
                            String urlAccessToken = baseUrl + "thirdInvoiceService";
                            URI uri;
                            uri = new URI(urlAccessToken);
                            map.add("sign", "caResult");
                            map.add("xml", param);
                            String xml = restTemplate.postForObject(uri, map, String.class);
                            resultMap = parseXml(xml);
                            String recode = resultMap.get("REPLYCODE").toString();
                            ExtraBill extraBill = extraBillService.selectByPrimaryKey(id);
                            if (StringUtils.isNotBlank(recode) && recode.equals("0000")) {
                                // 当单机的已经审核通过之后,才能修改订单状态
                                if (null != extraBill.getIsPassdj() && extraBill.getIsPassdj().equals(true)) {
                                    if (null != extraBill.geteInvoice()) {
                                        // 订单需要开票.判断是否开票了.
                                        Boolean isinvoiced = extraBill.getIsInvoiced();
                                        if (null == isinvoiced || isinvoiced.equals(false)) {
                                            extraBill.setBillStatus(ComNames.EXTRA_BILL_STATUS_6);
                                        } else {
                                            extraBill.setBillStatus(ComNames.EXTRA_BILL_STATUS_7);
                                            extraBill.setFinishTime(new Date());
                                        }
                                    } else {
                                        // 订单不需要开票,直接完成
                                        extraBill.setBillStatus(ComNames.EXTRA_BILL_STATUS_7);
                                        extraBill.setFinishTime(new Date());
                                    }
                                    extraBill.setCheckTime(new Date());
                                }
                                extraBill.setIsPassfpt(true);
                                is_passfpt = true;
                                status = transactionManager.getTransaction(def);
                                extraBillService.updateByPrimaryKeySelective(extraBill);
                                transactionManager.commit(status);
                                count++;
                            } else if (StringUtils.isNotBlank(recode) && recode.equals("0003")) {
                                extraBill.setRefuseReason(resultMap.get("REPLYMSG").toString());
                                extraBill.setBillStatus(ComNames.EXTRA_BILL_STATUS_5);
                                extraBill.setIsRefuse(true);
                                extraBill.setIsPassfpt(false);
                                extraBill.setIsSendfpt(false);
                                status = transactionManager.getTransaction(def);
                                extraBillService.updateByPrimaryKeySelective(extraBill);
                                transactionManager.commit(status);
                                log.error("审核拒绝_百旺发票通", "订单号:" + bill.get("bill_id").toString() + "拒绝信息:" + resultMap.get("REPLYMSG") + ", 参数:" + param2);
                                LogUtil.syslog(sqlSession, "审核拒绝_百旺发票通", "订单号:" + bill.get("bill_id").toString() + "拒绝信息:" + resultMap.get("REPLYMSG"));
                                count++;
                            }
                        }
                    } catch (Exception e) {
                        log.error("查询订单_百旺发票通", "出现异常,订单号:" + bill.get("bill_id").toString() + "错误异常:" + e.getMessage() + ", 参数:" + param2);
                        LogUtil.syslog(sqlSession, "查询订单_百旺发票通", "出现异常,订单号:" + bill.get("bill_id").toString() + "错误异常:" + e.getMessage());
                    }
                    // 查询单机
                    if (null != is_senddj && is_senddj.equals(true) && (null == is_passdj || is_passdj.equals(false))) {
                        StringBuffer stringBuffer = new StringBuffer();
                        String url = dan_ji_url + "/fpfw/api/kpbusiness";
                        /**
                         *								<?xml version="1.0" encoding="utf-8"?>
                         *								<business comment="查询申请结果" id="CXSQJG">
                         *								<head>
                         *								    <login_name><![CDATA[itruschina]]></login_name>
                         *								    <passwd><![CDATA[12345678]]></passwd>
                         *								    <skpbh><![CDATA[ceshi2017071311222333]]></skpbh>
                         *								    <nsrsbh><![CDATA[911101088020176222333]]></nsrsbh>
                         *								</head>
                         *								</business>
                         */
                        stringBuffer.append("<?xml version='1.0' encoding='utf-8'?>");
                        stringBuffer.append("<business comment='查询申请结果' id='CXSQJG'>");
                        stringBuffer.append("<head>");
                        stringBuffer.append("<login_name><![CDATA[" + dan_ji_userName + "]]></login_name>");
                        stringBuffer.append("<passwd><![CDATA[" + dan_ji_passWord + "]]></passwd>");
                        stringBuffer.append("<skpbh><![CDATA[" + openBankInfo.getTaxNumber() + "]]></skpbh>");
                        stringBuffer.append("<nsrsbh><![CDATA[" + enterprise.getNsrsbh() + "]]></nsrsbh>");
                        stringBuffer.append("</head>");
                        stringBuffer.append("</business>");
                        try {
                            resultMap = new HashMap<>();
                            HttpClient client = new HttpClient();
                            client.getHostConfiguration().setHost(dan_ji_url, dan_ji_port, dan_ji_protocol);
                            HttpMethod method = null;
                            PostMethod post = new PostMethod("/fpfw/api/kpbusiness");
                            NameValuePair bw = new NameValuePair("bw", stringBuffer.toString());
                            NameValuePair[] nameValuePairs = { bw };
                            post.setRequestBody(nameValuePairs);
                            method = post;
                            client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
                            method.addRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
                            client.executeMethod(method);
                            String xml = new String(method.getResponseBodyAsString().getBytes("UTF-8"));
                            resultMap = parseXml(xml);
                            /**
                             *								 返回报文:
                             *								<?xml version="1.0" encoding="utf-8"?>
                             *								<business id="CXSQJG" version='1.0'>
                             *								<head>
                             *								</head>
                             *								<body>
                             *								<sq_date>申请日期</sq_date>
                             *								<yxqq>有效期起</yxqq>
                             *								<yxqz>有效期止</yxqz>
                             *								<kt_date>开通日期</kt_date>
                             *								<downloadurl>下载地址</downloadurl>
                             *								<returncode>返回</returncode>
                             *								<returnmsg>返回信息</returnmsg>
                             *								</body>
                             *								</business>
                             */
                            String returncode = resultMap.get("returncode").toString();
                            ExtraBill extraBill = extraBillService.selectByPrimaryKey(id);
                            if (StringUtils.isNotBlank(returncode) && returncode.equals(BW_DANJI_SHEN_HE_TONG_GUO)) {
                                // 当发票通的已经审核通过之后,才能修改订单状态
                                if (null != extraBill.getIsPassfpt() && extraBill.getIsPassfpt().equals(true)) {
                                    if (null != extraBill.geteInvoice()) {
                                        // 订单需要开票.判断是否开票了.
                                        Boolean isinvoiced = extraBill.getIsInvoiced();
                                        if (null == isinvoiced || isinvoiced.equals(false)) {
                                            extraBill.setBillStatus(ComNames.EXTRA_BILL_STATUS_6);
                                        } else {
                                            extraBill.setBillStatus(ComNames.EXTRA_BILL_STATUS_7);
                                            extraBill.setFinishTime(new Date());
                                        }
                                    } else {
                                        // 订单不需要开票,直接完成
                                        extraBill.setBillStatus(ComNames.EXTRA_BILL_STATUS_7);
                                        extraBill.setFinishTime(new Date());
                                    }
                                    extraBill.setCheckTime(new Date());
                                }
                                extraBill.setIsPassdj(true);
                                is_passdj = true;
                                bwdjRecordService.insertOneRecored(resultMap, extraBill.getId());
                                status = transactionManager.getTransaction(def);
                                extraBillService.updateByPrimaryKeySelective(extraBill);
                                transactionManager.commit(status);
                                count_danji++;
                            } else if (StringUtils.isNotBlank(returncode) && returncode.equals(BW_DANJI_SHEN_HE_JU_JUE)) {
                                status = transactionManager.getTransaction(def);
                                String refuseReason = (String) resultMap.get("returnmsg");
                                extraBill.setRefuseReason(refuseReason);
                                refuseDanJi(extraBill);
                                transactionManager.commit(status);
                                log.error("审核拒绝_百旺单机", "订单号:" + bill.get("bill_id").toString() + "错误码:" + resultMap.get("returncode") + "错误信息:" + resultMap.get("returnmsg") + ", 参数:" + stringBuffer.toString());
                                LogUtil.syslog(sqlSession, "审核拒绝_百旺单机", "订单号:" + bill.get("bill_id").toString() + "错误码:" + resultMap.get("returncode") + "错误信息:" + resultMap.get("returnmsg"));
                            }
                        } catch (Exception e) {
                            log.error("查询订单_百旺单机", "出现异常,订单号:" + bill.get("bill_id").toString() + "错误异常:" + e.getMessage() + ", 参数:" + stringBuffer.toString());
                            LogUtil.syslog(sqlSession, "查询订单_百旺单机", "出现异常,订单号:" + bill.get("bill_id").toString() + "错误异常:" + e.getMessage());
                        }
                    }
                }
                LogUtil.syslog(sqlSession, "查询订单_百旺发票通", "总共:" + Extrabills.size() + "条,成功:" + count + "条");
            }
        } catch (Exception e) {
            LogUtil.syslog(sqlSession, "查询订单失败_百旺", "错误信息:" + e.getMessage());
            e.printStackTrace();
        } finally {
            if (status != null && !status.isCompleted()) {
                transactionManager.rollback(status);
            }
        }
    }
}
Also used : DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) HashMap(java.util.HashMap) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) PostMethod(org.apache.commons.httpclient.methods.PostMethod) ExtraBill(com.itrus.portal.db.ExtraBill) ArrayList(java.util.ArrayList) TransactionStatus(org.springframework.transaction.TransactionStatus) URI(java.net.URI) OpenBankInfo(com.itrus.portal.db.OpenBankInfo) NameValuePair(org.apache.commons.httpclient.NameValuePair) Date(java.util.Date) ExtraProduct(com.itrus.portal.db.ExtraProduct) BusinessLicense(com.itrus.portal.db.BusinessLicense) HttpClient(org.apache.commons.httpclient.HttpClient) Enterprise(com.itrus.portal.db.Enterprise) Map(java.util.Map) HashMap(java.util.HashMap) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) TaxRegisterCert(com.itrus.portal.db.TaxRegisterCert) HttpMethod(org.apache.commons.httpclient.HttpMethod) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 15 with BusinessLicense

use of com.itrus.portal.db.BusinessLicense in project portal by ixinportal.

the class BaiWangTask method submitOrder.

// 1.订单资料推送
@Scheduled(cron = "0 0/7 * * * ?")
public void submitOrder() {
    /**
     *		 <REQUEST>
     *<HEAD>
     *<client_id>企业的 client_id</client_id>
     *<access_token>二.1 接口获取到</access_token>
     *<openID>二.2 接口获取到</openID>
     *</HEAD>
     *<BODY>
     *<SQM>代办 CA 授权码</SQM>
     *<TAXPAYER_NAME>企业名称</TAXPAYER_NAME>
     *<SHORT_NAME>企业简称</SHORT_NAME>
     *<IS_SZHY>企业证件类型</IS_SZHY>
     *<TAX_REGISTER_NO>企业税号</TAX_REGISTER_NO>
     *<ENT_PROVINCE>省份</ENT_PROVINCE>
     *<ENT_CITY>城市</ENT_CITY>
     *<LEGAL_PERSON>企业法人</LEGAL_PERSON>
     *<ADDRESS>企业联系地址</ADDRESS>
     *<ENT_EMAIL>企业邮箱</ENT_EMAIL>
     *<A_NAME>企业联系人姓名</A_NAME>
     *<A_MOBILE>企业联系电话</A_MOBILE>
     *<A_ID_NO>企业联系人身份证号码</A_ID_NO>
     *<A_EINVOICE_DEL>CA 申请表</A_EINVOICE_DEL>
     *<A_BIZ_LIC>三证合一/营业执照</A_BIZ_LIC>
     *<A_ID_FRONT>企业联系人身份证(正面)</A_ID_FRONT>
     *<A_ID_BACK>企业联系人身份证(反面)</A_ID_BACK>
     *<TAXPAYER_ID>申请 CA 企业对应唯一编号/当 type=1 时必传</TAXPAYER_ID>
     *</BODY>
     *</REQUEST>
     *"<REQUEST><HEAD>"
     */
    synchronized (BaiWangTaskLock) {
        // start------------处理双机互斥----------
        if (null == taskFlag) {
            taskFlag = systemConfigService.isTimedTaskHost();
        }
        if (taskFlag.equals(false)) {
            return;
        }
        // end------------处理双机互斥----------
        if (!isConnection() || !isBaiWangDanJiConnection()) {
            initBaiWang();
        }
        List<ExtraProduct> products = new ArrayList<>();
        DefaultTransactionDefinition def = new DefaultTransactionDefinition();
        def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
        TransactionStatus status = null;
        try {
            // 1.先判断有没有该接口类型的产品,没有则返回
            products = extraProductService.getExtraProductBySIN(ComNames.SERVICE_INTERFACE_NAME_BWFPTPT);
            if (null == products || products.isEmpty()) {
                return;
            }
            for (ExtraProduct product : products) {
                // 筛选是该产品,并且订单状态是3:已支付,待服务商审核,5:服务商审核拒绝 :这两种状态的订单
                Map<String, Object> paramMap = new HashMap<String, Object>();
                paramMap.put("productId", product.getId());
                paramMap.put("issubmit", 1);
                paramMap.put("desc", 1);
                // 2.查找是该产品的订单,并且订单状态是已支付,待服务商审核的订单.然后遍历订单信息
                List<Map<String, Object>> Extrabills = sqlSession.selectList("com.itrus.portal.db.ExtraBillMapper.selectByCondition_BAIWANG", paramMap);
                if (null == Extrabills || Extrabills.isEmpty()) {
                    continue;
                }
                Integer count = 0;
                Integer count_danji = 0;
                Map<String, String> resultMap = new HashMap<>();
                for (Map<String, Object> bill : Extrabills) {
                    Long id = (Long) bill.get("id");
                    Boolean is_sendfpt = (Boolean) bill.get("is_sendfpt");
                    Boolean is_passfpt = (Boolean) bill.get("is_passfpt");
                    Boolean is_senddj = (Boolean) bill.get("is_senddj");
                    Boolean is_passdj = (Boolean) bill.get("is_passdj");
                    Long userinfoId = (Long) bill.get("unique_id");
                    // 企业信息
                    Enterprise enterprise = enterpriseService.getEnterpriseById((Long) bill.get("enterprise"));
                    // 其他附加信息
                    // 营业执照
                    BusinessLicense businessLicense = businessService.getBusinessByExtraBillId(id, null);
                    // 税务登记
                    TaxRegisterCert taxRegisterCert = taxCertService.getTaxRegisterCertByExtraBillId(id, null);
                    // 组织机构代码
                    // OrgCode orgCode = orgCodeService.getOrgCodeByExtraBillId(id, null);
                    // 代理人
                    // Agent agent = agentService.getAgentByExtraBillId(id, null);
                    // 用户
                    UserInfo userInfo = userInfoService.getUserInfoById(userinfoId);
                    // 开户行信息
                    OpenBankInfo openBankInfo = openBankInfoService.getOpenBankInfoByExtraBillId(id, null);
                    // 法人信息
                    IdentityCard identityCard = identityCardService.getIdentityCardByExtraBillId(id, null);
                    Integer type = 0;
                    Boolean isRefuse = (Boolean) bill.get("is_refuse");
                    if (null != isRefuse && isRefuse.equals(true)) {
                        type = 1;
                    }
                    // 0:税号 1:信用代码号
                    Integer credentialsType = null;
                    if (null != businessLicense && businessLicense.getBusinessType().equals(1)) {
                        credentialsType = 1;
                    } else if (null != taxRegisterCert) {
                        credentialsType = 0;
                    }
                    String TAX_REGISTER_NO = credentialsType == 1 ? businessLicense.getLicenseNo() : taxRegisterCert.getCertNo();
                    // 省份,当省份是几个直辖的或者特区的时候,省和市是一样的
                    // 北京市110000,天津市120000,上海市310000,重庆市500000,
                    // 香港,澳门,台湾先不做处理
                    String province = enterprise.getProvince();
                    boolean iscity = false;
                    if (province.equals("110000") || province.equals("120000") || province.equals("310000") || province.equals("500000")) {
                        iscity = true;
                    }
                    province = sysRegionService.getProvince(province);
                    // 城市
                    String city = "";
                    if (iscity) {
                        city = province;
                    } else {
                        city = sysRegionService.getCity(enterprise.getCity());
                    }
                    String param2 = "";
                    // 当没发送过到百旺发票通的时候,则进行发送
                    if (null == is_sendfpt || is_sendfpt.equals(false)) {
                        File file = new File(systemConfigService.getTrustDir().getPath() + File.separator + enterprise.getEnterpriseSn());
                        if (!file.exists()) {
                            file.mkdir();
                        }
                        File imgFile = new File(file, businessLicense.getImgFile());
                        FileInputStream fis = null;
                        fis = new FileInputStream(imgFile);
                        // 三证合一/营业执照
                        String A_BIZ_LIC = ImageToBase64Utils.GetFileBase64(fis);
                        // CompressImageUtils.getThumbPicture(A_BIZ_LIC, width, height);
                        if (A_BIZ_LIC.length() > BAI_WANG_MAX_IMG) {
                            A_BIZ_LIC = compressImage(A_BIZ_LIC);
                        }
                        fis.close();
                        // +"<A_ID_FRONT>"+"企业联系人身份证(正面)"+"</A_ID_FRONT>"
                        imgFile = new File(file, identityCard.getFrontImg());
                        fis = new FileInputStream(imgFile);
                        String A_ID_FRONT = ImageToBase64Utils.GetFileBase64(fis);
                        if (A_ID_FRONT.length() > BAI_WANG_MAX_IMG) {
                            A_ID_FRONT = compressImage(A_ID_FRONT);
                        }
                        fis.close();
                        // 若法人是合并上传的,则传递两张一样的照片过去
                        String A_ID_BACK = "";
                        if (StringUtils.isBlank(identityCard.getBackImg())) {
                            A_ID_BACK = A_ID_FRONT;
                        } else {
                            // +"<A_ID_BACK>"+"企业联系人身份证(反面)"+"</A_ID_BACK>"
                            imgFile = new File(file, identityCard.getBackImg());
                            fis = new FileInputStream(imgFile);
                            A_ID_BACK = ImageToBase64Utils.GetFileBase64(fis);
                            if (A_ID_BACK.length() > BAI_WANG_MAX_IMG) {
                                A_ID_BACK = compressImage(A_ID_BACK);
                            }
                            fis.close();
                        }
                        // +"<TAXPAYER_ID>"+"申请 CA 企业对应唯一编号/当 type=1 时必传"+"</TAXPAYER_ID>"
                        String TAXPAYER_ID = "";
                        if (type == 1) {
                            TAXPAYER_ID = bill.get("taxpayer_id").toString();
                        }
                        // 2.根据产品信息,去筛选企业信息.
                        // HTTPS 请求方式 POST 请求
                        // 1:type 0:代表 CA 新申请, 1: 新申请被驳回, 而再次推送修改过后的资料操作
                        // 服务商是否曾经拒绝过该订单,如果拒绝过.则为true;再次提交给服务商的时候,先判断这个值,如果为true,则进行特殊处理,发送之后,修改该值为false
                        // field boolean --fieldName isRefuse
                        // https://ip:port/Entoauth/thirdInvoiceService?sign=caApply&type=&xml=
                        param2 = "<REQUEST><HEAD>" + "<client_id>" + client_id + "</client_id>" + "<access_token>" + access_token + "</access_token>" + "<openID>" + openID + "</openID>" + "</HEAD>" + "<BODY>" + "<SQM>" + SQM + "</SQM>" + "<TAXPAYER_NAME>" + enterprise.getEnterpriseName() + "</TAXPAYER_NAME>" + "<SHORT_NAME>" + enterprise.getShortName() + "</SHORT_NAME>" + // 0:税号 1:信用代码号
                        "<IS_SZHY>" + credentialsType + "</IS_SZHY>" + // 企业税号或者企业三证合一之后的社会信用代码
                        "<TAX_REGISTER_NO>" + TAX_REGISTER_NO + "</TAX_REGISTER_NO>" + "<ENT_PROVINCE>" + province + "</ENT_PROVINCE>" + "<ENT_CITY>" + city + "</ENT_CITY>" + "<LEGAL_PERSON>" + identityCard.getName() + "</LEGAL_PERSON>" + "<ADDRESS>" + businessLicense.getBusinessPlace() + "</ADDRESS>" + "<ENT_EMAIL>" + bill.get("email").toString() + "</ENT_EMAIL>" + "<A_NAME>" + userInfo.getRealName() + "</A_NAME>" + "<A_MOBILE>" + bill.get("m_phone").toString() + "</A_MOBILE>" + "<A_ID_NO>" + identityCard.getIdCode() + "</A_ID_NO>" + "<A_EINVOICE_DEL></A_EINVOICE_DEL>" + "<A_BIZ_LIC>" + A_BIZ_LIC + "</A_BIZ_LIC>" + "<A_ID_FRONT>" + A_ID_FRONT + "</A_ID_FRONT>" + "<A_ID_BACK>" + A_ID_BACK + "</A_ID_BACK>" + "<TAXPAYER_ID>" + TAXPAYER_ID + "</TAXPAYER_ID>" + "</BODY>" + "</REQUEST>";
                        String param = URLEncoder.encode(new String(Base64.encode(param2.getBytes())), "UTF-8");
                        LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<String, Object>();
                        // https://ip:port/Entoauth/thirdInvoiceService?sign=caApply&type=&xml=
                        // String urlAccessToken = baseUrl + "thirdInvoiceService?sign=caApply"
                        // + "&type=" + type + "&xml=" + param;
                        String urlAccessToken = baseUrl + "thirdInvoiceService";
                        URI uri;
                        uri = new URI(urlAccessToken);
                        map.add("sign", "caApply");
                        map.add("type", type);
                        map.add("xml", param);
                        String xml = restTemplate.postForObject(uri, map, String.class);
                        resultMap = parseXml(xml);
                        String recode = resultMap.get("REPLYCODE");
                        if (StringUtils.isNotBlank(recode) && recode.equals("0000")) {
                            ExtraBill extraBill = extraBillService.selectByPrimaryKey(id);
                            extraBill.setIsSendfpt(true);
                            // 两个平台都成功送审之后,订单状态改为服务商审核中
                            if (null != extraBill.getIsSenddj() && extraBill.getIsSenddj().equals(true)) {
                                extraBill.setBillStatus(ComNames.EXTRA_BILL_STATUS_4);
                            }
                            extraBill.setTaxpayerId(resultMap.get("TAXPAYER_ID").toString());
                            if (type == 1) {
                                // 曾经拒绝过的订单,再次推送成功
                                extraBill.setIsRefuse(false);
                            }
                            status = transactionManager.getTransaction(def);
                            extraBillService.updateByPrimaryKeySelective(extraBill);
                            transactionManager.commit(status);
                            count++;
                        } else {
                            log.error("推送订单失败_百旺发票通", "订单号:" + bill.get("bill_id").toString() + "错误码:" + resultMap.get("REPLYCODE") + "错误信息:" + resultMap.get("REPLYMSG") + ", 参数:" + param2);
                            LogUtil.syslog(sqlSession, "推送订单失败_百旺发票通", "订单号:" + bill.get("bill_id").toString() + "错误码:" + resultMap.get("REPLYCODE") + "错误信息:" + resultMap.get("REPLYMSG"));
                        }
                    }
                    // 当没发送到百旺单机的时候,重新发送
                    if (null == is_senddj || is_senddj.equals(false)) {
                        StringBuffer stringBuffer = new StringBuffer();
                        /**
                         *						<?xml version="1.0" encoding="utf-8"?>
                         *						<business comment="注册申请" id="ZCSQ">
                         *						<body>
                         *						    <login_name><![CDATA[itruschina]]></login_name>
                         *						    <passwd><![CDATA[12345678]]></passwd>
                         *						    <skpbh><![CDATA[ceshi2017071311222333]]></skpbh>
                         *						    <nsrsbh><![CDATA[911101088020176222333]]></nsrsbh>
                         *						    <nsrmc><![CDATA[北京天威诚信电子商务服务有限公司测试070333]]></nsrmc>
                         *						    <city><![CDATA[北京市]]></city>
                         *						    <kh_usr_name><![CDATA[张三]]></kh_usr_name>
                         *						    <kh_lxdh><![CDATA[18878996333]]></kh_lxdh>
                         *						    <sfsy><![CDATA[1]]></sfsy>
                         *						    <bz><![CDATA[123]]></bz>
                         *						    <sqr_usr_name><![CDATA[何冠宏]]></sqr_usr_name>
                         *						    <sqr_lxdh><![CDATA[18878991333]]></sqr_lxdh>
                         *						    <sqr_ssgs><![CDATA[北京天威诚信电子商务服务有限公司]]></sqr_ssgs>
                         *						    <sfsf><![CDATA[1]]></sfsf>
                         *						    <sfje><![CDATA[0]]></sfje>
                         *						</body>
                         *						</business>
                         */
                        stringBuffer.append("<?xml version='1.0' encoding='utf-8'?>");
                        stringBuffer.append("<business comment='注册申请' id='ZCSQ'>");
                        stringBuffer.append("<body>");
                        stringBuffer.append("<login_name><![CDATA[" + dan_ji_userName + "]]></login_name>");
                        stringBuffer.append("<passwd><![CDATA[" + dan_ji_passWord + "]]></passwd>");
                        stringBuffer.append("<skpbh><![CDATA[" + openBankInfo.getTaxNumber() + "]]></skpbh>");
                        stringBuffer.append("<nsrsbh><![CDATA[" + enterprise.getNsrsbh() + "]]></nsrsbh>");
                        stringBuffer.append("<nsrmc><![CDATA[" + enterprise.getEnterpriseName() + "]]></nsrmc>");
                        stringBuffer.append("<city><![CDATA[" + city + "]]></city>");
                        stringBuffer.append("<kh_usr_name><![CDATA[" + userInfo.getRealName() + "]]></kh_usr_name>");
                        stringBuffer.append("<kh_lxdh><![CDATA[" + bill.get("m_phone").toString() + "]]></kh_lxdh>");
                        // 试用就是1 ,正式就用0.这个是针对客户端是否试用的
                        stringBuffer.append("<sfsy><![CDATA[0]]></sfsy>");
                        stringBuffer.append("<bz><![CDATA[" + bill.get("bill_id").toString() + "]]></bz>");
                        stringBuffer.append("<sqr_usr_name><![CDATA[" + "王晓雪" + "]]></sqr_usr_name>");
                        stringBuffer.append("<sqr_lxdh><![CDATA[" + "13120460901" + "]]></sqr_lxdh>");
                        stringBuffer.append("<sqr_ssgs><![CDATA[" + "北京天威诚信电子商务服务有限公司" + "]]></sqr_ssgs>");
                        stringBuffer.append("<sfsf><![CDATA[1]]></sfsf>");
                        stringBuffer.append("<sfje><![CDATA[0]]></sfje>");
                        stringBuffer.append("</body>");
                        stringBuffer.append("</business>");
                        try {
                            HttpClient client = new HttpClient();
                            client.getHostConfiguration().setHost(dan_ji_url, dan_ji_port, dan_ji_protocol);
                            HttpMethod method = null;
                            PostMethod post = new PostMethod("/fpfw/api/kpbusiness");
                            NameValuePair bw = new NameValuePair("bw", stringBuffer.toString());
                            NameValuePair[] nameValuePairs = { bw };
                            post.setRequestBody(nameValuePairs);
                            method = post;
                            client.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
                            method.addRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
                            client.executeMethod(method);
                            String xml = new String(method.getResponseBodyAsString().getBytes("UTF-8"));
                            resultMap = parseXml(xml);
                            String returncode = resultMap.get("returncode");
                            if (StringUtils.isNotBlank(returncode) && returncode.equals("0")) {
                                ExtraBill extraBill = extraBillService.selectByPrimaryKey(id);
                                extraBill.setIsSenddj(true);
                                // 两个平台都成功送审之后,订单状态改为服务商审核中
                                if (null != extraBill.getIsSendfpt() && extraBill.getIsSendfpt().equals(true)) {
                                    extraBill.setBillStatus(ComNames.EXTRA_BILL_STATUS_4);
                                }
                                status = transactionManager.getTransaction(def);
                                extraBillService.updateByPrimaryKeySelective(extraBill);
                                transactionManager.commit(status);
                                count_danji++;
                            } else {
                                /**
                                 * 现在是<?xml version='1.0' encoding='utf-8'?><business version='1.0'><head></head><body><returncode>3</returncode><returnmsg>xml解析错误</returnmsg></body></business>
                                 */
                                log.error("推送订单失败_百旺单机", "订单号:" + bill.get("bill_id").toString() + "错误码:" + resultMap.get("returncode") + ", 错误信息:" + resultMap.get("returnmsg") + ", 参数:" + stringBuffer.toString());
                                LogUtil.syslog(sqlSession, "推送订单失败_百旺单机", "订单号:" + bill.get("bill_id").toString() + "错误码:" + resultMap.get("returncode") + ", 错误信息:" + resultMap.get("returnmsg"));
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                            log.error("推送订单失败_百旺单机", "订单号:" + bill.get("bill_id").toString() + "错误信息:" + e.getMessage() + ", 参数:" + stringBuffer.toString());
                            LogUtil.syslog(sqlSession, "推送订单失败_百旺单机", "订单号:" + bill.get("bill_id").toString() + "错误信息:" + e.getMessage());
                            continue;
                        }
                    }
                }
                LogUtil.syslog(sqlSession, "推送订单_百旺", "总共:" + Extrabills.size() + "条,发票通成功:" + count + "条, 单机成功:" + count_danji + "条");
            }
        } catch (Exception e) {
            LogUtil.syslog(sqlSession, "推送订单失败_百旺", "错误信息:" + e.getMessage());
            e.printStackTrace();
        } finally {
            if (status != null && !status.isCompleted()) {
                transactionManager.rollback(status);
            }
        }
    }
}
Also used : DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) HashMap(java.util.HashMap) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) PostMethod(org.apache.commons.httpclient.methods.PostMethod) ExtraBill(com.itrus.portal.db.ExtraBill) ArrayList(java.util.ArrayList) TransactionStatus(org.springframework.transaction.TransactionStatus) UserInfo(com.itrus.portal.db.UserInfo) URI(java.net.URI) OpenBankInfo(com.itrus.portal.db.OpenBankInfo) IdentityCard(com.itrus.portal.db.IdentityCard) NameValuePair(org.apache.commons.httpclient.NameValuePair) FileInputStream(java.io.FileInputStream) ExtraProduct(com.itrus.portal.db.ExtraProduct) BusinessLicense(com.itrus.portal.db.BusinessLicense) HttpClient(org.apache.commons.httpclient.HttpClient) Enterprise(com.itrus.portal.db.Enterprise) Map(java.util.Map) HashMap(java.util.HashMap) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) File(java.io.File) TaxRegisterCert(com.itrus.portal.db.TaxRegisterCert) HttpMethod(org.apache.commons.httpclient.HttpMethod) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Aggregations

BusinessLicense (com.itrus.portal.db.BusinessLicense)43 TaxRegisterCert (com.itrus.portal.db.TaxRegisterCert)30 Enterprise (com.itrus.portal.db.Enterprise)26 OrgCode (com.itrus.portal.db.OrgCode)25 IdentityCard (com.itrus.portal.db.IdentityCard)24 UserInfo (com.itrus.portal.db.UserInfo)21 Agent (com.itrus.portal.db.Agent)20 UserInfoServiceException (com.itrus.portal.exception.UserInfoServiceException)16 HashMap (java.util.HashMap)14 OpenBankInfo (com.itrus.portal.db.OpenBankInfo)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)13 ExtraProduct (com.itrus.portal.db.ExtraProduct)12 Proxy (com.itrus.portal.db.Proxy)11 ExtraBill (com.itrus.portal.db.ExtraBill)10 File (java.io.File)10 Date (java.util.Date)10 ArrayList (java.util.ArrayList)9 TransactionStatus (org.springframework.transaction.TransactionStatus)9 DefaultTransactionDefinition (org.springframework.transaction.support.DefaultTransactionDefinition)9 Product (com.itrus.portal.db.Product)8