diff --git a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/fieldx/controller/FieldxController.java b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/fieldx/controller/FieldxController.java index 865de2f..6a6b92d 100644 --- a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/fieldx/controller/FieldxController.java +++ b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/fieldx/controller/FieldxController.java @@ -44,6 +44,7 @@ import org.jeecgframework.poi.excel.entity.ExportParams; import org.jeecgframework.poi.excel.view.JeecgEntityExcelView; import org.jsoup.helper.StringUtil; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.servlet.ModelAndView; @@ -316,6 +317,7 @@ public class FieldxController extends JeecgController { * * @return */ + @Transactional @PostMapping("/importExcel") public Result importExcel(@RequestPart MultipartFile file) throws Exception { LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); @@ -389,6 +391,40 @@ public class FieldxController extends JeecgController { webSocketUtils.sendMessage(loginUser.getId(), message); List list = new ArrayList<>(); //获取excel的所有页 + HashSet zt = new HashSet<>(); + zt.add("0"); + zt.add("1"); + zt.add("9"); + HashSet sf = new HashSet<>(); + sf.add("0"); + sf.add("1"); + HashSet sjlx = new HashSet<>(); + sjlx.add("1"); + sjlx.add("2"); + sjlx.add("3"); + sjlx.add("4"); + sjlx.add("5"); + sjlx.add("6"); + sjlx.add("7"); + sjlx.add("8"); + sjlx.add("9"); + sjlx.add("10"); + sjlx.add("11"); + sjlx.add("12"); + sjlx.add("13"); + sjlx.add("14"); + sjlx.add("15"); + sjlx.add("16"); + sjlx.add("17"); + sjlx.add("18"); + sjlx.add("19"); + sjlx.add("20"); + sjlx.add("21"); + sjlx.add("22"); + sjlx.add("23"); + sjlx.add("24"); + sjlx.add("25"); + sjlx.add("26"); int numberofSheets= workbook.getNumberOfSheets(); for (int i=0;i< numberofSheets;i++) { @@ -406,10 +442,9 @@ public class FieldxController extends JeecgController { Fieldx222 fieldx222 = new Fieldx222(); if (StringUtil.isBlank(excelInfo.getTableId())) { message.put("isError", "true"); - message.put("status","序号为" + (r - 2) + "的”表名”不能为空"); - message.put("closeable","true"); + message.put("status","序号为" + (r - 2) + "的”表名”不能为空或是此表不存在"); webSocketUtils.sendMessage(loginUser.getId(), message); - return Result.error("序号为" + (r - 2) + "的表名不能为空"); + return Result.error("序号为" + (r - 2) + "的表名不能为空或是此表不纯在"); } fieldx222.setTableId(excelInfo.getTableId()); if (StringUtil.isBlank(excelInfo.getFieldName())) { @@ -435,15 +470,36 @@ public class FieldxController extends JeecgController { webSocketUtils.sendMessage(loginUser.getId(), message); return Result.error("序号为" + (r - 2) + "的数据类型不能为空"); } + else if(!sjlx.contains(excelInfo.getType())){ + message.put("isError", "true"); + message.put("status","序号为" + (r - 2) + "的”数据类型”输入格式不正确"); + message.put("closeable","true"); + webSocketUtils.sendMessage(loginUser.getId(), message); + return Result.error("序号为" + (r - 2) + "的数据类型输入格式不正确"); + } fieldx222.setType(excelInfo.getType()); if (StringUtil.isBlank(excelInfo.getIsPk())) { fieldx222.setIsPk("0"); } + else if(!sf.contains(excelInfo.getIsPk())){ + message.put("isError", "true"); + message.put("status","序号为" + (r - 2) + "的”是否主键”输入格式不正确"); + message.put("closeable","true"); + webSocketUtils.sendMessage(loginUser.getId(), message); + return Result.error("序号为" + (r - 2) + "的是否主键输入格式不正确"); + } fieldx222.setIsPk(excelInfo.getIsPk()); if (StringUtil.isBlank(excelInfo.getIsFk())) { fieldx222.setIsFk("0"); } + else if(!sf.contains(excelInfo.getIsFk())){ + message.put("isError", "true"); + message.put("status","序号为" + (r - 2) + "的”是否外键”输入格式不正确"); + message.put("closeable","true"); + webSocketUtils.sendMessage(loginUser.getId(), message); + return Result.error("序号为" + (r - 2) + "的是否外键输入格式不正确"); + } fieldx222.setIsFk(excelInfo.getIsFk()); if (StringUtil.isBlank(excelInfo.getIsNull())) { message.put("isError", "true"); @@ -452,7 +508,14 @@ public class FieldxController extends JeecgController { webSocketUtils.sendMessage(loginUser.getId(), message); return Result.error("序号为" + (r - 2) + "的是否为空不能为空"); } - fieldx222.setIsFk(excelInfo.getIsFk()); + else if(!sf.contains(excelInfo.getIsNull())){ + message.put("isError", "true"); + message.put("status","序号为" + (r - 2) + "的”是否为空”输入格式不正确"); + message.put("closeable","true"); + webSocketUtils.sendMessage(loginUser.getId(), message); + return Result.error("序号为" + (r - 2) + "的是否为空输入格式不正确"); + } + fieldx222.setIsNull(excelInfo.getIsNull()); if (StringUtil.isBlank(excelInfo.getIsUniqueness())) { message.put("isError", "true"); message.put("status","序号为" + (r - 2) + "的”是否重复”不能为空"); @@ -460,6 +523,13 @@ public class FieldxController extends JeecgController { webSocketUtils.sendMessage(loginUser.getId(), message); return Result.error("序号为" + (r - 2) + "的是否重复不能为空"); } + else if(!sf.contains(excelInfo.getIsUniqueness())){ + message.put("isError", "true"); + message.put("status","序号为" + (r - 2) + "的”是否重复”输入格式不正确"); + message.put("closeable","true"); + webSocketUtils.sendMessage(loginUser.getId(), message); + return Result.error("序号为" + (r - 2) + "的是否重复输入格式不正确"); + } fieldx222.setIsUniqueness(excelInfo.getIsUniqueness()); if (StringUtil.isBlank(excelInfo.getStatus())) { message.put("isError", "true"); @@ -468,6 +538,13 @@ public class FieldxController extends JeecgController { webSocketUtils.sendMessage(loginUser.getId(), message); return Result.error("序号为" + (r - 2) + "的”字段状态”不能为空"); } + else if(!zt.contains(excelInfo.getStatus())){ + message.put("isError", "true"); + message.put("status","序号为" + (r - 2) + "的”字段状态”输入格式不正确"); + message.put("closeable","true"); + webSocketUtils.sendMessage(loginUser.getId(), message); + return Result.error("序号为" + (r - 2) + "的字段状态输入格式不正确"); + } fieldx222.setStatus(excelInfo.getStatus()); if (StringUtil.isBlank(excelInfo.getVerisonStatus())) { message.put("isError", "true"); @@ -476,6 +553,13 @@ public class FieldxController extends JeecgController { webSocketUtils.sendMessage(loginUser.getId(), message); return Result.error("序号为" + (r - 2) + "的”版本状态”不能为空"); } + else if(!sf.contains(excelInfo.getVerisonStatus())){ + message.put("isError", "true"); + message.put("status","序号为" + (r - 2) + "的”版本状态”输入格式不正确"); + message.put("closeable","true"); + webSocketUtils.sendMessage(loginUser.getId(), message); + return Result.error("序号为" + (r - 2) + "的版本状态输入格式不正确"); + } fieldx222.setVerisonStatus(excelInfo.getVerisonStatus()); if (!StringUtils.isEmpty(excelInfo.getAccuracy())) diff --git a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/fieldx/dto/ExcelInfo.java b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/fieldx/dto/ExcelInfo.java index 9755ec6..d6d682d 100644 --- a/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/fieldx/dto/ExcelInfo.java +++ b/jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/fieldx/dto/ExcelInfo.java @@ -2,14 +2,18 @@ package org.jeecg.modules.fieldx.dto; import com.aliyuncs.utils.StringUtils; import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Table; import org.jeecg.modules.tablex.entity.Tablex; import org.jeecg.modules.tablex.service.impl.TablexServiceImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.data.redis.core.index.Indexed; import org.springframework.stereotype.Component; +import org.w3c.dom.stylesheets.LinkStyle; import javax.annotation.PostConstruct; +import java.util.List; + @Component public class ExcelInfo { private Row cells; @@ -31,7 +35,10 @@ public class ExcelInfo { System.out.println("value = ==================================" + value); if(StringUtils.isEmpty(value)) return null; - Tablex tablex=excelInfo.tablexService.query().eq("table_name",value).one(); + List list =excelInfo.tablexService.query().eq("table_name",value).list(); + if(list==null||list.size()==0) + return null; + Tablex tablex =list.get(0); if(tablex==null) return null; return tablex.getId();