Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

setup: 论文评审系统初始化 #132

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
171 changes: 15 additions & 156 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,83 +8,20 @@
<version>2.3.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.softeng</groupId>
<artifactId>dingtalk</artifactId>
<groupId>cn.nju.edu.software</groupId>
<artifactId>thesis-review-system-server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>dingtalk</name>
<description>Demo project for dingtalk mini program</description>

<name>thesis-review-system-server</name>
<description>thesis-review-system-server</description>
<properties>
<java.version>11</java.version>
<java.version>8</java.version>
</properties>

<distributionManagement>
<repository>
<id>github</id>
<name>GitHub zhanyeye Apache Maven Packages</name>
<url>https://maven.pkg.github.com/zhanyeye/dingtalk-springboot</url>
</repository>
</distributionManagement>

<dependencies>

<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.83</version>
</dependency>

<!-- swagger 3 -->
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>3.0.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0</version>
</dependency>

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
<!-- swagger 3 -->

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.2</version>
</dependency>

<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.1.11</version>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
Expand All @@ -95,29 +32,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-crypto</artifactId>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-hibernate5</artifactId>
<version>2.9.7</version>
</dependency>

<!-- 钉钉旧版服务端SDK -->
Expand All @@ -131,84 +45,29 @@
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>dingtalk</artifactId>
<version>1.2.8</version>
</dependency>

<!-- https://mvnrepository.com/artifact/com.alibaba/easyexcel -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>2.2.10</version>
</dependency>


<!-- SpringWebSocket依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>

<!-- cache 依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-cache</artifactId>
<version>1.5.46</version>
</dependency>

<!-- cache -->
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
</dependency>

<!-- https://mvnrepository.com/artifact/javax.validation/validation-api -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>

<!-- https://mvnrepository.com/artifact/org.hyperledger.fabric-sdk-java/fabric-sdk-java -->
<dependency>
<groupId>org.hyperledger.fabric-sdk-java</groupId>
<artifactId>fabric-sdk-java</artifactId>
<version>1.4.7</version>
</dependency>


<dependency>
<groupId>com.aliyun.oss</groupId>
<artifactId>aliyun-sdk-oss</artifactId>
<version>3.8.0</version>
</dependency>

<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>2.0.0</version>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
<dependency>
<groupId>org.databene</groupId>
<artifactId>contiperf</artifactId>
<version>2.3.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
<version>2.2.6.RELEASE</version>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package cn.nju.edu.software.thesisreviewsystemserver;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;

@EnableCaching
@SpringBootApplication
public class ThesisReviewSystemServerApplication {

public static void main(String[] args) {
SpringApplication.run(ThesisReviewSystemServerApplication.class, args);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package cn.nju.edu.software.thesisreviewsystemserver.component.dingApi;

import lombok.Getter;

@Getter
public enum DingApiUrlEnum {
GET_USER_INFO("https://oapi.dingtalk.com/user/getuserinfo");

private String url;
DingApiUrlEnum(String url) {
this.url = url;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package cn.nju.edu.software.thesisreviewsystemserver.component.dingApi;

import com.aliyun.dingtalkoauth2_1_0.Client;
import com.aliyun.tea.*;
import com.aliyun.teautil.*;
import com.aliyun.teaopenapi.models.*;
import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiUserGetuserinfoRequest;
import com.dingtalk.api.response.OapiUserGetuserinfoResponse;
import com.github.benmanes.caffeine.cache.Cache;
import com.taobao.api.ApiException;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.Resource;

@Slf4j
public class DingBaseApi {

protected String corpId; // 钉钉组织的唯一id

protected String appKey; // 钉钉微应用的 key

protected String appSecret; // 钉钉微应用的密钥

@Resource
Cache<String, String> cache;

/**
* 使用 Token 初始化账号Client
* @return Client
* @throws Exception
*/
public Client createClient() throws Exception {
Config config = new Config();
config.protocol = "https";
config.regionId = "central";
return new Client(config);
}

public String getAccessToken() throws Exception {
String res = cache.asMap().get("AccessToken");
if(res == null) {
Client client = this.createClient();
com.aliyun.dingtalkoauth2_1_0.models.GetAccessTokenRequest getAccessTokenRequest = new com.aliyun.dingtalkoauth2_1_0.models.GetAccessTokenRequest()
.setAppKey(appKey)
.setAppSecret(appSecret);
try {
res = client.getAccessToken(getAccessTokenRequest).body.getAccessToken();
} catch (TeaException err) {
if (!Common.empty(err.code) && !Common.empty(err.message)) {
// err 中含有 code 和 message 属性,可帮助开发定位问题
log.error(err.code + " " + err.message);
}
} catch (Exception _err) {
TeaException err = new TeaException(_err.getMessage(), _err);
if (!Common.empty(err.code) && !Common.empty(err.message)) {
// err 中含有 code 和 message 属性,可帮助开发定位问题
log.error(err.code + " " + err.message);
}
}
}
return res;
}

public String getUserId(String requestAuthCode) throws Exception {
DingTalkClient client = new DefaultDingTalkClient(DingApiUrlEnum.GET_USER_INFO.getUrl());
OapiUserGetuserinfoRequest request = new OapiUserGetuserinfoRequest();
request.setCode(requestAuthCode);
request.setHttpMethod("GET");
OapiUserGetuserinfoResponse response;
try {
response = client.execute(request, this.getAccessToken());
} catch (ApiException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
return response.getUserid();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cn.nju.edu.software.thesisreviewsystemserver.component.dingApi;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class DingExpertGroupApi extends DingBaseApi{
@Value("${expertGroup.corpId}")
public void setCorID(String corpId) {
this.corpId = corpId;
}

@Value("${expertGroup.app_key}")
public void setAppKey(String appKey) {
this.appKey = appKey;
}

@Value("${expertGroup.app_secret}")
public void setAppSecret(String appSecret) {
this.appSecret = appSecret;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cn.nju.edu.software.thesisreviewsystemserver.component.dingApi;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class DingStudentGroupApi extends DingExpertGroupApi{
@Value("${studentGroup.corpId}")
public void setCorID(String corpId) {
this.corpId = corpId;
}

@Value("${studentGroup.app_key}")
public void setAppKey(String appKey) {
this.appKey = appKey;
}

@Value("${studentGroup.app_secret}")
public void setAppSecret(String appSecret) {
this.appSecret = appSecret;
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package com.softeng.dingtalk.config;
package cn.nju.edu.software.thesisreviewsystemserver.config;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.caffeine.CaffeineCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

@Configuration
public class CacheConfig {

/**
* Caffeine 缓存
* @return
Expand All @@ -21,4 +19,4 @@ public Cache<String, String> caffeineCache() {
return Caffeine.newBuilder().expireAfterWrite(60 * 55 * 2, TimeUnit.SECONDS)
.maximumSize(100).build();
}
}
}
Loading