UserApiController.java 33 KB

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