package com.xzx.gc.role.service;
|
|
import com.github.pagehelper.PageHelper;
|
import com.github.pagehelper.PageInfo;
|
import com.xzx.gc.annotation.Dict;
|
import com.xzx.gc.entity.CoreDict;
|
import com.xzx.gc.entity.CoreOrg;
|
import com.xzx.gc.model.query.OrgQuery;
|
import com.xzx.gc.role.mapper.CoreOrgMapper;
|
import com.xzx.gc.role.rbac.tree.OrgItem;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.text.SimpleDateFormat;
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
*
|
* @author : xiandafu
|
*/
|
@Service
|
@Transactional
|
public class OrgConsoleService{
|
|
@Autowired
|
private CoreOrgMapper orgDao;
|
@Autowired
|
private CoreDictService dictService;
|
@Autowired
|
private CorePlatformService platformService;
|
static SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
/**
|
* 根据条件查询
|
* @param query
|
*/
|
public PageInfo<CoreOrg> queryByCondtion(OrgQuery query) {
|
|
PageHelper.startPage(query.getPage(),query.getLimit());
|
List<CoreOrg> list=orgDao.queryByCondtion(query);
|
PageInfo<CoreOrg> pageInfo=new PageInfo<>(list);
|
//queryListAfter(list);
|
OrgItem root = platformService.buildOrg();
|
//处理父机构名称显示,没有用sql查询是考虑到跨数据库
|
for(CoreOrg org:list) {
|
Long parentId = org.getParentOrgId();
|
OrgItem item = root.findChild(parentId);
|
String name = item!=null?item.getName():"";
|
String dict = dictService.findNameByType(org.getType());
|
if(null!=org.getCreateTime()){
|
org.setCreateTimeStr(sdf1.format(org.getCreateTime()));
|
|
}
|
org.setTypeText(dict);
|
org.setParentOrgText(name);
|
System.out.println(dict);
|
//org.set("parentOrgText", name);
|
}
|
|
return pageInfo;
|
}
|
|
|
|
/**
|
* 获取机构下面的所以机构
|
* @param orgId 机构id
|
*/
|
public List<Long> getAllChildIdsByOrgId(Long orgId) {
|
if (orgId == null){
|
return null;}
|
OrgItem orgItem = platformService.buildOrg().findChild(orgId);
|
if (orgItem == null) {
|
return null;
|
}
|
List<Long> ids = orgItem.findAllChildrenId();
|
if (ids == null) {
|
ids = new ArrayList<>();
|
}
|
ids.add(orgId);
|
|
return ids;
|
}
|
|
public CoreOrg queryById(Long orgId) {
|
return orgDao.selectByPrimaryKey(orgId);
|
}
|
|
public void save(CoreOrg org) {
|
orgDao.insertSelective(org);
|
}
|
|
public boolean updateTemplate(CoreOrg org) {
|
return orgDao.updateByPrimaryKeySelective(org)>0;
|
}
|
|
// public void deleteById(List<Long> idList) {
|
// orgDao.batchDelByIds(idList);
|
// }
|
|
|
/*public boolean deleteById(List<Long> ids) {
|
OrgItem root = platformService.buildOrg();
|
//检查子节点
|
|
for (Long id : ids) {
|
OrgItem child = root.findChild(id);
|
if(child != null && child.getChildren().size()!=0){
|
throw new PlatformException("不能删除 "+child.getOrg().getName()+",还包含子机构");
|
}
|
}
|
return super.deleteById(ids);
|
}*/
|
|
|
}
|