From 71e96d3c1ab3e575e7bf4896c1bcf123e5fcd340 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E8=A3=95=E8=B4=A2?= Date: Wed, 23 Feb 2022 17:36:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=8A=82=E7=82=B9=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E3=80=81=E6=A0=87=E7=AD=BE=E7=AD=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/ctrl/XmProjectGroupController.java | 2 + .../ctrl/XmProjectGroupUserController.java | 102 +++++++++++++----- .../core/service/XmProjectGroupService.java | 65 +++++++++++ .../com/xm/core/vo/XmProjectGroupUserVo.java | 39 +++++++ 4 files changed, 180 insertions(+), 28 deletions(-) create mode 100644 xm-core/src/main/java/com/xm/core/vo/XmProjectGroupUserVo.java diff --git a/xm-core/src/main/java/com/xm/core/ctrl/XmProjectGroupController.java b/xm-core/src/main/java/com/xm/core/ctrl/XmProjectGroupController.java index aad51d54..0438ea72 100644 --- a/xm-core/src/main/java/com/xm/core/ctrl/XmProjectGroupController.java +++ b/xm-core/src/main/java/com/xm/core/ctrl/XmProjectGroupController.java @@ -12,6 +12,7 @@ import com.mdp.safe.client.utils.LoginUtils; import com.xm.core.entity.XmProduct; import com.xm.core.entity.XmProject; import com.xm.core.entity.XmProjectGroup; +import com.xm.core.entity.XmProjectGroupUser; import com.xm.core.service.XmProductService; import com.xm.core.service.XmProjectGroupService; import com.xm.core.service.XmProjectService; @@ -122,6 +123,7 @@ public class XmProjectGroupController { xmProjectGroupCacheService.clearProjectGroup(groupDb.getProjectId(),groupDb.getId()); } + m.put("tips", tips); return m; } diff --git a/xm-core/src/main/java/com/xm/core/ctrl/XmProjectGroupUserController.java b/xm-core/src/main/java/com/xm/core/ctrl/XmProjectGroupUserController.java index 7a6b8789..e0e2e1ff 100644 --- a/xm-core/src/main/java/com/xm/core/ctrl/XmProjectGroupUserController.java +++ b/xm-core/src/main/java/com/xm/core/ctrl/XmProjectGroupUserController.java @@ -1,19 +1,29 @@ package com.xm.core.ctrl; import com.mdp.core.entity.Tips; +import com.mdp.core.err.BizException; import com.mdp.core.utils.RequestUtils; +import com.mdp.core.utils.ResponseHelper; import com.mdp.mybatis.PageUtils; +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.XmProjectGroup; import com.xm.core.entity.XmProjectGroupUser; +import com.xm.core.service.XmProductService; +import com.xm.core.service.XmProjectGroupService; import com.xm.core.service.XmProjectGroupUserService; +import com.xm.core.service.XmProjectService; +import com.xm.core.vo.XmProjectGroupUserVo; +import com.xm.core.vo.XmProjectGroupVo; import io.swagger.annotations.*; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.util.StringUtils; +import org.springframework.web.bind.annotation.*; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -38,8 +48,17 @@ public class XmProjectGroupUserController { @Autowired private XmProjectGroupUserService xmProjectGroupUserService; - - + + + @Autowired + private XmProjectService xmProjectService; + + + @Autowired + private XmProductService xmProductService; + + @Autowired + XmProjectGroupService xmProjectGroupService; @ApiOperation( value = "查询xm_project_group_user信息列表",notes="listXmProjectGroupUser,条件之间是 and关系,模糊查询写法如 {studentName:'%才哥%'}") @@ -78,30 +97,64 @@ public class XmProjectGroupUserController { } - - /** + @ApiOperation( value = "新增一条xm_project_group_user信息",notes="addXmProjectGroupUser,主键如果为空,后台自动生成") @ApiResponses({ @ApiResponse(code = 200,response=XmProjectGroupUser.class,message = "{tips:{isOk:true/false,msg:'成功/失败原因',tipscode:'失败时错误码'},data:数据对象}") }) @RequestMapping(value="/add",method=RequestMethod.POST) - public Map addXmProjectGroupUser(@RequestBody XmProjectGroupUser xmProjectGroupUser) { + public Map addXmProjectGroupUser(@RequestBody XmProjectGroupUserVo xmProjectGroupUser) { Map m = new HashMap<>(); Tips tips=new Tips("成功新增一条数据"); try{ - if(StringUtils.isEmpty(xmProjectGroupUser.getId())) { - xmProjectGroupUser.setId(xmProjectGroupUserService.createKey("id")); + + if(!StringUtils.hasText(xmProjectGroupUser.getGroupId())||!StringUtils.hasText(xmProjectGroupUser.getUserid())){ + return ResponseHelper.failed("pk-0","请上送小组编号,用户编号groupId,userid"); + } + if(!StringUtils.hasText(xmProjectGroupUser.getPgClass())){ + return ResponseHelper.failed("pgClass-0","请上送小组类型pgClass"); + } + String pgClass=xmProjectGroupUser.getPgClass(); + User user=LoginUtils.getCurrentUserInfo(); + if("1".equals(pgClass)){ + + if(!StringUtils.hasText(xmProjectGroupUser.getProductId())){ + return ResponseHelper.failed("productId-0","请上送小组归属产品编号"); + } + XmProduct xmProduct=this.xmProductService.getProductFromCache(xmProjectGroupUser.getProductId()); + if(xmProduct==null){ + return ResponseHelper.failed("product-0","产品已不存在"); + } + if(!xmProjectGroupService.checkUserIsProductAdm(xmProduct, user.getUserid())){ + XmProjectGroupVo xmProjectGroupVo=this.xmProjectGroupService.getProductGroupFromCache(xmProduct.getId(),xmProjectGroupUser.getGroupId()); + if(xmProjectGroupVo==null){ + return ResponseHelper.failed("group-0","小组已不存在"); + } + xmProjectGroupService.checkUserIsTeamHeadOrAss(null,user.getUserid()); + } }else{ - XmProjectGroupUser xmProjectGroupUserQuery = new XmProjectGroupUser(xmProjectGroupUser.getId()); - if(xmProjectGroupUserService.countByWhere(xmProjectGroupUserQuery)>0){ - tips.setFailureMsg("编号重复,请修改编号再提交"); - m.put("tips", tips); - return m; + if(!StringUtils.hasText(xmProjectGroupUser.getProjectId())){ + return ResponseHelper.failed("projectId-0","请上送小组归属项目编号"); } } + + if(xmProjectGroupUserService.countByWhere(xmProjectGroupUser)>0){ + tips.setFailureMsg("该用户已在小组中"); + m.put("tips", tips); + return m; + } + + this.xmProjectGroupService.checkUserIsProjectAdm(); xmProjectGroupUserService.insert(xmProjectGroupUser); + Map usermap=new HashMap<>(); + usermap.put("userid", xmProjectGroupUser.getUserid()); + usermap.put("username", xmProjectGroupUser.getUsername()); + List> users=new ArrayList<>(); + users.add(usermap); + pushMsgService.pushJoinChannelGroupMsg(user.getBranchId(), u.getGroupId(), users); + xmRecordService.addXmGroupRecord(projectId,xmProjectGroupUser.getGroupId(), "项目-团队-新增小组成员", "增加组员["+u.getUsername()+"]",u.getUserid(),null); m.put("data",xmProjectGroupUser); - }catch (BizException e) { + }catch (BizException e) { tips=e.getTips(); logger.error("",e); }catch (Exception e) { @@ -111,9 +164,7 @@ public class XmProjectGroupUserController { m.put("tips", tips); return m; } - */ - - /** + @ApiOperation( value = "删除一条xm_project_group_user信息",notes="delXmProjectGroupUser,仅需要上传主键字段") @ApiResponses({ @ApiResponse(code = 200, message = "{tips:{isOk:true/false,msg:'成功/失败原因',tipscode:'失败时错误码'}}") @@ -134,9 +185,7 @@ public class XmProjectGroupUserController { m.put("tips", tips); return m; } - */ - - /** + @ApiOperation( value = "根据主键修改一条xm_project_group_user信息",notes="editXmProjectGroupUser") @ApiResponses({ @ApiResponse(code = 200,response=XmProjectGroupUser.class, message = "{tips:{isOk:true/false,msg:'成功/失败原因',tipscode:'失败时错误码'},data:数据对象}") @@ -158,11 +207,9 @@ public class XmProjectGroupUserController { m.put("tips", tips); return m; } - */ - - /** + @ApiOperation( value = "根据主键列表批量删除xm_project_group_user信息",notes="batchDelXmProjectGroupUser,仅需要上传主键字段") @ApiResponses({ @ApiResponse(code = 200, message = "{tips:{isOk:true/false,msg:'成功/失败原因',tipscode:'失败时错误码'}") @@ -182,6 +229,5 @@ public class XmProjectGroupUserController { } m.put("tips", tips); return m; - } - */ + } } diff --git a/xm-core/src/main/java/com/xm/core/service/XmProjectGroupService.java b/xm-core/src/main/java/com/xm/core/service/XmProjectGroupService.java index ad8f788c..73411b79 100644 --- a/xm-core/src/main/java/com/xm/core/service/XmProjectGroupService.java +++ b/xm-core/src/main/java/com/xm/core/service/XmProjectGroupService.java @@ -92,6 +92,50 @@ public class XmProjectGroupService extends BaseService { } } + + public boolean checkUserIsProjectAdm(XmProject xmProject,String userid){ + if(xmProject==null){ + return false; + } + Map map=this.getProjectAdmUsers(xmProject); + if(map.containsKey(userid)){ + return true; + } + return false; + } + public boolean checkUserIsProjectAdm(String projectId,String userid){ + XmProject xmProject=xmProjectService.getProjectFromCache(projectId); + if(xmProject==null){ + return false; + } + Map map=this.getProjectAdmUsers(xmProject); + if(map.containsKey(userid)){ + return true; + } + return false; + } + + public boolean checkUserIsProductAdm(XmProduct xmProduct,String userid){ + if(xmProduct==null){ + return false; + } + Map map=this.getProductAdmUsers(xmProduct); + if(map.containsKey(userid)){ + return true; + } + return false; + } + public boolean checkUserIsProductAdm(String productId,String userid){ + XmProduct xmProduct=xmProductService.getProductFromCache(productId); + if(xmProduct==null){ + return false; + } + Map map=this.getProductAdmUsers(xmProduct); + if(map.containsKey(userid)){ + return true; + } + return false; + } public List getProductGroupVoList(String productId) { List groupVoList=new ArrayList<>(); List groupVoList2 = groupCacheService.getProductGroups(productId); @@ -813,5 +857,26 @@ public class XmProjectGroupService extends BaseService { super.batchDelete(canDelNodes); batchSumParents(canDelNodes); } + + public XmProjectGroupVo getProductGroupFromCache(String productId, String groupId) { + XmProjectGroupVo groupVo=groupCacheService.getProductGroup(productId,groupId); + if(groupVo==null){ + XmProjectGroup group=this.selectOneObject(new XmProjectGroup(groupId)); + if(group==null){ + return null; + }else{ + XmProjectGroupUser xmProjectGroupUser=new XmProjectGroupUser(); + xmProjectGroupUser.setGroupId(groupId); + List users=this.xmProjectGroupUserService.selectListByWhere(xmProjectGroupUser); + XmProjectGroupVo xmProjectGroupVo=new XmProjectGroupVo(); + BeanUtils.copyProperties(group,xmProjectGroupVo); + xmProjectGroupVo.setGroupUsers(users); + this.groupCacheService.putProductGroup(xmProjectGroupVo); + return xmProjectGroupVo; + } + }else { + return groupVo; + } + } } diff --git a/xm-core/src/main/java/com/xm/core/vo/XmProjectGroupUserVo.java b/xm-core/src/main/java/com/xm/core/vo/XmProjectGroupUserVo.java new file mode 100644 index 00000000..818e2075 --- /dev/null +++ b/xm-core/src/main/java/com/xm/core/vo/XmProjectGroupUserVo.java @@ -0,0 +1,39 @@ +package com.xm.core.vo; + +import com.xm.core.entity.XmProjectGroupUser; + +public class XmProjectGroupUserVo extends XmProjectGroupUser { + + String pgClass; + + String projectId; + + + String productId; + + public String getPgClass() { + return pgClass; + } + + public void setPgClass(String pgClass) { + this.pgClass = pgClass; + } + + public String getProjectId() { + return projectId; + } + + public void setProjectId(String projectId) { + this.projectId = projectId; + } + + public String getProductId() { + return productId; + } + + public void setProductId(String productId) { + this.productId = productId; + } + + +}