|
|
@ -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; |
|
|
@ -49,251 +50,376 @@ import org.jeecg.common.aspect.annotation.AutoLog; |
|
|
|
@RequestMapping("/fieldx/fieldx") |
|
|
|
@RequestMapping("/fieldx/fieldx") |
|
|
|
@Slf4j |
|
|
|
@Slf4j |
|
|
|
public class FieldxController extends JeecgController<Fieldx, IFieldxService> { |
|
|
|
public class FieldxController extends JeecgController<Fieldx, IFieldxService> { |
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
private IFieldxService fieldxService; |
|
|
|
private IFieldxService fieldxService; |
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
private ITablexService tablexService; |
|
|
|
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); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 通过实体查询字段 |
|
|
|
* 分页列表查询 |
|
|
|
* |
|
|
|
* |
|
|
|
|
|
|
|
* @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 = "字段管理-通过实体查询字段") |
|
|
|
@AutoLog(value = "字段管理-通过实体查询字段") |
|
|
|
@ApiOperation(value="字段管理-通过实体查询字段", notes="字段管理-通过实体查询字段") |
|
|
|
@ApiOperation(value = "字段管理-通过实体查询字段", notes = "字段管理-通过实体查询字段") |
|
|
|
@GetMapping(value = "/getFieldByTableId") |
|
|
|
@GetMapping(value = "/getFieldByTableId") |
|
|
|
public Result<?> getFieldByTableId(@RequestParam(name="tableId",required=true) String tableId) { |
|
|
|
public Result<?> getFieldByTableId(@RequestParam(name = "tableId", required = true) String tableId) { |
|
|
|
if (tableId != null){ |
|
|
|
if (tableId != null) { |
|
|
|
List<Fieldx> fieldxList = fieldxService.list(new QueryWrapper<Fieldx>().eq("table_id", tableId)); |
|
|
|
List<Fieldx> fieldxList = fieldxService.list(new QueryWrapper<Fieldx>().eq("table_id", tableId)); |
|
|
|
ArrayList<HashMap> hashMaps = new ArrayList<>(); |
|
|
|
ArrayList<HashMap> hashMaps = new ArrayList<>(); |
|
|
|
for (Fieldx fieldx:fieldxList){ |
|
|
|
for (Fieldx fieldx : fieldxList) { |
|
|
|
HashMap<Object, Object> hashMap = new HashMap<>(); |
|
|
|
HashMap<Object, Object> hashMap = new HashMap<>(); |
|
|
|
hashMap.put("text",fieldx.getFieldName()); |
|
|
|
hashMap.put("text", fieldx.getFieldName()); |
|
|
|
hashMap.put("value",fieldx.getId()); |
|
|
|
hashMap.put("value", fieldx.getId()); |
|
|
|
hashMaps.add(hashMap); |
|
|
|
hashMaps.add(hashMap); |
|
|
|
} |
|
|
|
} |
|
|
|
return Result.OK(hashMaps); |
|
|
|
return Result.OK(hashMaps); |
|
|
|
}else return Result.error("未找到数据,请重试"); |
|
|
|
} else return Result.error("未找到数据,请重试"); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 添加 |
|
|
|
* 添加 |
|
|
|
* |
|
|
|
* |
|
|
|
* @param fieldx |
|
|
|
* @param fieldx |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@AutoLog(value = "字段管理-添加") |
|
|
|
@AutoLog(value = "字段管理-添加") |
|
|
|
@ApiOperation(value="字段管理-添加", notes="字段管理-添加") |
|
|
|
@ApiOperation(value = "字段管理-添加", notes = "字段管理-添加") |
|
|
|
@PostMapping(value = "/add") |
|
|
|
@PostMapping(value = "/add") |
|
|
|
public Result<?> add(@RequestBody Fieldx fieldx) { |
|
|
|
public Result<?> add(@RequestBody Fieldx fieldx) { |
|
|
|
if(fieldx.getTableId() ==null){ |
|
|
|
if (fieldx.getTableId() == null) { |
|
|
|
return Result.error("未选择相应实体,添加失败"); |
|
|
|
return Result.error("未选择相应实体,添加失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
if(fieldx.getFieldName() ==null){ |
|
|
|
if (fieldx.getFieldName() == null) { |
|
|
|
return Result.error("未输入中文名称,添加失败"); |
|
|
|
return Result.error("未输入中文名称,添加失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (fieldx.getFieldEnName() == null){ |
|
|
|
if (fieldx.getFieldEnName() == null) { |
|
|
|
return Result.error("未输入英文名称,添加失败"); |
|
|
|
return Result.error("未输入英文名称,添加失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (fieldx.getType() == null){ |
|
|
|
if (fieldx.getType() == null) { |
|
|
|
return Result.error("未选择数据类型,添加失败"); |
|
|
|
return Result.error("未选择数据类型,添加失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (fieldx.getIsNull() == null){ |
|
|
|
if (fieldx.getIsNull() == null) { |
|
|
|
return Result.error("未选择是否为空,添加失败"); |
|
|
|
return Result.error("未选择是否为空,添加失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (fieldx.getIsUniqueness() == null){ |
|
|
|
if (fieldx.getIsUniqueness() == null) { |
|
|
|
return Result.error("未选择是否重复,添加失败"); |
|
|
|
return Result.error("未选择是否重复,添加失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (fieldx.getStatus() == null){ |
|
|
|
if (fieldx.getStatus() == null) { |
|
|
|
return Result.error("未选择字段状态,添加失败"); |
|
|
|
return Result.error("未选择字段状态,添加失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (fieldx.getVerisonStatus() == null){ |
|
|
|
if (fieldx.getVerisonStatus() == null) { |
|
|
|
return Result.error("未选择版本状态,添加失败"); |
|
|
|
return Result.error("未选择版本状态,添加失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
fieldx.setVerison(1); |
|
|
|
fieldx.setVerison(1); |
|
|
|
if (fieldx.getAssociateTable() != null && fieldx.getAssociateTable().equals(fieldx.getTableId())){ |
|
|
|
if (fieldx.getAssociateTable() != null && fieldx.getAssociateTable().equals(fieldx.getTableId())) { |
|
|
|
return Result.error("实体不能关联自身,添加失败"); |
|
|
|
return Result.error("实体不能关联自身,添加失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (fieldx.getTableId() != null){ |
|
|
|
if (fieldx.getTableId() != null) { |
|
|
|
List<Fieldx> fieldxList = fieldxService.list(new QueryWrapper<Fieldx>().eq("table_id", fieldx.getTableId())); |
|
|
|
List<Fieldx> fieldxList = fieldxService.list(new QueryWrapper<Fieldx>().eq("table_id", fieldx.getTableId())); |
|
|
|
for (Fieldx fieldx1 : fieldxList){ |
|
|
|
for (Fieldx fieldx1 : fieldxList) { |
|
|
|
if (fieldx1.getFieldName().equals(fieldx.getFieldName())){ |
|
|
|
if (fieldx1.getFieldName().equals(fieldx.getFieldName())) { |
|
|
|
return Result.error("添加失败,所属实体已有该中文名称"); |
|
|
|
return Result.error("添加失败,所属实体已有该中文名称"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (fieldx1.getFieldEnName().equals(fieldx.getFieldEnName())){ |
|
|
|
if (fieldx1.getFieldEnName().equals(fieldx.getFieldEnName())) { |
|
|
|
return Result.error("添加失败,所属实体已有该英文名称"); |
|
|
|
return Result.error("添加失败,所属实体已有该英文名称"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (fieldx.getIsPk() == 1 && fieldx1.getIsPk() == 1){ |
|
|
|
if (fieldx.getIsPk() == 1 && fieldx1.getIsPk() == 1) { |
|
|
|
return Result.error("该实体已经有主键,添加失败"); |
|
|
|
return Result.error("该实体已经有主键,添加失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
fieldxService.save(fieldx); |
|
|
|
fieldxService.save(fieldx); |
|
|
|
// 更新table版本
|
|
|
|
// 更新table版本
|
|
|
|
Tablex tablex = tablexService.getById(fieldx.getTableId()); |
|
|
|
Tablex tablex = tablexService.getById(fieldx.getTableId()); |
|
|
|
tablexService.updateVersion(fieldx.getTableId(),tablex.getVerison()+1); |
|
|
|
tablexService.updateVersion(fieldx.getTableId(), tablex.getVerison() + 1); |
|
|
|
tablexService.updateSql(fieldx.getTableId(),createSql(fieldx.getTableId())); |
|
|
|
tablexService.updateSql(fieldx.getTableId(), createSql(fieldx.getTableId())); |
|
|
|
return Result.OK("添加成功!"); |
|
|
|
return Result.OK("添加成功!"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 编辑 |
|
|
|
* 编辑 |
|
|
|
* |
|
|
|
* |
|
|
|
* @param fieldx |
|
|
|
* @param fieldx |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@AutoLog(value = "字段管理-编辑") |
|
|
|
@AutoLog(value = "字段管理-编辑") |
|
|
|
@ApiOperation(value="字段管理-编辑", notes="字段管理-编辑") |
|
|
|
@ApiOperation(value = "字段管理-编辑", notes = "字段管理-编辑") |
|
|
|
@PutMapping(value = "/edit") |
|
|
|
@PutMapping(value = "/edit") |
|
|
|
public Result<?> edit(@RequestBody Fieldx fieldx) { |
|
|
|
public Result<?> edit(@RequestBody Fieldx fieldx) { |
|
|
|
if(fieldx.getFieldName() ==null){ |
|
|
|
if (fieldx.getFieldName() == null) { |
|
|
|
return Result.error("未输入中文名称,编辑失败"); |
|
|
|
return Result.error("未输入中文名称,编辑失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (fieldx.getFieldEnName() == null){ |
|
|
|
if (fieldx.getFieldEnName() == null) { |
|
|
|
return Result.error("未输入英文名称,编辑失败"); |
|
|
|
return Result.error("未输入英文名称,编辑失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (fieldx.getType() == null){ |
|
|
|
if (fieldx.getType() == null) { |
|
|
|
return Result.error("未选择数据类型,编辑失败"); |
|
|
|
return Result.error("未选择数据类型,编辑失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (fieldx.getIsNull() == null){ |
|
|
|
if (fieldx.getIsNull() == null) { |
|
|
|
return Result.error("未选择是否为空,编辑失败"); |
|
|
|
return Result.error("未选择是否为空,编辑失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (fieldx.getIsUniqueness() == null){ |
|
|
|
if (fieldx.getIsUniqueness() == null) { |
|
|
|
return Result.error("未选择是否重复,编辑失败"); |
|
|
|
return Result.error("未选择是否重复,编辑失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (fieldx.getStatus() == null){ |
|
|
|
if (fieldx.getStatus() == null) { |
|
|
|
return Result.error("未选择字段状态,编辑失败"); |
|
|
|
return Result.error("未选择字段状态,编辑失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (fieldx.getVerisonStatus() == null){ |
|
|
|
if (fieldx.getVerisonStatus() == null) { |
|
|
|
return Result.error("未选择版本状态,编辑失败"); |
|
|
|
return Result.error("未选择版本状态,编辑失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (fieldx.getAssociateTable() != null && fieldx.getAssociateTable().equals(fieldx.getTableId())){ |
|
|
|
if (fieldx.getAssociateTable() != null && fieldx.getAssociateTable().equals(fieldx.getTableId())) { |
|
|
|
return Result.error("实体不能关联自身,编辑失败"); |
|
|
|
return Result.error("实体不能关联自身,编辑失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (fieldx.getTableId() != null){ |
|
|
|
if (fieldx.getTableId() != null) { |
|
|
|
List<Fieldx> fieldxList = fieldxService.list(new QueryWrapper<Fieldx>().eq("table_id", fieldx.getTableId()).ne("id",fieldx.getId())); |
|
|
|
List<Fieldx> fieldxList = fieldxService.list(new QueryWrapper<Fieldx>().eq("table_id", fieldx.getTableId()).ne("id", fieldx.getId())); |
|
|
|
for (Fieldx fieldx1 : fieldxList){ |
|
|
|
for (Fieldx fieldx1 : fieldxList) { |
|
|
|
if (fieldx1.getFieldName().equals(fieldx.getFieldName())){ |
|
|
|
if (fieldx1.getFieldName().equals(fieldx.getFieldName())) { |
|
|
|
return Result.error("编辑失败,所属实体已有该中文名称"); |
|
|
|
return Result.error("编辑失败,所属实体已有该中文名称"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (fieldx1.getFieldEnName().equals(fieldx.getFieldEnName())){ |
|
|
|
if (fieldx1.getFieldEnName().equals(fieldx.getFieldEnName())) { |
|
|
|
return Result.error("编辑失败,所属实体已有该英文名称"); |
|
|
|
return Result.error("编辑失败,所属实体已有该英文名称"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (fieldx.getIsPk() == 1 && fieldx1.getIsPk() == 1){ |
|
|
|
if (fieldx.getIsPk() == 1 && fieldx1.getIsPk() == 1) { |
|
|
|
return Result.error("该实体已经有主键,编辑失败"); |
|
|
|
return Result.error("该实体已经有主键,编辑失败"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
fieldxService.updateById(fieldx); |
|
|
|
fieldxService.updateById(fieldx); |
|
|
|
// 更新table版本
|
|
|
|
// 更新table版本
|
|
|
|
Tablex tablex = tablexService.getById(fieldx.getTableId()); |
|
|
|
Tablex tablex = tablexService.getById(fieldx.getTableId()); |
|
|
|
tablexService.updateVersion(fieldx.getTableId(),tablex.getVerison()+1); |
|
|
|
tablexService.updateVersion(fieldx.getTableId(), tablex.getVerison() + 1); |
|
|
|
tablexService.updateSql(fieldx.getTableId(),createSql(fieldx.getTableId())); |
|
|
|
tablexService.updateSql(fieldx.getTableId(), createSql(fieldx.getTableId())); |
|
|
|
return Result.OK("编辑成功!"); |
|
|
|
return Result.OK("编辑成功!"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 通过id删除 |
|
|
|
* 通过id删除 |
|
|
|
* |
|
|
|
* |
|
|
|
* @param id |
|
|
|
* @param id |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@AutoLog(value = "字段管理-通过id删除") |
|
|
|
@AutoLog(value = "字段管理-通过id删除") |
|
|
|
@ApiOperation(value="字段管理-通过id删除", notes="字段管理-通过id删除") |
|
|
|
@ApiOperation(value = "字段管理-通过id删除", notes = "字段管理-通过id删除") |
|
|
|
@DeleteMapping(value = "/delete") |
|
|
|
@DeleteMapping(value = "/delete") |
|
|
|
public Result<?> delete(@RequestParam(name="id",required=true) String id) { |
|
|
|
public Result<?> delete(@RequestParam(name = "id", required = true) String id) { |
|
|
|
List<Fieldx> fieldxList = fieldxService.list(new QueryWrapper<Fieldx>().eq("associate_field", id)); |
|
|
|
List<Fieldx> fieldxList = fieldxService.list(new QueryWrapper<Fieldx>().eq("associate_field", id)); |
|
|
|
if (!fieldxList.isEmpty()){ |
|
|
|
if (!fieldxList.isEmpty()) { |
|
|
|
return Result.error("该字段已被关联,不能删除"); |
|
|
|
return Result.error("该字段已被关联,不能删除"); |
|
|
|
} |
|
|
|
} |
|
|
|
Fieldx fieldx = fieldxService.getById(id); |
|
|
|
Fieldx fieldx = fieldxService.getById(id); |
|
|
|
fieldxService.removeById(id); |
|
|
|
fieldxService.removeById(id); |
|
|
|
// 更新sql语句
|
|
|
|
// 更新sql语句
|
|
|
|
tablexService.updateSql(fieldx.getTableId(),createSql(fieldx.getTableId())); |
|
|
|
tablexService.updateSql(fieldx.getTableId(), createSql(fieldx.getTableId())); |
|
|
|
return Result.OK("删除成功!"); |
|
|
|
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); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 导出excel |
|
|
|
* 批量删除 |
|
|
|
* |
|
|
|
* |
|
|
|
* @param request |
|
|
|
* @param ids |
|
|
|
* @param fieldx |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@RequestMapping(value = "/exportXls") |
|
|
|
@AutoLog(value = "字段管理-批量删除") |
|
|
|
public ModelAndView exportXls(HttpServletRequest request, Fieldx fieldx) { |
|
|
|
@ApiOperation(value = "字段管理-批量删除", notes = "字段管理-批量删除") |
|
|
|
return super.exportXls(request, fieldx, Fieldx.class, "字段管理"); |
|
|
|
@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导入数据 |
|
|
|
* 通过id查询 |
|
|
|
* |
|
|
|
* |
|
|
|
* @param request |
|
|
|
* @param id |
|
|
|
* @param response |
|
|
|
* @return |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@AutoLog(value = "字段管理-通过id查询") |
|
|
|
@RequestMapping(value = "/importExcel", method = RequestMethod.POST) |
|
|
|
@ApiOperation(value = "字段管理-通过id查询", notes = "字段管理-通过id查询") |
|
|
|
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) { |
|
|
|
@GetMapping(value = "/queryById") |
|
|
|
return super.importExcel(request, response, Fieldx.class); |
|
|
|
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){ |
|
|
|
public String createSql(String tableId){ |
|
|
|
Tablex tablex = tablexService.getById(tableId); |
|
|
|
Tablex tablex = tablexService.getById(tableId); |
|
|
|
String tableEnName = tablex.getTableEnName(); |
|
|
|
String tableEnName = tablex.getTableEnName(); |
|
|
|