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
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
package com.product.org.admin.service;
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.product.admin.service.CodeService;
import com.product.admin.service.UpdateLoginUserInfoService;
import com.product.core.cache.DataPoolCacheImpl;
import com.product.core.dao.BaseDao;
import com.product.core.entity.DataTableEntity;
import com.product.core.entity.FieldMetaEntity;
import com.product.core.entity.FieldSetEntity;
import com.product.core.entity.SQLEntity;
import com.product.core.exception.BaseException;
import com.product.core.permission.PermissionService;
import com.product.core.service.support.AbstractBaseService;
import com.product.core.spring.context.SpringMVCContextHolder;
import com.product.core.transfer.Transactional;
import com.product.module.sys.entity.SystemUser;
import com.product.org.admin.config.CmnConst;
import com.product.org.admin.config.SystemCode;
import com.product.org.admin.service.idel.ISystemOrgLevelsService;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import com.product.util.BaseUtil;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.apache.commons.lang3.StringUtils;
 
/**
 * Copyright © 2020 MR-BASE
 *
 * @Title: SystemOrgLevelsService
 * @Project: LX-BASE-SERVER
 * @Date: 2019-05-26 11:07
 * @Author:Mr.Xu
 * @Description: 组织架构Service层
 */
@Service
public class SystemOrgLevelsService extends AbstractBaseService implements ISystemOrgLevelsService {
 
    @Autowired
    public BaseDao baseDao;
 
    @Autowired
    private CodeService codeService;
 
    @Autowired
    private PermissionService permissionService;
 
    @Autowired
    private UpdateLoginUserInfoService updateLoginUserInfoService;
 
    /**
     * 验证组织机构是否存在子级
     *
     * @param uuid
     * @return
     * @throws BaseException
     */
    public boolean verifyOrgChildExists(String uuid) throws BaseException {
        if (StringUtils.isEmpty(uuid)) {
            throw new BaseException(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText(),
                    this.getClass(), "verifyOrgChildExists");
        }
        String sql = "select * FROM product_sys_org_levels a  join product_sys_org_levels b on a.org_level_code=b.org_level_code_parent where a.uuid=?";
        DataTableEntity listTable = baseDao.listTable(sql, new Object[]{uuid});
        if (listTable != null && listTable.getRows() > 0) {
            return false;
        }
        return true;
    }
 
