liujiandao
2023-11-18 115bd9b51f5d8eade4658f844de37516486c60e7
api/v1/code.go
@@ -1,7 +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"
@@ -10,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
//
@@ -53,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),
@@ -71,3 +71,66 @@
      Count: list.Total,
   })
}
// GetAutoCode
//
// @Tags      编码
// @Summary   获取自动编码
// @Produce   application/json
// @Param      object   body      code.CodeStandard   true   "参数"
// @Success   200   {object}   response.ListResponse
//
//   @Router      /api/code/getAutoCode [post]
func (ca *CodeApi) GetAutoCode(c *gin.Context) {
   var params code.CodeStandard
   ctx, ok := contextx.NewContext(c, &params)
   if !ok {
      return
   }
   var (
      id  = 0
      err error
   )
   switch constvar.CodeStandardType(params.Type) {
   case constvar.CodeStandardTypeSaleKey:
      id, err = model.NewSaleChanceSearch().MaxAutoIncr()
   case constvar.CodeStandardTypeSaleLead:
      id, err = model.NewSalesLeadsSearch(nil).MaxAutoIncr()
   case constvar.CodeStandardTypeCustom:
      id, err = model.NewClientSearch(nil).MaxAutoIncr()
   case constvar.CodeStandardTypeFollowRecord:
      id, err = model.NewFollowRecordSearch().MaxAutoIncr()
   case constvar.CodeStandardTypeQuotation:
      id, err = model.NewQuotationSearch(nil).MaxAutoIncr()
   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()
   case constvar.CodeStandardTypeSaleReturnGoods:
      id, err = model.NewSalesReturnSearch().MaxAutoIncr()
   case constvar.CodeStandardTypeSaleRefund:
      id, err = model.NewSalesRefundSearch().MaxAutoIncr()
   case constvar.CodeStandardTypeContract:
      id, err = model.NewContractSearch().MaxAutoIncr()
   case constvar.CodeStandardTypeServerContract:
      id, err = model.NewServiceContractSearch().MaxAutoIncr()
   case constvar.CodeStandardTypeCustomServer:
      id, err = model.NewServiceOrderSearch().MaxAutoIncr()
   case constvar.CodeStandardTypeServerFollow:
      id, err = model.NewServiceFollowupSearch().MaxAutoIncr()
   case constvar.CodeStandardTypeSaleInvoice:
      id, err = model.NewInvoiceSearch().MaxAutoIncr()
   default:
      ctx.FailWithMsg(ecode.UnknownErr, "编码规则不存在")
      return
   }
   if err != nil {
      logx.Errorf("GetAutoCode err: %v", err.Error())
      ctx.FailWithMsg(ecode.UnknownErr, "获取最大值失败")
      return
   }
   autoCode := model.GetAutoCode(id, &params)
   ctx.OkWithDetailed(autoCode)
}