|
@@ -16,6 +16,7 @@ import (
|
|
|
"hongze/hongze_mobile_admin/models/tables/contract_operation_record"
|
|
|
"hongze/hongze_mobile_admin/models/tables/contract_relation"
|
|
|
"hongze/hongze_mobile_admin/models/tables/contract_service_detail"
|
|
|
+ "hongze/hongze_mobile_admin/models/tables/contract_service_template"
|
|
|
"hongze/hongze_mobile_admin/services"
|
|
|
"hongze/hongze_mobile_admin/utils"
|
|
|
"mime/multipart"
|
|
@@ -128,7 +129,13 @@ func getContractDetail(contractId int) (contractDetail *contract.ContractDetail,
|
|
|
err = errors.New(fmt.Sprint("查找合同服务异常", err))
|
|
|
return
|
|
|
}
|
|
|
- for i := 0; len(serviceList) > i; i++ {
|
|
|
+ // 权益合同主客观合并
|
|
|
+ if len(serviceList) > 0 && serviceList[0].ProductId == 2 {
|
|
|
+ mergeList := EquityMergeSubjectAndObject(serviceList)
|
|
|
+ serviceList = mergeList
|
|
|
+ }
|
|
|
+ newLen := len(serviceList)
|
|
|
+ for i := 0; newLen > i; i++ {
|
|
|
if serviceList[i].HasDetail == "是" {
|
|
|
list, detailErr := contract_service_detail.GetContractServiceDetailListByServiceId(serviceList[i].ContractServiceId)
|
|
|
if detailErr != nil {
|
|
@@ -459,3 +466,132 @@ func GetServicePermissionMap(serviceList []*contractCustom.ContractServiceAndDet
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+// 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 {
|
|
|
+ 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
|
|
|
+ }
|
|
|
+ // 计算每个行业的子套餐数, 并判断所有套餐所属行业
|
|
|
+ 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
|
|
|
+ }
|
|
|
+ // 行业套餐
|
|
|
+ if utils.InArrayByStr(mergeArr, temp.Title) {
|
|
|
+ serviceIndustryMap[serviceList[i].ContractServiceId] = temp.Title
|
|
|
+ industryServiceMap[temp.Title] = serviceList[i]
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ // 主/客观
|
|
|
+ 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])
|
|
|
+ }
|
|
|
+ mergeIndustryMap[industryName] += 1
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// CRM8.8-HandleEquityPermissionLookList 权益-权限展示的主客观合并处理
|
|
|
+func HandleEquityPermissionLookList(permissionLookList []*company_report_permission.PermissionLookList) []*company_report_permission.PermissionLookList {
|
|
|
+ if len(permissionLookList) <= 0 {
|
|
|
+ return permissionLookList
|
|
|
+ }
|
|
|
+ checkList := permissionLookList[0].CheckList
|
|
|
+ //fmt.Println(checkList)
|
|
|
+ permissionList := permissionLookList[0].Items
|
|
|
+ permissionLen := len(permissionList)
|
|
|
+ if len(checkList) <= 0 || permissionLen <= 0 {
|
|
|
+ return permissionLookList
|
|
|
+ }
|
|
|
+ // 若某个行业的主客观权限均被满足,则只留其中一个权限
|
|
|
+ // 1.取出每个行业对应的其中一个权限
|
|
|
+ industryName := []string{"医药", "消费", "科技", "智造"}
|
|
|
+ namePermissionMap := make(map[string]*company_report_permission.PermissionLookItem)
|
|
|
+ for i := 0; i < permissionLen; i++ {
|
|
|
+ pName := permissionList[i].PermissionName
|
|
|
+ if utils.InArrayByStr(industryName, pName) && namePermissionMap[pName] != nil {
|
|
|
+ namePermissionMap[pName] = permissionList[i]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 2.计算哪些行业主客观权限都有
|
|
|
+ countIndustryMap := make(map[string]int, 0)
|
|
|
+ for i := 0; i < permissionLen; i++ {
|
|
|
+ p := permissionList[i]
|
|
|
+ if utils.InArrayByStr(industryName, p.PermissionName) && utils.InArrayByInt(checkList, p.ChartPermissionId) {
|
|
|
+ countIndustryMap[p.PermissionName] += 1
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //fmt.Println(countIndustryMap)
|
|
|
+ // 3.重新组成一个权限列表
|
|
|
+ mergeIndustryMap := make(map[string]int, 0)
|
|
|
+ newPermissionList := make([]*company_report_permission.PermissionLookItem, 0)
|
|
|
+ for i := 0; i < permissionLen; i++ {
|
|
|
+ item := permissionList[i]
|
|
|
+ if utils.InArrayByStr(industryName, item.PermissionName) {
|
|
|
+ // 只有主客观之一, permissionName取remark
|
|
|
+ if countIndustryMap[item.PermissionName] == 1 {
|
|
|
+ item.PermissionName = item.Remark
|
|
|
+ newPermissionList = append(newPermissionList, item)
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ // 主客观都有
|
|
|
+ if countIndustryMap[item.PermissionName] > 1 && mergeIndustryMap[item.PermissionName] == 0 {
|
|
|
+ mergeIndustryMap[item.PermissionName] += 1
|
|
|
+ newPermissionList = append(newPermissionList, item)
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ newPermissionList = append(newPermissionList, item)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ permissionLookList[0].Items = newPermissionList
|
|
|
+ return permissionLookList
|
|
|
+}
|