zhangkan %!s(int64=2) %!d(string=hai) anos
achega
b0dd6fd520

+ 21 - 0
main/java/com/muzhi/huanshi/HuanshiApplication.java

@@ -0,0 +1,21 @@
+package com.muzhi.huanshi;
+
+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.simaner.mapper")
+@EnableAsync//开启异步注解
+@SpringBootApplication(exclude= DataSourceAutoConfiguration.class)//启动时不加载数据库(exclude= DataSourceAutoConfiguration.class)
+@EnableScheduling//开启定时任务
+//@ComponentScan(basePackages = {"com.muzhi"})
+public class HuanshiApplication {
+
+    public static void main(String[] args){
+        SpringApplication.run(HuanshiApplication.class, args);
+    }
+
+}

+ 77 - 0
main/java/com/muzhi/huanshi/common/R.java

@@ -0,0 +1,77 @@
+package com.muzhi.huanshi.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(String key, String value){
+        this.data.put(key, value);
+        return this;
+    }
+
+    public R data(Map<String, Object> map){
+        this.setData(map);
+        return this;
+    }
+}

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

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

+ 43 - 0
main/java/com/muzhi/huanshi/controller/AccessTokenController.java

@@ -0,0 +1,43 @@
+package com.muzhi.huanshi.controller;
+
+import com.muzhi.huanshi.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(斯曼尔)
+    @ApiOperation(value = "获取钉钉中的access_token")
+    @GetMapping("getAccessToken")
+    public String getAccessToken(){
+
+        String accessToken = AccessTokenService.getAccessToken();
+        return accessToken;
+    }
+
+    //获取钉钉中的access_token(环世TB应用)
+    @ApiOperation(value = "获取钉钉中的access_token")
+    @GetMapping("getAppToken")
+    public String getAppToken(){
+
+        String AppToken = AccessTokenService.getAppToken();
+        return AppToken;
+    }
+}

+ 43 - 0
main/java/com/muzhi/huanshi/controller/DingOaController.java

@@ -0,0 +1,43 @@
+package com.muzhi.huanshi.controller;
+
+import com.muzhi.huanshi.service.DingOaService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.web.bind.annotation.*;
+
+
+@Api(description = "钉钉")
+@RestController
+@RequestMapping("/dingservice")
+//@CrossOrigin//解决跨域问题
+public class DingOaController {
+
+    @Autowired
+    private DingOaService dingOaService;
+
+    //获取钉钉人员-同步至宜搭人员信息表
+    @ApiOperation(value = "获取钉钉人员-同步至宜搭人员信息表")
+    @PostMapping("addDingdingRenyuan")
+//    @Scheduled(cron = "0 10 23 * * ?")//每天23:10触发(也就是凌晨23点10分触发)
+//    @Scheduled(cron = "0 0/10 * * * ?")//每10分钟执行一次
+//    @Scheduled(cron = "0 */10 * * * ?")//每隔10分钟执行一次
+    public String getKaoqin(){
+
+        String addDingdingRenyuan = dingOaService.addDingdingRenyuan();
+        return addDingdingRenyuan;
+    }
+
+    //统计钉钉考勤、请假、TB项目/任务工时
+    @ApiOperation(value = "统计钉钉考勤、请假、TB项目/任务工时表")
+    @PostMapping("allTongji")
+//    @Scheduled(cron = "0 30 10 * * ?")//每天01:30触发(也就是凌晨01点30分触发)
+//    @Scheduled(cron = "0 0/10 * * * ?")//每10分钟执行一次
+//    @Scheduled(cron = "0 */10 * * * ?")//每隔10分钟执行一次
+    public String allTongji(int type){
+
+        String allTongji = dingOaService.allTongji(type);
+        return allTongji;
+    }
+}

+ 14 - 0
main/java/com/muzhi/huanshi/service/AccessTokenService.java

@@ -0,0 +1,14 @@
+package com.muzhi.huanshi.service;
+
+/**
+ * @Author ZhangKan
+ * @Data 15:34
+ */
+public interface AccessTokenService {
+
+    //获取access_token的方法(环世)
+    String getAccessToken();
+
+    //获取access_token的方法(环世TB应用)
+    String getAppToken();
+}

