123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768 |
- package models
- import (
- "fmt"
- "hongze/hongze_admin/utils"
- "rdluck_tools/orm"
- "sort"
- "strings"
- "time"
- )
- type DataList struct {
- TradeCode string `orm:"column(TRADE_CODE)" description:"指标编码"`
- SecName string `orm:"column(SEC_NAME)" description:"指标名称"`
- Unit string `orm:"column(UNIT)" description:"单位"`
- Remark string `orm:"column(REMARK)" description:"备注"`
- Frequency string `description:"频度"`
- ClassifyId int `description:"分类id"`
- ClassifyName string `description:"分类名称"`
- Dt string `orm:"column(DT)" description:"录入日期"`
- Close float64 `orm:"column(CLOSE)" description:"录入值"`
- ModifyTime string `description:"修改时间"`
- }
- type DataListResp struct {
- List []*DataList
- Paging *PagingItem `description:"分页数据"`
- }
- func GetDataList(condition string, pars []interface{}, startSize, pageSize int) (items []*DataList, err error) {
- 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
- inner join edbinfo AS a ON a.TRADE_CODE=c.TRADE_CODE
- left join edbdata_classify AS b ON a.classify_id=b.classify_id
- where left(a.TRADE_CODE,1)='W' AND a.REMARK='手动' AND a.classify_id>0`
- if condition != "" {
- sql += condition
- }
- sql += ` order by c.DT desc limit ?,? `
- o := orm.NewOrm()
- o.Using("edb")
- _, err = o.Raw(sql, pars).QueryRows(&items)
- return
- }
- func GetDataListCount(condition string, pars []interface{}) (count int, err error) {
- sql := ` select count(1) as count FROM edbdata AS c
- inner join edbinfo AS a ON a.TRADE_CODE=c.TRADE_CODE
- left join edbdata_classify AS b ON a.classify_id=b.classify_id
- where left(a.TRADE_CODE,1)='W' AND a.REMARK='手动' AND a.classify_id>0 `
- if condition != "" {
- sql += condition
- }
- o := orm.NewOrm()
- o.Using("edb")
- err = o.Raw(sql, pars).QueryRow(&count)
- return
- }
- type DataAddReq struct {
- TradeCode string `description:"指标唯一编码"`
- CreateDate string `description:"创建日期"`
- Close float64 `description:"录入值"`
- }
- type Edbdata struct {
- TradeCode string `orm:"column(TRADE_CODE);pk" description:"指标编码"`
- Dt string `orm:"column(DT)" description:"日期"`
- Close float64 `orm:"column(CLOSE)" description:"值"`
- ModifyTime time.Time `orm:"column(modify_time)" description:"修改时间"`
- }
- func GetDataInfo(tradeCode, creteDate string) (item *Edbdata, err error) {
- sql := " SELECT * FROM edbdata WHERE TRADE_CODE=? AND DT=? "
- o := orm.NewOrm()
- o.Using("edb")
- err = o.Raw(sql, tradeCode, creteDate).QueryRow(&item)
- return
- }
- func AddEdbdata(item *Edbdata) (lastId int64, err error) {
- o := orm.NewOrm()
- o.Using("edb")
- lastId, err = o.Insert(item)
- return
- }
- type DataEditReq struct {
- TradeCode string `description:"指标唯一编码"`
- CreateDate string `description:"创建日期"`
- Close float64 `description:"录入值"`
- OldCreateDate string `description:"旧的录入日期"`
- }
- //编辑数据
- func EditEdbdata(item *Edbdata) (err error) {
- o := orm.NewOrm()
- o.Using("edb")
- sql := ` UPDATE edbdata SET CLOSE = ?,modify_time=NOW() WHERE TRADE_CODE = ? AND DT = ? `
- _, err = o.Raw(sql, item.Close, item.TradeCode, item.Dt).Exec()
- return
- }
- type EdbdataDeleteRecord struct {
- Id int `orm:"column(id);pk"`
- TradeCode string `orm:"column(TRADE_CODE)" description:"指标编码"`
- Dt string `orm:"column(DT)" description:"日期"`
- Close float64 `orm:"column(CLOSE)" description:"值"`
- ModifyTime time.Time `orm:"column(modify_time)" description:"修改时间"`
- CreateTime time.Time
- SysUserId int
- }
- func AddEdbdataDeleteRecord(item *EdbdataDeleteRecord) (lastId int64, err error) {
- o := orm.NewOrm()
- o.Using("edb")
- lastId, err = o.Insert(item)
- return
- }
- //删除数据
- func DeleteEdbData(tradeCode, dt string) (err error) {
- o := orm.NewOrm()
- o.Using("edb")
- sql := ` DELETE FROM edbdata WHERE TRADE_CODE = ? AND DT = ? `
- _, err = o.Raw(sql, tradeCode, dt).Exec()
- return
- }
- type Edbinfo struct {
- TradeCode string `orm:"column(TRADE_CODE);pk" description:"指标code"`
- SecName string `orm:"column(SEC_NAME);" description:"指标名称"`
- Unit string `orm:"column(UNIT);" description:"单位"`
- Remark string `orm:"column(REMARK);" description:"备注"`
- Frequency string `description:"频度"`
- ClassifyId int `description:"分类id"`
- ClassifyName string `description:"分类名称"`
- CreateDate string `description:"创建时间"`
- UserId int `description:"录入用户id"`
- NoticeTime string `description:"通知时间"`
- Mobile string `description:"录入者手机号"`
- }
- func GetEdbinfoListCount(condition string, pars []interface{}, mobile string) (count int, err error) {
- o := orm.NewOrm()
- o.Using("edb")
- sql := ``
- if mobile != "" {
- sql = `SELECT COUNT(1) AS count FROM edbinfo AS a
- INNER JOIN edbinfo_user AS c ON a.TRADE_CODE=c.TRADE_CODE AND c.mobile=?
- WHERE LEFT(a.TRADE_CODE,1)='W' AND a.REMARK='手动' AND a.classify_id>0`
- if condition != "" {
- sql += condition
- }
- err = o.Raw(sql, mobile, pars).QueryRow(&count)
- } else {
- 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`
- if condition != "" {
- sql += condition
- }
- err = o.Raw(sql, pars).QueryRow(&count)
- }
- return
- }
- func GetEdbinfoList(condition string, pars []interface{}, startSize, pageSize int, mobile string) (items []*Edbinfo, err error) {
- o := orm.NewOrm()
- o.Using("edb")
- sql := ``
- if mobile != "" {
- sql = ` SELECT a.*,b.classify_name FROM edbinfo AS a
- LEFT JOIN edbdata_classify AS b ON a.classify_id=b.classify_id
- INNER JOIN edbinfo_user AS c ON a.TRADE_CODE=c.TRADE_CODE AND c.mobile=?
- WHERE LEFT(a.TRADE_CODE,1)='W' AND a.REMARK='手动' AND a.classify_id>0`
- if condition != "" {
- sql += condition
- }
- sql += ` ORDER BY c.DT DESC LIMIT ?,? `
- _, err = o.Raw(sql, mobile, pars).QueryRows(&items)
- } else {
- sql = `SELECT a.*,b.classify_name FROM edbinfo AS a
- LEFT JOIN edbdata_classify AS b on a.classify_id=b.classify_id
- WHERE LEFT(a.TRADE_CODE,1)='W' AND a.REMARK='手动' AND a.classify_id>0`
- if condition != "" {
- sql += condition
- }
- sql += ` ORDER BY c.DT DESC LIMIT ?,? `
- _, err = o.Raw(sql, pars).QueryRows(&items)
- }
- return
- }
- type TargetListResp struct {
- List []*Edbinfo
- Paging *PagingItem `description:"分页数据"`
- }
- type EdbinfoAddReq struct {
- SecName string `description:"指标名称"`
- Unit string `description:"单位"`
- Frequency string `description:"频度"`
- ClassifyId int `description:"分类id"`
- NoticeTime string `description:"通知时间"`
- }
- //获取指标最大trade_code
- func GetMaxTradeCode() (max_trade_code string, err error) {
- sql := " SELECT MAX(TRADE_CODE) AS max_trade_code FROM edbinfo WHERE LEFT(TRADE_CODE,1)='W' AND REMARK='手动' "
- o := orm.NewOrm()
- o.Using("edb")
- err = o.Raw(sql).QueryRow(&max_trade_code)
- return
- }
- func GetEdbinfoBySecName(secName string) (item *Edbinfo, err error) {
- sql := `SELECT * FROM edbinfo WHERE SEC_NAME=? AND left(TRADE_CODE,1)='W' AND REMARK='手动' `
- o := orm.NewOrm()
- o.Using("edb")
- err = o.Raw(sql, secName).QueryRow(&item)
- return
- }
- func AddEdbinfo(tradeCode, secName, unit, remark, frequency, noticeTime string, classifyId int, userId int) (err error) {
- sql := `INSERT INTO edbinfo(TRADE_CODE, SEC_NAME,UNIT, REMARK,frequency, classify_id,notice_time,user_id)
- VALUES(?,?,?,?,?,?,?,?,?) `
- o := orm.NewOrm()
- o.Using("edb")
- _, err = o.Raw(sql, tradeCode, secName, unit, remark, frequency, classifyId, noticeTime, userId).Exec()
- return
- }
- func AddEdbinfoUser(tradeCode, mobile string) (err error) {
- o := orm.NewOrm()
- o.Using("edb")
- sql := `INSERT INTO edbinfo_user(TRADE_CODE, mobile) VALUES (?,?)`
- _, err = o.Raw(sql, tradeCode, mobile).Exec()
- return
- }
- type EdbinfoEditReq struct {
- TradeCode string `description:"指标code"`
- SecName string `description:"指标名称"`
- Unit string `description:"单位"`
- Frequency string `description:"频度"`
- ClassifyId int `description:"分类id"`
- NoticeTime string `description:"通知时间"`
- }
- func EditEdbinfo(tradeCode, secName, unit, frequency, noticeTime string, classifyId int) (err error) {
- sql := `UPDATE edbinfo SET SEC_NAME= ?, UNIT = ?,classify_id=?,frequency=?,notice_time=?,create_date=NOW() WHERE TRADE_CODE=? `
- o := orm.NewOrm()
- o.Using("edb")
- _, err = o.Raw(sql, secName, unit, classifyId, frequency, noticeTime, tradeCode).Exec()
- return
- }
- func SearchTargetEntry(classifyId int, keyWord string) (items []*Edbinfo, err error) {
- where := ""
- if keyWord != "" {
- where = `AND SEC_NAME LIKE '%` + keyWord + `%'`
- }
- sql := `SELECT * FROM edbinfo WHERE LEFT(TRADE_CODE,1)='W' AND REMARK='手动' AND classify_id>0 AND classify_id=? `
- sql += where
- o := orm.NewOrm()
- o.Using("edb")
- _, err = o.Raw(sql, classifyId).QueryRows(&items)
- return
- }
- type SearchTargetListResp struct {
- List []*Edbinfo
- }
- type EdbdataClassify struct {
- ClassifyId int
- ClassifyName string
- ParentId int
- }
- func GetEdbdataClassifyByClassifyName(classifyName string) (item *EdbdataClassify, err error) {
- sql := `SELECT * FROM edbdata_classify WHERE classify_name=? `
- o := orm.NewOrm()
- o.Using("edb")
- err = o.Raw(sql, classifyName).QueryRow(&item)
- return
- }
- type EdbdataClassifyList struct {
- ClassifyId int
- ClassifyName string
- ParentId int
- Child []*EdbdataClassify
- }
- func GetEdbdataClassify(userId int64) (items []*EdbdataClassifyList, err error) {
- var newItems []*EdbdataClassifyList
- o := orm.NewOrm()
- o.Using("edb")
- sql := ` SELECT classify_id,classify_name,parent_id FROM edbdata_classify WHERE parent_id=0 `
- _, err = o.Raw(sql).QueryRows(&newItems)
- if err != nil {
- return
- }
- classifyLen := len(newItems)
- for i := 0; i < classifyLen; i++ {
- var childItems []*EdbdataClassify
- parentId := newItems[i].ClassifyId
- childSql := ``
- if userId > 0 {
- 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 "
- _, err = o.Raw(childSql, userId, parentId).QueryRows(&childItems)
- } else {
- childSql = "SELECT classify_id,classify_name,parent_id FROM edbdata_classify WHERE parent_id=? ORDER BY create_time ASC "
- _, err = o.Raw(childSql, parentId).QueryRows(&childItems)
- }
- if err != nil {
- return
- }
- newItems[i].Child = childItems
- }
- for _, v := range newItems {
- childLen := len(v.Child)
- if childLen > 0 {
- items = append(items, v)
- }
- }
- return
- }
- type EdbdataClassifyResp struct {
- List []*EdbdataClassifyList
- }
- func GetTargetBySecName(secName string) (item *Edbinfo, err error) {
- sql := `SELECT * FROM edbinfo WHERE SEC_NAME=? AND left(TRADE_CODE,1)='W' AND REMARK='手动' `
- o := orm.NewOrm()
- o.Using("edb")
- err = o.Raw(sql, secName).QueryRow(&item)
- return
- }
- func ModifyTargetClassifyId(tradeCode string, classifyId int) (err error) {
- sql := `UPDATE edbinfo SET classify_id=? WHERE TRADE_CODE=? `
- o := orm.NewOrm()
- o.Using("edb")
- _, err = o.Raw(sql, classifyId, tradeCode).Exec()
- return
- }
- func GetTargetsDataCount(tradeCode, dt string) (count int, err error) {
- sql := `SELECT COUNT(1) AS count FROM edbdata WHERE TRADE_CODE=? AND DT=? `
- o := orm.NewOrm()
- o.Using("edb")
- err = o.Raw(sql, tradeCode, dt).QueryRow(&count)
- return
- }
- func GetTargetsData(tradeCode, dt string) (item *Edbdata, err error) {
- sql := `SELECT * FROM edbdata WHERE TRADE_CODE=? AND DT=? `
- o := orm.NewOrm()
- o.Using("edb")
- err = o.Raw(sql, tradeCode, dt).QueryRow(&item)
- return
- }
- func ModifyTargetsDataByImport(tradeCode, dt, close string) (err error) {
- sql := `UPDATE edbdata SET CLOSE=?,modify_time=NOW() WHERE TRADE_CODE=? AND DT=? `
- o := orm.NewOrm()
- o.Using("edb")
- _, err = o.Raw(sql, close, tradeCode, dt).Exec()
- return
- }
- func AddTargetsDataByImport(tradeCode, dt, close string) (err error) {
- sql := `INSERT INTO edbdata(TRADE_CODE, DT,CLOSE, modify_time)VALUES(?,?,?,NOW()) `
- o := orm.NewOrm()
- o.Using("edb")
- _, err = o.Raw(sql, tradeCode, dt, close).Exec()
- return
- }
- type EdbdataImportResp struct {
- Status int
- Msg string
- }
- func GetFailList(sysUserId int) (items []*EdbdataImportFail, err error) {
- o := orm.NewOrm()
- o.Using("edb")
- sql := ` SELECT * FROM edbdata_import_fail WHERE sys_user_id=? `
- _, err = o.Raw(sql, sysUserId).QueryRows(&items)
- return
- }
- type DataListForExport struct {
- TradeCode string `orm:"column(TRADE_CODE)" description:"指标code"`
- SecName string `orm:"column(SEC_NAME)" description:"指标名称"`
- Unit string `orm:"column(UNIT)" description:"单位"`
- Frequency string `description:"频度"`
- ClassifyId int `description:"分类id"`
- NoticeTime string `description:"通知时间"`
- ClassifyName string
- Dt string `orm:"column(DT)" description:"日期"`
- Close float64 `orm:"column(CLOSE)" description:"值"`
- }
- func GetDataListForExport(startDate, endDate, frequency, keyWord string, classifyId int) (items []*DataListForExport, err error) {
- where := ``
- var pars []interface{}
- if keyWord != "" {
- where = ` AND SEC_NAME LIKE '%` + keyWord + `%`
- }
- if startDate != "" {
- where += ` AND create_date>=? `
- pars = append(pars, startDate)
- }
- if endDate != "" {
- where += ` AND create_date<=? `
- pars = append(pars, endDate)
- }
- if frequency != "" {
- where += ` AND frequency=? `
- pars = append(pars, frequency)
- }
- if classifyId > 0 {
- where += ` AND classify_id=? `
- pars = append(pars, classifyId)
- }
- 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
- INNER JOIN edbinfo AS a ON a.TRADE_CODE=c.TRADE_CODE
- LEFT JOIN edbdata_classify AS b ON a.classify_id=b.classify_id
- WHERE LEFT(a.TRADE_CODE,1)='W' AND a.REMARK='手动' AND a.classify_id>0 `
- if where != "" {
- sql += where
- }
- sql = sql + " ORDER BY c.DT DESC "
- o := orm.NewOrm()
- o.Using("edb")
- _, err = o.Raw(sql, pars).QueryRows(&items)
- return
- }
- type DataDeleteReq struct {
- TradeCode string `description:"指标唯一编码"`
- CreateDate string `description:"数据录入日期"`
- }
- func DataDelete(tradeCode, createDate string, close float64, modifyTime time.Time, sysUserId int) (err error) {
- o := orm.NewOrm()
- o.Using("edb")
- o.Begin()
- defer func() {
- if err != nil {
- o.Rollback()
- } else {
- o.Commit()
- }
- }()
- recordSql := ` INSERT INTO edbdata_delete_record(TRADE_CODE,DT,CLOSE,modify_time,create_time,sys_user_id)
- VALUES(?,?,?,?,?,?)`
- _, err = o.Raw(recordSql, tradeCode, createDate, close, modifyTime, time.Now(), sysUserId).Exec()
- sql := ` DELETE FROM edbdata WHERE TRADE_CODE = ? AND DT = ? `
- _, err = o.Raw(sql, tradeCode, createDate).Exec()
- return
- }
- func GetTargetInfoCount(tradeCode string) (count int, err error) {
- sql := ` SELECT COUNT(1) AS count FROM edbdata AS c
- INNER JOIN edbinfo AS a ON a.TRADE_CODE=c.TRADE_CODE
- WHERE a.TRADE_CODE=? `
- o := orm.NewOrm()
- o.Using("edb")
- err = o.Raw(sql, tradeCode).QueryRow(&count)
- return
- }
- type TargetDeleteReq struct {
- TradeCode string `description:"指标唯一编码"`
- }
- func TargetDelete(tradeCode string) (err error) {
- o := orm.NewOrm()
- o.Using("edb")
- sql := " DELETE FROM edbinfo WHERE TRADE_CODE = ? "
- _, err = o.Raw(sql, tradeCode).Exec()
- return
- }
- type Researcher struct {
- AdminId int `description:"系统用户id"`
- AdminName string `description:"系统用户名称"`
- RealName string `description:"系统用户姓名"`
- Role string `description:"系统用户角色"`
- Mobile string `description:"手机号"`
- TargetCount int `description:"指标数量"`
- }
- type ResearcherListResp struct {
- List []*Researcher
- }
- func GetResearcherEntry() (items []*Researcher, err error) {
- sql := ` SELECT admin_id,admin_name,real_name,mobile,0 as target_count FROM admin WHERE role='researcher' AND role_type=1 `
- o := orm.NewOrm()
- o.Using("edb")
- _, err = o.Raw(sql).QueryRows(&items)
- researchLen := len(items)
- for i := 0; i < researchLen; i++ {
- var count int
- mobile := items[i].Mobile
- sqlCount := ` SELECT COUNT(DISTINCT a.TRADE_CODE) AS count FROM edbinfo_user AS a
- INNER JOIN edbinfo AS b ON a.TRADE_CODE=b.TRADE_CODE
- WHERE a.mobile=? AND LEFT(b.TRADE_CODE,1)='W' AND b.REMARK='手动' AND b.classify_id>0 `
- err = o.Raw(sqlCount, mobile).QueryRow(&count)
- items[i].TargetCount = count
- }
- return
- }
- type EdbinfoItems struct {
- TradeCode string `orm:"column(TRADE_CODE);pk" description:"指标code"`
- SecName string `orm:"column(SEC_NAME);" description:"指标名称"`
- Unit string `orm:"column(UNIT);" description:"单位"`
- Remark string `orm:"column(REMARK);" description:"备注"`
- Frequency string `description:"频度"`
- ClassifyId int `description:"分类id"`
- ClassifyName string `description:"分类名称"`
- CreateDate string `description:"创建时间"`
- UserId int `description:"录入用户id"`
- NoticeTime string `description:"通知时间"`
- Mobile string `description:"录入者手机号"`
- ModifyDate string `description:"待更新日期"`
- Status string `description:"状态:未完成/完成"`
- }
- type TargetItemsResp struct {
- List SortEdbInfo
- }
- type SortEdbInfo []EdbinfoItems
- func GetTargetItems(mobile string) (lastItems SortEdbInfo, err error) {
- var items []*EdbinfoItems
- o := orm.NewOrm()
- o.Using("edb")
- sql := ` SELECT *,'' modify_date,'' status FROM edbinfo AS a WHERE LEFT(a.TRADE_CODE,1)='W' AND a.REMARK='手动' AND a.classify_id>0 `
- if mobile != "" {
- sql = ` SELECT *,'' modify_date,'' status FROM edbinfo AS a
- INNER JOIN edbinfo_user AS b ON a.TRADE_CODE=b.TRADE_CODE
- WHERE LEFT(a.TRADE_CODE,1)='W' AND a.REMARK='手动' AND a.classify_id>0
- AND b.mobile='` + mobile + `'`
- }
- sql = sql + ` ORDER BY CONVERT(a.SEC_NAME USING gbk ) COLLATE gbk_chinese_ci ASC `
- _, err = o.Raw(sql).QueryRows(&items)
- if err != nil {
- return
- }
- itemsLen := len(items)
- nowWeek := time.Now().Weekday().String()
- fmt.Println(nowWeek)
- finishEdbInfo := SortEdbInfo{}
- unFinishEdbInfo := SortEdbInfo{}
- for i := 0; i < itemsLen; i++ {
- noticeTime := items[i].NoticeTime
- frequency := items[i].Frequency
- tradeCode := items[i].TradeCode
- if noticeTime != "" {
- if frequency == "周度" {
- noticeArr := strings.Split(noticeTime, " ")
- noticeWeek := noticeArr[0]
- fmt.Println(noticeWeek)
- addDay := 0
- if nowWeek == "Sunday" {
- if noticeWeek == "周日" {
- addDay = 0
- } else if noticeWeek == "周一" {
- addDay = 1
- } else if noticeWeek == "周二" {
- addDay = 2
- } else if noticeWeek == "周三" {
- addDay = 3
- } else if noticeWeek == "周四" {
- addDay = 4
- } else if noticeWeek == "周五" {
- addDay = 5
- } else if noticeWeek == "周六" {
- addDay = 6
- } else {
- addDay = 0
- }
- } else if nowWeek == "Monday" {
- if noticeWeek == "周日" {
- addDay = 6
- } else if noticeWeek == "周一" {
- addDay = 0
- } else if noticeWeek == "周二" {
- addDay = 1
- } else if noticeWeek == "周三" {
- addDay = 2
- } else if noticeWeek == "周四" {
- addDay = 3
- } else if noticeWeek == "周五" {
- addDay = 4
- } else if noticeWeek == "周六" {
- addDay = 5
- } else {
- addDay = 0
- }
- } else if nowWeek == "Tuesday" {
- if noticeWeek == "周日" {
- addDay = 5
- } else if noticeWeek == "周一" {
- addDay = 6
- } else if noticeWeek == "周二" {
- addDay = 0
- } else if noticeWeek == "周三" {
- addDay = 1
- } else if noticeWeek == "周四" {
- addDay = 2
- } else if noticeWeek == "周五" {
- addDay = 3
- } else if noticeWeek == "周六" {
- addDay = 4
- } else {
- addDay = 0
- }
- } else if nowWeek == "Wednesday" {
- if noticeWeek == "周日" {
- addDay = 4
- } else if noticeWeek == "周一" {
- addDay = 5
- } else if noticeWeek == "周二" {
- addDay = 6
- } else if noticeWeek == "周三" {
- addDay = 0
- } else if noticeWeek == "周四" {
- addDay = 1
- } else if noticeWeek == "周五" {
- addDay = 2
- } else if noticeWeek == "周六" {
- addDay = 3
- } else {
- addDay = 0
- }
- } else if nowWeek == "Thursday" {
- if noticeWeek == "周日" {
- addDay = 3
- } else if noticeWeek == "周一" {
- addDay = 4
- } else if noticeWeek == "周二" {
- addDay = 5
- } else if noticeWeek == "周三" {
- addDay = 6
- } else if noticeWeek == "周四" {
- addDay = 0
- } else if noticeWeek == "周五" {
- addDay = 1
- } else if noticeWeek == "周六" {
- addDay = 2
- } else {
- addDay = 0
- }
- } else if nowWeek == "Friday" {
- if noticeWeek == "周日" {
- addDay = 2
- } else if noticeWeek == "周一" {
- addDay = 3
- } else if noticeWeek == "周二" {
- addDay = 4
- } else if noticeWeek == "周三" {
- addDay = 5
- } else if noticeWeek == "周四" {
- addDay = 6
- } else if noticeWeek == "周五" {
- addDay = 0
- } else if noticeWeek == "周六" {
- addDay = 1
- } else {
- addDay = 0
- }
- } else if nowWeek == "Saturday" {
- if noticeWeek == "周日" {
- addDay = 1
- } else if noticeWeek == "周一" {
- addDay = 2
- } else if noticeWeek == "周二" {
- addDay = 3
- } else if noticeWeek == "周三" {
- addDay = 4
- } else if noticeWeek == "周四" {
- addDay = 5
- } else if noticeWeek == "周五" {
- addDay = 6
- } else if noticeWeek == "周六" {
- addDay = 0
- } else {
- addDay = 0
- }
- }
- modifyDate := time.Now().AddDate(0, 0, addDay)
- modifyDateStr := modifyDate.Format(utils.FormatDate)
- items[i].ModifyDate = modifyDateStr
- modifyDateEndStr := modifyDate.AddDate(0, 0, -7).Format(utils.FormatDate)
- fmt.Println("addDay:", addDay)
- fmt.Println("modifyDateEndStr:", modifyDateEndStr)
- count := 0
- sqlCount := ` SELECT COUNT(1) AS num FROM edbdata WHERE TRADE_CODE=? AND DT >= ? AND DT <= ? `
- err = o.Raw(sqlCount, tradeCode, modifyDateEndStr, modifyDateStr).QueryRow(&count)
- if err != nil {
- return nil, err
- }
- if count > 0 {
- items[i].Status = "完成"
- finishEdbInfo = append(finishEdbInfo, *items[i])
- } else {
- items[i].Status = "未完成"
- unFinishEdbInfo = append(unFinishEdbInfo, *items[i])
- }
- }
- } else {
- items[i].Status = "完成"
- finishEdbInfo = append(finishEdbInfo, *items[i])
- }
- }
- sort.Sort(SortByModifyDate{finishEdbInfo})
- sort.Sort(SortByModifyDate{unFinishEdbInfo})
- lastItems = append(lastItems, unFinishEdbInfo...)
- lastItems = append(lastItems, finishEdbInfo...)
- return
- }
- //获取此 slice 的长度
- func (p SortEdbInfo) Len() int { return len(p) }
- // 根据元素的状态降序排序
- func (p SortEdbInfo) Less(i, j int) bool {
- return p[i].Status > p[j].Status
- }
- // 交换数据
- func (p SortEdbInfo) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
- // 嵌套结构体 将继承 SortEdbInfo 的所有属性和方法
- // 所以相当于SortByName 也实现了 Len() 和 Swap() 方法
- type SortByStatus struct{ SortEdbInfo }
- // 根据元素的姓名长度降序排序 (此处按照自己的业务逻辑写)
- func (p SortByStatus) Less(i, j int) bool {
- return len(p.SortEdbInfo[i].Status) > len(p.SortEdbInfo[j].Status)
- }
- type SortByModifyDate struct{ SortEdbInfo }
- // 根据元素的年龄降序排序 (此处按照自己的业务逻辑写)
- func (p SortByModifyDate) Less(i, j int) bool {
- return p.SortEdbInfo[i].ModifyDate > p.SortEdbInfo[j].ModifyDate
- }
|