123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- package service
- import (
- "fmt"
- "iot_manager_service/app/dao"
- "iot_manager_service/app/utils"
- "time"
- )
- // 中间件管理服务
- var LampPoleGroupService = new(lampPoleGroupService)
- type lampPoleGroupService struct{}
- func (s *lampPoleGroupService) Get(id int) (*dao.LampPoleGroup, *utils.Errors) {
- // 创建查询实例
- device := &dao.LampPoleGroup{
- ID: id,
- }
- err := device.GetDevice()
- if err != nil {
- return nil, utils.FailResponse(err.Error(), nil)
- }
- return device, nil
- }
- func (s *lampPoleGroupService) CreateOrUpdate(req *dao.LampPoleGroup) *utils.Errors {
- device := req
- if device.TenantId == "" {
- device.TenantId = "000000" // todo: 使用登录态
- }
- if req.ID == 0 {
- device.CreateTime = time.Now()
- device.CreateUser = "TODO" // todo: 使用登录态
- if device.IsExistedByName() {
- fmt.Printf("Create IsExistedByName \n")
- return utils.ParamsInvalidResponse("列表中存在重名,请更改灯杆分组名称!", nil)
- }
- if err := device.Create(); err != nil {
- fmt.Printf("Create err = %s \n", err.Error())
- return utils.FailResponse(err.Error(), nil)
- }
- return utils.SuccessResponse(utils.Succeeded, nil)
- }
- device.UpdateUser = "TODO" // todo: 使用登录态
- device.UpdateTime = time.Now()
- if device.IsExistedByNameAndCode() {
- fmt.Printf("Update IsExistedByNameAndCode \n")
- return utils.ParamsInvalidResponse("列表中存在重名,请更改灯杆分组名称!", nil)
- }
- if err := device.Update(); err != nil {
- fmt.Printf("Update err = %s \n", err.Error())
- return utils.FailResponse(err.Error(), nil)
- }
- //todo operation record
- return utils.SuccessResponse(utils.Succeeded, nil)
- }
- func (s *lampPoleGroupService) List(poleGroupName string, current, size int) ([]dao.LampPoleGroup, *utils.Errors) {
- // 创建查询实例
- device := &dao.LampPoleGroup{
- PoleGroupName: poleGroupName,
- }
- offset := (current - 1) * size
- limit := size
- devices, err := device.GetDevices(offset, limit)
- if err != nil {
- return nil, utils.FailResponse(err.Error(), nil)
- }
- return devices, nil
- }
- func (s *lampPoleGroupService) Remove(id int) *utils.Errors {
- // 创建查询实例
- device := &dao.LampPoleGroup{
- ID: id,
- IsDeleted: 1,
- UpdateUser: "TODO", // todo 使用登录态
- UpdateTime: time.Now(),
- }
- //todo
- // service.lampPoleService.CountRelation()
- //todo operation record
- err := device.Delete()
- if err != nil {
- return utils.FailResponse(err.Error(), nil)
- }
- return nil
- }
- func (s *lampPoleGroupService) GetList() ([]dao.LampPoleGroup, *utils.Errors) {
- // todo use redis cache
- device := &dao.LampPoleGroup{
- TenantId: "000000", // todo 使用登录态
- IsDeleted: 0,
- }
- devices, err := device.GetAllDevices()
- if err != nil {
- return nil, utils.FailResponse(err.Error(), nil)
- }
- return devices, nil
- }
- func (s *lampPoleGroupService) GetFiltration() ([]dao.LampPoleGroup, *utils.Errors) {
- // todo use redis cache
- device := &dao.LampPoleGroup{
- TenantId: "000000", // todo 使用登录态
- IsDeleted: 0,
- }
- //todo
- // get t_dev_light_control group_id
- // groupIds := lightControl.GetGroupIds()
- devices, err := device.GetAllDevices()
- if err != nil {
- return nil, utils.FailResponse(err.Error(), nil)
- }
- return devices, nil
- }
- func (s *lampPoleGroupService) GetTree() ([]dao.LampPoleGroup, *utils.Errors) {
- // todo use redis cache
- device := &dao.LampPoleGroup{
- TenantId: "000000", // todo 使用登录态
- IsDeleted: 0,
- }
- //todo lampPole getALlDevice
- devices, err := device.GetAllDevices()
- if err != nil {
- return nil, utils.FailResponse(err.Error(), nil)
- }
- return devices, nil
- }
|