UserApiController.java 31 KB

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