@Test public void testSaveInspection() throws Exception { }
public CommonResult saveInspection(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){ inspectionMapper.deleteByCollectionId(collectionId); inspectionProjectMapper.deleteItemsByCollectionId(collectionId); Inspection inspection = new Inspection(); inspection.setId(collectionId); inspection.setProjectId(0); inspection.setCaseId(caseId); inspection.setCreatorRoleId(applicantRoleId); count = inspectionMapper.insertSelective(inspection); if(count <= 0) return CommonResult.fail(ResultCode.E_802); return CommonResult.success(count); } List<Integer> existedProjectIds = inspectionMapper.listProjectIdsByCollectionId(collectionId); for(ProjectParam projectParam: projectParams) { Integer projectId = projectParam.getProjectId(); if(projectId == null) return CommonResult.fail(ResultCode.E_801); Inspection inspection = new Inspection(); inspection.setId(collectionId); inspection.setProjectId(projectId); inspection.setStatus(projectParam.getStatus()); inspection.setGoal(projectParam.getGoal()); inspection.setRequirement(projectParam.getRequirement()); if(existedProjectIds.contains(projectId)) { count = inspectionMapper.updateInfo(inspection); if (count <= 0) return CommonResult.fail(); List<ItemParam> itemParams = projectParam.getItems(); List<String> existedItemIds = inspectionProjectMapper. 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 = inspectionProjectMapper.updateAmount(collectionId, projectId, itemId, amount); if (count <= 0) return CommonResult.fail(); existedItemIds.remove(itemId); } else { count = insertInspectionProject(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) { inspectionProjectMapper.delete(collectionId, projectId, leftItemId); } existedProjectIds.remove(projectId); } else{ Integer departmentId = techProjectMapper.getDepartmentIdByProjectId(projectId); if (departmentId == null) return CommonResult.fail(ResultCode.E_800); inspection.setDepartmentId(departmentId); inspection.setCaseId(caseId); inspection.setCreatorRoleId(applicantRoleId); count = inspectionMapper.insertSelective(inspection); if (count <= 0) return CommonResult.fail(); List<ItemParam> itemParams = projectParam.getItems(); for(ItemParam itemParam : itemParams) { count = insertInspectionProject(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){ inspectionMapper.delete(collectionId, leftProjectId); inspectionProjectMapper.deleteItemsByCidAndPid(collectionId, leftProjectId); } return CommonResult.success(count); }
ProjectCollectionManagementServiceImpl implements ProjectCollectionManagementService { public CommonResult saveInspection(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){ inspectionMapper.deleteByCollectionId(collectionId); inspectionProjectMapper.deleteItemsByCollectionId(collectionId); Inspection inspection = new Inspection(); inspection.setId(collectionId); inspection.setProjectId(0); inspection.setCaseId(caseId); inspection.setCreatorRoleId(applicantRoleId); count = inspectionMapper.insertSelective(inspection); if(count <= 0) return CommonResult.fail(ResultCode.E_802); return CommonResult.success(count); } List<Integer> existedProjectIds = inspectionMapper.listProjectIdsByCollectionId(collectionId); for(ProjectParam projectParam: projectParams) { Integer projectId = projectParam.getProjectId(); if(projectId == null) return CommonResult.fail(ResultCode.E_801); Inspection inspection = new Inspection(); inspection.setId(collectionId); inspection.setProjectId(projectId); inspection.setStatus(projectParam.getStatus()); inspection.setGoal(projectParam.getGoal()); inspection.setRequirement(projectParam.getRequirement()); if(existedProjectIds.contains(projectId)) { count = inspectionMapper.updateInfo(inspection); if (count <= 0) return CommonResult.fail(); List<ItemParam> itemParams = projectParam.getItems(); List<String> existedItemIds = inspectionProjectMapper. 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 = inspectionProjectMapper.updateAmount(collectionId, projectId, itemId, amount); if (count <= 0) return CommonResult.fail(); existedItemIds.remove(itemId); } else { count = insertInspectionProject(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) { inspectionProjectMapper.delete(collectionId, projectId, leftItemId); } existedProjectIds.remove(projectId); } else{ Integer departmentId = techProjectMapper.getDepartmentIdByProjectId(projectId); if (departmentId == null) return CommonResult.fail(ResultCode.E_800); inspection.setDepartmentId(departmentId); inspection.setCaseId(caseId); inspection.setCreatorRoleId(applicantRoleId); count = inspectionMapper.insertSelective(inspection); if (count <= 0) return CommonResult.fail(); List<ItemParam> itemParams = projectParam.getItems(); for(ItemParam itemParam : itemParams) { count = insertInspectionProject(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){ inspectionMapper.delete(collectionId, leftProjectId); inspectionProjectMapper.deleteItemsByCidAndPid(collectionId, leftProjectId); } return CommonResult.success(count); } }
ProjectCollectionManagementServiceImpl implements ProjectCollectionManagementService { public CommonResult saveInspection(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){ inspectionMapper.deleteByCollectionId(collectionId); inspectionProjectMapper.deleteItemsByCollectionId(collectionId); Inspection inspection = new Inspection(); inspection.setId(collectionId); inspection.setProjectId(0); inspection.setCaseId(caseId); inspection.setCreatorRoleId(applicantRoleId); count = inspectionMapper.insertSelective(inspection); if(count <= 0) return CommonResult.fail(ResultCode.E_802); return CommonResult.success(count); } List<Integer> existedProjectIds = inspectionMapper.listProjectIdsByCollectionId(collectionId); for(ProjectParam projectParam: projectParams) { Integer projectId = projectParam.getProjectId(); if(projectId == null) return CommonResult.fail(ResultCode.E_801); Inspection inspection = new Inspection(); inspection.setId(collectionId); inspection.setProjectId(projectId); inspection.setStatus(projectParam.getStatus()); inspection.setGoal(projectParam.getGoal()); inspection.setRequirement(projectParam.getRequirement()); if(existedProjectIds.contains(projectId)) { count = inspectionMapper.updateInfo(inspection); if (count <= 0) return CommonResult.fail(); List<ItemParam> itemParams = projectParam.getItems(); List<String> existedItemIds = inspectionProjectMapper. 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 = inspectionProjectMapper.updateAmount(collectionId, projectId, itemId, amount); if (count <= 0) return CommonResult.fail(); existedItemIds.remove(itemId); } else { count = insertInspectionProject(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) { inspectionProjectMapper.delete(collectionId, projectId, leftItemId); } existedProjectIds.remove(projectId); } else{ Integer departmentId = techProjectMapper.getDepartmentIdByProjectId(projectId); if (departmentId == null) return CommonResult.fail(ResultCode.E_800); inspection.setDepartmentId(departmentId); inspection.setCaseId(caseId); inspection.setCreatorRoleId(applicantRoleId); count = inspectionMapper.insertSelective(inspection); if (count <= 0) return CommonResult.fail(); List<ItemParam> itemParams = projectParam.getItems(); for(ItemParam itemParam : itemParams) { count = insertInspectionProject(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){ inspectionMapper.delete(collectionId, leftProjectId); inspectionProjectMapper.deleteItemsByCidAndPid(collectionId, leftProjectId); } return CommonResult.success(count); }  }
ProjectCollectionManagementServiceImpl implements ProjectCollectionManagementService { public CommonResult saveInspection(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){ inspectionMapper.deleteByCollectionId(collectionId); inspectionProjectMapper.deleteItemsByCollectionId(collectionId); Inspection inspection = new Inspection(); inspection.setId(collectionId); inspection.setProjectId(0); inspection.setCaseId(caseId); inspection.setCreatorRoleId(applicantRoleId); count = inspectionMapper.insertSelective(inspection); if(count <= 0) return CommonResult.fail(ResultCode.E_802); return CommonResult.success(count); } List<Integer> existedProjectIds = inspectionMapper.listProjectIdsByCollectionId(collectionId); for(ProjectParam projectParam: projectParams) { Integer projectId = projectParam.getProjectId(); if(projectId == null) return CommonResult.fail(ResultCode.E_801); Inspection inspection = new Inspection(); inspection.setId(collectionId); inspection.setProjectId(projectId); inspection.setStatus(projectParam.getStatus()); inspection.setGoal(projectParam.getGoal()); inspection.setRequirement(projectParam.getRequirement()); if(existedProjectIds.contains(projectId)) { count = inspectionMapper.updateInfo(inspection); if (count <= 0) return CommonResult.fail(); List<ItemParam> itemParams = projectParam.getItems(); List<String> existedItemIds = inspectionProjectMapper. 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 = inspectionProjectMapper.updateAmount(collectionId, projectId, itemId, amount); if (count <= 0) return CommonResult.fail(); existedItemIds.remove(itemId); } else { count = insertInspectionProject(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) { inspectionProjectMapper.delete(collectionId, projectId, leftItemId); } existedProjectIds.remove(projectId); } else{ Integer departmentId = techProjectMapper.getDepartmentIdByProjectId(projectId); if (departmentId == null) return CommonResult.fail(ResultCode.E_800); inspection.setDepartmentId(departmentId); inspection.setCaseId(caseId); inspection.setCreatorRoleId(applicantRoleId); count = inspectionMapper.insertSelective(inspection); if (count <= 0) return CommonResult.fail(); List<ItemParam> itemParams = projectParam.getItems(); for(ItemParam itemParam : itemParams) { count = insertInspectionProject(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){ inspectionMapper.delete(collectionId, leftProjectId); inspectionProjectMapper.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 saveInspection(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){ inspectionMapper.deleteByCollectionId(collectionId); inspectionProjectMapper.deleteItemsByCollectionId(collectionId); Inspection inspection = new Inspection(); inspection.setId(collectionId); inspection.setProjectId(0); inspection.setCaseId(caseId); inspection.setCreatorRoleId(applicantRoleId); count = inspectionMapper.insertSelective(inspection); if(count <= 0) return CommonResult.fail(ResultCode.E_802); return CommonResult.success(count); } List<Integer> existedProjectIds = inspectionMapper.listProjectIdsByCollectionId(collectionId); for(ProjectParam projectParam: projectParams) { Integer projectId = projectParam.getProjectId(); if(projectId == null) return CommonResult.fail(ResultCode.E_801); Inspection inspection = new Inspection(); inspection.setId(collectionId); inspection.setProjectId(projectId); inspection.setStatus(projectParam.getStatus()); inspection.setGoal(projectParam.getGoal()); inspection.setRequirement(projectParam.getRequirement()); if(existedProjectIds.contains(projectId)) { count = inspectionMapper.updateInfo(inspection); if (count <= 0) return CommonResult.fail(); List<ItemParam> itemParams = projectParam.getItems(); List<String> existedItemIds = inspectionProjectMapper. 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 = inspectionProjectMapper.updateAmount(collectionId, projectId, itemId, amount); if (count <= 0) return CommonResult.fail(); existedItemIds.remove(itemId); } else { count = insertInspectionProject(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) { inspectionProjectMapper.delete(collectionId, projectId, leftItemId); } existedProjectIds.remove(projectId); } else{ Integer departmentId = techProjectMapper.getDepartmentIdByProjectId(projectId); if (departmentId == null) return CommonResult.fail(ResultCode.E_800); inspection.setDepartmentId(departmentId); inspection.setCaseId(caseId); inspection.setCreatorRoleId(applicantRoleId); count = inspectionMapper.insertSelective(inspection); if (count <= 0) return CommonResult.fail(); List<ItemParam> itemParams = projectParam.getItems(); for(ItemParam itemParam : itemParams) { count = insertInspectionProject(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){ inspectionMapper.delete(collectionId, leftProjectId); inspectionProjectMapper.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);  }