|
|
@ -1,5 +1,7 @@ |
|
|
|
package org.jeecg.modules.tablex.controller; |
|
|
|
package org.jeecg.modules.tablex.controller; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
|
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.*; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
@ -40,12 +42,16 @@ import org.jeecg.modules.tablex.vo.TablexVo; |
|
|
|
import org.jeecg.modules.tablex.ws.WebSocketUtils; |
|
|
|
import org.jeecg.modules.tablex.ws.WebSocketUtils; |
|
|
|
import org.jeecgframework.poi.excel.ExcelImportUtil; |
|
|
|
import org.jeecgframework.poi.excel.ExcelImportUtil; |
|
|
|
import org.jeecgframework.poi.excel.def.NormalExcelConstants; |
|
|
|
import org.jeecgframework.poi.excel.def.NormalExcelConstants; |
|
|
|
|
|
|
|
import org.jeecgframework.poi.excel.def.TemplateExcelConstants; |
|
|
|
import org.jeecgframework.poi.excel.entity.ExportParams; |
|
|
|
import org.jeecgframework.poi.excel.entity.ExportParams; |
|
|
|
import org.jeecgframework.poi.excel.entity.ImportParams; |
|
|
|
import org.jeecgframework.poi.excel.entity.ImportParams; |
|
|
|
|
|
|
|
import org.jeecgframework.poi.excel.entity.TemplateExportParams; |
|
|
|
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView; |
|
|
|
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView; |
|
|
|
import org.jeecg.common.system.base.controller.JeecgController; |
|
|
|
import org.jeecg.common.system.base.controller.JeecgController; |
|
|
|
|
|
|
|
import org.jeecgframework.poi.excel.view.JeecgTemplateExcelView; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.BeanUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
import org.springframework.web.multipart.MultipartFile; |
|
|
|
import org.springframework.web.multipart.MultipartHttpServletRequest; |
|
|
|
import org.springframework.web.multipart.MultipartHttpServletRequest; |
|
|
@ -86,6 +92,9 @@ public class TablexController extends JeecgController<Tablex, ITablexService> { |
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
private WebSocketUtils webSocketUtils; |
|
|
|
private WebSocketUtils webSocketUtils; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Value("${jeecg.wordPath}") |
|
|
|
|
|
|
|
private String wordPath; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 分页列表查询 |
|
|
|
* 分页列表查询 |
|
|
|
* |
|
|
|
* |
|
|
@ -291,7 +300,7 @@ public class TablexController extends JeecgController<Tablex, ITablexService> { |
|
|
|
if (StringUtils.isBlank(originalFilename) || |
|
|
|
if (StringUtils.isBlank(originalFilename) || |
|
|
|
(!originalFilename.endsWith("xls") && |
|
|
|
(!originalFilename.endsWith("xls") && |
|
|
|
!originalFilename.endsWith("xlsx"))) { |
|
|
|
!originalFilename.endsWith("xlsx"))) { |
|
|
|
message.put("isVisible", "false"); |
|
|
|
/* message.put("isVisible", "false");*/ |
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
return Result.error("文件格式不正确"); |
|
|
|
return Result.error("文件格式不正确"); |
|
|
|
} |
|
|
|
} |
|
|
@ -308,13 +317,13 @@ public class TablexController extends JeecgController<Tablex, ITablexService> { |
|
|
|
//读取excel数据
|
|
|
|
//读取excel数据
|
|
|
|
list = ExcelImportUtil.importExcel(file.getInputStream(), TablexVo.class, params); |
|
|
|
list = ExcelImportUtil.importExcel(file.getInputStream(), TablexVo.class, params); |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
message.put("isVisible", "false"); |
|
|
|
/* message.put("isVisible", "false");*/ |
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
return Result.error("文件读取失败"); |
|
|
|
return Result.error("文件读取失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
//判断文件中是否存在数据
|
|
|
|
//判断文件中是否存在数据
|
|
|
|
if (list == null || list.size() == 0) { |
|
|
|
if (list == null || list.size() == 0) { |
|
|
|
message.put("isVisible", "false"); |
|
|
|
/* message.put("isVisible", "false");*/ |
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
return Result.error("Excel数据为空"); |
|
|
|
return Result.error("Excel数据为空"); |
|
|
|
} |
|
|
|
} |
|
|
@ -323,36 +332,37 @@ public class TablexController extends JeecgController<Tablex, ITablexService> { |
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
for (TablexVo tablexVo : list) { |
|
|
|
for (TablexVo tablexVo : list) { |
|
|
|
//判断当前存入行是否为空值
|
|
|
|
//判断当前存入行是否为空值
|
|
|
|
if (tablexVo.getModuleId() == null && |
|
|
|
if (StringUtils.isBlank(tablexVo.getModuleId()) && |
|
|
|
tablexVo.getTableName() == null && |
|
|
|
StringUtils.isBlank(tablexVo.getTableName()) && |
|
|
|
tablexVo.getTableEnName() == null && |
|
|
|
StringUtils.isBlank(tablexVo.getTableEnName()) && |
|
|
|
tablexVo.getTableStructure() == null && |
|
|
|
StringUtils.isBlank(tablexVo.getTableStructure()) && |
|
|
|
tablexVo.getStructuralDiagram() == null && |
|
|
|
StringUtils.isBlank(tablexVo.getStructuralDiagram()) && |
|
|
|
tablexVo.getStatus() == null && |
|
|
|
StringUtils.isBlank(tablexVo.getStatus()) && |
|
|
|
tablexVo.getVerisonStatus() == null && |
|
|
|
StringUtils.isBlank(tablexVo.getVerisonStatus()) && |
|
|
|
tablexVo.getVerison() == null) continue; |
|
|
|
StringUtils.isBlank(tablexVo.getVerison())) { |
|
|
|
// 将总的记录数传递给前端
|
|
|
|
list.remove(tablexVo); |
|
|
|
message.put("records", String.valueOf(list.size())); |
|
|
|
continue; |
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//判断版本号长度
|
|
|
|
//判断版本号长度
|
|
|
|
String verison = tablexVo.getVerison(); |
|
|
|
String verison = tablexVo.getVerison(); |
|
|
|
if (verison.length() > 5) { |
|
|
|
if (verison.length() > 5) { |
|
|
|
message.put("isVisible", "false"); |
|
|
|
/* message.put("isVisible", "false");*/ |
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
return Result.error("预读入失败,版本号格式错误"); |
|
|
|
return Result.error("预读入失败,版本号格式错误"); |
|
|
|
} |
|
|
|
} |
|
|
|
//存入临时表中
|
|
|
|
//存入临时表中
|
|
|
|
tablexVoService.save(tablexVo); |
|
|
|
tablexVoService.save(tablexVo); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//从临时表中取出数据
|
|
|
|
//从临时表中取出数据
|
|
|
|
List<TablexVo> voList = tablexVoService.list(); |
|
|
|
List<TablexVo> voList = tablexVoService.list(); |
|
|
|
|
|
|
|
// 将总的记录数传递给前端
|
|
|
|
|
|
|
|
message.put("records", String.valueOf(voList.size())); |
|
|
|
|
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
//删除临时表中的数据
|
|
|
|
//删除临时表中的数据
|
|
|
|
tablexVoService.removeAll(voList); |
|
|
|
tablexVoService.removeAll(voList); |
|
|
|
|
|
|
|
|
|
|
|
if (voList.size() == 0) { |
|
|
|
if (voList.size() == 0) { |
|
|
|
message.put("isVisible", "false"); |
|
|
|
/* message.put("isVisible", "false");*/ |
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
return Result.error("导入失败,数据为空"); |
|
|
|
return Result.error("导入失败,数据为空"); |
|
|
|
} |
|
|
|
} |
|
|
@ -366,7 +376,7 @@ public class TablexController extends JeecgController<Tablex, ITablexService> { |
|
|
|
|
|
|
|
|
|
|
|
String moduleId = voList.get(i).getModuleId(); |
|
|
|
String moduleId = voList.get(i).getModuleId(); |
|
|
|
if (moduleId == null || moduleId.equals("")) { |
|
|
|
if (moduleId == null || moduleId.equals("")) { |
|
|
|
message.put("isVisible", "false"); |
|
|
|
/* message.put("isVisible", "false");*/ |
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
return Result.error("对应模块填写不能为空"); |
|
|
|
return Result.error("对应模块填写不能为空"); |
|
|
|
} |
|
|
|
} |
|
|
@ -374,7 +384,7 @@ public class TablexController extends JeecgController<Tablex, ITablexService> { |
|
|
|
queryWrapper.eq(Modulex::getId, moduleId); |
|
|
|
queryWrapper.eq(Modulex::getId, moduleId); |
|
|
|
Modulex modulex = modulexService.getOne(queryWrapper); |
|
|
|
Modulex modulex = modulexService.getOne(queryWrapper); |
|
|
|
if (modulex == null) { |
|
|
|
if (modulex == null) { |
|
|
|
message.put("isVisible", "false"); |
|
|
|
/* message.put("isVisible", "false");*/ |
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
return Result.error("对应模块填写错误"); |
|
|
|
return Result.error("对应模块填写错误"); |
|
|
|
} |
|
|
|
} |
|
|
@ -416,43 +426,70 @@ public class TablexController extends JeecgController<Tablex, ITablexService> { |
|
|
|
tablexService.saveSingleBatch(tablexList, loginUser, message); |
|
|
|
tablexService.saveSingleBatch(tablexList, loginUser, message); |
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
message.put("isVisible", "false"); |
|
|
|
/* message.put("isVisible", "false");*/ |
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
return Result.error("导入失败,第" + i + 1 + "行的版本号填写错误!"); |
|
|
|
return Result.error("导入失败,第" + i + 1 + "行的版本号填写错误!"); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
message.put("isVisible", "false"); |
|
|
|
/* message.put("isVisible", "false");*/ |
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
return Result.error("导入失败,第" + i + 1 + "行的版本状态填写错误!"); |
|
|
|
return Result.error("导入失败,第" + i + 1 + "行的版本状态填写错误!"); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
message.put("isVisible", "false"); |
|
|
|
/* message.put("isVisible", "false");*/ |
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
return Result.error("导入失败,第" + i + 1 + "行的实体状态填写错误!"); |
|
|
|
return Result.error("导入失败,第" + i + 1 + "行的实体状态填写错误!"); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
message.put("isVisible", "false"); |
|
|
|
/* message.put("isVisible", "false");*/ |
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
return Result.error("导入失败,第" + i + 1 + "行的英文名称填写错误!"); |
|
|
|
return Result.error("导入失败,第" + i + 1 + "行的英文名称填写错误!"); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
message.put("isVisible", "false"); |
|
|
|
/* message.put("isVisible", "false");*/ |
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
return Result.error("导入失败,第" + i + 1 + "行的中文名称填写错误!"); |
|
|
|
return Result.error("导入失败,第" + i + 1 + "行的中文名称填写错误!"); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
message.put("isVisible", "false"); |
|
|
|
/*message.put("isVisible", "false");*/ |
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
return Result.error("导入失败,第" + i + 1 + "行的对应模块填写错误!"); |
|
|
|
return Result.error("导入失败,第" + i + 1 + "行的对应模块填写错误!"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
message.put("isVisible", "false"); |
|
|
|
/* message.put("isVisible", "false");*/ |
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
return Result.error("文件导入失败"); |
|
|
|
return Result.error("文件导入失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
message.put("isVisible", "false"); |
|
|
|
/*message.put("isVisible", "false");*/ |
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
webSocketUtils.sendMessage(loginUser.getId(), message); |
|
|
|
return Result.ok("文件导入成功!"); |
|
|
|
return Result.ok("文件导入成功!"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//导出实体标准模板
|
|
|
|
|
|
|
|
@RequestMapping(value = "/templateExcel") |
|
|
|
|
|
|
|
public ModelAndView wbsExcelTemplate(HttpServletRequest request, HttpServletResponse response) { |
|
|
|
|
|
|
|
Map<String, Object> map = new HashMap<String, Object>(); |
|
|
|
|
|
|
|
//设置导出文件名称
|
|
|
|
|
|
|
|
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); |
|
|
|
|
|
|
|
Date date = new Date(System.currentTimeMillis()); |
|
|
|
|
|
|
|
String currTime = formatter.format(date); |
|
|
|
|
|
|
|
String fileName = currTime + "-" + "模板.xlsx"; |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
String url = getClass().getClassLoader().getResource("static").getPath(); |
|
|
|
|
|
|
|
// 模板存放地址 这里写的地址根本拿不到 在其他人的电脑上
|
|
|
|
|
|
|
|
String templateUrl = wordPath + File.separator + "实体表模板.xls"; |
|
|
|
|
|
|
|
TemplateExportParams params = new TemplateExportParams( |
|
|
|
|
|
|
|
templateUrl); |
|
|
|
|
|
|
|
ModelAndView mv = new ModelAndView(new JeecgTemplateExcelView()); |
|
|
|
|
|
|
|
mv.addObject(TemplateExcelConstants.FILE_NAME, fileName); |
|
|
|
|
|
|
|
mv.addObject(TemplateExcelConstants.PARAMS, params); |
|
|
|
|
|
|
|
// 添加模板参数
|
|
|
|
|
|
|
|
mv.addObject(TemplateExcelConstants.MAP_DATA, map); //data
|
|
|
|
|
|
|
|
return mv; |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
log.error("下载模板异常--》{}", e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|