Search in sources :

Example 16 with OrgCode

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

the class BillWebController method loadImg.

/**
 * 得到图片
 *
 * @param type
 * @param id
 * @param num
 * @param response
 * @return
 */
@RequestMapping(value = "/img/{type}/{id}/{num}/{eid}")
public String loadImg(@PathVariable("type") int type, @PathVariable("id") Long id, @PathVariable("num") Long num, @PathVariable("eid") Long eid, HttpServletResponse response, HttpServletRequest request) {
    HttpSession session = request.getSession();
    Boolean verifyCodeStatus = (Boolean) session.getAttribute("webverifyCodeStatus");
    UserInfo webuserInfo = (UserInfo) session.getAttribute("webuserInfo");
    Enterprise enterprise = (Enterprise) session.getAttribute("webenterprise");
    if (null == verifyCodeStatus || !verifyCodeStatus || null == webuserInfo || !eid.equals(enterprise.getId())) {
        // 登录状态失效,跳转到登录页面
        return "redirect:/userInfoWeb/denglu.html";
    }
    String img = null;
    Long trueInfo = null;
    Long userid = null;
    UserInfo userInfo = null;
    OutputStream os = null;
    FileInputStream fis = null;
    try {
        response.setHeader("Pragma", "no-cache");
        response.setHeader("Cache-Control", "no-cache");
        response.setDateHeader("Expires", 0);
        if (type == 1) {
            BusinessLicenseExample bl = new BusinessLicenseExample();
            BusinessLicenseExample.Criteria criteria = bl.createCriteria();
            criteria.andIdEqualTo(id);
            BusinessLicense license = sqlSession.selectOne("com.itrus.portal.db.BusinessLicenseMapper.selectByExample", bl);
            if (license == null) {
                return "status403";
            }
            img = license.getImgFile();
            trueInfo = license.getEnterprise();
        } else if (type == 2) {
            OrgCodeExample bl = new OrgCodeExample();
            OrgCodeExample.Criteria criteria = bl.createCriteria();
            criteria.andIdEqualTo(id);
            OrgCode code = sqlSession.selectOne("com.itrus.portal.db.OrgCodeMapper.selectByExample", bl);
            if (code == null) {
                return "status403";
            }
            img = code.getImgFile();
            trueInfo = code.getEnterprise();
        } else if (type == 3) {
            TaxRegisterCertExample bl = new TaxRegisterCertExample();
            TaxRegisterCertExample.Criteria criteria = bl.createCriteria();
            criteria.andIdEqualTo(id);
            TaxRegisterCert cert = sqlSession.selectOne("com.itrus.portal.db.TaxRegisterCertMapper.selectByExample", bl);
            if (cert == null) {
                return "status403";
            }
            img = cert.getImgFile();
            trueInfo = cert.getEnterprise();
        } else if (type == 4) {
            IdentityCardExample bl = new IdentityCardExample();
            IdentityCardExample.Criteria criteria = bl.createCriteria();
            criteria.andIdEqualTo(id);
            IdentityCard card = sqlSession.selectOne("com.itrus.portal.db.IdentityCardMapper.selectByExample", bl);
            if (card == null) {
                return "status403";
            }
            if (num == 0) {
                img = card.getFrontImg();
            } else {
                img = card.getBackImg();
            }
            trueInfo = card.getEnterprise();
        } else if (type == 7) {
            AgentExample bl = new AgentExample();
            AgentExample.Criteria criteria = bl.createCriteria();
            criteria.andIdEqualTo(id);
            Agent at = sqlSession.selectOne("com.itrus.portal.db.AgentMapper.selectByExample", bl);
            if (at == null) {
                return "status403";
            }
            if (num == 0) {
                img = at.getFrontImg();
            } else {
                img = at.getBackImg();
            }
            trueInfo = at.getEnterprise();
        } else if (type == 5) {
            ProxyExample pe = new ProxyExample();
            ProxyExample.Criteria criteria = pe.createCriteria();
            criteria.andIdEqualTo(id);
            Proxy proxy = sqlSession.selectOne("com.itrus.portal.db.ProxyMapper.selectByExample", pe);
            if (proxy == null) {
                return "status403";
            }
            img = proxy.getImgFile();
            userInfo = sqlSession.selectOne("com.itrus.portal.db.UserInfoMapper.selectByPrimaryKey", proxy.getUserInfo());
            trueInfo = proxy.getEnterprise();
        }
        if (img == null || trueInfo == null) {
            return "status403";
        }
        Enterprise info = sqlSession.selectOne("com.itrus.portal.db.EnterpriseMapper.selectByPrimaryKey", trueInfo);
        File file = new File(systemConfigService.getTrustDir().getPath() + File.separator + (type == 5 ? userInfo.getUniqueId() : info.getEnterpriseSn()));
        if (!file.exists()) {
            file.mkdir();
        }
        File imgFile = new File(file, img);
        fis = new FileInputStream(imgFile);
        byte[] bb = IOUtils.toByteArray(fis);
        os = response.getOutputStream();
        os.write(bb);
        os.flush();
    } catch (IOException e) {
        // 未找到
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        // 关闭流!
        try {
            if (null != fis) {
                fis.close();
            }
            if (null != os) {
                os.close();
            }
        } catch (IOException e) {
        }
    }
    return null;
}
Also used : IdentityCardExample(com.itrus.portal.db.IdentityCardExample) OutputStream(java.io.OutputStream) UserInfo(com.itrus.portal.db.UserInfo) Proxy(com.itrus.portal.db.Proxy) IdentityCard(com.itrus.portal.db.IdentityCard) Agent(com.itrus.portal.db.Agent) AgentExample(com.itrus.portal.db.AgentExample) HttpSession(javax.servlet.http.HttpSession) TaxRegisterCertExample(com.itrus.portal.db.TaxRegisterCertExample) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) EncDecException(com.itrus.portal.exception.EncDecException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) UserInfoServiceException(com.itrus.portal.exception.UserInfoServiceException) BusinessLicenseExample(com.itrus.portal.db.BusinessLicenseExample) ProxyExample(com.itrus.portal.db.ProxyExample) OrgCode(com.itrus.portal.db.OrgCode) BusinessLicense(com.itrus.portal.db.BusinessLicense) Enterprise(com.itrus.portal.db.Enterprise) CopyFile(com.itrus.portal.utils.CopyFile) File(java.io.File) TaxRegisterCert(com.itrus.portal.db.TaxRegisterCert) OrgCodeExample(com.itrus.portal.db.OrgCodeExample) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 17 with OrgCode

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

the class ClientWebController method submitOrder.

// TODO 用户提交订单:确认订单页面,点击去支付
@RequestMapping("/submitOrder")
@ResponseBody
public Map<String, Object> submitOrder(@RequestParam(value = "projectId", required = true) Long projectId, @RequestParam(value = "productId", required = true) Long productId, @RequestParam(value = "productNum", required = true) Integer productNum, @RequestParam(value = "productSpecId", required = true) Long productSpecId, @ModelAttribute("enterprise") Enterprise enterprise, @ModelAttribute("userInfo") UserInfo userInfo, @ModelAttribute("einvoice") Einvoice einvoice, @ModelAttribute("businessLicense") BusinessLicense businessLicense, @ModelAttribute("orgCode") OrgCode orgCode, @ModelAttribute("taxregisterCert") TaxRegisterCert taxregisterCert, @ModelAttribute("agent") Agent agent, @ModelAttribute("openBankInfo") OpenBankInfo openBankInfo, @ModelAttribute("identityCard") IdentityCard identityCard, HttpServletRequest request) {
    Map<String, Object> retMap = new HashMap<String, Object>();
    // 0标识失败,1标识成功
    retMap.put("retCode", 0);
    HttpSession session = request.getSession();
    UserInfo webuserInfo = (UserInfo) session.getAttribute("webuserInfo");
    Enterprise webenterprise = (Enterprise) session.getAttribute("webenterprise");
    if (null == webuserInfo || null == webenterprise) {
        retMap.put("retMsg", "用户登录信息已失效,请重新登录");
        return retMap;
    }
    ExtraProduct product = extraProductService.selectByPrimaryKey(productId);
    if (null == product) {
        retMap.put("retMsg", "产品信息不存在,请重新选择产品");
        return retMap;
    }
    ExtraProductSpec productSpec = extraProductSpecService.selectByPrimaryKey(productSpecId);
    if (null == productSpec || productSpec.getIsValid().equals(false)) {
        retMap.put("retMsg", "规格信息不存在或已经失效,请重新选择规格");
        return retMap;
    }
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    TransactionStatus status = transactionManager.getTransaction(def);
    try {
        // 保存发票信息(填写了发票信息才保存,未填写则不保存)
        if (StringUtils.isNotBlank(einvoice.getName()) && StringUtils.isNotBlank(einvoice.getIdNumber()) && null != einvoice.geteReiceipt())
            einvoice = EinvoiceService.saveEInvoice(webuserInfo.getId(), einvoice);
        // 计算订单价格
        Double billSum = null;
        billSum = productNum * productSpec.getPrice();
        // 生成订单
        ExtraBill bill = extraBillService.saveExtraBill(projectId, webuserInfo.getId(), webenterprise.getId(), productId, productSpecId, null != einvoice.getId() ? einvoice.getId() : null, productNum, billSum, ComNames.EXTRA_BILL_STATUS_1);
        // ""字符串判断,改为Null,避免覆盖数据库中的信息
        if (null != enterprise && StringUtils.isBlank(enterprise.getProvince())) {
            enterprise.setProvince(null);
        }
        if (null != enterprise && StringUtils.isBlank(enterprise.getCity())) {
            enterprise.setCity(null);
        }
        if (null != enterprise && StringUtils.isBlank(enterprise.getShortName())) {
            enterprise.setShortName(null);
        }
        // 更新用户信息和企业信息
        if (null != enterprise && null == enterprise.getId()) {
            enterprise.setId(webenterprise.getId());
        }
        if (null != userInfo && null == userInfo.getId()) {
            userInfo.setId(webuserInfo.getId());
        }
        enterprise = enterpriseService.updateByPrimaryKeySelective(enterprise);
        userInfo = userInfoService.updateByPrimaryKeySelective(userInfo);
        // 获取产品需要的附加信息项
        ExtraMessage extraMessage = extraMessageService.selectByPrimaryKey(product.getExtraMessage());
        // 是否有营业执照信息,默认false没有
        boolean hasBl = false;
        if (null != extraMessage) {
            // //企业信息 认证项(1.企业名称,2.统一社会信用代码/营业执照,3.组织机构代码,4.税务登记号)
            if (StringUtils.isNotBlank(extraMessage.getEnterpriseItems())) {
                if (StringUtils.isNotBlank(extraMessage.getEnterpriseItems())) {
                    if (extraMessage.getEnterpriseItems().contains("1")) {
                    }
                    if (extraMessage.getEnterpriseItems().contains("2") && !webenterprise.getEnterpriseNature().equals(3)) {
                        // 事业单位不填写营业执照
                        hasBl = true;
                        // 需要统一社会信用代码/营业执照实名认证项,但是页面没有传递过来的时候,用老的
                        if (null == businessLicense || !StringUtils.isNotBlank(businessLicense.getImgFile())) {
                            List<BusinessLicense> businessLicenses = businessService.getBusinessLicensesNews(webenterprise.getId());
                            if (null != businessLicenses && !businessLicenses.isEmpty()) {
                                businessLicense = businessLicenses.get(0);
                                businessLicense.setImgFile(null);
                            }
                        }
                        businessLicense = businessService.saveBusinessExtraBill(webenterprise.getId(), webenterprise.getEnterpriseSn(), bill.getId(), webuserInfo.getId(), businessLicense, ComNames.ITEM_STATUS_2, null);
                    }
                    if (extraMessage.getEnterpriseItems().contains("3")) {
                        // 需要统一组织机构代码认证项,但是页面没有传递过来的时候,用老的
                        if (!(hasBl && businessLicense.getBusinessType().equals(// 五证合一企业不用提交组织机构代码、税务登记信息
                        1))) {
                            if (null == orgCode || !StringUtils.isNotBlank(orgCode.getImgFile())) {
                                List<OrgCode> orgCodes = orgCodeService.getOrgCodesNews(webenterprise.getId());
                                if (null != orgCodes && !orgCodes.isEmpty()) {
                                    orgCode = orgCodes.get(0);
                                    orgCode.setImgFile(null);
                                }
                            }
                            orgCode = orgCodeService.saveOrgCodeExtraBill(webenterprise.getId(), webenterprise.getEnterpriseSn(), bill.getId(), webuserInfo.getId(), orgCode, ComNames.ITEM_STATUS_2, null);
                        }
                    }
                    if (extraMessage.getEnterpriseItems().contains("4")) {
                        if (!(hasBl && businessLicense.getBusinessType().equals(// 五证合一企业不用提交组织机构代码、税务登记信息
                        1))) {
                            // 保存税务登记证
                            if (// 事业单位不填写税务登记信息
                            !webenterprise.getEnterpriseNature().equals(3)) {
                                // 需要税务登记实名认证项,但是页面没有传递过来的时候,用老的
                                if (null == taxregisterCert || !StringUtils.isNotBlank(taxregisterCert.getImgFile())) {
                                    List<TaxRegisterCert> taxRegisterCerts = taxCertService.getTaxRegisterCertsNews(webenterprise.getId());
                                    if (null != taxRegisterCerts && !taxRegisterCerts.isEmpty()) {
                                        taxregisterCert = taxRegisterCerts.get(0);
                                        taxregisterCert.setImgFile(null);
                                    }
                                }
                                taxregisterCert = taxCertService.saveTaxCertExtraBill(webenterprise.getId(), webenterprise.getEnterpriseSn(), bill.getId(), webuserInfo.getId(), taxregisterCert, ComNames.ITEM_STATUS_2, null);
                            }
                        }
                    }
                }
            }
            // field string --fieldName agentItems
            if (StringUtils.isNotBlank(extraMessage.getAgentItems())) {
                if (null == agent || StringUtils.isBlank(agent.getFrontImg())) {
                    List<Agent> agents = agentService.getAgentsNews(webenterprise.getId());
                    if (null != agents && !agents.isEmpty()) {
                        agent = agents.get(0);
                        agent.setFrontImg(null);
                        agent.setBackImg(null);
                    }
                }
                agent = agentService.saveAgentExtraBill(webenterprise.getId(), webenterprise.getEnterpriseSn(), bill.getId(), webuserInfo.getId(), agent, ComNames.ITEM_STATUS_2, null);
            }
            // field string --fieldName bankItems
            if (StringUtils.isNotBlank(extraMessage.getBankItems())) {
                if (null == openBankInfo || StringUtils.isBlank(openBankInfo.getBankNumber())) {
                    List<OpenBankInfo> openBankInfos = openBankInfoService.getOpenBankInfosNews(webenterprise.getId());
                    if (null != openBankInfos && !openBankInfos.isEmpty()) {
                        openBankInfo = openBankInfos.get(0);
                    }
                }
                openBankInfo = openBankInfoService.saveOpenBankInfoExtraBill(webenterprise.getId(), bill.getId(), webuserInfo.getId(), openBankInfo, ComNames.ITEM_STATUS_2, null);
            }
            // field string  --fieldName identityCardItems
            if (StringUtils.isNotBlank(extraMessage.getIdentityCardItems())) {
                if (null == identityCard || StringUtils.isBlank(identityCard.getFrontImg())) {
                    List<IdentityCard> identityCards = identityCardService.getIdentityCardsNews(webenterprise.getId());
                    if (null != identityCards && !identityCards.isEmpty()) {
                        identityCard = identityCards.get(0);
                        identityCard.setFrontImg(null);
                        identityCard.setBackImg(null);
                    }
                }
                identityCard = identityCardService.saveIdentityCardExtraBill(webenterprise.getId(), webenterprise.getEnterpriseSn(), bill.getId(), webuserInfo.getId(), identityCard, ComNames.ITEM_STATUS_2, null);
            }
        }
        transactionManager.commit(status);
        retMap.put("retCode", 1);
        retMap.put("billId", bill.getId());
        // 更新session用户和企业信息
        webenterprise = enterpriseService.getEnterpriseById(webenterprise.getId());
        webuserInfo = userInfoService.getUserInfoById(webuserInfo.getId());
        session.setAttribute("webenterprise", webenterprise);
        session.setAttribute("webuserInfo", webuserInfo);
        // 记录日志
        UserLog userlog = new UserLog();
        userlog.setProject(projectId);
        userlog.setType("购买增值产品");
        userlog.setInfo(webuserInfo.getmPhone() + "购买了" + product.getAppName());
        userlog.setHostId("未知");
        userlog.setSn(null == webuserInfo.getUniqueId() ? null : webuserInfo.getUniqueId());
        LogUtil.userlog(sqlSession, userlog);
        return retMap;
    } catch (UserInfoServiceException e) {
        if (!status.isCompleted()) {
            transactionManager.rollback(status);
        }
        retMap.put("retMsg", e.getMessage());
        return retMap;
    } catch (Exception e) {
        if (!status.isCompleted()) {
            transactionManager.rollback(status);
        }
        UserLog userlog = new UserLog();
        userlog.setProject(projectId);
        userlog.setType("购买增值产品");
        userlog.setInfo("url:submitOrder,详细错误:" + e.getMessage());
        userlog.setHostId("未知");
        userlog.setSn(null == webuserInfo.getUniqueId() ? null : webuserInfo.getUniqueId());
        LogUtil.userlog(sqlSession, userlog);
        retMap.put("retMsg", "服务端出现未知错误,请联系管理员");
        return retMap;
    } finally {
        if (!status.isCompleted()) {
            transactionManager.rollback(status);
        }
    }
}
Also used : DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) HashMap(java.util.HashMap) ExtraBill(com.itrus.portal.db.ExtraBill) TransactionStatus(org.springframework.transaction.TransactionStatus) UserInfo(com.itrus.portal.db.UserInfo) OpenBankInfo(com.itrus.portal.db.OpenBankInfo) IdentityCard(com.itrus.portal.db.IdentityCard) Agent(com.itrus.portal.db.Agent) HttpSession(javax.servlet.http.HttpSession) ExtraProductSpec(com.itrus.portal.db.ExtraProductSpec) UserLog(com.itrus.portal.db.UserLog) UserInfoServiceException(com.itrus.portal.exception.UserInfoServiceException) IOException(java.io.IOException) UserInfoServiceException(com.itrus.portal.exception.UserInfoServiceException) ExtraProduct(com.itrus.portal.db.ExtraProduct) OrgCode(com.itrus.portal.db.OrgCode) BusinessLicense(com.itrus.portal.db.BusinessLicense) Enterprise(com.itrus.portal.db.Enterprise) UserinfoEnterprise(com.itrus.portal.db.UserinfoEnterprise) ExtraMessage(com.itrus.portal.db.ExtraMessage) TaxRegisterCert(com.itrus.portal.db.TaxRegisterCert) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 18 with OrgCode

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

the class APIService method entAuth.

/**
 * 提交企业认证申请
 *
 * @param authHmac
 *            hmac签名值,采用HmacSHA1算法
 * @param appId
 *            应用标识
 * @param productId
 *            项目产品标识
 * @param orderNumber
 *            申请流水号,审核拒绝修改提交时必填 (创建申请为空,修改申请不为空)
 * @param enterpriseType
 *            企业类型 1.企业,2.个体工商户,3.事业单位/政府机关
 * @param isThreeInOne
 *            是否三证合一
 * @param enterpriseName
 *            企业名称,事业单位名称
 * @param licenseNo
 *            营业执照注册号或统一社会信用代码,事业单位法人证书编号
 * @param orgCode
 *            组织机构代码(三证合一时非必填)
 * @param taxNo
 *            税务登记证号码(三证合一时非必填,或根据业务需要选填)
 * @param legalName
 *            法定代表人姓名(根据业务需要选填)
 * @param legalCardType
 *            证件类型(1代表身份证,2护照,3其他)
 * @param legalIdCardNo
 *            证件号码
 * @param agentName
 *            代理人姓名
 * @param agentPhone
 *            代理人手机号
 * @param agentEmail
 *            代理人邮箱
 * @param agentTelephone
 *            代理人固定电话(非必填)
 * @param agentCardType
 *            证件类型(1代表身份证,2护照,3其他)
 * @param agentIdCardNo
 *            证件号码
 * @return status 1: 表示处理正常, billId: 订单编号, orderNumber: 申请流水号 status 0:
 *         表示处理失败, message: 失败原因
 */
