shicf
2025-03-11 c25682f5868858e91bf5f04e4e56208e4bed6152
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
package com.product.mobile.core.service;
 
import cn.hutool.core.io.FileUtil;
import com.product.common.lang.StringUtils;
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.file.service.FileManagerService;
import com.product.mobile.core.config.MobileCoreCode;
import com.product.mobile.core.config.MobileCoreConst;
import com.product.mobile.core.entity.NavBarEntity;
import com.product.mobile.core.service.ide.INavBarManagerService;
import com.product.module.sys.entity.SystemUser;
import com.product.util.BaseUtil;
import com.product.util.sf.img4.util.ImageUtil;
import org.apache.commons.codec.binary.Base64;
import org.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.*;
 
/**
 * @Author cheng
 * @Date 2022/2/22 17:58
 * @Desc 导航栏管理实现
 */
@Service
public class NavBarManagerService extends AbstractBaseService implements INavBarManagerService {
 
    @Autowired
    QueryFilterService queryFilterService;
 
    /**
     * 配置列表
     *
     * @param fse
     * @return
     * @throws BaseException
     */
    @Override
    public DataTableEntity listConfig(FieldSetEntity fse) throws BaseException {
        String queryFilter = queryFilterService.getQueryFilter(fse);
        StringBuilder sql = new StringBuilder();
        sql.append(" SELECT module_category,count(function_uuid) function_count ")
                .append(" from product_sys_app_nav_bar a  ")
                .append(" group by module_category,module_sequence order by module_sequence");
        if (!StringUtils.isEmpty(queryFilter)) {
            sql.insert(0, " SELECT * FROM (");
            sql.append(") a WHERE ").append(queryFilter);
        }
        return getBaseDao().listTable(sql.toString(),
                new Object[]{}, fse.getInteger(MobileCoreConst.PAGESIZE), fse.getInteger(MobileCoreConst.CPAGE));
    }
 
    /**
     * 配置详情
     *
     * @param fse
     * @return
     * @throws BaseException
     */
    @Override
    public FieldSetEntity findConfig(FieldSetEntity fse) throws BaseException {
        String module_category = fse.getString(MobileCoreConst.MODULE_CATEGORY);
        if (!StringUtils.isEmpty(module_category)) {
            DataTableEntity dt = getBaseDao().listTable(MobileCoreConst.TABLE_NAV_BAR, "module_category=?", new Object[]{module_category});
            if (!DataTableEntity.isEmpty(dt)) {
                fse = new FieldSetEntity();
                fse.setTableName(MobileCoreConst.TABLE_NAV_BAR);
                fse.setValue(MobileCoreConst.MODULE_CATEGORY, module_category);
                fse.setValue(MobileCoreConst.MODULE_SEQUENCE, dt.getString(0, MobileCoreConst.MODULE_SEQUENCE));
                fse.addSubDataTable(dt);
                return fse;
            }
        }
        throw new BaseException(MobileCoreCode.FIND_NAV_BAR_CONFIG_FAIL);
    }
 
    /**
     * 保存配置
     *
     * @param fse
     * @return
     * @throws BaseException
     */
    @Override
    public void saveConfig(FieldSetEntity fse) throws BaseException {
        DataTableEntity subDataTable = fse.getSubDataTable(MobileCoreConst.TABLE_NAV_BAR);
        if (DataTableEntity.isEmpty(subDataTable)) {
            throw new BaseException(MobileCoreCode.SAVE_NAV_BAR_CONFIG_FAIL);
        }
        BaseUtil.createCreatorAndCreationTime(fse);
        for (int i = 0; i < subDataTable.getRows(); i++) {
            subDataTable.setFieldValue(i, MobileCoreConst.MODULE_CATEGORY, fse.getString(MobileCoreConst.MODULE_CATEGORY));
            subDataTable.setFieldValue(i, MobileCoreConst.MODULE_SEQUENCE, fse.getString(MobileCoreConst.MODULE_SEQUENCE));
            subDataTable.setFieldValue(i, MobileCoreConst.UPDATED_BY, fse.getString(MobileCoreConst.UPDATED_BY));
            subDataTable.setFieldValue(i, MobileCoreConst.CREATED_BY, fse.getString(MobileCoreConst.CREATED_BY));
            subDataTable.setFieldValue(i, MobileCoreConst.UPDATED_UTC_DATETIME, fse.getString(MobileCoreConst.UPDATED_UTC_DATETIME));
            subDataTable.setFieldValue(i, MobileCoreConst.CREATED_UTC_DATETIME, fse.getString(MobileCoreConst.CREATED_UTC_DATETIME));
        }
        getBaseDao().update(subDataTable);
    }
 
    /**
     * 删除配置
     *
     * @param fse
     * @throws BaseException
     */
    @Override
    public void delConfig(FieldSetEntity fse) throws BaseException {
        getBaseDao().delete(fse.getTableName(), "module_category = ?", new Object[]{fse.getString(MobileCoreConst.MODULE_CATEGORY)});
    }
 
    @Autowired
    FileManagerService fileManagerService;
 
    /**
     * 移动端获取导航栏(展示跳转)
     *
     * @return
     * @throws BaseException
     */
    @Override
    public List<Object> getNarBarTree() throws BaseException {
        SystemUser currentUser = SpringMVCContextHolder.getCurrentUser();
        if (currentUser == null) {
            return null;
        }
        StringBuilder sql = new StringBuilder();
        sql.append(" SELECT ");
        sql.append(" a.function_uuid, ");
        sql.append(" a.nav_bar_img, ");
        sql.append(" a.nav_bar_name, ");
        sql.append(" a.module_category, ");
        sql.append(" b.route_name, ");
        sql.append(" concat( '/', b.uuid ) path, ");
        sql.append(" a.uuid, ");
        sql.append(" a.sequence,a.module_sequence ");
        sql.append(" FROM ");
        sql.append(" product_sys_app_nav_bar a ");
        sql.append(" JOIN product_sys_functions c ON a.function_uuid = c.uuid ");
        sql.append(" AND c.status_uuid = 1 ");
        sql.append(" and c.function_type_uuid=1 ");
        sql.append(" AND concat( ',', c.client_type_uuid, ',' ) LIKE '%,App,%' ");
        sql.append(" JOIN product_sys_function_buttons b ON a.function_uuid = b.function_uuid ");
        sql.append(" AND b.button_type = 1 ");
        sql.append(" AND b.is_main = 1 ");
        sql.append(" AND b.client_type_uuid = 'App' ");
        sql.append(" JOIN product_sys_function_permission permission ON concat( ',', permission.button_uuid, ',' ) LIKE concat( ',%', b.uuid, '%,' ) ");
        sql.append(" JOIN product_sys_role role on role.uuid=permission.role_uuid and role.is_used=1 ");
        //使用角色做功能权限限制
        sql.append(" and ").append(BaseUtil.buildQuestionMarkFilter("role.uuid", currentUser.getRoles().split(","), true));
        sql.append(" GROUP BY a.function_uuid, ");
        sql.append(" a.nav_bar_img, ");
        sql.append(" a.nav_bar_name, ");
        sql.append(" a.module_category, ");
        sql.append(" a.uuid ,");
        sql.append(" concat( '/', b.uuid ) ,");
        sql.append(" a.sequence, ");
        sql.append(" b.route_name,a.module_sequence ");
        sql.append(" order by a.module_sequence,a.sequence");
        DataTableEntity dt = getBaseDao().listTable(sql.toString(), new Object[]{});
        if (!DataTableEntity.isEmpty(dt)) {
            Map<String, List<NavBarEntity>> map = new LinkedHashMap<>();
            for (int i = 0; i < dt.getRows(); i++) {
                String module_name = dt .getString(i, MobileCoreConst.MODULE_CATEGORY);
                List<NavBarEntity> navBarEntities = map.get(module_name);
                if (navBarEntities == null) {
                    navBarEntities = new ArrayList<>();
                    map.put(module_name, navBarEntities);
                }
                String file_uuid = dt.getString(i, MobileCoreConst.NAV_BAR_IMG);
                try {
                    String bytes = null;
                    byte[] fileContent = fileManagerService.getFileContent(file_uuid);
                    if (fileContent != null && fileContent.length > 0) {
                        bytes = Base64.encodeBase64String(fileContent);
                    }
                    dt.setFieldValue(i, MobileCoreConst.NAV_BAR_IMG, bytes);
                } catch (Exception e) {
                    dt.setFieldValue(i, MobileCoreConst.NAV_BAR_IMG, null);
                }
                navBarEntities.add(new NavBarEntity(dt.getFieldSetEntity(i)));
 
            }
            List<Object> list = new ArrayList<>();
            map.forEach((k, v) -> {
                Map<String, Object> m = new HashMap<>();
                m.put("name", k);
                m.put("functions", v);
                list.add(m);
            });
            return list;
        }
        return null;
    }
    /**
     * 设备管理
     * 移动端获取导航栏(展示跳转)
     *
     * @return
     * @throws BaseException
     */
    @Override
    public List<Object> getDeviceNarBarTree() throws BaseException {
        SystemUser currentUser = SpringMVCContextHolder.getCurrentUser();
        if (currentUser == null) {
            return null;
        }
        StringBuilder sql = new StringBuilder();
        sql.append(" SELECT ");
        sql.append(" a.function_uuid, ");
        sql.append(" a.nav_bar_img, ");
        sql.append(" a.nav_bar_name, ");
        sql.append(" a.module_category, ");
        sql.append(" b.route_name, ");
        sql.append(" concat( '/', b.uuid ) path, ");
        sql.append(" a.uuid, ");
        sql.append(" a.sequence,a.module_sequence ");
        sql.append(" FROM ");
        sql.append(" product_sys_app_nav_bar a ");
        sql.append(" JOIN product_sys_functions c ON a.function_uuid = c.uuid ");
        sql.append(" AND c.status_uuid = 1 ");
        sql.append(" and c.function_type_uuid=1 ");
        sql.append(" AND concat( ',', c.client_type_uuid, ',' ) LIKE '%,App,%' ");
        sql.append(" JOIN product_sys_function_buttons b ON a.function_uuid = b.function_uuid ");
        sql.append(" AND b.button_type = 1 ");
        sql.append(" AND b.is_main = 1 ");
        sql.append(" AND b.client_type_uuid = 'App' ");
        sql.append(" JOIN product_sys_function_permission permission ON concat( ',', permission.button_uuid, ',' ) LIKE concat( ',%', b.uuid, '%,' ) ");
        sql.append(" JOIN product_sys_role role on role.uuid=permission.role_uuid and role.is_used=1 ");
        //使用角色做功能权限限制
        sql.append(" and ").append(BaseUtil.buildQuestionMarkFilter("role.uuid", currentUser.getRoles().split(","), true));
        //添加设备管理模块过滤条件
        //sql.append(" and a.module_category='设备管理' ");
        
        sql.append(" GROUP BY a.function_uuid, ");
        sql.append(" a.nav_bar_img, ");
        sql.append(" a.nav_bar_name, ");
        sql.append(" a.module_category, ");
        sql.append(" a.uuid ,");
        sql.append(" concat( '/', b.uuid ) ,");
        sql.append(" a.sequence, ");
        sql.append(" b.route_name,a.module_sequence ");
        sql.append(" order by a.module_sequence,a.sequence");
        DataTableEntity dt = getBaseDao().listTable(sql.toString(), new Object[]{});
        if (!DataTableEntity.isEmpty(dt)) {
            Map<String, List<NavBarEntity>> map = new LinkedHashMap<>();
            for (int i = 0; i < dt.getRows(); i++) {
                String module_name = dt .getString(i, MobileCoreConst.MODULE_CATEGORY);
                List<NavBarEntity> navBarEntities = map.get(module_name);
                if (navBarEntities == null) {
                    navBarEntities = new ArrayList<>();
                    map.put(module_name, navBarEntities);
                }
                String file_uuid = dt.getString(i, MobileCoreConst.NAV_BAR_IMG);
                try {
                    String bytes = null;
                    byte[] fileContent = fileManagerService.getFileContent(file_uuid);
                    if (fileContent != null && fileContent.length > 0) {
                        bytes = Base64.encodeBase64String(fileContent);
                    }
                    dt.setFieldValue(i, MobileCoreConst.NAV_BAR_IMG, bytes);
                } catch (Exception e) {
                    dt.setFieldValue(i, MobileCoreConst.NAV_BAR_IMG, null);
                }
                navBarEntities.add(new NavBarEntity(dt.getFieldSetEntity(i)));
 
            }
            List<Object> list = new ArrayList<>();
            map.forEach((k, v) -> {
                Map<String, Object> m = new HashMap<>();
                m.put("name", k);
                m.put("functions", v);
                list.add(m);
            });
            return list;
        }
        return null;
    }
        
}