导入字段

dev
itcast 1 year ago
parent 98aba13e5f
commit 375329445b
  1. 18
      ant-design-vue-jeecg/src/views/fieldx/FieldxList.vue
  2. 12
      ant-design-vue-jeecg/src/views/modulex/ModulexList.vue
  3. 608
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/fieldx/controller/FieldxController.java
  4. 176
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/fieldx/dto/ExcelInfo.java
  5. 91
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/fieldx/entity/Fieldx222.java
  6. 8
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/fieldx/mapper/Fieldx222Mapper.java
  7. 8
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/fieldx/service/IFieldx222Service.java
  8. 12
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/fieldx/service/impl/Fieldx222ServiceImpl.java
  9. 6
      jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/modulex/service/impl/ModulexServiceImpl.java

@ -30,18 +30,8 @@
@pageChange="handlePageChange"
@valueChange="valueChange"
@added="added">
<template v-slot:toolbarSuffix>
<a style="
background: #e6f7ff;
color: red;
position: relative;
border: 1px solid #91d5ff;
padding: 6px 300px 8px 31px;
border-radius: 5px;">
注意: 编辑后请点击保存按钮保存数据</a>
<!-- <a-button type="primary" icon="rollback" @click="fanHui()">返回</a-button>-->
<!-- <p style="color: red;font-size: 16px"></p>-->
</template>
<template v-slot:action="props">
<a @click="submitForm(props)">保存</a>
@ -70,7 +60,7 @@
import {filterObj} from '@/utils/util'
import moment from "dayjs";
import { httpAction, getAction } from '@/api/manage'
import axios from 'axios';
export default {
name: 'FieldxList',
mixins: [JeecgListMixin, mixinDevice],
@ -238,7 +228,7 @@
delete: "/fieldx/fieldx/delete",
deleteBatch: "/fieldx/fieldx/deleteBatch",
exportXlsUrl: "/fieldx/fieldx/exportXls",
importExcelUrl: "fieldx/fieldx/importExcel",
importExcelUrl: "/fieldx/fieldx/importExcel",
getFieldByTableId:"/fieldx/fieldx/getFieldByTableId",
},

