zhang-kan-kan vor 2 Jahren
Commit
6c21fa5c6e

+ 37 - 0
.gitignore

@@ -0,0 +1,37 @@
+# IntelliJ project files
+.idea
+*.iml
+out
+gen
+### Java template
+# Compiled class file
+*.class
+
+# Log file
+*.log
+/log/
+
+# BlueJ files
+*.ctxt
+
+# Mobile Tools for Java (J2ME)
+.mtj.tmp/
+
+# Package Files #
+*.jar
+*.war
+*.nar
+*.ear
+*.zip
+*.tar.gz
+*.rar
+
+# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
+hs_err_pid*
+
+mvnw
+mvnw.cmd
+
+# tmp file
+.tmp
+/tmp/

+ 346 - 0
pom.xml

@@ -0,0 +1,346 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<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>2.3.3.RELEASE</version>
+        <relativePath/> <!-- lookup parent from repository -->
+    </parent>
+    <groupId>com.muzhi.donghang</groupId>
+    <artifactId>donghang</artifactId>
+<!--    <packaging>jar</packaging>-->
+    <version>1.0-SNAPSHOT</version>
+    <name>donghang</name>
+    <description>Demo project for Spring Boot</description>
+
+    <properties>
+        <java.version>1.8</java.version>
+        <fastjson.version>1.2.33</fastjson.version>
+        <gson.version>2.8.2</gson.version>
+        <json.version>20170516</json.version>
+        <poi.version>3.17</poi.version>
+        <jodatime.version>2.10.1</jodatime.version>
+        <swagger.version>2.7.0</swagger.version>
+        <commons-fileupload.version>1.3.1</commons-fileupload.version>
+        <!--        <thymeleaf.version>3.0.2.RELEASE</thymeleaf.version>-->
+        <!-- 布局功能的支持程序 thymeleaf3主程序 layout2以上版本-->
+        <!--        <thymeleaf-layout-dialect.version>2.1.1</thymeleaf-layout-dialect.version>-->
+    </properties>
+
+    <repositories>
+        <repository>
+            <id>sonatype-nexus-staging</id>
+            <name>Sonatype Nexus Staging</name>
+            <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
+            <releases>
+                <enabled>true</enabled>
+            </releases>
+            <snapshots>
+                <enabled>true</enabled>
+            </snapshots>
+        </repository>
+    </repositories>
+
+    <dependencies>
+        <dependency>
+            <groupId>com.auth0</groupId>
+            <artifactId>java-jwt</artifactId>
+            <version>3.4.0</version>
+        </dependency>
+
+        <!-- httpClient -->
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpclient</artifactId>
+            <version>4.5.2</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpcore</artifactId>
+            <version>4.4.13</version>
+        </dependency>
+
+        <dependency>
+            <groupId>commons-httpclient</groupId>
+            <artifactId>commons-httpclient</artifactId>
+            <version>3.1</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.squareup.okhttp3</groupId>
+            <artifactId>okhttp</artifactId>
+            <version>4.4.1</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.konghq</groupId>
+            <artifactId>unirest-java</artifactId>
+            <version>2.3.17</version>
+        </dependency>
+
+<!--        <dependency>-->
+<!--            <groupId>org.slf4j</groupId>-->
+<!--            <artifactId>slf4j-api</artifactId>-->
+<!--        </dependency>-->
+
+<!--        <dependency>-->
+<!--            <groupId>commons-io</groupId>-->
+<!--            <artifactId>commons-io</artifactId>-->
+<!--        </dependency>-->
+
+        <!--json 组件 -->
+<!--        <dependency>-->
+<!--            <groupId>com.alibaba</groupId>-->
+<!--            <artifactId>fastjson</artifactId>-->
+<!--            <scope>provided</scope>-->
+<!--        </dependency>-->
+
+        <!--        <dependency>-->
+        <!--            <groupId>org.apache.cxf</groupId>-->
+        <!--            <artifactId>cxf-spring-boot-starter-jaxws</artifactId>-->
+        <!--            <version>3.3.1</version>-->
+        <!--        </dependency>-->
+
+        <!--        <dependency>-->
+        <!--            <groupId>org.springframework.boot</groupId>-->
+        <!--            <artifactId>spring-boot-starter-thymeleaf</artifactId>-->
+        <!--&lt;!&ndash;            <version>2.3.3.RELEASE</version>&ndash;&gt;-->
+        <!--        </dependency>-->
+
+        <!--钉钉相关-->
+        <dependency>
+            <groupId>com.aliyun</groupId>
+            <artifactId>alibaba-dingtalk-service-sdk</artifactId>
+            <version>2.0.0</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.aliyun</groupId>
+            <artifactId>dingtalk</artifactId>
+            <version>1.4.35</version>
+        </dependency>
+
+        <!--json相关-->
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>fastjson</artifactId>
+            <version>${fastjson.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.json</groupId>
+            <artifactId>json</artifactId>
+            <version>${json.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>com.google.code.gson</groupId>
+            <artifactId>gson</artifactId>
+            <version>${gson.version}</version>
+        </dependency>
+
+        <!--        <dependency>-->
+        <!--            <groupId>net.sf.json-lib</groupId>-->
+        <!--            <artifactId>json-lib</artifactId>-->
+        <!--            <version>2.4</version>-->
+        <!--        </dependency>-->
+
+
+        <!-- JSONObject对象依赖的jar包 -->
+        <dependency>
+            <groupId>commons-beanutils</groupId>
+            <artifactId>commons-beanutils</artifactId>
+            <version>1.9.3</version>
+        </dependency>
+        <dependency>
+            <groupId>commons-collections</groupId>
+            <artifactId>commons-collections</artifactId>
+            <version>3.2.1</version>
+        </dependency>
+        <dependency>
+            <groupId>commons-lang</groupId>
+            <artifactId>commons-lang</artifactId>
+            <version>2.6</version>
+        </dependency>
+        <dependency>
+            <groupId>commons-logging</groupId>
+            <artifactId>commons-logging</artifactId>
+            <version>1.1.1</version>
+        </dependency>
+        <dependency>
+            <groupId>net.sf.ezmorph</groupId>
+            <artifactId>ezmorph</artifactId>
+            <version>1.0.6</version>
+        </dependency>
+        <dependency>
+            <groupId>net.sf.json-lib</groupId>
+            <artifactId>json-lib</artifactId>
+            <version>2.2.3</version>
+            <classifier>jdk15</classifier><!-- 指定jdk版本 -->
+        </dependency>
+
+
+        <!--xls-->
+        <dependency>
+            <groupId>org.apache.poi</groupId>
+            <artifactId>poi</artifactId>
+            <version>${poi.version}</version>
+        </dependency>
+        <!--xlsx-->
+        <dependency>
+            <groupId>org.apache.poi</groupId>
+            <artifactId>poi-ooxml</artifactId>
+            <version>${poi.version}</version>
+        </dependency>
+        <!--文件上传-->
+        <dependency>
+            <groupId>commons-fileupload</groupId>
+            <artifactId>commons-fileupload</artifactId>
+            <version>${commons-fileupload.version}</version>
+        </dependency>
+
+        <!--        <dependency>-->
+        <!--            <groupId>org.springframework.boot</groupId>-->
+        <!--            <artifactId>spring-boot-starter-thymeleaf</artifactId>-->
+        <!--        </dependency>-->
+
+        <!--引入web模块-->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+        </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-devtools</artifactId>
+            <version>2.3.3.RELEASE</version>
+        </dependency>
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+            <optional>true</optional>
+            <version>1.18.10</version>
+        </dependency>
+
+<!--        &lt;!&ndash;mybatis-plus数据库连接&ndash;&gt;-->
+<!--        <dependency>-->
+<!--            <groupId>com.baomidou</groupId>-->
+<!--            <artifactId>mybatis-plus-boot-starter</artifactId>-->
+<!--            <version>3.2.0</version>-->
+<!--        </dependency>-->
+<!--        &lt;!&ndash;引入mysql:数据库驱动&ndash;&gt;-->
+<!--        <dependency>-->
+<!--            <groupId>mysql</groupId>-->
+<!--            <artifactId>mysql-connector-java</artifactId>-->
+<!--            <scope>runtime</scope>-->
+<!--        </dependency>-->
+<!--        &lt;!&ndash;引入druid数据源&ndash;&gt;-->
+<!--        &lt;!&ndash; https://mvnrepository.com/artifact/com.alibaba/druid &ndash;&gt;-->
+<!--        <dependency>-->
+<!--            <groupId>com.alibaba</groupId>-->
+<!--            <artifactId>druid</artifactId>-->
+<!--            <version>1.1.9</version>-->
+<!--        </dependency>-->
+<!--        <dependency>-->
+<!--            <groupId>com.alibaba</groupId>-->
+<!--            <artifactId>druid-spring-boot-starter</artifactId>-->
+<!--            <version>1.1.9</version>-->
+<!--        </dependency>-->
+
+        <!--引入jpa模块-->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-data-jpa</artifactId>
+        </dependency>
+
+        <!--日期时间工具-->
+        <dependency>
+            <groupId>joda-time</groupId>
+            <artifactId>joda-time</artifactId>
+            <version>${jodatime.version}</version>
+        </dependency>
+
+        <!--log4j-->
+        <dependency>
+            <groupId>log4j</groupId>
+            <artifactId>log4j</artifactId>
+            <version>1.2.17</version>
+        </dependency>
+
+        <!--swagger-->
+        <dependency>
+            <groupId>io.springfox</groupId>
+            <artifactId>springfox-swagger2</artifactId>
+            <version>${swagger.version}</version>
+        </dependency>
+        <!--swagger ui-->
+        <dependency>
+            <groupId>io.springfox</groupId>
+            <artifactId>springfox-swagger-ui</artifactId>
+            <version>${swagger.version}</version>
+        </dependency>
+
+        <dependency>
+            <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>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+                <configuration>
+                    <fork>true</fork>
+                </configuration>
+            </plugin>
+
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>2.3.1</version>
+                <configuration>
+                    <source>1.8</source>
+                    <target>1.8</target>
+                    <encoding>utf8</encoding>
+                </configuration>
+            </plugin>
+
+            <!--打包跳过测试-->
+<!--            <plugin>-->
+<!--                <groupId>org.apache.maven.plugins</groupId>-->
+<!--                <artifactId>maven-surefire-plugin</artifactId>-->
+<!--                <version>2.4.2</version>-->
+<!--                <configuration>-->
+<!--                    <skipTests>true</skipTests>-->
+<!--                </configuration>-->
+<!--            </plugin>-->
+        </plugins>
+
+        <!--映射mapper中对应的xml配置文件,如果没有mapper.xml文件则将下列注释-->
+<!--        <resources>-->
+<!--            <resource>-->
+<!--                <directory>src/main/java</directory>-->
+<!--                <includes>-->
+<!--                    <include>**/*.xml</include>-->
+
+<!--                    <include>**/*.properties</include>-->
+<!--                    <include>**/*.tld</include>-->
+<!--                    <include>**/*.xls</include>-->
+<!--                    <include>**/*.xlsx</include>-->
+<!--                </includes>-->
+<!--                <filtering>false</filtering>-->
+<!--            </resource>-->
+<!--        </resources>-->
+    </build>
+
+</project>

+ 22 - 0
src/main/java/com/muzhi/donghang/DongHangApplication.java

@@ -0,0 +1,22 @@
+package com.muzhi.donghang;
+
+//import org.mybatis.spring.annotation.MapperScan;
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
+import org.springframework.scheduling.annotation.EnableAsync;
+import org.springframework.scheduling.annotation.EnableScheduling;
+
+
+//@MapperScan("com.muzhi.donghang.mapper")
+@EnableAsync//开启异步注解
+@SpringBootApplication(exclude= DataSourceAutoConfiguration.class)
+@EnableScheduling//开启定时任务
+//@ComponentScan(basePackages = {"com.muzhi"})
+public class DongHangApplication {
+
+    public static void main(String[] args){
+        SpringApplication.run(DongHangApplication.class, args);
+    }
+
+}

+ 72 - 0
src/main/java/com/muzhi/donghang/common/R.java

@@ -0,0 +1,72 @@
+package com.muzhi.donghang.common;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @Author ZhangKan
+ * @Data 11:20
+ */
+
+//统一返回结果类
+@Data
+public class R {
+
+    @ApiModelProperty(value = "是否成功")
+    private Boolean success;
+
+    @ApiModelProperty(value = "返回码")
+    private Integer code;
+
+    @ApiModelProperty(value = "返回消息")
+    private String message;
+
+    @ApiModelProperty(value = "返回数据")
+    private Map<String, Object> data = new HashMap<String, Object>();
+
+    //把构造方法私有
+    private R(){}
+
+    //成功静态方法
+    public static R ok(){
+
+        R r = new R();
+        r.setSuccess(true);
+        r.setCode(ResultCode.SUCCESS);
+        r.setMessage("成功");
+        return r;
+    }
+
+    //失败静态方法
+    public static R error(){
+
+        R r = new R();
+        r.setSuccess(false);
+        r.setCode(ResultCode.ERROR);
+        r.setMessage("失败");
+        return r;
+    }
+
+    public R message(String message){
+        this.setMessage(message);
+        return this;
+    }
+
+    public R code(Integer code){
+        this.setCode(code);
+        return this;
+    }
+
+    public R data(String key, Object value){
+        this.data.put(key, value);
+        return this;
+    }
+
+    public R data(Map<String, Object> map){
+        this.setData(map);
+        return this;
+    }
+}

+ 12 - 0
src/main/java/com/muzhi/donghang/common/ResultCode.java

@@ -0,0 +1,12 @@
+package com.muzhi.donghang.common;
+
+/**
+ * @Author ZhangKan
+ * @Data 11:15
+ */
+public interface ResultCode {
+
+    public static Integer SUCCESS = 200;//成功
+
+    public static Integer ERROR = 201;//失败
+}

+ 34 - 0
src/main/java/com/muzhi/donghang/controller/AccessTokenController.java

@@ -0,0 +1,34 @@
+package com.muzhi.donghang.controller;
+
+import com.muzhi.donghang.service.AccessTokenService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.CrossOrigin;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @Author ZhangKan
+ * @Data 15:03
+ */
+
+@Api(description = "钉钉授权AccessToken")
+@RestController
+@RequestMapping("/dingservice")
+@CrossOrigin//解决跨域问题
+public class AccessTokenController {
+
+    @Autowired
+    private AccessTokenService AccessTokenService;
+
+    //获取钉钉中的access_token(牧之测试架构4)
+    @ApiOperation(value = "获取钉钉中的access_token")
+    @GetMapping("getMuZhiAccessToken")
+    public String getMuZhiAccessToken(){
+
+        String muZhiAccessToken = AccessTokenService.getMuZhiAccessToken();
+        return muZhiAccessToken;
+    }
+}

+ 169 - 0
src/main/java/com/muzhi/donghang/controller/EmployeeController.java

@@ -0,0 +1,169 @@
+package com.muzhi.donghang.controller;
+
+import com.muzhi.donghang.common.R;
+import com.muzhi.donghang.service.EmployeeService;
+import io.swagger.annotations.Api;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.web.bind.annotation.CrossOrigin;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+import java.util.Map;
+
+
+@Api(description = "钉钉人事")
+@RestController
+@RequestMapping("/empservice")
+@CrossOrigin//解决跨域问题
+public class EmployeeController {
+
+    @Autowired
+    private EmployeeService employeeService;
+
+    //获取钉钉员工花名册主部门ID
+    @GetMapping("getMainDeptId")
+    public String getMainDeptId(String userid){
+        //TODO
+        //userid = "manager5889";//牧之测试架构,牧之userid
+//        userid = "0500382234808088";//东航架构,才浅userid
+
+        String employee = employeeService.getMainDeptId(userid);
+
+        return employee;
+    }
+
+    //获取指定部门的所有父部门id列表
+    @GetMapping("getDeptIdList")
+    public List getDeptIdList(String userid){
+        //TODO
+        //userid = "manager5889";//牧之测试架构,牧之userid
+//        userid = "0500382234808088";//东航架构,才浅userid
+
+        List deptIdList = employeeService.getDeptIdList(userid);
+
+        return deptIdList;
+    }
+
+    //======【最终接口】获取主架构部门名称======
+    @GetMapping("getMainDeptName")
+    public R getMainDeptName(){
+
+        String mainDeptName = employeeService.getMainDeptName();
+
+        if (mainDeptName == null || mainDeptName == ""){
+            return R.error().message("获取主架构部门失败!");
+        }else {
+            return R.ok().data("mainDeptName",mainDeptName);
+        }
+    }
+
+    //======【最终接口】根据所有的父部门id列表获取各个部门的名称======
+    @GetMapping("getDeptName")
+    public R getDeptName(String userid){
+        //TODO
+        //userid = "manager5889";//牧之测试架构,牧之userid
+//        userid = "0500382234808088";//东航架构,才浅userid
+
+        String deptName = employeeService.getDeptName(userid);
+
+        if (deptName == null || deptName == ""){
+            return R.error().message("获取部门层级失败!");
+        }else {
+            return R.ok().data("deptName",deptName);
+        }
+    }
+
+    //======【最终接口】获取钉钉员工入职日期,并换算入职天数======
+    @GetMapping("getJoinDay")
+    public R getJoinDay(String userid){
+        //TODO
+        //userid = "manager5889";//牧之测试架构,牧之userid
+//        userid = "0500382234808088";//东航架构,才浅userid
+
+        String joinDay = employeeService.getJoinDay(userid);
+
+        if (joinDay == null || joinDay == ""){
+            return R.error().message("获取员工入职天数失败,请检查钉钉中该人员入职日期是否填写!");
+        }else {
+            return R.ok().data("joinDay",joinDay);
+        }
+    }
+
+    //======【最终接口】当前人员的本月实际出勤天数======
+    @GetMapping("getChuQinDays")
+    public R getChuQinDays(String userid){
+        //TODO
+        //userid = "manager5889";//牧之测试架构,牧之userid
+//        userid = "0500382234808088";//东航架构,才浅userid
+
+        String chuQinDays = employeeService.getChuQinDays(userid);
+
+        if (chuQinDays == null || chuQinDays == ""){
+            return R.error().message("获取员工本月出勤天数失败!");
+        }else {
+            return R.ok().data("chuQinDays",chuQinDays);
+        }
+    }
+
+    //===【最终接口】获取当前人员的主部门下的人员,并循环获取每个人员的考勤打卡===
+    @GetMapping("getDeptDaKa")
+    public R getDeptDaKa(String userid){
+        //TODO
+        //userid = "manager5889";//牧之测试架构,牧之userid
+//        userid = "0500382234808088";//东航架构,才浅userid
+
+        String deptDaKa = employeeService.getDeptDaKa(userid);
+
+        if (deptDaKa == null || deptDaKa == ""){
+            return R.error().message("获取当前部门出勤人数失败!");
+        }else {
+            return R.ok().data("deptDaKa",deptDaKa);
+        }
+    }
+
+    //===【最终接口】获取当前人员的主部门下的人员,并循环获取每个人员是否请假===
+    @GetMapping("getDeptQingJia")
+    public R getDeptQingJia(String userid){
+        //TODO
+        //userid = "manager5889";//牧之测试架构,牧之userid
+//        userid = "0500382234808088";//东航架构,才浅userid
+
+        String deptQingJia = employeeService.getDeptQingJia(userid);
+
+        if (deptQingJia == null || deptQingJia == ""){
+            return R.error().message("获取当前部门请假人数失败!");
+        }else {
+            return R.ok().data("deptQingJia",deptQingJia);
+        }
+    }
+
+    //===【最终接口】获取钉钉日程信息===
+    @GetMapping("getSchedule")
+    public R getSchedule(String userid){
+        //TODO
+        //userid = "manager5889";//牧之测试架构,牧之userid
+//        userid = "0500382234808088";//东航架构,才浅userid
+
+        Map schedule = employeeService.getSchedule(userid);
+        System.out.println("controller返回:" + schedule);
+
+//        if (schedule == null || schedule.isEmpty()){
+//            return R.error().message("获取当前人员日程失败!");
+//        }else {
+            return R.ok().data(schedule);
+//        }
+    }
+
+    //===【最终接口】获取人天===
+    @GetMapping("getWeather")
+    public R getWeather(){
+
+        Map weather = employeeService.getWeather();
+
+//        return R.ok().data("getWeather",weather);
+        return R.ok().data(weather);
+    }
+}

+ 11 - 0
src/main/java/com/muzhi/donghang/service/AccessTokenService.java

@@ -0,0 +1,11 @@
+package com.muzhi.donghang.service;
+
+/**
+ * @Author ZhangKan
+ * @Data 15:34
+ */
+public interface AccessTokenService {
+
+    //获取access_token的方法(牧之测试架构4)
+    String getMuZhiAccessToken();
+}

+ 41 - 0
src/main/java/com/muzhi/donghang/service/EmployeeService.java

@@ -0,0 +1,41 @@
+package com.muzhi.donghang.service;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @Author ZhangKan
+ * @Data 15:34
+ */
+public interface EmployeeService {
+
+    //获取钉钉员工花名册主部门ID
+    String getMainDeptId(String userid);
+
+    //获取指定部门的所有父部门id列表
+    List getDeptIdList(String userid);
+
+    //======【最终接口】获取主架构部门名称======
+    String getMainDeptName();
+
+    //======【最终接口】根据所有的父部门id列表获取各个部门的名称======
+    String getDeptName(String userid);
+
+    //======【最终接口】获取钉钉员工入职日期,并换算入职天数======
+    String getJoinDay(String userid);
+
+    //======【最终接口】当前人员的本月实际出勤天数======
+    String getChuQinDays(String userid);
+
+    //===【最终接口】获取当前人员的主部门下的人员,并循环获取每个人员的考勤打卡===
+    String getDeptDaKa(String userid);
+
+    //===【最终接口】获取当前人员的主部门下的人员,并循环获取每个人员是否请假===
+    String getDeptQingJia(String userid);
+
+    //===【最终接口】获取钉钉日程信息===
+    Map getSchedule(String userid);
+
+    //===【最终接口】获取天气===
+    Map getWeather();
+}

+ 57 - 0
src/main/java/com/muzhi/donghang/service/impl/AccessTokenServiceImpl.java

@@ -0,0 +1,57 @@
+package com.muzhi.donghang.service.impl;
+
+import com.dingtalk.api.DefaultDingTalkClient;
+import com.dingtalk.api.request.OapiGettokenRequest;
+import com.dingtalk.api.response.OapiGettokenResponse;
+import com.muzhi.donghang.service.AccessTokenService;
+import com.taobao.api.ApiException;
+import org.springframework.stereotype.Service;
+
+
+/**
+ * @Author ZhangKan
+ * @Data 15:39
+ */
+
+@Service
+public class AccessTokenServiceImpl implements AccessTokenService {
+
+    //牧之测试架构4
+    //APPKEY
+    private static String APPKEY1 = "ding2katvzyqvlkunqtb";
+    //APPSECRET
+    private static String APPSECRET1 = "vSctQrVm5cGos0X6K86NN0A8Vv6-SmN4W_VRXjsqPqZRhZtbG6xfPATOZhPi3VBE";
+    //AgenthId:1200391050
+
+    public static String accessToken1 = null;
+
+    //东航
+    //APPKEY
+    private static String APPKEY = "dingt3kswmqcjdice2hd";
+    //APPSECRET
+    private static String APPSECRET = "s6C1ikKC50jOWq-1HgJfO6x0QhZtqgX1LNe72PD4PW_R8elop2-C-F6537HTRJ6k";
+    //AgenthId:2050803405
+
+    public static String accessToken = null;
+
+    //才浅userid:0500382234808088
+
+
+    //获取access_token的方法(东航架构)
+    @Override
+    public String getMuZhiAccessToken() {
+        DefaultDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken");
+        OapiGettokenRequest request = new OapiGettokenRequest();
+        request.setAppkey(APPKEY);
+        request.setAppsecret(APPSECRET);
+        request.setHttpMethod("GET");
+        try {
+            OapiGettokenResponse response = client.execute(request);
+            accessToken = response.getAccessToken();
+            System.out.println("AccessToken:" + accessToken);
+        } catch (ApiException e) {
+            e.printStackTrace();
+        }
+        return accessToken;
+    }
+}

+ 920 - 0
src/main/java/com/muzhi/donghang/service/impl/EmployeeServiceImpl.java

@@ -0,0 +1,920 @@
+package com.muzhi.donghang.service.impl;
+
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.aliyun.dingtalkcalendar_1_0.models.GetEventResponse;
+import com.aliyun.dingtalkcalendar_1_0.models.ListEventsResponse;
+import com.aliyun.tea.TeaException;
+import com.aliyun.teautil.models.RuntimeOptions;
+import com.dingtalk.api.DefaultDingTalkClient;
+import com.dingtalk.api.DingTalkClient;
+import com.dingtalk.api.request.*;
+import com.dingtalk.api.response.*;
+import com.muzhi.donghang.service.AccessTokenService;
+import com.muzhi.donghang.service.EmployeeService;
+import com.taobao.api.ApiException;
+import com.taobao.api.internal.util.StringUtils;
+import org.joda.time.DateTime;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.stereotype.Service;
+
+import java.net.URL;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+
+@Service
+public class EmployeeServiceImpl implements EmployeeService {
+
+    @Autowired
+    private AccessTokenService accessTokenService;
+
+    //获取钉钉员工花名册主部门ID
+//    @Async
+    @Override
+    public String getMainDeptId(String userid){
+        System.out.println("宜搭出入的人员userid:" + userid);
+
+        String employee = null;
+        try {
+            DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/smartwork/hrm/employee/v2/list");
+            OapiSmartworkHrmEmployeeV2ListRequest req = new OapiSmartworkHrmEmployeeV2ListRequest();
+            //待查询人员的userid
+            req.setUseridList(userid);
+            //固定查询主部门id字段信息
+            req.setFieldFilterList("sys00-mainDeptId");
+            //钉钉自建应用Agentid
+            req.setAgentid(1200391050L);
+            OapiSmartworkHrmEmployeeV2ListResponse rsp = client.execute(req, accessTokenService.getMuZhiAccessToken());
+            employee = rsp.getBody();
+            System.out.println("抓取花名册部门id的初始返回结果:" + employee);
+        } catch (ApiException e) {
+            e.printStackTrace();
+        }
+        JSONObject jsonObject = JSON.parseObject(employee);
+        //获取的主部门id
+        String mainDeptId = jsonObject.getJSONArray("result")
+                .getJSONObject(0)
+                .getJSONArray("field_data_list")
+                .getJSONObject(0)
+                .getJSONArray("field_value_list")
+                .getJSONObject(0)
+                .getString("value");
+        System.out.println("当前人员的主部门id:" + mainDeptId);
+
+        return mainDeptId;
+    }
+
+    //获取指定部门的所有父部门id列表
+//    @Async
+    @Override
+    public List getDeptIdList(String userid){
+        String mainDeptId = getMainDeptId(userid);
+        long mainDeptIdLong = Long.parseLong(mainDeptId);
+        System.out.println("转换成Long型的部门id:" + mainDeptIdLong);
+
+        String dept = null;
+        try {
+            DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/listparentbydept");
+            OapiV2DepartmentListparentbydeptRequest req = new OapiV2DepartmentListparentbydeptRequest();
+            //主部门id
+            req.setDeptId(mainDeptIdLong);
+            OapiV2DepartmentListparentbydeptResponse rsp = client.execute(req, accessTokenService.getMuZhiAccessToken());
+            dept = rsp.getBody();
+            System.out.println("抓取主部门的所有父部门id列表初始返回结果:" + dept);
+        } catch (ApiException e) {
+            e.printStackTrace();
+        }
+        JSONObject jsonObject = JSON.parseObject(dept);
+        JSONArray jsonArray = jsonObject.getJSONObject("result").getJSONArray("parent_id_list");
+        System.out.println(jsonArray);
+
+        return jsonArray;
+    }
+
+    //======【最终接口】获取主架构部门名称======
+//    @Async
+    @Override
+    public String getMainDeptName(){
+
+        String mainDeptName = null;
+        try {
+            DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/get");
+            OapiV2DepartmentGetRequest req = new OapiV2DepartmentGetRequest();
+            req.setDeptId(1L);
+            OapiV2DepartmentGetResponse rsp = client.execute(req, accessTokenService.getMuZhiAccessToken());
+            mainDeptName = rsp.getBody();
+            System.out.println("抓取主部门信息初始返回结果:" + mainDeptName);
+        } catch (ApiException e) {
+            e.printStackTrace();
+        }
+        JSONObject jsonObject = JSON.parseObject(mainDeptName);
+        String name = jsonObject.getJSONObject("result").getString("name");
+
+        return name;
+    }
+
+    //======【最终接口】根据所有的父部门id列表获取各个部门的名称======
+//    @Async
+    @Override
+    public String getDeptName(String userid){
+
+        List deptIdList = getDeptIdList(userid);
+
+        String substring = "";
+
+        for (int i = 0; deptIdList.size() > i; i++){
+            String s = deptIdList.get(i).toString();
+            long deptIdLong = Long.parseLong(s);
+            System.out.println("Long型的部门id:" + deptIdLong);
+
+            String deptName = null;
+            try {
+                DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/get");
+                OapiV2DepartmentGetRequest req = new OapiV2DepartmentGetRequest();
+                req.setDeptId(deptIdLong);
+                OapiV2DepartmentGetResponse rsp = client.execute(req, accessTokenService.getMuZhiAccessToken());
+                deptName = rsp.getBody();
+                System.out.println("抓取部门信息初始返回结果:" + deptName);
+            } catch (ApiException e) {
+                e.printStackTrace();
+            }
+            JSONObject jsonObject = JSON.parseObject(deptName);
+            String name = jsonObject.getJSONObject("result").getString("name");
+            System.out.println("循环抓取部门名称:" + name);
+
+            if (deptIdLong != 1L){
+                substring = "/ " + name + substring;
+            }
+        }
+        //去除拼接后的部门名称字符串的第一个字符“/”
+        String nameAll = substring.substring(2);
+        System.out.println("最终拼接的部门名称:" + nameAll);
+
+        return nameAll;
+    }
+
+    //======【最终接口】获取钉钉员工入职日期,并换算入职天数======
+//    @Async
+    @Override
+    public String getJoinDay(String userid){
+        System.out.println("宜搭传入的userid:" + userid);
+
+        String employee = null;
+        try {
+            DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/smartwork/hrm/employee/v2/list");
+            OapiSmartworkHrmEmployeeV2ListRequest req = new OapiSmartworkHrmEmployeeV2ListRequest();
+            //待查询人员的userid
+            req.setUseridList(userid);
+            //固定查询主部门id字段信息
+            req.setFieldFilterList("sys00-confirmJoinTime");
+            //钉钉自建应用Agentid
+            req.setAgentid(2050803405L);
+            OapiSmartworkHrmEmployeeV2ListResponse rsp = client.execute(req, accessTokenService.getMuZhiAccessToken());
+            employee = rsp.getBody();
+            System.out.println("抓取花名册入职日期的初始返回结果:" + employee);
+        } catch (ApiException e) {
+            e.printStackTrace();
+        }
+        JSONObject jsonObject = JSON.parseObject(employee);
+        //获取的主部门id
+        String joinDay = jsonObject.getJSONArray("result")
+                .getJSONObject(0)
+                .getJSONArray("field_data_list")
+                .getJSONObject(0)
+                .getJSONArray("field_value_list")
+                .getJSONObject(0)
+                .getString("value");
+        System.out.println("当前人员的入职日期:" + joinDay);
+
+        //获取当天的日期
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+        Date date = new Date();
+        String dateNow = simpleDateFormat.format(date);
+        System.out.println("当天的日期:" + dateNow);
+
+        //当天日期和入职日期进行相减,计算入职天数
+        String Days = "";
+        //当天日期
+        try {
+            long timeNow = simpleDateFormat.parse(dateNow).getTime();
+            long timeJoin = simpleDateFormat.parse(joinDay).getTime();
+            Days = String.valueOf((timeNow - timeJoin)/(24 * 60 * 60 * 1000));
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+        System.out.println("入职天数:" + Days);
+
+        return Days;
+    }
+
+    //======【最终接口】当前人员的本月实际出勤天数======
+//    @Async
+    @Override
+    public String getChuQinDays(String userid){
+        System.out.println("宜搭传入的userid:" + userid);
+
+        Date Date = new Date(System.currentTimeMillis());
+        System.out.println("当前时间:" + Date);
+
+        Calendar calendar111 = Calendar.getInstance();
+        calendar111.setTime(Date);
+        //当月第一天
+//        calendar111.add(Calendar.MONTH,-1);
+        calendar111.set(Calendar.DAY_OF_MONTH,1);
+        calendar111.set(Calendar.HOUR_OF_DAY,0);
+        calendar111.set(Calendar.MINUTE,0);
+        calendar111.set(Calendar.SECOND,0);
+        calendar111.set(Calendar.MILLISECOND,0);
+        String FORMtime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar111.getTime());
+        System.out.println("当月第一天零点:" + FORMtime);
+
+        //获取当天的日期时间
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        Date date = new Date();
+        String TOtime = simpleDateFormat.format(date);
+        System.out.println("当天的当前时间:" + TOtime);
+
+        //实际出勤天数
+        int sjcqts1 = 0;
+        try {
+            DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/attendance/getcolumnval");
+            OapiAttendanceGetcolumnvalRequest req = new OapiAttendanceGetcolumnvalRequest();
+            //待查询人员的userid
+            req.setUserid(userid);
+            //TODO 考勤报表列定义查出来的出勤天数的列id(固定)
+//            req.setColumnIdList("190133089");//牧之测试架构,出勤天数的列id
+            req.setColumnIdList("7186604");//东航架构,出勤天数的列id
+            //查询开始时间
+            req.setFromDate(StringUtils.parseDateTime(FORMtime));
+            //查询结束时间
+            req.setToDate(StringUtils.parseDateTime(TOtime));
+            OapiAttendanceGetcolumnvalResponse rsp = client.execute(req, accessTokenService.getMuZhiAccessToken());
+            System.out.println(rsp.getBody());
+            String string = rsp.getBody();
+            JSONObject jsonObject = JSON.parseObject(string);
+            JSONArray jsonArray = jsonObject.getJSONObject("result").
+                    getJSONArray("column_vals").
+                    getJSONObject(0).
+                    getJSONArray("column_vals");
+            for (int i = 0; i<jsonArray.size(); i++){
+                String value = jsonArray.getJSONObject(i).getString("value");
+                float a = Float.parseFloat(value);
+                int b = (int)a;
+                sjcqts1 = sjcqts1 + b;
+            }
+        } catch (ApiException e) {
+            e.printStackTrace();
+        }
+        String sjcqts = String.valueOf(sjcqts1);
+        System.out.println("实际出勤天数:" + sjcqts);
+
+        return sjcqts;
+    }
+
+    //===【最终接口】获取当前人员的主部门下的人员,并循环获取每个人员的考勤打卡===
+//    @Async
+    @Override
+    public String getDeptDaKa(String userid){
+        System.out.println("宜搭传入的userid:" + userid);
+
+        //获取当天的日期时间
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        Date date = new Date();
+        String timeNow = simpleDateFormat.format(date);
+        System.out.println("当天的当前时间:" + timeNow);
+
+        //获取当前人员的主部门id
+        String mainDeptId = getMainDeptId(userid);
+        long mainDeptIdLong = Long.parseLong(mainDeptId);
+        System.out.println("转换成Long型的部门id:" + mainDeptIdLong);
+
+        List listDeptAll = new ArrayList();
+
+        //获取当前人员的所有父部门id列表
+        List deptIdList = getDeptIdList(userid);
+        System.out.println("当前人员所有父部门id列表:" + deptIdList);
+
+        //从右往左获取第三层级部门(即客户要求展示的部门层级id)
+        String a = deptIdList.get(deptIdList.size() - 3).toString();
+        long zhanshiDept = Long.parseLong(a);
+        System.out.println("展示主部门的id:" + zhanshiDept);
+
+        //部门id第一次汇总
+        listDeptAll.add(zhanshiDept);
+
+        //获取下一级子部门id列表
+        JSONObject jsonObject11 = null;
+        try {
+            DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/listsubid");
+            OapiV2DepartmentListsubidRequest req = new OapiV2DepartmentListsubidRequest();
+            //展示主部门的id
+            req.setDeptId(zhanshiDept);
+            OapiV2DepartmentListsubidResponse rsp = client.execute(req, accessTokenService.getMuZhiAccessToken());
+            String result = rsp.getBody();
+            jsonObject11 = JSON.parseObject(result);
+            System.out.println(result);
+        } catch (ApiException e) {
+            e.printStackTrace();
+        }
+        JSONArray jsonArray11 = jsonObject11.getJSONObject("result").getJSONArray("dept_id_list");
+
+        for (int i = 0; i < jsonArray11.size(); i++) {
+            String b = jsonArray11.getString(i);
+            long Dept2 = Long.parseLong(b);
+            System.out.println("逐层获取展示主部门下一层级的部门id:" + Dept2);
+            //部门id第二次汇总
+            listDeptAll.add(Dept2);
+
+            //获取下一级子部门id列表
+            JSONObject jsonObject22 = null;
+            try {
+                DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/listsubid");
+                OapiV2DepartmentListsubidRequest req = new OapiV2DepartmentListsubidRequest();
+                //第二次汇总部门的id
+                req.setDeptId(Dept2);
+                OapiV2DepartmentListsubidResponse rsp = client.execute(req, accessTokenService.getMuZhiAccessToken());
+                String result = rsp.getBody();
+                jsonObject22 = JSON.parseObject(result);
+                System.out.println(result);
+            } catch (ApiException e) {
+                e.printStackTrace();
+            }
+            JSONArray jsonArray22 = jsonObject22.getJSONObject("result").getJSONArray("dept_id_list");
+
+            for (int j = 0; j < jsonArray22.size(); j++) {
+                String c = jsonArray22.getString(j);
+                long Dept3 = Long.parseLong(c);
+                System.out.println("逐层获取第二次汇总部门的下一层级的部门id:" + Dept3);
+                //部门id第三次汇总
+                listDeptAll.add(Dept3);
+
+                //获取下一级子部门id列表
+                JSONObject jsonObject33 = null;
+                try {
+                    DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/listsubid");
+                    OapiV2DepartmentListsubidRequest req = new OapiV2DepartmentListsubidRequest();
+                    //第三次汇总部门的id
+                    req.setDeptId(Dept3);
+                    OapiV2DepartmentListsubidResponse rsp = client.execute(req, accessTokenService.getMuZhiAccessToken());
+                    String result = rsp.getBody();
+                    jsonObject33 = JSON.parseObject(result);
+                    System.out.println(result);
+                } catch (ApiException e) {
+                    e.printStackTrace();
+                }
+                JSONArray jsonArray33 = jsonObject33.getJSONObject("result").getJSONArray("dept_id_list");
+
+                for (int k = 0; k < jsonArray33.size(); k++) {
+                    String d = jsonArray33.getString(k);
+                    long Dept4 = Long.parseLong(d);
+                    System.out.println("逐层获取第三次汇总部门的下一层级的部门id:" + Dept4);
+                    //部门id第四次汇总
+                    listDeptAll.add(Dept4);
+
+                    //获取下一级子部门id列表
+                    JSONObject jsonObject44 = null;
+                    try {
+                        DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/listsubid");
+                        OapiV2DepartmentListsubidRequest req = new OapiV2DepartmentListsubidRequest();
+                        //第四次汇总部门的id
+                        req.setDeptId(Dept4);
+                        OapiV2DepartmentListsubidResponse rsp = client.execute(req, accessTokenService.getMuZhiAccessToken());
+                        String result = rsp.getBody();
+                        jsonObject44 = JSON.parseObject(result);
+                        System.out.println(result);
+                    } catch (ApiException e) {
+                        e.printStackTrace();
+                    }
+                    JSONArray jsonArray44 = jsonObject44.getJSONObject("result").getJSONArray("dept_id_list");
+                    System.out.println("第四次查询第五层级返回结果:" + jsonArray44);
+
+                    for (int l = 0; l < jsonArray44.size(); l++) {
+                        String e = jsonArray44.getString(l);
+                        long Dept5 = Long.parseLong(e);
+                        System.out.println("逐层获取第三次汇总部门的下一层级的部门id:" + Dept5);
+                        //部门id第五次汇总
+                        listDeptAll.add(Dept5);
+                    }
+                }
+            }
+        }
+        String s = listDeptAll.toString();
+        String s1 = s.replaceAll("\\ ", "");
+        JSONArray jsonArray2 = JSON.parseArray(s1);
+        System.out.println("@@@@@@@@@@@@@@@@" + jsonArray2);
+        System.out.println("******当前用户所属展示部门下的所有id列表******:" + listDeptAll);
+
+        //记录当前人员的主部门的打卡数(出勤数)
+        int daka = 0;
+
+        for (int x = 0; x < jsonArray2.size(); x++) {
+            Long aLong = jsonArray2.getLong(x);
+            System.out.println("最终每一个待查询的部门id:" + aLong);
+
+            //循环获取该部门下所有的人员id
+            String result = null;
+            try {
+                DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/user/listid");
+                OapiUserListidRequest req = new OapiUserListidRequest();
+                req.setDeptId(aLong);
+                OapiUserListidResponse rsp = client.execute(req, accessTokenService.getMuZhiAccessToken());
+                result = rsp.getBody();
+                System.out.println(result);
+            } catch (ApiException e) {
+                e.printStackTrace();
+            }
+            JSONObject jsonObject = JSON.parseObject(result);
+            JSONArray jsonArray = jsonObject.getJSONObject("result").getJSONArray("userid_list");
+            System.out.println("部门人员的id列表:" + jsonArray);
+
+
+
+            if (jsonArray.isEmpty()){
+                System.out.println("部门人员为空!");
+            }else {
+                System.out.println("部门人员不为空!");
+                for (int i = 0; jsonArray.size() > i; i ++){
+                    String userID = jsonArray.getString(i);
+                    System.out.println("userID:" + userID);
+
+                    //循环查询人员当天的上班打卡时间(有打卡时间记为出勤)
+                    try {
+                        DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/attendance/getcolumnval");
+                        OapiAttendanceGetcolumnvalRequest req = new OapiAttendanceGetcolumnvalRequest();
+                        //待查询人员的userid
+                        req.setUserid(userID);
+                        //TODO 考勤报表列定义查出来的上班打卡时间的列id(固定)
+//                    req.setColumnIdList("190133111");//牧之测试架构,考勤报表的上班打卡时间1的列id
+                        req.setColumnIdList("7186626");//东航架构,考勤报表的上班打卡时间1的列id
+                        //查询开始时间
+                    req.setFromDate(StringUtils.parseDateTime(timeNow));
+//                        req.setFromDate(StringUtils.parseDateTime("2022-11-18 10:17:03"));
+                        //查询结束时间
+                    req.setToDate(StringUtils.parseDateTime(timeNow));
+//                        req.setToDate(StringUtils.parseDateTime("2022-11-18 10:17:03"));
+                        OapiAttendanceGetcolumnvalResponse rsp = client.execute(req, accessTokenService.getMuZhiAccessToken());
+                        System.out.println(rsp.getBody());
+                        String string = rsp.getBody();
+                        JSONObject jsonObject1 = JSON.parseObject(string);
+                        JSONArray jsonArray1 = jsonObject1.getJSONObject("result").
+                                getJSONArray("column_vals").
+                                getJSONObject(0).
+                                getJSONArray("column_vals");
+                        String value = jsonArray1.getJSONObject(0).getString("value");
+                        System.out.println("当天上班打卡时间:" + value);
+                        if (value.isEmpty()){
+                            System.out.println("上班没有打卡时间!");
+                        }else {
+                            System.out.println("上班有打卡时间!");
+                            daka = daka + 1;
+                        }
+
+                    } catch (ApiException e) {
+                        e.printStackTrace();
+                    }
+                }
+            }
+        }
+
+        String dakaString = String.valueOf(daka);
+        System.out.println("当前部门的出勤数:" + dakaString);
+        return dakaString;
+    }
+
+    //===【最终接口】获取当前人员的主部门下的人员,并循环获取每个人员是否请假===
+//    @Async
+    @Override
+    public String getDeptQingJia(String userid){
+        System.out.println("宜搭传入的userid:" + userid);
+
+        //获取当天的日期时间
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        Date date = new Date();
+        String timeNow = simpleDateFormat.format(date);
+        System.out.println("当天的当前时间:" + timeNow);
+
+        //获取当前人员的主部门id
+        String mainDeptId = getMainDeptId(userid);
+        long mainDeptIdLong = Long.parseLong(mainDeptId);
+        System.out.println("转换成Long型的部门id:" + mainDeptIdLong);
+
+        List listDeptAll = new ArrayList();
+
+        //获取当前人员的所有父部门id列表
+        List deptIdList = getDeptIdList(userid);
+        System.out.println("当前人员所有父部门id列表:" + deptIdList);
+
+        //从右往左获取第三层级部门(即客户要求展示的部门层级id)
+        String a = deptIdList.get(deptIdList.size() - 3).toString();
+        long zhanshiDept = Long.parseLong(a);
+        System.out.println("展示主部门的id:" + zhanshiDept);
+
+        //部门id第一次汇总
+        listDeptAll.add(zhanshiDept);
+
+        //获取下一级子部门id列表
+        JSONObject jsonObject11 = null;
+        try {
+            DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/listsubid");
+            OapiV2DepartmentListsubidRequest req = new OapiV2DepartmentListsubidRequest();
+            //展示主部门的id
+            req.setDeptId(zhanshiDept);
+            OapiV2DepartmentListsubidResponse rsp = client.execute(req, accessTokenService.getMuZhiAccessToken());
+            String result = rsp.getBody();
+            jsonObject11 = JSON.parseObject(result);
+            System.out.println(result);
+        } catch (ApiException e) {
+            e.printStackTrace();
+        }
+        JSONArray jsonArray11 = jsonObject11.getJSONObject("result").getJSONArray("dept_id_list");
+
+        for (int i = 0; i < jsonArray11.size(); i++) {
+            String b = jsonArray11.getString(i);
+            long Dept2 = Long.parseLong(b);
+            System.out.println("逐层获取展示主部门下一层级的部门id:" + Dept2);
+            //部门id第二次汇总
+            listDeptAll.add(Dept2);
+
+            //获取下一级子部门id列表
+            JSONObject jsonObject22 = null;
+            try {
+                DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/listsubid");
+                OapiV2DepartmentListsubidRequest req = new OapiV2DepartmentListsubidRequest();
+                //第二次汇总部门的id
+                req.setDeptId(Dept2);
+                OapiV2DepartmentListsubidResponse rsp = client.execute(req, accessTokenService.getMuZhiAccessToken());
+                String result = rsp.getBody();
+                jsonObject22 = JSON.parseObject(result);
+                System.out.println(result);
+            } catch (ApiException e) {
+                e.printStackTrace();
+            }
+            JSONArray jsonArray22 = jsonObject22.getJSONObject("result").getJSONArray("dept_id_list");
+
+            for (int j = 0; j < jsonArray22.size(); j++) {
+                String c = jsonArray22.getString(j);
+                long Dept3 = Long.parseLong(c);
+                System.out.println("逐层获取第二次汇总部门的下一层级的部门id:" + Dept3);
+                //部门id第三次汇总
+                listDeptAll.add(Dept3);
+
+                //获取下一级子部门id列表
+                JSONObject jsonObject33 = null;
+                try {
+                    DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/listsubid");
+                    OapiV2DepartmentListsubidRequest req = new OapiV2DepartmentListsubidRequest();
+                    //第三次汇总部门的id
+                    req.setDeptId(Dept3);
+                    OapiV2DepartmentListsubidResponse rsp = client.execute(req, accessTokenService.getMuZhiAccessToken());
+                    String result = rsp.getBody();
+                    jsonObject33 = JSON.parseObject(result);
+                    System.out.println(result);
+                } catch (ApiException e) {
+                    e.printStackTrace();
+                }
+                JSONArray jsonArray33 = jsonObject33.getJSONObject("result").getJSONArray("dept_id_list");
+
+                for (int k = 0; k < jsonArray33.size(); k++) {
+                    String d = jsonArray33.getString(k);
+                    long Dept4 = Long.parseLong(d);
+                    System.out.println("逐层获取第三次汇总部门的下一层级的部门id:" + Dept4);
+                    //部门id第四次汇总
+                    listDeptAll.add(Dept4);
+
+                    //获取下一级子部门id列表
+                    JSONObject jsonObject44 = null;
+                    try {
+                        DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/department/listsubid");
+                        OapiV2DepartmentListsubidRequest req = new OapiV2DepartmentListsubidRequest();
+                        //第四次汇总部门的id
+                        req.setDeptId(Dept4);
+                        OapiV2DepartmentListsubidResponse rsp = client.execute(req, accessTokenService.getMuZhiAccessToken());
+                        String result = rsp.getBody();
+                        jsonObject44 = JSON.parseObject(result);
+                        System.out.println(result);
+                    } catch (ApiException e) {
+                        e.printStackTrace();
+                    }
+                    JSONArray jsonArray44 = jsonObject44.getJSONObject("result").getJSONArray("dept_id_list");
+                    System.out.println("第四次查询第五层级返回结果:" + jsonArray44);
+
+                    for (int l = 0; l < jsonArray44.size(); l++) {
+                        String e = jsonArray44.getString(l);
+                        long Dept5 = Long.parseLong(e);
+                        System.out.println("逐层获取第三次汇总部门的下一层级的部门id:" + Dept5);
+                        //部门id第五次汇总
+                        listDeptAll.add(Dept5);
+                    }
+                }
+            }
+        }
+        String s = listDeptAll.toString();
+        String s1 = s.replaceAll("\\ ", "");
+        JSONArray jsonArray2 = JSON.parseArray(s1);
+        System.out.println("@@@@@@@@@@@@@@@@" + jsonArray2);
+        System.out.println("******当前用户所属展示部门下的所有id列表******:" + listDeptAll);
+
+        //记录当前人员的主部门的请假数
+        int qingjia = 0;
+
+        for (int y = 0; y < jsonArray2.size(); y++) {
+            Long aLong = jsonArray2.getLong(y);
+            System.out.println("最终每一个待查询的部门id:" + aLong);
+
+            //循环获取该部门下所有的人员id
+            String result = null;
+            try {
+                DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/user/listid");
+                OapiUserListidRequest req = new OapiUserListidRequest();
+                req.setDeptId(aLong);
+                OapiUserListidResponse rsp = client.execute(req, accessTokenService.getMuZhiAccessToken());
+                result = rsp.getBody();
+                System.out.println(result);
+            } catch (ApiException e) {
+                e.printStackTrace();
+            }
+            JSONObject jsonObject = JSON.parseObject(result);
+            JSONArray jsonArray = jsonObject.getJSONObject("result").getJSONArray("userid_list");
+            System.out.println("部门人员的id列表:" + jsonArray);
+
+
+
+            if (jsonArray.isEmpty()){
+                System.out.println("部门人员为空!");
+            }else {
+                System.out.println("部门人员不为空!");
+                for (int i = 0; jsonArray.size() > i; i ++) {
+                    String userID = jsonArray.getString(i);
+                    System.out.println("userID:" + userID);
+
+                    //循环查询人员当天的请假数据
+                    try {
+                        DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/attendance/getleavetimebynames");
+                        OapiAttendanceGetleavetimebynamesRequest req = new OapiAttendanceGetleavetimebynamesRequest();
+                        //待查询人员的userid
+                        req.setUserid(userID);
+                        //TODO 获取报表假期数据的名称
+                        req.setLeaveNames("事假,病假,年假,调休,产假,陪产假,婚假");
+                        req.setFromDate(StringUtils.parseDateTime(timeNow));
+                        req.setToDate(StringUtils.parseDateTime(timeNow));
+                        OapiAttendanceGetleavetimebynamesResponse rsp = client.execute(req, accessTokenService.getMuZhiAccessToken());
+                        System.out.println(rsp.getBody());
+                        String string = rsp.getBody();
+                        JSONObject jsonObject1 = JSON.parseObject(string);
+
+                        JSONArray jsonArray1 = jsonObject1.getJSONObject("result").getJSONArray("columns");
+
+                        String value = null;
+                        float valueFloatAll = 0;
+                        for (int x = 0; jsonArray1.size() > x; x++){
+                            JSONArray columnvals = jsonArray1.getJSONObject(x).getJSONArray("columnvals");
+                            value = columnvals.getJSONObject(0).getString("value");
+
+                            System.out.println("当天上班请假时长:" + value);
+                            float valueFloat = Float.parseFloat(value);
+                            System.out.println("请假时长字段转换成float:" + valueFloat);
+                            valueFloatAll = valueFloatAll + valueFloat;
+                            System.out.println("各种假期请假小时数合计:" + valueFloatAll);
+                        }
+                        if (valueFloatAll == 0){
+                            System.out.println(userID + "当天没有请假!");
+                        }else {
+                            System.out.println(userID + "当天有请假!");
+                            qingjia = qingjia + 1;
+                        }
+
+                    } catch (ApiException e) {
+                        e.printStackTrace();
+                    }
+                }
+            }
+        }
+
+        String qingjiaString = String.valueOf(qingjia);
+        System.out.println("当前部门的请假数:" + qingjiaString);
+        return qingjiaString;
+    }
+
+    public static com.aliyun.dingtalkcalendar_1_0.Client createClient() throws Exception {
+        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config();
+        config.protocol = "https";
+        config.regionId = "central";
+        return new com.aliyun.dingtalkcalendar_1_0.Client(config);
+    }
+
+    //===【最终接口】获取钉钉日程信息===
+//    @Async
+    @Override
+    public Map getSchedule(String userid){
+        System.out.println("宜搭传入的userid:" + userid);
+
+        Date date = new Date();
+        System.out.println("date:" + date);
+
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(date);
+        calendar.set(Calendar.HOUR_OF_DAY,0);
+        calendar.set(Calendar.MINUTE,0);
+        calendar.set(Calendar.SECOND,0);
+        calendar.set(Calendar.MILLISECOND,0);
+        String FORMtime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar.getTime());
+        System.out.println("当天零点:" + FORMtime);
+
+        calendar.setTime(date);
+        calendar.set(Calendar.HOUR_OF_DAY,23);
+        calendar.set(Calendar.MINUTE,59);
+        calendar.set(Calendar.SECOND,59);
+        calendar.set(Calendar.MILLISECOND,0);
+        String TOtime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar.getTime());
+        System.out.println("当天24点:" + TOtime);
+
+        Date parse = null;
+        Date parse1 = null;
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        try {
+            parse = simpleDateFormat.parse(FORMtime);
+            parse1 = simpleDateFormat.parse(TOtime);
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+        System.out.println("当天零点(时间型):" + parse);
+        System.out.println("当天24点(时间型):" + parse1);
+
+        TimeZone timeZone = TimeZone.getTimeZone("UTC");
+        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
+        dateFormat.setTimeZone(timeZone);
+        String isoDateStart = dateFormat.format(parse);
+        System.out.println("iso时间(每天零点):" + isoDateStart);
+        String isoDateEnd = dateFormat.format(parse1);
+        System.out.println("iso时间(每天24点):" + isoDateEnd);
+
+        String isoDateNow = dateFormat.format(date);
+        System.out.println("iso时间(当前时间):" + isoDateNow);
+
+        //获取当前人员的unionid
+        String unionid = null;
+        try {
+            DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/get");
+            OapiV2UserGetRequest req = new OapiV2UserGetRequest();
+            //待查询的人员userid
+            req.setUserid(userid);
+            OapiV2UserGetResponse rsp = client.execute(req, accessTokenService.getMuZhiAccessToken());
+            String result = rsp.getBody();
+            System.out.println(result);
+            unionid = JSON.parseObject(result).getJSONObject("result").getString("unionid");
+            System.out.println("获取的人员unionid:" + unionid);
+        } catch (ApiException e) {
+            e.printStackTrace();
+        }
+
+        JSONObject jsonObject = null;
+        try {
+            com.aliyun.dingtalkcalendar_1_0.Client client = createClient();
+            com.aliyun.dingtalkcalendar_1_0.models.ListEventsHeaders listEventsHeaders = new com.aliyun.dingtalkcalendar_1_0.models.ListEventsHeaders();
+            listEventsHeaders.xAcsDingtalkAccessToken = accessTokenService.getMuZhiAccessToken();
+            com.aliyun.dingtalkcalendar_1_0.models.ListEventsRequest listEventsRequest = new com.aliyun.dingtalkcalendar_1_0.models.ListEventsRequest()
+                    //日程结束时间
+                    .setTimeMax(isoDateEnd)
+//                    .setTimeMax("2022-11-17T15:59:59Z")
+                    //日程开始时间
+                    .setTimeMin(isoDateNow)
+//                    .setTimeMin("2022-11-16T11:52:20Z")
+                    //最大返回记录数
+                    .setMaxResults(0);
+            ListEventsResponse listEventsResponse = client.listEventsWithOptions(unionid, "primary", listEventsRequest, listEventsHeaders, new RuntimeOptions());
+            String s = JSON.toJSONString(listEventsResponse.getBody());
+            jsonObject = JSON.parseObject(s);
+            System.out.println("接口object对象:" + jsonObject);
+        } catch (TeaException err) {
+            if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
+                // err 中含有 code 和 message 属性,可帮助开发定位问题
+            }
+        } catch (Exception _err) {
+            TeaException err = new TeaException(_err.getMessage(), _err);
+            if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
+                // err 中含有 code 和 message 属性,可帮助开发定位问题
+            }
+        }
+
+        Map map = new HashMap();
+
+        //查询当前时段的第一个日程,如果当前时段没有日程则返回文本提示:本日接下来时段没有日程!
+        JSONArray events = null;
+        try {
+            events = jsonObject.getJSONArray("events");
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+
+        if (events == null){
+            map.put("name","本日接下来时段没有日程!");
+            map.put("start","");
+            map.put("end","");
+            map.put("url","");
+        }else {
+            for (int i = 0; events.size() > i; i++) {
+                //日程名称
+                String summary = events.getJSONObject(i).getString("summary");
+                System.out.println("日程名称:" + "【" + summary + "】");
+                //日程开始时间
+                String startDateTime = events.getJSONObject(i).getJSONObject("start").getString("dateTime");
+                System.out.println("日程开始时间:" + startDateTime);
+                Date date1 = new DateTime(startDateTime).toDate();
+                String formatStartTime = simpleDateFormat.format(date1);
+                System.out.println("日程开始时间(正常格式):" + formatStartTime);
+                //日程结束时间
+                String endDateTime = events.getJSONObject(i).getJSONObject("end").getString("dateTime");
+                System.out.println("日程结束时间:" + endDateTime);
+                Date date2 = new DateTime(endDateTime).toDate();
+                String formatEndTime = simpleDateFormat.format(date2);
+                System.out.println("日程结束时间(正常格式):" + formatEndTime);
+
+                //日程id
+                String id = events.getJSONObject(i).getString("id");
+                System.out.println("日程id:" + id);
+
+                JSONObject jsonObject1 = null;
+                try {
+                    com.aliyun.dingtalkcalendar_1_0.Client client = createClient();
+                    com.aliyun.dingtalkcalendar_1_0.models.GetEventHeaders getEventHeaders = new com.aliyun.dingtalkcalendar_1_0.models.GetEventHeaders();
+                    getEventHeaders.xAcsDingtalkAccessToken = accessTokenService.getMuZhiAccessToken();
+                    com.aliyun.dingtalkcalendar_1_0.models.GetEventRequest getEventRequest = new com.aliyun.dingtalkcalendar_1_0.models.GetEventRequest();
+                    GetEventResponse primary = client.getEventWithOptions(unionid, "primary", id, getEventRequest, getEventHeaders, new RuntimeOptions());
+                    String s = JSON.toJSONString(primary.getBody());
+                    jsonObject1 = JSON.parseObject(s);
+                    System.out.println("接口object对象:" + jsonObject1);
+                } catch (TeaException err) {
+                    if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
+                        // err 中含有 code 和 message 属性,可帮助开发定位问题
+                    }
+                } catch (Exception _err) {
+                    TeaException err = new TeaException(_err.getMessage(), _err);
+                    if (!com.aliyun.teautil.Common.empty(err.code) && !com.aliyun.teautil.Common.empty(err.message)) {
+                        // err 中含有 code 和 message 属性,可帮助开发定位问题
+                    }
+                }
+
+                String url = "";
+                try {
+                    JSONObject onlineMeetingInfo = jsonObject1.getJSONObject("onlineMeetingInfo");
+                    url = onlineMeetingInfo.getString("url");
+                    System.out.println("在线会议地址url:" + url);
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+
+//            map.put(i,"【" + summary + "】" + "[" + formatStartTime + "][" + formatEndTime + "]");
+                map.put("name", summary);
+                map.put("start", formatStartTime);
+                map.put("end", formatEndTime);
+                map.put("url", url);
+            }
+        }
+        System.out.println("map对象:" + map);
+
+        return map;
+    }
+
+    //获取天气
+//    @Async
+    @Override
+    public Map getWeather(){
+        String urlString = "https://www.weatherol.cn/api/home/getCurrAnd15dAnd24h?cityid=101010100";
+
+        String res = "";
+        try {
+            URL url = new URL(urlString);
+            java.net.HttpURLConnection conn = (java.net.HttpURLConnection)url.openConnection();
+            conn.setDoOutput(true);
+            conn.setRequestMethod("GET");
+            java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(conn.getInputStream(),"UTF-8"));
+            String line;
+            while ((line = in.readLine()) != null) {
+                res += line;
+            }
+            in.close();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        JSONObject jsonObject = JSON.parseObject(res);
+        JSONObject jsonObject1 = jsonObject.getJSONObject("data").getJSONObject("current").getJSONObject("current");
+        //温度
+        String temperature = jsonObject1.getString("temperature");
+        //天气
+        String weather = jsonObject1.getString("weather");
+        //风向
+        String winddir = jsonObject1.getString("winddir");
+
+        Map map = new HashMap();
+        map.put("temperature",temperature);
+        map.put("weather",weather);
+        map.put("winddir",winddir);
+
+        return map;
+    }
+}

