|
@@ -0,0 +1,103 @@
|
|
|
+package service
|
|
|
+
|
|
|
+import (
|
|
|
+ "fmt"
|
|
|
+ "iot_manager_service/app/dao"
|
|
|
+ "iot_manager_service/app/utils"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+var GarbageWayGroupService = new(garbageWayGroupService)
|
|
|
+
|
|
|
+type garbageWayGroupService struct{}
|
|
|
+
|
|
|
+func (s *garbageWayGroupService) Get(id int) (*dao.GarbageWayGroup, *utils.Errors) {
|
|
|
+ // 创建查询实例
|
|
|
+ device := &dao.GarbageWayGroup{
|
|
|
+ ID: id,
|
|
|
+ }
|
|
|
+ err := device.GetDevice()
|
|
|
+ if err != nil {
|
|
|
+ return nil, utils.FailResponse(err.Error(), nil)
|
|
|
+ }
|
|
|
+ return device, nil
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+func (s *garbageWayGroupService) CreateOrUpdate(req dao.GarbageWayGroup) *utils.Errors {
|
|
|
+ // 创建查询实例
|
|
|
+ device := req
|
|
|
+ if req.ID == 0 {
|
|
|
+ device.CreateTime = time.Now()
|
|
|
+ device.CreateUser = "TODO" // todo: 使用登录态
|
|
|
+ if device.IsExistedByName() {
|
|
|
+ fmt.Printf("Create GetDeviceID err \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() {
|
|
|
+ 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 *garbageWayGroupService) List(searchValue string, current, size int) ([]dao.GarbageWayGroup, *utils.Errors) {
|
|
|
+ device := dao.GarbageWayGroup{}
|
|
|
+ //if searchValue != "" {
|
|
|
+ // device.TransSN = searchValue
|
|
|
+ // device.TransName = searchValue
|
|
|
+ //}
|
|
|
+
|
|
|
+ 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 *garbageWayGroupService) Remove(id int) *utils.Errors {
|
|
|
+ // 创建查询实例
|
|
|
+ device := &dao.GarbageWayGroup{
|
|
|
+ ID: id,
|
|
|
+ IsDeleted: 1,
|
|
|
+ UpdateUser: "TODO", // todo 使用登录态
|
|
|
+ UpdateTime: time.Now(),
|
|
|
+ }
|
|
|
+ //todo
|
|
|
+ // service.transformerService.CountRelation()
|
|
|
+
|
|
|
+ //todo operation record
|
|
|
+ err := device.Delete()
|
|
|
+ if err != nil {
|
|
|
+ return utils.FailResponse(err.Error(), nil)
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
+func (s *garbageWayGroupService) GetList() ([]*dao.GarbageWayGroup, *utils.Errors) {
|
|
|
+ // todo use redis cache
|
|
|
+ device := &dao.GarbageWayGroup{
|
|
|
+ TenantId: "000000", // todo 使用登录态
|
|
|
+ IsDeleted: 0,
|
|
|
+ }
|
|
|
+ devices, err := device.GetAllDevices()
|
|
|
+ if err != nil {
|
|
|
+ return nil, utils.FailResponse(err.Error(), nil)
|
|
|
+ }
|
|
|
+
|
|
|
+ return devices, nil
|
|
|
+}
|