|
@@ -1,27 +1,43 @@
|
|
|
package com.jeeplus.human.enrollment.enrollmentRegistration.controller;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.extra.spring.SpringUtil;
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
+import com.alibaba.excel.ExcelWriter;
|
|
|
+import com.alibaba.excel.write.metadata.WriteSheet;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
import com.jeeplus.common.TokenProvider;
|
|
|
+import com.jeeplus.common.excel.EasyExcelUtils;
|
|
|
import com.jeeplus.common.utils.ResponseUtil;
|
|
|
import com.jeeplus.flowable.feign.IFlowableApi;
|
|
|
import com.jeeplus.human.depart.handover.domain.Handover;
|
|
|
import com.jeeplus.human.depart.handover.service.HandoverService;
|
|
|
import com.jeeplus.human.enrollment.enrollmentRegistration.domain.*;
|
|
|
import com.jeeplus.human.enrollment.enrollmentRegistration.service.*;
|
|
|
+import com.jeeplus.human.enrollment.enrollmentRegistration.service.dto.UserTemplate;
|
|
|
import com.jeeplus.human.enrollment.enrollmentRegistration.utils.HunamFreemarkerUtil;
|
|
|
+import com.jeeplus.human.enrollment.enrollmentRegistration.utils.IdCardUtil;
|
|
|
import com.jeeplus.human.practice.register.domain.Registration;
|
|
|
import com.jeeplus.logging.annotation.ApiLog;
|
|
|
import com.jeeplus.logging.constant.enums.LogTypeEnum;
|
|
|
+import com.jeeplus.pubmodules.holiday.utils.EasyPoiUtil;
|
|
|
+import com.jeeplus.sys.feign.IOfficeApi;
|
|
|
+import com.jeeplus.sys.feign.IRoleApi;
|
|
|
import com.jeeplus.sys.feign.IUserApi;
|
|
|
+import com.jeeplus.sys.service.dto.OfficeDTO;
|
|
|
+import com.jeeplus.sys.service.dto.RoleDTO;
|
|
|
import com.jeeplus.sys.service.dto.UserDTO;
|
|
|
+import com.jeeplus.utils.StringUtils;
|
|
|
import freemarker.template.Configuration;
|
|
|
import freemarker.template.Template;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import io.swagger.models.auth.In;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.pdfbox.pdmodel.PDDocument;
|
|
|
import org.apache.pdfbox.pdmodel.PDPage;
|
|
|
import org.apache.pdfbox.pdmodel.PDPageContentStream;
|
|
@@ -33,6 +49,7 @@ import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
|
|
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
import org.w3c.dom.Document;
|
|
|
import org.w3c.dom.Node;
|
|
|
import org.w3c.dom.NodeList;
|
|
@@ -47,6 +64,8 @@ import javax.validation.Valid;
|
|
|
import javax.xml.parsers.DocumentBuilder;
|
|
|
import javax.xml.parsers.DocumentBuilderFactory;
|
|
|
import java.io.*;
|
|
|
+import java.lang.reflect.Field;
|
|
|
+import java.lang.reflect.Type;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.nio.file.Files;
|
|
|
import java.nio.file.Path;
|
|
@@ -61,6 +80,7 @@ import java.util.stream.Collectors;
|
|
|
* @version 1.0
|
|
|
* @date 2023-09-27 14:14
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
@RestController
|
|
|
@Api("实习人员登记表信息")
|
|
|
@RequestMapping(value = "/enrollmentRegistration")
|
|
@@ -516,4 +536,133 @@ public class EnrollmentRegistrationController {
|
|
|
Integer idCardOnly = service.findMobilePhoneOnly(mobilePhone);
|
|
|
return ResponseEntity.ok(idCardOnly);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 下载导入用户数据模板
|
|
|
+ *
|
|
|
+ * @param response
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @GetMapping("import/template")
|
|
|
+ @ApiOperation(value = "下载模板")
|
|
|
+ public void importFileTemplate(HttpServletResponse response, HttpServletRequest request) throws IOException {
|
|
|
+ String fileName = "用户数据导入模板.xlsx";
|
|
|
+ List <UserTemplate> list = Lists.newArrayList ( );
|
|
|
+ UserTemplate userTemplate = new UserTemplate();
|
|
|
+ userTemplate.setInDate("例:1970-01-01");
|
|
|
+ list.add(userTemplate);
|
|
|
+ EasyExcelUtils.newInstance ( ).exportExcel ( list, "用户数据", UserTemplate.class, fileName, null, response );
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导入用户数据
|
|
|
+ */
|
|
|
+ @PostMapping("import")
|
|
|
+ @ApiOperation(value = "导入用户excel")
|
|
|
+ public ResponseEntity importDetail(@RequestPart("file") MultipartFile file, HttpServletRequest request) {
|
|
|
+ List<EnrollmentRegistration> dtoArrayList = new ArrayList<>();
|
|
|
+ //获取sheet
|
|
|
+ dtoArrayList = EasyPoiUtil.importExcel(file, 0, 1, EnrollmentRegistration.class);
|
|
|
+ //去除excel中的空行
|
|
|
+ dtoArrayList = getExcelList(dtoArrayList);
|
|
|
+ ArrayList<EnrollmentRegistration> list = new ArrayList<>();
|
|
|
+ //根据用户身份证号获取用户年龄,性别,出生日期
|
|
|
+ for (EnrollmentRegistration staffUserInfoDTO : dtoArrayList) {
|
|
|
+ if (StringUtils.isNotBlank(staffUserInfoDTO.getIdCard())){
|
|
|
+ //获取年龄
|
|
|
+ Integer age = IdCardUtil.getAge(staffUserInfoDTO.getIdCard());
|
|
|
+ staffUserInfoDTO.setAge(age.toString());
|
|
|
+ //获取性别
|
|
|
+ String sex = IdCardUtil.getSex(staffUserInfoDTO.getIdCard());
|
|
|
+ if (sex.equals("男")){
|
|
|
+ staffUserInfoDTO.setSex("1");
|
|
|
+ }else {
|
|
|
+ staffUserInfoDTO.setSex("2");
|
|
|
+ }
|
|
|
+ //获取出生日期
|
|
|
+ String birthday = IdCardUtil.getBirthday(staffUserInfoDTO.getIdCard());
|
|
|
+ staffUserInfoDTO.setBirthday(birthday);
|
|
|
+ }
|
|
|
+ staffUserInfoDTO.setOnJobStatus("2");
|
|
|
+ //根据所属公司获取部门
|
|
|
+ if (StringUtils.isNotBlank(staffUserInfoDTO.getCompany())){
|
|
|
+ List<OfficeDTO> officeDTOList = SpringUtil.getBean(IOfficeApi.class).getOfficeByCompany(staffUserInfoDTO.getCompany());
|
|
|
+ String tenantId = officeDTOList.get(0).getTenantId();
|
|
|
+ if (CollectionUtil.isNotEmpty(officeDTOList)){
|
|
|
+ for (OfficeDTO officeDTO : officeDTOList) {
|
|
|
+ //获取部门
|
|
|
+ if (StringUtils.isNotBlank(staffUserInfoDTO.getDepartment())){
|
|
|
+ if (officeDTO.getName().equals(staffUserInfoDTO.getDepartment())){
|
|
|
+ staffUserInfoDTO.setDepartment(officeDTO.getId());
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ service.updateInfo(staffUserInfoDTO);
|
|
|
+ }
|
|
|
+ return ResponseEntity.ok("导入成功");
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 去除excel中的空行
|
|
|
+ * @param list
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ArrayList<EnrollmentRegistration> getExcelList(List<EnrollmentRegistration> list){
|
|
|
+
|
|
|
+ ArrayList<EnrollmentRegistration> infoDTOS = new ArrayList<>();
|
|
|
+
|
|
|
+ list.stream().forEach(item->{
|
|
|
+ if(objectCheckIsNull(item)){
|
|
|
+ infoDTOS.add(item);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ return infoDTOS;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static boolean objectCheckIsNull(Object object) {
|
|
|
+ boolean flag = false; //定义返回结果,默认为true
|
|
|
+
|
|
|
+ if (Objects.isNull(object)) {
|
|
|
+ flag = false;
|
|
|
+ } else {
|
|
|
+ Class clazz = (Class) object.getClass(); // 得到类对象
|
|
|
+ Field fields[] = clazz.getDeclaredFields(); // 得到所有属性
|
|
|
+ for (Field field : fields) {
|
|
|
+ if("serialVersionUID".equals(field.getName()) || "BIZ_CODE".equalsIgnoreCase(field.getName())){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ field.setAccessible(true);
|
|
|
+ Object fieldValue = null;
|
|
|
+ try {
|
|
|
+ fieldValue = field.get(object); //得到属性值
|
|
|
+ Type fieldType = field.getGenericType();//得到属性类型
|
|
|
+ String fieldName = field.getName(); // 得到属性名
|
|
|
+ log.info("属性类型:" + fieldType + ",属性名:" + fieldName + ",属性值:" + fieldValue);
|
|
|
+ } catch (IllegalArgumentException e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ } catch (IllegalAccessException e) {
|
|
|
+ log.error(e.getMessage(), e);
|
|
|
+ }
|
|
|
+ if (fieldValue != null && fieldValue != "") { //只要有一个属性值不为null 就返回false 表示对象不为null
|
|
|
+ flag = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return flag;
|
|
|
+ }
|
|
|
+
|
|
|
}
|