package com.ld.igds.sys.service;
|
|
import com.bstek.bdf2.core.model.Url;
|
import com.bstek.bdf2.core.orm.hibernate.HibernateDao;
|
import com.ld.igds.constant.Constant;
|
import org.hibernate.Session;
|
import org.springframework.stereotype.Component;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
@Component
|
public class SysUrlService extends HibernateDao {
|
|
public List<Url> getAll(String companyId) {
|
String hql = " from " + Url.class.getName()
|
+ " where companyId=:companyId";
|
Map<String, Object> args = new HashMap<String, Object>();
|
args.put("companyId", companyId);
|
return this.query(hql, args);
|
}
|
|
/**
|
* 菜单copy
|
*
|
* @param sourceId
|
* 源ID
|
* @param targetId
|
* @return
|
*/
|
public String copy2Target(String sourceId, String targetId, String model) {
|
if (sourceId.equals(targetId)) {
|
return "不支持相同组织编码复制!";
|
}
|
|
// 目標下已有菜单,取消复制
|
List<Url> list = getAll(targetId);
|
if (null != list && list.size() > 0) {
|
return null;
|
}
|
|
// 源菜单
|
list = getAll(sourceId);
|
if (null == list || list.isEmpty())
|
return null;
|
|
Session session = this.getSessionFactory().openSession();
|
try {
|
for (Url url : list) {
|
|
if (url.getName().indexOf("多组织") >= 0) {
|
continue;
|
}
|
//根据选中的模块生成菜单
|
if("all".equals(model)){
|
//多功能模块,生成全部菜单
|
if (url.getId().startsWith(sourceId)) {
|
url.setId(url.getId().replace(sourceId, targetId));
|
} else {
|
url.setId(targetId + "-" + url.getId().substring(4));
|
}
|
|
if (null != url.getParentId()) {
|
if (url.getParentId().startsWith(sourceId)) {
|
url.setParentId(url.getParentId().replace(sourceId,
|
targetId));
|
} else {
|
url.setParentId(targetId + "-" + url.getParentId().substring(4));
|
}
|
}
|
|
url.setCompanyId(targetId);
|
session.saveOrUpdate(url);
|
}else {
|
|
//单功能模块,只生成对应模块菜单和系统模块菜单(且系统模块菜单标记成对应模块)
|
if(model.equals(url.getSystemId()) || Constant.MODEL_SYS.equals(url.getSystemId()) || Constant.MODEL_GROUP.equals(url.getSystemId())){
|
if (url.getId().startsWith(sourceId)) {
|
url.setId(url.getId().replace(sourceId, targetId));
|
} else {
|
url.setId(targetId + "-" + url.getId().substring(4));
|
}
|
|
if (null != url.getParentId()) {
|
if (url.getParentId().startsWith(sourceId)) {
|
url.setParentId(url.getParentId().replace(sourceId,
|
targetId));
|
} else {
|
url.setParentId(targetId + "-" + url.getParentId().substring(4));
|
}
|
}
|
|
//将系统模块标记到选中模块中
|
if(Constant.MODEL_SYS.equals(url.getSystemId())){
|
url.setSystemId(model);
|
}
|
|
url.setCompanyId(targetId);
|
session.saveOrUpdate(url);
|
}
|
}
|
}
|
} finally {
|
session.flush();
|
session.close();
|
}
|
|
return null;
|
}
|
|
}
|