From 87a0bd651fa979c99d522bbd1e7f0c521f394581 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AB=98=E5=B5=A9?= Date: Sun, 26 Mar 2023 02:39:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E5=8F=91OTA=E5=A4=87=E6=A1=88?= =?UTF-8?q?=E5=B7=A5=E5=85=B7-=E5=A1=AB=E5=86=99=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jero/modules/ota/entity/OtaBaCxTxjl.java | 8 ++ .../impl/OtaBaCxJsfzbacsServiceImpl.java | 15 +-- .../impl/OtaBaCxKsjjsmccsServiceImpl.java | 14 +++ .../impl/OtaBaCxKsjxtmccsServiceImpl.java | 19 +++- .../modules/ota/utils/ComparisonUtil.java | 99 +++++++++++++++++-- 5 files changed, 139 insertions(+), 16 deletions(-) diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/entity/OtaBaCxTxjl.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/entity/OtaBaCxTxjl.java index 28daea52e..7f71a2b36 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/entity/OtaBaCxTxjl.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/entity/OtaBaCxTxjl.java @@ -76,4 +76,12 @@ public class OtaBaCxTxjl implements Serializable { @ApiModelProperty(value = "填写内容") private String content; + public OtaBaCxTxjl() { + } + + public OtaBaCxTxjl(String otaId, String module, String content) { + this.otaId = otaId; + this.module = module; + this.content = content; + } } diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaCxJsfzbacsServiceImpl.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaCxJsfzbacsServiceImpl.java index b0c86a37f..607e6364f 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaCxJsfzbacsServiceImpl.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaCxJsfzbacsServiceImpl.java @@ -1,14 +1,16 @@ package com.jero.modules.ota.service.impl; -import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.jero.modules.ota.entity.*; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.jero.modules.ota.entity.OtaBaCxJsfzbacs; +import com.jero.modules.ota.entity.OtaBaCxSjmk; +import com.jero.modules.ota.entity.OtaBaCxTxjl; import com.jero.modules.ota.enums.OtaModuleEnum; +import com.jero.modules.ota.enums.OtaTitleEnum; import com.jero.modules.ota.mapper.OtaBaCxJsfzbacsMapper; import com.jero.modules.ota.service.IOtaBaCxJsfzbacsService; -import com.jero.modules.ota.service.IOtaBaCxLsjlService; import com.jero.modules.ota.service.IOtaBaCxSjmkService; import com.jero.modules.ota.service.IOtaBaCxTxjlService; import com.jero.modules.ota.utils.ComparisonUtil; @@ -19,8 +21,6 @@ import org.springframework.stereotype.Service; import java.lang.reflect.Field; import java.util.*; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; - /** * @Description: 车型备案-驾驶辅助系统基础备案参数 * @Author: jero-boot @@ -52,12 +52,15 @@ public class OtaBaCxJsfzbacsServiceImpl extends ServiceImpl reList = cu.comparisonRecord(otaId, OtaModuleEnum.CX_JSFZXTJCBACS, otaBaCxJsfzbacsOld, otaBaCxJsfzbacs); - otaBaCxTxjlService.saveBatch(reList); + //处理控制器列表,先删除,后添加 + List oldList = OtaBaCxSjmkService.queryByOtaId(otaId); OtaBaCxSjmkService.deleteByOtaId(otaId); JSONArray kzq = json.getJSONArray("kzq"); List sjmkList = parseKzqData(kzq, otaId); OtaBaCxSjmkService.saveBatch(sjmkList); + cu.comparisonListRecord(otaId, OtaModuleEnum.CX_JSFZXTJCBACS, OtaTitleEnum.BJMC.getName(), oldList, sjmkList); + otaBaCxTxjlService.saveBatch(reList); } diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaCxKsjjsmccsServiceImpl.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaCxKsjjsmccsServiceImpl.java index b40cdf332..ea68bd088 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaCxKsjjsmccsServiceImpl.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaCxKsjjsmccsServiceImpl.java @@ -5,9 +5,13 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.jero.modules.ota.entity.*; +import com.jero.modules.ota.enums.OtaModuleEnum; +import com.jero.modules.ota.enums.OtaTitleEnum; import com.jero.modules.ota.mapper.OtaBaCxKsjjsmccsMapper; import com.jero.modules.ota.service.IOtaBaCxKsjjsmccsService; import com.jero.modules.ota.service.IOtaBaCxListService; +import com.jero.modules.ota.service.IOtaBaCxTxjlService; +import com.jero.modules.ota.utils.ComparisonUtil; import com.jero.modules.system.util.StringUtils; import org.apache.commons.lang3.ObjectUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -31,6 +35,9 @@ public class OtaBaCxKsjjsmccsServiceImpl extends ServiceImpl newList = new ArrayList<>(); + List oldList; Date now = new Date(); String otaId = (String) json.get("otaId"); if (StringUtils.isNotEmpty(otaId)) { + oldList = getByOtaId(otaId); deleteByOtaId(otaId); JSONArray list = json.getJSONArray("list"); for (Object obj : list) { @@ -65,7 +75,11 @@ public class OtaBaCxKsjjsmccsServiceImpl extends ServiceImpl reList = cu.comparisonListRecord(otaId, OtaModuleEnum.CX_KZXSJDJSFZGNMCYCS, OtaTitleEnum.GNMC.getName(), oldList, newList); + otaBaCxTxjlService.saveBatch(reList); String fj = (String) json.get("fj"); if (StringUtils.isNotEmpty(fj)) { OtaBaCxList otaBaCxList = otaBaCxListService.queryById(otaId); diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaCxKsjxtmccsServiceImpl.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaCxKsjxtmccsServiceImpl.java index d6fd273b6..d6d260319 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaCxKsjxtmccsServiceImpl.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/service/impl/OtaBaCxKsjxtmccsServiceImpl.java @@ -4,13 +4,14 @@ import cn.hutool.core.util.ObjectUtil; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.jero.modules.ota.entity.OtaBaCxJbxx; -import com.jero.modules.ota.entity.OtaBaCxKsjjsmccs; -import com.jero.modules.ota.entity.OtaBaCxKsjxtmccs; -import com.jero.modules.ota.entity.OtaBaCxList; +import com.jero.modules.ota.entity.*; +import com.jero.modules.ota.enums.OtaModuleEnum; +import com.jero.modules.ota.enums.OtaTitleEnum; import com.jero.modules.ota.mapper.OtaBaCxKsjxtmccsMapper; import com.jero.modules.ota.service.IOtaBaCxKsjxtmccsService; import com.jero.modules.ota.service.IOtaBaCxListService; +import com.jero.modules.ota.service.IOtaBaCxTxjlService; +import com.jero.modules.ota.utils.ComparisonUtil; import com.jero.modules.system.util.StringUtils; import org.apache.commons.lang3.ObjectUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -33,6 +34,9 @@ public class OtaBaCxKsjxtmccsServiceImpl extends ServiceImpl newList = new ArrayList<>(); + List oldList; Date now = new Date(); String otaId = (String) json.get("otaId"); if (StringUtils.isNotEmpty(otaId)) { + oldList = getByOtaId(otaId); deleteByOtaId(otaId); JSONArray list = json.getJSONArray("list"); for (Object obj : list) { @@ -67,7 +74,11 @@ public class OtaBaCxKsjxtmccsServiceImpl extends ServiceImpl reList = cu.comparisonListRecord(otaId, OtaModuleEnum.CX_KSJDXTMCYCS, OtaTitleEnum.XTLB.getName(), oldList, newList); + otaBaCxTxjlService.saveBatch(reList); String fj = (String) json.get("fj"); if (StringUtils.isNotEmpty(fj)) { OtaBaCxList otaBaCxList = otaBaCxListService.queryById(otaId); diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/utils/ComparisonUtil.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/utils/ComparisonUtil.java index 4ddafd7de..ca0d1b446 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/utils/ComparisonUtil.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/ota/utils/ComparisonUtil.java @@ -12,6 +12,7 @@ import java.util.List; /** * 对比新老数据,添加填写记录 + * * @param */ public class ComparisonUtil { @@ -24,7 +25,6 @@ public class ComparisonUtil { */ public List comparisonRecord(String otaId, OtaModuleEnum otaModuleEnum, T oldClazz, T newClazz) { List resList = new ArrayList<>(); - Field[] fields = newClazz.getClass().getDeclaredFields(); for (Field field : fields) { try { @@ -44,11 +44,8 @@ public class ComparisonUtil { oldStr = oldVal.toString(); } if (!newStr.equals(oldStr)) { - OtaBaCxTxjl otaBaCxTxjl = new OtaBaCxTxjl(); - otaBaCxTxjl.setModule(otaModuleEnum.getName()); - otaBaCxTxjl.setContent("由" + title + "的" + oldStr + "改为" + newStr); - otaBaCxTxjl.setOtaId(otaId); - resList.add(otaBaCxTxjl); + String content = "由" + title + "的" + oldStr + "改为" + newStr; + resList.add(new OtaBaCxTxjl(otaId, otaModuleEnum.getName(), content)); } } catch (IllegalAccessException e) { e.printStackTrace(); @@ -56,4 +53,94 @@ public class ComparisonUtil { } return resList; } + + public List comparisonListRecord(String otaId, OtaModuleEnum otaModuleEnum, String tableTitle, List oldList, List newList) { + List resList = new ArrayList<>(); + try { + for (T newObj : newList) { + if (ObjectUtils.isNotEmpty(newObj)) { + Field idField = newObj.getClass().getDeclaredField("id"); + Object id = idField.get(newObj); + if (ObjectUtils.isEmpty(id)) { + String content = "新增了一条" + newObj.getClass().getDeclaredField(tableTitle).get(newObj).toString(); + resList.add(new OtaBaCxTxjl(otaId, otaModuleEnum.getName(), content)); + Field[] fields = newObj.getClass().getDeclaredFields(); + for (Field field : fields) { + String title = OtaTitleEnum.getVal(field.getName()); + if (ObjectUtils.isEmpty(title)) { + continue; + } + field.setAccessible(true); + Object newVal = field.get(newObj); + String newStr = "空"; + if (ObjectUtils.isNotEmpty(newVal)) { + newStr = newVal.toString(); + } + content = "增加" + newObj.getClass().getDeclaredField(tableTitle).get(newObj).toString() + "中" + title + "为" + newStr; + resList.add(new OtaBaCxTxjl(otaId, otaModuleEnum.getName(), content)); + } + } else { + for (T oldObj : oldList) { + String oldId = idField.get(oldObj).toString(); + if (oldId.equals(id.toString())) { + resList.addAll(comparisonCertRecord(otaId, otaModuleEnum, tableTitle, newObj, oldObj)); + } + } + } + } + } + for (T oldObj : oldList) { + if (ObjectUtils.isNotEmpty(oldObj)) { + Field idField = oldObj.getClass().getDeclaredField("id"); + String oldId = idField.get(oldObj).toString(); + for (T newObj : newList) { + if (ObjectUtils.isNotEmpty(newObj)) { + Object newId = idField.get(newObj); + if (ObjectUtils.isNotEmpty(newObj) && oldId.equals(newId.toString())) { + break; + } + } + } + String content = "删除了" + oldObj.getClass().getDeclaredField(tableTitle).get(oldObj).toString(); + resList.add(new OtaBaCxTxjl(otaId, otaModuleEnum.getName(), content)); + } + } + } catch (IllegalAccessException | NoSuchFieldException e) { + e.printStackTrace(); + } + + return resList; + } + + + public List comparisonCertRecord(String otaId, OtaModuleEnum otaModuleEnum, String tableTitle, T oldClazz, T newClazz) { + List resList = new ArrayList<>(); + Field[] fields = newClazz.getClass().getDeclaredFields(); + for (Field field : fields) { + try { + String title = OtaTitleEnum.getVal(field.getName()); + if (ObjectUtils.isEmpty(title)) { + continue; + } + field.setAccessible(true); + Object newVal = field.get(newClazz); + Object oldVal = field.get(oldClazz); + String newStr = "空"; + if (ObjectUtils.isNotEmpty(newVal)) { + newStr = newVal.toString(); + } + String oldStr = "空"; + if (ObjectUtils.isNotEmpty(oldVal)) { + oldStr = oldVal.toString(); + } + if (!newStr.equals(oldStr)) { + String content = newVal.getClass().getDeclaredField(tableTitle).get(newVal).toString() + "的" + title + "由" + oldStr + "改为" + newStr; + resList.add(new OtaBaCxTxjl(otaId, otaModuleEnum.getName(), content)); + } + } catch (IllegalAccessException | NoSuchFieldException e) { + e.printStackTrace(); + } + } + return resList; + } }