From 56e467dbedd9bdf2cf85756571b7099d96eef51d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E8=A3=95=E8=B4=A2?= Date: Sat, 12 Mar 2022 13:30:51 +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 --- .../com/xm/core/ctrl/XmProductController.java | 22 +++++++++++++++++-- .../com/xm/core/service/XmProductService.java | 12 ++++++++++ .../java/com/xm/core/vo/XmProductAddVo.java | 19 ++++++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 xm-core/src/main/java/com/xm/core/vo/XmProductAddVo.java diff --git a/xm-core/src/main/java/com/xm/core/ctrl/XmProductController.java b/xm-core/src/main/java/com/xm/core/ctrl/XmProductController.java index 9e73fd19..f8da4849 100644 --- a/xm-core/src/main/java/com/xm/core/ctrl/XmProductController.java +++ b/xm-core/src/main/java/com/xm/core/ctrl/XmProductController.java @@ -11,9 +11,11 @@ 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.XmProductCopyVo; +import com.xm.core.entity.XmProductProjectLink; import com.xm.core.service.XmProductService; import com.xm.core.service.XmGroupService; import com.xm.core.service.XmRecordService; +import com.xm.core.vo.XmProductAddVo; import io.swagger.annotations.*; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -218,7 +220,7 @@ public class XmProductController { }) @HasQx(value = "xm_core_xmProduct_add",name = "创建产品/战略规划等",categoryId = "admin-xm",categoryName = "管理端-项目管理系统") @RequestMapping(value="/add",method=RequestMethod.POST) - public Map addXmProduct(@RequestBody XmProduct xmProduct) { + public Map addXmProduct(@RequestBody XmProductAddVo xmProduct) { Map m = new HashMap<>(); Tips tips=new Tips("成功新增一条数据"); try{ @@ -235,6 +237,13 @@ public class XmProductController { return m; } } + if(xmProduct.getLinks()!=null && xmProduct.getLinks().size()>0){ + for (XmProductProjectLink link : xmProduct.getLinks()) { + if(!StringUtils.hasText(link.getProjectId())) { + return ResponseHelper.failed("projectId-0", "", "关联项目编号不能为空"); + } + } + } if(!StringUtils.hasText(xmProduct.getProductName())){ return ResponseHelper.failed("productName-0","","产品名称不能为空"); } @@ -252,7 +261,16 @@ public class XmProductController { xmProduct.setPstatus("0"); xmProduct.setDel("0"); xmProduct.setLocked("0"); - xmProductService.insert(xmProduct); + if(xmProduct.getLinks()!=null && xmProduct.getLinks().size()>0){ + for (XmProductProjectLink link : xmProduct.getLinks()) { + link.setProductId(xmProduct.getId()); + link.setCusername(user.getUsername()); + link.setCuserid(user.getUserid()); + link.setLinkStatus("1"); + link.setCtime(new Date()); + } + } + xmProductService.addProduct(xmProduct); xmRecordService.addXmProductRecord(xmProduct.getId(),"创建产品","创建产品【"+xmProduct.getId()+"】【"+xmProduct.getProductName()+"】"); m.put("data",xmProduct); diff --git a/xm-core/src/main/java/com/xm/core/service/XmProductService.java b/xm-core/src/main/java/com/xm/core/service/XmProductService.java index cdc9d0c8..d37e4889 100644 --- a/xm-core/src/main/java/com/xm/core/service/XmProductService.java +++ b/xm-core/src/main/java/com/xm/core/service/XmProductService.java @@ -5,6 +5,7 @@ import com.mdp.core.service.BaseService; import com.mdp.safe.client.entity.User; import com.xm.core.entity.*; import com.xm.core.service.cache.XmProductCacheService; +import com.xm.core.vo.XmProductAddVo; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -47,6 +48,9 @@ public class XmProductService extends BaseService { @Autowired XmPhaseService xmProjectPhaseService; + @Autowired + XmProductProjectLinkService linkService; + /** @@ -288,5 +292,13 @@ public class XmProductService extends BaseService { this.xmMenuService.doBatchDeleteByProductIds(canDelList.stream().map(i->i.getId()).collect(Collectors.toList())); super.batchDelete(canDelList); } + + @Transactional + public void addProduct(XmProductAddVo xmProduct) { + super.insert(xmProduct); + if(xmProduct.getLinks()!=null && xmProduct.getLinks().size()>0){ + linkService.batchInsert(xmProduct.getLinks()); + } + } } diff --git a/xm-core/src/main/java/com/xm/core/vo/XmProductAddVo.java b/xm-core/src/main/java/com/xm/core/vo/XmProductAddVo.java new file mode 100644 index 00000000..d3300898 --- /dev/null +++ b/xm-core/src/main/java/com/xm/core/vo/XmProductAddVo.java @@ -0,0 +1,19 @@ +package com.xm.core.vo; + +import com.xm.core.entity.XmProduct; +import com.xm.core.entity.XmProductProjectLink; + +import java.util.List; + +public class XmProductAddVo extends XmProduct { + + List links; + + public List getLinks() { + return links; + } + + public void setLinks(List links) { + this.links = links; + } +}