|
@@ -12,6 +12,7 @@ import (
|
|
|
"github.com/rdlucklib/rdluck_tools/paging"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
+ "time"
|
|
|
)
|
|
|
|
|
|
// ChartInfoController
|
|
@@ -21,14 +22,14 @@ type ChartInfoController struct {
|
|
|
}
|
|
|
|
|
|
// List
|
|
|
-// @Title 相关性图表列表接口
|
|
|
-// @Description 相关性图表列表接口
|
|
|
+// @Title 跨品种分析图表列表接口
|
|
|
+// @Description 跨品种分析图表列表接口
|
|
|
// @Param PageSize query int true "每页数据条数"
|
|
|
// @Param CurrentIndex query int true "当前页页码,从1开始"
|
|
|
// @Param ChartClassifyId query int true "分类id"
|
|
|
// @Param Keyword query string true "搜索关键词"
|
|
|
// @Param IsShowMe query bool true "是否只看我的,true、false"
|
|
|
-// @Param Source query int true "图表类型,3:相关性,4:滚动相关性"
|
|
|
+// @Param Source query int true "图表类型,10:跨品种分析
|
|
|
// @Success 200 {object} data_manage.ChartListResp
|
|
|
// @router /chart_info/list [get]
|
|
|
func (c *ChartInfoController) List() {
|
|
@@ -238,6 +239,11 @@ func (c *ChartInfoController) Preview() {
|
|
|
br.IsSendEmail = false
|
|
|
return
|
|
|
}
|
|
|
+ if req.CalculateUnit == `` {
|
|
|
+ br.Msg = "请设置时间频度"
|
|
|
+ br.IsSendEmail = false
|
|
|
+ return
|
|
|
+ }
|
|
|
|
|
|
// 品种配置
|
|
|
varietyListList := len(req.VarietyList)
|
|
@@ -261,7 +267,7 @@ func (c *ChartInfoController) Preview() {
|
|
|
}
|
|
|
|
|
|
chartInfo := new(data_manage.ChartInfoView)
|
|
|
- chartInfo.ChartType = 9
|
|
|
+ chartInfo.ChartType = utils.CHART_SOURCE_CROSS_HEDGING
|
|
|
|
|
|
// 获取图表x轴y轴
|
|
|
_, dataResp, err, errMsg, isSendEmail := cross_variety.GetChartData(0, req)
|
|
@@ -279,3 +285,405 @@ func (c *ChartInfoController) Preview() {
|
|
|
br.Success = true
|
|
|
br.Msg = "获取成功"
|
|
|
}
|
|
|
+
|
|
|
+// Add
|
|
|
+// @Title 新增图表接口
|
|
|
+// @Description 新增图表接口
|
|
|
+// @Param request body request.AddChartInfoReq true "type json string"
|
|
|
+// @Success 200 {object} data_manage.AddChartInfoResp
|
|
|
+// @router /chart_info/add [post]
|
|
|
+func (c *ChartInfoController) Add() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ c.Data["json"] = br
|
|
|
+ c.ServeJSON()
|
|
|
+ }()
|
|
|
+
|
|
|
+ sysUser := c.SysUser
|
|
|
+ if sysUser == nil {
|
|
|
+ br.Msg = "请登录"
|
|
|
+ br.ErrMsg = "请登录,SysUser Is Empty"
|
|
|
+ br.Ret = 408
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ cacheKey := "CACHE_CHART_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
|
|
|
+ if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
|
|
|
+ br.Msg = "系统处理中,请稍后重试!"
|
|
|
+ br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(c.Ctx.Input.RequestBody)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ defer func() {
|
|
|
+ _ = utils.Rc.Delete(cacheKey)
|
|
|
+ }()
|
|
|
+
|
|
|
+ var req request.AddChartReq
|
|
|
+ err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "参数解析异常!"
|
|
|
+ br.ErrMsg = "参数解析失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 添加图表
|
|
|
+ chartInfo, err, errMsg, isSendEmail := cross_variety.AddChartInfo(req, sysUser)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "保存失败"
|
|
|
+ if errMsg != `` {
|
|
|
+ br.Msg = errMsg
|
|
|
+ }
|
|
|
+ br.ErrMsg = err.Error()
|
|
|
+ br.IsSendEmail = isSendEmail
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //新增操作日志
|
|
|
+ {
|
|
|
+ chartLog := new(data_manage.ChartInfoLog)
|
|
|
+ chartLog.ChartInfoId = chartInfo.ChartInfoId
|
|
|
+ chartLog.ChartName = req.ChartName
|
|
|
+ chartLog.ChartClassifyId = chartInfo.ChartClassifyId
|
|
|
+ chartLog.SysUserId = sysUser.AdminId
|
|
|
+ chartLog.SysUserRealName = sysUser.RealName
|
|
|
+ chartLog.UniqueCode = chartInfo.UniqueCode
|
|
|
+ chartLog.CreateTime = time.Now()
|
|
|
+ chartLog.Content = string(c.Ctx.Input.RequestBody)
|
|
|
+ chartLog.Status = "新增跨品种分析图表"
|
|
|
+ chartLog.Method = c.Ctx.Input.URI()
|
|
|
+ go data_manage.AddChartInfoLog(chartLog)
|
|
|
+ }
|
|
|
+
|
|
|
+ resp := new(data_manage.AddChartInfoResp)
|
|
|
+ resp.ChartInfoId = chartInfo.ChartInfoId
|
|
|
+ resp.UniqueCode = chartInfo.UniqueCode
|
|
|
+ resp.ChartType = chartInfo.ChartType
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "保存成功"
|
|
|
+ br.Data = resp
|
|
|
+ br.IsAddLog = true
|
|
|
+}
|
|
|
+
|
|
|
+// Edit
|
|
|
+// @Title 编辑图表接口
|
|
|
+// @Description 编辑图表接口
|
|
|
+// @Param request body request.EditChartInfoReq true "type json string"
|
|
|
+// @Success Ret=200 保存成功
|
|
|
+// @router /chart_info/edit [post]
|
|
|
+func (c *ChartInfoController) Edit() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ c.Data["json"] = br
|
|
|
+ c.ServeJSON()
|
|
|
+ }()
|
|
|
+
|
|
|
+ sysUser := c.SysUser
|
|
|
+ if sysUser == nil {
|
|
|
+ br.Msg = "请登录"
|
|
|
+ br.ErrMsg = "请登录,SysUser Is Empty"
|
|
|
+ br.Ret = 408
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ var req request.EditChartReq
|
|
|
+ err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "参数解析异常!"
|
|
|
+ br.ErrMsg = "参数解析失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ chartItem, err, errMsg, isSendEmail := cross_variety.EditChartInfo(req, sysUser)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "保存失败"
|
|
|
+ if errMsg != `` {
|
|
|
+ br.Msg = errMsg
|
|
|
+ }
|
|
|
+ br.ErrMsg = err.Error()
|
|
|
+ br.IsSendEmail = isSendEmail
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ resp := new(data_manage.AddChartInfoResp)
|
|
|
+ resp.ChartInfoId = chartItem.ChartInfoId
|
|
|
+ resp.UniqueCode = chartItem.UniqueCode
|
|
|
+ //resp.ChartType = req.ChartType
|
|
|
+
|
|
|
+ //新增操作日志
|
|
|
+ {
|
|
|
+ chartLog := new(data_manage.ChartInfoLog)
|
|
|
+ chartLog.ChartName = chartItem.ChartName
|
|
|
+ chartLog.ChartInfoId = req.ChartInfoId
|
|
|
+ chartLog.ChartClassifyId = chartItem.ChartClassifyId
|
|
|
+ chartLog.SysUserId = sysUser.AdminId
|
|
|
+ chartLog.SysUserRealName = sysUser.RealName
|
|
|
+ chartLog.UniqueCode = chartItem.UniqueCode
|
|
|
+ chartLog.CreateTime = time.Now()
|
|
|
+ chartLog.Content = string(c.Ctx.Input.RequestBody)
|
|
|
+ chartLog.Status = "编辑跨品种分析图表"
|
|
|
+ chartLog.Method = c.Ctx.Input.URL()
|
|
|
+ go data_manage.AddChartInfoLog(chartLog)
|
|
|
+ }
|
|
|
+
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "保存成功"
|
|
|
+ br.Data = resp
|
|
|
+ br.IsAddLog = true
|
|
|
+}
|
|
|
+
|
|
|
+// Detail
|
|
|
+// @Title 获取图表详情
|
|
|
+// @Description 获取图表详情接口
|
|
|
+// @Param ChartInfoId query int true "图表id"
|
|
|
+// @Success 200 {object} data_manage.ChartInfoDetailResp
|
|
|
+// @router /chart_info/detail [get]
|
|
|
+func (c *ChartInfoController) Detail() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ c.Data["json"] = br
|
|
|
+ c.ServeJSON()
|
|
|
+ }()
|
|
|
+ sysUser := c.SysUser
|
|
|
+ if sysUser == nil {
|
|
|
+ br.Msg = "请登录"
|
|
|
+ br.ErrMsg = "请登录,SysUser Is Empty"
|
|
|
+ br.Ret = 408
|
|
|
+ return
|
|
|
+ }
|
|
|
+ chartInfoId, _ := c.GetInt("ChartInfoId")
|
|
|
+ if chartInfoId <= 0 {
|
|
|
+ br.Msg = "参数有误"
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ var err error
|
|
|
+ chartInfo := new(data_manage.ChartInfoView)
|
|
|
+ chartInfo, err = data_manage.GetChartInfoViewById(chartInfoId)
|
|
|
+ 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 chartInfo.ExtraConfig == `` {
|
|
|
+ br.Msg = "图表配置信息异常"
|
|
|
+ br.ErrMsg = "图表配置信息异常"
|
|
|
+ br.IsSendEmail = false
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var config request.ChartConfigReq
|
|
|
+ err = json.Unmarshal([]byte(chartInfo.ExtraConfig), &config)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "解析跨品种分析配置失败"
|
|
|
+ br.ErrMsg = "解析跨品种分析配置失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //mappingList, err := cross_varietyModel.GetChartVarietyMappingList(chartInfo.ChartInfoId)
|
|
|
+ //if err != nil {
|
|
|
+ // br.Msg = "获取品种失败"
|
|
|
+ // br.ErrMsg = "获取品种失败,Err:" + err.Error()
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+ // 获取跨品种分析配置
|
|
|
+ //chartInfoCrossVariety, err := cross_varietyModel.GetChartInfoCrossVarietyByChartInfoId(chartInfo.ChartInfoId)
|
|
|
+ //if err != nil {
|
|
|
+ // br.Msg = "获取跨品种分析配置失败"
|
|
|
+ // br.ErrMsg = "获取跨品种分析配置失败,Err:" + err.Error()
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+ //
|
|
|
+ //varietyIdList := make([]int,0)
|
|
|
+ //for _,v:=range mappingList{
|
|
|
+ // varietyIdList = append(varietyIdList,v.ChartVarietyId)
|
|
|
+ //}
|
|
|
+ //config := request.ChartConfigReq{
|
|
|
+ // TagX: chartInfoCrossVariety.ChartXTagId,
|
|
|
+ // TagY: chartInfoCrossVariety.ChartYTagId,
|
|
|
+ // CalculateValue: chartInfoCrossVariety.CalculateValue,
|
|
|
+ // CalculateUnit: chartInfoCrossVariety.CalculateUnit,
|
|
|
+ // DateConfigList: config.DateConfigList,
|
|
|
+ // VarietyList: varietyIdList,
|
|
|
+ //}
|
|
|
+ //config.TagX =
|
|
|
+
|
|
|
+ // 获取图表x轴y轴
|
|
|
+ _, dataResp, err, errMsg, isSendEmail := cross_variety.GetChartData(0, config)
|
|
|
+ if err != nil {
|
|
|
+ br.IsSendEmail = isSendEmail
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ if errMsg != `` {
|
|
|
+ br.Msg = errMsg
|
|
|
+ }
|
|
|
+ br.ErrMsg = "获取图表,指标信息失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 完善指标信息
|
|
|
+ //edbList, e := correlationServ.GetChartEdbInfoFormat(chartInfo.ChartInfoId, edbInfoMappingA, edbInfoMappingB)
|
|
|
+ //if e != nil {
|
|
|
+ // br.Msg = "获取失败"
|
|
|
+ // br.ErrMsg = "获取相关性图表, 完善指标信息失败, Err:" + e.Error()
|
|
|
+ // return
|
|
|
+ //}
|
|
|
+
|
|
|
+ // 判断是否加入我的图库
|
|
|
+ if chartInfoId > 0 && chartInfo != nil {
|
|
|
+ {
|
|
|
+ var myChartCondition string
|
|
|
+ var myChartPars []interface{}
|
|
|
+ myChartCondition += ` AND a.admin_id=? `
|
|
|
+ myChartPars = append(myChartPars, sysUser.AdminId)
|
|
|
+ myChartCondition += ` AND a.chart_info_id=? `
|
|
|
+ myChartPars = append(myChartPars, chartInfo.ChartInfoId)
|
|
|
+
|
|
|
+ myChartList, err := data_manage.GetMyChartByCondition(myChartCondition, myChartPars)
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ br.Msg = "获取失败"
|
|
|
+ br.ErrMsg = "获取我的图表信息失败,GetMyChartByCondition,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if myChartList != nil && len(myChartList) > 0 {
|
|
|
+ chartInfo.IsAdd = true
|
|
|
+ chartInfo.MyChartId = myChartList[0].MyChartId
|
|
|
+ chartInfo.MyChartClassifyId = myChartList[0].MyChartClassifyId
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //图表操作权限
|
|
|
+ chartInfo.IsEdit = data.CheckOpChartPermission(sysUser, chartInfo.SysUserId)
|
|
|
+ ////判断是否需要展示英文标识
|
|
|
+ //chartInfo.IsEnChart = data.CheckIsEnChart(chartInfo.ChartNameEn, edbList[0:1], chartInfo.Source, chartInfo.ChartType)
|
|
|
+ //chartInfo.UnitEn = edbInfoMappingA.UnitEn
|
|
|
+
|
|
|
+ // 另存为
|
|
|
+ chartInfo.Button = data_manage.ChartViewButton{
|
|
|
+ IsEdit: chartInfo.IsEdit,
|
|
|
+ IsEnChart: chartInfo.IsEnChart,
|
|
|
+ IsAdd: chartInfo.IsAdd,
|
|
|
+ IsCopy: true,
|
|
|
+ IsSetName: chartInfo.IsSetName,
|
|
|
+ }
|
|
|
+
|
|
|
+ resp := new(data_manage.ChartInfoDetailResp)
|
|
|
+ resp.ChartInfo = chartInfo
|
|
|
+ resp.DataResp = dataResp
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "获取成功"
|
|
|
+ br.Data = resp
|
|
|
+}
|
|
|
+
|
|
|
+// Copy
|
|
|
+// @Title 复制并新增图表接口
|
|
|
+// @Description 新增图表接口
|
|
|
+// @Param request body data_manage.CopyAddChartInfoReq true "type json string"
|
|
|
+// @Success 200 {object} data_manage.AddChartInfoResp
|
|
|
+// @router /chart_info/copy [post]
|
|
|
+func (c *ChartInfoController) Copy() {
|
|
|
+ br := new(models.BaseResponse).Init()
|
|
|
+ defer func() {
|
|
|
+ c.Data["json"] = br
|
|
|
+ c.ServeJSON()
|
|
|
+ }()
|
|
|
+
|
|
|
+ sysUser := c.SysUser
|
|
|
+ if sysUser == nil {
|
|
|
+ br.Msg = "请登录"
|
|
|
+ br.ErrMsg = "请登录,SysUser Is Empty"
|
|
|
+ br.Ret = 408
|
|
|
+ return
|
|
|
+ }
|
|
|
+ deleteCache := true
|
|
|
+ cacheKey := "CACHE_CHART_INFO_ADD_" + strconv.Itoa(sysUser.AdminId)
|
|
|
+ defer func() {
|
|
|
+ if deleteCache {
|
|
|
+ utils.Rc.Delete(cacheKey)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
|
|
|
+ deleteCache = false
|
|
|
+ br.Msg = "系统处理中,请稍后重试!"
|
|
|
+ br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(c.Ctx.Input.RequestBody)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ var req request.CopyAddChartInfoReq
|
|
|
+ err := json.Unmarshal(c.Ctx.Input.RequestBody, &req)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "参数解析异常!"
|
|
|
+ br.ErrMsg = "参数解析失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取原图表信息
|
|
|
+ oldChartInfo, err := data_manage.GetChartInfoById(req.ChartInfoId)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "获取原图表信息失败"
|
|
|
+ br.ErrMsg = "获取原图表信息失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ var config request.AddChartReq
|
|
|
+ err = json.Unmarshal([]byte(oldChartInfo.ExtraConfig), &config)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "原图表信息配置解析异常!"
|
|
|
+ br.ErrMsg = "原图表信息配置解析失败,Err:" + err.Error()
|
|
|
+ return
|
|
|
+ }
|
|
|
+ config.ChartName = req.ChartName
|
|
|
+
|
|
|
+ // 添加图表
|
|
|
+ chartInfo, err, errMsg, isSendEmail := cross_variety.AddChartInfo(config, sysUser)
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "保存失败"
|
|
|
+ if errMsg != `` {
|
|
|
+ br.Msg = errMsg
|
|
|
+ }
|
|
|
+ br.ErrMsg = err.Error()
|
|
|
+ br.IsSendEmail = isSendEmail
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if err != nil {
|
|
|
+ br.Msg = "保存失败"
|
|
|
+ if errMsg != `` {
|
|
|
+ br.Msg = errMsg
|
|
|
+ }
|
|
|
+ br.ErrMsg = err.Error()
|
|
|
+ br.IsSendEmail = isSendEmail
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ //新增操作日志
|
|
|
+ {
|
|
|
+ chartLog := new(data_manage.ChartInfoLog)
|
|
|
+ chartLog.ChartInfoId = chartInfo.ChartInfoId
|
|
|
+ chartLog.ChartName = req.ChartName
|
|
|
+ chartLog.ChartClassifyId = chartInfo.ChartClassifyId
|
|
|
+ chartLog.SysUserId = sysUser.AdminId
|
|
|
+ chartLog.SysUserRealName = sysUser.RealName
|
|
|
+ chartLog.UniqueCode = chartInfo.UniqueCode
|
|
|
+ chartLog.CreateTime = time.Now()
|
|
|
+ chartLog.Content = string(c.Ctx.Input.RequestBody)
|
|
|
+ chartLog.Status = "复制跨品种分析图表"
|
|
|
+ chartLog.Method = c.Ctx.Input.URI()
|
|
|
+ go data_manage.AddChartInfoLog(chartLog)
|
|
|
+ }
|
|
|
+
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ br.Msg = "保存成功"
|
|
|
+ br.Data = data_manage.AddChartInfoResp{
|
|
|
+ ChartInfoId: chartInfo.ChartInfoId,
|
|
|
+ UniqueCode: chartInfo.UniqueCode,
|
|
|
+ ChartType: chartInfo.ChartType,
|
|
|
+ }
|
|
|
+ br.IsAddLog = true
|
|
|
+}
|