Search in sources :

Example 61 with Bill

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

the class MakeCertController method makecert.

// 制作证书
@RequestMapping(value = "/make/{id}", produces = "text/html")
@ResponseBody
public Map<String, Object> makecert(@RequestParam(value = "uidIdx", required = true) Integer uidIdx, @RequestParam(value = "csr", required = true) String csr, @RequestParam(value = "pid", required = true) Long pid, @RequestParam(value = "index", required = false) Integer index, @RequestParam(value = "keySn", required = false) String keySn, @PathVariable("id") Long id) {
    Map<String, Object> ret = new HashMap<String, Object>();
    // 查询订单
    Bill bill = sqlSession.selectOne("com.itrus.portal.db.BillMapper.selectByPrimaryKey", id);
    // 查询项目产品
    Product product = sqlSession.selectOne("com.itrus.portal.db.ProductMapper.selectByPrimaryKey", pid);
    // 解析项目产品中,certinfo配置信息
    JSONArray certinfo = JSONArray.parseArray(product.getCertinfo());
    // 解析订单中uid信息{"ADDTIONAL_FIELD1_1":"","ADDTIONAL_FIELD3_1":"","ADDTIONAL_FIELD4_1":"G2016071301","inputName":"inputValue"}
    JSONObject uid = JSONObject.parseObject(bill.getUid());
    if (null != index) {
        if (index == 1) {
            uid = JSONObject.parseObject(bill.getUid1());
        }
        if (index == 2) {
            uid = JSONObject.parseObject(bill.getUid2());
        }
        if (index == 3) {
            uid = JSONObject.parseObject(bill.getUid3());
        }
    }
    // 获取产品、RA配置
    RaAccount ra = sqlSession.selectOne("com.itrus.portal.db.RaAccountMapper.selectByPrimaryKey", product.getRa());
    com.itrus.portal.utils.CertUtlis certutil = new com.itrus.portal.utils.CertUtlis();
    // 证书配置
    DigitalCert digitalcert = sqlSession.selectOne("com.itrus.portal.db.DigitalCertMapper.selectByPrimaryKey", product.getCert());
    // 组织RA参数
    cn.topca.tca.ra.service.UserInfo rauserinfo = new cn.topca.tca.ra.service.UserInfo();
    UIDInfoUtils uidutils = new UIDInfoUtils();
    uidutils.initService(businessService, orgCodeService, taxCertService, identityCardService, userInfoService, enterpriseService);
    String autoidType = "";
    Integer autoidValue = 0;
    for (int i = 0; i < certinfo.size(); i++) {
        JSONObject obj = certinfo.getJSONObject(i);
        String raParaName = obj.getString("raParaName");
        if (raParaName == null)
            continue;
        // "autoid":"yes",
        String autoid = obj.getString("autoid");
        // "raParaName": "userName",
        String constValue = obj.getString("constValue");
        // "constValue": "test@itrus.com.cn"
        String refName = obj.getString("refName");
        String val = null;
        if (constValue != null) {
            val = constValue;
        } else if (refName != null) {
            if (refName.indexOf("?") == -1)
                val = uidutils.getUidInfo(bill.getId(), refName);
            else {
                val = "";
                String[] arr = refName.split("\\?", 2);
                if (arr.length == 2) {
                    String condition = arr[0].trim();
                    String[] refarr = arr[1].split(":", 2);
                    if (refarr.length == 2) {
                        boolean bret = uidutils.checkCondition(bill.getId(), condition);
                        if (bret)
                            val = uidutils.getUidInfo(bill.getId(), refarr[0].trim());
                        else
                            val = uidutils.getUidInfo(bill.getId(), refarr[1].trim());
                    }
                }
            }
        } else if (autoid != null) {
            // "autoidPrev":"G",
            String autoidPrev = obj.getString("autoidPrev");
            // "autoidType":"mytestautoid",
            autoidType = obj.getString("autoidType");
            // "inputName": "ADDTIONAL_FIELD4",存在多个值
            String uidval = uid.getString(obj.getString("inputName") + "_" + uidIdx.toString());
            val = uidval;
            if (StringUtils.isNotBlank(uidval) && uidval.indexOf(autoidPrev) == 0) {
                // "autoidPrevDate":"yyyyMMdd",
                String autoidPrevDate = obj.getString("autoidPrevDate");
                try {
                    if (autoidPrevDate == null || autoidPrevDate.length() == 0)
                        autoidValue = Integer.parseInt(uidval.substring(autoidPrev.length()));
                    else
                        autoidValue = Integer.parseInt(uidval.substring(autoidPrev.length() + autoidPrevDate.length()));
                } catch (Exception e) {
                    e.printStackTrace();
                    autoidValue = 0;
                }
            }
        } else {
            val = uid.getString(obj.getString("inputName") + "_" + uidIdx.toString());
        }
        certutil.setUserInfoVal(rauserinfo, raParaName, val);
    }
    // 证书有效期
    // {"0":"1年","1":"2年","2":"3年","3":"5年","4":"10年"})
    Integer certValidity = 5;
    boolean hasProductSpec = false;
    // 判断订单中是否配了产品规格且有期限
    ProductSpec productSpec = null;
    if (null != bill.getProductSpec() && 0 != bill.getProductSpec()) {
        productSpec = productSpecService.getProductSpec(bill.getProductSpec());
        if (StringUtils.isNotBlank(productSpec.getProductValid())) {
            hasProductSpec = true;
        }
    }
    if (null != index) {
        if (index == 1)
            if (null != bill.getProductSpec1() && 0 != bill.getProductSpec1()) {
                productSpec = productSpecService.getProductSpec(bill.getProductSpec1());
                if (StringUtils.isNotBlank(productSpec.getProductValid())) {
                    hasProductSpec = true;
                }
            }
        if (index == 2)
            if (null != bill.getProductSpec2() && 0 != bill.getProductSpec2()) {
                productSpec = productSpecService.getProductSpec(bill.getProductSpec2());
                if (StringUtils.isNotBlank(productSpec.getProductValid())) {
                    hasProductSpec = true;
                }
            }
        if (index == 3)
            if (null != bill.getProductSpec3() && 0 != bill.getProductSpec3()) {
                productSpec = productSpecService.getProductSpec(bill.getProductSpec3());
                if (StringUtils.isNotBlank(productSpec.getProductValid())) {
                    hasProductSpec = true;
                }
            }
    }
    if (hasProductSpec) {
        Integer day = Integer.parseInt(productSpec.getProductValid());
        if (day == 100) {
            // TODO 测试时候,配置年限为100年,则有效期为10天
            certValidity = 1;
        } else {
            certValidity = 365 * day + 1 + (day / 4);
        }
    } else {
        if ("0".compareTo(digitalcert.getCertDeadline()) == 0) {
            certValidity = 365 * 1 + 1;
        } else if ("1".compareTo(digitalcert.getCertDeadline()) == 0) {
            certValidity = 365 * 2 + 1;
        } else if ("2".compareTo(digitalcert.getCertDeadline()) == 0) {
            certValidity = 365 * 3 + 1;
        } else if ("3".compareTo(digitalcert.getCertDeadline()) == 0) {
            certValidity = 365 * 5 + 2;
        } else if ("4".compareTo(digitalcert.getCertDeadline()) == 0) {
            certValidity = 365 * 10 + 2;
        } else if ("-1".compareTo(digitalcert.getCertDeadline()) == 0) {
            // 数字证书没有配置年限(-1),默认10天有效期
            certValidity = 10;
        }
    }
    log.error("证书期限*********" + certValidity);
    // 调用RA
    CertInfo racertinfo = null;
    try {
        if (ra.getAaPassword() != null)
            ra.setAaPassword(AESencrp.decrypt(ra.getAaPassword(), dbEncKey));
        racertinfo = certutil.enrollCertByWS(csr, ra, rauserinfo, certValidity);
    } catch (RaServiceUnavailable_Exception e) {
        e.printStackTrace();
        ret.put("status", 1001);
        ret.put("message", e.getMessage());
        // 记录日志
        String oper = "制作证书失败";
        String info = "企业名称: " + uidutils.getUidInfo(bill.getId(), "enterprise.enterpriseName") + ",参数:" + ToStringBuilder.reflectionToString(rauserinfo) + ",异常信息: " + e.toString();
        LogUtil.adminlog(sqlSession, oper, info);
        return ret;
    } catch (Exception e) {
        e.printStackTrace();
        ret.put("status", 1002);
        ret.put("message", e.getMessage());
        // 记录日志
        String oper = "制作证书失败";
        String info = "企业名称: " + uidutils.getUidInfo(bill.getId(), "enterprise.enterpriseName") + "参数:" + ToStringBuilder.reflectionToString(rauserinfo) + ",异常信息: " + e.toString();
        LogUtil.adminlog(sqlSession, oper, info);
        return ret;
    }
    // 解析数字证书信息
    // 存储数字证书信息
    CertBuf certbuf = new CertBuf();
    certbuf.setCreateTime(new Date());
    certbuf.setCertBuf(racertinfo.getCertSignBuf());
    certbuf.setCertKmcRep1(racertinfo.getCertKmcRep1());
    certbuf.setCertKmcRep2(racertinfo.getCertKmcRep2());
    certbuf.setCertsignBuf(racertinfo.getCertSignBuf());
    certbuf.setEncUserCert(racertinfo.getCertSignBufKmc());
    sqlSession.insert("com.itrus.portal.db.CertBufMapper.insert", certbuf);
    UserCert usercert = new UserCert();
    usercert.setBill(bill.getId());
    usercert.setRaAccount(ra.getId());
    usercert.setCertBuf(certbuf.getId());
    usercert.setUidIdx(uidIdx);
    usercert.setCertDn(racertinfo.getCertSubjectDn());
    usercert.setCertSn(racertinfo.getCertSerialNumber());
    usercert.setIssuerDn(racertinfo.getCertIssuerDn());
    usercert.setCertStatus("1");
    usercert.setCertUid("certUid");
    usercert.setProduct(pid);
    if (StringUtils.isNotBlank(keySn))
        // 设置证书keySn
        usercert.setKeySn(keySn);
    try {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmss");
        usercert.setCertStartTime(sdf.parse(racertinfo.getCertNotBefore()));
        usercert.setCertEndTime(sdf.parse(racertinfo.getCertNotAfter()));
    } catch (java.text.ParseException e) {
        e.printStackTrace();
    }
    usercert.setSha1Fingerprint("setSha1Fingerprint");
    // autoid 数据
    if (!autoidType.equals("")) {
        usercert.setAutoidType(autoidType);
        usercert.setAutoidValue(autoidValue);
    }
    usercert.setEnterprise(bill.getEnterprise());
    try {
        sqlSession.insert("com.itrus.portal.db.UserCertMapper.insert", usercert);
    } catch (Exception e) {
        e.printStackTrace();
    }
    // 查询userCert中,该bill的记录数目,如果数据 大于等于 bill 里面的购买数量,则修改该bill为制证完成
    updateBillStatus(bill, product);
    // 记录日志
    String oper = "制作证书";
    String info = "数字证书: " + racertinfo.getCertSerialNumber() + ", " + racertinfo.getCertSubjectDn();
    LogUtil.adminlog(sqlSession, oper, info);
    // 返回数字证书
    ret.put("certChain", racertinfo.getCertSignBufP7());
    ret.put("certsignBuf", racertinfo.getCertSignBuf());
    ret.put("certKmcRep1", racertinfo.getCertKmcRep1());
    ret.put("certKmcRep2", racertinfo.getCertKmcRep2());
    // 加密证书
    ret.put("encUserCert", racertinfo.getCertSignBufKmc());
    ret.put("status", 0);
    return ret;
}
Also used : CertInfo(cn.topca.tca.ra.service.CertInfo) RaServiceUnavailable_Exception(cn.topca.tca.ra.service.RaServiceUnavailable_Exception) HashMap(java.util.HashMap) Product(com.itrus.portal.db.Product) UserInfo(com.itrus.portal.db.UserInfo) UIDInfoUtils(com.itrus.portal.utils.UIDInfoUtils) DigitalCert(com.itrus.portal.db.DigitalCert) RaAccount(com.itrus.portal.db.RaAccount) CertBuf(com.itrus.portal.db.CertBuf) UserCert(com.itrus.portal.db.UserCert) JSONArray(com.alibaba.fastjson.JSONArray) ProductSpec(com.itrus.portal.db.ProductSpec) EncDecException(com.itrus.portal.exception.EncDecException) IOException(java.io.IOException) RaServiceUnavailable_Exception(cn.topca.tca.ra.service.RaServiceUnavailable_Exception) Date(java.util.Date) BigInteger(java.math.BigInteger) JSONObject(com.alibaba.fastjson.JSONObject) Bill(com.itrus.portal.db.Bill) JSONObject(com.alibaba.fastjson.JSONObject) SimpleDateFormat(java.text.SimpleDateFormat) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 62 with Bill

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

the class BillServiceImpl method getProjectMapByBills.

/**
 * 根据订单list查找出对应的projectMap
 *
 * @param bills
 * @return
 */
public Map<Long, Project> getProjectMapByBills(List<Bill> bills) {
    Map<Long, Project> projectMap = new HashMap<Long, Project>();
    List<Long> projectIds = new ArrayList<Long>();
    for (Bill bill : bills) {
        projectIds.add(bill.getProject());
    }
    if (!projectIds.isEmpty()) {
        ProjectExample projectExample = new ProjectExample();
        ProjectExample.Criteria criteria = projectExample.or();
        criteria.andIdIn(projectIds);
        projectMap = sqlSession.selectMap("com.itrus.portal.db.ProjectMapper.selectByExample", projectExample, "id");
    }
    return projectMap;
}
Also used : Project(com.itrus.portal.db.Project) HashMap(java.util.HashMap) ProjectExample(com.itrus.portal.db.ProjectExample) ArrayList(java.util.ArrayList) Bill(com.itrus.portal.db.Bill)

Example 63 with Bill

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

the class BillServiceImpl method getBillByBillId.

/**
 * 根据用户证书id,获取对应的解锁订单,只获取最新的一张
 * @param billId
 * @return
 */
public Bill getBillByBillId(String billId) {
    Bill bill = null;
    BillExample example = new BillExample();
    example.or().andBillIdEqualTo(billId);
    example.setLimit(1);
    example.setOrderByClause("create_time desc");
    bill = sqlSession.selectOne("com.itrus.portal.db.BillMapper.selectByExample", example);
    return bill;
}
Also used : BillExample(com.itrus.portal.db.BillExample) Bill(com.itrus.portal.db.Bill)

Example 64 with Bill

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

the class BillServiceImpl method saveBillCombined.

// 创建待支付组合产品订单
public Bill saveBillCombined(Long uniqueId, Long enterprise, Long product, Long product1, Long product2, Long product3, Long productSpec1, Long productSpec2, Long productSpec3, Long delivery, Long invoice, Long einvoice, String uid1, String uid2, String uid3, Long project, Integer productNum1, Integer productNum2, Integer productNum3, double price1, double price2, double price3, double billSum, Long creator, Integer billStatus) {
    Bill bill = new Bill();
    bill.setCreateTime(new Date());
    // 订单编号
    bill.setBillId(UniqueIDUtils.genBilUID(sqlSession));
    // 关联用户
    bill.setUniqueId(uniqueId);
    // 关联企业
    bill.setEnterprise(enterprise);
    // 产品
    bill.setProduct(product);
    if (null != product1) {
        // 产品1
        bill.setProduct1(product1);
        bill.setProductSpec1(productSpec1);
        bill.setUid1(uid1);
        bill.setProductNum1(productNum1);
        bill.setPrice1(price1);
    }
    if (null != product2) {
        // 产品2
        bill.setProduct2(product2);
        bill.setProductSpec2(productSpec2);
        bill.setUid2(uid2);
        bill.setProductNum2(productNum2);
        bill.setPrice2(price2);
    }
    if (null != product3) {
        // 产品3
        bill.setProduct3(product3);
        bill.setProductSpec3(productSpec3);
        bill.setUid3(uid3);
        bill.setProductNum3(productNum3);
        bill.setPrice3(price3);
    }
    // 配送id
    bill.setDelivery(delivery);
    // 发票id
    bill.setInvoice(invoice);
    // 电子发票id
    bill.seteInvoice(einvoice);
    bill.setProject(project);
    bill.setProductNum(1);
    bill.setBillSum(billSum);
    // 1:"待支付",2:"待支付确认",3:"已支付,待审核",4:"审核拒绝",5:"已审核,待制证",6:"已制证,待开票",7:"已开票,待配送",8:"已完成
    bill.setBillStatus(billStatus);
    // 未短信通知
    bill.setIsSms(false);
    bill.setCreator(uniqueId);
    bill.setIsDelete(false);
    bill.setUid("{}");
    bill.setUid0("{}");
    sqlSession.insert("com.itrus.portal.db.BillMapper.insert", bill);
    sqlSession.flushStatements();
    return bill;
}
Also used : Bill(com.itrus.portal.db.Bill) Date(java.util.Date)

