Merge branch 'main' of https://git.jsspisoft.com/ry-das
This commit is contained in:
commit
7fc9bd7079
@ -73,5 +73,7 @@ public class SysIotModelFieldDto implements Serializable {
|
||||
*/
|
||||
private String unit;
|
||||
|
||||
private Integer level;
|
||||
|
||||
|
||||
}
|
||||
|
@ -65,5 +65,6 @@ public class SysIotModelFieldExcel {
|
||||
*/
|
||||
private String unit;
|
||||
|
||||
private Integer level;
|
||||
|
||||
}
|
||||
|
@ -66,4 +66,6 @@ public class SysIotModelFieldVo {
|
||||
*/
|
||||
private String unit;
|
||||
|
||||
private Integer level;
|
||||
|
||||
}
|
||||
|
@ -99,4 +99,10 @@ public class SysIotModelField extends BaseEntity {
|
||||
*/
|
||||
@TableField("unit")
|
||||
private String unit;
|
||||
|
||||
/**
|
||||
* 离散量级别。0 提示;1告警;2 故障
|
||||
*/
|
||||
@TableField("level")
|
||||
private Integer level;
|
||||
}
|
||||
|
@ -304,6 +304,7 @@ public class SysIotModelServiceImpl implements SysIotModelService {
|
||||
map.put("dataType", "*数据类型");
|
||||
map.put("visible", "是否可见(0:不可见,1:可见)");
|
||||
map.put("highSpeed", "*属性频度(0低频属性,1高频属性)");
|
||||
map.put("level","离散量级别:0提示;1告警;2故障");
|
||||
sheetDTO.setSheetName("物模型属性");
|
||||
sheetDTO.setFieldAndAlias(map);
|
||||
sheetDTO.setCollection(sysIotModelFieldVoList);
|
||||
@ -517,6 +518,7 @@ public class SysIotModelServiceImpl implements SysIotModelService {
|
||||
field.setDataType(row.get(9).toString());
|
||||
field.setVisible(ObjectUtil.isEmpty(row.get(10)) ? null : Integer.valueOf(row.get(10).toString()));
|
||||
field.setHighSpeed(Integer.valueOf(row.get(11).toString()));
|
||||
field.setLevel(ObjectUtil.isEmpty(row.get(12)) ? null : Integer.valueOf(row.get(12).toString()));
|
||||
field.setIotModelId(Long.valueOf(iotModelId));
|
||||
}
|
||||
|
||||
|
@ -1,16 +1,26 @@
|
||||
package com.das.modules.fdr.controller;
|
||||
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import com.alibaba.excel.read.builder.ExcelReaderBuilder;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.das.common.result.R;
|
||||
import com.das.modules.curve.domain.dto.TheoreticalPowerCurveDto;
|
||||
import com.das.modules.curve.domain.entity.CurveItemEntity;
|
||||
import com.das.modules.curve.domain.excel.CurveItemExcel;
|
||||
import com.das.modules.equipment.entity.SysEquipment;
|
||||
import com.das.modules.fdr.domain.FileNode;
|
||||
import com.das.modules.fdr.domain.SysFaultRecordingDesc;
|
||||
import com.das.modules.fdr.domain.dto.FileDownloadDto;
|
||||
import com.das.modules.fdr.domain.excel.SysFaultRecordingExcel;
|
||||
import com.das.modules.fdr.listener.SysFaultRecordingListener;
|
||||
import com.das.modules.fdr.service.FaultRecorderService;
|
||||
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.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
@ -27,6 +37,9 @@ public class FaultRecorderController {
|
||||
@Autowired
|
||||
private FaultRecorderService faultRecorderService;
|
||||
|
||||
@Autowired
|
||||
private SysFaultRecordingListener sysFaultRecordingListener;
|
||||
|
||||
@RequestMapping(value = "/files", method = RequestMethod.POST)
|
||||
public R<List<FileNode>> findList(@RequestBody JSONObject jsonObject) {
|
||||
String code = jsonObject.getString("deviceCode");
|
||||
@ -53,4 +66,35 @@ public class FaultRecorderController {
|
||||
|
||||
faultRecorderService.download(fileDownloadDto.getUrl(),httpServletResponse);
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述导出
|
||||
*/
|
||||
@PostMapping("/export")
|
||||
public void exportTheoreticalPowerCurve(@RequestBody SysFaultRecordingDesc sysFaultRecordingDesc, HttpServletRequest request, HttpServletResponse response) {
|
||||
faultRecorderService.exportFaultRecordingDesc(sysFaultRecordingDesc,request, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 故障录波描述导入
|
||||
*/
|
||||
@PostMapping("/import")
|
||||
public R<Void> importSysIotModel(String id, @RequestParam("file") MultipartFile file) throws IOException {
|
||||
sysFaultRecordingListener.setParent(Long.valueOf(id));
|
||||
ExcelReaderBuilder read = EasyExcel.read(file.getInputStream(), SysFaultRecordingExcel.class,sysFaultRecordingListener);
|
||||
read.sheet().doRead();
|
||||
return R.success("导入成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据制造商厂家型号查询故障信息描述
|
||||
* @return 信息中英文描述
|
||||
*/
|
||||
@PostMapping("/queryFdrDesc")
|
||||
public R<List<SysFaultRecordingDesc>> queryAllCurve(@RequestBody JSONObject jsonObject) {
|
||||
String madeinfactory = jsonObject.getString("madeinfactory");
|
||||
String model = jsonObject.getString("model");
|
||||
List<SysFaultRecordingDesc> sysFaultRecordingDescList = faultRecorderService.queryFaultRecordingDes(madeinfactory,model);
|
||||
return R.success(sysFaultRecordingDescList);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,49 @@
|
||||
package com.das.modules.fdr.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@TableName("sys_fault_recording_var_desc")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class SysFaultRecordingDesc {
|
||||
|
||||
@TableId(value = "id", type = IdType.ASSIGN_ID)
|
||||
private Long id;
|
||||
|
||||
@TableField("parent")
|
||||
private Long parent;
|
||||
|
||||
@TableField("variable")
|
||||
private String variable;
|
||||
|
||||
@TableField("description")
|
||||
private String description;
|
||||
|
||||
@TableField("revision")
|
||||
private Integer revision;
|
||||
|
||||
@TableField("created_by")
|
||||
private String createdBy;
|
||||
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@TableField("created_time")
|
||||
private Date createdTime;
|
||||
|
||||
@TableField("updated_by")
|
||||
private String updatedBy;
|
||||
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@TableField("updated_time")
|
||||
private Date updatedTime;
|
||||
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package com.das.modules.fdr.domain.excel;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class SysFaultRecordingExcel implements Serializable {
|
||||
|
||||
|
||||
/**
|
||||
* 主键id
|
||||
*/
|
||||
@ExcelProperty(value = "英文名称",index = 0)
|
||||
private String variable;
|
||||
/**
|
||||
* 物模型ID
|
||||
*/
|
||||
@ExcelProperty(value = "中文描述",index = 1)
|
||||
private String description;
|
||||
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
package com.das.modules.fdr.listener;
|
||||
|
||||
import com.alibaba.excel.context.AnalysisContext;
|
||||
import com.alibaba.excel.event.AnalysisEventListener;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.das.common.exceptions.ServiceException;
|
||||
import com.das.common.utils.BeanCopyUtils;
|
||||
import com.das.common.utils.CommonFunction;
|
||||
import com.das.modules.fdr.domain.SysFaultRecordingDesc;
|
||||
import com.das.modules.fdr.domain.excel.SysFaultRecordingExcel;
|
||||
import com.das.modules.fdr.service.impl.FaultRecorderServiceImpl;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
||||
/**
|
||||
* 物模型属性监听器
|
||||
*
|
||||
* @author huguanghan
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
@Data
|
||||
public class SysFaultRecordingListener extends AnalysisEventListener<SysFaultRecordingExcel> {
|
||||
@Autowired
|
||||
private FaultRecorderServiceImpl faultRecorderService;
|
||||
|
||||
public SysFaultRecordingListener(FaultRecorderServiceImpl faultRecorderService) {
|
||||
this.faultRecorderService = faultRecorderService;
|
||||
}
|
||||
|
||||
//parentId
|
||||
private Long parent;
|
||||
|
||||
/**计数标记*/
|
||||
private Integer flag=0;
|
||||
|
||||
/**存放插入*/
|
||||
ArrayList<SysFaultRecordingDesc> sysFaultRecordingDescArrayList = new ArrayList<>();
|
||||
|
||||
|
||||
@Override
|
||||
public void invoke(SysFaultRecordingExcel sysFaultRecordingExcel, AnalysisContext analysisContext) {
|
||||
// 如果一行Excel数据均为空值,则不装载该行数据
|
||||
if (CommonFunction.objCheckIsNull(sysFaultRecordingExcel)) {
|
||||
return;
|
||||
}
|
||||
log.info("解析到一条数据:{}", JSON.toJSONString(sysFaultRecordingExcel));
|
||||
SysFaultRecordingDesc sysFaultRecordingDesc = new SysFaultRecordingDesc();
|
||||
BeanCopyUtils.copy(sysFaultRecordingExcel, sysFaultRecordingDesc);
|
||||
sysFaultRecordingDesc.setParent(parent);
|
||||
//加入集合
|
||||
sysFaultRecordingDescArrayList.add(sysFaultRecordingDesc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doAfterAllAnalysed(AnalysisContext analysisContext) {
|
||||
//确保最后遗留的数据也存储到数据库
|
||||
if (!sysFaultRecordingDescArrayList.isEmpty()){
|
||||
saveData();
|
||||
}
|
||||
log.info("所有数据解析完成!");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 存储数据库
|
||||
* @return
|
||||
*/
|
||||
private void saveData() {
|
||||
log.info("{}条数据,开始存储数据库!", flag);
|
||||
try {
|
||||
faultRecorderService.batchProcessing(sysFaultRecordingDescArrayList,parent);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
throw new ServiceException(e.getMessage());
|
||||
}finally {
|
||||
clear();
|
||||
}
|
||||
log.info("存储数据库成功!");
|
||||
}
|
||||
|
||||
public void clear(){
|
||||
//清理缓存
|
||||
sysFaultRecordingDescArrayList.clear();
|
||||
flag=0;
|
||||
log.info("缓存已清理");
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,10 @@
|
||||
package com.das.modules.fdr.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.das.modules.fdr.domain.SysFaultRecordingDesc;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface SysFaultRecordingDescMapper extends BaseMapper<SysFaultRecordingDesc> {
|
||||
|
||||
}
|
@ -2,6 +2,8 @@ package com.das.modules.fdr.service;
|
||||
|
||||
import com.das.modules.equipment.entity.SysEquipment;
|
||||
import com.das.modules.fdr.domain.FileNode;
|
||||
import com.das.modules.fdr.domain.SysFaultRecordingDesc;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@ -23,4 +25,8 @@ public interface FaultRecorderService {
|
||||
String upload(String parent, String folderName, MultipartFile file);
|
||||
|
||||
void readFileToSteam(String path, OutputStream stream);
|
||||
|
||||
void exportFaultRecordingDesc(SysFaultRecordingDesc sysFaultRecordingDesc, HttpServletRequest request, HttpServletResponse response);
|
||||
|
||||
List<SysFaultRecordingDesc> queryFaultRecordingDes(String madeinfactory, String model);
|
||||
}
|
||||
|
@ -1,19 +1,30 @@
|
||||
package com.das.modules.fdr.service.impl;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.das.common.config.SessionUtil;
|
||||
import com.das.common.constant.FileConstants;
|
||||
import com.das.common.exceptions.ServiceException;
|
||||
import com.das.common.utils.HuExcelUtils;
|
||||
import com.das.modules.auth.domain.vo.SysUserVo;
|
||||
import com.das.modules.curve.domain.entity.CurveItemEntity;
|
||||
import com.das.modules.curve.domain.entity.TheoreticalPowerCurveEntity;
|
||||
import com.das.modules.curve.mapper.TheoreticalPowerCurveMapper;
|
||||
import com.das.modules.equipment.domain.excel.SheetInfoBean;
|
||||
import com.das.modules.equipment.entity.SysEquipment;
|
||||
import com.das.modules.equipment.mapper.SysEquipmentMapper;
|
||||
import com.das.modules.fdr.config.MinioProperties;
|
||||
import com.das.modules.fdr.domain.FileNode;
|
||||
import com.das.modules.fdr.domain.SysFaultRecordingDesc;
|
||||
import com.das.modules.fdr.domain.vo.FdrFormatVo;
|
||||
import com.das.modules.fdr.domain.vo.FileParseConfig;
|
||||
import com.das.modules.fdr.mapper.SysFaultRecordingDescMapper;
|
||||
import com.das.modules.fdr.service.FaultRecorderService;
|
||||
import com.das.modules.fdr.service.MinioViewsServcie;
|
||||
import io.micrometer.common.util.StringUtils;
|
||||
import io.minio.MinioClient;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -46,6 +57,12 @@ public class FaultRecorderServiceImpl implements FaultRecorderService {
|
||||
@Autowired
|
||||
private SysEquipmentMapper sysEquipmentMapper;
|
||||
|
||||
@Autowired
|
||||
private SysFaultRecordingDescMapper sysFaultRecordingDescMapper;
|
||||
|
||||
@Autowired
|
||||
private TheoreticalPowerCurveMapper theoreticalPowerCurveMapper;
|
||||
|
||||
|
||||
@Override
|
||||
public List<FileNode> getDirOrFileList(String fileType,String name, String startTime, String endTime) {
|
||||
@ -72,6 +89,37 @@ public class FaultRecorderServiceImpl implements FaultRecorderService {
|
||||
minioViewsServcie.readFileToStream(path, stream);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exportFaultRecordingDesc(SysFaultRecordingDesc sysFaultRecordingDesc, HttpServletRequest request, HttpServletResponse response) {
|
||||
List<SheetInfoBean> exportList = new ArrayList<>();
|
||||
QueryWrapper<SysFaultRecordingDesc> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("PARENT",sysFaultRecordingDesc.getId());
|
||||
queryWrapper.orderByAsc("variable");
|
||||
List<SysFaultRecordingDesc> sysFaultRecordingDescList = sysFaultRecordingDescMapper.selectList(queryWrapper);
|
||||
TheoreticalPowerCurveEntity theoreticalPowerCurve = theoreticalPowerCurveMapper.selectById(sysFaultRecordingDesc.getId());
|
||||
LinkedHashMap<String, String> map = new LinkedHashMap<>();
|
||||
SheetInfoBean sheetDTO = new SheetInfoBean();
|
||||
map.put("variable", "英文名称");
|
||||
map.put("description", "中文描述");
|
||||
sheetDTO.setSheetName(theoreticalPowerCurve.getMadeinfactory());
|
||||
sheetDTO.setFieldAndAlias(map);
|
||||
sheetDTO.setCollection(sysFaultRecordingDescList);
|
||||
exportList.add(sheetDTO);
|
||||
HuExcelUtils.exportExcel(response, exportList, theoreticalPowerCurve.getMadeinfactory()+theoreticalPowerCurve.getModel()+"故障录波日志变量描述");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysFaultRecordingDesc> queryFaultRecordingDes(String madeinfactory, String model) {
|
||||
QueryWrapper<TheoreticalPowerCurveEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("madeinfactory",madeinfactory);
|
||||
queryWrapper.eq("MODEL",model);
|
||||
TheoreticalPowerCurveEntity theoreticalPowerCurveEntity = theoreticalPowerCurveMapper.selectOne(queryWrapper);
|
||||
QueryWrapper<SysFaultRecordingDesc> sysFaultRecordingDescQueryWrapper = new QueryWrapper<>();
|
||||
sysFaultRecordingDescQueryWrapper.eq("parent",theoreticalPowerCurveEntity.getId());
|
||||
sysFaultRecordingDescQueryWrapper.orderByAsc("variable");
|
||||
return sysFaultRecordingDescMapper.selectList(sysFaultRecordingDescQueryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void download(String path,HttpServletResponse httpServletResponse) throws IOException {
|
||||
Path tempDir = Files.createTempDirectory(null);
|
||||
@ -200,4 +248,22 @@ public class FaultRecorderServiceImpl implements FaultRecorderService {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
|
||||
return sdf.parse(time).getTime();
|
||||
}
|
||||
|
||||
public void batchProcessing(List<SysFaultRecordingDesc> insertSysIotModelFieldList, Long parent) {
|
||||
//先删除制造商数据
|
||||
QueryWrapper<SysFaultRecordingDesc> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("PARENT",parent);
|
||||
sysFaultRecordingDescMapper.delete(queryWrapper);
|
||||
|
||||
//新增新的制造商数据
|
||||
for (SysFaultRecordingDesc item : insertSysIotModelFieldList){
|
||||
SysUserVo sysUserVo = (SysUserVo) StpUtil.getTokenSession().get(SessionUtil.SESSION_USER_KEY);
|
||||
item.setCreatedTime(new Date());
|
||||
item.setUpdatedTime(new Date());
|
||||
item.setCreatedBy(sysUserVo.getAccount());
|
||||
item.setUpdatedBy(sysUserVo.getAccount());
|
||||
item.setRevision(1);
|
||||
sysFaultRecordingDescMapper.insert(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +1,25 @@
|
||||
package com.das.modules.plc.controller;
|
||||
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import com.alibaba.excel.read.builder.ExcelReaderBuilder;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.das.common.result.R;
|
||||
import com.das.modules.equipment.entity.SysEquipment;
|
||||
import com.das.modules.fdr.domain.FileNode;
|
||||
import com.das.modules.fdr.domain.SysFaultRecordingDesc;
|
||||
import com.das.modules.fdr.domain.dto.FileDownloadDto;
|
||||
import com.das.modules.fdr.domain.excel.SysFaultRecordingExcel;
|
||||
import com.das.modules.fdr.service.FaultRecorderService;
|
||||
import com.das.modules.plc.domain.Excel.SysRunLogExcel;
|
||||
import com.das.modules.plc.domain.SysRunLogDesc;
|
||||
import com.das.modules.plc.listener.SysRunLogListener;
|
||||
import com.das.modules.plc.service.PlcLogService;
|
||||
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.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
@ -30,6 +36,9 @@ public class PlcLogsController {
|
||||
@Autowired
|
||||
private PlcLogService plcLogService;
|
||||
|
||||
@Autowired
|
||||
private SysRunLogListener sysRunLogListener;
|
||||
|
||||
@RequestMapping(value = "/files", method = RequestMethod.POST)
|
||||
public R<List<FileNode>> findList(@RequestBody JSONObject jsonObject) {
|
||||
String code = jsonObject.getString("deviceCode");
|
||||
@ -56,4 +65,35 @@ public class PlcLogsController {
|
||||
|
||||
plcLogService.download(fileDownloadDto.getUrl(),httpServletResponse);
|
||||
}
|
||||
|
||||
/**
|
||||
* 描述导出
|
||||
*/
|
||||
@PostMapping("/export")
|
||||
public void exportTheoreticalPowerCurve(@RequestBody SysRunLogDesc sysRunLogDesc, HttpServletRequest request, HttpServletResponse response) {
|
||||
plcLogService.exportRunLogDesc(sysRunLogDesc,request, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 故障录波描述导入
|
||||
*/
|
||||
@PostMapping("/import")
|
||||
public R<Void> importSysIotModel(String id, @RequestParam("file") MultipartFile file) throws IOException {
|
||||
sysRunLogListener.setParent(Long.valueOf(id));
|
||||
ExcelReaderBuilder read = EasyExcel.read(file.getInputStream(), SysRunLogExcel.class,sysRunLogListener);
|
||||
read.sheet().doRead();
|
||||
return R.success("导入成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据制造商厂家型号查询故障信息描述
|
||||
* @return 信息中英文描述
|
||||
*/
|
||||
@PostMapping("/queryPlcDesc")
|
||||
public R<List<SysRunLogDesc>> queryAllCurve(@RequestBody JSONObject jsonObject) {
|
||||
String madeinfactory = jsonObject.getString("madeinfactory");
|
||||
String model = jsonObject.getString("model");
|
||||
List<SysRunLogDesc> sysRunLogDescList = plcLogService.queryRunLogDesc(madeinfactory,model);
|
||||
return R.success(sysRunLogDescList);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,23 @@
|
||||
package com.das.modules.plc.domain.Excel;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
public class SysRunLogExcel implements Serializable {
|
||||
|
||||
|
||||
/**
|
||||
* 主键id
|
||||
*/
|
||||
@ExcelProperty(value = "英文名称",index = 0)
|
||||
private String variable;
|
||||
/**
|
||||
* 物模型ID
|
||||
*/
|
||||
@ExcelProperty(value = "中文描述",index = 1)
|
||||
private String description;
|
||||
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package com.das.modules.plc.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@TableName("sys_run_log_var_desc")
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class SysRunLogDesc {
|
||||
|
||||
@TableId(value = "id", type = IdType.ASSIGN_ID)
|
||||
private Long id;
|
||||
|
||||
@TableField("parent")
|
||||
private Long parent;
|
||||
|
||||
@TableField("variable")
|
||||
private String variable;
|
||||
|
||||
@TableField("description")
|
||||
private String description;
|
||||
|
||||
@TableField("revision")
|
||||
private Integer revision;
|
||||
|
||||
@TableField("created_by")
|
||||
private String createdBy;
|
||||
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@TableField("created_time")
|
||||
private Date createdTime;
|
||||
|
||||
@TableField("updated_by")
|
||||
private String updatedBy;
|
||||
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@TableField("updated_time")
|
||||
private Date updatedTime;
|
||||
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
package com.das.modules.plc.listener;
|
||||
|
||||
import com.alibaba.excel.context.AnalysisContext;
|
||||
import com.alibaba.excel.event.AnalysisEventListener;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.das.common.exceptions.ServiceException;
|
||||
import com.das.common.utils.BeanCopyUtils;
|
||||
import com.das.common.utils.CommonFunction;
|
||||
import com.das.modules.fdr.domain.SysFaultRecordingDesc;
|
||||
import com.das.modules.fdr.domain.excel.SysFaultRecordingExcel;
|
||||
import com.das.modules.fdr.service.impl.FaultRecorderServiceImpl;
|
||||
import com.das.modules.plc.domain.Excel.SysRunLogExcel;
|
||||
import com.das.modules.plc.domain.SysRunLogDesc;
|
||||
import com.das.modules.plc.service.impl.PlcLogsServiceImpl;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
|
||||
/**
|
||||
* 物模型属性监听器
|
||||
*
|
||||
* @author huguanghan
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
@Data
|
||||
public class SysRunLogListener extends AnalysisEventListener<SysRunLogExcel> {
|
||||
@Autowired
|
||||
private PlcLogsServiceImpl plcLogsService;
|
||||
|
||||
public SysRunLogListener(PlcLogsServiceImpl plcLogsService) {
|
||||
this.plcLogsService = plcLogsService;
|
||||
}
|
||||
|
||||
//parentId
|
||||
private Long parent;
|
||||
|
||||
/**计数标记*/
|
||||
private Integer flag=0;
|
||||
|
||||
/**存放插入*/
|
||||
ArrayList<SysRunLogDesc> sysRunLogDescArrayList = new ArrayList<>();
|
||||
|
||||
|
||||
@Override
|
||||
public void invoke(SysRunLogExcel sysRunLogExcel, AnalysisContext analysisContext) {
|
||||
// 如果一行Excel数据均为空值,则不装载该行数据
|
||||
if (CommonFunction.objCheckIsNull(sysRunLogExcel)) {
|
||||
return;
|
||||
}
|
||||
log.info("解析到一条数据:{}", JSON.toJSONString(sysRunLogExcel));
|
||||
SysRunLogDesc sysRunLogDesc = new SysRunLogDesc();
|
||||
BeanCopyUtils.copy(sysRunLogExcel, sysRunLogDesc);
|
||||
sysRunLogDesc.setParent(parent);
|
||||
//加入集合
|
||||
sysRunLogDescArrayList.add(sysRunLogDesc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doAfterAllAnalysed(AnalysisContext analysisContext) {
|
||||
//确保最后遗留的数据也存储到数据库
|
||||
if (!sysRunLogDescArrayList.isEmpty()){
|
||||
saveData();
|
||||
}
|
||||
log.info("所有数据解析完成!");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 存储数据库
|
||||
* @return
|
||||
*/
|
||||
private void saveData() {
|
||||
log.info("{}条数据,开始存储数据库!", flag);
|
||||
try {
|
||||
plcLogsService.batchProcessing(sysRunLogDescArrayList,parent);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
throw new ServiceException(e.getMessage());
|
||||
}finally {
|
||||
clear();
|
||||
}
|
||||
log.info("存储数据库成功!");
|
||||
}
|
||||
|
||||
public void clear(){
|
||||
//清理缓存
|
||||
sysRunLogDescArrayList.clear();
|
||||
flag=0;
|
||||
log.info("缓存已清理");
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,11 @@
|
||||
package com.das.modules.plc.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.das.modules.fdr.domain.SysFaultRecordingDesc;
|
||||
import com.das.modules.plc.domain.SysRunLogDesc;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface SysRunLogDescMapper extends BaseMapper<SysRunLogDesc> {
|
||||
|
||||
}
|
@ -2,6 +2,8 @@ package com.das.modules.plc.service;
|
||||
|
||||
import com.das.modules.equipment.entity.SysEquipment;
|
||||
import com.das.modules.fdr.domain.FileNode;
|
||||
import com.das.modules.plc.domain.SysRunLogDesc;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -17,4 +19,8 @@ public interface PlcLogService {
|
||||
void updatePlcConfig(SysEquipment sysEquipment);
|
||||
|
||||
void download(String path, HttpServletResponse httpServletResponse) throws IOException;
|
||||
|
||||
void exportRunLogDesc(SysRunLogDesc sysRunLogDesc, HttpServletRequest request, HttpServletResponse response);
|
||||
|
||||
List<SysRunLogDesc> queryRunLogDesc(String madeinfactory, String model);
|
||||
}
|
||||
|
@ -1,18 +1,29 @@
|
||||
package com.das.modules.plc.service.impl;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
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.HuExcelUtils;
|
||||
import com.das.modules.auth.domain.vo.SysUserVo;
|
||||
import com.das.modules.curve.domain.entity.TheoreticalPowerCurveEntity;
|
||||
import com.das.modules.curve.mapper.TheoreticalPowerCurveMapper;
|
||||
import com.das.modules.equipment.domain.excel.SheetInfoBean;
|
||||
import com.das.modules.equipment.entity.SysEquipment;
|
||||
import com.das.modules.equipment.mapper.SysEquipmentMapper;
|
||||
import com.das.modules.fdr.domain.FileNode;
|
||||
import com.das.modules.fdr.domain.SysFaultRecordingDesc;
|
||||
import com.das.modules.fdr.domain.vo.FdrFormatVo;
|
||||
import com.das.modules.fdr.domain.vo.FileParseConfig;
|
||||
import com.das.modules.fdr.service.FaultRecorderService;
|
||||
import com.das.modules.fdr.service.MinioViewsServcie;
|
||||
import com.das.modules.plc.domain.SysRunLogDesc;
|
||||
import com.das.modules.plc.mapper.SysRunLogDescMapper;
|
||||
import com.das.modules.plc.service.PlcLogService;
|
||||
import io.micrometer.common.util.StringUtils;
|
||||
import io.minio.MinioClient;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -39,6 +50,12 @@ public class PlcLogsServiceImpl implements PlcLogService {
|
||||
@Autowired
|
||||
private SysEquipmentMapper sysEquipmentMapper;
|
||||
|
||||
@Autowired
|
||||
private TheoreticalPowerCurveMapper theoreticalPowerCurveMapper;
|
||||
|
||||
@Autowired
|
||||
private SysRunLogDescMapper sysRunLogDescMapper;
|
||||
|
||||
|
||||
@Override
|
||||
public List<FileNode> getDirOrFileList(String fileType, String name, String startTime, String endTime) {
|
||||
@ -93,6 +110,37 @@ public class PlcLogsServiceImpl implements PlcLogService {
|
||||
faultRecorderService.download(path,httpServletResponse);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exportRunLogDesc(SysRunLogDesc sysRunLogDesc, HttpServletRequest request, HttpServletResponse response) {
|
||||
List<SheetInfoBean> exportList = new ArrayList<>();
|
||||
QueryWrapper<SysRunLogDesc> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("PARENT",sysRunLogDesc.getId());
|
||||
queryWrapper.orderByAsc("variable");
|
||||
List<SysRunLogDesc> sysFaultRecordingDescList = sysRunLogDescMapper.selectList(queryWrapper);
|
||||
TheoreticalPowerCurveEntity theoreticalPowerCurve = theoreticalPowerCurveMapper.selectById(sysRunLogDesc.getId());
|
||||
LinkedHashMap<String, String> map = new LinkedHashMap<>();
|
||||
SheetInfoBean sheetDTO = new SheetInfoBean();
|
||||
map.put("variable", "英文名称");
|
||||
map.put("description", "中文描述");
|
||||
sheetDTO.setSheetName(theoreticalPowerCurve.getMadeinfactory());
|
||||
sheetDTO.setFieldAndAlias(map);
|
||||
sheetDTO.setCollection(sysFaultRecordingDescList);
|
||||
exportList.add(sheetDTO);
|
||||
HuExcelUtils.exportExcel(response, exportList, theoreticalPowerCurve.getMadeinfactory()+theoreticalPowerCurve.getModel()+"运行日志变量描述");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysRunLogDesc> queryRunLogDesc(String madeinfactory, String model) {
|
||||
QueryWrapper<TheoreticalPowerCurveEntity> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("madeinfactory",madeinfactory);
|
||||
queryWrapper.eq("MODEL",model);
|
||||
TheoreticalPowerCurveEntity theoreticalPowerCurveEntity = theoreticalPowerCurveMapper.selectOne(queryWrapper);
|
||||
QueryWrapper<SysRunLogDesc> sysRunLogDescQueryWrapper = new QueryWrapper<>();
|
||||
sysRunLogDescQueryWrapper.eq("parent",theoreticalPowerCurveEntity.getId());
|
||||
sysRunLogDescQueryWrapper.orderByAsc("variable");
|
||||
return sysRunLogDescMapper.selectList(sysRunLogDescQueryWrapper);
|
||||
}
|
||||
|
||||
public Map<String, List<Object>> parseFile(InputStream inputStream, String timeFormat, String delimiter, int validStartLine) {
|
||||
List<List<String>> result = new ArrayList<>();
|
||||
Map<String, List<Object>> stringListMap = null;
|
||||
@ -160,4 +208,23 @@ public class PlcLogsServiceImpl implements PlcLogService {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(pattern);
|
||||
return sdf.parse(time).getTime();
|
||||
}
|
||||
|
||||
public void batchProcessing(List<SysRunLogDesc> sysRunLogDescArrayList, Long parent) {
|
||||
|
||||
//先删除制造商数据
|
||||
QueryWrapper<SysRunLogDesc> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("PARENT",parent);
|
||||
sysRunLogDescMapper.delete(queryWrapper);
|
||||
|
||||
//新增新的制造商数据
|
||||
for (SysRunLogDesc item : sysRunLogDescArrayList){
|
||||
SysUserVo sysUserVo = (SysUserVo) StpUtil.getTokenSession().get(SessionUtil.SESSION_USER_KEY);
|
||||
item.setCreatedTime(new Date());
|
||||
item.setUpdatedTime(new Date());
|
||||
item.setCreatedBy(sysUserVo.getAccount());
|
||||
item.setUpdatedBy(sysUserVo.getAccount());
|
||||
item.setRevision(1);
|
||||
sysRunLogDescMapper.insert(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user