redis 课堂纪律相关内容

11111
zhouj1203@hotmail.com 5 months ago
parent c9e7268d87
commit a801724b75

@ -71,6 +71,18 @@
<version>3.14.9</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.36</version>
</dependency>
<!-- 选择一个具体的日志实现例如Logback -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.11</version>
</dependency>
<!-- cosmos -->
<!-- <dependency>-->
<!-- <groupId>com.azure.spring</groupId>-->
@ -106,10 +118,20 @@
</dependency>
<!-- 修改后的jjwt -->
<dependency>
<!--<dependency>
<groupId>jsonwebtoken</groupId>
<artifactId>habook-jjwt</artifactId>
<version>0.0.1</version>
</dependency>-->
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.9.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
@ -131,6 +153,12 @@
<version>RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<!-- 指定依赖的作用范围 -->
<scope>test</scope>
</dependency>
</dependencies>
<!-- 私服 -->

@ -0,0 +1,13 @@
package cn.teammodel.config.ies;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
@Getter
@Configuration
public class IESConfig {
@Value("${ies.server-url}")
private String serverUrl;
}

@ -0,0 +1,34 @@
package cn.teammodel.config.redis;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
@Configuration
public class RedisConfig {
@Bean
public LettuceConnectionFactory dbConnectionFactory() {
RedisStandaloneConfiguration config = new RedisStandaloneConfiguration("52.130.252.100", 6379);
config.setDatabase(8); // 设置数据库编号为8
config.setPassword("habook");
return new LettuceConnectionFactory(config);
}
@Bean
public StringRedisTemplate db1Template(LettuceConnectionFactory dbConnectionFactory) {
StringRedisTemplate template = new StringRedisTemplate();
template.setConnectionFactory(dbConnectionFactory);
template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new GenericJackson2JsonRedisSerializer());
return template;
}
}

@ -4,19 +4,25 @@ import cn.teammodel.common.R;
import cn.teammodel.controller.admin.service.AdminIndexDutyService;
import cn.teammodel.model.dto.admin.appraise.TimeRangeDto;
import cn.teammodel.model.dto.admin.weekduty.AdminFindDutyRecordDto;
import cn.teammodel.model.dto.weekDuty.LessonRecordDto;
import cn.teammodel.model.vo.admin.AppraiseNodeRankVo;
import cn.teammodel.model.vo.admin.DutyIndexData;
import cn.teammodel.model.vo.admin.DutyNodeRankVo;
import cn.teammodel.model.vo.admin.DutyRankPo;
import cn.teammodel.model.vo.weekDuty.DutyRecordVo;
import cn.teammodel.service.DutyService;
import com.google.gson.JsonElement;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;
import java.util.Map;
/**
* @author winter
@ -65,4 +71,10 @@ public class AdminDutyController {
List<DutyNodeRankVo> res = adminIndexDutyService.appraiseNodeRank(timeRangeDto);
return R.success(res);
}
@PostMapping("getLessonRecord")
@ApiOperation("获取课堂记录")
public R<Map<String, Object> > appraiseNodeRank(@Valid @RequestBody Map<String, Object> map , HttpServletRequest request) {
Map<String, Object> res = adminIndexDutyService.getLessonRecord(map,request);
return R.success(res);
}
}

@ -0,0 +1,26 @@
package cn.teammodel.controller.admin.controller;
import cn.teammodel.common.R;
import cn.teammodel.test.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.Map;
@RestController
@RequestMapping("/test")
public class RedisController {
private final RedisService redisService;
@Autowired
public RedisController(RedisService redisService) {
this.redisService = redisService;
}
@PostMapping("/redis")
public Map<Object, Object> getValueByKey(@RequestBody @Valid String key) {
Map<Object,Object> juri = redisService.getValueByKey(key);
return R.success(juri).getData();
}
}

@ -1,11 +1,15 @@
package cn.teammodel.controller.admin.service;
import cn.teammodel.model.dto.admin.appraise.TimeRangeDto;
import cn.teammodel.model.dto.weekDuty.LessonRecordDto;
import cn.teammodel.model.vo.admin.DutyIndexData;
import cn.teammodel.model.vo.admin.DutyNodeRankVo;
import cn.teammodel.model.vo.admin.DutyRankPo;
import com.google.gson.JsonElement;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
/**
* @author winter
@ -19,4 +23,7 @@ public interface AdminIndexDutyService {
List<DutyRankPo> teacherRank(TimeRangeDto timeRangeDto);
List<DutyNodeRankVo> appraiseNodeRank(TimeRangeDto timeRangeDto);
Map<String, Object> getLessonRecord (Map<String, Object> map, HttpServletRequest request);
}

@ -3,8 +3,10 @@ package cn.teammodel.controller.admin.service.impl;
import cn.teammodel.common.ErrorCode;
import cn.teammodel.common.PK;
import cn.teammodel.config.exception.ServiceException;
import cn.teammodel.config.ies.IESConfig;
import cn.teammodel.controller.admin.service.AdminIndexDutyService;
import cn.teammodel.model.dto.admin.appraise.TimeRangeDto;
import cn.teammodel.model.dto.weekDuty.LessonRecordDto;
import cn.teammodel.model.entity.User;
import cn.teammodel.model.entity.school.ClassInfo;
import cn.teammodel.model.entity.school.School;
@ -21,12 +23,31 @@ import cn.teammodel.repository.TeacherRepository;
import cn.teammodel.security.utils.SecurityUtil;
import cn.teammodel.utils.SchoolDateUtil;
import com.azure.spring.data.cosmos.core.query.CosmosPageRequest;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.TypeFactory;
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import lombok.var;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.data.domain.Slice;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.*;
@ -39,6 +60,7 @@ import static cn.teammodel.utils.SchoolDateUtil.calculateWeekNum;
* @create 2024-02-28 15:07
*/
@Service
@Slf4j
public class AdminIndexDutyServiceImpl implements AdminIndexDutyService {
@Resource
@ -52,6 +74,13 @@ public class AdminIndexDutyServiceImpl implements AdminIndexDutyService {
@Resource
private DutyRecordRepository dutyRecordRepository;
private final Environment env;
@Autowired
public AdminIndexDutyServiceImpl(Environment env) {
this.env = env;
}
@Override
public DutyIndexData getIndexData(String periodId) {
User loginUser = SecurityUtil.getLoginUser();
@ -193,4 +222,48 @@ public class AdminIndexDutyServiceImpl implements AdminIndexDutyService {
}
@Override
public Map<String, Object> getLessonRecord(Map<String, Object> map, HttpServletRequest request) {
Map<String, Object> mapper = new HashMap<>();
String apiUrl = env.getProperty("ies.server-url");
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
// 创建HttpPost对象
HttpPost httpPost = new HttpPost(apiUrl);
// 添加请求头
httpPost.setHeader("Authorization", request.getHeader("Authorization"));
httpPost.setHeader("X-Auth-Authtoken", request.getHeader("X-Auth-Authtoken"));
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-Type", "application/json; charset=utf-8");
// 设置请求体
//String requestBody = String.format("{\"school\":\"%s\"}","{\"name\":\"%s\"}","{\"periodId\":\"%s\"}", code,name,periodId);
httpPost.setEntity(new StringEntity(new Gson().toJson(map)));
// 发送请求
try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
// 获取响应实体
HttpEntity entity = response.getEntity();
if (entity != null) {
// 解析响应内容
String jsonString = EntityUtils.toString(entity);
ObjectMapper objectMapper = new ObjectMapper();
mapper = objectMapper.readValue(jsonString, TypeFactory.defaultInstance().constructMapType(Map.class, String.class, Object.class));
}
// 检查响应状态码
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != 200) throw new RuntimeException("Failed : HTTP error code : " + statusCode);
} catch (IOException e) {
log.error("Failed : HTTP error code : {}", e.getMessage());
}
} catch (IOException e) {
log.error("Failed : HTTP error code : {}", e.getMessage());
}
return mapper;
}
}

