UserApiController.java 31 KB

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