| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964 |
- package com.goafanti.common.controller;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.util.*;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- import javax.annotation.Resource;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import com.alibaba.fastjson.JSONObject;
- import com.goafanti.common.model.JtNews;
- import com.goafanti.common.utils.*;
- import com.goafanti.news.bo.InputJtNews;
- import com.goafanti.news.bo.OutJtNews;
- import com.goafanti.news.service.EventPlanningService;
- import org.apache.commons.lang3.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.context.annotation.Scope;
- import org.springframework.stereotype.Controller;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.ResponseBody;
- import com.goafanti.achievement.service.AchievementService;
- import com.goafanti.business.bo.JtBusinessProjectResult;
- import com.goafanti.business.service.JtBusinessService;
- import com.goafanti.comment.bo.CommentInput;
- import com.goafanti.comment.bo.CommentResult;
- import com.goafanti.comment.controller.UserCommentController;
- import com.goafanti.comment.service.CommentService;
- import com.goafanti.common.bo.Result;
- import com.goafanti.common.constant.ErrorConstants;
- import com.goafanti.common.enums.UserType;
- import com.goafanti.common.model.JtBusinessProject;
- import com.goafanti.common.model.User;
- import com.goafanti.common.service.DistrictGlossoryService;
- import com.goafanti.common.service.FieldGlossoryService;
- import com.goafanti.common.service.IndustryCategoryService;
- import com.goafanti.core.mybatis.JDBCIdGenerator;
- import com.goafanti.core.mybatis.page.Pagination;
- import com.goafanti.core.shiro.token.TokenManager;
- import com.goafanti.demand.bo.DemandListBo;
- import com.goafanti.demand.service.DemandService;
- import com.goafanti.portal.bo.AchievementObject;
- import com.goafanti.user.service.UserIdentityService;
- import com.goafanti.user.service.UserService;
- import com.goafanti.voucher.bo.JtVoucherListBo;
- import com.goafanti.voucher.service.VoucherDetailService;
- import com.goafanti.voucher.service.VoucherService;
- @Controller
- @Scope(value = "prototype")
- @RequestMapping("/open")
- public class PublicController extends BaseController {
- @Value(value = "${accessKey}")
- private String accessKey = null;
- @Value(value = "${accessSecret}")
- private String accessSecret = null;
- @Value(value = "${upload.path}")
- private String uploadPath = null;
- @Value(value = "${upload.private.path}")
- private String uploadPrivatePath = null;
- @Value(value = "${static.host}")
- private String staticHost = null;
- @Value(value = "${mobileCodeTemplate}")
- private String mobileCodeTemplate = null;
- @Resource
- private UserService userService;
- @Resource
- private FieldGlossoryService fieldGlossoryService;
- @Resource
- private CommentService commentService;
- @Autowired
- private IndustryCategoryService industryCategoryService;
- @Autowired
- private DistrictGlossoryService districtGlossoryService;
- @Autowired
- private UserIdentityService userIdentityService;
- @Autowired
- private AchievementService achievementService;
- @Autowired
- private DemandService demandService;
- @Autowired
- private JtBusinessService jtBusinessService;
- @Value(value = "${patentTemplate}")
- private String patentTemplate = null;
- @Resource(name = "passwordUtil")
- private PasswordUtil passwordUtil;
- @Resource
- private VoucherDetailService voucherDetailService;
- @Resource
- private VoucherService voucherService;
- @Resource
- private EventPlanningService eventPlanningService;
- /**
- * 获取验证码
- *
- * @param response
- */
- @RequestMapping(value = "/getVCode", method = RequestMethod.GET)
- public void getVCode(HttpServletResponse response, HttpServletRequest request) {
- try {
- response.setHeader("Pragma", "No-cache");
- response.setHeader("Cache-Control", "no-cache");
- response.setDateHeader("Expires", 0);
- response.setContentType("image/jpg");
- // 生成随机字串
- String verifyCode = VerifyCodeUtils.generateVerifyCode(4);
- // 存入Shiro会话session
- TokenManager.setVal2Session(VerifyCodeUtils.V_CODE, verifyCode.toLowerCase());
- // 生成图片
- int w = 146, h = 33;
- VerifyCodeUtils.outputImage(w, h, response.getOutputStream(), verifyCode);
- } catch (Exception e) {
- LoggerUtils.fmtError(getClass(), e, "获取验证码异常:%s", e.getMessage());
- }
- }
- /**
- * 手机验证码
- *
- * @param mobile
- * @param sign
- * 是否用与找回密码
- * @return
- */
- @RequestMapping(value = "/getMCode", method = RequestMethod.GET)
- @ResponseBody
- public Result getMcode(String mobile, boolean sign, String verificationCode) {
- Result res = new Result();
- // 用于找回密码
- if (sign) {
- if (null == userService.selectByMobieAndType(mobile.trim(),null)) {
- res.getError().add(buildError(ErrorConstants.NON_REGISTER, "", "该用户未注册!"));
- return res;
- }
- }
- /*if (!sign) {
- if (StringUtils.isBlank(verificationCode)) {
- res.getError().add(buildError(ErrorConstants.VCODE_EMPTY_ERROR, "", "图像验证码不能为空!"));
- return res;
- }
- if (!VerifyCodeUtils.verifyCode(verificationCode)) {
- res.getError().add(buildError(ErrorConstants.VCODE_ERROR, "", "图形验证码输入错误!"));
- return res;
- }
- }
- */
- if (TokenManager.getSession().getAttribute(VerifyCodeUtils.M_CODE_TIME) == null
- || TokenManager.getSession().getAttribute(VerifyCodeUtils.M_CODE_TIME) == "") {
- sendMessage(mobile, res,VerifyCodeUtils.M_CODE);
- } else if (TimeUtils.checkOverTime("getMCode")) {
- VerifyCodeUtils.clearMobileCode();
- VerifyCodeUtils.clearMobileCodeTime();
- sendMessage(mobile, res,VerifyCodeUtils.M_CODE);
- } else {
- res.getError().add(buildError(ErrorConstants.MCODE_FREQUENCY_ERROR, "", "手机验证码发送频繁!"));
- }
- return res;
- }
- /**
- *
- * @param mobile
- * @param res
- * @return
- */
- private Result sendMessage(String mobile, Result res,String codeType) {
- String mobileVerifyCode = VerifyCodeUtils.generateMobileVerifyCode(6); // 生成随机字串
- if(VerifyCodeUtils.M_CODE.equals(codeType)){
- TokenManager.setVal2Session(VerifyCodeUtils.M_CODE, mobileVerifyCode);// 存入Shiro会话session
- TokenManager.setVal2Session(VerifyCodeUtils.M_CODE_TIME, System.currentTimeMillis());
- }else if(VerifyCodeUtils.RESET_CODE.equals(codeType)){
- TokenManager.setVal2Session(VerifyCodeUtils.RESET_CODE, mobileVerifyCode);// 存入Shiro会话session
- TokenManager.setVal2Session(VerifyCodeUtils.RESET_CODE_TIME, System.currentTimeMillis());
- }
- String paramString = "{\"code\":\"" + mobileVerifyCode + "\",\"product\":\"技淘网\"}";
- String ret = MobileMessageUtils.sendMessage(mobileCodeTemplate, paramString, mobile, accessKey, accessSecret);
- if (StringUtils.isNotBlank(ret)) {
- res.getError().add(buildError(ErrorConstants.M_CODE_ERROR));
- }
- return res;
- }
- /**
- * 下载图片
- *
- * @param response
- * @param path
- * @param request
- */
- @RequestMapping(value = "/downLoadPicture", method = RequestMethod.GET)
- public Result downLoadPicture(HttpServletResponse response, String path, HttpServletRequest request) {
- Result res = new Result();
- if (StringUtils.isBlank(path)) {
- res.getError().add(buildError(ErrorConstants.FILE_NON_EXISTENT));
- return res;
- }
- String filename = Long.toString(System.nanoTime()) + ".jpg";
- InputStream in = null;
- OutputStream out = null;
- byte[] buffer = new byte[8 * 1024];
- String fileSaveRootPath = "";
- try {
- fileSaveRootPath = uploadPrivatePath + path;
- File file = new File(fileSaveRootPath);
- in = new FileInputStream(file);
- out = response.getOutputStream();
- // 设置文件MIME类型
- response.setContentType("application/octet-stream");
- response.setHeader("Content-Disposition", "attachment; filename=" + filename);
- for (;;) {
- int bytes = in.read(buffer);
- if (bytes == -1) {
- break;
- }
- out.write(buffer, 0, bytes);
- }
- } catch (IOException e) {
- LoggerUtils.fmtError(getClass(), e, "IO错误:%s", e.getMessage());
- } finally {
- try {
- if (null != in) {
- in.close();
- }
- } catch (IOException e) {
- LoggerUtils.fmtError(getClass(), e, "IO错误:%s", e.getMessage());
- }
- try {
- if (null != out) {
- out.close();
- }
- } catch (IOException e) {
- LoggerUtils.fmtError(getClass(), e, "IO错误:%s", e.getMessage());
- }
- }
- return res;
- }
- /**
- * 删除图片文件(public图片)
- *
- * @param path
- * @return
- */
- @RequestMapping(value = "/deleteUploadPicture", method = RequestMethod.POST)
- public boolean deleteUploadPicture(String path) {
- boolean flag = false;
- path = uploadPath + path;
- File file = new File(path);
- // 判断目录或文件是否存在
- if (!file.exists() || !file.isFile()) { // 不存在返回 false
- return flag;
- } else {
- return file.delete();
- }
- }
- /**
- * 获取并输出private图片
- */
- @RequestMapping(value = "/writeImage", method = RequestMethod.GET)
- public void writeImage(HttpServletResponse response, HttpServletRequest request, String path) {
- try {
- String realPath = uploadPrivatePath + path;
- PictureUtils.outputImage(response, realPath);
- } catch (IOException e) {
- LoggerUtils.fmtError(getClass(), e, "获取图片异常:%s", e.getMessage());
- }
- }
- /**
- * 下载文件
- *
- * @param fileName
- * @param response
- * @param path
- * @return
- */
- @RequestMapping(value = "/downloadFile", method = RequestMethod.GET)
- public Result downloadFile(String fileName, HttpServletResponse response, String path) {
- Result res = new Result();
- return handleDownloadFile(response, fileName, path, res);
- }
- private Result handleDownloadFile(HttpServletResponse response, String fileName, String path, Result res) {
- String fileSaveRootPath = uploadPrivatePath + path;
- InputStream in = null;
- OutputStream out = null;
- byte[] buffer = new byte[8 * 1024];
- try {
- File file = new File(fileSaveRootPath);
- in = new FileInputStream(file);
- out = response.getOutputStream();
- response.setContentType("multipart/form-data");
- fileName = java.net.URLEncoder.encode(fileName, "UTF-8");
- response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
- for (;;) {
- int bytes = in.read(buffer);
- if (bytes == -1) {
- break;
- }
- out.write(buffer, 0, bytes);
- }
- } catch (IOException e) {
- LoggerUtils.fmtError(getClass(), e, "IO错误:%s", e.getMessage());
- } finally {
- try {
- in.close();
- } catch (IOException e) {
- LoggerUtils.fmtError(getClass(), e, "IO错误:%s", e.getMessage());
- }
- try {
- out.close();
- } catch (IOException e) {
- LoggerUtils.fmtError(getClass(), e, "IO错误:%s", e.getMessage());
- }
- }
- return res;
- }
- @RequestMapping(value = "/findIndustryCategory", method = RequestMethod.GET)
- @ResponseBody
- public Result findIndustryCategory(String id, String noCache) {
- Integer pid = 0;
- if (StringUtils.isNumeric(id)) {
- try {
- pid = Integer.parseInt(id);
- } catch (Exception e) {
- pid = 0;
- }
- }
- if (StringUtils.isNotBlank(noCache)) {
- industryCategoryService.clear(pid);
- }
- return new Result().data(industryCategoryService.list(pid));
- }
- @RequestMapping(value = "/findDistrict", method = RequestMethod.GET)
- @ResponseBody
- public Result findDistrictGlossory(String id, String noCache) {
- Integer pid = 0;
- if (StringUtils.isNumeric(id)) {
- try {
- pid = Integer.parseInt(id);
- } catch (Exception e) {
- pid = 0;
- }
- }
- if (StringUtils.isNotBlank(noCache)) {
- districtGlossoryService.clear(pid);
- }
- return new Result().data(districtGlossoryService.list(pid));
- }
- /**
- *
- * @param mobileCode
- * @return
- */
- @RequestMapping(value = "/checkMCode", method = RequestMethod.POST)
- @ResponseBody
- public Result checkMCode(String mobileCode) {
- Result res = new Result();
- if (StringUtils.isBlank(mobileCode)) {
- res.getError().add(buildError(ErrorConstants.MCODE_EMPTY_ERROR, "", "手机验证码"));
- return res;
- }
- if (TimeUtils.checkOverTime(VerifyCodeUtils.M_CODE)) {
- res.getError().add(buildError(ErrorConstants.MCODE_OVERTIME_ERROR, "", "手机验证码超时失效!"));
- VerifyCodeUtils.clearMobileCode();
- VerifyCodeUtils.clearMobileCodeTime();
- return res;
- }
- if (!TokenManager.getSession().getAttribute(VerifyCodeUtils.M_CODE).equals(mobileCode)) {
- res.getError().add(buildError(ErrorConstants.MCODE_ERROR, "", "手机验证码错误"));
- return res;
- }
- // resetCode
- if (res.getError().isEmpty()) {
- String resetCode = UUID.randomUUID().toString();
- TokenManager.setVal2Session(VerifyCodeUtils.RESET_CODE, resetCode);
- TokenManager.setVal2Session(VerifyCodeUtils.RESET_CODE_TIME, System.currentTimeMillis());
- res.setData(resetCode);
- }
- return res;
- }
- /**
- * 重置密码
- *
- * @param resetCode
- * @param mobile
- * @param type
- * @param newPwd
- * @return
- */
- @RequestMapping(value = "/resetPwd", method = RequestMethod.POST)
- @ResponseBody
- public Result resetPwd(String resetCode, String mobile, Integer type, String newPwd) {
- Result res = new Result();
- if (TimeUtils.checkOverTime(VerifyCodeUtils.M_CODE)) {
- res.getError().add(buildError(ErrorConstants.RESET_CODE_OVERTIME, "", "页面超时失效,请重新获取验证码!"));
- cleanCodeSession();
- return res;
- }
- if(null == TokenManager.getSession().getAttribute(VerifyCodeUtils.RESET_CODE)){
- res.getError().add(buildError(ErrorConstants.RESET_CODE_OVERTIME, "", "页面超时失效,请重新获取验证码!"));
- cleanCodeSession();
- return res;
- }else if(!TokenManager.getSession().getAttribute(VerifyCodeUtils.RESET_CODE).equals(resetCode)){
- res.getError().add(buildError(ErrorConstants.RESET_CODE_ERROR, "", "验证码错误,请重新获取验证码!"));
- cleanCodeSession();
- return res;
- }
- if (StringUtils.isBlank(newPwd)) {
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "新密码"));
- return res;
- }
- if (StringUtils.isBlank(mobile)) {
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "mobile"));
- return res;
- }
- if (!UserType.ORGANIZATION.getCode().equals(type) && !UserType.PERSONAL.getCode().equals(type)) {
- res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "type"));
- return res;
- }
- User user = userService.selectByMobieAndType(mobile, type);
- if (null == user) {
- res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "mobile"));
- return res;
- }
- user.setPassword(newPwd);
- user.setPassword(passwordUtil.getEncryptPwd(user));
- userService.updateByPrimaryKeySelective(user);
- VerifyCodeUtils.clearResetCode();
- VerifyCodeUtils.clearResetCodeTime();
- return res;
- }
- @RequestMapping(value = "/resetPassword", method = RequestMethod.POST)
- @ResponseBody
- public Result resetPassword(String mobile,Integer type,String newPwd,String resetCode) {
- Result res=new Result();
- if (TimeUtils.checkOverTime(VerifyCodeUtils.M_CODE)) {
- res.getError().add(buildError(ErrorConstants.RESET_CODE_OVERTIME, "", "页面超时失效,请重新获取验证码!"));
- cleanCodeSession();
- return res;
- }
- if(null == TokenManager.getSession().getAttribute(VerifyCodeUtils.RESET_CODE)){
- res.getError().add(buildError(ErrorConstants.RESET_CODE_OVERTIME, "", "页面超时失效,请重新获取验证码!"));
- cleanCodeSession();
- return res;
- }else if(!TokenManager.getSession().getAttribute(VerifyCodeUtils.RESET_CODE).equals(resetCode)){
- res.getError().add(buildError(ErrorConstants.RESET_CODE_ERROR, "", "验证码错误,请重新获取验证码!"));
- cleanCodeSession();
- return res;
- }
- if (StringUtils.isBlank(newPwd)) {
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "新密码"));
- return res;
- }
- if (StringUtils.isBlank(mobile)) {
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "用户名"));
- return res;
- }
- User user=userService.selectByMobieAndType(mobile, type);
- if(user==null || user.getMobile()==null || !user.getMobile().equals(mobile))
- {
- res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "手机号或用户名错误"));
- return res;
- }
- user.setPassword(newPwd);
- user.setPassword(passwordUtil.getEncryptPwd(user));
- userService.updateByPrimaryKeySelective(user);
- return res;
- }
- /**
- *
- * @param mobileCode
- * @return
- */
- @RequestMapping(value = "/checkMNCode", method = RequestMethod.POST)
- @ResponseBody
- public Result checkMNCode(String mobileCode,Integer type,String mobile) {
- Result res = new Result();
- if (StringUtils.isBlank(mobileCode)) {
- res.getError().add(buildError(ErrorConstants.MCODE_EMPTY_ERROR, "", "手机验证码"));
- return res;
- }
- if (StringUtils.isBlank(mobile)) {
- res.getError().add(buildError(ErrorConstants.MCODE_EMPTY_ERROR, "", "手机号"));
- return res;
- }
- if (TimeUtils.checkOverTime(VerifyCodeUtils.M_CODE)) {
- res.getError().add(buildError(ErrorConstants.MCODE_OVERTIME_ERROR, "", "手机验证码超时失效!"));
- VerifyCodeUtils.clearMobileCode();
- VerifyCodeUtils.clearMobileCodeTime();
- return res;
- }
- if (!TokenManager.getSession().getAttribute(VerifyCodeUtils.M_CODE).equals(mobileCode)) {
- res.getError().add(buildError(ErrorConstants.MCODE_ERROR, "", "手机验证码错误"));
- return res;
- }
- User user=userService.selectByMobieAndType(mobile, type);
- if(user==null || user.getMobile()==null || !user.getMobile().equals(mobile))
- {
- res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "手机号或用户名错误"));
- return res;
- }
- // resetCode
- if (res.getError().isEmpty()) {
- String resetCode = UUID.randomUUID().toString();
- TokenManager.setVal2Session(VerifyCodeUtils.RESET_CODE, resetCode);
- TokenManager.setVal2Session(VerifyCodeUtils.RESET_CODE_TIME, System.currentTimeMillis());
- res.setData(resetCode);
- }
- return res;
- }
- private void cleanCodeSession() {
- VerifyCodeUtils.clearResetCode();
- VerifyCodeUtils.clearResetCodeTime();
- VerifyCodeUtils.clearMobileCode();
- VerifyCodeUtils.clearMobileCodeTime();
- }
- @RequestMapping(value = "/getRegisterMCode", method = RequestMethod.GET )
- @ResponseBody
- public Result getRegisterMCode(String mobile){
- Result res = new Result();
- if (TokenManager.getSession().getAttribute(VerifyCodeUtils.M_CODE_TIME) == null
- || TokenManager.getSession().getAttribute(VerifyCodeUtils.M_CODE_TIME) == "") {
- sendMessage(mobile, res,VerifyCodeUtils.M_CODE);
- } else if (TimeUtils.checkOverTime("getMCode")) {
- VerifyCodeUtils.clearMobileCode();
- VerifyCodeUtils.clearMobileCodeTime();
- sendMessage(mobile, res,VerifyCodeUtils.M_CODE);
- } else {
- res.getError().add(buildError(ErrorConstants.MCODE_FREQUENCY_ERROR, "", "手机验证码发送频繁!"));
- }
- return res;
- }
- @RequestMapping(value = "/getResetMCode", method = RequestMethod.GET )
- @ResponseBody
- public Result getResetMCode(String mobile) {
- Result res = new Result();
- if (userService.selectByMobieAndTypeCount(mobile.trim())<1) {
- res.getError().add(buildError(ErrorConstants.NON_REGISTER, "", "该用户未注册!"));
- return res;
- }
- if (TokenManager.getSession().getAttribute(VerifyCodeUtils.RESET_CODE_TIME) == null
- || TokenManager.getSession().getAttribute(VerifyCodeUtils.RESET_CODE_TIME) == "") {
- sendMessage(mobile, res,VerifyCodeUtils.RESET_CODE);
- } else if (TimeUtils.checkOverTime("resetCode")) {
- VerifyCodeUtils.clearMobileCode();
- VerifyCodeUtils.clearMobileCodeTime();
- sendMessage(mobile, res,VerifyCodeUtils.RESET_CODE);
- } else {
- res.getError().add(buildError(ErrorConstants.MCODE_FREQUENCY_ERROR, "", "手机验证码发送频繁!"));
- }
- return res;
- }
- /** 省市区查询 **/
- @RequestMapping(value = "/listAllProvince" , method = RequestMethod.POST)
- @ResponseBody
- public Result listAllProvince(){
- Result res = new Result();
- res.setData(districtGlossoryService.getProvince());
- return res;
- }
- @RequestMapping(value="/industryList", method = RequestMethod.GET)
- @ResponseBody
- public Result getIndustryList() {
- Result result=new Result();
- result.setData(userIdentityService.selectIndustryReletively());
- return result;
- }
- @RequestMapping(value="/achievementList", method = RequestMethod.GET)
- @ResponseBody
- public Result getAchievements(AchievementObject achievementObject,Integer pageNo,Integer pageSize) {
- Result result=new Result();
- result.setData(achievementService.getAchievementObjects(achievementObject, pageNo, pageSize));
- return result;
- }
- @RequestMapping(value="/demandList", method = RequestMethod.GET)
- @ResponseBody
- public Result getDemands(DemandListBo demandListBo,Integer pageNo,Integer pageSize) {
- Result result=new Result();
- result.setData(demandService.getDemandObjects(demandListBo, pageNo, pageSize));
- return result;
- }
- @RequestMapping(value = "/comment/list", method = RequestMethod.GET)
- @ResponseBody
- public Result listComment(String commodityId,Integer pageNo,Integer pageSize) {
- Result result=new Result();
- if(StringUtils.isBlank(commodityId)) {
- result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"","商品id"));
- }
- CommentResult commentResult=new CommentResult();
- commentResult.setPositiveCommentCount(commentService.getCommentCount(0, commodityId));
- commentResult.setOrdinaryCommentCount(commentService.getCommentCount(1, commodityId));
- commentResult.setNegativeCommentCount(commentService.getCommentCount(2, commodityId));
- commentResult.setComments(commentService.searchComment(commodityId, pageNo, pageSize));
- result.setData(commentResult);
- return result;
- }
- /**
- * APP重置密码
- */
- @RequestMapping(value = "/appResetPwd", method = RequestMethod.POST)
- @ResponseBody
- public Result resetPwd(String resetCode, String username,String mobile, Integer type, String newPwd) {
- Result res = new Result();
- if (TimeUtils.checkOverTime(VerifyCodeUtils.M_CODE)) {
- res.getError().add(buildError(ErrorConstants.RESET_CODE_OVERTIME, "", "页面超时失效,请重新获取验证码!"));
- cleanCodeSession();
- return res;
- }
- if(null == TokenManager.getSession().getAttribute(VerifyCodeUtils.RESET_CODE)){
- res.getError().add(buildError(ErrorConstants.RESET_CODE_OVERTIME, "", "页面超时失效,请重新获取验证码!"));
- cleanCodeSession();
- return res;
- }else if(!TokenManager.getSession().getAttribute(VerifyCodeUtils.RESET_CODE).equals(resetCode)){
- res.getError().add(buildError(ErrorConstants.RESET_CODE_ERROR, "", "验证码错误,请重新获取验证码!"));
- cleanCodeSession();
- return res;
- }
- if (StringUtils.isBlank(newPwd)) {
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "新密码"));
- return res;
- }
- if (StringUtils.isBlank(mobile)) {
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR, "", "mobile"));
- return res;
- }
- /*if (!UserType.ORGANIZATION.getCode().equals(type) && !UserType.PERSONAL.getCode().equals(type)) {
- res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "type"));
- return res;
- }*/
- User user = userService.selectByMobieAndType(mobile, type);
- if (null == user) {
- res.getError().add(buildError( "用户未注册", "用户未注册"));
- return res;
- }
- if (null!=user.getMobile()&&!user.getMobile().equals(mobile)) {
- res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", "手机号码"));
- return res;
- }
- user.setPassword(newPwd);
- user.setPassword(passwordUtil.getEncryptPwd(user));
- userService.updateByPrimaryKeySelective(user);
- VerifyCodeUtils.clearResetCode();
- VerifyCodeUtils.clearResetCodeTime();
- return res;
- }
- /**
- * 新增评价
- */
- @RequestMapping(value = "/addComment", method = RequestMethod.POST)
- @ResponseBody
- public Result addNewComment(HttpServletRequest request,CommentInput commentInput) {
- Result result=new Result();
- String ip=UserCommentController.getClientIp(request);
- if(StringUtils.isBlank(commentInput.getCommodityId())) {
- result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"商品id为空","商品id"));return result;
- }
- if(null == commentInput.getStar() || commentInput.getStar()<0 || commentInput.getStar()>5) {
- result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","评分"));return result;
- }
- if(StringUtils.isBlank(commentInput.getContent()) || commentInput.getContent().length()>512) {
- result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","内容限制1-512字符"));return result;
- }
- if(null == commentInput.getCommodityType() || commentInput.getCommodityType()<0 || commentInput.getCommodityType() > 5) {
- result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","产品类型"));return result;
- }
- int res=commentService.addNewComment(commentInput,ip);
- if(res ==-1) {
- result.getError().add(buildError(ErrorConstants.PARAM_ERROR,"","提交失败"));return result;
- }
- result.setData(res);
- return result;
- }
- /**
- *
- * @param commodityId
- * @param pageNo
- * @param pageSize
- * @return
- */
- @RequestMapping(value = "unlanded/comment/list", method = RequestMethod.GET)
- @ResponseBody
- public Result unlandedCommentList(String commodityId,Integer pageNo,Integer pageSize) {
- Result result=new Result();
- if(StringUtils.isBlank(commodityId)) {
- result.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"","商品id"));
- }
- CommentResult commentResult=new CommentResult();
- commentResult.setPositiveCommentCount(commentService.getCommentCount(0, commodityId));
- commentResult.setOrdinaryCommentCount(commentService.getCommentCount(1, commodityId));
- commentResult.setNegativeCommentCount(commentService.getCommentCount(2, commodityId));
- commentResult.setComments(commentService.searchUnlandedCommentList(commodityId, pageNo, pageSize));
- result.setData(commentResult);
- return result;
- }
- /**
- * 服务商项目列表
- */
- @SuppressWarnings("unchecked")
- @RequestMapping(value = "/user/projectList", method = RequestMethod.GET)
- @ResponseBody
- public Result userProjectList(String uid, Integer pageSize, Integer pageNo) {
- Result res = new Result();
- Pagination<JtBusinessProjectResult> pagination=jtBusinessService.getProjects(null,null, null, null, pageSize, pageNo, 0, 2, null, null, 0, 0, uid);
- List<JtBusinessProjectResult> list=(List<JtBusinessProjectResult>) pagination.getList();
- if (list!=null ) {
- for (JtBusinessProjectResult j : list) {
- if (j!=null&&j.getIntroduce()!=null) {
- j.setIntroduce(j.getIntroduce().replaceAll("\\<.*?>", ""));
- }
- }
- }
- res.setData(pagination);
- return res;
- }
- @SuppressWarnings("unchecked")
- @RequestMapping(value = "/getUserVoucher", method = RequestMethod.GET)
- @ResponseBody
- public Result getUserVoucher(String uid,Integer pageNo,Integer pageSize){
- Result res = new Result();
- Pagination<JtVoucherListBo> p=voucherService.selectVoucherList(null,1,1,4,uid, pageNo, pageSize);
- List<JtVoucherListBo> vl=(List<JtVoucherListBo>) p.getList();
- if (TokenManager.getUserId()==null) return res.data(p);
- List<String> l=voucherDetailService.getTokenVoucher();
- for (JtVoucherListBo jt : vl) {
- for (String s : l) {
- if (s.equals(jt.getId())) {
- jt.setIsGet(1);
- }
- }
- }
- return res.data(p);
- }
- @RequestMapping(value = "/userGetVoucher", method = RequestMethod.POST)
- @ResponseBody
- public Result userGetVoucher(String uid,String vid){
- Result res = new Result();
- if(StringUtils.isBlank(uid)&&TokenManager.getUserId()!=null)uid=TokenManager.getUserId();
- if(StringUtils.isBlank(vid)) {
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"","抵用券"));
- }
- if(StringUtils.isBlank(uid)) {
- res.getError().add(buildError(ErrorConstants.PARAM_EMPTY_ERROR,"","领用者"));
- }
- res.data(voucherDetailService.saveUserGetVoucher(uid,vid));
- return res;
- }
- /**
- * 服务商列表
- * @param user
- * @param pageNo
- * @param pageSize
- * @return
- */
- @RequestMapping(value="/organizationList", method = RequestMethod.GET)
- @ResponseBody
- public Result organizationList(User user, Integer pageNo, Integer pageSize){
- Result res = new Result();
- res.setData(userService.selectOrganizationList(user, pageNo, pageSize));
- return res;
- }
- @SuppressWarnings("unchecked")
- @RequestMapping(value="/invRegister",method = RequestMethod.GET)
- @ResponseBody
- public Result portalActivityDetails(){
- Result res = new Result();
- Map<String, Object> map =new HashMap<>();
- //获得项目抵用券
- List<JtVoucherListBo> vlist=voucherService.selectActivityVoucher();
- for (JtVoucherListBo j : vlist) {
- if (j!=null&&j.getName().length()>12) {
- j.setName(j.getName().substring(0, 11)+"…");
- }
- }
- map.put("vouchers",vlist);
- //高企服务
- List<JtBusinessProject> glist=jtBusinessService.getKJListByIds(2, 0, 2);
- for (JtBusinessProject j : glist) {
- if (j.getName().length()>5) {
- j.setName(j.getName().substring(0, 4)+"…");
- }
- }
- map.put( "gqfw",glist);
- //随机热门项目
- Pagination<JtBusinessProjectResult> p=jtBusinessService.getProjects(null,null,null,null, 3,1,null,2,null,1,null,null,null);
- List<JtBusinessProjectResult> plist=(List<JtBusinessProjectResult>) p.getList();
- for (JtBusinessProjectResult j : plist) {
- if (j.getName().length()>8) {
- j.setName(j.getName().substring(0, 7)+"…");
- }
- }
- map.put("hotProject",plist);
- //军民融合
- List<JtBusinessProject> jlist=jtBusinessService.getKJListByIds(3, 0, 3);
- for (JtBusinessProject j : jlist) {
- if (j.getName().length()>12) {
- j.setName(j.getName().substring(0, 11)+"…");
- }
- }
- map.put( "jmrh",jlist);
- //知识产权
- List<JtBusinessProject> zlist=jtBusinessService.getKJListByIds(1, 0, 3);
- for (JtBusinessProject j : zlist) {
- if (j.getName().length()>8) {
- j.setName(j.getName().substring(0, 7)+"…");
- }
- }
- map.put( "zscq",zlist);
- //政府扶持
- List<JtBusinessProject> zfList=jtBusinessService.getProjectByTag("政府扶持", 4);
- for (JtBusinessProject j : zlist) {
- if (j.getName().length()>11) {
- j.setName(j.getName().substring(0, 10)+"…");
- }
- }
- map.put( "zffc",zfList);
- return res.data(map);
- }
- @RequestMapping(value = "/getEventPlanningList",method = RequestMethod.GET)
- @ResponseBody
- public Result getEventPlanningList(InputJtNews inputJtNews){
- Result res = new Result();
- inputJtNews.setReleaseStatus(1);
- Pagination<OutJtNews> p= eventPlanningService.listnewsDetails(inputJtNews);
- List<OutJtNews> list = (List<OutJtNews>) p.getList();
- for (OutJtNews outJtNews : list) {
- outJtNews.setContent(removeHtmlTag(outJtNews.getContent()));
- }
- res.setData(p);
- return res;
- }
- @RequestMapping(value = "/selectChat",method = RequestMethod.GET)
- @ResponseBody
- public Result selectChat (String text){
- Result res=new Result();
- Map<String,Object> params=new HashMap();
- List<String> list =new ArrayList<>();
- params.put("priors",list);
- params.put("text",text);
- String str = HttpUtils.httpPostToStr("https://www.sciradar.com/gw/chat/chat/stream", params);
- return res.data(str);
- }
- @RequestMapping(value = "/SelectwebSocket",method = RequestMethod.GET)
- @ResponseBody
- public Result SelectwebSocket (String text){
- Result res=new Result();
- Map<String,Object> params=new HashMap();
- List<String> list =new ArrayList<>();
- params.put("type","text");
- params.put("msg",text);
- // MyWebSocketClient
- return res.data("");
- }
- /**
- * 删除Html标签
- */
- public static String removeHtmlTag(String htmlStr) {
- //定义script的正则表达式{或<script[^>]*?>[\\s\\S]*?<\\/script>
- //String regEx_script = "<[\\s]*?script[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?script[\\s]*?>";
- //定义style的正则表达式{或<style[^>]*?>[\\s\\S]*?<\\/style>
- // String regEx_style = "<[\\s]*?style[^>]*?>[\\s\\S]*?<[\\s]*?\\/[\\s]*?style[\\s]*?>";
- //定义HTML标签的正则表达式
- String regEx_html = "<[^>]+>";
- //定义一些特殊字符的正则表达式 如:
- String regEx_special = "\\&[a-zA-Z]{1,10};";
- // //1.过滤script标签
- // Pattern p_script = Pattern.compile(regEx_script, Pattern.CASE_INSENSITIVE);
- // Matcher m_script = p_script.matcher(htmlStr);
- // htmlStr = m_script.replaceAll("");
- // //2.过滤style标签
- // Pattern p_style = Pattern.compile(regEx_style, Pattern.CASE_INSENSITIVE);
- // Matcher m_style = p_style.matcher(htmlStr);
- // htmlStr = m_style.replaceAll("");
- //3.过滤html标签
- Pattern p_html = Pattern.compile(regEx_html, Pattern.CASE_INSENSITIVE);
- Matcher m_html = p_html.matcher(htmlStr);
- htmlStr = m_html.replaceAll("");
- //4.过滤特殊标签
- Pattern p_special = Pattern.compile(regEx_special, Pattern.CASE_INSENSITIVE);
- Matcher m_special = p_special.matcher(htmlStr);
- htmlStr = m_special.replaceAll("");
- return htmlStr;
- }
- }
|