liujiandao
2023-12-22 28d04b70a786c5084ddceb12f6cc34b5702e0d36
api/v1/code.go
@@ -1,9 +1,9 @@
package v1
import (
   "aps_crm/conf"
   "aps_crm/constvar"
   "aps_crm/model"
   "aps_crm/model/grpc_init"
   "aps_crm/model/request"
   "aps_crm/model/response"
   "aps_crm/pkg/contextx"
@@ -12,30 +12,28 @@
   "aps_crm/proto/code"
   "github.com/gin-gonic/gin"
   "github.com/spf13/cast"
   "google.golang.org/grpc"
   "google.golang.org/grpc/credentials/insecure"
)
type CodeApi struct{}
var (
   codeServiceConn *grpc.ClientConn
)
func InitCodeServiceConn() {
   var err error
   codeServiceConn, err = grpc.Dial(conf.Conf.GrpcServiceAddr.Aps, grpc.WithTransportCredentials(insecure.NewCredentials()))
   if err != nil {
      logx.Errorf("grpc dial product service error: %v", err.Error())
      return
   }
}
func CloseCodeServiceConn() {
   if codeServiceConn != nil {
      codeServiceConn.Close()
   }
}
//var (
//   codeServiceConn *grpc.ClientConn
//)
//
//func InitCodeServiceConn() {
//   var err error
//   codeServiceConn, err = grpc.Dial(conf.Conf.GrpcServiceAddr.Aps, grpc.WithTransportCredentials(insecure.NewCredentials()))
//   if err != nil {
//      logx.Errorf("grpc dial product service error: %v", err.Error())
//      return
//   }
//}
//
//func CloseCodeServiceConn() {
//   if codeServiceConn != nil {
//      codeServiceConn.Close()
//   }
//}
// GetCodeList
//
@@ -55,7 +53,7 @@
   params.CodeStandID = c.Query("codeStandID")
   params.Name = c.Query("name")
   params.Type = c.Query("type")
   client := code.NewCodeServiceClient(codeServiceConn)
   client := code.NewCodeServiceClient(grpc_init.CrmApsGrpcServiceConn)
   list, err := client.GetCodeList(ctx.GetCtx(), &code.GetCodeListRequest{
      Page:        cast.ToInt32(params.Page),
      PageSize:    cast.ToInt32(params.PageSize),
@@ -104,12 +102,39 @@
      id, err = model.NewFollowRecordSearch().MaxAutoIncr()
   case constvar.CodeStandardTypeQuotation:
      id, err = model.NewQuotationSearch(nil).MaxAutoIncr()
      //报价单是否必须关联销售机会
      first, err := model.NewSystemSetSearch().SetName("报价单是否必须关联销售机会").First()
      if err == nil {
         if first.Value == "是" {
            c.Writer.Header().Set("Xsjh", "yes")
         } else {
            c.Writer.Header().Set("Xsjh", "no")
         }
      }
   case constvar.CodeStandardTypeSaleTotalOrder:
      id, err = model.NewMasterOrderSearch().MaxAutoIncr()
   case constvar.CodeStandardTypeSaleSuborder:
      id, err = model.NewSubOrderSearch(nil).MaxAutoIncr()
   case constvar.CodeStandardTypeSaleDetail:
      id, err = model.NewSalesDetailsSearch().MaxAutoIncr()
      //销售明细单是否必须关联报价单
      first, err := model.NewSystemSetSearch().SetName("销售明细单是否必须关联报价单").First()
      if err == nil {
         if first.Value == "是" {
            c.Writer.Header().Set("Bjd", "yes")
         } else {
            c.Writer.Header().Set("Bjd", "no")
         }
      }
      //销售明细单是否必须关联业务机会
      first, err = model.NewSystemSetSearch().SetName("销售明细单是否必须关联业务机会").First()
      if err == nil {
         if first.Value == "是" {
            c.Writer.Header().Set("Ywjh", "yes")
         } else {
            c.Writer.Header().Set("Ywjh", "no")
         }
      }
   case constvar.CodeStandardTypeSaleReturnGoods:
      id, err = model.NewSalesReturnSearch().MaxAutoIncr()
   case constvar.CodeStandardTypeSaleRefund: