sixian пре 2 година
родитељ
комит
6eb84270ca

+ 1 - 1
Makefile

@@ -8,7 +8,7 @@ clear:
 	@$(RM) ${BINARY}
 
 build:
-	@go build -o ${BINARY} ./
+	@go build -tags=jsoniter -o ${BINARY} ./
 
 push-test:clear build
 	@$(push_test)

+ 6 - 1
app/system/dao/user.go

@@ -6,7 +6,7 @@ import (
 
 // User 用户
 type User struct {
-	ID                      int64     `gorm:"primary_key" json:"id"`                            //编号
+	ID                      int64     `gorm:"primary_key;type:bigint" json:"id"`                //编号
 	TenantId                int       `gorm:"type:int" json:"tenantId"`                         //租户ID
 	Code                    string    `gorm:"type:varchar(12)" json:"code"`                     //用户编号
 	Account                 string    `gorm:"type:varchar(45)" json:"account"`                  //账号
@@ -30,6 +30,11 @@ type User struct {
 	BigScreenIndexCameraIds string    `gorm:"type:varchar(255)" json:"bigScreenIndexCameraIds"` //数据大屏中摄像头保存位置
 	SecuritySixScreen       string    `gorm:"type:varchar(255)" json:"securitySixScreen"`       //安防页面六分屏
 }
+type JsonInt64 int64
+
+func (ji *JsonInt64) UnmarshalJSON() {
+
+}
 
 func (User) TableName() string {
 	return "user"

Разлика између датотеке није приказан због своје велике величине
+ 46 - 5
app/warn/controller/notice_set_contoller.go


+ 46 - 1
app/warn/dao/notice_set_dao.go

@@ -1,6 +1,9 @@
 package dao
 
-import "gorm.io/gorm"
+import (
+	"errors"
+	"gorm.io/gorm"
+)
 
 // NoticeSet 告警通知设置
 type NoticeSet struct {
@@ -8,6 +11,7 @@ type NoticeSet struct {
 	TenantId            string `gorm:"comment:租户;default:0" json:"_"`                     //租户
 	DeviceType          int    `gorm:"comment:设备类型;default:0" json:"deviceType"`          //设备类型1-15
 	DeviceId            int    `gorm:"comment:设备ID;default:0" json:"deviceId"`            //设备ID
+	DeviceSn            string `gorm:"comment:设备sn;" json:"sn"`                           //设备sn
 	RType               int    `gorm:"comment:发送类型:0 - 全部 1按设备 2设备ID;" json:"deviceType"` //发送类型:0 - 全部设备 1 按设备类型 2按设备ID
 	DevUserIds          string `gorm:"comment:运维通知人员;" json:"devUserIds"`                 //运维通知人员
 	BusinessUserIds     string `gorm:"comment:业务通知人员;" json:"businessUserIds"`            //业务通知人员
@@ -23,3 +27,44 @@ type NoticeSet struct {
 func (NoticeSet) TableName() string {
 	return "warn_notice_set"
 }
+
+func (s *NoticeSet) UpdateOrSave() error {
+	noticeSet := NoticeSet{}
+	db := Db.Debug().Model(&noticeSet)
+	var err error
+	switch s.RType {
+	case 1:
+		err = db.Where(&NoticeSet{RType: 1, TenantId: s.TenantId}).First(&noticeSet).Error
+	case 2:
+		err = db.Where(&NoticeSet{RType: 2, TenantId: s.TenantId, DeviceType: s.DeviceType}).First(&noticeSet).Error
+	case 3:
+		err = db.Where(&NoticeSet{RType: 3, TenantId: s.TenantId, DeviceType: s.DeviceType, DeviceId: s.DeviceId}).First(&noticeSet).Error
+	default:
+		return errors.New("没有Rtype")
+	}
+	if noticeSet.ID == 0 {
+		err = Db.Debug().Model(&noticeSet).Save(s).Error
+	} else {
+		err = Db.Debug().Model(&noticeSet).Updates(s).Error
+	}
+	return err
+}
+
+func (s NoticeSet) GetList() ([]NoticeSet, error) {
+	var list []NoticeSet
+	err := Db.Debug().Model(&s).Where(&NoticeSet{TenantId: s.TenantId}).Find(&list).Error
+	return list, err
+}
+
+func (s NoticeSet) GetById() (NoticeSet, error) {
+	var data NoticeSet
+	err := Db.Debug().Model(&s).Where(&NoticeSet{DeviceSn: s.DeviceSn}).First(&data).Error
+	return data, err
+}
+
+func (s *NoticeSet) Delete() error {
+	err := Db.Debug().Where(&NoticeSet{
+		DeviceSn: s.DeviceSn,
+	}).Delete(&s).Error
+	return err
+}

+ 44 - 4
app/warn/model/notice_set_model.go

@@ -19,9 +19,49 @@ type NoticeSetRecords struct {
 	DeviceId                int                `json:"deviceId,omitempty"`
 	DeviceType              int                `json:"deviceType,omitempty"`
 	RtypeName               string             `json:"showName,omitempty"`
-	DevUserNoticeModesName  string             `json:"devUserNoticeModesName,omitempty"`
-	BusinessNoticeModesName string             `json:"businessNoticeModesName,omitempty"`
-	DevUserIdsName          string             `json:"devUserIdsName,omitempty"`
-	BusinessUserIdsName     string             `json:"businessUserIdsName,omitempty"`
+	DevUserNoticeModesName  string             `json:"showOperationTypeName,omitempty"`
+	BusinessNoticeModesName string             `json:"showBusinessTypeName,omitempty"`
+	DevUserIdsName          string             `json:"noticeOperationName,omitempty"`
+	DevUserIds              string             `json:"noticeOperationMan,omitempty"`
+	BusinessUserIdsName     string             `json:"noticeBusinessName,omitempty"`
+	BusinessUserIds         string             `json:"noticeBusinessMan,omitempty"`
 	Children                []NoticeSetRecords `json:"children,omitempty"`
 }
+
+// NoticeUpdateData 保存时的请求数据
+type NoticeUpdateData struct {
+	DeviceID               int    `json:"deviceId"`
+	DeviceType             int    `json:"deviceType"`
+	ID                     string `json:"id"`
+	NoticeBusinessMan      string `json:"noticeBusinessMan"`
+	NoticeBusinessType     string `json:"noticeBusinessType"`
+	NoticeOperationMan     string `json:"noticeOperationMan"`
+	NoticeOperationType    string `json:"noticeOperationType"`
+	Rtype                  int    `json:"rtype"`
+	ShowBusinessTypeName   string `json:"showBusinessTypeName"`
+	ShowName               string `json:"showName"`
+	ShowOperationTypeName  string `json:"showOperationTypeName"`
+	NoticeBusinessManName  string `json:"$noticeBusinessMan"`
+	NoticeOperationManName string `json:"$noticeOperationMan"`
+}
+
+type NoticeSetDetail struct {
+	ID                  string `json:"id"`
+	RidType             int    `json:"ridType"`
+	NoticeOperationType string `json:"noticeOperationType"`
+	NoticeBusinessType  string `json:"noticeBusinessType"`
+	NoticeOperationMan  string `json:"noticeOperationMan"`
+	NoticeBusinessMan   string `json:"noticeBusinessMan"`
+	CreateTime          string `json:"createTime"`
+	CreateUser          string `json:"createUser"`
+	UpdateTime          string `json:"updateTime"`
+	UpdateUser          string `json:"updateUser"`
+	TenantID            string `json:"tenantId"`
+	IsDeleted           int    `json:"isDeleted"`
+	Rid                 int    `json:"rid"`
+}
+
+type NoticeSetDUserList struct {
+	ID   string `json:"id"`
+	Name string `json:"name"`
+}

+ 144 - 19
app/warn/service/notice_set_service.go

@@ -1,9 +1,12 @@
 package service
 
 import (
+	"fmt"
+	systemService "iot_manager_service/app/system/service"
 	"iot_manager_service/app/warn/dao"
 	"iot_manager_service/app/warn/model"
 	"strconv"
+	"strings"
 )
 
 var NoticeSetService = new(noticeSetService)
@@ -11,44 +14,166 @@ var NoticeSetService = new(noticeSetService)
 type noticeSetService struct{}
 
 func (s noticeSetService) GetList(tenantId int, searchValue string) ([]model.NoticeSetRecords, error) {
-
 	code := dao.ViewsAllCode{TenantId: tenantId}
 	deviceTypeGroups, _ := code.GetGroupByDeviceType(searchValue)
 	var deviceTypeGroupsNew []model.NoticeSetRecords
+	noteiceSets := s.getNoteiceSets(tenantId)
 	for _, group := range deviceTypeGroups {
 
 		var deviceNew []model.NoticeSetRecords
 		code.DeviceType = group.DeviceType
 		devices, _ := code.GetDatasByDeviceType(searchValue)
 		for _, device := range devices {
+			key := strconv.Itoa(tenantId) + strconv.Itoa(3) + strconv.Itoa(device.DeviceType) + strconv.Itoa(device.DeviceId)
+			set := noteiceSets[key]
 			deviceNew = append(deviceNew, model.NoticeSetRecords{
-				Rtype:      3,
-				RtypeName:  device.DeviceName + "(" + device.Sn + ")",
-				DeviceType: device.DeviceType,
-				DeviceId:   device.DeviceId,
-				ID:         device.Sn,
+				Rtype:                   3,
+				RtypeName:               device.DeviceName + "(" + device.Sn + ")",
+				DeviceType:              device.DeviceType,
+				DeviceId:                device.DeviceId,
+				ID:                      device.Sn,
+				DevUserNoticeModesName:  set.DevUserNoticeModesName,
+				BusinessNoticeModesName: set.BusinessNoticeModesName,
+				DevUserIdsName:          set.DevUserIdsName,
+				BusinessUserIdsName:     set.BusinessUserIdsName,
+				DevUserIds:              set.DevUserIds,
+				BusinessUserIds:         set.BusinessUserIds,
 			})
 		}
-
+		key := strconv.Itoa(tenantId) + strconv.Itoa(2) + strconv.Itoa(group.DeviceType) + strconv.Itoa(999999)
+		//set.TenantId + strconv.Itoa(set.RType) + strconv.Itoa(set.DeviceType) + strconv.Itoa(set.DeviceId)
+		//fmt.Printf("key = %v", key)
+		//println("")
+		set := noteiceSets[key]
+		//fmt.Printf("set = %v", set)
 		deviceTypeGroupsNew = append(deviceTypeGroupsNew, model.NoticeSetRecords{
-			Rtype:      2,
-			RtypeName:  group.DeviceTypeName + "(" + strconv.Itoa(len(deviceNew)) + "台)",
-			Children:   deviceNew,
-			DeviceType: group.DeviceType,
-			DeviceId:   0,
-			ID:         strconv.Itoa(group.DeviceType),
+			Rtype:                   2,
+			RtypeName:               group.DeviceTypeName + "(" + strconv.Itoa(len(deviceNew)) + "台)",
+			Children:                deviceNew,
+			DeviceType:              group.DeviceType,
+			DeviceId:                0,
+			ID:                      strconv.Itoa(group.DeviceType),
+			DevUserNoticeModesName:  set.DevUserNoticeModesName,
+			BusinessNoticeModesName: set.BusinessNoticeModesName,
+			DevUserIdsName:          set.DevUserIdsName,
+			BusinessUserIdsName:     set.BusinessUserIdsName,
+			DevUserIds:              set.DevUserIds,
+			BusinessUserIds:         set.BusinessUserIds,
 		})
 	}
 
+	key := strconv.Itoa(tenantId) + strconv.Itoa(1) + strconv.Itoa(0) + strconv.Itoa(999999)
+	set := noteiceSets[key]
 	data := []model.NoticeSetRecords{
 		{
-			Rtype:      0,
-			RtypeName:  "全部设备",
-			Children:   deviceTypeGroupsNew,
-			DeviceType: 0,
-			DeviceId:   0,
-			ID:         "999999",
+			Rtype:                   0,
+			RtypeName:               "全部设备",
+			Children:                deviceTypeGroupsNew,
+			DeviceType:              0,
+			DeviceId:                0,
+			ID:                      "999999",
+			DevUserNoticeModesName:  set.DevUserNoticeModesName,
+			BusinessNoticeModesName: set.BusinessNoticeModesName,
+			DevUserIdsName:          set.DevUserIdsName,
+			BusinessUserIdsName:     set.BusinessUserIdsName,
+			DevUserIds:              set.DevUserIds,
+			BusinessUserIds:         set.BusinessUserIds,
 		},
 	}
+	//fmt.Printf("noteiceSets = %v", noteiceSets)
 	return data, nil
 }
+
+func (s noticeSetService) Update(post model.NoticeUpdateData, tenantId int) error {
+	rtype := post.Rtype
+	if rtype == 0 {
+		rtype = 1
+	}
+	deviceId := 999999
+	if rtype == 3 {
+		deviceId = post.DeviceID
+
+	}
+	set := dao.NoticeSet{
+		TenantId:                strconv.Itoa(tenantId),
+		DeviceType:              post.DeviceType,
+		DeviceId:                deviceId,
+		DeviceSn:                post.ID,
+		RType:                   rtype,
+		DevUserNoticeModes:      post.NoticeOperationType,
+		BusinessNoticeModes:     post.NoticeBusinessType,
+		DevUserNoticeModesName:  post.ShowOperationTypeName,
+		BusinessNoticeModesName: post.ShowBusinessTypeName,
+		DevUserIds:              post.NoticeOperationMan,
+		BusinessUserIds:         post.NoticeBusinessMan,
+
+		DevUserIdsName:      s.getUserName(post.NoticeOperationMan),
+		BusinessUserIdsName: s.getUserName(post.NoticeBusinessMan),
+	}
+	return set.UpdateOrSave()
+}
+
+func (s noticeSetService) getNoteiceSets(tenantId int) map[string]dao.NoticeSet {
+	noticeSet := dao.NoticeSet{TenantId: strconv.Itoa(tenantId)}
+	list, _ := noticeSet.GetList()
+	news := make(map[string]dao.NoticeSet)
+	for _, set := range list {
+		key := set.TenantId + strconv.Itoa(set.RType) + strconv.Itoa(set.DeviceType) + strconv.Itoa(set.DeviceId)
+		fmt.Printf("xxxkey = %v", key)
+		set.BusinessUserIdsName = strings.ReplaceAll(set.BusinessUserIdsName, " | ", ",")
+		set.DevUserIdsName = strings.ReplaceAll(set.DevUserIdsName, " | ", ",")
+		news[key] = set
+	}
+	return news
+}
+
+func (s noticeSetService) GetById(id string) (*model.NoticeSetDetail, error) {
+	noticeSet := dao.NoticeSet{DeviceSn: id}
+	data, err := noticeSet.GetById()
+	if err != nil {
+		return nil, err
+	}
+	detail := &model.NoticeSetDetail{
+		ID:                  data.DeviceSn,
+		RidType:             data.RType,
+		NoticeOperationType: data.DevUserNoticeModes,
+		NoticeBusinessType:  data.BusinessNoticeModes,
+		NoticeOperationMan:  data.DevUserIds,
+		NoticeBusinessMan:   data.BusinessUserIds,
+	}
+
+	return detail, nil
+}
+
+func (s noticeSetService) UserList(account string, name string, current int, size int) ([]model.NoticeSetDUserList, error) {
+	var list []model.NoticeSetDUserList
+	userList, _ := systemService.UserService.List(account, name, current, size)
+	for _, user := range userList {
+		idStr := strconv.Itoa(int(user.ID))
+		list = append(list, model.NoticeSetDUserList{ID: idStr, Name: user.Name})
+	}
+	return list, nil
+}
+
+func (s noticeSetService) getUserName(ids string) string {
+	split := strings.Split(ids, ",")
+	fm := make(map[string]int)
+	for i, v := range split {
+		fm[v] = i
+	}
+	userList, _ := systemService.UserService.List("", "", 0, 1000)
+	new := []string{}
+	for _, detail := range userList {
+		id := strconv.Itoa(int(detail.ID))
+		if _, ok := fm[id]; ok {
+			new = append(new, detail.Name)
+		}
+	}
+	return strings.Join(new, ",")
+}
+
+func (s noticeSetService) Remove(id string, tenant_id int) error {
+	fmt.Printf("id = %v", id)
+	noticeSet := dao.NoticeSet{DeviceSn: id, TenantId: strconv.Itoa(tenant_id)}
+	return noticeSet.Delete()
+}

+ 2 - 0
router/router.go

@@ -563,6 +563,8 @@ func InitRouter(engine *gin.Engine) {
 		noticeGroup := warnGroup.Group("notice")
 		{
 			noticeGroup.GET("/list", warn.NoticeSet.List)
+			noticeGroup.POST("/update", warn.NoticeSet.Update)
+			noticeGroup.POST("/remove", warn.NoticeSet.Remove)
 			noticeGroup.GET("/detail", warn.NoticeSet.Detail)
 			noticeGroup.GET("/getUserList", warn.NoticeSet.GetUserList)
 		}