Commit 54cae241 authored by chenzhao's avatar chenzhao

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

parents 7871b01f 4fab24f8
......@@ -23,7 +23,6 @@ import com.yeejoin.amos.component.feign.model.FeignClientResult;
import com.yeejoin.amos.feign.privilege.model.AgencyUserModel;
import com.yeejoin.amos.feign.systemctl.Systemctl;
import com.yeejoin.amos.feign.systemctl.model.RegionModel;
import jdk.internal.org.objectweb.asm.TypeReference;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
......
......@@ -832,18 +832,26 @@ public class MonitorFanIndicatorImpl implements IMonitorFanIndicator {
public ResultsData runningPageByStationId(int current, int size, String stationId) {
StationBasic stationBasic = stationBasicMapper.selectById(stationId);
String baseSql = "SELECT equipmentNumber, value FROM \"indicators_%s\" where equipmentIndexName = '%s'";
String windSql = String.format(baseSql, stationBasic.getFanGatewayId(), "风向角");
List<IndicatorsDto> windSqlList = influxDButils.getListDataAll(windSql,IndicatorsDto.class);
String powerSql = String.format(baseSql, stationBasic.getFanGatewayId(), "有功功率");
List<IndicatorsDto> powerSqlList = influxDButils.getListDataAll(powerSql,IndicatorsDto.class);
String baseSql = "SELECT equipmentNumber, value, equipmentIndexName FROM \"indicators_%s\" where equipmentIndexName = '%s' or equipmentIndexName = '%s' or equipmentIndexName = '%s' or equipmentIndexName = '%s'";
String windSql = String.format(baseSql, stationBasic.getFanGatewayId(), "风向角", "有功功率", "瞬时风速", "日发电量");
List<IndicatorsDto> allList = influxDButils.getListDataAll(windSql,IndicatorsDto.class);
List<IndicatorsDto> windSqlList = new ArrayList<>();
List<IndicatorsDto> powerSqlList = new ArrayList<>();
List<IndicatorsDto> windSpeedSqlList = new ArrayList<>();
List<IndicatorsDto> electricitySqlList = new ArrayList<>();
allList.forEach(item -> {
if ("风向角".equals(item.getEquipmentIndexName())) {
windSqlList.add(item);
} if ("有功功率".equals(item.getEquipmentIndexName())) {
powerSqlList.add(item);
} if ("瞬时风速".equals(item.getEquipmentIndexName())) {
windSpeedSqlList.add(item);
} if ("日发电量".equals(item.getEquipmentIndexName())) {
electricitySqlList.add(item);
}
});
Map<String, String> powerSqlMap = powerSqlList.stream().collect(Collectors.toMap(IndicatorsDto::getEquipmentNumber, IndicatorsDto::getValue));
String windSpeedSql = String.format(baseSql, stationBasic.getFanGatewayId(), "瞬时风速");
List<IndicatorsDto> windSpeedSqlList = influxDButils.getListDataAll(windSpeedSql,IndicatorsDto.class);
Map<String, String> windSpeedSqlMap = windSpeedSqlList.stream().collect(Collectors.toMap(IndicatorsDto::getEquipmentNumber, IndicatorsDto::getValue));
String electricitySql = String.format(baseSql, stationBasic.getFanGatewayId(), "日发电量");
List<IndicatorsDto> electricitySqlList = influxDButils.getListDataAll(electricitySql,IndicatorsDto.class);
Map<String, String> electricitySqlMap = electricitySqlList.stream().collect(Collectors.toMap(IndicatorsDto::getEquipmentNumber, IndicatorsDto::getValue));
ArrayList<Map<String, String>> resultList = new ArrayList<>();
windSqlList.forEach(item -> {
......
......@@ -20,6 +20,7 @@ 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.biz.service.impl.EquipmentCategoryServiceImpl;
import com.yeejoin.amos.boot.module.tzs.biz.utils.ImageUtils;
import com.yeejoin.amos.component.robot.BadRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -311,6 +312,11 @@ public class EquipmentCategoryController extends BaseController {
@GetMapping(value = "/exportData")
@ApiOperation(httpMethod = "GET", value = "设备信息导出", notes = "设备信息导出")
public void exportData(HttpServletResponse response, EquipExportDto dto) {
if (!ObjectUtils.isEmpty(dto.getUSE_PLACE())) {
String address = dto.getUSE_PLACE().substring(1, dto.getUSE_PLACE().length() - 1);
address = address.replace(", ", "/");
dto.setUSE_PLACE(address);
}
List<EquipExportVo> equipExportData = equipmentCategoryServiceImpl.getEquipExportData(dto);
ExcelUtil.createTemplate(response, "设备信息", "设备信息", equipExportData, EquipExportVo.class, null, false);
}
......@@ -401,16 +407,32 @@ public class EquipmentCategoryController extends BaseController {
ImageSizeEnums imageSizeEnums = ImageSizeEnums.getEnumByCode(type);
//创建list 存放图片
List<File> fileList = new ArrayList<>();
if (!ObjectUtils.isEmpty(dto.getUSE_PLACE())) {
String address = dto.getUSE_PLACE().substring(1, dto.getUSE_PLACE().length() - 1);
address = address.replace(", ", "/");
dto.setUSE_PLACE(address);
}
List<EquipExportVo> equipExportData = equipmentCategoryServiceImpl.exportImageZip(dto, pageNum, size);
List<EquipExportVo> unique = equipExportData.stream().filter(item -> !ObjectUtils.isEmpty(item.getSupervisoryCode())).collect(
Collectors.collectingAndThen(
Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(EquipExportVo::getSupervisoryCode))), ArrayList::new)
);
List<EquipExportVo> collect = unique.stream().filter(item -> !ObjectUtils.isEmpty(item.getCode96333())).collect(
Collectors.collectingAndThen(
Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(EquipExportVo::getCode96333))), ArrayList::new)
);
for (EquipExportVo equipExportDatum : collect) {
if (ImageSizeEnums.DT.getCode().equals(type)){
unique = unique.stream().filter(item -> !ObjectUtils.isEmpty(item.getCode96333())).collect(
Collectors.collectingAndThen(
Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(EquipExportVo::getCode96333))), ArrayList::new)
);
}
if (ObjectUtils.isEmpty(unique)){
File zipFile = File.createTempFile("设备码信息", ".zip");
File nullFile = File.createTempFile("当前导出数据为空+", ".txt");
fileList.add(nullFile);
// 调用压缩方法
ImageUtils.zipFiles(fileList, zipFile, ".txt");
ImageUtils.downloadResourceZip("设备码信息.zip", zipFile.getAbsolutePath(), response);
zipFile.delete();
}
for (EquipExportVo equipExportDatum : unique) {
InputStream bgImgFile = getClass().getClassLoader().getResourceAsStream("temp/" + imageSizeEnums.getBgPath());
if ("DT".equals(type) && !ObjectUtils.isEmpty(equipExportDatum.getCode96333())) {
File QrCodeFile = File.createTempFile(equipExportDatum.getCode96333() + "+", ".png");
......@@ -423,10 +445,10 @@ public class EquipmentCategoryController extends BaseController {
}
bgImgFile.close();
}
File zipFile = File.createTempFile("imageZip", ".zip");
File zipFile = File.createTempFile("设备码信息", ".zip");
// 调用压缩方法
ImageUtils.zipFiles(fileList, zipFile);
ImageUtils.downloadResourceZip("imageZip.zip", zipFile.getAbsolutePath(), response);
ImageUtils.zipFiles(fileList, zipFile, ".png");
ImageUtils.downloadResourceZip("设备码信息.zip", zipFile.getAbsolutePath(), response);
zipFile.delete();
}
......
package com.yeejoin.amos.boot.module.tzs.biz.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yeejoin.amos.boot.biz.common.bo.ReginParams;
import com.yeejoin.amos.component.feign.config.TokenOperation;
import com.yeejoin.amos.component.feign.model.FeignClientResult;
import com.yeejoin.amos.feign.privilege.Privilege;
import com.yeejoin.amos.feign.privilege.model.AgencyUserModel;
import com.yeejoin.amos.feign.privilege.model.ApplicationModel;
import com.yeejoin.amos.feign.privilege.model.CompanyModel;
import com.yeejoin.amos.feign.privilege.model.IdPasswordAuthModel;
import com.yeejoin.amos.feign.privilege.util.DesUtil;
import com.yeejoin.amos.component.robot.AmosRequestContext;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.typroject.tyboot.core.foundation.context.RequestContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.typroject.tyboot.core.foundation.enumeration.UserType;
import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
/**
* @author zjw
* @date 2020-03-30
*/
@RestController
@RequestMapping(value = "/api/loginBytoken")
@Api(tags = "通过userName登录Api")
@RequestMapping(value = "/weapp/api")
@Api(tags = "小程序登录api")
public class LoginController {
private static final Logger logger = LoggerFactory.getLogger(LoginController.class);
// @Autowired
// private RedisTemplate<String, String> redisTemplate;
//
// @Value("${outSystem.user.password}")
// private String password;
//
// @Value("${amos.system.user.product}")
// private String product;
//
// @Value("${amos.system.user.app-key}")
// private String appKey;
@Autowired
private RedisTemplate<String, String> redisTemplate;
@Value("${outSystem.user.password}")
private String password;
@Value("${amos.system.user.product}")
private String product;
@Value("${amos.system.user.app-key}")
private String appKey;
AmosRequestContext amosRequestContext;
// @TycloudOperation(ApiLevel = UserType.AGENCY,needAuth = false)
// @ApiOperation(value = "通过userId登录", notes = "查询设备指标")
// @GetMapping(value = "/{userId}")
// synchronized public ReginParams getBindEquipment(@PathVariable("userId") String userId) throws Exception {
//
// if (ObjectUtils.isEmpty(userId)){
// throw new Exception("用户信息不存在");
// }
// HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder
// .getRequestAttributes()).getRequest();
// String token = "wxxcxdl";
// ReginParams reginParams;
// reginParams = JSON.parseObject(redisTemplate.opsForValue().get(buildKey(userId, token)), ReginParams.class);
// if(reginParams == null){
// reginParams = getLogin(userId, token);
// }else{
// RequestContext.setProduct(product);
// if (!TokenOperation.refresh(reginParams.getToken())) {
// reginParams = getLogin(userId, token);
// }
// }
// return reginParams;
// }
//
// private ReginParams getLogin(String userId, String token) throws Exception{
// ReginParams reginParams = new ReginParams();
// IdPasswordAuthModel dPasswordAuthModel = new IdPasswordAuthModel();
// dPasswordAuthModel.setLoginId(userId);
// dPasswordAuthModel.setPassword(DesUtil.encode(password, "qaz"));
// RequestContext.setProduct(product);
// FeignClientResult feignClientResult = Privilege.authClient.idpassword(dPasswordAuthModel);
// if (ObjectUtils.isEmpty(feignClientResult.getResult())){
// throw new Exception("缺失登录信息");
// }
// // 调用平台授权接口
// Map<String ,String > re = (Map<String, String>) feignClientResult.getResult();
// String amosToken = re.get("token");
//
// logger.info("应用授权开始======================================"+amosToken);
// RequestContext.setToken(amosToken);
// RequestContext.setProduct(product);
// RequestContext.setAppKey(appKey);
//
// List<ApplicationModel> fd = Privilege.applicationClient.queryUserService().getResult();
//
// logger.info("应用授权结束======================================"+JSON.toJSONString(fd)+amosToken);
//
// AgencyUserModel userModel = (AgencyUserModel) Privilege.agencyUserClient.getme().getResult();
// CompanyModel companyModel = userModel.getCompanys().get(0);
//
// reginParams.setToken(amosToken);
// reginParams.setUserModel(userModel);
// redisTemplate.opsForValue().set(buildKey(userId, token), JSONObject.toJSONString(reginParams),28, TimeUnit.DAYS);
// return reginParams;
// }
//
//
// private String buildKey(String userId, String token) {
// return "region_" + userId + "_" + token;
// }
@TycloudOperation(ApiLevel = UserType.AGENCY,needAuth = false)
@ApiOperation(value = "通过userId登录", notes = "查询设备指标")
@GetMapping(value = "/{userId}")
synchronized public ReginParams getBindEquipment(@PathVariable("userId") String userId) throws Exception {
if (ObjectUtils.isEmpty(userId)){
throw new Exception("用户信息不存在");
}
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder
.getRequestAttributes()).getRequest();
String token = "wxxcxdl";
ReginParams reginParams;
reginParams = JSON.parseObject(redisTemplate.opsForValue().get(buildKey(userId, token)), ReginParams.class);
if(reginParams == null){
reginParams = getLogin(userId, token);
}else{
RequestContext.setProduct(product);
if (!TokenOperation.refresh(reginParams.getToken())) {
reginParams = getLogin(userId, token);
}
}
return reginParams;
}
private ReginParams getLogin(String userId, String token) throws Exception{
ReginParams reginParams = new ReginParams();
IdPasswordAuthModel dPasswordAuthModel = new IdPasswordAuthModel();
dPasswordAuthModel.setLoginId(userId);
dPasswordAuthModel.setPassword(DesUtil.encode(password, "qaz"));
RequestContext.setProduct(product);
FeignClientResult feignClientResult = Privilege.authClient.idpassword(dPasswordAuthModel);
if (ObjectUtils.isEmpty(feignClientResult.getResult())){
throw new Exception("缺失登录信息");
}
// 调用平台授权接口
Map<String ,String > re = (Map<String, String>) feignClientResult.getResult();
String amosToken = re.get("token");
logger.info("应用授权开始======================================"+amosToken);
RequestContext.setToken(amosToken);
RequestContext.setProduct(product);
RequestContext.setAppKey(appKey);
List<ApplicationModel> fd = Privilege.applicationClient.queryUserService().getResult();
logger.info("应用授权结束======================================"+JSON.toJSONString(fd)+amosToken);
AgencyUserModel userModel = (AgencyUserModel) Privilege.agencyUserClient.getme().getResult();
CompanyModel companyModel = userModel.getCompanys().get(0);
reginParams.setToken(amosToken);
reginParams.setUserModel(userModel);
redisTemplate.opsForValue().set(buildKey(userId, token), JSONObject.toJSONString(reginParams),28, TimeUnit.DAYS);
return reginParams;
}
private String buildKey(String userId, String token) {
return "region_" + userId + "_" + token;
@ApiOperation(value = "获取机器人登录token", notes = "获取机器人登录token")
@GetMapping(value = "/acquireToken")
synchronized public String getRobotLoginToken() {
return amosRequestContext.getToken();
}
}
......@@ -169,7 +169,7 @@ public class ImageUtils {
OutputStream out = null;
InputStream fileInputStream = null;
try {
response.reset();
// response.reset();
response.setCharacterEncoding("UTF-8");
response.setHeader("content-Type", "application/zip");
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
......@@ -218,7 +218,7 @@ public class ImageUtils {
* @param srcFiles
* @param zipFile
*/
public static void zipFiles(List<File> srcFiles, File zipFile) {
public static void zipFiles(List<File> srcFiles, File zipFile, String fileType) {
try {
if (srcFiles.size() != 0) {
// 判断压缩后的文件存在不,不存在则创建
......@@ -255,7 +255,7 @@ public class ImageUtils {
for (File srcFile : srcFiles) {
fileInputStream = new FileInputStream(srcFile);
// 实例化 ZipEntry 对象,源文件数组中的当前文件
zipEntry = new ZipEntry(StringUtils.substringBefore(srcFile.getName(), "+") + ".png");
zipEntry = new ZipEntry(StringUtils.substringBefore(srcFile.getName(), "+") + fileType);
zipOutputStream.putNextEntry(zipEntry);
// 该变量记录每次真正读的字节个数
int len;
......
......@@ -153,10 +153,11 @@ tzs.cylinder.info.cron=0 0 1 * * ?
# ??????????
minio.url.path=http://172.16.10.210:9000/
## ɼǰ׺
regulatory_code_prefix=https://nav.sspai.top/tzs?code=
outSystem.user.password=a1234560
amos.system.user.app-key=AMOS_STUDIO
amos.system.user.product=STUDIO_APP_WEB
\ No newline at end of file
## 生成监管码前缀域名(预发布环境使用)
regulatory_code_prefix=https://sxtzsb.sxsei.com:9435/tzs?code=
## 生成监管码前缀域名(生产环境使用)
#regulatory_code_prefix=https://sxtzsb.sxsei.com:19435/tzs?code=
#outSystem.user.password=a1234560
#amos.system.user.app-key=AMOS_STUDIO
#amos.system.user.product=STUDIO_APP_WEB
\ No newline at end of file
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