EmployeeServiceImpl.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. package jnpf.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.baomidou.mybatisplus.core.metadata.IPage;
  4. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  5. import com.lowagie.text.Document;
  6. import com.lowagie.text.Element;
  7. import com.lowagie.text.Font;
  8. import com.lowagie.text.Phrase;
  9. import com.lowagie.text.pdf.BaseFont;
  10. import com.lowagie.text.pdf.PdfPCell;
  11. import com.lowagie.text.pdf.PdfPTable;
  12. import com.lowagie.text.pdf.PdfWriter;
  13. import jnpf.base.service.SuperServiceImpl;
  14. import jnpf.entity.EmployeeEntity;
  15. import jnpf.mapper.EmployeeMapper;
  16. import jnpf.model.EmployeeModel;
  17. import jnpf.model.employee.EmployeeImportVO;
  18. import jnpf.model.employee.PaginationEmployee;
  19. import jnpf.service.EmployeeService;
  20. import jnpf.util.*;
  21. import lombok.extern.slf4j.Slf4j;
  22. import org.apache.commons.lang3.StringUtils;
  23. import org.springframework.stereotype.Service;
  24. import java.io.FileOutputStream;
  25. import java.util.*;
  26. /**
  27. * 职员信息
  28. *
  29. * @author JNPF开发平台组
  30. * @version V3.1.0
  31. * @copyright 引迈信息技术有限公司
  32. */
  33. @Slf4j
  34. @Service
  35. public class EmployeeServiceImpl extends SuperServiceImpl<EmployeeMapper, EmployeeEntity> implements EmployeeService {
  36. @Override
  37. public List<EmployeeEntity> getList() {
  38. QueryWrapper<EmployeeEntity> queryWrapper = new QueryWrapper<>();
  39. queryWrapper.lambda().orderByDesc(EmployeeEntity::getCreatorTime);
  40. return this.list(queryWrapper);
  41. }
  42. @Override
  43. public List<EmployeeEntity> getList(PaginationEmployee paginationEmployee) {
  44. // Map<String, Object> queryParam = OptimizeUtil.queryParam(pagination);
  45. QueryWrapper<EmployeeEntity> queryWrapper = new QueryWrapper<>();
  46. //查询条件
  47. String propertyName = paginationEmployee.getCondition() != null ? paginationEmployee.getCondition() : null;
  48. String propertyValue = paginationEmployee.getKeyword() != null ? paginationEmployee.getKeyword() : null;
  49. if (!StringUtils.isEmpty(propertyName) && !StringUtils.isEmpty(propertyValue)) {
  50. switch (propertyName) {
  51. //工号
  52. case "EnCode":
  53. queryWrapper.lambda().like(EmployeeEntity::getEnCode, propertyValue);
  54. break;
  55. //姓名
  56. case "FullName":
  57. queryWrapper.lambda().like(EmployeeEntity::getFullName, propertyValue);
  58. break;
  59. //电话
  60. case "Telephone":
  61. queryWrapper.lambda().like(EmployeeEntity::getTelephone, propertyValue);
  62. break;
  63. //部门
  64. case "DepartmentName":
  65. queryWrapper.lambda().like(EmployeeEntity::getDepartmentName, propertyValue);
  66. break;
  67. //岗位
  68. case "PositionName":
  69. queryWrapper.lambda().like(EmployeeEntity::getPositionName, propertyValue);
  70. break;
  71. default:
  72. break;
  73. }
  74. }
  75. //排序
  76. if (StringUtils.isEmpty(paginationEmployee.getSidx())) {
  77. queryWrapper.lambda().orderByDesc(EmployeeEntity::getCreatorTime);
  78. } else {
  79. queryWrapper = "asc".equals(paginationEmployee.getSort().toLowerCase()) ? queryWrapper.orderByAsc(paginationEmployee.getSidx()) : queryWrapper.orderByDesc(paginationEmployee.getSidx());
  80. }
  81. Page page = new Page(paginationEmployee.getCurrentPage(), paginationEmployee.getPageSize());
  82. IPage<EmployeeEntity> userIPage = this.page(page, queryWrapper);
  83. return paginationEmployee.setData(userIPage.getRecords(), page.getTotal());
  84. }
  85. @Override
  86. public EmployeeEntity getInfo(String id) {
  87. QueryWrapper<EmployeeEntity> queryWrapper = new QueryWrapper<>();
  88. queryWrapper.lambda().eq(EmployeeEntity::getId, id);
  89. return this.getOne(queryWrapper);
  90. }
  91. @Override
  92. public void delete(EmployeeEntity entity) {
  93. this.removeById(entity.getId());
  94. }
  95. @Override
  96. public void create(EmployeeEntity entity) {
  97. entity.setId(RandomUtil.uuId());
  98. entity.setSortCode(RandomUtil.parses());
  99. entity.setCreatorUserId(UserProvider.getLoginUserId());
  100. this.save(entity);
  101. }
  102. @Override
  103. public void update(String id, EmployeeEntity entity) {
  104. entity.setId(id);
  105. entity.setLastModifyTime(new Date());
  106. entity.setLastModifyUserId(UserProvider.getLoginUserId());
  107. this.updateById(entity);
  108. }
  109. @Override
  110. public Map<String, Object> importPreview(List<EmployeeModel> personList) {
  111. List<Map<String, Object>> dataRow = new ArrayList<>();
  112. List<Map<String, Object>> columns = new ArrayList<>();
  113. for (int i = 0; i < personList.size(); i++) {
  114. Map<String, Object> dataRowMap = new HashMap<>();
  115. EmployeeModel model = personList.get(i);
  116. dataRowMap.put("enCode", model.getEnCode());
  117. dataRowMap.put("fullName", model.getFullName());
  118. dataRowMap.put("gender", model.getGender());
  119. dataRowMap.put("departmentName", model.getDepartmentName());
  120. dataRowMap.put("positionName", model.getPositionName());
  121. dataRowMap.put("workingNature", model.getWorkingNature());
  122. dataRowMap.put("idNumber", model.getIdNumber());
  123. dataRowMap.put("telephone", model.getTelephone());
  124. dataRowMap.put("attendWorkTime", model.getAttendWorkTime());
  125. dataRowMap.put("birthday", model.getBirthday());
  126. dataRowMap.put("education", model.getEducation());
  127. dataRowMap.put("major", model.getMajor());
  128. dataRowMap.put("graduationAcademy", model.getGraduationAcademy());
  129. dataRowMap.put("graduationTime", model.getGraduationTime());
  130. dataRow.add(dataRowMap);
  131. }
  132. for (int i = 1; i < 15; i++) {
  133. Map<String, Object> columnsMap = new HashMap<>();
  134. columnsMap.put("AllowDBNull", true);
  135. columnsMap.put("AutoIncrement", false);
  136. columnsMap.put("AutoIncrementSeed", 0);
  137. columnsMap.put("AutoIncrementStep", 1);
  138. columnsMap.put("Caption", this.getColumns(i));
  139. columnsMap.put("ColumnMapping", 1);
  140. columnsMap.put("ColumnName", this.getColumns(i));
  141. columnsMap.put("Container", null);
  142. columnsMap.put("DataType", "System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
  143. columnsMap.put("DateTimeMode", 3);
  144. columnsMap.put("DefaultValue", null);
  145. columnsMap.put("DesignMode", false);
  146. columnsMap.put("Expression", "");
  147. columnsMap.put("ExtendedProperties", "");
  148. columnsMap.put("MaxLength", -1);
  149. columnsMap.put("Namespace", "");
  150. columnsMap.put("Ordinal", 0);
  151. columnsMap.put("Prefix", "");
  152. columnsMap.put("ReadOnly", false);
  153. columnsMap.put("Site", null);
  154. columnsMap.put("Table", personList);
  155. columnsMap.put("Unique", false);
  156. columns.add(columnsMap);
  157. }
  158. Map<String, Object> map = new HashMap<>();
  159. map.put("dataRow", dataRow);
  160. map.put("columns", columns);
  161. return map;
  162. }
  163. @Override
  164. public EmployeeImportVO importData(List<EmployeeModel> dt) {
  165. for(EmployeeModel model :dt){
  166. model.setAttendWorkTime(DateUtil.cstFormat(model.getAttendWorkTime()));
  167. model.setBirthday(DateUtil.cstFormat(model.getBirthday()));
  168. model.setGraduationTime(DateUtil.cstFormat(model.getGraduationTime()));
  169. }
  170. List<EmployeeEntity> entitys = JsonUtil.getJsonToList(dt, EmployeeEntity.class);
  171. //记录成功了几条
  172. int sum=0;
  173. //记录第几条失败
  174. int num=0;
  175. List<EmployeeEntity> errList = new ArrayList<>();
  176. for (EmployeeEntity entity : entitys) {
  177. entity.setId(RandomUtil.uuId());
  178. entity.setCreatorUserId(UserProvider.getLoginUserId());
  179. entity.setCreatorTime(new Date());
  180. try {
  181. this.baseMapper.insert(entity);
  182. sum++;
  183. }catch (Exception e){
  184. errList.add(entity);
  185. num++;
  186. log.error("导入第"+(num+1)+"条数据失败");
  187. }
  188. }
  189. EmployeeImportVO vo=new EmployeeImportVO();
  190. vo.setSnum(sum);
  191. vo.setFnum(num);
  192. if(vo.getFnum()>0){
  193. vo.setResultType(1);
  194. vo.setFailResult(JsonUtil.getJsonToList(errList, EmployeeModel.class));
  195. return vo;
  196. }else{
  197. vo.setResultType(0);
  198. return vo;
  199. }
  200. }
  201. @Override
  202. public void exportPdf(List<EmployeeEntity> list, String outputUrl) {
  203. try {
  204. Document document = new Document();
  205. BaseFont bfChinese = BaseFont.createFont("STSongStd-Light", "UniGB-UCS2-H", false);
  206. Font font = new Font(bfChinese, 11, Font.NORMAL);
  207. PdfWriter.getInstance(document, new FileOutputStream(outputUrl));
  208. document.open();
  209. PdfPTable row;
  210. row = new PdfPTable(13);
  211. //表占页面100%宽度
  212. row.setWidthPercentage(100f);
  213. //标题
  214. String[] titles = {"姓名", "性别", "部门", "职位", "用工性质", "身份证号", "联系电话", "出生年月", "参加工作", "最高学历", "所学专业", "毕业院校", "毕业时间"};
  215. for (String title : titles) {
  216. row.addCell(createCell(title, font));
  217. }
  218. document.add(row);
  219. //内容
  220. for (EmployeeEntity entity : list) {
  221. row = new PdfPTable(13);
  222. //表占页面100%宽度
  223. row.setWidthPercentage(100f);
  224. row.addCell(createCell(entity.getFullName(), font));
  225. row.addCell(createCell(entity.getGender(), font));
  226. row.addCell(createCell(entity.getDepartmentName(), font));
  227. row.addCell(createCell(entity.getPositionName(), font));
  228. row.addCell(createCell(entity.getWorkingNature(), font));
  229. row.addCell(createCell(entity.getIdNumber(), font));
  230. row.addCell(createCell(entity.getTelephone(), font));
  231. row.addCell(createCell(entity.getAttendWorkTime() != null ? DateUtil.daFormat(entity.getAttendWorkTime()) : "", font));
  232. row.addCell(createCell(entity.getBirthday() != null ? DateUtil.daFormat(entity.getBirthday()) : "", font));
  233. row.addCell(createCell(entity.getEducation(), font));
  234. row.addCell(createCell(entity.getMajor(), font));
  235. row.addCell(createCell(entity.getGraduationAcademy(), font));
  236. row.addCell(createCell(entity.getGraduationTime() != null ? DateUtil.daFormat(entity.getGraduationTime()) : "", font));
  237. document.add(row);
  238. }
  239. document.close();
  240. } catch (Exception e) {
  241. log.error(e.getMessage());
  242. }
  243. }
  244. private PdfPCell createCell(String value, Font font) {
  245. PdfPCell cell = new PdfPCell();
  246. cell.setVerticalAlignment(Element.ALIGN_CENTER);
  247. cell.setPhrase(new Phrase(value, font));
  248. return cell;
  249. }
  250. private String getKey(String key) {
  251. Map<String, String> map = new HashMap<>();
  252. map.put("工号", "F_EnCode");
  253. map.put("姓名", "F_FullName");
  254. map.put("性别", "F_Gender");
  255. map.put("部门", "F_DepartmentName");
  256. map.put("职务", "F_PositionName");
  257. map.put("用工性质", "F_WorkingNature");
  258. map.put("身份证号", "F_IDNumber");
  259. map.put("联系电话", "F_Telephone");
  260. map.put("出生年月", "F_Birthday");
  261. map.put("参加工作", "F_AttendWorkTime");
  262. map.put("最高学历", "F_Education");
  263. map.put("所学专业", "F_Major");
  264. map.put("毕业院校", "F_GraduationAcademy");
  265. map.put("毕业时间", "F_GraduationTime");
  266. return map.get(key);
  267. }
  268. private String getColumns(Integer key) {
  269. Map<Integer, String> map = new HashMap<>();
  270. map.put(1, "工号");
  271. map.put(2, "姓名");
  272. map.put(3, "性别");
  273. map.put(4, "部门");
  274. map.put(5, "职务");
  275. map.put(6, "用工性质");
  276. map.put(7, "身份证号");
  277. map.put(8, "联系电话");
  278. map.put(9, "出生年月");
  279. map.put(10, "参加工作");
  280. map.put(11, "最高学历");
  281. map.put(12, "所学专业");
  282. map.put(13, "毕业院校");
  283. map.put(14, "毕业时间");
  284. return map.get(key);
  285. }
  286. }