| | |
| | | package com.sandu.ximon.admin.service; |
| | | |
| | | import cn.hutool.core.io.FileUtil; |
| | | import cn.hutool.core.util.RandomUtil; |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.alibaba.excel.ExcelWriter; |
| | | import com.alibaba.excel.write.metadata.WriteSheet; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.sandu.common.file.FileUploadDto; |
| | | import com.sandu.common.file.config.FileProperties; |
| | | import com.sandu.common.file.impl.AliOssFileServiceImpl; |
| | | import com.sandu.common.service.impl.BaseServiceImpl; |
| | | import com.sandu.ximon.admin.dto.LightDataDto; |
| | | import com.sandu.common.util.ResUtils; |
| | | import com.sandu.ximon.admin.manager.iot.frame.inner.report.A5LightHeartbeatReportInnerFrame; |
| | | import com.sandu.ximon.dao.bo.LightReportDataBo; |
| | | import com.sandu.ximon.dao.domain.LightReportData; |
| | | import com.sandu.ximon.dao.mapper.LightReportDataMapper; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.SneakyThrows; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.core.io.ClassPathResource; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.File; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | * 灯上报数据 service |
| | | */ |
| | | @Service |
| | | @AllArgsConstructor |
| | | public class LightReportDataService extends BaseServiceImpl<LightReportDataMapper, LightReportData> { |
| | | |
| | | private final FileProperties properties; |
| | | private final AliOssFileServiceImpl fileService; |
| | | |
| | | /** |
| | | * 保存上报的灯心跳数据 |
| | |
| | | * @return 是否成功 |
| | | */ |
| | | public boolean saveReportData(String deviceName, A5LightHeartbeatReportInnerFrame.HeartBeatDataPackage heartBeatDataPackage) { |
| | | |
| | | LightReportData lightReportData = new LightReportData(); |
| | | BeanUtils.copyProperties(heartBeatDataPackage, lightReportData); |
| | | lightReportData.setDeviceMac(deviceName); |
| | | lightReportData.setDeviceCode(deviceName); |
| | | |
| | | return save(lightReportData); |
| | | } |
| | | |
| | | /** |
| | | * 获取路灯列表 |
| | | * @return 返回组合数据dto |
| | | * 获取指定设备码最新的一天上报数据 |
| | | * |
| | | * @param deviceCodeList 设备码列表 |
| | | * @return 上报数据 |
| | | */ |
| | | public List<LightDataDto> listLight(int pageNo, int pageSize, String keyword) { |
| | | PageHelper.startPage(pageNo,pageSize); |
| | | public List<LightReportData> getNewestReportByDeviceCode(List<String> deviceCodeList) { |
| | | return baseMapper.getNewestReportByDeviceCode(deviceCodeList); |
| | | } |
| | | |
| | | return null; |
| | | /** |
| | | * 获取上报数据 |
| | | * |
| | | * @param keyword 关键词 |
| | | * @param deviceCode 设备码 |
| | | */ |
| | | public List<LightReportDataBo> listReportData(int pageNo, int pageSize, String keyword, String deviceCode) { |
| | | PageHelper.startPage(pageNo, pageSize); |
| | | return baseMapper.listReportData(keyword, deviceCode); |
| | | } |
| | | |
| | | @SneakyThrows |
| | | public String exportList(int pageNo, int pageSize, String keyword, String deviceCode) { |
| | | PageHelper.startPage(pageNo, pageSize); |
| | | List<LightReportDataBo> list = baseMapper.listReportData(keyword, deviceCode); |
| | | |
| | | File file = new File("./" + RandomUtil.randomString(12) + ".xlsx"); |
| | | // File file = new File(properties.getUploadRootPath() + "export" + File.separator + RandomUtil.randomString(12) + ".xlsx"); |
| | | // ClassPathResource cpr = new ClassPathResource("public/exportOrder.xlsx"); |
| | | // FileUtil.mkParentDirs(file); |
| | | // |
| | | // ExcelWriter excelWriter = EasyExcel.write(file).withTemplate(cpr.getInputStream()).build(); |
| | | // WriteSheet writeSheet = EasyExcel.writerSheet().build(); |
| | | // excelWriter.fill(list, writeSheet); |
| | | // excelWriter.finish(); |
| | | |
| | | EasyExcel.write(file, LightReportDataBo.class).sheet("模版").doWrite(list); |
| | | |
| | | FileUploadDto fileUploadDto = fileService.uploadFile(file); |
| | | // String url = file.getPath().replace(properties.getUploadRootPath(), ""); |
| | | String url = fileUploadDto.getFileUrl(); |
| | | file.delete(); |
| | | return url; |
| | | |
| | | // return list; |
| | | } |
| | | } |