@PostMapping(value = "/auth/entAuth")
@ResponseBody
public Map<String, Object> entAuth(@RequestHeader("Content-Signature") String authHmac, @RequestParam(value = "appId", required = true) String appId, @RequestParam(value = "productId", required = true) String productId, @RequestParam(value = "orderNumber", required = false) String orderNumber, @RequestParam(value = "enterpriseType", required = false) String enterpriseType, @RequestParam(value = "isThreeInOne", required = true) boolean isThreeInOne, @RequestParam(value = "enterpriseName", required = false) String enterpriseName, @RequestParam(value = "licenseNo", required = false) String licenseNo, @RequestParam(value = "orgCode", required = false) String orgCode, @RequestParam(value = "taxNo", required = false) String taxNo, @RequestParam(value = "legalName", required = false) String legalName, @RequestParam(value = "legalCardType", required = false) Integer legalCardType, @RequestParam(value = "legalIdCardNo", required = false) String legalIdCardNo, @RequestParam(value = "agentName", required = false) String agentName, @RequestParam(value = "agentPhone", required = false) String agentPhone, @RequestParam(value = "agentEmail", required = false) String agentEmail, @RequestParam(value = "agentTelephone", required = false) String agentTelephone, @RequestParam(value = "agentCardType", required = false) Integer agentCardType, @RequestParam(value = "agentIdCardNo", required = false) String agentIdCardNo, HttpServletRequest request) {
    log.error("【APIService 提交申请日志】appId=" + appId + ",productId=" + productId + ",orderNumber=" + orderNumber + ",enterpriseType=" + enterpriseType + ",isThreeInOne=" + isThreeInOne + ",enterpriseName" + enterpriseName + ",licenseNo=" + licenseNo + ",orgCode=" + orgCode + ",taxNo=" + taxNo + ",legalName=" + legalName + ",legalCardType=" + legalCardType + ",legalIdCardNo=" + legalIdCardNo + ",agentName=" + agentName + ",agentPhone=" + agentPhone + ",agentEmail=" + agentEmail + ",agentTelephone=" + agentTelephone + ",agentCardType=" + agentCardType + ",agentIdCardNo=" + agentIdCardNo);
    Map<String, Object> result = new HashMap<String, Object>();
    result.put("status", 0);
    // 验证参数是否完整
    if (StringUtils.isEmpty(authHmac) || StringUtils.isEmpty(appId) || StringUtils.isEmpty(productId) || StringUtils.isEmpty(enterpriseType) || StringUtils.isEmpty(enterpriseName) || StringUtils.isEmpty(licenseNo) || StringUtils.isEmpty(agentName) || StringUtils.isEmpty(agentPhone) || StringUtils.isEmpty(agentEmail)) {
        result.put("status", 0);
        result.put("message", "提交的参数信息不完整");
        return result;
    }
    // 得到对应产品信息
    Product product = productService.getProductById(StringTools.getLong(productId)[0]);
    if (product == null) {
        result.put("status", 0);
        result.put("message", "提交的项目产品标识有误");
        return result;
    }
    // 得到应用信息 改成service
    Map<String, ApplicationInfo> appInfoMap = CacheCustomer.getAPP_INFO_MAP();
    ApplicationInfo applicationInfo = appInfoMap.get(appId);
    if (applicationInfo == null) {
        ApplicationInfoExample applicationInfoExample = new ApplicationInfoExample();
        ApplicationInfoExample.Criteria appInfoExampleCriteria = applicationInfoExample.createCriteria();
        appInfoExampleCriteria.andAppIdEqualTo(appId);
        applicationInfo = sqlSession.selectOne("com.itrus.portal.db.ApplicationInfoMapper.selectByExample", applicationInfoExample);
    }
    if (applicationInfo == null) {
        result.put("message", "应用标识不存在");
        return result;
    }
    if (!applicationInfo.getAccessIp().contains(request.getRemoteAddr()) && "1".equals(applicationInfo.getIsIpStatus())) {
        result.put("status", -1);
        result.put("message", "没有此服务权限");
        log.error("APIService_AccsessIp : " + request.getRemoteAddr());
        return result;
    }
    // 验证hmac有效性
    try {
        String macVal = CertService.hmacSha1(applicationInfo.getSecretKey().getBytes(), (appId + productId + orderNumber + enterpriseType + isThreeInOne + enterpriseName + licenseNo + orgCode + taxNo + legalName + legalCardType + legalIdCardNo + agentName + agentPhone + agentEmail + agentTelephone + agentCardType + agentIdCardNo).getBytes("utf-8"));
        // sc.getAddressKey()), false);
        if (!authHmac.equals("HMAC-SHA1 " + macVal)) {
            result.put("status", -2);
            result.put("message", "服务密钥错误");
            return result;
        }
    } catch (Exception e) {
        result.put("status", -3);
        result.put("message", "Hmac验证错误");
        e.printStackTrace();
        return result;
    }
    // orderNumber==null true:新建 , false:审核拒绝修改提交
    if (StringUtils.isEmpty(orderNumber)) {
        UserInfo userInfo = null;
        Certification certification = null;
        // 获取产品的认证等级需要认证的项
        certification = certificationService.getSelectById(product.getAuthentication());
        DefaultTransactionDefinition def = new DefaultTransactionDefinition();
        def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
        TransactionStatus status = transactionManager.getTransaction(def);
        try {
            // 判断手机号是否存在
            userInfo = userInfoService.getUserInfoByMphone(agentPhone);
            if (userInfo != null) {
            /*
					 * result.put("status", 0); result.put("message",
					 * "该手机号已经存在关联用户"); return result;
					 */
            } else {
                try {
                    int passNumber = (int) ((Math.random() * 9 + 1) * 10000000);
                    // 新建用户 随机密码默认
                    userInfo = userInfoService.registerUserInfo(agentPhone, String.valueOf(passNumber), product.getProject());
                } catch (Exception e) {
                    result.put("status", 0);
                    result.put("message", "新建用户失败,请重试");
                    return result;
                }
            }
            /**
             * 需要认证的项:0营业执照,1组织机构代码,2税务登记证,3授权书,4法定代表人/经营者 5代理人
             */
            Long[] items = StringTools.getLong(certification.getCertItems());
            // 保存企业信息
            Enterprise enterprise = new Enterprise();
            enterprise.setEnterpriseName(enterpriseName);
            enterprise.setEnterpriseNature(Integer.parseInt(enterpriseType));
            enterprise.setAuthenticationLevel(product.getAuthentication());
            enterprise = enterpriseService.saveOrUpdateEnterprise(enterprise);
            // 保存代理人信息
            userInfo.setEmail(agentEmail);
            userInfo.setRealName(agentName);
            userInfo = userInfoService.updateUserInfo(userInfo);
            // 添加企业-代理人关联关系
            userInfoEnterpriseServiceImpl.saveUserInfoEnterprise(userInfo.getId(), enterprise.getId());
            // 生成订单
            Bill bill = billService.saveBill(userInfo.getId(), enterprise.getId(), product.getId(), null, null, null, null, product.getProject(), 1, product.getPrice(), userInfo.getId(), ComNames.BILL_STATUS_3);
            String billId = UniqueIDUtils.genBilUID(bill);
            bill.setBillId(billId);
            bill.setAppId(appId);
            bill.setUid("{}");
            bill.setUid0("{}");
            bill.setOrderNumber(billId.substring(4, billId.length()));
            sqlSession.update("com.itrus.portal.db.BillMapper.updateByPrimaryKey", bill);
            sqlSession.flushStatements();
            // 保持执照证件信息
            // 是否有营业执照信息,默认false没有
            boolean hasBl = false;
            BusinessLicense businessLicense = new BusinessLicense();
            OrgCode org = new OrgCode();
            TaxRegisterCert taxregisterCert = new TaxRegisterCert();
            IdentityCard identityCard = new IdentityCard();
            Agent agent = new Agent();
            Proxy proxy = new Proxy();
            for (Long item : items) {
                if (ComNames.BUSINESS_ITEM.equals(item) && !enterprise.getEnterpriseNature().equals(3)) {
                    // 事业单位不填写营业执照
                    hasBl = true;
                    // 设置企业唯一标识
                    if (enterprise.getEnterpriseNature().equals(1) || enterprise.getEnterpriseNature().equals(2)) {
                        // 类型为企业和个体工商户:当三证合一时,企业标识为统一社会信用代码;当非三证合一时,企业标识为营业执照注册号;
                        enterprise.setEnterpriseSn(licenseNo);
                    }
                    // 保存营业执照
                    businessLicense.setEnterpriseName(enterpriseName);
                    if (isThreeInOne) {
                        businessLicense.setBusinessType(1);
                    } else {
                        businessLicense.setBusinessType(0);
                    }
                    businessLicense.setLicenseNo(licenseNo);
                    businessLicense = businessService.portSaveBusiness(enterprise.getId(), enterprise.getEnterpriseSn(), bill.getId(), userInfo.getId(), businessLicense, null != businessLicense.getId() ? 2 : 1);
                } else if (ComNames.ORG_CODE_ITEM.equals(item)) {
                    if (hasBl && businessLicense.getBusinessType().equals(1))
                        // 五证合一企业不用提交组织机构代码、税务登记信息
                        continue;
                    if (enterprise.getEnterpriseNature().equals(3)) {
                        // 类型为政府机关/事业单位:企业标识为组织机构代码
                        enterprise.setEnterpriseSn(orgCode);
                    }
                    // 保存组织机构代码
                    org.setEnterpriseName(enterpriseName);
                    org.setOrgCode(orgCode);
                    org = orgCodeService.saveOrgCode(enterprise.getId(), enterprise.getEnterpriseSn(), bill.getId(), userInfo.getId(), org, null != org.getId() ? 2 : 1);
                } else if (ComNames.TAX_CERT_ITEM.equals(item)) {
                    if (hasBl && businessLicense.getBusinessType().equals(1))
                        // 五证合一企业不用提交组织机构代码、税务登记信息
                        continue;
                    // 保存税务登记证
                    if (enterprise.getEnterpriseNature().equals(3))
                        // 事业单位不填写税务登记信息
                        continue;
                    taxregisterCert.setEnterpriseName(enterpriseName);
                    taxregisterCert.setCertNo(taxNo);
                    taxregisterCert = taxCertService.saveTaxCert(enterprise.getId(), enterprise.getEnterpriseSn(), bill.getId(), userInfo.getId(), taxregisterCert, null != taxregisterCert.getId() ? 2 : 1);
                } else if (ComNames.IDENTITY_CARD_ITEM.equals(item)) {
                    // 保存法定代表人
                    identityCard.setEnterpriseName(enterpriseName);
                    identityCard.setName(legalName);
                    identityCard.setCardType(legalCardType);
                    identityCard.setIdCode(legalIdCardNo);
                    identityCard = identityCardService.portSaveIdentityCard(enterprise.getId(), enterprise.getEnterpriseSn(), bill.getId(), userInfo.getId(), identityCard, null != identityCard.getId() ? 2 : 1);
                } else if (ComNames.AGENT_ITEM.equals(item)) {
                    // 保存代理人
                    agent.setEnterpriseName(enterpriseName);
                    agent.setName(agentName);
                    agent.setIdCode(agentIdCardNo);
                    agent.setCardType(agentCardType);
                    agent = agentService.portSaveAgent(enterprise.getId(), enterprise.getEnterpriseSn(), bill.getId(), userInfo.getId(), agent, null != agent.getId() ? 2 : 1);
                } else if (ComNames.PROXY_ITEM.equals(item)) {
                    // 保存授权书
                    proxy = proxyService.portSaveProxy(enterprise.getId(), userInfo.getUniqueId(), bill.getId(), userInfo.getId(), proxy);
                }
            }
            // 更新企业唯一标识
            enterprise = enterpriseService.updateEnterpriseSn(enterprise);
            transactionManager.commit(status);
            // 返回第三方数据
            result.put("status", 1);
            result.put("billId", bill.getBillId());
            result.put("orderNumber", bill.getOrderNumber());
            // 记录日志
            UserLog userlog = new UserLog();
            userlog.setProject(userInfo.getProject());
            userlog.setType("购买产品");
            userlog.setInfo(userInfo.getmPhone() + "购买了" + product.getName() + ",应用标识:" + appId);
            userlog.setHostId("未知");
            userlog.setSn(null == userInfo.getUniqueId() ? null : userInfo.getUniqueId());
            LogUtil.userlog(sqlSession, userlog);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            if (!status.isCompleted())
                transactionManager.rollback(status);
            UserLog userlog = new UserLog();
            userlog.setProject(product.getProject());
            userlog.setType("购买产品");
            userlog.setInfo("url:/api/auth/search,应用标识:" + appId + ",详细错误:" + e.getMessage());
            userlog.setHostId("未知");
            userlog.setSn(null == userInfo.getUniqueId() ? null : userInfo.getUniqueId());
            LogUtil.userlog(sqlSession, userlog);
            if (e.getMessage().contains("请提交完整") || e.getMessage().contains("请确认输入是否有误")) {
                result.put("message", e.getMessage());
                return result;
            }
            result.put("message", "服务端出现未知错误,请联系管理员");
            return result;
        } finally {
            if (!status.isCompleted())
                transactionManager.rollback(status);
        }
    } else {
        // 提交企业认证申请(审核拒绝修改提交时)
        Bill bill = billService.getBillByOrderNumber(orderNumber);
        if (bill == null) {
            result.put("message", "申请流水号不存在");
            return result;
        }
        UserInfo userInfo = userInfoService.getUserInfoByBillId(bill.getId());
        Enterprise enterprise = enterpriseService.getEnterpriseById(bill.getEnterprise());
        if (bill.getBillStatus() != ComNames.BILL_STATUS_4) {
            result.put("message", "该订单未审核拒绝");
            return result;
        }
        // 根据订单id获取产品需要认证项,
        List<String> certItems = sqlSession.selectList("com.itrus.portal.db.CertificationMapper.selectCertItemsByBillId", bill.getId());
        if (null == certItems || certItems.isEmpty()) {
            result.put("message", "服务端出现异常,请联系管理员");
            return result;
        }
        // 记录旧的企业唯一标识:
        String oldEnterpriseSn = enterprise.getEnterpriseSn();
        // 设置企业唯一标识
        if (enterpriseType.equals(1) || enterpriseType.equals(2)) {
            // 类型为企业和个体工商户:当三证合一时,企业标识为统一社会信用代码;当非三证合一时,企业标识为营业执照注册号;
            enterprise.setEnterpriseSn(licenseNo);
        }
        if (enterpriseType.equals(3)) {
            // 类型为政府机关/事业单位:企业标识为组织机构代码
            enterprise.setEnterpriseSn(orgCode);
        }
        // 修改企业名称
        enterprise.setEnterpriseName(enterpriseName.replace(" ", ""));
        // 修改企业性质
        enterprise.setEnterpriseNature(Integer.parseInt(enterpriseType));
        DefaultTransactionDefinition def = new DefaultTransactionDefinition();
        def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
        TransactionStatus status = transactionManager.getTransaction(def);
        try {
            // 将参数传入对象
            BusinessLicense businessLicense = new BusinessLicense();
            OrgCode orgCd = new OrgCode();
            TaxRegisterCert taxregisterCert = new TaxRegisterCert();
            IdentityCard identityCard = new IdentityCard();
            Agent agent = new Agent();
            Proxy proxy = new Proxy();
            businessLicense.setEnterpriseName(enterpriseName);
            if (isThreeInOne) {
                businessLicense.setBusinessType(1);
            } else {
                businessLicense.setBusinessType(0);
            }
            businessLicense.setLicenseNo(licenseNo);
            orgCd.setEnterpriseName(enterpriseName);
            orgCd.setOrgCode(orgCode);
            taxregisterCert.setEnterpriseName(enterpriseName);
            taxregisterCert.setCertNo(taxNo);
            identityCard.setEnterpriseName(enterpriseName);
            identityCard.setName(legalName);
            identityCard.setCardType(legalCardType);
            identityCard.setIdCode(legalIdCardNo);
            agent.setEnterpriseName(enterpriseName);
            agent.setName(agentName);
            agent.setIdCode(agentIdCardNo);
            agent.setCardType(agentCardType);
            // 删除订单关联的旧认证项,新增订单对应的新认证项
            billWebService.portSaveBillAuthenticationItems(certItems.get(0), Integer.parseInt(enterpriseType), bill.getId(), businessLicense, orgCd, taxregisterCert, identityCard, agent, proxy, enterprise, userInfo);
            // 3、判断该订单对应的企业的认证项是否为通过,若是通过,则重新设置为不通过
            if (null != enterprise.getAuthenticationLevel())
                enterprise.setAuthenticationLevel(product.getAuthentication());
            if (null != enterprise.getHasBl())
                enterprise.setHasBl(null);
            if (null != enterprise.getHasOrgCode())
                enterprise.setHasOrgCode(null);
            if (null != enterprise.getHasTaxCert())
                enterprise.setHasTaxCert(null);
            if (null != enterprise.getHasIdCard())
                enterprise.setHasIdCard(null);
            if (null != enterprise.getHasAgent())
                enterprise.setHasAgent(null);
            sqlSession.update("com.itrus.portal.db.EnterpriseMapper.updateByPrimaryKey", enterprise);
            bill.setBillStatus(ComNames.BILL_STATUS_3);
            sqlSession.update("com.itrus.portal.db.BillMapper.updateByPrimaryKeySelective", bill);
            transactionManager.commit(status);
            // 企业标识改变后,将旧目录中的图片复制到新目录中
            if (!oldEnterpriseSn.equals(enterprise.getEnterpriseSn())) {
                CopyFile.copyFile(systemConfigService.getTrustDir().getPath() + File.separator + oldEnterpriseSn, systemConfigService.getTrustDir().getPath() + File.separator + enterprise.getEnterpriseSn());
            }
            // 判断代理人手机号是否存在 true:把全部订单关联到新手机号用户
            UserInfo userInfo1 = userInfoService.getUserInfoByMphone(agentPhone);
            if (userInfo1 != null) {
                BillExample be = new BillExample();
                BillExample.Criteria bec = be.createCriteria();
                bec.andUniqueIdEqualTo(userInfo.getId());
                List<Bill> billList = sqlSession.selectList("com.itrus.portal.db.BillMapper.selectByExample", be);
                // 循环修改订单关联的用户信息
                for (Bill b : billList) {
                    b.setUniqueId(userInfo1.getId());
                    sqlSession.update("com.itrus.portal.db.BillMapper.updateByPrimaryKeySelective", b);
                }
                userInfo1.setEnterprise(userInfo.getEnterprise());
                sqlSession.update("com.itrus.portal.db.UserInfoMapper.updateByPrimaryKeySelective", userInfo1);
                userInfo.setEnterprise(null);
                sqlSession.update("com.itrus.portal.db.UserInfoMapper.updateByPrimaryKeySelective", userInfo);
                UserinfoEnterpriseExample uee = new UserinfoEnterpriseExample();
                UserinfoEnterpriseExample.Criteria ueec = uee.createCriteria();
                ueec.andUserInfoEqualTo(userInfo.getId());
                List<UserinfoEnterprise> ueList = sqlSession.selectList("com.itrus.portal.db.UserinfoEnterpriseMapper.selectByExample", uee);
                for (UserinfoEnterprise ue : ueList) {
                    ue.setUserInfo(userInfo1.getId());
                    sqlSession.update("com.itrus.portal.db.UserinfoEnterpriseMapper.updateByPrimaryKeySelective", ue);
                }
            } else {
                userInfo.setmPhone(agentPhone);
                sqlSession.update("com.itrus.portal.db.UserInfoMapper.updateByPrimaryKeySelective", userInfo);
            }
            result.put("status", 1);
            result.put("billId", bill.getBillId());
        } catch (UserInfoServiceException e) {
            if (!status.isCompleted())
                transactionManager.rollback(status);
            result.put("message", "服务端出现未知错误,请联系管理员");
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            if (!status.isCompleted())
                transactionManager.rollback(status);
            UserLog userlog = new UserLog();
            userlog.setType("修改订单");
            userlog.setInfo("url:/api/auth/search,应用标识:" + appId + ",详细错误:" + e.getMessage());
            userlog.setHostId("未知");
            userlog.setProject(userInfo.getProject());
            LogUtil.userlog(sqlSession, userlog);
            result.put("message", "服务端出现未知错误,请联系管理员");
            if (e.getMessage().contains("有误")) {
                result.put("message", e.getMessage());
            }
            return result;
        } finally {
            if (!status.isCompleted())
                transactionManager.rollback(status);
        }
        return result;
    }
}
Also used : DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) HashMap(java.util.HashMap) ApplicationInfo(com.itrus.portal.db.ApplicationInfo) Product(com.itrus.portal.db.Product) TransactionStatus(org.springframework.transaction.TransactionStatus) UserInfo(com.itrus.portal.db.UserInfo) Proxy(com.itrus.portal.db.Proxy) BillExample(com.itrus.portal.db.BillExample) UserinfoEnterpriseExample(com.itrus.portal.db.UserinfoEnterpriseExample) IdentityCard(com.itrus.portal.db.IdentityCard) ApplicationInfoExample(com.itrus.portal.db.ApplicationInfoExample) Agent(com.itrus.portal.db.Agent) UserLog(com.itrus.portal.db.UserLog) JSONException(org.json.JSONException) UserInfoServiceException(com.itrus.portal.exception.UserInfoServiceException) Certification(com.itrus.portal.db.Certification) UserInfoServiceException(com.itrus.portal.exception.UserInfoServiceException) OrgCode(com.itrus.portal.db.OrgCode) BusinessLicense(com.itrus.portal.db.BusinessLicense) UserinfoEnterprise(com.itrus.portal.db.UserinfoEnterprise) Enterprise(com.itrus.portal.db.Enterprise) UserinfoEnterprise(com.itrus.portal.db.UserinfoEnterprise) Bill(com.itrus.portal.db.Bill) JSONObject(com.alibaba.fastjson.JSONObject) TaxRegisterCert(com.itrus.portal.db.TaxRegisterCert) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 19 with OrgCode

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

