futian.liu
2023-12-02 8e41786892a4bd7cff2d63bde8cb0636cdb0650c
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
package com.consum.base.service.impl;
 
import com.consum.base.pojo.FinSysServerSearchParam;
import com.consum.base.pojo.FinSysServerVo;
import com.consum.base.service.FinSysServerService;
import com.consum.model.po.FinSysServer;
import com.iplatform.model.po.S_role;
import com.walker.db.page.GenericPager;
import com.walker.jdbc.service.BaseServiceImpl;
import com.walker.jdbc.util.StringUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.springframework.stereotype.Service;
 
@Service
public class FinSysServerServiceImpl extends BaseServiceImpl implements FinSysServerService {
 
    private static final String SELECT_TREE_ALL = "select * from FIN_SYS_SERVER";
    private static final String SELECT_CHILD_BY_ID = "select * from FIN_SYS_SERVER where 1=1";
 
    // private static final String S
 
    /**
     * 查询所有服务目录
     *
     * @return
     * @date 2023-07-11
     */
    public List<FinSysServerVo> queryAllCategory() {
        List<FinSysServer> finSysCategories = this.select(SELECT_TREE_ALL, new Object[]{}, new FinSysServer());
        List<FinSysServerVo> result = null;
        if (finSysCategories != null) {
            List<FinSysServerVo> finSysCategoryVos = finSysCategories.stream().map(category -> {
                FinSysServerVo finSysCategoryVo = new FinSysServerVo();
                // BeanUtils.copyProperties(category, finSysCategoryVo);
                finSysCategoryVo.setId(category.getId());
                finSysCategoryVo.setLabel(category.getName());
                finSysCategoryVo.setParentId(category.getParentId());
                return finSysCategoryVo;
            }).collect(Collectors.toList());
            result = finSysCategoryVos.stream().filter(c -> c.getParentId() == 0).map(tree -> {
                tree.setChildren(getChildren(tree, finSysCategoryVos));
                return tree;
            }).collect(Collectors.toList());
        }
        return result;
    }
 
    private List<FinSysServerVo> getChildren(FinSysServerVo tree, List<FinSysServerVo> finSysCategoryVos) {
        return finSysCategoryVos.stream().filter(c -> c.getParentId() == tree.getId()).map(m -> {
            m.setChildren(getChildren(m, finSysCategoryVos));
            return m;
        }).collect(Collectors.toList());
    }
 
    /**
     * 根据id查询当下菜单所属子菜单
     */
    public List<FinSysServer> findChildById(Long parentId) {
        List<FinSysServer> children = this.select(SELECT_CHILD_BY_ID, new Object[]{parentId}, new FinSysServer());
        return children;
    }
 
    /**
     * 分页查询
     *
     * @param param
     * @return
     */
    public GenericPager<FinSysServer> selectServerListByPage(FinSysServerSearchParam param) {
        Map<String, Object> parameter = new HashMap();
        StringBuilder sql = new StringBuilder(SELECT_CHILD_BY_ID);
        if (param.getName() != null && StringUtils.isNotEmpty(param.getName())) {
            sql.append(" and NAME like :name");
            parameter.put("name", StringUtils.CHAR_PERCENT + param.getName() + StringUtils.CHAR_PERCENT);
        }
        if (param.getParentId() != null) {
            sql.append(" and PARENT_ID = :parentId");
            parameter.put("parentId", param.getParentId());
        }
        return this.selectSplit(sql.toString(), parameter, new FinSysServer());
 
    }
 
    /**
     * @Description 根据DataScope查询信息
     * @Author wh
     * @Date 2023/9/13 9:35
     */
    public List<S_role> getByDataScope(Integer dataScope) {
        Map<String, Object> parameter = new HashMap();
        String sql = "SELECT * FROM S_ROLE sr WHERE status=0 and  DATA_SCOPE = :dataScope";
        parameter.put("dataScope", dataScope);
        return this.select(sql.toString(), parameter, new S_role());
    }
}