refactor(sip): 重构维保信息展示逻辑
- 将服务信息封装为 ServiceInfo 类,提高数据结构的可维护性- 使用列表存储多个服务信息,支持更灵活的服务展示 -优化服务开始时间和结束时间的计算逻辑 - 移除冗余代码,提高代码可读性和性能master
parent
2b67e65246
commit
57b8f6d237
|
@ -2,14 +2,11 @@ package com.ruoyi.sip.service.impl;
|
|||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.DateUtils;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.sip.domain.OrderList;
|
||||
|
@ -18,7 +15,6 @@ import com.ruoyi.sip.dto.ApiDataQueryDto;
|
|||
import com.ruoyi.sip.mapper.OrderInfoMapper;
|
||||
import com.ruoyi.sip.mapper.ProductInfoMapper;
|
||||
import com.ruoyi.sip.vo.DeliveryInfoVo;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.sip.mapper.DeliveryListMapper;
|
||||
import com.ruoyi.sip.domain.DeliveryList;
|
||||
|
@ -206,14 +202,14 @@ public class DeliveryListServiceImpl implements IDeliveryListService {
|
|||
*/
|
||||
private void updateDeliveryInfoVo(DeliveryInfoVo deliveryInfoVo, Map<Long, List<ProductInfo>> maintenanceTypeMap, List<ProductInfo> productInfos) {
|
||||
List<ProductInfo> productInfoList = maintenanceTypeMap.get(deliveryInfoVo.getOrderId());
|
||||
List<DeliveryInfoVo.ServiceInfo> serviceInfoList = new ArrayList<>();
|
||||
if (CollUtil.isNotEmpty(productInfoList)) {
|
||||
int year = 0;
|
||||
StringJoiner desc=new StringJoiner(";");
|
||||
Date startTime = deliveryInfoVo.getServiceStartTime();
|
||||
if (ProductInfo.ProductTypeEnum.SOFTWARE.getType().equals(deliveryInfoVo.getProductType())) {
|
||||
for (ProductInfo productInfo : productInfoList) {
|
||||
if (ProductInfo.ProductTypeEnum.SOFTWARE_MAINTENANCE.getType().equals(productInfo.getType()) && StringUtils.isNotEmpty(productInfo.getValue())) {
|
||||
year += Integer.parseInt(productInfo.getValue());
|
||||
desc.add(productInfo.getDescription());
|
||||
startTime = updateStartTimeAndAddList(deliveryInfoVo, productInfo, startTime, serviceInfoList);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -221,24 +217,33 @@ public class DeliveryListServiceImpl implements IDeliveryListService {
|
|||
} else {
|
||||
for (ProductInfo productInfo : productInfoList) {
|
||||
if (ProductInfo.ProductTypeEnum.HARDWARE_MAINTENANCE.getType().equals(productInfo.getType()) && StringUtils.isNotEmpty(productInfo.getValue())) {
|
||||
year += Integer.parseInt(productInfo.getValue());
|
||||
desc.add(productInfo.getDescription());
|
||||
startTime = updateStartTimeAndAddList(deliveryInfoVo, productInfo, startTime, serviceInfoList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (year == 0 && ProductInfo.ProductTypeEnum.HARDWARE.getType().equals(deliveryInfoVo.getProductType())
|
||||
if (CollUtil.isEmpty(serviceInfoList) && ProductInfo.ProductTypeEnum.HARDWARE.getType().equals(deliveryInfoVo.getProductType())
|
||||
&& CollUtil.isNotEmpty(productInfos)) {
|
||||
// 判断是否硬件,如果是硬件取标准维保三年
|
||||
if (StringUtils.isNotEmpty(productInfos.get(0).getValue())) {
|
||||
year = Integer.parseInt(productInfos.get(0).getValue());
|
||||
startTime = updateStartTimeAndAddList(deliveryInfoVo, productInfos.get(0), startTime, serviceInfoList);
|
||||
}
|
||||
}
|
||||
deliveryInfoVo.setServiceInfo(serviceInfoList);
|
||||
|
||||
deliveryInfoVo.setServiceLevel(Integer.toString(year));
|
||||
deliveryInfoVo.setServiceDescribe(desc.toString());
|
||||
deliveryInfoVo.setServiceEndTime(DateUtils.addYears(deliveryInfoVo.getServiceStartTime(), year));
|
||||
}
|
||||
}
|
||||
|
||||
private static Date updateStartTimeAndAddList(DeliveryInfoVo deliveryInfoVo, ProductInfo productInfo, Date startTime, List<DeliveryInfoVo.ServiceInfo> serviceInfoList) {
|
||||
int year = Integer.parseInt(productInfo.getValue());
|
||||
DeliveryInfoVo.ServiceInfo serviceInfo = deliveryInfoVo.new ServiceInfo();
|
||||
serviceInfo.setServiceLevel(productInfo.getValue());
|
||||
serviceInfo.setServiceDescribe(productInfo.getDescription());
|
||||
serviceInfo.setServiceStartTime(startTime);
|
||||
serviceInfo.setServiceEndTime(DateUtils.addYears(startTime, year));
|
||||
startTime = DateUtils.addYears(startTime, year);
|
||||
serviceInfoList.add(serviceInfo);
|
||||
return startTime;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
|||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author : ch
|
||||
|
@ -32,20 +33,27 @@ public class DeliveryInfoVo {
|
|||
@JsonIgnore
|
||||
private String productName;
|
||||
private String productDescription;
|
||||
|
||||
|
||||
//服务级别
|
||||
private String serviceLevel;
|
||||
//服务描述
|
||||
private String serviceDescribe;
|
||||
|
||||
//服务开始时间
|
||||
@JsonIgnore
|
||||
private Date serviceStartTime;
|
||||
//服务结束时间
|
||||
private Date serviceEndTime;
|
||||
private List<ServiceInfo> serviceInfo;
|
||||
|
||||
private Date lastUpdateTime;
|
||||
@JsonIgnore
|
||||
private Long orderId;
|
||||
@JsonIgnore
|
||||
private String productType;
|
||||
|
||||
|
||||
@Data
|
||||
public class ServiceInfo {
|
||||
//服务级别
|
||||
private String serviceLevel;
|
||||
//服务描述
|
||||
private String serviceDescribe;
|
||||
|
||||
//服务开始时间
|
||||
private Date serviceStartTime;
|
||||
//服务结束时间
|
||||
private Date serviceEndTime;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue