Browse Source

Merge remote-tracking branch 'origin/debug' into debug

zwxi 11 months ago
parent
commit
4092057540

+ 4 - 16
controllers/data_manage/excel/excel_info.go

@@ -933,13 +933,15 @@ func (c *ExcelInfoController) Edit() {
 	excelInfo.ExcelType = req.ExcelType
 	excelInfo.ExcelType = req.ExcelType
 	excelInfo.ExcelClassifyId = req.ExcelClassifyId
 	excelInfo.ExcelClassifyId = req.ExcelClassifyId
 	excelInfo.ExcelImage = req.ExcelImage
 	excelInfo.ExcelImage = req.ExcelImage
+	excelInfo.UpdateUserId = sysUser.AdminId
+	excelInfo.UpdateUserRealName = sysUser.RealName
 	excelInfo.Content = content
 	excelInfo.Content = content
 	// 自动保存时不会传缩略图,也就不更新这个字段
 	// 自动保存时不会传缩略图,也就不更新这个字段
 	var updateExcelInfoParams []string
 	var updateExcelInfoParams []string
 	if req.ExcelImage != "" {
 	if req.ExcelImage != "" {
-		updateExcelInfoParams = []string{"ModifyTime", "ExcelName", "ExcelType", "ExcelClassifyId", "ExcelImage", "Content"}
+		updateExcelInfoParams = []string{"ModifyTime", "ExcelName", "ExcelType", "ExcelClassifyId", "ExcelImage", "Content", "UpdateUserId", "UpdateUserRealName"}
 	} else {
 	} else {
-		updateExcelInfoParams = []string{"ModifyTime", "ExcelName", "ExcelType", "ExcelClassifyId", "Content"}
+		updateExcelInfoParams = []string{"ModifyTime", "ExcelName", "ExcelType", "ExcelClassifyId", "Content", "UpdateUserId", "UpdateUserRealName"}
 	}
 	}
 
 
 	excelEdbMappingList := make([]*excel3.ExcelEdbMapping, 0)
 	excelEdbMappingList := make([]*excel3.ExcelEdbMapping, 0)
@@ -963,20 +965,6 @@ func (c *ExcelInfoController) Edit() {
 		return
 		return
 	}
 	}
 
 
-	if excelInfo.Source == utils.BALANCE_TABLE && req.IsAuto == false {
-		// 更新人变更
-		parentExcelInfoId := excelInfo.ParentId
-		if excelInfo.BalanceType == 1 {
-			parentExcelInfoId = excelInfo.RelExcelInfoId
-		}
-		err = excel3.ModifyExcelInfoUpdateUserId(parentExcelInfoId, sysUser.AdminId, sysUser.RealName)
-		if err != nil {
-			br.Msg = "保存失败"
-			br.ErrMsg = "保存失败,Err:" + err.Error()
-			return
-		}
-
-	}
 	// 更新excel下载地址(默认的EXCEL需要更新,自定义表格不需要更新)
 	// 更新excel下载地址(默认的EXCEL需要更新,自定义表格不需要更新)
 	if excelInfo.Source == 1 {
 	if excelInfo.Source == 1 {
 		go excel2.UpdateExcelInfoFileUrl(excelInfo)
 		go excel2.UpdateExcelInfoFileUrl(excelInfo)

+ 15 - 33
models/data_manage/chart_info.go

@@ -4,6 +4,7 @@ import (
 	"errors"
 	"errors"
 	"eta/eta_api/models/mgo"
 	"eta/eta_api/models/mgo"
 	"eta/eta_api/utils"
 	"eta/eta_api/utils"
+	"eta/eta_api/utils/mgodb"
 	"fmt"
 	"fmt"
 	"github.com/beego/beego/v2/client/orm"
 	"github.com/beego/beego/v2/client/orm"
 	"github.com/rdlucklib/rdluck_tools/paging"
 	"github.com/rdlucklib/rdluck_tools/paging"
@@ -459,24 +460,15 @@ func getEdbDataListByMongo(source, subSource, edbInfoId int, startDate, endDate
 		"edb_info_id": edbInfoId,
 		"edb_info_id": edbInfoId,
 	}
 	}
 
 
-	// 数据开始日期
-	if startDate != `` {
-		startDateTime, tmpErr := time.ParseInLocation(utils.FormatDate, startDate, time.Local)
-		if tmpErr != nil {
-			err = tmpErr
-			return
-		}
-		queryConditions["data_time"] = bson.M{"$gte": startDateTime}
+	// 数据日期
+	dateCondition, err := mgodb.BuildDateCondition(startDate, endDate)
+	if err != nil {
+		return
 	}
 	}
-	// 数据结束日期
-	if endDate != "" {
-		endDateTime, tmpErr := time.ParseInLocation(utils.FormatDate, endDate, time.Local)
-		if tmpErr != nil {
-			err = tmpErr
-			return
-		}
-		queryConditions["data_time"] = bson.M{"$lte": endDateTime}
+	if len(dateCondition) > 0 {
+		queryConditions["data_time"] = dateCondition
 	}
 	}
+
 	// 获取列表数据
 	// 获取列表数据
 	tmpDataList, tmpErr := mogDataObj.GetAllDataList(queryConditions, []string{"data_time"})
 	tmpDataList, tmpErr := mogDataObj.GetAllDataList(queryConditions, []string{"data_time"})
 	if tmpErr != nil {
 	if tmpErr != nil {
@@ -591,25 +583,15 @@ func getEdbDataListMinAndMaxByMongo(source, subSource, edbInfoId int, startDate,
 	queryConditions := bson.M{
 	queryConditions := bson.M{
 		"edb_info_id": edbInfoId,
 		"edb_info_id": edbInfoId,
 	}
 	}
-
-	// 数据开始日期
-	if startDate != `` {
-		startDateTime, tmpErr := time.ParseInLocation(utils.FormatDate, startDate, time.Local)
-		if tmpErr != nil {
-			err = tmpErr
-			return
-		}
-		queryConditions["data_time"] = bson.M{"$gte": startDateTime}
+	// 日期
+	dateCondition, err := mgodb.BuildDateCondition(startDate, endDate)
+	if err != nil {
+		return
 	}
 	}
-	// 数据结束日期
-	if endDate != "" {
-		endDateTime, tmpErr := time.ParseInLocation(utils.FormatDate, endDate, time.Local)
-		if tmpErr != nil {
-			err = tmpErr
-			return
-		}
-		queryConditions["data_time"] = bson.M{"$lte": endDateTime}
+	if len(dateCondition) > 0 {
+		queryConditions["data_time"] = dateCondition
 	}
 	}
+
 	pipeline := []bson.M{
 	pipeline := []bson.M{
 		{"$match": queryConditions},
 		{"$match": queryConditions},
 		{"$group": bson.M{
 		{"$group": bson.M{

+ 9 - 8
models/data_manage/edb_info.go

@@ -4,6 +4,7 @@ import (
 	"eta/eta_api/models/mgo"
 	"eta/eta_api/models/mgo"
 	"eta/eta_api/services/alarm_msg"
 	"eta/eta_api/services/alarm_msg"
 	"eta/eta_api/utils"
 	"eta/eta_api/utils"
+	"eta/eta_api/utils/mgodb"
 	"fmt"
 	"fmt"
 	"github.com/beego/beego/v2/client/orm"
 	"github.com/beego/beego/v2/client/orm"
 	"github.com/rdlucklib/rdluck_tools/paging"
 	"github.com/rdlucklib/rdluck_tools/paging"
@@ -1644,14 +1645,14 @@ func getAllDataByMongo(edbInfoId, source, subSource int, startDataTime string) (
 	queryConditions := bson.M{
 	queryConditions := bson.M{
 		"edb_info_id": edbInfoId,
 		"edb_info_id": edbInfoId,
 	}
 	}
-	// 结束日期
-	if startDataTime != "" {
-		startDateTime, tmpErr := time.ParseInLocation(utils.FormatDate, startDataTime, time.Local)
-		if tmpErr != nil {
-			err = tmpErr
-			return
-		}
-		queryConditions["data_time"] = bson.M{"$gt": startDateTime}
+
+	// 开始日期
+	dateCondition, err := mgodb.BuildDateCondition(startDataTime, "")
+	if err != nil {
+		return
+	}
+	if len(dateCondition) > 0 {
+		queryConditions["data_time"] = dateCondition
 	}
 	}
 
 
 	// 获取列表数据
 	// 获取列表数据

+ 0 - 7
models/data_manage/excel/excel_info.go

@@ -731,10 +731,3 @@ type ExcelInfoDetailButton struct {
 	RefreshEdbButton bool `description:"是否可刷新指标"`
 	RefreshEdbButton bool `description:"是否可刷新指标"`
 	OpWorkerButton   bool `description:"是否修改协作人"`
 	OpWorkerButton   bool `description:"是否修改协作人"`
 }
 }
-
-func ModifyExcelInfoUpdateUserId(excelInfoId, userId int, userName string) (err error) {
-	o := orm.NewOrmUsingDB("data")
-	sql := `UPDATE excel_info SET update_user_id=?,update_user_real_name=? WHERE excel_info_id =? `
-	_, err = o.Raw(sql, userId, userName, excelInfoId).Exec()
-	return
-}

+ 0 - 1
models/data_manage/excel/request/excel_info.go

@@ -35,7 +35,6 @@ type EditExcelInfoReq struct {
 	ExcelClassifyId int         `description:"分类id"`
 	ExcelClassifyId int         `description:"分类id"`
 	Content         string      `description:"Excel表格内容"`
 	Content         string      `description:"Excel表格内容"`
 	TableData       interface{} `description:"自定义表格的数据内容"`
 	TableData       interface{} `description:"自定义表格的数据内容"`
-	IsAuto          bool        `description:"是否自动保存,1:是,2:否,默认:1"`
 }
 }
 
 
 // SetExcelInfoImageReq 设置excel表格图片请求
 // SetExcelInfoImageReq 设置excel表格图片请求

+ 8 - 7
services/data/edb_data.go

@@ -6,6 +6,7 @@ import (
 	"eta/eta_api/models/data_manage"
 	"eta/eta_api/models/data_manage"
 	"eta/eta_api/models/mgo"
 	"eta/eta_api/models/mgo"
 	"eta/eta_api/utils"
 	"eta/eta_api/utils"
+	"eta/eta_api/utils/mgodb"
 	"fmt"
 	"fmt"
 	"github.com/shopspring/decimal"
 	"github.com/shopspring/decimal"
 	"go.mongodb.org/mongo-driver/bson"
 	"go.mongodb.org/mongo-driver/bson"
@@ -480,14 +481,14 @@ func getPageDataByMongo(edbInfoId, source, subSource int, endDataTime string, st
 	queryConditions := bson.M{
 	queryConditions := bson.M{
 		"edb_info_id": edbInfoId,
 		"edb_info_id": edbInfoId,
 	}
 	}
+
 	// 结束日期
 	// 结束日期
-	if endDataTime != "" {
-		endDateTime, tmpErr := time.ParseInLocation(utils.FormatDate, endDataTime, time.Local)
-		if tmpErr != nil {
-			err = tmpErr
-			return
-		}
-		queryConditions["data_time"] = bson.M{"$lte": endDateTime}
+	dateCondition, err := mgodb.BuildDateCondition("", endDataTime)
+	if err != nil {
+		return
+	}
+	if len(dateCondition) > 0 {
+		queryConditions["data_time"] = dateCondition
 	}
 	}
 
 
 	// 获取数据总量
 	// 获取数据总量

+ 3 - 3
services/data/excel/balance_table.go

@@ -13,7 +13,7 @@ import (
 	"time"
 	"time"
 )
 )
 
 
-// 将表格信息转化成指标数据
+// GetBalanceExcelData 将表格信息转化成指标数据
 func GetBalanceExcelData(excelDetail *excelModel.ExcelInfo, lang string) (newDataMap map[int]map[int]request.MixedTableCellDataReq, allRows, allCols int, err error, errMsg string) {
 func GetBalanceExcelData(excelDetail *excelModel.ExcelInfo, lang string) (newDataMap map[int]map[int]request.MixedTableCellDataReq, allRows, allCols int, err error, errMsg string) {
 	var result request.MixedTableReq
 	var result request.MixedTableReq
 	err = json.Unmarshal([]byte(excelDetail.Content), &result)
 	err = json.Unmarshal([]byte(excelDetail.Content), &result)
@@ -114,7 +114,7 @@ func GetBalanceExcelChartList(excelInfo *excelModel.ExcelInfo, lang string) (lis
 	return
 	return
 }
 }
 
 
-// 将表格信息转化成指标数据
+// GetBalanceExcelEdbData 将表格信息转化成指标数据
 func GetBalanceExcelEdbData(excelEdbMappingItem *excelModel.ExcelChartEdb, newMixedTableCellDataListMap map[int]map[int]request.MixedTableCellDataReq, dataListMap map[int][]*data_manage.EdbDataList, allRows, allCols int) (err error, errMsg string) {
 func GetBalanceExcelEdbData(excelEdbMappingItem *excelModel.ExcelChartEdb, newMixedTableCellDataListMap map[int]map[int]request.MixedTableCellDataReq, dataListMap map[int][]*data_manage.EdbDataList, allRows, allCols int) (err error, errMsg string) {
 	var dateList, dataList []string
 	var dateList, dataList []string
 	// 日期序列
 	// 日期序列
@@ -338,7 +338,7 @@ func GetBalanceExcelEdbData(excelEdbMappingItem *excelModel.ExcelChartEdb, newMi
 		// todo 处理DataTimestamp
 		// todo 处理DataTimestamp
 		dataTime, e := time.ParseInLocation(utils.FormatDate, v, time.Local)
 		dataTime, e := time.ParseInLocation(utils.FormatDate, v, time.Local)
 		if e != nil {
 		if e != nil {
-			err = errors.New("time.Parse Err:" + err.Error())
+			err = errors.New("time.Parse Err:" + e.Error())
 			return
 			return
 		}
 		}
 		timestamp := dataTime.UnixNano() / 1e6
 		timestamp := dataTime.UnixNano() / 1e6

+ 22 - 0
utils/common.go

@@ -2446,3 +2446,25 @@ func customXssPolicy() (p *bluemonday.Policy) {
 	p.AllowAttrs("allowfullscreen").OnElements("iframe")
 	p.AllowAttrs("allowfullscreen").OnElements("iframe")
 	return
 	return
 }
 }
+
+// DateConvMysqlConvMongo
+// @Description: 将mysql中的日期比较符转换成mongo中的日期比较符
+// @author: Roc
+// @datetime 2024-05-08 11:03:26
+// @param dateCon string
+func DateConvMysqlConvMongo(dateCon string) string {
+	cond := ""
+	switch dateCon {
+	case "=":
+		cond = "$eq"
+	case "<":
+		cond = "$lt"
+	case "<=":
+		cond = "$lte"
+	case ">":
+		cond = "$gt"
+	case ">=":
+		cond = "$gte"
+	}
+	return cond
+}

+ 58 - 0
utils/mgodb/common.go

@@ -0,0 +1,58 @@
+package mgodb
+
+import (
+	"eta/eta_api/utils"
+	"go.mongodb.org/mongo-driver/bson"
+	"time"
+)
+
+// BuildDateCondition
+// @Description:  构建日期查询条件
+// @author: Roc
+// @datetime 2024-06-03 09:41:19
+// @param start string
+// @param end string
+// @return condition bson.M
+// @return err error
+func BuildDateCondition(start, end string) (condition bson.M, err error) {
+	var startDateTime, endDateTime time.Time
+	if start != "" {
+		// 使用开始日期条件
+		startDateTime, err = time.ParseInLocation(utils.FormatDate, start, time.Local)
+		if err != nil {
+			return
+		}
+	}
+	if end != "" {
+		// 使用结束日期条件
+		endDateTime, err = time.ParseInLocation(utils.FormatDate, end, time.Local)
+		if err != nil {
+			return
+		}
+	}
+
+	return BuildDateTimeCondition(startDateTime, endDateTime)
+
+}
+
+// BuildDateTimeCondition
+// @Description: 构建日期查询条件
+// @author: Roc
+// @datetime 2024-06-03 09:47:32
+// @param startDateTime time.Time
+// @param endDateTime time.Time
+// @return condition bson.M
+// @return err error
+func BuildDateTimeCondition(startDateTime, endDateTime time.Time) (condition bson.M, err error) {
+	if !startDateTime.IsZero() && !endDateTime.IsZero() {
+		condition = bson.M{utils.DateConvMysqlConvMongo(">="): startDateTime, utils.DateConvMysqlConvMongo("<="): endDateTime}
+	} else if !startDateTime.IsZero() {
+		cond := utils.DateConvMysqlConvMongo(">=")
+		condition = bson.M{cond: startDateTime}
+	} else if !endDateTime.IsZero() {
+		cond := utils.DateConvMysqlConvMongo("<=")
+		condition = bson.M{cond: endDateTime}
+	}
+
+	return
+}