    /**
     * 查询组织机构列表
     *
     * @param fse
     * @return
     * @throws BaseException
     */
    public JSONArray listOrgLevels(FieldSetEntity fse) throws BaseException {
        if (SpringMVCContextHolder.getCurrentUser() != null
                && SpringMVCContextHolder.getCurrentUser().getUuid() != null) {
            String sql = "";
            String dept_parent = null;
            DataTableEntity data = new DataTableEntity();
            Object[] objects;
            SystemUser user = SpringMVCContextHolder.getCurrentUser();
            String clientUuid = fse.getString(CmnConst.CLIENT_UUID);
            Integer org_level_type = fse.getInteger(CmnConst.ORG_LEVEL_TYPE);
            if (1 == org_level_type) {// 部门
                dept_parent = fse.getString(CmnConst.ORG_LEVEL_CODE);
                if (StringUtils.isEmpty(dept_parent)) {
                    sql = "select a.*,(select count(*) from " + CmnConst.PRODUCT_SYS_STAFFS
                            + " where dept_uuid=a.uuid) staff_number from " + CmnConst.PRODUCT_SYS_ORG_LEVELS + " a  where "
                            + CmnConst.ORG_LEVEL_TYPE + "=? "
                            + " ORDER BY length(org_level_code),sequence asc,org_level_code";
                    objects = new Object[]{1};
                    data = baseDao.listInternationDataTable(baseDao.listTable(sql, objects), "");
                } else {
                    sql = "select a.*,(select count(*) from " + CmnConst.PRODUCT_SYS_STAFFS
                            + " where dept_uuid=a.uuid) staff_number from " + CmnConst.PRODUCT_SYS_ORG_LEVELS + " a  where "
                            + CmnConst.ORG_LEVEL_CODE_PARENT + "   like ? and " + CmnConst.ORG_LEVEL_TYPE + "=? "
                            + " ORDER BY length(org_level_code),sequence asc,org_level_code";
                    objects = new Object[]{fse.getString(CmnConst.ORG_LEVEL_CODE) + "%", 1};
                    data = baseDao.listInternationDataTable(baseDao.listTable(sql, objects), "");
                }
 
            } else if (user.getUserType() == 3 || user.getUserType() == 4) {// 公司
                if (clientUuid == null) {
                    clientUuid = user.getClientUuid();
                }
                if (clientUuid == null) {
                    return null;
                }
                // updatetime 2021年1月9日13:04:31 xupengcheng 修改隐藏管理员查看公司只能查看当前公司,加多单位过滤
                String orgLevelFilter = permissionService.getDataFilter("uuid");
                String filter = orgLevelFilter + " and " + CmnConst.ORG_LEVEL_TYPE + "=? and " + CmnConst.ORG_LEVEL_STATUS + "=? and  ("
                        + CmnConst.CLIENT_UUID + " = ?";
                String[] clients_uuid = clientUuid.split(",");
                objects = new Object[2 + clients_uuid.length];
                objects[0] = fse.getInteger(CmnConst.ORG_LEVEL_TYPE);
                objects[1] = 0;
                objects[2] = clients_uuid[0];
                for (int i = 1; i < clients_uuid.length; i++) {
                    filter += " or client_uuid=? ";
                    objects[2 + i] = clients_uuid[i];
                }
                filter += ")";
                data = baseDao.listInternationDataTable(
                        baseDao.listTable(CmnConst.PRODUCT_SYS_ORG_LEVELS, filter, objects), "");
            } else if (user.getUserType() == 2) {
                sql = "select level.*," +
                        " case when security_password_length then security_password_length else '' end security_password_length, " +
                        " case when security_upper=1 then '是' else '' end security_upper, " +
                        " case when security_lower=1 then '是' else '' end security_lower, " +
                        " case when security_number=1 then '是' else '' end security_number, " +
                        " case when security_other=1 then '是' else '' end security_other, " +
                        " case when security_repeate_history_password=1 then '是' else '' end security_repeate_history_password, " +
                        " case when security_update_frequency_day then security_update_frequency_day else '' end security_update_frequency_day " +
                        " from " + CmnConst.PRODUCT_SYS_ORG_LEVELS + " level LEFT JOIN " + CmnConst.PRODUCT_SYS_PASSWORD_SECURITY + " secur ON level.uuid=secur.org_level_uuid " +
                        " where level." + CmnConst.ORG_LEVEL_TYPE
                        + "=? and level." + CmnConst.ORG_LEVEL_STATUS + "=? and ( level." + CmnConst.UUID
                        + "=? or org_level_code_parent like CONCAT((select org_level_code FROM product_sys_org_levels where uuid=?),'%'))";
                sql += " Order by level.org_level_code_parent,level.org_level_code,level.sequence";
                String org_level = SpringMVCContextHolder.getCurrentUser().getOrg_level_uuid();
                objects = new Object[]{fse.getInteger(CmnConst.ORG_LEVEL_TYPE), 0, org_level, org_level};
                DataTableEntity data2 = baseDao.listInternationDataTable(baseDao.listTable(sql, objects), "");
                if (data2.getRows() > 0) {
                    for (int i = 0; i < data2.getRows(); i++) {
                        data.addFieldSetEntity(data2.getFieldSetEntity(i));
                    }
                }
            } else if (user.getUserType() == 1) {
                sql = "select level.*," +
                        " case when security_password_length then security_password_length else '' end security_password_length, " +
                        " case when security_upper=1 then '是' else '' end security_upper, " +
                        " case when security_lower=1 then '是' else '' end security_lower, " +
                        " case when security_number=1 then '是' else '' end security_number, " +
                        " case when security_other=1 then '是' else '' end security_other, " +
                        " case when security_repeate_history_password=1 then '是' else '' end security_repeate_history_password, " +
                        " case when security_update_frequency_day then security_update_frequency_day else '' end security_update_frequency_day " +
                        " from " + CmnConst.PRODUCT_SYS_ORG_LEVELS + " level LEFT JOIN " + CmnConst.PRODUCT_SYS_PASSWORD_SECURITY + " secur ON level.uuid=secur.org_level_uuid " +
                        " where " + CmnConst.ORG_LEVEL_TYPE +
                        " =? and " + CmnConst.ORG_LEVEL_STATUS + "=?";
                sql += " Order by org_level_code_parent,org_level_code,sequence";
                objects = new Object[]{fse.getInteger(CmnConst.ORG_LEVEL_TYPE), 0};
                DataTableEntity data2 = baseDao.listInternationDataTable(baseDao.listTable(sql, objects), "");
                if (data2.getRows() > 0) {
                    for (int i = 0; i < data2.getRows(); i++) {
                        data.addFieldSetEntity(data2.getFieldSetEntity(i));
                    }
                }
            } else {
                // 公司
                sql = "select * from " + CmnConst.PRODUCT_SYS_ORG_LEVELS + " where " + CmnConst.ORG_LEVEL_TYPE
                        + "=? and " + CmnConst.ORG_LEVEL_STATUS + "=? and  ( " + CmnConst.CREATED_BY + " =?  or "
                        + CmnConst.ORG_LEVEL_MANAGER_UUID + "=? )";
                sql += " Order by org_level_code_parent,org_level_code,sequence";
                if (StringUtils.isEmpty(clientUuid)) {
                    return null;
                }
                for (String s : clientUuid.split(",")) {
                    objects = new Object[]{fse.getInteger(CmnConst.ORG_LEVEL_TYPE), 0,
                            SpringMVCContextHolder.getCurrentUser().getUser_id(), s};
                    DataTableEntity data2 = baseDao.listInternationDataTable(baseDao.listTable(sql, objects), "");
                    if (data2.getRows() > 0) {
                        for (int i = 0; i < data2.getRows(); i++) {
                            data.addFieldSetEntity(data2.getFieldSetEntity(i));
                        }
                    }
                }
            }
 
            for (int i = 0; i < data.getRows(); i++) {
                FieldSetEntity fieldSetEntity = data.getFieldSetEntity(i);
                DataTableEntity org_level_name = fieldSetEntity.getSubDataTable("org_level_name");
                if (!BaseUtil.dataTableIsEmpty(org_level_name)) {
                    List<Object> names = new ArrayList<>();
                    for (int j = 0; j < org_level_name.getRows(); j++) {
                        Map<String, Object> name = new HashMap<>();
                        FieldSetEntity fieldSetEntity1 = org_level_name.getFieldSetEntity(j);
                        name.put(fieldSetEntity1.getString(CmnConst.LANGUAGE_CODE),
                                fieldSetEntity1.getString(fieldSetEntity1.getString(CmnConst.LANGUAGE_CODE)));
                        names.add(name);
                    }
                    fieldSetEntity.setValue("org_level_name", names);
                }
            }
            if (!BaseUtil.dataTableIsEmpty(data)) {// 封装树
 
                return OrgLevelsTree(data, fse.getInteger(CmnConst.ORG_LEVEL_TYPE), dept_parent);
            }
            return new JSONArray();
 
        }
        // 用户获取失败
        throw new BaseException(SystemCode.SYSTEM_USER_ACQUIRE_FAIL.getValue(),
                SystemCode.SYSTEM_USER_ACQUIRE_FAIL.getText(), this.getClass(), "listCompany");
    }
 
    public int sumStaff(FieldSetEntity fs, int sum) throws BaseException {
        if (fs.getValue(CmnConst.CHILDREN) != null) {
            sum += fs.getInteger(CmnConst.STAFF_NUMBER);
            DataTableEntity dt = (DataTableEntity) fs.getValue(CmnConst.CHILDREN);
            for (int i = 0; i < dt.getRows(); i++) {
                FieldSetEntity fss = dt.getFieldSetEntity(i);
                if (fss.getValue(CmnConst.CHILDREN) != null) {
                    this.sumStaff(fss, sum);
                } else {
                    sum += fss.getInteger(CmnConst.STAFF_NUMBER);
                }
            }
        } else {
            return sum;
        }
        return sum;
    }
 
