Jelajahi Sumber

Merge branch 'feature/eta1.6.7_permission' of hongze/hz_crm_api into master

xyxie 11 bulan lalu
induk
melakukan
0b1fb44b60

+ 58 - 110
controllers/classify.go

@@ -1,8 +1,9 @@
 package controllers
 
 import (
-	"github.com/rdlucklib/rdluck_tools/paging"
+	"encoding/json"
 	"hongze/hz_crm_api/models"
+	"hongze/hz_crm_api/services"
 	"hongze/hz_crm_api/utils"
 )
 
@@ -11,10 +12,9 @@ type ClassifyController struct {
 	BaseAuthController
 }
 
+// ListClassify
 // @Title 获取分类列表
 // @Description 获取分类列表
-// @Param   PageSize   query   int  true       "每页数据条数"
-// @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
 // @Param   KeyWord   query   string  true       "检索关键词"
 // @Param   CompanyType   query   string  false       "产品类型,枚举值:'ficc','权益';不传默认返回全部"
 // @Param   HideDayWeek   query   int  false       "是否隐藏晨周报"
@@ -26,123 +26,21 @@ func (this *ClassifyController) ListClassify() {
 		this.Data["json"] = br
 		this.ServeJSON()
 	}()
-	pageSize, _ := this.GetInt("PageSize")
-	currentIndex, _ := this.GetInt("CurrentIndex")
 	keyWord := this.GetString("KeyWord")
 	companyType := this.GetString("CompanyType")
 	hideDayWeek, _ := this.GetInt("HideDayWeek")
 
-	var startSize int
-	if pageSize <= 0 {
-		pageSize = utils.PageSize20
-	}
-	if currentIndex <= 0 {
-		currentIndex = 1
-	}
-
-	startSize = utils.StartIndex(currentIndex, pageSize)
-	list, err := models.GetClassifyList(startSize, pageSize, keyWord, companyType, hideDayWeek)
-	if err != nil {
-		br.Msg = "获取失败"
-		br.ErrMsg = "获取失败,Err:" + err.Error()
-		return
-	}
-	total, err := models.GetClassifyListCount(keyWord, companyType, hideDayWeek)
+	req := new(services.GetClassifyListReq)
+	req.Keyword = keyWord
+	req.CompanyType = companyType
+	req.HideDayWeek = hideDayWeek
+	resp, err := services.GetClassifyList(req)
 	if err != nil {
 		br.Msg = "获取失败"
 		br.ErrMsg = "获取失败,Err:" + err.Error()
 		return
 	}
 
-	parentIds := make([]int, 0)
-	for i := range list {
-		parentIds = append(parentIds, list[i].Id)
-	}
-	parentIdLen := len(parentIds)
-	if parentIdLen == 0 {
-		resp := &models.ClassifyListResp{
-			List:   list,
-			Paging: paging.GetPaging(currentIndex, pageSize, 0),
-		}
-		br.Data = resp
-		br.Ret = 200
-		br.Success = true
-		br.Msg = "获取成功"
-		return
-	}
-
-	// 获取一级分类-子目录列表
-	menuListMap := make(map[int][]*models.ClassifyMenu, 0)
-	var menuCond string
-	var menuPars []interface{}
-	menuCond += ` AND classify_id IN (` + utils.GetOrmInReplace(parentIdLen) + `)`
-	menuPars = append(menuPars, parentIds)
-	parentMenus, e := models.GetClassifyMenuList(menuCond, menuPars)
-	if e != nil {
-		br.Msg = "获取失败"
-		br.ErrMsg = "获取一级分类子目录列表失败"
-		return
-	}
-	for i := range parentMenus {
-		if menuListMap[parentMenus[i].ClassifyId] == nil {
-			menuListMap[parentMenus[i].ClassifyId] = make([]*models.ClassifyMenu, 0)
-		}
-		menuListMap[parentMenus[i].ClassifyId] = append(menuListMap[parentMenus[i].ClassifyId], parentMenus[i])
-	}
-
-	// 获取子分类
-	children, e := models.GetClassifyChildByParentIds(parentIds, keyWord)
-	if e != nil {
-		br.Msg = "获取失败"
-		br.ErrMsg = "获取子分类失败"
-		return
-	}
-	childrenIds := make([]int, 0)
-	for i := range children {
-		childrenIds = append(childrenIds, children[i].Id)
-	}
-	childrenIdsLen := len(childrenIds)
-
-	// 获取二级分类-子目录关联
-	relateMap := make(map[int]int, 0)
-	if childrenIdsLen > 0 {
-		var relateCond string
-		var relatePars []interface{}
-		relateCond += ` AND classify_id IN (` + utils.GetOrmInReplace(childrenIdsLen) + `)`
-		relatePars = append(relatePars, childrenIds)
-		relates, e := models.GetClassifyMenuRelationList(relateCond, relatePars)
-		if e != nil {
-			br.Msg = "获取失败"
-			br.ErrMsg = "获取二级分类子目录关联失败, Err: " + e.Error()
-			return
-		}
-		for i := range relates {
-			relateMap[relates[i].ClassifyId] = relates[i].MenuId
-		}
-	}
-
-	// 二级分类
-	childrenMap := make(map[int][]*models.ClassifyItem, 0)
-	for i := range children {
-		if childrenMap[children[i].ParentId] == nil {
-			childrenMap[children[i].ParentId] = make([]*models.ClassifyItem, 0)
-		}
-		childrenMap[children[i].ParentId] = append(childrenMap[children[i].ParentId], &models.ClassifyItem{
-			Classify:       *children[i],
-			ClassifyMenuId: relateMap[children[i].Id],
-		})
-	}
-
-	// 一级分类
-	for i := range list {
-		list[i].ClassifyMenuList = menuListMap[list[i].Id]
-		list[i].Child = childrenMap[list[i].Id]
-	}
-
-	page := paging.GetPaging(currentIndex, pageSize, total)
-	resp := new(models.ClassifyListResp)
-	resp.List = list
-	resp.Paging = page
 	br.Data = resp
 	br.Ret = 200
 	br.Success = true
