|
|
@@ -6,9 +6,11 @@ import (
|
|
|
"fwh-toolbox-server/domain"
|
|
|
"fwh-toolbox-server/dto"
|
|
|
"fwh-toolbox-server/utils/echart"
|
|
|
+ "fwh-toolbox-server/utils/mimetype"
|
|
|
"fwh-toolbox-server/utils/minio"
|
|
|
"os"
|
|
|
"path/filepath"
|
|
|
+ "regexp"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"time"
|
|
|
@@ -71,6 +73,32 @@ func excelSetCellValue(f *excelize.File, sheetName string, col int, row int, val
|
|
|
return f.SetCellValue(sheetName, fmt.Sprintf("%s%d", colName, row), val)
|
|
|
}
|
|
|
|
|
|
+// 判断功率流图文件是否存在
|
|
|
+func ExistsBatchDownloadPowerFlow(sn string, dateStr string) (bool, error) {
|
|
|
+ fileName := fmt.Sprintf("PowerFlow_%s.html", strings.ReplaceAll(dateStr, "-", ""))
|
|
|
+ objectName := fmt.Sprintf("%s/%s/%s/%s", mainPathName, sn, subPowerFlowPathName, fileName)
|
|
|
+ exists, err := minio.ExistsObject(objectName)
|
|
|
+ if err != nil {
|
|
|
+ zap.L().Error("检查PowerFlow文件失败", zap.String("fileName", fileName), zap.String("objectName", objectName), zap.String("err", err.Error()))
|
|
|
+ return false, err
|
|
|
+ }
|
|
|
+
|
|
|
+ return exists, nil
|
|
|
+}
|
|
|
+
|
|
|
+// 获取功率流图文件状态信息
|
|
|
+func StatBatchDownloadPowerFlow(sn string, dateStr string) (*minio.ObjectInfo, error) {
|
|
|
+ fileName := fmt.Sprintf("PowerFlow_%s.html", strings.ReplaceAll(dateStr, "-", ""))
|
|
|
+ objectName := fmt.Sprintf("%s/%s/%s/%s", mainPathName, sn, subPowerFlowPathName, fileName)
|
|
|
+ status, err := minio.StatObject(objectName)
|
|
|
+ if err != nil {
|
|
|
+ zap.L().Error("获取PowerFlow文件状态失败", zap.String("fileName", fileName), zap.String("objectName", objectName), zap.String("err", err.Error()))
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ return &status, nil
|
|
|
+}
|
|
|
+
|
|
|
// 保存功率流图到文件服务器
|
|
|
// return objName
|
|
|
func SaveBatchDownloadPowerFlow(sn string, dateStr string, powerFlowData dto.SitePowerFlow) (string, error) {
|
|
|
@@ -244,6 +272,32 @@ func SaveBatchDownloadPowerFlow(sn string, dateStr string, powerFlowData dto.Sit
|
|
|
return objectName, nil
|
|
|
}
|
|
|
|
|
|
+// 判断MqttLog excel文件是否存在
|
|
|
+func ExistsBatchDownloadMqttLog(sn string, cmdType string, dateStr string) (bool, error) {
|
|
|
+ fileName := fmt.Sprintf("MqttLog_%s_%s.xlsx", cmdType, strings.ReplaceAll(dateStr, "-", ""))
|
|
|
+ objectName := fmt.Sprintf("%s/%s/%s/%s", mainPathName, sn, subMqttPathName, fileName)
|
|
|
+ exists, err := minio.ExistsObject(objectName)
|
|
|
+ if err != nil {
|
|
|
+ zap.L().Error("检查MqttLog excel文件失败", zap.String("fileName", fileName), zap.String("objectName", objectName), zap.String("err", err.Error()))
|
|
|
+ return false, err
|
|
|
+ }
|
|
|
+
|
|
|
+ return exists, nil
|
|
|
+}
|
|
|
+
|
|
|
+// 获取MqttLog excel文件状态信息
|
|
|
+func StatBatchDownloadMqttLog(sn string, cmdType string, dateStr string) (*minio.ObjectInfo, error) {
|
|
|
+ fileName := fmt.Sprintf("MqttLog_%s_%s.xlsx", cmdType, strings.ReplaceAll(dateStr, "-", ""))
|
|
|
+ objectName := fmt.Sprintf("%s/%s/%s/%s", mainPathName, sn, subMqttPathName, fileName)
|
|
|
+ status, err := minio.StatObject(objectName)
|
|
|
+ if err != nil {
|
|
|
+ zap.L().Error("获取MqttLog excel文件状态失败", zap.String("fileName", fileName), zap.String("objectName", objectName), zap.String("err", err.Error()))
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ return &status, nil
|
|
|
+}
|
|
|
+
|
|
|
// 保存MqttLog excel到文件服务器
|
|
|
// return objName
|
|
|
func SaveBatchDownloadMqttLog(sn string, cmdType string, dateStr string, data []domain.MqttLogItem) (objectName string, err error) {
|
|
|
@@ -297,6 +351,32 @@ func SaveBatchDownloadMqttLog(sn string, cmdType string, dateStr string, data []
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+// 判断EventAlarm excel文件是否存在
|
|
|
+func ExistsBatchDownloadEventAlarm(sn string, dateStr string) (bool, error) {
|
|
|
+ fileName := fmt.Sprintf("EventAlarm_%s.xlsx", strings.ReplaceAll(dateStr, "-", ""))
|
|
|
+ objectName := fmt.Sprintf("%s/%s/%s/%s", mainPathName, sn, subEventAlarmPathName, fileName)
|
|
|
+ exists, err := minio.ExistsObject(objectName)
|
|
|
+ if err != nil {
|
|
|
+ zap.L().Error("检查EventAlarm excel文件失败", zap.String("fileName", fileName), zap.String("objectName", objectName), zap.String("err", err.Error()))
|
|
|
+ return false, err
|
|
|
+ }
|
|
|
+
|
|
|
+ return exists, nil
|
|
|
+}
|
|
|
+
|
|
|
+// 获取EventAlarm excel文件状态信息
|
|
|
+func StatBatchDownloadEventAlarm(sn string, dateStr string) (*minio.ObjectInfo, error) {
|
|
|
+ fileName := fmt.Sprintf("EventAlarm_%s.xlsx", strings.ReplaceAll(dateStr, "-", ""))
|
|
|
+ objectName := fmt.Sprintf("%s/%s/%s/%s", mainPathName, sn, subEventAlarmPathName, fileName)
|
|
|
+ status, err := minio.StatObject(objectName)
|
|
|
+ if err != nil {
|
|
|
+ zap.L().Error("获取EventAlarm excel文件状态失败", zap.String("fileName", fileName), zap.String("objectName", objectName), zap.String("err", err.Error()))
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ return &status, nil
|
|
|
+}
|
|
|
+
|
|
|
// 保存EventAlarm excel到文件服务器
|
|
|
// return objName
|
|
|
func SaveBatchDownloadEventAlarm(sn string, dateStr string, eventAlarmData []domain.EventAlarmItem) (objectName string, err error) {
|
|
|
@@ -365,6 +445,32 @@ func SaveBatchDownloadEventAlarm(sn string, dateStr string, eventAlarmData []dom
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+// 判断AlarmSnapshot文件是否存在
|
|
|
+func ExistsBatchDownloadAlarmSnapshot(sn string, dateStr string) (bool, error) {
|
|
|
+ fileName := fmt.Sprintf("EventAlarm_%s.xlsx", strings.ReplaceAll(dateStr, "-", ""))
|
|
|
+ objectName := fmt.Sprintf("%s/%s/%s/%s", mainPathName, sn, subAlarmSnapshotPathName, fileName)
|
|
|
+ exists, err := minio.ExistsObject(objectName)
|
|
|
+ if err != nil {
|
|
|
+ zap.L().Error("检查AlarmSnapshot文件失败", zap.String("fileName", fileName), zap.String("objectName", objectName), zap.String("err", err.Error()))
|
|
|
+ return false, err
|
|
|
+ }
|
|
|
+
|
|
|
+ return exists, nil
|
|
|
+}
|
|
|
+
|
|
|
+// 获取AlarmSnapshot文件状态信息
|
|
|
+func StatBatchDownloadAlarmSnapshot(sn string, dateStr string) (*minio.ObjectInfo, error) {
|
|
|
+ fileName := fmt.Sprintf("EventAlarm_%s.xlsx", strings.ReplaceAll(dateStr, "-", ""))
|
|
|
+ objectName := fmt.Sprintf("%s/%s/%s/%s", mainPathName, sn, subAlarmSnapshotPathName, fileName)
|
|
|
+ status, err := minio.StatObject(objectName)
|
|
|
+ if err != nil {
|
|
|
+ zap.L().Error("获取AlarmSnapshot文件状态失败", zap.String("fileName", fileName), zap.String("objectName", objectName), zap.String("err", err.Error()))
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ return &status, nil
|
|
|
+}
|
|
|
+
|
|
|
// 保存AlarmSnapshot文件到文件服务器
|
|
|
// return objName
|
|
|
func SaveBatchDownloadAlarmSnapshot(sn string, dateStr string, alarmSnapshotData []*domain.SiteAlarmSnapshotData) (objectName string, err error) {
|
|
|
@@ -425,26 +531,123 @@ func SaveBatchDownloadAlarmSnapshot(sn string, dateStr string, alarmSnapshotData
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+// 判断EmsLog文件是否存在
|
|
|
+func ExistsBatchDownloadEmsLog(sn string, originalFileName string, fileSupType string, dateStr string, callTime time.Time) (bool, error) {
|
|
|
+ // 使用正则匹配多级后缀,例如 .tar.bz2, .tar.gz, .min.js 等
|
|
|
+ re := regexp.MustCompile(`(\.[a-zA-Z0-9]+)+$`)
|
|
|
+ matchSuffix := re.FindString(originalFileName)
|
|
|
+
|
|
|
+ fileName := fmt.Sprintf("EmsLog_%s_%s_%s_%s%s", sn, fileSupType, strings.ReplaceAll(dateStr, "-", "_"), strconv.FormatInt(callTime.Unix(), 10), matchSuffix)
|
|
|
+ objectName := fmt.Sprintf("%s/%s/%s/%s", mainPathName, sn, subEmsLogsPathName, fileName)
|
|
|
+ exists, err := minio.ExistsObject(objectName)
|
|
|
+ if err != nil {
|
|
|
+ zap.L().Error("检查EmsLog文件失败", zap.String("fileName", fileName), zap.String("objectName", objectName), zap.String("err", err.Error()))
|
|
|
+ return false, err
|
|
|
+ }
|
|
|
+
|
|
|
+ return exists, nil
|
|
|
+}
|
|
|
+
|
|
|
+// 获取EmsLog文件状态信息
|
|
|
+func StatBatchDownloadEmsLog(sn string, originalFileName string, fileSupType string, dateStr string, callTime time.Time) (*minio.ObjectInfo, error) {
|
|
|
+ // 使用正则匹配多级后缀,例如 .tar.bz2, .tar.gz, .min.js 等
|
|
|
+ re := regexp.MustCompile(`(\.[a-zA-Z0-9]+)+$`)
|
|
|
+ matchSuffix := re.FindString(originalFileName)
|
|
|
+
|
|
|
+ fileName := fmt.Sprintf("EmsLog_%s_%s_%s_%s%s", sn, fileSupType, strings.ReplaceAll(dateStr, "-", "_"), strconv.FormatInt(callTime.Unix(), 10), matchSuffix)
|
|
|
+ objectName := fmt.Sprintf("%s/%s/%s/%s", mainPathName, sn, subEmsLogsPathName, fileName)
|
|
|
+ status, err := minio.StatObject(objectName)
|
|
|
+ if err != nil {
|
|
|
+ zap.L().Error("获取EmsLog文件状态失败", zap.String("fileName", fileName), zap.String("objectName", objectName), zap.String("err", err.Error()))
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ return &status, nil
|
|
|
+}
|
|
|
+
|
|
|
// 保存EmsLog文件到文件服务器
|
|
|
// return objName
|
|
|
-func SaveBatchDownloadEmsLog(sn string, dataBytes []byte, emsLogFileName string, contentType string) (string, error) {
|
|
|
+func SaveBatchDownloadEmsLog(sn string, dataBytes []byte, originalFileName string, fileSupType string, dateStr string, callTime time.Time) (string, error) {
|
|
|
// 将 []byte 封装成 io.Reader
|
|
|
dataReader := bytes.NewReader(dataBytes)
|
|
|
+
|
|
|
+ // 使用正则匹配多级后缀,例如 .tar.bz2, .tar.gz, .min.js 等
|
|
|
+ re := regexp.MustCompile(`(\.[a-zA-Z0-9]+)+$`)
|
|
|
+ matchSuffix := re.FindString(originalFileName)
|
|
|
+
|
|
|
+ // 计算Content Type
|
|
|
+ contentType := mimetype.GetContentType(originalFileName)
|
|
|
+
|
|
|
// 保存到minio
|
|
|
- objectName := fmt.Sprintf("%s/%s/%s/%s", mainPathName, sn, subEmsLogsPathName, emsLogFileName)
|
|
|
+ fileName := fmt.Sprintf("EmsLog_%s_%s_%s_%s%s", sn, fileSupType, strings.ReplaceAll(dateStr, "-", "_"), strconv.FormatInt(callTime.Unix(), 10), matchSuffix)
|
|
|
+ objectName := fmt.Sprintf("%s/%s/%s/%s", mainPathName, sn, subEmsLogsPathName, fileName)
|
|
|
return objectName, minio.UploadFromReader(dataReader, int64(len(dataBytes)), objectName, contentType)
|
|
|
}
|
|
|
|
|
|
+// 判断FaultRecord文件是否存在
|
|
|
+func ExistsBatchDownloadFaultRecord(sn string, faultRecordFileName string) (bool, error) {
|
|
|
+ objectName := fmt.Sprintf("%s/%s/%s/%s", mainPathName, sn, subFaultRecordPathName, faultRecordFileName)
|
|
|
+ exists, err := minio.ExistsObject(objectName)
|
|
|
+ if err != nil {
|
|
|
+ zap.L().Error("检查FaultRecord文件失败", zap.String("fileName", faultRecordFileName), zap.String("objectName", objectName), zap.String("err", err.Error()))
|
|
|
+ return false, err
|
|
|
+ }
|
|
|
+
|
|
|
+ return exists, nil
|
|
|
+}
|
|
|
+
|
|
|
+// 获取FaultRecord文件状态信息
|
|
|
+func StatBatchDownloadFaultRecord(sn string, faultRecordFileName string) (*minio.ObjectInfo, error) {
|
|
|
+ objectName := fmt.Sprintf("%s/%s/%s/%s", mainPathName, sn, subFaultRecordPathName, faultRecordFileName)
|
|
|
+ status, err := minio.StatObject(objectName)
|
|
|
+ if err != nil {
|
|
|
+ zap.L().Error("获取FaultRecord文件状态失败", zap.String("fileName", faultRecordFileName), zap.String("objectName", objectName), zap.String("err", err.Error()))
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ return &status, nil
|
|
|
+}
|
|
|
+
|
|
|
// 保存FaultRecord文件到文件服务器
|
|
|
// return objName
|
|
|
-func SaveBatchDownloadFaultRecord(sn string, dataBytes []byte, faultRecordFileName string, contentType string) (string, error) {
|
|
|
+func SaveBatchDownloadFaultRecord(sn string, dataBytes []byte, faultRecordFileName string) (string, error) {
|
|
|
// 将 []byte 封装成 io.Reader
|
|
|
dataReader := bytes.NewReader(dataBytes)
|
|
|
+
|
|
|
+ // 计算Content Type
|
|
|
+ contentType := mimetype.GetContentType(faultRecordFileName)
|
|
|
+
|
|
|
// 保存到minio
|
|
|
objectName := fmt.Sprintf("%s/%s/%s/%s", mainPathName, sn, subFaultRecordPathName, faultRecordFileName)
|
|
|
return objectName, minio.UploadFromReader(dataReader, int64(len(dataBytes)), objectName, contentType)
|
|
|
}
|
|
|
|
|
|
+// 判断UpdateLog excel文件是否存在
|
|
|
+func ExistsBatchDownloadUpdateLog(sn string, date time.Time) (bool, error) {
|
|
|
+ fileName := fmt.Sprintf("UpdateLog_%s_%s.xlsx", sn, strings.ReplaceAll(date.Format(time.DateTime), " ", "_"))
|
|
|
+ objectName := fmt.Sprintf("%s/%s/%s/%s", mainPathName, sn, subUpdateLogPathName, fileName)
|
|
|
+ exists, err := minio.ExistsObject(objectName)
|
|
|
+ if err != nil {
|
|
|
+ zap.L().Error("检查UpdateLog excel文件失败", zap.String("fileName", fileName), zap.String("objectName", objectName), zap.String("err", err.Error()))
|
|
|
+ return false, err
|
|
|
+ }
|
|
|
+
|
|
|
+ return exists, nil
|
|
|
+}
|
|
|
+
|
|
|
+// 获取UpdateLog excel文件状态信息
|
|
|
+func StatBatchDownloadUpdateLog(sn string, date time.Time) (*minio.ObjectInfo, error) {
|
|
|
+ fileName := fmt.Sprintf("UpdateLog_%s_%s.xlsx", sn, strings.ReplaceAll(date.Format(time.DateTime), " ", "_"))
|
|
|
+ objectName := fmt.Sprintf("%s/%s/%s/%s", mainPathName, sn, subUpdateLogPathName, fileName)
|
|
|
+ status, err := minio.StatObject(objectName)
|
|
|
+ if err != nil {
|
|
|
+ zap.L().Error("获取UpdateLog excel文件状态失败", zap.String("fileName", fileName), zap.String("objectName", objectName), zap.String("err", err.Error()))
|
|
|
+ return nil, err
|
|
|
+ }
|
|
|
+
|
|
|
+ return &status, nil
|
|
|
+}
|
|
|
+
|
|
|
// 保存UpdateLog excel到文件服务器
|
|
|
// return objName
|
|
|
func SaveBatchDownloadUpdateLog(sn string, systemUpdateLogData []domain.BatchDownloadSystemUpdateLogInfo, aHubUpdateLogData []domain.BatchDownloadAHubUpdateLogInfo) (objectName string, err error) {
|