123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- // Copyright 2019 githup.com. All rights reserved.
- // Use of this source code is governed by githup.com.
- package provider
- import (
- "context"
- "github.com/jaryhe/gopkgs/database"
- "smart-government-management/consts"
- "smart-government-management/errors"
- dbmodel "smart-government-management/model"
- pb_v1 "smart-government-management/pb/v1"
- )
- func Publicity(ctx context.Context, req *pb_v1.PublicityRequest)(reply *pb_v1.PublicityReply, err error) {
- // 设备类型map
- pdt := &dbmodel.TDeviceTypeItem{}
- m, _, err := pdt.AllMap(database.DB())
- if err != nil {
- return nil, errors.DataBaseError
- }
- // 供应商公示列表
- reply = &pb_v1.PublicityReply{}
- list, total, err := dbmodel.PublicityList(database.DB(), req.Provider)
- if err != nil {
- return nil, errors.DataBaseError
- }
- if total == 0 {
- return reply, nil
- }
- // 设配类型
- pids := make([]int64, len(list))
- for i, v := range list {
- pids[i] = v.Id
- }
- pt := dbmodel.TProviderDevice{}
- where := map[string]interface{}{
- "provider_id in":pids,
- "status":consts.DeviceTypeStatusAddAuditted,
- }
- if req.DeviceCode > 0 {
- where["device_code"] = req.DeviceCode
- }
- dlist, err := pt.List(database.DB(), where)
- if err != nil {
- return nil, errors.DataBaseError
- }
- dmap := map[int64][]dbmodel.TProviderDevice{}
- for _, v := range dlist {
- dmap[v.ProviderId] = append(dmap[v.ProviderId], v)
- }
- // 组装结果
- reply.List = make([]*pb_v1.PublicityItem, len(list))
- for i, v := range list {
- item := &pb_v1.PublicityItem{
- Name:v.Name,
- SocialCode:v.SocialCode,
- }
- if len(dmap[v.Id]) == 0 {
- continue
- }
- if dsublist, ok := dmap[v.Id]; ok {
- for _, value := range dsublist {
- subItem := &pb_v1.PublicityDeviceTypeItem{
- TypeCode:value.DeviceCode,
- TypeName:m[value.DeviceCode],
- }
- item.Devices = append(item.Devices, subItem)
- }
- }
- reply.List[i] = item
- }
- return reply, nil
- }
|