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
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
package com.product.admin.service;
 
import com.alibaba.druid.util.StringUtils;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.product.admin.config.CmnConst;
import com.product.admin.config.SystemCode;
import com.product.admin.service.idel.ISelectPersonnelService;
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.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.core.transfer.Transactional;
import com.product.module.sys.entity.SystemUser;
import com.product.util.BaseUtil;
 
import java.util.Date;
import java.util.HashSet;
import org.springframework.beans.factory.annotation.Autowired;
import com.product.core.permission.PermissionService;
import org.springframework.stereotype.Service;
 
/**
 * Copyright LX-BASE
 * 
 * @Title: SelectPersonnelService
 * @Project: LX-BASE-SERVER
 * @Date: 2020年8月26日 17:33:37
 * @Author: luoxin
 * @Description: 组织架构
 */
//
@Service
public class SelectPersonnelService extends AbstractBaseService implements ISelectPersonnelService {
    @Autowired
    public BaseDao baseDao;
    @Autowired
    PermissionService permissionService;
    @Autowired
    QueryFilterService queryFilterService;
    @Override
    public BaseDao getBaseDao() {
        return baseDao;
    }
    @Override
    public void setBaseDao(BaseDao baseDao) {
        this.baseDao = baseDao;
    }
 
    @Override
    public JSONObject getOrganizationStructureTree(String theCompanyUuid) throws BaseException {
 
        FieldSetEntity company = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_ORG_LEVELS, theCompanyUuid, false);
        DataTableEntity data = baseDao.listTable(
                "SELECT * FROM product_sys_org_levels a\n"
                        + "WHERE a.org_level_code LIKE  CONCAT((SELECT org_level_code  FROM product_sys_org_levels \n"
                        + "WHERE uuid = ?), '%') AND org_level_type=1 AND org_level_status=0 ORDER BY a.org_level_code",
                new String[] { theCompanyUuid });
 
        JSONObject companyObject = new JSONObject();
        companyObject.put(CmnConst.UUID, company.getString(CmnConst.UUID));
        companyObject.put(CmnConst.ORG_LEVEL_NAME, company.getString(CmnConst.ORG_LEVEL_NAME));
        companyObject.put(CmnConst.ORG_LEVEL_ALL, company.getString(CmnConst.ORG_LEVEL_ALL));
        if (data.getRows() > 0) {
            companyObject.put("children", OrgLevelChildrenTree(data, company.getString("org_level_code")));
        }
 