@@ -154,6 +52,7 @@ func (this *ClassifyController) ListClassify() {
 // @Success 200 {object} models.Classify
 // @router /tel_list [get]
 func (this *ClassifyController) TelListClassify() {
+	// todo 获取电话会 是否需要改成从中间服务项目中获取
 	br := new(models.BaseResponse).Init()
 	defer func() {
 		this.Data["json"] = br
@@ -189,3 +88,52 @@ func (this *ClassifyController) TelListClassify() {
 	br.Success = true
 	br.Msg = "获取成功"
 }
+
+// Edit
+// @Title 编辑报告分类
+// @Description 编辑报告分类
+// @Param	request  body  services.EditClassifyReq  true  "type json string"
+// @Success 200 string "操作成功"
+// @router /edit [post]
+func (this *ClassifyController) Edit() {
+	br := new(models.BaseResponse).Init()
+	br.IsSendEmail = false
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	sysUser := this.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+	var req services.EditClassifyReq
+	if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	if req.ClassifyId <= 0 {
+		br.Msg = "分类ID有误"
+		return
+	}
+
+	err, errMsg := services.EditReportClassify(&req)
+	if err != nil {
+		br.Msg = errMsg
+		br.ErrMsg = "编辑报告分类失败, Err:" + err.Error()
+		return
+	}
+
+	// 清除小程序端的章节缓存
+	{
+		key := "hongze_yb:report_chapter_type:GetEffectTypeID"
+		_ = utils.Rc.Delete(key)
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "操作成功"
+}

+ 108 - 91
controllers/company.go

@@ -3233,51 +3233,61 @@ func (this *CompanyController) Detail() {
 					}
 				}
 			}
-			for _, v := range utils.PermissionFiccClassifyArr {
-				checkList := make([]int, 0)
-				plist := new(company.PermissionLookList)
-				items, err := company.GetPermissionLookItems(item.ProductId, v)
-				if err != nil {
-					br.Msg = "获取失败"
-					br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
-					return
-				}
-				for itemK, n := range items {
-					permission, err := company.GetCompanyPermissionCheckItem(companyId, n.ChartPermissionId)
-					if err != nil && err.Error() != utils.ErrNoRow() {
-						br.Msg = "获取失败"
-						br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
-						return
+			// 编辑回显
+			allPermissions, e := company.GetPermissionLookItemsByProductId(utils.COMPANY_PRODUCT_FICC_ID)
+			if e != nil {
+				br.Msg = "获取失败"
+				br.ErrMsg = "获取权限信息失败,Err:" + e.Error()
+				return
+			}
+			permissionMap := make(map[int][]*company.PermissionLookItem, 0)
+			permissionCheckMap := make(map[int][]int, 0)
+			for _, v := range allPermissions {
+				if v.ParentId > 0 {
+					permissionMap[v.ParentId] = append(permissionMap[v.ParentId], v)
+					if v.IsPublic == 1 {
+						permissionCheckMap[v.ParentId] = append(permissionCheckMap[v.ParentId], v.ChartPermissionId)
 					}
-					if permission != nil && permission.ChartPermissionId > 0 {
-						checkList = append(checkList, n.ChartPermissionId)
-						items[itemK].StartDate = permission.StartDate
-						items[itemK].EndDate = permission.EndDate
-						items[itemK].Status = permission.Status
-
-						endDateTime, _ := time.Parse(utils.FormatDate, permission.EndDate)
-						endDateTime = endDateTime.AddDate(0, 0, 1)
-						sub := endDateTime.Sub(time.Now())
-						if sub < 0 {
-							sub = 0
+				}
+			}
+			for _, v := range allPermissions {
+				if v.ParentId == 0 {
+					checkList := make([]int, 0)
+					plist := new(company.PermissionLookList)
+					plist.Items = make([]*company.PermissionLookItem, 0)
+					plist.ItemsType = make([]*company.PermissionSetItemType, 0)
+					items, ok := permissionMap[v.ChartPermissionId]
+					if ok {
+						for itemK, n := range items {
+							permission, err := company.GetCompanyPermissionCheckItem(companyId, n.ChartPermissionId)
+							if err != nil && err.Error() != utils.ErrNoRow() {
+								br.Msg = "获取失败"
+								br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
+								return
+							}
+							if permission != nil && permission.ChartPermissionId > 0 {
+								checkList = append(checkList, n.ChartPermissionId)
+								items[itemK].StartDate = permission.StartDate
+								items[itemK].EndDate = permission.EndDate
+								items[itemK].Status = permission.Status
+
+								endDateTime, _ := time.Parse(utils.FormatDate, permission.EndDate)
+								endDateTime = endDateTime.AddDate(0, 0, 1)
+								sub := endDateTime.Sub(time.Now())
+								if sub < 0 {
+									sub = 0
+								}
+								expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
+								items[itemK].ExpireDay = expireDay
+							}
 						}
-						expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
-						items[itemK].ExpireDay = expireDay
+						plist.Items = items
 					}
-					//count, err := company.GetCompanyPermissionCheck(companyId, n.ChartPermissionId)
-					//if err != nil {
-					//	br.Msg = "获取失败"
-					//	br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
-					//	return
-					//}
-					//if count > 0 {
-					//	checkList = append(checkList, n.ChartPermissionId)
-					//}
+					plist.ClassifyName = v.PermissionName
+					plist.CheckList = checkList
+					item.PermissionList = append(item.PermissionList, plist)
 				}
-				plist.Items = items
-				plist.ClassifyName = v
-				plist.CheckList = checkList
-				item.PermissionList = append(item.PermissionList, plist)
+
 			}
 			resp.FiccItem = item
 			if resp.FiccItem.Status == utils.COMPANY_STATUS_FOREVER {
@@ -3574,51 +3584,51 @@ func (this *CompanyController) DetailByCreditCode() {
 					}
 				}
 			}
-			for _, v := range utils.PermissionFiccClassifyArr {
-				checkList := make([]int, 0)
-				plist := new(company.PermissionLookList)
-				items, err := company.GetPermissionLookItems(item.ProductId, v)
-				if err != nil {
-					br.Msg = "获取失败"
-					br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
-					return
-				}
-				for itemK, n := range items {
-					permission, err := company.GetCompanyPermissionCheckItem(companyId, n.ChartPermissionId)
-					if err != nil && err.Error() != utils.ErrNoRow() {
-						br.Msg = "获取失败"
-						br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
-						return
-					}
-					if permission != nil && permission.ChartPermissionId > 0 {
-						checkList = append(checkList, n.ChartPermissionId)
-						items[itemK].StartDate = permission.StartDate
-						items[itemK].EndDate = permission.EndDate
-						items[itemK].Status = permission.Status
-
-						endDateTime, _ := time.Parse(utils.FormatDate, permission.EndDate)
-						endDateTime = endDateTime.AddDate(0, 0, 1)
-						sub := endDateTime.Sub(time.Now())
-						if sub < 0 {
-							sub = 0
+			//子权限切片集合
+			allFiccPermissions, permissionMap, e := services.GetBasePermissionLookItem(utils.COMPANY_PRODUCT_FICC_ID)
+			if e != nil {
+				br.Msg = "查询基础权限失败"
+				br.ErrMsg = "查询基础权限失败,Err:" + e.Error()
+				return
+			}
+			//遍历获取
+			for _, v := range allFiccPermissions {
+				if v.ParentId == 0 {
+					checkList := make([]int, 0)
+					plist := new(company.PermissionLookList)
+					plist.Items = make([]*company.PermissionLookItem, 0)
+					items, ok1 := permissionMap[v.ChartPermissionId]
+					if ok1 {
+
+						for itemK, n := range items {
+							permission, e := company.GetCompanyPermissionCheckItem(companyId, n.ChartPermissionId)
+							if e != nil && e.Error() != utils.ErrNoRow() {
+								br.Msg = "获取失败"
+								br.ErrMsg = "获取权限信息失败,Err:" + e.Error()
+								return
+							}
+							if permission != nil && permission.ChartPermissionId > 0 {
+								checkList = append(checkList, n.ChartPermissionId)
+								items[itemK].StartDate = permission.StartDate
+								items[itemK].EndDate = permission.EndDate
+								items[itemK].Status = permission.Status
+
+								endDateTime, _ := time.Parse(utils.FormatDate, permission.EndDate)
+								endDateTime = endDateTime.AddDate(0, 0, 1)
+								sub := endDateTime.Sub(time.Now())
+								if sub < 0 {
+									sub = 0
+								}
+								expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
+								items[itemK].ExpireDay = expireDay
+							}
 						}
-						expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
-						items[itemK].ExpireDay = expireDay
+						plist.Items = items
 					}
-					//count, err := company.GetCompanyPermissionCheck(companyId, n.ChartPermissionId)
-					//if err != nil {
-					//	br.Msg = "获取失败"
-					//	br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
-					//	return
-					//}
-					//if count > 0 {
-					//	checkList = append(checkList, n.ChartPermissionId)
-					//}
+					plist.ClassifyName = v.PermissionName
+					plist.CheckList = checkList
+					item.PermissionList = append(item.PermissionList, plist)
 				}
-				plist.Items = items
-				plist.ClassifyName = v
-				plist.CheckList = checkList
-				item.PermissionList = append(item.PermissionList, plist)
 			}
 			resp.FiccItem = item
 			if (roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
@@ -7594,20 +7604,27 @@ func (this *CompanyController) PermissionList() {
 
 	for _, companyType := range companySlice {
 		//子权限切片集合
-		var permissionClassifyArr []string
+		//var permissionClassifyArr []string
+		var permissionProductId int
 		if companyType == "ficc" {
-			for _, v := range utils.PermissionFiccClassifyArr {
-				permissionClassifyArr = append(permissionClassifyArr, v)
-			}
+			permissionProductId = utils.COMPANY_PRODUCT_FICC_ID
 		} else {
-			permissionClassifyArr = append(permissionClassifyArr, "权益")
+			permissionProductId = utils.COMPANY_PRODUCT_RAI_ID
+		}
+		//子权限切片集合
+		permissionClassifyArr, err := models.GetPermissionFirstByProductId(permissionProductId)
+		if err != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
+			return
 		}
 
 		//遍历获取
 		for _, v := range permissionClassifyArr {
 			checkList := make([]int, 0)
 			plist := new(company.PermissionLookList)
-			items, err := company.GetPermissionLookItems(classifyMap[companyType], v)
+			plist.Items = make([]*company.PermissionLookItem, 0)
+			items, err := company.GetPermissionLookItemsByParentId(classifyMap[companyType], v.ChartPermissionId)
 			if err != nil {
 				br.Msg = "获取失败"
 				br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
@@ -7654,7 +7671,7 @@ func (this *CompanyController) PermissionList() {
 				}
 				expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
 				items[i].ExpireDay = expireDay
-				items[i].ClassifyName = v
+				items[i].ClassifyName = v.PermissionName
 				//if n.PermissionType == 1 {
 				//	items[i].PermissionTypeName = "主观"
 				//} else if n.PermissionType == 2 {
@@ -7675,7 +7692,7 @@ func (this *CompanyController) PermissionList() {
 					}
 				}
 			}
-			plist.ClassifyName = v
+			plist.ClassifyName = v.PermissionName
 			plist.CheckList = checkList
 			if companyType == "ficc" {
 				resp.FiccPermissionList = append(resp.FiccPermissionList, plist)

+ 89 - 54
controllers/company_apply.go

@@ -81,28 +81,38 @@ func (this *CompanyApplyController) ApplyContractHistoryList() {
 
 		productId = list[i].ProductId
 		if productId == 1 {
-			for _, v := range utils.PermissionFiccClassifyArr {
+			permissionClassifyArr, e := services.GetPermissionFirstArr(utils.COMPANY_PRODUCT_FICC_ID)
+			if e != nil {
+				br.Msg = "获取失败"
+				br.ErrMsg = "获取权限分类失败,Err:" + e.Error()
+				return
+			}
+			for _, v := range permissionClassifyArr {
 				checkList := make([]int, 0)
 				plist := new(company.ContractPermissionList)
-				items, err := company.GetPermissionLookItemsExt(productIdStr, v)
+				plist.Items = make([]*company.PermissionLookItem, 0)
+				items, err := company.GetPermissionLookItemsExtByParentId(productIdStr, v.ChartPermissionId)
 				if err != nil {
 					br.Msg = "获取失败"
 					br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
 					return
 				}
-				for _, n := range items {
-					count, err := company.GetCompanyContractPermissionCheckByContractId(companyId, companyContract.CompanyContractId, n.ChartPermissionId)
-					if err != nil {
-						br.Msg = "获取失败"
-						br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
-						return
-					}
-					if count > 0 {
-						checkList = append(checkList, n.ChartPermissionId)
+				if len(items) > 0 {
+					for _, n := range items {
+						count, err := company.GetCompanyContractPermissionCheckByContractId(companyId, companyContract.CompanyContractId, n.ChartPermissionId)
+						if err != nil {
+							br.Msg = "获取失败"
+							br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
+							return
+						}
+						if count > 0 {
+							checkList = append(checkList, n.ChartPermissionId)
+						}
 					}
+					plist.Items = items
 				}
-				plist.Items = items
-				plist.ClassifyName = v
+
+				plist.ClassifyName = v.PermissionName
 				plist.CheckList = checkList
 				list[i].PermissionList = append(list[i].PermissionList, plist)
 			}
@@ -398,30 +408,39 @@ func (this *CompanyApplyController) ApplyContractDetail() {
 	}
 
 	if detail.ProductId == 1 {
-		for _, v := range utils.PermissionFiccClassifyArr {
-			checkList := make([]int, 0)
-			plist := new(company.PermissionLookList)
-			items, err := company.GetPermissionLookItems(detail.ProductId, v)
-			if err != nil {
-				br.Msg = "获取失败"
-				br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
-				return
-			}
-			for _, n := range items {
-				count, err := company.GetCompanyContractPermissionCheckByContractId(companyId, detail.CompanyContractId, n.ChartPermissionId)
-				if err != nil {
-					br.Msg = "获取失败"
-					br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
+		//子权限切片集合
+		allFiccPermissions, permissionMap, e := services.GetBasePermissionLookItem(utils.COMPANY_PRODUCT_FICC_ID)
+		if e != nil {
+			br.Msg = "查询基础权限失败"
+			br.ErrMsg = "查询基础权限失败,Err:" + e.Error()
+			return
+		}
+		//遍历获取
+		for _, v := range allFiccPermissions {
+			if v.ParentId == 0 {
+				checkList := make([]int, 0)
+				plist := new(company.PermissionLookList)
+				items, ok := permissionMap[v.ChartPermissionId]
+				if !ok {
+					br.Msg = "获取权限信息失败"
 					return
 				}
-				if count > 0 {
-					checkList = append(checkList, n.ChartPermissionId)
+				for _, n := range items {
+					count, err := company.GetCompanyContractPermissionCheckByContractId(companyId, detail.CompanyContractId, n.ChartPermissionId)
+					if err != nil {
+						br.Msg = "获取失败"
+						br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
+						return
+					}
+					if count > 0 {
+						checkList = append(checkList, n.ChartPermissionId)
+					}
 				}
+				plist.Items = items
+				plist.ClassifyName = v.PermissionName
+				plist.CheckList = checkList
+				detail.PermissionList = append(detail.PermissionList, plist)
 			}
-			plist.Items = items
-			plist.ClassifyName = v
-			plist.CheckList = checkList
-			detail.PermissionList = append(detail.PermissionList, plist)
 		}
 	}
 
@@ -1920,30 +1939,46 @@ func (this *CompanyApplyController) ApplyContract() {
 	companyId := approvalRecord.CompanyId
 
 	if productId == 1 {
-		for _, v := range utils.PermissionFiccClassifyArr {
-			checkList := make([]int, 0)
-			plist := new(company.PermissionLookList)
-			items, err := company.GetPermissionLookItems(productId, v)
-			if err != nil {
-				br.Msg = "获取失败"
-				br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
-				return
-			}
-			for _, n := range items {
-				count, err := company.GetCompanyContractPermissionCheckByContractId(companyId, contractItem.CompanyContractId, n.ChartPermissionId)
-				if err != nil {
-					br.Msg = "获取失败"
-					br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
-					return
+		allFiccPermissions, e := company.GetPermissionLookItemsByProductId(utils.COMPANY_PRODUCT_FICC_ID)
+		if e != nil {
+			br.Msg = "获取权限信息失败"
+			br.ErrMsg = "获取权限信息失败,Err:" + e.Error()
+			return
+		}
+		permissionMap := make(map[int][]*company.PermissionLookItem, 0)
+		permissionCheckMap := make(map[int][]int, 0)
+		for _, v := range allFiccPermissions {
+			if v.ParentId > 0 {
+				permissionMap[v.ParentId] = append(permissionMap[v.ParentId], v)
+				if v.IsPublic == 1 {
+					permissionCheckMap[v.ParentId] = append(permissionCheckMap[v.ParentId], v.ChartPermissionId)
 				}
-				if count > 0 {
-					checkList = append(checkList, n.ChartPermissionId)
+			}
+		}
+		for _, v := range allFiccPermissions {
+			if v.ParentId == 0 {
+				checkList := make([]int, 0)
+				plist := new(company.PermissionLookList)
+				plist.Items = make([]*company.PermissionLookItem, 0)
+				items, ok := permissionMap[v.ChartPermissionId]
+				if ok {
+					for _, n := range items {
+						count, err := company.GetCompanyContractPermissionCheckByContractId(companyId, contractItem.CompanyContractId, n.ChartPermissionId)
+						if err != nil {
+							br.Msg = "获取失败"
+							br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
+							return
+						}
+						if count > 0 {
+							checkList = append(checkList, n.ChartPermissionId)
+						}
+					}
+					plist.Items = items
 				}
+				plist.ClassifyName = v.PermissionName
+				plist.CheckList = checkList
+				contractItem.PermissionList = append(contractItem.PermissionList, plist)
 			}
-			plist.Items = items
-			plist.ClassifyName = v
-			plist.CheckList = checkList
-			contractItem.PermissionList = append(contractItem.PermissionList, plist)
 		}
 	}
 

+ 29 - 21
controllers/company_approval.go

@@ -655,15 +655,19 @@ func (this *CompanyApprovalController) GetApprovalPermissionList() {
 	}
 
 	//子权限切片集合
-	var permissionClassifyArr []string
+	var permissionProductId int
+
 	if approvalInfo.ProductId == 1 {
-		for _, v := range utils.PermissionFiccClassifyArr {
-			permissionClassifyArr = append(permissionClassifyArr, v)
-		}
+		permissionProductId = 1
 	} else {
-		permissionClassifyArr = append(permissionClassifyArr, "权益")
+		permissionProductId = 2
+	}
+	permissionClassifyArr, err := services.GetPermissionFirstArr(permissionProductId)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取权限分类失败,Err:" + err.Error()
+		return
 	}
-
 	//获取需要审批的权限
 	delayPermissionList, err := company.GetDelayPermissionItems(approvalInfo.CompanyId, approvalInfo.CompanyApprovalId)
 	if err != nil && err.Error() != utils.ErrNoRow() {
@@ -682,26 +686,31 @@ func (this *CompanyApprovalController) GetApprovalPermissionList() {
 	for _, v := range permissionClassifyArr {
 		checkList := make([]int, 0)
 		plist := new(company.PermissionLookList)
-		items, err := company.GetPermissionLookItems(approvalInfo.ProductId, v)
+		plist.Items = make([]*company.PermissionLookItem, 0)
+		items, err := company.GetPermissionLookItemsByParentId(approvalInfo.ProductId, v.ChartPermissionId)
 		if err != nil {
 			br.Msg = "获取失败"
 			br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
 			return
 		}
-		//权益客户下,主观客观同时选择,进行合并
-		for _, n := range items {
-			if _, ok := delayPermissionIdMap[n.ChartPermissionId]; ok {
-				//if approvalInfo.ProductId == 2 {
-				//	if sandoPermissionIdMap[n.PermissionName] == 0 {
-				//		checkList = append(checkList, n.ChartPermissionId)
-				//	}
-				//	sandoPermissionIdMap[n.PermissionName] += 1
-				//} else {
-				//	checkList = append(checkList, n.ChartPermissionId)
-				//}
-				checkList = append(checkList, n.ChartPermissionId)
+		if len(items) > 0 {
+			//权益客户下,主观客观同时选择,进行合并
+			for _, n := range items {
+				if _, ok := delayPermissionIdMap[n.ChartPermissionId]; ok {
+					//if approvalInfo.ProductId == 2 {
+					//	if sandoPermissionIdMap[n.PermissionName] == 0 {
+					//		checkList = append(checkList, n.ChartPermissionId)
+					//	}
+					//	sandoPermissionIdMap[n.PermissionName] += 1
+					//} else {
+					//	checkList = append(checkList, n.ChartPermissionId)
+					//}
+					checkList = append(checkList, n.ChartPermissionId)
+				}
 			}
+			plist.Items = items
 		}
+
 		//if approvalInfo.ProductId == 2 {
 		//	for i, n := range items {
 		//		if sandoPermissionIdMap[n.PermissionName] == 1 {
@@ -709,8 +718,7 @@ func (this *CompanyApprovalController) GetApprovalPermissionList() {
 		//		}
 		//	}
 		//}
-		plist.Items = items
-		plist.ClassifyName = v
+		plist.ClassifyName = v.PermissionName
 		plist.CheckList = checkList
 		if approvalInfo.ProductId == 1 {
 			resp.FiccPermissionList = append(resp.FiccPermissionList, plist)

+ 111 - 90
controllers/company_permission.go

@@ -17,6 +17,7 @@ type CompanyPermissionController struct {
 	BaseAuthController
 }
 
+// List
 // @Title 获取权限设置基础信息
 // @Description 获取权限设置基础信息接口
 // @Param   CompanyType   query   string  true       "客户类型:传空字符串或者不传为全部,'ficc','权益'"
@@ -50,23 +51,40 @@ func (this *CompanyPermissionController) List() {
 
 	// FICC
 	if productId == utils.COMPANY_PRODUCT_FICC_ID || companyType == utils.COMPANY_PRODUCT_FICC_NAME {
-		for _, v := range utils.PermissionFiccClassifyArr {
-			checkList := make([]int, 0)
-			p := new(company.PermissionSetList)
-			p.ClassifyName = v
-			items, err := company.GetPermissionSetItems(utils.COMPANY_PRODUCT_FICC_ID, v)
-			if err != nil {
-				br.Msg = "获取失败"
-				br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
-				return
+		items, err := company.GetPermissionByProductId(utils.COMPANY_PRODUCT_FICC_ID)
+		if err != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
+			return
+		}
+		permissionMap := make(map[int][]*company.PermissionSetItem, 0)
+		permissionCheckMap := make(map[int][]int, 0)
+		for _, v := range items {
+			if v.ParentId > 0 {
+				permissionMap[v.ParentId] = append(permissionMap[v.ParentId], v)
+				if v.IsPublic == 1 {
+					permissionCheckMap[v.ParentId] = append(permissionCheckMap[v.ParentId], v.ChartPermissionId)
+				}
 			}
-			p.Items = items
-			if v == "宏观经济" {
-				checkList = append(checkList, 1)
+		}
+		for _, v := range items {
+			if v.ParentId == 0 {
+				p := new(company.PermissionSetList)
+				p.Items = make([]*company.PermissionSetItem, 0)
+				p.CheckList = make([]int, 0)
+				p.ClassifyName = v.PermissionName
+
+				if subList, ok := permissionMap[v.ChartPermissionId]; ok {
+					p.Items = subList
+				}
+
+				if checkList, ok := permissionCheckMap[v.ChartPermissionId]; ok {
+					p.CheckList = checkList
+				}
+				resp.List = append(resp.List, p)
 			}
-			p.CheckList = checkList
-			resp.List = append(resp.List, p)
 		}
+
 		br.Ret = 200
 		br.Success = true
 		br.Msg = "获取成功"
@@ -228,27 +246,41 @@ func (this *CompanyPermissionController) ListByContract() {
 
 	roleTypeCode := sysUser.RoleTypeCode
 	productId = services.GetProductId(roleTypeCode)
-	if productId == 1 {
-		for _, v := range utils.PermissionFiccClassifyArr {
-			//合同这边市场策略不需要体现出来,所以调整返回
-			if v == "市场策略" {
-				continue
-			}
-			checkList := make([]int, 0)
-			p := new(company.PermissionSetList)
-			p.ClassifyName = v
-			items, err := company.GetPermissionSetItems(productId, v)
-			if err != nil {
-				br.Msg = "获取失败"
-				br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
-				return
+	if productId == 1 || companyType == utils.COMPANY_PRODUCT_FICC_NAME {
+		allFiccPermissions, err := company.GetPermissionByProductId(utils.COMPANY_PRODUCT_FICC_ID)
+		if err != nil {
+			br.Msg = "获取失败"
+			br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
+			return
+		}
+		permissionMap := make(map[int][]*company.PermissionSetItem, 0)
+		permissionCheckMap := make(map[int][]int, 0)
+		for _, v := range allFiccPermissions {
+			if v.ParentId > 0 {
+				permissionMap[v.ParentId] = append(permissionMap[v.ParentId], v)
+				if v.IsPublic == 1 {
+					permissionCheckMap[v.ParentId] = append(permissionCheckMap[v.ParentId], v.ChartPermissionId)
+				}
 			}
-			p.Items = items
-			if v == "宏观经济" {
-				checkList = append(checkList, 1)
+		}
+		for _, v := range allFiccPermissions {
+			if v.ParentId == 0 {
+				//合同这边市场策略不需要体现出来,所以调整返回
+				if v.PermissionName == "市场策略" {
+					continue
+				}
+				p := new(company.PermissionSetList)
+				p.Items = make([]*company.PermissionSetItem, 0)
+				p.CheckList = make([]int, 0)
+				p.ClassifyName = v.PermissionName
+				if subList, ok := permissionMap[v.ChartPermissionId]; ok {
+					p.Items = subList
+				}
+				if checkList, ok := permissionCheckMap[v.ChartPermissionId]; ok {
+					p.CheckList = checkList
+				}
+				resp.List = append(resp.List, p)
 			}
-			p.CheckList = checkList
-			resp.List = append(resp.List, p)
 		}
 	} else if productId == 2 {
 		checkList := make([]int, 0)
@@ -265,25 +297,7 @@ func (this *CompanyPermissionController) ListByContract() {
 		p.CheckList = checkList
 		resp.List = append(resp.List, p)
 	} else {
-		if companyType == utils.COMPANY_PRODUCT_FICC_NAME {
-			for _, v := range utils.PermissionFiccClassifyArr {
-				checkList := make([]int, 0)
-				p := new(company.PermissionSetList)
-				p.ClassifyName = v
-				items, err := company.GetPermissionSetItems(1, v)
-				if err != nil {
-					br.Msg = "获取失败"
-					br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
-					return
-				}
-				p.Items = items
-				if v == "宏观经济" {
-					checkList = append(checkList, 1)
-				}
-				p.CheckList = checkList
-				resp.List = append(resp.List, p)
-			}
-		} else {
+		if companyType != utils.COMPANY_PRODUCT_FICC_NAME {
 			v := "权益"
 			checkList := make([]int, 0)
 			p := new(company.PermissionSetList)
@@ -336,38 +350,33 @@ func (this *CompanyPermissionController) PermissionLook() {
 	productId := services.GetProductId(roleTypeCode)
 
 	resp := new(company.PermissionLookResp)
-	permissionArr := []string{}
+	permissionArr := make([]*models.ChartPermission, 0)
+	var err error
 	if lookType == 1 {
-		if productId == 1 {
-			for _, permission := range utils.PermissionFiccClassifyArr {
-				permissionArr = append(permissionArr, permission)
-			}
-		} else if productId == 2 {
-			permissionArr = []string{"权益"}
-		} else {
-			for _, permission := range utils.PermissionAllClassifyArr {
-				permissionArr = append(permissionArr, permission)
-			}
-		}
+		permissionArr, err = services.GetPermissionFirstArr(productId)
 	} else {
-		for _, permission := range utils.PermissionAllClassifyArr {
-			permissionArr = append(permissionArr, permission)
-		}
+		permissionArr, err = services.GetPermissionFirstArr(0)
+	}
+	if err != nil {
+		br.Msg = "获取权限失败"
+		br.ErrMsg = "获取权限失败 err:" + err.Error()
+		return
 	}
 	//ficc权限类目
 	for _, v := range permissionArr {
 		checkList := make([]int, 0)
 		p := new(company.PermissionLookList)
+		p.Items = make([]*company.PermissionLookItem, 0)
 		var productId int
 		//if v == "权益" {
 		//	productId = 2
 		//} else {
 		//	productId = 1
 		//}
-		if v != "权益" {
+		if v.PermissionName != "权益" {
 			productId = 1
 			//mapPermissionName := make(map[string]int)
-			items, err := company.GetPermissionLookItems(productId, v)
+			items, err := company.GetPermissionLookItemsByParentId(productId, v.ChartPermissionId)
 			if err != nil {
 				br.Msg = "获取失败"
 				br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
@@ -413,7 +422,7 @@ func (this *CompanyPermissionController) PermissionLook() {
 				}
 				expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
 				items[i].ExpireDay = expireDay
-				items[i].ClassifyName = v
+				items[i].ClassifyName = v.PermissionName
 				if lookType == 1 {
 					permissionList = append(permissionList, items[i])
 				} else {
@@ -430,7 +439,7 @@ func (this *CompanyPermissionController) PermissionLook() {
 					mapPermissionNameList[v.PermissionName] = v.ChartPermissionId
 				}
 			}
-			p.ClassifyName = v
+			p.ClassifyName = v.PermissionName
 			//p.Items = permissionList
 			p.CheckList = checkList
 			if lookType == 1 {
@@ -452,7 +461,7 @@ func (this *CompanyPermissionController) PermissionLook() {
 	//权益权限类目
 	for _, v := range permissionArr {
 
-		if v == "权益" {
+		if v.PermissionName == "权益" {
 			// CRM8.8-权益权限列表调用较多、统一进行调整
 			unify := false
 			if lookType == 1 {
@@ -760,8 +769,34 @@ func (this *CompanyPermissionController) PermissionVariety() {
 		productId = 0
 	}
 
-	if productId == 1 {
-		for k, v := range utils.PermissionFiccClassifyArr {
+	if productId == 1 || companyType == utils.COMPANY_PRODUCT_FICC_NAME {
+		permissionFirst, e := services.GetPermissionFirstArr(utils.COMPANY_PRODUCT_FICC_ID)
+		if e != nil {
+			br.Msg = "获取权限信息失败"
+			br.ErrMsg = "获取权限信息失败,Err:" + e.Error()
+			return
+		}
+		allFiccPermissions, e := company.GetPermissionVarietyItemsByProductId(utils.COMPANY_PRODUCT_FICC_ID)
+		if e != nil {
+			br.Msg = "获取权限信息失败"
+			br.ErrMsg = "获取权限信息失败,Err:" + e.Error()
+			return
+		}
+		permissionMap := make(map[int][]*company.PermissionVarietyItem, 0)
+		for _, v := range allFiccPermissions {
+			permissionMap[v.ParentId] = append(permissionMap[v.ParentId], v)
+		}
+		for _, v := range permissionFirst {
+			p := new(company.PermissionVarietyList)
+			p.ClassifyName = v.ClassifyName
+			p.ChartPermissionId = v.ChartPermissionId + 100
+			items, ok := permissionMap[v.ChartPermissionId]
+			if ok {
+				p.Items = items
+			}
+			resp.List = append(resp.List, p)
+		}
+		/*for k, v := range utils.PermissionFiccClassifyArr {
 			p := new(company.PermissionVarietyList)
 			p.ClassifyName = v
 			p.ChartPermissionId = k + 100
@@ -773,7 +808,7 @@ func (this *CompanyPermissionController) PermissionVariety() {
 			}
 			p.Items = items
 			resp.List = append(resp.List, p)
-		}
+		}*/
 	} else if productId == 2 {
 		v := "权益"
 		p := new(company.PermissionVarietyList)
@@ -788,21 +823,7 @@ func (this *CompanyPermissionController) PermissionVariety() {
 		p.Items = items
 		resp.List = append(resp.List, p)
 	} else {
-		if companyType == utils.COMPANY_PRODUCT_FICC_NAME {
-			for k, v := range utils.PermissionFiccClassifyArr {
-				p := new(company.PermissionVarietyList)
-				p.ClassifyName = v
-				p.ChartPermissionId = k + 100
-				items, err := company.GetPermissionVarietyItems(1, v)
-				if err != nil {
-					br.Msg = "获取失败"
-					br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
-					return
-				}
-				p.Items = items
-				resp.List = append(resp.List, p)
-			}
-		} else if companyType == utils.COMPANY_PRODUCT_RAI_NAME {
+		if companyType == utils.COMPANY_PRODUCT_RAI_NAME {
 			v := "权益"
 			p := new(company.PermissionVarietyList)
 			p.ClassifyName = v

+ 58 - 13
controllers/contract/contract.go

@@ -78,6 +78,7 @@ func (this *ContractController) GetServiceTemplateList() {
 				br.ErrMsg = "获取详情模板失败,Err:" + err.Error()
 				return
 			}
+
 			tmpList[j].Detail = detail
 			// 权益存在第三级主客观套餐-CRM8.8
 			thirdList, e := contract.GetContractServiceTemplateMapByParentId(tmpList[j].ServiceTemplateId)
@@ -123,6 +124,44 @@ func (this *ContractController) GetServiceTemplateList() {
 			br.ErrMsg = "获取详情模板失败,Err:" + err.Error()
 			return
 		}
+		if productId == 1 && list[i].ServiceTemplateId == 2 {
+			// 特殊处理Ficc周报、商品双周报、数据点评的套餐显示
+			// 把detail转成go struct
+			// 查询默认的公有权限
+			publicPermissionList, tmpE := models.GetFiccPermissionSecondPublic()
+			if tmpE != nil {
+				br.Msg = "获取失败"
+				br.ErrMsg = "获取默认的公有权限失败,Err:" + tmpE.Error()
+				return
+			}
+			publicPermissionIds := make([]int, 0)
+			publicPermissionNames := make([]string, 0)
+			for _, v := range publicPermissionList {
+				publicPermissionIds = append(publicPermissionIds, v.ChartPermissionId)
+				publicPermissionNames = append(publicPermissionNames, v.PermissionName)
+			}
+			for k, v := range detail {
+				if v.Id == 4 || v.Id == 5 || v.Id == 6 {
+					detailStruct := new(contract.ServiceTemplateDetailCol2)
+					e := json.Unmarshal([]byte(v.Col2), detailStruct)
+					if e != nil {
+						br.Msg = "获取失败"
+						br.ErrMsg = "获取套餐信息失败, json.Unmarshal Err: " + e.Error()
+						return
+					}
+					//替换默认品种
+					detailStruct.ValueId = publicPermissionIds
+					detailStruct.Value = strings.Join(publicPermissionNames, ",")
+					newCol2, e := json.Marshal(detailStruct)
+					if e != nil {
+						br.Msg = "获取失败"
+						br.ErrMsg = "获取套餐信息失败, json.Marshal Err: " + e.Error()
+						return
+					}
+					detail[k].Col2 = string(newCol2)
+				}
+			}
+		}
 		if productId == 1 && contractType == "补充协议" {
 			for _, v := range detail {
 				//ficc 的合同模板的 补充协议需要将默认的宏观经济给移除掉
@@ -862,14 +901,20 @@ func contractListExport(this *ContractController, list []*contract.ContractList,
 					}
 
 					permissionList := make([]*company.PermissionSetItem, 0)
-					for _, v := range utils.PermissionFiccClassifyArr {
-						items, err := company.GetPermissionSetItems(1, v)
-						if err != nil {
-							br.Msg = "获取失败"
-							br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
-							return
+					allPermissions, permissionMap, e := services.GetBaseFiccPermissionSetItem()
+					if e != nil {
+						br.Msg = "查询基础权限失败"
+						br.ErrMsg = "查询基础权限失败,Err:" + e.Error()
+						return
+					}
+					//遍历获取
+					for _, v := range allPermissions {
+						if v.ParentId == 0 {
+							items, ok := permissionMap[v.ChartPermissionId]
+							if ok {
+								permissionList = append(permissionList, items...)
+							}
 						}
-						permissionList = append(permissionList, items...)
 					}
 
 					//权限列表
@@ -1611,7 +1656,7 @@ func (this *ContractController) Detail() {
 	if isNeedPermission {
 		checkPermissionMap, tErr := contractService.GetServicePermissionMap(contractInfo.Service)
 		if tErr == nil {
-			permissionLookListMap := make(map[string][]*contract.PermissionLookItem)
+			permissionLookListMap := make(map[int][]*contract.PermissionLookItem)
 			var permissionIds []string
 			for _, v := range checkPermissionMap {
 				permissionIds = append(permissionIds, strconv.Itoa(v))
@@ -1624,12 +1669,12 @@ func (this *ContractController) Detail() {
 					tmp.ClassifyName = v.ClassifyName
 					tmp.PermissionName = v.PermissionName
 					tmp.ChartPermissionId = v.ChartPermissionId
-					permissionLookListMap[v.ClassifyName] = append(permissionLookListMap[v.ClassifyName], tmp)
+					permissionLookListMap[v.ParentId] = append(permissionLookListMap[v.ParentId], tmp)
 				}
 				classifyNameList, tErr2 := company.GetChartPermissionFirst()
 				if tErr2 == nil {
 					for _, v := range classifyNameList {
-						if perList, ok := permissionLookListMap[v.ClassifyName]; ok {
+						if perList, ok := permissionLookListMap[v.ChartPermissionId]; ok {
 							permissionLookListRespItem := &contract.PermissionLookList{
 								ClassifyName: v.ClassifyName,
 								Items:        perList,
@@ -2998,7 +3043,7 @@ func (this *ContractController) DetailMerge() {
 	if isNeedPermission {
 		checkPermissionMap, tErr := contractService.GetServicePermissionMap(contractInfo.Service)
 		if tErr == nil {
-			permissionLookListMap := make(map[string][]*contract.PermissionLookItem)
+			permissionLookListMap := make(map[int][]*contract.PermissionLookItem)
 			var permissionIds []string
 			for _, v := range checkPermissionMap {
 				permissionIds = append(permissionIds, strconv.Itoa(v))
@@ -3011,12 +3056,12 @@ func (this *ContractController) DetailMerge() {
 					tmp.ClassifyName = v.ClassifyName
 					tmp.PermissionName = v.PermissionName
 					tmp.ChartPermissionId = v.ChartPermissionId
-					permissionLookListMap[v.ClassifyName] = append(permissionLookListMap[v.ClassifyName], tmp)
+					permissionLookListMap[v.ParentId] = append(permissionLookListMap[v.ParentId], tmp)
 				}
 				classifyNameList, tErr2 := company.GetChartPermissionFirst()
 				if tErr2 == nil {
 					for _, v := range classifyNameList {
-						if perList, ok := permissionLookListMap[v.ClassifyName]; ok {
+						if perList, ok := permissionLookListMap[v.ChartPermissionId]; ok {
 							permissionLookListRespItem := &contract.PermissionLookList{
 								ClassifyName: v.ClassifyName,
 								Items:        perList,

+ 34 - 4
controllers/contract/contract_approval.go

@@ -624,7 +624,22 @@ func contractApprovalListExport(this *ContractApprovalController, list []*contra
 					}
 
 					permissionList := make([]*company.PermissionSetItem, 0)
-					for _, v := range utils.PermissionFiccClassifyArr {
+					allPermissions, permissionMap, e := services.GetBaseFiccPermissionSetItem()
+					if e != nil {
+						br.Msg = "查询基础权限失败"
+						br.ErrMsg = "查询基础权限失败,Err:" + e.Error()
+						return
+					}
+					//遍历获取
+					for _, v := range allPermissions {
+						if v.ParentId == 0 {
+							items, ok := permissionMap[v.ChartPermissionId]
+							if ok {
+								permissionList = append(permissionList, items...)
+							}
+						}
+					}
+					/*for _, v := range utils.PermissionFiccClassifyArr {
 						items, err := company.GetPermissionSetItems(1, v)
 						if err != nil {
 							br.Msg = "获取失败"
@@ -632,7 +647,7 @@ func contractApprovalListExport(this *ContractApprovalController, list []*contra
 							return
 						}
 						permissionList = append(permissionList, items...)
-					}
+					}*/
 
 					//权限列表
 					for j := 0; j < len(permissionList); j++ {
@@ -1259,7 +1274,22 @@ func (this *ContractApprovalController) Export() {
 					}
 
 					permissionList := make([]*company.PermissionSetItem, 0)
-					for _, v := range utils.PermissionFiccClassifyArr {
+					allPermissions, permissionMap, e := services.GetBaseFiccPermissionSetItem()
+					if e != nil {
+						br.Msg = "查询基础权限失败"
+						br.ErrMsg = "查询基础权限失败,Err:" + e.Error()
+						return
+					}
+					//遍历获取
+					for _, v := range allPermissions {
+						if v.ParentId == 0 {
+							items, ok := permissionMap[v.ChartPermissionId]
+							if ok {
+								permissionList = append(permissionList, items...)
+							}
+						}
+					}
+					/*for _, v := range utils.PermissionFiccClassifyArr {
 						items, err := company.GetPermissionSetItems(1, v)
 						if err != nil {
 							br.Msg = "获取失败"
@@ -1268,7 +1298,7 @@ func (this *ContractApprovalController) Export() {
 						}
 						permissionList = append(permissionList, items...)
 					}
-
+					*/
 					//权限列表
 					for j := 0; j < len(permissionList); j++ {
 						key := fmt.Sprint(item.ServiceTemplateId, "_permission_", permissionList[j].ChartPermissionId)

+ 2 - 2
controllers/english_report/en_permission.go

@@ -198,7 +198,7 @@ func (this *EnPermissionController) ParentList() {
 		return
 	}
 
-	cond := fmt.Sprintf(` AND %s = ?`, models.EnPermissionColumns.ParentId)
+	cond := fmt.Sprintf(` enabled = 1 AND %s = ?`, models.EnPermissionColumns.ParentId)
 	pars := make([]interface{}, 0)
 	pars = append(pars, 0)
 	ob := new(models.EnPermission)
@@ -278,7 +278,7 @@ func (this *EnPermissionController) List() {
 		limitIds = ps
 	}
 
-	cond := ``
+	cond := ` AND enabled=1 `
 	pars := make([]interface{}, 0)
 	if keyword != "" {
 		k := fmt.Sprint("%", keyword, "%")

+ 67 - 46
controllers/full_company.go

@@ -2374,51 +2374,60 @@ func (this *FullCompanyController) Detail() {
 					}
 				}
 			}
-			for _, v := range utils.PermissionFiccClassifyArr {
-				checkList := make([]int, 0)
-				plist := new(company.PermissionLookList)
-				items, err := company.GetPermissionLookItems(item.ProductId, v)
-				if err != nil {
-					br.Msg = "获取失败"
-					br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
-					return
-				}
-				for itemK, n := range items {
-					permission, err := company.GetCompanyPermissionCheckItem(companyId, n.ChartPermissionId)
-					if err != nil && err.Error() != utils.ErrNoRow() {
-						br.Msg = "获取失败"
-						br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
+			//子权限切片集合
+			allFiccPermissions, permissionMap, e := services.GetBasePermissionLookItem(utils.COMPANY_PRODUCT_FICC_ID)
+			if e != nil {
+				br.Msg = "查询基础权限失败"
+				br.ErrMsg = "查询基础权限失败,Err:" + e.Error()
+				return
+			}
+			//遍历获取
+			for _, v := range allFiccPermissions {
+				if v.ParentId == 0 {
+					checkList := make([]int, 0)
+					plist := new(company.PermissionLookList)
+					items, ok := permissionMap[v.ChartPermissionId]
+					if !ok {
+						br.Msg = "获取权限信息失败"
 						return
 					}
-					if permission != nil && permission.ChartPermissionId > 0 {
-						checkList = append(checkList, n.ChartPermissionId)
-						items[itemK].StartDate = permission.StartDate
-						items[itemK].EndDate = permission.EndDate
-						items[itemK].Status = permission.Status
+					for itemK, n := range items {
+						permission, err := company.GetCompanyPermissionCheckItem(companyId, n.ChartPermissionId)
+						if err != nil && err.Error() != utils.ErrNoRow() {
+							br.Msg = "获取失败"
+							br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
+							return
+						}
+						if permission != nil && permission.ChartPermissionId > 0 {
+							checkList = append(checkList, n.ChartPermissionId)
+							items[itemK].StartDate = permission.StartDate
+							items[itemK].EndDate = permission.EndDate
+							items[itemK].Status = permission.Status
 
-						endDateTime, _ := time.Parse(utils.FormatDate, permission.EndDate)
-						endDateTime = endDateTime.AddDate(0, 0, 1)
-						sub := endDateTime.Sub(time.Now())
-						if sub < 0 {
-							sub = 0
+							endDateTime, _ := time.Parse(utils.FormatDate, permission.EndDate)
+							endDateTime = endDateTime.AddDate(0, 0, 1)
+							sub := endDateTime.Sub(time.Now())
+							if sub < 0 {
+								sub = 0
+							}
+							expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
+							items[itemK].ExpireDay = expireDay
 						}
-						expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
-						items[itemK].ExpireDay = expireDay
+						//count, err := company.GetCompanyPermissionCheck(companyId, n.ChartPermissionId)
+						//if err != nil {
+						//	br.Msg = "获取失败"
+						//	br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
+						//	return
+						//}
+						//if count > 0 {
+						//	checkList = append(checkList, n.ChartPermissionId)
+						//}
 					}
-					//count, err := company.GetCompanyPermissionCheck(companyId, n.ChartPermissionId)
-					//if err != nil {
-					//	br.Msg = "获取失败"
-					//	br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
-					//	return
-					//}
-					//if count > 0 {
-					//	checkList = append(checkList, n.ChartPermissionId)
-					//}
+					plist.Items = items
+					plist.ClassifyName = v.PermissionName
+					plist.CheckList = checkList
+					item.PermissionList = append(item.PermissionList, plist)
 				}
-				plist.Items = items
-				plist.ClassifyName = v
-				plist.CheckList = checkList
-				item.PermissionList = append(item.PermissionList, plist)
 			}
 			resp.FiccItem = item
 			if (roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
@@ -2635,8 +2644,19 @@ func (this *FullCompanyController) PermissionLook() {
 	}
 
 	resp := new(company.PermissionLookResp)
-	permissionArr := []string{}
+	permissionArr := make([]*models.ChartPermission, 0)
+	var err error
 	if lookType == 1 {
+		permissionArr, err = services.GetPermissionFirstArr(productId)
+	} else {
+		permissionArr, err = services.GetPermissionFirstArr(0)
+	}
+	if err != nil {
+		br.Msg = "获取权限失败"
+		br.ErrMsg = "获取权限失败 err:" + err.Error()
+		return
+	}
+	/*if lookType == 1 {
 		if productId == 1 {
 			for _, permission := range utils.PermissionFiccClassifyArr {
 				permissionArr = append(permissionArr, permission)
@@ -2652,21 +2672,22 @@ func (this *FullCompanyController) PermissionLook() {
 		for _, permission := range utils.PermissionAllClassifyArr {
 			permissionArr = append(permissionArr, permission)
 		}
-	}
+	}*/
 	//ficc权限类目
 	for _, v := range permissionArr {
 		checkList := make([]int, 0)
 		p := new(company.PermissionLookList)
+		p.Items = make([]*company.PermissionLookItem, 0)
 		var productId int
 		//if v == "权益" {
 		//	productId = 2
 		//} else {
 		//	productId = 1
 		//}
-		if v != "权益" {
+		if v.PermissionName != "权益" {
 			productId = 1
 			//mapPermissionName := make(map[string]int)
-			items, err := company.GetPermissionLookItems(productId, v)
+			items, err := company.GetPermissionLookItemsByParentId(productId, v.ChartPermissionId)
 			if err != nil {
 				br.Msg = "获取失败"
 				br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
@@ -2712,7 +2733,7 @@ func (this *FullCompanyController) PermissionLook() {
 				}
 				expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
 				items[i].ExpireDay = expireDay
-				items[i].ClassifyName = v
+				items[i].ClassifyName = v.PermissionName
 				if lookType == 1 {
 					permissionList = append(permissionList, items[i])
 				} else {
@@ -2729,7 +2750,7 @@ func (this *FullCompanyController) PermissionLook() {
 					mapPermissionNameList[v.PermissionName] = v.ChartPermissionId
 				}
 			}
-			p.ClassifyName = v
+			p.ClassifyName = v.PermissionName
 			//p.Items = permissionList
 			p.CheckList = checkList
 			if lookType == 1 {
@@ -2745,7 +2766,7 @@ func (this *FullCompanyController) PermissionLook() {
 	//权益权限类目
 	for _, v := range permissionArr {
 
-		if v == "权益" {
+		if v.PermissionName == "权益" {
 			// CRM8.8-权益权限列表调用较多、统一进行调整
 			unify := false
 			if lookType == 1 {

+ 12 - 0
controllers/report.go

@@ -202,6 +202,12 @@ func (this *ReportController) SetDayWeekReportUpdateRule() {
 		br.ErrMsg = "设置暂停时间失败, Err: " + err.Error()
 		return
 	}
+	// 同步eta系统的章节更新配置
+	go func() {
+		ruleSyncReq := new(services.EditReportChapterTypeRuleSyncReq)
+		ruleSyncReq.ResearchType = researchType
+		_, _ = services.EditReportChapterTypeRuleSync(ruleSyncReq)
+	}()
 
 	br.Ret = 200
 	br.Success = true
@@ -252,6 +258,12 @@ func (this *ReportController) SetDayWeekReportEnableRule() {
 		return
 	}
 
+	// 同步eta系统的章节更新配置
+	go func() {
+		ruleSyncReq := new(services.EditReportChapterTypeRuleSyncReq)
+		_, _ = services.EditReportChapterTypeRuleSync(ruleSyncReq)
+	}()
+
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "操作成功"

+ 150 - 0
controllers/report_chapter_type.go

@@ -0,0 +1,150 @@
+package controllers
+
+import (
+	"encoding/json"
+	"hongze/hz_crm_api/models"
+	"hongze/hz_crm_api/services"
+	"hongze/hz_crm_api/utils"
+)
+
+// ReportChapterTypeController 报告章节配置
+type ReportChapterTypeController struct {
+	BaseAuthController
+}
+
+// List
+// @Title 报告章节列表
+// @Description 报告章节列表
+// @Param   ReportType  query  string  true  "报告类型: day-晨报; week-周报"
+// @Success 200 {object} models.ReportChapterTypePageListResp
+// @router /chapter_type/list [get]
+func (this *ReportChapterTypeController) List() {
+	br := new(models.BaseResponse).Init()
+	br.IsSendEmail = false
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	sysUser := this.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+	reportType := this.GetString("ReportType")
+	typeArr := []string{utils.REPORT_TYPE_DAY, utils.REPORT_TYPE_WEEK}
+	if !utils.InArrayByStr(typeArr, reportType) {
+		br.Msg = "请选择报告类型"
+		return
+	}
+
+	cond := ` AND research_type = ?`
+	pars := make([]interface{}, 0)
+	pars = append(pars, reportType)
+	list, e := models.GetReportChapterTypePageList(cond, pars)
+	if e != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取报告章节列表失败, Err: " + e.Error()
+		return
+	}
+	respList := make([]*models.ReportChapterTypeListItem, 0)
+	for i := range list {
+		respList = append(respList, &models.ReportChapterTypeListItem{
+			ReportChapterTypeId:   list[i].ReportChapterTypeId,
+			ReportChapterTypeName: list[i].ReportChapterTypeName,
+			Sort:                  list[i].Sort,
+			CreatedTime:           list[i].CreatedTime.Format(utils.FormatDateTime),
+			ResearchType:          list[i].ResearchType,
+			SelectedImage:         list[i].SelectedImage,
+			UnselectedImage:       list[i].UnselectedImage,
+			WordsImage:            list[i].YbBottomIcon, // 此处的不一样
+			EditImgUrl:            list[i].EditImgUrl,
+			IsShow:                list[i].IsShow,
+			Enabled:               list[i].Enabled,
+		})
+	}
+
+	resp := new(models.ReportChapterTypeListResp)
+	resp.List = respList
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}
+
+// Edit
+// @Title 编辑报告章节
+// @Description 编辑报告章节
+// @Param	request  body  models.ReportChapterTypeEditReq  true  "type json string"
+// @Success 200 string "操作成功"
+// @router /chapter_type/edit [post]
+func (this *ReportChapterTypeController) Edit() {
+	br := new(models.BaseResponse).Init()
+	br.IsSendEmail = false
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	sysUser := this.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+	var req models.ReportChapterTypeEditReq
+	if err := json.Unmarshal(this.Ctx.Input.RequestBody, &req); err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	if req.ReportChapterTypeId <= 0 {
+		br.Msg = "章节ID有误"
+		return
+	}
+
+	item, e := models.GetReportChapterTypeById(req.ReportChapterTypeId)
+	if e != nil {
+		br.Msg = "操作失败"
+		br.ErrMsg = "获取报告章节失败, Err:" + e.Error()
+		return
+	}
+
+	item.SelectedImage = req.SelectedImage
+	item.UnselectedImage = req.UnselectedImage
+	item.PcSelectedImage = req.SelectedImage
+	item.PcUnselectedImage = req.UnselectedImage
+	item.EditImgUrl = req.EditImgUrl
+	item.YbIconUrl = req.UnselectedImage
+	item.YbBottomIcon = req.WordsImage
+	item.IsShow = req.IsShow
+	item.ReportChapterTypeThumb = req.EditImgUrl
+	item.BannerUrl = req.UnselectedImage
+
+	updateCols := []string{"SelectedImage", "UnselectedImage",
+		"PcSelectedImage", "PcUnselectedImage", "EditImgUrl", "YbIconUrl", "YbBottomIcon", "IsShow",
+		"ReportChapterTypeThumb", "BannerUrl",
+	}
+	if e = item.Update(updateCols); e != nil {
+		br.Msg = "操作失败"
+		br.ErrMsg = "更新报告章节失败, Err:" + e.Error()
+		return
+	}
+
+	// 清除小程序端的章节缓存
+	{
+		key := "hongze_yb:report_chapter_type:GetEffectTypeID"
+		_ = utils.Rc.Delete(key)
+	}
+	// 同步eta系统的章节小程序配置
+	go func() {
+		var reqEta services.EditReportChapterTypeSyncReq
+		reqEta.ReportChapterTypeId = req.ReportChapterTypeId
+		_, _ = services.EditReportChapterTypeSync(&reqEta)
+	}()
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "操作成功"
+}

+ 8 - 33
models/advisory/chart_permission.go

@@ -1,7 +1,6 @@
 package advisory
 
 import (
-	"fmt"
 	"github.com/beego/beego/v2/client/orm"
 )
 
@@ -18,7 +17,7 @@ type ChartPermissionResp struct {
 	List []*ChartPermission
 }
 
-//用户关注的分类
+// 用户关注的分类
 type ChartPermissionListResp struct {
 	ChartPermissionId   int    `description:"权限id"`
 	ChartPermissionName string `description:"名称"`
@@ -32,7 +31,7 @@ type GetChartPermissionAllByChartIdResp struct {
 	ChartPermissionId int `description:"权限id"`
 }
 
-//用户关注的分类
+// 用户关注的分类
 type MyChartPermission struct {
 	ChartPermissionId   int    `description:"权限id"`
 	ClassifyName        string `description:"分类名称"`
@@ -59,30 +58,6 @@ type NoAdminInfoResp struct {
 	List []*MyChartPermission
 }
 
-//获取一级分类名称
-func AdvisoryGetFirstChartPermissionAll() (items []*ChartPermission, err error) {
-	o := orm.NewOrm()
-	sql := `SELECT  * FROM chart_permission as ch  WHERE product_id = 1  AND product_name = 'ficc'  GROUP BY ch.classify_name ORDER BY sort ASC; `
-	_, err = o.Raw(sql).QueryRows(&items)
-	return
-}
-
-//获取关注分类名称
-func GetChartPermissionByIds(Ids string) (items []*MyChartPermission, err error) {
-	o := orm.NewOrm()
-	sql := `SELECT * FROM chart_permission WHERE chart_permission_id IN (` + Ids + `)`
-	fmt.Println(sql)
-	_, err = o.Raw(sql).QueryRows(&items)
-	return
-}
-
-func AdvisoryGetChartToClassifyName(ClassifyName string) (items []*ChartPermission, err error) {
-	o := orm.NewOrm()
-	sql := `SELECT * FROM chart_permission  WHERE product_id = 1  AND product_name = 'ficc' AND classify_name = ?  ORDER BY sort ASC `
-	_, err = o.Raw(sql, ClassifyName).QueryRows(&items)
-	return
-}
-
 func GetCategoryInfoById(chartPermissionId int) (item *ChartPermission, err error) {
 	o := orm.NewOrm()
 	//o.Using("rddp")
@@ -91,10 +66,10 @@ func GetCategoryInfoById(chartPermissionId int) (item *ChartPermission, err erro
 	return
 }
 
-//获取分类列表
+// 获取分类列表
 func GetChartPermissionList() (items []*MyChartPermission, err error) {
 	o := orm.NewOrm()
-	sql := `SELECT  * FROM chart_permission as ch  WHERE product_id = 1  AND product_name = 'ficc'   ORDER BY sort ASC; `
+	sql := `SELECT  * FROM chart_permission as ch  WHERE product_id = 1  AND product_name = 'ficc' and parent_id > 0  ORDER BY sort ASC; `
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }
@@ -109,7 +84,7 @@ type GetBuChartPermissionRespLIst struct {
 	List []*GetBuChartPermissionResp
 }
 
-//获取用户购买的分类信息
+// 获取用户购买的分类信息
 func GetBuChartPermission(CompanyId int, pars []interface{}) (items []*GetBuChartPermissionResp, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT ch.chart_permission_id , ch.permission_name ,ch.image_url  FROM chart_permission  as ch INNER JOIN company_report_permission as co ON co.chart_permission_id = ch.chart_permission_id WHERE co.company_id = ? `
@@ -117,7 +92,7 @@ func GetBuChartPermission(CompanyId int, pars []interface{}) (items []*GetBuChar
 	return
 }
 
-//获取分类列表
+// 获取分类列表
 func GetPermissionList(condition string, pars []interface{}, startSize, pageSize int) (items []*ChartPermission, err error) {
 	sql := ` SELECT * FROM chart_permission WHERE 1=1 `
 	if condition != "" {
@@ -129,7 +104,7 @@ func GetPermissionList(condition string, pars []interface{}, startSize, pageSize
 	return
 }
 
-//获取用户权限的一级分类名称
+// 获取用户权限的一级分类名称
 func GetFirstChartPermissionAllByUser(Ids string) (items []*ChartPermission, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT  * FROM chart_permission as ch  WHERE product_id = 1  AND product_name = 'ficc' AND chart_permission_id IN (` + Ids + `)` + ` GROUP BY ch.classify_name ORDER BY sort ASC; `
@@ -137,7 +112,7 @@ func GetFirstChartPermissionAllByUser(Ids string) (items []*ChartPermission, err
 	return
 }
 
-//获取用户权限的二级分类名称
+// 获取用户权限的二级分类名称
 func GetChartToClassifyNameByUser(ClassifyName, Ids string) (items []*ChartPermission, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT * FROM chart_permission  WHERE product_id = 1  AND product_name = 'ficc' AND classify_name = ?   AND chart_permission_id IN (` + Ids + `)`

+ 33 - 15
models/chart_permission.go

@@ -27,6 +27,8 @@ type ChartPermission struct {
 	CygxAuth            int       `description:"是否是权限,用于查研观向小程序前台权限校验"`
 	YbImgUrl            string    `description:"研报小程序报告列表icon"`
 	PriceDrivenState    int       `description:"品种价格驱动开启状态 0-关闭 1-开启"`
+	ParentId            int       `description:"父级权限id"`
+	IsPublic            int       `description:"是否是公有权限1:公有权限,0私有权限"`
 }
 
 // GetChartPermissionById 主键获取权限
@@ -70,26 +72,42 @@ func GetFiccPermissionExceptTactic() (items []*ChartPermission, err error) {
 	return
 }
 
-// GetPermissionByProductIdAndClassifyName 获取子分类
-func GetPermissionByProductIdAndClassifyName(productId int, classifyName string) (items []*ChartPermission, err error) {
+// GetFiccPermissionSecondPublic 获取ficc公有的二级品种
+func GetFiccPermissionSecondPublic() (items []*ChartPermission, err error) {
 	o := orm.NewOrm()
-	sql := `SELECT * FROM chart_permission WHERE enabled = 1 AND product_id = ? AND classify_name = ? AND permission_type = 0 ORDER BY sort ASC`
-	_, err = o.Raw(sql, productId, classifyName).QueryRows(&items)
+	sql := `SELECT * FROM chart_permission WHERE enabled = 1 AND permission_type = 0 AND product_id = 1 and parent_id>0 and is_public=1 ORDER BY sort ASC`
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
+// GetPermissionFirstByProductId 获取一级品种
+func GetPermissionFirstByProductId(productId int) (items []*ChartPermission, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM chart_permission WHERE enabled = 1 AND product_id = ? and parent_id=0  ORDER BY sort ASC`
+	_, err = o.Raw(sql, productId).QueryRows(&items)
 	return
 }
 
-// GetYbChartPermissionFirstByName 根据分类名称获取一级分类
-func GetYbChartPermissionFirstByName(classifyName string) (item *YbChartPermissionFirst, err error) {
+// GetPermissionFirst 获取一级品种
+func GetPermissionFirst() (items []*ChartPermission, err error) {
 	o := orm.NewOrm()
-	sql := `SELECT * FROM chart_permission_first WHERE classify_name = ? LIMIT 1`
-	err = o.Raw(sql, classifyName).QueryRow(&item)
+	sql := `SELECT * FROM chart_permission WHERE enabled = 1 and parent_id=0  ORDER BY sort ASC`
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
+// GetPermissionByProductIdAndClassifyName 获取子分类
+func GetPermissionByProductIdAndClassifyName(productId int, classifyName string) (items []*ChartPermission, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM chart_permission WHERE parent_id > 0 and enabled = 1 AND product_id = ? AND classify_name = ? AND permission_type = 0 ORDER BY sort ASC`
+	_, err = o.Raw(sql, productId, classifyName).QueryRows(&items)
 	return
 }
 
 // GetChartPermissionById 主键获取权限
 func GetChartPermissionByRemark(remark string) (item *ChartPermission, err error) {
 	o := orm.NewOrm()
-	sql := `SELECT * FROM chart_permission WHERE remark = ? LIMIT 1`
+	sql := `SELECT * FROM chart_permission WHERE parent_id > 0 and remark = ?  LIMIT 1`
 	err = o.Raw(sql, remark).QueryRow(&item)
 	return
 }
@@ -99,7 +117,7 @@ func GetChartPermissionByIds(permissionIds []string) (list []*ChartPermission, e
 	qb, _ := orm.NewQueryBuilder("mysql")
 	// 构建查询对象
 	qb.Select("*").From("chart_permission").
-		Where("chart_permission_id").In(permissionIds...)
+		Where("parent_id > 0 and chart_permission_id").In(permissionIds...)
 	// 导出 SQL 语句
 	sql := qb.String()
 
@@ -117,7 +135,7 @@ func GetChartPermissionByIdList(chartPermissionIdList []int) (list []*ChartPermi
 	}
 
 	o := orm.NewOrm()
-	sql := `select * from chart_permission where chart_permission_id in (` + utils.GetOrmInReplace(num) + `)`
+	sql := `select * from chart_permission where parent_id > 0 and chart_permission_id in (` + utils.GetOrmInReplace(num) + `)`
 	_, err = o.Raw(sql, chartPermissionIdList).QueryRows(&list)
 
 	return
@@ -128,7 +146,7 @@ func GetChartPermissionByNames(permissionNames []string) (list []*ChartPermissio
 	qb, _ := orm.NewQueryBuilder("mysql")
 	// 构建查询对象
 	qb.Select("*").From("chart_permission").
-		Where("chart_permission_name").In(permissionNames...)
+		Where("parent_id > 0 and chart_permission_name").In(permissionNames...)
 	// 导出 SQL 语句
 	sql := qb.String()
 
@@ -141,14 +159,14 @@ func GetChartPermissionByNames(permissionNames []string) (list []*ChartPermissio
 // GetChartPermissionList 获取品种权限列表
 func GetChartPermissionList() (list []*ChartPermission, err error) {
 	o := orm.NewOrm()
-	sql := `SELECT * FROM chart_permission ORDER BY product_id ASC, sort ASC`
+	sql := `SELECT * FROM chart_permission WHERE parent_id > 0 ORDER BY product_id ASC, sort ASC`
 	_, err = o.Raw(sql).QueryRows(&list)
 	return
 }
 
 func GetChartPermissionListRai() (items []*ChartPermission, err error) {
 	o := orm.NewOrm()
-	sql := `SELECT * FROM chart_permission WHERE product_id=2  ORDER BY sort ASC `
+	sql := `SELECT * FROM chart_permission WHERE product_id=2 and parent_id > 0  ORDER BY sort ASC `
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }
@@ -156,7 +174,7 @@ func GetChartPermissionListRai() (items []*ChartPermission, err error) {
 // 获取权益主观权限
 func GetChartPermissionListRaiSubjectivity() (items []*ChartPermission, err error) {
 	o := orm.NewOrm()
-	sql := `SELECT * FROM chart_permission WHERE product_id=2  AND permission_type = 1  ORDER BY sort ASC `
+	sql := `SELECT * FROM chart_permission WHERE product_id=2  AND permission_type = 1 and parent_id > 0  ORDER BY sort ASC `
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }

+ 3 - 3
models/classify.go

@@ -2,7 +2,6 @@ package models
 
 import (
 	"github.com/beego/beego/v2/client/orm"
-	"github.com/rdlucklib/rdluck_tools/paging"
 	"hongze/hz_crm_api/utils"
 	"time"
 )
@@ -39,6 +38,7 @@ type Classify struct {
 	RelateTel         int       `description:"是否在电话会中可选: 0-否; 1-是"`
 	RelateVideo       int       `description:"是否在路演视频中可选: 0-否; 1-是"`
 	IsMassSend        int       `description:"1:群发,0:非群发"`
+	Enabled           int       `description:"是否可用,1可用,0禁用"`
 }
 
 func GetClassifyById(classifyId int) (item *Classify, err error) {
@@ -71,6 +71,7 @@ type ClassifyList struct {
 	YbRightBanner     string    `description:"Pc端详情页,右侧,报告合集背景图"`
 	RelateTel         int       `description:"是否在电话会中可选: 0-否; 1-是"`
 	RelateVideo       int       `description:"是否在路演视频中可选: 0-否; 1-是"`
+	Enabled           int       `description:"是否可用,1可用,0禁用"`
 	Child             []*ClassifyItem
 	ClassifyMenuList  []*ClassifyMenu
 }
@@ -82,8 +83,7 @@ type ClassifyItem struct {
 }
 
 type ClassifyListResp struct {
-	List   []*ClassifyList
-	Paging *paging.PagingItem `description:"分页数据"`
+	List []*ClassifyList
 }
 
 // 获取分类列表

+ 60 - 15
models/company/company_permission.go

@@ -21,14 +21,19 @@ type ChartPermission struct {
 	ClassifyName        string    `description:"分类"`
 	PermissionType      int       `description:"1主观,2客观"`
 	Checked             bool      `description:"选中状态"`
+	ParentId            int       `description:"父级权限id"`
+	IsPublic            int       `description:"是否是公有权限1:公有权限,0私有权限"`
 }
 
 type PermissionSetItem struct {
-	ChartPermissionId int                  `description:"权限id"`
-	PermissionName    string               `description:"权限名称"`
-	PermissionType    int                  `description:"1主观,2客观"`
-	Checked           bool                 `description:"选中状态"`
-	Child             []*PermissionSetItem `description:"具体的主客观-方便前端的排版用的"`
+	ChartPermissionId int    `description:"权限id"`
+	PermissionName    string `description:"权限名称"`
+	PermissionType    int    `description:"1主观,2客观"`
+	ParentId          int    `description:"父级权限id"`
+	IsPublic          int    `description:"是否是公有权限1:公有权限,0私有权限"`
+	Checked           bool   `description:"选中状态"`
+
+	Child []*PermissionSetItem `description:"具体的主客观-方便前端的排版用的"`
 }
 
 type PermissionSetItemType struct {
@@ -58,26 +63,33 @@ type PermissionSetResp struct {
 }
 
 type ChartPermissionFirst struct {
-	ClassifyName string `description:"分类"`
+	ChartPermissionId int    `description:"权限id"`
+	ClassifyName      string `description:"分类"`
 }
 
 func GetPermissionSetItems(productId int, classifyName string) (items []*PermissionSetItem, err error) {
 	o := orm.NewOrm()
-	sql := ` SELECT * FROM chart_permission WHERE enabled=1 AND product_id=? AND classify_name=?  AND permission_type=0 ORDER BY sort ASC `
+	sql := ` SELECT * FROM chart_permission WHERE enabled=1 AND product_id=? AND classify_name=? AND parent_id>0 AND permission_type=0 ORDER BY sort ASC `
 	_, err = o.Raw(sql, productId, classifyName).QueryRows(&items)
 	return
 }
 
+func GetPermissionByProductId(productId int) (items []*PermissionSetItem, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT * FROM chart_permission WHERE enabled=1 AND product_id=? AND permission_type=0 ORDER BY sort ASC `
+	_, err = o.Raw(sql, productId).QueryRows(&items)
+	return
+}
 func GetPermissionSetItemsByType(productId int, classifyName string) (items []*PermissionSetItem, err error) {
 	o := orm.NewOrm()
-	sql := ` SELECT * FROM chart_permission WHERE enabled=1 AND product_id=? AND classify_name=?  AND permission_type!=2 ORDER BY sort ASC `
+	sql := ` SELECT * FROM chart_permission WHERE enabled=1 AND product_id=? AND classify_name=? AND parent_id>0 AND permission_type!=2 ORDER BY sort ASC `
 	_, err = o.Raw(sql, productId, classifyName).QueryRows(&items)
 	return
 }
 
 func GetPermissionSetSandoItems(productId int, classifyName string) (items []*PermissionLookItem, err error) {
 	o := orm.NewOrm()
-	sql := ` SELECT * FROM chart_permission WHERE enabled=1 AND product_id=? AND classify_name=?  ORDER BY sort ASC `
+	sql := ` SELECT * FROM chart_permission WHERE enabled=1 AND product_id=? AND classify_name=? AND parent_id>0 ORDER BY sort ASC `
 	_, err = o.Raw(sql, productId, classifyName).QueryRows(&items)
 	return
 }
@@ -164,16 +176,33 @@ type PermissionLookItem struct {
 	IsUpgrade          int                   `description:"是否升级,1是,0否"`
 	ExpensiveYx        int                   `description:"权益研选: 0-3w; 1-5w ,2: 10W"`
 	Points             float64               `description:"研选扣点包点数"`
+	ParentId           int                   `description:"父级权限id"`
+	IsPublic           int                   `description:"是否是公有权限1:公有权限,0私有权限"`
 	Child              []*PermissionLookItem `description:"子权限"`
 }
 
+// todo 确认是否需要删除
 func GetPermissionLookItems(productId int, classifyName string) (items []*PermissionLookItem, err error) {
 	o := orm.NewOrm()
-	sql := ` SELECT * FROM chart_permission WHERE enabled=1 AND product_id=? AND classify_name=? ORDER BY sort ASC `
+	sql := ` SELECT * FROM chart_permission WHERE enabled=1 AND product_id=? AND classify_name=? AND parent_id > 0 ORDER BY sort ASC `
 	_, err = o.Raw(sql, productId, classifyName).QueryRows(&items)
 	return
 }
 
+func GetPermissionLookItemsByProductId(productId int) (items []*PermissionLookItem, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT * FROM chart_permission WHERE enabled=1 AND product_id=? ORDER BY sort ASC `
+	_, err = o.Raw(sql, productId).QueryRows(&items)
+	return
+}
+
+func GetPermissionLookItemsByParentId(productId int, parentId int) (items []*PermissionLookItem, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT * FROM chart_permission WHERE enabled=1 AND product_id=? AND parent_id=? ORDER BY sort ASC `
+	_, err = o.Raw(sql, productId, parentId).QueryRows(&items)
+	return
+}
+
 func GetCompanyPermissionCheck(companyId, permissionId int) (count int, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT COUNT(1) AS count FROM company_report_permission AS a WHERE a.company_id=? AND a.chart_permission_id=? `
@@ -203,6 +232,7 @@ func GetPermissionIdById(permissionIds string) (allpermissionId string, err erro
 			FROM
 				chart_permission 
 			WHERE
+			    parent_id > 0 and 
 				product_permission_name IN (
 				SELECT
 					product_permission_name 
@@ -251,6 +281,7 @@ type PermissionVarietyResp struct {
 
 type PermissionVarietyItem struct {
 	ChartPermissionId int    `description:"权限id"`
+	ParentId          int    `description:"父级权限id"`
 	ClassifyName      string `orm:"column(permission_name)" description:"权限名称"`
 }
 
@@ -260,13 +291,21 @@ type PermissionVarietyList struct {
 	Items             []*PermissionVarietyItem
 }
 
+// todo 删除品种列表
 func GetPermissionVarietyItems(productId int, classifyName string) (items []*PermissionVarietyItem, err error) {
 	o := orm.NewOrm()
-	sql := ` SELECT * FROM chart_permission WHERE enabled=1 AND product_id=? AND classify_name=? GROUP BY permission_name ORDER BY sort ASC `
+	sql := ` SELECT * FROM chart_permission WHERE enabled=1 AND product_id=? AND classify_name=?  AND parent_id > 0 GROUP BY permission_name ORDER BY sort ASC `
 	_, err = o.Raw(sql, productId, classifyName).QueryRows(&items)
 	return
 }
 
+func GetPermissionVarietyItemsByProductId(productId int) (items []*PermissionVarietyItem, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT * FROM chart_permission WHERE enabled=1 AND product_id=? and parent_id > 0 GROUP BY permission_name ORDER BY sort ASC `
+	_, err = o.Raw(sql, productId).QueryRows(&items)
+	return
+}
+
 func GetCompanyReportPermission(companyId, productId int) (items []*CompanyReportPermission, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT * FROM company_report_permission WHERE company_id=? AND product_id=? `
@@ -349,10 +388,16 @@ func FixPermissionStatus(companyId, productId int, startDate, endDate, status st
 
 func GetPermissionLookItemsExt(productId string, classifyName string) (items []*PermissionLookItem, err error) {
 	o := orm.NewOrm()
-	sql := ` SELECT * FROM chart_permission WHERE enabled=1 AND product_id IN(` + productId + `) AND classify_name=? ORDER BY sort ASC `
+	sql := ` SELECT * FROM chart_permission WHERE enabled=1 AND product_id IN(` + productId + `) AND classify_name=? AND parent_id > 0 ORDER BY sort ASC `
 	_, err = o.Raw(sql, classifyName).QueryRows(&items)
 	return
 }
+func GetPermissionLookItemsExtByParentId(productId string, parentId int) (items []*PermissionLookItem, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT * FROM chart_permission WHERE enabled=1 AND product_id IN(` + productId + `) AND parent_id=? ORDER BY sort ASC `
+	_, err = o.Raw(sql, parentId).QueryRows(&items)
+	return
+}
 
 // 客户授权产品结构体(包含产品名称)
 type CompanyReportPermissionAndName struct {
@@ -429,7 +474,7 @@ func GetPermissionLookItemsSandO(permissionIds string) (items []*PermissionLookI
 
 func GetPermissionLookItemsSandOByName(permissionName string) (items []*PermissionLookItem, err error) {
 	o := orm.NewOrm()
-	sql := ` SELECT * FROM chart_permission WHERE enabled=1  AND product_id = 2 AND remark IN (` + permissionName + `) ORDER BY sort ASC `
+	sql := ` SELECT * FROM chart_permission WHERE enabled=1  AND product_id = 2 AND remark IN (` + permissionName + `) AND parent_id > 0 ORDER BY sort ASC `
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }
@@ -458,7 +503,7 @@ func GetGroupNamesById(gid int) (items *string, err error) {
 // GetChartPermissionFirst 获取排序后的权限分类
 func GetChartPermissionFirst() (list []*ChartPermissionFirst, err error) {
 	o := orm.NewOrm()
-	sql := ` SELECT classify_name FROM chart_permission_first ORDER BY yb_index_sort ASC `
+	sql := ` SELECT chart_permission_id, classify_name FROM chart_permission where enabled =1 and product_id=1 and parent_id=0 ORDER BY sort ASC `
 	_, err = o.Raw(sql).QueryRows(&list)
 	return
 }
@@ -543,7 +588,7 @@ func GetPermissionIdsByPermissionNames(names []string) (ids []int, err error) {
 			FROM
 				chart_permission
 			WHERE
-				chart_permission_name IN (` + utils.GetOrmInReplace(len(names)) + `)`
+				chart_permission_name IN (` + utils.GetOrmInReplace(len(names)) + `) AND parent_id > 0 `
 	_, err = o.Raw(sql, names).QueryRows(&ids)
 	return
 }

+ 11 - 2
models/contract/contract_service_detail.go

@@ -21,7 +21,16 @@ type ContractServiceDetail struct {
 	CreateTime        time.Time `description:"数据添加时间"`
 }
 
-//根据服务模板id获取对应的套餐表格数据详情
+type ServiceTemplateDetailCol2 struct {
+	CanEdit  bool   `json:"CanEdit"`
+	Type     string `json:"Type"`
+	ValueId  []int  `json:"ValueId"`
+	Value    string `json:"Value"`
+	HeadName string `json:"HeadName"`
+	RowName  string `json:"RowName"`
+}
+
+// 根据服务模板id获取对应的套餐表格数据详情
 func GetContractServiceDetailByTemplateId(serviceTemplateId int) (list []*ContractServiceDetail, err error) {
 	o := orm.NewOrm()
 	sql := `select * from contract_service_detail where service_template_id = ? and contract_service_id = 0 order by id asc`
@@ -45,7 +54,7 @@ func GetContractServiceDetailListByServiceIds(contractServiceIds string) (list [
 	return
 }
 
-//根据服务模板id获取对应的套餐表格数据详情
+// 根据服务模板id获取对应的套餐表格数据详情
 func GetContractServiceDetailList() (list []*ContractServiceDetail, err error) {
 	o := orm.NewOrm()
 	sql := `select * from contract_service_detail order by id asc`

+ 10 - 10
models/cygx/chart_permission.go

@@ -32,7 +32,7 @@ func GetChartPermissionAll() (items []*ChartPermission, err error) {
 // 获取带有ICo的产业
 func GetChartPermissionIco(condition string) (items []*ChartPermission, err error) {
 	o := orm.NewOrm()
-	sql := `SELECT * FROM chart_permission  WHERE 1=1 `
+	sql := `SELECT * FROM chart_permission  WHERE parent_id>0 `
 	if condition != "" {
 		sql += condition
 	}
@@ -44,7 +44,7 @@ func GetChartPermissionIco(condition string) (items []*ChartPermission, err erro
 // 获取带有ICo的产业
 func GetChartPermissionIcoNew(condition string) (items []*CygxRSlChartPermissionIcoTmp, err error) {
 	o := orm.NewOrm()
-	sql := `SELECT chart_permission_id ,chart_permission_name,image_url as ico_link FROM chart_permission  WHERE 1=1 `
+	sql := `SELECT chart_permission_id ,chart_permission_name,image_url as ico_link FROM chart_permission  WHERE parent_id>0 `
 	if condition != "" {
 		sql += condition
 	}
@@ -56,7 +56,7 @@ func GetChartPermissionIcoNew(condition string) (items []*CygxRSlChartPermission
 // 获取带有ICo的产业
 func GetChartPermissionIcoDetail(condition string) (items []*CygxRSlChartPermissionIco, err error) {
 	o := orm.NewOrm()
-	sql := `SELECT chart_permission_id ,chart_permission_name,image_url as ico_link FROM chart_permission  WHERE 1=1 `
+	sql := `SELECT chart_permission_id ,chart_permission_name,image_url as ico_link FROM chart_permission  WHERE parent_id>0 `
 	if condition != "" {
 		sql += condition
 	}
@@ -68,7 +68,7 @@ func GetChartPermissionIcoDetail(condition string) (items []*CygxRSlChartPermiss
 // 获取带有ICo的产业
 func GetChartPermissionDetail(condition string) (items []*CygxReportSelectionChart, err error) {
 	o := orm.NewOrm()
-	sql := `SELECT chart_permission_id ,chart_permission_name,image_url as ico_link FROM chart_permission  WHERE 1=1 `
+	sql := `SELECT chart_permission_id ,chart_permission_name,image_url as ico_link FROM chart_permission  WHERE parent_id>0 `
 	if condition != "" {
 		sql += condition
 	}
@@ -80,21 +80,21 @@ func GetChartPermissionDetail(condition string) (items []*CygxReportSelectionCha
 // 没有策略的顶级分类
 func GetChartPermissionAllNoTactics() (items []*ChartPermission, err error) {
 	o := orm.NewOrm()
-	sql := `SELECT * FROM chart_permission WHERE product_id=2 AND show_type=1 AND is_report=1 AND chart_permission_id != 23 AND is_other = 0 AND permission_type != 2   ORDER BY sort ASC   `
+	sql := `SELECT * FROM chart_permission WHERE product_id=2 AND show_type=1 AND is_report=1 AND chart_permission_id != 23 AND is_other = 0 AND permission_type != 2 AND parent_id>0  ORDER BY sort ASC   `
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }
 
 func GetChartPermissionOtherAll() (items []*ChartPermission, err error) {
 	o := orm.NewOrm()
-	sql := `SELECT * FROM chart_permission WHERE product_id=2 AND show_type=1 AND is_report=1  AND permission_type != 2   OR is_other = 1  ORDER BY sort ASC`
+	sql := `SELECT * FROM chart_permission WHERE product_id=2 AND show_type=1 AND is_report=1  AND permission_type != 2   OR is_other = 1 AND parent_id>0  ORDER BY sort ASC`
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }
 
 // 获取产业数量
 func GetChartPermissionCount(condition string, pars []interface{}) (count int, err error) {
-	sqlCount := ` SELECT COUNT(1) AS count  FROM chart_permission WHERE 1=1 `
+	sqlCount := ` SELECT COUNT(1) AS count  FROM chart_permission WHERE parent_id>0 `
 	if condition != "" {
 		sqlCount += condition
 	}
@@ -117,7 +117,7 @@ func GetCategoryInfoByName(name string) (item *ChartPermission, err error) {
 		name = "宏观经济"
 	}
 	o := orm.NewOrm()
-	sql := `SELECT * FROM chart_permission WHERE permission_name=?`
+	sql := `SELECT * FROM chart_permission WHERE permission_name=? AND parent_id>0`
 	err = o.Raw(sql, name).QueryRow(&item)
 	return
 }
@@ -132,14 +132,14 @@ type ReportMapping struct {
 
 func GetReportMapping() (item []*ReportMapping, err error) {
 	o := orm.NewOrmUsingDB("hz_cygx")
-	sql := ` SELECT *  FROM	cygx_report_mapping WHERE	match_type_name != ''  `
+	sql := ` SELECT *  FROM	cygx_report_mapping WHERE	match_type_name != '' `
 	_, err = o.Raw(sql).QueryRows(&item)
 	return
 }
 
 func GetReportMappingDetail(condition string, pars []interface{}) (item *ReportMapping, err error) {
 	o := orm.NewOrmUsingDB("hz_cygx")
-	sql := ` SELECT *  FROM	cygx_report_mapping WHERE	 1= 1  ` + condition + ` LIMIT 1 `
+	sql := ` SELECT *  FROM	cygx_report_mapping WHERE 1=1 ` + condition + ` LIMIT 1 `
 	err = o.Raw(sql, pars).QueryRow(&item)
 	return
 }

+ 11 - 16
models/report_chapter_type.go

@@ -2,7 +2,6 @@ package models
 
 import (
 	"github.com/beego/beego/v2/client/orm"
-	"github.com/rdlucklib/rdluck_tools/paging"
 	"hongze/hz_crm_api/utils"
 	"time"
 )
@@ -299,9 +298,8 @@ type UpdateReportChapterTypeResp struct {
 	Week []*ReportChapterType `description:"所有周报品种"`
 }
 
-type ReportChapterTypePageListResp struct {
-	List   []*ReportChapterTypeListItem
-	Paging *paging.PagingItem `description:"分页数据"`
+type ReportChapterTypeListResp struct {
+	List []*ReportChapterTypeListItem
 }
 
 // GetReportChapterTypeCount 获取章节类型总数
@@ -314,13 +312,12 @@ func GetReportChapterTypeCount(condition string, pars []interface{}) (count int,
 }
 
 // GetReportChapterTypeList 获取章节类型列表
-func GetReportChapterTypePageList(condition string, pars []interface{}, startSize, pageSize int) (list []*ReportChapterType, err error) {
+func GetReportChapterTypePageList(condition string, pars []interface{}) (list []*ReportChapterType, err error) {
 	o := orm.NewOrm()
 	sql := ` SELECT * FROM report_chapter_type WHERE 1 = 1 `
 	sql += condition
 	sql += ` ORDER BY sort ASC, created_time DESC`
-	sql += ` LIMIT ?,?`
-	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
+	_, err = o.Raw(sql, pars).QueryRows(&list)
 	return
 }
 
@@ -336,6 +333,7 @@ type ReportChapterTypeListItem struct {
 	WordsImage            string `description:"带字的icon"`
 	EditImgUrl            string `description:"管理后台编辑时选用的图"`
 	IsShow                int    `description:"显示隐藏: 1-显示; 0-隐藏"`
+	Enabled               int    `description:"是否可用,1可用,0禁用"`
 }
 
 // ReportChapterTypeAddReq 新增章节类型请求体
@@ -352,15 +350,12 @@ type ReportChapterTypeAddReq struct {
 
 // ReportChapterTypeEditReq 编辑章节类型请求体
 type ReportChapterTypeEditReq struct {
-	ReportChapterTypeId   int    `description:"报告章节类型id"`
-	ReportChapterTypeName string `description:"报告章节类型名称"`
-	Sort                  int    `description:"排序字段"`
-	ResearchType          string `description:"研报类型"`
-	SelectedImage         string `description:"选中时的icon"`
-	UnselectedImage       string `description:"未选中时的icon"`
-	WordsImage            string `description:"带字的icon"`
-	EditImgUrl            string `description:"管理后台编辑时选用的图"`
-	IsShow                int    `description:"显示隐藏: 1-显示; 0-隐藏"`
+	ReportChapterTypeId int    `description:"报告章节类型id"`
+	SelectedImage       string `description:"选中时的icon"`
+	UnselectedImage     string `description:"未选中时的icon"`
+	WordsImage          string `description:"带字的icon"`
+	EditImgUrl          string `description:"管理后台编辑时选用的图"`
+	IsShow              int    `description:"显示隐藏: 1-显示; 0-隐藏"`
 }
 
 // ReportChapterTypeDelReq 删除章节类型请求体

+ 27 - 0
routers/commentsRouter.go

@@ -8800,6 +8800,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hz_crm_api/controllers:ClassifyController"] = append(beego.GlobalControllerRouter["hongze/hz_crm_api/controllers:ClassifyController"],
+        beego.ControllerComments{
+            Method: "Edit",
+            Router: `/edit`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hz_crm_api/controllers:ClassifyController"] = append(beego.GlobalControllerRouter["hongze/hz_crm_api/controllers:ClassifyController"],
         beego.ControllerComments{
             Method: "ListClassify",
@@ -10384,6 +10393,24 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hz_crm_api/controllers:ReportChapterTypeController"] = append(beego.GlobalControllerRouter["hongze/hz_crm_api/controllers:ReportChapterTypeController"],
+        beego.ControllerComments{
+            Method: "Edit",
+            Router: `/chapter_type/edit`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["hongze/hz_crm_api/controllers:ReportChapterTypeController"] = append(beego.GlobalControllerRouter["hongze/hz_crm_api/controllers:ReportChapterTypeController"],
+        beego.ControllerComments{
+            Method: "List",
+            Router: `/chapter_type/list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hz_crm_api/controllers:ReportController"] = append(beego.GlobalControllerRouter["hongze/hz_crm_api/controllers:ReportController"],
         beego.ControllerComments{
             Method: "GetDayWeekReportChapterTypeList",

+ 1 - 0
routers/router.go

@@ -63,6 +63,7 @@ func init() {
 			web.NSInclude(
 				&controllers.ReportController{},
 				&controllers.ReportUploadCommonController{},
+				&controllers.ReportChapterTypeController{},
 			),
 		),
 		web.NSNamespace("/statistic_report",

+ 184 - 0
services/classify.go

@@ -0,0 +1,184 @@
+package services
+
+import (
+	"encoding/json"
+	"fmt"
+	"hongze/hz_crm_api/models"
+	"hongze/hz_crm_api/utils"
+	"io/ioutil"
+	"net/http"
+	"strings"
+)
+
+type GetClassifyListReq struct {
+	Keyword     string
+	CompanyType string
+	HideDayWeek int
+}
+
+type ClassifySetEnabledReq struct {
+	ClassifyId int `description:"分类ID"`
+	Enabled    int `description:"是否可用,1可用,0禁用"`
+}
+
+type EditClassifyReq struct {
+	ClassifyId int `description:"分类ID"`
+	/*Abstract          string                 `description:"栏目简介"`
+	Descript          string                 `description:"分享描述"`
+	ReportAuthor      string                 `description:"栏目作者"`
+	AuthorDescript    string                 `description:"作者简介"`
+	ColumnImgUrl      string                 `description:"栏目配图"`
+	ReportImgUrl      string                 `description:"报告配图"`
+	HeadImgUrl        string                 `description:"头部banner"`
+	AvatarImgUrl      string                 `description:"头像"`
+	HomeImgUrl        string                 `description:"首页配图"`*/
+	ClassifyLabel string `description:"分类标签"`
+	ShowType      int    `description:"展示类型:1-列表 2-专栏"`
+	/*HasTeleconference int                    `description:"是否有电话会:0-否 1-是"`
+	VipTitle          string                 `description:"研究员头衔"`*/
+	//Sort              int                    `description:"后台排序"`
+	IsShow         int                    `description:"是否在小程序显示:1-显示 0-隐藏"`
+	YbFiccSort     int                    `description:"小程序FICC页排序"`
+	YbFiccIcon     string                 `description:"小程序FICC页icon"`
+	YbFiccPcIcon   string                 `description:"小程序PC端FICC页背景图"`
+	YbIconUrl      string                 `description:"小程序已购页icon"`
+	YbBgUrl        string                 `description:"小程序已购详情背景图"`
+	YbListImg      string                 `description:"小程序研报列表封面图"`
+	YbShareBgImg   string                 `description:"小程序研报详情分享背景图"`
+	YbRightBanner  string                 `description:"Pc端详情页,右侧,报告合集背景图"`
+	MenuList       []*ClassifyMenuSaveReq `description:"子目录列表"`
+	ClassifyMenuId int                    `description:"二级分类-子目录ID"`
+	RelateTel      int                    `description:"是否在电话会中可选: 0-否; 1-是"`
+	RelateVideo    int                    `description:"是否在路演视频中可选: 0-否; 1-是"`
+}
+
+// ClassifyMenuSaveReq 保存分类子目录请求体
+type ClassifyMenuSaveReq struct {
+	MenuId   int    `description:"子目录ID, 0为新增, 大于0为编辑"`
+	MenuName string `description:"子目录名称"`
+}
+
+type CrmEtaBaseResp struct {
+	Code   int    `json:"code" description:"状态码"`
+	Msg    string `json:"msg" description:"提示信息"`
+	ErrMsg string `json:"-" description:"错误信息,不用返回给前端,只是做日志记录"`
+}
+
+func crmEtaPost(url string, param interface{}) (respBody []byte, err error) {
+	data, e := json.Marshal(param)
+	if e != nil {
+		err = fmt.Errorf("data json marshal err: %s", e.Error())
+		return
+	}
+
+	body := ioutil.NopCloser(strings.NewReader(string(data)))
+	client := &http.Client{}
+	req, e := http.NewRequest("POST", url, body)
+	if e != nil {
+		err = fmt.Errorf("http create request err: %s", e.Error())
+		return
+	}
+
+	contentType := "application/json;charset=utf-8"
+	req.Header.Set("Content-Type", contentType)
+	req.Header.Set("Authorization", utils.CrmEtaAuthorization)
+	resp, e := client.Do(req)
+	if e != nil {
+		err = fmt.Errorf("http client do err: %s", e.Error())
+		return
+	}
+	defer func() {
+		_ = resp.Body.Close()
+	}()
+	b, e := ioutil.ReadAll(resp.Body)
+	if e != nil {
+		err = fmt.Errorf("resp body read err: %s", e.Error())
+		return
+	}
+	if len(b) == 0 {
+		err = fmt.Errorf("resp body is empty")
+		return
+	}
+	// 生产环境解密, 注意有个坑前后的双引号
+	if utils.RunMode == "release" {
+		str := string(b)
+		str = strings.Trim(str, `"`)
+		b = utils.DesBase64Decrypt([]byte(str))
+	}
+
+	respBody = b
+	return
+}
+
+func EditReportClassify(pars *EditClassifyReq) (err error, errMsg string) {
+	if utils.CrmEtaServerUrl == "" {
+		return
+	}
+	url := fmt.Sprint(utils.CrmEtaServerUrl, "/api/eta/classify/edit")
+	b, err := crmEtaPost(url, pars)
+	if err != nil {
+		errMsg = "更新品种失败"
+		err = fmt.Errorf("url:%s err: %s", url, err.Error())
+		return
+	}
+	result := new(CrmEtaBaseResp)
+	if e := json.Unmarshal(b, &result); e != nil {
+		errMsg = "更新分类失败"
+		err = fmt.Errorf("result unmarshal err: %s\nresult: %s", e.Error(), string(b))
+		return
+	}
+	utils.FileLog.Info("%s", string(b))
+	if result.Code != 200 {
+		err = fmt.Errorf("result: %s, err: %s", string(b), result.ErrMsg)
+		errMsg = result.Msg
+		return
+	}
+	return
+}
+
+type EditClassifyPermissionReq struct {
+	Keyword               string
+	ChartPermissionIdList []int `description:"权限id数组"`
+	NewKeyword            string
+}
+
+// GetClassifyList 获取报告分类已绑定的权限
+func GetClassifyList(req *GetClassifyListReq) (list models.ClassifyListResp, err error) {
+	if utils.CrmEtaServerUrl == "" {
+		return
+	}
+	url := fmt.Sprint(utils.CrmEtaServerUrl, "/api/eta/classify/list")
+	b, err := crmEtaPost(url, req)
+	if err != nil {
+		err = fmt.Errorf("url:%s err: %s", url, err.Error())
+		return
+	}
+	//result := new(models.ResultData)
+	result := new(GetClassifyListResp)
+	if e := json.Unmarshal(b, &result); e != nil {
+		err = fmt.Errorf("result unmarshal err: %s\nresult: %s", e.Error(), string(b))
+		return
+	}
+	utils.FileLog.Info("%s", string(b))
+	if result.Code != 200 {
+		err = fmt.Errorf("result: %s", string(b))
+		return
+	}
+	list = result.Data
+	return
+}
+
+type ClassifyPermissionReq struct {
+	Keyword string
+}
+
+type ClassifyPermissionList struct {
+	List []*models.ChartPermissionSearchKeyWordMapping
+}
+
+type GetClassifyListResp struct {
+	Code   int                     `json:"code" description:"状态码"`
+	Msg    string                  `json:"msg" description:"提示信息"`
+	Data   models.ClassifyListResp `json:"data" description:"返回数据"`
+	ErrMsg string                  `json:"-" description:"错误信息,不用返回给前端,只是做日志记录"`
+}

+ 41 - 0
services/company_permission.go

@@ -378,3 +378,44 @@ func GetPermissionNameMap() (mapItem map[int]string, err error) {
 	mapItem = mapPermissionName
 	return
 }
+
+func GetBasePermissionLookItem(productId int) (allPermissions []*company.PermissionLookItem, permissionMap map[int][]*company.PermissionLookItem, err error) {
+	//子权限切片集合
+	allPermissions, err = company.GetPermissionLookItemsByProductId(productId)
+	if err != nil {
+		err = fmt.Errorf("获取权限失败,Err:%s", err.Error())
+		return
+	}
+	permissionMap = make(map[int][]*company.PermissionLookItem, 0)
+	for _, v := range allPermissions {
+		if v.ParentId > 0 {
+			permissionMap[v.ParentId] = append(permissionMap[v.ParentId], v)
+		}
+	}
+	return
+}
+
+func GetBaseFiccPermissionSetItem() (allPermissions []*company.PermissionSetItem, permissionMap map[int][]*company.PermissionSetItem, err error) {
+	//子权限切片集合
+	allPermissions, err = company.GetPermissionByProductId(utils.COMPANY_PRODUCT_FICC_ID)
+	if err != nil {
+		err = fmt.Errorf("获取权限失败,Err:%s", err.Error())
+		return
+	}
+	permissionMap = make(map[int][]*company.PermissionSetItem, 0)
+	for _, v := range allPermissions {
+		if v.ParentId > 0 {
+			permissionMap[v.ParentId] = append(permissionMap[v.ParentId], v)
+		}
+	}
+	return
+}
+
+func GetPermissionFirstArr(productId int) (list []*models.ChartPermission, err error) {
+	if productId == 0 {
+		list, err = models.GetPermissionFirst()
+	} else {
+		list, err = models.GetPermissionFirstByProductId(productId)
+	}
+	return
+}

+ 51 - 51
services/contract/contract.go

@@ -1167,52 +1167,41 @@ func GetPermissionByContractService(productId int, serviceList []*contract.Contr
 // GetPermissionByPermissionIdMap 通过权限id的map,获取权限列表
 func GetPermissionByPermissionIdMap(productId int, checkPermissionIdMap map[int]int) (permissionList []*company.PermissionLookList, err error) {
 	//子权限切片集合
-	var permissionClassifyArr []string
-	if productId == 1 {
-		for _, v := range utils.PermissionFiccClassifyArr {
-			permissionClassifyArr = append(permissionClassifyArr, v)
+	allPermissions, err := company.GetPermissionLookItemsByProductId(productId)
+	if err != nil {
+		err = fmt.Errorf("获取权限失败,Err:%s", err.Error())
+		return
+	}
+	permissionMap := make(map[int][]*company.PermissionLookItem, 0)
+	for _, v := range allPermissions {
+		if v.ParentId > 0 {
+			permissionMap[v.ParentId] = append(permissionMap[v.ParentId], v)
 		}
-	} else {
-		permissionClassifyArr = append(permissionClassifyArr, "权益")
 	}
-
 	//遍历获取
-	for _, v := range permissionClassifyArr {
-		checkList := make([]int, 0)
-		plist := new(company.PermissionLookList)
-		items, tmpErr := company.GetPermissionLookItems(productId, v)
-		if tmpErr != nil {
-			err = tmpErr
-			return
-		}
-		for _, n := range items {
-			if _, ok := checkPermissionIdMap[n.ChartPermissionId]; ok {
-				checkList = append(checkList, n.ChartPermissionId)
-			} else if _, ok2 := checkPermissionIdMap[n.ChartPermissionId+utils.PERMISSION_ID_UPGRADE]; ok2 {
-				checkList = append(checkList, n.ChartPermissionId)
-				n.IsUpgrade = 1
+	for _, v := range allPermissions {
+		if v.ParentId == 0 {
+			checkList := make([]int, 0)
+			plist := new(company.PermissionLookList)
+			plist.Items = make([]*company.PermissionLookItem, 0)
+			items, ok1 := permissionMap[v.ChartPermissionId]
+			if ok1 {
+				for _, n := range items {
+					if _, ok := checkPermissionIdMap[n.ChartPermissionId]; ok {
+						checkList = append(checkList, n.ChartPermissionId)
+					} else if _, ok2 := checkPermissionIdMap[n.ChartPermissionId+utils.PERMISSION_ID_UPGRADE]; ok2 {
+						checkList = append(checkList, n.ChartPermissionId)
+						n.IsUpgrade = 1
+					}
+				}
+				plist.Items = items
 			}
+			plist.ClassifyName = v.PermissionName
+			plist.CheckList = checkList
+
+			permissionList = append(permissionList, plist)
 		}
-		//sandoPermissionIdMap := make(map[string]int)
-		////权益客户下,主观客观同时选择,进行合并
-		//for _, n := range items {
-		//	if _, ok := checkPermissionIdMap[n.ChartPermissionId]; ok {
-		//		if sandoPermissionIdMap[n.PermissionName] == 0 {
-		//			checkList = append(checkList, n.ChartPermissionId)
-		//		}
-		//		sandoPermissionIdMap[n.PermissionName] += 1
-		//	}
-		//}
-		//for i, n := range items {
-		//	if sandoPermissionIdMap[n.PermissionName] == 1 {
-		//		items[i].PermissionName = n.Remark
-		//	}
-		//}
-		plist.Items = items
-		plist.ClassifyName = v
-		plist.CheckList = checkList
 
-		permissionList = append(permissionList, plist)
 	}
 	return
 }
@@ -1235,18 +1224,29 @@ func GetServicePermissionMap(serviceList []*contract.ContractServiceAndDetail) (
 		}
 		switch contractService.ServiceTemplateId {
 		case 1: //ficc 大套餐
-			for _, v := range utils.PermissionFiccClassifyArr {
-				//大套餐中 市场策略暂时不作为勾选项
-				if v == "市场策略" {
-					continue
-				}
-				items, tmpErr := company.GetPermissionLookItems(1, v)
-				if tmpErr != nil {
-					err = tmpErr
-					return
+			allFiccPermissions, e := company.GetPermissionLookItemsByProductId(utils.COMPANY_PRODUCT_FICC_ID)
+			if e != nil {
+				err = fmt.Errorf("获取权限失败 Err:%v", e)
+				return
+			}
+			permissionMap := make(map[int][]*company.PermissionLookItem, 0)
+			for _, v := range allFiccPermissions {
+				if v.ParentId > 0 {
+					permissionMap[v.ParentId] = append(permissionMap[v.ParentId], v)
 				}
-				for _, n := range items {
-					checkPermissionIdMap[n.ChartPermissionId] = n.ChartPermissionId
+			}
+			for _, v := range allFiccPermissions {
+				if v.ParentId == 0 {
+					//合同这边市场策略不需要体现出来,所以调整返回
+					if v.PermissionName == "市场策略" {
+						continue
+					}
+					items, ok := permissionMap[v.ChartPermissionId]
+					if ok {
+						for _, n := range items {
+							checkPermissionIdMap[n.ChartPermissionId] = n.ChartPermissionId
+						}
+					}
 				}
 			}
 		case 2: //ficc小套餐

+ 81 - 0
services/report_chapter_type_sync.go

@@ -0,0 +1,81 @@
+package services
+
+import (
+	"encoding/json"
+	"fmt"
+	"hongze/hz_crm_api/services/alarm_msg"
+	"hongze/hz_crm_api/utils"
+)
+
+type EditReportChapterTypeSyncReq struct {
+	ReportChapterTypeId int `description:"报告章节类型id"`
+}
+
+func EditReportChapterTypeSync(pars *EditReportChapterTypeSyncReq) (err error, errMsg string) {
+	defer func() {
+		if err != nil {
+			utils.FileLog.Info("同步章节小程序数据失败, Err: " + err.Error() + errMsg)
+			alarm_msg.SendAlarmMsg("同步章节小程序数据失败,Err:"+err.Error(), 3)
+		}
+	}()
+	if utils.CrmEtaServerUrl == "" {
+		return
+	}
+	url := fmt.Sprint(utils.CrmEtaServerUrl, "/api/eta/chapter_type/yb/sync")
+	b, err := crmEtaPost(url, pars)
+	if err != nil {
+		errMsg = "更新品种失败"
+		err = fmt.Errorf("url:%s err: %s", url, err.Error())
+		return
+	}
+	result := new(CrmEtaBaseResp)
+	if e := json.Unmarshal(b, &result); e != nil {
+		errMsg = "更新分类失败"
+		err = fmt.Errorf("result unmarshal err: %s\nresult: %s", e.Error(), string(b))
+		return
+	}
+	utils.FileLog.Info("%s", string(b))
+	if result.Code != 200 {
+		err = fmt.Errorf("result: %s, err: %s", string(b), result.ErrMsg)
+		errMsg = result.Msg
+		return
+	}
+	return
+}
+
+type EditReportChapterTypeRuleSyncReq struct {
+	ResearchType string `description:"研报类型"`
+}
+
+// EditReportChapterTypeRuleSync 同步章节更新设置
+func EditReportChapterTypeRuleSync(pars *EditReportChapterTypeRuleSyncReq) (err error, errMsg string) {
+	defer func() {
+		if err != nil {
+			utils.FileLog.Info("同步章节更新设置失败, Err: " + err.Error() + errMsg)
+			alarm_msg.SendAlarmMsg("同步章节更新设置失败,Err:"+err.Error(), 3)
+		}
+	}()
+	if utils.CrmEtaServerUrl == "" {
+		return
+	}
+	url := fmt.Sprint(utils.CrmEtaServerUrl, "/api/eta/chapter_type/rule/sync")
+	b, err := crmEtaPost(url, pars)
+	if err != nil {
+		errMsg = "更新品种失败"
+		err = fmt.Errorf("url:%s err: %s", url, err.Error())
+		return
+	}
+	result := new(CrmEtaBaseResp)
+	if e := json.Unmarshal(b, &result); e != nil {
+		errMsg = "更新分类失败"
+		err = fmt.Errorf("result unmarshal err: %s\nresult: %s", e.Error(), string(b))
+		return
+	}
+	utils.FileLog.Info("%s", string(b))
+	if result.Code != 200 {
+		err = fmt.Errorf("result: %s, err: %s", string(b), result.ErrMsg)
+		errMsg = result.Msg
+		return
+	}
+	return
+}

+ 23 - 13
services/yb/road_video.go

@@ -330,26 +330,33 @@ func GetFiccPermission() (ret response.RoadPermissionResp, err error) {
 	if err != nil {
 		return
 	}
-	permissionFirstMap := make(map[string]*response.RoadPermissionItem)
+	permissionFirstMap := make(map[int]*response.RoadPermissionItem)
 
-	//查询首页展示的图标
+	/*//查询首页展示的图标
 	permissionFirstList, err := models.GetYbChartPermissionFirst()
 	if err != nil {
 		return
-	}
-	for _, v := range permissionFirstList {
-		permissionFirstMap[v.ClassifyName] = &response.RoadPermissionItem{
-			Id:           v.Id,
-			ClassifyName: v.YbIndexName,
+	}*/
+	permissionFirstList := make([]*response.RoadPermissionItem, 0)
+	for _, v := range permissionList {
+		if v.ParentId == 0 {
+			tmp := &response.RoadPermissionItem{
+				Id:           v.ChartPermissionId,
+				ClassifyName: v.PermissionName,
+			}
+			permissionFirstMap[v.ChartPermissionId] = tmp
+			permissionFirstList = append(permissionFirstList, tmp)
 		}
 	}
 
 	for _, v := range permissionList {
-		temp := new(response.RoadPermissionSecondItem)
-		temp.ChartPermissionID = v.ChartPermissionId
-		temp.ChartPermissionName = v.PermissionName
-		if _, ok := permissionFirstMap[v.ClassifyName]; ok {
-			permissionFirstMap[v.ClassifyName].List = append(permissionFirstMap[v.ClassifyName].List, temp)
+		if v.ParentId > 0 {
+			temp := new(response.RoadPermissionSecondItem)
+			temp.ChartPermissionID = v.ChartPermissionId
+			temp.ChartPermissionName = v.PermissionName
+			if _, ok := permissionFirstMap[v.ParentId]; ok {
+				permissionFirstMap[v.ParentId].List = append(permissionFirstMap[v.ParentId].List, temp)
+			}
 		}
 	}
 
@@ -358,7 +365,10 @@ func GetFiccPermission() (ret response.RoadPermissionResp, err error) {
 		temp := new(response.RoadPermissionItem)
 		temp.Id = v.Id
 		temp.ClassifyName = v.ClassifyName
-		temp.List = permissionFirstMap[v.ClassifyName].List
+		l, ok := permissionFirstMap[v.Id]
+		if ok {
+			temp.List = l.List
+		}
 		list = append(list, temp)
 	}
 	ret.List = list