123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- package fe_calendar
- import (
- "fmt"
- "github.com/gin-gonic/gin"
- "hongze/hongze_yb/controller/response"
- "hongze/hongze_yb/models/request"
- "hongze/hongze_yb/models/tables/fe_calendar_matter"
- "hongze/hongze_yb/models/tables/rddp/chart_permission"
- "hongze/hongze_yb/services/company"
- userService "hongze/hongze_yb/services/user"
- "hongze/hongze_yb/utils"
- "time"
- )
- // PermissionList 品种列表
- func PermissionList(c *gin.Context) {
- userInfo := userService.GetInfoByClaims(c)
- // 获取用户有权限的品种
- validPermissionIds, e := company.GetValidPermissionIdListByCompany2ProductId(userInfo.CompanyID, int64(utils.FiccProductId))
- if e != nil {
- response.FailMsg("获取失败", "获取有权限品种列表失败, Err: "+e.Error(), c)
- return
- }
- // 遍历品种树
- permissions, e := chart_permission.GetChartPermissionsByProductId()
- if e != nil {
- response.FailMsg("获取失败", "获取品种列表失败, Err: "+e.Error(), c)
- return
- }
- 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 parentPermissions[v.ParentId] == nil {
- parentPermissions[v.ParentId] = make([]*chart_permission.SimpleChartPermission, 0)
- }
- parentPermissions[v.ParentId] = append(parentPermissions[v.ParentId], chart_permission.FormatChartPermission2Simple(v))
- continue
- }
- parents = append(parents, chart_permission.FormatChartPermission2Simple(v))
- }
- resp := make([]*chart_permission.SimpleChartPermission, 0)
- for _, v := range parents {
- if parentPermissions[v.ChartPermissionId] == nil {
- continue
- }
- v.Children = parentPermissions[v.ChartPermissionId]
- resp = append(resp, v)
- }
- response.OkData("获取成功", resp, c)
- }
- // LastestPermissionMonth 获取品种有数据最近的月份
- func LastestPermissionMonth(c *gin.Context) {
- var req request.FeCalendarLastestPermissionMonthReq
- if err := c.Bind(&req); err != nil {
- response.Fail("参数有误", c)
- return
- }
- if req.ChartPermissionId <= 0 {
- response.Fail("请选择品种", c)
- return
- }
- var month string
- matterOb := new(fe_calendar_matter.FeCalendarMatter)
- // 当月事项
- currentMonth := time.Now().Format("2006-01")
- cond := ` chart_permission_id = ? AND matter_month = ?`
- pars := make([]interface{}, 0)
- pars = append(pars, req.ChartPermissionId, currentMonth)
- item, e := matterOb.GetItemByCondition(cond, pars)
- if e != nil && e != utils.ErrNoRow {
- response.FailMsg("获取失败", "获取当月事项失败, Err: "+e.Error(), c)
- return
- }
- if item != nil && item.FeCalendarMatterId > 0 {
- month = currentMonth
- }
- // 无当月事项则查询最近的
- if month == "" {
- lastest, e := matterOb.GetLastestMonthItemByPermissionId(req.ChartPermissionId)
- if e != nil && e != utils.ErrNoRow {
- response.FailMsg("获取失败", "获取事项失败, Err: "+e.Error(), c)
- return
- }
- if lastest != nil && lastest.FeCalendarMatterId > 0 {
- month = lastest.MatterMonth
- }
- }
- response.OkData("获取成功", month, c)
- }
- // MatterList 事项列表
- func MatterList(c *gin.Context) {
- var req request.FeCalendarMatterListReq
- if err := c.Bind(&req); err != nil {
- response.Fail("参数有误", c)
- return
- }
- if req.ChartPermissionId <= 0 {
- response.Fail("请选择品种", c)
- return
- }
- //userInfo := userService.GetInfoByClaims(c)
- cond := ` 1=1`
- pars := make([]interface{}, 0)
- if req.ChartPermissionId > 0 {
- cond += fmt.Sprintf(` AND %s = ?`, fe_calendar_matter.FeCalendarMatterColumns.ChartPermissionId)
- pars = append(pars, req.ChartPermissionId)
- }
- if req.StartDate != "" && req.EndDate != "" {
- _, e := time.Parse(utils.FormatDate, req.StartDate)
- if e != nil {
- response.Fail("开始日期格式有误", c)
- return
- }
- _, e = time.Parse(utils.FormatDate, req.EndDate)
- if e != nil {
- response.Fail("结束日期格式有误", c)
- return
- }
- cond += fmt.Sprintf(` AND %s >= ? AND %s <= ?`, fe_calendar_matter.FeCalendarMatterColumns.MatterDate, fe_calendar_matter.FeCalendarMatterColumns.MatterDate)
- pars = append(pars, req.StartDate, req.EndDate)
- }
- matterOb := new(fe_calendar_matter.FeCalendarMatter)
- order := fmt.Sprintf(`%s ASC, %s ASC`, fe_calendar_matter.FeCalendarMatterColumns.MatterDate, fe_calendar_matter.FeCalendarMatterColumns.Sort)
- matters, e := matterOb.GetItemsByCondition(cond, pars, []string{}, order)
- if e != nil {
- response.FailMsg("获取失败", "获取事项列表失败, Err: "+e.Error(), c)
- return
- }
- dateMatter := make(map[string][]*fe_calendar_matter.FeCalendarMatterItem)
- for _, v := range matters {
- d := v.MatterDate.Format(utils.FormatDate)
- if dateMatter[d] == nil {
- dateMatter[d] = make([]*fe_calendar_matter.FeCalendarMatterItem, 0)
- }
- dateMatter[d] = append(dateMatter[d], fe_calendar_matter.FormatFeCalendarMatter2Item(v))
- }
- dateExist := make(map[string]bool)
- resp := make([]*fe_calendar_matter.FeCalendarMatterListItem, 0)
- for _, v := range matters {
- d := v.MatterDate.Format(utils.FormatDate)
- if dateExist[d] {
- continue
- }
- dateExist[d] = true
- resp = append(resp, &fe_calendar_matter.FeCalendarMatterListItem{
- Date: d,
- Matters: dateMatter[d],
- })
- }
- response.OkData("获取成功", resp, c)
- }
- // MatterDetail 事项详情
- func MatterDetail(c *gin.Context) {
- var req request.FeCalendarMatterDetailReq
- if err := c.Bind(&req); err != nil {
- response.Fail("参数有误", c)
- return
- }
- if req.ChartPermissionId <= 0 {
- response.Fail("请选择品种", c)
- return
- }
- if req.MatterDate == "" {
- response.Fail("请选择日期", c)
- return
- }
- _, e := time.Parse(utils.FormatDate, req.MatterDate)
- if e != nil {
- response.Fail("日期格式有误", c)
- return
- }
- //userInfo := userService.GetInfoByClaims(c)
- matterOb := new(fe_calendar_matter.FeCalendarMatter)
- cond := fmt.Sprintf(` %s = ? AND %s = ?`, fe_calendar_matter.FeCalendarMatterColumns.ChartPermissionId, fe_calendar_matter.FeCalendarMatterColumns.MatterDate)
- pars := make([]interface{}, 0)
- pars = append(pars, req.ChartPermissionId, req.MatterDate)
- order := fmt.Sprintf(`%s ASC`, fe_calendar_matter.FeCalendarMatterColumns.Sort)
- matters, e := matterOb.GetItemsByCondition(cond, pars, []string{}, order)
- if e != nil {
- response.FailMsg("获取失败", "获取事项列表失败, Err: "+e.Error(), c)
- return
- }
- resp := make([]*fe_calendar_matter.FeCalendarMatterItem, 0)
- for _, v := range matters {
- resp = append(resp, fe_calendar_matter.FormatFeCalendarMatter2Item(v))
- }
- response.OkData("获取成功", resp, c)
- }
|