Browse Source

first-commit

master
luoweijian 1 month ago
commit
31c7245356
  1. 38
      .gitignore
  2. 8
      .idea/.gitignore
  3. 7
      .idea/encodings.xml
  4. 14
      .idea/misc.xml
  5. 124
      .idea/uiDesigner.xml
  6. 139
      pom.xml
  7. 17
      src/main/java/com/project/AiEvaluatorApplication.java
  8. 21
      src/main/java/com/project/base/config/CorsConfig.java
  9. 39
      src/main/java/com/project/base/config/CustomIdGenerator.java
  10. 28
      src/main/java/com/project/base/config/MyMetaObjectHandler.java
  11. 185
      src/main/java/com/project/base/config/SnowflakeIdWorker.java
  12. 90
      src/main/java/com/project/base/domain/advice/GlobalExceptionHandlerAdvice.java
  13. 23
      src/main/java/com/project/base/domain/dto/BaseDTO.java
  14. 50
      src/main/java/com/project/base/domain/entity/BaseEntity.java
  15. 24
      src/main/java/com/project/base/domain/enums/HasValueEnum.java
  16. 17
      src/main/java/com/project/base/domain/enums/StatusEnum.java
  17. 21
      src/main/java/com/project/base/domain/exception/BusinessErrorException.java
  18. 21
      src/main/java/com/project/base/domain/exception/MissingParameterException.java
  19. 21
      src/main/java/com/project/base/domain/exception/ResourceNotExistException.java
  20. 63
      src/main/java/com/project/base/domain/result/Result.java
  21. 41
      src/main/java/com/project/base/domain/result/ResultCodeEnum.java
  22. 199
      src/main/java/com/project/base/domain/utils/TreeUtils.java
  23. 23
      src/main/java/com/project/ding/config/DingConfig.java
  24. 39
      src/main/java/com/project/ding/controller/DepartmentController.java
  25. 13
      src/main/java/com/project/ding/domain/dto/DepartmentDTO.java
  26. 67
      src/main/java/com/project/ding/domain/dto/DingUserDTO.java
  27. 9
      src/main/java/com/project/ding/domain/dto/UserDTO.java
  28. 27
      src/main/java/com/project/ding/domain/entity/DepartmentEntity.java
  29. 71
      src/main/java/com/project/ding/utils/DingUtil.java
  30. 39
      src/main/resources/application.yml

38
.gitignore

@ -0,0 +1,38 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

8
.idea/.gitignore

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

7
.idea/encodings.xml

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
</component>
</project>

14
.idea/misc.xml

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

124
.idea/uiDesigner.xml

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.svg" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.svg" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.svg" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.svg" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>

139
pom.xml

@ -0,0 +1,139 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.3</version>
<relativePath/>
</parent>
<groupId>com.project</groupId>
<artifactId>ai-evaluator</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>ai-evaluator</name>
<properties>
<java.version>17</java.version>
<!-- spring Boot -->
<spring-boot.version>3.0.0</spring-boot.version>
<!-- 数据库 & ORM -->
<mysql.version>8.0.29</mysql.version>
<druid.version>1.2.20</druid.version>
<mybatis-plus.version>3.5.5</mybatis-plus.version>
<!-- minio -->
<minio.version>8.0.3</minio.version>
<okhttp3.version>4.8.1</okhttp3.version>
<spring.boot.test.version>3.0.13</spring.boot.test.version>
<lombok.version>1.18.30</lombok.version>
</properties>
<dependencies>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring-boot.version}</version>
<exclusions>
<exclusion>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
</exclusion>
<exclusion>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-client</artifactId>
</exclusion>
<exclusion>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.github.tingyugetc520</groupId>
<artifactId>dt-java</artifactId>
<version>0.1.2</version>
</dependency>
<dependency>
<groupId>io.vavr</groupId>
<artifactId>vavr</artifactId>
<version>0.10.4</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.6</version>
<exclusions>
<exclusion>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.3</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>dynamic-datasource-spring-boot3-starter</artifactId>
<version>4.2.0</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>3.0.3</version>
</dependency>
<dependency>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-core</artifactId>
<version>6.4.4.Final</version>
</dependency>
</dependencies>
</project>

17
src/main/java/com/project/AiEvaluatorApplication.java

@ -0,0 +1,17 @@
package com.project;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableAsync;
@SpringBootApplication
@EnableAsync
@MapperScan({
"com.project.*.mapper"})
public class AiEvaluatorApplication {
public static void main( String[] args ) {
SpringApplication.run(AiEvaluatorApplication.class , args);
}
}

21
src/main/java/com/project/base/config/CorsConfig.java

