Browse Source

项目迁移

zhang-kan-kan 2 years ago
commit
1504428213

+ 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/

+ 367 - 0
pom.xml

@@ -0,0 +1,367 @@
+<?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.lingai</groupId>
+    <artifactId>lingai</artifactId>
+<!--    <packaging>jar</packaging>-->
+    <version>1.0-SNAPSHOT</version>
+    <name>lingai</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>
+
+        <!--MD5加密-->
+        <dependency>
+            <groupId>org.apache.directory.studio</groupId>
+            <artifactId>org.apache.commons.codec</artifactId>
+            <version>1.8</version>
+        </dependency>
+
+        <!--Map缓存方法:可设置Map中的Entry在一段时间后自动过期-->
+        <dependency>
+            <groupId>net.jodah</groupId>
+            <artifactId>expiringmap</artifactId>
+            <version>0.5.8</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>
+
+        <!--日期工具-->
+        <dependency>
+            <groupId>cn.hutool</groupId>
+            <artifactId>hutool-all</artifactId>
+            <version>4.6.8</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>

+ 21 - 0
src/main/java/com/muzhi/lingai/LingAiApplication.java

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

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

@@ -0,0 +1,77 @@
+package com.muzhi.lingai.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
src/main/java/com/muzhi/lingai/common/ResultCode.java

@@ -0,0 +1,12 @@
+package com.muzhi.lingai.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/lingai/controller/AccessTokenController.java

@@ -0,0 +1,34 @@
+package com.muzhi.lingai.controller;
+
+import com.muzhi.lingai.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;
+    }
+}

+ 57 - 0
src/main/java/com/muzhi/lingai/controller/DingOaController.java

@@ -0,0 +1,57 @@
+package com.muzhi.lingai.controller;
+
+import com.muzhi.lingai.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 = "获取售后宝接口授权码")
+    @GetMapping("getShouhoubaoAccessToken")
+//    @Scheduled(cron = "0 10 0 * * ?")//每天00:10触发(也就是凌晨0点10分触发)
+//    @Scheduled(cron = "0 0/10 * * * ?")//每10分钟执行一次
+//    @Scheduled(cron = "0 */10 * * * ?")//每隔10分钟执行一次
+    public String getWangdiantongStocks(){
+
+        String shouhoubaoAccessToken = dingOaService.getShouhoubaoAccessToken();
+        return shouhoubaoAccessToken;
+    }
+
+    //同步客户信息至售后宝
+    @ApiOperation(value = "同步客户信息至售后宝")
+    @PostMapping("tongbuKehu")
+//    @Scheduled(cron = "0 10 0 * * ?")//每天00:10触发(也就是凌晨0点10分触发)
+//    @Scheduled(cron = "0 0/10 * * * ?")//每10分钟执行一次
+//    @Scheduled(cron = "0 */10 * * * ?")//每隔10分钟执行一次
+    public String tongbuKehu(String khbh,String khmc,String khlxrList,String khlxrdhList,
+                             String khlxrzwList,String khdz,
+                             String userid,String khfzrxm,String htqydw){
+
+        String s = dingOaService.tongbuKehu(khbh, khmc, khlxrList, khlxrdhList, khlxrzwList, khdz, userid, khfzrxm, htqydw);
+        return s;
+    }
+
+    //创建售后宝工单
+    @ApiOperation(value = "创建售后宝工单")
+    @PostMapping("createGongdan")
+    public String createGongdan(String khbh,String khmc,String khdz,String khlxr,String khlxrdh,String gdid,String gdmc,
+                                String cpmcList,String cpppList,String cpxhList,String cpazwzList,
+                                String sdqkList,String azrq){
+
+        String s = dingOaService.createGongdan(khbh, khmc, khdz, khlxr, khlxrdh, gdid, gdmc,
+                cpmcList, cpppList, cpxhList, cpazwzList, sdqkList, azrq);
+        return s;
+    }
+}

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

@@ -0,0 +1,11 @@
+package com.muzhi.lingai.service;
+
+/**
+ * @Author ZhangKan
+ * @Data 15:34
+ */
+public interface AccessTokenService {
+
+    //获取access_token的方法(美邸艾架构)
+    String getAccessToken();
+}

+ 21 - 0
src/main/java/com/muzhi/lingai/service/DingOaService.java

@@ -0,0 +1,21 @@
+package com.muzhi.lingai.service;
+
+/**
+ * @Author ZhangKan
+ * @Data 15:34
+ */
+public interface DingOaService {
+
+    //获取售后宝接口授权码
+    String getShouhoubaoAccessToken();
+
+    //同步客户信息至售后宝
+    String tongbuKehu(String khbh,String khmc,String khlxrList,String khlxrdhList,
+                      String khlxrzwList,String khdz,
+                      String userid,String khfzrxm,String htqydw);
+
+    //创建售后宝工单
+    String createGongdan(String khbh,String khmc,String khdz,String khlxr,String khlxrdh,String gdid,String gdmc,
+                         String cpmcList,String cpppList,String cpxhList,String cpazwzList,
+                         String sdqkList,String azrq);
+}

+ 46 - 0
src/main/java/com/muzhi/lingai/service/impl/AccessTokenServiceImpl.java

@@ -0,0 +1,46 @@
+package com.muzhi.lingai.service.impl;
+
+import com.dingtalk.api.DefaultDingTalkClient;
+import com.dingtalk.api.request.OapiGettokenRequest;
+import com.dingtalk.api.response.OapiGettokenResponse;
+import com.muzhi.lingai.service.AccessTokenService;
+import com.taobao.api.ApiException;
+import org.springframework.stereotype.Service;
+
+
+/**
+ * @Author ZhangKan
+ * @Data 15:39
+ */
+
+@Service
+public class AccessTokenServiceImpl implements AccessTokenService {
+
+    //另爱
+    //APPKEY
+    private static String APPKEY = "dingwsnwdv2n8r8on4ds";
+    //APPSECRET
+    private static String APPSECRET = "D37UKaFTpFgWaO60BWcRrNBdoBqh2arcLFsGA5QEGx3RfjRehL_NLXjZD2835Bk9";
+    //AgenthId:2184795806
+
+    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;
+    }
+}

+ 746 - 0
src/main/java/com/muzhi/lingai/service/impl/DingOaServiceImpl.java

