同步Activiti待办事项和未读消息,并返回同步后的消息

  • Post author:
  • Post category:其他


    /**
     * 查询未读消息列表
     */
@PreAuthorize
    //@PreAuthorize("@ss.hasPermi('Info:message:list')")
    @GetMapping("/list")
    public TableDataInfo list(InfoMessage infoMessage) {
        beforeList(infoMessage);
        startPage();
        List<InfoMessage> list = infoMessageService.selectInfoMessageList(infoMessage);
        return getDataTable(list);
    }
    //同步待办和未读消息
    private  void beforeList(InfoMessage infoMessage) {
        int n=0;
        //是否有待办
        TaskVo taskVo = new TaskVo();
        taskVo.setUserId(SecurityUtils.getLoginUser().getUser().getUserName());
        TableDataInfo tableDataInfo = processService.findTodoTasks(taskVo);
        //如果有待办
        if (tableDataInfo.getTotal() > 0) {
            //待办事项
            List<TaskVo> taskVos = (List<TaskVo>) tableDataInfo.getRows();
            //未读消息
            infoMessage.setReadFlag(0L);
            List<InfoMessage> infoMessageList = infoMessageService.selectInfoMessageList(infoMessage);
            //待办任务和未读消息的差异数据
            List<TaskVo> taskVoDefrent = listDefrent(infoMessageList, taskVos);
            //差异数据转换
            List<InfoMessage> infoMessages = new ArrayList<InfoMessage>();
            if(infoMessages.size()>0)
            {
                for (TaskVo taskVoD : taskVoDefrent) {
                    InfoMessage infoMessage1 = new InfoMessage();
                    infoMessage1.setMessageclassid(PMTaskLogClassId.change.toString());
                    infoMessage1.setMessageclassname(PMTaskLogClass.变更.toString());
                    infoMessage1.setAcceptorid(taskVoD.getUserId());
                    infoMessage1.setAcceptorname(SecurityUtils.getLoginUser().getUser().getNickName());
                    infoMessage1.setMainid(taskVoD.getInstanceId());
                    infoMessage1.setTitle(taskVoD.getTaskName());
                    infoMessages.add(infoMessage1);
                }
                //批量插入
                n = infoMessageService.batchInsertInfoMessage(infoMessages);
                if(n>0)
                {System.out.println("插入成功!"+n+"条消息");}
                else
                {System.out.println("没有插入新消息!");}
            }
            else
            {System.out.println("没有差异待办信息!");}
        }
        else
        {
            System.out.println("没有新待办!");
        }
    }

        //比较两个list
        //取出存在menuOneList中,但不存在resourceList中的数据,差异数据放入differentList
        private List<TaskVo> listDefrent (List < InfoMessage > infoMessageList, List < TaskVo > taskVoList){

            List<TaskVo> sameList = new ArrayList<TaskVo>();

            for (TaskVo taskVo : taskVoList) {
                for (InfoMessage infoMessage : infoMessageList) {
                    //待办事项在已读消息列表
                    if (infoMessage.getMainid() == taskVo.getInstanceId()) ;
                    sameList.add(taskVo);
                }
            }
            taskVoList.removeAll(sameList);
            return taskVoList;
        }



版权声明:本文为wenxi2367原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。