!65 refactor(bgpartymatter): 合并重复的导入导出接口,通过参数区分会议类型
* refactor(bgpartymatter): 合并重复的导入导出接口,通过参数区分会议类型 * feat(excel): 导入支持收集实体 ID 和注入默认值,新增 BgPartymatter 常量类
This commit is contained in:
+31
-4
@@ -204,6 +204,16 @@ public class JeecgController<T, S extends IService<T>> {
|
||||
* 通过EasyExcel导入数据,基于 @Excel 注解读取列配置
|
||||
*/
|
||||
protected Result<?> importExcelByEasyExcel(HttpServletRequest request, Class<T> clazz) {
|
||||
return importExcelByEasyExcel(request, clazz, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过EasyExcel导入数据,基于 @Excel 注解读取列配置
|
||||
*
|
||||
* @param defaultValues 为每行数据注入的默认字段值(key 为实体属性名),在 saveBatch 前设置,可为 null
|
||||
*/
|
||||
protected Result<?> importExcelByEasyExcel(HttpServletRequest request, Class<T> clazz,
|
||||
Map<String, Object> defaultValues) {
|
||||
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
||||
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
||||
MultipartFile file = fileMap.values().stream().findFirst().orElse(null);
|
||||
@@ -213,21 +223,38 @@ public class JeecgController<T, S extends IService<T>> {
|
||||
try (InputStream inputStream = file.getInputStream()) {
|
||||
long start = System.currentTimeMillis();
|
||||
List<ExcelAnnotationUtils.ValidationError> errors = new ArrayList<>();
|
||||
List<String> importedIds = new ArrayList<>();
|
||||
int total = ExcelAnnotationUtils.read(
|
||||
inputStream,
|
||||
clazz,
|
||||
batch -> service.saveBatch(batch),
|
||||
batch -> {
|
||||
if (defaultValues != null && !defaultValues.isEmpty()) {
|
||||
for (T item : batch) {
|
||||
for (Map.Entry<String, Object> entry : defaultValues.entrySet()) {
|
||||
try {
|
||||
PropertyUtils.setProperty(item, entry.getKey(), entry.getValue());
|
||||
} catch (Exception e) {
|
||||
log.error("【EasyExcel导入】注入默认值失败, field: {}, value: {}",
|
||||
entry.getKey(), entry.getValue(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
service.saveBatch(batch);
|
||||
},
|
||||
BATCH_NUM,
|
||||
errors::addAll,
|
||||
dictQuery());
|
||||
log.info("【EasyExcel导入】导入完成, 数据行数: {}, 耗时: {}毫秒", total, System.currentTimeMillis() - start);
|
||||
dictQuery(),
|
||||
batch -> batch.forEach(item -> importedIds.add(getId(item))));
|
||||
log.info("【EasyExcel导入】导入完成, 数据行数: {}, 导入ID数: {}, 耗时: {}毫秒",
|
||||
total, importedIds.size(), System.currentTimeMillis() - start);
|
||||
if (!errors.isEmpty()) {
|
||||
for (ExcelAnnotationUtils.ValidationError err : errors) {
|
||||
log.error("【EasyExcel导入】校验失败, 行号: {}, 错误: {}", err.row(), err.messages());
|
||||
}
|
||||
return Result.error("文件导入失败: 存在" + errors.size() + "行数据校验不通过,请修改后重新导入", errors);
|
||||
}
|
||||
return Result.ok("文件导入成功!数据行数:" + total);
|
||||
return Result.OK("文件导入成功!数据行数:" + total, importedIds);
|
||||
} catch (DuplicateKeyException e) {
|
||||
log.error("【EasyExcel导入】存在重复数据", e);
|
||||
return Result.error("文件导入失败:有重复数据!");
|
||||
|
||||
+15
-1
@@ -177,6 +177,20 @@ public final class ExcelAnnotationUtils {
|
||||
Consumer<List<T>> batchHandler, int batchSize,
|
||||
Consumer<List<ValidationError>> errorHandler,
|
||||
DictQuery dictQuery) {
|
||||
return read(inputStream, clazz, batchHandler, batchSize, errorHandler, dictQuery, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 Excel 输入流分批导入数据,基于 @ExcelColumn 注解读取列配置。
|
||||
*
|
||||
* @param dictQuery 字典查询接口,可为 null(不启用字典翻译)
|
||||
* @param idCollector 导入成功后的实体 ID 收集器,在每批 batchHandler 执行后调用(此时实体已被保存,ID 已回填),可为 null
|
||||
*/
|
||||
public static <T> int read(InputStream inputStream, Class<T> clazz,
|
||||
Consumer<List<T>> batchHandler, int batchSize,
|
||||
Consumer<List<ValidationError>> errorHandler,
|
||||
DictQuery dictQuery,
|
||||
Consumer<List<T>> idCollector) {
|
||||
|
||||
List<ColumnMeta> columns = parseColumns(clazz, dictQuery);
|
||||
|
||||
@@ -189,7 +203,7 @@ public final class ExcelAnnotationUtils {
|
||||
}
|
||||
|
||||
ExcelImportListener<T> listener = new ExcelImportListener<>(
|
||||
clazz, batchSize, nameToCol, displayToCode, batchHandler, errorHandler
|
||||
clazz, batchSize, nameToCol, displayToCode, batchHandler, idCollector, errorHandler
|
||||
);
|
||||
|
||||
EasyExcel.read(inputStream, listener).sheet().doRead();
|
||||
|
||||
+14
-3
@@ -21,6 +21,7 @@ public class ExcelImportListener<T> implements ReadListener<Map<Integer, String>
|
||||
private final Class<T> clazz;
|
||||
private final int batchSize;
|
||||
private final Consumer<List<T>> batchHandler;
|
||||
private final Consumer<List<T>> idCollector;
|
||||
private final Consumer<List<ValidationError>> errorHandler;
|
||||
|
||||
// 外部传入的数据支撑
|
||||
@@ -40,12 +41,14 @@ public class ExcelImportListener<T> implements ReadListener<Map<Integer, String>
|
||||
|
||||
public ExcelImportListener(Class<T> clazz, int batchSize,
|
||||
Map<String, ColumnMeta> nameToCol, Map<String, String> displayToCode,
|
||||
Consumer<List<T>> batchHandler, Consumer<List<ValidationError>> errorHandler) {
|
||||
Consumer<List<T>> batchHandler, Consumer<List<T>> idCollector,
|
||||
Consumer<List<ValidationError>> errorHandler) {
|
||||
this.clazz = clazz;
|
||||
this.batchSize = batchSize;
|
||||
this.nameToCol = nameToCol;
|
||||
this.displayToCode = displayToCode;
|
||||
this.batchHandler = batchHandler;
|
||||
this.idCollector = idCollector;
|
||||
this.errorHandler = errorHandler;
|
||||
this.batch = batchHandler != null ? new ArrayList<>(batchSize) : null;
|
||||
this.errorBatch = new ArrayList<>(batchSize);
|
||||
@@ -138,7 +141,11 @@ public class ExcelImportListener<T> implements ReadListener<Map<Integer, String>
|
||||
if (batchHandler != null) {
|
||||
batch.add(obj);
|
||||
if (batch.size() >= batchSize) {
|
||||
batchHandler.accept(new ArrayList<>(batch));
|
||||
List<T> batchCopy = new ArrayList<>(batch);
|
||||
batchHandler.accept(batchCopy);
|
||||
if (idCollector != null) {
|
||||
idCollector.accept(batchCopy);
|
||||
}
|
||||
batch.clear();
|
||||
}
|
||||
}
|
||||
@@ -162,7 +169,11 @@ public class ExcelImportListener<T> implements ReadListener<Map<Integer, String>
|
||||
@Override
|
||||
public void doAfterAllAnalysed(AnalysisContext context) {
|
||||
if (batchHandler != null && batch != null && !batch.isEmpty()) {
|
||||
batchHandler.accept(new ArrayList<>(batch));
|
||||
List<T> batchCopy = new ArrayList<>(batch);
|
||||
batchHandler.accept(batchCopy);
|
||||
if (idCollector != null) {
|
||||
idCollector.accept(batchCopy);
|
||||
}
|
||||
batch.clear();
|
||||
}
|
||||
if (!errorBatch.isEmpty()) {
|
||||
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
package org.jeecg.modules.demo.bgpartymatter.constant;
|
||||
|
||||
/**
|
||||
* 党委/所务会事项模块常量类
|
||||
*/
|
||||
public final class BgPartymatterConstant {
|
||||
|
||||
private BgPartymatterConstant() {
|
||||
throw new UnsupportedOperationException("This is a constant class and cannot be instantiated");
|
||||
}
|
||||
|
||||
/** 会议类型 */
|
||||
public static final class MeetingType {
|
||||
/** 党委会 */
|
||||
public static final String PARTY = "party";
|
||||
/** 所务会 */
|
||||
public static final String OFFICE = "office";
|
||||
}
|
||||
|
||||
/** 是/否(字典 yn,replace {"是_1","否_0"}) */
|
||||
public static final class Yn {
|
||||
/** 是 */
|
||||
public static final String YES = "1";
|
||||
/** 否 */
|
||||
public static final String NO = "0";
|
||||
}
|
||||
|
||||
/** 密级(字典 secret_level) */
|
||||
public static final class SecretLevel {
|
||||
/** 一般 */
|
||||
public static final String NORMAL = "0";
|
||||
/** 秘密 */
|
||||
public static final String SECRET = "1";
|
||||
/** 机密 */
|
||||
public static final String CONFIDENTIAL = "2";
|
||||
/** 绝密 */
|
||||
public static final String TOP_SECRET = "3";
|
||||
}
|
||||
|
||||
/** 删除标记 */
|
||||
public static final class DelFlag {
|
||||
/** 未删除 */
|
||||
public static final String NORMAL = "0";
|
||||
/** 已删除 */
|
||||
public static final String DELETED = "1";
|
||||
}
|
||||
|
||||
/** 类字段名 */
|
||||
public static final class ClassFieldName {
|
||||
/** 未删除 */
|
||||
public static final String MEETING_TYPE_NAME = "meeting_type";
|
||||
/** 已删除 */
|
||||
public static final String DEL_FLAG_NAME = "del_flag";
|
||||
}
|
||||
}
|
||||
+238
-206
@@ -14,17 +14,22 @@ import org.jeecg.modules.bg.xispeak.entity.BgXiSpeak;
|
||||
import org.jeecg.modules.demo.dqinspecttask.entity.DqInspectTask;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.jeecg.common.util.oConvertUtils;
|
||||
import org.jeecg.modules.demo.bgpartymatter.dto.BgPartymatterBpmSaveDTO;
|
||||
import org.jeecg.modules.demo.bgpartymatter.entity.BgPartymatterFeedback;
|
||||
import org.jeecg.modules.demo.bgpartymatter.entity.BgPartymatter;
|
||||
import org.jeecg.modules.demo.bgpartymatter.service.IBgPartymatterService;
|
||||
import org.jeecg.modules.demo.bgpartymatter.service.IBgPartymatterFeedbackService;
|
||||
import org.jeecg.modules.demo.bgpartymatter.constant.BgPartymatterConstant;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import org.jeecg.common.aspect.annotation.AutoLog;
|
||||
@@ -37,80 +42,84 @@ import org.jeecgframework.poi.excel.entity.ImportParams;
|
||||
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.shiro.authz.annotation.Logical;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
/**
|
||||
|
||||
/**
|
||||
* @Description: 党委会
|
||||
* @Author: jeecg-boot
|
||||
* @Date: 2026-04-16
|
||||
* @Date: 2026-04-16
|
||||
* @Version: V1.0
|
||||
*/
|
||||
@Tag(name="党委会")
|
||||
@Tag(name = "党委会")
|
||||
@RestController
|
||||
@RequestMapping("/bgpartymatter/bgPartymatter")
|
||||
@Slf4j
|
||||
public class BgPartymatterController extends JeecgController<BgPartymatter, IBgPartymatterService> {
|
||||
|
||||
private static final String DEFAULT_MEETING_TYPE = "party";
|
||||
@Autowired
|
||||
private IBgPartymatterService bgPartymatterService;
|
||||
|
||||
@Autowired
|
||||
private IBgPartymatterService bgPartymatterService;
|
||||
@Autowired
|
||||
private IBgPartymatterFeedbackService bgPartymatterFeedbackService;
|
||||
|
||||
@Autowired
|
||||
private IBgPartymatterFeedbackService bgPartymatterFeedbackService;
|
||||
@Autowired
|
||||
protected RuntimeService runtimeService;
|
||||
|
||||
@Autowired
|
||||
protected RuntimeService runtimeService;
|
||||
/*---------------------------------主表处理-begin-------------------------------------*/
|
||||
|
||||
/*---------------------------------主表处理-begin-------------------------------------*/
|
||||
|
||||
/**
|
||||
* 分页列表查询
|
||||
* @param bgPartymatter
|
||||
* @param pageNo
|
||||
* @param pageSize
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
//@AutoLog(value = "党委会-分页列表查询")
|
||||
@Operation(summary="党委会-分页列表查询")
|
||||
@GetMapping(value = "/list")
|
||||
public Result<IPage<BgPartymatter>> queryPageList(BgPartymatter bgPartymatter,
|
||||
@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
|
||||
@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
|
||||
HttpServletRequest req) {
|
||||
QueryWrapper<BgPartymatter> queryWrapper = QueryGenerator.initQueryWrapper(bgPartymatter, req.getParameterMap());
|
||||
Page<BgPartymatter> page = new Page<BgPartymatter>(pageNo, pageSize);
|
||||
IPage<BgPartymatter> pageList = bgPartymatterService.page(page, queryWrapper);
|
||||
return Result.OK(pageList);
|
||||
}
|
||||
/**
|
||||
* 分页列表查询
|
||||
*
|
||||
* @param bgPartymatter
|
||||
* @param pageNo
|
||||
* @param pageSize
|
||||
* @param req
|
||||
* @return
|
||||
*/
|
||||
//@AutoLog(value = "党委会-分页列表查询")
|
||||
@Operation(summary = "党委会-分页列表查询")
|
||||
@GetMapping(value = "/list")
|
||||
public Result<IPage<BgPartymatter>> queryPageList(BgPartymatter bgPartymatter,
|
||||
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
|
||||
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
|
||||
HttpServletRequest req) {
|
||||
QueryWrapper<BgPartymatter> queryWrapper = QueryGenerator.initQueryWrapper(bgPartymatter, req.getParameterMap());
|
||||
Page<BgPartymatter> page = new Page<BgPartymatter>(pageNo, pageSize);
|
||||
IPage<BgPartymatter> pageList = bgPartymatterService.page(page, queryWrapper);
|
||||
return Result.OK(pageList);
|
||||
}
|
||||
|
||||
|
||||
@GetMapping(value = "/queryById")
|
||||
public Result<BgPartymatter> queryById(@RequestParam(name="id", required=true) String id) {
|
||||
BgPartymatter bgPartymatter = bgPartymatterService.getById(id);
|
||||
if (bgPartymatter == null) {
|
||||
return Result.error("未找到对应数据");
|
||||
}
|
||||
return Result.OK(bgPartymatter);
|
||||
}
|
||||
/**
|
||||
* 添加
|
||||
@GetMapping(value = "/queryById")
|
||||
public Result<BgPartymatter> queryById(@RequestParam(name = "id", required = true) String id) {
|
||||
BgPartymatter bgPartymatter = bgPartymatterService.getById(id);
|
||||
if (bgPartymatter == null) {
|
||||
return Result.error("未找到对应数据");
|
||||
}
|
||||
return Result.OK(bgPartymatter);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @param bgPartymatter
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "党委会-添加")
|
||||
@Operation(summary="党委会-添加")
|
||||
@Operation(summary = "党委会-添加")
|
||||
@RequiresPermissions(value = {"bgpartymatter:bg_partymatter:add", "bgofficematter:bg_officematter:add"}, logical = Logical.OR)
|
||||
@PostMapping(value = "/add")
|
||||
public Result<String> add(@RequestBody BgPartymatter bgPartymatter) {
|
||||
if (oConvertUtils.isEmpty(bgPartymatter.getDelFlag())) {
|
||||
bgPartymatter.setDelFlag("0");
|
||||
bgPartymatter.setDelFlag(BgPartymatterConstant.DelFlag.NORMAL);
|
||||
}
|
||||
fillDefaultMeetingTypeForCreate(bgPartymatter);
|
||||
fillGeneratedNumber(bgPartymatter);
|
||||
@@ -119,27 +128,30 @@ public class BgPartymatterController extends JeecgController<BgPartymatter, IBgP
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* 编辑
|
||||
*
|
||||
* @param bgPartymatter
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "党委会-编辑")
|
||||
@Operation(summary="党委会-编辑")
|
||||
@Operation(summary = "党委会-编辑")
|
||||
@RequiresPermissions(value = {"bgpartymatter:bg_partymatter:edit", "bgofficematter:bg_officematter:edit"}, logical = Logical.OR)
|
||||
@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
|
||||
@RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
|
||||
public Result<String> edit(@RequestBody BgPartymatter bgPartymatter) {
|
||||
fillMeetingTypeForUpdate(bgPartymatter);
|
||||
fillGeneratedNumber(bgPartymatter);
|
||||
bgPartymatterService.updateById(bgPartymatter);
|
||||
return Result.OK("编辑成功!");
|
||||
}
|
||||
/**
|
||||
* 编辑
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
*
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "保存业务数据同时更新流程变量jsonData")
|
||||
@Operation(summary="保存业务数据同时更新流程变量jsonData")
|
||||
@Operation(summary = "保存业务数据同时更新流程变量jsonData")
|
||||
@PostMapping(value = "/saveBpmForm")
|
||||
public Result<String> saveBpmForm(@RequestBody BgPartymatterBpmSaveDTO dto) {
|
||||
if (dto == null || dto.getFormData() == null || oConvertUtils.isEmpty(dto.getFormData().getId())) {
|
||||
@@ -161,7 +173,7 @@ public class BgPartymatterController extends JeecgController<BgPartymatter, IBgP
|
||||
*/
|
||||
private void fillDefaultMeetingTypeForCreate(BgPartymatter bgPartymatter) {
|
||||
if (bgPartymatter != null && oConvertUtils.isEmpty(bgPartymatter.getMeetingType())) {
|
||||
bgPartymatter.setMeetingType(DEFAULT_MEETING_TYPE);
|
||||
bgPartymatter.setMeetingType(BgPartymatterConstant.MeetingType.PARTY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -179,7 +191,7 @@ public class BgPartymatterController extends JeecgController<BgPartymatter, IBgP
|
||||
return;
|
||||
}
|
||||
}
|
||||
bgPartymatter.setMeetingType(DEFAULT_MEETING_TYPE);
|
||||
bgPartymatter.setMeetingType(BgPartymatterConstant.MeetingType.PARTY);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -196,45 +208,49 @@ public class BgPartymatterController extends JeecgController<BgPartymatter, IBgP
|
||||
|
||||
/**
|
||||
* 通过id删除
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "党委会-通过id删除")
|
||||
@Operation(summary="党委会-通过id删除")
|
||||
@Operation(summary = "党委会-通过id删除")
|
||||
@RequiresPermissions(value = {"bgpartymatter:bg_partymatter:delete", "bgofficematter:bg_officematter:delete"}, logical = Logical.OR)
|
||||
@DeleteMapping(value = "/delete")
|
||||
public Result<String> delete(@RequestParam(name="id",required=true) String id) {
|
||||
public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
|
||||
bgPartymatterService.delMain(id);
|
||||
return Result.OK("删除成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "党委会-批量删除")
|
||||
@Operation(summary="党委会-批量删除")
|
||||
@Operation(summary = "党委会-批量删除")
|
||||
@RequiresPermissions(value = {"bgpartymatter:bg_partymatter:deleteBatch", "bgofficematter:bg_officematter:deleteBatch"}, logical = Logical.OR)
|
||||
@DeleteMapping(value = "/deleteBatch")
|
||||
public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
|
||||
public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
|
||||
this.bgPartymatterService.delBatchMain(Arrays.asList(ids.split(",")));
|
||||
return Result.OK("批量删除成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions(value = {"bgpartymatter:bg_partymatter:exportXls", "bgofficematter:bg_officematter:exportXls"}, logical = Logical.OR)
|
||||
@RequestMapping(value = "/exportXls")
|
||||
public ModelAndView exportXls(HttpServletRequest request, BgPartymatter bgPartymatter) {
|
||||
String exportName = "office".equals(bgPartymatter.getMeetingType()) ? "所务会" : "党委会";
|
||||
String exportName = BgPartymatterConstant.MeetingType.OFFICE.equals(bgPartymatter.getMeetingType()) ? "所务会" : "党委会";
|
||||
return super.exportXls(request, bgPartymatter, BgPartymatter.class, exportName);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@RequiresPermissions(value = {"bgpartymatter:bg_partymatter:importExcel", "bgofficematter:bg_officematter:importExcel"}, logical = Logical.OR)
|
||||
@@ -242,191 +258,207 @@ public class BgPartymatterController extends JeecgController<BgPartymatter, IBgP
|
||||
public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
|
||||
return super.importExcel(request, response, BgPartymatter.class);
|
||||
}
|
||||
/*---------------------------------主表处理-end-------------------------------------*/
|
||||
|
||||
/*---------------------------------主表处理-end-------------------------------------*/
|
||||
|
||||
|
||||
/*--------------------------------子表处理-党委会反馈表-begin----------------------------------------------*/
|
||||
/**
|
||||
* 通过主表ID查询
|
||||
* @return
|
||||
*/
|
||||
//@AutoLog(value = "党委会反馈表-通过主表ID查询")
|
||||
@Operation(summary="党委会反馈表-通过主表ID查询")
|
||||
@GetMapping(value = "/listBgPartymatterFeedbackByMainId")
|
||||
|
||||
/**
|
||||
* 通过主表ID查询
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
//@AutoLog(value = "党委会反馈表-通过主表ID查询")
|
||||
@Operation(summary = "党委会反馈表-通过主表ID查询")
|
||||
@GetMapping(value = "/listBgPartymatterFeedbackByMainId")
|
||||
public Result<IPage<BgPartymatterFeedback>> listBgPartymatterFeedbackByMainId(BgPartymatterFeedback bgPartymatterFeedback,
|
||||
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
|
||||
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
|
||||
HttpServletRequest req) {
|
||||
@RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
|
||||
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
|
||||
HttpServletRequest req) {
|
||||
QueryWrapper<BgPartymatterFeedback> queryWrapper = QueryGenerator.initQueryWrapper(bgPartymatterFeedback, req.getParameterMap());
|
||||
Page<BgPartymatterFeedback> page = new Page<BgPartymatterFeedback>(pageNo, pageSize);
|
||||
IPage<BgPartymatterFeedback> pageList = bgPartymatterFeedbackService.page(page, queryWrapper);
|
||||
return Result.OK(pageList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
* @param bgPartymatterFeedback
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "党委会反馈表-添加")
|
||||
@Operation(summary="党委会反馈表-添加")
|
||||
@PostMapping(value = "/addBgPartymatterFeedback")
|
||||
public Result<String> addBgPartymatterFeedback(@RequestBody BgPartymatterFeedback bgPartymatterFeedback) {
|
||||
if (oConvertUtils.isEmpty(bgPartymatterFeedback.getDelFlag())) {
|
||||
bgPartymatterFeedback.setDelFlag("0");
|
||||
}
|
||||
bgPartymatterFeedbackService.save(bgPartymatterFeedback);
|
||||
return Result.OK("添加成功!");
|
||||
}
|
||||
/**
|
||||
* 添加
|
||||
*
|
||||
* @param bgPartymatterFeedback
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "党委会反馈表-添加")
|
||||
@Operation(summary = "党委会反馈表-添加")
|
||||
@PostMapping(value = "/addBgPartymatterFeedback")
|
||||
public Result<String> addBgPartymatterFeedback(@RequestBody BgPartymatterFeedback bgPartymatterFeedback) {
|
||||
if (oConvertUtils.isEmpty(bgPartymatterFeedback.getDelFlag())) {
|
||||
bgPartymatterFeedback.setDelFlag(BgPartymatterConstant.DelFlag.NORMAL);
|
||||
}
|
||||
bgPartymatterFeedbackService.save(bgPartymatterFeedback);
|
||||
return Result.OK("添加成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑
|
||||
* @param bgPartymatterFeedback
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "党委会反馈表-编辑")
|
||||
@Operation(summary="党委会反馈表-编辑")
|
||||
@RequestMapping(value = "/editBgPartymatterFeedback", method = {RequestMethod.PUT,RequestMethod.POST})
|
||||
public Result<String> editBgPartymatterFeedback(@RequestBody BgPartymatterFeedback bgPartymatterFeedback) {
|
||||
bgPartymatterFeedbackService.updateById(bgPartymatterFeedback);
|
||||
return Result.OK("编辑成功!");
|
||||
}
|
||||
* 编辑
|
||||
*
|
||||
* @param bgPartymatterFeedback
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "党委会反馈表-编辑")
|
||||
@Operation(summary = "党委会反馈表-编辑")
|
||||
@RequestMapping(value = "/editBgPartymatterFeedback", method = {RequestMethod.PUT, RequestMethod.POST})
|
||||
public Result<String> editBgPartymatterFeedback(@RequestBody BgPartymatterFeedback bgPartymatterFeedback) {
|
||||
bgPartymatterFeedbackService.updateById(bgPartymatterFeedback);
|
||||
return Result.OK("编辑成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id删除
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "党委会反馈表-通过id删除")
|
||||
@Operation(summary="党委会反馈表-通过id删除")
|
||||
@DeleteMapping(value = "/deleteBgPartymatterFeedback")
|
||||
public Result<String> deleteBgPartymatterFeedback(@RequestParam(name="id",required=true) String id) {
|
||||
bgPartymatterFeedbackService.removeById(id);
|
||||
return Result.OK("删除成功!");
|
||||
}
|
||||
/**
|
||||
* 通过id删除
|
||||
*
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "党委会反馈表-通过id删除")
|
||||
@Operation(summary = "党委会反馈表-通过id删除")
|
||||
@DeleteMapping(value = "/deleteBgPartymatterFeedback")
|
||||
public Result<String> deleteBgPartymatterFeedback(@RequestParam(name = "id", required = true) String id) {
|
||||
bgPartymatterFeedbackService.removeById(id);
|
||||
return Result.OK("删除成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "党委会反馈表-批量删除")
|
||||
@Operation(summary="党委会反馈表-批量删除")
|
||||
@DeleteMapping(value = "/deleteBatchBgPartymatterFeedback")
|
||||
public Result<String> deleteBatchBgPartymatterFeedback(@RequestParam(name="ids",required=true) String ids) {
|
||||
this.bgPartymatterFeedbackService.removeByIds(Arrays.asList(ids.split(",")));
|
||||
return Result.OK("批量删除成功!");
|
||||
}
|
||||
/**
|
||||
* 批量删除
|
||||
*
|
||||
* @param ids
|
||||
* @return
|
||||
*/
|
||||
@AutoLog(value = "党委会反馈表-批量删除")
|
||||
@Operation(summary = "党委会反馈表-批量删除")
|
||||
@DeleteMapping(value = "/deleteBatchBgPartymatterFeedback")
|
||||
public Result<String> deleteBatchBgPartymatterFeedback(@RequestParam(name = "ids", required = true) String ids) {
|
||||
this.bgPartymatterFeedbackService.removeByIds(Arrays.asList(ids.split(",")));
|
||||
return Result.OK("批量删除成功!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/exportBgPartymatterFeedback")
|
||||
public ModelAndView exportBgPartymatterFeedback(HttpServletRequest request, BgPartymatterFeedback bgPartymatterFeedback) {
|
||||
// Step.1 组装查询条件
|
||||
QueryWrapper<BgPartymatterFeedback> queryWrapper = QueryGenerator.initQueryWrapper(bgPartymatterFeedback, request.getParameterMap());
|
||||
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||
// Step.1 组装查询条件
|
||||
QueryWrapper<BgPartymatterFeedback> queryWrapper = QueryGenerator.initQueryWrapper(bgPartymatterFeedback, request.getParameterMap());
|
||||
LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||
|
||||
// Step.2 获取导出数据
|
||||
List<BgPartymatterFeedback> pageList = bgPartymatterFeedbackService.list(queryWrapper);
|
||||
List<BgPartymatterFeedback> exportList = null;
|
||||
// Step.2 获取导出数据
|
||||
List<BgPartymatterFeedback> pageList = bgPartymatterFeedbackService.list(queryWrapper);
|
||||
List<BgPartymatterFeedback> exportList = null;
|
||||
|
||||
// 过滤选中数据
|
||||
String selections = request.getParameter("selections");
|
||||
if (oConvertUtils.isNotEmpty(selections)) {
|
||||
List<String> selectionList = Arrays.asList(selections.split(","));
|
||||
exportList = pageList.stream().filter(item -> selectionList.contains(item.getId())).collect(Collectors.toList());
|
||||
} else {
|
||||
exportList = pageList;
|
||||
}
|
||||
// 过滤选中数据
|
||||
String selections = request.getParameter("selections");
|
||||
if (oConvertUtils.isNotEmpty(selections)) {
|
||||
List<String> selectionList = Arrays.asList(selections.split(","));
|
||||
exportList = pageList.stream().filter(item -> selectionList.contains(item.getId())).collect(Collectors.toList());
|
||||
} else {
|
||||
exportList = pageList;
|
||||
}
|
||||
|
||||
// Step.3 AutoPoi 导出Excel
|
||||
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
|
||||
//此处设置的filename无效,前端会重更新设置一下
|
||||
mv.addObject(NormalExcelConstants.FILE_NAME, "党委会反馈表");
|
||||
mv.addObject(NormalExcelConstants.CLASS, BgPartymatterFeedback.class);
|
||||
mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("党委会反馈表报表", "导出人:" + sysUser.getRealname(), "党委会反馈表"));
|
||||
mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
|
||||
return mv;
|
||||
// Step.3 AutoPoi 导出Excel
|
||||
ModelAndView mv = new ModelAndView(new JeecgEntityExcelView());
|
||||
//此处设置的filename无效,前端会重更新设置一下
|
||||
mv.addObject(NormalExcelConstants.FILE_NAME, "党委会反馈表");
|
||||
mv.addObject(NormalExcelConstants.CLASS, BgPartymatterFeedback.class);
|
||||
mv.addObject(NormalExcelConstants.PARAMS, new ExportParams("党委会反馈表报表", "导出人:" + sysUser.getRealname(), "党委会反馈表"));
|
||||
mv.addObject(NormalExcelConstants.DATA_LIST, exportList);
|
||||
return mv;
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/importBgPartymatterFeedback/{mainId}")
|
||||
public Result<?> importBgPartymatterFeedback(HttpServletRequest request, HttpServletResponse response, @PathVariable("mainId") String mainId) {
|
||||
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
||||
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
||||
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
||||
// 获取上传文件对象
|
||||
MultipartFile file = entity.getValue();
|
||||
ImportParams params = new ImportParams();
|
||||
params.setTitleRows(2);
|
||||
params.setHeadRows(1);
|
||||
params.setNeedSave(true);
|
||||
try {
|
||||
List<BgPartymatterFeedback> list = ExcelImportUtil.importExcel(file.getInputStream(), BgPartymatterFeedback.class, params);
|
||||
for (BgPartymatterFeedback temp : list) {
|
||||
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
|
||||
Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
|
||||
for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
|
||||
// 获取上传文件对象
|
||||
MultipartFile file = entity.getValue();
|
||||
ImportParams params = new ImportParams();
|
||||
params.setTitleRows(2);
|
||||
params.setHeadRows(1);
|
||||
params.setNeedSave(true);
|
||||
try {
|
||||
List<BgPartymatterFeedback> list = ExcelImportUtil.importExcel(file.getInputStream(), BgPartymatterFeedback.class, params);
|
||||
for (BgPartymatterFeedback temp : list) {
|
||||
temp.setMainId(mainId);
|
||||
}
|
||||
long start = System.currentTimeMillis();
|
||||
bgPartymatterFeedbackService.saveBatch(list);
|
||||
log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒");
|
||||
return Result.OK("文件导入成功!数据行数:" + list.size());
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return Result.error("文件导入失败:" + e.getMessage());
|
||||
} finally {
|
||||
try {
|
||||
file.getInputStream().close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return Result.error("文件导入失败!");
|
||||
}
|
||||
long start = System.currentTimeMillis();
|
||||
bgPartymatterFeedbackService.saveBatch(list);
|
||||
log.info("消耗时间" + (System.currentTimeMillis() - start) + "毫秒");
|
||||
return Result.OK("文件导入成功!数据行数:" + list.size());
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return Result.error("文件导入失败:" + e.getMessage());
|
||||
} finally {
|
||||
try {
|
||||
file.getInputStream().close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return Result.error("文件导入失败!");
|
||||
}
|
||||
|
||||
/*--------------------------------子表处理-党委会反馈表-end----------------------------------------------*/
|
||||
/**
|
||||
* 通过EasyExcel校验数据,只返回校验结果,不保存到数据库
|
||||
*/
|
||||
@RequiresPermissions("bgpartymatter:bg_partymatter:importExcel")
|
||||
@RequestMapping(value = "/checkExcelByEasyExcel", method = RequestMethod.POST)
|
||||
public Result<?> checkExcelByEasyExcel(HttpServletRequest request) {
|
||||
return super.checkExcelByEasyExcel(request, BgPartymatter.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过EasyExcel导入数据,支持字典校验和Hibernate Validator
|
||||
*/
|
||||
@RequiresPermissions("bgpartymatter:bg_partymatter:importExcel")
|
||||
@PostMapping(value = "/importExcelByEasyExcel")
|
||||
public Result<?> importExcelByEasyExcel(HttpServletRequest request) {
|
||||
return super.importExcelByEasyExcel(request, BgPartymatter.class);
|
||||
}
|
||||
/**
|
||||
* 通过EasyExcel校验数据,只返回校验结果,不保存到数据库
|
||||
*/
|
||||
@RequiresPermissions("bgpartymatter:bg_partymatter:importExcel")
|
||||
@RequestMapping(value = "/checkExcelByEasyExcel", method = RequestMethod.POST)
|
||||
public Result<?> checkExcelByEasyExcel(HttpServletRequest request) {
|
||||
return super.checkExcelByEasyExcel(request, BgPartymatter.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过EasyExcel导出数据
|
||||
*/
|
||||
@RequiresPermissions("bgpartymatter:bg_partymatter:exportXls")
|
||||
@GetMapping(value = "/exportXlsByEasyExcel")
|
||||
public void exportXlsByEasyExcel(HttpServletRequest request, HttpServletResponse response,
|
||||
BgPartymatter bgPartymatter) throws IOException {
|
||||
super.exportXlsByEasyExcel(request, response, bgPartymatter, BgPartymatter.class, "dq_inspect_task");
|
||||
}
|
||||
/**
|
||||
* 通过EasyExcel导入数据,支持字典校验和Hibernate Validator,通过 meetingType 参数指定导入类型
|
||||
*/
|
||||
@RequiresPermissions("bgpartymatter:bg_partymatter:importExcel")
|
||||
@PostMapping(value = "/importExcelByEasyExcel")
|
||||
public Result<?> importExcelByEasyExcel(HttpServletRequest request,
|
||||
@RequestParam(defaultValue = "party") String meetingType) {
|
||||
return super.importExcelByEasyExcel(request, BgPartymatter.class,
|
||||
Map.of(
|
||||
BgPartymatterConstant.ClassFieldName.MEETING_TYPE_NAME, meetingType,
|
||||
BgPartymatterConstant.ClassFieldName.DEL_FLAG_NAME,
|
||||
BgPartymatterConstant.DelFlag.NORMAL));
|
||||
}
|
||||
|
||||
/**
|
||||
* 仅导出Excel表头(EasyExcel)
|
||||
*/
|
||||
@RequiresPermissions("bgpartymatter:bg_partymatter:exportXls")
|
||||
@GetMapping(value = "/exportXlsHeaders")
|
||||
public void exportXlsHeaders(HttpServletResponse response) throws IOException {
|
||||
super.exportXlsHeadersByEasyExcel(response, BgPartymatter.class, "dq_inspect_task");
|
||||
}
|
||||
/**
|
||||
* 通过EasyExcel导出数据,根据 meetingType 动态切换标题
|
||||
*/
|
||||
@RequiresPermissions("bgpartymatter:bg_partymatter:exportXls")
|
||||
@GetMapping(value = "/exportXlsByEasyExcel")
|
||||
public void exportXlsByEasyExcel(HttpServletRequest request, HttpServletResponse response,
|
||||
BgPartymatter bgPartymatter) throws IOException {
|
||||
String title = BgPartymatterConstant.MeetingType.OFFICE.equals(bgPartymatter.getMeetingType()) ? "所务会" : "党委会";
|
||||
super.exportXlsByEasyExcel(request, response, bgPartymatter, BgPartymatter.class, title);
|
||||
}
|
||||
|
||||
/**
|
||||
* 仅导出Excel表头(EasyExcel),通过 meetingType 参数指定模板类型
|
||||
*/
|
||||
@RequiresPermissions("bgpartymatter:bg_partymatter:exportXls")
|
||||
@GetMapping(value = "/exportXlsHeaders")
|
||||
public void exportXlsHeaders(HttpServletResponse response,
|
||||
@RequestParam(defaultValue = "party") String meetingType) throws IOException {
|
||||
String title = BgPartymatterConstant.MeetingType.OFFICE.equals(meetingType) ? "所务会" : "党委会";
|
||||
super.exportXlsHeadersByEasyExcel(response, BgPartymatter.class, title);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user