target.go 59 KB

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