|
|
@ -8,17 +8,9 @@ import java.net.URLDecoder; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
|
|
|
|
import io.swagger.models.auth.In; |
|
|
|
import io.swagger.models.auth.In; |
|
|
|
import org.apache.commons.lang.StringUtils; |
|
|
|
|
|
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook; |
|
|
|
|
|
|
|
import org.apache.poi.ss.usermodel.Sheet; |
|
|
|
|
|
|
|
import org.apache.poi.ss.usermodel.Workbook; |
|
|
|
|
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
|
|
|
|
|
|
|
import org.apache.shiro.SecurityUtils; |
|
|
|
|
|
|
|
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.system.vo.LoginUser; |
|
|
|
|
|
|
|
import org.jeecg.common.util.oConvertUtils; |
|
|
|
import org.jeecg.common.util.oConvertUtils; |
|
|
|
import org.jeecg.modules.fieldx.controller.FieldxController; |
|
|
|
import org.jeecg.modules.fieldx.controller.FieldxController; |
|
|
|
import org.jeecg.modules.fieldx.entity.Fieldx; |
|
|
|
import org.jeecg.modules.fieldx.entity.Fieldx; |
|
|
@ -33,8 +25,6 @@ import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
|
|
|
|
|
|
import org.jeecg.modules.tablex.service.ITablexVoService; |
|
|
|
|
|
|
|
import org.jeecg.modules.tablex.vo.TablexVo; |
|
|
|
|
|
|
|
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.entity.ExportParams; |
|
|
|
import org.jeecgframework.poi.excel.entity.ExportParams; |
|
|
@ -62,300 +52,185 @@ import org.jeecg.common.aspect.annotation.AutoLog; |
|
|
|
@RequestMapping("/tablex/tablex") |
|
|
|
@RequestMapping("/tablex/tablex") |
|
|
|
@Slf4j |
|
|
|
@Slf4j |
|
|
|
public class TablexController extends JeecgController<Tablex, ITablexService> { |
|
|
|
public class TablexController extends JeecgController<Tablex, ITablexService> { |
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
private ITablexService tablexService; |
|
|
|
private ITablexService tablexService; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
private IModulexService modulexService; |
|
|
|
private IModulexService modulexService; |
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
private IFieldxService fieldxService; |
|
|
|
private IFieldxService fieldxService; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
private FieldxController fieldxController; |
|
|
|
private FieldxController fieldxController; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
/** |
|
|
|
private ITablexVoService tablexVoService; |
|
|
|
* 分页列表查询 |
|
|
|
|
|
|
|
* |
|
|
|
/** |
|
|
|
* @param tablex |
|
|
|
* 分页列表查询 |
|
|
|
* @param pageNo |
|
|
|
* |
|
|
|
* @param pageSize |
|
|
|
* @param tablex |
|
|
|
* @param req |
|
|
|
* @param pageNo |
|
|
|
* @return |
|
|
|
* @param pageSize |
|
|
|
*/ |
|
|
|
* @param req |
|
|
|
@AutoLog(value = "实体表-分页列表查询") |
|
|
|
* @return |
|
|
|
@ApiOperation(value="实体表-分页列表查询", notes="实体表-分页列表查询") |
|
|
|
*/ |
|
|
|
@GetMapping(value = "/list") |
|
|
|
@AutoLog(value = "实体表-分页列表查询") |
|
|
|
public Result<?> queryPageList(Tablex tablex, |
|
|
|
@ApiOperation(value = "实体表-分页列表查询", notes = "实体表-分页列表查询") |
|
|
|
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo, |
|
|
|
@GetMapping(value = "/list") |
|
|
|
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize, |
|
|
|
public Result<?> queryPageList(Tablex tablex, |
|
|
|
HttpServletRequest req) { |
|
|
|
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo, |
|
|
|
QueryWrapper<Tablex> queryWrapper = QueryGenerator.initQueryWrapper(tablex, req.getParameterMap()); |
|
|
|
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize, |
|
|
|
Page<Tablex> page = new Page<Tablex>(pageNo, pageSize); |
|
|
|
HttpServletRequest req) { |
|
|
|
IPage<Tablex> pageList = tablexService.page(page, queryWrapper); |
|
|
|
QueryWrapper<Tablex> queryWrapper = QueryGenerator.initQueryWrapper(tablex, req.getParameterMap()); |
|
|
|
return Result.OK(pageList); |
|
|
|
Page<Tablex> page = new Page<Tablex>(pageNo, pageSize); |
|
|
|
} |
|
|
|
IPage<Tablex> pageList = tablexService.page(page, queryWrapper); |
|
|
|
@AutoLog(value = "实体管理-通过模块查询实体") |
|
|
|
return Result.OK(pageList); |
|
|
|
@ApiOperation(value="实体管理-通过模块查询实体", notes="实体管理-通过模块查询实体") |
|
|
|
} |
|
|
|
@GetMapping(value = "/getTableByModuleId") |
|
|
|
|
|
|
|
public Result<?> getTableByModuleId(@RequestParam(name="moduleId",required=true) String moduleId){ |
|
|
|
/** |
|
|
|
if (moduleId!=null){ |
|
|
|
* 添加 |
|
|
|
List<Tablex> tablexList = tablexService.list(new QueryWrapper<Tablex>().eq("module_id", moduleId)); |
|
|
|
* |
|
|
|
ArrayList<HashMap> hashMaps = new ArrayList<>(); |
|
|
|
* @param tablex |
|
|
|
for (Tablex tablex:tablexList){ |
|
|
|
* @return |
|
|
|
HashMap<Object, Object> hashMap = new HashMap<>(); |
|
|
|
*/ |
|
|
|
hashMap.put("text",tablex.getTableName()); |
|
|
|
@AutoLog(value = "实体表-添加") |
|
|
|
hashMap.put("value",tablex.getId()); |
|
|
|
@ApiOperation(value = "实体表-添加", notes = "实体表-添加") |
|
|
|
hashMaps.add(hashMap); |
|
|
|
@PostMapping(value = "/add") |
|
|
|
} |
|
|
|
public Result<?> add(@RequestBody Tablex tablex) { |
|
|
|
return Result.OK(hashMaps); |
|
|
|
List<Tablex> tablexList = tablexService.list(); |
|
|
|
}else return Result.error("未找到数据,请重试"); |
|
|
|
for (Tablex tablex1 : tablexList) { |
|
|
|
|
|
|
|
if (tablex1.getModuleId().equals(tablex.getModuleId())) { |
|
|
|
|
|
|
|
return Result.error("该模块已有实体,添加失败"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (tablex.getModuleId() != null) { |
|
|
|
|
|
|
|
Modulex modulex = modulexService.getById(tablex.getModuleId()); |
|
|
|
|
|
|
|
tablex.setTableName(modulex.getModuleName()); |
|
|
|
|
|
|
|
tablex.setTableEnName(modulex.getModuleEnName()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
tablex.setVerison(1); |
|
|
|
|
|
|
|
tablex.setTableStructure("CREATE TABLE '" + tablex.getTableEnName() + "' ();"); |
|
|
|
|
|
|
|
tablexService.save(tablex); |
|
|
|
|
|
|
|
System.err.println(tablex.toString()); |
|
|
|
|
|
|
|
modulexService.setmodule(tablex.getId(), tablex.getModuleId()); |
|
|
|
|
|
|
|
return Result.OK("添加成功!"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 编辑 |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param tablex |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@AutoLog(value = "实体表-编辑") |
|
|
|
|
|
|
|
@ApiOperation(value = "实体表-编辑", notes = "实体表-编辑") |
|
|
|
|
|
|
|
@PutMapping(value = "/edit") |
|
|
|
|
|
|
|
public Result<?> edit(@RequestBody Tablex tablex) { |
|
|
|
|
|
|
|
tablex.setVerison(tablex.getVerison() + 1); |
|
|
|
|
|
|
|
List<Tablex> tablexList = tablexService.list(); |
|
|
|
|
|
|
|
for (Tablex tablex1 : tablexList) { |
|
|
|
|
|
|
|
if (tablex1.getModuleId().equals(tablex.getModuleId())) { |
|
|
|
|
|
|
|
return Result.error("该模块已有实体,编辑失败"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (tablex.getModuleId() != null) { |
|
|
|
|
|
|
|
Modulex modulex = modulexService.getById(tablex.getModuleId()); |
|
|
|
|
|
|
|
tablex.setTableName(modulex.getModuleName()); |
|
|
|
|
|
|
|
tablex.setTableEnName(modulex.getModuleEnName()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
tablexService.updateById(tablex); |
|
|
|
|
|
|
|
tablexService.updateSql(tablex.getId(), fieldxController.createSql(tablex.getId())); |
|
|
|
|
|
|
|
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("table_id", id)); |
|
|
|
|
|
|
|
if (!fieldxList.isEmpty()) { |
|
|
|
|
|
|
|
return Result.error("该表内已有字段,不能删除"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
List<Fieldx> fieldxList1 = fieldxService.list(new QueryWrapper<Fieldx>().eq("associate_table", id)); |
|
|
|
|
|
|
|
if (!fieldxList1.isEmpty()) { |
|
|
|
|
|
|
|
return Result.error("该表已被关联,不能删除"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
tablexService.removeById(id); |
|
|
|
|
|
|
|
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.tablexService.removeByIds(Arrays.asList(ids.split(","))); |
|
|
|
|
|
|
|
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) { |
|
|
|
|
|
|
|
Tablex tablex = tablexService.getById(id); |
|
|
|
|
|
|
|
if (tablex == null) { |
|
|
|
|
|
|
|
return Result.error("未找到对应数据"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return Result.OK(tablex); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 导出excel |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param request |
|
|
|
|
|
|
|
* @param tablex |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@RequestMapping(value = "/exportXls") |
|
|
|
|
|
|
|
public ModelAndView exportXls(HttpServletRequest request, Tablex tablex) { |
|
|
|
|
|
|
|
return super.exportXls(request, tablex, Tablex.class, "实体表"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 添加 |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param tablex |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@AutoLog(value = "实体表-添加") |
|
|
|
|
|
|
|
@ApiOperation(value="实体表-添加", notes="实体表-添加") |
|
|
|
|
|
|
|
@PostMapping(value = "/add") |
|
|
|
|
|
|
|
public Result<?> add(@RequestBody Tablex tablex) { |
|
|
|
|
|
|
|
List<Tablex> tablexList = tablexService.list(); |
|
|
|
|
|
|
|
for (Tablex tablex1 : tablexList){ |
|
|
|
|
|
|
|
if (tablex1.getModuleId().equals(tablex.getModuleId())){ |
|
|
|
|
|
|
|
return Result.error("该模块已有实体,添加失败"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (tablex.getModuleId() != null){ |
|
|
|
|
|
|
|
Modulex modulex = modulexService.getById(tablex.getModuleId()); |
|
|
|
|
|
|
|
tablex.setTableName(modulex.getModuleName()); |
|
|
|
|
|
|
|
tablex.setTableEnName(modulex.getModuleEnName()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
tablex.setVerison(1); |
|
|
|
|
|
|
|
tablex.setTableStructure("CREATE TABLE '"+tablex.getTableEnName()+"' ();"); |
|
|
|
|
|
|
|
tablexService.save(tablex); |
|
|
|
|
|
|
|
System.err.println(tablex.toString()); |
|
|
|
|
|
|
|
modulexService.setmodule(tablex.getId(),tablex.getModuleId()); |
|
|
|
|
|
|
|
return Result.OK("添加成功!"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 编辑 |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param tablex |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@AutoLog(value = "实体表-编辑") |
|
|
|
|
|
|
|
@ApiOperation(value="实体表-编辑", notes="实体表-编辑") |
|
|
|
|
|
|
|
@PutMapping(value = "/edit") |
|
|
|
|
|
|
|
public Result<?> edit(@RequestBody Tablex tablex) { |
|
|
|
|
|
|
|
tablex.setVerison(tablex.getVerison()+1); |
|
|
|
|
|
|
|
// List<Tablex> tablexList = tablexService.list();
|
|
|
|
|
|
|
|
// for (Tablex tablex1 : tablexList){
|
|
|
|
|
|
|
|
// if (tablex1.getModuleId().equals(tablex.getModuleId())){
|
|
|
|
|
|
|
|
// return Result.error("该模块已有实体,编辑失败");
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
if (tablex.getModuleId() != null){ |
|
|
|
|
|
|
|
Modulex modulex = modulexService.getById(tablex.getModuleId()); |
|
|
|
|
|
|
|
tablex.setTableName(modulex.getModuleName()); |
|
|
|
|
|
|
|
tablex.setTableEnName(modulex.getModuleEnName()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
tablexService.updateById(tablex); |
|
|
|
|
|
|
|
tablexService.updateSql(tablex.getId(),fieldxController.createSql(tablex.getId())); |
|
|
|
|
|
|
|
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("table_id", id)); |
|
|
|
|
|
|
|
if (!fieldxList.isEmpty()){ |
|
|
|
|
|
|
|
return Result.error("该表内已有字段,不能删除"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
List<Fieldx> fieldxList1 = fieldxService.list(new QueryWrapper<Fieldx>().eq("associate_table", id)); |
|
|
|
|
|
|
|
if (!fieldxList1.isEmpty()){ |
|
|
|
|
|
|
|
return Result.error("该表已被关联,不能删除"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
tablexService.removeById(id); |
|
|
|
|
|
|
|
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.tablexService.removeByIds(Arrays.asList(ids.split(","))); |
|
|
|
|
|
|
|
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) { |
|
|
|
|
|
|
|
Tablex tablex = tablexService.getById(id); |
|
|
|
|
|
|
|
if(tablex==null) { |
|
|
|
|
|
|
|
return Result.error("未找到对应数据"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return Result.OK(tablex); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 导出excel |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param request |
|
|
|
|
|
|
|
* @param tablex |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@RequestMapping(value = "/exportXls") |
|
|
|
|
|
|
|
public ModelAndView exportXls(HttpServletRequest request, Tablex tablex) { |
|
|
|
|
|
|
|
return super.exportXls(request, tablex, Tablex.class, "实体表"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 通过excel导入数据 |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param request |
|
|
|
|
|
|
|
* @param response |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@RequestMapping(value = "/importExcel", method = RequestMethod.POST) |
|
|
|
|
|
|
|
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) { |
|
|
|
|
|
|
|
return super.importExcel(request, response, Tablex.class); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 通过excel导入数据 |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param file |
|
|
|
|
|
|
|
* @return |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@RequestMapping(value = "/importExcel", method = RequestMethod.POST) |
|
|
|
|
|
|
|
public Result<?> importExcel(MultipartFile file) { |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal(); |
|
|
|
|
|
|
|
// 判断文件是否是表格
|
|
|
|
|
|
|
|
String originalFilename = file.getOriginalFilename(); |
|
|
|
|
|
|
|
if (StringUtils.isBlank(originalFilename) || |
|
|
|
|
|
|
|
(!originalFilename.endsWith("xls") && |
|
|
|
|
|
|
|
!originalFilename.endsWith("xlsx"))) { |
|
|
|
|
|
|
|
return Result.error("文件格式不正确"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//获取上传文件对象
|
|
|
|
|
|
|
|
ImportParams params = new ImportParams(); |
|
|
|
|
|
|
|
params.setTitleRows(2);//表格标题行数,默认0
|
|
|
|
|
|
|
|
params.setHeadRows(1);//表头行数,默认1
|
|
|
|
|
|
|
|
params.setNeedSave(true);//是否需要保存上传的Excel,默认为false
|
|
|
|
|
|
|
|
List<TablexVo> list = null; |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
//读取excel数据
|
|
|
|
|
|
|
|
list = ExcelImportUtil.importExcel(file.getInputStream(), TablexVo.class, params); |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
return Result.error("文件读取失败"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//判断文件中是否存在数据
|
|
|
|
|
|
|
|
if (list == null || list.size() == 0) { |
|
|
|
|
|
|
|
return Result.error("Excel数据为空"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (TablexVo tablexVo : list) { |
|
|
|
|
|
|
|
//判断当前存入行是否为空值
|
|
|
|
|
|
|
|
if (tablexVo.getModuleId() == null && |
|
|
|
|
|
|
|
tablexVo.getTableName() == null && |
|
|
|
|
|
|
|
tablexVo.getTableEnName() == null && |
|
|
|
|
|
|
|
tablexVo.getTableStructure() == null && |
|
|
|
|
|
|
|
tablexVo.getStructuralDiagram() == null && |
|
|
|
|
|
|
|
tablexVo.getStatus() == null && |
|
|
|
|
|
|
|
tablexVo.getVerisonStatus() == null && |
|
|
|
|
|
|
|
tablexVo.getVerison() == null) continue; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//判断版本号长度
|
|
|
|
|
|
|
|
String verison = tablexVo.getVerison(); |
|
|
|
|
|
|
|
if (verison.length() > 5) { |
|
|
|
|
|
|
|
return Result.error("导入失败,版本号格式错误"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//存入临时表中
|
|
|
|
|
|
|
|
tablexVoService.save(tablexVo); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//从临时表中取出数据
|
|
|
|
|
|
|
|
List<TablexVo> voList = tablexVoService.list(); |
|
|
|
|
|
|
|
//删除临时表中的数据
|
|
|
|
|
|
|
|
tablexVoService.removeAll(voList); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (voList.size() == 0) { |
|
|
|
|
|
|
|
return Result.error("导入失败,数据为空"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Tablex tablex = new Tablex(); |
|
|
|
|
|
|
|
for (int i = 0; i < voList.size(); i++) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String moduleId = voList.get(i).getModuleId(); |
|
|
|
|
|
|
|
if (moduleId == null || moduleId.equals("")){ |
|
|
|
|
|
|
|
return Result.error("对应模块填写不能为空"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
LambdaQueryWrapper<Modulex> queryWrapper = new LambdaQueryWrapper<>(); |
|
|
|
|
|
|
|
queryWrapper.eq(Modulex::getId,moduleId); |
|
|
|
|
|
|
|
Modulex modulex = modulexService.getOne(queryWrapper); |
|
|
|
|
|
|
|
if(modulex == null){ |
|
|
|
|
|
|
|
return Result.error("对应模块填写错误"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
String modulexId = modulex.getId(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String status = voList.get(i).getStatus(); |
|
|
|
|
|
|
|
String verisonStatus = voList.get(i).getVerisonStatus(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//判断实体状态
|
|
|
|
|
|
|
|
int statusInt = status.equals("正常") ? 1 : status.equals("停用") ? 0 : status.equals("废弃") ? 9 : 3; |
|
|
|
|
|
|
|
//判断版本状态
|
|
|
|
|
|
|
|
int verisonStatusInt = verisonStatus.equals("当前") ? 1 : verisonStatus.equals("历史") ? 0 : 3; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//判断对应模块
|
|
|
|
|
|
|
|
if (modulexId != null && voList.get(i).getModuleId() != null && !voList.get(i).getModuleId().equals("")) { |
|
|
|
|
|
|
|
//判断中文名称
|
|
|
|
|
|
|
|
if (voList.get(i).getTableName() != null && !voList.get(i).getTableName().equals("") && !voList.get(i).getTableName().equals(modulex.getModuleName())) { |
|
|
|
|
|
|
|
//判断英文名称
|
|
|
|
|
|
|
|
if (voList.get(i).getTableEnName() != null && !voList.get(i).getTableEnName().equals("") && !voList.get(i).getTableEnName().equals(modulex.getModuleEnName())) { |
|
|
|
|
|
|
|
//判断实体状态
|
|
|
|
|
|
|
|
if (statusInt == 1 || statusInt == 0 || statusInt == 9) { |
|
|
|
|
|
|
|
//判断版本状态
|
|
|
|
|
|
|
|
if (verisonStatusInt == 1 || verisonStatusInt == 0) { |
|
|
|
|
|
|
|
//判断版本号
|
|
|
|
|
|
|
|
if (voList.get(i).getVerison() != null && !voList.get(i).getVerison().equals("")) { |
|
|
|
|
|
|
|
tablex.setModuleId(voList.get(i).getModuleId()); |
|
|
|
|
|
|
|
tablex.setTableName(voList.get(i).getTableName()); |
|
|
|
|
|
|
|
tablex.setTableEnName(voList.get(i).getTableEnName()); |
|
|
|
|
|
|
|
tablex.setTableStructure(voList.get(i).getTableStructure()); |
|
|
|
|
|
|
|
tablex.setStructuralDiagram(voList.get(i).getStructuralDiagram()); |
|
|
|
|
|
|
|
tablex.setCreateBy(loginUser.getRealname()); |
|
|
|
|
|
|
|
tablex.setStatus(statusInt); |
|
|
|
|
|
|
|
tablex.setVerisonStatus(verisonStatusInt); |
|
|
|
|
|
|
|
tablex.setVerison(Integer.valueOf(voList.get(i).getVerison())); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//保存到真实表中
|
|
|
|
|
|
|
|
tablexService.save(tablex); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return Result.error("导入失败,第" + i + 1 + "行的版本号填写错误!"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return Result.error("导入失败,第" + i + 1 + "行的版本状态填写错误!"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return Result.error("导入失败,第" + i + 1 + "行的实体状态填写错误!"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return Result.error("导入失败,第" + i + 1 + "行的英文名称填写错误!"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return Result.error("导入失败,第" + i + 1 + "行的中文名称填写错误!"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return Result.error("导入失败,第" + i + 1 + "行的对应模块填写错误!"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Result.error("文件导入失败"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return Result.OK("文件导入成功!"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|