设备监控:模板下载、离线数据导入、解析列表接口开发(只是预留口子)

This commit is contained in:
guofeihu
2024-07-03 20:36:56 +08:00
parent 5385d3163b
commit 815b90f47f
8 changed files with 386 additions and 2 deletions

View File

@@ -0,0 +1,79 @@
package com.njcn.csdevice.controller.equipment;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.csdevice.pojo.param.WlRecordTemplete;
import com.njcn.csdevice.pojo.po.PortableOfflLog;
import com.njcn.csdevice.service.IPortableOfflLogService;
import com.njcn.csdevice.utils.ExcelStyleUtil;
import com.njcn.poi.util.PoiUtil;
import com.njcn.web.pojo.param.BaseParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.web.bind.annotation.*;
import com.njcn.web.controller.BaseController;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
/**
* <p>
* 便携式基础数据导入 前端控制器
* </p>
*
* @author guofeihu
* @since 2024-07-03
*/
@RestController
@RequestMapping("/portableOfflLog")
@Api(tags = " 出厂设备")
@AllArgsConstructor
public class PortableOfflLogController extends BaseController {
private final IPortableOfflLogService iPortableOfflLogService;
@ResponseBody
@ApiOperation("导出设备基础数据模板")
@GetMapping(value = "getExcelTemplate")
public HttpResult<String> getExcelTemplate(HttpServletResponse response) {
ExportParams exportParams = new ExportParams("批量导入模板(请严格按照模板标准填入数据,带*表示必填)", "便携式终端基础数据录入信息");
exportParams.setStyle(ExcelStyleUtil.class);
Workbook workbook = ExcelExportUtil.exportExcel(exportParams, WlRecordTemplete.class, new ArrayList<WlRecordTemplete>());
//ExcelUtil.selectList(workbook, 2, 2, Stream.of("直连设备","网关设备").collect(Collectors.toList()).toArray(new String[]{}));
//ExcelUtil.selectList(workbook, 4, 4, Stream.of("MQTT","CLD").collect(Collectors.toList()).toArray(new String[]{}));
String fileName = "便携式设备模板.xlsx";
PoiUtil.exportFileByWorkbook(workbook, fileName, response);
return null;
}
@OperateInfo(info = LogEnum.BUSINESS_COMMON)
@PostMapping("/queryPage")
@ApiOperation("便携式设备解析列表")
@ApiImplicitParam(name = "baseParam", value = "查询参数", required = true)
public HttpResult<Page<PortableOfflLog>> queryPage(@RequestBody BaseParam baseParam){
String methodDescribe = getMethodDescribe("queryPage");
Page<PortableOfflLog> list = iPortableOfflLogService.queryPage(baseParam);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, list, methodDescribe);
}
@ResponseBody
@ApiOperation("批量导入便携式设备信息")
@PostMapping(value = "importEquipment")
public HttpResult<String> importEquipment(@ApiParam(value = "文件", required = true) @RequestPart("file") MultipartFile file, HttpServletResponse response) {
String methodDescribe = getMethodDescribe("importEquipment");
iPortableOfflLogService.importEquipment(file, response);
return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, null, methodDescribe);
}
}

View File

@@ -0,0 +1,24 @@
package com.njcn.csdevice.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.csdevice.pojo.po.PortableOfflLog;
import com.njcn.web.pojo.param.BaseParam;
import org.apache.ibatis.annotations.Param;
/**
* <p>
* 便携式基础数据导入 Mapper 接口
* </p>
*
* @author guofeihu
* @since 2024-07-03
*/
public interface PortableOfflLogMapper extends BaseMapper<PortableOfflLog> {
/**
* 便携式设备解析列表
*/
Page<PortableOfflLog> queryPage(Page<PortableOfflLog> returnpage, @Param("baseParam") BaseParam baseParam);
}

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.njcn.csdevice.mapper.PortableOfflLogMapper">
<select id="queryPage" resultType="com.njcn.csdevice.pojo.po.PortableOfflLog">
select * from portable_offl_log where 1 = 1
<if test="baseParam.searchBeginTime!=null and baseParam.searchEndTime != null
and baseParam.searchBeginTime != '' and baseParam.searchEndTime != ''">
and create_Time between #{baseParam.searchBeginTime} and #{baseParam.searchEndTime}
</if>
</select>
</mapper>

