diff --git a/air/src/main/java/com/air/measuredata/controller/MeasureDataController.java b/air/src/main/java/com/air/measuredata/controller/MeasureDataController.java index 1d61ac5..ebb5efe 100644 --- a/air/src/main/java/com/air/measuredata/controller/MeasureDataController.java +++ b/air/src/main/java/com/air/measuredata/controller/MeasureDataController.java @@ -1,6 +1,8 @@ package com.air.measuredata.controller; import cn.hutool.core.bean.BeanUtil; +import com.air.measuredata.dto.MeasureStatisticsDto; +import com.air.measuredata.dto.MeasureTrendDto; import com.air.measuredata.entity.MeasureData; import com.air.measuredata.serivce.MeasureDataService; import com.air.measuredata.vo.MeasureDataVo; @@ -13,6 +15,8 @@ import lombok.AllArgsConstructor; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.*; +import java.util.List; + /** * 测算数据 @@ -62,36 +66,33 @@ public class MeasureDataController { */ @ApiOperation(value = "保存测算数据", notes = "保存测算数据") @PostMapping - public R save(@RequestBody MeasureDataVo measureDataVo) { + public R save(@RequestBody MeasureDataVo measureDataVo) { MeasureData measureData = new MeasureData(); BeanUtil.copyProperties(measureDataVo,measureData); return R.ok(measureDataService.saveOrUpdate(measureData)); } - @ApiOperation(value = "测算结果统计", notes = "测算结果统计") + @ApiOperation(value = "测算结果统计(小程序)", notes = "测算结果统计") @GetMapping("/statistics") - public R statistics() { + public R statistics() { return R.ok(measureDataService.statistics()); } - @ApiOperation(value = "测算趋势统计", notes = "测算趋势统计") + @ApiOperation(value = "测算趋势统计(小程序)", notes = "测算趋势统计") @GetMapping("/trend") - public R trend() { + public R> trend() { return R.ok(measureDataService.trend()); } - - - /** * 通过id删除测算数据 * * @param measureDataId id * @return R */ - @ApiOperation(value = "通过id删除测算数据", notes = "通过id删除测算数据") + @ApiOperation(value = "通过id删除测算数据(通用)", notes = "通过id删除测算数据") @DeleteMapping("/{measureDataId}") - public R removeById(@PathVariable Long measureDataId) { + public R removeById(@PathVariable Long measureDataId) { return R.ok(measureDataService.removeById(measureDataId)); } } diff --git a/air/src/main/java/com/air/measuredata/dto/MeasureStatisticsDto.java b/air/src/main/java/com/air/measuredata/dto/MeasureStatisticsDto.java index 78fbb07..e513930 100644 --- a/air/src/main/java/com/air/measuredata/dto/MeasureStatisticsDto.java +++ b/air/src/main/java/com/air/measuredata/dto/MeasureStatisticsDto.java @@ -18,11 +18,11 @@ public class MeasureStatisticsDto { private static final long serialVersionUID = 1L; @ApiModelProperty(value = "测算宗数") - private Integer totle; + private int totle = 0; @ApiModelProperty(value = "准确率") - private BigDecimal precision; + private double precision = 0d; @ApiModelProperty(value = "预测误差") - private BigDecimal error; + private double error = 0d; } diff --git a/air/src/main/java/com/air/measuredata/dto/MeasureTrendDto.java b/air/src/main/java/com/air/measuredata/dto/MeasureTrendDto.java index 4149dca..f102922 100644 --- a/air/src/main/java/com/air/measuredata/dto/MeasureTrendDto.java +++ b/air/src/main/java/com/air/measuredata/dto/MeasureTrendDto.java @@ -17,12 +17,18 @@ import java.math.BigDecimal; public class MeasureTrendDto { private static final long serialVersionUID = 1L; + @ApiModelProperty(value = "统计时间") + private String statisticDate; + @ApiModelProperty(value = "溢价率差异值") - private BigDecimal premiumSpread; + private double premiumSpread = 0; @ApiModelProperty(value = "平均差异值") - private BigDecimal average; + private double average = 0; @ApiModelProperty(value = "我的净利率") - private BigDecimal interestRate; + private double interestRate = 0; + + @ApiModelProperty(value = "总宗数",hidden = true) + private int total = 0; } diff --git a/air/src/main/java/com/air/measuredata/entity/MeasureData.java b/air/src/main/java/com/air/measuredata/entity/MeasureData.java index 678b1b6..3b239c4 100644 --- a/air/src/main/java/com/air/measuredata/entity/MeasureData.java +++ b/air/src/main/java/com/air/measuredata/entity/MeasureData.java @@ -113,7 +113,7 @@ public class MeasureData extends Model { private BigDecimal selfCommerceRate; @ApiModelProperty(value = "商业可售数量") - private Integer selfCommerceAamount; + private Integer selfCommerceAmount; @ApiModelProperty(value = "商业可售价格") private BigDecimal selfCommercePrice; diff --git a/air/src/main/java/com/air/measuredata/mapper/MeasureDataMapper.java b/air/src/main/java/com/air/measuredata/mapper/MeasureDataMapper.java index c44977b..9f5f908 100644 --- a/air/src/main/java/com/air/measuredata/mapper/MeasureDataMapper.java +++ b/air/src/main/java/com/air/measuredata/mapper/MeasureDataMapper.java @@ -1,10 +1,13 @@ package com.air.measuredata.mapper; +import com.air.measuredata.dto.MeasureTrendDto; import com.air.measuredata.entity.MeasureData; import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; import java.math.BigDecimal; +import java.util.List; /** * 测算数据 @@ -14,7 +17,24 @@ import java.math.BigDecimal; **/ public interface MeasureDataMapper extends BaseMapper { + + /** + * 统计所有误差之和 + * @author peihao + * @date 2021/6/7 + * @return + **/ @Select("select sum(error_absolute_value) from measure_data") BigDecimal getErrorAbsoluteValueSum(); + /** + * 测算趋势统计接口 + * @author peihao + * @param startTime 开始时间 + * @param endTime 结束时间 + * @date 2021/endTime/7 + * @return + **/ + List getTrend(@Param("startTime")String startTime, @Param("endTime") String endTime); + } diff --git a/air/src/main/java/com/air/measuredata/serivce/MeasureDataService.java b/air/src/main/java/com/air/measuredata/serivce/MeasureDataService.java index f9c3145..6570108 100644 --- a/air/src/main/java/com/air/measuredata/serivce/MeasureDataService.java +++ b/air/src/main/java/com/air/measuredata/serivce/MeasureDataService.java @@ -5,6 +5,8 @@ import com.air.measuredata.dto.MeasureTrendDto; import com.air.measuredata.entity.MeasureData; import com.baomidou.mybatisplus.extension.service.IService; +import java.util.List; + /** * 测算数据 * @@ -13,8 +15,21 @@ import com.baomidou.mybatisplus.extension.service.IService; */ public interface MeasureDataService extends IService { + + /** + * 测算结果统计 + * @author peihao + * @date 2021/6/7 + * @return + **/ MeasureStatisticsDto statistics(); - MeasureTrendDto trend(); + /** + * 测算趋势统计接口 + * @author peihao + * @date 2021/6/7 + * @return + **/ + List trend(); } diff --git a/air/src/main/java/com/air/measuredata/serivce/impl/MeasureDataServiceImpl.java b/air/src/main/java/com/air/measuredata/serivce/impl/MeasureDataServiceImpl.java index 228e168..0f5146e 100644 --- a/air/src/main/java/com/air/measuredata/serivce/impl/MeasureDataServiceImpl.java +++ b/air/src/main/java/com/air/measuredata/serivce/impl/MeasureDataServiceImpl.java @@ -5,13 +5,14 @@ import com.air.measuredata.dto.MeasureTrendDto; import com.air.measuredata.entity.MeasureData; import com.air.measuredata.mapper.MeasureDataMapper; import com.air.measuredata.serivce.MeasureDataService; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.air.utils.DateUtil; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.stereotype.Service; import java.math.BigDecimal; -import java.time.LocalDate; +import java.time.LocalDateTime; +import java.util.List; /** * 测算数据 @@ -27,28 +28,41 @@ public class MeasureDataServiceImpl extends ServiceImplquery().lambda().eq(MeasureData::getAccuracy, 1)); //准确率 - BigDecimal precision = new BigDecimal(precisionSum).divide(totle).setScale(2, BigDecimal.ROUND_HALF_UP); + BigDecimal precision = new BigDecimal(precisionSum).divide(totle,2, BigDecimal.ROUND_HALF_UP); //误差之和 BigDecimal absoluteValueSum = baseMapper.getErrorAbsoluteValueSum(); - //预测误差 - BigDecimal error = absoluteValueSum.divide(totle).setScale(2, BigDecimal.ROUND_HALF_UP); + if (absoluteValueSum != null){ + //预测误差 + BigDecimal error = absoluteValueSum.divide(totle,2,BigDecimal.ROUND_HALF_UP); + statisticsDto.setError(error.doubleValue()); + } statisticsDto.setTotle(totle.intValue()); - statisticsDto.setPrecision(precision); - statisticsDto.setError(error); + statisticsDto.setPrecision(precision.doubleValue()); return statisticsDto; } @Override - public MeasureTrendDto trend() { - MeasureTrendDto trendDto = new MeasureTrendDto(); + public List trend() { //统计时间 - LocalDate startTime = LocalDate.now().minusYears(1); - return trendDto; + LocalDateTime now = LocalDateTime.now(); + String startTime = DateUtil.fromString(now.minusYears(1), "yyyyMM"); + String endTime = DateUtil.fromString(now, "yyyyMM"); + List list = baseMapper.getTrend(startTime, endTime); + for (MeasureTrendDto trend : list) { + if (trend.getTotal() == 0) { + continue; + } + //平均差值= 溢价率差值/时间宗数 + double value = new BigDecimal(trend.getPremiumSpread()).divide(new BigDecimal(trend.getTotal()),2, BigDecimal.ROUND_HALF_UP).doubleValue(); + trend.setAverage(value); + } + return list; } + } diff --git a/air/src/main/java/com/air/measuredata/vo/MeasureDataVo.java b/air/src/main/java/com/air/measuredata/vo/MeasureDataVo.java index 4c821b0..4144270 100644 --- a/air/src/main/java/com/air/measuredata/vo/MeasureDataVo.java +++ b/air/src/main/java/com/air/measuredata/vo/MeasureDataVo.java @@ -105,7 +105,7 @@ public class MeasureDataVo { private BigDecimal selfCommerceRate; @ApiModelProperty(value = "商业可售数量") - private Integer selfCommerceAamount; + private Integer selfCommerceAmount; @ApiModelProperty(value = "商业可售价格") private BigDecimal selfCommercePrice; diff --git a/air/src/main/resources/mapper/MeasureDataMapper.xml b/air/src/main/resources/mapper/MeasureDataMapper.xml index f57d343..4efdfef 100644 --- a/air/src/main/resources/mapper/MeasureDataMapper.xml +++ b/air/src/main/resources/mapper/MeasureDataMapper.xml @@ -4,4 +4,19 @@ +