parent
3203295bff
commit
c7386fd09e
|
@ -6,15 +6,15 @@ logging:
|
|||
encodings: UTF-8
|
||||
file:
|
||||
# 日志保存路径
|
||||
path: F:\01zjya\10Log\kangarooDataCenterV3\voucher-gm\log
|
||||
path: D:\yonganProject\kangarooDataCenterV3-gm\log
|
||||
spring:
|
||||
datasource:
|
||||
dynamic:
|
||||
datasource:
|
||||
master:
|
||||
url: jdbc:mysql://127.0.0.1:3306/bussinesscenter_voucher_gm?useUnicode=true&characterEncoding=UTF8&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowLoadLocalInfile=false&autoReconnect=true&failOverReadOnly=false&connectTimeout=600000000&socketTimeout=600000000&autoReconnectForPools=true&keepAlive=true
|
||||
url: jdbc:mysql://127.0.0.1:3306/bussinesscenter_voucher_gm?useUnicode=true&characterEncoding=UTF8&serverTimezone=GMT%2B8&zeroDateTimeBehavior=convertToNull&useSSL=true&allowLoadLocalInfile=false&autoReconnect=true&failOverReadOnly=false&connectTimeout=600000000&socketTimeout=600000000&autoReconnectForPools=true&keepAlive=true
|
||||
username: root
|
||||
password: 9b1b3fca9719736fe4210f4e0a6df338
|
||||
password: d1588049c1d74db3f4c483dae53914d1
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver # 3.2.0开始支持SPI可省略此配置
|
||||
savefile:
|
||||
# 文件保存路径
|
||||
|
|
|
@ -164,10 +164,22 @@ public abstract class BaseService<E extends Serializable, PK extends Serializabl
|
|||
PageInfo pageInfo = new PageInfo(queryByLike);
|
||||
return BaseResult.getSuccessMessageEntity("查询数据成功", pageInfo);
|
||||
}
|
||||
/**
|
||||
* Generic method to retrieve data from a JSON object based on a key and convert it to the specified type.
|
||||
*
|
||||
* @param <T> The type of the data to be retrieved
|
||||
* @param key The key to look up in the JSON object
|
||||
* @param jsonObject The JSON object to retrieve data from
|
||||
* @param clz The class object of the type to convert to
|
||||
* @return The data of type T if found and valid, null otherwise
|
||||
*/
|
||||
protected <T> T getData(String key, JSONObject jsonObject, Class<T> clz) {
|
||||
// Check if the string value of the key is valid/not empty
|
||||
if (checkStr(jsonObject.getString(key)) ) {
|
||||
// Convert the JSON object value to the specified Java type and return it
|
||||
return jsonObject.getJSONObject(key).toJavaObject(clz);
|
||||
}
|
||||
// Return null if the key value is not valid
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,9 @@ public class JsonResultEntity {
|
|||
/** request 域放的对象 */
|
||||
private Object attribute;
|
||||
|
||||
public String getMsg() {
|
||||
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,11 @@
|
|||
<artifactId>mysql-connector-java</artifactId>
|
||||
<version>${mysql-connector-java}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>easyexcel</artifactId>
|
||||
<version>3.0.5</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
<build>
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
package com.hzya.frame.mdm.mdmModule;
|
||||
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import com.hzya.frame.mdm.mdmModule.service.IMdmModuleService;
|
||||
import com.hzya.frame.mdm.mdmModule.vo.ExcelTemplateVO;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class WriteTest {
|
||||
|
||||
@Autowired
|
||||
private IMdmModuleService mdmModuleService;
|
||||
|
||||
@Test
|
||||
public void testGenerateExcelTemplate() throws IOException {
|
||||
// 文件夹路径
|
||||
String folderPath = "D:/test/";
|
||||
// 完整文件路径(文件夹 + 文件名)
|
||||
String localFilePath = folderPath + "表字段定义模版.xlsx";
|
||||
File dir = new File(folderPath);
|
||||
if (!dir.exists()) {
|
||||
dir.mkdirs(); // 创建文件夹(如果不存在)
|
||||
}
|
||||
// 准备模板的示例数据
|
||||
List<ExcelTemplateVO> demoData = new ArrayList<>();
|
||||
// 生成Excel并保存到本地文件
|
||||
try (OutputStream outputStream = new FileOutputStream(localFilePath)) {
|
||||
EasyExcel.write(outputStream, ExcelTemplateVO.class)
|
||||
.sheet("表字段定义模版")
|
||||
.doWrite(demoData);
|
||||
}
|
||||
System.out.println("Excel模板已成功生成,保存路径:" + localFilePath);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package com.hzya.frame.mdm.mdmModule.config;
|
||||
|
||||
import org.springframework.cache.Cache;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.annotation.CachingConfigurerSupport;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.cache.concurrent.ConcurrentMapCache;
|
||||
import org.springframework.cache.support.SimpleCacheManager;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Configuration
|
||||
@EnableCaching
|
||||
public class CacheConfig extends CachingConfigurerSupport {
|
||||
|
||||
@Bean
|
||||
public CacheManager cacheManager() {
|
||||
SimpleCacheManager cacheManager = new SimpleCacheManager();
|
||||
|
||||
// 添加所有需要的缓存(包括缺失的mdmModuleDb)
|
||||
List<Cache> caches = new ArrayList<>();
|
||||
caches.add(new ConcurrentMapCache("mdmModuleDb"));
|
||||
caches.add(new ConcurrentMapCache("mdmModuleDbFileds"));
|
||||
caches.add(new ConcurrentMapCache("mdmModule"));
|
||||
|
||||
cacheManager.setCaches(caches);
|
||||
return cacheManager;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
package com.hzya.frame.mdm.mdmModule.controller;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.hzya.frame.mdm.mdmModule.service.IMdmModuleService;
|
||||
import com.hzya.frame.mdm.mdmModule.vo.ImportExcelVO;
|
||||
import com.hzya.frame.mdm.mdmModuleDbFileds.entity.MdmModuleDbFiledsEntity;
|
||||
import com.hzya.frame.web.entity.JsonResultEntity;
|
||||
import jline.internal.Log;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping(value = "/excel")
|
||||
public class ImportExcelController {
|
||||
@Autowired
|
||||
private IMdmModuleService iMdmModuleService;
|
||||
|
||||
/**
|
||||
* 导入模版
|
||||
*/
|
||||
@RequestMapping(value = "/importTemplateFile" ,method = RequestMethod.POST)
|
||||
public JsonResultEntity importTemplateFile(@RequestParam("file") MultipartFile file,
|
||||
@ModelAttribute ImportExcelVO importExcelVO){
|
||||
|
||||
List<MdmModuleDbFiledsEntity> entities = iMdmModuleService.importTemplateFile(file,importExcelVO);
|
||||
// 新增字段
|
||||
for (MdmModuleDbFiledsEntity entity : entities) {
|
||||
// JSONObject object = (JSONObject) JSONObject.toJSON(entity);
|
||||
|
||||
String str = JSONObject.toJSONString(entity);
|
||||
Map<String,String> jsonStr=new HashMap<>();
|
||||
jsonStr.put("jsonStr",str);
|
||||
String jsonS = JSON.toJSONString(jsonStr);
|
||||
JSONObject jsonObject = JSONObject.parseObject(jsonS);
|
||||
|
||||
iMdmModuleService.saveMdmDbField(jsonObject);
|
||||
}
|
||||
return new JsonResultEntity("导入模版成功",true,200);
|
||||
|
||||
}
|
||||
}
|
|
@ -3,7 +3,14 @@ package com.hzya.frame.mdm.mdmModule.service;
|
|||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.hzya.frame.mdm.mdmModule.entity.MdmModuleEntity;
|
||||
import com.hzya.frame.basedao.service.IBaseService;
|
||||
import com.hzya.frame.mdm.mdmModule.vo.ImportExcelVO;
|
||||
import com.hzya.frame.mdm.mdmModuleDbFileds.entity.MdmModuleDbFiledsEntity;
|
||||
import com.hzya.frame.web.entity.JsonResultEntity;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 主数据模版(MdmModule)表服务接口
|
||||
|
@ -397,4 +404,16 @@ public interface IMdmModuleService extends IBaseService<MdmModuleEntity, String>
|
|||
* @return com.hzya.frame.web.entity.JsonResultEntity
|
||||
**/
|
||||
JsonResultEntity queryMdmDistributeByMdmCode(JSONObject jsonObject);
|
||||
|
||||
/**
|
||||
* 下载导入模版
|
||||
* @return
|
||||
*/
|
||||
void generateExcelTemplate(HttpServletResponse response) throws IOException;
|
||||
|
||||
/**
|
||||
* 导入模版
|
||||
* @param file
|
||||
*/
|
||||
List<MdmModuleDbFiledsEntity> importTemplateFile(MultipartFile file, ImportExcelVO importExcelVO);
|
||||
}
|
||||
|
|
|
@ -1,8 +1,17 @@
|
|||
package com.hzya.frame.mdm.mdmModule.service.impl;
|
||||
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import com.alibaba.excel.ExcelWriter;
|
||||
import com.alibaba.excel.context.AnalysisContext;
|
||||
import com.alibaba.excel.event.AnalysisEventListener;
|
||||
import com.alibaba.excel.util.StringUtils;
|
||||
import com.alibaba.excel.write.metadata.WriteSheet;
|
||||
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.hzya.frame.beanutil.BeanUtil;
|
||||
import com.hzya.frame.mdm.entity.MdmDbFiledVo;
|
||||
import com.hzya.frame.mdm.entity.MdmDto;
|
||||
import com.hzya.frame.mdm.entity.MdmModuleViewVo;
|
||||
|
@ -10,6 +19,8 @@ import com.hzya.frame.mdm.entity.MdmQuery;
|
|||
import com.hzya.frame.mdm.mdmModule.entity.MdmModuleEntity;
|
||||
import com.hzya.frame.mdm.mdmModule.dao.IMdmModuleDao;
|
||||
import com.hzya.frame.mdm.mdmModule.service.IMdmModuleService;
|
||||
import com.hzya.frame.mdm.mdmModule.vo.ExcelTemplateVO;
|
||||
import com.hzya.frame.mdm.mdmModule.vo.ImportExcelVO;
|
||||
import com.hzya.frame.mdm.mdmModuleDb.dao.IMdmModuleDbDao;
|
||||
import com.hzya.frame.mdm.mdmModuleDb.dao.impl.MdmModuleDbDaoImpl;
|
||||
import com.hzya.frame.mdm.mdmModuleDb.entity.MdmModuleDbEntity;
|
||||
|
@ -50,17 +61,24 @@ import com.hzya.frame.web.entity.BaseResult;
|
|||
import com.hzya.frame.web.entity.JsonResultEntity;
|
||||
import com.hzya.frame.web.exception.BaseSystemException;
|
||||
import org.checkerframework.checker.units.qual.A;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.hzya.frame.basedao.service.impl.BaseService;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 主数据模版(MdmModule)表服务实现类
|
||||
|
@ -2961,4 +2979,290 @@ public class MdmModuleServiceImpl extends BaseService<MdmModuleEntity, String> i
|
|||
List<MdmModuleDistributeEntity> list = mdmModuleDistributeDao.queryBase(entity);
|
||||
return BaseResult.getSuccessMessageEntity("获取分发设置成功", list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成导入模版
|
||||
*/
|
||||
@Override
|
||||
public void generateExcelTemplate(HttpServletResponse response) throws IOException {
|
||||
// 设置响应内容类型
|
||||
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||
response.setCharacterEncoding("utf-8");
|
||||
// 设置文件名,注意中文需要URLEncoder编码
|
||||
String fileName = URLEncoder.encode("表字段定义模版", "UTF-8").replaceAll("\\+", "%20");
|
||||
response.setHeader("Content-disposition", "attachment;filename*=utf-8''" + fileName + ".xlsx");
|
||||
// 准备模板的示例数据
|
||||
List<ExcelTemplateVO> demoData = new ArrayList<>(); //createTemplateDemoData()
|
||||
// 使用EasyExcel直接写入响应输出流
|
||||
EasyExcel.write(response.getOutputStream(), ExcelTemplateVO.class)
|
||||
.sheet("表字段定义模版")
|
||||
.doWrite(demoData);
|
||||
}
|
||||
|
||||
/*private List<ExcelTemplateVO> createTemplateDemoData() {
|
||||
List<ExcelTemplateVO> demoData = new ArrayList<>();
|
||||
ExcelTemplateVO demo = new ExcelTemplateVO();
|
||||
demo.setChName("用户ID");
|
||||
demo.setEnName("userId");
|
||||
demo.setFiledType("1"); // 对应BIGINT类型
|
||||
demo.setFiledLength("20");
|
||||
demo.setIsSysPk("Y");
|
||||
demo.setIsSysCode("Y");
|
||||
demo.setIsSysName("N");
|
||||
demo.setIsSysDate("N");
|
||||
demo.setTitle("用户ID");
|
||||
demo.setRow("6");
|
||||
demo.setWidth("100");
|
||||
demo.setType("input");
|
||||
demo.setRequired("true");
|
||||
demo.setDisabled("true");
|
||||
|
||||
demoData.add(demo);
|
||||
return demoData;
|
||||
}
|
||||
*/
|
||||
/**
|
||||
* 导入模版
|
||||
*/
|
||||
@Transactional
|
||||
@Override
|
||||
public List<MdmModuleDbFiledsEntity> importTemplateFile(MultipartFile file , ImportExcelVO importExcelVO) {
|
||||
// 校验文件合法性
|
||||
if (file == null || file.isEmpty()) {
|
||||
throw new IllegalArgumentException("导入文件不能为空");
|
||||
}
|
||||
// 校验文件格式
|
||||
String fileName = file.getOriginalFilename();
|
||||
if (fileName == null || (!fileName.endsWith(".xlsx") && !fileName.endsWith(".xls"))) {
|
||||
throw new IllegalArgumentException("请上传Excel格式文件");
|
||||
}
|
||||
// 表头数据
|
||||
List<List<String>> headerList = new ArrayList<>();
|
||||
// 用于存储内容数据
|
||||
List<ExcelTemplateVO> dataList = new ArrayList<>();
|
||||
List<MdmModuleDbFiledsEntity> resultEntities = new ArrayList<>();
|
||||
try (InputStream inputStream = file.getInputStream()) {
|
||||
// 使用EasyExcel读取文件
|
||||
EasyExcel.read(inputStream)
|
||||
.head(ExcelTemplateVO.class) // 指定映射的实体类
|
||||
.sheet(0) // 指定第一个sheet页
|
||||
.headRowNumber(1) // 表头行数(从1开始)
|
||||
.autoTrim(true)
|
||||
.registerReadListener(new AnalysisEventListener<ExcelTemplateVO>() {
|
||||
/**
|
||||
* 获取表头行数据
|
||||
*/
|
||||
@Override
|
||||
public void invokeHeadMap(Map<Integer, String> headMap, AnalysisContext context) {
|
||||
// 1. 转换表头为有序列表
|
||||
List<String> header = new ArrayList<>();
|
||||
// 获取最大列索引,确保顺序正确
|
||||
int maxColIndex = headMap.keySet().stream().mapToInt(Integer::intValue).max().orElse(-1);
|
||||
for (int i = 0; i <= maxColIndex; i++) {
|
||||
header.add(headMap.getOrDefault(i, "")); // 无数据的列填空
|
||||
}
|
||||
headerList.add(header);
|
||||
}
|
||||
/**
|
||||
* 每解析一行数据触发
|
||||
*/
|
||||
@Override
|
||||
public void invoke(ExcelTemplateVO data, AnalysisContext context) {
|
||||
// 空行直接跳过
|
||||
if (isRowEmpty(data)) {
|
||||
return;
|
||||
}
|
||||
// 数据校验
|
||||
validateData(data, context.readRowHolder().getRowIndex() + 1);
|
||||
dataList.add(data);
|
||||
}
|
||||
/**
|
||||
* 所有数据解析完成后触发
|
||||
*/
|
||||
@Override
|
||||
public void doAfterAllAnalysed(AnalysisContext context) {
|
||||
// 解析完成后的数据处理
|
||||
List<MdmModuleDbFiledsEntity> entities = processImportData(headerList, dataList, importExcelVO);
|
||||
if (entities != null) {
|
||||
resultEntities.addAll(entities);
|
||||
}
|
||||
}
|
||||
})
|
||||
.doRead(); // 执行读取操作
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("文件读取失败:" + e.getMessage(), e);
|
||||
}
|
||||
return resultEntities;
|
||||
}
|
||||
|
||||
private boolean isRowEmpty(ExcelTemplateVO data) {
|
||||
if(data == null) {
|
||||
return true;
|
||||
}
|
||||
return StringUtils.isEmpty(data.getChName() ) &&
|
||||
StringUtils.isEmpty(data.getFiledType()) &&
|
||||
StringUtils.isEmpty(data.getEnName()) ;
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入数据,新增字段
|
||||
* @param headerList
|
||||
* @param dataList
|
||||
*/
|
||||
private List<MdmModuleDbFiledsEntity> processImportData(List<List<String>> headerList, List<ExcelTemplateVO> dataList,ImportExcelVO importExcelVO) {
|
||||
// 获取表头列名
|
||||
List<String> headers = headerList.get(0);
|
||||
// 数据库字段数据
|
||||
List<MdmModuleDbFiledsEntity> entities = new ArrayList<>();
|
||||
for (ExcelTemplateVO data : dataList) {
|
||||
MdmModuleDbFiledsEntity entity = new MdmModuleDbFiledsEntity();
|
||||
BeanUtils.copyProperties(data, entity);
|
||||
// 字段规则数据集合
|
||||
List<MdmModuleDbFiledsRuleEntity> rules = new ArrayList<>();
|
||||
for (String header : headers) {
|
||||
// 字段规则数据
|
||||
MdmModuleDbFiledsRuleEntity rule = new MdmModuleDbFiledsRuleEntity();
|
||||
rule.setRuleType("2");
|
||||
rule.setFormName("optionRuleForm");
|
||||
switch (header) {
|
||||
case "显示名":
|
||||
rule.setRuleName("显示名");
|
||||
rule.setRuleCode("title");
|
||||
rule.setRuleValue(data.getChName());
|
||||
break;
|
||||
case "宽度":
|
||||
rule.setRuleName("宽度");
|
||||
rule.setRuleCode("row");
|
||||
rule.setRuleValue(data.getRow());
|
||||
break;
|
||||
case "单元格宽度":
|
||||
rule.setRuleName("单元格宽度");
|
||||
rule.setRuleCode("width");
|
||||
rule.setRuleValue(data.getWidth());
|
||||
break;
|
||||
case "数据类型":
|
||||
rule.setRuleName("数据类型");
|
||||
rule.setRuleCode("type");
|
||||
rule.setRuleValue(data.getType());
|
||||
break;
|
||||
case "必填":
|
||||
rule.setRuleName("必填");
|
||||
rule.setRuleCode("required");
|
||||
rule.setRuleValue(data.getRequired() != null ? "true" : "false");
|
||||
break;
|
||||
case "禁止修改":
|
||||
rule.setRuleName("禁止修改");
|
||||
rule.setRuleCode("disabled");
|
||||
rule.setRuleValue(data.getDisabled() != null ? "true" : "false");
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
rules.add(rule);
|
||||
}
|
||||
entity.setMdmModuleDbFiledsRules(rules);
|
||||
entity.setDbName(importExcelVO.getDbName());
|
||||
entity.setDbId(importExcelVO.getDbId());
|
||||
entity.setDbType(importExcelVO.getDbType());
|
||||
entity.setMdmId(importExcelVO.getMdmId());
|
||||
entities.add(entity);
|
||||
}
|
||||
return entities;
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据校验方法,验证Excel导入的数据合法性
|
||||
* @param data 导入的Excel数据对象
|
||||
* @param rowNum 行号
|
||||
*/
|
||||
private void validateData(ExcelTemplateVO data, int rowNum) {
|
||||
List<String> errors = new ArrayList<>();
|
||||
|
||||
// 1. 校验中文名称必填
|
||||
if (StringUtils.isBlank(data.getChName())) {
|
||||
errors.add("第" + rowNum + "行:中文名称不能为空");
|
||||
}
|
||||
|
||||
// 2. 校验字段类型合法性
|
||||
if (StringUtils.isBlank(data.getFiledType())) {
|
||||
errors.add("第" + rowNum + "行:字段类型不能为空");
|
||||
} else {
|
||||
Set<String> validTypes = new HashSet<>(Arrays.asList("1", "2", "3", "4"));
|
||||
if (!validTypes.contains(data.getFiledType())) {
|
||||
errors.add("第" + rowNum + "行:字段类型无效,允许值为1(BIGINT)、2(DECIMAL)、3(VARCHAR)、4(DATETIME)");
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 校验长度(数字类型且当字段类型为1、2、3时必填)
|
||||
if (StringUtils.isNotBlank(data.getFiledType()) &&
|
||||
(data.getFiledType().equals("1") || data.getFiledType().equals("2") || data.getFiledType().equals("3"))) {
|
||||
|
||||
if (StringUtils.isBlank(data.getFiledLength())) {
|
||||
errors.add("第" + rowNum + "行:字段长度不能为空");
|
||||
} else if (!StringUtils.isNumeric(data.getFiledLength())) {
|
||||
errors.add("第" + rowNum + "行:字段长度必须为数字");
|
||||
} else {
|
||||
int length = Integer.parseInt(data.getFiledLength());
|
||||
if (length <= 0) {
|
||||
errors.add("第" + rowNum + "行:字段长度必须大于0");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 4. 校验系统主键标识合法性
|
||||
if (StringUtils.isNotBlank(data.getIsSysPk()) &&
|
||||
!"Y".equals(data.getIsSysPk()) && !"N".equals(data.getIsSysPk())) {
|
||||
errors.add("第" + rowNum + "行:是否系统主键只能为Y或N");
|
||||
}
|
||||
|
||||
// 5. 校验系统数据编码标识合法性
|
||||
if (StringUtils.isNotBlank(data.getIsSysCode()) &&
|
||||
!"Y".equals(data.getIsSysCode()) && !"N".equals(data.getIsSysCode())) {
|
||||
errors.add("第" + rowNum + "行:是否系统数据编码只能为Y或N");
|
||||
}
|
||||
|
||||
// 6. 校验系统数据名称标识合法性
|
||||
if (StringUtils.isNotBlank(data.getIsSysName()) &&
|
||||
!"Y".equals(data.getIsSysName()) && !"N".equals(data.getIsSysName())) {
|
||||
errors.add("第" + rowNum + "行:是否系统数据名称只能为Y或N");
|
||||
}
|
||||
|
||||
// 7. 校验系统日期标识合法性
|
||||
if (StringUtils.isNotBlank(data.getIsSysDate()) &&
|
||||
!"Y".equals(data.getIsSysDate()) && !"N".equals(data.getIsSysDate())) {
|
||||
errors.add("第" + rowNum + "行:是否系统日期只能为Y或N");
|
||||
}
|
||||
|
||||
// 8. 校验是否必填标识合法性
|
||||
if (data.getRequired() != null && !data.getRequired().trim().isEmpty()) {
|
||||
String required = data.getRequired().trim();
|
||||
if (!"TRUE".equalsIgnoreCase(required) && !"FALSE".equalsIgnoreCase(required)) {
|
||||
errors.add("第" + rowNum + "行:是否必填只能为true或false");
|
||||
}
|
||||
}
|
||||
|
||||
// 9. 校验禁止修改标识合法性
|
||||
if (data.getDisabled() != null && !data.getDisabled().trim().isEmpty()) {
|
||||
String disabled = data.getDisabled().trim();
|
||||
if (!"TRUE".equalsIgnoreCase(disabled) && !"FALSE".equalsIgnoreCase(disabled)) {
|
||||
errors.add("第" + rowNum + "行:禁止修改只能为true或false");
|
||||
}
|
||||
}
|
||||
|
||||
// 如果有错误,抛出异常中断导入
|
||||
if (!errors.isEmpty()) {
|
||||
throw new ExcelDataValidateException(String.join(";", errors));
|
||||
}
|
||||
}
|
||||
|
||||
// 自定义异常类
|
||||
public class ExcelDataValidateException extends RuntimeException {
|
||||
public ExcelDataValidateException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
package com.hzya.frame.mdm.mdmModule.vo;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ExcelTemplateVO {
|
||||
|
||||
@ExcelProperty(value = "中文名称", index = 0)
|
||||
private String chName;
|
||||
|
||||
@ExcelProperty(value = "英文名称", index = 1)
|
||||
private String enName;
|
||||
|
||||
/** 字段类型 1、BIGINT 2、DECIMAL 3、VARCHAR 4、DATETIME */
|
||||
@ExcelProperty(value = "字段类型", index = 2)
|
||||
private String filedType;
|
||||
|
||||
@ExcelProperty(value = "长度", index = 3)
|
||||
private String filedLength;
|
||||
|
||||
@ExcelProperty(value = "是否系统主键", index = 4)
|
||||
private String isSysPk;// Y N
|
||||
|
||||
@ExcelProperty(value = "系统数据编码", index = 5)
|
||||
private String isSysCode;// Y N
|
||||
|
||||
@ExcelProperty(value = "系统数据名称", index = 6)
|
||||
private String isSysName;// Y N
|
||||
|
||||
@ExcelProperty(value = "系统日期", index = 7)
|
||||
private String isSysDate; // Y N
|
||||
|
||||
@ExcelProperty(value = "显示名", index = 8)
|
||||
private String title;
|
||||
|
||||
@ExcelProperty(value = "宽度", index = 9)
|
||||
private String row;
|
||||
|
||||
@ExcelProperty(value = "单元格宽度", index = 10)
|
||||
private String width;
|
||||
|
||||
@ExcelProperty(value = "数据类型",index = 11)
|
||||
private String type;
|
||||
|
||||
@ExcelProperty(value= "必填",index = 12)
|
||||
private String required; // true false
|
||||
|
||||
@ExcelProperty(value= "禁止修改",index = 13)
|
||||
private String disabled; // true false
|
||||
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package com.hzya.frame.mdm.mdmModule.vo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.checkerframework.checker.units.qual.A;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class ImportExcelVO {
|
||||
/** 主数据模版ID */
|
||||
private String dbName;
|
||||
/** 主数据模版ID */
|
||||
private String mdmId;
|
||||
/** 模版数据库id */
|
||||
private String dbId;
|
||||
/** 类型 1、主表 2、明细 3、操作日志 4、下发日志 */
|
||||
private String dbType;
|
||||
|
||||
// MultipartFile file;
|
||||
}
|
|
@ -1,7 +1,9 @@
|
|||
package com.hzya.frame.mdm.mdmModuleDbFileds.entity;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import com.hzya.frame.mdm.mdmModuleDb.entity.MdmModuleDbEntity;
|
||||
import com.hzya.frame.mdm.mdmModuleDbFiledsRule.entity.MdmModuleDbFiledsRuleEntity;
|
||||
import com.hzya.frame.web.entity.BaseEntity;
|
||||
|
@ -21,11 +23,14 @@ public class MdmModuleDbFiledsEntity extends BaseEntity {
|
|||
/** 模版数据库id */
|
||||
private String dbId;
|
||||
/** 中文名 */
|
||||
@ExcelProperty(value = "中文名称", index = 0)
|
||||
private String chName;
|
||||
/** 英文名 */
|
||||
private String enName;
|
||||
@ExcelProperty(value = "英文名称", index = 1)
|
||||
private String enName;
|
||||
/** 字段类型 1、BIGINT 2、DECIMAL 3、VARCHAR 4、DATETIME */
|
||||
private String filedType;
|
||||
@ExcelProperty(value = "字段类型", index = 2)
|
||||
private String filedType;
|
||||
/** 显示类型:新增 */
|
||||
private String addType;
|
||||
/** 显示类型:修改 */
|
||||
|
@ -34,12 +39,14 @@ public class MdmModuleDbFiledsEntity extends BaseEntity {
|
|||
private String showType;
|
||||
/** 显示类型:查询 */
|
||||
private String queryType;
|
||||
|
||||
/** 显示类型:列表 */
|
||||
private String listType;
|
||||
/** 显示类型:显示 */
|
||||
private String viewType;
|
||||
/** 长度 */
|
||||
private String filedLength;
|
||||
@ExcelProperty(value = "长度", index = 3)
|
||||
private String filedLength;
|
||||
/** 公司id */
|
||||
private String companyId;
|
||||
/** 数据类型 1、新增 2、修改 */
|
||||
|
@ -54,10 +61,30 @@ public class MdmModuleDbFiledsEntity extends BaseEntity {
|
|||
* roletype
|
||||
*/
|
||||
private String roleValue;
|
||||
private List<MdmModuleDbFiledsRuleEntity> mdmModuleDbFiledsRules;
|
||||
private List<MdmModuleDbFiledsRuleEntity> mdmModuleDbFiledsRules;
|
||||
|
||||
//1、查询2、列表3、新增4、修改 5、查看
|
||||
private String fieldType;
|
||||
/**
|
||||
* 是否sys主键 系统主键(三方系统主键,同步中台之后,该字段作为主键)Y/N
|
||||
*/
|
||||
@ExcelProperty(value = "是否系统主键", index = 4)
|
||||
private String isSysPk;
|
||||
/**
|
||||
* 是否sys编码 系统code(三方系统code,同步中台之后,该字段作为code)Y/N
|
||||
*/
|
||||
@ExcelProperty(value = "是否系统数据编码", index = 5)
|
||||
private String isSysCode;
|
||||
/**
|
||||
* 是否sys名称 系统name(三方系统name,同步中台之后,该字段作为name)Y/N
|
||||
*/
|
||||
@ExcelProperty(value = "是否系统数据名称", index = 6)
|
||||
private String isSysName;
|
||||
/**
|
||||
* 是否sys日期 系统date(三方系统name,同步中台之后,该字段作为name)Y/N
|
||||
*/
|
||||
@ExcelProperty(value = "是否系统日期", index = 7)
|
||||
private String isSysDate;
|
||||
public String getMdmId() {
|
||||
return mdmId;
|
||||
}
|
||||
|
@ -218,22 +245,7 @@ public class MdmModuleDbFiledsEntity extends BaseEntity {
|
|||
this.dbType = dbType;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否sys主键 系统主键(三方系统主键,同步中台之后,该字段作为主键)Y/N
|
||||
*/
|
||||
private String isSysPk;
|
||||
/**
|
||||
* 是否sys编码 系统code(三方系统code,同步中台之后,该字段作为code)Y/N
|
||||
*/
|
||||
private String isSysCode;
|
||||
/**
|
||||
* 是否sys名称 系统name(三方系统name,同步中台之后,该字段作为name)Y/N
|
||||
*/
|
||||
private String isSysName;
|
||||
/**
|
||||
* 是否sys名称 系统date(三方系统name,同步中台之后,该字段作为name)Y/N
|
||||
*/
|
||||
private String isSysDate;
|
||||
|
||||
|
||||
public String getIsSysPk() {
|
||||
return isSysPk;
|
||||
|
@ -292,5 +304,7 @@ public class MdmModuleDbFiledsEntity extends BaseEntity {
|
|||
public void setSublistMdmModuleDbFileds(List<MdmModuleDbFiledsEntity> sublistMdmModuleDbFileds) {
|
||||
this.sublistMdmModuleDbFileds = sublistMdmModuleDbFileds;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue