UserApiController.java 30 KB

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