123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- package service
- import (
- deviceModel "iot_manager_service/app/device/model"
- "iot_manager_service/app/multimedia/dao"
- "iot_manager_service/app/multimedia/model"
- "iot_manager_service/app/system/service"
- "iot_manager_service/util/common"
- "iot_manager_service/util/logger"
- "time"
- )
- var ProgramService = new(programService)
- type programService struct{}
- func (s *programService) Get(id int) (*dao.Program, *common.Errors) {
- Program := &dao.Program{
- ID: id,
- }
- err := Program.Get()
- if err != nil {
- return nil, common.FailResponse(err.Error(), nil)
- }
- return Program, nil
- }
- func (s *programService) List(tenantId int, searchValue string, current, size, sysType int) ([]model.ProgramDetail,
- *common.Errors) {
- program := &dao.Program{
- TenantId: tenantId,
- }
- offset := (current - 1) * size
- limit := size
- if searchValue != "" {
- program.Name = searchValue
- }
- if sysType != -1 {
- program.SysType = sysType
- }
- programs, err := program.GetPrograms(offset, limit)
- if err != nil {
- return nil, common.FailResponse(err.Error(), nil)
- }
- var rsp []model.ProgramDetail
- for _, pro := range programs {
- rsp = append(rsp, model.ProgramDetail{
- Program: pro,
- ResolutionName: service.DictService.GetResolutionName(tenantId, pro.Resolution),
- })
- }
- return rsp, nil
- }
- func (s *programService) Remove(userId int64, tenantId int, id int) *common.Errors {
- relation := &dao.ProgramRelation{
- ProgramId: id,
- TenantId: tenantId,
- IsDeleted: 1,
- }
- err := relation.Delete()
- if err != nil {
- return common.FailResponse(err.Error(), nil)
- }
- program := &dao.Program{
- ID: id,
- IsDeleted: 1,
- UpdateUser: userId,
- UpdateTime: time.Now(),
- }
- err = program.Delete()
- if err != nil {
- return common.FailResponse(err.Error(), nil)
- }
- service.OperationHisService.Save(userId, tenantId, common.OperationRemove, common.ModuleTypeInfoBar,
- common.DeviceTypeDefault, "", common.OperationSuccess)
- return nil
- }
- func (s *programService) GetList(tenantId int, name string) ([]dao.Program, *common.Errors) {
- Program := &dao.Program{
- TenantId: tenantId,
- Name: name,
- }
- libraries, err := Program.GetAll()
- if err != nil {
- return nil, common.FailResponse(err.Error(), nil)
- }
- return libraries, nil
- }
- func (s *programService) Submit(tenantId int, userId int64, req model.ReqProgramSubmit) *common.Errors {
- program := &dao.Program{
- Name: req.Name,
- Resolution: req.Resolution,
- Duration: req.Duration,
- FileSize: req.FileSize,
- ImgDuration: req.ImgDuration,
- Remarks: req.Remarks,
- TenantId: tenantId,
- CreateTime: time.Now(),
- CreateUser: userId,
- UpdateTime: time.Now(),
- UpdateUser: userId,
- IsDeleted: 0,
- }
- if err := program.Create(); err != nil {
- logger.Logger.Errorf("Create err = %s \n", err.Error())
- return common.FailResponse(err.Error(), nil)
- }
- libraryIds := common.StringToIntArray(req.LibraryIds)
- for index, libraryId := range libraryIds {
- relation := &dao.ProgramRelation{
- ProgramId: program.ID,
- LibraryId: libraryId,
- OrderNo: index + 1,
- TenantId: tenantId,
- IsDeleted: 0,
- }
- err := relation.Save()
- if err != nil {
- logger.Logger.Errorf("relation save err = %s \n", err.Error())
- _ = program.Remove()
- _ = relation.Remove()
- return common.FailResponse(err.Error(), nil)
- }
- }
- service.OperationHisService.Save(userId, tenantId, common.OperationCreate, common.ModuleTypeInfoBar,
- common.DeviceTypeDefault, program.Name, common.OperationSuccess)
- return common.SuccessResponse(common.Succeeded, nil)
- }
- func (s *programService) GetLibraryList(tenantId, programId int) ([]dao.Library, *common.Errors) {
- relation := &dao.ProgramRelation{
- ProgramId: programId,
- TenantId: tenantId,
- }
- relations, err := relation.GetByProgram()
- if err != nil {
- logger.Logger.Errorf("relation BatchCreate err = %s \n", err.Error())
- return nil, common.FailResponse(err.Error(), nil)
- }
- var libraryIds []int
- for _, relation := range relations {
- libraryIds = append(libraryIds, relation.LibraryId)
- }
- library := &dao.Library{TenantId: tenantId}
- libraries, err := library.GetLibrariesByIds(libraryIds)
- if err != nil {
- logger.Logger.Errorf("GetLibrariesByIds err = %s \n", err.Error())
- return nil, common.FailResponse(err.Error(), nil)
- }
- return libraries, nil
- }
- func (s *programService) RelationDeviceList(tenantId, resolution int) ([]deviceModel.LampPoleGroupDetail,
- *common.Errors) {
- return nil, nil
- }
|