diff --git a/xm-core/src/main/java/com/xm/core/ctrl/XmQuestionController.java b/xm-core/src/main/java/com/xm/core/ctrl/XmQuestionController.java index da4922bf..35e1b71c 100644 --- a/xm-core/src/main/java/com/xm/core/ctrl/XmQuestionController.java +++ b/xm-core/src/main/java/com/xm/core/ctrl/XmQuestionController.java @@ -291,89 +291,15 @@ public class XmQuestionController { ResponseHelper.failed("bugs-0","该bug已不存在"); } + List canOper=new ArrayList<>(); - List canDel=new ArrayList<>(); + List noOper=new ArrayList<>(); - List noDel=new ArrayList<>(); - - List noDelTips=new ArrayList<>(); - - - /** - * 如果有测试计划,有产品编号,走产品团队判断权限 - * 如果未通过,继续走项目权限判断 - */ - Map> productsMap=new HashMap<>();//有产品的数据 - Map> projectsMap=new HashMap<>();//没有产品、但有项目的数据 - for (XmQuestion xmQuestion : xmQuestionsDb) { - if(StringUtils.hasText(xmQuestion.getProductId())){ - List datas=productsMap.get(xmQuestion.getProductId()); - if(datas==null){ - datas=new ArrayList<>(); - datas.add(xmQuestion); - productsMap.put(xmQuestion.getProductId(),datas); - }else { - datas.add(xmQuestion); - } - }else if(StringUtils.hasText(xmQuestion.getProjectId())) { - List datas=projectsMap.get(xmQuestion.getProjectId()); - if(datas==null){ - datas=new ArrayList<>(); - datas.add(xmQuestion); - projectsMap.put(xmQuestion.getProjectId(),datas); - }else { - datas.add(xmQuestion); - } - } - } - - if(productsMap.size()>0){ - for (String productId : productsMap.keySet()) { - XmProduct xmProduct=productService.getProductFromCache(productId); - Tips tips1=groupService.checkProductQx(xmProduct,1,user); - if(!tips1.isOk()){ - noDel.addAll(productsMap.get(productId)); - productsMap.remove(productId); - noDelTips.add(tips1); - }else{ - List questions=productsMap.get(productId); - for (XmQuestion question : questions) { - tips1=groupService.checkProductQx(xmProduct,1,user,question.getCreateUserid(),question.getHandlerUserid()); - if(!tips1.isOk()){ - noDel.add(question); - noDelTips.add(tips1); - }else { - canDel.add(question); - } - } - - } - } - } - if(projectsMap.size()>0){ - for (String projectId : projectsMap.keySet()) { - XmProject xmProject=projectService.getProjectFromCache(projectId); - Tips tips1=groupService.checkProjectQx(xmProject,user); - if(!tips1.isOk()){ - noDel.addAll(projectsMap.get(projectId)); - projectsMap.remove(projectId); - noDelTips.add(tips1); - }else{ - List questions=projectsMap.get(projectId); - for (XmQuestion question : questions) { - tips1=groupService.checkProjectQx(xmProject,user,question.getCreateUserid(),question.getHandlerUserid()); - if(!tips1.isOk()){ - noDel.add(question); - noDelTips.add(tips1); - }else { - canDel.add(question); - } - } - } - } - } + Map noOperTips=new HashMap<>(); + this.checkQx(xmQuestionsDb,canOper,noOper,noOperTips); + xmQuestionMap.put("ids",canOper.stream().map(k->k.getId()).collect(Collectors.toList())); Set fieldKey=xmQuestionMap.keySet().stream().filter(i->fieldsMap.containsKey(i)).collect(Collectors.toSet()); fieldKey=fieldKey.stream().filter(i->!StringUtils.isEmpty(xmQuestionMap.get(i) )).collect(Collectors.toSet()); @@ -394,7 +320,7 @@ public class XmQuestionController { Map map=new HashMap<>(); map.putAll(xmQuestionMap); map.remove("ids"); - for (XmQuestion xmQuestionVo : xmQuestionsDb) { + for (XmQuestion xmQuestionVo : canOper) { Map m2=BaseUtils.toMap(xmQuestionVo); m2.putAll(map); xmQuestionVo=BaseUtils.fromMap(m2,XmQuestion.class); @@ -431,7 +357,26 @@ public class XmQuestionController { } - + List msgs=new ArrayList<>(); + if(canOper.size()>0){ + for (XmQuestion xmQuestion : canOper) { + noOperTips.remove(xmQuestion.getId()); + } + msgs.add(String.format("修改了%s个缺陷。",canOper.size())); + } + if(noOper.size()>0){ + Set noDelTips2=new HashSet<>(); + for (XmQuestion xmQuestion : noOper) { + Tips tips1=noOperTips.get(xmQuestion.getId()); + noDelTips2.add(tips1.getMsg()); + } + msgs.add(String.format("其中%s个缺陷,无权限修改。原因【%s】",noOper.size(),noDelTips2.stream().collect(Collectors.joining(";")))); + } + if(canOper.size()>0){ + tips.setOkMsg(msgs.stream().collect(Collectors.joining())); + }else{ + tips.setFailureMsg(msgs.stream().collect(Collectors.joining())); + } //m.put("data",xmMenu); }catch (BizException e) { tips=e.getTips(); @@ -461,129 +406,34 @@ public class XmQuestionController { if(xmQuestionsDb==null || xmQuestionsDb.size()==0){ return ResponseHelper.failed("data-0","所有数据已不存在"); } - List canDel=new ArrayList<>(); - - List noDel=new ArrayList<>(); - - Map noDelTips=new HashMap<>(); - - - /** - * 如果有测试计划,有产品编号,走产品团队判断权限 - * 如果未通过,继续走项目权限判断 - */ - Map> productsMap=new HashMap<>();//有产品的数据 - Map> projectsMap=new HashMap<>();//没有产品、但有项目的数据 - for (XmQuestion xmQuestion : xmQuestionsDb) { - if(StringUtils.hasText(xmQuestion.getProductId())){ - List datas=productsMap.get(xmQuestion.getProductId()); - if(datas==null){ - datas=new ArrayList<>(); - datas.add(xmQuestion); - productsMap.put(xmQuestion.getProductId(),datas); - }else { - datas.add(xmQuestion); - } - }else if(StringUtils.hasText(xmQuestion.getProjectId())) { - List datas=projectsMap.get(xmQuestion.getProjectId()); - if(datas==null){ - datas=new ArrayList<>(); - datas.add(xmQuestion); - projectsMap.put(xmQuestion.getProjectId(),datas); - }else { - datas.add(xmQuestion); - } - } - } + List canOper=new ArrayList<>(); - List productNoDel=new ArrayList<>(); - if(productsMap.size()>0){ - for (String productId : productsMap.keySet()) { - XmProduct xmProduct=productService.getProductFromCache(productId); - Tips tips1=groupService.checkProductQx(xmProduct,1,user); - if(!tips1.isOk()){ - productNoDel.addAll(productsMap.get(productId)); - for (XmQuestion xmQuestion : productsMap.get(productId)) { - noDelTips.put(xmQuestion.getId(),tips1); - } - productsMap.remove(productId); - }else{ - List questions=productsMap.get(productId); - for (XmQuestion question : questions) { - tips1=groupService.checkProductQx(xmProduct,1,user,question.getCreateUserid(),question.getHandlerUserid()); - if(!tips1.isOk()){ - productNoDel.add(question); - noDelTips.put(question.getId(),tips1); - }else { - canDel.add(question); - } - } + List noOper=new ArrayList<>(); - } - } - } - for (XmQuestion xmQuestion : productNoDel) { - if(StringUtils.hasText(xmQuestion.getProjectId())){ - List ques=projectsMap.get(xmQuestion.getProjectId()); - if(ques!=null){ - if(!ques.stream().filter(k->k.getId().equals(xmQuestion.getId())).findAny().isPresent()){ - ques.add(xmQuestion); - } - }else{ - ques=new ArrayList<>(); - ques.add(xmQuestion); - projectsMap.put(xmQuestion.getProjectId(),ques); - } + Map noOperTips=new HashMap<>(); - }else{ - noDel.add(xmQuestion); - } - } - if(projectsMap.size()>0){ - for (String projectId : projectsMap.keySet()) { - XmProject xmProject=projectService.getProjectFromCache(projectId); - Tips tips1=groupService.checkProjectQx(xmProject,user); - if(!tips1.isOk()){ - noDel.addAll(projectsMap.get(projectId)); - for (XmQuestion xmQuestion : projectsMap.get(projectId)) { - noDelTips.put(xmQuestion.getId(),tips1); - } - projectsMap.remove(projectId); - }else{ - List questions=projectsMap.get(projectId); - for (XmQuestion question : questions) { - tips1=groupService.checkProjectQx(xmProject,user,question.getCreateUserid(),question.getHandlerUserid()); - if(!tips1.isOk()){ - noDel.add(question); - noDelTips.put(question.getId(),tips1); - }else { - canDel.add(question); - } - } - } - } - } + this.checkQx(xmQuestionsDb,canOper,noOper,noOperTips); - if(canDel.size()>0){ - xmQuestionService.batchDelete(canDel); + if(canOper.size()>0){ + xmQuestionService.batchDelete(canOper); } List msgs=new ArrayList<>(); - if(canDel.size()>0){ - for (XmQuestion xmQuestion : canDel) { - noDelTips.remove(xmQuestion.getId()); + if(canOper.size()>0){ + for (XmQuestion xmQuestion : canOper) { + noOperTips.remove(xmQuestion.getId()); } - msgs.add(String.format("删除了%s个缺陷。",canDel.size())); + msgs.add(String.format("删除了%s个缺陷。",canOper.size())); } - if(noDel.size()>0){ + if(noOper.size()>0){ Set noDelTips2=new HashSet<>(); - for (XmQuestion xmQuestion : noDel) { - Tips tips1=noDelTips.get(xmQuestion.getId()); + for (XmQuestion xmQuestion : noOper) { + Tips tips1=noOperTips.get(xmQuestion.getId()); noDelTips2.add(tips1.getMsg()); } - msgs.add(String.format("其中%s个缺陷,无权限删除。原因【%s】",noDel.size(),noDelTips2.stream().collect(Collectors.joining(";")))); + msgs.add(String.format("其中%s个缺陷,无权限删除。原因【%s】",noOper.size(),noDelTips2.stream().collect(Collectors.joining(";")))); } - if(canDel.size()>0){ + if(canOper.size()>0){ tips.setOkMsg(msgs.stream().collect(Collectors.joining())); }else{ tips.setFailureMsg(msgs.stream().collect(Collectors.joining())); @@ -598,11 +448,109 @@ public class XmQuestionController { } m.put("tips", tips); return m; - } + } - + public void checkQx(List xmQuestionsDb, List canOper, List noOper, Map noOperTips){ + User user=LoginUtils.getCurrentUserInfo(); + /** + * 如果有测试计划,有产品编号,走产品团队判断权限 + * 如果未通过,继续走项目权限判断 + */ + Map> productsMap=new HashMap<>();//有产品的数据 + Map> projectsMap=new HashMap<>();//没有产品、但有项目的数据 + for (XmQuestion xmQuestion : xmQuestionsDb) { + if(StringUtils.hasText(xmQuestion.getProductId())){ + List datas=productsMap.get(xmQuestion.getProductId()); + if(datas==null){ + datas=new ArrayList<>(); + datas.add(xmQuestion); + productsMap.put(xmQuestion.getProductId(),datas); + }else { + datas.add(xmQuestion); + } + }else if(StringUtils.hasText(xmQuestion.getProjectId())) { + List datas=projectsMap.get(xmQuestion.getProjectId()); + if(datas==null){ + datas=new ArrayList<>(); + datas.add(xmQuestion); + projectsMap.put(xmQuestion.getProjectId(),datas); + }else { + datas.add(xmQuestion); + } + } + } + + List productNoDel=new ArrayList<>(); + if(productsMap.size()>0){ + for (String productId : productsMap.keySet()) { + XmProduct xmProduct=productService.getProductFromCache(productId); + Tips tips1=groupService.checkProductQx(xmProduct,1,user); + if(!tips1.isOk()){ + productNoDel.addAll(productsMap.get(productId)); + for (XmQuestion xmQuestion : productsMap.get(productId)) { + noOperTips.put(xmQuestion.getId(),tips1); + } + productsMap.remove(productId); + }else{ + List questions=productsMap.get(productId); + for (XmQuestion question : questions) { + tips1=groupService.checkProductQx(xmProduct,1,user,question.getCreateUserid(),question.getHandlerUserid()); + if(!tips1.isOk()){ + productNoDel.add(question); + noOperTips.put(question.getId(),tips1); + }else { + canOper.add(question); + } + } + + } + } + } + for (XmQuestion xmQuestion : productNoDel) { + if(StringUtils.hasText(xmQuestion.getProjectId())){ + List ques=projectsMap.get(xmQuestion.getProjectId()); + if(ques!=null){ + if(!ques.stream().filter(k->k.getId().equals(xmQuestion.getId())).findAny().isPresent()){ + ques.add(xmQuestion); + } + }else{ + ques=new ArrayList<>(); + ques.add(xmQuestion); + projectsMap.put(xmQuestion.getProjectId(),ques); + } + + }else{ + noOper.add(xmQuestion); + } + } + if(projectsMap.size()>0){ + for (String projectId : projectsMap.keySet()) { + XmProject xmProject=projectService.getProjectFromCache(projectId); + Tips tips1=groupService.checkProjectQx(xmProject,user); + if(!tips1.isOk()){ + noOper.addAll(projectsMap.get(projectId)); + for (XmQuestion xmQuestion : projectsMap.get(projectId)) { + noOperTips.put(xmQuestion.getId(),tips1); + } + projectsMap.remove(projectId); + }else{ + List questions=projectsMap.get(projectId); + for (XmQuestion question : questions) { + tips1=groupService.checkProjectQx(xmProject,user,question.getCreateUserid(),question.getHandlerUserid()); + if(!tips1.isOk()){ + noOper.add(question); + noOperTips.put(question.getId(),tips1); + }else { + canOper.add(question); + } + } + } + } + } + } + /** * 流程审批过程中回调该接口,更新业务数据 * 如果发起流程时上送了restUrl,则无论流程中是否配置了监听器都会在流程发生以下事件时推送数据过来 diff --git a/xm-core/src/main/java/com/xm/core/service/XmQuestionService.java b/xm-core/src/main/java/com/xm/core/service/XmQuestionService.java index 11ee92ec..5a5e5df5 100644 --- a/xm-core/src/main/java/com/xm/core/service/XmQuestionService.java +++ b/xm-core/src/main/java/com/xm/core/service/XmQuestionService.java @@ -6,18 +6,18 @@ import com.mdp.core.service.BaseService; import com.mdp.core.utils.BaseUtils; import com.mdp.safe.client.entity.User; import com.mdp.safe.client.utils.LoginUtils; +import com.xm.core.entity.XmProduct; +import com.xm.core.entity.XmProject; import com.xm.core.entity.XmQuestion; import com.xm.core.entity.XmQuestionHandle; import com.xm.core.vo.XmQuestionVo; +import org.apache.poi.ss.formula.functions.T; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * 父类已经支持增删改查操作,因此,即使本类什么也不写,也已经可以满足一般的增删改查操作了.
@@ -35,6 +35,9 @@ public class XmQuestionService extends BaseService { @Autowired XmRecordService xmRecordService; + + + /** 请在此类添加自定义函数 */ public List> getQuestion (Map params) {