Investigation.go
2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package Api
import (
"encoding/json"
"github.com/aarongao/tools"
"github.com/gin-gonic/gin"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo/options"
"letu/DB"
"math"
"strconv"
)
// @Title 增加调查
// @Description 问券调查 - 增加调查
// @Accept json
// @Produce json
// @Param UserId 1111111 string true "UserId"
// @Param Mobile 18616619599 string true "联系电话"
// @Param type 1 string true "类型"
// @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":"ok"}"
// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
// @Router /Investigation/Save? [post]
func SaveInvestigation(c *gin.Context) {
c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
c.Header("Access-Control-Allow-Credentials", "true")
var Data map[string]interface{}
json.Unmarshal([]byte(c.PostForm("Data")), &Data)
DB.CInvestigation.InsertOne(tools.GetContext(),DB.SInvestigation{
c.PostForm("UserId"),
c.PostForm("Mobile"),
Data,
})
c.JSON(200, tools.ResponseSeccess{
0,
"ok",
})
}
// @Title 查询所有问券调查
// @Description 问券调查 - 查询所有问券调查
// @Accept json
// @Produce json
// @Param Page 1 int true "当前第几页"
// @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"total":1,"currpage":1,"totalpages":1,"prepage":20,"result":}"
// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
// @Router /Investigation/List? [get]
func AllInvestigation(c *gin.Context) {
c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
c.Header("Access-Control-Allow-Credentials", "true")
total,_ := DB.CComplaint.CountDocuments(tools.GetContext(), bson.M{})
limit, _ := strconv.ParseInt(c.Query("Limit"),10,64)
if limit == 0 {
limit = 50
}
currPage, _ := strconv.ParseInt(c.Query("Page"),10,64)
if currPage == 0 {
currPage = 1
}
skip := (currPage - 1) * limit
var aInvestigation []DB.SInvestigation
cur, err := DB.CInvestigation.Find(tools.GetContext(), bson.M{}, &options.FindOptions{Limit: &limit, Skip: &skip, Sort: bson.M{"_id": -1}})
defer cur.Close(tools.GetContext())
if err == nil {
for cur.Next(tools.GetContext()) {
var e DB.SInvestigation
cur.Decode(&e)
aInvestigation = append(aInvestigation,e)
}
}
c.JSON(200, tools.Page{
0,
total,
currPage,
int(math.Ceil(float64(total) / float64(limit))),
limit,
aInvestigation,
})
}