2021与蓝度共同重构项目,服务端
liuhaonan
2022-04-19 7e2175df8ed913a858296d4fde0d268879a91daf
ximon-admin/src/main/java/com/sandu/ximon/admin/service/LightService.java
@@ -22,6 +22,8 @@
import com.sandu.ximon.dao.bo.LightBo;
import com.sandu.ximon.dao.domain.Light;
import com.sandu.ximon.dao.domain.LightReportData;
import com.sandu.ximon.dao.domain.Pole;
import com.sandu.ximon.dao.domain.PoleBinding;
import com.sandu.ximon.dao.enums.DeviceRespStatusEnums;
import com.sandu.ximon.dao.mapper.LightMapper;
import lombok.AllArgsConstructor;
@@ -46,6 +48,8 @@
    private final RedisService redisService;
    private final LightReportDataService lightReportDataService;
    private final PoleBindingService bindingService;
    private final PoleService poleService;
    /**
     * 录入当前设备码的路灯数据
@@ -83,7 +87,10 @@
     * @return 返回组合数据dto
     */
    public List<LightBo> listLight(int pageNo, int pageSize, String keyword) {
        Long clientId = SecurityUtils.getClientId();
        Long clientId=null;
        if(SecurityUtils.getClientId()!=null){
            clientId = SecurityUtils.getClientId();
        }
        PageHelper.startPage(pageNo, pageSize);
@@ -94,6 +101,17 @@
        if (CollectionUtil.isNotEmpty(deviceCodeList)) {
            List<LightReportData> reportDataList = lightReportDataService.getNewestReportByDeviceCode(deviceCodeList);
            for (LightBo lightBo : listLight) {
                deviceCodeList.forEach(code -> {
                            PoleBinding bind = bindingService.getPoleIdByMac(code);
                            if (bind != null&&lightBo.getDeviceCode().equals(bind.getDeviceCode())) {
                                Long poleId = bind.getPoleId();
                                    Pole pole = poleService.getById(poleId);
                                    lightBo.setPoleId(pole.getId());
                                    lightBo.setPoleCode(pole.getDeviceCode());
                                    lightBo.setPoleName(pole.getPoleName());
                            }
                        }
                );
                for (LightReportData lightReportData : reportDataList) {
                    if (StrUtil.equals(lightBo.getDeviceCode(), lightReportData.getDeviceCode())) {
                        lightBo.setReportTime(lightReportData.getCreateTime());
@@ -104,6 +122,22 @@
        }
        return listLight;
    }
    /**
     * 获取单个路灯信息
     * @param deviceCode 设备码
     * @return
     */
    public Light getLight(String deviceCode) {
        Light one = getOne(Wrappers.<Light>lambdaQuery().eq(Light::getDeviceCode, deviceCode));
        Object o = redisService.get(LightKey.REPORT_MAC.key(deviceCode));
        if (o != null) {
            one.setOnlineStatus(1);
        }else {
            one.setOnlineStatus(0);
        }
        return one;
    }
    public boolean addRemark(LightRemarkParam param) {
@@ -152,7 +186,7 @@
                    light.setLightPercent(param.getBrightness());
                    update(light, Wrappers.lambdaUpdate(Light.class).eq(Light::getDeviceCode, param.getDeviceCode()));
                }
            }catch (BusinessException e){
            } catch (BusinessException e) {
                map.put("status", DeviceRespStatusEnums.OTHER_ERROR.getCode());
                resultList.add(map);
            }
@@ -160,4 +194,37 @@
        return resultList;
    }
    /**
     * 单灯节能率
     */
    public List<Map<String, Object>> controlEnergySaving() {
        List<LightBo> listLight = baseMapper.listLight(SecurityUtils.getUserId(), null);
        return null;
    }
    /**
     * 用户拥有的路灯
     */
    public List<Light> listLight() {
        List<LightBo> listLight = baseMapper.listLight(SecurityUtils.getUserId(), null);
        if (CollectionUtil.isEmpty(listLight)) {
            throw new BusinessException("没有路灯数据");
        }
        List<String> deviceCodeList = listLight.stream().map(LightBo::getDeviceCode).collect(Collectors.toList());
        List<LightReportData> reportDataList = lightReportDataService.list(Wrappers.<LightReportData>lambdaQuery().in(LightReportData::getDeviceCode, deviceCodeList));
        if (CollectionUtil.isEmpty(reportDataList)) {
            throw new BusinessException("没有路灯数据");
        }
        List<Light> lightList = new ArrayList<>();
        for (String deviceCode : deviceCodeList) {
            Light light = getLight(deviceCode);
            lightList.add(light);
        }
        return lightList;
    }
}