@ -0,0 +1,21 @@
package com.project.base.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* Cors解决跨域问题
*/
@Configuration
public class CorsConfig implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins("*")
.allowedMethods("GET", "POST", "Options", "DELETE", "PUT")
.allowedHeaders("*")
.allowCredentials(false)
.maxAge(16800);
}
}

39
src/main/java/com/project/base/config/CustomIdGenerator.java

@ -0,0 +1,39 @@
package com.project.base.config;
import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.concurrent.atomic.AtomicLong;
/**
* 自定义ID生成器
*/
@Slf4j
@Component
public class CustomIdGenerator implements IdentifierGenerator {
/**
* workerId机器id
* datacenterId数据标识id
*/
private final SnowflakeIdWorker idWorker = new SnowflakeIdWorker(0, 0);
/**
* AtomicLong是作用是对长整形进行原子操作
* 在32位操作系统中64位的long double 变量由于会被JVM当作两个分离的32位来进行操作所以不具有原子性
* 而使用AtomicLong能让long的操作保持原子型
* @param entity
* @return
*/
@Override
public Long nextId(Object entity) {
//可以将当前传入的class全类名来作为bizKey,或者提取参数来生成bizKey进行分布式Id调用生成.
String bizKey = entity.getClass().getName();
log.debug("bizKey:{}", bizKey);
AtomicLong al = new AtomicLong(idWorker.nextId());
final long id = al.get();
log.debug("为{}生成主键值->:{}", bizKey, id);
return id;
}
}

28
src/main/java/com/project/base/config/MyMetaObjectHandler.java

@ -0,0 +1,28 @@
package com.project.base.config;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;
import java.util.Date;
@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {
@Override
public void insertFill(MetaObject metaObject) {
long timeMillis = System.currentTimeMillis() / 1000 * 1000;
Date currentDate = new Date(timeMillis);
this.strictInsertFill(metaObject, "createTime", Date.class, currentDate); // 起始版本 3.3.0(推荐使用)
this.strictInsertFill(metaObject, "updateTime", Date.class, currentDate);
}
@Override
public void updateFill(MetaObject metaObject) {
long timeMillis = System.currentTimeMillis() / 1000 * 1000;
Date currentDate = new Date(timeMillis);
this.strictUpdateFill(metaObject, "updateTime", Date.class, currentDate); // 起始版本 3.3.0(推荐使用)
}
}

185
src/main/java/com/project/base/config/SnowflakeIdWorker.java