    /**
     * 新增公司
     *
     * @param fse
     * @return
     * @throws BaseException
     */
    @Transactional
    public String addCompany(FieldSetEntity fse) throws BaseException {
        //获取公司名称
        String org_level_name=fse.getString(CmnConst.ORG_LEVEL_NAME);
        //获取公司上级公司
        String org_level_code_parent=fse.getString(CmnConst.ORG_LEVEL_CODE_PARENT);
        // 公司名称唯一验证
        uniqueVerification(org_level_name,null, org_level_code_parent, 0);
        if (StringUtils.isEmpty(org_level_code_parent)) {
            fse.setValue(CmnConst.ORG_LEVEL_CODE_PARENT, "");
        }
        // 拼接机构全称
        createOrgLevelAllLanguage(fse, org_level_name, org_level_code_parent);
        SystemUser currentUser = SpringMVCContextHolder.getCurrentUser();
        fse.setValue(CmnConst.ORG_LEVEL_MANAGER_UUID, currentUser.getUuid());
        fse.setValue(CmnConst.ORG_LEVEL_TYPE, 0);
        // 创建机构编码
        fse.setValue(CmnConst.ORG_LEVEL_CODE, codeService.createCode(CmnConst.PRODUCT_SYS_ORG_LEVELS, CmnConst.ORG_LEVEL_CODE, fse.getString(CmnConst.ORG_LEVEL_CODE_PARENT)));
        fse.setValue(CmnConst.CLIENT_UUID, currentUser.getClient_uuid());
        fse.setValue(CmnConst.ORG_LEVEL_STATUS, 0);
        fse.setValue(CmnConst.CREATED_BY, currentUser.getUser_id());
        fse.setValue(CmnConst.CREATED_UTC_DATETIME, new Date());
 
        String uuid = baseDao.add(fse, true);
        if (null != uuid) {
            FieldSetEntity fs = new FieldSetEntity();
            FieldMetaEntity f = new FieldMetaEntity();
            f.setTableName(new Object[]{CmnConst.PRODUCT_SYS_DATA_STRATEGY_MASTER});
            fs.setMeta(f);
            fs.setValue(CmnConst.ORG_LEVEL_UUID, fse.getString(CmnConst.UUID));
            fs.setValue("property_uuid", "001");
            fs.setValue("is_used", "1");
            fs.setValue("effective_start_date", new Date());
            fs.setValue(CmnConst.CREATED_BY, currentUser.getUser_id());
            fs.setValue(CmnConst.CREATED_UTC_DATETIME, new Date());
            baseDao.add(fs);
 
        }
        if (currentUser.getUserType() == 2) {
            FieldSetEntity currentManager = currentUser.getCurrentManager();
            String manager_org_level_uuid = currentManager.getString(CmnConst.ORG_LEVEL_UUID);
            if (StringUtils.isEmpty(manager_org_level_uuid)) {
                manager_org_level_uuid = uuid;
            } else {
                manager_org_level_uuid = manager_org_level_uuid + "," + uuid;
            }
            currentManager.setValue(CmnConst.ORG_LEVEL_UUID, manager_org_level_uuid);
            baseDao.saveFieldSetEntity(currentManager);
            updateLoginUserInfoService.updateUserInfoByUserId(currentUser.getUser_id(), 1, true);
 
        }
 
        // 回写到隐藏管理员所管理的公司
//        baseDao.executeUpdate("UPDATE product_sys_org_manager SET org_level_uuid =(SELECT group_concat(UUID) FROM product_sys_org_levels WHERE CLIENT_UUID =? AND ORG_LEVEL_TYPE =0) WHERE CLIENTS_UUID=? AND MANAGER_TYPE=? "
//                , new Object[]{fse.getString(CmnConst.CLIENT_UUID), fse.getString(CmnConst.CLIENT_UUID), 3});
        return uuid;
    }
 
    /**
     * 组织机构名称唯一值验证
     *
     * @param org_level_name
     * @param uuid
     * @throws BaseException
     */
    public void uniqueVerification(String org_level_name, String uuid,String org_level_code_parent,Integer type) throws BaseException {
        List<String> param= Lists.newArrayList();
        String filter=" org_level_type = "+ type +" and org_level_name= ? ";
        param.add(org_level_name);
        if (!StringUtils.isEmpty(uuid)) {
            param.add(uuid);
            filter += " AND uuid != ? ";
        }
        if (!StringUtils.isEmpty(org_level_code_parent)) {
            filter += " AND org_level_code_parent = ?";
            param.add(org_level_code_parent);
        }
        DataTableEntity dt=baseDao.listTable(CmnConst.PRODUCT_SYS_ORG_LEVELS, filter, param.toArray());
        if (!BaseUtil.dataTableIsEmpty(dt)) {
            throw new BaseException(SystemCode.SYSTEM_COMPANY_NAME_DUPLICATE_OPERATION_FIAL.getValue(), SystemCode.SYSTEM_COMPANY_NAME_DUPLICATE_OPERATION_FIAL.getText());
        }
    }
 
    /**
     * 更新公司
     *
     * @param fseNew
     * @throws BaseException
     */
    @Transactional
    public boolean updateCompany(FieldSetEntity fseNew) throws BaseException {
 
        // 公司名称唯一验证
        uniqueVerification(fseNew.getString(CmnConst.ORG_LEVEL_NAME),fseNew.getUUID(),fseNew.getString(CmnConst.ORG_LEVEL_CODE_PARENT), 0);
 
        // 原数据信息
        FieldSetEntity fseOrigin = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_ORG_LEVELS, fseNew.getString(CmnConst.UUID), false);
 
        // 获取相应组织机构上级编码
        String newOrgLevelCodeParent = fseNew.getString(CmnConst.ORG_LEVEL_CODE_PARENT);
        String originOrgLevelCodeParent = fseOrigin.getString(CmnConst.ORG_LEVEL_CODE_PARENT);
 
        if (newOrgLevelCodeParent == null) {
            newOrgLevelCodeParent = "";
        }
        if (originOrgLevelCodeParent == null) {
            originOrgLevelCodeParent = "";
        }
 
        // 上级组织机构发生改变
        if (!newOrgLevelCodeParent.equals(originOrgLevelCodeParent)) {
 
            // 生成当前新公司编码
            String newOrgLevelCode = codeService.createCode(fseNew, CmnConst.PRODUCT_SYS_ORG_LEVELS, CmnConst.ORG_LEVEL_CODE, newOrgLevelCodeParent);
//            fseNew.setValue(CmnConst.ORG_LEVEL_CODE, newOrgLevelCode);
 
 
            // 获取变更前组织机构编码
            String originOrgLevelCode = fseOrigin.getString(CmnConst.ORG_LEVEL_CODE);
            // 变更相关组织机构编码,父级组织机构编码
            changeCode(originOrgLevelCode, newOrgLevelCode);
 
            // 变更相关组织机构全称
            changeOrgLevelAll(fseNew, originOrgLevelCodeParent, newOrgLevelCodeParent);
        } else if (!fseOrigin.getString(CmnConst.ORG_LEVEL_NAME).equals(fseNew.getString(CmnConst.ORG_LEVEL_NAME))) {
            changeOrgLevelAll(fseNew, originOrgLevelCodeParent, newOrgLevelCodeParent);
        }
 
        // 更新组织机构下属员工信息
        updateLoginUserInfoService.updateUserInfoByOrgLevelUuid(new String[]{fseNew.getUUID()}, 1, true);
        return baseDao.update(fseNew, true);
    }
 
    /**
     * 变更组织机构全称
     *
     * @param fseOrgInfo
     * @param originParentCode
     * @param newParentCode
     */
    public void changeOrgLevelAll(FieldSetEntity fseOrgInfo, String originParentCode, String newParentCode) {
        String newOrgLevelAll = null;
        String originOrgLevelAll = fseOrgInfo.getString(CmnConst.ORG_LEVEL_ALL);    //获取原组织机构全称
        String orgLevelName = fseOrgInfo.getString(CmnConst.ORG_LEVEL_NAME);        //获取组织机构名称
        if (!StringUtils.isEmpty(newParentCode)) {    //新上级组织机构
            FieldSetEntity fseNewParent = baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_SYS_ORG_LEVELS, "org_level_code=?", new Object[]{newParentCode}, false);
            if (fseNewParent == null) {
                throw new BaseException(SystemCode.SYSTEM_ORG_LEVEL_PARENT_NO_EXIST.getValue(), SystemCode.SYSTEM_ORG_LEVEL_PARENT_NO_EXIST.getText(), this.getClass(), "changeOrgLevelAll");
            }
            newOrgLevelAll = fseNewParent.getString(CmnConst.ORG_LEVEL_ALL) + ">" + orgLevelName;
            fseOrgInfo.setValue(CmnConst.ORG_LEVEL_ALL, newOrgLevelAll);
        } else {    //无上级组织机构
 
            newOrgLevelAll = orgLevelName;
            fseOrgInfo.setValue(CmnConst.ORG_LEVEL_ALL, newOrgLevelAll);
        }
        changeOrgLevelAll(originOrgLevelAll, newOrgLevelAll, fseOrgInfo.getString(CmnConst.ORG_LEVEL_CODE));
    }
 
    /**
     * 变更相关组织机构全称
     *
     * @param originOrgLevelAll
     * @param newOrgLevelAll
     * @param org_level_code
     */
    public void changeOrgLevelAll(String originOrgLevelAll, String newOrgLevelAll, String org_level_code) {
        String sql = "UPDATE product_sys_org_levels SET org_level_all=REPLACE(org_level_all,?,?) WHERE org_level_code like ?";
        baseDao.executeUpdate(sql, new Object[]{originOrgLevelAll, newOrgLevelAll, org_level_code + "%"});
    }
 
 
    /**
     * 更改当前公司下所有组织机构编码,组织机构父级编码,员工编码
     *
     * @param originCode 原公司编码
     * @param newCode    新公司编码
     * @return
     * @throws BaseException
     */
    public boolean changeCode(String originCode, String newCode) throws BaseException {
        //郑盟 2020/12/18
        boolean flag = true;
        String sqlOrgCode = "update " + CmnConst.PRODUCT_SYS_ORG_LEVELS + " set org_level_code=concat('" + newCode + "', mid(org_level_code,length('" + originCode + "')+1)) where org_level_code like '" + originCode + "%'";
        flag = baseDao.executeUpdate(sqlOrgCode);
        if (!flag) {
            throw new BaseException(SystemCode.SYSTEM_ORG_UPDATE_FAIL_ORGCODE.getValue(),
                    SystemCode.SYSTEM_ORG_UPDATE_FAIL_ORGCODE.getText(), this.getClass(), "changeCode");
        }
        String sqlOrgCodeParent = "update " + CmnConst.PRODUCT_SYS_ORG_LEVELS
                + " set org_level_code_parent=concat('" + newCode + "', mid(org_level_code_parent,length('" + originCode + "')+1)) where org_level_code_parent like '" + originCode + "%'";
        flag = baseDao.executeUpdate(sqlOrgCodeParent);
        if (!flag) {
            throw new BaseException(SystemCode.SYSTEM_ORG_UPDATE_FAIL_ORGPARENTCODE.getValue(),
                    SystemCode.SYSTEM_ORG_UPDATE_FAIL_ORGPARENTCODE.getText(), this.getClass(), "changeCode");
        }
        DataPoolCacheImpl.getInstance().reloadCodeManager(CmnConst.PRODUCT_SYS_ORG_LEVELS, CmnConst.ORG_LEVEL_CODE);
        String sqlCodeStaff = "update " + CmnConst.PRODUCT_SYS_STAFFS + " set tricode=concat('" + newCode + "', mid(tricode,length('" + originCode + "')+1)) where tricode like '" + originCode + "%'";
        flag = baseDao.executeUpdate(sqlCodeStaff);
        if (!flag) {
            throw new BaseException(SystemCode.SYSTEM_ORG_UPDATE_FAIL_ORGSTAFFCODE.getValue(),
                    SystemCode.SYSTEM_ORG_UPDATE_FAIL_ORGSTAFFCODE.getText(), this.getClass(), "changeCode");
        }
        String sqlCodeStaffDirect = "update " + CmnConst.PRODUCT_SYS_STAFFS + " set direct_leader_code=concat('" + newCode + "', mid(direct_leader_code,length('" + originCode + "')+1)) where direct_leader_code like '" + originCode + "%'";
        flag = baseDao.executeUpdate(sqlCodeStaffDirect);
        if (!flag) {
            throw new BaseException(SystemCode.SYSTEM_ORG_UPDATE_FAIL_ORGSTAFFCODE.getValue(),
                    SystemCode.SYSTEM_ORG_UPDATE_FAIL_ORGSTAFFCODE.getText(), this.getClass(), "changeCode");
        }
        DataPoolCacheImpl.getInstance().reloadCodeManager(CmnConst.PRODUCT_SYS_STAFFS, "tricode");
        return flag;
    }
 
    /**
     * 查询组织机构详情
     *
     * @param fse
     * @return
     * @throws BaseException
     */
    public FieldSetEntity findOrgLevel(FieldSetEntity fse) throws BaseException {
        return baseDao.listInternationDataTable(
                baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_SYS_ORG_LEVELS,
                        CmnConst.UUID + "=? and " + CmnConst.ORG_LEVEL_TYPE + "=?",
                        new Object[]{fse.getString(CmnConst.UUID), fse.getString(CmnConst.ORG_LEVEL_TYPE)}, true),
                null);
    }
 
    @Transactional
    @Override
    public boolean deleteCompany(FieldSetEntity fse) throws BaseException {
        String uuid = fse.getUUID();
        if (StringUtils.isEmpty(uuid)) {
            throw new BaseException(SystemCode.SYSTEM_COMANY_DELETE_FAIL.getValue(),
                    SystemCode.SYSTEM_COMANY_DELETE_FAIL.getText(), this.getClass(), "public boolean deleteCompany(FieldSetEntity fse) throws BaseException");
        }
        // 存在下级公司不能删除
        if (!verifyOrgChildExists(fse.getString(CmnConst.UUID))) {
            throw new BaseException(SystemCode.SYSTEM_ORG_UPDATE_EXIST_CHILDREN_FAIL.getValue(),
                    SystemCode.SYSTEM_ORG_UPDATE_EXIST_CHILDREN_FAIL.getText(), this.getClass(), "public boolean deleteCompany(FieldSetEntity fse) throws BaseException");
        }
        //删除公司数据策略
        baseDao.delete(CmnConst.PRODUCT_SYS_DATA_STRATEGY_MASTER, "org_level_uuid=?",
                new String[]{uuid});
        //删除公司
        baseDao.delete(CmnConst.PRODUCT_SYS_ORG_LEVELS, "uuid=?",
                new String[]{uuid});
        //删除管理员管理里该公司的uuid
        baseDao.executeUpdate("update product_sys_org_manager set org_level_uuid=replace(replace(org_level_uuid,concat(',',?),''),concat(?,','),'') where org_level_uuid like  concat('%',?,'%')", new Object[]{uuid,uuid,uuid});
        return true;
    }
 
    /**
     * 部门列表(包含公司)
     *
     * @param fse
     * @return
     * @throws BaseException
     */
    public DataTableEntity listDepartment(FieldSetEntity fse) throws BaseException {
        if (SpringMVCContextHolder.getCurrentUser() != null
                && SpringMVCContextHolder.getCurrentUser().getUuid() != null) {
            FieldSetEntity fs = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_ORG_LEVELS,
                    fse.getString(CmnConst.ORG_LEVEL_UUID), false);
            if (fs == null) {
                // 抛出请求参数错误
                throw new BaseException(SystemCode.SYSTEM_FORM_COUNT.getValue(), SystemCode.SYSTEM_FORM_COUNT.getText(),
                        this.getClass(), "listDepartment");
            }
            SQLEntity sql = new SQLEntity();
            sql.setTableNames(CmnConst.PRODUCT_SYS_ORG_LEVELS);
            sql.setFilter(CmnConst.ORG_LEVEL_TYPE + "=? and " + CmnConst.ORG_LEVEL_STATUS + "=?");
            sql.setParas(new Object[]{1, 0});
            sql.setOrderBy("org_level_code_parent");
            DataTableEntity dt = baseDao.listTable(sql);
            if (dt != null && dt.getRows() > 0) {
                return findDepartmentChild(dt, fs, new DataTableEntity());
            }
            return null;
        }
        // 用户获取失败
        throw new BaseException(SystemCode.SYSTEM_USER_ACQUIRE_FAIL.getValue(),
                SystemCode.SYSTEM_USER_ACQUIRE_FAIL.getText(), this.getClass(), "listDepartment");
    }
 
    public JSONArray OrgLevelsTree(DataTableEntity data, Integer org_level_type, String dept_parent)
            throws BaseException {
        JSONArray menus = new JSONArray();
        JSONObject parent_menu = new JSONObject();
        if (data != null && data.getRows() > 0) {
//            for (int i = 0; i  < data.getRows(); i++) {
//                FieldSetEntity fs=data.getFieldSetEntity(i);
//                //|| (!StringUtils.isEmpty(dept_parent)  && dept_parent.equals(fs.getString(CmnConst.ORG_LEVEL_CODE_PARENT)))|| (!StringUtils.isEmpty(fs.getString(CmnConst.ORG_LEVEL_CODE_PARENT))  && fs.getString(CmnConst.ORG_LEVEL_CODE_PARENT).equals("001"))
//                if(StringUtils.isEmpty(fs.getString(CmnConst.ORG_LEVEL_CODE_PARENT)) || (!StringUtils.isEmpty(dept_parent)  && dept_parent.equals(fs.getString(CmnConst.ORG_LEVEL_CODE)))) {
//                    JSONObject org_top=new JSONObject();
//                    org_top.put(CmnConst.UUID,fs.getString(CmnConst.UUID));
//                    org_top.put(CmnConst.CLIENT_UUID,fs.getString(CmnConst.CLIENT_UUID));
//                    org_top.put(CmnConst.ORG_LEVEL_NAME,fs.getObject(CmnConst.ORG_LEVEL_NAME));
//                    org_top.put(CmnConst.ORG_LEVEL_CODE,fs.getString(CmnConst.ORG_LEVEL_CODE));
//                    org_top.put(CmnConst.ORG_LEVEL_CODE_PARENT,fs.getString(CmnConst.ORG_LEVEL_CODE_PARENT));
//                    org_top.put(CmnConst.ORG_LEVEL_TYPE,fs.getString(CmnConst.ORG_LEVEL_TYPE));
//                    if(org_level_type==1)org_top.put("staff_number", fs.getInteger("staff_number"));
//                    org_top.put("children", OrgLevelChildrenTree(data,fs.getString(CmnConst.ORG_LEVEL_CODE),org_level_type));
//                    top_array.add(org_top);
//                }
//            }
            for (int i = 0; i < data.getRows(); i++) {
                FieldSetEntity fs = data.getFieldSetEntity(i);
                JSONObject menu = BaseUtil.fieldSetEntityToJson(fs);
                String pcode = fs.getString("org_level_code_parent");
                if (StringUtils.isEmpty(pcode) || parent_menu.getString(pcode) == null) {
                    menus.add(menu);
                } else {// 上级菜单
                    JSONObject pm = parent_menu.getJSONObject(pcode);
                    JSONArray subs = pm.getJSONArray(CmnConst.CHILDREN);
                    JSONArray submenus = null;
                    if (subs == null) {
                        submenus = new JSONArray();
                        pm.put(CmnConst.CHILDREN, submenus);
                    } else {
                        submenus = subs;
                    }
                    submenus.add(menu);
                }
                parent_menu.put(menu.getString(CmnConst.ORG_LEVEL_CODE), menu);
            }
        }
        return menus;
    }
 
    public JSONArray OrgLevelChildrenTree(DataTableEntity data, String level_code_parent, Integer org_level_type)
            throws BaseException {
        JSONArray children_array = new JSONArray();
        if (data != null && data.getRows() > 0 && !StringUtils.isEmpty(level_code_parent)) {
            for (int i = 0; i < data.getRows(); i++) {
                FieldSetEntity fs = data.getFieldSetEntity(i);
                if (level_code_parent.equals(fs.getString(CmnConst.ORG_LEVEL_CODE_PARENT))) {
                    JSONObject org_children = new JSONObject();
                    org_children.put(CmnConst.UUID, fs.getString(CmnConst.UUID));
                    org_children.put(CmnConst.ORG_LEVEL_NAME, fs.getObject(CmnConst.ORG_LEVEL_NAME));
                    org_children.put(CmnConst.CLIENT_UUID, fs.getString(CmnConst.CLIENT_UUID));
                    org_children.put(CmnConst.ORG_LEVEL_CODE, fs.getString(CmnConst.ORG_LEVEL_CODE));
                    org_children.put(CmnConst.ORG_LEVEL_CODE_PARENT, fs.getString(CmnConst.ORG_LEVEL_CODE_PARENT));
                    org_children.put(CmnConst.ORG_LEVEL_TYPE, fs.getString(CmnConst.ORG_LEVEL_TYPE));
 
                    if (org_level_type == 1)
                        org_children.put(CmnConst.STAFF_NUMBER, fs.getInteger(CmnConst.STAFF_NUMBER));
                    if (org_level_type == 1)
                        org_children.put("staff_sum", fs.getInteger(CmnConst.STAFF_NUMBER));
                    org_children.put(CmnConst.CHILDREN,
                            OrgLevelChildrenTree(data, fs.getString(CmnConst.ORG_LEVEL_CODE), org_level_type));
                    children_array.add(org_children);
                }
            }
        }
        return children_array;
    }
 
    private DataTableEntity findDepartmentChild(DataTableEntity dt, FieldSetEntity fse, DataTableEntity newDt)
            throws BaseException {
        if (dt != null && dt.getRows() > 0 && fse != null) {
            String org_level_code = fse.getString(CmnConst.ORG_LEVEL_CODE);
            if ("1".equals(fse.getString(CmnConst.ORG_LEVEL_TYPE))) {
                newDt.addFieldSetEntity(fse);
                newDt.setMeta(fse.getMeta());
            }
            for (int i = 0; i < dt.getRows(); i++) {
                FieldSetEntity fs = dt.getFieldSetEntity(i);
                if (StringUtils.equals(org_level_code, fs.getString(CmnConst.ORG_LEVEL_CODE_PARENT))) {
                    newDt = findDepartmentChild(dt, fs, newDt);
                }
            }
            return newDt;
        }
        return null;
    }
 
    /**
     * 新增部门
     *
     * @param fse
     * @return
     * @throws BaseException
     */
    @Transactional
    public String addDepartment(FieldSetEntity fse) throws BaseException {
        uniqueVerification(fse.getString(CmnConst.ORG_LEVEL_NAME), null,fse.getString(CmnConst.ORG_LEVEL_CODE_PARENT), 1);
        createOrgLevelAllLanguage(fse, fse.getString(CmnConst.ORG_LEVEL_NAME), fse.getString(CmnConst.ORG_LEVEL_CODE_PARENT));
        fse.setValue(CmnConst.ORG_LEVEL_TYPE, 1);
        fse.setValue(CmnConst.ORG_LEVEL_CODE, codeService.createCode(CmnConst.PRODUCT_SYS_ORG_LEVELS,
                CmnConst.ORG_LEVEL_CODE, fse.getString(CmnConst.ORG_LEVEL_CODE_PARENT)));
        fse.setValue(CmnConst.CLIENT_UUID, SpringMVCContextHolder.getCurrentUser().getClient_uuid()); // 待修改
        fse.setValue(CmnConst.ORG_LEVEL_STATUS, 0);
 
        DataTableEntity orgLevelDte = baseDao.listTable(CmnConst.PRODUCT_SYS_ORG_LEVELS, "? like concat(org_level_code,'%') and org_level_type=0", new Object[]{fse.getString(CmnConst.ORG_LEVEL_CODE)}, "org_level_code desc");
        if (!BaseUtil.dataTableIsEmpty(orgLevelDte)) {
            fse.setValue(CmnConst.ORG_LEVEL_UUID, orgLevelDte.getFieldSetEntity(0).getUUID());
        }
 
        BaseUtil.createCreatorAndCreationTime(SpringMVCContextHolder.getCurrentUser(), fse);
        return baseDao.add(fse);
    }
 
    /**
     * 创建组织机构全称国际化
     *
     * @param fse
     * @return
     * @throws BaseException
     */
    public void createOrgLevelAllLanguage(FieldSetEntity fse, String org_level_name, String org_level_code_parent) throws BaseException {
        //判断上级组织机构是否存在
        if (StringUtils.isEmpty(org_level_code_parent)) {
            fse.setValue(CmnConst.ORG_LEVEL_ALL, org_level_name);
        } else {
            //获取上级组织机构
            FieldSetEntity fseOrgParent = baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_SYS_ORG_LEVELS, "org_level_code=?", new Object[]{org_level_code_parent}, false);
            if (fseOrgParent == null) {
                throw new BaseException(SystemCode.SYSTEM_ORG_LEVEL_PARENT_NO_EXIST.getValue(), SystemCode.SYSTEM_ORG_LEVEL_PARENT_NO_EXIST.getText(), this.getClass(), "addDepartment");
            }
            //获取上级组织机构全称
            String org_level_parent_all = fseOrgParent.getString(CmnConst.ORG_LEVEL_ALL);
            //拼接当前组织机构全称
            fse.setValue(CmnConst.ORG_LEVEL_ALL, org_level_parent_all + ">" + org_level_name);
        }
    }
 
    /**
     * 国际化解析
     *
     * @param currentField  当前字段
     * @param language_code 语言代码
     * @param languageValue 语言内容
     * @return
     * @throws BaseException
     */
    public FieldSetEntity parseInternational(String currentField, String language_code, String languageValue)
            throws BaseException {
        FieldSetEntity fseLanguage = new FieldSetEntity();
        fseLanguage.setTableName(currentField);
        fseLanguage.setValue(language_code, languageValue);
        return fseLanguage;
    }
 
    /**
     * 更新部门
     *
     * @param fse
     * @return
     * @throws BaseException
     */
    @Override
    @Transactional
    public boolean updateDepartment(FieldSetEntity fse) throws BaseException {
        FieldSetEntity fs = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_ORG_LEVELS, fse.getString(CmnConst.UUID),
                false);
        // 没有查询到结果
        if (fs == null)
            throw new BaseException(SystemCode.SYSTEM_COMANY_UPDATE_FAIL.getValue(),
                    SystemCode.SYSTEM_COMANY_UPDATE_FAIL.getText(), this.getClass(), "updateDepartment");
        // 判断是否修改了上级编码
        if (!StringUtils.equals(fs.getString(CmnConst.ORG_LEVEL_CODE_PARENT),
                fse.getString(CmnConst.ORG_LEVEL_CODE_PARENT))) {
            throw new BaseException(SystemCode.SYSTEM_DEPARTMENT_UPDATE_FAIL.getValue(),
                    SystemCode.SYSTEM_DEPARTMENT_UPDATE_FAIL.getText(), this.getClass(), "updateDepartment");
        }
        // 注释国际化代码
//        DataTableEntity level_name_dt = fse.getSubDataTable(CmnConst.ORG_LEVEL_NAME);
//        DataTableEntity level_all_dt = jointOrgLevelAll(fs, level_name_dt);
//        fse.addSubDataTable(level_all_dt);
//        updateOrgLevelAll(listInternationfs.getSubDataTable(CmnConst.ORG_LEVEL_ALL), level_all_dt,
//                fs.getString(CmnConst.ORG_LEVEL_CODE));
        updateOrgLevelAll(fse);
        BaseUtil.createCreatorAndCreationTime(SpringMVCContextHolder.getCurrentUser(), fse);
        // xupengcheng dateTime 2020年11月28日14:12:18 更新部门下属员工信息
        updateLoginUserInfoService.updateUserInfoByDeptUuid(new String[]{fse.getUUID()}, true);
        return baseDao.update(fse);
    }
 
    public void updateOrgLevelAll(FieldSetEntity fse) throws BaseException {
        FieldSetEntity fs = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_ORG_LEVELS, fse.getUUID(), false);
        if (fs != null) {
            if (!StringUtils.isEmpty(fs.getString(CmnConst.ORG_LEVEL_NAME)) && fs.getString(CmnConst.ORG_LEVEL_NAME).equals(fse.getString(fse.getString(CmnConst.ORG_LEVEL_NAME)))) {
                return;
            }
            String org_level_code_parent = fse.getString(CmnConst.ORG_LEVEL_CODE_PARENT);
            FieldSetEntity parentOrg = baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_SYS_ORG_LEVELS, "org_level_code=?", new Object[]{org_level_code_parent}, false);
            String parent_level = parentOrg.getString(CmnConst.ORG_LEVEL_ALL);
            String org_level_code = fse.getString(CmnConst.ORG_LEVEL_CODE);
            String org_level_all = parent_level + '>' + fse.getString(CmnConst.ORG_LEVEL_NAME);
            fse.setValue(CmnConst.ORG_LEVEL_ALL, org_level_all);
            String befor_level_all = fs.getString(CmnConst.ORG_LEVEL_ALL);
            String sql = "UPDATE " + CmnConst.PRODUCT_SYS_ORG_LEVELS + " SET org_level_all=replace(org_level_all,?,?)  where org_level_code_parent like concat(?,'%') ";
            baseDao.executeUpdate(sql, new Object[]{befor_level_all, org_level_all, org_level_code});
        }
 
    }
 
    /**
     * 更新下级机构全称
     *
     * @param before_org_level_all 更新前 机构全称
     * @param later_org_level_all  更新后 机构全称
     * @param org_level_code       机构编码
     * @return
     * @throws BaseException
     */
    public boolean updateOrgLevelAll(DataTableEntity before_org_level_all, DataTableEntity later_org_level_all,
                                     String org_level_code) throws BaseException {
        DataTableEntity level_dt = baseDao.listTable(CmnConst.PRODUCT_SYS_ORG_LEVELS,
                " org_level_code_parent like '" + org_level_code + "%'", new String[]{});
        if (level_dt.getRows() == 0)
            return true;
        String[] level_uuid_arr = new String[level_dt.getRows()];
        for (int i = 0; i < level_dt.getRows(); i++) {
            level_uuid_arr[i] = level_dt.getString(i, CmnConst.UUID);
        }
        String level_uuid = StringUtils.join(level_uuid_arr, ",");
        String level_uuid_new = level_uuid.replace(",", "','");
        DataTableEntity language_dt = baseDao.listTable(CmnConst.PRODUCT_SYS_LANGUAGE_CONT_VALUES,
                "data_uuid in('" + level_uuid_new + "') and field_name='org_level_all'", new String[]{});
        JSONObject before_level_all_json = dt_json(before_org_level_all);
        JSONObject later_level_all_json = dt_json(later_org_level_all);
        for (int i = 0; i < language_dt.getRows(); i++) {
            FieldSetEntity fs = language_dt.getFieldSetEntity(i);
            String new_field_value = fs.getString(CmnConst.FIELD_VALUE).replace(
                    before_level_all_json.get(fs.getString(CmnConst.LANGUAGE_CODE)).toString(),
                    later_level_all_json.get(fs.getString(CmnConst.LANGUAGE_CODE)).toString());
            fs.setValue(CmnConst.FIELD_VALUE, new_field_value);
        }
        boolean update = baseDao.update(language_dt);
        if (!update){
            return update;
        }
 
        if (SpringMVCContextHolder.getCurrentUser() != null) {
            String sql = "UPDATE " + CmnConst.PRODUCT_SYS_ORG_LEVELS + " SET org_level_all=replace(org_level_all,'"
                    + before_level_all_json.get("zh-CN").toString() + "','"
                    + later_level_all_json.get("zh-CN").toString() + "')  where org_level_code_parent like '"
                    + org_level_code + "%'";
            return baseDao.executeUpdate(sql);
        }
        return false;
    }
 
    // 将国际化dt转换未JSONObject
    public JSONObject dt_json(DataTableEntity dt) throws BaseException {
        JSONObject name_json = new JSONObject();
        for (int i = 0; i < dt.getRows(); i++) {
            FieldSetEntity level_name_fs = dt.getFieldSetEntity(i);
            if (null != level_name_fs.getString("en") && !"".contentEquals(level_name_fs.getString("en"))) {
                name_json.put("en", level_name_fs.getString("en"));
            }
            if (null != level_name_fs.getString("zh-CN") && !"".contentEquals(level_name_fs.getString("zh-CN"))) {
                name_json.put("zh-CN", level_name_fs.getString("zh-CN"));
            }
            if (null != level_name_fs.getString("zh-HK") && !"".contentEquals(level_name_fs.getString("zh-HK"))) {
                name_json.put("zh-HK", level_name_fs.getString("zh-HK"));
            }
        }
        return name_json;
    }
 
    /**
     * 机构全称拼接
     *
     * @param odlfs
     * @param org_level_name        机构名称
     * @return
     * @throws BaseException
     */
    public DataTableEntity jointOrgLevelAll(FieldSetEntity odlfs, DataTableEntity org_level_name) throws BaseException {
        String org_level_code_parent = odlfs.getString(CmnConst.ORG_LEVEL_CODE_PARENT);
        DataTableEntity odldt = baseDao.listTable(CmnConst.PRODUCT_SYS_LANGUAGE_CONT_VALUES,
                "data_uuid=? and field_name='org_level_all'", new String[]{odlfs.getUUID()});
        if (!StringUtils.isEmpty(org_level_code_parent) && null != org_level_name) {
            FieldSetEntity fs = baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_SYS_ORG_LEVELS, "org_level_code=?",
                    new Object[]{org_level_code_parent}, false);
            if (fs != null && fs.getString(CmnConst.ORG_LEVEL_ALL) != null) {
                JSONObject level_name_json = dt_json(org_level_name);
                DataTableEntity dt = baseDao.listTable(CmnConst.PRODUCT_SYS_LANGUAGE_CONT_VALUES,
                        "data_uuid=? and field_name='org_level_all'", new String[]{fs.getUUID()});
 
                DataTableEntity level_name_dt = new DataTableEntity();
                for (int i = 0; i < dt.getRows(); i++) {
                    FieldSetEntity level_all_fs = new FieldSetEntity();
                    FieldMetaEntity ff = new FieldMetaEntity();
                    ff.setTableName(new Object[]{"org_level_all"});
                    level_all_fs.setMeta(ff);
                    level_all_fs.setValue(dt.getString(i, CmnConst.LANGUAGE_CODE), dt.getString(i, CmnConst.FIELD_VALUE) + ">"
                            + level_name_json.get(dt.getString(i, CmnConst.LANGUAGE_CODE)));
                    for (int j = 0; j < odldt.getRows(); j++) {
                        if (dt.getString(i, CmnConst.LANGUAGE_CODE).equals(odldt.getString(j, CmnConst.LANGUAGE_CODE))) {
                            level_all_fs.setValue(CmnConst.UUID, odldt.getString(j, CmnConst.UUID));
                        }
                    }
 
                    level_name_dt.addFieldSetEntity(level_all_fs);
                }
                return level_name_dt;
            }
        }
 
        throw new BaseException(SystemCode.SYSTEM_FORM_NODATA.getValue(), SystemCode.SYSTEM_FORM_NODATA.getText(),
                this.getClass(), "jointOrgLevelAll");
    }
 
    /**
     * 查询制定部门详情
     *
     * @param uuid 部门uuid
     * @return
     * @throws BaseException
     */
    public FieldSetEntity findDept(String uuid) throws BaseException {
        return baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_SYS_ORG_LEVELS, "uuid=? and org_level_type=1",
                new Object[]{uuid}, false);
    }
}