| | |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.github.pagehelper.PageHelper; |
| | | import com.sandu.common.domain.CommonPage; |
| | | import com.sandu.common.execption.BusinessException; |
| | | import com.sandu.common.file.config.FileProperties; |
| | | import com.sandu.common.file.impl.AliOssFileServiceImpl; |
| | | import com.sandu.common.object.BaseConditionVO; |
| | | import com.sandu.common.service.impl.BaseServiceImpl; |
| | | import com.sandu.common.util.SpringContextHolder; |
| | | import com.sandu.ximon.admin.manager.iot.frame.inner.report.A5LightHeartbeatReportInnerFrame; |
| | |
| | | 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.OrderByEnums; |
| | | import com.sandu.ximon.dao.mapper.LightReportDataMapper; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.SneakyThrows; |
| | |
| | | |
| | | private final FileProperties properties; |
| | | private final AliOssFileServiceImpl fileService; |
| | | private final LightReportDataMapper lightReportDataMapper; |
| | | |
| | | /** |
| | | * 保存上报的灯心跳数据 |
| | |
| | | lightReportData = new LightReportData(); |
| | | lightReportData.setCreateTime(format); |
| | | } |
| | | //todo |
| | | lightReportData.setCreateTime(format); |
| | | BeanUtils.copyProperties(heartBeatDataPackage, lightReportData); |
| | | lightReportData.setDeviceCode(deviceName); |
| | |
| | | * @param keyword 关键词 |
| | | * @param deviceCode 设备码 |
| | | */ |
| | | public CommonPage listReportData(int pageNo, int pageSize, String keyword, String deviceCode) { |
| | | public CommonPage listReportData(int pageNo, int pageSize, String keyword, String deviceCode, Integer order, Integer seq) { |
| | | |
| | | List<LightReportDataBo> lightReportDataBos = new ArrayList<>(pageSize); |
| | | |
| | | CommonPage<String> stringCommonPage = SpringContextHolder.getBean(LightService.class).listDeviceCode(pageNo, pageSize, keyword, deviceCode); |
| | | //排序字段 |
| | | String orderByResult = "t1.create_time"; |
| | | //正序、倒叙 |
| | | String orderBySeq = OrderByEnums.ASC.getCode(); |
| | | if (order != null) { |
| | | switch (order) { |
| | | case 1: |
| | | orderByResult = OrderByEnums.LIGHT_DATA_CREATE_TIME.getCode(); |
| | | break; |
| | | default: |
| | | } |
| | | } |
| | | if (seq != null) { |
| | | switch (seq) { |
| | | case 1: |
| | | orderBySeq = " ASC"; |
| | | break; |
| | | case 2: |
| | | orderBySeq = " DESC"; |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | //排序方式 |
| | | String orderBy = orderByResult + " " + orderBySeq; |
| | | CommonPage<String> stringCommonPage = SpringContextHolder.getBean(LightService.class).listDeviceCode(pageNo, pageSize, keyword, deviceCode, orderBy); |
| | | List<String> macList = stringCommonPage.getList(); |
| | | if (CollUtil.isEmpty(macList)) { |
| | | return new CommonPage(); |
| | |
| | | } |
| | | |
| | | @SneakyThrows |
| | | public String exportList(HttpServletRequest request, HttpServletResponse response, String deviceCode) { |
| | | public void exportList(HttpServletRequest request, HttpServletResponse response, String deviceCode) { |
| | | |
| | | if (SecurityUtils.getClientId() != null) { |
| | | PoleBinding one = SpringContextHolder.getBean(PoleBindingService.class).getOne(Wrappers.lambdaQuery(PoleBinding.class).eq(PoleBinding::getDeviceCode, deviceCode) |
| | |
| | | } |
| | | } |
| | | |
| | | List<LightReportDataBo> list = baseMapper.listReportData(null, deviceCode); |
| | | List<LightReportDataBo> list = lightReportDataMapper.listReportData(null, deviceCode); |
| | | |
| | | File file = new File("./" + RandomUtil.randomString(12) + ".xlsx"); |
| | | |
| | |
| | | //文件流化返回给前端 |
| | | findfile(request, response, file); |
| | | //删除文件 |
| | | file.delete(); |
| | | return null; |
| | | // file.delete(); |
| | | } |
| | | |
| | | /** |
| | |
| | | ServletOutputStream out = null; |
| | | FileInputStream ips = null; |
| | | try { |
| | | //获取文件存放的路径 |
| | | String fileName = file.getName(); |
| | | //获取到文字 数据库里对应的附件名字加上老的文件名字:filename 截取到后面的文件类型 例:txt 组成一个新的文件名字:newFileName |
| | | //生成3个随机数,用来生成新的文件名字 |
| | | String newFileName = "单灯数据" + RandomUtil.randomString(3) + ".xlsx"; |
| | |
| | | try { |
| | | out.close(); |
| | | ips.close(); |
| | | file.delete(); |
| | | } catch (IOException e) { |
| | | System.out.println("关闭流出现异常"); |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 根据macCode获取灯的数据 |
| | | */ |
| | | public List<LightReportData> getReportDataList(BaseConditionVO conditionVO, String macCode) { |
| | | if (macCode.isEmpty()) { |
| | | throw new BusinessException("mac不能为空"); |
| | | } |
| | | PageHelper.startPage(conditionVO.getPageNo(), conditionVO.getPageSize()); |
| | | List<LightReportData> list = list(Wrappers.lambdaQuery(LightReportData.class).eq(LightReportData::getDeviceCode, macCode)); |
| | | list.forEach( |
| | | lightReportData -> { |
| | | lightReportData.setCreateTime(lightReportData.getCreateTime1().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); |
| | | lightReportData.setUpdateTime(lightReportData.getUpdateTime1().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))); |
| | | } |
| | | ); |
| | | return list; |
| | | } |
| | | } |