From 8726eb5cb98fe39e5110079d49841273583794ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E8=A3=95=E8=B4=A2?= Date: Mon, 21 Feb 2022 15:20:33 +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/service/XmProductService.java | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) 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 29ba235b..4b31d6fc 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 @@ -6,9 +6,12 @@ import com.mdp.safe.client.entity.User; import com.xm.core.entity.XmMenu; import com.xm.core.entity.XmProduct; import com.xm.core.entity.XmProductCopyVo; +import com.xm.core.entity.XmProject; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.StringUtils; import java.util.Date; import java.util.HashMap; @@ -55,6 +58,7 @@ public class XmProductService extends BaseService { return this.selectList("selectListMapByWhereWithState", iterationMap); } + @Transactional public XmProduct copyTo(User user, XmProductCopyVo xmProduct) { XmProduct pq=new XmProduct(); pq.setId(xmProduct.getId()); @@ -64,9 +68,12 @@ public class XmProductService extends BaseService { } XmProduct xmProductTo=new XmProduct(); BeanUtils.copyProperties(xmProductDb,xmProductTo); - xmProductTo.setId(null); + xmProductTo.setId(this.createKey("id")); xmProductTo.setProductName(xmProduct.getProductName()); xmProductTo.setCode(xmProduct.getCode()); + if(!StringUtils.hasText(xmProduct.getCode())){ + xmProductTo.setCode(createProductCode(user.getBranchId())); + } xmProductTo.setBranchId(user.getBranchId()); xmProductTo.setDeptid(user.getDeptid()); xmProductTo.setDeptName(user.getDeptName()); @@ -101,6 +108,7 @@ public class XmProductService extends BaseService { node.setCtime(new Date()); node.setMmUserid(user.getUserid()); node.setMmUsername(user.getUsername()); + node.setProductId(xmProductTo.getId()); } this.xmMenuService.parentIdPathsCalcBeforeSave(xmMenus); this.xmMenuService.doBatchInsert(xmMenus); @@ -108,5 +116,22 @@ public class XmProductService extends BaseService { } return xmProductTo; } + + public String createProductCode(String branchId){ + XmProject projectQ=new XmProject(); + projectQ.setBranchId(branchId); + long count=this.countByWhere(projectQ); + String seq=(count+1)+""; + int preLength=6-seq.length(); + + if(preLength>0){ + for (int i = 0; i < preLength; i++) { + seq="0"+seq; + } + } + String code=sequenceService.getCommonNo("pro-{date:yyyyMMdd}-"+seq+"-{rand:2}"); + return code; + + } }