+ 14 - 0
main/java/com/muzhi/huanshi/service/DingOaService.java

@@ -0,0 +1,14 @@
+package com.muzhi.huanshi.service;
+
+/**
+ * @Author ZhangKan
+ * @Data 15:34
+ */
+public interface DingOaService {
+
+    //获取钉钉人员-同步至宜搭人员信息表
+    String addDingdingRenyuan();
+
+    //统计钉钉考勤、请假、TB项目/任务工时
+    String allTongji(int type);
+}

+ 86 - 0
main/java/com/muzhi/huanshi/service/impl/AccessTokenServiceImpl.java

@@ -0,0 +1,86 @@
+package com.muzhi.huanshi.service.impl;
+
+import com.auth0.jwt.JWT;
+import com.auth0.jwt.algorithms.Algorithm;
+import com.dingtalk.api.DefaultDingTalkClient;
+import com.dingtalk.api.request.OapiGettokenRequest;
+import com.dingtalk.api.response.OapiGettokenResponse;
+import com.muzhi.huanshi.service.AccessTokenService;
+import com.taobao.api.ApiException;
+import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
+
+import java.util.Date;
+
+
+/**
+ * @Author ZhangKan
+ * @Data 15:39
+ */
+
+@Service
+public class AccessTokenServiceImpl implements AccessTokenService {
+
+    //环世
+    //APPKEY
+    private static String APPKEY = "dingobpyhlo3vioasyo9";
+    //APPSECRET
+    private static String APPSECRET = "RNLnat9hiz8zQGSyOhLf1GEAx9qS66_VoFZFYJTwT_uy2aB_5sEoByTdd7oWc3Y0";
+    //AgenthId:2769663130
+
+    public static String accessToken = null;
+
+
+
+    //获取access_token的方法(环世)
+    @Override
+    public String getAccessToken() {
+        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;
+    }
+
+    public static final Long   EXPIRES_IN = 1 * 3600 * 1000L;
+    public static final String TOKEN_APPID = "_appId";
+
+    public static String appId = "6555d03b73aa2fd874f4cc12";
+    public static String appSecret = "HDMqRuUY08eY1FtEzxs0hNB6A2Tq58aL";
+    //获取access_token的方法(环世TB应用)
+    @Override
+    public String getAppToken() {
+        if (StringUtils.isEmpty(appId) || StringUtils.isEmpty(appSecret)) {
+            return null;
+        }
+
+        Algorithm algorithm = Algorithm.HMAC256(appSecret);
+        long timestamp = System.currentTimeMillis();
+        Date issuedAt = new Date(timestamp);
+        Date expiresAt = new Date(timestamp + EXPIRES_IN);
+
+//        return JWT.create()
+//                .withClaim(TOKEN_APPID, appId)
+//                .withIssuedAt(issuedAt)
+//                .withExpiresAt(expiresAt)
+//                .sign(algorithm);
+
+        String sign = JWT.create()
+                .withClaim(TOKEN_APPID, appId)
+                .withIssuedAt(issuedAt)
+                .withExpiresAt(expiresAt)
+                .sign(algorithm);
+        System.out.println("环世TB应用的AccessToken:" + sign);
+
+        return sign;
+
+    }
+}

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 2921 - 0
main/java/com/muzhi/huanshi/service/impl/DingOaServiceImpl.java


+ 57 - 0
main/resources/application.properties

@@ -0,0 +1,57 @@
+server.port=8107
+server.servlet.context-path=/huanshi
+
+server.tomcat.uri-encoding=UTF-8
+
+## 服务名
+#spring.application.name=simaner-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.97.181.40:3306/dingtalk?serverTimezone=GMT%2B8
+#spring.datasource.username=root
+#spring.datasource.password=cp-root@2022++
+
+#定时同步
+
+#配置日志,当前为默认的控制台输出,也可以用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/

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 3321 - 0
test/java/com/muzhi/huanshi/APITest/Test1.java


+ 13 - 0
test/java/com/muzhi/huanshi/TestApplicationTests.java

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