Преглед на файлове

Merge branch 'crm/8.8' into debug

hsun преди 2 години
родител
ревизия
9d2d9aa1ec
променени са 1 файла, в които са добавени 60 реда и са изтрити 59 реда
  1. 60 59
      services/contract/contract.go

+ 60 - 59
services/contract/contract.go

@@ -131,11 +131,7 @@ func getContractDetail(contractId int) (contractDetail *contract.ContractDetail,
 	}
 	// 权益合同主客观合并
 	if len(serviceList) > 0 && serviceList[0].ProductId == 2 {
-		mergeList, e := EquityMergeSubjectAndObject(serviceList)
-		if e != nil {
-			err = errors.New(fmt.Sprint("合并权益合同服务异常", err))
-			return
-		}
+		mergeList := EquityMergeSubjectAndObject(serviceList)
 		serviceList = mergeList
 	}
 	newLen := len(serviceList)
@@ -471,75 +467,80 @@ func GetServicePermissionMap(serviceList []*contractCustom.ContractServiceAndDet
 	return
 }
 
-// 权益合同主客观合并
-func EquityMergeSubjectAndObject(serviceList []*contractCustom.ContractServiceAndDetail) (mergeList []*contractCustom.ContractServiceAndDetail, err error) {
-	mergeList = make([]*contractCustom.ContractServiceAndDetail, 0)
+// CRM8.8-权益合同主客观套餐合并
+func EquityMergeSubjectAndObject(serviceList []*contractCustom.ContractServiceAndDetail) (mergeList []*contractCustom.ContractServiceAndDetail) {
+	serviceLen := len(serviceList)
+	if serviceLen == 0 {
+		return serviceList
+	}
+	mergeArr := []string{"医药", "消费", "科技", "智造"}
 	// 获取模板列表
 	templateList, e := contract_service_template.GetAllContractServiceTemplateList()
 	if e != nil {
-		err = errors.New("获取合同服务模板异常, Err: " + e.Error())
-		return
+		return serviceList
 	}
+	parentTempMap := make(map[string]int, 0)
 	templateMap := make(map[int]*contract_service_template.ContractServiceTemplate, 0)
 	for _, v := range templateList {
+		if utils.InArrayByStr(mergeArr, v.Title) {
+			parentTempMap[v.Title] = v.ServiceTemplateId
+		}
 		templateMap[v.ServiceTemplateId] = v
 	}
-	mergeArr := []string{"医药", "消费", "科技", "智造"}
-	// 遍历原服务
-	serviceLen := len(serviceList)
-	if serviceLen > 0 {
-		otherList := make([]*contractCustom.ContractServiceAndDetail, 0)
-		needCheck := make([]*contractCustom.ContractServiceAndDetail, 0)
-		for i := 0; i < serviceLen; i++ {
-			sv := serviceList[i]
-			if sv.ProductId != 2 {
-				mergeList = serviceList
-				return
-			}
-			// 判断是否包含主观客观
-			if utils.InArrayByStr(mergeArr, sv.Title) {
-				needCheck = append(needCheck, sv)
-			} else {
-				if !strings.Contains(sv.Title, "主观") && !strings.Contains(sv.Title, "客观") {
-					otherList = append(otherList, sv)
-					//mergeList = append(mergeList, sv)
-				}
-			}
+	// 计算每个行业的子套餐数, 并判断所有套餐所属行业
+	countIndustryMap := make(map[string]int, 0)
+	serviceIndustryMap := make(map[int]string, 0)
+	industryServiceMap := make(map[string]*contractCustom.ContractServiceAndDetail, 0)
+	childrenServiceMap := make(map[string]*contractCustom.ContractServiceAndDetail, 0)
+	for i := 0; i < serviceLen; i++ {
+		temp := templateMap[serviceList[i].ServiceTemplateId]
+		if temp == nil {
+			continue
 		}
-		// 不需要合并
-		checkLen := len(needCheck)
-		if checkLen == 0 {
-			mergeList = serviceList
-			return
+		// 行业套餐
+		if utils.InArrayByStr(mergeArr, temp.Title) {
+			serviceIndustryMap[serviceList[i].ContractServiceId] = temp.Title
+			industryServiceMap[temp.Title] = serviceList[i]
+			continue
 		}
-		for i := 0; i < checkLen; i++ {
-			count := 0
-			parent := needCheck[i]
-			parentId := parent.ServiceTemplateId
-			// 检查需要合并的是否包含主客观
-			children := make([]*contractCustom.ContractServiceAndDetail, 0)
-			for ii := 0; ii < serviceLen; ii++ {
-				sv := serviceList[ii]
-				temp := templateMap[sv.ServiceTemplateId]
-				if temp.Pid == parentId {
-					count += 1
-					//sv.Title = fmt.Sprint(parent.Title, "(", sv.Title, ")")
-					children = append(children, sv)
-				}
-			}
-			// 均包含时只取二级套餐, 否则取主/客观
-			if count == 1 {
-				mergeList = append(mergeList, children...)
-			} else {
-				mergeList = append(mergeList, parent)
-			}
+		// 主/客观
+		parentTemp := templateMap[temp.Pid]
+		if parentTemp != nil && utils.InArrayByStr(mergeArr, parentTemp.Title) {
+			countIndustryMap[parentTemp.Title] += 1
+			serviceIndustryMap[serviceList[i].ContractServiceId] = parentTemp.Title
+			childrenServiceMap[parentTemp.Title] = serviceList[i]
+		}
+	}
+	mergeList = make([]*contractCustom.ContractServiceAndDetail, 0)
+	// 遍历每一个套餐, 取出所属的行业, 不属于合并的行业则直接加入数组
+	// 属于合并的行业, 则校验行业子套餐数, 若子套餐数为1, 则取取主/客观套餐, 否则取行业套餐
+	mergeIndustryMap := make(map[string]int, 0)
+	for i := 0; i < serviceLen; i++ {
+		industryName := serviceIndustryMap[serviceList[i].ContractServiceId]
+		// 不需要合并的行业
+		if industryName == "" {
+			fmt.Println("1:", serviceList[i])
+			mergeList = append(mergeList, serviceList[i])
+			continue
+		}
+		// 未合并则进行合并
+		if mergeIndustryMap[industryName] > 0 {
+			continue
+		}
+		count := countIndustryMap[industryName]
+		if count == 1 {
+			// 取主/客观套餐
+			mergeList = append(mergeList, childrenServiceMap[industryName])
+		} else {
+			// 0或者2都取行业套餐
+			mergeList = append(mergeList, industryServiceMap[industryName])
 		}
-		mergeList = append(mergeList, otherList...)
+		mergeIndustryMap[industryName] += 1
 	}
 	return
 }
 
-// HandleEquityPermissionLookList 权益-权限展示的主客观合并处理
+// CRM8.8-HandleEquityPermissionLookList 权益-权限展示的主客观合并处理
 func HandleEquityPermissionLookList(permissionLookList []*company_report_permission.PermissionLookList) []*company_report_permission.PermissionLookList {
 	if len(permissionLookList) <= 0 {
 		return permissionLookList