开发OTA备案工具

This commit is contained in:
高嵩
2023-03-26 01:20:43 +08:00
parent ded9572f2a
commit 7f99dfa14e
5 changed files with 169 additions and 80 deletions
@@ -2,6 +2,7 @@ package com.jero.modules.ota.enums;
public enum OtaTitleEnum { public enum OtaTitleEnum {
CPDJBH("cpdjbh", "产品登记编号"), CPDJBH("cpdjbh", "产品登记编号"),
GGPC("ggpc", "公告批次"), GGPC("ggpc", "公告批次"),
CPSB("cpsb", "产品商标"), CPSB("cpsb", "产品商标"),
@@ -15,8 +16,8 @@ public enum OtaTitleEnum {
QYMC("qymc", "企业名称"), QYMC("qymc", "企业名称"),
DJBH("djbh", "产品登记编号"), DJBH("djbh", "产品登记编号"),
CPLB("cplb", "产品类别"), CPLB("cplb", "产品类别"),
DLLX1("dllx1", "车辆动力类型1"), DLLX1("dllx1", "车辆动力类型"),
DLLX2("dllx2", "车辆动力类型2"), DLLX2("dllx2", "车辆动力类型"),
TXZD("txzd", "通信终端"), TXZD("txzd", "通信终端"),
CDOTASJ("cdotasj", "车端OTA升级管理系统"), CDOTASJ("cdotasj", "车端OTA升级管理系统"),
BHSJB("bhsjb", "保护升级包"), BHSJB("bhsjb", "保护升级包"),
@@ -216,4 +217,15 @@ public enum OtaTitleEnum {
public void setValue(String value) { public void setValue(String value) {
this.value = value; this.value = value;
} }
public static String getVal(String name){
String res = "";
for (OtaTitleEnum e:values()) {
if(e.getName().equals(name)){
res = e.getValue();
break;
}
}
return res;
}
} }
@@ -2,6 +2,9 @@ package com.jero.modules.ota.service;
import com.jero.modules.ota.entity.OtaBaCxTxjl; import com.jero.modules.ota.entity.OtaBaCxTxjl;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.jero.modules.ota.enums.OtaModuleEnum;
import org.apache.poi.ss.formula.functions.T;
import java.util.List; import java.util.List;
/** /**
@@ -12,6 +15,8 @@ import java.util.List;
*/ */
public interface IOtaBaCxTxjlService extends IService<OtaBaCxTxjl> { public interface IOtaBaCxTxjlService extends IService<OtaBaCxTxjl> {
public void addHistory(OtaModuleEnum otaModuleEnum, String title, String oldStr, String newStr);
/** /**
* 保存 * 保存
* *
@@ -4,9 +4,13 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jero.modules.ota.entity.OtaBaCxJbxx; import com.jero.modules.ota.entity.OtaBaCxJbxx;
import com.jero.modules.ota.entity.OtaBaCxList; import com.jero.modules.ota.entity.OtaBaCxList;
import com.jero.modules.ota.entity.OtaBaCxTxjl;
import com.jero.modules.ota.enums.OtaModuleEnum;
import com.jero.modules.ota.mapper.OtaBaCxJbxxMapper; import com.jero.modules.ota.mapper.OtaBaCxJbxxMapper;
import com.jero.modules.ota.service.IOtaBaCxJbxxService; import com.jero.modules.ota.service.IOtaBaCxJbxxService;
import com.jero.modules.ota.service.IOtaBaCxListService; import com.jero.modules.ota.service.IOtaBaCxListService;
import com.jero.modules.ota.service.IOtaBaCxTxjlService;
import com.jero.modules.ota.utils.ComparisonUtil;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@@ -19,110 +23,120 @@ import java.util.UUID;
/** /**
* @Description: 车型备案-车型基本信息 * @Description: 车型备案-车型基本信息
* @Author: jero-boot * @Author: jero-boot
* @Date: 2023-03-17 * @Date: 2023-03-17
* @Version: V1.0 * @Version: V1.0
*/ */
@Service @Service
public class OtaBaCxJbxxServiceImpl extends ServiceImpl<OtaBaCxJbxxMapper, OtaBaCxJbxx> implements IOtaBaCxJbxxService { public class OtaBaCxJbxxServiceImpl extends ServiceImpl<OtaBaCxJbxxMapper, OtaBaCxJbxx> implements IOtaBaCxJbxxService {
@Autowired @Autowired
private IOtaBaCxListService otaBaCxListService; private IOtaBaCxListService otaBaCxListService;
/**
* 保存 @Autowired
* private IOtaBaCxTxjlService otaBaCxTxjlService;
* @param otaBaCxJbxx
* @return /**
*/ * 保存
*
* @param otaBaCxJbxx
* @return
*/
public OtaBaCxJbxx add(OtaBaCxJbxx otaBaCxJbxx) { public OtaBaCxJbxx add(OtaBaCxJbxx otaBaCxJbxx) {
Date now = new Date(); //对比填写记录用的
OtaBaCxList otaBaCxList; OtaBaCxJbxx OtaBaCxJbxxOld = new OtaBaCxJbxx();
if(StringUtils.isEmpty(otaBaCxJbxx.getOtaId())){ Date now = new Date();
//在保存的时候设置一个id 并返回前端 下次保存的时候判断是否为更新 OtaBaCxList otaBaCxList;
otaBaCxList = new OtaBaCxList(); if (StringUtils.isEmpty(otaBaCxJbxx.getOtaId())) {
otaBaCxList.setId(UUID.randomUUID().toString().replace("-", "")); //在保存的时候设置一个id 并返回前端 下次保存的时候判断是否为更新
otaBaCxList.updateData(otaBaCxJbxx); otaBaCxList = new OtaBaCxList();
otaBaCxListService.add(otaBaCxList); otaBaCxList.setId(UUID.randomUUID().toString().replace("-", ""));
otaBaCxJbxx.setOtaId(otaBaCxList.getId()); otaBaCxList.updateData(otaBaCxJbxx);
otaBaCxJbxx.setCreateTime(now); otaBaCxListService.add(otaBaCxList);
}else{ otaBaCxJbxx.setOtaId(otaBaCxList.getId());
otaBaCxList = otaBaCxListService.queryById(otaBaCxJbxx.getOtaId()); otaBaCxJbxx.setCreateTime(now);
otaBaCxList.updateData(otaBaCxJbxx); } else {
otaBaCxListService.editById(otaBaCxList); OtaBaCxJbxxOld = this.getByOtaId(otaBaCxJbxx.getOtaId());
} otaBaCxList = otaBaCxListService.queryById(otaBaCxJbxx.getOtaId());
otaBaCxList.updateData(otaBaCxJbxx);
otaBaCxListService.editById(otaBaCxList);
}
otaBaCxJbxx.setUpdateTime(now); otaBaCxJbxx.setUpdateTime(now);
saveOrUpdate(otaBaCxJbxx); saveOrUpdate(otaBaCxJbxx);
return otaBaCxJbxx; ComparisonUtil cu = new ComparisonUtil();
List<OtaBaCxTxjl> reList = cu.comparisonRecord(otaBaCxJbxx.getOtaId(), OtaModuleEnum.CX_CXJBXX, OtaBaCxJbxxOld, otaBaCxJbxx);
otaBaCxTxjlService.saveBatch(reList);
return otaBaCxJbxx;
} }
/** /**
* 更新 * 更新
* *
* @param otaBaCxJbxx * @param otaBaCxJbxx
* @return * @return
*/ */
@Override @Override
public void editById(OtaBaCxJbxx otaBaCxJbxx) { public void editById(OtaBaCxJbxx otaBaCxJbxx) {
Date now = new Date(); Date now = new Date();
otaBaCxJbxx.setUpdateTime(now); otaBaCxJbxx.setUpdateTime(now);
saveOrUpdate(otaBaCxJbxx); saveOrUpdate(otaBaCxJbxx);
} }
/** /**
* 通过id删除 * 通过id删除
* *
* @param id * @param id
* @return * @return
*/ */
@Override @Override
public void deleteById(String id) { public void deleteById(String id) {
removeById(id); removeById(id);
} }
/** /**
* 批量删除 * 批量删除
* *
* @param ids * @param ids
* @return * @return
*/ */
@Override @Override
public void deleteByIds(List<String> ids) { public void deleteByIds(List<String> ids) {
removeByIds(ids); removeByIds(ids);
} }
/** /**
* 通过id查询 * 通过id查询
* *
* @param id * @param id
* @return * @return
*/ */
@Override @Override
public OtaBaCxJbxx queryById(String id) { public OtaBaCxJbxx queryById(String id) {
return getById(id); return getById(id);
} }
/** /**
* 列表查询 * 列表查询
* *
* @return * @return
*/ */
@Override @Override
public List<OtaBaCxJbxx> queryList() { public List<OtaBaCxJbxx> queryList() {
return list(); return list();
} }
@Override @Override
public OtaBaCxJbxx queryByOtaId(String otaId, String otaIdT){ public OtaBaCxJbxx queryByOtaId(String otaId, String otaIdT) {
//判断是否保存过,否则查询模版数据回显 //判断是否保存过,否则查询模版数据回显
OtaBaCxJbxx res = getByOtaId(otaId); OtaBaCxJbxx res = getByOtaId(otaId);
if(ObjectUtils.isEmpty(res)){ if (ObjectUtils.isEmpty(res)) {
res = getByOtaId(otaIdT); res = getByOtaId(otaIdT);
} }
return res; return res;
} }
private OtaBaCxJbxx getByOtaId(String otaId) { private OtaBaCxJbxx getByOtaId(String otaId) {
LambdaQueryWrapper<OtaBaCxJbxx> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<OtaBaCxJbxx> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(OtaBaCxJbxx::getOtaId, otaId); queryWrapper.eq(OtaBaCxJbxx::getOtaId, otaId);
return this.getOne(queryWrapper,false); return this.getOne(queryWrapper, false);
} }
} }
@@ -3,9 +3,7 @@ package com.jero.modules.ota.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jero.modules.ota.entity.OtaBaCxTxjl; import com.jero.modules.ota.entity.OtaBaCxTxjl;
import com.jero.modules.ota.entity.OtaBaSjLsjl;
import com.jero.modules.ota.enums.OtaModuleEnum; import com.jero.modules.ota.enums.OtaModuleEnum;
import com.jero.modules.ota.enums.OtaTitleEnum;
import com.jero.modules.ota.mapper.OtaBaCxTxjlMapper; import com.jero.modules.ota.mapper.OtaBaCxTxjlMapper;
import com.jero.modules.ota.service.IOtaBaCxTxjlService; import com.jero.modules.ota.service.IOtaBaCxTxjlService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@@ -22,6 +20,7 @@ import java.util.List;
@Service @Service
public class OtaBaCxTxjlServiceImpl extends ServiceImpl<OtaBaCxTxjlMapper, OtaBaCxTxjl> implements IOtaBaCxTxjlService { public class OtaBaCxTxjlServiceImpl extends ServiceImpl<OtaBaCxTxjlMapper, OtaBaCxTxjl> implements IOtaBaCxTxjlService {
/** /**
* 添加填写历史 * 添加填写历史
* *
@@ -33,7 +32,7 @@ public class OtaBaCxTxjlServiceImpl extends ServiceImpl<OtaBaCxTxjlMapper, OtaBa
public void addHistory(OtaModuleEnum otaModuleEnum, String title, String oldStr, String newStr) { public void addHistory(OtaModuleEnum otaModuleEnum, String title, String oldStr, String newStr) {
OtaBaCxTxjl otaBaCxTxjl = new OtaBaCxTxjl(); OtaBaCxTxjl otaBaCxTxjl = new OtaBaCxTxjl();
otaBaCxTxjl.setModule(otaModuleEnum.getName()); otaBaCxTxjl.setModule(otaModuleEnum.getName());
otaBaCxTxjl.setContent("将" + title + "的" + oldStr + "改为" + newStr); otaBaCxTxjl.setContent("由" + title + "的" + oldStr + "改为" + newStr);
add(otaBaCxTxjl); add(otaBaCxTxjl);
} }
@@ -0,0 +1,59 @@
package com.jero.modules.ota.utils;
import com.jero.modules.ota.entity.OtaBaCxTxjl;
import com.jero.modules.ota.enums.OtaModuleEnum;
import com.jero.modules.ota.enums.OtaTitleEnum;
import org.apache.commons.lang3.ObjectUtils;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
/**
* 对比新老数据,添加填写记录
* @param <T>
*/
public class ComparisonUtil<T> {
public ComparisonUtil() {
}
/**
* 对比字段并添加到记录
*/
public List<OtaBaCxTxjl> comparisonRecord(String otaId, OtaModuleEnum otaModuleEnum, T oldClazz, T newClazz) {
List<OtaBaCxTxjl> 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)) {
OtaBaCxTxjl otaBaCxTxjl = new OtaBaCxTxjl();
otaBaCxTxjl.setModule(otaModuleEnum.getName());
otaBaCxTxjl.setContent("由" + title + "的" + oldStr + "改为" + newStr);
otaBaCxTxjl.setOtaId(otaId);
resList.add(otaBaCxTxjl);
}
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
return resList;
}
}