PublicController.java 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. package com.goafanti.common.controller;
  2. import java.io.File;
  3. import java.io.FileInputStream;
  4. import java.io.IOException;
  5. import java.io.InputStream;
  6. import java.io.OutputStream;
  7. import java.util.UUID;
  8. import javax.annotation.Resource;
  9. import javax.servlet.http.HttpServletRequest;
  10. import javax.servlet.http.HttpServletResponse;
  11. import org.apache.commons.lang3.StringUtils;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.beans.factory.annotation.Value;
  14. import org.springframework.context.annotation.Scope;
  15. import org.springframework.stereotype.Controller;
  16. import org.springframework.web.bind.annotation.RequestMapping;
  17. import org.springframework.web.bind.annotation.RequestMethod;
  18. import org.springframework.web.bind.annotation.ResponseBody;
  19. import com.goafanti.achievement.service.AchievementService;
  20. import com.goafanti.comment.bo.CommentResult;
  21. import com.goafanti.comment.service.CommentService;
  22. import com.goafanti.common.bo.Result;
  23. import com.goafanti.common.constant.ErrorConstants;
  24. import com.goafanti.common.enums.UserType;
  25. import com.goafanti.common.model.User;
  26. import com.goafanti.common.service.DistrictGlossoryService;
  27. import com.goafanti.common.service.FieldGlossoryService;
  28. import com.goafanti.common.service.IndustryCategoryService;
  29. import com.goafanti.common.utils.LoggerUtils;
  30. import com.goafanti.common.utils.MobileMessageUtils;
  31. import com.goafanti.common.utils.PasswordUtil;
  32. import com.goafanti.common.utils.PictureUtils;
  33. import com.goafanti.common.utils.TimeUtils;
  34. import com.goafanti.common.utils.VerifyCodeUtils;
  35. import com.goafanti.core.shiro.token.TokenManager;
  36. import com.goafanti.demand.bo.DemandListBo;
  37. import com.goafanti.demand.service.DemandService;
  38. import com.goafanti.portal.bo.AchievementObject;
  39. import com.goafanti.user.service.UserIdentityService;
  40. import com.goafanti.user.service.UserService;
  41. @Controller
  42. @Scope(value = "prototype")
  43. @RequestMapping("/open")
  44. public class PublicController extends BaseController {
  45. @Value(value = "${accessKey}")
  46. private String accessKey = null;
  47. @Value(value = "${accessSecret}")
  48. private String accessSecret = null;
  49. @Value(value = "${upload.path}")
  50. private String uploadPath = null;
  51. @Value(value = "${upload.private.path}")
  52. private String uploadPrivatePath = null;
  53. @Value(value = "${static.host}")
  54. private String staticHost = null;
  55. @Value(value = "${mobileCodeTemplate}")
  56. private String mobileCodeTemplate = null;
  57. @Resource
  58. private UserService userService;
  59. @Resource
  60. private FieldGlossoryService fieldGlossoryService;
  61. @Resource
  62. private CommentService commentService;
  63. @Autowired
  64. private IndustryCategoryService industryCategoryService;
  65. @Autowired
  66. private DistrictGlossoryService districtGlossoryService;
  67. @Autowired
  68. private UserIdentityService userIdentityService;
  69. @Autowired
  70. private AchievementService achievementService;
  71. @Autowired
  72. private DemandService demandService;
  73. @Value(value = "${patentTemplate}")
  74. private String patentTemplate = null;
  75. @Resource(name = "passwordUtil")
  76. private PasswordUtil passwordUtil;
  77. /**
  78. * 获取验证码
  79. *
  80. * @param response
  81. */
  82. @RequestMapping(value = "/getVCode", method = RequestMethod.GET)
  83. public void getVCode(HttpServletResponse response, HttpServletRequest request) {
  84. try {
  85. response.setHeader("Pragma", "No-cache");
  86. response.setHeader("Cache-Control", "no-cache");
  87. response.setDateHeader("Expires", 0);
  88. response.setContentType("image/jpg");
  89. // 生成随机字串
  90. String verifyCode = VerifyCodeUtils.generateVerifyCode(4);
  91. // 存入Shiro会话session
  92. TokenManager.setVal2Session(VerifyCodeUtils.V_CODE, verifyCode.toLowerCase());
  93. // 生成图片
  94. int w = 146, h = 33;
  95. VerifyCodeUtils.outputImage(w, h, response.getOutputStream(), verifyCode);
  96. } catch (Exception e) {
  97. LoggerUtils.fmtError(getClass(), e, "获取验证码异常:%s", e.getMessage());
  98. }
  99. }
  100. /**
  101. * 手机验证码
  102. *
  103. * @param mobile
  104. * @param sign
  105. * 是否用与找回密码
  106. * @param type
  107. * @return
  108. */
  109. @RequestMapping(value = "/getMCode", method = RequestMethod.GET)
  110. @ResponseBody
  111. public Result getMcode(String mobile, boolean sign, String verificationCode) {
  112. Result res = new Result();
  113. // 用于找回密码
  114. if (sign) {
  115. if (null == userService.selectByMobieAndType(mobile.trim(),null)) {
  116. res.getError().add(buildError(ErrorConstants.NON_REGISTER, "", "该用户未注册!"));
  117. return res;
  118. }
  119. }
  120. /*if (!sign) {
  121. if (StringUtils.isBlank(verificationCode)) {
  122. res.getError().add(buildError(ErrorConstants.VCODE_EMPTY_ERROR, "", "图像验证码不能为空!"));
  123. return res;
  124. }
  125. if (!VerifyCodeUtils.verifyCode(verificationCode)) {
  126. res.getError().add(buildError(ErrorConstants.VCODE_ERROR, "", "图形验证码输入错误!"));
  127. return res;
  128. }
  129. }
  130. */
  131. if (TokenManager.getSession().getAttribute(VerifyCodeUtils.M_CODE_TIME) == null
  132. || TokenManager.getSession().getAttribute(VerifyCodeUtils.M_CODE_TIME) == "") {
  133. sendMessage(mobile, res,VerifyCodeUtils.M_CODE);
  134. } else if (TimeUtils.checkOverTime("getMCode")) {
  135. VerifyCodeUtils.clearMobileCode();
  136. VerifyCodeUtils.clearMobileCodeTime();
  137. sendMessage(mobile, res,VerifyCodeUtils.M_CODE);
  138. } else {
  139. res.getError().add(buildError(ErrorConstants.MCODE_FREQUENCY_ERROR, "", "手机验证码发送频繁!"));
  140. }
  141. return res;
  142. }
  143. /**
  144. *
  145. * @param mobile
  146. * @param res
  147. * @return
  148. */
  149. private Result sendMessage(String mobile, Result res,String codeType) {
  150. String mobileVerifyCode = VerifyCodeUtils.generateMobileVerifyCode(6); // 生成随机字串
  151. if(VerifyCodeUtils.M_CODE.equals(codeType)){
  152. TokenManager.setVal2Session(VerifyCodeUtils.M_CODE, mobileVerifyCode);// 存入Shiro会话session
  153. TokenManager.setVal2Session(VerifyCodeUtils.M_CODE_TIME, System.currentTimeMillis());
  154. }else if(VerifyCodeUtils.RESET_CODE.equals(codeType)){
  155. TokenManager.setVal2Session(VerifyCodeUtils.RESET_CODE, mobileVerifyCode);// 存入Shiro会话session
  156. TokenManager.setVal2Session(VerifyCodeUtils.RESET_CODE_TIME, System.currentTimeMillis());
  157. }
  158. String paramString = "{\"code\":\"" + mobileVerifyCode + "\",\"product\":\"技淘网\"}";
  159. String ret = MobileMessageUtils.sendMessage(mobileCodeTemplate, paramString, mobile, accessKey, accessSecret);
  160. if (StringUtils.isNotBlank(ret)) {
  161. res.getError().add(buildError(ErrorConstants.M_CODE_ERROR));
  162. }
  163. return res;
  164. }
  165. /**
  166. * 下载图片
  167. *
  168. * @param response
  169. * @param path
  170. * @param request
  171. */
  172. @RequestMapping(value = "/downLoadPicture", method = RequestMethod.GET)
  173. public Result downLoadPicture(HttpServletResponse response, String path, HttpServletRequest request) {
  174. Result res = new Result();
  175. if (StringUtils.isBlank(path)) {
  176. res.getError().add(buildError(ErrorConstants.FILE_NON_EXISTENT));
  177. return res;
  178. }
  179. String filename = Long.toString(System.nanoTime()) + ".jpg";
  180. InputStream in = null;
  181. OutputStream out = null;
  182. byte[] buffer = new byte[8 * 1024];
  183. String fileSaveRootPath = "";
  184. try {
  185. fileSaveRootPath = uploadPrivatePath + path;
  186. File file = new File(fileSaveRootPath);
  187. in = new FileInputStream(file);
  188. out = response.getOutputStream();
  189. // 设置文件MIME类型
  190. response.setContentType("application/octet-stream");
  191. response.setHeader("Content-Disposition", "attachment; filename=" + filename);
  192. for (;;) {
  193. int bytes = in.read(buffer);
  194. if (bytes == -1) {
  195. break;
  196. }
  197. out.write(buffer, 0, bytes);
  198. }
  199. } catch (IOException e) {
  200. LoggerUtils.fmtError(getClass(), e, "IO错误:%s", e.getMessage());
  201. } finally {
  202. try {
  203. if (null != in) {
  204. in.close();
  205. }
  206. } catch (IOException e) {
  207. LoggerUtils.fmtError(getClass(), e, "IO错误:%s", e.getMessage());
  208. }
  209. try {
  210. if (null != out) {
  211. out.close();
  212. }
  213. } catch (IOException e) {
  214. LoggerUtils.fmtError(getClass(), e, "IO错误:%s", e.getMessage());
  215. }
  216. }
  217. return res;
  218. }
  219. /**
  220. * 删除图片文件(public图片)
  221. *
  222. * @param path
  223. * @return
  224. */
  225. @RequestMapping(value = "/deleteUploadPicture", method = RequestMethod.POST)
  226. public boolean deleteUploadPicture(String path) {
  227. boolean flag = false;
  228. path = uploadPath + path;
  229. File file = new File(path);
  230. // 判断目录或文件是否存在
  231. if (!file.exists() || !file.isFile()) { // 不存在返回 false
  232. return flag;
  233. } else {
  234. return file.delete();
  235. }
  236. }
  237. /**
  238. * 获取并输出private图片
  239. */
  240. @RequestMapping(value = "/writeImage", method = RequestMethod.GET)
  241. public void writeImage(HttpServletResponse response, HttpServletRequest request, String path) {
  242. try {
  243. String realPath = uploadPrivatePath + path;
  244. PictureUtils.outputImage(response, realPath);
  245. } catch (IOException e) {
  246. LoggerUtils.fmtError(getClass(), e, "获取图片异常:%s", e.getMessage());
  247. }
  248. }
  249. /**
  250. * 下载文件
  251. *
  252. * @param res
  253. * @param fileName
  254. * @param response
  255. * @param path
  256. * @param request
  257. * @return
  258. */
  259. @RequestMapping(value = "/downloadFile", method = RequestMethod.GET)
  260. public Result downloadFile(String fileName, HttpServletResponse response, String path) {
  261. Result res = new Result();
  262. return handleDownloadFile(response, fileName, path, res);
  263. }
  264. private Result handleDownloadFile(HttpServletResponse response, String fileName, String path, Result res) {
  265. String fileSaveRootPath = uploadPrivatePath + path;
  266. InputStream in = null;
  267. OutputStream out = null;
  268. byte[] buffer = new byte[8 * 1024];
  269. try {
  270. File file = new File(fileSaveRootPath);
  271. in = new FileInputStream(file);
  272. out = response.getOutputStream();
  273. response.setContentType("multipart/form-data");
  274. fileName = java.net.URLEncoder.encode(fileName, "UTF-8");
  275. response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
  276. for (;;) {
  277. int bytes = in.read(buffer);
  278. if (bytes == -1) {
  279. break;
  280. }
  281. out.write(buffer, 0, bytes);
  282. }
  283. } catch (IOException e) {
  284. LoggerUtils.fmtError(getClass(), e, "IO错误:%s", e.getMessage());
  285. } finally {
  286. try {
  287. in.close();
  288. } catch (IOException e) {
  289. LoggerUtils.fmtError(getClass(), e, "IO错误:%s", e.getMessage());
  290. }
  291. try {
  292. out.close();
  293. } catch (IOException e) {
  294. LoggerUtils.fmtError(getClass(), e, "IO错误:%s", e.getMessage());
  295. }
  296. }
  297. return res;
  298. }
  299. @RequestMapping(value = "/findIndustryCategory", method = RequestMethod.GET)
  300. @ResponseBody
  301. public Result findIndustryCategory(String id, String noCache) {
  302. Integer pid = 0;
  303. if (StringUtils.isNumeric(id)) {
  304. try {
  305. pid = Integer.parseInt(id);
  306. } catch (Exception e) {
  307. pid = 0;
  308. }
  309. }
  310. if (StringUtils.isNotBlank(noCache)) {
  311. industryCategoryService.clear(pid);
  312. }
  313. return new Result().data(industryCategoryService.list(pid));
  314. }
  315. @RequestMapping(value = "/findDistrict", method = RequestMethod.GET)
  316. @ResponseBody
  317. public Result findDistrictGlossory(String id, String noCache) {
  318. Integer pid = 0;
  319. if (StringUtils.isNumeric(id)) {
  320. try {
  321. pid = Integer.parseInt(id);
  322. } catch (Exception e) {
  323. pid = 0;
  324. }
  325. }
  326. if (StringUtils.isNotBlank(noCache)) {
  327. districtGlossoryService.clear(pid);
  328. }
  329. return new Result().data(districtGlossoryService.list(pid));
  330. }
  331. /**
  332. *
  333. * @param mobileCode
  334. * @return
  335. */
  336. @RequestMapping(value = "/checkMCode", method = RequestMethod.POST)
  337. @ResponseBody
  338. public Result checkMCode(String mobileCode) {
  339. Result res = new Result();
  340. if (StringUtils.isBlank(mobileCode)) {
  341. res.getError().add(buildError(ErrorConstants.MCODE_EMPTY_ERROR, "", "手机验证码"));
  342. return res;
  343. }
  344. if (TimeUtils.checkOverTime(VerifyCodeUtils.M_CODE)) {
  345. res.getError().add(buildError(ErrorConstants.MCODE_OVERTIME_ERROR, "", "手机验证码超时失效!"));
  346. VerifyCodeUtils.clearMobileCode();
  347. VerifyCodeUtils.clearMobileCodeTime();
  348. return res;
  349. }
  350. if (!TokenManager.getSession().getAttribute(VerifyCodeUtils.M_CODE).equals(mobileCode)) {
  351. res.getError().add(buildError(ErrorConstants.MCODE_ERROR, "", "手机验证码错误"));
  352. return res;
  353. }
  354. // resetCode
  355. if (res.getError().isEmpty()) {
  356. String resetCode = UUID.randomUUID().toString();
  357. TokenManager.setVal2Session(VerifyCodeUtils.RESET_CODE, resetCode);
  358. TokenManager.setVal2Session(VerifyCodeUtils.RESET_CODE_TIME, System.currentTimeMillis());
  359. res.setData(resetCode);
  360. }
  361. return res;
  362. }
  363. /**
  364. * 重置密码
  365. *
  366. * @param resetCode
  367. * @param mobile
  368. * @param type
  369. * @param newPwd
  370. * @return
  371. */
  372. @RequestMapping(value = "/resetPwd", method = RequestMethod.POST)
  373. @ResponseBody
  374. public Result resetPwd(String resetCode, String mobile, Integer type, String newPwd) {
  375. Result res = new Result();
  376. if (TimeUtils.checkOverTime(VerifyCodeUtils.M_CODE)) {
  377. res.getError().add(buildError(ErrorConstants.RESET_CODE_OVERTIME, "", "页面超时失效,请重新获取验证码!"));
  378. cleanCodeSession();
  379. return res;
  380. }
  381. if(null == TokenManager.getSession().getAttribute(VerifyCodeUtils.RESET_CODE)){
  382. res.getError().add(buildError(ErrorConstants.RESET_CODE_OVERTIME, "", "页面超时失效,请重新获取验证码!"));
  383. cleanCodeSession();
  384. return res;
  385. }else if(!TokenManager.getSession().getAttribute(VerifyCodeUtils.RESET_CODE).equals(resetCode)){
  386. res.getError().add(buildError(ErrorConstants.RESET_CODE_ERROR, "", "验证码错误,请重新获取验证码!"));
  387. cleanCodeSession();
  388. return res;
  389. }
  390. if (StringUtils.isBlank(newPwd)) {
  391. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "新密码"));
  392. return res;
  393. }
  394. if (StringUtils.isBlank(mobile)) {
  395. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "mobile"));
  396. return res;
  397. }
  398. if (!UserType.ORGANIZATION.getCode().equals(type) && !UserType.PERSONAL.getCode().equals(type)) {
  399. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "type"));
  400. return res;
  401. }
  402. User user = userService.selectByMobieAndType(mobile, type);
  403. if (null == user) {
  404. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "mobile"));
  405. return res;
  406. }
  407. user.setPassword(newPwd);
  408. user.setPassword(passwordUtil.getEncryptPwd(user));
  409. userService.updateByPrimaryKeySelective(user);
  410. VerifyCodeUtils.clearResetCode();
  411. VerifyCodeUtils.clearResetCodeTime();
  412. return res;
  413. }
  414. @RequestMapping(value = "/resetPassword", method = RequestMethod.POST)
  415. @ResponseBody
  416. public Result resetPassword(String mobile,Integer type,String newPwd,String resetCode) {
  417. Result res=new Result();
  418. if (TimeUtils.checkOverTime(VerifyCodeUtils.M_CODE)) {
  419. res.getError().add(buildError(ErrorConstants.RESET_CODE_OVERTIME, "", "页面超时失效,请重新获取验证码!"));
  420. cleanCodeSession();
  421. return res;
  422. }
  423. if(null == TokenManager.getSession().getAttribute(VerifyCodeUtils.RESET_CODE)){
  424. res.getError().add(buildError(ErrorConstants.RESET_CODE_OVERTIME, "", "页面超时失效,请重新获取验证码!"));
  425. cleanCodeSession();
  426. return res;
  427. }else if(!TokenManager.getSession().getAttribute(VerifyCodeUtils.RESET_CODE).equals(resetCode)){
  428. res.getError().add(buildError(ErrorConstants.RESET_CODE_ERROR, "", "验证码错误,请重新获取验证码!"));
  429. cleanCodeSession();
  430. return res;
  431. }
  432. if (StringUtils.isBlank(newPwd)) {
  433. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "新密码"));
  434. return res;
  435. }
  436. if (StringUtils.isBlank(mobile)) {
  437. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "用户名"));
  438. return res;
  439. }
  440. User user=userService.selectByNameAndType(mobile, type);
  441. user.setPassword(newPwd);
  442. user.setPassword(passwordUtil.getEncryptPwd(user));
  443. userService.updateByPrimaryKeySelective(user);
  444. return res;
  445. }
  446. /**
  447. *
  448. * @param mobileCode
  449. * @return
  450. */
  451. @RequestMapping(value = "/checkMNCode", method = RequestMethod.POST)
  452. @ResponseBody
  453. public Result checkMNCode(String mobileCode,String userName,String mobile) {
  454. Result res = new Result();
  455. if (StringUtils.isBlank(mobileCode)) {
  456. res.getError().add(buildError(ErrorConstants.MCODE_EMPTY_ERROR, "", "手机验证码"));
  457. return res;
  458. }
  459. if (StringUtils.isBlank(mobile)) {
  460. res.getError().add(buildError(ErrorConstants.MCODE_EMPTY_ERROR, "", "手机号"));
  461. return res;
  462. }
  463. if (StringUtils.isBlank(userName)) {
  464. res.getError().add(buildError(ErrorConstants.MCODE_EMPTY_ERROR, "", "用户名"));
  465. return res;
  466. }
  467. if (TimeUtils.checkOverTime(VerifyCodeUtils.M_CODE)) {
  468. res.getError().add(buildError(ErrorConstants.MCODE_OVERTIME_ERROR, "", "手机验证码超时失效!"));
  469. VerifyCodeUtils.clearMobileCode();
  470. VerifyCodeUtils.clearMobileCodeTime();
  471. return res;
  472. }
  473. if (!TokenManager.getSession().getAttribute(VerifyCodeUtils.M_CODE).equals(mobileCode)) {
  474. res.getError().add(buildError(ErrorConstants.MCODE_ERROR, "", "手机验证码错误"));
  475. return res;
  476. }
  477. User user=userService.selectByNameAndType(userName, null);
  478. if(user==null || user.getMobile()==null || !user.getMobile().equals(mobile))
  479. {
  480. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "手机号或用户名错误"));
  481. return res;
  482. }
  483. // resetCode
  484. if (res.getError().isEmpty()) {
  485. String resetCode = UUID.randomUUID().toString();
  486. TokenManager.setVal2Session(VerifyCodeUtils.RESET_CODE, resetCode);
  487. TokenManager.setVal2Session(VerifyCodeUtils.RESET_CODE_TIME, System.currentTimeMillis());
  488. res.setData(resetCode);
  489. }
  490. return res;
  491. }
  492. private void cleanCodeSession() {
  493. VerifyCodeUtils.clearResetCode();
  494. VerifyCodeUtils.clearResetCodeTime();
  495. VerifyCodeUtils.clearMobileCode();
  496. VerifyCodeUtils.clearMobileCodeTime();
  497. }
  498. @RequestMapping(value = "/getRegisterMCode", method = RequestMethod.GET )
  499. @ResponseBody
  500. public Result getRegisterMCode(String mobile){
  501. Result res = new Result();
  502. if (TokenManager.getSession().getAttribute(VerifyCodeUtils.M_CODE_TIME) == null
  503. || TokenManager.getSession().getAttribute(VerifyCodeUtils.M_CODE_TIME) == "") {
  504. sendMessage(mobile, res,VerifyCodeUtils.M_CODE);
  505. } else if (TimeUtils.checkOverTime("getMCode")) {
  506. VerifyCodeUtils.clearMobileCode();
  507. VerifyCodeUtils.clearMobileCodeTime();
  508. sendMessage(mobile, res,VerifyCodeUtils.M_CODE);
  509. } else {
  510. res.getError().add(buildError(ErrorConstants.MCODE_FREQUENCY_ERROR, "", "手机验证码发送频繁!"));
  511. }
  512. return res;
  513. }
  514. @RequestMapping(value = "/getResetMCode", method = RequestMethod.GET )
  515. @ResponseBody
  516. public Result getResetMCode(String mobile) {
  517. Result res = new Result();
  518. if (userService.selectByMobieAndTypeCount(mobile.trim())<1) {
  519. res.getError().add(buildError(ErrorConstants.NON_REGISTER, "", "该用户未注册!"));
  520. return res;
  521. }
  522. if (TokenManager.getSession().getAttribute(VerifyCodeUtils.RESET_CODE_TIME) == null
  523. || TokenManager.getSession().getAttribute(VerifyCodeUtils.RESET_CODE_TIME) == "") {
  524. sendMessage(mobile, res,VerifyCodeUtils.RESET_CODE);
  525. } else if (TimeUtils.checkOverTime("resetCode")) {
  526. VerifyCodeUtils.clearMobileCode();
  527. VerifyCodeUtils.clearMobileCodeTime();
  528. sendMessage(mobile, res,VerifyCodeUtils.RESET_CODE);
  529. } else {
  530. res.getError().add(buildError(ErrorConstants.MCODE_FREQUENCY_ERROR, "", "手机验证码发送频繁!"));
  531. }
  532. return res;
  533. }
  534. /** 省市区查询 **/
  535. @RequestMapping(value = "/listAllProvince" , method = RequestMethod.POST)
  536. @ResponseBody
  537. public Result listAllProvince(){
  538. Result res = new Result();
  539. res.setData(districtGlossoryService.getProvince());
  540. return res;
  541. }
  542. @RequestMapping(value="/industryList", method = RequestMethod.GET)
  543. @ResponseBody
  544. public Result getIndustryList() {
  545. Result result=new Result();
  546. result.setData(userIdentityService.selectIndustryReletively());
  547. return result;
  548. }
  549. @RequestMapping(value="/achievementList", method = RequestMethod.GET)
  550. @ResponseBody
  551. public Result getAchievements(AchievementObject achievementObject,Integer pageNo,Integer pageSize) {
  552. Result result=new Result();
  553. result.setData(achievementService.getAchievementObjects(achievementObject, pageNo, pageSize));
  554. return result;
  555. }
  556. @RequestMapping(value="/demandList", method = RequestMethod.GET)
  557. @ResponseBody
  558. public Result getDemands(DemandListBo demandListBo,Integer pageNo,Integer pageSize) {
  559. Result result=new Result();
  560. result.setData(demandService.getDemandObjects(demandListBo, pageNo, pageSize));
  561. return result;
  562. }
  563. @RequestMapping(value = "/comment/list", method = RequestMethod.GET)
  564. @ResponseBody
  565. public Result listComment(String commodityId,Integer pageNo,Integer pageSize) {
  566. Result result=new Result();
  567. if(StringUtils.isBlank(commodityId)) {
  568. result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"","商品id"));
  569. }
  570. CommentResult commentResult=new CommentResult();
  571. commentResult.setPositiveCommentCount(commentService.getCommentCount(0, commodityId));
  572. commentResult.setOrdinaryCommentCount(commentService.getCommentCount(1, commodityId));
  573. commentResult.setNegativeCommentCount(commentService.getCommentCount(2, commodityId));
  574. commentResult.setComments(commentService.searchComment(commodityId, pageNo, pageSize));
  575. result.setData(commentResult);
  576. return result;
  577. }
  578. /**
  579. * APP重置密码
  580. */
  581. @RequestMapping(value = "/appResetPwd", method = RequestMethod.POST)
  582. @ResponseBody
  583. public Result resetPwd(String resetCode, String username,String mobile, Integer type, String newPwd) {
  584. Result res = new Result();
  585. if (TimeUtils.checkOverTime(VerifyCodeUtils.M_CODE)) {
  586. res.getError().add(buildError(ErrorConstants.RESET_CODE_OVERTIME, "", "页面超时失效,请重新获取验证码!"));
  587. cleanCodeSession();
  588. return res;
  589. }
  590. if(null == TokenManager.getSession().getAttribute(VerifyCodeUtils.RESET_CODE)){
  591. res.getError().add(buildError(ErrorConstants.RESET_CODE_OVERTIME, "", "页面超时失效,请重新获取验证码!"));
  592. cleanCodeSession();
  593. return res;
  594. }else if(!TokenManager.getSession().getAttribute(VerifyCodeUtils.RESET_CODE).equals(resetCode)){
  595. res.getError().add(buildError(ErrorConstants.RESET_CODE_ERROR, "", "验证码错误,请重新获取验证码!"));
  596. cleanCodeSession();
  597. return res;
  598. }
  599. if (StringUtils.isBlank(newPwd)) {
  600. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "新密码"));
  601. return res;
  602. }
  603. if (StringUtils.isBlank(mobile)) {
  604. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "mobile"));
  605. return res;
  606. }
  607. /*if (!UserType.ORGANIZATION.getCode().equals(type) && !UserType.PERSONAL.getCode().equals(type)) {
  608. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "type"));
  609. return res;
  610. }*/
  611. User user = userService.selectByMobieAndType(mobile, type);
  612. if (null == user) {
  613. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "用户"));
  614. return res;
  615. }
  616. if (null!=user.getMobile()&&!user.getMobile().equals(mobile)) {
  617. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "手机号码"));
  618. return res;
  619. }
  620. user.setPassword(newPwd);
  621. user.setPassword(passwordUtil.getEncryptPwd(user));
  622. userService.updateByPrimaryKeySelective(user);
  623. VerifyCodeUtils.clearResetCode();
  624. VerifyCodeUtils.clearResetCodeTime();
  625. return res;
  626. }
  627. }