UserApiController.java 30 KB

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