@ -0,0 +1,185 @@
package com.project.base.config;
/**
* Twitter_Snowflake<br>
* SnowFlake的结构如下(每部分用-分开):<br>
* 0 - 0000000000 0000000000 0000000000 0000000000 0 - 00000 - 00000 - 000000000000 <br>
* 1位标识由于long基本类型在Java中是带符号的最高位是符号位正数是0负数是1所以id一般是正数最高位是0<br>
* 41位时间截(毫秒级)注意41位时间截不是存储当前时间的时间截而是存储时间截的差值当前时间截 - 开始时间截)
* 得到的值这里的的开始时间截一般是我们的id生成器开始使用的时间由我们程序来指定的如下下面程序IdWorker类的startTime属性41位的时间截可以使用69年年T = (1L << 41) / (1000L * 60 * 60 * 24 * 365) = 69<br>
* 10位的数据机器位可以部署在1024个节点包括5位datacenterId和5位workerId<br>
* 12位序列毫秒内的计数12位的计数顺序号支持每个节点每毫秒(同一机器同一时间截)产生4096个ID序号<br>
* 加起来刚好64位为一个Long型<br>
* SnowFlake的优点是整体上按照时间自增排序并且整个分布式系统内不会产生ID碰撞(由数据中心ID和机器ID作区分)并且效率较高经测试SnowFlake每秒能够产生26万ID左右
*/
public class SnowflakeIdWorker {
// ==============================Fields===========================================
/**
* 1766395305
* 开始时间截 2021-01-01 00:00:00
* https://tool.lu/timestamp/
*/
private static final long twepoch = 1609430400000L;
/**
* 机器id所占的位数
*/
private static final long workerIdBits = 5L;
/**
* 数据标识id所占的位数
*/
private static final long datacenterIdBits = 5L;
/**
* 支持的最大机器id结果是31 (这个移位算法可以很快的计算出几位二进制数所能表示的最大十进制数)
*/
private static final long maxWorkerId = -1L ^ (-1L << workerIdBits);
/**
* 支持的最大数据标识id结果是31
*/
private static final long maxDatacenterId = -1L ^ (-1L << datacenterIdBits);
/**
* 序列在id中占的位数
*/
private static final long sequenceBits = 12L;
/**
* 机器ID向左移12位
*/
private static final long workerIdShift = sequenceBits;
/**
* 数据标识id向左移17位(12+5)
*/
private static final long datacenterIdShift = sequenceBits + workerIdBits;
/**
* 时间截向左移22位(5+5+12)
*/
private static final long timestampLeftShift = sequenceBits + workerIdBits + datacenterIdBits;
/**
* 生成序列的掩码这里为4095 (0b111111111111=0xfff=4095)
*/
private static final long sequenceMask = -1L ^ (-1L << sequenceBits);
/**
* 工作机器ID(0~31)
*/
private long workerId;
/**
* 数据中心ID(0~31)
*/
private long datacenterId;
/**
* 毫秒内序列(0~4095)
*/
private long sequence = 0L;
/**
* 上次生成ID的时间截
*/
private long lastTimestamp = -1L;
//==============================Constructors=====================================
/**
* 构造函数
*
* @param workerId 工作ID (0~31)
* @param datacenterId 数据中心ID (0~31)
*/
public SnowflakeIdWorker(long workerId, long datacenterId) {
if (workerId > maxWorkerId || workerId < 0) {
throw new IllegalArgumentException(String.format("worker Id can't be greater than %d or less than 0", maxWorkerId));
}
if (datacenterId > maxDatacenterId || datacenterId < 0) {
throw new IllegalArgumentException(String.format("datacenter Id can't be greater than %d or less than 0", maxDatacenterId));
}
this.workerId = workerId;
this.datacenterId = datacenterId;
}
// ==============================Methods==========================================
/**
* 获得下一个ID (该方法是线程安全的)
*
* @return SnowflakeId
*/
public synchronized long nextId() {
long timestamp = timeGen();
//如果当前时间小于上一次ID生成的时间戳,说明系统时钟回退过这个时候应当抛出异常
if (timestamp < lastTimestamp) {
throw new RuntimeException(
String.format("Clock moved backwards. Refusing to generate id for %d milliseconds", lastTimestamp - timestamp));
}
//如果是同一时间生成的,则进行毫秒内序列
if (lastTimestamp == timestamp) {
sequence = (sequence + 1) & sequenceMask;
//毫秒内序列溢出
if (sequence == 0) {
//阻塞到下一个毫秒,获得新的时间戳
timestamp = tilNextMillis(lastTimestamp);
}
}
//时间戳改变,毫秒内序列重置
else {
sequence = 0L;
}
//上次生成ID的时间截
lastTimestamp = timestamp;
//移位并通过或运算拼到一起组成64位的ID
return ((timestamp - twepoch) << timestampLeftShift) //
| (datacenterId << datacenterIdShift) //
| (workerId << workerIdShift) //
| sequence;
}
/**
* 阻塞到下一个毫秒直到获得新的时间戳
*
* @param lastTimestamp 上次生成ID的时间截
* @return 当前时间戳
*/
protected long tilNextMillis(long lastTimestamp) {
long timestamp = timeGen();
while (timestamp <= lastTimestamp) {
timestamp = timeGen();
}
return timestamp;
}
/**
* 返回以毫秒为单位的当前时间
*
* @return 当前时间(毫秒)
*/
protected long timeGen() {
return System.currentTimeMillis();
}
//==============================Test=============================================
/**
* 测试
*/
public static void main(String[] args) {
SnowflakeIdWorker idWorker = new SnowflakeIdWorker(0, 0);
for (int i = 0; i < 1000; i++) {
long id = idWorker.nextId();
System.out.println(Long.toBinaryString(id));
System.out.println(id);
}
}
}

90
src/main/java/com/project/base/domain/advice/GlobalExceptionHandlerAdvice.java

