PublicController.java 31 KB

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