das接口修改

This commit is contained in:
chenhaojie 2024-07-15 16:48:20 +08:00
parent 387d1d9410
commit e10c5d919d
62 changed files with 400 additions and 354 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
@ -80,19 +80,19 @@
<version>${sa.version}</version>
</dependency>
<!-- easyexcel导入导出 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
<version>${easyexcel.version}</version>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>${apache.poi}</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>${apache.poi}</version>
<groupId>cn.hutool</groupId>
<artifactId>hutool-poi</artifactId>
<version>${hutool.version}</version>
</dependency>
<!-- 提供Redis连接池 -->
<dependency>
<groupId>org.apache.commons</groupId>

View File

@ -6,7 +6,7 @@ import org.springframework.stereotype.Component;
/**
* @author chenhaojie
* @Description
*
*/
@Component
@Data

View File

@ -11,7 +11,7 @@ import java.time.Duration;
/**
* @author chenhaojie
* @Description
*
*/
public class CaptchaUtils {

View File

@ -5,7 +5,7 @@ import lombok.NoArgsConstructor;
/**
* @author chenhaojie
* @Description
*
*/
@NoArgsConstructor
@Data

View File

@ -2,7 +2,7 @@ package com.das.common.captcha;
/**
* @author chenhaojie
* @Description
*
*/
public enum VerifyTypeEnum {

View File

@ -6,8 +6,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* @author zb
* @Description
* @author chenhaojie
*
*/
@Component
@Getter

View File

@ -6,8 +6,8 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
/**
* @author zb
* @Description
* @author chenhaojie
*
*/
@Component

View File

@ -12,7 +12,7 @@ import org.springframework.context.annotation.Configuration;
/**
* @author chenhaojie
* @Description
*
*/
@MapperScan(basePackages = {"com.das.**.mapper"})
@Configuration

View File

@ -9,7 +9,7 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
/**
* @author chenhaojie
* @Description 配置redis序列化与反序列化
*
*/
@Configuration
public class RedisConfig {

View File

@ -2,7 +2,7 @@ package com.das.common.constant;
/**
* @author chenhaojie
* @Description
*
*/
public interface AdminConstant {

View File

@ -13,7 +13,6 @@ import java.util.Date;
/**
* @author chenhaojie
* @Description 父类
*/
@Data
public class BaseEntity implements Serializable {

View File

@ -11,7 +11,7 @@ import java.util.List;
/**
* @author chenhaojie
* @Description
*
*/
@Validated
public class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseEntity> extends ServiceImpl<M, T> implements IBaseService<T> {

View File

@ -2,7 +2,7 @@ package com.das.common.constant;
/**
* @author chenhaojie
* @Description
*
*/
public interface DataStatus {

View File

@ -7,22 +7,19 @@ import java.util.List;
/**
* @author chenhaojie
* @Description 父类
*
*/
public interface IBaseService<T> extends IService<T> {
/**
* 批量逻辑删除
* @param ids
* @return
*
*/
boolean deleteLogic(@NotNull List<Long> ids);
/***
* 批量改变状态
* @param ids
* @param status
* @return
*
*/
boolean changeStatus(@NotNull List<Long> ids, String status);

View File

@ -8,8 +8,7 @@ import java.io.Serial;
/**
* @author chenhaojie
* @Description 自定义业务异常
* 全局捕获的业务异常只会记录本项目抛出的堆栈异常信息
*
*/
public class BusinessException extends RuntimeException {

View File

@ -7,7 +7,7 @@ import java.io.Serial;
/**
* @author chenhaojie
* @Description
*
*/
public class EasyExcelException extends RuntimeException {

View File

@ -8,7 +8,7 @@ import java.io.Serial;
/**
* @author chenhaojie
* @Description oss存储服务异常
*
*/
public class OssException extends RuntimeException {

View File

@ -9,7 +9,7 @@ import java.io.Serial;
/**
* @author chenhaojie
* @Description 频率限制异常
*
*/
@Getter
public class RateLimiterException extends RuntimeException {

View File

@ -9,7 +9,7 @@ import java.io.Serial;
/**
* @author chenhaojie
* @Description 频率限制异常
*
*/
@Getter
public class RepeatSubmitException extends RuntimeException {

View File

@ -8,7 +8,7 @@ import java.io.Serial;
/**
* @author chenhaojie
* @Description 自定义服务异常
*
*/
public class ServiceException extends RuntimeException {

View File

@ -23,7 +23,6 @@ import java.util.stream.Collectors;
/**
* @author chenhaojie
* @Description 全局异常拦截
* <p>
* 如果我同时捕获了父类和子类那么到底能够被那个异常处理器捕获呢比如 Exception BusinessException
* 当然是 BusinessException 的异常处理器捕获了精确匹配如果没有 BusinessException 的异常处理器才会轮到它的 父亲
@ -37,7 +36,7 @@ public class GlobalExceptionHandler {
/**
* @param businessException 业务异常
* @return @ResponseBody
* @ExceptionHandler相当于controller的@RequestMapping 如果抛出的的是BusinessException则调用该方法
*
*/
@ExceptionHandler(BusinessException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)

View File

@ -12,7 +12,7 @@ import org.springframework.http.MediaType;
import org.springframework.web.filter.OncePerRequestFilter;
import org.springframework.web.multipart.support.StandardMultipartHttpServletRequest;
import java.io.*;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import static com.das.common.constant.HeaderConstant.IV_ATTR_NAME;

View File

@ -8,8 +8,8 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author
* @Description 请求参数过滤器配置
* @author chenhaojie
*
*/
@Configuration
public class FilterConfig {

View File

@ -7,7 +7,7 @@ import java.util.concurrent.Executor;
/**
* @author chenhaojie
* @Description 解决线程异步场景下RequestId的打印问题
*
*/
@Slf4j
public class MdcExecutor implements Executor {

View File

@ -4,7 +4,7 @@ import java.util.UUID;
/**
* @author chenhaojie
* @Description
*
*/
public class RequestIdUtils {

View File

@ -14,7 +14,7 @@ import java.util.UUID;
/**
* @author chenhaojie
* @Description
*
*/
@Slf4j
public class RequestLogInterceptor implements HandlerInterceptor {

View File

@ -4,7 +4,7 @@ import java.io.Serializable;
/**
* @author chenhaojie
* @Description
*
*/
public interface IResultCode extends Serializable {
/**

View File

@ -10,7 +10,7 @@ import java.util.Optional;
/**
* @author chenhaojie
* @Description 公共返回信息
*
*/
@Setter
@Getter

View File

@ -2,7 +2,7 @@ package com.das.common.result;
/**
* @author chenhaojie
* @Description
*
*/
public enum ResultCode implements IResultCode {
/**

View File

@ -8,8 +8,7 @@ import cn.hutool.crypto.symmetric.AES;
import java.nio.charset.StandardCharsets;
/**
* @author xxx
* @date 2020-09-16 11:17
* @author chenhaojie
**/
public class AESUtil {

View File

@ -13,7 +13,7 @@ import java.util.function.Supplier;
/**
* @author chenhaojie
* @Description redis 工具类
*
*/
@Component
public class AdminRedisTemplate {

View File

@ -1,55 +0,0 @@
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

@ -0,0 +1,67 @@
package com.das.common.utils;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.das.modules.equipment.domain.excel.SheetInfoBean;
import jakarta.servlet.ServletOutputStream;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpHeaders;
import org.springframework.util.CollectionUtils;
import java.io.IOException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.List;
@Slf4j
public class HuExcelUtils {
/**
* 导出多个 Sheet
*/
public static void exportExcel(HttpServletResponse response, List<SheetInfoBean> sheetList, String fileName) {
ExcelWriter bigWriter = ExcelUtil.getBigWriter();
// 重命名第一个Sheet的名称不然会默认多出一个Sheet1的页
bigWriter.renameSheet(0, sheetList.get(0).getSheetName());
for (SheetInfoBean sheetDto : sheetList) {
// 指定要写出的 Sheet
bigWriter.setSheet(sheetDto.getSheetName());
List<Integer> columnWidthList = sheetDto.getColumnWidth();
if (CollectionUtils.isEmpty(columnWidthList) || columnWidthList.size() != sheetDto.getFieldAndAlias().size()) {
// 设置默认宽度
for (int i = 0; i < sheetDto.getFieldAndAlias().size(); i++) {
bigWriter.setColumnWidth(i, 25);
}
} else {
// 设置自定义宽度
for (int i = 0; i < columnWidthList.size(); i++) {
bigWriter.setColumnWidth(i, columnWidthList.get(i));
}
}
// 设置字段和别名
bigWriter.setHeaderAlias(sheetDto.getFieldAndAlias());
// 设置只导出有别名的字段
bigWriter.setOnlyAlias(true);
// 设置默认行高
bigWriter.setDefaultRowHeight(18);
// 一次性写出内容使用默认样式强制输出标题
bigWriter.write(sheetDto.getCollection(), true);
}
ServletOutputStream out = null;
try {
//attachment 弹出下载对话框 inline 则会使用默认浏览器打开文件不出现弹框在线预览
response.setHeader(HttpHeaders.CONTENT_DISPOSITION, String.format("attachment;filename=%s", URLEncoder.encode(fileName + ".xls", StandardCharsets.UTF_8)));
out = response.getOutputStream();
//这里的servlet流会自动关闭, 我们不需要手动自己去关, 否则会报 stream is close错误
bigWriter.flush(out, true);
} catch (IOException e) {
log.error("导出多个 Sheet 页异常:" + e.getMessage());
} finally {
// 关闭writer释放内存
bigWriter.close();
}
}
}

View File

@ -18,7 +18,7 @@ import java.util.Map;
/**
* @author chenhaojie
* @Description
*
*/
@Component
public class SpringUtil implements BeanFactoryPostProcessor, ApplicationContextAware {

View File

@ -25,7 +25,7 @@ import org.springframework.web.bind.annotation.RestController;
/**
* @author chenhaojie
* @Description 登录控制层
*
*/
@Slf4j
@RequestMapping("/api/auth")

View File

@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.RestController;
/**
* @author chenhaojie
* @Description 角色控制层
*
*/
@Slf4j
@RequestMapping("/api/authority")

View File

@ -20,7 +20,7 @@ import org.springframework.web.bind.annotation.RestController;
/**
* @author chenhaojie
* @Description 菜单控制层
*
*/
@Slf4j
@RequestMapping("/api/menus")

View File

@ -18,7 +18,7 @@ import org.springframework.web.bind.annotation.RestController;
/**
* @author chenhaojie
* @Description 用户控制层
*
*/
@Slf4j
@RequestMapping("/api/org")

View File

@ -18,7 +18,7 @@ import org.springframework.web.bind.annotation.RestController;
/**
* @author chenhaojie
* @Description 角色控制层
*
*/
@Slf4j
@RequestMapping("/api/role")

View File

@ -18,7 +18,7 @@ import org.springframework.web.bind.annotation.RestController;
/**
* @author chenhaojie
* @Description 用户控制层
*
*/
@Slf4j
@RequestMapping("/api/user")

View File

@ -6,7 +6,7 @@ import lombok.Data;
/**
* @author chenhaojie
* @Description
*
*/
@Data
public class LoginDto {

View File

@ -6,7 +6,7 @@ import lombok.Data;
/**
* @author chenhaojie
* @Description
*
*/
@Data
public class RefreshTokenDto {

View File

@ -7,7 +7,7 @@ import java.io.Serializable;
/**
* @author chenhaojie
* @Description
*
*/
@Data
public class LoginUserDetailsVo implements Serializable {

View File

@ -7,7 +7,7 @@ import java.io.Serializable;
/**
* @author chenhaojie
* @Description
*
*/
@Data
public class LoginVo implements Serializable {

View File

@ -5,15 +5,11 @@ import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.das.common.constant.BaseEntity;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import java.io.Serial;
/**
* <p>
* 权限信息

View File

@ -12,7 +12,7 @@ import jakarta.servlet.http.HttpServletResponse;
/**
* @author chenhaojie
* @Description
*
*/
public interface LoginService {

View File

@ -31,7 +31,7 @@ import java.util.Date;
/**
* @author chenhaojie
* @Description
*
*/
@Service
public class LoginServiceImpl implements LoginService {

View File

@ -18,6 +18,7 @@ import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
@ -52,10 +53,10 @@ public class EquipmentController {
@PostMapping("/add")
public R<SysEquipmentVo> addSysEquipment(@RequestBody SysEquipmentDto sysEquipmentDto) {
//判断是否有权限
// boolean hasPermission = StpUtil.hasPermission(SysAuthorityIds.SYS_AUTHORITY_ID_DEVICE_MGR.toString());
// if(!hasPermission){
// return R.fail("没有设备管理权限");
// }
boolean hasPermission = StpUtil.hasPermission(SysAuthorityIds.SYS_AUTHORITY_ID_DEVICE_MGR.toString());
if(!hasPermission){
return R.fail("没有设备管理权限");
}
return R.success(sysEquipmentService.creatSysEquipment(sysEquipmentDto));
}
@ -130,7 +131,7 @@ public class EquipmentController {
/** 设备导出 */
@PostMapping("/import")
public R<Void> importSysIotModel(String id, @RequestParam("file") MultipartFile file) throws IOException {
public R<Void> importSysIotModel(String id, @RequestParam("file") MultipartFile file) throws IOException, ParseException {
sysEquipmentService.importSysEquipment(id, file);
return R.success();
}

View File

@ -226,12 +226,12 @@ public class SysIotModelController {
/** 物模型导入 */
@PostMapping("/import")
public R<Void> importSysIotModel(String id, @RequestParam("file") MultipartFile file) throws IOException {
public R<Void> importSysIotModel(String iotModelId, @RequestParam("file") MultipartFile file) throws IOException {
if (StringUtils.isEmpty(id)) {
if (StringUtils.isEmpty(iotModelId)) {
throw new ServiceException("请选择需要导入的物模型属性信息");
}
sysIotModelService.importSysIotModel(id, file);
sysIotModelService.importSysIotModel(iotModelId, file);
return R.success();
}

View File

@ -1,31 +1,52 @@
package com.das.modules.equipment.domain.excel;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
public class SheetInfoBean {
private static final long serialVersionUID = 1L;
/**
* sheet页名称
*/
* */
private String sheetName;
/**
* sheet标题bean
* 字段和别名如果使用这个properties titles可以不用处理
* 如果要求导出字段按集合顺序则需要LinkedHashMap 无要求则用HashMap
* LinkedHashMap<字段, 别名> LinkedHashMap<"name", "姓名">
*/
private Class<?> headClass;
private LinkedHashMap<String, String> fieldAndAlias;
/**
* sheet页数据
* 列宽<br/>
* 设置列宽时必须每个字段都设置才生效columnWidth.size = fieldAndAlias.size
*/
private List<?> dataList;
private List<Integer> columnWidth;
/**
* 数据集 需要导出的数据集
* */
private Collection<?> collection;
public SheetInfoBean() {
}
public SheetInfoBean(String sheetName, Class<?> headClass, List<?> dataList) {
/**
*
* @param sheetName sheet页名称
* @param fieldAndAlias 字段和别名
* @param collection 数据集
*/
public SheetInfoBean(String sheetName, LinkedHashMap<String, String> fieldAndAlias, Collection<?> collection) {
super();
this.sheetName = sheetName;
this.headClass = headClass;
this.dataList = dataList;
this.fieldAndAlias = fieldAndAlias;
this.collection = collection;
}
public String getSheetName() {
@ -36,28 +57,27 @@ public class SheetInfoBean {
this.sheetName = sheetName;
}
public Class<?> getHeadClass() {
return headClass;
public Map<String, String> getFieldAndAlias() {
return fieldAndAlias;
}
public void setHeadClass(Class<?> headClass) {
this.headClass = headClass;
public void setFieldAndAlias(LinkedHashMap<String, String> fieldAndAlias) {
this.fieldAndAlias = fieldAndAlias;
}
public List<?> getDataList() {
return dataList;
public List<Integer> getColumnWidth() {
return this.columnWidth;
}
public void setDataList(List<?> dataList) {
this.dataList = dataList;
public void setColumnWidth(List<Integer> columnWidth) {
this.columnWidth = columnWidth;
}
@Override
public String toString() {
return "SheetInfoBean{" +
"sheetName='" + sheetName + '\'' +
", headClass=" + headClass +
", dataList=" + dataList +
'}';
public Collection<?> getCollection() {
return collection;
}
public void setCollection(Collection<?> collection) {
this.collection = collection;
}
}

View File

@ -1,6 +1,5 @@
package com.das.modules.equipment.domain.excel;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
import java.util.Date;
@ -11,79 +10,66 @@ public class SysEquipmentExcel {
/**
* 设备类型编码
*/
@ExcelProperty(value = "设备类型编码",index = 0)
private Integer objectType;
/**
* 所属物模型ID
*/
@ExcelProperty(value = "所属物模型名称",index = 1)
private String iotModelName;
/**
* 设备编码
*/
@ExcelProperty(value = "设备编码",index = 2)
private String code;
/**
* 设备名称
*/
@ExcelProperty(value = "设备名称",index = 3)
private String name;
/**
* 制造商
*/
@ExcelProperty(value = "制造商",index = 4)
private String madeinFactory;
/**
* 型号规格
*/
@ExcelProperty(value = "型号规格",index = 5)
private String model;
/**
* 安装位置
*/
@ExcelProperty(value = "安装位置",index = 6)
private String location;
/**
* 安装位置_经度
*/
@ExcelProperty(value = "安装位置_经度",index = 7)
private Double longitude;
/**
* 安装位置_纬度
*/
@ExcelProperty(value = "安装位置_纬度",index = 8)
private Double latitude;
/**
* 安装日期
*/
@ExcelProperty(value = "安装日期",index = 9)
private Date installDate;
/**
* 备注
*/
@ExcelProperty(value = "备注",index = 10)
private String remarks;
/**
* 机构id
*/
@ExcelProperty(value = "机构名称",index = 11)
private String orgName;
/**
* 上级设备id
*/
@ExcelProperty(value = "上级设备名称",index = 12)
private String parentEquipmentName;
}

View File

@ -1,6 +1,5 @@
package com.das.modules.equipment.domain.excel;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
@ -16,32 +15,32 @@ public class SysIotModelFieldExcel {
/**
* 所属物模型ID
*/
@ExcelProperty(value = "所属物模型名称",index = 0)
// @Excel(name = "所属物模型名称", width = 20.0)
private String iotModelName;
/**
* 物模型动作编码
*/
@ExcelProperty(value = "物模型属性编码",index = 1)
// @Excel(name = "物模型属性编码", width = 20.0)
private String attributeCode;
/**
* 物模型动作名称
*/
@ExcelProperty(value = "物模型属性名称",index = 2)
// @Excel(name = "物模型属性名称", width = 20.0)
private String attributeName;
/**
* 属性类型
*/
@ExcelProperty(value = "属性类型",index = 3)
// @Excel(name = "属性类型", width = 20.0)
private Integer attributeType;
/**
* 测点序号
*/
@ExcelProperty(value = "测点序号",index = 4)
// @Excel(name = "测点序号", width = 20.0)
private Integer porder;
}

View File

@ -1,6 +1,5 @@
package com.das.modules.equipment.domain.excel;
import com.alibaba.excel.annotation.ExcelProperty;
import lombok.Data;
import java.io.Serializable;
@ -18,32 +17,32 @@ public class SysIotModelServiceExcel implements Serializable {
/**
* 所属物模型ID
*/
@ExcelProperty(value = "所属物模型名称",index = 0)
// @Excel(name = "所属物模型名称", width = 20.0)
private String iotModelName;
/**
* 物模型动作编码
*/
@ExcelProperty(value = "物模型动作编码",index = 1)
// @Excel(name = "物模型动作编码", width = 20.0)
private String serviceCode;
/**
* 物模型动作名称
*/
@ExcelProperty(value = "物模型动作名称",index = 2)
// @Excel(name = "物模型动作名称", width = 20.0)
private String serviceName;
/**
* 动作类型
*/
@ExcelProperty(value = "动作类型",index = 3)
// @Excel(name = "动作类型", width = 20.0)
private Integer serviceType;
/**
* 测点序号
*/
@ExcelProperty(value = "测点序号",index = 4)
// @Excel(name = "测点序号", width = 20.0)
private Integer porder;
}

View File

@ -1,32 +0,0 @@
package com.das.modules.equipment.listener;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import java.util.ArrayList;
import java.util.List;
public class ExcelListener extends AnalysisEventListener{
//可以通过实例获取该值
private List<Object> datas = new ArrayList<Object>();
public void invoke(Object o, AnalysisContext analysisContext) {
datas.add(o);
doSomething(o);
}
private void doSomething(Object object) {
}
public List<Object> getDatas() {
return datas;
}
public void setDatas(List<Object> datas) {
this.datas = datas;
}
public void doAfterAllAnalysed(AnalysisContext analysisContext) {
}
}

View File

@ -1,8 +1,8 @@
package com.das.modules.equipment.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.das.modules.auth.mapper.BaseMapperPlus;
import com.das.modules.equipment.domain.dto.SysEquipmentDto;
import com.das.modules.equipment.domain.excel.SysEquipmentExcel;
import com.das.modules.equipment.domain.vo.SysEquipmentVo;
@ -13,7 +13,7 @@ import org.apache.ibatis.annotations.Param;
import java.util.List;
@Mapper
public interface SysEquipmentMapper extends BaseMapper<SysEquipment> {
public interface SysEquipmentMapper extends BaseMapperPlus<SysEquipment, SysEquipment> {
IPage<SysEquipmentVo> querySysEquipmentList(IPage<SysEquipmentVo> page, @Param("info") SysEquipmentDto sysEquipmentDto);

View File

@ -8,6 +8,7 @@ import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.text.ParseException;
import java.util.List;
public interface SysEquipmentService {
@ -25,6 +26,6 @@ public interface SysEquipmentService {
void exportSysEquipment(SysEquipmentDto sysEquipmentDto, HttpServletRequest request, HttpServletResponse response);
void importSysEquipment(String parentEquipmentId,MultipartFile file) throws IOException;
void importSysEquipment(String parentEquipmentId,MultipartFile file) throws IOException, ParseException;
}

View File

@ -1,36 +1,46 @@
package com.das.modules.equipment.service.impl;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.bean.BeanUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelReader;
import com.alibaba.excel.read.metadata.ReadSheet;
import cn.hutool.core.io.IoUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.das.common.config.SessionUtil;
import com.das.common.utils.*;
import com.das.common.utils.BeanCopyUtils;
import com.das.common.utils.PageDataInfo;
import com.das.common.utils.PageQuery;
import com.das.common.utils.SequenceUtils;
import com.das.modules.auth.domain.vo.SysUserVo;
import com.das.modules.auth.mapper.SysOrgMapper;
import com.das.modules.equipment.domain.dto.SysEquipmentDto;
import com.das.modules.equipment.domain.excel.SheetInfoBean;
import com.das.modules.equipment.domain.excel.SysEquipmentExcel;
import com.das.modules.equipment.domain.vo.SysEquipmentVo;
import com.das.modules.equipment.entity.SysEquipment;
import com.das.modules.equipment.listener.ExcelListener;
import com.das.modules.equipment.mapper.SysEquipmentMapper;
import com.das.modules.equipment.mapper.SysIotModelMapper;
import com.das.modules.equipment.service.SysEquipmentService;
import jakarta.servlet.ServletOutputStream;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
@Transactional(rollbackFor = Exception.class)
@ -49,33 +59,30 @@ public class SysEquipmentServiceImpl implements SysEquipmentService {
@Override
public SysEquipmentVo creatSysEquipment(SysEquipmentDto sysEquipmentDto) {
SysEquipment sysEquipment = new SysEquipment();
BeanCopyUtils.copy(sysEquipmentDto,sysEquipment);
BeanCopyUtils.copy(sysEquipmentDto, sysEquipment);
// SysUserVo sysUserVo = (SysUserVo) StpUtil.getTokenSession().get(SessionUtil.SESSION_USER_KEY);
SysUserVo sysUserVo = (SysUserVo) StpUtil.getTokenSession().get(SessionUtil.SESSION_USER_KEY);
sysEquipment.setCreatedTime(new Date());
sysEquipment.setUpdatedTime(new Date());
// sysEquipment.setCreatedBy(sysUserVo.getAccount());
// sysEquipment.setUpdatedBy(sysUserVo.getAccount());
sysEquipment.setCreatedBy("测试");
sysEquipment.setUpdatedBy("测试");
sysEquipment.setCreatedBy(sysUserVo.getAccount());
sysEquipment.setUpdatedBy(sysUserVo.getAccount());
sysEquipment.setRevision(1);
sysEquipmentMapper.insert(sysEquipment);
SysEquipmentVo sysEquipmentVo = new SysEquipmentVo();
BeanCopyUtils.copy(sysEquipment,sysEquipmentVo);
BeanCopyUtils.copy(sysEquipment, sysEquipmentVo);
return sysEquipmentVo;
}
@Override
public SysEquipmentVo updateSysEquipment(SysEquipmentDto sysEquipmentDto) {
SysEquipment sysEquipment = new SysEquipment();
BeanCopyUtils.copy(sysEquipmentDto,sysEquipment);
BeanCopyUtils.copy(sysEquipmentDto, sysEquipment);
SysUserVo sysUserVo = (SysUserVo) StpUtil.getTokenSession().get(SessionUtil.SESSION_USER_KEY);
sysEquipment.setUpdatedTime(new Date());
// sysEquipment.setUpdatedBy("测试");
sysEquipment.setUpdatedBy(sysUserVo.getAccount());
sysEquipmentMapper.updateById(sysEquipment);
SysEquipmentVo sysEquipmentVo = new SysEquipmentVo();
BeanCopyUtils.copy(sysEquipment,sysEquipmentVo);
BeanCopyUtils.copy(sysEquipment, sysEquipmentVo);
return sysEquipmentVo;
}
@ -104,6 +111,7 @@ public class SysEquipmentServiceImpl implements SysEquipmentService {
queryWrapper.eq("org_id", sysEquipmentDto.getOrgId());
queryWrapper.eq("parent_equipment_id", sysEquipmentDto.getParentEquipmentId());
queryWrapper.eq("object_type", sysEquipmentDto.getObjectType());
queryWrapper.orderByAsc("name");
List<SysEquipment> sysEquipmentList = sysEquipmentMapper.selectList(queryWrapper);
List<SysEquipmentVo> list = new ArrayList<>();
list.addAll(BeanCopyUtils.copyList(sysEquipmentList, SysEquipmentVo.class));
@ -118,55 +126,99 @@ public class SysEquipmentServiceImpl implements SysEquipmentService {
@Override
public void exportSysEquipment(SysEquipmentDto sysEquipmentDto, HttpServletRequest request, HttpServletResponse response) {
// 查询物模型属性和动作
List<SysEquipmentExcel> sysEquipmentList = sysEquipmentMapper.queryInfoById(sysEquipmentDto);
String fileName = "设备类型信息表";
List<SheetInfoBean> sheetInfoBeanList = new ArrayList<>();
SheetInfoBean sheetInfoBean = new SheetInfoBean("设备类型信息", SysEquipmentExcel.class, sysEquipmentList);
sheetInfoBeanList.add(sheetInfoBean);
ExcelUtil.exportMoreSheet(fileName,request,response,sheetInfoBeanList);
//自定义别名 别名的key和实体类中的名称要对应上
LinkedHashMap<String, String> map = new LinkedHashMap<>();
map.put("objectType", "设备类型编码");
map.put("iotModelName", "所属物模型名称");
map.put("code", "设备编码");
map.put("name", "设备名称");
map.put("madeinFactory", "制造商");
map.put("model", "型号规格");
map.put("location", "安装位置");
map.put("longitude", "经度");
map.put("latitude", "纬度");
map.put("installDate", "安装时间");
map.put("remarks", "备注");
map.put("orgName", "机构名称");
map.put("parentEquipmentName", "上级设备名称");
ExcelWriter writer = new ExcelWriter();
writer.setHeaderAlias(map);
//水平居中对齐垂直中间对齐
writer.getStyleSet().setAlign(HorizontalAlignment.CENTER, VerticalAlignment.CENTER);
//所有单元格宽25个字符
writer.setColumnWidth(-1, 25);
// 一次性写出内容使用默认样式强制输出标题
writer.write(sysEquipmentList, true);
response.setCharacterEncoding(StandardCharsets.UTF_8.name());
response.setContentType("application/octet-stream");
ServletOutputStream out = null;
try {
// 设置请求头属性
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("设备类型信息表.xls", StandardCharsets.UTF_8));
out = response.getOutputStream();
// 写出到文件
writer.flush(out, true);
// 关闭writer释放内存
writer.close();
// 此处记得关闭输出Servlet流
IoUtil.close(out);
} catch (IOException e) {
throw new RuntimeException("文件下载失败==" + e);
}
}
@Override
public void importSysEquipment(String parentEquipmentId, MultipartFile file) throws IOException {
//输入流
InputStream inputStream = file.getInputStream();
//监视器
ExcelListener listener = new ExcelListener();
ExcelReader excelReader = EasyExcel.read(inputStream, listener).build();
// 第一个sheet读取物模型属性
ReadSheet readSheet = EasyExcel.readSheet(0).head(SysEquipmentExcel.class).build();
// 开始读取第一个sheet
excelReader.read(readSheet);
//excel sheet0 信息
List<Object> fieldList = listener.getDatas();
//List<object> List<实体类>
public void importSysEquipment(String parentEquipmentId, MultipartFile file) throws IOException, ParseException {
// 通过文件获取输入流
InputStream is = file.getInputStream();
// 借助hutool读取
ExcelReader reader = ExcelUtil.getReader(is);
List<List<Object>> list = reader.read(1); // 从第二行开始读
// 创建一个List集合
List<SysEquipment> sysEquipmentList = new ArrayList<>();
//List object for 转换 实体类
for (Object objects : fieldList) {
SysEquipmentExcel dto = (SysEquipmentExcel) objects;
// 遍历
for (List<Object> row : list) {
SysEquipment field = new SysEquipment();
BeanUtil.copyProperties(dto,field);
// 根据名称获取物模型id
if(StringUtils.isNotBlank(dto.getOrgName())) {
Long iotModelId = sysIotModelMapper.queryIotModelIdByName(dto.getIotModelName());
if (StringUtils.hasText(row.get(1).toString())) {
Long iotModelId = sysIotModelMapper.queryIotModelIdByName(row.get(1).toString());
field.setIotModelId(iotModelId);
}
if(StringUtils.isNotBlank(dto.getOrgName())) {
Long orgId = sysOrgMapper.queryOrgIdByName(dto.getOrgName());
if (StringUtils.hasText(row.get(11).toString())) {
Long orgId = sysOrgMapper.queryOrgIdByName(row.get(11).toString());
field.setOrgId(orgId);
}
// 转换成字符串
field.setObjectType(Integer.valueOf(row.get(0).toString()));
field.setCode(row.get(2).toString());
field.setName(row.get(3).toString());
field.setMadeinFactory(row.get(4).toString());
field.setModel(row.get(5).toString());
field.setLocation(row.get(6).toString());
if (StringUtils.hasText(row.get(7).toString())) {
field.setLongitude(Double.valueOf(row.get(7).toString()));
}
if (StringUtils.hasText(row.get(8).toString())) {
field.setLatitude(Double.valueOf(row.get(8).toString()));
}
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
if (StringUtils.hasText(row.get(9).toString())) {
field.setInstallDate(sf.parse(row.get(9).toString()));
}
field.setRemarks(row.get(10).toString());
field.setParentEquipmentId(Long.valueOf(parentEquipmentId));
// 遍历完一个添加一个
field.setRevision(1);
field.setId(SequenceUtils.generateId());
field.setCreatedTime(new Date());
field.setUpdatedTime(new Date());
field.setRevision(1);
// field.setCreatedBy(StpUtil.getLoginIdAsString());
// field.setUpdatedBy(StpUtil.getLoginIdAsString());
field.setCreatedBy("测试人员");
field.setUpdatedBy("测试人员");
field.setCreatedBy(StpUtil.getLoginIdAsString());
field.setUpdatedBy(StpUtil.getLoginIdAsString());
sysEquipmentList.add(field);
}
sysEquipmentMapper.insertBatch(sysEquipmentList);
}
}

View File

@ -1,10 +1,8 @@
package com.das.modules.equipment.service.impl;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.bean.BeanUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelReader;
import com.alibaba.excel.read.metadata.ReadSheet;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.das.common.config.SessionUtil;
@ -23,26 +21,27 @@ import com.das.modules.equipment.domain.vo.SysIotModelVo;
import com.das.modules.equipment.entity.SysIotModel;
import com.das.modules.equipment.entity.SysIotModelField;
import com.das.modules.equipment.entity.SysIotModelServices;
import com.das.modules.equipment.listener.ExcelListener;
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 lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
@Transactional(rollbackFor = Exception.class)
@Service
@Slf4j
public class SysIotModelServiceImpl implements SysIotModelService {
@Autowired
@ -57,12 +56,12 @@ public class SysIotModelServiceImpl implements SysIotModelService {
public SysIotModelVo creatSysIotModel(SysIotModelDto sysIotModelDto) {
SysIotModel sysIotModel = new SysIotModel();
BeanCopyUtils.copy(sysIotModelDto,sysIotModel);
BeanCopyUtils.copy(sysIotModelDto, sysIotModel);
QueryWrapper<SysIotModel> sysIotModelQueryWrapper = new QueryWrapper<>();
sysIotModelQueryWrapper.eq("iot_model_code", sysIotModelDto.getIotModelCode());
SysIotModel sysIotModelQuery = sysIotModelMapper.selectOne(sysIotModelQueryWrapper);
if (!(sysIotModelQuery == null)){
if (!(sysIotModelQuery == null)) {
throw new ServiceException("物模型code已经存在");
}
SysUserVo sysUserVo = (SysUserVo) StpUtil.getTokenSession().get(SessionUtil.SESSION_USER_KEY);
@ -74,27 +73,27 @@ public class SysIotModelServiceImpl implements SysIotModelService {
sysIotModel.setRevision(1);
sysIotModelMapper.insert(sysIotModel);
SysIotModelVo sysIotModelVo = new SysIotModelVo();
BeanCopyUtils.copy(sysIotModel,sysIotModelVo);
BeanCopyUtils.copy(sysIotModel, sysIotModelVo);
return sysIotModelVo;
}
public SysIotModelVo updateSysIotModel(SysIotModelDto sysIotModelDto) {
SysIotModel sysIotModel = new SysIotModel();
BeanCopyUtils.copy(sysIotModelDto,sysIotModel);
BeanCopyUtils.copy(sysIotModelDto, sysIotModel);
SysUserVo sysUserVo = (SysUserVo) StpUtil.getTokenSession().get(SessionUtil.SESSION_USER_KEY);
sysIotModel.setUpdatedTime(new Date());
sysIotModel.setUpdatedBy(sysUserVo.getAccount());
// sysIotModel.setUpdatedBy("sysUserVo.getAccount()");
sysIotModelMapper.updateById(sysIotModel);
SysIotModelVo sysIotModelVo = new SysIotModelVo();
BeanCopyUtils.copy(sysIotModel,sysIotModelVo);
BeanCopyUtils.copy(sysIotModel, sysIotModelVo);
return sysIotModelVo;
}
@Override
public void deleteSysIotModel(SysIotModelDto sysIotModelDto) {
// 物模型下面有类型或者动作则不能删除
if ((sysIotModelServiceMapper.querySysIotModelServiceByModelId(sysIotModelDto.getId()) > 0) || (sysIotModelFieldMapper.querySysIotModelFieldByModelId(sysIotModelDto.getId()) > 0)){
if ((sysIotModelServiceMapper.querySysIotModelServiceByModelId(sysIotModelDto.getId()) > 0) || (sysIotModelFieldMapper.querySysIotModelFieldByModelId(sysIotModelDto.getId()) > 0)) {
throw new RuntimeException("该物模型下面有类型,不能删除");
}
sysIotModelMapper.deleteById(sysIotModelDto.getId());
@ -106,17 +105,17 @@ public class SysIotModelServiceImpl implements SysIotModelService {
List<SysIotModelVo> sysIotModelVoList = new ArrayList<>();
List<SysIotModel> sysIotModels;
QueryWrapper<SysIotModel> sysIotModelQueryWrapper = new QueryWrapper<>();
if (sysIotModelDto.getIotModelCode() == null && sysIotModelDto.getIotModelName() == null){
if (sysIotModelDto.getIotModelCode() == null && sysIotModelDto.getIotModelName() == null) {
sysIotModelQueryWrapper.orderByAsc("object_type");
sysIotModels = sysIotModelMapper.selectList(sysIotModelQueryWrapper);
} else {
sysIotModelQueryWrapper.like("iot_model_code",sysIotModelDto.getIotModelCode()).or().like("iot_model_name",sysIotModelDto.getIotModelName());
sysIotModelQueryWrapper.like("iot_model_code", sysIotModelDto.getIotModelCode()).or().like("iot_model_name", sysIotModelDto.getIotModelName());
sysIotModelQueryWrapper.orderByAsc("object_type");
sysIotModels = sysIotModelMapper.selectList(sysIotModelQueryWrapper);
}
for (SysIotModel item : sysIotModels){
for (SysIotModel item : sysIotModels) {
SysIotModelVo sysIotModelVo = new SysIotModelVo();
BeanCopyUtils.copy(item,sysIotModelVo);
BeanCopyUtils.copy(item, sysIotModelVo);
sysIotModelVoList.add(sysIotModelVo);
}
return sysIotModelVoList;
@ -134,12 +133,12 @@ public class SysIotModelServiceImpl implements SysIotModelService {
@Override
public SysIotModelFieldVo creatSysIotModelField(SysIotModelFieldDto sysIotModelFieldDto) {
SysIotModelField sysIotModelField = new SysIotModelField();
BeanCopyUtils.copy(sysIotModelFieldDto,sysIotModelField);
BeanCopyUtils.copy(sysIotModelFieldDto, sysIotModelField);
QueryWrapper<SysIotModelField> sysIotModelFieldQueryWrapper = new QueryWrapper<>();
sysIotModelFieldQueryWrapper.eq("attribute_code", sysIotModelFieldDto.getAttributeCode());
SysIotModelField sysIotModelFieldQuery = sysIotModelFieldMapper.selectOne(sysIotModelFieldQueryWrapper);
if (!(sysIotModelFieldQuery == null)){
if (!(sysIotModelFieldQuery == null)) {
throw new ServiceException("物模型属性code已经存在");
}
SysUserVo sysUserVo = (SysUserVo) StpUtil.getTokenSession().get(SessionUtil.SESSION_USER_KEY);
@ -151,21 +150,21 @@ public class SysIotModelServiceImpl implements SysIotModelService {
sysIotModelField.setRevision(1);
sysIotModelFieldMapper.insert(sysIotModelField);
SysIotModelFieldVo sysIotModelFieldVo = new SysIotModelFieldVo();
BeanCopyUtils.copy(sysIotModelField,sysIotModelFieldVo);
BeanCopyUtils.copy(sysIotModelField, sysIotModelFieldVo);
return sysIotModelFieldVo;
}
@Override
public SysIotModelFieldVo updateSysIotModelField(SysIotModelFieldDto sysIotModelFieldDto) {
SysIotModelField sysIotModelField = new SysIotModelField();
BeanCopyUtils.copy(sysIotModelFieldDto,sysIotModelField);
BeanCopyUtils.copy(sysIotModelFieldDto, sysIotModelField);
SysUserVo sysUserVo = (SysUserVo) StpUtil.getTokenSession().get(SessionUtil.SESSION_USER_KEY);
sysIotModelField.setUpdatedTime(new Date());
sysIotModelField.setUpdatedBy(sysUserVo.getAccount());
// sysIotModelField.setUpdatedBy("sysUserVo.getAccount()");
sysIotModelFieldMapper.updateById(sysIotModelField);
SysIotModelFieldVo sysIotModelFieldVo = new SysIotModelFieldVo();
BeanCopyUtils.copy(sysIotModelField,sysIotModelFieldVo);
BeanCopyUtils.copy(sysIotModelField, sysIotModelFieldVo);
return sysIotModelFieldVo;
}
@ -186,12 +185,12 @@ public class SysIotModelServiceImpl implements SysIotModelService {
@Override
public SysIotModelServiceVo creatSysIotModelService(SysIotModelServiceDto sysIotModelServiceDto) {
SysIotModelServices sysIotModelServices = new SysIotModelServices();
BeanCopyUtils.copy(sysIotModelServiceDto,sysIotModelServices);
BeanCopyUtils.copy(sysIotModelServiceDto, sysIotModelServices);
QueryWrapper<SysIotModelServices> sysIotModelServiceQueryWrapper = new QueryWrapper<>();
sysIotModelServiceQueryWrapper.eq("service_code", sysIotModelServiceDto.getServiceCode());
SysIotModelServices sysIotModelServiceQuery = sysIotModelServiceMapper.selectOne(sysIotModelServiceQueryWrapper);
if (!(sysIotModelServiceQuery == null)){
if (!(sysIotModelServiceQuery == null)) {
throw new ServiceException("物模型动作code已经存在");
}
SysUserVo sysUserVo = (SysUserVo) StpUtil.getTokenSession().get(SessionUtil.SESSION_USER_KEY);
@ -203,21 +202,21 @@ public class SysIotModelServiceImpl implements SysIotModelService {
sysIotModelServices.setRevision(1);
sysIotModelServiceMapper.insert(sysIotModelServices);
SysIotModelServiceVo sysIotModelServiceVo = new SysIotModelServiceVo();
BeanCopyUtils.copy(sysIotModelServices,sysIotModelServiceVo);
BeanCopyUtils.copy(sysIotModelServices, sysIotModelServiceVo);
return sysIotModelServiceVo;
}
@Override
public SysIotModelServiceVo updateSysIotModelService(SysIotModelServiceDto sysIotModelServiceDto) {
SysIotModelServices sysIotModelServices = new SysIotModelServices();
BeanCopyUtils.copy(sysIotModelServiceDto,sysIotModelServices);
BeanCopyUtils.copy(sysIotModelServiceDto, sysIotModelServices);
SysUserVo sysUserVo = (SysUserVo) StpUtil.getTokenSession().get(SessionUtil.SESSION_USER_KEY);
sysIotModelServices.setUpdatedTime(new Date());
sysIotModelServices.setUpdatedBy(sysUserVo.getAccount());
// sysIotModelServices.setUpdatedBy("sysUserVo.getAccount()");
sysIotModelServiceMapper.updateById(sysIotModelServices);
SysIotModelServiceVo sysIotModelServiceVo = new SysIotModelServiceVo();
BeanCopyUtils.copy(sysIotModelServices,sysIotModelServiceVo);
BeanCopyUtils.copy(sysIotModelServices, sysIotModelServiceVo);
return sysIotModelServiceVo;
}
@ -228,83 +227,102 @@ public class SysIotModelServiceImpl implements SysIotModelService {
@Override
public void exportSysIotModel(SysIotModelDto sysIotModelDto, HttpServletRequest request, HttpServletResponse response) {
// 查询物模型属性和动作
List<SheetInfoBean> exportList = new ArrayList<>();
List<SysIotModelFieldExcel> sysIotModelFieldVoList = sysIotModelMapper.queryFieldByModelId(sysIotModelDto.getId());
LinkedHashMap<String, String> map = new LinkedHashMap<>();
SheetInfoBean sheetDTO = new SheetInfoBean();
map.put("iotModelName", "所属物模型名称");
map.put("attributeCode", "物模型属性编码");
map.put("attributeName", "物模型属性名称");
map.put("attributeType", "属性类型");
map.put("porder", "测点序号");
sheetDTO.setSheetName("物模型属性");
sheetDTO.setFieldAndAlias(map);
sheetDTO.setCollection(sysIotModelFieldVoList);
exportList.add(sheetDTO);
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);
LinkedHashMap<String, String> map1= new LinkedHashMap<>();
SheetInfoBean sheetDTO1 = new SheetInfoBean();
map1.put("iotModelName", "所属物模型名称");
map1.put("serviceCode", "物模型动作编码");
map1.put("serviceName", "物模型动作名称");
map1.put("serviceType", "动作类型");
map1.put("porder", "测点序号");
sheetDTO1.setSheetName("物模型动作");
sheetDTO1.setFieldAndAlias(map1);
sheetDTO1.setCollection(sysIotModelServiceVoList);
exportList.add(sheetDTO1);
HuExcelUtils.exportExcel(response, exportList, "物模型信息导出");
}
@Override
public void importSysIotModel(String iotModelId, MultipartFile file) throws IOException {
//输入流
public void importSysIotModel(String iotModelId, MultipartFile file){
try {
InputStream inputStream = file.getInputStream();
//监视器
ExcelListener listener = new ExcelListener();
ExcelReader excelReader = EasyExcel.read(inputStream, listener).build();
// 第一个sheet读取物模型属性
ReadSheet readSheet1 = EasyExcel.readSheet(0).head(SysIotModelFieldExcel.class).build();
// 第二个sheet读取物模型动作
ReadSheet readSheet2 = EasyExcel.readSheet(1).head(SysIotModelServiceExcel.class).build();
// 开始读取第一个sheet
excelReader.read(readSheet1);
//excel sheet0 信息
List<Object> fieldList = listener.getDatas();
//List<object> List<实体类>
List<SysIotModelField> sysIotModelFieldList = new ArrayList<>();
//List object for 转换 实体类
for (Object objects : fieldList) {
SysIotModelFieldExcel dto = (SysIotModelFieldExcel) objects;
SysIotModelField field = new SysIotModelField();
BeanUtil.copyProperties(dto,field);
field.setIotModelId(Long.valueOf(iotModelId));
field.setId(SequenceUtils.generateId());
field.setCreatedTime(new Date());
field.setUpdatedTime(new Date());
field.setRevision(1);
// field.setCreatedBy(StpUtil.getLoginIdAsString());
// field.setUpdatedBy(StpUtil.getLoginIdAsString());
field.setCreatedBy("测试人员");
field.setUpdatedBy("测试人员");
sysIotModelFieldList.add(field);
ExcelReader readerAll = ExcelUtil.getReader(inputStream);
int sheetCount = readerAll.getSheetCount();
List<String> sheetNameList = readerAll.getSheetNames();
for (int i = 0; i < sheetCount; i++) {
// 获取图层名称
String sheetName = sheetNameList.get(i);
ExcelReader sheetReader = ExcelUtil.getReader(file.getInputStream(), i);
List<List<Object>> list = sheetReader.read(1); // 从第二行开始读
if ("物模型属性".equals(sheetName)) {
saveIotModelFieldInfo(iotModelId, list);
}else {
saveIotModelServiceInfo(iotModelId, list);
}
}
} catch (Exception e) {
log.error("导入物模型异常:" + e.getMessage());
}
//保存第一个sheet页中的数据
sysIotModelFieldMapper.insertBatch(sysIotModelFieldList);
// 清空之前的数据
listener.getDatas().clear();
// 开始读取第二个sheet
excelReader.read(readSheet2);
//excel sheet1 信息
List<Object> serviceList = listener.getDatas();
//List<object> List<实体类>
}
private void saveIotModelServiceInfo(String iotModelId, List<List<Object>> list) {
List<SysIotModelServices> sysIotModelServiceList = new ArrayList<>();
//List object for 转换 实体类
for (Object objects : serviceList) {
SysIotModelServiceExcel dto = (SysIotModelServiceExcel) objects;
for (List<Object> row : list) {
// 遍历sheet页中记录构造需要导入的对象
SysIotModelServices services = new SysIotModelServices();
BeanUtil.copyProperties(dto,services);
services.setServiceCode(row.get(1).toString());
services.setServiceName(row.get(2).toString());
services.setServiceType(Integer.valueOf(row.get(3).toString()));
services.setPorder(Integer.valueOf(row.get(4).toString()));
services.setIotModelId(Long.valueOf(iotModelId));
services.setId(SequenceUtils.generateId());
services.setCreatedTime(new Date());
services.setUpdatedTime(new Date());
services.setRevision(1);
// services.setCreatedBy(StpUtil.getLoginIdAsString());
// services.setUpdatedBy(StpUtil.getLoginIdAsString());
services.setCreatedBy("测试人员");
services.setUpdatedBy("测试人员");
services.setCreatedBy(StpUtil.getLoginIdAsString());
services.setUpdatedBy(StpUtil.getLoginIdAsString());
sysIotModelServiceList.add(services);
}
//保存第一个sheet页中的数据
sysIotModelServiceMapper.insertBatch(sysIotModelServiceList);
}
private void saveIotModelFieldInfo(String iotModelId, List<List<Object>> list) {
List<SysIotModelField> sysIotModelFieldList = new ArrayList<>();
for (List<Object> row : list) {
// 遍历sheet页中记录构造需要导入的对象
SysIotModelField field = new SysIotModelField();
field.setAttributeCode(row.get(1).toString());
field.setAttributeName(row.get(2).toString());
field.setAttributeType(Integer.valueOf(row.get(3).toString()));
field.setPorder(Integer.valueOf(row.get(4).toString()));
field.setIotModelId(Long.valueOf(iotModelId));
field.setId(SequenceUtils.generateId());
field.setCreatedTime(new Date());
field.setUpdatedTime(new Date());
field.setRevision(1);
field.setCreatedBy(StpUtil.getLoginIdAsString());
field.setUpdatedBy(StpUtil.getLoginIdAsString());
sysIotModelFieldList.add(field);
}
sysIotModelFieldMapper.insertBatch(sysIotModelFieldList);
}
@Override

View File

@ -57,8 +57,6 @@ public class SysNodeServiceImpl implements SysNodeService {
sysNode.setUpdatedTime(new Date());
sysNode.setCreatedBy(sysUserVo.getAccount());
sysNode.setUpdatedBy(sysUserVo.getAccount());
// sysNode.setCreatedBy("测试");
// sysNode.setUpdatedBy("测试");
sysNode.setRevision(1);
sysNodeMapper.insert(sysNode);
SysNodeVo sysNodeVo = new SysNodeVo();
@ -115,8 +113,6 @@ public class SysNodeServiceImpl implements SysNodeService {
sysCommunicationLink.setUpdatedTime(new Date());
sysCommunicationLink.setCreatedBy(sysUserVo.getAccount());
sysCommunicationLink.setUpdatedBy(sysUserVo.getAccount());
// sysCommunicationLink.setCreatedBy("测试");
// sysCommunicationLink.setUpdatedBy("测试");
sysCommunicationLink.setRevision(1);
sysCommunicationLinkMapper.insert(sysCommunicationLink);
SysCommunicationLinkVo sysCommunicationLinkVo = new SysCommunicationLinkVo();

View File

@ -22,6 +22,7 @@
and sc.link_name like concat('%',#{info.linkName},'%')
</if>
</where>
order by sc.link_name
</select>
<select id="querySysCommunicationLinkCount" resultType="java.lang.Long">

View File

@ -76,11 +76,12 @@
and t.object_type = #{info.objectType}
</if>
</where>
order by t.name
</select>
<select id="queryEquipmentTree" resultMap="SysEquipmentListMap">
select t.* from sys_equipment t where t.parent_equipment_id is null or t.parent_equipment_id = 0 order by t.code
select t.* from sys_equipment t where t.parent_equipment_id is null or t.parent_equipment_id = 0 order by t.name
</select>
<select id="queryChildrenEquipById" resultMap="SysEquipmentListMap">
@ -97,6 +98,9 @@
<if test="info.id != null and info.id != ''">
and t.parent_equipment_id = #{info.id}
</if>
<if test="info.objectType != null and info.objectType != ''">
and t.object_type = #{info.objectType}
</if>
<if test="info.orgId != null and info.orgId != ''">
and t.org_id = #{info.orgId}
</if>

View File

@ -12,7 +12,7 @@
</resultMap>
<select id="querySysNodeList" resultMap="SysNodeMap">
select sn.*,so."name" as orgName from sys_node sn left join sys_org so on sn.org_id = so.id
select sn.*,so."name" as orgName from sys_node sn left join sys_org so on sn.org_id = so.id order by sn.node_name
</select>