@ -82,10 +82,13 @@
<a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="tablexImportExcelUrl" @change="handleImportExcel">
<a-button type="primary" icon="import">导入实体</a-button>
</a-upload>
<a-button type="primary" icon="import">导入字段</a-button>
<a-button @click="fanhui" type="primary" icon="rollback">返回</a-button>
<a-button type="primary" icon="download" @click="exportxsxl('模块,功能,规则表')">导出综合表</a-button>
<a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrlf" @change="handleImportExcel">
<a-button type="primary" icon="import">导入字段</a-button>
</a-upload>
</div>
<!-- table区域-begin -->
@ -197,7 +200,7 @@ import store from "@/store"
import { filterObj } from "@/utils/util"
import FieldxList from "@views/fieldx/FieldxList.vue"
import TablexList from "@views/tablex/TablexList.vue"
import axios from 'axios';
export default {
name: 'ModulexList',
mixins: [JeecgListMixin, mixinDevice],
@ -401,6 +404,8 @@ export default {
delete: "/modulex/modulex/delete",
deleteBatch: "/modulex/modulex/deleteBatch",
exportXlsUrl: "/modulex/modulex/exportXls",
importExcelUrlf: "fieldx/fieldx/importExcel",
importExcelUrl: "modulex/modulex/importExcel",
functionImportExcelUrl: "/functionx/functionx/importExcel",
tablexImportExcelUrl: "tablex/tablex/importExcel",
@ -427,6 +432,9 @@ export default {
importExcelUrl: function () {
return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
},
importExcelUrlf: function () {
return `${window._CONFIG['domianURL']}/${this.url.importExcelUrlf}`
},
// columnsdataIndex
checkColumn: function () {
return this.columns.map(item => item.title)

@ -1,18 +1,26 @@
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.stream.Collectors;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
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.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.Fieldx222;
import org.jeecg.modules.fieldx.service.IFieldx222Service;
import org.jeecg.modules.fieldx.service.IFieldxService;
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.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.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;
@ -49,251 +50,376 @@ import org.jeecg.common.aspect.annotation.AutoLog;
@RequestMapping("/fieldx/fieldx")
@Slf4j
public class FieldxController extends JeecgController<Fieldx, IFieldxService> {
@Autowired
private IFieldxService fieldxService;
@Autowired
private ITablexService tablexService;
/**
* 分页列表查询
*
* @param fieldx
* @param pageNo
* @param pageSize
* @param req
* @return
*/
@AutoLog(value = "字段管理-分页列表查询")
@ApiOperation(value="字段管理-分页列表查询", notes="字段管理-分页列表查询")
@GetMapping(value = "/list")
public Result<?> queryPageList(Fieldx fieldx,
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
HttpServletRequest req) {
QueryWrapper<Fieldx> queryWrapper = QueryGenerator.initQueryWrapper(fieldx, req.getParameterMap());
Page<Fieldx> page = new Page<Fieldx>(pageNo, pageSize);
IPage<Fieldx> pageList = fieldxService.page(page, queryWrapper);
return Result.OK(pageList);
}
@Autowired
private IFieldxService fieldxService;
@Autowired
private ITablexService tablexService;
@Autowired
private IFieldx222Service fieldx222Service;
/**
* 通过实体查询字段
* 分页列表查询
*
* @param fieldx
* @param pageNo
* @param pageSize
* @param req
* @return
*/
@AutoLog(value = "字段管理-分页列表查询")
@ApiOperation(value = "字段管理-分页列表查询", notes = "字段管理-分页列表查询")
@GetMapping(value = "/list")
public Result<?> queryPageList(Fieldx fieldx,
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
HttpServletRequest req) {
QueryWrapper<Fieldx> queryWrapper = QueryGenerator.initQueryWrapper(fieldx, req.getParameterMap());
Page<Fieldx> page = new Page<Fieldx>(pageNo, pageSize);
IPage<Fieldx> pageList = fieldxService.page(page, queryWrapper);
return Result.OK(pageList);
}
/**
* 通过实体查询字段
*/
@AutoLog(value = "字段管理-通过实体查询字段")
@ApiOperation(value="字段管理-通过实体查询字段", notes="字段管理-通过实体查询字段")
@ApiOperation(value = "字段管理-通过实体查询字段", notes = "字段管理-通过实体查询字段")
@GetMapping(value = "/getFieldByTableId")
public Result<?> getFieldByTableId(@RequestParam(name="tableId",required=true) String tableId) {
if (tableId != null){
List<Fieldx> fieldxList = fieldxService.list(new QueryWrapper<Fieldx>().eq("table_id", tableId));
ArrayList<HashMap> hashMaps = new ArrayList<>();
for (Fieldx fieldx:fieldxList){
HashMap<Object, Object> hashMap = new HashMap<>();
hashMap.put("text",fieldx.getFieldName());
hashMap.put("value",fieldx.getId());
hashMaps.add(hashMap);
}
return Result.OK(hashMaps);
}else return Result.error("未找到数据,请重试");
public Result<?> getFieldByTableId(@RequestParam(name = "tableId", required = true) String tableId) {
if (tableId != null) {
List<Fieldx> fieldxList = fieldxService.list(new QueryWrapper<Fieldx>().eq("table_id", tableId));
ArrayList<HashMap> hashMaps = new ArrayList<>();
for (Fieldx fieldx : fieldxList) {
HashMap<Object, Object> hashMap = new HashMap<>();
hashMap.put("text", fieldx.getFieldName());
hashMap.put("value", fieldx.getId());
hashMaps.add(hashMap);
}
return Result.OK(hashMaps);
} else return Result.error("未找到数据,请重试");
}
/**
* 添加
*
* @param fieldx
* @return
*/
@AutoLog(value = "字段管理-添加")
@ApiOperation(value="字段管理-添加", notes="字段管理-添加")
@PostMapping(value = "/add")
public Result<?> add(@RequestBody Fieldx fieldx) {
if(fieldx.getTableId() ==null){
return Result.error("未选择相应实体,添加失败");
}
if(fieldx.getFieldName() ==null){
return Result.error("未输入中文名称,添加失败");
}
if (fieldx.getFieldEnName() == null){
return Result.error("未输入英文名称,添加失败");
}
if (fieldx.getType() == null){
return Result.error("未选择数据类型,添加失败");
}
if (fieldx.getIsNull() == null){
return Result.error("未选择是否为空,添加失败");
}
if (fieldx.getIsUniqueness() == null){
return Result.error("未选择是否重复,添加失败");
}
if (fieldx.getStatus() == null){
return Result.error("未选择字段状态,添加失败");
}
if (fieldx.getVerisonStatus() == null){
return Result.error("未选择版本状态,添加失败");
}
fieldx.setVerison(1);
if (fieldx.getAssociateTable() != null && fieldx.getAssociateTable().equals(fieldx.getTableId())){
return Result.error("实体不能关联自身,添加失败");
}
if (fieldx.getTableId() != null){
List<Fieldx> fieldxList = fieldxService.list(new QueryWrapper<Fieldx>().eq("table_id", fieldx.getTableId()));
for (Fieldx fieldx1 : fieldxList){
if (fieldx1.getFieldName().equals(fieldx.getFieldName())){
return Result.error("添加失败,所属实体已有该中文名称");
}
if (fieldx1.getFieldEnName().equals(fieldx.getFieldEnName())){
return Result.error("添加失败,所属实体已有该英文名称");
}
if (fieldx.getIsPk() == 1 && fieldx1.getIsPk() == 1){
return Result.error("该实体已经有主键,添加失败");
}
}
}
fieldxService.save(fieldx);
/**
* 添加
*
* @param fieldx
* @return
*/
@AutoLog(value = "字段管理-添加")
@ApiOperation(value = "字段管理-添加", notes = "字段管理-添加")
@PostMapping(value = "/add")
public Result<?> add(@RequestBody Fieldx fieldx) {
if (fieldx.getTableId() == null) {
return Result.error("未选择相应实体,添加失败");
}
if (fieldx.getFieldName() == null) {
return Result.error("未输入中文名称,添加失败");
}
if (fieldx.getFieldEnName() == null) {
return Result.error("未输入英文名称,添加失败");
}
if (fieldx.getType() == null) {
return Result.error("未选择数据类型,添加失败");
}
if (fieldx.getIsNull() == null) {
return Result.error("未选择是否为空,添加失败");
}
if (fieldx.getIsUniqueness() == null) {
return Result.error("未选择是否重复,添加失败");
}
if (fieldx.getStatus() == null) {
return Result.error("未选择字段状态,添加失败");
}
if (fieldx.getVerisonStatus() == null) {
return Result.error("未选择版本状态,添加失败");
}
fieldx.setVerison(1);
if (fieldx.getAssociateTable() != null && fieldx.getAssociateTable().equals(fieldx.getTableId())) {
return Result.error("实体不能关联自身,添加失败");
}
if (fieldx.getTableId() != null) {
List<Fieldx> fieldxList = fieldxService.list(new QueryWrapper<Fieldx>().eq("table_id", fieldx.getTableId()));
for (Fieldx fieldx1 : fieldxList) {
if (fieldx1.getFieldName().equals(fieldx.getFieldName())) {
return Result.error("添加失败,所属实体已有该中文名称");
}
if (fieldx1.getFieldEnName().equals(fieldx.getFieldEnName())) {
return Result.error("添加失败,所属实体已有该英文名称");
}
if (fieldx.getIsPk() == 1 && fieldx1.getIsPk() == 1) {
return Result.error("该实体已经有主键,添加失败");
}
}
}
fieldxService.save(fieldx);
// 更新table版本
Tablex tablex = tablexService.getById(fieldx.getTableId());
tablexService.updateVersion(fieldx.getTableId(),tablex.getVerison()+1);
tablexService.updateSql(fieldx.getTableId(),createSql(fieldx.getTableId()));
return Result.OK("添加成功!");
}
/**
* 编辑
*
* @param fieldx
* @return
*/
@AutoLog(value = "字段管理-编辑")
@ApiOperation(value="字段管理-编辑", notes="字段管理-编辑")
@PutMapping(value = "/edit")
public Result<?> edit(@RequestBody Fieldx fieldx) {
if(fieldx.getFieldName() ==null){
return Result.error("未输入中文名称,编辑失败");
}
if (fieldx.getFieldEnName() == null){
return Result.error("未输入英文名称,编辑失败");
}
if (fieldx.getType() == null){
return Result.error("未选择数据类型,编辑失败");
}
if (fieldx.getIsNull() == null){
return Result.error("未选择是否为空,编辑失败");
}
if (fieldx.getIsUniqueness() == null){
return Result.error("未选择是否重复,编辑失败");
}
if (fieldx.getStatus() == null){
return Result.error("未选择字段状态,编辑失败");
}
if (fieldx.getVerisonStatus() == null){
return Result.error("未选择版本状态,编辑失败");
}
if (fieldx.getAssociateTable() != null && fieldx.getAssociateTable().equals(fieldx.getTableId())){
return Result.error("实体不能关联自身,编辑失败");
}
if (fieldx.getTableId() != null){
List<Fieldx> fieldxList = fieldxService.list(new QueryWrapper<Fieldx>().eq("table_id", fieldx.getTableId()).ne("id",fieldx.getId()));
for (Fieldx fieldx1 : fieldxList){
if (fieldx1.getFieldName().equals(fieldx.getFieldName())){
return Result.error("编辑失败,所属实体已有该中文名称");
}
if (fieldx1.getFieldEnName().equals(fieldx.getFieldEnName())){
return Result.error("编辑失败,所属实体已有该英文名称");
}
if (fieldx.getIsPk() == 1 && fieldx1.getIsPk() == 1){
return Result.error("该实体已经有主键,编辑失败");
}
}
}
fieldxService.updateById(fieldx);
Tablex tablex = tablexService.getById(fieldx.getTableId());
tablexService.updateVersion(fieldx.getTableId(), tablex.getVerison() + 1);
tablexService.updateSql(fieldx.getTableId(), createSql(fieldx.getTableId()));
return Result.OK("添加成功!");
}
/**
* 编辑
*
* @param fieldx
* @return
*/
@AutoLog(value = "字段管理-编辑")
@ApiOperation(value = "字段管理-编辑", notes = "字段管理-编辑")
@PutMapping(value = "/edit")
public Result<?> edit(@RequestBody Fieldx fieldx) {
if (fieldx.getFieldName() == null) {
return Result.error("未输入中文名称,编辑失败");
}
if (fieldx.getFieldEnName() == null) {
return Result.error("未输入英文名称,编辑失败");
}
if (fieldx.getType() == null) {
return Result.error("未选择数据类型,编辑失败");
}
if (fieldx.getIsNull() == null) {
return Result.error("未选择是否为空,编辑失败");
}
if (fieldx.getIsUniqueness() == null) {
return Result.error("未选择是否重复,编辑失败");
}
if (fieldx.getStatus() == null) {
return Result.error("未选择字段状态,编辑失败");
}
if (fieldx.getVerisonStatus() == null) {
return Result.error("未选择版本状态,编辑失败");
}
if (fieldx.getAssociateTable() != null && fieldx.getAssociateTable().equals(fieldx.getTableId())) {
return Result.error("实体不能关联自身,编辑失败");
}
if (fieldx.getTableId() != null) {
List<Fieldx> fieldxList = fieldxService.list(new QueryWrapper<Fieldx>().eq("table_id", fieldx.getTableId()).ne("id", fieldx.getId()));
for (Fieldx fieldx1 : fieldxList) {
if (fieldx1.getFieldName().equals(fieldx.getFieldName())) {
return Result.error("编辑失败,所属实体已有该中文名称");
}
if (fieldx1.getFieldEnName().equals(fieldx.getFieldEnName())) {
return Result.error("编辑失败,所属实体已有该英文名称");
}
if (fieldx.getIsPk() == 1 && fieldx1.getIsPk() == 1) {
return Result.error("该实体已经有主键,编辑失败");
}
}
}
fieldxService.updateById(fieldx);
// 更新table版本
Tablex tablex = tablexService.getById(fieldx.getTableId());
tablexService.updateVersion(fieldx.getTableId(),tablex.getVerison()+1);
tablexService.updateSql(fieldx.getTableId(),createSql(fieldx.getTableId()));
return Result.OK("编辑成功!");
}
/**
* 通过id删除
*
* @param id
* @return
*/
@AutoLog(value = "字段管理-通过id删除")
@ApiOperation(value="字段管理-通过id删除", notes="字段管理-通过id删除")
@DeleteMapping(value = "/delete")
public Result<?> delete(@RequestParam(name="id",required=true) String id) {
List<Fieldx> fieldxList = fieldxService.list(new QueryWrapper<Fieldx>().eq("associate_field", id));
if (!fieldxList.isEmpty()){
return Result.error("该字段已被关联,不能删除");
}
Fieldx fieldx = fieldxService.getById(id);
fieldxService.removeById(id);
Tablex tablex = tablexService.getById(fieldx.getTableId());
tablexService.updateVersion(fieldx.getTableId(), tablex.getVerison() + 1);
tablexService.updateSql(fieldx.getTableId(), createSql(fieldx.getTableId()));
return Result.OK("编辑成功!");
}
/**
* 通过id删除
*
* @param id
* @return
*/
@AutoLog(value = "字段管理-通过id删除")
@ApiOperation(value = "字段管理-通过id删除", notes = "字段管理-通过id删除")
@DeleteMapping(value = "/delete")
public Result<?> delete(@RequestParam(name = "id", required = true) String id) {
List<Fieldx> fieldxList = fieldxService.list(new QueryWrapper<Fieldx>().eq("associate_field", id));
if (!fieldxList.isEmpty()) {
return Result.error("该字段已被关联,不能删除");
}
Fieldx fieldx = fieldxService.getById(id);
fieldxService.removeById(id);
// 更新sql语句
tablexService.updateSql(fieldx.getTableId(),createSql(fieldx.getTableId()));
return Result.OK("删除成功!");
}
/**
* 批量删除
*
* @param ids
* @return
*/
@AutoLog(value = "字段管理-批量删除")
@ApiOperation(value="字段管理-批量删除", notes="字段管理-批量删除")
@DeleteMapping(value = "/deleteBatch")
public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
this.fieldxService.removeByIds(Arrays.asList(ids.split(",")));
Fieldx fieldx = fieldxService.getById(ids.split(",")[0]);
tablexService.updateSql(fieldx.getTableId(),createSql(fieldx.getTableId()));
return Result.OK("批量删除成功!");
}
/**
* 通过id查询
*
* @param id
* @return
*/
@AutoLog(value = "字段管理-通过id查询")
@ApiOperation(value="字段管理-通过id查询", notes="字段管理-通过id查询")
@GetMapping(value = "/queryById")
public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
Fieldx fieldx = fieldxService.getById(id);
if(fieldx==null) {
return Result.error("未找到对应数据");
}
return Result.OK(fieldx);
}
tablexService.updateSql(fieldx.getTableId(), createSql(fieldx.getTableId()));
return Result.OK("删除成功!");
}
/**
* 导出excel
*
* @param request
* @param fieldx
*/
@RequestMapping(value = "/exportXls")
public ModelAndView exportXls(HttpServletRequest request, Fieldx fieldx) {
return super.exportXls(request, fieldx, Fieldx.class, "字段管理");
}
/**
* 批量删除
*
* @param ids
* @return
*/
@AutoLog(value = "字段管理-批量删除")
@ApiOperation(value = "字段管理-批量删除", notes = "字段管理-批量删除")
@DeleteMapping(value = "/deleteBatch")
public Result<?> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
this.fieldxService.removeByIds(Arrays.asList(ids.split(",")));
Fieldx fieldx = fieldxService.getById(ids.split(",")[0]);
tablexService.updateSql(fieldx.getTableId(), createSql(fieldx.getTableId()));
return Result.OK("批量删除成功!");
}
/**
* 通过excel导入数据
*
* @param request
* @param response
* @return
*/
@RequestMapping(value = "/importExcel", method = RequestMethod.POST)
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
return super.importExcel(request, response, Fieldx.class);
}
/**
* 通过id查询
*
* @param id
* @return
*/
@AutoLog(value = "字段管理-通过id查询")
@ApiOperation(value = "字段管理-通过id查询", notes = "字段管理-通过id查询")
@GetMapping(value = "/queryById")
public Result<?> queryById(@RequestParam(name = "id", required = true) String id) {
Fieldx fieldx = fieldxService.getById(id);
if (fieldx == null) {
return Result.error("未找到对应数据");
}
return Result.OK(fieldx);
}
/**
* 导出excel
*
* @param request
* @param fieldx
*/
@RequestMapping(value = "/exportXls")
public ModelAndView exportXls(HttpServletRequest request, Fieldx fieldx) {
return super.exportXls(request, fieldx, Fieldx.class, "字段管理");
}
/**
* 通过excel导入数据
*
* @param request
* @param response
* @return
*/
@PostMapping("/importExcel")
public Result<?> importExcel(@RequestPart MultipartFile file) throws Exception {
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){
Tablex tablex = tablexService.getById(tableId);
String tableEnName = tablex.getTableEnName();

@ -0,0 +1,176 @@
package org.jeecg.modules.fieldx.dto;
import com.aliyuncs.utils.StringUtils;
import org.apache.poi.ss.usermodel.Row;
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 javax.annotation.PostConstruct;
@Component
public class ExcelInfo {
private Row cells;
@Autowired
private TablexServiceImpl tablexService;
public void setcells(Row cells){
this.cells = cells;
}
public static ExcelInfo excelInfo;
@PostConstruct
public void init(){
excelInfo=this;
excelInfo.tablexService=this.tablexService;
}
public String getTableId(){
String value=cells.getCell(1).getStringCellValue();
System.out.println("value = ==================================" + value);
if(StringUtils.isEmpty(value))
return null;
Tablex tablex=excelInfo.tablexService.query().eq("table_name",value).one();
if(tablex==null)
return null;
return tablex.getId();
}
public String getFieldName(){
String value=cells.getCell(2).getStringCellValue();
return getvalue(value);
}
public String getFieldEnName(){
String value=cells.getCell(3).getStringCellValue();
return getvalue(value);
}
public String getType(){
String value=cells.getCell(4).getStringCellValue();
return getvalue(value);
}
public String getLength(){
String value=cells.getCell(5).getStringCellValue();
return getvalue(value);
}
public String getAccuracy(){
String value=cells.getCell(6).getStringCellValue();
return getvalue(value);
}
public String getFormat(){
String value=cells.getCell(7).getStringCellValue();
return getvalue(value);
}
public String getIsPk(){
String value=cells.getCell(8).getStringCellValue();
return getvalue(value);
}
public String getIsFk(){
String value=cells.getCell(9).getStringCellValue();
return getvalue(value);
}
public String getAssociateTable(){
String value=cells.getCell(10).getStringCellValue();
return getvalue(value);
}
public String getAssociateField(){
String value=cells.getCell(11).getStringCellValue();
return getvalue(value);
}
public String getIsNull(){
String value=cells.getCell(12).getStringCellValue();
return getvalue(value);
}
public String getIsUniqueness(){
String value=cells.getCell(13).getStringCellValue();
return getvalue(value);
}
public String getRule(){
String value=cells.getCell(14).getStringCellValue();
return getvalue(value);
}
public String getVerisonStatus(){
String value=cells.getCell(15).getStringCellValue();
return getvalue(value);
}
public String getVerison(){
String value=cells.getCell(16).getStringCellValue();
return getvalue(value);
}
private String getvalue(String value){
if(StringUtils.isEmpty(value))
return null;
if(value.equals("否")||value.equals("历史")||value.equals("停用"))
return "0";
if(value.equals("是")|| value.equals("正常")||value.equals("当前")||value.equals("TINYINT"))
return "1";
if(value.equals("SMALLINT"))
return "2";
if(value.equals("MEDIUMINT")||value.equals("废弃"))
return "3";
if(value.equals("INT"))
return "4";
if(value.equals("BIGINT"))
return "5";
if(value.equals("FLOAT"))
return "6";
if(value.equals("DOUBLE"))
return "7";
if(value.equals("DECIMAL"))
return "8";
if(value.equals("YEAR"))
return "9";
if(value.equals("TIME"))
return "10";
if(value.equals("DATE"))
return "11";
if(value.equals("DATETIME"))
return "12";
if(value.equals("TIMESTAMP"))
return "13";
if(value.equals("CHAR"))
return "14";
if(value.equals("VARCHAR"))
return "15";
if(value.equals("BINARY"))
return "16";
if(value.equals("VARBINARY"))
return "17";
if(value.equals("BLOB"))
return "18";
if(value.equals("TEXT"))
return "19";
if(value.equals("ENUM"))
return "20";
if(value.equals("SET"))
return "21";
if(value.equals("BIT"))
return "22";
if(value.equals("TINYBLOB"))
return "23";
if(value.equals("BLOB"))
return "24";
if(value.equals("MEDIUMBLOB"))
return "25";
if(value.equals("LONGBLOB"))
return "26";
return value;
}
}

@ -0,0 +1,91 @@
package org.jeecg.modules.fieldx.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.jeecg.common.aspect.annotation.Dict;
import org.jeecgframework.poi.excel.annotation.Excel;
import java.io.Serializable;
@Data
@TableName("fieldx222")
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
public class Fieldx222 implements Serializable {
private static final long serialVersionUID = 1L;
/**主键*/
@TableId(type = IdType.ASSIGN_ID)
@ApiModelProperty(value = "主键")
private java.lang.String id;
/**对应实体id*/
@Excel(name = "对应实体id", width = 15,dictTable="tablex",dicText = "table_name",dicCode = "id")
@ApiModelProperty(value = "对应实体")
private java.lang.String tableId;
/**中文名称*/
@Excel(name = "中文名称", width = 15)
@ApiModelProperty(value = "中文名称")
private java.lang.String fieldName;
/**英文名称*/
@Excel(name = "英文名称", width = 15)
@ApiModelProperty(value = "英文名称")
private java.lang.String fieldEnName;
/**数据类型*/
@Excel(name = "数据类型", width = 15, dicCode = "date_type")
@ApiModelProperty(value = "数据类型")
private java.lang.String type;
/**数据长度*/
@Excel(name = "数据长度", width = 15)
@ApiModelProperty(value = "数据长度")
private java.lang.String length;
/**浮点精度*/
@Excel(name = "浮点精度", width = 15)
@ApiModelProperty(value = "浮点精度")
private java.lang.String accuracy;
/**显示形式*/
@Excel(name = "显示形式", width = 15)
@ApiModelProperty(value = "显示形式")
private java.lang.String format;
/**是否主键*/
@Excel(name = "是否主键", width = 15,dicCode = "yn")
@ApiModelProperty(value = "是否主键")
private java.lang.String isPk;
/**是否外键*/
@Excel(name = "是否外键", width = 15,dicCode = "yn")
@ApiModelProperty(value = "是否外键")
private java.lang.String isFk;
/**关联实体*/
@Excel(name = "关联实体", width = 15)
@ApiModelProperty(value = "关联实体")
private java.lang.String associateTable;
/**关联字段*/
@Excel(name = "关联字段", width = 15)
@ApiModelProperty(value = "关联字段")
private java.lang.String associateField;
/**是否为空*/
@Excel(name = "是否为空", width = 15,dicCode = "yn")
@ApiModelProperty(value = "是否为空")
private java.lang.String isNull;
/**是否重复*/
@Excel(name = "是否重复", width = 15,dicCode = "yn")
@ApiModelProperty(value = "是否重复")
private java.lang.String isUniqueness;
/**字段规则*/
@Excel(name = "字段规则", width = 15)
@ApiModelProperty(value = "字段规则")
private java.lang.String rull;
/**版本状态*/
@Excel(name = "版本状态", width = 15 ,dicCode = "verison_status")
@ApiModelProperty(value = "版本状态")
private java.lang.String verisonStatus;
/**版本号*/
@Excel(name = "版本号", width = 15)
@ApiModelProperty(value = "版本号")
private java.lang.String verison;
}

@ -0,0 +1,8 @@
package org.jeecg.modules.fieldx.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.jeecg.modules.fieldx.entity.Fieldx222;
@Mapper
public interface Fieldx222Mapper extends BaseMapper<Fieldx222> {
}

@ -0,0 +1,8 @@
package org.jeecg.modules.fieldx.service;
import com.baomidou.mybatisplus.extension.service.IService;
import org.jeecg.modules.fieldx.entity.Fieldx;
import org.jeecg.modules.fieldx.entity.Fieldx222;
public interface IFieldx222Service extends IService<Fieldx222> {
}

@ -0,0 +1,12 @@
package org.jeecg.modules.fieldx.service.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.fieldx.entity.Fieldx222;
import org.jeecg.modules.fieldx.mapper.Fieldx222Mapper;
import org.jeecg.modules.fieldx.service.IFieldx222Service;
import org.springframework.stereotype.Service;
@Service
public class Fieldx222ServiceImpl extends ServiceImpl<Fieldx222Mapper, Fieldx222> implements IFieldx222Service {
}

@ -101,11 +101,9 @@ public class ModulexServiceImpl extends ServiceImpl<ModulexMapper, Modulex> impl
@Autowired
private IProjectxService projectxService;
@Autowired
private ISysRoleService iSysRoleService;
@Autowired
private ISysUserService iSysUserService;
/**
* 得到最大的版本号

Loading…
Cancel
Save