fix: 网元软件包类型字段变更

This commit is contained in:
TsMask
2024-05-27 17:11:09 +08:00
parent 4ac4fb55dc
commit abfe3227f2
6 changed files with 54 additions and 44 deletions

View File

@@ -71,7 +71,7 @@ func (s *NeSoftwareController) Add(c *gin.Context) {
// 找到已存在的删除后重新添加
neSoftwares := s.neSoftwareService.SelectList(model.NeSoftware{
NeType: body.NeType,
Type: body.Type,
Name: body.Name,
Version: body.Version,
})
@@ -111,7 +111,7 @@ func (s *NeSoftwareController) Edit(c *gin.Context) {
}
// 检查属性值唯一
uniqueSoftware := s.neSoftwareService.CheckUniqueTypeAndNameAndVersion(body.NeType, body.Name, body.Version, body.ID)
uniqueSoftware := s.neSoftwareService.CheckUniqueTypeAndNameAndVersion(body.Type, body.Name, body.Version, body.ID)
if !uniqueSoftware {
// 网元软件包操作【%s】失败网元类型与文件名版本已存在
msg := i18n.TTemplate(language, "neSoftware.errKeyExists", map[string]any{"name": body.Name})
@@ -176,14 +176,14 @@ func (s *NeSoftwareController) NewNeVersion(c *gin.Context) {
// 找到已存在的软件包信息
neSoftwares := s.neSoftwareService.SelectList(model.NeSoftware{
NeType: body.NeType,
Type: body.Type,
Name: body.Name,
Version: body.Version,
})
if len(neSoftwares) > 0 {
neSoftware := neSoftwares[0]
s.neSoftwareService.UpdateVersions(neSoftware, model.NeVersion{
NeType: neSoftware.NeType,
NeType: neSoftware.Type,
UpdateBy: ctx.LoginUserToUserName(c),
})
c.JSON(200, result.Ok(nil))

View File

@@ -3,7 +3,7 @@ package model
// NeSoftware 网元软件包 ne_software
type NeSoftware struct {
ID string `json:"id" gorm:"id"`
NeType string `json:"neType" gorm:"ne_type" binding:"required"` // 网元类型
Type string `json:"type" gorm:"type" binding:"required"` // 类型
Name string `json:"name" gorm:"name" binding:"required"` // 包名称
Path string `json:"path" gorm:"path"` // 包路径
Version string `json:"version" gorm:"version" binding:"required"` // 包版本

View File

@@ -15,12 +15,12 @@ import (
// 实例化数据层 NewNeSoftware 结构体
var NewNeSoftwareImpl = &NeSoftwareImpl{
selectSql: `select
id, ne_type, name, path, version, description, create_by, create_time, update_by, update_time
id, type, name, path, version, description, create_by, create_time, update_by, update_time
from ne_software`,
resultMap: map[string]string{
"id": "ID",
"ne_type": "NeType",
"type": "Type",
"name": "Name",
"path": "Path",
"version": "Version",
@@ -60,9 +60,18 @@ func (r *NeSoftwareImpl) SelectPage(query map[string]any) map[string]any {
// 查询条件拼接
var conditions []string
var params []any
if v, ok := query["neType"]; ok && v != "" {
conditions = append(conditions, "ne_type = ?")
params = append(params, strings.Trim(v.(string), " "))
if v, ok := query["type"]; ok && v != "" {
softwareType := v.(string)
if strings.Contains(softwareType, ",") {
softwareTypeArr := strings.Split(softwareType, ",")
placeholder := repo.KeyPlaceholderByQuery(len(softwareTypeArr))
conditions = append(conditions, "type in ("+placeholder+")")
parameters := repo.ConvertIdsSlice(softwareTypeArr)
params = append(params, parameters...)
} else {
conditions = append(conditions, "type = ?")
params = append(params, strings.Trim(softwareType, " "))
}
}
if v, ok := query["name"]; ok && v != "" {
conditions = append(conditions, "name like concat(?, '%')")
@@ -122,9 +131,9 @@ func (r *NeSoftwareImpl) SelectList(neSoftware model.NeSoftware) []model.NeSoftw
// 查询条件拼接
var conditions []string
var params []any
if neSoftware.NeType != "" {
conditions = append(conditions, "ne_type = ?")
params = append(params, neSoftware.NeType)
if neSoftware.Type != "" {
conditions = append(conditions, "type = ?")
params = append(params, neSoftware.Type)
}
if neSoftware.Path != "" {
conditions = append(conditions, "path = ?")
@@ -175,9 +184,9 @@ func (r *NeSoftwareImpl) CheckUniqueTypeAndNameAndVersion(neSoftware model.NeSof
// 查询条件拼接
var conditions []string
var params []any
if neSoftware.NeType != "" {
conditions = append(conditions, "ne_type = ?")
params = append(params, neSoftware.NeType)
if neSoftware.Type != "" {
conditions = append(conditions, "type = ?")
params = append(params, neSoftware.Type)
}
if neSoftware.Version != "" {
conditions = append(conditions, "version = ?")
@@ -213,8 +222,8 @@ func (r *NeSoftwareImpl) CheckUniqueTypeAndNameAndVersion(neSoftware model.NeSof
func (r *NeSoftwareImpl) Insert(neSoftware model.NeSoftware) string {
// 参数拼接
params := make(map[string]any)
if neSoftware.NeType != "" {
params["ne_type"] = neSoftware.NeType
if neSoftware.Type != "" {
params["type"] = neSoftware.Type
}
if neSoftware.Name != "" {
params["name"] = neSoftware.Name
@@ -262,8 +271,8 @@ func (r *NeSoftwareImpl) Insert(neSoftware model.NeSoftware) string {
func (r *NeSoftwareImpl) Update(neSoftware model.NeSoftware) int64 {
// 参数拼接
params := make(map[string]any)
if neSoftware.NeType != "" {
params["ne_type"] = neSoftware.NeType
if neSoftware.Type != "" {
params["type"] = neSoftware.Type
}
if neSoftware.Name != "" {
params["name"] = neSoftware.Name

View File

@@ -47,7 +47,7 @@ func (r *NeSoftwareImpl) Insert(neSoftware model.NeSoftware) string {
inserId := r.neSoftwareRepository.Insert(neSoftware)
if inserId != "" {
// 更新同类型的新包版本
neVersions := NewNeVersionImpl.SelectList(model.NeVersion{NeType: neSoftware.NeType})
neVersions := NewNeVersionImpl.SelectList(model.NeVersion{NeType: neSoftware.Type})
if len(neVersions) > 0 {
for _, neVersion := range neVersions {
neVersion.NewName = neSoftware.Name
@@ -68,7 +68,7 @@ func (r *NeSoftwareImpl) Update(neSoftware model.NeSoftware) int64 {
if rows > 0 {
// 更新同类型的新包版本
neVersions := NewNeVersionImpl.SelectList(model.NeVersion{
NeType: neSoftware.NeType,
NeType: neSoftware.Type,
Status: "3",
})
if len(neVersions) > 0 {
@@ -112,9 +112,9 @@ func (r *NeSoftwareImpl) DeleteByIds(ids []string) (int64, error) {
}
// CheckUniqueTypeAndNameAndVersion 校验网元类型和文件名版本是否唯一
func (r *NeSoftwareImpl) CheckUniqueTypeAndNameAndVersion(neType, name, version, id string) bool {
func (r *NeSoftwareImpl) CheckUniqueTypeAndNameAndVersion(softwareType, name, version, id string) bool {
uniqueId := r.neSoftwareRepository.CheckUniqueTypeAndNameAndVersion(model.NeSoftware{
NeType: neType,
Type: softwareType,
Name: name,
Version: version,
})