AppUserController.java 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. package com.goafanti.app.controller;
  2. import java.lang.reflect.InvocationTargetException;
  3. import java.util.ArrayList;
  4. import java.util.Date;
  5. import java.util.List;
  6. import java.util.UUID;
  7. import javax.annotation.Resource;
  8. import javax.servlet.http.HttpServletRequest;
  9. import javax.validation.Valid;
  10. import org.apache.commons.lang3.StringUtils;
  11. import org.apache.shiro.crypto.hash.SimpleHash;
  12. import org.springframework.beans.BeanUtils;
  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.ResponseBody;
  18. import org.springframework.web.bind.annotation.RestController;
  19. import com.alibaba.fastjson.JSONObject;
  20. import com.goafanti.achievement.bo.InputAchievement;
  21. import com.goafanti.achievement.service.AchievementInterestService;
  22. import com.goafanti.achievement.service.AchievementService;
  23. import com.goafanti.banners.service.BannersService;
  24. import com.goafanti.common.bo.Result;
  25. import com.goafanti.common.constant.AFTConstants;
  26. import com.goafanti.common.constant.ErrorConstants;
  27. import com.goafanti.common.controller.BaseApiController;
  28. import com.goafanti.common.dao.JpushEasemobAccountMapper;
  29. import com.goafanti.common.enums.AchievementFields;
  30. import com.goafanti.common.enums.AttachmentType;
  31. import com.goafanti.common.enums.DemandFields;
  32. import com.goafanti.common.model.Achievement;
  33. import com.goafanti.common.model.Demand;
  34. import com.goafanti.common.model.JpushEasemobAccount;
  35. import com.goafanti.common.model.MessageConsumer;
  36. import com.goafanti.common.model.MessageFromSystem;
  37. import com.goafanti.common.model.MessageProducer;
  38. import com.goafanti.common.model.User;
  39. import com.goafanti.common.service.FieldGlossoryService;
  40. import com.goafanti.common.utils.DateUtils;
  41. import com.goafanti.common.utils.PasswordUtil;
  42. import com.goafanti.common.utils.TimeUtils;
  43. import com.goafanti.common.utils.VerifyCodeUtils;
  44. import com.goafanti.core.shiro.token.TokenManager;
  45. import com.goafanti.demand.bo.InputDemand;
  46. import com.goafanti.demand.service.DemandService;
  47. import com.goafanti.easemob.EasemobUtils;
  48. import com.goafanti.easemob.bo.EasemobInfo;
  49. import com.goafanti.message.bo.MessageBo;
  50. import com.goafanti.message.bo.MessageListBo;
  51. import com.goafanti.message.service.MessageService;
  52. import com.goafanti.news.service.NewsService;
  53. import com.goafanti.user.service.UserCareerService;
  54. import com.goafanti.user.service.UserIdentityService;
  55. import com.goafanti.user.service.UserInterestService;
  56. import com.goafanti.user.service.UserService;
  57. @RestController
  58. @RequestMapping(value = "/app/user")
  59. public class AppUserController extends BaseApiController {
  60. @Resource
  61. private UserService userServiceImpl;
  62. @Resource
  63. private MessageService messageService;
  64. @Resource
  65. private EasemobUtils easemobUtils;
  66. @Resource
  67. private BannersService bannersService;
  68. @Resource
  69. private NewsService newsService;
  70. @Resource
  71. private AchievementService achievementService;
  72. @Resource
  73. private DemandService demandService;
  74. @Resource
  75. private UserCareerService userCareerService;
  76. @Resource
  77. private UserInterestService userInterestService;
  78. @Resource
  79. private UserIdentityService userIdentityService;
  80. @Resource
  81. AchievementInterestService achievementInterestService;
  82. @Resource
  83. private FieldGlossoryService fieldGlossoryService;
  84. @Resource
  85. private UserService userService;
  86. @Resource(name = "passwordUtil")
  87. private PasswordUtil passwordUtil;
  88. @RequestMapping(value = "/uploadImg",method = RequestMethod.POST)
  89. public Result uploadAvatar(HttpServletRequest req){
  90. Result res = new Result();
  91. String headPortraitUrl = handleFile(res, "/avatar/", false, req, "");
  92. if(TokenManager.getToken() instanceof User){
  93. User u = new User();
  94. u.setId(TokenManager.getUserId());
  95. u.setHeadPortraitUrl(headPortraitUrl);
  96. userServiceImpl.updateByPrimaryKeySelective(u);
  97. }
  98. res.setData(headPortraitUrl);
  99. return res;
  100. }
  101. @RequestMapping(value = "/updateUser",method = RequestMethod.POST)
  102. public Result updateUser(User u){
  103. Result res = new Result();
  104. if(StringUtils.isBlank(u.getNickname())){
  105. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"用户昵称不能为空"));
  106. return res;
  107. }
  108. u.setId(TokenManager.getUserId());
  109. userServiceImpl.updateByPrimaryKeySelective(u);
  110. return res;
  111. }
  112. @RequestMapping(value = "/logout",method = RequestMethod.GET)
  113. public Result logout(HttpServletRequest request){
  114. Result res = new Result();
  115. TokenManager.logout();
  116. return res;
  117. }
  118. @RequestMapping(value = "/userInfo",method = RequestMethod.GET)
  119. public Result userInfo(HttpServletRequest request){
  120. Result res = new Result();
  121. res.setData(userServiceImpl.selectBaseInfo());
  122. return res;
  123. }
  124. @RequestMapping(value = "/index", method = RequestMethod.GET)
  125. public Result index(){
  126. Result res = new Result();
  127. res.setData(messageService.selectMessageWithGroup());
  128. return res;
  129. }
  130. @RequestMapping(value = "/listMessage", method = RequestMethod.POST)
  131. public Result listMessage(Integer subject,Integer sourceType,Integer pageNo,Integer pageSize){
  132. Result res = new Result();
  133. /*if(null == subject){
  134. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "必须指定消息类型"));
  135. return res;
  136. }*/
  137. User u = TokenManager.getUserToken();
  138. if(u != null){
  139. List<MessageBo> boList = messageService.selectSyncMessage(u.getId());
  140. if(boList != null && boList.size()>0){
  141. List<MessageProducer> producers = new ArrayList<MessageProducer>();
  142. List<MessageConsumer> consumers = new ArrayList<MessageConsumer>();
  143. MessageProducer mp = null;
  144. MessageConsumer mc = null;
  145. Date date = new Date();
  146. for(MessageBo bo : boList){
  147. mp = new MessageProducer();
  148. mp.setId(bo.getId());
  149. mp.setSendTime(date);
  150. producers.add(mp);
  151. mc = new MessageConsumer();
  152. mc.setId(UUID.randomUUID().toString());
  153. mc.setConsumerId(TokenManager.getUserId());
  154. mc.setMessageId(bo.getMessageId());
  155. consumers.add(mc);
  156. }
  157. if(producers.size()>0)messageService.updateMessageProducer(producers);
  158. //新增 message_consumer
  159. if(consumers.size()>0)messageService.insertBatchConsumer(consumers);
  160. }
  161. }
  162. res.setData(messageService.listPersonalMessage(subject,sourceType,pageNo,pageSize));
  163. return res;
  164. }
  165. /**
  166. * 同步绑定账号
  167. * @param uuid
  168. * @param registrationId
  169. * @param userName
  170. */
  171. @RequestMapping(value = "/synBindingAccount",method = RequestMethod.POST)
  172. private Result synBindingAccount(String uuid,String registrationId,String easemobName,String easemobPass){
  173. Result res = new Result();
  174. //更新 jpush_easemob_account
  175. messageService.updateJpushEasemobAccount(uuid, registrationId, easemobName,easemobPass);
  176. return res;
  177. }
  178. /*
  179. * 更新极光推送
  180. *
  181. * */
  182. @RequestMapping(value = "/updateJpushAccount",method = RequestMethod.POST)
  183. private Result updateJpush(String uuid,String registrationId,String easemobName,String easemobPass,String uid){
  184. Result res = new Result();
  185. //更新 jpush_easemob_account
  186. JpushEasemobAccount jpushEasemobAccount=messageService.selectSynAccByUid(uid);
  187. if(jpushEasemobAccount==null) {
  188. messageService.addJpushEasemobAccount(uuid, uid, easemobName, easemobPass);
  189. }
  190. messageService.updateJpushEasemobAccount(uuid, registrationId, easemobName,easemobPass);
  191. return res;
  192. }
  193. /**
  194. * 读取消息
  195. * @param messageId
  196. * @throws IllegalAccessException
  197. * @throws InvocationTargetException
  198. */
  199. @RequestMapping(value = "/readMessage",method = RequestMethod.GET)
  200. private Result readMessage(String messageId){
  201. Result res = new Result();
  202. if(StringUtils.isBlank(messageId)){
  203. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"", "消息编号为空"));
  204. return res;
  205. }
  206. //读取消息详情
  207. MessageFromSystem mfs = messageService.selectSystemMessageDetail(messageId);
  208. MessageListBo bo = new MessageListBo();
  209. bo.setCreateTime(mfs.getCreateTime()==null?"":DateUtils.formatDate(mfs.getCreateTime(), AFTConstants.YYYYMMDDHHMMSS));
  210. bo.setResourceType(String.valueOf(mfs.getResourceType()));
  211. bo.setSubject(String.valueOf(mfs.getSubject()));
  212. bo.setMessageId(mfs.getId());
  213. bo.setTitle(mfs.getTitle());
  214. bo.setBody(mfs.getBody());
  215. bo.setIsRead("1");//app操作已读
  216. res.setData(bo);
  217. //更新 message_consumer
  218. messageService.updateMessageConsumer(messageId);
  219. return res;
  220. }
  221. /**
  222. * 查询环信昵称和头像
  223. * @param easemobName
  224. * @return
  225. */
  226. @RequestMapping(value = "/getNicknameAndHeadPortrait",method = RequestMethod.GET)
  227. public Result getNicknameAndHeadPortrait(String easemobName){
  228. Result res = new Result();
  229. User user = userServiceImpl.selectByNumber(easemobName);
  230. JSONObject jsonObject = new JSONObject();
  231. jsonObject.put("nickName", user.getNickname());
  232. jsonObject.put("headPortraitUrl", null == user.getHeadPortraitUrl()?"":user.getHeadPortraitUrl());
  233. res.setData(jsonObject);
  234. return res;
  235. }
  236. /**
  237. * 关注功能
  238. */
  239. @RequestMapping(value = "/interestAdd", method = RequestMethod.GET)
  240. public Result Addinterest( Integer type,String objectId,String interest) {
  241. Result res = new Result();
  242. if (null==type) {
  243. res.getError().add(buildError( "分类错误!", "分类错误"));
  244. return res;
  245. }
  246. String uid=null;
  247. if (StringUtils.isNotBlank(TokenManager.getUserId())) {
  248. uid=TokenManager.getUserId();
  249. }
  250. if (Integer.valueOf(interest)==0) {
  251. res.setData(achievementInterestService.saveInterest( uid, type, objectId,interest));
  252. }else {
  253. res.setData(achievementInterestService.deleteInterest( uid, type, objectId,interest));
  254. }
  255. return res;
  256. }
  257. /**
  258. * 我的成果
  259. */
  260. @RequestMapping(value = "/achievementList", method = RequestMethod.GET)
  261. private Result achievementList(String pageNo, String pageSize) {
  262. Result res = new Result();
  263. Integer pNo = 1;
  264. Integer pSize = 10;
  265. if (StringUtils.isNumeric(pageSize)) {
  266. pSize = Integer.parseInt(pageSize);
  267. }
  268. if (StringUtils.isNumeric(pageNo)) {
  269. pNo = Integer.parseInt(pageNo);
  270. }
  271. res.setData(achievementService.listAppMyAchievement(pNo, pSize));
  272. return res;
  273. }
  274. /**
  275. * 我的需求
  276. */
  277. @RequestMapping(value = "/demandList", method = RequestMethod.GET)
  278. public Result demandList(String pageNo, String pageSize) {
  279. Result res = new Result();
  280. Integer pNo = 1;
  281. Integer pSize = 10;
  282. if (StringUtils.isNumeric(pageSize)) {
  283. pSize = Integer.parseInt(pageSize);
  284. }
  285. if (StringUtils.isNumeric(pageNo)) {
  286. pNo = Integer.parseInt(pageNo);
  287. }
  288. res.setData(demandService.listMyDemand( pNo, pSize));
  289. return res;
  290. }
  291. /**
  292. * 关注列表
  293. */
  294. @RequestMapping(value = "/interestList", method = RequestMethod.GET)
  295. public Result interestList(Integer type,String pageNo, String pageSize) {
  296. Result res = new Result();
  297. Integer pNo = 1;
  298. Integer pSize = 10;
  299. if (null==type||type<0||type>8) {
  300. res.getError().add(buildError( "类型选择错误", "类型选择错误"));
  301. }
  302. if (StringUtils.isNumeric(pageSize)) {
  303. pSize = Integer.parseInt(pageSize);
  304. }
  305. if (StringUtils.isNumeric(pageNo)) {
  306. pNo = Integer.parseInt(pageNo);
  307. }
  308. res.setData(demandService.selectinterest(type, pNo, pSize));
  309. return res;
  310. }
  311. /**
  312. * 成果详情
  313. * @param id
  314. * @return
  315. */
  316. @RequestMapping(value = "/achievementDetail", method = RequestMethod.GET)
  317. private Result userDetail(String id ) {
  318. Result res = new Result();
  319. if (StringUtils.isBlank(id)) {
  320. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"成果必须指定","成果"));
  321. return res;
  322. }
  323. res.setData(achievementService.selectAppUserOwnerDetail(id));
  324. return res;
  325. }
  326. /**
  327. * 需求详情
  328. */
  329. @RequestMapping(value = "/demandDetail", method = RequestMethod.GET)
  330. public Result DemandDetail(String id ) {
  331. Result res = new Result();
  332. if (StringUtils.isBlank(id)) {
  333. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"需求必须指定","需求"));
  334. return res;
  335. }
  336. res.setData(demandService.selectAppDemandDetail( id));
  337. return res;
  338. }
  339. /**
  340. * 新增成果
  341. */
  342. @RequestMapping(value = "/appAddAchievement", method = RequestMethod.POST)
  343. private Result appAddAchievement(@Valid InputAchievement ia, BindingResult bindingResult,
  344. String keyword1,String keyword2,String keyword3) {
  345. Result res = new Result();
  346. List<String> keyword=new ArrayList<>();
  347. if (!StringUtils.isBlank(keyword1)) {
  348. keyword.add(keyword1);
  349. }
  350. if (!StringUtils.isBlank(keyword2)) {
  351. keyword.add(keyword2);
  352. }
  353. if (!StringUtils.isBlank(keyword3)) {
  354. keyword.add(keyword3);
  355. }
  356. String[] keywords=(String[])keyword.toArray(new String[keyword.size()]);
  357. ia.setKeyword(StringUtils.join(keywords,","));
  358. if (bindingResult.hasErrors()) {
  359. res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
  360. AchievementFields.getFieldDesc(bindingResult.getFieldError().getField())));
  361. return res;
  362. }
  363. res = disposeInputAchievement(res, ia, keywords);
  364. if (!res.getError().isEmpty()) {
  365. return res;
  366. }
  367. Achievement a = new Achievement();
  368. BeanUtils.copyProperties(ia, a);
  369. res.setData(achievementService.saveAppAchievement(a, keywords));
  370. return res;
  371. }
  372. private Result disposeInputAchievement(Result res, InputAchievement ia, String[] keywords) {
  373. if (StringUtils.isBlank(ia.getName())) {
  374. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到成果名称", "成果名称"));
  375. return res;
  376. }
  377. if (null == ia.getCategory()) {
  378. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到数据类别", "数据类别"));
  379. return res;
  380. }
  381. if (StringUtils.isBlank(ia.getKeyword())) {
  382. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到关键词", "关键词"));
  383. return res;
  384. }
  385. if (null == keywords || keywords.length < 1) {
  386. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到关键词", "关键词"));
  387. return res;
  388. }
  389. if (null == ia.getCooperationMode()) {
  390. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到合作方式", "合作方式"));
  391. return res;
  392. }
  393. for (int i = 0; i < keywords.length; i++) {
  394. if (AFTConstants.KEYWORDLENTH < keywords[i].length()) {
  395. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "关键词长度"));
  396. return res;
  397. }
  398. }
  399. return res;
  400. }
  401. /**
  402. * 新增需求
  403. */
  404. @RequestMapping(value = "/appAddDemand", method = RequestMethod.POST)
  405. public Result appAddDemand(@Valid InputDemand demand, BindingResult bindingResult,
  406. String keyword1,String keyword2,String keyword3,
  407. String validityPeriodFormattedDate) {
  408. Result res = new Result();
  409. /*String[] keywords ;
  410. if (StringUtils.isNotEmpty(keyword3)) {
  411. keywords=new String[]{keyword1,keyword2};
  412. }else if (StringUtils.isNotEmpty(keyword2)) {
  413. keywords=new String[]{keyword1};
  414. }else {
  415. keywords=new String[]{keyword1,keyword2,keyword3};
  416. }
  417. if (null!=keywords) {
  418. demand.setKeyword(StringUtils.join(keywords,","));
  419. }*/
  420. if (bindingResult.hasErrors()) {
  421. res.getError().add(buildErrorByMsg(bindingResult.getFieldError().getDefaultMessage(),
  422. DemandFields.getFieldDesc(bindingResult.getFieldError().getField())));
  423. return res;
  424. }
  425. res = disposeDemand(res, demand, null);
  426. if (!res.getError().isEmpty()) {
  427. return res;
  428. }
  429. Demand d = new Demand();
  430. BeanUtils.copyProperties(demand, d);
  431. if (null == demand.getUrgentMoney()) {
  432. d.setUrgentMoney(demand.getUrgentMoney());
  433. }
  434. res.setData(demandService.saveAppUserDemand(d, validityPeriodFormattedDate, null));
  435. return res;
  436. }
  437. private Result disposeDemand(Result res, InputDemand demand, String[] keywords) {
  438. if (StringUtils.isBlank(demand.getName())) {
  439. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到需求名称", "需求名称"));
  440. return res;
  441. }
  442. /*if (StringUtils.isBlank(demand.getKeyword())) {
  443. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到关键词", "关键词"));
  444. return res;
  445. }
  446. if (null == keywords || keywords.length < 1) {
  447. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到关键词", "关键词"));
  448. return res;
  449. }*/
  450. if (null == demand.getIndustryCategoryA()) {
  451. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到行业类别", "行业类别"));
  452. return res;
  453. }
  454. if (null == demand.getDemandType()) {
  455. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到需求类型", "需求类型"));
  456. return res;
  457. }
  458. if (StringUtils.isBlank(demand.getProblemDes())) {
  459. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "找不到问题说明", "问题说明"));
  460. return res;
  461. }
  462. /*for (int i = 0; i < keywords.length; i++) {
  463. if (AFTConstants.KEYWORDLENTH < keywords[i].length()) {
  464. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "关键词长度"));
  465. return res;
  466. }
  467. }*/
  468. return res;
  469. }
  470. /**
  471. * 成果、需求图片上传
  472. */
  473. @RequestMapping(value = "/uploadPicture", method = RequestMethod.POST)
  474. public Result uploadPicture(HttpServletRequest req, String sign) {
  475. Result res = new Result();
  476. AttachmentType attachmentType = AttachmentType.getField(sign);
  477. if (attachmentType == AttachmentType.ACHIEVEMENT_PICTURE) {
  478. res.setData(handleFiles(res, "/achievement/", false, req, sign, "achievement"));
  479. } else if (attachmentType==AttachmentType.DEMAND_PICTURE){
  480. res.setData(handleFiles(res, "/demand/", false, req, sign, "demand"));
  481. }else {
  482. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "附件标示"));
  483. }
  484. return res;
  485. }
  486. /**
  487. * 获取领域
  488. * @param pid
  489. * @param level
  490. * @return
  491. */
  492. @RequestMapping(value = "/getField", method = RequestMethod.POST)
  493. public Result getField(Integer pid, Integer level) {
  494. Result res = new Result();
  495. res.setData(fieldGlossoryService.getField(pid, level));
  496. return res;
  497. }
  498. /**
  499. * 获取环信登录账号,如果未注册则先注册
  500. */
  501. @RequestMapping(value = "/easemob", method = RequestMethod.GET)
  502. public Result getEasemob() {
  503. User u = TokenManager.getUserToken();
  504. if (u != null) {
  505. JSONObject res = easemobUtils.send(new EasemobInfo().uri("/users/" + u.getNumber()).method(HttpMethod.GET));
  506. JSONObject resultObj = new JSONObject();
  507. resultObj.put("easemobPass", new SimpleHash("md5", u.getId(), null, 1).toHex());
  508. resultObj.put("easemobName", String.valueOf(u.getNumber()));
  509. resultObj.put("nickname", StringUtils.isBlank(u.getNickname()) ? "技淘用户" + u.getNumber() : u.getNickname());
  510. if (res == null || StringUtils.equals("service_resource_not_found", (CharSequence) res.get("error"))) {
  511. easemobUtils.sendLater(
  512. new EasemobInfo().uri("/users/").data(resultObj.toJSONString()).method(HttpMethod.POST));
  513. }
  514. return res().data(resultObj);
  515. } else {
  516. return res().error(buildError("user only", "必须是登录会员才能访问。"));
  517. }
  518. }
  519. @RequestMapping(value = "/updatePassword", method = RequestMethod.POST)
  520. @ResponseBody
  521. public Result resetPassword(String userName,String newPwd,String pwd) {
  522. Result res=new Result();
  523. if(null == TokenManager.getSession().getAttribute(VerifyCodeUtils.RESET_CODE)){
  524. res.getError().add(buildError(ErrorConstants.RESET_CODE_OVERTIME, "", "页面超时失效,请重新获取!"));
  525. cleanCodeSession();
  526. return res;
  527. }
  528. if (StringUtils.isBlank(newPwd)) {
  529. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "新密码"));
  530. return res;
  531. }
  532. if (StringUtils.isBlank(userName)) {
  533. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "用户名"));
  534. return res;
  535. }
  536. User user=userService.selectByNameAndType(userName, null);
  537. user.setPassword(newPwd);
  538. user.setPassword(passwordUtil.getEncryptPwd(user));
  539. userService.updateByPrimaryKeySelective(user);
  540. return res;
  541. }
  542. private void cleanCodeSession() {
  543. VerifyCodeUtils.clearResetCode();
  544. VerifyCodeUtils.clearResetCodeTime();
  545. VerifyCodeUtils.clearMobileCode();
  546. VerifyCodeUtils.clearMobileCodeTime();
  547. }
  548. }