添加综合信息库相关服务

This commit is contained in:
duwenyuan 2025-12-10 09:11:29 +08:00
parent 5fff260a9a
commit 154c3ad206
26 changed files with 3078 additions and 0 deletions

View File

@ -0,0 +1,329 @@
package org.jeecg.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.modules.base.entity.SourceRebuildMonitoringData;
import org.jeecg.modules.base.entity.configuration.GardsAccelerator;
import org.jeecg.modules.base.entity.configuration.GardsCorrectionFactor;
import org.jeecg.service.GardsAcceleratorService;
import org.jeecgframework.poi.excel.ExcelExportUtil;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.entity.enmus.ExcelType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Slf4j
@RestController
@RequestMapping("/gards-accelerator")
public class GardsAcceleratorController {
@Autowired
private GardsAcceleratorService gardsAcceleratorService;
/**
* 新增 加速器信息
*/
@AutoLog(value = "新增加速器信息")
@Operation(summary = "新增加速器信息")
@PostMapping("create")
public Result<?> create(@RequestBody GardsAccelerator gardsAccelerator) {
try {
boolean success = gardsAcceleratorService.save(gardsAccelerator);
if (success) {
return Result.OK("添加成功",gardsAccelerator);
} else {
return Result.error("设施信息添加失败");
}
} catch (Exception e) {
log.error(e.getMessage());
return Result.error("操作失败");
}
}
/**
* 根据ID删除设施信息
*/
@AutoLog(value = "删除加速器信息")
@Operation(summary = "删除加速器信息")
@DeleteMapping("/delete")
public Result<?> delete(@RequestParam Integer id) {
try {
boolean success = gardsAcceleratorService.removeById(id);
if (success) {
return Result.ok("删除成功");
} else {
return Result.error("设施信息删除失败,可能该记录不存在");
}
} catch (Exception e) {
log.error(e.getMessage());
return Result.error("操作失败");
}
}
/**
* 更新设施信息
*/
@Operation(summary = "更新加速器信息")
@PutMapping("/update")
public Result<?> update(@RequestBody GardsAccelerator gardsAccelerator) {
try {
boolean success = gardsAcceleratorService.updateById(gardsAccelerator);
if (success) {
return Result.OK("设施信息更新成功",gardsAccelerator);
} else {
return Result.error("设施信息更新失败,可能该记录不存在");
}
} catch (Exception e) {
log.error(e.getMessage());
return Result.error("操作失败");
}
}
/**
* 根据ID查询设施详情
*/
@Operation(summary = "查询加速器信息")
@GetMapping("/queryById")
public Result<GardsAccelerator> getById(@RequestParam Integer id) {
try {
GardsAccelerator facility = gardsAcceleratorService.getById(id);
if (facility != null) {
return Result.ok(facility);
} else {
return Result.error("未找到对应的设施信息");
}
} catch (Exception e) {
log.error(e.getMessage());
return Result.error("查询失败");
}
}
/**
* 分页查询设施列表
*/
@Operation(summary = "加速器信息分页查询")
@GetMapping("/page")
public Result<IPage<GardsAccelerator>> page(
@RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "10") Integer pageSize,
@RequestParam(required = false) String country,
@RequestParam(required = false) String facilityName
) {
try {
Page<GardsAccelerator> page = new Page<>(pageNum, pageSize);
LambdaQueryWrapper<GardsAccelerator> wrapper = new LambdaQueryWrapper<>();
if (facilityName != null && !facilityName.trim().isEmpty()) {
wrapper.eq(GardsAccelerator::getFacilityName, facilityName);
}
if (country != null && !country.trim().isEmpty()) {
wrapper.eq(GardsAccelerator::getCountry, country);
}
IPage<GardsAccelerator> pageResult = gardsAcceleratorService.page(page,wrapper);
return Result.ok(pageResult);
} catch (Exception e) {
log.error("分页查询失败: " + e.getMessage());
return Result.error("分页查询失败");
}
}
/**
* 查询所有设施列表
*/
@Operation(summary = "查询加速器所有信息")
@GetMapping("/list")
public Result<List<GardsAccelerator>> list() {
try {
List<GardsAccelerator> list = gardsAcceleratorService.list();
return Result.ok(list);
} catch (Exception e) {
log.error("查询失败: " + e.getMessage());
return Result.error("查询失败");
}
}
/**
* 根据设施代码查询
*/
@Operation(summary = "根据加速器代码查询")
@GetMapping("/by-facility-code")
public Result<GardsAccelerator> getByFacilityCode(@RequestParam String facilityCode) {
try {
GardsAccelerator facility = gardsAcceleratorService.getByFacilityCode(facilityCode);
if (facility != null) {
return Result.ok(facility);
} else {
return Result.error("未找到设施代码为 " + facilityCode + " 的设施");
}
} catch (Exception e) {
log.error("查询失败: " + e.getMessage());
return Result.error("查询失败");
}
}
/**
* 根据国家查询
*/
@Operation(summary = "根据加速器国家查询")
@GetMapping("/by-country")
public Result<List<GardsAccelerator>> getByCountry(@RequestParam String country) {
try {
List<GardsAccelerator> list = gardsAcceleratorService.getByCountry(country);
return Result.ok(list);
} catch (Exception e) {
log.error("查询失败: " + e.getMessage());
return Result.error("查询失败" );
}
}
/**
* 根据运行状态查询
*/
@Operation(summary = "根据加速器运行状态查询")
@GetMapping("/by-status")
public Result<List<GardsAccelerator>> getByOperationalStatus(@RequestParam Integer isOperational) {
try {
List<GardsAccelerator> list = gardsAcceleratorService.getByOperationalStatus(isOperational);
return Result.ok(list);
} catch (Exception e) {
log.error("查询失败: " + e.getMessage());
return Result.error("查询失败");
}
}
/**
* 条件组合查询
*/
@GetMapping("/search")
@Operation(summary = "条件组合查询")
public Result<List<GardsAccelerator>> search(
@RequestParam(required = false) String country,
@RequestParam(required = false) String category,
@RequestParam(required = false) Integer isOperational) {
try {
LambdaQueryWrapper<GardsAccelerator> wrapper = new LambdaQueryWrapper<>();
if (country != null && !country.isEmpty()) {
wrapper.eq(GardsAccelerator::getCountry, country);
}
if (category != null && !category.isEmpty()) {
wrapper.eq(GardsAccelerator::getCategory, category);
}
if (isOperational != null) {
wrapper.eq(GardsAccelerator::getIsOperational, isOperational);
}
List<GardsAccelerator> list = gardsAcceleratorService.list(wrapper);
return Result.ok(list);
} catch (Exception e) {
log.error("条件查询失败: " + e.getMessage());
return Result.error("条件查询失败");
}
}
@AutoLog(value = "导出模版")
@Operation(summary = "加速器信息导出模版")
@GetMapping("/exportTemplate")
public void exportTemplate(HttpServletResponse response) throws IOException {
ExportParams params = new ExportParams();
params.setTitle("加速器信息");
params.setFixedTitle(true);
params.setTitleHeight((short) 8);
params.setType(ExcelType.XSSF);
ExcelExportUtil.exportExcel(params, GardsAccelerator.class, new ArrayList<>()).write(response.getOutputStream());
}
@AutoLog(value = "导出数据")
@Operation(summary = "加速器信息导出数据")
@GetMapping("/exportExcel")
public void exportExcel(HttpServletResponse response,
@RequestParam(required = false) String country,
@RequestParam(required = false) String facilityName,
@RequestParam(required = false) String category) throws IOException {
ExportParams params = new ExportParams();
params.setTitle("加速器信息");
params.setFixedTitle(true);
params.setTitleHeight((short) 8);
params.setType(ExcelType.XSSF);
LambdaQueryWrapper<GardsAccelerator> wrapper = new LambdaQueryWrapper<>();
if (country != null && !country.isEmpty()) {
wrapper.eq(GardsAccelerator::getCountry, country);
}
if (category != null && !category.isEmpty()) {
wrapper.eq(GardsAccelerator::getCategory, category);
}
if (facilityName != null && !facilityName.isEmpty()) {
wrapper.eq(GardsAccelerator::getFacilityName, facilityName);
}
List<GardsAccelerator> list = gardsAcceleratorService.list(wrapper);
ExcelExportUtil.exportExcel(params, GardsAccelerator.class, list).write(response.getOutputStream());
}
/**
* 通过excel导入数据
*
* @param request
* @return
*/
@AutoLog(value = "导入GardsAccelerator数据")
@Operation(summary = "导入加速器数据")
@PostMapping(value = "/importExcel")
public Result<?> importExcel(HttpServletRequest request) {
// 1. 获取上传文件
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
// 2. 遍历文件进行处理
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
// 获取上传文件对象
MultipartFile file = entity.getValue();
ImportParams params = new ImportParams();
// 设置标题行行数通常为1如果没有标题填0
params.setTitleRows(1);
// 设置表头行数通常为1
params.setHeadRows(1);
params.setNeedSave(true);
try {
// 3. 使用 AutoPoi 工具类解析 Excel
List<GardsAccelerator> list = ExcelImportUtil.importExcel(file.getInputStream(), GardsAccelerator.class, params);
// 4. 批量保存数据到数据库
gardsAcceleratorService.saveBatch(list);
return Result.OK("文件导入成功!数据行数:" + list.size());
} catch (Exception e) {
return Result.error("文件导入失败:" + e.getMessage());
} finally {
try {
file.getInputStream().close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return Result.error("文件导入失败!");
}
}

View File

@ -0,0 +1,358 @@
package org.jeecg.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.modules.base.entity.configuration.GardsAccelerator;
import org.jeecg.modules.base.entity.configuration.GardsCorrectionFactor;
import org.jeecg.service.GardsCorrectionFactorService;
import org.jeecgframework.poi.excel.ExcelExportUtil;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.entity.enmus.ExcelType;
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 java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Slf4j
@RestController
@RequestMapping("/gardsCorrectionFactor")
public class GardsCorrectionFactorController {
@Autowired
private GardsCorrectionFactorService gardsCorrectionFactorService;
/**
* 新增校正因子
*/
@PostMapping("/create")
@Operation(summary = "新增校正因子")
public Result<?> create(@RequestBody GardsCorrectionFactor gardsCorrectionFactor) {
try {
boolean success = gardsCorrectionFactorService.save(gardsCorrectionFactor);
if (success) {
return Result.OK("校正因子添加成功", gardsCorrectionFactor);
} else {
return Result.error("校正因子添加失败");
}
} catch (Exception e) {
log.error("操作失败: " + e.getMessage());
return Result.error("操作失败");
}
}
/**
* 根据ID删除校正因子
*/
@DeleteMapping("/delete")
@Operation(summary = "根据ID删除校正因子")
public Result<?> delete(@RequestParam(name="id") Integer id) {
try {
boolean success = gardsCorrectionFactorService.removeById(id);
if (success) {
return Result.ok("校正因子删除成功");
} else {
return Result.error("校正因子删除失败,可能该记录不存在");
}
} catch (Exception e) {
log.error("操作失败: " + e.getMessage());
return Result.error("操作失败");
}
}
/**
* 更新校正因子信息
*/
@PutMapping("/update")
@Operation(summary = "更新校正因子信息")
public Result<?> update(@RequestBody GardsCorrectionFactor gardsCorrectionFactor) {
try {
boolean success = gardsCorrectionFactorService.updateById(gardsCorrectionFactor);
if (success) {
return Result.OK("校正因子更新成功", gardsCorrectionFactor);
} else {
return Result.error("校正因子更新失败,可能该记录不存在");
}
} catch (Exception e) {
log.error("操作失败: " + e.getMessage());
return Result.error("操作失败");
}
}
/**
* 根据ID查询校正因子详情
*/
@GetMapping("/queryById")
@Operation(summary = "根据ID查询校正因子详情")
public Result<GardsCorrectionFactor> getById(@RequestParam(name="id") Integer id) {
try {
GardsCorrectionFactor factor = gardsCorrectionFactorService.getById(id);
if (factor != null) {
return Result.OK("查询成功", factor);
} else {
return Result.error("未找到对应的校正因子信息");
}
} catch (Exception e) {
log.error("操作失败: " + e.getMessage());
return Result.error("查询失败");
}
}
/**
* 分页查询校正因子列表
*/
@GetMapping("/page")
@Operation(summary = "分页查询校正因子列表")
public Result<IPage<GardsCorrectionFactor>> page(
@RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "10") Integer pageSize,
@RequestParam(required = false) String stationCode,
@RequestParam(required = false) String detectorCode) {
try {
Page<GardsCorrectionFactor> page = new Page<>(pageNum, pageSize);
LambdaQueryWrapper<GardsCorrectionFactor> wrapper = new LambdaQueryWrapper<>();
if (stationCode != null && !stationCode.trim().isEmpty()) {
wrapper.eq(GardsCorrectionFactor::getStationCode, stationCode);
}
if (detectorCode != null && !detectorCode.trim().isEmpty()) {
wrapper.eq(GardsCorrectionFactor::getDetectorCode, detectorCode);
}
IPage<GardsCorrectionFactor> pageResult = gardsCorrectionFactorService.page(page, wrapper);
return Result.OK ("分页查询成功", pageResult);
} catch (Exception e) {
log.error("分页查询失败: " + e.getMessage());
return Result.error("分页查询失败");
}
}
/**
* 查询所有校正因子列表
*/
@GetMapping("/list")
@Operation(summary = "查询所有校正因子列表")
public Result<List<GardsCorrectionFactor>> list() {
try {
List<GardsCorrectionFactor> list = gardsCorrectionFactorService.list();
return Result.OK ("查询成功", list);
} catch (Exception e) {
log.error("查询失败: " + e.getMessage());
return Result.error("查询失败" );
}
}
/**
* 根据站点代码查询
*/
@GetMapping("/by-station")
@Operation(summary = "根据站点代码查询")
public Result<List<GardsCorrectionFactor>> getByStationCode(@RequestParam(name = "stationCode") String stationCode) {
try {
List<GardsCorrectionFactor> list = gardsCorrectionFactorService.getByStationCode(stationCode);
return Result.OK ("查询成功", list);
} catch (Exception e) {
log.error("查询失败: " + e.getMessage());
return Result.error("查询失败");
}
}
/**
* 根据探测器代码查询
*/
@GetMapping("/by-detector")
@Operation(summary = "查询所有校正因子库数据")
public Result<List<GardsCorrectionFactor>> getByDetectorCode(@RequestParam(name="detectorCode") String detectorCode) {
try {
List<GardsCorrectionFactor> list = gardsCorrectionFactorService.getByDetectorCode(detectorCode);
return Result.OK ("查询成功", list);
} catch (Exception e) {
log.error("查询失败: " + e.getMessage());
return Result.error("查询失败");
}
}
/**
* 根据站点和探测器代码组合查询
*/
@GetMapping("/by-station-detector")
@Operation(summary = "根据站点和探测器代码组合查询")
public Result<List<GardsCorrectionFactor>> getByStationAndDetector(
@RequestParam String stationCode,
@RequestParam String detectorCode) {
try {
List<GardsCorrectionFactor> factor = gardsCorrectionFactorService.getByStationAndDetector(stationCode, detectorCode);
if (factor != null) {
return Result.OK("查询成功", factor);
} else {
return Result.error("未找到对应的校正因子");
}
} catch (Exception e) {
log.error("查询失败: " + e.getMessage());
return Result.error("查询失败");
}
}
/**
* 根据制造商查询
*/
@GetMapping("/by-manufacturer")
@Operation(summary = "根据制造商查询")
public Result<List<GardsCorrectionFactor>> getByManufacturer(@RequestParam String manufacturer) {
try {
List<GardsCorrectionFactor> list = gardsCorrectionFactorService.getByManufacturer(manufacturer);
return Result.OK("查询成功", list);
} catch (Exception e) {
log.error("查询失败: " + e.getMessage());
return Result.error("查询失败");
}
}
/**
* 根据型号查询
*/
@GetMapping("/by-model")
@Operation(summary = "根据型号查询")
public Result<List<GardsCorrectionFactor>> getByModel(@RequestParam String model) {
try {
List<GardsCorrectionFactor> list = gardsCorrectionFactorService.getByModel(model);
return Result.OK ("查询成功", list);
} catch (Exception e) {
log.error("查询失败: " + e.getMessage());
return Result.error("查询失败");
}
}
/**
* 多条件组合查询
*/
@GetMapping("/search")
@Operation(summary = "校正因子多条件组合查询")
public Result<List<GardsCorrectionFactor>> search(
@RequestParam(required = false) String stationCode,
@RequestParam(required = false) String detectorCode,
@RequestParam(required = false) String manufacturer,
@RequestParam(required = false) String model) {
try {
List<GardsCorrectionFactor> list = gardsCorrectionFactorService.getByConditions(
stationCode, detectorCode, manufacturer, model);
return Result.OK ("查询成功", list);
} catch (Exception e) {
log.error("条件查询失败: " + e.getMessage());
return Result.error("条件查询失败");
}
}
/**
* 批量更新校正因子
*/
@PutMapping("/batch")
@Operation(summary = "校正因子批量更新")
public Result<?> updateBatch(@RequestBody List<GardsCorrectionFactor> factors) {
try {
boolean success = gardsCorrectionFactorService.updateBatchCorrectionFactors(factors);
if (success) {
return Result.ok("批量更新成功");
} else {
return Result.error("批量更新失败");
}
} catch (Exception e) {
log.error("批量操作失败: " + e.getMessage());
return Result.error("批量操作失败");
}
}
@AutoLog(value = "导出模版")
@Operation(summary = "导出模版")
@GetMapping("/exportTemplate")
public void exportTemplate(HttpServletResponse response) throws IOException {
ExportParams params = new ExportParams();
params.setTitle("探测器模拟及联符合校正因子信息");
params.setFixedTitle(true);
params.setTitleHeight((short) 8);
params.setType(ExcelType.XSSF);
ExcelExportUtil.exportExcel(params, GardsCorrectionFactor.class,new ArrayList<>()).write(response.getOutputStream());
}
@AutoLog(value = "导出Excel")
@Operation(summary = "导出校正因子Excel")
@GetMapping("/exportExcel")
public void exportExcel(HttpServletResponse response,@RequestParam(required = false) String stationCode,
@RequestParam(required = false) String detectorCode,
@RequestParam(required = false) String manufacturer,
@RequestParam(required = false) String model) throws IOException {
ExportParams params = new ExportParams();
params.setTitle("探测器模拟及联符合校正因子信息");
params.setFixedTitle(true);
params.setTitleHeight((short) 8);
params.setType(ExcelType.XSSF);
List<GardsCorrectionFactor> list = gardsCorrectionFactorService.getByConditions(
stationCode, detectorCode, manufacturer, model);
ExcelExportUtil.exportExcel(params, GardsCorrectionFactor.class,list).write(response.getOutputStream());
}
/**
* 通过excel导入数据
*
* @param request
* @return
*/
@AutoLog(value = "导入GardsAccelerator数据")
@PostMapping(value = "/importExcel")
public Result<?> importExcel(HttpServletRequest request ) {
// 1. 获取上传文件
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
// 2. 遍历文件进行处理
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
// 获取上传文件对象
MultipartFile file = entity.getValue();
ImportParams params = new ImportParams();
// 设置标题行行数通常为1如果没有标题填0
params.setTitleRows(1);
// 设置表头行数通常为1
params.setHeadRows(1);
params.setNeedSave(true);
try {
// 3. 使用 AutoPoi 工具类解析 Excel
List<GardsCorrectionFactor> list = ExcelImportUtil.importExcel(file.getInputStream(), GardsCorrectionFactor.class, params);
// 4. 批量保存数据到数据库
gardsCorrectionFactorService.saveBatch(list);
return Result.OK("文件导入成功!数据行数:" + list.size());
} catch (Exception e) {
return Result.error("文件导入失败:" + e.getMessage());
} finally {
try {
file.getInputStream().close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return Result.error("文件导入失败!");
}
}

View File

@ -0,0 +1,285 @@
package org.jeecg.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.modules.base.entity.configuration.GardsCorrectionFactor;
import org.jeecg.modules.base.entity.configuration.GardsNuclearFuelFacilities;
import org.jeecg.service.GardsNuclearFuelFacilityService;
import org.jeecgframework.poi.excel.ExcelExportUtil;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.entity.enmus.ExcelType;
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 java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Slf4j
@RestController
@RequestMapping("/gardsNuclearFuelFacility")
public class GardsNuclearFuelFacilityController {
@Autowired
private GardsNuclearFuelFacilityService nuclearFuelFacilitiesService;
/**
* 新增核燃料设施信息
*/
@PostMapping("/create")
@Operation(summary = "新增核燃料设施信息")
public Result<?> create(@RequestBody GardsNuclearFuelFacilities facility) {
try {
boolean success = nuclearFuelFacilitiesService.save(facility);
if (success) {
return Result.OK("核燃料设施信息添加成功", facility);
} else {
return Result.error("核燃料设施信息添加失败");
}
} catch (Exception e) {
log.error("操作失败: " + e.getMessage());
return Result.error("操作失败");
}
}
/**
* 根据ID删除核燃料设施信息
*/
@DeleteMapping("/delete")
@Operation(summary = "根据ID删除核燃料设施信息")
public Result<?> delete(@RequestParam Integer id) {
try {
boolean success = nuclearFuelFacilitiesService.removeById(id);
if (success) {
return Result.ok("核燃料设施信息删除成功");
} else {
return Result.error("核燃料设施信息删除失败,可能该记录不存在");
}
} catch (Exception e) {
log.error("操作失败: " + e.getMessage());
return Result.error("操作失败 ");
}
}
/**
* 更新核燃料设施信息
*/
@PutMapping("/update")
@Operation(summary = "更新核燃料设施信息")
public Result<?> update(@RequestBody GardsNuclearFuelFacilities facility) {
try {
boolean success = nuclearFuelFacilitiesService.updateById(facility);
if (success) {
return Result.OK("核燃料设施信息更新成功", facility);
} else {
return Result.error("核燃料设施信息更新失败,可能该记录不存在");
}
} catch (Exception e) {
log.error("操作失败: " + e.getMessage());
return Result.error("操作失败");
}
}
/**
* 根据ID查询核燃料设施详情
*/
@GetMapping("/getById")
@Operation(summary = "根据ID查询核燃料设施详情")
public Result<GardsNuclearFuelFacilities> getById(@RequestParam Integer id) {
try {
GardsNuclearFuelFacilities facility = nuclearFuelFacilitiesService.getById(id);
if (facility != null) {
return Result.ok(facility);
} else {
return Result.error("未找到对应的核燃料设施信息");
}
} catch (Exception e) {
log.error("操作失败: " + e.getMessage());
return Result.error("查询失败");
}
}
/**
* 分页查询核燃料设施列表
*/
@GetMapping("/page")
@Operation(summary = "分页查询核燃料设施列表")
public Result<IPage<GardsNuclearFuelFacilities>> page(
@RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "10") Integer pageSize,
@RequestParam(required = false) String facilityType,
@RequestParam(required = false) String facilityStatus,
@RequestParam(required = false) String facilityName,
@RequestParam(required = false) String country) {
try {
Page<GardsNuclearFuelFacilities> page = new Page<>(pageNum, pageSize);
LambdaQueryWrapper<GardsNuclearFuelFacilities> wrapper = new LambdaQueryWrapper<>();
if (facilityType != null && !facilityType.trim().isEmpty()) {
wrapper.eq(GardsNuclearFuelFacilities::getFacilityType, facilityType);
}
if (facilityStatus != null && !facilityStatus.trim().isEmpty()) {
wrapper.eq(GardsNuclearFuelFacilities::getFacilityStatus, facilityStatus);
}
if (facilityName != null && !facilityName.trim().isEmpty()) {
wrapper.eq(GardsNuclearFuelFacilities::getFacilityName, facilityName);
}
if (country != null && !country.trim().isEmpty()) {
wrapper.eq(GardsNuclearFuelFacilities::getCountry, country);
}
IPage<GardsNuclearFuelFacilities> pageResult = nuclearFuelFacilitiesService.page(page, wrapper);
return Result.OK("分页查询成功", pageResult);
} catch (Exception e) {
log.error("操作失败: " + e.getMessage());
return Result.error("分页查询失败");
}
}
/**
* 查询所有核燃料设施列表
*/
@GetMapping("/list")
@Operation(summary = "查询所有核燃料设施列表")
public Result<List<GardsNuclearFuelFacilities>> list() {
try {
List<GardsNuclearFuelFacilities> list = nuclearFuelFacilitiesService.list();
return Result.OK("查询成功", list);
} catch (Exception e) {
log.error("操作失败: " + e.getMessage());
return Result.error("查询失败");
}
}
/**
* 根据设施名称模糊查询
*/
@GetMapping("/by-name")
@Operation(summary = "根据设施名称模糊查询")
public Result<List<GardsNuclearFuelFacilities>> getByFacilityNameLike(@RequestParam String facilityName) {
try {
List<GardsNuclearFuelFacilities> list = nuclearFuelFacilitiesService.getByFacilityNameLike(facilityName);
return Result.OK("查询成功", list);
} catch (Exception e) {
log.error("操作失败: " + e.getMessage());
return Result.error("查询失败");
}
}
/**
* 多条件组合查询
*/
@GetMapping("/search")
@Operation(summary = "多条件组合查询")
public Result<List<GardsNuclearFuelFacilities>> search(
@RequestParam(required = false) String facilityType,
@RequestParam(required = false) String facilityStatus,
@RequestParam(required = false) String country,
@RequestParam(required = false) String facilityName,
@RequestParam(required = false) String fuelType) {
try {
List<GardsNuclearFuelFacilities> list = nuclearFuelFacilitiesService.getByConditions(
facilityType, facilityStatus, country, facilityName, fuelType);
return Result.OK("查询成功", list);
} catch (Exception e) {
log.error("操作失败: " + e.getMessage());
return Result.error("条件查询失败");
}
}
@AutoLog(value = "导出模版")
@Operation(summary = "导出模版")
@GetMapping("/exportTemplate")
public void exportTemplate(HttpServletResponse response) throws IOException {
ExportParams params = new ExportParams();
params.setTitle("后处理厂设施信息");
params.setFixedTitle(true);
params.setTitleHeight((short) 8);
params.setType(ExcelType.XSSF);
ExcelExportUtil.exportExcel(params, GardsNuclearFuelFacilities.class, new ArrayList<>()).write(response.getOutputStream());
}
@AutoLog(value = "导出Excel")
@Operation(summary = "导出Excel")
@GetMapping("/exportExcel")
public void exportExcel(HttpServletResponse response, @RequestParam(required = false) String facilityType,
@RequestParam(required = false) String facilityStatus,
@RequestParam(required = false) String country,
@RequestParam(required = false) String facilityName,
@RequestParam(required = false) String fuelType) throws IOException {
ExportParams params = new ExportParams();
params.setTitle("后处理厂设施信息");
params.setFixedTitle(true);
params.setTitleHeight((short) 8);
params.setType(ExcelType.XSSF);
List<GardsNuclearFuelFacilities> list = nuclearFuelFacilitiesService.getByConditions(
facilityType, facilityStatus, country, facilityName, fuelType);
ExcelExportUtil.exportExcel(params, GardsNuclearFuelFacilities.class, list).write(response.getOutputStream());
}
/**
* 通过excel导入数据
*
* @param request
* @param response
* @return
*/
@AutoLog(value = "导入GardsAccelerator数据")
@PostMapping(value = "/importExcel")
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
// 1. 获取上传文件
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
// 2. 遍历文件进行处理
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
// 获取上传文件对象
MultipartFile file = entity.getValue();
ImportParams params = new ImportParams();
// 设置标题行行数通常为1如果没有标题填0
params.setTitleRows(1);
// 设置表头行数通常为1
params.setHeadRows(1);
params.setNeedSave(true);
try {
// 3. 使用 AutoPoi 工具类解析 Excel
List<GardsNuclearFuelFacilities> list = ExcelImportUtil.importExcel(file.getInputStream(), GardsNuclearFuelFacilities.class, params);
// 4. 批量保存数据到数据库
boolean success = nuclearFuelFacilitiesService.saveBatch(list, 500);
if (success) {
return Result.OK("文件导入成功!数据行数:" + list.size());
} else {
return Result.error("文件导入失败");
}
} catch (Exception e) {
return Result.error("文件导入失败:" + e.getMessage());
} finally {
try {
file.getInputStream().close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return Result.error("文件导入失败!");
}
}

View File

@ -0,0 +1,307 @@
package org.jeecg.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.log4j.Log4j;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.modules.base.entity.configuration.GardsNuclearFuelFacilities;
import org.jeecg.modules.base.entity.configuration.GardsNuclearReactors;
import org.jeecg.modules.base.mapper.GardsNuclearReactorsMapper;
import org.jeecg.service.GardsNuclearReactorsService;
import org.jeecg.util.BizUpsertUtil;
import org.jeecgframework.poi.excel.ExcelExportUtil;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.entity.enmus.ExcelType;
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 java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Slf4j
@RestController
@RequestMapping("/gardsNuclearReactors")
public class GardsNuclearReactorsController {
@Autowired
private GardsNuclearReactorsService gardsNuclearReactorsService;
/**
* 新增 核设施信息
*
* @param gardsNuclearReactors
* @return
*/
@PostMapping("/create")
@Operation(summary = "新增核设施信息")
public Result<?> create(@RequestBody GardsNuclearReactors gardsNuclearReactors) {
try {
boolean success = gardsNuclearReactorsService.save(gardsNuclearReactors);
if (success) {
return Result.OK("添加核设施信息成功", gardsNuclearReactors);
} else {
return Result.error("添加核设施信息失败");
}
} catch (Exception e) {
log.error("新增操作失败: " + e.getMessage());
return Result.error("操作失败");
}
}
/**
* 删除反应堆数据
*
* @param id
* @return
*/
@DeleteMapping("/delete")
@Operation(summary = "删除核设施信息数据")
public Result<?> delete(@RequestParam Integer id) {
try {
boolean success = gardsNuclearReactorsService.removeById(id);
if (success) {
return Result.ok("核设施信息删除成功");
}
return Result.error("删除核设施信息失败,可能该记录不存在");
} catch (Exception e) {
log.error("操作失败: " + e.getMessage());
return Result.error("操作失败");
}
}
/**
* 更新反应堆数据
*
* @param gardsNuclearReactors
* @return
*/
@PutMapping("/update")
@Operation(summary = "更新核设施数据")
public Result<?> update(@RequestBody GardsNuclearReactors gardsNuclearReactors) {
try {
boolean success = gardsNuclearReactorsService.updateById(gardsNuclearReactors);
if (success) {
return Result.OK("更新成功", gardsNuclearReactors);
} else {
return Result.error("更新失败,或者记录不存在");
}
} catch (Exception e) {
log.error("操作失败: " + e.getMessage());
return Result.error("操作失败");
}
}
/**
* 根据Id查询反应堆数据
*
* @param id
* @return
*/
@GetMapping("/getById")
@Operation(summary = "根据Id查询反应堆数据")
public Result<GardsNuclearReactors> getById(@RequestParam Integer id) {
try {
GardsNuclearReactors nuclearReactors = gardsNuclearReactorsService.getById(id);
if (nuclearReactors != null) {
return Result.OK(nuclearReactors);
} else {
return Result.error("未找到核设施信息数据");
}
} catch (Exception e) {
log.error("操作失败: " + e.getMessage());
return Result.error("查询失败");
}
}
/**
* 分页查询反应堆数据
*
* @param pageNum 页码
* @param pageSize 分页大小
* @param unitName 单位名称
* @param country 国家
* @return
*/
@GetMapping("/page")
@Operation(summary = "分页查询核设施信息数据")
public Result<IPage<GardsNuclearReactors>> page(
@RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "10") Integer pageSize,
@RequestParam(required = false) String unitName,
@RequestParam(required = false) String country) {
try {
Page<GardsNuclearReactors> page = new Page<>(pageNum, pageSize);
LambdaQueryWrapper<GardsNuclearReactors> wrapper = new LambdaQueryWrapper<>();
if (unitName != null && !unitName.trim().isEmpty()) {
wrapper.eq(GardsNuclearReactors::getUnitName, unitName);
}
if (country != null && !country.trim().isEmpty()) {
wrapper.eq(GardsNuclearReactors::getCountry, country);
}
IPage<GardsNuclearReactors> pageResult = gardsNuclearReactorsService.page(page, wrapper);
return Result.OK(pageResult);
} catch (Exception e) {
log.error("查询失败: " + e.getMessage());
return Result.error("查询失败");
}
}
/**
* 组合条件查询
*
* @param unitName 名称
* @param country 国家
* @param reactorType reactorType
* @param reactorStatus reactorStatus
* @return list
*/
@GetMapping("/search")
@Operation(summary = "核设施信息组合条件查询")
public Result<List<GardsNuclearReactors>> search(@RequestParam(required = false) String unitName,
@RequestParam(required = false) String country,
@RequestParam(required = false) String reactorType,
@RequestParam(required = false) String reactorStatus) {
try {
List<GardsNuclearReactors> list = gardsNuclearReactorsService.getByConditions(unitName, country, reactorType, reactorStatus);
return Result.OK(list);
} catch (Exception e) {
log.error("条件查询失败: " + e.getMessage());
return Result.error("条件查询失败");
}
}
@AutoLog(value = "导出模版")
@Operation(summary = "核设施信息导出模版")
@GetMapping("/exportTemplate")
public void exportTemplate(HttpServletResponse response) throws IOException {
ExportParams params = new ExportParams();
params.setTitle("核设施信息");
params.setFixedTitle(true);
params.setTitleHeight((short) 8);
params.setType(ExcelType.XSSF);
ExcelExportUtil.exportExcel(params, GardsNuclearReactors.class, new ArrayList<>()).write(response.getOutputStream());
}
@AutoLog(value = "导出Excel")
@Operation(summary = "核设施信息导出Excel")
@GetMapping("/exportExcel")
public void exportExcel(HttpServletResponse response,
@RequestParam(required = false) String unitName,
@RequestParam(required = false) String country,
@RequestParam(required = false) String reactorType,
@RequestParam(required = false) String reactorStatus) throws IOException {
ExportParams params = new ExportParams();
params.setTitle("核设施信息");
params.setFixedTitle(true);
params.setTitleHeight((short) 8);
params.setType(ExcelType.XSSF);
List<GardsNuclearReactors> list = gardsNuclearReactorsService.getByConditions(unitName, country, reactorType, reactorStatus);
ExcelExportUtil.exportExcel(params, GardsNuclearReactors.class, list).write(response.getOutputStream());
}
/**
* 通过excel导入数据
*
* @param request
* @param
* @return
*/
@AutoLog(value = "GardsNuclearReactors")
@Operation(summary = "核设施信息导入数据")
@PostMapping(value = "/importExcel")
public Result<?> importExcel(HttpServletRequest request) {
// 1. 关键修复检查请求是否为 multipart 请求
// 如果前端没有使用 form-data 格式提交或者 Content-Type 不对这里会拦截
if (!(request instanceof MultipartHttpServletRequest)) {
return Result.error("请求不是文件上传格式,请检查 Content-Type 是否为 multipart/form-data");
}
// 2. 安全转换为 MultipartHttpServletRequest
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
// 3. 检查是否有文件
if (fileMap == null || fileMap.isEmpty()) {
return Result.error("未检测到上传的文件");
}
// 4. 遍历文件进行处理
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
// 获取上传文件对象
MultipartFile file = entity.getValue();
// 过滤空文件
if (file == null || file.isEmpty()) {
continue;
}
ImportParams params = new ImportParams();
// 设置标题行行数通常为1如果没有标题填0
params.setTitleRows(1);
// 设置表头行数通常为1
params.setHeadRows(1);
params.setNeedSave(true);
// 5.使用 try-with-resources 自动关闭流
try (InputStream inputStream = file.getInputStream()) {
// 使用 AutoPoi 工具类解析 Excel
List<GardsNuclearReactors> list = ExcelImportUtil.importExcel(inputStream, GardsNuclearReactors.class, params);
// 简单的校验防止空列表报错
if (list == null || list.isEmpty()) {
return Result.error("导入失败:文件中没有数据");
}
// 批量保存数据到数据库
boolean success = BizUpsertUtil.upsert(gardsNuclearReactorsService, list, GardsNuclearReactors::getUnitName);
//gardsNuclearReactorsService.saveBatch(list);
if (success) {
return Result.OK("文件导入成功!数据行数:" + list.size());
} else {
Result.error("文件导入失败");
}
} catch (Exception e) {
return Result.error("文件导入失败: " + e.getMessage());
}
}
return Result.error("文件导入失败,未找到有效文件!");
}
}

