use of com.itrus.portal.db.UserinfoEnterprise in project portal by ixinportal.
the class ClientWebController method getAllInfo.
/**
* 接收客户端传递的项目,用户,企业信息,返回项目下面的的产品信息,如果传递了用户信息和企业信息,则查询是否存在了,不存在则注册.
* @param projectName,项目名称
* @param type,类型.web.app,客户端,目前是客户端,跟发布平台的值相同:{1:"web", 2:"客户端", 3:"app"}
* @param isregister,是否已经注册或者需要更新附加信息的标识.0标识未注册或者需要更新信息,1标识已经注册且是最新信息.由ukey平台传递给客户端,客户端直接回传
* @param keySn,key序列号
* @param certSn,证书序列号
* @param enterprise,企业信息
* @param userInfo,用户信息
* @param businessLicense,营业执照信息
* @param orgCode,组织机构代码信息
* @param taxregisterCert,税务登记信息
* @param identityCard,法人信息
* @param uiModel
* @param request
* @return
*/
@RequestMapping("/getProductInfo")
public String getAllInfo(@RequestParam(value = "projectName", required = true) String projectName, @RequestParam(value = "type", required = true) String type, @RequestParam(value = "isregister", required = true) Integer isregister, @RequestParam(value = "certSn", required = true) String certSn, @RequestParam(value = "keySn", required = false) String keySn, @ModelAttribute("enterprise") Enterprise enterprise, @ModelAttribute("userInfo") UserInfo userInfo, @ModelAttribute("businessLicense") BusinessLicense businessLicense, @ModelAttribute("orgCode") OrgCode orgCode, @ModelAttribute("taxregisterCert") TaxRegisterCert taxregisterCert, @ModelAttribute("identityCard") IdentityCard identityCard, Model uiModel, HttpServletRequest request) {
Map<String, Object> retMap = new HashMap<String, Object>();
// 0标识处理失败,1标识成功
retMap.put("retCode", 0);
// projectName = "宁波CA";
Project project = projectService.getProjectByName(projectName);
HttpSession session = request.getSession();
if (null == project) {
uiModel.addAttribute("errorMsg", "项目名称:" + projectName + ", 在ixin运营服务平台中不存在,请联系系统管理员进行配置");
return "client/errorpage";
}
session.setAttribute("webproject", project);
session.setAttribute("isregister", isregister);
try {
List<ExtraProductRelease> extraProductReleases = extraProductReleaseService.getByprojectAndType(project.getId(), type);
// 获取项目下所有的发布产品
List<ExtraProduct> extraProducts = extraProductService.getproductByEPR(extraProductReleases);
session.setAttribute("webExtraProducts", extraProducts);
// 增值产品的类型
Set<Object> productTypeSet = new LinkedHashSet<>();
for (ExtraProduct ep : extraProducts) {
productTypeSet.add(ep.getAppType());
}
session.setAttribute("webProductTypes", productTypeSet);
// 若用户已经存在了,则标识用户
UserInfo userInfo2 = null;
if (null != userInfo && StringUtils.isNotBlank(userInfo.getmPhone())) {
userInfo2 = userInfoService.getUserInfoByMphone(userInfo.getmPhone());
if (null != userInfo2) {
if (isNeedToUpdateUserInfo(userInfo, userInfo2)) {
userInfo.setId(userInfo2.getId());
userInfoService.updateByPrimaryKeySelective(userInfo);
userInfo2 = userInfoService.getUserInfoByMphone(userInfo.getmPhone());
}
userInfo = userInfo2;
session.setAttribute("webuserInfo", userInfo2);
} else {
// 用户密码取手机号后六位
String password = userInfo.getmPhone().substring(userInfo.getmPhone().length() - 6, userInfo.getmPhone().length());
userInfo = userInfoService.registerUserInfoExtraProduct(userInfo, password, project.getId());
session.setAttribute("webuserInfo", userInfo);
}
}
// 企业信息
Enterprise enterprise2 = null;
if (null != enterprise && StringUtils.isNotBlank(enterprise.getEnterpriseName()) && StringUtils.isNotBlank(enterprise.getEnterpriseSn())) {
enterprise2 = enterpriseService.getEntByName(enterprise.getEnterpriseName());
if (null != enterprise2) {
enterprise = enterprise2;
if (StringUtils.isNotBlank(userInfo.getRegionCodes()) && (StringUtils.isBlank(enterprise.getProvince()) || StringUtils.isBlank(enterprise.getCity()))) {
// 组装企业信息中的企业省,市
String[] regegions = userInfo.getRegionCodes().split("@");
enterprise.setProvince(regegions[1]);
enterprise.setCity(regegions[2]);
enterpriseService.updateEnterprise(enterprise);
}
} else {
if (StringUtils.isNotBlank(userInfo.getRegionCodes()) && (StringUtils.isBlank(enterprise.getProvince()) || StringUtils.isBlank(enterprise.getCity()))) {
// 组装企业信息中的企业省,市
String[] regegions = userInfo.getRegionCodes().split("@");
enterprise.setProvince(regegions[1]);
enterprise.setCity(regegions[2]);
}
enterpriseService.addEnterPrise(enterprise);
}
session.setAttribute("webenterprise", enterprise);
}
if (null != userInfo && null != userInfo.getId() && null != enterprise && null != enterprise.getId()) {
// 若用户和企业之间没有关联关系,则关联起来
UserinfoEnterprise userinfoEnterprise = UserInfoEnterpriseService.selectOne(enterprise.getId(), userInfo.getId());
if (null == userinfoEnterprise) {
UserInfoEnterpriseService.saveUserInfoEnterprise(userInfo.getId(), enterprise.getId());
}
// 保存营业执照.覆盖服务器中最新的信息..如果有则覆盖,没有则新增
if (isregister != 1 && null != businessLicense && StringUtils.isNotBlank(businessLicense.getEnterpriseName()) && StringUtils.isNotBlank(businessLicense.getImgFile()) && StringUtils.isNotBlank(businessLicense.getLicenseNo())) {
// 查询数据库中是否存在该用户,该企业,未关联订单和增值订单.并且认证通过的营业执照信息,如果有的话,就对营业执照进行更新
BusinessLicense oldBl = businessService.getBusinessLicensesNews2(enterprise.getId(), userInfo.getId());
// 判断是否三证合一
if (null == businessLicense.getBusinessType()) {
Integer businessType = 0;
if (businessLicense.getLicenseNo().length() == 18) {
businessType = 1;
// 填充企业纳税人识别号
if (StringUtils.isBlank(enterprise.getNsrsbh())) {
enterprise.setNsrsbh(businessLicense.getLicenseNo());
}
}
businessLicense.setBusinessType(businessType);
}
businessLicense = businessService.saveBusinessExtraBill(enterprise.getId(), enterprise.getEnterpriseSn(), null, userInfo.getId(), businessLicense, ComNames.ITEM_STATUS_2, oldBl);
// 设置企业和附加信息的认证关系
if (null == enterprise.getHasBl()) {
enterprise.setHasBl(businessLicense.getId());
}
}
if (isregister != 1 && null != orgCode && StringUtils.isNotBlank(orgCode.getEnterpriseName()) && StringUtils.isNotBlank(orgCode.getImgFile()) && StringUtils.isNotBlank(orgCode.getOrgCode())) {
OrgCode oldoc = orgCodeService.getOrgCodesNews2(enterprise.getId(), userInfo.getId());
orgCode = orgCodeService.saveOrgCodeExtraBill(enterprise.getId(), enterprise.getEnterpriseSn(), null, userInfo.getId(), orgCode, ComNames.ITEM_STATUS_2, oldoc);
// 设置企业和附加信息的认证关系
if (null == enterprise.getHasOrgCode()) {
enterprise.setHasOrgCode(orgCode.getId());
}
}
if (isregister != 1 && null != taxregisterCert && StringUtils.isNotBlank(taxregisterCert.getEnterpriseName()) && StringUtils.isNotBlank(taxregisterCert.getImgFile()) && StringUtils.isNotBlank(taxregisterCert.getCertNo())) {
TaxRegisterCert oldTaxRegisterCert = taxCertService.getTaxRegisterCertsNews2(enterprise.getId(), userInfo.getId());
taxregisterCert = taxCertService.saveTaxCertExtraBill(enterprise.getId(), enterprise.getEnterpriseSn(), null, userInfo.getId(), taxregisterCert, ComNames.ITEM_STATUS_2, oldTaxRegisterCert);
// 设置企业和附加信息的认证关系
if (null == enterprise.getHasTaxCert()) {
enterprise.setHasTaxCert(taxregisterCert.getId());
}
// 填充企业纳税人识别号
if (StringUtils.isBlank(enterprise.getNsrsbh())) {
enterprise.setNsrsbh(taxregisterCert.getCertNo());
}
}
if (isregister != 1 && null != identityCard && StringUtils.isNotBlank(identityCard.getEnterpriseName()) && StringUtils.isNotBlank(identityCard.getName()) && StringUtils.isNotBlank(identityCard.getFrontImg())) {
IdentityCard oldIdentityCard = identityCardService.getIdentityCardsNews2(enterprise.getId(), userInfo.getId());
identityCard = identityCardService.saveIdentityCardExtraBillFromUkey(enterprise.getId(), enterprise.getEnterpriseSn(), null, userInfo.getId(), identityCard, ComNames.ITEM_STATUS_2, oldIdentityCard);
// 设置企业和附加信息的认证关系
if (null == enterprise.getHasIdCard()) {
enterprise.setHasIdCard(identityCard.getId());
}
}
enterpriseService.updateEnterprise(enterprise);
}
// 如果用户是第一次来登录,并且用户没有通过认证,则不能认为用户认证通过了.(只有当本次输入是没有注册过,并且本次有通过认证的附加信息项,才能认为本次是注册成功了.)
boolean hasOnePass = (null != businessLicense && null != businessLicense.getId()) || (null != orgCode && null != orgCode.getId()) || (null != taxregisterCert && null != taxregisterCert.getId()) || (null != identityCard && null != identityCard.getId());
if (isregister != 1 && (null != userInfo.getId() && null != enterprise.getId()) && hasOnePass) {
ixinUkeyRegrecordService.insertOrUpdate(keySn, certSn);
// 判定用户是否已经在本平台注册成功.是否可以开始购买
boolean isCanBuy = isCanBuy(enterprise, businessLicense, taxregisterCert, orgCode, identityCard);
if (isCanBuy) {
session.setAttribute("isregister", 1);
}
}
UserLog userlog = new UserLog();
userlog.setCreateTime(new Date());
userlog.setHostId("未知");
if (null == userInfo2) {
userlog.setInfo("用户登录" + userInfo.getmPhone());
userlog.setType("用户登录_增值产品");
} else {
userlog.setInfo("用户注册:" + userInfo.getmPhone());
userlog.setType("用户注册_增值产品");
}
userlog.setProject(project.getId());
userlog.setSn(null == userInfo.getUniqueId() ? null : userInfo.getUniqueId());
LogUtil.userlog(sqlSession, userlog);
} catch (Exception e) {
UserLog userlog = new UserLog();
userlog.setCreateTime(new Date());
userlog.setHostId("未知");
userlog.setInfo("增值订单用户注册出现异常,异常信息:" + e.getMessage());
userlog.setProject(project.getId());
userlog.setType("用户登录_增值产品");
userlog.setSn(null == userInfo.getUniqueId() ? null : userInfo.getUniqueId());
LogUtil.userlog(sqlSession, userlog);
}
return "client/yingyongzhanshi";
}
use of com.itrus.portal.db.UserinfoEnterprise in project portal by ixinportal.
the class UserInfoEnterpriseServiceImpl method saveUserInfoEnterprise.
/**
* 保存用户-企业关联关系
*
* @param userInfoId
* @param enterpriseId
* @return
*/
public UserinfoEnterprise saveUserInfoEnterprise(Long userInfoId, Long enterpriseId) {
// 需先判断关联关系是否已经存在,存在则不添加,不存在则添加
UserinfoEnterprise userinfoEnterprise = new UserinfoEnterprise();
userinfoEnterprise.setUserInfo(userInfoId);
userinfoEnterprise.setEnterprise(enterpriseId);
sqlSession.insert("com.itrus.portal.db.UserinfoEnterpriseMapper.insertByUnique", userinfoEnterprise);
sqlSession.flushStatements();
return userinfoEnterprise;
}
use of com.itrus.portal.db.UserinfoEnterprise in project portal by ixinportal.
the class UnlockKeyBillController method submitUnlockBill.
/**
* 提交解锁订单
* @param productId,购买产品的id
* @param certSn
* @param keySn
* @param einvoice
* @param proxy
* @param request
* @return
*/
@RequestMapping("/submitUnlockBill")
@ResponseBody
public Map<String, Object> submitUnlockBill(@RequestParam("productId") Long productId, @RequestParam("certSn") String certSn, @RequestParam("keySn") String keySn, @RequestParam("keyType") String keyType, @RequestParam("enterpriseName") String enterpriseName, @RequestParam("reqCode") String reqCode, @ModelAttribute("einvoice") Einvoice einvoice, @ModelAttribute("userInfo") UserInfo userInfo, @ModelAttribute("enterprise") Enterprise enterprise, @ModelAttribute("proxy") Proxy proxy, HttpServletRequest request) {
Map<String, Object> retMap = new HashMap<String, Object>();
retMap.put("retCode", 0);
HttpSession session = request.getSession();
UserCert userCert = userCertService.getUserCertByCertSn(certSn);
if (StringUtils.isBlank(keySn)) {
retMap.put("retMsg", "key序列号不能为空");
return retMap;
}
if (StringUtils.isBlank(reqCode)) {
retMap.put("retMsg", "解锁请求码不能为空");
return retMap;
}
if (null == userCert) {
retMap.put("retMsg", "该证书未注册,请您先注册");
return retMap;
}
if (StringUtils.isBlank(userCert.getKeySn()) || !keySn.equals(userCert.getKeySn())) {
userCert.setKeySn(keySn);
userCertService.updateByPrimaryKeySelective(userCert);
}
UserInfo webUserInfo = null;
if (null == userInfo || StringUtils.isBlank(userInfo.getmPhone())) {
retMap.put("retMsg", "用户信息不完整,请重新提交");
return retMap;
} else {
webUserInfo = userInfoService.getUserInfoByMphone(userInfo.getmPhone());
}
if (null == webUserInfo) {
retMap.put("retMsg", "手机号:" + userInfo.getmPhone() + ", 尚未注册或者校验通过,请检查您输入的手机号是否正确!");
return retMap;
}
Enterprise enterpriseByName = enterpriseService.getEntByName(enterpriseName);
if (null == enterpriseByName) {
// 若新提交的企业信息为null或者信息不全,则提示
if (null == enterprise || StringUtils.isBlank(enterprise.getEnterpriseName()) || null == enterprise.getEnterpriseNature() || StringUtils.isBlank(enterprise.getEnterpriseSn())) {
retMap.put("retMsg", "企业信息不完整,请重新提交");
return retMap;
} else {
// 保存新增的企业信息
enterprise = enterpriseService.saveOrUpdateEnterprise(enterprise);
// 添加企业-代理人关联关系
UserinfoEnterprise userinfoEnterprise = userInfoEnterpriseServiceImpl.selectOne(enterprise.getId(), webUserInfo.getId());
if (null == userinfoEnterprise) {
userInfoEnterpriseServiceImpl.saveUserInfoEnterprise(webUserInfo.getId(), enterprise.getId());
}
}
} else {
enterprise = enterpriseByName;
}
Product product = productService.getProduct(productId);
if (null == product) {
retMap.put("retMsg", "您选择的产品不存在");
return retMap;
}
if (null == product.getKeyUnlockType()) {
retMap.put("retMsg", "您选择的产品不属于解锁产品,请重新选择");
return retMap;
}
if (null == userCert.getUserinfo() && product.getKeyUnlockType().equals(ComNames.KEY_UNLOCK_TYPE_1)) {
retMap.put("retMsg", "未绑定用户的证书,不能购买自助解锁产品");
return retMap;
}
Bill billOld = billService.getBillWaitingForUnlock(userCert.getId());
if (null != billOld) {
retMap.put("retMsg", "当前证书尚有未解锁的订单,请先在原订单解锁,订单号:" + billOld.getBillId());
return retMap;
}
Project project = projectService.selectByPrimaryKey(product.getProject());
DefaultTransactionDefinition dtd = new DefaultTransactionDefinition();
dtd.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
TransactionStatus status = transactionManager.getTransaction(dtd);
try {
if (StringUtils.isNotBlank(userInfo.getEmail()) && StringUtils.isBlank(webUserInfo.getEmail())) {
webUserInfo.setEmail(userInfo.getEmail());
userInfoService.updateUserInfo(webUserInfo);
}
if (StringUtils.isNotBlank(einvoice.getName()) && null != einvoice.geteReiceipt()) {
einvoice = EinvoiceService.saveEInvoice(webUserInfo.getId(), einvoice);
}
Bill bill = null;
// 生成订单
double billSum = product.getPrice();
bill = billService.saveBill(webUserInfo.getId(), enterprise.getId(), product.getId(), null, null, null == einvoice.getId() ? null : einvoice.getId(), null, product.getProject(), 1, billSum, webUserInfo.getId(), ComNames.BILL_STATUS_1);
bill.setBillId(UniqueIDUtils.genBilUID(bill));
bill.setUnlockUserCert(userCert.getId());
sqlSession.update("com.itrus.portal.db.BillMapper.updateByPrimaryKey", bill);
keyUnlockService.insert(bill.getId(), project.getId(), keySn, certSn, enterpriseName, keyType, "ENROLL", product.getKeyUnlockType() == 1 ? 1 : 2, reqCode);
sqlSession.flushStatements();
if (null != proxy && StringUtils.isNotBlank(proxy.getImgFile())) {
// 保存授权书
proxy = proxyService.saveProxy(enterprise.getId(), webUserInfo.getUniqueId(), bill.getId(), webUserInfo.getId(), proxy, project);
}
transactionManager.commit(status);
retMap.put("billId", bill.getId());
retMap.put("retCode", 1);
// 将用户信息放入session中,避免支付出错
session.setAttribute(ComNames.WEB_USER_INFO, webUserInfo);
// 记录日志
LogUtil.userlog(sqlSession, project.getId(), "购买解锁产品", webUserInfo.getmPhone() + "购买了" + product.getName(), "未知", "", null == webUserInfo.getUniqueId() ? null : webUserInfo.getUniqueId());
return retMap;
} catch (Exception e) {
if (!status.isCompleted())
transactionManager.rollback(status);
UserLog userlog = new UserLog();
userlog.setProject(project.getId());
userlog.setType("购买解锁产品");
userlog.setInfo("url:submitUnlockBill,详细错误:" + 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);
}
}
}
use of com.itrus.portal.db.UserinfoEnterprise in project portal by ixinportal.
the class UnlockKeyBillController method checkUserAndEnterpriseInfo.
/**
* 证书解锁第一步:校验key,证书对应的用户信息,企业信息是否存在.
* 如果用户信息企业信息存在,则跳转列表页面
* 如果不存在,则跳转
*/
@RequestMapping(value = "/checkUserEntInfo", method = RequestMethod.POST)
public String checkUserAndEnterpriseInfo(@RequestParam(value = "certBase64", required = true) String certBase64, @RequestParam("certSn") String certSn, @RequestParam("keySn") String keySn, @RequestParam("enterpriseName") String enterpriseName, Model uiModel, HttpServletRequest request) {
UserCert userCert = null;
Enterprise enterprise = null;
try {
userCert = userCertService.getUserCertByCertSn(certSn);
enterprise = enterpriseService.getEntByName(enterpriseName);
if (null == userCert) {
userCert = userCertService.getUserCert(certBase64);
}
// 若外部证书第一次就忘记了口令,则需要记录keysn
if (StringUtils.isBlank(userCert.getKeySn()) || !keySn.equals(userCert.getKeySn())) {
userCert.setKeySn(keySn);
userCertService.updateByPrimaryKeySelective(userCert);
}
// 查看用户和企业是否已经关联起来了,没关联则关联起来
if (null != userCert.getUserinfo() && null != enterprise) {
UserinfoEnterprise userinfoEnterprise = userInfoEnterpriseService.selectOne(enterprise.getId(), userCert.getUserinfo());
if (null == userinfoEnterprise) {
userInfoEnterpriseService.saveUserInfoEnterprise(userCert.getUserinfo(), enterprise.getId());
}
}
} catch (Exception e) {
log.error(e.getMessage());
uiModel.addAttribute("errorMsg", "出现异常,异常信息:" + e.getMessage());
return ComNames.CLIENTFW_ERRORPAGE;
}
return "forward:/unlockKeyBill/getUnlockProducts";
}
use of com.itrus.portal.db.UserinfoEnterprise 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;
}
}
Aggregations