redis 课堂纪律相关内容

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

@ -71,6 +71,18 @@
<version>3.14.9</version> <version>3.14.9</version>
</dependency> </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 --> <!-- cosmos -->
<!-- <dependency>--> <!-- <dependency>-->
<!-- <groupId>com.azure.spring</groupId>--> <!-- <groupId>com.azure.spring</groupId>-->
@ -106,10 +118,20 @@
</dependency> </dependency>
<!-- 修改后的jjwt --> <!-- 修改后的jjwt -->
<dependency> <!--<dependency>
<groupId>jsonwebtoken</groupId> <groupId>jsonwebtoken</groupId>
<artifactId>habook-jjwt</artifactId> <artifactId>habook-jjwt</artifactId>
<version>0.0.1</version> <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> </dependency>
@ -131,6 +153,12 @@
<version>RELEASE</version> <version>RELEASE</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<!-- 指定依赖的作用范围 -->
<scope>test</scope>
</dependency>
</dependencies> </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.controller.admin.service.AdminIndexDutyService;
import cn.teammodel.model.dto.admin.appraise.TimeRangeDto; import cn.teammodel.model.dto.admin.appraise.TimeRangeDto;
import cn.teammodel.model.dto.admin.weekduty.AdminFindDutyRecordDto; 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.AppraiseNodeRankVo;
import cn.teammodel.model.vo.admin.DutyIndexData; import cn.teammodel.model.vo.admin.DutyIndexData;
import cn.teammodel.model.vo.admin.DutyNodeRankVo; import cn.teammodel.model.vo.admin.DutyNodeRankVo;
import cn.teammodel.model.vo.admin.DutyRankPo; import cn.teammodel.model.vo.admin.DutyRankPo;
import cn.teammodel.model.vo.weekDuty.DutyRecordVo; import cn.teammodel.model.vo.weekDuty.DutyRecordVo;
import cn.teammodel.service.DutyService; import cn.teammodel.service.DutyService;
import com.google.gson.JsonElement;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; 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 org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid; import javax.validation.Valid;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* @author winter * @author winter
@ -65,4 +71,10 @@ public class AdminDutyController {
List<DutyNodeRankVo> res = adminIndexDutyService.appraiseNodeRank(timeRangeDto); List<DutyNodeRankVo> res = adminIndexDutyService.appraiseNodeRank(timeRangeDto);
return R.success(res); 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; package cn.teammodel.controller.admin.service;
import cn.teammodel.model.dto.admin.appraise.TimeRangeDto; 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.DutyIndexData;
import cn.teammodel.model.vo.admin.DutyNodeRankVo; import cn.teammodel.model.vo.admin.DutyNodeRankVo;
import cn.teammodel.model.vo.admin.DutyRankPo; import cn.teammodel.model.vo.admin.DutyRankPo;
import com.google.gson.JsonElement;
import javax.servlet.http.HttpServletRequest;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* @author winter * @author winter
@ -19,4 +23,7 @@ public interface AdminIndexDutyService {
List<DutyRankPo> teacherRank(TimeRangeDto timeRangeDto); List<DutyRankPo> teacherRank(TimeRangeDto timeRangeDto);
List<DutyNodeRankVo> appraiseNodeRank(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.ErrorCode;
import cn.teammodel.common.PK; import cn.teammodel.common.PK;
import cn.teammodel.config.exception.ServiceException; import cn.teammodel.config.exception.ServiceException;
import cn.teammodel.config.ies.IESConfig;
import cn.teammodel.controller.admin.service.AdminIndexDutyService; import cn.teammodel.controller.admin.service.AdminIndexDutyService;
import cn.teammodel.model.dto.admin.appraise.TimeRangeDto; 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.User;
import cn.teammodel.model.entity.school.ClassInfo; import cn.teammodel.model.entity.school.ClassInfo;
import cn.teammodel.model.entity.school.School; 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.security.utils.SecurityUtil;
import cn.teammodel.utils.SchoolDateUtil; import cn.teammodel.utils.SchoolDateUtil;
import com.azure.spring.data.cosmos.core.query.CosmosPageRequest; 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.ObjectUtils;
import org.apache.commons.lang3.StringUtils; 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.data.domain.Slice;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.*; import java.util.*;
@ -39,6 +60,7 @@ import static cn.teammodel.utils.SchoolDateUtil.calculateWeekNum;
* @create 2024-02-28 15:07 * @create 2024-02-28 15:07
*/ */
@Service @Service
@Slf4j
public class AdminIndexDutyServiceImpl implements AdminIndexDutyService { public class AdminIndexDutyServiceImpl implements AdminIndexDutyService {
@Resource @Resource
@ -52,6 +74,13 @@ public class AdminIndexDutyServiceImpl implements AdminIndexDutyService {
@Resource @Resource
private DutyRecordRepository dutyRecordRepository; private DutyRecordRepository dutyRecordRepository;
private final Environment env;
@Autowired
public AdminIndexDutyServiceImpl(Environment env) {
this.env = env;
}
@Override @Override
public DutyIndexData getIndexData(String periodId) { public DutyIndexData getIndexData(String periodId) {
User loginUser = SecurityUtil.getLoginUser(); 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,43 +1,57 @@
spring: spring:
env: dev # redis:
mvc: # dabase: 9
pathmatch: # host: 52.130.252.100
matching-strategy: ant_path_matcher # port: 6379
# password: habook
# 文件上传 # ssl: false
servlet: # abort_connection: false
multipart: # write_timeout: 10240
# 大小限制
max-file-size: 10MB
env: dev
cloud: mvc:
azure: pathmatch:
cosmos: matching-strategy: ant_path_matcher
endpoint: https://cdhabookdep-free.documents.azure.cn:443
database: TEAMModelOS # 文件上传
key: JTUVk92Gjsx17L0xqxn0X4wX2thDPMKiw4daeTyV1HzPb6JmBeHdtFY1MF1jdctW1ofgzqkDMFOtcqS46by31A== servlet:
populate-query-metrics: true multipart:
# 大小限制
security: max-file-size: 10MB
oauth2:
resourceserver: cloud:
jwt: azure:
issuer-uri: https://login.partner.microsoftonline.cn/4807e9cf-87b8-4174-aa5b-e76497d7392b/v2.0 cosmos:
audiences: 72643704-b2e7-4b26-b881-bd5865e7a7a5 endpoint: https://cdhabookdep-free.documents.azure.cn:443
database: TEAMModelOS
spark: key: JTUVk92Gjsx17L0xqxn0X4wX2thDPMKiw4daeTyV1HzPb6JmBeHdtFY1MF1jdctW1ofgzqkDMFOtcqS46by31A==
gpt: populate-query-metrics: true
endpoint: https://spark-api.xf-yun.com/v3.1/chat
appId: c49d1e24 security:
apiKey: 6c586e7dd1721ed1bb19bdb573b4ad34 oauth2:
apiSecret: MDU1MTU1Nzg4MDg2ZTJjZWU3MmI4ZGU1 resourceserver:
cache_timeout: 1800000 # 30min jwt:
cache_context: 3 issuer-uri: https://login.partner.microsoftonline.cn/4807e9cf-87b8-4174-aa5b-e76497d7392b/v2.0
audiences: 72643704-b2e7-4b26-b881-bd5865e7a7a5
jwt: spark:
secret: fXO6ko/qyXeYrkecPeKdgXnuLXf9vMEtnBC9OB3s+aA= gpt:
endpoint: https://spark-api.xf-yun.com/v3.1/chat
# 钉钉 webhook appId: c49d1e24
ding: apiKey: 6c586e7dd1721ed1bb19bdb573b4ad34
server-url: https://oapi.dingtalk.com/robot/send?access_token=32d9b24f69c2c4fd7c2dab43268b6258a7214d2620e0805d7b6d1429003b64b6 apiSecret: MDU1MTU1Nzg4MDg2ZTJjZWU3MmI4ZGU1
cache_timeout: 1800000 # 30min
cache_context: 3
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