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 2b557704..69066cff 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 @@ -259,14 +259,14 @@ public class XmProductController { return ResponseHelper.failed("id-0","","产品编号不能为空"); } User user=LoginUtils.getCurrentUserInfo(); - XmProduct xmProductDb=xmProductService.selectOneObject(new XmProduct(xmProduct.getId())); + XmProduct xmProductDb=xmProductService.getProductFromCache(xmProduct.getId()); if(xmProductDb==null){ return ResponseHelper.failed("data-0","产品已不存在"); }else if(!"0".equals(xmProductDb.getPstatus())&&!"3".equals(xmProductDb.getPstatus())){ return ResponseHelper.failed("pstatus-not-0-3","该产品不是初始、已关闭状态,不允许删除"); }else if(!user.getBranchId().equals(xmProductDb.getBranchId())){ return ResponseHelper.failed("branchId-not-right","该产品不属于您所在的机构,不允许删除"); - }else if(!user.getUserid().equals(xmProductDb.getPmUserid()) && !user.getUserid().equals(xmProductDb.getAssistantUserid())){ + }else if(!user.getUserid().equals(xmProductDb.getPmUserid()) && !user.getUserid().equals(xmProductDb.getAssUserid())){ return ResponseHelper.failed("pmUserid-not-right","您不是该产品产品负责人,也不是产品助理,不允许删除"); } if(!"1".equals(xmProductDb.getIsTpl())){ @@ -277,6 +277,7 @@ public class XmProductController { } } xmProductService.doDeleteByPk(xmProduct); + xmProductService.clearCache(xmProduct.getId()); }catch (BizException e) { tips=e.getTips(); logger.error("",e); @@ -301,6 +302,7 @@ public class XmProductController { Tips tips=new Tips("成功更新一条数据"); try{ xmProductService.updateByPk(xmProduct); + xmProductService.clearCache(xmProduct.getId()); m.put("data",xmProduct); }catch (BizException e) { tips=e.getTips(); @@ -345,7 +347,7 @@ public class XmProductController { otips.setFailureMsg("pstatus-not-0-3","产品【"+xmProductDb.getProductName()+"】不是初始、已关闭状态,不允许删除"); }else if(!user.getBranchId().equals(xmProductDb.getBranchId())){ otips.setFailureMsg("branchId-not-right","产品【"+xmProductDb.getProductName()+"】不属于您所在的机构,不允许删除"); - }else if(!user.getUserid().equals(xmProductDb.getPmUserid()) && !user.getUserid().equals(xmProductDb.getAssistantUserid())){ + }else if(!user.getUserid().equals(xmProductDb.getPmUserid()) && !user.getUserid().equals(xmProductDb.getAssUserid())){ otips.setFailureMsg("pmUserid-not-right","您不是产品【"+xmProductDb.getProductName()+"】负责人,也不是产品助理,不允许删除"); }else{ if(!"1".equals(xmProductDb.getIsTpl())){ @@ -364,6 +366,9 @@ public class XmProductController { } if(canDelList.size()>0) { xmProductService.doBatchDelete(canDelList); + for (XmProduct xmProduct : canDelList) { + xmProductService.clearCache(xmProduct.getId()); + } } String msg="成功删除"+canDelList.size()+"条产品信息"; if(canDelList.size()==xmProducts.size()){ 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 253fe8a9..7021202d 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 @@ -7,6 +7,7 @@ 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 com.xm.core.service.cache.XmProductCacheService; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -34,6 +35,9 @@ public class XmProductService extends BaseService { @Autowired XmMenuService xmMenuService; + + @Autowired + XmProductCacheService xmProductCacheService; /** * 产品不直接根项目关联,此函数作废了 * @param productId @@ -48,7 +52,19 @@ public class XmProductService extends BaseService { p.setProductId(productId); return xmMenuService.countByWhere(p); } - + public XmProduct getProductFromCache(String productId) { + XmProduct productCahce=xmProductCacheService.getProduct(productId); + if(productCahce==null) { + productCahce = this.selectOneObject(new XmProduct(productId)); + xmProductCacheService.putProduct(productId, productCahce); + return productCahce; + } + return productCahce; + } + public void clearCache(String productId){ + xmProductCacheService.clear(productId); + } + /** * 连同产品关联的状态数据一起带出 * @param iterationMap @@ -85,8 +101,8 @@ public class XmProductService extends BaseService { xmProductTo.setCtime(new Date()); xmProductTo.setPstatus("0"); xmProductTo.setIsTpl(xmProduct.getIsTpl()); - xmProductTo.setAssistantUserid(user.getUserid()); - xmProductTo.setAssistantUsername(user.getUsername()); + xmProductTo.setAssUserid(user.getUserid()); + xmProductTo.setAssUsername(user.getUsername()); if(xmProduct.getProductName().equals(xmProductDb.getProductName())){ xmProductTo.setProductName(xmProduct.getProductName()+"(复制)"); } diff --git a/xm-core/src/main/java/com/xm/core/service/cache/XmProductCacheService.java b/xm-core/src/main/java/com/xm/core/service/cache/XmProductCacheService.java new file mode 100644 index 00000000..38e0f13a --- /dev/null +++ b/xm-core/src/main/java/com/xm/core/service/cache/XmProductCacheService.java @@ -0,0 +1,63 @@ +package com.xm.core.service.cache; + +import com.xm.core.entity.XmProduct; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Service; + +import java.util.Calendar; +import java.util.List; +import java.util.Map; +import java.util.concurrent.TimeUnit; + +@Service +public class XmProductCacheService { + + @Autowired + RedisTemplate redisTemplate; + String currDateKey=""; + public String getKey(){ + Calendar currCal=Calendar.getInstance(); + String dateKey=currCal.get(Calendar.YEAR)+"-"+currCal.get(Calendar.DAY_OF_YEAR); + if(dateKey.equals(currDateKey)){ + return this.getCacheKey()+":"+dateKey; + }else { + currDateKey=dateKey; + this.redisTemplate.expire(this.getCacheKey()+":"+dateKey,24,TimeUnit.HOURS); + return this.getCacheKey()+":"+dateKey; + } + } + String getCacheKey() { + return "xm_product"; + } + public void putProduct(String productId,XmProduct Product){ + String key=this.getKey(); + String hashKey=productId; + redisTemplate.opsForHash().put(key, hashKey, Product); + } + + public XmProduct getProduct(String productId){ + String key=this.getKey(); + String hashKey=productId; + return (XmProduct) redisTemplate.opsForHash().get(key, hashKey); + + } + + public void clear(String productId){ + String key=this.getKey(); + redisTemplate.opsForHash().delete(key,productId); + } + + public void putPortalProductStates(List> products){ + String key=this.getKey(); + String hashKey="portal"; + redisTemplate.opsForHash().put(key, hashKey, products); + } + + public List> getPortalProductStates(){ + String key=this.getKey(); + String hashKey="portal"; + return (List>) redisTemplate.opsForHash().get(key, hashKey); + + } +} diff --git a/xm-core/src/main/java/com/xm/core/service/cache/XmProjectCacheService.java b/xm-core/src/main/java/com/xm/core/service/cache/XmProjectCacheService.java index a4f47c94..6fdf9e5d 100644 --- a/xm-core/src/main/java/com/xm/core/service/cache/XmProjectCacheService.java +++ b/xm-core/src/main/java/com/xm/core/service/cache/XmProjectCacheService.java @@ -31,27 +31,27 @@ public class XmProjectCacheService { return "xm_project"; } public void putProject(String projectId,XmProject Project){ - String key=this.getKey()+"_"+projectId; - String hashKey=key; + String key=this.getKey(); + String hashKey=projectId; redisTemplate.opsForHash().put(key, hashKey, Project); } public XmProject getProject(String projectId){ - String key=this.getKey()+"_"+projectId; - String hashKey=key; + String key=this.getKey(); + String hashKey=projectId; return (XmProject) redisTemplate.opsForHash().get(key, hashKey); } public void putPortalProjectStates(List> projects){ - String key=this.getKey()+"_"+"portal"; - String hashKey=key; + String key=this.getKey(); + String hashKey="portal"; redisTemplate.opsForHash().put(key, hashKey, projects); } public List> getPortalProjectStates(){ - String key=this.getKey()+"_"+"portal"; - String hashKey=key; + String key=this.getKey(); + String hashKey="portal"; return (List>) redisTemplate.opsForHash().get(key, hashKey); } diff --git a/xm-core/src/main/java/com/xm/core/service/cache/XmProjectGroupCacheService.java b/xm-core/src/main/java/com/xm/core/service/cache/XmProjectGroupCacheService.java index 635f3d6a..cf07d6fd 100644 --- a/xm-core/src/main/java/com/xm/core/service/cache/XmProjectGroupCacheService.java +++ b/xm-core/src/main/java/com/xm/core/service/cache/XmProjectGroupCacheService.java @@ -7,6 +7,7 @@ import org.springframework.stereotype.Service; import java.util.Calendar; import java.util.List; +import java.util.Set; import java.util.concurrent.TimeUnit; @Service @@ -15,44 +16,112 @@ public class XmProjectGroupCacheService { @Autowired RedisTemplate redisTemplate; - String currDateKey=""; - public String getKey(){ + String currPrdDateKey=""; + public String getProductKey(String productId){ Calendar currCal=Calendar.getInstance(); - String dateKey=currCal.get(Calendar.YEAR)+"-"+currCal.get(Calendar.DAY_OF_YEAR); - if(dateKey.equals(currDateKey)){ - return this.getCacheKey()+":"+dateKey; + String dateKey=currCal.get(Calendar.YEAR)+"-"+currCal.get(Calendar.DAY_OF_YEAR)+"_prd"; + String finalKey=this.getCacheKey()+":"+dateKey+":"+productId; + if(dateKey.equals(currPrdDateKey)){ + return finalKey; }else { - currDateKey=dateKey; - this.redisTemplate.expire(this.getCacheKey()+":"+dateKey,24,TimeUnit.HOURS); - return this.getCacheKey()+":"+dateKey; + currPrdDateKey=dateKey; + this.redisTemplate.expire(finalKey,24,TimeUnit.HOURS); + return finalKey; + } + } + String currPrjDateKey=""; + public String getProjectKey(String projectId){ + Calendar currCal=Calendar.getInstance(); + String dateKey=currCal.get(Calendar.YEAR)+"-"+currCal.get(Calendar.DAY_OF_YEAR)+"_prj"; + String finalKey=this.getCacheKey()+":"+dateKey+":"+projectId; + if(dateKey.equals(currPrjDateKey)){ + return finalKey; + }else { + currPrjDateKey=dateKey; + this.redisTemplate.expire(finalKey,24,TimeUnit.HOURS); + return finalKey; } } - String getCacheKey() { return "xm_project_group"; - } - public void putProjectGroups(String projectId,List groups){ - String key=this.getKey()+"_prj_"+projectId; - String hashKey=key; - redisTemplate.opsForHash().put(key, hashKey, groups); } - + public List getProjectGroups(String projectId){ - String key=this.getKey()+"_"+projectId; - String hashKey=key; - return (List) redisTemplate.opsForHash().get(key, hashKey); - + String key=this.getProjectKey(projectId); + return (List) redisTemplate.opsForHash().values(key); + + } + public XmProjectGroupVo getProjectGroup(String projectId,String groupId){ + String key=this.getProjectKey(projectId); + return (XmProjectGroupVo) redisTemplate.opsForHash().get(key,groupId); + } + public void putProjectGroup(XmProjectGroupVo group){ + String key=this.getProjectKey(group.getProjectId()); + redisTemplate.opsForHash().put(key, group.getId(), group); } + + /** + * + * @param projectId + * @param groupId + */ + public void clearProjectGroup(String projectId,String groupId){ + String key=this.getProjectKey(projectId); + this.clearProjectGroups(projectId); + } + public void putProjectGroups(String projectId,List groups){ + String key=this.getProjectKey(projectId); + if(groups==null || groups.size()==0){ + this.clearProjectGroups(projectId); + return; + } + for (XmProjectGroupVo group : groups) { + String hashKey= group.getId(); + redisTemplate.opsForHash().put(key, hashKey, group); + } + } + public void clearProjectGroups(String projectId){ + String key=this.getProjectKey(projectId); + Set keySet=redisTemplate.opsForHash().keys(key); + if(keySet!=null && keySet.size()>0){ + redisTemplate.opsForHash().delete(key,keySet.toArray()); + } + } + public List getProductGroups(String productId){ - String key=this.getKey()+"_pro_"+productId; - String hashKey=key; - return (List) redisTemplate.opsForHash().get(key, hashKey); + String key=this.getProductKey(productId); + return (List) redisTemplate.opsForHash().values(key); } + public XmProjectGroupVo getProductGroup(String productId,String groupId){ + String key=this.getProductKey(productId); + return (XmProjectGroupVo) redisTemplate.opsForHash().get(key,groupId); + } + public void putProductGroup(XmProjectGroupVo group){ + String key=this.getProductKey(group.getProductId()); + redisTemplate.opsForHash().put(key, group.getId(), group); + } + public void clearProductGroup(String productId,String groupId){ + String key=this.getProductKey(productId); + this.clearProductGroups(productId); + } public void putProductGroups(String productId,List groups){ - String key=this.getKey()+"_pro_"+productId; - String hashKey=key; - redisTemplate.opsForHash().put(key, hashKey, groups); + String key=this.getProductKey(productId); + if(groups==null || groups.size()==0){ + this.clearProductGroups(productId); + return; + } + for (XmProjectGroupVo group : groups) { + String hashKey= group.getId(); + redisTemplate.opsForHash().put(key, hashKey, group); + } + } + public void clearProductGroups(String productId){ + String key=this.getProductKey(productId); + Set keySet=redisTemplate.opsForHash().keys(key); + if(keySet!=null && keySet.size()>0){ + redisTemplate.opsForHash().delete(key,keySet.toArray()); + } } } diff --git a/xm-core/src/main/java/com/xm/core/service/cache/XmTaskCacheService.java b/xm-core/src/main/java/com/xm/core/service/cache/XmTaskCacheService.java index 2bba223a..958f8d90 100644 --- a/xm-core/src/main/java/com/xm/core/service/cache/XmTaskCacheService.java +++ b/xm-core/src/main/java/com/xm/core/service/cache/XmTaskCacheService.java @@ -34,14 +34,14 @@ public class XmTaskCacheService { return "xm_task"; } public void putTasks(String queryKeys, PageSerializable> tasks){ - String key=this.getKey()+"_"+queryKeys; - String hashKey=key; + String key=this.getKey(); + String hashKey=queryKeys; redisTemplate.opsForHash().put(key, hashKey, tasks); } public PageSerializable> getTasks(String queryKeys){ - String key=this.getKey()+"_"+queryKeys; - String hashKey=key; + String key=this.getKey(); + String hashKey=queryKeys; return (PageSerializable>) redisTemplate.opsForHash().get(key, hashKey); }