12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- // Copyright 2019 github.com. All rights reserved.
- // Use of this source code is governed by github.com.
- package device
- import (
- "context"
- "github.com/jaryhe/gopkgs/database"
- "smart-government-management/consts"
- "smart-government-management/errors"
- "smart-government-management/model"
- "smart-government-management/pb/v1"
- "github.com/jaryhe/gopkgs/logger"
- "go.uber.org/zap"
- )
- func DeviceList(ctx context.Context, req *v1.DeviceListRequest) (reply *v1.DeviceListReply, err error) {
- reply = &v1.DeviceListReply{}
- /*
- where := map[string]interface{}{
- "provider_id":req.ProviderId,
- }
- if len(req.StatusFilters) > 0 {
- where["verify_status in"] = req.StatusFilters
- }*/
- p := &model.TDevice{}
- if req.Page < 1 {
- req.Page = 1
- }
- pt := &model.TDeviceTypeItem{}
- m, _, err := pt.AllMap(database.DB())
- if err != nil {
- logger.Error("DeviceList",
- zap.String("err", err.Error()))
- return nil, errors.DataBaseError
- }
- dbReq := model.ListRawRequest{
- Page:req.Page,
- ProjectId:req.ProjectId,
- ProviderId:req.ProviderId,
- Filter:req.Filter,
- StatusFilter:req.StatusFilters,
- IsAll:req.IsAll,
- CanDel:req.CanDel,
- TypeCode:req.TypeCode,
- }
- list, total, err := p.ListRaw(database.DB(), dbReq)
- if err != nil {
- logger.Error("DeviceList",
- zap.String("err", err.Error()))
- return nil, errors.DataBaseError
- }
- reply.Page = req.Page
- reply.Total = total
- reply.PageSize = int32(model.PageSize)
- if total == 0 {
- return reply, nil
- }
- reply.List = make([]*v1.DeviceItem, len(list))
- for i, v := range list{
- item := &v1.DeviceItem{
- Id: int64(v.Id),
- Sn: v.Sn,
- TypeCode: v.TypeCode,
- TypeName: m[v.TypeCode],
- ProjectName: v.ProjectName,
- SafetyRecordNo: v.SafetyRecordNo,
- ApplyTime: v.CreatedTime.Format(layout),
- Status:v.Status,
- State:v.State,
- Key:v.Key,
- ProviderName:v.ProviderName,
- SocialCode:v.SocialCode,
- Name:v.Name,
- Lon:v.Lon,
- Lat:v.Lat,
- }
- if item.Status == consts.DeviceStatusAddAuditted ||
- item.Status == consts.DeviceStatusAddAudittedFail {
- item.ApproveTime = v.ProjectApproveTime.Format(layout)
- }
- reply.List[i] = item
- }
- reply.Page = req.Page
- reply.Total = total
- reply.PageSize = int32(model.PageSize)
- return reply, nil
- }
|