UserApiController.java 34 KB

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