manual_edb.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. package models
  2. import (
  3. "eta_gn/eta_api/global"
  4. "eta_gn/eta_api/utils"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "time"
  7. )
  8. // TargetDetailResp 指标数据结构体
  9. type TargetDetailResp struct {
  10. Detail *EdbInfoItem
  11. ClassifyList []*EdbdataClassify
  12. }
  13. // GetTargetByTradeCode
  14. // @Description: 根据手工指标编码获取指标信息
  15. // @author: Roc
  16. // @datetime 2024-07-16 14:18:10
  17. // @param tradeCode string
  18. // @return item *Edbinfo
  19. // @return err error
  20. func GetTargetByTradeCode(tradeCode string) (item *EdbInfoItem, err error) {
  21. sql := `SELECT * FROM edbinfo WHERE TRADE_CODE = ? `
  22. err = global.DmSQL["edb"].Raw(sql, tradeCode).First(&item).Error
  23. return
  24. }
  25. // GetCountManualUserClassify
  26. // @Description: 根据用户ID和分类ID获取关系数量
  27. // @author: Roc
  28. // @datetime 2024-07-16 14:27:58
  29. // @param sysUserId int
  30. // @param classifyId int
  31. // @return total int
  32. // @return err error
  33. func GetCountManualUserClassify(sysUserId, classifyId int) (total int, err error) {
  34. sql := `SELECT count(1) ct FROM manual_user_classify WHERE admin_id=? AND classify_id = ? `
  35. err = global.DmSQL["data"].Raw(sql, sysUserId, classifyId).Scan(&total).Error
  36. return
  37. }
  38. func GetManualClassifyByClassifyId(classifyId int) (item *EdbdataClassify, err error) {
  39. sql := ` SELECT classify_id,classify_name,parent_id FROM edbdata_classify WHERE classify_id = ? `
  40. err = global.DmSQL["edb"].Raw(sql, classifyId).First(&item).Error
  41. return
  42. }
  43. // GetEdbDataListByCode
  44. // @Description: 通过指标ID获取所有数据
  45. // @author: Roc
  46. // @datetime 2024-07-16 15:32:41
  47. // @param tradeCode string
  48. // @return items []*Edbdata
  49. // @return err error
  50. func GetEdbDataListByCode(tradeCode string) (items []*Edbdata, err error) {
  51. sql := ` SELECT TRADE_CODE,DT,round(CLOSE,4) CLOSE,modify_time FROM edbdata WHERE TRADE_CODE = ? GROUP BY TRADE_CODE,DT ORDER BY DT DESC `
  52. err = global.DmSQL["edb"].Raw(sql, tradeCode).Find(&items).Error
  53. return
  54. }
  55. // EdbInfoListItem
  56. type EdbInfoListItem struct {
  57. TradeCode string `orm:"column(TRADE_CODE);pk" gorm:"primaryKey" description:"指标code"`
  58. SecName string `orm:"column(SEC_NAME);" description:"指标名称"`
  59. Unit string `orm:"column(UNIT);" description:"单位"`
  60. Remark string `orm:"column(REMARK);" description:"备注"`
  61. Frequency string `description:"频度"`
  62. ClassifyId int `description:"分类id"`
  63. ClassifyName string `description:"分类名称"`
  64. CreateDate string `description:"创建时间"`
  65. UserId int `description:"录入用户id"`
  66. NoticeTime string `description:"通知时间"`
  67. Mobile string `description:"录入者手机号"`
  68. ModifyDate string `description:"待更新日期"`
  69. ModifyTime string `description:"数据更新时间"`
  70. Status string `description:"状态:未完成/完成"`
  71. UniqueCode string
  72. IsJoinEdb int8 `description:"指标库是否已添加:0-否;1-是"`
  73. UserName string `description:"录入用户名称"`
  74. StartDate string `description:"数据开始日期"`
  75. EndDate string `description:"数据结束日期"`
  76. LatestValue float64 `description:"指标最新值"`
  77. }
  78. // EdbListResp 指标数据结构体
  79. type EdbListResp struct {
  80. List []*EdbInfoListItem
  81. Paging *paging.PagingItem `description:"分页数据"`
  82. }
  83. // GetEdbInfoList
  84. // @Description: 根据条件获取指标列表
  85. // @author: Roc
  86. // @datetime 2024-07-17 10:34:05
  87. // @param condition string
  88. // @param pars []interface{}
  89. // @return items []*Edbinfo
  90. // @return err error
  91. func GetEdbInfoList(condition string, pars []interface{}, startSize, pageSize int) (items []*EdbInfoListItem, err error) {
  92. sql := `SELECT DISTINCT a.* FROM edbinfo AS a WHERE a.classify_id > 0 `
  93. if condition != "" {
  94. sql += condition
  95. }
  96. sql += ` ORDER BY a.create_date DESC `
  97. if pageSize > 0 {
  98. sql += ` LIMIT ?,? `
  99. pars = append(pars, startSize)
  100. pars = append(pars, pageSize)
  101. }
  102. err = global.DmSQL["edb"].Raw(sql, pars...).Find(&items).Error
  103. return
  104. }
  105. // GetCountEdbInfoList
  106. // @Description: 根据条件获取指标数量
  107. // @author: Roc
  108. // @datetime 2024-07-17 14:51:00
  109. // @param condition string
  110. // @param pars []interface{}
  111. // @return total int
  112. // @return err error
  113. func GetCountEdbInfoList(condition string, pars []interface{}) (total int, err error) {
  114. sql := `SELECT COUNT(1) ct FROM edbinfo AS a WHERE a.classify_id > 0 `
  115. if condition != "" {
  116. sql += condition
  117. }
  118. sql += ` ORDER BY a.create_date DESC `
  119. err = global.DmSQL["edb"].Raw(sql, pars...).Scan(&total).Error
  120. return
  121. }
  122. // OnlyMultiAddEdbdata
  123. // @Description: 批量添加指标数据
  124. // @author: Roc
  125. // @datetime 2024-07-18 16:48:55
  126. // @param items []*Edbdata
  127. // @return err error
  128. func OnlyMultiAddEdbdata(items []*Edbdata) (err error) {
  129. err = global.DmSQL["edb"].CreateInBatches(items, utils.MultiAddNum).Error
  130. return
  131. }
  132. // DelEdbdataByCodeAndDateList
  133. // @Description: 根据指标编码和日期列表批量删除指标的明细数据
  134. // @author: Roc
  135. // @datetime 2024-07-18 16:54:27
  136. // @param tradeCode string
  137. // @param dateList []string
  138. // @return err error
  139. func DelEdbdataByCodeAndDateList(tradeCode string, dateList []string) (err error) {
  140. num := len(dateList)
  141. if num <= 0 {
  142. return
  143. }
  144. sql := `delete from edbdata WHERE TRADE_CODE=? AND DT in (` + utils.GetOrmInReplace(num) + `) `
  145. err = global.DmSQL["edb"].Exec(sql, tradeCode, dateList).Error
  146. return
  147. }
  148. // UpdateManualIsJoinEdbStatus
  149. // @Description: 根据手工数据加入指标的状态
  150. // @author: Roc
  151. // @datetime 2024-07-22 11:29:13
  152. // @param edbCode string
  153. // @param isJoinEdb int 是否加入指标库
  154. // @return err error
  155. func UpdateManualIsJoinEdbStatus(edbCode string, isJoinEdb int8) (err error) {
  156. sql := ` UPDATE edbinfo SET is_join_edb = ? WHERE TRADE_CODE =? `
  157. err = global.DmSQL["edb"].Exec(sql, isJoinEdb, edbCode).Error
  158. return
  159. }
  160. // BatchManualEdbReq 指标数据结构体
  161. type BatchManualEdbReq struct {
  162. //IsJoinEdb int `form:"IsJoinEdb" description:"是否加到指标库,0:未加到指标库"`
  163. FrequencyList []string `description:"频度;枚举值:日度、周度、月度、季度、半年度、年度"`
  164. Keyword string `description:"关键字"`
  165. ClassifyIdList []int `description:"所选品种id列表"`
  166. UserIdList []int `description:"所选用户id列表"`
  167. ListAll bool `form:"ListAll" json:"ListAll" description:"列表全选"`
  168. TradeCodeList []string `form:"TradeCodeList" json:"TradeCodeList" description:"全选为false时, 该数组为选中; 全选为true时, 该数组为不选的指标"`
  169. PageSize int `form:"PageSize" json:"PageSize"`
  170. CurrentIndex int `form:"CurrentIndex" form:"CurrentIndex"`
  171. }
  172. // DelManualIndexByCodeList
  173. // @Description: 根据指标编码列表删除指标
  174. // @author: Roc
  175. // @datetime 2024-07-30 14:10:12
  176. // @param codeList []string
  177. // @return err error
  178. func DelManualIndexByCodeList(codeList []string) (err error) {
  179. num := len(codeList)
  180. if num <= 0 {
  181. return
  182. }
  183. to := global.DmSQL["edb"].Begin()
  184. defer func() {
  185. if err != nil {
  186. _ = to.Rollback()
  187. } else {
  188. _ = to.Commit()
  189. }
  190. }()
  191. // 删除指标
  192. sql := `DELETE FROM edbinfo WHERE TRADE_CODE in (` + utils.GetOrmInReplace(num) + `) `
  193. err = to.Exec(sql, codeList).Error
  194. if err != nil {
  195. }
  196. // 删除指标数据
  197. sql = `DELETE FROM edbdata WHERE TRADE_CODE in (` + utils.GetOrmInReplace(num) + `) `
  198. err = to.Exec(sql, codeList).Error
  199. if err != nil {
  200. }
  201. return
  202. }
  203. // GetEdbinfoListBySecNameList
  204. // @Description: 根据指标名称获取列表数据
  205. // @author: Roc
  206. // @datetime 2024-07-30 19:14:25
  207. // @param secNameList []string
  208. // @return item []*Edbinfo
  209. // @return err error
  210. func GetEdbinfoListBySecNameList(secNameList []string) (items []*Edbinfo, err error) {
  211. num := len(secNameList)
  212. if num <= 0 {
  213. return
  214. }
  215. sql := `SELECT * FROM edbinfo WHERE SEC_NAME in (` + utils.GetOrmInReplace(num) + ` ) AND REMARK='手动' `
  216. err = global.DmSQL["edb"].Raw(sql, secNameList).Find(&items).Error
  217. return
  218. }
  219. // GetTargetsDataListByCodeList
  220. // @Description: 根据code列表获取指标数据列表
  221. // @author: Roc
  222. // @datetime 2024-07-30 19:19:36
  223. // @param tradeCodeList []string
  224. // @return items []*Edbdata
  225. // @return err error
  226. func GetTargetsDataListByCodeList(tradeCodeList []string) (items []*Edbdata, err error) {
  227. num := len(tradeCodeList)
  228. if num <= 0 {
  229. return
  230. }
  231. sql := `SELECT * FROM edbdata WHERE TRADE_CODE in (` + utils.GetOrmInReplace(num) + ` ) ORDER BY DT ASC `
  232. err = global.DmSQL["edb"].Raw(sql, tradeCodeList).Find(&items).Error
  233. return
  234. }
  235. // EdbinfoOpRecord
  236. // @Description: 手工数据的操作日志
  237. type EdbinfoOpRecord struct {
  238. EdbinfoOpRecordId int `gorm:"column:edbinfo_op_record_id;primaryKey;type:int" orm:"column(edbinfo_op_record_id);pk" gorm:"primaryKey" description:"操作记录ID"`
  239. TradeCode string `gorm:"column:TRADE_CODE;type:varchar(255)" orm:"column(TRADE_CODE)" description:"指标编码"`
  240. Remark string `gorm:"column:REMARK;type:varchar(255)" orm:"column(remark)" description:"操作信息"`
  241. UserId int `gorm:"column:USER_ID;type:int" orm:"column(user_id)" description:"用户id"`
  242. UserName string `gorm:"column:USER_NAME;type:varchar(255)" orm:"column(user_name)" description:"用户姓名"`
  243. CreateTime time.Time `gorm:"column:CREATE_TIME;type:datetime" orm:"column(create_time)" description:"创建时间"`
  244. }
  245. // Remark备注:
  246. // 1、创建指标
  247. // 2、编辑指标
  248. // 3、更新数据
  249. // 4、数据资产由<xxx>转移给<xxx>
  250. // Create
  251. // @Description: 添加手工数据的操作日志
  252. // @author: Roc
  253. // @receiver m
  254. // @datetime 2024-07-30 16:25:55
  255. // @return err error
  256. func (m *EdbinfoOpRecord) Create() (err error) {
  257. err = global.DmSQL["edb"].Create(m).Error
  258. return
  259. }
  260. // MulCreate
  261. // @Description: 批量添加手工数据的操作日志
  262. // @author: Roc
  263. // @receiver m
  264. // @datetime 2024-08-01 11:05:02
  265. // @param list []*EdbinfoOpRecord
  266. // @return err error
  267. func (m *EdbinfoOpRecord) MulCreate(list []*EdbinfoOpRecord) (err error) {
  268. err = global.DmSQL["edb"].CreateInBatches(list, utils.MultiAddNum).Error
  269. return
  270. }
  271. // EdbinfoOpRecordItem
  272. // @Description: 手工数据的操作日志
  273. type EdbinfoOpRecordItem struct {
  274. TradeCode string `orm:"column(TRADE_CODE);pk" gorm:"primaryKey" description:"指标编码"`
  275. Remark string `orm:"column(remark)" description:"操作信息"`
  276. UserId int `orm:"column(user_id)" description:"用户id"`
  277. UserName string `orm:"column(user_name)" description:"用户姓名"`
  278. CreateTime string `orm:"column(create_time)" description:"创建时间"`
  279. }
  280. // EdbinfoOpRecordListResp 指标数据结构体
  281. type EdbinfoOpRecordListResp struct {
  282. List []*EdbinfoOpRecordItem
  283. Paging *paging.PagingItem `description:"分页数据"`
  284. }
  285. // GetEdbinfoOpRecordPageList
  286. // @Description: 根据指标编码获取手工数据的操作日志
  287. // @author: Roc
  288. // @datetime 2024-07-30 17:32:33
  289. // @param tradeCode string
  290. // @param startSize int
  291. // @param total int
  292. // @return pageSize int
  293. // @return items []*EdbinfoOpRecordItem
  294. // @return err error
  295. func GetEdbinfoOpRecordPageList(tradeCode string, startSize, pageSize int) (total int, items []*EdbinfoOpRecordItem, err error) {
  296. sql := `SELECT count(1) FROM edbinfo_op_record AS a WHERE TRADE_CODE = ? `
  297. err = global.DmSQL["edb"].Raw(sql, tradeCode).Scan(&total).Error
  298. if err != nil {
  299. return
  300. }
  301. sql = `SELECT a.* FROM edbinfo_op_record AS a WHERE TRADE_CODE = ? ORDER BY a.create_time DESC LIMIT ?,?`
  302. err = global.DmSQL["edb"].Raw(sql, tradeCode, startSize, pageSize).Find(&items).Error
  303. return
  304. }
  305. // GetManualEdbCountByCondition
  306. // @Description: 根据获取手工数据条数
  307. // @author: Roc
  308. // @datetime 2024-08-05 09:37:16
  309. // @param condition string
  310. // @param pars []interface{}
  311. // @return count int
  312. // @return err error
  313. func GetManualEdbCountByCondition(condition string, pars []interface{}) (count int, err error) {
  314. sql := ` SELECT COUNT(1) AS count FROM edbinfo WHERE 1=1 `
  315. if condition != "" {
  316. sql += condition
  317. }
  318. err = global.DmSQL["edb"].Raw(sql, pars...).Scan(&count).Error
  319. return
  320. }
  321. // DelEdbinfoOpRecordByTradeCode
  322. // @Description: 根据指标编码删除操作日志
  323. // @author: Roc
  324. // @datetime 2024-08-05 10:27:29
  325. // @param tradeCode string
  326. // @return err error
  327. func DelEdbinfoOpRecordByTradeCode(tradeCode string) (err error) {
  328. sql := ` DELETE FROM edbinfo_op_record WHERE TRADE_CODE = ? `
  329. err = global.DmSQL["edb"].Exec(sql, tradeCode).Error
  330. return
  331. }