许鹏程
2023-05-18 d3cbcd265d0ee70eca677972403afcff1a0fc990
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
package com.product.admin.service;
 
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Sets;
import com.product.admin.config.CmnConst;
import com.product.admin.config.SystemCode;
import com.product.common.lang.StringUtils;
import com.product.core.cache.DataPoolCacheImpl;
import com.product.core.dao.BaseDao;
import com.product.core.entity.DataTableEntity;
import com.product.core.entity.FieldSetEntity;
import com.product.core.exception.BaseException;
import com.product.core.service.support.AbstractBaseService;
import com.product.core.service.support.QueryFilterService;
import com.product.core.spring.context.SpringMVCContextHolder;
import com.product.module.sys.entity.SystemUser;
import com.product.util.BaseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import java.util.*;
 
/**
 * Copyright  LX-BASE
 *
 * @Title: PagesService
 * @Project: LX-BASE-SERVER
 * @Date: 2021-03-16 09:36
 * @Author: ZhouJie
 * @Description: 栏目配置
 */
@Component
public class PagesService extends AbstractBaseService {
 
    @Autowired
    public BaseDao baseDao;
 
    @Autowired
    private QueryFilterService queryFilterService;
 
    /**
     * 获取所有公司的公司角色树 只适用于超级管理员
     *
     * @return
     */
    public Object getCompanyRoleTree() {
        SystemUser user = SpringMVCContextHolder.getCurrentUser();
        if (user != null && 1 == user.getUserType()) {
            //查出所有公司的角色
            StringBuilder sql = new StringBuilder();
            sql.append(" SELECT ");
            sql.append(" a.*, ");
            sql.append(" a.uuid org_level_code_parent ");
            sql.append(" FROM ");
            sql.append(" ( ");
            sql.append(" SELECT ");
            sql.append(" ( SELECT org_level_code FROM product_sys_org_levels WHERE uuid = a.org_level_uuid ) uuid, ");
            sql.append(" uuid role_uuid, ");
            sql.append(" role_name, ");
            sql.append(" 1 type,( ");
            sql.append(" SELECT ");
            sql.append(" uuid()) org_level_code ");
            sql.append(" FROM ");
            sql.append(" product_sys_role a ");
            sql.append(" WHERE ");
            sql.append(" is_used = 1 ");
            sql.append(" AND org_level_uuid !=? ");
            sql.append(" AND length( org_level_uuid )> 0 ");
            sql.append(" ORDER BY org_level_uuid,sequence ");
            sql.append(" ) a ");
            DataTableEntity dt = baseDao.listTable(sql.toString(), new Object[]{CmnConst.PRODUCT_SYS_ORG_CLIENT_UUID_VALUE});
            if (!BaseUtil.dataTableIsEmpty(dt)) {
                DataPoolCacheImpl dataPoolCache = DataPoolCacheImpl.getInstance();
                Map<Object, List<FieldSetEntity>> fieldSets = dt.getFieldSets();
                Set<Object> companyCodes = fieldSets.keySet();
                Set<String> paramCode = Sets.newHashSet();
                companyCodes.forEach(org_level_code -> {
                    String code = String.valueOf(org_level_code);
                    paramCode.add(code);
                    while (code.indexOf('-') > -1) {
                        paramCode.add(code = code.substring(0, code.lastIndexOf('-')));
                    }
                });
                paramCode.forEach(code -> {
                    DataTableEntity companyDt = dataPoolCache.getCacheData("所有公司信息", new String[]{code});
                    dt.getData().addAll(companyDt.clones().getData());
                });
                dt.setData(dt.getData());
                //根据编码长度排序
                dt.getData().sort((a, b) -> {
                    return a.getString(CmnConst.ORG_LEVEL_CODE).compareTo(b.getString(CmnConst.ORG_LEVEL_CODE));
                });
                return BaseUtil.dataTableToTreeData(dt, CmnConst.ORG_LEVEL_CODE, CmnConst.ORG_LEVEL_CODE_PARENT, object -> {
                    JSONObject jsonObject = object[0];
                    if (jsonObject.getString("type") != null) {
                        jsonObject.put(CmnConst.UUID, jsonObject.getString(CmnConst.ROLE_UUID));
                    }
                }, false);
            }
        }
        return null;
    }
 
    /**
     * @Date: 2020-03-22 10:03
     * @Author: ZhouJie
     * @Description: 查询栏目类型列表
     */
    public DataTableEntity getPageListPagetype(FieldSetEntity fs) throws BaseException {
        StringBuilder sql = new StringBuilder();
        sql.append(" select page_type FROM product_sys_portal_column_config group by page_type ");
        DataTableEntity dt = baseDao.listTable(sql.toString(), new Object[]{});
        return dt;
    }
 
