bug
jiangqs
2023-09-11 3adbcc42d5f84c3c83d220543189361add81e04d
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/staff/SysStaffServiceImpl.java
@@ -16,6 +16,7 @@
import com.ruoyi.system.api.domain.dto.MgtShopStaffEditDto;
import com.ruoyi.system.api.domain.poji.sys.SysDept;
import com.ruoyi.system.api.domain.poji.sys.SysUser;
import com.ruoyi.system.api.domain.vo.MgtUserTaskMsgVo;
import com.ruoyi.system.api.service.RemoteShopService;
import com.ruoyi.system.domain.dto.MgtStaffEditDto;
import com.ruoyi.system.domain.dto.MgtStaffPageDto;
@@ -31,6 +32,11 @@
import com.ruoyi.system.service.sys.ISysDeptService;
import com.ruoyi.system.service.sys.ISysUserService;
import com.ruoyi.system.util.QiYeUtils;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.message.WxCpMessage;
import me.chanjar.weixin.cp.bean.message.WxCpMessageSendResult;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@@ -69,6 +75,10 @@
    @Resource
    private ISysDeptService sysDeptService;
    @Resource
    @Qualifier("wxService")
    private WxCpService wxCpService;
    /**
@@ -190,7 +200,8 @@
        mgtShopStaffEditDto.setStaffAvatar(sysStaff.getStaffAvatar());
        remoteShopService.editMgtShopStaff(mgtShopStaffEditDto);
        //如果wxUserId和wxDeptId不为空 同步到企业微信
        if(mgtStaffEditDto.getWxUserId()!=null&&sysDept.getWxDeptId()!=null){
        if(sysStaff.getWxUserId()!=null&&sysDept.getWxDeptId()!=null){
            log.debug("同步员工到企业微信:"+mgtStaffEditDto.getStaffName());
            MgtWxCPStaffDto mgtWxCPStaffDto = new MgtWxCPStaffDto();
            mgtWxCPStaffDto.setWxDeptId(sysDept.getWxDeptId());
            mgtWxCPStaffDto.setWxUserId(mgtStaffEditDto.getWxUserId());
@@ -436,4 +447,37 @@
    public List<SysStaff> listSysStaffByIds(List<Long> userIdList){
        return sysStaffMapper.listSysStaffByIds(userIdList);
    }
    /**
     * @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 = this.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);
                    }
                }
            }
        }
    }
}