123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- // 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"
- "github.com/jinzhu/gorm"
- "smart-government-management/errors"
- dbmodel "smart-government-management/model"
- pb_v1 "smart-government-management/pb/v1"
- "github.com/jaryhe/gopkgs/logger"
- "go.uber.org/zap"
- )
- var layout = "2006-01-02 15:04:05"
- func ProviderList(ctx context.Context, req *pb_v1.ProviderListRequest)(reply *pb_v1.ProviderListReply, err error) {
- p := &dbmodel.TProvider{}
- and := map[string]interface{}{}
- or := map[string]interface{}{}
- if req.Filter != "" {
- or["name like"] = "%"+req.Filter+"%"
- or["social_code like"] = "%"+req.Filter+"%"
- }
- if len(req.FilterStatus) > 0 {
- and["status in"] = req.FilterStatus
- }
- total, err := p.Count(database.DB(), and, or)
- if err != nil {
- logger.Error("ProviderList",
- zap.String("err", err.Error()))
- return nil, errors.DataBaseError
- }
- reply = &pb_v1.ProviderListReply{
- Total:total,
- Page:req.Page,
- PageSize:int32(dbmodel.PageSize),
- }
- if total == 0 {
- return reply, nil
- }
- list, err := p.List(database.DB(), and, or, req.Page)
- if err != nil && err != gorm.ErrRecordNotFound{
- logger.Error("ProviderList",
- zap.String("err", err.Error()))
- return nil, errors.DataBaseError
- }
- reply.List = make([]*pb_v1.ProviderItem, len(list))
- for i, v := range list {
- reply.List[i] = &pb_v1.ProviderItem{}
- reply.List[i].Id = v.Id
- reply.List[i].Name = v.Name
- reply.List[i].SocialCode = v.SocialCode
- reply.List[i].ApplyTime = v.CreatedAt.Format(layout)
- reply.List[i].Status = v.Status
- reply.List[i].BusinessContact = v.BusinessContact
- reply.List[i].BusinessContactPhone = v.BusinessContactPhone
- reply.List[i].Feedback = v.Feedback
- reply.List[i].EmergencyContactPhone = v.EmergencyContactPhone
- reply.List[i].EmergencyContact = v.EmergencyContact
- reply.List[i].IdCert = v.IdCert
- reply.List[i].BusinessResponsiblePhone = v.BusinessResponsiblePhone
- reply.List[i].BusinessResponsible = v.BusinessResponsible
- if v.EnterpriseLocation == 0 {
- reply.List[i].EnterpriseLocation = "省内"
- } else {
- reply.List[i].EnterpriseLocation = "省外"
- }
- reply.List[i].UserName = v.UserName
- reply.List[i].LegalPerson = v.LegalPerson
- if v.BusinessLicense != "" {
- reply.List[i].BusinessLicense = v.BusinessLicense
- } else {
- reply.List[i].BusinessLicense = "[]"
- }
- if v.BusinessResponsibleLetter != "" {
- reply.List[i].BusinessResponsibleLetter = v.BusinessResponsibleLetter
- } else {
- reply.List[i].BusinessResponsibleLetter = "[]"
- }
- if v.IntegrityManagementLetter != "" {
- reply.List[i].IntegrityManagementLetter = v.IntegrityManagementLetter
- } else {
- reply.List[i].IntegrityManagementLetter = "[]"
- }
- if v.LegalPersonLetter != "" {
- reply.List[i].LegalPersonLetter = v.LegalPersonLetter
- } else {
- reply.List[i].LegalPersonLetter = "[]"
- }
- if v.Status == 1 || v.Status == 2 {
- reply.List[i].ApproveTime = v.ApproveTime.Format(layout)
- }
- }
- return reply, nil
- }
|