@Test public void testSaveExamination() throws Exception { }
public CommonResult saveExamination(CollectionParam collectionParam, int operation){ int count = 0; Integer creatorRoleId = collectionParam.getRoleId(); Integer caseId = collectionParam.getCaseId(); Integer collectionId = collectionParam.getCollectionId(); Integer applicantRoleId = collectionParam.getApplicantRoleId(); List<ProjectParam> projectParams = collectionParam.getProjects(); if(caseId == null || collectionId == null || applicantRoleId == null) return CommonResult.fail(ResultCode.E_801); if(projectParams.size() == 0){ examinationMapper.deleteByCollectionId(collectionId); examinationProjectMapper.deleteItemsByCollectionId(collectionId); Examination examination = new Examination(); examination.setId(collectionId); examination.setProjectId(0); examination.setCaseId(caseId); examination.setCreatorRoleId(applicantRoleId); count = examinationMapper.insertSelective(examination); if(count <= 0) return CommonResult.fail(ResultCode.E_802); return CommonResult.success(count); } List<Integer> existedProjectIds = examinationMapper.listProjectIdsByCollectionId(collectionId); for(ProjectParam projectParam: projectParams) { Integer projectId = projectParam.getProjectId(); if(projectId == null) return CommonResult.fail(ResultCode.E_801); Examination examination = new Examination(); examination.setId(collectionId); examination.setProjectId(projectId); examination.setStatus(projectParam.getStatus()); examination.setGoal(projectParam.getGoal()); examination.setRequirement(projectParam.getRequirement()); if(existedProjectIds.contains(projectId)) { count = examinationMapper.updateInfo(examination); if (count <= 0) return CommonResult.fail(); List<ItemParam> itemParams = projectParam.getItems(); List<String> existedItemIds = examinationProjectMapper. listItemIdsByCollectionIdAndProjectId(collectionId, projectId); for (ItemParam itemParam : itemParams) { String itemId = itemParam.getItemId(); if (itemId == null) return CommonResult.fail(ResultCode.E_801); if (existedItemIds.contains(itemId)) { Short amount = itemParam.getAmount(); count = examinationProjectMapper.updateAmount(collectionId, projectId, itemId, amount); if (count <= 0) return CommonResult.fail(); existedItemIds.remove(itemId); } else { count = insertExaminationProject(collectionId, projectId, itemParam); if(count <= 0) return CommonResult.fail(ResultCode.E_802); } if (operation == 2) { CommonResult commonResult = insertTransactionLog(collectionParam, projectParam, itemParam, creatorRoleId); if (commonResult.getCode() != 200) return CommonResult.fail(ResultCode.E_802); } } for (String leftItemId : existedItemIds) { examinationProjectMapper.delete(collectionId, projectId, leftItemId); } existedProjectIds.remove(projectId); } else{ Integer departmentId = techProjectMapper.getDepartmentIdByProjectId(projectId); System.out.println(departmentId); if (departmentId == null) return CommonResult.fail(ResultCode.E_800); examination.setDepartmentId(departmentId); examination.setCaseId(caseId); examination.setCreatorRoleId(applicantRoleId); count = examinationMapper.insertSelective(examination); if (count <= 0) return CommonResult.fail(); List<ItemParam> itemParams = projectParam.getItems(); for(ItemParam itemParam : itemParams) { count = insertExaminationProject(collectionId, projectId, itemParam); if(count <= 0) return CommonResult.fail(ResultCode.E_802); if (operation == 2) { CommonResult commonResult = insertTransactionLog(collectionParam, projectParam, itemParam, creatorRoleId); if (commonResult.getCode() != 200) return CommonResult.fail(ResultCode.E_802); } } } } for(Integer leftProjectId: existedProjectIds){ examinationMapper.delete(collectionId, leftProjectId); examinationProjectMapper.deleteItemsByCidAndPid(collectionId, leftProjectId); } return CommonResult.success(count); }
ProjectCollectionManagementServiceImpl implements ProjectCollectionManagementService { public CommonResult saveExamination(CollectionParam collectionParam, int operation){ int count = 0; Integer creatorRoleId = collectionParam.getRoleId(); Integer caseId = collectionParam.getCaseId(); Integer collectionId = collectionParam.getCollectionId(); Integer applicantRoleId = collectionParam.getApplicantRoleId(); List<ProjectParam> projectParams = collectionParam.getProjects(); if(caseId == null || collectionId == null || applicantRoleId == null) return CommonResult.fail(ResultCode.E_801); if(projectParams.size() == 0){ examinationMapper.deleteByCollectionId(collectionId); examinationProjectMapper.deleteItemsByCollectionId(collectionId); Examination examination = new Examination(); examination.setId(collectionId); examination.setProjectId(0); examination.setCaseId(caseId); examination.setCreatorRoleId(applicantRoleId); count = examinationMapper.insertSelective(examination); if(count <= 0) return CommonResult.fail(ResultCode.E_802); return CommonResult.success(count); } List<Integer> existedProjectIds = examinationMapper.listProjectIdsByCollectionId(collectionId); for(ProjectParam projectParam: projectParams) { Integer projectId = projectParam.getProjectId(); if(projectId == null) return CommonResult.fail(ResultCode.E_801); Examination examination = new Examination(); examination.setId(collectionId); examination.setProjectId(projectId); examination.setStatus(projectParam.getStatus()); examination.setGoal(projectParam.getGoal()); examination.setRequirement(projectParam.getRequirement()); if(existedProjectIds.contains(projectId)) { count = examinationMapper.updateInfo(examination); if (count <= 0) return CommonResult.fail(); List<ItemParam> itemParams = projectParam.getItems(); List<String> existedItemIds = examinationProjectMapper. listItemIdsByCollectionIdAndProjectId(collectionId, projectId); for (ItemParam itemParam : itemParams) { String itemId = itemParam.getItemId(); if (itemId == null) return CommonResult.fail(ResultCode.E_801); if (existedItemIds.contains(itemId)) { Short amount = itemParam.getAmount(); count = examinationProjectMapper.updateAmount(collectionId, projectId, itemId, amount); if (count <= 0) return CommonResult.fail(); existedItemIds.remove(itemId); } else { count = insertExaminationProject(collectionId, projectId, itemParam); if(count <= 0) return CommonResult.fail(ResultCode.E_802); } if (operation == 2) { CommonResult commonResult = insertTransactionLog(collectionParam, projectParam, itemParam, creatorRoleId); if (commonResult.getCode() != 200) return CommonResult.fail(ResultCode.E_802); } } for (String leftItemId : existedItemIds) { examinationProjectMapper.delete(collectionId, projectId, leftItemId); } existedProjectIds.remove(projectId); } else{ Integer departmentId = techProjectMapper.getDepartmentIdByProjectId(projectId); System.out.println(departmentId); if (departmentId == null) return CommonResult.fail(ResultCode.E_800); examination.setDepartmentId(departmentId); examination.setCaseId(caseId); examination.setCreatorRoleId(applicantRoleId); count = examinationMapper.insertSelective(examination); if (count <= 0) return CommonResult.fail(); List<ItemParam> itemParams = projectParam.getItems(); for(ItemParam itemParam : itemParams) { count = insertExaminationProject(collectionId, projectId, itemParam); if(count <= 0) return CommonResult.fail(ResultCode.E_802); if (operation == 2) { CommonResult commonResult = insertTransactionLog(collectionParam, projectParam, itemParam, creatorRoleId); if (commonResult.getCode() != 200) return CommonResult.fail(ResultCode.E_802); } } } } for(Integer leftProjectId: existedProjectIds){ examinationMapper.delete(collectionId, leftProjectId); examinationProjectMapper.deleteItemsByCidAndPid(collectionId, leftProjectId); } return CommonResult.success(count); } }
ProjectCollectionManagementServiceImpl implements ProjectCollectionManagementService { public CommonResult saveExamination(CollectionParam collectionParam, int operation){ int count = 0; Integer creatorRoleId = collectionParam.getRoleId(); Integer caseId = collectionParam.getCaseId(); Integer collectionId = collectionParam.getCollectionId(); Integer applicantRoleId = collectionParam.getApplicantRoleId(); List<ProjectParam> projectParams = collectionParam.getProjects(); if(caseId == null || collectionId == null || applicantRoleId == null) return CommonResult.fail(ResultCode.E_801); if(projectParams.size() == 0){ examinationMapper.deleteByCollectionId(collectionId); examinationProjectMapper.deleteItemsByCollectionId(collectionId); Examination examination = new Examination(); examination.setId(collectionId); examination.setProjectId(0); examination.setCaseId(caseId); examination.setCreatorRoleId(applicantRoleId); count = examinationMapper.insertSelective(examination); if(count <= 0) return CommonResult.fail(ResultCode.E_802); return CommonResult.success(count); } List<Integer> existedProjectIds = examinationMapper.listProjectIdsByCollectionId(collectionId); for(ProjectParam projectParam: projectParams) { Integer projectId = projectParam.getProjectId(); if(projectId == null) return CommonResult.fail(ResultCode.E_801); Examination examination = new Examination(); examination.setId(collectionId); examination.setProjectId(projectId); examination.setStatus(projectParam.getStatus()); examination.setGoal(projectParam.getGoal()); examination.setRequirement(projectParam.getRequirement()); if(existedProjectIds.contains(projectId)) { count = examinationMapper.updateInfo(examination); if (count <= 0) return CommonResult.fail(); List<ItemParam> itemParams = projectParam.getItems(); List<String> existedItemIds = examinationProjectMapper. listItemIdsByCollectionIdAndProjectId(collectionId, projectId); for (ItemParam itemParam : itemParams) { String itemId = itemParam.getItemId(); if (itemId == null) return CommonResult.fail(ResultCode.E_801); if (existedItemIds.contains(itemId)) { Short amount = itemParam.getAmount(); count = examinationProjectMapper.updateAmount(collectionId, projectId, itemId, amount); if (count <= 0) return CommonResult.fail(); existedItemIds.remove(itemId); } else { count = insertExaminationProject(collectionId, projectId, itemParam); if(count <= 0) return CommonResult.fail(ResultCode.E_802); } if (operation == 2) { CommonResult commonResult = insertTransactionLog(collectionParam, projectParam, itemParam, creatorRoleId); if (commonResult.getCode() != 200) return CommonResult.fail(ResultCode.E_802); } } for (String leftItemId : existedItemIds) { examinationProjectMapper.delete(collectionId, projectId, leftItemId); } existedProjectIds.remove(projectId); } else{ Integer departmentId = techProjectMapper.getDepartmentIdByProjectId(projectId); System.out.println(departmentId); if (departmentId == null) return CommonResult.fail(ResultCode.E_800); examination.setDepartmentId(departmentId); examination.setCaseId(caseId); examination.setCreatorRoleId(applicantRoleId); count = examinationMapper.insertSelective(examination); if (count <= 0) return CommonResult.fail(); List<ItemParam> itemParams = projectParam.getItems(); for(ItemParam itemParam : itemParams) { count = insertExaminationProject(collectionId, projectId, itemParam); if(count <= 0) return CommonResult.fail(ResultCode.E_802); if (operation == 2) { CommonResult commonResult = insertTransactionLog(collectionParam, projectParam, itemParam, creatorRoleId); if (commonResult.getCode() != 200) return CommonResult.fail(ResultCode.E_802); } } } } for(Integer leftProjectId: existedProjectIds){ examinationMapper.delete(collectionId, leftProjectId); examinationProjectMapper.deleteItemsByCidAndPid(collectionId, leftProjectId); } return CommonResult.success(count); }  }
ProjectCollectionManagementServiceImpl implements ProjectCollectionManagementService { public CommonResult saveExamination(CollectionParam collectionParam, int operation){ int count = 0; Integer creatorRoleId = collectionParam.getRoleId(); Integer caseId = collectionParam.getCaseId(); Integer collectionId = collectionParam.getCollectionId(); Integer applicantRoleId = collectionParam.getApplicantRoleId(); List<ProjectParam> projectParams = collectionParam.getProjects(); if(caseId == null || collectionId == null || applicantRoleId == null) return CommonResult.fail(ResultCode.E_801); if(projectParams.size() == 0){ examinationMapper.deleteByCollectionId(collectionId); examinationProjectMapper.deleteItemsByCollectionId(collectionId); Examination examination = new Examination(); examination.setId(collectionId); examination.setProjectId(0); examination.setCaseId(caseId); examination.setCreatorRoleId(applicantRoleId); count = examinationMapper.insertSelective(examination); if(count <= 0) return CommonResult.fail(ResultCode.E_802); return CommonResult.success(count); } List<Integer> existedProjectIds = examinationMapper.listProjectIdsByCollectionId(collectionId); for(ProjectParam projectParam: projectParams) { Integer projectId = projectParam.getProjectId(); if(projectId == null) return CommonResult.fail(ResultCode.E_801); Examination examination = new Examination(); examination.setId(collectionId); examination.setProjectId(projectId); examination.setStatus(projectParam.getStatus()); examination.setGoal(projectParam.getGoal()); examination.setRequirement(projectParam.getRequirement()); if(existedProjectIds.contains(projectId)) { count = examinationMapper.updateInfo(examination); if (count <= 0) return CommonResult.fail(); List<ItemParam> itemParams = projectParam.getItems(); List<String> existedItemIds = examinationProjectMapper. listItemIdsByCollectionIdAndProjectId(collectionId, projectId); for (ItemParam itemParam : itemParams) { String itemId = itemParam.getItemId(); if (itemId == null) return CommonResult.fail(ResultCode.E_801); if (existedItemIds.contains(itemId)) { Short amount = itemParam.getAmount(); count = examinationProjectMapper.updateAmount(collectionId, projectId, itemId, amount); if (count <= 0) return CommonResult.fail(); existedItemIds.remove(itemId); } else { count = insertExaminationProject(collectionId, projectId, itemParam); if(count <= 0) return CommonResult.fail(ResultCode.E_802); } if (operation == 2) { CommonResult commonResult = insertTransactionLog(collectionParam, projectParam, itemParam, creatorRoleId); if (commonResult.getCode() != 200) return CommonResult.fail(ResultCode.E_802); } } for (String leftItemId : existedItemIds) { examinationProjectMapper.delete(collectionId, projectId, leftItemId); } existedProjectIds.remove(projectId); } else{ Integer departmentId = techProjectMapper.getDepartmentIdByProjectId(projectId); System.out.println(departmentId); if (departmentId == null) return CommonResult.fail(ResultCode.E_800); examination.setDepartmentId(departmentId); examination.setCaseId(caseId); examination.setCreatorRoleId(applicantRoleId); count = examinationMapper.insertSelective(examination); if (count <= 0) return CommonResult.fail(); List<ItemParam> itemParams = projectParam.getItems(); for(ItemParam itemParam : itemParams) { count = insertExaminationProject(collectionId, projectId, itemParam); if(count <= 0) return CommonResult.fail(ResultCode.E_802); if (operation == 2) { CommonResult commonResult = insertTransactionLog(collectionParam, projectParam, itemParam, creatorRoleId); if (commonResult.getCode() != 200) return CommonResult.fail(ResultCode.E_802); } } } } for(Integer leftProjectId: existedProjectIds){ examinationMapper.delete(collectionId, leftProjectId); examinationProjectMapper.deleteItemsByCidAndPid(collectionId, leftProjectId); } return CommonResult.success(count); }  @Override CommonResult listCollections(Integer caseId, Integer type); @Override CommonResult applyNewCollection(Integer collectionType); @Override CommonResult savePresentCollection(CollectionParam collectionParam); @Override CommonResult submitPresentCollection(CollectionParam collectionParam); CommonResult chooseByType(CollectionParam collectionParam, int operation); CommonResult saveInspection(CollectionParam collectionParam, int operation); CommonResult saveExamination(CollectionParam collectionParam, int operation); CommonResult saveTreatment(CollectionParam collectionParam, int operation); int insertInspectionProject(Integer collectionId, Integer projectId, ItemParam itemParam); int insertExaminationProject(Integer collectionId, Integer projectId, ItemParam itemParam); CommonResult insertTransactionLog(CollectionParam collectionParam, ProjectParam projectParam,
                                             ItemParam itemParam, Integer creatorRoleId); CommonResult cancelSubmittedCollection(Integer collectionId, Integer type); CommonResult deleteCollection(Integer collectionId, Integer type); CommonResult getProjectResult(ProjectParam projectParam); }
ProjectCollectionManagementServiceImpl implements ProjectCollectionManagementService { public CommonResult saveExamination(CollectionParam collectionParam, int operation){ int count = 0; Integer creatorRoleId = collectionParam.getRoleId(); Integer caseId = collectionParam.getCaseId(); Integer collectionId = collectionParam.getCollectionId(); Integer applicantRoleId = collectionParam.getApplicantRoleId(); List<ProjectParam> projectParams = collectionParam.getProjects(); if(caseId == null || collectionId == null || applicantRoleId == null) return CommonResult.fail(ResultCode.E_801); if(projectParams.size() == 0){ examinationMapper.deleteByCollectionId(collectionId); examinationProjectMapper.deleteItemsByCollectionId(collectionId); Examination examination = new Examination(); examination.setId(collectionId); examination.setProjectId(0); examination.setCaseId(caseId); examination.setCreatorRoleId(applicantRoleId); count = examinationMapper.insertSelective(examination); if(count <= 0) return CommonResult.fail(ResultCode.E_802); return CommonResult.success(count); } List<Integer> existedProjectIds = examinationMapper.listProjectIdsByCollectionId(collectionId); for(ProjectParam projectParam: projectParams) { Integer projectId = projectParam.getProjectId(); if(projectId == null) return CommonResult.fail(ResultCode.E_801); Examination examination = new Examination(); examination.setId(collectionId); examination.setProjectId(projectId); examination.setStatus(projectParam.getStatus()); examination.setGoal(projectParam.getGoal()); examination.setRequirement(projectParam.getRequirement()); if(existedProjectIds.contains(projectId)) { count = examinationMapper.updateInfo(examination); if (count <= 0) return CommonResult.fail(); List<ItemParam> itemParams = projectParam.getItems(); List<String> existedItemIds = examinationProjectMapper. listItemIdsByCollectionIdAndProjectId(collectionId, projectId); for (ItemParam itemParam : itemParams) { String itemId = itemParam.getItemId(); if (itemId == null) return CommonResult.fail(ResultCode.E_801); if (existedItemIds.contains(itemId)) { Short amount = itemParam.getAmount(); count = examinationProjectMapper.updateAmount(collectionId, projectId, itemId, amount); if (count <= 0) return CommonResult.fail(); existedItemIds.remove(itemId); } else { count = insertExaminationProject(collectionId, projectId, itemParam); if(count <= 0) return CommonResult.fail(ResultCode.E_802); } if (operation == 2) { CommonResult commonResult = insertTransactionLog(collectionParam, projectParam, itemParam, creatorRoleId); if (commonResult.getCode() != 200) return CommonResult.fail(ResultCode.E_802); } } for (String leftItemId : existedItemIds) { examinationProjectMapper.delete(collectionId, projectId, leftItemId); } existedProjectIds.remove(projectId); } else{ Integer departmentId = techProjectMapper.getDepartmentIdByProjectId(projectId); System.out.println(departmentId); if (departmentId == null) return CommonResult.fail(ResultCode.E_800); examination.setDepartmentId(departmentId); examination.setCaseId(caseId); examination.setCreatorRoleId(applicantRoleId); count = examinationMapper.insertSelective(examination); if (count <= 0) return CommonResult.fail(); List<ItemParam> itemParams = projectParam.getItems(); for(ItemParam itemParam : itemParams) { count = insertExaminationProject(collectionId, projectId, itemParam); if(count <= 0) return CommonResult.fail(ResultCode.E_802); if (operation == 2) { CommonResult commonResult = insertTransactionLog(collectionParam, projectParam, itemParam, creatorRoleId); if (commonResult.getCode() != 200) return CommonResult.fail(ResultCode.E_802); } } } } for(Integer leftProjectId: existedProjectIds){ examinationMapper.delete(collectionId, leftProjectId); examinationProjectMapper.deleteItemsByCidAndPid(collectionId, leftProjectId); } return CommonResult.success(count); }  @Override CommonResult listCollections(Integer caseId, Integer type); @Override CommonResult applyNewCollection(Integer collectionType); @Override CommonResult savePresentCollection(CollectionParam collectionParam); @Override CommonResult submitPresentCollection(CollectionParam collectionParam); CommonResult chooseByType(CollectionParam collectionParam, int operation); CommonResult saveInspection(CollectionParam collectionParam, int operation); CommonResult saveExamination(CollectionParam collectionParam, int operation); CommonResult saveTreatment(CollectionParam collectionParam, int operation); int insertInspectionProject(Integer collectionId, Integer projectId, ItemParam itemParam); int insertExaminationProject(Integer collectionId, Integer projectId, ItemParam itemParam); CommonResult insertTransactionLog(CollectionParam collectionParam, ProjectParam projectParam,
                                             ItemParam itemParam, Integer creatorRoleId); CommonResult cancelSubmittedCollection(Integer collectionId, Integer type); CommonResult deleteCollection(Integer collectionId, Integer type); CommonResult getProjectResult(ProjectParam projectParam);  }