Example 65 with Bill

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

the class BillServiceImpl method hasAuthticationLevel.

/**
 * 判断该用户,该企业,该项目,已经通过了实名认证
 * @param userInfoId
 * @param enterpriseId
 * @param projectId
 * @return
 */
public List<Bill> hasAuthticationLevel(Long userInfoId, Long enterpriseId, Long projectId) {
    boolean flag = false;
    if (null == userInfoId || null == enterpriseId || null == projectId) {
        return null;
    }
    BillExample billExample = new BillExample();
    BillExample.Criteria criteria = billExample.or();
    criteria.andUniqueIdEqualTo(userInfoId);
    criteria.andEnterpriseEqualTo(enterpriseId);
    criteria.andProjectEqualTo(projectId);
    List<Integer> billStatus = new ArrayList<>();
    billStatus.add(ComNames.BILL_STATUS_5);
    billStatus.add(ComNames.BILL_STATUS_6);
    billStatus.add(ComNames.BILL_STATUS_7);
    billStatus.add(ComNames.BILL_STATUS_8);
    billStatus.add(ComNames.BILL_STATUS_12);
    billStatus.add(ComNames.BILL_STATUS_13);
    criteria.andBillStatusIn(billStatus);
    billExample.setOrderByClause("create_time desc");
    List<Bill> bills = getBillsByExample(billExample);
    return bills;
}
Also used : BillExample(com.itrus.portal.db.BillExample) ArrayList(java.util.ArrayList) Bill(com.itrus.portal.db.Bill)

Aggregations

Bill (com.itrus.portal.db.Bill)74 HashMap (java.util.HashMap)45 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)42 Product (com.itrus.portal.db.Product)39 UserInfo (com.itrus.portal.db.UserInfo)32 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)27 Enterprise (com.itrus.portal.db.Enterprise)26 UserCert (com.itrus.portal.db.UserCert)22 JSONObject (com.alibaba.fastjson.JSONObject)21 Date (java.util.Date)20 ArrayList (java.util.ArrayList)19 BillExample (com.itrus.portal.db.BillExample)18 IOException (java.io.IOException)18 UserInfoServiceException (com.itrus.portal.exception.UserInfoServiceException)16 DigitalCert (com.itrus.portal.db.DigitalCert)15 Map (java.util.Map)12 TransactionStatus (org.springframework.transaction.TransactionStatus)10 DefaultTransactionDefinition (org.springframework.transaction.support.DefaultTransactionDefinition)10 OnPayInfo (com.itrus.portal.db.OnPayInfo)9 Proxy (com.itrus.portal.db.Proxy)9