UserApiController.java 34 KB

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