+ 57 - 0
src/main/resources/application.properties

@@ -0,0 +1,57 @@
+server.port=8096
+server.servlet.context-path=/donghang
+
+server.tomcat.uri-encoding=UTF-8
+
+## 服务名
+#spring.application.name=donghang-yd
+## 环境设置:dev、test、prod(开发环境、测试环境、生产环境)
+#spring.profiles.active=dev
+
+# mysql数据库连接
+# 本地测试数据库
+#spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
+#spring.datasource.url=jdbc:mysql://localhost:3306/dingtalk?serverTimezone=GMT%2B8
+#spring.datasource.username=root
+#spring.datasource.password=123456
+
+# 云璞【47.98.130.40服务器】测试数据库
+#spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
+#spring.datasource.url=jdbc:mysql://47.98.130.40:3306/dingtalk?serverTimezone=GMT%2B8
+#spring.datasource.username=root
+#spring.datasource.password=123456
+
+#定时同步
+
+#配置日志,当前为默认的控制台输出,也可以用log4j
+#mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
+
+#控制台显示sql
+#spring.jpa.show-sql=true
+#更新或者创建数据表结构
+#spring.jpa.hibernate.ddl-auto=update
+
+#返回json的全局时间格式
+spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
+spring.jackson.time-zone=GMT+8
+#配置mapper xml文件的路径
+#mybatis-plus.mapper-locations=classpath:com/muzhi/lz/mapper/xml/*.xml
+
+#mybatis-plus.config-location=classpath:mybatis/mybatis-config.xml
+
+#禁用缓存
+spring.thymeleaf.cache=false
+#spring.thymeleaf.mode= LEGACYHTML5
+#spring.resources.chain.strategy.content.enabled=true
+#spring.resources.chain.strategy.content.paths=/**
+#spring.thymeleaf.check-template = true
+#spring.thymeleaf.servlet.content-type=text/html
+#spring.thymeleaf.enabled = true
+#spring.thymeleaf.encoding = UTF-8
+#spring.thymeleaf.prefix = classpath:/static/
+#spring.thymeleaf.suffix = .html
+
+#定义日期提交的格式(日期的格式化):SpingMVC将页面提交的值需要转换为指定类型;默认的是yyyy/MM/dd
+#spring.mvc.date-format=yyyy-MM-dd
+
+spring.resources.static-locations=classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/,classpath:/templates/

