das新增物模型导出接口

This commit is contained in:
chenhaojie 2024-07-03 16:25:51 +08:00
parent 18039132c0
commit 49bef6be8c
14 changed files with 319 additions and 4 deletions

View File

@ -24,6 +24,7 @@
<postgresql.version>42.7.3</postgresql.version>
<sa.version>1.38.0</sa.version>
<easyexcel.version>4.0.1</easyexcel.version>
<annotations.version>4.8.6</annotations.version>
</properties>
@ -72,6 +73,20 @@
<version>${sa.version}</version>
</dependency>
<!-- easyexcel导入导出 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>${easyexcel.version}</version>
<exclusions>
<exclusion>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- 提供Redis连接池 -->
<dependency>
<groupId>org.apache.commons</groupId>

View File

@ -0,0 +1,55 @@
package com.das.common.utils;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.das.modules.equipment.domain.excel.SheetInfoBean;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.List;
/**
* EXCEL处理工具类
* @author 王凯
* @version 1.0.0
* @since 2022-08-17
*/
public class ExcelUtil {
/**导出*/
public static void exportMoreSheet(String fileName,
HttpServletRequest request,
HttpServletResponse response,
List<SheetInfoBean> sheetInfoList){
try {
// response.reset();
response.setHeader("Access-Control-Allow-Origin", "*");
if (request.getMethod().equals("OPTIONS")) {
response.addHeader("Access-Control-Allow-Methods", "GET,HEAD,POST,PUT,DELETE,TRACE,OPTIONS,PATCH");
response.addHeader("Access-Control-Allow-Headers", "dnt,Origin, X-Requested-With,Content-Type, Accept, Authorization");
}
response.setCharacterEncoding("utf-8");
response.setContentType("application/vnd.ms-excel");
String encodedFileName = URLEncoder.encode(fileName, "UTF-8").replaceAll("\\+", "%20");
response.setHeader("Content-Disposition", "attachment; filename*=UTF-8''" + encodedFileName);
ExcelWriter excelWriter = EasyExcel.write(response.getOutputStream()).build();
WriteSheet writeSheet;
for (SheetInfoBean bean : sheetInfoList) {
// 构建sheet对象
writeSheet = EasyExcel.writerSheet(bean.getSheetName()).head(bean.getHeadClass()).build();
// 写出sheet数据
excelWriter.write(bean.getDataList(), writeSheet);
}
// // 关流
excelWriter.finish();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

View File

@ -4,13 +4,17 @@ import cn.dev33.satoken.stp.StpUtil;
import com.das.common.constant.SysAuthorityIds;
import com.das.common.exceptions.ServiceException;
import com.das.common.result.R;
import com.das.common.utils.ExcelUtil;
import com.das.modules.equipment.domain.dto.SysIotModelDto;
import com.das.modules.equipment.domain.dto.SysIotModelFieldDto;
import com.das.modules.equipment.domain.dto.SysIotModelServiceDto;
import com.das.modules.equipment.domain.vo.SysIotModelFieldVo;
import com.das.modules.equipment.domain.vo.SysIotModelServiceVo;
import com.das.modules.equipment.domain.vo.SysIotModelVo;
import com.das.modules.equipment.entity.SysIotModel;
import com.das.modules.equipment.service.SysIotModelService;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@ -209,5 +213,16 @@ public class SysIotModelController {
sysIotModelService.deleteSysIotModelService(sysIotModelServiceDto);
return R.success();
}
/** 物模型导出 */
@PostMapping("/export")
public void exportSysIotModel(@RequestBody SysIotModelDto sysIotModelDto, HttpServletRequest request, HttpServletResponse response) {
if (sysIotModelDto.getId() == null) {
throw new ServiceException("请选择需要下载的物模型属性信息");
}
sysIotModelService.exportSysIotModel(sysIotModelDto,request, response);
}
}

View File

@ -32,5 +32,5 @@ public class SysIotModelFieldDto implements Serializable {
*/
private Integer porder;
private Integer version;
private Integer revision;
}

View File

@ -35,5 +35,5 @@ public class SysIotModelServiceDto implements Serializable {
*/
private Integer porder;
private Integer version;
private Integer revision;
}

View File

@ -0,0 +1,63 @@
package com.das.modules.equipment.domain.excel;
import java.util.List;
public class SheetInfoBean {
/**
* sheet页名称
*/
private String sheetName;
/**
* sheet标题bean
*/
private Class<?> headClass;
/**
* sheet页数据
*/
private List<?> dataList;
public SheetInfoBean() {
}
public SheetInfoBean(String sheetName, Class<?> headClass, List<?> dataList) {
this.sheetName = sheetName;
this.headClass = headClass;
this.dataList = dataList;
}
public String getSheetName() {
return sheetName;
}
public void setSheetName(String sheetName) {
this.sheetName = sheetName;
}
public Class<?> getHeadClass() {
return headClass;
}
public void setHeadClass(Class<?> headClass) {
this.headClass = headClass;
}
public List<?> getDataList() {
return dataList;
}
public void setDataList(List<?> dataList) {
this.dataList = dataList;
}
@Override
public String toString() {
return "SheetInfoBean{" +
"sheetName='" + sheetName + '\'' +
", headClass=" + headClass +
", dataList=" + dataList +
'}';
}
}

View File

@ -0,0 +1,49 @@
package com.das.modules.equipment.domain.excel;
import com.alibaba.excel.annotation.ExcelProperty;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.Data;
/**
* 物模型属性前端回显
*
* @author guchengwei
*/
@Data
public class SysIotModelFieldExcel {
/**
* 所属物模型ID
*/
@ExcelProperty(value = "所属物模型名称",index = 0)
private String iotModelName;
/**
* 物模型动作编码
*/
@ExcelProperty(value = "物模型属性编码",index = 1)
private String attributeCode;
/**
* 物模型动作名称
*/
@ExcelProperty(value = "物模型属性名称",index = 2)
private String attributeName;
/**
* 属性类型
*/
@ExcelProperty(value = "属性类型",index = 3)
private Integer attributeType;
/**
* 测点序号
*/
@ExcelProperty(value = "测点序号",index = 4)
private Integer porder;
}

View File

@ -0,0 +1,51 @@
package com.das.modules.equipment.domain.excel;
import com.alibaba.excel.annotation.ExcelProperty;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.Data;
import java.io.Serializable;
/**
* 物模型动作前端回显
*
* @author guchengwei
*/
@Data
public class SysIotModelServiceExcel implements Serializable {
/**
* 所属物模型ID
*/
@ExcelProperty(value = "所属物模型名称",index = 0)
private String iotModelName;
/**
* 物模型动作编码
*/
@ExcelProperty(value = "物模型动作编码",index = 1)
private String serviceCode;
/**
* 物模型动作名称
*/
@ExcelProperty(value = "物模型动作名称",index = 2)
private String serviceName;
/**
* 动作类型
*/
@ExcelProperty(value = "动作类型",index = 3)
private Integer serviceType;
/**
* 测点序号
*/
@ExcelProperty(value = "测点序号",index = 4)
private Integer porder;
}

View File

@ -43,6 +43,6 @@ public class SysIotModelFieldVo {
*/
private Integer porder;
private Integer version;
private Integer revision;
}

View File

@ -43,6 +43,6 @@ public class SysIotModelServiceVo {
*/
private Integer porder;
private Integer version;
private Integer revision;
}

View File

@ -2,10 +2,20 @@ package com.das.modules.equipment.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.das.modules.equipment.domain.excel.SysIotModelFieldExcel;
import com.das.modules.equipment.domain.excel.SysIotModelServiceExcel;
import com.das.modules.equipment.domain.vo.SysIotModelFieldVo;
import com.das.modules.equipment.domain.vo.SysIotModelServiceVo;
import com.das.modules.equipment.entity.SysIotModel;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface SysIotModelMapper extends BaseMapper<SysIotModel> {
List<SysIotModelFieldExcel> queryFieldByModelId(Long id);
List<SysIotModelServiceExcel> queryServiceByModelId(Long id);
}

View File

@ -6,6 +6,8 @@ import com.das.modules.equipment.domain.dto.SysIotModelServiceDto;
import com.das.modules.equipment.domain.vo.SysIotModelFieldVo;
import com.das.modules.equipment.domain.vo.SysIotModelServiceVo;
import com.das.modules.equipment.domain.vo.SysIotModelVo;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.util.List;
@ -34,4 +36,6 @@ public interface SysIotModelService {
void deleteSysIotModelService(SysIotModelServiceDto sysIotModelServiceDto);
void exportSysIotModel(SysIotModelDto sysIotModelDto, HttpServletRequest request, HttpServletResponse response);
}

View File

@ -5,10 +5,14 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.das.common.config.SessionUtil;
import com.das.common.exceptions.ServiceException;
import com.das.common.utils.BeanCopyUtils;
import com.das.common.utils.ExcelUtil;
import com.das.modules.auth.domain.vo.SysUserVo;
import com.das.modules.equipment.domain.excel.SheetInfoBean;
import com.das.modules.equipment.domain.dto.SysIotModelDto;
import com.das.modules.equipment.domain.dto.SysIotModelFieldDto;
import com.das.modules.equipment.domain.dto.SysIotModelServiceDto;
import com.das.modules.equipment.domain.excel.SysIotModelFieldExcel;
import com.das.modules.equipment.domain.excel.SysIotModelServiceExcel;
import com.das.modules.equipment.domain.vo.SysIotModelFieldVo;
import com.das.modules.equipment.domain.vo.SysIotModelServiceVo;
import com.das.modules.equipment.domain.vo.SysIotModelVo;
@ -19,6 +23,8 @@ import com.das.modules.equipment.mapper.SysIotModelFieldMapper;
import com.das.modules.equipment.mapper.SysIotModelMapper;
import com.das.modules.equipment.mapper.SysIotModelServiceMapper;
import com.das.modules.equipment.service.SysIotModelService;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -242,4 +248,20 @@ public class SysIotModelServiceImpl implements SysIotModelService {
sysIotModelServiceMapper.deleteById(sysIotModelServiceDto.getId());
}
@Override
public void exportSysIotModel(SysIotModelDto sysIotModelDto, HttpServletRequest request, HttpServletResponse response) {
// 查询物模型属性和动作
List<SysIotModelFieldExcel> sysIotModelFieldVoList = sysIotModelMapper.queryFieldByModelId(sysIotModelDto.getId());
List<SysIotModelServiceExcel> sysIotModelServiceVoList = sysIotModelMapper.queryServiceByModelId(sysIotModelDto.getId());
SysIotModel sysIotModel = sysIotModelMapper.selectById(sysIotModelDto.getId());
String fileName = sysIotModel.getIotModelName()+":物模型信息表";
List<SheetInfoBean> sheetInfoBeanList = new ArrayList<>();
SheetInfoBean sheetInfoBean1 = new SheetInfoBean("物模型属性", SysIotModelFieldExcel.class, sysIotModelFieldVoList);
SheetInfoBean sheetInfoBean2 = new SheetInfoBean("物模型动作", SysIotModelServiceExcel.class, sysIotModelServiceVoList);
sheetInfoBeanList.add(sheetInfoBean1);
sheetInfoBeanList.add(sheetInfoBean2);
ExcelUtil.exportMoreSheet(fileName,request,response,sheetInfoBeanList);
}
}

View File

@ -0,0 +1,31 @@
<?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.das.modules.equipment.mapper.SysIotModelMapper">
<resultMap type="com.das.modules.equipment.domain.excel.SysIotModelServiceExcel" id="SysIotModelServiceMap">
<result property="iotModelName" column="iotModelName" jdbcType="VARCHAR"/>
<result property="serviceCode" column="service_code" jdbcType="VARCHAR"/>
<result property="serviceName" column="service_name" jdbcType="VARCHAR"/>
<result property="serviceType" column="service_type" jdbcType="INTEGER"/>
<result property="porder" column="porder" jdbcType="INTEGER"/>
</resultMap>
<resultMap type="com.das.modules.equipment.domain.excel.SysIotModelFieldExcel" id="SysIotModelFieldMap">
<result property="iotModelName" column="iotModelName" jdbcType="VARCHAR"/>
<result property="attributeCode" column="attribute_code" jdbcType="VARCHAR"/>
<result property="attributeName" column="attribute_name" jdbcType="VARCHAR"/>
<result property="attributeType" column="attribute_type" jdbcType="INTEGER"/>
<result property="porder" column="porder" jdbcType="INTEGER"/>
</resultMap>
<select id="queryFieldByModelId" resultMap="SysIotModelFieldMap">
select simf.*,sim.iot_model_name as iotModelName from sys_iot_model_field simf left join sys_iot_model sim on simf.iot_model_id = sim.id
where simf.iot_model_id = #{id}
</select>
<select id="queryServiceByModelId" resultMap="SysIotModelServiceMap">
select sims.*,sim.iot_model_name as iotModelName from sys_iot_model_service sims left join sys_iot_model sim on sims.iot_model_id = sim.id
where sims.iot_model_id = #{id}
</select>
</mapper>