    /**
     * @Date: 2020-03-19 17:03
     * @Author: ZhouJie
     * @Description: 按照栏目类型查询栏目配置列表
     */
    public DataTableEntity getPageListByPagetype(FieldSetEntity fs) throws BaseException {
        String columnType = fs.getString(CmnConst.COLUMN_TYPE);
        StringBuilder filter = new StringBuilder(32);
        if (!StringUtils.isEmpty(columnType)) {
            for (String singleColumnType : columnType.split(",")) {
                if (filter.length() > 0) {
                    filter.append(" or ");
                }
                if (filter.length() == 0) {
                    filter.append("(");
                }
                filter.append("find_in_set('").append(singleColumnType).append("',column_type)");
            }
        }
        if (filter.length() > 0) {
            filter.append(") and ");
        }
        filter.append("is_use=1");
        DataTableEntity dt = baseDao.listTable(CmnConst.PRODUCT_SYS_PORTAL_COLUMN_CONFIG, filter.toString(), null, null, null, Integer.MAX_VALUE, 0);
        return dt;
    }
 
    /**
     * @Date: 2020-03-18 09:58
     * @Author: ZhouJie
     * @Description: 栏目配置列表查询
     */
    public DataTableEntity getPageList(FieldSetEntity fs) throws BaseException {
        String queryFilter = queryFilterService.getQueryFilter(fs);
        DataTableEntity dt = baseDao.listTable(CmnConst.PRODUCT_SYS_PORTAL_COLUMN_CONFIG, queryFilter, null, null, null, fs.getInteger(CmnConst.PAGESIZE), fs.getInteger(CmnConst.CPAGE));
        baseDao.loadPromptData(dt);
        return dt;
    }
 
    /**
     * @Date: 2020-03-18 10:44
     * @Author: ZhouJie
     * @Description: 栏目配置详情查询
     */
    public FieldSetEntity getPageInfo(FieldSetEntity fs) throws BaseException {
        FieldSetEntity fss = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_PORTAL_COLUMN_CONFIG, fs.getUUID(), false);
        FieldSetEntity fsrc = null;
        FieldSetEntity fsmp = null;
        if (fss.getInteger("page_type") == 1) {
            fsrc = baseDao.getFieldSetEntityByFilter("product_sys_report_config", CmnConst.UUID + "=?", new Object[]{fss.getString("data_source")}, false);
        }
        if (fss.getInteger("page_type") == 2) {
            fsrc = baseDao.getFieldSetEntityByFilter("product_sys_report_config", CmnConst.UUID + "=?", new Object[]{fss.getString("data_source")}, false);
        }
        if (fsrc != null) {
            fsmp = baseDao.getFieldSetEntityByFilter("product_sys_mvc_page", "function_uuid = ?", new Object[]{fsrc.getString("function_uuid")}, false);
            if (fsmp != null) {
                fss.setValue("link_address", fsmp.getString("page_url"));
            }
        }
        return fss;
        //return baseDao.listInternationDataTable(baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_PORTAL_COLUMN_CONFIG, fs.getString(CmnConst.UUID), true),null);
    }
 
    /**
     * @Date: 2020-03-16 14:59
     * @Author: ZhouJie
     * @Description: 新增栏目配置
     */
    public String addPage(FieldSetEntity fs) throws BaseException {
        //判断标题名称是否为空,为空则默认栏目名称
        if (StringUtils.isEmpty(fs.getString("title_name"))) {
            fs.setValue("title_name", fs.getString("page_name"));
        }
        //fs.setValue(CmnConst.CREATED_BY, SpringMVCContextHolder.getCurrentUser().getUser_id());
        fs.setValue(CmnConst.CREATED_BY, 1);
        fs.setValue(CmnConst.CREATED_UTC_DATETIME, new Date());
        return baseDao.add(fs);
    }
 
    /**
     * @Date: 2020-03-16 15:44
     * @Author: ZhouJie
     * @Description: 修改栏目配置
     */
    public boolean updatePage(FieldSetEntity fs) throws BaseException {
        //判断标题名称是否为空,为空则默认栏目名称
        if (StringUtils.isEmpty(fs.getString("title_name"))) {
            fs.setValue("title_name", fs.getString("page_name"));
        }
        //fs.setValue(CmnConst.UPDATED_BY, SpringMVCContextHolder.getCurrentUser().getUser_id());
        fs.setValue(CmnConst.UPDATED_BY, 1);
        fs.setValue(CmnConst.UPDATED_UTC_DATETIME, new Date());
        return baseDao.update(fs);
    }
 
    /**
     * @Date: 2020-03-16 16:30
     * @Author: ZhouJie
     * @Description: 删除栏目配置
     */
    public boolean deletePage(FieldSetEntity fs) throws BaseException {
        String sql="select 1 FROM product_sys_portals_sub where page_uuid=? limit 1";
        FieldSetEntity fseprotal=baseDao.getFieldSetBySQL(sql, new Object[] {fs.getUUID()}, false);
        if (fseprotal!=null) {
            throw new BaseException(SystemCode.PAGES_HAS_REFERED.getValue(), SystemCode.PAGES_HAS_REFERED.getText());
        }
        return baseDao.delete(CmnConst.PRODUCT_SYS_PORTAL_COLUMN_CONFIG, fs.getUUID().split(","));
    }
}