@ -0,0 +1,90 @@
package com.project.base.domain.advice;
import com.project.base.domain.exception.BusinessErrorException;
import com.project.base.domain.exception.MissingParameterException;
import com.project.base.domain.exception.ResourceNotExistException;
import com.project.base.domain.result.Result;
import com.project.base.domain.result.ResultCodeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.validation.BindException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
import org.springframework.web.multipart.MaxUploadSizeExceededException;
@Slf4j
@ControllerAdvice
public class GlobalExceptionHandlerAdvice {
/**-------- 其他错误 --------**/
@ExceptionHandler(Exception.class)
@ResponseBody
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public Result error(Exception e) {
e.printStackTrace();
log.error("全局异常捕获:" + e);
return Result.fail();
}
/**-------- 前端传参类型转换错误 --------**/
@ExceptionHandler(BindException.class)
@ResponseBody
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public Result error(BindException e) {
e.printStackTrace();
log.error("全局异常捕获:" + e);
return Result.fail(ResultCodeEnum.MISSING_PARAMETER);
}
@ExceptionHandler(MethodArgumentTypeMismatchException.class)
@ResponseBody
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public Result error(MethodArgumentTypeMismatchException e) {
e.printStackTrace();
log.error("全局异常捕获:" + e);
return Result.fail(ResultCodeEnum.MISSING_PARAMETER);
}
/**-------- 业务错误 --------**/
@ExceptionHandler(BusinessErrorException.class)
@ResponseBody
@ResponseStatus(HttpStatus.OK)
public Result error(BusinessErrorException e) {
e.printStackTrace();
log.error("全局异常捕获:" + e);
return Result.fail(ResultCodeEnum.BUSINESS_ERROR , e.getMessage());
}
/**-------- 缺少必须参数 --------**/
@ExceptionHandler(MissingParameterException.class)
@ResponseBody
@ResponseStatus(HttpStatus.OK)
public Result error(MissingParameterException e) {
e.printStackTrace();
log.error("全局异常捕获:" + e);
return Result.fail(ResultCodeEnum.getResultCodeEnumByCode(e.getCode()) , e.getMessage());
}
@ExceptionHandler(ResourceNotExistException.class)
@ResponseBody
@ResponseStatus(HttpStatus.OK)
public Result error(ResourceNotExistException e) {
log.error("出错了" , e);
log.error("全局异常捕获:" + e);
return Result.fail(ResultCodeEnum.getResultCodeEnumByCode(e.getCode()) , e.getMessage());
}
@ExceptionHandler(MaxUploadSizeExceededException.class)
@ResponseBody
@ResponseStatus(HttpStatus.OK)
public Result error(MaxUploadSizeExceededException e) {
e.printStackTrace();
log.error("全局异常捕获:" + e);
return Result.fail(ResultCodeEnum.MISSING_PARAMETER , e.getMessage());
}
}

23
src/main/java/com/project/base/domain/dto/BaseDTO.java

@ -0,0 +1,23 @@
package com.project.base.domain.dto;
import lombok.Data;
import java.util.Date;
@Data
public class BaseDTO {
private Long id;
private Long creatorId;
private Date createTime;
private Long updaterId;
private Date updateTime;
private Boolean deleted;
}

50
src/main/java/com/project/base/domain/entity/BaseEntity.java

@ -0,0 +1,50 @@
package com.project.base.domain.entity;
import com.baomidou.mybatisplus.annotation.*;
import com.project.base.domain.enums.StatusEnum;
import jakarta.persistence.Column;
import jakarta.persistence.Id;
import jakarta.persistence.MappedSuperclass;
import lombok.Data;
import org.hibernate.annotations.Comment;
import java.io.Serializable;
import java.util.Date;
@MappedSuperclass
@Data
public class BaseEntity implements Serializable {
@Id
@TableId(value = "id" , type = IdType.ASSIGN_ID)
@Column(name = "id" , columnDefinition="bigint(20)")
private Long id;
@TableField(value = "creator_id" , fill = FieldFill.INSERT)
@Column(name = "creator_id" , columnDefinition="bigint(20) comment '创建用户id'")
private Long creatorId;
@TableField(value = "create_time" , fill = FieldFill.INSERT)
@Comment("创建时间")
@Column(name = "create_time")
private Date createTime;
@TableField(value = "updater_id" , fill = FieldFill.INSERT_UPDATE)
@Column(name = "updater_id", columnDefinition="bigint(20) comment '更新用户id'")
private Long updaterId;
@TableField(value = "update_time" , fill = FieldFill.INSERT_UPDATE)
@Comment("更新时间")
@Column(name = "update_time")
private Date updateTime;
/**
* deleted字段请在数据库中 设置为tinyInt 并且非null 默认值为0
*/
@TableField("deleted")
@TableLogic
@Comment("逻辑删除位")
@Column(name = "deleted")
private Boolean deleted = StatusEnum.Normal.getValue();
}

24
src/main/java/com/project/base/domain/enums/HasValueEnum.java

@ -0,0 +1,24 @@
package com.project.base.domain.enums;
public interface HasValueEnum<T> {
/**
* 获取枚举名将会由枚举抽象类默认实现
*
* @see Enum
*/
String name();
/**
* 获取枚举值
*/
T getValue();
/**
* 枚举名比较时是否需要区分大小写默认为需要区分
*/
default boolean caseCompare() {
return true;
}
}

17
src/main/java/com/project/base/domain/enums/StatusEnum.java

@ -0,0 +1,17 @@
package com.project.base.domain.enums;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
@Getter
@RequiredArgsConstructor
public enum StatusEnum implements HasValueEnum<Boolean>{
Normal(Boolean.FALSE), Delete(Boolean.TRUE);
private final Boolean value;
}

21
src/main/java/com/project/base/domain/exception/BusinessErrorException.java

