refactor(用例管理): 导入处理调整
This commit is contained in:
parent
d0632d1660
commit
da92c8673f
|
@ -66,9 +66,9 @@ public class FunctionalCaseImportEventListener extends AnalysisEventListener<Map
|
||||||
private FunctionalCaseExcelData currentMergeData;
|
private FunctionalCaseExcelData currentMergeData;
|
||||||
private Integer firstMergeRowIndex;
|
private Integer firstMergeRowIndex;
|
||||||
/**
|
/**
|
||||||
* 每隔5000条存储数据库,然后清理list ,方便内存回收
|
* 每隔1000条存储数据库,然后清理list ,方便内存回收
|
||||||
*/
|
*/
|
||||||
protected static final int BATCH_COUNT = 5000;
|
protected static final int BATCH_COUNT = 1000;
|
||||||
protected List<FunctionalCaseExcelData> list = new ArrayList<>();
|
protected List<FunctionalCaseExcelData> list = new ArrayList<>();
|
||||||
protected List<ExcelErrData<FunctionalCaseExcelData>> errList = new ArrayList<>();
|
protected List<ExcelErrData<FunctionalCaseExcelData>> errList = new ArrayList<>();
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -105,12 +105,15 @@
|
||||||
<update id="batchUpdateAbandoned">
|
<update id="batchUpdateAbandoned">
|
||||||
update case_review_history
|
update case_review_history
|
||||||
set abandoned = true
|
set abandoned = true
|
||||||
where review_id = #{reviewId}
|
where abandoned = false
|
||||||
|
<if test="reviewId != null and reviewId != ''">
|
||||||
|
and review_id = #{reviewId}
|
||||||
|
</if>
|
||||||
and case_id in
|
and case_id in
|
||||||
<foreach collection="caseIds" item="caseId" separator="," open="(" close=")">
|
<foreach collection="caseIds" item="caseId" separator="," open="(" close=")">
|
||||||
#{caseId}
|
#{caseId}
|
||||||
</foreach>
|
</foreach>
|
||||||
and abandoned = false
|
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -335,10 +335,10 @@ public class CaseReviewFunctionalCaseService {
|
||||||
if (CollectionUtils.isNotEmpty(caseReviewFunctionalCases)) {
|
if (CollectionUtils.isNotEmpty(caseReviewFunctionalCases)) {
|
||||||
//重新提审,作废之前的记录
|
//重新提审,作废之前的记录
|
||||||
extCaseReviewHistoryMapper.updateAbandoned(blob.getId());
|
extCaseReviewHistoryMapper.updateAbandoned(blob.getId());
|
||||||
|
List<CaseReviewHistory> historyList = new ArrayList<>();
|
||||||
caseReviewFunctionalCases.forEach(item -> {
|
caseReviewFunctionalCases.forEach(item -> {
|
||||||
updateReviewCaseAndCaseStatus(item);
|
updateReviewCaseAndCaseStatus(item);
|
||||||
insertHistory(item);
|
insertHistory(item, historyList);
|
||||||
//更新用例触发重新提审-需要重新计算评审的整体状态
|
//更新用例触发重新提审-需要重新计算评审的整体状态
|
||||||
Map<String, Integer> countMap = new HashMap<>();
|
Map<String, Integer> countMap = new HashMap<>();
|
||||||
countMap.put(item.getStatus(), 1);
|
countMap.put(item.getStatus(), 1);
|
||||||
|
@ -354,10 +354,11 @@ public class CaseReviewFunctionalCaseService {
|
||||||
provider.updateCaseReview(param);
|
provider.updateCaseReview(param);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
caseReviewHistoryMapper.batchInsertSelective(historyList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void insertHistory(CaseReviewFunctionalCase item) {
|
private void insertHistory(CaseReviewFunctionalCase item, List<CaseReviewHistory> historyList) {
|
||||||
CaseReviewHistory caseReviewHistory = new CaseReviewHistory();
|
CaseReviewHistory caseReviewHistory = new CaseReviewHistory();
|
||||||
caseReviewHistory.setId(IDGenerator.nextStr());
|
caseReviewHistory.setId(IDGenerator.nextStr());
|
||||||
caseReviewHistory.setCaseId(item.getCaseId());
|
caseReviewHistory.setCaseId(item.getCaseId());
|
||||||
|
@ -366,7 +367,7 @@ public class CaseReviewFunctionalCaseService {
|
||||||
caseReviewHistory.setCreateUser(UserRoleScope.SYSTEM);
|
caseReviewHistory.setCreateUser(UserRoleScope.SYSTEM);
|
||||||
caseReviewHistory.setCreateTime(System.currentTimeMillis());
|
caseReviewHistory.setCreateTime(System.currentTimeMillis());
|
||||||
caseReviewHistory.setDeleted(false);
|
caseReviewHistory.setDeleted(false);
|
||||||
caseReviewHistoryMapper.insertSelective(caseReviewHistory);
|
historyList.add(caseReviewHistory);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateReviewCaseAndCaseStatus(CaseReviewFunctionalCase item) {
|
private void updateReviewCaseAndCaseStatus(CaseReviewFunctionalCase item) {
|
||||||
|
@ -522,7 +523,7 @@ public class CaseReviewFunctionalCaseService {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
//检查是否全部是通过,全是才是PASS,否则是评审中(如果时自动重新提审,会有个system用户,这里需要排出一下)
|
//检查是否全部是通过,全是才是PASS,否则是评审中(如果时自动重新提审,会有个system用户,这里需要排出一下)
|
||||||
if (hasReviewedUserMap.get(UserRoleScope.SYSTEM) !=null) {
|
if (hasReviewedUserMap.get(UserRoleScope.SYSTEM) != null) {
|
||||||
hasReviewedUserMap.remove(UserRoleScope.SYSTEM);
|
hasReviewedUserMap.remove(UserRoleScope.SYSTEM);
|
||||||
}
|
}
|
||||||
if (unPassCount.get() > 0) {
|
if (unPassCount.get() > 0) {
|
||||||
|
@ -806,13 +807,24 @@ public class CaseReviewFunctionalCaseService {
|
||||||
example.createCriteria().andCaseIdIn(caseIds);
|
example.createCriteria().andCaseIdIn(caseIds);
|
||||||
List<CaseReviewFunctionalCase> caseReviewFunctionalCases = caseReviewFunctionalCaseMapper.selectByExample(example);
|
List<CaseReviewFunctionalCase> caseReviewFunctionalCases = caseReviewFunctionalCaseMapper.selectByExample(example);
|
||||||
Map<String, List<CaseReviewFunctionalCase>> reviews = caseReviewFunctionalCases.stream().collect(Collectors.groupingBy(CaseReviewFunctionalCase::getReviewId));
|
Map<String, List<CaseReviewFunctionalCase>> reviews = caseReviewFunctionalCases.stream().collect(Collectors.groupingBy(CaseReviewFunctionalCase::getReviewId));
|
||||||
|
List<CaseReviewHistory> historyList = new ArrayList<>();
|
||||||
|
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
||||||
|
CaseReviewFunctionalCaseMapper caseReviewFunctionalCaseMapper = sqlSession.getMapper(CaseReviewFunctionalCaseMapper.class);
|
||||||
|
FunctionalCaseMapper functionalCaseMapper = sqlSession.getMapper(FunctionalCaseMapper.class);
|
||||||
reviews.forEach((k, v) -> {
|
reviews.forEach((k, v) -> {
|
||||||
Map<String, Integer> countMap = new HashMap<>();
|
Map<String, Integer> countMap = new HashMap<>();
|
||||||
Map<String, String> statusMap = new HashMap<>();
|
Map<String, String> statusMap = new HashMap<>();
|
||||||
v.forEach(c -> {
|
v.forEach(c -> {
|
||||||
extCaseReviewHistoryMapper.updateAbandoned(c.getCaseId());
|
c.setStatus(FunctionalCaseReviewStatus.RE_REVIEWED.name());
|
||||||
updateReviewCaseAndCaseStatus(c);
|
c.setUpdateTime(System.currentTimeMillis());
|
||||||
insertHistory(c);
|
caseReviewFunctionalCaseMapper.updateByPrimaryKeySelective(c);
|
||||||
|
|
||||||
|
FunctionalCase functionalCase = new FunctionalCase();
|
||||||
|
functionalCase.setId(c.getCaseId());
|
||||||
|
functionalCase.setReviewStatus(FunctionalCaseReviewStatus.RE_REVIEWED.name());
|
||||||
|
functionalCaseMapper.updateByPrimaryKeySelective(functionalCase);
|
||||||
|
|
||||||
|
insertHistory(c, historyList);
|
||||||
statusMap.put(c.getCaseId(), c.getStatus());
|
statusMap.put(c.getCaseId(), c.getStatus());
|
||||||
});
|
});
|
||||||
//更新用例触发重新提审-需要重新计算评审的整体状态
|
//更新用例触发重新提审-需要重新计算评审的整体状态
|
||||||
|
@ -826,5 +838,10 @@ public class CaseReviewFunctionalCaseService {
|
||||||
param.put(CaseEvent.Param.EVENT_NAME, CaseEvent.Event.REVIEW_FUNCTIONAL_CASE);
|
param.put(CaseEvent.Param.EVENT_NAME, CaseEvent.Event.REVIEW_FUNCTIONAL_CASE);
|
||||||
provider.updateCaseReview(param);
|
provider.updateCaseReview(param);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
sqlSession.flushStatements();
|
||||||
|
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
|
||||||
|
extCaseReviewHistoryMapper.batchUpdateAbandoned(null, caseIds);
|
||||||
|
caseReviewHistoryMapper.batchInsertSelective(historyList);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -46,11 +46,7 @@ import io.metersphere.system.log.service.OperationLogService;
|
||||||
import io.metersphere.system.mapper.OperationHistoryMapper;
|
import io.metersphere.system.mapper.OperationHistoryMapper;
|
||||||
import io.metersphere.system.mapper.UserMapper;
|
import io.metersphere.system.mapper.UserMapper;
|
||||||
import io.metersphere.system.notice.constants.NoticeConstants;
|
import io.metersphere.system.notice.constants.NoticeConstants;
|
||||||
import io.metersphere.system.service.CommonNoticeSendService;
|
import io.metersphere.system.service.*;
|
||||||
import io.metersphere.system.service.BaseCustomFieldOptionService;
|
|
||||||
import io.metersphere.system.service.BaseCustomFieldService;
|
|
||||||
import io.metersphere.system.service.OperationHistoryService;
|
|
||||||
import io.metersphere.system.service.UserLoginService;
|
|
||||||
import io.metersphere.system.uid.IDGenerator;
|
import io.metersphere.system.uid.IDGenerator;
|
||||||
import io.metersphere.system.uid.NumGenerator;
|
import io.metersphere.system.uid.NumGenerator;
|
||||||
import io.metersphere.system.utils.ServiceUtils;
|
import io.metersphere.system.utils.ServiceUtils;
|
||||||
|
@ -199,8 +195,8 @@ public class FunctionalCaseService {
|
||||||
addCaseReviewCase(request.getReviewId(), caseId, userId);
|
addCaseReviewCase(request.getReviewId(), caseId, userId);
|
||||||
|
|
||||||
//记录日志
|
//记录日志
|
||||||
FunctionalCaseHistoryLogDTO historyLogDTO = getImportLogModule(functionalCase);
|
FunctionalCaseHistoryLogDTO historyLogDTO = getAddLogModule(functionalCase);
|
||||||
saveImportDataLog(functionalCase, new FunctionalCaseHistoryLogDTO(), historyLogDTO, userId, organizationId, OperationLogType.ADD.name(), OperationLogModule.FUNCTIONAL_CASE);
|
saveAddDataLog(functionalCase, new FunctionalCaseHistoryLogDTO(), historyLogDTO, userId, organizationId, OperationLogType.ADD.name(), OperationLogModule.FUNCTIONAL_CASE);
|
||||||
|
|
||||||
return functionalCase;
|
return functionalCase;
|
||||||
}
|
}
|
||||||
|
@ -677,9 +673,9 @@ public class FunctionalCaseService {
|
||||||
return handleCustomFields(functionalCaseLists, request.getProjectId());
|
return handleCustomFields(functionalCaseLists, request.getProjectId());
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<FunctionalCasePageDTO> handleCustomFields(List<FunctionalCasePageDTO> functionalCaseLists,String projectId) {
|
private List<FunctionalCasePageDTO> handleCustomFields(List<FunctionalCasePageDTO> functionalCaseLists, String projectId) {
|
||||||
List<String> ids = functionalCaseLists.stream().map(FunctionalCasePageDTO::getId).collect(Collectors.toList());
|
List<String> ids = functionalCaseLists.stream().map(FunctionalCasePageDTO::getId).collect(Collectors.toList());
|
||||||
Map<String, List<FunctionalCaseCustomFieldDTO>> collect = getCaseCustomFiledMap(ids,projectId);
|
Map<String, List<FunctionalCaseCustomFieldDTO>> collect = getCaseCustomFiledMap(ids, projectId);
|
||||||
Set<String> userIds = extractUserIds(functionalCaseLists);
|
Set<String> userIds = extractUserIds(functionalCaseLists);
|
||||||
Map<String, String> userMap = userLoginService.getUserNameMap(new ArrayList<>(userIds));
|
Map<String, String> userMap = userLoginService.getUserNameMap(new ArrayList<>(userIds));
|
||||||
functionalCaseLists.forEach(functionalCasePageDTO -> {
|
functionalCaseLists.forEach(functionalCasePageDTO -> {
|
||||||
|
@ -698,7 +694,7 @@ public class FunctionalCaseService {
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, List<FunctionalCaseCustomFieldDTO>> getCaseCustomFiledMap(List<String> ids,String projectId) {
|
public Map<String, List<FunctionalCaseCustomFieldDTO>> getCaseCustomFiledMap(List<String> ids, String projectId) {
|
||||||
List<CustomFieldOption> memberCustomOption = getMemberOptions(projectId);
|
List<CustomFieldOption> memberCustomOption = getMemberOptions(projectId);
|
||||||
List<FunctionalCaseCustomFieldDTO> customFields = functionalCaseCustomFieldService.getCustomFieldsByCaseIds(ids);
|
List<FunctionalCaseCustomFieldDTO> customFields = functionalCaseCustomFieldService.getCustomFieldsByCaseIds(ids);
|
||||||
customFields.forEach(customField -> {
|
customFields.forEach(customField -> {
|
||||||
|
@ -834,7 +830,7 @@ public class FunctionalCaseService {
|
||||||
historyLogDTO.setCustomFields(customFields);
|
historyLogDTO.setCustomFields(customFields);
|
||||||
historyLogDTO.setCaseAttachments(caseAttachments);
|
historyLogDTO.setCaseAttachments(caseAttachments);
|
||||||
historyLogDTO.setFileAssociationList(fileAssociationList);
|
historyLogDTO.setFileAssociationList(fileAssociationList);
|
||||||
saveImportDataLog(functionalCase, new FunctionalCaseHistoryLogDTO(), historyLogDTO, userId, organizationId, OperationLogType.ADD.name(), OperationLogModule.FUNCTIONAL_CASE);
|
saveAddDataLog(functionalCase, new FunctionalCaseHistoryLogDTO(), historyLogDTO, userId, organizationId, OperationLogType.ADD.name(), OperationLogModule.FUNCTIONAL_CASE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1006,20 +1002,57 @@ public class FunctionalCaseService {
|
||||||
FunctionalCaseCustomFieldMapper customFieldMapper = sqlSession.getMapper(FunctionalCaseCustomFieldMapper.class);
|
FunctionalCaseCustomFieldMapper customFieldMapper = sqlSession.getMapper(FunctionalCaseCustomFieldMapper.class);
|
||||||
Long nextOrder = getNextOrder(request.getProjectId());
|
Long nextOrder = getNextOrder(request.getProjectId());
|
||||||
List<FunctionalCaseDTO> noticeList = new ArrayList<>();
|
List<FunctionalCaseDTO> noticeList = new ArrayList<>();
|
||||||
|
List<FunctionalCaseHistoryLogDTO> historyLogDTOS = new ArrayList<>();
|
||||||
|
List<LogDTO> logDTOS = new ArrayList<>();
|
||||||
|
List<String> caseIds = new ArrayList<>();
|
||||||
for (int i = list.size() - 1; i > -1; i--) {
|
for (int i = list.size() - 1; i > -1; i--) {
|
||||||
parseInsertDataToModule(list.get(i), request, user.getId(), caseModulePathMap, defaultTemplateDTO, nextOrder, caseMapper, caseBlobMapper, customFieldMapper, customFieldsMap, user.getLastOrganizationId());
|
parseInsertDataToModule(list.get(i), request, user.getId(), caseModulePathMap, defaultTemplateDTO, nextOrder, caseMapper, caseBlobMapper, customFieldMapper, customFieldsMap, caseIds, historyLogDTOS);
|
||||||
nextOrder += ServiceUtils.POS_STEP;
|
nextOrder += ServiceUtils.POS_STEP;
|
||||||
//通知
|
//通知
|
||||||
noticeModule(noticeList, list.get(i), request, user.getId(), customFieldsMap);
|
noticeModule(noticeList, list.get(i), request, user.getId(), customFieldsMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlSession.flushStatements();
|
sqlSession.flushStatements();
|
||||||
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
|
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
|
||||||
|
|
||||||
|
//新增用例记录日志
|
||||||
|
historyLogDTOS.forEach(historyLogDTO -> {
|
||||||
|
batchSaveImportData(historyLogDTO, new FunctionalCaseHistoryLogDTO(), user, OperationLogType.IMPORT.name(), OperationLogModule.FUNCTIONAL_CASE, logDTOS);
|
||||||
|
});
|
||||||
|
operationLogService.batchAdd(logDTOS);
|
||||||
|
|
||||||
List<Map> resources = new ArrayList<>();
|
List<Map> resources = new ArrayList<>();
|
||||||
resources.addAll(JSON.parseArray(JSON.toJSONString(noticeList), Map.class));
|
resources.addAll(JSON.parseArray(JSON.toJSONString(noticeList), Map.class));
|
||||||
commonNoticeSendService.sendNotice(NoticeConstants.TaskType.FUNCTIONAL_CASE_TASK, NoticeConstants.Event.CREATE, resources, user, request.getProjectId());
|
commonNoticeSendService.sendNotice(NoticeConstants.TaskType.FUNCTIONAL_CASE_TASK, NoticeConstants.Event.CREATE, resources, user, request.getProjectId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导入数据日志 批量
|
||||||
|
*
|
||||||
|
* @param historyLogDTO
|
||||||
|
* @param functionalCaseHistoryLogDTO
|
||||||
|
* @param user
|
||||||
|
* @param type
|
||||||
|
* @param module
|
||||||
|
* @param logDTOS
|
||||||
|
*/
|
||||||
|
private void batchSaveImportData(FunctionalCaseHistoryLogDTO historyLogDTO, FunctionalCaseHistoryLogDTO functionalCaseHistoryLogDTO, SessionUser user, String type, String module, List<LogDTO> logDTOS) {
|
||||||
|
LogDTO dto = new LogDTO(
|
||||||
|
historyLogDTO.getFunctionalCase().getProjectId(),
|
||||||
|
user.getLastOrganizationId(),
|
||||||
|
historyLogDTO.getFunctionalCase().getId(),
|
||||||
|
user.getId(),
|
||||||
|
type,
|
||||||
|
module,
|
||||||
|
historyLogDTO.getFunctionalCase().getName());
|
||||||
|
dto.setHistory(true);
|
||||||
|
dto.setPath("/functional/case/import/excel");
|
||||||
|
dto.setMethod(HttpMethodConstants.POST.name());
|
||||||
|
dto.setModifiedValue(JSON.toJSONBytes(historyLogDTO));
|
||||||
|
dto.setOriginalValue(JSON.toJSONBytes(functionalCaseHistoryLogDTO));
|
||||||
|
logDTOS.add(dto);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 组装通知数据
|
* 组装通知数据
|
||||||
*
|
*
|
||||||
|
@ -1050,7 +1083,7 @@ public class FunctionalCaseService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseInsertDataToModule(FunctionalCaseExcelData functionalCaseExcelData, FunctionalCaseImportRequest request, String userId, Map<String, String> caseModulePathMap, TemplateDTO defaultTemplateDTO, Long nextOrder,
|
private void parseInsertDataToModule(FunctionalCaseExcelData functionalCaseExcelData, FunctionalCaseImportRequest request, String userId, Map<String, String> caseModulePathMap, TemplateDTO defaultTemplateDTO, Long nextOrder,
|
||||||
FunctionalCaseMapper caseMapper, FunctionalCaseBlobMapper caseBlobMapper, FunctionalCaseCustomFieldMapper customFieldMapper, Map<String, TemplateCustomFieldDTO> customFieldsMap, String organizationId) {
|
FunctionalCaseMapper caseMapper, FunctionalCaseBlobMapper caseBlobMapper, FunctionalCaseCustomFieldMapper customFieldMapper, Map<String, TemplateCustomFieldDTO> customFieldsMap, List<String> caseIds, List<FunctionalCaseHistoryLogDTO> historyLogDTOS) {
|
||||||
//构建用例
|
//构建用例
|
||||||
FunctionalCase functionalCase = new FunctionalCase();
|
FunctionalCase functionalCase = new FunctionalCase();
|
||||||
String caseId = IDGenerator.nextStr();
|
String caseId = IDGenerator.nextStr();
|
||||||
|
@ -1084,15 +1117,11 @@ public class FunctionalCaseService {
|
||||||
caseBlobMapper.insertSelective(caseBlob);
|
caseBlobMapper.insertSelective(caseBlob);
|
||||||
|
|
||||||
//自定义字段
|
//自定义字段
|
||||||
handleImportCustomField(functionalCaseExcelData, caseId, customFieldMapper, customFieldsMap);
|
List<FunctionalCaseCustomField> customFields = handleImportCustomField(functionalCaseExcelData, caseId, customFieldMapper, customFieldsMap);
|
||||||
|
|
||||||
//新增用例记录日志
|
caseIds.add(functionalCase.getId());
|
||||||
FunctionalCaseCustomFieldExample fieldExample = new FunctionalCaseCustomFieldExample();
|
historyLogDTOS.add(new FunctionalCaseHistoryLogDTO(functionalCase, caseBlob, customFields, new ArrayList<>(), new ArrayList<>()));
|
||||||
fieldExample.createCriteria().andCaseIdEqualTo(functionalCase.getId());
|
|
||||||
List<FunctionalCaseCustomField> customFields = functionalCaseCustomFieldMapper.selectByExample(fieldExample);
|
|
||||||
FunctionalCaseHistoryLogDTO historyLogDTO = new FunctionalCaseHistoryLogDTO(functionalCase, caseBlob, customFields, new ArrayList<>(), new ArrayList<>());
|
|
||||||
|
|
||||||
saveImportDataLog(functionalCase, new FunctionalCaseHistoryLogDTO(), historyLogDTO, userId, organizationId, OperationLogType.IMPORT.name(), OperationLogModule.FUNCTIONAL_CASE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1116,7 +1145,8 @@ public class FunctionalCaseService {
|
||||||
* @param customFieldMapper 自定义字段mapper
|
* @param customFieldMapper 自定义字段mapper
|
||||||
* @param customFieldsMap 当前默认模板的自定义字段
|
* @param customFieldsMap 当前默认模板的自定义字段
|
||||||
*/
|
*/
|
||||||
private void handleImportCustomField(FunctionalCaseExcelData functionalCaseExcelData, String caseId, FunctionalCaseCustomFieldMapper customFieldMapper, Map<String, TemplateCustomFieldDTO> customFieldsMap) {
|
private List<FunctionalCaseCustomField> handleImportCustomField(FunctionalCaseExcelData functionalCaseExcelData, String caseId, FunctionalCaseCustomFieldMapper customFieldMapper, Map<String, TemplateCustomFieldDTO> customFieldsMap) {
|
||||||
|
List<FunctionalCaseCustomField> customFields = new ArrayList<>();
|
||||||
//需要保存的自定义字段
|
//需要保存的自定义字段
|
||||||
Map<String, Object> customData = functionalCaseExcelData.getCustomData();
|
Map<String, Object> customData = functionalCaseExcelData.getCustomData();
|
||||||
customFieldsMap.forEach((k, v) -> {
|
customFieldsMap.forEach((k, v) -> {
|
||||||
|
@ -1129,8 +1159,10 @@ public class FunctionalCaseService {
|
||||||
}, () -> {
|
}, () -> {
|
||||||
setCustomFieldValue(v.getDefaultValue(), caseCustomField);
|
setCustomFieldValue(v.getDefaultValue(), caseCustomField);
|
||||||
});
|
});
|
||||||
|
customFields.add(caseCustomField);
|
||||||
customFieldMapper.insertSelective(caseCustomField);
|
customFieldMapper.insertSelective(caseCustomField);
|
||||||
});
|
});
|
||||||
|
return customFields;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setCustomFieldValue(Object value, FunctionalCaseCustomField caseCustomField) {
|
private void setCustomFieldValue(Object value, FunctionalCaseCustomField caseCustomField) {
|
||||||
|
@ -1160,18 +1192,35 @@ public class FunctionalCaseService {
|
||||||
List<String> modulePath = updateList.stream().map(FunctionalCaseExcelData::getModule).toList();
|
List<String> modulePath = updateList.stream().map(FunctionalCaseExcelData::getModule).toList();
|
||||||
//构建模块树
|
//构建模块树
|
||||||
Map<String, String> caseModulePathMap = functionalCaseModuleService.createCaseModule(modulePath, request.getProjectId(), moduleTree, user.getId(), pathMap);
|
Map<String, String> caseModulePathMap = functionalCaseModuleService.createCaseModule(modulePath, request.getProjectId(), moduleTree, user.getId(), pathMap);
|
||||||
|
|
||||||
|
//获取重新提审标识
|
||||||
|
ProjectApplicationExample example = new ProjectApplicationExample();
|
||||||
|
example.createCriteria().andProjectIdEqualTo(request.getProjectId()).andTypeEqualTo(ProjectApplicationType.CASE.CASE_RE_REVIEW.name());
|
||||||
|
List<ProjectApplication> projectApplications = projectApplicationMapper.selectByExample(example);
|
||||||
|
|
||||||
|
List<String> ids = updateList.stream().map(FunctionalCaseExcelData::getNum).toList();
|
||||||
|
List<FunctionalCase> caseList = getCaseDataByIds(ids);
|
||||||
|
Map<String, List<FunctionalCase>> collect = caseList.stream().collect(Collectors.groupingBy(FunctionalCase::getId));
|
||||||
|
List<FunctionalCaseBlob> blobs = getBlobDataByIds(ids);
|
||||||
|
Map<String, List<FunctionalCaseBlob>> blobsCollect = blobs.stream().collect(Collectors.groupingBy(FunctionalCaseBlob::getId));
|
||||||
|
Map<String, List<FunctionalCaseCustomField>> customFieldMap = functionalCaseCustomFieldService.getCustomFieldMapByCaseIds(ids);
|
||||||
|
|
||||||
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
||||||
FunctionalCaseMapper caseMapper = sqlSession.getMapper(FunctionalCaseMapper.class);
|
FunctionalCaseMapper caseMapper = sqlSession.getMapper(FunctionalCaseMapper.class);
|
||||||
FunctionalCaseBlobMapper caseBlobMapper = sqlSession.getMapper(FunctionalCaseBlobMapper.class);
|
FunctionalCaseBlobMapper caseBlobMapper = sqlSession.getMapper(FunctionalCaseBlobMapper.class);
|
||||||
FunctionalCaseCustomFieldMapper customFieldMapper = sqlSession.getMapper(FunctionalCaseCustomFieldMapper.class);
|
FunctionalCaseCustomFieldMapper customFieldMapper = sqlSession.getMapper(FunctionalCaseCustomFieldMapper.class);
|
||||||
List<FunctionalCaseDTO> noticeList = new ArrayList<>();
|
List<FunctionalCaseDTO> noticeList = new ArrayList<>();
|
||||||
List<String> caseIds = new ArrayList<>();
|
List<String> caseIds = new ArrayList<>();
|
||||||
|
List<FunctionalCaseHistoryLogDTO> historyLogDTOS = new ArrayList<>();
|
||||||
|
List<LogDTO> logDTOS = new ArrayList<>();
|
||||||
|
|
||||||
for (int i = 0; i < updateList.size(); i++) {
|
for (int i = 0; i < updateList.size(); i++) {
|
||||||
parseUpdateDataToModule(updateList.get(i), request, user.getId(), caseModulePathMap, defaultTemplateDTO, caseMapper, caseBlobMapper, customFieldMapper, customFieldsMap, user.getLastOrganizationId(), caseIds);
|
parseUpdateDataToModule(updateList.get(i), request, user.getId(), caseModulePathMap, defaultTemplateDTO, caseMapper, caseBlobMapper, customFieldMapper, customFieldsMap, collect, historyLogDTOS);
|
||||||
|
// 重新提审的数据
|
||||||
|
addStatusIds(projectApplications, caseIds, collect, blobsCollect, updateList.get(i));
|
||||||
//通知
|
//通知
|
||||||
noticeModule(noticeList, updateList.get(i), request, user.getId(), customFieldsMap);
|
noticeModule(noticeList, updateList.get(i), request, user.getId(), customFieldsMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
sqlSession.flushStatements();
|
sqlSession.flushStatements();
|
||||||
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
|
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
|
||||||
|
|
||||||
|
@ -1180,21 +1229,53 @@ public class FunctionalCaseService {
|
||||||
caseReviewFunctionalCaseService.batchHandleStatusAndHistory(caseIds, user.getId());
|
caseReviewFunctionalCaseService.batchHandleStatusAndHistory(caseIds, user.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 日志
|
||||||
|
historyLogDTOS.forEach(historyLogDTO -> {
|
||||||
|
batchHandImportUpdateLog(historyLogDTO, collect, blobsCollect, customFieldMap, logDTOS, user);
|
||||||
|
});
|
||||||
|
operationLogService.batchAdd(logDTOS);
|
||||||
|
|
||||||
List<Map> resources = new ArrayList<>();
|
List<Map> resources = new ArrayList<>();
|
||||||
resources.addAll(JSON.parseArray(JSON.toJSONString(noticeList), Map.class));
|
resources.addAll(JSON.parseArray(JSON.toJSONString(noticeList), Map.class));
|
||||||
commonNoticeSendService.sendNotice(NoticeConstants.TaskType.FUNCTIONAL_CASE_TASK, NoticeConstants.Event.UPDATE, resources, user, request.getProjectId());
|
commonNoticeSendService.sendNotice(NoticeConstants.TaskType.FUNCTIONAL_CASE_TASK, NoticeConstants.Event.UPDATE, resources, user, request.getProjectId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void batchHandImportUpdateLog(FunctionalCaseHistoryLogDTO newData, Map<String, List<FunctionalCase>> collect, Map<String, List<FunctionalCaseBlob>> blobsCollect, Map<String, List<FunctionalCaseCustomField>> customFieldMap, List<LogDTO> logDTOS, SessionUser user) {
|
||||||
|
FunctionalCase oldCase = collect.get(newData.getFunctionalCase().getId()).get(0);
|
||||||
|
FunctionalCaseBlob oldBlod = blobsCollect.get(newData.getFunctionalCase().getId()).get(0);
|
||||||
|
List<FunctionalCaseCustomField> oldCustomFields = customFieldMap.get(newData.getFunctionalCase().getId());
|
||||||
|
batchSaveImportData(newData, new FunctionalCaseHistoryLogDTO(oldCase, oldBlod, oldCustomFields, new ArrayList<>(), new ArrayList<>()), user, OperationLogType.IMPORT.name(), OperationLogModule.FUNCTIONAL_CASE, logDTOS);
|
||||||
|
}
|
||||||
|
|
||||||
private void parseUpdateDataToModule(FunctionalCaseExcelData functionalCaseExcelData, FunctionalCaseImportRequest request, String userId, Map<String, String> caseModulePathMap, TemplateDTO defaultTemplateDTO, FunctionalCaseMapper caseMapper, FunctionalCaseBlobMapper caseBlobMapper, FunctionalCaseCustomFieldMapper customFieldMapper, Map<String, TemplateCustomFieldDTO> customFieldsMap, String organizationId, List<String> caseIds) {
|
/**
|
||||||
|
* 获取更新的用例大字段数据
|
||||||
|
*
|
||||||
|
* @param ids
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private List<FunctionalCaseBlob> getBlobDataByIds(List<String> ids) {
|
||||||
|
FunctionalCaseBlobExample blobExample = new FunctionalCaseBlobExample();
|
||||||
|
blobExample.createCriteria().andIdIn(ids);
|
||||||
|
return functionalCaseBlobMapper.selectByExampleWithBLOBs(blobExample);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取更新的用例数据
|
||||||
|
*
|
||||||
|
* @param ids
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private List<FunctionalCase> getCaseDataByIds(List<String> ids) {
|
||||||
|
FunctionalCaseExample example = new FunctionalCaseExample();
|
||||||
|
example.createCriteria().andIdIn(ids);
|
||||||
|
return functionalCaseMapper.selectByExample(example);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void parseUpdateDataToModule(FunctionalCaseExcelData functionalCaseExcelData, FunctionalCaseImportRequest request, String userId, Map<String, String> caseModulePathMap, TemplateDTO defaultTemplateDTO, FunctionalCaseMapper caseMapper, FunctionalCaseBlobMapper caseBlobMapper,
|
||||||
|
FunctionalCaseCustomFieldMapper customFieldMapper, Map<String, TemplateCustomFieldDTO> customFieldsMap, Map<String, List<FunctionalCase>> collect, List<FunctionalCaseHistoryLogDTO> historyLogDTOS) {
|
||||||
//用例表
|
//用例表
|
||||||
FunctionalCase functionalCase = caseMapper.selectByPrimaryKey(functionalCaseExcelData.getNum());
|
FunctionalCase functionalCase = collect.get(functionalCaseExcelData.getNum()).get(0);
|
||||||
|
|
||||||
//触发重新提审id
|
|
||||||
addStatusIds(caseIds, functionalCase, functionalCaseExcelData);
|
|
||||||
|
|
||||||
//记录原值
|
|
||||||
FunctionalCaseHistoryLogDTO originalValue = getImportLogModule(functionalCase);
|
|
||||||
|
|
||||||
functionalCase.setName(functionalCaseExcelData.getName());
|
functionalCase.setName(functionalCaseExcelData.getName());
|
||||||
functionalCase.setModuleId(caseModulePathMap.get(functionalCaseExcelData.getModule()));
|
functionalCase.setModuleId(caseModulePathMap.get(functionalCaseExcelData.getModule()));
|
||||||
|
@ -1218,20 +1299,17 @@ public class FunctionalCaseService {
|
||||||
caseBlobMapper.updateByPrimaryKeyWithBLOBs(caseBlob);
|
caseBlobMapper.updateByPrimaryKeyWithBLOBs(caseBlob);
|
||||||
|
|
||||||
//自定义字段
|
//自定义字段
|
||||||
handleUpdateCustomField(functionalCaseExcelData, functionalCase.getId(), customFieldMapper, customFieldsMap);
|
List<FunctionalCaseCustomField> customFields = handleUpdateCustomField(functionalCaseExcelData, functionalCase.getId(), customFieldMapper, customFieldsMap);
|
||||||
|
|
||||||
|
// 记录新值
|
||||||
|
historyLogDTOS.add(new FunctionalCaseHistoryLogDTO(functionalCase, caseBlob, customFields, new ArrayList<>(), new ArrayList<>()));
|
||||||
|
|
||||||
//记录新值
|
|
||||||
FunctionalCaseHistoryLogDTO modifiedLogDTO = getImportLogModule(functionalCase);
|
|
||||||
//记录日志
|
|
||||||
saveImportDataLog(functionalCase, originalValue, modifiedLogDTO, userId, organizationId, OperationLogType.IMPORT.name(), OperationLogModule.FUNCTIONAL_CASE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addStatusIds(List<String> caseIds, FunctionalCase functionalCase, FunctionalCaseExcelData functionalCaseExcelData) {
|
private void addStatusIds(List<ProjectApplication> projectApplications, List<String> caseIds, Map<String, List<FunctionalCase>> collect, Map<String, List<FunctionalCaseBlob>> blobsCollect, FunctionalCaseExcelData functionalCaseExcelData) {
|
||||||
ProjectApplicationExample example = new ProjectApplicationExample();
|
FunctionalCase functionalCase = collect.get(functionalCaseExcelData.getNum()).get(0);
|
||||||
example.createCriteria().andProjectIdEqualTo(functionalCase.getProjectId()).andTypeEqualTo(ProjectApplicationType.CASE.CASE_RE_REVIEW.name());
|
|
||||||
List<ProjectApplication> projectApplications = projectApplicationMapper.selectByExample(example);
|
|
||||||
if (CollectionUtils.isNotEmpty(projectApplications) && Boolean.valueOf(projectApplications.get(0).getTypeValue())) {
|
if (CollectionUtils.isNotEmpty(projectApplications) && Boolean.valueOf(projectApplications.get(0).getTypeValue())) {
|
||||||
FunctionalCaseBlob blob = functionalCaseBlobMapper.selectByPrimaryKey(functionalCase.getId());
|
FunctionalCaseBlob blob = blobsCollect.get(functionalCaseExcelData.getNum()).get(0);
|
||||||
if (!StringUtils.equals(functionalCase.getName(), functionalCaseExcelData.getName())
|
if (!StringUtils.equals(functionalCase.getName(), functionalCaseExcelData.getName())
|
||||||
|| !StringUtils.equals(new String(blob.getSteps(), StandardCharsets.UTF_8), StringUtils.defaultIfBlank(functionalCaseExcelData.getSteps(), StringUtils.EMPTY))
|
|| !StringUtils.equals(new String(blob.getSteps(), StandardCharsets.UTF_8), StringUtils.defaultIfBlank(functionalCaseExcelData.getSteps(), StringUtils.EMPTY))
|
||||||
|| !StringUtils.equals(new String(blob.getTextDescription(), StandardCharsets.UTF_8), StringUtils.defaultIfBlank(functionalCaseExcelData.getTextDescription(), StringUtils.EMPTY))
|
|| !StringUtils.equals(new String(blob.getTextDescription(), StandardCharsets.UTF_8), StringUtils.defaultIfBlank(functionalCaseExcelData.getTextDescription(), StringUtils.EMPTY))
|
||||||
|
@ -1241,11 +1319,12 @@ public class FunctionalCaseService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleUpdateCustomField(FunctionalCaseExcelData functionalCaseExcelData, String caseId, FunctionalCaseCustomFieldMapper customFieldMapper, Map<String, TemplateCustomFieldDTO> customFieldsMap) {
|
private List<FunctionalCaseCustomField> handleUpdateCustomField(FunctionalCaseExcelData functionalCaseExcelData, String caseId, FunctionalCaseCustomFieldMapper customFieldMapper, Map<String, TemplateCustomFieldDTO> customFieldsMap) {
|
||||||
FunctionalCaseCustomFieldExample fieldExample = new FunctionalCaseCustomFieldExample();
|
FunctionalCaseCustomFieldExample fieldExample = new FunctionalCaseCustomFieldExample();
|
||||||
fieldExample.createCriteria().andCaseIdEqualTo(caseId);
|
fieldExample.createCriteria().andCaseIdEqualTo(caseId);
|
||||||
customFieldMapper.deleteByExample(fieldExample);
|
customFieldMapper.deleteByExample(fieldExample);
|
||||||
handleImportCustomField(functionalCaseExcelData, caseId, customFieldMapper, customFieldsMap);
|
List<FunctionalCaseCustomField> customFields = handleImportCustomField(functionalCaseExcelData, caseId, customFieldMapper, customFieldsMap);
|
||||||
|
return customFields;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1256,7 +1335,7 @@ public class FunctionalCaseService {
|
||||||
* @param originalValue 原值
|
* @param originalValue 原值
|
||||||
* @param modifiedLogDTO 新值
|
* @param modifiedLogDTO 新值
|
||||||
*/
|
*/
|
||||||
private void saveImportDataLog(FunctionalCase functionalCase, FunctionalCaseHistoryLogDTO originalValue, FunctionalCaseHistoryLogDTO modifiedLogDTO, String userId, String organizationId, String type, String module) {
|
private void saveAddDataLog(FunctionalCase functionalCase, FunctionalCaseHistoryLogDTO originalValue, FunctionalCaseHistoryLogDTO modifiedLogDTO, String userId, String organizationId, String type, String module) {
|
||||||
LogDTO dto = new LogDTO(
|
LogDTO dto = new LogDTO(
|
||||||
functionalCase.getProjectId(),
|
functionalCase.getProjectId(),
|
||||||
organizationId,
|
organizationId,
|
||||||
|
@ -1266,7 +1345,7 @@ public class FunctionalCaseService {
|
||||||
module,
|
module,
|
||||||
functionalCase.getName());
|
functionalCase.getName());
|
||||||
dto.setHistory(true);
|
dto.setHistory(true);
|
||||||
dto.setPath("/functional/case/import/excel");
|
dto.setPath("/functional/case/add");
|
||||||
dto.setMethod(HttpMethodConstants.POST.name());
|
dto.setMethod(HttpMethodConstants.POST.name());
|
||||||
dto.setModifiedValue(JSON.toJSONBytes(modifiedLogDTO));
|
dto.setModifiedValue(JSON.toJSONBytes(modifiedLogDTO));
|
||||||
dto.setOriginalValue(JSON.toJSONBytes(originalValue));
|
dto.setOriginalValue(JSON.toJSONBytes(originalValue));
|
||||||
|
@ -1279,7 +1358,7 @@ public class FunctionalCaseService {
|
||||||
* @param functionalCase
|
* @param functionalCase
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private FunctionalCaseHistoryLogDTO getImportLogModule(FunctionalCase functionalCase) {
|
private FunctionalCaseHistoryLogDTO getAddLogModule(FunctionalCase functionalCase) {
|
||||||
FunctionalCaseBlob functionalCaseBlob = functionalCaseBlobMapper.selectByPrimaryKey(functionalCase.getId());
|
FunctionalCaseBlob functionalCaseBlob = functionalCaseBlobMapper.selectByPrimaryKey(functionalCase.getId());
|
||||||
//自定义字段
|
//自定义字段
|
||||||
FunctionalCaseCustomFieldExample fieldExample = new FunctionalCaseCustomFieldExample();
|
FunctionalCaseCustomFieldExample fieldExample = new FunctionalCaseCustomFieldExample();
|
||||||
|
|
Loading…
Reference in New Issue