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
package com.product.org.admin.service;
 
import com.alibaba.druid.util.StringUtils;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.product.core.config.CoreConst;
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.service.support.QueryFilterService;
import com.product.core.spring.context.SpringMVCContextHolder;
import com.product.core.transfer.Transactional;
import com.product.module.sys.config.SystemErrorCode;
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.ISystemPostGradesService;
import com.product.org.admin.util.InternationalLanguage;
import com.product.util.BaseUtil;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import java.util.*;
import java.util.Map.Entry;
 
/**
 * Copyright © 2020 LX-BASE
 *
 * @Title: LX-BASE-SERVER
 * @Project: base-server-org-admin
 * @Date: 2020年6月10日
 * @Author: Mr.Xu
 * @Description:岗位等级管理
 */
@Component
public class SystemPostGradesService extends AbstractBaseService implements ISystemPostGradesService {
 
    @Autowired
    public BaseDao dao;
    @Autowired
    PermissionService permissionService;
    @Autowired
    public QueryFilterService queryFilterService;
 
    /**
     * 岗位等级列表
     *
     * @param fse
     * @return
     * @throws BaseException
     */
    public DataTableEntity listPostGrades(FieldSetEntity fse) throws BaseException {
        // 数据策略
        String dataFilter = permissionService.getDataFilter(CmnConst.ORG_LEVEL_UUID);
        // 高级搜索
        String queryFilter = queryFilterService.getQueryFilter(fse);
        if (!StringUtils.isEmpty(dataFilter)) {
            dataFilter = " WHERE " + dataFilter;
            if (!StringUtils.isEmpty(queryFilter)) {
                dataFilter += " AND " + queryFilter;
            }
        } else {
            if (!StringUtils.isEmpty(queryFilter)) {
                dataFilter = " WHERE " + queryFilter;
            }
        }
        String org_level_code = SpringMVCContextHolder.getCurrentUser().getOrg_level_code();
        StringBuilder sql = new StringBuilder();
        List<String> fieList = new ArrayList<>();
        // sql拼接执行
        appendListSql(dataFilter, org_level_code, sql, fieList);
        // 获取岗位等级分组和单个岗位等级
        DataTableEntity dtPostGrades = dao.listTable(sql.toString(), fieList.toArray(), fse.getInteger(CmnConst.PAGESIZE), fse.getInteger(CmnConst.CPAGE));
        if (dtPostGrades != null && dtPostGrades.getRows() > 0) {
/*            
            dao.listInternationDataTable((dtPostGrades),null);
            
            // 遍历岗位等级
            List<String> list = new ArrayList<>();
            for (int i = 0; i < dtPostGrades.getRows(); i++) {
                FieldSetEntity fsePostGrades = dtPostGrades.getFieldSetEntity(i);
 
                String group_name = fsePostGrades.getString("group_name");
 
                boolean contains = list.contains(group_name);
                if (contains && !StringUtils.isEmpty(group_name)) {
                    dtPostGrades.removeFieldSetEntity(i);
                    i--;
                    continue;
                } else {
                    list.add(group_name);
                }
                //根据是否有组名判断是单个等级还是分组等级 单个等级只需要国际化即可 分组等级需将每个等级名称相同国际化数据拼接后,生成新的国际化等级名称
                if (!StringUtils.isEmpty(group_name)) {
                    getGroupList(group_name, fsePostGrades);
                }
            }
*/
        }
 
        dao.loadPromptData(dtPostGrades);
        return dtPostGrades;
    }
 
