Browse Source

添加节点类型、标签等

master
陈裕财 4 years ago
parent
commit
94f3bfdee7
  1. 11
      xm-core/src/main/java/com/xm/core/ctrl/XmProductController.java
  2. 20
      xm-core/src/main/java/com/xm/core/service/XmProductService.java
  3. 63
      xm-core/src/main/java/com/xm/core/service/cache/XmProductCacheService.java
  4. 16
      xm-core/src/main/java/com/xm/core/service/cache/XmProjectCacheService.java
  5. 115
      xm-core/src/main/java/com/xm/core/service/cache/XmProjectGroupCacheService.java
  6. 8
      xm-core/src/main/java/com/xm/core/service/cache/XmTaskCacheService.java

11
xm-core/src/main/java/com/xm/core/ctrl/XmProductController.java

@ -259,14 +259,14 @@ public class XmProductController {
return ResponseHelper.failed("id-0","","产品编号不能为空"); return ResponseHelper.failed("id-0","","产品编号不能为空");
} }
User user=LoginUtils.getCurrentUserInfo(); User user=LoginUtils.getCurrentUserInfo();
XmProduct xmProductDb=xmProductService.selectOneObject(new XmProduct(xmProduct.getId()));
XmProduct xmProductDb=xmProductService.getProductFromCache(xmProduct.getId());
if(xmProductDb==null){ if(xmProductDb==null){
return ResponseHelper.failed("data-0","产品已不存在"); return ResponseHelper.failed("data-0","产品已不存在");
}else if(!"0".equals(xmProductDb.getPstatus())&&!"3".equals(xmProductDb.getPstatus())){ }else if(!"0".equals(xmProductDb.getPstatus())&&!"3".equals(xmProductDb.getPstatus())){
return ResponseHelper.failed("pstatus-not-0-3","该产品不是初始、已关闭状态,不允许删除"); return ResponseHelper.failed("pstatus-not-0-3","该产品不是初始、已关闭状态,不允许删除");
}else if(!user.getBranchId().equals(xmProductDb.getBranchId())){ }else if(!user.getBranchId().equals(xmProductDb.getBranchId())){
return ResponseHelper.failed("branchId-not-right","该产品不属于您所在的机构,不允许删除"); 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","您不是该产品产品负责人,也不是产品助理,不允许删除"); return ResponseHelper.failed("pmUserid-not-right","您不是该产品产品负责人,也不是产品助理,不允许删除");
} }
if(!"1".equals(xmProductDb.getIsTpl())){ if(!"1".equals(xmProductDb.getIsTpl())){
@ -277,6 +277,7 @@ public class XmProductController {
} }
} }
xmProductService.doDeleteByPk(xmProduct); xmProductService.doDeleteByPk(xmProduct);
xmProductService.clearCache(xmProduct.getId());
}catch (BizException e) { }catch (BizException e) {
tips=e.getTips(); tips=e.getTips();
logger.error("",e); logger.error("",e);
@ -301,6 +302,7 @@ public class XmProductController {
Tips tips=new Tips("成功更新一条数据"); Tips tips=new Tips("成功更新一条数据");
try{ try{
xmProductService.updateByPk(xmProduct); xmProductService.updateByPk(xmProduct);
xmProductService.clearCache(xmProduct.getId());
m.put("data",xmProduct); m.put("data",xmProduct);
}catch (BizException e) { }catch (BizException e) {
tips=e.getTips(); tips=e.getTips();
@ -345,7 +347,7 @@ public class XmProductController {
otips.setFailureMsg("pstatus-not-0-3","产品【"+xmProductDb.getProductName()+"】不是初始、已关闭状态,不允许删除"); otips.setFailureMsg("pstatus-not-0-3","产品【"+xmProductDb.getProductName()+"】不是初始、已关闭状态,不允许删除");
}else if(!user.getBranchId().equals(xmProductDb.getBranchId())){ }else if(!user.getBranchId().equals(xmProductDb.getBranchId())){
otips.setFailureMsg("branchId-not-right","产品【"+xmProductDb.getProductName()+"】不属于您所在的机构,不允许删除"); 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()+"】负责人,也不是产品助理,不允许删除"); otips.setFailureMsg("pmUserid-not-right","您不是产品【"+xmProductDb.getProductName()+"】负责人,也不是产品助理,不允许删除");
}else{ }else{
if(!"1".equals(xmProductDb.getIsTpl())){ if(!"1".equals(xmProductDb.getIsTpl())){
@ -364,6 +366,9 @@ public class XmProductController {
} }
if(canDelList.size()>0) { if(canDelList.size()>0) {
xmProductService.doBatchDelete(canDelList); xmProductService.doBatchDelete(canDelList);
for (XmProduct xmProduct : canDelList) {
xmProductService.clearCache(xmProduct.getId());
}
} }
String msg="成功删除"+canDelList.size()+"条产品信息"; String msg="成功删除"+canDelList.size()+"条产品信息";
if(canDelList.size()==xmProducts.size()){ if(canDelList.size()==xmProducts.size()){

20
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.XmProduct;
import com.xm.core.entity.XmProductCopyVo; import com.xm.core.entity.XmProductCopyVo;
import com.xm.core.entity.XmProject; import com.xm.core.entity.XmProject;
import com.xm.core.service.cache.XmProductCacheService;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -34,6 +35,9 @@ public class XmProductService extends BaseService {
@Autowired @Autowired
XmMenuService xmMenuService; XmMenuService xmMenuService;
@Autowired
XmProductCacheService xmProductCacheService;
/** /**
* 产品不直接根项目关联此函数作废了 * 产品不直接根项目关联此函数作废了
* @param productId * @param productId
@ -48,6 +52,18 @@ public class XmProductService extends BaseService {
p.setProductId(productId); p.setProductId(productId);
return xmMenuService.countByWhere(p); 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);
}
/** /**
* 连同产品关联的状态数据一起带出 * 连同产品关联的状态数据一起带出
@ -85,8 +101,8 @@ public class XmProductService extends BaseService {
xmProductTo.setCtime(new Date()); xmProductTo.setCtime(new Date());
xmProductTo.setPstatus("0"); xmProductTo.setPstatus("0");
xmProductTo.setIsTpl(xmProduct.getIsTpl()); 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())){ if(xmProduct.getProductName().equals(xmProductDb.getProductName())){
xmProductTo.setProductName(xmProduct.getProductName()+"(复制)"); xmProductTo.setProductName(xmProduct.getProductName()+"(复制)");
} }

63
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<Map<String,Object>> products){
String key=this.getKey();
String hashKey="portal";
redisTemplate.opsForHash().put(key, hashKey, products);
}
public List<Map<String,Object>> getPortalProductStates(){
String key=this.getKey();
String hashKey="portal";
return (List<Map<String,Object>>) redisTemplate.opsForHash().get(key, hashKey);
}
}

16
xm-core/src/main/java/com/xm/core/service/cache/XmProjectCacheService.java

@ -31,27 +31,27 @@ public class XmProjectCacheService {
return "xm_project"; return "xm_project";
} }
public void putProject(String projectId,XmProject 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); redisTemplate.opsForHash().put(key, hashKey, Project);
} }
public XmProject getProject(String projectId){ 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); return (XmProject) redisTemplate.opsForHash().get(key, hashKey);
} }
public void putPortalProjectStates(List<Map<String,Object>> projects){ public void putPortalProjectStates(List<Map<String,Object>> projects){
String key=this.getKey()+"_"+"portal";
String hashKey=key;
String key=this.getKey();
String hashKey="portal";
redisTemplate.opsForHash().put(key, hashKey, projects); redisTemplate.opsForHash().put(key, hashKey, projects);
} }
public List<Map<String,Object>> getPortalProjectStates(){ public List<Map<String,Object>> getPortalProjectStates(){
String key=this.getKey()+"_"+"portal";
String hashKey=key;
String key=this.getKey();
String hashKey="portal";
return (List<Map<String,Object>>) redisTemplate.opsForHash().get(key, hashKey); return (List<Map<String,Object>>) redisTemplate.opsForHash().get(key, hashKey);
} }

115
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.Calendar;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@Service @Service
@ -15,44 +16,112 @@ public class XmProjectGroupCacheService {
@Autowired @Autowired
RedisTemplate redisTemplate; RedisTemplate redisTemplate;
String currDateKey="";
public String getKey(){
String currPrdDateKey="";
public String getProductKey(String productId){
Calendar currCal=Calendar.getInstance(); 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 { }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() { String getCacheKey() {
return "xm_project_group"; return "xm_project_group";
} }
public void putProjectGroups(String projectId,List<XmProjectGroupVo> groups){
String key=this.getKey()+"_prj_"+projectId;
String hashKey=key;
redisTemplate.opsForHash().put(key, hashKey, groups);
}
public List<XmProjectGroupVo> getProjectGroups(String projectId){ public List<XmProjectGroupVo> getProjectGroups(String projectId){
String key=this.getKey()+"_"+projectId;
String hashKey=key;
return (List<XmProjectGroupVo>) redisTemplate.opsForHash().get(key, hashKey);
String key=this.getProjectKey(projectId);
return (List<XmProjectGroupVo>) 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<XmProjectGroupVo> 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<String> keySet=redisTemplate.opsForHash().keys(key);
if(keySet!=null && keySet.size()>0){
redisTemplate.opsForHash().delete(key,keySet.toArray());
}
}
public List<XmProjectGroupVo> getProductGroups(String productId){ public List<XmProjectGroupVo> getProductGroups(String productId){
String key=this.getKey()+"_pro_"+productId;
String hashKey=key;
return (List<XmProjectGroupVo>) redisTemplate.opsForHash().get(key, hashKey);
String key=this.getProductKey(productId);
return (List<XmProjectGroupVo>) 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<XmProjectGroupVo> groups){ public void putProductGroups(String productId,List<XmProjectGroupVo> 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<String> keySet=redisTemplate.opsForHash().keys(key);
if(keySet!=null && keySet.size()>0){
redisTemplate.opsForHash().delete(key,keySet.toArray());
}
} }
} }

8
xm-core/src/main/java/com/xm/core/service/cache/XmTaskCacheService.java

@ -34,14 +34,14 @@ public class XmTaskCacheService {
return "xm_task"; return "xm_task";
} }
public void putTasks(String queryKeys, PageSerializable<Map<String,Object>> tasks){ public void putTasks(String queryKeys, PageSerializable<Map<String,Object>> tasks){
String key=this.getKey()+"_"+queryKeys;
String hashKey=key;
String key=this.getKey();
String hashKey=queryKeys;
redisTemplate.opsForHash().put(key, hashKey, tasks); redisTemplate.opsForHash().put(key, hashKey, tasks);
} }
public PageSerializable<Map<String,Object>> getTasks(String queryKeys){ public PageSerializable<Map<String,Object>> getTasks(String queryKeys){
String key=this.getKey()+"_"+queryKeys;
String hashKey=key;
String key=this.getKey();
String hashKey=queryKeys;
return (PageSerializable<Map<String,Object>>) redisTemplate.opsForHash().get(key, hashKey); return (PageSerializable<Map<String,Object>>) redisTemplate.opsForHash().get(key, hashKey);
} }

Loading…
Cancel
Save