|
@@ -39,15 +39,33 @@ func (this *ReportChapterTypeController) List() {
|
|
|
br.Msg = "请选择报告类型"
|
|
|
return
|
|
|
}
|
|
|
- var req services.ChapterTypeReq
|
|
|
- req.ReportType = reportType
|
|
|
- resp, e := services.GetReportChapterType(req)
|
|
|
+ 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()
|
|
|
+ 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,
|
|
|
+ })
|
|
|
+ }
|
|
|
|
|
|
+ resp := new(models.ReportChapterTypeListResp)
|
|
|
+ resp.List = respList
|
|
|
br.Ret = 200
|
|
|
br.Success = true
|
|
|
br.Msg = "获取成功"
|
|
@@ -90,10 +108,84 @@ func (this *ReportChapterTypeController) Add() {
|
|
|
return
|
|
|
}
|
|
|
// 重名校验
|
|
|
- e, msg := services.AddReportChapterType(&req)
|
|
|
+ cond := ` AND report_chapter_type_name = ? AND research_type = ?`
|
|
|
+ pars := make([]interface{}, 0)
|
|
|
+ pars = append(pars, req.ReportChapterTypeName, req.ResearchType)
|
|
|
+ exists, e := models.GetReportChapterTypeByCondition(cond, pars)
|
|
|
+ if e != nil && e.Error() != utils.ErrNoRow() {
|
|
|
+ br.Msg = "操作失败"
|
|
|
+ br.ErrMsg = "获取重名报告章节失败, Err:" + e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if exists != nil {
|
|
|
+ br.Msg = "章节名称已存在"
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ nowTime := time.Now().Local()
|
|
|
+ item := new(models.ReportChapterType)
|
|
|
+ maxSort, e := item.GetMaxSort()
|
|
|
if e != nil {
|
|
|
- br.Msg = msg
|
|
|
- br.ErrMsg = "新增章节失败, Err: " + e.Error()
|
|
|
+ br.Msg = "操作失败"
|
|
|
+ br.ErrMsg = "获取章节最大排序失败, Err:" + e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ item.ReportChapterTypeName = req.ReportChapterTypeName
|
|
|
+ item.Sort = maxSort + 1
|
|
|
+ item.Enabled = 1
|
|
|
+ item.CreatedTime = nowTime
|
|
|
+ item.LastUpdatedTime = nowTime
|
|
|
+ item.ResearchType = req.ResearchType
|
|
|
+ item.IsSet = 0
|
|
|
+ item.ReportChapterTypeKey = req.ReportChapterTypeName
|
|
|
+ item.TickerTitle = req.ReportChapterTypeName
|
|
|
+
|
|
|
+ if e = item.Create(); e != nil {
|
|
|
+ br.Msg = "操作失败"
|
|
|
+ br.ErrMsg = "新增报告章节失败, Err:" + e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // todo 更新章节权限
|
|
|
+ cond = ` and product_id=1`
|
|
|
+ pars = make([]interface{}, 0)
|
|
|
+ permissionList, e := services.GetChartPermissionList(cond, pars)
|
|
|
+ if e != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取品种列表失败, Err: " + e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ permissionIdName := make(map[int]string)
|
|
|
+ for i := range permissionList {
|
|
|
+ permissionIdName[permissionList[i].ChartPermissionId] = permissionList[i].PermissionName
|
|
|
+ }
|
|
|
+
|
|
|
+ researchType := item.ResearchType
|
|
|
+ newPermissions := make([]*models.ReportChapterTypePermission, 0) // 报告章节权限表(新)
|
|
|
+ newWeekPermissions := make([]*models.ChartPermissionChapterMapping, 0) // 报告章节权限表(老)
|
|
|
+ for i := range req.ChartPermissionIdList {
|
|
|
+ newPermissions = append(newPermissions, &models.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, &models.ChartPermissionChapterMapping{
|
|
|
+ ChartPermissionId: req.ChartPermissionIdList[i],
|
|
|
+ ReportChapterTypeId: item.ReportChapterTypeId,
|
|
|
+ ResearchType: researchType,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置权限
|
|
|
+ e = models.SetReportChapterTypePermission(item.ReportChapterTypeId, researchType, newPermissions, newWeekPermissions)
|
|
|
+ if e != nil {
|
|
|
+ br.Msg = "操作失败"
|
|
|
+ br.ErrMsg = "设置章节类型权限失败, Err: " + e.Error()
|
|
|
return
|
|
|
}
|
|
|
// 清除小程序端的章节缓存
|
|
@@ -102,6 +194,13 @@ func (this *ReportChapterTypeController) Add() {
|
|
|
_ = utils.Rc.Delete(key)
|
|
|
}
|
|
|
|
|
|
+ //todo 同步更新crm章节权限和章节类型
|
|
|
+ go func() {
|
|
|
+ var syncReq services.ChapterTypeSyncReq
|
|
|
+ syncReq.ResearchType = researchType
|
|
|
+ syncReq.ReportChapterTypeId = item.ReportChapterTypeId
|
|
|
+ _, _ = services.ReportChapterTypeSync(&syncReq)
|
|
|
+ }()
|
|
|
br.Ret = 200
|
|
|
br.Success = true
|
|
|
br.Msg = "操作成功"
|
|
@@ -146,14 +245,74 @@ func (this *ReportChapterTypeController) Edit() {
|
|
|
br.Msg = "请选择报告类型"
|
|
|
return
|
|
|
}
|
|
|
- ret, e, msg := services.EditReportChapterType(&req)
|
|
|
+ // 重名校验
|
|
|
+ cond := ` AND report_chapter_type_name = ? AND research_type = ?`
|
|
|
+ pars := make([]interface{}, 0)
|
|
|
+ pars = append(pars, req.ReportChapterTypeName, req.ResearchType)
|
|
|
+ exists, e := models.GetReportChapterTypeByCondition(cond, pars)
|
|
|
+ if e != nil && e.Error() != utils.ErrNoRow() {
|
|
|
+ br.Msg = "操作失败"
|
|
|
+ br.ErrMsg = "获取重名报告章节失败, Err:" + e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if exists != nil && exists.ReportChapterTypeId != req.ReportChapterTypeId {
|
|
|
+ br.Msg = "章节名称已存在"
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ item, e := models.GetReportChapterTypeById(req.ReportChapterTypeId)
|
|
|
if e != nil {
|
|
|
- br.Msg = msg
|
|
|
- br.ErrMsg = "编辑章节失败, Err: " + e.Error()
|
|
|
+ br.Msg = "操作失败"
|
|
|
+ br.ErrMsg = "获取报告章节失败, Err:" + e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ originName := item.ReportChapterTypeName
|
|
|
+ //更新章节权限
|
|
|
+ // todo 更新章节权限
|
|
|
+ cond = ` and product_id=1`
|
|
|
+ pars = make([]interface{}, 0)
|
|
|
+ permissionList, e := services.GetChartPermissionList(cond, pars)
|
|
|
+ if e != nil {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取品种列表失败, Err: " + e.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ permissionIdName := make(map[int]string)
|
|
|
+ nowTime := time.Now().Local()
|
|
|
+ for i := range permissionList {
|
|
|
+ permissionIdName[permissionList[i].ChartPermissionId] = permissionList[i].PermissionName
|
|
|
+ }
|
|
|
+
|
|
|
+ researchType := item.ResearchType
|
|
|
+ newPermissions := make([]*models.ReportChapterTypePermission, 0) // 报告章节权限表(新)
|
|
|
+ newWeekPermissions := make([]*models.ChartPermissionChapterMapping, 0) // 报告章节权限表(老)
|
|
|
+ for i := range req.ChartPermissionIdList {
|
|
|
+ newPermissions = append(newPermissions, &models.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, &models.ChartPermissionChapterMapping{
|
|
|
+ ChartPermissionId: req.ChartPermissionIdList[i],
|
|
|
+ ReportChapterTypeId: item.ReportChapterTypeId,
|
|
|
+ ResearchType: researchType,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 设置权限
|
|
|
+ e = models.SetReportChapterTypePermission(item.ReportChapterTypeId, researchType, newPermissions, newWeekPermissions)
|
|
|
+ if e != nil {
|
|
|
+ br.Msg = "操作失败"
|
|
|
+ br.ErrMsg = "设置章节类型权限失败, Err: " + e.Error()
|
|
|
return
|
|
|
}
|
|
|
// 更新研报章节表冗余
|
|
|
- if ret.OriginReportChapterTypeName != req.ReportChapterTypeName {
|
|
|
+ if originName != req.ReportChapterTypeName {
|
|
|
go func() {
|
|
|
_ = models.UpdateReportChapterTypeNameByTypeId(req.ReportChapterTypeId, req.ReportChapterTypeName)
|
|
|
}()
|
|
@@ -165,6 +324,12 @@ func (this *ReportChapterTypeController) Edit() {
|
|
|
_ = utils.Rc.Delete(key)
|
|
|
}
|
|
|
|
|
|
+ go func() {
|
|
|
+ var syncReq services.ChapterTypeSyncReq
|
|
|
+ syncReq.ResearchType = researchType
|
|
|
+ syncReq.ReportChapterTypeId = item.ReportChapterTypeId
|
|
|
+ _, _ = services.ReportChapterTypeSync(&syncReq)
|
|
|
+ }()
|
|
|
br.Ret = 200
|
|
|
br.Success = true
|
|
|
br.Msg = "操作成功"
|
|
@@ -282,11 +447,12 @@ func (this *ReportChapterTypeController) AuthSetting() {
|
|
|
br.Msg = "章节不存在或已被删除"
|
|
|
return
|
|
|
}
|
|
|
- // todo 测试品种在报告中的使用
|
|
|
- permissionList, e := services.GetChartPermissionList("", []interface{}{})
|
|
|
+ cond := ` and product_id=1`
|
|
|
+ pars := make([]interface{}, 0)
|
|
|
+ permissionList, e := services.GetChartPermissionList(cond, pars)
|
|
|
if e != nil {
|
|
|
- br.Msg = "操作失败"
|
|
|
- br.ErrMsg = "获取权限列表失败, Err: " + e.Error()
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取品种列表失败, Err: " + e.Error()
|
|
|
return
|
|
|
}
|
|
|
permissionIdName := make(map[int]string)
|
|
@@ -425,7 +591,10 @@ func (this *ReportChapterTypeController) Move() {
|
|
|
br.ErrMsg = "移动品种失败, Err: " + e.Error()
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
+ go func() {
|
|
|
+ var syncReq services.ChapterTypeSyncReq
|
|
|
+ _, _ = services.ReportChapterTypeSync(&syncReq)
|
|
|
+ }()
|
|
|
br.Ret = 200
|
|
|
br.Success = true
|
|
|
br.Msg = "操作成功"
|
|
@@ -468,13 +637,33 @@ func (this *ReportChapterTypeController) SetEnabled() {
|
|
|
br.Msg = "请选择正确的启用禁用状态"
|
|
|
return
|
|
|
}
|
|
|
- e := services.SetEnabledReportChapterType(&req)
|
|
|
- if e != nil {
|
|
|
+ ob := new(models.ReportChapterType)
|
|
|
+ item, err := models.GetReportChapterTypeById(req.ReportChapterTypeId)
|
|
|
+ if err != nil {
|
|
|
+ if err.Error() == utils.ErrNoRow() {
|
|
|
+ br.Msg = "章节不存在"
|
|
|
+ br.ErrMsg = "章节不存在, Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ br.Msg = "获取章节信息失败"
|
|
|
+ br.ErrMsg = "获取章节信息失败, Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if item == nil {
|
|
|
+ br.Msg = "章节不存在"
|
|
|
+ return
|
|
|
+ }
|
|
|
+ //设置分类启用、禁用状态
|
|
|
+ err = ob.SetEnabled(req.ReportChapterTypeId, req.Enabled)
|
|
|
+ if err != nil {
|
|
|
br.Msg = "操作失败"
|
|
|
- br.ErrMsg = "设置报告章节状态失败, Err: " + e.Error()
|
|
|
+ br.ErrMsg = "设置报告章节状态失败, Err: " + err.Error()
|
|
|
return
|
|
|
}
|
|
|
-
|
|
|
+ go func() {
|
|
|
+ var syncReq services.ChapterTypeSyncReq
|
|
|
+ _, _ = services.ReportChapterTypeSync(&syncReq)
|
|
|
+ }()
|
|
|
br.Ret = 200
|
|
|
br.Success = true
|
|
|
br.Msg = "操作成功"
|