123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196 |
- package line_feature
- import (
- "eta/eta_mobile/models/data_manage"
- "eta/eta_mobile/utils"
- "fmt"
- "github.com/beego/beego/v2/client/orm"
- "strconv"
- "strings"
- "time"
- )
- type BatchAddChart struct {
- ChartInfo *data_manage.ChartInfo
- EdbMappingList []*data_manage.ChartEdbMapping
- MultipleGraphConfigChartMapping *data_manage.MultipleGraphConfigChartMapping
- }
- func CreateLineFeatureChartAndEdb(chartInfo *data_manage.ChartInfo, edbMappingList []*data_manage.ChartEdbMapping) (chartInfoId int, err error) {
- o := orm.NewOrmUsingDB("data")
- tx, err := o.Begin()
- if err != nil {
- return
- }
- defer func() {
- if err != nil {
- _ = tx.Rollback()
- } else {
- _ = tx.Commit()
- }
- }()
- // 新增图表信息
- newId, err := tx.Insert(chartInfo)
- if err != nil {
- return
- }
- // 指标mapping
- chartInfo.ChartInfoId = int(newId)
- chartInfoId = int(newId)
- if len(edbMappingList) > 0 {
- for i := range edbMappingList {
- edbMappingList[i].ChartInfoId = chartInfoId
- }
- _, err = tx.InsertMulti(len(edbMappingList), edbMappingList)
- if err != nil {
- return
- }
- }
- return
- }
- // EditLineFeatureChartAndMapping 批量新增/编辑拟合方程图表
- func EditLineFeatureChartAndMapping(req *data_manage.EditChartInfoReq, edbInfoIdStr string, calendar string, dateType, disabled int, extraConfig string) (err error) {
- o := orm.NewOrmUsingDB("data")
- to, err := o.Begin()
- if err != nil {
- return
- }
- defer func() {
- if err != nil {
- _ = to.Rollback()
- } else {
- _ = to.Commit()
- }
- }()
- var pars []interface{}
- pars = append(pars, req.ChartName)
- pars = append(pars, req.ChartNameEn)
- pars = append(pars, edbInfoIdStr)
- pars = append(pars, req.ChartClassifyId)
- pars = append(pars, disabled)
- pars = append(pars, extraConfig)
- sql := ` UPDATE chart_info
- SET
- chart_name =?,
- chart_name_en =?,
- edb_info_ids=?,
- chart_classify_id = ?,
- modify_time = NOW(),
- disabled = ?,
- extra_config = ?
- `
- if calendar != "" {
- sql += `,calendar = ? `
- pars = append(pars, calendar)
- }
- if dateType > 0 {
- sql += `,date_type = ? `
- pars = append(pars, dateType)
- }
- sql += `,start_date = ? `
- pars = append(pars, req.StartDate)
- sql += `,end_date = ? `
- pars = append(pars, req.EndDate)
- sql += `,season_start_date = ? `
- pars = append(pars, req.StartDate)
- sql += `,season_end_date = ? `
- pars = append(pars, req.EndDate)
- sql += `,left_min = ? `
- pars = append(pars, req.LeftMin)
- sql += `,left_max = ? `
- pars = append(pars, req.LeftMax)
- sql += `,right_min = ? `
- pars = append(pars, req.RightMin)
- sql += `,right_max = ? `
- pars = append(pars, req.RightMax)
- sql += `WHERE chart_info_id = ?`
- pars = append(pars, req.ChartInfoId)
- _, err = to.Raw(sql, pars).Exec()
- if err != nil {
- fmt.Println("UPDATE chart_info Err:", err.Error())
- return err
- }
- chartEdbMappingIdList := make([]string, 0)
- for _, v := range req.CorrelationChartInfo.EdbInfoIdList {
- // 查询该指标是否存在,如果存在的话,那么就去修改,否则新增
- var tmpChartEdbMapping *data_manage.ChartEdbMapping
- csql := `SELECT * FROM chart_edb_mapping WHERE chart_info_id=? AND edb_info_id=? AND source = ? `
- err = to.Raw(csql, req.ChartInfoId, v.EdbInfoId, utils.CHART_SOURCE_CORRELATION).QueryRow(&tmpChartEdbMapping)
- if err != nil && err.Error() != utils.ErrNoRow() {
- fmt.Println("QueryRow Err:", err.Error())
- return err
- }
- if tmpChartEdbMapping != nil {
- chartEdbMappingIdList = append(chartEdbMappingIdList, strconv.Itoa(tmpChartEdbMapping.ChartEdbMappingId))
- //tmpChartEdbMapping.ModifyTime = time.Now()
- //tmpChartEdbMapping.MaxData = v.MaxData
- //tmpChartEdbMapping.MinData = v.MinData
- //tmpChartEdbMapping.IsOrder = v.IsOrder
- //tmpChartEdbMapping.IsAxis = v.IsAxis
- //tmpChartEdbMapping.EdbInfoType = v.EdbInfoType
- //tmpChartEdbMapping.LeadValue = v.LeadValue
- //tmpChartEdbMapping.LeadUnit = v.LeadUnit
- //tmpChartEdbMapping.ChartStyle = v.ChartStyle
- //tmpChartEdbMapping.ChartColor = v.ChartColor
- //tmpChartEdbMapping.PredictChartColor = v.PredictChartColor
- //tmpChartEdbMapping.ChartWidth = v.ChartWidth
- //_, err = to.Update(tmpChartEdbMapping, "ModifyTime", "MaxData", "MinData", "IsOrder", "IsAxis", "EdbInfoType", "LeadValue", "LeadUnit", "ChartStyle", "ChartColor", "PredictChartColor", "ChartWidth")
- //if err != nil {
- // fmt.Println("chart_edb_mapping Err:" + err.Error())
- // return err
- //}
- } else {
- mapItem := new(data_manage.ChartEdbMapping)
- mapItem.ChartInfoId = req.ChartInfoId
- mapItem.EdbInfoId = v.EdbInfoId
- mapItem.CreateTime = time.Now()
- mapItem.ModifyTime = time.Now()
- timestamp := strconv.FormatInt(time.Now().UnixNano(), 10)
- mapItem.UniqueCode = utils.MD5(utils.CHART_PREFIX + "_" + timestamp + "_" + strconv.Itoa(v.EdbInfoId))
- //mapItem.MaxData = v.MaxData
- //mapItem.MinData = v.MinData
- mapItem.IsOrder = true
- mapItem.IsAxis = 1
- mapItem.EdbInfoType = 1
- //mapItem.LeadValue = v.LeadValue
- //mapItem.LeadUnit = v.LeadUnit
- //mapItem.ChartStyle = v.ChartStyle
- //mapItem.ChartColor = v.ChartColor
- //mapItem.PredictChartColor = v.PredictChartColor
- //mapItem.ChartWidth = v.ChartWidth
- mapItem.Source = utils.CHART_SOURCE_CORRELATION
- tmpId, err := to.Insert(mapItem)
- if err != nil {
- fmt.Println("AddChartEdbMapping Err:" + err.Error())
- return err
- }
- mapItem.ChartEdbMappingId = int(tmpId)
- chartEdbMappingIdList = append(chartEdbMappingIdList, strconv.Itoa(mapItem.ChartEdbMappingId))
- }
- }
- if len(chartEdbMappingIdList) > 0 {
- chartEdbMappingIdStr := strings.Join(chartEdbMappingIdList, ",")
- dsql := `DELETE FROM chart_edb_mapping WHERE chart_info_id=? AND chart_edb_mapping_id NOT IN(` + chartEdbMappingIdStr + `)`
- _, err = to.Raw(dsql, req.ChartInfoId).Exec()
- if err != nil {
- fmt.Println("delete err:" + err.Error())
- return err
- }
- }
- return
- }
|