package jnpf.flowable.service.impl; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.ObjectUtil; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import jnpf.base.service.SuperServiceImpl; import jnpf.flowable.entity.RevokeEntity; import jnpf.flowable.entity.TaskLineEntity; import jnpf.flowable.mapper.TaskLineMapper; import jnpf.flowable.service.RevokeService; import jnpf.flowable.service.TaskLineService; import jnpf.util.RandomUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.stream.Collectors; /** * 类的描述 * * @author JNPF@YinMai Info. Co., Ltd * @version 5.0.x * @since 2024/8/23 17:37 */ @Service public class TaskLineServiceImpl extends SuperServiceImpl implements TaskLineService { @Autowired private RevokeService revokeService; @Override public List getList(String taskId) { QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.lambda().eq(TaskLineEntity::getTaskId, taskId); return this.list(queryWrapper); } @Override public void create(String taskId, Map conditionResMap) { if (CollectionUtil.isEmpty(conditionResMap)) { return; } List createList = new ArrayList<>(); List updateList = new ArrayList<>(); List list = this.getList(taskId); if (CollectionUtil.isNotEmpty(list)) { conditionResMap.forEach((k, v) -> { TaskLineEntity entity = list.stream().filter(e -> ObjectUtil.equals(k, e.getLineKey())).findFirst().orElse(null); if (null != entity) { Boolean b = conditionResMap.get(entity.getLineKey()); if (null != b) { entity.setLineValue(String.valueOf(b)); updateList.add(entity); } } else { entity = new TaskLineEntity(); entity.setId(RandomUtil.uuId()); entity.setTaskId(taskId); entity.setLineKey(k); entity.setLineValue(String.valueOf(v)); createList.add(entity); } }); } else { conditionResMap.forEach((k, v) -> { TaskLineEntity entity = new TaskLineEntity(); entity.setId(RandomUtil.uuId()); entity.setTaskId(taskId); entity.setLineKey(k); entity.setLineValue(String.valueOf(v)); createList.add(entity); }); } if (CollectionUtil.isNotEmpty(createList)) { this.saveBatch(createList); } if (CollectionUtil.isNotEmpty(updateList)) { this.updateBatchById(updateList); } } @Override public List getLineKeyList(String taskId) { List resList = new ArrayList<>(); RevokeEntity revokeEntity = revokeService.getRevokeTask(taskId); if (null != revokeEntity) { taskId = revokeEntity.getTaskId(); } List list = this.getList(taskId); Map> collect = list.stream().collect(Collectors.groupingBy(TaskLineEntity::getLineKey)); collect.forEach((k, v) -> { List sortList = v.stream().sorted(Comparator.comparing(TaskLineEntity::getCreatorTime).reversed()).collect(Collectors.toList()); boolean bo = Boolean.parseBoolean(sortList.get(0).getLineValue()); if (bo) { resList.add(k); } }); return resList; } }