target.go 69 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798
  1. package models
  2. import (
  3. "eta_gn/eta_api/global"
  4. "eta_gn/eta_api/models/data_manage"
  5. "eta_gn/eta_api/utils"
  6. "fmt"
  7. "sort"
  8. "strconv"
  9. "strings"
  10. "time"
  11. "gorm.io/gorm"
  12. "github.com/rdlucklib/rdluck_tools/paging"
  13. )
  14. type DataList struct {
  15. TradeCode string `gorm:"column:TRADE_CODE;type:varchar(255);not null" description:"指标编码"`
  16. SecName string `gorm:"column:SEC_NAME;type:varchar(255);not null" description:"指标名称"`
  17. Unit string `gorm:"column:UNIT;type:varchar(255);not null" description:"单位"`
  18. Remark string `gorm:"column:REMARK;type:varchar(255);not null" description:"备注"`
  19. Frequency string `gorm:"type:varchar(255);not null" description:"频度"`
  20. ClassifyId int `gorm:"type:int;not null" description:"分类id"`
  21. ClassifyName string `gorm:"type:varchar(255);not null" description:"分类名称"`
  22. Dt string `gorm:"column:DT;type:varchar(255);not null" description:"录入日期"`
  23. Close float64 `gorm:"column:CLOSE;type:float;not null" description:"录入值"`
  24. ModifyTime string `gorm:"type:varchar(255);not null" description:"修改时间"`
  25. }
  26. type DataListResp struct {
  27. List []*DataList
  28. Paging *paging.PagingItem `description:"分页数据"`
  29. }
  30. func GetDataList(condition string, pars []interface{}, startSize, pageSize int) (items []*DataList, err error) {
  31. 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
  32. inner join edbinfo AS a ON a.TRADE_CODE=c.TRADE_CODE
  33. left join edbdata_classify AS b ON a.classify_id=b.classify_id
  34. where a.classify_id>0`
  35. if condition != "" {
  36. sql += condition
  37. }
  38. sql += ` order by c.DT desc limit ?,? `
  39. //o := orm.NewOrmUsingDB("edb")
  40. //_, err = o.Raw(sql, pars...).QueryRows(&items)
  41. pars = append(pars, startSize)
  42. pars = append(pars, pageSize)
  43. err = global.DmSQL["edb"].Raw(sql, pars...).Find(&items).Error
  44. return
  45. }
  46. func GetDataListCount(condition string, pars []interface{}) (count int, err error) {
  47. sql := ` select count(1) as count FROM edbdata AS c
  48. inner join edbinfo AS a ON a.TRADE_CODE=c.TRADE_CODE
  49. left join edbdata_classify AS b ON a.classify_id=b.classify_id
  50. where a.classify_id>0 `
  51. if condition != "" {
  52. sql += condition
  53. }
  54. //o := orm.NewOrmUsingDB("edb")
  55. //err = o.Raw(sql, pars).QueryRow(&count)
  56. err = global.DmSQL["edb"].Raw(sql, pars...).Scan(&count).Error
  57. return
  58. }
  59. type DataAddReq struct {
  60. TradeCode string `description:"指标唯一编码"`
  61. CreateDate string `description:"创建日期"`
  62. Close string `description:"录入值"`
  63. }
  64. type Edbdata struct {
  65. TradeCode string `gorm:"column:TRADE_CODE;primaryKey;type:varchar(255)" orm:"column(TRADE_CODE);pk" gorm:"primaryKey" description:"指标编码"`
  66. Dt string `gorm:"column:DT;type:varchar(255)" orm:"column(DT)" description:"日期"`
  67. Close string `gorm:"column:CLOSE;type:varchar(255)" orm:"column(CLOSE)" description:"值"`
  68. ModifyTime time.Time `gorm:"column:modify_time;type:timestamp" orm:"column(modify_time)" description:"修改时间"`
  69. }
  70. func GetDataInfo(tradeCode, creteDate string) (item *Edbdata, err error) {
  71. sql := " SELECT * FROM edbdata WHERE TRADE_CODE=? AND DT=? "
  72. //o := orm.NewOrmUsingDB("edb")
  73. //err = o.Raw(sql, tradeCode, creteDate).QueryRow(&item)
  74. err = global.DmSQL["edb"].Raw(sql, tradeCode, creteDate).First(&item).Error
  75. return
  76. }
  77. func AddEdbdata(item *Edbdata) (lastId int64, err error) {
  78. //o := orm.NewOrmUsingDB("edb")
  79. //lastId, err = o.Insert(item)
  80. err = global.DmSQL["edb"].Create(item).Error
  81. if err != nil {
  82. return
  83. }
  84. return
  85. }
  86. type DataEditReq struct {
  87. TradeCode string `description:"指标唯一编码"`
  88. CreateDate string `description:"创建日期"`
  89. Close interface{} `description:"录入值"`
  90. OldCreateDate string `description:"旧的录入日期"`
  91. }
  92. // BatchDataEditReq 批量修改指标
  93. type BatchDataEditReq struct {
  94. OldCreateDate string `description:"旧的录入日期"`
  95. CreateDate string `description:"新的录入日期"`
  96. List []DataEditReq `description:"需要修改的数据"`
  97. }
  98. // 编辑数据
  99. func EditEdbdata(item *Edbdata) (err error) {
  100. //o := orm.NewOrmUsingDB("edb")
  101. sql := ` UPDATE edbdata SET CLOSE = ?,modify_time=NOW() WHERE TRADE_CODE = ? AND DT = ? `
  102. //_, err = o.Raw(sql, item.Close, item.TradeCode, item.Dt).Exec()
  103. err = global.DmSQL["edb"].Exec(sql, item.Close, item.TradeCode, item.Dt).Error
  104. return
  105. }
  106. type EdbdataDeleteRecord struct {
  107. Id int `gorm:"primaryKey" `
  108. TradeCode string `orm:"column(TRADE_CODE)" description:"指标编码"`
  109. Dt string `orm:"column(DT)" description:"日期"`
  110. Close string `orm:"column(CLOSE)" description:"值"`
  111. ModifyTime time.Time `orm:"column(modify_time)" description:"修改时间"`
  112. CreateTime time.Time
  113. SysUserId int
  114. }
  115. func AddEdbdataDeleteRecord(item *EdbdataDeleteRecord) (lastId int64, err error) {
  116. //o := orm.NewOrmUsingDB("edb")
  117. //lastId, err = o.Insert(item)
  118. err = global.DmSQL["edb"].Create(item).Error
  119. lastId = int64(item.Id)
  120. return
  121. }
  122. // DeleteEdbData 根据指标code和日期删除数据
  123. func DeleteEdbData(tradeCode, dt string) (err error) {
  124. //o := orm.NewOrmUsingDB("edb")
  125. sql := ` DELETE FROM edbdata WHERE TRADE_CODE = ? AND DT = ? `
  126. //_, err = o.Raw(sql, tradeCode, dt).Exec()
  127. err = global.DmSQL["edb"].Exec(sql, tradeCode, dt).Error
  128. return
  129. }
  130. // DeleteAllEdbData 根据指标code删除数据
  131. func DeleteAllEdbData(tradeCode string) (err error) {
  132. //o := orm.NewOrmUsingDB("edb")
  133. sql := ` DELETE FROM edbdata WHERE TRADE_CODE = ? `
  134. //_, err = o.Raw(sql, tradeCode).Exec()
  135. err = global.DmSQL["edb"].Exec(sql, tradeCode).Error
  136. return
  137. }
  138. type Edbinfo struct {
  139. TradeCode string `gorm:"column:TRADE_CODE;primaryKey;type:varchar(255)" orm:"column(TRADE_CODE);pk" gorm:"primaryKey" description:"指标code"`
  140. SecName string `gorm:"column:SEC_NAME;type:varchar(255)" orm:"column(SEC_NAME);" description:"指标名称"`
  141. Unit string `gorm:"column:UNIT;type:varchar(255)" orm:"column(UNIT);" description:"单位"`
  142. Remark string `gorm:"column:REMARK;type:varchar(255)" orm:"column(REMARK);" description:"备注"`
  143. Frequency string `gorm:"column:FREQUENCY;type:varchar(255)" orm:"column(frequency)" description:"频度"`
  144. ClassifyId int `gorm:"column:CLASSIFY_ID;type:int" orm:"column(classify_id)" description:"分类id"`
  145. ClassifyName string `gorm:"-" orm:"-" description:"分类名称"`
  146. CreateDate string `gorm:"column:CREATE_DATE;type:varchar(255)" orm:"column(create_date)" description:"创建时间"`
  147. UserId int `gorm:"column:USER_ID;type:int" orm:"column(user_id)" description:"录入用户id"`
  148. UserName string `gorm:"column:USER_NAME;type:varchar(255)" orm:"column(user_name)" description:"录入用户名称"`
  149. NoticeTime string `gorm:"column:NOTICE_TIME;type:varchar(255)" orm:"column(notice_time)" description:"通知时间"`
  150. Mobile string `gorm:"column:MOBILE;type:varchar(255)" orm:"column(mobile)" description:"录入者手机号"`
  151. Sort int `gorm:"column:SORT;type:int" orm:"column(sort)" description:"排序"`
  152. ModifyTime string `gorm:"column:MODIFY_TIME;type:varchar(255)" description:"最近一次更新时间"`
  153. IsJoinEdb int8 `gorm:"column:IS_JOIN_EDB;type:tinyint" description:"指标库是否已添加:0-否;1-是"`
  154. StartDate string `gorm:"column:START_DATE;type:varchar(255)" description:"数据开始日期"`
  155. EndDate string `gorm:"column:END_DATE;type:varchar(255)" description:"数据结束日期"`
  156. LatestValue float64 `gorm:"column:LATEST_VALUE;type:decimal(10,2)" description:"指标最新值"`
  157. }
  158. func DeleteEdbinfoByTraceCodeList(tradeCodeList []string) (err error) {
  159. if len(tradeCodeList) == 0 {
  160. return
  161. }
  162. //o := orm.NewOrmUsingDB("edb")
  163. o := global.DmSQL["edb"]
  164. //err = o.DoTx(func(ctx context.Context, txOrm orm.TxOrmer) error {
  165. // var holder []string
  166. // for range tradeCodeList {
  167. // holder = append(holder, "?")
  168. // }
  169. // sql := ` DELETE FROM edbdata WHERE TRADE_CODE in (` + strings.Join(holder, ",") + `) `
  170. // _, err := txOrm.Raw(sql, tradeCodeList).Exec()
  171. // if err != nil {
  172. // return err
  173. // }
  174. // sql = ` DELETE FROM edbinfo WHERE TRADE_CODE in (` + strings.Join(holder, ",") + `)`
  175. // _, err = txOrm.Raw(sql, tradeCodeList).Exec()
  176. // if err != nil {
  177. // return err
  178. // }
  179. // return nil
  180. //})
  181. err = o.Transaction(func(tx *gorm.DB) error {
  182. var holder []string
  183. for range tradeCodeList {
  184. holder = append(holder, "?")
  185. }
  186. sql := ` DELETE FROM edbdata WHERE TRADE_CODE in (` + strings.Join(holder, ",") + `) `
  187. txErr := tx.Exec(sql, tradeCodeList).Error
  188. if txErr != nil {
  189. return txErr
  190. }
  191. sql = ` DELETE FROM edbinfo WHERE TRADE_CODE in (` + strings.Join(holder, ",") + `)`
  192. txErr = tx.Exec(sql, tradeCodeList).Error
  193. if txErr != nil {
  194. return txErr
  195. }
  196. return nil
  197. })
  198. return
  199. }
  200. func GetEdbinfoListCount(condition string, pars []interface{}, mobile string, roleType int) (count int, err error) {
  201. //o := orm.NewOrmUsingDB("edb")
  202. sql := ``
  203. if mobile != "" && roleType == 1 {
  204. sql = `SELECT COUNT(1) AS count FROM edbinfo AS a
  205. INNER JOIN edbinfo_user AS c ON a.TRADE_CODE=c.TRADE_CODE AND c.mobile=?
  206. WHERE a.classify_id>0`
  207. if condition != "" {
  208. sql += condition
  209. }
  210. //err = o.Raw(sql, mobile, pars).QueryRow(&count)
  211. err = global.DmSQL["edb"].Raw(sql, utils.ForwardPars(pars, mobile)...).Scan(&count).Error
  212. } else {
  213. sql = `SELECT COUNT(1) AS count FROM edbinfo AS a WHERE a.classify_id>0`
  214. if condition != "" {
  215. sql += condition
  216. }
  217. //err = o.Raw(sql, pars).QueryRow(&count)
  218. err = global.DmSQL["edb"].Raw(sql, pars...).Scan(&count).Error
  219. }
  220. return
  221. }
  222. type EdbinfoItem struct {
  223. TradeCode string `gorm:"column:TRADE_CODE;primaryKey;type:varchar(255)"` //`orm:"column(TRADE_CODE);pk" gorm:"primaryKey" description:"指标code"`
  224. SecName string `gorm:"column:SEC_NAME;type:varchar(255)"` //`orm:"column(SEC_NAME);" description:"指标名称"`
  225. Unit string `gorm:"column:UNIT;type:varchar(255)"` //`orm:"column(UNIT);" description:"单位"`
  226. Remark string `gorm:"column:REMARK;type:varchar(255)"` //`orm:"column(REMARK);" description:"备注"`
  227. Frequency string `gorm:"column:frequency;"` //`description:"频度"`
  228. ClassifyId int `gorm:"column:classify_id;type:int"` //`description:"分类id"`
  229. ClassifyName string `gorm:"-"` // `description:"分类名称"`
  230. CreateDate string `gorm:"column:create_date;"` // `description:"创建时间"`
  231. UserId int `gorm:"column:user_id;"` // `description:"录入用户id"`
  232. UserName string `gorm:"column:user_name;"` // `description:"录入用户名称"`
  233. NoticeTime string `gorm:"column:notice_time;"` //`description:"通知时间"`
  234. Mobile string `gorm:"column:mobile"` // `description:"录入者手机号"`
  235. ModifyTime string `gorm:"column:modify_time;"` //`// `description:"最近一次更新时间"`
  236. StartDate string `gorm:"column:start_date;"` // `description:"数据开始日期"`
  237. EndDate string `gorm:"column:end_date;"` // `description:"数据结束日期"`
  238. LatestValue float64 `gorm:"column:latest_value;"` // `description:"指标最新值"`
  239. }
  240. func GetEdbinfoItemList(condition string, pars []interface{}, startSize, pageSize int, mobile string, roleType int) (items []*EdbinfoItem, err error) {
  241. //o := orm.NewOrmUsingDB("edb")
  242. sql := ``
  243. if mobile != "" && roleType == 1 {
  244. sql = ` SELECT DISTINCT a.*,b.classify_name FROM edbinfo AS a
  245. LEFT JOIN edbdata_classify AS b ON a.classify_id=b.classify_id
  246. INNER JOIN edbinfo_user AS c ON a.TRADE_CODE=c.TRADE_CODE AND c.mobile=?
  247. WHERE a.classify_id>0`
  248. if condition != "" {
  249. sql += condition
  250. }
  251. sql += ` ORDER BY a.create_date DESC LIMIT ?,? `
  252. //_, err = o.Raw(sql, mobile, pars...).QueryRows(&items)
  253. err = global.DmSQL["edb"].Raw(sql, mobile, pars, startSize, pageSize).Find(&items).Error
  254. } else {
  255. sql = `SELECT DISTINCT a.*,b.classify_name FROM edbinfo AS a
  256. LEFT JOIN edbdata_classify AS b on a.classify_id=b.classify_id
  257. WHERE a.classify_id>0`
  258. if condition != "" {
  259. sql += condition
  260. }
  261. sql += ` ORDER BY a.create_date DESC LIMIT ?,? `
  262. //_, err = o.Raw(sql, pars...).QueryRows(&items)
  263. pars = append(pars, startSize, pageSize)
  264. err = global.DmSQL["edb"].Raw(sql, pars...).Find(&items).Error
  265. }
  266. return
  267. }
  268. // EdbParamsInfo 指标数据结构体
  269. type EdbParamsInfo struct {
  270. Unit string `gorm:"column:UNIT;"` //`orm:"column(UNIT);" description:"单位"`
  271. Frequency string `gorm:"column:frequency;"` //`orm:"column(frequency);" description:"单位"`
  272. }
  273. // GetEdbUnitList 获取指标单位
  274. func GetEdbUnitList() (items []*EdbParamsInfo, err error) {
  275. //o := orm.NewOrmUsingDB("edb")
  276. sql := `SELECT UNIT from edbinfo group by UNIT`
  277. //_, err = o.Raw(sql).QueryRows(&items)
  278. err = global.DmSQL["edb"].Raw(sql).Find(&items).Error
  279. return
  280. }
  281. // GetEdbFrequencyList 获取指标频度
  282. func GetEdbFrequencyList(classifyId, userId int) (items []*EdbParamsInfo, err error) {
  283. //o := orm.NewOrmUsingDB("edb")
  284. sql := `SELECT frequency from edbinfo a
  285. join edbdata b on a.TRADE_CODE=b.TRADE_CODE
  286. where classify_id = ? `
  287. if userId > 0 {
  288. sql += ` and a.user_id = ` + fmt.Sprint(userId) + ` `
  289. }
  290. sql += ` group by a.frequency`
  291. //_, err = o.Raw(sql, classifyId).QueryRows(&items)
  292. err = global.DmSQL["edb"].Raw(sql, classifyId).Find(&items).Error
  293. return
  294. }
  295. type TargetListResp struct {
  296. List []*EdbinfoItem
  297. Paging *paging.PagingItem `description:"分页数据"`
  298. }
  299. type EdbinfoAddReq struct {
  300. SecName string `description:"指标名称"`
  301. Unit string `description:"单位"`
  302. Frequency string `description:"频度"`
  303. ClassifyId int `description:"分类id"`
  304. NoticeTime string `description:"通知时间"`
  305. }
  306. // GetMaxTradeCode 获取指标最大trade_code
  307. func GetMaxTradeCode() (max_trade_code string, err error) {
  308. sql := " SELECT MAX(TRADE_CODE) AS max_trade_code FROM edbinfo WHERE LEFT(TRADE_CODE,1)='W' "
  309. //o := orm.NewOrmUsingDB("edb")
  310. //err = o.Raw(sql).QueryRow(&max_trade_code)
  311. err = global.DmSQL["edb"].Raw(sql).Scan(&max_trade_code).Error
  312. if (err != nil && utils.IsErrNoRow(err)) || max_trade_code == `` {
  313. max_trade_code = "W00"
  314. }
  315. return
  316. }
  317. func GetEdbinfoBySecName(secName string) (item *Edbinfo, err error) {
  318. sql := `SELECT * FROM edbinfo WHERE SEC_NAME=? `
  319. //o := orm.NewOrmUsingDB("edb")
  320. //err = o.Raw(sql, secName).QueryRow(&item)
  321. err = global.DmSQL["edb"].Raw(sql, secName).First(&item).Error
  322. return
  323. }
  324. func GetEdbinfoByTradeCode(tradeCode string) (item *Edbinfo, err error) {
  325. sql := `SELECT * FROM edbinfo WHERE TRADE_CODE=? `
  326. //o := orm.NewOrmUsingDB("edb")
  327. //err = o.Raw(sql, tradeCode).QueryRow(&item)
  328. err = global.DmSQL["edb"].Raw(sql, tradeCode).First(&item).Error
  329. return
  330. }
  331. func AddEdbinfo(tradeCode, secName, unit, remark, frequency, noticeTime string, classifyId int, userId int, userName string) (err error) {
  332. //o := orm.NewOrmUsingDB("edb")
  333. currTime := time.Now().Format(utils.FormatDateTime)
  334. edbInfo := &Edbinfo{
  335. TradeCode: tradeCode,
  336. SecName: secName,
  337. Unit: unit,
  338. Remark: remark,
  339. Frequency: frequency,
  340. ClassifyId: classifyId,
  341. CreateDate: currTime,
  342. UserId: userId,
  343. UserName: userName,
  344. NoticeTime: noticeTime,
  345. Mobile: "",
  346. ModifyTime: currTime,
  347. IsJoinEdb: 0,
  348. }
  349. //_, err = o.Insert(edbInfo)
  350. err = global.DmSQL["edb"].Create(edbInfo).Error
  351. return
  352. }
  353. func AddEdbinfoUser(tradeCode, mobile string) (err error) {
  354. //o := orm.NewOrmUsingDB("edb")
  355. sql := `INSERT INTO edbinfo_user(TRADE_CODE, mobile) VALUES (?,?)`
  356. //_, err = o.Raw(sql, tradeCode, mobile).Exec()
  357. err = global.DmSQL["edb"].Exec(sql, tradeCode, mobile).Error
  358. return
  359. }
  360. type EdbinfoEditReq struct {
  361. TradeCode string `description:"指标code"`
  362. SecName string `description:"指标名称"`
  363. Unit string `description:"单位"`
  364. Frequency string `description:"频度"`
  365. ClassifyId int `description:"分类id"`
  366. NoticeTime string `description:"通知时间"`
  367. }
  368. func EditEdbinfo(tradeCode, secName, unit, frequency, noticeTime string, classifyId int) (err error) {
  369. sql := `UPDATE edbinfo SET SEC_NAME= ?, UNIT = ?,classify_id=?,frequency=?,notice_time=?,create_date=NOW() WHERE TRADE_CODE=? `
  370. //o := orm.NewOrmUsingDB("edb")
  371. //_, err = o.Raw(sql, secName, unit, classifyId, frequency, noticeTime, tradeCode).Exec()
  372. err = global.DmSQL["edb"].Exec(sql, secName, unit, classifyId, frequency, noticeTime, tradeCode).Error
  373. return
  374. }
  375. func SearchTargetEntry(classifyId int, keyWord string) (items []*Edbinfo, err error) {
  376. where := ""
  377. pars := make([]interface{}, 0)
  378. sql := `SELECT * FROM edbinfo WHERE classify_id>0 AND classify_id=? `
  379. pars = append(pars, classifyId)
  380. if keyWord != "" {
  381. sql += `AND SEC_NAME LIKE ? `
  382. pars = utils.GetLikeKeywordPars(pars, keyWord, 1)
  383. }
  384. sql += where
  385. //o := orm.NewOrmUsingDB("edb")
  386. //_, err = o.Raw(sql, pars...).QueryRows(&items)
  387. err = global.DmSQL["edb"].Raw(sql, pars...).Find(&items).Error
  388. return
  389. }
  390. type SearchTargetListResp struct {
  391. List []*Edbinfo
  392. }
  393. type EdbdataClassify struct {
  394. ClassifyId int `gorm:"column:classify_id;type:int" xorm:"int 'classify_id'"`
  395. ClassifyName string `gorm:"column:classify_name;type:varchar(255)" xorm:"varchar(255) 'classify_name'"`
  396. ParentId int `gorm:"column:parent_id;type:int" xorm:"int 'parent_id'"`
  397. EdbInfoTotal int `gorm:"column:edb_info_total;type:int" xorm:"int 'edb_info_total'"`
  398. TradeCode string `gorm:"column:trade_code;type:varchar(255)" xorm:"varchar(255) 'trade_code'"`
  399. UniqueCode string `gorm:"column:unique_code;type:varchar(255)" xorm:"varchar(255) 'unique_code'"`
  400. }
  401. func GetEdbdataClassifyByClassifyName(classifyName string) (item *EdbdataClassify, err error) {
  402. sql := `SELECT * FROM edbdata_classify WHERE classify_name=? `
  403. //o := orm.NewOrmUsingDB("edb")
  404. //err = o.Raw(sql, classifyName).QueryRow(&item)
  405. err = global.DmSQL["edb"].Raw(sql, classifyName).First(&item).Error
  406. return
  407. }
  408. type EdbdataClassifyList struct {
  409. ClassifyId int
  410. ClassifyName string
  411. ParentId int
  412. Child []*EdbdataClassify `gorm:"-"`
  413. TradeCode string
  414. UniqueCode string
  415. }
  416. func GetEdbdataClassify(userId int64) (items []*EdbdataClassifyList, err error) {
  417. var newItems []*EdbdataClassifyList
  418. //o := orm.NewOrmUsingDB("edb")
  419. sql := ` SELECT classify_id,classify_name,parent_id FROM edbdata_classify WHERE parent_id=0 `
  420. //_, err = o.Raw(sql).QueryRows(&newItems)
  421. err = global.DmSQL["edb"].Raw(sql).Find(&newItems).Error
  422. if err != nil {
  423. return
  424. }
  425. classifyLen := len(newItems)
  426. for i := 0; i < classifyLen; i++ {
  427. var childItems []*EdbdataClassify
  428. parentId := newItems[i].ClassifyId
  429. childSql := ``
  430. if userId > 0 {
  431. userClassifyList, _ := GetManualUserClassify(int(userId))
  432. var userIdArr []string
  433. for _, v := range userClassifyList {
  434. userIdArr = append(userIdArr, strconv.Itoa(v.ClassifyId))
  435. }
  436. userIdStr := strings.Join(userIdArr, ",")
  437. if userIdStr != "" {
  438. 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 "
  439. // _, err = o.Raw(childSql, parentId).QueryRows(&childItems)
  440. err = global.DmSQL["edb"].Raw(childSql, parentId).Find(&childItems).Error
  441. }
  442. } else {
  443. childSql = "SELECT classify_id,classify_name,parent_id FROM edbdata_classify WHERE is_show=1 and parent_id=? ORDER BY create_time ASC "
  444. //_, err = o.Raw(childSql, parentId).QueryRows(&childItems)
  445. err = global.DmSQL["edb"].Raw(childSql, parentId).Find(&childItems).Error
  446. }
  447. if err != nil {
  448. return
  449. }
  450. newItems[i].Child = childItems
  451. }
  452. for _, v := range newItems {
  453. childLen := len(v.Child)
  454. if childLen > 0 {
  455. items = append(items, v)
  456. }
  457. }
  458. return
  459. }
  460. type ManualUserClassify struct {
  461. ManualUserClassifyId int `gorm:"column:manual_user_classify_id"` //`orm:"column(manual_user_classify_id);pk" gorm:"primaryKey" `
  462. AdminId int `gorm:"column:admin_id"`
  463. ClassifyId int `gorm:"column:classify_id"`
  464. CreateTime time.Time `gorm:"column:create_time"`
  465. }
  466. func GetManualUserClassify(sysUserId int) (list []*ManualUserClassify, err error) {
  467. //o := orm.NewOrmUsingDB("data")
  468. sql := `SELECT * FROM manual_user_classify WHERE admin_id=? `
  469. //_, err = o.Raw(sql, sysUserId).QueryRows(&list)
  470. err = global.DmSQL["data"].Raw(sql, sysUserId).Find(&list).Error
  471. return
  472. }
  473. type EdbdataClassifyResp struct {
  474. List []*EdbdataClassifyList
  475. }
  476. func GetTargetBySecName(secName string) (item *Edbinfo, err error) {
  477. sql := `SELECT * FROM edbinfo WHERE SEC_NAME=? `
  478. //o := orm.NewOrmUsingDB("edb")
  479. //err = o.Raw(sql, secName).QueryRow(&item)
  480. err = global.DmSQL["edb"].Raw(sql, secName).First(&item).Error
  481. return
  482. }
  483. // 更新指标数据信息
  484. func (edbinfo *Edbinfo) Update(cols []string) (err error) {
  485. //o := orm.NewOrmUsingDB("edb")
  486. //_, err = o.Update(edbinfo, cols...)
  487. err = global.DmSQL["edb"].Select(cols).Updates(edbinfo).Error
  488. return
  489. }
  490. func ModifyTargetClassifyId(tradeCode string, classifyId int) (err error) {
  491. sql := `UPDATE edbinfo SET classify_id=? WHERE TRADE_CODE=? `
  492. //o := orm.NewOrmUsingDB("edb")
  493. //_, err = o.Raw(sql, classifyId, tradeCode).Exec()
  494. err = global.DmSQL["edb"].Exec(sql, classifyId, tradeCode).Error
  495. return
  496. }
  497. func GetTargetsDataCount(tradeCode, dt string) (count int, err error) {
  498. sql := `SELECT COUNT(1) AS count FROM edbdata WHERE TRADE_CODE=? AND DT=? `
  499. //o := orm.NewOrmUsingDB("edb")
  500. //err = o.Raw(sql, tradeCode, dt).QueryRow(&count)
  501. err = global.DmSQL["edb"].Raw(sql, tradeCode, dt).Scan(&count).Error
  502. return
  503. }
  504. // GetTargetsDataList 根据code获取指标数据列表
  505. func GetTargetsDataList(tradeCode string) (items []*Edbdata, err error) {
  506. //o := orm.NewOrmUsingDB("edb")
  507. sql := `SELECT * FROM edbdata WHERE TRADE_CODE=? ORDER BY DT ASC `
  508. //_, err = o.Raw(sql, tradeCode).QueryRows(&items)
  509. err = global.DmSQL["edb"].Raw(sql, tradeCode).Find(&items).Error
  510. return
  511. }
  512. func GetTargetsData(tradeCode, dt string) (item *Edbdata, err error) {
  513. sql := `SELECT * FROM edbdata WHERE TRADE_CODE=? AND DT=? `
  514. //o := orm.NewOrmUsingDB("edb")
  515. //err = o.Raw(sql, tradeCode, dt).QueryRow(&item)
  516. err = global.DmSQL["edb"].Raw(sql, tradeCode, dt).First(&item).Error
  517. return
  518. }
  519. func ModifyTargetsDataByImport(tradeCode, dt, close string) (err error) {
  520. sql := `UPDATE edbdata SET CLOSE=?,modify_time=NOW() WHERE TRADE_CODE=? AND DT=? `
  521. //o := orm.NewOrmUsingDB("edb")
  522. //_, err = o.Raw(sql, close, tradeCode, dt).Exec()
  523. err = global.DmSQL["edb"].Exec(sql, close, tradeCode, dt).Error
  524. return
  525. }
  526. func AddTargetsDataByImport(tradeCode, dt, close string) (err error) {
  527. sql := `INSERT INTO edbdata(TRADE_CODE, DT,CLOSE, modify_time)VALUES(?,?,?,NOW()) `
  528. //o := orm.NewOrmUsingDB("edb")
  529. //_, err = o.Raw(sql, tradeCode, dt, close).Exec()
  530. err = global.DmSQL["edb"].Exec(sql, tradeCode, dt, close).Error
  531. return
  532. }
  533. type EdbdataImportResp struct {
  534. Status int
  535. Msg string
  536. SuccessCount int
  537. FailCount int
  538. }
  539. func GetFailList(sysUserId int) (items []*EdbdataImportFail, err error) {
  540. //o := orm.NewOrmUsingDB("edb")
  541. sql := ` SELECT * FROM edbdata_import_fail WHERE sys_user_id=? `
  542. //_, err = o.Raw(sql, sysUserId).QueryRows(&items)
  543. err = global.DmSQL["edb"].Raw(sql, sysUserId).Find(&items).Error
  544. return
  545. }
  546. type DataListForExport struct {
  547. TradeCode string `gorm:"column:TRADE_CODE"` //`orm:"column(TRADE_CODE)" description:"指标code"`
  548. SecName string `gorm:"column:SEC_NAME"` //`orm:"column(SEC_NAME)" description:"指标名称"`
  549. Unit string `gorm:"column:UNIT"` //`orm:"column(UNIT)" description:"单位"`
  550. Frequency string `gorm:"column:frequency"` //`description:"频度"`
  551. ClassifyId int `gorm:"column:classify_id"` //`description:"分类id"`
  552. NoticeTime string `gorm:"column:notice_time"` //`description:"通知时间"`
  553. ClassifyName string `gorm:"column:classify_name"`
  554. Dt string `gorm:"column:DT"` //`orm:"column(DT)" description:"日期"`
  555. Close float64 `gorm:"column:CLOSE"` //`orm:"column(CLOSE)" description:"值"`
  556. }
  557. func GetDataListForExport(startDate, endDate, frequency, keyWord string, classifyId int) (items []*DataListForExport, err error) {
  558. where := ``
  559. var pars []interface{}
  560. if keyWord != "" {
  561. where = ` AND SEC_NAME LIKE ? `
  562. pars = utils.GetLikeKeywordPars(pars, keyWord, 1)
  563. }
  564. if startDate != "" {
  565. where += ` AND create_date>=? `
  566. pars = append(pars, startDate)
  567. }
  568. if endDate != "" {
  569. where += ` AND create_date<=? `
  570. pars = append(pars, endDate)
  571. }
  572. if frequency != "" {
  573. where += ` AND frequency=? `
  574. pars = append(pars, frequency)
  575. }
  576. if classifyId > 0 {
  577. where += ` AND classify_id=? `
  578. pars = append(pars, classifyId)
  579. }
  580. 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
  581. INNER JOIN edbinfo AS a ON a.TRADE_CODE=c.TRADE_CODE
  582. LEFT JOIN edbdata_classify AS b ON a.classify_id=b.classify_id
  583. WHERE a.classify_id>0 `
  584. if where != "" {
  585. sql += where
  586. }
  587. sql = sql + " ORDER BY c.DT DESC "
  588. //o := orm.NewOrmUsingDB("edb")
  589. //_, err = o.Raw(sql, pars).QueryRows(&items)
  590. err = global.DmSQL["edb"].Raw(sql, pars...).Find(&items).Error
  591. return
  592. }
  593. type DataDeleteReq struct {
  594. TradeCode string `description:"指标唯一编码"`
  595. CreateDate string `description:"数据录入日期"`
  596. }
  597. func DataDelete(tradeCode, createDate, close string, modifyTime time.Time, sysUserId int) (err error) {
  598. //o := orm.NewOrmUsingDB("edb")
  599. //to, err := o.Begin()
  600. to := global.DmSQL["edb"].Begin()
  601. defer func() {
  602. if err != nil {
  603. _ = to.Rollback()
  604. } else {
  605. _ = to.Commit()
  606. }
  607. }()
  608. recordSql := ` INSERT INTO edbdata_delete_record(TRADE_CODE,DT,CLOSE,modify_time,create_time,sys_user_id)
  609. VALUES(?,?,?,?,?,?)`
  610. //_, err = to.Raw(recordSql, tradeCode, createDate, close, modifyTime, time.Now(), sysUserId).Exec()
  611. err = to.Exec(recordSql, tradeCode, createDate, close, modifyTime, time.Now(), sysUserId).Error
  612. sql := ` DELETE FROM edbdata WHERE TRADE_CODE = ? AND DT = ? `
  613. //_, err = to.Raw(sql, tradeCode, createDate).Exec()
  614. err = to.Exec(sql, tradeCode, createDate).Error
  615. return
  616. }
  617. func GetTargetInfoCount(tradeCode string) (count int, err error) {
  618. sql := ` SELECT COUNT(1) AS count FROM edbdata AS c
  619. INNER JOIN edbinfo AS a ON a.TRADE_CODE=c.TRADE_CODE
  620. WHERE a.TRADE_CODE=? `
  621. //o := orm.NewOrmUsingDB("edb")
  622. //err = o.Raw(sql, tradeCode).QueryRow(&count)
  623. err = global.DmSQL["edb"].Raw(sql, tradeCode).Scan(&count).Error
  624. return
  625. }
  626. type TargetDeleteReq struct {
  627. TradeCode string `description:"指标唯一编码"`
  628. }
  629. func TargetDelete(tradeCode string) (err error) {
  630. //o := orm.NewOrmUsingDB("edb")
  631. //to, err := o.Begin()
  632. to := global.DmSQL["edb"].Begin()
  633. defer func() {
  634. if err != nil {
  635. _ = to.Rollback()
  636. } else {
  637. _ = to.Commit()
  638. }
  639. }()
  640. sql := " DELETE FROM edbinfo WHERE TRADE_CODE = ? "
  641. //_, err = to.Raw(sql, tradeCode).Exec()
  642. err = to.Exec(sql, tradeCode).Error
  643. sql = " DELETE FROM edbdata WHERE TRADE_CODE = ? "
  644. //_, err = to.Raw(sql, tradeCode).Exec()
  645. err = to.Exec(sql, tradeCode).Error
  646. return
  647. }
  648. type Researcher struct {
  649. AdminId int `gorm:"column:admin_id"` //`description:"系统用户id"`
  650. AdminName string `gorm:"column:admin_name"` //`description:"系统用户名称"`
  651. RealName string `gorm:"column:real_name"` //`description:"系统用户姓名"`
  652. Role string `gorm:"column:role"` //`description:"系统用户角色"`
  653. Mobile string `gorm:"column:mobile"` //`description:"手机号"`
  654. TargetCount int `gorm:"column:target_count"` //`description:"指标数量"`
  655. }
  656. type ResearcherListResp struct {
  657. List []*Researcher
  658. }
  659. func GetResearcherEntry() (items []*Researcher, err error) {
  660. sql := ` SELECT admin_id,admin_name,real_name,mobile,0 as target_count FROM admin WHERE role_type=1 `
  661. //o := orm.NewOrm()
  662. //_, err = o.Raw(sql).QueryRows(&items)
  663. err = global.DmSQL["edb"].Raw(sql).Find(&items).Error
  664. researchLen := len(items)
  665. //edbO := orm.NewOrmUsingDB("edb")
  666. for i := 0; i < researchLen; i++ {
  667. var count int
  668. mobile := items[i].Mobile
  669. sqlCount := ` SELECT COUNT(DISTINCT a.TRADE_CODE) AS count FROM edbinfo_user AS a
  670. INNER JOIN edbinfo AS b ON a.TRADE_CODE=b.TRADE_CODE
  671. WHERE a.mobile=? AND b.classify_id>0 `
  672. //err = edbO.Raw(sqlCount, mobile).QueryRow(&count)
  673. err = global.DmSQL["edb"].Raw(sqlCount, mobile).Scan(&count).Error
  674. items[i].TargetCount = count
  675. }
  676. return
  677. }
  678. func GetResearcherEntryByMobile(mobile string) (items []*Researcher, err error) {
  679. sql := ` SELECT admin_id,admin_name,real_name,mobile,0 as target_count FROM admin WHERE role_type=1 `
  680. if mobile != "" {
  681. sql += ` AND mobile IN(` + mobile + `)`
  682. }
  683. //o := orm.NewOrm()
  684. //_, err = o.Raw(sql).QueryRows(&items)
  685. err = global.DmSQL["edb"].Raw(sql).Find(&items).Error
  686. researchLen := len(items)
  687. //edbO := orm.NewOrmUsingDB("edb")
  688. for i := 0; i < researchLen; i++ {
  689. var count int
  690. mobile := items[i].Mobile
  691. sqlCount := ` SELECT COUNT(DISTINCT a.TRADE_CODE) AS count FROM edbinfo_user AS a
  692. INNER JOIN edbinfo AS b ON a.TRADE_CODE=b.TRADE_CODE
  693. WHERE a.mobile=? AND b.classify_id>0 `
  694. //err = edbO.Raw(sqlCount, mobile).QueryRow(&count)
  695. err = global.DmSQL["edb"].Raw(sqlCount, mobile).Scan(&count).Error
  696. items[i].TargetCount = count
  697. }
  698. return
  699. }
  700. type EdbinfoItems struct {
  701. TradeCode string `gorm:"column:TRADE_CODE"` //`orm:"column(TRADE_CODE);pk" gorm:"primaryKey" description:"指标code"`
  702. SecName string `gorm:"column:SEC_NAME"` //`orm:"column(SEC_NAME);" description:"指标名称"`
  703. Unit string `gorm:"column:UNIT"` //`orm:"column(UNIT);" description:"单位"`
  704. Remark string `gorm:"column:REMARK"` //`orm:"column(REMARK);" description:"备注"`
  705. Frequency string `gorm:"column:frequency"` //`description:"频度"`
  706. ClassifyId int `gorm:"column:classify_id"` //`description:"分类id"`
  707. ClassifyName string `gorm:"column:classify_name"` //`description:"分类名称"`
  708. CreateDate string `gorm:"column:create_date"` //`description:"创建时间"`
  709. UserId int `gorm:"column:user_id"` //`description:"录入用户id"`
  710. NoticeTime string `gorm:"column:notice_time"` //`description:"通知时间"`
  711. Mobile string `gorm:"column:mobile"` //`description:"录入者手机号"`
  712. ModifyDate string `gorm:"column:modify_date"` //`description:"待更新日期"`
  713. Status string `gorm:"column:status"` // `description:"状态:未完成/完成"`
  714. }
  715. type TargetItemsResp struct {
  716. List SortEdbInfo
  717. }
  718. type SortEdbInfo []EdbinfoItems
  719. func GetTargetItems(mobile string, classifyId int) (lastItems SortEdbInfo, err error) {
  720. var items []*EdbinfoItems
  721. //o := orm.NewOrmUsingDB("edb")
  722. //sql := ` SELECT *,'' modify_date,'' status FROM edbinfo AS a WHERE a.classify_id>0 `
  723. sql := ` SELECT *,'' modify_date,'' STATUS FROM edbinfo AS a
  724. WHERE a.classify_id>0
  725. `
  726. if classifyId > 0 {
  727. sql += ` AND a.classify_id=` + strconv.Itoa(classifyId) + ``
  728. }
  729. sql += ` GROUP BY a.TRADE_CODE `
  730. //if classifyId > 0 {
  731. // sql = ` SELECT *,'' modify_date,'' status FROM edbinfo AS a
  732. // WHERE a.classify_id=` + strconv.Itoa(classifyId) + ` AND a.classify_id>0
  733. // GROUP BY a.TRADE_CODE `
  734. //}
  735. sql = sql + ` ORDER BY CONVERT(a.SEC_NAME USING gbk ) COLLATE gbk_chinese_ci ASC `
  736. //_, err = o.Raw(sql).QueryRows(&items)
  737. err = global.DmSQL["edb"].Raw(sql).Find(&items).Error
  738. if err != nil {
  739. return
  740. }
  741. itemsLen := len(items)
  742. nowWeek := time.Now().Weekday().String()
  743. fmt.Println(nowWeek)
  744. finishEdbInfo := SortEdbInfo{}
  745. unFinishEdbInfo := SortEdbInfo{}
  746. for i := 0; i < itemsLen; i++ {
  747. noticeTime := items[i].NoticeTime
  748. frequency := items[i].Frequency
  749. tradeCode := items[i].TradeCode
  750. if noticeTime != "" {
  751. if frequency == "周度" {
  752. noticeArr := strings.Split(noticeTime, " ")
  753. noticeWeek := noticeArr[0]
  754. fmt.Println(noticeWeek)
  755. addDay := 0
  756. if nowWeek == "Sunday" {
  757. if noticeWeek == "周日" {
  758. addDay = 0
  759. } else if noticeWeek == "周一" {
  760. addDay = 1
  761. } else if noticeWeek == "周二" {
  762. addDay = 2
  763. } else if noticeWeek == "周三" {
  764. addDay = 3
  765. } else if noticeWeek == "周四" {
  766. addDay = 4
  767. } else if noticeWeek == "周五" {
  768. addDay = 5
  769. } else if noticeWeek == "周六" {
  770. addDay = 6
  771. } else {
  772. addDay = 0
  773. }
  774. } else if nowWeek == "Monday" {
  775. if noticeWeek == "周日" {
  776. addDay = 6
  777. } else if noticeWeek == "周一" {
  778. addDay = 0
  779. } else if noticeWeek == "周二" {
  780. addDay = 1
  781. } else if noticeWeek == "周三" {
  782. addDay = 2
  783. } else if noticeWeek == "周四" {
  784. addDay = 3
  785. } else if noticeWeek == "周五" {
  786. addDay = 4
  787. } else if noticeWeek == "周六" {
  788. addDay = 5
  789. } else {
  790. addDay = 0
  791. }
  792. } else if nowWeek == "Tuesday" {
  793. if noticeWeek == "周日" {
  794. addDay = 5
  795. } else if noticeWeek == "周一" {
  796. addDay = 6
  797. } else if noticeWeek == "周二" {
  798. addDay = 0
  799. } else if noticeWeek == "周三" {
  800. addDay = 1
  801. } else if noticeWeek == "周四" {
  802. addDay = 2
  803. } else if noticeWeek == "周五" {
  804. addDay = 3
  805. } else if noticeWeek == "周六" {
  806. addDay = 4
  807. } else {
  808. addDay = 0
  809. }
  810. } else if nowWeek == "Wednesday" {
  811. if noticeWeek == "周日" {
  812. addDay = 4
  813. } else if noticeWeek == "周一" {
  814. addDay = 5
  815. } else if noticeWeek == "周二" {
  816. addDay = 6
  817. } else if noticeWeek == "周三" {
  818. addDay = 0
  819. } else if noticeWeek == "周四" {
  820. addDay = 1
  821. } else if noticeWeek == "周五" {
  822. addDay = 2
  823. } else if noticeWeek == "周六" {
  824. addDay = 3
  825. } else {
  826. addDay = 0
  827. }
  828. } else if nowWeek == "Thursday" {
  829. if noticeWeek == "周日" {
  830. addDay = 3
  831. } else if noticeWeek == "周一" {
  832. addDay = 4
  833. } else if noticeWeek == "周二" {
  834. addDay = 5
  835. } else if noticeWeek == "周三" {
  836. addDay = 6
  837. } else if noticeWeek == "周四" {
  838. addDay = 0
  839. } else if noticeWeek == "周五" {
  840. addDay = 1
  841. } else if noticeWeek == "周六" {
  842. addDay = 2
  843. } else {
  844. addDay = 0
  845. }
  846. } else if nowWeek == "Friday" {
  847. if noticeWeek == "周日" {
  848. addDay = 2
  849. } else if noticeWeek == "周一" {
  850. addDay = 3
  851. } else if noticeWeek == "周二" {
  852. addDay = 4
  853. } else if noticeWeek == "周三" {
  854. addDay = 5
  855. } else if noticeWeek == "周四" {
  856. addDay = 6
  857. } else if noticeWeek == "周五" {
  858. addDay = 0
  859. } else if noticeWeek == "周六" {
  860. addDay = 1
  861. } else {
  862. addDay = 0
  863. }
  864. } else if nowWeek == "Saturday" {
  865. if noticeWeek == "周日" {
  866. addDay = 1
  867. } else if noticeWeek == "周一" {
  868. addDay = 2
  869. } else if noticeWeek == "周二" {
  870. addDay = 3
  871. } else if noticeWeek == "周三" {
  872. addDay = 4
  873. } else if noticeWeek == "周四" {
  874. addDay = 5
  875. } else if noticeWeek == "周五" {
  876. addDay = 6
  877. } else if noticeWeek == "周六" {
  878. addDay = 0
  879. } else {
  880. addDay = 0
  881. }
  882. }
  883. modifyDate := time.Now().AddDate(0, 0, addDay)
  884. modifyDateStr := modifyDate.Format(utils.FormatDate)
  885. items[i].ModifyDate = modifyDateStr
  886. modifyDateEndStr := modifyDate.AddDate(0, 0, -7).Format(utils.FormatDate)
  887. fmt.Println("addDay:", addDay)
  888. fmt.Println("modifyDateEndStr:", modifyDateEndStr)
  889. count := 0
  890. sqlCount := ` SELECT COUNT(1) AS num FROM edbdata WHERE TRADE_CODE=? AND DT >= ? AND DT <= ? `
  891. //err = o.Raw(sqlCount, tradeCode, modifyDateEndStr, modifyDateStr).QueryRow(&count)
  892. err = global.DmSQL["edb"].Raw(sqlCount, tradeCode, modifyDateEndStr, modifyDateStr).Scan(&count).Error
  893. if err != nil {
  894. return nil, err
  895. }
  896. if count > 0 {
  897. items[i].Status = "完成"
  898. finishEdbInfo = append(finishEdbInfo, *items[i])
  899. } else {
  900. items[i].Status = "未完成"
  901. unFinishEdbInfo = append(unFinishEdbInfo, *items[i])
  902. }
  903. } else if frequency == "日度" {
  904. items[i].Status = "完成"
  905. finishEdbInfo = append(finishEdbInfo, *items[i])
  906. } else if frequency == "月度" {
  907. myYear := time.Now().Year()
  908. myMonth := time.Now().Format("01")
  909. startDate, endDate := utils.GetMonthStartAndEnd(strconv.Itoa(myYear), myMonth)
  910. count := 0
  911. sqlCount := ` SELECT COUNT(1) AS num FROM edbdata WHERE TRADE_CODE=? AND DT >= ? AND DT <= ? `
  912. //err = o.Raw(sqlCount, tradeCode, startDate, endDate).QueryRow(&count)
  913. err = global.DmSQL["edb"].Raw(sqlCount, tradeCode, startDate, endDate).Scan(&count).Error
  914. if err != nil {
  915. return nil, err
  916. }
  917. if noticeTime != "" {
  918. var modifyDateStr string
  919. strArr := strings.Split(noticeTime, "日")
  920. myYear := time.Now().Year()
  921. myMonth := time.Now().Format("01")
  922. modifyDateStr = strconv.Itoa(myYear) + "-" + myMonth + "-" + strArr[0]
  923. items[i].ModifyDate = modifyDateStr
  924. }
  925. if count > 0 {
  926. items[i].Status = "完成"
  927. finishEdbInfo = append(finishEdbInfo, *items[i])
  928. } else {
  929. items[i].Status = "未完成"
  930. unFinishEdbInfo = append(unFinishEdbInfo, *items[i])
  931. }
  932. } else {
  933. items[i].Status = "完成"
  934. finishEdbInfo = append(finishEdbInfo, *items[i])
  935. }
  936. } else {
  937. if frequency == "月度" {
  938. myYear := time.Now().Year()
  939. myMonth := time.Now().Format("01")
  940. startDate, endDate := utils.GetMonthStartAndEnd(strconv.Itoa(myYear), myMonth)
  941. count := 0
  942. sqlCount := ` SELECT COUNT(1) AS num FROM edbdata WHERE TRADE_CODE=? AND DT >= ? AND DT <= ? `
  943. //err = o.Raw(sqlCount, tradeCode, startDate, endDate).QueryRow(&count)
  944. err = global.DmSQL["edb"].Raw(sqlCount, tradeCode, startDate, endDate).Scan(&count).Error
  945. if err != nil {
  946. return nil, err
  947. }
  948. if count > 0 {
  949. items[i].Status = "完成"
  950. finishEdbInfo = append(finishEdbInfo, *items[i])
  951. } else {
  952. items[i].Status = "未完成"
  953. unFinishEdbInfo = append(unFinishEdbInfo, *items[i])
  954. }
  955. } else {
  956. items[i].Status = "完成"
  957. finishEdbInfo = append(finishEdbInfo, *items[i])
  958. }
  959. }
  960. }
  961. sort.Sort(SortByModifyDate{finishEdbInfo})
  962. sort.Sort(SortByModifyDate{unFinishEdbInfo})
  963. lastItems = append(lastItems, unFinishEdbInfo...)
  964. lastItems = append(lastItems, finishEdbInfo...)
  965. return
  966. }
  967. // 获取此 slice 的长度
  968. func (p SortEdbInfo) Len() int { return len(p) }
  969. // 根据元素的状态降序排序
  970. func (p SortEdbInfo) Less(i, j int) bool {
  971. return p[i].Status > p[j].Status
  972. }
  973. // 交换数据
  974. func (p SortEdbInfo) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
  975. // 嵌套结构体 将继承 SortEdbInfo 的所有属性和方法
  976. // 所以相当于SortByName 也实现了 Len() 和 Swap() 方法
  977. type SortByStatus struct{ SortEdbInfo }
  978. // 根据元素的姓名长度降序排序 (此处按照自己的业务逻辑写)
  979. func (p SortByStatus) Less(i, j int) bool {
  980. return len(p.SortEdbInfo[i].Status) > len(p.SortEdbInfo[j].Status)
  981. }
  982. type SortByModifyDate struct{ SortEdbInfo }
  983. // 根据元素的年龄降序排序 (此处按照自己的业务逻辑写)
  984. func (p SortByModifyDate) Less(i, j int) bool {
  985. return p.SortEdbInfo[i].ModifyDate > p.SortEdbInfo[j].ModifyDate
  986. }
  987. type DataCheckResp struct {
  988. Status int `description:"状态:1:该日期已存在数据,是否确认修改?,0:数据不存在"`
  989. Close string `description:"值"`
  990. }
  991. type TargetCheckResp struct {
  992. Status int `description:"状态:1:该指标有关联数据,请先删除数据,0:指标不存在关联数据,可直接删除"`
  993. }
  994. type EdbdataExportList struct {
  995. TradeCode string `gorm:"column:TRADE_CODE;primaryKey;not null" description:"指标code"`
  996. SecName string `gorm:"column:SEC_NAME" description:"指标名称"`
  997. Unit string `gorm:"column:UNIT" description:"单位"`
  998. Remark string `gorm:"column:REMARK" description:"备注"`
  999. Frequency string `gorm:"column:frequency" description:"频度"` //`description:"频度"`
  1000. ClassifyId int `gorm:"column:classify_id" description:"分类id"` //`description:"分类id"`
  1001. ClassifyName string `gorm:"column:classify_name" description:"分类名称"` //`description:"分类名称"`
  1002. CreateDate string `gorm:"column:create_date" description:"创建时间"` //`description:"创建时间"`
  1003. Dt string `gorm:"column:DT" description:"最新一次录入时间"`
  1004. }
  1005. func GetEdbdataSecName(condition string, pars []interface{}) (items []*EdbdataExportList, err error) {
  1006. //sql := `SELECT a.TRADE_CODE,a.SEC_NAME,a.frequency,a.UNIT,MAX(c.DT) AS Dt
  1007. // FROM edbdata AS c
  1008. // INNER JOIN edbinfo AS a ON a.TRADE_CODE=c.TRADE_CODE
  1009. // INNER JOIN edbinfo_user AS d ON a.TRADE_CODE=d.TRADE_CODE
  1010. // LEFT JOIN edbdata_classify AS b ON a.classify_id=b.classify_id
  1011. // WHERE a.classify_id>0`
  1012. sql := `SELECT a.TRADE_CODE,a.SEC_NAME,a.frequency,a.UNIT,MAX(c.DT) AS Dt,b.classify_name
  1013. FROM edbdata AS c
  1014. INNER JOIN edbinfo AS a ON a.TRADE_CODE=c.TRADE_CODE
  1015. LEFT JOIN edbdata_classify AS b ON a.classify_id=b.classify_id
  1016. WHERE a.classify_id>0`
  1017. if condition != "" {
  1018. sql += condition
  1019. }
  1020. sql += " GROUP BY a.TRADE_CODE ORDER BY a.TRADE_CODE ASC "
  1021. //o := orm.NewOrmUsingDB("edb")
  1022. //_, err = o.Raw(sql, pars).QueryRows(&items)
  1023. err = global.DmSQL["edb"].Raw(sql, pars...).Find(&items).Error
  1024. return
  1025. }
  1026. func GetEdbDataFrequency(classifyId int) (items []*string, err error) {
  1027. sql := `SELECT DISTINCT frequency FROM edbinfo where classify_id=? AND frequency IS NOT NULL ORDER BY FIELD(frequency,'日度','周度','月度','季度','半年度','年度') `
  1028. //o := orm.NewOrmUsingDB("edb")
  1029. //_, err = o.Raw(sql, classifyId).QueryRows(&items)
  1030. err = global.DmSQL["edb"].Raw(sql, classifyId).Find(&items).Error
  1031. return
  1032. }
  1033. // GetEdbDataFrequencyByClassifyIdList
  1034. // @Description: 根据分类列表获取所有的频度
  1035. // @author: Roc
  1036. // @datetime 2024-08-15 17:51:13
  1037. // @param classifyIdList []int
  1038. // @return items []*string
  1039. // @return err error
  1040. func GetEdbDataFrequencyByClassifyIdList(classifyIdList []int) (items []string, err error) {
  1041. num := len(classifyIdList)
  1042. if num <= 0 {
  1043. return
  1044. }
  1045. sql := `SELECT DISTINCT frequency FROM edbinfo where classify_id in (` + utils.GetOrmInReplace(num) + `) AND frequency IS NOT NULL ORDER BY FIELD(frequency,'日度','周度','月度','季度','半年度','年度') `
  1046. //o := orm.NewOrmUsingDB("edb")
  1047. //_, err = o.Raw(sql, classifyIdList).QueryRows(&items)
  1048. err = global.DmSQL["edb"].Raw(sql, classifyIdList).Find(&items).Error
  1049. return
  1050. }
  1051. func GetEdbDataFrequencyByKeyord(keyword string) (items []string, err error) {
  1052. sql := `SELECT DISTINCT frequency FROM edbinfo where SEC_NAME=? ORDER BY FIELD(frequency,'日度','周度','月度','季度','半年度','年度') `
  1053. //o := orm.NewOrmUsingDB("edb")
  1054. //_, err = o.Raw(sql, keyword).QueryRows(&items)
  1055. err = global.DmSQL["edb"].Raw(sql, keyword).Find(&items).Error
  1056. return
  1057. }
  1058. type EdbdataList struct {
  1059. Dt string `gorm:"column:DT" description:"录入时间"` //`orm:"column(DT);" description:"录入时间"`
  1060. }
  1061. func GetEdbdataList(tradeCode string) (items []*EdbdataList, err error) {
  1062. sql := ` SELECT DT FROM edbdata WHERE TRADE_CODE IN(` + tradeCode + `) GROUP BY DT ORDER BY DT DESC `
  1063. //o := orm.NewOrmUsingDB("edb")
  1064. //_, err = o.Raw(sql).QueryRows(&items)
  1065. err = global.DmSQL["edb"].Raw(sql).Find(&items).Error
  1066. return
  1067. }
  1068. type EdbdataItem struct {
  1069. TradeCode string `gorm:"column:TRADE_CODE" description:"指标code"` //`orm:"column(TRADE_CODE);" description:"指标code"`
  1070. Dt string `gorm:"column:DT" description:"最新一次录入时间"` // `orm:"column(DT);" description:"最新一次录入时间"`
  1071. Close float64 `gorm:"column:CLOSE" description:"值"` //`orm:"column(CLOSE);" description:"值"`
  1072. }
  1073. func GetEdbdataValueByTradeCode(tradeCode, dt string) (item *EdbdataItem, err error) {
  1074. sql := ` SELECT TRADE_CODE,DT,CLOSE FROM edbdata WHERE TRADE_CODE=? AND DT=? `
  1075. //o := orm.NewOrmUsingDB("edb")
  1076. //err = o.Raw(sql, tradeCode, dt).QueryRow(&item)
  1077. err = global.DmSQL["edb"].Raw(sql, tradeCode, dt).First(&item).Error
  1078. return
  1079. }
  1080. func GetEdbdataAllByTradeCode(tradeCode string) (items []*EdbdataItem, err error) {
  1081. sql := ` SELECT * FROM edbdata WHERE TRADE_CODE=? `
  1082. //o := orm.NewOrmUsingDB("edb")
  1083. //_, err = o.Raw(sql, tradeCode).QueryRows(&items)
  1084. err = global.DmSQL["edb"].Raw(sql, tradeCode).Find(&items).Error
  1085. return
  1086. }
  1087. func GetEdbdataClassifyByParentId(parentId int) (items []*EdbdataClassify, err error) {
  1088. sql := ` SELECT * FROM edbdata_classify WHERE parent_id=? `
  1089. //o := orm.NewOrmUsingDB("edb")
  1090. //_, err = o.Raw(sql, parentId).QueryRows(&items)
  1091. err = global.DmSQL["edb"].Raw(sql, parentId).Find(&items).Error
  1092. return
  1093. }
  1094. type LzPriceClassify struct {
  1095. ProductName string `gorm:"column:product_name" description:"产品名称"`
  1096. }
  1097. func GetLzPriceClassify() (items []*LzPriceClassify, err error) {
  1098. sql := ` SELECT product_name FROM longzhongpriceinfo GROUP BY product_name ORDER BY product_name DESC `
  1099. //o := orm.NewOrmUsingDB("edb")
  1100. //_, err = o.Raw(sql).QueryRows(&items)
  1101. err = global.DmSQL["edb"].Raw(sql).Find(&items).Error
  1102. return
  1103. }
  1104. type Longzhongpriceinfo struct {
  1105. LongzhongpriceinfoId int `gorm:"column:longzhongpriceinfo_id"` //`orm:"column(longzhongpriceinfo_id);pk" gorm:"primaryKey" `
  1106. Standard string `gorm:"column:standard"`
  1107. ModelName string `gorm:"column:model_name"`
  1108. Unit string `gorm:"column:unit"`
  1109. AreaName string `gorm:"column:area_name"`
  1110. PriceType string `gorm:"column:price_type"`
  1111. Memo string `gorm:"column:memo"`
  1112. PriceId string `gorm:"column:price_id"`
  1113. ProductName string `gorm:"column:product_name"`
  1114. InfoType string `gorm:"column:info_type"`
  1115. InfoTypeRemark string `gorm:"column:info_type_remark"`
  1116. MarketName string `gorm:"column:market_name"`
  1117. ManufactureName string `gorm:"column:manufacture_name"`
  1118. }
  1119. func GetLongzhongpriceinfoByClassifyName(productName string) (items []*Longzhongpriceinfo, err error) {
  1120. sql := `SELECT * FROM longzhongpriceinfo WHERE product_name=? ORDER BY longzhongpriceinfo_id ASC `
  1121. //o := orm.NewOrmUsingDB("edb")
  1122. //_, err = o.Raw(sql, productName).QueryRows(&items)
  1123. err = global.DmSQL["edb"].Raw(sql, productName).Find(&items).Error
  1124. return
  1125. }
  1126. func GetLongzhongPriceDataMaxCount(productName string) (count int, err error) {
  1127. //o := orm.NewOrmUsingDB("edb")
  1128. sql := `SELECT COALESCE(MAX(t.num), 0) AS count FROM (
  1129. SELECT COUNT(1) AS num FROM longzhongpriceinfo AS a
  1130. INNER JOIN longzhongpricedata AS b ON a.longzhongpriceinfo_id=b.longzhongpriceinfo_id
  1131. WHERE a.product_name=?
  1132. GROUP BY a.product_name
  1133. )AS t `
  1134. //err = o.Raw(sql, productName).QueryRow(&count)
  1135. err = global.DmSQL["edb"].Raw(sql, productName).Scan(&count).Error
  1136. return
  1137. }
  1138. type LongzhongpricedataItems struct {
  1139. LongzhongpricedataId int `gorm:"column:longzhongpricedata_id"` //`orm:"column(longzhongpricedata_id);pk" gorm:"primaryKey" `
  1140. LongzhongpriceinfoId int `gorm:"column:longzhongpriceinfo_id"`
  1141. PriceDate string `gorm:"column:price_date"`
  1142. Memo string `gorm:"column:memo"`
  1143. Price float64 `gorm:"column:price"`
  1144. CnyPrice float64 `gorm:"column:cny_price"`
  1145. ZsyPrice float64 `gorm:"column:zsy_price"`
  1146. ZshPrice float64 `gorm:"column:zsh_price"`
  1147. LowPrice float64 `gorm:"column:low_price"`
  1148. HighPrice float64 `gorm:"column:high_price"`
  1149. RisePrice float64 `gorm:"column:rise_price"`
  1150. TonPrice float64 `gorm:"column:ton_price"`
  1151. PriceType string `gorm:"column:price_type"`
  1152. UpdateDate string `gorm:"column:update_date"`
  1153. }
  1154. func GetLongzhongPriceDataById(lzPriceInfoId int) (items []*LongzhongpricedataItems, err error) {
  1155. //o := orm.NewOrmUsingDB("edb")
  1156. 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
  1157. FROM longzhongpricedata AS a
  1158. WHERE longzhongpriceinfo_id=? ORDER BY price_date DESC `
  1159. //_, err = o.Raw(sql, lzPriceInfoId).QueryRows(&items)
  1160. err = global.DmSQL["edb"].Raw(sql, lzPriceInfoId).Find(&items).Error
  1161. return
  1162. }
  1163. func GetLzSurveyClassify() (items []*LzPriceClassify, err error) {
  1164. sql := ` SELECT breed_name AS product_name FROM longzhong_survey_product GROUP BY breed_name ORDER BY breed_name DESC `
  1165. //o := orm.NewOrmUsingDB("edb")
  1166. //_, err = o.Raw(sql).QueryRows(&items)
  1167. err = global.DmSQL["edb"].Raw(sql).Find(&items).Error
  1168. return
  1169. }
  1170. // LongzhongSurveyProduct 结构体
  1171. type LongzhongSurveyProduct struct {
  1172. SurveyProductId int `gorm:"column:survey_product_id;primaryKey;autoIncrement:true;not null" description:"调查产品ID"`
  1173. ProjectQuotaId int64 `gorm:"column:project_quota_id" description:"项目配额ID"`
  1174. BreedId string `gorm:"column:breed_id" description:"品种ID"`
  1175. BreedName string `gorm:"column:breed_name" description:"品种名称"`
  1176. QuotaId string `gorm:"column:quota_id" description:"配额ID"`
  1177. QuotaName string `gorm:"column:quota_name" description:"配额名称"`
  1178. UnitId string `gorm:"column:unit_id" description:"单位ID"`
  1179. UnitName string `gorm:"column:unit_name" description:"单位名称"`
  1180. SampleType int64 `gorm:"column:sample_type" description:"样本类型"`
  1181. SampleId string `gorm:"column:sample_id" description:"样本ID"`
  1182. SampleName string `gorm:"column:sample_name" description:"样本名称"`
  1183. DeviceId string `gorm:"column:device_id" description:"设备ID"`
  1184. Device string `gorm:"column:device" description:"设备名称"`
  1185. ProductCraftId string `gorm:"column:product_craft_id" description:"工艺ID"`
  1186. ProductCraft string `gorm:"column:product_craft" description:"工艺名称"`
  1187. ProductLine string `gorm:"column:product_line" description:"生产线"`
  1188. InputMode int64 `gorm:"column:input_mode" description:"输入模式"`
  1189. Frequency int64 `gorm:"column:frequency" description:"频率"`
  1190. InputValue string `gorm:"column:input_value" description:"输入值"`
  1191. TaskShouldFinishTime int `gorm:"column:task_should_finish_time" description:"任务应完成时间"`
  1192. CustomId string `gorm:"column:custom_id" description:"自定义ID"`
  1193. CustomType int64 `gorm:"column:custom_type" description:"自定义类型"`
  1194. Custom string `gorm:"column:custom" description:"自定义名称"`
  1195. QuotaSampleId int64 `gorm:"column:quota_sample_id" description:"配额样本ID"`
  1196. StartDate string `gorm:"column:start_date" description:"开始日期"`
  1197. EndDate string `gorm:"column:end_date" description:"结束日期"`
  1198. LzCode string `gorm:"column:lz_code" description:"龙种代码"`
  1199. }
  1200. func GetLongzhongSurveyProductByClassifyName(productName string) (items []*LongzhongSurveyProduct, err error) {
  1201. sql := `SELECT * FROM longzhong_survey_product WHERE breed_name=? ORDER BY survey_product_id ASC `
  1202. //o := orm.NewOrmUsingDB("edb")
  1203. //_, err = o.Raw(sql, productName).QueryRows(&items)
  1204. err = global.DmSQL["edb"].Raw(sql, productName).Find(&items).Error
  1205. return
  1206. }
  1207. func GetLzSurveyProductByNameAndFrequency(productName string, frequency int) (items []*LongzhongSurveyProduct, err error) {
  1208. sql := `SELECT * FROM longzhong_survey_product WHERE breed_name=? AND frequency=? ORDER BY survey_product_id ASC `
  1209. //o := orm.NewOrmUsingDB("edb")
  1210. //_, err = o.Raw(sql, productName, frequency).QueryRows(&items)
  1211. err = global.DmSQL["edb"].Raw(sql, productName, frequency).Find(&items).Error
  1212. return
  1213. }
  1214. func GetExportLzSurveyProductByBreedIds(breedIds []string) (items []*LongzhongSurveyProduct, err error) {
  1215. if len(breedIds) == 0 {
  1216. return
  1217. }
  1218. field := ` survey_product_id, breed_id, breed_name, sample_name, custom, quota_name, lz_code, frequency, unit_name, end_date, input_value `
  1219. 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 `
  1220. //o := orm.NewOrmUsingDB("edb")
  1221. //_, err = o.Raw(sql, breedIds).QueryRows(&items)
  1222. err = global.DmSQL["edb"].Raw(sql, breedIds).Find(&items).Error
  1223. return
  1224. }
  1225. func GetLzFrequency(productName string) (items []*int, err error) {
  1226. sql := `SELECT DISTINCT frequency FROM longzhong_survey_product WHERE breed_name=? ORDER BY frequency`
  1227. //o := orm.NewOrmUsingDB("edb")
  1228. //_, err = o.Raw(sql, productName).QueryRows(&items)
  1229. err = global.DmSQL["edb"].Raw(sql, productName).Find(&items).Error
  1230. return
  1231. }
  1232. // EdbInfoItem
  1233. type EdbInfoItem struct {
  1234. TradeCode string `gorm:"column:TRADE_CODE;primaryKey;type:varchar(255)" orm:"column(TRADE_CODE);pk" gorm:"primaryKey" description:"指标code"`
  1235. SecName string `gorm:"column:SEC_NAME;type:varchar(255)" orm:"column(SEC_NAME);" description:"指标名称"`
  1236. Unit string `gorm:"column:UNIT;type:varchar(255)" orm:"column(UNIT);" description:"单位"`
  1237. Remark string `gorm:"column:REMARK;type:varchar(255)" orm:"column(REMARK);" description:"备注"`
  1238. Frequency string `gorm:"column:FREQUENCY;type:varchar(255)" description:"频度"`
  1239. ClassifyId int `gorm:"column:CLASSIFY_ID;type:int" description:"分类id"`
  1240. ClassifyName string `gorm:"column:CLASSIFY_NAME;type:varchar(255)" description:"分类名称"`
  1241. CreateDate string `gorm:"column:CREATE_DATE;type:varchar(255)" description:"创建时间"`
  1242. UserId int `gorm:"column:USER_ID;type:int" description:"录入用户id"`
  1243. UserName string `gorm:"column:USER_NAME;type:varchar(255)" description:"录入用户名称"`
  1244. NoticeTime string `gorm:"column:NOTICE_TIME;type:varchar(255)" description:"通知时间"`
  1245. Mobile string `gorm:"column:MOBILE;type:varchar(255)" description:"录入者手机号"`
  1246. ModifyDate string `gorm:"column:MODIFY_DATE;type:varchar(255)" description:"待更新日期"`
  1247. ModifyTime string `gorm:"column:MODIFY_TIME;type:varchar(255)" description:"最近一次更新时间"`
  1248. Status string `gorm:"column:STATUS;type:varchar(255)" description:"状态:未完成/完成"`
  1249. IsJoinEdb int8 `gorm:"column:IS_JOIN_EDB;type:tinyint" description:"指标库是否已添加:0-否;1-是"`
  1250. StartDate string `gorm:"column:START_DATE;type:varchar(255)" description:"数据开始日期"`
  1251. EndDate string `gorm:"column:END_DATE;type:varchar(255)" description:"数据结束日期"`
  1252. LatestValue float64 `gorm:"column:LATEST_VALUE;type:decimal(10,2)" description:"指标最新值"`
  1253. DataList []*Edbdata `gorm:"-" description:"指标数据列表"`
  1254. }
  1255. // GetTargetItemList 获取指标列表数据
  1256. func GetTargetItemList(classifyId, edbShowType int, frequency, keyword, tradeCode string, classifyIdStrList []string) (items []*EdbInfoItem, err error) {
  1257. //o := orm.NewOrmUsingDB("edb")
  1258. pars := make([]interface{}, 0)
  1259. sql := ` SELECT a.*,'' modify_date,'' STATUS FROM edbinfo AS a `
  1260. if edbShowType != 0 {
  1261. sql = ` SELECT a.*,b.DT,'' modify_date,'' STATUS FROM edbinfo AS a
  1262. left join edbdata b on a.TRADE_CODE=b.TRADE_CODE `
  1263. }
  1264. sql += ` WHERE a.classify_id>0 `
  1265. //如果没有分类id集合列表,那么就没有数据了,不用往下执行了,直接返回好了
  1266. if len(classifyIdStrList) <= 0 {
  1267. return
  1268. }
  1269. if len(classifyIdStrList) > 0 {
  1270. sql += ` AND a.classify_id in (` + strings.Join(classifyIdStrList, ",") + `) `
  1271. }
  1272. if classifyId > 0 {
  1273. sql += ` AND a.classify_id=` + strconv.Itoa(classifyId) + ` `
  1274. }
  1275. //频度
  1276. if frequency != "" {
  1277. sql += ` AND a.frequency="` + frequency + `" `
  1278. }
  1279. //关键字
  1280. if keyword != "" {
  1281. sql += ` AND (a.SEC_NAME like ? or a.TRADE_CODE like ? )`
  1282. pars = utils.GetLikeKeywordPars(pars, keyword, 2)
  1283. }
  1284. //指定指标
  1285. if tradeCode != "" {
  1286. sql += ` AND a.TRADE_CODE = "` + tradeCode + `" `
  1287. }
  1288. //指标里面是否有数据
  1289. switch edbShowType {
  1290. case 1:
  1291. sql += ` AND b.CLOSE is not null `
  1292. case 2:
  1293. sql += ` AND b.CLOSE is null `
  1294. }
  1295. sql += ` GROUP BY a.TRADE_CODE `
  1296. sql = sql + ` ORDER BY CONVERT(a.SEC_NAME USING gbk ) COLLATE gbk_chinese_ci ASC `
  1297. //_, err = o.Raw(sql, pars).QueryRows(&items)
  1298. err = global.DmSQL["edb"].Raw(sql, pars...).Find(&items).Error
  1299. return
  1300. }
  1301. // GetLzItemList 模糊查询隆众数据库指标列表
  1302. func GetLzItemList(keyword string) (items []*data_manage.LongzhongSurveyProduct, err error) {
  1303. //o := orm.NewOrmUsingDB("edb")
  1304. sql := "SELECT * FROM longzhong_survey_product WHERE CONCAT(sample_name,breed_name,custom,quota_name,lz_code) LIKE ?"
  1305. //_, err = o.Raw(sql, utils.GetLikeKeyword(keyword)).QueryRows(&items)
  1306. err = global.DmSQL["edb"].Raw(sql, utils.GetLikeKeyword(keyword)).Find(&items).Error
  1307. return
  1308. }
  1309. type lzSurveyData struct {
  1310. DataTime string `gorm:"column:data_time"` //`orm:"column(data_time)" description:"日期"`
  1311. InputValue string `gorm:"column:input_value"` //`orm:"column(input_value)" description:"值"`
  1312. }
  1313. // GetLzItemListByCode 根据code查询隆众数据列表
  1314. func GetLzItemListByCode(lzCode string) (items []*lzSurveyData, err error) {
  1315. //o := orm.NewOrmUsingDB("edb")
  1316. sql := "SELECT * FROM longzhong_survey_data WHERE survey_product_id=? GROUP BY data_time DESC"
  1317. //_, err = o.Raw(sql, lzCode).QueryRows(&items)
  1318. err = global.DmSQL["edb"].Raw(sql, lzCode).Find(&items).Error
  1319. return
  1320. }
  1321. // GetEdbDataListByCodes 通过指标ID获取所有数据
  1322. func GetEdbDataListByCodes(tradeCode string) (items []*Edbdata, err error) {
  1323. 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 `
  1324. //o := orm.NewOrmUsingDB("edb")
  1325. //_, err = o.Raw(sql).QueryRows(&items)
  1326. err = global.DmSQL["edb"].Raw(sql).Find(&items).Error
  1327. return
  1328. }
  1329. // TargetItemListResp 指标数据结构体
  1330. type TargetItemListResp struct {
  1331. List []*EdbInfoItem
  1332. FrequencyList []string
  1333. }
  1334. // BatchDataDeleteReq 批量删除某日的指标数据请求结构体
  1335. type BatchDataDeleteReq struct {
  1336. CreateDate string `description:"创建日期"`
  1337. TradeCodeList []string `description:"指标唯一编码列表"`
  1338. }
  1339. // BatchDeleteEdbDataByDate 批量删除某日的指标数据
  1340. func BatchDeleteEdbDataByDate(tradeCodes, dt string, opUserId int) (err error) {
  1341. //o := orm.NewOrmUsingDB("edb")
  1342. var list []*Edbdata
  1343. sql := ` select * FROM edbdata WHERE TRADE_CODE in (` + tradeCodes + `) AND DT = ? `
  1344. //_, err = o.Raw(sql, dt).QueryRows(&list)
  1345. err = global.DmSQL["edb"].Raw(sql, dt).Find(&list).Error
  1346. if err != nil {
  1347. return
  1348. }
  1349. deleteRecordList := make([]*EdbdataDeleteRecord, 0)
  1350. for _, edbDataInfo := range list {
  1351. deleteRecord := &EdbdataDeleteRecord{
  1352. TradeCode: edbDataInfo.TradeCode,
  1353. Dt: edbDataInfo.Dt,
  1354. Close: edbDataInfo.Close,
  1355. ModifyTime: time.Now(),
  1356. CreateTime: time.Now(),
  1357. SysUserId: opUserId,
  1358. }
  1359. deleteRecordList = append(deleteRecordList, deleteRecord)
  1360. }
  1361. if len(deleteRecordList) > 0 {
  1362. //_, tmpErr := o.InsertMulti(len(deleteRecordList), deleteRecordList)
  1363. tmpErr := global.DmSQL["edb"].CreateInBatches(deleteRecordList, utils.MultiAddNum).Error
  1364. if tmpErr != nil {
  1365. err = tmpErr
  1366. return
  1367. }
  1368. }
  1369. sql = ` DELETE FROM edbdata WHERE TRADE_CODE in (` + tradeCodes + `) AND DT = ? `
  1370. //_, err = o.Raw(sql, dt).Exec()
  1371. err = global.DmSQL["edb"].Exec(sql, dt).Error
  1372. return
  1373. }
  1374. // BatchDeleteEdbData 批量删除指标数据
  1375. func BatchDeleteEdbData(tradeCode string, opUserId int) (err error) {
  1376. //o := orm.NewOrmUsingDB("edb")
  1377. var list []*Edbdata
  1378. sql := ` select * FROM edbdata WHERE TRADE_CODE = ? `
  1379. //_, err = o.Raw(sql, tradeCode).QueryRows(&list)
  1380. err = global.DmSQL["edb"].Raw(sql, tradeCode).Find(&list).Error
  1381. if err != nil {
  1382. return
  1383. }
  1384. deleteRecordList := make([]*EdbdataDeleteRecord, 0)
  1385. for _, edbDataInfo := range list {
  1386. deleteRecord := &EdbdataDeleteRecord{
  1387. TradeCode: edbDataInfo.TradeCode,
  1388. Dt: edbDataInfo.Dt,
  1389. Close: edbDataInfo.Close,
  1390. ModifyTime: time.Now(),
  1391. CreateTime: time.Now(),
  1392. SysUserId: opUserId,
  1393. }
  1394. deleteRecordList = append(deleteRecordList, deleteRecord)
  1395. }
  1396. //_, err = o.InsertMulti(len(deleteRecordList), deleteRecordList)
  1397. err = global.DmSQL["edb"].CreateInBatches(deleteRecordList, utils.MultiAddNum).Error
  1398. if err != nil {
  1399. return
  1400. }
  1401. sql = ` DELETE FROM edbdata WHERE TRADE_CODE = ? `
  1402. //_, err = o.Raw(sql, tradeCode).Exec()
  1403. err = global.DmSQL["edb"].Exec(sql, tradeCode).Error
  1404. return
  1405. }
  1406. // GetEdbInfoCountByClassifyId 根据指标分类id获取当前分类下的指标数量
  1407. func GetEdbInfoCountByClassifyId(classifyId int) (count int, err error) {
  1408. //o := orm.NewOrmUsingDB("edb")
  1409. sql := `SELECT COUNT(1) AS count FROM ( SELECT a.*,b.CLOSE FROM edbinfo AS a
  1410. INNER JOIN edbdata AS b ON a.TRADE_CODE=b.TRADE_CODE
  1411. WHERE a.classify_id=? group by a.TRADE_CODE) d `
  1412. //err = o.Raw(sql, classifyId).QueryRow(&count)
  1413. err = global.DmSQL["edb"].Raw(sql, classifyId).Scan(&count).Error
  1414. return
  1415. }
  1416. // EdbInfoGroupCount 指标分类id获取当前分类下的指标数量
  1417. type EdbInfoGroupCount struct {
  1418. Count int `gorm:"column:count"`
  1419. ClassifyId int `gorm:"column:classify_id"`
  1420. }
  1421. // GetEdbInfoGroupCountByClassifyIds 根据指标分类id获取当前分类下的指标数量
  1422. func GetEdbInfoGroupCountByClassifyIds(classifyIds string) (list []*EdbInfoGroupCount, err error) {
  1423. //o := orm.NewOrmUsingDB("edb")
  1424. sql := `SELECT COUNT(1) AS count,classify_id FROM ( SELECT a.*,b.CLOSE FROM edbinfo AS a
  1425. INNER JOIN edbdata AS b ON a.TRADE_CODE=b.TRADE_CODE
  1426. WHERE a.classify_id in (` + classifyIds + `) group by a.TRADE_CODE) d
  1427. GROUP BY classify_id `
  1428. //_, err = o.Raw(sql).QueryRows(&list)
  1429. err = global.DmSQL["edb"].Raw(sql).Find(&list).Error
  1430. return
  1431. }
  1432. // GetExcelData 获取excel样式数据
  1433. func GetExcelData() (list []*data_manage.ExcelStyle, err error) {
  1434. //o := orm.NewOrmUsingDB("edb")
  1435. sql := `SELECT * FROM excel_style `
  1436. //_, err = o.Raw(sql).QueryRows(&list)
  1437. err = global.DmSQL["edb"].Raw(sql).Find(&list).Error
  1438. return
  1439. }
  1440. // AddExcelData 添加excel样式数据
  1441. func AddExcelData(item *data_manage.ExcelStyle) (id int64, err error) {
  1442. //o := orm.NewOrmUsingDB("edb")
  1443. //id, err = o.Insert(item)
  1444. err = global.DmSQL["edb"].Create(item).Error
  1445. return
  1446. }
  1447. type EdbdataFloat struct {
  1448. TradeCode string `gorm:"column:TRADE_CODE"` //`orm:"column(TRADE_CODE);pk" gorm:"primaryKey" description:"指标编码"`
  1449. Dt string `gorm:"column:DT"` //`orm:"column(DT)" description:"日期"`
  1450. Close float64 `gorm:"column:CLOSE"` //`orm:"column(CLOSE)" description:"值"`
  1451. ModifyTime time.Time `gorm:"column:modify_time"` //`orm:"column(modify_time)" description:"修改时间"`
  1452. }
  1453. func GetTargetsDataFloat(tradeCode, dt string) (item *EdbdataFloat, err error) {
  1454. sql := `SELECT * FROM edbdata WHERE TRADE_CODE=? AND DT=? `
  1455. //o := orm.NewOrmUsingDB("edb")
  1456. //err = o.Raw(sql, tradeCode, dt).QueryRow(&item)
  1457. err = global.DmSQL["edb"].Raw(sql, tradeCode, dt).First(&item).Error
  1458. return
  1459. }
  1460. func ModifyEdbinfo(tradeCode, unit, frequency string, classifyId int) (err error) {
  1461. sql := `UPDATE edbinfo SET UNIT = ?,frequency=?, classify_id=?, create_date=NOW() WHERE TRADE_CODE=? `
  1462. //o := orm.NewOrmUsingDB("edb")
  1463. //_, err = o.Raw(sql, unit, frequency, classifyId, tradeCode).Exec()
  1464. err = global.DmSQL["edb"].Exec(sql, unit, frequency, classifyId, tradeCode).Error
  1465. return
  1466. }
  1467. func DeleteTargetsDataByImport(tradeCode, dt string) (err error) {
  1468. sql := `DELETE FROM edbdata WHERE TRADE_CODE=? AND DT=? `
  1469. //o := orm.NewOrmUsingDB("edb")
  1470. //_, err = o.Raw(sql, tradeCode, dt).Exec()
  1471. err = global.DmSQL["edb"].Exec(sql, tradeCode, dt).Error
  1472. return
  1473. }
  1474. // GetEdbinfoListByCodeListGroupByUserId 根据指标code列表、用户分组获取指标信息
  1475. func GetEdbinfoListByCodeListGroupByUserId(edbCodeList []string) (items []*Edbinfo, err error) {
  1476. num := len(edbCodeList)
  1477. if num <= 0 {
  1478. return
  1479. }
  1480. //o := orm.NewOrmUsingDB("edb")
  1481. sql := `SELECT * FROM edbinfo WHERE TRADE_CODE in (` + utils.GetOrmInReplace(num) + `) GROUP BY user_id `
  1482. //_, err = o.Raw(sql, edbCodeList).QueryRows(&items)
  1483. err = global.DmSQL["edb"].Raw(sql, edbCodeList).Find(&items).Error
  1484. return
  1485. }
  1486. // GetEdbinfoListByCodeListByCodeIdList
  1487. // @Description: 根据指标code列表获取列表信息
  1488. // @param edbCodeList
  1489. // @return items
  1490. // @return err
  1491. func GetEdbinfoListByCodeListByCodeIdList(edbCodeList []string) (items []*Edbinfo, err error) {
  1492. num := len(edbCodeList)
  1493. if num <= 0 {
  1494. return
  1495. }
  1496. //o := orm.NewOrmUsingDB("edb")
  1497. sql := `SELECT * FROM edbinfo WHERE TRADE_CODE in (` + utils.GetOrmInReplace(num) + `) `
  1498. //_, err = o.Raw(sql, edbCodeList).QueryRows(&items)
  1499. err = global.DmSQL["edb"].Raw(sql, edbCodeList).Find(&items).Error
  1500. return
  1501. }
  1502. // GetEdbinfoListByCodeListByUserId
  1503. // @Description: 根据用户id列表获取指标列表信息
  1504. // @param userIdList
  1505. // @return items
  1506. // @return err
  1507. func GetEdbinfoListByCodeListByUserId(userIdList []int) (items []*Edbinfo, err error) {
  1508. num := len(userIdList)
  1509. if num <= 0 {
  1510. return
  1511. }
  1512. //o := orm.NewOrmUsingDB("edb")
  1513. sql := `SELECT * FROM edbinfo WHERE user_id in (` + utils.GetOrmInReplace(num) + `) `
  1514. //_, err = o.Raw(sql, userIdList).QueryRows(&items)
  1515. err = global.DmSQL["edb"].Raw(sql, userIdList).Find(&items).Error
  1516. return
  1517. }
  1518. // ModifyEdbinfoUserIdByCodeList 根据指标code列表修改创建人
  1519. func ModifyEdbinfoUserIdByCodeList(edbCodeList []string, userId int, userName string) (err error) {
  1520. num := len(edbCodeList)
  1521. if num <= 0 {
  1522. return
  1523. }
  1524. //o := orm.NewOrmUsingDB("edb")
  1525. sql := `UPDATE edbinfo SET user_id = ?,user_name = ? WHERE TRADE_CODE in (` + utils.GetOrmInReplace(num) + `) `
  1526. //_, err = o.Raw(sql, userId, userName, edbCodeList).Exec()
  1527. err = global.DmSQL["edb"].Exec(sql, userId, userName, edbCodeList).Error
  1528. return
  1529. }
  1530. // ModifyEdbinfoUserIdByOldUserId
  1531. // @Description: 根据旧用户id修改新用户id
  1532. // @author: Roc
  1533. // @datetime 2024-03-25 17:59:32
  1534. // @param oldUserId int
  1535. // @param userId int
  1536. // @return err error
  1537. func ModifyEdbinfoUserIdByOldUserId(oldUserIdList []int, userId int) (err error) {
  1538. num := len(oldUserIdList)
  1539. if num <= 0 {
  1540. return
  1541. }
  1542. //o := orm.NewOrmUsingDB("edb")
  1543. sql := `UPDATE edbinfo SET user_id=? WHERE user_id in (` + utils.GetOrmInReplace(num) + `) `
  1544. //_, err = o.Raw(sql, userId, oldUserIdList).Exec()
  1545. err = global.DmSQL["edb"].Exec(sql, userId, oldUserIdList).Error
  1546. return
  1547. }
  1548. func GetEdbInfoAdminList() (list []int, err error) {
  1549. sql := `SELECT user_id FROM edbinfo GROUP BY user_id `
  1550. //o := orm.NewOrmUsingDB("edb")
  1551. //_, err = o.Raw(sql).QueryRows(&list)
  1552. err = global.DmSQL["edb"].Raw(sql).Find(&list).Error
  1553. return
  1554. }
  1555. // GetAllChildManualEdbClassify
  1556. // @Description: 获取手工数据中所有的子分类
  1557. // @author: Roc
  1558. // @datetime 2024-07-16 13:27:28
  1559. // @return items []*EdbdataClassify
  1560. // @return err error
  1561. func GetAllChildManualEdbClassify() (items []*EdbdataClassify, err error) {
  1562. //o := orm.NewOrmUsingDB("edb")
  1563. sql := ` SELECT classify_id,classify_name,parent_id FROM edbdata_classify WHERE parent_id > 0 `
  1564. //_, err = o.Raw(sql).QueryRows(&items)
  1565. err = global.DmSQL["edb"].Raw(sql).Find(&items).Error
  1566. return
  1567. }
  1568. // GetChildManualEdbClassifyByIdList
  1569. // @Description: 获取手工数据中所有的子分类
  1570. // @author: Roc
  1571. // @datetime 2024-07-16 13:33:57
  1572. // @param idList []int
  1573. // @return items []*EdbdataClassify
  1574. // @return err error
  1575. func GetChildManualEdbClassifyByIdList(idList []int) (items []*EdbdataClassify, err error) {
  1576. num := len(idList)
  1577. if num <= 0 {
  1578. return
  1579. }
  1580. //o := orm.NewOrmUsingDB("edb")
  1581. sql := ` SELECT classify_id,classify_name,parent_id FROM edbdata_classify WHERE classify_id in (` + utils.GetOrmInReplace(num) + `) `
  1582. //_, err = o.Raw(sql, idList).QueryRows(&items)
  1583. err = global.DmSQL["edb"].Raw(sql, idList).Find(&items).Error
  1584. return
  1585. }
  1586. // EdbinfoMaxMinDate
  1587. // @Description: 手工指标的最小最大日期
  1588. type EdbinfoMaxMinDate struct {
  1589. MinDate string `gorm:"column:min_date"`
  1590. MaxDate string `gorm:"column:max_date"`
  1591. }
  1592. // GetEdbdataMaxMinDate
  1593. // @Description: 获取手工指标的最小最大日期
  1594. // @author: Roc
  1595. // @datetime 2024-08-01 14:27:20
  1596. // @param tradeCode string
  1597. // @return item EdbinfoMaxMinDate
  1598. // @return err error
  1599. func GetEdbdataMaxMinDate(tradeCode string) (item EdbinfoMaxMinDate, err error) {
  1600. //o := orm.NewOrmUsingDB("edb")
  1601. sql := ` SELECT MIN(DT) min_date,MAX(DT) max_date FROM edbdata WHERE TRADE_CODE = ? `
  1602. //err = o.Raw(sql, tradeCode).QueryRow(&item)
  1603. err = global.DmSQL["edb"].Raw(sql, tradeCode).Find(&item).Error
  1604. return
  1605. }
  1606. // GetEdbdataLatestValue
  1607. // @Description: 获取手工数据的最新值
  1608. // @author: Roc
  1609. // @datetime 2024-08-02 10:33:22
  1610. // @param tradeCode string
  1611. // @return latestValue float64
  1612. // @return err error
  1613. func GetEdbdataLatestValue(tradeCode string) (latestValue float64, err error) {
  1614. //o := orm.NewOrmUsingDB("edb")
  1615. sql := ` SELECT CLOSE FROM edbdata WHERE TRADE_CODE = ? ORDER BY DT DESC LIMIT 1`
  1616. //err = o.Raw(sql, tradeCode).QueryRow(&latestValue)
  1617. err = global.DmSQL["edb"].Raw(sql, tradeCode).Scan(&latestValue).Error
  1618. return
  1619. }
  1620. // ModifyEdbinfoMaxMinDate
  1621. // @Description: 修改手工指标的最小最大日期
  1622. // @author: Roc
  1623. // @datetime 2024-08-01 15:33:45
  1624. // @param startDate string
  1625. // @param endDate string
  1626. // @param tradeCode string
  1627. // @return err error
  1628. func ModifyEdbinfoMaxMinDate(tradeCode, startDate, endDate string, latestValue float64) (err error) {
  1629. //o := orm.NewOrmUsingDB("edb")
  1630. sql := ` UPDATE edbinfo SET start_date = ?, end_date = ?, latest_value = ? , modify_time = now() WHERE TRADE_CODE = ? `
  1631. //_, err = o.Raw(sql, startDate, endDate, latestValue, tradeCode).Exec()
  1632. err = global.DmSQL["edb"].Exec(sql, startDate, endDate, latestValue, tradeCode).Error
  1633. return
  1634. }