    private void getGroupList(String group_name, FieldSetEntity fsePostGrades) {
        // 获取每个组的岗位等级
        DataTableEntity dtGradesLanguage = dao.listInternationDataTable(
                dao.listTable(CmnConst.PRODUCT_SYS_JOB_POST_GRAGES, "group_name=?", new Object[]{group_name}), null);
 
        if (dtGradesLanguage != null && dtGradesLanguage.getRows() > 0) {
 
            // 装载最新的国际化等级数据
            Map<String, String> all_language_code_Value = new HashMap<>();
 
            // 遍历每个岗位等级信息
            for (int j = 0; j < dtGradesLanguage.getRows(); j++) {
 
                FieldSetEntity fseGradeLanguage = dtGradesLanguage.getFieldSetEntity(j);
 
                // 获取等级名称国际化数据
                DataTableEntity gradeLanguage = fseGradeLanguage.getSubDataTable("job_grade_name");
 
                // 获取等级名称国际化数据(language_code,language_value)
                Map<String, String> mapLanguage = InternationalLanguage.parseLanguage(gradeLanguage);
 
                if (mapLanguage != null) {
                    forMapLanguage(mapLanguage, all_language_code_Value);
                }
            }
            if (!all_language_code_Value.isEmpty()) {
                DataTableEntity dtJobPostGradeslanguage = new DataTableEntity();
                FieldMetaEntity fseMate = new FieldMetaEntity();
                dtJobPostGradeslanguage.setMeta(fseMate);
                fseMate.setTableName(new Object[]{"job_grade_name"});
                for (Entry<String, String> key : all_language_code_Value.entrySet()) {
                    FieldSetEntity fseJobPostGradesLanguage = new FieldSetEntity();
                    fseJobPostGradesLanguage.setMeta(fseMate);
                    fseJobPostGradesLanguage.setValue("language_code", key.getKey());
                    fseJobPostGradesLanguage.setValue(key.getKey(), key.getValue());
                    dtJobPostGradeslanguage.addFieldSetEntity(fseJobPostGradesLanguage);
                }
                Map<String, DataTableEntity> map = new HashMap<>();
                map.put("job_grade_name", dtJobPostGradeslanguage);
                fsePostGrades.setSubData(map);
            }
        }
 
    }
 
    private void forMapLanguage(Map<String, String> mapLanguage, Map<String, String> all_language_code_Value) {
        for (Entry<String, String> mapLanguageMap : mapLanguage.entrySet()) {
            String language_value = mapLanguageMap.getValue();
            String language_key = mapLanguageMap.getKey();
            if (all_language_code_Value.get(language_key) == null) {
                all_language_code_Value.put(language_key, language_value);
            } else {
                all_language_code_Value.put(language_key,
                        all_language_code_Value.get(language_key) + "," + language_value);
            }
        }
 
    }
 
