增加供水统计分析接口
parent
d683fa2792
commit
cc7765d782
|
|
@ -0,0 +1,166 @@
|
|||
package com.gunshi.project.xyt.controller;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.gunshi.project.xyt.entity.vo.StWaterRReorganizeVo;
|
||||
import com.gunshi.project.xyt.entity.vo.StWaterRReorganizeYearVo;
|
||||
import com.gunshi.project.xyt.util.ConvertUtil;
|
||||
import com.gunshi.project.xyt.util.DateUtil;
|
||||
import com.gunshi.project.xyt.util.ExcelUtil;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.gunshi.core.result.R;
|
||||
import com.gunshi.project.xyt.model.StWaterRReorganize;
|
||||
import com.gunshi.project.xyt.service.StWaterRReorganizeService;
|
||||
import com.gunshi.project.xyt.validate.markers.Insert;
|
||||
import com.gunshi.project.xyt.validate.markers.Update;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
/**
|
||||
* 描述: 供水量整编表
|
||||
* author: cxw
|
||||
* date: 2024-07-24 11:22:46
|
||||
*/
|
||||
@Tag(name = "供水量整编表")
|
||||
@RestController
|
||||
@RequestMapping(value="/stWaterRReorganize")
|
||||
public class StWaterRReorganizeController {
|
||||
|
||||
@Autowired
|
||||
private StWaterRReorganizeService service;
|
||||
|
||||
|
||||
@Operation(summary = "新增")
|
||||
@PostMapping("/insert")
|
||||
public R<StWaterRReorganize> insert(@Validated(Insert.class) @RequestBody StWaterRReorganize dto) {
|
||||
boolean result = service.save(dto);
|
||||
return R.ok(result ? dto : null);
|
||||
}
|
||||
|
||||
@Operation(summary = "修改")
|
||||
@PostMapping("/update")
|
||||
public R<StWaterRReorganize> update(@Validated(Update.class) @RequestBody StWaterRReorganize dto) {
|
||||
boolean result = service.updateById(dto);
|
||||
return R.ok(result ? dto : null);
|
||||
}
|
||||
|
||||
@Operation(summary = "删除")
|
||||
@GetMapping("/del/{id}")
|
||||
public R<Boolean> del(@Schema(name = "id") @PathVariable("id") Serializable id) {
|
||||
return R.ok(service.removeById(id));
|
||||
}
|
||||
|
||||
@Operation(summary = "列表")
|
||||
@PostMapping("/list")
|
||||
public R<List<StWaterRReorganize>> list(@RequestBody @Validated StWaterRReorganize stWaterRReorganize) {
|
||||
String searchType = stWaterRReorganize.getSearchType();
|
||||
String groupBy = "";
|
||||
if("2".equals(searchType)){
|
||||
groupBy = "LEFT(tm, 10)";
|
||||
} else if("3".equals(searchType)){
|
||||
groupBy = "LEFT(tm, 7)";
|
||||
} else if("4".equals(searchType)){
|
||||
groupBy = "LEFT(tm, 4)";
|
||||
} else {
|
||||
groupBy = "LEFT(tm, 13)";
|
||||
}
|
||||
QueryWrapper<StWaterRReorganize> wrapper = new QueryWrapper<StWaterRReorganize>()
|
||||
.select(groupBy + " tm,ROUND( AVG ( ecology_q ), 2 ) ecology_q,SUM ( ecology_v ) ecology_v,ROUND( AVG ( life_q ), 2 ) life_q,SUM ( life_v ) life_v,SUM ( sum_v ) sum_v")
|
||||
.ge(ObjectUtils.isNotNull(stWaterRReorganize.getStartTime()), "tm", stWaterRReorganize.getStartTime())
|
||||
.le(ObjectUtils.isNotNull(stWaterRReorganize.getEndTime()), "tm", stWaterRReorganize.getEndTime())
|
||||
.groupBy(groupBy);
|
||||
if(StringUtils.isNotBlank(stWaterRReorganize.getSortField())){
|
||||
wrapper.orderBy(true, ObjectUtils.isEmpty(stWaterRReorganize.getIsAsc()) ? false : stWaterRReorganize.getIsAsc(), stWaterRReorganize.getSortField());
|
||||
}
|
||||
return R.ok(service.list(wrapper));
|
||||
}
|
||||
|
||||
@Operation(summary = "分页")
|
||||
@PostMapping("/page")
|
||||
public R<Page<StWaterRReorganize>> page(@RequestBody @Validated StWaterRReorganize stWaterRReorganize) {
|
||||
String searchType = stWaterRReorganize.getSearchType();
|
||||
String groupBy = "";
|
||||
if("2".equals(searchType)){
|
||||
groupBy = "LEFT(tm, 10)";
|
||||
} else if("3".equals(searchType)){
|
||||
groupBy = "LEFT(tm, 7)";
|
||||
} else if("4".equals(searchType)){
|
||||
groupBy = "LEFT(tm, 4)";
|
||||
} else {
|
||||
groupBy = "LEFT(tm, 13)";
|
||||
}
|
||||
QueryWrapper<StWaterRReorganize> wrapper = new QueryWrapper<StWaterRReorganize>()
|
||||
.select(groupBy + " tm,ROUND( AVG ( ecology_q ), 2 ) ecology_q,SUM ( ecology_v ) ecology_v,ROUND( AVG ( life_q ), 2 ) life_q,SUM ( life_v ) life_v,SUM ( sum_v ) sum_v")
|
||||
.ge(ObjectUtils.isNotNull(stWaterRReorganize.getStartTime()), "tm", stWaterRReorganize.getStartTime())
|
||||
.le(ObjectUtils.isNotNull(stWaterRReorganize.getEndTime()), "tm", stWaterRReorganize.getEndTime())
|
||||
.groupBy(groupBy);
|
||||
if(StringUtils.isNotBlank(stWaterRReorganize.getSortField())){
|
||||
wrapper.orderBy(true, ObjectUtils.isEmpty(stWaterRReorganize.getIsAsc()) ? false : stWaterRReorganize.getIsAsc(), stWaterRReorganize.getSortField());
|
||||
}
|
||||
return R.ok(service.page(stWaterRReorganize.getPageSo().toPage(), wrapper));
|
||||
}
|
||||
|
||||
@Operation(summary = "供水水方数据导出")
|
||||
@PostMapping("/exportWaterRReorganizeDataExcel")
|
||||
@CrossOrigin
|
||||
public void exportWaterRReorganizeDataExcel(@RequestBody @Validated StWaterRReorganize stWaterRReorganize, HttpServletResponse response) {
|
||||
String searchType = stWaterRReorganize.getSearchType();
|
||||
String start = DateUtil.convertDateToMDSString(stWaterRReorganize.getStartTime());
|
||||
String end = DateUtil.convertDateToMDSString(stWaterRReorganize.getEndTime());
|
||||
if("2".equals(searchType)){
|
||||
start = start.substring(0, 10);
|
||||
end = end.substring(0, 10);
|
||||
} else if("3".equals(searchType)){
|
||||
start = start.substring(0, 7);
|
||||
end = end.substring(0, 7);
|
||||
} else if("4".equals(searchType)){
|
||||
start = start.substring(0, 4);
|
||||
end = end.substring(0, 4);
|
||||
} else {
|
||||
start = start.substring(0, 13);
|
||||
end = end.substring(0, 13);
|
||||
}
|
||||
String filename = "供水水方表" + start + "_" + end;
|
||||
List<StWaterRReorganizeVo> vos = ConvertUtil.entityToVoList(this.list(stWaterRReorganize).getData(), StWaterRReorganizeVo.class);
|
||||
ExcelUtil.exportExcel(vos, filename, StWaterRReorganizeVo.class, response, "供水水方表");
|
||||
}
|
||||
|
||||
@Operation(summary = "统计分析")
|
||||
@PostMapping("/getYearStatisticAnalysis")
|
||||
public R<List<StWaterRReorganizeYearVo>> getYearStatisticAnalysis(@Schema(name = "year", description = "年度") @RequestParam("year") int year) {
|
||||
List<StWaterRReorganizeYearVo> resList = new ArrayList<>();
|
||||
service.getYearStatisticAnalysis(year, resList);
|
||||
return R.ok(resList);
|
||||
}
|
||||
|
||||
@Operation(summary = "统计分析数据导出")
|
||||
@PostMapping("/exportYearStatisticAnalysisExcel")
|
||||
@CrossOrigin
|
||||
public void exportYearStatisticAnalysisExcel(@Schema(name = "year", description = "年度") @RequestParam("year") int year, HttpServletResponse response) {
|
||||
String filename = year + "年度统计分析";
|
||||
List<StWaterRReorganizeYearVo> resList = new ArrayList<>();
|
||||
service.getYearStatisticAnalysis(year, resList);
|
||||
ExcelUtil.exportExcel(resList, filename, StWaterRReorganizeYearVo.class, response, "统计分析");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
package com.gunshi.project.xyt.entity.vo;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import com.alibaba.excel.annotation.write.style.ColumnWidth;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
*@description
|
||||
*@author cxw
|
||||
*@classname StWaterRReorganizeVo.java
|
||||
*@create 2024-07-24, 周三, 11:51:01
|
||||
*/
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class StWaterRReorganizeVo {
|
||||
|
||||
@ExcelProperty({"${title}", "时间"})
|
||||
@ColumnWidth(15)
|
||||
private String tm;
|
||||
|
||||
/**
|
||||
* 流量(生态供水)
|
||||
*/
|
||||
@ExcelProperty({"${title}", "流量(生态供水)(m³/s)"})
|
||||
private BigDecimal ecologyQ;
|
||||
|
||||
/**
|
||||
* 水量(生态供水)
|
||||
*/
|
||||
@ExcelProperty({"${title}", "水量(生态供水)(万m³)"})
|
||||
private BigDecimal ecologyV;
|
||||
|
||||
/**
|
||||
* 流量(生活供水)
|
||||
*/
|
||||
@ExcelProperty({"${title}", "流量(生活供水)(m³/s)"})
|
||||
private BigDecimal lifeQ;
|
||||
|
||||
/**
|
||||
* 水量(生活供水)
|
||||
*/
|
||||
@ExcelProperty({"${title}", "水量(生活供水)(万m³)"})
|
||||
private BigDecimal lifeV;
|
||||
|
||||
/**
|
||||
* 水量小计
|
||||
*/
|
||||
@ExcelProperty({"${title}", "小计(万m³)"})
|
||||
private BigDecimal sumV;
|
||||
}
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
package com.gunshi.project.xyt.entity.vo;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelIgnoreUnannotated;
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import com.alibaba.excel.annotation.write.style.ColumnWidth;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
*@description
|
||||
*@author cxw
|
||||
*@classname StWaterRReorganizeYearVo.java
|
||||
*@create 2024-07-24, 周三, 14:28:34
|
||||
*/
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class StWaterRReorganizeYearVo {
|
||||
|
||||
@Schema(description="时间")
|
||||
private String tm;
|
||||
|
||||
/**
|
||||
* 年度占比(生态供水)
|
||||
*/
|
||||
@Schema(description="年度占比(生态供水)")
|
||||
private String ecologyYearRateV;
|
||||
|
||||
/**
|
||||
* 水量(生态供水)
|
||||
*/
|
||||
@Schema(description="水量(生态供水)")
|
||||
private String ecologyV;
|
||||
|
||||
/**
|
||||
* 同比(生态供水)
|
||||
*/
|
||||
@Schema(description="水量(生态供水)")
|
||||
private String ecologyYoyV;
|
||||
|
||||
/**
|
||||
* 环比(生态供水)
|
||||
*/
|
||||
@Schema(description="水量(生态供水)")
|
||||
private String ecologyQoqV;
|
||||
|
||||
/**
|
||||
* 年度占比(生活供水)
|
||||
*/
|
||||
@Schema(description="年度占比(生活供水)")
|
||||
private String lifeYearRateV;
|
||||
|
||||
/**
|
||||
* 水量(生活供水)
|
||||
*/
|
||||
@Schema(description="水量(生活供水)")
|
||||
private String lifeV;
|
||||
|
||||
/**
|
||||
* 同比(生活供水)
|
||||
*/
|
||||
@Schema(description="同比(生活供水)")
|
||||
private String lifeYoyV;
|
||||
|
||||
/**
|
||||
* 环比(生活供水)
|
||||
*/
|
||||
@Schema(description="环比(生活供水)")
|
||||
private String lifeQoqV;
|
||||
}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
package com.gunshi.project.xyt.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.gunshi.project.xyt.model.StWaterRReorganize;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* 描述: 供水量整编表
|
||||
* author: cxw
|
||||
* date: 2024-07-24 11:22:46
|
||||
*/
|
||||
@Mapper
|
||||
public interface StWaterRReorganizeMapper extends BaseMapper<StWaterRReorganize> {
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,102 @@
|
|||
package com.gunshi.project.xyt.model;
|
||||
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.gunshi.core.dateformat.DateFormatString;
|
||||
import com.gunshi.project.xyt.entity.page.GenericPageParams;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Size;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 描述: 供水量整编表
|
||||
* author: cxw
|
||||
* date: 2024-07-24 11:22:46
|
||||
*/
|
||||
@Schema(description="供水量整编表")
|
||||
@Data
|
||||
@TableName("public.st_water_r_reorganize")
|
||||
public class StWaterRReorganize extends GenericPageParams implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 时间(年月日 时)
|
||||
*/
|
||||
@TableId(value="tm", type= IdType.NONE)
|
||||
@Schema(description="时间(年月日 时)")
|
||||
@Size(max = 13,message = "时间(年月日 时)最大长度要小于 13")
|
||||
// @NotBlank(message = "时间(年月日 时)不能为空")
|
||||
// @NotNull(message = "时间(年月日 时)不能为空")
|
||||
private String tm;
|
||||
|
||||
/**
|
||||
* 流量(生态供水)
|
||||
*/
|
||||
@TableField(value="ecology_q")
|
||||
@Schema(description="流量(生态供水)")
|
||||
private BigDecimal ecologyQ;
|
||||
|
||||
/**
|
||||
* 水量(生态供水)
|
||||
*/
|
||||
@TableField(value="ecology_v")
|
||||
@Schema(description="水量(生态供水)")
|
||||
private BigDecimal ecologyV;
|
||||
|
||||
/**
|
||||
* 流量(生活供水)
|
||||
*/
|
||||
@TableField(value="life_q")
|
||||
@Schema(description="流量(生活供水)")
|
||||
private BigDecimal lifeQ;
|
||||
|
||||
/**
|
||||
* 水量(生活供水)
|
||||
*/
|
||||
@TableField(value="life_v")
|
||||
@Schema(description="水量(生活供水)")
|
||||
private BigDecimal lifeV;
|
||||
|
||||
/**
|
||||
* 水量小计
|
||||
*/
|
||||
@TableField(value="sum_v")
|
||||
@Schema(description="水量小计")
|
||||
private BigDecimal sumV;
|
||||
|
||||
/**
|
||||
* 查询时间类型
|
||||
*/
|
||||
@Schema(description = "查询时间类型searchType:1-小时 2-日 3-月 4-年")
|
||||
@TableField(exist = false)
|
||||
@NotNull(message = "查询时间类型searchType不能为空")
|
||||
private String searchType;
|
||||
|
||||
/**
|
||||
* 选择的起始时间
|
||||
*/
|
||||
@Schema(description = "选择的起始时间")
|
||||
@JsonFormat(pattern = DateFormatString.YYYY_MM_DD_HH_MM_SS, timezone = "GMT+8")
|
||||
@TableField(exist = false)
|
||||
private Date startTime;
|
||||
|
||||
/**
|
||||
* 选择的结束时间
|
||||
*/
|
||||
@Schema(description = "选择的结束时间")
|
||||
@JsonFormat(pattern = DateFormatString.YYYY_MM_DD_HH_MM_SS, timezone = "GMT+8")
|
||||
@TableField(exist = false)
|
||||
private Date endTime;
|
||||
}
|
||||
|
|
@ -0,0 +1,148 @@
|
|||
package com.gunshi.project.xyt.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.gunshi.project.xyt.entity.vo.StWaterRReorganizeYearVo;
|
||||
import com.gunshi.project.xyt.mapper.StWaterRReorganizeMapper;
|
||||
import com.gunshi.project.xyt.model.StWaterRReorganize;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 描述: 供水量整编表
|
||||
* author: cxw
|
||||
* date: 2024-07-24 11:22:46
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public class StWaterRReorganizeService extends ServiceImpl<StWaterRReorganizeMapper, StWaterRReorganize>
|
||||
{
|
||||
|
||||
public List<StWaterRReorganizeYearVo> getYearStatisticAnalysis(int year, List<StWaterRReorganizeYearVo> resList) {
|
||||
// 查询 选择年 数据
|
||||
QueryWrapper<StWaterRReorganize> nowYearQw = new QueryWrapper<StWaterRReorganize>()
|
||||
.select("LEFT(tm, 7) tm,ROUND( AVG ( ecology_q ), 2 ) ecology_q,SUM ( ecology_v ) ecology_v,ROUND( AVG ( life_q ), 2 ) life_q,SUM ( life_v ) life_v,SUM ( sum_v ) sum_v")
|
||||
.eq("LEFT(tm, 4)", String.valueOf(year)).groupBy("LEFT(tm, 7)").orderBy(true, true, "tm");
|
||||
List<StWaterRReorganize> nowYearList = this.list(nowYearQw);
|
||||
|
||||
// 查询 选择年的前一年 数据
|
||||
QueryWrapper<StWaterRReorganize> lastYearQw = new QueryWrapper<StWaterRReorganize>()
|
||||
.select("LEFT(tm, 7) tm,ROUND( AVG ( ecology_q ), 2 ) ecology_q,SUM ( ecology_v ) ecology_v,ROUND( AVG ( life_q ), 2 ) life_q,SUM ( life_v ) life_v,SUM ( sum_v ) sum_v")
|
||||
.eq("LEFT(tm, 4)", String.valueOf(year - 1)).groupBy("LEFT(tm, 7)").orderBy(true, true, "tm");
|
||||
List<StWaterRReorganize> lastYearList = this.list(lastYearQw);
|
||||
|
||||
// 组装VO
|
||||
if(CollectionUtils.isNotEmpty(nowYearList)){
|
||||
BigDecimal ecologyVSum = nowYearList.stream().map(StWaterRReorganize::getEcologyV).reduce(BigDecimal.ZERO, BigDecimal::add);// 年度生态水量的和
|
||||
BigDecimal lifeVSum = nowYearList.stream().map(StWaterRReorganize::getLifeV).reduce(BigDecimal.ZERO, BigDecimal::add);// 年度生活水量的和
|
||||
for(int i = 0; i < nowYearList.size(); i++){
|
||||
String jiantou = "";
|
||||
StWaterRReorganizeYearVo vo = new StWaterRReorganizeYearVo();
|
||||
StWaterRReorganize nowStwrr = nowYearList.get(i);
|
||||
vo.setTm(nowStwrr.getTm());
|
||||
vo.setEcologyYearRateV(nowStwrr.getEcologyV().divide(ecologyVSum, 1, BigDecimal.ROUND_HALF_UP).toString());
|
||||
vo.setEcologyV(nowStwrr.getEcologyV().toString());
|
||||
vo.setLifeYearRateV(nowStwrr.getEcologyV().divide(lifeVSum, 1, BigDecimal.ROUND_HALF_UP).toString());
|
||||
vo.setLifeV(nowStwrr.getLifeV().toString());
|
||||
|
||||
StWaterRReorganize lastStwrr = lastYearList.stream()
|
||||
.filter(item -> nowStwrr.getTm()
|
||||
.equals(String.valueOf((Integer.valueOf(item.getTm().substring(0, 4)) + 1))
|
||||
.concat(item.getTm().substring(4, 7)))).findAny().orElse(null);
|
||||
// 生态同比 (本期数 - 同期数) / 同期数 × 100%
|
||||
if(ObjectUtils.isEmpty(lastStwrr) || lastStwrr.getEcologyV().compareTo(BigDecimal.ZERO) == 0){
|
||||
vo.setEcologyYoyV("-");
|
||||
} else {
|
||||
BigDecimal ecologyYoyV = (nowStwrr.getEcologyV().subtract(lastStwrr.getEcologyV())).divide(lastStwrr.getEcologyV(), 1, BigDecimal.ROUND_HALF_UP);
|
||||
jiantou = "";
|
||||
if(ecologyYoyV.compareTo(BigDecimal.ZERO) == 0){
|
||||
jiantou = "↔";
|
||||
vo.setEcologyYoyV(jiantou);
|
||||
} else {
|
||||
if(ecologyYoyV.compareTo(BigDecimal.ZERO) < 0){
|
||||
jiantou = "↓";
|
||||
} else if(ecologyYoyV.compareTo(BigDecimal.ZERO) > 0){
|
||||
jiantou = "↑";
|
||||
}
|
||||
vo.setEcologyYoyV(jiantou.concat(ecologyYoyV.abs().toString()).concat("%"));
|
||||
}
|
||||
}
|
||||
// 生活同比 (本期数 - 同期数) / 同期数 × 100%
|
||||
if(ObjectUtils.isEmpty(lastStwrr) || lastStwrr.getLifeV().compareTo(BigDecimal.ZERO) == 0){
|
||||
vo.setLifeYoyV("-");
|
||||
} else {
|
||||
BigDecimal lifeYoyV = (nowStwrr.getLifeV().subtract(lastStwrr.getLifeV())).divide(lastStwrr.getLifeV(), 1, BigDecimal.ROUND_HALF_UP);
|
||||
jiantou = "";
|
||||
if(lifeYoyV.compareTo(BigDecimal.ZERO) == 0){
|
||||
jiantou = "↔";
|
||||
vo.setLifeYoyV(jiantou);
|
||||
} else {
|
||||
if(lifeYoyV.compareTo(BigDecimal.ZERO) < 0){
|
||||
jiantou = "↓";
|
||||
} else if(lifeYoyV.compareTo(BigDecimal.ZERO) > 0){
|
||||
jiantou = "↑";
|
||||
}
|
||||
vo.setLifeYoyV(jiantou.concat(lifeYoyV.abs().toString()).concat("%"));
|
||||
}
|
||||
}
|
||||
// 环比 (本期数 - 上期数) / 上期数 × 100%
|
||||
StWaterRReorganize lastOneStwrr;
|
||||
// 如果是1月,需要拿到去年12月的
|
||||
if(i == 0 && nowStwrr.getTm().contains("-01")){
|
||||
lastOneStwrr = lastYearList.stream().filter(item -> item.getTm().contains("-12")).findAny().orElse(null);
|
||||
} else {
|
||||
lastOneStwrr = nowYearList.get(i-1);
|
||||
}
|
||||
// 生态
|
||||
if(ObjectUtils.isEmpty(lastOneStwrr) || lastOneStwrr.getEcologyV().compareTo(BigDecimal.ZERO) == 0){
|
||||
vo.setEcologyQoqV("-");
|
||||
} else {
|
||||
BigDecimal ecologyQoqV = (nowStwrr.getEcologyV().subtract(lastOneStwrr.getEcologyV())).divide(lastOneStwrr.getEcologyV(), 1, BigDecimal.ROUND_HALF_UP);
|
||||
jiantou = "";
|
||||
if(ecologyQoqV.compareTo(BigDecimal.ZERO) == 0){
|
||||
jiantou = "↔";
|
||||
vo.setEcologyQoqV(jiantou);
|
||||
} else {
|
||||
if(ecologyQoqV.compareTo(BigDecimal.ZERO) < 0){
|
||||
jiantou = "↓";
|
||||
} else if(ecologyQoqV.compareTo(BigDecimal.ZERO) > 0){
|
||||
jiantou = "↑";
|
||||
}
|
||||
vo.setEcologyQoqV(jiantou.concat(ecologyQoqV.abs().toString()).concat("%"));
|
||||
}
|
||||
}
|
||||
// 生活
|
||||
if(ObjectUtils.isEmpty(lastOneStwrr) || lastOneStwrr.getLifeV().compareTo(BigDecimal.ZERO) == 0){
|
||||
vo.setLifeQoqV("-");
|
||||
} else {
|
||||
BigDecimal lifeQoqV = (nowStwrr.getLifeV().subtract(lastOneStwrr.getLifeV())).divide(lastOneStwrr.getLifeV(), 1, BigDecimal.ROUND_HALF_UP);
|
||||
jiantou = "";
|
||||
if(lifeQoqV.compareTo(BigDecimal.ZERO) == 0){
|
||||
jiantou = "↔";
|
||||
vo.setLifeQoqV(jiantou);
|
||||
} else {
|
||||
if(lifeQoqV.compareTo(BigDecimal.ZERO) < 0){
|
||||
jiantou = "↓";
|
||||
} else if(lifeQoqV.compareTo(BigDecimal.ZERO) > 0){
|
||||
jiantou = "↑";
|
||||
}
|
||||
vo.setLifeQoqV(jiantou.concat(lifeQoqV.abs().toString()).concat("%"));
|
||||
}
|
||||
}
|
||||
resList.add(vo);
|
||||
}
|
||||
}
|
||||
return resList;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.gunshi.project.xyt.mapper.StWaterRReorganizeMapper">
|
||||
|
||||
</mapper>
|
||||
Loading…
Reference in New Issue