shichongfu
2023-04-25 ce0b49552668d3331055e2b1a1447a743dc54939
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
package com.product.admin.service;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;
 
import com.google.common.collect.Sets;
import com.product.admin.service.idel.IDictService;
import com.product.common.lang.StringUtils;
import com.product.core.config.CoreConst;
import com.product.core.transfer.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
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 com.product.admin.config.CmnConst;
import com.product.admin.config.SystemCode;
 
/**
 * Copyright LX-BASE
 *
 * @Title: DictService
 * @Project: LX-BASE-SERVER
 * @Date: 2020年5月30日 上午11:56:57
 * @Author: 郑盟
 * @Description:普通参照配置
 */
@Component
public class DictService extends AbstractBaseService implements IDictService {
    /**
     * 数据查询 ,spring 注入
     */
    @Autowired
    public BaseDao baseDao;
    @Autowired
 
    public QueryFilterService queryFilterService;
 
    private final String SYSTEM_CACHE_KEY = "system-cache:dict";
 
 
    public void initCache(FieldSetEntity fse) {
        if (fse == null || StringUtils.isEmpty(fse.getString(CmnConst.UUID))) {
            //更新所有
            DataTableEntity dt = baseDao.listTable(CmnConst.PRODUCT_SYS_DICT, "is_used=1");
        }
    }
 
 
    public void initCache() {
 
    }
 
