UserApiController.java 31 KB

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