use of com.itrus.portal.db.KeyUnlock in project portal by ixinportal.
the class DoUnlockKeyController method unlockResult.
/**
* 解锁结果.
* @param isUnlockSuccess,是否解锁成功.true解锁成功,false解锁失败
* @param certSn
* @param keySn
* @param enterpriseName
* @param newPassword
* @param uiModel
* @return
*/
@RequestMapping("/unlockResult")
@ResponseBody
public Map<String, Object> unlockResult(@RequestParam("isUnlockSuccess") Boolean isUnlockSuccess, @RequestParam("billId") Long billId, @RequestParam("certSn") String certSn, @RequestParam("keySn") String keySn, @RequestParam(value = "enterpriseName", required = false) String enterpriseName, @RequestParam("newPassword") String newPassword, @RequestParam(value = "errorMsg", required = false) String errorMsg, Model uiModel, HttpSession session) {
Map<String, Object> retMap = new HashMap<String, Object>();
retMap.put("retCode", 0);
boolean verifyCodeZSJS = (boolean) session.getAttribute("verifyCodeZSJS");
if (!verifyCodeZSJS) {
// 查看解锁短信验证是否成功
retMap.put("retMsg", "短信验证失败");
return retMap;
}
session.removeAttribute("verifyCodeZSJS");
DefaultTransactionDefinition dtd = new DefaultTransactionDefinition();
dtd.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
TransactionStatus status = transactionManager.getTransaction(dtd);
UserInfo userInfo = null;
Bill bill = null;
try {
bill = billService.getBill(billId);
if (null == bill) {
retMap.put("retMsg", "订单不存在");
return retMap;
}
userInfo = userInfoService.getUserInfoById(bill.getUniqueId());
KeyUnlock keyUnlock = keyUnlockService.getKeyUnlockByBillId(billId);
if (null == keyUnlock) {
retMap.put("retMsg", "解锁信息不存证");
return retMap;
}
UserCert userCert = userCertService.getUserCertByCertSn(certSn);
if (isUnlockSuccess) {
// 解锁成功,若不需要开票,则直接完成
if (null == bill.geteInvoice() && null == bill.getInvoice()) {
bill.setBillStatus(ComNames.BILL_STATUS_8);
} else {
// 需要开票,校验是否已经开票了
if (null != bill.getIsInvoiced() && bill.getIsInvoiced().equals(1)) {
bill.setBillStatus(ComNames.BILL_STATUS_8);
} else {
bill.setBillStatus(ComNames.BILL_STATUS_18);
}
}
keyUnlock.setUnlockTime(new Date());
keyUnlock.setStatus("UNLOCK");
// 审批解锁成功后,证书和手机号绑定成功,无需登录时再次绑定
if (null == userCert.getUserinfo() || !userCert.getUserinfo().equals(userInfo.getId())) {
userCert.setUserinfo(userInfo.getId());
if (null == userCert.getEnterprise()) {
userCert.setEnterprise(bill.getEnterprise());
}
// 若进行管理员解锁,且订单用户与证书绑定用户不一致,则更换证书所绑定的用户为当前订单用户
if (null != userCert.getUserinfo() && !userCert.getUserinfo().equals(userInfo.getId())) {
userCert.setUserinfo(userInfo.getId());
}
userCertService.updateByPrimaryKeySelective(userCert);
}
} else {
// 解锁异常
bill.setBillStatus(ComNames.BILL_STATUS_17);
}
billService.updateBill(bill);
keyUnlockService.updateByPrimaryKey(keyUnlock);
transactionManager.commit(status);
if (isUnlockSuccess) {
LogUtil.userlog(sqlSession, bill.getProject(), "证书解锁", "解锁成功,keySn:" + keySn, "未知", "", null == userInfo.getUniqueId() ? null : userInfo.getUniqueId());
} else {
LogUtil.userlog(sqlSession, bill.getProject(), "证书解锁", "解锁失败,keySn:" + keySn + ", 错误信息" + errorMsg, "未知", "", null == userInfo.getUniqueId() ? null : userInfo.getUniqueId());
}
retMap.put("retCode", 1);
} catch (Exception e) {
if (!status.isCompleted()) {
transactionManager.rollback(status);
}
LogUtil.userlog(sqlSession, bill.getProject(), "证书解锁", "解锁异常,keySn:" + keySn + "异常信息:" + e.getMessage(), "未知", "", null == userInfo.getUniqueId() ? null : userInfo.getUniqueId());
retMap.put("retMsg", "证书解锁出现异常,请联系系统管理员进行处理!");
} finally {
if (!status.isCompleted()) {
transactionManager.rollback(status);
}
}
return retMap;
}
Aggregations