Commit deecf65c authored by suhuiguang's avatar suhuiguang

reafact(jg): 压力管道管道长度

1.压力管道管道长度调整为字符串/分隔开,大编辑调整
parent 320099f9
......@@ -2,6 +2,7 @@ package com.yeejoin.amos.boot.biz.config;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.yeejoin.amos.boot.biz.common.annotation.FillCommonUserField;
import com.yeejoin.amos.boot.biz.common.annotation.PipeLengthField;
import com.yeejoin.amos.boot.biz.common.bo.ReginParams;
......@@ -20,6 +21,7 @@ import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Arrays;
import java.util.Date;
import java.util.Map;
import java.util.Objects;
/**
......@@ -47,7 +49,14 @@ public class MetaHandler implements MetaObjectHandler {
@Override
public void insertFill(MetaObject metaObject) {
Date currentDate = new Date();
Class<?> clazz = metaObject.getOriginalObject().getClass();
Object originalObj = metaObject.getOriginalObject();
Class<?> clazz = originalObj.getClass();
// 处理 Map 封装的情况(update(entity, wrapper) 方式)
if (originalObj instanceof Map) {
Map<?,?> map = (Map<?,?>) originalObj;
Object et = map.get(Constants.ENTITY); // MyBatis-Plus 的实体key
clazz = (et != null) ? et.getClass() : clazz;
}
FillCommonUserField annotation = clazz.getAnnotation(FillCommonUserField.class);
if (annotation == null || annotation.isAutoFill()) {
autoFillUser(metaObject, metaObject.getOriginalObject());
......@@ -59,15 +68,60 @@ public class MetaHandler implements MetaObjectHandler {
this.setFieldValByName("createDate", currentDate, metaObject);
}
private void processAutoFill(MetaObject metaObject, PipeLengthField pipeLengthField) {
Object sourceValue = metaObject.getValue(pipeLengthField.sourceField());
if (sourceValue != null) {
Object convertedValue = convertValue(sourceValue, pipeLengthField);
this.setFieldValByName(pipeLengthField.targetField(), convertedValue, metaObject);
// 1. 防御性校验
if (metaObject == null || pipeLengthField == null) {
return;
}
if (StringUtils.isBlank(pipeLengthField.sourceField()) ||
StringUtils.isBlank(pipeLengthField.targetField())) {
return;
}
// 2. 获取实际要操作的对象(处理Map封装情况)
Object operationObj = getOperationObject(metaObject);
if (operationObj == null) {
return;
}
// 3. 重新基于实际对象创建MetaObject
MetaObject targetMetaObject = metaObject.hasGetter(Constants.ENTITY)
? MetaObject.forObject(operationObj, metaObject.getObjectFactory(), metaObject.getObjectWrapperFactory(), metaObject.getReflectorFactory())
: metaObject;
// 4. 安全取值
if (!targetMetaObject.hasGetter(pipeLengthField.sourceField())) {
return;
}
Object sourceValue = targetMetaObject.getValue(pipeLengthField.sourceField());
if (sourceValue == null) {
return;
}
// 5. 转换并设值
Object convertedValue = convertValue(sourceValue, pipeLengthField);
this.setFieldValByName(pipeLengthField.targetField(), convertedValue, targetMetaObject);
}
/**
* 处理Map类型的参数封装
*/
private Object getOperationObject(MetaObject metaObject) {
Object original = metaObject.getOriginalObject();
// 处理update(entity, wrapper)产生的Map封装
if (original instanceof Map) {
Map<?, ?> map = (Map<?, ?>) original;
// MyBatis-Plus的标准实体key
return map.get(Constants.ENTITY) == null ? original : map.get(Constants.ENTITY);
}
return original;
}
private Object convertValue(Object sourceValue, PipeLengthField pipeLengthField) {
// 示例:针对pipeLength的特殊处理
if ("pipeLengthText".equals(pipeLengthField.sourceField())) {
......@@ -177,7 +231,14 @@ public class MetaHandler implements MetaObjectHandler {
*/
@Override
public void updateFill(MetaObject metaObject) {
Class<?> clazz = metaObject.getOriginalObject().getClass();
Object originalObj = metaObject.getOriginalObject();
Class<?> clazz = originalObj.getClass();
// 处理 Map 封装的情况(update(entity, wrapper) 方式)
if (originalObj instanceof Map) {
Map<?,?> map = (Map<?,?>) originalObj;
Object et = map.get(Constants.ENTITY); // MyBatis-Plus 的实体key
clazz = (et != null) ? et.getClass() : clazz;
}
FillCommonUserField annotation = clazz.getAnnotation(FillCommonUserField.class);
if (annotation == null || annotation.isAutoFill()) {
String userId = RequestContext.getExeUserId();
......
......@@ -22,7 +22,6 @@ import com.yeejoin.amos.boot.biz.common.utils.RedisUtils;
import com.yeejoin.amos.boot.module.common.api.dao.ESEquipmentCategory;
import com.yeejoin.amos.boot.module.common.api.dto.ESEquipmentCategoryDto;
import com.yeejoin.amos.boot.module.common.biz.refresh.DataRefreshEvent;
import com.yeejoin.amos.boot.module.jg.api.common.PipLenCalUtils;
import com.yeejoin.amos.boot.module.jg.api.dto.*;
import com.yeejoin.amos.boot.module.jg.api.entity.*;
import com.yeejoin.amos.boot.module.jg.api.enums.BusinessTypeEnum;
......@@ -853,7 +852,6 @@ public class JgChangeRegistrationReformServiceImpl extends BaseService<JgChangeR
pipeline.setWorkPressure(item.getString("workPressure"));
pipeline.setWorkTemperature(item.getString("workTemperature"));
pipeline.setPipeLengthText(item.getString("pipeLengthText"));
pipeline.setPipeLength(PipLenCalUtils.cal(item.getString("pipeLengthText")));
LambdaUpdateWrapper<IdxBizJgTechParamsPipeline> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper.eq(IdxBizJgTechParamsPipeline::getRecord, item.getString("record"));
// 技术参数更新
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment