Commit 74c24277 authored by 王琮's avatar 王琮

修改员工导入

parent ff43a267
......@@ -219,11 +219,11 @@ public class SysUserController extends CyPaginationController<SysUser> {
@ApiOperation(value = "导入用户信息", notes = "导入用户信息")
@PostMapping("/importExcel")
@CyEptSm4EnableAnno
public CyResult importSysUser(MultipartFile file) {
public CyResult importSysUser(MultipartFile file,HttpServletResponse response) {
return CyResultGenUtil.builder(new CyPersistModel(1),
CyMessCons.MESSAGE_ALERT_SUCCESS,
CyMessCons.MESSAGE_ALERT_ERROR,
sysUserServiceImpl.importUserExcel(file));
sysUserServiceImpl.importUserExcel(file,response));
}
/**
......
package org.rcisoft.sys.sysuser.dto;
import cn.afterturn.easypoi.excel.annotation.Excel;
import lombok.Data;
@Data
public class UserErrorDTO extends ExportUserDTO{
@Excel(name = "错误提示", orderNum = "2", width = 40)
private String error;
}
......@@ -92,7 +92,7 @@ public interface SysUserService {
int exportEmptyTemplate(HttpServletResponse response);
ImportUserDTO importUserExcel(MultipartFile file);
ImportUserDTO importUserExcel(MultipartFile file,HttpServletResponse response);
/**
......
......@@ -6,6 +6,7 @@ import org.apache.commons.lang3.StringUtils;
import org.rcisoft.core.constant.CySysCons;
import org.rcisoft.core.exception.CyServiceException;
import org.rcisoft.sys.sysuser.dto.ExportUserDTO;
import org.rcisoft.sys.sysuser.dto.UserErrorDTO;
import org.rcisoft.sys.sysuser.entity.SysUser;
import org.rcisoft.sys.visit.dto.ExportVisitInfoDto;
import org.rcisoft.sys.visit.dto.ExportVisitUserDTO;
......@@ -35,27 +36,31 @@ public class CheckUtil {
* 对导入的用户信息进行非空校验
*
* @param sysUser 用户信息
* @param row 行数
* @return
*/
public static ErrorDTO userNotNull(ExportUserDTO sysUser, int row) {
ErrorDTO errorDTO = new ErrorDTO();
Map<Integer, List<String>> notTrues = new HashMap<>();
public static UserErrorDTO userNotNull(ExportUserDTO sysUser) {
UserErrorDTO errorDTO = new UserErrorDTO();
List<String> notTrue = new ArrayList<>();
errorDTO.setSuccess(0);
if (StringUtils.isEmpty(sysUser.getName())) {
if (StringUtils.isEmpty(sysUser.getName()))
notTrue.add("姓名不能为空");
}
if (StringUtils.isEmpty(sysUser.getPhone())) {
if (StringUtils.isEmpty(sysUser.getPhone()))
notTrue.add("手机号不能为空");
}
if (StringUtils.isEmpty(sysUser.getSex())) {
if (!sysUser.getPhone().matches("^1[3-9]\\d{9}$"))
notTrue.add("手机号格式不正确");
if (StringUtils.isEmpty(sysUser.getSex()))
notTrue.add("性别不能为空");
}
if (StringUtils.isEmpty(sysUser.getAddress()))
notTrue.add("所属园区不能为空");
if (StringUtils.isEmpty(sysUser.getDeptId()))
notTrue.add("所属部门不能为空");
if (StringUtils.isEmpty(sysUser.getPosition()))
notTrue.add("职位不能为空");
if (StringUtils.isEmpty(sysUser.getNltBz()))
notTrue.add("班次不能为空");
if (notTrue.size() > 0) {
errorDTO.setSuccess(1);
notTrues.put(row, notTrue);
errorDTO.setMap(notTrues);
BeanUtil.copyProperties(sysUser, errorDTO);
errorDTO.setError(notTrue.stream().collect(Collectors.joining(",")));
return errorDTO;
}
return errorDTO;
}
......
......@@ -90,7 +90,6 @@ public interface VisitPersonService {
int exportEmptyTemplate(HttpServletResponse response);
ImportUserDTO importUserExcel(MultipartFile file);
/**
......
......@@ -369,162 +369,6 @@ public class VisitPersonServiceImpl extends ServiceImpl<VisitPersonRepositorys,
importUserDTO.setFilename(fileName);
}
@Override
@Transactional
public ImportUserDTO importUserExcel(MultipartFile file) {
ImportUserDTO importUserDTO = new ImportUserDTO();
Calendar calendar = Calendar.getInstance();
String nowTime = new SimpleDateFormat("yyyyMMddHHmmss").format(calendar.getTime());
String fileName = "用户错误信息" + nowTime + ".txt";
List<Map<Integer, List<String>>> maps = new ArrayList<>();
ExportUserDTO exportUserDTO = new ExportUserDTO();
boolean flag = false;
try {
flag = CyEpExcelUtil.isFileInUser(file, exportUserDTO, 2);
} catch (Exception e) {
throw new CyServiceException(CyResSvcExcEnum.ERROR_NETWORK);
}
if (!flag || !CyCompareToolUtils.compareFileName(file, "用户信息", 0, 0)) {
String errorBefore = "上传模板错误请重新下载!";
errorText(errorBefore, importUserDTO, maps, fileName);
try {
errorTxt.exportTxtPaper(maps, fileName);
} catch (Exception e) {
throw new CyServiceException(CyResSvcExcEnum.ERROR_NETWORK);
}
return importUserDTO;
}
/** 从excel表中读到数据,有一部分为空值 */
List<ExportUserDTO> sysUserList = CyEpExcelUtil.importExcel(file, 2, 1, ExportUserDTO.class);
/** 遍历 从Excel表中读到的数据 抛出不合适的数据 */
//判断整个Excel是不是为空 计算非空数据有多少条
int information = CyCompareToolUtils.cmpareInformation(sysUserList);
if (information == 0) {
String errorBefore = "Excel文件不可为空,请检查Excel文件是否填写!";
errorText(errorBefore, importUserDTO, maps, fileName);
try {
errorTxt.exportTxtPaper(maps, fileName);
} catch (Exception e) {
throw new CyServiceException(CyResSvcExcEnum.ERROR_NETWORK);
}
return importUserDTO;
} else if (information > 500) {
String errorMore = "单次导入数据不可超过500,请检查!";
errorText(errorMore, importUserDTO, maps, fileName);
try {
errorTxt.exportTxtPaper(maps, fileName);
} catch (Exception e) {
throw new CyServiceException(CyResSvcExcEnum.ERROR_NETWORK);
}
return importUserDTO;
} else {
//去除空数据
try {
sysUserList = ThrowNull(sysUserList);
} catch (Exception e) {
throw new CyServiceException(CyResSvcExcEnum.ERROR_NETWORK);
}
//校验 将错误信息放入maps
int index = 3; //从第3行开始
SysUser sysUserDTO = new SysUser();
sysUserDTO.setDeleted();
List<SysUser> sysUsers = sysUserRepositorys.querySysUsers(sysUserDTO);
for (ExportUserDTO sysUser : sysUserList) {
//判断 是否为空
ErrorDTO userNull = CheckUtil.userNotNull(sysUser, index);
if (userNull.getSuccess() == 1) {
maps.add(userNull.getMap());
}
//判断 信息是否重复
ErrorDTO userRepeat = CheckUtil.userRepeat(sysUser, index, sysUsers);
if (userRepeat.getSuccess() == 1) {
maps.add(userRepeat.getMap());
}
index++;
}
}
/** 将 信息插入sys_user */
if (sysUserList.size() > 0) {
//用户性别数据字典
List<DictData> userSex = dictionaryService.selectByTypes(CyDictCons.USER_SEX);
for (ExportUserDTO sysUser : sysUserList) {
sysUser.setIdentity("0");
//数据库需要插入的用户信息
//登录名
if (sysUser.getUsername() == null) {
throw new CyServiceException(500, "数据错误");
}
//手机号
if (sysUser.getPhone() == null) {
throw new CyServiceException(500, "数据错误");
}
//人脸信息
if (sysUser.getFaceAddress() == null) {
throw new CyServiceException(500, "数据错误");
}
//所属园区
if (sysUser.getAddress() == null) {
throw new CyServiceException(500, "数据错误");
}
//性别
if (sysUser.getSex() != null) {
if (sysUser.getSex().equals("男")) {
sysUser.setSex("0");
} else if (sysUser.getSex().equals("女")) {
sysUser.setSex("1");
} else {
throw new CyServiceException(500, "数据错误");
}
} else {
throw new CyServiceException(500, "数据错误");
}
//所属部门
SysDept sysDept = sysDeptRepositorys.querySysDeptByName(sysUser.getDeptId());
if (sysDept == null || sysDept.equals(' ')) {
throw new CyServiceException(500, "数据错误");
} else {
sysUser.setDeptId(sysDept.getBusinessId().toString());
}
//字典职位
SysDictData sysDictData1 = sysDictDataRepositorys.queryDataByDeptIdC(sysUser.getPosition());
if (sysDictData1 == null || sysDictData1.equals(' ')) {
throw new CyServiceException(500, "数据错误");
} else {
sysUser.setPosition(sysDictData1.getBusinessId().toString());
}
//字典班次
SysDictData sysDictData2 = sysDictDataRepositorys.queryDataByDeptIdC(sysUser.getNltBz());
if (sysDictData2 == null || sysDictData2.equals(' ')) {
throw new CyServiceException(500, "数据错误");
} else {
sysUser.setNltBz(sysDictData2.getBusinessId().toString());
}
//工作状态
if (sysUser.getFlag() != null) {
if (sysUser.getFlag().equals("停用")) {
sysUser.setFlag("0");
} else if (sysUser.getFlag().equals("正常") || sysUser.getFlag().equals("在职")) {
sysUser.setFlag("1");
} else if (sysUser.getFlag().equals("离职")) {
sysUser.setFlag("2");
} else {
throw new CyServiceException(500, "数据错误");
}
} else {
throw new CyServiceException(500, "数据错误");
}
//用户类型
sysUser.setUserType("0");
//身份
sysUser.setIdentity("1");
sysUserRepositorys.addSysUser(sysUser);
}
}
return importUserDTO;
}
/**
* @param persionId
* @param userId
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment