PublicController.java 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964
  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.*;
  8. import java.util.regex.Matcher;
  9. import java.util.regex.Pattern;
  10. import javax.annotation.Resource;
  11. import javax.servlet.http.HttpServletRequest;
  12. import javax.servlet.http.HttpServletResponse;
  13. import com.alibaba.fastjson.JSONObject;
  14. import com.goafanti.common.model.JtNews;
  15. import com.goafanti.common.utils.*;
  16. import com.goafanti.news.bo.InputJtNews;
  17. import com.goafanti.news.bo.OutJtNews;
  18. import com.goafanti.news.service.EventPlanningService;
  19. import org.apache.commons.lang3.StringUtils;
  20. import org.springframework.beans.factory.annotation.Autowired;
  21. import org.springframework.beans.factory.annotation.Value;
  22. import org.springframework.context.annotation.Scope;
  23. import org.springframework.stereotype.Controller;
  24. import org.springframework.web.bind.annotation.RequestMapping;
  25. import org.springframework.web.bind.annotation.RequestMethod;
  26. import org.springframework.web.bind.annotation.ResponseBody;
  27. import com.goafanti.achievement.service.AchievementService;
  28. import com.goafanti.business.bo.JtBusinessProjectResult;
  29. import com.goafanti.business.service.JtBusinessService;
  30. import com.goafanti.comment.bo.CommentInput;
  31. import com.goafanti.comment.bo.CommentResult;
  32. import com.goafanti.comment.controller.UserCommentController;
  33. import com.goafanti.comment.service.CommentService;
  34. import com.goafanti.common.bo.Result;
  35. import com.goafanti.common.constant.ErrorConstants;
  36. import com.goafanti.common.enums.UserType;
  37. import com.goafanti.common.model.JtBusinessProject;
  38. import com.goafanti.common.model.User;
  39. import com.goafanti.common.service.DistrictGlossoryService;
  40. import com.goafanti.common.service.FieldGlossoryService;
  41. import com.goafanti.common.service.IndustryCategoryService;
  42. import com.goafanti.core.mybatis.JDBCIdGenerator;
  43. import com.goafanti.core.mybatis.page.Pagination;
  44. import com.goafanti.core.shiro.token.TokenManager;
  45. import com.goafanti.demand.bo.DemandListBo;
  46. import com.goafanti.demand.service.DemandService;
  47. import com.goafanti.portal.bo.AchievementObject;
  48. import com.goafanti.user.service.UserIdentityService;
  49. import com.goafanti.user.service.UserService;
  50. import com.goafanti.voucher.bo.JtVoucherListBo;
  51. import com.goafanti.voucher.service.VoucherDetailService;
  52. import com.goafanti.voucher.service.VoucherService;
  53. @Controller
  54. @Scope(value = "prototype")
  55. @RequestMapping("/open")
  56. public class PublicController extends BaseController {
  57. @Value(value = "${accessKey}")
  58. private String accessKey = null;
  59. @Value(value = "${accessSecret}")
  60. private String accessSecret = null;
  61. @Value(value = "${upload.path}")
  62. private String uploadPath = null;
  63. @Value(value = "${upload.private.path}")
  64. private String uploadPrivatePath = null;
  65. @Value(value = "${static.host}")
  66. private String staticHost = null;
  67. @Value(value = "${mobileCodeTemplate}")
  68. private String mobileCodeTemplate = null;
  69. @Resource
  70. private UserService userService;
  71. @Resource
  72. private FieldGlossoryService fieldGlossoryService;
  73. @Resource
  74. private CommentService commentService;
  75. @Autowired
  76. private IndustryCategoryService industryCategoryService;
  77. @Autowired
  78. private DistrictGlossoryService districtGlossoryService;
  79. @Autowired
  80. private UserIdentityService userIdentityService;
  81. @Autowired
  82. private AchievementService achievementService;
  83. @Autowired
  84. private DemandService demandService;
  85. @Autowired
  86. private JtBusinessService jtBusinessService;
  87. @Value(value = "${patentTemplate}")
  88. private String patentTemplate = null;
  89. @Resource(name = "passwordUtil")
  90. private PasswordUtil passwordUtil;
  91. @Resource
  92. private VoucherDetailService voucherDetailService;
  93. @Resource
  94. private VoucherService voucherService;
  95. @Resource
  96. private EventPlanningService eventPlanningService;
  97. /**
  98. * 获取验证码
  99. *
  100. * @param response
  101. */
  102. @RequestMapping(value = "/getVCode", method = RequestMethod.GET)
  103. public void getVCode(HttpServletResponse response, HttpServletRequest request) {
  104. try {
  105. response.setHeader("Pragma", "No-cache");
  106. response.setHeader("Cache-Control", "no-cache");
  107. response.setDateHeader("Expires", 0);
  108. response.setContentType("image/jpg");
  109. // 生成随机字串
  110. String verifyCode = VerifyCodeUtils.generateVerifyCode(4);
  111. // 存入Shiro会话session
  112. TokenManager.setVal2Session(VerifyCodeUtils.V_CODE, verifyCode.toLowerCase());
  113. // 生成图片
  114. int w = 146, h = 33;
  115. VerifyCodeUtils.outputImage(w, h, response.getOutputStream(), verifyCode);
  116. } catch (Exception e) {
  117. LoggerUtils.fmtError(getClass(), e, "获取验证码异常:%s", e.getMessage());
  118. }
  119. }
  120. /**
  121. * 手机验证码
  122. *
  123. * @param mobile
  124. * @param sign
  125. * 是否用与找回密码
  126. * @return
  127. */
  128. @RequestMapping(value = "/getMCode", method = RequestMethod.GET)
  129. @ResponseBody
  130. public Result getMcode(String mobile, boolean sign, String verificationCode) {
  131. Result res = new Result();
  132. // 用于找回密码
  133. if (sign) {
  134. if (null == userService.selectByMobieAndType(mobile.trim(),null)) {
  135. res.getError().add(buildError(ErrorConstants.NON_REGISTER, "", "该用户未注册!"));
  136. return res;
  137. }
  138. }
  139. /*if (!sign) {
  140. if (StringUtils.isBlank(verificationCode)) {
  141. res.getError().add(buildError(ErrorConstants.VCODE_EMPTY_ERROR, "", "图像验证码不能为空!"));
  142. return res;
  143. }
  144. if (!VerifyCodeUtils.verifyCode(verificationCode)) {
  145. res.getError().add(buildError(ErrorConstants.VCODE_ERROR, "", "图形验证码输入错误!"));
  146. return res;
  147. }
  148. }
  149. */
  150. if (TokenManager.getSession().getAttribute(VerifyCodeUtils.M_CODE_TIME) == null
  151. || TokenManager.getSession().getAttribute(VerifyCodeUtils.M_CODE_TIME) == "") {
  152. sendMessage(mobile, res,VerifyCodeUtils.M_CODE);
  153. } else if (TimeUtils.checkOverTime("getMCode")) {
  154. VerifyCodeUtils.clearMobileCode();
  155. VerifyCodeUtils.clearMobileCodeTime();
  156. sendMessage(mobile, res,VerifyCodeUtils.M_CODE);
  157. } else {
  158. res.getError().add(buildError(ErrorConstants.MCODE_FREQUENCY_ERROR, "", "手机验证码发送频繁!"));
  159. }
  160. return res;
  161. }
  162. /**
  163. *
  164. * @param mobile
  165. * @param res
  166. * @return
  167. */
  168. private Result sendMessage(String mobile, Result res,String codeType) {
  169. String mobileVerifyCode = VerifyCodeUtils.generateMobileVerifyCode(6); // 生成随机字串
  170. if(VerifyCodeUtils.M_CODE.equals(codeType)){
  171. TokenManager.setVal2Session(VerifyCodeUtils.M_CODE, mobileVerifyCode);// 存入Shiro会话session
  172. TokenManager.setVal2Session(VerifyCodeUtils.M_CODE_TIME, System.currentTimeMillis());
  173. }else if(VerifyCodeUtils.RESET_CODE.equals(codeType)){
  174. TokenManager.setVal2Session(VerifyCodeUtils.RESET_CODE, mobileVerifyCode);// 存入Shiro会话session
  175. TokenManager.setVal2Session(VerifyCodeUtils.RESET_CODE_TIME, System.currentTimeMillis());
  176. }
  177. String paramString = "{\"code\":\"" + mobileVerifyCode + "\",\"product\":\"技淘网\"}";
  178. String ret = MobileMessageUtils.sendMessage(mobileCodeTemplate, paramString, mobile, accessKey, accessSecret);
  179. if (StringUtils.isNotBlank(ret)) {
  180. res.getError().add(buildError(ErrorConstants.M_CODE_ERROR));
  181. }
  182. return res;
  183. }
  184. /**
  185. * 下载图片
  186. *
  187. * @param response
  188. * @param path
  189. * @param request
  190. */
  191. @RequestMapping(value = "/downLoadPicture", method = RequestMethod.GET)
  192. public Result downLoadPicture(HttpServletResponse response, String path, HttpServletRequest request) {
  193. Result res = new Result();
  194. if (StringUtils.isBlank(path)) {
  195. res.getError().add(buildError(ErrorConstants.FILE_NON_EXISTENT));
  196. return res;
  197. }
  198. String filename = Long.toString(System.nanoTime()) + ".jpg";
  199. InputStream in = null;
  200. OutputStream out = null;
  201. byte[] buffer = new byte[8 * 1024];
  202. String fileSaveRootPath = "";
  203. try {
  204. fileSaveRootPath = uploadPrivatePath + path;
  205. File file = new File(fileSaveRootPath);
  206. in = new FileInputStream(file);
  207. out = response.getOutputStream();
  208. // 设置文件MIME类型
  209. response.setContentType("application/octet-stream");
  210. response.setHeader("Content-Disposition", "attachment; filename=" + filename);
  211. for (;;) {
  212. int bytes = in.read(buffer);
  213. if (bytes == -1) {
  214. break;
  215. }
  216. out.write(buffer, 0, bytes);
  217. }
  218. } catch (IOException e) {
  219. LoggerUtils.fmtError(getClass(), e, "IO错误:%s", e.getMessage());
  220. } finally {
  221. try {
  222. if (null != in) {
  223. in.close();
  224. }
  225. } catch (IOException e) {
  226. LoggerUtils.fmtError(getClass(), e, "IO错误:%s", e.getMessage());
  227. }
  228. try {
  229. if (null != out) {
  230. out.close();
  231. }
  232. } catch (IOException e) {
  233. LoggerUtils.fmtError(getClass(), e, "IO错误:%s", e.getMessage());
  234. }
  235. }
  236. return res;
  237. }
  238. /**
  239. * 删除图片文件(public图片)
  240. *
  241. * @param path
  242. * @return
  243. */
  244. @RequestMapping(value = "/deleteUploadPicture", method = RequestMethod.POST)
  245. public boolean deleteUploadPicture(String path) {
  246. boolean flag = false;
  247. path = uploadPath + path;
  248. File file = new File(path);
  249. // 判断目录或文件是否存在
  250. if (!file.exists() || !file.isFile()) { // 不存在返回 false
  251. return flag;
  252. } else {
  253. return file.delete();
  254. }
  255. }
  256. /**
  257. * 获取并输出private图片
  258. */
  259. @RequestMapping(value = "/writeImage", method = RequestMethod.GET)
  260. public void writeImage(HttpServletResponse response, HttpServletRequest request, String path) {
  261. try {
  262. String realPath = uploadPrivatePath + path;
  263. PictureUtils.outputImage(response, realPath);
  264. } catch (IOException e) {
  265. LoggerUtils.fmtError(getClass(), e, "获取图片异常:%s", e.getMessage());
  266. }
  267. }
  268. /**
  269. * 下载文件
  270. *
  271. * @param fileName
  272. * @param response
  273. * @param path
  274. * @return
  275. */
  276. @RequestMapping(value = "/downloadFile", method = RequestMethod.GET)
  277. public Result downloadFile(String fileName, HttpServletResponse response, String path) {
  278. Result res = new Result();
  279. return handleDownloadFile(response, fileName, path, res);
  280. }
  281. private Result handleDownloadFile(HttpServletResponse response, String fileName, String path, Result res) {
  282. String fileSaveRootPath = uploadPrivatePath + path;
  283. InputStream in = null;
  284. OutputStream out = null;
  285. byte[] buffer = new byte[8 * 1024];
  286. try {
  287. File file = new File(fileSaveRootPath);
  288. in = new FileInputStream(file);
  289. out = response.getOutputStream();
  290. response.setContentType("multipart/form-data");
  291. fileName = java.net.URLEncoder.encode(fileName, "UTF-8");
  292. response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
  293. for (;;) {
  294. int bytes = in.read(buffer);
  295. if (bytes == -1) {
  296. break;
  297. }
  298. out.write(buffer, 0, bytes);
  299. }
  300. } catch (IOException e) {
  301. LoggerUtils.fmtError(getClass(), e, "IO错误:%s", e.getMessage());
  302. } finally {
  303. try {
  304. in.close();
  305. } catch (IOException e) {
  306. LoggerUtils.fmtError(getClass(), e, "IO错误:%s", e.getMessage());
  307. }
  308. try {
  309. out.close();
  310. } catch (IOException e) {
  311. LoggerUtils.fmtError(getClass(), e, "IO错误:%s", e.getMessage());
  312. }
  313. }
  314. return res;
  315. }
  316. @RequestMapping(value = "/findIndustryCategory", method = RequestMethod.GET)
  317. @ResponseBody
  318. public Result findIndustryCategory(String id, String noCache) {
  319. Integer pid = 0;
  320. if (StringUtils.isNumeric(id)) {
  321. try {
  322. pid = Integer.parseInt(id);
  323. } catch (Exception e) {
  324. pid = 0;
  325. }
  326. }
  327. if (StringUtils.isNotBlank(noCache)) {
  328. industryCategoryService.clear(pid);
  329. }
  330. return new Result().data(industryCategoryService.list(pid));
  331. }
  332. @RequestMapping(value = "/findDistrict", method = RequestMethod.GET)
  333. @ResponseBody
  334. public Result findDistrictGlossory(String id, String noCache) {
  335. Integer pid = 0;
  336. if (StringUtils.isNumeric(id)) {
  337. try {
  338. pid = Integer.parseInt(id);
  339. } catch (Exception e) {
  340. pid = 0;
  341. }
  342. }
  343. if (StringUtils.isNotBlank(noCache)) {
  344. districtGlossoryService.clear(pid);
  345. }
  346. return new Result().data(districtGlossoryService.list(pid));
  347. }
  348. /**
  349. *
  350. * @param mobileCode
  351. * @return
  352. */
  353. @RequestMapping(value = "/checkMCode", method = RequestMethod.POST)
  354. @ResponseBody
  355. public Result checkMCode(String mobileCode) {
  356. Result res = new Result();
  357. if (StringUtils.isBlank(mobileCode)) {
  358. res.getError().add(buildError(ErrorConstants.MCODE_EMPTY_ERROR, "", "手机验证码"));
  359. return res;
  360. }
  361. if (TimeUtils.checkOverTime(VerifyCodeUtils.M_CODE)) {
  362. res.getError().add(buildError(ErrorConstants.MCODE_OVERTIME_ERROR, "", "手机验证码超时失效!"));
  363. VerifyCodeUtils.clearMobileCode();
  364. VerifyCodeUtils.clearMobileCodeTime();
  365. return res;
  366. }
  367. if (!TokenManager.getSession().getAttribute(VerifyCodeUtils.M_CODE).equals(mobileCode)) {
  368. res.getError().add(buildError(ErrorConstants.MCODE_ERROR, "", "手机验证码错误"));
  369. return res;
  370. }
  371. // resetCode
  372. if (res.getError().isEmpty()) {
  373. String resetCode = UUID.randomUUID().toString();
  374. TokenManager.setVal2Session(VerifyCodeUtils.RESET_CODE, resetCode);
  375. TokenManager.setVal2Session(VerifyCodeUtils.RESET_CODE_TIME, System.currentTimeMillis());
  376. res.setData(resetCode);
  377. }
  378. return res;
  379. }
  380. /**
  381. * 重置密码
  382. *
  383. * @param resetCode
  384. * @param mobile
  385. * @param type
  386. * @param newPwd
  387. * @return
  388. */
  389. @RequestMapping(value = "/resetPwd", method = RequestMethod.POST)
  390. @ResponseBody
  391. public Result resetPwd(String resetCode, String mobile, Integer type, String newPwd) {
  392. Result res = new Result();
  393. if (TimeUtils.checkOverTime(VerifyCodeUtils.M_CODE)) {
  394. res.getError().add(buildError(ErrorConstants.RESET_CODE_OVERTIME, "", "页面超时失效,请重新获取验证码!"));
  395. cleanCodeSession();
  396. return res;
  397. }
  398. if(null == TokenManager.getSession().getAttribute(VerifyCodeUtils.RESET_CODE)){
  399. res.getError().add(buildError(ErrorConstants.RESET_CODE_OVERTIME, "", "页面超时失效,请重新获取验证码!"));
  400. cleanCodeSession();
  401. return res;
  402. }else if(!TokenManager.getSession().getAttribute(VerifyCodeUtils.RESET_CODE).equals(resetCode)){
  403. res.getError().add(buildError(ErrorConstants.RESET_CODE_ERROR, "", "验证码错误,请重新获取验证码!"));
  404. cleanCodeSession();
  405. return res;
  406. }
  407. if (StringUtils.isBlank(newPwd)) {
  408. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "新密码"));
  409. return res;
  410. }
  411. if (StringUtils.isBlank(mobile)) {
  412. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "mobile"));
  413. return res;
  414. }
  415. if (!UserType.ORGANIZATION.getCode().equals(type) && !UserType.PERSONAL.getCode().equals(type)) {
  416. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "type"));
  417. return res;
  418. }
  419. User user = userService.selectByMobieAndType(mobile, type);
  420. if (null == user) {
  421. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "mobile"));
  422. return res;
  423. }
  424. user.setPassword(newPwd);
  425. user.setPassword(passwordUtil.getEncryptPwd(user));
  426. userService.updateByPrimaryKeySelective(user);
  427. VerifyCodeUtils.clearResetCode();
  428. VerifyCodeUtils.clearResetCodeTime();
  429. return res;
  430. }
  431. @RequestMapping(value = "/resetPassword", method = RequestMethod.POST)
  432. @ResponseBody
  433. public Result resetPassword(String mobile,Integer type,String newPwd,String resetCode) {
  434. Result res=new Result();
  435. if (TimeUtils.checkOverTime(VerifyCodeUtils.M_CODE)) {
  436. res.getError().add(buildError(ErrorConstants.RESET_CODE_OVERTIME, "", "页面超时失效,请重新获取验证码!"));
  437. cleanCodeSession();
  438. return res;
  439. }
  440. if(null == TokenManager.getSession().getAttribute(VerifyCodeUtils.RESET_CODE)){
  441. res.getError().add(buildError(ErrorConstants.RESET_CODE_OVERTIME, "", "页面超时失效,请重新获取验证码!"));
  442. cleanCodeSession();
  443. return res;
  444. }else if(!TokenManager.getSession().getAttribute(VerifyCodeUtils.RESET_CODE).equals(resetCode)){
  445. res.getError().add(buildError(ErrorConstants.RESET_CODE_ERROR, "", "验证码错误,请重新获取验证码!"));
  446. cleanCodeSession();
  447. return res;
  448. }
  449. if (StringUtils.isBlank(newPwd)) {
  450. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "新密码"));
  451. return res;
  452. }
  453. if (StringUtils.isBlank(mobile)) {
  454. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "用户名"));
  455. return res;
  456. }
  457. User user=userService.selectByMobieAndType(mobile, type);
  458. if(user==null || user.getMobile()==null || !user.getMobile().equals(mobile))
  459. {
  460. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "手机号或用户名错误"));
  461. return res;
  462. }
  463. user.setPassword(newPwd);
  464. user.setPassword(passwordUtil.getEncryptPwd(user));
  465. userService.updateByPrimaryKeySelective(user);
  466. return res;
  467. }
  468. /**
  469. *
  470. * @param mobileCode
  471. * @return
  472. */
  473. @RequestMapping(value = "/checkMNCode", method = RequestMethod.POST)
  474. @ResponseBody
  475. public Result checkMNCode(String mobileCode,Integer type,String mobile) {
  476. Result res = new Result();
  477. if (StringUtils.isBlank(mobileCode)) {
  478. res.getError().add(buildError(ErrorConstants.MCODE_EMPTY_ERROR, "", "手机验证码"));
  479. return res;
  480. }
  481. if (StringUtils.isBlank(mobile)) {
  482. res.getError().add(buildError(ErrorConstants.MCODE_EMPTY_ERROR, "", "手机号"));
  483. return res;
  484. }
  485. if (TimeUtils.checkOverTime(VerifyCodeUtils.M_CODE)) {
  486. res.getError().add(buildError(ErrorConstants.MCODE_OVERTIME_ERROR, "", "手机验证码超时失效!"));
  487. VerifyCodeUtils.clearMobileCode();
  488. VerifyCodeUtils.clearMobileCodeTime();
  489. return res;
  490. }
  491. if (!TokenManager.getSession().getAttribute(VerifyCodeUtils.M_CODE).equals(mobileCode)) {
  492. res.getError().add(buildError(ErrorConstants.MCODE_ERROR, "", "手机验证码错误"));
  493. return res;
  494. }
  495. User user=userService.selectByMobieAndType(mobile, type);
  496. if(user==null || user.getMobile()==null || !user.getMobile().equals(mobile))
  497. {
  498. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "手机号或用户名错误"));
  499. return res;
  500. }
  501. // resetCode
  502. if (res.getError().isEmpty()) {
  503. String resetCode = UUID.randomUUID().toString();
  504. TokenManager.setVal2Session(VerifyCodeUtils.RESET_CODE, resetCode);
  505. TokenManager.setVal2Session(VerifyCodeUtils.RESET_CODE_TIME, System.currentTimeMillis());
  506. res.setData(resetCode);
  507. }
  508. return res;
  509. }
  510. private void cleanCodeSession() {
  511. VerifyCodeUtils.clearResetCode();
  512. VerifyCodeUtils.clearResetCodeTime();
  513. VerifyCodeUtils.clearMobileCode();
  514. VerifyCodeUtils.clearMobileCodeTime();
  515. }
  516. @RequestMapping(value = "/getRegisterMCode", method = RequestMethod.GET )
  517. @ResponseBody
  518. public Result getRegisterMCode(String mobile){
  519. Result res = new Result();
  520. if (TokenManager.getSession().getAttribute(VerifyCodeUtils.M_CODE_TIME) == null
  521. || TokenManager.getSession().getAttribute(VerifyCodeUtils.M_CODE_TIME) == "") {
  522. sendMessage(mobile, res,VerifyCodeUtils.M_CODE);
  523. } else if (TimeUtils.checkOverTime("getMCode")) {
  524. VerifyCodeUtils.clearMobileCode();
  525. VerifyCodeUtils.clearMobileCodeTime();
  526. sendMessage(mobile, res,VerifyCodeUtils.M_CODE);
  527. } else {
  528. res.getError().add(buildError(ErrorConstants.MCODE_FREQUENCY_ERROR, "", "手机验证码发送频繁!"));
  529. }
  530. return res;
  531. }
  532. @RequestMapping(value = "/getResetMCode", method = RequestMethod.GET )
  533. @ResponseBody
  534. public Result getResetMCode(String mobile) {
  535. Result res = new Result();
  536. if (userService.selectByMobieAndTypeCount(mobile.trim())<1) {
  537. res.getError().add(buildError(ErrorConstants.NON_REGISTER, "", "该用户未注册!"));
  538. return res;
  539. }
  540. if (TokenManager.getSession().getAttribute(VerifyCodeUtils.RESET_CODE_TIME) == null
  541. || TokenManager.getSession().getAttribute(VerifyCodeUtils.RESET_CODE_TIME) == "") {
  542. sendMessage(mobile, res,VerifyCodeUtils.RESET_CODE);
  543. } else if (TimeUtils.checkOverTime("resetCode")) {
  544. VerifyCodeUtils.clearMobileCode();
  545. VerifyCodeUtils.clearMobileCodeTime();
  546. sendMessage(mobile, res,VerifyCodeUtils.RESET_CODE);
  547. } else {
  548. res.getError().add(buildError(ErrorConstants.MCODE_FREQUENCY_ERROR, "", "手机验证码发送频繁!"));
  549. }
  550. return res;
  551. }
  552. /** 省市区查询 **/
  553. @RequestMapping(value = "/listAllProvince" , method = RequestMethod.POST)
  554. @ResponseBody
  555. public Result listAllProvince(){
  556. Result res = new Result();
  557. res.setData(districtGlossoryService.getProvince());
  558. return res;
  559. }
  560. @RequestMapping(value="/industryList", method = RequestMethod.GET)
  561. @ResponseBody
  562. public Result getIndustryList() {
  563. Result result=new Result();
  564. result.setData(userIdentityService.selectIndustryReletively());
  565. return result;
  566. }
  567. @RequestMapping(value="/achievementList", method = RequestMethod.GET)
  568. @ResponseBody
  569. public Result getAchievements(AchievementObject achievementObject,Integer pageNo,Integer pageSize) {
  570. Result result=new Result();
  571. result.setData(achievementService.getAchievementObjects(achievementObject, pageNo, pageSize));
  572. return result;
  573. }
  574. @RequestMapping(value="/demandList", method = RequestMethod.GET)
  575. @ResponseBody
  576. public Result getDemands(DemandListBo demandListBo,Integer pageNo,Integer pageSize) {
  577. Result result=new Result();
  578. result.setData(demandService.getDemandObjects(demandListBo, pageNo, pageSize));
  579. return result;
  580. }
  581. @RequestMapping(value = "/comment/list", method = RequestMethod.GET)
  582. @ResponseBody
  583. public Result listComment(String commodityId,Integer pageNo,Integer pageSize) {
  584. Result result=new Result();
  585. if(StringUtils.isBlank(commodityId)) {
  586. result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"","商品id"));
  587. }
  588. CommentResult commentResult=new CommentResult();
  589. commentResult.setPositiveCommentCount(commentService.getCommentCount(0, commodityId));
  590. commentResult.setOrdinaryCommentCount(commentService.getCommentCount(1, commodityId));
  591. commentResult.setNegativeCommentCount(commentService.getCommentCount(2, commodityId));
  592. commentResult.setComments(commentService.searchComment(commodityId, pageNo, pageSize));
  593. result.setData(commentResult);
  594. return result;
  595. }
  596. /**
  597. * APP重置密码
  598. */
  599. @RequestMapping(value = "/appResetPwd", method = RequestMethod.POST)
  600. @ResponseBody
  601. public Result resetPwd(String resetCode, String username,String mobile, Integer type, String newPwd) {
  602. Result res = new Result();
  603. if (TimeUtils.checkOverTime(VerifyCodeUtils.M_CODE)) {
  604. res.getError().add(buildError(ErrorConstants.RESET_CODE_OVERTIME, "", "页面超时失效,请重新获取验证码!"));
  605. cleanCodeSession();
  606. return res;
  607. }
  608. if(null == TokenManager.getSession().getAttribute(VerifyCodeUtils.RESET_CODE)){
  609. res.getError().add(buildError(ErrorConstants.RESET_CODE_OVERTIME, "", "页面超时失效,请重新获取验证码!"));
  610. cleanCodeSession();
  611. return res;
  612. }else if(!TokenManager.getSession().getAttribute(VerifyCodeUtils.RESET_CODE).equals(resetCode)){
  613. res.getError().add(buildError(ErrorConstants.RESET_CODE_ERROR, "", "验证码错误,请重新获取验证码!"));
  614. cleanCodeSession();
  615. return res;
  616. }
  617. if (StringUtils.isBlank(newPwd)) {
  618. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "新密码"));
  619. return res;
  620. }
  621. if (StringUtils.isBlank(mobile)) {
  622. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "mobile"));
  623. return res;
  624. }
  625. /*if (!UserType.ORGANIZATION.getCode().equals(type) && !UserType.PERSONAL.getCode().equals(type)) {
  626. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "type"));
  627. return res;
  628. }*/
  629. User user = userService.selectByMobieAndType(mobile, type);
  630. if (null == user) {
  631. res.getError().add(buildError( "用户未注册", "用户未注册"));
  632. return res;
  633. }
  634. if (null!=user.getMobile()&&!user.getMobile().equals(mobile)) {
  635. res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "手机号码"));
  636. return res;
  637. }
  638. user.setPassword(newPwd);
  639. user.setPassword(passwordUtil.getEncryptPwd(user));
  640. userService.updateByPrimaryKeySelective(user);
  641. VerifyCodeUtils.clearResetCode();
  642. VerifyCodeUtils.clearResetCodeTime();
  643. return res;
  644. }
  645. /**
  646. * 新增评价
  647. */
  648. @RequestMapping(value = "/addComment", method = RequestMethod.POST)
  649. @ResponseBody
  650. public Result addNewComment(HttpServletRequest request,CommentInput commentInput) {
  651. Result result=new Result();
  652. String ip=UserCommentController.getClientIp(request);
  653. if(StringUtils.isBlank(commentInput.getCommodityId())) {
  654. result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"商品id为空","商品id"));return result;
  655. }
  656. if(null == commentInput.getStar() || commentInput.getStar()<0 || commentInput.getStar()>5) {
  657. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","评分"));return result;
  658. }
  659. if(StringUtils.isBlank(commentInput.getContent()) || commentInput.getContent().length()>512) {
  660. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","内容限制1-512字符"));return result;
  661. }
  662. if(null == commentInput.getCommodityType() || commentInput.getCommodityType()<0 || commentInput.getCommodityType() > 5) {
  663. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","产品类型"));return result;
  664. }
  665. int res=commentService.addNewComment(commentInput,ip);
  666. if(res ==-1) {
  667. result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","提交失败"));return result;
  668. }
  669. result.setData(res);
  670. return result;
  671. }
  672. /**
  673. *
  674. * @param commodityId
  675. * @param pageNo
  676. * @param pageSize
  677. * @return
  678. */
  679. @RequestMapping(value = "unlanded/comment/list", method = RequestMethod.GET)
  680. @ResponseBody
  681. public Result unlandedCommentList(String commodityId,Integer pageNo,Integer pageSize) {
  682. Result result=new Result();
  683. if(StringUtils.isBlank(commodityId)) {
  684. result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"","商品id"));
  685. }
  686. CommentResult commentResult=new CommentResult();
  687. commentResult.setPositiveCommentCount(commentService.getCommentCount(0, commodityId));
  688. commentResult.setOrdinaryCommentCount(commentService.getCommentCount(1, commodityId));
  689. commentResult.setNegativeCommentCount(commentService.getCommentCount(2, commodityId));
  690. commentResult.setComments(commentService.searchUnlandedCommentList(commodityId, pageNo, pageSize));
  691. result.setData(commentResult);
  692. return result;
  693. }
  694. /**
  695. * 服务商项目列表
  696. */
  697. @SuppressWarnings("unchecked")
  698. @RequestMapping(value = "/user/projectList", method = RequestMethod.GET)
  699. @ResponseBody
  700. public Result userProjectList(String uid, Integer pageSize, Integer pageNo) {
  701. Result res = new Result();
  702. Pagination<JtBusinessProjectResult> pagination=jtBusinessService.getProjects(null,null, null, null, pageSize, pageNo, 0, 2, null, null, 0, 0, uid);
  703. List<JtBusinessProjectResult> list=(List<JtBusinessProjectResult>) pagination.getList();
  704. if (list!=null ) {
  705. for (JtBusinessProjectResult j : list) {
  706. if (j!=null&&j.getIntroduce()!=null) {
  707. j.setIntroduce(j.getIntroduce().replaceAll("\\<.*?>", ""));
  708. }
  709. }
  710. }
  711. res.setData(pagination);
  712. return res;
  713. }
  714. @SuppressWarnings("unchecked")
  715. @RequestMapping(value = "/getUserVoucher", method = RequestMethod.GET)
  716. @ResponseBody
  717. public Result getUserVoucher(String uid,Integer pageNo,Integer pageSize){
  718. Result res = new Result();
  719. Pagination<JtVoucherListBo> p=voucherService.selectVoucherList(null,1,1,4,uid, pageNo, pageSize);
  720. List<JtVoucherListBo> vl=(List<JtVoucherListBo>) p.getList();
  721. if (TokenManager.getUserId()==null) return res.data(p);
  722. List<String> l=voucherDetailService.getTokenVoucher();
  723. for (JtVoucherListBo jt : vl) {
  724. for (String s : l) {
  725. if (s.equals(jt.getId())) {
  726. jt.setIsGet(1);
  727. }
  728. }
  729. }
  730. return res.data(p);
  731. }
  732. @RequestMapping(value = "/userGetVoucher", method = RequestMethod.POST)
  733. @ResponseBody
  734. public Result userGetVoucher(String uid,String vid){
  735. Result res = new Result();
  736. if(StringUtils.isBlank(uid)&&TokenManager.getUserId()!=null)uid=TokenManager.getUserId();
  737. if(StringUtils.isBlank(vid)) {
  738. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"","抵用券"));
  739. }
  740. if(StringUtils.isBlank(uid)) {
  741. res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"","领用者"));
  742. }
  743. res.data(voucherDetailService.saveUserGetVoucher(uid,vid));
  744. return res;
  745. }
  746. /**
  747. * 服务商列表
  748. * @param user
  749. * @param pageNo
  750. * @param pageSize
  751. * @return
  752. */
  753. @RequestMapping(value="/organizationList", method = RequestMethod.GET)
  754. @ResponseBody
  755. public Result organizationList(User user, Integer pageNo, Integer pageSize){
  756. Result res = new Result();
  757. res.setData(userService.selectOrganizationList(user, pageNo, pageSize));
  758. return res;
  759. }
  760. @SuppressWarnings("unchecked")
  761. @RequestMapping(value="/invRegister",method = RequestMethod.GET)
  762. @ResponseBody
  763. public Result portalActivityDetails(){
  764. Result res = new Result();
  765. Map<String, Object> map =new HashMap<>();
  766. //获得项目抵用券
  767. List<JtVoucherListBo> vlist=voucherService.selectActivityVoucher();
  768. for (JtVoucherListBo j : vlist) {
  769. if (j!=null&&j.getName().length()>12) {
  770. j.setName(j.getName().substring(0, 11)+"…");
  771. }
  772. }
  773. map.put("vouchers",vlist);
  774. //高企服务
  775. List<JtBusinessProject> glist=jtBusinessService.getKJListByIds(2, 0, 2);
  776. for (JtBusinessProject j : glist) {
  777. if (j.getName().length()>5) {
  778. j.setName(j.getName().substring(0, 4)+"…");
  779. }
  780. }
  781. map.put( "gqfw",glist);
  782. //随机热门项目
  783. Pagination<JtBusinessProjectResult> p=jtBusinessService.getProjects(null,null,null,null, 3,1,null,2,null,1,null,null,null);
  784. List<JtBusinessProjectResult> plist=(List<JtBusinessProjectResult>) p.getList();
  785. for (JtBusinessProjectResult j : plist) {
  786. if (j.getName().length()>8) {
  787. j.setName(j.getName().substring(0, 7)+"…");
  788. }
  789. }
  790. map.put("hotProject",plist);
  791. //军民融合
  792. List<JtBusinessProject> jlist=jtBusinessService.getKJListByIds(3, 0, 3);
  793. for (JtBusinessProject j : jlist) {
  794. if (j.getName().length()>12) {
  795. j.setName(j.getName().substring(0, 11)+"…");
  796. }
  797. }
  798. map.put( "jmrh",jlist);
  799. //知识产权
  800. List<JtBusinessProject> zlist=jtBusinessService.getKJListByIds(1, 0, 3);
  801. for (JtBusinessProject j : zlist) {
  802. if (j.getName().length()>8) {
  803. j.setName(j.getName().substring(0, 7)+"…");
  804. }
  805. }
  806. map.put( "zscq",zlist);
  807. //政府扶持
  808. List<JtBusinessProject> zfList=jtBusinessService.getProjectByTag("政府扶持", 4);
  809. for (JtBusinessProject j : zlist) {
  810. if (j.getName().length()>11) {
  811. j.setName(j.getName().substring(0, 10)+"…");
  812. }
  813. }
  814. map.put( "zffc",zfList);
  815. return res.data(map);
  816. }
  817. @RequestMapping(value = "/getEventPlanningList",method = RequestMethod.GET)
  818. @ResponseBody
  819. public Result getEventPlanningList(InputJtNews inputJtNews){
  820. Result res = new Result();
  821. inputJtNews.setReleaseStatus(1);
  822. Pagination<OutJtNews> p= eventPlanningService.listnewsDetails(inputJtNews);
  823. List<OutJtNews> list = (List<OutJtNews>) p.getList();
  824. for (OutJtNews outJtNews : list) {
  825. outJtNews.setContent(removeHtmlTag(outJtNews.getContent()));
  826. }
  827. res.setData(p);
  828. return res;
  829. }
  830. @RequestMapping(value = "/selectChat",method = RequestMethod.GET)
  831. @ResponseBody
  832. public Result selectChat (String text){
  833. Result res=new Result();
  834. Map<String,Object> params=new HashMap();
  835. List<String> list =new ArrayList<>();
  836. params.put("priors",list);
  837. params.put("text",text);
  838. String str = HttpUtils.httpPostToStr("https://www.sciradar.com/gw/chat/chat/stream", params);
  839. return res.data(str);
  840. }
  841. @RequestMapping(value = "/SelectwebSocket",method = RequestMethod.GET)
  842. @ResponseBody
  843. public Result SelectwebSocket (String text){
  844. Result res=new Result();
  845. Map<String,Object> params=new HashMap();
  846. List<String> list =new ArrayList<>();
  847. params.put("type","text");
  848. params.put("msg",text);
  849. // MyWebSocketClient
  850. return res.data("");
  851. }
  852. /**
  853. * 删除Html标签
  854. */
  855. public static String removeHtmlTag(String htmlStr) {
  856. //定义script的正则表达式{或<script[^>]*?>[\\s\\S]*?<\\/script>
  857. //String regEx_script = "<[\\s]*?script[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?script[\\s]*?>";
  858. //定义style的正则表达式{或<style[^>]*?>[\\s\\S]*?<\\/style>
  859. // String regEx_style = "<[\\s]*?style[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?style[\\s]*?>";
  860. //定义HTML标签的正则表达式
  861. String regEx_html = "<[^>]+>";
  862. //定义一些特殊字符的正则表达式 如:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  863. String regEx_special = "\\&[a-zA-Z]{1,10};";
  864. // //1.过滤script标签
  865. // Pattern p_script = Pattern.compile(regEx_script, Pattern.CASE_INSENSITIVE);
  866. // Matcher m_script = p_script.matcher(htmlStr);
  867. // htmlStr = m_script.replaceAll("");
  868. // //2.过滤style标签
  869. // Pattern p_style = Pattern.compile(regEx_style, Pattern.CASE_INSENSITIVE);
  870. // Matcher m_style = p_style.matcher(htmlStr);
  871. // htmlStr = m_style.replaceAll("");
  872. //3.过滤html标签
  873. Pattern p_html = Pattern.compile(regEx_html, Pattern.CASE_INSENSITIVE);
  874. Matcher m_html = p_html.matcher(htmlStr);
  875. htmlStr = m_html.replaceAll("");
  876. //4.过滤特殊标签
  877. Pattern p_special = Pattern.compile(regEx_special, Pattern.CASE_INSENSITIVE);
  878. Matcher m_special = p_special.matcher(htmlStr);
  879. htmlStr = m_special.replaceAll("");
  880. return htmlStr;
  881. }
  882. }