xg
许鹏程
2023-05-26 2476c4f7acc1a3a9087227660e32ef42157a46b6
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
package com.product.org.admin.service;
 
import com.product.common.lang.StringUtils;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import com.product.core.dao.BaseDao;
import com.product.core.entity.DataTableEntity;
import com.product.core.entity.FieldSetEntity;
import com.product.core.exception.BaseException;
import com.product.core.permission.PermissionService;
import com.product.core.service.support.AbstractBaseService;
import com.product.core.service.support.QueryFilterService;
import com.product.core.transfer.Transactional;
import com.product.org.admin.config.CmnConst;
import com.product.org.admin.service.idel.IDimissionHandoverService;
import com.product.util.BaseUtil;
 
/**
 * Copyright LX-BASE
 * 
 * @Title: DimissionHandoverService
 * @Project: LX-BASE-SERVER
 * @Date: 2020年6月11日 下午5:25:34
 * @Author: 郑盟
 * @Description: 离职交接
 */
@Component
public class DimissionHandoverService extends AbstractBaseService implements IDimissionHandoverService{
    
    @Autowired
    public BaseDao baseDao;
    
    @Autowired
    PermissionService permissionService;
 
    @Autowired
    QueryFilterService queryFilterService;
    
    /**
     * 离职交接详情
     * 
     * @param uuid
     * @return
     * @throws BaseException
     */
    public FieldSetEntity findHandover(String uuid) throws BaseException {
        return baseDao.getFieldSetEntity("product_sys_staff_termination", uuid,false);
    }
 
    /**
     * 离职交接列表
     * @param fs
     * @return
     * @throws BaseException
     */
    public DataTableEntity listHandover(FieldSetEntity fs) throws BaseException {
        //数据策略
        String dataFilter=permissionService.getDataFilter("b."+CmnConst.ORG_LEVEL_UUID) ;
        //高级查询
        String searchFilter=queryFilterService.getQueryFilter(fs);
        if(!StringUtils.isEmpty(dataFilter)) {
            dataFilter=" WHERE "+dataFilter;
            if (!StringUtils.isEmpty(searchFilter)) {
                dataFilter+=" AND "+ searchFilter;
            }
        }else {
            if (!StringUtils.isEmpty(searchFilter)) {
                dataFilter=searchFilter;
            }
        }
        
        StringBuilder sql=new StringBuilder();
 
        //luoxin 添加字段  a.handover_staff_uuid,a.handover_date     交接人     交接时间
        sql.append(" SELECT * FROM( ");
        sql.append(" SELECT a.uuid uuid,b.uuid uuid1,c.uuid uuid2,d.uuid uuid3,e.uuid uuid4,f.uuid uuid5,a.apply_staff_uuid,a.termination_reason,a.change_effective,a.result_status,a.handover_staff_uuid,a.handover_date,b.show_name,b.preferred_name,c.client_name,d.org_level_all,e.job_post_name,f.job_grade_name ");
        sql.append(" FROM product_sys_staff_termination a ");
        sql.append(" LEFT JOIN product_sys_staffs b ON a.apply_staff_uuid=b.uuid ");
        sql.append(" LEFT JOIN product_sys_clients c ON c.uuid=b.client_uuid ");
        sql.append(" LEFT JOIN product_sys_org_levels d ON d.uuid=b.dept_uuid ");
        sql.append(" LEFT JOIN product_sys_job_posts e ON e.uuid=b.job_post_uuid ");
        sql.append(" LEFT JOIN product_sys_job_post_grades f ON f.uuid=b.job_post_grade_uuid ");
        sql.append(dataFilter);
        sql.append(" )b ");
        
        DataTableEntity dt=baseDao.listTable(sql.toString(), null, fs.getInteger("pagesize"), fs.getInteger("cpage"));
        dt.getMeta().addAliasTable(CmnConst.PRODUCT_SYS_STAFF_TERMINATION,"a");
        dt.getMeta().addAliasTable("product_sys_staffs","b");
        dt.getMeta().addAliasTable("product_sys_clients","c");
        dt.getMeta().addAliasTable("product_sys_org_levels","d");
        dt.getMeta().addAliasTable("product_sys_job_posts","e");
        dt.getMeta().addAliasTable("product_sys_job_post_grades","f");
        dt.getMeta().addAliasField("product_sys_staffs.uuid", "uuid1");
        dt.getMeta().addAliasField("product_sys_staffs.show_name", "show_name");
        
        if (!BaseUtil.dataTableIsEmpty(dt)) {
            baseDao.loadPromptData(dt);
            baseDao.listInternationDataTable(dt, null);
        }
        return dt;
    }
 