    private void appendListSql(String queryFilter, String org_level_code, StringBuilder sql, List<String> fieList) {
        if (StringUtils.isEmpty(org_level_code)) {
            sql.append(
                    " select a.job_grade_id,a.staff_number,a.job_grade_class,uuid,group_name,org_level_uuid org_level_name,job_grade_name,is_used ");
            sql.append(" FROM( ");
            sql.append(
                    " select job_grade_id,SUM(staff_number)staff_number,GROUP_CONCAT(job_grade_class) job_grade_class from ( ");
            sql.append(
                    " select *,(select count(*) FROM product_sys_job_posts_grades_mapping where job_grade_uuid =a.uuid) staff_number FROM product_sys_job_post_grades a ");
            sql.append(" )a where group_name IS NOT NULL GROUP BY job_grade_id,group_name,org_level_uuid ");
            sql.append(" UNION ALL ");
            sql.append(
                    " select job_grade_id,SUM(staff_number)staff_number,GROUP_CONCAT(job_grade_class) job_grade_class from ( ");
            sql.append(
                    " select *,(select count(*) FROM product_sys_job_posts_grades_mapping where job_grade_uuid =a.uuid) staff_number FROM product_sys_job_post_grades a ");
            sql.append(" )a where group_name IS NULL GROUP BY job_grade_id,job_grade_name,org_level_uuid ");
            sql.append(" )a ");
            sql.append(" left Join  product_sys_job_post_grades b on a.job_grade_id=b.job_grade_id " + queryFilter);
        } else {
            sql.append(" SELECT uuid,group_name,job_grade_name,job_grade_class,staff_number,");
            sql.append(" (SELECT ORG_LEVEL_NAME FROM product_sys_org_levels WHERE uuid=a.org_level_uuid)org_level_uuid ");
            sql.append(" FROM( ");
            sql.append(" SELECT null uuid,group_name,GROUP_CONCAT(job_grade_name) job_grade_name,GROUP_CONCAT(job_grade_class) job_grade_class,org_level_uuid,SUM(staff_number) staff_number ");
            sql.append(" FROM (SELECT *, ( SELECT count( * ) FROM product_sys_job_posts_grades_mapping WHERE job_grade_uuid = a.uuid) staff_number FROM product_sys_job_post_grades a) a ");
            sql.append(" WHERE group_name IS NOT NULL AND org_level_uuid IN ( SELECT uuid FROM product_sys_org_levels WHERE org_level_code LIKE concat( ?, '%' )) ");
            sql.append(" GROUP BY ");
            sql.append(" group_name,org_level_uuid ");
            sql.append(" UNION ALL ");
            sql.append(" SELECT uuid,group_name,job_grade_name,job_grade_class,org_level_uuid,SUM(staff_number) staff_number ");
            sql.append(" FROM (SELECT *, ( SELECT count( * ) FROM product_sys_job_posts_grades_mapping WHERE job_grade_uuid = a.uuid) staff_number FROM product_sys_job_post_grades a) a ");
            sql.append(" WHERE group_name IS NULL AND org_level_uuid IN ( SELECT uuid FROM product_sys_org_levels WHERE org_level_code LIKE concat( ?, '%' )) ");
            sql.append(" GROUP BY job_grade_id,job_grade_name,org_level_uuid ");
            sql.append(" )a " + queryFilter);
/*            
            sql.append(
                    " select a.job_grade_id,a.staff_number,a.job_grade_class,uuid,group_name,org_level_uuid,job_grade_name,is_used ");
            sql.append(" FROM( ");
            sql.append(
                    " select job_grade_id,SUM(staff_number)staff_number,GROUP_CONCAT(job_grade_class) job_grade_class from ( ");
            sql.append(
                    " select *,(select count(*) FROM product_sys_job_posts_grades_mapping where job_grade_uuid =a.uuid) staff_number FROM product_sys_job_post_grades a ");
            sql.append(
                    " )a where group_name IS NOT NULL AND org_level_uuid in  (select uuid  FROM product_sys_org_levels where org_level_code like concat(?,'%')) GROUP BY job_grade_id,group_name,org_level_uuid ");
            sql.append(" UNION ALL ");
            sql.append(
                    " select job_grade_id,SUM(staff_number)staff_number,GROUP_CONCAT(job_grade_class) job_grade_class from ( ");
            sql.append(
                    " select *,(select count(*) FROM product_sys_job_posts_grades_mapping where job_grade_uuid =a.uuid) staff_number FROM product_sys_job_post_grades a ");
            sql.append(
                    " )a where group_name IS NULL AND org_level_uuid in  (select uuid  FROM product_sys_org_levels where org_level_code like concat(?,'%')) GROUP BY job_grade_id,job_grade_name,org_level_uuid ");
            sql.append(" )a ");
            sql.append(" left Join .PRODUCT_SYS_job_post_grades b on a.job_grade_id=b.job_grade_id " + queryFilter);
*/
            fieList.add("%" + org_level_code + "%");
            fieList.add("%" + org_level_code + "%");
        }
    }
 
    /**
     * 查询岗位等级详情
     *
     * @param fse
     * @return
     * @throws BaseException
     */
    public FieldSetEntity findPostGrades(FieldSetEntity fse) throws BaseException {
        FieldSetEntity fs = dao.getFieldSetEntity(CmnConst.PRODUCT_SYS_JOB_POST_GRAGES, fse.getString(CmnConst.UUID),
                false);
        // 设置岗位国际化名
        return dao.listInternationDataTable(fs, null);
    }
 
