target.go 69 KB

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