| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875 |
- 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.apache.shiro.crypto.hash.SimpleHash;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.http.HttpMethod;
- 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 org.springframework.web.bind.annotation.RestController;
- import com.alibaba.fastjson.JSONObject;
- 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.UserType;
- import com.goafanti.common.model.OrgHumanResource;
- import com.goafanti.common.model.OrganizationIdentity;
- 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.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.easemob.EasemobUtils;
- import com.goafanti.easemob.bo.EasemobInfo;
- 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.UserIdentityBo;
- import com.goafanti.user.service.OrgHumanResourceService;
- import com.goafanti.user.service.OrganizationIdentityService;
- 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.UserService;
- @RestController
- @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 UserEduService userEduService;
- @Resource
- private UserCareerService userCareerService;
- @Resource
- private UserAbilityService userAbilityService;
- @Resource
- private OrganizationIdentityService organizationIdentityService;
- @Resource
- private OrganizationTechService organizationTechService;
- @Resource
- private OrganizationPropertiesService organizationPropertiesService;
- @Resource
- private OrgHumanResourceService orgHumanResourceService;
- @Resource
- private TechWebsiteService techWebsiteService;
- @Resource
- private OrgRatepayService orgRatepayService;
- @Autowired
- private EasemobUtils easemobUtils;
- 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;
- }
- User u = userService.selectByMobieAndType(mobile, user.getType());
- if (null != u) {
- res.getError().add(buildError(ErrorConstants.DUNPLICATE_KAY_ERROR, "", mobile));
- return res;
- }
- if (res.getError().isEmpty()) {
- user.setMobile(mobile);
- res.setData(userService.updateByPrimaryKeySelective(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);
- UserIdentity u = userIdentityService.selectUserIdentityByUserId(TokenManager.getUserId());
- if (null == u && StringUtils.isBlank(ui.getId())) {
- ui.setId(UUID.randomUUID().toString());
- ui.setUid(TokenManager.getUserId());
- userIdentityService.insert(ui);
- } else {
- if (StringUtils.isBlank(ui.getId())) {
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "认证信息ID"));
- return res;
- }
- 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(BindingResult bindingResult) {
- Result res = new Result();
-
- 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);
- UserEdu u = userEduService.selectUserEduByUserId(TokenManager.getUserId());
- if (null == u && StringUtils.isBlank(ue.getId())) {
- ue.setId(UUID.randomUUID().toString());
- ue.setUid(TokenManager.getUserId());
- userEduService.insert(ue);
- } else {
- if (StringUtils.isBlank(ue.getId())) {
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "教育信息ID"));
- return res;
- }
- 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);
- UserCareer u = userCareerService.selectUserCareerByUserId(TokenManager.getUserId());
- if (null == u && StringUtils.isBlank(uc.getId())) {
- uc.setId(UUID.randomUUID().toString());
- uc.setUid(TokenManager.getUserId());
- userCareerService.insert(uc);
- } else {
- if (StringUtils.isBlank(uc.getId())) {
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "职业信息ID"));
- return res;
- }
- 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);
- UserAbility u = userAbilityService.selectUserAbilityByUserId(TokenManager.getUserId());
- if (null == u && StringUtils.isBlank(ua.getId())) {
- ua.setId(UUID.randomUUID().toString());
- ua.setUid(TokenManager.getUserId());
- userAbilityService.insert(ua);
- } else {
- if (StringUtils.isBlank(ua.getId())) {
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "能力标签ID"));
- return res;
- }
- 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;
- }
- organizationIdentityService.save(orgIdentityBo);
- 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;
- }
- if (StringUtils.isBlank(pro.getCompanyName())) {
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到单位名称", "单位名称"));
- return res;
- }
- 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);
- OrganizationTech o = organizationTechService.selectOrgTechByUserId(TokenManager.getUserId());
- if (null == o && 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();
- if (UserType.PERSONAL.getCode().equals(TokenManager.getUserType())) {
- UserIdentityBo u = userIdentityService.selectUserIdentityBoByUserId(TokenManager.getUserId());
- res.setData(u);
- } else {
- OrgIdentityBo o = organizationIdentityService.selectOrgIdentityBoByUserId(TokenManager.getUserId());
- res.setData(o);
- }
- return res;
- }
- /**
- * 个人资料/团体会员资料
- */
- @RequestMapping(value = "/member", method = RequestMethod.GET)
- public Result member() {
- Result res = new Result();
-
- return res;
- }
- /**
- * 个人会员教育信息
- *
- * @return
- */
- @RequestMapping(value = "/educate", method = RequestMethod.GET)
- public Result educate() {
- Result res = new Result();
- UserEdu u = userEduService.selectUserEduByUserId(TokenManager.getUserId());
- res.setData(u);
- return res;
- }
- /**
- * 个人会员职业信息/团体会员技术能力
- *
- * @return
- */
- @RequestMapping(value = "/job", method = RequestMethod.GET)
- public Result job() {
- Result res = new Result();
- if (UserType.PERSONAL.getCode().equals(TokenManager.getUserType())) {
- UserCareer u = userCareerService.selectUserCareerByUserId(TokenManager.getUserId());
- res.setData(u);
- } else {
- OrganizationTech o = organizationTechService.selectOrgTechByUserId(TokenManager.getUserId());
- res.setData(o);
- }
- return res;
- }
- /**
- * 个人/团体能力标签
- *
- * @return
- */
- @RequestMapping(value = "/ability", method = RequestMethod.GET)
- public Result ability() {
- Result res = new Result();
- UserAbility u = userAbilityService.selectUserAbilityByUserId(TokenManager.getUserId());
- 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.SUCCESS.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.SUCCESS.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.SUCCESS.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.selectOrgIdentityUserBoByUserId(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 (!VerifyCodeUtils.verifyCode(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.SUCCESS.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.SUCCESS.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.SUCCESS.getCode());
- }
- return dealOrgProcess(res, orgIdentity, TokenManager.getUserId());
- }
- /**
- * 认证失败
- */
- @RequestMapping(value = "/identFailed", method = RequestMethod.GET)
- public Result authenticationFailed() {
- Result res = new Result();
- return dealFaild(res);
- }
- /**
- * 获取公司联系人
- */
- @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 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;
- }
- /**
- * 获取环信登录账号,如果未注册则先注册
- */
- @RequestMapping(value = "/easemob", method = RequestMethod.GET)
- public Result getEasemob() {
- User u = TokenManager.getUserToken();
- if (u != null) {
- JSONObject res = easemobUtils.send(new EasemobInfo().uri("/users/" + u.getNumber()).method(HttpMethod.GET));
- JSONObject resultObj = new JSONObject();
- resultObj.put("easemobPass", new SimpleHash("md5", u.getId(), null, 1).toHex());
- resultObj.put("easemobName", String.valueOf(u.getNumber()));
- resultObj.put("nickname", StringUtils.isBlank(u.getNickname()) ? "技淘用户" + u.getNumber() : u.getNickname());
- if (res == null || StringUtils.equals("service_resource_not_found", (CharSequence) res.get("error"))) {
- easemobUtils.sendLater(
- new EasemobInfo().uri("/users/").data(resultObj.toJSONString()).method(HttpMethod.POST));
- }
- return res().data(resultObj);
- } else {
- return res().error(buildError("user only", "必须是登录会员才能访问。"));
- }
- }
- }
|