target.go 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768
  1. package models
  2. import (
  3. "fmt"
  4. "hongze/hongze_admin/utils"
  5. "rdluck_tools/orm"
  6. "sort"
  7. "strings"
  8. "time"
  9. )
  10. type DataList struct {
  11. TradeCode string `orm:"column(TRADE_CODE)" description:"指标编码"`
  12. SecName string `orm:"column(SEC_NAME)" description:"指标名称"`
  13. Unit string `orm:"column(UNIT)" description:"单位"`
  14. Remark string `orm:"column(REMARK)" description:"备注"`
  15. Frequency string `description:"频度"`
  16. ClassifyId int `description:"分类id"`
  17. ClassifyName string `description:"分类名称"`
  18. Dt string `orm:"column(DT)" description:"录入日期"`
  19. Close float64 `orm:"column(CLOSE)" description:"录入值"`
  20. ModifyTime string `description:"修改时间"`
  21. }
  22. type DataListResp struct {
  23. List []*DataList
  24. Paging *PagingItem `description:"分页数据"`
  25. }
  26. func GetDataList(condition string, pars []interface{}, startSize, pageSize int) (items []*DataList, err error) {
  27. 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
  28. inner join edbinfo AS a ON a.TRADE_CODE=c.TRADE_CODE
  29. left join edbdata_classify AS b ON a.classify_id=b.classify_id
  30. where left(a.TRADE_CODE,1)='W' AND a.REMARK='手动' AND a.classify_id>0`
  31. if condition != "" {
  32. sql += condition
  33. }
  34. sql += ` order by c.DT desc limit ?,? `
  35. o := orm.NewOrm()
  36. o.Using("edb")
  37. _, err = o.Raw(sql, pars).QueryRows(&items)
  38. return
  39. }
  40. func GetDataListCount(condition string, pars []interface{}) (count int, err error) {
  41. sql := ` select count(1) as count FROM edbdata AS c
  42. inner join edbinfo AS a ON a.TRADE_CODE=c.TRADE_CODE
  43. left join edbdata_classify AS b ON a.classify_id=b.classify_id
  44. where left(a.TRADE_CODE,1)='W' AND a.REMARK='手动' AND a.classify_id>0 `
  45. if condition != "" {
  46. sql += condition
  47. }
  48. o := orm.NewOrm()
  49. o.Using("edb")
  50. err = o.Raw(sql, pars).QueryRow(&count)
  51. return
  52. }
  53. type DataAddReq struct {
  54. TradeCode string `description:"指标唯一编码"`
  55. CreateDate string `description:"创建日期"`
  56. Close float64 `description:"录入值"`
  57. }
  58. type Edbdata struct {
  59. TradeCode string `orm:"column(TRADE_CODE);pk" description:"指标编码"`
  60. Dt string `orm:"column(DT)" description:"日期"`
  61. Close float64 `orm:"column(CLOSE)" description:"值"`
  62. ModifyTime time.Time `orm:"column(modify_time)" description:"修改时间"`
  63. }
  64. func GetDataInfo(tradeCode, creteDate string) (item *Edbdata, err error) {
  65. sql := " SELECT * FROM edbdata WHERE TRADE_CODE=? AND DT=? "
  66. o := orm.NewOrm()
  67. o.Using("edb")
  68. err = o.Raw(sql, tradeCode, creteDate).QueryRow(&item)
  69. return
  70. }
  71. func AddEdbdata(item *Edbdata) (lastId int64, err error) {
  72. o := orm.NewOrm()
  73. o.Using("edb")
  74. lastId, err = o.Insert(item)
  75. return
  76. }
  77. type DataEditReq struct {
  78. TradeCode string `description:"指标唯一编码"`
  79. CreateDate string `description:"创建日期"`
  80. Close float64 `description:"录入值"`
  81. OldCreateDate string `description:"旧的录入日期"`
  82. }
  83. //编辑数据
  84. func EditEdbdata(item *Edbdata) (err error) {
  85. o := orm.NewOrm()
  86. o.Using("edb")
  87. sql := ` UPDATE edbdata SET CLOSE = ?,modify_time=NOW() WHERE TRADE_CODE = ? AND DT = ? `
  88. _, err = o.Raw(sql, item.Close, item.TradeCode, item.Dt).Exec()
  89. return
  90. }
  91. type EdbdataDeleteRecord struct {
  92. Id int `orm:"column(id);pk"`
  93. TradeCode string `orm:"column(TRADE_CODE)" description:"指标编码"`
  94. Dt string `orm:"column(DT)" description:"日期"`
  95. Close float64 `orm:"column(CLOSE)" description:"值"`
  96. ModifyTime time.Time `orm:"column(modify_time)" description:"修改时间"`
  97. CreateTime time.Time
  98. SysUserId int
  99. }
  100. func AddEdbdataDeleteRecord(item *EdbdataDeleteRecord) (lastId int64, err error) {
  101. o := orm.NewOrm()
  102. o.Using("edb")
  103. lastId, err = o.Insert(item)
  104. return
  105. }
  106. //删除数据
  107. func DeleteEdbData(tradeCode, dt string) (err error) {
  108. o := orm.NewOrm()
  109. o.Using("edb")
  110. sql := ` DELETE FROM edbdata WHERE TRADE_CODE = ? AND DT = ? `
  111. _, err = o.Raw(sql, tradeCode, dt).Exec()
  112. return
  113. }
  114. type Edbinfo struct {
  115. TradeCode string `orm:"column(TRADE_CODE);pk" description:"指标code"`
  116. SecName string `orm:"column(SEC_NAME);" description:"指标名称"`
  117. Unit string `orm:"column(UNIT);" description:"单位"`
  118. Remark string `orm:"column(REMARK);" description:"备注"`
  119. Frequency string `description:"频度"`
  120. ClassifyId int `description:"分类id"`
  121. ClassifyName string `description:"分类名称"`
  122. CreateDate string `description:"创建时间"`
  123. UserId int `description:"录入用户id"`
  124. NoticeTime string `description:"通知时间"`
  125. Mobile string `description:"录入者手机号"`
  126. }
  127. func GetEdbinfoListCount(condition string, pars []interface{}, mobile string) (count int, err error) {
  128. o := orm.NewOrm()
  129. o.Using("edb")
  130. sql := ``
  131. if mobile != "" {
  132. sql = `SELECT COUNT(1) AS count FROM edbinfo AS a
  133. INNER JOIN edbinfo_user AS c ON a.TRADE_CODE=c.TRADE_CODE AND c.mobile=?
  134. WHERE LEFT(a.TRADE_CODE,1)='W' AND a.REMARK='手动' AND a.classify_id>0`
  135. if condition != "" {
  136. sql += condition
  137. }
  138. err = o.Raw(sql, mobile, pars).QueryRow(&count)
  139. } else {
  140. sql := `SELECT COUNT(1) AS count FROM edbinfo AS a WHERE LEFT(a.TRADE_CODE,1)='W' AND a.REMARK='手动' AND a.classify_id>0`
  141. if condition != "" {
  142. sql += condition
  143. }
  144. err = o.Raw(sql, pars).QueryRow(&count)
  145. }
  146. return
  147. }
  148. func GetEdbinfoList(condition string, pars []interface{}, startSize, pageSize int, mobile string) (items []*Edbinfo, err error) {
  149. o := orm.NewOrm()
  150. o.Using("edb")
  151. sql := ``
  152. if mobile != "" {
  153. sql = ` SELECT a.*,b.classify_name FROM edbinfo AS a
  154. LEFT JOIN edbdata_classify AS b ON a.classify_id=b.classify_id
  155. INNER JOIN edbinfo_user AS c ON a.TRADE_CODE=c.TRADE_CODE AND c.mobile=?
  156. WHERE LEFT(a.TRADE_CODE,1)='W' AND a.REMARK='手动' AND a.classify_id>0`
  157. if condition != "" {
  158. sql += condition
  159. }
  160. sql += ` ORDER BY c.DT DESC LIMIT ?,? `
  161. _, err = o.Raw(sql, mobile, pars).QueryRows(&items)
  162. } else {
  163. sql = `SELECT a.*,b.classify_name FROM edbinfo AS a
  164. LEFT JOIN edbdata_classify AS b on a.classify_id=b.classify_id
  165. WHERE LEFT(a.TRADE_CODE,1)='W' AND a.REMARK='手动' AND a.classify_id>0`
  166. if condition != "" {
  167. sql += condition
  168. }
  169. sql += ` ORDER BY c.DT DESC LIMIT ?,? `
  170. _, err = o.Raw(sql, pars).QueryRows(&items)
  171. }
  172. return
  173. }
  174. type TargetListResp struct {
  175. List []*Edbinfo
  176. Paging *PagingItem `description:"分页数据"`
  177. }
  178. type EdbinfoAddReq struct {
  179. SecName string `description:"指标名称"`
  180. Unit string `description:"单位"`
  181. Frequency string `description:"频度"`
  182. ClassifyId int `description:"分类id"`
  183. NoticeTime string `description:"通知时间"`
  184. }
  185. //获取指标最大trade_code
  186. func GetMaxTradeCode() (max_trade_code string, err error) {
  187. sql := " SELECT MAX(TRADE_CODE) AS max_trade_code FROM edbinfo WHERE LEFT(TRADE_CODE,1)='W' AND REMARK='手动' "
  188. o := orm.NewOrm()
  189. o.Using("edb")
  190. err = o.Raw(sql).QueryRow(&max_trade_code)
  191. return
  192. }
  193. func GetEdbinfoBySecName(secName string) (item *Edbinfo, err error) {
  194. sql := `SELECT * FROM edbinfo WHERE SEC_NAME=? AND left(TRADE_CODE,1)='W' AND REMARK='手动' `
  195. o := orm.NewOrm()
  196. o.Using("edb")
  197. err = o.Raw(sql, secName).QueryRow(&item)
  198. return
  199. }
  200. func AddEdbinfo(tradeCode, secName, unit, remark, frequency, noticeTime string, classifyId int, userId int) (err error) {
  201. sql := `INSERT INTO edbinfo(TRADE_CODE, SEC_NAME,UNIT, REMARK,frequency, classify_id,notice_time,user_id)
  202. VALUES(?,?,?,?,?,?,?,?,?) `
  203. o := orm.NewOrm()
  204. o.Using("edb")
  205. _, err = o.Raw(sql, tradeCode, secName, unit, remark, frequency, classifyId, noticeTime, userId).Exec()
  206. return
  207. }
  208. func AddEdbinfoUser(tradeCode, mobile string) (err error) {
  209. o := orm.NewOrm()
  210. o.Using("edb")
  211. sql := `INSERT INTO edbinfo_user(TRADE_CODE, mobile) VALUES (?,?)`
  212. _, err = o.Raw(sql, tradeCode, mobile).Exec()
  213. return
  214. }
  215. type EdbinfoEditReq struct {
  216. TradeCode string `description:"指标code"`
  217. SecName string `description:"指标名称"`
  218. Unit string `description:"单位"`
  219. Frequency string `description:"频度"`
  220. ClassifyId int `description:"分类id"`
  221. NoticeTime string `description:"通知时间"`
  222. }
  223. func EditEdbinfo(tradeCode, secName, unit, frequency, noticeTime string, classifyId int) (err error) {
  224. sql := `UPDATE edbinfo SET SEC_NAME= ?, UNIT = ?,classify_id=?,frequency=?,notice_time=?,create_date=NOW() WHERE TRADE_CODE=? `
  225. o := orm.NewOrm()
  226. o.Using("edb")
  227. _, err = o.Raw(sql, secName, unit, classifyId, frequency, noticeTime, tradeCode).Exec()
  228. return
  229. }
  230. func SearchTargetEntry(classifyId int, keyWord string) (items []*Edbinfo, err error) {
  231. where := ""
  232. if keyWord != "" {
  233. where = `AND SEC_NAME LIKE '%` + keyWord + `%'`
  234. }
  235. sql := `SELECT * FROM edbinfo WHERE LEFT(TRADE_CODE,1)='W' AND REMARK='手动' AND classify_id>0 AND classify_id=? `
  236. sql += where
  237. o := orm.NewOrm()
  238. o.Using("edb")
  239. _, err = o.Raw(sql, classifyId).QueryRows(&items)
  240. return
  241. }
  242. type SearchTargetListResp struct {
  243. List []*Edbinfo
  244. }
  245. type EdbdataClassify struct {
  246. ClassifyId int
  247. ClassifyName string
  248. ParentId int
  249. }
  250. func GetEdbdataClassifyByClassifyName(classifyName string) (item *EdbdataClassify, err error) {
  251. sql := `SELECT * FROM edbdata_classify WHERE classify_name=? `
  252. o := orm.NewOrm()
  253. o.Using("edb")
  254. err = o.Raw(sql, classifyName).QueryRow(&item)
  255. return
  256. }
  257. type EdbdataClassifyList struct {
  258. ClassifyId int
  259. ClassifyName string
  260. ParentId int
  261. Child []*EdbdataClassify
  262. }
  263. func GetEdbdataClassify(userId int64) (items []*EdbdataClassifyList, err error) {
  264. var newItems []*EdbdataClassifyList
  265. o := orm.NewOrm()
  266. o.Using("edb")
  267. sql := ` SELECT classify_id,classify_name,parent_id FROM edbdata_classify WHERE parent_id=0 `
  268. _, err = o.Raw(sql).QueryRows(&newItems)
  269. if err != nil {
  270. return
  271. }
  272. classifyLen := len(newItems)
  273. for i := 0; i < classifyLen; i++ {
  274. var childItems []*EdbdataClassify
  275. parentId := newItems[i].ClassifyId
  276. childSql := ``
  277. if userId > 0 {
  278. childSql = "SELECT a.classify_id,a.classify_name,a.parent_id FROM edbdata_classify AS a INNER JOIN edbdata_classify_user AS b ON a.classify_id=b.classify_id WHERE b.user_id =? AND parent_id=? ORDER BY create_time ASC "
  279. _, err = o.Raw(childSql, userId, parentId).QueryRows(&childItems)
  280. } else {
  281. childSql = "SELECT classify_id,classify_name,parent_id FROM edbdata_classify WHERE parent_id=? ORDER BY create_time ASC "
  282. _, err = o.Raw(childSql, parentId).QueryRows(&childItems)
  283. }
  284. if err != nil {
  285. return
  286. }
  287. newItems[i].Child = childItems
  288. }
  289. for _, v := range newItems {
  290. childLen := len(v.Child)
  291. if childLen > 0 {
  292. items = append(items, v)
  293. }
  294. }
  295. return
  296. }
  297. type EdbdataClassifyResp struct {
  298. List []*EdbdataClassifyList
  299. }
  300. func GetTargetBySecName(secName string) (item *Edbinfo, err error) {
  301. sql := `SELECT * FROM edbinfo WHERE SEC_NAME=? AND left(TRADE_CODE,1)='W' AND REMARK='手动' `
  302. o := orm.NewOrm()
  303. o.Using("edb")
  304. err = o.Raw(sql, secName).QueryRow(&item)
  305. return
  306. }
  307. func ModifyTargetClassifyId(tradeCode string, classifyId int) (err error) {
  308. sql := `UPDATE edbinfo SET classify_id=? WHERE TRADE_CODE=? `
  309. o := orm.NewOrm()
  310. o.Using("edb")
  311. _, err = o.Raw(sql, classifyId, tradeCode).Exec()
  312. return
  313. }
  314. func GetTargetsDataCount(tradeCode, dt string) (count int, err error) {
  315. sql := `SELECT COUNT(1) AS count FROM edbdata WHERE TRADE_CODE=? AND DT=? `
  316. o := orm.NewOrm()
  317. o.Using("edb")
  318. err = o.Raw(sql, tradeCode, dt).QueryRow(&count)
  319. return
  320. }
  321. func GetTargetsData(tradeCode, dt string) (item *Edbdata, err error) {
  322. sql := `SELECT * FROM edbdata WHERE TRADE_CODE=? AND DT=? `
  323. o := orm.NewOrm()
  324. o.Using("edb")
  325. err = o.Raw(sql, tradeCode, dt).QueryRow(&item)
  326. return
  327. }
  328. func ModifyTargetsDataByImport(tradeCode, dt, close string) (err error) {
  329. sql := `UPDATE edbdata SET CLOSE=?,modify_time=NOW() WHERE TRADE_CODE=? AND DT=? `
  330. o := orm.NewOrm()
  331. o.Using("edb")
  332. _, err = o.Raw(sql, close, tradeCode, dt).Exec()
  333. return
  334. }
  335. func AddTargetsDataByImport(tradeCode, dt, close string) (err error) {
  336. sql := `INSERT INTO edbdata(TRADE_CODE, DT,CLOSE, modify_time)VALUES(?,?,?,NOW()) `
  337. o := orm.NewOrm()
  338. o.Using("edb")
  339. _, err = o.Raw(sql, tradeCode, dt, close).Exec()
  340. return
  341. }
  342. type EdbdataImportResp struct {
  343. Status int
  344. Msg string
  345. }
  346. func GetFailList(sysUserId int) (items []*EdbdataImportFail, err error) {
  347. o := orm.NewOrm()
  348. o.Using("edb")
  349. sql := ` SELECT * FROM edbdata_import_fail WHERE sys_user_id=? `
  350. _, err = o.Raw(sql, sysUserId).QueryRows(&items)
  351. return
  352. }
  353. type DataListForExport struct {
  354. TradeCode string `orm:"column(TRADE_CODE)" description:"指标code"`
  355. SecName string `orm:"column(SEC_NAME)" description:"指标名称"`
  356. Unit string `orm:"column(UNIT)" description:"单位"`
  357. Frequency string `description:"频度"`
  358. ClassifyId int `description:"分类id"`
  359. NoticeTime string `description:"通知时间"`
  360. ClassifyName string
  361. Dt string `orm:"column(DT)" description:"日期"`
  362. Close float64 `orm:"column(CLOSE)" description:"值"`
  363. }
  364. func GetDataListForExport(startDate, endDate, frequency, keyWord string, classifyId int) (items []*DataListForExport, err error) {
  365. where := ``
  366. var pars []interface{}
  367. if keyWord != "" {
  368. where = ` AND SEC_NAME LIKE '%` + keyWord + `%`
  369. }
  370. if startDate != "" {
  371. where += ` AND create_date>=? `
  372. pars = append(pars, startDate)
  373. }
  374. if endDate != "" {
  375. where += ` AND create_date<=? `
  376. pars = append(pars, endDate)
  377. }
  378. if frequency != "" {
  379. where += ` AND frequency=? `
  380. pars = append(pars, frequency)
  381. }
  382. if classifyId > 0 {
  383. where += ` AND classify_id=? `
  384. pars = append(pars, classifyId)
  385. }
  386. 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
  387. INNER JOIN edbinfo AS a ON a.TRADE_CODE=c.TRADE_CODE
  388. LEFT JOIN edbdata_classify AS b ON a.classify_id=b.classify_id
  389. WHERE LEFT(a.TRADE_CODE,1)='W' AND a.REMARK='手动' AND a.classify_id>0 `
  390. if where != "" {
  391. sql += where
  392. }
  393. sql = sql + " ORDER BY c.DT DESC "
  394. o := orm.NewOrm()
  395. o.Using("edb")
  396. _, err = o.Raw(sql, pars).QueryRows(&items)
  397. return
  398. }
  399. type DataDeleteReq struct {
  400. TradeCode string `description:"指标唯一编码"`
  401. CreateDate string `description:"数据录入日期"`
  402. }
  403. func DataDelete(tradeCode, createDate string, close float64, modifyTime time.Time, sysUserId int) (err error) {
  404. o := orm.NewOrm()
  405. o.Using("edb")
  406. o.Begin()
  407. defer func() {
  408. if err != nil {
  409. o.Rollback()
  410. } else {
  411. o.Commit()
  412. }
  413. }()
  414. recordSql := ` INSERT INTO edbdata_delete_record(TRADE_CODE,DT,CLOSE,modify_time,create_time,sys_user_id)
  415. VALUES(?,?,?,?,?,?)`
  416. _, err = o.Raw(recordSql, tradeCode, createDate, close, modifyTime, time.Now(), sysUserId).Exec()
  417. sql := ` DELETE FROM edbdata WHERE TRADE_CODE = ? AND DT = ? `
  418. _, err = o.Raw(sql, tradeCode, createDate).Exec()
  419. return
  420. }
  421. func GetTargetInfoCount(tradeCode string) (count int, err error) {
  422. sql := ` SELECT COUNT(1) AS count FROM edbdata AS c
  423. INNER JOIN edbinfo AS a ON a.TRADE_CODE=c.TRADE_CODE
  424. WHERE a.TRADE_CODE=? `
  425. o := orm.NewOrm()
  426. o.Using("edb")
  427. err = o.Raw(sql, tradeCode).QueryRow(&count)
  428. return
  429. }
  430. type TargetDeleteReq struct {
  431. TradeCode string `description:"指标唯一编码"`
  432. }
  433. func TargetDelete(tradeCode string) (err error) {
  434. o := orm.NewOrm()
  435. o.Using("edb")
  436. sql := " DELETE FROM edbinfo WHERE TRADE_CODE = ? "
  437. _, err = o.Raw(sql, tradeCode).Exec()
  438. return
  439. }
  440. type Researcher struct {
  441. AdminId int `description:"系统用户id"`
  442. AdminName string `description:"系统用户名称"`
  443. RealName string `description:"系统用户姓名"`
  444. Role string `description:"系统用户角色"`
  445. Mobile string `description:"手机号"`
  446. TargetCount int `description:"指标数量"`
  447. }
  448. type ResearcherListResp struct {
  449. List []*Researcher
  450. }
  451. func GetResearcherEntry() (items []*Researcher, err error) {
  452. sql := ` SELECT admin_id,admin_name,real_name,mobile,0 as target_count FROM admin WHERE role='researcher' AND role_type=1 `
  453. o := orm.NewOrm()
  454. o.Using("edb")
  455. _, err = o.Raw(sql).QueryRows(&items)
  456. researchLen := len(items)
  457. for i := 0; i < researchLen; i++ {
  458. var count int
  459. mobile := items[i].Mobile
  460. sqlCount := ` SELECT COUNT(DISTINCT a.TRADE_CODE) AS count FROM edbinfo_user AS a
  461. INNER JOIN edbinfo AS b ON a.TRADE_CODE=b.TRADE_CODE
  462. WHERE a.mobile=? AND LEFT(b.TRADE_CODE,1)='W' AND b.REMARK='手动' AND b.classify_id>0 `
  463. err = o.Raw(sqlCount, mobile).QueryRow(&count)
  464. items[i].TargetCount = count
  465. }
  466. return
  467. }
  468. type EdbinfoItems struct {
  469. TradeCode string `orm:"column(TRADE_CODE);pk" description:"指标code"`
  470. SecName string `orm:"column(SEC_NAME);" description:"指标名称"`
  471. Unit string `orm:"column(UNIT);" description:"单位"`
  472. Remark string `orm:"column(REMARK);" description:"备注"`
  473. Frequency string `description:"频度"`
  474. ClassifyId int `description:"分类id"`
  475. ClassifyName string `description:"分类名称"`
  476. CreateDate string `description:"创建时间"`
  477. UserId int `description:"录入用户id"`
  478. NoticeTime string `description:"通知时间"`
  479. Mobile string `description:"录入者手机号"`
  480. ModifyDate string `description:"待更新日期"`
  481. Status string `description:"状态:未完成/完成"`
  482. }
  483. type TargetItemsResp struct {
  484. List SortEdbInfo
  485. }
  486. type SortEdbInfo []EdbinfoItems
  487. func GetTargetItems(mobile string) (lastItems SortEdbInfo, err error) {
  488. var items []*EdbinfoItems
  489. o := orm.NewOrm()
  490. o.Using("edb")
  491. sql := ` SELECT *,'' modify_date,'' status FROM edbinfo AS a WHERE LEFT(a.TRADE_CODE,1)='W' AND a.REMARK='手动' AND a.classify_id>0 `
  492. if mobile != "" {
  493. sql = ` SELECT *,'' modify_date,'' status FROM edbinfo AS a
  494. INNER JOIN edbinfo_user AS b ON a.TRADE_CODE=b.TRADE_CODE
  495. WHERE LEFT(a.TRADE_CODE,1)='W' AND a.REMARK='手动' AND a.classify_id>0
  496. AND b.mobile='` + mobile + `'`
  497. }
  498. sql = sql + ` ORDER BY CONVERT(a.SEC_NAME USING gbk ) COLLATE gbk_chinese_ci ASC `
  499. _, err = o.Raw(sql).QueryRows(&items)
  500. if err != nil {
  501. return
  502. }
  503. itemsLen := len(items)
  504. nowWeek := time.Now().Weekday().String()
  505. fmt.Println(nowWeek)
  506. finishEdbInfo := SortEdbInfo{}
  507. unFinishEdbInfo := SortEdbInfo{}
  508. for i := 0; i < itemsLen; i++ {
  509. noticeTime := items[i].NoticeTime
  510. frequency := items[i].Frequency
  511. tradeCode := items[i].TradeCode
  512. if noticeTime != "" {
  513. if frequency == "周度" {
  514. noticeArr := strings.Split(noticeTime, " ")
  515. noticeWeek := noticeArr[0]
  516. fmt.Println(noticeWeek)
  517. addDay := 0
  518. if nowWeek == "Sunday" {
  519. if noticeWeek == "周日" {
  520. addDay = 0
  521. } else if noticeWeek == "周一" {
  522. addDay = 1
  523. } else if noticeWeek == "周二" {
  524. addDay = 2
  525. } else if noticeWeek == "周三" {
  526. addDay = 3
  527. } else if noticeWeek == "周四" {
  528. addDay = 4
  529. } else if noticeWeek == "周五" {
  530. addDay = 5
  531. } else if noticeWeek == "周六" {
  532. addDay = 6
  533. } else {
  534. addDay = 0
  535. }
  536. } else if nowWeek == "Monday" {
  537. if noticeWeek == "周日" {
  538. addDay = 6
  539. } else if noticeWeek == "周一" {
  540. addDay = 0
  541. } else if noticeWeek == "周二" {
  542. addDay = 1
  543. } else if noticeWeek == "周三" {
  544. addDay = 2
  545. } else if noticeWeek == "周四" {
  546. addDay = 3
  547. } else if noticeWeek == "周五" {
  548. addDay = 4
  549. } else if noticeWeek == "周六" {
  550. addDay = 5
  551. } else {
  552. addDay = 0
  553. }
  554. } else if nowWeek == "Tuesday" {
  555. if noticeWeek == "周日" {
  556. addDay = 5
  557. } else if noticeWeek == "周一" {
  558. addDay = 6
  559. } else if noticeWeek == "周二" {
  560. addDay = 0
  561. } else if noticeWeek == "周三" {
  562. addDay = 1
  563. } else if noticeWeek == "周四" {
  564. addDay = 2
  565. } else if noticeWeek == "周五" {
  566. addDay = 3
  567. } else if noticeWeek == "周六" {
  568. addDay = 4
  569. } else {
  570. addDay = 0
  571. }
  572. } else if nowWeek == "Wednesday" {
  573. if noticeWeek == "周日" {
  574. addDay = 4
  575. } else if noticeWeek == "周一" {
  576. addDay = 5
  577. } else if noticeWeek == "周二" {
  578. addDay = 6
  579. } else if noticeWeek == "周三" {
  580. addDay = 0
  581. } else if noticeWeek == "周四" {
  582. addDay = 1
  583. } else if noticeWeek == "周五" {
  584. addDay = 2
  585. } else if noticeWeek == "周六" {
  586. addDay = 3
  587. } else {
  588. addDay = 0
  589. }
  590. } else if nowWeek == "Thursday" {
  591. if noticeWeek == "周日" {
  592. addDay = 3
  593. } else if noticeWeek == "周一" {
  594. addDay = 4
  595. } else if noticeWeek == "周二" {
  596. addDay = 5
  597. } else if noticeWeek == "周三" {
  598. addDay = 6
  599. } else if noticeWeek == "周四" {
  600. addDay = 0
  601. } else if noticeWeek == "周五" {
  602. addDay = 1
  603. } else if noticeWeek == "周六" {
  604. addDay = 2
  605. } else {
  606. addDay = 0
  607. }
  608. } else if nowWeek == "Friday" {
  609. if noticeWeek == "周日" {
  610. addDay = 2
  611. } else if noticeWeek == "周一" {
  612. addDay = 3
  613. } else if noticeWeek == "周二" {
  614. addDay = 4
  615. } else if noticeWeek == "周三" {
  616. addDay = 5
  617. } else if noticeWeek == "周四" {
  618. addDay = 6
  619. } else if noticeWeek == "周五" {
  620. addDay = 0
  621. } else if noticeWeek == "周六" {
  622. addDay = 1
  623. } else {
  624. addDay = 0
  625. }
  626. } else if nowWeek == "Saturday" {
  627. if noticeWeek == "周日" {
  628. addDay = 1
  629. } else if noticeWeek == "周一" {
  630. addDay = 2
  631. } else if noticeWeek == "周二" {
  632. addDay = 3
  633. } else if noticeWeek == "周三" {
  634. addDay = 4
  635. } else if noticeWeek == "周四" {
  636. addDay = 5
  637. } else if noticeWeek == "周五" {
  638. addDay = 6
  639. } else if noticeWeek == "周六" {
  640. addDay = 0
  641. } else {
  642. addDay = 0
  643. }
  644. }
  645. modifyDate := time.Now().AddDate(0, 0, addDay)
  646. modifyDateStr := modifyDate.Format(utils.FormatDate)
  647. items[i].ModifyDate = modifyDateStr
  648. modifyDateEndStr := modifyDate.AddDate(0, 0, -7).Format(utils.FormatDate)
  649. fmt.Println("addDay:", addDay)
  650. fmt.Println("modifyDateEndStr:", modifyDateEndStr)
  651. count := 0
  652. sqlCount := ` SELECT COUNT(1) AS num FROM edbdata WHERE TRADE_CODE=? AND DT >= ? AND DT <= ? `
  653. err = o.Raw(sqlCount, tradeCode, modifyDateEndStr, modifyDateStr).QueryRow(&count)
  654. if err != nil {
  655. return nil, err
  656. }
  657. if count > 0 {
  658. items[i].Status = "完成"
  659. finishEdbInfo = append(finishEdbInfo, *items[i])
  660. } else {
  661. items[i].Status = "未完成"
  662. unFinishEdbInfo = append(unFinishEdbInfo, *items[i])
  663. }
  664. }
  665. } else {
  666. items[i].Status = "完成"
  667. finishEdbInfo = append(finishEdbInfo, *items[i])
  668. }
  669. }
  670. sort.Sort(SortByModifyDate{finishEdbInfo})
  671. sort.Sort(SortByModifyDate{unFinishEdbInfo})
  672. lastItems = append(lastItems, unFinishEdbInfo...)
  673. lastItems = append(lastItems, finishEdbInfo...)
  674. return
  675. }
  676. //获取此 slice 的长度
  677. func (p SortEdbInfo) Len() int { return len(p) }
  678. // 根据元素的状态降序排序
  679. func (p SortEdbInfo) Less(i, j int) bool {
  680. return p[i].Status > p[j].Status
  681. }
  682. // 交换数据
  683. func (p SortEdbInfo) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
  684. // 嵌套结构体 将继承 SortEdbInfo 的所有属性和方法
  685. // 所以相当于SortByName 也实现了 Len() 和 Swap() 方法
  686. type SortByStatus struct{ SortEdbInfo }
  687. // 根据元素的姓名长度降序排序 (此处按照自己的业务逻辑写)
  688. func (p SortByStatus) Less(i, j int) bool {
  689. return len(p.SortEdbInfo[i].Status) > len(p.SortEdbInfo[j].Status)
  690. }
  691. type SortByModifyDate struct{ SortEdbInfo }
  692. // 根据元素的年龄降序排序 (此处按照自己的业务逻辑写)
  693. func (p SortByModifyDate) Less(i, j int) bool {
  694. return p.SortEdbInfo[i].ModifyDate > p.SortEdbInfo[j].ModifyDate
  695. }