parent
e1743ced68
commit
47c91bb061
|
@ -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);
|
||||
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue