From e8858df15a89365287aa9ac783deee44678655bf Mon Sep 17 00:00:00 2001
From: zhouxiantao <1026371446@qq.com>
Date: Fri, 06 Sep 2024 14:27:05 +0800
Subject: [PATCH] 小程序案件

---
 dyh-service/dyh-sys/src/main/java/cn/huge/module/file/controller/wechat/FileInfoWechatController.java      |   78 +++
 dyh-service/dyh-mediate/src/main/java/cn/huge/module/cases/domain/dto/CaseInfoWeChatDTO.java               |   53 ++
 dyh-service/dyh-sys/pom.xml                                                                                |   17 
 dyh-service/dyh-mediate/src/main/java/cn/huge/module/cases/dao/mapper/xml/CaseInfoMapper.xml               |   13 
 dyh-service/dyh-mediate/src/main/java/cn/huge/module/cases/service/CaseInfoService.java                    |  260 ++++++++++
 dyh-service/dyh-sys/src/main/java/cn/huge/module/xfyun/config/XfyunConfig.java                             |   81 +++
 dyh-service/dyh-mediate/src/main/java/cn/huge/module/client/api/impl/CustClientImpl.java                   |    2 
 dyh-service/dyh-sys/src/main/java/cn/huge/module/xfyun/iflytek/WebIATWS.java                               |  392 ++++++++++++++++
 dyh-service/dyh-cust/src/main/java/cn/huge/module/pauser/controller/client/PaUserClientController.java     |  207 ++++++++
 dyh-service/dyh-mediate/src/main/java/cn/huge/module/cases/controller/wechat/CaseInfoWechatController.java |  149 ++++++
 dyh-service/dyh-mediate/src/main/java/cn/huge/module/cases/dao/mapper/CaseInfoMapper.java                  |    1 
 dyh-service/dyh-cust/src/main/java/cn/huge/module/pauser/service/PaUserService.java                        |   10 
 dyh-service/dyh-base/src/main/java/cn/huge/base/common/utils/GuavaCacheUtils.java                          |   45 +
 dyh-service/dyh-mediate/src/main/java/cn/huge/module/client/api/CustClient.java                            |    1 
 dyh-service/dyh-sys/src/main/java/cn/huge/module/xfyun/controller/wechat/XfyunWechatController.java        |   66 ++
 dyh-service/dyh-mediate/src/main/java/cn/huge/module/cases/domain/dto/CasePersonWechatDTO.java             |   30 +
 16 files changed, 1,402 insertions(+), 3 deletions(-)

diff --git a/dyh-service/dyh-base/src/main/java/cn/huge/base/common/utils/GuavaCacheUtils.java b/dyh-service/dyh-base/src/main/java/cn/huge/base/common/utils/GuavaCacheUtils.java
new file mode 100644
index 0000000..e9245c0
--- /dev/null
+++ b/dyh-service/dyh-base/src/main/java/cn/huge/base/common/utils/GuavaCacheUtils.java
@@ -0,0 +1,45 @@
+package cn.huge.base.common.utils;
+
+import com.google.common.cache.Cache;
+import com.google.common.cache.CacheBuilder;
+import org.springframework.util.ObjectUtils;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * 本地缓存工具类
+ * @author zhouxiantao
+ * @create 2024-09-05 10:51
+ */
+public class GuavaCacheUtils {
+    private static Cache<String, Object> cache = CacheBuilder.newBuilder()
+            //5分钟后过期
+            .expireAfterWrite(5, TimeUnit.SECONDS)
+//            .expireAfterWrite(10, TimeUnit.SECONDS)
+            //最大10个缓存
+            .maximumSize(10)
+            .build();
+
+
+    public static Object getCache(String k) {
+        return cache.getIfPresent(k);
+    }
+
+    public static void putCache(String k, Object value) {
+        cache.put(k, value);
+    }
+
+    public static void main(String[] args) throws InterruptedException {
+        putCache("15008985673","123456");
+        while (true){
+            Thread.sleep(1000);
+            Object cache = getCache("15008985673");
+            System.out.println(cache);
+            if(ObjectUtils.isEmpty(cache)){
+                System.out.println("结束。。。");
+                return;
+            }
+        }
+    }
+
+}
diff --git a/dyh-service/dyh-cust/src/main/java/cn/huge/module/pauser/controller/client/PaUserClientController.java b/dyh-service/dyh-cust/src/main/java/cn/huge/module/pauser/controller/client/PaUserClientController.java
new file mode 100644
index 0000000..f56ddf1
--- /dev/null
+++ b/dyh-service/dyh-cust/src/main/java/cn/huge/module/pauser/controller/client/PaUserClientController.java
@@ -0,0 +1,207 @@
+package cn.huge.module.pauser.controller.client;
+
+import cn.huge.base.common.utils.ReturnFailUtils;
+import cn.huge.base.common.utils.ReturnSucUtils;
+import cn.huge.base.config.CurrentUser;
+import cn.huge.module.cust.dto.PaUserDTO;
+import cn.huge.module.mediate.dto.WechatBindCaseDTO;
+import cn.huge.module.pauser.domain.po.PaUser;
+import cn.huge.module.pauser.service.PaUserService;
+import com.google.common.collect.Maps;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.Map;
+
+/**
+ * @title: 公众用户表接口api-wechat端
+ * @description: 公众用户表接口api-wechat端
+ * @company: hugeinfo
+ */
+@Slf4j
+@RestController
+@RequestMapping("/api/client/paUser")
+public class PaUserClientController {
+
+    @Autowired(required = false)
+    private HttpServletRequest request;
+
+    @Autowired
+    private PaUserService service;
+
+    /**
+    * 获取请求URL参数
+    * @return Map<String, Object>
+    */
+    private Map<String, Object> getParameter(){
+        Map<String, Object> terms = Maps.newHashMap();
+        // 当事人编号
+        String id = request.getParameter("id");
+        if (StringUtils.isNotBlank(id)){
+            terms.put("id", id);
+        }
+        // 姓名
+        String trueName = request.getParameter("trueName");
+        if (StringUtils.isNotBlank(trueName)){
+            terms.put("trueName", trueName);
+        }
+        // 性别
+        String sex = request.getParameter("sex");
+        if (StringUtils.isNotBlank(sex)){
+            terms.put("sex", sex);
+        }
+        // 性别名称
+        String sexName = request.getParameter("sexName");
+        if (StringUtils.isNotBlank(sexName)){
+            terms.put("sexName", sexName);
+        }
+        // 手机号码
+        String mobile = request.getParameter("mobile");
+        if (StringUtils.isNotBlank(mobile)){
+            terms.put("mobile", mobile);
+        }
+        // 身份证号码
+        String idcard = request.getParameter("idcard");
+        if (StringUtils.isNotBlank(idcard)){
+            terms.put("idcard", idcard);
+        }
+        // 电子邮箱
+        String email = request.getParameter("email");
+        if (StringUtils.isNotBlank(email)){
+            terms.put("email", email);
+        }
+        // 微信号
+        String wechat = request.getParameter("wechat");
+        if (StringUtils.isNotBlank(wechat)){
+            terms.put("wechat", wechat);
+        }
+        // QQ号
+        String qq = request.getParameter("qq");
+        if (StringUtils.isNotBlank(qq)){
+            terms.put("qq", qq);
+        }
+        // 现居地省
+        String prov = request.getParameter("prov");
+        if (StringUtils.isNotBlank(prov)){
+            terms.put("prov", prov);
+        }
+        // 现居地省名称
+        String provName = request.getParameter("provName");
+        if (StringUtils.isNotBlank(provName)){
+            terms.put("provName", provName);
+        }
+        // 现居地市
+        String city = request.getParameter("city");
+        if (StringUtils.isNotBlank(city)){
+            terms.put("city", city);
+        }
+        // 现居地市名称
+        String cityName = request.getParameter("cityName");
+        if (StringUtils.isNotBlank(cityName)){
+            terms.put("cityName", cityName);
+        }
+        // 现居地区
+        String area = request.getParameter("area");
+        if (StringUtils.isNotBlank(area)){
+            terms.put("area", area);
+        }
+        // 现居地区名称
+        String areaName = request.getParameter("areaName");
+        if (StringUtils.isNotBlank(areaName)){
+            terms.put("areaName", areaName);
+        }
+        // 现居地街道
+        String road = request.getParameter("road");
+        if (StringUtils.isNotBlank(road)){
+            terms.put("road", road);
+        }
+        // 现居地街道名称
+        String roadName = request.getParameter("roadName");
+        if (StringUtils.isNotBlank(roadName)){
+            terms.put("roadName", roadName);
+        }
+        // 现居地社区
+        String village = request.getParameter("village");
+        if (StringUtils.isNotBlank(village)){
+            terms.put("village", village);
+        }
+        // 现居地社区名称
+        String villageName = request.getParameter("villageName");
+        if (StringUtils.isNotBlank(villageName)){
+            terms.put("villageName", villageName);
+        }
+        // 现居地详细地址
+        String addr = request.getParameter("addr");
+        if (StringUtils.isNotBlank(addr)){
+            terms.put("addr", addr);
+        }
+        // 头像
+        String avatar = request.getParameter("avatar");
+        if (StringUtils.isNotBlank(avatar)){
+            terms.put("avatar", avatar);
+        }
+        // 实名认证状态,0:未认证,1:已认证
+        String realStatus = request.getParameter("realStatus");
+        if (StringUtils.isNotBlank(realStatus)){
+            terms.put("realStatus", realStatus);
+        }
+        // 用户状态,0:停用,1:启用
+        String status = request.getParameter("status");
+        if (StringUtils.isNotBlank(status)){
+            terms.put("status", status);
+        }
+        // 关注纠纷类型,多个用,隔开
+        String followCaseType = request.getParameter("followCaseType");
+        if (StringUtils.isNotBlank(followCaseType)){
+            terms.put("followCaseType", followCaseType);
+        }
+        // 删除状态,0:未删除,1:已删除
+        String deleteStatus = request.getParameter("deleteStatus");
+        if (StringUtils.isNotBlank(deleteStatus)){
+            terms.put("deleteStatus", deleteStatus);
+        }
+        // 客户编号
+        String custId = request.getParameter("custId");
+        if (StringUtils.isNotBlank(custId)){
+            terms.put("custId", custId);
+        }
+        // 创建时间区间
+        String createStart = request.getParameter("createStart");
+        String createEnd = request.getParameter("createEnd");
+        if(StringUtils.isNotBlank(createStart) && StringUtils.isNotBlank(createEnd)) {
+            terms.put("createStart", createStart);
+            terms.put("createEnd", createEnd);
+        }
+        // 更新时间区间
+        String updateStart = request.getParameter("updateStart");
+        String updateEnd = request.getParameter("updateEnd");
+        if(StringUtils.isNotBlank(updateStart) && StringUtils.isNotBlank(updateEnd)) {
+            terms.put("updateStart", updateStart);
+            terms.put("updateEnd", updateEnd);
+        }
+        return terms;
+    }
+
+
+
+    /**
+     * 当事人用户信息
+     * url: {ctx}/api/client/paUser/clientGetUserAll
+     * type: post
+     */
+    @GetMapping(value = "/clientGetUserAll")
+    public Object clientGetUserAll(@RequestParam(value = "userId") String userId) {
+        try {
+            PaUserDTO paUser = service.clientGetUserAll(userId);
+            return ReturnSucUtils.getRepInfo(paUser);
+        } catch (Exception e) {
+            log.error("Controller接口[PaUserClientController.clientGetUserAll]请求异常:"+e, e);
+            return ReturnFailUtils.getRepInfo(e.getMessage());
+        }
+    }
+
+
+}
diff --git a/dyh-service/dyh-cust/src/main/java/cn/huge/module/pauser/service/PaUserService.java b/dyh-service/dyh-cust/src/main/java/cn/huge/module/pauser/service/PaUserService.java
index c4cc93f..a4b92bc 100644
--- a/dyh-service/dyh-cust/src/main/java/cn/huge/module/pauser/service/PaUserService.java
+++ b/dyh-service/dyh-cust/src/main/java/cn/huge/module/pauser/service/PaUserService.java
@@ -5,6 +5,7 @@
 import cn.huge.base.common.utils.IdUtils;
 import cn.huge.base.common.utils.ObjectUtils;
 import cn.huge.module.client.api.impl.UtilsClientImpl;
+import cn.huge.module.cust.dto.PaUserDTO;
 import cn.huge.module.mediate.dto.WechatBindCaseDTO;
 import cn.huge.module.cust.constant.UserBaseConsts;
 import cn.huge.module.mediate.dto.WechatBindCaseDTO;
@@ -236,5 +237,12 @@
         }
     }
 
-
+    public PaUserDTO clientGetUserAll(String userId){
+        PaUserDTO paUserDTO = new PaUserDTO();
+        PaUser paUser = mapper.selectById(userId);
+        if(ObjectUtils.isNotEmpty(paUser)){
+            BeanUtils.copyProperties(paUser, paUserDTO);
+        }
+        return paUserDTO;
+    }
 }
diff --git a/dyh-service/dyh-mediate/src/main/java/cn/huge/module/cases/controller/wechat/CaseInfoWechatController.java b/dyh-service/dyh-mediate/src/main/java/cn/huge/module/cases/controller/wechat/CaseInfoWechatController.java
new file mode 100644
index 0000000..06fb123
--- /dev/null
+++ b/dyh-service/dyh-mediate/src/main/java/cn/huge/module/cases/controller/wechat/CaseInfoWechatController.java
@@ -0,0 +1,149 @@
+package cn.huge.module.cases.controller.wechat;
+
+import cn.huge.base.common.utils.GuavaCacheUtils;
+import cn.huge.base.common.utils.ObjectUtils;
+import cn.huge.base.common.utils.ReturnFailUtils;
+import cn.huge.base.common.utils.ReturnSucUtils;
+import cn.huge.base.config.CurrentUser;
+import cn.huge.module.cases.domain.dto.CaseInfoWeChatDTO;
+import cn.huge.module.cases.domain.dto.RegisterSaveDTO;
+import cn.huge.module.cases.domain.po.CaseInfo;
+import cn.huge.module.cases.service.CaseInfoService;
+import cn.huge.module.client.api.impl.UtilsClientImpl;
+import com.google.common.collect.Maps;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Sort;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @title: 纠纷信息主表接口api-web端
+ * @description: 纠纷信息主表接口api-web端
+ * @company: hugeinfo
+ * @author: wangwh
+ * @time: 2024-08-27 10:00:57
+ * @version: 1.0.0
+ */
+@Slf4j
+@RestController
+@RequestMapping("/api/wechat/caseInfo")
+public class CaseInfoWechatController {
+
+    @Autowired(required = false)
+    private HttpServletRequest request;
+
+    @Autowired
+    private CaseInfoService service;
+    @Autowired
+    private UtilsClientImpl utilsClient;
+
+    /**
+    * 获取请求URL参数
+    * @return Map<String, Object>
+    */
+    private Map<String, Object> getParameter(){
+        Map<String, Object> terms = Maps.newHashMap();
+        // 人员类型,1:我是申请方,2:我是被申请方
+        String personType = request.getParameter("personType");
+        if (StringUtils.isNotBlank(personType)){
+            terms.put("personType", personType);
+        }
+
+        // 事项进度,1:来访登记,2:事件流转,3:办理反馈,4:结案申请,5:当事人评价,6:结案归档
+        String process = request.getParameter("process");
+        if (StringUtils.isNotBlank(process)){
+            terms.put("process", process);
+        }
+        // 办理进度,1:待受理,2:办理中,3:已结案,4:不予受理
+        String processStatus = request.getParameter("processStatus");
+        if (StringUtils.isNotBlank(processStatus)){
+            if("1".equals(processStatus)){
+                List<Integer> processList = Arrays.asList(1,2);
+                terms.put("processList", processList);
+            }else if("2".equals(processStatus)){
+                List<Integer> processList = Arrays.asList(3,4);
+                terms.put("processList", processList);
+            }else if("3".equals(processStatus)){
+                List<Integer> processList = Arrays.asList(5,6);
+                terms.put("processList", processList);
+            }else{
+                List<Integer> processList = Arrays.asList(7);
+                terms.put("processList", processList);
+            }
+        }
+
+        return terms;
+    }
+
+    /**
+    * 条件分页查询
+    * @url {ctx}/api/wechat/caseInfo/pageCard
+    * @param page 页码
+    * @param size 每页数量
+    * @return Object
+     * @CurrentUser String userId,
+    */
+    @GetMapping("/pageCard")
+    public Object pageCard(@RequestParam(value = "page") int page, @RequestParam(value = "size") int size) {
+        try {
+            String userId = "2408301111391000";
+            Map<String, Object> terms = getParameter();
+            Sort sort = Sort.by(Sort.Direction.DESC, "create_time");
+            PageRequest pageRequest = PageRequest.of(page-1, size, sort);
+            Page<CaseInfoWeChatDTO> caseInfoPage = service.pageQueryWechat(userId,pageRequest, terms);
+            return ReturnSucUtils.getRepInfo( "处理成功", caseInfoPage);
+        } catch (Exception e) {
+            log.error("Controller接口[CaseInfoWechatController.pageCard]请求异常:"+e, e);
+            return ReturnFailUtils.getRepInfo();
+        }
+    }
+
+
+    /**
+     * 小程序端-纠纷登记-保存纠纷信息-正常案件
+     * @url {ctx}/api/v1/caseInfo/caseRegister
+     * @param registerSaveDTO 实体对象
+     */
+    @PostMapping("/caseRegister")
+    public Object caseRegister(@CurrentUser String userId, @RequestBody RegisterSaveDTO registerSaveDTO) {
+        try {
+            Object caseRegister = GuavaCacheUtils.getCache("caseRegister"+userId);
+            if(ObjectUtils.isNotEmpty(caseRegister)){
+                log.info("caseRegister is exist {}",caseRegister);
+                return ReturnSucUtils.getRepInfo(caseRegister);
+            }else{
+                if(ObjectUtils.isEmpty(registerSaveDTO.getId())){
+                    registerSaveDTO.setId(utilsClient.getNewTimeCaseId());
+                }
+                GuavaCacheUtils.putCache("caseRegister"+userId,registerSaveDTO.getId());
+            }
+            String caseId = service.caseRegisterWechat(registerSaveDTO, userId);
+            return ReturnSucUtils.getRepInfo(caseId);
+        } catch (Exception e) {
+            log.error("Controller接口[CaseInfoWechatController.caseRegister]请求异常:"+e, e);
+            return ReturnFailUtils.getRepInfo(e.getMessage());
+        }
+    }
+
+    /**
+     * 小程序端-查看案件详情
+     * @url {ctx}/api/v1/caseInfo/getCaseInfo
+     */
+    @GetMapping("/getCaseInfo")
+    public Object getCaseInfo(@RequestParam(value = "id") String id) {
+        try {
+            return ReturnSucUtils.getRepInfo(service.getCaseInfoWechat(id));
+        } catch (Exception e) {
+            log.error("Controller接口[CaseInfoWechatController.caseInfo]请求异常:"+e, e);
+            return ReturnFailUtils.getRepInfo(e.getMessage());
+        }
+    }
+}
diff --git a/dyh-service/dyh-mediate/src/main/java/cn/huge/module/cases/dao/mapper/CaseInfoMapper.java b/dyh-service/dyh-mediate/src/main/java/cn/huge/module/cases/dao/mapper/CaseInfoMapper.java
index 659092a..0ce7586 100644
--- a/dyh-service/dyh-mediate/src/main/java/cn/huge/module/cases/dao/mapper/CaseInfoMapper.java
+++ b/dyh-service/dyh-mediate/src/main/java/cn/huge/module/cases/dao/mapper/CaseInfoMapper.java
@@ -1,5 +1,6 @@
 package cn.huge.module.cases.dao.mapper;
 
