ny
23 小时以前 b6f169fe43a2b13f351aefc152374fc7f0bc8cb7
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
package jnpf.service.impl;
 
import com.lowagie.text.Document;
import com.lowagie.text.Element;
import com.lowagie.text.Font;
import com.lowagie.text.Phrase;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;
import jnpf.base.service.SuperServiceImpl;
import jnpf.entity.EmployeeEntity;
import jnpf.mapper.EmployeeMapper;
import jnpf.model.EmployeeModel;
import jnpf.model.employee.EmployeeImportVO;
import jnpf.model.employee.PaginationEmployee;
import jnpf.service.EmployeeService;
import jnpf.util.DateUtil;
import jnpf.util.JsonUtil;
import jnpf.util.RandomUtil;
import jnpf.util.UserProvider;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
 
import java.io.FileOutputStream;
import java.util.*;
 
/**
 * 职员信息
 *
 * @author JNPF开发平台组
 * @version V3.1.0
 * @copyright 引迈信息技术有限公司
 */
@Slf4j
@Service
public class EmployeeServiceImpl extends SuperServiceImpl<EmployeeMapper, EmployeeEntity> implements EmployeeService {
 
    @Override
    public List<EmployeeEntity> getList() {
        return this.baseMapper.getList();
    }
 
    @Override
    public List<EmployeeEntity> getList(PaginationEmployee paginationEmployee) {
        return this.baseMapper.getList(paginationEmployee);
    }
 
    @Override
    public EmployeeEntity getInfo(String id) {
        return this.baseMapper.getInfo(id);
    }
 
    @Override
    public void delete(EmployeeEntity entity) {
        this.baseMapper.delete(entity);
    }
 
    @Override
    public void create(EmployeeEntity entity) {
        this.baseMapper.create(entity);
    }
 
    @Override
    public void update(String id, EmployeeEntity entity) {
        this.baseMapper.update(id, entity);
    }
 
