UserApiController.java 30 KB

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