| | |
| | | /** |
| | | # __----~~~~~~~~~~~------___ |
| | | # . . ~~//====...... __--~ ~~ |
| | | # -. \_|// |||\\ ~~~~~~::::... /~ |
| | | # ___-==_ _-~o~ \/ ||| \\ _/~~- |
| | | # __---~~~.==~||\=_ -_--~/_-~|- |\\ \\ _/~ |
| | | # _-~~ .=~ | \\-_ '-~7 /- / || \ / |
| | | # .~ .~ | \\ -_ / /- / || \ / |
| | | # / ____ / | \\ ~-_/ /|- _/ .|| \ / |
| | | # |~~ ~~|--~~~~--_ \ ~==-/ | \~--===~~ .\ |
| | | # ' ~-| /| |-~\~~ __--~~ |
| | | # |-~~-_/ | | ~\_ _-~ /\ |
| | | # / \ \__ \/~ \__ |
| | | # _--~ _/ | .-~~____--~-/ ~~==. |
| | | # ((->/~ '.|||' -_| ~~-/ , . _|| |
| | | # -_ ~\ ~~---l__i__i__i--~~_/ |
| | | # _-~-__ ~) \--______________--~~ |
| | | # //.-~~~-~_--~- |-------~~~~~~~~ |
| | | # //.-~~~--\ |
| | | # 神兽保佑 |
| | | # 永无BUG! |
| | | */ |
| | | # __----~~~~~~~~~~~------___ |
| | | # . . ~~//====...... __--~ ~~ |
| | | # -. \_|// |||\\ ~~~~~~::::... /~ |
| | | # ___-==_ _-~o~ \/ ||| \\ _/~~- |
| | | # __---~~~.==~||\=_ -_--~/_-~|- |\\ \\ _/~ |
| | | # _-~~ .=~ | \\-_ '-~7 /- / || \ / |
| | | # .~ .~ | \\ -_ / /- / || \ / |
| | | # / ____ / | \\ ~-_/ /|- _/ .|| \ / |
| | | # |~~ ~~|--~~~~--_ \ ~==-/ | \~--===~~ .\ |
| | | # ' ~-| /| |-~\~~ __--~~ |
| | | # |-~~-_/ | | ~\_ _-~ /\ |
| | | # / \ \__ \/~ \__ |
| | | # _--~ _/ | .-~~____--~-/ ~~==. |
| | | # ((->/~ '.|||' -_| ~~-/ , . _|| |
| | | # -_ ~\ ~~---l__i__i__i--~~_/ |
| | | # _-~-__ ~) \--______________--~~ |
| | | # //.-~~~-~_--~- |-------~~~~~~~~ |
| | | # //.-~~~--\ |
| | | # 神兽保佑 |
| | | # 永无BUG! |
| | | */ |
| | | package com.fengdu.gas.service; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.fengdu.gas.common.*; |
| | | import com.fengdu.gas.common.enums.*; |
| | | import com.fengdu.gas.common.model.Tuple; |
| | | import com.fengdu.gas.common.util.*; |
| | | import com.fengdu.gas.entity.response.facility.FacilityCount; |
| | | import com.fengdu.gas.entity.response.facility.FacilityData; |
| | | import com.fengdu.gas.entity.response.facility.FacilityPointCount; |
| | | import com.fengdu.gas.entity.response.facility.FacilityStateData; |
| | | import com.fengdu.gas.repository.impl.WaterFacilityParameterMapperImpl; |
| | | import com.fengdu.gas.repository.impl.WaterFacilityTypeMapperImpl; |
| | | import com.fengdu.gas.repository.impl.WaterMonitoryPointMapperImpl; |
| | | import com.fengdu.gas.repository.po.WaterFacilityParameterPO; |
| | | import com.fengdu.gas.repository.po.WaterFacilityTypePO; |
| | | import com.fengdu.gas.repository.po.WaterMonitoryPointPO; |
| | | import org.apache.commons.lang3.BooleanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | import java.util.stream.Stream; |
| | | |
| | | import com.fengdu.gas.repository.impl.WaterFacilityMapperImpl; |
| | | import com.fengdu.gas.repository.po.WaterFacilityPO; |
| | | import com.fengdu.gas.entity.request.waterfacility.ReqCreateWaterFacility; |
| | |
| | | public class WaterFacilityService extends BaseService { |
| | | @Autowired |
| | | private WaterFacilityMapperImpl mapper; |
| | | @Autowired |
| | | private WaterFacilityParameterMapperImpl waterFacilityParameterMapper; |
| | | @Autowired |
| | | private WaterMonitoryPointMapperImpl waterMonitoryPointMapper; |
| | | @Autowired |
| | | private WaterFacilityTypeMapperImpl waterFacilityTypeMapper; |
| | | |
| | | public ExecutedResult<Long> create(ReqCreateWaterFacility request) { |
| | | WaterMonitoryPointPO pointPO = waterMonitoryPointMapper.getById(request.getPointId()); |
| | | if(Objects.isNull(pointPO)){ |
| | | return ExecutedResult.failed("监测点不存在"); |
| | | } |
| | | // 转换po |
| | | WaterFacilityPO item = WaterFacilityConvert.INSTANCE.toCreate(request); |
| | | WaterFacilityPO item = CopierUtil.mapTo(request, WaterFacilityPO.class); |
| | | item.setPointId(pointPO.getId()); |
| | | item.setPointName(pointPO.getPointName()); |
| | | // 设置状态 |
| | | //item.setStatus(EState.NORMAL.getValue()); |
| | | // 设置记录创建时间 |
| | |
| | | } |
| | | return ExecutedResult.success(result); |
| | | } |
| | | public ExecutedResult<List<WaterFacilityPO>> getFacilityFan(Integer type){ |
| | | List<WaterFacilityPO>result = new ArrayList<>(); |
| | | if(type!=null){ |
| | | LambdaQueryWrapper<WaterFacilityPO>wrapper=new LambdaQueryWrapper<>(); |
| | | wrapper.eq(WaterFacilityPO::getFacilityFanState,type); |
| | | result= mapper.selectList(wrapper); |
| | | }else { |
| | | result= mapper.getList(); |
| | | } |
| | | return ExecutedResult.success(result); |
| | | } |
| | | public ExecutedResult<List<FacilityStateData>> getFacilityState(){ |
| | | List<FacilityStateData>result = new ArrayList<>(); |
| | | List<WaterFacilityPO> facilityPOList = mapper.getList(); |
| | | EFacilityState[] values = EFacilityState.values(); |
| | | for(EFacilityState v:values){ |
| | | FacilityStateData stateData=new FacilityStateData(); |
| | | stateData.setTypeName(EFacilityState.getByValue(v.getValue()).getDesc()); |
| | | List<WaterFacilityPO> collect = facilityPOList.stream().filter(item -> item.getFacilityState().equals(v.getValue())).collect(Collectors.toList()); |
| | | if(ListUtil.isNotNullOrEmpty(collect)){ |
| | | BigDecimal bigDecimal = new BigDecimal(collect.size()).divide(new BigDecimal(facilityPOList.size())).setScale(2, RoundingMode.DOWN); |
| | | BigDecimal bigDecimal1 = bigDecimal.multiply(new BigDecimal(100)).setScale(2, RoundingMode.DOWN); |
| | | stateData.setValue(bigDecimal1); |
| | | } |
| | | result.add(stateData); |
| | | } |
| | | return ExecutedResult.success(result); |
| | | } |
| | | public ExecutedResult<List<FacilityPointCount>> getFacilityPointCount(){ |
| | | return ExecutedResult.success(mapper.getFacilityPointCount()); |
| | | } |
| | | public ExecutedResult<List<FacilityData>> getFacilityList() { |
| | | List<FacilityData> result = new ArrayList<>(); |
| | | List<WaterMonitoryPointPO> pointPOList = waterMonitoryPointMapper.getList(); |
| | | List<WaterFacilityPO> facilityPOList = mapper.getList(); |
| | | List<WaterFacilityParameterPO> parameterPOList = waterFacilityParameterMapper.getList(); |
| | | for (WaterFacilityPO facilityPO : facilityPOList) { |
| | | WaterMonitoryPointPO pointPO = pointPOList.stream().filter(item -> item.getId().equals(facilityPO.getPointId())).findFirst().orElse(null); |
| | | FacilityData data = new FacilityData(); |
| | | data.setPointId(facilityPO.getPointId()); |
| | | data.setPointName(facilityPO.getPointName()); |
| | | data.setLeft(pointPO.getLeftMargin()); |
| | | data.setTop(pointPO.getTopMargin()); |
| | | data.setFacilityId(facilityPO.getId()); |
| | | data.setFacilityName(facilityPO.getFacilityName()); |
| | | data.setBoxType(pointPO.getBoxType()); |
| | | data.setFacilityState(EFacilityState.getByValue(facilityPO.getFacilityState()).getDesc()); |
| | | data.setFacilityFanState(EFacilityState.getByValue(facilityPO.getFacilityFanState()).getDesc()); |
| | | List<WaterFacilityParameterPO> poList = parameterPOList.stream().filter(item -> item.getFacilityId().equals(facilityPO.getId())).collect(Collectors.toList()); |
| | | if (ListUtil.isNotNullOrEmpty(poList)) { |
| | | //获取甲烷值 |
| | | String methaneValue = poList.stream().filter(item -> item.getColumnsCode().equals("JW001")).map(WaterFacilityParameterPO::getColumnValue).findFirst().orElse(null); |
| | | //获取硫化氢值 |
| | | String hyrothionValue = poList.stream().filter(item -> item.getColumnsCode().equals("LHQ001")).map(WaterFacilityParameterPO::getColumnValue).findFirst().orElse(null); |
| | | //获取温度 |
| | | String temperature = poList.stream().filter(item -> item.getColumnsCode().equals("WD001")).map(WaterFacilityParameterPO::getColumnValue).findFirst().orElse(null); |
| | | |
| | | // public ExecutedResult<String> stop(Long id) { |
| | | // // 验证记录是否存在 |
| | | // ExecutedResult<WaterFacilityPO> checkExists = this.check4Id(id); |
| | | // if (checkExists.isFailed()) { |
| | | // return ExecutedResult.failed(checkExists.getMsg()); |
| | | // } |
| | | // WaterFacilityPO item = new WaterFacilityPO(); |
| | | // item.setId(id); |
| | | // item.setStatus(EState.DISABLED.getValue()); |
| | | // |
| | | // int rowCount = mapper.updateById(item); |
| | | // if (rowCount != 1) { |
| | | // return ExecutedResult.failed("停用[设备信息]失败。"); |
| | | // } |
| | | // return ExecutedResult.success(); |
| | | // } |
| | | // |
| | | // public ExecutedResult<String> enable(Long id) { |
| | | // // 验证记录是否存在 |
| | | // ExecutedResult<WaterFacilityPO> checkExists = this.check4Id(id); |
| | | // if (checkExists.isFailed()) { |
| | | // return ExecutedResult.failed(checkExists.getMsg()); |
| | | // } |
| | | // WaterFacilityPO item = new WaterFacilityPO(); |
| | | // item.setId(id); |
| | | // item.setStatus(EState.NORMAL.getValue()); |
| | | // |
| | | // int rowCount = mapper.updateById(item); |
| | | // if (rowCount != 1) { |
| | | // return ExecutedResult.failed("启用[设备信息]失败。"); |
| | | // } |
| | | // return ExecutedResult.success(); |
| | | // } |
| | | // |
| | | // public ExecutedResult<String> setSort(ReqSetSort request) { |
| | | // // 验证记录是否存在 |
| | | // ExecutedResult<WaterFacilityPO> checkExists = this.check4Id(request.getId()); |
| | | // if (checkExists.isFailed()) { |
| | | // return ExecutedResult.failed(checkExists.getMsg()); |
| | | // } |
| | | // WaterFacilityPO item = new WaterFacilityPO(); |
| | | // item.setId(request.getId()); |
| | | // item.setSort(request.getSort()); |
| | | // |
| | | // int rowCount = mapper.updateById(item); |
| | | // if (rowCount != 1) { |
| | | // return ExecutedResult.failed("设置[设备信息]排序值失败。"); |
| | | // } |
| | | // return ExecutedResult.success(); |
| | | // } |
| | | // |
| | | // public ExecutedResult<String> listSetSort(ReqListSetSort request) { |
| | | // // id列表 |
| | | // List<Long> listId = request.getList().stream().map(ReqSetSort::getId).collect(Collectors.toList()); |
| | | // // 验证记录是否存在 |
| | | // ExecutedResult<List<WaterFacilityPO>> checkExists = this.check4Id(listId); |
| | | // if (checkExists.isFailed()) { |
| | | // return ExecutedResult.failed(checkExists.getMsg()); |
| | | // } |
| | | // |
| | | // List<WaterFacilityPO> listUpdate = request.getList().stream() |
| | | // .map(c -> { |
| | | // WaterFacilityPO item = new WaterFacilityPO(); |
| | | // item.setId(c.getId()); |
| | | // item.setSort(c.getSort()); |
| | | // return item; |
| | | // }) |
| | | // .collect(Collectors.toList()); |
| | | // Boolean result = mapper.modifyList(listUpdate); |
| | | // if (result) { |
| | | // return ExecutedResult.success(); |
| | | // } |
| | | // return ExecutedResult.failed("[设备信息]设置排序值失败"); |
| | | // } |
| | | // |
| | | // public ExecutedResult<String> remove(Long id) { |
| | | // Boolean result = mapper.deleteLogic(id); |
| | | // if (BooleanUtils.isFalse(result)) { |
| | | // return ExecutedResult.failed("删除[设备信息]失败。"); |
| | | // } |
| | | // return ExecutedResult.success(); |
| | | // } |
| | | // |
| | | // public ExecutedResult<String> removeList(List<Long> ids) { |
| | | // Boolean result = mapper.deleteLogic(ids); |
| | | // if (BooleanUtils.isFalse(result)) { |
| | | // return ExecutedResult.failed("删除[设备信息]失败。"); |
| | | // } |
| | | // return ExecutedResult.success(); |
| | | // } |
| | | if (StringUtil.isNotNullOrEmpty(methaneValue)) |
| | | data.setMethaneValue(new BigDecimal(methaneValue)); |
| | | if (StringUtil.isNotNullOrEmpty(hyrothionValue)) |
| | | data.setHyrothionValue(new BigDecimal(hyrothionValue)); |
| | | if (StringUtil.isNotNullOrEmpty(temperature)) |
| | | data.setTemperature(new BigDecimal(temperature)); |
| | | } |
| | | result.add(data); |
| | | } |
| | | return ExecutedResult.success(result); |
| | | } |
| | | public ExecutedResult<List<FacilityCount>> deviceCount(){ |
| | | List<FacilityCount> result = new ArrayList<>(); |
| | | List<WaterMonitoryPointPO> pointPOList = waterMonitoryPointMapper.getList(); |
| | | List<WaterFacilityPO> facilityPOList = mapper.getList(); |
| | | for(WaterMonitoryPointPO po:pointPOList){ |
| | | List<WaterFacilityPO> collect = facilityPOList.stream().filter(item -> item.getPointId().equals(po.getId())).collect(Collectors.toList()); |
| | | if(ListUtil.isNotNullOrEmpty(collect)&&collect.size()>0){ |
| | | FacilityCount count=new FacilityCount(); |
| | | count.setPointId(po.getId()); |
| | | count.setPointName(po.getPointName()); |
| | | count.setFacilityFanCount(collect.size()); |
| | | count.setMethaneCount(collect.size()); |
| | | count.setHyrothionCount(collect.size()); |
| | | count.setBoxCount(collect.size()); |
| | | int i = count.getFacilityFanCount() + count.getMethaneCount() + count.getHyrothionCount() + count.getBoxCount(); |
| | | count.setSumCount( i); |
| | | result.add(count); |
| | | } |
| | | } |
| | | return ExecutedResult.success(result); |
| | | } |
| | | |
| | | public ExecutedResult<List<WaterFacilityVO>> getList(List<Long> listId) { |
| | | List<WaterFacilityVO> result = new ArrayList<>(); |
| | |
| | | if (ListUtil.isNotNullOrEmpty(list)) { |
| | | pageList.setLastId(list.get(list.size() - 1).getId()); |
| | | // 转换vo |
| | | List<WaterFacilityTypePO> typePOS = waterFacilityTypeMapper.getList(); |
| | | listVo = WaterFacilityConvert.INSTANCE.toVo(list); |
| | | for(WaterFacilityVO vo:listVo){ |
| | | WaterFacilityTypePO facilityTypePO = typePOS.stream().filter(item -> item.getId().equals(vo.getFacilityType())).findFirst().orElse(null); |
| | | if(Objects.nonNull(facilityTypePO)){ |
| | | vo.setFacilityTypeName(facilityTypePO.getName()); |
| | | } |
| | | } |
| | | } |
| | | PagerResult<WaterFacilityVO> result = new PagerResult<>(pageList.getLimit(), pageList.getPage(), pageList.getTotal(), listVo); |
| | | result.setLastId(pageList.getLastId()); |
| | |
| | | } |
| | | return ExecutedResult.success(exists); |
| | | } |
| | | |
| | | protected ExecutedResult<List<WaterFacilityPO>> check4Id(List<Long> listId) { |
| | | // 从数据库查找设备信息 |
| | | List<WaterFacilityPO> list = mapper.getList(listId); |
| | |
| | | } |
| | | } |
| | | return ExecutedResult.success(list); |
| | | }} |
| | | } |
| | | } |