@@ -0,0 +1,746 @@
+package com.muzhi.lingai.service.impl;
+
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.aliyun.dingtalkyida_1_0.models.CreateOrUpdateFormDataResponse;
+import com.aliyun.dingtalkyida_1_0.models.GetFormDataByIDResponse;
+import com.aliyun.tea.TeaException;
+import com.aliyun.teautil.models.RuntimeOptions;
+import com.muzhi.lingai.service.AccessTokenService;
+import com.muzhi.lingai.service.DingOaService;
+import lombok.extern.slf4j.Slf4j;
+import okhttp3.*;
+import org.apache.commons.codec.digest.DigestUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+
+@Service
+@Slf4j
+public class DingOaServiceImpl implements DingOaService {
+
+    @Autowired
+    private AccessTokenService accessTokenService;
+
+    //宜搭接口调用
+    public static com.aliyun.dingtalkyida_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.dingtalkyida_1_0.Client(config);
+    }
+
+    //售后宝接口授权码接口
+    public JSONObject getToken(){
+
+        //MD5加密
+        /*明文
+         * timestamp毫秒级时间戳
+         * */
+        //当前时间的时间戳
+        long timeMillis = System.currentTimeMillis();
+        String timestamp = String.valueOf(timeMillis);
+        log.info("当前时间的时间戳(毫秒级):" + timestamp);
+
+        /*秘钥
+         * AppSecret应用秘钥
+         * */
+        String AppSecret = "f7585e1f2c4c25682f407af23b7ff7d5f21f4f9e3715c294";
+
+        //加密后的字符串
+        String encodeStr= DigestUtils.md5Hex(AppSecret + "_" + timestamp);
+        log.info("MD5加密后的字符串encodeStr:" + encodeStr);
+
+        Map mapMY = new HashMap();
+        mapMY.put("appKey","shbqv00tso4dg5kcjz");
+        mapMY.put("timestamp",timestamp);
+        mapMY.put("verifyCode",encodeStr);
+        String parmsStr = JSON.toJSONString(mapMY);
+        log.info("封装秘钥参数parmsStr:" + parmsStr);
+
+        //售后宝【接口授权】
+        //授权码
+        String access_token = null;
+        //失效时间
+        String expire_time = null;
+        try {
+            OkHttpClient client = new OkHttpClient().newBuilder()
+                    .build();
+            MediaType mediaType = MediaType.parse("application/json");
+            RequestBody body = RequestBody.create(mediaType, parmsStr);
+            Request request = new Request.Builder()
+                    .url("https://oapi.shb.ltd/service/auth/get_access_token")
+                    .method("POST", body)
+                    .addHeader("Content-Type", "application/json")
+                    .addHeader("Cookie", "acw_tc=0a45662a16728986832314856e80f39124201b89184960430078b3ebfda740")
+                    .build();
+
+            Response response = client.newCall(request).execute();
+            String responseBody = response.body().string();
+            log.info("售后宝【接口授权】返回信息:" + responseBody);
+            String substring1 = responseBody.substring(1, responseBody.length() - 1);
+            log.info("去除首尾双引号后的返回信息:" + substring1);
+            String substring2 = substring1.replaceAll("\\\\", "");
+            log.info("去除转义字符后的返回信息:" + substring2);
+
+            JSONObject jsonObject = JSON.parseObject(substring2);
+            JSONObject data = jsonObject.getJSONObject("data");
+            //授权码
+            access_token = data.getString("access_token");
+            //失效时间
+            expire_time = data.getString("expire_time");
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        long endLong = new Long(expire_time);
+        //将时间戳转换为时间
+        Date endDate = new Date(endLong);
+        System.out.println("授权码失效时间(时间型):" + endDate);
+        //将时间调整为yyyy-MM-dd HH:mm:ss时间样式
+        String endString = simpleDateFormat.format(endDate);
+        System.out.println("授权码失效时间(时间样式):" + endString);
+        log.info("【授权码】:" + access_token + "【失效时间】:" + endString);
+
+        Map map = new HashMap();
+        map.put("token", access_token);
+        map.put("endTime", endString);
+        String jsonString = JSON.toJSONString(map);
+        JSONObject jsonObjectToken = JSON.parseObject(jsonString);
+        System.out.println("封装的售后宝接口返回的授权码和失效时间的Map对象:" + jsonObjectToken);
+
+        return jsonObjectToken;
+    }
+
+    //获取售后宝接口授权码
+    @Override
+    public String getShouhoubaoAccessToken(){
+
+        //查询表单实例详情
+        JSONObject jsonObject = null;
+        try {
+            com.aliyun.dingtalkyida_1_0.Client client = createClient();
+            com.aliyun.dingtalkyida_1_0.models.GetFormDataByIDHeaders getFormDataByIDHeaders = new com.aliyun.dingtalkyida_1_0.models.GetFormDataByIDHeaders();
+            getFormDataByIDHeaders.xAcsDingtalkAccessToken = accessTokenService.getAccessToken();
+            com.aliyun.dingtalkyida_1_0.models.GetFormDataByIDRequest getFormDataByIDRequest = new com.aliyun.dingtalkyida_1_0.models.GetFormDataByIDRequest()
+                    .setSystemToken("RH766AC1Z0P6IBWRFIA885XCULUV275UHT5CLYF")
+                    .setUserId("yida_pub_account")
+                    .setAppType("APP_EXJ5WMWZ18FS1F2UFOHN");
+            //TODO 【勿动】审批实例ID
+            GetFormDataByIDResponse formDataByIDWithOptions = client.getFormDataByIDWithOptions("FINST-SD866HA1JEBAFL9O7EK0N5AY3RH32A27ZH8HLLH9", getFormDataByIDRequest, getFormDataByIDHeaders, new RuntimeOptions());
+            String s = JSON.toJSONString(formDataByIDWithOptions.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 属性,可帮助开发定位问题
+            }
+        }
+
+        JSONObject formData = jsonObject.getJSONObject("formData");
+        //宜搭存储的授权码
+        String textField_lgstof07 = formData.getString("textField_lgstof07");
+        System.out.println("宜搭存储的授权码:" + textField_lgstof07);
+        //失效时间
+        long dateField_lgstof08 = formData.getLong("dateField_lgstof08");
+        System.out.println("失效时间:" + dateField_lgstof08);
+
+
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        //将时间戳转换为时间
+        Date shixiaoDate = new Date(dateField_lgstof08);
+        System.out.println("失效时间(时间型):" + shixiaoDate);
+        //将时间调整为yyyy-MM-dd HH:mm:ss时间样式
+        String shixiaoString = simpleDateFormat.format(shixiaoDate);
+        System.out.println("失效时间(时间样式):" + shixiaoString);
+
+        //当前时间
+        Date nowTime = new Date();
+        //比较两个时间,如果返回1说明shixiaoDate>nowTime -1说明小于  0说明等于
+        int sign = shixiaoDate.compareTo(nowTime);
+        System.out.println("时间比较结果(1失效时间大于当前时间,即为有效;-1失效时间小于当前时间,即为过期):" + sign);
+        if (sign > 0){
+            System.out.println("token在有效期~~~");
+
+            return textField_lgstof07;
+        }else {
+            System.out.println("token已过期!!!");
+
+            log.info("======开始执行调用售后宝授权码接口======");
+            JSONObject token = getToken();
+            String token1 = token.getString("token");
+            System.out.println("获取最新的售后宝授权码:" + token1);
+            String endTime = token.getString("endTime");
+
+            long time = 0;
+            try {
+                time = simpleDateFormat.parse(endTime).getTime();
+            }catch (Exception e){
+                e.printStackTrace();
+            }
+
+            //判断宜搭授权码页面是否有当前有效的时间
+            /*同步至宜搭*/
+            Map map = new HashMap();
+            //最新授权码
+            map.put("textField_lgstof07", token1);
+            //失效时间
+            map.put("dateField_lgstof08", time);
+
+            String mapJson = JSON.toJSONString(map);
+            System.out.println("mapJson:" + mapJson);
+
+            //宜搭表单判断查询条件
+            Map map1 = new HashMap();
+            //字段编号
+            map1.put("key","textField_lh8hyihp");
+            //同步类型
+            map1.put("value", "系统同步");
+            //控件类型
+            map1.put("type","TEXT");
+            //逻辑判断符
+            map1.put("operator","eq");
+            //控件名称
+            map1.put("componentName","TextField");
+
+            List list11 = new ArrayList();
+            list11.add(map1);
+
+            String listJson = JSON.toJSONString(list11);
+            System.out.println("查询条件listJson:" + listJson);
+
+
+            //新增或更新表单实例【宜搭】
+            try {
+                com.aliyun.dingtalkyida_1_0.Client client11 = createClient();
+                com.aliyun.dingtalkyida_1_0.models.CreateOrUpdateFormDataHeaders createOrUpdateFormDataHeaders = new com.aliyun.dingtalkyida_1_0.models.CreateOrUpdateFormDataHeaders();
+                createOrUpdateFormDataHeaders.xAcsDingtalkAccessToken = accessTokenService.getAccessToken();
+                com.aliyun.dingtalkyida_1_0.models.CreateOrUpdateFormDataRequest createOrUpdateFormDataRequest = new com.aliyun.dingtalkyida_1_0.models.CreateOrUpdateFormDataRequest()
+                        //应用秘钥
+                        .setSystemToken("RH766AC1Z0P6IBWRFIA885XCULUV275UHT5CLYF")
+                        //表单编码
+                        .setFormUuid("FORM-NO766591UX3A9LC18PX8PB38WZB52I20OTSGL6")
+                        .setUserId("yida_pub_account")
+                        .setSearchCondition(listJson)
+                        //应用编码
+                        .setAppType("APP_EXJ5WMWZ18FS1F2UFOHN")
+                        .setFormDataJson(mapJson);
+
+                CreateOrUpdateFormDataResponse orUpdateFormDataWithOptions = client11.createOrUpdateFormDataWithOptions(createOrUpdateFormDataRequest, createOrUpdateFormDataHeaders, new RuntimeOptions());
+                String s = JSON.toJSONString(orUpdateFormDataWithOptions.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 属性,可帮助开发定位问题
+                }
+
+            }
+            /*同步至宜搭*/
+
+            return token1;
+        }
+    }
+
+
+    //根据姓名获取售后宝人员id
+    public String getSHBid(String userName){
+
+        //获取售后宝授权码
+        String shouhoubaoAccessToken = getShouhoubaoAccessToken();
+
+        int pageNum = 1;
+        int pageSize = 50;
+
+        //根据售人员姓名进行匹配查询售后宝人员id
+//        String userName = "牧之";
+        List list = new ArrayList();
+        list.add(userName);
+
+        Map map = new HashMap();
+        map.put("pageNum",pageNum);
+        map.put("pageSize",pageSize);
+        map.put("userNameList",list);
+
+        //根据售售后宝人员userid进行匹配查询售后宝人员信息
+//        String userid = "f58e62b5-a843-11ed-bdbf-00163e179ed7";
+//        List list = new ArrayList();
+//        list.add(userid);
+//
+//        Map map = new HashMap();
+//        map.put("pageNum",pageNum);
+//        map.put("pageSize",pageSize);
+//        map.put("userIds",list);
+
+        String bodyStr = JSON.toJSONString(map);
+
+        String userId = null;
+
+        OkHttpClient client = new OkHttpClient().newBuilder()
+                .build();
+        MediaType mediaType = MediaType.parse("application/json");
+        RequestBody body = RequestBody.create(mediaType, bodyStr);
+        Request request = new Request.Builder()
+                .url("https://oapi.shb.ltd/service/user/get_user_params?accessToken="+ shouhoubaoAccessToken)
+                .method("POST", body)
+                .addHeader("Content-Type", "application/json")
+                .build();
+
+        try {
+            Response response = client.newCall(request).execute();
+            String responseBody = response.body().string();
+            log.info("售后宝【人员列表】返回信息:" + responseBody);
+            String substring1 = responseBody.substring(1, responseBody.length() - 1);
+            log.info("去除首尾双引号后的返回信息:" + substring1);
+            String substring2 = substring1.replaceAll("\\\\", "");
+            log.info("去除转义字符后的返回信息:" + substring2);
+
+            JSONObject jsonObject = JSON.parseObject(substring2);
+            JSONObject data = jsonObject.getJSONObject("data");
+//            System.out.println("data===" + data);
+
+            userId = data.getJSONArray("list").getJSONObject(0).getString("userId");
+            System.out.println("售后宝人员userId:" + userId);
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+
+        return userId;
+    }
+
+    //根据客户编号查询售后宝客户是否存在
+    public Boolean getKehuBoolean(String khbh){
+
+        //获取售后宝授权码
+        String shouhoubaoAccessToken = getShouhoubaoAccessToken();
+
+        OkHttpClient client = new OkHttpClient().newBuilder()
+                .build();
+        Request request = new Request.Builder()
+                .url("https://oapi.shb.ltd/service/customer/get_customer_customerNo?accessToken="+shouhoubaoAccessToken+
+                        "&customerNo="+khbh)
+                .method("GET", null)
+                .build();
+
+        boolean flag = false;
+        try {
+            Response response = client.newCall(request).execute();
+            String responseBody = response.body().string();
+            log.info("售后宝【客户详情】返回信息:" + responseBody);
+            String substring1 = responseBody.substring(1, responseBody.length() - 1);
+            log.info("去除首尾双引号后的返回信息:" + substring1);
+            String substring2 = substring1.replaceAll("\\\\", "");
+            log.info("去除转义字符后的返回信息:" + substring2);
+
+            JSONObject jsonObject = JSON.parseObject(substring2);
+            Integer errorCode = jsonObject.getInteger("errorCode");
+            if (errorCode == 0){
+                System.out.println("当前客户在售后宝【已存在】!");
+                flag = true;
+            }else {
+                System.out.println("当前客户在售后宝【不存在】!");
+                flag = false;
+            }
+
+            System.out.println("根据客户编号查询售后宝客户是否存在(true存在;false不存在):" + flag);
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+
+        return flag;
+    }
+
+    //同步客户信息至售后宝
+    @Override
+    public String tongbuKehu(String khbh,String khmc,String khlxrList,String khlxrdhList,String khlxrzwList,String khdz,
+                             String userid,String khfzrxm,String htqydw){
+
+        System.out.println("【客户编号】" + khbh + "【客户名称】" + khmc
+                + "【客户联系人列表】" + khlxrList + "【客户联系人电话列表】" + khlxrdhList
+                + "【客户联系人职务列表】" + khlxrzwList + "【客户地址】" + khdz
+                + "【客户负责人(售后宝人员id)】" + userid + "【客户负责人姓名】" + khfzrxm + "【合同签约主体】" + htqydw);
+
+        //获取售后宝授权码
+        String shouhoubaoAccessToken = getShouhoubaoAccessToken();
+
+        /*客户负责人(售后宝人员id)通过人员姓名进行查询匹配*/
+        log.info("开始执行调用根据姓名获取售后宝人员id...");
+        String shBid = getSHBid(khfzrxm);
+
+        /*根据客户编号,调用售后宝接口查询客户是否存在*/
+        log.info("开始执行调用根据客户编号获取客户信息(判断是否存在)...");
+        Boolean kehuBoolean = getKehuBoolean(khbh);
+
+        /*处理客户联系人明细列表(获取第一条客户联系信息)*/
+        //客户联系人姓名
+        JSONArray khlxrArray = JSON.parseArray(khlxrList);
+        String khlxrStr = khlxrArray.getString(0);
+        System.out.println("获取明细列表第一条【客户联系人姓名】:" + khlxrStr);
+        //客户联系人电话
+        JSONArray khlxrdhArray = JSON.parseArray(khlxrdhList);
+        String khlxrdhStr = khlxrdhArray.getString(0);
+        System.out.println("获取明细列表第一条【客户联系人电话】:" + khlxrdhStr);
+        //客户联系人职务
+        JSONArray khlxrzwArray = JSON.parseArray(khlxrzwList);
+        String khlxrzwStr = khlxrzwArray.getString(0);
+        System.out.println("获取明细列表第一条【客户联系人职务】:" + khlxrzwStr);
+
+        if (kehuBoolean == false){
+            log.info("客户【不存在】,开始执行同步【创建】客户信息至售后宝!");
+            /*调用售后宝【客户新增】接口*/
+            //封装售后宝客户新增接口需要的参数
+            Map map2 = new HashMap();
+            map2.put("field_2L1hdL8o2Gz563tQ",htqydw);
+
+            Map map1 = new HashMap();
+            //客户编号
+            map1.put("serialNumber",khbh);
+            //客户名称
+            map1.put("name",khmc);
+            //客户联系人
+            map1.put("lmName",khlxrStr);
+            //客户联系电话
+            map1.put("lmPhone",khlxrdhStr);
+            //客户地址
+            map1.put("address",khdz);
+            //客户负责人(售后宝人员id)
+            map1.put("customerManager",shBid);
+            //客户负责人姓名
+            map1.put("customerManagerName",khfzrxm);
+            //合同签约单位(单选项匹配)
+            map1.put("attribute",map2);
+
+            String jsonString = JSON.toJSONString(map1);
+            System.out.println("封装售后宝客户新增接口需要的参数:" + jsonString);
+
+            //休眠1秒后,进行调用【客户新增】接口
+            try {
+                log.info("休眠中,时长为:1秒...");
+                Thread.sleep(1000);
+            }catch (Exception e){
+                e.printStackTrace();
+            }
+            log.info("调用售后宝【客户新增】接口===>");
+            try {
+                OkHttpClient client = new OkHttpClient().newBuilder()
+                        .build();
+                MediaType mediaType = MediaType.parse("application/json");
+                RequestBody body = RequestBody.create(mediaType, jsonString);
+                Request request = new Request.Builder()
+                        .url("https://oapi.shb.ltd/service/customer/createV2?accessToken=" + shouhoubaoAccessToken)
+                        .method("POST", body)
+                        .addHeader("Content-Type", "application/json")
+                        .build();
+                Response response = client.newCall(request).execute();
+                String responseBody = response.body().string();
+                log.info("售后宝【客户新增】接口返回信息:" + responseBody);
+            }catch (Exception e){
+                e.printStackTrace();
+            }
+            /*调用售后宝【客户新增】接口*/
+
+            return "同步创建客户信息完成!";
+        }else {
+            log.info("客户【已存在】,开始执行同步【更新】客户信息至售后宝!");
+            /*调用售后宝【客户更新】接口*/
+            //封装售后宝客户更新接口需要的参数
+            Map map2 = new HashMap();
+            map2.put("field_2L1hdL8o2Gz563tQ",htqydw);
+
+//            //封装客户地址
+//            Map map3 = new HashMap();
+
+            Map map1 = new HashMap();
+            //客户编号
+            map1.put("customerNo",khbh);
+            //客户名称
+            map1.put("name",khmc);
+            //客户联系人
+            map1.put("lmName",khlxrStr);
+            //客户联系电话
+            map1.put("lmPhone",khlxrdhStr);
+            //客户地址
+//            map1.put("address",khdz);
+            //客户负责人(售后宝人员id)
+            map1.put("customerManager",shBid);
+            //客户负责人姓名
+            map1.put("customerManagerName",khfzrxm);
+            //合同签约单位(单选项匹配)
+            map1.put("attribute",map2);
+
+            String jsonString = JSON.toJSONString(map1);
+            System.out.println("封装售后宝客户更新接口需要的参数:" + jsonString);
+
+            //休眠1秒后,进行调用【客户新增】接口
+            try {
+                log.info("休眠中,时长为:1秒...");
+                Thread.sleep(1000);
+            }catch (Exception e){
+                e.printStackTrace();
+            }
+            log.info("调用售后宝【客户更新】接口===>");
+            try {
+                OkHttpClient client = new OkHttpClient().newBuilder()
+                        .build();
+                MediaType mediaType = MediaType.parse("application/json");
+                RequestBody body = RequestBody.create(mediaType, jsonString);
+                Request request = new Request.Builder()
+                        .url("https://oapi.shb.ltd/service/customer/update_customer?accessToken=" + shouhoubaoAccessToken)
+                        .method("POST", body)
+                        .addHeader("Content-Type", "application/json")
+                        .build();
+                Response response = client.newCall(request).execute();
+                String responseBody = response.body().string();
+                log.info("售后宝【客户更新】接口返回信息:" + responseBody);
+            }catch (Exception e){
+                e.printStackTrace();
+            }
+            /*调用售后宝【客户更新】接口*/
+
+            return "更新客户信息完成!";
+        }
+    }
+
+    //产品新增
+    public JSONArray saveChanpin(String jsonString){
+
+        //获取售后宝授权码
+        String shouhoubaoAccessToken = getShouhoubaoAccessToken();
+
+        System.out.println("传参【产品新增】接口封装的参数:" + jsonString);
+
+        OkHttpClient client = new OkHttpClient().newBuilder()
+                .build();
+        MediaType mediaType = MediaType.parse("application/json");
+        RequestBody body = RequestBody.create(mediaType, jsonString);
+        Request request = new Request.Builder()
+                .url("https://oapi.shb.ltd/service/product/batch_save_product?accessToken=" + shouhoubaoAccessToken)
+                .method("POST", body)
+                .addHeader("Content-Type", "application/json")
+                .build();
+
+        JSONArray data = null;
+        try {
+            Response response = client.newCall(request).execute();
+            String responseBody = response.body().string();
+            log.info("售后宝【产品新增】返回信息:" + responseBody);
+            String substring1 = responseBody.substring(1, responseBody.length() - 1);
+            log.info("去除首尾双引号后的返回信息:" + substring1);
+            String substring2 = substring1.replaceAll("\\\\", "");
+            log.info("去除转义字符后的返回信息:" + substring2);
+
+            JSONObject jsonObject = JSON.parseObject(substring2);
+            data = jsonObject.getJSONArray("data");
+            System.out.println("售后宝【产品新增】返回的产品Id:" + data);
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+
+        return data;
+    }
+
+    //创建售后宝工单
+    @Override
+    public String createGongdan(String khbh,String khmc,String khdz,String khlxr,String khlxrdh,String gdid,String gdmc,
+                                String cpmcList,String cpppList,String cpxhList,String cpazwzList,
+                                String sdqkList,String azrq){
+
+        System.out.println("客户编号:" + khbh + "客户名称:" + khmc
+                + "客户地址:" + khdz + "客户联系人:" + khlxr + "客户联系人电话:" + khlxrdh
+                + "工单id:" + gdid + "工单名称:" + gdmc
+                + "产品名称列表:" + cpmcList + "产品品牌列表:" + cpppList + "产品型号列表:" + cpxhList + "产品安装位置列表:" + cpazwzList
+                + "3米内水电情况列表:" + sdqkList + "最晚安装日期:" + azrq);
+
+//        客户编号:KH20230625120731011
+//        客户名称:上海市国家安全局松江分局
+//        客户地址:上海市松江区谷阳北路128号
+//        客户联系人:张主任
+//        客户联系人电话:13917912291
+//        工单id:279bb347-913e-4627-bffc-605317774885
+//        工单名称:安装工单
+//        产品名称列表:["直饮水机"]
+//        产品品牌列表:["史密斯"]
+//        产品型号列表:["BZR800-T6H"]
+//        产品安装位置列表:["底楼茶水间,具体几号楼没有标,靠马路那栋楼底楼"]
+//        3米内水电情况列表:["有排污","有水","有电"]
+//        最晚安装日期:1687708800000
+
+        khbh = "KH20230625120731011";
+        khmc = "上海市国家安全局松江分局";
+        khdz = "上海市松江区谷阳北路128号";
+        khlxr = "张主任";
+        khlxrdh = "13917912291";
+        gdid = "279bb347-913e-4627-bffc-605317774885";
+        gdmc = "安装工单";
+        cpmcList = "[\"直饮水机\"]";
+        cpppList = "[\"史密斯\"]";
+        cpxhList = "[\"BZR800-T6H\"]";
+        cpazwzList = "[\"底楼茶水间,具体几号楼没有标,靠马路那栋楼底楼\"]";
+        sdqkList = "[\"有排污\",\"有水\",\"有电\"]";
+        azrq = "1687708800000";
+
+        long azrqLong = Long.parseLong(azrq);
+
+        //获取售后宝授权码
+        String shouhoubaoAccessToken = getShouhoubaoAccessToken();
+
+        /*处理传参*/
+        //==============================================================================================
+        //最晚安装日期(计划日期)
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+        //将时间戳转换为时间
+        Date azrqDate = new Date(azrqLong);
+        System.out.println("最晚安装日期(时间型):" + azrqDate);
+        //将时间调整为yyyy-MM-dd HH:mm:ss时间样式
+        String azrqDateString = simpleDateFormat.format(azrqDate);
+        System.out.println("最晚安装日期(时间样式):" + azrqDateString);
+
+        //==============================================================================================
+        //【***】通过产品名称这列,作为列表循环条数
+        JSONArray cpmcArray = JSON.parseArray(cpmcList);
+
+        JSONArray cpppArray = JSON.parseArray(cpppList);
+        JSONArray cpxhArray = JSON.parseArray(cpxhList);
+        JSONArray cpazwzArray = JSON.parseArray(cpazwzList);
+
+        //封装批量新增产品参数
+        List listAll = new ArrayList();
+
+        for (int i = 0; i < cpmcArray.size(); i++) {
+            Map map = new HashMap();
+            Map map1 = new HashMap();
+
+            //当前时间的时间戳(作为售后宝产品编号)
+            long timeMillis = System.currentTimeMillis();
+            String timestamp = String.valueOf(timeMillis);
+            log.info("当前时间的时间戳(毫秒级):" + timestamp);
+
+            //产品名称
+            String cpmc = cpmcArray.getString(i);
+            //产品品牌
+            String cppp = cpppArray.getString(i);
+            //产品型号
+            String cpxh = cpxhArray.getString(i);
+            //产品安装位置
+            String cpazwz = cpazwzArray.getString(i);
+
+            map1.put("field_WbLmDtP58EMzDzdf",cppp);
+            map1.put("field_peyKFqp3QwQptCFq",cpxh);
+            map1.put("field_EDhkN5owZL3T5KtM",cpazwz);
+            map1.put("field_HD3kiNGTA75UmqvV",azrqDateString);
+
+            map.put("serialNumber",timestamp);//产品编号
+            map.put("name",cpmc);//产品名称
+            map.put("customerSN",khbh);//客户编号
+            map.put("customerName",khmc);//客户名称
+            map.put("attribute",map1);//自定义字段
+
+            listAll.add(map);
+        }
+
+        String jsonString = JSON.toJSONString(listAll);
+        System.out.println("封装的批量新增产品的参数:" + jsonString);
+
+        //调用批量新增产品
+        log.info("开始执行批量新增售后宝产品...");
+        JSONArray jsonArray = saveChanpin(jsonString);
+        List chanpinList = new ArrayList();
+        for (int i = 0; i < jsonArray.size(); i++) {
+            String string = jsonArray.getString(i);
+            chanpinList.add(string);
+        }
+
+        //==============================================================================================
+        //3米内水电情况列表
+        List SDQKlist = new ArrayList();
+        JSONArray sdqkArray = JSON.parseArray(sdqkList);
+        for (int i = 0; i < sdqkArray.size(); i++) {
+            String string = sdqkArray.getString(i);
+            SDQKlist.add(string);
+        }
+        /*处理传参*/
+
+        /*
+        【创建工单json参数示例】
+        {
+            "cusNo":"KH000384",
+            "cusName":"上海松江区就业促进中心",
+            "address":"上海市-市辖区-松江区-荣乐东路2378号1/2/3/6楼",
+            "lmName":"闻老师",
+            "lmPhone":"15800656968",
+            "templateId":"279bb347-913e-4627-bffc-605317774885",
+            "templateName":"安装工单",
+            "planTime":"2023-03-19",
+            "productIds": ["a0a6c248-f5f5-11ed-ae93-00163e1537d3","4ef0ee3f-f619-11ed-996b-00163e17c56d"],
+            "attribute": {
+                "field_DfIX3Gg9ziTYZQpY": ["有水","有电"]
+            }
+        }
+         */
+
+        Map map = new HashMap();
+        Map map1 = new HashMap();
+        map1.put("field_DfIX3Gg9ziTYZQpY",SDQKlist);
+        //客户编号
+        map.put("cusNo",khbh);
+        //客户名称
+        map.put("cusName",khmc);
+        //客户地址
+        map.put("address",khdz);
+        //客户联系人
+        map.put("lmName",khlxr);
+        //客户联系人电话
+        map.put("lmPhone",khlxrdh);
+        //工单id
+        map.put("templateId",gdid);
+        //工单名称
+        map.put("templateName",gdmc);
+        //计划时间(最晚安装日期)
+        map.put("planTime",azrqDateString);
+        //产品列表(传售后宝和客户绑定的产品id)
+        map.put("productIds",chanpinList);
+        //3米内水电情况列表(固定选项)
+        map.put("attribute",map1);
+
+        String jsonString1 = JSON.toJSONString(map);
+        System.out.println("封装售后宝【创建工单】接口需要的参数:" + jsonString1);
+
+        OkHttpClient client = new OkHttpClient().newBuilder()
+                .build();
+        MediaType mediaType = MediaType.parse("application/json");
+        RequestBody body = RequestBody.create(mediaType, jsonString);
+        Request request = new Request.Builder()
+                .url("https://oapi.shb.ltd/service/task/create_task_v2?accessToken=" + shouhoubaoAccessToken)
+                .method("POST", body)
+                .addHeader("Content-Type", "application/json")
+                .build();
+
+        try {
+            Response response = client.newCall(request).execute();
+            String responseBody = response.body().string();
+            log.info("售后宝【创建工单】返回信息:" + responseBody);
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+
+        return "创建售后宝工单完成!";
+    }
+
+}

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

@@ -0,0 +1,57 @@
+server.port=8099
+server.servlet.context-path=/lingai
+
+server.tomcat.uri-encoding=UTF-8
+
+## 服务名
+#spring.application.name=lingai-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/

+ 743 - 0
src/test/java/com/muzhi/lingai/APITest/Test1.java

@@ -0,0 +1,743 @@
+package com.muzhi.lingai.APITest;
+
+import cn.hutool.core.date.DateTime;
+import cn.hutool.core.date.DateUtil;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.aliyun.dingtalkyida_1_0.models.SearchFormDatasResponse;
+import com.aliyun.tea.TeaException;
+import com.aliyun.teautil.models.RuntimeOptions;
+import com.muzhi.lingai.service.AccessTokenService;
+import lombok.extern.slf4j.Slf4j;
+import okhttp3.*;
+import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.commons.lang.StringEscapeUtils;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+
+import java.io.IOException;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+@SpringBootTest
+@Slf4j
+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(){
+        int dkcs = 5;
+        int ccts = 0;
+
+        dkcs = dkcs/2;
+        int dkcsLast = (int)dkcs;
+
+
+        if (dkcs > 0){
+            //实际出差天数
+            ccts = ccts + dkcsLast;
+            System.out.println("实际出差天数:" + ccts);
+        }
+
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        long startLong = new Long("1670342400000");
+        //将时间戳转换为时间
+        Date startDate = new Date(startLong);
+        System.out.println("出差开始时间(时间型):" + startDate);
+        //将时间调整为yyyy-MM-dd HH:mm:ss时间样式
+        String startString = simpleDateFormat.format(startDate);
+        System.out.println("出差开始时间(时间样式):" + startString);
+
+        long endLong = new Long("1670428800000");
+        //将时间戳转换为时间
+        Date endDate = new Date(endLong);
+        System.out.println("出差结束时间(时间型):" + endDate);
+        //将时间调整为yyyy-MM-dd HH:mm:ss时间样式
+        String endString = simpleDateFormat.format(endDate);
+        System.out.println("出差结束时间(时间样式):" + endString);
+
+        Calendar calendar1 = Calendar.getInstance();
+        calendar1.setTime(endDate);
+        //后面一天
+        calendar1.add(Calendar.DAY_OF_MONTH,1);
+        calendar1.set(Calendar.HOUR_OF_DAY,0);
+        calendar1.set(Calendar.MINUTE,0);
+        calendar1.set(Calendar.SECOND,0);
+        calendar1.set(Calendar.MILLISECOND,0);
+        String time1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(calendar1.getTime());
+        System.out.println("出差结束时间后面一天零点:" + time1);
+
+        DateTime lastDateTime = DateUtil.parse(time1);
+        System.out.println("出差结束时间后面一天(时间型):" + lastDateTime);
+
+        //获取当天前一天的零点零分零秒
+        Date Date = new Date(System.currentTimeMillis());
+        System.out.println("当前时间:" + Date);
+        String dateNowString = simpleDateFormat.format(Date);
+        System.out.println("当前时间(时间样式):" + dateNowString);
+
+        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);
+    }
+
+    //MD5加密
+    @Test
+    public void MD5(){
+
+        /*明文
+        * timestamp毫秒级时间戳
+        * */
+        //当前时间的时间戳
+        long timeMillis = System.currentTimeMillis();
+        String timestamp = String.valueOf(timeMillis);
+        log.info("当前时间的时间戳(毫秒级):" + timestamp);
+
+        /*秘钥
+         * AppSecret应用秘钥
+         * */
+        String AppSecret = "f7585e1f2c4c25682f407af23b7ff7d5f21f4f9e3715c294";
+
+        //加密后的字符串
+        String encodeStr= DigestUtils.md5Hex(AppSecret + "_" + timestamp);
+        log.info("MD5加密后的字符串encodeStr:" + encodeStr);
+
+        Map map = new HashMap();
+        map.put("appKey","shbqv00tso4dg5kcjz");
+        map.put("timestamp",timestamp);
+        map.put("verifyCode",encodeStr);
+        String parmsStr = JSON.toJSONString(map);
+        log.info("封装秘钥参数parmsStr:" + parmsStr);
+
+        //售后宝【接口授权】
+        //授权码
+        String access_token = null;
+        //失效时间
+        String expire_time = null;
+        try {
+            OkHttpClient client = new OkHttpClient().newBuilder()
+                    .build();
+            MediaType mediaType = MediaType.parse("application/json");
+            RequestBody body = RequestBody.create(mediaType, parmsStr);
+            Request request = new Request.Builder()
+                    .url("https://oapi.shb.ltd/service/auth/get_access_token")
+                    .method("POST", body)
+                    .addHeader("Content-Type", "application/json")
+                    .addHeader("Cookie", "acw_tc=0a45662a16728986832314856e80f39124201b89184960430078b3ebfda740")
+                    .build();
+
+            Response response = client.newCall(request).execute();
+            String responseBody = response.body().string();
+            log.info("售后宝【接口授权】返回信息:" + responseBody);
+            String substring1 = responseBody.substring(1, responseBody.length() - 1);
+            log.info("去除首尾双引号后的返回信息:" + substring1);
+            String substring2 = substring1.replaceAll("\\\\", "");
+            log.info("去除转义字符后的返回信息:" + substring2);
+
+            JSONObject jsonObject = JSON.parseObject(substring2);
+            JSONObject data = jsonObject.getJSONObject("data");
+            //授权码
+            access_token = data.getString("access_token");
+            //失效时间
+            expire_time = data.getString("expire_time");
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        long endLong = new Long(expire_time);
+        //将时间戳转换为时间
+        Date endDate = new Date(endLong);
+        System.out.println("授权码失效时间(时间型):" + endDate);
+        //将时间调整为yyyy-MM-dd HH:mm:ss时间样式
+        String endString = simpleDateFormat.format(endDate);
+        System.out.println("授权码失效时间(时间样式):" + endString);
+        log.info("【授权码】:" + access_token + "【失效时间】:" + endString);
+    }
+
+    //【客户列表】
+    @Test
+    public void getKehuList(){
+        Map map = new HashMap();
+        map.put("pageSize",50);
+        map.put("pageNum",1);
+        map.put("keyword","KH20230607020507345");
+
+        String jsonString = JSON.toJSONString(map);
+        System.out.println("封装的客户列表查询接口条件参数:" + jsonString);
+
+        OkHttpClient client = new OkHttpClient().newBuilder()
+                .build();
+        MediaType mediaType = MediaType.parse("application/json");
+        RequestBody body = RequestBody.create(mediaType, jsonString);
+        Request request = new Request.Builder()
+                .url("https://oapi.shb.ltd/service/customer/get_customers?accessToken=4da6f063-5083-481f-8e0a-be59d41eea40")
+                .method("POST", body)
+                .addHeader("Content-Type", "application/json")
+                .build();
+
+        try {
+            Response response = client.newCall(request).execute();
+            String responseBody = response.body().string();
+            log.info("售后宝【客户列表】返回信息:" + responseBody);
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+    }
+
+    //根据客户编号查询售后宝客户是否存在
+    @Test
+    public void getKehuBoolean(){
+
+        //售后宝授权码
+        String shouhoubaoAccessToken = "46998202-77f4-4943-a2a3-61a3a96a0959";
+        //客户编号
+        String khbh = "KH001";
+
+        OkHttpClient client = new OkHttpClient().newBuilder()
+                .build();
+        Request request = new Request.Builder()
+                .url("https://oapi.shb.ltd/service/customer/get_customer_customerNo?accessToken="+shouhoubaoAccessToken+
+                        "&customerNo="+khbh)
+                .method("GET", null)
+                .build();
+
+        boolean flag = false;
+        try {
+            Response response = client.newCall(request).execute();
+            String responseBody = response.body().string();
+            log.info("售后宝【客户详情】返回信息:" + responseBody);
+            String substring1 = responseBody.substring(1, responseBody.length() - 1);
+            log.info("去除首尾双引号后的返回信息:" + substring1);
+            String substring2 = substring1.replaceAll("\\\\", "");
+            log.info("去除转义字符后的返回信息:" + substring2);
+
+            JSONObject jsonObject = JSON.parseObject(substring2);
+            Integer errorCode = jsonObject.getInteger("errorCode");
+            if (errorCode == 0){
+                System.out.println("当前客户在售后宝【已存在】!");
+                flag = true;
+            }else {
+                System.out.println("当前客户在售后宝【不存在】!");
+                flag = false;
+            }
+
+            System.out.println("根据客户编号查询售后宝客户是否存在(true存在;false不存在):" + flag);
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+
+    }
+
+    //【售后宝人员ID】
+    @Test
+    public void getSHBid(){
+
+        int pageNum = 1;
+        int pageSize = 50;
+
+        //根据售人员姓名进行匹配查询售后宝人员id
+        String userName = "牧之";
+        List list = new ArrayList();
+        list.add(userName);
+
+        Map map = new HashMap();
+        map.put("pageNum",pageNum);
+        map.put("pageSize",pageSize);
+        map.put("userNameList",list);
+
+        //根据售售后宝人员userid进行匹配查询售后宝人员信息
+//        String userid = "f58e62b5-a843-11ed-bdbf-00163e179ed7";
+//        List list = new ArrayList();
+//        list.add(userid);
+//
+//        Map map = new HashMap();
+//        map.put("pageNum",pageNum);
+//        map.put("pageSize",pageSize);
+//        map.put("userIds",list);
+
+        String bodyStr = JSON.toJSONString(map);
+
+        String userId = null;
+
+        OkHttpClient client = new OkHttpClient().newBuilder()
+                .build();
+        MediaType mediaType = MediaType.parse("application/json");
+        RequestBody body = RequestBody.create(mediaType, bodyStr);
+        Request request = new Request.Builder()
+                .url("https://oapi.shb.ltd/service/user/get_user_params?accessToken=f3fa69d7-b152-4e5d-9659-4208dc4c7296")
+                .method("POST", body)
+                .addHeader("Content-Type", "application/json")
+                .build();
+
+        try {
+            Response response = client.newCall(request).execute();
+            String responseBody = response.body().string();
+            log.info("售后宝【人员列表】返回信息:" + responseBody);
+            String substring1 = responseBody.substring(1, responseBody.length() - 1);
+            log.info("去除首尾双引号后的返回信息:" + substring1);
+            String substring2 = substring1.replaceAll("\\\\", "");
+            log.info("去除转义字符后的返回信息:" + substring2);
+
+            JSONObject jsonObject = JSON.parseObject(substring2);
+            JSONObject data = jsonObject.getJSONObject("data");
+//            System.out.println("data===" + data);
+
+            userId = data.getJSONArray("list").getJSONObject(0).getString("userId");
+            System.out.println("售后宝人员userId:" + userId);
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+
+//        return userId;f58e62b5-a843-11ed-bdbf-00163e179ed7
+    }
+
+    //【工单类型】
+    @Test
+    public void getGongdanType(){
+        OkHttpClient client = new OkHttpClient().newBuilder()
+                .build();
+        Request request = new Request.Builder()
+                .url("https://oapi.shb.ltd/service/task/get_task_types?accessToken=0824c173-62f3-4ad5-a2d0-dc2d03fa8e6c")
+                .method("GET", null)
+                .build();
+
+        try {
+            Response response = client.newCall(request).execute();
+            String responseBody = response.body().string();
+            log.info("售后宝【工单类型】返回信息:" + responseBody);
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+    }
+
+    //【创建工单】
+    @Test
+    public void addGongdan(){
+
+        /*
+        【创建工单json参数】
+        {
+            "cusNo":"KH000384",
+            "cusName":"上海松江区就业促进中心",
+            "address":"上海市-市辖区-松江区-荣乐东路2378号1/2/3/6楼",
+            "lmName":"闻老师",
+            "lmPhone":"15800656968",
+            "templateId":"279bb347-913e-4627-bffc-605317774885",
+            "templateName":"安装工单",
+            "planTime":"2023-03-19",
+            "productIds": ["a0a6c248-f5f5-11ed-ae93-00163e1537d3","4ef0ee3f-f619-11ed-996b-00163e17c56d"],
+            "attribute": {
+                "field_DfIX3Gg9ziTYZQpY": ["有水","有电"]
+            }
+        }
+         */
+
+        OkHttpClient client = new OkHttpClient().newBuilder()
+                .build();
+        MediaType mediaType = MediaType.parse("application/json");
+        RequestBody body = RequestBody.create(mediaType, "        {\n" +
+                "            \"cusNo\":\"KH000384\",\n" +
+                "            \"cusName\":\"上海松江区就业促进中心\",\n" +
+                "            \"address\":\"上海市-市辖区-松江区-荣乐东路2378号1/2/3/6楼\",\n" +
+                "            \"lmName\":\"闻老师\",\n" +
+                "            \"lmPhone\":\"15800656968\",\n" +
+                "            \"templateId\":\"279bb347-913e-4627-bffc-605317774885\",\n" +
+                "            \"templateName\":\"安装工单\",\n" +
+                "            \"planTime\":\"2023-03-19\",\n" +
+                "            \"productIds\": [\"a0a6c248-f5f5-11ed-ae93-00163e1537d3\",\"4ef0ee3f-f619-11ed-996b-00163e17c56d\"],\n" +
+                "            \"attribute\": {\n" +
+                "                \"field_DfIX3Gg9ziTYZQpY\": [\"有水\",\"有电\"]\n" +
+                "            }\n" +
+                "        }");
+        Request request = new Request.Builder()
+                .url("https://oapi.shb.ltd/service/task/create_task_v2?accessToken=88ee3824-1fd4-4209-811f-03b9a0b5d98c")
+                .method("POST", body)
+                .addHeader("Content-Type", "application/json")
+                .build();
+
+        try {
+            Response response = client.newCall(request).execute();
+            String responseBody = response.body().string();
+            log.info("售后宝【创建工单】返回信息:" + responseBody);
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+    }
+
+    //sha256加密测试
+    @Test
+    public void sha256test(){
+
+        //sha256加密
+        /*明文
+         * timestamp毫秒级时间戳
+         * */
+        //当前时间的时间戳
+        long timeMillis = System.currentTimeMillis();
+        String timestamp = String.valueOf(timeMillis);
+        log.info("当前时间的时间戳(毫秒级):" + timestamp);
+
+        String qingqiu = "{\"mihome\": 112,\"date\": \"2023-01-01\"}";
+
+        /*秘钥
+         * AppSecret应用秘钥
+         * */
+        String AppSecret = "uFW0o8ALNiwZAT9saHUD";
+
+        //加密后的字符串
+        String encodeStr= DigestUtils.sha256Hex(qingqiu + "|" + AppSecret);
+        log.info("sha256加密后的字符串encodeStr:" + encodeStr);
+    }
+
+    @Test
+    public void AA(){
+
+        /*明文
+         * 时间型:yyyy-MM-dd-HH
+         * */
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd-HH");
+        Date Date = new Date(System.currentTimeMillis());
+        System.out.println("当前时间:" + Date);
+        String dateNowString = simpleDateFormat.format(Date);
+        System.out.println("当前时间(时间样式:yyyy-MM-dd-HH)" + dateNowString);
+
+        /*秘钥
+         * 系统id和Secret密钥
+         * */
+        String SystemId = "6CBAC3D3-F055-6150-E3C9-142FB65524B5";
+        String secret = "c2Vhc2t5Y29udHJhY3RhcGk=";
+
+        //加密后的字符串
+        String encodeStr= DigestUtils.md5Hex(SystemId + "|" + dateNowString + "|" + secret);
+        log.info("MD5加密后的字符串encodeStr:" + encodeStr);
+    }
+
+    public static com.aliyun.dingtalkyida_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.dingtalkyida_1_0.Client(config);
+    }
+
+    //获取审批实例详情
+    @Test
+    public void getShenpi(){
+
+        JSONObject jsonObject = null;
+
+        int size = 100;
+        int page = 1;
+
+        do {
+            try {
+                com.aliyun.dingtalkyida_1_0.Client client = createClient();
+                com.aliyun.dingtalkyida_1_0.models.SearchFormDatasHeaders searchFormDatasHeaders = new com.aliyun.dingtalkyida_1_0.models.SearchFormDatasHeaders();
+                searchFormDatasHeaders.xAcsDingtalkAccessToken = accessTokenService.getAccessToken();
+                com.aliyun.dingtalkyida_1_0.models.SearchFormDatasRequest searchFormDatasRequest = new com.aliyun.dingtalkyida_1_0.models.SearchFormDatasRequest()
+                        //宜搭应用秘钥
+                        .setSystemToken("RH766AC1Z0P6IBWRFIA885XCULUV275UHT5CLYF")
+                        //每页查询数量
+                        .setPageSize(size)
+                        //当前分页
+                        .setCurrentPage(page)
+                        //宜搭表单ID
+                        .setFormUuid("FORM-FDA66N81C5V672VY53J7D7ZBSIC63EQHRT5CL0")
+                        //TODO 系统管理员id
+                        .setUserId("yida_pub_account")
+                        //宜搭应用编码
+                        .setAppType("APP_EXJ5WMWZ18FS1F2UFOHN");
+
+                SearchFormDatasResponse searchFormDatasResponse = client.searchFormDatasWithOptions(searchFormDatasRequest, searchFormDatasHeaders, new RuntimeOptions());
+                System.out.println(JSON.toJSONString(searchFormDatasResponse.getBody()));
+                String s = JSON.toJSONString(searchFormDatasResponse.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 属性,可帮助开发定位问题
+                }
+
+            }
+
+            JSONArray data = jsonObject.getJSONArray("data");
+            for (int i = 0; data.size()>i; i++){
+
+                JSONObject formData = data.getJSONObject(i).getJSONObject("formData");
+
+                String khbh = formData.getString("textField_lhemu0bf");
+                System.out.println("客户编号:" + khbh);
+
+                String khmc = formData.getString("textField_lc5vdt71");
+                System.out.println("客户名称:" + khmc);
+
+
+                //客户联系人列表
+                JSONArray tableField_le6s0mhc = formData.getJSONArray("tableField_le6s0mhc");
+                JSONObject jsonObject1 = tableField_le6s0mhc.getJSONObject(0);
+                //客户联系人姓名
+                String khlxr = jsonObject1.getString("textField_lc5vdt76");
+                System.out.println("客户联系人姓名:" + khlxr);
+                //客户联系人电话
+                String khlxrdh = jsonObject1.getString("textField_lc5vdt77");
+                System.out.println("客户联系人电话:" + khlxrdh);
+
+
+                String khdz = formData.getString("textField_lfj2zo84");
+                System.out.println("客户地址:" + khdz);
+
+
+
+                String khfzrmc = formData.getJSONArray("employeeField_lc5vdt7w").getString(0);
+                System.out.println("客户负责人姓名:" + khfzrmc);
+
+
+                /*根据客户负责人姓名来匹配售后宝的人员ID*/
+                //休眠1秒后,进行调用【获取售后宝人员ID】
+                try {
+                    log.info("休眠中,时长为:1秒...");
+                    Thread.sleep(1000);
+                }catch (Exception e){
+                    e.printStackTrace();
+                }
+                log.info("根据客户负责人姓名来匹配售后宝的人员ID===>");
+
+                int pageNum = 1;
+                int pageSize = 50;
+
+                String userName = khfzrmc;
+                List list = new ArrayList();
+                list.add(userName);
+
+                Map map = new HashMap();
+                map.put("pageNum",pageNum);
+                map.put("pageSize",pageSize);
+                map.put("userNameList",list);
+
+                String bodyStr = JSON.toJSONString(map);
+
+                String userId = null;
+
+                try {
+                    OkHttpClient client = new OkHttpClient().newBuilder()
+                            .build();
+                    MediaType mediaType = MediaType.parse("application/json");
+                    RequestBody body = RequestBody.create(mediaType, bodyStr);
+                    Request request = new Request.Builder()
+                            .url("https://oapi.shb.ltd/service/user/get_user_params?accessToken=6ff00058-58a9-49a3-b354-e9fb1f507f5a")
+                            .method("POST", body)
+                            .addHeader("Content-Type", "application/json")
+                            .build();
+
+
+                    Response response = client.newCall(request).execute();
+                    String responseBody = response.body().string();
+                    log.info("售后宝【人员列表】返回信息:" + responseBody);
+                    String substring1 = responseBody.substring(1, responseBody.length() - 1);
+                    log.info("去除首尾双引号后的返回信息:" + substring1);
+                    String substring2 = substring1.replaceAll("\\\\", "");
+                    log.info("去除转义字符后的返回信息:" + substring2);
+
+                    JSONObject jsonObject111 = JSON.parseObject(substring2);
+                    JSONObject data111 = jsonObject111.getJSONObject("data");
+//            System.out.println("data===" + data);
+
+                    userId = data111.getJSONArray("list").getJSONObject(0).getString("userId");
+                    System.out.println("售后宝人员userId:" + userId);
+                }catch (Exception e){
+                    e.printStackTrace();
+                }
+                /*根据客户负责人姓名来匹配售后宝的人员ID*/
+
+
+                String htqydw = formData.getString("selectField_lc5vdt7v");
+                System.out.println("合同签约单位:" + htqydw);
+
+                /*调用售后宝【客户新增】接口*/
+                //封装售后宝客户新增接口需要的参数
+                Map map2 = new HashMap();
+                map2.put("field_2L1hdL8o2Gz563tQ",htqydw);
+
+                Map map1 = new HashMap();
+                //客户编号
+                map1.put("serialNumber",khbh);
+                //客户名称
+                map1.put("name",khmc);
+                //客户联系人
+                map1.put("lmName",khlxr);
+                //客户联系电话
+                map1.put("lmPhone",khlxrdh);
+                //客户地址
+                map1.put("address",khdz);
+                //客户负责人(售后宝人员id)
+                map1.put("customerManager",userId);
+                //客户负责人姓名
+                map1.put("customerManagerName",khfzrmc);
+                //合同签约单位(单选项匹配)
+                map1.put("attribute",map2);
+
+                String jsonString = JSON.toJSONString(map1);
+                System.out.println("封装售后宝客户新增接口需要的参数:" + jsonString);
+
+                //休眠1秒后,进行调用【客户新增】接口
+                try {
+                    log.info("休眠中,时长为:1秒...");
+                    Thread.sleep(1000);
+                }catch (Exception e){
+                    e.printStackTrace();
+                }
+                log.info("调用售后宝【客户新增】接口===>");
+                try {
+                    OkHttpClient client = new OkHttpClient().newBuilder()
+                            .build();
+                    MediaType mediaType = MediaType.parse("application/json");
+                    RequestBody body = RequestBody.create(mediaType, jsonString);
+                    Request request = new Request.Builder()
+                            .url("https://oapi.shb.ltd/service/customer/createV2?accessToken=6ff00058-58a9-49a3-b354-e9fb1f507f5a")
+                            .method("POST", body)
+                            .addHeader("Content-Type", "application/json")
+                            .build();
+                    Response response = client.newCall(request).execute();
+                    String responseBody = response.body().string();
+                    log.info("售后宝【客户新增】接口返回信息:" + responseBody);
+                }catch (Exception e){
+                    e.printStackTrace();
+                }
+                /*调用售后宝【客户新增】接口*/
+
+            }
+
+            if (data.size() == 100){
+                page = page + 1;
+            }
+
+//            float aa = jsonObject.getFloat("totalCount") / 100;
+//            int bb = jsonObject.getInteger("currentPage");
+//            log.info("aa" + aa + "---bb" + bb);
+        }while (jsonObject.getFloat("totalCount") / 100 > jsonObject.getInteger("currentPage"));
+
+
+        System.out.println("同步【宜搭客户信息至售后宝】完成!");
+    }
+
+    //更新售后宝客户信息接口
+    @Test
+    public void updateKehu(){
+        /*调用售后宝【客户更新】接口*/
+        //封装售后宝客户更新接口需要的参数
+//        Map map2 = new HashMap();
+//        map2.put("field_2L1hdL8o2Gz563tQ",htqydw);
+//
+//        Map map1 = new HashMap();
+//        //客户编号
+//        map1.put("serialNumber",khbh);
+//        //客户名称
+//        map1.put("name",khmc);
+//        //客户联系人
+//        map1.put("lmName",khlxrStr);
+//        //客户联系电话
+//        map1.put("lmPhone",khlxrdhStr);
+//        //客户地址
+//        map1.put("address",khdz);
+//        //客户负责人(售后宝人员id)
+//        map1.put("customerManager",shBid);
+//        //客户负责人姓名
+//        map1.put("customerManagerName",khfzrxm);
+//        //合同签约单位(单选项匹配)
+//        map1.put("attribute",map2);
+
+//            String jsonString = JSON.toJSONString(map1);
+        String jsonString = "{\"customerNo\":\"KH20230607020507345\",\"address\":\"上海市浦东新区曹路镇AAA号\",\"lmPhone\":\"15200000000\",\"customerManager\":\"be8d91b5-85a9-11ed-b57f-00163e0b3979\",\"name\":\"测试客户名称AAA\",\"attribute\":{\"field_2L1hdL8o2Gz563tQ\":\"上海另爱实业有限公司\"},\"lmName\":\"联系人AAA\",\"customerManagerName\":\"孟慧菲\"}";//TODO 测试使用!
+        System.out.println("封装售后宝客户更新接口需要的参数:" + jsonString);
+
+        //休眠1秒后,进行调用【客户新增】接口
+        try {
+            log.info("休眠中,时长为:1秒...");
+            Thread.sleep(1000);
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+        log.info("调用售后宝【客户更新】接口===>");
+        try {
+            OkHttpClient client = new OkHttpClient().newBuilder()
+                    .build();
+            MediaType mediaType = MediaType.parse("application/json");
+            RequestBody body = RequestBody.create(mediaType, jsonString);
+            Request request = new Request.Builder()
+                    .url("https://oapi.shb.ltd/service/customer/update_customer?accessToken=4da6f063-5083-481f-8e0a-be59d41eea40")
+                    .method("POST", body)
+                    .addHeader("Content-Type", "application/json")
+                    .build();
+            Response response = client.newCall(request).execute();
+            String responseBody = response.body().string();
+            log.info("售后宝【客户更新】接口返回信息:" + responseBody);
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+        /*调用售后宝【客户更新】接口*/
+    }
+}

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

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

+ 57 - 0
target/classes/application.properties

@@ -0,0 +1,57 @@
+server.port=8099
+server.servlet.context-path=/lingai
+
+server.tomcat.uri-encoding=UTF-8
+
+## ������
+#spring.application.name=lingai-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/

BIN
target/lingai-1.0-SNAPSHOT.jar.original


+ 3 - 0
target/maven-archiver/pom.properties

@@ -0,0 +1,3 @@
+artifactId=lingai
+groupId=com.muzhi.lingai
+version=1.0-SNAPSHOT

File diff suppressed because it is too large
+ 66 - 0
target/surefire-reports/TEST-com.muzhi.lingai.TestApplicationTests.xml


+ 4 - 0
target/surefire-reports/com.muzhi.lingai.TestApplicationTests.txt

@@ -0,0 +1,4 @@
+-------------------------------------------------------------------------------
+Test set: com.muzhi.lingai.TestApplicationTests
+-------------------------------------------------------------------------------
+Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.077 s - in com.muzhi.lingai.TestApplicationTests