优化猜词按钮颜色,新增首页每日情话,新增斗图功能
This commit is contained in:
12
src/main/java/com/quinn/common/ExpBucket.java
Normal file
12
src/main/java/com/quinn/common/ExpBucket.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package com.quinn.common;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ExpBucket {
|
||||
|
||||
String name;
|
||||
String category;
|
||||
String url;
|
||||
|
||||
}
|
||||
@@ -7,6 +7,8 @@ public interface QuinnConstant {
|
||||
String LINK_KEY_WORD = ",";
|
||||
|
||||
String LINK_DATE_STR = "_";
|
||||
|
||||
String LINK_LOVE_STR = "#";
|
||||
/**
|
||||
* REDIS PATTEN
|
||||
*/
|
||||
|
||||
@@ -3,9 +3,13 @@ package com.quinn.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.quinn.common.ExpBucket;
|
||||
import com.quinn.intergration.BucketImage;
|
||||
import com.quinn.pojo.About;
|
||||
import com.quinn.service.AboutService;
|
||||
import com.quinn.utils.QuinnUtils;
|
||||
import com.quinn.vo.FindNavReq;
|
||||
import com.quinn.vo.MyPageParam;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
@@ -13,6 +17,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -41,16 +46,36 @@ public class AboutController extends BaseModelController {
|
||||
return "page/about";
|
||||
}
|
||||
|
||||
@GetMapping("/favor")
|
||||
public String favor(){
|
||||
return "favor";
|
||||
}
|
||||
|
||||
@GetMapping("/guess")
|
||||
public String guess(){
|
||||
return "cimi/guess";
|
||||
}
|
||||
|
||||
// 列表展示
|
||||
@GetMapping("/favor")
|
||||
public String sourceList(Model model) throws IOException {
|
||||
MyPageParam pageParam = new MyPageParam(1,24);
|
||||
List<ExpBucket> recordList = aboutService.listExp(null,pageParam);
|
||||
model.addAttribute("recordList",recordList);
|
||||
model.addAttribute("pageParam",pageParam);
|
||||
return "page/favor";
|
||||
}
|
||||
|
||||
@PostMapping("/favor")
|
||||
public String blogListPage(FindNavReq findNavReq, Model model) throws IOException {
|
||||
int page = findNavReq.getPageNum();
|
||||
int limit = findNavReq.getLimit();
|
||||
if (findNavReq.getPageNum() < 1){
|
||||
page = 1;
|
||||
}
|
||||
MyPageParam pageParam = new MyPageParam(page,limit);
|
||||
List<ExpBucket> recordList = aboutService.listExp(findNavReq.getFindWhat(),pageParam);
|
||||
// 结果
|
||||
model.addAttribute("recordList",recordList);
|
||||
model.addAttribute("pageParam",pageParam);
|
||||
return "page/favor::user_table_refresh";
|
||||
}
|
||||
|
||||
@PostMapping("/about/append")
|
||||
@PreAuthorize("hasAuthority('ADMIN')")
|
||||
public String saveSay(About about){
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.quinn.common.QuinnException;
|
||||
import com.quinn.common.RoleType;
|
||||
import com.quinn.intergration.AttrIcon;
|
||||
import com.quinn.intergration.TodayLove;
|
||||
import com.quinn.pojo.Invite;
|
||||
import com.quinn.pojo.User;
|
||||
import com.quinn.pojo.UserInfo;
|
||||
@@ -22,6 +23,7 @@ import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
@@ -35,11 +37,15 @@ public class LoginController {
|
||||
UserService userService;
|
||||
@Autowired
|
||||
UserInfoService userInfoService;
|
||||
@Resource
|
||||
TodayLove todayLove;
|
||||
|
||||
@GetMapping({"/","/index","/source/view/index",
|
||||
"/blog/read/index"
|
||||
})
|
||||
public String index(){
|
||||
public String index(Model model) throws IOException {
|
||||
// 每日情话
|
||||
model.addAttribute("LoveList",todayLove.getTodayLoveStr());
|
||||
return "index";
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ public class CodeGenerator {
|
||||
|
||||
// 5、策略配置
|
||||
StrategyConfig strategy = new StrategyConfig();
|
||||
strategy.setInclude("qn_email");//设置要映射的表名
|
||||
strategy.setInclude("qn_bucket_url");//设置要映射的表名
|
||||
strategy.setNaming(NamingStrategy.underline_to_camel);//数据库表映射到实体的命名策略
|
||||
strategy.setTablePrefix("qn_");//设置表前缀不生成
|
||||
|
||||
|
||||
65
src/main/java/com/quinn/intergration/BucketImage.java
Normal file
65
src/main/java/com/quinn/intergration/BucketImage.java
Normal file
@@ -0,0 +1,65 @@
|
||||
package com.quinn.intergration;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.quinn.common.ExpBucket;
|
||||
import com.quinn.utils.JsonUtils;
|
||||
import com.quinn.vo.MyPageParam;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.ResourceUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
public class BucketImage implements InitializingBean {
|
||||
|
||||
Map<String,String> dictionary = new HashMap<>();
|
||||
|
||||
public List<ExpBucket> listExp(String findWhat, MyPageParam myPageParam) throws IOException {
|
||||
List<ExpBucket> result = new ArrayList<>();
|
||||
if (CollectionUtils.isEmpty(dictionary)){
|
||||
makeDictionary();
|
||||
}
|
||||
List<String> resultAll = dictionary.keySet().stream().filter(x ->
|
||||
StringUtils.isEmpty(findWhat) ? true : x.contains(findWhat)).collect(Collectors.toList());
|
||||
myPageParam.setTotal(resultAll.size());
|
||||
int pageNum = myPageParam.getPageNum();
|
||||
for (int i = 0;i<myPageParam.getSize(); i++){
|
||||
if (pageNum + i >= myPageParam.getTotal()){
|
||||
break;
|
||||
}
|
||||
ExpBucket expBucket = new ExpBucket();
|
||||
expBucket.setName(resultAll.get(pageNum + i));
|
||||
expBucket.setUrl(dictionary.get(resultAll.get(pageNum + i)));
|
||||
result.add(expBucket);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
makeDictionary();
|
||||
}
|
||||
|
||||
private void makeDictionary() throws IOException {
|
||||
File file = ResourceUtils.getFile("classpath:bqb/image.json");
|
||||
InputStreamReader insReader = new InputStreamReader(
|
||||
new FileInputStream(file), "UTF-8");
|
||||
BufferedReader bufReader = new BufferedReader(insReader);
|
||||
String json = bufReader.readLine();
|
||||
bufReader.close();
|
||||
insReader.close();
|
||||
List<ExpBucket> decode = JsonUtils.decode(json, new TypeReference<List<ExpBucket>>() {
|
||||
});
|
||||
for (ExpBucket expBucket : decode) {
|
||||
this.dictionary.put(expBucket.getName(),expBucket.getUrl());
|
||||
}
|
||||
}
|
||||
}
|
||||
49
src/main/java/com/quinn/intergration/TodayLove.java
Normal file
49
src/main/java/com/quinn/intergration/TodayLove.java
Normal file
@@ -0,0 +1,49 @@
|
||||
package com.quinn.intergration;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.quinn.common.QuinnConstant;
|
||||
import com.quinn.utils.JsonUtils;
|
||||
import com.quinn.utils.QuinnUtils;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.ResourceUtils;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
@Component
|
||||
public class TodayLove implements InitializingBean {
|
||||
|
||||
private List<String> dictionary = new ArrayList<>();
|
||||
|
||||
public List<String> getTodayLoveStr() throws IOException {
|
||||
if (CollectionUtils.isEmpty(dictionary)){
|
||||
makeDictionary();
|
||||
}
|
||||
int days = QuinnUtils.differentDays(new Date(2022, 4, 1), new Date());
|
||||
int i = days % dictionary.size();
|
||||
String todayStr = dictionary.get(i);
|
||||
String[] split = todayStr.split(QuinnConstant.LINK_LOVE_STR);
|
||||
return Arrays.asList(split);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
makeDictionary();
|
||||
}
|
||||
|
||||
private void makeDictionary() throws IOException {
|
||||
File file = ResourceUtils.getFile("classpath:bqb/love.json");
|
||||
InputStreamReader insReader = new InputStreamReader(
|
||||
new FileInputStream(file), "UTF-8");
|
||||
BufferedReader bufReader = new BufferedReader(insReader);
|
||||
String json = bufReader.readLine();
|
||||
bufReader.close();
|
||||
insReader.close();
|
||||
List<String> decode = JsonUtils.decode(json, new TypeReference<List<String>>() {
|
||||
});
|
||||
dictionary = decode;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,12 @@
|
||||
package com.quinn.service;
|
||||
|
||||
import com.quinn.common.ExpBucket;
|
||||
import com.quinn.pojo.About;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.quinn.vo.MyPageParam;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -13,4 +18,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
*/
|
||||
public interface AboutService extends IService<About> {
|
||||
|
||||
List<ExpBucket> listExp(String findWhat, MyPageParam pageParam) throws IOException;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,18 @@
|
||||
package com.quinn.service.impl;
|
||||
|
||||
import com.quinn.common.ExpBucket;
|
||||
import com.quinn.intergration.BucketImage;
|
||||
import com.quinn.pojo.About;
|
||||
import com.quinn.mapper.AboutMapper;
|
||||
import com.quinn.service.AboutService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.quinn.vo.MyPageParam;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.*;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 服务实现类
|
||||
@@ -17,4 +24,11 @@ import org.springframework.stereotype.Service;
|
||||
@Service
|
||||
public class AboutServiceImpl extends ServiceImpl<AboutMapper, About> implements AboutService {
|
||||
|
||||
@Resource
|
||||
BucketImage bucketImage;
|
||||
|
||||
@Override
|
||||
public List<ExpBucket> listExp(String findWhat, MyPageParam pageParam) throws IOException {
|
||||
return bucketImage.listExp(findWhat,pageParam);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.quinn.utils;
|
||||
|
||||
import java.sql.Timestamp;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Random;
|
||||
import java.util.UUID;
|
||||
@@ -39,4 +40,42 @@ public class QuinnUtils {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* date2比date1多的天数
|
||||
* @param date1
|
||||
* @param date2
|
||||
* @return
|
||||
*/
|
||||
public static int differentDays(Date date1,Date date2) {
|
||||
Calendar cal1 = Calendar.getInstance();
|
||||
cal1.setTime(date1);
|
||||
|
||||
Calendar cal2 = Calendar.getInstance();
|
||||
cal2.setTime(date2);
|
||||
int day1= cal1.get(Calendar.DAY_OF_YEAR);
|
||||
int day2 = cal2.get(Calendar.DAY_OF_YEAR);
|
||||
|
||||
int year1 = cal1.get(Calendar.YEAR);
|
||||
int year2 = cal2.get(Calendar.YEAR);
|
||||
if(year1 != year2) {//同一年
|
||||
int timeDistance = 0 ;
|
||||
for(int i = year1 ; i < year2 ; i ++)
|
||||
{
|
||||
if(i%4==0 && i%100!=0 || i%400==0) //闰年
|
||||
{
|
||||
timeDistance += 366;
|
||||
}
|
||||
else //不是闰年
|
||||
{
|
||||
timeDistance += 365;
|
||||
}
|
||||
}
|
||||
|
||||
return timeDistance + (day2-day1) ;
|
||||
} else {// 不同年
|
||||
System.out.println("判断day2 - day1 : " + (day2-day1));
|
||||
return day2-day1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ public class FindNavReq {
|
||||
@ApiModelProperty(value = "个数")
|
||||
private int limit;
|
||||
|
||||
@ApiModelProperty(value = "用户编号")
|
||||
@ApiModelProperty(value = "查询字符串")
|
||||
private String findWhat;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user