package com.platform.service.impl; import cn.hutool.core.collection.CollUtil; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.platform.mapper.CaseMapper; import com.platform.model.dto.CaseDTO; import com.platform.model.dto.CaseDTO; import com.platform.model.dto.ExcelDataDTO; import com.platform.model.entity.CaseEntity; import com.platform.model.vo.CaseVO; import com.platform.model.entity.ExcelDataEntity; import com.platform.model.vo.CaseVO; import com.platform.model.vo.ExcelDataVO; import com.platform.service.CaseService; import com.platform.service.ExcelDataService; import com.platform.utils.StringUtils; import org.apache.commons.compress.utils.Lists; import org.springframework.stereotype.Service; import java.util.List; import javax.annotation.Resource; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @Service public class CaseServiceImpl extends ServiceImpl implements CaseService { @Resource private ExcelDataService excelDataService; @Override public List queryDataList(String id) { //查看案件所有的excelData List excelDataEntityList = excelDataService.queryByCaseId(id); excelDataEntityList.forEach(excelDataEntity -> { if (StringUtils.isNull(excelDataEntity.getPayUserName())) { excelDataEntity.setPayUserName("无对应人员的数据"); } }); // 调用分组方法 Map> groupedMap = groupByPayUserName(excelDataEntityList); //初始化集合 List caseVOList = Lists.newArrayList(); //遍历groupedMap for (Map.Entry> entry : groupedMap.entrySet()) { System.out.println("Key: " + entry.getKey() + ", Values: " + entry.getValue()); caseVOList.add(CaseVO.builder().excelDataList(entry.getValue()) .payUserName(entry.getKey()) .build()); } return caseVOList; } @Override public boolean updatePayUser(ExcelDataDTO excelDataDTO) { //查看fileId线管的excelData数据 List excelDataEntityList = excelDataService.queryListByFileId(excelDataDTO.getFileId(), excelDataDTO.getCaseId()); if (CollUtil.isNotEmpty(excelDataEntityList)) { excelDataEntityList.forEach(excelDataEntity -> excelDataEntity.setPayUserName(excelDataDTO.getPayUserName())); } return excelDataService.updateBatchById(excelDataEntityList); } @Override public boolean deleteExcel(String fileId) { return excelDataService.deleteByFileId(fileId); } @Override public boolean updateExcelUse(ExcelDataDTO excelDataDTO) { //查看数据 List excelDataEntityList = excelDataService.queryListByFileId(excelDataDTO.getFileId(), excelDataDTO.getCaseId()); if (CollUtil.isNotEmpty(excelDataEntityList)) { excelDataEntityList.forEach(excelDataEntity -> excelDataEntity.setUseFlag(excelDataDTO.getUseFlag())); } return excelDataService.updateBatchById(excelDataEntityList); } @Override public boolean mergeUser(ExcelDataDTO excelDataDTO) { //查看合并之前的人员数据 //初始化合并后的集合 List mergeList = Lists.newArrayList(); excelDataDTO.getOldPayUserName().forEach(payUserName -> { List excelDataEntityList = excelDataService.queryListByCaseIdAndPayUserName(excelDataDTO.getCaseId(), payUserName); if (CollUtil.isNotEmpty(excelDataEntityList)) { mergeList.addAll(excelDataEntityList); } }); if (CollUtil.isNotEmpty(mergeList)) { mergeList.forEach(excelDataEntity -> excelDataEntity.setPayUserName(excelDataDTO.getNewPayUserName())); excelDataService.updateBatchById(mergeList); } return Boolean.TRUE; } private Map> groupByPayUserName(List excelDataVOList) { Map> groupedMap = new HashMap<>(); for (ExcelDataVO obj : excelDataVOList) { String key = obj.getPayUserName(); // 获取A字段的值作为键 if (!groupedMap.containsKey(key)) { groupedMap.put(key, new ArrayList<>()); // 如果键不存在,创建一个新的List } groupedMap.get(key).add(obj); // 将对象添加到对应的List中 } return groupedMap; } @Override public List pageCase(CaseDTO caseDTO) { return baseMapper.pageCase(caseDTO); } }