Bläddra i källkod

Merge branch 'feature/pool294_fa_calendar' into debug

xyxie 1 månad sedan
förälder
incheckning
5e874d3623

+ 28 - 3
controller/fe_calendar/fe_calendar.go

@@ -24,6 +24,15 @@ func PermissionList(c *gin.Context) {
 		return
 	}
 
+	// 获取品种下面挂有日历的品种列表
+
+	matterOb := new(fe_calendar_matter.FeCalendarMatter)
+	matterPermissionIds, e := matterOb.GetAllPermissionIds()
+	if e != nil {
+		response.FailMsg("获取失败", "获取有日历品种列表失败, Err: "+e.Error(), c)
+		return
+	}
+
 	// 遍历品种树
 	permissions, e := chart_permission.GetChartPermissionsByProductId()
 	if e != nil {
@@ -33,7 +42,7 @@ func PermissionList(c *gin.Context) {
 	parents := make([]*chart_permission.SimpleChartPermission, 0)
 	parentPermissions := make(map[int][]*chart_permission.SimpleChartPermission, 0)
 	for _, v := range permissions {
-		if v.ParentId > 0 && utils.InArrayByInt(validPermissionIds, int(v.ChartPermissionID)) {
+		if v.ParentId > 0 && utils.InArrayByInt(validPermissionIds, int(v.ChartPermissionID)) && utils.InArrayByInt(matterPermissionIds, int(v.ChartPermissionID)) {
 			if parentPermissions[v.ParentId] == nil {
 				parentPermissions[v.ParentId] = make([]*chart_permission.SimpleChartPermission, 0)
 			}
@@ -42,15 +51,31 @@ func PermissionList(c *gin.Context) {
 		}
 		parents = append(parents, chart_permission.FormatChartPermission2Simple(v))
 	}
-	resp := make([]*chart_permission.SimpleChartPermission, 0)
+	var resp chart_permission.FaCalendarPermissionResp
+	list := make([]*chart_permission.SimpleChartPermission, 0)
 	for _, v := range parents {
 		if parentPermissions[v.ChartPermissionId] == nil {
 			continue
 		}
 		v.Children = parentPermissions[v.ChartPermissionId]
-		resp = append(resp, v)
+		list = append(list, v)
+	}
+	lastEditPermissionId := 0
+	lastEditPermissionName := ""
+	// 查询最近被编辑过的品种ID
+	matter, e := matterOb.GetLaststModifyMatter()
+	if e != nil && e.Error() != utils.NotEmpty() {
+		response.FailMsg("获取失败", "获取品种列表失败, Err: "+e.Error(), c)
+		return
+	}
+	if e == nil {
+		lastEditPermissionId = matter.ChartPermissionId
+		lastEditPermissionName = matter.ChartPermissionName
 	}
 
+	resp.CheckedPermissionId = lastEditPermissionId
+	resp.CheckedPermissionName = lastEditPermissionName
+	resp.List = list
 	response.OkData("获取成功", resp, c)
 }
 

+ 10 - 0
models/tables/fe_calendar_matter/model.go

@@ -67,3 +67,13 @@ func (m *FeCalendarMatter) GetLastestMonthItemByPermissionId(permissionId int) (
 	err = global.MYSQL["data"].Where("chart_permission_id = ?", permissionId).Order("matter_date DESC").First(&item).Error
 	return
 }
+
+func (m *FeCalendarMatter) GetLaststModifyMatter() (item *FeCalendarMatter, err error) {
+	err = global.MYSQL["data"].Order("modify_time DESC").First(&item).Error
+	return
+}
+
+func (m *FeCalendarMatter) GetAllPermissionIds() (chartPermissionIds []int, err error) {
+	err = global.MYSQL["data"].Model(m).Select(" distinct chart_permission_id ").Scan(&chartPermissionIds).Error
+	return
+}

+ 6 - 0
models/tables/rddp/chart_permission/query.go

@@ -85,3 +85,9 @@ func FormatChartPermission2Simple(origin *ChartPermission) (item *SimpleChartPer
 	item.Sort = origin.Sort
 	return
 }
+
+type FaCalendarPermissionResp struct {
+	List                  []*SimpleChartPermission
+	CheckedPermissionId   int    `json:"checked_permission_id"`
+	CheckedPermissionName string `json:"checked_permission_name"`
+}