@ -0,0 +1,21 @@
package com.project.base.domain.exception;
import com.project.base.domain.result.ResultCodeEnum;
import lombok.Data;
@Data
public class BusinessErrorException extends RuntimeException{
private Integer code;
public BusinessErrorException(String msg) {
super(msg);
this.code = ResultCodeEnum.BUSINESS_ERROR.getCode();
}
public BusinessErrorException(Integer code , String msg) {
super(msg);
this.code = code;
}
}

21
src/main/java/com/project/base/domain/exception/MissingParameterException.java

@ -0,0 +1,21 @@
package com.project.base.domain.exception;
import com.project.base.domain.result.ResultCodeEnum;
import lombok.Data;
@Data
public class MissingParameterException extends RuntimeException {
private final Integer code;
public MissingParameterException(String msg) {
super(msg);
this.code = ResultCodeEnum.MISSING_PARAMETER.getCode();
}
public MissingParameterException(Integer code , String msg) {
super(msg);
this.code = code;
}
}

21
src/main/java/com/project/base/domain/exception/ResourceNotExistException.java

@ -0,0 +1,21 @@
package com.project.base.domain.exception;
import com.project.base.domain.result.ResultCodeEnum;
import lombok.Data;
@Data
public class ResourceNotExistException extends RuntimeException {
private final Integer code;
public ResourceNotExistException(String msg) {
super(msg);
this.code = ResultCodeEnum.RESOURCE_NOT_EXIST.getCode();
}
public ResourceNotExistException(Integer code , String msg) {
super(msg);
this.code = code;
}
}

63
src/main/java/com/project/base/domain/result/Result.java

@ -0,0 +1,63 @@
package com.project.base.domain.result;
import lombok.Getter;
import lombok.Setter;
import java.io.Serializable;
@Getter
@Setter
public class Result<T> implements Serializable {
private Integer code = 0;;
private Boolean success = true;
private String message;
private T data;
public static <T> Result<T> success(T data) {
Result<T> result = new Result<T>();
result.setCode(ResultCodeEnum.SUCCESS.getCode());
result.setMessage("success");
result.setData(data);
return result;
}
public static <T> Result<T> success(T data, String message) {
Result<T> result = new Result<T>();
result.setCode(ResultCodeEnum.SUCCESS.getCode());
result.setMessage(message);
result.setData(data);
return result;
}
public static <T> Result<T> fail() {
Result<T> res = new Result<T>();
res.setCode(ResultCodeEnum.UNKNOWN_ERROR.getCode());
res.setMessage(ResultCodeEnum.UNKNOWN_ERROR.getMessage());
res.setSuccess(false);
return res;
}
public static <T> Result<T> fail(ResultCodeEnum resultCodeEnum) {
Result<T> res = new Result<T>();
res.setCode(resultCodeEnum.getCode());
res.setMessage(resultCodeEnum.getMessage());
res.setSuccess(false);
return res;
}
public static <T> Result<T> fail(ResultCodeEnum resultCodeEnum , String msg) {
Result<T> res = new Result<T>();
res.setCode(resultCodeEnum.getCode());
res.setMessage(msg);
res.setSuccess(false);
return res;
}
}

41
src/main/java/com/project/base/domain/result/ResultCodeEnum.java

@ -0,0 +1,41 @@
package com.project.base.domain.result;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
@Getter
@RequiredArgsConstructor
public enum ResultCodeEnum {
SUCCESS(true , 0 , "成功"),
MISSING_PARAMETER(false , 40001 , "请求参数缺失或格式错误"),
INVALID_REQUEST_BODY(false , 40002 , "无效的请求体"),
SIGNATURE_VERIFICATION_FAIL(false , 40101 , "API签名验证失败"),
TIMESTAMP_INVALID(false ,40102 , "请求时间戳已过期") ,
USER_NOT_FIND(false , 40103 , "用户身份信息缺失") ,
PERMISSION_DENIED(false , 40301 , "操作权限不足"),
RESOURCE_NOT_EXIST(false , 40401 , "请求的资源不存在") ,
INTERNAL_SYSTEM_ERROR(false , 50001 , "系统内部错误,请稍后重试"),
EXTERNAL_CALL_ERROR(false , 50002 , "外部服务调用失败"),
BUSINESS_ERROR(false , 60001 , "业务错误"),
UNKNOWN_ERROR(false , -1 , "未知错误"),
;
private Boolean success;
private Integer code;
private String message;
ResultCodeEnum(boolean success, Integer code, String message) {
this.success = success;
this.code = code;
this.message = message;
}
public static ResultCodeEnum getResultCodeEnumByCode(Integer code) {
for (ResultCodeEnum value : ResultCodeEnum.values()) {
if (value.getCode().equals(code)) {
return value;
}
}
return null;
}
}

199
src/main/java/com/project/base/domain/utils/TreeUtils.java

