123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689 |
- package models
- import (
- "context"
- "eta/eta_api/models/data_manage"
- "eta/eta_api/utils"
- "fmt"
- "sort"
- "strconv"
- "strings"
- "time"
- "github.com/beego/beego/v2/client/orm"
- "github.com/rdlucklib/rdluck_tools/paging"
- )
- type DataList struct {
- TradeCode string `orm:"column(TRADE_CODE)" description:"指标编码"`
- SecName string `orm:"column(SEC_NAME)" description:"指标名称"`
- Unit string `orm:"column(UNIT)" description:"单位"`
- Remark string `orm:"column(REMARK)" description:"备注"`
- Frequency string `description:"频度"`
- ClassifyId int `description:"分类id"`
- ClassifyName string `description:"分类名称"`
- Dt string `orm:"column(DT)" description:"录入日期"`
- Close float64 `orm:"column(CLOSE)" description:"录入值"`
- ModifyTime string `description:"修改时间"`
- }
- type DataListResp struct {
- List []*DataList
- Paging *paging.PagingItem `description:"分页数据"`
- }
- func GetDataList(condition string, pars []interface{}, startSize, pageSize int) (items []*DataList, err error) {
- sql := `select a.TRADE_CODE,a.SEC_NAME,a.UNIT,a.frequency,a.classify_id,b.classify_name,c.DT,c.CLOSE,c.modify_time FROM edbdata AS c
- inner join edbinfo AS a ON a.TRADE_CODE=c.TRADE_CODE
- left join edbdata_classify AS b ON a.classify_id=b.classify_id
- where a.classify_id>0`
- if condition != "" {
- sql += condition
- }
- sql += ` order by c.DT desc limit ?,? `
- o := orm.NewOrmUsingDB("edb")
- _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
- return
- }
- func GetDataListCount(condition string, pars []interface{}) (count int, err error) {
- sql := ` select count(1) as count FROM edbdata AS c
- inner join edbinfo AS a ON a.TRADE_CODE=c.TRADE_CODE
- left join edbdata_classify AS b ON a.classify_id=b.classify_id
- where a.classify_id>0 `
- if condition != "" {
- sql += condition
- }
- o := orm.NewOrmUsingDB("edb")
- err = o.Raw(sql, pars).QueryRow(&count)
- return
- }
- type DataAddReq struct {
- TradeCode string `description:"指标唯一编码"`
- CreateDate string `description:"创建日期"`
- Close string `description:"录入值"`
- }
- type Edbdata struct {
- TradeCode string `orm:"column(TRADE_CODE);pk" description:"指标编码"`
- Dt string `orm:"column(DT)" description:"日期"`
- Close string `orm:"column(CLOSE)" description:"值"`
- ModifyTime time.Time `orm:"column(modify_time)" description:"修改时间"`
- }
- func GetDataInfo(tradeCode, creteDate string) (item *Edbdata, err error) {
- sql := " SELECT * FROM edbdata WHERE TRADE_CODE=? AND DT=? "
- o := orm.NewOrmUsingDB("edb")
- err = o.Raw(sql, tradeCode, creteDate).QueryRow(&item)
- return
- }
- func AddEdbdata(item *Edbdata) (lastId int64, err error) {
- o := orm.NewOrmUsingDB("edb")
- lastId, err = o.Insert(item)
- return
- }
- type DataEditReq struct {
- TradeCode string `description:"指标唯一编码"`
- CreateDate string `description:"创建日期"`
- Close interface{} `description:"录入值"`
- OldCreateDate string `description:"旧的录入日期"`
- }
- // BatchDataEditReq 批量修改指标
- type BatchDataEditReq struct {
- OldCreateDate string `description:"旧的录入日期"`
- CreateDate string `description:"新的录入日期"`
- List []DataEditReq `description:"需要修改的数据"`
- }
- // 编辑数据
- func EditEdbdata(item *Edbdata) (err error) {
- o := orm.NewOrmUsingDB("edb")
- sql := ` UPDATE edbdata SET CLOSE = ?,modify_time=NOW() WHERE TRADE_CODE = ? AND DT = ? `
- _, err = o.Raw(sql, item.Close, item.TradeCode, item.Dt).Exec()
- return
- }
- type EdbdataDeleteRecord struct {
- Id int `orm:"column(id);pk"`
- TradeCode string `orm:"column(TRADE_CODE)" description:"指标编码"`
- Dt string `orm:"column(DT)" description:"日期"`
- Close string `orm:"column(CLOSE)" description:"值"`
- ModifyTime time.Time `orm:"column(modify_time)" description:"修改时间"`
- CreateTime time.Time
- SysUserId int
- }
- func AddEdbdataDeleteRecord(item *EdbdataDeleteRecord) (lastId int64, err error) {
- o := orm.NewOrmUsingDB("edb")
- lastId, err = o.Insert(item)
- return
- }
- // DeleteEdbData 根据指标code和日期删除数据
- func DeleteEdbData(tradeCode, dt string) (err error) {
- o := orm.NewOrmUsingDB("edb")
- sql := ` DELETE FROM edbdata WHERE TRADE_CODE = ? AND DT = ? `
- _, err = o.Raw(sql, tradeCode, dt).Exec()
- return
- }
- // DeleteAllEdbData 根据指标code删除数据
- func DeleteAllEdbData(tradeCode string) (err error) {
- o := orm.NewOrmUsingDB("edb")
- sql := ` DELETE FROM edbdata WHERE TRADE_CODE = ? `
- _, err = o.Raw(sql, tradeCode).Exec()
- return
- }
- type Edbinfo struct {
- TradeCode string `orm:"column(TRADE_CODE);pk" description:"指标code"`
- SecName string `orm:"column(SEC_NAME);" description:"指标名称"`
- Unit string `orm:"column(UNIT);" description:"单位"`
- Remark string `orm:"column(REMARK);" description:"备注"`
- Frequency string `orm:"column(frequency)" description:"频度"`
- ClassifyId int `orm:"column(classify_id)" description:"分类id"`
- ClassifyName string `orm:"-" description:"分类名称"`
- CreateDate string `orm:"column(create_date)" description:"创建时间"`
- UserId int `orm:"column(user_id)" description:"录入用户id"`
- UserName string `orm:"column(user_name)" description:"录入用户名称"`
- NoticeTime string `orm:"column(notice_time)" description:"通知时间"`
- Mobile string `orm:"column(mobile)" description:"录入者手机号"`
- Sort int `orm:"column(sort)" description:"排序"`
- ModifyTime string `description:"最近一次更新时间"`
- IsJoinEdb int8 `description:"指标库是否已添加:0-否;1-是"`
- StartDate string `description:"数据开始日期"`
- EndDate string `description:"数据结束日期"`
- LatestValue float64 `description:"指标最新值"`
- }
- func DeleteEdbinfoByTraceCodeList(tradeCodeList []string) (err error) {
- if len(tradeCodeList) == 0 {
- return
- }
- o := orm.NewOrmUsingDB("edb")
- err = o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error {
- var holder []string
- for range tradeCodeList {
- holder = append(holder, "?")
- }
- sql := ` DELETE FROM edbdata WHERE TRADE_CODE in (` + strings.Join(holder, ",") + `) `
- _, err := txOrm.Raw(sql, tradeCodeList).Exec()
- if err != nil {
- return err
- }
- sql = ` DELETE FROM edbinfo WHERE TRADE_CODE in (` + strings.Join(holder, ",") + `)`
- _, err = txOrm.Raw(sql, tradeCodeList).Exec()
- if err != nil {
- return err
- }
- return nil
- })
- return
- }
- func GetEdbinfoListCount(condition string, pars []interface{}, mobile string, roleType int) (count int, err error) {
- o := orm.NewOrmUsingDB("edb")
- sql := ``
- if mobile != "" && roleType == 1 {
- sql = `SELECT COUNT(1) AS count FROM edbinfo AS a
- INNER JOIN edbinfo_user AS c ON a.TRADE_CODE=c.TRADE_CODE AND c.mobile=?
- WHERE a.classify_id>0`
- if condition != "" {
- sql += condition
- }
- err = o.Raw(sql, mobile, pars).QueryRow(&count)
- } else {
- sql := `SELECT COUNT(1) AS count FROM edbinfo AS a WHERE a.classify_id>0`
- if condition != "" {
- sql += condition
- }
- err = o.Raw(sql, pars).QueryRow(&count)
- }
- return
- }
- type EdbinfoItem struct {
- TradeCode string `orm:"column(TRADE_CODE);pk" description:"指标code"`
- SecName string `orm:"column(SEC_NAME);" description:"指标名称"`
- Unit string `orm:"column(UNIT);" description:"单位"`
- Remark string `orm:"column(REMARK);" description:"备注"`
- Frequency string `description:"频度"`
- ClassifyId int `description:"分类id"`
- ClassifyName string `description:"分类名称"`
- CreateDate string `description:"创建时间"`
- UserId int `description:"录入用户id"`
- UserName string `description:"录入用户名称"`
- NoticeTime string `description:"通知时间"`
- Mobile string `description:"录入者手机号"`
- ModifyTime string `description:"最近一次更新时间"`
- StartDate string `description:"数据开始日期"`
- EndDate string `description:"数据结束日期"`
- LatestValue float64 `description:"指标最新值"`
- }
- func GetEdbinfoItemList(condition string, pars []interface{}, startSize, pageSize int, mobile string, roleType int) (items []*EdbinfoItem, err error) {
- o := orm.NewOrmUsingDB("edb")
- sql := ``
- if mobile != "" && roleType == 1 {
- sql = ` SELECT DISTINCT a.*,b.classify_name FROM edbinfo AS a
- LEFT JOIN edbdata_classify AS b ON a.classify_id=b.classify_id
- INNER JOIN edbinfo_user AS c ON a.TRADE_CODE=c.TRADE_CODE AND c.mobile=?
- WHERE a.classify_id>0`
- if condition != "" {
- sql += condition
- }
- sql += ` ORDER BY a.create_date DESC LIMIT ?,? `
- _, err = o.Raw(sql, mobile, pars, startSize, pageSize).QueryRows(&items)
- } else {
- sql = `SELECT DISTINCT a.*,b.classify_name FROM edbinfo AS a
- LEFT JOIN edbdata_classify AS b on a.classify_id=b.classify_id
- WHERE a.classify_id>0`
- if condition != "" {
- sql += condition
- }
- sql += ` ORDER BY a.create_date DESC LIMIT ?,? `
- _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
- }
- return
- }
- // EdbParamsInfo 指标数据结构体
- type EdbParamsInfo struct {
- Unit string `orm:"column(UNIT);" description:"单位"`
- Frequency string `orm:"column(frequency);" description:"单位"`
- }
- // GetEdbUnitList 获取指标单位
- func GetEdbUnitList() (items []*EdbParamsInfo, err error) {
- o := orm.NewOrmUsingDB("edb")
- sql := `SELECT UNIT from edbinfo group by UNIT`
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- // GetEdbFrequencyList 获取指标频度
- func GetEdbFrequencyList(classifyId, userId int) (items []*EdbParamsInfo, err error) {
- o := orm.NewOrmUsingDB("edb")
- sql := `SELECT frequency from edbinfo a
- join edbdata b on a.TRADE_CODE=b.TRADE_CODE
- where classify_id = ? `
- if userId > 0 {
- sql += ` and a.user_id = ` + fmt.Sprint(userId) + ` `
- }
- sql += ` group by a.frequency`
- _, err = o.Raw(sql, classifyId).QueryRows(&items)
- return
- }
- type TargetListResp struct {
- List []*EdbinfoItem
- Paging *paging.PagingItem `description:"分页数据"`
- }
- type EdbinfoAddReq struct {
- SecName string `description:"指标名称"`
- Unit string `description:"单位"`
- Frequency string `description:"频度"`
- ClassifyId int `description:"分类id"`
- NoticeTime string `description:"通知时间"`
- }
- // GetMaxTradeCode 获取指标最大trade_code
- func GetMaxTradeCode() (max_trade_code string, err error) {
- sql := " SELECT MAX(TRADE_CODE) AS max_trade_code FROM edbinfo WHERE LEFT(TRADE_CODE,1)='W' "
- o := orm.NewOrmUsingDB("edb")
- err = o.Raw(sql).QueryRow(&max_trade_code)
- if (err != nil && err.Error() == utils.ErrNoRow()) || max_trade_code == `` {
- max_trade_code = "W00"
- }
- return
- }
- func GetEdbinfoBySecName(secName string) (item *Edbinfo, err error) {
- sql := `SELECT * FROM edbinfo WHERE SEC_NAME=? `
- o := orm.NewOrmUsingDB("edb")
- err = o.Raw(sql, secName).QueryRow(&item)
- return
- }
- func GetEdbinfoByTradeCode(tradeCode string) (item *Edbinfo, err error) {
- sql := `SELECT * FROM edbinfo WHERE TRADE_CODE=? `
- o := orm.NewOrmUsingDB("edb")
- err = o.Raw(sql, tradeCode).QueryRow(&item)
- return
- }
- func AddEdbinfo(tradeCode, secName, unit, remark, frequency, noticeTime string, classifyId int, userId int, userName string) (err error) {
- o := orm.NewOrmUsingDB("edb")
- currTime := time.Now().Format(utils.FormatDateTime)
- edbInfo := &Edbinfo{
- TradeCode: tradeCode,
- SecName: secName,
- Unit: unit,
- Remark: remark,
- Frequency: frequency,
- ClassifyId: classifyId,
- CreateDate: currTime,
- UserId: userId,
- UserName: userName,
- NoticeTime: noticeTime,
- Mobile: "",
- ModifyTime: currTime,
- IsJoinEdb: 0,
- }
- _, err = o.Insert(edbInfo)
- return
- }
- func AddEdbinfoUser(tradeCode, mobile string) (err error) {
- o := orm.NewOrmUsingDB("edb")
- sql := `INSERT INTO edbinfo_user(TRADE_CODE, mobile) VALUES (?,?)`
- _, err = o.Raw(sql, tradeCode, mobile).Exec()
- return
- }
- type EdbinfoEditReq struct {
- TradeCode string `description:"指标code"`
- SecName string `description:"指标名称"`
- Unit string `description:"单位"`
- Frequency string `description:"频度"`
- ClassifyId int `description:"分类id"`
- NoticeTime string `description:"通知时间"`
- }
- func EditEdbinfo(tradeCode, secName, unit, frequency, noticeTime string, classifyId int) (err error) {
- sql := `UPDATE edbinfo SET SEC_NAME= ?, UNIT = ?,classify_id=?,frequency=?,notice_time=?,create_date=NOW() WHERE TRADE_CODE=? `
- o := orm.NewOrmUsingDB("edb")
- _, err = o.Raw(sql, secName, unit, classifyId, frequency, noticeTime, tradeCode).Exec()
- return
- }
- func SearchTargetEntry(classifyId int, keyWord string) (items []*Edbinfo, err error) {
- where := ""
- pars := make([]interface{}, 0)
- sql := `SELECT * FROM edbinfo WHERE classify_id>0 AND classify_id=? `
- pars = append(pars, classifyId)
- if keyWord != "" {
- sql += `AND SEC_NAME LIKE ? `
- pars = utils.GetLikeKeywordPars(pars, keyWord, 1)
- }
- sql += where
- o := orm.NewOrmUsingDB("edb")
- _, err = o.Raw(sql, pars...).QueryRows(&items)
- return
- }
- type SearchTargetListResp struct {
- List []*Edbinfo
- }
- type EdbdataClassify struct {
- ClassifyId int
- ClassifyName string
- ParentId int
- EdbInfoTotal int
- TradeCode string
- UniqueCode string
- }
- func GetEdbdataClassifyByClassifyName(classifyName string) (item *EdbdataClassify, err error) {
- sql := `SELECT * FROM edbdata_classify WHERE classify_name=? `
- o := orm.NewOrmUsingDB("edb")
- err = o.Raw(sql, classifyName).QueryRow(&item)
- return
- }
- type EdbdataClassifyList struct {
- ClassifyId int
- ClassifyName string
- ParentId int
- Child []*EdbdataClassify
- TradeCode string
- UniqueCode string
- }
- func GetEdbdataClassify(userId int64) (items []*EdbdataClassifyList, err error) {
- var newItems []*EdbdataClassifyList
- o := orm.NewOrmUsingDB("edb")
- sql := ` SELECT classify_id,classify_name,parent_id FROM edbdata_classify WHERE parent_id=0 `
- _, err = o.Raw(sql).QueryRows(&newItems)
- if err != nil {
- return
- }
- classifyLen := len(newItems)
- for i := 0; i < classifyLen; i++ {
- var childItems []*EdbdataClassify
- parentId := newItems[i].ClassifyId
- childSql := ``
- if userId > 0 {
- userClassifyList, _ := GetManualUserClassify(int(userId))
- var userIdArr []string
- for _, v := range userClassifyList {
- userIdArr = append(userIdArr, strconv.Itoa(v.ClassifyId))
- }
- userIdStr := strings.Join(userIdArr, ",")
- if userIdStr != "" {
- childSql = "SELECT a.classify_id,a.classify_name,a.parent_id FROM edbdata_classify AS a WHERE a.is_show=1 and a.classify_id IN(" + userIdStr + ") AND parent_id=? ORDER BY a.create_time ASC "
- _, err = o.Raw(childSql, parentId).QueryRows(&childItems)
- }
- } else {
- childSql = "SELECT classify_id,classify_name,parent_id FROM edbdata_classify WHERE is_show=1 and parent_id=? ORDER BY create_time ASC "
- _, err = o.Raw(childSql, parentId).QueryRows(&childItems)
- }
- if err != nil {
- return
- }
- newItems[i].Child = childItems
- }
- for _, v := range newItems {
- childLen := len(v.Child)
- if childLen > 0 {
- items = append(items, v)
- }
- }
- return
- }
- type ManualUserClassify struct {
- ManualUserClassifyId int `orm:"column(manual_user_classify_id);pk"`
- AdminId int
- ClassifyId int
- CreateTime time.Time
- }
- func GetManualUserClassify(sysUserId int) (list []*ManualUserClassify, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := `SELECT * FROM manual_user_classify WHERE admin_id=? `
- _, err = o.Raw(sql, sysUserId).QueryRows(&list)
- return
- }
- type EdbdataClassifyResp struct {
- List []*EdbdataClassifyList
- }
- func GetTargetBySecName(secName string) (item *Edbinfo, err error) {
- sql := `SELECT * FROM edbinfo WHERE SEC_NAME=? `
- o := orm.NewOrmUsingDB("edb")
- err = o.Raw(sql, secName).QueryRow(&item)
- return
- }
- // 更新指标数据信息
- func (edbinfo *Edbinfo) Update(cols []string) (err error) {
- o := orm.NewOrmUsingDB("edb")
- _, err = o.Update(edbinfo, cols...)
- return
- }
- func ModifyTargetClassifyId(tradeCode string, classifyId int) (err error) {
- sql := `UPDATE edbinfo SET classify_id=? WHERE TRADE_CODE=? `
- o := orm.NewOrmUsingDB("edb")
- _, err = o.Raw(sql, classifyId, tradeCode).Exec()
- return
- }
- func GetTargetsDataCount(tradeCode, dt string) (count int, err error) {
- sql := `SELECT COUNT(1) AS count FROM edbdata WHERE TRADE_CODE=? AND DT=? `
- o := orm.NewOrmUsingDB("edb")
- err = o.Raw(sql, tradeCode, dt).QueryRow(&count)
- return
- }
- // GetTargetsDataList 根据code获取指标数据列表
- func GetTargetsDataList(tradeCode string) (items []*Edbdata, err error) {
- o := orm.NewOrmUsingDB("edb")
- sql := `SELECT * FROM edbdata WHERE TRADE_CODE=? ORDER BY DT ASC `
- _, err = o.Raw(sql, tradeCode).QueryRows(&items)
- return
- }
- func GetTargetsData(tradeCode, dt string) (item *Edbdata, err error) {
- sql := `SELECT * FROM edbdata WHERE TRADE_CODE=? AND DT=? `
- o := orm.NewOrmUsingDB("edb")
- err = o.Raw(sql, tradeCode, dt).QueryRow(&item)
- return
- }
- func ModifyTargetsDataByImport(tradeCode, dt, close string) (err error) {
- sql := `UPDATE edbdata SET CLOSE=?,modify_time=NOW() WHERE TRADE_CODE=? AND DT=? `
- o := orm.NewOrmUsingDB("edb")
- _, err = o.Raw(sql, close, tradeCode, dt).Exec()
- return
- }
- func AddTargetsDataByImport(tradeCode, dt, close string) (err error) {
- sql := `INSERT INTO edbdata(TRADE_CODE, DT,CLOSE, modify_time)VALUES(?,?,?,NOW()) `
- o := orm.NewOrmUsingDB("edb")
- _, err = o.Raw(sql, tradeCode, dt, close).Exec()
- return
- }
- type EdbdataImportResp struct {
- Status int
- Msg string
- SuccessCount int
- FailCount int
- }
- func GetFailList(sysUserId int) (items []*EdbdataImportFail, err error) {
- o := orm.NewOrmUsingDB("edb")
- sql := ` SELECT * FROM edbdata_import_fail WHERE sys_user_id=? `
- _, err = o.Raw(sql, sysUserId).QueryRows(&items)
- return
- }
- type DataListForExport struct {
- TradeCode string `orm:"column(TRADE_CODE)" description:"指标code"`
- SecName string `orm:"column(SEC_NAME)" description:"指标名称"`
- Unit string `orm:"column(UNIT)" description:"单位"`
- Frequency string `description:"频度"`
- ClassifyId int `description:"分类id"`
- NoticeTime string `description:"通知时间"`
- ClassifyName string
- Dt string `orm:"column(DT)" description:"日期"`
- Close float64 `orm:"column(CLOSE)" description:"值"`
- }
- func GetDataListForExport(startDate, endDate, frequency, keyWord string, classifyId int) (items []*DataListForExport, err error) {
- where := ``
- var pars []interface{}
- if keyWord != "" {
- where = ` AND SEC_NAME LIKE ? `
- pars = utils.GetLikeKeywordPars(pars, keyWord, 1)
- }
- if startDate != "" {
- where += ` AND create_date>=? `
- pars = append(pars, startDate)
- }
- if endDate != "" {
- where += ` AND create_date<=? `
- pars = append(pars, endDate)
- }
- if frequency != "" {
- where += ` AND frequency=? `
- pars = append(pars, frequency)
- }
- if classifyId > 0 {
- where += ` AND classify_id=? `
- pars = append(pars, classifyId)
- }
- sql := ` SELECT a.TRADE_CODE,a.SEC_NAME,a.UNIT,a.frequency,a.classify_id,b.classify_name,c.DT,c.CLOSE FROM edbdata AS c
- INNER JOIN edbinfo AS a ON a.TRADE_CODE=c.TRADE_CODE
- LEFT JOIN edbdata_classify AS b ON a.classify_id=b.classify_id
- WHERE a.classify_id>0 `
- if where != "" {
- sql += where
- }
- sql = sql + " ORDER BY c.DT DESC "
- o := orm.NewOrmUsingDB("edb")
- _, err = o.Raw(sql, pars).QueryRows(&items)
- return
- }
- type DataDeleteReq struct {
- TradeCode string `description:"指标唯一编码"`
- CreateDate string `description:"数据录入日期"`
- }
- func DataDelete(tradeCode, createDate, close string, modifyTime time.Time, sysUserId int) (err error) {
- o := orm.NewOrmUsingDB("edb")
- to, err := o.Begin()
- if err != nil {
- return
- }
- defer func() {
- if err != nil {
- _ = to.Rollback()
- } else {
- _ = to.Commit()
- }
- }()
- recordSql := ` INSERT INTO edbdata_delete_record(TRADE_CODE,DT,CLOSE,modify_time,create_time,sys_user_id)
- VALUES(?,?,?,?,?,?)`
- _, err = to.Raw(recordSql, tradeCode, createDate, close, modifyTime, time.Now(), sysUserId).Exec()
- sql := ` DELETE FROM edbdata WHERE TRADE_CODE = ? AND DT = ? `
- _, err = to.Raw(sql, tradeCode, createDate).Exec()
- return
- }
- func GetTargetInfoCount(tradeCode string) (count int, err error) {
- sql := ` SELECT COUNT(1) AS count FROM edbdata AS c
- INNER JOIN edbinfo AS a ON a.TRADE_CODE=c.TRADE_CODE
- WHERE a.TRADE_CODE=? `
- o := orm.NewOrmUsingDB("edb")
- err = o.Raw(sql, tradeCode).QueryRow(&count)
- return
- }
- type TargetDeleteReq struct {
- TradeCode string `description:"指标唯一编码"`
- }
- func TargetDelete(tradeCode string) (err error) {
- o := orm.NewOrmUsingDB("edb")
- to, err := o.Begin()
- if err != nil {
- return
- }
- defer func() {
- if err != nil {
- _ = to.Rollback()
- } else {
- _ = to.Commit()
- }
- }()
- sql := " DELETE FROM edbinfo WHERE TRADE_CODE = ? "
- _, err = to.Raw(sql, tradeCode).Exec()
- sql = " DELETE FROM edbdata WHERE TRADE_CODE = ? "
- _, err = to.Raw(sql, tradeCode).Exec()
- return
- }
- type Researcher struct {
- AdminId int `description:"系统用户id"`
- AdminName string `description:"系统用户名称"`
- RealName string `description:"系统用户姓名"`
- Role string `description:"系统用户角色"`
- Mobile string `description:"手机号"`
- TargetCount int `description:"指标数量"`
- }
- type ResearcherListResp struct {
- List []*Researcher
- }
- func GetResearcherEntry() (items []*Researcher, err error) {
- sql := ` SELECT admin_id,admin_name,real_name,mobile,0 as target_count FROM admin WHERE role_type=1 `
- o := orm.NewOrm()
- _, err = o.Raw(sql).QueryRows(&items)
- researchLen := len(items)
- edbO := orm.NewOrmUsingDB("edb")
- for i := 0; i < researchLen; i++ {
- var count int
- mobile := items[i].Mobile
- sqlCount := ` SELECT COUNT(DISTINCT a.TRADE_CODE) AS count FROM edbinfo_user AS a
- INNER JOIN edbinfo AS b ON a.TRADE_CODE=b.TRADE_CODE
- WHERE a.mobile=? AND b.classify_id>0 `
- err = edbO.Raw(sqlCount, mobile).QueryRow(&count)
- items[i].TargetCount = count
- }
- return
- }
- func GetResearcherEntryByMobile(mobile string) (items []*Researcher, err error) {
- sql := ` SELECT admin_id,admin_name,real_name,mobile,0 as target_count FROM admin WHERE role_type=1 `
- if mobile != "" {
- sql += ` AND mobile IN(` + mobile + `)`
- }
- o := orm.NewOrm()
- _, err = o.Raw(sql).QueryRows(&items)
- researchLen := len(items)
- edbO := orm.NewOrmUsingDB("edb")
- for i := 0; i < researchLen; i++ {
- var count int
- mobile := items[i].Mobile
- sqlCount := ` SELECT COUNT(DISTINCT a.TRADE_CODE) AS count FROM edbinfo_user AS a
- INNER JOIN edbinfo AS b ON a.TRADE_CODE=b.TRADE_CODE
- WHERE a.mobile=? AND b.classify_id>0 `
- err = edbO.Raw(sqlCount, mobile).QueryRow(&count)
- items[i].TargetCount = count
- }
- return
- }
- type EdbinfoItems struct {
- TradeCode string `orm:"column(TRADE_CODE);pk" description:"指标code"`
- SecName string `orm:"column(SEC_NAME);" description:"指标名称"`
- Unit string `orm:"column(UNIT);" description:"单位"`
- Remark string `orm:"column(REMARK);" description:"备注"`
- Frequency string `description:"频度"`
- ClassifyId int `description:"分类id"`
- ClassifyName string `description:"分类名称"`
- CreateDate string `description:"创建时间"`
- UserId int `description:"录入用户id"`
- NoticeTime string `description:"通知时间"`
- Mobile string `description:"录入者手机号"`
- ModifyDate string `description:"待更新日期"`
- Status string `description:"状态:未完成/完成"`
- }
- type TargetItemsResp struct {
- List SortEdbInfo
- }
- type SortEdbInfo []EdbinfoItems
- func GetTargetItems(mobile string, classifyId int) (lastItems SortEdbInfo, err error) {
- var items []*EdbinfoItems
- o := orm.NewOrmUsingDB("edb")
- //sql := ` SELECT *,'' modify_date,'' status FROM edbinfo AS a WHERE a.classify_id>0 `
- sql := ` SELECT *,'' modify_date,'' STATUS FROM edbinfo AS a
- WHERE a.classify_id>0
- `
- if classifyId > 0 {
- sql += ` AND a.classify_id=` + strconv.Itoa(classifyId) + ``
- }
- sql += ` GROUP BY a.TRADE_CODE `
- //if classifyId > 0 {
- // sql = ` SELECT *,'' modify_date,'' status FROM edbinfo AS a
- // WHERE a.classify_id=` + strconv.Itoa(classifyId) + ` AND a.classify_id>0
- // GROUP BY a.TRADE_CODE `
- //}
- sql = sql + ` ORDER BY CONVERT(a.SEC_NAME USING gbk ) COLLATE gbk_chinese_ci ASC `
- _, err = o.Raw(sql).QueryRows(&items)
- if err != nil {
- return
- }
- itemsLen := len(items)
- nowWeek := time.Now().Weekday().String()
- fmt.Println(nowWeek)
- finishEdbInfo := SortEdbInfo{}
- unFinishEdbInfo := SortEdbInfo{}
- for i := 0; i < itemsLen; i++ {
- noticeTime := items[i].NoticeTime
- frequency := items[i].Frequency
- tradeCode := items[i].TradeCode
- if noticeTime != "" {
- if frequency == "周度" {
- noticeArr := strings.Split(noticeTime, " ")
- noticeWeek := noticeArr[0]
- fmt.Println(noticeWeek)
- addDay := 0
- if nowWeek == "Sunday" {
- if noticeWeek == "周日" {
- addDay = 0
- } else if noticeWeek == "周一" {
- addDay = 1
- } else if noticeWeek == "周二" {
- addDay = 2
- } else if noticeWeek == "周三" {
- addDay = 3
- } else if noticeWeek == "周四" {
- addDay = 4
- } else if noticeWeek == "周五" {
- addDay = 5
- } else if noticeWeek == "周六" {
- addDay = 6
- } else {
- addDay = 0
- }
- } else if nowWeek == "Monday" {
- if noticeWeek == "周日" {
- addDay = 6
- } else if noticeWeek == "周一" {
- addDay = 0
- } else if noticeWeek == "周二" {
- addDay = 1
- } else if noticeWeek == "周三" {
- addDay = 2
- } else if noticeWeek == "周四" {
- addDay = 3
- } else if noticeWeek == "周五" {
- addDay = 4
- } else if noticeWeek == "周六" {
- addDay = 5
- } else {
- addDay = 0
- }
- } else if nowWeek == "Tuesday" {
- if noticeWeek == "周日" {
- addDay = 5
- } else if noticeWeek == "周一" {
- addDay = 6
- } else if noticeWeek == "周二" {
- addDay = 0
- } else if noticeWeek == "周三" {
- addDay = 1
- } else if noticeWeek == "周四" {
- addDay = 2
- } else if noticeWeek == "周五" {
- addDay = 3
- } else if noticeWeek == "周六" {
- addDay = 4
- } else {
- addDay = 0
- }
- } else if nowWeek == "Wednesday" {
- if noticeWeek == "周日" {
- addDay = 4
- } else if noticeWeek == "周一" {
- addDay = 5
- } else if noticeWeek == "周二" {
- addDay = 6
- } else if noticeWeek == "周三" {
- addDay = 0
- } else if noticeWeek == "周四" {
- addDay = 1
- } else if noticeWeek == "周五" {
- addDay = 2
- } else if noticeWeek == "周六" {
- addDay = 3
- } else {
- addDay = 0
- }
- } else if nowWeek == "Thursday" {
- if noticeWeek == "周日" {
- addDay = 3
- } else if noticeWeek == "周一" {
- addDay = 4
- } else if noticeWeek == "周二" {
- addDay = 5
- } else if noticeWeek == "周三" {
- addDay = 6
- } else if noticeWeek == "周四" {
- addDay = 0
- } else if noticeWeek == "周五" {
- addDay = 1
- } else if noticeWeek == "周六" {
- addDay = 2
- } else {
- addDay = 0
- }
- } else if nowWeek == "Friday" {
- if noticeWeek == "周日" {
- addDay = 2
- } else if noticeWeek == "周一" {
- addDay = 3
- } else if noticeWeek == "周二" {
- addDay = 4
- } else if noticeWeek == "周三" {
- addDay = 5
- } else if noticeWeek == "周四" {
- addDay = 6
- } else if noticeWeek == "周五" {
- addDay = 0
- } else if noticeWeek == "周六" {
- addDay = 1
- } else {
- addDay = 0
- }
- } else if nowWeek == "Saturday" {
- if noticeWeek == "周日" {
- addDay = 1
- } else if noticeWeek == "周一" {
- addDay = 2
- } else if noticeWeek == "周二" {
- addDay = 3
- } else if noticeWeek == "周三" {
- addDay = 4
- } else if noticeWeek == "周四" {
- addDay = 5
- } else if noticeWeek == "周五" {
- addDay = 6
- } else if noticeWeek == "周六" {
- addDay = 0
- } else {
- addDay = 0
- }
- }
- modifyDate := time.Now().AddDate(0, 0, addDay)
- modifyDateStr := modifyDate.Format(utils.FormatDate)
- items[i].ModifyDate = modifyDateStr
- modifyDateEndStr := modifyDate.AddDate(0, 0, -7).Format(utils.FormatDate)
- fmt.Println("addDay:", addDay)
- fmt.Println("modifyDateEndStr:", modifyDateEndStr)
- count := 0
- sqlCount := ` SELECT COUNT(1) AS num FROM edbdata WHERE TRADE_CODE=? AND DT >= ? AND DT <= ? `
- err = o.Raw(sqlCount, tradeCode, modifyDateEndStr, modifyDateStr).QueryRow(&count)
- if err != nil {
- return nil, err
- }
- if count > 0 {
- items[i].Status = "完成"
- finishEdbInfo = append(finishEdbInfo, *items[i])
- } else {
- items[i].Status = "未完成"
- unFinishEdbInfo = append(unFinishEdbInfo, *items[i])
- }
- } else if frequency == "日度" {
- items[i].Status = "完成"
- finishEdbInfo = append(finishEdbInfo, *items[i])
- } else if frequency == "月度" {
- myYear := time.Now().Year()
- myMonth := time.Now().Format("01")
- startDate, endDate := utils.GetMonthStartAndEnd(strconv.Itoa(myYear), myMonth)
- count := 0
- sqlCount := ` SELECT COUNT(1) AS num FROM edbdata WHERE TRADE_CODE=? AND DT >= ? AND DT <= ? `
- err = o.Raw(sqlCount, tradeCode, startDate, endDate).QueryRow(&count)
- if err != nil {
- return nil, err
- }
- if noticeTime != "" {
- var modifyDateStr string
- strArr := strings.Split(noticeTime, "日")
- myYear := time.Now().Year()
- myMonth := time.Now().Format("01")
- modifyDateStr = strconv.Itoa(myYear) + "-" + myMonth + "-" + strArr[0]
- items[i].ModifyDate = modifyDateStr
- }
- if count > 0 {
- items[i].Status = "完成"
- finishEdbInfo = append(finishEdbInfo, *items[i])
- } else {
- items[i].Status = "未完成"
- unFinishEdbInfo = append(unFinishEdbInfo, *items[i])
- }
- } else {
- items[i].Status = "完成"
- finishEdbInfo = append(finishEdbInfo, *items[i])
- }
- } else {
- if frequency == "月度" {
- myYear := time.Now().Year()
- myMonth := time.Now().Format("01")
- startDate, endDate := utils.GetMonthStartAndEnd(strconv.Itoa(myYear), myMonth)
- count := 0
- sqlCount := ` SELECT COUNT(1) AS num FROM edbdata WHERE TRADE_CODE=? AND DT >= ? AND DT <= ? `
- err = o.Raw(sqlCount, tradeCode, startDate, endDate).QueryRow(&count)
- if err != nil {
- return nil, err
- }
- if count > 0 {
- items[i].Status = "完成"
- finishEdbInfo = append(finishEdbInfo, *items[i])
- } else {
- items[i].Status = "未完成"
- unFinishEdbInfo = append(unFinishEdbInfo, *items[i])
- }
- } else {
- items[i].Status = "完成"
- finishEdbInfo = append(finishEdbInfo, *items[i])
- }
- }
- }
- sort.Sort(SortByModifyDate{finishEdbInfo})
- sort.Sort(SortByModifyDate{unFinishEdbInfo})
- lastItems = append(lastItems, unFinishEdbInfo...)
- lastItems = append(lastItems, finishEdbInfo...)
- return
- }
- // 获取此 slice 的长度
- func (p SortEdbInfo) Len() int { return len(p) }
- // 根据元素的状态降序排序
- func (p SortEdbInfo) Less(i, j int) bool {
- return p[i].Status > p[j].Status
- }
- // 交换数据
- func (p SortEdbInfo) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
- // 嵌套结构体 将继承 SortEdbInfo 的所有属性和方法
- // 所以相当于SortByName 也实现了 Len() 和 Swap() 方法
- type SortByStatus struct{ SortEdbInfo }
- // 根据元素的姓名长度降序排序 (此处按照自己的业务逻辑写)
- func (p SortByStatus) Less(i, j int) bool {
- return len(p.SortEdbInfo[i].Status) > len(p.SortEdbInfo[j].Status)
- }
- type SortByModifyDate struct{ SortEdbInfo }
- // 根据元素的年龄降序排序 (此处按照自己的业务逻辑写)
- func (p SortByModifyDate) Less(i, j int) bool {
- return p.SortEdbInfo[i].ModifyDate > p.SortEdbInfo[j].ModifyDate
- }
- type DataCheckResp struct {
- Status int `description:"状态:1:该日期已存在数据,是否确认修改?,0:数据不存在"`
- Close string `description:"值"`
- }
- type TargetCheckResp struct {
- Status int `description:"状态:1:该指标有关联数据,请先删除数据,0:指标不存在关联数据,可直接删除"`
- }
- type EdbdataExportList struct {
- TradeCode string `orm:"column(TRADE_CODE);" description:"指标code"`
- SecName string `orm:"column(SEC_NAME);" description:"指标名称"`
- Unit string `orm:"column(UNIT);" description:"单位"`
- Remark string `orm:"column(REMARK);" description:"备注"`
- Frequency string `description:"频度"`
- ClassifyId int `description:"分类id"`
- ClassifyName string `description:"分类名称"`
- CreateDate string `description:"创建时间"`
- Dt string `orm:"column(Dt);" description:"最新一次录入时间"`
- }
- func GetEdbdataSecName(condition string, pars []interface{}) (items []*EdbdataExportList, err error) {
- //sql := `SELECT a.TRADE_CODE,a.SEC_NAME,a.frequency,a.UNIT,MAX(c.DT) AS Dt
- // FROM edbdata AS c
- // INNER JOIN edbinfo AS a ON a.TRADE_CODE=c.TRADE_CODE
- // INNER JOIN edbinfo_user AS d ON a.TRADE_CODE=d.TRADE_CODE
- // LEFT JOIN edbdata_classify AS b ON a.classify_id=b.classify_id
- // WHERE a.classify_id>0`
- sql := `SELECT a.TRADE_CODE,a.SEC_NAME,a.frequency,a.UNIT,MAX(c.DT) AS Dt,b.classify_name
- FROM edbdata AS c
- INNER JOIN edbinfo AS a ON a.TRADE_CODE=c.TRADE_CODE
- LEFT JOIN edbdata_classify AS b ON a.classify_id=b.classify_id
- WHERE a.classify_id>0`
- if condition != "" {
- sql += condition
- }
- sql += " GROUP BY a.TRADE_CODE ORDER BY a.TRADE_CODE ASC "
- o := orm.NewOrmUsingDB("edb")
- _, err = o.Raw(sql, pars).QueryRows(&items)
- return
- }
- func GetEdbDataFrequency(classifyId int) (items []*string, err error) {
- sql := `SELECT DISTINCT frequency FROM edbinfo where classify_id=? AND frequency IS NOT NULL ORDER BY FIELD(frequency,'日度','周度','月度','季度','半年度','年度') `
- o := orm.NewOrmUsingDB("edb")
- _, err = o.Raw(sql, classifyId).QueryRows(&items)
- return
- }
- // GetEdbDataFrequencyByClassifyIdList
- // @Description: 根据分类列表获取所有的频度
- // @author: Roc
- // @datetime 2024-08-15 17:51:13
- // @param classifyIdList []int
- // @return items []*string
- // @return err error
- func GetEdbDataFrequencyByClassifyIdList(classifyIdList []int) (items []string, err error) {
- num := len(classifyIdList)
- if num <= 0 {
- return
- }
- sql := `SELECT DISTINCT frequency FROM edbinfo where classify_id in (` + utils.GetOrmInReplace(num) + `) AND frequency IS NOT NULL ORDER BY FIELD(frequency,'日度','周度','月度','季度','半年度','年度') `
- o := orm.NewOrmUsingDB("edb")
- _, err = o.Raw(sql, classifyIdList).QueryRows(&items)
- return
- }
- func GetEdbDataFrequencyByKeyord(keyword string) (items []string, err error) {
- sql := `SELECT DISTINCT frequency FROM edbinfo where SEC_NAME=? ORDER BY FIELD(frequency,'日度','周度','月度','季度','半年度','年度') `
- o := orm.NewOrmUsingDB("edb")
- _, err = o.Raw(sql, keyword).QueryRows(&items)
- return
- }
- type EdbdataList struct {
- Dt string `orm:"column(DT);" description:"录入时间"`
- }
- func GetEdbdataList(tradeCode string) (items []*EdbdataList, err error) {
- sql := ` SELECT DT FROM edbdata WHERE TRADE_CODE IN(` + tradeCode + `) GROUP BY DT ORDER BY DT DESC `
- o := orm.NewOrmUsingDB("edb")
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- type EdbdataItem struct {
- TradeCode string `orm:"column(TRADE_CODE);" description:"指标code"`
- Dt string `orm:"column(DT);" description:"最新一次录入时间"`
- Close float64 `orm:"column(CLOSE);" description:"值"`
- }
- func GetEdbdataValueByTradeCode(tradeCode, dt string) (item *EdbdataItem, err error) {
- sql := ` SELECT TRADE_CODE,DT,CLOSE FROM edbdata WHERE TRADE_CODE=? AND DT=? `
- o := orm.NewOrmUsingDB("edb")
- err = o.Raw(sql, tradeCode, dt).QueryRow(&item)
- return
- }
- func GetEdbdataAllByTradeCode(tradeCode string) (items []*EdbdataItem, err error) {
- sql := ` SELECT * FROM edbdata WHERE TRADE_CODE=? `
- o := orm.NewOrmUsingDB("edb")
- _, err = o.Raw(sql, tradeCode).QueryRows(&items)
- return
- }
- func GetEdbdataClassifyByParentId(parentId int) (items []*EdbdataClassify, err error) {
- sql := ` SELECT * FROM edbdata_classify WHERE parent_id=? `
- o := orm.NewOrmUsingDB("edb")
- _, err = o.Raw(sql, parentId).QueryRows(&items)
- return
- }
- type LzPriceClassify struct {
- ProductName string
- }
- func GetLzPriceClassify() (items []*LzPriceClassify, err error) {
- sql := ` SELECT product_name FROM longzhongpriceinfo GROUP BY product_name ORDER BY product_name DESC `
- o := orm.NewOrmUsingDB("edb")
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- type Longzhongpriceinfo struct {
- LongzhongpriceinfoId int `orm:"column(longzhongpriceinfo_id);pk"`
- Standard string
- ModelName string
- Unit string
- AreaName string
- PriceType string
- Memo string
- PriceId string
- ProductName string
- InfoType string
- InfoTypeRemark string
- MarketName string
- ManufactureName string
- }
- func GetLongzhongpriceinfoByClassifyName(productName string) (items []*Longzhongpriceinfo, err error) {
- sql := `SELECT * FROM longzhongpriceinfo WHERE product_name=? ORDER BY longzhongpriceinfo_id ASC `
- o := orm.NewOrmUsingDB("edb")
- _, err = o.Raw(sql, productName).QueryRows(&items)
- return
- }
- func GetLongzhongPriceDataMaxCount(productName string) (count int, err error) {
- o := orm.NewOrmUsingDB("edb")
- sql := `SELECT MAX(t.num) AS count FROM (
- SELECT COUNT(1) AS num FROM longzhongpriceinfo AS a
- INNER JOIN longzhongpricedata AS b ON a.longzhongpriceinfo_id=b.longzhongpriceinfo_id
- WHERE a.product_name=?
- GROUP BY a.product_name
- )AS t `
- err = o.Raw(sql, productName).QueryRow(&count)
- return
- }
- type LongzhongpricedataItems struct {
- LongzhongpricedataId int `orm:"column(longzhongpricedata_id);pk"`
- LongzhongpriceinfoId int
- PriceDate string
- Memo string
- Price float64
- CnyPrice float64
- ZsyPrice float64
- ZshPrice float64
- LowPrice float64
- HighPrice float64
- RisePrice float64
- TonPrice float64
- PriceType string
- UpdateDate string
- }
- func GetLongzhongPriceDataById(lzPriceInfoId int) (items []*LongzhongpricedataItems, err error) {
- o := orm.NewOrmUsingDB("edb")
- sql := ` SELECT DISTINCT a.longzhongpriceinfo_id,a.price_date,a.memo,a.price,a.cny_price,a.zsy_price,a.zsh_price,a.low_price,a.high_price,a.rise_price,a.ton_price,a.price_type,a.update_date
- FROM longzhongpricedata AS a
- WHERE longzhongpriceinfo_id=? ORDER BY price_date DESC `
- _, err = o.Raw(sql, lzPriceInfoId).QueryRows(&items)
- return
- }
- func GetLzSurveyClassify() (items []*LzPriceClassify, err error) {
- sql := ` SELECT breed_name AS product_name FROM longzhong_survey_product GROUP BY breed_name ORDER BY breed_name DESC `
- o := orm.NewOrmUsingDB("edb")
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- type LongzhongSurveyProduct struct {
- SurveyProductId int `orm:"column(survey_product_id);pk"`
- ProjectQuotaId int64
- BreedId string
- BreedName string
- QuotaId string
- QuotaName string
- UnitId string
- UnitName string
- SampleType int64
- SampleId string
- SampleName string
- DeviceId string
- Device string
- ProductCraftId string
- ProductCraft string
- ProductLine string
- InputMode int64
- Frequency int64
- InputValue string
- TaskShouldFinishTime int
- CustomId string
- CustomType int64
- Custom string
- QuotaSampleId int64
- StartDate string
- EndDate string
- LzCode string
- }
- func GetLongzhongSurveyProductByClassifyName(productName string) (items []*LongzhongSurveyProduct, err error) {
- sql := `SELECT * FROM longzhong_survey_product WHERE breed_name=? ORDER BY survey_product_id ASC `
- o := orm.NewOrmUsingDB("edb")
- _, err = o.Raw(sql, productName).QueryRows(&items)
- return
- }
- func GetLzSurveyProductByNameAndFrequency(productName string, frequency int) (items []*LongzhongSurveyProduct, err error) {
- sql := `SELECT * FROM longzhong_survey_product WHERE breed_name=? AND frequency=? ORDER BY survey_product_id ASC `
- o := orm.NewOrmUsingDB("edb")
- _, err = o.Raw(sql, productName, frequency).QueryRows(&items)
- return
- }
- func GetExportLzSurveyProductByBreedIds(breedIds []string) (items []*LongzhongSurveyProduct, err error) {
- if len(breedIds) == 0 {
- return
- }
- field := ` survey_product_id, breed_id, breed_name, sample_name, custom, quota_name, lz_code, frequency, unit_name, end_date, input_value `
- sql := `SELECT ` + field + ` FROM longzhong_survey_product WHERE breed_id IN (` + utils.GetOrmInReplace(len(breedIds)) + `) ORDER BY breed_id ASC, frequency ASC, survey_product_id ASC `
- o := orm.NewOrmUsingDB("edb")
- _, err = o.Raw(sql, breedIds).QueryRows(&items)
- return
- }
- func GetLzFrequency(productName string) (items []*int, err error) {
- sql := `SELECT DISTINCT frequency FROM longzhong_survey_product WHERE breed_name=? ORDER BY frequency`
- o := orm.NewOrmUsingDB("edb")
- _, err = o.Raw(sql, productName).QueryRows(&items)
- return
- }
- // EdbInfoItem
- type EdbInfoItem struct {
- TradeCode string `orm:"column(TRADE_CODE);pk" description:"指标code"`
- SecName string `orm:"column(SEC_NAME);" description:"指标名称"`
- Unit string `orm:"column(UNIT);" description:"单位"`
- Remark string `orm:"column(REMARK);" description:"备注"`
- Frequency string `description:"频度"`
- ClassifyId int `description:"分类id"`
- ClassifyName string `description:"分类名称"`
- CreateDate string `description:"创建时间"`
- UserId int `description:"录入用户id"`
- UserName string `description:"录入用户名称"`
- NoticeTime string `description:"通知时间"`
- Mobile string `description:"录入者手机号"`
- ModifyDate string `description:"待更新日期"`
- ModifyTime string `description:"最近一次更新时间"`
- Status string `description:"状态:未完成/完成"`
- IsJoinEdb int8 `description:"指标库是否已添加:0-否;1-是"`
- StartDate string `description:"数据开始日期"`
- EndDate string `description:"数据结束日期"`
- LatestValue float64 `description:"指标最新值"`
- DataList []*Edbdata `description:"指标数据列表"`
- }
- // GetTargetItemList 获取指标列表数据
- func GetTargetItemList(classifyId, edbShowType int, frequency, keyword, tradeCode string, classifyIdStrList []string) (items []*EdbInfoItem, err error) {
- o := orm.NewOrmUsingDB("edb")
- pars := make([]interface{}, 0)
- sql := ` SELECT a.*,'' modify_date,'' STATUS FROM edbinfo AS a `
- if edbShowType != 0 {
- sql = ` SELECT a.*,b.DT,'' modify_date,'' STATUS FROM edbinfo AS a
- left join edbdata b on a.TRADE_CODE=b.TRADE_CODE `
- }
- sql += ` WHERE a.classify_id>0 `
- //如果没有分类id集合列表,那么就没有数据了,不用往下执行了,直接返回好了
- if len(classifyIdStrList) <= 0 {
- return
- }
- if len(classifyIdStrList) > 0 {
- sql += ` AND a.classify_id in (` + strings.Join(classifyIdStrList, ",") + `) `
- }
- if classifyId > 0 {
- sql += ` AND a.classify_id=` + strconv.Itoa(classifyId) + ` `
- }
- //频度
- if frequency != "" {
- sql += ` AND a.frequency="` + frequency + `" `
- }
- //关键字
- if keyword != "" {
- sql += ` AND (a.SEC_NAME like ? or a.TRADE_CODE like ? )`
- pars = utils.GetLikeKeywordPars(pars, keyword, 2)
- }
- //指定指标
- if tradeCode != "" {
- sql += ` AND a.TRADE_CODE = "` + tradeCode + `" `
- }
- //指标里面是否有数据
- switch edbShowType {
- case 1:
- sql += ` AND b.CLOSE is not null `
- case 2:
- sql += ` AND b.CLOSE is null `
- }
- sql += ` GROUP BY a.TRADE_CODE `
- sql = sql + ` ORDER BY CONVERT(a.SEC_NAME USING gbk ) COLLATE gbk_chinese_ci ASC `
- _, err = o.Raw(sql, pars).QueryRows(&items)
- return
- }
- // GetLzItemList 模糊查询隆众数据库指标列表
- func GetLzItemList(keyword string) (items []*data_manage.LongzhongSurveyProduct, err error) {
- o := orm.NewOrmUsingDB("edb")
- sql := "SELECT * FROM longzhong_survey_product WHERE CONCAT(sample_name,breed_name,custom,quota_name,lz_code) LIKE ?"
- _, err = o.Raw(sql, utils.GetLikeKeyword(keyword)).QueryRows(&items)
- return
- }
- type lzSurveyData struct {
- DataTime string `orm:"column(data_time)" description:"日期"`
- InputValue string `orm:"column(input_value)" description:"值"`
- }
- // GetLzItemListByCode 根据code查询隆众数据列表
- func GetLzItemListByCode(lzCode string) (items []*lzSurveyData, err error) {
- o := orm.NewOrmUsingDB("edb")
- sql := "SELECT * FROM longzhong_survey_data WHERE survey_product_id=? GROUP BY data_time DESC"
- _, err = o.Raw(sql, lzCode).QueryRows(&items)
- return
- }
- // GetEdbDataListByCodes 通过指标ID获取所有数据
- func GetEdbDataListByCodes(tradeCode string) (items []*Edbdata, err error) {
- sql := ` SELECT TRADE_CODE,DT,round(CLOSE,4) CLOSE,modify_time FROM edbdata WHERE TRADE_CODE IN(` + tradeCode + `) GROUP BY TRADE_CODE,DT ORDER BY DT DESC `
- o := orm.NewOrmUsingDB("edb")
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- // TargetItemListResp 指标数据结构体
- type TargetItemListResp struct {
- List []*EdbInfoItem
- FrequencyList []string
- }
- // BatchDataDeleteReq 批量删除某日的指标数据请求结构体
- type BatchDataDeleteReq struct {
- CreateDate string `description:"创建日期"`
- TradeCodeList []string `description:"指标唯一编码列表"`
- }
- // BatchDeleteEdbDataByDate 批量删除某日的指标数据
- func BatchDeleteEdbDataByDate(tradeCodes, dt string, opUserId int) (err error) {
- o := orm.NewOrmUsingDB("edb")
- var list []*Edbdata
- sql := ` select * FROM edbdata WHERE TRADE_CODE in (` + tradeCodes + `) AND DT = ? `
- _, err = o.Raw(sql, dt).QueryRows(&list)
- if err != nil {
- return
- }
- deleteRecordList := make([]*EdbdataDeleteRecord, 0)
- for _, edbDataInfo := range list {
- deleteRecord := &EdbdataDeleteRecord{
- TradeCode: edbDataInfo.TradeCode,
- Dt: edbDataInfo.Dt,
- Close: edbDataInfo.Close,
- ModifyTime: time.Now(),
- CreateTime: time.Now(),
- SysUserId: opUserId,
- }
- deleteRecordList = append(deleteRecordList, deleteRecord)
- }
- if len(deleteRecordList) > 0 {
- _, tmpErr := o.InsertMulti(len(deleteRecordList), deleteRecordList)
- if tmpErr != nil {
- err = tmpErr
- return
- }
- }
- sql = ` DELETE FROM edbdata WHERE TRADE_CODE in (` + tradeCodes + `) AND DT = ? `
- _, err = o.Raw(sql, dt).Exec()
- return
- }
- // BatchDeleteEdbData 批量删除指标数据
- func BatchDeleteEdbData(tradeCode string, opUserId int) (err error) {
- o := orm.NewOrmUsingDB("edb")
- var list []*Edbdata
- sql := ` select * FROM edbdata WHERE TRADE_CODE = ? `
- _, err = o.Raw(sql, tradeCode).QueryRows(&list)
- if err != nil {
- return
- }
- deleteRecordList := make([]*EdbdataDeleteRecord, 0)
- for _, edbDataInfo := range list {
- deleteRecord := &EdbdataDeleteRecord{
- TradeCode: edbDataInfo.TradeCode,
- Dt: edbDataInfo.Dt,
- Close: edbDataInfo.Close,
- ModifyTime: time.Now(),
- CreateTime: time.Now(),
- SysUserId: opUserId,
- }
- deleteRecordList = append(deleteRecordList, deleteRecord)
- }
- _, err = o.InsertMulti(len(deleteRecordList), deleteRecordList)
- if err != nil {
- return
- }
- sql = ` DELETE FROM edbdata WHERE TRADE_CODE = ? `
- _, err = o.Raw(sql, tradeCode).Exec()
- return
- }
- // GetEdbInfoCountByClassifyId 根据指标分类id获取当前分类下的指标数量
- func GetEdbInfoCountByClassifyId(classifyId int) (count int, err error) {
- o := orm.NewOrmUsingDB("edb")
- sql := `SELECT COUNT(1) AS count FROM ( SELECT a.*,b.CLOSE FROM edbinfo AS a
- INNER JOIN edbdata AS b ON a.TRADE_CODE=b.TRADE_CODE
- WHERE a.classify_id=? group by a.TRADE_CODE) d `
- err = o.Raw(sql, classifyId).QueryRow(&count)
- return
- }
- // EdbInfoGroupCount 指标分类id获取当前分类下的指标数量
- type EdbInfoGroupCount struct {
- Count int
- ClassifyId int
- }
- // GetEdbInfoGroupCountByClassifyIds 根据指标分类id获取当前分类下的指标数量
- func GetEdbInfoGroupCountByClassifyIds(classifyIds string) (list []*EdbInfoGroupCount, err error) {
- o := orm.NewOrmUsingDB("edb")
- sql := `SELECT COUNT(1) AS count,classify_id FROM ( SELECT a.*,b.CLOSE FROM edbinfo AS a
- INNER JOIN edbdata AS b ON a.TRADE_CODE=b.TRADE_CODE
- WHERE a.classify_id in (` + classifyIds + `) group by a.TRADE_CODE) d
- GROUP BY classify_id `
- _, err = o.Raw(sql).QueryRows(&list)
- return
- }
- // GetExcelData 获取excel样式数据
- func GetExcelData() (list []*data_manage.ExcelStyle, err error) {
- o := orm.NewOrmUsingDB("edb")
- sql := `SELECT * FROM excel_style `
- _, err = o.Raw(sql).QueryRows(&list)
- return
- }
- // AddExcelData 添加excel样式数据
- func AddExcelData(item *data_manage.ExcelStyle) (id int64, err error) {
- o := orm.NewOrmUsingDB("edb")
- id, err = o.Insert(item)
- return
- }
- type EdbdataFloat struct {
- TradeCode string `orm:"column(TRADE_CODE);pk" description:"指标编码"`
- Dt string `orm:"column(DT)" description:"日期"`
- Close float64 `orm:"column(CLOSE)" description:"值"`
- ModifyTime time.Time `orm:"column(modify_time)" description:"修改时间"`
- }
- func GetTargetsDataFloat(tradeCode, dt string) (item *EdbdataFloat, err error) {
- sql := `SELECT * FROM edbdata WHERE TRADE_CODE=? AND DT=? `
- o := orm.NewOrmUsingDB("edb")
- err = o.Raw(sql, tradeCode, dt).QueryRow(&item)
- return
- }
- func ModifyEdbinfo(tradeCode, unit, frequency string, classifyId int) (err error) {
- sql := `UPDATE edbinfo SET UNIT = ?,frequency=?, classify_id=?, create_date=NOW() WHERE TRADE_CODE=? `
- o := orm.NewOrmUsingDB("edb")
- _, err = o.Raw(sql, unit, frequency, classifyId, tradeCode).Exec()
- return
- }
- func DeleteTargetsDataByImport(tradeCode, dt string) (err error) {
- sql := `DELETE FROM edbdata WHERE TRADE_CODE=? AND DT=? `
- o := orm.NewOrmUsingDB("edb")
- _, err = o.Raw(sql, tradeCode, dt).Exec()
- return
- }
- // GetEdbinfoListByCodeListGroupByUserId 根据指标code列表、用户分组获取指标信息
- func GetEdbinfoListByCodeListGroupByUserId(edbCodeList []string) (items []*Edbinfo, err error) {
- num := len(edbCodeList)
- if num <= 0 {
- return
- }
- o := orm.NewOrmUsingDB("edb")
- sql := `SELECT * FROM edbinfo WHERE TRADE_CODE in (` + utils.GetOrmInReplace(num) + `) GROUP BY user_id `
- _, err = o.Raw(sql, edbCodeList).QueryRows(&items)
- return
- }
- // GetEdbinfoListByCodeListByCodeIdList
- // @Description: 根据指标code列表获取列表信息
- // @param edbCodeList
- // @return items
- // @return err
- func GetEdbinfoListByCodeListByCodeIdList(edbCodeList []string) (items []*Edbinfo, err error) {
- num := len(edbCodeList)
- if num <= 0 {
- return
- }
- o := orm.NewOrmUsingDB("edb")
- sql := `SELECT * FROM edbinfo WHERE TRADE_CODE in (` + utils.GetOrmInReplace(num) + `) `
- _, err = o.Raw(sql, edbCodeList).QueryRows(&items)
- return
- }
- // GetEdbinfoListByCodeListByUserId
- // @Description: 根据用户id列表获取指标列表信息
- // @param userIdList
- // @return items
- // @return err
- func GetEdbinfoListByCodeListByUserId(userIdList []int) (items []*Edbinfo, err error) {
- num := len(userIdList)
- if num <= 0 {
- return
- }
- o := orm.NewOrmUsingDB("edb")
- sql := `SELECT * FROM edbinfo WHERE user_id in (` + utils.GetOrmInReplace(num) + `) `
- _, err = o.Raw(sql, userIdList).QueryRows(&items)
- return
- }
- // ModifyEdbinfoUserIdByCodeList 根据指标code列表修改创建人
- func ModifyEdbinfoUserIdByCodeList(edbCodeList []string, userId int, userName string) (err error) {
- num := len(edbCodeList)
- if num <= 0 {
- return
- }
- o := orm.NewOrmUsingDB("edb")
- sql := `UPDATE edbinfo SET user_id = ?,user_name = ? WHERE TRADE_CODE in (` + utils.GetOrmInReplace(num) + `) `
- _, err = o.Raw(sql, userId, userName, edbCodeList).Exec()
- return
- }
- // ModifyEdbinfoUserIdByOldUserId
- // @Description: 根据旧用户id修改新用户id
- // @author: Roc
- // @datetime 2024-03-25 17:59:32
- // @param oldUserId int
- // @param userId int
- // @return err error
- func ModifyEdbinfoUserIdByOldUserId(oldUserIdList []int, userId int) (err error) {
- num := len(oldUserIdList)
- if num <= 0 {
- return
- }
- o := orm.NewOrmUsingDB("edb")
- sql := `UPDATE edbinfo SET user_id=? WHERE user_id in (` + utils.GetOrmInReplace(num) + `) `
- _, err = o.Raw(sql, userId, oldUserIdList).Exec()
- return
- }
- func GetEdbInfoAdminList() (list []int, err error) {
- sql := `SELECT user_id FROM edbinfo GROUP BY user_id `
- o := orm.NewOrmUsingDB("edb")
- _, err = o.Raw(sql).QueryRows(&list)
- return
- }
- // GetAllChildManualEdbClassify
- // @Description: 获取手工数据中所有的子分类
- // @author: Roc
- // @datetime 2024-07-16 13:27:28
- // @return items []*EdbdataClassify
- // @return err error
- func GetAllChildManualEdbClassify() (items []*EdbdataClassify, err error) {
- o := orm.NewOrmUsingDB("edb")
- sql := ` SELECT classify_id,classify_name,parent_id FROM edbdata_classify WHERE parent_id > 0 `
- _, err = o.Raw(sql).QueryRows(&items)
- return
- }
- // GetChildManualEdbClassifyByIdList
- // @Description: 获取手工数据中所有的子分类
- // @author: Roc
- // @datetime 2024-07-16 13:33:57
- // @param idList []int
- // @return items []*EdbdataClassify
- // @return err error
- func GetChildManualEdbClassifyByIdList(idList []int) (items []*EdbdataClassify, err error) {
- num := len(idList)
- if num <= 0 {
- return
- }
- o := orm.NewOrmUsingDB("edb")
- sql := ` SELECT classify_id,classify_name,parent_id FROM edbdata_classify WHERE classify_id in (` + utils.GetOrmInReplace(num) + `) `
- _, err = o.Raw(sql, idList).QueryRows(&items)
- return
- }
- // EdbinfoMaxMinDate
- // @Description: 手工指标的最小最大日期
- type EdbinfoMaxMinDate struct {
- MinDate string
- MaxDate string
- }
- // GetEdbdataMaxMinDate
- // @Description: 获取手工指标的最小最大日期
- // @author: Roc
- // @datetime 2024-08-01 14:27:20
- // @param tradeCode string
- // @return item EdbinfoMaxMinDate
- // @return err error
- func GetEdbdataMaxMinDate(tradeCode string) (item EdbinfoMaxMinDate, err error) {
- o := orm.NewOrmUsingDB("edb")
- sql := ` SELECT MIN(DT) min_date,MAX(DT) max_date FROM edbdata WHERE TRADE_CODE = ? `
- err = o.Raw(sql, tradeCode).QueryRow(&item)
- return
- }
- // GetEdbdataLatestValue
- // @Description: 获取手工数据的最新值
- // @author: Roc
- // @datetime 2024-08-02 10:33:22
- // @param tradeCode string
- // @return latestValue float64
- // @return err error
- func GetEdbdataLatestValue(tradeCode string) (latestValue float64, err error) {
- o := orm.NewOrmUsingDB("edb")
- sql := ` SELECT CLOSE FROM edbdata WHERE TRADE_CODE = ? ORDER BY DT DESC LIMIT 1`
- err = o.Raw(sql, tradeCode).QueryRow(&latestValue)
- return
- }
- // ModifyEdbinfoMaxMinDate
- // @Description: 修改手工指标的最小最大日期
- // @author: Roc
- // @datetime 2024-08-01 15:33:45
- // @param startDate string
- // @param endDate string
- // @param tradeCode string
- // @return err error
- func ModifyEdbinfoMaxMinDate(tradeCode, startDate, endDate string, latestValue float64) (err error) {
- o := orm.NewOrmUsingDB("edb")
- sql := ` UPDATE edbinfo SET start_date = ?, end_date = ?, latest_value = ? , modify_time = now() WHERE TRADE_CODE = ? `
- _, err = o.Raw(sql, startDate, endDate, latestValue, tradeCode).Exec()
- return
- }
|