Commit 798c67ca authored by tianyiming's avatar tianyiming

Merge branch 'developer' of http://39.98.45.134:8090/moa/amos-boot-biz into developer

parents f406891c 6718fa39
package com.yeejoin.amos.boot.biz.common;
public class Test {
public static void main(String[] args) {
System.out.println("dddddddddddddd");
}
}
...@@ -17,7 +17,12 @@ public class IndexDto { ...@@ -17,7 +17,12 @@ public class IndexDto {
private String address;// 指标地址 private String address;// 指标地址
private String createdTime;// '上报时间', private String createdTime;// '上报时间',
private String equipmentSpecificName;// private String equipmentSpecificName;//
private String equipmentNumber;
private String value; private String value;
private int count; private int count;
private String equipmentsIdx; private String equipmentsIdx;
private String equipmentIndexName; // 指标名称【风机状态名称】
private String longitude; // 经度
private String latitude; // 纬度
private String frontModule;
} }
...@@ -112,7 +112,7 @@ ...@@ -112,7 +112,7 @@
station_basic.station_type stationType, station_basic.station_type stationType,
station_basic.station_flag stationFlag, station_basic.station_flag stationFlag,
station_basic.area_code areaCode, station_basic.area_code areaCode,
station_basic.jumpPath, station_basic.jump_path,
station_basic.risk_level riskLevel, station_basic.risk_level riskLevel,
station_basic.belong_area belongArea, station_basic.belong_area belongArea,
station_coordinate.longitude, station_coordinate.longitude,
...@@ -154,7 +154,7 @@ ...@@ -154,7 +154,7 @@
<select id="getStationListByRegionCode" resultType="com.yeejoin.amos.boot.module.jxiop.api.dto.TreeDto"> <select id="getStationListByRegionCode" resultType="com.yeejoin.amos.boot.module.jxiop.api.dto.TreeDto">
select select
station_name as name, station_name as name,
station_code as code, sequence_nbr as code,
station_type as parentCode, station_type as parentCode,
sequence_nbr as id, sequence_nbr as id,
'1' as isOnclick '1' as isOnclick
......
...@@ -175,7 +175,7 @@ public class StationBasicController extends BaseController { ...@@ -175,7 +175,7 @@ public class StationBasicController extends BaseController {
@TycloudOperation(ApiLevel = UserType.AGENCY) @TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(httpMethod = "GET", value = "场站地图数据", notes = "场站地图数据") @ApiOperation(httpMethod = "GET", value = "场站地图数据", notes = "场站地图数据")
@GetMapping(value = "/listforMap") @GetMapping(value = "/listforMap")
public ResponseModel<List<StationInfoDto>> getStationList(@RequestParam(value = "areaCode", required = false) String areaCode,@RequestParam(value = "type", required = false) String type) { public ResponseModel<List<StationInfoDto>> getStationList(@RequestParam(value = "areaCode", required = false) String areaCode,@RequestParam(value = "type", required = false,defaultValue = "qj") String type) {
return ResponseHelper.buildResponse(stationBasicServiceImpl.getStationList(areaCode,type)); return ResponseHelper.buildResponse(stationBasicServiceImpl.getStationList(areaCode,type));
} }
} }
...@@ -2,10 +2,11 @@ package com.yeejoin.amos.boot.module.jxiop.biz.controller; ...@@ -2,10 +2,11 @@ package com.yeejoin.amos.boot.module.jxiop.biz.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.biz.common.controller.BaseController; import com.yeejoin.amos.boot.biz.common.controller.BaseController;
import com.yeejoin.amos.boot.module.jxiop.api.dto.DeviceDto;
import com.yeejoin.amos.boot.module.jxiop.api.dto.IndexDto; import com.yeejoin.amos.boot.module.jxiop.api.dto.IndexDto;
import com.yeejoin.amos.boot.module.jxiop.api.dto.PersonAccountDto; import com.yeejoin.amos.boot.module.jxiop.biz.dto.ColModel;
import com.yeejoin.amos.boot.module.jxiop.biz.dto.RegionNationWideDto; import com.yeejoin.amos.boot.module.jxiop.biz.dto.DataGridMock;
import com.yeejoin.amos.boot.module.jxiop.biz.dto.ResultsData;
import com.yeejoin.amos.boot.module.jxiop.biz.service.impl.MonitorFanIndicatorImpl;
import com.yeejoin.amos.boot.module.jxiop.biz.utils.InfluxDButils; import com.yeejoin.amos.boot.module.jxiop.biz.utils.InfluxDButils;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
...@@ -20,6 +21,7 @@ import org.typroject.tyboot.core.restful.doc.TycloudOperation; ...@@ -20,6 +21,7 @@ import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.utils.ResponseHelper; import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel; import org.typroject.tyboot.core.restful.utils.ResponseModel;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
...@@ -34,43 +36,27 @@ import java.util.List; ...@@ -34,43 +36,27 @@ import java.util.List;
public class DeviceController extends BaseController { public class DeviceController extends BaseController {
@Autowired @Autowired
InfluxDButils influxDButils; MonitorFanIndicatorImpl monitorFanIndicatorImpl;
@TycloudOperation(needAuth = false, ApiLevel = UserType.AGENCY) @TycloudOperation(needAuth = false, ApiLevel = UserType.AGENCY)
@ApiOperation(value = "获取告警数据") @ApiOperation(value = "获取每个风机实时告警数据")
@GetMapping("/nationwide") @GetMapping("/nationwide")
public ResponseModel<Page<IndexDto>> getNationWideInfo(@RequestParam(value = "current") int current,@RequestParam public ResponseModel<ResultsData> getNationWideInfo(@RequestParam(value = "current") int current,@RequestParam
(value = "size") int size,@RequestParam(value = "gateway") String gateway,@RequestParam(value = "equipmentNumber") String equipmentNumber) { (value = "size") int size,@RequestParam(value = "stationBasicId") String stationBasicId,@RequestParam(value = "equipmentNumber" , required = false ) String equipmentNumber) {
Page<IndexDto> page = new Page<IndexDto>(); ResultsData resultsData=monitorFanIndicatorImpl.getNationWideInfo( current, size, stationBasicId, equipmentNumber);
page.setCurrent(current); return ResponseHelper.buildResponse(resultsData);
page.setSize(size);
StringBuffer querysql = new StringBuffer("SELECT createdTime ,gatewayId,address,valueLabel,equipmentSpecificName,value FROM ");
querysql.append("indicators_").append(gateway);
querysql.append(" WHERE isAlarm='1' and value!='0.0' and gatewayId=");
querysql.append(gateway);
StringBuffer querysqlcount = new StringBuffer("SELECT count(value) FROM ");
querysqlcount.append("indicators_").append(gateway);
querysqlcount.append(" WHERE isAlarm='1' and value!='0.0' and gatewayId=");
querysqlcount.append(gateway);
if(StringUtils.isNotEmpty(querysqlcount)){
querysqlcount.append(" and equipmentNumber =").append(equipmentNumber);
querysql.append(" and equipmentNumber =").append(equipmentNumber);
}
querysql.append(" ORDER BY time desc LIMIT ").append(page.getSize()).append(" OFFSET ").append((page.getCurrent() - 1)*page.getSize());
//每个分机的指标数据
List<IndexDto> list = influxDButils.getListData(querysql.toString(),IndexDto.class);
List<IndexDto> list1 = influxDButils.getListData(querysqlcount.toString(),IndexDto.class);
page.setRecords(list);
if(list1!=null&&list1.size()>0){
page.setTotal(list1.get(0).getCount());
}
return ResponseHelper.buildResponse(page);
} }
@TycloudOperation(needAuth = false, ApiLevel = UserType.AGENCY)
@ApiOperation(value = "获取历史告警数据")
@GetMapping("/historyNationwide")
public ResponseModel<ResultsData> getLSNationWideInfo(@RequestParam(value = "current") int current,@RequestParam
(value = "size") int size,@RequestParam(value = "stationBasicId") String stationBasicId,@RequestParam(value = "equipmentNumber" , required = false ) String equipmentNumber) {
ResultsData resultsData=monitorFanIndicatorImpl.getLsNationWideInfo( current, size, stationBasicId, equipmentNumber);
return ResponseHelper.buildResponse(resultsData);
}
......
...@@ -3,6 +3,7 @@ package com.yeejoin.amos.boot.module.jxiop.biz.controller; ...@@ -3,6 +3,7 @@ package com.yeejoin.amos.boot.module.jxiop.biz.controller;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.biz.common.controller.BaseController; import com.yeejoin.amos.boot.biz.common.controller.BaseController;
import com.yeejoin.amos.boot.module.jxiop.api.dto.IndexDto;
import com.yeejoin.amos.boot.module.jxiop.api.dto.RunRecord; import com.yeejoin.amos.boot.module.jxiop.api.dto.RunRecord;
import com.yeejoin.amos.boot.module.jxiop.api.dto.TreeDto; import com.yeejoin.amos.boot.module.jxiop.api.dto.TreeDto;
import com.yeejoin.amos.boot.module.jxiop.api.entity.MonitorFanIndicator; import com.yeejoin.amos.boot.module.jxiop.api.entity.MonitorFanIndicator;
...@@ -20,6 +21,7 @@ import org.typroject.tyboot.core.restful.utils.ResponseHelper; ...@@ -20,6 +21,7 @@ import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel; import org.typroject.tyboot.core.restful.utils.ResponseModel;
import java.util.List; import java.util.List;
import java.util.Map;
@RestController @RestController
@Api(tags = "大屏相关API") @Api(tags = "大屏相关API")
...@@ -36,12 +38,13 @@ public class MonitorFanIdxController extends BaseController { ...@@ -36,12 +38,13 @@ public class MonitorFanIdxController extends BaseController {
@TycloudOperation(needAuth = false, ApiLevel = UserType.AGENCY) @TycloudOperation(needAuth = false, ApiLevel = UserType.AGENCY)
@ApiOperation(value = "根据设备编号、网关ID、前段展示模块查询表数据") @ApiOperation(value = "根据设备编号、网关ID、前段展示模块查询表数据")
@GetMapping("/getFanIdxInfoByPage") @GetMapping("/getFanIdxInfoByPage")
public ResponseModel<IPage<MonitorFanIndicator>> getFanIdxInfoByPage(@RequestParam(value = "equipmentNumber", required = false) String equipmentNumber, public ResponseModel<IPage<IndexDto>> getFanIdxInfoByPage(@RequestParam(value = "equipNum", required = false) String equipNum,
@RequestParam(value = "gateway", required = false) String gateway, @RequestParam(value = "stationId", required = false) String stationId,
@RequestParam(value = "frontModule", required = false) String frontModule, @RequestParam(value = "frontModule", required = false) String frontModule,
@RequestParam(value = "systemType", required = false) String systemType,
@RequestParam(value = "current", required = false) int current, @RequestParam(value = "current", required = false) int current,
@RequestParam(value = "size", required = false) int size) { @RequestParam(value = "size", required = false) int size) {
return ResponseHelper.buildResponse(monitorFanIndicator.getFanIdxInfoByPage(equipmentNumber, gateway, frontModule, current, size)); return ResponseHelper.buildResponse(monitorFanIndicator.getFanIdxInfoByPage(equipNum, stationId, frontModule, current, size, systemType));
} }
@TycloudOperation(needAuth = false, ApiLevel = UserType.AGENCY) @TycloudOperation(needAuth = false, ApiLevel = UserType.AGENCY)
...@@ -54,7 +57,27 @@ public class MonitorFanIdxController extends BaseController { ...@@ -54,7 +57,27 @@ public class MonitorFanIdxController extends BaseController {
@TycloudOperation(needAuth = false, ApiLevel = UserType.AGENCY)
@ApiOperation(value = "风机布置图 - 风机状态列表")
@GetMapping("/getFanStatusList")
public ResponseModel<List<IndexDto>> getFanStatusList(@RequestParam(value = "stationId", required = false) String stationId) {
return ResponseHelper.buildResponse(monitorFanIndicator.getFanStatusList(stationId));
}
@TycloudOperation(needAuth = false, ApiLevel = UserType.AGENCY)
@ApiOperation(value = "风机布置图 - 风机状态统计")
@GetMapping("/getFanStatusStatistics")
public ResponseModel<Map<String, Long>> getFanStatusStatistics(@RequestParam(value = "stationId", required = false) String stationId) {
return ResponseHelper.buildResponse(monitorFanIndicator.getFanStatusStatistics(stationId));
}
@TycloudOperation(needAuth = false, ApiLevel = UserType.AGENCY)
@ApiOperation(value = "风机布置图 - 风机基础信息")
@GetMapping("/getFanBasicInfoByEquipNum")
public ResponseModel<IndexDto> getFanBasicInfoByEquipNum(@RequestParam(value = "equipNum", required = false) String equipNum,
@RequestParam(value = "stationId", required = false) String stationId) {
return ResponseHelper.buildResponse(monitorFanIndicator.getFanBasicInfoByEquipNum(equipNum, stationId));
}
} }
...@@ -8,6 +8,7 @@ import com.yeejoin.amos.boot.module.jxiop.api.entity.StationBasic; ...@@ -8,6 +8,7 @@ import com.yeejoin.amos.boot.module.jxiop.api.entity.StationBasic;
import com.yeejoin.amos.boot.module.jxiop.api.mapper.StationBasicMapper; import com.yeejoin.amos.boot.module.jxiop.api.mapper.StationBasicMapper;
import com.yeejoin.amos.boot.module.jxiop.api.service.IMapRegionService; import com.yeejoin.amos.boot.module.jxiop.api.service.IMapRegionService;
import com.yeejoin.amos.boot.module.jxiop.biz.dto.RegionNationWideDto; import com.yeejoin.amos.boot.module.jxiop.biz.dto.RegionNationWideDto;
import com.yeejoin.amos.boot.module.jxiop.biz.dto.ResultsData;
import com.yeejoin.amos.boot.module.jxiop.biz.dto.SocialContributionDto; import com.yeejoin.amos.boot.module.jxiop.biz.dto.SocialContributionDto;
import com.yeejoin.amos.boot.module.jxiop.biz.entity.Test; import com.yeejoin.amos.boot.module.jxiop.biz.entity.Test;
import com.yeejoin.amos.boot.module.jxiop.biz.service.impl.MonitoringServiceImpl; import com.yeejoin.amos.boot.module.jxiop.biz.service.impl.MonitoringServiceImpl;
...@@ -48,9 +49,9 @@ public class MonitoringMapController extends BaseController { ...@@ -48,9 +49,9 @@ public class MonitoringMapController extends BaseController {
} }
@TycloudOperation(needAuth = false, ApiLevel = UserType.AGENCY) @TycloudOperation(needAuth = false, ApiLevel = UserType.AGENCY)
@ApiOperation(value = "获取社会贡献") @ApiOperation(value = "获取区域电量指标完成情况")
@GetMapping("/getTotalSocialContribution") @GetMapping("/getCompletionOfPowerIndicatorsByProvinceName")
public void getTotalSocialContribution() { public ResponseModel<ResultsData> getCompletionOfPowerIndicatorsByProvinceName(@RequestParam(required = true) int current, @RequestParam(required = true) int size, @RequestParam(required = true) String provinceName) {
// return ResponseHelper.buildResponse(monitoringServiceImpl.getTotalSocialContribution()); return ResponseHelper.buildResponse(monitoringServiceImpl.getCompletionOfPowerIndicatorsByProvinceName(current,size,provinceName));
} }
} }
package com.yeejoin.amos.boot.module.jxiop.biz.dto;
import lombok.Data;
/**
* @description:
* @author: tw
* @createDate: 2023/7/6
*/
@Data
public class ColModel {
private String fid;
private String dataIndex;
private String name;
private String title;
private String type;
private String key;
public ColModel(String fid, String dataIndex, String name, String title, String type, String key) {
this.fid = fid;
this.dataIndex = dataIndex;
this.name = name;
this.title = title;
this.type = type;
this.key = key;
}
}
package com.yeejoin.amos.boot.module.jxiop.biz.dto;
import lombok.Data;
@Data
public class CompletionOfPowerIndicatorsDto {
//场站名称
private String stationName;
//装机容量
private String installCapactity;
//风速或者辐照度
private String windSpeedOrIrradiance;
// 有功功率
private String activePower;
//日发电量
private String dailyPower;
//月发电量
private String monthlyPower;
//年发电量
private String annualPower;
}
package com.yeejoin.amos.boot.module.jxiop.biz.dto;
import lombok.Data;
import org.apache.poi.ss.formula.functions.T;
import java.util.List;
/**
* @description:
* @author: tw
* @createDate: 2023/7/6
*/
@Data
public class DataGridMock {
private int current;
private int total;
private boolean pagination;
private int totalPage;
private List dataList;
public DataGridMock(int current, int total, boolean pagination, int totalPage, List dataList) {
this.current = current;
this.total = total;
this.pagination = pagination;
this.totalPage = totalPage;
this.dataList = dataList;
}
}
...@@ -2,7 +2,25 @@ package com.yeejoin.amos.boot.module.jxiop.biz.dto; ...@@ -2,7 +2,25 @@ package com.yeejoin.amos.boot.module.jxiop.biz.dto;
import lombok.Data; import lombok.Data;
/**
* 指标dto-用于接收influxdb里边查询的到的数据
*/
@Data @Data
public class IndicatorsDto { public class IndicatorsDto {
private String address;
private String createdTime;
private String dataType;
private String equipmentIndex;
private String equipmentIndexName;
private String equipmentNumber;
private String equipmentSpecificName;
private String equipmentsIdx;
private String frontModule;
private String gatewayId;
private String isAlarm;
private String systemType;
private String traceId;
private String unit;
private String value;
private String valueLabel;
} }
package com.yeejoin.amos.boot.module.jxiop.biz.dto;
import lombok.Data;
import org.apache.poi.ss.formula.functions.T;
import java.util.List;
/**
* @description:
* @author: tw
* @createDate: 2023/7/6
*/
@Data
public class ResultsData {
private DataGridMock dataGridMock;
private List<ColModel> colModel;
public ResultsData(DataGridMock dataGridMock, List<ColModel> colModel) {
this.dataGridMock = dataGridMock;
this.colModel = colModel;
}
}
package com.yeejoin.amos.boot.module.jxiop.api.service; package com.yeejoin.amos.boot.module.jxiop.biz.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.mysql.cj.x.protobuf.MysqlxCrud;
import com.yeejoin.amos.boot.module.jxiop.api.dto.IndexDto; import com.yeejoin.amos.boot.module.jxiop.api.dto.IndexDto;
import com.yeejoin.amos.boot.module.jxiop.api.entity.MonitorFanIndicator; import com.yeejoin.amos.boot.module.jxiop.biz.dto.ResultsData;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List; import java.util.List;
...@@ -16,4 +15,6 @@ public interface IMonitorFanIndicator { ...@@ -16,4 +15,6 @@ public interface IMonitorFanIndicator {
//批量修改指标值 //批量修改指标值
void UpdateMonitorFanIndicator(List<IndexDto> list); void UpdateMonitorFanIndicator(List<IndexDto> list);
ResultsData getNationWideInfo( int current, int size, String stationBasicId, String equipmentNumber);
ResultsData getLsNationWideInfo( int current, int size, String stationBasicId, String equipmentNumber);
} }
package com.yeejoin.amos.boot.module.jxiop.biz.service.impl;
import com.yeejoin.amos.boot.module.jxiop.biz.dto.IndicatorsDto;
import com.yeejoin.amos.boot.module.jxiop.biz.utils.InfluxDButils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class CommonServiceImpl {
@Autowired
InfluxDButils influxDButils;
/**
* @deprecated 获取指标值总和
* @param gatewayId 网关id 用于拼接sql语句
* @param indicator 指标名称 查询条件-根据指标名称获取风速
* @return 指标值总和
*/
public Double getTotalByIndicatior(String gatewayId,String indicator){
String sql = "SELECT * FROM indicators_"+gatewayId+" where equipmentIndexName='"+indicator+"'";
Double totalvalue = 0.0;
List<IndicatorsDto> indicatorsDtoList = influxDButils.getListData(sql,IndicatorsDto.class);
List<Double> doubleList = indicatorsDtoList.stream().map(indicatorsDto -> Double.parseDouble(indicatorsDto.getValue())).collect(Collectors.toList());
totalvalue = doubleList.stream().mapToDouble(Double::doubleValue).sum();
return totalvalue;
}
/**
* @deprecated 获取指标值平均值
* @param gatewayId 网关id 用于拼接sql语句
* @param indicator 指标名称 查询条件-根据指标名称获取风速
* @return 指标值总和
*/
public Double getAvgvalueByIndicatior(String gatewayId,String indicator){
String sql = "SELECT * FROM indicators_"+gatewayId+" where equipmentIndexName='"+indicator+"'";
Double avageValue = 0.0;
List<IndicatorsDto> indicatorsDtoList = influxDButils.getListData(sql,IndicatorsDto.class);
List<Double> doubleList = indicatorsDtoList.stream().map(indicatorsDto -> Double.parseDouble(indicatorsDto.getValue())).collect(Collectors.toList());
avageValue = doubleList.stream().mapToDouble(Double::doubleValue).average().getAsDouble();
return avageValue;
}
}
...@@ -6,7 +6,6 @@ import com.baomidou.mybatisplus.core.metadata.IPage; ...@@ -6,7 +6,6 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.module.jxiop.api.dto.IndexDto; import com.yeejoin.amos.boot.module.jxiop.api.dto.IndexDto;
import com.yeejoin.amos.boot.module.jxiop.api.dto.RunRecord;
import com.yeejoin.amos.boot.module.jxiop.api.dto.TreeDto; import com.yeejoin.amos.boot.module.jxiop.api.dto.TreeDto;
import com.yeejoin.amos.boot.module.jxiop.api.entity.MonitorFanIndicator; import com.yeejoin.amos.boot.module.jxiop.api.entity.MonitorFanIndicator;
import com.yeejoin.amos.boot.module.jxiop.api.entity.Region; import com.yeejoin.amos.boot.module.jxiop.api.entity.Region;
...@@ -14,14 +13,18 @@ import com.yeejoin.amos.boot.module.jxiop.api.entity.StationBasic; ...@@ -14,14 +13,18 @@ import com.yeejoin.amos.boot.module.jxiop.api.entity.StationBasic;
import com.yeejoin.amos.boot.module.jxiop.api.mapper.MonitorFanIndicatorMapper; import com.yeejoin.amos.boot.module.jxiop.api.mapper.MonitorFanIndicatorMapper;
import com.yeejoin.amos.boot.module.jxiop.api.mapper.RegionMapper; import com.yeejoin.amos.boot.module.jxiop.api.mapper.RegionMapper;
import com.yeejoin.amos.boot.module.jxiop.api.mapper.StationBasicMapper; import com.yeejoin.amos.boot.module.jxiop.api.mapper.StationBasicMapper;
import com.yeejoin.amos.boot.module.jxiop.api.service.IMonitorFanIndicator; import com.yeejoin.amos.boot.module.jxiop.biz.dto.ColModel;
import com.yeejoin.amos.boot.module.jxiop.biz.dto.DataGridMock;
import com.yeejoin.amos.boot.module.jxiop.biz.dto.ResultsData;
import com.yeejoin.amos.boot.module.jxiop.biz.entity.SjglZsjZsbtz;
import com.yeejoin.amos.boot.module.jxiop.biz.entity.TpriDmpDatabook;
import com.yeejoin.amos.boot.module.jxiop.biz.utils.InfluxDButils;
import com.yeejoin.amos.boot.module.jxiop.biz.service.IMonitorFanIndicator;
import com.yeejoin.amos.component.robot.BadRequest; import com.yeejoin.amos.component.robot.BadRequest;
import org.apache.ibatis.annotations.Param; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.*;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
...@@ -41,6 +44,21 @@ public class MonitorFanIndicatorImpl implements IMonitorFanIndicator { ...@@ -41,6 +44,21 @@ public class MonitorFanIndicatorImpl implements IMonitorFanIndicator {
@Autowired @Autowired
private RegionMapper regionMapper; private RegionMapper regionMapper;
@Autowired
InfluxDButils influxDButils;
@Autowired
SjglZsjZsbtzServiceImpl sjglZsjZsbtzServiceImpl;
@Autowired
TpriDmpDatabookServiceImpl tpriDmpDatabookServiceImpl;
@Autowired
StationDataTaskImpl stationDataTask;
@Override @Override
public void UpdateMonitorFanIndicator(List<IndexDto> list) { public void UpdateMonitorFanIndicator(List<IndexDto> list) {
...@@ -51,12 +69,104 @@ public class MonitorFanIndicatorImpl implements IMonitorFanIndicator { ...@@ -51,12 +69,104 @@ public class MonitorFanIndicatorImpl implements IMonitorFanIndicator {
} }
public IPage<MonitorFanIndicator> getFanIdxInfoByPage(String equipmentNumber, String gateway, String frontModule, int current, int size) { @Override
Page<MonitorFanIndicator> page = new Page<>(current, size); public ResultsData getNationWideInfo(int current, int size, String stationBasicId, String equipmentNumber) {
Integer integer = monitorFanIndicatorregionMapper.queryByPageTotal(equipmentNumber, gateway, frontModule); StationBasic stationBasic =stationBasicMapper.selectById(stationBasicId);
List<MonitorFanIndicator> monitorFanIndicators = monitorFanIndicatorregionMapper.queryByPage(page.getSize(), equipmentNumber, gateway, frontModule, (current - 1) * size); String gateway=stationBasic.getFanGatewayId();
page.setTotal(integer); Page<IndexDto> page = new Page<IndexDto>();
page.setRecords(monitorFanIndicators); page.setCurrent(current);
page.setSize(size);
String table=gateway;
StringBuffer querysql = new StringBuffer("SELECT createdTime ,equipmentNumber,gatewayId,address,valueLabel,equipmentSpecificName,value FROM indicators_%s WHERE isAlarm='1' and value!='0.0' and gatewayId= %s ORDER BY time desc LIMIT %d OFFSET %d ");
StringBuffer querysqlcount = new StringBuffer("SELECT count(value) FROM indicators_%s WHERE isAlarm='1' and value!='0.0' and gatewayId= %s ");
if(StringUtils.isNotEmpty(equipmentNumber)){
String date ="'%s' and equipmentNumber = '%s' ";
gateway= String.format(date,gateway,equipmentNumber);
}else{
gateway=String.format("'%s'",gateway);
}
String querysqln= String.format(querysql.toString(),table,gateway, (int)page.getSize(),(int)(page.getCurrent() - 1)*page.getSize());
String querysqlcountn= String.format(querysqlcount.toString(),table,gateway);
//每个分机的指标数据
List<IndexDto> list = influxDButils.getListData(querysqln,IndexDto.class);
List<IndexDto> list1 = influxDButils.getListData(querysqlcountn,IndexDto.class);
page.setRecords(list);
//构建平台数据
DataGridMock DataGridMock=new DataGridMock(current, list1!=null?list1.get(0).getCount():0, false, current, list);
ColModel colModelequipmentNumber=new ColModel("equipmentNumber", "equipmentNumber", "风机号", "风机号", "dataGrid", "equipmentNumber");
ColModel colModelvalueLabel=new ColModel("valueLabel", "valueLabel", "事件描述", "事件描述", "dataGrid", "valueLabel");
ColModel colModelcreatedTime=new ColModel("createdTime", "createdTime", "发生时间", "发生时间", "dataGrid", "createdTime");
ColModel colModelvalue=new ColModel("value", "value", "告警值", "告警值", "dataGrid", "value");
List<ColModel> listColModel=new ArrayList<>();
listColModel.add(colModelequipmentNumber);
listColModel.add(colModelvalueLabel);
listColModel.add(colModelcreatedTime);
listColModel.add(colModelvalue);
ResultsData resultsData=new ResultsData(DataGridMock,listColModel);
return resultsData;
}
@Override
public ResultsData getLsNationWideInfo(int current, int size, String stationBasicId, String equipmentNumber) {
StationBasic stationBasic =stationBasicMapper.selectById(stationBasicId);
String gateway=stationBasic.getFanGatewayId();
Page<IndexDto> page = new Page<IndexDto>();
page.setCurrent(current);
page.setSize(size);
String table=gateway;
StringBuffer querysql = new StringBuffer("SELECT createdTime ,gatewayId,address,valueLabel,equipmentSpecificName,value FROM iot_data_%s WHERE isAlarm='1' and value!='0.0' and gatewayId= %s ORDER BY time desc LIMIT %d OFFSET %d ");
StringBuffer querysqlcount = new StringBuffer("SELECT count(value) FROM iot_data_%s WHERE isAlarm='1' and value!='0.0' and gatewayId= %s ");
if(StringUtils.isNotEmpty(equipmentNumber)){
String date = " '%s' and equipmentSpecificName=~/.*%s风机.*/ ";
gateway= String.format(date,gateway,equipmentNumber);
}else{
gateway=String.format("'%s'",gateway);
}
String querysqln= String.format(querysql.toString(),table,gateway, (int)page.getSize(),(int)(page.getCurrent() - 1)*page.getSize());
String querysqlcountn= String.format(querysqlcount.toString(),table,gateway);
//每个分机的指标数据
List<IndexDto> list = influxDButils.getListData(querysqln,IndexDto.class);
List<IndexDto> list1 = influxDButils.getListData(querysqlcountn,IndexDto.class);
page.setRecords(list);
//构建平台数据
DataGridMock DataGridMock=new DataGridMock(current, list1!=null?list1.get(0).getCount():0, false, current, list);
ColModel colModelequipmentNumber=new ColModel("equipmentNumber", "equipmentSpecificName", "风机号", "风机号", "dataGrid", "equipmentNumber");
ColModel colModelvalueLabel=new ColModel("valueLabel", "valueLabel", "事件描述", "事件描述", "dataGrid", "valueLabel");
ColModel colModelcreatedTime=new ColModel("createdTime", "createdTime", "发生时间", "发生时间", "dataGrid", "createdTime");
ColModel colModelvalue=new ColModel("value", "value", "告警值", "告警值", "dataGrid", "value");
List<ColModel> listColModel=new ArrayList<>();
listColModel.add(colModelequipmentNumber);
listColModel.add(colModelvalueLabel);
listColModel.add(colModelcreatedTime);
listColModel.add(colModelvalue);
ResultsData resultsData=new ResultsData(DataGridMock,listColModel);
return resultsData;
}
public IPage<IndexDto> getFanIdxInfoByPage(String equipNum, String stationId, String frontModule, int current, int size, String systemType) {
StationBasic stationBasic = getOneByStationNumber(stationId);
Page<IndexDto> page = new Page<>(current, size);
String sql = "";
if (StringUtils.isNotEmpty(systemType)) {
sql = String.format("SELECT equipmentIndexName, value, frontModule FROM \"indicators_%s\" WHERE equipmentNumber = '%s' and frontModule =~/%s/ and systemType =~/%s/ ", stationBasic.getFanGatewayId(), equipNum, frontModule, systemType);
} else {
sql = String.format("SELECT equipmentIndexName, value, frontModule FROM \"indicators_%s\" WHERE equipmentNumber = '%s' and frontModule =~/%s/", stationBasic.getFanGatewayId(), equipNum, frontModule);
}
List<IndexDto> influxDBList = influxDButils.getListData(sql, IndexDto.class);
List<IndexDto> collect = influxDBList.stream()
.skip((long) (current - 1) * size)
.limit(size)
.collect(Collectors.toList());
page.setTotal(influxDBList.size());
page.setRecords(collect);
return page; return page;
} }
...@@ -119,7 +229,40 @@ public class MonitorFanIndicatorImpl implements IMonitorFanIndicator { ...@@ -119,7 +229,40 @@ public class MonitorFanIndicatorImpl implements IMonitorFanIndicator {
* @param indicator * @param indicator
* @return * @return
*/ */
public Object getIndicatoralueTotal(String gateway,String indicator){ public Object getIndicatoralueTotal(String gateway,String indicator) {
return monitorFanIndicatorregionMapper.getIndicatoralueTotal(gateway,indicator); return monitorFanIndicatorregionMapper.getIndicatoralueTotal(gateway,indicator);
} }
private StationBasic getOneByStationNumber(String stationId) {
return stationBasicMapper.selectById(stationId);
}
public List<IndexDto> getFanStatusList(String stationId) {
StationBasic stationBasic = getOneByStationNumber(stationId);
String sql = String.format("SELECT equipmentNumber, equipmentIndexName FROM \"indicators_%s\" WHERE equipmentIndexName =~/^正常运行|告警运行|正常停机|故障停机|限功率|待机状态|维护状态|通讯中断$/ and value = 'true'", stationBasic.getFanGatewayId());
List<IndexDto> influxDBList = influxDButils.getListData(sql, IndexDto.class);
return influxDBList;
}
public Map<String, Long> getFanStatusStatistics(String stationId) {
StationBasic stationBasic = getOneByStationNumber(stationId);
String sql = String.format("SELECT equipmentNumber, equipmentIndexName FROM \"indicators_%s\" WHERE equipmentIndexName =~/^正常运行|告警运行|正常停机|故障停机|限功率|待机状态|维护状态|通讯中断$/ and value = 'true'", stationBasic.getFanGatewayId());
List<IndexDto> influxDBList = influxDButils.getListData(sql, IndexDto.class);
// key:状态 value:数量
Map<String, Long> collect = influxDBList.stream().collect(Collectors.groupingBy(IndexDto::getEquipmentIndexName, Collectors.counting()));
return collect;
}
public IndexDto getFanBasicInfoByEquipNum(String equipNum, String stationId) {
StationBasic stationBasic = getOneByStationNumber(stationId);
String sql = String.format("SELECT equipmentNumber, equipmentSpecificName, equipmentIndexName FROM \"indicators_%s\" WHERE equipmentNumber = '%s' and value = 'true' order by time desc limit 1", stationBasic.getFanGatewayId(), equipNum);
List<IndexDto> influxDBList = influxDButils.getListData(sql, IndexDto.class);
if (CollectionUtils.isNotEmpty(influxDBList)) {
String equipmentSpecificName = influxDBList.get(0).getEquipmentSpecificName();
influxDBList.get(0).setEquipmentSpecificName(equipmentSpecificName.substring(0, equipmentSpecificName.indexOf("#")));
return influxDBList.get(0);
}
return new IndexDto();
}
} }
\ No newline at end of file
package com.yeejoin.amos.boot.module.jxiop.biz.service.impl;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.module.jxiop.api.entity.Region;
import com.yeejoin.amos.boot.module.jxiop.api.entity.StationBasic;
import com.yeejoin.amos.boot.module.jxiop.api.mapper.RegionMapper;
import com.yeejoin.amos.boot.module.jxiop.api.mapper.StationBasicMapper;
import com.yeejoin.amos.boot.module.jxiop.biz.dto.SocialContributionDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.typroject.tyboot.component.emq.EmqKeeper;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
@Async
@Service
public class MonitoringServiceIMQTTmpl {
Logger logger = LoggerFactory.getLogger(MonitoringServiceIMQTTmpl.class);
/**
* 场站mapper
*/
@Autowired
StationBasicMapper stationBasicMapper;
@Autowired
CommonServiceImpl commonServiceImpl;
@Autowired
RegionMapper regionMapper;
@Autowired
EmqKeeper emqKeeper;
@Scheduled(cron = "0 0/1 * * * *")
public void getTotalSocialContribution() {
Page<SocialContributionDto> socialContributionDtoPage = new Page<SocialContributionDto>();
logger.error("--------------------------社会贡献定时执行----------------------------------------------");
List<SocialContributionDto> socialContributionDtoList = new ArrayList<>();
//定义社会贡献列表
AtomicReference<Double> totalSocialContribution = new AtomicReference<>(0.0);
//获取所有网关id不为空的数据
List<StationBasic> stationBasicList = stationBasicMapper.selectList(new QueryWrapper<StationBasic>().isNotNull("fan_gateway_id"));
stationBasicList.forEach(stationBasic -> {
totalSocialContribution.updateAndGet(v -> v + commonServiceImpl.getTotalByIndicatior(stationBasic.getFanGatewayId(), "年发电量"));
});
//二氧化碳贡献数
SocialContributionDto co2 = new SocialContributionDto();
//标准煤贡献度
SocialContributionDto coal = new SocialContributionDto();
//碳粉尘计算公式
SocialContributionDto toner = new SocialContributionDto();
//二氧化硫贡献度
SocialContributionDto so2 = new SocialContributionDto();
/** 社会贡献原始计算公式,后边的数据已经经过处理
//二氧化碳计算公式 *10000*832/10000/1000/1000
//标准煤计算公式 *10000*304.9/10000/1000/1000
//碳粉尘计算公式 *10000*0.032/1000/1000
//二氧化硫计算公式 =A2*10000*0.16/1000/1000
*/
co2.setUnit("二氧化碳减排量(万t)");
co2.setTitle(totalSocialContribution.get() * 0.000832);
socialContributionDtoList.add(co2);
coal.setUnit("节约标准煤(万t)");
coal.setTitle(totalSocialContribution.get() * 0.0003049);
socialContributionDtoList.add(coal);
toner.setUnit("碳粉尘减排量(万t)");
toner.setTitle(totalSocialContribution.get() * 0.00032);
socialContributionDtoList.add(toner);
so2.setUnit("二氧化硫减排量(万t)");
so2.setTitle(totalSocialContribution.get() * 0.0016);
socialContributionDtoList.add(so2);
socialContributionDtoPage.setRecords(socialContributionDtoList);
socialContributionDtoPage.setTotal(100);
socialContributionDtoPage.setCurrent(1);
try {
emqKeeper.getMqttClient().publish("socialcontribution_topic", JSON.toJSON(socialContributionDtoPage).toString().getBytes("UTF-8"), 1, true);
logger.info("-----------------发送社会贡献消息=================== 成功!" + JSON.toJSONString(socialContributionDtoPage));
} catch (Exception exception) {
logger.error("-----------------发送社会贡献消息=================== 失败!");
}
}
@Scheduled(cron = "0/30 * * * * *")
public void getCompletionOfPowerIndicatorsByProvinceName() {
Page<SocialContributionDto> socialContributionDtoPage = new Page<SocialContributionDto>();
logger.error("--------------------------区域实时数据消息开始发送----------------------------------------------");
List<SocialContributionDto> socialContributionDtoList = new ArrayList<>();
Region region = this.regionMapper.selectOne(new QueryWrapper<Region>().eq("level", 1).eq("region_name", "江苏省"));
List<StationBasic> stationBasicList = stationBasicMapper.selectList(new QueryWrapper<StationBasic>().like("belong_area", region.getRegionCode()));
//日发电量
AtomicReference<Double> dailyPower = new AtomicReference<>(0.0);
//月发电量
AtomicReference<Double> monthlyPower = new AtomicReference<>(0.0);
//年发电量
AtomicReference<Double> annualPower = new AtomicReference<>(0.0);
//年发电量完成比例
Double completionRatio = 23.11;
//年利用小时数
AtomicReference<Double> useHours = new AtomicReference<>(0.01);
stationBasicList.forEach(stationBasic -> {
dailyPower.updateAndGet(v -> v + commonServiceImpl.getTotalByIndicatior(stationBasic.getFanGatewayId(), "日发电量"));
monthlyPower.updateAndGet(v -> v + commonServiceImpl.getTotalByIndicatior(stationBasic.getFanGatewayId(), "月发电量"));
annualPower.updateAndGet(v -> v + commonServiceImpl.getTotalByIndicatior(stationBasic.getFanGatewayId(), "年发电量"));
useHours.updateAndGet(v -> v + commonServiceImpl.getTotalByIndicatior(stationBasic.getFanGatewayId(), "日工作时间"));
});
SocialContributionDto dailyPowerdto = new SocialContributionDto();
dailyPowerdto.setTitle(dailyPower.get());
dailyPowerdto.setUnit("万kWh");
SocialContributionDto monthlyPowerdto = new SocialContributionDto();
monthlyPowerdto.setTitle(monthlyPower.get());
monthlyPowerdto.setUnit("万kWh");
SocialContributionDto annualPowerdto = new SocialContributionDto();
annualPowerdto.setTitle(annualPower.get());
annualPowerdto.setUnit("万kWh");
SocialContributionDto completionRatioDto = new SocialContributionDto();
completionRatioDto.setTitle(completionRatio);
completionRatioDto.setUnit("%");
SocialContributionDto useHoursDto = new SocialContributionDto();
useHoursDto.setTitle(useHours.get());
useHoursDto.setUnit("h");
socialContributionDtoList.add(dailyPowerdto);
socialContributionDtoList.add(monthlyPowerdto);
socialContributionDtoList.add(annualPowerdto);
socialContributionDtoList.add(completionRatioDto);
socialContributionDtoList.add(useHoursDto);
socialContributionDtoPage.setRecords(socialContributionDtoList);
socialContributionDtoPage.setTotal(100);
socialContributionDtoPage.setCurrent(1);
try {
emqKeeper.getMqttClient().publish("completionofpowerindicator_topic", JSON.toJSON(socialContributionDtoPage).toString().getBytes("UTF-8"), 1, true);
logger.info("-----------------发送区域实时生产数据消息=================== 成功!" + JSON.toJSONString(socialContributionDtoPage));
} catch (Exception exception) {
logger.error("-----------------发送区域实时生产数据消息=================== 失败!");
}
}
}
...@@ -10,8 +10,7 @@ import com.yeejoin.amos.boot.module.jxiop.api.entity.StationCoordinate; ...@@ -10,8 +10,7 @@ import com.yeejoin.amos.boot.module.jxiop.api.entity.StationCoordinate;
import com.yeejoin.amos.boot.module.jxiop.api.mapper.RegionMapper; import com.yeejoin.amos.boot.module.jxiop.api.mapper.RegionMapper;
import com.yeejoin.amos.boot.module.jxiop.api.mapper.StationBasicMapper; import com.yeejoin.amos.boot.module.jxiop.api.mapper.StationBasicMapper;
import com.yeejoin.amos.boot.module.jxiop.api.mapper.StationCoordinateMapper; import com.yeejoin.amos.boot.module.jxiop.api.mapper.StationCoordinateMapper;
import com.yeejoin.amos.boot.module.jxiop.biz.dto.RegionNationWideDto; import com.yeejoin.amos.boot.module.jxiop.biz.dto.*;
import com.yeejoin.amos.boot.module.jxiop.biz.dto.SocialContributionDto;
import com.yeejoin.amos.boot.module.jxiop.biz.utils.InfluxDButils; import com.yeejoin.amos.boot.module.jxiop.biz.utils.InfluxDButils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -26,8 +25,9 @@ import java.util.ArrayList; ...@@ -26,8 +25,9 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
@Async
@Service @Service
public class MonitoringServiceImpl { public class MonitoringServiceImpl {
Logger logger = LoggerFactory.getLogger(MonitoringServiceImpl.class); Logger logger = LoggerFactory.getLogger(MonitoringServiceImpl.class);
...@@ -52,18 +52,20 @@ public class MonitoringServiceImpl { ...@@ -52,18 +52,20 @@ public class MonitoringServiceImpl {
@Autowired @Autowired
SjglZsjZsbtzServiceImpl SjglZsjZsbtzServiceImpl; SjglZsjZsbtzServiceImpl SjglZsjZsbtzServiceImpl;
/**
* 热工院-数据字典表
*/
@Autowired
TpriDmpDatabookServiceImpl TpriDmpDatabookServiceImpl;
@Autowired @Autowired
MonitorFanIndicatorImpl monitorFanIndicatorImpl; CommonServiceImpl commonServiceImpl;
@Autowired
EmqKeeper emqKeeper;
@Autowired /**
InfluxDButils influxDButils; * 根据场站编号获取该场站的装机容量
*
* @param werks
* @return
*/
public Double getStationCaPACITYL(String werks) {
return this.SjglZsjZsbtzServiceImpl.getStationCapactityByStationWerks(werks);
}
/** /**
* 根据省份名称查询电站详情 * 根据省份名称查询电站详情
...@@ -71,11 +73,11 @@ public class MonitoringServiceImpl { ...@@ -71,11 +73,11 @@ public class MonitoringServiceImpl {
* @param provinceName * @param provinceName
* @return * @return
*/ */
public List<RegionNationWideDto> getNationWideInfo(String provinceName){ public List<RegionNationWideDto> getNationWideInfo(String provinceName) {
List<RegionNationWideDto> regionNationWideDtoList= new ArrayList<>(); List<RegionNationWideDto> regionNationWideDtoList = new ArrayList<>();
//如果 provinceName 为空则表示当前为全国地图 否则则为省份地图 //如果 provinceName 为空则表示当前为全国地图 否则则为省份地图
if(ObjectUtils.isEmpty(provinceName)||provinceName.equals("")){ if (ObjectUtils.isEmpty(provinceName) || provinceName.equals("")) {
List<Region> regionList = this.regionMapper.selectList(new QueryWrapper<Region>().eq("level",1)); List<Region> regionList = this.regionMapper.selectList(new QueryWrapper<Region>().eq("level", 1));
for (int i = 0; i < regionList.size(); i++) { for (int i = 0; i < regionList.size(); i++) {
RegionNationWideDto regionNationWideDto = new RegionNationWideDto(); RegionNationWideDto regionNationWideDto = new RegionNationWideDto();
AtomicReference<Double> guangfuMW = new AtomicReference<>(0.0); AtomicReference<Double> guangfuMW = new AtomicReference<>(0.0);
...@@ -83,15 +85,15 @@ public class MonitoringServiceImpl { ...@@ -83,15 +85,15 @@ public class MonitoringServiceImpl {
AtomicReference<Integer> guangfu = new AtomicReference<>(0); AtomicReference<Integer> guangfu = new AtomicReference<>(0);
AtomicReference<Integer> fengdian = new AtomicReference<>(0); AtomicReference<Integer> fengdian = new AtomicReference<>(0);
Region region = regionList.get(i); Region region = regionList.get(i);
List<StationBasic> list = stationBasicMapper.selectList(new QueryWrapper<StationBasic>().like("belong_area",region.getRegionCode())); List<StationBasic> list = stationBasicMapper.selectList(new QueryWrapper<StationBasic>().like("belong_area", region.getRegionCode()));
list.forEach(stationBasic -> { list.forEach(stationBasic -> {
if (!ObjectUtils.isEmpty(stationBasic.getFanGatewayId()) && !ObjectUtils.isEmpty(stationBasic.getStationNumber())) { if (!ObjectUtils.isEmpty(stationBasic.getFanGatewayId()) && !ObjectUtils.isEmpty(stationBasic.getStationNumber())) {
regionNationWideDto.setJsJoin(true); regionNationWideDto.setJsJoin(true);
} }
if(stationBasic.getStationType().equals("FDZ")){ if (stationBasic.getStationType().equals("FDZ")) {
fengdianMW.set(getStationCaPACITYL(stationBasic.getStationNumber())); fengdianMW.set(getStationCaPACITYL(stationBasic.getStationNumber()));
fengdian.getAndSet(fengdian.get() + 1); fengdian.getAndSet(fengdian.get() + 1);
}else { } else {
guangfuMW.set(getStationCaPACITYL(stationBasic.getStationNumber())); guangfuMW.set(getStationCaPACITYL(stationBasic.getStationNumber()));
guangfu.getAndSet(guangfu.get() + 1); guangfu.getAndSet(guangfu.get() + 1);
} }
...@@ -103,23 +105,23 @@ public class MonitoringServiceImpl { ...@@ -103,23 +105,23 @@ public class MonitoringServiceImpl {
regionNationWideDto.setName(region.getRegionName()); regionNationWideDto.setName(region.getRegionName());
regionNationWideDtoList.add(regionNationWideDto); regionNationWideDtoList.add(regionNationWideDto);
} }
}else { } else {
Region region = this.regionMapper.selectOne(new QueryWrapper<Region>().eq("level",1).eq("region_name",provinceName)); Region region = this.regionMapper.selectOne(new QueryWrapper<Region>().eq("level", 1).eq("region_name", provinceName));
List<StationBasic> list = stationBasicMapper.selectList(new QueryWrapper<StationBasic>().like("belong_area",region.getRegionCode())); List<StationBasic> list = stationBasicMapper.selectList(new QueryWrapper<StationBasic>().like("belong_area", region.getRegionCode()));
HashMap<String,Double> hashMap = new HashMap<>(); HashMap<String, Double> hashMap = new HashMap<>();
for (int i = 0; i <list.size() ; i++) { for (int i = 0; i < list.size(); i++) {
StationBasic stationBasic = list.get(i); StationBasic stationBasic = list.get(i);
RegionNationWideDto regionNationWideDto =new RegionNationWideDto(); RegionNationWideDto regionNationWideDto = new RegionNationWideDto();
regionNationWideDto.setStaitionName(stationBasic.getStationName()); regionNationWideDto.setStaitionName(stationBasic.getStationName());
regionNationWideDto.setStaitionType(stationBasic.getStationType()); regionNationWideDto.setStaitionType(stationBasic.getStationType());
String speendOrirradiate = ""; String speendOrirradiate = "";
if (stationBasic.getStationType().equals("FDZ")) { if (stationBasic.getStationType().equals("FDZ")) {
speendOrirradiate = String.valueOf(getIndicatoralueAvage(stationBasic.getFanGatewayId(), "30秒平均风速")); speendOrirradiate = String.valueOf(commonServiceImpl.getAvgvalueByIndicatior(stationBasic.getFanGatewayId(), "30秒平均风速"));
regionNationWideDto.setSpeendOrirradiate(speendOrirradiate); regionNationWideDto.setSpeendOrirradiate(speendOrirradiate);
}else{ } else {
regionNationWideDto.setSpeendOrirradiate(String.valueOf(Math.random()*1000)); regionNationWideDto.setSpeendOrirradiate(String.valueOf(Math.random() * 1000));
} }
StationCoordinate stationCoordinate = stationCoordinateMapper.selectOne(new QueryWrapper<StationCoordinate>().eq("station_id",stationBasic.getSequenceNbr()).eq("is_main_coordinate",0)); StationCoordinate stationCoordinate = stationCoordinateMapper.selectOne(new QueryWrapper<StationCoordinate>().eq("station_id", stationBasic.getSequenceNbr()).eq("is_main_coordinate", 0));
hashMap.put("lng", Double.valueOf(stationCoordinate.getLongitude())); hashMap.put("lng", Double.valueOf(stationCoordinate.getLongitude()));
hashMap.put("lat", Double.valueOf(stationCoordinate.getLaitude())); hashMap.put("lat", Double.valueOf(stationCoordinate.getLaitude()));
regionNationWideDto.setPosition(hashMap); regionNationWideDto.setPosition(hashMap);
...@@ -130,82 +132,41 @@ public class MonitoringServiceImpl { ...@@ -130,82 +132,41 @@ public class MonitoringServiceImpl {
return regionNationWideDtoList; return regionNationWideDtoList;
} }
/**
* 根据场站编号获取该场站的装机容量
*
* @param werks
* @return
*/
public Double getStationCaPACITYL(String werks) {
return this.SjglZsjZsbtzServiceImpl.getStationCapactityByStationWerks(werks);
}
/**
* 根据网关id以及指标值 获取同一网关下指标的平均值
*
* @param gateway 网关id
* @param indicatorcName 指标名称
* @return 同一网关下指标的平均值
*/
public Object getIndicatoralueAvage(String gateway, String indicatorcName) {
return this.monitorFanIndicatorImpl.getIndicatoralueAvage(gateway, indicatorcName);
}
/**
* 根据网关id以及指标值 同一网关下指标的值总和
*
* @param gateway 网关id
* @param indicatorcName 指标名称
* @return 同一网关下指标的值总和
*/
public Object getIndicatoralueTotal(String gateway, String indicatorcName) {
return this.monitorFanIndicatorImpl.getIndicatoralueTotal(gateway, indicatorcName);
}
@Scheduled(cron = "*/10 * * * * *") public ResultsData getCompletionOfPowerIndicatorsByProvinceName(int current, int size, String provinceName) {
public void getTotalSocialContribution() { Region region = this.regionMapper.selectOne(new QueryWrapper<Region>().eq("level", 1).eq("region_name", provinceName));
Page<SocialContributionDto> socialContributionDtoPage = new Page<SocialContributionDto>(); List<StationBasic> stationBasicList = stationBasicMapper.selectList(new QueryWrapper<StationBasic>().like("belong_area", region.getRegionCode()));
logger.error("--------------------------社会贡献定时执行----------------------------------------------"); List<ColModel> colModels = new ArrayList<>();
List<SocialContributionDto> socialContributionDtoList = new ArrayList<>(); List<CompletionOfPowerIndicatorsDto> completionOfPowerIndicatorsDtoList = new ArrayList<>();
//定义社会贡献列表 ColModel colModelStatitonName = new ColModel("stationName", "stationName", "场站", "场站", "dataGrid", "stationName");
AtomicReference<Double> totalSocialContribution = new AtomicReference<>(0.0); ColModel colModelInstallCapactity = new ColModel("installCapactity", "installCapactity", "装机容量", "装机容量", "dataGrid", "installCapactity");
//获取所有网关id不为空的数据 ColModel colModelWindSpeedOrIrradiance = new ColModel("windSpeedOrIrradiance", "windSpeedOrIrradiance", "风度/辐照度", "风度/辐照度", "dataGrid", "windSpeedOrIrradiance");
List<StationBasic> stationBasicList = stationBasicMapper.selectList(new QueryWrapper<StationBasic>().isNotNull("gateway_id")); ColModel colModelActivePower = new ColModel("activePower", "activePower", "有功", "有功", "dataGrid", "activePower");
ColModel colModelDailyPower = new ColModel("dailyPower", "dailyPower", "日发电量", "日发电量", "dataGrid", "dailyPower");
ColModel colModelMonthlyPower = new ColModel("monthlyPower", "monthlyPower", "月发电量", "月发电量", "dataGrid", "monthlyPower");
ColModel colModelAnnualPower = new ColModel("annualPower", "annualPower", "年发电量", "年发电量", "dataGrid", "annualPower");
colModels.add(colModelStatitonName);
colModels.add(colModelInstallCapactity);
colModels.add(colModelWindSpeedOrIrradiance);
colModels.add(colModelActivePower);
colModels.add(colModelDailyPower);
colModels.add(colModelMonthlyPower);
colModels.add(colModelAnnualPower);
//遍历列表
stationBasicList.forEach(stationBasic -> { stationBasicList.forEach(stationBasic -> {
totalSocialContribution.updateAndGet(v -> v + (Double) monitorFanIndicatorImpl.getIndicatoralueTotal(stationBasic.getFanGatewayId(), "年发电量")); CompletionOfPowerIndicatorsDto completionOfPowerIndicatorsDto = new CompletionOfPowerIndicatorsDto();
completionOfPowerIndicatorsDto.setStationName(stationBasic.getStationName());
completionOfPowerIndicatorsDto.setInstallCapactity(String.valueOf(getStationCaPACITYL(stationBasic.getStationNumber())));
completionOfPowerIndicatorsDto.setWindSpeedOrIrradiance(String.valueOf(commonServiceImpl.getAvgvalueByIndicatior(stationBasic.getFanGatewayId(),"30秒平均风速")));
completionOfPowerIndicatorsDto.setActivePower(String.valueOf(commonServiceImpl.getTotalByIndicatior(stationBasic.getFanGatewayId(),"有功功率")));
completionOfPowerIndicatorsDto.setDailyPower(String.valueOf(commonServiceImpl.getTotalByIndicatior(stationBasic.getFanGatewayId(),"日发电量")));
completionOfPowerIndicatorsDto.setMonthlyPower(String.valueOf(commonServiceImpl.getTotalByIndicatior(stationBasic.getFanGatewayId(),"月发电量")));
completionOfPowerIndicatorsDto.setAnnualPower(String.valueOf(commonServiceImpl.getTotalByIndicatior(stationBasic.getFanGatewayId(),"年发电量")));
completionOfPowerIndicatorsDtoList.add(completionOfPowerIndicatorsDto);
}); });
SocialContributionDto co2 = new SocialContributionDto(); Integer allsize = completionOfPowerIndicatorsDtoList.size();
SocialContributionDto coal = new SocialContributionDto(); DataGridMock dataGridMock = new DataGridMock(current, allsize, false, allsize/size+1,completionOfPowerIndicatorsDtoList);
SocialContributionDto toner = new SocialContributionDto(); ResultsData resultsData = new ResultsData(dataGridMock, colModels);
SocialContributionDto so2 = new SocialContributionDto(); return resultsData;
/** 社会贡献原始计算公式,后边的数据已经经过处理
//二氧化碳计算公式 *10000*832/10000/1000/1000
//标准煤计算公式 *10000*304.9/10000/1000/1000
//碳粉尘计算公式 *10000*0.032/1000/1000
//二氧化硫计算公式 =A2*10000*0.16/1000/1000
*/
co2.setUnit("二氧化碳减排量(万t)");
co2.setTitle(totalSocialContribution.get() * 0.000832);
socialContributionDtoList.add(co2);
coal.setUnit("节约标准煤(万t)");
coal.setTitle(totalSocialContribution.get() * 0.0003049);
socialContributionDtoList.add(coal);
toner.setUnit("碳粉尘减排量(万t)");
toner.setTitle(totalSocialContribution.get() * 0.00032);
socialContributionDtoList.add(toner);
so2.setUnit("二氧化硫减排量(万t)");
so2.setTitle(totalSocialContribution.get() * 0.0016);
socialContributionDtoList.add(so2);
socialContributionDtoPage.setRecords(socialContributionDtoList);
socialContributionDtoPage.setTotal(100);
socialContributionDtoPage.setCurrent(1);
try {
emqKeeper.getMqttClient().publish("SocialContribution", JSON.toJSON(socialContributionDtoPage).toString().getBytes("UTF-8"), 1, true);
logger.info("-----------------发送社会贡献消息=================== 失败!"+JSON.toJSONString(socialContributionDtoPage));
} catch (Exception exception) {
logger.error("-----------------发送社会贡献消息=================== 失败!");
}
} }
} }
...@@ -66,8 +66,8 @@ privilege.fegin.name=AMOS-API-PRIVILEGE ...@@ -66,8 +66,8 @@ privilege.fegin.name=AMOS-API-PRIVILEGE
feign.client.config.default.connect-timeout=20000 feign.client.config.default.connect-timeout=20000
feign.client.config.default.read-timeout=20000 feign.client.config.default.read-timeout=20000
#场站实时数据 #场站实时数据
station.task.cron=0/10 * * * * ? station.task.cron=* * */10 * * ?
#是否切片 #是否切片
station.isok=true station.isok=false
#风机更新数据切片量 #风机更新数据切片量
station.section=10 station.section=1000
\ No newline at end of file \ No newline at end of file
package com.yeejoin.amos.boot.module.tzs.api.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
@AllArgsConstructor
@Getter
public enum ImageSizeEnums {
/**
* 导出监管码、96333码尺寸
*/
// 监管码-大
JG_BIG("JG_BIG", "bigBg.png", 350, 350, 60, 720, 190, 0, 0, 780, 680),
// 监管码-中
JG_MID("JG_MID", "centreBg.png", 230, 230, 40, 480, 170, 0, 0, 520, 525),
// 监管码-小
JG_MIN("JG_MIN", "smallBg.png", 170, 170, 30, 360, 110, 0, 0, 380, 355),
// 96333电梯码
DT("DT", "dt.png", 170, 170, 30, 30, 110, 0, 0, 330, 355);
String code;
String bgPath;
Integer with;
Integer height;
Integer size;
Integer imagesX;
Integer imagesY;
Integer text1X;
Integer text1Y;
Integer text2X;
Integer text2Y;
public static ImageSizeEnums getEnumByCode(String code) {
for (ImageSizeEnums value : ImageSizeEnums.values()) {
if (value.getCode().equals(code)) {
return value;
}
}
return null;
}
}
...@@ -84,6 +84,7 @@ public interface IdxFeignService { ...@@ -84,6 +84,7 @@ public interface IdxFeignService {
FeignClientResult<String> submit(@RequestParam(value = "pageId") long pageId, FeignClientResult<String> submit(@RequestParam(value = "pageId") long pageId,
@RequestParam(value = "taskId",required = false) String taskId, @RequestParam(value = "taskId",required = false) String taskId,
@RequestParam(value = "planInstanceId", required = false) String planInstanceId, @RequestParam(value = "planInstanceId", required = false) String planInstanceId,
@RequestParam(value = "bizField", required = false) String bizField,
@RequestParam(value = "topic", required = false) String topic, @RequestParam(value = "topic", required = false) String topic,
@RequestParam(value = "tableName", required = false) String tableName, @RequestParam(value = "tableName", required = false) String tableName,
@RequestBody Map<String, Object> kv) throws Exception; @RequestBody Map<String, Object> kv) throws Exception;
......
...@@ -351,6 +351,7 @@ ...@@ -351,6 +351,7 @@
<if test="dto.ORG_BRANCH_NAME != '' and dto.ORG_BRANCH_NAME != null">and ORG_BRANCH_NAME = #{dto.ORG_BRANCH_NAME}</if> <if test="dto.ORG_BRANCH_NAME != '' and dto.ORG_BRANCH_NAME != null">and ORG_BRANCH_NAME = #{dto.ORG_BRANCH_NAME}</if>
<if test="dto.USE_PLACE != '' and dto.USE_PLACE != null">and USE_PLACE = #{dto.USE_PLACE}</if> <if test="dto.USE_PLACE != '' and dto.USE_PLACE != null">and USE_PLACE = #{dto.USE_PLACE}</if>
<if test="dto.STATUS != '' and dto.STATUS != null">and STATUS = #{dto.STATUS}</if> <if test="dto.STATUS != '' and dto.STATUS != null">and STATUS = #{dto.STATUS}</if>
<if test="dto.EQU_CATEGORY != '' and dto.EQU_CATEGORY != null">and EQU_CATEGORY = #{dto.EQU_CATEGORY}</if>
<if test="dto.USE_UNIT_CREDIT_CODE != '' and dto.USE_UNIT_CREDIT_CODE != null">and USE_UNIT_CREDIT_CODE like concat('%', #{dto.USE_UNIT_CREDIT_CODE},'%')</if> <if test="dto.USE_UNIT_CREDIT_CODE != '' and dto.USE_UNIT_CREDIT_CODE != null">and USE_UNIT_CREDIT_CODE like concat('%', #{dto.USE_UNIT_CREDIT_CODE},'%')</if>
<if test="dto.ORG_BRANCH_CODE != '' and dto.ORG_BRANCH_CODE != null">and ORG_BRANCH_CODE like concat('%', #{dto.ORG_BRANCH_CODE},'%')</if> <if test="dto.ORG_BRANCH_CODE != '' and dto.ORG_BRANCH_CODE != null">and ORG_BRANCH_CODE like concat('%', #{dto.ORG_BRANCH_CODE},'%')</if>
<if test='dto.ids != null'> and SEQUENCE_NBR in <if test='dto.ids != null'> and SEQUENCE_NBR in
......
package com.yeejoin.amos.boot.module.tzs.biz.controller; package com.yeejoin.amos.boot.module.tzs.biz.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
...@@ -13,13 +14,16 @@ import com.yeejoin.amos.boot.module.tzs.api.dto.EquipExportDto; ...@@ -13,13 +14,16 @@ import com.yeejoin.amos.boot.module.tzs.api.dto.EquipExportDto;
import com.yeejoin.amos.boot.module.tzs.api.dto.EquipmentCategoryDto; import com.yeejoin.amos.boot.module.tzs.api.dto.EquipmentCategoryDto;
import com.yeejoin.amos.boot.module.tzs.api.entity.CategoryOtherInfo; import com.yeejoin.amos.boot.module.tzs.api.entity.CategoryOtherInfo;
import com.yeejoin.amos.boot.module.tzs.api.entity.EquipmentCategory; import com.yeejoin.amos.boot.module.tzs.api.entity.EquipmentCategory;
import com.yeejoin.amos.boot.module.tzs.api.enums.ImageSizeEnums;
import com.yeejoin.amos.boot.module.tzs.api.mapper.EquipmentCategoryMapper; import com.yeejoin.amos.boot.module.tzs.api.mapper.EquipmentCategoryMapper;
import com.yeejoin.amos.boot.module.tzs.api.service.IEquipmentCategoryService; import com.yeejoin.amos.boot.module.tzs.api.service.IEquipmentCategoryService;
import com.yeejoin.amos.boot.module.tzs.api.vo.EquipExportVo; import com.yeejoin.amos.boot.module.tzs.api.vo.EquipExportVo;
import com.yeejoin.amos.boot.module.tzs.biz.service.impl.EquipmentCategoryServiceImpl; import com.yeejoin.amos.boot.module.tzs.biz.service.impl.EquipmentCategoryServiceImpl;
import com.yeejoin.amos.boot.module.tzs.biz.utils.ImageUtils;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -30,10 +34,12 @@ import org.typroject.tyboot.core.restful.utils.ResponseModel; ...@@ -30,10 +34,12 @@ import org.typroject.tyboot.core.restful.utils.ResponseModel;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList; import java.io.*;
import java.util.Collection; import java.net.URL;
import java.util.List; import java.util.*;
import java.util.Map; import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
/** /**
* 装备分类 * 装备分类
...@@ -55,6 +61,13 @@ public class EquipmentCategoryController extends BaseController { ...@@ -55,6 +61,13 @@ public class EquipmentCategoryController extends BaseController {
EquipmentCategoryMapper equipmentCategoryMapper; EquipmentCategoryMapper equipmentCategoryMapper;
@Value("${regulatory_code_prefix}")
String REGULATORY_CODE_PREFIX ;
/**
* 监管码背景图路径
*/
private static final String BASE_PATH = "amos-boot-system-tzs/amos-boot-module-tzs-biz/src/main/resources/temp/";
/** /**
* 新增装备分类 * 新增装备分类
...@@ -374,6 +387,64 @@ public class EquipmentCategoryController extends BaseController { ...@@ -374,6 +387,64 @@ public class EquipmentCategoryController extends BaseController {
} }
@TycloudOperation(ApiLevel = UserType.AGENCY)
@GetMapping(value = "/exportImage")
@ApiOperation(httpMethod = "GET", value = "设备监管码下载", notes = "设备监管码下载")
public void exportImage(HttpServletResponse response, @RequestParam("code") String code, @RequestParam("type") String type) throws IOException {
FileInputStream bgImgFile = null;
ImageSizeEnums imageSizeEnums = ImageSizeEnums.getEnumByCode(type);
try {
bgImgFile = new FileInputStream(BASE_PATH + imageSizeEnums.getBgPath());
} catch (FileNotFoundException e) {
e.printStackTrace();
}
File QrCodeFile = new File(BASE_PATH + code + ".png");
ImageUtils.creatQRCode(QrCodeFile, bgImgFile, imageSizeEnums.getWith(), imageSizeEnums.getHeight(), REGULATORY_CODE_PREFIX+code, "", code, imageSizeEnums.getSize(), imageSizeEnums.getImagesX(), imageSizeEnums.getImagesY(), imageSizeEnums.getText1X(), imageSizeEnums.getText1Y(), imageSizeEnums.getText2X(), imageSizeEnums.getText2Y());
ImageUtils.downloadResource(code + ".png", BASE_PATH + code + ".png", response);
QrCodeFile.delete();
}
@TycloudOperation(ApiLevel = UserType.AGENCY)
@GetMapping(value = "/exportImageZip")
@ApiOperation(httpMethod = "GET", value = "设备信息导出", notes = "设备信息导出")
public void exportImageZip(HttpServletResponse response, EquipExportDto dto, @RequestParam("type") String type) throws IOException {
File delete = new File(BASE_PATH + "images");
if (!delete.exists()) {
delete.mkdir();
}
ImageSizeEnums imageSizeEnums = ImageSizeEnums.getEnumByCode(type);
//创建list 存放图片
List<File> fileList = new ArrayList<>();
List<EquipExportVo> equipExportData = equipmentCategoryServiceImpl.getEquipExportData(dto);
List<EquipExportVo> unique = equipExportData.stream().collect(
Collectors. collectingAndThen(
Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(o -> o.getSupervisoryCode() + ";" + o.getCode96333()))), ArrayList::new)
);
for (EquipExportVo equipExportDatum : unique) {
FileInputStream bgImgFile = new FileInputStream(BASE_PATH + imageSizeEnums.getBgPath());
if ("DT".equals(type) && !ObjectUtils.isEmpty(equipExportDatum.getCode96333())) {
File QrCodeFile = new File(BASE_PATH + "images/" + equipExportDatum.getCode96333() + ".png");
ImageUtils.creatQRCode(QrCodeFile, bgImgFile, imageSizeEnums.getWith(), imageSizeEnums.getHeight(), REGULATORY_CODE_PREFIX+equipExportDatum.getCode96333(), "", equipExportDatum.getCode96333(), imageSizeEnums.getSize(), imageSizeEnums.getImagesX(), imageSizeEnums.getImagesY(), imageSizeEnums.getText1X(), imageSizeEnums.getText1Y(), imageSizeEnums.getText2X(), imageSizeEnums.getText2Y());
fileList.add(new File(BASE_PATH + "images/" + equipExportDatum.getCode96333() + ".png"));
} else if (!ObjectUtils.isEmpty(equipExportDatum.getSupervisoryCode())) {
File QrCodeFile = new File(BASE_PATH + "images/" + equipExportDatum.getSupervisoryCode() + ".png");
ImageUtils.creatQRCode(QrCodeFile, bgImgFile, imageSizeEnums.getWith(), imageSizeEnums.getHeight(), REGULATORY_CODE_PREFIX+equipExportDatum.getSupervisoryCode(), "", equipExportDatum.getSupervisoryCode(), imageSizeEnums.getSize(), imageSizeEnums.getImagesX(), imageSizeEnums.getImagesY(), imageSizeEnums.getText1X(), imageSizeEnums.getText1Y(), imageSizeEnums.getText2X(), imageSizeEnums.getText2Y());
fileList.add(new File(BASE_PATH + "images/" + equipExportDatum.getSupervisoryCode() + ".png"));
}
bgImgFile.close();
}
File zipFile = new File(BASE_PATH + "images/imageZip.zip");
zipFile.createTempFile("imageZip", ".zip");
// 调用压缩方法
ImageUtils.zipFiles(fileList, zipFile);
ImageUtils.downloadResourceZip("imageZip.zip", BASE_PATH + "images/imageZip.zip", response);
zipFile.delete();
ImageUtils.deleteAllFilesOfDir(delete);
if (delete.exists()) {
ImageUtils.deleteAllFilesOfDir(delete);
}
}
} }
package com.yeejoin.amos.boot.module.tzs.biz.utils;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.common.BitMatrix;
import com.itextpdf.text.pdf.qrcode.ErrorCorrectionLevel;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletResponse;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
public class ImageUtils {
private static final int QRCOLOR = 0x201f1f; // 二维码颜色:黑色
private static final int BGWHITE = 0xFFFFFF; //二维码背景颜色:白色
private static Map<EncodeHintType, Object> hints = new HashMap<EncodeHintType, Object>() {
private static final long serialVersionUID = 1L;
{
put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M);// 设置QR二维码的纠错级别(H为最高级别)
put(EncodeHintType.CHARACTER_SET, "utf-8");// 设置编码方式
put(EncodeHintType.MARGIN, 0);// 白边
}
};
/**
* 生成二维码图片+背景+文字描述
*
* @param codeFile 生成图地址
* @param bgImgFile 背景图地址
* @param width 二维码宽度
* @param height 二维码高度
* @param qrUrl 内容
* @param note 文字说明
* @param tui 文字说明2
* @param size 文字大小
* @param imagesX 二维码x轴方向
* @param imagesY 二维码y轴方向
* @param text1X 文字描述1x轴方向
* @param text1Y 文字描述1y轴方向
* @param text2X 文字描述2x轴方向
* @param text2Y 文字描述2y轴方向
*/
public static void creatQRCode(File codeFile, FileInputStream bgImgFile, Integer width, Integer height, String qrUrl,
String note, String tui, Integer size, Integer imagesX, Integer imagesY, Integer text1X, Integer text1Y
, Integer text2X, Integer text2Y) throws IOException {
try {
MultiFormatWriter multiFormatWriter = new MultiFormatWriter();
BitMatrix bm = multiFormatWriter.encode(qrUrl, BarcodeFormat.QR_CODE, width, height, hints);
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
image.setRGB(x, y, bm.get(x, y) ? QRCOLOR : BGWHITE);
}
}
BufferedImage backgroundImage = ImageIO.read(bgImgFile);
int bgWidth = backgroundImage.getWidth();
int qrWidth = image.getWidth();
int disx = (bgWidth - qrWidth) - imagesX;
int disy = imagesY;
Graphics2D rng = backgroundImage.createGraphics();
rng.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP));
rng.drawImage(image, disx, disy, width, height, null);
// 抗锯齿
rng.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
// 文字描述参数设置
Color textColor = Color.white;
rng.setColor(textColor);
rng.drawImage(backgroundImage, 0, 0, null);
// 设置字体类型和大小(BOLD加粗/ PLAIN平常)
rng.setFont(new Font("Microsoft YaHei", Font.BOLD, size));
// 设置字体颜色
rng.setColor(Color.black);
int strWidth = rng.getFontMetrics().stringWidth(note);
// 文字1显示位置
int disx1 = (bgWidth - strWidth) - text1X;//左右
rng.drawString(note, disx1, text1Y);//上下
// 文字2显示位置
int disx2 = (bgWidth - strWidth) - text2X;//左右
rng.drawString(tui, disx2, text2Y);//上下
rng.dispose();
image = backgroundImage;
image.flush();
ImageIO.write(image, "png", codeFile);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (null != bgImgFile) {
bgImgFile.close();
}
}
}
/**
* 下载图片
*
* @param fileName
* @param resourceName
* @param response
*/
public static void downloadResource(String fileName, String resourceName, HttpServletResponse response) {
DataInputStream in = null;
OutputStream out = null;
InputStream fileInputStream = null;
try {
response.reset();
response.setCharacterEncoding("UTF-8");
response.setHeader("content-Type", "image/png");
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
fileInputStream = new FileInputStream(resourceName);
in = new DataInputStream(fileInputStream);
out = response.getOutputStream();
int bytes = 0;
byte[] bufferOut = new byte[1024];
while ((bytes = in.read(bufferOut)) != -1) {
out.write(bufferOut, 0, bytes);
}
} catch (Exception e) {
e.printStackTrace();
response.reset();
} finally {
try {
if (out != null) {
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
try {
if (in != null) {
in.close();
}
} catch (IOException e) {
e.printStackTrace();
}
try {
if (fileInputStream != null) {
fileInputStream.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* 下载压缩包
*
* @param fileName
* @param resourceName
* @param response
*/
public static void downloadResourceZip(String fileName, String resourceName, HttpServletResponse response) {
DataInputStream in = null;
OutputStream out = null;
InputStream fileInputStream = null;
try {
response.reset();
response.setCharacterEncoding("UTF-8");
response.setHeader("content-Type", "application/zip");
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
response.setHeader("Access-Control-Expose-Headers", "Content-Disposition");
fileInputStream = new FileInputStream(resourceName);
in = new DataInputStream(fileInputStream);
out = response.getOutputStream();
int bytes = 0;
byte[] bufferOut = new byte[1024];
while ((bytes = in.read(bufferOut)) != -1) {
out.write(bufferOut, 0, bytes);
}
} catch (Exception e) {
e.printStackTrace();
response.reset();
} finally {
try {
if (out != null) {
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
try {
if (in != null) {
in.close();
}
} catch (IOException e) {
e.printStackTrace();
}
try {
if (fileInputStream != null) {
fileInputStream.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
/**
* 压缩文件
*
* @param srcFiles
* @param zipFile
*/
public static void zipFiles(List<File> srcFiles, File zipFile) {
try {
if (srcFiles.size() != 0) {
// 判断压缩后的文件存在不,不存在则创建
if (!zipFile.exists()) {
zipFile.createNewFile();
} else {
zipFile.delete();
zipFile.createNewFile();
}
// 创建 FileInputStream 对象
InputStream fileInputStream = null;
// 实例化 FileOutputStream 对象
FileOutputStream fileOutputStream = new FileOutputStream(zipFile);
// 实例化 ZipOutputStream 对象
ZipOutputStream zipOutputStream = new ZipOutputStream(fileOutputStream);
// 创建 ZipEntry 对象
ZipEntry zipEntry = null;
// 遍历源文件数组
// for (int i = 0; i < srcFiles.size(); i++) {
// // 将源文件数组中的当前文件读入 FileInputStream 流中
// File file = srcFiles.get(i);
// fileInputStream = new FileInputStream(file);
// // 实例化 ZipEntry 对象,源文件数组中的当前文件
// zipEntry = new ZipEntry(i + ".jpg");
// zipOutputStream.putNextEntry(zipEntry);
// // 该变量记录每次真正读的字节个数
// int len;
// // 定义每次读取的字节数组
// byte[] buffer = new byte[1024];
// while ((len = fileInputStream.read(buffer)) > 0) {
// zipOutputStream.write(buffer, 0, len);
// }
// }
for (File srcFile : srcFiles) {
fileInputStream = new FileInputStream(srcFile);
// 实例化 ZipEntry 对象,源文件数组中的当前文件
zipEntry = new ZipEntry(srcFile.getName());
zipOutputStream.putNextEntry(zipEntry);
// 该变量记录每次真正读的字节个数
int len;
// 定义每次读取的字节数组
byte[] buffer = new byte[1024];
while ((len = fileInputStream.read(buffer)) > 0) {
zipOutputStream.write(buffer, 0, len);
}
}
zipOutputStream.closeEntry();
zipOutputStream.close();
fileInputStream.close();
fileOutputStream.close();
System.out.println("下载完成");
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 删除文件夹(强制删除)
*
* @param file
*/
public static void deleteAllFilesOfDir(File file) {
if (null != file) {
if (!file.exists())
return;
if (file.isFile()) {
boolean result = file.delete();
int tryCount = 0;
while (!result && tryCount++ < 10) {
System.gc(); // 回收资源
result = file.delete();
}
}
File[] files = file.listFiles();
if (null != files) {
for (int i = 0; i < files.length; i++) {
deleteAllFilesOfDir(files[i]);
}
}
file.delete();
}
}
}
...@@ -780,18 +780,19 @@ public class RegUnitInfoServiceImpl extends BaseService<RegUnitInfoDto, RegUnitI ...@@ -780,18 +780,19 @@ public class RegUnitInfoServiceImpl extends BaseService<RegUnitInfoDto, RegUnitI
String userIdsTask = String.join(",", task); String userIdsTask = String.join(",", task);
// 添加被检查企业下的人员id // 添加被检查企业下的人员id
objectMap.put("CHECKED_COMPANY_USERS", userIds); objectMap.put("CHECKED_COMPANY_USERS", userIds);
objectMap.put("CHECKED_COMPANY_USER_ids", userIdsTask);
// 表单信息提交 // 表单信息提交
FeignClientResult<String> submit = idxFeignService.submit(pageId, taskId, planInstanceId, topic, tableName, objectMap); FeignClientResult<String> submit = idxFeignService.submit(pageId, taskId, planInstanceId,"CHECKED_COMPANY_USER_ids", topic, tableName, objectMap);
if ("200".equals(String.valueOf(submit.getStatus()))) { // if ("200".equals(String.valueOf(submit.getStatus()))) {
JSONObject jsonObject = new JSONObject(); // JSONObject jsonObject = new JSONObject();
jsonObject.put("title", "企业整改"); // jsonObject.put("title", "企业整改");
jsonObject.put("userIds", userIdsTask); // jsonObject.put("userIds", userIdsTask);
logger.info("idx执行任务更新参数,{}", JSONObject.toJSONString(jsonObject)); // logger.info("idx执行任务更新参数,{}", JSONObject.toJSONString(jsonObject));
//FeignClientResult<JSONObject> jsonObjectFeignClientResult = idxFeignService.updateAmosTask(taskId, jsonObject); // //FeignClientResult<JSONObject> jsonObjectFeignClientResult = idxFeignService.updateAmosTask(taskId, jsonObject);
updateAmosTask(taskId, jsonObject); // updateAmosTask(taskId, jsonObject);
//logger.info("idx执行任务更新任务返回参数,{}", JSONObject.toJSONString(jsonObjectFeignClientResult)); // //logger.info("idx执行任务更新任务返回参数,{}", JSONObject.toJSONString(jsonObjectFeignClientResult));
//
} // }
return "ok"; return "ok";
} }
......
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