PublicController.java 26 KB

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