the class APIService method entAuth1.

/*
	 * @PostMapping(value= "/auth/entAuthPay") public String entAuthPay(
	 * 
	 * @RequestHeader("Content-Signature") String authHmac,
	 * 
	 * @RequestParam("appId") String appId,
	 * 
	 * @RequestParam("productId") String productId,
	 * 
	 * @RequestParam("orderNumber") String orderNumber,
	 * 
	 * @RequestParam("enterpriseType") String enterpriseType,
	 * 
	 * @RequestParam("isThreeInOne") boolean isThreeInOne,
	 * 
	 * @RequestParam("enterpriseName") String enterpriseName,
	 * 
	 * @RequestParam("licenseNo") String licenseNo,
	 * 
	 * @RequestParam("orgCode") String orgCode,
	 * 
	 * @RequestParam("taxNo") String taxNo,
	 * 
	 * @RequestParam("legalName") String legalName,
	 * 
	 * @RequestParam("legalCardType") Integer legalCardType,
	 * 
	 * @RequestParam("legalIdCardNo") String legalIdCardNo,
	 * 
	 * @RequestParam("agentName") String agentName,
	 * 
	 * @RequestParam("agentPhone") String agentPhone,
	 * 
	 * @RequestParam("agentEmail") String agentEmail,
	 * 
	 * @RequestParam("agentTelephone")String agentTelephone,
	 * 
	 * @RequestParam("agentCardType") Integer agentCardType,
	 * 
	 * @RequestParam("agentIdCardNo")String agentIdCardNo, HttpServletRequest
	 * request,Model uiModel){ HttpSession session = request.getSession();
	 * //新创建订单设置为 代支付状态 if(StringUtils.isEmpty(orderNumber)){
	 * 
	 * //String authHmac = "123";
	 * 
	 * Map<String, Object> result = this.entAuth(authHmac, appId, productId,
	 * orderNumber, enterpriseType, isThreeInOne, enterpriseName , licenseNo,
	 * orgCode, taxNo, legalName, legalCardType, legalIdCardNo, agentName,
	 * agentPhone , agentEmail, agentTelephone, agentCardType, agentIdCardNo,
	 * request);
	 * 
	 * if(result != null && (int)result.get("status") == 1){ Bill bill =
	 * billService.getBillByOrderNumber(result.get("orderNumber").toString());
	 * Product product = sqlSession.selectOne(
	 * "com.itrus.portal.db.ProductMapper.selectByPrimaryKey",
	 * bill.getProduct()); uiModel.addAttribute("product", product);
	 * 
	 * bill.setBillStatus(1); bill.setBillSum(product.getPrice()); sqlSession
	 * .update("com.itrus.portal.db.BillMapper.updateByPrimaryKeySelective",
	 * bill); //uiModel.addAttribute("webbill", bill);
	 * session.setAttribute("webbill", bill); UserInfo userInfo =
	 * sqlSession.selectOne(
	 * "com.itrus.portal.db.UserInfoMapper.selectByPrimaryKey",
	 * bill.getUniqueId()); session.setAttribute("webuserInfo", userInfo);
	 * session.setAttribute("webverifyCodeStatus", true);// 通过 if
	 * (product.getOnpay() != null && product.getOnpay() != ""){ List<Long>
	 * onlinepays = new ArrayList<Long>(); String[] onpay =
	 * (product.getOnpay()).split(","); Map<Integer, String> map = new
	 * HashMap<Integer, String>(); for (int i = 0; i < onpay.length; i++) {
	 * OnlinePay op = sqlSession .selectOne(
	 * "com.itrus.portal.db.OnlinePayMapper.selectByPrimaryKey", onpay[i]);
	 * map.put(op.getSort(), onpay[i]); } Set<Integer> set = map.keySet();
	 * Object[] obj = set.toArray(); Arrays.sort(obj); for (int i =
	 * (onpay.length - 1); i >= 0; i--) { String a = map.get(obj[i]);
	 * onlinepays.add(Long.parseLong(a)); }
	 * 
	 * Map<Long, OnlinePay> opMap = sqlSession .selectMap(
	 * "com.itrus.portal.db.OnlinePayMapper.selectByExample", "id");
	 * uiModel.addAttribute("opMap", opMap); uiModel.addAttribute("onlinepays",
	 * onlinepays); Map<Long, PayConfig> pcMap = sqlSession .selectMap(
	 * "com.itrus.portal.db.PayConfigMapper.selectByExample", "id");
	 * uiModel.addAttribute("pcMap", pcMap); } Enterprise emterprise =
	 * sqlSession.selectOne(
	 * "com.itrus.portal.db.EnterpriseMapper.selectByPrimaryKey",
	 * bill.getEnterprise()); session.setAttribute("webenterprise",
	 * emterprise);//得到付款方姓名 DigitalCert digitalCert = sqlSession.selectOne(
	 * "com.itrus.portal.db.DigitalCertMapper.selectByPrimaryKey",
	 * product.getCert()); uiModel.addAttribute("digitalCert", digitalCert);
	 * //期限
	 * 
	 * if(StringUtils.isNotBlank(product.getPay())){ Transfer transfer =
	 * sqlSession.selectOne(
	 * "com.itrus.portal.db.TransferMapper.selectByPrimaryKey",
	 * Long.parseLong(product.getPay())); uiModel.addAttribute("transfer",
	 * transfer);//银行账户汇款 } return "ixinweb/zhifu"; } return
	 * "ixinweb/tijiaoshibai"; }else{ return "ixinweb/tijiaoshibai"; } }
	 * 
	 * @RequestMapping(value = "/to") public String to(){ return
	 * "ixinweb/apiResult"; }
	 */
/**
 * 提交企业认证申请(新加)
 *
 * @param authHmac
 *            hmac签名值,采用HmacSHA1算法
 * @param appId
 *            应用标识
 * @param productId
 *            项目产品标识
 * @param orderNumber
 *            申请流水号,审核拒绝修改提交时必填 (创建申请为空,修改申请不为空)
 * @param enterpriseType
 *            企业类型 1.企业,2.个体工商户,3.事业单位/政府机关
 * @param isThreeInOne
 *            是否三证合一
 * @param enterpriseName
 *            企业名称,事业单位名称
 * @param licenseNo
 *            营业执照注册号或统一社会信用代码,事业单位法人证书编号
 * @param orgCode
 *            组织机构代码(三证合一时非必填)
 * @param taxNo
 *            税务登记证号码(三证合一时非必填,或根据业务需要选填)
 * @param legalName
 *            法定代表人姓名(根据业务需要选填)
 * @param legalCardType
 *            证件类型(1代表身份证,2护照,3其他)
 * @param legalIdCardNo
 *            证件号码
 * @param agentName
 *            代理人姓名
 * @param agentPhone
 *            代理人手机号
 * @param agentEmail
 *            代理人邮箱
 * @param agentTelephone
 *            代理人固定电话(非必填)
 * @param agentCardType
 *            证件类型(1代表身份证,2护照,3其他)
 * @param agentIdCardNo
 *            证件号码
 * @param detailAdds
 *            配送地址
 * @param certUid
 *            特定证书信息
 * @param certsize
 *            企业用户证书数量
 * @param isenterprisecert
 *            是否购买企业证书
 * @param productType
 *            产品业务类型
 * @return status 1: 表示处理正常, billId: 订单编号, orderNumber: 申请流水号 status 0:
 *         表示处理失败, message: 失败原因
 */
@PostMapping(value = "/auth/entAuth1")
@ResponseBody
public Map<String, Object> entAuth1(@RequestHeader("Content-Signature") String authHmac, @RequestParam(value = "appId", required = true) String appId, @RequestParam(value = "productId", required = true) String productId, @RequestParam(value = "orderNumber", required = false) String orderNumber, @RequestParam(value = "enterpriseType", required = false) String enterpriseType, @RequestParam(value = "isThreeInOne", required = true) boolean isThreeInOne, @RequestParam(value = "enterpriseName", required = false) String enterpriseName, @RequestParam(value = "licenseNo", required = false) String licenseNo, @RequestParam(value = "orgCode", required = false) String orgCode, @RequestParam(value = "taxNo", required = false) String taxNo, @RequestParam(value = "legalName", required = false) String legalName, @RequestParam(value = "legalCardType", required = false) Integer legalCardType, @RequestParam(value = "legalIdCardNo", required = false) String legalIdCardNo, @RequestParam(value = "agentName", required = false) String agentName, @RequestParam(value = "agentPhone", required = false) String agentPhone, @RequestParam(value = "agentEmail", required = false) String agentEmail, @RequestParam(value = "agentTelephone", required = false) String agentTelephone, @RequestParam(value = "agentCardType", required = false) Integer agentCardType, @RequestParam(value = "agentIdCardNo", required = false) String agentIdCardNo, @RequestParam(value = "detailAdds", required = false) String detailAdds, @RequestParam(value = "certUid", required = false) String certUid, @RequestParam(value = "certsize", required = false) Integer certsize, @RequestParam(value = "isenterprisecert", required = false) Boolean isenterprisecert, @RequestParam(value = "courier", required = false) Integer courier, @RequestParam(value = "cost", required = false) Integer cost, /* @RequestParam(value = "productType", required = false)String
			 * productType,
			 */
HttpServletRequest request) {
    log.error("【APIService 提交申请日志】appId=" + appId + ",authHmac=" + authHmac + ",productId=" + productId + ",orderNumber=" + orderNumber + ",enterpriseType=" + enterpriseType + ",isThreeInOne=" + isThreeInOne + ",enterpriseName" + enterpriseName + ",licenseNo=" + licenseNo + ",orgCode=" + orgCode + ",taxNo=" + taxNo + ",legalName=" + legalName + ",legalCardType=" + legalCardType + ",legalIdCardNo=" + legalIdCardNo + ",agentName=" + agentName + ",agentPhone=" + agentPhone + ",agentEmail=" + agentEmail + ",agentTelephone=" + agentTelephone + ",agentCardType=" + agentCardType + ",agentIdCardNo=" + agentIdCardNo + ",detailAdds=" + detailAdds + ",certUid=" + certUid + ",certsize=" + certsize + ",courier=" + courier + ",cost=" + cost + ",isenterprisecert" + isenterprisecert);
    Map<String, Object> result = new HashMap<String, Object>();
    // 验证参数是否完整
    if (StringUtils.isEmpty(authHmac) || StringUtils.isEmpty(appId) || StringUtils.isEmpty(productId) || StringUtils.isEmpty(enterpriseType) || StringUtils.isEmpty(enterpriseName) || StringUtils.isEmpty(licenseNo) || /* 营业执照 */
    StringUtils.isEmpty(agentName) || StringUtils.isEmpty(agentPhone) || StringUtils.isEmpty(agentEmail)) {
        result.put("status", 0);
        result.put("message", "提交的参数信息不完整");
        return result;
    }
    log.error("企业名称位数=" + enterpriseName.length());
    if (enterpriseName.length() > 32) {
        result.put("status", -7);
        result.put("message", "企业名称超过32个汉字,请检查企业名称或联系管理员");
        return result;
    }
    // 得到对应产品信息
    Product product = productService.getProductById(StringTools.getLong(productId)[0]);
    if (product == null) {
        result.put("status", 0);
        result.put("message", "提交的项目产品标识有误");
        return result;
    }
    DigitalCert dcert = sqlSession.selectOne("com.itrus.portal.db.DigitalCertMapper.selectByPrimaryKey", product.getCert());
    if ("3".equals(dcert.getInitBuy())) {
        if (null != isenterprisecert) {
            if (isenterprisecert == false) {
                isenterprisecert = false;
            } else {
                isenterprisecert = true;
            }
        } else {
            isenterprisecert = true;
        }
    } else {
        if (null != isenterprisecert) {
            if (isenterprisecert == false) {
                isenterprisecert = false;
            } else {
                isenterprisecert = true;
            }
        } else {
            isenterprisecert = null;
        }
    }
    if ("2".equals(dcert.getCertType())) {
        if (StringUtils.isEmpty(certUid)) {
            result.put("status", 0);
            result.put("message", "提交的参数信息不完整,证书信息项不能为空");
            return result;
        }
    }
    if (StringUtils.isNotEmpty(product.getDelivery())) {
        if (StringUtils.isEmpty(detailAdds)) {
            result.put("status", 0);
            result.put("message", "提交的参数信息不完整,配送地址不能为空");
            return result;
        }
    }
    // 得到应用信息 改成service
    Map<String, ApplicationInfo> appInfoMap = CacheCustomer.getAPP_INFO_MAP();
    ApplicationInfo applicationInfo = appInfoMap.get(appId);
    if (applicationInfo == null) {
        ApplicationInfoExample applicationInfoExample = new ApplicationInfoExample();
        ApplicationInfoExample.Criteria appInfoExampleCriteria = applicationInfoExample.createCriteria();
        appInfoExampleCriteria.andAppIdEqualTo(appId);
        applicationInfo = sqlSession.selectOne("com.itrus.portal.db.ApplicationInfoMapper.selectByExample", applicationInfoExample);
    }
    if (applicationInfo == null) {
        result.put("status", 0);
        result.put("message", "应用标识不存在");
        return result;
    }
    if (!applicationInfo.getAccessIp().contains(request.getRemoteAddr()) && "1".equals(applicationInfo.getIsIpStatus())) {
        result.put("status", -1);
        result.put("message", "此IP没有此服务权限");
        log.error("APIService_AccsessIp : " + request.getRemoteAddr());
        return result;
    }
    // 验证hmac有效性
    log.error("打印isenterprisecert=" + isenterprisecert);
    try {
        if (isenterprisecert != null) {
            String macVal = CertService.hmacSha1(applicationInfo.getSecretKey().getBytes(), (appId + productId + orderNumber + enterpriseType + isThreeInOne + enterpriseName + licenseNo + orgCode + taxNo + legalName + legalCardType + legalIdCardNo + agentName + agentPhone + agentEmail + agentTelephone + agentCardType + agentIdCardNo + detailAdds + certUid + certsize + courier + cost + isenterprisecert).getBytes("utf-8"));
            if (!authHmac.equals("HMAC-SHA1 " + macVal)) {
                result.put("status", -3);
                result.put("message", "服务密钥错误");
                return result;
            }
        } else {
            String macVal = CertService.hmacSha1(applicationInfo.getSecretKey().getBytes(), (appId + productId + orderNumber + enterpriseType + isThreeInOne + enterpriseName + licenseNo + orgCode + taxNo + legalName + legalCardType + legalIdCardNo + agentName + agentPhone + agentEmail + agentTelephone + agentCardType + agentIdCardNo + detailAdds + certUid + certsize + courier + cost).getBytes("utf-8"));
            if (!authHmac.equals("HMAC-SHA1 " + macVal)) {
                result.put("status", -3);
                result.put("message", "服务密钥错误");
                return result;
            }
        }
    // Base64.encode(HMACSHA1.getHmacSHA1(csr+billId+uid+userId,
    // sc.getAddressKey()), false);
    } catch (Exception e) {
        result.put("status", -2);
        result.put("message", "Hmac验证错误");
        e.printStackTrace();
        return result;
    }
    // orderNumber==null true:新建 , false:审核拒绝修改提交
    if (StringUtils.isEmpty(orderNumber)) {
        UserInfo userInfo = null;
        Certification certification = null;
        // 获取产品的认证等级需要认证的项
        certification = certificationService.getSelectById(product.getAuthentication());
        DefaultTransactionDefinition def = new DefaultTransactionDefinition();
        def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
        TransactionStatus status = transactionManager.getTransaction(def);
        try {
            // 判断手机号是否存在
            userInfo = userInfoService.getUserInfoByMphone(agentPhone);
            if (userInfo != null) {
            /*
					 * result.put("status", 0); result.put("message",
					 * "该手机号已经存在关联用户"); return result;
					 */
            } else {
                try {
                    int passNumber = (int) ((Math.random() * 9 + 1) * 10000000);
                    // 新建用户 随机密码默认
                    userInfo = userInfoService.registerUserInfo(agentPhone, String.valueOf(passNumber), product.getProject());
                } catch (Exception e) {
                    result.put("status", -4);
                    result.put("message", "新建用户失败,请重试");
                    return result;
                }
            }
            /**
             * 需要认证的项:0营业执照,1组织机构代码,2税务登记证,3授权书,4法定代表人/经营者 5代理人
             */
            if (certification == null) {
                result.put("status", -6);
                result.put("message", "产品的认证等级未配置需要认证的项");
                return result;
            }
            Long[] items = StringTools.getLong(certification.getCertItems());
            // 保存企业信息
            Enterprise enterprise = new Enterprise();
            enterprise.setEnterpriseName(enterpriseName);
            enterprise.setEnterpriseNature(Integer.parseInt(enterpriseType));
            enterprise.setAuthenticationLevel(product.getAuthentication());
            enterprise = enterpriseService.saveOrUpdateEnterprise(enterprise);
            // 保存代理人信息
            userInfo.setEmail(agentEmail);
            userInfo.setRealName(agentName);
            userInfo = userInfoService.updateUserInfo(userInfo);
            Delivery deliver = null;
            // 判断是否配送
            if (StringUtils.isNotEmpty(product.getDelivery())) {
                // 保存配送信息
                Delivery delivery = new Delivery();
                if (courier != null && cost != null) {
                    delivery.setCourier(courier);
                    delivery.setCost(cost);
                } else {
                    // 0:1,0:0
                    String[] deliverPrices = product.getDeliveryPrice().split(",");
                    for (int j = 0; j < deliverPrices.length; j++) {
                        // [0]:0,1;[1]:0,0
                        String[] deliverpi = deliverPrices[j].split(":");
                        if (Integer.parseInt(deliverpi[0].toString()) != 0) {
                            String courier1 = deliverpi[0].toString();
                            String cost1 = deliverpi[1].toString();
                            delivery.setCourier(Integer.parseInt(courier1));
                            delivery.setCost(Integer.parseInt(cost1));
                        }
                    }
                /*String courier1 = product.getDeliveryPrice().split(":")[0];
	    				String cost1 = product.getDeliveryPrice().split(":")[1];
	    				delivery.setCourier(Integer.parseInt(courier1));
	    				delivery.setCost(Integer.parseInt(cost1));*/
                }
                delivery.setDetailAdds(detailAdds);
                delivery.setUserInfo(userInfo.getId());
                delivery.setReceiver(agentName);
                delivery.setRvPhone(agentPhone);
                deliveryService.saveDelivery(userInfo.getId(), agentName, agentPhone, delivery);
                deliver = deliveryService.getDelibery(userInfo.getId());
            }
            /*	
				String[] uid = {};
				
				
				
				JSONArray jsonArray = new JSONArray(product.getCertinfo());
				for(int i=0;i<jsonArray.length();i++){
					JSONObject jsob = JSONObject.parseObject(jsonArray.get(i).toString());
					jsob.getString("inputName");
				}*/
            // Delivery deliver = deliveryService.getDelibery(userInfo.getId());
            // 添加企业-代理人关联关系
            userInfoEnterpriseServiceImpl.saveUserInfoEnterprise(userInfo.getId(), enterprise.getId());
            // 生成订单
            Bill bill = billService.saveBill(userInfo.getId(), enterprise.getId(), product.getId(), null, null, null, null, product.getProject(), 1, product.getPrice(), userInfo.getId(), ComNames.BILL_STATUS_3);
            String billId = UniqueIDUtils.genBilUID(bill);
            bill.setBillId(billId);
            bill.setAppId(appId);
            if (deliver != null) {
                bill.setDelivery(deliver.getId());
            }
            if ("2".equals(dcert.getCertType())) {
                /*try {
						String[] cuid = certUid.split(",");
						String s2 = null;
						String s3 = null;
						
						JSONArray jsonArray = new JSONArray(product.getCertinfo());
						for(int i=0;i<jsonArray.length();i++){
							JSONObject jsob = JSONObject.parseObject(jsonArray.get(i).toString());
							String iput = jsob.getString("inputName");
							System.out.println(iput);
							if(iput!=null){
								for(int j=0;j<cuid.length;j++){
									
									s2 = ""+iput+"_"+(j+1)+":"+cuid[j]+"";
									if(s2!=null){
										s2 = ","+iput+"_"+(j+1)+""+":"+""+cuid[j]+"";
									}
									System.out.println(s2);
									
								}
							}
						}
						s3="{"+s2+"}";*/
                // 证书信息项
                bill.setUid(certUid);
            /*} catch (JSONException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					*/
            } else {
                // 证书信息项
                bill.setUid("{}");
            }
            // bill.setUid("{}");// 证书信息项
            bill.setUid0("{}");
            bill.setOrderNumber(billId.substring(4, billId.length()));
            // 判断证书数量是否为空
            if (certsize != null && certsize > 0) {
                // 购买数量
                bill.setProductNum(certsize);
            } else {
                // 购买数量
                bill.setProductNum(1);
            }
            bill.setIsenterprisecert(isenterprisecert);
            sqlSession.update("com.itrus.portal.db.BillMapper.updateByPrimaryKey", bill);
            sqlSession.flushStatements();
            // 保持执照证件信息
            // 是否有营业执照信息,默认false没有
            boolean hasBl = false;
            BusinessLicense businessLicense = new BusinessLicense();
            OrgCode org = new OrgCode();
            TaxRegisterCert taxregisterCert = new TaxRegisterCert();
            IdentityCard identityCard = new IdentityCard();
            Agent agent = new Agent();
            Proxy proxy = new Proxy();
            for (Long item : items) {
                if (ComNames.BUSINESS_ITEM.equals(item) && !enterprise.getEnterpriseNature().equals(3)) {
                    // 事业单位不填写营业执照
                    hasBl = true;
                    // 设置企业唯一标识
                    if (enterprise.getEnterpriseNature().equals(1) || enterprise.getEnterpriseNature().equals(2)) {
                        // 类型为企业和个体工商户:当三证合一时,企业标识为统一社会信用代码;当非三证合一时,企业标识为营业执照注册号;
                        enterprise.setEnterpriseSn(licenseNo);
                    }
                    // 保存营业执照
                    businessLicense.setEnterpriseName(enterpriseName);
                    if (isThreeInOne) {
                        businessLicense.setBusinessType(1);
                    } else {
                        businessLicense.setBusinessType(0);
                    }
                    businessLicense.setLicenseNo(licenseNo);
                    businessLicense = businessService.portSaveBusiness(enterprise.getId(), enterprise.getEnterpriseSn(), bill.getId(), userInfo.getId(), businessLicense, null != businessLicense.getId() ? 2 : 1);
                } else if (ComNames.ORG_CODE_ITEM.equals(item)) {
                    if (hasBl && businessLicense.getBusinessType().equals(1))
                        // 五证合一企业不用提交组织机构代码、税务登记信息
                        continue;
                    if (enterprise.getEnterpriseNature().equals(3)) {
                        // 类型为政府机关/事业单位:企业标识为组织机构代码
                        enterprise.setEnterpriseSn(orgCode);
                    }
                    // 保存组织机构代码
                    org.setEnterpriseName(enterpriseName);
                    org.setOrgCode(orgCode);
                    org = orgCodeService.saveOrgCode(enterprise.getId(), enterprise.getEnterpriseSn(), bill.getId(), userInfo.getId(), org, null != org.getId() ? 2 : 1);
                } else if (ComNames.TAX_CERT_ITEM.equals(item)) {
                    if (hasBl && businessLicense.getBusinessType().equals(1))
                        // 五证合一企业不用提交组织机构代码、税务登记信息
                        continue;
                    // 保存税务登记证
                    if (enterprise.getEnterpriseNature().equals(3))
                        // 事业单位不填写税务登记信息
                        continue;
                    taxregisterCert.setEnterpriseName(enterpriseName);
                    taxregisterCert.setCertNo(taxNo);
                    taxregisterCert = taxCertService.saveTaxCert(enterprise.getId(), enterprise.getEnterpriseSn(), bill.getId(), userInfo.getId(), taxregisterCert, null != taxregisterCert.getId() ? 2 : 1);
                } else if (ComNames.IDENTITY_CARD_ITEM.equals(item)) {
                    // 保存法定代表人
                    identityCard.setEnterpriseName(enterpriseName);
                    identityCard.setName(legalName);
                    identityCard.setCardType(legalCardType);
                    identityCard.setIdCode(legalIdCardNo);
                    identityCard = identityCardService.portSaveIdentityCard(enterprise.getId(), enterprise.getEnterpriseSn(), bill.getId(), userInfo.getId(), identityCard, null != identityCard.getId() ? 2 : 1);
                } else if (ComNames.AGENT_ITEM.equals(item)) {
                    // 保存代理人
                    agent.setEnterpriseName(enterpriseName);
                    agent.setName(agentName);
                    agent.setIdCode(agentIdCardNo);
                    agent.setCardType(agentCardType);
                    agent = agentService.portSaveAgent(enterprise.getId(), enterprise.getEnterpriseSn(), bill.getId(), userInfo.getId(), agent, null != agent.getId() ? 2 : 1);
                } else if (ComNames.PROXY_ITEM.equals(item)) {
                    // 保存授权书
                    proxy = proxyService.portSaveProxy(enterprise.getId(), userInfo.getUniqueId(), bill.getId(), userInfo.getId(), proxy);
                }
            }
            // 更新企业唯一标识
            enterprise = enterpriseService.updateEnterpriseSn(enterprise);
            transactionManager.commit(status);
            // 返回第三方数据
            result.put("status", 1);
            result.put("billId", bill.getBillId());
            result.put("orderNumber", bill.getOrderNumber());
            // 记录日志
            UserLog userlog = new UserLog();
            userlog.setProject(userInfo.getProject());
            userlog.setType("购买产品");
            userlog.setInfo(userInfo.getmPhone() + "购买了" + product.getName() + ",应用标识:" + appId);
            userlog.setHostId("未知");
            userlog.setSn(null == userInfo.getUniqueId() ? null : userInfo.getUniqueId());
            LogUtil.userlog(sqlSession, userlog);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            if (!status.isCompleted())
                transactionManager.rollback(status);
            UserLog userlog = new UserLog();
            userlog.setProject(product.getProject());
            userlog.setType("购买产品");
            userlog.setInfo("url:/api/auth/search,应用标识:" + appId + ",详细错误:" + e.getMessage());
            userlog.setHostId("未知");
            userlog.setSn(null == userInfo.getUniqueId() ? null : userInfo.getUniqueId());
            LogUtil.userlog(sqlSession, userlog);
            if (e.getMessage().contains("请提交完整") || e.getMessage().contains("请确认输入是否有误")) {
                result.put("status", 0);
                result.put("message", e.getMessage());
                return result;
            }
            result.put("status", -4);
            result.put("message", "服务端出现未知错误,请联系管理员");
            return result;
        } finally {
            if (!status.isCompleted())
                transactionManager.rollback(status);
        }
    } else {
        // 提交企业认证申请(审核拒绝修改提交时)
        Bill bill = billService.getBillByOrderNumber(orderNumber);
        if (bill == null) {
            result.put("status", -5);
            result.put("message", "申请流水号不存在");
            return result;
        }
        UserInfo userInfo = userInfoService.getUserInfoByBillId(bill.getId());
        Enterprise enterprise = enterpriseService.getEnterpriseById(bill.getEnterprise());
        if (bill.getBillStatus() != ComNames.BILL_STATUS_4) {
            result.put("status", -5);
            result.put("message", "该订单未审核拒绝");
            return result;
        }
        // 根据订单id获取产品需要认证项,
        List<String> certItems = sqlSession.selectList("com.itrus.portal.db.CertificationMapper.selectCertItemsByBillId", bill.getId());
        if (null == certItems || certItems.isEmpty()) {
            result.put("status", -4);
            result.put("message", "服务端出现异常,请联系管理员");
            return result;
        }
        // 记录旧的企业唯一标识:
        String oldEnterpriseSn = enterprise.getEnterpriseSn();
        // 设置企业唯一标识
        if (enterpriseType.equals(1) || enterpriseType.equals(2)) {
            // 类型为企业和个体工商户:当三证合一时,企业标识为统一社会信用代码;当非三证合一时,企业标识为营业执照注册号;
            enterprise.setEnterpriseSn(licenseNo);
        }
        if (enterpriseType.equals(3)) {
            // 类型为政府机关/事业单位:企业标识为组织机构代码
            enterprise.setEnterpriseSn(orgCode);
        }
        // 修改企业名称
        enterprise.setEnterpriseName(enterpriseName.replace(" ", ""));
        // 修改企业性质
        enterprise.setEnterpriseNature(Integer.parseInt(enterpriseType));
        DefaultTransactionDefinition def = new DefaultTransactionDefinition();
        def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
        TransactionStatus status = transactionManager.getTransaction(def);
        try {
            // 将参数传入对象
            BusinessLicense businessLicense = new BusinessLicense();
            OrgCode orgCd = new OrgCode();
            TaxRegisterCert taxregisterCert = new TaxRegisterCert();
            IdentityCard identityCard = new IdentityCard();
            Agent agent = new Agent();
            Proxy proxy = new Proxy();
            businessLicense.setEnterpriseName(enterpriseName);
            if (isThreeInOne) {
                businessLicense.setBusinessType(1);
            } else {
                businessLicense.setBusinessType(0);
            }
            businessLicense.setLicenseNo(licenseNo);
            orgCd.setEnterpriseName(enterpriseName);
            orgCd.setOrgCode(orgCode);
            taxregisterCert.setEnterpriseName(enterpriseName);
            taxregisterCert.setCertNo(taxNo);
            identityCard.setEnterpriseName(enterpriseName);
            identityCard.setName(legalName);
            identityCard.setCardType(legalCardType);
            identityCard.setIdCode(legalIdCardNo);
            agent.setEnterpriseName(enterpriseName);
            agent.setName(agentName);
            agent.setIdCode(agentIdCardNo);
            agent.setCardType(agentCardType);
            // 删除订单关联的旧认证项,新增订单对应的新认证项
            billWebService.portSaveBillAuthenticationItems(certItems.get(0), Integer.parseInt(enterpriseType), bill.getId(), businessLicense, orgCd, taxregisterCert, identityCard, agent, proxy, enterprise, userInfo);
            // 3、判断该订单对应的企业的认证项是否为通过,若是通过,则重新设置为不通过
            if (null != enterprise.getAuthenticationLevel())
                enterprise.setAuthenticationLevel(product.getAuthentication());
            if (null != enterprise.getHasBl())
                enterprise.setHasBl(null);
            if (null != enterprise.getHasOrgCode())
                enterprise.setHasOrgCode(null);
            if (null != enterprise.getHasTaxCert())
                enterprise.setHasTaxCert(null);
            if (null != enterprise.getHasIdCard())
                enterprise.setHasIdCard(null);
            if (null != enterprise.getHasAgent())
                enterprise.setHasAgent(null);
            sqlSession.update("com.itrus.portal.db.EnterpriseMapper.updateByPrimaryKey", enterprise);
            bill.setBillStatus(ComNames.BILL_STATUS_3);
            sqlSession.update("com.itrus.portal.db.BillMapper.updateByPrimaryKeySelective", bill);
            transactionManager.commit(status);
            // 企业标识改变后,将旧目录中的图片复制到新目录中
            if (!oldEnterpriseSn.equals(enterprise.getEnterpriseSn())) {
                CopyFile.copyFile(systemConfigService.getTrustDir().getPath() + File.separator + oldEnterpriseSn, systemConfigService.getTrustDir().getPath() + File.separator + enterprise.getEnterpriseSn());
            }
            // 判断代理人手机号是否存在 true:把全部订单关联到新手机号用户
            UserInfo userInfo1 = userInfoService.getUserInfoByMphone(agentPhone);
            if (userInfo1 != null) {
                BillExample be = new BillExample();
                BillExample.Criteria bec = be.createCriteria();
                bec.andUniqueIdEqualTo(userInfo.getId());
                List<Bill> billList = sqlSession.selectList("com.itrus.portal.db.BillMapper.selectByExample", be);
                // 循环修改订单关联的用户信息
                for (Bill b : billList) {
                    b.setUniqueId(userInfo1.getId());
                    sqlSession.update("com.itrus.portal.db.BillMapper.updateByPrimaryKeySelective", b);
                }
                userInfo1.setEnterprise(userInfo.getEnterprise());
                sqlSession.update("com.itrus.portal.db.UserInfoMapper.updateByPrimaryKeySelective", userInfo1);
                userInfo.setEnterprise(null);
                sqlSession.update("com.itrus.portal.db.UserInfoMapper.updateByPrimaryKeySelective", userInfo);
                UserinfoEnterpriseExample uee = new UserinfoEnterpriseExample();
                UserinfoEnterpriseExample.Criteria ueec = uee.createCriteria();
                ueec.andUserInfoEqualTo(userInfo.getId());
                List<UserinfoEnterprise> ueList = sqlSession.selectList("com.itrus.portal.db.UserinfoEnterpriseMapper.selectByExample", uee);
                for (UserinfoEnterprise ue : ueList) {
                    ue.setUserInfo(userInfo1.getId());
                    sqlSession.update("com.itrus.portal.db.UserinfoEnterpriseMapper.updateByPrimaryKeySelective", ue);
                }
            } else {
                userInfo.setmPhone(agentPhone);
                sqlSession.update("com.itrus.portal.db.UserInfoMapper.updateByPrimaryKeySelective", userInfo);
            }
            result.put("status", 1);
            result.put("billId", bill.getBillId());
        } catch (UserInfoServiceException e) {
            if (!status.isCompleted())
                transactionManager.rollback(status);
            result.put("status", -4);
            result.put("message", "服务端出现未知错误,请联系管理员");
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            if (!status.isCompleted())
                transactionManager.rollback(status);
            UserLog userlog = new UserLog();
            userlog.setType("修改订单");
            userlog.setInfo("url:/api/auth/entAuth1,应用标识:" + appId + ",详细错误:" + e.getMessage());
            userlog.setHostId("未知");
            userlog.setProject(userInfo.getProject());
            LogUtil.userlog(sqlSession, userlog);
            result.put("status", -4);
            result.put("message", "服务端出现未知错误,请联系管理员");
            if (e.getMessage().contains("有误")) {
                result.put("status", 0);
                result.put("message", e.getMessage());
            }
            return result;
        } finally {
            if (!status.isCompleted())
                transactionManager.rollback(status);
        }
        return result;
    }
}
Also used : DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) HashMap(java.util.HashMap) ApplicationInfo(com.itrus.portal.db.ApplicationInfo) Product(com.itrus.portal.db.Product) TransactionStatus(org.springframework.transaction.TransactionStatus) UserInfo(com.itrus.portal.db.UserInfo) DigitalCert(com.itrus.portal.db.DigitalCert) Proxy(com.itrus.portal.db.Proxy) BillExample(com.itrus.portal.db.BillExample) UserinfoEnterpriseExample(com.itrus.portal.db.UserinfoEnterpriseExample) IdentityCard(com.itrus.portal.db.IdentityCard) ApplicationInfoExample(com.itrus.portal.db.ApplicationInfoExample) Agent(com.itrus.portal.db.Agent) UserLog(com.itrus.portal.db.UserLog) JSONException(org.json.JSONException) UserInfoServiceException(com.itrus.portal.exception.UserInfoServiceException) Certification(com.itrus.portal.db.Certification) UserInfoServiceException(com.itrus.portal.exception.UserInfoServiceException) OrgCode(com.itrus.portal.db.OrgCode) BusinessLicense(com.itrus.portal.db.BusinessLicense) UserinfoEnterprise(com.itrus.portal.db.UserinfoEnterprise) Enterprise(com.itrus.portal.db.Enterprise) UserinfoEnterprise(com.itrus.portal.db.UserinfoEnterprise) Bill(com.itrus.portal.db.Bill) JSONObject(com.alibaba.fastjson.JSONObject) Delivery(com.itrus.portal.db.Delivery) TaxRegisterCert(com.itrus.portal.db.TaxRegisterCert) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 20 with OrgCode

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

