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