完善市场法规库清单添加接口

This commit is contained in:
梁琦涛
2024-07-07 14:49:27 +08:00
parent 1439eb56c4
commit 88692b8e3a
6 changed files with 196 additions and 37 deletions
@@ -223,4 +223,11 @@ public interface ILawsCommonService {
* @return * @return
*/ */
Map<String, Object> getInfoByStandardNo(String standardNumber); Map<String, Object> getInfoByStandardNo(String standardNumber);
/**
* 验证excel注解翻译是否匹配
* @param obj
* @return
*/
StringBuilder validateFieldByDict(Object obj);
} }
@@ -4,20 +4,29 @@ import cn.hutool.core.io.FileUtil;
import cn.hutool.core.text.CharSequenceUtil; import cn.hutool.core.text.CharSequenceUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.jero.common.api.vo.ResultCommon; import com.jero.common.api.vo.ResultCommon;
import com.jero.common.aspect.annotation.Dict;
import com.jero.common.constant.CommonConstant;
import com.jero.common.constant.enums.LanguageEnum; import com.jero.common.constant.enums.LanguageEnum;
import com.jero.common.constant.enums.YesOrNoEnum; import com.jero.common.constant.enums.YesOrNoEnum;
import com.jero.common.exception.JeroBootException; import com.jero.common.exception.JeroBootException;
import com.jero.common.system.api.ISysBaseAPI;
import com.jero.common.system.vo.LoginUser; import com.jero.common.system.vo.LoginUser;
import com.jero.common.system.vo.SysDictItemCore;
import com.jero.common.util.IntekeyUtils; import com.jero.common.util.IntekeyUtils;
import com.jero.common.util.MessageUtils; import com.jero.common.util.MessageUtils;
import com.jero.common.util.MinioUtil; import com.jero.common.util.MinioUtil;
import com.jero.common.util.oConvertUtils;
import com.jero.modules.activiti.process.common.enums.StandardStateEnum; import com.jero.modules.activiti.process.common.enums.StandardStateEnum;
import com.jero.modules.laws.common.constant.FieldCommon; import com.jero.modules.laws.common.constant.FieldCommon;
import com.jero.modules.laws.common.mapper.LawsCommonMapper; import com.jero.modules.laws.common.mapper.LawsCommonMapper;
@@ -69,6 +78,7 @@ import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.shiro.SecurityUtils; import org.apache.shiro.SecurityUtils;
import org.jeecgframework.poi.excel.annotation.Excel;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.mock.web.MockMultipartFile; import org.springframework.mock.web.MockMultipartFile;
@@ -79,6 +89,7 @@ import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.*; import java.io.*;
import java.lang.reflect.Field;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
@@ -153,6 +164,8 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
private ISysUserService sysUserRoleService; private ISysUserService sysUserRoleService;
@Resource @Resource
private ILawsPartNameStandardService partNameStandardService; private ILawsPartNameStandardService partNameStandardService;
@Resource
private ISysBaseAPI sysBaseAPI;
public static boolean ENCRYPT_ENABLE; public static boolean ENCRYPT_ENABLE;
public static String DECRYPT_URL; public static String DECRYPT_URL;
@@ -2619,6 +2632,7 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
return null; return null;
} }
/** /**
* 创建企标导入模板的Workbook * 创建企标导入模板的Workbook
* *
@@ -2779,4 +2793,94 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
this.setRow3CellValue(row3, fieldList, style); this.setRow3CellValue(row3, fieldList, style);
return workbook; return workbook;
} }
@Override
public StringBuilder validateFieldByDict(Object record) {
StringBuilder msg = new StringBuilder();
List<SysDictItemCore> listDict = sysBaseAPI.getDictItemAll();
if(CollectionUtils.isEmpty(listDict)){
return msg;
}
ObjectMapper mapper = new ObjectMapper();
String json;
String jsonError = "json解析失败";
try {
json = mapper.writeValueAsString(record);
} catch (JsonProcessingException e) {
log.error(jsonError + e.getMessage(), e);
throw new JeroBootException(jsonError);
}
JSONObject item;
try {
item = JSON.parseObject(json);
} catch (Exception e) {
log.error(jsonError + e.getMessage(), e);
throw new JeroBootException(jsonError);
}
for (Field field : oConvertUtils.getAllFields(record)) {
field.setAccessible(true);
if (field.getAnnotation(Excel.class) != null) {
String code = field.getAnnotation(Excel.class).dicCode();
if(StringUtils.isBlank(code)){
continue;
}
String name = field.getAnnotation(Excel.class).name();
String text = field.getAnnotation(Excel.class).dicText();
String table = field.getAnnotation(Excel.class).dictTable();
String key = String.valueOf(item.get(field.getName()));
if(StringUtils.isBlank(key) || Objects.equals("null", key)){
item.put(field.getName(), null);
continue;
}
String textValue = translateDictValue(code, text, table, key, listDict);
if(StringUtils.isBlank(textValue)){
msg.append(name).append("数据不存在;");
}else{
item.put(field.getName(), textValue);
}
}
}
return msg;
}
/**
* 翻译字典文本
*
* @param code 编码
* @param text 值
* @param table 表名
* @param key 键
* @param listDict 字典集合
*/
private String translateDictValue(String code, String text, String table, String key, List<SysDictItemCore> listDict) {
if (oConvertUtils.isEmpty(key)) {
return null;
}
StringBuilder textValue = new StringBuilder();
String[] keys = key.split(",");
for (String k : keys) {
String tmpValue = null;
if (k.trim().length() == 0) {
continue; //跳过循环
}
if (!org.springframework.util.StringUtils.isEmpty(table)) {
tmpValue = sysBaseAPI.queryTableDictTextByKey(table, code, text, k.trim());
} else {
List<SysDictItemCore> listNew = listDict.stream().filter(o -> Objects.equals(o.getDictCode(), code) && Objects.equals(o.getItemText(), k.trim())).collect(Collectors.toList());
if (!org.springframework.util.CollectionUtils.isEmpty(listNew)) {
tmpValue = listNew.get(0).getItemText();
}
}
if (tmpValue != null) {
if (!"".equals(textValue.toString())) {
textValue.append(",");
}
textValue.append(tmpValue);
}
}
return textValue.toString();
}
} }
@@ -123,7 +123,7 @@ public class LawsMarketStandardDetailExcel implements Serializable {
/** /**
* 国家 * 国家
*/ */
@Excel(name = "*国家/地区", width = 15,dicCode = "market_state") @Excel(name = "*国家/地区", width = 15)
@NotBlank(message = "国家/地区不能为空") @NotBlank(message = "国家/地区不能为空")
@ApiModelProperty(value = "国家") @ApiModelProperty(value = "国家")
@Dict(dicCode = "market_state") @Dict(dicCode = "market_state")
@@ -132,7 +132,7 @@ public class LawsMarketStandardDetailExcel implements Serializable {
/** /**
* 适用车型 * 适用车型
*/ */
@Excel(name = "适用车型", width = 15, dicCode = "applicable_vehicle_type") @Excel(name = "适用车型", width = 15)
@Dict(dicCode = "applicable_vehicle_type") @Dict(dicCode = "applicable_vehicle_type")
@ApiModelProperty(value = "适用车型") @ApiModelProperty(value = "适用车型")
private String applicableVehicle; private String applicableVehicle;
@@ -148,7 +148,7 @@ public class LawsMarketStandardDetailExcel implements Serializable {
*/ */
@ApiModelProperty(value = "认证对象") @ApiModelProperty(value = "认证对象")
@Dict(dicCode = "authentication_object") @Dict(dicCode = "authentication_object")
@Excel(name = "认证对象", width = 15, dicCode = "authentication_object") @Excel(name = "认证对象", width = 15)
private String authenticationObject; private String authenticationObject;
/** /**
@@ -162,7 +162,7 @@ public class LawsMarketStandardDetailExcel implements Serializable {
* 类型 * 类型
*/ */
@Dict(dicCode = "type") @Dict(dicCode = "type")
@Excel(name = "类型", width = 15, dicCode = "type") @Excel(name = "类型", width = 15)
@ApiModelProperty(value = "类型") @ApiModelProperty(value = "类型")
private String type; private String type;
@@ -171,7 +171,7 @@ public class LawsMarketStandardDetailExcel implements Serializable {
*/ */
@Dict(dicCode = "dynamic_type") @Dict(dicCode = "dynamic_type")
@ApiModelProperty(value = "动力类型") @ApiModelProperty(value = "动力类型")
@Excel(name = "动力类型", width = 15, dicCode = "dynamic_type") @Excel(name = "动力类型", width = 15)
private String dynamicType; private String dynamicType;
/** /**
@@ -180,7 +180,7 @@ public class LawsMarketStandardDetailExcel implements Serializable {
@Dict(dictTable = "sys_depart", dicCode = "id", dicText = "depart_name") @Dict(dictTable = "sys_depart", dicCode = "id", dicText = "depart_name")
@ApiModelProperty(value = "主控部门") @ApiModelProperty(value = "主控部门")
@NotBlank(message = "主控部门不能为空") @NotBlank(message = "主控部门不能为空")
@Excel(name = "*主控部门", width = 15,dictTable = "sys_depart", dicCode = "id", dicText = "depart_name") @Excel(name = "*主控部门", width = 15)
private String mainDept; private String mainDept;
/** /**
@@ -189,7 +189,7 @@ public class LawsMarketStandardDetailExcel implements Serializable {
@ApiModelProperty(value = "主控部门专业模块") @ApiModelProperty(value = "主控部门专业模块")
@NotBlank(message = "主控部门专业模块不能为空") @NotBlank(message = "主控部门专业模块不能为空")
@Dict(dicCode = "professional_module") @Dict(dicCode = "professional_module")
@Excel(name = "*主控部门专业模块", width = 15, dicCode = "professional_module") @Excel(name = "*主控部门专业模块", width = 15)
private String mainDeptProfMode; private String mainDeptProfMode;
/** /**
@@ -197,14 +197,14 @@ public class LawsMarketStandardDetailExcel implements Serializable {
*/ */
@Dict(dictTable = "sys_depart", dicCode = "id", dicText = "depart_name") @Dict(dictTable = "sys_depart", dicCode = "id", dicText = "depart_name")
@ApiModelProperty(value = "关联部门") @ApiModelProperty(value = "关联部门")
@Excel(name = "关联部门", width = 15,dictTable = "sys_depart", dicCode = "id", dicText = "depart_name") @Excel(name = "关联部门", width = 15)
private String associateDept; private String associateDept;
/** /**
* 关联部门专业模块 * 关联部门专业模块
*/ */
@ApiModelProperty(value = "关联部门专业模块") @ApiModelProperty(value = "关联部门专业模块")
@Excel(name = "关联部门专业模块", width = 15, dicCode = "professional_module") @Excel(name = "关联部门专业模块", width = 15)
@Dict(dicCode = "professional_module") @Dict(dicCode = "professional_module")
private String associateDeptProfMode; private String associateDeptProfMode;
@@ -212,7 +212,7 @@ public class LawsMarketStandardDetailExcel implements Serializable {
* 批量限制 * 批量限制
*/ */
@ApiModelProperty(value = "批量限制") @ApiModelProperty(value = "批量限制")
@Excel(name = "批量限制", width = 15, dicCode = "batch_restriction") @Excel(name = "批量限制", width = 15)
@Dict(dicCode = "batch_restriction") @Dict(dicCode = "batch_restriction")
private String batchLimit; private String batchLimit;
@@ -221,7 +221,7 @@ public class LawsMarketStandardDetailExcel implements Serializable {
*/ */
@Dict(dicCode = "automatic_driving_level") @Dict(dicCode = "automatic_driving_level")
@ApiModelProperty(value = "自动驾驶等级") @ApiModelProperty(value = "自动驾驶等级")
@Excel(name = "自动驾驶等级", width = 15,dicCode = "automatic_driving_level") @Excel(name = "自动驾驶等级", width = 15)
private String autopilotLevel; private String autopilotLevel;
/** /**
@@ -229,7 +229,7 @@ public class LawsMarketStandardDetailExcel implements Serializable {
*/ */
@Dict(dicCode = "requirement_type") @Dict(dicCode = "requirement_type")
@ApiModelProperty(value = "要求类型") @ApiModelProperty(value = "要求类型")
@Excel(name = "要求类型", width = 15,dicCode = "requirement_type") @Excel(name = "要求类型", width = 15)
private String requireType; private String requireType;
@@ -10,10 +10,10 @@
from laws_domestic_standard from laws_domestic_standard
where del_flag = 0 where del_flag = 0
union all union all
select id, standard_number, select id, standard_number
from laws_enterprise_standard from laws_enterprise_standard
where del_flag = 0) a where standard_number in where del_flag = 0) a where standard_number in
<foreach collection="listNum.split(',')" item="item" separator="," open="(" close=")"> <foreach collection="listNum" item="item" separator="," open="(" close=")">
#{item} #{item}
</foreach> </foreach>
</select> </select>
@@ -10,10 +10,10 @@ import com.jero.common.exception.JeroBootException;
import com.jero.common.system.query.QueryGenerator; import com.jero.common.system.query.QueryGenerator;
import com.jero.common.system.vo.LoginUser; import com.jero.common.system.vo.LoginUser;
import com.jero.common.util.ImportExcelUtil; import com.jero.common.util.ImportExcelUtil;
import com.jero.modules.laws.common.service.ILawsCommonService;
import com.jero.modules.laws.marketStandard.entity.LawsMarketStandard; import com.jero.modules.laws.marketStandard.entity.LawsMarketStandard;
import com.jero.modules.laws.marketStandard.entity.LawsMarketStandardDetail; import com.jero.modules.laws.marketStandard.entity.LawsMarketStandardDetail;
import com.jero.modules.laws.marketStandard.entity.LawsMarketStandardDetailExcel; import com.jero.modules.laws.marketStandard.entity.LawsMarketStandardDetailExcel;
import com.jero.modules.laws.marketStandard.entity.MarketStandardDetailVO;
import com.jero.modules.laws.marketStandard.mapper.LawsMarketStandardDetailMapper; import com.jero.modules.laws.marketStandard.mapper.LawsMarketStandardDetailMapper;
import com.jero.modules.laws.marketStandard.service.ILawsMarketStandardDetailService; import com.jero.modules.laws.marketStandard.service.ILawsMarketStandardDetailService;
import com.jero.modules.laws.marketStandard.service.ILawsMarketStandardService; import com.jero.modules.laws.marketStandard.service.ILawsMarketStandardService;
@@ -23,7 +23,6 @@ import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.SecurityUtils; import org.apache.shiro.SecurityUtils;
import org.jeecgframework.poi.excel.ExcelImportUtil; import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.entity.ImportParams; import org.jeecgframework.poi.excel.entity.ImportParams;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@@ -32,7 +31,9 @@ import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.*; import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@@ -45,13 +46,15 @@ import java.util.stream.Collectors;
* @createDate 2024-06-29 11:34:34 * @createDate 2024-06-29 11:34:34
*/ */
@Service @Service
public class LawsMarketStandardDetailServiceImpl extends ServiceImpl<LawsMarketStandardDetailMapper, LawsMarketStandardDetail> public class LawsMarketStandardDetailServiceImpl extends ServiceImpl<LawsMarketStandardDetailMapper,
implements ILawsMarketStandardDetailService { LawsMarketStandardDetail> implements ILawsMarketStandardDetailService {
@Resource @Resource
private ILawsMarketStandardService marketStandardService; private ILawsMarketStandardService marketStandardService;
@Resource @Resource
private LawsMarketStandardDetailMapper lawsMarketStandardDetailMapper; private LawsMarketStandardDetailMapper lawsMarketStandardDetailMapper;
@Resource
private ILawsCommonService lawsCommonService;
@Override @Override
@@ -115,7 +118,6 @@ public class LawsMarketStandardDetailServiceImpl extends ServiceImpl<LawsMarketS
@Override @Override
@Transactional(rollbackFor = JeroBootException.class) @Transactional(rollbackFor = JeroBootException.class)
public synchronized Result<?> importExcel(MultipartFile file,String manifestId) { public synchronized Result<?> importExcel(MultipartFile file,String manifestId) {
List<LawsMarketStandardDetail> list = new ArrayList<>();
// 校验文件是否为excel // 校验文件是否为excel
if (!ImportExcelUtil.checkExcelFile(file)) { if (!ImportExcelUtil.checkExcelFile(file)) {
return Result.error("请导入excel文件"); return Result.error("请导入excel文件");
@@ -123,50 +125,86 @@ public class LawsMarketStandardDetailServiceImpl extends ServiceImpl<LawsMarketS
ImportParams params = new ImportParams(); ImportParams params = new ImportParams();
params.setHeadRows(1); params.setHeadRows(1);
// 校验excel 字段是否正确 // 校验excel 字段是否正确
boolean b = ImportExcelUtil.checkTemplateTitle(file, LawsMarketStandardDetailExcel.class, 0, 0); boolean b = ImportExcelUtil.
checkTemplateTitle(file, LawsMarketStandardDetailExcel.class, 0, 0);
if (!b) { if (!b) {
return Result.error("excel文件表头错误,请重新下载"); return Result.error("excel文件表头错误,请重新下载");
} }
try { try {
List<LawsMarketStandardDetailExcel> listLawsMarketStandardDetailExcel = ExcelImportUtil.importExcel(file.getInputStream(), LawsMarketStandardDetailExcel.class, params); List<LawsMarketStandardDetailExcel> listLawsMarketStandardDetailExcel = ExcelImportUtil.importExcel(
if(!CollectionUtils.isEmpty(listLawsMarketStandardDetailExcel) && listLawsMarketStandardDetailExcel.size() >= 2){ file.getInputStream(), LawsMarketStandardDetailExcel.class, params);
listLawsMarketStandardDetailExcel = listLawsMarketStandardDetailExcel.subList(2,listLawsMarketStandardDetailExcel.size()); if(!CollectionUtils.isEmpty(listLawsMarketStandardDetailExcel)
&& listLawsMarketStandardDetailExcel.size() >= 2){
listLawsMarketStandardDetailExcel = listLawsMarketStandardDetailExcel.
subList(2,listLawsMarketStandardDetailExcel.size());
} }
if(CollectionUtils.isEmpty(listLawsMarketStandardDetailExcel)){ if(CollectionUtils.isEmpty(listLawsMarketStandardDetailExcel)){
return Result.error("导入数据为空"); return Result.error("导入数据为空");
} }
List<LawsMarketStandardDetail> listLawsMarketStandardDetail = JSON.parseArray( List<LawsMarketStandardDetail> listLawsMarketStandardDetail = JSON.parseArray(
JSON.toJSONString(listLawsMarketStandardDetailExcel),LawsMarketStandardDetail.class); JSON.toJSONString(listLawsMarketStandardDetailExcel),LawsMarketStandardDetail.class);
List<LawsMarketStandardDetail> listStandardNumberNotNull = listLawsMarketStandardDetail.stream().filter(o->!StringUtils.isBlank(o.getStandardNumber())).collect(Collectors.toList()); List<LawsMarketStandardDetail> listStandardNumberNotNull = listLawsMarketStandardDetail.stream().filter(o->
!StringUtils.isBlank(o.getStandardNumber())).collect(Collectors.toList());
if(CollectionUtils.isEmpty(listStandardNumberNotNull)){ if(CollectionUtils.isEmpty(listStandardNumberNotNull)){
return Result.error("标准编号不能为空"); return Result.error("标准编号不能为空");
} }
List<String> listStandardNumber = listStandardNumberNotNull.stream().map(LawsMarketStandardDetail::getStandardNumber).collect(Collectors.toList()); List<String> listStandardNumber = listStandardNumberNotNull.stream()
.map(LawsMarketStandardDetail::getStandardNumber).collect(Collectors.toList());
// 根据标准编号获取标准id // 根据标准编号获取标准id
List<LawsMarketStandardDetail> listIds = lawsMarketStandardDetailMapper.getStandardData(listStandardNumber); List<LawsMarketStandardDetail> listIds = lawsMarketStandardDetailMapper.getStandardData(listStandardNumber);
if(CollectionUtils.isEmpty(listIds)){ if(CollectionUtils.isEmpty(listIds)){
return Result.error("标准编号不存在"); return Result.error("标准编号不存在");
} }
StringBuilder m = new StringBuilder(); StringBuilder m = new StringBuilder();
// 获取当前清单的标准
LambdaQueryWrapper<LawsMarketStandardDetail> queryLawsMarketStandardDetail = new LambdaQueryWrapper<>();
queryLawsMarketStandardDetail.select(LawsMarketStandardDetail::getStandardId);
queryLawsMarketStandardDetail.eq(LawsMarketStandardDetail::getManifestId,manifestId);
queryLawsMarketStandardDetail.isNotNull(LawsMarketStandardDetail::getStandardId);
List<LawsMarketStandardDetail> listStandardId = list(queryLawsMarketStandardDetail);
List<String> listStandardIds = new ArrayList<>();
if(!CollectionUtils.isEmpty(listStandardId)){
listStandardIds = listStandardId.stream().map(LawsMarketStandardDetail::getStandardId)
.collect(Collectors.toList());
}
// 验证标准编号是否重复 // 验证标准编号是否重复
List<String> listStandardNum = new ArrayList<>(); List<String> listStandardIdRepeat = new ArrayList<>();
for (int i = 0; i < listLawsMarketStandardDetail.size(); i++) { for (int i = 0; i < listLawsMarketStandardDetail.size(); i++) {
LawsMarketStandardDetail p = listLawsMarketStandardDetail.get(i); LawsMarketStandardDetail p = listLawsMarketStandardDetail.get(i);
p.setManifestId(manifestId); p.setManifestId(manifestId);
// 校验数据 // 校验数据
StringBuilder g = ValidUtil.validateReturnBuilder(p); StringBuilder s = new StringBuilder();
StringBuilder g = ValidUtil.validateReturnBuilder(p);
if(!StringUtils.isEmpty(g.toString())){ if(!StringUtils.isEmpty(g.toString())){
m.append(i + 4).append("行,").append(g.toString()); s.append(g.toString());
} }
// 验证字典值是否满足条件
StringBuilder dict = lawsCommonService.validateFieldByDict(p);
if(!StringUtils.isBlank(dict)){
s.append(dict);
}
// 验证标准编号
if(!StringUtils.isBlank(p.getStandardNumber())){ if(!StringUtils.isBlank(p.getStandardNumber())){
List<LawsMarketStandardDetail> listStandardNumberData = listIds.stream().filter(o-> List<LawsMarketStandardDetail> listStandardNumberData = listIds.stream().filter(o->
Objects.equals(o.getStandardNumber(),p.getStandardNumber())).collect(Collectors.toList()); Objects.equals(o.getStandardNumber(),p.getStandardNumber())).collect(Collectors.toList());
if(CollectionUtils.isEmpty(listStandardNumberData)){ if(CollectionUtils.isEmpty(listStandardNumberData)){
m.append(i + 4).append("行,标准编号不存在"); s.append("标准编号不存在;");
}else{
String id = listStandardNumberData.get(0).getStandardId();
p.setStandardId(id);
if(!CollectionUtils.isEmpty(listStandardIds) && listStandardIds.contains(id)){
s.append("标准编号已存在;");
}else if(!CollectionUtils.isEmpty(listStandardIdRepeat) && listStandardIdRepeat.contains(id)){
s.append("标准编号重复;");
}
listStandardIdRepeat.add(listStandardNumberData.get(0).getId());
} }
} }
if(!StringUtils.isBlank(s.toString())){
m.append("").append(i + 4).append("行,").append(s.toString());
}
} }
if(!StringUtils.isBlank(m.toString())){ if(!StringUtils.isBlank(m.toString())){
return Result.error(m.toString()); return Result.error(m.toString());
} }
@@ -176,6 +214,7 @@ public class LawsMarketStandardDetailServiceImpl extends ServiceImpl<LawsMarketS
return Result.OK("导入成功"); return Result.OK("导入成功");
} catch (Exception e) { } catch (Exception e) {
log.error(e.getMessage(),e); log.error(e.getMessage(),e);
return Result.error("导入失败");
} finally { } finally {
try { try {
file.getInputStream().close(); file.getInputStream().close();
@@ -183,8 +222,6 @@ public class LawsMarketStandardDetailServiceImpl extends ServiceImpl<LawsMarketS
e.printStackTrace(); e.printStackTrace();
} }
} }
return Result.OK("导入成功");
} }
@Override @Override
@@ -1,18 +1,29 @@
package com.jero.modules.laws.utils; package com.jero.modules.laws.utils;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.jero.common.aspect.annotation.Dict;
import com.jero.common.constant.CommonConstant;
import com.jero.common.exception.JeroBootException; import com.jero.common.exception.JeroBootException;
import com.jero.common.system.api.ISysBaseAPI;
import com.jero.common.system.vo.SysDictItemCore;
import com.jero.common.util.oConvertUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ReflectionUtils; import org.springframework.util.ReflectionUtils;
import javax.annotation.Resource;
import javax.validation.ConstraintViolation; import javax.validation.ConstraintViolation;
import javax.validation.Validation; import javax.validation.Validation;
import javax.validation.Validator; import javax.validation.Validator;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.ArrayList; import java.text.SimpleDateFormat;
import java.util.List; import java.util.*;
import java.util.Objects; import java.util.stream.Collectors;
import java.util.Set;
/** /**
* 手动校验@Vaild方法 * 手动校验@Vaild方法