...
This commit is contained in:
parent
8c18204ccd
commit
f87e887680
@ -5,7 +5,7 @@ import org.springframework.boot.SpringApplication;
|
|||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@MapperScan("com.szxgl.vote2021.mapper")
|
@MapperScan("com.szxgl.pars2021.mapper")
|
||||||
public class H52021Application {
|
public class H52021Application {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|||||||
31
src/main/java/com/szxgl/pars2021/config/CorsConfig.java
Normal file
31
src/main/java/com/szxgl/pars2021/config/CorsConfig.java
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
package com.szxgl.pars2021.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.cors.CorsConfiguration;
|
||||||
|
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||||
|
import org.springframework.web.filter.CorsFilter;
|
||||||
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class CorsConfig implements WebMvcConfigurer {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public CorsFilter corsFilter() {
|
||||||
|
CorsConfiguration corsConfiguration = new CorsConfiguration();
|
||||||
|
//1,允许任何来源
|
||||||
|
corsConfiguration.setAllowedOriginPatterns(Collections.singletonList("*"));
|
||||||
|
//2,允许任何请求头
|
||||||
|
corsConfiguration.addAllowedHeader(CorsConfiguration.ALL);
|
||||||
|
//3,允许任何方法
|
||||||
|
corsConfiguration.addAllowedMethod(CorsConfiguration.ALL);
|
||||||
|
//4,允许凭证
|
||||||
|
corsConfiguration.setAllowCredentials(true);
|
||||||
|
|
||||||
|
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||||
|
source.registerCorsConfiguration("/**", corsConfiguration);
|
||||||
|
return new CorsFilter(source);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -41,21 +41,21 @@ public class PraiseController {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@PostMapping("/savePraise")
|
@PostMapping("/savePraise")
|
||||||
public R savePraise(HttpServletRequest request,Integer worksId){
|
public R savePraise(HttpServletRequest request,Integer worksId,String openid){
|
||||||
String openid = getValue(request.getCookies(), "openid");
|
/*String openid = getValue(request.getCookies(), "openid");
|
||||||
if("prod".equals(activeProfiles) && StringUtils.isBlank(openid)){
|
if("prod".equals(activeProfiles) && StringUtils.isBlank(openid)){
|
||||||
log.error("openid为空,请求参数");
|
log.error("openid为空,请求参数");
|
||||||
return R.error("openid不能为空");
|
return R.error("openid不能为空");
|
||||||
}
|
}*/
|
||||||
if(worksId == null){
|
if(worksId == null){
|
||||||
log.info("作品id不能为空!");
|
log.error("作品id不能为空!");
|
||||||
return R.error("作品id不能为空!");
|
return R.error("作品id不能为空!");
|
||||||
}
|
}
|
||||||
QueryWrapper<WorksDao> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<WorksDao> queryWrapper = new QueryWrapper<>();
|
||||||
queryWrapper.eq("id",worksId);
|
queryWrapper.eq("id",worksId);
|
||||||
WorksDao worksDao = worksMapper.selectOne(queryWrapper);
|
WorksDao worksDao = worksMapper.selectOne(queryWrapper);
|
||||||
if(worksDao == null){
|
if(worksDao == null){
|
||||||
log.info("作品不存在!");
|
log.error("作品不存在!");
|
||||||
return R.error("作品不存在!");
|
return R.error("作品不存在!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,11 +64,6 @@ public class PraiseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// @PostMapping("/saveSharePraise")
|
|
||||||
// public R saveSharePraise(HttpServletRequest request){
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取cookie
|
* 获取cookie
|
||||||
* @param cookies
|
* @param cookies
|
||||||
|
|||||||
@ -46,10 +46,11 @@ public class RankingController {
|
|||||||
private WorksService worksService;
|
private WorksService worksService;
|
||||||
|
|
||||||
//redis中作品排序的key
|
//redis中作品排序的key
|
||||||
private static final String RANKING = "RANKING";
|
private static final String RANKING = "2021_pars_h5:sort:RANKING";
|
||||||
|
|
||||||
|
//redis中用户作品的key userInfo + openid
|
||||||
@Autowired
|
@Autowired
|
||||||
private static final String USERINFO = "userInfo";
|
private static final String USERINFO = "2021_pars_h5:userInfo:user";
|
||||||
|
|
||||||
//Bucket 域名
|
//Bucket 域名
|
||||||
@Value("${oss.bucketDomain}")
|
@Value("${oss.bucketDomain}")
|
||||||
@ -59,24 +60,16 @@ public class RankingController {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 排行榜列表
|
* 排行榜列表
|
||||||
* @param page 分页数
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@GetMapping("/getWorksPraiseNo")
|
@GetMapping("/getWorksPraiseNo")
|
||||||
public R getWorksPraiseNo(Integer page, HttpServletRequest request){
|
public R getWorksPraiseNo(HttpServletRequest request,String openid){
|
||||||
String openid = getValue(request.getCookies(), "openid");
|
/*String openid = getValue(request.getCookies(), "openid");
|
||||||
if("prod".equals(activeProfiles) && StringUtils.isBlank(openid)){
|
if("prod".equals(activeProfiles) && StringUtils.isBlank(openid)){
|
||||||
log.error("openid为空,请求参数");
|
log.error("openid为空,请求参数");
|
||||||
return R.error("openid不能为空");
|
return R.error("openid不能为空");
|
||||||
}
|
}*/
|
||||||
//排行榜最多显示30个数据 一页显示8个数据
|
|
||||||
if(page > 4 ){
|
|
||||||
page = 30;
|
|
||||||
}else if(page == 4){
|
|
||||||
page = page * 8 - 2;
|
|
||||||
}else {
|
|
||||||
page = page*(8-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<UserDO> userDOS = userService.getUserList();
|
List<UserDO> userDOS = userService.getUserList();
|
||||||
for (UserDO userDO : userDOS) {
|
for (UserDO userDO : userDOS) {
|
||||||
@ -91,12 +84,17 @@ public class RankingController {
|
|||||||
UserWorks userWorks1 = userService.getUserWorks(openid);
|
UserWorks userWorks1 = userService.getUserWorks(openid);
|
||||||
UserWorks userWork = null;
|
UserWorks userWork = null;
|
||||||
if(userWorks1 != null){
|
if(userWorks1 != null){
|
||||||
|
if(redisUtil.hasKey(RANKING)){
|
||||||
//获取自己当前排行
|
//获取自己当前排行
|
||||||
userWork = (UserWorks) redisUtil.get(USERINFO + openid);
|
userWork = (UserWorks) redisUtil.get(USERINFO + openid);
|
||||||
Long aLong1 = redisUtil.reverseRank(RANKING, openid);
|
Long aLong1 = redisUtil.reverseRank(RANKING, openid);
|
||||||
if(aLong1 != null){
|
if(aLong1 != null){
|
||||||
userWork.setRank(aLong1+1);
|
userWork.setRank(aLong1+1);
|
||||||
}
|
}
|
||||||
|
String url = userWork.getUrl();
|
||||||
|
//oss的文件路径 oss服务器默认域名+文件路径
|
||||||
|
url = bucketDomain + "/" +url;
|
||||||
|
userWork.setUrl(url);
|
||||||
//用户点赞数
|
//用户点赞数
|
||||||
int i = redisUtil.score(RANKING, openid).intValue();
|
int i = redisUtil.score(RANKING, openid).intValue();
|
||||||
userWork.setPraiseno(i);
|
userWork.setPraiseno(i);
|
||||||
@ -104,13 +102,16 @@ public class RankingController {
|
|||||||
Integer praiseId = praiseService.getPraiseStatus(openid,userWork.getId());
|
Integer praiseId = praiseService.getPraiseStatus(openid,userWork.getId());
|
||||||
userWork.setPraiseStatus(praiseId);
|
userWork.setPraiseStatus(praiseId);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Set<ZSetOperations.TypedTuple<Object>> set = null;
|
Set<ZSetOperations.TypedTuple<Object>> set = null;
|
||||||
List<UserWorks> list = new ArrayList<>();
|
List<UserWorks> list = new ArrayList<>();
|
||||||
if(redisUtil.hasKey(RANKING)){
|
if(redisUtil.hasKey(RANKING)){
|
||||||
set = redisUtil.rangeWithScores(RANKING, 0, page);
|
set = redisUtil.rangeWithScores(RANKING, 0, 30);
|
||||||
for (ZSetOperations.TypedTuple<Object> objectTypedTuple : set) {
|
for (ZSetOperations.TypedTuple<Object> objectTypedTuple : set) {
|
||||||
Long aLong = redisUtil.reverseRank(RANKING, objectTypedTuple.getValue());
|
Long aLong = redisUtil.reverseRank(RANKING, objectTypedTuple.getValue());
|
||||||
|
//判断redis中是否有用户信息
|
||||||
|
if(redisUtil.hasKey(USERINFO+objectTypedTuple.getValue())){
|
||||||
//redis获取用户信息
|
//redis获取用户信息
|
||||||
UserWorks userWorks = (UserWorks)redisUtil.get(USERINFO + objectTypedTuple.getValue());
|
UserWorks userWorks = (UserWorks)redisUtil.get(USERINFO + objectTypedTuple.getValue());
|
||||||
String url = userWorks.getUrl();
|
String url = userWorks.getUrl();
|
||||||
@ -127,11 +128,14 @@ public class RankingController {
|
|||||||
userWorks.setPraiseStatus(result);
|
userWorks.setPraiseStatus(result);
|
||||||
list.add(userWorks);
|
list.add(userWorks);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//list按分数升序
|
//list按分数升序
|
||||||
list.sort(Comparator.comparing(UserWorks::getRank));
|
list.sort(Comparator.comparing(UserWorks::getRank));
|
||||||
HashMap<String, Object> map = new HashMap<>();
|
HashMap<String, Object> map = new HashMap<>();
|
||||||
map.put("data",list);
|
map.put("data",list);
|
||||||
|
map.put("Total",list.size());
|
||||||
map.put("userWork",userWork);
|
map.put("userWork",userWork);
|
||||||
return R.ok(map);
|
return R.ok(map);
|
||||||
}
|
}
|
||||||
@ -142,20 +146,22 @@ public class RankingController {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@GetMapping("/getUserRank")
|
@GetMapping("/getUserRank")
|
||||||
public R getUserRank(HttpServletRequest request){
|
public R getUserRank(HttpServletRequest request,String openid){
|
||||||
String openid = getValue(request.getCookies(), "openid");
|
/*String openid = getValue(request.getCookies(), "openid");
|
||||||
if("prod".equals(activeProfiles) && StringUtils.isBlank(openid)){
|
if("prod".equals(activeProfiles) && StringUtils.isBlank(openid)){
|
||||||
log.error("openid为空,请求参数");
|
log.error("openid为空,请求参数");
|
||||||
return R.error("openid不能为空");
|
return R.error("openid不能为空");
|
||||||
}
|
}*/
|
||||||
HashMap<String, Object> map = new HashMap<>();
|
HashMap<String, Object> map = new HashMap<>();
|
||||||
UserWorks userWorks = userService.getUserWorks(openid);
|
UserWorks userWorks = userService.getUserWorks(openid);
|
||||||
if(userWorks!=null){
|
if(userWorks!=null){
|
||||||
|
if(redisUtil.hasKey(RANKING)){
|
||||||
Long aLong = redisUtil.reverseRank(RANKING, openid);
|
Long aLong = redisUtil.reverseRank(RANKING, openid);
|
||||||
//返回索引值+1 = 排序值
|
//返回索引值+1 = 排序值
|
||||||
map.put("rank",aLong+1);
|
map.put("rank",aLong+1);
|
||||||
map.put("nickname",userWorks.getNickname());
|
map.put("nickname",userWorks.getNickname());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return R.ok(map);
|
return R.ok(map);
|
||||||
}
|
}
|
||||||
@ -168,12 +174,12 @@ public class RankingController {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@GetMapping("/getUserRanking")
|
@GetMapping("/getUserRanking")
|
||||||
public R getUserRanking(HttpServletRequest request,Integer worksId){
|
public R getUserRanking(HttpServletRequest request,Integer worksId,String openid){
|
||||||
String openid = getValue(request.getCookies(), "openid");
|
/*String openid = getValue(request.getCookies(), "openid");
|
||||||
if("prod".equals(activeProfiles) && StringUtils.isBlank(openid)){
|
if("prod".equals(activeProfiles) && StringUtils.isBlank(openid)){
|
||||||
log.error("openid为空,请求参数");
|
log.error("openid为空,请求参数");
|
||||||
return R.error("openid不能为空");
|
return R.error("openid不能为空");
|
||||||
}
|
}*/
|
||||||
//根据作品获取用户openid
|
//根据作品获取用户openid
|
||||||
String openid2 = userService.getWorksUser(worksId);
|
String openid2 = userService.getWorksUser(worksId);
|
||||||
//获取用户作品信息
|
//获取用户作品信息
|
||||||
@ -210,12 +216,12 @@ public class RankingController {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@GetMapping("/getRandom")
|
@GetMapping("/getRandom")
|
||||||
public R getRandom(HttpServletRequest request){
|
public R getRandom(HttpServletRequest request,String openid){
|
||||||
String openid = getValue(request.getCookies(), "openid");
|
/*String openid = getValue(request.getCookies(), "openid");
|
||||||
if("prod".equals(activeProfiles) && StringUtils.isBlank(openid)){
|
if("prod".equals(activeProfiles) && StringUtils.isBlank(openid)){
|
||||||
log.error("openid为空,请求参数");
|
log.error("openid为空,请求参数");
|
||||||
return R.error("openid不能为空");
|
return R.error("openid不能为空");
|
||||||
}
|
}*/
|
||||||
//获取作品id
|
//获取作品id
|
||||||
UserWorks userWorks = (UserWorks) redisUtil.get(USERINFO + openid);
|
UserWorks userWorks = (UserWorks) redisUtil.get(USERINFO + openid);
|
||||||
if(userWorks == null){
|
if(userWorks == null){
|
||||||
|
|||||||
@ -1,13 +1,17 @@
|
|||||||
package com.szxgl.pars2021.controller;
|
package com.szxgl.pars2021.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import com.szxgl.pars2021.utils.R;
|
||||||
import com.szxgl.pars2021.utils.RedisUtil;
|
import com.szxgl.pars2021.utils.RedisUtil;
|
||||||
import com.szxgl.pars2021.utils.VerifyUtil;
|
import com.szxgl.pars2021.utils.VerifyUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.servlet.http.Cookie;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
@ -16,7 +20,10 @@ import javax.servlet.http.HttpServletResponse;
|
|||||||
@RequestMapping("/code")
|
@RequestMapping("/code")
|
||||||
public class VerificationCodeController {
|
public class VerificationCodeController {
|
||||||
|
|
||||||
public static final String RANDOMCODEKEY= "RANDOMREDISKEY";//放到session中的key
|
public static final String RANDOMCODEKEY= "2021_pars_h5:code:RANDOMREDISKEY";//放到session中的key
|
||||||
|
|
||||||
|
@Value("${spring.profiles.active}")
|
||||||
|
private String activeProfiles;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private RedisUtil redisUtil;
|
private RedisUtil redisUtil;
|
||||||
@ -26,7 +33,11 @@ public class VerificationCodeController {
|
|||||||
* @desc 图形验证码生成
|
* @desc 图形验证码生成
|
||||||
*/
|
*/
|
||||||
@RequestMapping("/createImg")
|
@RequestMapping("/createImg")
|
||||||
public void createImg(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
public void createImg(HttpServletRequest request, HttpServletResponse response,String openid) throws Exception {
|
||||||
|
/*String openid = getValue(request.getCookies(), "openid");
|
||||||
|
if("prod".equals(activeProfiles) && StringUtils.isBlank(openid)){
|
||||||
|
log.error("openid为空,请求参数");
|
||||||
|
}*/
|
||||||
try {
|
try {
|
||||||
response.setContentType("image/jpeg");//设置相应类型,告诉浏览器输出的内容为图片
|
response.setContentType("image/jpeg");//设置相应类型,告诉浏览器输出的内容为图片
|
||||||
response.setHeader("Pragma", "No-cache");//设置响应头信息,告诉浏览器不要缓存此内容
|
response.setHeader("Pragma", "No-cache");//设置响应头信息,告诉浏览器不要缓存此内容
|
||||||
@ -35,9 +46,29 @@ public class VerificationCodeController {
|
|||||||
VerifyUtil randomValidateCode = new VerifyUtil();
|
VerifyUtil randomValidateCode = new VerifyUtil();
|
||||||
randomValidateCode.getRandcode(request, response);//输出验证码图片
|
randomValidateCode.getRandcode(request, response);//输出验证码图片
|
||||||
//将生成的随机验证码存放到redis中
|
//将生成的随机验证码存放到redis中
|
||||||
redisUtil.set(RANDOMCODEKEY,request.getSession().getAttribute(RANDOMCODEKEY),Long.parseLong("60"));
|
redisUtil.set(RANDOMCODEKEY+openid,request.getSession().getAttribute(RANDOMCODEKEY),Long.parseLong("60"));
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
log.error("获取验证码异常:", e);
|
log.error("获取验证码异常:", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取cookie
|
||||||
|
* @param cookies
|
||||||
|
* @param key
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected String getValue(Cookie[] cookies, String key) {
|
||||||
|
String value = null;
|
||||||
|
if (null != cookies && cookies.length > 0) {
|
||||||
|
for (Cookie c : cookies) {
|
||||||
|
if (key.equals(c.getName())) {
|
||||||
|
value = c.getValue();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -38,7 +38,8 @@ public class WechatController {
|
|||||||
@Value("${spring.profiles.active}")
|
@Value("${spring.profiles.active}")
|
||||||
private String activeProfiles;
|
private String activeProfiles;
|
||||||
|
|
||||||
public static final String RANDOMCODEKEY= "RANDOMREDISKEY";//验证码放到session和redis中的key
|
public static final String RANDOMCODEKEY= "2021_pars_h5:code:RANDOMREDISKEY";//验证码放到session和redis中的key
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private RedisUtil redisUtil;
|
private RedisUtil redisUtil;
|
||||||
@ -116,12 +117,12 @@ public class WechatController {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@GetMapping("/getUserInfo")
|
@GetMapping("/getUserInfo")
|
||||||
public R getUserInfo(HttpServletRequest request){
|
public R getUserInfo(HttpServletRequest request,String openid){
|
||||||
String openid = getValue(request.getCookies(), "openid");
|
/*String openid = getValue(request.getCookies(), "openid");
|
||||||
if("prod".equals(activeProfiles) && StringUtils.isBlank(openid)){
|
if("prod".equals(activeProfiles) && StringUtils.isBlank(openid)){
|
||||||
log.error("openid为空,请求参数");
|
log.error("openid为空,请求参数");
|
||||||
return R.error("openid不能为空");
|
return R.error("openid不能为空");
|
||||||
}
|
}*/
|
||||||
UserDO userDO = userService.getUserInfo(openid);
|
UserDO userDO = userService.getUserInfo(openid);
|
||||||
Map<String,Object> map = new HashMap<>();
|
Map<String,Object> map = new HashMap<>();
|
||||||
if(!StringUtils.isNoneBlank(userDO.getRealname()) || !StringUtils.isNoneBlank(userDO.getPhone())) {
|
if(!StringUtils.isNoneBlank(userDO.getRealname()) || !StringUtils.isNoneBlank(userDO.getPhone())) {
|
||||||
@ -142,12 +143,12 @@ public class WechatController {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@PostMapping("/saveUserInfo")
|
@PostMapping("/saveUserInfo")
|
||||||
public R saveUserInfo(HttpServletRequest request,UserDO userDO,String code){
|
public R saveUserInfo(HttpServletRequest request,UserDO userDO,String code,String openid){
|
||||||
String openid = getValue(request.getCookies(), "openid");
|
/*String openid = getValue(request.getCookies(), "openid");
|
||||||
if("prod".equals(activeProfiles) && StringUtils.isBlank(openid)){
|
if("prod".equals(activeProfiles) && StringUtils.isBlank(openid)){
|
||||||
log.error("openid为空,请求参数");
|
log.error("openid为空,请求参数");
|
||||||
return R.error("openid不能为空");
|
return R.error("openid不能为空");
|
||||||
}
|
}*/
|
||||||
if(!StringUtils.isNoneBlank(userDO.getRealname()) || !StringUtils.isNoneBlank(userDO.getPhone())){
|
if(!StringUtils.isNoneBlank(userDO.getRealname()) || !StringUtils.isNoneBlank(userDO.getPhone())){
|
||||||
log.error("真实姓名和手机号的参数不能为空!");
|
log.error("真实姓名和手机号的参数不能为空!");
|
||||||
return R.error("真实姓名和手机号的参数不能为空!");
|
return R.error("真实姓名和手机号的参数不能为空!");
|
||||||
@ -159,13 +160,13 @@ public class WechatController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//判断验证码是否过期
|
//判断验证码是否过期
|
||||||
if(!redisUtil.hasKey(RANDOMCODEKEY)){
|
if(!redisUtil.hasKey(RANDOMCODEKEY+openid)){
|
||||||
log.error("验证码已过期!");
|
log.error("验证码已过期!");
|
||||||
return R.error("验证码已过期!");
|
return R.error("验证码已过期!");
|
||||||
}
|
}
|
||||||
|
|
||||||
//判断验证码是否正确
|
//判断验证码是否正确
|
||||||
if(!redisUtil.get(RANDOMCODEKEY).equals(code.toUpperCase())){
|
if(!redisUtil.get(RANDOMCODEKEY+openid).equals(code.toUpperCase())){
|
||||||
log.error("验证码错误!");
|
log.error("验证码错误!");
|
||||||
return R.error("验证码错误!");
|
return R.error("验证码错误!");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -34,7 +34,7 @@ public class WorksController {
|
|||||||
private String activeProfiles;
|
private String activeProfiles;
|
||||||
|
|
||||||
//redis中作品排序的key
|
//redis中作品排序的key
|
||||||
private static final String RANKING = "RANKING";
|
private static final String RANKING = "2021_pars_h5:sort:RANKING";
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserService userService;
|
private UserService userService;
|
||||||
@ -61,12 +61,12 @@ public class WorksController {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@PostMapping("/saveWorks")
|
@PostMapping("/saveWorks")
|
||||||
public R saveWorks(MultipartFile file, HttpServletRequest request){
|
public R saveWorks(MultipartFile file, HttpServletRequest request,String openid){
|
||||||
String openid = getValue(request.getCookies(), "openid");
|
/*String openid = getValue(request.getCookies(), "openid");
|
||||||
if("prod".equals(activeProfiles) && StringUtils.isBlank(openid)){
|
if("prod".equals(activeProfiles) && StringUtils.isBlank(openid)){
|
||||||
log.error("openid为空,请求参数");
|
log.error("openid为空,请求参数");
|
||||||
return R.error("openid不能为空");
|
return R.error("openid不能为空");
|
||||||
}
|
}*/
|
||||||
|
|
||||||
UserDO userDO = userService.get(openid);
|
UserDO userDO = userService.get(openid);
|
||||||
if(!StringUtils.isNoneBlank(userDO.getRealname()) || !StringUtils.isNoneBlank(userDO.getPhone())){
|
if(!StringUtils.isNoneBlank(userDO.getRealname()) || !StringUtils.isNoneBlank(userDO.getPhone())){
|
||||||
@ -81,6 +81,8 @@ public class WorksController {
|
|||||||
return R.error("您已经上传过作品,请勿重复上传!");
|
return R.error("您已经上传过作品,请勿重复上传!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
//上传文件到oss上
|
//上传文件到oss上
|
||||||
R r = UploadFileToOssUtil.uploadFileToOss(file.getInputStream(), Objects.requireNonNull(file.getOriginalFilename()));
|
R r = UploadFileToOssUtil.uploadFileToOss(file.getInputStream(), Objects.requireNonNull(file.getOriginalFilename()));
|
||||||
@ -115,12 +117,12 @@ public class WorksController {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@GetMapping("/getUploadFile")
|
@GetMapping("/getUploadFile")
|
||||||
public R getUploadFile(HttpServletRequest request){
|
public R getUploadFile(HttpServletRequest request,String openid){
|
||||||
String openid = getValue(request.getCookies(), "openid");
|
/*String openid = getValue(request.getCookies(), "openid");
|
||||||
if("prod".equals(activeProfiles) && StringUtils.isBlank(openid)){
|
if("prod".equals(activeProfiles) && StringUtils.isBlank(openid)){
|
||||||
log.error("openid为空,请求参数");
|
log.error("openid为空,请求参数");
|
||||||
return R.error("openid不能为空");
|
return R.error("openid不能为空");
|
||||||
}
|
}*/
|
||||||
WorksDao works = worksService.getWorks(openid);
|
WorksDao works = worksService.getWorks(openid);
|
||||||
HashMap<String, Object> map = new HashMap<>();
|
HashMap<String, Object> map = new HashMap<>();
|
||||||
if(works == null){
|
if(works == null){
|
||||||
|
|||||||
@ -1,23 +1,30 @@
|
|||||||
package com.szxgl.pars2021.exception;
|
package com.szxgl.pars2021.exception;
|
||||||
|
|
||||||
import com.szxgl.pars2021.utils.R;
|
import com.szxgl.pars2021.utils.R;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
import org.springframework.web.bind.annotation.RestControllerAdvice;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
@RestControllerAdvice
|
@RestControllerAdvice
|
||||||
|
@Slf4j
|
||||||
public class MyAjaxExceptionHandler {
|
public class MyAjaxExceptionHandler {
|
||||||
|
|
||||||
@ExceptionHandler(value = Exception.class)
|
@ExceptionHandler(value = Exception.class)
|
||||||
public R defaultErrorHandler(HttpServletRequest request, Exception e){
|
public R defaultErrorHandler(HttpServletRequest request, Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
log.error(e.getMessage());
|
||||||
|
log.error(Arrays.toString(e.getStackTrace()));
|
||||||
return R.error("服务器出现异常!");
|
return R.error("服务器出现异常!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ExceptionHandler(value = ParameterException.class)
|
@ExceptionHandler(value = ParameterException.class)
|
||||||
public R ParameterErrorHandler(HttpServletRequest request, Exception e){
|
public R ParameterErrorHandler(HttpServletRequest request, Exception e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
log.error(e.getMessage());
|
||||||
|
log.error(Arrays.toString(e.getStackTrace()));
|
||||||
return R.error(e.getMessage());
|
return R.error(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +0,0 @@
|
|||||||
package com.szxgl.pars2021.service;
|
|
||||||
|
|
||||||
public interface RankingService {
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -36,7 +36,7 @@ public class PraiseServiceImpl implements PraiseService {
|
|||||||
private RedisUtil redisUtil;
|
private RedisUtil redisUtil;
|
||||||
|
|
||||||
//redis中作品排序的key
|
//redis中作品排序的key
|
||||||
private static final String RANKING = "RANKING";
|
private static final String RANKING = "2021_pars_h5:sort:RANKING";
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -97,16 +97,4 @@ public class PraiseServiceImpl implements PraiseService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
//String time = "2021-10-15 14:14:07";
|
|
||||||
//String substring = time.substring(0,time.lastIndexOf(" ")).replaceAll("-","");
|
|
||||||
String time = new SimpleDateFormat("yyyyMMdd").format(new Date()).replaceAll("-","");
|
|
||||||
String newTime = new SimpleDateFormat("yyyyMMdd").format(new Date()).replaceAll("-","");
|
|
||||||
if(time.equals(newTime)){
|
|
||||||
System.out.println("1111");
|
|
||||||
}
|
|
||||||
System.out.println(newTime);
|
|
||||||
System.out.println(time);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,16 +0,0 @@
|
|||||||
package com.szxgl.pars2021.service.impl;
|
|
||||||
|
|
||||||
import com.szxgl.pars2021.service.RankingService;
|
|
||||||
import com.szxgl.pars2021.utils.RedisUtil;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@Service
|
|
||||||
public class RankingServiceImpl implements RankingService {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private RedisUtil redisUtil;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -27,7 +27,7 @@ public class UserServiceImpl implements UserService {
|
|||||||
private RedisUtil redisUtil;
|
private RedisUtil redisUtil;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private static final String USERINFO = "userInfo";
|
private static final String USERINFO = "2021_pars_h5:userInfo:user";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void saveAndUpdate(WxMpUser wxMpUser) {
|
public void saveAndUpdate(WxMpUser wxMpUser) {
|
||||||
|
|||||||
@ -1,10 +1,11 @@
|
|||||||
package com.szxgl.pars2021.service;
|
package com.szxgl.pars2021.service.impl;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.szxgl.pars2021.entity.UserWorks;
|
import com.szxgl.pars2021.entity.UserWorks;
|
||||||
import com.szxgl.pars2021.entity.WorksDao;
|
import com.szxgl.pars2021.entity.WorksDao;
|
||||||
import com.szxgl.pars2021.mapper.WorksMapper;
|
import com.szxgl.pars2021.mapper.WorksMapper;
|
||||||
import com.szxgl.pars2021.mapper.WorksMapper2;
|
import com.szxgl.pars2021.mapper.WorksMapper2;
|
||||||
|
import com.szxgl.pars2021.service.WorksService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@ -21,7 +22,6 @@ public class WorksServiceImpl implements WorksService {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void saveWorks(WorksDao worksDao) {
|
public void saveWorks(WorksDao worksDao) {
|
||||||
worksMapper.insert(worksDao);
|
worksMapper.insert(worksDao);
|
||||||
@ -12,7 +12,7 @@ import java.util.Random;
|
|||||||
|
|
||||||
|
|
||||||
public class VerifyUtil {
|
public class VerifyUtil {
|
||||||
public static final String RANDOMCODEKEY= "RANDOMREDISKEY";//放到session中的key
|
public static final String RANDOMCODEKEY= "2021_pars_h5:code:RANDOMREDISKEY";//放到session中的key
|
||||||
private String randString = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";//随机产生数字与字母组合的字符串
|
private String randString = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";//随机产生数字与字母组合的字符串
|
||||||
private int width = 95;// 图片宽
|
private int width = 95;// 图片宽
|
||||||
private int height = 25;// 图片高
|
private int height = 25;// 图片高
|
||||||
|
|||||||
@ -31,6 +31,25 @@ spring:
|
|||||||
wall:
|
wall:
|
||||||
config:
|
config:
|
||||||
multi-statement-allow: true
|
multi-statement-allow: true
|
||||||
|
servlet:
|
||||||
|
multipart:
|
||||||
|
max-file-size: 500MB
|
||||||
|
max-request-size: 500MB
|
||||||
|
redis:
|
||||||
|
open: false # 是否开启redis缓存 true开启 false关闭
|
||||||
|
database: 0
|
||||||
|
host: localhost
|
||||||
|
port: 6379
|
||||||
|
password: '' # 密码
|
||||||
|
timeout: 6000ms # 连接超时时长(毫秒)
|
||||||
|
jedis:
|
||||||
|
pool:
|
||||||
|
max-active: 1000 # 连接池最大连接数(使用负值表示没有限制)
|
||||||
|
max-wait: -1ms # 连接池最大阻塞等待时间(使用负值表示没有限制)
|
||||||
|
max-idle: 10 # 连接池中的最大空闲连接
|
||||||
|
min-idle: 5 # 连接池中的最小空闲连接
|
||||||
|
|
||||||
|
|
||||||
wx:
|
wx:
|
||||||
appid: wx35766a64d73d08a9 #appid
|
appid: wx35766a64d73d08a9 #appid
|
||||||
project-id: 20210001000100011 #活动id
|
project-id: 20210001000100011 #活动id
|
||||||
@ -43,11 +62,13 @@ activity:
|
|||||||
end-date: '2021-11-10 00:00' #投票结束时间
|
end-date: '2021-11-10 00:00' #投票结束时间
|
||||||
times: 1 #投票次数限制
|
times: 1 #投票次数限制
|
||||||
|
|
||||||
|
oss:
|
||||||
#阿里云 OSS
|
#阿里云 OSS
|
||||||
#不同的服务器,地址不同
|
#地域节点
|
||||||
endpoint: oss-cn-hangzhou.aliyuncs.com
|
endpoint: oss-cn-hangzhou.aliyuncs.com
|
||||||
keyid: LTAI4G88mJUn3YzWo2eFmxVG
|
keyid: LTAI4G88mJUn3YzWo2eFmxVG
|
||||||
keysecret: iWNQskqvXC7Rm0au2W2u3AGNFEgYMl
|
keysecret: iWNQskqvXC7Rm0au2W2u3AGNFEgYMl
|
||||||
#bucket可以在控制台创建,也可以使用java代码创建
|
#Bucket 名字
|
||||||
bucketname: h5buckets
|
bucketname: h5buckets
|
||||||
|
#Bucket 域名
|
||||||
bucketDomain: h5buckets.oss-cn-hangzhou.aliyuncs.com
|
bucketDomain: h5buckets.oss-cn-hangzhou.aliyuncs.com
|
||||||
|
|||||||
@ -35,6 +35,19 @@ spring:
|
|||||||
multipart:
|
multipart:
|
||||||
max-file-size: 500MB
|
max-file-size: 500MB
|
||||||
max-request-size: 500MB
|
max-request-size: 500MB
|
||||||
|
redis:
|
||||||
|
open: false # 是否开启redis缓存 true开启 false关闭
|
||||||
|
database: 0
|
||||||
|
host: 120.25.121.117
|
||||||
|
port: 8266
|
||||||
|
password: 'Qiween@4531871' # 密码
|
||||||
|
timeout: 6000ms # 连接超时时长(毫秒)
|
||||||
|
jedis:
|
||||||
|
pool:
|
||||||
|
max-active: 1000 # 连接池最大连接数(使用负值表示没有限制)
|
||||||
|
max-wait: -1ms # 连接池最大阻塞等待时间(使用负值表示没有限制)
|
||||||
|
max-idle: 10 # 连接池中的最大空闲连接
|
||||||
|
min-idle: 5 # 连接池中的最小空闲连接
|
||||||
|
|
||||||
|
|
||||||
wx:
|
wx:
|
||||||
|
|||||||
@ -7,7 +7,7 @@ spring:
|
|||||||
# mvc:
|
# mvc:
|
||||||
# dispatch-options-request: true
|
# dispatch-options-request: true
|
||||||
jmx:
|
jmx:
|
||||||
default-domain: vote2021
|
default-domain: pars-h5-2021
|
||||||
profiles:
|
profiles:
|
||||||
active: test
|
active: test
|
||||||
# mvc:
|
# mvc:
|
||||||
@ -18,6 +18,8 @@ spring:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#mybatis
|
#mybatis
|
||||||
mybatis-plus:
|
mybatis-plus:
|
||||||
mapper-locations: classpath*:/mapper/**/*.xml
|
mapper-locations: classpath*:/mapper/**/*.xml
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user