Browse Source

1.0.0 修改测算统计接口

release/v1.0.0
peihao 4 years ago
parent
commit
141054752d
  1. 21
      air/src/main/java/com/air/measuredata/controller/MeasureDataController.java
  2. 6
      air/src/main/java/com/air/measuredata/dto/MeasureStatisticsDto.java
  3. 12
      air/src/main/java/com/air/measuredata/dto/MeasureTrendDto.java
  4. 2
      air/src/main/java/com/air/measuredata/entity/MeasureData.java
  5. 20
      air/src/main/java/com/air/measuredata/mapper/MeasureDataMapper.java
  6. 17
      air/src/main/java/com/air/measuredata/serivce/MeasureDataService.java
  7. 34
      air/src/main/java/com/air/measuredata/serivce/impl/MeasureDataServiceImpl.java
  8. 2
      air/src/main/java/com/air/measuredata/vo/MeasureDataVo.java
  9. 15
      air/src/main/resources/mapper/MeasureDataMapper.xml

21
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<Boolean> 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<MeasureStatisticsDto> statistics() {
return R.ok(measureDataService.statistics());
}
@ApiOperation(value = "测算趋势统计", notes = "测算趋势统计")
@ApiOperation(value = "测算趋势统计(小程序)", notes = "测算趋势统计")
@GetMapping("/trend")
public R trend() {
public R<List<MeasureTrendDto>> 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<Boolean> removeById(@PathVariable Long measureDataId) {
return R.ok(measureDataService.removeById(measureDataId));
}
}

6
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;
}

12
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;
}

2
air/src/main/java/com/air/measuredata/entity/MeasureData.java

@ -113,7 +113,7 @@ public class MeasureData extends Model<MeasureData> {
private BigDecimal selfCommerceRate;
@ApiModelProperty(value = "商业可售数量")
private Integer selfCommerceAamount;
private Integer selfCommerceAmount;
@ApiModelProperty(value = "商业可售价格")
private BigDecimal selfCommercePrice;

20
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<MeasureData> {
/**
* 统计所有误差之和
* @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<MeasureTrendDto> getTrend(@Param("startTime")String startTime, @Param("endTime") String endTime);
}

17
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<MeasureData> {
/**
* 测算结果统计
* @author peihao
* @date 2021/6/7
* @return
**/
MeasureStatisticsDto statistics();
MeasureTrendDto trend();
/**
* 测算趋势统计接口
* @author peihao
* @date 2021/6/7
* @return
**/
List<MeasureTrendDto> trend();
}

34
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;
/**
* 测算数据
@ -33,22 +34,35 @@ public class MeasureDataServiceImpl extends ServiceImpl<MeasureDataMapper, Measu
//测试正确数
int precisionSum = this.count(Wrappers.<MeasureData>query().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();
if (absoluteValueSum != null){
//预测误差
BigDecimal error = absoluteValueSum.divide(totle).setScale(2, BigDecimal.ROUND_HALF_UP);
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<MeasureTrendDto> 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<MeasureTrendDto> 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;
}
}

2
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;

15
air/src/main/resources/mapper/MeasureDataMapper.xml

@ -4,4 +4,19 @@
<mapper namespace="com.air.measuredata.mapper.MeasureDataMapper">
<select id="getTrend" resultType="com.air.measuredata.dto.MeasureTrendDto">
SELECT
count(measure_data_id) total,
sum(forecast_net_profit_ratio) interestRate,
sum(( forecast_premium_rate - premium_rate )) premiumSpread,
DATE_FORMAT( create_date, '%Y%m' ) statisticDate
FROM
measure_data
WHERE
DATE_FORMAT( create_date, '%Y%m' ) >= #{startTime}
and #{endTime} >= DATE_FORMAT( create_date, '%Y%m' )
GROUP BY
DATE_FORMAT( create_date, '%Y%m' )
order by create_date asc
</select>
</mapper>

Loading…
Cancel
Save