|
@@ -7,88 +7,18 @@ import (
|
|
|
"hongze/hz_crm_eta/global"
|
|
|
"hongze/hz_crm_eta/models/crm"
|
|
|
crmService "hongze/hz_crm_eta/services/crm"
|
|
|
- "hongze/hz_crm_eta/utils"
|
|
|
- "time"
|
|
|
)
|
|
|
|
|
|
type ReportChapterTypeController struct{}
|
|
|
|
|
|
-// List
|
|
|
-// @Title 报告章节列表
|
|
|
-// @Description 报告章节列表
|
|
|
-// @Param ReportType query string true "报告类型: day-晨报; week-周报"
|
|
|
-// @Success 200 {object} models.ReportChapterTypePageListResp
|
|
|
-// @router /chapter_type/list [get]
|
|
|
-func (this *ReportChapterTypeController) List(c *gin.Context) {
|
|
|
- var req crm.ChapterTypeReq
|
|
|
- err := c.Bind(&req)
|
|
|
- if err != nil {
|
|
|
- errs, ok := err.(validator.ValidationErrors)
|
|
|
- if !ok {
|
|
|
- resp.FailData("参数解析失败", "Err:"+err.Error(), c)
|
|
|
- return
|
|
|
- }
|
|
|
- resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
|
|
|
- return
|
|
|
- }
|
|
|
- reportType := req.ReportType
|
|
|
- typeArr := []string{utils.REPORT_TYPE_DAY, utils.REPORT_TYPE_WEEK}
|
|
|
- if !utils.InArrayByStr(typeArr, reportType) {
|
|
|
- resp.Fail("请选择报告类型", c)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- cond := ` research_type = ?`
|
|
|
- pars := make([]interface{}, 0)
|
|
|
- pars = append(pars, reportType)
|
|
|
- list, e := crm.GetReportChapterTypePageList(cond, pars)
|
|
|
- if e != nil {
|
|
|
- resp.FailData("获取失败", "获取报告章节列表失败, Err:"+e.Error(), c)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- mappingList, e := crm.GetChapterTypePermissionByTypeIdAndResearchType(reportType)
|
|
|
- if e != nil {
|
|
|
- resp.FailData("获取章节类型权限列表失败", "获取章节类型权限列表失败, Err:"+e.Error(), c)
|
|
|
- return
|
|
|
- }
|
|
|
- mappingMap := make(map[int][]int)
|
|
|
- for _, v := range mappingList {
|
|
|
- mappingMap[v.ReportChapterTypeId] = append(mappingMap[v.ReportChapterTypeId], v.ChartPermissionId)
|
|
|
- }
|
|
|
-
|
|
|
- respList := make([]*crm.ReportChapterTypeListItem, 0)
|
|
|
- for i := range list {
|
|
|
- permissionIds, _ := mappingMap[list[i].ReportChapterTypeId]
|
|
|
- respList = append(respList, &crm.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,
|
|
|
- ChartPermissionIdList: permissionIds,
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
- data := new(crm.ReportChapterTypeListResp)
|
|
|
- data.List = respList
|
|
|
- resp.OkData("查询成功", data, c)
|
|
|
-}
|
|
|
-
|
|
|
-// Add
|
|
|
-// @Title 新增报告章节
|
|
|
-// @Description 新增报告章节
|
|
|
+// Sync
|
|
|
+// @Title 同步报告章节
|
|
|
+// @Description 同步报告章节
|
|
|
// @Param request body crm.ReportChapterTypeAddReq true "type json string"
|
|
|
// @Success 200 string "操作成功"
|
|
|
-// @router /chapter_type/add [post]
|
|
|
-func (this *ReportChapterTypeController) Add(c *gin.Context) {
|
|
|
- var req crm.ReportChapterTypeAddReq
|
|
|
+// @router /chapter_type/sync [post]
|
|
|
+func (this *ReportChapterTypeController) Sync(c *gin.Context) {
|
|
|
+ var req crm.ReportChapterTypeSyncReq
|
|
|
err := c.Bind(&req)
|
|
|
if err != nil {
|
|
|
errs, ok := err.(validator.ValidationErrors)
|
|
@@ -100,300 +30,11 @@ func (this *ReportChapterTypeController) Add(c *gin.Context) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- if req.ReportChapterTypeName == "" {
|
|
|
- resp.Fail("请输入章节名称", c)
|
|
|
- return
|
|
|
- }
|
|
|
- typeArr := []string{utils.REPORT_TYPE_DAY, utils.REPORT_TYPE_WEEK}
|
|
|
- if !utils.InArrayByStr(typeArr, req.ResearchType) {
|
|
|
- resp.Fail("请选择报告类型", c)
|
|
|
- return
|
|
|
- }
|
|
|
- // 重名校验
|
|
|
- cond := ` report_chapter_type_name = ? AND research_type = ?`
|
|
|
- pars := make([]interface{}, 0)
|
|
|
- pars = append(pars, req.ReportChapterTypeName, req.ResearchType)
|
|
|
- exists, e := crm.GetReportChapterTypeByCondition(cond, pars)
|
|
|
- if e != nil && e != utils.ErrNoRow {
|
|
|
- resp.FailData("操作失败", "获取报告章节失败, Err:"+e.Error(), c)
|
|
|
- return
|
|
|
- }
|
|
|
- if exists.ReportChapterTypeId > 0 {
|
|
|
- resp.Fail("章节名称已存在", c)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- nowTime := time.Now().Local()
|
|
|
- item := new(crm.ReportChapterType)
|
|
|
- maxSort, e := item.GetMaxSort()
|
|
|
- if e != nil {
|
|
|
- resp.FailData("操作失败", "获取章节最大排序失败, Err:"+e.Error(), c)
|
|
|
- return
|
|
|
- }
|
|
|
- item.ReportChapterTypeName = req.ReportChapterTypeName
|
|
|
- item.Sort = maxSort + 1
|
|
|
- item.Enabled = 1
|
|
|
- item.CreatedTime = nowTime
|
|
|
- item.LastUpdatedTime = nowTime
|
|
|
- item.ResearchType = req.ResearchType
|
|
|
- item.ReportChapterTypeName = req.ReportChapterTypeName
|
|
|
- item.IsSet = 0
|
|
|
- item.ReportChapterTypeKey = req.ReportChapterTypeName
|
|
|
- item.TickerTitle = req.ReportChapterTypeName
|
|
|
- if e = item.Create(); e != nil {
|
|
|
- resp.FailData("操作失败", "新增报告章节失败, Err:"+e.Error(), c)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- // 设置权限
|
|
|
- cond = ""
|
|
|
- pars = make([]interface{}, 0)
|
|
|
- permissionList, e := crmService.GetChartPermissionList(cond, pars)
|
|
|
- if e != nil {
|
|
|
- resp.FailData("操作失败", "获取权限列表失败, Err:"+e.Error(), c)
|
|
|
- return
|
|
|
- }
|
|
|
- permissionIdName := make(map[int]string)
|
|
|
- for i := range permissionList {
|
|
|
- permissionIdName[permissionList[i].ChartPermissionId] = permissionList[i].PermissionName
|
|
|
- }
|
|
|
-
|
|
|
- researchType := item.ResearchType
|
|
|
- newPermissions := make([]*crm.ReportChapterTypePermission, 0) // 报告章节权限表(新)
|
|
|
- newWeekPermissions := make([]*crm.ChartPermissionChapterMapping, 0) // 报告章节权限表(老)
|
|
|
- for i := range req.ChartPermissionIdList {
|
|
|
- // todo 检查权限是否被禁用,过滤一级品种,只能绑定二级品种
|
|
|
- newPermissions = append(newPermissions, &crm.ReportChapterTypePermission{
|
|
|
- ReportChapterTypeId: item.ReportChapterTypeId,
|
|
|
- ReportChapterTypeName: item.ReportChapterTypeName,
|
|
|
- ChartPermissionId: req.ChartPermissionIdList[i],
|
|
|
- PermissionName: permissionIdName[req.ChartPermissionIdList[i]],
|
|
|
- ResearchType: researchType,
|
|
|
- CreatedTime: nowTime,
|
|
|
- })
|
|
|
- if researchType == utils.REPORT_TYPE_WEEK {
|
|
|
- newWeekPermissions = append(newWeekPermissions, &crm.ChartPermissionChapterMapping{
|
|
|
- ChartPermissionId: req.ChartPermissionIdList[i],
|
|
|
- ReportChapterTypeId: item.ReportChapterTypeId,
|
|
|
- ResearchType: researchType,
|
|
|
- })
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 设置权限
|
|
|
- e = crm.SetReportChapterTypePermission(item.ReportChapterTypeId, researchType, newPermissions, newWeekPermissions)
|
|
|
- if e != nil {
|
|
|
- resp.FailData("操作失败", "设置章节类型权限失败, Err:"+e.Error(), c)
|
|
|
- return
|
|
|
- }
|
|
|
- // todo 清除小程序端的章节缓存
|
|
|
- /*{
|
|
|
- key := "hongze_yb:report_chapter_type:GetEffectTypeID"
|
|
|
- _ = utils.Rc.Delete(key)
|
|
|
- }*/
|
|
|
-
|
|
|
- resp.Ok("操作成功", c)
|
|
|
-}
|
|
|
-
|
|
|
-// Edit
|
|
|
-// @Title 编辑报告章节
|
|
|
-// @Description 编辑报告章节
|
|
|
-// @Param request body crm.ReportChapterTypeEditReq true "type json string"
|
|
|
-// @Success 200 string "操作成功"
|
|
|
-// @router /chapter_type/edit [post]
|
|
|
-func (this *ReportChapterTypeController) Edit(c *gin.Context) {
|
|
|
- var req crm.ReportChapterTypeEditReq
|
|
|
- err := c.Bind(&req)
|
|
|
- if err != nil {
|
|
|
- errs, ok := err.(validator.ValidationErrors)
|
|
|
- if !ok {
|
|
|
- resp.FailData("参数解析失败", "Err:"+err.Error(), c)
|
|
|
- return
|
|
|
- }
|
|
|
- resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- if req.ReportChapterTypeId <= 0 {
|
|
|
- resp.Fail("章节ID有误", c)
|
|
|
- return
|
|
|
- }
|
|
|
- if req.ReportChapterTypeName == "" {
|
|
|
- resp.Fail("请输入章节名称", c)
|
|
|
- return
|
|
|
- }
|
|
|
- if len(req.ChartPermissionIdList) == 0 {
|
|
|
- resp.Fail("请选择权限", c)
|
|
|
- return
|
|
|
- }
|
|
|
- typeArr := []string{utils.REPORT_TYPE_DAY, utils.REPORT_TYPE_WEEK}
|
|
|
- if !utils.InArrayByStr(typeArr, req.ResearchType) {
|
|
|
- resp.Fail("请选择报告类型", c)
|
|
|
- return
|
|
|
- }
|
|
|
- // 重名校验
|
|
|
- cond := ` report_chapter_type_name = ? AND research_type = ?`
|
|
|
- pars := make([]interface{}, 0)
|
|
|
- pars = append(pars, req.ReportChapterTypeName, req.ResearchType)
|
|
|
- exists, e := crm.GetReportChapterTypeByCondition(cond, pars)
|
|
|
- if e != nil && e != utils.ErrNoRow {
|
|
|
- resp.FailData("操作失败", "获取重名报告章节失败, Err:"+e.Error(), c)
|
|
|
- return
|
|
|
- }
|
|
|
- if exists != nil && exists.ReportChapterTypeId > 0 && exists.ReportChapterTypeId != req.ReportChapterTypeId {
|
|
|
- resp.Fail("章节名称已存在", c)
|
|
|
- return
|
|
|
- }
|
|
|
- ob := new(crm.ReportChapterType)
|
|
|
- item, e := ob.GetReportChapterTypeById(req.ReportChapterTypeId)
|
|
|
- if e != nil {
|
|
|
- if e == utils.ErrNoRow {
|
|
|
- resp.Fail("报告章节不存在", c)
|
|
|
- return
|
|
|
- }
|
|
|
- resp.FailData("操作失败", "获取报告章节失败, Err:"+e.Error(), c)
|
|
|
- return
|
|
|
- }
|
|
|
- originReportChapterTypeName := item.ReportChapterTypeName
|
|
|
- item.ReportChapterTypeName = req.ReportChapterTypeName
|
|
|
- item.ResearchType = req.ResearchType
|
|
|
- item.ReportChapterTypeKey = req.ReportChapterTypeName
|
|
|
- item.TickerTitle = req.ReportChapterTypeName
|
|
|
- updateCols := []string{"ReportChapterTypeName", "ResearchType", "ReportChapterTypeKey", "TickerTitle"}
|
|
|
- if e = item.Update(updateCols); e != nil {
|
|
|
- resp.FailData("操作失败", "更新报告章节失败, Err:"+e.Error(), c)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- // 设置权限
|
|
|
- cond = ""
|
|
|
- pars = make([]interface{}, 0)
|
|
|
- permissionList, e := crmService.GetChartPermissionList(cond, pars)
|
|
|
- if e != nil {
|
|
|
- resp.FailData("操作失败", "获取权限列表失败, Err:"+e.Error(), c)
|
|
|
- return
|
|
|
- }
|
|
|
- permissionIdName := make(map[int]string)
|
|
|
- for i := range permissionList {
|
|
|
- permissionIdName[permissionList[i].ChartPermissionId] = permissionList[i].PermissionName
|
|
|
- }
|
|
|
-
|
|
|
- researchType := item.ResearchType
|
|
|
- nowTime := time.Now().Local()
|
|
|
- newPermissions := make([]*crm.ReportChapterTypePermission, 0) // 报告章节权限表(新)
|
|
|
- newWeekPermissions := make([]*crm.ChartPermissionChapterMapping, 0) // 报告章节权限表(老)
|
|
|
- for i := range req.ChartPermissionIdList {
|
|
|
- newPermissions = append(newPermissions, &crm.ReportChapterTypePermission{
|
|
|
- ReportChapterTypeId: item.ReportChapterTypeId,
|
|
|
- ReportChapterTypeName: item.ReportChapterTypeName,
|
|
|
- ChartPermissionId: req.ChartPermissionIdList[i],
|
|
|
- PermissionName: permissionIdName[req.ChartPermissionIdList[i]],
|
|
|
- ResearchType: researchType,
|
|
|
- CreatedTime: nowTime,
|
|
|
- })
|
|
|
- if researchType == utils.REPORT_TYPE_WEEK {
|
|
|
- newWeekPermissions = append(newWeekPermissions, &crm.ChartPermissionChapterMapping{
|
|
|
- ChartPermissionId: req.ChartPermissionIdList[i],
|
|
|
- ReportChapterTypeId: item.ReportChapterTypeId,
|
|
|
- ResearchType: researchType,
|
|
|
- })
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 设置权限
|
|
|
- e = crm.SetReportChapterTypePermission(item.ReportChapterTypeId, researchType, newPermissions, newWeekPermissions)
|
|
|
- if e != nil {
|
|
|
- resp.FailData("操作失败", "设置章节类型权限失败, Err:"+e.Error(), c)
|
|
|
- return
|
|
|
- }
|
|
|
- var ret crm.ReportChapterTypeEditResp
|
|
|
- ret.OriginReportChapterTypeName = originReportChapterTypeName
|
|
|
- // todo 清除小程序端的章节缓存
|
|
|
- /* {
|
|
|
- key := "hongze_yb:report_chapter_type:GetEffectTypeID"
|
|
|
- _ = utils.Rc.Delete(key)
|
|
|
- }*/
|
|
|
-
|
|
|
- resp.Ok("操作成功", c)
|
|
|
-}
|
|
|
-
|
|
|
-// SetEnabled
|
|
|
-// @Title 启用/禁用分类接口
|
|
|
-// @Description 启用/禁用分类
|
|
|
-// @Param request body models.ClassifyMoveReq true "type json string"
|
|
|
-// @Success 200 新增成功
|
|
|
-// @router /chapter_type/enabled/set [post]
|
|
|
-func (this *ReportChapterTypeController) SetEnabled(c *gin.Context) {
|
|
|
- var req crm.ReportChapterTypeEnabledReq
|
|
|
- err := c.Bind(&req)
|
|
|
- if err != nil {
|
|
|
- errs, ok := err.(validator.ValidationErrors)
|
|
|
- if !ok {
|
|
|
- resp.FailData("参数解析失败", "Err:"+err.Error(), c)
|
|
|
- return
|
|
|
- }
|
|
|
- resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- if req.ReportChapterTypeId <= 0 {
|
|
|
- resp.Fail("请选择章节", c)
|
|
|
- return
|
|
|
- }
|
|
|
- if req.Enabled != 0 && req.Enabled != 1 {
|
|
|
- resp.Fail("请选择正确的启用禁用状态", c)
|
|
|
- return
|
|
|
- }
|
|
|
- ob := new(crm.ReportChapterType)
|
|
|
- item, err := ob.GetReportChapterTypeById(req.ReportChapterTypeId)
|
|
|
- if err != nil {
|
|
|
- if err == utils.ErrNoRow {
|
|
|
- resp.FailData("章节不存在", "Err:"+err.Error(), c)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- resp.FailData("获取章节信息失败", "Err:"+err.Error(), c)
|
|
|
- return
|
|
|
- }
|
|
|
- if item == nil {
|
|
|
- resp.Fail("章节不存在", c)
|
|
|
- return
|
|
|
- }
|
|
|
- //设置分类启用、禁用状态
|
|
|
- err = ob.SetEnabled(req.ReportChapterTypeId, req.Enabled)
|
|
|
- if err != nil {
|
|
|
- resp.FailData("操作失败", "Err:"+err.Error(), c)
|
|
|
- return
|
|
|
- }
|
|
|
- resp.Ok("操作成功", c)
|
|
|
-}
|
|
|
-
|
|
|
-// Move
|
|
|
-// @Description 移动报告章节类型
|
|
|
-// @Success 200 {string} string "操作成功"
|
|
|
-// @Router /report_chapter_type/move [post]
|
|
|
-func (this *ReportChapterTypeController) Move(c *gin.Context) {
|
|
|
- var req crm.ReportChapterTypeMoveReq
|
|
|
- err := c.Bind(&req)
|
|
|
- if err != nil {
|
|
|
- errs, ok := err.(validator.ValidationErrors)
|
|
|
- if !ok {
|
|
|
- resp.FailData("参数解析失败", "Err:"+err.Error(), c)
|
|
|
- return
|
|
|
- }
|
|
|
- resp.FailData("参数解析失败", errs.Translate(global.Trans), c)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- if req.ReportChapterTypeId <= 0 {
|
|
|
- resp.Fail("请选择报告章节类型", c)
|
|
|
- return
|
|
|
- }
|
|
|
-
|
|
|
- e, msg := crmService.MoveReportChapterType(req)
|
|
|
+ e, msg := crmService.SyncReportChapterType(&req)
|
|
|
if e != nil {
|
|
|
resp.FailData(msg, e.Error(), c)
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
resp.Ok("操作成功", c)
|
|
|
}
|