浏览代码

Merge branch 'feature/eta2.5.9_api_stat' into debug

xyxie 2 天之前
父节点
当前提交
a53cdca411

+ 245 - 0
controllers/data_manage/edb_inspection.go

@@ -0,0 +1,245 @@
+package data_manage
+
+import (
+	"encoding/json"
+	"eta/eta_api/models"
+	"eta/eta_api/models/data_manage/edb_inspection"
+	"eta/eta_api/services/data"
+	"eta/eta_api/controllers"
+)
+
+type EdbInspectionController struct {
+	controllers.BaseAuthController
+}
+
+// InspectionSourceList
+// @Title 获取巡检配置的来源接口
+// @Description 获取巡检配置的来源接口
+// @Success Ret=200 获取成功
+// @router /edb_inspection/source_list [get]
+func (c *EdbInspectionController) InspectionSourceList() {
+	br := new(models.BaseResponse).Init()
+
+	defer func() {
+		c.Data["json"] = br
+		c.ServeJSON()
+	}()
+
+	// 这里可以添加获取巡检来源的逻辑
+	// 目前暂时返回空列表
+	list := make([]interface{}, 0)
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = list
+}
+
+// InspectionConfigList
+// @Title 获取巡检配置列表接口
+// @Description 获取巡检配置列表接口
+// @Param   Source   query   int  true       "来源"
+// @Param   TerminalCode   query   string  false       "终端编码"
+// @Success Ret=200 获取成功
+// @router /edb_inspection/config/list [get]
+func (c *EdbInspectionController) InspectionConfigList() {
+	br := new(models.BaseResponse).Init()
+
+	defer func() {
+		c.Data["json"] = br
+		c.ServeJSON()
+	}()
+
+	source, _ := c.GetInt("Source")
+	terminalCode := c.GetString("TerminalCode")
+
+	if source <= 0 {
+		br.Msg = "来源不能为空"
+		br.IsSendEmail = false
+		return
+	}
+
+	list, err, errMsg, isSendEmail := data.GetConfigList(source, terminalCode)
+	if err != nil {
+		br.Msg = errMsg
+		br.ErrMsg = "获取失败,Err:" + err.Error()
+		br.IsSendEmail = isSendEmail
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = list
+}
+
+// SaveInspectionConfig
+// @Title 设置巡检配置接口
+// @Description 设置巡检配置接口
+// @Param	request	body edb_inspection.EdbInspectionConfigAddReq true "type json string"
+// @Success Ret=200 保存成功
+// @router /edb_inspection/config/save [post]
+func (c *EdbInspectionController) SaveInspectionConfig() {
+	br := new(models.BaseResponse).Init()
+
+	defer func() {
+		c.Data["json"] = br
+		c.ServeJSON()
+	}()
+
+	var req edb_inspection.EdbInspectionConfigAddReq
+	err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+
+	// 保存
+	err, errMsg, isSendEmail := data.SaveEdbInspectionConfig(&req)
+	if err != nil {
+		br.Msg = errMsg
+		br.ErrMsg = "保存失败,Err:" + err.Error()
+		br.IsSendEmail = isSendEmail
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "保存成功"
+}
+
+// UpdateInspectionConfigStatus
+// @Title 更新巡检配置状态接口
+// @Description 更新巡检配置状态接口
+// @Param   ConfigId   query   int64  true       "配置ID"
+// @Param   Status   query   int8  true       "状态"
+// @Success Ret=200 更新成功
+// @router /edb_inspection/config/status/update [post]
+func (c *EdbInspectionController) UpdateInspectionConfigStatus() {
+	br := new(models.BaseResponse).Init()
+
+	defer func() {
+		c.Data["json"] = br
+		c.ServeJSON()
+	}()
+	var req edb_inspection.EdbInspectionConfigStatusReq
+	err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+
+	configId := req.ConfigId
+	status := req.Status
+	if status != 1 && status != 0 {
+		br.Msg = "状态错误"
+		br.ErrMsg = "状态错误,请输入1或0"
+		br.IsSendEmail = false
+		return
+	}
+
+	if configId <= 0 {
+		br.Msg = "配置ID不能为空"
+		br.IsSendEmail = false
+		return
+	}
+
+	config := &edb_inspection.EdbInspectionConfig{
+		ConfigId: configId,
+	}
+
+	err = config.UpdateStatus(status)
+	if err != nil {
+		br.Msg = "更新失败"
+		br.ErrMsg = "更新失败,Err:" + err.Error()
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "更新成功"
+}
+
+// DeleteInspectionConfig
+// @Title 删除巡检配置接口
+// @Description 删除巡检配置接口
+// @Param   ConfigId   query   int64  true       "配置ID"
+// @Success Ret=200 删除成功
+// @router /edb_inspection/config/delete [post]
+func (c *EdbInspectionController) DeleteInspectionConfig() {
+	br := new(models.BaseResponse).Init()
+
+	defer func() {
+		c.Data["json"] = br
+		c.ServeJSON()
+	}()
+
+	var req edb_inspection.EdbInspectionConfigDeleteReq
+	err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+
+	configId := req.ConfigId
+	if configId <= 0 {
+		br.Msg = "配置ID不能为空"
+		br.IsSendEmail = false
+		return
+	}
+
+	config := &edb_inspection.EdbInspectionConfig{
+		ConfigId: configId,
+	}
+
+	err = config.Delete()
+	if err != nil {
+		br.Msg = "删除失败"
+		br.ErrMsg = "删除失败,Err:" + err.Error()
+		return
+	}
+
+	_ = edb_inspection.DeleteEdbInspectionDateConfigByConfigId(configId)
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "删除成功"
+}
+
+// GetInspectionConfigDetail
+// @Title 获取巡检配置详情接口
+// @Description 获取巡检配置详情接口
+// @Param   ConfigId   query   int64  true       "配置ID"
+// @Success Ret=200 获取成功
+// @router /edb_inspection/config/detail [get]
+func (c *EdbInspectionController) GetInspectionConfigDetail() {
+	br := new(models.BaseResponse).Init()
+
+	defer func() {
+		c.Data["json"] = br
+		c.ServeJSON()
+	}()
+
+	configId, _ := c.GetInt64("ConfigId")
+
+	if configId <= 0 {
+		br.Msg = "配置ID不能为空"
+		br.IsSendEmail = false
+		return
+	}
+
+	detail, err := data.GetConfigDetail(configId)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败,Err:" + err.Error()
+		return
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = detail
+} 

+ 163 - 0
models/data_manage/edb_inspection/edb_inspection_config.go

@@ -0,0 +1,163 @@
+package edb_inspection
+
+import (
+	"eta/eta_api/global"
+	"eta/eta_api/utils"
+	"time"
+)
+
+// EdbInspectionConfig
+// @Description: 数据源巡检配置表
+type EdbInspectionConfig struct {
+	ConfigId          int64     `gorm:"column:config_id;primaryKey;autoIncrement"`
+	Source           int       `gorm:"column:source"`
+	TerminalCode     string    `gorm:"column:terminal_code"`
+	DateType   int8      `gorm:"column:date_type"`
+	StartTime        string    `gorm:"column:start_time"`
+	IntervalTime     int       `gorm:"column:interval_time"`
+	NotifyUsers      string    `gorm:"column:notify_users"`
+	Status           int8      `gorm:"column:status"`
+	CreateTime       time.Time `gorm:"column:create_time"`
+	ModifyTime       time.Time `gorm:"column:modify_time"`
+	InspectionTime   string    `gorm:"-"` // 用于显示巡检时间,不存储到数据库
+}
+
+// Add
+// @Description: 添加巡检配置
+// @receiver m
+// @return err error
+func (m *EdbInspectionConfig) Add() (err error) {
+	m.CreateTime = time.Now()
+	m.ModifyTime = time.Now()
+	err = global.DbMap[utils.DbNameIndex].Create(m).Error
+	return
+}
+
+// Update
+// @Description: 更新巡检配置
+// @receiver m
+// @param cols []string
+// @return err error
+func (m *EdbInspectionConfig) Update(cols []string) (err error) {
+	m.ModifyTime = time.Now()
+	err = global.DbMap[utils.DbNameIndex].Select(cols).Updates(m).Error
+	return
+}
+
+// Delete
+// @Description: 删除巡检配置
+// @receiver m
+// @return err error
+func (m *EdbInspectionConfig) Delete() (err error) {
+	sql := `DELETE FROM edb_inspection_config WHERE config_id = ?`
+	err = global.DbMap[utils.DbNameIndex].Exec(sql, m.ConfigId).Error
+	return
+}
+
+// UpdateStatus
+// @Description: 更新巡检配置状态
+// @receiver m
+// @param status int8
+// @return err error
+func (m *EdbInspectionConfig) UpdateStatus(status int8) (err error) {
+	sql := `UPDATE edb_inspection_config SET status = ?, modify_time = ? WHERE config_id = ?`
+	err = global.DbMap[utils.DbNameIndex].Exec(sql, status, time.Now(), m.ConfigId).Error
+	return
+}
+
+// GetListByTerminalCode
+// @Description: 根据终端编码获取巡检配置列表
+// @param terminalCode string
+// @return list []*EdbInspectionConfig
+// @return err error
+func GetListByTerminalCode(terminalCode string) (list []*EdbInspectionConfig, err error) {
+	sql := `SELECT * FROM edb_inspection_config WHERE terminal_code = ? ORDER BY config_id ASC`
+	err = global.DbMap[utils.DbNameIndex].Raw(sql, terminalCode).Find(&list).Error
+	return
+}
+
+// GetById
+// @Description: 根据ID获取巡检配置
+// @param configId int64
+// @return item *EdbInspectionConfig
+// @return err error
+func GetById(configId int64) (item *EdbInspectionConfig, err error) {
+	sql := `SELECT * FROM edb_inspection_config WHERE config_id = ?`
+	err = global.DbMap[utils.DbNameIndex].Raw(sql, configId).First(&item).Error
+	return
+}
+
+// GetListBySource
+// @Description: 根据来源获取巡检配置列表
+// @param source int
+// @return list []*EdbInspectionConfig
+// @return err error
+func GetListBySource(source int) (list []*EdbInspectionConfig, err error) {
+	sql := `SELECT * FROM edb_inspection_config WHERE source = ? ORDER BY config_id ASC`
+	err = global.DbMap[utils.DbNameIndex].Raw(sql, source).Find(&list).Error
+	return
+}
+
+func GetConfigListBySourceAndTerminalCode(source int, terminalCode string) (list []*EdbInspectionConfigItem, err error) {
+	condition := " c.source = ? "
+	var pars []interface{}
+	pars = append(pars, source)
+
+	if terminalCode != "" {
+		condition += " AND c.terminal_code = ? "
+		pars = append(pars, terminalCode)
+	}
+
+	sql := `SELECT c.*, t.name AS terminal_name, s.source_name FROM edb_inspection_config c left join edb_terminal t on c.terminal_code = t.terminal_code left join edb_source s on c.source = s.edb_source_id WHERE ` + condition + ` ORDER BY c.modify_time DESC`
+	err = global.DbMap[utils.DbNameIndex].Raw(sql, pars...).Find(&list).Error
+	return
+}
+
+type EdbInspectionConfigAddReq struct {
+	ConfigId          int64    
+	Source           int       
+	TerminalCode     string    
+	NotifyUsers         string `description:"通知用户"`
+	//Status              int8   `description:"状态"` 
+	DateType   int8      
+	StartTime         string 
+	IntervalTime      int   
+	List      []InspectionConfigReq `description:"刷新配置项"`
+}
+
+// @Description: 刷新时间配置项
+type InspectionConfigReq struct {
+	InspectionFrequency string `description:"巡检频率"`
+	InspectionFrequencyDay        int    `description:"具体刷新的日期"`
+	InspectionDate      string `description:"巡检日期"`
+	InspectionTime      string `description:"巡检时间"`
+}
+
+type EdbInspectionConfigDetailResp struct {
+	*EdbInspectionConfig
+	List      []InspectionConfigReq `description:"刷新配置项"`
+}
+
+type EdbInspectionConfigItem struct {
+	ConfigId          int64    
+	Source           int       
+	SourceName       string
+	TerminalCode     string    
+	TerminalName     string
+	StartTime        string `description:"开始时间"`
+	IntervalTime     int    `description:"间隔时间"`
+	NotifyUsers         string `description:"通知用户"`
+	NotifyUsersName   string `description:"通知用户名称"`
+	Status              int8   `description:"状态"` 
+	DateType   int8      
+	InspectionTime   string `description:"巡检时间"`
+}
+
+type EdbInspectionConfigStatusReq struct {
+	ConfigId int64 `description:"配置ID"`
+	Status   int8  `description:"状态"`
+}
+
+type EdbInspectionConfigDeleteReq struct {
+	ConfigId int64 `description:"配置ID"`
+}

+ 114 - 0
models/data_manage/edb_inspection/edb_inspection_date_config.go

@@ -0,0 +1,114 @@
+package edb_inspection
+
+import (
+	"eta/eta_api/global"
+	"eta/eta_api/utils"
+	"time"
+)
+
+// EdbInspectionDateConfig
+// @Description: 数据源巡检配置表
+type EdbInspectionDateConfig struct {
+	DateConfigId        int64     `orm:"column(date_config_id);pk" gorm:"primaryKey" `
+	InspectionFrequency string    `description:"巡检频率,枚举值:每自然日、每交易日、每周"`
+	InspectionFrequencyDay int    `description:"具体刷新的日期"`
+	InspectionDate      string    `description:"巡检日期(每周几/每月几号)"`
+	InspectionTime      string    `description:"巡检时间,具体到时分"`
+	ConfigId            int64     `description:"关联的巡检配置ID"`
+	CreateTime          time.Time `description:"创建时间"`
+	ModifyTime          time.Time `description:"修改时间"`
+}
+
+// Add
+// @Description: 添加
+// @author: Roc
+// @receiver m
+// @datetime 2024-01-10 16:11:10
+// @return err error
+func AddEdbInspectionDateConfigList(list []*EdbInspectionDateConfig, configId int64) (err error) {
+	err = global.DbMap[utils.DbNameIndex].CreateInBatches(list, utils.MultiAddNum).Error
+	return
+}
+
+// Update
+// @Description: 更新
+// @author: Roc
+// @receiver m
+// @datetime 2024-01-10 16:11:10
+// @param cols []string
+// @return err error
+func (m *EdbInspectionDateConfig) Update(cols []string) (err error) {
+	err = global.DbMap[utils.DbNameIndex].Select(cols).Updates(m).Error
+	return
+}
+
+// Delete
+// @Description: 删除
+// @author: Roc
+// @receiver m
+// @datetime 2024-01-10 16:11:10
+// @return err error
+func (m *EdbInspectionDateConfig) Delete() (err error) {
+	sql := ` DELETE FROM edb_inspection_date_config WHERE date_config_id=?`
+	err = global.DbMap[utils.DbNameIndex].Exec(sql, m.DateConfigId).Error
+	return
+}
+
+// 删除配置关联的所有巡检日期配置
+func DeleteEdbInspectionDateConfigByConfigId(configId int64) (err error) {
+	sql := `DELETE FROM edb_inspection_date_config WHERE config_id = ?`
+	err = global.DbMap[utils.DbNameIndex].Exec(sql, configId).Error
+	return
+}
+
+// GetEdbInspectionDateConfigListByCondition
+// @Description: 根据条件获取巡检配置列表
+// @author: Roc
+// @datetime 2024-01-10 16:11:10
+// @param inspectionFrequency string
+// @param inspectionFrequencyDay int
+// @param inspectionDate string
+// @param inspectionTime string
+// @param configId int64
+// @return item *EdbInspectionDateConfig
+// @return err error
+func GetEdbInspectionDateConfigListByCondition(inspectionFrequency string, inspectionFrequencyDay int, inspectionDate, inspectionTime string, configId int64) (item *EdbInspectionDateConfig, err error) {
+	sql := `SELECT * FROM edb_inspection_date_config
+	     WHERE inspection_frequency = ? AND inspection_frequency_day = ? AND inspection_date = ? AND inspection_time = ? AND config_id = ? ORDER BY date_config_id ASC `
+
+	err = global.DbMap[utils.DbNameIndex].Raw(sql, inspectionFrequency, inspectionFrequencyDay, inspectionDate, inspectionTime, configId).First(&item).Error
+	return
+}
+
+// GetEdbInspectionDateConfigListByConfigId
+// @Description: 根据配置ID获取巡检日期配置列表
+// @author: Roc
+// @datetime 2024-01-10 16:11:10
+// @param configId int64
+// @return list []*EdbInspectionDateConfig
+// @return err error
+func GetEdbInspectionDateConfigListByConfigId(configId int64) (list []*EdbInspectionDateConfig, err error) {
+	sql := `SELECT * FROM edb_inspection_date_config WHERE config_id = ? ORDER BY date_config_id ASC`
+	err = global.DbMap[utils.DbNameIndex].Raw(sql, configId).Find(&list).Error
+	return
+}
+
+func GetEdbInspectionDateConfigListByConfigIdList(configIdList []int64) (list []*EdbInspectionDateConfig, err error) {
+	sql := `SELECT * FROM edb_inspection_date_config WHERE config_id IN (?) ORDER BY date_config_id ASC`
+	err = global.DbMap[utils.DbNameIndex].Raw(sql, configIdList).Find(&list).Error
+	return
+}
+
+// GetEdbInspectionDateConfigListBySourceAndTerminalCode
+// @Description: 根据来源和终端编码获取巡检日期配置列表
+// @author: Roc
+// @datetime 2024-01-10 16:11:10
+// @param source int
+// @param terminalCode string
+// @return list []*EdbInspectionDateConfig
+// @return err error
+func GetEdbInspectionDateConfigListBySourceAndTerminalCode(source int, terminalCode string) (list []*EdbInspectionDateConfig, err error) {
+	sql := `SELECT * FROM edb_inspection_date_config WHERE source = ? AND terminal_code = ? ORDER BY date_config_id ASC`
+	err = global.DbMap[utils.DbNameIndex].Raw(sql, source, terminalCode).Find(&list).Error
+	return
+}	

+ 54 - 0
routers/commentsRouter.go

@@ -6442,6 +6442,60 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:EdbInspectionController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:EdbInspectionController"],
+        beego.ControllerComments{
+            Method: "DeleteInspectionConfig",
+            Router: `/edb_inspection/config/delete`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:EdbInspectionController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:EdbInspectionController"],
+        beego.ControllerComments{
+            Method: "GetInspectionConfigDetail",
+            Router: `/edb_inspection/config/detail`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:EdbInspectionController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:EdbInspectionController"],
+        beego.ControllerComments{
+            Method: "InspectionConfigList",
+            Router: `/edb_inspection/config/list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:EdbInspectionController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:EdbInspectionController"],
+        beego.ControllerComments{
+            Method: "SaveInspectionConfig",
+            Router: `/edb_inspection/config/save`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:EdbInspectionController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:EdbInspectionController"],
+        beego.ControllerComments{
+            Method: "UpdateInspectionConfigStatus",
+            Router: `/edb_inspection/config/status/update`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:EdbInspectionController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:EdbInspectionController"],
+        beego.ControllerComments{
+            Method: "InspectionSourceList",
+            Router: `/edb_inspection/source_list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:FactorEdbSeriesController"] = append(beego.GlobalControllerRouter["eta/eta_api/controllers/data_manage:FactorEdbSeriesController"],
         beego.ControllerComments{
             Method: "Add",

+ 1 - 0
routers/router.go

@@ -207,6 +207,7 @@ func init() {
 				&data_manage.BaseFromGprRiskController{},
 				&data_manage.BaseFromPurangController{},
 				&data_manage.BaseFromRadishResearchController{},
+				&data_manage.EdbInspectionController{},
 			),
 		),
 		web.NSNamespace("/my_chart",

+ 397 - 0
services/data/edb_inspection.go

@@ -0,0 +1,397 @@
+package data
+
+import (
+	"encoding/json"
+	"errors"
+	"eta/eta_api/models/data_manage/edb_inspection"
+	"eta/eta_api/models/data_manage"
+	"eta/eta_api/models/system"
+	"eta/eta_api/utils"
+	"fmt"
+	"strconv"
+	"strings"
+	"time"
+)
+
+// 所有巡检配置key
+var allDefaultEdbInspectionConfigKey = `edb_inspection_config:default:all:`
+
+// GetAllDefaultEdbInspectionConfigListBySource
+// @Description: 获取默认的所有巡检配置列表
+// @author: Roc
+// @datetime 2024-01-10 15:03:36
+// @param source int
+// @return list []*edb_inspection.EdbInspectionConfig
+// @return err error
+func GetAllDefaultEdbInspectionConfigListBySource(source int) (list []*edb_inspection.EdbInspectionConfig, err error) {
+	key := getAllDefaultEdbInspectionConfigKey(source)
+	if utils.Re == nil {
+		if utils.Re == nil && utils.Rc.IsExist(key) {
+			if data, err1 := utils.Rc.RedisBytes(key); err1 == nil {
+				err = json.Unmarshal(data, &list)
+				return
+			}
+		}
+	}
+
+	list, err = edb_inspection.GetListBySource(source)
+	if err != nil {
+		return
+	}
+
+	// 将数据加入缓存
+	if utils.Re == nil {
+		data, _ := json.Marshal(list)
+		utils.Rc.Put(key, data, 2*time.Hour)
+	}
+
+	return
+}
+
+// SaveEdbInspectionConfig
+// @Description: 设置巡检配置接口
+// @author: Roc
+// @datetime 2024-01-10 15:11:19
+// @param req *edb_inspection.EdbInspectionConfigAddReq
+// @return err error
+// @return errMsg string
+// @return isSendEmail bool
+func SaveEdbInspectionConfig(req *edb_inspection.EdbInspectionConfigAddReq) (err error, errMsg string, isSendEmail bool) {
+	isSendEmail = true
+	errMsg = `保存失败`
+
+	if req.Source <= 0 {
+		errMsg = "来源不能为空"
+		err = errors.New(errMsg)
+		isSendEmail = false
+		return
+	}
+
+	if req.TerminalCode == "" {
+		errMsg = "终端编码不能为空"
+		err = errors.New(errMsg)
+		isSendEmail = false
+		return
+	}
+
+	// 判断终端是否存在
+	terminal, e := data_manage.GetEdbTerminalByCode(req.TerminalCode)
+	if e != nil {
+		errMsg = "终端不存在"
+		err = errors.New(errMsg)
+		isSendEmail = false
+		return
+	}
+	if terminal.TerminalCode != "" && terminal.Source != req.Source {
+		errMsg = "数据源不匹配"
+		err = errors.New(errMsg)
+		isSendEmail = false
+		return
+	}
+
+	//判断该终端配置是否已存在
+	if req.ConfigId <= 0 {
+		inspectionConfig, e := edb_inspection.GetListByTerminalCode(req.TerminalCode)
+		if e != nil && !utils.IsErrNoRow(e) {
+			errMsg = "查询终端配置失败"
+			err = errors.New(errMsg)
+			isSendEmail = false
+			return
+		}
+		if e == nil && len(inspectionConfig) > 0 {
+			errMsg = "终端配置已存在"
+			err = errors.New(errMsg)
+			isSendEmail = false
+			return
+		}
+	}
+
+	lenConf := len(req.List)
+	if req.DateType == 1 && lenConf == 0 {
+		errMsg = "至少需要一个巡检配置"
+		err = errors.New(errMsg)
+		isSendEmail = false
+		return
+	}
+	if req.DateType == 1 && lenConf > 5 {
+		errMsg = "巡检时间设置最多不超过5个"
+		err = errors.New(errMsg)
+		isSendEmail = false
+		return
+	}
+
+	tmpArr := []string{"每自然日", "每交易日", "每周"}
+	// 配置的map,避免同一种类型配置同一个时间
+	configMap := make(map[string]string)
+	for _, v := range req.List {
+		if !utils.InArrayByStr(tmpArr, v.InspectionFrequency) {
+			errMsg = "巡检频率不合法"
+			err = errors.New(errMsg)
+			isSendEmail = false
+			return
+		}
+
+		if v.InspectionTime == "" {
+			errMsg = "请选择具体时间"
+			err = errors.New(errMsg)
+			isSendEmail = false
+			return
+		}
+
+		// 配置的map,避免同一种类型配置同一个时间
+		key := fmt.Sprint(v.InspectionFrequency, "_", v.InspectionFrequencyDay, "_", v.InspectionTime)
+		if _, ok := configMap[key]; ok {
+			errMsg = "巡检频率和日期不能重复"
+			err = errors.New(errMsg)
+			isSendEmail = false
+			return
+		}
+		configMap[key] = key
+	}
+
+
+
+	configId := req.ConfigId
+	if configId > 0 {
+		// 查询配置
+		inspectionConfig, e := edb_inspection.GetById(configId)
+		if e != nil {
+			errMsg = "配置不存在"
+			err = errors.New(errMsg)
+			isSendEmail = false
+			return
+		}
+		inspectionConfig.ConfigId = req.ConfigId
+		updateCols := []string{"source", "terminal_code", "date_type", "start_time", "interval_time", "notify_users", "modify_time"}
+		inspectionConfig.Source = req.Source
+		inspectionConfig.TerminalCode = req.TerminalCode
+		inspectionConfig.DateType = req.DateType
+		inspectionConfig.StartTime = req.StartTime
+		inspectionConfig.IntervalTime = req.IntervalTime
+		inspectionConfig.NotifyUsers = req.NotifyUsers
+		inspectionConfig.ModifyTime = time.Now()
+		err = inspectionConfig.Update(updateCols)
+	} else {
+		// 创建巡检配置
+		inspectionConfig := &edb_inspection.EdbInspectionConfig{
+			Source:       req.Source,
+			TerminalCode: req.TerminalCode,
+			DateType:     req.DateType,
+			StartTime:    req.StartTime,
+			Status:       1,
+			IntervalTime: req.IntervalTime,
+			NotifyUsers:  req.NotifyUsers,
+			CreateTime:   time.Now(),
+			ModifyTime:   time.Now(),
+		}
+		err = inspectionConfig.Add()
+		if err != nil {
+			return
+		}
+		configId = inspectionConfig.ConfigId
+	}
+	if err != nil {
+		return
+	}
+
+	// 删除原先的配置
+	err = edb_inspection.DeleteEdbInspectionDateConfigByConfigId(configId)
+	if err != nil {
+		return
+	}
+
+	// 创建巡检日期配置
+	dateConfigList := make([]*edb_inspection.EdbInspectionDateConfig, 0)
+	if req.DateType == 1 {
+		for _, v := range req.List {
+			dateConfig := &edb_inspection.EdbInspectionDateConfig{
+				InspectionFrequency:    v.InspectionFrequency,
+				InspectionFrequencyDay: v.InspectionFrequencyDay,
+				InspectionDate:         v.InspectionDate,
+				InspectionTime:         v.InspectionTime,
+				ConfigId:              configId,
+				CreateTime:            time.Now(),
+				ModifyTime:            time.Now(),
+			}
+			dateConfigList = append(dateConfigList, dateConfig)
+		}
+
+		if len(dateConfigList) > 0 {
+			err = edb_inspection.AddEdbInspectionDateConfigList(dateConfigList, configId)
+			if err != nil {
+				return
+			}
+		}
+	}
+
+	// 清除缓存
+	{
+		key := getAllDefaultEdbInspectionConfigKey(req.Source)
+		if utils.Re == nil {
+			_ = utils.Rc.Delete(key)
+		}
+	}
+
+	return
+}
+
+// HandleInspectionTime
+// @Description: 处理巡检时间的显示
+// @author: Roc
+// @datetime 2024-01-10 17:00:03
+// @param source int
+// @param terminalCode string
+// @return list []*edb_inspection.EdbInspectionConfig
+// @return err error
+// @return errMsg string
+// @return isSendEmail bool
+func GetConfigList(source int, terminalCode string) (list []*edb_inspection.EdbInspectionConfigItem, err error, errMsg string, isSendEmail bool) {
+	isSendEmail = true
+	errMsg = "获取失败"
+
+	list, err = edb_inspection.GetConfigListBySourceAndTerminalCode(source, terminalCode)
+	if err != nil {
+		return
+	}
+	if len(list) <= 0 {
+		return
+	}
+	configIdList := make([]int64, 0)
+	adminIds := make([]int, 0)
+	for _, config := range list {
+		configIdList = append(configIdList, config.ConfigId)
+		adminIdSlice := strings.Split(config.NotifyUsers, ",")
+		for _, adminId := range adminIdSlice {
+			if adminId != "" {
+				id, _ := strconv.Atoi(adminId)
+				adminIds = append(adminIds, id)
+			}
+		}
+	}
+	adminNameMap := make(map[int]string)
+	if len(adminIds) > 0 {
+		adminList, e := system.GetAdminItemByIdList(adminIds)
+		if e != nil {
+			errMsg = "获取通知用户失败"
+			err = errors.New(errMsg+e.Error())
+			isSendEmail = false
+			return
+		}
+		for _, admin := range adminList {
+			adminNameMap[admin.AdminId] = admin.RealName
+		}
+	}
+
+	// 获取每个配置的日期配置
+	dateConfigs, tmpErr := edb_inspection.GetEdbInspectionDateConfigListByConfigIdList(configIdList)
+	if tmpErr != nil {
+		err = tmpErr
+		return
+	}
+
+	// 处理巡检时间显示
+	inspectionTimeList := make(map[int64][]string, 0)
+	for _, dateConfig := range dateConfigs {
+		inspectionTimeList[dateConfig.ConfigId] = append(inspectionTimeList[dateConfig.ConfigId], GetInspectionStr(dateConfig.InspectionFrequency, dateConfig.InspectionFrequencyDay, dateConfig.InspectionTime))
+	}
+	for _, config := range list {
+		if config.NotifyUsers != "" {
+			adminIdSlice := strings.Split(config.NotifyUsers, ",")
+			nameList := make([]string, 0)
+			for _, adminId := range adminIdSlice {
+				if adminId != "" {
+					id, _ := strconv.Atoi(adminId)
+					nameList = append(nameList, adminNameMap[id])
+				}
+			}
+			config.NotifyUsersName = strings.Join(nameList, ",")
+		}
+		if config.DateType == 1 {
+			tmpList, ok := inspectionTimeList[config.ConfigId]
+			if ok {
+				config.InspectionTime = strings.Join(tmpList, ",")
+			}
+		} else {
+			config.InspectionTime = fmt.Sprintf("%s开始每间隔%d小时", config.StartTime, config.IntervalTime)
+		}
+	}
+
+	return
+}
+
+func GetConfigDetail(configId int64) (detail *edb_inspection.EdbInspectionConfigDetailResp, err error) {
+	item, err := edb_inspection.GetById(configId)
+	if err != nil {
+		return
+	}
+	dateConfigs, err := edb_inspection.GetEdbInspectionDateConfigListByConfigId(configId)
+	if err != nil {
+		return
+	}
+	list := make([]edb_inspection.InspectionConfigReq, 0)
+	for _, dateConfig := range dateConfigs {
+		list = append(list, edb_inspection.InspectionConfigReq{
+			InspectionFrequency: dateConfig.InspectionFrequency,
+			InspectionFrequencyDay: dateConfig.InspectionFrequencyDay,
+			InspectionDate: dateConfig.InspectionDate,
+			InspectionTime: dateConfig.InspectionTime,
+		})
+	}
+	detail = &edb_inspection.EdbInspectionConfigDetailResp{
+		EdbInspectionConfig: item,
+		List:   list,
+	}
+
+	return
+}
+
+// getAllDefaultEdbInspectionConfigKey
+// @Description: 获取默认的所有巡检配置key
+// @author: Roc
+// @datetime 2024-01-10 15:02:49
+// @param source int
+// @return string
+func getAllDefaultEdbInspectionConfigKey(source int) string {
+	return allDefaultEdbInspectionConfigKey + fmt.Sprintf("%d", source)
+}
+
+// GetInspectionStr
+// @Description: 获取巡检配置的中文字符串
+// @author: Roc
+// @datetime 2024-01-10 16:05:10
+// @param inspectionFrequency string
+// @param inspectionFrequencyDay int
+// @param inspectionTime string
+// @return string
+func GetInspectionStr(inspectionFrequency string, inspectionFrequencyDay int, inspectionTime string) string {
+	inspectionDayStr := ``
+	switch inspectionFrequency {
+	case "每自然日", "每交易日":
+	case "每周":
+		switch inspectionFrequencyDay {
+		case 0:
+			inspectionDayStr = "日"
+		case 1:
+			inspectionDayStr = "一"
+		case 2:
+			inspectionDayStr = "二"
+		case 3:
+			inspectionDayStr = "三"
+		case 4:
+			inspectionDayStr = "四"
+		case 5:
+			inspectionDayStr = "五"
+		case 6:
+			inspectionDayStr = "六"
+		case 7:
+			inspectionDayStr = "日"
+		}
+	default:
+		if inspectionFrequencyDay > 0 {
+			inspectionDayStr = fmt.Sprintf("第%d天", inspectionFrequencyDay)
+		} else {
+			inspectionDayStr = `最后一天`
+		}
+	}
+	return inspectionFrequency + inspectionDayStr + " " + inspectionTime
+}