    @Override
    public Map<String, Object> importPreview(List<EmployeeModel> personList) {
        List<Map<String, Object>> dataRow = new ArrayList<>();
        List<Map<String, Object>> columns = new ArrayList<>();
        for (int i = 0; i < personList.size(); i++) {
            Map<String, Object> dataRowMap = new HashMap<>();
            EmployeeModel model = personList.get(i);
            dataRowMap.put("enCode", model.getEnCode());
            dataRowMap.put("fullName", model.getFullName());
            dataRowMap.put("gender", model.getGender());
            dataRowMap.put("departmentName", model.getDepartmentName());
            dataRowMap.put("positionName", model.getPositionName());
            dataRowMap.put("workingNature", model.getWorkingNature());
            dataRowMap.put("idNumber", model.getIdNumber());
            dataRowMap.put("telephone", model.getTelephone());
            dataRowMap.put("attendWorkTime", model.getAttendWorkTime());
            dataRowMap.put("birthday", model.getBirthday());
            dataRowMap.put("education", model.getEducation());
            dataRowMap.put("major", model.getMajor());
            dataRowMap.put("graduationAcademy", model.getGraduationAcademy());
            dataRowMap.put("graduationTime", model.getGraduationTime());
            dataRow.add(dataRowMap);
        }
        for (int i = 1; i < 15; i++) {
            Map<String, Object> columnsMap = new HashMap<>();
            columnsMap.put("AllowDBNull", true);
            columnsMap.put("AutoIncrement", false);
            columnsMap.put("AutoIncrementSeed", 0);
            columnsMap.put("AutoIncrementStep", 1);
            columnsMap.put("Caption", this.getColumns(i));
            columnsMap.put("ColumnMapping", 1);
            columnsMap.put("ColumnName", this.getColumns(i));
            columnsMap.put("Container", null);
            columnsMap.put("DataType", "System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
            columnsMap.put("DateTimeMode", 3);
            columnsMap.put("DefaultValue", null);
            columnsMap.put("DesignMode", false);
            columnsMap.put("Expression", "");
            columnsMap.put("ExtendedProperties", "");
            columnsMap.put("MaxLength", -1);
            columnsMap.put("Namespace", "");
            columnsMap.put("Ordinal", 0);
            columnsMap.put("Prefix", "");
            columnsMap.put("ReadOnly", false);
            columnsMap.put("Site", null);
            columnsMap.put("Table", personList);
            columnsMap.put("Unique", false);
            columns.add(columnsMap);
        }
        Map<String, Object> map = new HashMap<>();
        map.put("dataRow", dataRow);
        map.put("columns", columns);
        return map;
    }
 
    @Override
    public EmployeeImportVO importData(List<EmployeeModel> dt) {
 
        for (EmployeeModel model : dt) {
            model.setAttendWorkTime(DateUtil.cstFormat(model.getAttendWorkTime()));
            model.setBirthday(DateUtil.cstFormat(model.getBirthday()));
            model.setGraduationTime(DateUtil.cstFormat(model.getGraduationTime()));
        }
        List<EmployeeEntity> entitys = JsonUtil.getJsonToList(dt, EmployeeEntity.class);
        //记录成功了几条
        int sum = 0;
        //记录第几条失败
        int num = 0;
        List<EmployeeEntity> errList = new ArrayList<>();
        for (EmployeeEntity entity : entitys) {
            entity.setId(RandomUtil.uuId());
            entity.setCreatorUserId(UserProvider.getLoginUserId());
            entity.setCreatorTime(new Date());
            try {
                this.baseMapper.insert(entity);
                sum++;
            } catch (Exception e) {
                errList.add(entity);
                num++;
                log.error("导入第" + (num + 1) + "条数据失败");
            }
 
        }
        EmployeeImportVO vo = new EmployeeImportVO();
        vo.setSnum(sum);
        vo.setFnum(num);
        if (vo.getFnum() > 0) {
            vo.setResultType(1);
            vo.setFailResult(JsonUtil.getJsonToList(errList, EmployeeModel.class));
            return vo;
        } else {
            vo.setResultType(0);
            return vo;
        }
    }
 
    @Override
    public void exportPdf(List<EmployeeEntity> list, String outputUrl) {
        try {
            Document document = new Document();
            BaseFont bfChinese = BaseFont.createFont("STSongStd-Light", "UniGB-UCS2-H", false);
            Font font = new Font(bfChinese, 11, Font.NORMAL);
            PdfWriter.getInstance(document, new FileOutputStream(outputUrl));
            document.open();
            PdfPTable row;
            row = new PdfPTable(13);
            //表占页面100%宽度
            row.setWidthPercentage(100f);
            //标题
            String[] titles = {"姓名", "性别", "部门", "职位", "用工性质", "身份证号", "联系电话", "出生年月", "参加工作", "最高学历", "所学专业", "毕业院校", "毕业时间"};
            for (String title : titles) {
                row.addCell(createCell(title, font));
            }
            document.add(row);
            //内容
            for (EmployeeEntity entity : list) {
                row = new PdfPTable(13);
                //表占页面100%宽度
                row.setWidthPercentage(100f);
                row.addCell(createCell(entity.getFullName(), font));
                row.addCell(createCell(entity.getGender(), font));
                row.addCell(createCell(entity.getDepartmentName(), font));
                row.addCell(createCell(entity.getPositionName(), font));
                row.addCell(createCell(entity.getWorkingNature(), font));
                row.addCell(createCell(entity.getIdNumber(), font));
                row.addCell(createCell(entity.getTelephone(), font));
                row.addCell(createCell(entity.getAttendWorkTime() != null ? DateUtil.daFormat(entity.getAttendWorkTime()) : "", font));
                row.addCell(createCell(entity.getBirthday() != null ? DateUtil.daFormat(entity.getBirthday()) : "", font));
                row.addCell(createCell(entity.getEducation(), font));
                row.addCell(createCell(entity.getMajor(), font));
                row.addCell(createCell(entity.getGraduationAcademy(), font));
                row.addCell(createCell(entity.getGraduationTime() != null ? DateUtil.daFormat(entity.getGraduationTime()) : "", font));
                document.add(row);
            }
            document.close();
        } catch (Exception e) {
            log.error(e.getMessage());
        }
    }
 
    private PdfPCell createCell(String value, Font font) {
        PdfPCell cell = new PdfPCell();
        cell.setVerticalAlignment(Element.ALIGN_CENTER);
        cell.setPhrase(new Phrase(value, font));
        return cell;
    }
 
    private String getKey(String key) {
        Map<String, String> map = new HashMap<>();
        map.put("工号", "F_EnCode");
        map.put("姓名", "F_FullName");
        map.put("性别", "F_Gender");
        map.put("部门", "F_DepartmentName");
        map.put("职务", "F_PositionName");
        map.put("用工性质", "F_WorkingNature");
        map.put("身份证号", "F_IDNumber");
        map.put("联系电话", "F_Telephone");
        map.put("出生年月", "F_Birthday");
        map.put("参加工作", "F_AttendWorkTime");
        map.put("最高学历", "F_Education");
        map.put("所学专业", "F_Major");
        map.put("毕业院校", "F_GraduationAcademy");
        map.put("毕业时间", "F_GraduationTime");
        return map.get(key);
    }
 
    private String getColumns(Integer key) {
        Map<Integer, String> map = new HashMap<>();
        map.put(1, "工号");
        map.put(2, "姓名");
        map.put(3, "性别");
        map.put(4, "部门");
        map.put(5, "职务");
        map.put(6, "用工性质");
        map.put(7, "身份证号");
        map.put(8, "联系电话");
        map.put(9, "出生年月");
        map.put(10, "参加工作");
        map.put(11, "最高学历");
        map.put(12, "所学专业");
        map.put(13, "毕业院校");
        map.put(14, "毕业时间");
        return map.get(key);
    }
}