UserApiController.java 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032
  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,Integer type){
  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. if (nickname.length()>6) {
  650. res.getError().add(buildError("昵称长度必须小于6","昵称长度必须小于6"));
  651. }
  652. User user = new User();
  653. user.setId(TokenManager.getUserId());
  654. user.setIdentifyName(identifyName);
  655. if(StringUtils.isNotEmpty(mobile)){
  656. //验证手机号码格式是否正确
  657. Pattern p = Pattern.compile("^[1][3,4,5,7,8][0-9]{9}$"); // 验证手机号
  658. Matcher m = p.matcher(mobile);
  659. if(!m.matches()){
  660. res.getError().add(buildError("电话号码格式不对","电话号码格式不对"));
  661. }else{
  662. //验证手机是否存在
  663. int i = userService.getCountByMobile(user.getId(),mobile,type);
  664. if(i>0){
  665. res.getError().add(buildError("电话号码重复","电话号码重复"));
  666. }else{
  667. user.setMobile(mobile);//修改电话号码
  668. }
  669. }
  670. }
  671. if(StringUtils.isNotBlank(email))user.setEmail(email);
  672. user.setNickname(nickname);
  673. if(type !=null)user.setType(type);
  674. if(res.getError().size()>0){
  675. return res;
  676. }
  677. userService.updateByPrimaryKeySelective(user);
  678. return res;
  679. }
  680. /**
  681. * 登陆后返回用户基本信息
  682. *
  683. * @return
  684. */
  685. @RequestMapping(value = "/afterSignIn", method = RequestMethod.GET)
  686. public Result afterSignIn() {
  687. Result res = new Result();
  688. if (TokenManager.isLogin()) {
  689. User u = userService.selectByPrimaryKey(TokenManager.getUserId());
  690. res.setData(u);
  691. }
  692. return res;
  693. }
  694. /**
  695. * 个人实名认证流程入口
  696. *
  697. * @return
  698. */
  699. @RequestMapping(value = "/userPro", method = RequestMethod.GET)
  700. public Result userProcess() {
  701. Result res = new Result();
  702. if (TokenManager.isLogin()) {
  703. res.setData(userIdentityService.selectUserIdentityByUserId(TokenManager.getUserId()));
  704. }
  705. return res;
  706. }
  707. /**
  708. * 个人实名认证流程下一步
  709. */
  710. @RequestMapping(value = "/userNextPro", method = RequestMethod.POST)
  711. public Result userNextProcess(UserIdentity userIdentity, String verificationCode) {
  712. Result res = new Result();
  713. if (null == userIdentity.getProcess()) {
  714. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "process"));
  715. return res;
  716. }
  717. if (STEP_ONE.equals(userIdentity.getProcess())) {
  718. if (StringUtils.isBlank(verificationCode)) {
  719. res.getError().add(buildError(ErrorConstants.VCODE_EMPTY_ERROR));
  720. return res;
  721. }
  722. if (!VerifyCodeUtils.verifyCode(verificationCode)) {
  723. res.getError().add(buildError(ErrorConstants.VCODE_ERROR));
  724. return res;
  725. }
  726. } else if (STEP_THREE.equals(userIdentity.getProcess())) {
  727. UserIdentity u = userIdentityService.selectUserIdentityByUserId(TokenManager.getUserId());
  728. u.setProcess(IdentityProcess.COMMITTED.getCode());
  729. u.setAuditStatus(IdentityAuditStatus.COMMITTED.getCode());
  730. userIdentityService.updateByPrimaryKeySelective(u);
  731. return res;
  732. } else if (STEP_FIVE.equals(userIdentity.getProcess())) {
  733. UserIdentity u = userIdentityService.selectUserIdentityByUserId(TokenManager.getUserId());
  734. if ((System.currentTimeMillis() - u.getPaymentDate().getTime()) > 432000000) {
  735. u.setAuditStatus(IdentityAuditStatus.NOTPASSED.getCode());// 4
  736. userIdentityService.updateByPrimaryKeySelective(u);
  737. res.getError().add(buildError(ErrorConstants.IDENTITY_PAY_OVER_TIME));// 超过打款日期5日,无法提交确认
  738. return res;
  739. }
  740. if (MAX_WRONG_COUNT.equals(u.getWrongCount())) {
  741. u.setAuditStatus(IdentityAuditStatus.NOTPASSED.getCode());// 4
  742. u.setProcess(IdentityProcess.SUCCESS.getCode());// 5
  743. userIdentityService.updateByPrimaryKeySelective(u);
  744. res.getError().add(buildError(ErrorConstants.OVER_MAX_WRONG_COUNT));// 输入错误金额次数过多
  745. return res;
  746. }
  747. if (0 != (u.getAmountMoney().compareTo(userIdentity.getAmountMoney()))) {
  748. int t = 3 - u.getWrongCount() - 1;
  749. u.setWrongCount(u.getWrongCount() + 1);
  750. if (0 == t) {
  751. u.setAuditStatus(IdentityAuditStatus.NOTPASSED.getCode());// 4
  752. u.setProcess(IdentityProcess.SUCCESS.getCode());// 5
  753. res.getError().add(buildError(ErrorConstants.OVER_MAX_WRONG_COUNT));// 输入错误金额次数过多
  754. } else {
  755. res.getError().add(buildError(ErrorConstants.WRONG_MONEY, "", t));
  756. }
  757. userIdentityService.updateByPrimaryKeySelective(u);
  758. return res;
  759. }
  760. userIdentity.setAuditStatus(IdentityAuditStatus.PASSED.getCode());
  761. userIdentity.setProcess(IdentityProcess.SUCCESS.getCode());
  762. }
  763. return dealUserProcess(res, userIdentity, TokenManager.getUserId());
  764. }
  765. // 认证失败清除相关认证信息
  766. private Result dealFaild(Result res) {
  767. if (UserType.PERSONAL.getCode().equals(userService.selectByPrimaryKey(TokenManager.getUserId()).getType())) {
  768. UserIdentity u = userIdentityService.selectUserIdentityByUserId(TokenManager.getUserId());
  769. UserIdentity user = new UserIdentity();
  770. user.setId(u.getId());
  771. user.setUid(u.getUid());
  772. user.setProcess(IdentityProcess.UNCOMMITTED.getCode());
  773. user.setWrongCount(INIT_WRONG_COUNT);
  774. user.setAmountMoney(new BigDecimal(0));
  775. user.setAuditStatus(IdentityAuditStatus.UNCOMMITTED.getCode());
  776. res.setData(userIdentityService.updateByPrimaryKey(user));
  777. } else {
  778. OrganizationIdentity o = organizationIdentityService.selectOrgIdentityByUserId(TokenManager.getUserId());
  779. OrganizationIdentity org = new OrganizationIdentity();
  780. org.setId(o.getId());
  781. org.setUid(o.getUid());
  782. org.setProcess(IdentityProcess.UNCOMMITTED.getCode());
  783. org.setWrongCount(INIT_WRONG_COUNT);
  784. org.setAuditStatus(IdentityAuditStatus.UNCOMMITTED.getCode());
  785. org.setValidationAmount(new BigDecimal(0));
  786. res.setData(organizationIdentityService.updateByPrimaryKey(org));
  787. }
  788. return res;
  789. }
  790. // orgProcess
  791. private Result dealOrgProcess(Result res, OrganizationIdentity o, String uid) {
  792. //res.setData(organizationIdentityService.saveOrgIndentityProcess(res, o, uid));
  793. return res;
  794. }
  795. // userProcess
  796. private Result dealUserProcess(Result res, UserIdentity u, String uid) {
  797. res.setData(userIdentityService.saveUserIdentityProcess(res, u, uid));
  798. return res;
  799. }
  800. // 判断用户是否通过认证
  801. private Result checkCertify(Result res) {
  802. OrganizationIdentity o = organizationIdentityService.selectOrgIdentityByUserId(TokenManager.getUserId());
  803. if (null == o || !IdentityAuditStatus.PASSED.getCode().equals(o.getAuditStatus())) {
  804. res.getError().add(buildError(ErrorConstants.NON_CERTIFIED, "未通过实名认证,无法操作!"));
  805. }
  806. return res;
  807. }
  808. /**
  809. * 新增客户联系人
  810. * @param bo
  811. * @return
  812. */
  813. @RequestMapping(value = "/addUserContcat", method = RequestMethod.POST)
  814. public Result addUserContcat(UserContactBo bo){
  815. Result res = new Result();
  816. if(StringUtils.isBlank(bo.getMobile())){
  817. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "手机号码不能为空"));
  818. return res;
  819. }
  820. if(userContactService.checkUserContact(TokenManager.getUserId(), bo.getMobile())){
  821. res.getError().add(buildError(ErrorConstants.USER_CONTACT_ALREADY_EXIST,"联系人已存在"));
  822. }
  823. bo.setUid(TokenManager.getUserId());
  824. userContactService.insertSelective(bo);
  825. return res;
  826. }
  827. /**
  828. * 修改客户联系人
  829. * @param bo
  830. * @return
  831. */
  832. @RequestMapping(value = "/udpateUserContact", method = RequestMethod.POST)
  833. public Result udpateUserContact(UserContactBo bo){
  834. Result res = new Result();
  835. if(StringUtils.isBlank(bo.getMobile())){
  836. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "手机号码不能为空"));
  837. return res;
  838. }
  839. if(StringUtils.isBlank(bo.getId())){
  840. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "联系人ID"));
  841. return res;
  842. }
  843. userContactService.updateByPrimaryKeySelective(bo);
  844. return res;
  845. }
  846. /**
  847. * 删除客户联系人
  848. * @param id
  849. * @return
  850. */
  851. @RequestMapping(value = "/deleteUserContact", method = RequestMethod.GET)
  852. public Result deleteUserContact(String id){
  853. Result res = new Result();
  854. if(StringUtils.isBlank(id)){
  855. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "联系人ID"));
  856. return res;
  857. }
  858. userContactService.deleteUserContact(id);
  859. return res;
  860. }
  861. /**
  862. * 获取用户联系人
  863. * @return
  864. */
  865. @RequestMapping(value = "/getUserContacts", method = RequestMethod.GET)
  866. public Result getUserContacts(){
  867. Result res = new Result();
  868. res.setData(userContactService.selectContactByUid(TokenManager.getUserId()));
  869. return res;
  870. }
  871. /**
  872. * 图片上传
  873. */
  874. @RequestMapping(value = "/uploadPicture", method = RequestMethod.POST)
  875. public Result uploadPicture(HttpServletRequest req, String sign) {
  876. Result res = new Result();
  877. AttachmentType attachmentType = AttachmentType.getField(sign);
  878. if (attachmentType == AttachmentType.USER_PICTURE) {
  879. res.setData(handleFiles(res, "/user/", false, req, sign, TokenManager.getUserId()));
  880. } else {
  881. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "附件标示"));
  882. }
  883. return res;
  884. }
  885. @RequestMapping(value = "/uploadHonerPicture", method = RequestMethod.POST)
  886. public Result uploadHonerPicture(HttpServletRequest req, String sign) {
  887. Result res = new Result();
  888. AttachmentType attachmentType = AttachmentType.getField(sign);
  889. if (attachmentType == AttachmentType.HONOR_PICTURE
  890. ) {
  891. res.setData(handleFiles(res, "/honorPicture/", false, req, sign, ""));
  892. } else {
  893. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "图片"));
  894. }
  895. return res;
  896. }
  897. /**
  898. * 顾问专家审核列表
  899. * @return
  900. */
  901. @RequestMapping(value = "/customerAuditList", method = RequestMethod.GET)
  902. public Result customerAuditList(String name,String type,String identity, Integer pageNo,Integer pageSize) {
  903. Result res = new Result();
  904. res.setData(userIdentityService.selectCustomerAuditList(name,type,identity,pageNo,pageSize));
  905. return res;
  906. }
  907. /**
  908. * 顾问专家审核
  909. * @return
  910. */
  911. @RequestMapping(value = "/customerAudit", method = RequestMethod.GET)
  912. public Result customerAudit(String id) {
  913. Result res = new Result();
  914. //res.setData(userIdentityService.selectCustomerAuditList(name,type,identity,pageNo,pageSize));
  915. return res;
  916. }
  917. /**
  918. * 解码base64位图片
  919. * @param picturebase
  920. * @param filename
  921. * @param sign
  922. * @return
  923. */
  924. @RequestMapping(value="/uploadPicture64")
  925. public Result uploadPicture64(String picturebase, String filename,String sign){
  926. Result res = new Result();
  927. byte[] bs=Base64.getDecoder().decode(picturebase);
  928. AttachmentType attachmentType = AttachmentType.getField(sign);
  929. if (attachmentType == AttachmentType.USER_PICTURE) {
  930. filename = System.nanoTime() + filename.substring(filename.indexOf("."));
  931. res.setData(handleBaseFiles(res, "/user/", false,bs, sign, TokenManager.getUserId(),filename));
  932. } else {
  933. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "附件标示"));
  934. }
  935. return res;
  936. }
  937. /**
  938. * 获取用户邀请码
  939. */
  940. @RequestMapping(value = "/InvitationCode", method = RequestMethod.GET)
  941. public Result InvitationCode(String uid) {
  942. Result res = new Result();
  943. if (uid==null) {
  944. if(!(TokenManager.getToken() instanceof User)||TokenManager.getUserId()==null){
  945. res.getError().add(buildError("未获取到用户信息", "未获取到用户信息"));
  946. return res;
  947. }
  948. uid=TokenManager.getUserId();
  949. }
  950. res.data(userService.updateGetInvitationCode(uid));
  951. return res;
  952. }
  953. }