    /**
     * 查询一组岗位等级详情
     *
     * @param fse
     * @return
     * @throws BaseException
     */
    public JSONObject findPostGradesGroup(FieldSetEntity fse) throws BaseException {
        if (!StringUtils.isEmpty(fse.getString("group_name"))) {
            SQLEntity sql = new SQLEntity();
            sql.setTableNames(CmnConst.PRODUCT_SYS_JOB_POST_GRAGES);
            sql.setFilter(" group_name=?");
            sql.setParas(new Object[]{fse.getString("group_name")});
            DataTableEntity dt = dao.listTable(sql);
            if (!validDataPermission(dt)) {
                SpringMVCContextHolder.getSystemLogger().error(SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getValue(),
                        SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getText());
                throw new BaseException(SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getValue(),
                        SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getText());
            }
            dt = dao.listInternationDataTable(dt, null);
            JSONArray dataTableEntityToJson = BaseUtil.dataTableEntityToJson(dt);
            JSONObject json = new JSONObject();
            json.put("group_name", dataTableEntityToJson.getJSONObject(0).getString("group_name"));
            json.put("org_level_uuid", dataTableEntityToJson.getJSONObject(0).getString("org_level_uuid"));
            json.put("is_used", dataTableEntityToJson.getJSONObject(0).getInteger("is_used"));
            json.put(CmnConst.PRODUCT_SYS_JOB_POST_GRAGES, dataTableEntityToJson);
            return json;
        }
        return null;
    }
 
    /**
     * 新增岗位等级
     *
     * @param fse
     * @return
     * @throws BaseException
     */
    public String addPostGrades(FieldSetEntity fse) throws BaseException {
        fse.setValue("is_used", 1);
        fse = BaseUtil.createCreatorAndCreationTime(SpringMVCContextHolder.getCurrentUser(), fse);
        
        // 验证岗位级别是否存在
        if (!BaseUtil.dataTableIsEmpty(dao.listTable(CmnConst.PRODUCT_SYS_JOB_POST_GRAGES, "job_grade_name=? and org_level_uuid=?",
                new Object[]{fse.getString("job_grade_name"), SpringMVCContextHolder.getCurrentUser().getOrg_level_uuid()}))) {
            throw new BaseException(SystemCode.SYSTEM_POST_GRADE_GARDE_NAME_REPETITION_ADD_FAIL.getValue(),
                    SystemCode.SYSTEM_POST_GRADE_GARDE_NAME_REPETITION_ADD_FAIL.getText());
        }
        
        fse.setValue(CmnConst.ORG_LEVEL_UUID, SpringMVCContextHolder.getCurrentUser().getOrg_level_uuid());
        return dao.add(fse);
    }
 
    /**
     * 新增岗位等级组
     *
     * @param fse
     * @return
     * @throws BaseException
     */
    @Transactional
    public boolean addPostGradesGroup(FieldSetEntity fse) throws BaseException {
        String org_level_uuid = SpringMVCContextHolder.getCurrentUser().getOrg_level_uuid();
        //获取岗位等级子表
        DataTableEntity post_grades_group_list = fse.getSubDataTable("product_sys_job_post_grades");
        fse.setValue(CmnConst.ORG_LEVEL_UUID, org_level_uuid);
        
        //验证岗位等级组名称是否重复
        DataTableEntity listTable = dao.listTable(CmnConst.PRODUCT_SYS_JOB_POST_GRAGES, "group_name=? and org_level_uuid=?",new Object[]{fse.getString("group_name"), org_level_uuid});
        if (!BaseUtil.dataTableIsEmpty(listTable)) { 
            throw new BaseException(SystemCode.SYSTEM_POST_GRADE_GROUP_NAME_REPETITION_ADD_FAIL.getValue(),
                    SystemCode.SYSTEM_POST_GRADE_GROUP_NAME_REPETITION_ADD_FAIL.getText());
        }
        //验证是否输入岗位等级列表
        if (BaseUtil.dataTableIsEmpty(post_grades_group_list)) {
            throw new BaseException(SystemCode.SYSTEM_POST_GRADE_GROUP_NOEXIST_FAIL.getValue(),
                    SystemCode.SYSTEM_POST_GRADE_GROUP_NOEXIST_FAIL.getText(), this.getClass(), "addPostGradesGroup");
        }
        
        //验证岗位等级名称是否重复
        DataTableEntity dt = dao.listTable("select job_grade_name uuid FROM product_sys_job_post_grades where org_level_uuid =?", new Object[]{org_level_uuid});
        List<String> gradeNames = null;
        if (!BaseUtil.dataTableIsEmpty(dt)) {
            gradeNames = new ArrayList<>(Arrays.asList(dt.getUuidsToString().split(",")));
        }
        post_grades_group_list.getMeta().setTableName(new Object[]{"product_sys_job_post_grades"});
        for (int i = 0; i < post_grades_group_list.getRows(); i++) {
            if (gradeNames != null) {
                //重复判断
                if (gradeNames.contains(post_grades_group_list.getString(i, "job_grade_name"))) {
                    throw new BaseException(SystemCode.SYSTEM_POST_GRADE_GARDE_NAME_REPETITION_ADD_FAIL.getValue(),
                            SystemCode.SYSTEM_POST_GRADE_GARDE_NAME_REPETITION_ADD_FAIL.getText());
                }else {
                    //非重复填充
                    gradeNames.add(post_grades_group_list.getString(i, "job_grade_name"));
                }
            }
            post_grades_group_list.setFieldValue(i, "group_name", fse.getString("group_name"));
            post_grades_group_list.setFieldValue(i, "org_level_uuid", org_level_uuid);
            post_grades_group_list.setFieldValue(i, "is_used", fse.getString("is_used"));
            post_grades_group_list.getFieldSetEntity(i).getMeta().setTableName(new Object[]{"product_sys_job_post_grades"});
            post_grades_group_list.setFieldValue(i, CmnConst.CREATED_BY,SpringMVCContextHolder.getCurrentUser().getUser_id());
            post_grades_group_list.setFieldValue(i, CmnConst.CREATED_UTC_DATETIME, new Date());
        }
        return dao.add(post_grades_group_list);
    }
 
