Selaa lähdekoodia

同比环比时间修改

yq 4 vuotta sitten
vanhempi
commit
94bcd9c77c

+ 8 - 14
mhfire-service/src/main/java/com/bizmatics/mhfire/service/impl/SiAeAllServiceImpl.java

@@ -4,6 +4,7 @@ import com.bizmatics.common.core.exception.BusinessException;
 import com.bizmatics.common.core.util.DateUtils;
 import com.bizmatics.mhfire.persistence.mapper.SiAeAllMapper;
 import com.bizmatics.mhfire.service.SiAeAllService;
+import com.bizmatics.mhfire.service.util.Arith;
 import com.bizmatics.mhfire.service.vo.SiAeAllVO;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -28,12 +29,10 @@ public class SiAeAllServiceImpl implements SiAeAllService {
         Optional.ofNullable(endTime).orElseThrow(() -> new BusinessException("结束时间不能为空"));
         Map<String, Double> aeAllCollect = siAeAllMapper.selectAeAllCollect(startTime,endTime);
         //获取同比
-        startTime.setYear(Integer.parseInt(DateUtils.getYear(startTime)) - 1 -1900);
-        endTime.setYear(Integer.parseInt(DateUtils.getYear(endTime)) - 1 -1900);
-        Map<String, Double> upAllCollect = siAeAllMapper.selectAeAllCollect(startTime,endTime);
+        Date upStartTime = DateUtils.addYears(startTime, -1);
+        Date upEndTime = DateUtils.addYears(endTime, -1);
+        Map<String, Double> upAllCollect = siAeAllMapper.selectAeAllCollect(upStartTime,upEndTime);
         //获取环比
-        startTime.setYear(Integer.parseInt(DateUtils.getYear(startTime)) + 1 - 1900);
-        endTime.setYear(Integer.parseInt(DateUtils.getYear(endTime)) + 1 - 1900);
         //获取两个时间天数之差
         int distanceOfTwoDate = DateUtils.getDistanceOfTwoDateNew(startTime, endTime);
         Date linkEndTime = DateUtils.addDays(startTime, -1);
@@ -46,14 +45,10 @@ public class SiAeAllServiceImpl implements SiAeAllService {
                 Double radio = aeAll.get(type);
                 siAeAllVO.setNumber(radio);
                 if (0 != radio){
-                    double upRadio = Optional.ofNullable(upAllCollect).map(up -> up.get(type)).orElse(0.0)/radio;
-                    BigDecimal b = new BigDecimal(upRadio);
-                    upRadio = b.setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
-                    siAeAllVO.setSameRatio(upRadio);
-                    double linkRadio = Optional.ofNullable(linkAllCollect).map(link -> link.get(type)).orElse(0.0)/radio;
-                    b = new BigDecimal(linkRadio);
-                    linkRadio = b.setScale(4, BigDecimal.ROUND_HALF_UP).doubleValue();
-                    siAeAllVO.setLinkRelativeRatio(linkRadio);
+                    double upRadio = Optional.ofNullable(upAllCollect).map(up -> up.get(type)).orElse(0.0);
+                    siAeAllVO.setSameRatio(Arith.div(upRadio,radio));
+                    double linkRadio = Optional.ofNullable(linkAllCollect).map(link -> link.get(type)).orElse(0.0);
+                    siAeAllVO.setLinkRelativeRatio(Arith.div(linkRadio,radio));
                 }else {
                     siAeAllVO.setSameRatio(0.00);
                     siAeAllVO.setLinkRelativeRatio(0.00);
@@ -65,5 +60,4 @@ public class SiAeAllServiceImpl implements SiAeAllService {
     }
 
 
-
 }