三七 5 dní pred
rodič
commit
a961faedfe

+ 11 - 0
fs-admin/src/main/java/com/fs/qw/qwTask/qwTask.java

@@ -3,6 +3,7 @@ package com.fs.qw.qwTask;
 import com.fs.course.service.IFsUserCourseService;
 import com.fs.qw.service.IQwExternalContactService;
 import com.fs.qw.service.IQwGroupMsgService;
+import com.fs.qw.service.IQwMaterialService;
 import com.fs.qw.service.IQwUserService;
 import com.fs.sop.service.impl.QwSopLogsServiceImpl;
 import com.fs.sop.service.impl.QwSopServiceImpl;
@@ -46,6 +47,10 @@ public class qwTask {
     @Autowired
     private IFsStatisQwWatchService fsStatisQwWatchService;
 
+    @Autowired
+    private IQwMaterialService iQwMaterialService;
+
+
     //正在使用
     public void qwExternalContact()
     {
@@ -188,4 +193,10 @@ public class qwTask {
         fsStatisQwWatchService.writeData(today.toString());
     }
 
+    /**
+    * 每俩天 更新一次 素材库
+    */
+    public void updateMaterialByTwoDays(){
+        iQwMaterialService.updateQwMaterialByQw();
+    }
 }

+ 2 - 0
fs-company/src/main/java/com/fs/company/controller/qw/QwMaterialController.java

@@ -1,6 +1,7 @@
 package com.fs.company.controller.qw;
 
 import com.fs.common.annotation.Log;
+import com.fs.common.annotation.RepeatSubmit;
 import com.fs.common.core.controller.BaseController;
 import com.fs.common.core.domain.AjaxResult;
 import com.fs.common.core.domain.R;
@@ -101,6 +102,7 @@ public class QwMaterialController extends BaseController
     @PreAuthorize("@ss.hasPermi('qw:material:add')")
     @Log(title = "素材库", businessType = BusinessType.INSERT)
     @PostMapping
+    @RepeatSubmit
     public R add(@RequestBody QwMaterial qwMaterial) throws Exception {
         LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
         qwMaterial.setCreateUserId(loginUser.getUser().getUserId());

+ 5 - 3
fs-qw-task/src/main/java/com/fs/app/controller/CommonController.java

@@ -16,6 +16,7 @@ import com.fs.his.service.IFsInquiryOrderService;
 import com.fs.his.service.IFsPackageOrderService;
 import com.fs.qw.mapper.QwExternalContactMapper;
 import com.fs.qw.service.IQwExternalContactService;
+import com.fs.qw.service.IQwMaterialService;
 import com.fs.qwApi.service.QwApiService;
 import com.fs.sop.mapper.QwSopLogsMapper;
 import com.fs.sop.mapper.QwSopMapper;
@@ -99,6 +100,8 @@ public class CommonController {
     @Autowired
     private IFsInquiryOrderService inquiryOrderService;
 
+    @Autowired
+    private IQwMaterialService iQwMaterialService;
 
     /**
     * 发官方通连
@@ -139,9 +142,8 @@ public class CommonController {
     @GetMapping("/testSop")
     public R testSop() throws Exception {
 
-        byte[] bytes = inquiryOrderService.getWxaCodeInquiryOrderUnLimit(2582616L);
-        String base64 = Base64.getEncoder().encodeToString(bytes);
-        return R.ok().put("data",base64);
+        iQwMaterialService.updateQwMaterialByQw();
+        return R.ok();
     }
 
     @GetMapping("/testRatingSop")

+ 73 - 0
fs-qwhook-sop/src/main/java/com/fs/app/controller/ApisQwMaterialBySidebar.java

@@ -0,0 +1,73 @@
+package com.fs.app.controller;
+
+import com.fs.common.core.domain.R;
+import com.fs.qw.domain.QwUser;
+import com.fs.qw.param.QwMaterialParam;
+import com.fs.qw.param.QwMaterialParamBySidebar;
+import com.fs.qw.service.IQwExternalContactService;
+import com.fs.qw.service.IQwMaterialService;
+import com.fs.qw.vo.QwMaterialVO;
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
+import io.swagger.annotations.Api;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+@Api("素材库库相关接口")
+@RestController
+@RequestMapping("/app/fs/material")
+@Slf4j
+public class ApisQwMaterialBySidebar {
+
+
+
+    @Autowired
+    private IQwExternalContactService qwExternalContactService;
+
+    @Autowired
+    private IQwMaterialService qwMaterialService;
+
+    /**
+     * 查询素材库列表
+     */
+    @PostMapping("/MaterialList")
+    public R list(@RequestBody QwMaterialParamBySidebar param)
+    {
+
+        QwUser qwUser = qwExternalContactService.getQwUserByRedis(param.getCorpId().trim(),param.getQwUserId().trim());
+
+        if (qwUser == null || qwUser.getCompanyId() == null) {
+            return R.error("员工未绑定 销售公司 或 未获取到员工信息,请重试!");
+        }
+
+
+        PageHelper.startPage(param.getPageNum(), param.getPageSize());
+
+        QwMaterialParam materialParam=new QwMaterialParam();
+        materialParam.setCompanyId(qwUser.getCompanyId());
+
+        List<QwMaterialVO> list = qwMaterialService.selectQwMaterialList(materialParam);
+
+
+        PageInfo<QwMaterialVO> result = new PageInfo<>(list);
+        return R.ok().put("data", result);
+
+
+    }
+
+    @GetMapping("/updateMaterialTime/{materialId}")
+    public R updateMaterialTime(@PathVariable Long materialId) throws Exception {
+
+        return R.ok().put("data",qwMaterialService.selectQwMaterialByMaterialIdByTime(materialId));
+    }
+
+    @GetMapping("/getMaterialByTime/{materialId}")
+    public R getMaterialByTime(@PathVariable Long materialId) throws Exception {
+
+        return R.ok().put("data",qwMaterialService.selectQwMaterialByMaterialIdByTimeTwo(materialId));
+    }
+
+}

+ 72 - 0
fs-qwhook-sop/src/main/java/com/fs/app/controller/QwMaterialBySidebar.java

@@ -0,0 +1,72 @@
+package com.fs.app.controller;
+
+import com.fs.common.core.domain.R;
+import com.fs.qw.domain.QwUser;
+import com.fs.qw.param.QwMaterialParam;
+import com.fs.qw.param.QwMaterialParamBySidebar;
+import com.fs.qw.service.IQwExternalContactService;
+import com.fs.qw.service.IQwMaterialService;
+import com.fs.qw.vo.QwMaterialVO;
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
+import io.swagger.annotations.Api;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+@Api("素材库库相关接口")
+@RestController
+@RequestMapping("/apis/app/fs/material")
+@Slf4j
+public class QwMaterialBySidebar {
+
+
+
+    @Autowired
+    private IQwExternalContactService qwExternalContactService;
+
+    @Autowired
+    private IQwMaterialService qwMaterialService;
+
+    /**
+     * 查询素材库列表
+     */
+    @PostMapping("/MaterialList")
+    public R list(@RequestBody QwMaterialParamBySidebar param)
+    {
+
+        QwUser qwUser = qwExternalContactService.getQwUserByRedis(param.getCorpId().trim(),param.getQwUserId().trim());
+
+        if (qwUser == null || qwUser.getCompanyId() == null) {
+            return R.error("员工未绑定 销售公司 或 未获取到员工信息,请重试!");
+        }
+
+
+        PageHelper.startPage(param.getPageNum(), param.getPageSize());
+
+        QwMaterialParam materialParam=new QwMaterialParam();
+        materialParam.setCompanyId(qwUser.getCompanyId());
+
+        List<QwMaterialVO> list = qwMaterialService.selectQwMaterialList(materialParam);
+
+
+        PageInfo<QwMaterialVO> result = new PageInfo<>(list);
+        return R.ok().put("data", result);
+
+    }
+
+    @GetMapping("/updateMaterialTime/{materialId}")
+    public R updateMaterialTime(@PathVariable Long materialId) throws Exception {
+
+        return R.ok().put("data",qwMaterialService.selectQwMaterialByMaterialIdByTime(materialId));
+    }
+
+    @GetMapping("/getMaterialByTime/{materialId}")
+    public R getMaterialByTime(@PathVariable Long materialId) throws Exception {
+
+        return R.ok().put("data",qwMaterialService.selectQwMaterialByMaterialIdByTimeTwo(materialId));
+    }
+
+}

+ 81 - 0
fs-qwhook/src/main/java/com/fs/app/controller/ApisQwMaterialBySidebar.java

@@ -0,0 +1,81 @@
+package com.fs.app.controller;
+
+import com.fs.common.core.domain.R;
+import com.fs.qw.domain.QwMaterial;
+import com.fs.qw.domain.QwUser;
+import com.fs.qw.param.QwMaterialParam;
+import com.fs.qw.param.QwMaterialParamBySidebar;
+import com.fs.qw.service.IQwExternalContactService;
+import com.fs.qw.service.IQwMaterialService;
+import com.fs.qw.vo.QwMaterialVO;
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
+import io.swagger.annotations.Api;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+@Api("素材库库相关接口")
+@RestController
+@RequestMapping("/app/fs/material")
+@Slf4j
+public class ApisQwMaterialBySidebar {
+
+
+
+    @Autowired
+    private IQwExternalContactService qwExternalContactService;
+
+    @Autowired
+    private IQwMaterialService qwMaterialService;
+
+    /**
+     * 查询素材库列表
+     */
+    @PostMapping("/MaterialList")
+    public R list(@RequestBody QwMaterialParamBySidebar param)
+    {
+
+        QwUser qwUser = qwExternalContactService.getQwUserByRedis(param.getCorpId().trim(),param.getQwUserId().trim());
+
+        if (qwUser == null || qwUser.getCompanyId() == null) {
+            return R.error("员工未绑定 销售公司 或 未获取到员工信息,请重试!");
+        }
+
+
+        PageHelper.startPage(param.getPageNum(), param.getPageSize());
+
+        QwMaterialParam materialParam=new QwMaterialParam();
+        materialParam.setCompanyId(qwUser.getCompanyId());
+
+        List<QwMaterialVO> list = qwMaterialService.selectQwMaterialList(materialParam);
+
+
+        PageInfo<QwMaterialVO> result = new PageInfo<>(list);
+        return R.ok().put("data", result);
+
+
+    }
+
+    /**
+    * 更新 素材库的某个素材的 media_id
+    */
+    @GetMapping("/updateMaterialTime/{materialId}")
+    public R updateMaterialTime(@PathVariable Long materialId) throws Exception {
+
+        return R.ok().put("data",qwMaterialService.selectQwMaterialByMaterialIdByTime(materialId));
+    }
+
+    /**
+    * 获取某个素材id
+    */
+    @GetMapping("/getMaterialByTime/{materialId}")
+    public R getMaterialByTime(@PathVariable Long materialId) throws Exception {
+
+        return R.ok().put("data",qwMaterialService.selectQwMaterialByMaterialIdByTimeTwo(materialId));
+    }
+
+
+}

+ 73 - 0
fs-qwhook/src/main/java/com/fs/app/controller/QwMaterialBySidebar.java

@@ -0,0 +1,73 @@
+package com.fs.app.controller;
+
+import com.fs.common.core.domain.R;
+import com.fs.qw.domain.QwUser;
+import com.fs.qw.param.QwMaterialParam;
+import com.fs.qw.param.QwMaterialParamBySidebar;
+import com.fs.qw.service.IQwExternalContactService;
+import com.fs.qw.service.IQwMaterialService;
+import com.fs.qw.vo.QwMaterialVO;
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
+import io.swagger.annotations.Api;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
+
+@Api("素材库库相关接口")
+@RestController
+@RequestMapping("/apis/app/fs/material")
+@Slf4j
+public class QwMaterialBySidebar {
+
+
+
+    @Autowired
+    private IQwExternalContactService qwExternalContactService;
+
+    @Autowired
+    private IQwMaterialService qwMaterialService;
+
+    /**
+     * 查询素材库列表
+     */
+    @PostMapping("/MaterialList")
+    public R list(@RequestBody QwMaterialParamBySidebar param)
+    {
+
+        QwUser qwUser = qwExternalContactService.getQwUserByRedis(param.getCorpId().trim(),param.getQwUserId().trim());
+
+        if (qwUser == null || qwUser.getCompanyId() == null) {
+            return R.error("员工未绑定 销售公司 或 未获取到员工信息,请重试!");
+        }
+
+
+        PageHelper.startPage(param.getPageNum(), param.getPageSize());
+
+        QwMaterialParam materialParam=new QwMaterialParam();
+        materialParam.setCompanyId(qwUser.getCompanyId());
+
+        List<QwMaterialVO> list = qwMaterialService.selectQwMaterialList(materialParam);
+
+
+        PageInfo<QwMaterialVO> result = new PageInfo<>(list);
+        return R.ok().put("data", result);
+
+
+    }
+
+    @GetMapping("/updateMaterialTime/{materialId}")
+    public R updateMaterialTime(@PathVariable Long materialId) throws Exception {
+
+        return R.ok().put("data",qwMaterialService.selectQwMaterialByMaterialIdByTime(materialId));
+    }
+
+    @GetMapping("/getMaterialByTime/{materialId}")
+    public R getMaterialByTime(@PathVariable Long materialId) throws Exception {
+
+        return R.ok().put("data",qwMaterialService.selectQwMaterialByMaterialIdByTimeTwo(materialId));
+    }
+
+}

+ 11 - 2
fs-service/src/main/java/com/fs/qw/domain/QwMaterial.java

@@ -1,5 +1,7 @@
 package com.fs.qw.domain;
 
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import com.fs.common.annotation.Excel;
 import com.fs.common.core.domain.BaseEntity;
@@ -14,11 +16,12 @@ import java.util.Date;
  * @date 2024-06-20
  */
 @Data
-public class QwMaterial extends BaseEntity
+public class QwMaterial
 {
     private static final long serialVersionUID = 1L;
 
     /** 素材库id */
+    @TableId(type = IdType.AUTO)
     private Long materialId;
 
     /** 媒体文件类型,分别有图片(image),语音(voice),视频(video),普通文件(file) */
@@ -31,7 +34,7 @@ public class QwMaterial extends BaseEntity
 
     /** 媒体文件上传时间戳 */
     @Excel(name = "媒体文件上传时间戳")
-    private String createdAt;
+    private Long createdAt;
 
     /** 文件地址,图片可以上传永久的,其他类型的3天有效 */
     @Excel(name = "文件地址,图片可以上传永久的,其他类型的3天有效")
@@ -74,6 +77,12 @@ public class QwMaterial extends BaseEntity
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private Date createTime;
 
+    /**
+     *  更新时间
+     */
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date updateTime;
+
 
     /**
      *  素材分类 1 普通素材组 2 朋友圈素材组

+ 5 - 1
fs-service/src/main/java/com/fs/qw/mapper/QwMaterialMapper.java

@@ -1,6 +1,7 @@
 package com.fs.qw.mapper;
 
 
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.fs.qw.domain.QwMaterial;
 import com.fs.qw.param.QwMaterialParam;
 import com.fs.qw.vo.QwMaterialVO;
@@ -15,7 +16,7 @@ import java.util.List;
  * @author fs
  * @date 2024-06-20
  */
-public interface QwMaterialMapper
+public interface QwMaterialMapper extends BaseMapper<QwMaterial>
 {
     /**
      * 查询素材库
@@ -107,4 +108,7 @@ public interface QwMaterialMapper
      * @return 结果
      */
     public int deleteQwMaterialByMaterialIds(Long[] materialIds);
+    public List<QwMaterial> selectQwMaterialListByMediaIdList();
+
+
 }

+ 6 - 1
fs-service/src/main/java/com/fs/qw/param/QwMaterialParam.java

@@ -1,10 +1,12 @@
 package com.fs.qw.param;
 
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.fasterxml.jackson.annotation.JsonFormat;
 import com.fs.common.annotation.Excel;
 import com.fs.common.core.domain.BaseEntity;
 import lombok.Data;
 
+import java.io.Serializable;
 import java.util.Date;
 
 /**
@@ -14,7 +16,7 @@ import java.util.Date;
  * @date 2024-06-20
  */
 @Data
-public class QwMaterialParam extends BaseEntity
+public class QwMaterialParam extends BaseEntity implements Serializable
 {
     private static final long serialVersionUID = 1L;
 
@@ -79,4 +81,7 @@ public class QwMaterialParam extends BaseEntity
      *  素材分类 1 普通素材组 2 朋友圈素材组
      */
     private Integer groupType;
+
+    @TableField(exist = false)
+    private String QwUserId;
 }

+ 28 - 0
fs-service/src/main/java/com/fs/qw/param/QwMaterialParamBySidebar.java

@@ -0,0 +1,28 @@
+package com.fs.qw.param;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+
+@Data
+public class QwMaterialParamBySidebar  implements Serializable  {
+
+
+    @ApiModelProperty(value = "页码,默认为1", required = true)
+    private Integer pageNum = 1;
+
+    @ApiModelProperty(value = "页大小,默认为10", required = true)
+    private Integer pageSize = 10;
+
+    @ApiModelProperty(value = "模糊搜索,通过视频名称来匹配")
+    private String keyword;
+
+    @ApiModelProperty(value = "公司id")
+    private Long companyId;
+
+    private String corpId;
+
+    private String qwUserId;
+
+}

+ 8 - 0
fs-service/src/main/java/com/fs/qw/service/IQwMaterialService.java

@@ -63,4 +63,12 @@ public interface IQwMaterialService
      * @return 结果
      */
     public int deleteQwMaterialByMaterialId(Long materialId);
+
+    /**
+    * 定时更新 上传的企业微信素材库
+    */
+    public void updateQwMaterialByQw();
+
+    public QwMaterial selectQwMaterialByMaterialIdByTime(Long materialId) throws Exception;
+    public QwMaterial selectQwMaterialByMaterialIdByTimeTwo(Long materialId) throws Exception;
 }

+ 147 - 7
fs-service/src/main/java/com/fs/qw/service/impl/QwMaterialServiceImpl.java

@@ -1,6 +1,7 @@
 package com.fs.qw.service.impl;
 
 
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fs.common.core.domain.R;
 import com.fs.common.utils.DateUtils;
 import com.fs.qw.domain.QwMaterial;
@@ -11,6 +12,7 @@ import com.fs.qw.vo.QwMaterialVO;
 import com.fs.qwApi.Result.QwUploadResult;
 import com.fs.qwApi.service.QwApiService;
 import com.fs.voice.utils.StringUtil;
+import lombok.extern.log4j.Log4j2;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -19,8 +21,14 @@ import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.net.URL;
+import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.stream.Collectors;
 
 /**
  * 素材库Service业务层处理
@@ -28,8 +36,9 @@ import java.util.List;
  * @author fs
  * @date 2024-06-20
  */
+@Log4j2
 @Service
-public class QwMaterialServiceImpl implements IQwMaterialService
+public class QwMaterialServiceImpl extends ServiceImpl<QwMaterialMapper, QwMaterial> implements IQwMaterialService
 {
     @Autowired
     private QwMaterialMapper qwMaterialMapper;
@@ -73,14 +82,62 @@ public class QwMaterialServiceImpl implements IQwMaterialService
 
         //调用企业微信接口 上次临时图片
 
-        File fileImage = urlToFile(qwMaterial.getMaterialUrl());
-        QwUploadResult imageResult = qwApiService.upload(fileImage, "image", qwMaterial.getCorpId());
-        if (imageResult.getErrCode()==0){
-            qwMaterial.setMaterialMediaId(imageResult.getMediaId());
+        if ("text".equals(qwMaterial.getMaterialType())){
             qwMaterialMapper.insertQwMaterial(qwMaterial);
             return R.ok();
-        }else {
-            return R.error("上传图片失败:"+imageResult.getErrMsg());
+        }else if ("image".equals(qwMaterial.getMaterialType())
+                ||"video".equals(qwMaterial.getMaterialType())
+                ||"file".equals(qwMaterial.getMaterialType())){
+            return uploadAndSaveQwMaterial(qwMaterial);
+        }
+
+        return R.ok();
+
+    }
+
+    public R uploadAndSaveQwMaterial(QwMaterial qwMaterial){
+        try {
+            // 将URL转换为文件
+            File materialFile = urlToFile(qwMaterial.getMaterialUrl());
+
+            // 上传素材到企业微信
+            QwUploadResult uploadResult = qwApiService.upload(materialFile, qwMaterial.getMaterialType(), qwMaterial.getCorpId());
+
+            if (uploadResult.getErrCode() == 0) {
+                // 设置素材信息并保存到数据库
+                qwMaterial.setMaterialMediaId(uploadResult.getMediaId());
+                qwMaterial.setCreatedAt(Long.valueOf(uploadResult.getCreatedAt()));
+                qwMaterialMapper.insertQwMaterial(qwMaterial);
+                return R.ok();
+            } else {
+                return R.error("上传"+qwMaterial.getMaterialType()+"失败:" + uploadResult.getErrMsg());
+            }
+        } catch (Exception e) {
+            return R.error("处理"+qwMaterial.getMaterialType()+"时发生异常:" + e.getMessage());
+        }
+    }
+
+    public QwMaterial uploadAndSaveQwMaterialByDTO(QwMaterial qwMaterial){
+        try {
+            // 将URL转换为文件
+            File materialFile = urlToFile(qwMaterial.getMaterialUrl());
+
+            // 上传素材到企业微信
+            QwUploadResult uploadResult = qwApiService.upload(materialFile, qwMaterial.getMaterialType(), qwMaterial.getCorpId());
+
+            if (uploadResult.getErrCode() == 0) {
+                // 设置素材信息并保存到数据库
+                qwMaterial.setMaterialMediaId(uploadResult.getMediaId());
+                qwMaterial.setCreatedAt(Long.valueOf(uploadResult.getCreatedAt()));
+                qwMaterialMapper.insertQwMaterial(qwMaterial);
+                return qwMaterial;
+            } else {
+                log.error("上传DTO"+qwMaterial.getMaterialType()+"失败:" + uploadResult.getErrMsg());
+                return null;
+            }
+        } catch (Exception e) {
+            log.error("处理DTO"+qwMaterial.getMaterialType()+"时发生异常:" + e.getMessage());
+            return null;
         }
     }
 
@@ -188,6 +245,89 @@ public class QwMaterialServiceImpl implements IQwMaterialService
     @Override
     public int deleteQwMaterialByMaterialId(Long materialId)
     {
+        log.info("删除素材库中信息:{}",qwMaterialMapper.selectQwMaterialByMaterialId(materialId));
         return qwMaterialMapper.deleteQwMaterialByMaterialId(materialId);
     }
+
+    @Override
+    public void updateQwMaterialByQw() {
+
+        List<QwMaterial> qwMaterials = qwMaterialMapper.selectQwMaterialListByMediaIdList();
+
+
+        // 创建线程安全的集合用于存储处理结果
+        ConcurrentLinkedQueue<QwMaterial> successQueue = new ConcurrentLinkedQueue<>();
+
+        // 创建线程池
+        int threadPoolSize = Math.min(8, Runtime.getRuntime().availableProcessors() * 2);
+        ExecutorService executor = Executors.newFixedThreadPool(threadPoolSize);
+
+        try {
+            // 创建并执行所有异步任务
+            List<CompletableFuture<Void>> futures = qwMaterials.stream()
+                    .filter(item -> "image".equals(item.getMaterialType())
+                            || "video".equals(item.getMaterialType())
+                            || "file".equals(item.getMaterialType()))
+                    .map(item -> CompletableFuture.runAsync(() -> {
+                        try {
+                            // 将URL转换为文件
+                            File materialFile = urlToFile(item.getMaterialUrl());
+
+                            // 上传素材到企业微信
+                            QwUploadResult uploadResult = qwApiService.upload(
+                                    materialFile,
+                                    item.getMaterialType(),
+                                    item.getCorpId()
+                            );
+
+                            if (uploadResult.getErrCode() == 0) {
+                                // 设置素材信息
+                                item.setMaterialMediaId(uploadResult.getMediaId());
+                                item.setCreatedAt(Long.valueOf(uploadResult.getCreatedAt()));
+                                successQueue.add(item);
+                            } else {
+                                log.error("上传失败:{},{}", uploadResult.getErrMsg(), item);
+                            }
+                        } catch (Exception e) {
+                            log.error("上传失败异常:{},{}", e.getMessage(), item);
+                        }
+                    }, executor))
+                    .collect(Collectors.toList());
+
+            // 等待所有任务完成
+            CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
+
+            // 批量更新成功的记录
+            if (!successQueue.isEmpty()) {
+                super.saveOrUpdateBatch(new ArrayList<>(successQueue),300);
+            }
+
+
+        } finally {
+            // 关闭线程池
+            executor.shutdown();
+        }
+    }
+
+    @Override
+    public QwMaterial selectQwMaterialByMaterialIdByTime(Long materialId) throws Exception {
+
+        return uploadAndSaveQwMaterialByDTO(qwMaterialMapper.selectQwMaterialByMaterialId(materialId));
+    }
+
+    @Override
+    public QwMaterial selectQwMaterialByMaterialIdByTimeTwo(Long materialId) throws Exception {
+
+        QwMaterial qwMaterial = qwMaterialMapper.selectQwMaterialByMaterialId(materialId);
+
+        Long createdAt = qwMaterial.getCreatedAt();
+        boolean isOver48h = createdAt != null
+                && (System.currentTimeMillis() / 1000 - createdAt) > 172800;
+
+        if (qwMaterial.getMaterialType() != null && isOver48h) {
+            return uploadAndSaveQwMaterialByDTO(qwMaterial);
+        }
+
+        return qwMaterial;
+    }
 }

+ 1 - 0
fs-service/src/main/resources/application-config-dev.yml

@@ -85,6 +85,7 @@ headerImg:
   imgUrl: https://jz-cos-1356808054.cos.ap-chengdu.myqcloud.com/fs/20250515/0877754b59814ea8a428fa3697b20e68.png
 ipad:
   ipadUrl: http://ipad.cdwjyyh.com
+  aiApi:
 wx_miniapp_temp:
   pay_order_temp_id:
   inquiry_temp_id:

+ 1 - 0
fs-service/src/main/resources/application-config-druid-xfk.yml

@@ -87,6 +87,7 @@ headerImg:
   imgUrl: https://xiaofangke-1360933944.cos.ap-nanjing.myqcloud.com/xiaofangke/20250610/9c3fb587d224492e8b61f5dece0b8b7b.png
 ipad:
   ipadUrl: http://ipad.cdwjyyh.com
+  aiApi:
 wx_miniapp_temp:
   pay_order_temp_id: VXEvKaGNPFuJmhWK9O_QPrTZxe9umDCukq-maI8Vdek
   inquiry_temp_id: 9POPYeqhI48LOPvq-Rfoklze7H-9SlunJKh10Qt4_2I

+ 10 - 0
fs-service/src/main/resources/mapper/qw/QwMaterialMapper.xml

@@ -54,6 +54,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         where material_id = #{materialId}
     </select>
 
+    <select id="selectQwMaterialListByMediaIdList"  resultMap="QwMaterialResult">
+        SELECT
+            material_id, material_type, material_media_id, created_at, material_name,
+            material_url, material_group_id, company_id, text_content, create_time,
+            title, title_url, update_time, create_user_id, send_count, group_type, corp_id
+        FROM qw_material
+        WHERE material_media_id IS NOT NULL
+        AND created_at &lt; UNIX_TIMESTAMP() - 48*3600;
+    </select>
+
     <insert id="insertQwMaterial" parameterType="QwMaterial">
         insert into qw_material
         <trim prefix="(" suffix=")" suffixOverrides=",">