mysql.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  1. package dao
  2. import (
  3. "context"
  4. rsql "database/sql"
  5. "fmt"
  6. "strings"
  7. "go-common/app/service/main/account-recovery/dao/sqlbuilder"
  8. "go-common/app/service/main/account-recovery/model"
  9. "go-common/library/database/sql"
  10. "go-common/library/log"
  11. xtime "go-common/library/time"
  12. "go-common/library/xstr"
  13. )
  14. const (
  15. _selectCountRecoveryInfo = "select count(rid) from account_recovery_info"
  16. _selectRecoveryInfoLimit = "select rid,mid,user_type,status,login_addrs,unames,reg_time,reg_type,reg_addr,pwds,phones,emails,safe_question,safe_answer,card_type,card_id," +
  17. "sys_login_addrs,sys_reg,sys_unames,sys_pwds,sys_phones,sys_emails,sys_safe,sys_card," +
  18. "link_email,operator,opt_time,remark,ctime,business from account_recovery_info %s"
  19. _getSuccessCount = "SELECT count FROM account_recovery_success WHERE mid=?"
  20. _batchGetRecoverySuccess = "SELECT mid,count,ctime,mtime FROM account_recovery_success WHERE mid in (%s)"
  21. _updateSuccessCount = "INSERT INTO account_recovery_success (mid, count) VALUES (?, 1) ON DUPLICATE KEY UPDATE count = count + 1"
  22. _batchUpdateSuccessCount = "INSERT INTO account_recovery_success (mid, count) VALUES %s ON DUPLICATE KEY UPDATE count = count + 1"
  23. _updateStatus = "UPDATE account_recovery_info SET status=?,operator=?,opt_time=?,remark=? WHERE rid = ? AND `status`=0"
  24. _getNoDeal = "SELECT COUNT(1) FROM account_recovery_info WHERE mid=? AND `status`=0"
  25. _updateUserType = "UPDATE account_recovery_info SET user_type=? WHERE rid = ?"
  26. _insertRecoveryInfo = "INSERT INTO account_recovery_info(login_addrs,unames,reg_time,reg_type,reg_addr,pwds,phones,emails,safe_question,safe_answer,card_type,card_id,link_email,mid,business,last_suc_count,last_suc_ctime) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
  27. _updateSysInfo = "UPDATE account_recovery_info SET sys_login_addrs=?,sys_reg=?,sys_unames=?,sys_pwds=?,sys_phones=?,sys_emails=?,sys_safe=?,sys_card=?,user_type=? WHERE rid=?"
  28. _getUinfoByRid = "SELECT mid,link_email,ctime FROM account_recovery_info WHERE rid=? LIMIT 1"
  29. _getUinfoByRidMore = "SELECT rid,mid,link_email,ctime FROM account_recovery_info WHERE rid in (%s)"
  30. _selectUnCheckInfo = "SELECT mid,login_addrs,unames,reg_time,reg_type,reg_addr,pwds,phones,emails,safe_question,safe_answer,card_type,card_id FROM account_recovery_info WHERE rid=? AND `status`=0 AND sys_card=''"
  31. _getStatusByRid = "SELECT `status` FROM account_recovery_info WHERE rid=?"
  32. _getMailStatus = "SELECT mail_status FROM account_recovery_info WHERE rid=?"
  33. _updateMailStatus = "UPDATE account_recovery_info SET mail_status=1 WHERE rid=?"
  34. _insertRecoveryAddit = "INSERT INTO account_recovery_addit(`rid`, `files`, `extra`) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE files=VALUES(files),extra=VALUES(extra)"
  35. _updateRecoveryAddit = "UPDATE account_recovery_addit SET `files` = ?,`extra` = ? WHERE rid = ?"
  36. _getRecoveryAddit = "SELECT rid, `files`,`extra`, ctime, mtime FROM account_recovery_addit WHERE rid= ?"
  37. _batchRecoveryAAdit = "SELECT rid, `files`, `extra`, ctime, mtime FROM account_recovery_addit WHERE rid in (%s)"
  38. _batchGetLastSuccess = "SELECT mid,max(ctime) FROM account_recovery_info WHERE mid in (%s) AND `status`=1 GROUP BY mid"
  39. _getLastSuccess = "SELECT mid,max(ctime) FROM account_recovery_info WHERE mid = ? AND `status`=1"
  40. )
  41. // GetStatusByRid get status by rid
  42. func (dao *Dao) GetStatusByRid(c context.Context, rid int64) (status int64, err error) {
  43. res := dao.db.Prepared(_getStatusByRid).QueryRow(c, rid)
  44. if err = res.Scan(&status); err != nil {
  45. if err == sql.ErrNoRows {
  46. status = -1
  47. err = nil
  48. } else {
  49. log.Error("GetStatusByRid row.Scan error(%v)", err)
  50. }
  51. }
  52. return
  53. }
  54. // GetSuccessCount get success count
  55. func (dao *Dao) GetSuccessCount(c context.Context, mid int64) (count int64, err error) {
  56. res := dao.db.Prepared(_getSuccessCount).QueryRow(c, mid)
  57. if err = res.Scan(&count); err != nil {
  58. if err == sql.ErrNoRows {
  59. count = 0
  60. err = nil
  61. } else {
  62. log.Error("GetSuccessCount row.Scan error(%v)", err)
  63. }
  64. }
  65. return
  66. }
  67. // BatchGetRecoverySuccess batch get recovery success info
  68. func (dao *Dao) BatchGetRecoverySuccess(c context.Context, mids []int64) (successMap map[int64]*model.RecoverySuccess, err error) {
  69. rows, err := dao.db.Query(c, fmt.Sprintf(_batchGetRecoverySuccess, xstr.JoinInts(mids)))
  70. if err != nil {
  71. if err == sql.ErrNoRows {
  72. err = nil
  73. return
  74. }
  75. log.Error("BatchGetRecoverySuccess d.db.Query error(%v)", err)
  76. return
  77. }
  78. successMap = make(map[int64]*model.RecoverySuccess)
  79. for rows.Next() {
  80. r := new(model.RecoverySuccess)
  81. if err = rows.Scan(&r.SuccessMID, &r.SuccessCount, &r.FirstSuccessTime, &r.LastSuccessTime); err != nil {
  82. log.Error("BatchGetRecoverySuccess rows.Scan error(%v)", err)
  83. continue
  84. }
  85. successMap[r.SuccessMID] = r
  86. }
  87. return
  88. }
  89. // UpdateSuccessCount insert or update success count
  90. func (dao *Dao) UpdateSuccessCount(c context.Context, mid int64) (err error) {
  91. _, err = dao.db.Exec(c, _updateSuccessCount, mid)
  92. return
  93. }
  94. // BatchUpdateSuccessCount batch insert or update success count
  95. func (dao *Dao) BatchUpdateSuccessCount(c context.Context, mids string) (err error) {
  96. var s string
  97. midArr := strings.Split(mids, ",")
  98. for _, mid := range midArr {
  99. s = s + fmt.Sprintf(",(%s, 1)", mid)
  100. }
  101. _, err = dao.db.Exec(c, fmt.Sprintf(_batchUpdateSuccessCount, s[1:]))
  102. return
  103. }
  104. // GetNoDeal get no deal record
  105. func (dao *Dao) GetNoDeal(c context.Context, mid int64) (count int64, err error) {
  106. res := dao.db.Prepared(_getNoDeal).QueryRow(c, mid)
  107. if err = res.Scan(&count); err != nil {
  108. if err == sql.ErrNoRows {
  109. err = nil
  110. return
  111. }
  112. log.Error("GetNoDeal row.Scan error(%v)", err)
  113. return
  114. }
  115. return
  116. }
  117. // UpdateStatus update field status.
  118. func (dao *Dao) UpdateStatus(c context.Context, status int64, rid int64, operator string, optTime xtime.Time, remark string) (err error) {
  119. _, err = dao.db.Exec(c, _updateStatus, status, operator, optTime, remark, rid)
  120. return
  121. }
  122. // UpdateUserType update field user_type.
  123. func (dao *Dao) UpdateUserType(c context.Context, status int64, rid int64) (err error) {
  124. if _, err = dao.db.Exec(c, _updateUserType, status, rid); err != nil {
  125. log.Error("dao.db.Exec(%s, %d, %d) error(%v)", _updateUserType, status, rid, err)
  126. }
  127. return
  128. }
  129. // InsertRecoveryInfo insert data
  130. func (dao *Dao) InsertRecoveryInfo(c context.Context, uinfo *model.UserInfoReq) (lastID int64, err error) {
  131. var res rsql.Result
  132. if res, err = dao.db.Exec(c, _insertRecoveryInfo, uinfo.LoginAddrs, uinfo.Unames, uinfo.RegTime, uinfo.RegType, uinfo.RegAddr,
  133. uinfo.Pwds, uinfo.Phones, uinfo.Emails, uinfo.SafeQuestion, uinfo.SafeAnswer, uinfo.CardType, uinfo.CardID, uinfo.LinkMail, uinfo.Mid, uinfo.Business, uinfo.LastSucCount, uinfo.LastSucCTime); err != nil {
  134. log.Error("dao.db.Exec(%s, %v) error(%v)", _insertRecoveryInfo, uinfo, err)
  135. return
  136. }
  137. return res.LastInsertId()
  138. }
  139. // UpdateSysInfo update sysinfo and user_type
  140. func (dao *Dao) UpdateSysInfo(c context.Context, sys *model.SysInfo, userType int64, rid int64) (err error) {
  141. if _, err = dao.db.Exec(c, _updateSysInfo, &sys.SysLoginAddrs, &sys.SysReg, &sys.SysUNames, &sys.SysPwds, &sys.SysPhones,
  142. &sys.SysEmails, &sys.SysSafe, &sys.SysCard, userType, rid); err != nil {
  143. log.Error("dao.db.Exec(%s, %v) error(%v)", _updateSysInfo, sys, err)
  144. }
  145. return
  146. }
  147. // GetAllByCon get a pageData by more condition
  148. func (dao *Dao) GetAllByCon(c context.Context, aq *model.QueryRecoveryInfoReq) ([]*model.AccountRecoveryInfo, int64, error) {
  149. query := sqlbuilder.NewSelectBuilder().Select("rid,mid,user_type,status,login_addrs,unames,reg_time,reg_type,reg_addr,pwds,phones,emails,safe_question,safe_answer,card_type,card_id,sys_login_addrs,sys_reg,sys_unames,sys_pwds,sys_phones,sys_emails,sys_safe,sys_card,link_email,operator,opt_time,remark,ctime,business,last_suc_count,last_suc_ctime").From("account_recovery_info")
  150. if aq.Bussiness != "" {
  151. query = query.Where(query.Equal("business", aq.Bussiness))
  152. }
  153. if aq.Status != nil {
  154. query = query.Where(fmt.Sprintf("status=%d", *aq.Status))
  155. }
  156. if aq.Game != nil {
  157. query = query.Where(fmt.Sprintf("user_type=%d", *aq.Game))
  158. }
  159. if aq.UID != 0 {
  160. query = query.Where(fmt.Sprintf("mid=%d", aq.UID))
  161. }
  162. if aq.RID != 0 {
  163. query = query.Where(fmt.Sprintf("rid=%d", aq.RID))
  164. }
  165. if aq.StartTime != 0 {
  166. query = query.Where(query.GE("ctime", aq.StartTime.Time()))
  167. }
  168. if aq.EndTime != 0 {
  169. query = query.Where(query.LE("ctime", aq.EndTime.Time()))
  170. }
  171. totalSQL, totalArg := query.Copy().Select("count(1)").Build()
  172. log.Info("Build GetAllByCon total count SQL: %s", totalSQL)
  173. page := aq.Page
  174. if page == 0 {
  175. page = 1
  176. }
  177. size := aq.Size
  178. if size == 0 {
  179. size = 50
  180. }
  181. query = query.Limit(int(size)).Offset(int(size * (page - 1))).OrderBy("rid DESC")
  182. rawSQL, rawArg := query.Build()
  183. log.Info("Build GetAllByCon SQL: %s", rawSQL)
  184. total := int64(0)
  185. row := dao.db.QueryRow(c, totalSQL, totalArg...)
  186. if err := row.Scan(&total); err != nil {
  187. return nil, 0, err
  188. }
  189. rows, err := dao.db.Query(c, rawSQL, rawArg...)
  190. if err != nil {
  191. return nil, 0, err
  192. }
  193. defer rows.Close()
  194. resultData := make([]*model.AccountRecoveryInfo, 0)
  195. for rows.Next() {
  196. r := new(model.AccountRecoveryInfo)
  197. if err = rows.Scan(&r.Rid, &r.Mid, &r.UserType, &r.Status, &r.LoginAddr, &r.UNames, &r.RegTime, &r.RegType, &r.RegAddr,
  198. &r.Pwd, &r.Phones, &r.Emails, &r.SafeQuestion, &r.SafeAnswer, &r.CardType, &r.CardID,
  199. &r.SysLoginAddr, &r.SysReg, &r.SysUNames, &r.SysPwds, &r.SysPhones, &r.SysEmails, &r.SysSafe, &r.SysCard,
  200. &r.LinkEmail, &r.Operator, &r.OptTime, &r.Remark, &r.CTime, &r.Bussiness, &r.LastSucCount, &r.LastSucCTime); err != nil {
  201. log.Error("GetAllByCon error (%+v)", err)
  202. continue
  203. }
  204. resultData = append(resultData, r)
  205. }
  206. return resultData, total, err
  207. }
  208. // QueryByID query by rid
  209. func (dao *Dao) QueryByID(c context.Context, rid int64, fromTime, endTime xtime.Time) (res *model.AccountRecoveryInfo, err error) {
  210. sql1 := "select rid,mid,user_type,status,login_addrs,unames,reg_time,reg_type,reg_addr,pwds,phones,emails,safe_question,safe_answer,card_type,card_id," +
  211. "sys_login_addrs,sys_reg,sys_unames,sys_pwds,sys_phones,sys_emails,sys_safe,sys_card," +
  212. "link_email,operator,opt_time,remark,ctime,business from account_recovery_info where ctime between ? and ? and rid = ?"
  213. res = new(model.AccountRecoveryInfo)
  214. row := dao.db.QueryRow(c, sql1, fromTime, endTime, rid)
  215. if err = row.Scan(&res.Rid, &res.Mid, &res.UserType, &res.Status, &res.LoginAddr, &res.UNames, &res.RegTime, &res.RegType, &res.RegAddr,
  216. &res.Pwd, &res.Phones, &res.Emails, &res.SafeQuestion, &res.SafeAnswer, &res.CardType, &res.CardID,
  217. &res.SysLoginAddr, &res.SysReg, &res.SysUNames, &res.SysPwds, &res.SysPhones, &res.SysEmails, &res.SysSafe, &res.SysCard,
  218. &res.LinkEmail, &res.Operator, &res.OptTime, &res.Remark, &res.CTime, &res.Bussiness); err != nil {
  219. if err == sql.ErrNoRows {
  220. err = nil
  221. res = nil
  222. return
  223. }
  224. log.Error("QueryByID(%d) error(%v)", rid, err)
  225. return
  226. }
  227. return
  228. }
  229. //QueryInfoByLimit page query through limit m,n
  230. func (dao *Dao) QueryInfoByLimit(c context.Context, req *model.DBRecoveryInfoParams) (res []*model.AccountRecoveryInfo, total int64, err error) {
  231. p := make([]interface{}, 0)
  232. s := " where ctime between ? and ?"
  233. p = append(p, req.StartTime)
  234. p = append(p, req.EndTime)
  235. if req.ExistGame {
  236. s = s + " and user_type = ?"
  237. p = append(p, req.Game)
  238. }
  239. if req.ExistStatus {
  240. s = s + " and status = ?"
  241. p = append(p, req.Status)
  242. }
  243. if req.ExistMid {
  244. s = s + " and mid = ?"
  245. p = append(p, req.Mid)
  246. }
  247. var s2 = s + " order by rid desc limit ?,?"
  248. p2 := p
  249. p2 = append(p2, (req.CurrPage-1)*req.Size, req.Size)
  250. var rows *sql.Rows
  251. rows, err = dao.db.Query(c, fmt.Sprintf(_selectRecoveryInfoLimit, s2), p2...)
  252. if err != nil {
  253. if err == sql.ErrNoRows {
  254. err = nil
  255. return
  256. }
  257. log.Error("QueryInfo err: d.db.Query error(%v)", err)
  258. return
  259. }
  260. defer rows.Close()
  261. res = make([]*model.AccountRecoveryInfo, 0, req.Size)
  262. for rows.Next() {
  263. r := new(model.AccountRecoveryInfo)
  264. if err = rows.Scan(&r.Rid, &r.Mid, &r.UserType, &r.Status, &r.LoginAddr, &r.UNames, &r.RegTime, &r.RegType, &r.RegAddr,
  265. &r.Pwd, &r.Phones, &r.Emails, &r.SafeQuestion, &r.SafeAnswer, &r.CardType, &r.CardID,
  266. &r.SysLoginAddr, &r.SysReg, &r.SysUNames, &r.SysPwds, &r.SysPhones, &r.SysEmails, &r.SysSafe, &r.SysCard,
  267. &r.LinkEmail, &r.Operator, &r.OptTime, &r.Remark, &r.CTime, &r.Bussiness); err != nil {
  268. log.Error("QueryInfo (%v) error (%v)", req, err)
  269. return
  270. }
  271. res = append(res, r)
  272. }
  273. row := dao.db.QueryRow(c, _selectCountRecoveryInfo+s, p...)
  274. if err = row.Scan(&total); err != nil {
  275. log.Error("QueryInfo total error (%v)", err)
  276. return
  277. }
  278. return
  279. }
  280. // GetUinfoByRid get mid,linkMail by rid
  281. func (dao *Dao) GetUinfoByRid(c context.Context, rid int64) (mid int64, linkMail string, ctime string, err error) {
  282. res := dao.db.Prepared(_getUinfoByRid).QueryRow(c, rid)
  283. req := new(struct {
  284. Mid int64
  285. LinKMail string
  286. Ctime xtime.Time
  287. })
  288. if err = res.Scan(&req.Mid, &req.LinKMail, &req.Ctime); err != nil {
  289. if err == sql.ErrNoRows {
  290. req.Mid = 0
  291. err = nil
  292. } else {
  293. log.Error("GetUinfoByRid row.Scan error(%v)", err)
  294. }
  295. }
  296. mid = req.Mid
  297. linkMail = req.LinKMail
  298. ctime = req.Ctime.Time().Format("2006-01-02 15:04:05")
  299. return
  300. }
  301. // GetUinfoByRidMore get list of BatchAppeal by rid
  302. func (dao *Dao) GetUinfoByRidMore(c context.Context, ridsStr string) (bathRes []*model.BatchAppeal, err error) {
  303. rows, err := dao.db.Prepared(fmt.Sprintf(_getUinfoByRidMore, ridsStr)).Query(c)
  304. if err != nil {
  305. return nil, err
  306. }
  307. defer rows.Close()
  308. bathRes = make([]*model.BatchAppeal, 0, len(strings.Split(ridsStr, ",")))
  309. for rows.Next() {
  310. req := &model.BatchAppeal{}
  311. if err = rows.Scan(&req.Rid, &req.Mid, &req.LinkMail, &req.Ctime); err != nil {
  312. return
  313. }
  314. bathRes = append(bathRes, req)
  315. }
  316. return
  317. }
  318. // GetUnCheckInfo get uncheck info
  319. func (dao *Dao) GetUnCheckInfo(c context.Context, rid int64) (r *model.UserInfoReq, err error) {
  320. row := dao.db.QueryRow(c, _selectUnCheckInfo, rid)
  321. r = new(model.UserInfoReq)
  322. if err = row.Scan(&r.Mid, &r.LoginAddrs, &r.Unames, &r.RegTime, &r.RegType, &r.RegAddr,
  323. &r.Pwds, &r.Phones, &r.Emails, &r.SafeQuestion, &r.SafeAnswer, &r.CardType, &r.CardID); err != nil {
  324. if err == sql.ErrNoRows {
  325. err = nil
  326. return
  327. }
  328. log.Error("GetUnCheckInfo (%v) error (%v)", rid, err)
  329. }
  330. return
  331. }
  332. //BeginTran begin transaction
  333. func (dao *Dao) BeginTran(ctx context.Context) (tx *sql.Tx, err error) {
  334. if tx, err = dao.db.Begin(ctx); err != nil {
  335. log.Error("db: begintran BeginTran d.db.Begin error(%v)", err)
  336. }
  337. return
  338. }
  339. // GetMailStatus get mail_status by rid
  340. func (dao *Dao) GetMailStatus(c context.Context, rid int64) (mailStatus int64, err error) {
  341. res := dao.db.Prepared(_getMailStatus).QueryRow(c, rid)
  342. if err = res.Scan(&mailStatus); err != nil {
  343. if err == sql.ErrNoRows {
  344. mailStatus = -1
  345. err = nil
  346. } else {
  347. log.Error("GetStatusByRid row.Scan error(%v)", err)
  348. }
  349. }
  350. return
  351. }
  352. // UpdateMailStatus update mail_status.
  353. func (dao *Dao) UpdateMailStatus(c context.Context, rid int64) (err error) {
  354. _, err = dao.db.Exec(c, _updateMailStatus, rid)
  355. return
  356. }
  357. // UpdateRecoveryAddit is
  358. func (dao *Dao) UpdateRecoveryAddit(c context.Context, rid int64, files []string, extra string) (err error) {
  359. _, err = dao.db.Exec(c, _updateRecoveryAddit, strings.Join(files, ","), extra, rid)
  360. return
  361. }
  362. // GetRecoveryAddit is
  363. func (dao *Dao) GetRecoveryAddit(c context.Context, rid int64) (addit *model.DBAccountRecoveryAddit, err error) {
  364. row := dao.db.QueryRow(c, _getRecoveryAddit, rid)
  365. addit = new(model.DBAccountRecoveryAddit)
  366. if err = row.Scan(&addit.Rid, &addit.Files, &addit.Extra, &addit.Ctime, &addit.Mtime); err != nil {
  367. if err == sql.ErrNoRows {
  368. err = nil
  369. return
  370. }
  371. log.Error("GetRecoveryAddit (%v) error (%v)", rid, err)
  372. }
  373. return
  374. }
  375. // InsertRecoveryAddit is
  376. func (dao *Dao) InsertRecoveryAddit(c context.Context, rid int64, files, extra string) (err error) {
  377. _, err = dao.db.Exec(c, _insertRecoveryAddit, rid, files, extra)
  378. return
  379. }
  380. //BatchGetRecoveryAddit is
  381. func (dao *Dao) BatchGetRecoveryAddit(c context.Context, rids []int64) (addits map[int64]*model.DBAccountRecoveryAddit, err error) {
  382. rows, err := dao.db.Query(c, fmt.Sprintf(_batchRecoveryAAdit, xstr.JoinInts(rids)))
  383. if err != nil {
  384. if err == sql.ErrNoRows {
  385. err = nil
  386. return
  387. }
  388. log.Error("BatchGetRecoveryAddit d.db.Query error(%v)", err)
  389. return
  390. }
  391. defer rows.Close()
  392. addits = make(map[int64]*model.DBAccountRecoveryAddit)
  393. for rows.Next() {
  394. var addit = new(model.DBAccountRecoveryAddit)
  395. if err = rows.Scan(&addit.Rid, &addit.Files, &addit.Extra, &addit.Ctime, &addit.Mtime); err != nil {
  396. log.Error("BatchGetRecoveryAddit rows.Scan error(%v)", err)
  397. continue
  398. }
  399. addits[addit.Rid] = addit
  400. }
  401. return
  402. }
  403. // BatchGetLastSuccess batch get last find success info
  404. func (dao *Dao) BatchGetLastSuccess(c context.Context, mids []int64) (lastSuccessMap map[int64]*model.LastSuccessData, err error) {
  405. rows, err := dao.db.Query(c, fmt.Sprintf(_batchGetLastSuccess, xstr.JoinInts(mids)))
  406. if err != nil {
  407. if err == sql.ErrNoRows {
  408. err = nil
  409. return
  410. }
  411. log.Error("BatchGetLastSuccess d.db.Query error(%v)", err)
  412. return
  413. }
  414. defer rows.Close()
  415. lastSuccessMap = make(map[int64]*model.LastSuccessData)
  416. for rows.Next() {
  417. r := new(model.LastSuccessData)
  418. if err = rows.Scan(&r.LastApplyMID, &r.LastApplyTime); err != nil {
  419. log.Error("BatchGetLastSuccess rows.Scan error(%v)", err)
  420. continue
  421. }
  422. lastSuccessMap[r.LastApplyMID] = r
  423. }
  424. return
  425. }
  426. // GetLastSuccess get last find success info
  427. func (dao *Dao) GetLastSuccess(c context.Context, mid int64) (lastSuc *model.LastSuccessData, err error) {
  428. row := dao.db.QueryRow(c, _getLastSuccess, mid)
  429. lastSuc = new(model.LastSuccessData)
  430. if err = row.Scan(&lastSuc.LastApplyMID, &lastSuc.LastApplyTime); err != nil {
  431. if err == sql.ErrNoRows {
  432. err = nil
  433. return
  434. }
  435. log.Error("GetRecoveryAddit (%v) error (%v)", mid, err)
  436. }
  437. return
  438. }