入场人员导入导出
This commit is contained in:
parent
19f1880f13
commit
4db714fa4c
|
|
@ -35,6 +35,8 @@ import java.time.LocalDateTime;
|
|||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static cn.hutool.poi.excel.cell.CellUtil.getCellValue;
|
||||
|
||||
/**
|
||||
* Excel相关处理
|
||||
*
|
||||
|
|
@ -178,6 +180,11 @@ public class ExcelUtil<T>
|
|||
return importExcel(StringUtils.EMPTY, is, titleNum);
|
||||
}
|
||||
|
||||
public List<T> importExcelDoubleTitle(InputStream is, int titleNum) throws Exception
|
||||
{
|
||||
return importExcelDoubleTitle(StringUtils.EMPTY, is, titleNum);
|
||||
}
|
||||
|
||||
/**
|
||||
* 对excel表单默认第一个索引名转换成list
|
||||
*
|
||||
|
|
@ -364,6 +371,187 @@ public class ExcelUtil<T>
|
|||
return list;
|
||||
}
|
||||
|
||||
public List<T> importExcelDoubleTitle(String sheetName, InputStream is, int titleNum) throws Exception
|
||||
{
|
||||
this.type = Type.IMPORT;
|
||||
this.wb = WorkbookFactory.create(is);
|
||||
List<T> list = new ArrayList<T>();
|
||||
// 如果指定sheet名,则取指定sheet中的内容 否则默认指向第1个sheet
|
||||
Sheet sheet = StringUtils.isNotEmpty(sheetName) ? wb.getSheet(sheetName) : wb.getSheetAt(0);
|
||||
if (sheet == null)
|
||||
{
|
||||
throw new IOException("文件sheet不存在");
|
||||
}
|
||||
|
||||
// 获取最后一个非空行的行下标,比如总行数为n,则返回的为n-1
|
||||
int rows = sheet.getLastRowNum();
|
||||
while (rows > 0) {
|
||||
Row currentRow = sheet.getRow(rows);
|
||||
if (isRowEmpty(currentRow)) {
|
||||
rows--; // 如果是空行则回退到上一行
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
rows++;
|
||||
|
||||
if (rows > 0)
|
||||
{
|
||||
int headerRows = 2;
|
||||
Map<String, Integer> cellMap = new LinkedHashMap<>();
|
||||
for (int col = 0; col < sheet.getRow(titleNum).getLastCellNum(); col++) {
|
||||
StringBuilder headerBuilder = new StringBuilder();
|
||||
for (int row = 0; row < headerRows; row++) {
|
||||
Row currentRow = sheet.getRow(titleNum + row);
|
||||
if (currentRow != null) {
|
||||
String cellValue = getCellValue(currentRow, col).toString().trim();
|
||||
if (!cellValue.isEmpty()) {
|
||||
if (headerBuilder.length() > 0) {
|
||||
headerBuilder.append(".");
|
||||
}
|
||||
headerBuilder.append(cellValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
cellMap.put(headerBuilder.toString(), col);
|
||||
}
|
||||
// 有数据时才处理 得到类的所有field.
|
||||
List<Object[]> fields = this.getFields();
|
||||
Map<Integer, Object[]> fieldsMap = new HashMap<Integer, Object[]>();
|
||||
for (Object[] objects : fields)
|
||||
{
|
||||
Excel attr = (Excel) objects[1];
|
||||
Integer column = cellMap.get(attr.name());
|
||||
if (column != null)
|
||||
{
|
||||
fieldsMap.put(column, objects);
|
||||
}
|
||||
}
|
||||
for (int i = titleNum + headerRows; i <= rows; i++)
|
||||
{
|
||||
// 从第2行开始取数据,默认第一行是表头.
|
||||
Row row = sheet.getRow(i);
|
||||
// 判断当前行是否是空行
|
||||
if (isRowEmpty(row))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
T entity = null;
|
||||
for (Map.Entry<Integer, Object[]> entry : fieldsMap.entrySet())
|
||||
{
|
||||
Object val = this.getCellValue(row, entry.getKey());
|
||||
|
||||
// 如果不存在实例则新建.
|
||||
entity = (entity == null ? clazz.newInstance() : entity);
|
||||
// 从map中得到对应列的field.
|
||||
Field field = (Field) entry.getValue()[0];
|
||||
Excel attr = (Excel) entry.getValue()[1];
|
||||
// 取得类型,并根据对象类型设置值.
|
||||
Class<?> fieldType = field.getType();
|
||||
if (String.class == fieldType)
|
||||
{
|
||||
String s = Convert.toStr(val);
|
||||
if (StringUtils.endsWith(s, ".0"))
|
||||
{
|
||||
val = StringUtils.substringBefore(s, ".0");
|
||||
}
|
||||
else
|
||||
{
|
||||
String dateFormat = field.getAnnotation(Excel.class).dateFormat();
|
||||
if (StringUtils.isNotEmpty(dateFormat))
|
||||
{
|
||||
val = parseDateToStr(dateFormat, val);
|
||||
}
|
||||
else
|
||||
{
|
||||
val = Convert.toStr(val);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ((Integer.TYPE == fieldType || Integer.class == fieldType) && StringUtils.isNumeric(Convert.toStr(val)))
|
||||
{
|
||||
val = Convert.toInt(val);
|
||||
}
|
||||
else if ((Long.TYPE == fieldType || Long.class == fieldType) && StringUtils.isNumeric(Convert.toStr(val)))
|
||||
{
|
||||
val = Convert.toLong(val);
|
||||
}
|
||||
else if (Double.TYPE == fieldType || Double.class == fieldType)
|
||||
{
|
||||
val = Convert.toDouble(val);
|
||||
}
|
||||
else if (Float.TYPE == fieldType || Float.class == fieldType)
|
||||
{
|
||||
val = Convert.toFloat(val);
|
||||
}
|
||||
else if (BigDecimal.class == fieldType)
|
||||
{
|
||||
val = Convert.toBigDecimal(val);
|
||||
}
|
||||
else if (Date.class == fieldType)
|
||||
{
|
||||
if (val instanceof String)
|
||||
{
|
||||
val = DateUtils.parseDate(val);
|
||||
}
|
||||
else if (val instanceof Double)
|
||||
{
|
||||
val = DateUtil.getJavaDate((Double) val);
|
||||
}
|
||||
}
|
||||
else if (Boolean.TYPE == fieldType || Boolean.class == fieldType)
|
||||
{
|
||||
val = Convert.toBool(val, false);
|
||||
}
|
||||
//是否必填
|
||||
boolean required = attr.required();
|
||||
//是否必须符合电话号码的规则
|
||||
String isRegex = attr.isRegex();
|
||||
if (StringUtils.isNotNull(fieldType))
|
||||
{
|
||||
String propertyName = field.getName();
|
||||
if (StringUtils.isNotEmpty(attr.targetAttr()))
|
||||
{
|
||||
propertyName = field.getName() + "." + attr.targetAttr();
|
||||
}
|
||||
else if(required) {
|
||||
if(StringUtils.isNull(val) || StringUtils.isEmpty(val.toString().trim())) {
|
||||
throw new IllegalArgumentException(attr.name()+" 单元格必填项未填写,请正确填写!");
|
||||
}
|
||||
}
|
||||
else if(StringUtils.isNotEmpty(isRegex)) {
|
||||
if(StringUtils.isNull(val) || StringUtils.isEmpty(val.toString().trim())) {
|
||||
throw new IllegalArgumentException(attr.name()+" 单元格必填项未填写,请正确填写!");
|
||||
}else{
|
||||
boolean b = changeDataType(isRegex, val.toString().trim());
|
||||
if(!b) {
|
||||
throw new IllegalArgumentException(attr.name()+" 单元格必需填写正确的格式!");
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (StringUtils.isNotEmpty(attr.readConverterExp()))
|
||||
{
|
||||
val = reverseByExp(Convert.toStr(val), attr.readConverterExp(), attr.separator());
|
||||
}
|
||||
else if (!attr.handler().equals(ExcelHandlerAdapter.class))
|
||||
{
|
||||
val = dataFormatHandlerAdapter(val, attr);
|
||||
}
|
||||
ReflectUtils.invokeSetter(entity, propertyName, val);
|
||||
}
|
||||
}
|
||||
list.add(entity);
|
||||
}
|
||||
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 对excel表单指定表格索引名转换成list---
|
||||
|
|
@ -689,8 +877,7 @@ public class ExcelUtil<T>
|
|||
}
|
||||
|
||||
/**
|
||||
* 根据Excel注解创建表格头样式
|
||||
*
|
||||
* 根据Excel注解创建表格头样式*
|
||||
* @param wb 工作薄对象
|
||||
* @return 自定义样式列表
|
||||
*/
|
||||
|
|
@ -724,7 +911,6 @@ public class ExcelUtil<T>
|
|||
|
||||
/**
|
||||
* 根据Excel注解创建表格列样式
|
||||
*
|
||||
* @param wb 工作薄对象
|
||||
* @return 自定义样式列表
|
||||
*/
|
||||
|
|
@ -920,7 +1106,7 @@ public class ExcelUtil<T>
|
|||
|
||||
/**
|
||||
* 设置 POI XSSFSheet 单元格提示或选择框
|
||||
*
|
||||
*
|
||||
* @param sheet 表单
|
||||
* @param textlist 下拉框显示的内容
|
||||
* @param promptContent 提示内容
|
||||
|
|
@ -1325,7 +1511,7 @@ public class ExcelUtil<T>
|
|||
|
||||
/**
|
||||
* 格式化不同类型的日期对象
|
||||
*
|
||||
*
|
||||
* @param dateFormat 日期格式
|
||||
* @param val 被格式化的日期对象
|
||||
* @return 格式化后的日期字符
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.bonus.bmw.person.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.bonus.bmw.person.entity.BasePersonBean;
|
||||
import com.bonus.bmw.person.service.BasePersonService;
|
||||
|
|
@ -9,11 +10,19 @@ import com.bonus.common.core.table.PageTableResponse;
|
|||
import com.bonus.common.log.annotation.Log;
|
||||
import com.bonus.common.log.enums.BusinessType;
|
||||
import com.bonus.common.security.annotation.RequiresPermissions;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* 人员库
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import cn.hutool.core.date.DateTime;
|
|||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import com.bonus.bmw.basic.entity.ProjectBean;
|
||||
import com.bonus.bmw.basic.entity.ProjectFileBean;
|
||||
import com.bonus.bmw.basic.service.UserService;
|
||||
import com.bonus.bmw.config.IpAndPathConfig;
|
||||
import com.bonus.bmw.person.entity.PersonComprehensiveBean;
|
||||
|
|
@ -13,6 +14,7 @@ import com.bonus.bmw.person.utils.FaceResult;
|
|||
import com.bonus.common.core.domain.R;
|
||||
import com.bonus.common.core.table.PageTableRequest;
|
||||
import com.bonus.common.core.table.PageTableResponse;
|
||||
import com.bonus.common.core.utils.poi.ExcelUtil;
|
||||
import com.bonus.common.log.annotation.Log;
|
||||
import com.bonus.common.log.enums.BusinessType;
|
||||
import com.bonus.common.security.annotation.RequiresPermissions;
|
||||
|
|
@ -329,4 +331,21 @@ public class PersonComprehensiveController {
|
|||
}
|
||||
}
|
||||
|
||||
//导出
|
||||
// @GetMapping("/exportBtnOut")
|
||||
// @Log(title = "出场人员-导出", businessType = BusinessType.EXPORT)
|
||||
// public void exportBtnOut(HttpServletResponse response, PersonComprehensiveBean o) {
|
||||
// try{
|
||||
// List<PersonComprehensiveBean> list = service.exportBtnOut(o);
|
||||
// ExcelUtil<PersonComprehensiveBean> util = new ExcelUtil<PersonComprehensiveBean>(PersonComprehensiveBean.class);
|
||||
// util.exportExcel(response, list, "入场人员管理");
|
||||
// }catch (Exception e){
|
||||
// log.error(e.toString(),e);
|
||||
// }
|
||||
// }
|
||||
@GetMapping("/exportBtnOut")
|
||||
public void exportBtnOut(HttpServletResponse response, PageTableRequest request) {
|
||||
service.exportBtnOut(response,request.getParams());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,6 +104,8 @@ public interface PersonComprehensiveDao {
|
|||
|
||||
PersonComprehensiveBean selectTeamHistoryData(PersonComprehensiveBean o);
|
||||
|
||||
List<PersonComprehensiveBean> getBasePersonLists(@Param("params")Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 根据工程查组织
|
||||
* @param proId
|
||||
|
|
|
|||
|
|
@ -21,13 +21,13 @@ public class BasePersonBean {
|
|||
/**
|
||||
* 姓名
|
||||
*/
|
||||
@Excel(name = "姓名 * ",required = true)
|
||||
@Excel(name = "身份证信息.*姓 名",required = true)
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 身份证
|
||||
*/
|
||||
@Excel(name = "身份证号 * ", isRegex = RegexConstants.IDCARD)
|
||||
@Excel(name = "*身份证号", isRegex = RegexConstants.IDCARD)
|
||||
private String idNumber;
|
||||
|
||||
/**
|
||||
|
|
@ -38,66 +38,67 @@ public class BasePersonBean {
|
|||
/**
|
||||
* 性别
|
||||
*/
|
||||
@Excel(name = "性别 * ",required = true)
|
||||
// @Excel(name = "性别 * ",required = true)
|
||||
private String sex;
|
||||
|
||||
/**
|
||||
* 民族
|
||||
*/
|
||||
@Excel(name = "民族 * ",required = true)
|
||||
@Excel(name = "*民族",required = true)
|
||||
private String ethnic;
|
||||
|
||||
/**
|
||||
* 出生日期
|
||||
*/
|
||||
@Excel(name = "出生日期 * ",required = true)
|
||||
// @Excel(name = "出生日期 * ",required = true)
|
||||
private String birthday;
|
||||
|
||||
/**
|
||||
* 家庭地址
|
||||
*/
|
||||
@Excel(name = "身份证住址 * ",required = true)
|
||||
@Excel(name = "*身份证住址",required = true)
|
||||
private String address;
|
||||
|
||||
/**
|
||||
* 办证机关
|
||||
*/
|
||||
@Excel(name = "签发机关 * ",required = true)
|
||||
@Excel(name = "*签发机关",required = true)
|
||||
private String issueauthority;
|
||||
|
||||
/**
|
||||
* 有效开始日期
|
||||
*/
|
||||
@Excel(name = "有效期限 * ",required = true)
|
||||
@Excel(name = "*身份证生效日期",required = true)
|
||||
private String signDate;
|
||||
|
||||
/**
|
||||
* 有效结束日期
|
||||
*/
|
||||
@Excel(name = "*身份证失效日期",required = true)
|
||||
private String expiryDate;
|
||||
|
||||
/**
|
||||
* 联系方式
|
||||
*/
|
||||
@Excel(name = "手机号码 * ", isRegex = RegexConstants.PHONE )
|
||||
@Excel(name = "*手机号码", isRegex = RegexConstants.PHONE )
|
||||
private String phone;
|
||||
|
||||
/**
|
||||
* 文化程度
|
||||
*/
|
||||
@Excel(name = "文化程度")
|
||||
// @Excel(name = "文化程度")
|
||||
private String cultrue;
|
||||
|
||||
/**
|
||||
* 政治面貌
|
||||
*/
|
||||
@Excel(name = "政治面貌")
|
||||
// @Excel(name = "政治面貌")
|
||||
private String politicalOutlook;
|
||||
|
||||
/**
|
||||
* 家庭电话
|
||||
*/
|
||||
@Excel(name = "家庭电话")
|
||||
// @Excel(name = "家庭电话")
|
||||
private String addressPhone;
|
||||
|
||||
/**
|
||||
|
|
@ -108,43 +109,43 @@ public class BasePersonBean {
|
|||
/**
|
||||
* 工种名称
|
||||
*/
|
||||
@Excel(name = "工人工种 * ",required = true)
|
||||
// @Excel(name = "工人工种 * ",required = true)
|
||||
private String postName;
|
||||
|
||||
/**
|
||||
* 人员类型
|
||||
*/
|
||||
@Excel(name = "人员类型")
|
||||
// @Excel(name = "人员类型")
|
||||
private String personType;
|
||||
|
||||
/**
|
||||
* 工人技能
|
||||
*/
|
||||
@Excel(name = "工人技能")
|
||||
// @Excel(name = "工人技能")
|
||||
private String workerSkill;
|
||||
|
||||
/**
|
||||
* 重要人员
|
||||
*/
|
||||
@Excel(name = "重要人员")
|
||||
// @Excel(name = "重要人员")
|
||||
private String importantPerson;
|
||||
|
||||
/**
|
||||
* 紧急联系人
|
||||
*/
|
||||
@Excel(name = "紧急联系人")
|
||||
@Excel(name = "亲属.*紧急联系人")
|
||||
private String urgentPerson;
|
||||
|
||||
/**
|
||||
* 紧急联系人电话
|
||||
*/
|
||||
@Excel(name = "紧急联系人电话")
|
||||
@Excel(name = "*紧急联系人电话")
|
||||
private String urgentPersonPhone;
|
||||
|
||||
/**
|
||||
* 银行名称
|
||||
*/
|
||||
@Excel(name = "银行名称")
|
||||
@Excel(name = "银行卡.银行名称")
|
||||
private String bankName;
|
||||
|
||||
/**
|
||||
|
|
@ -153,6 +154,9 @@ public class BasePersonBean {
|
|||
@Excel(name = "银行卡号")
|
||||
private String bankCard;
|
||||
|
||||
@Excel(name = "银行卡号(选填)")
|
||||
private String bankInter;
|
||||
|
||||
/**
|
||||
* 年龄
|
||||
*/
|
||||
|
|
@ -239,7 +243,7 @@ public class BasePersonBean {
|
|||
private Integer operate;
|
||||
|
||||
private int isPlan;
|
||||
|
||||
|
||||
private String isTeamMan;
|
||||
private String exitVideoPath;
|
||||
private String exitSignPath;
|
||||
|
|
@ -250,7 +254,7 @@ public class BasePersonBean {
|
|||
|
||||
private List<BasePersonBean> idNumberList;
|
||||
|
||||
@Excel(name = "务工类型 * ",required = true)
|
||||
// @Excel(name = "务工类型 * ",required = true)
|
||||
private String employmentTypes;//关键信息 务工类型
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import com.bonus.common.core.table.PageTableResponse;
|
|||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 人员库-业务层
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
package com.bonus.bmw.person.service;
|
||||
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.poi.excel.ExcelWriter;
|
||||
import com.bonus.bmw.person.dao.BasePersonDao;
|
||||
import com.bonus.bmw.person.dao.TDictDao;
|
||||
import com.bonus.bmw.person.entity.BasePersonBean;
|
||||
|
|
@ -18,7 +20,11 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
|
@ -91,10 +97,15 @@ public class BasePersonServiceImp implements BasePersonService{
|
|||
public R insertBasePersonData(MultipartFile file) throws Exception{
|
||||
int insertBasicCount = 0;
|
||||
ExcelUtil<BasePersonBean> util = new ExcelUtil<BasePersonBean>(BasePersonBean.class);
|
||||
List<BasePersonBean> list = util.importExcel(file.getInputStream(),2);
|
||||
List<BasePersonBean> list = util.importExcelDoubleTitle(file.getInputStream(),2);
|
||||
if(list.size() != 0){
|
||||
list = listThread(list);
|
||||
insertBasicCount = dao.insertBasePersonBasicData(list);
|
||||
boolean hasBankData = list.stream()
|
||||
.anyMatch(p -> !StringUtils.isEmpty(p.getBankCard()));
|
||||
if(insertBasicCount>0 && hasBankData){
|
||||
dao.insertBasePersonBankData(list);
|
||||
}
|
||||
}
|
||||
return insertBasicCount > 0 ?
|
||||
R.ok(Constants.INSERT_SUCCESS)
|
||||
|
|
@ -203,46 +214,58 @@ public class BasePersonServiceImp implements BasePersonService{
|
|||
SimpleDateFormat originalFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", java.util.Locale.US);
|
||||
list.forEach(c->{
|
||||
TrimUtil.trimBean(c);
|
||||
if(StringUtils.isNotEmpty(c.getSignDate()) && c.getSignDate().contains("-")){
|
||||
String signDate = StringUtils.getThreeBarVal(c.getSignDate(),1);
|
||||
String expiryDate = StringUtils.getThreeBarVal(c.getSignDate(),2);
|
||||
c.setSignDate(signDate);
|
||||
c.setExpiryDate(expiryDate);
|
||||
}
|
||||
// if(StringUtils.isNotEmpty(c.getSignDate()) && c.getSignDate().contains("/")){
|
||||
// String signDate = StringUtils.getThreeBarVal(c.getSignDate(),1);
|
||||
// String expiryDate = StringUtils.getThreeBarVal(c.getSignDate(),2);
|
||||
// c.setSignDate(signDate);
|
||||
// c.setExpiryDate(expiryDate);
|
||||
// }
|
||||
try {
|
||||
Date date = originalFormat.parse(c.getBirthday());
|
||||
Map<String, String> resultMap = StringUtils.getBirthdayAgeSex(c.getIdNumber());
|
||||
Date sDate = originalFormat.parse(c.getSignDate());
|
||||
Date eDate = originalFormat.parse(c.getExpiryDate());
|
||||
// 转换为LocalDate
|
||||
LocalDate localDate = date.toInstant().atZone(java.time.ZoneId.systemDefault()).toLocalDate();
|
||||
LocalDate sLocalDate = sDate.toInstant().atZone(java.time.ZoneId.systemDefault()).toLocalDate();
|
||||
LocalDate eLocalDate = eDate.toInstant().atZone(java.time.ZoneId.systemDefault()).toLocalDate();
|
||||
// 格式化输出为"yyyy-MM-dd"
|
||||
String formattedDate = localDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
||||
c.setBirthday(formattedDate);
|
||||
String sFormattedDate = sLocalDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
||||
String eFormattedDate = eLocalDate.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
|
||||
c.setSignDate(sFormattedDate);
|
||||
c.setExpiryDate(eFormattedDate);
|
||||
c.setBirthday(resultMap.get("birthday"));
|
||||
if(Objects.equals(resultMap.get("sex"), "1")){
|
||||
c.setSex("男");
|
||||
}
|
||||
else{
|
||||
c.setSex("女");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
//岗位
|
||||
AtomicInteger x = new AtomicInteger();
|
||||
dictBeanList.forEach(i -> {
|
||||
if(c.getPostName().equals(i.getValue())){
|
||||
c.setPostId(i.getId());
|
||||
x.getAndIncrement();
|
||||
}
|
||||
});
|
||||
if(x.intValue()==0){
|
||||
throw new IllegalArgumentException(c.getPostName()+" 工种无法正确匹配,请正确填写!");
|
||||
}
|
||||
String u = dao.getExistPerson(c.getIdNumber());
|
||||
String b = dao.getBlackPerson(c.getIdNumber());
|
||||
if (u != null || b != null) {
|
||||
throw new IllegalArgumentException(c.getIdNumber() + "已存在或为黑名单");
|
||||
}
|
||||
|
||||
if(c.getEmploymentTypes().equals("本地务工(兰坪)")){
|
||||
c.setEmploymentTypes("0");
|
||||
}else if(c.getEmploymentTypes().equals("外地务工")){
|
||||
c.setEmploymentTypes("1");
|
||||
}else{
|
||||
throw new IllegalArgumentException(c.getEmploymentTypes()+"务工类型无法正确匹配,请正确填写!");
|
||||
}
|
||||
// //岗位
|
||||
// AtomicInteger x = new AtomicInteger();
|
||||
// dictBeanList.forEach(i -> {
|
||||
// if(c.getPostName().equals(i.getValue())){
|
||||
// c.setPostId(i.getId());
|
||||
// x.getAndIncrement();
|
||||
// }
|
||||
// });
|
||||
// if(x.intValue()==0){
|
||||
// throw new IllegalArgumentException(c.getPostName()+" 工种无法正确匹配,请正确填写!");
|
||||
// }
|
||||
// String u = dao.getExistPerson(c.getIdNumber());
|
||||
// String b = dao.getBlackPerson(c.getIdNumber());
|
||||
// if (u != null || b != null) {
|
||||
// throw new IllegalArgumentException(c.getIdNumber() + "已存在或为黑名单");
|
||||
// }
|
||||
//
|
||||
// if(c.getEmploymentTypes().equals("本地务工(兰坪)")){
|
||||
// c.setEmploymentTypes("0");
|
||||
// }else if(c.getEmploymentTypes().equals("外地务工")){
|
||||
// c.setEmploymentTypes("1");
|
||||
// }else{
|
||||
// throw new IllegalArgumentException(c.getEmploymentTypes()+"务工类型无法正确匹配,请正确填写!");
|
||||
// }
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,14 @@
|
|||
package com.bonus.bmw.person.service;
|
||||
|
||||
import com.bonus.bmw.basic.entity.ProjectFileBean;
|
||||
import com.bonus.bmw.person.entity.PersonComprehensiveBean;
|
||||
import com.bonus.common.core.domain.R;
|
||||
import com.bonus.common.core.table.PageTableRequest;
|
||||
import com.bonus.common.core.table.PageTableResponse;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 人员库-业务层
|
||||
|
|
@ -40,4 +43,8 @@ public interface PersonComprehensiveService {
|
|||
R<List<String>> getHolidaysList(String nation);
|
||||
|
||||
List<PersonComprehensiveBean> getDownloads(PersonComprehensiveBean bean);
|
||||
|
||||
// List<PersonComprehensiveBean> exportBtnOut(PersonComprehensiveBean bean);
|
||||
|
||||
void exportBtnOut(HttpServletResponse response, Map<String, Object> params);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,12 @@
|
|||
package com.bonus.bmw.person.service;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.poi.excel.ExcelWriter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import com.bonus.bmw.attendanceMachine.dao.AttendanceMachineDao;
|
||||
import com.bonus.bmw.basic.dao.UserDao;
|
||||
import com.bonus.bmw.basic.entity.ProjectFileBean;
|
||||
import com.bonus.bmw.person.dao.BasePersonDao;
|
||||
import com.bonus.bmw.person.dao.PersonComprehensiveDao;
|
||||
import com.bonus.bmw.person.dao.TDictDao;
|
||||
|
|
@ -25,8 +29,14 @@ import org.springframework.stereotype.Service;
|
|||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 人员库-业务层
|
||||
|
|
@ -594,4 +604,146 @@ public class PersonComprehensiveServiceImp implements PersonComprehensiveService
|
|||
});
|
||||
return list;
|
||||
}
|
||||
//
|
||||
@Override
|
||||
public void exportBtnOut(HttpServletResponse response, Map<String, Object> params) {
|
||||
|
||||
List<PersonComprehensiveBean> list = getBasePersonLists(params);
|
||||
//根据工程计算出合并单元格的数量
|
||||
Map<String, Long> collect = list.stream().collect(Collectors.groupingBy(PersonComprehensiveBean::getName, Collectors.counting()));
|
||||
List<Long> integerList = new ArrayList<>();
|
||||
collect.forEach((k, v) -> integerList.add(v));
|
||||
|
||||
int rowNum = list.size();
|
||||
String fileName = " 出场人员 ";
|
||||
//记录用于合并的rowIndex
|
||||
ArrayList<HashMap<String, Integer>> mergeRows = new ArrayList<>();
|
||||
int startRowIndex = 3, start = 0;
|
||||
start = startRowIndex;
|
||||
int end = 0;
|
||||
for (int i = 0; i < integerList.size(); i++) {
|
||||
end = (int) (start + integerList.get(i)) - 1;
|
||||
if (end != start) {
|
||||
HashMap<String, Integer> map = new HashMap<>();
|
||||
map.put("start", start);
|
||||
map.put("end", end);
|
||||
mergeRows.add(map);
|
||||
}
|
||||
start = end + 1;
|
||||
}
|
||||
// 导出标题
|
||||
ExcelWriter writer = cn.hutool.poi.excel.ExcelUtil.getWriter(true);
|
||||
if (list.size() > 0) {
|
||||
writer.merge(9, fileName, false);
|
||||
writer.writeCellValue(0, 1, "序号");
|
||||
writer.setColumnWidth(0, 6);
|
||||
|
||||
writer.writeCellValue(1, 1, "姓名");
|
||||
writer.setColumnWidth(1, 20);
|
||||
|
||||
writer.writeCellValue(2, 1, "身份证");
|
||||
writer.setColumnWidth(2, 20);
|
||||
|
||||
writer.writeCellValue(3, 1, "联系方式");
|
||||
writer.setColumnWidth(3, 15);
|
||||
|
||||
|
||||
writer.writeCellValue(4, 1, "工种");
|
||||
writer.setColumnWidth(4, 10);
|
||||
|
||||
writer.writeCellValue(5, 1, "所属工程");
|
||||
writer.setColumnWidth(5, 15);
|
||||
|
||||
writer.writeCellValue(6, 1, "人员类型");
|
||||
writer.setColumnWidth(6, 15);
|
||||
|
||||
writer.writeCellValue(7, 1, "红绿灯状态");
|
||||
writer.setColumnWidth(7, 20);
|
||||
|
||||
writer.writeCellValue(8, 1, "出入场状态");
|
||||
writer.setColumnWidth(8, 20);
|
||||
|
||||
writer.writeCellValue(9, 1, "体检状态");
|
||||
writer.setColumnWidth(9, 20);
|
||||
|
||||
// 设置表头高度、单元格宽度
|
||||
writer.setRowHeight(0, 25);
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
writer.writeCellValue(0, 2 + i, i + 1);
|
||||
writer.writeCellValue(1, 2 + i, list.get(i).getName() == null ? "" : list.get(i).getName());
|
||||
writer.writeCellValue(2, 2 + i, list.get(i).getIdNumber() == null ? "" : list.get(i).getIdNumber());
|
||||
writer.writeCellValue(3, 2 + i, list.get(i).getPhone() == null ? "" : list.get(i).getPhone());
|
||||
writer.writeCellValue(4, 2 + i, list.get(i).getPostName() == null ? "" : list.get(i).getPostName());
|
||||
writer.writeCellValue(5, 2 + i, list.get(i).getProName() == null ? "" : list.get(i).getProName());
|
||||
writer.writeCellValue(6, 2 + i, list.get(i).getEmploymentType() == null ? "" : list.get(i).getEmploymentType());
|
||||
writer.writeCellValue(7, 2 + i, list.get(i).getLightStatus() == null ? "" : list.get(i).getLightStatus());
|
||||
writer.writeCellValue(8, 2 + i, list.get(i).getExitStatus() == null ? "" : list.get(i).getExitStatus());
|
||||
writer.writeCellValue(9, 2 + i, list.get(i).getCheckupState() == null ? "" : list.get(i).getCheckupState());
|
||||
}
|
||||
|
||||
|
||||
}else{
|
||||
writer.merge(9, fileName, false);
|
||||
writer.writeCellValue(0, 1, "序号");
|
||||
writer.setColumnWidth(0, 6);
|
||||
|
||||
writer.writeCellValue(1, 1, "姓名");
|
||||
writer.setColumnWidth(1, 20);
|
||||
|
||||
writer.writeCellValue(2, 1, "身份证");
|
||||
writer.setColumnWidth(2, 20);
|
||||
|
||||
writer.writeCellValue(3, 1, "联系方式");
|
||||
writer.setColumnWidth(3, 15);
|
||||
|
||||
|
||||
writer.writeCellValue(4, 1, "工种");
|
||||
writer.setColumnWidth(4, 10);
|
||||
|
||||
writer.writeCellValue(5, 1, "所属工程");
|
||||
writer.setColumnWidth(5, 15);
|
||||
|
||||
writer.writeCellValue(6, 1, "人员类型");
|
||||
writer.setColumnWidth(6, 15);
|
||||
|
||||
writer.writeCellValue(7, 1, "红绿灯状态");
|
||||
writer.setColumnWidth(7, 20);
|
||||
|
||||
writer.writeCellValue(8, 1, "出入场状态");
|
||||
writer.setColumnWidth(8, 20);
|
||||
|
||||
writer.writeCellValue(9, 1, "体检状态");
|
||||
writer.setColumnWidth(9, 20);
|
||||
|
||||
|
||||
|
||||
writer.merge(2, 2, 0, 9, "无数据", false);
|
||||
}
|
||||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");
|
||||
try {
|
||||
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8") + ".xlsx");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
ServletOutputStream out = null;
|
||||
try {
|
||||
out = response.getOutputStream();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
writer.flush(out, true);
|
||||
writer.close();
|
||||
IoUtil.close(out);
|
||||
}
|
||||
|
||||
private List<PersonComprehensiveBean> getBasePersonLists (Map < String, Object > params){
|
||||
List<PersonComprehensiveBean> list = new ArrayList<>();
|
||||
try {
|
||||
list = dao.getBasePersonLists(params);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ public class PersonSettingServiceImpl implements PersonSettingService {
|
|||
public R importData(MultipartFile file, String teamId, String subId) throws Exception {
|
||||
ExcelUtil<TeamPersonBean> util = new ExcelUtil<>(TeamPersonBean.class);
|
||||
//读取文件到list
|
||||
List<TeamPersonBean> list = util.importExcel(file.getInputStream(),0);
|
||||
List<TeamPersonBean> list = util.importExcelDoubleTitle(file.getInputStream(),0);
|
||||
//
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
list.forEach(i -> {
|
||||
|
|
|
|||
|
|
@ -24,10 +24,10 @@
|
|||
|
||||
<insert id="insertBasePersonBankData">
|
||||
replace into bm_worker_bank
|
||||
(`id_number`, `bank_card`, `bank_name`)
|
||||
(`id_number`, `bank_card`, `bank_name`,`bank_inter`)
|
||||
values
|
||||
<foreach item="params" collection="list" separator=",">
|
||||
(#{params.idNumber},#{params.bankCard},#{params.bankName})
|
||||
(#{params.idNumber},#{params.bankCard},#{params.bankName},#{params.bankInter})
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
|
|
@ -190,4 +190,4 @@
|
|||
select COUNT(1) from bm_worker_bank where id_number = #{idNumber} and is_active = '1'
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
</mapper>
|
||||
|
|
|
|||
|
|
@ -644,5 +644,53 @@
|
|||
GROUP BY bw.id_number
|
||||
</select>
|
||||
|
||||
<select id="getBasePersonLists" resultType="com.bonus.bmw.person.entity.PersonComprehensiveBean">
|
||||
select
|
||||
bw.name as name,bw.id_number as idNumber,bw.phone as phone,
|
||||
td.value as postName,bp.name as proName,
|
||||
CASE
|
||||
bw.employment_type
|
||||
WHEN '0' THEN
|
||||
'固定用工'
|
||||
WHEN '1' THEN
|
||||
'临时用工'
|
||||
WHEN '2' THEN
|
||||
'分包管理人员'
|
||||
END employmentType,
|
||||
CASE
|
||||
bw.light_status
|
||||
WHEN '0' THEN
|
||||
'红灯'
|
||||
WHEN '1' THEN
|
||||
'黄灯'
|
||||
WHEN '2' THEN
|
||||
'绿灯'
|
||||
END lightStatus,
|
||||
CASE
|
||||
bw.ein_status
|
||||
WHEN '0' THEN
|
||||
'未入场'
|
||||
WHEN '1' THEN
|
||||
'已入场'
|
||||
END exitStatus,
|
||||
bw.checkup_date as checkupDate,
|
||||
checkup.PHOTO_PATH as checkupFilePath,
|
||||
CASE
|
||||
WHEN STR_TO_DATE(bw.checkup_date, '%Y-%m-%d') < DATE_SUB(CURDATE(), INTERVAL 1 YEAR) THEN '过期'
|
||||
ELSE '有效'
|
||||
END AS checkupState
|
||||
from bm_worker bw
|
||||
LEFT JOIN t_dict td ON td.id = bw.post_id
|
||||
AND td.is_active = '1'
|
||||
LEFT JOIN bm_worker_ein_history bweh ON bweh.id_number = bw.id_number
|
||||
and bweh.is_active = '1'
|
||||
LEFT JOIN bm_project bp ON bp.id = bweh.project_id
|
||||
AND bp.is_active = '1'
|
||||
LEFT JOIN bm_worker_checkup checkup ON checkup.ID_NUMBER = bw.id_number
|
||||
AND checkup.IS_ACTIVE = '1'
|
||||
where bw.is_active='1'
|
||||
|
||||
</mapper>
|
||||
</select>
|
||||
|
||||
|
||||
</mapper>
|
||||
|
|
|
|||
|
|
@ -80,6 +80,7 @@
|
|||
href="../../../../downloads/农民工实名制导入模版.xlsx" download="农民工实名制导入模板.xlsx" style="margin-top:0.5%">
|
||||
<i class="layui-icon"></i> 农民工实名制模板下载
|
||||
</a>
|
||||
<button id="exportBt" onclick="exportPersonnelOnSite()" class="layui-btn layui-btn-sm" style="margin-top:0.5%"><i class="layui-icon"></i>导出</button>
|
||||
</div>
|
||||
</form>
|
||||
</td>
|
||||
|
|
|
|||
|
|
@ -485,4 +485,46 @@ function checkViewEn(idNumber) {
|
|||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//导出excel表格
|
||||
function exportPersonnelOnSite() {
|
||||
var name = $("#mame").val();
|
||||
var idNumber = $("#idNumber").val();
|
||||
var phone = $("#phone").val();
|
||||
var postName = $("#postName").val();
|
||||
var proName = $("#proName").val();
|
||||
var employmentType = $("#employmentType").val();
|
||||
var lightStatus = $("#lightStatus").val();
|
||||
var exitStatus = $("#exitStatus").val();
|
||||
var checkupState = $("#checkupState").val();
|
||||
|
||||
window.location.href = ctxPath + "/personComprehensive/exportBtnOut?token=" + token
|
||||
+ "&name=" + name
|
||||
+ "&idNumber=" + idNumber
|
||||
+ "&phone=" + phone
|
||||
+ "&postName=" + postName
|
||||
+ "&proName=" + proName
|
||||
+ "&employmentType=" + employmentType
|
||||
+ "&lightStatus=" + lightStatus
|
||||
+ "&exitStatus=" + exitStatus
|
||||
+ "&checkupState=" + checkupState;
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("get", url, true);
|
||||
xhr.responseType = "blob"; // 转换流
|
||||
xhr.onload = function () {
|
||||
layer.close(loadingMsg);
|
||||
if (this.status === 200) {
|
||||
var blob = this.response;
|
||||
var a = document.createElement("a");
|
||||
var url = window.URL.createObjectURL(blob);
|
||||
a.href = url;
|
||||
a.download = "入场人员信息.xlsx"; // 文件名
|
||||
}else {
|
||||
layer.msg('发生异常,请稍后重试', {icon: 16, scrollbar: false, time: 2000});
|
||||
}
|
||||
a.click()
|
||||
window.URL.revokeObjectURL(url)
|
||||
};
|
||||
xhr.send();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue