|
@@ -1,9 +1,12 @@
|
|
|
package org.eco.als.listener;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.alibaba.excel.context.AnalysisContext;
|
|
|
import com.alibaba.excel.event.AnalysisEventListener;
|
|
|
+import com.mybatisflex.core.query.QueryWrapper;
|
|
|
+import com.mybatisflex.core.util.LambdaGetter;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.eco.als.domain.bo.AircraftBo;
|
|
|
import org.eco.als.domain.vo.AircraftImportVo;
|
|
@@ -18,6 +21,8 @@ import org.eco.common.excel.entity.ExcelResultRes;
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
+import static org.eco.als.domain.table.AircraftTableDef.AIRCRAFT;
|
|
|
+
|
|
|
/**
|
|
|
* 机型机号自定义导入
|
|
|
*
|
|
@@ -43,41 +48,40 @@ public class AircraftImportListener extends AnalysisEventListener<AircraftImport
|
|
|
@Override
|
|
|
public void invoke(AircraftImportVo aircraftVo, AnalysisContext context) {
|
|
|
try {
|
|
|
-
|
|
|
AircraftBo aircraftBo = BeanUtil.toBean(aircraftVo, AircraftBo.class);
|
|
|
-
|
|
|
//TODO:根据某个字段,查询数据库表中是否存在记录,不存在就新增,存在就更新
|
|
|
AircraftVo aircraftVo1 = null;
|
|
|
-
|
|
|
aircraftVo1 = aircraftService.selectById(aircraftVo.getId());
|
|
|
- if (ObjectUtil.isNull(aircraftVo1)) {
|
|
|
+ QueryWrapper queryWrapper = QueryWrapper.create();
|
|
|
+ queryWrapper.where("name = ?", aircraftBo.getName());
|
|
|
+ queryWrapper.and("parent_name = ?", aircraftBo.getParentName());
|
|
|
+ AircraftVo aircraftVo2 = aircraftService.getOneAs(queryWrapper ,AircraftVo.class);
|
|
|
+ AircraftVo pAircraftVo = aircraftService.selectByName(aircraftBo.getParentName());
|
|
|
+ if (ObjectUtil.isNull(aircraftVo2)) {
|
|
|
//不存在就新增
|
|
|
aircraftBo.setVersion(0);
|
|
|
+ aircraftBo.setTenantId(loginUser.getTenantId());
|
|
|
+ aircraftBo.setParentId(ObjectUtil.isNull(pAircraftVo) ? 0 : pAircraftVo.getId());
|
|
|
+ aircraftBo.setParentName(ObjectUtil.isNull(pAircraftVo) ? "" : pAircraftVo.getName());
|
|
|
ValidatorUtils.validate(aircraftBo);
|
|
|
- boolean inserted = aircraftService.insertWithPk(aircraftBo);//树表需要前台传来主键值
|
|
|
-
|
|
|
+ boolean inserted = aircraftService.insert(aircraftBo);//树表需要前台传来主键值
|
|
|
if (inserted) {
|
|
|
successNum++;
|
|
|
successMsg.append("<br/>").append(successNum).append("、机型机号 记录导入成功");
|
|
|
- return;
|
|
|
} else {
|
|
|
failureNum++;
|
|
|
failureMsg.append("<br/>").append(failureNum).append("、机型机号 记录导入失败");
|
|
|
- return;
|
|
|
}
|
|
|
} else if (isUpdateSupport) {
|
|
|
//存在就更新
|
|
|
- aircraftBo.setId(aircraftVo1.getId());//主键
|
|
|
aircraftBo.setVersion(aircraftVo1.getVersion());
|
|
|
boolean updated = aircraftService.update(aircraftBo);
|
|
|
if (updated) {
|
|
|
successNum++;
|
|
|
successMsg.append("<br/>").append(successNum).append("、机型机号 记录更新成功");
|
|
|
- return;
|
|
|
} else {
|
|
|
failureNum++;
|
|
|
failureMsg.append("<br/>").append(failureNum).append("、机型机号 记录更新失败");
|
|
|
- return;
|
|
|
}
|
|
|
}
|
|
|
} catch (Exception e) {
|