    /**
     * 修改岗位等级
     *
     * @param fse
     * @return
     * @throws BaseException
     */
    public boolean updatePostGrades(FieldSetEntity fse) throws BaseException {
        // 验证岗位级别是否存在
        if (!BaseUtil.dataTableIsEmpty(dao.listTable(CmnConst.PRODUCT_SYS_JOB_POST_GRAGES, "job_grade_name=? and org_level_uuid=? and uuid!=?",
                new Object[]{fse.getString("job_grade_name"), SpringMVCContextHolder.getCurrentUser().getOrg_level_uuid(), fse.getUUID()}))) { 
            throw new BaseException(SystemCode.SYSTEM_POST_GRADE_GARDE_NAME_REPETITION_ADD_FAIL.getValue(),
                    SystemCode.SYSTEM_POST_GRADE_GARDE_NAME_REPETITION_ADD_FAIL.getText());
        }
        fse = BaseUtil.createCreatorAndCreationTime(SpringMVCContextHolder.getCurrentUser(), fse);
        return dao.update(fse);
    }
 
    /**
     * 修改岗位等级组
     *
     * @param fse
     * @return
     * @throws BaseException
     */
    public boolean updatePostGradesGroup(FieldSetEntity fse) throws BaseException {
        DataTableEntity post_grades_group_list = fse.getSubDataTable("product_sys_job_post_grades");
        DataTableEntity post_gradesDt = dao.listTable(fse.getTableName(), "uuid=?", new Object[]{post_grades_group_list.getString(0, "uuid")});
        if (!validDataPermission(post_gradesDt)) {
            SpringMVCContextHolder.getSystemLogger().error(SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getValue(),
                    SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getText());
            throw new BaseException(SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getValue(),
                    SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getText());
        }
        if (BaseUtil.dataTableIsEmpty(post_grades_group_list)) {
            throw new BaseException(SystemCode.SYSTEM_POST_GRADE_GROUP_NOEXIST_FAIL.getValue(),
                    SystemCode.SYSTEM_POST_GRADE_GROUP_NOEXIST_FAIL.getText(), this.getClass(), "addPostGradesGroup");
        }
        
        post_grades_group_list.getMeta().setTableName(new Object[]{"product_sys_job_post_grades"});
        for (int i = 0; i < post_grades_group_list.getRows(); i++) {
            post_grades_group_list.setFieldValue(i, "group_name", fse.getString("group_name"));
            post_grades_group_list.setFieldValue(i, "org_level_uuid", fse.getString("org_level_uuid"));
            post_grades_group_list.setFieldValue(i, "is_used", fse.getString("is_used"));
            post_grades_group_list.getFieldSetEntity(i).getMeta()
                    .setTableName(new Object[]{"product_sys_job_post_grades"});
            if (StringUtils.isEmpty(post_grades_group_list.getString(i, CmnConst.CREATED_BY))) {
                post_grades_group_list.setFieldValue(i, CmnConst.CREATED_BY,
                        SpringMVCContextHolder.getCurrentUser().getUser_id());
                post_grades_group_list.setFieldValue(i, CmnConst.CREATED_UTC_DATETIME, new Date());
            } else {
                post_grades_group_list.setFieldValue(i, CmnConst.UPDATED_BY,
                        SpringMVCContextHolder.getCurrentUser().getUser_id());
                post_grades_group_list.setFieldValue(i, CmnConst.UPDATED_UTC_DATETIME, new Date());
            }
        }
        return dao.update(post_grades_group_list);
    }
 
