123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- package http
- import (
- "encoding/json"
- "fmt"
- "go-common/app/service/main/upcredit/model/calculator"
- "go-common/app/service/main/upcredit/model/upcrmmodel"
- "go-common/app/service/main/upcredit/service"
- "go-common/library/ecode"
- "go-common/library/log"
- "go-common/library/net/http/blademaster"
- "io/ioutil"
- "time"
- )
- func logCredit(c *blademaster.Context) {
- var data interface{}
- var err error
- var errMsg string
- var r = new(upcrmmodel.ArgCreditLogAdd)
- switch {
- default:
- var body, _ = ioutil.ReadAll(c.Request.Body)
- if err = json.Unmarshal(body, r); err != nil {
- log.Error("request argument json decode fail, err=%v", err)
- errMsg = fmt.Sprintf("wrong argument, %s, body={%s}", err.Error(), string(body))
- err = ecode.RequestErr
- break
- }
- err = Svc.LogCredit(c, r)
- }
- if err != nil {
- service.BmHTTPErrorWithMsg(c, err, errMsg)
- } else {
- c.JSON(data, err)
- }
- }
- func recalc(c *blademaster.Context) {
- var data interface{}
- var err error
- var errMsg string
- var r = new(struct {
- TableNum int `form:"tablenum"`
- CalcDate string `form:"date"`
- AllTable bool `form:"all_table" default:"false"`
- })
- switch {
- default:
- if err = c.Bind(r); err != nil {
- log.Error("param error")
- err = ecode.RequestErr
- break
- }
- var calc = calculator.New(Svc.CreditScoreInputChan)
- var date = time.Time{}
- if r.CalcDate != "" {
- date, _ = time.Parse("2006-01-02", r.CalcDate)
- } else {
- date = time.Now()
- }
- if r.AllTable {
- Svc.CalcSvc.AddCalcJob(date)
- } else {
- go calc.CalcLogTable(r.TableNum, date, nil)
- }
- log.Info("start calculate process, req=%+v", r)
- }
- if err != nil {
- service.BmHTTPErrorWithMsg(c, err, errMsg)
- } else {
- c.JSON(data, err)
- }
- }
- func scoreGet(c *blademaster.Context) {
- var data interface{}
- var err error
- var errMsg string
- var r = new(upcrmmodel.ArgMidDate)
- switch {
- default:
- if err = c.Bind(r); err != nil {
- log.Error("param error")
- err = ecode.RequestErr
- break
- }
- var arg = upcrmmodel.GetScoreParam{
- Mid: r.Mid,
- ScoreType: r.ScoreType,
- }
- var now = time.Now()
- if r.Days > 60 {
- r.Days = 60
- }
- if r.FromDate != "" {
- arg.FromDate, err = time.Parse(upcrmmodel.DateStr, r.FromDate)
- if err != nil {
- errMsg = err.Error()
- err = ecode.RequestErr
- break
- }
- }
- if r.ToDate != "" {
- arg.ToDate, err = time.Parse(upcrmmodel.DateStr, r.FromDate)
- if err != nil {
- errMsg = err.Error()
- err = ecode.RequestErr
- break
- }
- }
- if r.Days != 0 {
- var y, m, d = now.Date()
- arg.ToDate = time.Date(y, m, d, 0, 0, 0, 0, now.Location())
- arg.FromDate = arg.ToDate.AddDate(0, 0, -r.Days)
- }
- var result, e = Svc.GetCreditScore(c, &arg)
- err = e
- if err != nil {
- log.Error("fail to get credit score, req=%+v, err=%+v", arg, err)
- break
- }
- data = map[string]interface{}{
- "score_list": result,
- }
- log.Info("get credit score, req=%+v, datalen=%d", r, len(result))
- }
- if err != nil {
- service.BmHTTPErrorWithMsg(c, err, errMsg)
- } else {
- c.JSON(data, err)
- }
- }
- func logGet(c *blademaster.Context) {
- var data interface{}
- var err error
- var errMsg string
- var r = new(upcrmmodel.ArgGetLogHistory)
- switch {
- default:
- if err = c.Bind(r); err != nil {
- log.Error("param error")
- errMsg = "param error"
- err = ecode.RequestErr
- break
- }
- var result, e = Svc.GetCreditLog(c, r)
- err = e
- if err != nil {
- errMsg = err.Error()
- log.Error("fail to get credit log, req=%+v, err=%+v", r, err)
- break
- }
- data = map[string]interface{}{
- "log_list": result,
- }
- log.Info("get credit log ok, req=%+v, datalen=%d", r, len(result))
- }
- if err != nil {
- service.BmHTTPErrorWithMsg(c, err, errMsg)
- } else {
- c.JSON(data, err)
- }
- }
- func calcSection(c *blademaster.Context) {
- var data interface{}
- var err error
- var errMsg string
- var r = new(struct {
- CalcDate string `form:"date"`
- })
- switch {
- default:
- if err = c.Bind(r); err != nil {
- log.Error("param error")
- err = ecode.RequestErr
- break
- }
- var date = time.Time{}
- if r.CalcDate != "" {
- date, _ = time.Parse("2006-01-02", r.CalcDate)
- } else {
- date = time.Now().AddDate(0, 0, -1)
- }
- var job = &service.CalcStatisticJob{
- ID: 1,
- Date: date,
- Svc: Svc.CalcSvc,
- }
- Svc.CalcSvc.JobChannel <- job
- log.Info("start calculate process, req=%+v, job=%+v", r, job)
- }
- if err != nil {
- service.BmHTTPErrorWithMsg(c, err, errMsg)
- } else {
- c.JSON(data, err)
- }
- }
- func test(c *blademaster.Context) {
- Svc.Test()
- }
|