style: 去除Impl接口声明层聚焦服务函数
This commit is contained in:
@@ -1,30 +1,171 @@
|
||||
package service
|
||||
|
||||
import "be.ems/src/modules/network_element/model"
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
// INeHost 网元主机连接 服务层接口
|
||||
type INeHost interface {
|
||||
// SelectPage 根据条件分页查询字典类型
|
||||
SelectPage(query map[string]any) map[string]any
|
||||
"be.ems/src/framework/config"
|
||||
"be.ems/src/framework/logger"
|
||||
"be.ems/src/framework/utils/crypto"
|
||||
"be.ems/src/modules/network_element/model"
|
||||
"be.ems/src/modules/network_element/repository"
|
||||
)
|
||||
|
||||
// SelectList 根据实体查询
|
||||
SelectList(neHost model.NeHost) []model.NeHost
|
||||
|
||||
// SelectById 通过ID查询
|
||||
SelectById(hostId string) model.NeHost
|
||||
|
||||
// CheckUniqueHostTitle 校验分组组和主机名称是否唯一
|
||||
CheckUniqueHostTitle(groupId, title, hostType, hostId string) bool
|
||||
|
||||
// Insert 新增信息
|
||||
Insert(neHost model.NeHost) string
|
||||
|
||||
// Update 修改信息
|
||||
Update(neHost model.NeHost) int64
|
||||
|
||||
// Insert 批量添加
|
||||
Inserts(neHosts []model.NeHost) int64
|
||||
|
||||
// DeleteByIds 批量删除网元主机连接信息
|
||||
DeleteByIds(hostIds []string) (int64, error)
|
||||
// 实例化服务层 NeHost 结构体
|
||||
var NewNeHost = &NeHost{
|
||||
neHostRepository: repository.NewNeHost,
|
||||
}
|
||||
|
||||
// NeHost 网元主机连接 服务层处理
|
||||
type NeHost struct {
|
||||
neHostRepository *repository.NeHost // 网元主机连接表
|
||||
}
|
||||
|
||||
// SelectNeHostPage 分页查询列表数据
|
||||
func (r *NeHost) SelectPage(query map[string]any) map[string]any {
|
||||
return r.neHostRepository.SelectPage(query)
|
||||
}
|
||||
|
||||
// SelectConfigList 查询列表
|
||||
func (r *NeHost) SelectList(neHost model.NeHost) []model.NeHost {
|
||||
return r.neHostRepository.SelectList(neHost)
|
||||
}
|
||||
|
||||
// SelectByIds 通过ID查询
|
||||
func (r *NeHost) SelectById(hostId string) model.NeHost {
|
||||
neHost := model.NeHost{}
|
||||
if hostId == "" {
|
||||
return neHost
|
||||
}
|
||||
neHosts := r.neHostRepository.SelectByIds([]string{hostId})
|
||||
if len(neHosts) > 0 {
|
||||
neHost := neHosts[0]
|
||||
hostKey := config.Get("aes.hostKey").(string)
|
||||
if neHost.Password != "" {
|
||||
passwordDe, err := crypto.AESDecryptBase64(neHost.Password, hostKey)
|
||||
if err != nil {
|
||||
logger.Errorf("select encrypt: %v", err.Error())
|
||||
return neHost
|
||||
}
|
||||
neHost.Password = passwordDe
|
||||
}
|
||||
if neHost.PrivateKey != "" {
|
||||
privateKeyDe, err := crypto.AESDecryptBase64(neHost.PrivateKey, hostKey)
|
||||
if err != nil {
|
||||
logger.Errorf("select encrypt: %v", err.Error())
|
||||
return neHost
|
||||
}
|
||||
neHost.PrivateKey = privateKeyDe
|
||||
}
|
||||
if neHost.PassPhrase != "" {
|
||||
passPhraseDe, err := crypto.AESDecryptBase64(neHost.PassPhrase, hostKey)
|
||||
if err != nil {
|
||||
logger.Errorf("select encrypt: %v", err.Error())
|
||||
return neHost
|
||||
}
|
||||
neHost.PassPhrase = passPhraseDe
|
||||
}
|
||||
return neHost
|
||||
}
|
||||
return model.NeHost{}
|
||||
}
|
||||
|
||||
// Insert 批量添加
|
||||
func (r *NeHost) Inserts(neHosts []model.NeHost) int64 {
|
||||
var num int64 = 0
|
||||
for _, v := range neHosts {
|
||||
hostId := r.neHostRepository.Insert(v)
|
||||
if hostId != "" {
|
||||
num += 1
|
||||
}
|
||||
}
|
||||
return num
|
||||
}
|
||||
|
||||
// Insert 新增信息
|
||||
func (r *NeHost) Insert(neHost model.NeHost) string {
|
||||
hostKey := config.Get("aes.hostKey").(string)
|
||||
if neHost.Password != "" {
|
||||
passwordEn, err := crypto.AESEncryptBase64(neHost.Password, hostKey)
|
||||
if err != nil {
|
||||
logger.Errorf("insert encrypt: %v", err.Error())
|
||||
return ""
|
||||
}
|
||||
neHost.Password = passwordEn
|
||||
}
|
||||
if neHost.PrivateKey != "" {
|
||||
privateKeyEn, err := crypto.AESEncryptBase64(neHost.PrivateKey, hostKey)
|
||||
if err != nil {
|
||||
logger.Errorf("insert encrypt: %v", err.Error())
|
||||
return ""
|
||||
}
|
||||
neHost.PrivateKey = privateKeyEn
|
||||
}
|
||||
if neHost.PassPhrase != "" {
|
||||
passPhraseEn, err := crypto.AESEncryptBase64(neHost.PassPhrase, hostKey)
|
||||
if err != nil {
|
||||
logger.Errorf("insert encrypt: %v", err.Error())
|
||||
return ""
|
||||
}
|
||||
neHost.PassPhrase = passPhraseEn
|
||||
}
|
||||
return r.neHostRepository.Insert(neHost)
|
||||
}
|
||||
|
||||
// Update 修改信息
|
||||
func (r *NeHost) Update(neHost model.NeHost) int64 {
|
||||
hostKey := config.Get("aes.hostKey").(string)
|
||||
if neHost.Password != "" {
|
||||
passwordEn, err := crypto.AESEncryptBase64(neHost.Password, hostKey)
|
||||
if err != nil {
|
||||
logger.Errorf("update password encrypt: %v", err.Error())
|
||||
return 0
|
||||
}
|
||||
neHost.Password = passwordEn
|
||||
}
|
||||
if neHost.PrivateKey != "" {
|
||||
privateKeyEn, err := crypto.AESEncryptBase64(neHost.PrivateKey, hostKey)
|
||||
if err != nil {
|
||||
logger.Errorf("update private key encrypt: %v", err.Error())
|
||||
return 0
|
||||
}
|
||||
neHost.PrivateKey = privateKeyEn
|
||||
}
|
||||
if neHost.PassPhrase != "" {
|
||||
passPhraseEn, err := crypto.AESEncryptBase64(neHost.PassPhrase, hostKey)
|
||||
if err != nil {
|
||||
logger.Errorf("update pass phrase encrypt: %v", err.Error())
|
||||
return 0
|
||||
}
|
||||
neHost.PassPhrase = passPhraseEn
|
||||
}
|
||||
return r.neHostRepository.Update(neHost)
|
||||
}
|
||||
|
||||
// DeleteByIds 批量删除网元主机连接信息
|
||||
func (r *NeHost) DeleteByIds(hostIds []string) (int64, error) {
|
||||
// 检查是否存在
|
||||
ids := r.neHostRepository.SelectByIds(hostIds)
|
||||
if len(ids) <= 0 {
|
||||
return 0, fmt.Errorf("neHost.noData")
|
||||
}
|
||||
|
||||
if len(ids) == len(hostIds) {
|
||||
rows := r.neHostRepository.DeleteByIds(hostIds)
|
||||
return rows, nil
|
||||
}
|
||||
// 删除信息失败!
|
||||
return 0, fmt.Errorf("delete fail")
|
||||
}
|
||||
|
||||
// CheckUniqueHostTitle 校验分组组和主机名称是否唯一
|
||||
func (r *NeHost) CheckUniqueHostTitle(groupId, title, hostType, hostId string) bool {
|
||||
uniqueId := r.neHostRepository.CheckUniqueNeHost(model.NeHost{
|
||||
HostType: hostType,
|
||||
GroupID: groupId,
|
||||
Title: title,
|
||||
})
|
||||
if uniqueId == hostId {
|
||||
return true
|
||||
}
|
||||
return uniqueId == ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user