+ 90 - 0
src/test/java/com/muzhi/donghang/APITest/Test1.java

@@ -0,0 +1,90 @@
+package com.muzhi.donghang.APITest;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.dingtalk.api.DefaultDingTalkClient;
+import com.dingtalk.api.DingTalkClient;
+import com.dingtalk.api.request.OapiAttendanceGetcolumnvalRequest;
+import com.dingtalk.api.response.OapiAttendanceGetcolumnvalResponse;
+import com.muzhi.donghang.service.AccessTokenService;
+import com.taobao.api.ApiException;
+import com.taobao.api.internal.util.StringUtils;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+
+@SpringBootTest
+public class Test1 {
+
+    @Autowired
+    private AccessTokenService accessTokenService;
+
+    @Test
+    public void panduan(){
+        //判断日期是否为周六周日
+        String date = "2022-10-08 00:00:00";
+        DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
+        Date date1 = null;
+        try {
+            date1 = format.parse(date);
+            System.out.println("date1:" + date1);
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(date1);
+
+        if (calendar.get(Calendar.DAY_OF_WEEK)==Calendar.SATURDAY||calendar.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY){
+            System.out.println("当前日期为周六周日!");
+        }else {
+            System.out.println("当前日期为工作日");
+        }
+    }
+
+    @Test
+    public void date(){
+        //获取当天前一天的零点零分零秒
+        Date Date = new Date(System.currentTimeMillis());
+        System.out.println("当前时间:" + Date);
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(Date);
+        //前一天
+        calendar.add(Calendar.DAY_OF_MONTH,-1);
+        calendar.set(Calendar.HOUR_OF_DAY,0);
+        calendar.set(Calendar.MINUTE,0);
+        calendar.set(Calendar.SECOND,0);
+        calendar.set(Calendar.MILLISECOND,0);
+        String time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar.getTime());
+        System.out.println("前一天零点:" + time);
+
+        Calendar calendar111 = Calendar.getInstance();
+        calendar111.setTime(Date);
+        //前一个月第一天
+        calendar111.add(Calendar.MONTH,-1);
+        calendar111.set(Calendar.DAY_OF_MONTH,1);
+        calendar111.set(Calendar.HOUR_OF_DAY,0);
+        calendar111.set(Calendar.MINUTE,0);
+        calendar111.set(Calendar.SECOND,0);
+        calendar111.set(Calendar.MILLISECOND,0);
+        String FORMtime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar111.getTime());
+        System.out.println("前一个月第一天零点:" + FORMtime);
+
+        Calendar calendar222 = Calendar.getInstance();
+        int month222 = calendar222.get(Calendar.MONTH);
+        //前一个月最后一天
+        calendar222.set(Calendar.MONTH,month222-1);
+        calendar222.set(Calendar.DAY_OF_MONTH,calendar222.getActualMaximum(Calendar.DAY_OF_MONTH));
+        calendar222.set(Calendar.HOUR_OF_DAY,0);
+        calendar222.set(Calendar.MINUTE,0);
+        calendar222.set(Calendar.SECOND,0);
+        calendar222.set(Calendar.MILLISECOND,0);
+        String TOtime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar222.getTime());
+        System.out.println("前一个月最后一天零点:" + TOtime);
+    }
+}

+ 13 - 0
src/test/java/com/muzhi/donghang/TestApplicationTests.java

@@ -0,0 +1,13 @@
+package com.muzhi.donghang;
+
+import org.junit.jupiter.api.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+
+@SpringBootTest
+class TestApplicationTests {
+
+    @Test
+    void contextLoads() {
+    }
+
+}