Browse Source

员工档案excel导出

jzh 1 year ago
parent
commit
967d0ebfd2

+ 45 - 0
zjugis-module-adm/zjugis-module-adm-biz/src/main/java/com/zjugis/module/adm/constants/DictConstants.java

@@ -21,6 +21,51 @@ public class DictConstants {
      */
     public static final String FUNCTIONAL_DEPT = "functional_dept";
 
+    /**
+     * 性别
+     */
+    public static final String sex_type = "sex_type";
+    /**
+     * 入职状态
+     */
+    public static final String staff_state_type = "staff_state_type";
+    /**
+     * 政治面貌
+     */
+    public static final String polity_type = "polity_type";
+    /**
+     * 户口性质
+     */
+    public static final String hk_type = "hk_type";
+    /**
+     * 婚姻状况
+     */
+    public static final String hy_type = "hy_type";
+    /**
+     * 最高学历
+     */
+    public static final String xl_type = "xl_type";
+    /**
+     * 是否已调档
+     */
+    public static final String td_type = "td_type";
 
+    /**
+     * 紧急联系人关系
+     */
+    public static final String contact_type = "contact_type";
+    /**
+     * 民族
+     */
+    public static final String nation_type = "nation_type";
+    /**
+     * 能力等级
+     */
+    public static final String ABILITY_LEVEL = "ABILITY_LEVEL";
+
+    /**
+     * 岗位
+     */
+    public static final String post_type = "post_type";
 
 }

+ 35 - 0
zjugis-module-adm/zjugis-module-adm-biz/src/main/java/com/zjugis/module/adm/controller/admin/staff/StaffRecordsController.java

@@ -2,20 +2,33 @@ package com.zjugis.module.adm.controller.admin.staff;
 
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.zjugis.framework.common.pojo.CommonResult;
+import com.zjugis.framework.excel.core.util.ExcelUtils;
 import com.zjugis.module.adm.api.staff.dto.StaffRecordsDTO;
 import com.zjugis.module.adm.controller.admin.staff.vo.records.RecordsPageReqVO;
 import com.zjugis.module.adm.controller.admin.staff.vo.records.RecordsRespVO;
+import com.zjugis.module.adm.controller.admin.staff.vo.records.StaffExcelResponse;
 import com.zjugis.module.adm.convert.staff.RecordsConvert;
+import com.zjugis.module.adm.dal.dataobject.staff.StaffRecordSDO;
 import com.zjugis.module.adm.service.staff.RecordsService;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
+import org.springframework.beans.BeanUtils;
 import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
+import javax.servlet.http.HttpServletResponse;
 import javax.validation.Valid;
 import javax.validation.constraints.NotNull;
 
+import java.io.IOException;
+import java.net.URLEncoder;
+import java.nio.charset.StandardCharsets;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.List;
+
 import static com.zjugis.framework.common.pojo.CommonResult.success;
 
 /**
@@ -82,4 +95,26 @@ public class StaffRecordsController {
         return success(recordsService.generateNum());
     }
 
+
+    /**
+     * 档案导出
+     */
+    @GetMapping("/excel")
+    public void export(RecordsPageReqVO vo, HttpServletResponse response) throws IOException {
+        Page<StaffRecordSDO> page = recordsService.getRecordsPage(vo);
+        List<StaffRecordSDO> staffs = page.getRecords();
+
+        List<StaffExcelResponse> excelList = new ArrayList<>(staffs.size());
+        staffs.forEach(staff -> {
+            StaffExcelResponse staffExcelResponse = new StaffExcelResponse();
+            BeanUtils.copyProperties(staff, staffExcelResponse);
+            excelList.add(staffExcelResponse);
+        });
+        String date = LocalDate.now().toString();
+        response.setContentType("multipart/form-data");
+        response.setCharacterEncoding(String.valueOf(StandardCharsets.UTF_8));
+        response.setHeader("Content-Disposition",
+                "attachment;filename*=utf-8'zh-cn'" + URLEncoder.encode(date + "_员工花名册.xlsx", String.valueOf(StandardCharsets.UTF_8)));
+        ExcelUtils.write(response, "员工花名册.xlsx", "员工花名册", StaffExcelResponse.class, excelList);
+    }
 }

+ 158 - 0
zjugis-module-adm/zjugis-module-adm-biz/src/main/java/com/zjugis/module/adm/controller/admin/staff/vo/records/StaffConverter.java

