UserApiController.java 32 KB

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