From 71df561902baf31f252fd2ff44c34bb69d07cbeb Mon Sep 17 00:00:00 2001 From: yang_shj <1069818635@QQ.com> Date: Fri, 26 Jul 2024 08:18:53 +0800 Subject: [PATCH] =?UTF-8?q?#=E7=A6=BB=E7=BA=BF=E5=B7=A1=E6=A3=80=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E4=B8=8A=E4=BC=A0=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../equipment/mapper/PlanGenerationMapper.java | 4 +- .../inspect/offline/filter/ContentTypeFilter.java | 22 ++++++++ .../offline/filter/ContentTypeRequestWrapper.java | 53 +++++++++++++++++++ .../service/impl/InspectOfflineServiceImpl.java | 59 +++++++--------------- .../controller/CentralMonitorController.java | 6 +-- .../config/service/CentralMonitorService.java | 4 +- .../service/impl/CentralMonitorServiceImpl.java | 39 +++++++------- .../history/service/impl/AlarmServiceImpl.java | 6 ++- .../history/service/impl/PointServiceImpl.java | 26 +++++++--- 9 files changed, 141 insertions(+), 78 deletions(-) create mode 100644 hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/offline/filter/ContentTypeFilter.java create mode 100644 hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/offline/filter/ContentTypeRequestWrapper.java diff --git a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/mapper/PlanGenerationMapper.java b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/mapper/PlanGenerationMapper.java index eb7f592..f6be400 100644 --- a/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/mapper/PlanGenerationMapper.java +++ b/hzims-service/equipment/src/main/java/com/hnac/hzims/equipment/mapper/PlanGenerationMapper.java @@ -10,7 +10,7 @@ import java.util.Map; public interface PlanGenerationMapper extends UserDataScopeBaseMapper { - Float selectPlanGenertionYearCount(String stationId, int year); + Float selectPlanGenertionYearCount(@Param("stationId") String stationId,@Param("year") int year); List selectListAll(@Param("date") String date); @@ -42,5 +42,5 @@ public interface PlanGenerationMapper extends UserDataScopeBaseMapper getPlanPowerByYear(String code, int year); + List getPlanPowerByYear(@Param("code") String code,@Param("year") int year); } diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/offline/filter/ContentTypeFilter.java b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/offline/filter/ContentTypeFilter.java new file mode 100644 index 0000000..94c64e1 --- /dev/null +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/offline/filter/ContentTypeFilter.java @@ -0,0 +1,22 @@ +package com.hnac.hzinfo.inspect.offline.filter; + +import javax.servlet.*; +import javax.servlet.annotation.WebFilter; +import javax.servlet.http.HttpServletRequest; +import java.io.IOException; + +/** + * @author ysj + * @version 4.0.0 + * @create 2024-07-24-19:07 + */ +@WebFilter(filterName = "ContentTypeFilter", urlPatterns = "/offline/syncOfflineDataToOnline") +public class ContentTypeFilter implements Filter { + + @Override + public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { + HttpServletRequest httpRequest = (HttpServletRequest) request; + ContentTypeRequestWrapper wrappedRequest = new ContentTypeRequestWrapper(httpRequest); + chain.doFilter(wrappedRequest, response); + } +} diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/offline/filter/ContentTypeRequestWrapper.java b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/offline/filter/ContentTypeRequestWrapper.java new file mode 100644 index 0000000..47053a5 --- /dev/null +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/offline/filter/ContentTypeRequestWrapper.java @@ -0,0 +1,53 @@ +package com.hnac.hzinfo.inspect.offline.filter; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletRequestWrapper; +import java.util.Collections; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Map; + +/** + * @author ysj + * @version 4.0.0 + * @create 2024-07-24-19:08 + */ +public class ContentTypeRequestWrapper extends HttpServletRequestWrapper { + + private final String newContentType; + + public ContentTypeRequestWrapper(HttpServletRequest request) { + super(request); + // 你想要设置的新Content-Type + this.newContentType = "form-data"; + } + + @Override + public String getHeader(String name) { + if ("Content-Type".equalsIgnoreCase(name)) { + return newContentType; + } + return super.getHeader(name); + } + + @Override + public Enumeration getHeaders(String name) { + if ("Content-Type".equalsIgnoreCase(name)) { + return Collections.enumeration(Collections.singleton(newContentType)); + } + return super.getHeaders(name); + } + + @Override + public Enumeration getHeaderNames() { + Map headers = new HashMap<>(); + HttpServletRequest originalRequest = (HttpServletRequest) getRequest(); + Enumeration headerNames = originalRequest.getHeaderNames(); + while (headerNames.hasMoreElements()) { + String headerName = headerNames.nextElement(); + headers.put(headerName, headerName); + } + headers.put("Content-Type", "Content-Type"); + return Collections.enumeration(headers.keySet()); + } +} \ No newline at end of file diff --git a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/offline/service/impl/InspectOfflineServiceImpl.java b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/offline/service/impl/InspectOfflineServiceImpl.java index e33d189..8accdf3 100644 --- a/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/offline/service/impl/InspectOfflineServiceImpl.java +++ b/hzims-service/inspect/src/main/java/com/hnac/hzinfo/inspect/offline/service/impl/InspectOfflineServiceImpl.java @@ -37,6 +37,7 @@ import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.MapUtils; import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.FileItemFactory; +import org.apache.commons.fileupload.disk.DiskFileItem; import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.io.IOUtils; import org.springblade.core.log.exception.ServiceException; @@ -53,6 +54,7 @@ import org.springblade.core.tool.utils.StringUtil; import org.springblade.offline.service.IOfflineDataService; import org.springblade.resource.feign.IOssClient; import org.springblade.system.vo.CreateTableVO; +import org.springblade.system.vo.TemplateVO; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Primary; import org.springframework.jdbc.core.JdbcTemplate; @@ -69,6 +71,7 @@ import java.lang.reflect.Method; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; +import java.nio.file.Files; import java.util.*; import java.util.stream.Collectors; @@ -905,8 +908,7 @@ public class InspectOfflineServiceImpl implements IOfflineDataService { } R r = null; try { - MultipartFile multipartFile = this.getMultipartFile(file); - r = ossClient.putFile(multipartFile); + r = putFile(file); if (!r.isSuccess()) { throw new RuntimeException("上传文件["+fileName+"]失败,bladex-resource报错:" + r); } @@ -948,8 +950,8 @@ public class InspectOfflineServiceImpl implements IOfflineDataService { } R r = null; try { - MultipartFile multipartFile = this.getMultipartFile(file); - r = ossClient.putFile(multipartFile); + + r = putFile(file); if (!r.isSuccess()) { throw new RuntimeException("上传文件["+fileName+"]失败,bladex-resource报错:" + r); } @@ -963,46 +965,21 @@ public class InspectOfflineServiceImpl implements IOfflineDataService { }); } - private MultipartFile getMultipartFile(File file) { - FileItem fileItem = this.createFileItem(file); - return new CommonsMultipartFile(fileItem); - } - + public R putFile(File file) throws IOException { + FileItem fileItem = new DiskFileItem("file", Files.probeContentType(file.toPath()),false,file.getName(),(int)file.length(),file.getParentFile()); + try (InputStream inputStream = new FileInputStream(file); OutputStream os = fileItem.getOutputStream()){ + IOUtils.copy(inputStream,os); - public FileItem createFileItem(File file) { - FileItemFactory factory = new DiskFileItemFactory(16, null); - String textFieldName = "file"; - FileItem item = factory.createItem(textFieldName, "text/plain", false, - file.getName()); - int bytesRead = 0; - byte[] buffer = new byte[1024]; - FileInputStream fis = null; - OutputStream os = null; - try { - fis = new FileInputStream(file); - os = item.getOutputStream(); - - while ((bytesRead = fis.read(buffer, 0, buffer.length)) != -1) { - os.write(buffer, 0, bytesRead); - } - os.close(); - fis.close(); - } catch (IOException e) { + /* + 把用户上传的zip包中的视频文件,照片文件上传到miniio服务器并且返回映射关系的map + */ + MultipartFile multipartFile = new CommonsMultipartFile(fileItem); + R r = ossClient.putFile(multipartFile); + return r; + }catch (IOException e){ e.printStackTrace(); - } finally { - try { - if (null != os) { - os.close(); - } - if (null != fis) { - fis.close(); - } - } catch (IOException e) { - e.printStackTrace(); - } } - return item; + return R.fail("shangc"); } - } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/controller/CentralMonitorController.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/controller/CentralMonitorController.java index 824c597..f490b1e 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/controller/CentralMonitorController.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/controller/CentralMonitorController.java @@ -53,8 +53,8 @@ public class CentralMonitorController extends BladeController { public R selectCommunication(@PathVariable Integer page, @PathVariable Integer size, String roleId, - Date start, - Date end){ + String start, + String end){ IPage result = monitorService.selectOriginalDataByRealIds(page, size, roleId,start,end); return R.data(result); } @@ -62,7 +62,7 @@ public class CentralMonitorController extends BladeController { @GetMapping("/communications") @ApiOperation("查询通讯告警图表数据") @ApiOperationSupport(order = 4) - public R> communications(String roleId,Date start,Date end){ + public R> communications(String roleId,String start,String end){ return R.data(monitorService.communications(roleId,start,end)); } } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/CentralMonitorService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/CentralMonitorService.java index cc3caf8..8e399cc 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/CentralMonitorService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/CentralMonitorService.java @@ -29,7 +29,7 @@ public interface CentralMonitorService{ * @param roleId * @return */ - IPage selectOriginalDataByRealIds(Integer page, Integer size, String roleId, Date start, Date end); + IPage selectOriginalDataByRealIds(Integer page, Integer size, String roleId, String start, String end); - List communications(String roleId, Date start, Date end); + List communications(String roleId, String start, String end); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/impl/CentralMonitorServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/impl/CentralMonitorServiceImpl.java index e3f5b51..c901442 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/impl/CentralMonitorServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/config/service/impl/CentralMonitorServiceImpl.java @@ -22,6 +22,7 @@ import lombok.RequiredArgsConstructor; import org.springblade.core.log.exception.ServiceException; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.CollectionUtil; +import org.springblade.core.tool.utils.DateUtil; import org.springblade.core.tool.utils.ObjectUtil; import org.springblade.core.tool.utils.StringUtil; import org.springblade.system.entity.Dept; @@ -37,10 +38,7 @@ import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.format.DateTimeFormatter; -import java.util.Calendar; -import java.util.Collections; -import java.util.Date; -import java.util.List; +import java.util.*; import java.util.stream.Collectors; @@ -94,7 +92,7 @@ public class CentralMonitorServiceImpl implements CentralMonitorService { * @return */ @Override - public IPage selectOriginalDataByRealIds(Integer page, Integer size, String roleId,Date start,Date end) { + public IPage selectOriginalDataByRealIds(Integer page, Integer size, String roleId,String start,String end) { OriginalDataQuery originalDataQuery = new OriginalDataQuery(); originalDataQuery.setRealId(roleId); originalDataQuery.setLimit(size); @@ -109,12 +107,13 @@ public class CentralMonitorServiceImpl implements CentralMonitorService { calendar.add(Calendar.MILLISECOND,-calendar.get(Calendar.MILLISECOND)); originalDataQuery.setBeginTime(calendar.getTime()); }else{ - originalDataQuery.setBeginTime(start); - originalDataQuery.setEndTime(end); + originalDataQuery.setBeginTime(DateUtil.parse(start,DateUtil.PATTERN_DATETIME)); + originalDataQuery.setEndTime(DateUtil.parse(end,DateUtil.PATTERN_DATETIME)); } + IPage iPage = new Page<>(page, size); Result> originalDataByRealIds = historyDataSearchClient.getOriginalDataByRealIds(originalDataQuery); - if (!originalDataByRealIds.isSuccess()) { - throw new ServiceException("数据不存在"); + if (!originalDataByRealIds.isSuccess() || ObjectUtil.isEmpty(originalDataByRealIds.getData()) || CollectionUtil.isEmpty(originalDataByRealIds.getData().getRecords())) { + return iPage; } HzPage data = originalDataByRealIds.getData(); List collect = data.getRecords().stream().map(item -> { @@ -130,8 +129,6 @@ public class CentralMonitorServiceImpl implements CentralMonitorService { } return pointDataVo; }).collect(Collectors.toList()); - - IPage iPage = new Page<>(data.getCurrent(), data.getSize()); iPage.setRecords(collect); iPage.setTotal(originalDataByRealIds.getData().getTotal()); return iPage; @@ -145,11 +142,11 @@ public class CentralMonitorServiceImpl implements CentralMonitorService { * @return */ @Override - public List communications(String roleId, Date start, Date end) { + public List communications(String roleId, String start, String end) { OriginalDataQuery originalDataQuery = new OriginalDataQuery(); originalDataQuery.setRealId(roleId); - originalDataQuery.setLimit(1); - originalDataQuery.setPage(100000); + originalDataQuery.setLimit(10000); + originalDataQuery.setPage(1); // 当日 if(ObjectUtil.isEmpty(start) && ObjectUtil.isEmpty(end)){ Calendar calendar = Calendar.getInstance(); @@ -160,22 +157,22 @@ public class CentralMonitorServiceImpl implements CentralMonitorService { calendar.add(Calendar.MILLISECOND,-calendar.get(Calendar.MILLISECOND)); originalDataQuery.setBeginTime(calendar.getTime()); }else{ - originalDataQuery.setBeginTime(start); - originalDataQuery.setEndTime(end); + originalDataQuery.setBeginTime(DateUtil.parse(start,DateUtil.PATTERN_DATETIME)); + originalDataQuery.setEndTime(DateUtil.parse(end,DateUtil.PATTERN_DATETIME)); } Result> originalDataByRealIds = historyDataSearchClient.getOriginalDataByRealIds(originalDataQuery); - if (!originalDataByRealIds.isSuccess()) { - throw new ServiceException("数据不存在"); + if (!originalDataByRealIds.isSuccess() || ObjectUtil.isEmpty(originalDataByRealIds.getData()) || CollectionUtil.isEmpty(originalDataByRealIds.getData().getRecords())) { + return new ArrayList<>(); } HzPage data = originalDataByRealIds.getData(); + StationEntity station = stationService.getOne(Wrappers.lambdaQuery() + .eq(StationEntity::getCode,originalDataByRealIds.getData().getRecords().get(0).getStation()) + ); return data.getRecords().stream().map(item -> { PointDataVo pointDataVo = new PointDataVo(); BeanUtils.copyProperties(item, pointDataVo); //通过站点id获取站点名称 String code = pointDataVo.getStation(); - StationEntity station = stationService.getOne(Wrappers.lambdaQuery() - .eq(StationEntity::getCode,code) - ); if(ObjectUtil.isNotEmpty(station)){ pointDataVo.setStationName(station.getName()); } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/history/service/impl/AlarmServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/history/service/impl/AlarmServiceImpl.java index 296e515..ee37907 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/history/service/impl/AlarmServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/history/service/impl/AlarmServiceImpl.java @@ -3,6 +3,7 @@ package com.hnac.hzims.operational.history.service.impl; import com.hnac.hzims.operational.history.service.AlarmService; import com.hnac.hzims.operational.history.vo.HistoryProjectAlarmVo; import com.hnac.hzinfo.sdk.core.response.Result; +import org.springblade.core.log.exception.ServiceException; import org.springblade.core.mp.support.Query; import com.hnac.hzinfo.sdk.v5.soe.SoeDataClient; import lombok.AllArgsConstructor; @@ -42,7 +43,10 @@ public class AlarmServiceImpl implements AlarmService { query.getCurrent(), query.getSize() ); - if(!result.isSuccess() || CollectionUtil.isEmpty(result.getData())){ + if(!result.isSuccess()){ + throw new ServiceException(result.getMsg()); + } + if(CollectionUtil.isEmpty(result.getData())){ return new HashMap<>(); } return result.getData(); diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/history/service/impl/PointServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/history/service/impl/PointServiceImpl.java index 5ea8453..6b488f3 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/history/service/impl/PointServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/history/service/impl/PointServiceImpl.java @@ -15,10 +15,14 @@ import com.hnac.hzinfo.sdk.v5.project.ProjectClient; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springblade.core.log.exception.ServiceException; +import org.springblade.core.tool.api.IResultCode; import org.springblade.core.tool.api.R; +import org.springblade.core.tool.api.ResultCode; import org.springblade.core.tool.utils.CollectionUtil; import org.springframework.stereotype.Service; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -48,7 +52,7 @@ public class PointServiceImpl implements PointService { public List projectFacDevice(String projectId,String attrName) { Result> result = hzFacClient.facDeviceByProjectId(projectId,attrName); if(!result.isSuccess() || CollectionUtil.isEmpty(result.getData())){ - throw new ServiceException(DataResultCode.FAIL,result.getMsg()); + return new ArrayList<>(); } return result.getData(); } @@ -63,7 +67,7 @@ public class PointServiceImpl implements PointService { public List projectFacDeviceAttr(String facDeviceId, String attrName) { Result> result = hzFacClient.facDeviceAttrList(facDeviceId,attrName); if(!result.isSuccess() || CollectionUtil.isEmpty(result.getData())){ - throw new ServiceException(DataResultCode.FAIL,result.getMsg()); + return new ArrayList<>(); } return result.getData(); } @@ -77,7 +81,7 @@ public class PointServiceImpl implements PointService { public List projectDeviceInstance(String projectId,String attrName) { R> result = deviceClient.getOnlineDeviceInstanceSearchName(projectId,attrName); if(!result.isSuccess() || CollectionUtil.isEmpty(result.getData())){ - throw new ServiceException(DataResultCode.FAIL,result.getMsg()); + return new ArrayList<>(); } return result.getData(); } @@ -92,7 +96,7 @@ public class PointServiceImpl implements PointService { public List projectDeviceInstanceAttr(String deviceCode, String attrName) { Result> result = deviceClient.getDeviceAttrByName(deviceCode,attrName); if(!result.isSuccess() || CollectionUtil.isEmpty(result.getData())){ - throw new ServiceException(DataResultCode.FAIL,result.getMsg()); + return new ArrayList<>(); } return result.getData(); } @@ -117,8 +121,11 @@ public class PointServiceImpl implements PointService { curve.getCurrent(), curve.getPageSize() ); - if(!result.isSuccess() || CollectionUtil.isEmpty(result.getData())){ - throw new ServiceException(DataResultCode.FAIL,result.getMsg()); + if(!result.isSuccess()){ + throw new ServiceException(result.getMsg()); + } + if(CollectionUtil.isEmpty(result.getData())){ + return new HashMap<>(); } return result.getData(); } @@ -140,8 +147,11 @@ public class PointServiceImpl implements PointService { curve.getEndTime(), curve.getDimension(), curve.getIntervalType()); - if(!result.isSuccess() || CollectionUtil.isEmpty(result.getData())){ - throw new ServiceException(DataResultCode.FAIL,result.getMsg()); + if(!result.isSuccess()){ + throw new ServiceException(result.getMsg()); + } + if(CollectionUtil.isEmpty(result.getData())){ + return new HashMap<>(); } return result.getData(); }