UserApiController.java 32 KB

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