package com.casic.service.impl; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.casic.dao.NbConfigMapper; import com.casic.dao.NbDeviceMapper; import com.casic.entity.NbDevice; import com.casic.model.DataGasConfigParam; import com.casic.model.ResponseData; import com.casic.service.AepCommandSend; import com.casic.service.GasDeviceService; import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.dao.DataAccessException; import org.springframework.stereotype.Service; import java.util.*; @Slf4j @Service @AllArgsConstructor public class GasDeviceServiceImpl implements GasDeviceService { private final NbDeviceMapper nbDeviceMapper; private final AepCommandSend aepCommandSend; private final NbConfigMapper nbConfigMapper; @Override public ResponseData devcieStatusConfig(List<DataGasConfigParam> dataGasConfigParam) { ResponseData responseData = new ResponseData(); try { aepCommandSend.sendStatusNb(dataGasConfigParam); responseData.setCode(200); responseData.setMessage("配置成功"); } catch (Exception dex) { log.error("主题:哈尔滨燃气设备下发异常,异常信息:{}", dex.getMessage()); responseData.setCode(500); responseData.setMessage("配置异常"); } return responseData; } @Override public List<NbDevice> getDevicieList(String beginTime, String endTime, String devcode) { devcode = StringUtils.isEmpty(devcode) ? "" : devcode; List<NbDevice> nbDevicesList = new ArrayList<>(); try { QueryWrapper<NbDevice> lucencyGasWrapper = new QueryWrapper<NbDevice>().like("devcode", devcode); if (!StringUtils.isEmpty(beginTime)) { lucencyGasWrapper = lucencyGasWrapper.gt("uptime", beginTime); } if (!StringUtils.isEmpty(endTime)) { lucencyGasWrapper = lucencyGasWrapper.lt("uptime", endTime); } lucencyGasWrapper = lucencyGasWrapper.orderByDesc("logtime"); nbDevicesList = nbDeviceMapper.selectList(lucencyGasWrapper); } catch (DataAccessException dex) { log.error("主题:哈尔滨燃气设备导出查询异常,异常信息:{}", dex.getMessage()); } return nbDevicesList; } @Override public ResponseData<List<NbDevice>> getDevicieListPage(String devcode, String beginTime, String endTime, Integer currentIndex, Integer pageSize,Boolean emptyStatus,Boolean sortDevcode) { ResponseData responseData = new ResponseData(); try { devcode = StringUtils.isEmpty(devcode) ? "" : devcode; QueryWrapper<NbDevice> lucencyGasWrapper =emptyStatus? new QueryWrapper<NbDevice>().isNull("device_id"):new QueryWrapper<NbDevice>().like("devcode", devcode); if (!StringUtils.isEmpty(beginTime)) { lucencyGasWrapper = lucencyGasWrapper.gt("logtime", beginTime); } if (!StringUtils.isEmpty(endTime)) { lucencyGasWrapper = lucencyGasWrapper.lt("logtime", endTime); } lucencyGasWrapper = sortDevcode ? lucencyGasWrapper.orderByAsc("devcode") : lucencyGasWrapper.orderByDesc("logtime"); Page<NbDevice> userPage = new Page<>(currentIndex, pageSize); IPage<NbDevice> userIPage = nbDeviceMapper.selectPage(userPage, lucencyGasWrapper); Map<String, Object> page = new HashMap(); page.put("total", userIPage.getTotal()); page.put("rows", userIPage.getRecords()); page.put("current", userIPage.getCurrent()); responseData.setCode(200); responseData.setMessage("查询成功"); responseData.setData(page); } catch (DataAccessException dex) { log.error("主题:哈尔滨燃气设备状态查询异常,异常信息:{}", dex.getMessage()); responseData.setCode(500); responseData.setMessage("查询异常"); } return responseData; } @Override public ResponseData<List<NbDevice>> deviceDict() { ResponseData responseData = new ResponseData(); try { QueryWrapper<NbDevice> nbDeviceWrapper = new QueryWrapper<NbDevice>() .isNotNull("devcode"); List<NbDevice> nbDevicesList = nbDeviceMapper.selectList(nbDeviceWrapper); responseData.setCode(200); responseData.setMessage("配置成功"); responseData.setData(nbDevicesList); } catch (Exception dex) { log.error("主题:哈尔滨燃气设备字典列表查询异常,异常信息:{}", dex.getMessage()); responseData.setCode(500); responseData.setMessage("配置异常"); } return responseData; } }