@ -0,0 +1,15 @@
package cn.teammodel.model.dto.weekDuty;
import lombok.Data;
@Data
public class LessonRecordDto {
private String code;
private String name;
private String periodId;
private Long startTime;
private Long endTime;
private String Authorization;
private String AuthToken;
private String continuationToken;
}

@ -0,0 +1,21 @@
package cn.teammodel.test;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
/*@Component
public class ConfigCheck implements CommandLineRunner {
@Value("${spring.redis.host}")
private String redisHost;
@Value("${spring.redis.port}")
private int redisPort;
@Override
public void run(String... args) throws Exception {
System.out.println("Redis Host: " + redisHost);
System.out.println("Redis Port: " + redisPort);
}
}*/

@ -0,0 +1,30 @@
package cn.teammodel.test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import java.util.Map;
@Service
public class RedisService {
private final StringRedisTemplate redisTemplate;
@Autowired
public RedisService(StringRedisTemplate redisTemplate) {
this.redisTemplate = redisTemplate;
}
public void setKeyValue(String key, String value) {
//ruredisTemplate.slaveOf();
redisTemplate.opsForValue().set(key, value);
}
public Map<Object, Object> getValueByKey(String key) {
System.out.println(redisTemplate.opsForHash().values("ArtArea:area:primary"));
return redisTemplate.opsForHash().entries("ArtArea:area:junior");
}
}

@ -1,4 +1,14 @@
spring:
# redis:
# dabase: 9
# host: 52.130.252.100
# port: 6379
# password: habook
# ssl: false
# abort_connection: false
# write_timeout: 10240
env: dev
mvc:
pathmatch:
@ -38,6 +48,10 @@ spark:
jwt:
secret: fXO6ko/qyXeYrkecPeKdgXnuLXf9vMEtnBC9OB3s+aA=
# 钉钉 webhook
ding:
server-url: https://oapi.dingtalk.com/robot/send?access_token=32d9b24f69c2c4fd7c2dab43268b6258a7214d2620e0805d7b6d1429003b64b6
#IES 课堂记录
ies:
server-url: https://www.teammodel.cn/common/lesson-record/get-lesson-record
Loading…
Cancel
Save