Commit 70efd29e authored by shiyiwei's avatar shiyiwei

能耗分布bug

parent 28326304
......@@ -26,16 +26,26 @@ import java.util.List;
* @author
* @date 2018-4-3 10:11:34
*/
@RestController
@RestController//
/*@RestController=@Controller+@ResponseBody
*
* 返回json数据不需要在方法前面加@ResponseBody注解了,但是使用@RestController这个注解,就不能返回jsp,html页面,视图解析器无法解析jsp,html页面
*
* */
@RequestMapping("buildtp")
public class BuildTpController extends PaginationController<BuildTp> {
@Autowired
private BuildTpService buildTpServiceImpl;
/*
* @ApiOperation注解不是Spring自带的,他是swagger里的,它是swagger里的
* 注解@ApiOperation是用来构建API文档的
* @ApiOperation(value="接口说明",httpMethod="接口请求方式",response="接口返回参数类型",notes="接口发布说明")
*/
@ApiOperation(value="添加建筑类型", notes="添加建筑类型")
@PostMapping(value = "/add")
@PostMapping(value = "/add")//
/* // @PostMapping 是一个组合注解 是@RequestMapping(method=RequestMethod.POST)的缩写*/
public Result add(@Valid BuildTp buildTp) {
PersistModel data = buildTpServiceImpl.save(buildTp);
return Result.builder(data);
......
......@@ -19,7 +19,12 @@ import javax.persistence.Table;
@Table(name = "bus_build_tp")
public class BuildTp{
/*
@Table
常用两个属性
name :用来命名,当前实体类对应数据库表的名字
uniqueConstraints :用来批量命名唯一键 其作用等同于多个@Column(unique=true)
*/
private String bldTpId;
......
......@@ -160,6 +160,7 @@ public class BusDeviceController extends PaginationController<BusDevice> {
}
//设置响应头信息
response.setHeader("Content-disposition", "attachment;filename="+URLEncoder.encode(filename, "utf-8"));
try {
OutputStream outputStream = response.getOutputStream();
workbook.write(outputStream);
......
......@@ -11,9 +11,9 @@ import javax.persistence.Entity;
* 原始数据 + 传感器数据 + 表具数据
*/
@Entity
@Data
@NoArgsConstructor
@AllArgsConstructor
@Data//不用添加setter getter方法
@NoArgsConstructor//提供一个无参构造
@AllArgsConstructor//提供一个全参构造
public class Original {
//设备num
......
......@@ -13,7 +13,6 @@ import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.rcisoft.business.mainte.adaptive.AddressUtils;
import org.rcisoft.business.mainte.adaptive.IPUtils;
import org.rcisoft.business.mainte.adaptive.dao.BusParamReferRepository;
import org.rcisoft.business.mainte.adaptive.dao.BusTemperatureRepository;
import org.rcisoft.business.mainte.adaptive.dao.TotalSensorRepository;
......
......@@ -4,7 +4,9 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.rcisoft.business.mainte.distributed.entity.EnergyDistributed;
import org.rcisoft.business.mainte.distributed.service.MainteDistributedService;
import org.rcisoft.business.mainte.distributed.vo.EnergyDistributedVo;
import org.rcisoft.core.constant.MessageConstant;
import org.rcisoft.core.model.PersistModel;
import org.rcisoft.core.result.Result;
......@@ -13,6 +15,11 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.Calendar;
import java.util.ArrayList;
import java.util.List;
/**
* Created by JiChao on 2018/4/23.
*/
......@@ -21,8 +28,13 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("maintedistributed")
public class MainteDistributedController {
/*
GoGlic
*/
@Autowired
private MainteDistributedService mainteDistributedServiceImpl;
//int month;
@ApiOperation(value="能耗分布", notes="能耗分布")
@ApiImplicitParams({@ApiImplicitParam(name = "year", value = "年", required = true, dataType = "字符串或数字"),
......@@ -30,7 +42,15 @@ public class MainteDistributedController {
})
@RequestMapping("/queryEnergyDistributed")
public Result queryEnergyDistributed(@RequestParam String year, @RequestParam(required = false) String month) {
return Result.builder(new PersistModel(1), MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_ERROR, mainteDistributedServiceImpl.queryEnergyDistributed(year, month));
Calendar cale =Calendar.getInstance();//创建一个日历类
int month_now = cale.get(Calendar.MONTH)+1;//得到当前月份
List<EnergyDistributedVo> list = new ArrayList<>();//
if(month.equals(String.valueOf(month_now))){
list=null;
}else{
list =mainteDistributedServiceImpl.queryEnergyDistributed(year, month);
}
return Result.builder(new PersistModel(1), MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_ERROR,list);
}
@ApiOperation(value="能耗对比", notes="能耗对比")
......@@ -39,6 +59,11 @@ public class MainteDistributedController {
})
@RequestMapping("/queryEnergyCompared")
public Result queryEnergyCompared(@RequestParam String year, @RequestParam String bldZoneId) {
return Result.builder(new PersistModel(1), MessageConstant.MESSAGE_ALERT_SUCCESS, MessageConstant.MESSAGE_ALERT_ERROR, mainteDistributedServiceImpl.queryEnergyCompared(year, bldZoneId));
}
......
package org.rcisoft.business.mainte.distributed.dao;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.rcisoft.business.mainte.distributed.entity.BuildingAge;
......@@ -32,11 +33,12 @@ public interface MainteDistributedRepository {
"select t.BLD_TP_NM,e.MON," +
"CONVERT(sum((if(e.WATER_MONEY is null, 0, e.WATER_MONEY)+if(e.ELEC_MONEY is null, 0, e.ELEC_MONEY)+if(e.GAS_MONEY is null, 0, e.GAS_MONEY))*12/b.BLD_AREA),DECIMAL(10,2)) MONEY " +
"from energy_count_m e,bus_project b,bus_build_tp t " +
"where e.PRO_ID=b.PRO_ID and b.BLD_TP_ID=t.BLD_TP_ID and e.`YEAR`=#{year} and b.BLD_ZONE_ID=#{bldZoneId} " +
"where e.PRO_ID=b.PRO_ID and b.BLD_TP_ID=t.BLD_TP_ID and e.`YEAR`=#{year} and e.`MON` &lt; #{month} and b.BLD_ZONE_ID=#{bldZoneId} " +
"group by e.PRO_ID,t.BLD_TP_NM,e.MON order by t.BLD_TP_NM,e.MON" +
"</script>")
@ResultMap(value = "EnergyCompared")
List<EnergyCompared> queryEnergyCompared(Params params);
//and e.`MON`<#{month}
@Select("<script>select b.PRO_NM,t.BLD_TP_NM,date_format(b.BLD_YEAR, '%Y') `YEAR`," +
"convert(sum((if(e.WATER_MONEY is null, 0, e.WATER_MONEY)+if(e.ELEC_MONEY is null, 0, e.ELEC_MONEY)+if(e.GAS_MONEY is null, 0, e.GAS_MONEY))/b.BLD_AREA),decimal(10,2)) MONEY " +
......
......@@ -14,7 +14,7 @@ import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
import java.util.Calendar;
/**
* Created by JiChao on 2018/4/23.
*/
......@@ -28,6 +28,10 @@ public class MainteDistributedServiceImpl implements MainteDistributedService {
public List<EnergyDistributedVo> queryEnergyDistributed(String year, String month) {
List<EnergyDistributedVo> resultList = new ArrayList<>();
// 如果month是空,查全年的
/*
* month 如果是null 返回查找全年
* month 不为null返回的月数小于当前月
* */
List<EnergyDistributed> list = mainteDistributedRepository.queryEnergyDistributed(new Params(year, month, null));
list.forEach(energyDistributed -> {
EnergyDistributedVo vo = new EnergyDistributedVo();
......@@ -39,11 +43,15 @@ public class MainteDistributedServiceImpl implements MainteDistributedService {
value.add(Float.parseFloat(coordinate[0]));
value.add(Float.parseFloat(coordinate[1]));
//值
//
value.add(new BigDecimal(0)
.add(energyDistributed.getWaterMoney())
.add(energyDistributed.getElecMoney())
.add(energyDistributed.getGasMoney())
.divide(energyDistributed.getBldArea(), 2)
.multiply(new BigDecimal(12)) //乘以12 *GoGlic
.divide(energyDistributed.getBldArea(), 2).setScale(2)
// .divide(energyDistributed.getBldArea(), 2)
);
vo.setValue(value);
//放入结果集
......@@ -54,13 +62,23 @@ public class MainteDistributedServiceImpl implements MainteDistributedService {
@Override
public EnergyComparedVo queryEnergyCompared(String year, String bldZoneId) {
//标题集
List<Object> title = new ArrayList<>();
//返回集
List<EnergyComparedVo.EnergyCompareResult> resultList = new ArrayList<>();
//结果集
List<EnergyCompared> list = mainteDistributedRepository.queryEnergyCompared(new Params(year, null, bldZoneId));
Calendar cale =Calendar.getInstance();//创建一个日历类
int month_now = cale.get(Calendar.MONTH)+1;//得到当前月份
String month = String.valueOf(month_now);
if (month.length()==1){
month="0"+month;
}
System.err.println("-=-=-=-=-=-=-=-=-=-=-=-=--==-===-="+month +"-==-=-=-=-=-=-==-=-=-==-=-=-=-=-==--=-=-=-=-=-==-====--==-=");
// List<EnergyCompared> list = mainteDistributedRepository.queryEnergyCompared(new Params(year, null, bldZoneId));
List<EnergyCompared> list = mainteDistributedRepository.queryEnergyCompared(new Params(year,month,bldZoneId));
list.forEach(e -> {
String bldTPNm = e.getBldTPNm();
//判断,如果title中没有这个值
if(!title.contains(bldTPNm)){
......@@ -70,11 +88,12 @@ public class MainteDistributedServiceImpl implements MainteDistributedService {
//放入标题集
title.add(bldTPNm);
}
//取返回集中对应的记录,添加内容
resultList.forEach(ev -> {
if (StringUtils.equals(ev.getName(), bldTPNm))
ev.getData().set(e.getMon() - 1, e.getMoney());
});
});
});
//结果
return new EnergyComparedVo(title, resultList);
......
......@@ -11,7 +11,8 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor
@Data
public class Params {
private String year,month;
private String year;
private String month;
//建筑分区id
private String bldZoneId;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment