Parcourir la source

fix:修复bug

liuyaqi il y a 2 ans
Parent
commit
1813389d15

+ 1 - 1
opms_parent/app/handler/cust/customer.go

@@ -247,7 +247,7 @@ func (c *CustomerHeader) Export(ctx context.Context, req *model.CustCustomerExpo
 	if err != nil {
 		return err
 	} //Export
-	buffer, err := customerServer.Export(req)
+	buffer, err := customerServer.Export(ctx, req)
 	if err != nil {
 		return err
 	}

+ 18 - 19
opms_parent/app/model/cust/cust_customer.go

@@ -46,25 +46,24 @@ type CustExport struct {
 
 //CustomerAddSeq 单表添加客户信息表
 type CustomerAddSeq struct {
-	CustName         string      `p:"custName"        json:"custName"      v:"required#客户名称不能为空"` // 客户名称
-	AbbrName         string      `p:"abbrName"        json:"abbrName"   `                         // 助计名
-	CustLocation     string      `p:"custLocation"    json:"custLocation"    `                    // 所在地区
-	CustAddress      string      `p:"custAddress"     json:"custAddress"   `                      // 详细地址
-	CustProvinceId   int         `json:"custProvinceId"`                                          // 所在省ID
-	CustProvince     string      `json:"custProvince"`                                            // 所在省
-	CustCityId       int         `json:"custCityId"`                                              // 所在市ID
-	CustCity         string      `json:"custCity"`                                                // 所在市
-	CustRegionId     int         `json:"custRegionId"`                                            // 所在区县ID
-	CustRegion       string      `json:"custRegion"`                                              // 所在区县
-	FollowUpDate     *gtime.Time `p:"followUpDate"    json:"followUpDate"   `                     //跟进时间
-	CustIndustry     string      `p:"custIndustry"    json:"custIndustry"  v:"required#客户行业不能为空"` //客户行业
-	CustIndustryCode string      `json:"custIndustryCode"`                                        //客户行业编码
-	CustLevel        string      `p:"custLevel"       json:"custLevel"`                           //客户级别
-	CustSource       string      `p:"custSource"      json:"source"        v:"required#客户来源不能为空"` //客户来源
-	CustDistCode     int         `p:"custDistCode"    json:"custDistCode"  v:"required#省份不能为空" `  // 省份Id
-	Remark           string      `p:"remark"          json:"remark"`                              //备注
-	SalesName        string      `p:"salesName"       json:"salesName"   `                        // 销售名称
-	SalesId          int         `p:"salesId"         json:"salesId"   `                          // 销售id
+	CustName       string      `p:"custName"        json:"custName"      v:"required#客户名称不能为空"` // 客户名称
+	AbbrName       string      `p:"abbrName"        json:"abbrName"   `                         // 助计名
+	CustLocation   string      `p:"custLocation"    json:"custLocation"    `                    // 所在地区
+	CustAddress    string      `p:"custAddress"     json:"custAddress"   `                      // 详细地址
+	CustProvinceId int         `json:"custProvinceId"`                                          // 所在省ID
+	CustProvince   string      `json:"custProvince"`                                            // 所在省
+	CustCityId     int         `json:"custCityId"`                                              // 所在市ID
+	CustCity       string      `json:"custCity"`                                                // 所在市
+	CustRegionId   int         `json:"custRegionId"`                                            // 所在区县ID
+	CustRegion     string      `json:"custRegion"`                                              // 所在区县
+	FollowUpDate   *gtime.Time `p:"followUpDate"    json:"followUpDate"   `                     //跟进时间
+	CustIndustry   string      `p:"custIndustry"    json:"custIndustry"  v:"required#客户行业不能为空"` //客户行业
+	CustLevel      string      `p:"custLevel"       json:"custLevel"`                           //客户级别
+	CustSource     string      `p:"custSource"      json:"source"        v:"required#客户来源不能为空"` //客户来源
+	CustDistCode   int         `p:"custDistCode"    json:"custDistCode"  v:"required#省份不能为空" `  // 省份Id
+	Remark         string      `p:"remark"          json:"remark"`                              //备注
+	SalesName      string      `p:"salesName"       json:"salesName"   `                        // 销售名称
+	SalesId        int         `p:"salesId"         json:"salesId"   `                          // 销售id
 }
 
 // 客户联系人信息

+ 39 - 0
opms_parent/app/service/base.go

@@ -1,9 +1,13 @@
 package service
 
 import (
+	"context"
+	"fmt"
 	"log"
 	"reflect"
 
+	"dashoo.cn/common_definition/comm_def"
+	"dashoo.cn/opms_libary/micro_srv"
 	"github.com/gogf/gf/database/gdb"
 	"github.com/gogf/gf/os/gtime"
 )
@@ -128,3 +132,38 @@ func Div(Num int) string {
 	}
 	return Str
 }
+
+type GetDictReq struct {
+	DictType     string `p:"dictType" v:"required#字典类型不能为空"`
+	DefaultValue string `p:"defaultValue"`
+}
+
+func GetDictDataByType(ctx context.Context, typ string) (map[string]string, error) {
+	srv := micro_srv.InitMicroSrvClient("Dict", "micro_srv.auth")
+	defer srv.Close()
+	resp := &comm_def.CommonMsg{}
+	err := srv.Call(ctx, "GetDictDataByType", GetDictReq{
+		DictType: typ,
+	}, resp)
+	if err != nil {
+		return nil, fmt.Errorf("获取字典 %s %s", typ, err.Error())
+	}
+	fmt.Println(resp.Data)
+	data := resp.Data.(map[string]interface{})["Values"].([]interface{})
+	fmt.Println(data)
+	res := map[string]string{}
+	for _, i := range data {
+		info := i.(map[string]interface{})
+		res[info["DictValue"].(string)] = info["DictLabel"].(string)
+	}
+	return res, nil
+}
+
+func StringSlicecontains(s []string, ele string) bool {
+	for _, i := range s {
+		if i == ele {
+			return true
+		}
+	}
+	return false
+}

+ 24 - 8
opms_parent/app/service/cust/cust_customer.go

@@ -163,7 +163,7 @@ func (s *CustomerService) Create(req *model.CustomerAddSeq) (insertId int64, err
 		return
 	}
 	service.SetCreatedInfo(cusTomer, s.GetCxtUserId(), s.CxtUser.NickName)
-	custCode, err := s.customerCode(req.CustProvince, req.CustIndustryCode)
+	custCode, err := s.customerCode(req.CustProvince, req.CustIndustry)
 	if err != nil {
 		return 0, err
 	}
@@ -173,7 +173,7 @@ func (s *CustomerService) Create(req *model.CustomerAddSeq) (insertId int64, err
 	roles := s.GetCxtUserRoles()
 	isSales := false
 	for _, v := range roles {
-		if v == "Sales" { // 销售角色
+		if v == "SalesEngineer" { // 销售角色
 			isSales = true
 			break
 		}
@@ -183,13 +183,14 @@ func (s *CustomerService) Create(req *model.CustomerAddSeq) (insertId int64, err
 		cusTomer.IsPublic = noPublic
 		cusTomer.SalesId = s.GetCxtUserId()
 		cusTomer.SalesName = s.CxtUser.NickName
+		cusTomer.CustStatus = "30"
 		insertId, err = s.Dao.InsertAndGetId(cusTomer)
 		if err != nil {
 			g.Log().Error(err)
 			return 0, err
 		}
-		s.CreateBelong(gconv.Int(insertId))
-		return
+		err = s.CreateBelong(gconv.Int(insertId))
+		return insertId, err
 	} else {
 		cusTomer.IsPublic = isPublic
 		insertId, err = s.Dao.InsertAndGetId(cusTomer)
@@ -478,6 +479,11 @@ func (s *CustomerService) MoveToPublicRequest(ctx context.Context, req *model.Mo
 		return myerrors.TipsError("移回用户不能为空")
 	}
 
+	cusType, err := service.GetDictDataByType(ctx, "cust_idy")
+	if err != nil {
+		return err
+	}
+
 	for _, v := range data {
 		if v.CustStatus == "10" {
 			return myerrors.TipsError(fmt.Sprintf("客户: %s 已被移回公海", v.CustName))
@@ -536,7 +542,7 @@ func (s *CustomerService) MoveToPublicRequest(ctx context.Context, req *model.Mo
 				{
 					Id:    utils.String("TextField_S966SSJHCCG0"),
 					Name:  utils.String("客户类别"),
-					Value: utils.String(u.CustIndustry),
+					Value: utils.String(cusType[u.CustIndustry]),
 				},
 				{
 					Id:    utils.String("TextField_Y3EQ11P49LC0"),
@@ -1145,13 +1151,17 @@ func (s *CustomerService) BatchCreatebelong(rep []*model.CustCustomer, req *mode
 }
 
 // 导出数据
-func (s *CustomerService) Export(req *model.CustCustomerExport) (content *model.CustExport, err error) {
+func (s *CustomerService) Export(ctx context.Context, req *model.CustCustomerExport) (content *model.CustExport, err error) {
 	var con model.CustExport
 	req.IsRemovePage = true // 去掉分页标识
 	total, data, err := s.GetList(&req.CustCustomerSearchReq)
 	if err != nil {
 		return
 	}
+	cusType, err := service.GetDictDataByType(ctx, "cust_idy")
+	if err != nil {
+		return nil, err
+	}
 	f := excelize.NewFile()
 	index := f.NewSheet("Sheet1")
 	for index, item := range req.Columns {
@@ -1177,8 +1187,8 @@ func (s *CustomerService) Export(req *model.CustCustomerExport) (content *model.
 				if v == "所在地区" {
 					f.SetCellValue("Sheet1", service.Div(index+1)+strconv.Itoa(ck+2), item.CustLocation)
 				}
-				if v == "客户行业" {
-					f.SetCellValue("Sheet1", service.Div(index+1)+strconv.Itoa(ck+2), item.CustIndustry)
+				if v == "客户类型" {
+					f.SetCellValue("Sheet1", service.Div(index+1)+strconv.Itoa(ck+2), cusType[item.CustIndustry])
 				}
 				if v == "客户级别" {
 					f.SetCellValue("Sheet1", service.Div(index+1)+strconv.Itoa(ck+2), item.CustLevel)
@@ -1200,6 +1210,12 @@ func (s *CustomerService) Export(req *model.CustCustomerExport) (content *model.
 				if v == "创建时间" {
 					f.SetCellValue("Sheet1", service.Div(index+1)+strconv.Itoa(ck+2), item.CreatedTime)
 				}
+				if v == "所在省" {
+					f.SetCellValue("Sheet1", service.Div(index+1)+strconv.Itoa(ck+2), item.CustProvince)
+				}
+				if v == "所在市" {
+					f.SetCellValue("Sheet1", service.Div(index+1)+strconv.Itoa(ck+2), item.CustCity)
+				}
 			}
 
 		}

+ 38 - 0
opms_parent/app/service/cust/cust_customer_test.go

@@ -5,7 +5,9 @@ import (
 	"fmt"
 	"testing"
 
+	"dashoo.cn/common_definition/comm_def"
 	modelWorkflow "dashoo.cn/micro/app/model/workflow"
+	"dashoo.cn/opms_libary/micro_srv"
 	"dashoo.cn/opms_libary/plugin/dingtalk/message"
 	"github.com/gogf/gf/frame/g"
 	"github.com/smallnest/rpcx/share"
@@ -95,3 +97,39 @@ func TestGetUser(t *testing.T) {
 	err := GetUser(ctx, 1)
 	fmt.Println(err)
 }
+
+func TestGetDictDataByType(t *testing.T) {
+	ctx := context.WithValue(context.Background(), share.ReqMetaDataKey, map[string]string{
+		"tenant":      testTenant,
+		share.AuthKey: "CpTRPY8d4MdhDOYwLe+8giLLH/By5z9W+plGyiyITHy2WRmW08Lo84Aeaj7fbBQz",
+	})
+
+	res, err := GetDictDataByType(ctx, "cust_idy")
+	fmt.Println(res, err)
+}
+
+type GetDictReq struct {
+	DictType     string `p:"dictType" v:"required#字典类型不能为空"`
+	DefaultValue string `p:"defaultValue"`
+}
+
+func GetDictDataByType(ctx context.Context, typ string) (map[string]string, error) {
+	srv := micro_srv.InitMicroSrvClient("Dict", "micro_srv.auth")
+	defer srv.Close()
+	resp := &comm_def.CommonMsg{}
+	err := srv.Call(ctx, "GetDictDataByType", GetDictReq{
+		DictType: typ,
+	}, resp)
+	if err != nil {
+		return nil, fmt.Errorf("获取字典 %s %s", typ, err.Error())
+	}
+	fmt.Println(resp.Data)
+	data := resp.Data.(map[string]interface{})["Values"].([]interface{})
+	fmt.Println(data)
+	res := map[string]string{}
+	for _, i := range data {
+		info := i.(map[string]interface{})
+		res[info["DictValue"].(string)] = info["DictLabel"].(string)
+	}
+	return res, nil
+}