Commit 7ef92938 authored by suhuiguang's avatar suhuiguang

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

1.压力管道管道长度调整为字符串/分隔开
parent 24d166b0
......@@ -40,6 +40,7 @@ import com.yeejoin.amos.boot.module.jg.biz.event.CancellationEvent;
import com.yeejoin.amos.boot.module.jg.biz.event.publisher.EventPublisher;
import com.yeejoin.amos.boot.module.jg.biz.feign.TzsServiceFeignClient;
import com.yeejoin.amos.boot.module.jg.biz.service.*;
import com.yeejoin.amos.boot.module.jg.biz.utils.PipLenCalUtils;
import com.yeejoin.amos.boot.module.jg.biz.utils.WordTemplateUtils;
import com.yeejoin.amos.boot.module.ymt.api.entity.*;
import com.yeejoin.amos.boot.module.ymt.api.enums.ApplicationFormTypeEnum;
......@@ -80,8 +81,6 @@ import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import static com.alibaba.fastjson.JSON.toJSONString;
import static com.yeejoin.amos.boot.module.jg.api.common.BizCommonConstant.PIPE_LENGTH;
import static com.yeejoin.amos.boot.module.jg.api.common.BizCommonConstant.PIPE_LENGTH_SPILT;
/**
* 改造告知服务实现类
......@@ -653,24 +652,13 @@ public class JgReformNoticeServiceImpl extends BaseService<JgReformNoticeDto, Jg
* @return 管道长度变化,正值为增长,负值为减少
*/
private String calculatePipeLengthChange(JSONArray oldPipData, JSONArray newPipData) {
double oldPipLen = getPipLen(oldPipData); ;
double newPipLen = getPipLen(newPipData);
double oldPipLen = PipLenCalUtils.getPipLen(oldPipData); ;
double newPipLen = PipLenCalUtils.getPipLen(newPipData);
double change = newPipLen - oldPipLen;
return change == 0 ? "0" : String.format("%+.2f", change);
}
private static double getPipLen(JSONArray oldPipData) {
return oldPipData.stream()
.map(p -> JSON.parseObject(p.toString()))
.filter(s -> StringUtil.isNotEmpty(s.getString(PIPE_LENGTH)))
.map(d ->
Arrays.stream(d.getString(PIPE_LENGTH).split(PIPE_LENGTH_SPILT)) // 分割字符串
.map(BigDecimal::new) // 转 BigDecimal
.reduce(BigDecimal.ZERO, BigDecimal::add) // 分段求和
)
.reduce(BigDecimal.ZERO, BigDecimal::add) // 全局求和
.doubleValue();
}
private JSONObject getNowPipJsonData(String projectContraptionId) {
return new JSONObject(Optional.ofNullable(idxBizJgProjectContraptionMapper.getDetail(projectContraptionId))
......@@ -1135,7 +1123,7 @@ public class JgReformNoticeServiceImpl extends BaseService<JgReformNoticeDto, Jg
// 产品质量合格证明 PRODUCT_QUALIFICATION_CERTIFICATE 其他附件 OTHER_ACCESSORIES 管道总长度
// String productQualificationCertificate = JSON.toJSONString(newData.get(PRODUCT_QUALIFICATION_CERTIFICATE));
// String otherAccessories = JSON.toJSONString(newData.get(OTHER_ACCESSORIES));
double pipLengthLastSum = getPipLen(newPipData); // 最终转 double
double pipLengthLastSum = PipLenCalUtils.getPipLen(newPipData); // 最终转 double
LambdaUpdateWrapper<IdxBizJgProjectContraption> updateWrapper = new LambdaUpdateWrapper<IdxBizJgProjectContraption>()
.eq(IdxBizJgProjectContraption::getSequenceNbr, notice.getProjectContraptionId())
// .set(IdxBizJgProjectContraption::getProductQualificationCertificate, productQualificationCertificate)
......@@ -1477,7 +1465,7 @@ public class JgReformNoticeServiceImpl extends BaseService<JgReformNoticeDto, Jg
JSONArray alreadyDelPipData = Optional.ofNullable(JSONArray.parseArray(newData.getString(DEL_DEVICE_LIST))).orElse(new JSONArray());
JSONObject oldData = Optional.ofNullable(JSONObject.parseObject(registrationHistory.getOldData())).orElse(new JSONObject());
JSONArray oldPipData = Optional.ofNullable(JSONArray.parseArray(oldData.getString(DEVICE_LIST))).orElse(new JSONArray());
double oldPipLength = getPipLen(oldPipData);
double oldPipLength = PipLenCalUtils.getPipLen(oldPipData);
List<String> oldPipDataRecords = oldPipData.stream().map(item -> JSON.parseObject(item.toString()).getString(RECORD)).collect(Collectors.toList());
List<String> nowPipDataRecords = idxBizJgProjectContraptionMapper.selectEquipList(notice.getProjectContraptionId()).stream().map(item -> String.valueOf(item.get("record"))).collect(Collectors.toList());
List<JSONObject> toAddPipData = alreadyDelPipData.stream().map(item -> JSON.parseObject(item.toString())).collect(Collectors.toList());
......
package com.yeejoin.amos.boot.module.jg.biz.utils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.github.pagehelper.util.StringUtil;
import java.math.BigDecimal;
import java.util.Arrays;
import static com.yeejoin.amos.boot.module.jg.api.common.BizCommonConstant.PIPE_LENGTH;
import static com.yeejoin.amos.boot.module.jg.api.common.BizCommonConstant.PIPE_LENGTH_SPILT;
/**
* 管道长度计算公共类-便于统一维护口
*/
public class PipLenCalUtils {
public static double getPipLen(JSONArray oldPipData) {
return oldPipData.stream()
.map(p -> JSON.parseObject(p.toString()))
.filter(s -> StringUtil.isNotEmpty(s.getString(PIPE_LENGTH)))
.map(d ->
Arrays.stream(d.getString(PIPE_LENGTH).split(PIPE_LENGTH_SPILT)) // 分割字符串
.map(BigDecimal::new) // 转 BigDecimal
.reduce(BigDecimal.ZERO, BigDecimal::add) // 分段求和
)
.reduce(BigDecimal.ZERO, BigDecimal::add) // 全局求和
.doubleValue();
}
}
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