@ -0,0 +1,199 @@
package com.project.base.domain.utils;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import java.util.ArrayList;
import java.util.List;
import java.util.function.BiConsumer;
import java.util.function.Function;
/**
* @Description: 树形结构对象的构建工具类
* @ClassName: TreeUtils
* @Author: luoweijian
* @Date: 2023/8/7 13:59
* Copyright (C) 2021-2022 CASEEDER, All Rights Reserved.
* 注意本内容仅限于内部传阅禁止外泄以及用于其他的商业目的
*/
@Slf4j
public class TreeUtils {
/**
* 构建前端所需要树结构主键为 Long
* @param tList 要构建的节点列表
* @param getIdFn 获取节点标识Fn
* @param getParentIdFn 获取父节点标识Fn
* @param setChild 知道父节点的所有子节点后的Fn
* @return
* @param <T>
* @param <R>
*/
public static <T, R> List<T> buildLongTree(List<T> tList , Function<T, R> getIdFn , Function<T , R> getParentIdFn , BiConsumer<T , List<T>> setChild) {
try {
List<T> returnList = new ArrayList<>();
//主键id集合
List<Long> tempList = new ArrayList<>();
for (T t : tList) {
Long primaryId = (Long) getIdFn.apply(t);
tempList.add(primaryId);
}
for (T t : tList) {
// 如果是顶级节点, 遍历该父节点的所有子节点
Long parentId = (Long) getParentIdFn.apply(t);
if (!tempList.contains(parentId)) {
recursionLong(tList, t , getIdFn , getParentIdFn, setChild);
returnList.add(t);
}
}
if (returnList.isEmpty()) {
returnList = tList;
}
return returnList;
} catch (Exception e) {
log.error(String.format("树结构转换失败:%s" , e.getMessage()));
return tList;
}
}
/**
* 递归设置子集数据主键为 Long
* @param list
* @param o
* @param getIdFn
* @param getParentIdFn
* @param setChild
* @param <T>
* @param <R>
* @throws IllegalAccessException
*/
private static <T, R> void recursionLong(List<T> list, T o , Function<T, R> getIdFn , Function<T , R> getParentIdFn , BiConsumer<T , List<T>> setChild) throws IllegalAccessException {
// 得到子节点列表
List<T> childList = getLongChildList(list, o , getIdFn , getParentIdFn);
invokeChildrenList(o, childList , setChild);
for (T oChild : childList) {
if (getLongChildList(list, oChild , getIdFn , getParentIdFn).size() > 0) {
recursionLong(list, oChild , getIdFn , getParentIdFn , setChild);
}
}
}
/**
* 得到子节点列表主键为 Long
* @param list
* @param object
* @param getIdFn
* @param getParentIdFn
* @return
* @param <T>
* @param <R>
* @throws IllegalAccessException
*/
private static <T, R> List<T> getLongChildList(List<T> list, T object , Function<T, R> getIdFn , Function<T , R> getParentIdFn) throws IllegalAccessException {
Long primaryId = (Long) getIdFn.apply(object);
List<T> objects = new ArrayList<>();
for (T o : list) {
Long parentId = (Long) getParentIdFn.apply(o);
if (null != parentId && parentId.longValue() == primaryId.longValue()) {
objects.add(o);
}
}
return objects;
}
/**
* 设置子集数据
* @param o
* @param childList
* @param setChild
* @param <T>
*/
private static <T> void invokeChildrenList(T o, List<T> childList , BiConsumer<T , List<T>> setChild) {
setChild.accept(o , childList);
}
/**
* 将树转为List
* @param list
* @param getChildFn
* @return
* @param <T>
*/
public static <T> List<T> tree2List(List<T> list , Function<T , List<T>> getChildFn) {
List<T> res = Lists.newArrayList();
for (T node : list) {
List<T> childList = getChildFn.apply(node);
res.add(node);
if (CollUtil.isNotEmpty(childList)) {
res.addAll(tree2List(childList , getChildFn));
}
}
return res;
}
public static <T, R> List<T> buildStrTree(List<T> tList , Function<T, R> getIdFn , Function<T , R> getParentIdFn , BiConsumer<T , List<T>> setChild) {
try {
List<T> returnList = new ArrayList<>();
//主键id集合
List<String> tempList = new ArrayList<>();
for (T t : tList) {
String primaryId = String.valueOf(getIdFn.apply(t));
tempList.add(primaryId);
}
for (T t : tList) {
// 如果是顶级节点, 遍历该父节点的所有子节点
String parentId = String.valueOf(getParentIdFn.apply(t));
if (!tempList.contains(parentId)) {
recursionStr(tList, t , getIdFn , getParentIdFn, setChild);
returnList.add(t);
}
}
if (returnList.isEmpty()) {
returnList = tList;
}
return returnList;
} catch (Exception e) {
log.error(String.format("树结构转换失败:%s" , e.getMessage()));
return tList;
}
}
private static <T, R> void recursionStr(List<T> list, T o , Function<T, R> getIdFn , Function<T , R> getParentIdFn , BiConsumer<T , List<T>> setChild) throws IllegalAccessException {
// 得到子节点列表
List<T> childList = getStrChildList(list, o , getIdFn , getParentIdFn);
invokeChildrenList(o, childList , setChild);
for (T oChild : childList) {
if (getStrChildList(list, oChild , getIdFn , getParentIdFn).size() > 0) {
recursionStr(list, oChild , getIdFn , getParentIdFn , setChild);
}
}
}
private static <T, R> List<T> getStrChildList(List<T> list, T object , Function<T, R> getIdFn , Function<T , R> getParentIdFn) throws IllegalAccessException {
String primaryId = String.valueOf(getIdFn.apply(object));
List<T> objects = new ArrayList<>();
for (T o : list) {
String parentId = String.valueOf(getParentIdFn.apply(o));
if (null != parentId && StrUtil.equals(parentId , primaryId)) {
objects.add(o);
}
}
return objects;
}
}

