Search in sources :

Example 1 with AuditSystemConfig

use of com.itrus.portal.db.AuditSystemConfig 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 2 with AuditSystemConfig

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

the class AuditSystemConfigController method saveUI.

// 添加/更新页面
@RequestMapping(params = "form", produces = "text/html")
public String saveUI(@RequestParam(value = "id", required = false) Long id, @RequestParam(value = "status", required = false) Integer status, Model uiModel) {
    uiModel.addAttribute("status", status);
    if (status == null) {
        status = 1;
    }
    String rt = null;
    try {
        List<AuditSystemConfig> realNameList = auditSystemConfigService.getAuditSystemConfig1(new AuditSystemConfigExample());
        for (AuditSystemConfig realName : realNameList) {
            switch(realName.getType()) {
                case 1:
                    uiModel.addAttribute("realname1", realName);
                    break;
                case 2:
                    uiModel.addAttribute("realname2", realName);
                    String str = realName.getServerCode();
                    String value = str.replaceAll("\"", "&quot;");
                    uiModel.addAttribute("serverCode", value);
                    break;
                default:
                    break;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    switch(status) {
        case 1:
            rt = "auditconfig/create";
            break;
        case 2:
            rt = "auditconfig/create1";
            break;
        default:
            rt = "auditconfig/create";
            break;
    }
    return rt;
/*if (id == null) {
			return "auditconfig/create";
		}
		AuditSystemConfig auditSystemConfig = sqlSession
				.selectOne(
						"com.itrus.portal.db.AuditSystemConfigMapper.selectByPrimaryKey",
						id);
		if (null == auditSystemConfig) {
			return "auditconfig/create";
		} else {
			uiModel.addAttribute("auditSystemConfig", auditSystemConfig);
			return "auditconfig/create";
		}*/
}
Also used : AuditSystemConfig(com.itrus.portal.db.AuditSystemConfig) AuditSystemConfigExample(com.itrus.portal.db.AuditSystemConfigExample) ServiceNullException(com.itrus.portal.exception.ServiceNullException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with AuditSystemConfig

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

the class ReviewServiceImpl method audit.

/**
 * 送审
 *
 * @param bill
 * @return
 * @throws Exception
 */
public boolean audit(Bill bill) throws Exception {
    AuditSystemConfig auditSystemConfig = auditSystemConfigService.getAuditSystemConfig(new AuditSystemConfigExample());
    if (null == auditSystemConfig) {
        // 未配置第三方鉴证信息
        return false;
    }
    String jsonString = submitReviewService.getAuditJsonParam(bill);
    String appsecret = submitReviewService.getProductAppsecret(bill.getProduct());
    String result = RequestUtils.post(auditSystemConfig.getAuditSystemUrl() + ComNames.APIS, jsonString, appsecret);
    // 将返回信息同步至订单状态
    JsonNode respNode = jsonTool.readTree(result);
    if (200 == respNode.get("status").asInt()) {
        String dataId = respNode.get("result").get("dataid").getTextValue();
        // 提交成功
        // 设置为送审中的状态
        bill.setBillStatus(ComNames.BILL_STATUS_10);
        bill.setCheckTime(new Date());
        // 设置送审系统中返回的企业的唯一标识
        bill.setDataId(dataId);
        sqlSession.update("com.itrus.portal.db.BillMapper.updateByPrimaryKey", bill);
        // 添加系统日志
        LogUtil.syslog(sqlSession, "单条送审", "产品ID" + bill.getProduct() + "企业ID:" + bill.getEnterprise());
        return true;
    } else if (201 == respNode.get("status").asInt()) {
        String message = respNode.get("message").getTextValue();
        throw new UserInfoServiceException(message);
    }
    return false;
}
Also used : AuditSystemConfig(com.itrus.portal.db.AuditSystemConfig) AuditSystemConfigExample(com.itrus.portal.db.AuditSystemConfigExample) JsonNode(org.codehaus.jackson.JsonNode) Date(java.util.Date) UserInfoServiceException(com.itrus.portal.exception.UserInfoServiceException)

Example 4 with AuditSystemConfig

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

the class SubmitReviewTask method query.

/**
 * 查询送审
 */
public void query() {
    if (!isRun()) {
        return;
    }
    // 获取第三方鉴证配置信息
    AuditSystemConfig auditSystemConfig = auditSystemConfigService.getAuditSystemConfig(new AuditSystemConfigExample());
    // 未配置第三方鉴证信息、未开启查询送审、未配置查询送审时间间隔,直接返回
    if (null == auditSystemConfig || !auditSystemConfig.getIsQuery() || null == auditSystemConfig.getQueryInterval()) {
        log.debug("未配置第三方鉴证信息、未开启查询送审、未配置查询送审时间间隔--返回");
        return;
    }
    // 上次查询送审时间为空,或者上次查询送审时间大于当前时间,则重新设置上次查询送审时间为当前时间的毫秒数
    if (null == auditSystemConfig.getQueryStartTime() || auditSystemConfig.getQueryStartTime() > System.currentTimeMillis()) {
        auditSystemConfig.setQueryStartTime(System.currentTimeMillis());
        auditSystemConfigService.updateAuditSystemConfig(auditSystemConfig);
    }
    // 判断是否在查询送审的时间间隔内(当前时间小于 上次查询送审时间加上送审时间间隔)
    if (System.currentTimeMillis() < auditSystemConfig.getQueryStartTime() + (auditSystemConfig.getQueryInterval() * 1000)) {
        log.debug("不在查询送审时间内");
        return;
    }
    // 设置本次送审时间
    auditSystemConfig.setQueryStartTime(System.currentTimeMillis());
    auditSystemConfigService.updateAuditSystemConfig(auditSystemConfig);
    // TransactionStatus s = null;
    try {
        // 获取送审中的订单
        Map<Long, List<Bill>> billListMap = submitReviewService.getQueryBill(submitReviewService.getAuditProduct());
        // 根据产品来提交信息
        Product product = null;
        Enterprise ent = null;
        JSONObject jsonMap = null;
        JSONObject data = null;
        BusinessLicense bl = null;
        OrgCode oc = null;
        TaxRegisterCert trc = null;
        IdentityCard ic = null;
        Agent at = null;
        Proxy p = null;
        Product product1 = null;
        Product product2 = null;
        Product product3 = null;
        int count;
        int reject;
        for (Long productId : billListMap.keySet()) {
            List<Bill> billList = billListMap.get(productId);
            product = sqlSession.selectOne("com.itrus.portal.db.ProductMapper.selectByPrimaryKey", productId);
            DigitalCert cert1 = null;
            DigitalCert cert2 = null;
            DigitalCert cert3 = null;
            if (null != product.getIsCombined() && product.getIsCombined() == 1) {
                if (null != product.getCombinedId()) {
                    String[] comb = product.getCombinedId().split(",");
                    product1 = sqlSession.selectOne("com.itrus.portal.db.ProductMapper.selectByPrimaryKey", Long.parseLong(comb[0]));
                    product2 = sqlSession.selectOne("com.itrus.portal.db.ProductMapper.selectByPrimaryKey", Long.parseLong(comb[1]));
                    if (comb.length == 3) {
                        product3 = sqlSession.selectOne("com.itrus.portal.db.ProductMapper.selectByPrimaryKey", Long.parseLong(comb[2]));
                    }
                }
                if (null != product1 && null != product1.getCert()) {
                    // 产品关联的数字证书
                    cert1 = sqlSession.selectOne("com.itrus.portal.db.DigitalCertMapper.selectByPrimaryKey", product1.getCert());
                }
                if (null != product2 && null != product2.getCert()) {
                    // 产品关联的数字证书
                    cert2 = sqlSession.selectOne("com.itrus.portal.db.DigitalCertMapper.selectByPrimaryKey", product2.getCert());
                }
                if (null != product3 && 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());
            count = 0;
            reject = 0;
            for (Bill bill : billList) {
                ent = sqlSession.selectOne("com.itrus.portal.db.EnterpriseMapper.selectByPrimaryKey", bill.getEnterprise());
                if (null == jsonMap) {
                    jsonMap = new JSONObject();
                }
                jsonMap.put("appId", product.getAppId());
                jsonMap.put("appsecret", product.getAppsecret());
                // 待查询的记录id
                jsonMap.put("dataid", bill.getDataId());
                String result = RequestUtils.post(auditSystemConfig.getAuditSystemUrl() + queryUrl, jsonMap.toString(), product.getAppsecret());
                // log.info(result);
                data = JSON.parseObject(result);
                if (data.getInteger("status") != 200) {
                    continue;
                }
                data = data.getJSONObject("result");
                // 将返回信息同步至订单状态
                // 0是未通过,1是通过,2是审核中
                int status = data.getInteger("auditstatus");
                // data.getString("auditmessage");
                if (status == 2 || status == 1003) {
                    continue;
                }
                // DefaultTransactionDefinition def = new
                // DefaultTransactionDefinition();
                // def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
                // s = transactionManager.getTransaction(def);
                String reason = data.getString("auditresult");
                bill.setBillStatus(ComNames.BILL_STATUS_4);
                bill.setCheckTime(new Date(data.getLong("auditdate")));
                bill.setCancelReason(reason);
                bl = businessService.getBusinessByBillId(bill.getId(), null);
                oc = orgCodeService.getOrgCodeByBillId(bill.getId(), null);
                trc = taxCertService.getTaxRegisterCertByBillId(bill.getId(), null);
                ic = identityCardService.getIdentityCardByBillId(bill.getId(), null);
                at = agentService.getAgentByBillId(bill.getId(), null);
                // 默认未审核
                Integer itemStatus = 1;
                JsonNode respNode = jsonTool.readTree(result);
                if (status == 1) {
                    if (respNode.get("source") != null) {
                        ent.setInfo(respNode.get("source").getTextValue().getBytes());
                    }
                    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;
                        }
                    }
                    ent.setAuthenticationLevel(product.getAuthentication());
                    ent.setReviewTime(new Date());
                    // 设置状态
                    itemStatus = 2;
                    count++;
                } else if (status == 0) {
                    // 审核拒绝
                    itemStatus = 3;
                    // 发送短信
                    if (reviewService.sendSmsBySHJJ(bill.getId())) {
                        bill.setIsSms(true);
                        bill.setSendTime(new Date());
                    }
                    reject++;
                }
                // 更新认证项
                if (null != bl) {
                    bl.setItemStatus(itemStatus);
                    reviewService.saveBl(bl, respNode.get("source"));
                    ent.setHasBl(bl.getId());
                    if (status == 1 && respNode.get("source") == null) {
                        // 通过 无值
                        String pid = systemConfigService.getReviewProjectId();
                        if (null != pid && Long.valueOf(pid) == bill.getProject()) {
                            // 用友
                            bill.setBillStatus(ComNames.BILL_STATUS_10);
                            LogUtil.syslog(this.sqlSession, "查询送审", "错误:" + bill.getBillId() + respNode.toString());
                        }
                    }
                }
                if (null != oc) {
                    oc.setItemStatus(itemStatus);
                    sqlSession.update("com.itrus.portal.db.OrgCodeMapper.updateByPrimaryKeySelective", oc);
                    ent.setHasOrgCode(oc.getId());
                }
                if (null != trc) {
                    trc.setItemStatus(itemStatus);
                    sqlSession.update("com.itrus.portal.db.TaxRegisterCertMapper.updateByPrimaryKeySelective", trc);
                    ent.setHasTaxCert(trc.getId());
                }
                if (null != ic) {
                    ic.setItemStatus(itemStatus);
                    sqlSession.update("com.itrus.portal.db.IdentityCardMapper.updateByPrimaryKeySelective", ic);
                    ent.setHasIdCard(ic.getId());
                }
                if (null != at) {
                    at.setItemStatus(itemStatus);
                    sqlSession.update("com.itrus.portal.db.AgentMapper.updateByPrimaryKeySelective", at);
                    ent.setHasAgent(at.getId());
                }
                // 更新企业
                sqlSession.update("com.itrus.portal.db.EnterpriseMapper.updateByPrimaryKeyWithBLOBs", ent);
                p = proxyService.getProxyByBillId(bill.getId());
                if (p != null) {
                    p.setItemStatus(2);
                    sqlSession.update("com.itrus.portal.db.ProxyMapper.updateByPrimaryKeySelective", p);
                }
                sqlSession.update("com.itrus.portal.db.BillMapper.updateByPrimaryKeySelective", bill);
                reviewLogService.saveReviewLog(1, null, status == 1 ? 1 : 2, reason, ent.getId(), 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());
            // transactionManager.commit(s);
            }
            LogUtil.syslog(sqlSession, "批量查询送审结果", "产品名称:" + product.getName() + ",订单" + billList.size() + "条,审核通过" + count + "条,审核拒绝" + reject + "条");
        }
        log.debug("查询送审结果结束");
    } catch (Exception e) {
        log.error("ERRORLOG查询送审 {}", e.getMessage());
        e.printStackTrace();
        return;
    }
// finally{
// if (s != null && !s.isCompleted()) {
// transactionManager.rollback(s);
// }
// }
}
Also used : Agent(com.itrus.portal.db.Agent) 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) UnknownHostException(java.net.UnknownHostException) OrgCode(com.itrus.portal.db.OrgCode) DigitalCert(com.itrus.portal.db.DigitalCert) BusinessLicense(com.itrus.portal.db.BusinessLicense) Proxy(com.itrus.portal.db.Proxy) JSONObject(com.alibaba.fastjson.JSONObject) Enterprise(com.itrus.portal.db.Enterprise) Bill(com.itrus.portal.db.Bill) List(java.util.List) TaxRegisterCert(com.itrus.portal.db.TaxRegisterCert) IdentityCard(com.itrus.portal.db.IdentityCard)

Example 5 with AuditSystemConfig

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

the class SubmitReviewTask method audit.

/**
 * 送审
 */
public synchronized void audit() {
    // start------------处理双机互斥----------
    // 系统是否配置同步任务的主机名
    SysConfig sysConfigHost = sqlSession.selectOne("com.itrus.portal.db.SysConfigMapper.selectByType", "raInfoHost");
    if (null == sysConfigHost) {
        // 没有配置,直接返回
        return;
    }
    String host = sysConfigHost.getConfig();
    host = host.replaceAll(" ", "");
    String[] hosts = host.split(",");
    // 获取本机主机名称
    InetAddress ia = null;
    try {
        ia = ia.getLocalHost();
    } catch (UnknownHostException e1) {
        e1.printStackTrace();
        return;
    }
    String hostName = ia.getHostName();
    boolean flag = false;
    for (String str : hosts) {
        if (hostName.equals(str.replaceAll(" ", ""))) {
            flag = true;
        }
    }
    // 判断本地主机名称是否与系统配置的同步主机名称一致,不一致则返回
    if (!flag) {
        // LogUtil.syslog(sqlSession, type, info);
        return;
    }
    // end------------处理双机互斥----------
    // 获取第三方鉴证配置信息
    AuditSystemConfig auditSystemConfig = auditSystemConfigService.getAuditSystemConfig(new AuditSystemConfigExample());
    // 未配置第三方鉴证信息、未开启送审、未配置送审时间间隔,直接返回
    if (null == auditSystemConfig || !auditSystemConfig.getIsAudit() || null == auditSystemConfig.getAuditInterval()) {
        log.debug("未配置第三方鉴证信息、未开启送审、未配置送审时间间隔--返回");
        return;
    }
    // 上次送审时间为空,或者上次送审时间大于当前时间,则重新设置上次送审时间为当前时间的毫秒数
    if (null == auditSystemConfig.getAudiStartTime() || auditSystemConfig.getAudiStartTime() > System.currentTimeMillis()) {
        auditSystemConfig.setAudiStartTime(System.currentTimeMillis());
        auditSystemConfigService.updateAuditSystemConfig(auditSystemConfig);
    }
    // 判断是否在送审的时间间隔内(当前时间小于 上次送审时间加上送审时间间隔)
    if (System.currentTimeMillis() < auditSystemConfig.getAudiStartTime() + (auditSystemConfig.getAuditInterval() * 1000)) {
        log.debug("不在送审时间内");
        return;
    }
    log.debug("送审任务开始--");
    // 设置本次送审时间
    auditSystemConfig.setAudiStartTime(System.currentTimeMillis());
    auditSystemConfigService.updateAuditSystemConfig(auditSystemConfig);
    try {
        // 获取需要送审的订单
        Map<Long, List<Bill>> billListMap = submitReviewService.getAuditBill(submitReviewService.getAuditProduct());
        if (billListMap.isEmpty() || billListMap.size() == 0) {
            // 没有需要送审的订单
            return;
        }
        // 根据产品来批量提交企业的认证信息
        for (Long productId : billListMap.keySet()) {
            // 发送给送审系统的json数据
            List<Bill> billList = billListMap.get(productId);
            String jsonString = submitReviewService.getAuditJsonParams(billList);
            String appsecret = submitReviewService.getProductAppsecret(productId);
            String result = RequestUtils.post(auditSystemConfig.getAuditSystemUrl() + auditUrl, jsonString, appsecret);
            // 将返回信息同步至订单状态
            JsonNode respNode = jsonTool.readTree(result);
            for (int i = 0; i < respNode.size(); i++) {
                if (200 == respNode.get(i).get("status").asInt()) {
                    String dataId = respNode.get(i).get("result").get("dataid").toString();
                    if (dataId.indexOf("\"") == 0)
                        // 去掉第一个
                        dataId = dataId.substring(1, dataId.length());
                    if (dataId.lastIndexOf("\"") == (dataId.length() - 1))
                        // 去掉最后一个
                        dataId = dataId.substring(0, dataId.length() - 1);
                    // 提交成功
                    Bill bill = billList.get(i);
                    // 设置为送审中的状态
                    bill.setBillStatus(ComNames.BILL_STATUS_10);
                    // 设置送审系统中返回的企业的唯一标识
                    bill.setDataId(dataId);
                    sqlSession.update("com.itrus.portal.db.BillMapper.updateByPrimaryKey", bill);
                }
            }
            Product product = sqlSession.selectOne("com.itrus.portal.db.ProductMapper.selectByPrimaryKey", productId);
            LogUtil.syslog(sqlSession, "批量送审", "产品名称" + product.getName() + ",订单" + billList.size() + "条");
            log.debug("送审结束");
        }
    } catch (Exception e) {
        log.error("ERRORLOG送审 {}", e.getMessage());
        e.printStackTrace();
        return;
    }
}
Also used : SysConfig(com.itrus.portal.db.SysConfig) UnknownHostException(java.net.UnknownHostException) AuditSystemConfig(com.itrus.portal.db.AuditSystemConfig) AuditSystemConfigExample(com.itrus.portal.db.AuditSystemConfigExample) Product(com.itrus.portal.db.Product) JsonNode(org.codehaus.jackson.JsonNode) UnknownHostException(java.net.UnknownHostException) Bill(com.itrus.portal.db.Bill) List(java.util.List) InetAddress(java.net.InetAddress)

Aggregations

AuditSystemConfig (com.itrus.portal.db.AuditSystemConfig)5 AuditSystemConfigExample (com.itrus.portal.db.AuditSystemConfigExample)5 JsonNode (org.codehaus.jackson.JsonNode)4 Product (com.itrus.portal.db.Product)3 Date (java.util.Date)3 JSONObject (com.alibaba.fastjson.JSONObject)2 Agent (com.itrus.portal.db.Agent)2 Bill (com.itrus.portal.db.Bill)2 BusinessLicense (com.itrus.portal.db.BusinessLicense)2 DigitalCert (com.itrus.portal.db.DigitalCert)2 Enterprise (com.itrus.portal.db.Enterprise)2 IdentityCard (com.itrus.portal.db.IdentityCard)2 OrgCode (com.itrus.portal.db.OrgCode)2 Proxy (com.itrus.portal.db.Proxy)2 TaxRegisterCert (com.itrus.portal.db.TaxRegisterCert)2 UserInfoServiceException (com.itrus.portal.exception.UserInfoServiceException)2 UnknownHostException (java.net.UnknownHostException)2 List (java.util.List)2 SysConfig (com.itrus.portal.db.SysConfig)1 ServiceNullException (com.itrus.portal.exception.ServiceNullException)1