瀏覽代碼

PayIn list wit new filter

master
sp 4 年之前
父節點
當前提交
d52fc8c5cf
共有 5 個文件被更改,包括 59 次插入9 次删除
  1. +37
    -0
      apiV1PayInList.go
  2. +2
    -2
      apiV1Uploads.go
  3. +6
    -0
      apiv1.go
  4. +5
    -0
      html/index.html
  5. +9
    -7
      payIn-AAA.go

+ 37
- 0
apiV1PayInList.go 查看文件

@@ -0,0 +1,37 @@
package main

import (
"biukop.com/sfm/loan"
"encoding/json"
log "github.com/sirupsen/logrus"
"net/http"
)

func decodePayInFilter(r *http.Request) (ret loan.PayInListFilter, e error) {
decoder := json.NewDecoder(r.Body)
//decoder.DisallowUnknownFields()
e = decoder.Decode(&ret)
if e != nil {
log.Error("failed decoding PayIn list filter", e.Error())
return
}
return
}

func apiV1PayInList(w http.ResponseWriter, r *http.Request, ss *loan.Session) {
filter, e := decodePayInFilter(r)
if e != nil {
log.Error("invalid pay in list filter", filter, e)
apiV1Client404Error(w, r, ss)
return
}

ret, e := filter.RetrieveData()
if e != nil {
log.Error("failed to retrieve PayIn list", filter, e)
apiV1Server500Error(w, r)
return
}

apiV1SendJson(ret, w, r, ss)
}

+ 2
- 2
apiV1Uploads.go 查看文件

@@ -242,7 +242,7 @@ func apiV1UploadAsImage(w http.ResponseWriter, r *http.Request, ss *loan.Session
if e != nil {
return
}
//time.Sleep(5* time.Second);
// if this is image itself, serve it directly
if strings.Contains(strings.ToLower(ul.Upload.Format), "image") {
f, e := os.Open(ul.filePath())
@@ -336,7 +336,7 @@ func apiV1UploadAsPDF(w http.ResponseWriter, r *http.Request, ss *loan.Session)
if forceHttpDownload(r) {
w.Header().Set("Content-Disposition", "attachment; filename="+ul.Upload.FileName)
}
http.ServeContent(w, r, ul.filePath(), fi.ModTime(), f)
http.ServeContent(w, r, ul.Upload.FileName, fi.ModTime(), f)
return
}
}

+ 6
- 0
apiv1.go 查看文件

@@ -66,8 +66,11 @@ func setupApiV1Handler() []apiV1HandlerMap {
{"GET", "people-list/", apiV1PeopleList},
{"GET", "broker-list/", apiV1BrokerList},
{"POST", "sync-people/", apiV1SyncPeople},

{"POST", "payIn/", apiV1PayInPost},
{"DELETE", "payIn/", apiV1PayInDelete},
{"POST", "pay-in-list/", apiV1PayInList},

{"GET", "user-reward/", apiV1UserReward},
{"GET", "login-available/", apiV1LoginAvailable},

@@ -124,8 +127,11 @@ func setupApiV1Handler() []apiV1HandlerMap {
{"GET", "people-list", apiV1PeopleList},
{"GET", "broker-list/", apiV1BrokerList},
{"POST", "sync-people/", apiV1SyncPeople},

{"POST", "payIn/", apiV1PayInPost},
{"DELETE", "payIn/", apiV1PayInDelete},
{"POST", "pay-in-list/", apiV1PayInList},

{"GET", "user-reward/", apiV1UserReward},
{"GET", "login-available/", apiV1LoginAvailable},


+ 5
- 0
html/index.html 查看文件

@@ -59,6 +59,11 @@
<p id="socketOutPut"></p>
</div>

<!--<script type="text/javascript">-->
<!-- setTimeout(function(){-->
<!-- location.reload();-->
<!-- },1000)-->
<!--</script>-->

</body>


+ 9
- 7
payIn-AAA.go 查看文件

@@ -42,7 +42,7 @@ func (m *AiDecodeIncome) decodeAAAPdf(raw string) (e error) {
m.AAA = make([]PayInAAAPeriod, 0, 10)
lines := strings.Split(raw, "\n")

currentDecoder := PayInAAAPeriod{}
var currentDecoder *PayInAAAPeriod = nil
state := "start"
for _, l := range lines { // DFA, wow, finally it's used. after years of learning
switch state {
@@ -55,25 +55,27 @@ func (m *AiDecodeIncome) decodeAAAPdf(raw string) (e error) {
case "LookingForPeriod":
state = currentDecoder.processPeriod(l)
if state == "LookingForRows" {
currentDecoder.Period, e = currentDecoder.getPeriod(l)
currentDecoder.Rows = make([]PayInAAARow, 0, 10)
Period, e := currentDecoder.getPeriod(l)
if e != nil {
log.Warn("cannot find period", l, e)
state = "LookingForPeriod"
} else {
m.AAA = append(m.AAA, currentDecoder)

m.AAA = append(m.AAA, PayInAAAPeriod{})
idx := len(m.AAA) - 1
currentDecoder = &(m.AAA[idx])
currentDecoder.Rows = make([]PayInAAARow, 0, 10)
currentDecoder.Period = Period
}
}
break
case "LookingForRows", "LookingForRowsSkipCurrent":
nextState, row, valid := currentDecoder.processRow(l)
if valid {
if valid && currentDecoder != nil {
currentDecoder.Rows = append(currentDecoder.Rows, row)
}
state = nextState
if nextState == "start" {
currentDecoder = PayInAAAPeriod{} //renew to a empty state
currentDecoder = nil //renew to a empty state
}
break
}

Loading…
取消
儲存