    public FieldSetEntity findDict(FieldSetEntity fse) throws BaseException {
 
        return baseDao.listInternationDataTable(baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_DICT, fse.getString("uuid"), false), null);
    }
 
    /**
     * 手机端专用
     *
     * @return
     * @throws BaseException
     */
    public FieldSetEntity findDictForMobile(FieldSetEntity fse, String language_code) throws BaseException {
 
        return baseDao.listInternationDataTable(baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_DICT, fse.getString("uuid"), false),
                language_code);
    }
 
    public DataTableEntity listDict(FieldSetEntity fse) throws BaseException {
        // 郑盟 12-18 12:02
        String queryFilter = "";
        String filter = fse.getString("filter");
        if (!StringUtils.isEmpty(filter)) {
            queryFilter += " and (" + filter + ")";
        }
        DataTableEntity dt = null;
        if (!BaseUtil.dataTableIsEmpty(fse.getSubDataTable("systemSeniorQueryString"))) {
            queryFilter = " and " + queryFilterService.getQueryFilter(fse);
        }
        StringBuilder sql = new StringBuilder();
        SystemUser currentUser = SpringMVCContextHolder.getCurrentUser();
        String manager_type = null;
 
        if (currentUser != null && currentUser.getCurrentManager() != null) {
            manager_type = currentUser.getCurrentManager().getString("manager_type");
        }
        if (StringUtils.isEmpty(manager_type)) {
            return null;
        } else if ("1".equals(manager_type) || "4".equals(manager_type)) {
            sql.append(" select * FROM product_sys_dict  where (client_uuid is null or client_uuid='') ");
            sql.append(queryFilter);
            sql.append(" order by dict_name ");
            dt = baseDao.listTable(sql.toString(), new Object[]{}, fse.getInteger("pagesize"), fse.getInteger("cpage"));
 
        } else {
            String client_uuid = SpringMVCContextHolder.getCurrentUser().getClient_uuid();
            // 郑盟 12-18 12:02
            if (!StringUtils.isEmpty(client_uuid)) {
                sql.append("SELECT a.dict_value_img,a.dict_value_color,a.dict_id,a.uuid,a.dict_name,a.dict_label,a.is_used,a.sequence,a.dict_value FROM (SELECT * FROM (select dict_value_img,dict_value_color,dict_id,uuid,dict_name,dict_label,is_used,sequence,dict_value FROM product_sys_dict WHERE (client_uuid is null or client_uuid='') ");
                sql.append(queryFilter);
                sql.append(" and is_used=1 and CONCAT(dict_name,dict_value ) not in(");
                sql.append(" select CONCAT(dict_name,dict_value ) FROM product_sys_dict  WHERE client_uuid='");
                sql.append(client_uuid);
                sql.append("') union all ");
                sql.append(" select dict_value_img,dict_value_color,dict_id,uuid,dict_name,dict_label,is_used,sequence,dict_value FROM product_sys_dict b WHERE  is_used=1 ");
                sql.append(queryFilter);
                sql.append(" and  client_uuid='");
                sql.append(client_uuid);
                sql.append("') a) a ");
                dt = baseDao.listTable(sql.toString(), new Object[]{}, fse.getInteger("pagesize"), fse.getInteger("cpage"));
                dt.getMeta().addAliasTable(CmnConst.PRODUCT_SYS_DICT, "a");
            } else {
                return null;
            }
        }
        DataTableEntity dataTableEntity = baseDao.listInternationDataTable(dt, null);
        baseDao.loadPromptData(dataTableEntity);
        return dataTableEntity;
    }
 
    public DataTableEntity listDictForMobile(Integer cpage, Integer pagesize, String language_code)
            throws BaseException {
        StringBuilder sql = new StringBuilder();
        SystemUser currentUser = SpringMVCContextHolder.getCurrentUser();
        String manager_type = null;
        if (currentUser != null && currentUser.getCurrentManager() != null) {
            manager_type = currentUser.getCurrentManager().getString("manager_type");
        }
        // 郑盟 2020年12月17日 下午15:55
        if (StringUtils.isEmpty(manager_type)) {
            return null;
        } else if ("1".equals(manager_type) || "4".equals(manager_type)) {
            sql.append("select * FROM product_sys_dict  where client_uuid is null or client_uuid=''  order by dict_name");
        } else {
            String client_uuid = SpringMVCContextHolder.getCurrentUser().getClient_uuid();
            // 郑盟 2020年12月17日 下午15:55
            if (!StringUtils.isEmpty(client_uuid)) {
                sql.append(" select * FROM product_sys_dict WHERE (client_uuid is null or client_uuid='') and  CONCAT(dict_name,dict_value ) not in(");
                sql.append(" select CONCAT(dict_name,dict_value ) FROM product_sys_dict WHERE client_uuid='");
                sql.append(client_uuid);
                sql.append("') union all");
                sql.append(" select * FROM product_sys_dict WHERE client_uuid='");
                sql.append(client_uuid + "'");
            } else {
                return null;
            }
        }
        DataTableEntity dataTableEntity = baseDao
                .listInternationDataTable(baseDao.listTable(sql.toString(), new Object[]{}, pagesize, cpage), language_code);
 
        baseDao.loadPromptData(dataTableEntity);
        return dataTableEntity;
    }
 
    public DataTableEntity listDictByname(FieldSetEntity fse, String manager_type) throws BaseException {
        String dictName = fse.getString("dict_name");
        // 郑盟 2020年12月17日 下午15:55
        if (StringUtils.isEmpty(dictName)) {
            return null;
        }
        StringBuilder sql = new StringBuilder();
        SystemUser currentUser = SpringMVCContextHolder.getCurrentUser();
        String client_uuid = null;
        if (currentUser != null && currentUser.getClient_uuid() != null) {
            client_uuid = currentUser.getClient_uuid();
        }
        List<Object> params = new ArrayList<>();
        params.add(dictName);
        //updatetime 2021年1月15日16:07:48  xupengcheng 增加客户端类型过滤,修改参数传递方式 改为占位符
        if (("1".equals(manager_type) || "4".equals(manager_type)) && (currentUser != null && currentUser.getCurrentManager() != null)) {
            sql.append("select dict_id,uuid,dict_name,dict_label,is_used,sequence,dict_value FROM product_sys_dict where dict_name=? and concat(',',client_type,',') like concat('%,',?,',%') and is_used=1 and (client_uuid is null or client_uuid='') order by sequence");
            params.add(fse.getString(CoreConst.SYSTEM_CLIENT_TYPE_));
        } else {
            //SELECT包两层 给最外层a 别名表名完成国际化   郑盟   2020/12/21
            sql.append("SELECT a.dict_value_img,a.dict_value_color,a.dict_id,a.uuid,a.dict_name,a.dict_label,a.is_used,a.sequence,a.dict_value FROM (SELECT * FROM (select dict_value_img,dict_value_color,dict_id,uuid,dict_name,dict_label,is_used,sequence,dict_value FROM product_sys_dict WHERE (client_uuid is null or client_uuid='') and dict_name=? and is_used=1 and CONCAT(dict_name,dict_value ) not in(");
            sql.append("select CONCAT(dict_name,dict_value ) FROM product_sys_dict  WHERE client_uuid= ? ");
            sql.append(" ) union all");
            sql.append(" select dict_value_img,dict_value_color,dict_id,uuid,dict_name,dict_label,is_used,sequence,dict_value FROM product_sys_dict b WHERE dict_name=? ");
            sql.append(" and is_used=1 and client_uuid= ? ");
            sql.append(" and concat(',',client_type,',') like concat('%,',?,',%')");
            sql.append(" ) a) a");
            params.add(client_uuid);
            params.add(dictName);
            params.add(client_uuid);
            params.add(fse.getString(CoreConst.SYSTEM_CLIENT_TYPE_));
        }
        DataTableEntity listTable = baseDao.listTable(sql.toString(), params.toArray());
        listTable.getMeta().addAliasTable(CmnConst.PRODUCT_SYS_DICT, "a");
        return baseDao.listInternationDataTable(listTable, null);
    }
 
 
    public String addDict(FieldSetEntity fse, String client_uuid) throws BaseException {
        String filter = "";
        // 郑盟 2020年12月17日 下午15:55
        if (!StringUtils.isEmpty(client_uuid)) {
            filter = "  and  client_uuid= '" + client_uuid + "'";
            fse.setValue(CmnConst.CLIENT_UUID, client_uuid);
        }
        if (!dictRepeat(fse, filter)) {
            throw new BaseException(SystemCode.SYSTEM_DICTREPEAT_ADD_FAIL.getValue(),
                    SystemCode.SYSTEM_DICTREPEAT_ADD_FAIL.getText(), this.getClass(), "public String addDict(FieldSetEntity fse, String client_uuid) throws BaseException");
        }
        fse.setValue(CmnConst.CREATED_BY, SpringMVCContextHolder.getCurrentUser().getUser_id());
        fse.setValue(CmnConst.CREATED_UTC_DATETIME, new Date());
        return baseDao.add(fse);
    }
 
    /**
     * 批量删除数据字典
     * 如该字典包含个性化 或通用字典 则对应无权限操作
     *
     * @param dict_name
     * @throws BaseException
     * @auth cheng
     * @date 2021年11月29日15:01:43
     */
    public void deleteMultipleDict(String dict_name) throws BaseException {
        String client_uuid = getClientUuid();
        StringBuilder sql = new StringBuilder();
        sql.append(" SELECT count(dict_name) count FROM product_sys_dict ");
        sql.append("  where ");
        //当前客户uuid不为空说明是该客户进行操作 判断该字典所有数据是否所属该客户
        if (!StringUtils.isEmpty(client_uuid)) {
            //个性化操作
            sql.append(" (client_uuid is null or client_uuid ='') ");
        } else {
            //当前客户uuid为空说明是超级管理员操作 判断该字典所有数据是否为通用数据
            sql.append(" length(client_uuid)>0 ");
        }
        sql.append(" AND (dict_name=?)");
        FieldSetEntity f = baseDao.getFieldSetEntityBySQL(sql.toString(), new Object[]{dict_name}, false);
        //不判断查询结果是否为空 如有报错则说明逻辑错误
        if (f.getInteger("count") > 0) {
            throw new BaseException(SystemCode.MULTIPLE_DELETE_NOT_PERMISSION.getValue(), SystemCode.MULTIPLE_DELETE_NOT_PERMISSION.getText());
        } else {
            baseDao.delete(CmnConst.PRODUCT_SYS_DICT, "dict_name=?", new Object[]{dict_name});
        }
    }
 
    public DataTableEntity getDictTree() {
        String clientUuid = getClientUuid();
        if (!StringUtils.isEmpty(clientUuid)) {
            return baseDao.listTable("select dict_name FROM product_sys_dict where client_uuid is null or client_uuid in ('',?) GROUP BY dict_name", new Object[]{clientUuid});
        }
        return baseDao.listTable("select dict_name FROM product_sys_dict GROUP BY dict_name  ", new Object[]{});
    }
 
    public boolean updateDictIsUsed(FieldSetEntity fse) {
        String clientUuid = getClientUuid();
 
        FieldSetEntity f = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_DICT, fse.getUUID(), false);
        if (f != null) {
            boolean noPermission = false;
            if (StringUtils.isEmpty(clientUuid) && StringUtils.isEmpty(f.getString(CmnConst.CLIENT_UUID))) {
 
            } else if (!StringUtils.isEmpty(clientUuid) && !clientUuid.equals(f.getString(CmnConst.CLIENT_UUID))) {
                noPermission = true;
            } else if (!StringUtils.isEmpty(f.getString(CmnConst.CLIENT_UUID)) && !f.getString(CmnConst.CLIENT_UUID).equals(clientUuid)) {
                noPermission = true;
            }
            if (noPermission) {
 
                throw new BaseException(SystemCode.OPER_DICT_NOT_PERMISSION.getValue(), SystemCode.OPER_DICT_NOT_PERMISSION.getText());
            }
        }
        if (!StringUtils.isEmpty(fse.getUUID())) {
            StringBuilder sql = new StringBuilder();
            sql.append(" UPDATE product_sys_dict ");
            sql.append(" SET is_used = ( SELECT is_used FROM ( ");
            sql.append("SELECT CASE WHEN is_used = 1 THEN 0 ELSE 1 END AS is_used FROM product_sys_dict WHERE uuid = ? ");
            sql.append(" ) a ) ");
            sql.append(" WHERE ");
            sql.append(" uuid = ? ");
            baseDao.executeUpdate(sql.toString(), new Object[]{fse.getUUID(), fse.getUUID()});
            return true;
        }
        return false;
    }
 
 
    public String getClientUuid() {
 
        SystemUser currentUser = SpringMVCContextHolder.getCurrentUser();
        String manager_type = null;
        if (currentUser != null && currentUser.getCurrentManager() != null) {
            manager_type = currentUser.getCurrentManager().getString(CmnConst.MANAGER_TYPE);
        } else {
            throw new BaseException(SystemCode.SYSTEM_NOTOBTAINEDROLE_FAIL.getValue(),
                    SystemCode.SYSTEM_NOTOBTAINEDROLE_FAIL.getText());
        }
        String client_uuid = "1".equals(manager_type) || "4".equals(manager_type) ? ""
                : SpringMVCContextHolder.getCurrentUser().getClientUuid();
        return client_uuid;
    }
 
    public FieldSetEntity findMultipleDict(FieldSetEntity fse) throws BaseException {
        String client_uuid = getClientUuid();
        String dict_name = fse.getString("dict_name");
        StringBuilder sql = new StringBuilder();
        sql.append(" SELECT ");
        sql.append(" * ");
        sql.append(" FROM ");
        sql.append(" product_sys_dict ");
        sql.append(" WHERE ");
        sql.append(" ( client_uuid IS NULL OR client_uuid = '' ) ");
        sql.append(" AND dict_name = ? ");
        Object[] objects = new Object[]{dict_name};
        if (!StringUtils.isEmpty(client_uuid)) {
            sql.append(" AND CONCAT( dict_name, dict_value ) NOT IN ( SELECT CONCAT( dict_name, dict_value ) FROM product_sys_dict WHERE client_uuid = ? ) UNION ALL ");
            sql.append(" SELECT ");
            sql.append(" * ");
            sql.append(" FROM ");
            sql.append(" product_sys_dict b ");
            sql.append(" WHERE ");
            sql.append(" dict_name = ? ");
            sql.append(" AND client_uuid = ? ");
            objects = new Object[]{dict_name, client_uuid, dict_name, client_uuid};
        }
        sql.append(" ORDER BY created_utc_datetime ");
        DataTableEntity dt = baseDao.listTable(sql.toString(), objects);
        FieldSetEntity fs = new FieldSetEntity();
        fs.setTableName(CmnConst.PRODUCT_SYS_DICT);
        fs.setValue(CmnConst.DICT_NAME, dict_name);
        if (!BaseUtil.dataTableIsEmpty(dt)) {
            dt.getMeta().setTableName(new Object[]{CmnConst.PRODUCT_SYS_DICT});
            fs.addSubDataTable(dt);
        }
        return fs;
    }
 
    /**
     * 批量保存数据字典
     *
     * @param fse
     * @throws BaseException
     * @date 2021年11月26日17:07:53
     * @aUth cheng
     */
    @Transactional
    public boolean saveDict(FieldSetEntity fse) throws BaseException {
        SystemUser currentUser = SpringMVCContextHolder.getCurrentUser();
        String manager_type = null;
        if (currentUser != null && currentUser.getCurrentManager() != null) {
            manager_type = currentUser.getCurrentManager().getString(CmnConst.MANAGER_TYPE);
        } else {
            throw new BaseException(SystemCode.SYSTEM_NOTOBTAINEDROLE_FAIL.getValue(),
                    SystemCode.SYSTEM_NOTOBTAINEDROLE_FAIL.getText());
        }
        String client_uuid = "1".equals(manager_type) || "4".equals(manager_type) ? ""
                : SpringMVCContextHolder.getCurrentUser().getClientUuid();
        String dict_name = fse.getString(CmnConst.DICT_NAME);
        DataTableEntity historyData = baseDao.listTable(CmnConst.PRODUCT_SYS_DICT, "dict_name=?", new Object[]{dict_name});
 
        DataTableEntity subDataTable = fse.getSubDataTable(CmnConst.PRODUCT_SYS_DICT);
        if (!BaseUtil.dataTableIsEmpty(subDataTable)) {
            Set<String> keySet = Sets.newHashSet();
            for (int i = 0; i < subDataTable.getRows(); i++) {
                //新提交的数据
                FieldSetEntity fs = subDataTable.getFieldSetEntity(i);
                fs.setValue(CmnConst.DICT_NAME, dict_name);
                // 默认客户端类型为 web
                fs.setValue("client_type", "Web");
                String key = dict_name + fs.getString(CmnConst.DICT_VALUE);
                //判断数据字典值是否重复
                if (keySet.contains(key)) {
                    throw new BaseException(SystemCode.SYSTEM_DICTREPEAT_ADD_FAIL.getValue(),
                            SystemCode.SYSTEM_DICTREPEAT_ADD_FAIL.getText());
                } else {
                    keySet.add(key);
                }
                String uuid = fs.getString("uuid");
                if (StringUtils.isEmpty(uuid)) {
                    //新增的数据
                    //客户uuid不为空时 该字典是客户个性化的
                    if (!StringUtils.isEmpty(client_uuid)) {
                        fs.setValue(CmnConst.CLIENT_UUID, client_uuid);
                    }
                    //添加创建时间、创建人
                    BaseUtil.createCreatorAndCreationTime(fs);
                } else {
                    if (BaseUtil.dataTableIsEmpty(historyData)) {
                        historyData = subDataTable;
                    }
                    //旧数据
                    List<FieldSetEntity> fieldSetEntity = historyData.getFieldSetEntity(uuid);
                    FieldSetEntity historyFs = fieldSetEntity.get(0);
                    //判断是否个性化 前提
                    if (!StringUtils.isEmpty(client_uuid) && StringUtils.isEmpty(fs.getString(CmnConst.CLIENT_UUID))) {
                        //判断是否修改过通用数据
                        if (isUpdateDict(fs, historyFs)) {
                            //修改过 将uuid去掉 变为该客户个性化字典
                            fs.setValue(CmnConst.CLIENT_UUID, client_uuid);
                            fs.setValue(CmnConst.UUID, null);
                            //去掉更新时间、更新人
                            fs.setValue(CmnConst.UPDATED_BY, null);
                            fs.setValue(CmnConst.UPDATED_UTC_DATETIME, null);
                            //添加创建时间、创建人
                            BaseUtil.createCreatorAndCreationTime(fs);
                        }
                    }
                }
            }
 
            return baseDao.update(subDataTable);
        }
        return false;
 
    }
 
    /**
     * 判断历史数据字典和现有数据字典是否变化
     *
     * @param fse
     * @param historyFse
     * @return
     */
    public boolean isUpdateDict(FieldSetEntity fse, FieldSetEntity historyFse) {
        //需要对比的字段集合
        String[] fieldNames = {CmnConst.DICT_LABEL, CmnConst.DICT_VALUE, CmnConst.DICT_VALUE_COLOR, CmnConst.DICT_VALUE_IMG};
        for (String fieldName : fieldNames) {
            String value = fse.getString(fieldName);
            String historyValue = historyFse.getString(fieldName);
            if (StringUtils.isEmpty(value) && StringUtils.isEmpty(historyValue)) {
                continue;
            } else if (StringUtils.isEmpty(value) && !StringUtils.isEmpty(historyValue)) {
                return true;
            } else if (!StringUtils.isEmpty(value) && StringUtils.isEmpty(historyValue)) {
                return true;
            } else if (!value.equals(historyValue)) {
                return true;
            }
        }
        return false;
    }
 
    public String addDict(FieldSetEntity fse, String client_uuid, String language_code) throws BaseException {
        String filter = "";
        // 郑盟 2020年12月17日 下午15:55
        if (!StringUtils.isEmpty(client_uuid)) {
            filter = " and client_uuid= '" + client_uuid + "'";
            fse.setValue(CmnConst.CLIENT_UUID, client_uuid);
        }
        if (!dictRepeat(fse, filter)) {
            throw new BaseException(SystemCode.SYSTEM_DICTREPEAT_ADD_FAIL.getValue(),
                    SystemCode.SYSTEM_DICTREPEAT_ADD_FAIL.getText(), this.getClass(), "public String addDict(FieldSetEntity fse, String client_uuid, String language_code) throws BaseException");
        }
        fse.setValue(CmnConst.CREATED_BY, SpringMVCContextHolder.getCurrentUser().getUser_id());
        fse.setValue(CmnConst.CREATED_UTC_DATETIME, new Date());
        return baseDao.add(fse);
    }
 
    /**
     * 验证数据字典是否重复
     *
     * @throws BaseException
     */
    public boolean dictRepeat(FieldSetEntity fse, String filter) throws BaseException {
        String uuidFilter = "";
        String likeclient = "";
        // 郑盟 2020年12月17日 下午15:55
        if (!StringUtils.isEmpty(fse.getString("uuid"))) {
            uuidFilter = "and uuid!='" + fse.getString("uuid") + "'";
        }
        // 郑盟 2020年12月17日 下午15:55
        if (StringUtils.isEmpty(filter)) {
            String client_uuid = fse.getString(CmnConst.CLIENT_UUID);
            if (!StringUtils.isEmpty(client_uuid)) {
                likeclient = "and (client_uuid = '" + client_uuid + "')";
            }
        }
        DataTableEntity dd = baseDao.listTable(CmnConst.PRODUCT_SYS_DICT,
                "dict_name=? and dict_value=? " + likeclient + " " + uuidFilter + " " + filter + "",
                new Object[]{fse.getString("dict_name"), fse.getString("dict_value")});
 
        if (dd != null && dd.getRows() > 0) {
            return false;
        }
        return true;
    }
 
    public boolean updateDict(FieldSetEntity fse, String language_code) throws BaseException {
        String uuid = fse.getString("uuid");
        FieldSetEntity fs = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_DICT, uuid, false);
        String client_uuid = fs.getString(CmnConst.CLIENT_UUID);
        String org_level = SpringMVCContextHolder.getCurrentUser().getClient_uuid();
        if (StringUtils.isEmpty(org_level)) {
            return false;
        }
        if (StringUtils.isEmpty(client_uuid)) {
            fse.remove("uuid");
            String addDict = addDict(fse, org_level);
            return addDict != null && !"".equals(addDict);
        } else if (client_uuid.equals(org_level)) {
            String filter = " and client_uuid='" + client_uuid + "'";
            if (!dictRepeat(fse, filter)) {
                throw new BaseException(SystemCode.SYSTEM_DICTREPEAT_ADD_FAIL.getValue(),
                        SystemCode.SYSTEM_DICTREPEAT_ADD_FAIL.getText(), this.getClass(), "public boolean updateDict(FieldSetEntity fse, String language_code) throws BaseException");
            }
            fse.setValue(CmnConst.CLIENT_UUID, client_uuid);
            fse.setValue(CmnConst.UPDATED_BY, SpringMVCContextHolder.getCurrentUser().getUser_id());
            fse.setValue(CmnConst.UPDATED_UTC_DATETIME, new Date());
            return baseDao.update(fse);
        } else {
            throw new BaseException(SystemCode.SYSTEM_DICTLEVELS_UPDATE_FAIL.getValue(),
                    SystemCode.SYSTEM_DICTLEVELS_UPDATE_FAIL.getText(), this.getClass(), "public boolean updateDict(FieldSetEntity fse, String language_code) throws BaseException");
        }
    }
 
    public boolean updateDict(FieldSetEntity fse) throws BaseException {
        String uuid = fse.getString("uuid");
        FieldSetEntity fs = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_DICT, uuid, false);
        String client_uuid = fs.getString(CmnConst.CLIENT_UUID);
        String org_level = SpringMVCContextHolder.getCurrentUser().getClient_uuid();
        if (StringUtils.isEmpty(org_level)) {
            return false;
        }
        // 郑盟 2020年12月17日 下午15:55
        if (StringUtils.isEmpty(client_uuid)) {
            fse.remove("uuid");
            String addDict = addDict(fse, org_level);
            return addDict != null && !"".equals(addDict);
        } else if (client_uuid.equals(org_level)) {
            String filter = " and client_uuid='" + client_uuid + "'";
            if (!dictRepeat(fse, filter)) {
                throw new BaseException(SystemCode.SYSTEM_DICTREPEAT_ADD_FAIL.getValue(),
                        SystemCode.SYSTEM_DICTREPEAT_ADD_FAIL.getText(), this.getClass(), "public boolean updateDict(FieldSetEntity fse) throws BaseException");
            }
            fse.setValue(CmnConst.CLIENT_UUID, client_uuid);
            fse.setValue(CmnConst.UPDATED_BY, SpringMVCContextHolder.getCurrentUser().getUser_id());
            fse.setValue(CmnConst.UPDATED_UTC_DATETIME, new Date());
            return baseDao.update(fse);
        } else {
            throw new BaseException(SystemCode.SYSTEM_DICTLEVELS_UPDATE_FAIL.getValue(),
                    SystemCode.SYSTEM_DICTLEVELS_UPDATE_FAIL.getText(), this.getClass(), "public boolean updateDict(FieldSetEntity fse) throws BaseException");
        }
 
    }
 
}