|
|
@ -1,18 +1,26 @@ |
|
|
|
package org.jeecg.modules.fieldx.controller; |
|
|
|
package org.jeecg.modules.fieldx.controller; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
|
|
|
import java.io.InputStream; |
|
|
|
|
|
|
|
import java.lang.reflect.Field; |
|
|
|
import java.util.*; |
|
|
|
import java.util.*; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.io.IOException; |
|
|
|
|
|
|
|
import java.io.UnsupportedEncodingException; |
|
|
|
|
|
|
|
import java.net.URLDecoder; |
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.ibatis.annotations.Param; |
|
|
|
import com.aliyuncs.utils.StringUtils; |
|
|
|
|
|
|
|
import org.apache.poi.hssf.usermodel.HSSFRow; |
|
|
|
|
|
|
|
import org.apache.poi.hssf.usermodel.HSSFSheet; |
|
|
|
|
|
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
|
|
|
|
|
|
|
import org.apache.poi.ss.usermodel.Row; |
|
|
|
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFRow; |
|
|
|
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFSheet; |
|
|
|
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
|
|
|
import org.jeecg.common.api.vo.Result; |
|
|
|
import org.jeecg.common.api.vo.Result; |
|
|
|
import org.jeecg.common.system.query.QueryGenerator; |
|
|
|
import org.jeecg.common.system.query.QueryGenerator; |
|
|
|
import org.jeecg.common.util.oConvertUtils; |
|
|
|
import org.jeecg.modules.fieldx.dto.ExcelInfo; |
|
|
|
import org.jeecg.modules.fieldx.entity.Fieldx; |
|
|
|
import org.jeecg.modules.fieldx.entity.Fieldx; |
|
|
|
|
|
|
|
import org.jeecg.modules.fieldx.entity.Fieldx222; |
|
|
|
|
|
|
|
import org.jeecg.modules.fieldx.service.IFieldx222Service; |
|
|
|
import org.jeecg.modules.fieldx.service.IFieldxService; |
|
|
|
import org.jeecg.modules.fieldx.service.IFieldxService; |
|
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
@ -22,18 +30,11 @@ import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
|
|
|
|
|
|
import org.jeecg.modules.tablex.entity.Tablex; |
|
|
|
import org.jeecg.modules.tablex.entity.Tablex; |
|
|
|
import org.jeecg.modules.tablex.service.ITablexService; |
|
|
|
import org.jeecg.modules.tablex.service.ITablexService; |
|
|
|
import org.jeecgframework.poi.excel.ExcelImportUtil; |
|
|
|
|
|
|
|
import org.jeecgframework.poi.excel.def.NormalExcelConstants; |
|
|
|
|
|
|
|
import org.jeecgframework.poi.excel.entity.ExportParams; |
|
|
|
|
|
|
|
import org.jeecgframework.poi.excel.entity.ImportParams; |
|
|
|
|
|
|
|
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.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
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.servlet.ModelAndView; |
|
|
|
import org.springframework.web.servlet.ModelAndView; |
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
|
|
|
|
import io.swagger.annotations.Api; |
|
|
|
import io.swagger.annotations.Api; |
|
|
|
import io.swagger.annotations.ApiOperation; |
|
|
|
import io.swagger.annotations.ApiOperation; |
|
|
|
import org.jeecg.common.aspect.annotation.AutoLog; |
|
|
|
import org.jeecg.common.aspect.annotation.AutoLog; |
|
|
@ -53,6 +54,8 @@ public class FieldxController extends JeecgController<Fieldx, IFieldxService> { |
|
|
|
private IFieldxService fieldxService; |
|
|
|
private IFieldxService fieldxService; |
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
private ITablexService tablexService; |
|
|
|
private ITablexService tablexService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
|
|
private IFieldx222Service fieldx222Service; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 分页列表查询 |
|
|
|
* 分页列表查询 |
|
|
@ -78,7 +81,6 @@ public class FieldxController extends JeecgController<Fieldx, IFieldxService> { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 通过实体查询字段 |
|
|
|
* 通过实体查询字段 |
|
|
|
* |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@AutoLog(value = "字段管理-通过实体查询字段") |
|
|
|
@AutoLog(value = "字段管理-通过实体查询字段") |
|
|
|
@ApiOperation(value = "字段管理-通过实体查询字段", notes = "字段管理-通过实体查询字段") |
|
|
|
@ApiOperation(value = "字段管理-通过实体查询字段", notes = "字段管理-通过实体查询字段") |
|
|
@ -280,6 +282,7 @@ public class FieldxController extends JeecgController<Fieldx, IFieldxService> { |
|
|
|
return super.exportXls(request, fieldx, Fieldx.class, "字段管理"); |
|
|
|
return super.exportXls(request, fieldx, Fieldx.class, "字段管理"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 通过excel导入数据 |
|
|
|
* 通过excel导入数据 |
|
|
|
* |
|
|
|
* |
|
|
@ -287,11 +290,134 @@ public class FieldxController extends JeecgController<Fieldx, IFieldxService> { |
|
|
|
* @param response |
|
|
|
* @param response |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@RequestMapping(value = "/importExcel", method = RequestMethod.POST) |
|
|
|
@PostMapping("/importExcel") |
|
|
|
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) { |
|
|
|
public Result<?> importExcel(@RequestPart MultipartFile file) throws Exception { |
|
|
|
return super.importExcel(request, response, Fieldx.class); |
|
|
|
if (file == null) { |
|
|
|
|
|
|
|
return Result.error("文件上传失败"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//判断格式
|
|
|
|
|
|
|
|
String path = file.getOriginalFilename(); |
|
|
|
|
|
|
|
if (!(path.endsWith(".xls") || path.endsWith(".xlsx"))) { |
|
|
|
|
|
|
|
return Result.error("文件格式上传有误"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//根据格式读取
|
|
|
|
|
|
|
|
List<Fieldx222> list = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (path.endsWith(".xls")) { |
|
|
|
|
|
|
|
list = readXLS(file); |
|
|
|
|
|
|
|
} else list = readXLSX(file); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fieldx222Service.saveBatch(list); |
|
|
|
|
|
|
|
List<Fieldx222> list222 = fieldx222Service.list(); |
|
|
|
|
|
|
|
if(list222==null) |
|
|
|
|
|
|
|
return Result.error("文件上传失败"); |
|
|
|
|
|
|
|
List<Fieldx> list1= list222.stream().map((item)->{ |
|
|
|
|
|
|
|
Fieldx fieldx=new Fieldx(); |
|
|
|
|
|
|
|
String id=item.getId(); |
|
|
|
|
|
|
|
fieldx.setTableId(item.getTableId()); |
|
|
|
|
|
|
|
fieldx.setFieldName(item.getFieldName()); |
|
|
|
|
|
|
|
fieldx.setFieldEnName(item.getFieldName()); |
|
|
|
|
|
|
|
fieldx.setType(Integer.valueOf(item.getType())); |
|
|
|
|
|
|
|
fieldx.setLength(Integer.valueOf(item.getLength())); |
|
|
|
|
|
|
|
fieldx.setIsPk(Integer.valueOf(item.getIsPk())); |
|
|
|
|
|
|
|
fieldx.setIsFk(Integer.valueOf(item.getIsFk())); |
|
|
|
|
|
|
|
fieldx.setIsNull(Integer.valueOf(item.getIsNull())); |
|
|
|
|
|
|
|
fieldx.setIsUniqueness(Integer.valueOf(item.getIsUniqueness())); |
|
|
|
|
|
|
|
fieldx.setVerisonStatus(Integer.valueOf(item.getVerisonStatus())); |
|
|
|
|
|
|
|
fieldx.setVerison(Integer.valueOf(item.getVerison())); |
|
|
|
|
|
|
|
if(!StringUtils.isEmpty(item.getAccuracy())) |
|
|
|
|
|
|
|
fieldx.setAccuracy(Integer.valueOf(item.getAccuracy())); |
|
|
|
|
|
|
|
if(!StringUtils.isEmpty(item.getFormat())) |
|
|
|
|
|
|
|
fieldx.setFormat(item.getFormat()); |
|
|
|
|
|
|
|
if(!StringUtils.isEmpty(item.getAssociateTable())) |
|
|
|
|
|
|
|
fieldx.setAssociateTable(item.getAssociateTable()); |
|
|
|
|
|
|
|
if(!StringUtils.isEmpty(item.getAssociateField())) |
|
|
|
|
|
|
|
fieldx.setAssociateField(item.getAssociateField()); |
|
|
|
|
|
|
|
if(!StringUtils.isEmpty(item.getRull())) |
|
|
|
|
|
|
|
fieldx.setRule(item.getRull()); |
|
|
|
|
|
|
|
return fieldx; |
|
|
|
|
|
|
|
}).collect(Collectors.toList()); |
|
|
|
|
|
|
|
fieldx222Service.remove(null); |
|
|
|
|
|
|
|
fieldxService.saveBatch(list1); |
|
|
|
|
|
|
|
return Result.OK("文件上传成功"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public List<Fieldx222> readXLS(MultipartFile file) throws IOException { |
|
|
|
|
|
|
|
List<Fieldx222> list=new ArrayList<>(); |
|
|
|
|
|
|
|
InputStream inputStream=file.getInputStream(); |
|
|
|
|
|
|
|
HSSFWorkbook workbook=new HSSFWorkbook(inputStream); |
|
|
|
|
|
|
|
//读取表
|
|
|
|
|
|
|
|
HSSFSheet hssfSheet=workbook.getSheetAt(0); |
|
|
|
|
|
|
|
for(int r=3;r<=hssfSheet.getLastRowNum();r++){ |
|
|
|
|
|
|
|
HSSFRow cells =hssfSheet.getRow(r); |
|
|
|
|
|
|
|
String cell=cells.getCell(0).getStringCellValue(); |
|
|
|
|
|
|
|
if(StringUtils.isEmpty(cell)){ |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
ExcelInfo excelInfo = new ExcelInfo(); |
|
|
|
|
|
|
|
excelInfo.setcells(cells); |
|
|
|
|
|
|
|
Fieldx222 fieldx=copy(excelInfo); |
|
|
|
|
|
|
|
list.add(fieldx); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return list; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public List<Fieldx222> readXLSX(MultipartFile file) throws IOException { |
|
|
|
|
|
|
|
List<Fieldx222> list=new ArrayList<>(); |
|
|
|
|
|
|
|
InputStream inputStream=file.getInputStream(); |
|
|
|
|
|
|
|
XSSFWorkbook workbook=new XSSFWorkbook(inputStream); |
|
|
|
|
|
|
|
//读取表
|
|
|
|
|
|
|
|
XSSFSheet hssfSheet=workbook.getSheetAt(0); |
|
|
|
|
|
|
|
for(int r=3;r<=hssfSheet.getLastRowNum();r++){ |
|
|
|
|
|
|
|
XSSFRow cells =hssfSheet.getRow(r); |
|
|
|
|
|
|
|
String cell=cells.getCell(0).getStringCellValue(); |
|
|
|
|
|
|
|
if(StringUtils.isEmpty(cell)){ |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
ExcelInfo excelInfo=new ExcelInfo(); |
|
|
|
|
|
|
|
excelInfo.setcells(cells); |
|
|
|
|
|
|
|
Fieldx222 fieldx=copy(excelInfo); |
|
|
|
|
|
|
|
list.add(fieldx); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return list; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
private Fieldx222 copy(ExcelInfo excelInfo){ |
|
|
|
|
|
|
|
Fieldx222 fieldx222=new Fieldx222(); |
|
|
|
|
|
|
|
if(pdNull(excelInfo.getTableId())||pdNull((excelInfo.getFieldName()))||pdNull((excelInfo.getFieldEnName()))|| |
|
|
|
|
|
|
|
pdNull((excelInfo.getType()))||pdNull((excelInfo.getLength()))||pdNull((excelInfo.getIsPk()))|| |
|
|
|
|
|
|
|
pdNull((excelInfo.getIsFk()))||pdNull((excelInfo.getIsNull()))||pdNull((excelInfo.getIsUniqueness()))|| |
|
|
|
|
|
|
|
pdNull((excelInfo.getVerison()))||pdNull((excelInfo.getVerison()))) |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
fieldx222.setTableId(excelInfo.getTableId()); |
|
|
|
|
|
|
|
fieldx222.setFieldName(excelInfo.getFieldName()); |
|
|
|
|
|
|
|
fieldx222.setFieldEnName(excelInfo.getFieldEnName()); |
|
|
|
|
|
|
|
fieldx222.setType(excelInfo.getType()); |
|
|
|
|
|
|
|
fieldx222.setLength(excelInfo.getLength()); |
|
|
|
|
|
|
|
fieldx222.setIsPk(excelInfo.getIsPk()); |
|
|
|
|
|
|
|
fieldx222.setIsFk(excelInfo.getIsFk()); |
|
|
|
|
|
|
|
fieldx222.setIsNull(excelInfo.getIsNull()); |
|
|
|
|
|
|
|
fieldx222.setIsUniqueness(excelInfo.getIsUniqueness()); |
|
|
|
|
|
|
|
fieldx222.setVerisonStatus(excelInfo.getVerisonStatus()); |
|
|
|
|
|
|
|
fieldx222.setVerison(excelInfo.getVerison()); |
|
|
|
|
|
|
|
if(!StringUtils.isEmpty(excelInfo.getAccuracy())) |
|
|
|
|
|
|
|
fieldx222.setAccuracy(excelInfo.getAccuracy()); |
|
|
|
|
|
|
|
if(!StringUtils.isEmpty(excelInfo.getFormat())) |
|
|
|
|
|
|
|
fieldx222.setFormat(excelInfo.getFormat()); |
|
|
|
|
|
|
|
if(!StringUtils.isEmpty(excelInfo.getAssociateTable())) |
|
|
|
|
|
|
|
fieldx222.setAssociateTable(excelInfo.getAssociateTable()); |
|
|
|
|
|
|
|
if(!StringUtils.isEmpty(excelInfo.getAssociateField())) |
|
|
|
|
|
|
|
fieldx222.setAssociateField(excelInfo.getAssociateField()); |
|
|
|
|
|
|
|
if(!StringUtils.isEmpty(excelInfo.getRule())) |
|
|
|
|
|
|
|
fieldx222.setRull(excelInfo.getRule()); |
|
|
|
|
|
|
|
return fieldx222; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public boolean pdNull(Object object){ |
|
|
|
|
|
|
|
if (object == null) |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 生成sql
|
|
|
|
// 生成sql
|
|
|
|
public String createSql(String tableId){ |
|
|
|
public String createSql(String tableId){ |
|
|
|