View File

@@ -0,0 +1,23 @@
package com.njcn.csdevice.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService;
import com.njcn.csdevice.pojo.po.PortableOfflLog;
import com.njcn.web.pojo.param.BaseParam;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
/**
* <p>
* 便携式基础数据导入 服务类
* </p>
*
* @author guofeihu
* @since 2024-07-03
*/
public interface IPortableOfflLogService extends IService<PortableOfflLog> {
Page<PortableOfflLog> queryPage(BaseParam baseParam);
void importEquipment(MultipartFile file, HttpServletResponse response);
}

View File

@@ -359,8 +359,8 @@ public class CsGroupServiceImpl extends ServiceImpl<CsGroupMapper, CsGroup> impl
}
}
//暂降幅值
//List<RmpEventDetailPO> eventDetails = eventDetailFeignClient.getEventDetailByIdsList(Arrays.asList(temp.getEventId())).getData();
//if(eventDetails !=null && !eventDetails.isEmpty()) temp.setAmplitude(PubUtils.floatRound(2, eventDetails.get(0).getFeatureAmplitude().floatValue()));
List<RmpEventDetailPO> eventDetails = eventDetailFeignClient.getEventDetailByIdsList(Arrays.asList(temp.getEventId())).getData();
if(eventDetails !=null && !eventDetails.isEmpty()) temp.setAmplitude(PubUtils.floatRound(2, eventDetails.get(0).getFeatureAmplitude().floatValue()));
});
return returnpage;
}

View File

@@ -0,0 +1,53 @@
package com.njcn.csdevice.service.impl;
import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.csdevice.mapper.PortableOfflLogMapper;
import com.njcn.csdevice.pojo.param.DeviceExcelTemplete;
import com.njcn.csdevice.pojo.po.PortableOfflLog;
import com.njcn.csdevice.service.IPortableOfflLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.njcn.web.pojo.param.BaseParam;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
/**
* <p>
* 便携式基础数据导入 服务实现类
* </p>
*
* @author guofeihu
* @since 2024-07-03
*/
@Service
public class PortableOfflLogServiceImpl extends ServiceImpl<PortableOfflLogMapper, PortableOfflLog> implements IPortableOfflLogService {
@Override
public Page<PortableOfflLog> queryPage(BaseParam baseParam) {
Page<PortableOfflLog> returnpage = new Page<> (baseParam.getPageNum(), baseParam.getPageSize ());
if(baseParam.getSearchBeginTime()!=null) baseParam.setSearchBeginTime(baseParam.getSearchBeginTime()+" 00:00:00");
if(baseParam.getSearchEndTime()!=null) baseParam.setSearchEndTime(baseParam.getSearchEndTime()+" 23:59:59");
returnpage = this.getBaseMapper().queryPage(returnpage,baseParam);
return returnpage;
}
@Override
public void importEquipment(MultipartFile file, HttpServletResponse response) {
ImportParams params = new ImportParams ( );
params.setHeadRows(1);
params.setTitleRows(1);
//第一个sheet为台账信息
params.setStartSheetIndex(0);
params.setSheetNum(1);
try {
ExcelImportResult<DeviceExcelTemplete> terminalBaseList = ExcelImportUtil.importExcelMore (file.getInputStream ( ), DeviceExcelTemplete.class, params);
} catch (Exception e) {
e.printStackTrace();
}
//记录导入信息
PortableOfflLog portableOfflLog = new PortableOfflLog();
}
}