    /**
     * 删除岗位等级
     *
     * @param fse
     * @return
     * @throws BaseException
     */
    public boolean deletePostGrades(FieldSetEntity fse) throws BaseException {
        String sql = "select * from " + CmnConst.PRODUCT_SYS_STAFFS + " where job_post_grade_uuid=?";
        DataTableEntity listTable = dao.listTable(sql, new Object[]{fse.getString(CmnConst.UUID)});
        if (!BaseUtil.dataTableIsEmpty(listTable)) { // 岗位级别被员工占用 不能删除
            throw new BaseException(SystemCode.SYSTEM_POST_GRADE_OCCUPY_DELETE_FAIL.getValue(),
                    SystemCode.SYSTEM_POST_GRADE_OCCUPY_DELETE_FAIL.getText());
        }
        return dao.delete(fse.getTableName(), new String[]{fse.getString(CmnConst.UUID)});
    }
 
    /**
     * 删除岗位等级组
     *
     * @param fse
     * @return
     * @throws BaseException
     */
    public boolean deletePostGradesGroup(FieldSetEntity fse) throws BaseException {
 
        DataTableEntity post_gradesDt = dao.listTable(fse.getTableName(), "group_name=?",
                new Object[]{fse.getString("group_name")});
        if (!validDataPermission(post_gradesDt)) {
            SpringMVCContextHolder.getSystemLogger().error(SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getValue(),
                    SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getText());
            throw new BaseException(SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getValue(),
                    SystemErrorCode.SYSTEM_NOT_OPER_PERMISSION.getText());
        }
        if (BaseUtil.dataTableIsEmpty(post_gradesDt) || StringUtils.isEmpty(post_gradesDt.getUuidsToString())) {
            throw new BaseException(SystemCode.SYSTEM_POSTS_DELETE_FAIL.getValue(),
                    SystemCode.SYSTEM_POSTS_DELETE_FAIL.getText(), this.getClass(), "deletePostGradesGroup");
        }
 
        String sql = "select * from " + CmnConst.PRODUCT_SYS_STAFFS + " where job_post_grade_uuid in (?)";
        Object[] uuids = post_gradesDt.getUuids();
        DataTableEntity listTable = dao.listTable(sql,
                new Object[]{post_gradesDt.getUuidsToString().replace(",", "','")});
        if (!BaseUtil.dataTableIsEmpty(listTable)) { // 岗位级别被员工占用 不能删除
            throw new BaseException(SystemCode.SYSTEM_POST_GRADE_OCCUPY_DELETE_FAIL.getValue(),
                    SystemCode.SYSTEM_POST_GRADE_OCCUPY_DELETE_FAIL.getText());
        }
 
        return dao.delete(fse.getTableName(), uuids);
    }
 
    /**
     * 自定义验证
     */
    private boolean validDataPermission(DataTableEntity dt) {
        SystemUser currentUser = SpringMVCContextHolder.getCurrentUser();
        if (currentUser != null && currentUser.isManager()) {
            String org_level_uuid = currentUser.getOrg_level_uuid();
            String dt_org_level_uuid = dt.getString(0, "org_level_uuid");
            String sql = "SELECT * FROM product_sys_org_levels WHERE org_level_code like concat((SELECT org_level_code FROM product_sys_org_levels WHERE uuid=?),'%') and uuid in('" + dt_org_level_uuid.replace(",", "','") + "')";
            DataTableEntity listTable = dao.listTable(sql, new String[]{org_level_uuid});
            if (listTable.getRows() > 0) {
                return true;
            }
        }
        return false;
    }
 
}