bug
jiangqs
2023-08-29 1695aa136a89421b1cff75d672888e81d2a24d9a
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/staff/SysWxCpServiceImpl.java
@@ -1,6 +1,11 @@
package com.ruoyi.system.service.impl.staff;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.system.api.domain.poji.sys.SysDept;
import com.ruoyi.system.api.domain.vo.MgtUserTaskMsgVo;
import com.ruoyi.system.api.service.RemoteShopService;
import com.ruoyi.system.domain.pojo.staff.SysStaff;
import com.ruoyi.system.service.staff.SysStaffService;
import com.ruoyi.system.service.staff.SysWxCpService;
import com.ruoyi.system.service.sys.ISysDeptService;
import lombok.extern.log4j.Log4j2;
@@ -8,6 +13,8 @@
import me.chanjar.weixin.cp.api.WxCpDepartmentService;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.WxCpDepart;
import me.chanjar.weixin.cp.bean.message.WxCpMessage;
import me.chanjar.weixin.cp.bean.message.WxCpMessageSendResult;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@@ -28,7 +35,13 @@
    private WxCpService wxCpService;
    @Resource
    private RemoteShopService remoteShopService;
    @Resource
    private ISysDeptService  sysDeptService;
    @Resource
    private SysStaffService sysStaffService;
    /**
     * @description
     * @author  jqs
@@ -94,4 +107,35 @@
            throw new RuntimeException(e);
        }
    }
    /**
     * @description  企业微信消息推送
     * @author  jqs
     * @date    2023/8/29 11:05
     * @return  void
     */
    @Override
    public void sendTaskMessage(){
        List<MgtUserTaskMsgVo> userTaskMsgVoList = remoteShopService.getTaskMsgList().getData();
        WxCpMessage message;
        SysStaff sysStaff;
        if(userTaskMsgVoList!=null&&!userTaskMsgVoList.isEmpty()){
            for(MgtUserTaskMsgVo mgtUserTaskMsgVo : userTaskMsgVoList){
                sysStaff = sysStaffService.getByUserId(mgtUserTaskMsgVo.getUserId());
                if(sysStaff!=null&& StringUtils.isNotBlank(sysStaff.getWxUserId())){
                    message = new WxCpMessage();
                    message.setAgentId(1000024);
                    message.setToUser(sysStaff.getWxUserId());
                    message.setMsgType("text");
                    message.setContent(mgtUserTaskMsgVo.getTaskTitle()+"今日需要任务跟进,请注意!");
                    try {
                        WxCpMessageSendResult result = wxCpService.getMessageService().send(message);
                        System.out.println(result);
                    } catch (WxErrorException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        }
    }
}