zhangf
2024-09-11 d4020168658efdee89a633083cd9c14b06c4d863
src/main/java/com/gkhy/fourierSpecialGasMonitor/service/impl/MonitorDataServiceImpl.java
@@ -5,16 +5,18 @@
import com.gkhy.fourierSpecialGasMonitor.commons.enums.ResultCode;
import com.gkhy.fourierSpecialGasMonitor.commons.exception.BusinessException;
import com.gkhy.fourierSpecialGasMonitor.commons.model.PageQuery;
import com.gkhy.fourierSpecialGasMonitor.commons.utils.BeanCopyUtils;
import com.gkhy.fourierSpecialGasMonitor.entity.*;
import com.gkhy.fourierSpecialGasMonitor.entity.query.GasAtmospherePageQuery;
import com.gkhy.fourierSpecialGasMonitor.entity.query.GasFluxPageQuery;
import com.gkhy.fourierSpecialGasMonitor.entity.query.GasPageQuery;
import com.gkhy.fourierSpecialGasMonitor.entity.req.GasAtmosphereLineChartReqDTO;
import com.gkhy.fourierSpecialGasMonitor.entity.req.GasFluxLineChartReqDTO;
import com.gkhy.fourierSpecialGasMonitor.entity.req.GasLineChartReqDTO;
import com.gkhy.fourierSpecialGasMonitor.entity.req.*;
import com.gkhy.fourierSpecialGasMonitor.entity.resp.*;
import com.gkhy.fourierSpecialGasMonitor.service.*;
import com.gkhy.fourierSpecialGasMonitor.utils.AreaHandle;
import com.gkhy.fourierSpecialGasMonitor.utils.PositionHandle;
import io.micrometer.core.instrument.util.StringUtils;
import jodd.bean.BeanCopy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
@@ -26,6 +28,7 @@
import java.lang.reflect.Field;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@@ -67,7 +70,7 @@
            startTime = zeroTime;
            endTime = nowTime;
        }
        List<GasConcentration> gasConcentrationList =  gasConcentrationService.listDatabyTimeSlot(startTime,endTime);
        List<GasConcentration> gasConcentrationList =  gasConcentrationService.listDatabyTimeSlotAndPosition(startTime,endTime,reqDto.getPosition());
        if (CollectionUtils.isEmpty(gasConcentrationList))
            return success;
        GasCategory gasCategory = gasCategoryService.findById(reqDto.getGasName());
@@ -124,7 +127,7 @@
        searchResult.setPageIndex(pageQuery.getPageIndex());
        searchResult.setPageSize(pageQuery.getPageSize());
        searchResult.setSuccess();
        Page<GasConcentration> pageResult =  gasConcentrationService.listDatabyTimeSlotAndPage(pageQuery);
        Page<GasConcentration> pageResult =  gasConcentrationService.listDatabyTimeSlotAndPositionAndPage(pageQuery);
        if (CollectionUtils.isEmpty(pageResult.getContent()))
            return searchResult;
        searchResult.setTotal(pageResult.getTotalElements());
@@ -309,11 +312,10 @@
            gasAtmosphereLineChartRespDTO.setTime(gasConcentration.getTime());
            Field[] fields = gasConcentration.getClass().getDeclaredFields();
            for (Field field : fields) {
                field.setAccessible(true);  // 设置字段可访问,即使是私有字段
                field.setAccessible(true);
                if (field.getName().equals(reqDto.getAtmosphere())) {
                    Double value = null;
                    try {
                        value = (Double) field.get(gasConcentration);
                        Object value = field.get(gasConcentration);
                        gasAtmosphereLineChartRespDTO.setValue(value);
                    } catch (IllegalAccessException e) {
                        logger.info("【警告】气象折线图反射获取气体浓度失败");
@@ -360,9 +362,8 @@
            for (Field field : fields) {
                field.setAccessible(true);  // 设置字段可访问,即使是私有字段
                if (field.getName().equals(atmosphere)) {
                    Double value = null;
                    try {
                        value = (Double) field.get(gasConcentration);
                        Object value = field.get(gasConcentration);
                        gasAtmospherePageRespDTO.setValue(value);
                    } catch (IllegalAccessException e) {
                        logger.info("【警告】气象折线图反射获取气体浓度失败");
@@ -374,4 +375,109 @@
        searchResult.setData(respDTOS);
        return searchResult;
    }
    @Override
    public Result gasFluxExport(GasFluxExportBO gasFluxExportBO) {
        Result<List<GasFluxExportDTO>> result = new Result<>();
        List<GasFlux> gasFluxes = gasFluxService.gasFluxExport(gasFluxExportBO);
        List<GasFluxExportDTO> exportLists = new ArrayList<>();
        AreaHandle areaHandle = new AreaHandle();
        for (GasFlux gasFlux : gasFluxes) {
            GasFluxExportDTO gasFluxExportDTO = BeanCopyUtils.copyBean(gasFlux, GasFluxExportDTO.class);
            gasFluxExportDTO.setGasName01("甲烷CH4");
            gasFluxExportDTO.setGasName02("乙烷C2H6");
            gasFluxExportDTO.setGasName03("丙烷C3H8");
            gasFluxExportDTO.setGasName04("丁烷C4H10");
            gasFluxExportDTO.setGasName05("硫化氢H2S");
            gasFluxExportDTO.setGasName06("乙烯C2H4");
            gasFluxExportDTO.setGasName07("异丁烷C4H10");
            gasFluxExportDTO.setAreaId(areaHandle.areaHandleMethod(gasFlux.getAreaId()));
            if (gasFluxExportBO.getCh4() == 0){
                gasFluxExportDTO.setGasValue01(null);
            }
            if (gasFluxExportBO.getC2h6() == 0){
                gasFluxExportDTO.setGasValue02(null);
            }
            if (gasFluxExportBO.getC3H8() == 0){
                gasFluxExportDTO.setGasValue03(null);
            }
            if (gasFluxExportBO.getC4h101() == 0){
                gasFluxExportDTO.setGasValue04(null);
            }
            if (gasFluxExportBO.getH2s() == 0){
                gasFluxExportDTO.setGasValue05(null);
            }
            if (gasFluxExportBO.getC2h4() == 0){
                gasFluxExportDTO.setGasValue06(null);
            }
            if (gasFluxExportBO.getC4h102() == 0){
                gasFluxExportDTO.setGasValue07(null);
            }
            exportLists.add(gasFluxExportDTO);
        }
        //sql根据时间查所有,业务中处理数据项
        result.setData(exportLists);
        result.setCode(200);
        result.setCount(exportLists.size());
        result.setMsg("通量数据导出成功");
        return result;
    }
    @Override
    public Result gasConcentrationExport(GasConcentrationExportBO gasConcentrationExportBO) {
        Result<List<GasConcentrationExportDTO>> result = new Result<>();
        List<GasConcentration> gasConcentrationList = gasConcentrationService.gasConcentrationExport(gasConcentrationExportBO);
        List<GasConcentrationExportDTO> exportLists = new ArrayList<>();
        PositionHandle positionHandle = new PositionHandle();
        for (GasConcentration gasConcentration : gasConcentrationList) {
            GasConcentrationExportDTO gasConcentrationExportDTO = BeanCopyUtils.copyBean(gasConcentration, GasConcentrationExportDTO.class);
            gasConcentrationExportDTO.setPosition(positionHandle.positionHandleMethod(gasConcentration.getPosition()));
            gasConcentrationExportDTO.setGasName01("甲烷CH4");
            gasConcentrationExportDTO.setGasName02("乙烷C2H6");
            gasConcentrationExportDTO.setGasName03("丙烷C3H8");
            gasConcentrationExportDTO.setGasName04("丁烷C4H10");
            gasConcentrationExportDTO.setGasName05("硫化氢H2S");
            gasConcentrationExportDTO.setGasName06("乙烯C2H4");
            gasConcentrationExportDTO.setGasName07("异丁烷C4H10");
            if (gasConcentrationExportBO.getCh4() == 0){
                gasConcentrationExportDTO.setGasValue01(null);
            }
            if (gasConcentrationExportBO.getC2h6() == 0){
                gasConcentrationExportDTO.setGasValue02(null);
            }
            if (gasConcentrationExportBO.getC3H8() == 0){
                gasConcentrationExportDTO.setGasValue03(null);
            }
            if (gasConcentrationExportBO.getC4h101() == 0){
                gasConcentrationExportDTO.setGasValue04(null);
            }
            if (gasConcentrationExportBO.getH2s() == 0){
                gasConcentrationExportDTO.setGasValue05(null);
            }
            if (gasConcentrationExportBO.getC2h4() == 0){
                gasConcentrationExportDTO.setGasValue06(null);
            }
            if (gasConcentrationExportBO.getC4h102() == 0){
                gasConcentrationExportDTO.setGasValue07(null);
            }
            exportLists.add(gasConcentrationExportDTO);
        }
        //sql根据时间查所有,业务中处理数据项
        result.setData(exportLists);
        result.setCode(200);
        result.setCount(exportLists.size());
        result.setMsg("气体浓度数据导出成功");
        return result;
    }
}