diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java index 2cd61be..47293b9 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java @@ -1,5 +1,6 @@ package com.newfiber.termite.controller; +import com.newfiber.common.core.exception.ServiceException; import com.newfiber.common.core.utils.poi.ExcelUtil; import com.newfiber.common.core.web.controller.BaseController; import com.newfiber.common.core.web.domain.Result; @@ -72,6 +73,9 @@ @PostMapping("/importExcel") public Result> importExcel(MultipartFile file, String projectCode) throws Exception{ + if(null == file){ + throw new ServiceException("请上传文件"); + } ExcelUtil util = new ExcelUtil<>(DeviceInfoImportRequest.class); List deviceInfoImportRequestList = util.importExcel(file.getInputStream()); DeviceInfoBatchSaveRequest batchSaveRequest = new DeviceInfoBatchSaveRequest(projectCode, deviceInfoImportRequestList); diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java index 2cd61be..47293b9 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java @@ -1,5 +1,6 @@ package com.newfiber.termite.controller; +import com.newfiber.common.core.exception.ServiceException; import com.newfiber.common.core.utils.poi.ExcelUtil; import com.newfiber.common.core.web.controller.BaseController; import com.newfiber.common.core.web.domain.Result; @@ -72,6 +73,9 @@ @PostMapping("/importExcel") public Result> importExcel(MultipartFile file, String projectCode) throws Exception{ + if(null == file){ + throw new ServiceException("请上传文件"); + } ExcelUtil util = new ExcelUtil<>(DeviceInfoImportRequest.class); List deviceInfoImportRequestList = util.importExcel(file.getInputStream()); DeviceInfoBatchSaveRequest batchSaveRequest = new DeviceInfoBatchSaveRequest(projectCode, deviceInfoImportRequestList); diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java index f0bbcba..7a14a13 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java @@ -7,7 +7,6 @@ import com.newfiber.common.log.annotation.Log; import com.newfiber.common.log.enums.BusinessType; import com.newfiber.termite.domain.ProjectInfo; -import com.newfiber.termite.domain.dto.DeviceInfoDto; import com.newfiber.termite.domain.request.ProjectInfoQueryRequest; import com.newfiber.termite.domain.request.ProjectInfoSaveRequest; import com.newfiber.termite.domain.request.ProjectInfoUpdateRequest; @@ -15,11 +14,18 @@ import com.newfiber.termite.service.IProjectInfoService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import org.springframework.web.bind.annotation.*; - +import java.util.List; +import java.util.Set; import javax.annotation.Resource; import javax.validation.Valid; -import java.util.List; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/termiteProject") @@ -101,7 +107,15 @@ return success(list); } - + /** + * 列表查询人员项目 + */ + @GetMapping("/getUserProjectList/{userId}") + @ApiOperation(value = "列表查询人员项目", position = 60) + public Result> list(@PathVariable("userId") Long userId) { + Set list = projectInfoService.getUserProjectList(userId); + return success(list); + } /** * 通过设备SN获取上传地址 diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java index 2cd61be..47293b9 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java @@ -1,5 +1,6 @@ package com.newfiber.termite.controller; +import com.newfiber.common.core.exception.ServiceException; import com.newfiber.common.core.utils.poi.ExcelUtil; import com.newfiber.common.core.web.controller.BaseController; import com.newfiber.common.core.web.domain.Result; @@ -72,6 +73,9 @@ @PostMapping("/importExcel") public Result> importExcel(MultipartFile file, String projectCode) throws Exception{ + if(null == file){ + throw new ServiceException("请上传文件"); + } ExcelUtil util = new ExcelUtil<>(DeviceInfoImportRequest.class); List deviceInfoImportRequestList = util.importExcel(file.getInputStream()); DeviceInfoBatchSaveRequest batchSaveRequest = new DeviceInfoBatchSaveRequest(projectCode, deviceInfoImportRequestList); diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java index f0bbcba..7a14a13 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java @@ -7,7 +7,6 @@ import com.newfiber.common.log.annotation.Log; import com.newfiber.common.log.enums.BusinessType; import com.newfiber.termite.domain.ProjectInfo; -import com.newfiber.termite.domain.dto.DeviceInfoDto; import com.newfiber.termite.domain.request.ProjectInfoQueryRequest; import com.newfiber.termite.domain.request.ProjectInfoSaveRequest; import com.newfiber.termite.domain.request.ProjectInfoUpdateRequest; @@ -15,11 +14,18 @@ import com.newfiber.termite.service.IProjectInfoService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import org.springframework.web.bind.annotation.*; - +import java.util.List; +import java.util.Set; import javax.annotation.Resource; import javax.validation.Valid; -import java.util.List; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/termiteProject") @@ -101,7 +107,15 @@ return success(list); } - + /** + * 列表查询人员项目 + */ + @GetMapping("/getUserProjectList/{userId}") + @ApiOperation(value = "列表查询人员项目", position = 60) + public Result> list(@PathVariable("userId") Long userId) { + Set list = projectInfoService.getUserProjectList(userId); + return success(list); + } /** * 通过设备SN获取上传地址 diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java index ad441f7..eb340bc 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java @@ -122,7 +122,7 @@ @PostMapping("/queryhistoryData") @ApiOperation(value = "查询历史数据", position = 60) public PageResult> queryhistoryData(TermiteHistoryQueryRequest request){ -// startPage(); + startPage(); PageResult> result =termiteService.queryhistoryData(request); return result; } @@ -208,4 +208,13 @@ public Result queryNowWeather(){ return success(termiteService.queryNowWeather()); } + + /** + */ + @PostMapping("/transferMySql2Mongo") + @ApiOperation(value = "termiteService.transferMySql2Mongo()", position = 60) + public Result transferMySql2Mongo(){ + termiteService.transferMySql2Mongo(); + return success(); + } } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java index 2cd61be..47293b9 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java @@ -1,5 +1,6 @@ package com.newfiber.termite.controller; +import com.newfiber.common.core.exception.ServiceException; import com.newfiber.common.core.utils.poi.ExcelUtil; import com.newfiber.common.core.web.controller.BaseController; import com.newfiber.common.core.web.domain.Result; @@ -72,6 +73,9 @@ @PostMapping("/importExcel") public Result> importExcel(MultipartFile file, String projectCode) throws Exception{ + if(null == file){ + throw new ServiceException("请上传文件"); + } ExcelUtil util = new ExcelUtil<>(DeviceInfoImportRequest.class); List deviceInfoImportRequestList = util.importExcel(file.getInputStream()); DeviceInfoBatchSaveRequest batchSaveRequest = new DeviceInfoBatchSaveRequest(projectCode, deviceInfoImportRequestList); diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java index f0bbcba..7a14a13 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java @@ -7,7 +7,6 @@ import com.newfiber.common.log.annotation.Log; import com.newfiber.common.log.enums.BusinessType; import com.newfiber.termite.domain.ProjectInfo; -import com.newfiber.termite.domain.dto.DeviceInfoDto; import com.newfiber.termite.domain.request.ProjectInfoQueryRequest; import com.newfiber.termite.domain.request.ProjectInfoSaveRequest; import com.newfiber.termite.domain.request.ProjectInfoUpdateRequest; @@ -15,11 +14,18 @@ import com.newfiber.termite.service.IProjectInfoService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import org.springframework.web.bind.annotation.*; - +import java.util.List; +import java.util.Set; import javax.annotation.Resource; import javax.validation.Valid; -import java.util.List; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/termiteProject") @@ -101,7 +107,15 @@ return success(list); } - + /** + * 列表查询人员项目 + */ + @GetMapping("/getUserProjectList/{userId}") + @ApiOperation(value = "列表查询人员项目", position = 60) + public Result> list(@PathVariable("userId") Long userId) { + Set list = projectInfoService.getUserProjectList(userId); + return success(list); + } /** * 通过设备SN获取上传地址 diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java index ad441f7..eb340bc 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java @@ -122,7 +122,7 @@ @PostMapping("/queryhistoryData") @ApiOperation(value = "查询历史数据", position = 60) public PageResult> queryhistoryData(TermiteHistoryQueryRequest request){ -// startPage(); + startPage(); PageResult> result =termiteService.queryhistoryData(request); return result; } @@ -208,4 +208,13 @@ public Result queryNowWeather(){ return success(termiteService.queryNowWeather()); } + + /** + */ + @PostMapping("/transferMySql2Mongo") + @ApiOperation(value = "termiteService.transferMySql2Mongo()", position = 60) + public Result transferMySql2Mongo(){ + termiteService.transferMySql2Mongo(); + return success(); + } } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java index bdb88aa..5f79da7 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java @@ -5,9 +5,7 @@ import com.newfiber.common.core.web.domain.BaseEntity; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; -import com.fasterxml.jackson.annotation.JsonFormat; import java.util.Date; -import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; import lombok.EqualsAndHashCode; @@ -136,4 +134,11 @@ @ApiModelProperty(value = "上传地址") private String uploadApi; + /** + * 项目名称 + */ + @TableField(exist = false) + @ApiModelProperty(value = "项目名称") + private String projectName; + } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java index 2cd61be..47293b9 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java @@ -1,5 +1,6 @@ package com.newfiber.termite.controller; +import com.newfiber.common.core.exception.ServiceException; import com.newfiber.common.core.utils.poi.ExcelUtil; import com.newfiber.common.core.web.controller.BaseController; import com.newfiber.common.core.web.domain.Result; @@ -72,6 +73,9 @@ @PostMapping("/importExcel") public Result> importExcel(MultipartFile file, String projectCode) throws Exception{ + if(null == file){ + throw new ServiceException("请上传文件"); + } ExcelUtil util = new ExcelUtil<>(DeviceInfoImportRequest.class); List deviceInfoImportRequestList = util.importExcel(file.getInputStream()); DeviceInfoBatchSaveRequest batchSaveRequest = new DeviceInfoBatchSaveRequest(projectCode, deviceInfoImportRequestList); diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java index f0bbcba..7a14a13 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java @@ -7,7 +7,6 @@ import com.newfiber.common.log.annotation.Log; import com.newfiber.common.log.enums.BusinessType; import com.newfiber.termite.domain.ProjectInfo; -import com.newfiber.termite.domain.dto.DeviceInfoDto; import com.newfiber.termite.domain.request.ProjectInfoQueryRequest; import com.newfiber.termite.domain.request.ProjectInfoSaveRequest; import com.newfiber.termite.domain.request.ProjectInfoUpdateRequest; @@ -15,11 +14,18 @@ import com.newfiber.termite.service.IProjectInfoService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import org.springframework.web.bind.annotation.*; - +import java.util.List; +import java.util.Set; import javax.annotation.Resource; import javax.validation.Valid; -import java.util.List; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/termiteProject") @@ -101,7 +107,15 @@ return success(list); } - + /** + * 列表查询人员项目 + */ + @GetMapping("/getUserProjectList/{userId}") + @ApiOperation(value = "列表查询人员项目", position = 60) + public Result> list(@PathVariable("userId") Long userId) { + Set list = projectInfoService.getUserProjectList(userId); + return success(list); + } /** * 通过设备SN获取上传地址 diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java index ad441f7..eb340bc 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java @@ -122,7 +122,7 @@ @PostMapping("/queryhistoryData") @ApiOperation(value = "查询历史数据", position = 60) public PageResult> queryhistoryData(TermiteHistoryQueryRequest request){ -// startPage(); + startPage(); PageResult> result =termiteService.queryhistoryData(request); return result; } @@ -208,4 +208,13 @@ public Result queryNowWeather(){ return success(termiteService.queryNowWeather()); } + + /** + */ + @PostMapping("/transferMySql2Mongo") + @ApiOperation(value = "termiteService.transferMySql2Mongo()", position = 60) + public Result transferMySql2Mongo(){ + termiteService.transferMySql2Mongo(); + return success(); + } } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java index bdb88aa..5f79da7 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java @@ -5,9 +5,7 @@ import com.newfiber.common.core.web.domain.BaseEntity; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; -import com.fasterxml.jackson.annotation.JsonFormat; import java.util.Date; -import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; import lombok.EqualsAndHashCode; @@ -136,4 +134,11 @@ @ApiModelProperty(value = "上传地址") private String uploadApi; + /** + * 项目名称 + */ + @TableField(exist = false) + @ApiModelProperty(value = "项目名称") + private String projectName; + } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java index fb04bd0..0d6416f 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java @@ -1,9 +1,24 @@ package com.newfiber.termite.domain.dto; +import com.newfiber.termite.domain.DeviceInfo; +import java.util.List; +import java.util.stream.Collectors; import lombok.Data; +import org.apache.commons.collections4.CollectionUtils; @Data public class SnAlarmStatisticDto { private String name; private Number value; + List snList; + List locationList; + + public void setDeviceInfo(List deviceInfoList){ + if(CollectionUtils.isEmpty(deviceInfoList)){ + return; + } + + snList = deviceInfoList.stream().map(DeviceInfo::getSn).collect(Collectors.toList()); + locationList = deviceInfoList.stream().map(DeviceInfo::getLocation).collect(Collectors.toList()); + } } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java index 2cd61be..47293b9 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java @@ -1,5 +1,6 @@ package com.newfiber.termite.controller; +import com.newfiber.common.core.exception.ServiceException; import com.newfiber.common.core.utils.poi.ExcelUtil; import com.newfiber.common.core.web.controller.BaseController; import com.newfiber.common.core.web.domain.Result; @@ -72,6 +73,9 @@ @PostMapping("/importExcel") public Result> importExcel(MultipartFile file, String projectCode) throws Exception{ + if(null == file){ + throw new ServiceException("请上传文件"); + } ExcelUtil util = new ExcelUtil<>(DeviceInfoImportRequest.class); List deviceInfoImportRequestList = util.importExcel(file.getInputStream()); DeviceInfoBatchSaveRequest batchSaveRequest = new DeviceInfoBatchSaveRequest(projectCode, deviceInfoImportRequestList); diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java index f0bbcba..7a14a13 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java @@ -7,7 +7,6 @@ import com.newfiber.common.log.annotation.Log; import com.newfiber.common.log.enums.BusinessType; import com.newfiber.termite.domain.ProjectInfo; -import com.newfiber.termite.domain.dto.DeviceInfoDto; import com.newfiber.termite.domain.request.ProjectInfoQueryRequest; import com.newfiber.termite.domain.request.ProjectInfoSaveRequest; import com.newfiber.termite.domain.request.ProjectInfoUpdateRequest; @@ -15,11 +14,18 @@ import com.newfiber.termite.service.IProjectInfoService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import org.springframework.web.bind.annotation.*; - +import java.util.List; +import java.util.Set; import javax.annotation.Resource; import javax.validation.Valid; -import java.util.List; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/termiteProject") @@ -101,7 +107,15 @@ return success(list); } - + /** + * 列表查询人员项目 + */ + @GetMapping("/getUserProjectList/{userId}") + @ApiOperation(value = "列表查询人员项目", position = 60) + public Result> list(@PathVariable("userId") Long userId) { + Set list = projectInfoService.getUserProjectList(userId); + return success(list); + } /** * 通过设备SN获取上传地址 diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java index ad441f7..eb340bc 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java @@ -122,7 +122,7 @@ @PostMapping("/queryhistoryData") @ApiOperation(value = "查询历史数据", position = 60) public PageResult> queryhistoryData(TermiteHistoryQueryRequest request){ -// startPage(); + startPage(); PageResult> result =termiteService.queryhistoryData(request); return result; } @@ -208,4 +208,13 @@ public Result queryNowWeather(){ return success(termiteService.queryNowWeather()); } + + /** + */ + @PostMapping("/transferMySql2Mongo") + @ApiOperation(value = "termiteService.transferMySql2Mongo()", position = 60) + public Result transferMySql2Mongo(){ + termiteService.transferMySql2Mongo(); + return success(); + } } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java index bdb88aa..5f79da7 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java @@ -5,9 +5,7 @@ import com.newfiber.common.core.web.domain.BaseEntity; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; -import com.fasterxml.jackson.annotation.JsonFormat; import java.util.Date; -import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; import lombok.EqualsAndHashCode; @@ -136,4 +134,11 @@ @ApiModelProperty(value = "上传地址") private String uploadApi; + /** + * 项目名称 + */ + @TableField(exist = false) + @ApiModelProperty(value = "项目名称") + private String projectName; + } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java index fb04bd0..0d6416f 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java @@ -1,9 +1,24 @@ package com.newfiber.termite.domain.dto; +import com.newfiber.termite.domain.DeviceInfo; +import java.util.List; +import java.util.stream.Collectors; import lombok.Data; +import org.apache.commons.collections4.CollectionUtils; @Data public class SnAlarmStatisticDto { private String name; private Number value; + List snList; + List locationList; + + public void setDeviceInfo(List deviceInfoList){ + if(CollectionUtils.isEmpty(deviceInfoList)){ + return; + } + + snList = deviceInfoList.stream().map(DeviceInfo::getSn).collect(Collectors.toList()); + locationList = deviceInfoList.stream().map(DeviceInfo::getLocation).collect(Collectors.toList()); + } } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/request/TermiteHistoryQueryRequest.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/request/TermiteHistoryQueryRequest.java index 2cb9cef..ab1f689 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/request/TermiteHistoryQueryRequest.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/request/TermiteHistoryQueryRequest.java @@ -25,4 +25,11 @@ @ApiModelProperty(value = "结束时间") private String endtime; + + /** + * 分类(生产 production | 项目 project) + */ + @ApiModelProperty(value = "分类(生产 production | 项目 project)") + private String category = "project"; + } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java index 2cd61be..47293b9 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java @@ -1,5 +1,6 @@ package com.newfiber.termite.controller; +import com.newfiber.common.core.exception.ServiceException; import com.newfiber.common.core.utils.poi.ExcelUtil; import com.newfiber.common.core.web.controller.BaseController; import com.newfiber.common.core.web.domain.Result; @@ -72,6 +73,9 @@ @PostMapping("/importExcel") public Result> importExcel(MultipartFile file, String projectCode) throws Exception{ + if(null == file){ + throw new ServiceException("请上传文件"); + } ExcelUtil util = new ExcelUtil<>(DeviceInfoImportRequest.class); List deviceInfoImportRequestList = util.importExcel(file.getInputStream()); DeviceInfoBatchSaveRequest batchSaveRequest = new DeviceInfoBatchSaveRequest(projectCode, deviceInfoImportRequestList); diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java index f0bbcba..7a14a13 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java @@ -7,7 +7,6 @@ import com.newfiber.common.log.annotation.Log; import com.newfiber.common.log.enums.BusinessType; import com.newfiber.termite.domain.ProjectInfo; -import com.newfiber.termite.domain.dto.DeviceInfoDto; import com.newfiber.termite.domain.request.ProjectInfoQueryRequest; import com.newfiber.termite.domain.request.ProjectInfoSaveRequest; import com.newfiber.termite.domain.request.ProjectInfoUpdateRequest; @@ -15,11 +14,18 @@ import com.newfiber.termite.service.IProjectInfoService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import org.springframework.web.bind.annotation.*; - +import java.util.List; +import java.util.Set; import javax.annotation.Resource; import javax.validation.Valid; -import java.util.List; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/termiteProject") @@ -101,7 +107,15 @@ return success(list); } - + /** + * 列表查询人员项目 + */ + @GetMapping("/getUserProjectList/{userId}") + @ApiOperation(value = "列表查询人员项目", position = 60) + public Result> list(@PathVariable("userId") Long userId) { + Set list = projectInfoService.getUserProjectList(userId); + return success(list); + } /** * 通过设备SN获取上传地址 diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java index ad441f7..eb340bc 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java @@ -122,7 +122,7 @@ @PostMapping("/queryhistoryData") @ApiOperation(value = "查询历史数据", position = 60) public PageResult> queryhistoryData(TermiteHistoryQueryRequest request){ -// startPage(); + startPage(); PageResult> result =termiteService.queryhistoryData(request); return result; } @@ -208,4 +208,13 @@ public Result queryNowWeather(){ return success(termiteService.queryNowWeather()); } + + /** + */ + @PostMapping("/transferMySql2Mongo") + @ApiOperation(value = "termiteService.transferMySql2Mongo()", position = 60) + public Result transferMySql2Mongo(){ + termiteService.transferMySql2Mongo(); + return success(); + } } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java index bdb88aa..5f79da7 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java @@ -5,9 +5,7 @@ import com.newfiber.common.core.web.domain.BaseEntity; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; -import com.fasterxml.jackson.annotation.JsonFormat; import java.util.Date; -import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; import lombok.EqualsAndHashCode; @@ -136,4 +134,11 @@ @ApiModelProperty(value = "上传地址") private String uploadApi; + /** + * 项目名称 + */ + @TableField(exist = false) + @ApiModelProperty(value = "项目名称") + private String projectName; + } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java index fb04bd0..0d6416f 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java @@ -1,9 +1,24 @@ package com.newfiber.termite.domain.dto; +import com.newfiber.termite.domain.DeviceInfo; +import java.util.List; +import java.util.stream.Collectors; import lombok.Data; +import org.apache.commons.collections4.CollectionUtils; @Data public class SnAlarmStatisticDto { private String name; private Number value; + List snList; + List locationList; + + public void setDeviceInfo(List deviceInfoList){ + if(CollectionUtils.isEmpty(deviceInfoList)){ + return; + } + + snList = deviceInfoList.stream().map(DeviceInfo::getSn).collect(Collectors.toList()); + locationList = deviceInfoList.stream().map(DeviceInfo::getLocation).collect(Collectors.toList()); + } } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/request/TermiteHistoryQueryRequest.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/request/TermiteHistoryQueryRequest.java index 2cb9cef..ab1f689 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/request/TermiteHistoryQueryRequest.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/request/TermiteHistoryQueryRequest.java @@ -25,4 +25,11 @@ @ApiModelProperty(value = "结束时间") private String endtime; + + /** + * 分类(生产 production | 项目 project) + */ + @ApiModelProperty(value = "分类(生产 production | 项目 project)") + private String category = "project"; + } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IDeviceInfoService.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IDeviceInfoService.java index 51515d8..9c03500 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IDeviceInfoService.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IDeviceInfoService.java @@ -81,6 +81,14 @@ */ DeviceInfo selectDetail(String sn); + /** + * 详细查询设备信息 + * + * @param id 主键 + * @return 设备信息 + */ + DeviceInfo selectDetailByCategory(String category, String sn); + /** * 分页查询设备信息 * diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java index 2cd61be..47293b9 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java @@ -1,5 +1,6 @@ package com.newfiber.termite.controller; +import com.newfiber.common.core.exception.ServiceException; import com.newfiber.common.core.utils.poi.ExcelUtil; import com.newfiber.common.core.web.controller.BaseController; import com.newfiber.common.core.web.domain.Result; @@ -72,6 +73,9 @@ @PostMapping("/importExcel") public Result> importExcel(MultipartFile file, String projectCode) throws Exception{ + if(null == file){ + throw new ServiceException("请上传文件"); + } ExcelUtil util = new ExcelUtil<>(DeviceInfoImportRequest.class); List deviceInfoImportRequestList = util.importExcel(file.getInputStream()); DeviceInfoBatchSaveRequest batchSaveRequest = new DeviceInfoBatchSaveRequest(projectCode, deviceInfoImportRequestList); diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java index f0bbcba..7a14a13 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java @@ -7,7 +7,6 @@ import com.newfiber.common.log.annotation.Log; import com.newfiber.common.log.enums.BusinessType; import com.newfiber.termite.domain.ProjectInfo; -import com.newfiber.termite.domain.dto.DeviceInfoDto; import com.newfiber.termite.domain.request.ProjectInfoQueryRequest; import com.newfiber.termite.domain.request.ProjectInfoSaveRequest; import com.newfiber.termite.domain.request.ProjectInfoUpdateRequest; @@ -15,11 +14,18 @@ import com.newfiber.termite.service.IProjectInfoService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import org.springframework.web.bind.annotation.*; - +import java.util.List; +import java.util.Set; import javax.annotation.Resource; import javax.validation.Valid; -import java.util.List; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/termiteProject") @@ -101,7 +107,15 @@ return success(list); } - + /** + * 列表查询人员项目 + */ + @GetMapping("/getUserProjectList/{userId}") + @ApiOperation(value = "列表查询人员项目", position = 60) + public Result> list(@PathVariable("userId") Long userId) { + Set list = projectInfoService.getUserProjectList(userId); + return success(list); + } /** * 通过设备SN获取上传地址 diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java index ad441f7..eb340bc 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java @@ -122,7 +122,7 @@ @PostMapping("/queryhistoryData") @ApiOperation(value = "查询历史数据", position = 60) public PageResult> queryhistoryData(TermiteHistoryQueryRequest request){ -// startPage(); + startPage(); PageResult> result =termiteService.queryhistoryData(request); return result; } @@ -208,4 +208,13 @@ public Result queryNowWeather(){ return success(termiteService.queryNowWeather()); } + + /** + */ + @PostMapping("/transferMySql2Mongo") + @ApiOperation(value = "termiteService.transferMySql2Mongo()", position = 60) + public Result transferMySql2Mongo(){ + termiteService.transferMySql2Mongo(); + return success(); + } } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java index bdb88aa..5f79da7 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java @@ -5,9 +5,7 @@ import com.newfiber.common.core.web.domain.BaseEntity; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; -import com.fasterxml.jackson.annotation.JsonFormat; import java.util.Date; -import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; import lombok.EqualsAndHashCode; @@ -136,4 +134,11 @@ @ApiModelProperty(value = "上传地址") private String uploadApi; + /** + * 项目名称 + */ + @TableField(exist = false) + @ApiModelProperty(value = "项目名称") + private String projectName; + } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java index fb04bd0..0d6416f 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java @@ -1,9 +1,24 @@ package com.newfiber.termite.domain.dto; +import com.newfiber.termite.domain.DeviceInfo; +import java.util.List; +import java.util.stream.Collectors; import lombok.Data; +import org.apache.commons.collections4.CollectionUtils; @Data public class SnAlarmStatisticDto { private String name; private Number value; + List snList; + List locationList; + + public void setDeviceInfo(List deviceInfoList){ + if(CollectionUtils.isEmpty(deviceInfoList)){ + return; + } + + snList = deviceInfoList.stream().map(DeviceInfo::getSn).collect(Collectors.toList()); + locationList = deviceInfoList.stream().map(DeviceInfo::getLocation).collect(Collectors.toList()); + } } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/request/TermiteHistoryQueryRequest.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/request/TermiteHistoryQueryRequest.java index 2cb9cef..ab1f689 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/request/TermiteHistoryQueryRequest.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/request/TermiteHistoryQueryRequest.java @@ -25,4 +25,11 @@ @ApiModelProperty(value = "结束时间") private String endtime; + + /** + * 分类(生产 production | 项目 project) + */ + @ApiModelProperty(value = "分类(生产 production | 项目 project)") + private String category = "project"; + } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IDeviceInfoService.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IDeviceInfoService.java index 51515d8..9c03500 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IDeviceInfoService.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IDeviceInfoService.java @@ -81,6 +81,14 @@ */ DeviceInfo selectDetail(String sn); + /** + * 详细查询设备信息 + * + * @param id 主键 + * @return 设备信息 + */ + DeviceInfo selectDetailByCategory(String category, String sn); + /** * 分页查询设备信息 * diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IProjectInfoService.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IProjectInfoService.java index e476c09..eed1f59 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IProjectInfoService.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IProjectInfoService.java @@ -4,7 +4,6 @@ import com.newfiber.termite.domain.request.ProjectInfoQueryRequest; import com.newfiber.termite.domain.request.ProjectInfoSaveRequest; import com.newfiber.termite.domain.request.ProjectInfoUpdateRequest; - import java.util.List; import java.util.Set; @@ -71,4 +70,6 @@ Set getUserProjectCodeList(Long userId); + Set getUserProjectList(Long userId); + } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java index 2cd61be..47293b9 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java @@ -1,5 +1,6 @@ package com.newfiber.termite.controller; +import com.newfiber.common.core.exception.ServiceException; import com.newfiber.common.core.utils.poi.ExcelUtil; import com.newfiber.common.core.web.controller.BaseController; import com.newfiber.common.core.web.domain.Result; @@ -72,6 +73,9 @@ @PostMapping("/importExcel") public Result> importExcel(MultipartFile file, String projectCode) throws Exception{ + if(null == file){ + throw new ServiceException("请上传文件"); + } ExcelUtil util = new ExcelUtil<>(DeviceInfoImportRequest.class); List deviceInfoImportRequestList = util.importExcel(file.getInputStream()); DeviceInfoBatchSaveRequest batchSaveRequest = new DeviceInfoBatchSaveRequest(projectCode, deviceInfoImportRequestList); diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java index f0bbcba..7a14a13 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java @@ -7,7 +7,6 @@ import com.newfiber.common.log.annotation.Log; import com.newfiber.common.log.enums.BusinessType; import com.newfiber.termite.domain.ProjectInfo; -import com.newfiber.termite.domain.dto.DeviceInfoDto; import com.newfiber.termite.domain.request.ProjectInfoQueryRequest; import com.newfiber.termite.domain.request.ProjectInfoSaveRequest; import com.newfiber.termite.domain.request.ProjectInfoUpdateRequest; @@ -15,11 +14,18 @@ import com.newfiber.termite.service.IProjectInfoService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import org.springframework.web.bind.annotation.*; - +import java.util.List; +import java.util.Set; import javax.annotation.Resource; import javax.validation.Valid; -import java.util.List; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/termiteProject") @@ -101,7 +107,15 @@ return success(list); } - + /** + * 列表查询人员项目 + */ + @GetMapping("/getUserProjectList/{userId}") + @ApiOperation(value = "列表查询人员项目", position = 60) + public Result> list(@PathVariable("userId") Long userId) { + Set list = projectInfoService.getUserProjectList(userId); + return success(list); + } /** * 通过设备SN获取上传地址 diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java index ad441f7..eb340bc 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java @@ -122,7 +122,7 @@ @PostMapping("/queryhistoryData") @ApiOperation(value = "查询历史数据", position = 60) public PageResult> queryhistoryData(TermiteHistoryQueryRequest request){ -// startPage(); + startPage(); PageResult> result =termiteService.queryhistoryData(request); return result; } @@ -208,4 +208,13 @@ public Result queryNowWeather(){ return success(termiteService.queryNowWeather()); } + + /** + */ + @PostMapping("/transferMySql2Mongo") + @ApiOperation(value = "termiteService.transferMySql2Mongo()", position = 60) + public Result transferMySql2Mongo(){ + termiteService.transferMySql2Mongo(); + return success(); + } } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java index bdb88aa..5f79da7 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java @@ -5,9 +5,7 @@ import com.newfiber.common.core.web.domain.BaseEntity; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; -import com.fasterxml.jackson.annotation.JsonFormat; import java.util.Date; -import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; import lombok.EqualsAndHashCode; @@ -136,4 +134,11 @@ @ApiModelProperty(value = "上传地址") private String uploadApi; + /** + * 项目名称 + */ + @TableField(exist = false) + @ApiModelProperty(value = "项目名称") + private String projectName; + } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java index fb04bd0..0d6416f 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java @@ -1,9 +1,24 @@ package com.newfiber.termite.domain.dto; +import com.newfiber.termite.domain.DeviceInfo; +import java.util.List; +import java.util.stream.Collectors; import lombok.Data; +import org.apache.commons.collections4.CollectionUtils; @Data public class SnAlarmStatisticDto { private String name; private Number value; + List snList; + List locationList; + + public void setDeviceInfo(List deviceInfoList){ + if(CollectionUtils.isEmpty(deviceInfoList)){ + return; + } + + snList = deviceInfoList.stream().map(DeviceInfo::getSn).collect(Collectors.toList()); + locationList = deviceInfoList.stream().map(DeviceInfo::getLocation).collect(Collectors.toList()); + } } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/request/TermiteHistoryQueryRequest.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/request/TermiteHistoryQueryRequest.java index 2cb9cef..ab1f689 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/request/TermiteHistoryQueryRequest.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/request/TermiteHistoryQueryRequest.java @@ -25,4 +25,11 @@ @ApiModelProperty(value = "结束时间") private String endtime; + + /** + * 分类(生产 production | 项目 project) + */ + @ApiModelProperty(value = "分类(生产 production | 项目 project)") + private String category = "project"; + } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IDeviceInfoService.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IDeviceInfoService.java index 51515d8..9c03500 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IDeviceInfoService.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IDeviceInfoService.java @@ -81,6 +81,14 @@ */ DeviceInfo selectDetail(String sn); + /** + * 详细查询设备信息 + * + * @param id 主键 + * @return 设备信息 + */ + DeviceInfo selectDetailByCategory(String category, String sn); + /** * 分页查询设备信息 * diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IProjectInfoService.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IProjectInfoService.java index e476c09..eed1f59 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IProjectInfoService.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IProjectInfoService.java @@ -4,7 +4,6 @@ import com.newfiber.termite.domain.request.ProjectInfoQueryRequest; import com.newfiber.termite.domain.request.ProjectInfoSaveRequest; import com.newfiber.termite.domain.request.ProjectInfoUpdateRequest; - import java.util.List; import java.util.Set; @@ -71,4 +70,6 @@ Set getUserProjectCodeList(Long userId); + Set getUserProjectList(Long userId); + } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceInfoServiceImpl.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceInfoServiceImpl.java index 063d4e7..21280ad 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceInfoServiceImpl.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceInfoServiceImpl.java @@ -146,6 +146,18 @@ return null; } + @Override + public DeviceInfo selectDetailByCategory(String category, String sn) { + DeviceInfoQueryRequest request = new DeviceInfoQueryRequest(); + request.setCategory(category); + request.setSn(sn); + List deviceInfoList = selectList(request); + if(CollectionUtils.isNotEmpty(deviceInfoList)){ + return deviceInfoList.get(0); + } + return null; + } + public DeviceInfo selectDetail(String sn, String projectCode) { DeviceInfoQueryRequest request = new DeviceInfoQueryRequest(); request.setCategory(EDeviceCategory.project.getCode()); diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java index 2cd61be..47293b9 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java @@ -1,5 +1,6 @@ package com.newfiber.termite.controller; +import com.newfiber.common.core.exception.ServiceException; import com.newfiber.common.core.utils.poi.ExcelUtil; import com.newfiber.common.core.web.controller.BaseController; import com.newfiber.common.core.web.domain.Result; @@ -72,6 +73,9 @@ @PostMapping("/importExcel") public Result> importExcel(MultipartFile file, String projectCode) throws Exception{ + if(null == file){ + throw new ServiceException("请上传文件"); + } ExcelUtil util = new ExcelUtil<>(DeviceInfoImportRequest.class); List deviceInfoImportRequestList = util.importExcel(file.getInputStream()); DeviceInfoBatchSaveRequest batchSaveRequest = new DeviceInfoBatchSaveRequest(projectCode, deviceInfoImportRequestList); diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java index f0bbcba..7a14a13 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java @@ -7,7 +7,6 @@ import com.newfiber.common.log.annotation.Log; import com.newfiber.common.log.enums.BusinessType; import com.newfiber.termite.domain.ProjectInfo; -import com.newfiber.termite.domain.dto.DeviceInfoDto; import com.newfiber.termite.domain.request.ProjectInfoQueryRequest; import com.newfiber.termite.domain.request.ProjectInfoSaveRequest; import com.newfiber.termite.domain.request.ProjectInfoUpdateRequest; @@ -15,11 +14,18 @@ import com.newfiber.termite.service.IProjectInfoService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import org.springframework.web.bind.annotation.*; - +import java.util.List; +import java.util.Set; import javax.annotation.Resource; import javax.validation.Valid; -import java.util.List; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/termiteProject") @@ -101,7 +107,15 @@ return success(list); } - + /** + * 列表查询人员项目 + */ + @GetMapping("/getUserProjectList/{userId}") + @ApiOperation(value = "列表查询人员项目", position = 60) + public Result> list(@PathVariable("userId") Long userId) { + Set list = projectInfoService.getUserProjectList(userId); + return success(list); + } /** * 通过设备SN获取上传地址 diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java index ad441f7..eb340bc 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java @@ -122,7 +122,7 @@ @PostMapping("/queryhistoryData") @ApiOperation(value = "查询历史数据", position = 60) public PageResult> queryhistoryData(TermiteHistoryQueryRequest request){ -// startPage(); + startPage(); PageResult> result =termiteService.queryhistoryData(request); return result; } @@ -208,4 +208,13 @@ public Result queryNowWeather(){ return success(termiteService.queryNowWeather()); } + + /** + */ + @PostMapping("/transferMySql2Mongo") + @ApiOperation(value = "termiteService.transferMySql2Mongo()", position = 60) + public Result transferMySql2Mongo(){ + termiteService.transferMySql2Mongo(); + return success(); + } } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java index bdb88aa..5f79da7 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java @@ -5,9 +5,7 @@ import com.newfiber.common.core.web.domain.BaseEntity; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; -import com.fasterxml.jackson.annotation.JsonFormat; import java.util.Date; -import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; import lombok.EqualsAndHashCode; @@ -136,4 +134,11 @@ @ApiModelProperty(value = "上传地址") private String uploadApi; + /** + * 项目名称 + */ + @TableField(exist = false) + @ApiModelProperty(value = "项目名称") + private String projectName; + } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java index fb04bd0..0d6416f 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java @@ -1,9 +1,24 @@ package com.newfiber.termite.domain.dto; +import com.newfiber.termite.domain.DeviceInfo; +import java.util.List; +import java.util.stream.Collectors; import lombok.Data; +import org.apache.commons.collections4.CollectionUtils; @Data public class SnAlarmStatisticDto { private String name; private Number value; + List snList; + List locationList; + + public void setDeviceInfo(List deviceInfoList){ + if(CollectionUtils.isEmpty(deviceInfoList)){ + return; + } + + snList = deviceInfoList.stream().map(DeviceInfo::getSn).collect(Collectors.toList()); + locationList = deviceInfoList.stream().map(DeviceInfo::getLocation).collect(Collectors.toList()); + } } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/request/TermiteHistoryQueryRequest.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/request/TermiteHistoryQueryRequest.java index 2cb9cef..ab1f689 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/request/TermiteHistoryQueryRequest.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/request/TermiteHistoryQueryRequest.java @@ -25,4 +25,11 @@ @ApiModelProperty(value = "结束时间") private String endtime; + + /** + * 分类(生产 production | 项目 project) + */ + @ApiModelProperty(value = "分类(生产 production | 项目 project)") + private String category = "project"; + } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IDeviceInfoService.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IDeviceInfoService.java index 51515d8..9c03500 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IDeviceInfoService.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IDeviceInfoService.java @@ -81,6 +81,14 @@ */ DeviceInfo selectDetail(String sn); + /** + * 详细查询设备信息 + * + * @param id 主键 + * @return 设备信息 + */ + DeviceInfo selectDetailByCategory(String category, String sn); + /** * 分页查询设备信息 * diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IProjectInfoService.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IProjectInfoService.java index e476c09..eed1f59 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IProjectInfoService.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IProjectInfoService.java @@ -4,7 +4,6 @@ import com.newfiber.termite.domain.request.ProjectInfoQueryRequest; import com.newfiber.termite.domain.request.ProjectInfoSaveRequest; import com.newfiber.termite.domain.request.ProjectInfoUpdateRequest; - import java.util.List; import java.util.Set; @@ -71,4 +70,6 @@ Set getUserProjectCodeList(Long userId); + Set getUserProjectList(Long userId); + } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceInfoServiceImpl.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceInfoServiceImpl.java index 063d4e7..21280ad 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceInfoServiceImpl.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceInfoServiceImpl.java @@ -146,6 +146,18 @@ return null; } + @Override + public DeviceInfo selectDetailByCategory(String category, String sn) { + DeviceInfoQueryRequest request = new DeviceInfoQueryRequest(); + request.setCategory(category); + request.setSn(sn); + List deviceInfoList = selectList(request); + if(CollectionUtils.isNotEmpty(deviceInfoList)){ + return deviceInfoList.get(0); + } + return null; + } + public DeviceInfo selectDetail(String sn, String projectCode) { DeviceInfoQueryRequest request = new DeviceInfoQueryRequest(); request.setCategory(EDeviceCategory.project.getCode()); diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceMonitoringDataServiceImpl.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceMonitoringDataServiceImpl.java index 85ccf9b..190169b 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceMonitoringDataServiceImpl.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceMonitoringDataServiceImpl.java @@ -1,5 +1,6 @@ package com.newfiber.termite.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.newfiber.common.core.exception.ServiceException; import com.newfiber.common.core.web.domain.BaseEntity; import com.newfiber.common.core.web.service.BaseServiceImpl; @@ -15,10 +16,7 @@ import java.util.Optional; import javax.annotation.Resource; import org.springframework.beans.BeanUtils; -import org.springframework.data.domain.Sort; import org.springframework.data.mongodb.core.MongoTemplate; -import org.springframework.data.mongodb.core.query.Criteria; -import org.springframework.data.mongodb.core.query.Query; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -77,28 +75,28 @@ @Override public DeviceMonitoringData lastDruging(String sn) { - Query query = new Query().with(Sort.by(Sort.Direction.DESC,"druing_datetime")). - addCriteria(Criteria.where("druing").ne(EDrugFlag.False.getCode())); - return mongoTemplate.findOne(query, DeviceMonitoringData.class, sn); +// Query query = new Query().with(Sort.by(Sort.Direction.DESC,"druing_datetime")). +// addCriteria(Criteria.where("druing").ne(EDrugFlag.False.getCode())); +// return mongoTemplate.findOne(query, DeviceMonitoringData.class, sn); // -// QueryWrapper queryWrapper = new QueryWrapper(). -// eq("sn", sn). -// ne("druing", EDrugFlag.False.getCode()). -// orderByDesc("druing_datetime").last("limit 1"); -// return getOne(queryWrapper); + QueryWrapper queryWrapper = new QueryWrapper(). + eq("sn", sn). + ne("druing", EDrugFlag.False.getCode()). + orderByDesc("druing_datetime").last("limit 1"); + return getOne(queryWrapper); } @Override public DeviceMonitoringData lastHeating(String sn) { - Query query = new Query().with(Sort.by(Sort.Direction.DESC,"heating_datetime")). - addCriteria(Criteria.where("heating").is(EHeatingFlag.True.getCode())); - return mongoTemplate.findOne(query, DeviceMonitoringData.class, sn); +// Query query = new Query().with(Sort.by(Sort.Direction.DESC,"heating_datetime")). +// addCriteria(Criteria.where("heating").is(EHeatingFlag.True.getCode())); +// return mongoTemplate.findOne(query, DeviceMonitoringData.class, sn); -// QueryWrapper queryWrapper = new QueryWrapper(). -// eq("sn", sn). -// eq("heating", EHeatingFlag.True.getCode()). -// orderByDesc("heating_datetime").last("limit 1"); -// return getOne(queryWrapper); + QueryWrapper queryWrapper = new QueryWrapper(). + eq("sn", sn). + eq("heating", EHeatingFlag.True.getCode()). + orderByDesc("heating_datetime").last("limit 1"); + return getOne(queryWrapper); } @Override @@ -113,14 +111,14 @@ @Override public List selectList(String sn, String startDate, String endDate) { - Query query = new Query().with(Sort.by(Sort.Direction.DESC,"date")). - addCriteria(Criteria.where("date").gte(startDate)).addCriteria(Criteria.where("date").lte(endDate)); - return mongoTemplate.find(query, DeviceMonitoringData.class, sn); +// Query query = new Query().with(Sort.by(Sort.Direction.DESC,"date")). +// addCriteria(Criteria.where("date").gte(startDate)).addCriteria(Criteria.where("date").lte(endDate)); +// return mongoTemplate.find(query, DeviceMonitoringData.class, sn); -// QueryWrapper queryWrapper = new QueryWrapper(). -// eq("sn", sn). -// ge("date", startDate).le("date", endDate).orderByDesc("date"); -// return list(queryWrapper); + QueryWrapper queryWrapper = new QueryWrapper(). + eq("sn", sn). + ge("date", startDate).le("date", endDate).orderByDesc("date"); + return list(queryWrapper); } @Override diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java index 2cd61be..47293b9 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java @@ -1,5 +1,6 @@ package com.newfiber.termite.controller; +import com.newfiber.common.core.exception.ServiceException; import com.newfiber.common.core.utils.poi.ExcelUtil; import com.newfiber.common.core.web.controller.BaseController; import com.newfiber.common.core.web.domain.Result; @@ -72,6 +73,9 @@ @PostMapping("/importExcel") public Result> importExcel(MultipartFile file, String projectCode) throws Exception{ + if(null == file){ + throw new ServiceException("请上传文件"); + } ExcelUtil util = new ExcelUtil<>(DeviceInfoImportRequest.class); List deviceInfoImportRequestList = util.importExcel(file.getInputStream()); DeviceInfoBatchSaveRequest batchSaveRequest = new DeviceInfoBatchSaveRequest(projectCode, deviceInfoImportRequestList); diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java index f0bbcba..7a14a13 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java @@ -7,7 +7,6 @@ import com.newfiber.common.log.annotation.Log; import com.newfiber.common.log.enums.BusinessType; import com.newfiber.termite.domain.ProjectInfo; -import com.newfiber.termite.domain.dto.DeviceInfoDto; import com.newfiber.termite.domain.request.ProjectInfoQueryRequest; import com.newfiber.termite.domain.request.ProjectInfoSaveRequest; import com.newfiber.termite.domain.request.ProjectInfoUpdateRequest; @@ -15,11 +14,18 @@ import com.newfiber.termite.service.IProjectInfoService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import org.springframework.web.bind.annotation.*; - +import java.util.List; +import java.util.Set; import javax.annotation.Resource; import javax.validation.Valid; -import java.util.List; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/termiteProject") @@ -101,7 +107,15 @@ return success(list); } - + /** + * 列表查询人员项目 + */ + @GetMapping("/getUserProjectList/{userId}") + @ApiOperation(value = "列表查询人员项目", position = 60) + public Result> list(@PathVariable("userId") Long userId) { + Set list = projectInfoService.getUserProjectList(userId); + return success(list); + } /** * 通过设备SN获取上传地址 diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java index ad441f7..eb340bc 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java @@ -122,7 +122,7 @@ @PostMapping("/queryhistoryData") @ApiOperation(value = "查询历史数据", position = 60) public PageResult> queryhistoryData(TermiteHistoryQueryRequest request){ -// startPage(); + startPage(); PageResult> result =termiteService.queryhistoryData(request); return result; } @@ -208,4 +208,13 @@ public Result queryNowWeather(){ return success(termiteService.queryNowWeather()); } + + /** + */ + @PostMapping("/transferMySql2Mongo") + @ApiOperation(value = "termiteService.transferMySql2Mongo()", position = 60) + public Result transferMySql2Mongo(){ + termiteService.transferMySql2Mongo(); + return success(); + } } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java index bdb88aa..5f79da7 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java @@ -5,9 +5,7 @@ import com.newfiber.common.core.web.domain.BaseEntity; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; -import com.fasterxml.jackson.annotation.JsonFormat; import java.util.Date; -import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; import lombok.EqualsAndHashCode; @@ -136,4 +134,11 @@ @ApiModelProperty(value = "上传地址") private String uploadApi; + /** + * 项目名称 + */ + @TableField(exist = false) + @ApiModelProperty(value = "项目名称") + private String projectName; + } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java index fb04bd0..0d6416f 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java @@ -1,9 +1,24 @@ package com.newfiber.termite.domain.dto; +import com.newfiber.termite.domain.DeviceInfo; +import java.util.List; +import java.util.stream.Collectors; import lombok.Data; +import org.apache.commons.collections4.CollectionUtils; @Data public class SnAlarmStatisticDto { private String name; private Number value; + List snList; + List locationList; + + public void setDeviceInfo(List deviceInfoList){ + if(CollectionUtils.isEmpty(deviceInfoList)){ + return; + } + + snList = deviceInfoList.stream().map(DeviceInfo::getSn).collect(Collectors.toList()); + locationList = deviceInfoList.stream().map(DeviceInfo::getLocation).collect(Collectors.toList()); + } } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/request/TermiteHistoryQueryRequest.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/request/TermiteHistoryQueryRequest.java index 2cb9cef..ab1f689 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/request/TermiteHistoryQueryRequest.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/request/TermiteHistoryQueryRequest.java @@ -25,4 +25,11 @@ @ApiModelProperty(value = "结束时间") private String endtime; + + /** + * 分类(生产 production | 项目 project) + */ + @ApiModelProperty(value = "分类(生产 production | 项目 project)") + private String category = "project"; + } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IDeviceInfoService.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IDeviceInfoService.java index 51515d8..9c03500 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IDeviceInfoService.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IDeviceInfoService.java @@ -81,6 +81,14 @@ */ DeviceInfo selectDetail(String sn); + /** + * 详细查询设备信息 + * + * @param id 主键 + * @return 设备信息 + */ + DeviceInfo selectDetailByCategory(String category, String sn); + /** * 分页查询设备信息 * diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IProjectInfoService.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IProjectInfoService.java index e476c09..eed1f59 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IProjectInfoService.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IProjectInfoService.java @@ -4,7 +4,6 @@ import com.newfiber.termite.domain.request.ProjectInfoQueryRequest; import com.newfiber.termite.domain.request.ProjectInfoSaveRequest; import com.newfiber.termite.domain.request.ProjectInfoUpdateRequest; - import java.util.List; import java.util.Set; @@ -71,4 +70,6 @@ Set getUserProjectCodeList(Long userId); + Set getUserProjectList(Long userId); + } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceInfoServiceImpl.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceInfoServiceImpl.java index 063d4e7..21280ad 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceInfoServiceImpl.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceInfoServiceImpl.java @@ -146,6 +146,18 @@ return null; } + @Override + public DeviceInfo selectDetailByCategory(String category, String sn) { + DeviceInfoQueryRequest request = new DeviceInfoQueryRequest(); + request.setCategory(category); + request.setSn(sn); + List deviceInfoList = selectList(request); + if(CollectionUtils.isNotEmpty(deviceInfoList)){ + return deviceInfoList.get(0); + } + return null; + } + public DeviceInfo selectDetail(String sn, String projectCode) { DeviceInfoQueryRequest request = new DeviceInfoQueryRequest(); request.setCategory(EDeviceCategory.project.getCode()); diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceMonitoringDataServiceImpl.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceMonitoringDataServiceImpl.java index 85ccf9b..190169b 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceMonitoringDataServiceImpl.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceMonitoringDataServiceImpl.java @@ -1,5 +1,6 @@ package com.newfiber.termite.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.newfiber.common.core.exception.ServiceException; import com.newfiber.common.core.web.domain.BaseEntity; import com.newfiber.common.core.web.service.BaseServiceImpl; @@ -15,10 +16,7 @@ import java.util.Optional; import javax.annotation.Resource; import org.springframework.beans.BeanUtils; -import org.springframework.data.domain.Sort; import org.springframework.data.mongodb.core.MongoTemplate; -import org.springframework.data.mongodb.core.query.Criteria; -import org.springframework.data.mongodb.core.query.Query; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -77,28 +75,28 @@ @Override public DeviceMonitoringData lastDruging(String sn) { - Query query = new Query().with(Sort.by(Sort.Direction.DESC,"druing_datetime")). - addCriteria(Criteria.where("druing").ne(EDrugFlag.False.getCode())); - return mongoTemplate.findOne(query, DeviceMonitoringData.class, sn); +// Query query = new Query().with(Sort.by(Sort.Direction.DESC,"druing_datetime")). +// addCriteria(Criteria.where("druing").ne(EDrugFlag.False.getCode())); +// return mongoTemplate.findOne(query, DeviceMonitoringData.class, sn); // -// QueryWrapper queryWrapper = new QueryWrapper(). -// eq("sn", sn). -// ne("druing", EDrugFlag.False.getCode()). -// orderByDesc("druing_datetime").last("limit 1"); -// return getOne(queryWrapper); + QueryWrapper queryWrapper = new QueryWrapper(). + eq("sn", sn). + ne("druing", EDrugFlag.False.getCode()). + orderByDesc("druing_datetime").last("limit 1"); + return getOne(queryWrapper); } @Override public DeviceMonitoringData lastHeating(String sn) { - Query query = new Query().with(Sort.by(Sort.Direction.DESC,"heating_datetime")). - addCriteria(Criteria.where("heating").is(EHeatingFlag.True.getCode())); - return mongoTemplate.findOne(query, DeviceMonitoringData.class, sn); +// Query query = new Query().with(Sort.by(Sort.Direction.DESC,"heating_datetime")). +// addCriteria(Criteria.where("heating").is(EHeatingFlag.True.getCode())); +// return mongoTemplate.findOne(query, DeviceMonitoringData.class, sn); -// QueryWrapper queryWrapper = new QueryWrapper(). -// eq("sn", sn). -// eq("heating", EHeatingFlag.True.getCode()). -// orderByDesc("heating_datetime").last("limit 1"); -// return getOne(queryWrapper); + QueryWrapper queryWrapper = new QueryWrapper(). + eq("sn", sn). + eq("heating", EHeatingFlag.True.getCode()). + orderByDesc("heating_datetime").last("limit 1"); + return getOne(queryWrapper); } @Override @@ -113,14 +111,14 @@ @Override public List selectList(String sn, String startDate, String endDate) { - Query query = new Query().with(Sort.by(Sort.Direction.DESC,"date")). - addCriteria(Criteria.where("date").gte(startDate)).addCriteria(Criteria.where("date").lte(endDate)); - return mongoTemplate.find(query, DeviceMonitoringData.class, sn); +// Query query = new Query().with(Sort.by(Sort.Direction.DESC,"date")). +// addCriteria(Criteria.where("date").gte(startDate)).addCriteria(Criteria.where("date").lte(endDate)); +// return mongoTemplate.find(query, DeviceMonitoringData.class, sn); -// QueryWrapper queryWrapper = new QueryWrapper(). -// eq("sn", sn). -// ge("date", startDate).le("date", endDate).orderByDesc("date"); -// return list(queryWrapper); + QueryWrapper queryWrapper = new QueryWrapper(). + eq("sn", sn). + ge("date", startDate).le("date", endDate).orderByDesc("date"); + return list(queryWrapper); } @Override diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/ProjectInfoServiceImpl.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/ProjectInfoServiceImpl.java index 3e1a784..23163a0 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/ProjectInfoServiceImpl.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/ProjectInfoServiceImpl.java @@ -3,25 +3,22 @@ import com.newfiber.common.core.exception.ServiceException; import com.newfiber.common.core.web.domain.BaseEntity; import com.newfiber.common.core.web.service.BaseServiceImpl; -import com.newfiber.common.redis.service.RedisService; import com.newfiber.termite.domain.ProjectInfo; import com.newfiber.termite.domain.request.ProjectInfoQueryRequest; import com.newfiber.termite.domain.request.ProjectInfoSaveRequest; import com.newfiber.termite.domain.request.ProjectInfoUpdateRequest; import com.newfiber.termite.mapper.ProjectInfoMapper; import com.newfiber.termite.service.IProjectInfoService; -import java.util.ArrayList; import java.util.HashSet; +import java.util.List; +import java.util.Optional; import java.util.Set; +import javax.annotation.Resource; import org.apache.commons.collections4.CollectionUtils; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import javax.annotation.Resource; -import java.util.List; -import java.util.Optional; - @Service public class ProjectInfoServiceImpl extends BaseServiceImpl implements IProjectInfoService { @@ -100,4 +97,18 @@ } return projectCodeList; } + + @Override + public Set getUserProjectList(Long userId) { + List projectInfoList = list(); + Set result = new HashSet<>(); + for(ProjectInfo projectInfo : projectInfoList){ + for(String projectUserId : projectInfo.getProjectUsers().split(",")){ + if(userId.toString().equals(projectUserId)){ + result.add(projectInfo); + } + } + } + return result; + } } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java index 2cd61be..47293b9 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java @@ -1,5 +1,6 @@ package com.newfiber.termite.controller; +import com.newfiber.common.core.exception.ServiceException; import com.newfiber.common.core.utils.poi.ExcelUtil; import com.newfiber.common.core.web.controller.BaseController; import com.newfiber.common.core.web.domain.Result; @@ -72,6 +73,9 @@ @PostMapping("/importExcel") public Result> importExcel(MultipartFile file, String projectCode) throws Exception{ + if(null == file){ + throw new ServiceException("请上传文件"); + } ExcelUtil util = new ExcelUtil<>(DeviceInfoImportRequest.class); List deviceInfoImportRequestList = util.importExcel(file.getInputStream()); DeviceInfoBatchSaveRequest batchSaveRequest = new DeviceInfoBatchSaveRequest(projectCode, deviceInfoImportRequestList); diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java index f0bbcba..7a14a13 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java @@ -7,7 +7,6 @@ import com.newfiber.common.log.annotation.Log; import com.newfiber.common.log.enums.BusinessType; import com.newfiber.termite.domain.ProjectInfo; -import com.newfiber.termite.domain.dto.DeviceInfoDto; import com.newfiber.termite.domain.request.ProjectInfoQueryRequest; import com.newfiber.termite.domain.request.ProjectInfoSaveRequest; import com.newfiber.termite.domain.request.ProjectInfoUpdateRequest; @@ -15,11 +14,18 @@ import com.newfiber.termite.service.IProjectInfoService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import org.springframework.web.bind.annotation.*; - +import java.util.List; +import java.util.Set; import javax.annotation.Resource; import javax.validation.Valid; -import java.util.List; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/termiteProject") @@ -101,7 +107,15 @@ return success(list); } - + /** + * 列表查询人员项目 + */ + @GetMapping("/getUserProjectList/{userId}") + @ApiOperation(value = "列表查询人员项目", position = 60) + public Result> list(@PathVariable("userId") Long userId) { + Set list = projectInfoService.getUserProjectList(userId); + return success(list); + } /** * 通过设备SN获取上传地址 diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java index ad441f7..eb340bc 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java @@ -122,7 +122,7 @@ @PostMapping("/queryhistoryData") @ApiOperation(value = "查询历史数据", position = 60) public PageResult> queryhistoryData(TermiteHistoryQueryRequest request){ -// startPage(); + startPage(); PageResult> result =termiteService.queryhistoryData(request); return result; } @@ -208,4 +208,13 @@ public Result queryNowWeather(){ return success(termiteService.queryNowWeather()); } + + /** + */ + @PostMapping("/transferMySql2Mongo") + @ApiOperation(value = "termiteService.transferMySql2Mongo()", position = 60) + public Result transferMySql2Mongo(){ + termiteService.transferMySql2Mongo(); + return success(); + } } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java index bdb88aa..5f79da7 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java @@ -5,9 +5,7 @@ import com.newfiber.common.core.web.domain.BaseEntity; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; -import com.fasterxml.jackson.annotation.JsonFormat; import java.util.Date; -import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; import lombok.EqualsAndHashCode; @@ -136,4 +134,11 @@ @ApiModelProperty(value = "上传地址") private String uploadApi; + /** + * 项目名称 + */ + @TableField(exist = false) + @ApiModelProperty(value = "项目名称") + private String projectName; + } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java index fb04bd0..0d6416f 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java @@ -1,9 +1,24 @@ package com.newfiber.termite.domain.dto; +import com.newfiber.termite.domain.DeviceInfo; +import java.util.List; +import java.util.stream.Collectors; import lombok.Data; +import org.apache.commons.collections4.CollectionUtils; @Data public class SnAlarmStatisticDto { private String name; private Number value; + List snList; + List locationList; + + public void setDeviceInfo(List deviceInfoList){ + if(CollectionUtils.isEmpty(deviceInfoList)){ + return; + } + + snList = deviceInfoList.stream().map(DeviceInfo::getSn).collect(Collectors.toList()); + locationList = deviceInfoList.stream().map(DeviceInfo::getLocation).collect(Collectors.toList()); + } } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/request/TermiteHistoryQueryRequest.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/request/TermiteHistoryQueryRequest.java index 2cb9cef..ab1f689 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/request/TermiteHistoryQueryRequest.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/request/TermiteHistoryQueryRequest.java @@ -25,4 +25,11 @@ @ApiModelProperty(value = "结束时间") private String endtime; + + /** + * 分类(生产 production | 项目 project) + */ + @ApiModelProperty(value = "分类(生产 production | 项目 project)") + private String category = "project"; + } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IDeviceInfoService.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IDeviceInfoService.java index 51515d8..9c03500 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IDeviceInfoService.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IDeviceInfoService.java @@ -81,6 +81,14 @@ */ DeviceInfo selectDetail(String sn); + /** + * 详细查询设备信息 + * + * @param id 主键 + * @return 设备信息 + */ + DeviceInfo selectDetailByCategory(String category, String sn); + /** * 分页查询设备信息 * diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IProjectInfoService.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IProjectInfoService.java index e476c09..eed1f59 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IProjectInfoService.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IProjectInfoService.java @@ -4,7 +4,6 @@ import com.newfiber.termite.domain.request.ProjectInfoQueryRequest; import com.newfiber.termite.domain.request.ProjectInfoSaveRequest; import com.newfiber.termite.domain.request.ProjectInfoUpdateRequest; - import java.util.List; import java.util.Set; @@ -71,4 +70,6 @@ Set getUserProjectCodeList(Long userId); + Set getUserProjectList(Long userId); + } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceInfoServiceImpl.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceInfoServiceImpl.java index 063d4e7..21280ad 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceInfoServiceImpl.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceInfoServiceImpl.java @@ -146,6 +146,18 @@ return null; } + @Override + public DeviceInfo selectDetailByCategory(String category, String sn) { + DeviceInfoQueryRequest request = new DeviceInfoQueryRequest(); + request.setCategory(category); + request.setSn(sn); + List deviceInfoList = selectList(request); + if(CollectionUtils.isNotEmpty(deviceInfoList)){ + return deviceInfoList.get(0); + } + return null; + } + public DeviceInfo selectDetail(String sn, String projectCode) { DeviceInfoQueryRequest request = new DeviceInfoQueryRequest(); request.setCategory(EDeviceCategory.project.getCode()); diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceMonitoringDataServiceImpl.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceMonitoringDataServiceImpl.java index 85ccf9b..190169b 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceMonitoringDataServiceImpl.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceMonitoringDataServiceImpl.java @@ -1,5 +1,6 @@ package com.newfiber.termite.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.newfiber.common.core.exception.ServiceException; import com.newfiber.common.core.web.domain.BaseEntity; import com.newfiber.common.core.web.service.BaseServiceImpl; @@ -15,10 +16,7 @@ import java.util.Optional; import javax.annotation.Resource; import org.springframework.beans.BeanUtils; -import org.springframework.data.domain.Sort; import org.springframework.data.mongodb.core.MongoTemplate; -import org.springframework.data.mongodb.core.query.Criteria; -import org.springframework.data.mongodb.core.query.Query; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -77,28 +75,28 @@ @Override public DeviceMonitoringData lastDruging(String sn) { - Query query = new Query().with(Sort.by(Sort.Direction.DESC,"druing_datetime")). - addCriteria(Criteria.where("druing").ne(EDrugFlag.False.getCode())); - return mongoTemplate.findOne(query, DeviceMonitoringData.class, sn); +// Query query = new Query().with(Sort.by(Sort.Direction.DESC,"druing_datetime")). +// addCriteria(Criteria.where("druing").ne(EDrugFlag.False.getCode())); +// return mongoTemplate.findOne(query, DeviceMonitoringData.class, sn); // -// QueryWrapper queryWrapper = new QueryWrapper(). -// eq("sn", sn). -// ne("druing", EDrugFlag.False.getCode()). -// orderByDesc("druing_datetime").last("limit 1"); -// return getOne(queryWrapper); + QueryWrapper queryWrapper = new QueryWrapper(). + eq("sn", sn). + ne("druing", EDrugFlag.False.getCode()). + orderByDesc("druing_datetime").last("limit 1"); + return getOne(queryWrapper); } @Override public DeviceMonitoringData lastHeating(String sn) { - Query query = new Query().with(Sort.by(Sort.Direction.DESC,"heating_datetime")). - addCriteria(Criteria.where("heating").is(EHeatingFlag.True.getCode())); - return mongoTemplate.findOne(query, DeviceMonitoringData.class, sn); +// Query query = new Query().with(Sort.by(Sort.Direction.DESC,"heating_datetime")). +// addCriteria(Criteria.where("heating").is(EHeatingFlag.True.getCode())); +// return mongoTemplate.findOne(query, DeviceMonitoringData.class, sn); -// QueryWrapper queryWrapper = new QueryWrapper(). -// eq("sn", sn). -// eq("heating", EHeatingFlag.True.getCode()). -// orderByDesc("heating_datetime").last("limit 1"); -// return getOne(queryWrapper); + QueryWrapper queryWrapper = new QueryWrapper(). + eq("sn", sn). + eq("heating", EHeatingFlag.True.getCode()). + orderByDesc("heating_datetime").last("limit 1"); + return getOne(queryWrapper); } @Override @@ -113,14 +111,14 @@ @Override public List selectList(String sn, String startDate, String endDate) { - Query query = new Query().with(Sort.by(Sort.Direction.DESC,"date")). - addCriteria(Criteria.where("date").gte(startDate)).addCriteria(Criteria.where("date").lte(endDate)); - return mongoTemplate.find(query, DeviceMonitoringData.class, sn); +// Query query = new Query().with(Sort.by(Sort.Direction.DESC,"date")). +// addCriteria(Criteria.where("date").gte(startDate)).addCriteria(Criteria.where("date").lte(endDate)); +// return mongoTemplate.find(query, DeviceMonitoringData.class, sn); -// QueryWrapper queryWrapper = new QueryWrapper(). -// eq("sn", sn). -// ge("date", startDate).le("date", endDate).orderByDesc("date"); -// return list(queryWrapper); + QueryWrapper queryWrapper = new QueryWrapper(). + eq("sn", sn). + ge("date", startDate).le("date", endDate).orderByDesc("date"); + return list(queryWrapper); } @Override diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/ProjectInfoServiceImpl.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/ProjectInfoServiceImpl.java index 3e1a784..23163a0 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/ProjectInfoServiceImpl.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/ProjectInfoServiceImpl.java @@ -3,25 +3,22 @@ import com.newfiber.common.core.exception.ServiceException; import com.newfiber.common.core.web.domain.BaseEntity; import com.newfiber.common.core.web.service.BaseServiceImpl; -import com.newfiber.common.redis.service.RedisService; import com.newfiber.termite.domain.ProjectInfo; import com.newfiber.termite.domain.request.ProjectInfoQueryRequest; import com.newfiber.termite.domain.request.ProjectInfoSaveRequest; import com.newfiber.termite.domain.request.ProjectInfoUpdateRequest; import com.newfiber.termite.mapper.ProjectInfoMapper; import com.newfiber.termite.service.IProjectInfoService; -import java.util.ArrayList; import java.util.HashSet; +import java.util.List; +import java.util.Optional; import java.util.Set; +import javax.annotation.Resource; import org.apache.commons.collections4.CollectionUtils; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import javax.annotation.Resource; -import java.util.List; -import java.util.Optional; - @Service public class ProjectInfoServiceImpl extends BaseServiceImpl implements IProjectInfoService { @@ -100,4 +97,18 @@ } return projectCodeList; } + + @Override + public Set getUserProjectList(Long userId) { + List projectInfoList = list(); + Set result = new HashSet<>(); + for(ProjectInfo projectInfo : projectInfoList){ + for(String projectUserId : projectInfo.getProjectUsers().split(",")){ + if(userId.toString().equals(projectUserId)){ + result.add(projectInfo); + } + } + } + return result; + } } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/TermiteServiceImpl.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/TermiteServiceImpl.java index ed03fb7..c77fc7c 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/TermiteServiceImpl.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/TermiteServiceImpl.java @@ -2,13 +2,16 @@ import cn.hutool.core.date.DateUtil; +import cn.hutool.core.img.Img; +import cn.hutool.core.img.ImgUtil; +import cn.hutool.core.io.FileUtil; import cn.hutool.core.util.ReflectUtil; import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.newfiber.common.core.enums.EBoolean; -import com.newfiber.common.core.web.page.PageDomain; +import com.newfiber.common.core.exception.ServiceException; import com.newfiber.common.core.web.page.PageResult; import com.newfiber.common.core.web.page.PageSupport; import com.newfiber.common.core.web.service.BaseServiceImpl; @@ -45,6 +48,11 @@ import com.newfiber.termite.service.jingchu.IJingchuDeviceConfigService; import com.newfiber.termite.service.jingchu.IJingchuProjectConfigService; import com.newfiber.termite.util.CosUtil; +import com.newfiber.termite.util.FileUploadUtils; +import java.awt.Color; +import java.awt.Font; +import java.awt.Image; +import java.io.IOException; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Date; @@ -52,10 +60,11 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; import javax.annotation.Resource; import lombok.extern.slf4j.Slf4j; +import org.jetbrains.annotations.NotNull; import org.springframework.beans.BeanUtils; -import org.springframework.data.domain.Sort; import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Query; @@ -99,6 +108,8 @@ private final ExecutorService jingchuExecutorService = Executors.newFixedThreadPool(4); + Font font = new Font("微软雅黑", Font.BOLD, 50); + @Transactional(rollbackFor = Exception.class) public DataUpResponse termiteDataup(TermiteDataUpRequest termiteDateUpRequest, MultipartFile image){ String date = DateUtil.formatDateTime(new Date()); @@ -140,8 +151,9 @@ public String photoIdentify(PhotoIdentifyDto dataDto, MultipartFile image) throws Exception{ DeviceMonitoringData existedDeviceMonitoringData = deviceMonitoringDataService.selectDetail(Long.parseLong(dataDto.getId())); log.info("站点{}在{}时刻更新识别结果", existedDeviceMonitoringData.getSn(), DateUtil.formatDateTime(new Date())); + DeviceInfo deviceInfo = deviceInfoService.selectDetail(existedDeviceMonitoringData.getSn()); - String url = CosUtil.putFile(image); + String url = uploadFile(dataDto, image, existedDeviceMonitoringData, deviceInfo); DeviceMonitoringData deviceMonitoringData = new DeviceMonitoringData(); deviceMonitoringData.setId(Long.parseLong(dataDto.getId())); @@ -164,6 +176,24 @@ return url; } + @NotNull + private String uploadFile(PhotoIdentifyDto dataDto, MultipartFile image, DeviceMonitoringData existedDeviceMonitoringData, DeviceInfo deviceInfo) + throws IOException { + String url = ""; + if(EExistsAnt.True.getCode().equals(dataDto.getYesnoant())){ + Image srcImage = ImgUtil.read(image.getInputStream()); + Img img = Img.from(srcImage); + img.setPositionBaseCentre(false); + img = img.pressText("项目:" + deviceInfo.getProjectName(), Color.WHITE, font, 0, 900, 1f); + img = img.pressText("位置:" + deviceInfo.getLocation(), Color.WHITE, font, 0, 1000, 1f); + img = img.pressText("时间:" + DateUtil.format(existedDeviceMonitoringData.getUptime(), "yyyy-MM-dd HH:mm"), Color.WHITE, font, 0, 1100, 1f); + url = CosUtil.putFile(ImgUtil.toStream(img.getImg(), FileUtil.extName(image.getName())), FileUploadUtils.extractFilename(image)); + }else{ + url = CosUtil.putFile(image); + } + return url; + } + private void jingChuUpload(DeviceMonitoringData existedDeviceMonitoringData, String yesnoant) { JingchuDeviceConfig jingchuDeviceConfig = jingchuDeviceConfigService.selectDetail(existedDeviceMonitoringData.getSn()); JingchuProjectConfig jingchuProjectConfig = jingchuProjectConfigService.selectDetail(existedDeviceMonitoringData.getProjectCode()); @@ -182,8 +212,8 @@ if(EBoolean.False.getStringValue().equals(jingchuDeviceConfig.getUploadConfirmFlag())){ jingChuUpload.setStatus(EBoolean.False.getIntValue()); }else{ - int status = EExistsAnt.True.getCode().equals(yesnoant) ? 1 : 0; - jingChuUpload.setStatus(status); +// int status = EExistsAnt.True.getCode().equals(yesnoant) ? 1 : 0; + jingChuUpload.setStatus(EBoolean.True.getIntValue()); } List jingChuUploadList = new ArrayList<>(); @@ -291,49 +321,54 @@ @Override public PageResult> queryhistoryData(TermiteHistoryQueryRequest request){ - DeviceInfo deviceInfo = deviceInfoService.selectDetail(request.getSn()); - - Query query = new Query().with(Sort.by(Sort.Direction.DESC, "date")); - Criteria criteria = new Criteria(); - - if (null != request.getStarttime()) { - criteria.andOperator(Criteria.where("tt").gte(request.getStarttime())); - } - if (null != request.getEndtime()) { - criteria.andOperator(Criteria.where("tt").lte(request.getEndtime())); - } - if (null != request.getYesnoant()) { - criteria.andOperator(Criteria.where("yesnoant").lte(request.getYesnoant())); - } - if (null != request.getIdencolle()) { - criteria.andOperator(Criteria.where("idencolle").lte(request.getIdencolle())); - } - if (null != request.getDruing()) { - criteria.andOperator(Criteria.where("druing").lte(request.getDruing())); - } - - Long countNum = mongoTemplate.count(query, request.getSn()); - - PageDomain pageDomain = PageSupport.buildPageRequest(); - Integer pageNum = pageDomain.getPageNum(); - Integer pageSize = pageDomain.getPageSize(); - query.skip((pageNum - 1) * pageSize).limit(pageSize); - - List responseList = new ArrayList<>(); - List deviceMonitoringDataRealtimeList = mongoTemplate.find(query, DeviceMonitoringDataRealtime.class, request.getSn()); - for(DeviceMonitoringDataRealtime realtime : deviceMonitoringDataRealtimeList){ - TermiteInfoResponse response = new TermiteInfoResponse(); - BeanUtils.copyProperties(realtime, response); - response.setLocation(deviceInfo.getLocation()); - responseList.add(response); - } - - return new PageResult<>(responseList, countNum); -// return PageSupport.pageResult(termiteMapper.queryhistoryData(request)); +// DeviceInfo deviceInfo = deviceInfoService.selectDetail(request.getSn()); +// +// Query query = new Query().with(Sort.by(Sort.Direction.DESC, "date")); +// Criteria criteria = new Criteria(); +// +// if (null != request.getStarttime()) { +// criteria.andOperator(Criteria.where("tt").gte(request.getStarttime())); +// } +// if (null != request.getEndtime()) { +// criteria.andOperator(Criteria.where("tt").lte(request.getEndtime())); +// } +// if (null != request.getYesnoant()) { +// criteria.andOperator(Criteria.where("yesnoant").lte(request.getYesnoant())); +// } +// if (null != request.getIdencolle()) { +// criteria.andOperator(Criteria.where("idencolle").lte(request.getIdencolle())); +// } +// if (null != request.getDruing()) { +// criteria.andOperator(Criteria.where("druing").lte(request.getDruing())); +// } +// +// Long countNum = mongoTemplate.count(query, request.getSn()); +// +// PageDomain pageDomain = PageSupport.buildPageRequest(); +// Integer pageNum = pageDomain.getPageNum(); +// Integer pageSize = pageDomain.getPageSize(); +// query.skip((pageNum - 1) * pageSize).limit(pageSize); +// +// List responseList = new ArrayList<>(); +// List deviceMonitoringDataRealtimeList = mongoTemplate.find(query, DeviceMonitoringDataRealtime.class, request.getSn()); +// for(DeviceMonitoringDataRealtime realtime : deviceMonitoringDataRealtimeList){ +// TermiteInfoResponse response = new TermiteInfoResponse(); +// BeanUtils.copyProperties(realtime, response); +// response.setLocation(deviceInfo.getLocation()); +// responseList.add(response); +// } +// +// return new PageResult<>(responseList, countNum); + return PageSupport.pageResult(termiteMapper.queryhistoryData(request)); } @Override public boolean insertMonitorDevice(TermiteInfoSaveRequest request){ + DeviceInfo existDeviceInfo = deviceInfoService.selectDetailByCategory(request.getCategory(), request.getSn()); + if(null != existDeviceInfo){ + throw new ServiceException(String.format("站点%s已存在", request.getSn())); + } + DeviceInfo deviceInfo = new DeviceInfo(); BeanUtils.copyProperties(request, deviceInfo); deviceInfoService.save(deviceInfo); @@ -367,6 +402,8 @@ List result = new ArrayList<>(); //查询所有站点的数据信息 List deviceInfoList = deviceInfoService.selectList(projectCode); + List offlineDeviceList = new ArrayList<>(); + AtomicInteger outlineflag = new AtomicInteger(0); deviceInfoList.forEach(e->{ Date date1 = new Date(); @@ -376,23 +413,30 @@ double diffdays = diff/(1000l*60l*60l*24l); if(diffdays>1){ outlineflag.getAndIncrement(); + offlineDeviceList.add(e); } }else { outlineflag.getAndIncrement(); + offlineDeviceList.add(e); } }); + + List onlineDeviceList = deviceInfoList.stream().filter(t -> !offlineDeviceList.contains(t)).collect(Collectors.toList()); int onlineflag = deviceInfoList.size()- outlineflag.get(); SnAlarmStatisticDto snAlarmStatisticDto =new SnAlarmStatisticDto(); snAlarmStatisticDto.setName("在线"); snAlarmStatisticDto.setValue(onlineflag); + snAlarmStatisticDto.setDeviceInfo(onlineDeviceList); result.add(snAlarmStatisticDto); SnAlarmStatisticDto snAlarmStatisticDto2 =new SnAlarmStatisticDto(); snAlarmStatisticDto2.setName("离线"); snAlarmStatisticDto2.setValue(outlineflag.get()); + snAlarmStatisticDto2.setDeviceInfo(offlineDeviceList); result.add(snAlarmStatisticDto2); SnAlarmStatisticDto snAlarmStatisticDto3 =new SnAlarmStatisticDto(); snAlarmStatisticDto3.setName("告警"); snAlarmStatisticDto3.setValue(deviceInfoList.stream().filter(t -> null != t.getFirstWarnDatetime()).count()); + snAlarmStatisticDto3.setDeviceInfo(deviceInfoList.stream().filter(t -> null != t.getFirstWarnDatetime()).collect(Collectors.toList())); result.add(snAlarmStatisticDto3); return result; } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java index 2cd61be..47293b9 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java @@ -1,5 +1,6 @@ package com.newfiber.termite.controller; +import com.newfiber.common.core.exception.ServiceException; import com.newfiber.common.core.utils.poi.ExcelUtil; import com.newfiber.common.core.web.controller.BaseController; import com.newfiber.common.core.web.domain.Result; @@ -72,6 +73,9 @@ @PostMapping("/importExcel") public Result> importExcel(MultipartFile file, String projectCode) throws Exception{ + if(null == file){ + throw new ServiceException("请上传文件"); + } ExcelUtil util = new ExcelUtil<>(DeviceInfoImportRequest.class); List deviceInfoImportRequestList = util.importExcel(file.getInputStream()); DeviceInfoBatchSaveRequest batchSaveRequest = new DeviceInfoBatchSaveRequest(projectCode, deviceInfoImportRequestList); diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java index f0bbcba..7a14a13 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java @@ -7,7 +7,6 @@ import com.newfiber.common.log.annotation.Log; import com.newfiber.common.log.enums.BusinessType; import com.newfiber.termite.domain.ProjectInfo; -import com.newfiber.termite.domain.dto.DeviceInfoDto; import com.newfiber.termite.domain.request.ProjectInfoQueryRequest; import com.newfiber.termite.domain.request.ProjectInfoSaveRequest; import com.newfiber.termite.domain.request.ProjectInfoUpdateRequest; @@ -15,11 +14,18 @@ import com.newfiber.termite.service.IProjectInfoService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import org.springframework.web.bind.annotation.*; - +import java.util.List; +import java.util.Set; import javax.annotation.Resource; import javax.validation.Valid; -import java.util.List; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/termiteProject") @@ -101,7 +107,15 @@ return success(list); } - + /** + * 列表查询人员项目 + */ + @GetMapping("/getUserProjectList/{userId}") + @ApiOperation(value = "列表查询人员项目", position = 60) + public Result> list(@PathVariable("userId") Long userId) { + Set list = projectInfoService.getUserProjectList(userId); + return success(list); + } /** * 通过设备SN获取上传地址 diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java index ad441f7..eb340bc 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java @@ -122,7 +122,7 @@ @PostMapping("/queryhistoryData") @ApiOperation(value = "查询历史数据", position = 60) public PageResult> queryhistoryData(TermiteHistoryQueryRequest request){ -// startPage(); + startPage(); PageResult> result =termiteService.queryhistoryData(request); return result; } @@ -208,4 +208,13 @@ public Result queryNowWeather(){ return success(termiteService.queryNowWeather()); } + + /** + */ + @PostMapping("/transferMySql2Mongo") + @ApiOperation(value = "termiteService.transferMySql2Mongo()", position = 60) + public Result transferMySql2Mongo(){ + termiteService.transferMySql2Mongo(); + return success(); + } } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java index bdb88aa..5f79da7 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java @@ -5,9 +5,7 @@ import com.newfiber.common.core.web.domain.BaseEntity; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; -import com.fasterxml.jackson.annotation.JsonFormat; import java.util.Date; -import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; import lombok.EqualsAndHashCode; @@ -136,4 +134,11 @@ @ApiModelProperty(value = "上传地址") private String uploadApi; + /** + * 项目名称 + */ + @TableField(exist = false) + @ApiModelProperty(value = "项目名称") + private String projectName; + } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java index fb04bd0..0d6416f 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java @@ -1,9 +1,24 @@ package com.newfiber.termite.domain.dto; +import com.newfiber.termite.domain.DeviceInfo; +import java.util.List; +import java.util.stream.Collectors; import lombok.Data; +import org.apache.commons.collections4.CollectionUtils; @Data public class SnAlarmStatisticDto { private String name; private Number value; + List snList; + List locationList; + + public void setDeviceInfo(List deviceInfoList){ + if(CollectionUtils.isEmpty(deviceInfoList)){ + return; + } + + snList = deviceInfoList.stream().map(DeviceInfo::getSn).collect(Collectors.toList()); + locationList = deviceInfoList.stream().map(DeviceInfo::getLocation).collect(Collectors.toList()); + } } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/request/TermiteHistoryQueryRequest.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/request/TermiteHistoryQueryRequest.java index 2cb9cef..ab1f689 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/request/TermiteHistoryQueryRequest.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/request/TermiteHistoryQueryRequest.java @@ -25,4 +25,11 @@ @ApiModelProperty(value = "结束时间") private String endtime; + + /** + * 分类(生产 production | 项目 project) + */ + @ApiModelProperty(value = "分类(生产 production | 项目 project)") + private String category = "project"; + } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IDeviceInfoService.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IDeviceInfoService.java index 51515d8..9c03500 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IDeviceInfoService.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IDeviceInfoService.java @@ -81,6 +81,14 @@ */ DeviceInfo selectDetail(String sn); + /** + * 详细查询设备信息 + * + * @param id 主键 + * @return 设备信息 + */ + DeviceInfo selectDetailByCategory(String category, String sn); + /** * 分页查询设备信息 * diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IProjectInfoService.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IProjectInfoService.java index e476c09..eed1f59 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IProjectInfoService.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IProjectInfoService.java @@ -4,7 +4,6 @@ import com.newfiber.termite.domain.request.ProjectInfoQueryRequest; import com.newfiber.termite.domain.request.ProjectInfoSaveRequest; import com.newfiber.termite.domain.request.ProjectInfoUpdateRequest; - import java.util.List; import java.util.Set; @@ -71,4 +70,6 @@ Set getUserProjectCodeList(Long userId); + Set getUserProjectList(Long userId); + } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceInfoServiceImpl.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceInfoServiceImpl.java index 063d4e7..21280ad 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceInfoServiceImpl.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceInfoServiceImpl.java @@ -146,6 +146,18 @@ return null; } + @Override + public DeviceInfo selectDetailByCategory(String category, String sn) { + DeviceInfoQueryRequest request = new DeviceInfoQueryRequest(); + request.setCategory(category); + request.setSn(sn); + List deviceInfoList = selectList(request); + if(CollectionUtils.isNotEmpty(deviceInfoList)){ + return deviceInfoList.get(0); + } + return null; + } + public DeviceInfo selectDetail(String sn, String projectCode) { DeviceInfoQueryRequest request = new DeviceInfoQueryRequest(); request.setCategory(EDeviceCategory.project.getCode()); diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceMonitoringDataServiceImpl.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceMonitoringDataServiceImpl.java index 85ccf9b..190169b 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceMonitoringDataServiceImpl.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceMonitoringDataServiceImpl.java @@ -1,5 +1,6 @@ package com.newfiber.termite.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.newfiber.common.core.exception.ServiceException; import com.newfiber.common.core.web.domain.BaseEntity; import com.newfiber.common.core.web.service.BaseServiceImpl; @@ -15,10 +16,7 @@ import java.util.Optional; import javax.annotation.Resource; import org.springframework.beans.BeanUtils; -import org.springframework.data.domain.Sort; import org.springframework.data.mongodb.core.MongoTemplate; -import org.springframework.data.mongodb.core.query.Criteria; -import org.springframework.data.mongodb.core.query.Query; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -77,28 +75,28 @@ @Override public DeviceMonitoringData lastDruging(String sn) { - Query query = new Query().with(Sort.by(Sort.Direction.DESC,"druing_datetime")). - addCriteria(Criteria.where("druing").ne(EDrugFlag.False.getCode())); - return mongoTemplate.findOne(query, DeviceMonitoringData.class, sn); +// Query query = new Query().with(Sort.by(Sort.Direction.DESC,"druing_datetime")). +// addCriteria(Criteria.where("druing").ne(EDrugFlag.False.getCode())); +// return mongoTemplate.findOne(query, DeviceMonitoringData.class, sn); // -// QueryWrapper queryWrapper = new QueryWrapper(). -// eq("sn", sn). -// ne("druing", EDrugFlag.False.getCode()). -// orderByDesc("druing_datetime").last("limit 1"); -// return getOne(queryWrapper); + QueryWrapper queryWrapper = new QueryWrapper(). + eq("sn", sn). + ne("druing", EDrugFlag.False.getCode()). + orderByDesc("druing_datetime").last("limit 1"); + return getOne(queryWrapper); } @Override public DeviceMonitoringData lastHeating(String sn) { - Query query = new Query().with(Sort.by(Sort.Direction.DESC,"heating_datetime")). - addCriteria(Criteria.where("heating").is(EHeatingFlag.True.getCode())); - return mongoTemplate.findOne(query, DeviceMonitoringData.class, sn); +// Query query = new Query().with(Sort.by(Sort.Direction.DESC,"heating_datetime")). +// addCriteria(Criteria.where("heating").is(EHeatingFlag.True.getCode())); +// return mongoTemplate.findOne(query, DeviceMonitoringData.class, sn); -// QueryWrapper queryWrapper = new QueryWrapper(). -// eq("sn", sn). -// eq("heating", EHeatingFlag.True.getCode()). -// orderByDesc("heating_datetime").last("limit 1"); -// return getOne(queryWrapper); + QueryWrapper queryWrapper = new QueryWrapper(). + eq("sn", sn). + eq("heating", EHeatingFlag.True.getCode()). + orderByDesc("heating_datetime").last("limit 1"); + return getOne(queryWrapper); } @Override @@ -113,14 +111,14 @@ @Override public List selectList(String sn, String startDate, String endDate) { - Query query = new Query().with(Sort.by(Sort.Direction.DESC,"date")). - addCriteria(Criteria.where("date").gte(startDate)).addCriteria(Criteria.where("date").lte(endDate)); - return mongoTemplate.find(query, DeviceMonitoringData.class, sn); +// Query query = new Query().with(Sort.by(Sort.Direction.DESC,"date")). +// addCriteria(Criteria.where("date").gte(startDate)).addCriteria(Criteria.where("date").lte(endDate)); +// return mongoTemplate.find(query, DeviceMonitoringData.class, sn); -// QueryWrapper queryWrapper = new QueryWrapper(). -// eq("sn", sn). -// ge("date", startDate).le("date", endDate).orderByDesc("date"); -// return list(queryWrapper); + QueryWrapper queryWrapper = new QueryWrapper(). + eq("sn", sn). + ge("date", startDate).le("date", endDate).orderByDesc("date"); + return list(queryWrapper); } @Override diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/ProjectInfoServiceImpl.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/ProjectInfoServiceImpl.java index 3e1a784..23163a0 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/ProjectInfoServiceImpl.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/ProjectInfoServiceImpl.java @@ -3,25 +3,22 @@ import com.newfiber.common.core.exception.ServiceException; import com.newfiber.common.core.web.domain.BaseEntity; import com.newfiber.common.core.web.service.BaseServiceImpl; -import com.newfiber.common.redis.service.RedisService; import com.newfiber.termite.domain.ProjectInfo; import com.newfiber.termite.domain.request.ProjectInfoQueryRequest; import com.newfiber.termite.domain.request.ProjectInfoSaveRequest; import com.newfiber.termite.domain.request.ProjectInfoUpdateRequest; import com.newfiber.termite.mapper.ProjectInfoMapper; import com.newfiber.termite.service.IProjectInfoService; -import java.util.ArrayList; import java.util.HashSet; +import java.util.List; +import java.util.Optional; import java.util.Set; +import javax.annotation.Resource; import org.apache.commons.collections4.CollectionUtils; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import javax.annotation.Resource; -import java.util.List; -import java.util.Optional; - @Service public class ProjectInfoServiceImpl extends BaseServiceImpl implements IProjectInfoService { @@ -100,4 +97,18 @@ } return projectCodeList; } + + @Override + public Set getUserProjectList(Long userId) { + List projectInfoList = list(); + Set result = new HashSet<>(); + for(ProjectInfo projectInfo : projectInfoList){ + for(String projectUserId : projectInfo.getProjectUsers().split(",")){ + if(userId.toString().equals(projectUserId)){ + result.add(projectInfo); + } + } + } + return result; + } } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/TermiteServiceImpl.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/TermiteServiceImpl.java index ed03fb7..c77fc7c 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/TermiteServiceImpl.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/TermiteServiceImpl.java @@ -2,13 +2,16 @@ import cn.hutool.core.date.DateUtil; +import cn.hutool.core.img.Img; +import cn.hutool.core.img.ImgUtil; +import cn.hutool.core.io.FileUtil; import cn.hutool.core.util.ReflectUtil; import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.newfiber.common.core.enums.EBoolean; -import com.newfiber.common.core.web.page.PageDomain; +import com.newfiber.common.core.exception.ServiceException; import com.newfiber.common.core.web.page.PageResult; import com.newfiber.common.core.web.page.PageSupport; import com.newfiber.common.core.web.service.BaseServiceImpl; @@ -45,6 +48,11 @@ import com.newfiber.termite.service.jingchu.IJingchuDeviceConfigService; import com.newfiber.termite.service.jingchu.IJingchuProjectConfigService; import com.newfiber.termite.util.CosUtil; +import com.newfiber.termite.util.FileUploadUtils; +import java.awt.Color; +import java.awt.Font; +import java.awt.Image; +import java.io.IOException; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Date; @@ -52,10 +60,11 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; import javax.annotation.Resource; import lombok.extern.slf4j.Slf4j; +import org.jetbrains.annotations.NotNull; import org.springframework.beans.BeanUtils; -import org.springframework.data.domain.Sort; import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Query; @@ -99,6 +108,8 @@ private final ExecutorService jingchuExecutorService = Executors.newFixedThreadPool(4); + Font font = new Font("微软雅黑", Font.BOLD, 50); + @Transactional(rollbackFor = Exception.class) public DataUpResponse termiteDataup(TermiteDataUpRequest termiteDateUpRequest, MultipartFile image){ String date = DateUtil.formatDateTime(new Date()); @@ -140,8 +151,9 @@ public String photoIdentify(PhotoIdentifyDto dataDto, MultipartFile image) throws Exception{ DeviceMonitoringData existedDeviceMonitoringData = deviceMonitoringDataService.selectDetail(Long.parseLong(dataDto.getId())); log.info("站点{}在{}时刻更新识别结果", existedDeviceMonitoringData.getSn(), DateUtil.formatDateTime(new Date())); + DeviceInfo deviceInfo = deviceInfoService.selectDetail(existedDeviceMonitoringData.getSn()); - String url = CosUtil.putFile(image); + String url = uploadFile(dataDto, image, existedDeviceMonitoringData, deviceInfo); DeviceMonitoringData deviceMonitoringData = new DeviceMonitoringData(); deviceMonitoringData.setId(Long.parseLong(dataDto.getId())); @@ -164,6 +176,24 @@ return url; } + @NotNull + private String uploadFile(PhotoIdentifyDto dataDto, MultipartFile image, DeviceMonitoringData existedDeviceMonitoringData, DeviceInfo deviceInfo) + throws IOException { + String url = ""; + if(EExistsAnt.True.getCode().equals(dataDto.getYesnoant())){ + Image srcImage = ImgUtil.read(image.getInputStream()); + Img img = Img.from(srcImage); + img.setPositionBaseCentre(false); + img = img.pressText("项目:" + deviceInfo.getProjectName(), Color.WHITE, font, 0, 900, 1f); + img = img.pressText("位置:" + deviceInfo.getLocation(), Color.WHITE, font, 0, 1000, 1f); + img = img.pressText("时间:" + DateUtil.format(existedDeviceMonitoringData.getUptime(), "yyyy-MM-dd HH:mm"), Color.WHITE, font, 0, 1100, 1f); + url = CosUtil.putFile(ImgUtil.toStream(img.getImg(), FileUtil.extName(image.getName())), FileUploadUtils.extractFilename(image)); + }else{ + url = CosUtil.putFile(image); + } + return url; + } + private void jingChuUpload(DeviceMonitoringData existedDeviceMonitoringData, String yesnoant) { JingchuDeviceConfig jingchuDeviceConfig = jingchuDeviceConfigService.selectDetail(existedDeviceMonitoringData.getSn()); JingchuProjectConfig jingchuProjectConfig = jingchuProjectConfigService.selectDetail(existedDeviceMonitoringData.getProjectCode()); @@ -182,8 +212,8 @@ if(EBoolean.False.getStringValue().equals(jingchuDeviceConfig.getUploadConfirmFlag())){ jingChuUpload.setStatus(EBoolean.False.getIntValue()); }else{ - int status = EExistsAnt.True.getCode().equals(yesnoant) ? 1 : 0; - jingChuUpload.setStatus(status); +// int status = EExistsAnt.True.getCode().equals(yesnoant) ? 1 : 0; + jingChuUpload.setStatus(EBoolean.True.getIntValue()); } List jingChuUploadList = new ArrayList<>(); @@ -291,49 +321,54 @@ @Override public PageResult> queryhistoryData(TermiteHistoryQueryRequest request){ - DeviceInfo deviceInfo = deviceInfoService.selectDetail(request.getSn()); - - Query query = new Query().with(Sort.by(Sort.Direction.DESC, "date")); - Criteria criteria = new Criteria(); - - if (null != request.getStarttime()) { - criteria.andOperator(Criteria.where("tt").gte(request.getStarttime())); - } - if (null != request.getEndtime()) { - criteria.andOperator(Criteria.where("tt").lte(request.getEndtime())); - } - if (null != request.getYesnoant()) { - criteria.andOperator(Criteria.where("yesnoant").lte(request.getYesnoant())); - } - if (null != request.getIdencolle()) { - criteria.andOperator(Criteria.where("idencolle").lte(request.getIdencolle())); - } - if (null != request.getDruing()) { - criteria.andOperator(Criteria.where("druing").lte(request.getDruing())); - } - - Long countNum = mongoTemplate.count(query, request.getSn()); - - PageDomain pageDomain = PageSupport.buildPageRequest(); - Integer pageNum = pageDomain.getPageNum(); - Integer pageSize = pageDomain.getPageSize(); - query.skip((pageNum - 1) * pageSize).limit(pageSize); - - List responseList = new ArrayList<>(); - List deviceMonitoringDataRealtimeList = mongoTemplate.find(query, DeviceMonitoringDataRealtime.class, request.getSn()); - for(DeviceMonitoringDataRealtime realtime : deviceMonitoringDataRealtimeList){ - TermiteInfoResponse response = new TermiteInfoResponse(); - BeanUtils.copyProperties(realtime, response); - response.setLocation(deviceInfo.getLocation()); - responseList.add(response); - } - - return new PageResult<>(responseList, countNum); -// return PageSupport.pageResult(termiteMapper.queryhistoryData(request)); +// DeviceInfo deviceInfo = deviceInfoService.selectDetail(request.getSn()); +// +// Query query = new Query().with(Sort.by(Sort.Direction.DESC, "date")); +// Criteria criteria = new Criteria(); +// +// if (null != request.getStarttime()) { +// criteria.andOperator(Criteria.where("tt").gte(request.getStarttime())); +// } +// if (null != request.getEndtime()) { +// criteria.andOperator(Criteria.where("tt").lte(request.getEndtime())); +// } +// if (null != request.getYesnoant()) { +// criteria.andOperator(Criteria.where("yesnoant").lte(request.getYesnoant())); +// } +// if (null != request.getIdencolle()) { +// criteria.andOperator(Criteria.where("idencolle").lte(request.getIdencolle())); +// } +// if (null != request.getDruing()) { +// criteria.andOperator(Criteria.where("druing").lte(request.getDruing())); +// } +// +// Long countNum = mongoTemplate.count(query, request.getSn()); +// +// PageDomain pageDomain = PageSupport.buildPageRequest(); +// Integer pageNum = pageDomain.getPageNum(); +// Integer pageSize = pageDomain.getPageSize(); +// query.skip((pageNum - 1) * pageSize).limit(pageSize); +// +// List responseList = new ArrayList<>(); +// List deviceMonitoringDataRealtimeList = mongoTemplate.find(query, DeviceMonitoringDataRealtime.class, request.getSn()); +// for(DeviceMonitoringDataRealtime realtime : deviceMonitoringDataRealtimeList){ +// TermiteInfoResponse response = new TermiteInfoResponse(); +// BeanUtils.copyProperties(realtime, response); +// response.setLocation(deviceInfo.getLocation()); +// responseList.add(response); +// } +// +// return new PageResult<>(responseList, countNum); + return PageSupport.pageResult(termiteMapper.queryhistoryData(request)); } @Override public boolean insertMonitorDevice(TermiteInfoSaveRequest request){ + DeviceInfo existDeviceInfo = deviceInfoService.selectDetailByCategory(request.getCategory(), request.getSn()); + if(null != existDeviceInfo){ + throw new ServiceException(String.format("站点%s已存在", request.getSn())); + } + DeviceInfo deviceInfo = new DeviceInfo(); BeanUtils.copyProperties(request, deviceInfo); deviceInfoService.save(deviceInfo); @@ -367,6 +402,8 @@ List result = new ArrayList<>(); //查询所有站点的数据信息 List deviceInfoList = deviceInfoService.selectList(projectCode); + List offlineDeviceList = new ArrayList<>(); + AtomicInteger outlineflag = new AtomicInteger(0); deviceInfoList.forEach(e->{ Date date1 = new Date(); @@ -376,23 +413,30 @@ double diffdays = diff/(1000l*60l*60l*24l); if(diffdays>1){ outlineflag.getAndIncrement(); + offlineDeviceList.add(e); } }else { outlineflag.getAndIncrement(); + offlineDeviceList.add(e); } }); + + List onlineDeviceList = deviceInfoList.stream().filter(t -> !offlineDeviceList.contains(t)).collect(Collectors.toList()); int onlineflag = deviceInfoList.size()- outlineflag.get(); SnAlarmStatisticDto snAlarmStatisticDto =new SnAlarmStatisticDto(); snAlarmStatisticDto.setName("在线"); snAlarmStatisticDto.setValue(onlineflag); + snAlarmStatisticDto.setDeviceInfo(onlineDeviceList); result.add(snAlarmStatisticDto); SnAlarmStatisticDto snAlarmStatisticDto2 =new SnAlarmStatisticDto(); snAlarmStatisticDto2.setName("离线"); snAlarmStatisticDto2.setValue(outlineflag.get()); + snAlarmStatisticDto2.setDeviceInfo(offlineDeviceList); result.add(snAlarmStatisticDto2); SnAlarmStatisticDto snAlarmStatisticDto3 =new SnAlarmStatisticDto(); snAlarmStatisticDto3.setName("告警"); snAlarmStatisticDto3.setValue(deviceInfoList.stream().filter(t -> null != t.getFirstWarnDatetime()).count()); + snAlarmStatisticDto3.setDeviceInfo(deviceInfoList.stream().filter(t -> null != t.getFirstWarnDatetime()).collect(Collectors.toList())); result.add(snAlarmStatisticDto3); return result; } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/util/CosUtil.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/util/CosUtil.java index 06d19f1..8f27670 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/util/CosUtil.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/util/CosUtil.java @@ -57,6 +57,25 @@ return ""; } + public static String putFile(InputStream inputStream, String fileName){ + + try { + ObjectMetadata objectMetadata = new ObjectMetadata(); + + PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, fileName, inputStream, objectMetadata); + // 设置单链接限速(如有需要),不需要可忽略 + putObjectRequest.setTrafficLimit(8*1024*1024); + PutObjectResult putObjectResult = cosClient.putObject(putObjectRequest); +// System.out.println(putObjectResult.getRequestId()); + return url + fileName; + } catch (CosServiceException e) { + e.printStackTrace(); + } catch (CosClientException e) { + e.printStackTrace(); + } + + return ""; + } private static void putLocalFileDemo() { String key = "abc/abc.txt"; String localPath = "abc.txt"; diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java index 2cd61be..47293b9 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java @@ -1,5 +1,6 @@ package com.newfiber.termite.controller; +import com.newfiber.common.core.exception.ServiceException; import com.newfiber.common.core.utils.poi.ExcelUtil; import com.newfiber.common.core.web.controller.BaseController; import com.newfiber.common.core.web.domain.Result; @@ -72,6 +73,9 @@ @PostMapping("/importExcel") public Result> importExcel(MultipartFile file, String projectCode) throws Exception{ + if(null == file){ + throw new ServiceException("请上传文件"); + } ExcelUtil util = new ExcelUtil<>(DeviceInfoImportRequest.class); List deviceInfoImportRequestList = util.importExcel(file.getInputStream()); DeviceInfoBatchSaveRequest batchSaveRequest = new DeviceInfoBatchSaveRequest(projectCode, deviceInfoImportRequestList); diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java index f0bbcba..7a14a13 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java @@ -7,7 +7,6 @@ import com.newfiber.common.log.annotation.Log; import com.newfiber.common.log.enums.BusinessType; import com.newfiber.termite.domain.ProjectInfo; -import com.newfiber.termite.domain.dto.DeviceInfoDto; import com.newfiber.termite.domain.request.ProjectInfoQueryRequest; import com.newfiber.termite.domain.request.ProjectInfoSaveRequest; import com.newfiber.termite.domain.request.ProjectInfoUpdateRequest; @@ -15,11 +14,18 @@ import com.newfiber.termite.service.IProjectInfoService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import org.springframework.web.bind.annotation.*; - +import java.util.List; +import java.util.Set; import javax.annotation.Resource; import javax.validation.Valid; -import java.util.List; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/termiteProject") @@ -101,7 +107,15 @@ return success(list); } - + /** + * 列表查询人员项目 + */ + @GetMapping("/getUserProjectList/{userId}") + @ApiOperation(value = "列表查询人员项目", position = 60) + public Result> list(@PathVariable("userId") Long userId) { + Set list = projectInfoService.getUserProjectList(userId); + return success(list); + } /** * 通过设备SN获取上传地址 diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java index ad441f7..eb340bc 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java @@ -122,7 +122,7 @@ @PostMapping("/queryhistoryData") @ApiOperation(value = "查询历史数据", position = 60) public PageResult> queryhistoryData(TermiteHistoryQueryRequest request){ -// startPage(); + startPage(); PageResult> result =termiteService.queryhistoryData(request); return result; } @@ -208,4 +208,13 @@ public Result queryNowWeather(){ return success(termiteService.queryNowWeather()); } + + /** + */ + @PostMapping("/transferMySql2Mongo") + @ApiOperation(value = "termiteService.transferMySql2Mongo()", position = 60) + public Result transferMySql2Mongo(){ + termiteService.transferMySql2Mongo(); + return success(); + } } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java index bdb88aa..5f79da7 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java @@ -5,9 +5,7 @@ import com.newfiber.common.core.web.domain.BaseEntity; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; -import com.fasterxml.jackson.annotation.JsonFormat; import java.util.Date; -import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; import lombok.EqualsAndHashCode; @@ -136,4 +134,11 @@ @ApiModelProperty(value = "上传地址") private String uploadApi; + /** + * 项目名称 + */ + @TableField(exist = false) + @ApiModelProperty(value = "项目名称") + private String projectName; + } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java index fb04bd0..0d6416f 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java @@ -1,9 +1,24 @@ package com.newfiber.termite.domain.dto; +import com.newfiber.termite.domain.DeviceInfo; +import java.util.List; +import java.util.stream.Collectors; import lombok.Data; +import org.apache.commons.collections4.CollectionUtils; @Data public class SnAlarmStatisticDto { private String name; private Number value; + List snList; + List locationList; + + public void setDeviceInfo(List deviceInfoList){ + if(CollectionUtils.isEmpty(deviceInfoList)){ + return; + } + + snList = deviceInfoList.stream().map(DeviceInfo::getSn).collect(Collectors.toList()); + locationList = deviceInfoList.stream().map(DeviceInfo::getLocation).collect(Collectors.toList()); + } } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/request/TermiteHistoryQueryRequest.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/request/TermiteHistoryQueryRequest.java index 2cb9cef..ab1f689 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/request/TermiteHistoryQueryRequest.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/request/TermiteHistoryQueryRequest.java @@ -25,4 +25,11 @@ @ApiModelProperty(value = "结束时间") private String endtime; + + /** + * 分类(生产 production | 项目 project) + */ + @ApiModelProperty(value = "分类(生产 production | 项目 project)") + private String category = "project"; + } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IDeviceInfoService.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IDeviceInfoService.java index 51515d8..9c03500 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IDeviceInfoService.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IDeviceInfoService.java @@ -81,6 +81,14 @@ */ DeviceInfo selectDetail(String sn); + /** + * 详细查询设备信息 + * + * @param id 主键 + * @return 设备信息 + */ + DeviceInfo selectDetailByCategory(String category, String sn); + /** * 分页查询设备信息 * diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IProjectInfoService.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IProjectInfoService.java index e476c09..eed1f59 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IProjectInfoService.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IProjectInfoService.java @@ -4,7 +4,6 @@ import com.newfiber.termite.domain.request.ProjectInfoQueryRequest; import com.newfiber.termite.domain.request.ProjectInfoSaveRequest; import com.newfiber.termite.domain.request.ProjectInfoUpdateRequest; - import java.util.List; import java.util.Set; @@ -71,4 +70,6 @@ Set getUserProjectCodeList(Long userId); + Set getUserProjectList(Long userId); + } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceInfoServiceImpl.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceInfoServiceImpl.java index 063d4e7..21280ad 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceInfoServiceImpl.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceInfoServiceImpl.java @@ -146,6 +146,18 @@ return null; } + @Override + public DeviceInfo selectDetailByCategory(String category, String sn) { + DeviceInfoQueryRequest request = new DeviceInfoQueryRequest(); + request.setCategory(category); + request.setSn(sn); + List deviceInfoList = selectList(request); + if(CollectionUtils.isNotEmpty(deviceInfoList)){ + return deviceInfoList.get(0); + } + return null; + } + public DeviceInfo selectDetail(String sn, String projectCode) { DeviceInfoQueryRequest request = new DeviceInfoQueryRequest(); request.setCategory(EDeviceCategory.project.getCode()); diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceMonitoringDataServiceImpl.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceMonitoringDataServiceImpl.java index 85ccf9b..190169b 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceMonitoringDataServiceImpl.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceMonitoringDataServiceImpl.java @@ -1,5 +1,6 @@ package com.newfiber.termite.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.newfiber.common.core.exception.ServiceException; import com.newfiber.common.core.web.domain.BaseEntity; import com.newfiber.common.core.web.service.BaseServiceImpl; @@ -15,10 +16,7 @@ import java.util.Optional; import javax.annotation.Resource; import org.springframework.beans.BeanUtils; -import org.springframework.data.domain.Sort; import org.springframework.data.mongodb.core.MongoTemplate; -import org.springframework.data.mongodb.core.query.Criteria; -import org.springframework.data.mongodb.core.query.Query; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -77,28 +75,28 @@ @Override public DeviceMonitoringData lastDruging(String sn) { - Query query = new Query().with(Sort.by(Sort.Direction.DESC,"druing_datetime")). - addCriteria(Criteria.where("druing").ne(EDrugFlag.False.getCode())); - return mongoTemplate.findOne(query, DeviceMonitoringData.class, sn); +// Query query = new Query().with(Sort.by(Sort.Direction.DESC,"druing_datetime")). +// addCriteria(Criteria.where("druing").ne(EDrugFlag.False.getCode())); +// return mongoTemplate.findOne(query, DeviceMonitoringData.class, sn); // -// QueryWrapper queryWrapper = new QueryWrapper(). -// eq("sn", sn). -// ne("druing", EDrugFlag.False.getCode()). -// orderByDesc("druing_datetime").last("limit 1"); -// return getOne(queryWrapper); + QueryWrapper queryWrapper = new QueryWrapper(). + eq("sn", sn). + ne("druing", EDrugFlag.False.getCode()). + orderByDesc("druing_datetime").last("limit 1"); + return getOne(queryWrapper); } @Override public DeviceMonitoringData lastHeating(String sn) { - Query query = new Query().with(Sort.by(Sort.Direction.DESC,"heating_datetime")). - addCriteria(Criteria.where("heating").is(EHeatingFlag.True.getCode())); - return mongoTemplate.findOne(query, DeviceMonitoringData.class, sn); +// Query query = new Query().with(Sort.by(Sort.Direction.DESC,"heating_datetime")). +// addCriteria(Criteria.where("heating").is(EHeatingFlag.True.getCode())); +// return mongoTemplate.findOne(query, DeviceMonitoringData.class, sn); -// QueryWrapper queryWrapper = new QueryWrapper(). -// eq("sn", sn). -// eq("heating", EHeatingFlag.True.getCode()). -// orderByDesc("heating_datetime").last("limit 1"); -// return getOne(queryWrapper); + QueryWrapper queryWrapper = new QueryWrapper(). + eq("sn", sn). + eq("heating", EHeatingFlag.True.getCode()). + orderByDesc("heating_datetime").last("limit 1"); + return getOne(queryWrapper); } @Override @@ -113,14 +111,14 @@ @Override public List selectList(String sn, String startDate, String endDate) { - Query query = new Query().with(Sort.by(Sort.Direction.DESC,"date")). - addCriteria(Criteria.where("date").gte(startDate)).addCriteria(Criteria.where("date").lte(endDate)); - return mongoTemplate.find(query, DeviceMonitoringData.class, sn); +// Query query = new Query().with(Sort.by(Sort.Direction.DESC,"date")). +// addCriteria(Criteria.where("date").gte(startDate)).addCriteria(Criteria.where("date").lte(endDate)); +// return mongoTemplate.find(query, DeviceMonitoringData.class, sn); -// QueryWrapper queryWrapper = new QueryWrapper(). -// eq("sn", sn). -// ge("date", startDate).le("date", endDate).orderByDesc("date"); -// return list(queryWrapper); + QueryWrapper queryWrapper = new QueryWrapper(). + eq("sn", sn). + ge("date", startDate).le("date", endDate).orderByDesc("date"); + return list(queryWrapper); } @Override diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/ProjectInfoServiceImpl.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/ProjectInfoServiceImpl.java index 3e1a784..23163a0 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/ProjectInfoServiceImpl.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/ProjectInfoServiceImpl.java @@ -3,25 +3,22 @@ import com.newfiber.common.core.exception.ServiceException; import com.newfiber.common.core.web.domain.BaseEntity; import com.newfiber.common.core.web.service.BaseServiceImpl; -import com.newfiber.common.redis.service.RedisService; import com.newfiber.termite.domain.ProjectInfo; import com.newfiber.termite.domain.request.ProjectInfoQueryRequest; import com.newfiber.termite.domain.request.ProjectInfoSaveRequest; import com.newfiber.termite.domain.request.ProjectInfoUpdateRequest; import com.newfiber.termite.mapper.ProjectInfoMapper; import com.newfiber.termite.service.IProjectInfoService; -import java.util.ArrayList; import java.util.HashSet; +import java.util.List; +import java.util.Optional; import java.util.Set; +import javax.annotation.Resource; import org.apache.commons.collections4.CollectionUtils; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import javax.annotation.Resource; -import java.util.List; -import java.util.Optional; - @Service public class ProjectInfoServiceImpl extends BaseServiceImpl implements IProjectInfoService { @@ -100,4 +97,18 @@ } return projectCodeList; } + + @Override + public Set getUserProjectList(Long userId) { + List projectInfoList = list(); + Set result = new HashSet<>(); + for(ProjectInfo projectInfo : projectInfoList){ + for(String projectUserId : projectInfo.getProjectUsers().split(",")){ + if(userId.toString().equals(projectUserId)){ + result.add(projectInfo); + } + } + } + return result; + } } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/TermiteServiceImpl.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/TermiteServiceImpl.java index ed03fb7..c77fc7c 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/TermiteServiceImpl.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/TermiteServiceImpl.java @@ -2,13 +2,16 @@ import cn.hutool.core.date.DateUtil; +import cn.hutool.core.img.Img; +import cn.hutool.core.img.ImgUtil; +import cn.hutool.core.io.FileUtil; import cn.hutool.core.util.ReflectUtil; import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.newfiber.common.core.enums.EBoolean; -import com.newfiber.common.core.web.page.PageDomain; +import com.newfiber.common.core.exception.ServiceException; import com.newfiber.common.core.web.page.PageResult; import com.newfiber.common.core.web.page.PageSupport; import com.newfiber.common.core.web.service.BaseServiceImpl; @@ -45,6 +48,11 @@ import com.newfiber.termite.service.jingchu.IJingchuDeviceConfigService; import com.newfiber.termite.service.jingchu.IJingchuProjectConfigService; import com.newfiber.termite.util.CosUtil; +import com.newfiber.termite.util.FileUploadUtils; +import java.awt.Color; +import java.awt.Font; +import java.awt.Image; +import java.io.IOException; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Date; @@ -52,10 +60,11 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; import javax.annotation.Resource; import lombok.extern.slf4j.Slf4j; +import org.jetbrains.annotations.NotNull; import org.springframework.beans.BeanUtils; -import org.springframework.data.domain.Sort; import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Query; @@ -99,6 +108,8 @@ private final ExecutorService jingchuExecutorService = Executors.newFixedThreadPool(4); + Font font = new Font("微软雅黑", Font.BOLD, 50); + @Transactional(rollbackFor = Exception.class) public DataUpResponse termiteDataup(TermiteDataUpRequest termiteDateUpRequest, MultipartFile image){ String date = DateUtil.formatDateTime(new Date()); @@ -140,8 +151,9 @@ public String photoIdentify(PhotoIdentifyDto dataDto, MultipartFile image) throws Exception{ DeviceMonitoringData existedDeviceMonitoringData = deviceMonitoringDataService.selectDetail(Long.parseLong(dataDto.getId())); log.info("站点{}在{}时刻更新识别结果", existedDeviceMonitoringData.getSn(), DateUtil.formatDateTime(new Date())); + DeviceInfo deviceInfo = deviceInfoService.selectDetail(existedDeviceMonitoringData.getSn()); - String url = CosUtil.putFile(image); + String url = uploadFile(dataDto, image, existedDeviceMonitoringData, deviceInfo); DeviceMonitoringData deviceMonitoringData = new DeviceMonitoringData(); deviceMonitoringData.setId(Long.parseLong(dataDto.getId())); @@ -164,6 +176,24 @@ return url; } + @NotNull + private String uploadFile(PhotoIdentifyDto dataDto, MultipartFile image, DeviceMonitoringData existedDeviceMonitoringData, DeviceInfo deviceInfo) + throws IOException { + String url = ""; + if(EExistsAnt.True.getCode().equals(dataDto.getYesnoant())){ + Image srcImage = ImgUtil.read(image.getInputStream()); + Img img = Img.from(srcImage); + img.setPositionBaseCentre(false); + img = img.pressText("项目:" + deviceInfo.getProjectName(), Color.WHITE, font, 0, 900, 1f); + img = img.pressText("位置:" + deviceInfo.getLocation(), Color.WHITE, font, 0, 1000, 1f); + img = img.pressText("时间:" + DateUtil.format(existedDeviceMonitoringData.getUptime(), "yyyy-MM-dd HH:mm"), Color.WHITE, font, 0, 1100, 1f); + url = CosUtil.putFile(ImgUtil.toStream(img.getImg(), FileUtil.extName(image.getName())), FileUploadUtils.extractFilename(image)); + }else{ + url = CosUtil.putFile(image); + } + return url; + } + private void jingChuUpload(DeviceMonitoringData existedDeviceMonitoringData, String yesnoant) { JingchuDeviceConfig jingchuDeviceConfig = jingchuDeviceConfigService.selectDetail(existedDeviceMonitoringData.getSn()); JingchuProjectConfig jingchuProjectConfig = jingchuProjectConfigService.selectDetail(existedDeviceMonitoringData.getProjectCode()); @@ -182,8 +212,8 @@ if(EBoolean.False.getStringValue().equals(jingchuDeviceConfig.getUploadConfirmFlag())){ jingChuUpload.setStatus(EBoolean.False.getIntValue()); }else{ - int status = EExistsAnt.True.getCode().equals(yesnoant) ? 1 : 0; - jingChuUpload.setStatus(status); +// int status = EExistsAnt.True.getCode().equals(yesnoant) ? 1 : 0; + jingChuUpload.setStatus(EBoolean.True.getIntValue()); } List jingChuUploadList = new ArrayList<>(); @@ -291,49 +321,54 @@ @Override public PageResult> queryhistoryData(TermiteHistoryQueryRequest request){ - DeviceInfo deviceInfo = deviceInfoService.selectDetail(request.getSn()); - - Query query = new Query().with(Sort.by(Sort.Direction.DESC, "date")); - Criteria criteria = new Criteria(); - - if (null != request.getStarttime()) { - criteria.andOperator(Criteria.where("tt").gte(request.getStarttime())); - } - if (null != request.getEndtime()) { - criteria.andOperator(Criteria.where("tt").lte(request.getEndtime())); - } - if (null != request.getYesnoant()) { - criteria.andOperator(Criteria.where("yesnoant").lte(request.getYesnoant())); - } - if (null != request.getIdencolle()) { - criteria.andOperator(Criteria.where("idencolle").lte(request.getIdencolle())); - } - if (null != request.getDruing()) { - criteria.andOperator(Criteria.where("druing").lte(request.getDruing())); - } - - Long countNum = mongoTemplate.count(query, request.getSn()); - - PageDomain pageDomain = PageSupport.buildPageRequest(); - Integer pageNum = pageDomain.getPageNum(); - Integer pageSize = pageDomain.getPageSize(); - query.skip((pageNum - 1) * pageSize).limit(pageSize); - - List responseList = new ArrayList<>(); - List deviceMonitoringDataRealtimeList = mongoTemplate.find(query, DeviceMonitoringDataRealtime.class, request.getSn()); - for(DeviceMonitoringDataRealtime realtime : deviceMonitoringDataRealtimeList){ - TermiteInfoResponse response = new TermiteInfoResponse(); - BeanUtils.copyProperties(realtime, response); - response.setLocation(deviceInfo.getLocation()); - responseList.add(response); - } - - return new PageResult<>(responseList, countNum); -// return PageSupport.pageResult(termiteMapper.queryhistoryData(request)); +// DeviceInfo deviceInfo = deviceInfoService.selectDetail(request.getSn()); +// +// Query query = new Query().with(Sort.by(Sort.Direction.DESC, "date")); +// Criteria criteria = new Criteria(); +// +// if (null != request.getStarttime()) { +// criteria.andOperator(Criteria.where("tt").gte(request.getStarttime())); +// } +// if (null != request.getEndtime()) { +// criteria.andOperator(Criteria.where("tt").lte(request.getEndtime())); +// } +// if (null != request.getYesnoant()) { +// criteria.andOperator(Criteria.where("yesnoant").lte(request.getYesnoant())); +// } +// if (null != request.getIdencolle()) { +// criteria.andOperator(Criteria.where("idencolle").lte(request.getIdencolle())); +// } +// if (null != request.getDruing()) { +// criteria.andOperator(Criteria.where("druing").lte(request.getDruing())); +// } +// +// Long countNum = mongoTemplate.count(query, request.getSn()); +// +// PageDomain pageDomain = PageSupport.buildPageRequest(); +// Integer pageNum = pageDomain.getPageNum(); +// Integer pageSize = pageDomain.getPageSize(); +// query.skip((pageNum - 1) * pageSize).limit(pageSize); +// +// List responseList = new ArrayList<>(); +// List deviceMonitoringDataRealtimeList = mongoTemplate.find(query, DeviceMonitoringDataRealtime.class, request.getSn()); +// for(DeviceMonitoringDataRealtime realtime : deviceMonitoringDataRealtimeList){ +// TermiteInfoResponse response = new TermiteInfoResponse(); +// BeanUtils.copyProperties(realtime, response); +// response.setLocation(deviceInfo.getLocation()); +// responseList.add(response); +// } +// +// return new PageResult<>(responseList, countNum); + return PageSupport.pageResult(termiteMapper.queryhistoryData(request)); } @Override public boolean insertMonitorDevice(TermiteInfoSaveRequest request){ + DeviceInfo existDeviceInfo = deviceInfoService.selectDetailByCategory(request.getCategory(), request.getSn()); + if(null != existDeviceInfo){ + throw new ServiceException(String.format("站点%s已存在", request.getSn())); + } + DeviceInfo deviceInfo = new DeviceInfo(); BeanUtils.copyProperties(request, deviceInfo); deviceInfoService.save(deviceInfo); @@ -367,6 +402,8 @@ List result = new ArrayList<>(); //查询所有站点的数据信息 List deviceInfoList = deviceInfoService.selectList(projectCode); + List offlineDeviceList = new ArrayList<>(); + AtomicInteger outlineflag = new AtomicInteger(0); deviceInfoList.forEach(e->{ Date date1 = new Date(); @@ -376,23 +413,30 @@ double diffdays = diff/(1000l*60l*60l*24l); if(diffdays>1){ outlineflag.getAndIncrement(); + offlineDeviceList.add(e); } }else { outlineflag.getAndIncrement(); + offlineDeviceList.add(e); } }); + + List onlineDeviceList = deviceInfoList.stream().filter(t -> !offlineDeviceList.contains(t)).collect(Collectors.toList()); int onlineflag = deviceInfoList.size()- outlineflag.get(); SnAlarmStatisticDto snAlarmStatisticDto =new SnAlarmStatisticDto(); snAlarmStatisticDto.setName("在线"); snAlarmStatisticDto.setValue(onlineflag); + snAlarmStatisticDto.setDeviceInfo(onlineDeviceList); result.add(snAlarmStatisticDto); SnAlarmStatisticDto snAlarmStatisticDto2 =new SnAlarmStatisticDto(); snAlarmStatisticDto2.setName("离线"); snAlarmStatisticDto2.setValue(outlineflag.get()); + snAlarmStatisticDto2.setDeviceInfo(offlineDeviceList); result.add(snAlarmStatisticDto2); SnAlarmStatisticDto snAlarmStatisticDto3 =new SnAlarmStatisticDto(); snAlarmStatisticDto3.setName("告警"); snAlarmStatisticDto3.setValue(deviceInfoList.stream().filter(t -> null != t.getFirstWarnDatetime()).count()); + snAlarmStatisticDto3.setDeviceInfo(deviceInfoList.stream().filter(t -> null != t.getFirstWarnDatetime()).collect(Collectors.toList())); result.add(snAlarmStatisticDto3); return result; } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/util/CosUtil.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/util/CosUtil.java index 06d19f1..8f27670 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/util/CosUtil.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/util/CosUtil.java @@ -57,6 +57,25 @@ return ""; } + public static String putFile(InputStream inputStream, String fileName){ + + try { + ObjectMetadata objectMetadata = new ObjectMetadata(); + + PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, fileName, inputStream, objectMetadata); + // 设置单链接限速(如有需要),不需要可忽略 + putObjectRequest.setTrafficLimit(8*1024*1024); + PutObjectResult putObjectResult = cosClient.putObject(putObjectRequest); +// System.out.println(putObjectResult.getRequestId()); + return url + fileName; + } catch (CosServiceException e) { + e.printStackTrace(); + } catch (CosClientException e) { + e.printStackTrace(); + } + + return ""; + } private static void putLocalFileDemo() { String key = "abc/abc.txt"; String localPath = "abc.txt"; diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/resources/mapper/termite/DeviceInfoMapper.xml b/newfiber-termites/newfiber-termites-dataup/src/main/resources/mapper/termite/DeviceInfoMapper.xml index 8fca61f..9a3acf1 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/resources/mapper/termite/DeviceInfoMapper.xml +++ b/newfiber-termites/newfiber-termites-dataup/src/main/resources/mapper/termite/DeviceInfoMapper.xml @@ -26,6 +26,7 @@ + @@ -50,6 +51,7 @@ , t.camera , tpi.upload_api + , tpi.project_name diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java index 2cd61be..47293b9 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java @@ -1,5 +1,6 @@ package com.newfiber.termite.controller; +import com.newfiber.common.core.exception.ServiceException; import com.newfiber.common.core.utils.poi.ExcelUtil; import com.newfiber.common.core.web.controller.BaseController; import com.newfiber.common.core.web.domain.Result; @@ -72,6 +73,9 @@ @PostMapping("/importExcel") public Result> importExcel(MultipartFile file, String projectCode) throws Exception{ + if(null == file){ + throw new ServiceException("请上传文件"); + } ExcelUtil util = new ExcelUtil<>(DeviceInfoImportRequest.class); List deviceInfoImportRequestList = util.importExcel(file.getInputStream()); DeviceInfoBatchSaveRequest batchSaveRequest = new DeviceInfoBatchSaveRequest(projectCode, deviceInfoImportRequestList); diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java index f0bbcba..7a14a13 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java @@ -7,7 +7,6 @@ import com.newfiber.common.log.annotation.Log; import com.newfiber.common.log.enums.BusinessType; import com.newfiber.termite.domain.ProjectInfo; -import com.newfiber.termite.domain.dto.DeviceInfoDto; import com.newfiber.termite.domain.request.ProjectInfoQueryRequest; import com.newfiber.termite.domain.request.ProjectInfoSaveRequest; import com.newfiber.termite.domain.request.ProjectInfoUpdateRequest; @@ -15,11 +14,18 @@ import com.newfiber.termite.service.IProjectInfoService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import org.springframework.web.bind.annotation.*; - +import java.util.List; +import java.util.Set; import javax.annotation.Resource; import javax.validation.Valid; -import java.util.List; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/termiteProject") @@ -101,7 +107,15 @@ return success(list); } - + /** + * 列表查询人员项目 + */ + @GetMapping("/getUserProjectList/{userId}") + @ApiOperation(value = "列表查询人员项目", position = 60) + public Result> list(@PathVariable("userId") Long userId) { + Set list = projectInfoService.getUserProjectList(userId); + return success(list); + } /** * 通过设备SN获取上传地址 diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java index ad441f7..eb340bc 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java @@ -122,7 +122,7 @@ @PostMapping("/queryhistoryData") @ApiOperation(value = "查询历史数据", position = 60) public PageResult> queryhistoryData(TermiteHistoryQueryRequest request){ -// startPage(); + startPage(); PageResult> result =termiteService.queryhistoryData(request); return result; } @@ -208,4 +208,13 @@ public Result queryNowWeather(){ return success(termiteService.queryNowWeather()); } + + /** + */ + @PostMapping("/transferMySql2Mongo") + @ApiOperation(value = "termiteService.transferMySql2Mongo()", position = 60) + public Result transferMySql2Mongo(){ + termiteService.transferMySql2Mongo(); + return success(); + } } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java index bdb88aa..5f79da7 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java @@ -5,9 +5,7 @@ import com.newfiber.common.core.web.domain.BaseEntity; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; -import com.fasterxml.jackson.annotation.JsonFormat; import java.util.Date; -import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; import lombok.EqualsAndHashCode; @@ -136,4 +134,11 @@ @ApiModelProperty(value = "上传地址") private String uploadApi; + /** + * 项目名称 + */ + @TableField(exist = false) + @ApiModelProperty(value = "项目名称") + private String projectName; + } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java index fb04bd0..0d6416f 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java @@ -1,9 +1,24 @@ package com.newfiber.termite.domain.dto; +import com.newfiber.termite.domain.DeviceInfo; +import java.util.List; +import java.util.stream.Collectors; import lombok.Data; +import org.apache.commons.collections4.CollectionUtils; @Data public class SnAlarmStatisticDto { private String name; private Number value; + List snList; + List locationList; + + public void setDeviceInfo(List deviceInfoList){ + if(CollectionUtils.isEmpty(deviceInfoList)){ + return; + } + + snList = deviceInfoList.stream().map(DeviceInfo::getSn).collect(Collectors.toList()); + locationList = deviceInfoList.stream().map(DeviceInfo::getLocation).collect(Collectors.toList()); + } } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/request/TermiteHistoryQueryRequest.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/request/TermiteHistoryQueryRequest.java index 2cb9cef..ab1f689 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/request/TermiteHistoryQueryRequest.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/request/TermiteHistoryQueryRequest.java @@ -25,4 +25,11 @@ @ApiModelProperty(value = "结束时间") private String endtime; + + /** + * 分类(生产 production | 项目 project) + */ + @ApiModelProperty(value = "分类(生产 production | 项目 project)") + private String category = "project"; + } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IDeviceInfoService.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IDeviceInfoService.java index 51515d8..9c03500 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IDeviceInfoService.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IDeviceInfoService.java @@ -81,6 +81,14 @@ */ DeviceInfo selectDetail(String sn); + /** + * 详细查询设备信息 + * + * @param id 主键 + * @return 设备信息 + */ + DeviceInfo selectDetailByCategory(String category, String sn); + /** * 分页查询设备信息 * diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IProjectInfoService.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IProjectInfoService.java index e476c09..eed1f59 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IProjectInfoService.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IProjectInfoService.java @@ -4,7 +4,6 @@ import com.newfiber.termite.domain.request.ProjectInfoQueryRequest; import com.newfiber.termite.domain.request.ProjectInfoSaveRequest; import com.newfiber.termite.domain.request.ProjectInfoUpdateRequest; - import java.util.List; import java.util.Set; @@ -71,4 +70,6 @@ Set getUserProjectCodeList(Long userId); + Set getUserProjectList(Long userId); + } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceInfoServiceImpl.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceInfoServiceImpl.java index 063d4e7..21280ad 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceInfoServiceImpl.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceInfoServiceImpl.java @@ -146,6 +146,18 @@ return null; } + @Override + public DeviceInfo selectDetailByCategory(String category, String sn) { + DeviceInfoQueryRequest request = new DeviceInfoQueryRequest(); + request.setCategory(category); + request.setSn(sn); + List deviceInfoList = selectList(request); + if(CollectionUtils.isNotEmpty(deviceInfoList)){ + return deviceInfoList.get(0); + } + return null; + } + public DeviceInfo selectDetail(String sn, String projectCode) { DeviceInfoQueryRequest request = new DeviceInfoQueryRequest(); request.setCategory(EDeviceCategory.project.getCode()); diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceMonitoringDataServiceImpl.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceMonitoringDataServiceImpl.java index 85ccf9b..190169b 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceMonitoringDataServiceImpl.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceMonitoringDataServiceImpl.java @@ -1,5 +1,6 @@ package com.newfiber.termite.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.newfiber.common.core.exception.ServiceException; import com.newfiber.common.core.web.domain.BaseEntity; import com.newfiber.common.core.web.service.BaseServiceImpl; @@ -15,10 +16,7 @@ import java.util.Optional; import javax.annotation.Resource; import org.springframework.beans.BeanUtils; -import org.springframework.data.domain.Sort; import org.springframework.data.mongodb.core.MongoTemplate; -import org.springframework.data.mongodb.core.query.Criteria; -import org.springframework.data.mongodb.core.query.Query; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -77,28 +75,28 @@ @Override public DeviceMonitoringData lastDruging(String sn) { - Query query = new Query().with(Sort.by(Sort.Direction.DESC,"druing_datetime")). - addCriteria(Criteria.where("druing").ne(EDrugFlag.False.getCode())); - return mongoTemplate.findOne(query, DeviceMonitoringData.class, sn); +// Query query = new Query().with(Sort.by(Sort.Direction.DESC,"druing_datetime")). +// addCriteria(Criteria.where("druing").ne(EDrugFlag.False.getCode())); +// return mongoTemplate.findOne(query, DeviceMonitoringData.class, sn); // -// QueryWrapper queryWrapper = new QueryWrapper(). -// eq("sn", sn). -// ne("druing", EDrugFlag.False.getCode()). -// orderByDesc("druing_datetime").last("limit 1"); -// return getOne(queryWrapper); + QueryWrapper queryWrapper = new QueryWrapper(). + eq("sn", sn). + ne("druing", EDrugFlag.False.getCode()). + orderByDesc("druing_datetime").last("limit 1"); + return getOne(queryWrapper); } @Override public DeviceMonitoringData lastHeating(String sn) { - Query query = new Query().with(Sort.by(Sort.Direction.DESC,"heating_datetime")). - addCriteria(Criteria.where("heating").is(EHeatingFlag.True.getCode())); - return mongoTemplate.findOne(query, DeviceMonitoringData.class, sn); +// Query query = new Query().with(Sort.by(Sort.Direction.DESC,"heating_datetime")). +// addCriteria(Criteria.where("heating").is(EHeatingFlag.True.getCode())); +// return mongoTemplate.findOne(query, DeviceMonitoringData.class, sn); -// QueryWrapper queryWrapper = new QueryWrapper(). -// eq("sn", sn). -// eq("heating", EHeatingFlag.True.getCode()). -// orderByDesc("heating_datetime").last("limit 1"); -// return getOne(queryWrapper); + QueryWrapper queryWrapper = new QueryWrapper(). + eq("sn", sn). + eq("heating", EHeatingFlag.True.getCode()). + orderByDesc("heating_datetime").last("limit 1"); + return getOne(queryWrapper); } @Override @@ -113,14 +111,14 @@ @Override public List selectList(String sn, String startDate, String endDate) { - Query query = new Query().with(Sort.by(Sort.Direction.DESC,"date")). - addCriteria(Criteria.where("date").gte(startDate)).addCriteria(Criteria.where("date").lte(endDate)); - return mongoTemplate.find(query, DeviceMonitoringData.class, sn); +// Query query = new Query().with(Sort.by(Sort.Direction.DESC,"date")). +// addCriteria(Criteria.where("date").gte(startDate)).addCriteria(Criteria.where("date").lte(endDate)); +// return mongoTemplate.find(query, DeviceMonitoringData.class, sn); -// QueryWrapper queryWrapper = new QueryWrapper(). -// eq("sn", sn). -// ge("date", startDate).le("date", endDate).orderByDesc("date"); -// return list(queryWrapper); + QueryWrapper queryWrapper = new QueryWrapper(). + eq("sn", sn). + ge("date", startDate).le("date", endDate).orderByDesc("date"); + return list(queryWrapper); } @Override diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/ProjectInfoServiceImpl.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/ProjectInfoServiceImpl.java index 3e1a784..23163a0 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/ProjectInfoServiceImpl.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/ProjectInfoServiceImpl.java @@ -3,25 +3,22 @@ import com.newfiber.common.core.exception.ServiceException; import com.newfiber.common.core.web.domain.BaseEntity; import com.newfiber.common.core.web.service.BaseServiceImpl; -import com.newfiber.common.redis.service.RedisService; import com.newfiber.termite.domain.ProjectInfo; import com.newfiber.termite.domain.request.ProjectInfoQueryRequest; import com.newfiber.termite.domain.request.ProjectInfoSaveRequest; import com.newfiber.termite.domain.request.ProjectInfoUpdateRequest; import com.newfiber.termite.mapper.ProjectInfoMapper; import com.newfiber.termite.service.IProjectInfoService; -import java.util.ArrayList; import java.util.HashSet; +import java.util.List; +import java.util.Optional; import java.util.Set; +import javax.annotation.Resource; import org.apache.commons.collections4.CollectionUtils; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import javax.annotation.Resource; -import java.util.List; -import java.util.Optional; - @Service public class ProjectInfoServiceImpl extends BaseServiceImpl implements IProjectInfoService { @@ -100,4 +97,18 @@ } return projectCodeList; } + + @Override + public Set getUserProjectList(Long userId) { + List projectInfoList = list(); + Set result = new HashSet<>(); + for(ProjectInfo projectInfo : projectInfoList){ + for(String projectUserId : projectInfo.getProjectUsers().split(",")){ + if(userId.toString().equals(projectUserId)){ + result.add(projectInfo); + } + } + } + return result; + } } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/TermiteServiceImpl.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/TermiteServiceImpl.java index ed03fb7..c77fc7c 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/TermiteServiceImpl.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/TermiteServiceImpl.java @@ -2,13 +2,16 @@ import cn.hutool.core.date.DateUtil; +import cn.hutool.core.img.Img; +import cn.hutool.core.img.ImgUtil; +import cn.hutool.core.io.FileUtil; import cn.hutool.core.util.ReflectUtil; import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.newfiber.common.core.enums.EBoolean; -import com.newfiber.common.core.web.page.PageDomain; +import com.newfiber.common.core.exception.ServiceException; import com.newfiber.common.core.web.page.PageResult; import com.newfiber.common.core.web.page.PageSupport; import com.newfiber.common.core.web.service.BaseServiceImpl; @@ -45,6 +48,11 @@ import com.newfiber.termite.service.jingchu.IJingchuDeviceConfigService; import com.newfiber.termite.service.jingchu.IJingchuProjectConfigService; import com.newfiber.termite.util.CosUtil; +import com.newfiber.termite.util.FileUploadUtils; +import java.awt.Color; +import java.awt.Font; +import java.awt.Image; +import java.io.IOException; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Date; @@ -52,10 +60,11 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; import javax.annotation.Resource; import lombok.extern.slf4j.Slf4j; +import org.jetbrains.annotations.NotNull; import org.springframework.beans.BeanUtils; -import org.springframework.data.domain.Sort; import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Query; @@ -99,6 +108,8 @@ private final ExecutorService jingchuExecutorService = Executors.newFixedThreadPool(4); + Font font = new Font("微软雅黑", Font.BOLD, 50); + @Transactional(rollbackFor = Exception.class) public DataUpResponse termiteDataup(TermiteDataUpRequest termiteDateUpRequest, MultipartFile image){ String date = DateUtil.formatDateTime(new Date()); @@ -140,8 +151,9 @@ public String photoIdentify(PhotoIdentifyDto dataDto, MultipartFile image) throws Exception{ DeviceMonitoringData existedDeviceMonitoringData = deviceMonitoringDataService.selectDetail(Long.parseLong(dataDto.getId())); log.info("站点{}在{}时刻更新识别结果", existedDeviceMonitoringData.getSn(), DateUtil.formatDateTime(new Date())); + DeviceInfo deviceInfo = deviceInfoService.selectDetail(existedDeviceMonitoringData.getSn()); - String url = CosUtil.putFile(image); + String url = uploadFile(dataDto, image, existedDeviceMonitoringData, deviceInfo); DeviceMonitoringData deviceMonitoringData = new DeviceMonitoringData(); deviceMonitoringData.setId(Long.parseLong(dataDto.getId())); @@ -164,6 +176,24 @@ return url; } + @NotNull + private String uploadFile(PhotoIdentifyDto dataDto, MultipartFile image, DeviceMonitoringData existedDeviceMonitoringData, DeviceInfo deviceInfo) + throws IOException { + String url = ""; + if(EExistsAnt.True.getCode().equals(dataDto.getYesnoant())){ + Image srcImage = ImgUtil.read(image.getInputStream()); + Img img = Img.from(srcImage); + img.setPositionBaseCentre(false); + img = img.pressText("项目:" + deviceInfo.getProjectName(), Color.WHITE, font, 0, 900, 1f); + img = img.pressText("位置:" + deviceInfo.getLocation(), Color.WHITE, font, 0, 1000, 1f); + img = img.pressText("时间:" + DateUtil.format(existedDeviceMonitoringData.getUptime(), "yyyy-MM-dd HH:mm"), Color.WHITE, font, 0, 1100, 1f); + url = CosUtil.putFile(ImgUtil.toStream(img.getImg(), FileUtil.extName(image.getName())), FileUploadUtils.extractFilename(image)); + }else{ + url = CosUtil.putFile(image); + } + return url; + } + private void jingChuUpload(DeviceMonitoringData existedDeviceMonitoringData, String yesnoant) { JingchuDeviceConfig jingchuDeviceConfig = jingchuDeviceConfigService.selectDetail(existedDeviceMonitoringData.getSn()); JingchuProjectConfig jingchuProjectConfig = jingchuProjectConfigService.selectDetail(existedDeviceMonitoringData.getProjectCode()); @@ -182,8 +212,8 @@ if(EBoolean.False.getStringValue().equals(jingchuDeviceConfig.getUploadConfirmFlag())){ jingChuUpload.setStatus(EBoolean.False.getIntValue()); }else{ - int status = EExistsAnt.True.getCode().equals(yesnoant) ? 1 : 0; - jingChuUpload.setStatus(status); +// int status = EExistsAnt.True.getCode().equals(yesnoant) ? 1 : 0; + jingChuUpload.setStatus(EBoolean.True.getIntValue()); } List jingChuUploadList = new ArrayList<>(); @@ -291,49 +321,54 @@ @Override public PageResult> queryhistoryData(TermiteHistoryQueryRequest request){ - DeviceInfo deviceInfo = deviceInfoService.selectDetail(request.getSn()); - - Query query = new Query().with(Sort.by(Sort.Direction.DESC, "date")); - Criteria criteria = new Criteria(); - - if (null != request.getStarttime()) { - criteria.andOperator(Criteria.where("tt").gte(request.getStarttime())); - } - if (null != request.getEndtime()) { - criteria.andOperator(Criteria.where("tt").lte(request.getEndtime())); - } - if (null != request.getYesnoant()) { - criteria.andOperator(Criteria.where("yesnoant").lte(request.getYesnoant())); - } - if (null != request.getIdencolle()) { - criteria.andOperator(Criteria.where("idencolle").lte(request.getIdencolle())); - } - if (null != request.getDruing()) { - criteria.andOperator(Criteria.where("druing").lte(request.getDruing())); - } - - Long countNum = mongoTemplate.count(query, request.getSn()); - - PageDomain pageDomain = PageSupport.buildPageRequest(); - Integer pageNum = pageDomain.getPageNum(); - Integer pageSize = pageDomain.getPageSize(); - query.skip((pageNum - 1) * pageSize).limit(pageSize); - - List responseList = new ArrayList<>(); - List deviceMonitoringDataRealtimeList = mongoTemplate.find(query, DeviceMonitoringDataRealtime.class, request.getSn()); - for(DeviceMonitoringDataRealtime realtime : deviceMonitoringDataRealtimeList){ - TermiteInfoResponse response = new TermiteInfoResponse(); - BeanUtils.copyProperties(realtime, response); - response.setLocation(deviceInfo.getLocation()); - responseList.add(response); - } - - return new PageResult<>(responseList, countNum); -// return PageSupport.pageResult(termiteMapper.queryhistoryData(request)); +// DeviceInfo deviceInfo = deviceInfoService.selectDetail(request.getSn()); +// +// Query query = new Query().with(Sort.by(Sort.Direction.DESC, "date")); +// Criteria criteria = new Criteria(); +// +// if (null != request.getStarttime()) { +// criteria.andOperator(Criteria.where("tt").gte(request.getStarttime())); +// } +// if (null != request.getEndtime()) { +// criteria.andOperator(Criteria.where("tt").lte(request.getEndtime())); +// } +// if (null != request.getYesnoant()) { +// criteria.andOperator(Criteria.where("yesnoant").lte(request.getYesnoant())); +// } +// if (null != request.getIdencolle()) { +// criteria.andOperator(Criteria.where("idencolle").lte(request.getIdencolle())); +// } +// if (null != request.getDruing()) { +// criteria.andOperator(Criteria.where("druing").lte(request.getDruing())); +// } +// +// Long countNum = mongoTemplate.count(query, request.getSn()); +// +// PageDomain pageDomain = PageSupport.buildPageRequest(); +// Integer pageNum = pageDomain.getPageNum(); +// Integer pageSize = pageDomain.getPageSize(); +// query.skip((pageNum - 1) * pageSize).limit(pageSize); +// +// List responseList = new ArrayList<>(); +// List deviceMonitoringDataRealtimeList = mongoTemplate.find(query, DeviceMonitoringDataRealtime.class, request.getSn()); +// for(DeviceMonitoringDataRealtime realtime : deviceMonitoringDataRealtimeList){ +// TermiteInfoResponse response = new TermiteInfoResponse(); +// BeanUtils.copyProperties(realtime, response); +// response.setLocation(deviceInfo.getLocation()); +// responseList.add(response); +// } +// +// return new PageResult<>(responseList, countNum); + return PageSupport.pageResult(termiteMapper.queryhistoryData(request)); } @Override public boolean insertMonitorDevice(TermiteInfoSaveRequest request){ + DeviceInfo existDeviceInfo = deviceInfoService.selectDetailByCategory(request.getCategory(), request.getSn()); + if(null != existDeviceInfo){ + throw new ServiceException(String.format("站点%s已存在", request.getSn())); + } + DeviceInfo deviceInfo = new DeviceInfo(); BeanUtils.copyProperties(request, deviceInfo); deviceInfoService.save(deviceInfo); @@ -367,6 +402,8 @@ List result = new ArrayList<>(); //查询所有站点的数据信息 List deviceInfoList = deviceInfoService.selectList(projectCode); + List offlineDeviceList = new ArrayList<>(); + AtomicInteger outlineflag = new AtomicInteger(0); deviceInfoList.forEach(e->{ Date date1 = new Date(); @@ -376,23 +413,30 @@ double diffdays = diff/(1000l*60l*60l*24l); if(diffdays>1){ outlineflag.getAndIncrement(); + offlineDeviceList.add(e); } }else { outlineflag.getAndIncrement(); + offlineDeviceList.add(e); } }); + + List onlineDeviceList = deviceInfoList.stream().filter(t -> !offlineDeviceList.contains(t)).collect(Collectors.toList()); int onlineflag = deviceInfoList.size()- outlineflag.get(); SnAlarmStatisticDto snAlarmStatisticDto =new SnAlarmStatisticDto(); snAlarmStatisticDto.setName("在线"); snAlarmStatisticDto.setValue(onlineflag); + snAlarmStatisticDto.setDeviceInfo(onlineDeviceList); result.add(snAlarmStatisticDto); SnAlarmStatisticDto snAlarmStatisticDto2 =new SnAlarmStatisticDto(); snAlarmStatisticDto2.setName("离线"); snAlarmStatisticDto2.setValue(outlineflag.get()); + snAlarmStatisticDto2.setDeviceInfo(offlineDeviceList); result.add(snAlarmStatisticDto2); SnAlarmStatisticDto snAlarmStatisticDto3 =new SnAlarmStatisticDto(); snAlarmStatisticDto3.setName("告警"); snAlarmStatisticDto3.setValue(deviceInfoList.stream().filter(t -> null != t.getFirstWarnDatetime()).count()); + snAlarmStatisticDto3.setDeviceInfo(deviceInfoList.stream().filter(t -> null != t.getFirstWarnDatetime()).collect(Collectors.toList())); result.add(snAlarmStatisticDto3); return result; } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/util/CosUtil.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/util/CosUtil.java index 06d19f1..8f27670 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/util/CosUtil.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/util/CosUtil.java @@ -57,6 +57,25 @@ return ""; } + public static String putFile(InputStream inputStream, String fileName){ + + try { + ObjectMetadata objectMetadata = new ObjectMetadata(); + + PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, fileName, inputStream, objectMetadata); + // 设置单链接限速(如有需要),不需要可忽略 + putObjectRequest.setTrafficLimit(8*1024*1024); + PutObjectResult putObjectResult = cosClient.putObject(putObjectRequest); +// System.out.println(putObjectResult.getRequestId()); + return url + fileName; + } catch (CosServiceException e) { + e.printStackTrace(); + } catch (CosClientException e) { + e.printStackTrace(); + } + + return ""; + } private static void putLocalFileDemo() { String key = "abc/abc.txt"; String localPath = "abc.txt"; diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/resources/mapper/termite/DeviceInfoMapper.xml b/newfiber-termites/newfiber-termites-dataup/src/main/resources/mapper/termite/DeviceInfoMapper.xml index 8fca61f..9a3acf1 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/resources/mapper/termite/DeviceInfoMapper.xml +++ b/newfiber-termites/newfiber-termites-dataup/src/main/resources/mapper/termite/DeviceInfoMapper.xml @@ -26,6 +26,7 @@ + @@ -50,6 +51,7 @@ , t.camera , tpi.upload_api + , tpi.project_name diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/resources/mapper/termite/DeviceMonitoringDataMapper.xml b/newfiber-termites/newfiber-termites-dataup/src/main/resources/mapper/termite/DeviceMonitoringDataMapper.xml index 650b281..e2761e6 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/resources/mapper/termite/DeviceMonitoringDataMapper.xml +++ b/newfiber-termites/newfiber-termites-dataup/src/main/resources/mapper/termite/DeviceMonitoringDataMapper.xml @@ -63,7 +63,7 @@ from ter_device_monitoring_data t - where t.del_flag = 0 + where t.del_flag = 0 and di.project_code is not null order by t.${request.orderBy} @@ -73,7 +73,7 @@ from ter_device_monitoring_data t - where t.id = #{id} and t.del_flag = 0 + where t.id = #{id} and t.del_flag = 0 and di.project_code is not null limit 1 diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java index 2cd61be..47293b9 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java @@ -1,5 +1,6 @@ package com.newfiber.termite.controller; +import com.newfiber.common.core.exception.ServiceException; import com.newfiber.common.core.utils.poi.ExcelUtil; import com.newfiber.common.core.web.controller.BaseController; import com.newfiber.common.core.web.domain.Result; @@ -72,6 +73,9 @@ @PostMapping("/importExcel") public Result> importExcel(MultipartFile file, String projectCode) throws Exception{ + if(null == file){ + throw new ServiceException("请上传文件"); + } ExcelUtil util = new ExcelUtil<>(DeviceInfoImportRequest.class); List deviceInfoImportRequestList = util.importExcel(file.getInputStream()); DeviceInfoBatchSaveRequest batchSaveRequest = new DeviceInfoBatchSaveRequest(projectCode, deviceInfoImportRequestList); diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java index f0bbcba..7a14a13 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java @@ -7,7 +7,6 @@ import com.newfiber.common.log.annotation.Log; import com.newfiber.common.log.enums.BusinessType; import com.newfiber.termite.domain.ProjectInfo; -import com.newfiber.termite.domain.dto.DeviceInfoDto; import com.newfiber.termite.domain.request.ProjectInfoQueryRequest; import com.newfiber.termite.domain.request.ProjectInfoSaveRequest; import com.newfiber.termite.domain.request.ProjectInfoUpdateRequest; @@ -15,11 +14,18 @@ import com.newfiber.termite.service.IProjectInfoService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import org.springframework.web.bind.annotation.*; - +import java.util.List; +import java.util.Set; import javax.annotation.Resource; import javax.validation.Valid; -import java.util.List; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/termiteProject") @@ -101,7 +107,15 @@ return success(list); } - + /** + * 列表查询人员项目 + */ + @GetMapping("/getUserProjectList/{userId}") + @ApiOperation(value = "列表查询人员项目", position = 60) + public Result> list(@PathVariable("userId") Long userId) { + Set list = projectInfoService.getUserProjectList(userId); + return success(list); + } /** * 通过设备SN获取上传地址 diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java index ad441f7..eb340bc 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java @@ -122,7 +122,7 @@ @PostMapping("/queryhistoryData") @ApiOperation(value = "查询历史数据", position = 60) public PageResult> queryhistoryData(TermiteHistoryQueryRequest request){ -// startPage(); + startPage(); PageResult> result =termiteService.queryhistoryData(request); return result; } @@ -208,4 +208,13 @@ public Result queryNowWeather(){ return success(termiteService.queryNowWeather()); } + + /** + */ + @PostMapping("/transferMySql2Mongo") + @ApiOperation(value = "termiteService.transferMySql2Mongo()", position = 60) + public Result transferMySql2Mongo(){ + termiteService.transferMySql2Mongo(); + return success(); + } } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java index bdb88aa..5f79da7 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java @@ -5,9 +5,7 @@ import com.newfiber.common.core.web.domain.BaseEntity; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; -import com.fasterxml.jackson.annotation.JsonFormat; import java.util.Date; -import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; import lombok.EqualsAndHashCode; @@ -136,4 +134,11 @@ @ApiModelProperty(value = "上传地址") private String uploadApi; + /** + * 项目名称 + */ + @TableField(exist = false) + @ApiModelProperty(value = "项目名称") + private String projectName; + } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java index fb04bd0..0d6416f 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java @@ -1,9 +1,24 @@ package com.newfiber.termite.domain.dto; +import com.newfiber.termite.domain.DeviceInfo; +import java.util.List; +import java.util.stream.Collectors; import lombok.Data; +import org.apache.commons.collections4.CollectionUtils; @Data public class SnAlarmStatisticDto { private String name; private Number value; + List snList; + List locationList; + + public void setDeviceInfo(List deviceInfoList){ + if(CollectionUtils.isEmpty(deviceInfoList)){ + return; + } + + snList = deviceInfoList.stream().map(DeviceInfo::getSn).collect(Collectors.toList()); + locationList = deviceInfoList.stream().map(DeviceInfo::getLocation).collect(Collectors.toList()); + } } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/request/TermiteHistoryQueryRequest.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/request/TermiteHistoryQueryRequest.java index 2cb9cef..ab1f689 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/request/TermiteHistoryQueryRequest.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/request/TermiteHistoryQueryRequest.java @@ -25,4 +25,11 @@ @ApiModelProperty(value = "结束时间") private String endtime; + + /** + * 分类(生产 production | 项目 project) + */ + @ApiModelProperty(value = "分类(生产 production | 项目 project)") + private String category = "project"; + } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IDeviceInfoService.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IDeviceInfoService.java index 51515d8..9c03500 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IDeviceInfoService.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IDeviceInfoService.java @@ -81,6 +81,14 @@ */ DeviceInfo selectDetail(String sn); + /** + * 详细查询设备信息 + * + * @param id 主键 + * @return 设备信息 + */ + DeviceInfo selectDetailByCategory(String category, String sn); + /** * 分页查询设备信息 * diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IProjectInfoService.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IProjectInfoService.java index e476c09..eed1f59 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IProjectInfoService.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IProjectInfoService.java @@ -4,7 +4,6 @@ import com.newfiber.termite.domain.request.ProjectInfoQueryRequest; import com.newfiber.termite.domain.request.ProjectInfoSaveRequest; import com.newfiber.termite.domain.request.ProjectInfoUpdateRequest; - import java.util.List; import java.util.Set; @@ -71,4 +70,6 @@ Set getUserProjectCodeList(Long userId); + Set getUserProjectList(Long userId); + } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceInfoServiceImpl.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceInfoServiceImpl.java index 063d4e7..21280ad 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceInfoServiceImpl.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceInfoServiceImpl.java @@ -146,6 +146,18 @@ return null; } + @Override + public DeviceInfo selectDetailByCategory(String category, String sn) { + DeviceInfoQueryRequest request = new DeviceInfoQueryRequest(); + request.setCategory(category); + request.setSn(sn); + List deviceInfoList = selectList(request); + if(CollectionUtils.isNotEmpty(deviceInfoList)){ + return deviceInfoList.get(0); + } + return null; + } + public DeviceInfo selectDetail(String sn, String projectCode) { DeviceInfoQueryRequest request = new DeviceInfoQueryRequest(); request.setCategory(EDeviceCategory.project.getCode()); diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceMonitoringDataServiceImpl.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceMonitoringDataServiceImpl.java index 85ccf9b..190169b 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceMonitoringDataServiceImpl.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceMonitoringDataServiceImpl.java @@ -1,5 +1,6 @@ package com.newfiber.termite.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.newfiber.common.core.exception.ServiceException; import com.newfiber.common.core.web.domain.BaseEntity; import com.newfiber.common.core.web.service.BaseServiceImpl; @@ -15,10 +16,7 @@ import java.util.Optional; import javax.annotation.Resource; import org.springframework.beans.BeanUtils; -import org.springframework.data.domain.Sort; import org.springframework.data.mongodb.core.MongoTemplate; -import org.springframework.data.mongodb.core.query.Criteria; -import org.springframework.data.mongodb.core.query.Query; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -77,28 +75,28 @@ @Override public DeviceMonitoringData lastDruging(String sn) { - Query query = new Query().with(Sort.by(Sort.Direction.DESC,"druing_datetime")). - addCriteria(Criteria.where("druing").ne(EDrugFlag.False.getCode())); - return mongoTemplate.findOne(query, DeviceMonitoringData.class, sn); +// Query query = new Query().with(Sort.by(Sort.Direction.DESC,"druing_datetime")). +// addCriteria(Criteria.where("druing").ne(EDrugFlag.False.getCode())); +// return mongoTemplate.findOne(query, DeviceMonitoringData.class, sn); // -// QueryWrapper queryWrapper = new QueryWrapper(). -// eq("sn", sn). -// ne("druing", EDrugFlag.False.getCode()). -// orderByDesc("druing_datetime").last("limit 1"); -// return getOne(queryWrapper); + QueryWrapper queryWrapper = new QueryWrapper(). + eq("sn", sn). + ne("druing", EDrugFlag.False.getCode()). + orderByDesc("druing_datetime").last("limit 1"); + return getOne(queryWrapper); } @Override public DeviceMonitoringData lastHeating(String sn) { - Query query = new Query().with(Sort.by(Sort.Direction.DESC,"heating_datetime")). - addCriteria(Criteria.where("heating").is(EHeatingFlag.True.getCode())); - return mongoTemplate.findOne(query, DeviceMonitoringData.class, sn); +// Query query = new Query().with(Sort.by(Sort.Direction.DESC,"heating_datetime")). +// addCriteria(Criteria.where("heating").is(EHeatingFlag.True.getCode())); +// return mongoTemplate.findOne(query, DeviceMonitoringData.class, sn); -// QueryWrapper queryWrapper = new QueryWrapper(). -// eq("sn", sn). -// eq("heating", EHeatingFlag.True.getCode()). -// orderByDesc("heating_datetime").last("limit 1"); -// return getOne(queryWrapper); + QueryWrapper queryWrapper = new QueryWrapper(). + eq("sn", sn). + eq("heating", EHeatingFlag.True.getCode()). + orderByDesc("heating_datetime").last("limit 1"); + return getOne(queryWrapper); } @Override @@ -113,14 +111,14 @@ @Override public List selectList(String sn, String startDate, String endDate) { - Query query = new Query().with(Sort.by(Sort.Direction.DESC,"date")). - addCriteria(Criteria.where("date").gte(startDate)).addCriteria(Criteria.where("date").lte(endDate)); - return mongoTemplate.find(query, DeviceMonitoringData.class, sn); +// Query query = new Query().with(Sort.by(Sort.Direction.DESC,"date")). +// addCriteria(Criteria.where("date").gte(startDate)).addCriteria(Criteria.where("date").lte(endDate)); +// return mongoTemplate.find(query, DeviceMonitoringData.class, sn); -// QueryWrapper queryWrapper = new QueryWrapper(). -// eq("sn", sn). -// ge("date", startDate).le("date", endDate).orderByDesc("date"); -// return list(queryWrapper); + QueryWrapper queryWrapper = new QueryWrapper(). + eq("sn", sn). + ge("date", startDate).le("date", endDate).orderByDesc("date"); + return list(queryWrapper); } @Override diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/ProjectInfoServiceImpl.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/ProjectInfoServiceImpl.java index 3e1a784..23163a0 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/ProjectInfoServiceImpl.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/ProjectInfoServiceImpl.java @@ -3,25 +3,22 @@ import com.newfiber.common.core.exception.ServiceException; import com.newfiber.common.core.web.domain.BaseEntity; import com.newfiber.common.core.web.service.BaseServiceImpl; -import com.newfiber.common.redis.service.RedisService; import com.newfiber.termite.domain.ProjectInfo; import com.newfiber.termite.domain.request.ProjectInfoQueryRequest; import com.newfiber.termite.domain.request.ProjectInfoSaveRequest; import com.newfiber.termite.domain.request.ProjectInfoUpdateRequest; import com.newfiber.termite.mapper.ProjectInfoMapper; import com.newfiber.termite.service.IProjectInfoService; -import java.util.ArrayList; import java.util.HashSet; +import java.util.List; +import java.util.Optional; import java.util.Set; +import javax.annotation.Resource; import org.apache.commons.collections4.CollectionUtils; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import javax.annotation.Resource; -import java.util.List; -import java.util.Optional; - @Service public class ProjectInfoServiceImpl extends BaseServiceImpl implements IProjectInfoService { @@ -100,4 +97,18 @@ } return projectCodeList; } + + @Override + public Set getUserProjectList(Long userId) { + List projectInfoList = list(); + Set result = new HashSet<>(); + for(ProjectInfo projectInfo : projectInfoList){ + for(String projectUserId : projectInfo.getProjectUsers().split(",")){ + if(userId.toString().equals(projectUserId)){ + result.add(projectInfo); + } + } + } + return result; + } } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/TermiteServiceImpl.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/TermiteServiceImpl.java index ed03fb7..c77fc7c 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/TermiteServiceImpl.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/TermiteServiceImpl.java @@ -2,13 +2,16 @@ import cn.hutool.core.date.DateUtil; +import cn.hutool.core.img.Img; +import cn.hutool.core.img.ImgUtil; +import cn.hutool.core.io.FileUtil; import cn.hutool.core.util.ReflectUtil; import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.newfiber.common.core.enums.EBoolean; -import com.newfiber.common.core.web.page.PageDomain; +import com.newfiber.common.core.exception.ServiceException; import com.newfiber.common.core.web.page.PageResult; import com.newfiber.common.core.web.page.PageSupport; import com.newfiber.common.core.web.service.BaseServiceImpl; @@ -45,6 +48,11 @@ import com.newfiber.termite.service.jingchu.IJingchuDeviceConfigService; import com.newfiber.termite.service.jingchu.IJingchuProjectConfigService; import com.newfiber.termite.util.CosUtil; +import com.newfiber.termite.util.FileUploadUtils; +import java.awt.Color; +import java.awt.Font; +import java.awt.Image; +import java.io.IOException; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Date; @@ -52,10 +60,11 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; import javax.annotation.Resource; import lombok.extern.slf4j.Slf4j; +import org.jetbrains.annotations.NotNull; import org.springframework.beans.BeanUtils; -import org.springframework.data.domain.Sort; import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Query; @@ -99,6 +108,8 @@ private final ExecutorService jingchuExecutorService = Executors.newFixedThreadPool(4); + Font font = new Font("微软雅黑", Font.BOLD, 50); + @Transactional(rollbackFor = Exception.class) public DataUpResponse termiteDataup(TermiteDataUpRequest termiteDateUpRequest, MultipartFile image){ String date = DateUtil.formatDateTime(new Date()); @@ -140,8 +151,9 @@ public String photoIdentify(PhotoIdentifyDto dataDto, MultipartFile image) throws Exception{ DeviceMonitoringData existedDeviceMonitoringData = deviceMonitoringDataService.selectDetail(Long.parseLong(dataDto.getId())); log.info("站点{}在{}时刻更新识别结果", existedDeviceMonitoringData.getSn(), DateUtil.formatDateTime(new Date())); + DeviceInfo deviceInfo = deviceInfoService.selectDetail(existedDeviceMonitoringData.getSn()); - String url = CosUtil.putFile(image); + String url = uploadFile(dataDto, image, existedDeviceMonitoringData, deviceInfo); DeviceMonitoringData deviceMonitoringData = new DeviceMonitoringData(); deviceMonitoringData.setId(Long.parseLong(dataDto.getId())); @@ -164,6 +176,24 @@ return url; } + @NotNull + private String uploadFile(PhotoIdentifyDto dataDto, MultipartFile image, DeviceMonitoringData existedDeviceMonitoringData, DeviceInfo deviceInfo) + throws IOException { + String url = ""; + if(EExistsAnt.True.getCode().equals(dataDto.getYesnoant())){ + Image srcImage = ImgUtil.read(image.getInputStream()); + Img img = Img.from(srcImage); + img.setPositionBaseCentre(false); + img = img.pressText("项目:" + deviceInfo.getProjectName(), Color.WHITE, font, 0, 900, 1f); + img = img.pressText("位置:" + deviceInfo.getLocation(), Color.WHITE, font, 0, 1000, 1f); + img = img.pressText("时间:" + DateUtil.format(existedDeviceMonitoringData.getUptime(), "yyyy-MM-dd HH:mm"), Color.WHITE, font, 0, 1100, 1f); + url = CosUtil.putFile(ImgUtil.toStream(img.getImg(), FileUtil.extName(image.getName())), FileUploadUtils.extractFilename(image)); + }else{ + url = CosUtil.putFile(image); + } + return url; + } + private void jingChuUpload(DeviceMonitoringData existedDeviceMonitoringData, String yesnoant) { JingchuDeviceConfig jingchuDeviceConfig = jingchuDeviceConfigService.selectDetail(existedDeviceMonitoringData.getSn()); JingchuProjectConfig jingchuProjectConfig = jingchuProjectConfigService.selectDetail(existedDeviceMonitoringData.getProjectCode()); @@ -182,8 +212,8 @@ if(EBoolean.False.getStringValue().equals(jingchuDeviceConfig.getUploadConfirmFlag())){ jingChuUpload.setStatus(EBoolean.False.getIntValue()); }else{ - int status = EExistsAnt.True.getCode().equals(yesnoant) ? 1 : 0; - jingChuUpload.setStatus(status); +// int status = EExistsAnt.True.getCode().equals(yesnoant) ? 1 : 0; + jingChuUpload.setStatus(EBoolean.True.getIntValue()); } List jingChuUploadList = new ArrayList<>(); @@ -291,49 +321,54 @@ @Override public PageResult> queryhistoryData(TermiteHistoryQueryRequest request){ - DeviceInfo deviceInfo = deviceInfoService.selectDetail(request.getSn()); - - Query query = new Query().with(Sort.by(Sort.Direction.DESC, "date")); - Criteria criteria = new Criteria(); - - if (null != request.getStarttime()) { - criteria.andOperator(Criteria.where("tt").gte(request.getStarttime())); - } - if (null != request.getEndtime()) { - criteria.andOperator(Criteria.where("tt").lte(request.getEndtime())); - } - if (null != request.getYesnoant()) { - criteria.andOperator(Criteria.where("yesnoant").lte(request.getYesnoant())); - } - if (null != request.getIdencolle()) { - criteria.andOperator(Criteria.where("idencolle").lte(request.getIdencolle())); - } - if (null != request.getDruing()) { - criteria.andOperator(Criteria.where("druing").lte(request.getDruing())); - } - - Long countNum = mongoTemplate.count(query, request.getSn()); - - PageDomain pageDomain = PageSupport.buildPageRequest(); - Integer pageNum = pageDomain.getPageNum(); - Integer pageSize = pageDomain.getPageSize(); - query.skip((pageNum - 1) * pageSize).limit(pageSize); - - List responseList = new ArrayList<>(); - List deviceMonitoringDataRealtimeList = mongoTemplate.find(query, DeviceMonitoringDataRealtime.class, request.getSn()); - for(DeviceMonitoringDataRealtime realtime : deviceMonitoringDataRealtimeList){ - TermiteInfoResponse response = new TermiteInfoResponse(); - BeanUtils.copyProperties(realtime, response); - response.setLocation(deviceInfo.getLocation()); - responseList.add(response); - } - - return new PageResult<>(responseList, countNum); -// return PageSupport.pageResult(termiteMapper.queryhistoryData(request)); +// DeviceInfo deviceInfo = deviceInfoService.selectDetail(request.getSn()); +// +// Query query = new Query().with(Sort.by(Sort.Direction.DESC, "date")); +// Criteria criteria = new Criteria(); +// +// if (null != request.getStarttime()) { +// criteria.andOperator(Criteria.where("tt").gte(request.getStarttime())); +// } +// if (null != request.getEndtime()) { +// criteria.andOperator(Criteria.where("tt").lte(request.getEndtime())); +// } +// if (null != request.getYesnoant()) { +// criteria.andOperator(Criteria.where("yesnoant").lte(request.getYesnoant())); +// } +// if (null != request.getIdencolle()) { +// criteria.andOperator(Criteria.where("idencolle").lte(request.getIdencolle())); +// } +// if (null != request.getDruing()) { +// criteria.andOperator(Criteria.where("druing").lte(request.getDruing())); +// } +// +// Long countNum = mongoTemplate.count(query, request.getSn()); +// +// PageDomain pageDomain = PageSupport.buildPageRequest(); +// Integer pageNum = pageDomain.getPageNum(); +// Integer pageSize = pageDomain.getPageSize(); +// query.skip((pageNum - 1) * pageSize).limit(pageSize); +// +// List responseList = new ArrayList<>(); +// List deviceMonitoringDataRealtimeList = mongoTemplate.find(query, DeviceMonitoringDataRealtime.class, request.getSn()); +// for(DeviceMonitoringDataRealtime realtime : deviceMonitoringDataRealtimeList){ +// TermiteInfoResponse response = new TermiteInfoResponse(); +// BeanUtils.copyProperties(realtime, response); +// response.setLocation(deviceInfo.getLocation()); +// responseList.add(response); +// } +// +// return new PageResult<>(responseList, countNum); + return PageSupport.pageResult(termiteMapper.queryhistoryData(request)); } @Override public boolean insertMonitorDevice(TermiteInfoSaveRequest request){ + DeviceInfo existDeviceInfo = deviceInfoService.selectDetailByCategory(request.getCategory(), request.getSn()); + if(null != existDeviceInfo){ + throw new ServiceException(String.format("站点%s已存在", request.getSn())); + } + DeviceInfo deviceInfo = new DeviceInfo(); BeanUtils.copyProperties(request, deviceInfo); deviceInfoService.save(deviceInfo); @@ -367,6 +402,8 @@ List result = new ArrayList<>(); //查询所有站点的数据信息 List deviceInfoList = deviceInfoService.selectList(projectCode); + List offlineDeviceList = new ArrayList<>(); + AtomicInteger outlineflag = new AtomicInteger(0); deviceInfoList.forEach(e->{ Date date1 = new Date(); @@ -376,23 +413,30 @@ double diffdays = diff/(1000l*60l*60l*24l); if(diffdays>1){ outlineflag.getAndIncrement(); + offlineDeviceList.add(e); } }else { outlineflag.getAndIncrement(); + offlineDeviceList.add(e); } }); + + List onlineDeviceList = deviceInfoList.stream().filter(t -> !offlineDeviceList.contains(t)).collect(Collectors.toList()); int onlineflag = deviceInfoList.size()- outlineflag.get(); SnAlarmStatisticDto snAlarmStatisticDto =new SnAlarmStatisticDto(); snAlarmStatisticDto.setName("在线"); snAlarmStatisticDto.setValue(onlineflag); + snAlarmStatisticDto.setDeviceInfo(onlineDeviceList); result.add(snAlarmStatisticDto); SnAlarmStatisticDto snAlarmStatisticDto2 =new SnAlarmStatisticDto(); snAlarmStatisticDto2.setName("离线"); snAlarmStatisticDto2.setValue(outlineflag.get()); + snAlarmStatisticDto2.setDeviceInfo(offlineDeviceList); result.add(snAlarmStatisticDto2); SnAlarmStatisticDto snAlarmStatisticDto3 =new SnAlarmStatisticDto(); snAlarmStatisticDto3.setName("告警"); snAlarmStatisticDto3.setValue(deviceInfoList.stream().filter(t -> null != t.getFirstWarnDatetime()).count()); + snAlarmStatisticDto3.setDeviceInfo(deviceInfoList.stream().filter(t -> null != t.getFirstWarnDatetime()).collect(Collectors.toList())); result.add(snAlarmStatisticDto3); return result; } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/util/CosUtil.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/util/CosUtil.java index 06d19f1..8f27670 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/util/CosUtil.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/util/CosUtil.java @@ -57,6 +57,25 @@ return ""; } + public static String putFile(InputStream inputStream, String fileName){ + + try { + ObjectMetadata objectMetadata = new ObjectMetadata(); + + PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, fileName, inputStream, objectMetadata); + // 设置单链接限速(如有需要),不需要可忽略 + putObjectRequest.setTrafficLimit(8*1024*1024); + PutObjectResult putObjectResult = cosClient.putObject(putObjectRequest); +// System.out.println(putObjectResult.getRequestId()); + return url + fileName; + } catch (CosServiceException e) { + e.printStackTrace(); + } catch (CosClientException e) { + e.printStackTrace(); + } + + return ""; + } private static void putLocalFileDemo() { String key = "abc/abc.txt"; String localPath = "abc.txt"; diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/resources/mapper/termite/DeviceInfoMapper.xml b/newfiber-termites/newfiber-termites-dataup/src/main/resources/mapper/termite/DeviceInfoMapper.xml index 8fca61f..9a3acf1 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/resources/mapper/termite/DeviceInfoMapper.xml +++ b/newfiber-termites/newfiber-termites-dataup/src/main/resources/mapper/termite/DeviceInfoMapper.xml @@ -26,6 +26,7 @@ + @@ -50,6 +51,7 @@ , t.camera , tpi.upload_api + , tpi.project_name diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/resources/mapper/termite/DeviceMonitoringDataMapper.xml b/newfiber-termites/newfiber-termites-dataup/src/main/resources/mapper/termite/DeviceMonitoringDataMapper.xml index 650b281..e2761e6 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/resources/mapper/termite/DeviceMonitoringDataMapper.xml +++ b/newfiber-termites/newfiber-termites-dataup/src/main/resources/mapper/termite/DeviceMonitoringDataMapper.xml @@ -63,7 +63,7 @@ from ter_device_monitoring_data t - where t.del_flag = 0 + where t.del_flag = 0 and di.project_code is not null order by t.${request.orderBy} @@ -73,7 +73,7 @@ from ter_device_monitoring_data t - where t.id = #{id} and t.del_flag = 0 + where t.id = #{id} and t.del_flag = 0 and di.project_code is not null limit 1 diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/resources/mapper/termite/TermiteMapper.xml b/newfiber-termites/newfiber-termites-dataup/src/main/resources/mapper/termite/TermiteMapper.xml index 276400d..16129a0 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/resources/mapper/termite/TermiteMapper.xml +++ b/newfiber-termites/newfiber-termites-dataup/src/main/resources/mapper/termite/TermiteMapper.xml @@ -98,7 +98,7 @@ tb.location FROM ter_device_monitoring_data ta - left join ter_device_info tb on ta.sn=tb.sn + left join ter_device_info tb on ta.sn=tb.sn where ta.sn=#{request.sn} and ta.yesnoant =#{request.yesnoant} @@ -109,7 +109,9 @@ and ta.druing =#{request.druing} - + + and tb.category = #{request.category} + and ta.uptime > #{request.starttime} diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java index 2cd61be..47293b9 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/DeviceInfoController.java @@ -1,5 +1,6 @@ package com.newfiber.termite.controller; +import com.newfiber.common.core.exception.ServiceException; import com.newfiber.common.core.utils.poi.ExcelUtil; import com.newfiber.common.core.web.controller.BaseController; import com.newfiber.common.core.web.domain.Result; @@ -72,6 +73,9 @@ @PostMapping("/importExcel") public Result> importExcel(MultipartFile file, String projectCode) throws Exception{ + if(null == file){ + throw new ServiceException("请上传文件"); + } ExcelUtil util = new ExcelUtil<>(DeviceInfoImportRequest.class); List deviceInfoImportRequestList = util.importExcel(file.getInputStream()); DeviceInfoBatchSaveRequest batchSaveRequest = new DeviceInfoBatchSaveRequest(projectCode, deviceInfoImportRequestList); diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java index f0bbcba..7a14a13 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/ProjectInfoController.java @@ -7,7 +7,6 @@ import com.newfiber.common.log.annotation.Log; import com.newfiber.common.log.enums.BusinessType; import com.newfiber.termite.domain.ProjectInfo; -import com.newfiber.termite.domain.dto.DeviceInfoDto; import com.newfiber.termite.domain.request.ProjectInfoQueryRequest; import com.newfiber.termite.domain.request.ProjectInfoSaveRequest; import com.newfiber.termite.domain.request.ProjectInfoUpdateRequest; @@ -15,11 +14,18 @@ import com.newfiber.termite.service.IProjectInfoService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import org.springframework.web.bind.annotation.*; - +import java.util.List; +import java.util.Set; import javax.annotation.Resource; import javax.validation.Valid; -import java.util.List; +import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/termiteProject") @@ -101,7 +107,15 @@ return success(list); } - + /** + * 列表查询人员项目 + */ + @GetMapping("/getUserProjectList/{userId}") + @ApiOperation(value = "列表查询人员项目", position = 60) + public Result> list(@PathVariable("userId") Long userId) { + Set list = projectInfoService.getUserProjectList(userId); + return success(list); + } /** * 通过设备SN获取上传地址 diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java index ad441f7..eb340bc 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/controller/TermiteController.java @@ -122,7 +122,7 @@ @PostMapping("/queryhistoryData") @ApiOperation(value = "查询历史数据", position = 60) public PageResult> queryhistoryData(TermiteHistoryQueryRequest request){ -// startPage(); + startPage(); PageResult> result =termiteService.queryhistoryData(request); return result; } @@ -208,4 +208,13 @@ public Result queryNowWeather(){ return success(termiteService.queryNowWeather()); } + + /** + */ + @PostMapping("/transferMySql2Mongo") + @ApiOperation(value = "termiteService.transferMySql2Mongo()", position = 60) + public Result transferMySql2Mongo(){ + termiteService.transferMySql2Mongo(); + return success(); + } } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java index bdb88aa..5f79da7 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/DeviceInfo.java @@ -5,9 +5,7 @@ import com.newfiber.common.core.web.domain.BaseEntity; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; -import com.fasterxml.jackson.annotation.JsonFormat; import java.util.Date; -import com.fasterxml.jackson.annotation.JsonFormat; import lombok.Data; import lombok.EqualsAndHashCode; @@ -136,4 +134,11 @@ @ApiModelProperty(value = "上传地址") private String uploadApi; + /** + * 项目名称 + */ + @TableField(exist = false) + @ApiModelProperty(value = "项目名称") + private String projectName; + } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java index fb04bd0..0d6416f 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/dto/SnAlarmStatisticDto.java @@ -1,9 +1,24 @@ package com.newfiber.termite.domain.dto; +import com.newfiber.termite.domain.DeviceInfo; +import java.util.List; +import java.util.stream.Collectors; import lombok.Data; +import org.apache.commons.collections4.CollectionUtils; @Data public class SnAlarmStatisticDto { private String name; private Number value; + List snList; + List locationList; + + public void setDeviceInfo(List deviceInfoList){ + if(CollectionUtils.isEmpty(deviceInfoList)){ + return; + } + + snList = deviceInfoList.stream().map(DeviceInfo::getSn).collect(Collectors.toList()); + locationList = deviceInfoList.stream().map(DeviceInfo::getLocation).collect(Collectors.toList()); + } } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/request/TermiteHistoryQueryRequest.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/request/TermiteHistoryQueryRequest.java index 2cb9cef..ab1f689 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/request/TermiteHistoryQueryRequest.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/domain/request/TermiteHistoryQueryRequest.java @@ -25,4 +25,11 @@ @ApiModelProperty(value = "结束时间") private String endtime; + + /** + * 分类(生产 production | 项目 project) + */ + @ApiModelProperty(value = "分类(生产 production | 项目 project)") + private String category = "project"; + } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IDeviceInfoService.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IDeviceInfoService.java index 51515d8..9c03500 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IDeviceInfoService.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IDeviceInfoService.java @@ -81,6 +81,14 @@ */ DeviceInfo selectDetail(String sn); + /** + * 详细查询设备信息 + * + * @param id 主键 + * @return 设备信息 + */ + DeviceInfo selectDetailByCategory(String category, String sn); + /** * 分页查询设备信息 * diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IProjectInfoService.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IProjectInfoService.java index e476c09..eed1f59 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IProjectInfoService.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/IProjectInfoService.java @@ -4,7 +4,6 @@ import com.newfiber.termite.domain.request.ProjectInfoQueryRequest; import com.newfiber.termite.domain.request.ProjectInfoSaveRequest; import com.newfiber.termite.domain.request.ProjectInfoUpdateRequest; - import java.util.List; import java.util.Set; @@ -71,4 +70,6 @@ Set getUserProjectCodeList(Long userId); + Set getUserProjectList(Long userId); + } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceInfoServiceImpl.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceInfoServiceImpl.java index 063d4e7..21280ad 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceInfoServiceImpl.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceInfoServiceImpl.java @@ -146,6 +146,18 @@ return null; } + @Override + public DeviceInfo selectDetailByCategory(String category, String sn) { + DeviceInfoQueryRequest request = new DeviceInfoQueryRequest(); + request.setCategory(category); + request.setSn(sn); + List deviceInfoList = selectList(request); + if(CollectionUtils.isNotEmpty(deviceInfoList)){ + return deviceInfoList.get(0); + } + return null; + } + public DeviceInfo selectDetail(String sn, String projectCode) { DeviceInfoQueryRequest request = new DeviceInfoQueryRequest(); request.setCategory(EDeviceCategory.project.getCode()); diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceMonitoringDataServiceImpl.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceMonitoringDataServiceImpl.java index 85ccf9b..190169b 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceMonitoringDataServiceImpl.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/DeviceMonitoringDataServiceImpl.java @@ -1,5 +1,6 @@ package com.newfiber.termite.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.newfiber.common.core.exception.ServiceException; import com.newfiber.common.core.web.domain.BaseEntity; import com.newfiber.common.core.web.service.BaseServiceImpl; @@ -15,10 +16,7 @@ import java.util.Optional; import javax.annotation.Resource; import org.springframework.beans.BeanUtils; -import org.springframework.data.domain.Sort; import org.springframework.data.mongodb.core.MongoTemplate; -import org.springframework.data.mongodb.core.query.Criteria; -import org.springframework.data.mongodb.core.query.Query; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -77,28 +75,28 @@ @Override public DeviceMonitoringData lastDruging(String sn) { - Query query = new Query().with(Sort.by(Sort.Direction.DESC,"druing_datetime")). - addCriteria(Criteria.where("druing").ne(EDrugFlag.False.getCode())); - return mongoTemplate.findOne(query, DeviceMonitoringData.class, sn); +// Query query = new Query().with(Sort.by(Sort.Direction.DESC,"druing_datetime")). +// addCriteria(Criteria.where("druing").ne(EDrugFlag.False.getCode())); +// return mongoTemplate.findOne(query, DeviceMonitoringData.class, sn); // -// QueryWrapper queryWrapper = new QueryWrapper(). -// eq("sn", sn). -// ne("druing", EDrugFlag.False.getCode()). -// orderByDesc("druing_datetime").last("limit 1"); -// return getOne(queryWrapper); + QueryWrapper queryWrapper = new QueryWrapper(). + eq("sn", sn). + ne("druing", EDrugFlag.False.getCode()). + orderByDesc("druing_datetime").last("limit 1"); + return getOne(queryWrapper); } @Override public DeviceMonitoringData lastHeating(String sn) { - Query query = new Query().with(Sort.by(Sort.Direction.DESC,"heating_datetime")). - addCriteria(Criteria.where("heating").is(EHeatingFlag.True.getCode())); - return mongoTemplate.findOne(query, DeviceMonitoringData.class, sn); +// Query query = new Query().with(Sort.by(Sort.Direction.DESC,"heating_datetime")). +// addCriteria(Criteria.where("heating").is(EHeatingFlag.True.getCode())); +// return mongoTemplate.findOne(query, DeviceMonitoringData.class, sn); -// QueryWrapper queryWrapper = new QueryWrapper(). -// eq("sn", sn). -// eq("heating", EHeatingFlag.True.getCode()). -// orderByDesc("heating_datetime").last("limit 1"); -// return getOne(queryWrapper); + QueryWrapper queryWrapper = new QueryWrapper(). + eq("sn", sn). + eq("heating", EHeatingFlag.True.getCode()). + orderByDesc("heating_datetime").last("limit 1"); + return getOne(queryWrapper); } @Override @@ -113,14 +111,14 @@ @Override public List selectList(String sn, String startDate, String endDate) { - Query query = new Query().with(Sort.by(Sort.Direction.DESC,"date")). - addCriteria(Criteria.where("date").gte(startDate)).addCriteria(Criteria.where("date").lte(endDate)); - return mongoTemplate.find(query, DeviceMonitoringData.class, sn); +// Query query = new Query().with(Sort.by(Sort.Direction.DESC,"date")). +// addCriteria(Criteria.where("date").gte(startDate)).addCriteria(Criteria.where("date").lte(endDate)); +// return mongoTemplate.find(query, DeviceMonitoringData.class, sn); -// QueryWrapper queryWrapper = new QueryWrapper(). -// eq("sn", sn). -// ge("date", startDate).le("date", endDate).orderByDesc("date"); -// return list(queryWrapper); + QueryWrapper queryWrapper = new QueryWrapper(). + eq("sn", sn). + ge("date", startDate).le("date", endDate).orderByDesc("date"); + return list(queryWrapper); } @Override diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/ProjectInfoServiceImpl.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/ProjectInfoServiceImpl.java index 3e1a784..23163a0 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/ProjectInfoServiceImpl.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/ProjectInfoServiceImpl.java @@ -3,25 +3,22 @@ import com.newfiber.common.core.exception.ServiceException; import com.newfiber.common.core.web.domain.BaseEntity; import com.newfiber.common.core.web.service.BaseServiceImpl; -import com.newfiber.common.redis.service.RedisService; import com.newfiber.termite.domain.ProjectInfo; import com.newfiber.termite.domain.request.ProjectInfoQueryRequest; import com.newfiber.termite.domain.request.ProjectInfoSaveRequest; import com.newfiber.termite.domain.request.ProjectInfoUpdateRequest; import com.newfiber.termite.mapper.ProjectInfoMapper; import com.newfiber.termite.service.IProjectInfoService; -import java.util.ArrayList; import java.util.HashSet; +import java.util.List; +import java.util.Optional; import java.util.Set; +import javax.annotation.Resource; import org.apache.commons.collections4.CollectionUtils; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import javax.annotation.Resource; -import java.util.List; -import java.util.Optional; - @Service public class ProjectInfoServiceImpl extends BaseServiceImpl implements IProjectInfoService { @@ -100,4 +97,18 @@ } return projectCodeList; } + + @Override + public Set getUserProjectList(Long userId) { + List projectInfoList = list(); + Set result = new HashSet<>(); + for(ProjectInfo projectInfo : projectInfoList){ + for(String projectUserId : projectInfo.getProjectUsers().split(",")){ + if(userId.toString().equals(projectUserId)){ + result.add(projectInfo); + } + } + } + return result; + } } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/TermiteServiceImpl.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/TermiteServiceImpl.java index ed03fb7..c77fc7c 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/TermiteServiceImpl.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/service/impl/TermiteServiceImpl.java @@ -2,13 +2,16 @@ import cn.hutool.core.date.DateUtil; +import cn.hutool.core.img.Img; +import cn.hutool.core.img.ImgUtil; +import cn.hutool.core.io.FileUtil; import cn.hutool.core.util.ReflectUtil; import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpUtil; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.newfiber.common.core.enums.EBoolean; -import com.newfiber.common.core.web.page.PageDomain; +import com.newfiber.common.core.exception.ServiceException; import com.newfiber.common.core.web.page.PageResult; import com.newfiber.common.core.web.page.PageSupport; import com.newfiber.common.core.web.service.BaseServiceImpl; @@ -45,6 +48,11 @@ import com.newfiber.termite.service.jingchu.IJingchuDeviceConfigService; import com.newfiber.termite.service.jingchu.IJingchuProjectConfigService; import com.newfiber.termite.util.CosUtil; +import com.newfiber.termite.util.FileUploadUtils; +import java.awt.Color; +import java.awt.Font; +import java.awt.Image; +import java.io.IOException; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Date; @@ -52,10 +60,11 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; import javax.annotation.Resource; import lombok.extern.slf4j.Slf4j; +import org.jetbrains.annotations.NotNull; import org.springframework.beans.BeanUtils; -import org.springframework.data.domain.Sort; import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Query; @@ -99,6 +108,8 @@ private final ExecutorService jingchuExecutorService = Executors.newFixedThreadPool(4); + Font font = new Font("微软雅黑", Font.BOLD, 50); + @Transactional(rollbackFor = Exception.class) public DataUpResponse termiteDataup(TermiteDataUpRequest termiteDateUpRequest, MultipartFile image){ String date = DateUtil.formatDateTime(new Date()); @@ -140,8 +151,9 @@ public String photoIdentify(PhotoIdentifyDto dataDto, MultipartFile image) throws Exception{ DeviceMonitoringData existedDeviceMonitoringData = deviceMonitoringDataService.selectDetail(Long.parseLong(dataDto.getId())); log.info("站点{}在{}时刻更新识别结果", existedDeviceMonitoringData.getSn(), DateUtil.formatDateTime(new Date())); + DeviceInfo deviceInfo = deviceInfoService.selectDetail(existedDeviceMonitoringData.getSn()); - String url = CosUtil.putFile(image); + String url = uploadFile(dataDto, image, existedDeviceMonitoringData, deviceInfo); DeviceMonitoringData deviceMonitoringData = new DeviceMonitoringData(); deviceMonitoringData.setId(Long.parseLong(dataDto.getId())); @@ -164,6 +176,24 @@ return url; } + @NotNull + private String uploadFile(PhotoIdentifyDto dataDto, MultipartFile image, DeviceMonitoringData existedDeviceMonitoringData, DeviceInfo deviceInfo) + throws IOException { + String url = ""; + if(EExistsAnt.True.getCode().equals(dataDto.getYesnoant())){ + Image srcImage = ImgUtil.read(image.getInputStream()); + Img img = Img.from(srcImage); + img.setPositionBaseCentre(false); + img = img.pressText("项目:" + deviceInfo.getProjectName(), Color.WHITE, font, 0, 900, 1f); + img = img.pressText("位置:" + deviceInfo.getLocation(), Color.WHITE, font, 0, 1000, 1f); + img = img.pressText("时间:" + DateUtil.format(existedDeviceMonitoringData.getUptime(), "yyyy-MM-dd HH:mm"), Color.WHITE, font, 0, 1100, 1f); + url = CosUtil.putFile(ImgUtil.toStream(img.getImg(), FileUtil.extName(image.getName())), FileUploadUtils.extractFilename(image)); + }else{ + url = CosUtil.putFile(image); + } + return url; + } + private void jingChuUpload(DeviceMonitoringData existedDeviceMonitoringData, String yesnoant) { JingchuDeviceConfig jingchuDeviceConfig = jingchuDeviceConfigService.selectDetail(existedDeviceMonitoringData.getSn()); JingchuProjectConfig jingchuProjectConfig = jingchuProjectConfigService.selectDetail(existedDeviceMonitoringData.getProjectCode()); @@ -182,8 +212,8 @@ if(EBoolean.False.getStringValue().equals(jingchuDeviceConfig.getUploadConfirmFlag())){ jingChuUpload.setStatus(EBoolean.False.getIntValue()); }else{ - int status = EExistsAnt.True.getCode().equals(yesnoant) ? 1 : 0; - jingChuUpload.setStatus(status); +// int status = EExistsAnt.True.getCode().equals(yesnoant) ? 1 : 0; + jingChuUpload.setStatus(EBoolean.True.getIntValue()); } List jingChuUploadList = new ArrayList<>(); @@ -291,49 +321,54 @@ @Override public PageResult> queryhistoryData(TermiteHistoryQueryRequest request){ - DeviceInfo deviceInfo = deviceInfoService.selectDetail(request.getSn()); - - Query query = new Query().with(Sort.by(Sort.Direction.DESC, "date")); - Criteria criteria = new Criteria(); - - if (null != request.getStarttime()) { - criteria.andOperator(Criteria.where("tt").gte(request.getStarttime())); - } - if (null != request.getEndtime()) { - criteria.andOperator(Criteria.where("tt").lte(request.getEndtime())); - } - if (null != request.getYesnoant()) { - criteria.andOperator(Criteria.where("yesnoant").lte(request.getYesnoant())); - } - if (null != request.getIdencolle()) { - criteria.andOperator(Criteria.where("idencolle").lte(request.getIdencolle())); - } - if (null != request.getDruing()) { - criteria.andOperator(Criteria.where("druing").lte(request.getDruing())); - } - - Long countNum = mongoTemplate.count(query, request.getSn()); - - PageDomain pageDomain = PageSupport.buildPageRequest(); - Integer pageNum = pageDomain.getPageNum(); - Integer pageSize = pageDomain.getPageSize(); - query.skip((pageNum - 1) * pageSize).limit(pageSize); - - List responseList = new ArrayList<>(); - List deviceMonitoringDataRealtimeList = mongoTemplate.find(query, DeviceMonitoringDataRealtime.class, request.getSn()); - for(DeviceMonitoringDataRealtime realtime : deviceMonitoringDataRealtimeList){ - TermiteInfoResponse response = new TermiteInfoResponse(); - BeanUtils.copyProperties(realtime, response); - response.setLocation(deviceInfo.getLocation()); - responseList.add(response); - } - - return new PageResult<>(responseList, countNum); -// return PageSupport.pageResult(termiteMapper.queryhistoryData(request)); +// DeviceInfo deviceInfo = deviceInfoService.selectDetail(request.getSn()); +// +// Query query = new Query().with(Sort.by(Sort.Direction.DESC, "date")); +// Criteria criteria = new Criteria(); +// +// if (null != request.getStarttime()) { +// criteria.andOperator(Criteria.where("tt").gte(request.getStarttime())); +// } +// if (null != request.getEndtime()) { +// criteria.andOperator(Criteria.where("tt").lte(request.getEndtime())); +// } +// if (null != request.getYesnoant()) { +// criteria.andOperator(Criteria.where("yesnoant").lte(request.getYesnoant())); +// } +// if (null != request.getIdencolle()) { +// criteria.andOperator(Criteria.where("idencolle").lte(request.getIdencolle())); +// } +// if (null != request.getDruing()) { +// criteria.andOperator(Criteria.where("druing").lte(request.getDruing())); +// } +// +// Long countNum = mongoTemplate.count(query, request.getSn()); +// +// PageDomain pageDomain = PageSupport.buildPageRequest(); +// Integer pageNum = pageDomain.getPageNum(); +// Integer pageSize = pageDomain.getPageSize(); +// query.skip((pageNum - 1) * pageSize).limit(pageSize); +// +// List responseList = new ArrayList<>(); +// List deviceMonitoringDataRealtimeList = mongoTemplate.find(query, DeviceMonitoringDataRealtime.class, request.getSn()); +// for(DeviceMonitoringDataRealtime realtime : deviceMonitoringDataRealtimeList){ +// TermiteInfoResponse response = new TermiteInfoResponse(); +// BeanUtils.copyProperties(realtime, response); +// response.setLocation(deviceInfo.getLocation()); +// responseList.add(response); +// } +// +// return new PageResult<>(responseList, countNum); + return PageSupport.pageResult(termiteMapper.queryhistoryData(request)); } @Override public boolean insertMonitorDevice(TermiteInfoSaveRequest request){ + DeviceInfo existDeviceInfo = deviceInfoService.selectDetailByCategory(request.getCategory(), request.getSn()); + if(null != existDeviceInfo){ + throw new ServiceException(String.format("站点%s已存在", request.getSn())); + } + DeviceInfo deviceInfo = new DeviceInfo(); BeanUtils.copyProperties(request, deviceInfo); deviceInfoService.save(deviceInfo); @@ -367,6 +402,8 @@ List result = new ArrayList<>(); //查询所有站点的数据信息 List deviceInfoList = deviceInfoService.selectList(projectCode); + List offlineDeviceList = new ArrayList<>(); + AtomicInteger outlineflag = new AtomicInteger(0); deviceInfoList.forEach(e->{ Date date1 = new Date(); @@ -376,23 +413,30 @@ double diffdays = diff/(1000l*60l*60l*24l); if(diffdays>1){ outlineflag.getAndIncrement(); + offlineDeviceList.add(e); } }else { outlineflag.getAndIncrement(); + offlineDeviceList.add(e); } }); + + List onlineDeviceList = deviceInfoList.stream().filter(t -> !offlineDeviceList.contains(t)).collect(Collectors.toList()); int onlineflag = deviceInfoList.size()- outlineflag.get(); SnAlarmStatisticDto snAlarmStatisticDto =new SnAlarmStatisticDto(); snAlarmStatisticDto.setName("在线"); snAlarmStatisticDto.setValue(onlineflag); + snAlarmStatisticDto.setDeviceInfo(onlineDeviceList); result.add(snAlarmStatisticDto); SnAlarmStatisticDto snAlarmStatisticDto2 =new SnAlarmStatisticDto(); snAlarmStatisticDto2.setName("离线"); snAlarmStatisticDto2.setValue(outlineflag.get()); + snAlarmStatisticDto2.setDeviceInfo(offlineDeviceList); result.add(snAlarmStatisticDto2); SnAlarmStatisticDto snAlarmStatisticDto3 =new SnAlarmStatisticDto(); snAlarmStatisticDto3.setName("告警"); snAlarmStatisticDto3.setValue(deviceInfoList.stream().filter(t -> null != t.getFirstWarnDatetime()).count()); + snAlarmStatisticDto3.setDeviceInfo(deviceInfoList.stream().filter(t -> null != t.getFirstWarnDatetime()).collect(Collectors.toList())); result.add(snAlarmStatisticDto3); return result; } diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/util/CosUtil.java b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/util/CosUtil.java index 06d19f1..8f27670 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/util/CosUtil.java +++ b/newfiber-termites/newfiber-termites-dataup/src/main/java/com/newfiber/termite/util/CosUtil.java @@ -57,6 +57,25 @@ return ""; } + public static String putFile(InputStream inputStream, String fileName){ + + try { + ObjectMetadata objectMetadata = new ObjectMetadata(); + + PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, fileName, inputStream, objectMetadata); + // 设置单链接限速(如有需要),不需要可忽略 + putObjectRequest.setTrafficLimit(8*1024*1024); + PutObjectResult putObjectResult = cosClient.putObject(putObjectRequest); +// System.out.println(putObjectResult.getRequestId()); + return url + fileName; + } catch (CosServiceException e) { + e.printStackTrace(); + } catch (CosClientException e) { + e.printStackTrace(); + } + + return ""; + } private static void putLocalFileDemo() { String key = "abc/abc.txt"; String localPath = "abc.txt"; diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/resources/mapper/termite/DeviceInfoMapper.xml b/newfiber-termites/newfiber-termites-dataup/src/main/resources/mapper/termite/DeviceInfoMapper.xml index 8fca61f..9a3acf1 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/resources/mapper/termite/DeviceInfoMapper.xml +++ b/newfiber-termites/newfiber-termites-dataup/src/main/resources/mapper/termite/DeviceInfoMapper.xml @@ -26,6 +26,7 @@ + @@ -50,6 +51,7 @@ , t.camera , tpi.upload_api + , tpi.project_name diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/resources/mapper/termite/DeviceMonitoringDataMapper.xml b/newfiber-termites/newfiber-termites-dataup/src/main/resources/mapper/termite/DeviceMonitoringDataMapper.xml index 650b281..e2761e6 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/resources/mapper/termite/DeviceMonitoringDataMapper.xml +++ b/newfiber-termites/newfiber-termites-dataup/src/main/resources/mapper/termite/DeviceMonitoringDataMapper.xml @@ -63,7 +63,7 @@ from ter_device_monitoring_data t - where t.del_flag = 0 + where t.del_flag = 0 and di.project_code is not null order by t.${request.orderBy} @@ -73,7 +73,7 @@ from ter_device_monitoring_data t - where t.id = #{id} and t.del_flag = 0 + where t.id = #{id} and t.del_flag = 0 and di.project_code is not null limit 1 diff --git a/newfiber-termites/newfiber-termites-dataup/src/main/resources/mapper/termite/TermiteMapper.xml b/newfiber-termites/newfiber-termites-dataup/src/main/resources/mapper/termite/TermiteMapper.xml index 276400d..16129a0 100644 --- a/newfiber-termites/newfiber-termites-dataup/src/main/resources/mapper/termite/TermiteMapper.xml +++ b/newfiber-termites/newfiber-termites-dataup/src/main/resources/mapper/termite/TermiteMapper.xml @@ -98,7 +98,7 @@ tb.location FROM ter_device_monitoring_data ta - left join ter_device_info tb on ta.sn=tb.sn + left join ter_device_info tb on ta.sn=tb.sn where ta.sn=#{request.sn} and ta.yesnoant =#{request.yesnoant} @@ -109,7 +109,9 @@ and ta.druing =#{request.druing} - + + and tb.category = #{request.category} + and ta.uptime > #{request.starttime} diff --git a/newfiber-termites/newfiber-termites-package/src/test/java/CommonTest.java b/newfiber-termites/newfiber-termites-package/src/test/java/CommonTest.java index 786ae2b..a20699b 100644 --- a/newfiber-termites/newfiber-termites-package/src/test/java/CommonTest.java +++ b/newfiber-termites/newfiber-termites-package/src/test/java/CommonTest.java @@ -1,10 +1,15 @@ import cn.hutool.core.date.DateUtil; +import cn.hutool.core.img.Img; +import cn.hutool.core.img.ImgUtil; import cn.hutool.http.HttpResponse; import cn.hutool.http.HttpUtil; import com.alibaba.fastjson.JSONObject; import com.newfiber.common.core.utils.file.FileUtils; import com.newfiber.termite.domain.jingchu.JingChuUpload; import com.newfiber.termite.util.CosUtil; +import java.awt.Color; +import java.awt.Font; +import java.awt.Image; import java.io.File; import java.util.ArrayList; import java.util.Date; @@ -46,4 +51,22 @@ log.info("同步荆楚监测数据.请求:{},响应:{}", JSONObject.toJSONString(jingChuUploadList), httpResponse.body()); } + + @Test + public void imgUtil(){ + Font font = new Font("微软雅黑", Font.BOLD, 50); + +// ImgUtil.pressText(new File("C:\\Users\\Administrator\\Downloads\\capture_202407.jpg"), +// new File("C:\\Users\\Administrator\\Downloads\\capture_202407_ex.jpg"), +// "Hello\r\n" + "World", Color.WHITE, font, -1, -1, 1f); + + Image srcImage = ImgUtil.read(new File("C:\\Users\\Administrator\\Downloads\\capture_202407.jpg")); + Img img = Img.from(srcImage); + img.setPositionBaseCentre(false); + img = img.pressText("项目:皇田水库", Color.WHITE, font, 0, 900, 1f); + img = img.pressText("位置:3-5", Color.WHITE, font, 0, 1000, 1f); + img = img.pressText("时间:2024/05/01 13:00", Color.WHITE, font, 0, 1100, 1f); + + ImgUtil.write(img.getImg(), new File("C:\\Users\\Administrator\\Downloads\\capture_202407_ex.jpg")); + } }