        return companyObject;
    }
 
    @Override
    public JSONArray getOrganizationThoseWho(String tablenaem, String uuid) throws BaseException {
        // 获取公司或部门信息
        FieldSetEntity setEntity = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_ORG_LEVELS, uuid, false);
        // 1为部门 获取部门下的人或岗位
        DataTableEntity dataTableEntity;
    
        String dataFilter=permissionService.getDataFilter(CmnConst.ORG_LEVEL_UUID) ;
        
        if (setEntity.getString("org_level_type").equals("1")) {
            // 如果为岗位表
            if (CmnConst.PRODUCT_SYS_JOB_POSTS.equals(tablenaem)) {
                StringBuffer sql = new StringBuffer();
                sql.append(" SELECT * FROM ( ")
                        .append(" SELECT b.*,a.org_level_all FROM product_sys_org_levels a ")
                        .append(" LEFT JOIN product_sys_job_posts b ON a.uuid = b.dept_uuid ")
                        .append(" WHERE  b.is_used = '1' AND  b.dept_uuid = ? ) c");
                        if(!BaseUtil.strIsNull(dataFilter)) {
                        sql.append(" where " + dataFilter);
                        }
                dataTableEntity = baseDao.listTable(sql.toString(), new String[] { uuid });
            } else {
                StringBuffer filter = new StringBuffer();
                filter.append(" dept_uuid = ?  ");
                if(!BaseUtil.strIsNull(dataFilter)) {
                    filter.append(" and ").append(dataFilter);
                }
                dataTableEntity = baseDao.listTable(tablenaem, filter.toString(), new String[] { uuid });
                if (!BaseUtil.dataTableIsEmpty(dataTableEntity)) {
                    return acquireInternationalization(CmnConst.PRODUCT_SYS_JOB_POSTS, CmnConst.JOB_POST_NAME, dataTableEntity);
                }
            }
            // 0为公司 获取公司下的人
        } else {
            // 如果为岗位表
 
            if (CmnConst.PRODUCT_SYS_JOB_POSTS.equals(tablenaem)) {
                StringBuilder sql = new StringBuilder();
                sql.append(" SELECT * FROM ( ")
                    .append(" SELECT b.*,a.org_level_all FROM ")
                    .append(" product_sys_org_levels a LEFT JOIN ")
                    .append(" product_sys_job_posts b ON a.uuid = b.dept_uuid WHERE b.is_used = '1' AND b.org_level_uuid = ?) c ");
                if(!BaseUtil.strIsNull(dataFilter)) {
                        sql.append(" where " + dataFilter);
                        }
                dataTableEntity = baseDao.listTable(sql.toString(), new String[] { uuid });
            } else {
                StringBuffer filter = new StringBuffer();
                filter.append(" org_level_uuid = ?  ");
                if(!BaseUtil.strIsNull(dataFilter)) {
                    filter.append(" and ").append(dataFilter);
                }
                dataTableEntity = baseDao.listTable(tablenaem, filter.toString(),
                        new String[] { uuid });
                if (!BaseUtil.dataTableIsEmpty(dataTableEntity)) {
                    return acquireInternationalization(CmnConst.PRODUCT_SYS_JOB_POSTS,  CmnConst.JOB_POST_NAME, dataTableEntity);
                }
            }
 
        }
 
        return BaseUtil.dataTableEntityToJson(baseDao.listInternationDataTable(dataTableEntity, null));
    }
 
    /**
     * 通过员工data获取对应的国际化岗位 存入员工field
     * 
     * @param tableName  岗位表名
     * @param parameter  岗位字段
     * @param staffField 员工field数据
     * @return 员工field数据
     */
    public JSONObject acquireInternationalization(String tableName, String parameter, FieldSetEntity staffField)
            throws BaseException {
        FieldSetEntity set = staffField;
        JSONObject jsonObject = new JSONObject();
        // 员工uuid
        jsonObject.put(CmnConst.UUID, set.getString(CmnConst.UUID));
        // 员工展示名称
        jsonObject.put("show_name", set.getString("show_name"));
        // 岗位表UUID
        jsonObject.put(CmnConst.JOB_POST_UUID, set.getString(CmnConst.JOB_POST_UUID));
        // 公司uuid
        jsonObject.put("org_level_uuid", set.getString("org_level_uuid"));
        // 部门uuid
        jsonObject.put("dept_uuid", set.getString("dept_uuid"));
 
        // 国际化data
//        DataTableEntity data = baseDao.listInternationDataTable(tableName, new String[] { parameter },
//                new String[] { set.getString(CmnConst.JOB_POST_UUID) }, null);
//        JSONArray subArray = new JSONArray();
//        JSONObject obj;
//        FieldSetEntity fe;
//        for (int j = 0, le = data.getRows(); j < le; j++) {
//            obj = new JSONObject();
//            fe = data.getFieldSetEntity(j);
//            obj.put(String.valueOf(fe.getValues().get(CmnConst.LANGUAGE_CODE)),
//                    String.valueOf(fe.getValues().get(CmnConst.FIELD_VALUE)));
//            obj.put(CmnConst.UUID, String.valueOf(fe.getValues().get(CmnConst.UUID)));
//            subArray.add(obj);
//        }
//        jsonObject.put(parameter, subArray);
        return jsonObject;
    }
 
    /**
     * 通过员工data获取对应的国际化岗位 存入员工data
     * 
     * @param tableName 岗位表名
     * @param parameter 岗位字段
     * @param staffData 员工data数据
     * @return 员工data数据
     */
    public JSONArray acquireInternationalization(String tableName, String parameter, DataTableEntity staffData)
            throws BaseException {
        JSONArray array = new JSONArray();
        for (int i = 0, length = staffData.getRows(); i < length; i++) {
            array.add(acquireInternationalization(tableName, parameter, staffData.getFieldSetEntity(i)));
        }
        return array;
    }
 
    @Override
    @Transactional
    public String savePersonageTheGroup(FieldSetEntity fse) throws BaseException {
        SystemUser currentUser=SpringMVCContextHolder.getCurrentUser();
        String userId = String.valueOf(currentUser.getUser_id());
        String uuid;
        Integer groupType = fse.getInteger(CmnConst.GROUP_TYPE);
        String groupName = fse.getString(CmnConst.GROUP_NAME);
        FieldSetEntity fieldSetEntity = baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_SYS_GROUP, "group_name = ? and created_by = ? ",
                new String[] { groupName,userId }, false);
        // fieldSetEntity为空 新增
        if (fieldSetEntity == null) {
            fieldSetEntity = new FieldSetEntity();
            fieldSetEntity.setTableName(fse.getTableName());
            // 个人组 获取当前人ID uuid
            fieldSetEntity.setValue(CmnConst.USER_ID, SpringMVCContextHolder.getCurrentUser().getUser_id());
            fieldSetEntity.setValue(CmnConst.GROUP_TYPE, groupType);
            fieldSetEntity.setValue(CmnConst.GROUP_NAME, groupName);
            fieldSetEntity = BaseUtil.createCreatorAndCreationTime(SpringMVCContextHolder.getCurrentUser(),
                    fieldSetEntity);
            FieldMetaEntity f = new FieldMetaEntity();
            f.setTableName(new Object[]{CmnConst.GROUP_NAME});
            //luoxin 2020-12-17 11:38:31  新增时虚拟国际化
            DataTableEntity data = baseDao.listTable("SELECT language_code FROM product_common_language WHERE is_used = 1",new Object[]{});
            DataTableEntity dt = new DataTableEntity();
            dt.setMeta(f);
            for (int i = 0,length = data.getRows(); i < length; i++) {
                FieldSetEntity entity = new FieldSetEntity();
                entity.setMeta(f);
                String languageCode = data.getFieldSetEntity(i).getString("language_code");
                if(!BaseUtil.strIsNull(languageCode)){
                    entity.setValue(languageCode, groupName);
                    dt.addFieldSetEntity(entity);
                }
            }
            fieldSetEntity.addSubDataTable(dt);
            uuid = baseDao.add(fieldSetEntity);
            // fieldSetEntity不为空 替换
        } else {
            // 个人组 获取当前人ID uuid
            uuid = fieldSetEntity.getString(CmnConst.UUID);
            fieldSetEntity.setValue(CmnConst.USER_ID, SpringMVCContextHolder.getCurrentUser().getUser_id());
            fieldSetEntity.setValue(CmnConst.GROUP_TYPE, groupType);
            fieldSetEntity.setValue(CmnConst.GROUP_NAME, groupName);
            fieldSetEntity = baseDao.listInternationDataTable(fieldSetEntity,null);
            // 添加创建人
            fieldSetEntity = BaseUtil.createCreatorAndCreationTime(SpringMVCContextHolder.getCurrentUser(),
                    fieldSetEntity);
            // 清除子表
            baseDao.delete(CmnConst.PRODUCT_SYS_GROUP_SUB, CmnConst.GROUP_UUID+" = ? ", new Object[] { uuid });
            baseDao.update(fieldSetEntity);
        }
        // 添加子表
        DataTableEntity subData;
 
        // 员工map
        HashSet<Integer> hashSet = analyticalFramework(fse.getSubDataTable(CmnConst.PRODUCT_SYS_GROUP_SUB));
        if (hashSet.size() > 0) {
            subData = encapsulateTheUser(hashSet, uuid);
            baseDao.add(subData);
        }
 
        return uuid;
 
    }
 
    @Override
    @Transactional
    public String saveCompanyTheGroup(FieldSetEntity fse) throws BaseException {
        FieldSetEntity fieldSetEntity;
        String uuid = fse.getString(CmnConst.UUID);
        Integer groupType = fse.getInteger(CmnConst.GROUP_TYPE);
        // 获取子表
        DataTableEntity sub = fse.getSubDataTable(CmnConst.PRODUCT_SYS_GROUP_SUB);
        // uuid为空 新增
        if (uuid == null || uuid.isEmpty()) {
            fieldSetEntity = new FieldSetEntity();
            FieldMetaEntity f = new FieldMetaEntity();
            f.setTableName(new Object[] { fse.getTableName() });
            fieldSetEntity.setMeta(f);
            // 公司组 获取当前人ID uuid
            fieldSetEntity.setValue(CmnConst.COMPANY_UUID, fse.getString(CmnConst.COMPANY_UUID));
            fieldSetEntity.setValue(CmnConst.GROUP_TYPE, groupType);
            DataTableEntity group_name = fse.getSubDataTable(CmnConst.GROUP_NAME);
            FieldMetaEntity ff = new FieldMetaEntity();
            ff.setTableName(new Object[] { CmnConst.GROUP_NAME });
            group_name.setMeta(ff);
            fieldSetEntity.addSubDataTable(group_name);
            if (!StringUtils.isEmpty(fse.getString("sort"))) {
                fieldSetEntity.setValue("sort", Integer.parseInt(fse.getString("sort")));
            }
            fieldSetEntity = BaseUtil.createCreatorAndCreationTime(SpringMVCContextHolder.getCurrentUser(),
                    fieldSetEntity);
 
            uuid = baseDao.add(fieldSetEntity);
 
            // uuid不为空 替换
        } else {
            fieldSetEntity = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_GROUP, uuid, false);
            // 公司组 获取选择 uuid
            fieldSetEntity.setValue(CmnConst.COMPANY_UUID, fse.getString(CmnConst.COMPANY_UUID));
            fieldSetEntity.setValue(CmnConst.GROUP_TYPE, groupType);
            fieldSetEntity.setValue(CmnConst.COMPANY_UUID, fse.getString(CmnConst.COMPANY_UUID));
            fieldSetEntity.setValue(CmnConst.GROUP_TYPE, groupType);
            DataTableEntity group_name = fse.getSubDataTable(CmnConst.GROUP_NAME);
            FieldMetaEntity ff = new FieldMetaEntity();
            ff.setTableName(new Object[] { CmnConst.GROUP_NAME });
            group_name.setMeta(ff);
            fieldSetEntity.addSubDataTable(group_name);
            if (!StringUtils.isEmpty(fse.getString("sort"))) {
                fieldSetEntity.setValue("sort", Integer.parseInt(fse.getString("sort")));
            }
 
            // 添加创建人
            fieldSetEntity = BaseUtil.createCreatorAndCreationTime(SpringMVCContextHolder.getCurrentUser(),
                    fieldSetEntity);
            // 清除子表
            baseDao.delete(CmnConst.PRODUCT_SYS_GROUP_SUB, "group_uuid = ? ", new Object[] { uuid });
            // 架构子表
            baseDao.delete(CmnConst.PRODUCT_SYS_GROUP_SELECT, "group_uuid = ? ", new Object[] { uuid });
            baseDao.update(fieldSetEntity);
        }
        // 判断子表是否为空
        if (BaseUtil.dataTableIsEmpty(sub)) {
            return uuid;
        } else {
            // 添加子表
            DataTableEntity subData;
 
            // 员工map
            HashSet<Integer> hashSet = analyticalFramework(sub);
            if (hashSet.size() > 0) {
                // 创建用户子表
                subData = encapsulateTheUser(hashSet, uuid);
                // 保存用户子表
                baseDao.add(subData);
            }
 
            // 保存已经选择的架构子表
            DataTableEntity select = packagingSelect(sub, uuid);
            baseDao.add(select);
            return uuid;
        }
 
    }
 
    /**
     * 封装架构子表
     * 
     * @param sub       子表data
     * @param superUuid 组uuid
     * @return
     * @throws BaseException
     */
    public DataTableEntity packagingSelect(DataTableEntity sub, String superUuid) throws BaseException {
        DataTableEntity subData = new DataTableEntity();
        FieldSetEntity setEntity;
        FieldMetaEntity f = new FieldMetaEntity();
        f.setTableName(new Object[] { CmnConst.PRODUCT_SYS_GROUP_SELECT });
        subData.setMeta(f);
        // 保存组织架构子表
        for (int i = 0, length = sub.getRows(); i < length; i++) {
            setEntity = new FieldSetEntity();
            setEntity.setMeta(f);
            setEntity.setValue(CmnConst.ORGANIZATION_TYPES, sub.getFieldSetEntity(i).getString(CmnConst.ORGANIZATION_TYPES));
            setEntity.setValue(CmnConst.ORGANIZATION_UUIDS, sub.getFieldSetEntity(i).getString(CmnConst.ORGANIZATION_UUIDS));
            setEntity.setValue(CmnConst.GROUP_UUID, superUuid);
            setEntity = BaseUtil.createCreatorAndCreationTime(SpringMVCContextHolder.getCurrentUser(), setEntity);
            subData.addFieldSetEntity(setEntity);
        }
        return subData;
    }
 
    @Override
    @Transactional
    public boolean deleteTheGroup(FieldSetEntity fse) throws BaseException {
        String uuids = fse.getString("uuids");
        // 查询是否被引用
        String parameter = "%" + uuids + "%";
        DataTableEntity data = baseDao.listTable(
                "SELECT * FROM product_sys_organizational_structure_storage WHERE organization_uuids like ? ",
                new String[] { parameter });
        if (BaseUtil.dataTableIsEmpty(data)) {
            String[] uuid = uuids.split(",");
            //luoxin 2020-12-17 11:37:56修改删除方法
            for (int i = 0, length = uuid.length; i < length; ++i) {
                baseDao.delete(CmnConst.PRODUCT_SYS_GROUP, new String[] { uuid[i] });
            }
            return true;
        } else {
            return false;
        }
    }
 
    /**
     * 封装组子表
     * 
     * @param hashSet 用户id集
     * @param uuid    组uuid
     * @return
     * @throws BaseException
     */
    public DataTableEntity encapsulateTheUser(HashSet<Integer> hashSet, String uuid) throws BaseException {
        DataTableEntity subData = new DataTableEntity();
        FieldSetEntity setEntity;
        FieldMetaEntity f = new FieldMetaEntity();
        f.setTableName(new Object[] { CmnConst.PRODUCT_SYS_GROUP_SUB });
        subData.setMeta(f);
        for (Integer key : hashSet) {
            setEntity = new FieldSetEntity();
            setEntity.setMeta(f);
            setEntity.setValue(CmnConst.GROUP_UUID, uuid);
            setEntity.setValue(CmnConst.STAFF_ID, key);
            setEntity = BaseUtil.createCreatorAndCreationTime(SpringMVCContextHolder.getCurrentUser(), setEntity);
            subData.addFieldSetEntity(setEntity);
        }
        return subData;
    }
 
    @Override
    public DataTableEntity getTheGroup(FieldSetEntity fse) throws BaseException {
        String uuid = fse.getString(CmnConst.UUID);
        StringBuilder sql = new StringBuilder();
        sql.append("SELECT a.* FROM product_sys_staffs a ")
                .append("LEFT JOIN product_sys_group_sub b ON a.staff_id = b.staff_id WHERE group_uuid = ?");
        DataTableEntity dataTableEntity = baseDao.listTable(sql.toString(), new Object[] { uuid });
        return dataTableEntity;
    }
 
    @Override
    public DataTableEntity listAllGroup(FieldSetEntity fse) throws BaseException {
        // 当前人uuid
        int userId = SpringMVCContextHolder.getCurrentUser().getUser_id();
        // 公司uuid 4个人组 5单位组
        String companyUuid = fse.getString(CmnConst.COMPANY_UUID);
        companyUuid = "%" + companyUuid + "%";
        StringBuilder sql = new StringBuilder();
        sql.append("SELECT * FROM product_sys_group WHERE group_type = 4 AND user_id = ?  UNION ALL ")
                .append("SELECT * FROM product_sys_group WHERE group_type = 5 AND company_uuid like ? order by sort desc");
        return baseDao.listTable(sql.toString(), new Object[] { userId, companyUuid });
    }
 
    @Override
    public JSONObject listCompanyGroup(FieldSetEntity fse) throws BaseException {
        // 公司uuid
        String companyUuid = fse.getString(CmnConst.COMPANY_UUID);
        if(BaseUtil.strIsNull(companyUuid)){
            return null;
        }
        String queryFilter;
        Integer cpage = fse.getInteger("cpage");// 当前页数
        Integer pagesize = fse.getInteger("pagesize");// 每页条数
        if(BaseUtil.dataTableIsEmpty(fse.getSubDataTable("systemSeniorQueryString"))){
            queryFilter = " company_uuid = ? ";
        }else {
            queryFilter    = " company_uuid = ? AND " + queryFilterService.getQueryFilter(fse);
        }
        DataTableEntity dataTableEntity = baseDao.listTable(fse.getTableName(),queryFilter,new String[]{companyUuid},null,null, pagesize, cpage);
        JSONObject object = new JSONObject();
        if (BaseUtil.dataTableIsEmpty(dataTableEntity)) {
            object.put("data",dataTableEntity);
            return object;
        }
        JSONArray jsonArray = new JSONArray();
        for (int i = 0, length = dataTableEntity.getRows(); i < length; ++i) {
            FieldSetEntity set = dataTableEntity.getFieldSetEntity(i);
            String group_uuid = set.getString(CmnConst.UUID);
            JSONObject obj = new JSONObject();
            // 组名
            obj.put(CmnConst.UUID, group_uuid);
            //group_name国际化
            FieldSetEntity fee;
            JSONArray arr = new JSONArray();
            DataTableEntity dd = baseDao.listInternationDataTable(CmnConst.PRODUCT_SYS_GROUP,
                    new String[] { CmnConst.GROUP_NAME }, new String[] { group_uuid }, null);
            JSONObject object0;
            for (int j = 0, le = dd.getRows(); j < le; j++) {
                object0 = new JSONObject();
                fee = dd.getFieldSetEntity(j);
                // 国际化标识
                String languageCode = String.valueOf(fee.getValues().get(CmnConst.LANGUAGE_CODE));
                // 国际化值
                String fieldValue = String.valueOf(fee.getValues().get(CmnConst.FIELD_VALUE));
                // 国际uuid
                String uuid = String.valueOf(fee.getValues().get(CmnConst.UUID));
                object0.put(languageCode, fieldValue);
                object0.put(CmnConst.UUID, uuid);
                arr.add(object0);
            }
            obj.put("groupName", arr);
            JSONArray array = new JSONArray();
            StringBuilder sql = new StringBuilder();
            sql.append("SELECT a.organization_types,b.uuid,b.show_name name FROM product_sys_group_select a ")
                    .append("LEFT JOIN product_sys_staffs b ON a.organization_uuids = b.uuid ")
                    .append("WHERE a.organization_types = 1 AND a.group_uuid = ?  UNION ALL ")
                    .append("SELECT a.organization_types,b.uuid,b.org_level_name name FROM product_sys_group_select a ")
                    .append("LEFT JOIN product_sys_org_levels b ON a.organization_uuids = b.uuid ")
                    .append("WHERE a.organization_types = 2 AND a.group_uuid = ?  UNION ALL ")
                    .append("SELECT a.organization_types,b.uuid,b.job_post_name FROM product_sys_group_select a ")
                    .append("LEFT JOIN product_sys_job_posts b ON a.organization_uuids = b.uuid ")
                    .append("WHERE a.organization_types = 3 AND a.group_uuid = ? ");
            DataTableEntity table1 = baseDao.listTable(sql.toString(),new String[] { group_uuid, group_uuid, group_uuid });
            if (!BaseUtil.dataTableIsEmpty(table1)) {
                for (int k = 0, ta = table1.getRows(); k < ta; k++) {
                    FieldSetEntity setEntity = table1.getFieldSetEntity(k);
                    JSONObject ob = new JSONObject();
                    ob.put(CmnConst.ORGANIZATION_TYPES, setEntity.getString(CmnConst.ORGANIZATION_TYPES));
                    ob.put(CmnConst.ORGANIZATION_UUIDS, setEntity.getString(CmnConst.UUID));
                    if ("1".equals(setEntity.getString(CmnConst.ORGANIZATION_TYPES))) {
                        ob.put(CmnConst.ORGANIZATION_NAMES, setEntity.getString("name"));
                    }
                    //部门
                    if ("2".equals(setEntity.getString(CmnConst.ORGANIZATION_TYPES))) {
                        FieldSetEntity fe;
                        JSONArray ar = new JSONArray();
                        DataTableEntity d = baseDao.listInternationDataTable(CmnConst.PRODUCT_SYS_ORG_LEVELS,
                                new String[] { CmnConst.ORG_LEVEL_NAME }, new String[] { setEntity.getString(CmnConst.UUID) }, null);
                        JSONObject object1;
                        for (int j = 0, le = d.getRows(); j < le; j++) {
                            object1 = new JSONObject();
                            fe = d.getFieldSetEntity(j);
                            // 国际化标识
                            String languageCode = String.valueOf(fe.getValues().get(CmnConst.LANGUAGE_CODE));
                            // 国际化值
                            String fieldValue = String.valueOf(fe.getValues().get(CmnConst.FIELD_VALUE));
                            // 国际uuid
                            String uuid = String.valueOf(fe.getValues().get(CmnConst.UUID));
                            object1.put(languageCode, fieldValue);
                            object1.put(CmnConst.UUID, uuid);
                            ar.add(object1);
                        }
                        ob.put(CmnConst.ORGANIZATION_NAMES, ar);
                    }
                    //岗位
                    if ("3".equals(setEntity.getString(CmnConst.ORGANIZATION_TYPES))) {
                        FieldSetEntity fe;
                        JSONArray ar = new JSONArray();
                        DataTableEntity d = baseDao.listInternationDataTable(CmnConst.PRODUCT_SYS_JOB_POSTS,
                                new String[] { CmnConst.JOB_POST_NAME }, new String[] { setEntity.getString(CmnConst.UUID) }, null);
                        JSONObject object1;
                        for (int j = 0, le = d.getRows(); j < le; j++) {
                            object1 = new JSONObject();
                            fe = d.getFieldSetEntity(j);
                            // 国际化标识
                            String languageCode = String.valueOf(fe.getValues().get(CmnConst.LANGUAGE_CODE));
                            // 国际化值
                            String fieldValue = String.valueOf(fe.getValues().get(CmnConst.FIELD_VALUE));
                            // 国际uuid
                            String uuid = String.valueOf(fe.getValues().get(CmnConst.UUID));
                            object1.put(languageCode, fieldValue);
                            object1.put(CmnConst.UUID, uuid);
                            ar.add(object1);
                        }
                        ob.put(CmnConst.ORGANIZATION_NAMES, ar);
                    }
                    array.add(ob);
                }
            }
            obj.put("organization_info", array);
            jsonArray.add(obj);
        }
        object.put("data", jsonArray);
        object.put("totalCount", dataTableEntity.getSqle().getTotalCount());// 总条数
        object.put("totalpage", dataTableEntity.getSqle().getTotalpage());// 总页数
        object.put("psize", dataTableEntity.getSqle().getPsize());// 每页条数
        object.put("pindex", dataTableEntity.getSqle().getPindex());// 当前页
        object.put("datatable",dataTableEntity);
        return object;
    }
 
    @Override
    public FieldSetEntity getCompanyGroupInfo(FieldSetEntity fse) throws BaseException {
        String uuid = fse.getString(CmnConst.UUID);
        FieldSetEntity fieldSetEntity = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_GROUP, uuid, false);
        StringBuilder staffsSql = new StringBuilder();
        staffsSql.append("SELECT c.uuid FROM product_sys_group a  ")
                            .append("LEFT JOIN product_sys_group_select b ON a.uuid = b.group_uuid ")
                            .append("LEFT JOIN product_sys_staffs c ON c.uuid = b.organization_uuids ")
                            .append("WHERE a.group_type = 5 AND b.organization_types = '1' AND a.uuid = ?");
        DataTableEntity staffs = baseDao.listTable(staffsSql.toString(), new String[] { uuid });
        if (!BaseUtil.dataTableIsEmpty(staffs)) {
            StringBuilder staffsUuids = new StringBuilder();
            for (int i = 0, length = staffs.getRows(); i < length; ++i) {
                staffsUuids.append(staffs.getFieldSetEntity(i).getString(CmnConst.UUID)).append(",");
            }
            String suuid = staffsUuids.substring(0, staffsUuids.length() - 1);
            fieldSetEntity.setValue("staffsUuids", suuid);
        }
        StringBuilder levelsSql = new StringBuilder();
        levelsSql.append("SELECT c.uuid FROM product_sys_group a ")
                            .append("LEFT JOIN product_sys_group_select b ON a.uuid = b.group_uuid ")
                            .append("LEFT JOIN product_sys_org_levels c ON c.uuid = b.organization_uuids ")
                            .append("WHERE a.group_type = 5 AND b.organization_types = '2' AND a.uuid = ? ");
        DataTableEntity levels = baseDao.listTable(levelsSql.toString(), new String[] { uuid });
        if (!BaseUtil.dataTableIsEmpty(levels)) {
            StringBuilder levelsUuids = new StringBuilder();
            for (int i = 0, length = levels.getRows(); i < length; ++i) {
                levelsUuids.append(levels.getFieldSetEntity(i).getString(CmnConst.UUID)).append(",");
            }
            String luuid = levelsUuids.substring(0, levelsUuids.length() - 1);
            fieldSetEntity.setValue("levelsUuids", luuid);
        }
        StringBuilder postsSql = new StringBuilder();
        postsSql.append("SELECT c.uuid FROM product_sys_group a ")
                        .append("LEFT JOIN product_sys_group_select b ON a.uuid = b.group_uuid ")
                        .append("LEFT JOIN product_sys_job_posts c ON c.uuid = b.organization_uuids ")
                        .append("WHERE a.group_type = 5 AND b.organization_types = '3' AND a.uuid = ? ");
        DataTableEntity posts = baseDao.listTable(postsSql.toString(), new String[] { uuid });
        if (!BaseUtil.dataTableIsEmpty(posts)) {
            StringBuilder postsUuids = new StringBuilder();
            for (int i = 0, length = posts.getRows(); i < length; ++i) {
                postsUuids.append(posts.getFieldSetEntity(i).getString(CmnConst.UUID)).append(",");
            }
            String puuid = postsUuids.substring(0, postsUuids.length() - 1);
            fieldSetEntity.setValue("postsUuids", puuid);
        }
        FieldSetEntity fs = baseDao.listInternationDataTable(fieldSetEntity,null);
 
        return fs;
    }
 
    /**
     *
     * @param organizationalData 要处理的DATA
     * @param fieldSetEntity     存值fs
     * @param name               名称集
     * @param type               类型集
     * @param uuid               uuid集
     * @return 返回fs
     * @throws BaseException
     */
    public FieldSetEntity encapsulatedOrganizationStructure(DataTableEntity organizationalData,
            FieldSetEntity fieldSetEntity, String name, String type, String uuid) throws BaseException {
        if (organizationalData != null && organizationalData.getRows() > 0) {
            StringBuilder names = new StringBuilder();
            StringBuilder types = new StringBuilder();
            StringBuilder uuids = new StringBuilder();
            names.append(organizationalData.getFieldSetEntity(0).getString(name));
            types.append(organizationalData.getFieldSetEntity(0).getString(type));
            uuids.append(organizationalData.getFieldSetEntity(0).getString(uuid));
            for (int i = 1, length = organizationalData.getRows(); i < length; ++i) {
                FieldSetEntity setEntity = organizationalData.getFieldSetEntity(i);
                names.append(",").append(setEntity.getString(name));
                types.append(",").append(setEntity.getString(type));
                uuids.append(",").append(setEntity.getString(uuid));
            }
            fieldSetEntity.setValue(name, names.toString());
            fieldSetEntity.setValue(type, types.toString());
            fieldSetEntity.setValue(uuid, uuids.toString());
 
        } else {
            fieldSetEntity.setValue(name, "");
            fieldSetEntity.setValue(type, "");
            fieldSetEntity.setValue(uuid, "");
        }
        return fieldSetEntity;
    }
 
    /**
     * 保存组织架构信息 并保存人的组织架构下的人id
     * 
     * @param fse 组信息
     * @return
     * @throws BaseException
     */
    @Override
    @Transactional
    public String saveOrganization(FieldSetEntity fse) throws BaseException {
        String uuid = fse.getString(CmnConst.UUID);
        DataTableEntity organizationalData = fse.getSubDataTable("organizational_sub");
            // 创建组织架构储存表
            FieldSetEntity fieldSetEntity = new FieldSetEntity();
            FieldMetaEntity f = new FieldMetaEntity();
            f.setTableName(new Object[]{fse.getTableName()});
            fieldSetEntity.setMeta(f);
        if(!BaseUtil.dataTableIsEmpty(organizationalData)) {
            fieldSetEntity = encapsulatedOrganizationStructure(organizationalData, fieldSetEntity, CmnConst.ORGANIZATION_NAMES,
                    CmnConst.ORGANIZATION_TYPES, CmnConst.ORGANIZATION_UUIDS);
            HashSet<Integer> set = analyticalFramework(organizationalData);
            if (!set.isEmpty() && set.size() > 0) {
                StringBuilder userIds = new StringBuilder();
                for (Integer key : set) {
                    // 拼接员工id集
                    userIds.append(key).append(",");
                }
                String Ids = userIds.substring(0, userIds.length() - 1);
                // 储存员工id集
                fieldSetEntity.setValue("staff_ids", Ids);
            } else {
                fieldSetEntity.setValue("staff_ids", "");
            }
            // 新增
            if (uuid == null || uuid.isEmpty()) {
                fieldSetEntity = BaseUtil.createCreatorAndCreationTime(SpringMVCContextHolder.getCurrentUser(),
                        fieldSetEntity);
                uuid = baseDao.add(fieldSetEntity);
                // 修改
            } else {
                fieldSetEntity.setValue(CmnConst.UUID, uuid);
                fieldSetEntity = BaseUtil.updatedRegeneratorAndUpdateTime(SpringMVCContextHolder.getCurrentUser(),
                        fieldSetEntity);
                baseDao.update(fieldSetEntity);
            }
        }else {
            baseDao.executeUpdate("update product_sys_organizational_structure_storage set `organization_names` = null, `staff_ids` = null, `organization_uuids` = null, `organization_types` = null where uuid = ? ",new String[]{uuid});
        }
        return uuid;
    }
 
    @Override
    public JSONArray getAtPresentOrganization(FieldSetEntity fse) throws BaseException {
        FieldSetEntity set = baseDao.getFieldSetEntity(fse.getTableName(), fse.getString(CmnConst.UUID), false);
        if (set == null) {
            return null;
        }
        String names = set.getString(CmnConst.ORGANIZATION_NAMES);
        JSONArray array = new JSONArray();
        // 没有值
        if (StringUtils.isEmpty(names)) {
            return array;
        } else {
            String types = set.getString(CmnConst.ORGANIZATION_TYPES);
            String uuids = set.getString(CmnConst.ORGANIZATION_UUIDS);
            String[] type = types.split(",");
            String[] uuid = uuids.split(",");
            FieldSetEntity fieldSetEntity;
 
            for (int i = 0, length = type.length; i < length; ++i) {
                // 员工
                switch (type[i]){
                    case "1":
                    fieldSetEntity = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_STAFFS, uuid[i], false);
                    break;
                    // 部门
                    case "2":
                    fieldSetEntity = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_ORG_LEVELS, uuid[i], false);
                    break;
                    // 岗位
                    case "3":
                    StringBuilder sql = new StringBuilder();
                    sql.append("SELECT b.*,a.org_level_all FROM product_sys_org_levels a LEFT JOIN ")
                            .append("product_sys_job_posts b ON a.uuid = b.dept_uuid WHERE b.uuid = ? ");
                    DataTableEntity data = baseDao.listTable(sql.toString(), new String[] { uuid[i] });
                    fieldSetEntity = data.getFieldSetEntity(0);
                    fieldSetEntity = baseDao.listInternationDataTable(fieldSetEntity, null);
                        break;
                    // 个人组或单位组
                    default:
                    fieldSetEntity = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_GROUP, uuid[i], false);
                }
                // 放入结构类型
                if (fieldSetEntity != null) {
                    fieldSetEntity.setValue("type", type[i]);
                    // 为人员要添加对应国际化岗位
                    if ("1".equals(type[i])) {
                        JSONObject object = acquireInternationalization(CmnConst.PRODUCT_SYS_JOB_POSTS,  CmnConst.JOB_POST_NAME,
                                fieldSetEntity);
                        object.put("type", type[i]);
                        array.add(object);
                    } else {
                        array.add(BaseUtil.fieldSetEntityToJson(fieldSetEntity));
                    }
                }
            }
            return array;
        }
    }
 
    /**
     * 获取单位 部门 岗位组下的人 员工
     * 
     * @param dataTableEntity
     * @return
     */
    public HashSet<Integer> analyticalFramework(DataTableEntity dataTableEntity) throws BaseException {
        FieldSetEntity fieldSetEntity;
        FieldSetEntity set;
        DataTableEntity data;
        HashSet<Integer> hashSet = new HashSet<>();
        if(BaseUtil.dataTableIsEmpty(dataTableEntity)){
            return hashSet;
        }
        for (int i = 0, length = dataTableEntity.getRows(); i < length; i++) {
            fieldSetEntity = dataTableEntity.getFieldSetEntity(i);
            String type = fieldSetEntity.getString(CmnConst.ORGANIZATION_TYPES);
            String uuid = fieldSetEntity.getString(CmnConst.ORGANIZATION_UUIDS);
            // 员工
            if ("1".equals(type)) {
                set = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_STAFFS, uuid, false);
                hashSet.add(set.getInteger(CmnConst.STAFF_ID));
                // 部门
            } else if ("2".equals(type)) {
                data = baseDao.listTable(CmnConst.PRODUCT_SYS_STAFFS, "dept_uuid = ?", new Object[] { uuid });
                for (int j = 0, len = data.getRows(); j < len; j++) {
                    hashSet.add(data.getFieldSetEntity(j).getInteger(CmnConst.STAFF_ID));
                }
                // 岗位
            } else if ("3".equals(type)) {
                data = baseDao.listTable(CmnConst.PRODUCT_SYS_STAFFS, "job_post_uuid = ?", new Object[] { uuid });
                for (int j = 0, len = data.getRows(); j < len; j++) {
                    hashSet.add(data.getFieldSetEntity(j).getInteger(CmnConst.STAFF_ID));
                }
                // 单位组或个人组
            } else {
                data = baseDao.listTable(
                        "SELECT b.* FROM product_sys_group_sub a LEFT JOIN product_sys_staffs b on a.staff_id = b.staff_id WHERE group_uuid = ?",
                        new Object[] { uuid });
                for (int j = 0, len = data.getRows(); j < len; j++) {
                    hashSet.add(data.getFieldSetEntity(j).getInteger(CmnConst.STAFF_ID));
                }
            }
        }
        return hashSet;
    }
 
    /**
     * 封装组织架构树
     * 
     * @param data
     * @param org_level_code 上级code
     * @return
     * @throws BaseException
     */
    public JSONArray OrgLevelChildrenTree(DataTableEntity data, String org_level_code) throws BaseException {
        JSONArray children_array = new JSONArray();
        if (!StringUtils.isEmpty(org_level_code)) {
            for (int i = 0; i < data.getRows(); i++) {
                FieldSetEntity fs = data.getFieldSetEntity(i);
                if (org_level_code.equals(fs.getString("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.getString(CmnConst.ORG_LEVEL_NAME));
                    org_children.put(CmnConst.ORG_LEVEL_ALL, fs.getString(CmnConst.ORG_LEVEL_ALL));
                    org_children.put("children", OrgLevelChildrenTree(data, fs.getString("org_level_code")));
                    children_array.add(org_children);
                }
            }
        }
        return children_array;
    }
 
    /**
     * 定时执行更新组织架构
     * 
     * @throws BaseException
     */
    public void timingOrganization() throws BaseException {
        DataTableEntity dt = baseDao.listTable(CmnConst.PRODUCT_SYS_ORGANIZATIONAL_STRUCTURE_STORAGE, "is_auto_update=1");
        for (int i = 0; i < dt.getRows(); i++) {
            FieldSetEntity fs = dt.getFieldSetEntity(i);
            FieldSetEntity fss = new FieldSetEntity();
            FieldMetaEntity f = new FieldMetaEntity();
            f.setTableName(new Object[] { CmnConst.PRODUCT_SYS_ORGANIZATIONAL_STRUCTURE_STORAGE });
            fss.setMeta(f);
            fss.setValue(CmnConst.UUID, fs.getString(CmnConst.UUID));
 
            DataTableEntity subDt = new DataTableEntity();
            String[] organization_names = fs.getString(CmnConst.ORGANIZATION_NAMES).split(",");
            String[] organization_types = fs.getString(CmnConst.ORGANIZATION_TYPES).split(",");
            String[] organization_uuids = fs.getString(CmnConst.ORGANIZATION_UUIDS).split(",");
            if (organization_names.length != organization_types.length
                    || organization_types.length != organization_uuids.length) {
                throw new BaseException(SystemCode.SYSTEM_UPDATE_TIMINGORGANIZATION_CENTER.getText(),
                        SystemCode.SYSTEM_UPDATE_TIMINGORGANIZATION_CENTER.getValue(), this.getClass(),
                        "timingOrganization");
            }
            for (int j = 0; j < organization_names.length; j++) {
                FieldSetEntity existencefSetEntity = null;
                switch (organization_types[j]){
                    case "1":
                    existencefSetEntity = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_STAFFS, organization_uuids[j], false);
                    break;
                    case "2":
                    existencefSetEntity = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_ORG_LEVELS, organization_uuids[j],
                            false);
                    break;
                    case "3":
                    existencefSetEntity = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_JOB_POSTS, organization_uuids[j],
                            false);
 
                    break;
                    case "4":
                    case "5":
                    existencefSetEntity = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_GROUP, organization_uuids[j], false);
                    break;
                    default:
            }
                if (existencefSetEntity != null) {
                    FieldSetEntity sbufss = new FieldSetEntity();
                    FieldMetaEntity subf = new FieldMetaEntity();
                    subf.setTableName(new Object[] { "organizational_sub" });
                    sbufss.setMeta(subf);
                    sbufss.setValue(CmnConst.ORGANIZATION_NAMES, organization_names[j]);
                    sbufss.setValue(CmnConst.ORGANIZATION_TYPES, organization_types[j]);
                    sbufss.setValue(CmnConst.ORGANIZATION_UUIDS, organization_uuids[j]);
                    subDt.addFieldSetEntity(sbufss);
                }
            }
            if (subDt.getRows() == 0) {
                baseDao.delete(CmnConst.PRODUCT_SYS_ORGANIZATIONAL_STRUCTURE_STORAGE, "uuid=?",
                        new String[] { fs.getString(CmnConst.UUID) });
            } else {
                fss.addSubDataTable(subDt);
                saveOrganization(fss);
            }
        }
 
    }
 
 
    /**
     * 修改员工岗位或部门就修改组内容
      * @param department_uuid 部门uuid
     * @param company_uuid 岗位uuid
     * @param staff_uuid 员工uuid
     */
    public void updataGruopContent(String department_uuid,String company_uuid,String staff_uuid) throws BaseException{
 
        FieldSetEntity staff = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_STAFFS,staff_uuid,false);
        if (staff == null){
            return;
        }
        String staff_id = staff.getString(CmnConst.STAFF_ID);
            //当前人之前岗位或部门是否在组里面  在组里
 
            StringBuilder sql = new StringBuilder();
            sql.append(" SELECT b.uuid FROM product_sys_group_select a LEFT JOIN product_sys_group_sub b on a.group_uuid = b.group_uuid ")
                     .append(" WHERE b.staff_id = ? AND (a.organization_types = 2 or a.organization_types = 3) AND a.group_uuid not in ( ")
                     .append(" SELECT c.group_uuid FROM product_sys_group_select c WHERE c.organization_types = 1) GROUP BY b.uuid");
            DataTableEntity dataTableEntity = baseDao.listTable(sql.toString(), new Object[]{staff_id});
            for (int i = 0,length = dataTableEntity.getRows(); i < length; i++) {
                FieldSetEntity fieldSetEntity = dataTableEntity.getFieldSetEntity(i);
                //删除之前的组成员
                baseDao.delete(CmnConst.PRODUCT_SYS_GROUP_SUB,new String[]{fieldSetEntity.getString(CmnConst.UUID)});
            }
        //查询当前部门或岗位是否存在组里面
        DataTableEntity dataOrganization = baseDao.listTable("SELECT * FROM product_sys_group_select WHERE (organization_types = 2 AND organization_uuids = ? ) or (organization_types = 3 AND organization_uuids = ?)", new Object[]{department_uuid, company_uuid});
        //当前部门或岗位在组里面
        if(!BaseUtil.dataTableIsEmpty(dataOrganization)){
            for (int i = 0,length = dataOrganization.getRows(); i < length; i++) {
                FieldSetEntity fieldOrganization = dataOrganization.getFieldSetEntity(i);
                //组主表uuid
                String group_uuid = fieldOrganization.getString(CmnConst.GROUP_UUID);
                //组uuid
                String organization_uuids = fieldOrganization.getString(CmnConst.ORGANIZATION_UUIDS);
                // 部门 2
                if(fieldOrganization.getString(CmnConst.ORGANIZATION_TYPES).equals("2")){
                    addGruopContent(organization_uuids,department_uuid,group_uuid,staff_id);
                    // 岗位 3
                }else if(fieldOrganization.getString(CmnConst.ORGANIZATION_TYPES).equals("3")){
                    addGruopContent(organization_uuids,company_uuid,group_uuid,staff_id);
                }
            }
        }
    }
 
    /**
     * 组岗位部门新增员工 时时修改群主表
     * @param organization_uuids 组的部门和岗位uuid
     * @param company_uuid 部门或岗位uuid
     * @param group_uuid 组uuid
     * @param staff_id 员工id
     */
    public void addGruopContent(String organization_uuids,String company_uuid,String group_uuid,String staff_id) throws BaseException{
        //当前人岗位跟公司组岗位相等
        if(organization_uuids.equals(company_uuid)){
            //查询组部门下是否有此人
            DataTableEntity data = baseDao.listTable("SELECT * FROM product_sys_group_sub WHERE group_uuid = ? AND staff_id = ?",new Object[]{group_uuid,staff_id});
            //为空就新增一条数据
            if(BaseUtil.dataTableIsEmpty(data)){
                    FieldSetEntity newField = new FieldSetEntity();
                    newField.setTableName(CmnConst.PRODUCT_SYS_GROUP_SUB);
                    newField.setValue(CmnConst.GROUP_UUID,group_uuid);
                    newField.setValue(CmnConst.STAFF_ID,staff_id);
                    newField.setValue(CmnConst.CREATED_BY,SpringMVCContextHolder.getCurrentUser().getUser_id());
                    newField.setValue(CmnConst.CREATED_UTC_DATETIME,new Date());
                    baseDao.add(newField);
            }
        }
    }
}