UserApiController.java 29 KB

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