package com.goafanti.user.controller; import java.math.BigDecimal; import java.text.ParseException; import java.util.Arrays; import java.util.UUID; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.validation.Valid; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Controller; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import com.goafanti.cognizance.bo.InputOrgHumanResource; import com.goafanti.cognizance.service.OrgRatepayService; import com.goafanti.common.bo.Result; import com.goafanti.common.constant.AFTConstants; import com.goafanti.common.constant.ErrorConstants; import com.goafanti.common.controller.BaseApiController; import com.goafanti.common.enums.DeleteStatus; import com.goafanti.common.enums.IdentityAuditStatus; import com.goafanti.common.enums.IdentityProcess; import com.goafanti.common.enums.OrgHumanResourceFields; import com.goafanti.common.enums.OrgProFields; import com.goafanti.common.enums.OrganizationIdentityFields; import com.goafanti.common.enums.OrganizationTechFields; import com.goafanti.common.enums.UserAbilityFields; import com.goafanti.common.enums.UserCareerFields; import com.goafanti.common.enums.UserEduFields; import com.goafanti.common.enums.UserIdentityFields; import com.goafanti.common.enums.UserInfoBoFields; import com.goafanti.common.enums.UserType; import com.goafanti.common.model.OrgHumanResource; import com.goafanti.common.model.OrganizationIdentity; import com.goafanti.common.model.OrganizationInfo; import com.goafanti.common.model.OrganizationProperties; import com.goafanti.common.model.OrganizationTech; import com.goafanti.common.model.User; import com.goafanti.common.model.UserAbility; import com.goafanti.common.model.UserCareer; import com.goafanti.common.model.UserEdu; import com.goafanti.common.model.UserIdentity; import com.goafanti.common.model.UserInfo; import com.goafanti.common.utils.DateUtils; import com.goafanti.common.utils.PasswordUtil; import com.goafanti.common.utils.TimeUtils; import com.goafanti.common.utils.VerifyCodeUtils; import com.goafanti.core.shiro.token.TokenManager; import com.goafanti.techproject.service.TechWebsiteService; import com.goafanti.user.bo.InputOrgPro; import com.goafanti.user.bo.InputOrganizationTech; import com.goafanti.user.bo.InputUserAbility; import com.goafanti.user.bo.InputUserCareer; import com.goafanti.user.bo.InputUserEdu; import com.goafanti.user.bo.InputUserIdentity; import com.goafanti.user.bo.OrgIdentityBo; import com.goafanti.user.bo.OrgProBo; import com.goafanti.user.bo.UidAndTypeBo; import com.goafanti.user.bo.UserIdentityBo; import com.goafanti.user.bo.UserInfoBo; import com.goafanti.user.service.OrgHumanResourceService; import com.goafanti.user.service.OrganizationIdentityService; import com.goafanti.user.service.OrganizationInfoService; import com.goafanti.user.service.OrganizationPropertiesService; import com.goafanti.user.service.OrganizationTechService; import com.goafanti.user.service.UserAbilityService; import com.goafanti.user.service.UserCareerService; import com.goafanti.user.service.UserEduService; import com.goafanti.user.service.UserIdentityService; import com.goafanti.user.service.UserInfoService; import com.goafanti.user.service.UserService; @Controller @RequestMapping(value = "/api/user") public class UserApiController extends BaseApiController { @Resource private UserService userService; @Resource(name = "passwordUtil") private PasswordUtil passwordUtil; @Resource private UserIdentityService userIdentityService; @Resource private UserInfoService userInfoService; @Resource private UserEduService userEduService; @Resource private UserCareerService userCareerService; @Resource private UserAbilityService userAbilityService; @Resource private OrganizationIdentityService organizationIdentityService; @Resource private OrganizationInfoService organizationInfoService; @Resource private OrganizationTechService organizationTechService; @Resource private OrganizationPropertiesService organizationPropertiesService; @Resource private OrgHumanResourceService orgHumanResourceService; @Resource private TechWebsiteService techWebsiteService; @Resource private OrgRatepayService orgRatepayService; private static final Integer STEP_ONE = 1; // private static final Integer STEP_TWO = 2; private static final Integer STEP_THREE = 3; // private static final Integer STEP_FOUR = 4; private static final Integer STEP_FIVE = 5; private static final Integer MAX_WRONG_COUNT = 3; private static final Integer INIT_WRONG_COUNT = 0; /** * 修改密码 * * @param password * @param newPassword * @return */ @RequestMapping(value = "/pwd", method = RequestMethod.POST) public Result updatePwd(String password, String newPassword) { Result res = new Result(); if (StringUtils.isBlank(password) || StringUtils.isBlank(newPassword)) { res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "必须指定", "密码")); } if (password.equals(newPassword)) { res.getError().add(buildError(ErrorConstants.PWD_SAME_ERROR, "新密码必须与原密码不同!")); } if (res.getError().isEmpty() && TokenManager.isLogin()) { User u = new User(); User user = userService.selectByPrimaryKey(TokenManager.getUserId()); u.setId(user.getId()); u.setCreateTime(user.getCreateTime()); u.setPassword(newPassword); u.setPassword(passwordUtil.getEncryptPwd(u)); if (!user.getPassword().equals(passwordUtil.getEncryptPwd(password, user.getCreateTime()))) { res.getError().add(buildError(ErrorConstants.PWD_NOT_MATCH_ERROR)); } else { res.setData(userService.updateByPrimaryKeySelective(u)); } } return res; } /** * 更换手机 * * @param mobile * @param mobileCode * @return */ @RequestMapping(value = "/mobile", method = RequestMethod.POST) public Result updateMobile(String mobile, String mobileCode) { Result res = new Result(); if (StringUtils.isBlank(mobile)) { res.getError().add(buildError(ErrorConstants.MOBILE_EMPTY_ERROR, "手机号不能为空!")); return res; } if (StringUtils.isBlank(mobileCode)) { res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "手机验证码")); return res; } // 验证码15分钟有效 if (TimeUtils.checkOverTime("register")) { res.getError().add(buildError(ErrorConstants.MCODE_OVERTIME_ERROR, "手机验证码超时失效")); return res; } if (!TokenManager.getSession().getAttribute(VerifyCodeUtils.M_CODE).equals(mobileCode)) { res.getError().add(buildError(ErrorConstants.MCODE_ERROR, "手机验证码错误")); return res; } User user = userService.selectByPrimaryKey(TokenManager.getUserId()); if (mobile.equals(user.getMobile())) { res.getError().add(buildError(ErrorConstants.MOBILE_SAME_ERROR, "新手机号必须和原手机号不同!")); return res; } if (res.getError().isEmpty() && TokenManager.isLogin()) { user.setMobile(mobile); res.setData(userService.updateByPrimaryKey(user)); } return res; } /** * 个人会员基本信息 * * @param userIdentity * @param bindingResult * @return */ @RequestMapping(value = "/userIndentity", method = RequestMethod.POST) public Result basicInfo(@Valid InputUserIdentity userIdentity, BindingResult bindingResult) { Result res = new Result(); if (bindingResult.hasErrors()) { res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(), UserIdentityFields.getFieldDesc(bindingResult.getFieldError().getField()))); return res; } if (res.getError().isEmpty()) { UserIdentity ui = new UserIdentity(); BeanUtils.copyProperties(userIdentity, ui); if (StringUtils.isBlank(ui.getId())) { ui.setId(UUID.randomUUID().toString()); ui.setUid(TokenManager.getUserId()); userIdentityService.insert(ui); } else { userIdentityService.updateByPrimaryKeySelective(ui); } } res.setData(userIdentity); return res; } /** * 公共 * * @param req * @return */ @RequestMapping(value = "/avatar/upload", method = RequestMethod.POST) public Result avatar(HttpServletRequest req) { Result res = new Result(); res.setData(handleFile(res, "/avatar/", false, req, "")); return res; } /** * 公共可替换 */ @RequestMapping(value = "/avatar/uploadReplace", method = RequestMethod.POST) public Result avatarReplace(HttpServletRequest req, String sign) { Result res = new Result(); res.setData(handleFile(res, "/avatar/", false, req, sign)); return res; } /** * 认证 * * @param req * @return */ @RequestMapping(value = "/identity/upload", method = RequestMethod.POST) public Result identityFile(HttpServletRequest req, String sign) { Result res = new Result(); res.setData(handleFile(res, "/identity/", true, req, sign)); return res; } /** * 个人资料 * * @param userInfoBo * @param bindingResult * @return */ @RequestMapping(value = "/userInfo", method = RequestMethod.POST) public Result personalData(@Valid UserInfoBo userInfoBo, BindingResult bindingResult) { Result res = new Result(); if (bindingResult.hasErrors()) { res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(), UserInfoBoFields.getFieldDesc(bindingResult.getFieldError().getField()))); return res; } if (res.getError().isEmpty()) { User u = userService.selectByPrimaryKey(TokenManager.getUserId()); u.setNickname(userInfoBo.getNickname()); u.setEmail(userInfoBo.getEmail()); userService.updateByPrimaryKeySelective(u); UserInfo ui = new UserInfo(); BeanUtils.copyProperties(userInfoBo, ui); if (StringUtils.isBlank(ui.getId())) { ui.setId(UUID.randomUUID().toString()); ui.setUid(TokenManager.getUserId()); userInfoService.insert(ui); } else { userInfoService.updateByPrimaryKeySelective(ui); } } res.setData(userInfoBo); return res; } /** * 个人会员教育信息 * * @param userEdu * @return */ @RequestMapping(value = "/userEdu", method = RequestMethod.POST) public Result educationInfo(@Valid InputUserEdu userEdu, BindingResult bindingResult) { Result res = new Result(); if (bindingResult.hasErrors()) { res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(), UserEduFields.getFieldDesc(bindingResult.getFieldError().getField()))); return res; } UserEdu ue = new UserEdu(); BeanUtils.copyProperties(userEdu, ue); if (StringUtils.isBlank(ue.getId())) { ue.setId(UUID.randomUUID().toString()); ue.setUid(TokenManager.getUserId()); userEduService.insert(ue); } else { userEduService.updateByPrimaryKeySelective(ue); } res.setData(userEdu); return res; } /** * 个人会员职业信息 * * @param userCareer * @return */ @RequestMapping(value = "/userCareer", method = RequestMethod.POST) public Result careerInfo(@Valid InputUserCareer userCareer, BindingResult bindingResult) { Result res = new Result(); if (bindingResult.hasErrors()) { res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(), UserCareerFields.getFieldDesc(bindingResult.getFieldError().getField()))); return res; } UserCareer uc = new UserCareer(); BeanUtils.copyProperties(userCareer, uc); if (StringUtils.isBlank(uc.getId())) { uc.setId(UUID.randomUUID().toString()); uc.setUid(TokenManager.getUserId()); userCareerService.insert(uc); } else { userCareerService.updateByPrimaryKeySelective(uc); } res.setData(userCareer); return res; } /** * 会员能力标签 * * @param userAbility * @return */ @RequestMapping(value = "/userAbility", method = RequestMethod.POST) public Result abilityLabel(@Valid InputUserAbility userAbility, BindingResult bindingResult) { Result res = new Result(); if (bindingResult.hasErrors()) { res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(), UserAbilityFields.getFieldDesc(bindingResult.getFieldError().getField()))); return res; } UserAbility ua = new UserAbility(); BeanUtils.copyProperties(userAbility, ua); if (StringUtils.isBlank(ua.getId())) { ua.setId(UUID.randomUUID().toString()); ua.setUid(TokenManager.getUserId()); userAbilityService.insert(ua); } else { userAbilityService.updateByPrimaryKeySelective(ua); } res.setData(userAbility); return res; } /** * 团体会员基本信息 * * @param orgIdentityBo * @return */ @RequestMapping(value = "/orgIdentity", method = RequestMethod.POST) public Result groupBasicInfo(@Valid OrgIdentityBo orgIdentityBo, BindingResult bindingResult) { Result res = new Result(); if (bindingResult.hasErrors()) { res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(), OrganizationIdentityFields.getFieldDesc(bindingResult.getFieldError().getField()))); return res; } OrganizationIdentity oi = new OrganizationIdentity(); BeanUtils.copyProperties(orgIdentityBo, oi); User u = userService.selectByPrimaryKey(TokenManager.getUserId()); u.setEmail(orgIdentityBo.getEmail()); userService.updateByPrimaryKeySelective(u); if (StringUtils.isBlank(oi.getId())) { oi.setId(UUID.randomUUID().toString()); oi.setUid(TokenManager.getUserId()); organizationIdentityService.insert(oi); } else { organizationIdentityService.updateByPrimaryKeySelective(oi); } res.setData(orgIdentityBo); return res; } /** * 团体会员单位资料 * * @param orgInfo * @return */ @RequestMapping(value = "/orgPro", method = RequestMethod.POST) public Result groupProInfo(@Valid InputOrgPro pro, BindingResult bindingResult) { Result res = new Result(); if (bindingResult.hasErrors()) { res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(), OrgProFields.getFieldDesc(bindingResult.getFieldError().getField()))); return res; } OrganizationInfo oi = new OrganizationInfo(); OrganizationProperties op = new OrganizationProperties(); BeanUtils.copyProperties(pro, oi); BeanUtils.copyProperties(pro, op); oi.setId(pro.getIid()); op.setId(pro.getPid()); organizationInfoService.insertInfoAndPro(oi, op); res.setData(pro); return res; } /** * 团体会员技术能力 * * @param orgTech * @return */ @RequestMapping(value = "/orgTech", method = RequestMethod.POST) public Result tech(@Valid InputOrganizationTech orgTech, BindingResult bindingResult) { Result res = new Result(); if (bindingResult.hasErrors()) { res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(), OrganizationTechFields.getFieldDesc(bindingResult.getFieldError().getField()))); return res; } OrganizationTech ot = new OrganizationTech(); BeanUtils.copyProperties(orgTech, ot); if (StringUtils.isBlank(ot.getId())) { ot.setId(UUID.randomUUID().toString()); ot.setUid(TokenManager.getUserId()); organizationTechService.insert(ot); } else { organizationTechService.updateByPrimaryKeySelective(ot); } res.setData(orgTech); return res; } /** * 个人会员基本信息/团体会员基本信息 * * @return */ @RequestMapping(value = "/base", method = RequestMethod.GET) public Result basic() { Result res = new Result(); UidAndTypeBo ub = basicInfo(userService); if (UserType.PERSONAL.getCode().equals(ub.getType())) { UserIdentityBo u = userIdentityService.selectUserIdentityBoByUserId(ub.getUid()); res.setData(u); } else { OrgIdentityBo o = organizationIdentityService.selectOrgIdentityBoByUserId(ub.getUid()); res.setData(o); } return res; } /** * 个人资料/团体会员资料 */ @RequestMapping(value = "/member", method = RequestMethod.GET) public Result member() { Result res = new Result(); UidAndTypeBo ub = basicInfo(userService); if (UserType.PERSONAL.getCode().equals(ub.getType())) { UserInfoBo u = userInfoService.selectUserInfoBoByUserId(ub.getUid()); res.setData(u); } else { OrganizationInfo o = organizationInfoService.selectOrgInfoByUserId(ub.getUid()); OrganizationProperties p = organizationPropertiesService.selectOrgProByUserId(ub.getUid()); res.setData(new OrgProBo(o, p)); } return res; } /** * 个人会员教育信息 * * @return */ @RequestMapping(value = "/educate", method = RequestMethod.GET) public Result educate() { Result res = new Result(); UidAndTypeBo ub = basicInfo(userService); if (null != ub) { UserEdu u = userEduService.selectUserEduByUserId(ub.getUid()); res.setData(u); } return res; } /** * 个人会员职业信息/团体会员技术能力 * * @return */ @RequestMapping(value = "/job", method = RequestMethod.GET) public Result job() { Result res = new Result(); UidAndTypeBo ub = basicInfo(userService); if (UserType.PERSONAL.getCode().equals(ub.getType())) { UserCareer u = userCareerService.selectUserCareerByUserId(ub.getUid()); res.setData(u); } else { OrganizationTech o = organizationTechService.selectOrgTechByUserId(ub.getUid()); res.setData(o); } return res; } /** * 个人/团体能力标签 * * @return */ @RequestMapping(value = "/ability", method = RequestMethod.GET) public Result ability() { Result res = new Result(); UidAndTypeBo ub = basicInfo(userService); if (null != ub) { UserAbility u = userAbilityService.selectUserAbilityByUserId(ub.getUid()); res.setData(u); } return res; } /** * 团体人力资源情况入口 * * @return */ @RequestMapping(value = "/humanResource", method = RequestMethod.GET) @ResponseBody public Result humanResource(Integer year, String pageNo, String pageSize) { Result res = new Result(); res = checkCertify(res); if (res.getError().isEmpty()) { Integer pNo = 1; Integer pSize = 10; if (StringUtils.isNumeric(pageSize)) { pSize = Integer.parseInt(pageSize); } if (StringUtils.isNumeric(pageNo)) { pNo = Integer.parseInt(pageNo); } res.setData(orgHumanResourceService.listOrgHumanResource(year, pNo, pSize, TokenManager.getUserId())); } return res; } /** * 团体人力资源情况新增修改保存(用户端) * * @param orgHumanResource * @return */ @RequestMapping(value = "/SaveHumanResource", method = RequestMethod.POST) public Result SaveHumanResource(@Valid InputOrgHumanResource ohr, BindingResult bindingResult) { Result res = new Result(); if (bindingResult.hasErrors()) { res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(), OrgHumanResourceFields.getFieldDesc(bindingResult.getFieldError().getField()))); return res; } if (null == ohr.getYear()) { res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "年份")); return res; } OrgHumanResource orgHumanResource = new OrgHumanResource(); BeanUtils.copyProperties(ohr, orgHumanResource); if (StringUtils.isBlank(orgHumanResource.getId())) { if (null != orgHumanResourceService.selectOrgHumanResourceByUidAndYear(orgHumanResource.getYear(), TokenManager.getUserId())) { res.getError().add(buildError(ErrorConstants.DUPLICATE_DATA_ERROR, "当年度人力资源情况已录入!")); return res; } orgHumanResource.setId(UUID.randomUUID().toString()); orgHumanResource.setUid(TokenManager.getUserId()); orgHumanResource.setDeletedSign(DeleteStatus.UNDELETE.getCode()); orgHumanResourceService.insert(orgHumanResource); } else { orgHumanResourceService.updateByPrimaryKeySelective(orgHumanResource); } return res; } /** * 删除团体人力资源 * * @return */ @RequestMapping(value = "/deleteHumanResource", method = RequestMethod.POST) public Result deleteHumanResource(@RequestParam(name = "ids[]", required = false) String[] ids) { Result res = new Result(); if (ids == null || ids.length < 1) { res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "")); } else { orgHumanResourceService.batchDeleteByPrimaryKey(Arrays.asList(ids)); } return res; } /** * 首页 * * @return */ @RequestMapping(value = "/homePage", method = RequestMethod.GET) public Result homePage() { Result res = new Result(); res.setData(userService.selectUserPageHomeBoByUserId(TokenManager.getUserId())); return res; } /** * 登陆后返回用户基本信息 * * @return */ @RequestMapping(value = "/afterSignIn", method = RequestMethod.GET) public Result afterSignIn() { Result res = new Result(); if (TokenManager.isLogin()) { User u = userService.selectByPrimaryKey(TokenManager.getUserId()); res.setData(u); } return res; } /** * 个人实名认证流程入口 * * @return */ @RequestMapping(value = "/userPro", method = RequestMethod.GET) public Result userProcess() { Result res = new Result(); if (TokenManager.isLogin()) { res.setData(userIdentityService.selectUserIdentityByUserId(TokenManager.getUserId())); } return res; } /** * 个人实名认证流程下一步 */ @RequestMapping(value = "/userNextPro", method = RequestMethod.POST) public Result userNextProcess(UserIdentity userIdentity, String verificationCode) { Result res = new Result(); if (null == userIdentity.getProcess()) { res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "process")); return res; } if (STEP_ONE.equals(userIdentity.getProcess())) { if (StringUtils.isBlank(verificationCode)) { res.getError().add(buildError(ErrorConstants.VCODE_EMPTY_ERROR)); return res; } if (!VerifyCodeUtils.verifyCode(verificationCode)) { res.getError().add(buildError(ErrorConstants.VCODE_ERROR)); return res; } } else if (STEP_THREE.equals(userIdentity.getProcess())) { UserIdentity u = userIdentityService.selectUserIdentityByUserId(TokenManager.getUserId()); u.setProcess(IdentityProcess.COMMITTED.getCode()); u.setAuditStatus(IdentityAuditStatus.COMMITTED.getCode()); userIdentityService.updateByPrimaryKeySelective(u); return res; } else if (STEP_FIVE.equals(userIdentity.getProcess())) { UserIdentity u = userIdentityService.selectUserIdentityByUserId(TokenManager.getUserId()); if ((System.currentTimeMillis() - u.getPaymentDate().getTime()) > 432000000) { u.setAuditStatus(IdentityAuditStatus.NOTPASSED.getCode());// 4 userIdentityService.updateByPrimaryKeySelective(u); res.getError().add(buildError(ErrorConstants.IDENTITY_PAY_OVER_TIME));// 超过打款日期5日,无法提交确认 return res; } if (MAX_WRONG_COUNT.equals(u.getWrongCount())) { u.setAuditStatus(IdentityAuditStatus.NOTPASSED.getCode());// 4 u.setProcess(IdentityProcess.RESULTS.getCode());// 5 userIdentityService.updateByPrimaryKeySelective(u); res.getError().add(buildError(ErrorConstants.OVER_MAX_WRONG_COUNT));// 输入错误金额次数过多 return res; } if (0 != (u.getAmountMoney().compareTo(userIdentity.getAmountMoney()))) { int t = 3 - u.getWrongCount() - 1; u.setWrongCount(u.getWrongCount() + 1); if (0 == t) { u.setAuditStatus(IdentityAuditStatus.NOTPASSED.getCode());// 4 u.setProcess(IdentityProcess.RESULTS.getCode());// 5 res.getError().add(buildError(ErrorConstants.OVER_MAX_WRONG_COUNT));// 输入错误金额次数过多 } else { res.getError().add(buildError(ErrorConstants.WRONG_MONEY, "", t)); } userIdentityService.updateByPrimaryKeySelective(u); return res; } userIdentity.setAuditStatus(IdentityAuditStatus.PASSED.getCode()); userIdentity.setProcess(IdentityProcess.RESULTS.getCode()); } return dealUserProcess(res, userIdentity, TokenManager.getUserId()); } /** * 团体实名认证流程入口 */ @RequestMapping(value = "/orgProcess", method = RequestMethod.GET) public Result orgProcess() { Result res = new Result(); if (TokenManager.isLogin()) { res.setData(organizationIdentityService.selectOrgIdentityByUserId(TokenManager.getUserId())); } return res; } /** * 团体实名认证流程下一步 * */ @RequestMapping(value = "/orgNextPro", method = RequestMethod.POST) public Result orgNextProcess(OrganizationIdentity orgIdentity, String listedDateFormattedDate, String verificationCode) throws ParseException { Result res = new Result(); if (null == orgIdentity.getProcess()) { res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "process")); return res; } if (STEP_ONE.equals(orgIdentity.getProcess())) { if (StringUtils.isBlank(verificationCode)) { res.getError().add(buildError(ErrorConstants.VCODE_EMPTY_ERROR)); return res; } if (!TokenManager.getSession().getAttribute(VerifyCodeUtils.V_CODE).equals(verificationCode)) { res.getError().add(buildError(ErrorConstants.VCODE_ERROR)); return res; } if (!StringUtils.isBlank(listedDateFormattedDate)) { orgIdentity.setListedDate(DateUtils.parseDate(listedDateFormattedDate, AFTConstants.YYYYMMDD)); } } else if (STEP_THREE.equals(orgIdentity.getProcess())) { OrganizationIdentity o = organizationIdentityService.selectOrgIdentityByUserId(TokenManager.getUserId()); o.setAuditStatus(IdentityAuditStatus.COMMITTED.getCode()); o.setProcess(IdentityProcess.COMMITTED.getCode()); organizationIdentityService.updateByPrimaryKeySelective(o); return res; } else if (STEP_FIVE.equals(orgIdentity.getProcess())) { OrganizationIdentity o = organizationIdentityService.selectOrgIdentityByUserId(TokenManager.getUserId()); if (System.currentTimeMillis() - o.getPaymentDate().getTime() > 432000000) { o.setAuditStatus(IdentityAuditStatus.NOTPASSED.getCode());// 4 organizationIdentityService.updateByPrimaryKeySelective(o); res.getError().add(buildError(ErrorConstants.IDENTITY_PAY_OVER_TIME));// 超过打款日期5日,无法提交确认 return res; } if (MAX_WRONG_COUNT.equals(o.getWrongCount())) { o.setAuditStatus(IdentityAuditStatus.NOTPASSED.getCode());// 4 o.setProcess(IdentityProcess.RESULTS.getCode());// 5 organizationIdentityService.updateByPrimaryKeySelective(o); res.getError().add(buildError(ErrorConstants.OVER_MAX_WRONG_COUNT));// 输入错误金额次数过多 return res; } if (0 != (o.getValidationAmount().compareTo(orgIdentity.getValidationAmount()))) { int t = 3 - o.getWrongCount() - 1; o.setWrongCount(o.getWrongCount() + 1); if (0 == t) { o.setAuditStatus(IdentityAuditStatus.NOTPASSED.getCode());// 4 o.setProcess(IdentityProcess.RESULTS.getCode());// 5 res.getError().add(buildError(ErrorConstants.OVER_MAX_WRONG_COUNT));// 输入错误金额次数过多 } else { res.getError().add(buildError(ErrorConstants.WRONG_MONEY, "", t)); } organizationIdentityService.updateByPrimaryKeySelective(o); return res; } orgIdentity.setAuditStatus(IdentityAuditStatus.PASSED.getCode()); orgIdentity.setProcess(IdentityProcess.RESULTS.getCode()); } return dealOrgProcess(res, orgIdentity, TokenManager.getUserId()); } /** * 认证失败 */ @RequestMapping(value = "/identFailed", method = RequestMethod.GET) public Result authenticationFailed() { Result res = new Result(); return dealFaild(res); } /** * 获取公司联系人 * * @param uid * @return */ @RequestMapping(value = "/getContacts", method = RequestMethod.GET) public Result getContacts() { Result res = new Result(); res.setData(organizationIdentityService.selectContactsByUserId(TokenManager.getUserId())); return res; } // 认证失败清除相关认证信息 private Result dealFaild(Result res) { if (UserType.PERSONAL.getCode().equals(userService.selectByPrimaryKey(TokenManager.getUserId()).getType())) { UserIdentity u = userIdentityService.selectUserIdentityByUserId(TokenManager.getUserId()); UserIdentity user = new UserIdentity(); user.setId(u.getId()); user.setUid(u.getUid()); user.setProcess(IdentityProcess.UNCOMMITTED.getCode()); user.setWrongCount(INIT_WRONG_COUNT); user.setAmountMoney(new BigDecimal(0)); user.setAuditStatus(IdentityAuditStatus.UNCOMMITTED.getCode()); res.setData(userIdentityService.updateByPrimaryKey(user)); } else { OrganizationIdentity o = organizationIdentityService.selectOrgIdentityByUserId(TokenManager.getUserId()); OrganizationIdentity org = new OrganizationIdentity(); org.setId(o.getId()); org.setUid(o.getUid()); org.setProcess(IdentityProcess.UNCOMMITTED.getCode()); org.setWrongCount(INIT_WRONG_COUNT); org.setAuditStatus(IdentityAuditStatus.UNCOMMITTED.getCode()); org.setValidationAmount(new BigDecimal(0)); res.setData(organizationIdentityService.updateByPrimaryKey(org)); } return res; } // orgProcess private Result dealOrgProcess(Result res, OrganizationIdentity o, String uid) { res.setData(organizationIdentityService.saveOrgIndentityProcess(res, o, uid)); return res; } // userProcess private Result dealUserProcess(Result res, UserIdentity u, String uid) { res.setData(userIdentityService.saveUserIdentityProcess(res, u, uid)); return res; } private UidAndTypeBo basicInfo(UserService userService) { User u = userService.selectByPrimaryKey(TokenManager.getUserId()); UidAndTypeBo ub = new UidAndTypeBo(); if (null != u) { ub.setType(u.getType()); ub.setUid(u.getId()); } return ub; } // 判断用户是否通过认证 private Result checkCertify(Result res) { OrganizationIdentity o = organizationIdentityService.selectOrgIdentityByUserId(TokenManager.getUserId()); if (null == o || !IdentityAuditStatus.PASSED.getCode().equals(o.getAuditStatus())) { res.getError().add(buildError(ErrorConstants.NON_CERTIFIED, "未通过实名认证,无法操作!")); } return res; } }