fix
Helius
2021-12-08 2ff788504ed25ed15d75047afb16f058b655eeb6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
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);
    }*/
 
 
}