1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- package service
- import (
- "fmt"
- "iot_manager_service/app/device/dao"
- "iot_manager_service/util"
- "time"
- )
- var InfoBoardService = new(infoBoardService)
- type infoBoardService struct{}
- func (s *infoBoardService) Get(id int) (*dao.InfoBoard, *util.Errors) {
- // 创建查询实例
- device := &dao.InfoBoard{
- ID: id,
- }
- err := device.GetDevice()
- if err != nil {
- return nil, util.FailResponse(err.Error(), nil)
- }
- return device, nil
- }
- func (s *infoBoardService) CreateOrUpdate(userId int64, tenantId int, req dao.InfoBoard) *util.Errors {
- // 创建查询实例
- device := req
- device.TenantId = tenantId
- device.UpdateUser = userId
- device.UpdateTime = time.Now()
- if req.ID == 0 {
- device.CreateTime = time.Now()
- device.CreateUser = userId
- if device.IsExistedBySN() {
- fmt.Printf("Create GetDeviceID err \n")
- return util.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
- }
- if err := device.Create(); err != nil {
- fmt.Printf("Create err = %s \n", err.Error())
- return util.FailResponse(err.Error(), nil)
- }
- return util.SuccessResponse(util.Succeeded, nil)
- }
- if device.IsExistedByNameAndCode() {
- return util.ParamsInvalidResponse("编码不能重复,请重新填写!", nil)
- }
- if err := device.Update(); err != nil {
- fmt.Printf("Update err = %s \n", err.Error())
- return util.FailResponse(err.Error(), nil)
- }
- //todo operation record
- return util.SuccessResponse(util.Succeeded, nil)
- }
- func (s *infoBoardService) List(searchValue string, current, size int) ([]dao.InfoBoard, *util.Errors) {
- device := dao.InfoBoard{}
- if searchValue != "" {
- device.SN = searchValue
- device.InfoName = searchValue
- }
- offset := (current - 1) * size
- limit := size
- devices, err := device.GetDevices(offset, limit)
- if err != nil {
- return nil, util.FailResponse(err.Error(), nil)
- }
- return devices, nil
- }
- func (s *infoBoardService) Remove(userId int64, id int) *util.Errors {
- // 创建查询实例
- device := &dao.InfoBoard{
- ID: id,
- IsDeleted: 1,
- UpdateUser: userId,
- UpdateTime: time.Now(),
- }
- //todo
- // service.transformerService.CountRelation()
- //todo operation record
- err := device.Delete()
- if err != nil {
- return util.FailResponse(err.Error(), nil)
- }
- return nil
- }
|