+import cn.huge.module.cases.domain.dto.CaseInfoWeChatDTO;
 import cn.huge.module.cases.domain.po.CaseInfo;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.apache.ibatis.annotations.Param;
diff --git a/dyh-service/dyh-mediate/src/main/java/cn/huge/module/cases/dao/mapper/xml/CaseInfoMapper.xml b/dyh-service/dyh-mediate/src/main/java/cn/huge/module/cases/dao/mapper/xml/CaseInfoMapper.xml
index 87423e9..25b9fad 100644
--- a/dyh-service/dyh-mediate/src/main/java/cn/huge/module/cases/dao/mapper/xml/CaseInfoMapper.xml
+++ b/dyh-service/dyh-mediate/src/main/java/cn/huge/module/cases/dao/mapper/xml/CaseInfoMapper.xml
@@ -224,6 +224,12 @@
     <sql id="where-part">
         <if test="terms != null">
             <where>
+                <if test="terms.ids != null and terms.ids.size > 0">
+                    and id in
+                    <foreach collection="terms.id" item="terms.ids" index="index" open="(" separator="," close=")">
+                        #{terms.id}
+                    </foreach>
+                </if>
                 <if test="terms.id != null and terms.id !=''">
                     and id = #{terms.id}
                 </if>
@@ -395,6 +401,12 @@
                 <if test="terms.statusName != null and terms.statusName !=''">
                     and status_name = #{terms.statusName}
                 </if>
+                <if test="terms.processList != null and terms.processList.size > 0">
+                    and process in
+                    <foreach collection="terms.process" item="terms.processList" index="index" open="(" separator="," close=")">
+                        #{terms.process}
+                    </foreach>
+                </if>
                 <if test="terms.process != null and terms.process !=''">
                     and process = #{terms.process}
                 </if>
@@ -499,4 +511,5 @@
         limit #{page.offset}, #{page.size}
     </select>
 
+
 </mapper> 
\ No newline at end of file
diff --git a/dyh-service/dyh-mediate/src/main/java/cn/huge/module/cases/domain/dto/CaseInfoWeChatDTO.java b/dyh-service/dyh-mediate/src/main/java/cn/huge/module/cases/domain/dto/CaseInfoWeChatDTO.java
new file mode 100644
index 0000000..84e6e92
--- /dev/null
+++ b/dyh-service/dyh-mediate/src/main/java/cn/huge/module/cases/domain/dto/CaseInfoWeChatDTO.java
@@ -0,0 +1,53 @@
+package cn.huge.module.cases.domain.dto;
+
+import lombok.Data;
+
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @author zhouxiantao
+ * @create 2024-09-05 10:17
+ */
+@Data
+public class CaseInfoWeChatDTO {
+    /**
+     * 主键编号
+     */
+    private String id;
+    /**
+     * 事项标题
+     */
+    private String caseTitle;
+    /**
+     * 来访时间(申请时间)
+     */
+    private Date visitTime;
+    /**
+     * 事项进度,1:来访登记,2:事件流转,3:办理反馈,4:结案审核,5:当事人评价,6:结案归档
+     */
+    private Integer process;
+
+    /**
+     * 事项进度名称
+     */
+    private String processName;
+
+    /**
+     * 事项进度,1:来访登记,2:事件流转,3:办理反馈,4:结案审核,5:当事人评价,6:结案归档
+     */
+    private Integer processStatus;
+
+    /**
+     * 事项进度名称
+     */
+    private String processStatusName;
+    /**
+     * 申请人集合
+     * */
+    private List<CasePersonWechatDTO> plaintiffList;
+    /**
+     * 被申请人集合
+     * */
+    private List<CasePersonWechatDTO> defendantList;
+}
diff --git a/dyh-service/dyh-mediate/src/main/java/cn/huge/module/cases/domain/dto/CasePersonWechatDTO.java b/dyh-service/dyh-mediate/src/main/java/cn/huge/module/cases/domain/dto/CasePersonWechatDTO.java
new file mode 100644
index 0000000..03e43ce
--- /dev/null
+++ b/dyh-service/dyh-mediate/src/main/java/cn/huge/module/cases/domain/dto/CasePersonWechatDTO.java
@@ -0,0 +1,30 @@
+package cn.huge.module.cases.domain.dto;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import lombok.Data;
+
+/**
+ * @author zhouxiantao
+ * @create 2024-09-05 11:36
+ */
+@Data
+public class CasePersonWechatDTO {
+    /**
+     * 姓名/企业/机构名称
+     */
+    private String trueName;
+
+    /**
+     * 联系方式
+     */
+    private String mobile;
+    /**
+     * 当事人地位
+     */
+    private String perType;
+
+    /**
+     * 当事人地位名称
+     */
+    private String perTypeName;
+}
diff --git a/dyh-service/dyh-mediate/src/main/java/cn/huge/module/cases/service/CaseInfoService.java b/dyh-service/dyh-mediate/src/main/java/cn/huge/module/cases/service/CaseInfoService.java
index 381b422..7cc943c 100644
--- a/dyh-service/dyh-mediate/src/main/java/cn/huge/module/cases/service/CaseInfoService.java
+++ b/dyh-service/dyh-mediate/src/main/java/cn/huge/module/cases/service/CaseInfoService.java
@@ -3,9 +3,11 @@
 import cn.huge.base.common.exception.ServiceException;
 import cn.huge.base.common.utils.DateUtils;
 import cn.huge.base.common.utils.IdUtils;