View File

@ -0,0 +1,260 @@
package org.jeecg.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.modules.base.entity.configuration.GardsNuclearReactors;
import org.jeecg.modules.base.entity.configuration.GardsNuclearReleaseRecords;
import org.jeecg.service.GardsNuclearReleaseService;
import org.jeecgframework.poi.excel.ExcelExportUtil;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.entity.enmus.ExcelType;
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 java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Slf4j
@RestController
@RequestMapping("/gardsNuclearReleaseRecords")
public class GardsNuclearReleaseController {
@Autowired
private GardsNuclearReleaseService gardsNuclearReleaseService;
/**
* 新增加核设施放射性排放记录信息
*/
@PostMapping("/create")
@Operation(summary = "新增加核设施放射性排放记录信息")
public Result<?> create(@RequestBody GardsNuclearReleaseRecords gardsNuclearReleaseRecords) {
try {
boolean success = gardsNuclearReleaseService.save(gardsNuclearReleaseRecords);
if (success) {
return Result.OK("添加成功", gardsNuclearReleaseRecords);
} else {
return Result.error("添加失败");
}
} catch (Exception e) {
log.error("create: " + e.getMessage());
return Result.error("添加失败");
}
}
/**
* 删除核设施放射性排放记录信息
*/
@DeleteMapping("/delete")
@Operation(summary = "删除核设施放射性排放记录信息")
public Result<?> deleteById(@RequestParam Integer id) {
try {
boolean success = gardsNuclearReleaseService.removeById(id);
if (success) {
return Result.OK("删除成功");
} else {
return Result.error("删除失败,可能数据不存在");
}
} catch (Exception e) {
log.error("deleteById: " + e.getMessage());
return Result.error("操作失败");
}
}
/**
* 更新核设施放射性排放记录信息
*/
@PutMapping("/update")
@Operation(summary = "更新核设施放射性排放记录信息")
public Result<?> update(@RequestBody GardsNuclearReleaseRecords gardsNuclearReleaseRecords) {
try {
boolean success = gardsNuclearReleaseService.updateById(gardsNuclearReleaseRecords);
if (success) {
return Result.OK("数据更新成功", gardsNuclearReleaseRecords);
} else {
return Result.error("数据更新失败");
}
} catch (Exception e) {
log.error("update: " + e.getMessage());
return Result.error("操作失败");
}
}
/**
* 查询核设施放射性排放记录信息
*/
@GetMapping("/queryById")
@Operation(summary = "查询核设施放射性排放记录信息")
public Result<GardsNuclearReleaseRecords> getById(@RequestParam Integer id) {
try {
GardsNuclearReleaseRecords nuclearReactors = gardsNuclearReleaseService.getById(id);
if (nuclearReactors != null) {
return Result.OK(nuclearReactors);
} else {
return Result.error("未找到数据");
}
} catch (Exception e) {
log.error("getById: " + e.getMessage());
return Result.error("查询失败");
}
}
/**
* 分页查询
*
* @param pageNum
* @param pageSize
* @param siteName
* @param nuclide
* @return
*/
@GetMapping("/page")
@Operation(summary = "核设施放射性排放记录分页查询")
public Result<IPage<GardsNuclearReleaseRecords>> page(
@RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "10") Integer pageSize,
@RequestParam(required = false) String siteName,
@RequestParam(required = false) String nuclide) {
try {
Page<GardsNuclearReleaseRecords> page = new Page<>(pageNum, pageSize);
LambdaQueryWrapper<GardsNuclearReleaseRecords> wrapper = new LambdaQueryWrapper<>();
if (siteName != null && !siteName.trim().isEmpty()) {
wrapper.eq(GardsNuclearReleaseRecords::getSiteName, siteName);
}
if (nuclide != null && !nuclide.trim().isEmpty()) {
wrapper.eq(GardsNuclearReleaseRecords::getNuclide, nuclide);
}
IPage<GardsNuclearReleaseRecords> pageResult = gardsNuclearReleaseService.page(page, wrapper);
return Result.OK(pageResult);
} catch (Exception e) {
log.error("page: " + e.getMessage());
return Result.error("查询失败:");
}
}
/**
* 组合条件查询
*
* @param siteName 地点名称
* @param nuclide 具体核素
* @param nuclideType 核素类型
* @param releaseType 释放类型
* @return
*/
@GetMapping("/search")
@Operation(summary = "核设施放射性排放记录组合条件查询")
public Result<List<GardsNuclearReleaseRecords>> search(
@RequestParam(required = false) String siteName,
@RequestParam(required = false) String nuclide,
@RequestParam(required = false) String nuclideType,
@RequestParam(required = false) String releaseType) {
try {
List<GardsNuclearReleaseRecords> list = gardsNuclearReleaseService.getByConditions(siteName, nuclide, nuclideType, releaseType);
return Result.OK(list);
} catch (Exception e) {
log.error("条件查询失败: " + e.getMessage());
return Result.error("查询失败");
}
}
@AutoLog(value = "导出模版")
@Operation(summary = "核设施放射性排放记录导出模版")
@GetMapping("/exportTemplate")
public void exportTemplate(HttpServletResponse response) throws IOException {
ExportParams params = new ExportParams();
params.setTitle("核设施放射性排放记录信息");
params.setFixedTitle(true);
params.setTitleHeight((short) 8);
params.setType(ExcelType.XSSF);
ExcelExportUtil.exportExcel(params, GardsNuclearReleaseRecords.class, new ArrayList<>()).write(response.getOutputStream());
}
@AutoLog(value = "导出Excel")
@Operation(summary = "核设施放射性排放记录导出Excel")
@GetMapping("/exportExcel")
public void exportExcel(HttpServletResponse response,
@RequestParam(required = false) String siteName,
@RequestParam(required = false) String nuclide,
@RequestParam(required = false) String nuclideType,
@RequestParam(required = false) String releaseType) throws IOException {
ExportParams params = new ExportParams();
params.setTitle("核设施放射性排放记录信息");
params.setFixedTitle(true);
params.setTitleHeight((short) 8);
params.setType(ExcelType.XSSF);
List<GardsNuclearReleaseRecords> list = gardsNuclearReleaseService.getByConditions(siteName, nuclide, nuclideType, releaseType);
ExcelExportUtil.exportExcel(params, GardsNuclearReleaseRecords.class, list).write(response.getOutputStream());
}
/**
* 通过excel导入数据
*
* @param request
* @param response
* @return
*/
@AutoLog(value = "GardsNuclearReleaseRecords")
@Operation(summary = "导入核设施放射性排放记录数据")
@PostMapping(value = "/importExcel")
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
// 1. 获取上传文件
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
// 2. 遍历文件进行处理
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
// 获取上传文件对象
MultipartFile file = entity.getValue();
ImportParams params = new ImportParams();
// 设置标题行行数通常为1如果没有标题填0
params.setTitleRows(1);
// 设置表头行数通常为1
params.setHeadRows(1);
params.setNeedSave(true);
try {
// 3. 使用 AutoPoi 工具类解析 Excel
List<GardsNuclearReleaseRecords> list = ExcelImportUtil.importExcel(file.getInputStream(), GardsNuclearReleaseRecords.class, params);
// 4. 批量保存数据到数据库
gardsNuclearReleaseService.saveBatch(list);
return Result.OK("文件导入成功!数据行数:" + list.size());
} catch (Exception e) {
return Result.error("文件导入失败:" + e.getMessage());
} finally {
try {
file.getInputStream().close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return Result.error("文件导入失败!");
}
}