the class ExtraBillWebController method refuse.

// 审核拒绝重新提交页面
@RequestMapping(value = "/resubmit/{id}", produces = "text/html")
public String refuse(@PathVariable("id") Long id, Model uiModel, HttpServletRequest request) {
    HttpSession session = request.getSession();
    Enterprise webenterprise = (Enterprise) session.getAttribute("webenterprise");
    UserInfo webuserInfo = (UserInfo) session.getAttribute("webuserInfo");
    if (null == webenterprise || null == webuserInfo) {
        uiModel.addAttribute("errorMsg", "登录失效");
        return "client/errorpage";
    }
    ExtraBill bill = extraBillService.selectByPrimaryKey(id);
    if (null == bill) {
        uiModel.addAttribute("errorMsg", "未找到该订单");
        return "client/errorpage";
    }
    if (!bill.getUniqueId().equals(webuserInfo.getId())) {
        uiModel.addAttribute("errorMsg", "您无权操作该订单");
        return "client/errorpage";
    }
    // 获取订单在线支付方式
    if (null != bill.getOnPayInfo()) {
        // 第三方在线支付记录信息
        Map<Long, OnPayInfo> opiMap = sqlSession.selectMap("com.itrus.portal.db.OnPayInfoMapper.selectByExample", "id");
        uiModel.addAttribute("opiMap", opiMap);
        // 在线支付方式配置,目前有微信和支付宝两种
        Map<Long, OnlinePay> opMap = sqlSession.selectMap("com.itrus.portal.db.OnlinePayMapper.selectByExample", "id");
        uiModel.addAttribute("opMap", opMap);
    }
    // 订单
    uiModel.addAttribute("bill", bill);
    // 产品
    ExtraProduct product = sqlSession.selectOne("com.itrus.portal.db.ExtraProductMapper.selectByPrimaryKey", bill.getExtraProduct());
    uiModel.addAttribute("product", product);
    // 用户
    UserInfo userInfo = sqlSession.selectOne("com.itrus.portal.db.UserInfoMapper.selectByPrimaryKey", bill.getUniqueId());
    uiModel.addAttribute("userInfo", userInfo);
    // 企业
    Enterprise enterprise = sqlSession.selectOne("com.itrus.portal.db.EnterpriseMapper.selectByPrimaryKey", bill.getEnterprise());
    uiModel.addAttribute("enterprise", enterprise);
    FileInputStream fis = null;
    try {
        if (null != product.getExtraMessage()) {
            ExtraMessage extraMessage = extraMessageService.selectByPrimaryKey(product.getExtraMessage());
            // 用附加信息项的有无来判断是否需要用户填写附加信息,如果需要,则取附加信息项进行分割处理
            uiModel.addAttribute("extraMessage", extraMessage);
            File file = new File(systemConfigService.getTrustDir().getPath() + File.separator + enterprise.getEnterpriseSn());
            if (!file.exists()) {
                file.mkdir();
            }
            // //企业信息 认证项(1.企业名称,2.统一社会信用代码/营业执照,3.组织机构代码,4.税务登记号)
            if (StringUtils.isNotBlank(extraMessage.getEnterpriseItems())) {
                if (extraMessage.getEnterpriseItems().contains("2")) {
                    // 营业执照
                    BusinessLicense businessLicense = businessService.getBusinessByExtraBillId(id, null);
                    if (null != businessLicense) {
                        File imgFile = new File(file, businessLicense.getImgFile());
                        fis = new FileInputStream(imgFile);
                        businessLicense.setImgFile(ImageToBase64Utils.GetFileBase64(fis));
                        fis.close();
                        uiModel.addAttribute("businessLicense", businessLicense);
                    }
                }
                if (extraMessage.getEnterpriseItems().contains("3")) {
                    // 组织机构代码
                    OrgCode orgCode = orgCodeService.getOrgCodeByExtraBillId(id, null);
                    if (null != orgCode) {
                        File imgFile = new File(file, orgCode.getImgFile());
                        fis = new FileInputStream(imgFile);
                        orgCode.setImgFile(ImageToBase64Utils.GetFileBase64(fis));
                        fis.close();
                        uiModel.addAttribute("orgCode", orgCode);
                    }
                }
                if (extraMessage.getEnterpriseItems().contains("4")) {
                    // 税务登记
                    TaxRegisterCert taxRegisterCert = taxCertService.getTaxRegisterCertByExtraBillId(id, null);
                    if (null != taxRegisterCert) {
                        File imgFile = new File(file, taxRegisterCert.getImgFile());
                        fis = new FileInputStream(imgFile);
                        taxRegisterCert.setImgFile(ImageToBase64Utils.GetFileBase64(fis));
                        fis.close();
                        uiModel.addAttribute("taxRegisterCert", taxRegisterCert);
                    }
                }
            }
            // field string --fieldName agentItems
            if (StringUtils.isNotBlank(extraMessage.getAgentItems())) {
                Agent agent = agentService.getAgentByExtraBillId(id, null);
                if (null != agent) {
                    File imgFile = new File(file, agent.getFrontImg());
                    fis = new FileInputStream(imgFile);
                    agent.setFrontImg(ImageToBase64Utils.GetFileBase64(fis));
                    if (StringUtils.isNotBlank(agent.getBackImg())) {
                        File backImgFile = new File(file, agent.getBackImg());
                        fis = new FileInputStream(backImgFile);
                        agent.setBackImg(ImageToBase64Utils.GetFileBase64(fis));
                        fis.close();
                    }
                    uiModel.addAttribute("agent", agent);
                }
            }
            // field string --fieldName bankItems
            if (StringUtils.isNotBlank(extraMessage.getBankItems())) {
                OpenBankInfo openBankInfo = openBankInfoService.getOpenBankInfoByExtraBillId(id, null);
                if (null != openBankInfo) {
                    uiModel.addAttribute("openBankInfo", openBankInfo);
                }
            }
            // 法人认证项
            if (StringUtils.isNotBlank(extraMessage.getIdentityCardItems())) {
                IdentityCard identityCard = identityCardService.getIdentityCardByExtraBillId(id, null);
                if (null != identityCard) {
                    File imgFile = new File(file, identityCard.getFrontImg());
                    fis = new FileInputStream(imgFile);
                    identityCard.setFrontImg(ImageToBase64Utils.GetFileBase64(fis));
                    if (StringUtils.isNotBlank(identityCard.getBackImg())) {
                        File backImgFile = new File(file, identityCard.getBackImg());
                        fis = new FileInputStream(backImgFile);
                        identityCard.setBackImg(ImageToBase64Utils.GetFileBase64(fis));
                        fis.close();
                    }
                    uiModel.addAttribute("identityCard", identityCard);
                }
            }
        }
    } catch (Exception e) {
        // TODO: handle exception
        UserLog userlog = new UserLog();
        userlog.setProject(bill.getProject());
        userlog.setType("审核拒绝重新提交");
        userlog.setInfo("url:resubmit,详细错误:" + e.getMessage());
        userlog.setHostId("未知");
        userlog.setSn(null == webuserInfo.getUniqueId() ? null : webuserInfo.getUniqueId());
        LogUtil.userlog(sqlSession, userlog);
    } finally {
        if (null != fis) {
            try {
                fis.close();
            } catch (Exception e2) {
            // TODO: handle exception
            }
        }
    }
    return "client/shenhejujue_chongxintijiao";
}
Also used : Agent(com.itrus.portal.db.Agent) HttpSession(javax.servlet.http.HttpSession) ExtraBill(com.itrus.portal.db.ExtraBill) UserInfo(com.itrus.portal.db.UserInfo) UserLog(com.itrus.portal.db.UserLog) FileInputStream(java.io.FileInputStream) ExtraProduct(com.itrus.portal.db.ExtraProduct) OrgCode(com.itrus.portal.db.OrgCode) BusinessLicense(com.itrus.portal.db.BusinessLicense) OnPayInfo(com.itrus.portal.db.OnPayInfo) OpenBankInfo(com.itrus.portal.db.OpenBankInfo) Enterprise(com.itrus.portal.db.Enterprise) ExtraMessage(com.itrus.portal.db.ExtraMessage) File(java.io.File) TaxRegisterCert(com.itrus.portal.db.TaxRegisterCert) OnlinePay(com.itrus.portal.db.OnlinePay) IdentityCard(com.itrus.portal.db.IdentityCard) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

OrgCode (com.itrus.portal.db.OrgCode)34 BusinessLicense (com.itrus.portal.db.BusinessLicense)25 TaxRegisterCert (com.itrus.portal.db.TaxRegisterCert)24 Enterprise (com.itrus.portal.db.Enterprise)23 IdentityCard (com.itrus.portal.db.IdentityCard)22 Agent (com.itrus.portal.db.Agent)20 UserInfo (com.itrus.portal.db.UserInfo)19 UserInfoServiceException (com.itrus.portal.exception.UserInfoServiceException)15 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)12 Proxy (com.itrus.portal.db.Proxy)11 ExtraProduct (com.itrus.portal.db.ExtraProduct)10 HashMap (java.util.HashMap)10 OpenBankInfo (com.itrus.portal.db.OpenBankInfo)9 ExtraBill (com.itrus.portal.db.ExtraBill)8 Product (com.itrus.portal.db.Product)8 Project (com.itrus.portal.db.Project)8 File (java.io.File)8 Date (java.util.Date)8 JSONObject (com.alibaba.fastjson.JSONObject)7 Bill (com.itrus.portal.db.Bill)7