Skip to content

Commit

Permalink
重构了部分逻辑,添加了一些常量
Browse files Browse the repository at this point in the history
  • Loading branch information
yilin committed Mar 16, 2023
1 parent 23eb505 commit 9185c1f
Show file tree
Hide file tree
Showing 10 changed files with 370 additions and 19 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/yilin/csuftspider/common/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public enum ErrorCode {
AUTH_ERROR(40101,"没有权限!","");



/**
* 状态码信息
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public class ThreadPoolConfig {
public Executor threadPoolTaskExecutor() {
ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolTaskExecutor();
// 设置核心线程数
threadPoolTaskExecutor.setCorePoolSize(5);
threadPoolTaskExecutor.setCorePoolSize(2);
// 设置最大线程数
threadPoolTaskExecutor.setMaxPoolSize(5);
threadPoolTaskExecutor.setMaxPoolSize(3);
// 设置工作队列大小
threadPoolTaskExecutor.setQueueCapacity(2000);
// 设置线程名称前缀
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/com/yilin/csuftspider/constant/ConstantData.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,25 @@ public interface ConstantData {
* 与前端约定的 sm4 加密密钥 通常是约定密钥16位 如 6666666666666666
*/

String sm4Salt = "";
String sm4Salt = "1234567890123456";

/**
* 百度orc 图片识别 ak
*
*/


String baiduAk = "";
String baiduAk = "SsTGPEllk3cQcTDLYXFmIEmV";

/**
* 百度orc 图片识别 sk
*/

String baiduSk = "";
String baiduSk = "a9tWw38mZw49ajw0S02ZvNT4rPQzafqo";



String UVALUATION_BASE = "老师在教学态度上,绝大部分老师都能得到学生的认可,如有高度的责任心,对学生有耐心、爱心,教书育人,遵守教学纪律,并能以身作则,为人师表;在教学内容上,能够从学生的实际水平出发,认真备课,内容充实,重点突出。在教学过程中,对学生一视同仁,鼓励学生主动探求知识点,承认差异,关注基础薄弱的学生,善于激励,耐心辅导,给基础弱的学生以表现的机会,让他们尝试成功的喜悦;在教学方法上,能够合理运用现代化教学手段,且教法灵活,课堂气氛活跃,注意知识性和趣味性的结合。";



Expand Down
20 changes: 20 additions & 0 deletions src/main/java/com/yilin/csuftspider/constant/UrlConstant.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ public interface UrlConstant {

String BASE_URL = "http://jwgl.webvpn.csuft.edu.cn";


/**
* 基础 教务处通知 url
*/

String BASE_NOTICE_URL = "https://jwc.csuft.edu.cn/tzgg/";

/**
* 登录 url
*/
Expand Down Expand Up @@ -63,6 +70,19 @@ public interface UrlConstant {

String COURSE_TABEL_URL = BASE_URL + "/jsxsd/xskb/xskb_list.do";

/**
* 评教 url
*/


String EVALUATION_URL = BASE_URL + "/jsxsd/xspj/xspj_find.do";

/**
* 评教提交url
*/

String EVALUATION_COMMIT_URL = BASE_URL + "/jsxsd/xspj/xspj_save.do";




Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.yilin.csuftspider.exception.BusinessException;
import com.yilin.csuftspider.model.User;
import com.yilin.csuftspider.service.UserService;
import com.yilin.csuftspider.utils.IPUtil;
import com.yilin.csuftspider.utils.JsMachine;
import com.yilin.csuftspider.utils.Session;

Expand All @@ -20,10 +21,15 @@
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.data.redis.core.HyperLogLogOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;

/**
Expand All @@ -39,7 +45,8 @@
@Slf4j
public class UserServiceimpl implements UserService {


@Resource
RedisTemplate redisTemplate1;
@Override
public User login(String sid, String pwd, HttpServletRequest request) {

Expand Down Expand Up @@ -132,25 +139,35 @@ public User login(String sid, String pwd, HttpServletRequest request) {

resText = mySession.post(UrlConstant.LOGIN_URL,paramsMap);

//检查是否登陆成功
Document document1 = Jsoup.parse(resText);

Elements title = document1.getElementsByTag("title");

if(title == null || (!"中南林业科技大学 WebVPN".equals(title.get(0).text()))){

if("统一身份认证".equals(title.get(0).text())){

throw new BusinessException(ErrorCode.SYSTEM_ERROR,"学号或密码错误");
}
throw new BusinessException(ErrorCode.PARAMS_ERROR,"学校教务系统正在维护,请稍后再重试");

}

resText = mySession.get("http://jwgl.webvpn.csuft.edu.cn");
//请求失败
if(resText == null){

return null;
}
//检查是否登陆成功
Document document1 = Jsoup.parse(resText);
document1 = Jsoup.parse(resText);

Elements title = document1.getElementsByTag("title");
title = document1.getElementsByTag("title");

if(title == null || (!"学生个人中心".equals(title.get(0).text()))){

if("500错误".equals(title.get(0).text())){

throw new BusinessException(ErrorCode.SYSTEM_ERROR,"学校教务系统正在维护,请稍后再重试");
}

throw new BusinessException(ErrorCode.PARAMS_ERROR,"账号密码错误");
throw new BusinessException(ErrorCode.PARAMS_ERROR,"学校教务系统正在维护,请稍后再重试");
}


Expand All @@ -166,12 +183,22 @@ public User login(String sid, String pwd, HttpServletRequest request) {
//将mySession 和 User 信息 存入本次http请求session
HttpSession session = request.getSession();
session.setAttribute(USER_LOGIN_STATE,mySession);
log.info("登陆成功: "+strName + ",学号:"+ sid);


User user = new User(strName,sid);

session.setAttribute(USER_LOGIN_INFO,user);

//统计ip日活跃量
SimpleDateFormat sd = new SimpleDateFormat("yyyy-MM-dd");
String redisKey = String.format("com:yilin:csuftspider:dau:%s",sd.format(new Date()));
// String ipAdress = IPUtil.getIpAddress(request);
HyperLogLogOperations<String,String> hyperlog = redisTemplate1.opsForHyperLogLog();
hyperlog.add(redisKey,sid);
log.info("登陆成功: "+strName + ",学号:"+ sid);

log.info("今日活跃用户人数:" + hyperlog.size(redisKey).intValue());

return user;


Expand Down
58 changes: 56 additions & 2 deletions src/main/java/com/yilin/csuftspider/utils/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@



import javafx.util.Pair;
import lombok.extern.slf4j.Slf4j;

import org.apache.http.Consts;
Expand Down Expand Up @@ -51,7 +52,7 @@ public String get(String url) {
try {
HttpResponse response = httpClient.execute(httpGet);

return EntityUtils.toString(response.getEntity());
return EntityUtils.toString(response.getEntity(),"UTF-8");
} catch (IOException e) {
e.printStackTrace();
}
Expand All @@ -60,6 +61,8 @@ public String get(String url) {
return null;
}



//post 请求 自动处理重定向
public String post(String url, HashMap<String, String > paramsMap){

Expand Down Expand Up @@ -94,7 +97,56 @@ public String post(String url, HashMap<String, String > paramsMap){
httpGet.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36");
response = httpClient.execute(httpGet);
}
String res = EntityUtils.toString(response.getEntity());

String res = EntityUtils.toString(response.getEntity(),"UTF-8");



return res;

} catch (IOException e) {
e.printStackTrace();
}

return null;
}

//post 请求 自动处理重定向
public String postByOrderParams(String url, List<Pair<String,String>> lists){


List<NameValuePair> params = new ArrayList<>();


for(Pair<String,String> key:lists) {


params.add(new BasicNameValuePair(key.getKey(),key.getValue()));

}

HttpPost httpPost = new HttpPost(url);
httpPost.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36");

httpPost.setEntity(new UrlEncodedFormEntity(params, Consts.UTF_8));


try {
CloseableHttpResponse response = httpClient.execute(httpPost);


// 三次重定向 均是 get 请求
while (response.getStatusLine().getStatusCode() == 302) {

HttpGet httpGet;
Header header = response.getFirstHeader("location");
String newUri = header.getValue();
httpGet = new HttpGet(newUri);
httpGet.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36");
response = httpClient.execute(httpGet);
}

String res = EntityUtils.toString(response.getEntity(),"UTF-8");



Expand All @@ -106,6 +158,8 @@ public String post(String url, HashMap<String, String > paramsMap){

return null;
}


//获取图片验证码
public byte[] getYzm(String url) {
HttpGet httpGet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,8 @@ public static Info getInfo(List<Grade> list){
}

Double score = (gp*10.0) + 50.0;

//todo 判断score >=59.9
sumScore += score;
sumGp += gp * g.getCredit();
sumCredit += g.getCredit();
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ spring:
redis:
port: 6379 #端口号
password: #输入redis数据库密码
host: 127.0.0.1 #输入ip地址
host: 127.0.0.1 #输入ip地址

jedis:
pool:
Expand Down
Loading

0 comments on commit 9185c1f

Please sign in to comment.