Explorar o código

feature:公海客户导入模板添加

sunxinyuan hai 1 ano
pai
achega
8ff3efe101

+ 16 - 0
opms_parent/app/handler/cust/customer.go

@@ -3,6 +3,7 @@ package cust
 import (
 	"context"
 	"dashoo.cn/micro/app/model/contract"
+	"encoding/base64"
 
 	"dashoo.cn/common_definition/comm_def"
 	"dashoo.cn/opms_libary/myerrors"
@@ -93,6 +94,21 @@ func (c *CustomerHeader) Import(ctx context.Context, req *contract.ExcelImportRe
 	return nil
 }
 
+// Swagger:Customer 导入客户 模板
+func (c *CustomerHeader) ExcelTemplate(ctx context.Context, req *struct{}, rsp *comm_def.CommonMsg) error {
+	//g.Log().Infof("TeQuestionDocDetail.ExcelTemplate request %#v ", *req)
+	f, err := server.ExcelTemplate()
+	if err != nil {
+		return err
+	}
+	buf, err := f.WriteToBuffer()
+	if err != nil {
+		return err
+	}
+	rsp.Data = base64.StdEncoding.EncodeToString(buf.Bytes())
+	return nil
+}
+
 // Swagger:Customer 客户 修改客户
 func (c *CustomerHeader) UpdateById(ctx context.Context, req *model.UpdateCustomer, rsp *comm_def.CommonMsg) error {
 	s, err := server.NewCustomerService(ctx)

+ 6 - 5
opms_parent/app/model/cust/cust_customer.go

@@ -87,14 +87,15 @@ type ImportFile struct {
 type CustomerAddImport struct {
 	CustName     string `import:"客户名称"  p:"custName"        json:"custName"      v:"required#客户名称不能为空"`    // 客户名称
 	AbbrName     string `import:"助计名"  p:"abbrName"        json:"abbrName"   `                             // 助计名
-	CustAddress  string `import:"详细地址" p:"custAddress"     json:"custAddress"   `                          // 详细地址
+	CustIndustry string `import:"客户类型" p:"custIndustry"    json:"custIndustry"  v:"required#客户行业不能为空"`     // 客户行业
+	CustSource   string `import:"客户来源" p:"custSource"      json:"custSource"        v:"required#客户来源不能为空"` // 客户来源
 	CustProvince string `import:"所在省" json:"custProvince"`                                                 // 所在省
 	CustCity     string `import:"所在市" json:"custCity"`                                                     // 所在市
 	CustRegion   string `import:"所在区县" json:"custRegion"`                                                  // 所在区县
-	CustIndustry string `import:"客户行业" p:"custIndustry"    json:"custIndustry"  v:"required#客户行业不能为空"`     // 客户行业
-	CustSource   string `import:"客户来源" p:"custSource"      json:"custSource"        v:"required#客户来源不能为空"` // 客户来源
-	Keyword      string `import:"招标关键字" json:"keyword"`                                                    // 招标关键字
-	Remark       string `import:"备注" p:"remark"          json:"remark"`                                    // 备注
+	CustAddress  string `import:"详细地址" p:"custAddress"     json:"custAddress"   `                          // 详细地址
+
+	Keyword string `import:"招标关键字" json:"keyword"`                 // 招标关键字
+	Remark  string `import:"备注" p:"remark"          json:"remark"` // 备注
 
 	CuctName       string `import:"姓名" p:"cuctName"     json:"cuctName"  v:"required#联系人名字不能为空"`                         // 姓名
 	CuctGender     string `import:"性别" p:"cuctGender"    json:"cuctGender"  v:"required|in:10,20#性别不能为空|填写错误"`           // 性别(10男20女)

+ 47 - 11
opms_parent/app/service/cust/cust_customer.go

@@ -26,6 +26,7 @@ import (
 	"github.com/gogf/gf/os/gtime"
 	"github.com/gogf/gf/util/gconv"
 	"github.com/mozillazg/go-pinyin"
+	excelizev2 "github.com/xuri/excelize/v2"
 
 	"dashoo.cn/micro/app/dao/cust"
 	platdao "dashoo.cn/micro/app/dao/plat"
@@ -240,6 +241,43 @@ func reverseMap(originalMap map[string]string) map[string]string {
 	return reversedMap
 }
 
+var contactExcelHeader = []partner.ExcelHeader{
+	{Name: "*客户名称", Width: 30},
+	{Name: "助计名", Width: 30},
+	{Name: "*客户类型", Width: 30},
+	{Name: "*客户来源", Width: 30},
+	{Name: "所在省", Width: 30},
+	{Name: "所在市", Width: 30},
+	{Name: "所在区县", Width: 30},
+	{Name: "详细地址", Width: 30},
+	{Name: "招标关键字(以逗号分隔)", Width: 40},
+	{Name: "备注", Width: 30},
+	{Name: "*联系人姓名", Width: 30},
+	{Name: "*联系人性别", Width: 30},
+	{Name: "*联系人电话", Width: 30},
+	{Name: "联系人微信", Width: 30},
+	{Name: "联系人邮箱", Width: 30},
+	{Name: "联系人部门", Width: 30},
+	{Name: "*联系人职位", Width: 30},
+	{Name: "联系人办公地点", Width: 30},
+	{Name: "*关键决策人(是/否)", Width: 30},
+	{Name: "联系人备注", Width: 30},
+}
+
+func ExcelTemplate() (*excelizev2.File, error) {
+	tempData := [][]string{
+		{
+			"张三", "张三(备注)", "医院", "经销商", "北京市", "北京市", "朝阳区", "ffff", "20387,生物样本库", "备注",
+			"李四", "男", "18000000000", "weixin", "abc@163.com", "部门", "职务", "办公地点", "否", "联系人备注",
+		},
+	}
+	excel, err := partner.NewExcel(contactExcelHeader, tempData)
+	if err != nil {
+		return nil, err
+	}
+	return excel, nil
+}
+
 // Create 导入客户
 func (s *CustomerService) Import(ctx context.Context, req *contract.ExcelImportReq) (err error) {
 	validErr := gvalid.CheckStruct(ctx, req, nil)
@@ -253,7 +291,7 @@ func (s *CustomerService) Import(ctx context.Context, req *contract.ExcelImportR
 		return myerrors.TipsError(fmt.Sprintf("下载 excel 异常 %s", err.Error()))
 	}
 
-	// 解析excel,构造销售目标数据
+	// 解析excel
 	excelData, err := s.parseExcel(buf)
 	if err != nil {
 		return myerrors.TipsError(fmt.Sprintf("解析 excel 异常 %s", err.Error()))
@@ -270,8 +308,6 @@ func (s *CustomerService) Import(ctx context.Context, req *contract.ExcelImportR
 	keywordsMap = reverseMap(keywordsMap)
 	svc, err := sbase.NewDistrictService(ctx)
 	treeList, err := svc.GetProvincesList(0)
-	fmt.Println("treeList", treeList)
-	//insertContactList := make([]*model.CustCustomerContactSeq, 0)
 	contactService, err := NewCustomerContactService(ctx)
 	if err != nil {
 		return err
@@ -295,7 +331,7 @@ func (s *CustomerService) Import(ctx context.Context, req *contract.ExcelImportR
 			var city *base.ProvincesTree
 			var region *base.ProvincesTree
 
-			keywords := strings.Split(data.Keyword, ",")
+			keywords := strings.Split(data.Keyword, "")
 			for _, keyword := range keywords {
 				if _, ok := keywordsMap[keyword]; !ok {
 					return myerrors.TipsError(fmt.Sprintf("关键字 %s 不存在", keyword))
@@ -388,18 +424,18 @@ func (s CustomerService) parseExcel(b []byte) ([]*model.CustomerAddImport, error
 		return nil, err
 	}
 
-	// 客户名称 助计名 所在地区 详细地址 所在省 所在市 所在区县 客户行业 客户级别 客户来源 备注 销售名称 开票抬头 关联客户 姓名 性别 电话 微信 邮箱 部门 职位 办公地点 是否关键决策人 招标关键字
+	// 客户名称 助计名 客户类型 客户来源 所在省 所在市 所在区县 详细地址 招标关键字 备注 姓名 性别 电话 微信 邮箱 部门 职位 办公地点 是否关键决策人 联系人备注
 	var saleTargets []*model.CustomerAddImport
 	for _, row := range rows[1:] {
 		temp := &model.CustomerAddImport{
 			CustName:       row[0],
 			AbbrName:       row[1],
-			CustAddress:    row[2],
-			CustProvince:   row[3],
-			CustCity:       row[4],
-			CustRegion:     row[5],
-			CustIndustry:   row[6],
-			CustSource:     row[7],
+			CustIndustry:   row[2],
+			CustSource:     row[3],
+			CustProvince:   row[4],
+			CustCity:       row[5],
+			CustRegion:     row[6],
+			CustAddress:    row[7],
 			Keyword:        row[8],
 			Remark:         row[9],
 			CuctName:       row[10],