@@ -0,0 +1,158 @@
+package com.zjugis.module.adm.controller.admin.staff.vo.records;
+
+
+import com.alibaba.excel.converters.Converter;
+import com.alibaba.excel.metadata.GlobalConfiguration;
+import com.alibaba.excel.metadata.data.WriteCellData;
+import com.alibaba.excel.metadata.property.ExcelContentProperty;
+import com.zjugis.framework.common.pojo.CommonResult;
+import com.zjugis.module.adm.constants.DictConstants;
+import com.zjugis.module.adm.framework.spring.ApplicationContextProvider;
+import com.zjugis.module.system.api.dict.DictDataApi;
+import com.zjugis.module.system.api.dict.dto.DictDataRespDTO;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.lang.reflect.Field;
+import java.util.*;
+
+public class StaffConverter implements Converter<String> {
+
+
+    private final String[] dictFieldName = {"drzw", "sex", "zgxl", "hkxz", "zzmm", "hyzk", "jjlxrgx", "nation", "state", "nldj"};
+
+    private final Map<String, Map<String, String>> dictMap = new HashMap<>();
+
+    private final Map<String, String> drzw = new HashMap<>();
+
+    private final Map<String, String> sex = new HashMap<>();
+
+    private final Map<String, String> zgxl = new HashMap<>();
+
+    private final Map<String, String> hkxz = new HashMap<>();
+
+    private final Map<String, String> zzmm = new HashMap<>();
+
+    private final Map<String, String> hyzk = new HashMap<>();
+
+    private final Map<String, String> jjlxrgx = new HashMap<>();
+
+    private final Map<String, String> nation = new HashMap<>();
+
+    private final Map<String, String> state = new HashMap<>();
+
+    private final Map<String, String> nldj = new HashMap<>();
+
+    public StaffConverter() {
+
+        //字典查询
+        List<String> types = getTypeList();
+        DictDataApi dictDataApi = ApplicationContextProvider.getBean(DictDataApi.class);
+        CommonResult<List<DictDataRespDTO>> res = dictDataApi.getDictDataListByTypes(types);
+        List<DictDataRespDTO> resData = res.getCheckedData();
+
+        resData.forEach(dict -> {
+            switch (dict.getDictType()) {
+                case DictConstants.post_type:
+                    this.drzw.put(dict.getValue(), dict.getLabel());
+                    break;
+
+                case DictConstants.sex_type:
+                    this.sex.put(dict.getValue(), dict.getLabel());
+                    break;
+
+                case DictConstants.xl_type:
+                    this.zgxl.put(dict.getValue(), dict.getLabel());
+                    break;
+
+                case DictConstants.hk_type:
+                    this.hkxz.put(dict.getValue(), dict.getLabel());
+                    break;
+
+                case DictConstants.polity_type:
+                    this.zzmm.put(dict.getValue(), dict.getLabel());
+                    break;
+
+                case DictConstants.hy_type:
+                    this.hyzk.put(dict.getValue(), dict.getLabel());
+                    break;
+
+                case DictConstants.contact_type:
+                    this.jjlxrgx.put(dict.getValue(), dict.getLabel());
+                    break;
+
+                case DictConstants.nation_type:
+                    this.nation.put(dict.getValue(), dict.getLabel());
+                    break;
+
+                case DictConstants.staff_state_type:
+                    this.state.put(dict.getValue(), dict.getLabel());
+                    break;
+
+                case DictConstants.ABILITY_LEVEL:
+                    this.nldj.put(dict.getValue(), dict.getLabel());
+                    break;
+
+                default:
+                    break;
+            }
+
+        });
+
+
+        dictMap.put("drzw", drzw);
+        dictMap.put("sex", sex);
+        dictMap.put("zgxl", zgxl);
+        dictMap.put("hkxz", hkxz);
+        dictMap.put("zzmm", zzmm);
+        dictMap.put("hyzk", hyzk);
+        dictMap.put("jjlxrgx", jjlxrgx);
+        dictMap.put("nation", nation);
+        dictMap.put("state", state);
+        dictMap.put("nldj", nldj);
+
+
+    }
+
+    private List<String> getTypeList() {
+        List<String> res = new ArrayList<>();
+        res.add(DictConstants.sex_type);
+        res.add(DictConstants.staff_state_type);
+        res.add(DictConstants.polity_type);
+        res.add(DictConstants.hk_type);
+        res.add(DictConstants.hy_type);
+        res.add(DictConstants.xl_type);
+        res.add(DictConstants.contact_type);
+        res.add(DictConstants.nation_type);
+        res.add(DictConstants.post_type);
+        res.add(DictConstants.ABILITY_LEVEL);
+        return res;
+    }
+
+    @Override
+    public Class<?> supportJavaTypeKey() {
+        return Integer.class;
+    }
+
+    /**
+     * @param value               Java Data.NotNull.
+     * @param contentProperty     Content property.Nullable.
+     * @param globalConfiguration Global configuration.NotNull.
+     */
+    @Override
+    public WriteCellData<?> convertToExcelData(String value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
+
+        Field field = contentProperty.getField();
+        String fieldName = field.getName();
+        String excelValue;
+        if (StringUtils.equalsAnyIgnoreCase(fieldName, dictFieldName)) {
+            Map<String, String> dict = dictMap.get(fieldName);
+            Set<String> dictKeys = dict.keySet();
+            excelValue = dictKeys.contains(value) ? dict.get(value) : "";
+        } else {
+            excelValue = value;
+        }
+        return new WriteCellData<>(excelValue);
+    }
+}

