//package com.zjty.tynotes.job.status.service.impl;
//
//import com.zjty.tynotes.job.basic.entity.database.Work;
//import com.zjty.tynotes.job.basic.service.WorkService;
//import com.zjty.tynotes.job.common.Constants;
//import com.zjty.tynotes.job.common.exception.WorkAttribution;
//import com.zjty.tynotes.job.common.exception.WorkAttribution1;
//import com.zjty.tynotes.job.status.entity.RedisPersonalWork;
//import com.zjty.tynotes.job.status.entity.RoleSum;
//import com.zjty.tynotes.job.status.service.WorkShowService;
//import com.zjty.tynotes.job.status.utils.JacksonUtil;
//import com.zjty.tynotes.pas.service.IUserService;
//import com.zjty.tynotes.search.subject.entity.EsSource;
//import com.zjty.tynotes.search.subject.service.EsUtil;
//import com.zjty.tynotes.sms.service.MessageTemplateService;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.data.redis.core.RedisTemplate;
//import org.springframework.stereotype.Service;
//
//import java.util.*;
//import java.util.concurrent.CompletableFuture;
//
//@Slf4j
//@Service
//public class WorkShowServiceImpl implements WorkShowService {
//    @Autowired
//    private RedisTemplate<String,Object> redisTemplate;
//
//    @Autowired
//    MessageTemplateService messageTemplateService;
//
//    @Autowired
//    WorkService workService;
//
//    @Autowired
//    EsUtil esUtil;
//
//    @Autowired
//    IUserService iUserService;
//
//    @Override
//    public void test(String executorId, String latestNews, Work work) {
//        List<String> uIds=new ArrayList<>();
//
//        Long time=new Date().getTime();
//        String releaseName= iUserService.findUserById(work.getPublisher()).getUsername();
//        String executorName= iUserService.findUserById(work.getExecutor()).getUsername();
//        RedisPersonalWork personalWork=new RedisPersonalWork(work.getId(),time,work.getTitle(),work.getStatus(),releaseName,executorName,1,WorkAttribution.ME_WORK,latestNews,work.getSuperiorId(),new ArrayList<>(),0);
//        //发布人
//        if (work.getSuperiorId()==null){
//            personalWork.setWorkAttribution(WorkAttribution1.ME_RELEASE_WORK);
//            personalWork.setReadState(0);
//            redisTemplate.opsForList().leftPush(Constants.REDIS_EVENT+work.getPublisher(),personalWork);
//
//            asynchronousAddEs(Constants.REDIS_EVENT+work.getPublisher(),personalWork);
//            List<Object> list=redisTemplate.opsForList().range(Constants.REDIS_EVENT+work.getPublisher(),0,-1);
//            assert list != null;
//            pushData(work.getPublisher(),JacksonUtil.toJSon(statisticalRoleCount(list)));
//            log.info("{}这里发送{}",work.getPublisher(), JacksonUtil.toJSon(statisticalRoleCount(list)));
//
//        }else {
//            uIds=tests(work.getSuperiorId(),uIds);
//            personalWork.setWorkAttribution(WorkAttribution.ME_RESOLVE_WORK);
//            personalWork.setReadState(0);
//            redisTemplate.opsForList().leftPush(Constants.REDIS_EVENT+work.getPublisher(),personalWork);
//
//            asynchronousAddEs(Constants.REDIS_EVENT+work.getPublisher(),personalWork);
//            List<Object> list=redisTemplate.opsForList().range(Constants.REDIS_EVENT+work.getPublisher(),0,-1);
//            assert list != null;
//            pushData(work.getPublisher(),JacksonUtil.toJSon(statisticalRoleCount(list)));
//            subWork(list,work,work.getPublisher());
//            log.info("{}这里发送{}",work.getPublisher(), JacksonUtil.toJSon(statisticalRoleCount(list)));
//        }
//        //执行人 判断执行人是否有分解权限
//        boolean flag=true;
//        if (flag){
//            personalWork.setWorkAttribution(WorkAttribution.ME_RECEIVE_WORK);
//            personalWork.setReadState(1);
//            redisTemplate.opsForList().leftPush(Constants.REDIS_EVENT+work.getExecutor(),personalWork);
//
//            asynchronousAddEs(Constants.REDIS_EVENT+work.getExecutor(),personalWork);
//            List<Object> list=redisTemplate.opsForList().range(Constants.REDIS_EVENT+work.getExecutor(),0,-1);
//            assert list != null;
//            pushData(work.getExecutor(),JacksonUtil.toJSon(statisticalRoleCount(list)));
//            subWork(list,work,work.getExecutor());
//            log.info("{}这里发送{}",work.getExecutor(), JacksonUtil.toJSon(statisticalRoleCount(list)));
//        }else {
//            personalWork.setWorkAttribution(WorkAttribution.ME_WORK);
//            personalWork.setReadState(1);
//            redisTemplate.opsForList().leftPush(Constants.REDIS_EVENT+work.getExecutor(),personalWork);
//
//            asynchronousAddEs(Constants.REDIS_EVENT+work.getExecutor(),personalWork);
//            List<Object> list=redisTemplate.opsForList().range(Constants.REDIS_EVENT+work.getExecutor(),0,-1);
//            assert list != null;
//            pushData(work.getExecutor(),JacksonUtil.toJSon(statisticalRoleCount(list)));
//            subWork(list,work,work.getExecutor());
//            log.info("{}这里发送{}",work.getExecutor(), JacksonUtil.toJSon(statisticalRoleCount(list)));
//        }
//        //有待修改
//        if (uIds.size()!=0) {
//            for (String id : uIds) {
//                personalWork.setWorkAttribution(0);
//                personalWork.setReadState(1);
//                redisTemplate.opsForList().leftPush(Constants.REDIS_EVENT + id, personalWork);
//
//                asynchronousAddEs(Constants.REDIS_EVENT + id, personalWork);
//                List<Object> list = redisTemplate.opsForList().range(Constants.REDIS_EVENT + id, 0, -1);
//                assert list != null;
//                pushData(id, JacksonUtil.toJSon(statisticalRoleCount(list)));
//                subWork(list, work, id);
//                log.info("{}这里发送{}", id, JacksonUtil.toJSon(statisticalRoleCount(list)));
//            }
//        }
//
//
//    }
//
//    private List<String> tests(String id,List<String> list){
//        Work work=workService.findById(id);
//        String workId=work.getSuperiorId();
//        list.add(work.getPublisher());
//        if (workId==null || "".equals(workId)){
//            return list;
//        }
//        return tests(workId,list);
//    }
//
//    //加一个时间
//    @Override
//    public void saveTakePushWork(String executorId, String latestNews, List<String> userIds, Work work) {
//        Long time=new Date().getTime();
//        String releaseName= iUserService.findUserById(work.getPublisher()).getUsername();
//        String executorName= iUserService.findUserById(work.getExecutor()).getUsername();
//        RedisPersonalWork personalWork=new RedisPersonalWork(work.getId(),time,work.getTitle(),work.getStatus(),releaseName,executorName,1,WorkAttribution.ME_WORK,latestNews,work.getSuperiorId(),new ArrayList<>(),0);
//        //发布人
//        if (work.getSuperiorId()==null){
//            personalWork.setWorkAttribution(WorkAttribution.ME_RELEASE_WORK);
//            personalWork.setReadState(0);
//            redisTemplate.opsForList().leftPush(Constants.REDIS_EVENT+work.getPublisher(),personalWork);
//
//            asynchronousAddEs(Constants.REDIS_EVENT+work.getPublisher(),personalWork);
//            List<Object> list=redisTemplate.opsForList().range(Constants.REDIS_EVENT+work.getPublisher(),0,-1);
//            assert list != null;
//            pushData(work.getPublisher(),JacksonUtil.toJSon(statisticalRoleCount(list)));
//            log.info("{}这里发送{}",work.getPublisher(), JacksonUtil.toJSon(statisticalRoleCount(list)));
//
//        }else {
//            personalWork.setWorkAttribution(WorkAttribution.ME_RESOLVE_WORK);
//            personalWork.setReadState(0);
//            redisTemplate.opsForList().leftPush(Constants.REDIS_EVENT+work.getPublisher(),personalWork);
//
//            asynchronousAddEs(Constants.REDIS_EVENT+work.getPublisher(),personalWork);
//            List<Object> list=redisTemplate.opsForList().range(Constants.REDIS_EVENT+work.getPublisher(),0,-1);
//            assert list != null;
//            pushData(work.getPublisher(),JacksonUtil.toJSon(statisticalRoleCount(list)));
//            log.info("{}这里发送{}",work.getPublisher(), JacksonUtil.toJSon(statisticalRoleCount(list)));
//        }
//        //执行人 判断执行人是否有分解权限
//        boolean flag=true;
//        if (flag){
//            personalWork.setWorkAttribution(WorkAttribution.ME_RECEIVE_WORK);
//            personalWork.setReadState(1);
//            redisTemplate.opsForList().leftPush(Constants.REDIS_EVENT+work.getExecutor(),personalWork);
//
//            asynchronousAddEs(Constants.REDIS_EVENT+work.getExecutor(),personalWork);
//            List<Object> list=redisTemplate.opsForList().range(Constants.REDIS_EVENT+work.getExecutor(),0,-1);
//            assert list != null;
//            pushData(work.getExecutor(),JacksonUtil.toJSon(statisticalRoleCount(list)));
//            log.info("{}这里发送{}",work.getExecutor(), JacksonUtil.toJSon(statisticalRoleCount(list)));
//        }else {
//            personalWork.setWorkAttribution(WorkAttribution.ME_WORK);
//            personalWork.setReadState(1);
//            redisTemplate.opsForList().leftPush(Constants.REDIS_EVENT+work.getExecutor(),personalWork);
//
//            asynchronousAddEs(Constants.REDIS_EVENT+work.getExecutor(),personalWork);
//            List<Object> list=redisTemplate.opsForList().range(Constants.REDIS_EVENT+work.getExecutor(),0,-1);
//            assert list != null;
//            pushData(work.getExecutor(),JacksonUtil.toJSon(statisticalRoleCount(list)));
//            log.info("{}这里发送{}",work.getExecutor(), JacksonUtil.toJSon(statisticalRoleCount(list)));
//        }
//        //有待修改
//        for (String id:userIds){
//            personalWork.setWorkAttribution(WorkAttribution.ME_RELEASE_WORK);
//            personalWork.setReadState(1);
//            redisTemplate.opsForList().leftPush(Constants.REDIS_EVENT+id,personalWork);
//
//            asynchronousAddEs(Constants.REDIS_EVENT+id,personalWork);
//            List<Object> list=redisTemplate.opsForList().range(Constants.REDIS_EVENT+id,0,-1);
//            assert list != null;
//            pushData(id,JacksonUtil.toJSon(statisticalRoleCount(list)));
//            log.info("{}这里发送{}",id, JacksonUtil.toJSon(statisticalRoleCount(list)));
//        }
//    }
//
//    @Override
//    public void saveTakePushWork1(String executorId, String latestNews, List<String> userIds, Work work) {
//        Long time=new Date().getTime();
//        String releaseName= iUserService.findUserById(work.getPublisher()).getUsername();
//        String executorName= iUserService.findUserById(work.getExecutor()).getUsername();
//        RedisPersonalWork personalWork=new RedisPersonalWork(work.getId(),time,work.getTitle(),work.getStatus(),releaseName,executorName,1,WorkAttribution.ME_WORK,latestNews,work.getSuperiorId(),new ArrayList<>(),0);
//        //发布人
//        if (work.getSuperiorId()==null){
//            personalWork.setWorkAttribution(WorkAttribution.ME_RELEASE_WORK);
//            personalWork.setReadState(0);
//            redisTemplate.opsForList().leftPush(Constants.REDIS_EVENT+work.getPublisher(),personalWork);
//
//            asynchronousAddEs(Constants.REDIS_EVENT+work.getPublisher(),personalWork);
//            List<Object> list=redisTemplate.opsForList().range(Constants.REDIS_EVENT+work.getPublisher(),0,-1);
//            assert list != null;
//            pushData(work.getPublisher(),JacksonUtil.toJSon(statisticalRoleCount(list)));
//            subWork(list,work,work.getPublisher());
//            log.info("{}这里发送{}",work.getPublisher(), JacksonUtil.toJSon(statisticalRoleCount(list)));
//
//        }else {
//            personalWork.setWorkAttribution(WorkAttribution.ME_RESOLVE_WORK);
//            personalWork.setReadState(0);
//            redisTemplate.opsForList().leftPush(Constants.REDIS_EVENT+work.getPublisher(),personalWork);
//
//            asynchronousAddEs(Constants.REDIS_EVENT+work.getPublisher(),personalWork);
//            List<Object> list=redisTemplate.opsForList().range(Constants.REDIS_EVENT+work.getPublisher(),0,-1);
//            assert list != null;
//            pushData(work.getPublisher(),JacksonUtil.toJSon(statisticalRoleCount(list)));
//            subWork(list,work,work.getPublisher());
//            log.info("{}这里发送{}",work.getPublisher(), JacksonUtil.toJSon(statisticalRoleCount(list)));
//        }
//        //执行人 判断执行人是否有分解权限
//        boolean flag=true;
//        if (flag){
//            personalWork.setWorkAttribution(WorkAttribution.ME_RECEIVE_WORK);
//            personalWork.setReadState(1);
//            redisTemplate.opsForList().leftPush(Constants.REDIS_EVENT+work.getExecutor(),personalWork);
//
//            asynchronousAddEs(Constants.REDIS_EVENT+work.getExecutor(),personalWork);
//            List<Object> list=redisTemplate.opsForList().range(Constants.REDIS_EVENT+work.getExecutor(),0,-1);
//            assert list != null;
//            pushData(work.getExecutor(),JacksonUtil.toJSon(statisticalRoleCount(list)));
//            subWork(list,work,work.getExecutor());
//            log.info("{}这里发送{}",work.getExecutor(), JacksonUtil.toJSon(statisticalRoleCount(list)));
//        }else {
//            personalWork.setWorkAttribution(WorkAttribution.ME_WORK);
//            personalWork.setReadState(1);
//            redisTemplate.opsForList().leftPush(Constants.REDIS_EVENT+work.getExecutor(),personalWork);
//
//            asynchronousAddEs(Constants.REDIS_EVENT+work.getExecutor(),personalWork);
//            List<Object> list=redisTemplate.opsForList().range(Constants.REDIS_EVENT+work.getExecutor(),0,-1);
//            assert list != null;
//            pushData(work.getExecutor(),JacksonUtil.toJSon(statisticalRoleCount(list)));
//            subWork(list,work,work.getExecutor());
//            log.info("{}这里发送{}",work.getExecutor(), JacksonUtil.toJSon(statisticalRoleCount(list)));
//        }
//        //有待修改
//        for (String id:userIds){
//            personalWork.setWorkAttribution(WorkAttribution.ME_RELEASE_WORK);
//            personalWork.setReadState(1);
//            redisTemplate.opsForList().leftPush(Constants.REDIS_EVENT+id,personalWork);
//
//            asynchronousAddEs(Constants.REDIS_EVENT+id,personalWork);
//            List<Object> list=redisTemplate.opsForList().range(Constants.REDIS_EVENT+id,0,-1);
//            assert list != null;
//            pushData(id,JacksonUtil.toJSon(statisticalRoleCount(list)));
//            subWork(list,work,id);
//            log.info("{}这里发送{}",id, JacksonUtil.toJSon(statisticalRoleCount(list)));
//        }
//    }
//
//    @Override
//    public void saveWork(String executorId, String latestNews, Work work) {
//        Long time=new Date().getTime();
//        String releaseName= iUserService.findUserById(work.getPublisher()).getUsername();
//        String executorName= iUserService.findUserById(work.getExecutor()).getUsername();
//        RedisPersonalWork personalWork=new RedisPersonalWork(work.getId(),time,work.getTitle(),work.getStatus(),releaseName,executorName,1,WorkAttribution.ME_WORK,latestNews,work.getSuperiorId(),new ArrayList<>(),0);
//        //发布人
//        if (work.getSuperiorId()==null){
//            personalWork.setWorkAttribution(WorkAttribution.ME_RELEASE_WORK);
//            personalWork.setReadState(0);
//            redisTemplate.opsForList().leftPush(Constants.REDIS_EVENT+work.getPublisher(),personalWork);
//
//            asynchronousAddEs(Constants.REDIS_EVENT+work.getPublisher(),personalWork);
//            List<Object> list=redisTemplate.opsForList().range(Constants.REDIS_EVENT+work.getPublisher(),0,-1);
//            assert list != null;
//            pushData(work.getPublisher(),JacksonUtil.toJSon(statisticalRoleCount(list)));
//            log.info("{}这里发送{}",work.getPublisher(), JacksonUtil.toJSon(statisticalRoleCount(list)));
//
//        }else {
//            personalWork.setWorkAttribution(WorkAttribution.ME_RESOLVE_WORK);
//            personalWork.setReadState(0);
//            redisTemplate.opsForList().leftPush(Constants.REDIS_EVENT+work.getPublisher(),personalWork);
//
//            asynchronousAddEs(Constants.REDIS_EVENT+work.getPublisher(),personalWork);
//            List<Object> list=redisTemplate.opsForList().range(Constants.REDIS_EVENT+work.getPublisher(),0,-1);
//            assert list != null;
//            pushData(work.getPublisher(),JacksonUtil.toJSon(statisticalRoleCount(list)));
//            subWork(list,work,work.getPublisher());
//            log.info("{}这里发送{}",work.getPublisher(), JacksonUtil.toJSon(statisticalRoleCount(list)));
//        }
//    }
//
//    @Override
//    public void unpublishedToOngoing(String executorId, String latestNews, List<String> userIds, Work work) {
//
//        Long time=new Date().getTime();
//        String releaseName= iUserService.findUserById(work.getPublisher()).getUsername();
//        String executorName= iUserService.findUserById(work.getExecutor()).getUsername();
//        RedisPersonalWork personalWork=new RedisPersonalWork(work.getId(),time,work.getTitle(),work.getStatus(),releaseName,executorName,1,WorkAttribution.ME_WORK,latestNews,work.getSuperiorId(),new ArrayList<>(),0);
//        //发布人
//
//            List<Object> objects = redisTemplate.opsForList().range(Constants.REDIS_EVENT + work.getPublisher(), 0, -1);
//            for (Object object:objects){
//                RedisPersonalWork redisPersonalWork=(RedisPersonalWork) object;
//                if (work.getId().equals(redisPersonalWork.getWorkId())){
//                    redisTemplate.opsForList().remove(Constants.REDIS_EVENT+work.getPublisher(),1,redisPersonalWork);
//                    redisPersonalWork.setStatus(work.getStatus());
//                    redisPersonalWork.setTime(time);
//                    redisPersonalWork.setLatestNews(latestNews);
//                    redisTemplate.opsForList().leftPush(Constants.REDIS_EVENT+work.getPublisher(),redisPersonalWork);
//                    asynchronousAddEs(Constants.REDIS_EVENT+work.getPublisher(),personalWork);
//                }
//            }
//        pushData(work.getPublisher(),JacksonUtil.toJSon(statisticalRoleCount(objects)));
//        subWork(objects,work,work.getPublisher());
//        log.info("{}这里发送{}",work.getPublisher(), JacksonUtil.toJSon(statisticalRoleCount(objects)));
//        boolean flag=true;
//        if (flag){
//            personalWork.setWorkAttribution(WorkAttribution.ME_RECEIVE_WORK);
//            personalWork.setReadState(1);
//            redisTemplate.opsForList().leftPush(Constants.REDIS_EVENT+work.getExecutor(),personalWork);
//
//            asynchronousAddEs(Constants.REDIS_EVENT+work.getExecutor(),personalWork);
//            List<Object> list=redisTemplate.opsForList().range(Constants.REDIS_EVENT+work.getExecutor(),0,-1);
//            assert list != null;
//            pushData(work.getExecutor(),JacksonUtil.toJSon(statisticalRoleCount(list)));
//            subWork(list,work,work.getExecutor());
//            log.info("{}这里发送{}",work.getExecutor(), JacksonUtil.toJSon(statisticalRoleCount(list)));
//        }else {
//            personalWork.setWorkAttribution(WorkAttribution.ME_WORK);
//            personalWork.setReadState(1);
//            redisTemplate.opsForList().leftPush(Constants.REDIS_EVENT+work.getExecutor(),personalWork);
//
//            asynchronousAddEs(Constants.REDIS_EVENT+work.getExecutor(),personalWork);
//            List<Object> list=redisTemplate.opsForList().range(Constants.REDIS_EVENT+work.getExecutor(),0,-1);
//            assert list != null;
//            pushData(work.getExecutor(),JacksonUtil.toJSon(statisticalRoleCount(list)));
//            subWork(list,work,work.getExecutor());
//            log.info("{}这里发送{}",work.getExecutor(), JacksonUtil.toJSon(statisticalRoleCount(list)));
//        }
//        //有待修改
//        for (String id:userIds){
//            personalWork.setWorkAttribution(WorkAttribution.ME_RELEASE_WORK);
//            personalWork.setReadState(1);
//            redisTemplate.opsForList().leftPush(Constants.REDIS_EVENT+id,personalWork);
//
//            asynchronousAddEs(Constants.REDIS_EVENT+id,personalWork);
//            List<Object> list=redisTemplate.opsForList().range(Constants.REDIS_EVENT+id,0,-1);
//            assert list != null;
//            pushData(id,JacksonUtil.toJSon(statisticalRoleCount(list)));
//            subWork(list,work,id);
//            log.info("{}这里发送{}",id, JacksonUtil.toJSon(statisticalRoleCount(list)));
//        }
//    }
//
//    @Override
//    public void updateWorkStatus(String executorId, String latestNews, List<String> userIds, String status,String workId) {
//        upDateRedisWorkStatus(executorId,workId,status,latestNews,0);
//
//        for (String id:userIds){
//            upDateRedisWorkStatus(id,workId,status,latestNews,1);
//        }
//    }
//
//    @Override
//    public void upDateWork(String executorId, String latestNews, List<String> userIds,String workId) {
//        upDateRedisWork(executorId,workId,latestNews,0);
//
//        for (String id:userIds){
//            upDateRedisWork(id,workId,latestNews,1);
//        }
//    }
//
//    private void upDateRedisWorkStatus(String uId,String workId,String status,String latestNews ,int read){
//        List<Object> list=redisTemplate.opsForList().range(Constants.REDIS_EVENT+uId,0,-1);
//        for (Object object:list){
//            RedisPersonalWork redisPersonalWork=(RedisPersonalWork)object;
//            if (redisPersonalWork.getWorkId().equals(workId)){
//                redisTemplate.opsForList().remove(Constants.REDIS_EVENT+uId,1,redisPersonalWork);
//                redisPersonalWork.setStatus(status);
//                redisPersonalWork.setReadState(read);
//                redisPersonalWork.setLatestNews(latestNews);
//                redisTemplate.opsForList().leftPush(Constants.REDIS_EVENT+uId,redisPersonalWork);
//                asynchronousAddEs(Constants.REDIS_EVENT+uId,redisPersonalWork);
//            }
//        }
//        pushData(uId,JacksonUtil.toJSon(statisticalRoleCount(list)));
//    }
//
//    private void upDateRedisWork(String uId,String workId,String latestNews ,int read){
//        List<Object> list=redisTemplate.opsForList().range(Constants.REDIS_EVENT+uId,0,-1);
//        for (Object object:list){
//            RedisPersonalWork redisPersonalWork=(RedisPersonalWork)object;
//            if (redisPersonalWork.getWorkId().equals(workId)){
//                redisTemplate.opsForList().remove(Constants.REDIS_EVENT+uId,1,redisPersonalWork);
//                redisPersonalWork.setReadState(read);
//                redisPersonalWork.setLatestNews(latestNews);
//                redisTemplate.opsForList().leftPush(Constants.REDIS_EVENT+uId,redisPersonalWork);
//                asynchronousAddEs(Constants.REDIS_EVENT+uId,redisPersonalWork);
//            }
//        }
//        pushData(uId,JacksonUtil.toJSon(statisticalRoleCount(list)));
//    }
//
//
//    private void subWork(List<Object> list,Work work,String userId){
//        for (Object object:list){
//            RedisPersonalWork personalWork=(RedisPersonalWork)object;
//            if (personalWork.getWorkId().equals(work.getSuperiorId())){
//                redisTemplate.opsForList().remove(Constants.REDIS_EVENT+userId,1,personalWork);
//                List<String> list1=personalWork.getSubtaskIds();
//                list1.add(work.getId());
//                personalWork.setSubtaskIds(list1);
//                asynchronousAddEs(Constants.REDIS_EVENT + userId, personalWork);
//                redisTemplate.opsForList().leftPush(Constants.REDIS_EVENT+userId,personalWork);
//            }
//        }
//        pushData(userId,JacksonUtil.toJSon(statisticalRoleCount(list)));
//    }
//
//    @Override
//    public void readsStatus(String id, String eventId, int readState) {
//        List<Object> list = redisTemplate.opsForList().range(Constants.REDIS_EVENT + id, 0, -1);
//        if (readState == 1) {
//            assert list != null;
//            for (Object object : list) {
//                RedisPersonalWork personalWork = (RedisPersonalWork) object;
//                if (personalWork.getWorkId().equals(eventId)) {
//                    redisTemplate.opsForList().remove(Constants.REDIS_EVENT + id, 1, personalWork);
//                    personalWork.setReadState(0);
//                    redisTemplate.opsForList().leftPush(Constants.REDIS_EVENT + id, personalWork);
//                    asynchronousAddEs(Constants.REDIS_EVENT + id, personalWork);
//                }
//            }
//            pushData(id, JacksonUtil.toJSon(statisticalRoleCount(list)));
//            log.info("{}这里发送{}", id, JacksonUtil.toJSon(statisticalRoleCount(list)));
//        }
//    }
//
//    //对象转es
//    private EsSource eventToEs(RedisPersonalWork personalWork) {
//        EsSource esSource = new EsSource();
//        Map<String, Object> objectMap = new HashMap<>(20);
//        objectMap.put("workId", personalWork.getWorkId());
//        objectMap.put("title", personalWork.getTitle());
//        objectMap.put("status", personalWork.getStatus());
//        objectMap.put("release", personalWork.getRelease());
//        objectMap.put("executor", personalWork.getExecutor());
//        objectMap.put("readState", personalWork.getReadState());
//        objectMap.put("workAttribution", personalWork.getWorkAttribution());
//        objectMap.put("latestNews", personalWork.getLatestNews());
//        objectMap.put("superiorId", personalWork.getSuperiorId());
//        objectMap.put("time", personalWork.getTime());
//        objectMap.put("subtaskIds", personalWork.getSubtaskIds());
//        esSource.setJsonMap(objectMap);
//        return esSource;
//    }
//
//   // 添加es
//    private void asynchronousAddEs(String index,RedisPersonalWork personalWork){
//        CompletableFuture.runAsync(() -> {
//            esUtil.save(index, eventToEs(personalWork));
//            log.info("异步写入es完成");
//        });
//
//    }
//
//
//    private RoleSum statisticalRoleCount(List<Object> list){
//        int role1=0,role2=0,role3=0,role4=0;
//        int unread1=0,unread2=0,unread3=0,unread4=0;
//        for (Object object:list){
//            RedisPersonalWork redisPersonalWork=(RedisPersonalWork)object;
//            switch(redisPersonalWork.getWorkAttribution()){
//                case WorkAttribution.ME_WORK :
//                    role1++;
//                    if (redisPersonalWork.getReadState()==1){
//                        unread1=1;
//                    }
//                    break;
//                case WorkAttribution.ME_RECEIVE_WORK :
//                    int size=0;
//                    if (redisPersonalWork.getSubtaskIds()!=null){
//                        size=redisPersonalWork.getSubtaskIds().size();
//                    }
//                    role2=role2-size;
//                    role2++;
//                    if (redisPersonalWork.getReadState()==1){
//                        unread2=1;
//                    }
//                    break;
//                case WorkAttribution.ME_RESOLVE_WORK :
//                    role3++;
//                    if (redisPersonalWork.getReadState()==1){
//                        unread3=1;
//                    }
//                    break;
//                case WorkAttribution.ME_RELEASE_WORK :
//                    if (redisPersonalWork.getSuperiorId()==null) {
//                        role4++;
//                    }
//                    if (redisPersonalWork.getReadState()==1){
//                        unread4=1;
//                    }
//                    break;
//            }
//        }
//        return new RoleSum(unread1,role1,unread2,role2,unread3,role3,unread4,role4);
//
//    }
//
//    @Override
//    public void loginFirstOneManualPush(String id) {
//        log.info("redis :{}",Constants.REDIS_EVENT);
//        List<Object> list= redisTemplate.opsForList().range(Constants.REDIS_EVENT+id,0,-1);
//        assert list != null;
//        RoleSum roleSum= statisticalRoleCount(list);
//        String receive=iUserService.findUserById(id).getUsername();
//        log.info("{}调用了id查询的接口",receive);
//        if (receive!=null) {
//            messageTemplateService.beingPushed(receive, "/topic/note", JacksonUtil.toJSon(roleSum));
//        }else {
//            log.info("{}数据库查询不到，请尝试",id);
//        }
//    }
//
//
//    private void pushData(String id,String payload){
//        log.info("[Status,pushData] 传入的id值为：{} ", id);
//        String receive=  iUserService.findUserById(id).getUsername();
//        if (receive!=null) {
//            messageTemplateService.beingPushed(receive, "/topic/note", payload);
//
//        }else {
//            log.info("{}数据库查询不到，请检查",id);
//        }
//    }
//}
