Search in sources :

Example 6 with KeyUnlock

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;
}
Also used : KeyUnlock(com.itrus.portal.db.KeyUnlock) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) HashMap(java.util.HashMap) TransactionStatus(org.springframework.transaction.TransactionStatus) UserInfo(com.itrus.portal.db.UserInfo) Date(java.util.Date) UserInfoServiceException(com.itrus.portal.exception.UserInfoServiceException) Bill(com.itrus.portal.db.Bill) UserCert(com.itrus.portal.db.UserCert) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

KeyUnlock (com.itrus.portal.db.KeyUnlock)6 Bill (com.itrus.portal.db.Bill)3 UserInfo (com.itrus.portal.db.UserInfo)3 Date (java.util.Date)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 UserInfoServiceException (com.itrus.portal.exception.UserInfoServiceException)2 HashMap (java.util.HashMap)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 KeyUnlockExample (com.itrus.portal.db.KeyUnlockExample)1 ProjectKeyInfo (com.itrus.portal.db.ProjectKeyInfo)1 UserCert (com.itrus.portal.db.UserCert)1 TransactionStatus (org.springframework.transaction.TransactionStatus)1 DefaultTransactionDefinition (org.springframework.transaction.support.DefaultTransactionDefinition)1