style: 三标通用导入(常规字段导入)-代码优化
This commit is contained in:
+4
-262
@@ -10,10 +10,9 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.jero.common.constant.enums.LanguageEnum;
|
||||
import com.jero.common.constant.enums.YesOrNoEnum;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.common.system.api.ISysBaseAPI;
|
||||
import com.jero.common.system.vo.DictModel;
|
||||
import com.jero.common.system.vo.LoginUser;
|
||||
import com.jero.common.util.MessageUtils;
|
||||
import com.jero.modules.laws.common.util.ImportUtil;
|
||||
import com.jero.modules.laws.common.constant.FieldCommon;
|
||||
import com.jero.modules.laws.common.constant.ResultCommon;
|
||||
import com.jero.modules.laws.common.mapper.LawsCommonMapper;
|
||||
@@ -44,7 +43,6 @@ import com.jero.modules.tag.enums.LawsFieldTypeEnum;
|
||||
import com.jero.modules.tag.service.ILawsAreaService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
@@ -61,7 +59,6 @@ import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.*;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.text.SimpleDateFormat;
|
||||
@@ -112,9 +109,7 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
|
||||
@Resource
|
||||
private EnterpriseStandardUtil esUtil;
|
||||
@Resource
|
||||
private ISysBaseAPI sysBaseAPI;
|
||||
@Resource
|
||||
private ISysDictItemService dictItemService;
|
||||
private ImportUtil importUtil;
|
||||
// 自我注入
|
||||
@Autowired
|
||||
private ILawsCommonService commonService;
|
||||
@@ -1440,126 +1435,12 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
|
||||
for (int i = 3; i < sheet.getPhysicalNumberOfRows(); i++) {
|
||||
Map<String, Object> parameterMap = new HashMap<>();
|
||||
for (int j = 0; j < sheet.getRow(i).getPhysicalNumberOfCells(); j++) {
|
||||
boolean errorFlag = false;
|
||||
// 获取当前单元格
|
||||
Cell cell = sheet.getRow(i).getCell(j);
|
||||
|
||||
// 获取当前单元格内容对应的字段
|
||||
LawsTag tag = headerList.get(j);
|
||||
|
||||
// 按照标签要求的格式验证
|
||||
// 必填验证
|
||||
if (YesOrNoEnum.YES.getValue().equals(tag.getFieldMustInput())) {
|
||||
if (!this.mustInputValid(cell)) {
|
||||
errMsgList.add("第" + (i) + "行第" + (j + 1) + "列为必填");
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// 获取当前单元格内容
|
||||
if (cell == null) {
|
||||
continue;
|
||||
}
|
||||
// 单选时间
|
||||
String cellValue = cell.toString();
|
||||
if (FieldShowTypeEnum.SINGLE_DATE_PICKER.getValue().equals(tag.getFieldShowType())) {
|
||||
Date date = cell.getDateCellValue();
|
||||
// 创建一个SimpleDateFormat对象,并指定所需的格式
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
// 使用SimpleDateFormat对象的format方法将Date对象转换为字符串
|
||||
cellValue = sdf.format(date);
|
||||
}
|
||||
// TODO 多选时间
|
||||
|
||||
// 字段长度校验
|
||||
if (FieldShowTypeEnum.TEXT_BOX.getValue().equals(tag.getFieldShowType())) {
|
||||
if (cellValue.length() > 50) {
|
||||
errMsgList.add("第" + (i + 1) + "行第" + (j + 1) + "列字段超过50字");
|
||||
errorFlag = true;
|
||||
}
|
||||
}
|
||||
if (FieldShowTypeEnum.MULTI_TEXT.getValue().equals(tag.getFieldShowType())) {
|
||||
if (cellValue.length() > 500) {
|
||||
errMsgList.add("第" + (i + 1) + "行第" + (j + 1) + "列字段超过500字");
|
||||
errorFlag = true;
|
||||
}
|
||||
}
|
||||
|
||||
// 下拉单选
|
||||
if (FieldShowTypeEnum.DROPDOWN_SINGLE_SELECT.getValue().equals(tag.getFieldShowType()) ||
|
||||
FieldShowTypeEnum.DROPDOWN_MULTI_SELECT.getValue().equals(tag.getFieldShowType())) {
|
||||
if (!this.dictValid(tag.getDictField(), cellValue)) {
|
||||
errMsgList.add("第" + (i + 1) + "行第" + (j + 1) + "列选项填写错误");
|
||||
errorFlag = true;
|
||||
} else {
|
||||
// 转为value
|
||||
cellValue = this.convertDictValue(tag.getDictField(), cellValue);
|
||||
}
|
||||
}
|
||||
// 单选组织机构
|
||||
if (FieldShowTypeEnum.SINGLE_ORGANIZATION_DIALOG.getValue().equals(tag.getFieldShowType())) {
|
||||
if (!this.singleOrgValid(cellValue)) {
|
||||
errMsgList.add("第" + (i + 1) + "行第" + (j + 1) + "列填写错误");
|
||||
errorFlag = true;
|
||||
} else {
|
||||
// 转为id
|
||||
cellValue = this.convertSingleOrgId(cellValue);
|
||||
}
|
||||
}
|
||||
// 单选人员
|
||||
if (FieldShowTypeEnum.SINGLE_USER_DIALOG.getValue().equals(tag.getFieldShowType())) {
|
||||
if (!this.singleUserValid(cellValue)) {
|
||||
errMsgList.add("第" + (i + 1) + "行第" + (j + 1) + "列填写错误");
|
||||
errorFlag = true;
|
||||
} else {
|
||||
// 转为id
|
||||
cellValue = this.convertSingleUserId(cellValue);
|
||||
}
|
||||
}
|
||||
// 多选组织机构
|
||||
if (FieldShowTypeEnum.MULTI_ORGANIZATION_DIALOG.getValue().equals(tag.getFieldShowType())) {
|
||||
if (!this.multiOrgValid(cellValue)) {
|
||||
errMsgList.add("第" + (i + 1) + "行第" + (j + 1) + "列填写错误");
|
||||
errorFlag = true;
|
||||
} else {
|
||||
// 转为id
|
||||
cellValue = this.convertMultiOrgId(cellValue);
|
||||
}
|
||||
}
|
||||
// 零部件
|
||||
if (tag.getDbFieldName().equals("part_name") && StrUtil.isNotBlank(cellValue)) {
|
||||
if (!this.partValid(cellValue)) {
|
||||
errMsgList.add("第" + (i + 1) + "行第" + (j + 1) + "列填写错误");
|
||||
errorFlag = true;
|
||||
} else {
|
||||
// 转为id
|
||||
cellValue = this.convertPartId(cellValue);
|
||||
}
|
||||
}
|
||||
// 多选组织机构
|
||||
if (FieldShowTypeEnum.MULTI_ORGANIZATION_DIALOG.getValue().equals(tag.getFieldShowType())) {
|
||||
if (!this.multiOrgValid(cellValue)) {
|
||||
errMsgList.add("第" + (i + 1) + "行第" + (j + 1) + "列填写错误");
|
||||
errorFlag = true;
|
||||
} else {
|
||||
// 转为id
|
||||
cellValue = this.convertMultiOrgId(cellValue);
|
||||
}
|
||||
}
|
||||
// 体系
|
||||
if (FieldCommon.STANDARD_SYSTEM.equals(tag.getDbFieldName())) {
|
||||
if (!this.standardSystemValid(cellValue)) {
|
||||
errMsgList.add("第" + (i + 1) + "行第" + (j + 1) + "列填写错误");
|
||||
errorFlag = true;
|
||||
} else {
|
||||
// 转为id
|
||||
cellValue = this.convertStandardSystem(cellValue);
|
||||
}
|
||||
}
|
||||
if (!errorFlag) {
|
||||
// 如果数据通过了校验则将数据按照格式加入Map
|
||||
// 如果是企标稽查内容,则需要将整个Excel文档序列化成JSON 然后走新增逻辑
|
||||
parameterMap.put(tag.getDbFieldName(), cellValue);
|
||||
}
|
||||
// 调用导入工具类的校验方法
|
||||
errMsgList.addAll(importUtil.allColumnValid(cell, tag, i, j, parameterMap));
|
||||
}
|
||||
insertDataList.add(parameterMap);
|
||||
}
|
||||
@@ -1569,145 +1450,6 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
|
||||
}
|
||||
}
|
||||
|
||||
private String convertStandardSystem(String cellValue) {
|
||||
List<String> valueList = Arrays.asList(cellValue.split(","));
|
||||
LambdaQueryWrapper<LawsTreeNode> treeNodeLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
treeNodeLambdaQueryWrapper.in(LawsTreeNode::getNodeName, valueList);
|
||||
List<LawsTreeNode> treeNodeList = lawsTreeNodeService.list(treeNodeLambdaQueryWrapper);
|
||||
Map<String, String> systemMap = treeNodeList.stream().collect(Collectors.toMap(LawsTreeNode::getNodeName, LawsTreeNode::getId));
|
||||
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (String value : valueList) {
|
||||
result.append(systemMap.get(value)).append(",");
|
||||
}
|
||||
// 去除掉最后的逗号
|
||||
return result.substring(0, result.length() - 1);
|
||||
}
|
||||
|
||||
private String convertSingleUserId(String cellValue) {
|
||||
LambdaQueryWrapper<SysUser> sysUserLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
sysUserLambdaQueryWrapper.eq(SysUser::getNameWorkNo, cellValue);
|
||||
return sysUserService.getOne(sysUserLambdaQueryWrapper).getId();
|
||||
}
|
||||
|
||||
private String convertPartId(String cellValue) {
|
||||
String[] valueList = cellValue.split(",");
|
||||
Map<String, DictModel> sexDictModelMap =
|
||||
sysBaseAPI.getDictItems("Part Name").stream()
|
||||
.collect(Collectors.toMap(DictModel::getText, d -> d));
|
||||
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (String value : valueList) {
|
||||
result.append(sexDictModelMap.get(value).getValue()).append(",");
|
||||
}
|
||||
// 去除掉最后的逗号
|
||||
return result.substring(0, result.length() - 1);
|
||||
}
|
||||
|
||||
private String convertMultiOrgId(String cellValue) {
|
||||
List<String> valueList = Arrays.asList(cellValue.split(","));
|
||||
LambdaQueryWrapper<SysDepart> sysDepartLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
sysDepartLambdaQueryWrapper.in(SysDepart::getDepartName, valueList);
|
||||
List<SysDepart> deptList = sysDepartService.list(sysDepartLambdaQueryWrapper);
|
||||
Map<String, String> deptMap = deptList.stream().collect(Collectors.toMap(SysDepart::getDepartName, SysDepart::getId));
|
||||
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (String value : valueList) {
|
||||
result.append(deptMap.get(value)).append(",");
|
||||
}
|
||||
// 去除掉最后的逗号
|
||||
return result.substring(0, result.length() - 1);
|
||||
}
|
||||
|
||||
private String convertSingleOrgId(String cellValue) {
|
||||
LambdaQueryWrapper<SysDepart> sysDepartLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
sysDepartLambdaQueryWrapper.eq(SysDepart::getDepartName, cellValue);
|
||||
return sysDepartService.getOne(sysDepartLambdaQueryWrapper).getId();
|
||||
}
|
||||
|
||||
private String convertDictValue(String dictCode, String cellValue) {
|
||||
String[] valueList = cellValue.split(",");
|
||||
Map<String, DictModel> sexDictModelMap =
|
||||
sysBaseAPI.getDictItems(dictCode).stream()
|
||||
.collect(Collectors.toMap(DictModel::getText, d -> d));
|
||||
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (String value : valueList) {
|
||||
result.append(sexDictModelMap.get(value).getValue()).append(",");
|
||||
}
|
||||
// 去除掉最后的逗号
|
||||
return result.substring(0, result.length() - 1);
|
||||
}
|
||||
|
||||
// 必填校验
|
||||
private boolean mustInputValid(Cell cell) {
|
||||
if (cell == null) {
|
||||
return false;
|
||||
}
|
||||
String cellValue = cell.toString();
|
||||
return StrUtil.isNotBlank(cellValue);
|
||||
}
|
||||
// 字典验证(判断填写的是否是选项中的一个)
|
||||
private boolean dictValid(String dictCode, String cellValue) {
|
||||
String[] valueList = cellValue.split(",");
|
||||
Map<String, DictModel> sexDictModelMap =
|
||||
sysBaseAPI.getDictItems(dictCode).stream()
|
||||
.collect(Collectors.toMap(DictModel::getText, d -> d));
|
||||
|
||||
for (String value : valueList) {
|
||||
if (sexDictModelMap.get(value) == null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// 单选组织机构
|
||||
private boolean singleOrgValid(String cellValue) {
|
||||
LambdaQueryWrapper<SysDepart> sysDepartLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
sysDepartLambdaQueryWrapper.eq(SysDepart::getDepartName, cellValue);
|
||||
return Objects.nonNull(sysDepartService.getOne(sysDepartLambdaQueryWrapper));
|
||||
}
|
||||
// 单选人员
|
||||
private boolean singleUserValid(String cellValue) {
|
||||
LambdaQueryWrapper<SysUser> sysUserLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
sysUserLambdaQueryWrapper.eq(SysUser::getNameWorkNo, cellValue);
|
||||
return Objects.nonNull(sysUserService.getOne(sysUserLambdaQueryWrapper));
|
||||
}
|
||||
// 多选组织机构
|
||||
private boolean multiOrgValid(String cellValue) {
|
||||
List<String> valueList = Arrays.asList(cellValue.split(","));
|
||||
LambdaQueryWrapper<SysDepart> sysDepartLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
sysDepartLambdaQueryWrapper.in(SysDepart::getDepartName, valueList);
|
||||
List<SysDepart> list = sysDepartService.list(sysDepartLambdaQueryWrapper);
|
||||
return valueList.size() == list.size();
|
||||
}
|
||||
// 零部件
|
||||
private boolean partValid(String cellValue) {
|
||||
String[] valueList = cellValue.split(",");
|
||||
List<DictModel> educationDictModelList = sysBaseAPI.getDictItems("Part Name");
|
||||
Map<String, DictModel> sexDictModelMap = educationDictModelList.stream()
|
||||
.collect(Collectors.toMap(DictModel::getText, d -> d));
|
||||
for (String value : valueList) {
|
||||
if (sexDictModelMap.get(value) == null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private boolean standardSystemValid(String cellValue) {
|
||||
List<String> valueList = Arrays.asList(cellValue.split(","));
|
||||
LambdaQueryWrapper<LawsTreeNode> treeNodeLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
treeNodeLambdaQueryWrapper.in(LawsTreeNode::getNodeName, valueList);
|
||||
List<LawsTreeNode> treeNodeList = lawsTreeNodeService.list(treeNodeLambdaQueryWrapper);
|
||||
Map<String, String> systemMap = treeNodeList.stream().collect(Collectors.toMap(LawsTreeNode::getNodeName, LawsTreeNode::getId));
|
||||
for (String value : valueList) {
|
||||
if (systemMap.get(value) == null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置导入模板的第三行提示内容
|
||||
* @param row3
|
||||
|
||||
@@ -0,0 +1,301 @@
|
||||
package com.jero.modules.laws.common.util;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.jero.common.constant.enums.YesOrNoEnum;
|
||||
import com.jero.common.system.api.ISysBaseAPI;
|
||||
import com.jero.common.system.vo.DictModel;
|
||||
import com.jero.modules.laws.common.constant.FieldCommon;
|
||||
import com.jero.modules.laws.standard.entity.LawsTreeNode;
|
||||
import com.jero.modules.laws.standard.service.ILawsTreeNodeService;
|
||||
import com.jero.modules.system.entity.SysDepart;
|
||||
import com.jero.modules.system.entity.SysUser;
|
||||
import com.jero.modules.system.service.ISysDepartService;
|
||||
import com.jero.modules.system.service.ISysUserService;
|
||||
import com.jero.modules.tag.entity.LawsTag;
|
||||
import com.jero.modules.tag.enums.FieldShowTypeEnum;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author: Mzaxd
|
||||
* @Date: 2023/9/26 17:31
|
||||
*/
|
||||
@Component
|
||||
public class ImportUtil {
|
||||
|
||||
@Resource
|
||||
private ILawsTreeNodeService lawsTreeNodeService;
|
||||
|
||||
@Resource
|
||||
private ISysUserService sysUserService;
|
||||
|
||||
@Resource
|
||||
private ISysBaseAPI sysBaseAPI;
|
||||
|
||||
@Resource
|
||||
private ISysDepartService sysDepartService;
|
||||
|
||||
public List<String> allColumnValid(Cell cell, LawsTag tag, int i, int j, Map<String, Object> parameterMap) {
|
||||
List<String> errMsgList = new ArrayList<>();
|
||||
// 必填验证
|
||||
if (YesOrNoEnum.YES.getValue().equals(tag.getFieldMustInput())) {
|
||||
if (!this.mustInputValid(cell)) {
|
||||
errMsgList.add("第" + (i) + "行第" + (j + 1) + "列为必填");
|
||||
return errMsgList;
|
||||
}
|
||||
}
|
||||
// 获取当前单元格内容
|
||||
if (cell == null) {
|
||||
return errMsgList;
|
||||
}
|
||||
// 单选时间
|
||||
String cellValue = cell.toString();
|
||||
if (FieldShowTypeEnum.SINGLE_DATE_PICKER.getValue().equals(tag.getFieldShowType())) {
|
||||
Date date = cell.getDateCellValue();
|
||||
// 创建一个SimpleDateFormat对象,并指定所需的格式
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
// 使用SimpleDateFormat对象的format方法将Date对象转换为字符串
|
||||
cellValue = sdf.format(date);
|
||||
}
|
||||
// 字段长度校验
|
||||
if (FieldShowTypeEnum.TEXT_BOX.getValue().equals(tag.getFieldShowType())) {
|
||||
if (cellValue.length() > 50) {
|
||||
errMsgList.add("第" + (i + 1) + "行第" + (j + 1) + "列字段超过50字");
|
||||
}
|
||||
}
|
||||
if (FieldShowTypeEnum.MULTI_TEXT.getValue().equals(tag.getFieldShowType())) {
|
||||
if (cellValue.length() > 500) {
|
||||
errMsgList.add("第" + (i + 1) + "行第" + (j + 1) + "列字段超过500字");
|
||||
}
|
||||
}
|
||||
|
||||
// 下拉单选
|
||||
if (FieldShowTypeEnum.DROPDOWN_SINGLE_SELECT.getValue().equals(tag.getFieldShowType()) ||
|
||||
FieldShowTypeEnum.DROPDOWN_MULTI_SELECT.getValue().equals(tag.getFieldShowType())) {
|
||||
if (!this.dictValid(tag.getDictField(), cellValue)) {
|
||||
errMsgList.add("第" + (i + 1) + "行第" + (j + 1) + "列选项填写错误");
|
||||
} else {
|
||||
// 转为value
|
||||
cellValue = this.convertDictValue(tag.getDictField(), cellValue);
|
||||
}
|
||||
}
|
||||
// 单选组织机构
|
||||
if (FieldShowTypeEnum.SINGLE_ORGANIZATION_DIALOG.getValue().equals(tag.getFieldShowType())) {
|
||||
if (!this.singleOrgValid(cellValue)) {
|
||||
errMsgList.add("第" + (i + 1) + "行第" + (j + 1) + "列填写错误");
|
||||
} else {
|
||||
// 转为id
|
||||
cellValue = this.convertSingleOrgId(cellValue);
|
||||
}
|
||||
}
|
||||
// 单选人员
|
||||
if (FieldShowTypeEnum.SINGLE_USER_DIALOG.getValue().equals(tag.getFieldShowType())) {
|
||||
if (!this.singleUserValid(cellValue)) {
|
||||
errMsgList.add("第" + (i + 1) + "行第" + (j + 1) + "列填写错误");
|
||||
} else {
|
||||
// 转为id
|
||||
cellValue = this.convertSingleUserId(cellValue);
|
||||
}
|
||||
}
|
||||
// 多选组织机构
|
||||
if (FieldShowTypeEnum.MULTI_ORGANIZATION_DIALOG.getValue().equals(tag.getFieldShowType())) {
|
||||
if (!this.multiOrgValid(cellValue)) {
|
||||
errMsgList.add("第" + (i + 1) + "行第" + (j + 1) + "列填写错误");
|
||||
} else {
|
||||
// 转为id
|
||||
cellValue = this.convertMultiOrgId(cellValue);
|
||||
}
|
||||
}
|
||||
// 零部件
|
||||
if (tag.getDbFieldName().equals("part_name") && StrUtil.isNotBlank(cellValue)) {
|
||||
if (!this.partValid(cellValue)) {
|
||||
errMsgList.add("第" + (i + 1) + "行第" + (j + 1) + "列填写错误");
|
||||
} else {
|
||||
// 转为id
|
||||
cellValue = this.convertPartId(cellValue);
|
||||
}
|
||||
}
|
||||
// 多选组织机构
|
||||
if (FieldShowTypeEnum.MULTI_ORGANIZATION_DIALOG.getValue().equals(tag.getFieldShowType())) {
|
||||
if (!this.multiOrgValid(cellValue)) {
|
||||
errMsgList.add("第" + (i + 1) + "行第" + (j + 1) + "列填写错误");
|
||||
} else {
|
||||
// 转为id
|
||||
cellValue = this.convertMultiOrgId(cellValue);
|
||||
}
|
||||
}
|
||||
// 体系
|
||||
if (FieldCommon.STANDARD_SYSTEM.equals(tag.getDbFieldName())) {
|
||||
if (!this.standardSystemValid(cellValue)) {
|
||||
errMsgList.add("第" + (i + 1) + "行第" + (j + 1) + "列填写错误");
|
||||
} else {
|
||||
// 转为id
|
||||
cellValue = this.convertStandardSystem(cellValue);
|
||||
}
|
||||
}
|
||||
// TODO 多选时间
|
||||
// 将转好的值加入Map
|
||||
parameterMap.put(tag.getDbFieldName(), cellValue);
|
||||
return errMsgList;
|
||||
}
|
||||
|
||||
|
||||
// 体系转换
|
||||
public String convertStandardSystem(String cellValue) {
|
||||
List<String> valueList = Arrays.asList(cellValue.split(","));
|
||||
LambdaQueryWrapper<LawsTreeNode> treeNodeLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
treeNodeLambdaQueryWrapper.in(LawsTreeNode::getNodeName, valueList);
|
||||
List<LawsTreeNode> treeNodeList = lawsTreeNodeService.list(treeNodeLambdaQueryWrapper);
|
||||
Map<String, String> systemMap = treeNodeList.stream().collect(Collectors.toMap(LawsTreeNode::getNodeName, LawsTreeNode::getId));
|
||||
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (String value : valueList) {
|
||||
result.append(systemMap.get(value)).append(",");
|
||||
}
|
||||
// 去除掉最后的逗号
|
||||
return result.substring(0, result.length() - 1);
|
||||
}
|
||||
|
||||
// 单选用户转换
|
||||
public String convertSingleUserId(String cellValue) {
|
||||
LambdaQueryWrapper<SysUser> sysUserLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
sysUserLambdaQueryWrapper.eq(SysUser::getNameWorkNo, cellValue);
|
||||
return sysUserService.getOne(sysUserLambdaQueryWrapper).getId();
|
||||
}
|
||||
|
||||
// 零部件转换
|
||||
public String convertPartId(String cellValue) {
|
||||
String[] valueList = cellValue.split(",");
|
||||
Map<String, DictModel> sexDictModelMap =
|
||||
sysBaseAPI.getDictItems("Part Name").stream()
|
||||
.collect(Collectors.toMap(DictModel::getText, d -> d));
|
||||
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (String value : valueList) {
|
||||
result.append(sexDictModelMap.get(value).getValue()).append(",");
|
||||
}
|
||||
// 去除掉最后的逗号
|
||||
return result.substring(0, result.length() - 1);
|
||||
}
|
||||
|
||||
// 多选部门转换
|
||||
public String convertMultiOrgId(String cellValue) {
|
||||
List<String> valueList = Arrays.asList(cellValue.split(","));
|
||||
LambdaQueryWrapper<SysDepart> sysDepartLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
sysDepartLambdaQueryWrapper.in(SysDepart::getDepartName, valueList);
|
||||
List<SysDepart> deptList = sysDepartService.list(sysDepartLambdaQueryWrapper);
|
||||
Map<String, String> deptMap = deptList.stream().collect(Collectors.toMap(SysDepart::getDepartName, SysDepart::getId));
|
||||
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (String value : valueList) {
|
||||
result.append(deptMap.get(value)).append(",");
|
||||
}
|
||||
// 去除掉最后的逗号
|
||||
return result.substring(0, result.length() - 1);
|
||||
}
|
||||
|
||||
// 单选部门转换
|
||||
public String convertSingleOrgId(String cellValue) {
|
||||
LambdaQueryWrapper<SysDepart> sysDepartLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
sysDepartLambdaQueryWrapper.eq(SysDepart::getDepartName, cellValue);
|
||||
return sysDepartService.getOne(sysDepartLambdaQueryWrapper).getId();
|
||||
}
|
||||
|
||||
// 字典转换
|
||||
public String convertDictValue(String dictCode, String cellValue) {
|
||||
String[] valueList = cellValue.split(",");
|
||||
Map<String, DictModel> sexDictModelMap =
|
||||
sysBaseAPI.getDictItems(dictCode).stream()
|
||||
.collect(Collectors.toMap(DictModel::getText, d -> d));
|
||||
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (String value : valueList) {
|
||||
result.append(sexDictModelMap.get(value).getValue()).append(",");
|
||||
}
|
||||
// 去除掉最后的逗号
|
||||
return result.substring(0, result.length() - 1);
|
||||
}
|
||||
|
||||
// 必填校验
|
||||
public boolean mustInputValid(Cell cell) {
|
||||
if (cell == null) {
|
||||
return false;
|
||||
}
|
||||
String cellValue = cell.toString();
|
||||
return StrUtil.isNotBlank(cellValue);
|
||||
}
|
||||
|
||||
// 字典验证(判断填写的是否是选项中的一个)
|
||||
public boolean dictValid(String dictCode, String cellValue) {
|
||||
String[] valueList = cellValue.split(",");
|
||||
Map<String, DictModel> sexDictModelMap =
|
||||
sysBaseAPI.getDictItems(dictCode).stream()
|
||||
.collect(Collectors.toMap(DictModel::getText, d -> d));
|
||||
|
||||
for (String value : valueList) {
|
||||
if (sexDictModelMap.get(value) == null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// 单选组织机构
|
||||
public boolean singleOrgValid(String cellValue) {
|
||||
LambdaQueryWrapper<SysDepart> sysDepartLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
sysDepartLambdaQueryWrapper.eq(SysDepart::getDepartName, cellValue);
|
||||
return Objects.nonNull(sysDepartService.getOne(sysDepartLambdaQueryWrapper));
|
||||
}
|
||||
|
||||
// 单选人员
|
||||
public boolean singleUserValid(String cellValue) {
|
||||
LambdaQueryWrapper<SysUser> sysUserLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
sysUserLambdaQueryWrapper.eq(SysUser::getNameWorkNo, cellValue);
|
||||
return Objects.nonNull(sysUserService.getOne(sysUserLambdaQueryWrapper));
|
||||
}
|
||||
|
||||
// 多选组织机构
|
||||
public boolean multiOrgValid(String cellValue) {
|
||||
List<String> valueList = Arrays.asList(cellValue.split(","));
|
||||
LambdaQueryWrapper<SysDepart> sysDepartLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
sysDepartLambdaQueryWrapper.in(SysDepart::getDepartName, valueList);
|
||||
List<SysDepart> list = sysDepartService.list(sysDepartLambdaQueryWrapper);
|
||||
return valueList.size() == list.size();
|
||||
}
|
||||
|
||||
// 零部件
|
||||
public boolean partValid(String cellValue) {
|
||||
String[] valueList = cellValue.split(",");
|
||||
List<DictModel> educationDictModelList = sysBaseAPI.getDictItems("Part Name");
|
||||
Map<String, DictModel> sexDictModelMap = educationDictModelList.stream()
|
||||
.collect(Collectors.toMap(DictModel::getText, d -> d));
|
||||
for (String value : valueList) {
|
||||
if (sexDictModelMap.get(value) == null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// 体系校验
|
||||
public boolean standardSystemValid(String cellValue) {
|
||||
List<String> valueList = Arrays.asList(cellValue.split(","));
|
||||
LambdaQueryWrapper<LawsTreeNode> treeNodeLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
treeNodeLambdaQueryWrapper.in(LawsTreeNode::getNodeName, valueList);
|
||||
List<LawsTreeNode> treeNodeList = lawsTreeNodeService.list(treeNodeLambdaQueryWrapper);
|
||||
Map<String, String> systemMap = treeNodeList.stream().collect(Collectors.toMap(LawsTreeNode::getNodeName, LawsTreeNode::getId));
|
||||
for (String value : valueList) {
|
||||
if (systemMap.get(value) == null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user