+ 276 - 0
zjugis-module-adm/zjugis-module-adm-biz/src/main/java/com/zjugis/module/adm/controller/admin/staff/vo/records/StaffExcelResponse.java

@@ -0,0 +1,276 @@
+package com.zjugis.module.adm.controller.admin.staff.vo.records;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+
+
+@Data
+public class StaffExcelResponse {
+
+    /**
+     * 部门名称
+     */
+    @ExcelProperty(value = "部门名称")
+    private String deptName;
+
+
+    /**
+     * 登录名称
+     */
+    @ExcelProperty(value = "工号")
+    private String loginName;
+
+
+    /**
+     * 员工姓名
+     */
+    @ExcelProperty(value = "员工姓名")
+    private String nickname;
+
+    /**
+     * 担任职务
+     */
+    @ExcelProperty(value = "担任职务", converter = StaffConverter.class)
+    private String drzw;
+
+    /**
+     * 性别
+     */
+    @ExcelProperty(value = "性别", converter = StaffConverter.class)
+    private String sex;
+
+    /**
+     * 出生日期
+     */
+    @ExcelProperty(value = "出生日期")
+    private LocalDateTime birthday;
+
+    /**
+     * 年龄
+     */
+    @ExcelProperty(value = "年龄")
+    private Integer nl;
+
+    /**
+     * 毕业时间
+     */
+    @ExcelProperty(value = "毕业时间")
+    private LocalDateTime bysj;
+
+    /**
+     * 最高学历
+     */
+    @ExcelProperty(value = "学历", converter = StaffConverter.class)
+    private String zgxl;
+
+    /**
+     * 毕业学校
+     */
+    @ExcelProperty(value = "毕业学校")
+    private String byxx;
+
+    /**
+     * 专业
+     */
+    @ExcelProperty(value = "专业")
+    private String major;
+
+    /**
+     * 身份证号码
+     */
+    @ExcelProperty(value = "身份证号码")
+    private String cardid;
+
+
+    /**
+     * 参加工作时间
+     */
+    @ExcelProperty(value = "参加工作时间")
+    private LocalDateTime cjgzsj;
+
+    /**
+     * 户口性质
+     */
+    @ExcelProperty(value = "户口性质", converter = StaffConverter.class)
+    private String hkxz;
+
+    /**
+     * 户口所在地
+     */
+    @ExcelProperty(value = "户口所在地")
+    private String hkszd;
+
+    /**
+     * 万维空间入职时间
+     */
+    @ExcelProperty(value = "万维空间入职时间")
+    private LocalDateTime rgssj;
+
+    /**
+     * 转正时间
+     */
+    @ExcelProperty(value = "转正时间")
+    private LocalDateTime zzsj;
+
+    /**
+     * 签订公司
+     */
+    @ExcelProperty(value = "签订公司")
+    private String qdgs;
+
+    /**
+     * 原始合同起始日期
+     */
+    @ExcelProperty(value = "原始合同起始日期")
+    private LocalDate yshtqssj;
+
+    /**
+     * 合同签订时间
+     */
+    @ExcelProperty(value = "合同签订时间")
+    private LocalDateTime htqdsj;
+
+    /**
+     * 合同到期时
+     */
+    @ExcelProperty(value = "合同到期时")
+    private LocalDateTime htdqs;
+
+    /**
+     * 续签情况
+     */
+    @ExcelProperty(value = "续签情况")
+    private String xqqk;
+
+    /**
+     * 职称
+     */
+    @ExcelProperty(value = "职称")
+    private String zc;
+
+    /**
+     * 政治面貌
+     */
+    @ExcelProperty(value = "政治面貌", converter = StaffConverter.class)
+    private String zzmm;
+
+    /**
+     * 婚姻状况
+     */
+    @ExcelProperty(value = "婚姻状况", converter = StaffConverter.class)
+    private String hyzk;
+
+    /**
+     * 现居住地址
+     */
+    @ExcelProperty(value = "现居住地址")
+    private String xjzdz;
+
+    /**
+     * 手机
+     */
+    @ExcelProperty(value = "手机")
+    private String mobilePhone;
+
+
+    /**
+     * 紧急联系人姓名
+     */
+    @ExcelProperty(value = "紧急联系人姓名")
+    private String jjlxrxm;
+
+    /**
+     * 紧急联系人号码
+     */
+    @ExcelProperty(value = "紧急联系人号码")
+    private String jjlxrhm;
+
+    /**
+     * 紧急联系人关系
+     */
+    @ExcelProperty(value = "紧急联系人关系", converter = StaffConverter.class)
+    private String jjlxrgx;
+
+
+    /**
+     * 工作经历
+     */
+    @ExcelProperty(value = "工作经历")
+    private String gzjl;
+
+    /**
+     * 民族
+     */
+    @ExcelProperty(value = "民族",converter = StaffConverter.class)
+    private String nation;
+    /**
+     * 状态 1-实习
+     * 2-试用
+     * 3-正式
+     * 4-离职
+     */
+    @ExcelProperty(value = "状态", converter = StaffConverter.class)
+    private String state;
+
+    /**
+     * 能力等级
+     */
+    @ExcelProperty(value = "能力等级", converter = StaffConverter.class)
+    private String nldj;
+
+
+    /**
+     * 指导人名称
+     */
+    @ExcelProperty(value = "指导人名称")
+    private String zdrmc;
+
+    /**
+     * 初始司领
+     */
+    @ExcelProperty(value = "初始司领")
+    private Integer cssl;
+
+    /**
+     * 年假
+     */
+    @ExcelProperty(value = "年假")
+    private Integer nj;
+
+    /**
+     * 开户银行
+     */
+    @ExcelProperty(value = "开户银行")
+    private String khyh;
+
+    /**
+     * 银行账号
+     */
+    @ExcelProperty(value = "银行账号")
+    private String yhzh;
+
+
+    /**
+     * 试用期
+     */
+    @ExcelProperty(value = "试用期")
+    private Integer syq;
+
+    /**
+     * 续签次数
+     */
+    @ExcelProperty(value = "续签次数")
+    private Integer xqcs;
+
+    /**
+     * 离职时间
+     */
+    @ExcelProperty(value = "离职时间")
+    private LocalDateTime lzsj;
+
+
+}

+ 29 - 0
zjugis-module-adm/zjugis-module-adm-biz/src/main/java/com/zjugis/module/adm/framework/spring/ApplicationContextProvider.java

@@ -0,0 +1,29 @@
+package com.zjugis.module.adm.framework.spring;
+
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+import org.springframework.stereotype.Component;
+
+/**
+ * @author jzh
+ * @since 2024/6/4 11:23
+ */
+@Component
+public class ApplicationContextProvider implements ApplicationContextAware {
+
+    private static ApplicationContext applicationContext;
+
+    @Override
+    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
+        ApplicationContextProvider.applicationContext = applicationContext;
+    }
+
+    public static ApplicationContext getApplicationContext() {
+        return applicationContext;
+    }
+
+    public static <T> T getBean(Class<T> requiredType) {
+        return applicationContext.getBean(requiredType);
+    }
+}

+ 7 - 0
zjugis-module-adm/zjugis-module-adm-biz/src/main/java/com/zjugis/module/adm/service/staff/RecordsServiceImpl.java

@@ -210,6 +210,13 @@ public class RecordsServiceImpl implements RecordsService {
             staffRecordSDO.setLoginName(generateNum());
             staffRecordSDO.setUserId(UUID.randomUUID().toString());
             staffRecordSDO.setDeleted(false);
+
+            //计算年龄
+            if (staffRecordSDO.getBirthday() != null) {
+                Integer birthYear = staffRecordSDO.getBirthday().getYear();
+                Integer nowYear = LocalDateTime.now().getYear();
+                staffRecordSDO.setNl(nowYear - birthYear);
+            }
             recordsMapper.insert(staffRecordSDO);
         }