View File

@ -0,0 +1,268 @@
package org.jeecg.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.modules.base.entity.configuration.GardsNuclearReleaseRecords;
import org.jeecg.modules.base.entity.configuration.GardsNuclearTestingPlant;
import org.jeecg.service.GardsNuclearReleaseService;
import org.jeecg.service.GardsNuclearTestingPlantService;
import org.jeecgframework.poi.excel.ExcelExportUtil;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.entity.enmus.ExcelType;
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 java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Slf4j
@RestController
@RequestMapping("/gardsNuclearTestingPlant")
public class GardsNuclearTestingPlantController {
@Autowired
private GardsNuclearTestingPlantService gardsNuclearTestingPlantService;
/**
* 新增 核试验信息
*/
@PostMapping("/create")
@Operation(summary = "新增核试验信息")
public Result<?> create(@RequestBody GardsNuclearTestingPlant gardsNuclearTestingPlant) {
try {
boolean success = gardsNuclearTestingPlantService.save(gardsNuclearTestingPlant);
if (success) {
return Result.OK("添加成功", gardsNuclearTestingPlant);
} else {
return Result.error("添加失败");
}
} catch (Exception e) {
log.error("create: " + e.getMessage());
return Result.error("添加失败");
}
}
/**
* 删除核设施放射性排放记录信息
*/
@DeleteMapping("/delete")
@Operation(summary = "删除核试验信息")
public Result<?> deleteById(@RequestParam Integer id) {
try {
boolean success = gardsNuclearTestingPlantService.removeById(id);
if (success) {
return Result.OK("删除成功");
} else {
return Result.error("删除失败,可能数据不存在");
}
} catch (Exception e) {
log.error("deleteById: " + e.getMessage());
return Result.error("操作失败:");
}
}
/**
* 更新核设施放射性排放记录信息
*/
@PutMapping("/update")
@Operation(summary = "更新核试验信息")
public Result<?> update(@RequestBody GardsNuclearTestingPlant gardsNuclearTestingPlant) {
try {
boolean success = gardsNuclearTestingPlantService.updateById(gardsNuclearTestingPlant);
if (success) {
return Result.OK("数据更新成功", gardsNuclearTestingPlant);
} else {
return Result.error("数据更新失败");
}
} catch (Exception e) {
log.error("update: " + e.getMessage());
return Result.error("操作失败");
}
}
/**
* 查询核设施放射性排放记录信息
*/
@GetMapping("/queryById")
@Operation(summary = "查询核试验信息")
public Result<GardsNuclearTestingPlant> getById(@RequestParam Integer id) {
try {
GardsNuclearTestingPlant nuclearReactors = gardsNuclearTestingPlantService.getById(id);
if (nuclearReactors != null) {
return Result.OK(nuclearReactors);
} else {
return Result.error("未找到数据");
}
} catch (Exception e) {
log.error("getById: " + e.getMessage());
return Result.error("查询失败:" + e.getMessage());
}
}
/**
* 分页查询
*
* @param pageNum
* @param pageSize
* @param name
* @param type
* @return
*/
@GetMapping("/page")
@Operation(summary = "核试验信息分页查询")
public Result<IPage<GardsNuclearTestingPlant>> page(
@RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "10") Integer pageSize,
@RequestParam(required = false) String name,
@RequestParam(required = false) String type) {
try {
Page<GardsNuclearTestingPlant> page = new Page<>(pageNum, pageSize);
LambdaQueryWrapper<GardsNuclearTestingPlant> wrapper = new LambdaQueryWrapper<>();
if (name != null && !name.trim().isEmpty()) {
wrapper.eq(GardsNuclearTestingPlant::getName, name);
}
if (type != null && !type.trim().isEmpty()) {
wrapper.eq(GardsNuclearTestingPlant::getType, type);
}
IPage<GardsNuclearTestingPlant> pageResult = gardsNuclearTestingPlantService.page(page, wrapper);
return Result.OK(pageResult);
} catch (Exception e) {
log.error("page: " + e.getMessage());
return Result.error("查询失败:" + e.getMessage());
}
}
/**
* 组合条件查询
*
* @param name 地点名称
* @param type 具体核素
* @return
*/
@GetMapping("/search")
@Operation(summary = "核试验信息组合条件查询")
public Result<List<GardsNuclearTestingPlant>> search(
@RequestParam(required = false) String name,
@RequestParam(required = false) String type) {
try {
List<GardsNuclearTestingPlant> list = gardsNuclearTestingPlantService.getByConditions(name, type);
return Result.OK(list);
} catch (Exception e) {
log.error("search: " + e.getMessage());
return Result.error("查询失败");
}
}
@AutoLog(value = "导出模版")
@Operation(summary = "核试验信息导出模版")
@GetMapping("/exportTemplate")
public void exportTemplate(HttpServletResponse response) throws IOException {
ExportParams params = new ExportParams();
params.setTitle("核试验信息");
params.setFixedTitle(true);
params.setTitleHeight((short) 8);
params.setType(ExcelType.XSSF);
ExcelExportUtil.exportExcel(params, GardsNuclearTestingPlant.class, new ArrayList<>()).write(response.getOutputStream());
}
@AutoLog(value = "导出Excel")
@Operation(summary = "核试验信息导出Excel")
@GetMapping("/exportExcel")
public void exportExcel(HttpServletResponse response,
@RequestParam(required = false) String name,
@RequestParam(required = false) String type) throws IOException {
ExportParams params = new ExportParams();
params.setTitle("核试验信息");
params.setFixedTitle(true);
params.setTitleHeight((short) 8);
params.setType(ExcelType.XSSF);
List<GardsNuclearTestingPlant> list = gardsNuclearTestingPlantService.getByConditions(name, type);
ExcelExportUtil.exportExcel(params, GardsNuclearTestingPlant.class, list).write(response.getOutputStream());
}
/**
* 通过excel导入数据
*
* @param request
* @return
*/
@AutoLog(value = "GardsNuclearTestingPlant")
@Operation(summary = "核试验信息导入数据")
@PostMapping(value = "/importExcel")
public Result<?> importExcel(HttpServletRequest request) {
// 1. 获取上传文件
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
// 2. 遍历文件进行处理
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
// 获取上传文件对象
MultipartFile file = entity.getValue();
ImportParams params = new ImportParams();
// 设置标题行行数通常为1如果没有标题填0
params.setTitleRows(1);
// 设置表头行数通常为1
params.setHeadRows(1);
params.setNeedSave(true);
try {
// 3. 使用 AutoPoi 工具类解析 Excel
List<GardsNuclearTestingPlant> list = ExcelImportUtil.importExcel(file.getInputStream(), GardsNuclearTestingPlant.class, params);
list.forEach(testingPlant -> {
if (StringUtils.isNotBlank(testingPlant.getInfo())) {
testingPlant.setInfo(testingPlant.getInfo()
.replace("&", "&amp;")
.replace("<", "&lt;")
.replace(">", "&gt;")
.replace("\"", "&quot;")
.replace("'", "&#39;")
.replaceAll("(?i)\\bmegatons?\\b", "Mt")
.replaceAll("(?i)\\bkilotons?\\b", "kt")
);
}
});
// 4. 批量保存数据到数据库
gardsNuclearTestingPlantService.saveBatch(list,5);
return Result.OK("文件导入成功!数据行数:" + list.size());
} catch (Exception e) {
return Result.error("文件导入失败:" + e.getMessage());
} finally {
try {
file.getInputStream().close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return Result.error("文件导入失败!");
}
}

View File

@ -0,0 +1,256 @@
package org.jeecg.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.modules.base.entity.configuration.GardsNuclearTestingPlant;
import org.jeecg.modules.base.entity.configuration.GardsResearchReactors;
import org.jeecg.modules.base.entity.configuration.GardsResearchReactors;
import org.jeecg.service.GardsResearchReactorsService;
import org.jeecg.service.GardsResearchReactorsService;
import org.jeecgframework.poi.excel.ExcelExportUtil;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.entity.enmus.ExcelType;
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 java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Slf4j
@RestController
@RequestMapping("/gardsResearchReactors")//C17ZNRJDMD6N
public class GardsResearchReactorsController {
@Autowired
private GardsResearchReactorsService gardsResearchReactorsService;
/**
* 新增信息
*/
@PostMapping("/create")
@Operation(summary = "新增反应堆信息")
public Result<?> create(@RequestBody GardsResearchReactors gardsResearchReactors) {
try {
boolean success = gardsResearchReactorsService.save(gardsResearchReactors);
if (success) {
return Result.OK("反应堆信息添加成功", gardsResearchReactors);
} else {
return Result.error("反应堆信息添加失败");
}
} catch (Exception e) {
log.error("create: " + e.getMessage());
return Result.error("添加失败");
}
}
/**
* 删除信息
*/
@DeleteMapping("/delete")
@Operation(summary = "删除反应堆信息")
public Result<?> deleteById(@RequestParam Integer id) {
try {
boolean success = gardsResearchReactorsService.removeById(id);
if (success) {
return Result.OK("删除成功");
} else {
return Result.error("删除失败,可能数据不存在");
}
} catch (Exception e) {
log.error("deleteById: " + e.getMessage());
return Result.error("操作失败");
}
}
/**
* 更新反应堆信息
*/
@PutMapping("/update")
@Operation(summary = "更新反应堆信息")
public Result<?> update(@RequestBody GardsResearchReactors gardsResearchReactors) {
try {
boolean success = gardsResearchReactorsService.updateById(gardsResearchReactors);
if (success) {
return Result.OK("数据更新成功", gardsResearchReactors);
} else {
return Result.error("数据更新失败");
}
} catch (Exception e) {
log.error("update: " + e.getMessage());
return Result.error("操作失败");
}
}
/**
* 查询信息
*/
@GetMapping("/queryById")
@Operation(summary = "查询反应堆信息")
public Result<GardsResearchReactors> getById(@RequestParam Integer id) {
try {
GardsResearchReactors nuclearReactors = gardsResearchReactorsService.getById(id);
if (nuclearReactors != null) {
return Result.OK(nuclearReactors);
} else {
return Result.error("未找到数据");
}
} catch (Exception e) {
log.error("getById: " + e.getMessage());
return Result.error("查询失败");
}
}
/**
* 分页查询
*
* @param pageNum
* @param pageSize
* @param facilityName
* @param country
* @return
*/
@GetMapping("/page")
@Operation(summary = "反应堆信息分页查询")
public Result<IPage<GardsResearchReactors>> page(
@RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "10") Integer pageSize,
@RequestParam(required = false) String facilityName,
@RequestParam(required = false) String country) {
try {
Page<GardsResearchReactors> page = new Page<>(pageNum, pageSize);
LambdaQueryWrapper<GardsResearchReactors> wrapper = new LambdaQueryWrapper<>();
if (facilityName != null && !facilityName.trim().isEmpty()) {
wrapper.eq(GardsResearchReactors::getFacilityName, facilityName);
}
if (country != null && !country.trim().isEmpty()) {
wrapper.eq(GardsResearchReactors::getCountry, country);
}
IPage<GardsResearchReactors> pageResult = gardsResearchReactorsService.page(page, wrapper);
return Result.OK(pageResult);
} catch (Exception e) {
log.error("page: " + e.getMessage());
return Result.error("查询失败" );
}
}
/**
* 组合条件查询
*
* @param facilityName 地点名称
* @param country 具体核素
* @return
*/
@GetMapping("/search")
@Operation(summary = "反应堆信息组合条件查询")
public Result<List<GardsResearchReactors>> search(@RequestParam(required = false) String facilityName,
@RequestParam(required = false) String country,
@RequestParam(required = false) String reactorType,
@RequestParam(required = false) String status) {
try {
List<GardsResearchReactors> list = gardsResearchReactorsService.getByConditions(facilityName, country, reactorType, status);
return Result.OK(list);
} catch (Exception e) {
log.error("search: " + e.getMessage());
return Result.error("查询失败");
}
}
@AutoLog(value = "导出模版")
@Operation(summary = "反应堆信息导出模版")
@GetMapping("/exportTemplate")
public void exportTemplate(HttpServletResponse response) throws IOException {
ExportParams params = new ExportParams();
params.setTitle("反应堆信息");
params.setFixedTitle(true);
params.setTitleHeight((short) 8);
params.setType(ExcelType.XSSF);
ExcelExportUtil.exportExcel(params, GardsResearchReactors.class, new ArrayList<>()).write(response.getOutputStream());
}
@AutoLog(value = "导出Excel")
@Operation(summary = "反应堆信息导出Excel")
@GetMapping("/exportExcel")
public void exportExcel(HttpServletResponse response,
@RequestParam(required = false) String facilityName,
@RequestParam(required = false) String country,
@RequestParam(required = false) String reactorType,
@RequestParam(required = false) String status) throws IOException {
ExportParams params = new ExportParams();
params.setTitle("反应堆信息");
params.setFixedTitle(true);
params.setTitleHeight((short) 8);
params.setType(ExcelType.XSSF);
List<GardsResearchReactors> list = gardsResearchReactorsService.getByConditions(facilityName, country, reactorType, status);
ExcelExportUtil.exportExcel(params, GardsResearchReactors.class, list).write(response.getOutputStream());
}
/**
* 通过excel导入数据
*
* @param request
* @return
*/
@AutoLog(value = "GardsResearchReactors")
@Operation(summary = "反应堆信息导入数据")
@PostMapping(value = "/importExcel")
public Result<?> importExcel(HttpServletRequest request) {
// 1. 获取上传文件
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
// 2. 遍历文件进行处理
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
// 获取上传文件对象
MultipartFile file = entity.getValue();
ImportParams params = new ImportParams();
// 设置标题行行数通常为1如果没有标题填0
params.setTitleRows(1);
// 设置表头行数通常为1
params.setHeadRows(1);
params.setNeedSave(true);
try {
// 3. 使用 AutoPoi 工具类解析 Excel
List<GardsResearchReactors> list = ExcelImportUtil.importExcel(file.getInputStream(), GardsResearchReactors.class, params);
// 4. 批量保存数据到数据库
gardsResearchReactorsService.saveBatch(list);
return Result.OK("文件导入成功!数据行数:" + list.size());
} catch (Exception e) {
return Result.error("文件导入失败:" + e.getMessage());
} finally {
try {
file.getInputStream().close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return Result.error("文件导入失败!");
}
}

View File

@ -0,0 +1,252 @@
package org.jeecg.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.modules.base.entity.configuration.GardsResearchReactors;
import org.jeecg.modules.base.entity.configuration.GardsStations;
import org.jeecg.service.GardsResearchReactorsService;
import org.jeecg.service.GardsStationsService;
import org.jeecgframework.poi.excel.ExcelExportUtil;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.entity.enmus.ExcelType;
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 java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@Slf4j
@RestController
@RequestMapping("/gardsStations")
public class GardsStationsController {
@Autowired
private GardsStationsService gardsStationsService;
/**
* 新增信息
*/
@PostMapping("/create")
@Operation(summary = "新增台站信息")
public Result<?> create(@RequestBody GardsStations gardsStations) {
try {
boolean success = gardsStationsService.save(gardsStations);
if (success) {
return Result.OK("添加成功", gardsStations);
} else {
return Result.error("添加失败");
}
} catch (Exception e) {
log.error("create: " + e.getMessage());
return Result.error("添加失败");
}
}
/**
* 删除信息
*/
@DeleteMapping("/delete")
@Operation(summary = "删除台站信息")
public Result<?> deleteById(@RequestParam Integer stationId) {
try {
boolean success = gardsStationsService.removeById(stationId);
if (success) {
return Result.OK("删除成功");
} else {
return Result.error("删除失败,可能数据不存在");
}
} catch (Exception e) {
log.error("deleteById: " + e.getMessage());
return Result.error("操作失败");
}
}
/**
* 更新信息
*/
@PutMapping("/update")
@Operation(summary = "更新台站信息")
public Result<?> update(@RequestBody GardsStations gardsStations) {
try {
boolean success = gardsStationsService.updateById(gardsStations);
if (success) {
return Result.OK("数据更新成功", gardsStations);
} else {
return Result.error("数据更新失败");
}
} catch (Exception e) {
log.error("update: " + e.getMessage());
return Result.error("操作失败");
}
}
/**
* 查询信息
*/
@GetMapping("/queryById")
@Operation(summary = "查询台站信息")
public Result<GardsStations> getById(@RequestParam Integer stationId) {
try {
GardsStations nuclearReactors = gardsStationsService.getById(stationId);
if (nuclearReactors != null) {
return Result.OK(nuclearReactors);
} else {
return Result.error("未找到数据");
}
} catch (Exception e) {
log.error("getById: " + e.getMessage());
return Result.error("查询失败" );
}
}
/**
* 分页查询
*
* @param pageNum
* @param pageSize
* @param stationCode
* @param countryCode
* @return
*/
@GetMapping("/page")
@Operation(summary = "台站分页查询")
public Result<IPage<GardsStations>> page(
@RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "10") Integer pageSize,
@RequestParam(required = false) String stationCode,
@RequestParam(required = false) String countryCode) {
try {
Page<GardsStations> page = new Page<>(pageNum, pageSize);
LambdaQueryWrapper<GardsStations> wrapper = new LambdaQueryWrapper<>();
if (stationCode != null && !stationCode.trim().isEmpty()) {
wrapper.eq(GardsStations::getStationCode, stationCode);
}
if (countryCode != null && !countryCode.trim().isEmpty()) {
wrapper.eq(GardsStations::getCountryCode, countryCode);
}
IPage<GardsStations> pageResult = gardsStationsService.page(page, wrapper);
return Result.OK(pageResult);
} catch (Exception e) {
log.error("page: " + e.getMessage());
return Result.error("查询失败");
}
}
/**
* 组合条件查询
*
* @param stationCode 地点名称
* @param type 类型
* @return
*/
@GetMapping("/search")
@Operation(summary = "台站组合条件查询")
public Result<List<GardsStations>> search(@RequestParam(required = false) String stationCode,
@RequestParam(required = false) String type,
@RequestParam(required = false) String status,
@RequestParam(required = false) String countryCode) {
try {
List<GardsStations> list = gardsStationsService.getByConditions(stationCode, type, status, countryCode);
return Result.OK(list);
} catch (Exception e) {
log.error("search: " + e.getMessage());
return Result.error("查询失败");
}
}
@AutoLog(value = "导出模版")
@Operation(summary = "台站导出模版")
@GetMapping("/exportTemplate")
public void exportTemplate(HttpServletResponse response) throws IOException {
ExportParams params = new ExportParams();
params.setTitle("台站信息");
params.setFixedTitle(true);
params.setTitleHeight((short) 8);
params.setType(ExcelType.XSSF);
ExcelExportUtil.exportExcel(params, GardsStations.class, new ArrayList<>()).write(response.getOutputStream());
}
@AutoLog(value = "导出Excel")
@Operation(summary = "台站导出Excel")
@GetMapping("/exportExcel")
public void exportExcel(HttpServletResponse response,
@RequestParam(required = false) String stationCode,
@RequestParam(required = false) String type,
@RequestParam(required = false) String status,
@RequestParam(required = false) String countryCode) throws IOException {
ExportParams params = new ExportParams();
params.setTitle("台站信息");
params.setFixedTitle(true);
params.setTitleHeight((short) 8);
params.setType(ExcelType.XSSF);
List<GardsStations> list = gardsStationsService.getByConditions(stationCode, type, status, countryCode);
ExcelExportUtil.exportExcel(params, GardsStations.class, list).write(response.getOutputStream());
}
/**
* 通过excel导入数据
*
* @param request
* @return
*/
@AutoLog(value = "GardsStations")
@Operation(summary = "导入台站数据")
@PostMapping(value = "/importExcel")
public Result<?> importExcel(HttpServletRequest request) {
// 1. 获取上传文件
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
// 2. 遍历文件进行处理
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
// 获取上传文件对象
MultipartFile file = entity.getValue();
ImportParams params = new ImportParams();
// 设置标题行行数通常为1如果没有标题填0
params.setTitleRows(1);
// 设置表头行数通常为1
params.setHeadRows(1);
params.setNeedSave(true);
try {
// 3. 使用 AutoPoi 工具类解析 Excel
List<GardsStations> list = ExcelImportUtil.importExcel(file.getInputStream(), GardsStations.class, params);
// 4. 批量保存数据到数据库
gardsStationsService.saveBatch(list);
return Result.OK("文件导入成功!数据行数:" + list.size());
} catch (Exception e) {
return Result.error("文件导入失败:" + e.getMessage());
} finally {
try {
file.getInputStream().close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return Result.error("文件导入失败!");
}
}

View File

@ -0,0 +1,35 @@
package org.jeecg.service;
import com.baomidou.mybatisplus.extension.service.IService;
import org.jeecg.modules.base.entity.configuration.GardsAccelerator;
import java.util.List;
public interface GardsAcceleratorService extends IService <GardsAccelerator> {
/**
* 根据设施代码查询设施信息
*/
GardsAccelerator getByFacilityCode(String facilityCode);
/**
* 根据国家查询设施列表
*/
List<GardsAccelerator> getByCountry(String country);
/**
* 根据运行状态查询设施列表
*/
List<GardsAccelerator> getByOperationalStatus(Integer isOperational);
/**
* 根据分类查询设施列表
*/
List<GardsAccelerator> getByCategory(String category);
/**
* 条件查询国家 + 运行状态
*/
List<GardsAccelerator> getByCountryAndStatus(String country, Integer isOperational);
}

View File

@ -0,0 +1,47 @@
package org.jeecg.service;
import com.baomidou.mybatisplus.extension.service.IService;
import org.jeecg.modules.base.entity.configuration.GardsCorrectionFactor;
import java.util.List;
public interface GardsCorrectionFactorService extends IService<GardsCorrectionFactor> {
/**
* 根据站点代码查询校正因子列表
*/
List<GardsCorrectionFactor> getByStationCode(String stationCode);
/**
* 根据探测器代码查询校正因子列表
*/
List<GardsCorrectionFactor> getByDetectorCode(String detectorCode);
/**
* 根据站点和探测器代码查询校正因子
*/
List<GardsCorrectionFactor> getByStationAndDetector(String stationCode, String detectorCode);
/**
* 根据制造商查询校正因子列表
*/
List<GardsCorrectionFactor> getByManufacturer(String manufacturer);
/**
* 根据型号查询校正因子列表
*/
List<GardsCorrectionFactor> getByModel(String model);
/**
* 条件组合查询
*/
List<GardsCorrectionFactor> getByConditions(String stationCode, String detectorCode,
String manufacturer, String model);
/**
* 批量更新校正因子
*/
boolean updateBatchCorrectionFactors(List<GardsCorrectionFactor> factors);
}

View File

@ -0,0 +1,30 @@
package org.jeecg.service;
import com.baomidou.mybatisplus.extension.service.IService;
import org.jeecg.modules.base.entity.configuration.GardsNuclearFuelFacilities;
import java.util.List;
/**
* 核燃料设施信息
*/
public interface GardsNuclearFuelFacilityService extends IService<GardsNuclearFuelFacilities> {
/**
* 根据设施名称模糊查询
*/
List<GardsNuclearFuelFacilities> getByFacilityNameLike(String facilityName);
/**
* 多条件组合查询
*/
List<GardsNuclearFuelFacilities> getByConditions(String facilityType, String facilityStatus, String country,String facilityName, String fuelType);
/**
* 批量更新设施状态
*/
boolean updateBatchFacilityStatus(List<Long> ids, String status);
}

View File

@ -0,0 +1,21 @@
package org.jeecg.service;
import com.baomidou.mybatisplus.extension.service.IService;
import org.jeecg.modules.base.entity.configuration.GardsNuclearReactors;
import org.jeecg.modules.base.mapper.GardsNuclearReactorsMapper;
import java.util.List;
public interface GardsNuclearReactorsService extends IService<GardsNuclearReactors> {
/**
* 多条件组合查询
* @return List
*/
List<GardsNuclearReactors> getByConditions(String unitName,String country,String reactorType,String reactorStatus);
void saveOrUpdateBatchByUniqueFields(List<GardsNuclearReactors> list);
}

View File

@ -0,0 +1,21 @@
package org.jeecg.service;
import com.baomidou.mybatisplus.extension.service.IService;
import org.jeecg.modules.base.entity.configuration.GardsNuclearReactors;
import org.jeecg.modules.base.entity.configuration.GardsNuclearReleaseRecords;
import java.util.List;
public interface GardsNuclearReleaseService extends IService<GardsNuclearReleaseRecords> {
/**
* 多条件组合查询
* @param siteName 站点/电厂名称
* @param nuclide 具体核素
* @param nuclideType 核素类别
* @param releaseType 排放类型
* @return List
*/
List<GardsNuclearReleaseRecords> getByConditions(String siteName, String nuclide, String nuclideType, String releaseType);
}

View File

@ -0,0 +1,20 @@
package org.jeecg.service;
import com.baomidou.mybatisplus.extension.service.IService;
import org.jeecg.modules.base.entity.configuration.GardsNuclearReleaseRecords;
import org.jeecg.modules.base.entity.configuration.GardsNuclearTestingPlant;
import java.util.List;
public interface GardsNuclearTestingPlantService extends IService<GardsNuclearTestingPlant> {
/**
* 多条件组合查询
* @param name 名称
* @param type 类型
* @return List
*/
List<GardsNuclearTestingPlant> getByConditions(String name, String type);
}

View File

@ -0,0 +1,19 @@
package org.jeecg.service;
import com.baomidou.mybatisplus.extension.service.IService;
import org.jeecg.modules.base.entity.configuration.GardsNuclearTestingPlant;
import org.jeecg.modules.base.entity.configuration.GardsResearchReactors;
import java.util.List;
public interface GardsResearchReactorsService extends IService<GardsResearchReactors> {
/**
* 多条件组合查询
* @param facilityName 名称
* @param country 类型
* @return List
*/
List<GardsResearchReactors> getByConditions(String facilityName, String country,String reactorType,String status);
}

View File

@ -0,0 +1,17 @@
package org.jeecg.service;
import com.baomidou.mybatisplus.extension.service.IService;
import org.jeecg.modules.base.entity.configuration.GardsResearchReactors;
import org.jeecg.modules.base.entity.configuration.GardsStations;
import java.util.List;
public interface GardsStationsService extends IService<GardsStations> {
/**
* 多条件组合查询
* @param stationCode 名称
* @param type 类型
* @return List
*/
List<GardsStations> getByConditions(String stationCode, String type, String status,String countryCode);
}

View File

@ -0,0 +1,52 @@
package org.jeecg.service.impl;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.base.entity.configuration.GardsAccelerator;
import org.jeecg.modules.base.mapper.GardsAcceleratorMapper;
import org.jeecg.service.GardsAcceleratorService;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
@DS("ora")
public class GardsAcceleratorServiceImpl extends ServiceImpl<GardsAcceleratorMapper,GardsAccelerator> implements GardsAcceleratorService {
@Override
public GardsAccelerator getByFacilityCode(String facilityCode) {
LambdaQueryWrapper<GardsAccelerator> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(GardsAccelerator::getFacilityCode, facilityCode);
return this.getOne(wrapper);
}
@Override
public List<GardsAccelerator> getByCountry(String country) {
LambdaQueryWrapper<GardsAccelerator> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(GardsAccelerator::getCountry, country);
return this.list(wrapper);
}
@Override
public List<GardsAccelerator> getByOperationalStatus(Integer isOperational) {
LambdaQueryWrapper<GardsAccelerator> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(GardsAccelerator::getIsOperational, isOperational);
return this.list(wrapper);
}
@Override
public List<GardsAccelerator> getByCategory(String category) {
LambdaQueryWrapper<GardsAccelerator> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(GardsAccelerator::getCategory, category);
return this.list(wrapper);
}
@Override
public List<GardsAccelerator> getByCountryAndStatus(String country, Integer isOperational) {
LambdaQueryWrapper<GardsAccelerator> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(GardsAccelerator::getCountry, country)
.eq(GardsAccelerator::getIsOperational, isOperational);
return this.list(wrapper);
}
}

View File

@ -0,0 +1,79 @@
package org.jeecg.service.impl;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.base.entity.configuration.GardsCorrectionFactor;
import org.jeecg.modules.base.mapper.GardsCorrectionFactorMapper;
import org.jeecg.service.GardsCorrectionFactorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
@DS("ora")
public class GardsCorrectionFactorServiceImpl extends ServiceImpl<GardsCorrectionFactorMapper,GardsCorrectionFactor> implements GardsCorrectionFactorService {
@Override
public List<GardsCorrectionFactor> getByStationCode(String stationCode) {
LambdaQueryWrapper<GardsCorrectionFactor> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(GardsCorrectionFactor::getStationCode, stationCode);
return this.list(wrapper);
}
@Override
public List<GardsCorrectionFactor> getByDetectorCode(String detectorCode) {
LambdaQueryWrapper<GardsCorrectionFactor> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(GardsCorrectionFactor::getDetectorCode, detectorCode);
return this.list(wrapper);
}
@Override
public List<GardsCorrectionFactor> getByStationAndDetector(String stationCode, String detectorCode) {
LambdaQueryWrapper<GardsCorrectionFactor> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(GardsCorrectionFactor::getStationCode, stationCode)
.eq(GardsCorrectionFactor::getDetectorCode, detectorCode);
return this.list(wrapper);
}
@Override
public List<GardsCorrectionFactor> getByManufacturer(String manufacturer) {
LambdaQueryWrapper<GardsCorrectionFactor> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(GardsCorrectionFactor::getManufacturer, manufacturer);
return this.list(wrapper);
}
@Override
public List<GardsCorrectionFactor> getByModel(String model) {
LambdaQueryWrapper<GardsCorrectionFactor> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(GardsCorrectionFactor::getModel, model);
return this.list(wrapper);
}
@Override
public List<GardsCorrectionFactor> getByConditions(String stationCode, String detectorCode,
String manufacturer, String model) {
LambdaQueryWrapper<GardsCorrectionFactor> wrapper = new LambdaQueryWrapper<>();
if (stationCode != null && !stationCode.trim().isEmpty()) {
wrapper.eq(GardsCorrectionFactor::getStationCode, stationCode);
}
if (detectorCode != null && !detectorCode.trim().isEmpty()) {
wrapper.eq(GardsCorrectionFactor::getDetectorCode, detectorCode);
}
if (manufacturer != null && !manufacturer.trim().isEmpty()) {
wrapper.eq(GardsCorrectionFactor::getManufacturer, manufacturer);
}
if (model != null && !model.trim().isEmpty()) {
wrapper.eq(GardsCorrectionFactor::getModel, model);
}
return this.list(wrapper);
}
@Override
public boolean updateBatchCorrectionFactors(List<GardsCorrectionFactor> factors) {
return this.updateBatchById(factors);
}
}

View File

@ -0,0 +1,56 @@
package org.jeecg.service.impl;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.base.entity.configuration.GardsNuclearFuelFacilities;
import org.jeecg.modules.base.mapper.GardsNuclearFuelFacilitiesMapper;
import org.jeecg.service.GardsNuclearFuelFacilityService;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
@DS("ora")
public class GardsNuclearFuelFacilityServiceImpl extends ServiceImpl<GardsNuclearFuelFacilitiesMapper,GardsNuclearFuelFacilities> implements GardsNuclearFuelFacilityService {
@Override
public List<GardsNuclearFuelFacilities> getByFacilityNameLike(String facilityName) {
LambdaQueryWrapper<GardsNuclearFuelFacilities> wrapper = new LambdaQueryWrapper<>();
wrapper.like(GardsNuclearFuelFacilities::getFacilityName, facilityName);
return this.list(wrapper);
}
@Override
public List<GardsNuclearFuelFacilities> getByConditions(String facilityType, String facilityStatus, String country,String facilityName, String fuelType) {
LambdaQueryWrapper<GardsNuclearFuelFacilities> wrapper = new LambdaQueryWrapper<>();
if (facilityType != null && !facilityType.trim().isEmpty()) {
wrapper.eq(GardsNuclearFuelFacilities::getFacilityType, facilityType);
}
if (facilityStatus != null && !facilityStatus.trim().isEmpty()) {
wrapper.eq(GardsNuclearFuelFacilities::getFacilityStatus, facilityStatus);
}
if (country != null && !country.trim().isEmpty()) {
wrapper.eq(GardsNuclearFuelFacilities::getCountry, country);
}
if (facilityName != null && !facilityName.trim().isEmpty()) {
wrapper.eq(GardsNuclearFuelFacilities::getFacilityName, facilityName);
}
if (fuelType != null && !fuelType.trim().isEmpty()) {
wrapper.eq(GardsNuclearFuelFacilities::getFuelType, fuelType);
}
return this.list(wrapper);
}
@Override
public boolean updateBatchFacilityStatus(List<Long> ids, String status) {
LambdaQueryWrapper<GardsNuclearFuelFacilities> wrapper = new LambdaQueryWrapper<>();
wrapper.in(GardsNuclearFuelFacilities::getId, ids);
GardsNuclearFuelFacilities updateEntity = new GardsNuclearFuelFacilities();
return this.update(updateEntity, wrapper);
}
}

View File

@ -0,0 +1,39 @@
package org.jeecg.service.impl;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.base.entity.configuration.GardsNuclearReactors;
import org.jeecg.modules.base.mapper.GardsNuclearReactorsMapper;
import org.jeecg.service.GardsNuclearReactorsService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Service
@DS("ora")
public class GardsNuclearReactorsServiceImpl extends ServiceImpl<GardsNuclearReactorsMapper, GardsNuclearReactors> implements GardsNuclearReactorsService {
@Override
public List<GardsNuclearReactors> getByConditions(String unitName, String country, String reactorType, String reactorStatus) {
LambdaQueryWrapper<GardsNuclearReactors> wrapper = new LambdaQueryWrapper<>();
if (unitName != null && !unitName.trim().isEmpty()) {
wrapper.eq(GardsNuclearReactors::getUnitName, unitName);
}
if (country != null && !country.trim().isEmpty()) {
wrapper.eq(GardsNuclearReactors::getCountry, country);
}
if (reactorType != null && !reactorType.trim().isEmpty()) {
wrapper.eq(GardsNuclearReactors::getReactorType, reactorType);
}
if (reactorStatus != null && !reactorStatus.trim().isEmpty()) {
wrapper.eq(GardsNuclearReactors::getReactorStatus, reactorStatus);
}
return this.list(wrapper);
}
@Transactional(rollbackFor = Exception.class)
@Override
public void saveOrUpdateBatchByUniqueFields(List<GardsNuclearReactors> list) {
this.saveOrUpdateBatch(list);
}
}

View File

@ -0,0 +1,34 @@
package org.jeecg.service.impl;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.base.entity.configuration.GardsNuclearReactors;
import org.jeecg.modules.base.entity.configuration.GardsNuclearReleaseRecords;
import org.jeecg.modules.base.mapper.GardsNuclearReleaseRecordsMapper;
import org.jeecg.service.GardsNuclearReleaseService;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
@DS("ora")
public class GardsNuclearReleaseServiceImpl extends ServiceImpl<GardsNuclearReleaseRecordsMapper, GardsNuclearReleaseRecords> implements GardsNuclearReleaseService {
@Override
public List<GardsNuclearReleaseRecords> getByConditions(String siteName, String nuclide, String nuclideType, String releaseType) {
LambdaQueryWrapper<GardsNuclearReleaseRecords> queryWrapper = new LambdaQueryWrapper<>();
if (siteName != null && !siteName.trim().isEmpty()) {
queryWrapper.eq(GardsNuclearReleaseRecords::getSiteName, siteName);
}
if (nuclide != null && !nuclide.trim().isEmpty()) {
queryWrapper.eq(GardsNuclearReleaseRecords::getNuclide, nuclide);
}
if (nuclideType != null && !nuclideType.trim().isEmpty()) {
queryWrapper.eq(GardsNuclearReleaseRecords::getNuclideType, nuclideType);
}
if (releaseType != null && !releaseType.trim().isEmpty()) {
queryWrapper.eq(GardsNuclearReleaseRecords::getReleaseType, releaseType);
}
return this.list(queryWrapper);
}
}

View File

@ -0,0 +1,29 @@
package org.jeecg.service.impl;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.base.entity.configuration.GardsNuclearTestingPlant;
import org.jeecg.modules.base.mapper.GardsNuclearTestingPlantMapper;
import org.jeecg.service.GardsNuclearTestingPlantService;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
@DS("ora")
public class GardsNuclearTestingPlantServiceImpl extends ServiceImpl<GardsNuclearTestingPlantMapper, GardsNuclearTestingPlant> implements GardsNuclearTestingPlantService {
@Override
public List<GardsNuclearTestingPlant> getByConditions(String name, String type) {
LambdaQueryWrapper<GardsNuclearTestingPlant> query = new LambdaQueryWrapper<>();
if (name != null&&!name.trim().isEmpty()) {
query.eq(GardsNuclearTestingPlant::getName, name);
}
if (type != null&&!type.trim().isEmpty()) {
query.eq(GardsNuclearTestingPlant::getType, type);
}
return this.list(query);
}
}

View File

@ -0,0 +1,34 @@
package org.jeecg.service.impl;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.base.entity.configuration.GardsNuclearTestingPlant;
import org.jeecg.modules.base.entity.configuration.GardsResearchReactors;
import org.jeecg.modules.base.mapper.GardsResearchReactorsMapper;
import org.jeecg.service.GardsResearchReactorsService;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
@DS("ora")
public class GardsResearchReactorsServiceImpl extends ServiceImpl<GardsResearchReactorsMapper, GardsResearchReactors> implements GardsResearchReactorsService {
@Override
public List<GardsResearchReactors> getByConditions(String facilityName, String country,String reactorType,String status) {
LambdaQueryWrapper<GardsResearchReactors> query = new LambdaQueryWrapper<>();
if (facilityName != null&&!facilityName.trim().isEmpty()) {
query.eq(GardsResearchReactors::getFacilityName, facilityName);
}
if (country != null&&!country.trim().isEmpty()) {
query.eq(GardsResearchReactors::getCountry, country);
}
if (reactorType != null&&!reactorType.trim().isEmpty()) {
query.eq(GardsResearchReactors::getReactorType, reactorType);
}
if (status != null&&!status.trim().isEmpty()) {
query.eq(GardsResearchReactors::getStatus, status);
}
return this.list(query);
}
}

View File

@ -0,0 +1,37 @@
package org.jeecg.service.impl;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.base.entity.configuration.GardsResearchReactors;
import org.jeecg.modules.base.entity.configuration.GardsStations;
import org.jeecg.modules.base.mapper.GardsStationsMapper;
import org.jeecg.service.GardsStationsService;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
@DS("ora")
public class GardsStationsServiceImpl extends ServiceImpl<GardsStationsMapper, GardsStations> implements GardsStationsService {
@Override
public List<GardsStations> getByConditions(String stationCode, String type, String status,String countryCode) {
LambdaQueryWrapper<GardsStations> query = new LambdaQueryWrapper<>();
if (stationCode != null&&!stationCode.trim().isEmpty()) {
query.eq(GardsStations::getStationCode, stationCode);
}
if (type != null&&!type.trim().isEmpty()) {
query.eq(GardsStations::getType, type);
}
if (status != null&&!status.trim().isEmpty()) {
query.eq(GardsStations::getStatus, status);
}
if (countryCode != null&&!countryCode.trim().isEmpty()) {
query.eq(GardsStations::getCountryCode, countryCode);
}
return this.list(query);
}
}

View File

@ -0,0 +1,170 @@
package org.jeecg.util;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.baomidou.mybatisplus.extension.service.IService;
import java.lang.reflect.Field;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
public class BizUpsertUtil {
@SafeVarargs
public static <T> boolean upsert(IService<T> service, List<T> list,
SFunction<T, ?>... uniqueColumns) {
return upsert(service, list, Arrays.asList(uniqueColumns));
}
//
public static <T> boolean upsertByColumnNames(IService<T> service, List<T> list,
String... uniqueColumnNames) {
if (list.isEmpty()) return true;
String firstCol = uniqueColumnNames[0];
// 提取第一个字段的值用于 IN 查询反射取值
List<Object> firstValues = list.stream()
.map(entity -> getFieldValue(entity, firstCol))
.filter(Objects::nonNull)
.distinct()
.toList();
// QueryWrapper完全不涉及 SFunction
List<T> existList = service.list(new QueryWrapper<T>()
.in(firstCol, firstValues)
.select(uniqueColumnNames) // 可选只查需要的字段
);
Map<String, T> existMap = existList.stream()
.collect(Collectors.toMap(
e -> buildKey(e, uniqueColumnNames),
e -> e
));
List<T> insert = new ArrayList<>();
List<T> update = new ArrayList<>();
for (T entity : list) {
String key = buildKey(entity, uniqueColumnNames);
T db = existMap.get(key);
if (db == null) {
insert.add(entity);
} else {
copyId(db, entity);
update.add(entity);
}
}
boolean ok1 = insert.isEmpty() || service.saveBatch(insert, 1000);
boolean ok2 = update.isEmpty() || service.updateBatchById(update, 1000);
System.out.println("插入:" + insert.size() + " 更新:" + update.size());
return ok1 && ok2;
}
// 反射取字段值支持驼峰转下划线
private static <T> Object getFieldValue(T entity, String fieldName) {
try {
Field field = entity.getClass().getDeclaredField(fieldName);
field.setAccessible(true);
return field.get(entity);
} catch (Exception e) {
// 如果字段名是 username但数据库是 user_name可以自动转换
String dbColumn = StringUtils.camelToUnderline(fieldName);
try {
Field field = entity.getClass().getDeclaredField(dbColumn);
field.setAccessible(true);
return field.get(entity);
} catch (Exception ex) {
return null;
}
}
}
// 构建 key
private static <T> String buildKey(T entity, String[] columnNames) {
return Arrays.stream(columnNames)
.map(col -> Objects.toString(getFieldValue(entity, col), "NULL"))
.collect(Collectors.joining("::"));
}
public static <T> boolean upsert(IService<T> service, List<T> list,
List<SFunction<T, ?>> uniqueColumns) {
if (list == null || list.isEmpty()) return true;
// 1. 提取所有业务唯一键用于匹配
Map<String, T> keyToEntity = new HashMap<>();
for (T entity : list) {
String key = buildKey(entity, uniqueColumns);
keyToEntity.put(key, entity);
}
// 2. 用第一个字段去数据库查已存在的记录关键修复
SFunction<T, ?> firstCol = uniqueColumns.get(0);
List<?> firstColumnValues = list.stream()
.map(firstCol)
.filter(Objects::nonNull)
.distinct()
.toList();
List<T> existList = service.list(
(new LambdaQueryWrapper<T>()).in( firstCol, firstColumnValues)
);
// 3. 构建已存在记录的 key 映射
Map<String, T> existMap = existList.stream()
.collect(Collectors.toMap(
e -> buildKey(e, uniqueColumns),
e -> e
));
List<T> insertList = new ArrayList<>();
List<T> updateList = new ArrayList<>();
for (T entity : list) {
String key = buildKey(entity, uniqueColumns);
T dbEntity = existMap.get(key);
if (dbEntity == null) {
insertList.add(entity);
} else {
// 把数据库的主键 ID 复制回来最简单方式
copyId(dbEntity, entity);
updateList.add(entity);
}
}
boolean ok1 = insertList.isEmpty() || service.saveBatch(insertList, 1000);
boolean ok2 = updateList.isEmpty() || service.updateBatchById(updateList, 1000);
System.out.println("插入: " + insertList.size() + ", 更新: " + updateList.size());
return ok1 && ok2;
}
// 拼接 keyvalue1::value2
private static <T> String buildKey(T entity, List<SFunction<T, ?>> columns) {
return columns.stream()
.map(col -> {
Object v = col.apply(entity);
return v == null ? "NULL" : v.toString();
})
.collect(Collectors.joining("::"));
}
// 复制主键假设主键字段叫 id改成你的就行
private static <T> void copyId(T from, T to) {
try {
var fromId = from.getClass().getMethod("getId").invoke(from);
if (fromId != null) {
var setId = to.getClass().getMethod("setId", fromId.getClass());
setId.invoke(to, fromId);
}
} catch (Exception ignored) {
// 如果没有 getId/setId 方法就忽略或者你改成自己的主键名
}
}
}

View File

@ -0,0 +1,23 @@
package org.jeecg.util;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.util.Date;
@Component
public class DbMetaObjectHandler implements MetaObjectHandler {
@Override
public void insertFill(MetaObject metaObject) {
this.strictInsertFill(metaObject, "moddate", java.util.Date.class, new Date());
//this.strictInsertFill(metaObject, "updatedAt", java.util.Date.class, new Date());
}
@Override
public void updateFill(MetaObject metaObject) {
LocalDateTime now = LocalDateTime.now();
this.strictUpdateFill(metaObject, "moddate", java.util.Date.class, new Date());
}
}