23
src/main/java/com/project/ding/config/DingConfig.java

@ -0,0 +1,23 @@
package com.project.ding.config;
import com.github.tingyugetc520.ali.dingtalk.api.DtService;
import com.github.tingyugetc520.ali.dingtalk.api.impl.DtServiceImpl;
import com.github.tingyugetc520.ali.dingtalk.config.impl.DtDefaultConfigImpl;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class DingConfig {
@Bean
public DtService dtService() {
DtDefaultConfigImpl config = new DtDefaultConfigImpl();
config.setAppKey("ding4eootvq4jzas96lr");
config.setAppSecret("UI6XcD8GFPE_W_yo2eQkMuoSsTEf1whpZYEXrsDA7CV7bkJp40B3VNcETWS1aGgg");
// 如果是企业内部应用,通常还需要 AgentId ,
// config.setAgentId(4145005949L);
DtService dtService = new DtServiceImpl();
dtService.setDtConfigStorage(config);
return dtService;//
}
}

39
src/main/java/com/project/ding/controller/DepartmentController.java

@ -0,0 +1,39 @@
package com.project.ding.controller;
import com.github.tingyugetc520.ali.dingtalk.api.DtService;
import com.github.tingyugetc520.ali.dingtalk.bean.department.DtDepart;
import com.github.tingyugetc520.ali.dingtalk.bean.user.DtUser;
import com.project.ding.domain.dto.DingUserDTO;
import com.project.ding.utils.DingUtil;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.List;
@RestController
@Slf4j
public class DepartmentController {
@Autowired
private DingUtil dingUtil;
@Autowired
private DtService dtService;
@GetMapping("/test")
public void test(HttpServletResponse response) throws Exception {
List<DtDepart> list = dingUtil.getAllDepartment();
List<DingUserDTO> userList = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
List<DingUserDTO> userInDepartment = dingUtil.getUserIdInDepartment(list.get(i).getId());
userList.addAll(userInDepartment);
}
for (int i = 0; i < 10; i++) {
System.out.println(111);
}
}
}

13
src/main/java/com/project/ding/domain/dto/DepartmentDTO.java

@ -0,0 +1,13 @@
package com.project.ding.domain.dto;
import com.project.base.domain.dto.BaseDTO;
import lombok.Data;
@Data
public class DepartmentDTO extends BaseDTO {
private String name;
private Long parentId;
}

67
src/main/java/com/project/ding/domain/dto/DingUserDTO.java

@ -0,0 +1,67 @@
package com.project.ding.domain.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import java.util.Date;
import java.util.List;
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class DingUserDTO {
/**
* 用户id
*/
@JsonProperty("userid")
private String userId;
/**
* 用户在当前开发者企业账号范围内的唯一标识
*/
@JsonProperty("unionid")
private String unionId;
/**
* 用户姓名
*/
@JsonProperty("name")
private String name;
/**
* 头像地址
*/
@JsonProperty("avatar")
private String avatar;
/**
* 手机号码
*/
@JsonProperty("mobile")
private String mobile;
/**
* 员工工号
*/
@JsonProperty("job_number")
private String jobNumber;
/**
* 职位
*/
@JsonProperty("title")
private String title;
/**
* 所属部门id列表
*/
@JsonProperty("dept_id_list")
private List<Long> deptIdList;
/**
* 入职时间
*/
@JsonProperty("hired_date")
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
private Date hiredDate;
}

9
src/main/java/com/project/ding/domain/dto/UserDTO.java

@ -0,0 +1,9 @@
package com.project.ding.domain.dto;
import com.project.base.domain.dto.BaseDTO;
import lombok.Data;
@Data
public class UserDTO extends BaseDTO {
}

