UserApiController.java 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916
  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.goafanti.common.bo.Result;
  16. import com.goafanti.common.constant.ErrorConstants;
  17. import com.goafanti.common.controller.BaseApiController;
  18. import com.goafanti.common.enums.AttachmentType;
  19. import com.goafanti.common.enums.IdentityAuditStatus;
  20. import com.goafanti.common.enums.IdentityProcess;
  21. import com.goafanti.common.enums.OrgProFields;
  22. import com.goafanti.common.enums.OrganizationTechFields;
  23. import com.goafanti.common.enums.UserAbilityFields;
  24. import com.goafanti.common.enums.UserAuthentication;
  25. import com.goafanti.common.enums.UserCareerFields;
  26. import com.goafanti.common.enums.UserEduFields;
  27. import com.goafanti.common.enums.UserIdentityFields;
  28. import com.goafanti.common.enums.UserType;
  29. import com.goafanti.common.model.OrganizationIdentity;
  30. import com.goafanti.common.model.OrganizationTech;
  31. import com.goafanti.common.model.User;
  32. import com.goafanti.common.model.UserAbility;
  33. import com.goafanti.common.model.UserCareer;
  34. import com.goafanti.common.model.UserEdu;
  35. import com.goafanti.common.model.UserIdentity;
  36. import com.goafanti.common.utils.PasswordUtil;
  37. import com.goafanti.common.utils.TimeUtils;
  38. import com.goafanti.common.utils.VerifyCodeUtils;
  39. import com.goafanti.core.shiro.token.TokenManager;
  40. import com.goafanti.easemob.EasemobUtils;
  41. import com.goafanti.order.enums.AuditState;
  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.getAuditStatus()){
  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. if(userIdentityService.updateUserIdentityDetail(userIdentity) < 0){
  393. userIdentity.setAuditInfo("系统提示:修改用户的基本信息,没有修改认证信息");
  394. }
  395. }
  396. res.setData(userIdentity);
  397. return res;
  398. }
  399. /**
  400. * 更新专家信息
  401. *
  402. * @param userIdentity
  403. * @param bindingResult
  404. * @return
  405. */
  406. @RequestMapping(value = "/updateExpertDetail", method = RequestMethod.POST)
  407. public Result updateExpertDetail(@Valid ExpertUserIdentity userIdentity, BindingResult bindingResult) {
  408. Result res = new Result();
  409. if (bindingResult.hasErrors()) {
  410. res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
  411. UserIdentityFields.getFieldDesc(bindingResult.getFieldError().getField())));
  412. return res;
  413. }
  414. if(StringUtils.isBlank(userIdentity.getUid())) {
  415. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "用户ID"));
  416. return res;
  417. }
  418. if(userIdentity.getAuthentication().intValue() == UserAuthentication.UN_AUTHENTICATION.getCode().intValue()){
  419. // userIdentity.setType(UserType.PERSONAL.getCode());
  420. userIdentity.setAuthentication(UserAuthentication.AUTHENTICATION.getCode());
  421. }
  422. if (res.getError().isEmpty()) {
  423. UserIdentity ui = new UserIdentity();
  424. User user = new User();
  425. BeanUtils.copyProperties(userIdentity, ui);
  426. BeanUtils.copyProperties(userIdentity, user);
  427. UserIdentity u = userIdentityService.selectUserIdentityByUserId(TokenManager.getUserId());
  428. if (null == u&&userIdentity.getAuthenticationType()==0) {
  429. ui.setId(UUID.randomUUID().toString());
  430. ui.setExpert(1);//直接变为专家
  431. ui.setAuditStatus(1);//提交审核
  432. ui.setUid(TokenManager.getUserId());
  433. userIdentityService.insert(ui);
  434. }else if (null == u&&userIdentity.getAuthenticationType()==1) {
  435. ui.setId(UUID.randomUUID().toString());
  436. ui.setExpert(2);//直接变为专家
  437. ui.setAuditStatus(1);//提交审核
  438. ui.setUid(TokenManager.getUserId());
  439. userIdentityService.insert(ui);
  440. } else {
  441. ui.setId(u.getId());
  442. userIdentityService.updateByPrimaryKeySelective(ui);
  443. }
  444. user.setId(TokenManager.getUserId());
  445. userService.updateByPrimaryKeySelective(user);
  446. }
  447. res.setData(userIdentity);
  448. return res;
  449. }
  450. /**
  451. * 企业信息详情
  452. * @return
  453. */
  454. @RequestMapping(value = "/getOrganizationDetail", method = RequestMethod.GET)
  455. public Result getOrganizationDetail(){
  456. Result res = new Result();
  457. OrgIdentityBo o = organizationIdentityService.selectOrgIdentityBoByUserId(TokenManager.getUserId());
  458. res.setData(o);
  459. return res;
  460. }
  461. /**
  462. * 修改企业信息
  463. *
  464. * @param userIdentity
  465. * @param bindingResult
  466. * @return
  467. */
  468. @RequestMapping(value = "/updateOrganizationDetail", method = RequestMethod.POST)
  469. public Result updateOrganizationDetail(@Valid InputOrganizationIdentity organizationIdentity, BindingResult bindingResult) {
  470. Result res = new Result();
  471. if (bindingResult.hasErrors()) {
  472. res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
  473. UserIdentityFields.getFieldDesc(bindingResult.getFieldError().getField())));
  474. return res;
  475. }
  476. if(StringUtils.isBlank(organizationIdentity.getUid())) {
  477. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "用户ID"));
  478. return res;
  479. }
  480. if(organizationIdentity.getAuthentication() == UserAuthentication.AUTHENTICATION.getCode()
  481. && organizationIdentity.getType() == UserType.PERSONAL.getCode()){
  482. res.getError().add(buildError(null, "", "用户已经个人认证"));
  483. return res;
  484. }else if(organizationIdentity.getAuthentication() == UserAuthentication.UN_AUTHENTICATION.getCode()){
  485. organizationIdentity.setType(UserType.ORGANIZATION.getCode());
  486. organizationIdentity.setAuthentication(UserAuthentication.AUTHENTICATION.getCode());
  487. }
  488. if (res.getError().isEmpty()) {
  489. OrganizationIdentity oi = new OrganizationIdentity();
  490. User user = new User();
  491. BeanUtils.copyProperties(organizationIdentity, oi);
  492. BeanUtils.copyProperties(organizationIdentity, user);
  493. OrganizationIdentity u = organizationIdentityService.selectOrgIdentityByUserId(TokenManager.getUserId());
  494. if (null == u) {
  495. oi.setId(UUID.randomUUID().toString());
  496. oi.setUid(TokenManager.getUserId());
  497. organizationIdentityService.insert(oi);
  498. } else {
  499. oi.setId(u.getId());
  500. organizationIdentityService.updateByPrimaryKeySelective(oi);
  501. }
  502. user.setId(TokenManager.getUserId());
  503. userService.updateByPrimaryKeySelective(user);
  504. }
  505. res.setData(organizationIdentity);
  506. return res;
  507. }
  508. /**
  509. * 个人资料/团体会员资料
  510. */
  511. @RequestMapping(value = "/member", method = RequestMethod.GET)
  512. public Result member() {
  513. Result res = new Result();
  514. return res;
  515. }
  516. /**
  517. * 个人会员教育信息
  518. *
  519. * @return
  520. */
  521. @RequestMapping(value = "/educate", method = RequestMethod.GET)
  522. public Result educate() {
  523. Result res = new Result();
  524. UserEdu u = userEduService.selectUserEduByUserId(TokenManager.getUserId());
  525. res.setData(u);
  526. return res;
  527. }
  528. /**
  529. * 个人会员职业信息/团体会员�?术能�?
  530. *
  531. * @return
  532. */
  533. @RequestMapping(value = "/job", method = RequestMethod.GET)
  534. public Result job() {
  535. Result res = new Result();
  536. if (UserType.PERSONAL.getCode().equals(TokenManager.getUserType())) {
  537. UserCareer u = userCareerService.selectUserCareerByUserId(TokenManager.getUserId());
  538. res.setData(u);
  539. } else {
  540. OrganizationTech o = organizationTechService.selectOrgTechByUserId(TokenManager.getUserId());
  541. res.setData(o);
  542. }
  543. return res;
  544. }
  545. /**
  546. * 个人/团体能力标签
  547. *
  548. * @return
  549. */
  550. @RequestMapping(value = "/ability", method = RequestMethod.GET)
  551. public Result ability() {
  552. Result res = new Result();
  553. UserAbility u = userAbilityService.selectUserAbilityByUserId(TokenManager.getUserId());
  554. res.setData(u);
  555. return res;
  556. }
  557. /**
  558. * 获取昵称
  559. *
  560. * @return
  561. */
  562. @RequestMapping(value = "/nickname", method = RequestMethod.GET)
  563. public Result nickname() {
  564. User u = userService.selectByPrimaryKey(TokenManager.getUserId());
  565. Assert.notNull(u, "用户不存�?");
  566. return res().data(u.getNickname());
  567. }
  568. /**
  569. * 首页
  570. *
  571. * @return
  572. */
  573. @RequestMapping(value = "/homePage", method = RequestMethod.GET)
  574. public Result homePage() {
  575. Result res = new Result();
  576. res.setData(userService.selectUserPageHomeBoByUserId(TokenManager.getUserId()));
  577. return res;
  578. }
  579. /**
  580. * 用户基本信息
  581. * @return
  582. */
  583. @RequestMapping(value = "/userBase", method = RequestMethod.GET)
  584. public Result userBase(){
  585. Result res = new Result();
  586. res.setData(userService.selectUserBase(TokenManager.getUserId()));
  587. return res;
  588. }
  589. /**
  590. * 修改用户基本信息
  591. * @return
  592. */
  593. @RequestMapping(value = "/updateUserBase", method = RequestMethod.POST)
  594. public Result updateUserBase(String identifyName,String mobile,String email,String nickname){
  595. Result res = new Result();
  596. if(StringUtils.isBlank(identifyName) || StringUtils.isBlank(mobile)
  597. ||StringUtils.isBlank(nickname)){
  598. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"用户信息不全"));
  599. }
  600. User user = new User();
  601. user.setId(TokenManager.getUserId());
  602. user.setIdentifyName(identifyName);
  603. user.setMobile(mobile);
  604. if(StringUtils.isNotBlank(email))user.setEmail(email);
  605. user.setNickname(nickname);
  606. userService.updateByPrimaryKeySelective(user);
  607. return res;
  608. }
  609. /**
  610. * 登陆后返回用户基本信�?
  611. *
  612. * @return
  613. */
  614. @RequestMapping(value = "/afterSignIn", method = RequestMethod.GET)
  615. public Result afterSignIn() {
  616. Result res = new Result();
  617. if (TokenManager.isLogin()) {
  618. User u = userService.selectByPrimaryKey(TokenManager.getUserId());
  619. res.setData(u);
  620. }
  621. return res;
  622. }
  623. /**
  624. * 个人实名认证流程入口
  625. *
  626. * @return
  627. */
  628. @RequestMapping(value = "/userPro", method = RequestMethod.GET)
  629. public Result userProcess() {
  630. Result res = new Result();
  631. if (TokenManager.isLogin()) {
  632. res.setData(userIdentityService.selectUserIdentityByUserId(TokenManager.getUserId()));
  633. }
  634. return res;
  635. }
  636. /**
  637. * 个人实名认证流程下一�?
  638. */
  639. @RequestMapping(value = "/userNextPro", method = RequestMethod.POST)
  640. public Result userNextProcess(UserIdentity userIdentity, String verificationCode) {
  641. Result res = new Result();
  642. if (null == userIdentity.getProcess()) {
  643. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "process"));
  644. return res;
  645. }
  646. if (STEP_ONE.equals(userIdentity.getProcess())) {
  647. if (StringUtils.isBlank(verificationCode)) {
  648. res.getError().add(buildError(ErrorConstants.VCODE_EMPTY_ERROR));
  649. return res;
  650. }
  651. if (!VerifyCodeUtils.verifyCode(verificationCode)) {
  652. res.getError().add(buildError(ErrorConstants.VCODE_ERROR));
  653. return res;
  654. }
  655. } else if (STEP_THREE.equals(userIdentity.getProcess())) {
  656. UserIdentity u = userIdentityService.selectUserIdentityByUserId(TokenManager.getUserId());
  657. u.setProcess(IdentityProcess.COMMITTED.getCode());
  658. u.setAuditStatus(IdentityAuditStatus.COMMITTED.getCode());
  659. userIdentityService.updateByPrimaryKeySelective(u);
  660. return res;
  661. } else if (STEP_FIVE.equals(userIdentity.getProcess())) {
  662. UserIdentity u = userIdentityService.selectUserIdentityByUserId(TokenManager.getUserId());
  663. if ((System.currentTimeMillis() - u.getPaymentDate().getTime()) > 432000000) {
  664. u.setAuditStatus(IdentityAuditStatus.NOTPASSED.getCode());// 4
  665. userIdentityService.updateByPrimaryKeySelective(u);
  666. res.getError().add(buildError(ErrorConstants.IDENTITY_PAY_OVER_TIME));// 超过打款日期5日,无法提交确认
  667. return res;
  668. }
  669. if (MAX_WRONG_COUNT.equals(u.getWrongCount())) {
  670. u.setAuditStatus(IdentityAuditStatus.NOTPASSED.getCode());// 4
  671. u.setProcess(IdentityProcess.SUCCESS.getCode());// 5
  672. userIdentityService.updateByPrimaryKeySelective(u);
  673. res.getError().add(buildError(ErrorConstants.OVER_MAX_WRONG_COUNT));// 输入错误金额次数过多
  674. return res;
  675. }
  676. if (0 != (u.getAmountMoney().compareTo(userIdentity.getAmountMoney()))) {
  677. int t = 3 - u.getWrongCount() - 1;
  678. u.setWrongCount(u.getWrongCount() + 1);
  679. if (0 == t) {
  680. u.setAuditStatus(IdentityAuditStatus.NOTPASSED.getCode());// 4
  681. u.setProcess(IdentityProcess.SUCCESS.getCode());// 5
  682. res.getError().add(buildError(ErrorConstants.OVER_MAX_WRONG_COUNT));// 输入错误金额次数过多
  683. } else {
  684. res.getError().add(buildError(ErrorConstants.WRONG_MONEY, "", t));
  685. }
  686. userIdentityService.updateByPrimaryKeySelective(u);
  687. return res;
  688. }
  689. userIdentity.setAuditStatus(IdentityAuditStatus.PASSED.getCode());
  690. userIdentity.setProcess(IdentityProcess.SUCCESS.getCode());
  691. }
  692. return dealUserProcess(res, userIdentity, TokenManager.getUserId());
  693. }
  694. // 认证失败清除相关认证信息
  695. private Result dealFaild(Result res) {
  696. if (UserType.PERSONAL.getCode().equals(userService.selectByPrimaryKey(TokenManager.getUserId()).getType())) {
  697. UserIdentity u = userIdentityService.selectUserIdentityByUserId(TokenManager.getUserId());
  698. UserIdentity user = new UserIdentity();
  699. user.setId(u.getId());
  700. user.setUid(u.getUid());
  701. user.setProcess(IdentityProcess.UNCOMMITTED.getCode());
  702. user.setWrongCount(INIT_WRONG_COUNT);
  703. user.setAmountMoney(new BigDecimal(0));
  704. user.setAuditStatus(IdentityAuditStatus.UNCOMMITTED.getCode());
  705. res.setData(userIdentityService.updateByPrimaryKey(user));
  706. } else {
  707. OrganizationIdentity o = organizationIdentityService.selectOrgIdentityByUserId(TokenManager.getUserId());
  708. OrganizationIdentity org = new OrganizationIdentity();
  709. org.setId(o.getId());
  710. org.setUid(o.getUid());
  711. org.setProcess(IdentityProcess.UNCOMMITTED.getCode());
  712. org.setWrongCount(INIT_WRONG_COUNT);
  713. org.setAuditStatus(IdentityAuditStatus.UNCOMMITTED.getCode());
  714. org.setValidationAmount(new BigDecimal(0));
  715. res.setData(organizationIdentityService.updateByPrimaryKey(org));
  716. }
  717. return res;
  718. }
  719. // orgProcess
  720. private Result dealOrgProcess(Result res, OrganizationIdentity o, String uid) {
  721. //res.setData(organizationIdentityService.saveOrgIndentityProcess(res, o, uid));
  722. return res;
  723. }
  724. // userProcess
  725. private Result dealUserProcess(Result res, UserIdentity u, String uid) {
  726. res.setData(userIdentityService.saveUserIdentityProcess(res, u, uid));
  727. return res;
  728. }
  729. // 判断用户是否通过认证
  730. private Result checkCertify(Result res) {
  731. OrganizationIdentity o = organizationIdentityService.selectOrgIdentityByUserId(TokenManager.getUserId());
  732. if (null == o || !IdentityAuditStatus.PASSED.getCode().equals(o.getAuditStatus())) {
  733. res.getError().add(buildError(ErrorConstants.NON_CERTIFIED, "未�?�过实名认证,无法操作!"));
  734. }
  735. return res;
  736. }
  737. /**
  738. * 新增客户联系�?
  739. * @param bo
  740. * @return
  741. */
  742. @RequestMapping(value = "/addUserContcat", method = RequestMethod.POST)
  743. public Result addUserContcat(UserContactBo bo){
  744. Result res = new Result();
  745. if(StringUtils.isBlank(bo.getMobile())){
  746. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "手机号码不能为空"));
  747. return res;
  748. }
  749. if(userContactService.checkUserContact(TokenManager.getUserId(), bo.getMobile())){
  750. res.getError().add(buildError(ErrorConstants.USER_CONTACT_ALREADY_EXIST,"联系人已存在"));
  751. }
  752. bo.setUid(TokenManager.getUserId());
  753. userContactService.insertSelective(bo);
  754. return res;
  755. }
  756. /**
  757. * 修改客户联系�?
  758. * @param bo
  759. * @return
  760. */
  761. @RequestMapping(value = "/udpateUserContact", method = RequestMethod.POST)
  762. public Result udpateUserContact(UserContactBo bo){
  763. Result res = new Result();
  764. if(StringUtils.isBlank(bo.getMobile())){
  765. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "手机号码不能为空"));
  766. return res;
  767. }
  768. if(StringUtils.isBlank(bo.getId())){
  769. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "联系人ID"));
  770. return res;
  771. }
  772. userContactService.updateByPrimaryKeySelective(bo);
  773. return res;
  774. }
  775. /**
  776. * 删除客户联系�?
  777. * @param id
  778. * @return
  779. */
  780. @RequestMapping(value = "/deleteUserContact", method = RequestMethod.GET)
  781. public Result deleteUserContact(String id){
  782. Result res = new Result();
  783. if(StringUtils.isBlank(id)){
  784. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "联系人ID"));
  785. return res;
  786. }
  787. userContactService.deleteUserContact(id);
  788. return res;
  789. }
  790. /**
  791. * 获取用户联系�?
  792. * @return
  793. */
  794. @RequestMapping(value = "/getUserContacts", method = RequestMethod.GET)
  795. public Result getUserContacts(){
  796. Result res = new Result();
  797. res.setData(userContactService.selectContactByUid(TokenManager.getUserId()));
  798. return res;
  799. }
  800. /**
  801. * 图片上传
  802. */
  803. @RequestMapping(value = "/uploadPicture", method = RequestMethod.POST)
  804. public Result uploadPicture(HttpServletRequest req, String sign) {
  805. Result res = new Result();
  806. AttachmentType attachmentType = AttachmentType.getField(sign);
  807. if (attachmentType == AttachmentType.USER_PICTURE) {
  808. res.setData(handleFiles(res, "/user/", false, req, sign, TokenManager.getUserId()));
  809. } else {
  810. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "附件标示"));
  811. }
  812. return res;
  813. }
  814. @RequestMapping(value = "/uploadHonerPicture", method = RequestMethod.POST)
  815. public Result uploadHonerPicture(HttpServletRequest req, String sign) {
  816. Result res = new Result();
  817. AttachmentType attachmentType = AttachmentType.getField(sign);
  818. if (attachmentType == AttachmentType.HONOR_PICTURE
  819. ) {
  820. res.setData(handleFiles(res, "/honorPicture/", false, req, sign, ""));
  821. } else {
  822. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "图片"));
  823. }
  824. return res;
  825. }
  826. /**
  827. * 顾问专家审核列表
  828. * @return
  829. */
  830. @RequestMapping(value = "/customerAuditList", method = RequestMethod.GET)
  831. public Result customerAuditList(String name,String type,String identity, Integer pageNo,Integer pageSize) {
  832. Result res = new Result();
  833. res.setData(userIdentityService.selectCustomerAuditList(name,type,identity,pageNo,pageSize));
  834. return res;
  835. }
  836. /**
  837. * 顾问专家审核
  838. * @return
  839. */
  840. @RequestMapping(value = "/customerAudit", method = RequestMethod.GET)
  841. public Result customerAudit(String id) {
  842. Result res = new Result();
  843. //res.setData(userIdentityService.selectCustomerAuditList(name,type,identity,pageNo,pageSize));
  844. return res;
  845. }
  846. }