|
@@ -1,119 +0,0 @@
|
|
|
-package com.taais.biz.listener;
|
|
|
-
|
|
|
-import cn.hutool.core.bean.BeanUtil;
|
|
|
-import cn.hutool.core.util.ObjectUtil;
|
|
|
-import com.alibaba.excel.context.AnalysisContext;
|
|
|
-import com.alibaba.excel.event.AnalysisEventListener;
|
|
|
-import com.taais.common.core.exception.ServiceException;
|
|
|
-import com.taais.common.core.utils.SpringUtils;
|
|
|
-import com.taais.common.core.utils.ValidatorUtils;
|
|
|
-import com.taais.common.excel.core.ExcelListener;
|
|
|
-import com.taais.common.excel.core.ExcelResult;
|
|
|
-import com.taais.biz.domain.bo.TargetIdentificationSubtaskDetailsBo;
|
|
|
-import com.taais.biz.domain.vo.TargetIdentificationSubtaskDetailsImportVo;
|
|
|
-import com.taais.biz.domain.vo.TargetIdentificationSubtaskDetailsVo;
|
|
|
-import com.taais.biz.service.ITargetIdentificationSubtaskDetailsService;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
-
|
|
|
-import java.util.List;
|
|
|
-
|
|
|
-/**
|
|
|
- * 目标识别子任务自定义导入
|
|
|
- *
|
|
|
- * @author 0
|
|
|
- */
|
|
|
-@Slf4j
|
|
|
-public class TargetIdentificationSubtaskDetailsImportListener extends AnalysisEventListener<TargetIdentificationSubtaskDetailsImportVo> implements ExcelListener<TargetIdentificationSubtaskDetailsImportVo> {
|
|
|
- private final ITargetIdentificationSubtaskDetailsService targetIdentificationSubtaskDetailsService;
|
|
|
-
|
|
|
- private final Boolean isUpdateSupport;
|
|
|
- private int successNum = 0;
|
|
|
- private int failureNum = 0;
|
|
|
- private final StringBuilder successMsg = new StringBuilder();
|
|
|
- private final StringBuilder failureMsg = new StringBuilder();
|
|
|
-
|
|
|
- public TargetIdentificationSubtaskDetailsImportListener(Boolean isUpdateSupport) {
|
|
|
- this.targetIdentificationSubtaskDetailsService = SpringUtils.getBean(ITargetIdentificationSubtaskDetailsService.class);
|
|
|
- this.isUpdateSupport = isUpdateSupport;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void invoke(TargetIdentificationSubtaskDetailsImportVo targetIdentificationSubtaskDetailsVo, AnalysisContext context) {
|
|
|
- try {
|
|
|
-
|
|
|
- TargetIdentificationSubtaskDetailsBo targetIdentificationSubtaskDetailsBo = BeanUtil.toBean(targetIdentificationSubtaskDetailsVo, TargetIdentificationSubtaskDetailsBo.class);
|
|
|
-
|
|
|
- //TODO:根据某个字段,查询数据库表中是否存在记录,不存在就新增,存在就更新
|
|
|
- TargetIdentificationSubtaskDetailsVo targetIdentificationSubtaskDetailsVo1 = null;
|
|
|
-
|
|
|
- //targetIdentificationSubtaskDetailsVo1 = targetIdentificationSubtaskDetailsService.selectBySomefield(targetIdentificationSubtaskDetailsVo.getSomefield());
|
|
|
- if (ObjectUtil.isNull(targetIdentificationSubtaskDetailsVo1)) {
|
|
|
- //不存在就新增
|
|
|
- targetIdentificationSubtaskDetailsBo.setVersion(0);
|
|
|
- ValidatorUtils.validate(targetIdentificationSubtaskDetailsBo);
|
|
|
- boolean inserted = targetIdentificationSubtaskDetailsService.insert(targetIdentificationSubtaskDetailsBo);
|
|
|
-
|
|
|
- if (inserted) {
|
|
|
- successNum++;
|
|
|
- successMsg.append("<br/>").append(successNum).append("、目标识别子任务 记录导入成功");
|
|
|
- return;
|
|
|
- } else {
|
|
|
- failureNum++;
|
|
|
- failureMsg.append("<br/>").append(failureNum).append("、目标识别子任务 记录导入失败");
|
|
|
- return;
|
|
|
- }
|
|
|
- } else if (isUpdateSupport) {
|
|
|
- //存在就更新
|
|
|
- targetIdentificationSubtaskDetailsBo.setId(targetIdentificationSubtaskDetailsVo1.getId());//主键
|
|
|
- targetIdentificationSubtaskDetailsBo.setVersion(targetIdentificationSubtaskDetailsVo1.getVersion());
|
|
|
- boolean updated = targetIdentificationSubtaskDetailsService.update(targetIdentificationSubtaskDetailsBo);
|
|
|
- if (updated) {
|
|
|
- successNum++;
|
|
|
- successMsg.append("<br/>").append(successNum).append("、目标识别子任务 记录更新成功");
|
|
|
- return;
|
|
|
- } else {
|
|
|
- failureNum++;
|
|
|
- failureMsg.append("<br/>").append(failureNum).append("、目标识别子任务 记录更新失败");
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- failureNum++;
|
|
|
- String msg = "<br/>" + failureNum + "、目标识别子任务 记录导入失败:";
|
|
|
- failureMsg.append(msg).append(e.getMessage());
|
|
|
- log.error(msg, e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void doAfterAllAnalysed(AnalysisContext context) {
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public ExcelResult<TargetIdentificationSubtaskDetailsImportVo> getExcelResult() {
|
|
|
- return new ExcelResult<>() {
|
|
|
-
|
|
|
- @Override
|
|
|
- public String getAnalysis() {
|
|
|
- if (failureNum > 0) {
|
|
|
- failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据没有成功导入,错误如下:");
|
|
|
- throw new ServiceException(failureMsg.toString());
|
|
|
- } else {
|
|
|
- successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
|
|
|
- }
|
|
|
- return successMsg.toString();
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<TargetIdentificationSubtaskDetailsImportVo> getList() {
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<String> getErrorList() {
|
|
|
- return null;
|
|
|
- }
|
|
|
- };
|
|
|
- }
|
|
|
-}
|