    /**
     * 离职交接新增
     * @param fs
     * @return
     * @throws BaseException
     */
    public boolean addHandover(FieldSetEntity fs) throws BaseException {
        String staff_uuid = fs.getString("apply_staff_uuid");
        FieldSetEntity fss = baseDao.getFieldSetEntityByFilter(CmnConst.PRODUCT_SYS_STAFF_TERMINATION,
                "result_status=0 and apply_staff_uuid =?", new String[] {staff_uuid}, false);
        fss.setValue(CmnConst.HANDOVER_STAFF_UUID, fs.getString(CmnConst.HANDOVER_STAFF_UUID));
        fss.setValue(CmnConst.HANDOVER_DATE, fs.getString(CmnConst.HANDOVER_DATE));
        fss.setValue(CmnConst.HANDOVER_DETAIL, fs.getString(CmnConst.HANDOVER_DETAIL));
        fss.setValue(CmnConst.ATTACHMENT, fs.getString(CmnConst.ATTACHMENT));
        return baseDao.update(fss);
    }
 
    /**
     * 离职交接修改
     * @param fs
     * @return
     * @throws BaseException
     */
    @Transactional
    public boolean updateHandover(FieldSetEntity fs) throws BaseException {
        String uuid = fs.getString("uuid");
        FieldSetEntity fss = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_STAFF_TERMINATION, uuid, false);
        if (fss != null) {
            fss.setValue(CmnConst.HANDOVER_STAFF_UUID, fs.getString(CmnConst.HANDOVER_STAFF_UUID));
            fss.setValue(CmnConst.HANDOVER_DATE, fs.getString(CmnConst.HANDOVER_DATE));
            fss.setValue(CmnConst.HANDOVER_DETAIL, fs.getString(CmnConst.HANDOVER_DETAIL));
            fss.setValue(CmnConst.ATTACHMENT, fs.getString(CmnConst.ATTACHMENT));
        }
//        处理删除的文件
        String delete_attachments = fs.getString("delete_attachments");
        if (!StringUtils.isEmpty(delete_attachments)) {
            String[] split = delete_attachments.split(",");
            for (int i = 0; i < split.length; i++) {
                baseDao.delete("product_sys_attachments", new Object[] { split[i] });
            }
        }
        return baseDao.update(fss);
    }
    
    /**
     * 员工交接删除
     * @param fs
     * @return
     * @throws BaseException
     */
    @Transactional
    public boolean delectHandover(FieldSetEntity fs) throws BaseException {
 
        // 删除文件
        FieldSetEntity product_sys_staff_termination = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_STAFF_TERMINATION,fs.getUUID(), false);
        String changeUuids =product_sys_staff_termination.getString("apply_staff_uuid") + ","+product_sys_staff_termination.getString(CmnConst.HANDOVER_STAFF_UUID);
        baseDao.delete("product_sys_attachments", "staff_uuid=? and attachment_data_field='attachment' and attachment_data_table='product_sys_staff_termination'",new String[] { changeUuids });
 
        String uuid = fs.getString("uuid");
        if (StringUtils.isEmpty(uuid)) {    //杜洪波 updateTime 2020-12-17 09:48:00
            return false;
        }
        FieldSetEntity fss = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_STAFF_TERMINATION, uuid, false);
        fss.setValue(CmnConst.HANDOVER_STAFF_UUID, null);
        fss.setValue(CmnConst.HANDOVER_DATE, null);
        fss.setValue(CmnConst.HANDOVER_DETAIL, null);
        fss.setValue(CmnConst.ATTACHMENT, null);
        return baseDao.update(fss);
    }
 
 
}