27
src/main/java/com/project/ding/domain/entity/DepartmentEntity.java

@ -0,0 +1,27 @@
package com.project.ding.domain.entity;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.project.base.domain.entity.BaseEntity;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Index;
import jakarta.persistence.Table;
import lombok.Data;
import lombok.EqualsAndHashCode;
@Data
@Table(name = "evaluator_department" , indexes = {@Index(name = "Idx_parentId", columnList = "parent_id")})
@Entity
@TableName("evaluator_department")
@EqualsAndHashCode(callSuper = true)
public class DepartmentEntity extends BaseEntity {
@Column(name = "name" , columnDefinition="varchar(255) comment '部门名称'")
private String name;
@TableField("parent_id")
@Column(name = "parent_id" , columnDefinition="bigint(20) comment '父部门id'")
private Long parentId;
}

71
src/main/java/com/project/ding/utils/DingUtil.java

@ -0,0 +1,71 @@
package com.project.ding.utils;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.tingyugetc520.ali.dingtalk.api.DtService;
import com.github.tingyugetc520.ali.dingtalk.bean.department.DtDepart;
import com.google.gson.JsonObject;
import com.jayway.jsonpath.JsonPath;
import com.project.ding.domain.dto.DingUserDTO;
import io.vavr.control.Try;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
@Component
public class DingUtil {
@Autowired
private DtService dtService;
public List<DtDepart> getAllDepartment() throws Exception {
return dtService.getDepartmentService().list(null , true);
}
public List<DingUserDTO> getAllUser() throws Exception {
List<DtDepart> list = getAllDepartment();
List<DingUserDTO> userList = new ArrayList<>();
for (int i = 0; i < list.size(); i++) {
List<DingUserDTO> userInDepartment = getUserIdInDepartment(list.get(i).getId());
userList.addAll(userInDepartment);
}
return userList;
}
public List<DingUserDTO> getUserIdInDepartment(Long id) throws Exception {
List<DingUserDTO> res = new ArrayList<>();
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("dept_id" , id);
jsonObject.addProperty("cursor" , 0);
jsonObject.addProperty("size" , 100);
String url = dtService.getDtConfigStorage().getApiUrl("/topapi/v2/user/list");
String responseContent = dtService.post(url, jsonObject);
res.addAll(Try.of(() -> new ObjectMapper().convertValue(
JsonPath.read(responseContent, "$.result.list"),
new TypeReference<List<DingUserDTO>>() {})).getOrElse(new ArrayList<>()));
Boolean hasMore = Try.of(() -> new ObjectMapper().convertValue(
JsonPath.read(responseContent, "$.result.has_more"),
new TypeReference<Boolean>() {})).getOrElse(Boolean.FALSE);
while (hasMore) {
jsonObject.addProperty("cursor" , new ObjectMapper().convertValue(
JsonPath.read(responseContent, "$.result.next_cursor"),
new TypeReference<Long>() {}));
String nextResponseContent = dtService.post(url, jsonObject);
res.addAll(Try.of(() -> new ObjectMapper().convertValue(
JsonPath.read(nextResponseContent, "$.result.list"),
new TypeReference<List<DingUserDTO>>() {})).getOrElse(new ArrayList<>()));
hasMore = Try.of(() -> new ObjectMapper().convertValue(
JsonPath.read(nextResponseContent, "$.result.has_more"),
new TypeReference<Boolean>() {})).getOrElse(Boolean.FALSE);
}
return res;
}
}

39
src/main/resources/application.yml

@ -0,0 +1,39 @@
server:
port: 7088
spring:
datasource:
dynamic:
primary: master
datasource:
master:
driverClassName: com.mysql.cj.jdbc.Driver
password: Itc@123456
url: jdbc:mysql://172.16.204.50:3306/proposal_workshop?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true
username: root
jpa:
hibernate:
ddl-auto: update
naming:
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
properties:
hibernate:
dialect: org.hibernate.dialect.MySQL8Dialect
show-sql: true
# 上传下载限制
servlet:
multipart:
max-file-size: 100MB
max-request-size: 100MB
jackson:
generator:
write-numbers-as-strings: true
minio:
endpoint: ${MINIO_ENDPOINT:http://172.16.124.14:9000}
accessKey: ${MINIO_ASSESSKEY:X42cCp42U4BSJHPAV1Aq}
secretKey: ${MINIO_SECRETKEY:099NCOOSklhJyeJE6C73YxbbUT4Y4dRJK0RafAgv}
bucket: ${MINIO_BUCKET:proposalworkshop}
mybatis-plus:
configuration:
map-underscore-to-camel-case: true
mapper-locations: classpath*:mapper/**/*.xml
type-aliases-package: com.proposal.**.domain.entity
Loading…
Cancel
Save