Commit fbbf2c8d authored by 刘林's avatar 刘林

Merge remote-tracking branch 'origin/develop_tzs_register' into develop_tzs_register

parents 911a3a0e e774410e
package com.yeejoin.amos.boot.module.tcm.api.converter;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import java.util.HashMap;
import java.util.Map;
public class TestLevelConverter implements Converter<String> {
private static final Map<String,String> CODE_MAP = new HashMap<>();
static {
CODE_MAP.put("Ⅰ级(初级)","RYJB_JC");
CODE_MAP.put("Ⅱ级(中级)","RYJB_JC");
CODE_MAP.put("Ⅲ级(高级)","RYJB_JC");
}
@Override
public Class supportJavaTypeKey() {
return String.class;
}
@Override
public CellDataTypeEnum supportExcelTypeKey() {
return CellDataTypeEnum.STRING;
}
@Override
public String convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
String cellDataStr = cellData.getStringValue();
return CODE_MAP.get(cellDataStr);
}
@Override
public CellData convertToExcelData(String value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
return null;
}
}
package com.yeejoin.amos.boot.module.tcm.api.converter;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.CellData;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import java.util.HashMap;
import java.util.Map;
public class TestProjectConverter implements Converter<String> {
private static final Map<String,String> CODE_MAP = new HashMap<>();
static {
CODE_MAP.put("声发射检测","ZZXM_III");
CODE_MAP.put("涡流检测","ZZXM_III");
CODE_MAP.put("渗透检测","ZZXM_III");
CODE_MAP.put("磁粉检测","ZZXM_III");
CODE_MAP.put("脉冲反射法超声检测","ZZXM_III");
CODE_MAP.put("射线数字成像检测","ZZXM_II");
CODE_MAP.put("脉冲反射法超声检测(自动)","ZZXM_II");
CODE_MAP.put("衍射时差法超声检测","ZZXM_II");
CODE_MAP.put("相控阵超声检测","ZZXM_II");
CODE_MAP.put("涡流检测(自动)","ZZXM_II");
CODE_MAP.put("漏磁检测(自动)","ZZXM_II");
CODE_MAP.put("射线胶片照相检测","ZZXM_II");
}
@Override
public Class supportJavaTypeKey() {
return String.class;
}
@Override
public CellDataTypeEnum supportExcelTypeKey() {
return CellDataTypeEnum.STRING;
}
@Override
public String convertToJavaData(CellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
String cellDataStr = cellData.getStringValue();
return CODE_MAP.get(cellDataStr);
}
@Override
public CellData convertToExcelData(String value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
return null;
}
}
...@@ -84,6 +84,10 @@ public class CompanyUserImportDto { ...@@ -84,6 +84,10 @@ public class CompanyUserImportDto {
@ExcelProperty(value = "证件编号") @ExcelProperty(value = "证件编号")
private String certificateNum; private String certificateNum;
@NotBlank(message = "检验资质发证机关不能为空!")
@ExcelProperty(value = "证书编号")
private String certNo;
@NotBlank(message = "发证机关不能为空!") @NotBlank(message = "发证机关不能为空!")
@ExcelProperty(value = "发证机关") @ExcelProperty(value = "发证机关")
private String approvedOrgan; private String approvedOrgan;
...@@ -117,16 +121,20 @@ public class CompanyUserImportDto { ...@@ -117,16 +121,20 @@ public class CompanyUserImportDto {
@ExcelProperty(value = "证件编号") @ExcelProperty(value = "证件编号")
private String certificateNum; private String certificateNum;
@NotBlank(message = "检测资质发证机关不能为空!")
@ExcelProperty(value = "证书编号")
private String certNo;
@NotBlank(message = "发证机关不能为空!") @NotBlank(message = "发证机关不能为空!")
@ExcelProperty(value = "发证机关") @ExcelProperty(value = "发证机关")
private String approvedOrgan; private String approvedOrgan;
@NotBlank(message = "检测资质级别不能为空!") @NotBlank(message = "检测资质级别不能为空!")
@ExcelProperty(value = "级别", converter = QualificationLevelConverter.class) @ExcelProperty(value = "级别", converter = TestLevelConverter.class)
private String permissionLevel; private String permissionLevel;
@NotBlank(message = "检测资质项目不能为空!") @NotBlank(message = "检测资质项目不能为空!")
@ExcelProperty(value = "项目", converter = QualificationProjectConverter.class) @ExcelProperty(value = "项目", converter = TestProjectConverter.class)
private String permissionItem; private String permissionItem;
@NotBlank(message = "检测资质发证日期不能为空!") @NotBlank(message = "检测资质发证日期不能为空!")
......
...@@ -1489,40 +1489,52 @@ public class TzsUserInfoServiceImpl extends BaseService<TzsUserInfoDto, TzsUserI ...@@ -1489,40 +1489,52 @@ public class TzsUserInfoServiceImpl extends BaseService<TzsUserInfoDto, TzsUserI
} }
// 存在检验不通过的数据则返回错误信息,不在向下写入库 // 存在检验不通过的数据则返回错误信息,不在向下写入库
if (!sheetError.isEmpty()) { if (!sheetError.isEmpty()) {
// 发送错误文件 sendErrorContext(sheetError);
String uuid = UUID.randomUUID().toString();
startDownLoadMsg("人员导入错误文件", uuid);
File tempFile = File.createTempFile("errors", ".txt");
try (FileWriter writer = new FileWriter(tempFile)) {
for (String error : sheetError) {
writer.write(error + System.lineSeparator());
}
}
byte[] fileContent = Files.readAllBytes(tempFile.toPath());
MultipartFile mockMultipartFile = new MockMultipartFile("errors.txt", "errors.txt", "text/plain", fileContent);
String urlString = this.uploadExcelFile(mockMultipartFile);
sendDownLoadExcelMsg(String.format(DOWNLOAD_TOPIC, RequestContext.getToken()), new JSONObject()
.fluentPut("id", uuid)
.fluentPut("status", "done")
.fluentPut("fileName", "人员导入错误文件")
.fluentPut("url", urlString)
.fluentPut("time", new Date().getTime()));
tempFile.delete();
throw new BadRequest("校验出错,请查看错误文件!");
} }
// 3.数据入库 // 3.数据入库
dataList.forEach(data -> { dataList.forEach(data -> {
TzsUserInfoDto dto = new TzsUserInfoDto(); TzsUserInfoDto dto = new TzsUserInfoDto();
BeanUtils.copyProperties(data, dto); BeanUtils.copyProperties(data, dto);
dto.setCreateDate(new Date()); dto.setCreateDate(new Date());
this.saveUserInfo(dto); try {
this.saveUserInfo(dto);
} catch (Exception e) {
sheetError.add(dto.getName() + "-" + dto.getCertificateNum() + ":" + e.getMessage());
}
}); });
// 第二次捕获save中的异常
if (!sheetError.isEmpty()) {
sendErrorContext(sheetError);
}
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
return ResponseHelper.buildResponse("success"); return ResponseHelper.buildResponse("success");
} }
private void sendErrorContext(ArrayList<String> sheetError) throws IOException {
// 发送错误文件
String uuid = UUID.randomUUID().toString();
startDownLoadMsg("人员导入错误文件", uuid);
File tempFile = File.createTempFile("errors", ".txt");
try (FileWriter writer = new FileWriter(tempFile)) {
for (String error : sheetError) {
writer.write(error + System.lineSeparator());
}
}
byte[] fileContent = Files.readAllBytes(tempFile.toPath());
MultipartFile mockMultipartFile = new MockMultipartFile("errors.txt", "errors.txt", "text/plain", fileContent);
String urlString = this.uploadExcelFile(mockMultipartFile);
sendDownLoadExcelMsg(String.format(DOWNLOAD_TOPIC, RequestContext.getToken()), new JSONObject()
.fluentPut("id", uuid)
.fluentPut("status", "done")
.fluentPut("fileName", "人员导入错误文件")
.fluentPut("url", urlString)
.fluentPut("time", new Date().getTime()));
tempFile.delete();
throw new BadRequest("校验出错,请查看错误文件!");
}
private void companyUserCheckField(ArrayList<String> sheetError, String sheetName, List<CompanyUserImportDto> dataList, private void companyUserCheckField(ArrayList<String> sheetError, String sheetName, List<CompanyUserImportDto> dataList,
CompanyUserImportDto userItems, int excelRowNum, Map<String, String> phoneOnly, Map<String, String> certificateNumOnly, CompanyUserImportDto userItems, int excelRowNum, Map<String, String> phoneOnly, Map<String, String> certificateNumOnly,
CompanyBo company) { CompanyBo company) {
...@@ -1564,7 +1576,7 @@ public class TzsUserInfoServiceImpl extends BaseService<TzsUserInfoDto, TzsUserI ...@@ -1564,7 +1576,7 @@ public class TzsUserInfoServiceImpl extends BaseService<TzsUserInfoDto, TzsUserI
Map<String, String> allPostNames = this.postByUnitType(company).stream().collect(Collectors.toMap(DataDictionary::getName, DataDictionary::getCode)); Map<String, String> allPostNames = this.postByUnitType(company).stream().collect(Collectors.toMap(DataDictionary::getName, DataDictionary::getCode));
String postNameStr = userItems.getPost(); String postNameStr = userItems.getPost();
if (!ValidationUtil.isEmpty(postNameStr)) { if (!ValidationUtil.isEmpty(postNameStr)) {
List<String> postNameList = Arrays.asList(postNameStr.replace(",", ",").replace("-", ",").split(",")); List<String> postNameList = Arrays.asList(postNameStr.replace(",", ",").replace("-", ",").replace("\n","").split(","));
// postNameList 中,不存在于 allPostNames 中的元素 // postNameList 中,不存在于 allPostNames 中的元素
List<String> notExistPosts = postNameList.stream() List<String> notExistPosts = postNameList.stream()
.filter(p -> !allPostNames.containsKey(p)) .filter(p -> !allPostNames.containsKey(p))
...@@ -1584,7 +1596,7 @@ public class TzsUserInfoServiceImpl extends BaseService<TzsUserInfoDto, TzsUserI ...@@ -1584,7 +1596,7 @@ public class TzsUserInfoServiceImpl extends BaseService<TzsUserInfoDto, TzsUserI
// 5.人员类型和人员子类型的匹配 // 5.人员类型和人员子类型的匹配
String subPost = userItems.getSubPost(); String subPost = userItems.getSubPost();
if (!ValidationUtil.isEmpty(subPost)) { if (!ValidationUtil.isEmpty(subPost)) {
String subPostStr = subPost.replace(",", ",").replace("-", ","); String subPostStr = subPost.replace(",", ",").replace("-", ",").replace("\n","");
List<String> subPostList = Arrays.asList(subPostStr.split(",")); List<String> subPostList = Arrays.asList(subPostStr.split(","));
String postCode = this.postByUnitType(company).stream().filter(item -> item.getName().equals(postName)).map(DataDictionary::getCode).findFirst().orElse(""); String postCode = this.postByUnitType(company).stream().filter(item -> item.getName().equals(postName)).map(DataDictionary::getCode).findFirst().orElse("");
Map<String, String> allSubPostNames = this.subPostByUnitType(company, postCode).stream().collect(Collectors.toMap(DataDictionary::getName, DataDictionary::getCode)); Map<String, String> allSubPostNames = this.subPostByUnitType(company, postCode).stream().collect(Collectors.toMap(DataDictionary::getName, DataDictionary::getCode));
...@@ -1599,7 +1611,7 @@ public class TzsUserInfoServiceImpl extends BaseService<TzsUserInfoDto, TzsUserI ...@@ -1599,7 +1611,7 @@ public class TzsUserInfoServiceImpl extends BaseService<TzsUserInfoDto, TzsUserI
errors.add("第" + excelRowNum + "行,错误信息->" + "不可以录入以下人员类型的数据:" + String.join(",", notExistSubPosts)); errors.add("第" + excelRowNum + "行,错误信息->" + "不可以录入以下人员类型的数据:" + String.join(",", notExistSubPosts));
} }
// 转化subPost // 转化subPost
userItems.setSubPost(subPostList.stream().map(allSubPostNames::get).collect(Collectors.joining(","))); userItems.setSubPost(new JSONArray(subPostList.stream().map(allSubPostNames::get).collect(Collectors.toList())).toString());
} }
}); });
} }
......
...@@ -98,12 +98,12 @@ public class TzsUserPermissionServiceImpl extends BaseService<TzsUserPermissionD ...@@ -98,12 +98,12 @@ public class TzsUserPermissionServiceImpl extends BaseService<TzsUserPermissionD
// permissionData66151 检验资质 // permissionData66151 检验资质
JSONArray permissionData66151 = userInfoDto.getPermissionData66151(); JSONArray permissionData66151 = userInfoDto.getPermissionData66151();
if (!ValidationUtil.isEmpty(permissionData66151)) { if (!ValidationUtil.isEmpty(permissionData66151)) {
permissionData66151.forEach(x -> tzsUserPermissions.add(buildPermission(JYRY_TYPE, (JSONObject) x, userInfoDto))); permissionData66151.forEach(x -> tzsUserPermissions.add(buildPermission(JYRY_TYPE, JSONObject.parseObject(JSON.toJSONString(x)), userInfoDto)));
} }
// permissionData66152 检测资质 // permissionData66152 检测资质
JSONArray permissionData66152 = userInfoDto.getPermissionData66152(); JSONArray permissionData66152 = userInfoDto.getPermissionData66152();
if (!ValidationUtil.isEmpty(permissionData66152)) { if (!ValidationUtil.isEmpty(permissionData66152)) {
permissionData66152.forEach(x -> tzsUserPermissions.add(buildPermission(JCRY_TYPE, (JSONObject) x, userInfoDto))); permissionData66152.forEach(x -> tzsUserPermissions.add(buildPermission(JCRY_TYPE, JSONObject.parseObject(JSON.toJSONString(x)), userInfoDto)));
} }
// permissionData6552 作业人员资质 // permissionData6552 作业人员资质
JSONArray permissionData6552 = userInfoDto.getPermissionData6552(); JSONArray permissionData6552 = userInfoDto.getPermissionData6552();
...@@ -117,10 +117,10 @@ public class TzsUserPermissionServiceImpl extends BaseService<TzsUserPermissionD ...@@ -117,10 +117,10 @@ public class TzsUserPermissionServiceImpl extends BaseService<TzsUserPermissionD
String jobItem = String.valueOf(itempermissionData6552.get("jobItem")); String jobItem = String.valueOf(itempermissionData6552.get("jobItem"));
String otherItem = String.valueOf(itempermissionData6552.get("otherItem")); String otherItem = String.valueOf(itempermissionData6552.get("otherItem"));
JSONObject itemCode = JSON.parseObject(String.valueOf(itempermissionData6552.get("itemCode"))); JSONObject itemCode = JSON.parseObject(String.valueOf(itempermissionData6552.get("itemCode")));
if (jobItem.contains("金属焊接操作") && ObjectUtils.isEmpty(itemCode.get("JSHJCZItemCode"))) { if (jobItem.contains("金属焊接操作") && !ObjectUtils.isEmpty(itemCode) && ObjectUtils.isEmpty(itemCode.get("JSHJCZItemCode"))) {
throw new BadRequest("作业项目中含有金属焊接操作,需填写金属焊接操作-项目代号"); throw new BadRequest("作业项目中含有金属焊接操作,需填写金属焊接操作-项目代号");
} }
if (jobItem.contains("非金属焊接操作") && ObjectUtils.isEmpty(itemCode.get("FJSHJCZItemCode"))) { if (jobItem.contains("非金属焊接操作") && !ObjectUtils.isEmpty(itemCode) && ObjectUtils.isEmpty(itemCode.get("FJSHJCZItemCode"))) {
throw new BadRequest("作业项目中含有非金属焊接操作,需填写非金属焊接操作-项目代号"); throw new BadRequest("作业项目中含有非金属焊接操作,需填写非金属焊接操作-项目代号");
} }
if (jobItem.contains("其他") && ObjectUtils.isEmpty(otherItem)) { if (jobItem.contains("其他") && ObjectUtils.isEmpty(otherItem)) {
......
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