-
 import cn.huge.base.common.utils.ObjectUtils;
 import cn.huge.module.cases.domain.dto.CaseInfoDTO;
+
+import cn.huge.module.cases.domain.dto.CaseInfoWeChatDTO;
+import cn.huge.module.cases.domain.dto.CasePersonWechatDTO;
 import cn.huge.module.cases.domain.dto.RegisterSaveDTO;
 import cn.huge.module.cases.domain.po.CaseAgent;
 import cn.huge.module.cases.domain.po.CaseInfoUnfold;
@@ -17,6 +19,7 @@
 import cn.huge.module.cases.dao.mapper.CaseInfoMapper;
 import cn.huge.module.cases.domain.po.CaseInfo;
 import cn.huge.module.constant.BaseConsts;
+import cn.huge.module.cust.dto.PaUserDTO;
 import cn.huge.module.mediate.constant.CaseBaseConsts;
 import cn.huge.module.mediate.constant.CaseBaseConstsEnum;
 import cn.huge.module.cust.dto.CtUserDTO;
@@ -453,4 +456,259 @@
             }
         }
     }
+
+    /**
+     * PC端-纠纷登记-保存纠纷信息-正常案件
+     * @param registerSaveDTO 纠纷信息
+     * @param userId 用户编号
+     * @return String 纠纷编号
+     */
+    public String caseRegisterWechat(RegisterSaveDTO registerSaveDTO, String userId){
+        try {
+            // 获取当前登录用户
+            PaUserDTO loginUser = custClient.paclientGetUser(userId);
+            if(ObjectUtils.isEmpty(registerSaveDTO.getCustId())){
+                registerSaveDTO.setCustId(loginUser.getCustId());
+            }
+
+            Date nowDate = DateUtils.getNowDate();
+            registerSaveDTO.setUpdateTime(nowDate);
+            StringBuffer plaintiffs = new StringBuffer();
+            StringBuffer defendants = new StringBuffer();
+            StringBuffer pagents = new StringBuffer();
+            StringBuffer dagents = new StringBuffer();
+            int peopleNum = 0;
+
+            CaseInfo caseInfo = new CaseInfo();
+            CaseInfoUnfold caseInfoUnfold = new CaseInfoUnfold();
+            BeanUtils.copyProperties(registerSaveDTO, caseInfo);
+            if(ObjectUtils.isEmpty(caseInfo.getId())){
+                caseInfo.setId(utilsClient.getNewTimeCaseId());
+            }
+//            caseInfo.setInputUnitId(loginUser.getUnitId());
+//            caseInfo.setInputUnitName(loginUser.getUnitName());
+            caseInfo.setInputUserId(loginUser.getId());
+            caseInfo.setInputUserName(loginUser.getTrueName());
+            caseInfo.setInputWay(CaseBaseConsts.INPUT_WAY_1);
+            caseInfo.setCreateTime(nowDate);
+            caseInfo.setUpdateTime(nowDate);
+            caseInfo.setDeleteStatus(BaseConsts.DELETE_STATUS_0);
+            //todo case_ref生成、case_title生成
+
+            caseInfoUnfold.setId(utilsClient.getNewTimeId());
+            caseInfoUnfold.setCaseId(caseInfo.getId());
+            caseInfoUnfold.setCreateTime(nowDate);
+            caseInfoUnfold.setUpdateTime(nowDate);
+
+            // 常规登记-保存当事人
+            peopleNum += this.saveCasePersonWechat(registerSaveDTO, plaintiffs, pagents, defendants, dagents,loginUser);
+            caseInfo.setPeopleNum(peopleNum);
+            caseInfo.setPlaintiffs(plaintiffs.toString());
+            caseInfo.setPagents(pagents.toString());
+            caseInfo.setDefendants(defendants.toString());
+            caseInfo.setDagents(dagents.toString());
+            //todo 流程接口修改status、status_name、process、process_name
+
+            this.saveOrUpdate(caseInfo);
+            return registerSaveDTO.getId();
+        }catch (Exception e){
+            log.error("service方法[CaseInfoService.caseRegisterWechat]调用异常:"+e, e);
+            throw new ServiceException("CaseInfoService.caseRegisterWechat", e);
+        }
+    }
+
+    /**
+     * pc端-常规登记-保存正式案件-保存人员信息
+     * @param registerSaveDTO 纠纷信息
+     * @param plaintiffs 申请人
+     * @param pagents 申请人代理人
+     * @param defendants 被申请人
+     * @param dagents 被申请人代理人
+     * @return int
+     */
+    private int saveCasePersonWechat(RegisterSaveDTO registerSaveDTO, StringBuffer plaintiffs, StringBuffer pagents,
+                               StringBuffer defendants, StringBuffer dagents,PaUserDTO loginUser){
+        int peopleNum = 0;
+        List<String> newPersonIdList = new ArrayList<>();
+        List<String> newAgentIdList = new ArrayList<>();
+        // 保存申请人
+        List<CasePerson> personList = registerSaveDTO.getPersonList();
+        if (CollectionUtils.isNotEmpty(personList)) {
+            for (CasePerson casePerson : personList) {
+                if(ObjectUtils.isEmpty(casePerson.getId())){
+                    casePerson.setId(utilsClient.getNewTimeCaseId());
+                }
+                newPersonIdList.add(casePerson.getId());
+                casePerson.setCaseId(registerSaveDTO.getId());
+//                casePerson.setPerType(CaseBaseConstsEnum.PERSON_TYPE_1.getIndex());
+//                casePerson.setPerTypeName(CaseBaseConstsEnum.PERSON_TYPE_1.getDes());
+                casePerson.setPartyUserId(loginUser.getId());
+                casePerson.setCustId(registerSaveDTO.getCustId());
+                casePerson.setCreateTime(registerSaveDTO.getUpdateTime());
+                casePerson.setUpdateTime(registerSaveDTO.getUpdateTime());
+                //todo 绑定当事人小程序
+
+                personService.saveOrUpdate(casePerson);
+
+                //添加申请方和被申请方人名组合
+                if(CaseBaseConstsEnum.PERSON_TYPE_1.equals(casePerson.getPerType())){
+                    //申请方
+                    if (StringUtils.isNotEmpty(plaintiffs.toString())) {
+                        plaintiffs.append(BaseConsts.COMMA);
+                    }
+                    plaintiffs.append(casePerson.getTrueName());
+                }else if(CaseBaseConstsEnum.PERSON_TYPE_2.equals(casePerson.getPerType())){
+                    //被申请方
+                    if (StringUtils.isNotEmpty(defendants.toString())) {
+                        defendants.append(BaseConsts.COMMA);
+                    }
+                    defendants.append(casePerson.getTrueName());
+                }
+                peopleNum++;
+
+            }
+            //保存代理人
+            List<CaseAgent> agentList = registerSaveDTO.getAgentList();
+            if (CollectionUtils.isNotEmpty(agentList)) {
+                for(CaseAgent caseAgent: agentList){
+                    newAgentIdList.add(caseAgent.getId());
+                    if(ObjectUtils.isEmpty(caseAgent.getId())){
+                        caseAgent.setId(utilsClient.getNewTimeCaseId());
+                    }
+                    caseAgent.setPartyUserId(loginUser.getId());
+                    caseAgent.setCaseId(registerSaveDTO.getId());
+                    caseAgent.setAgentTypeName(CaseBaseConstsEnum.getDes(caseAgent.getAgentType()));
+
+                    caseAgent.setCustId(registerSaveDTO.getCustId());
+                    caseAgent.setCreateTime(registerSaveDTO.getUpdateTime());
+                    caseAgent.setUpdateTime(registerSaveDTO.getUpdateTime());
+
+                    agentService.saveOrUpdate(caseAgent);
+
+                    if (StringUtils.isNotEmpty(pagents.toString())) {
+                        pagents.append(BaseConsts.COMMA);
+                    }
+                    pagents.append(caseAgent.getTrueName());
+                }
+                //todo 绑定当事人小程序
+            }
+        }
+
+        // 删除冗余的申请人
+        if (CollectionUtils.isNotEmpty(newPersonIdList)) {
+            List<String> oldPersonIdList = personService.listIdByCaseId(registerSaveDTO.getId());
+            for (String oldPersonId : oldPersonIdList) {
+                if (!newPersonIdList.contains(oldPersonId)) {
+                    personService.removeById(oldPersonId);
+                }
+            }
+        }else{
+            QueryWrapper<CasePerson> casePersonQueryWrapper = new QueryWrapper<>();
+            casePersonQueryWrapper.eq("case_id", registerSaveDTO.getId());
+            personService.remove(casePersonQueryWrapper);
+        }
+        //删除冗余的代理人
+        if(CollectionUtils.isNotEmpty(newAgentIdList)){
+            List<String> oldAgentIdList = agentService.listIdByCaseId(registerSaveDTO.getId());
+            for(String oldAgentId: oldAgentIdList){
+                if(!newAgentIdList.contains(oldAgentId)){
+                    agentService.removeById(oldAgentId);
+                }
+            }
+        }else{
+            QueryWrapper<CaseAgent> caseAgentQueryWrapper = new QueryWrapper<>();
+            caseAgentQueryWrapper.eq("case_id", registerSaveDTO.getId());
+            agentService.remove(caseAgentQueryWrapper);
+        }
+
+        return peopleNum;
+    }
+
+    public RegisterSaveDTO getCaseInfoWechat(String id){
+        RegisterSaveDTO registerSaveDTO = new RegisterSaveDTO();
+        CaseInfo caseInfo = this.getById(id);
+        if(ObjectUtils.isNotEmpty(caseInfo)){
+            BeanUtils.copyProperties(caseInfo, registerSaveDTO);
+        }
+        QueryWrapper<CasePerson> casePersonQueryWrapper = new QueryWrapper<>();
+        casePersonQueryWrapper.eq("case_id", registerSaveDTO.getId());
+        List<CasePerson>  personList = personService.list(casePersonQueryWrapper);
+        registerSaveDTO.setPersonList(personList);
+
+        QueryWrapper<CaseAgent> caseAgentQueryWrapper = new QueryWrapper<>();
+        caseAgentQueryWrapper.eq("case_id", registerSaveDTO.getId());
+        List<CaseAgent> agentList = agentService.list(caseAgentQueryWrapper);
+        registerSaveDTO.setAgentList(agentList);
+
+        return registerSaveDTO;
+    }
+
+    /**
+     * 按条件分页查询
+     * @param page 分页对象
+     * @param terms 条件
+     * @return Page
+     */
+    public Page<CaseInfoWeChatDTO> pageQueryWechat(String userId,PageRequest page, Map<String, Object> terms){
+        List<CaseInfoWeChatDTO> list = new ArrayList<>();
+        String personType = terms.get("personType")+"";
+        if(ObjectUtils.isEmpty(personType)){
+            throw new RuntimeException("请选择人员类型");
+        }
+        QueryWrapper<CasePerson> personWrapper = new QueryWrapper<>();
+        personWrapper.select("case_id");
+        personWrapper.eq("party_user_id", userId);
+        if("1".equals(personType)){
+            personWrapper.eq("per_type",CaseBaseConstsEnum.PERSON_TYPE_1.getIndex());
+        }else {
+            personWrapper.eq("per_type",CaseBaseConstsEnum.PERSON_TYPE_2.getIndex());
+        }
+        List<CasePerson> casePersonList = personService.list(personWrapper);
+        if(ObjectUtils.isEmpty(casePersonList)){
+            return new PageImpl<CaseInfoWeChatDTO>(list, page, 0);
+        }
+        List<String> ids = casePersonList.stream().map(CasePerson::getCaseId).collect(Collectors.toList());
+        terms.put("idList",ids);
+        long total = mapper.countTerms(terms);
+        List<CaseInfo> content = mapper.pageTerms(page, terms);
+        if(ObjectUtils.isNotEmpty(content)){
+            for(CaseInfo caseInfo: content){
+                CaseInfoWeChatDTO caseInfoWeChatDTO = new CaseInfoWeChatDTO();
+                BeanUtils.copyProperties(caseInfo, caseInfoWeChatDTO);
+                if(ObjectUtils.isNotEmpty(caseInfo.getProcess()) && caseInfo.getProcess().equals(1) || caseInfo.getProcess().equals(2)){
+                    caseInfoWeChatDTO.setProcessStatus(1);
+                    caseInfoWeChatDTO.setProcessStatusName("待受理");
+                }else if(ObjectUtils.isNotEmpty(caseInfo.getProcess()) && caseInfo.getProcess().equals(3) || caseInfo.getProcess().equals(4)){
+                    caseInfoWeChatDTO.setProcessStatus(2);
+                    caseInfoWeChatDTO.setProcessStatusName("办理中");
+                }else if(ObjectUtils.isNotEmpty(caseInfo.getProcess()) && caseInfo.getProcess().equals(5) || caseInfo.getProcess().equals(6)){
+                    caseInfoWeChatDTO.setProcessStatus(3);
+                    caseInfoWeChatDTO.setProcessStatusName("已结案");
+                }else{
+                    caseInfoWeChatDTO.setProcessStatus(4);
+                    caseInfoWeChatDTO.setProcessStatusName("不予受理");
+                }
+                QueryWrapper<CasePerson> personWrapper1 = new QueryWrapper<>();
+                personWrapper1.eq("case_id", caseInfo.getId());
+                List<CasePerson> casePersonList1 = personService.list(personWrapper1);
+                //申请人集合
+                List<CasePersonWechatDTO> plaintiffList = new ArrayList<>();
+                //被申请人集合
+                List<CasePersonWechatDTO> defendantList = new ArrayList<>();
+                for (CasePerson casePerson : casePersonList1) {
+                    CasePersonWechatDTO casePersonWechatDTO = new CasePersonWechatDTO();
+                    BeanUtils.copyProperties(casePerson, casePersonWechatDTO);
+                    if(CaseBaseConstsEnum.PERSON_TYPE_1.getIndex().equals(casePerson.getPerType())){
+                        plaintiffList.add(casePersonWechatDTO);
+                    }else if(CaseBaseConstsEnum.PERSON_TYPE_2.getIndex().equals(casePerson.getPerType())){
+                        defendantList.add(casePersonWechatDTO);
+                    }
+                }
+                caseInfoWeChatDTO.setDefendantList(defendantList);
+                caseInfoWeChatDTO.setPlaintiffList(plaintiffList);
+                list.add(caseInfoWeChatDTO);
+            }
+        }
+        return new PageImpl<CaseInfoWeChatDTO>(list, page, total);
+    }
 }
diff --git a/dyh-service/dyh-mediate/src/main/java/cn/huge/module/client/api/CustClient.java b/dyh-service/dyh-mediate/src/main/java/cn/huge/module/client/api/CustClient.java
index 04fbe98..28ab532 100644
--- a/dyh-service/dyh-mediate/src/main/java/cn/huge/module/client/api/CustClient.java
+++ b/dyh-service/dyh-mediate/src/main/java/cn/huge/module/client/api/CustClient.java
@@ -46,6 +46,7 @@
     @GetMapping("/api/client/paUser/clientGetUserAll")
     ReturnBO paclientGetUser(@RequestParam("userId") String userId);
 
+
     /**
      * pc端提交案件后-获取相关当事人用户编号
      * @url {ctx}/api/weChat/paUser/bindGetUserId
diff --git a/dyh-service/dyh-mediate/src/main/java/cn/huge/module/client/api/impl/CustClientImpl.java b/dyh-service/dyh-mediate/src/main/java/cn/huge/module/client/api/impl/CustClientImpl.java
index da1fda0..1907587 100644
--- a/dyh-service/dyh-mediate/src/main/java/cn/huge/module/client/api/impl/CustClientImpl.java
+++ b/dyh-service/dyh-mediate/src/main/java/cn/huge/module/client/api/impl/CustClientImpl.java
@@ -86,6 +86,8 @@
         }
     }
 
+
+
     /**
      * 当事人-获取登录用户-所有信息
      * @param userId 用户编号
diff --git a/dyh-service/dyh-sys/pom.xml b/dyh-service/dyh-sys/pom.xml
index 124dc92..daecefc 100644
--- a/dyh-service/dyh-sys/pom.xml
+++ b/dyh-service/dyh-sys/pom.xml
@@ -19,6 +19,8 @@
 
     <properties>
         <commons-net.version>3.1</commons-net.version>
+        <gson.version>2.8.5</gson.version>
+        <okhttp3.version>3.13.1</okhttp3.version>
     </properties>
 
     <dependencies>
@@ -67,6 +69,21 @@
             <version>${commons-net.version}</version>
         </dependency>
         <!-- net end -->
+
+        <!-- gson -->
+        <dependency>
+            <groupId>com.google.code.gson</groupId>
+            <artifactId>gson</artifactId>
+            <version>${gson.version}</version>
+        </dependency>
+        <!-- gson end -->
+
+        <dependency>
+            <groupId>com.squareup.okhttp3</groupId>
+            <artifactId>okhttp</artifactId>
+            <version>${okhttp3.version}</version>
+        </dependency>
+
     </dependencies>
 
     <build>
diff --git a/dyh-service/dyh-sys/src/main/java/cn/huge/module/file/controller/wechat/FileInfoWechatController.java b/dyh-service/dyh-sys/src/main/java/cn/huge/module/file/controller/wechat/FileInfoWechatController.java
index 6967199..d837fa1 100644
--- a/dyh-service/dyh-sys/src/main/java/cn/huge/module/file/controller/wechat/FileInfoWechatController.java
+++ b/dyh-service/dyh-sys/src/main/java/cn/huge/module/file/controller/wechat/FileInfoWechatController.java
@@ -18,7 +18,9 @@
 import cn.huge.module.sys.constant.FileBaseConsts;
 import cn.huge.module.sys.constant.FileOwnerTypeBaseEnum;
 import cn.huge.module.sys.dto.FileInfoBaseDTO;
+import cn.huge.module.sys.dto.IdcardOcrResultDTO;
 import cn.huge.module.utils.BaiduOcrUtils;
+import com.google.common.collect.Maps;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang3.StringUtils;
@@ -36,6 +38,7 @@
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 
 /**
  * @title: 附件信息表接口api-wechat端
@@ -198,7 +201,80 @@
         }
     }
 
+    /**
+     * ocr识别身份证
+     * @url {ctx}/api/wechat/fileInfo/wecatRecognition?ownerId=&ownerType=
+     * @param request
+     * @return Object
+     */
+    @PostMapping(value = "/wecatRecognition")
+    public Object wecatRecognition(MultipartHttpServletRequest request, @CurrentUser String userId){
+        try{
+            // todo 判断是小程序还是PC
+//            UploaderDTO uploaderDTO = new UploaderDTO();
+//            PaUserDTO paUserDTO = custClient.paClientGetUserAll(userId);
+//            BeanUtils.copyProperties(paUserDTO, uploaderDTO);
+            Map<String , Object> result = Maps.newHashMap();
+            Iterator<String> itr = request.getFileNames();
+            while (itr.hasNext()) {
+                MultipartFile file = request.getFile(itr.next());
+//                try{
+//                    String ownerId = request.getParameter("ownerId");
+//                    if (StringUtils.isNotEmpty(ownerId)) {
+//                        String ownerType = request.getParameter("ownerType");
+//                        int fileCount = fileRelateService.countByOwnerIdAndType(ownerId, ownerType)+1;
+//                        if(StringUtils.isEmpty(ownerType)){
+//                            ownerType = FileOwnerTypeBaseEnum.OWNER_TYPE_000.getIndex();
+//                        }
+//                        FileInfo fileInfo = service.wechatUploadFile(file, ownerId,ownerId, ownerType, fileCount, uploaderDTO);
+//                        FileInfoBaseDTO fileInfoBaseDTO = new FileInfoBaseDTO();
+//                        BeanUtils.copyProperties(fileInfo, fileInfoBaseDTO);
+//                        result.put("attachment", fileInfoBaseDTO);
+//                    }
+//                }catch (Exception e){
+//                    log.error("Controller接口[FileInfoWechatController.wecatRecognition]请求异常:"+e, e);
+//                }
+                try{
+                    IdcardOcrResultDTO map = BaiduOcrUtils.ocrIdcard(file.getBytes());
+                    result.put("ocrResult", map);
+                }catch (Exception e){
+                    log.error("Controller接口[FileInfoWechatController.wecatRecognition]请求异常:"+e, e);
+                    return ReturnFailUtils.getRepInfo("OCR失败失败!");
+                }
+            }
+            return ReturnSucUtils.getRepInfo(result);
+        }catch (Exception e){
+            log.error("Controller接口[FileInfoWechatController.wecatRecognition]请求异常:"+e, e);
+            return ReturnFailUtils.getRepInfo(e.getMessage());
+        }
+    }
 
