Commit 6f3dd1bd authored by zhengjiangtao's avatar zhengjiangtao

修改数据隔离

parent b593c33a
......@@ -11,6 +11,7 @@ import java.util.stream.Collectors;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
......@@ -37,6 +38,8 @@ import com.yeejoin.amos.op.core.jpa.GenericManagerImpl;
import com.yeejoin.amos.spc.business.remote.RemoteSecurityService;
import com.yeejoin.amos.spc.business.remote.RemoteWebSocketServer;
import fr.opensagres.xdocreport.template.velocity.internal.Foreach;
/**
* 拓扑图service
*
......@@ -44,6 +47,15 @@ import com.yeejoin.amos.spc.business.remote.RemoteWebSocketServer;
*/
@Service
public class TopographyServiceImpl extends GenericManagerImpl<TopographyTree, String> implements ITopographyService {
//平台字典管理中配置value为key值
private static final String BNAK_ORG_KEY = "BANK_ORG";
//平台字典管理中配置value为key值
private static final String BNAK_XIAN_KEY = "xian";
//平台字典管理中配置value为key值
private static final String BNAK_KEJICHU_KEY = "科技处";
@Autowired
private ITopographyTreeRepository iTopographyTreeDao;
......@@ -73,7 +85,12 @@ public class TopographyServiceImpl extends GenericManagerImpl<TopographyTree, St
@Override
public List<TopographyTreeDTO> getTree(String orgcode,int type) {
List<TopographyTreeDTO> list = iTopographyTreeDao.findByTypeAndOrgCode(type,orgcode).stream().map(t -> convert(t)).collect(Collectors.toList());
boolean judgeDeviceAuth = JudgeDeviceAuth(list,orgcode);
if(false == judgeDeviceAuth) {
return new ArrayList<TopographyTreeDTO>();
}
Map<String, TopographyTreeDTO> map = list.stream().collect(Collectors.toMap(n -> n.getId(), n -> n));
list.forEach(n -> {
if (n.getParent() != null) {
......@@ -90,6 +107,7 @@ public class TopographyServiceImpl extends GenericManagerImpl<TopographyTree, St
topographyTreeDTO.setParent(node.getParentCode());
topographyTreeDTO.setTreeCode(node.getTreeCode());
topographyTreeDTO.setGroup(node.getGroup());
topographyTreeDTO.setOrgCode(node.getOrgCode());
return topographyTreeDTO;
}
......@@ -144,10 +162,10 @@ public class TopographyServiceImpl extends GenericManagerImpl<TopographyTree, St
@Override
public String getSelfOrgCode() {
List<DictionarieValueModel> listDictionaryByDictCode = remoteSecurityService.listDictionaryByDictCode("BANK_ORG");
List<DictionarieValueModel> listDictionaryByDictCode = remoteSecurityService.listDictionaryByDictCode(BNAK_ORG_KEY);
StringBuffer sb = new StringBuffer();
listDictionaryByDictCode.forEach(e ->{
if("xian".equals(e.getDictDataKey())||"kejichu".equals(e.getDictDataKey())) {
if(BNAK_XIAN_KEY.equals(e.getDictDataKey())||BNAK_KEJICHU_KEY.equals(e.getDictDataKey())) {
sb.append('#').append(e.getDictDataValue());
}
});
......@@ -375,5 +393,77 @@ public class TopographyServiceImpl extends GenericManagerImpl<TopographyTree, St
}
}
/**
* 判断该用户登选择公司有无查看该拓扑的权限
* @param list
* @param userOrgCode
* @return
*/
private boolean JudgeDeviceAuth(List<TopographyTreeDTO> list, String orgCode) {
String userOrgCode = null;
if(orgCode.startsWith("%#")) {
userOrgCode = truncateHeadString(orgCode,2);
}else {
userOrgCode = orgCode;
}
for (TopographyTreeDTO topographyTreeDTO : list) {
if (!StringUtils.isEmpty(topographyTreeDTO.getOrgCode())) {
if (topographyTreeDTO.getOrgCode().contains("#")) {
String[] array = topographyTreeDTO.getOrgCode().split("#");
for (int i = 0; i < array.length; i++) {
String str = array[i];
if(str.contains("-")) {
String[] split = str.split("-");
for (int j = 0; j < split.length; j++) {
if (userOrgCode.equals(split[j])) {
return true;
}
}
} else {
if(userOrgCode.equals(str)) {
return true;
}
}
}
} else {
String[] arr = topographyTreeDTO.getOrgCode().split("-");
for (int i = 0; i < arr.length; i++) {
if (userOrgCode.equals(arr[i])) {
return true;
}
}
}
}
}
return false;
}
/**
* 去除字符串前n个字符
* @param origin 要操作的字符串
* @param count 去掉字符串的数量
* @return
*/
public static String truncateHeadString(String origin, int count) {
if (origin == null || origin.length() < count) {
return null;
}
char[] arr = origin.toCharArray();
char[] ret = new char[arr.length - count];
for (int i = 0; i < ret.length; i++) {
ret[i] = arr[i + count];
}
return String.copyValueOf(ret);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment