UserApiController.java 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956
  1. package com.goafanti.user.controller;
  2. import java.math.BigDecimal;
  3. import java.util.UUID;
  4. import javax.annotation.Resource;
  5. import javax.servlet.http.HttpServletRequest;
  6. import javax.validation.Valid;
  7. import org.apache.commons.lang3.StringUtils;
  8. import org.springframework.beans.BeanUtils;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.util.Assert;
  11. import org.springframework.validation.BindingResult;
  12. import org.springframework.web.bind.annotation.RequestMapping;
  13. import org.springframework.web.bind.annotation.RequestMethod;
  14. import org.springframework.web.bind.annotation.RestController;
  15. import com.alibaba.druid.sql.parser.Token;
  16. import com.goafanti.common.bo.Result;
  17. import com.goafanti.common.constant.ErrorConstants;
  18. import com.goafanti.common.controller.BaseApiController;
  19. import com.goafanti.common.enums.AttachmentType;
  20. import com.goafanti.common.enums.IdentityAuditStatus;
  21. import com.goafanti.common.enums.IdentityProcess;
  22. import com.goafanti.common.enums.OrgProFields;
  23. import com.goafanti.common.enums.OrganizationTechFields;
  24. import com.goafanti.common.enums.UserAbilityFields;
  25. import com.goafanti.common.enums.UserAuthentication;
  26. import com.goafanti.common.enums.UserCareerFields;
  27. import com.goafanti.common.enums.UserEduFields;
  28. import com.goafanti.common.enums.UserIdentityFields;
  29. import com.goafanti.common.enums.UserType;
  30. import com.goafanti.common.model.OrganizationIdentity;
  31. import com.goafanti.common.model.OrganizationTech;
  32. import com.goafanti.common.model.User;
  33. import com.goafanti.common.model.UserAbility;
  34. import com.goafanti.common.model.UserCareer;
  35. import com.goafanti.common.model.UserEdu;
  36. import com.goafanti.common.model.UserIdentity;
  37. import com.goafanti.common.utils.PasswordUtil;
  38. import com.goafanti.common.utils.TimeUtils;
  39. import com.goafanti.common.utils.VerifyCodeUtils;
  40. import com.goafanti.core.shiro.token.TokenManager;
  41. import com.goafanti.easemob.EasemobUtils;
  42. import com.goafanti.user.bo.ExpertUserIdentity;
  43. import com.goafanti.user.bo.InputOrgPro;
  44. import com.goafanti.user.bo.InputOrganizationIdentity;
  45. import com.goafanti.user.bo.InputOrganizationTech;
  46. import com.goafanti.user.bo.InputUserAbility;
  47. import com.goafanti.user.bo.InputUserCareer;
  48. import com.goafanti.user.bo.InputUserEdu;
  49. import com.goafanti.user.bo.InputUserIdentity;
  50. import com.goafanti.user.bo.OrgIdentityBo;
  51. import com.goafanti.user.bo.UserContactBo;
  52. import com.goafanti.user.service.OrganizationIdentityService;
  53. import com.goafanti.user.service.OrganizationTechService;
  54. import com.goafanti.user.service.UserAbilityService;
  55. import com.goafanti.user.service.UserCareerService;
  56. import com.goafanti.user.service.UserContactService;
  57. import com.goafanti.user.service.UserEduService;
  58. import com.goafanti.user.service.UserIdentityService;
  59. import com.goafanti.user.service.UserService;
  60. @RestController
  61. @RequestMapping(value = "/api/user")
  62. public class UserApiController extends BaseApiController {
  63. @Resource
  64. private UserService userService;
  65. @Resource(name = "passwordUtil")
  66. private PasswordUtil passwordUtil;
  67. @Resource
  68. private UserIdentityService userIdentityService;
  69. @Resource
  70. private UserEduService userEduService;
  71. @Resource
  72. private UserCareerService userCareerService;
  73. @Resource
  74. private UserAbilityService userAbilityService;
  75. @Resource
  76. private OrganizationIdentityService organizationIdentityService;
  77. @Resource
  78. private OrganizationTechService organizationTechService;
  79. @Resource
  80. private UserContactService userContactService;
  81. @Autowired
  82. private EasemobUtils easemobUtils;
  83. private static final Integer STEP_ONE = 1;
  84. // private static final Integer STEP_TWO = 2;
  85. private static final Integer STEP_THREE = 3;
  86. // private static final Integer STEP_FOUR = 4;
  87. private static final Integer STEP_FIVE = 5;
  88. private static final Integer MAX_WRONG_COUNT = 3;
  89. private static final Integer INIT_WRONG_COUNT = 0;
  90. /**
  91. * 修改密码
  92. *
  93. * @param password
  94. * @param newPassword
  95. * @return
  96. */
  97. @RequestMapping(value = "/pwd", method = RequestMethod.POST)
  98. public Result updatePwd(String password, String newPassword) {
  99. Result res = new Result();
  100. if (StringUtils.isBlank(password) || StringUtils.isBlank(newPassword)) {
  101. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "必须指定", "密码"));
  102. }
  103. if (password.equals(newPassword)) {
  104. res.getError().add(buildError(ErrorConstants.PWD_SAME_ERROR, "新密码必须与原密码不同!"));
  105. }
  106. if (res.getError().isEmpty() && TokenManager.isLogin()) {
  107. User u = new User();
  108. User user = userService.selectByPrimaryKey(TokenManager.getUserId());
  109. u.setId(user.getId());
  110. u.setCreateTime(user.getCreateTime());
  111. u.setPassword(newPassword);
  112. u.setPassword(passwordUtil.getEncryptPwd(u));
  113. if (!user.getPassword().equals(passwordUtil.getEncryptPwd(password, user.getCreateTime()))) {
  114. res.getError().add(buildError(ErrorConstants.PWD_NOT_MATCH_ERROR));
  115. } else {
  116. res.setData(userService.updateByPrimaryKeySelective(u));
  117. }
  118. }
  119. return res;
  120. }
  121. /**
  122. * 更换手机
  123. *
  124. * @param mobile
  125. * @param mobileCode
  126. * @return
  127. */
  128. @RequestMapping(value = "/mobile", method = RequestMethod.POST)
  129. public Result updateMobile(String mobile, String mobileCode) {
  130. Result res = new Result();
  131. if (StringUtils.isBlank(mobile)) {
  132. res.getError().add(buildError(ErrorConstants.MOBILE_EMPTY_ERROR, "手机号不能为空!"));
  133. return res;
  134. }
  135. if (StringUtils.isBlank(mobileCode)) {
  136. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "手机验证码"));
  137. return res;
  138. }
  139. // 验证码15分钟有效
  140. if (TimeUtils.checkOverTime("register")) {
  141. res.getError().add(buildError(ErrorConstants.MCODE_OVERTIME_ERROR, "手机验证码超时失效"));
  142. return res;
  143. }
  144. if (!TokenManager.getSession().getAttribute(VerifyCodeUtils.M_CODE).equals(mobileCode)) {
  145. res.getError().add(buildError(ErrorConstants.MCODE_ERROR, "手机验证码错误"));
  146. return res;
  147. }
  148. User user = userService.selectByPrimaryKey(TokenManager.getUserId());
  149. if (mobile.equals(user.getMobile())) {
  150. res.getError().add(buildError(ErrorConstants.MOBILE_SAME_ERROR));
  151. return res;
  152. }
  153. User u = userService.selectByMobieAndType(mobile, user.getType());
  154. if (null != u) {
  155. res.getError().add(buildError(ErrorConstants.DUNPLICATE_KAY_ERROR, "", mobile));
  156. return res;
  157. }
  158. if (res.getError().isEmpty()) {
  159. user.setMobile(mobile);
  160. res.setData(userService.updateByPrimaryKeySelective(user));
  161. }
  162. return res;
  163. }
  164. /**
  165. * 公共
  166. *
  167. * @param req
  168. * @return
  169. */
  170. @RequestMapping(value = "/avatar/upload", method = RequestMethod.POST)
  171. public Result avatar(HttpServletRequest req) {
  172. Result res = new Result();
  173. res.setData(handleFile(res, "/avatar/", false, req, ""));
  174. return res;
  175. }
  176. /**
  177. * 公共可替换
  178. */
  179. @RequestMapping(value = "/avatar/uploadReplace", method = RequestMethod.POST)
  180. public Result avatarReplace(HttpServletRequest req, String sign) {
  181. Result res = new Result();
  182. res.setData(handleFile(res, "/avatar/", false, req, sign));
  183. return res;
  184. }
  185. /**
  186. * 认证
  187. *
  188. * @param req
  189. * @return
  190. */
  191. @RequestMapping(value = "/identity/upload", method = RequestMethod.POST)
  192. public Result identityFile(HttpServletRequest req, String sign) {
  193. Result res = new Result();
  194. res.setData(handleFile(res, "/identity/", true, req, sign));
  195. return res;
  196. }
  197. /**
  198. * 个人资料
  199. *
  200. * @param userInfoBo
  201. * @param bindingResult
  202. * @return
  203. */
  204. @RequestMapping(value = "/userInfo", method = RequestMethod.POST)
  205. public Result personalData(BindingResult bindingResult) {
  206. Result res = new Result();
  207. return res;
  208. }
  209. /**
  210. * 个人会员教育信息
  211. *
  212. * @param userEdu
  213. * @return
  214. */
  215. @RequestMapping(value = "/userEdu", method = RequestMethod.POST)
  216. public Result educationInfo(@Valid InputUserEdu userEdu, BindingResult bindingResult) {
  217. Result res = new Result();
  218. if (bindingResult.hasErrors()) {
  219. res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
  220. UserEduFields.getFieldDesc(bindingResult.getFieldError().getField())));
  221. return res;
  222. }
  223. UserEdu ue = new UserEdu();
  224. BeanUtils.copyProperties(userEdu, ue);
  225. UserEdu u = userEduService.selectUserEduByUserId(TokenManager.getUserId());
  226. if (null == u && StringUtils.isBlank(ue.getId())) {
  227. ue.setId(UUID.randomUUID().toString());
  228. ue.setUid(TokenManager.getUserId());
  229. userEduService.insert(ue);
  230. } else {
  231. if (StringUtils.isBlank(ue.getId())) {
  232. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "教育信息ID"));
  233. return res;
  234. }
  235. userEduService.updateByPrimaryKeySelective(ue);
  236. }
  237. res.setData(userEdu);
  238. return res;
  239. }
  240. /**
  241. * 个人会员职业信息
  242. *
  243. * @param userCareer
  244. * @return
  245. */
  246. @RequestMapping(value = "/userCareer", method = RequestMethod.POST)
  247. public Result careerInfo(@Valid InputUserCareer userCareer, BindingResult bindingResult) {
  248. Result res = new Result();
  249. if (bindingResult.hasErrors()) {
  250. res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
  251. UserCareerFields.getFieldDesc(bindingResult.getFieldError().getField())));
  252. return res;
  253. }
  254. UserCareer uc = new UserCareer();
  255. BeanUtils.copyProperties(userCareer, uc);
  256. UserCareer u = userCareerService.selectUserCareerByUserId(TokenManager.getUserId());
  257. if (null == u && StringUtils.isBlank(uc.getId())) {
  258. uc.setId(UUID.randomUUID().toString());
  259. uc.setUid(TokenManager.getUserId());
  260. userCareerService.insert(uc);
  261. } else {
  262. if (StringUtils.isBlank(uc.getId())) {
  263. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "职业信息ID"));
  264. return res;
  265. }
  266. userCareerService.updateByPrimaryKeySelective(uc);
  267. }
  268. res.setData(userCareer);
  269. return res;
  270. }
  271. /**
  272. * 会员能力标签
  273. *
  274. * @param userAbility
  275. * @return
  276. */
  277. @RequestMapping(value = "/userAbility", method = RequestMethod.POST)
  278. public Result abilityLabel(@Valid InputUserAbility userAbility, BindingResult bindingResult) {
  279. Result res = new Result();
  280. if (bindingResult.hasErrors()) {
  281. res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
  282. UserAbilityFields.getFieldDesc(bindingResult.getFieldError().getField())));
  283. return res;
  284. }
  285. UserAbility ua = new UserAbility();
  286. BeanUtils.copyProperties(userAbility, ua);
  287. UserAbility u = userAbilityService.selectUserAbilityByUserId(TokenManager.getUserId());
  288. if (null == u && StringUtils.isBlank(ua.getId())) {
  289. ua.setId(UUID.randomUUID().toString());
  290. ua.setUid(TokenManager.getUserId());
  291. userAbilityService.insert(ua);
  292. } else {
  293. if (StringUtils.isBlank(ua.getId())) {
  294. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "能力标签ID"));
  295. return res;
  296. }
  297. userAbilityService.updateByPrimaryKeySelective(ua);
  298. }
  299. res.setData(userAbility);
  300. return res;
  301. }
  302. /**
  303. * 团体会员单位资料
  304. *
  305. * @param orgInfo
  306. * @return
  307. */
  308. @RequestMapping(value = "/orgPro", method = RequestMethod.POST)
  309. public Result groupProInfo(@Valid InputOrgPro pro, BindingResult bindingResult) {
  310. Result res = new Result();
  311. if (bindingResult.hasErrors()) {
  312. res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
  313. OrgProFields.getFieldDesc(bindingResult.getFieldError().getField())));
  314. return res;
  315. }
  316. if (StringUtils.isBlank(pro.getCompanyName())) {
  317. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到单位名称", "单位名称"));
  318. return res;
  319. }
  320. return res;
  321. }
  322. /**
  323. * 团体会员技术能力
  324. *
  325. * @param orgTech
  326. * @return
  327. */
  328. @RequestMapping(value = "/orgTech", method = RequestMethod.POST)
  329. public Result tech(@Valid InputOrganizationTech orgTech, BindingResult bindingResult) {
  330. Result res = new Result();
  331. if (bindingResult.hasErrors()) {
  332. res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
  333. OrganizationTechFields.getFieldDesc(bindingResult.getFieldError().getField())));
  334. return res;
  335. }
  336. OrganizationTech ot = new OrganizationTech();
  337. BeanUtils.copyProperties(orgTech, ot);
  338. OrganizationTech o = organizationTechService.selectOrgTechByUserId(TokenManager.getUserId());
  339. if (null == o && StringUtils.isBlank(ot.getId())) {
  340. ot.setId(UUID.randomUUID().toString());
  341. ot.setUid(TokenManager.getUserId());
  342. organizationTechService.insert(ot);
  343. } else {
  344. organizationTechService.updateByPrimaryKeySelective(ot);
  345. }
  346. res.setData(orgTech);
  347. return res;
  348. }
  349. /**
  350. * 个人会员基本信息
  351. *
  352. * @return
  353. */
  354. @RequestMapping(value = "/getUserDetail", method = RequestMethod.GET)
  355. public Result getUserDetail() {
  356. Result res = new Result();
  357. res.setData(userIdentityService.selectUserIdentityBoByUserId(TokenManager.getUserId()));
  358. return res;
  359. }
  360. /**
  361. * 个人会员基本信息
  362. *
  363. * @param userIdentity
  364. * @param bindingResult
  365. * @return
  366. */
  367. @RequestMapping(value = "/updateUserDetail", method = RequestMethod.POST)
  368. public Result updateUserDetail(@Valid InputUserIdentity userIdentity, BindingResult bindingResult) {
  369. Result res = new Result();
  370. if (bindingResult.hasErrors()) {
  371. res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
  372. UserIdentityFields.getFieldDesc(bindingResult.getFieldError().getField())));
  373. return res;
  374. }
  375. if(null == userIdentity.getExpertAudit()){
  376. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "审核状态未提交"));
  377. return res;
  378. }
  379. if(StringUtils.isBlank(userIdentity.getUid())) {
  380. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "用户ID"));
  381. return res;
  382. }
  383. if(userIdentity.getAuthentication().intValue() == UserAuthentication.AUTHENTICATION.getCode().intValue()
  384. && userIdentity.getType().intValue() == UserType.ORGANIZATION.getCode().intValue()){
  385. res.getError().add(buildError(null, "", "用户已经企业认证"));
  386. return res;
  387. }else if(userIdentity.getAuthentication().intValue() == UserAuthentication.UN_AUTHENTICATION.getCode().intValue()){
  388. userIdentity.setType(UserType.PERSONAL.getCode());
  389. userIdentity.setAuthentication(UserAuthentication.AUTHENTICATION.getCode());
  390. }
  391. if (res.getError().isEmpty()) {
  392. UserIdentity ui = new UserIdentity();
  393. User user = new User();
  394. BeanUtils.copyProperties(userIdentity, ui);
  395. BeanUtils.copyProperties(userIdentity, user);
  396. //获得用户的认证信息
  397. UserIdentity u = userIdentityService.selectUserIdentityByUserId(TokenManager.getUserId());
  398. if (null == u) {
  399. ui.setId(UUID.randomUUID().toString());
  400. ui.setUid(TokenManager.getUserId());
  401. userIdentityService.insert(ui);
  402. } else {
  403. System.out.println(u.getAuditStatus());
  404. //判断审核状态
  405. if (userIdentity.getExpertAudit() == 0 || userIdentity.getExpertAudit() == 3) {
  406. ui.setExpertAudit(1);
  407. } else {
  408. res.getError().add(buildError("", "已经提交审核或者审核已经通过"));
  409. return res;
  410. }
  411. ui.setId(u.getId());
  412. userIdentityService.updateByPrimaryKeySelective(ui);
  413. }
  414. System.out.println(user.getBackgroundUrl());
  415. user.setId(TokenManager.getUserId());
  416. userService.updateByPrimaryKeySelective(user);
  417. userIdentity.setGraduateSchool(ui.getGraduateSchool());
  418. userIdentity.setExpert(ui.getExpert());
  419. userIdentity.setExpertAudit(ui.getExpertAudit());
  420. }
  421. res.setData(userIdentity);
  422. return res;
  423. }
  424. /**
  425. * 更新专家信息
  426. *
  427. * @param userIdentity
  428. * @param bindingResult
  429. * @return
  430. */
  431. @RequestMapping(value = "/updateExpertDetail", method = RequestMethod.POST)
  432. public Result updateExpertDetail(@Valid ExpertUserIdentity userIdentity, BindingResult bindingResult) {
  433. Result res = new Result();
  434. if (bindingResult.hasErrors()) {
  435. res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
  436. UserIdentityFields.getFieldDesc(bindingResult.getFieldError().getField())));
  437. return res;
  438. }
  439. if(StringUtils.isBlank(userIdentity.getUid())) {
  440. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "用户ID"));
  441. return res;
  442. }
  443. if(userIdentity.getAuthentication().intValue() == UserAuthentication.UN_AUTHENTICATION.getCode().intValue()){
  444. // userIdentity.setType(UserType.PERSONAL.getCode());
  445. userIdentity.setAuthentication(UserAuthentication.AUTHENTICATION.getCode());
  446. }
  447. if (res.getError().isEmpty()) {
  448. UserIdentity ui = new UserIdentity();
  449. User user = new User();
  450. BeanUtils.copyProperties(userIdentity, ui);
  451. BeanUtils.copyProperties(userIdentity, user);
  452. UserIdentity u = userIdentityService.selectUserIdentityByUserId(TokenManager.getUserId());
  453. if (null == u&&userIdentity.getAuthenticationType()==0) {
  454. ui.setId(UUID.randomUUID().toString());
  455. ui.setExpert(1);//直接变为专家
  456. ui.setExpertAudit(1);//提交审核
  457. ui.setUid(TokenManager.getUserId());
  458. userIdentityService.insert(ui);
  459. }else if (null == u&&userIdentity.getAuthenticationType()==1) {
  460. ui.setId(UUID.randomUUID().toString());
  461. ui.setExpert(2);//直接变为专家
  462. ui.setExpertAudit(1);//提交审核
  463. ui.setUid(TokenManager.getUserId());
  464. userIdentityService.insert(ui);
  465. } else {
  466. ui.setId(u.getId());
  467. userIdentityService.updateByPrimaryKeySelective(ui);
  468. }
  469. user.setId(TokenManager.getUserId());
  470. userService.updateByPrimaryKeySelective(user);
  471. }
  472. res.setData(userIdentity);
  473. return res;
  474. }
  475. /**
  476. * 企业信息详情
  477. * @return
  478. */
  479. @RequestMapping(value = "/getOrganizationDetail", method = RequestMethod.GET)
  480. public Result getOrganizationDetail(){
  481. Result res = new Result();
  482. OrgIdentityBo o = organizationIdentityService.selectOrgIdentityBoByUserId(TokenManager.getUserId());
  483. res.setData(o);
  484. return res;
  485. }
  486. /**
  487. * 修改企业信息
  488. *
  489. * @param userIdentity
  490. * @param bindingResult
  491. * @return
  492. */
  493. @RequestMapping(value = "/updateOrganizationDetail", method = RequestMethod.POST)
  494. public Result updateOrganizationDetail(@Valid InputOrganizationIdentity organizationIdentity, BindingResult bindingResult) {
  495. Result res = new Result();
  496. if (bindingResult.hasErrors()) {
  497. res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
  498. UserIdentityFields.getFieldDesc(bindingResult.getFieldError().getField())));
  499. return res;
  500. }
  501. if(StringUtils.isBlank(organizationIdentity.getUid())) {
  502. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "用户ID"));
  503. return res;
  504. }
  505. if(organizationIdentity.getAuthentication() == UserAuthentication.AUTHENTICATION.getCode()
  506. && organizationIdentity.getType() == UserType.PERSONAL.getCode()){
  507. res.getError().add(buildError(null, "", "用户已经个人认证"));
  508. return res;
  509. }else if(organizationIdentity.getAuthentication() == UserAuthentication.UN_AUTHENTICATION.getCode()){
  510. organizationIdentity.setType(UserType.ORGANIZATION.getCode());
  511. organizationIdentity.setAuthentication(UserAuthentication.AUTHENTICATION.getCode());
  512. }
  513. if (res.getError().isEmpty()) {
  514. OrganizationIdentity oi = new OrganizationIdentity();
  515. User user = new User();
  516. BeanUtils.copyProperties(organizationIdentity, oi);
  517. BeanUtils.copyProperties(organizationIdentity, user);
  518. OrganizationIdentity u = organizationIdentityService.selectOrgIdentityByUserId(TokenManager.getUserId());
  519. if (null == u) {
  520. oi.setId(UUID.randomUUID().toString());
  521. oi.setUid(TokenManager.getUserId());
  522. organizationIdentityService.insert(oi);
  523. } else {
  524. oi.setId(u.getId());
  525. organizationIdentityService.updateByPrimaryKeySelective(oi);
  526. }
  527. user.setId(TokenManager.getUserId());
  528. userService.updateByPrimaryKeySelective(user);
  529. }
  530. res.setData(organizationIdentity);
  531. return res;
  532. }
  533. /**
  534. * 个人资料/团体会员资料
  535. */
  536. @RequestMapping(value = "/member", method = RequestMethod.GET)
  537. public Result member() {
  538. Result res = new Result();
  539. return res;
  540. }
  541. /**
  542. * 个人会员教育信息
  543. *
  544. * @return
  545. */
  546. @RequestMapping(value = "/educate", method = RequestMethod.GET)
  547. public Result educate() {
  548. Result res = new Result();
  549. UserEdu u = userEduService.selectUserEduByUserId(TokenManager.getUserId());
  550. res.setData(u);
  551. return res;
  552. }
  553. /**
  554. * 个人会员职业信息/团体会员技术能力
  555. *
  556. * @return
  557. */
  558. @RequestMapping(value = "/job", method = RequestMethod.GET)
  559. public Result job() {
  560. Result res = new Result();
  561. if (UserType.PERSONAL.getCode().equals(TokenManager.getUserType())) {
  562. UserCareer u = userCareerService.selectUserCareerByUserId(TokenManager.getUserId());
  563. res.setData(u);
  564. } else {
  565. OrganizationTech o = organizationTechService.selectOrgTechByUserId(TokenManager.getUserId());
  566. res.setData(o);
  567. }
  568. return res;
  569. }
  570. /**
  571. * 个人/团体能力标签
  572. *
  573. * @return
  574. */
  575. @RequestMapping(value = "/ability", method = RequestMethod.GET)
  576. public Result ability() {
  577. Result res = new Result();
  578. UserAbility u = userAbilityService.selectUserAbilityByUserId(TokenManager.getUserId());
  579. res.setData(u);
  580. return res;
  581. }
  582. /**
  583. * 获取昵称
  584. *
  585. * @return
  586. */
  587. @RequestMapping(value = "/nickname", method = RequestMethod.GET)
  588. public Result nickname() {
  589. User u = userService.selectByPrimaryKey(TokenManager.getUserId());
  590. Assert.notNull(u, "用户不存在");
  591. return res().data(u.getNickname());
  592. }
  593. /**
  594. * 首页
  595. *
  596. * @return
  597. */
  598. @RequestMapping(value = "/homePage", method = RequestMethod.GET)
  599. public Result homePage() {
  600. Result res = new Result();
  601. res.setData(userService.selectUserPageHomeBoByUserId(TokenManager.getUserId()));
  602. return res;
  603. }
  604. /**
  605. * 用户基本信息
  606. * @return
  607. */
  608. @RequestMapping(value = "/userBase", method = RequestMethod.GET)
  609. public Result userBase(){
  610. Result res = new Result();
  611. res.setData(userService.selectUserBase(TokenManager.getUserId()));
  612. return res;
  613. }
  614. /**
  615. * 修改用户基本信息
  616. * @return
  617. */
  618. @RequestMapping(value = "/updateUserBase", method = RequestMethod.POST)
  619. public Result updateUserBase(String identifyName,String mobile,String email,String nickname){
  620. Result res = new Result();
  621. if(StringUtils.isBlank(identifyName) || StringUtils.isBlank(mobile)
  622. ||StringUtils.isBlank(nickname)){
  623. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"用户信息不全"));
  624. }
  625. User user = new User();
  626. user.setId(TokenManager.getUserId());
  627. user.setIdentifyName(identifyName);
  628. user.setMobile(mobile);
  629. if(StringUtils.isNotBlank(email))user.setEmail(email);
  630. user.setNickname(nickname);
  631. userService.updateByPrimaryKeySelective(user);
  632. return res;
  633. }
  634. /**
  635. * 登陆后返回用户基本信息
  636. *
  637. * @return
  638. */
  639. @RequestMapping(value = "/afterSignIn", method = RequestMethod.GET)
  640. public Result afterSignIn() {
  641. Result res = new Result();
  642. if (TokenManager.isLogin()) {
  643. User u = userService.selectByPrimaryKey(TokenManager.getUserId());
  644. res.setData(u);
  645. }
  646. return res;
  647. }
  648. /**
  649. * 个人实名认证流程入口
  650. *
  651. * @return
  652. */
  653. @RequestMapping(value = "/userPro", method = RequestMethod.GET)
  654. public Result userProcess() {
  655. Result res = new Result();
  656. if (TokenManager.isLogin()) {
  657. res.setData(userIdentityService.selectUserIdentityByUserId(TokenManager.getUserId()));
  658. }
  659. return res;
  660. }
  661. /**
  662. * 个人实名认证流程下一步
  663. */
  664. @RequestMapping(value = "/userNextPro", method = RequestMethod.POST)
  665. public Result userNextProcess(UserIdentity userIdentity, String verificationCode) {
  666. Result res = new Result();
  667. if (null == userIdentity.getProcess()) {
  668. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "process"));
  669. return res;
  670. }
  671. if (STEP_ONE.equals(userIdentity.getProcess())) {
  672. if (StringUtils.isBlank(verificationCode)) {
  673. res.getError().add(buildError(ErrorConstants.VCODE_EMPTY_ERROR));
  674. return res;
  675. }
  676. if (!VerifyCodeUtils.verifyCode(verificationCode)) {
  677. res.getError().add(buildError(ErrorConstants.VCODE_ERROR));
  678. return res;
  679. }
  680. } else if (STEP_THREE.equals(userIdentity.getProcess())) {
  681. UserIdentity u = userIdentityService.selectUserIdentityByUserId(TokenManager.getUserId());
  682. u.setProcess(IdentityProcess.COMMITTED.getCode());
  683. u.setAuditStatus(IdentityAuditStatus.COMMITTED.getCode());
  684. userIdentityService.updateByPrimaryKeySelective(u);
  685. return res;
  686. } else if (STEP_FIVE.equals(userIdentity.getProcess())) {
  687. UserIdentity u = userIdentityService.selectUserIdentityByUserId(TokenManager.getUserId());
  688. if ((System.currentTimeMillis() - u.getPaymentDate().getTime()) > 432000000) {
  689. u.setAuditStatus(IdentityAuditStatus.NOTPASSED.getCode());// 4
  690. userIdentityService.updateByPrimaryKeySelective(u);
  691. res.getError().add(buildError(ErrorConstants.IDENTITY_PAY_OVER_TIME));// 超过打款日期5日,无法提交确认
  692. return res;
  693. }
  694. if (MAX_WRONG_COUNT.equals(u.getWrongCount())) {
  695. u.setAuditStatus(IdentityAuditStatus.NOTPASSED.getCode());// 4
  696. u.setProcess(IdentityProcess.SUCCESS.getCode());// 5
  697. userIdentityService.updateByPrimaryKeySelective(u);
  698. res.getError().add(buildError(ErrorConstants.OVER_MAX_WRONG_COUNT));// 输入错误金额次数过多
  699. return res;
  700. }
  701. if (0 != (u.getAmountMoney().compareTo(userIdentity.getAmountMoney()))) {
  702. int t = 3 - u.getWrongCount() - 1;
  703. u.setWrongCount(u.getWrongCount() + 1);
  704. if (0 == t) {
  705. u.setAuditStatus(IdentityAuditStatus.NOTPASSED.getCode());// 4
  706. u.setProcess(IdentityProcess.SUCCESS.getCode());// 5
  707. res.getError().add(buildError(ErrorConstants.OVER_MAX_WRONG_COUNT));// 输入错误金额次数过多
  708. } else {
  709. res.getError().add(buildError(ErrorConstants.WRONG_MONEY, "", t));
  710. }
  711. userIdentityService.updateByPrimaryKeySelective(u);
  712. return res;
  713. }
  714. userIdentity.setAuditStatus(IdentityAuditStatus.PASSED.getCode());
  715. userIdentity.setProcess(IdentityProcess.SUCCESS.getCode());
  716. }
  717. return dealUserProcess(res, userIdentity, TokenManager.getUserId());
  718. }
  719. // 认证失败清除相关认证信息
  720. private Result dealFaild(Result res) {
  721. if (UserType.PERSONAL.getCode().equals(userService.selectByPrimaryKey(TokenManager.getUserId()).getType())) {
  722. UserIdentity u = userIdentityService.selectUserIdentityByUserId(TokenManager.getUserId());
  723. UserIdentity user = new UserIdentity();
  724. user.setId(u.getId());
  725. user.setUid(u.getUid());
  726. user.setProcess(IdentityProcess.UNCOMMITTED.getCode());
  727. user.setWrongCount(INIT_WRONG_COUNT);
  728. user.setAmountMoney(new BigDecimal(0));
  729. user.setAuditStatus(IdentityAuditStatus.UNCOMMITTED.getCode());
  730. res.setData(userIdentityService.updateByPrimaryKey(user));
  731. } else {
  732. OrganizationIdentity o = organizationIdentityService.selectOrgIdentityByUserId(TokenManager.getUserId());
  733. OrganizationIdentity org = new OrganizationIdentity();
  734. org.setId(o.getId());
  735. org.setUid(o.getUid());
  736. org.setProcess(IdentityProcess.UNCOMMITTED.getCode());
  737. org.setWrongCount(INIT_WRONG_COUNT);
  738. org.setAuditStatus(IdentityAuditStatus.UNCOMMITTED.getCode());
  739. org.setValidationAmount(new BigDecimal(0));
  740. res.setData(organizationIdentityService.updateByPrimaryKey(org));
  741. }
  742. return res;
  743. }
  744. // orgProcess
  745. private Result dealOrgProcess(Result res, OrganizationIdentity o, String uid) {
  746. //res.setData(organizationIdentityService.saveOrgIndentityProcess(res, o, uid));
  747. return res;
  748. }
  749. // userProcess
  750. private Result dealUserProcess(Result res, UserIdentity u, String uid) {
  751. res.setData(userIdentityService.saveUserIdentityProcess(res, u, uid));
  752. return res;
  753. }
  754. // 判断用户是否通过认证
  755. private Result checkCertify(Result res) {
  756. OrganizationIdentity o = organizationIdentityService.selectOrgIdentityByUserId(TokenManager.getUserId());
  757. if (null == o || !IdentityAuditStatus.PASSED.getCode().equals(o.getAuditStatus())) {
  758. res.getError().add(buildError(ErrorConstants.NON_CERTIFIED, "未通过实名认证,无法操作!"));
  759. }
  760. return res;
  761. }
  762. /**
  763. * 新增客户联系人
  764. * @param bo
  765. * @return
  766. */
  767. @RequestMapping(value = "/addUserContcat", method = RequestMethod.POST)
  768. public Result addUserContcat(UserContactBo bo){
  769. Result res = new Result();
  770. if(StringUtils.isBlank(bo.getMobile())){
  771. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "手机号码不能为空"));
  772. return res;
  773. }
  774. if(userContactService.checkUserContact(TokenManager.getUserId(), bo.getMobile())){
  775. res.getError().add(buildError(ErrorConstants.USER_CONTACT_ALREADY_EXIST,"联系人已存在"));
  776. }
  777. bo.setUid(TokenManager.getUserId());
  778. userContactService.insertSelective(bo);
  779. return res;
  780. }
  781. /**
  782. * 修改客户联系人
  783. * @param bo
  784. * @return
  785. */
  786. @RequestMapping(value = "/udpateUserContact", method = RequestMethod.POST)
  787. public Result udpateUserContact(UserContactBo bo){
  788. Result res = new Result();
  789. if(StringUtils.isBlank(bo.getMobile())){
  790. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "手机号码不能为空"));
  791. return res;
  792. }
  793. if(StringUtils.isBlank(bo.getId())){
  794. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "联系人ID"));
  795. return res;
  796. }
  797. userContactService.updateByPrimaryKeySelective(bo);
  798. return res;
  799. }
  800. /**
  801. * 删除客户联系人
  802. * @param id
  803. * @return
  804. */
  805. @RequestMapping(value = "/deleteUserContact", method = RequestMethod.GET)
  806. public Result deleteUserContact(String id){
  807. Result res = new Result();
  808. if(StringUtils.isBlank(id)){
  809. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "联系人ID"));
  810. return res;
  811. }
  812. userContactService.deleteUserContact(id);
  813. return res;
  814. }
  815. /**
  816. * 获取用户联系人
  817. * @return
  818. */
  819. @RequestMapping(value = "/getUserContacts", method = RequestMethod.GET)
  820. public Result getUserContacts(){
  821. Result res = new Result();
  822. res.setData(userContactService.selectContactByUid(TokenManager.getUserId()));
  823. return res;
  824. }
  825. /**
  826. * 图片上传
  827. */
  828. @RequestMapping(value = "/uploadPicture", method = RequestMethod.POST)
  829. public Result uploadPicture(HttpServletRequest req, String sign) {
  830. Result res = new Result();
  831. AttachmentType attachmentType = AttachmentType.getField(sign);
  832. if (attachmentType == AttachmentType.USER_PICTURE) {
  833. res.setData(handleFiles(res, "/user/", false, req, sign, TokenManager.getUserId()));
  834. } else {
  835. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "附件标示"));
  836. }
  837. return res;
  838. }
  839. @RequestMapping(value = "/uploadHonerPicture", method = RequestMethod.POST)
  840. public Result uploadHonerPicture(HttpServletRequest req, String sign) {
  841. Result res = new Result();
  842. AttachmentType attachmentType = AttachmentType.getField(sign);
  843. if (attachmentType == AttachmentType.HONOR_PICTURE
  844. ) {
  845. res.setData(handleFiles(res, "/honorPicture/", false, req, sign, ""));
  846. } else {
  847. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "图片"));
  848. }
  849. return res;
  850. }
  851. //获得专家顾问审核数据
  852. @RequestMapping(value="/getExpertAuditList", method = RequestMethod.GET )
  853. public Result getExpertAuditList(InputUserIdentity identity, Integer pageNo, Integer pageSize){
  854. Result res = new Result();
  855. res.setData(userIdentityService.getExpertAuditList(identity, pageNo, pageSize));
  856. return res;
  857. }
  858. //获得某个人认证的详情信息
  859. @RequestMapping(value="/getUserIdentityByUid" , method = RequestMethod.POST)
  860. public Result getUserIdentityByUid(String uid){
  861. Result res = new Result();
  862. res.setData(userIdentityService.getUserIdentityByUid(uid));
  863. return res;
  864. }
  865. /**
  866. * 顾问专家审核列表
  867. * @return
  868. */
  869. @RequestMapping(value = "/customerAuditList", method = RequestMethod.GET)
  870. public Result customerAuditList(String name,String type,String identity, Integer pageNo,Integer pageSize) {
  871. Result res = new Result();
  872. res.setData(userIdentityService.selectCustomerAuditList(name,type,identity,pageNo,pageSize));
  873. return res;
  874. }
  875. /**
  876. * 顾问专家审核
  877. * @return
  878. */
  879. @RequestMapping(value = "/customerAudit", method = RequestMethod.GET)
  880. public Result customerAudit(String id) {
  881. Result res = new Result();
  882. //res.setData(userIdentityService.selectCustomerAuditList(name,type,identity,pageNo,pageSize));
  883. return res;
  884. }
  885. }