-
+    /**
+     * ocr识别文字
+     * @url {ctx}/api/wechat/fileInfo/recognitionText
+     * @param request
+     * @return Object
+     */
+    @PostMapping(value = "/recognitionText")
+    public Object recognitionText(MultipartHttpServletRequest request){
+        try{
+            Map<String , Object> result = Maps.newHashMap();
+            Iterator<String> itr = request.getFileNames();
+            while (itr.hasNext()) {
+                MultipartFile file = request.getFile(itr.next());
+                try{
+                    Map<String , Object> map = BaiduOcrUtils.ocrText(file.getBytes());
+                    result.put("ocrResult", map);
+                }catch (Exception e){
+                    log.error("Controller接口[FileInfoWechatController.recognitionText]请求异常:"+e, e);
+                    return ReturnFailUtils.getRepInfo("OCR失败!");
+                }
+            }
+            return ReturnSucUtils.getRepInfo("识别成功", result);
+        }catch (Exception e){
+            log.error("Controller接口[FileInfoWechatController.recognitionText]请求异常:"+e, e);
+            return ReturnFailUtils.getRepInfo(e.getMessage());
+        }
+    }
 
 }
diff --git a/dyh-service/dyh-sys/src/main/java/cn/huge/module/xfyun/config/XfyunConfig.java b/dyh-service/dyh-sys/src/main/java/cn/huge/module/xfyun/config/XfyunConfig.java
new file mode 100644
index 0000000..3cfa131
--- /dev/null
+++ b/dyh-service/dyh-sys/src/main/java/cn/huge/module/xfyun/config/XfyunConfig.java
@@ -0,0 +1,81 @@
+package cn.huge.module.xfyun.config;
+
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Component;
+
+
+/**
+ * @title: 科大讯飞工具类
+ * @description: 科大讯飞工具类
+ * @company: hugeinfo
+ * @author: liyj
+ * @time: 2021-11-05 16:51:48
+ * @version: 1.0.0
+ */
+@Component
+public class XfyunConfig {
+
+    /**
+     * hostUrl
+     */
+    public static String hostUrl;
+
+    /**
+     * appid
+     */
+    public static String appid;
+
+    /**
+     * apiSecret
+     */
+    public static String apiSecret;
+
+    /**
+     * apiKey
+     */
+    public static String apiKey;
+
+    @Value("${xfyun.host_url}")
+    public void setHostUrl(String host_url) {
+        hostUrl = host_url;
+    }
+
+    @Value("${xfyun.appid}")
+    public void setAppid(String app_id) {
+        appid = app_id;
+    }
+
+    @Value("${xfyun.api_secret}")
+    public void setApiSecret(String api_secret) {
+        apiSecret = api_secret;
+    }
+
+    @Value("${xfyun.api_key}")
+    public void setApiKey(String api_key) {
+        apiKey = api_key;
+    }
+
+
+}
+/**
+ * -------------------_ooOoo_-------------------
+ * ------------------o8888888o------------------
+ * ------------------88" . "88------------------
+ * ------------------(| -_- |)------------------
+ * ------------------O\  =  /O------------------
+ * ---------------____/`---'\____---------------
+ * -------------.'  \\|     |//  `.-------------
+ * ------------/  \\|||  :  |||//  \------------
+ * -----------/  _||||| -:- |||||-  \-----------
+ * -----------|   | \\\  -  /// |   |-----------
+ * -----------| \_|  ''\---/''  |   |-----------
+ * -----------\  .-\__  `-`  ___/-. /-----------
+ * ---------___`. .'  /--.--\  `. . __----------
+ * ------."" '<  `.___\_<|>_/___.'  >'"".-------
+ * -----| | :  `- \`.;`\ _ /`;.`/ - ` : | |-----
+ * -----\  \ `-.   \_ __\ /__ _/   .-` /  /-----
+ * ======`-.____`-.___\_____/___.-`____.-'======
+ * -------------------`=---='
+ * ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ * ---------佛祖保佑---hugeinfo---永无BUG----------
+ */
\ No newline at end of file
diff --git a/dyh-service/dyh-sys/src/main/java/cn/huge/module/xfyun/controller/wechat/XfyunWechatController.java b/dyh-service/dyh-sys/src/main/java/cn/huge/module/xfyun/controller/wechat/XfyunWechatController.java
new file mode 100644
index 0000000..fbfffbf
--- /dev/null
+++ b/dyh-service/dyh-sys/src/main/java/cn/huge/module/xfyun/controller/wechat/XfyunWechatController.java
@@ -0,0 +1,66 @@
+package cn.huge.module.xfyun.controller.wechat;
+
+import cn.huge.base.common.utils.ReturnFailUtils;
+import cn.huge.base.common.utils.ReturnSucUtils;
+import cn.huge.module.constant.CacheConsts;
+import cn.huge.module.xfyun.config.XfyunConfig;
+import cn.huge.module.xfyun.iflytek.WebIATWS;
+import lombok.extern.slf4j.Slf4j;
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+import okhttp3.WebSocket;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
+import org.springframework.web.multipart.MultipartHttpServletRequest;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.Iterator;
+import java.util.concurrent.CountDownLatch;
+
+
+/**
+ * @title: 讯飞语音转文字api
+ * @description: 讯飞语音转文字api
+ * @company: hugeinfo
+ * @author: chenx
+ * @time: 2022-05-17 14:55:19
+ * @version: 1.0.0
+ */
+@Slf4j
+@RestController
+@RequestMapping("/api/wechat/xfyun")
+public class XfyunWechatController {
+
+    /**
+     * 讯飞语音转文字
+     * @url {ctx}/api/v1/xfyun/speech
+     * @return Object
+     */
+    @PostMapping(value = "/speech")
+    public Object speech(MultipartHttpServletRequest rq){
+        try{
+            Iterator<String> itr = rq.getFileNames();
+            while (itr.hasNext()) {
+                MultipartFile file = rq.getFile(itr.next());
+                byte [] byteArr = file.getBytes();
+                InputStream inputStream = new ByteArrayInputStream(byteArr);
+                // 构建鉴权url
+                String authUrl = WebIATWS.getAuthUrl(XfyunConfig.hostUrl, XfyunConfig.apiKey, XfyunConfig.apiSecret);
+                OkHttpClient client = new OkHttpClient.Builder().build();
+                String url = authUrl.toString().replace("http://", "ws://").replace("https://", "wss://");
+                Request request = new Request.Builder().url(url).build();
+                CountDownLatch countDownLatch = new CountDownLatch(1);
+                WebSocket webSocket = client.newWebSocket(request, new WebIATWS(inputStream, countDownLatch));
+                countDownLatch.await();
+            }
+            return ReturnSucUtils.getRepInfo(CacheConsts.XF_RESULT);
+        }catch (Exception e){
+            log.error("Controller接口[XfyunController.speech]请求异常:"+e, e);
+            return ReturnFailUtils.getRepInfo(e.getMessage());
+        }
+    }
+
+}
diff --git a/dyh-service/dyh-sys/src/main/java/cn/huge/module/xfyun/iflytek/WebIATWS.java b/dyh-service/dyh-sys/src/main/java/cn/huge/module/xfyun/iflytek/WebIATWS.java
new file mode 100644
index 0000000..374ccae
--- /dev/null
+++ b/dyh-service/dyh-sys/src/main/java/cn/huge/module/xfyun/iflytek/WebIATWS.java
@@ -0,0 +1,392 @@
+package cn.huge.module.xfyun.iflytek;
+
+import cn.huge.module.constant.CacheConsts;
+import cn.huge.module.xfyun.config.XfyunConfig;
+import com.google.gson.Gson;
+import com.google.gson.JsonObject;
+import lombok.extern.slf4j.Slf4j;
+import okhttp3.*;
+
+import javax.crypto.Mac;
+import javax.crypto.spec.SecretKeySpec;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.nio.charset.Charset;
+import java.text.SimpleDateFormat;
+import java.util.*;
+import java.util.concurrent.CountDownLatch;
+
+/**
+ * 语音听写流式 WebAPI 接口调用示例 接口文档(必看):https://doc.xfyun.cn/rest_api/语音听写(流式版).html
+ * webapi 听写服务参考帖子(必看):http://bbs.xfyun.cn/forum.php?mod=viewthread&tid=38947&extra=
+ * 语音听写流式WebAPI 服务,热词使用方式:登陆开放平台https://www.xfyun.cn/后,找到控制台--我的应用---语音听写---个性化热词,上传热词
+ * 注意:热词只能在识别的时候会增加热词的识别权重,需要注意的是增加相应词条的识别率,但并不是绝对的,具体效果以您测试为准。
+ * 错误码链接:https://www.xfyun.cn/document/error-code (code返回错误码时必看)
+ * 语音听写流式WebAPI 服务,方言或小语种试用方法:登陆开放平台https://www.xfyun.cn/后,在控制台--语音听写(流式)--方言/语种处添加
+ * 添加后会显示该方言/语种的参数值
+ * @author iflytek
+ */
+@Slf4j
+public class WebIATWS extends WebSocketListener {
+    public static final int StatusFirstFrame = 0;
+    public static final int StatusContinueFrame = 1;
+    public static final int StatusLastFrame = 2;
+    private static InputStream inputStream;
+    private static CountDownLatch countDownLatch;
+    private static final SimpleDateFormat sdf = new SimpleDateFormat("yyy-MM-dd HH:mm:ss.SSS");
+    private static Date dateBegin = new Date();
+    private static Date dateEnd = new Date();
+    public static final Gson json = new Gson();
+    Decoder decoder = new Decoder();
+
+    /**
+     * 构造方法
+     * @param inputStream
+     * @param countDownLatch
+     */
+    public WebIATWS(InputStream inputStream, CountDownLatch countDownLatch) {
+        this.inputStream = inputStream;
+        this.countDownLatch = countDownLatch;
+    }
+
+    /**
+     * main方法
+     * @param args
+     * @throws Exception
+     */
+    public static void main(String[] args) throws Exception {
+
+    }
+
+    /**
+     * 发送语音
+     * @param webSocket
+     * @param response
+     */
+    @Override
+    public void onOpen(WebSocket webSocket, Response response) {
+        super.onOpen(webSocket, response);
+        new Thread(()->{
+            //连接成功,开始发送数据,每一帧音频的大小,建议每 40ms 发送 122B
+            int frameSize = 1280;
+            int intervel = 40;
+            // 音频的状态
+            int status = 0;
+            try  {
+                byte[] buffer = new byte[frameSize];
+                // 发送音频
+                end:
+                while (true) {
+                    int len = inputStream.read(buffer);
+                    if (len == -1) {
+                        //文件读完,改变status 为 2
+                        status = StatusLastFrame;
+                    }
+                    switch (status) {
+                        case StatusFirstFrame:
+                            // 第一帧音频status = 0
+                            JsonObject frame = new JsonObject();
+                            //第一帧必须发送
+                            JsonObject business = new JsonObject();
+                            //第一帧必须发送
+                            JsonObject common = new JsonObject();
+                            //每一帧都要发送
+                            JsonObject data = new JsonObject();
+                            // 填充common
+                            common.addProperty("app_id", XfyunConfig.appid);
+                            //填充business
+                            business.addProperty("language", "zh_cn");
+                            business.addProperty("domain", "iat");
+                            //中文方言请在控制台添加试用,添加后即展示相应参数值
+                            business.addProperty("accent", "mandarin");
+                            //动态修正(若未授权不生效,在控制台可免费开通)
+                            business.addProperty("dwa", "wpgs");
+                            //填充data
+                            data.addProperty("status", StatusFirstFrame);
+                            data.addProperty("format", "audio/L16;rate=16000");
+                            data.addProperty("encoding", "raw");
+                            data.addProperty("audio", Base64.getEncoder().encodeToString(Arrays.copyOf(buffer, len)));
+                            //填充frame
+                            frame.add("common", common);
+                            frame.add("business", business);
+                            frame.add("data", data);
+                            webSocket.send(frame.toString());
+                            // 发送完第一帧改变status 为 1
+                            status = StatusContinueFrame;
+                            break;
+                        case StatusContinueFrame:
+                            //中间帧status = 1
+                            JsonObject frame1 = new JsonObject();
+                            JsonObject data1 = new JsonObject();
+                            data1.addProperty("status", StatusContinueFrame);
+                            data1.addProperty("format", "audio/L16;rate=16000");
+                            data1.addProperty("encoding", "raw");
+                            data1.addProperty("audio", Base64.getEncoder().encodeToString(Arrays.copyOf(buffer, len)));
+                            frame1.add("data", data1);
+                            webSocket.send(frame1.toString());
+                            break;
+                        case StatusLastFrame:
+                            // 最后一帧音频status = 2 ,标志音频发送结束
+                            JsonObject frame2 = new JsonObject();
+                            JsonObject data2 = new JsonObject();
+                            data2.addProperty("status", StatusLastFrame);
+                            data2.addProperty("audio", "");
+                            data2.addProperty("format", "audio/L16;rate=16000");
+                            data2.addProperty("encoding", "raw");
+                            frame2.add("data", data2);
+                            webSocket.send(frame2.toString());
+                            System.out.println("sendlast");
+                            break end;
+                    }
+                    //模拟音频采样延时
+                    Thread.sleep(intervel);
+                }
+                System.out.println("all data is send");
+            } catch (FileNotFoundException e) {
+                e.printStackTrace();
+            } catch (IOException e) {
+                e.printStackTrace();
+            } catch (InterruptedException e) {
+                e.printStackTrace();
+            }
+        }).start();
+    }
+
+    /**
+     * 接收识别结果
+     * @param webSocket
+     * @param text
+     */
+    @Override
+    public void onMessage(WebSocket webSocket, String text) {
+        super.onMessage(webSocket, text);
+        ResponseData resp = json.fromJson(text, ResponseData.class);
+        if (resp != null) {
+            if (resp.getCode() != 0) {
+                log.error( "code=>" + resp.getCode() + " error=>" + resp.getMessage() + " sid=" + resp.getSid());
+                log.error( "错误码查询链接:https://www.xfyun.cn/document/error-code");
+                return;
+            }
+            if (resp.getData() != null) {
+                if (resp.getData().getResult() != null) {
+                    Text te = resp.getData().getResult().getText();
+                    try {
+                        decoder.decode(te);
+                        System.out.println("中间识别结果 ==》" + decoder.toString());
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    }
+                }
+                if (resp.getData().getStatus() == 2) {
+                    // resp.data.status ==2 说明数据全部返回完毕,可以关闭连接,释放资源
+                    System.out.println("session end ");
+                    dateEnd = new Date();
+                    System.out.println(sdf.format(dateBegin) + "开始");
+                    System.out.println(sdf.format(dateEnd) + "结束");
+                    log.info("耗时:" + (dateEnd.getTime() - dateBegin.getTime()) + "ms");
+                    log.info("最终识别结果 ==》" + decoder.toString());
+                    CacheConsts.XF_RESULT = decoder.toString();
+                    System.out.println("本次识别sid ==》" + resp.getSid());
+                    countDownLatch.countDown();
+                    decoder.discard();
+                    webSocket.close(1000, "");
+                } else {
+                    System.out.println("识别中");
+                }
+            }
+        }
+    }
+
+    /**
+     * 失败结果
+     * @param webSocket
+     * @param t
+     * @param response
+     */
+    @Override
+    public void onFailure(WebSocket webSocket, Throwable t, Response response) {
+        super.onFailure(webSocket, t, response);
+        try {
+            if (null != response) {
+                int code = response.code();
+                System.out.println("onFailure code:" + code);
+                System.out.println("onFailure body:" + response.body().string());
+                if (101 != code) {
+                    System.out.println("connection failed");
+                    System.exit(0);
+                }
+            }
+        } catch (IOException e) {
+            // TODO Auto-generated catch block
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * 获取授权URL
+     * @param hostUrl
+     * @param apiKey
+     * @param apiSecret
+     * @return
+     * @throws Exception
+     */
+    public static String getAuthUrl(String hostUrl, String apiKey, String apiSecret) throws Exception {
+        URL url = new URL(hostUrl);
+        SimpleDateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
+        format.setTimeZone(TimeZone.getTimeZone("GMT"));
+        String date = format.format(new Date());
+        StringBuilder builder = new StringBuilder("host: ").append(url.getHost()).append("\n").//
+                append("date: ").append(date).append("\n").//
+                append("GET ").append(url.getPath()).append(" HTTP/1.1");
+        Charset charset = Charset.forName("UTF-8");
+        Mac mac = Mac.getInstance("hmacsha256");
+        SecretKeySpec spec = new SecretKeySpec(apiSecret.getBytes(charset), "hmacsha256");
+        mac.init(spec);
+        byte[] hexDigits = mac.doFinal(builder.toString().getBytes(charset));
+        String sha = Base64.getEncoder().encodeToString(hexDigits);
+
+        String authorization = String.format("api_key=\"%s\", algorithm=\"%s\", headers=\"%s\", signature=\"%s\"", apiKey, "hmac-sha256", "host date request-line", sha);
+        HttpUrl httpUrl = HttpUrl.parse("https://" + url.getHost() + url.getPath()).newBuilder().//
+                addQueryParameter("authorization", Base64.getEncoder().encodeToString(authorization.getBytes(charset))).//
+                addQueryParameter("date", date).//
+                addQueryParameter("host", url.getHost()).//
+                build();
+        return httpUrl.toString();
+    }
+
+    /**
+     * 解析返回数据
+     */
+    public static class Decoder {
+        private Text[] texts;
+        private int defc = 10;
+        public Decoder() {
+            this.texts = new Text[this.defc];
+        }
+        public synchronized void decode(Text text) {
+            if (text.sn >= this.defc) {
+                this.resize();
+            }
+            if ("rpl".equals(text.pgs)) {
+                for (int i = text.rg[0]; i <= text.rg[1]; i++) {
+                    this.texts[i].deleted = true;
+                }
+            }
+            this.texts[text.sn] = text;
+        }
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            for (Text t : this.texts) {
+                if (t != null && !t.deleted) {
+                    sb.append(t.text);
+                }
+            }
+            return sb.toString();
+        }
+        public void resize() {
+            int oc = this.defc;
+            this.defc <<= 1;
+            Text[] old = this.texts;
+            this.texts = new Text[this.defc];
+            for (int i = 0; i < oc; i++) {
+                this.texts[i] = old[i];
+            }
+        }
+        public void discard(){
+            for(int i=0;i<this.texts.length;i++){
+                this.texts[i]= null;
+            }
+        }
+    }
+    public static class ResponseData {
+        private int code;
+        private String message;
+        private String sid;
+        private Data data;
+        public int getCode() {
+            return code;
+        }
+        public String getMessage() {
+            return this.message;
+        }
+        public String getSid() {
+            return sid;
+        }
+        public Data getData() {
+            return data;
+        }
+    }
+    public static class Data {
+        private int status;
+        private Result result;
+        public int getStatus() {
+            return status;
+        }
+        public Result getResult() {
+            return result;
+        }
+    }
+    public static class Result {
+        int bg;
+        int ed;
+        String pgs;
+        int[] rg;
+        int sn;
+        Ws[] ws;
+        boolean ls;
+        JsonObject vad;
+        public Text getText() {
+            Text text = new Text();
+            StringBuilder sb = new StringBuilder();
+            for (Ws ws : this.ws) {
+                sb.append(ws.cw[0].w);
+            }
+            text.sn = this.sn;
+            text.text = sb.toString();
+            text.sn = this.sn;
+            text.rg = this.rg;
+            text.pgs = this.pgs;
+            text.bg = this.bg;
+            text.ed = this.ed;
+            text.ls = this.ls;
+            text.vad = this.vad==null ? null : this.vad;
+            return text;
+        }
+    }
+    public static class Ws {
+        Cw[] cw;
+        int bg;
+        int ed;
+    }
+    public static class Cw {
+        int sc;
+        String w;
+    }
+    public static class Text {
+        int sn;
+        int bg;
+        int ed;
+        String text;
+        String pgs;
+        int[] rg;
+        boolean deleted;
+        boolean ls;
+        JsonObject vad;
+        @Override
+        public String toString() {
+            return "Text{" +
+                    "bg=" + bg +
+                    ", ed=" + ed +
+                    ", ls=" + ls +
+                    ", sn=" + sn +
+                    ", text='" + text + '\'' +
+                    ", pgs=" + pgs +
+                    ", rg=" + Arrays.toString(rg) +
+                    ", deleted=" + deleted +
+                    ", vad=" + (vad==null ? "null" : vad.getAsJsonArray("ws").toString()) +
+                    '}';
+        }
+    }
+}
\ No newline at end of file

--
Gitblit v1.8.0