正在显示
40 个修改的文件
包含
4792 行增加
和
0 行删除
.gitignore
0 → 100644
Dockerfile
0 → 100644
1 | +FROM golang:1.13 as build | ||
2 | + | ||
3 | +ENV GOPROXY https://goproxy.cn | ||
4 | +ENV GO111MODULE on | ||
5 | + | ||
6 | +WORKDIR /go/ability | ||
7 | + | ||
8 | +ADD go.mod . | ||
9 | +ADD go.sum . | ||
10 | +RUN go mod download | ||
11 | + | ||
12 | +RUN GOOS=linux CGO_ENABLED=0 go build -ldflags="-s -w" -installsuffix cgo -o examples_gocomm main.go | ||
13 | + | ||
14 | +CMD ["/ability"] |
conf/app.conf
0 → 100644
conf/dev.conf
0 → 100644
conf/prod.conf
0 → 100644
controllers/v1/default.go
0 → 100644
1 | +package v1 | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/mybeego" | ||
5 | +) | ||
6 | + | ||
7 | +type MainController struct { | ||
8 | + mybeego.BaseController | ||
9 | +} | ||
10 | + | ||
11 | +// URLMapping ... | ||
12 | +func (this *MainController) URLMapping() { | ||
13 | + //this.Mapping("Get", this.Get) | ||
14 | + //this.Mapping("Hello", this.Hello) | ||
15 | +} | ||
16 | + | ||
17 | +func (c *MainController) Get() { | ||
18 | + c.Data["Website"] = "beego.me" | ||
19 | + c.Data["Email"] = "astaxie@gmail.com" | ||
20 | + c.TplName = "index.tpl" | ||
21 | +} | ||
22 | + | ||
23 | + |
controllers/v1/user.go
0 → 100644
1 | +package v1 | ||
2 | + | ||
3 | +import ( | ||
4 | + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/mybeego" | ||
5 | +) | ||
6 | + | ||
7 | +type UserController struct { | ||
8 | + mybeego.BaseController | ||
9 | +} | ||
10 | + | ||
11 | +//匹配的是路由 | ||
12 | +// 127.0.0.1:8080/user/login/* | ||
13 | +//127.0.0.1:8080/user/logout/* | ||
14 | + | ||
15 | +func(this *UserController)URLMapping(){ | ||
16 | + //this.Mapping("/v1/user/login",this.Login) | ||
17 | + //this.Mapping("/v1/user/select",this.SelectUser) | ||
18 | +} | ||
19 | + | ||
20 | +// Login | ||
21 | +// @Title Login | ||
22 | +// @Description 登录 | ||
23 | +// @Param body body string true "body" | ||
24 | +// @router /v1/user/login [post] | ||
25 | +func(this *UserController)Login(){ | ||
26 | + var msg *mybeego.Message | ||
27 | + defer func(){ | ||
28 | + this.Resp(msg) | ||
29 | + }() | ||
30 | + msg = mybeego.NewErrMessage(0,"login success") | ||
31 | +} | ||
32 | + | ||
33 | +func(this *UserController)Logout(){ | ||
34 | + var msg *mybeego.Message | ||
35 | + defer func(){ | ||
36 | + this.Resp(msg) | ||
37 | + }() | ||
38 | + msg = mybeego.NewErrMessage(0,"logout success") | ||
39 | +} |
docker-compose.yaml
0 → 100644
1 | +version: '3.1' #指定docker-compose 版本 | ||
2 | + | ||
3 | +services: | ||
4 | + redis: | ||
5 | + image: redis #使用 镜像 | ||
6 | + container_name: gocomm_redis | ||
7 | + command: redis-server /usr/local/etc/redis/redis.conf | ||
8 | + ports: # | ||
9 | + - 6379:6379 | ||
10 | + volumes: | ||
11 | + - ./data:/data | ||
12 | + - ./redis.conf:/usr/local/etc/redis/redis.conf | ||
13 | + db: | ||
14 | + #构建mysql镜像 | ||
15 | + image: mysql | ||
16 | + container_name: gocomm-mysql # 容器名 | ||
17 | + command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci #设置utf8字符集 | ||
18 | + restart: always | ||
19 | + environment: | ||
20 | + MYSQL_ROOT_PASSWORD: 123456 #root管理员用户密码 | ||
21 | + MYSQL_USER: test #创建test用户 | ||
22 | + MYSQL_PASSWORD: 123456 #设置test用户的密码 | ||
23 | + ports: | ||
24 | + - 3306:3306 #host物理直接映射端口为6606 | ||
25 | + volumes: | ||
26 | + #mysql数据库挂载到host物理机目录/e/docker/mysql/data/db | ||
27 | + - "/docker/mysql/data/db:/var/lib/mysql" | ||
28 | + #容器的配置目录挂载到host物理机目录/e/docker/mysql/data/conf | ||
29 | + - "/docker/mysql/data/conf:/etc/mysql/conf.d" | ||
30 | + ability: #定义服务名称 | ||
31 | + build: ./ #引入了 build 的路径,它指向一个存有 Dockerfile 的目录 | ||
32 | + ports: # | ||
33 | + - 8081:8081 | ||
34 | + environment: | ||
35 | + RUNMODULE: "PROD" |
go.mod
0 → 100644
1 | +module gitlab.fjmaimaimai.com/mmm-go/ability | ||
2 | + | ||
3 | +go 1.12 | ||
4 | + | ||
5 | +require ( | ||
6 | + github.com/astaxie/beego v1.10.0 | ||
7 | + github.com/go-sql-driver/mysql v1.4.1 | ||
8 | + github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337 | ||
9 | + gitlab.fjmaimaimai.com/mmm-go/gocomm v0.0.1 | ||
10 | + google.golang.org/appengine v1.6.2 // indirect | ||
11 | +) | ||
12 | + | ||
13 | +replace gitlab.fjmaimaimai.com/mmm-go/gocomm => ../gocomm |
go.sum
0 → 100644
1 | +cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= | ||
2 | +github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= | ||
3 | +github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= | ||
4 | +github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= | ||
5 | +github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0= | ||
6 | +github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8= | ||
7 | +github.com/astaxie/beego v1.10.0 h1:s0OZ1iUO0rl8+lwWZfPK/0GhQi1tFUcIClTevyz48Pg= | ||
8 | +github.com/astaxie/beego v1.10.0/go.mod h1:0R4++1tUqERR0WYFWdfkcrsyoVBCG4DgpDGokT3yb+U= | ||
9 | +github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= | ||
10 | +github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= | ||
11 | +github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc= | ||
12 | +github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= | ||
13 | +github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI= | ||
14 | +github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk= | ||
15 | +github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= | ||
16 | +github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= | ||
17 | +github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= | ||
18 | +github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= | ||
19 | +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
20 | +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
21 | +github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= | ||
22 | +github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no= | ||
23 | +github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= | ||
24 | +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= | ||
25 | +github.com/garyburd/redigo v1.6.0 h1:0VruCpn7yAIIu7pWVClQC8wxCJEcG3nyzpMSHKi1PQc= | ||
26 | +github.com/garyburd/redigo v1.6.0/go.mod h1:NR3MbYisc3/PwhQ00EMzDiPmrwpPxAn5GI05/YaO1SY= | ||
27 | +github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= | ||
28 | +github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3 h1:t8FVkw33L+wilf2QiWkw0UV77qRpcH/JHPKGpKa2E8g= | ||
29 | +github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3/go.mod h1:VJ0WA2NBN22VlZ2dKZQPAPnyWw5XTlK1KymzLKsr59s= | ||
30 | +github.com/gin-gonic/gin v1.4.0 h1:3tMoCCfM7ppqsR0ptz/wi1impNpT7/9wQtMZ8lr1mCQ= | ||
31 | +github.com/gin-gonic/gin v1.4.0/go.mod h1:OW2EZn3DO8Ln9oIKOvM++LBO+5UPHJJDH72/q/3rZdM= | ||
32 | +github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= | ||
33 | +github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE= | ||
34 | +github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= | ||
35 | +github.com/go-sql-driver/mysql v1.4.1 h1:g24URVg0OFbNUTx9qqY1IRZ9D9z3iPyi5zKhQZpNwpA= | ||
36 | +github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= | ||
37 | +github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= | ||
38 | +github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= | ||
39 | +github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4= | ||
40 | +github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= | ||
41 | +github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= | ||
42 | +github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= | ||
43 | +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= | ||
44 | +github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg= | ||
45 | +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= | ||
46 | +github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ= | ||
47 | +github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= | ||
48 | +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8= | ||
49 | +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= | ||
50 | +github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ= | ||
51 | +github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= | ||
52 | +github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs= | ||
53 | +github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= | ||
54 | +github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY= | ||
55 | +github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4= | ||
56 | +github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ= | ||
57 | +github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo= | ||
58 | +github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU= | ||
59 | +github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo= | ||
60 | +github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU= | ||
61 | +github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w= | ||
62 | +github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q= | ||
63 | +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= | ||
64 | +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= | ||
65 | +github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= | ||
66 | +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= | ||
67 | +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= | ||
68 | +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= | ||
69 | +github.com/lib/pq v1.2.0 h1:LXpIM/LZ5xGFhOpXAQUIMM1HdyqzVYM13zNdjCEEcA0= | ||
70 | +github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= | ||
71 | +github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY= | ||
72 | +github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= | ||
73 | +github.com/mattn/go-isatty v0.0.7 h1:UvyT9uN+3r7yLEYSlJsbQGdsaB/a0DlgWP3pql6iwOc= | ||
74 | +github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= | ||
75 | +github.com/mattn/go-sqlite3 v1.11.0 h1:LDdKkqtYlom37fkvqs8rMPFKAMe8+SgjbwZ6ex1/A/Q= | ||
76 | +github.com/mattn/go-sqlite3 v1.11.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= | ||
77 | +github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= | ||
78 | +github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE= | ||
79 | +github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y= | ||
80 | +github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= | ||
81 | +github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= | ||
82 | +github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= | ||
83 | +github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= | ||
84 | +github.com/opentracing-contrib/go-stdlib v0.0.0-20190519235532-cf7a6c988dc9/go.mod h1:PLldrQSroqzH70Xl+1DQcGnefIbqsKR7UDaiux3zV+w= | ||
85 | +github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= | ||
86 | +github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc= | ||
87 | +github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= | ||
88 | +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= | ||
89 | +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
90 | +github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= | ||
91 | +github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso= | ||
92 | +github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= | ||
93 | +github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= | ||
94 | +github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro= | ||
95 | +github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4= | ||
96 | +github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk= | ||
97 | +github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA= | ||
98 | +github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= | ||
99 | +github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg= | ||
100 | +github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo= | ||
101 | +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM= | ||
102 | +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc= | ||
103 | +github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337 h1:WN9BUFbdyOsSH/XohnWpXOlq9NBD5sGAB2FciQMUEe8= | ||
104 | +github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA= | ||
105 | +github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM= | ||
106 | +github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA= | ||
107 | +github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI= | ||
108 | +github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= | ||
109 | +github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8= | ||
110 | +github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= | ||
111 | +github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk= | ||
112 | +github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= | ||
113 | +github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg= | ||
114 | +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= | ||
115 | +github.com/spf13/viper v1.4.0 h1:yXHLWeravcrgGyFSyCgdYpXQ9dR9c/WED3pg1RhxqEU= | ||
116 | +github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE= | ||
117 | +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
118 | +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
119 | +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= | ||
120 | +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= | ||
121 | +github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= | ||
122 | +github.com/uber-go/atomic v1.4.0/go.mod h1:/Ct5t2lcmbJ4OSe/waGBoaVvVqtO0bmtfVNex1PFV8g= | ||
123 | +github.com/uber/jaeger-client-go v2.16.0+incompatible/go.mod h1:WVhlPFC8FDjOFMMWRy2pZqQJSXxYSwNYOkTr/Z6d3Kk= | ||
124 | +github.com/uber/jaeger-lib v2.0.0+incompatible/go.mod h1:ComeNDZlWwrWnDv8aPp0Ba6+uUTzImX/AauajbLI56U= | ||
125 | +github.com/ugorji/go v1.1.4 h1:j4s+tAvLfL3bZyefP2SEWmhBzmuIlH/eqNuPdFPgngw= | ||
126 | +github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc= | ||
127 | +github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= | ||
128 | +github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= | ||
129 | +github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= | ||
130 | +github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q= | ||
131 | +go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= | ||
132 | +go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= | ||
133 | +go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0= | ||
134 | +go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= | ||
135 | +golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= | ||
136 | +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M= | ||
137 | +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= | ||
138 | +golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5 h1:58fnuSXlxZmFdJyvtTFVmVhcMLU6v5fEb/ok4wyqtNU= | ||
139 | +golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= | ||
140 | +golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= | ||
141 | +golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= | ||
142 | +golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= | ||
143 | +golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= | ||
144 | +golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= | ||
145 | +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= | ||
146 | +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= | ||
147 | +golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= | ||
148 | +golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= | ||
149 | +golang.org/x/net v0.0.0-20190603091049-60506f45cf65 h1:+rhAzEzT3f4JtomfC371qB+0Ola2caSKcY69NUBZrRQ= | ||
150 | +golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= | ||
151 | +golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= | ||
152 | +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | ||
153 | +golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | ||
154 | +golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | ||
155 | +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | ||
156 | +golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||
157 | +golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||
158 | +golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||
159 | +golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||
160 | +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||
161 | +golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||
162 | +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
163 | +golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
164 | +golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= | ||
165 | +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= | ||
166 | +golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs= | ||
167 | +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= | ||
168 | +golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= | ||
169 | +golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= | ||
170 | +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= | ||
171 | +golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= | ||
172 | +golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= | ||
173 | +golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= | ||
174 | +golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc= | ||
175 | +google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= | ||
176 | +google.golang.org/appengine v1.6.2 h1:j8RI1yW0SkI+paT6uGwMlrMI/6zwYA6/CFil8rxOzGI= | ||
177 | +google.golang.org/appengine v1.6.2/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= | ||
178 | +google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= | ||
179 | +google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= | ||
180 | +google.golang.org/grpc v1.21.0/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= | ||
181 | +gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= | ||
182 | +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= | ||
183 | +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
184 | +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
185 | +gopkg.in/go-playground/assert.v1 v1.2.1/go.mod h1:9RXL0bg/zibRAgZUYszZSwO/z8Y/a8bDuhia5mkpMnE= | ||
186 | +gopkg.in/go-playground/validator.v8 v8.18.2 h1:lFB4DoMU6B626w8ny76MV7VX6W2VHct2GVOI3xgiMrQ= | ||
187 | +gopkg.in/go-playground/validator.v8 v8.18.2/go.mod h1:RX2a/7Ha8BgOhfk7j780h4/u/RRjR0eouCJSH80/M2Y= | ||
188 | +gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo= | ||
189 | +gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74= | ||
190 | +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= | ||
191 | +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= | ||
192 | +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= | ||
193 | +honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= |
main.go
0 → 100644
1 | +package main | ||
2 | + | ||
3 | +import ( | ||
4 | + "github.com/astaxie/beego" | ||
5 | + _ "gitlab.fjmaimaimai.com/mmm-go/ability/routers" | ||
6 | + "gitlab.fjmaimaimai.com/mmm-go/gocomm/config" | ||
7 | + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" | ||
8 | + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/orm" | ||
9 | + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/redis" | ||
10 | + _ "github.com/go-sql-driver/mysql" | ||
11 | +) | ||
12 | + | ||
13 | +func init(){ | ||
14 | + log.InitLog(config.Logger{ | ||
15 | + Filename:"app.log", | ||
16 | + Level:"7", | ||
17 | + }) | ||
18 | + err:= redis.InitWithDb(100,beego.AppConfig.String("redis_add_port"),beego.AppConfig.String("redis_auth"),"0") | ||
19 | + if err!=nil{ | ||
20 | + log.Fatal(err) | ||
21 | + } | ||
22 | + orm.NewBeeormEngine(config.Mysql{ | ||
23 | + DataSource:beego.AppConfig.String("data_source"), | ||
24 | + MaxIdle: 100, | ||
25 | + MaxOpen:100, | ||
26 | + }) | ||
27 | +} | ||
28 | + | ||
29 | +func main() { | ||
30 | + defer func(){ | ||
31 | + log.Info("app on stop!") | ||
32 | + }() | ||
33 | + beego.Run() | ||
34 | +} | ||
35 | + |
models/announcement.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "errors" | ||
5 | + "fmt" | ||
6 | + "reflect" | ||
7 | + "strings" | ||
8 | + "time" | ||
9 | + | ||
10 | + "github.com/astaxie/beego/orm" | ||
11 | +) | ||
12 | + | ||
13 | +type Announcement struct { | ||
14 | + Id int `orm:"column(id);pk" description:"主键ID"` | ||
15 | + CreateTime time.Time `orm:"column(createTime);type(timestamp);auto_now_add" description:"创建时间"` | ||
16 | + Content string `orm:"column(content);size(500)" description:"消息标题"` | ||
17 | + CompanyId int64 `orm:"column(company_id);null"` | ||
18 | + Day string `orm:"column(day);size(20)" description:"日期"` | ||
19 | +} | ||
20 | + | ||
21 | +func (t *Announcement) TableName() string { | ||
22 | + return "announcement" | ||
23 | +} | ||
24 | + | ||
25 | +func init() { | ||
26 | + orm.RegisterModel(new(Announcement)) | ||
27 | +} | ||
28 | + | ||
29 | +// AddAnnouncement insert a new Announcement into database and returns | ||
30 | +// last inserted Id on success. | ||
31 | +func AddAnnouncement(m *Announcement) (id int64, err error) { | ||
32 | + o := orm.NewOrm() | ||
33 | + id, err = o.Insert(m) | ||
34 | + return | ||
35 | +} | ||
36 | + | ||
37 | +// GetAnnouncementById retrieves Announcement by Id. Returns error if | ||
38 | +// Id doesn't exist | ||
39 | +func GetAnnouncementById(id int) (v *Announcement, err error) { | ||
40 | + o := orm.NewOrm() | ||
41 | + v = &Announcement{Id: id} | ||
42 | + if err = o.Read(v); err == nil { | ||
43 | + return v, nil | ||
44 | + } | ||
45 | + return nil, err | ||
46 | +} | ||
47 | + | ||
48 | +// GetAllAnnouncement retrieves all Announcement matches certain condition. Returns empty list if | ||
49 | +// no records exist | ||
50 | +func GetAllAnnouncement(query map[string]string, fields []string, sortby []string, order []string, | ||
51 | + offset int64, limit int64) (ml []interface{}, err error) { | ||
52 | + o := orm.NewOrm() | ||
53 | + qs := o.QueryTable(new(Announcement)) | ||
54 | + // query k=v | ||
55 | + for k, v := range query { | ||
56 | + // rewrite dot-notation to Object__Attribute | ||
57 | + k = strings.Replace(k, ".", "__", -1) | ||
58 | + if strings.Contains(k, "isnull") { | ||
59 | + qs = qs.Filter(k, (v == "true" || v == "1")) | ||
60 | + } else { | ||
61 | + qs = qs.Filter(k, v) | ||
62 | + } | ||
63 | + } | ||
64 | + // order by: | ||
65 | + var sortFields []string | ||
66 | + if len(sortby) != 0 { | ||
67 | + if len(sortby) == len(order) { | ||
68 | + // 1) for each sort field, there is an associated order | ||
69 | + for i, v := range sortby { | ||
70 | + orderby := "" | ||
71 | + if order[i] == "desc" { | ||
72 | + orderby = "-" + v | ||
73 | + } else if order[i] == "asc" { | ||
74 | + orderby = v | ||
75 | + } else { | ||
76 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
77 | + } | ||
78 | + sortFields = append(sortFields, orderby) | ||
79 | + } | ||
80 | + qs = qs.OrderBy(sortFields...) | ||
81 | + } else if len(sortby) != len(order) && len(order) == 1 { | ||
82 | + // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
83 | + for _, v := range sortby { | ||
84 | + orderby := "" | ||
85 | + if order[0] == "desc" { | ||
86 | + orderby = "-" + v | ||
87 | + } else if order[0] == "asc" { | ||
88 | + orderby = v | ||
89 | + } else { | ||
90 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
91 | + } | ||
92 | + sortFields = append(sortFields, orderby) | ||
93 | + } | ||
94 | + } else if len(sortby) != len(order) && len(order) != 1 { | ||
95 | + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
96 | + } | ||
97 | + } else { | ||
98 | + if len(order) != 0 { | ||
99 | + return nil, errors.New("Error: unused 'order' fields") | ||
100 | + } | ||
101 | + } | ||
102 | + | ||
103 | + var l []Announcement | ||
104 | + qs = qs.OrderBy(sortFields...) | ||
105 | + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
106 | + if len(fields) == 0 { | ||
107 | + for _, v := range l { | ||
108 | + ml = append(ml, v) | ||
109 | + } | ||
110 | + } else { | ||
111 | + // trim unused fields | ||
112 | + for _, v := range l { | ||
113 | + m := make(map[string]interface{}) | ||
114 | + val := reflect.ValueOf(v) | ||
115 | + for _, fname := range fields { | ||
116 | + m[fname] = val.FieldByName(fname).Interface() | ||
117 | + } | ||
118 | + ml = append(ml, m) | ||
119 | + } | ||
120 | + } | ||
121 | + return ml, nil | ||
122 | + } | ||
123 | + return nil, err | ||
124 | +} | ||
125 | + | ||
126 | +// UpdateAnnouncement updates Announcement by Id and returns error if | ||
127 | +// the record to be updated doesn't exist | ||
128 | +func UpdateAnnouncementById(m *Announcement) (err error) { | ||
129 | + o := orm.NewOrm() | ||
130 | + v := Announcement{Id: m.Id} | ||
131 | + // ascertain id exists in the database | ||
132 | + if err = o.Read(&v); err == nil { | ||
133 | + var num int64 | ||
134 | + if num, err = o.Update(m); err == nil { | ||
135 | + fmt.Println("Number of records updated in database:", num) | ||
136 | + } | ||
137 | + } | ||
138 | + return | ||
139 | +} | ||
140 | + | ||
141 | +// DeleteAnnouncement deletes Announcement by Id and returns error if | ||
142 | +// the record to be deleted doesn't exist | ||
143 | +func DeleteAnnouncement(id int) (err error) { | ||
144 | + o := orm.NewOrm() | ||
145 | + v := Announcement{Id: id} | ||
146 | + // ascertain id exists in the database | ||
147 | + if err = o.Read(&v); err == nil { | ||
148 | + var num int64 | ||
149 | + if num, err = o.Delete(&Announcement{Id: id}); err == nil { | ||
150 | + fmt.Println("Number of records deleted in database:", num) | ||
151 | + } | ||
152 | + } | ||
153 | + return | ||
154 | +} |
models/bonus_point.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "errors" | ||
5 | + "fmt" | ||
6 | + "reflect" | ||
7 | + "strings" | ||
8 | + "time" | ||
9 | + | ||
10 | + "github.com/astaxie/beego/orm" | ||
11 | +) | ||
12 | + | ||
13 | +type BonusPoint struct { | ||
14 | + Id int `orm:"column(id);pk"` | ||
15 | + CompanyId int `orm:"column(company_id)" description:"公司ID"` | ||
16 | + Type int8 `orm:"column(type)" description:"加分类型 0发现 1分析 2解决"` | ||
17 | + Uid int64 `orm:"column(uid)" description:"被加分人"` | ||
18 | + Score int `orm:"column(score)" description:"加分数值"` | ||
19 | + JoinDate time.Time `orm:"column(join_date);type(date)" description:"加入年月"` | ||
20 | + OperatorId int64 `orm:"column(operator_id)" description:"加分人(操作者id)"` | ||
21 | + Reason string `orm:"column(reason);size(500);null" description:"加分理由"` | ||
22 | + CreateTime time.Time `orm:"column(createTime);type(timestamp);auto_now_add"` | ||
23 | + UpdateTime time.Time `orm:"column(updateTime);type(timestamp);auto_now_add"` | ||
24 | +} | ||
25 | + | ||
26 | +func (t *BonusPoint) TableName() string { | ||
27 | + return "bonus_point" | ||
28 | +} | ||
29 | + | ||
30 | +func init() { | ||
31 | + orm.RegisterModel(new(BonusPoint)) | ||
32 | +} | ||
33 | + | ||
34 | +// AddBonusPoint insert a new BonusPoint into database and returns | ||
35 | +// last inserted Id on success. | ||
36 | +func AddBonusPoint(m *BonusPoint) (id int64, err error) { | ||
37 | + o := orm.NewOrm() | ||
38 | + id, err = o.Insert(m) | ||
39 | + return | ||
40 | +} | ||
41 | + | ||
42 | +// GetBonusPointById retrieves BonusPoint by Id. Returns error if | ||
43 | +// Id doesn't exist | ||
44 | +func GetBonusPointById(id int) (v *BonusPoint, err error) { | ||
45 | + o := orm.NewOrm() | ||
46 | + v = &BonusPoint{Id: id} | ||
47 | + if err = o.Read(v); err == nil { | ||
48 | + return v, nil | ||
49 | + } | ||
50 | + return nil, err | ||
51 | +} | ||
52 | + | ||
53 | +// GetAllBonusPoint retrieves all BonusPoint matches certain condition. Returns empty list if | ||
54 | +// no records exist | ||
55 | +func GetAllBonusPoint(query map[string]string, fields []string, sortby []string, order []string, | ||
56 | + offset int64, limit int64) (ml []interface{}, err error) { | ||
57 | + o := orm.NewOrm() | ||
58 | + qs := o.QueryTable(new(BonusPoint)) | ||
59 | + // query k=v | ||
60 | + for k, v := range query { | ||
61 | + // rewrite dot-notation to Object__Attribute | ||
62 | + k = strings.Replace(k, ".", "__", -1) | ||
63 | + if strings.Contains(k, "isnull") { | ||
64 | + qs = qs.Filter(k, (v == "true" || v == "1")) | ||
65 | + } else { | ||
66 | + qs = qs.Filter(k, v) | ||
67 | + } | ||
68 | + } | ||
69 | + // order by: | ||
70 | + var sortFields []string | ||
71 | + if len(sortby) != 0 { | ||
72 | + if len(sortby) == len(order) { | ||
73 | + // 1) for each sort field, there is an associated order | ||
74 | + for i, v := range sortby { | ||
75 | + orderby := "" | ||
76 | + if order[i] == "desc" { | ||
77 | + orderby = "-" + v | ||
78 | + } else if order[i] == "asc" { | ||
79 | + orderby = v | ||
80 | + } else { | ||
81 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
82 | + } | ||
83 | + sortFields = append(sortFields, orderby) | ||
84 | + } | ||
85 | + qs = qs.OrderBy(sortFields...) | ||
86 | + } else if len(sortby) != len(order) && len(order) == 1 { | ||
87 | + // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
88 | + for _, v := range sortby { | ||
89 | + orderby := "" | ||
90 | + if order[0] == "desc" { | ||
91 | + orderby = "-" + v | ||
92 | + } else if order[0] == "asc" { | ||
93 | + orderby = v | ||
94 | + } else { | ||
95 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
96 | + } | ||
97 | + sortFields = append(sortFields, orderby) | ||
98 | + } | ||
99 | + } else if len(sortby) != len(order) && len(order) != 1 { | ||
100 | + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
101 | + } | ||
102 | + } else { | ||
103 | + if len(order) != 0 { | ||
104 | + return nil, errors.New("Error: unused 'order' fields") | ||
105 | + } | ||
106 | + } | ||
107 | + | ||
108 | + var l []BonusPoint | ||
109 | + qs = qs.OrderBy(sortFields...) | ||
110 | + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
111 | + if len(fields) == 0 { | ||
112 | + for _, v := range l { | ||
113 | + ml = append(ml, v) | ||
114 | + } | ||
115 | + } else { | ||
116 | + // trim unused fields | ||
117 | + for _, v := range l { | ||
118 | + m := make(map[string]interface{}) | ||
119 | + val := reflect.ValueOf(v) | ||
120 | + for _, fname := range fields { | ||
121 | + m[fname] = val.FieldByName(fname).Interface() | ||
122 | + } | ||
123 | + ml = append(ml, m) | ||
124 | + } | ||
125 | + } | ||
126 | + return ml, nil | ||
127 | + } | ||
128 | + return nil, err | ||
129 | +} | ||
130 | + | ||
131 | +// UpdateBonusPoint updates BonusPoint by Id and returns error if | ||
132 | +// the record to be updated doesn't exist | ||
133 | +func UpdateBonusPointById(m *BonusPoint) (err error) { | ||
134 | + o := orm.NewOrm() | ||
135 | + v := BonusPoint{Id: m.Id} | ||
136 | + // ascertain id exists in the database | ||
137 | + if err = o.Read(&v); err == nil { | ||
138 | + var num int64 | ||
139 | + if num, err = o.Update(m); err == nil { | ||
140 | + fmt.Println("Number of records updated in database:", num) | ||
141 | + } | ||
142 | + } | ||
143 | + return | ||
144 | +} | ||
145 | + | ||
146 | +// DeleteBonusPoint deletes BonusPoint by Id and returns error if | ||
147 | +// the record to be deleted doesn't exist | ||
148 | +func DeleteBonusPoint(id int) (err error) { | ||
149 | + o := orm.NewOrm() | ||
150 | + v := BonusPoint{Id: id} | ||
151 | + // ascertain id exists in the database | ||
152 | + if err = o.Read(&v); err == nil { | ||
153 | + var num int64 | ||
154 | + if num, err = o.Delete(&BonusPoint{Id: id}); err == nil { | ||
155 | + fmt.Println("Number of records deleted in database:", num) | ||
156 | + } | ||
157 | + } | ||
158 | + return | ||
159 | +} |
models/bulletin.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "errors" | ||
5 | + "fmt" | ||
6 | + "reflect" | ||
7 | + "strings" | ||
8 | + "time" | ||
9 | + | ||
10 | + "github.com/astaxie/beego/orm" | ||
11 | +) | ||
12 | + | ||
13 | +type Bulletin struct { | ||
14 | + Id int `orm:"column(id);auto"` | ||
15 | + Title string `orm:"column(title);size(2000);null" description:"标题"` | ||
16 | + Content string `orm:"column(content);null" description:"内容"` | ||
17 | + Cover string `orm:"column(cover);size(255);null" description:"封面地址"` | ||
18 | + W int `orm:"column(w);null" description:"宽"` | ||
19 | + H int `orm:"column(h);null" description:"高"` | ||
20 | + Type int8 `orm:"column(type);null" description:"公告类型(0图+跳转链接、1链接)"` | ||
21 | + Receiver string `orm:"column(receiver);null" description:"接收者"` | ||
22 | + QuestionSwitch int8 `orm:"column(question_switch);null" description:"设置问题开关"` | ||
23 | + CreateTime time.Time `orm:"column(createTime);type(timestamp);null" description:"创建时间"` | ||
24 | + UpdateTime time.Time `orm:"column(updateTime);type(timestamp);null" description:"更新时间"` | ||
25 | + AllowClose int8 `orm:"column(allowClose);null" description:"允许关闭公告(0允许,1禁止)"` | ||
26 | + CompanyId int `orm:"column(company_id);null" description:"公司Id"` | ||
27 | + Status uint8 `orm:"column(status)" description:"状态 0-下架 1- 上架"` | ||
28 | +} | ||
29 | + | ||
30 | +func (t *Bulletin) TableName() string { | ||
31 | + return "bulletin" | ||
32 | +} | ||
33 | + | ||
34 | +func init() { | ||
35 | + orm.RegisterModel(new(Bulletin)) | ||
36 | +} | ||
37 | + | ||
38 | +// AddBulletin insert a new Bulletin into database and returns | ||
39 | +// last inserted Id on success. | ||
40 | +func AddBulletin(m *Bulletin) (id int64, err error) { | ||
41 | + o := orm.NewOrm() | ||
42 | + id, err = o.Insert(m) | ||
43 | + return | ||
44 | +} | ||
45 | + | ||
46 | +// GetBulletinById retrieves Bulletin by Id. Returns error if | ||
47 | +// Id doesn't exist | ||
48 | +func GetBulletinById(id int) (v *Bulletin, err error) { | ||
49 | + o := orm.NewOrm() | ||
50 | + v = &Bulletin{Id: id} | ||
51 | + if err = o.Read(v); err == nil { | ||
52 | + return v, nil | ||
53 | + } | ||
54 | + return nil, err | ||
55 | +} | ||
56 | + | ||
57 | +// GetAllBulletin retrieves all Bulletin matches certain condition. Returns empty list if | ||
58 | +// no records exist | ||
59 | +func GetAllBulletin(query map[string]string, fields []string, sortby []string, order []string, | ||
60 | + offset int64, limit int64) (ml []interface{}, err error) { | ||
61 | + o := orm.NewOrm() | ||
62 | + qs := o.QueryTable(new(Bulletin)) | ||
63 | + // query k=v | ||
64 | + for k, v := range query { | ||
65 | + // rewrite dot-notation to Object__Attribute | ||
66 | + k = strings.Replace(k, ".", "__", -1) | ||
67 | + if strings.Contains(k, "isnull") { | ||
68 | + qs = qs.Filter(k, (v == "true" || v == "1")) | ||
69 | + } else { | ||
70 | + qs = qs.Filter(k, v) | ||
71 | + } | ||
72 | + } | ||
73 | + // order by: | ||
74 | + var sortFields []string | ||
75 | + if len(sortby) != 0 { | ||
76 | + if len(sortby) == len(order) { | ||
77 | + // 1) for each sort field, there is an associated order | ||
78 | + for i, v := range sortby { | ||
79 | + orderby := "" | ||
80 | + if order[i] == "desc" { | ||
81 | + orderby = "-" + v | ||
82 | + } else if order[i] == "asc" { | ||
83 | + orderby = v | ||
84 | + } else { | ||
85 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
86 | + } | ||
87 | + sortFields = append(sortFields, orderby) | ||
88 | + } | ||
89 | + qs = qs.OrderBy(sortFields...) | ||
90 | + } else if len(sortby) != len(order) && len(order) == 1 { | ||
91 | + // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
92 | + for _, v := range sortby { | ||
93 | + orderby := "" | ||
94 | + if order[0] == "desc" { | ||
95 | + orderby = "-" + v | ||
96 | + } else if order[0] == "asc" { | ||
97 | + orderby = v | ||
98 | + } else { | ||
99 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
100 | + } | ||
101 | + sortFields = append(sortFields, orderby) | ||
102 | + } | ||
103 | + } else if len(sortby) != len(order) && len(order) != 1 { | ||
104 | + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
105 | + } | ||
106 | + } else { | ||
107 | + if len(order) != 0 { | ||
108 | + return nil, errors.New("Error: unused 'order' fields") | ||
109 | + } | ||
110 | + } | ||
111 | + | ||
112 | + var l []Bulletin | ||
113 | + qs = qs.OrderBy(sortFields...) | ||
114 | + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
115 | + if len(fields) == 0 { | ||
116 | + for _, v := range l { | ||
117 | + ml = append(ml, v) | ||
118 | + } | ||
119 | + } else { | ||
120 | + // trim unused fields | ||
121 | + for _, v := range l { | ||
122 | + m := make(map[string]interface{}) | ||
123 | + val := reflect.ValueOf(v) | ||
124 | + for _, fname := range fields { | ||
125 | + m[fname] = val.FieldByName(fname).Interface() | ||
126 | + } | ||
127 | + ml = append(ml, m) | ||
128 | + } | ||
129 | + } | ||
130 | + return ml, nil | ||
131 | + } | ||
132 | + return nil, err | ||
133 | +} | ||
134 | + | ||
135 | +// UpdateBulletin updates Bulletin by Id and returns error if | ||
136 | +// the record to be updated doesn't exist | ||
137 | +func UpdateBulletinById(m *Bulletin) (err error) { | ||
138 | + o := orm.NewOrm() | ||
139 | + v := Bulletin{Id: m.Id} | ||
140 | + // ascertain id exists in the database | ||
141 | + if err = o.Read(&v); err == nil { | ||
142 | + var num int64 | ||
143 | + if num, err = o.Update(m); err == nil { | ||
144 | + fmt.Println("Number of records updated in database:", num) | ||
145 | + } | ||
146 | + } | ||
147 | + return | ||
148 | +} | ||
149 | + | ||
150 | +// DeleteBulletin deletes Bulletin by Id and returns error if | ||
151 | +// the record to be deleted doesn't exist | ||
152 | +func DeleteBulletin(id int) (err error) { | ||
153 | + o := orm.NewOrm() | ||
154 | + v := Bulletin{Id: id} | ||
155 | + // ascertain id exists in the database | ||
156 | + if err = o.Read(&v); err == nil { | ||
157 | + var num int64 | ||
158 | + if num, err = o.Delete(&Bulletin{Id: id}); err == nil { | ||
159 | + fmt.Println("Number of records deleted in database:", num) | ||
160 | + } | ||
161 | + } | ||
162 | + return | ||
163 | +} |
models/bulletin_question.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "errors" | ||
5 | + "fmt" | ||
6 | + "reflect" | ||
7 | + "strings" | ||
8 | + "time" | ||
9 | + | ||
10 | + "github.com/astaxie/beego/orm" | ||
11 | +) | ||
12 | + | ||
13 | +type BulletinQuestion struct { | ||
14 | + Id int `orm:"column(id);auto"` | ||
15 | + BulletinId int `orm:"column(bulletin_id);null" description:"公告id"` | ||
16 | + Type int8 `orm:"column(type);null" description:"类型:0-单选,1-多选"` | ||
17 | + Title string `orm:"column(title);size(2000);null" description:"标题"` | ||
18 | + Content string `orm:"column(content);size(2000);null" description:"内容"` | ||
19 | + CreateTime time.Time `orm:"column(createTime);type(timestamp);null" description:"创建时间"` | ||
20 | + UpdateTime time.Time `orm:"column(updateTime);type(timestamp);null" description:"更新时间"` | ||
21 | +} | ||
22 | + | ||
23 | +func (t *BulletinQuestion) TableName() string { | ||
24 | + return "bulletin_question" | ||
25 | +} | ||
26 | + | ||
27 | +func init() { | ||
28 | + orm.RegisterModel(new(BulletinQuestion)) | ||
29 | +} | ||
30 | + | ||
31 | +// AddBulletinQuestion insert a new BulletinQuestion into database and returns | ||
32 | +// last inserted Id on success. | ||
33 | +func AddBulletinQuestion(m *BulletinQuestion) (id int64, err error) { | ||
34 | + o := orm.NewOrm() | ||
35 | + id, err = o.Insert(m) | ||
36 | + return | ||
37 | +} | ||
38 | + | ||
39 | +// GetBulletinQuestionById retrieves BulletinQuestion by Id. Returns error if | ||
40 | +// Id doesn't exist | ||
41 | +func GetBulletinQuestionById(id int) (v *BulletinQuestion, err error) { | ||
42 | + o := orm.NewOrm() | ||
43 | + v = &BulletinQuestion{Id: id} | ||
44 | + if err = o.Read(v); err == nil { | ||
45 | + return v, nil | ||
46 | + } | ||
47 | + return nil, err | ||
48 | +} | ||
49 | + | ||
50 | +// GetAllBulletinQuestion retrieves all BulletinQuestion matches certain condition. Returns empty list if | ||
51 | +// no records exist | ||
52 | +func GetAllBulletinQuestion(query map[string]string, fields []string, sortby []string, order []string, | ||
53 | + offset int64, limit int64) (ml []interface{}, err error) { | ||
54 | + o := orm.NewOrm() | ||
55 | + qs := o.QueryTable(new(BulletinQuestion)) | ||
56 | + // query k=v | ||
57 | + for k, v := range query { | ||
58 | + // rewrite dot-notation to Object__Attribute | ||
59 | + k = strings.Replace(k, ".", "__", -1) | ||
60 | + if strings.Contains(k, "isnull") { | ||
61 | + qs = qs.Filter(k, (v == "true" || v == "1")) | ||
62 | + } else { | ||
63 | + qs = qs.Filter(k, v) | ||
64 | + } | ||
65 | + } | ||
66 | + // order by: | ||
67 | + var sortFields []string | ||
68 | + if len(sortby) != 0 { | ||
69 | + if len(sortby) == len(order) { | ||
70 | + // 1) for each sort field, there is an associated order | ||
71 | + for i, v := range sortby { | ||
72 | + orderby := "" | ||
73 | + if order[i] == "desc" { | ||
74 | + orderby = "-" + v | ||
75 | + } else if order[i] == "asc" { | ||
76 | + orderby = v | ||
77 | + } else { | ||
78 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
79 | + } | ||
80 | + sortFields = append(sortFields, orderby) | ||
81 | + } | ||
82 | + qs = qs.OrderBy(sortFields...) | ||
83 | + } else if len(sortby) != len(order) && len(order) == 1 { | ||
84 | + // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
85 | + for _, v := range sortby { | ||
86 | + orderby := "" | ||
87 | + if order[0] == "desc" { | ||
88 | + orderby = "-" + v | ||
89 | + } else if order[0] == "asc" { | ||
90 | + orderby = v | ||
91 | + } else { | ||
92 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
93 | + } | ||
94 | + sortFields = append(sortFields, orderby) | ||
95 | + } | ||
96 | + } else if len(sortby) != len(order) && len(order) != 1 { | ||
97 | + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
98 | + } | ||
99 | + } else { | ||
100 | + if len(order) != 0 { | ||
101 | + return nil, errors.New("Error: unused 'order' fields") | ||
102 | + } | ||
103 | + } | ||
104 | + | ||
105 | + var l []BulletinQuestion | ||
106 | + qs = qs.OrderBy(sortFields...) | ||
107 | + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
108 | + if len(fields) == 0 { | ||
109 | + for _, v := range l { | ||
110 | + ml = append(ml, v) | ||
111 | + } | ||
112 | + } else { | ||
113 | + // trim unused fields | ||
114 | + for _, v := range l { | ||
115 | + m := make(map[string]interface{}) | ||
116 | + val := reflect.ValueOf(v) | ||
117 | + for _, fname := range fields { | ||
118 | + m[fname] = val.FieldByName(fname).Interface() | ||
119 | + } | ||
120 | + ml = append(ml, m) | ||
121 | + } | ||
122 | + } | ||
123 | + return ml, nil | ||
124 | + } | ||
125 | + return nil, err | ||
126 | +} | ||
127 | + | ||
128 | +// UpdateBulletinQuestion updates BulletinQuestion by Id and returns error if | ||
129 | +// the record to be updated doesn't exist | ||
130 | +func UpdateBulletinQuestionById(m *BulletinQuestion) (err error) { | ||
131 | + o := orm.NewOrm() | ||
132 | + v := BulletinQuestion{Id: m.Id} | ||
133 | + // ascertain id exists in the database | ||
134 | + if err = o.Read(&v); err == nil { | ||
135 | + var num int64 | ||
136 | + if num, err = o.Update(m); err == nil { | ||
137 | + fmt.Println("Number of records updated in database:", num) | ||
138 | + } | ||
139 | + } | ||
140 | + return | ||
141 | +} | ||
142 | + | ||
143 | +// DeleteBulletinQuestion deletes BulletinQuestion by Id and returns error if | ||
144 | +// the record to be deleted doesn't exist | ||
145 | +func DeleteBulletinQuestion(id int) (err error) { | ||
146 | + o := orm.NewOrm() | ||
147 | + v := BulletinQuestion{Id: id} | ||
148 | + // ascertain id exists in the database | ||
149 | + if err = o.Read(&v); err == nil { | ||
150 | + var num int64 | ||
151 | + if num, err = o.Delete(&BulletinQuestion{Id: id}); err == nil { | ||
152 | + fmt.Println("Number of records deleted in database:", num) | ||
153 | + } | ||
154 | + } | ||
155 | + return | ||
156 | +} |
models/bulletin_question_answer.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "errors" | ||
5 | + "fmt" | ||
6 | + "reflect" | ||
7 | + "strings" | ||
8 | + "time" | ||
9 | + | ||
10 | + "github.com/astaxie/beego/orm" | ||
11 | +) | ||
12 | + | ||
13 | +type BulletinQuestionAnswer struct { | ||
14 | + Id int `orm:"column(id);auto"` | ||
15 | + Answer string `orm:"column(answer);null" description:"答案"` | ||
16 | + BulletinId int `orm:"column(bulletin_id);null" description:"公告id"` | ||
17 | + BulletinQuestionId int `orm:"column(bulletin_question_id);null" description:"公告问题id"` | ||
18 | + Uid int64 `orm:"column(uid);null" description:"用户id"` | ||
19 | + CreateTime time.Time `orm:"column(createTime);type(timestamp);null" description:"创建时间"` | ||
20 | + UpdateTime time.Time `orm:"column(updateTime);type(timestamp);null" description:"更新时间"` | ||
21 | +} | ||
22 | + | ||
23 | +func (t *BulletinQuestionAnswer) TableName() string { | ||
24 | + return "bulletin_question_answer" | ||
25 | +} | ||
26 | + | ||
27 | +func init() { | ||
28 | + orm.RegisterModel(new(BulletinQuestionAnswer)) | ||
29 | +} | ||
30 | + | ||
31 | +// AddBulletinQuestionAnswer insert a new BulletinQuestionAnswer into database and returns | ||
32 | +// last inserted Id on success. | ||
33 | +func AddBulletinQuestionAnswer(m *BulletinQuestionAnswer) (id int64, err error) { | ||
34 | + o := orm.NewOrm() | ||
35 | + id, err = o.Insert(m) | ||
36 | + return | ||
37 | +} | ||
38 | + | ||
39 | +// GetBulletinQuestionAnswerById retrieves BulletinQuestionAnswer by Id. Returns error if | ||
40 | +// Id doesn't exist | ||
41 | +func GetBulletinQuestionAnswerById(id int) (v *BulletinQuestionAnswer, err error) { | ||
42 | + o := orm.NewOrm() | ||
43 | + v = &BulletinQuestionAnswer{Id: id} | ||
44 | + if err = o.Read(v); err == nil { | ||
45 | + return v, nil | ||
46 | + } | ||
47 | + return nil, err | ||
48 | +} | ||
49 | + | ||
50 | +// GetAllBulletinQuestionAnswer retrieves all BulletinQuestionAnswer matches certain condition. Returns empty list if | ||
51 | +// no records exist | ||
52 | +func GetAllBulletinQuestionAnswer(query map[string]string, fields []string, sortby []string, order []string, | ||
53 | + offset int64, limit int64) (ml []interface{}, err error) { | ||
54 | + o := orm.NewOrm() | ||
55 | + qs := o.QueryTable(new(BulletinQuestionAnswer)) | ||
56 | + // query k=v | ||
57 | + for k, v := range query { | ||
58 | + // rewrite dot-notation to Object__Attribute | ||
59 | + k = strings.Replace(k, ".", "__", -1) | ||
60 | + if strings.Contains(k, "isnull") { | ||
61 | + qs = qs.Filter(k, (v == "true" || v == "1")) | ||
62 | + } else { | ||
63 | + qs = qs.Filter(k, v) | ||
64 | + } | ||
65 | + } | ||
66 | + // order by: | ||
67 | + var sortFields []string | ||
68 | + if len(sortby) != 0 { | ||
69 | + if len(sortby) == len(order) { | ||
70 | + // 1) for each sort field, there is an associated order | ||
71 | + for i, v := range sortby { | ||
72 | + orderby := "" | ||
73 | + if order[i] == "desc" { | ||
74 | + orderby = "-" + v | ||
75 | + } else if order[i] == "asc" { | ||
76 | + orderby = v | ||
77 | + } else { | ||
78 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
79 | + } | ||
80 | + sortFields = append(sortFields, orderby) | ||
81 | + } | ||
82 | + qs = qs.OrderBy(sortFields...) | ||
83 | + } else if len(sortby) != len(order) && len(order) == 1 { | ||
84 | + // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
85 | + for _, v := range sortby { | ||
86 | + orderby := "" | ||
87 | + if order[0] == "desc" { | ||
88 | + orderby = "-" + v | ||
89 | + } else if order[0] == "asc" { | ||
90 | + orderby = v | ||
91 | + } else { | ||
92 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
93 | + } | ||
94 | + sortFields = append(sortFields, orderby) | ||
95 | + } | ||
96 | + } else if len(sortby) != len(order) && len(order) != 1 { | ||
97 | + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
98 | + } | ||
99 | + } else { | ||
100 | + if len(order) != 0 { | ||
101 | + return nil, errors.New("Error: unused 'order' fields") | ||
102 | + } | ||
103 | + } | ||
104 | + | ||
105 | + var l []BulletinQuestionAnswer | ||
106 | + qs = qs.OrderBy(sortFields...) | ||
107 | + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
108 | + if len(fields) == 0 { | ||
109 | + for _, v := range l { | ||
110 | + ml = append(ml, v) | ||
111 | + } | ||
112 | + } else { | ||
113 | + // trim unused fields | ||
114 | + for _, v := range l { | ||
115 | + m := make(map[string]interface{}) | ||
116 | + val := reflect.ValueOf(v) | ||
117 | + for _, fname := range fields { | ||
118 | + m[fname] = val.FieldByName(fname).Interface() | ||
119 | + } | ||
120 | + ml = append(ml, m) | ||
121 | + } | ||
122 | + } | ||
123 | + return ml, nil | ||
124 | + } | ||
125 | + return nil, err | ||
126 | +} | ||
127 | + | ||
128 | +// UpdateBulletinQuestionAnswer updates BulletinQuestionAnswer by Id and returns error if | ||
129 | +// the record to be updated doesn't exist | ||
130 | +func UpdateBulletinQuestionAnswerById(m *BulletinQuestionAnswer) (err error) { | ||
131 | + o := orm.NewOrm() | ||
132 | + v := BulletinQuestionAnswer{Id: m.Id} | ||
133 | + // ascertain id exists in the database | ||
134 | + if err = o.Read(&v); err == nil { | ||
135 | + var num int64 | ||
136 | + if num, err = o.Update(m); err == nil { | ||
137 | + fmt.Println("Number of records updated in database:", num) | ||
138 | + } | ||
139 | + } | ||
140 | + return | ||
141 | +} | ||
142 | + | ||
143 | +// DeleteBulletinQuestionAnswer deletes BulletinQuestionAnswer by Id and returns error if | ||
144 | +// the record to be deleted doesn't exist | ||
145 | +func DeleteBulletinQuestionAnswer(id int) (err error) { | ||
146 | + o := orm.NewOrm() | ||
147 | + v := BulletinQuestionAnswer{Id: id} | ||
148 | + // ascertain id exists in the database | ||
149 | + if err = o.Read(&v); err == nil { | ||
150 | + var num int64 | ||
151 | + if num, err = o.Delete(&BulletinQuestionAnswer{Id: id}); err == nil { | ||
152 | + fmt.Println("Number of records deleted in database:", num) | ||
153 | + } | ||
154 | + } | ||
155 | + return | ||
156 | +} |
models/cfg_app_version.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "errors" | ||
5 | + "fmt" | ||
6 | + "reflect" | ||
7 | + "strings" | ||
8 | + "time" | ||
9 | + | ||
10 | + "github.com/astaxie/beego/orm" | ||
11 | +) | ||
12 | + | ||
13 | +type CfgAppVersion struct { | ||
14 | + Id int `orm:"column(id);auto"` | ||
15 | + DeviceType int8 `orm:"column(device_type);null" description:"设备类型 (0 ios 1android)"` | ||
16 | + VersionName string `orm:"column(version_name);size(255)" description:"版本名"` | ||
17 | + VersionNo int `orm:"column(version_no)" description:"版本号"` | ||
18 | + VersionState int8 `orm:"column(version_state)" description:"版本状态(0正常 1危险)"` | ||
19 | + Title string `orm:"column(title);size(255)" description:"版本标题"` | ||
20 | + Content string `orm:"column(content);size(500)" description:"更新的内容"` | ||
21 | + DownloadPage string `orm:"column(download_page);size(255);null" description:"下载页"` | ||
22 | + DownloadFile string `orm:"column(download_file);size(255)" description:"文件下载页"` | ||
23 | + CreateTime time.Time `orm:"column(create_time);type(timestamp);null;auto_now"` | ||
24 | + Enabled int8 `orm:"column(enabled);null" description:"是否有效"` | ||
25 | + AdminId int `orm:"column(admin_id)" description:"操作人员"` | ||
26 | + UpdateTime time.Time `orm:"column(update_time);type(timestamp);auto_now_add" description:"更新时间"` | ||
27 | + Channel string `orm:"column(channel);size(255)" description:"当前渠道 0_AppStore、1_fir平台、2_华为、3_小米、4_魅族、5_oppo、6_vivo、7_360、8_百度、9_应用宝、10_其他(使用应用宝地址)"` | ||
28 | + Type int8 `orm:"column(type);null" description:"0为手机 1为平板 终端类型"` | ||
29 | +} | ||
30 | + | ||
31 | +func (t *CfgAppVersion) TableName() string { | ||
32 | + return "cfg_app_version" | ||
33 | +} | ||
34 | + | ||
35 | +func init() { | ||
36 | + orm.RegisterModel(new(CfgAppVersion)) | ||
37 | +} | ||
38 | + | ||
39 | +// AddCfgAppVersion insert a new CfgAppVersion into database and returns | ||
40 | +// last inserted Id on success. | ||
41 | +func AddCfgAppVersion(m *CfgAppVersion) (id int64, err error) { | ||
42 | + o := orm.NewOrm() | ||
43 | + id, err = o.Insert(m) | ||
44 | + return | ||
45 | +} | ||
46 | + | ||
47 | +// GetCfgAppVersionById retrieves CfgAppVersion by Id. Returns error if | ||
48 | +// Id doesn't exist | ||
49 | +func GetCfgAppVersionById(id int) (v *CfgAppVersion, err error) { | ||
50 | + o := orm.NewOrm() | ||
51 | + v = &CfgAppVersion{Id: id} | ||
52 | + if err = o.Read(v); err == nil { | ||
53 | + return v, nil | ||
54 | + } | ||
55 | + return nil, err | ||
56 | +} | ||
57 | + | ||
58 | +// GetAllCfgAppVersion retrieves all CfgAppVersion matches certain condition. Returns empty list if | ||
59 | +// no records exist | ||
60 | +func GetAllCfgAppVersion(query map[string]string, fields []string, sortby []string, order []string, | ||
61 | + offset int64, limit int64) (ml []interface{}, err error) { | ||
62 | + o := orm.NewOrm() | ||
63 | + qs := o.QueryTable(new(CfgAppVersion)) | ||
64 | + // query k=v | ||
65 | + for k, v := range query { | ||
66 | + // rewrite dot-notation to Object__Attribute | ||
67 | + k = strings.Replace(k, ".", "__", -1) | ||
68 | + if strings.Contains(k, "isnull") { | ||
69 | + qs = qs.Filter(k, (v == "true" || v == "1")) | ||
70 | + } else { | ||
71 | + qs = qs.Filter(k, v) | ||
72 | + } | ||
73 | + } | ||
74 | + // order by: | ||
75 | + var sortFields []string | ||
76 | + if len(sortby) != 0 { | ||
77 | + if len(sortby) == len(order) { | ||
78 | + // 1) for each sort field, there is an associated order | ||
79 | + for i, v := range sortby { | ||
80 | + orderby := "" | ||
81 | + if order[i] == "desc" { | ||
82 | + orderby = "-" + v | ||
83 | + } else if order[i] == "asc" { | ||
84 | + orderby = v | ||
85 | + } else { | ||
86 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
87 | + } | ||
88 | + sortFields = append(sortFields, orderby) | ||
89 | + } | ||
90 | + qs = qs.OrderBy(sortFields...) | ||
91 | + } else if len(sortby) != len(order) && len(order) == 1 { | ||
92 | + // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
93 | + for _, v := range sortby { | ||
94 | + orderby := "" | ||
95 | + if order[0] == "desc" { | ||
96 | + orderby = "-" + v | ||
97 | + } else if order[0] == "asc" { | ||
98 | + orderby = v | ||
99 | + } else { | ||
100 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
101 | + } | ||
102 | + sortFields = append(sortFields, orderby) | ||
103 | + } | ||
104 | + } else if len(sortby) != len(order) && len(order) != 1 { | ||
105 | + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
106 | + } | ||
107 | + } else { | ||
108 | + if len(order) != 0 { | ||
109 | + return nil, errors.New("Error: unused 'order' fields") | ||
110 | + } | ||
111 | + } | ||
112 | + | ||
113 | + var l []CfgAppVersion | ||
114 | + qs = qs.OrderBy(sortFields...) | ||
115 | + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
116 | + if len(fields) == 0 { | ||
117 | + for _, v := range l { | ||
118 | + ml = append(ml, v) | ||
119 | + } | ||
120 | + } else { | ||
121 | + // trim unused fields | ||
122 | + for _, v := range l { | ||
123 | + m := make(map[string]interface{}) | ||
124 | + val := reflect.ValueOf(v) | ||
125 | + for _, fname := range fields { | ||
126 | + m[fname] = val.FieldByName(fname).Interface() | ||
127 | + } | ||
128 | + ml = append(ml, m) | ||
129 | + } | ||
130 | + } | ||
131 | + return ml, nil | ||
132 | + } | ||
133 | + return nil, err | ||
134 | +} | ||
135 | + | ||
136 | +// UpdateCfgAppVersion updates CfgAppVersion by Id and returns error if | ||
137 | +// the record to be updated doesn't exist | ||
138 | +func UpdateCfgAppVersionById(m *CfgAppVersion) (err error) { | ||
139 | + o := orm.NewOrm() | ||
140 | + v := CfgAppVersion{Id: m.Id} | ||
141 | + // ascertain id exists in the database | ||
142 | + if err = o.Read(&v); err == nil { | ||
143 | + var num int64 | ||
144 | + if num, err = o.Update(m); err == nil { | ||
145 | + fmt.Println("Number of records updated in database:", num) | ||
146 | + } | ||
147 | + } | ||
148 | + return | ||
149 | +} | ||
150 | + | ||
151 | +// DeleteCfgAppVersion deletes CfgAppVersion by Id and returns error if | ||
152 | +// the record to be deleted doesn't exist | ||
153 | +func DeleteCfgAppVersion(id int) (err error) { | ||
154 | + o := orm.NewOrm() | ||
155 | + v := CfgAppVersion{Id: id} | ||
156 | + // ascertain id exists in the database | ||
157 | + if err = o.Read(&v); err == nil { | ||
158 | + var num int64 | ||
159 | + if num, err = o.Delete(&CfgAppVersion{Id: id}); err == nil { | ||
160 | + fmt.Println("Number of records deleted in database:", num) | ||
161 | + } | ||
162 | + } | ||
163 | + return | ||
164 | +} |
models/cfg_attr.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "errors" | ||
5 | + "fmt" | ||
6 | + "reflect" | ||
7 | + "strings" | ||
8 | + "time" | ||
9 | + | ||
10 | + "github.com/astaxie/beego/orm" | ||
11 | +) | ||
12 | + | ||
13 | +type CfgAttr struct { | ||
14 | + Id int `orm:"column(id);auto" description:"主键ID"` | ||
15 | + CompanyId int `orm:"column(company_id)" description:"公司Id"` | ||
16 | + Name string `orm:"column(name);size(200)" description:"名称"` | ||
17 | + Sort uint `orm:"column(sort)" description:"排序"` | ||
18 | + CreateTime time.Time `orm:"column(createTime);type(timestamp);auto_now_add" description:"创建时间"` | ||
19 | + Enabled int `orm:"column(enabled)"` | ||
20 | +} | ||
21 | + | ||
22 | +func (t *CfgAttr) TableName() string { | ||
23 | + return "cfg_attr" | ||
24 | +} | ||
25 | + | ||
26 | +func init() { | ||
27 | + orm.RegisterModel(new(CfgAttr)) | ||
28 | +} | ||
29 | + | ||
30 | +// AddCfgAttr insert a new CfgAttr into database and returns | ||
31 | +// last inserted Id on success. | ||
32 | +func AddCfgAttr(m *CfgAttr) (id int64, err error) { | ||
33 | + o := orm.NewOrm() | ||
34 | + id, err = o.Insert(m) | ||
35 | + return | ||
36 | +} | ||
37 | + | ||
38 | +// GetCfgAttrById retrieves CfgAttr by Id. Returns error if | ||
39 | +// Id doesn't exist | ||
40 | +func GetCfgAttrById(id int) (v *CfgAttr, err error) { | ||
41 | + o := orm.NewOrm() | ||
42 | + v = &CfgAttr{Id: id} | ||
43 | + if err = o.Read(v); err == nil { | ||
44 | + return v, nil | ||
45 | + } | ||
46 | + return nil, err | ||
47 | +} | ||
48 | + | ||
49 | +// GetAllCfgAttr retrieves all CfgAttr matches certain condition. Returns empty list if | ||
50 | +// no records exist | ||
51 | +func GetAllCfgAttr(query map[string]string, fields []string, sortby []string, order []string, | ||
52 | + offset int64, limit int64) (ml []interface{}, err error) { | ||
53 | + o := orm.NewOrm() | ||
54 | + qs := o.QueryTable(new(CfgAttr)) | ||
55 | + // query k=v | ||
56 | + for k, v := range query { | ||
57 | + // rewrite dot-notation to Object__Attribute | ||
58 | + k = strings.Replace(k, ".", "__", -1) | ||
59 | + if strings.Contains(k, "isnull") { | ||
60 | + qs = qs.Filter(k, (v == "true" || v == "1")) | ||
61 | + } else { | ||
62 | + qs = qs.Filter(k, v) | ||
63 | + } | ||
64 | + } | ||
65 | + // order by: | ||
66 | + var sortFields []string | ||
67 | + if len(sortby) != 0 { | ||
68 | + if len(sortby) == len(order) { | ||
69 | + // 1) for each sort field, there is an associated order | ||
70 | + for i, v := range sortby { | ||
71 | + orderby := "" | ||
72 | + if order[i] == "desc" { | ||
73 | + orderby = "-" + v | ||
74 | + } else if order[i] == "asc" { | ||
75 | + orderby = v | ||
76 | + } else { | ||
77 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
78 | + } | ||
79 | + sortFields = append(sortFields, orderby) | ||
80 | + } | ||
81 | + qs = qs.OrderBy(sortFields...) | ||
82 | + } else if len(sortby) != len(order) && len(order) == 1 { | ||
83 | + // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
84 | + for _, v := range sortby { | ||
85 | + orderby := "" | ||
86 | + if order[0] == "desc" { | ||
87 | + orderby = "-" + v | ||
88 | + } else if order[0] == "asc" { | ||
89 | + orderby = v | ||
90 | + } else { | ||
91 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
92 | + } | ||
93 | + sortFields = append(sortFields, orderby) | ||
94 | + } | ||
95 | + } else if len(sortby) != len(order) && len(order) != 1 { | ||
96 | + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
97 | + } | ||
98 | + } else { | ||
99 | + if len(order) != 0 { | ||
100 | + return nil, errors.New("Error: unused 'order' fields") | ||
101 | + } | ||
102 | + } | ||
103 | + | ||
104 | + var l []CfgAttr | ||
105 | + qs = qs.OrderBy(sortFields...) | ||
106 | + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
107 | + if len(fields) == 0 { | ||
108 | + for _, v := range l { | ||
109 | + ml = append(ml, v) | ||
110 | + } | ||
111 | + } else { | ||
112 | + // trim unused fields | ||
113 | + for _, v := range l { | ||
114 | + m := make(map[string]interface{}) | ||
115 | + val := reflect.ValueOf(v) | ||
116 | + for _, fname := range fields { | ||
117 | + m[fname] = val.FieldByName(fname).Interface() | ||
118 | + } | ||
119 | + ml = append(ml, m) | ||
120 | + } | ||
121 | + } | ||
122 | + return ml, nil | ||
123 | + } | ||
124 | + return nil, err | ||
125 | +} | ||
126 | + | ||
127 | +// UpdateCfgAttr updates CfgAttr by Id and returns error if | ||
128 | +// the record to be updated doesn't exist | ||
129 | +func UpdateCfgAttrById(m *CfgAttr) (err error) { | ||
130 | + o := orm.NewOrm() | ||
131 | + v := CfgAttr{Id: m.Id} | ||
132 | + // ascertain id exists in the database | ||
133 | + if err = o.Read(&v); err == nil { | ||
134 | + var num int64 | ||
135 | + if num, err = o.Update(m); err == nil { | ||
136 | + fmt.Println("Number of records updated in database:", num) | ||
137 | + } | ||
138 | + } | ||
139 | + return | ||
140 | +} | ||
141 | + | ||
142 | +// DeleteCfgAttr deletes CfgAttr by Id and returns error if | ||
143 | +// the record to be deleted doesn't exist | ||
144 | +func DeleteCfgAttr(id int) (err error) { | ||
145 | + o := orm.NewOrm() | ||
146 | + v := CfgAttr{Id: id} | ||
147 | + // ascertain id exists in the database | ||
148 | + if err = o.Read(&v); err == nil { | ||
149 | + var num int64 | ||
150 | + if num, err = o.Delete(&CfgAttr{Id: id}); err == nil { | ||
151 | + fmt.Println("Number of records deleted in database:", num) | ||
152 | + } | ||
153 | + } | ||
154 | + return | ||
155 | +} |
models/cfg_client.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "errors" | ||
5 | + "fmt" | ||
6 | + "reflect" | ||
7 | + "strings" | ||
8 | + "time" | ||
9 | + | ||
10 | + "github.com/astaxie/beego/orm" | ||
11 | +) | ||
12 | + | ||
13 | +type CfgClient struct { | ||
14 | + Id int `orm:"column(id);auto" description:"主键ID"` | ||
15 | + ClientId string `orm:"column(client_id);size(32)" description:"客户端ID"` | ||
16 | + ClientSecret string `orm:"column(client_secret);size(128);null" description:"客户端密钥"` | ||
17 | + CreateTime time.Time `orm:"column(create_time);type(timestamp);auto_now" description:"创建时间"` | ||
18 | + Enabled int8 `orm:"column(enabled)" description:"是否有效"` | ||
19 | +} | ||
20 | + | ||
21 | +func (t *CfgClient) TableName() string { | ||
22 | + return "cfg_client" | ||
23 | +} | ||
24 | + | ||
25 | +func init() { | ||
26 | + orm.RegisterModel(new(CfgClient)) | ||
27 | +} | ||
28 | + | ||
29 | +// AddCfgClient insert a new CfgClient into database and returns | ||
30 | +// last inserted Id on success. | ||
31 | +func AddCfgClient(m *CfgClient) (id int64, err error) { | ||
32 | + o := orm.NewOrm() | ||
33 | + id, err = o.Insert(m) | ||
34 | + return | ||
35 | +} | ||
36 | + | ||
37 | +// GetCfgClientById retrieves CfgClient by Id. Returns error if | ||
38 | +// Id doesn't exist | ||
39 | +func GetCfgClientById(id int) (v *CfgClient, err error) { | ||
40 | + o := orm.NewOrm() | ||
41 | + v = &CfgClient{Id: id} | ||
42 | + if err = o.Read(v); err == nil { | ||
43 | + return v, nil | ||
44 | + } | ||
45 | + return nil, err | ||
46 | +} | ||
47 | + | ||
48 | +// GetAllCfgClient retrieves all CfgClient matches certain condition. Returns empty list if | ||
49 | +// no records exist | ||
50 | +func GetAllCfgClient(query map[string]string, fields []string, sortby []string, order []string, | ||
51 | + offset int64, limit int64) (ml []interface{}, err error) { | ||
52 | + o := orm.NewOrm() | ||
53 | + qs := o.QueryTable(new(CfgClient)) | ||
54 | + // query k=v | ||
55 | + for k, v := range query { | ||
56 | + // rewrite dot-notation to Object__Attribute | ||
57 | + k = strings.Replace(k, ".", "__", -1) | ||
58 | + if strings.Contains(k, "isnull") { | ||
59 | + qs = qs.Filter(k, (v == "true" || v == "1")) | ||
60 | + } else { | ||
61 | + qs = qs.Filter(k, v) | ||
62 | + } | ||
63 | + } | ||
64 | + // order by: | ||
65 | + var sortFields []string | ||
66 | + if len(sortby) != 0 { | ||
67 | + if len(sortby) == len(order) { | ||
68 | + // 1) for each sort field, there is an associated order | ||
69 | + for i, v := range sortby { | ||
70 | + orderby := "" | ||
71 | + if order[i] == "desc" { | ||
72 | + orderby = "-" + v | ||
73 | + } else if order[i] == "asc" { | ||
74 | + orderby = v | ||
75 | + } else { | ||
76 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
77 | + } | ||
78 | + sortFields = append(sortFields, orderby) | ||
79 | + } | ||
80 | + qs = qs.OrderBy(sortFields...) | ||
81 | + } else if len(sortby) != len(order) && len(order) == 1 { | ||
82 | + // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
83 | + for _, v := range sortby { | ||
84 | + orderby := "" | ||
85 | + if order[0] == "desc" { | ||
86 | + orderby = "-" + v | ||
87 | + } else if order[0] == "asc" { | ||
88 | + orderby = v | ||
89 | + } else { | ||
90 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
91 | + } | ||
92 | + sortFields = append(sortFields, orderby) | ||
93 | + } | ||
94 | + } else if len(sortby) != len(order) && len(order) != 1 { | ||
95 | + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
96 | + } | ||
97 | + } else { | ||
98 | + if len(order) != 0 { | ||
99 | + return nil, errors.New("Error: unused 'order' fields") | ||
100 | + } | ||
101 | + } | ||
102 | + | ||
103 | + var l []CfgClient | ||
104 | + qs = qs.OrderBy(sortFields...) | ||
105 | + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
106 | + if len(fields) == 0 { | ||
107 | + for _, v := range l { | ||
108 | + ml = append(ml, v) | ||
109 | + } | ||
110 | + } else { | ||
111 | + // trim unused fields | ||
112 | + for _, v := range l { | ||
113 | + m := make(map[string]interface{}) | ||
114 | + val := reflect.ValueOf(v) | ||
115 | + for _, fname := range fields { | ||
116 | + m[fname] = val.FieldByName(fname).Interface() | ||
117 | + } | ||
118 | + ml = append(ml, m) | ||
119 | + } | ||
120 | + } | ||
121 | + return ml, nil | ||
122 | + } | ||
123 | + return nil, err | ||
124 | +} | ||
125 | + | ||
126 | +// UpdateCfgClient updates CfgClient by Id and returns error if | ||
127 | +// the record to be updated doesn't exist | ||
128 | +func UpdateCfgClientById(m *CfgClient) (err error) { | ||
129 | + o := orm.NewOrm() | ||
130 | + v := CfgClient{Id: m.Id} | ||
131 | + // ascertain id exists in the database | ||
132 | + if err = o.Read(&v); err == nil { | ||
133 | + var num int64 | ||
134 | + if num, err = o.Update(m); err == nil { | ||
135 | + fmt.Println("Number of records updated in database:", num) | ||
136 | + } | ||
137 | + } | ||
138 | + return | ||
139 | +} | ||
140 | + | ||
141 | +// DeleteCfgClient deletes CfgClient by Id and returns error if | ||
142 | +// the record to be deleted doesn't exist | ||
143 | +func DeleteCfgClient(id int) (err error) { | ||
144 | + o := orm.NewOrm() | ||
145 | + v := CfgClient{Id: id} | ||
146 | + // ascertain id exists in the database | ||
147 | + if err = o.Read(&v); err == nil { | ||
148 | + var num int64 | ||
149 | + if num, err = o.Delete(&CfgClient{Id: id}); err == nil { | ||
150 | + fmt.Println("Number of records deleted in database:", num) | ||
151 | + } | ||
152 | + } | ||
153 | + return | ||
154 | +} |
models/cfg_msg.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "errors" | ||
5 | + "fmt" | ||
6 | + "reflect" | ||
7 | + "strings" | ||
8 | + "time" | ||
9 | + | ||
10 | + "github.com/astaxie/beego/orm" | ||
11 | +) | ||
12 | + | ||
13 | +type CfgMsg struct { | ||
14 | + Id int `orm:"column(id);pk" description:"主键ID"` | ||
15 | + CreateTime time.Time `orm:"column(createTime);type(timestamp);auto_now_add" description:"创建时间"` | ||
16 | + Title string `orm:"column(title);size(100)" description:"消息标题"` | ||
17 | + Type int `orm:"column(type)" description:"1为某某某代表解决 2为某某某提出 3为某某某申请解决"` | ||
18 | +} | ||
19 | + | ||
20 | +func (t *CfgMsg) TableName() string { | ||
21 | + return "cfg_msg" | ||
22 | +} | ||
23 | + | ||
24 | +func init() { | ||
25 | + orm.RegisterModel(new(CfgMsg)) | ||
26 | +} | ||
27 | + | ||
28 | +// AddCfgMsg insert a new CfgMsg into database and returns | ||
29 | +// last inserted Id on success. | ||
30 | +func AddCfgMsg(m *CfgMsg) (id int64, err error) { | ||
31 | + o := orm.NewOrm() | ||
32 | + id, err = o.Insert(m) | ||
33 | + return | ||
34 | +} | ||
35 | + | ||
36 | +// GetCfgMsgById retrieves CfgMsg by Id. Returns error if | ||
37 | +// Id doesn't exist | ||
38 | +func GetCfgMsgById(id int) (v *CfgMsg, err error) { | ||
39 | + o := orm.NewOrm() | ||
40 | + v = &CfgMsg{Id: id} | ||
41 | + if err = o.Read(v); err == nil { | ||
42 | + return v, nil | ||
43 | + } | ||
44 | + return nil, err | ||
45 | +} | ||
46 | + | ||
47 | +// GetAllCfgMsg retrieves all CfgMsg matches certain condition. Returns empty list if | ||
48 | +// no records exist | ||
49 | +func GetAllCfgMsg(query map[string]string, fields []string, sortby []string, order []string, | ||
50 | + offset int64, limit int64) (ml []interface{}, err error) { | ||
51 | + o := orm.NewOrm() | ||
52 | + qs := o.QueryTable(new(CfgMsg)) | ||
53 | + // query k=v | ||
54 | + for k, v := range query { | ||
55 | + // rewrite dot-notation to Object__Attribute | ||
56 | + k = strings.Replace(k, ".", "__", -1) | ||
57 | + if strings.Contains(k, "isnull") { | ||
58 | + qs = qs.Filter(k, (v == "true" || v == "1")) | ||
59 | + } else { | ||
60 | + qs = qs.Filter(k, v) | ||
61 | + } | ||
62 | + } | ||
63 | + // order by: | ||
64 | + var sortFields []string | ||
65 | + if len(sortby) != 0 { | ||
66 | + if len(sortby) == len(order) { | ||
67 | + // 1) for each sort field, there is an associated order | ||
68 | + for i, v := range sortby { | ||
69 | + orderby := "" | ||
70 | + if order[i] == "desc" { | ||
71 | + orderby = "-" + v | ||
72 | + } else if order[i] == "asc" { | ||
73 | + orderby = v | ||
74 | + } else { | ||
75 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
76 | + } | ||
77 | + sortFields = append(sortFields, orderby) | ||
78 | + } | ||
79 | + qs = qs.OrderBy(sortFields...) | ||
80 | + } else if len(sortby) != len(order) && len(order) == 1 { | ||
81 | + // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
82 | + for _, v := range sortby { | ||
83 | + orderby := "" | ||
84 | + if order[0] == "desc" { | ||
85 | + orderby = "-" + v | ||
86 | + } else if order[0] == "asc" { | ||
87 | + orderby = v | ||
88 | + } else { | ||
89 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
90 | + } | ||
91 | + sortFields = append(sortFields, orderby) | ||
92 | + } | ||
93 | + } else if len(sortby) != len(order) && len(order) != 1 { | ||
94 | + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
95 | + } | ||
96 | + } else { | ||
97 | + if len(order) != 0 { | ||
98 | + return nil, errors.New("Error: unused 'order' fields") | ||
99 | + } | ||
100 | + } | ||
101 | + | ||
102 | + var l []CfgMsg | ||
103 | + qs = qs.OrderBy(sortFields...) | ||
104 | + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
105 | + if len(fields) == 0 { | ||
106 | + for _, v := range l { | ||
107 | + ml = append(ml, v) | ||
108 | + } | ||
109 | + } else { | ||
110 | + // trim unused fields | ||
111 | + for _, v := range l { | ||
112 | + m := make(map[string]interface{}) | ||
113 | + val := reflect.ValueOf(v) | ||
114 | + for _, fname := range fields { | ||
115 | + m[fname] = val.FieldByName(fname).Interface() | ||
116 | + } | ||
117 | + ml = append(ml, m) | ||
118 | + } | ||
119 | + } | ||
120 | + return ml, nil | ||
121 | + } | ||
122 | + return nil, err | ||
123 | +} | ||
124 | + | ||
125 | +// UpdateCfgMsg updates CfgMsg by Id and returns error if | ||
126 | +// the record to be updated doesn't exist | ||
127 | +func UpdateCfgMsgById(m *CfgMsg) (err error) { | ||
128 | + o := orm.NewOrm() | ||
129 | + v := CfgMsg{Id: m.Id} | ||
130 | + // ascertain id exists in the database | ||
131 | + if err = o.Read(&v); err == nil { | ||
132 | + var num int64 | ||
133 | + if num, err = o.Update(m); err == nil { | ||
134 | + fmt.Println("Number of records updated in database:", num) | ||
135 | + } | ||
136 | + } | ||
137 | + return | ||
138 | +} | ||
139 | + | ||
140 | +// DeleteCfgMsg deletes CfgMsg by Id and returns error if | ||
141 | +// the record to be deleted doesn't exist | ||
142 | +func DeleteCfgMsg(id int) (err error) { | ||
143 | + o := orm.NewOrm() | ||
144 | + v := CfgMsg{Id: id} | ||
145 | + // ascertain id exists in the database | ||
146 | + if err = o.Read(&v); err == nil { | ||
147 | + var num int64 | ||
148 | + if num, err = o.Delete(&CfgMsg{Id: id}); err == nil { | ||
149 | + fmt.Println("Number of records deleted in database:", num) | ||
150 | + } | ||
151 | + } | ||
152 | + return | ||
153 | +} |
models/cfg_qtype.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "errors" | ||
5 | + "fmt" | ||
6 | + "reflect" | ||
7 | + "strings" | ||
8 | + "time" | ||
9 | + | ||
10 | + "github.com/astaxie/beego/orm" | ||
11 | +) | ||
12 | + | ||
13 | +type CfgQtype struct { | ||
14 | + Id int `orm:"column(id);auto" description:"主键ID"` | ||
15 | + CompanyId int `orm:"column(company_id)" description:"公司Id"` | ||
16 | + Name string `orm:"column(name);size(200)" description:"消息标题"` | ||
17 | + CreateTime time.Time `orm:"column(createTime);type(timestamp);auto_now_add" description:"创建时间"` | ||
18 | + Enabled int `orm:"column(enabled)"` | ||
19 | +} | ||
20 | + | ||
21 | +func (t *CfgQtype) TableName() string { | ||
22 | + return "cfg_qtype" | ||
23 | +} | ||
24 | + | ||
25 | +func init() { | ||
26 | + orm.RegisterModel(new(CfgQtype)) | ||
27 | +} | ||
28 | + | ||
29 | +// AddCfgQtype insert a new CfgQtype into database and returns | ||
30 | +// last inserted Id on success. | ||
31 | +func AddCfgQtype(m *CfgQtype) (id int64, err error) { | ||
32 | + o := orm.NewOrm() | ||
33 | + id, err = o.Insert(m) | ||
34 | + return | ||
35 | +} | ||
36 | + | ||
37 | +// GetCfgQtypeById retrieves CfgQtype by Id. Returns error if | ||
38 | +// Id doesn't exist | ||
39 | +func GetCfgQtypeById(id int) (v *CfgQtype, err error) { | ||
40 | + o := orm.NewOrm() | ||
41 | + v = &CfgQtype{Id: id} | ||
42 | + if err = o.Read(v); err == nil { | ||
43 | + return v, nil | ||
44 | + } | ||
45 | + return nil, err | ||
46 | +} | ||
47 | + | ||
48 | +// GetAllCfgQtype retrieves all CfgQtype matches certain condition. Returns empty list if | ||
49 | +// no records exist | ||
50 | +func GetAllCfgQtype(query map[string]string, fields []string, sortby []string, order []string, | ||
51 | + offset int64, limit int64) (ml []interface{}, err error) { | ||
52 | + o := orm.NewOrm() | ||
53 | + qs := o.QueryTable(new(CfgQtype)) | ||
54 | + // query k=v | ||
55 | + for k, v := range query { | ||
56 | + // rewrite dot-notation to Object__Attribute | ||
57 | + k = strings.Replace(k, ".", "__", -1) | ||
58 | + if strings.Contains(k, "isnull") { | ||
59 | + qs = qs.Filter(k, (v == "true" || v == "1")) | ||
60 | + } else { | ||
61 | + qs = qs.Filter(k, v) | ||
62 | + } | ||
63 | + } | ||
64 | + // order by: | ||
65 | + var sortFields []string | ||
66 | + if len(sortby) != 0 { | ||
67 | + if len(sortby) == len(order) { | ||
68 | + // 1) for each sort field, there is an associated order | ||
69 | + for i, v := range sortby { | ||
70 | + orderby := "" | ||
71 | + if order[i] == "desc" { | ||
72 | + orderby = "-" + v | ||
73 | + } else if order[i] == "asc" { | ||
74 | + orderby = v | ||
75 | + } else { | ||
76 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
77 | + } | ||
78 | + sortFields = append(sortFields, orderby) | ||
79 | + } | ||
80 | + qs = qs.OrderBy(sortFields...) | ||
81 | + } else if len(sortby) != len(order) && len(order) == 1 { | ||
82 | + // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
83 | + for _, v := range sortby { | ||
84 | + orderby := "" | ||
85 | + if order[0] == "desc" { | ||
86 | + orderby = "-" + v | ||
87 | + } else if order[0] == "asc" { | ||
88 | + orderby = v | ||
89 | + } else { | ||
90 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
91 | + } | ||
92 | + sortFields = append(sortFields, orderby) | ||
93 | + } | ||
94 | + } else if len(sortby) != len(order) && len(order) != 1 { | ||
95 | + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
96 | + } | ||
97 | + } else { | ||
98 | + if len(order) != 0 { | ||
99 | + return nil, errors.New("Error: unused 'order' fields") | ||
100 | + } | ||
101 | + } | ||
102 | + | ||
103 | + var l []CfgQtype | ||
104 | + qs = qs.OrderBy(sortFields...) | ||
105 | + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
106 | + if len(fields) == 0 { | ||
107 | + for _, v := range l { | ||
108 | + ml = append(ml, v) | ||
109 | + } | ||
110 | + } else { | ||
111 | + // trim unused fields | ||
112 | + for _, v := range l { | ||
113 | + m := make(map[string]interface{}) | ||
114 | + val := reflect.ValueOf(v) | ||
115 | + for _, fname := range fields { | ||
116 | + m[fname] = val.FieldByName(fname).Interface() | ||
117 | + } | ||
118 | + ml = append(ml, m) | ||
119 | + } | ||
120 | + } | ||
121 | + return ml, nil | ||
122 | + } | ||
123 | + return nil, err | ||
124 | +} | ||
125 | + | ||
126 | +// UpdateCfgQtype updates CfgQtype by Id and returns error if | ||
127 | +// the record to be updated doesn't exist | ||
128 | +func UpdateCfgQtypeById(m *CfgQtype) (err error) { | ||
129 | + o := orm.NewOrm() | ||
130 | + v := CfgQtype{Id: m.Id} | ||
131 | + // ascertain id exists in the database | ||
132 | + if err = o.Read(&v); err == nil { | ||
133 | + var num int64 | ||
134 | + if num, err = o.Update(m); err == nil { | ||
135 | + fmt.Println("Number of records updated in database:", num) | ||
136 | + } | ||
137 | + } | ||
138 | + return | ||
139 | +} | ||
140 | + | ||
141 | +// DeleteCfgQtype deletes CfgQtype by Id and returns error if | ||
142 | +// the record to be deleted doesn't exist | ||
143 | +func DeleteCfgQtype(id int) (err error) { | ||
144 | + o := orm.NewOrm() | ||
145 | + v := CfgQtype{Id: id} | ||
146 | + // ascertain id exists in the database | ||
147 | + if err = o.Read(&v); err == nil { | ||
148 | + var num int64 | ||
149 | + if num, err = o.Delete(&CfgQtype{Id: id}); err == nil { | ||
150 | + fmt.Println("Number of records deleted in database:", num) | ||
151 | + } | ||
152 | + } | ||
153 | + return | ||
154 | +} |
models/commend.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "errors" | ||
5 | + "fmt" | ||
6 | + "reflect" | ||
7 | + "strings" | ||
8 | + "time" | ||
9 | + | ||
10 | + "github.com/astaxie/beego/orm" | ||
11 | +) | ||
12 | + | ||
13 | +type Commend struct { | ||
14 | + Id int `orm:"column(cid);pk" description:"主键ID"` | ||
15 | + Uid int64 `orm:"column(uid)" description:"用户ID"` | ||
16 | + Username string `orm:"column(username);size(255)" description:"用户名"` | ||
17 | + CreateTime time.Time `orm:"column(createTime);type(timestamp);auto_now_add" description:"创建时间"` | ||
18 | + QuestionTitle string `orm:"column(questionTitle);size(100)" description:"标题"` | ||
19 | + QuestionId int64 `orm:"column(questionId);null"` | ||
20 | + Way int `orm:"column(way)" description:"0提出问题、1参与解决问题"` | ||
21 | + Company string `orm:"column(company);size(50)" description:"是否已读 0未读,1已读"` | ||
22 | + CompanyId int `orm:"column(company_id)" description:"公司id"` | ||
23 | + Status int8 `orm:"column(status)" description:"状态 1可见 2不可见"` | ||
24 | + CommendationTime time.Time `orm:"column(commendation_time);type(date)" description:"表彰时间"` | ||
25 | +} | ||
26 | + | ||
27 | +func (t *Commend) TableName() string { | ||
28 | + return "commend" | ||
29 | +} | ||
30 | + | ||
31 | +func init() { | ||
32 | + orm.RegisterModel(new(Commend)) | ||
33 | +} | ||
34 | + | ||
35 | +// AddCommend insert a new Commend into database and returns | ||
36 | +// last inserted Id on success. | ||
37 | +func AddCommend(m *Commend) (id int64, err error) { | ||
38 | + o := orm.NewOrm() | ||
39 | + id, err = o.Insert(m) | ||
40 | + return | ||
41 | +} | ||
42 | + | ||
43 | +// GetCommendById retrieves Commend by Id. Returns error if | ||
44 | +// Id doesn't exist | ||
45 | +func GetCommendById(id int) (v *Commend, err error) { | ||
46 | + o := orm.NewOrm() | ||
47 | + v = &Commend{Id: id} | ||
48 | + if err = o.Read(v); err == nil { | ||
49 | + return v, nil | ||
50 | + } | ||
51 | + return nil, err | ||
52 | +} | ||
53 | + | ||
54 | +// GetAllCommend retrieves all Commend matches certain condition. Returns empty list if | ||
55 | +// no records exist | ||
56 | +func GetAllCommend(query map[string]string, fields []string, sortby []string, order []string, | ||
57 | + offset int64, limit int64) (ml []interface{}, err error) { | ||
58 | + o := orm.NewOrm() | ||
59 | + qs := o.QueryTable(new(Commend)) | ||
60 | + // query k=v | ||
61 | + for k, v := range query { | ||
62 | + // rewrite dot-notation to Object__Attribute | ||
63 | + k = strings.Replace(k, ".", "__", -1) | ||
64 | + if strings.Contains(k, "isnull") { | ||
65 | + qs = qs.Filter(k, (v == "true" || v == "1")) | ||
66 | + } else { | ||
67 | + qs = qs.Filter(k, v) | ||
68 | + } | ||
69 | + } | ||
70 | + // order by: | ||
71 | + var sortFields []string | ||
72 | + if len(sortby) != 0 { | ||
73 | + if len(sortby) == len(order) { | ||
74 | + // 1) for each sort field, there is an associated order | ||
75 | + for i, v := range sortby { | ||
76 | + orderby := "" | ||
77 | + if order[i] == "desc" { | ||
78 | + orderby = "-" + v | ||
79 | + } else if order[i] == "asc" { | ||
80 | + orderby = v | ||
81 | + } else { | ||
82 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
83 | + } | ||
84 | + sortFields = append(sortFields, orderby) | ||
85 | + } | ||
86 | + qs = qs.OrderBy(sortFields...) | ||
87 | + } else if len(sortby) != len(order) && len(order) == 1 { | ||
88 | + // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
89 | + for _, v := range sortby { | ||
90 | + orderby := "" | ||
91 | + if order[0] == "desc" { | ||
92 | + orderby = "-" + v | ||
93 | + } else if order[0] == "asc" { | ||
94 | + orderby = v | ||
95 | + } else { | ||
96 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
97 | + } | ||
98 | + sortFields = append(sortFields, orderby) | ||
99 | + } | ||
100 | + } else if len(sortby) != len(order) && len(order) != 1 { | ||
101 | + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
102 | + } | ||
103 | + } else { | ||
104 | + if len(order) != 0 { | ||
105 | + return nil, errors.New("Error: unused 'order' fields") | ||
106 | + } | ||
107 | + } | ||
108 | + | ||
109 | + var l []Commend | ||
110 | + qs = qs.OrderBy(sortFields...) | ||
111 | + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
112 | + if len(fields) == 0 { | ||
113 | + for _, v := range l { | ||
114 | + ml = append(ml, v) | ||
115 | + } | ||
116 | + } else { | ||
117 | + // trim unused fields | ||
118 | + for _, v := range l { | ||
119 | + m := make(map[string]interface{}) | ||
120 | + val := reflect.ValueOf(v) | ||
121 | + for _, fname := range fields { | ||
122 | + m[fname] = val.FieldByName(fname).Interface() | ||
123 | + } | ||
124 | + ml = append(ml, m) | ||
125 | + } | ||
126 | + } | ||
127 | + return ml, nil | ||
128 | + } | ||
129 | + return nil, err | ||
130 | +} | ||
131 | + | ||
132 | +// UpdateCommend updates Commend by Id and returns error if | ||
133 | +// the record to be updated doesn't exist | ||
134 | +func UpdateCommendById(m *Commend) (err error) { | ||
135 | + o := orm.NewOrm() | ||
136 | + v := Commend{Id: m.Id} | ||
137 | + // ascertain id exists in the database | ||
138 | + if err = o.Read(&v); err == nil { | ||
139 | + var num int64 | ||
140 | + if num, err = o.Update(m); err == nil { | ||
141 | + fmt.Println("Number of records updated in database:", num) | ||
142 | + } | ||
143 | + } | ||
144 | + return | ||
145 | +} | ||
146 | + | ||
147 | +// DeleteCommend deletes Commend by Id and returns error if | ||
148 | +// the record to be deleted doesn't exist | ||
149 | +func DeleteCommend(id int) (err error) { | ||
150 | + o := orm.NewOrm() | ||
151 | + v := Commend{Id: id} | ||
152 | + // ascertain id exists in the database | ||
153 | + if err = o.Read(&v); err == nil { | ||
154 | + var num int64 | ||
155 | + if num, err = o.Delete(&Commend{Id: id}); err == nil { | ||
156 | + fmt.Println("Number of records deleted in database:", num) | ||
157 | + } | ||
158 | + } | ||
159 | + return | ||
160 | +} |
models/comment.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "errors" | ||
5 | + "fmt" | ||
6 | + "reflect" | ||
7 | + "strings" | ||
8 | + "time" | ||
9 | + | ||
10 | + "github.com/astaxie/beego/orm" | ||
11 | +) | ||
12 | + | ||
13 | +type Comment struct { | ||
14 | + Id int `orm:"column(cid);pk"` | ||
15 | + Uid int64 `orm:"column(uid);null"` | ||
16 | + CreateTime time.Time `orm:"column(createTime);type(timestamp);auto_now_add"` | ||
17 | + Content string `orm:"column(content)"` | ||
18 | + PageView int `orm:"column(pageView);null" description:"浏览总数"` | ||
19 | + CommentTotal int `orm:"column(commentTotal);null" description:"评论总数"` | ||
20 | + SympathyTotal int `orm:"column(sympathyTotal)" description:"同感总数"` | ||
21 | + Type int `orm:"column(type);null" description:"0问题、1评论、2方案"` | ||
22 | + Id_RENAME int64 `orm:"column(id);null" description:"对应的ID"` | ||
23 | +} | ||
24 | + | ||
25 | +func (t *Comment) TableName() string { | ||
26 | + return "comment" | ||
27 | +} | ||
28 | + | ||
29 | +func init() { | ||
30 | + orm.RegisterModel(new(Comment)) | ||
31 | +} | ||
32 | + | ||
33 | +// AddComment insert a new Comment into database and returns | ||
34 | +// last inserted Id on success. | ||
35 | +func AddComment(m *Comment) (id int64, err error) { | ||
36 | + o := orm.NewOrm() | ||
37 | + id, err = o.Insert(m) | ||
38 | + return | ||
39 | +} | ||
40 | + | ||
41 | +// GetCommentById retrieves Comment by Id. Returns error if | ||
42 | +// Id doesn't exist | ||
43 | +func GetCommentById(id int) (v *Comment, err error) { | ||
44 | + o := orm.NewOrm() | ||
45 | + v = &Comment{Id: id} | ||
46 | + if err = o.Read(v); err == nil { | ||
47 | + return v, nil | ||
48 | + } | ||
49 | + return nil, err | ||
50 | +} | ||
51 | + | ||
52 | +// GetAllComment retrieves all Comment matches certain condition. Returns empty list if | ||
53 | +// no records exist | ||
54 | +func GetAllComment(query map[string]string, fields []string, sortby []string, order []string, | ||
55 | + offset int64, limit int64) (ml []interface{}, err error) { | ||
56 | + o := orm.NewOrm() | ||
57 | + qs := o.QueryTable(new(Comment)) | ||
58 | + // query k=v | ||
59 | + for k, v := range query { | ||
60 | + // rewrite dot-notation to Object__Attribute | ||
61 | + k = strings.Replace(k, ".", "__", -1) | ||
62 | + if strings.Contains(k, "isnull") { | ||
63 | + qs = qs.Filter(k, (v == "true" || v == "1")) | ||
64 | + } else { | ||
65 | + qs = qs.Filter(k, v) | ||
66 | + } | ||
67 | + } | ||
68 | + // order by: | ||
69 | + var sortFields []string | ||
70 | + if len(sortby) != 0 { | ||
71 | + if len(sortby) == len(order) { | ||
72 | + // 1) for each sort field, there is an associated order | ||
73 | + for i, v := range sortby { | ||
74 | + orderby := "" | ||
75 | + if order[i] == "desc" { | ||
76 | + orderby = "-" + v | ||
77 | + } else if order[i] == "asc" { | ||
78 | + orderby = v | ||
79 | + } else { | ||
80 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
81 | + } | ||
82 | + sortFields = append(sortFields, orderby) | ||
83 | + } | ||
84 | + qs = qs.OrderBy(sortFields...) | ||
85 | + } else if len(sortby) != len(order) && len(order) == 1 { | ||
86 | + // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
87 | + for _, v := range sortby { | ||
88 | + orderby := "" | ||
89 | + if order[0] == "desc" { | ||
90 | + orderby = "-" + v | ||
91 | + } else if order[0] == "asc" { | ||
92 | + orderby = v | ||
93 | + } else { | ||
94 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
95 | + } | ||
96 | + sortFields = append(sortFields, orderby) | ||
97 | + } | ||
98 | + } else if len(sortby) != len(order) && len(order) != 1 { | ||
99 | + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
100 | + } | ||
101 | + } else { | ||
102 | + if len(order) != 0 { | ||
103 | + return nil, errors.New("Error: unused 'order' fields") | ||
104 | + } | ||
105 | + } | ||
106 | + | ||
107 | + var l []Comment | ||
108 | + qs = qs.OrderBy(sortFields...) | ||
109 | + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
110 | + if len(fields) == 0 { | ||
111 | + for _, v := range l { | ||
112 | + ml = append(ml, v) | ||
113 | + } | ||
114 | + } else { | ||
115 | + // trim unused fields | ||
116 | + for _, v := range l { | ||
117 | + m := make(map[string]interface{}) | ||
118 | + val := reflect.ValueOf(v) | ||
119 | + for _, fname := range fields { | ||
120 | + m[fname] = val.FieldByName(fname).Interface() | ||
121 | + } | ||
122 | + ml = append(ml, m) | ||
123 | + } | ||
124 | + } | ||
125 | + return ml, nil | ||
126 | + } | ||
127 | + return nil, err | ||
128 | +} | ||
129 | + | ||
130 | +// UpdateComment updates Comment by Id and returns error if | ||
131 | +// the record to be updated doesn't exist | ||
132 | +func UpdateCommentById(m *Comment) (err error) { | ||
133 | + o := orm.NewOrm() | ||
134 | + v := Comment{Id: m.Id} | ||
135 | + // ascertain id exists in the database | ||
136 | + if err = o.Read(&v); err == nil { | ||
137 | + var num int64 | ||
138 | + if num, err = o.Update(m); err == nil { | ||
139 | + fmt.Println("Number of records updated in database:", num) | ||
140 | + } | ||
141 | + } | ||
142 | + return | ||
143 | +} | ||
144 | + | ||
145 | +// DeleteComment deletes Comment by Id and returns error if | ||
146 | +// the record to be deleted doesn't exist | ||
147 | +func DeleteComment(id int) (err error) { | ||
148 | + o := orm.NewOrm() | ||
149 | + v := Comment{Id: id} | ||
150 | + // ascertain id exists in the database | ||
151 | + if err = o.Read(&v); err == nil { | ||
152 | + var num int64 | ||
153 | + if num, err = o.Delete(&Comment{Id: id}); err == nil { | ||
154 | + fmt.Println("Number of records deleted in database:", num) | ||
155 | + } | ||
156 | + } | ||
157 | + return | ||
158 | +} |
models/companies.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "errors" | ||
5 | + "fmt" | ||
6 | + "reflect" | ||
7 | + "strings" | ||
8 | + "time" | ||
9 | + | ||
10 | + "github.com/astaxie/beego/orm" | ||
11 | +) | ||
12 | + | ||
13 | +type Companies struct { | ||
14 | + Id int `orm:"column(id);auto"` | ||
15 | + Name string `orm:"column(name);size(255)"` | ||
16 | + Username string `orm:"column(username);size(255)"` | ||
17 | + Phone string `orm:"column(phone);size(255)"` | ||
18 | + Status uint8 `orm:"column(status)" description:"状态 1启用 2禁用"` | ||
19 | + CreateTime time.Time `orm:"column(create_time);type(timestamp);auto_now"` | ||
20 | +} | ||
21 | + | ||
22 | +func (t *Companies) TableName() string { | ||
23 | + return "companies" | ||
24 | +} | ||
25 | + | ||
26 | +func init() { | ||
27 | + orm.RegisterModel(new(Companies)) | ||
28 | +} | ||
29 | + | ||
30 | +// AddCompanies insert a new Companies into database and returns | ||
31 | +// last inserted Id on success. | ||
32 | +func AddCompanies(m *Companies) (id int64, err error) { | ||
33 | + o := orm.NewOrm() | ||
34 | + id, err = o.Insert(m) | ||
35 | + return | ||
36 | +} | ||
37 | + | ||
38 | +// GetCompaniesById retrieves Companies by Id. Returns error if | ||
39 | +// Id doesn't exist | ||
40 | +func GetCompaniesById(id int) (v *Companies, err error) { | ||
41 | + o := orm.NewOrm() | ||
42 | + v = &Companies{Id: id} | ||
43 | + if err = o.Read(v); err == nil { | ||
44 | + return v, nil | ||
45 | + } | ||
46 | + return nil, err | ||
47 | +} | ||
48 | + | ||
49 | +// GetAllCompanies retrieves all Companies matches certain condition. Returns empty list if | ||
50 | +// no records exist | ||
51 | +func GetAllCompanies(query map[string]string, fields []string, sortby []string, order []string, | ||
52 | + offset int64, limit int64) (ml []interface{}, err error) { | ||
53 | + o := orm.NewOrm() | ||
54 | + qs := o.QueryTable(new(Companies)) | ||
55 | + // query k=v | ||
56 | + for k, v := range query { | ||
57 | + // rewrite dot-notation to Object__Attribute | ||
58 | + k = strings.Replace(k, ".", "__", -1) | ||
59 | + if strings.Contains(k, "isnull") { | ||
60 | + qs = qs.Filter(k, (v == "true" || v == "1")) | ||
61 | + } else { | ||
62 | + qs = qs.Filter(k, v) | ||
63 | + } | ||
64 | + } | ||
65 | + // order by: | ||
66 | + var sortFields []string | ||
67 | + if len(sortby) != 0 { | ||
68 | + if len(sortby) == len(order) { | ||
69 | + // 1) for each sort field, there is an associated order | ||
70 | + for i, v := range sortby { | ||
71 | + orderby := "" | ||
72 | + if order[i] == "desc" { | ||
73 | + orderby = "-" + v | ||
74 | + } else if order[i] == "asc" { | ||
75 | + orderby = v | ||
76 | + } else { | ||
77 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
78 | + } | ||
79 | + sortFields = append(sortFields, orderby) | ||
80 | + } | ||
81 | + qs = qs.OrderBy(sortFields...) | ||
82 | + } else if len(sortby) != len(order) && len(order) == 1 { | ||
83 | + // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
84 | + for _, v := range sortby { | ||
85 | + orderby := "" | ||
86 | + if order[0] == "desc" { | ||
87 | + orderby = "-" + v | ||
88 | + } else if order[0] == "asc" { | ||
89 | + orderby = v | ||
90 | + } else { | ||
91 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
92 | + } | ||
93 | + sortFields = append(sortFields, orderby) | ||
94 | + } | ||
95 | + } else if len(sortby) != len(order) && len(order) != 1 { | ||
96 | + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
97 | + } | ||
98 | + } else { | ||
99 | + if len(order) != 0 { | ||
100 | + return nil, errors.New("Error: unused 'order' fields") | ||
101 | + } | ||
102 | + } | ||
103 | + | ||
104 | + var l []Companies | ||
105 | + qs = qs.OrderBy(sortFields...) | ||
106 | + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
107 | + if len(fields) == 0 { | ||
108 | + for _, v := range l { | ||
109 | + ml = append(ml, v) | ||
110 | + } | ||
111 | + } else { | ||
112 | + // trim unused fields | ||
113 | + for _, v := range l { | ||
114 | + m := make(map[string]interface{}) | ||
115 | + val := reflect.ValueOf(v) | ||
116 | + for _, fname := range fields { | ||
117 | + m[fname] = val.FieldByName(fname).Interface() | ||
118 | + } | ||
119 | + ml = append(ml, m) | ||
120 | + } | ||
121 | + } | ||
122 | + return ml, nil | ||
123 | + } | ||
124 | + return nil, err | ||
125 | +} | ||
126 | + | ||
127 | +// UpdateCompanies updates Companies by Id and returns error if | ||
128 | +// the record to be updated doesn't exist | ||
129 | +func UpdateCompaniesById(m *Companies) (err error) { | ||
130 | + o := orm.NewOrm() | ||
131 | + v := Companies{Id: m.Id} | ||
132 | + // ascertain id exists in the database | ||
133 | + if err = o.Read(&v); err == nil { | ||
134 | + var num int64 | ||
135 | + if num, err = o.Update(m); err == nil { | ||
136 | + fmt.Println("Number of records updated in database:", num) | ||
137 | + } | ||
138 | + } | ||
139 | + return | ||
140 | +} | ||
141 | + | ||
142 | +// DeleteCompanies deletes Companies by Id and returns error if | ||
143 | +// the record to be deleted doesn't exist | ||
144 | +func DeleteCompanies(id int) (err error) { | ||
145 | + o := orm.NewOrm() | ||
146 | + v := Companies{Id: id} | ||
147 | + // ascertain id exists in the database | ||
148 | + if err = o.Read(&v); err == nil { | ||
149 | + var num int64 | ||
150 | + if num, err = o.Delete(&Companies{Id: id}); err == nil { | ||
151 | + fmt.Println("Number of records deleted in database:", num) | ||
152 | + } | ||
153 | + } | ||
154 | + return | ||
155 | +} |
models/departments.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "errors" | ||
5 | + "fmt" | ||
6 | + "reflect" | ||
7 | + "strings" | ||
8 | + "time" | ||
9 | + | ||
10 | + "github.com/astaxie/beego/orm" | ||
11 | +) | ||
12 | + | ||
13 | +type Departments struct { | ||
14 | + Id int `orm:"column(id);auto"` | ||
15 | + CompanyId int `orm:"column(company_id)"` | ||
16 | + Name string `orm:"column(name);size(255)"` | ||
17 | + Username string `orm:"column(username);size(255)"` | ||
18 | + Number int `orm:"column(number)"` | ||
19 | + CreateTime time.Time `orm:"column(create_time);type(timestamp);auto_now"` | ||
20 | + Enabled uint8 `orm:"column(enabled)" description:"状态 1启用 0禁用"` | ||
21 | +} | ||
22 | + | ||
23 | +func (t *Departments) TableName() string { | ||
24 | + return "departments" | ||
25 | +} | ||
26 | + | ||
27 | +func init() { | ||
28 | + orm.RegisterModel(new(Departments)) | ||
29 | +} | ||
30 | + | ||
31 | +// AddDepartments insert a new Departments into database and returns | ||
32 | +// last inserted Id on success. | ||
33 | +func AddDepartments(m *Departments) (id int64, err error) { | ||
34 | + o := orm.NewOrm() | ||
35 | + id, err = o.Insert(m) | ||
36 | + return | ||
37 | +} | ||
38 | + | ||
39 | +// GetDepartmentsById retrieves Departments by Id. Returns error if | ||
40 | +// Id doesn't exist | ||
41 | +func GetDepartmentsById(id int) (v *Departments, err error) { | ||
42 | + o := orm.NewOrm() | ||
43 | + v = &Departments{Id: id} | ||
44 | + if err = o.Read(v); err == nil { | ||
45 | + return v, nil | ||
46 | + } | ||
47 | + return nil, err | ||
48 | +} | ||
49 | + | ||
50 | +// GetAllDepartments retrieves all Departments matches certain condition. Returns empty list if | ||
51 | +// no records exist | ||
52 | +func GetAllDepartments(query map[string]string, fields []string, sortby []string, order []string, | ||
53 | + offset int64, limit int64) (ml []interface{}, err error) { | ||
54 | + o := orm.NewOrm() | ||
55 | + qs := o.QueryTable(new(Departments)) | ||
56 | + // query k=v | ||
57 | + for k, v := range query { | ||
58 | + // rewrite dot-notation to Object__Attribute | ||
59 | + k = strings.Replace(k, ".", "__", -1) | ||
60 | + if strings.Contains(k, "isnull") { | ||
61 | + qs = qs.Filter(k, (v == "true" || v == "1")) | ||
62 | + } else { | ||
63 | + qs = qs.Filter(k, v) | ||
64 | + } | ||
65 | + } | ||
66 | + // order by: | ||
67 | + var sortFields []string | ||
68 | + if len(sortby) != 0 { | ||
69 | + if len(sortby) == len(order) { | ||
70 | + // 1) for each sort field, there is an associated order | ||
71 | + for i, v := range sortby { | ||
72 | + orderby := "" | ||
73 | + if order[i] == "desc" { | ||
74 | + orderby = "-" + v | ||
75 | + } else if order[i] == "asc" { | ||
76 | + orderby = v | ||
77 | + } else { | ||
78 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
79 | + } | ||
80 | + sortFields = append(sortFields, orderby) | ||
81 | + } | ||
82 | + qs = qs.OrderBy(sortFields...) | ||
83 | + } else if len(sortby) != len(order) && len(order) == 1 { | ||
84 | + // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
85 | + for _, v := range sortby { | ||
86 | + orderby := "" | ||
87 | + if order[0] == "desc" { | ||
88 | + orderby = "-" + v | ||
89 | + } else if order[0] == "asc" { | ||
90 | + orderby = v | ||
91 | + } else { | ||
92 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
93 | + } | ||
94 | + sortFields = append(sortFields, orderby) | ||
95 | + } | ||
96 | + } else if len(sortby) != len(order) && len(order) != 1 { | ||
97 | + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
98 | + } | ||
99 | + } else { | ||
100 | + if len(order) != 0 { | ||
101 | + return nil, errors.New("Error: unused 'order' fields") | ||
102 | + } | ||
103 | + } | ||
104 | + | ||
105 | + var l []Departments | ||
106 | + qs = qs.OrderBy(sortFields...) | ||
107 | + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
108 | + if len(fields) == 0 { | ||
109 | + for _, v := range l { | ||
110 | + ml = append(ml, v) | ||
111 | + } | ||
112 | + } else { | ||
113 | + // trim unused fields | ||
114 | + for _, v := range l { | ||
115 | + m := make(map[string]interface{}) | ||
116 | + val := reflect.ValueOf(v) | ||
117 | + for _, fname := range fields { | ||
118 | + m[fname] = val.FieldByName(fname).Interface() | ||
119 | + } | ||
120 | + ml = append(ml, m) | ||
121 | + } | ||
122 | + } | ||
123 | + return ml, nil | ||
124 | + } | ||
125 | + return nil, err | ||
126 | +} | ||
127 | + | ||
128 | +// UpdateDepartments updates Departments by Id and returns error if | ||
129 | +// the record to be updated doesn't exist | ||
130 | +func UpdateDepartmentsById(m *Departments) (err error) { | ||
131 | + o := orm.NewOrm() | ||
132 | + v := Departments{Id: m.Id} | ||
133 | + // ascertain id exists in the database | ||
134 | + if err = o.Read(&v); err == nil { | ||
135 | + var num int64 | ||
136 | + if num, err = o.Update(m); err == nil { | ||
137 | + fmt.Println("Number of records updated in database:", num) | ||
138 | + } | ||
139 | + } | ||
140 | + return | ||
141 | +} | ||
142 | + | ||
143 | +// DeleteDepartments deletes Departments by Id and returns error if | ||
144 | +// the record to be deleted doesn't exist | ||
145 | +func DeleteDepartments(id int) (err error) { | ||
146 | + o := orm.NewOrm() | ||
147 | + v := Departments{Id: id} | ||
148 | + // ascertain id exists in the database | ||
149 | + if err = o.Read(&v); err == nil { | ||
150 | + var num int64 | ||
151 | + if num, err = o.Delete(&Departments{Id: id}); err == nil { | ||
152 | + fmt.Println("Number of records deleted in database:", num) | ||
153 | + } | ||
154 | + } | ||
155 | + return | ||
156 | +} |
models/log_uuid.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "errors" | ||
5 | + "fmt" | ||
6 | + "reflect" | ||
7 | + "strings" | ||
8 | + | ||
9 | + "github.com/astaxie/beego/orm" | ||
10 | +) | ||
11 | + | ||
12 | +type LogUuid struct { | ||
13 | + Id int `orm:"column(id);auto" description:"主键ID"` | ||
14 | + Uuid string `orm:"column(uuid);size(128)"` | ||
15 | +} | ||
16 | + | ||
17 | +func (t *LogUuid) TableName() string { | ||
18 | + return "log_uuid" | ||
19 | +} | ||
20 | + | ||
21 | +func init() { | ||
22 | + orm.RegisterModel(new(LogUuid)) | ||
23 | +} | ||
24 | + | ||
25 | +// AddLogUuid insert a new LogUuid into database and returns | ||
26 | +// last inserted Id on success. | ||
27 | +func AddLogUuid(m *LogUuid) (id int64, err error) { | ||
28 | + o := orm.NewOrm() | ||
29 | + id, err = o.Insert(m) | ||
30 | + return | ||
31 | +} | ||
32 | + | ||
33 | +// GetLogUuidById retrieves LogUuid by Id. Returns error if | ||
34 | +// Id doesn't exist | ||
35 | +func GetLogUuidById(id int) (v *LogUuid, err error) { | ||
36 | + o := orm.NewOrm() | ||
37 | + v = &LogUuid{Id: id} | ||
38 | + if err = o.Read(v); err == nil { | ||
39 | + return v, nil | ||
40 | + } | ||
41 | + return nil, err | ||
42 | +} | ||
43 | + | ||
44 | +// GetAllLogUuid retrieves all LogUuid matches certain condition. Returns empty list if | ||
45 | +// no records exist | ||
46 | +func GetAllLogUuid(query map[string]string, fields []string, sortby []string, order []string, | ||
47 | + offset int64, limit int64) (ml []interface{}, err error) { | ||
48 | + o := orm.NewOrm() | ||
49 | + qs := o.QueryTable(new(LogUuid)) | ||
50 | + // query k=v | ||
51 | + for k, v := range query { | ||
52 | + // rewrite dot-notation to Object__Attribute | ||
53 | + k = strings.Replace(k, ".", "__", -1) | ||
54 | + if strings.Contains(k, "isnull") { | ||
55 | + qs = qs.Filter(k, (v == "true" || v == "1")) | ||
56 | + } else { | ||
57 | + qs = qs.Filter(k, v) | ||
58 | + } | ||
59 | + } | ||
60 | + // order by: | ||
61 | + var sortFields []string | ||
62 | + if len(sortby) != 0 { | ||
63 | + if len(sortby) == len(order) { | ||
64 | + // 1) for each sort field, there is an associated order | ||
65 | + for i, v := range sortby { | ||
66 | + orderby := "" | ||
67 | + if order[i] == "desc" { | ||
68 | + orderby = "-" + v | ||
69 | + } else if order[i] == "asc" { | ||
70 | + orderby = v | ||
71 | + } else { | ||
72 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
73 | + } | ||
74 | + sortFields = append(sortFields, orderby) | ||
75 | + } | ||
76 | + qs = qs.OrderBy(sortFields...) | ||
77 | + } else if len(sortby) != len(order) && len(order) == 1 { | ||
78 | + // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
79 | + for _, v := range sortby { | ||
80 | + orderby := "" | ||
81 | + if order[0] == "desc" { | ||
82 | + orderby = "-" + v | ||
83 | + } else if order[0] == "asc" { | ||
84 | + orderby = v | ||
85 | + } else { | ||
86 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
87 | + } | ||
88 | + sortFields = append(sortFields, orderby) | ||
89 | + } | ||
90 | + } else if len(sortby) != len(order) && len(order) != 1 { | ||
91 | + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
92 | + } | ||
93 | + } else { | ||
94 | + if len(order) != 0 { | ||
95 | + return nil, errors.New("Error: unused 'order' fields") | ||
96 | + } | ||
97 | + } | ||
98 | + | ||
99 | + var l []LogUuid | ||
100 | + qs = qs.OrderBy(sortFields...) | ||
101 | + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
102 | + if len(fields) == 0 { | ||
103 | + for _, v := range l { | ||
104 | + ml = append(ml, v) | ||
105 | + } | ||
106 | + } else { | ||
107 | + // trim unused fields | ||
108 | + for _, v := range l { | ||
109 | + m := make(map[string]interface{}) | ||
110 | + val := reflect.ValueOf(v) | ||
111 | + for _, fname := range fields { | ||
112 | + m[fname] = val.FieldByName(fname).Interface() | ||
113 | + } | ||
114 | + ml = append(ml, m) | ||
115 | + } | ||
116 | + } | ||
117 | + return ml, nil | ||
118 | + } | ||
119 | + return nil, err | ||
120 | +} | ||
121 | + | ||
122 | +// UpdateLogUuid updates LogUuid by Id and returns error if | ||
123 | +// the record to be updated doesn't exist | ||
124 | +func UpdateLogUuidById(m *LogUuid) (err error) { | ||
125 | + o := orm.NewOrm() | ||
126 | + v := LogUuid{Id: m.Id} | ||
127 | + // ascertain id exists in the database | ||
128 | + if err = o.Read(&v); err == nil { | ||
129 | + var num int64 | ||
130 | + if num, err = o.Update(m); err == nil { | ||
131 | + fmt.Println("Number of records updated in database:", num) | ||
132 | + } | ||
133 | + } | ||
134 | + return | ||
135 | +} | ||
136 | + | ||
137 | +// DeleteLogUuid deletes LogUuid by Id and returns error if | ||
138 | +// the record to be deleted doesn't exist | ||
139 | +func DeleteLogUuid(id int) (err error) { | ||
140 | + o := orm.NewOrm() | ||
141 | + v := LogUuid{Id: id} | ||
142 | + // ascertain id exists in the database | ||
143 | + if err = o.Read(&v); err == nil { | ||
144 | + var num int64 | ||
145 | + if num, err = o.Delete(&LogUuid{Id: id}); err == nil { | ||
146 | + fmt.Println("Number of records deleted in database:", num) | ||
147 | + } | ||
148 | + } | ||
149 | + return | ||
150 | +} |
models/logic.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "errors" | ||
5 | + "fmt" | ||
6 | + "reflect" | ||
7 | + "strings" | ||
8 | + | ||
9 | + "github.com/astaxie/beego/orm" | ||
10 | +) | ||
11 | + | ||
12 | +type Logic struct { | ||
13 | + Id int `orm:"column(id);auto"` | ||
14 | + Data string `orm:"column(data);null"` | ||
15 | + Db string `orm:"column(db);size(50);null"` | ||
16 | + Datatype string `orm:"column(datatype);size(50);null"` | ||
17 | + Type string `orm:"column(type);size(100);null"` | ||
18 | + Defaultparam string `orm:"column(defaultparam);size(200);null"` | ||
19 | +} | ||
20 | + | ||
21 | +func (t *Logic) TableName() string { | ||
22 | + return "logic" | ||
23 | +} | ||
24 | + | ||
25 | +func init() { | ||
26 | + orm.RegisterModel(new(Logic)) | ||
27 | +} | ||
28 | + | ||
29 | +// AddLogic insert a new Logic into database and returns | ||
30 | +// last inserted Id on success. | ||
31 | +func AddLogic(m *Logic) (id int64, err error) { | ||
32 | + o := orm.NewOrm() | ||
33 | + id, err = o.Insert(m) | ||
34 | + return | ||
35 | +} | ||
36 | + | ||
37 | +// GetLogicById retrieves Logic by Id. Returns error if | ||
38 | +// Id doesn't exist | ||
39 | +func GetLogicById(id int) (v *Logic, err error) { | ||
40 | + o := orm.NewOrm() | ||
41 | + v = &Logic{Id: id} | ||
42 | + if err = o.Read(v); err == nil { | ||
43 | + return v, nil | ||
44 | + } | ||
45 | + return nil, err | ||
46 | +} | ||
47 | + | ||
48 | +// GetAllLogic retrieves all Logic matches certain condition. Returns empty list if | ||
49 | +// no records exist | ||
50 | +func GetAllLogic(query map[string]string, fields []string, sortby []string, order []string, | ||
51 | + offset int64, limit int64) (ml []interface{}, err error) { | ||
52 | + o := orm.NewOrm() | ||
53 | + qs := o.QueryTable(new(Logic)) | ||
54 | + // query k=v | ||
55 | + for k, v := range query { | ||
56 | + // rewrite dot-notation to Object__Attribute | ||
57 | + k = strings.Replace(k, ".", "__", -1) | ||
58 | + if strings.Contains(k, "isnull") { | ||
59 | + qs = qs.Filter(k, (v == "true" || v == "1")) | ||
60 | + } else { | ||
61 | + qs = qs.Filter(k, v) | ||
62 | + } | ||
63 | + } | ||
64 | + // order by: | ||
65 | + var sortFields []string | ||
66 | + if len(sortby) != 0 { | ||
67 | + if len(sortby) == len(order) { | ||
68 | + // 1) for each sort field, there is an associated order | ||
69 | + for i, v := range sortby { | ||
70 | + orderby := "" | ||
71 | + if order[i] == "desc" { | ||
72 | + orderby = "-" + v | ||
73 | + } else if order[i] == "asc" { | ||
74 | + orderby = v | ||
75 | + } else { | ||
76 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
77 | + } | ||
78 | + sortFields = append(sortFields, orderby) | ||
79 | + } | ||
80 | + qs = qs.OrderBy(sortFields...) | ||
81 | + } else if len(sortby) != len(order) && len(order) == 1 { | ||
82 | + // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
83 | + for _, v := range sortby { | ||
84 | + orderby := "" | ||
85 | + if order[0] == "desc" { | ||
86 | + orderby = "-" + v | ||
87 | + } else if order[0] == "asc" { | ||
88 | + orderby = v | ||
89 | + } else { | ||
90 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
91 | + } | ||
92 | + sortFields = append(sortFields, orderby) | ||
93 | + } | ||
94 | + } else if len(sortby) != len(order) && len(order) != 1 { | ||
95 | + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
96 | + } | ||
97 | + } else { | ||
98 | + if len(order) != 0 { | ||
99 | + return nil, errors.New("Error: unused 'order' fields") | ||
100 | + } | ||
101 | + } | ||
102 | + | ||
103 | + var l []Logic | ||
104 | + qs = qs.OrderBy(sortFields...) | ||
105 | + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
106 | + if len(fields) == 0 { | ||
107 | + for _, v := range l { | ||
108 | + ml = append(ml, v) | ||
109 | + } | ||
110 | + } else { | ||
111 | + // trim unused fields | ||
112 | + for _, v := range l { | ||
113 | + m := make(map[string]interface{}) | ||
114 | + val := reflect.ValueOf(v) | ||
115 | + for _, fname := range fields { | ||
116 | + m[fname] = val.FieldByName(fname).Interface() | ||
117 | + } | ||
118 | + ml = append(ml, m) | ||
119 | + } | ||
120 | + } | ||
121 | + return ml, nil | ||
122 | + } | ||
123 | + return nil, err | ||
124 | +} | ||
125 | + | ||
126 | +// UpdateLogic updates Logic by Id and returns error if | ||
127 | +// the record to be updated doesn't exist | ||
128 | +func UpdateLogicById(m *Logic) (err error) { | ||
129 | + o := orm.NewOrm() | ||
130 | + v := Logic{Id: m.Id} | ||
131 | + // ascertain id exists in the database | ||
132 | + if err = o.Read(&v); err == nil { | ||
133 | + var num int64 | ||
134 | + if num, err = o.Update(m); err == nil { | ||
135 | + fmt.Println("Number of records updated in database:", num) | ||
136 | + } | ||
137 | + } | ||
138 | + return | ||
139 | +} | ||
140 | + | ||
141 | +// DeleteLogic deletes Logic by Id and returns error if | ||
142 | +// the record to be deleted doesn't exist | ||
143 | +func DeleteLogic(id int) (err error) { | ||
144 | + o := orm.NewOrm() | ||
145 | + v := Logic{Id: id} | ||
146 | + // ascertain id exists in the database | ||
147 | + if err = o.Read(&v); err == nil { | ||
148 | + var num int64 | ||
149 | + if num, err = o.Delete(&Logic{Id: id}); err == nil { | ||
150 | + fmt.Println("Number of records deleted in database:", num) | ||
151 | + } | ||
152 | + } | ||
153 | + return | ||
154 | +} |
models/permissions.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "errors" | ||
5 | + "fmt" | ||
6 | + "reflect" | ||
7 | + "strings" | ||
8 | + | ||
9 | + "github.com/astaxie/beego/orm" | ||
10 | +) | ||
11 | + | ||
12 | +type Permissions struct { | ||
13 | + Id int `orm:"column(id);auto"` | ||
14 | + Name string `orm:"column(name);size(255)"` | ||
15 | + Value int8 `orm:"column(value)"` | ||
16 | +} | ||
17 | + | ||
18 | +func (t *Permissions) TableName() string { | ||
19 | + return "permissions" | ||
20 | +} | ||
21 | + | ||
22 | +func init() { | ||
23 | + orm.RegisterModel(new(Permissions)) | ||
24 | +} | ||
25 | + | ||
26 | +// AddPermissions insert a new Permissions into database and returns | ||
27 | +// last inserted Id on success. | ||
28 | +func AddPermissions(m *Permissions) (id int64, err error) { | ||
29 | + o := orm.NewOrm() | ||
30 | + id, err = o.Insert(m) | ||
31 | + return | ||
32 | +} | ||
33 | + | ||
34 | +// GetPermissionsById retrieves Permissions by Id. Returns error if | ||
35 | +// Id doesn't exist | ||
36 | +func GetPermissionsById(id int) (v *Permissions, err error) { | ||
37 | + o := orm.NewOrm() | ||
38 | + v = &Permissions{Id: id} | ||
39 | + if err = o.Read(v); err == nil { | ||
40 | + return v, nil | ||
41 | + } | ||
42 | + return nil, err | ||
43 | +} | ||
44 | + | ||
45 | +// GetAllPermissions retrieves all Permissions matches certain condition. Returns empty list if | ||
46 | +// no records exist | ||
47 | +func GetAllPermissions(query map[string]string, fields []string, sortby []string, order []string, | ||
48 | + offset int64, limit int64) (ml []interface{}, err error) { | ||
49 | + o := orm.NewOrm() | ||
50 | + qs := o.QueryTable(new(Permissions)) | ||
51 | + // query k=v | ||
52 | + for k, v := range query { | ||
53 | + // rewrite dot-notation to Object__Attribute | ||
54 | + k = strings.Replace(k, ".", "__", -1) | ||
55 | + if strings.Contains(k, "isnull") { | ||
56 | + qs = qs.Filter(k, (v == "true" || v == "1")) | ||
57 | + } else { | ||
58 | + qs = qs.Filter(k, v) | ||
59 | + } | ||
60 | + } | ||
61 | + // order by: | ||
62 | + var sortFields []string | ||
63 | + if len(sortby) != 0 { | ||
64 | + if len(sortby) == len(order) { | ||
65 | + // 1) for each sort field, there is an associated order | ||
66 | + for i, v := range sortby { | ||
67 | + orderby := "" | ||
68 | + if order[i] == "desc" { | ||
69 | + orderby = "-" + v | ||
70 | + } else if order[i] == "asc" { | ||
71 | + orderby = v | ||
72 | + } else { | ||
73 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
74 | + } | ||
75 | + sortFields = append(sortFields, orderby) | ||
76 | + } | ||
77 | + qs = qs.OrderBy(sortFields...) | ||
78 | + } else if len(sortby) != len(order) && len(order) == 1 { | ||
79 | + // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
80 | + for _, v := range sortby { | ||
81 | + orderby := "" | ||
82 | + if order[0] == "desc" { | ||
83 | + orderby = "-" + v | ||
84 | + } else if order[0] == "asc" { | ||
85 | + orderby = v | ||
86 | + } else { | ||
87 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
88 | + } | ||
89 | + sortFields = append(sortFields, orderby) | ||
90 | + } | ||
91 | + } else if len(sortby) != len(order) && len(order) != 1 { | ||
92 | + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
93 | + } | ||
94 | + } else { | ||
95 | + if len(order) != 0 { | ||
96 | + return nil, errors.New("Error: unused 'order' fields") | ||
97 | + } | ||
98 | + } | ||
99 | + | ||
100 | + var l []Permissions | ||
101 | + qs = qs.OrderBy(sortFields...) | ||
102 | + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
103 | + if len(fields) == 0 { | ||
104 | + for _, v := range l { | ||
105 | + ml = append(ml, v) | ||
106 | + } | ||
107 | + } else { | ||
108 | + // trim unused fields | ||
109 | + for _, v := range l { | ||
110 | + m := make(map[string]interface{}) | ||
111 | + val := reflect.ValueOf(v) | ||
112 | + for _, fname := range fields { | ||
113 | + m[fname] = val.FieldByName(fname).Interface() | ||
114 | + } | ||
115 | + ml = append(ml, m) | ||
116 | + } | ||
117 | + } | ||
118 | + return ml, nil | ||
119 | + } | ||
120 | + return nil, err | ||
121 | +} | ||
122 | + | ||
123 | +// UpdatePermissions updates Permissions by Id and returns error if | ||
124 | +// the record to be updated doesn't exist | ||
125 | +func UpdatePermissionsById(m *Permissions) (err error) { | ||
126 | + o := orm.NewOrm() | ||
127 | + v := Permissions{Id: m.Id} | ||
128 | + // ascertain id exists in the database | ||
129 | + if err = o.Read(&v); err == nil { | ||
130 | + var num int64 | ||
131 | + if num, err = o.Update(m); err == nil { | ||
132 | + fmt.Println("Number of records updated in database:", num) | ||
133 | + } | ||
134 | + } | ||
135 | + return | ||
136 | +} | ||
137 | + | ||
138 | +// DeletePermissions deletes Permissions by Id and returns error if | ||
139 | +// the record to be deleted doesn't exist | ||
140 | +func DeletePermissions(id int) (err error) { | ||
141 | + o := orm.NewOrm() | ||
142 | + v := Permissions{Id: id} | ||
143 | + // ascertain id exists in the database | ||
144 | + if err = o.Read(&v); err == nil { | ||
145 | + var num int64 | ||
146 | + if num, err = o.Delete(&Permissions{Id: id}); err == nil { | ||
147 | + fmt.Println("Number of records deleted in database:", num) | ||
148 | + } | ||
149 | + } | ||
150 | + return | ||
151 | +} |
models/pics_log.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "errors" | ||
5 | + "fmt" | ||
6 | + "reflect" | ||
7 | + "strings" | ||
8 | + | ||
9 | + "github.com/astaxie/beego/orm" | ||
10 | +) | ||
11 | + | ||
12 | +type PicsLog struct { | ||
13 | + Id int `orm:"column(id);auto" description:"主键ID"` | ||
14 | + Url string `orm:"column(url);size(128)"` | ||
15 | + Thumbnail string `orm:"column(thumbnail);size(128)" description:"缩略图"` | ||
16 | + Width int `orm:"column(width)" description:"宽度"` | ||
17 | + Length int `orm:"column(length)" description:"长度"` | ||
18 | +} | ||
19 | + | ||
20 | +func (t *PicsLog) TableName() string { | ||
21 | + return "pics_log" | ||
22 | +} | ||
23 | + | ||
24 | +func init() { | ||
25 | + orm.RegisterModel(new(PicsLog)) | ||
26 | +} | ||
27 | + | ||
28 | +// AddPicsLog insert a new PicsLog into database and returns | ||
29 | +// last inserted Id on success. | ||
30 | +func AddPicsLog(m *PicsLog) (id int64, err error) { | ||
31 | + o := orm.NewOrm() | ||
32 | + id, err = o.Insert(m) | ||
33 | + return | ||
34 | +} | ||
35 | + | ||
36 | +// GetPicsLogById retrieves PicsLog by Id. Returns error if | ||
37 | +// Id doesn't exist | ||
38 | +func GetPicsLogById(id int) (v *PicsLog, err error) { | ||
39 | + o := orm.NewOrm() | ||
40 | + v = &PicsLog{Id: id} | ||
41 | + if err = o.Read(v); err == nil { | ||
42 | + return v, nil | ||
43 | + } | ||
44 | + return nil, err | ||
45 | +} | ||
46 | + | ||
47 | +// GetAllPicsLog retrieves all PicsLog matches certain condition. Returns empty list if | ||
48 | +// no records exist | ||
49 | +func GetAllPicsLog(query map[string]string, fields []string, sortby []string, order []string, | ||
50 | + offset int64, limit int64) (ml []interface{}, err error) { | ||
51 | + o := orm.NewOrm() | ||
52 | + qs := o.QueryTable(new(PicsLog)) | ||
53 | + // query k=v | ||
54 | + for k, v := range query { | ||
55 | + // rewrite dot-notation to Object__Attribute | ||
56 | + k = strings.Replace(k, ".", "__", -1) | ||
57 | + if strings.Contains(k, "isnull") { | ||
58 | + qs = qs.Filter(k, (v == "true" || v == "1")) | ||
59 | + } else { | ||
60 | + qs = qs.Filter(k, v) | ||
61 | + } | ||
62 | + } | ||
63 | + // order by: | ||
64 | + var sortFields []string | ||
65 | + if len(sortby) != 0 { | ||
66 | + if len(sortby) == len(order) { | ||
67 | + // 1) for each sort field, there is an associated order | ||
68 | + for i, v := range sortby { | ||
69 | + orderby := "" | ||
70 | + if order[i] == "desc" { | ||
71 | + orderby = "-" + v | ||
72 | + } else if order[i] == "asc" { | ||
73 | + orderby = v | ||
74 | + } else { | ||
75 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
76 | + } | ||
77 | + sortFields = append(sortFields, orderby) | ||
78 | + } | ||
79 | + qs = qs.OrderBy(sortFields...) | ||
80 | + } else if len(sortby) != len(order) && len(order) == 1 { | ||
81 | + // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
82 | + for _, v := range sortby { | ||
83 | + orderby := "" | ||
84 | + if order[0] == "desc" { | ||
85 | + orderby = "-" + v | ||
86 | + } else if order[0] == "asc" { | ||
87 | + orderby = v | ||
88 | + } else { | ||
89 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
90 | + } | ||
91 | + sortFields = append(sortFields, orderby) | ||
92 | + } | ||
93 | + } else if len(sortby) != len(order) && len(order) != 1 { | ||
94 | + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
95 | + } | ||
96 | + } else { | ||
97 | + if len(order) != 0 { | ||
98 | + return nil, errors.New("Error: unused 'order' fields") | ||
99 | + } | ||
100 | + } | ||
101 | + | ||
102 | + var l []PicsLog | ||
103 | + qs = qs.OrderBy(sortFields...) | ||
104 | + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
105 | + if len(fields) == 0 { | ||
106 | + for _, v := range l { | ||
107 | + ml = append(ml, v) | ||
108 | + } | ||
109 | + } else { | ||
110 | + // trim unused fields | ||
111 | + for _, v := range l { | ||
112 | + m := make(map[string]interface{}) | ||
113 | + val := reflect.ValueOf(v) | ||
114 | + for _, fname := range fields { | ||
115 | + m[fname] = val.FieldByName(fname).Interface() | ||
116 | + } | ||
117 | + ml = append(ml, m) | ||
118 | + } | ||
119 | + } | ||
120 | + return ml, nil | ||
121 | + } | ||
122 | + return nil, err | ||
123 | +} | ||
124 | + | ||
125 | +// UpdatePicsLog updates PicsLog by Id and returns error if | ||
126 | +// the record to be updated doesn't exist | ||
127 | +func UpdatePicsLogById(m *PicsLog) (err error) { | ||
128 | + o := orm.NewOrm() | ||
129 | + v := PicsLog{Id: m.Id} | ||
130 | + // ascertain id exists in the database | ||
131 | + if err = o.Read(&v); err == nil { | ||
132 | + var num int64 | ||
133 | + if num, err = o.Update(m); err == nil { | ||
134 | + fmt.Println("Number of records updated in database:", num) | ||
135 | + } | ||
136 | + } | ||
137 | + return | ||
138 | +} | ||
139 | + | ||
140 | +// DeletePicsLog deletes PicsLog by Id and returns error if | ||
141 | +// the record to be deleted doesn't exist | ||
142 | +func DeletePicsLog(id int) (err error) { | ||
143 | + o := orm.NewOrm() | ||
144 | + v := PicsLog{Id: id} | ||
145 | + // ascertain id exists in the database | ||
146 | + if err = o.Read(&v); err == nil { | ||
147 | + var num int64 | ||
148 | + if num, err = o.Delete(&PicsLog{Id: id}); err == nil { | ||
149 | + fmt.Println("Number of records deleted in database:", num) | ||
150 | + } | ||
151 | + } | ||
152 | + return | ||
153 | +} |
models/positions.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "errors" | ||
5 | + "fmt" | ||
6 | + "reflect" | ||
7 | + "strings" | ||
8 | + "time" | ||
9 | + | ||
10 | + "github.com/astaxie/beego/orm" | ||
11 | +) | ||
12 | + | ||
13 | +type Positions struct { | ||
14 | + Id int `orm:"column(id);auto"` | ||
15 | + CompanyId int `orm:"column(company_id)"` | ||
16 | + Name string `orm:"column(name);size(255)"` | ||
17 | + Pid string `orm:"column(pid);size(255)"` | ||
18 | + Path string `orm:"column(path);size(1000)"` | ||
19 | + Level int8 `orm:"column(level)" description:"级别"` | ||
20 | + CreateTime time.Time `orm:"column(create_time);type(timestamp);auto_now"` | ||
21 | + Enabled int8 `orm:"column(enabled)"` | ||
22 | +} | ||
23 | + | ||
24 | +func (t *Positions) TableName() string { | ||
25 | + return "positions" | ||
26 | +} | ||
27 | + | ||
28 | +func init() { | ||
29 | + orm.RegisterModel(new(Positions)) | ||
30 | +} | ||
31 | + | ||
32 | +// AddPositions insert a new Positions into database and returns | ||
33 | +// last inserted Id on success. | ||
34 | +func AddPositions(m *Positions) (id int64, err error) { | ||
35 | + o := orm.NewOrm() | ||
36 | + id, err = o.Insert(m) | ||
37 | + return | ||
38 | +} | ||
39 | + | ||
40 | +// GetPositionsById retrieves Positions by Id. Returns error if | ||
41 | +// Id doesn't exist | ||
42 | +func GetPositionsById(id int) (v *Positions, err error) { | ||
43 | + o := orm.NewOrm() | ||
44 | + v = &Positions{Id: id} | ||
45 | + if err = o.Read(v); err == nil { | ||
46 | + return v, nil | ||
47 | + } | ||
48 | + return nil, err | ||
49 | +} | ||
50 | + | ||
51 | +// GetAllPositions retrieves all Positions matches certain condition. Returns empty list if | ||
52 | +// no records exist | ||
53 | +func GetAllPositions(query map[string]string, fields []string, sortby []string, order []string, | ||
54 | + offset int64, limit int64) (ml []interface{}, err error) { | ||
55 | + o := orm.NewOrm() | ||
56 | + qs := o.QueryTable(new(Positions)) | ||
57 | + // query k=v | ||
58 | + for k, v := range query { | ||
59 | + // rewrite dot-notation to Object__Attribute | ||
60 | + k = strings.Replace(k, ".", "__", -1) | ||
61 | + if strings.Contains(k, "isnull") { | ||
62 | + qs = qs.Filter(k, (v == "true" || v == "1")) | ||
63 | + } else { | ||
64 | + qs = qs.Filter(k, v) | ||
65 | + } | ||
66 | + } | ||
67 | + // order by: | ||
68 | + var sortFields []string | ||
69 | + if len(sortby) != 0 { | ||
70 | + if len(sortby) == len(order) { | ||
71 | + // 1) for each sort field, there is an associated order | ||
72 | + for i, v := range sortby { | ||
73 | + orderby := "" | ||
74 | + if order[i] == "desc" { | ||
75 | + orderby = "-" + v | ||
76 | + } else if order[i] == "asc" { | ||
77 | + orderby = v | ||
78 | + } else { | ||
79 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
80 | + } | ||
81 | + sortFields = append(sortFields, orderby) | ||
82 | + } | ||
83 | + qs = qs.OrderBy(sortFields...) | ||
84 | + } else if len(sortby) != len(order) && len(order) == 1 { | ||
85 | + // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
86 | + for _, v := range sortby { | ||
87 | + orderby := "" | ||
88 | + if order[0] == "desc" { | ||
89 | + orderby = "-" + v | ||
90 | + } else if order[0] == "asc" { | ||
91 | + orderby = v | ||
92 | + } else { | ||
93 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
94 | + } | ||
95 | + sortFields = append(sortFields, orderby) | ||
96 | + } | ||
97 | + } else if len(sortby) != len(order) && len(order) != 1 { | ||
98 | + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
99 | + } | ||
100 | + } else { | ||
101 | + if len(order) != 0 { | ||
102 | + return nil, errors.New("Error: unused 'order' fields") | ||
103 | + } | ||
104 | + } | ||
105 | + | ||
106 | + var l []Positions | ||
107 | + qs = qs.OrderBy(sortFields...) | ||
108 | + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
109 | + if len(fields) == 0 { | ||
110 | + for _, v := range l { | ||
111 | + ml = append(ml, v) | ||
112 | + } | ||
113 | + } else { | ||
114 | + // trim unused fields | ||
115 | + for _, v := range l { | ||
116 | + m := make(map[string]interface{}) | ||
117 | + val := reflect.ValueOf(v) | ||
118 | + for _, fname := range fields { | ||
119 | + m[fname] = val.FieldByName(fname).Interface() | ||
120 | + } | ||
121 | + ml = append(ml, m) | ||
122 | + } | ||
123 | + } | ||
124 | + return ml, nil | ||
125 | + } | ||
126 | + return nil, err | ||
127 | +} | ||
128 | + | ||
129 | +// UpdatePositions updates Positions by Id and returns error if | ||
130 | +// the record to be updated doesn't exist | ||
131 | +func UpdatePositionsById(m *Positions) (err error) { | ||
132 | + o := orm.NewOrm() | ||
133 | + v := Positions{Id: m.Id} | ||
134 | + // ascertain id exists in the database | ||
135 | + if err = o.Read(&v); err == nil { | ||
136 | + var num int64 | ||
137 | + if num, err = o.Update(m); err == nil { | ||
138 | + fmt.Println("Number of records updated in database:", num) | ||
139 | + } | ||
140 | + } | ||
141 | + return | ||
142 | +} | ||
143 | + | ||
144 | +// DeletePositions deletes Positions by Id and returns error if | ||
145 | +// the record to be deleted doesn't exist | ||
146 | +func DeletePositions(id int) (err error) { | ||
147 | + o := orm.NewOrm() | ||
148 | + v := Positions{Id: id} | ||
149 | + // ascertain id exists in the database | ||
150 | + if err = o.Read(&v); err == nil { | ||
151 | + var num int64 | ||
152 | + if num, err = o.Delete(&Positions{Id: id}); err == nil { | ||
153 | + fmt.Println("Number of records deleted in database:", num) | ||
154 | + } | ||
155 | + } | ||
156 | + return | ||
157 | +} |
models/question.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "errors" | ||
5 | + "fmt" | ||
6 | + "reflect" | ||
7 | + "strings" | ||
8 | + "time" | ||
9 | + | ||
10 | + "github.com/astaxie/beego/orm" | ||
11 | +) | ||
12 | + | ||
13 | +type Question struct { | ||
14 | + Id int `orm:"column(id);pk"` | ||
15 | + Title string `orm:"column(title);size(30)" description:"标题"` | ||
16 | + Content string `orm:"column(content)" description:"内容"` | ||
17 | + Uid int64 `orm:"column(uid)" description:"用户ID"` | ||
18 | + CreateTime time.Time `orm:"column(createTime);type(timestamp);auto_now_add"` | ||
19 | + Way int `orm:"column(way)" description:"提问方式(0语音,1图文)"` | ||
20 | + PageView int `orm:"column(pageView)" description:"浏览总数"` | ||
21 | + CommentTotal int `orm:"column(commentTotal)" description:"评论总数"` | ||
22 | + SympathyTotal int `orm:"column(sympathyTotal)" description:"同感总数"` | ||
23 | + Review int `orm:"column(review)" description:"0 待审核 1已审核"` | ||
24 | + Status int `orm:"column(status);null" description:"状态 0 未解决 1已解决"` | ||
25 | + UpdateTime time.Time `orm:"column(updateTime);type(timestamp);null"` | ||
26 | + ScoreAnalyze int `orm:"column(scoreAnalyze);null" description:"分析评分"` | ||
27 | + ScoreAsk int `orm:"column(scoreAsk);null" description:"提问评分"` | ||
28 | + ScoreScheme int `orm:"column(scoreScheme);null" description:"方案评分"` | ||
29 | + Published int `orm:"column(published);null" description:"公开状态 0未公开、1本部门公开、2本公司公开"` | ||
30 | + Level int `orm:"column(level)" description:"最后评分或审核人的级别"` | ||
31 | + CheckUid int64 `orm:"column(checkUid);null" description:"审核人ID"` | ||
32 | + Enabled int `orm:"column(enabled);null" description:"1有效 0删除"` | ||
33 | + Tlevel int `orm:"column(tlevel)" description:"公开操作权限"` | ||
34 | + PfUid int64 `orm:"column(pfUid)"` | ||
35 | + QType int `orm:"column(qType)"` | ||
36 | + SoluteTime time.Time `orm:"column(soluteTime);type(timestamp);auto_now_add"` | ||
37 | + ResolverTime time.Time `orm:"column(resolverTime);type(timestamp);auto_now_add"` | ||
38 | + Resolver int64 `orm:"column(resolver)"` | ||
39 | + RelevantDepartmentId int `orm:"column(relevantDepartmentId)" description:"相关部门id"` | ||
40 | + ReceiveStatus int8 `orm:"column(receiveStatus)" description:"领取状态 0未领取 1已领取"` | ||
41 | +} | ||
42 | + | ||
43 | +func (t *Question) TableName() string { | ||
44 | + return "question" | ||
45 | +} | ||
46 | + | ||
47 | +func init() { | ||
48 | + orm.RegisterModel(new(Question)) | ||
49 | +} | ||
50 | + | ||
51 | +// AddQuestion insert a new Question into database and returns | ||
52 | +// last inserted Id on success. | ||
53 | +func AddQuestion(m *Question) (id int64, err error) { | ||
54 | + o := orm.NewOrm() | ||
55 | + id, err = o.Insert(m) | ||
56 | + return | ||
57 | +} | ||
58 | + | ||
59 | +// GetQuestionById retrieves Question by Id. Returns error if | ||
60 | +// Id doesn't exist | ||
61 | +func GetQuestionById(id int) (v *Question, err error) { | ||
62 | + o := orm.NewOrm() | ||
63 | + v = &Question{Id: id} | ||
64 | + if err = o.Read(v); err == nil { | ||
65 | + return v, nil | ||
66 | + } | ||
67 | + return nil, err | ||
68 | +} | ||
69 | + | ||
70 | +// GetAllQuestion retrieves all Question matches certain condition. Returns empty list if | ||
71 | +// no records exist | ||
72 | +func GetAllQuestion(query map[string]string, fields []string, sortby []string, order []string, | ||
73 | + offset int64, limit int64) (ml []interface{}, err error) { | ||
74 | + o := orm.NewOrm() | ||
75 | + qs := o.QueryTable(new(Question)) | ||
76 | + // query k=v | ||
77 | + for k, v := range query { | ||
78 | + // rewrite dot-notation to Object__Attribute | ||
79 | + k = strings.Replace(k, ".", "__", -1) | ||
80 | + if strings.Contains(k, "isnull") { | ||
81 | + qs = qs.Filter(k, (v == "true" || v == "1")) | ||
82 | + } else { | ||
83 | + qs = qs.Filter(k, v) | ||
84 | + } | ||
85 | + } | ||
86 | + // order by: | ||
87 | + var sortFields []string | ||
88 | + if len(sortby) != 0 { | ||
89 | + if len(sortby) == len(order) { | ||
90 | + // 1) for each sort field, there is an associated order | ||
91 | + for i, v := range sortby { | ||
92 | + orderby := "" | ||
93 | + if order[i] == "desc" { | ||
94 | + orderby = "-" + v | ||
95 | + } else if order[i] == "asc" { | ||
96 | + orderby = v | ||
97 | + } else { | ||
98 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
99 | + } | ||
100 | + sortFields = append(sortFields, orderby) | ||
101 | + } | ||
102 | + qs = qs.OrderBy(sortFields...) | ||
103 | + } else if len(sortby) != len(order) && len(order) == 1 { | ||
104 | + // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
105 | + for _, v := range sortby { | ||
106 | + orderby := "" | ||
107 | + if order[0] == "desc" { | ||
108 | + orderby = "-" + v | ||
109 | + } else if order[0] == "asc" { | ||
110 | + orderby = v | ||
111 | + } else { | ||
112 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
113 | + } | ||
114 | + sortFields = append(sortFields, orderby) | ||
115 | + } | ||
116 | + } else if len(sortby) != len(order) && len(order) != 1 { | ||
117 | + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
118 | + } | ||
119 | + } else { | ||
120 | + if len(order) != 0 { | ||
121 | + return nil, errors.New("Error: unused 'order' fields") | ||
122 | + } | ||
123 | + } | ||
124 | + | ||
125 | + var l []Question | ||
126 | + qs = qs.OrderBy(sortFields...) | ||
127 | + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
128 | + if len(fields) == 0 { | ||
129 | + for _, v := range l { | ||
130 | + ml = append(ml, v) | ||
131 | + } | ||
132 | + } else { | ||
133 | + // trim unused fields | ||
134 | + for _, v := range l { | ||
135 | + m := make(map[string]interface{}) | ||
136 | + val := reflect.ValueOf(v) | ||
137 | + for _, fname := range fields { | ||
138 | + m[fname] = val.FieldByName(fname).Interface() | ||
139 | + } | ||
140 | + ml = append(ml, m) | ||
141 | + } | ||
142 | + } | ||
143 | + return ml, nil | ||
144 | + } | ||
145 | + return nil, err | ||
146 | +} | ||
147 | + | ||
148 | +// UpdateQuestion updates Question by Id and returns error if | ||
149 | +// the record to be updated doesn't exist | ||
150 | +func UpdateQuestionById(m *Question) (err error) { | ||
151 | + o := orm.NewOrm() | ||
152 | + v := Question{Id: m.Id} | ||
153 | + // ascertain id exists in the database | ||
154 | + if err = o.Read(&v); err == nil { | ||
155 | + var num int64 | ||
156 | + if num, err = o.Update(m); err == nil { | ||
157 | + fmt.Println("Number of records updated in database:", num) | ||
158 | + } | ||
159 | + } | ||
160 | + return | ||
161 | +} | ||
162 | + | ||
163 | +// DeleteQuestion deletes Question by Id and returns error if | ||
164 | +// the record to be deleted doesn't exist | ||
165 | +func DeleteQuestion(id int) (err error) { | ||
166 | + o := orm.NewOrm() | ||
167 | + v := Question{Id: id} | ||
168 | + // ascertain id exists in the database | ||
169 | + if err = o.Read(&v); err == nil { | ||
170 | + var num int64 | ||
171 | + if num, err = o.Delete(&Question{Id: id}); err == nil { | ||
172 | + fmt.Println("Number of records deleted in database:", num) | ||
173 | + } | ||
174 | + } | ||
175 | + return | ||
176 | +} |
models/question_department.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "errors" | ||
5 | + "fmt" | ||
6 | + "reflect" | ||
7 | + "strings" | ||
8 | + "time" | ||
9 | + | ||
10 | + "github.com/astaxie/beego/orm" | ||
11 | +) | ||
12 | + | ||
13 | +type QuestionDepartment struct { | ||
14 | + Id int `orm:"column(id);pk"` | ||
15 | + Qid int64 `orm:"column(qid)" description:"所属的问题ID"` | ||
16 | + DepartmentId int `orm:"column(department_id)" description:"语音路径"` | ||
17 | + CreateTime time.Time `orm:"column(createTime);type(timestamp);auto_now_add"` | ||
18 | +} | ||
19 | + | ||
20 | +func (t *QuestionDepartment) TableName() string { | ||
21 | + return "question_department" | ||
22 | +} | ||
23 | + | ||
24 | +func init() { | ||
25 | + orm.RegisterModel(new(QuestionDepartment)) | ||
26 | +} | ||
27 | + | ||
28 | +// AddQuestionDepartment insert a new QuestionDepartment into database and returns | ||
29 | +// last inserted Id on success. | ||
30 | +func AddQuestionDepartment(m *QuestionDepartment) (id int64, err error) { | ||
31 | + o := orm.NewOrm() | ||
32 | + id, err = o.Insert(m) | ||
33 | + return | ||
34 | +} | ||
35 | + | ||
36 | +// GetQuestionDepartmentById retrieves QuestionDepartment by Id. Returns error if | ||
37 | +// Id doesn't exist | ||
38 | +func GetQuestionDepartmentById(id int) (v *QuestionDepartment, err error) { | ||
39 | + o := orm.NewOrm() | ||
40 | + v = &QuestionDepartment{Id: id} | ||
41 | + if err = o.Read(v); err == nil { | ||
42 | + return v, nil | ||
43 | + } | ||
44 | + return nil, err | ||
45 | +} | ||
46 | + | ||
47 | +// GetAllQuestionDepartment retrieves all QuestionDepartment matches certain condition. Returns empty list if | ||
48 | +// no records exist | ||
49 | +func GetAllQuestionDepartment(query map[string]string, fields []string, sortby []string, order []string, | ||
50 | + offset int64, limit int64) (ml []interface{}, err error) { | ||
51 | + o := orm.NewOrm() | ||
52 | + qs := o.QueryTable(new(QuestionDepartment)) | ||
53 | + // query k=v | ||
54 | + for k, v := range query { | ||
55 | + // rewrite dot-notation to Object__Attribute | ||
56 | + k = strings.Replace(k, ".", "__", -1) | ||
57 | + if strings.Contains(k, "isnull") { | ||
58 | + qs = qs.Filter(k, (v == "true" || v == "1")) | ||
59 | + } else { | ||
60 | + qs = qs.Filter(k, v) | ||
61 | + } | ||
62 | + } | ||
63 | + // order by: | ||
64 | + var sortFields []string | ||
65 | + if len(sortby) != 0 { | ||
66 | + if len(sortby) == len(order) { | ||
67 | + // 1) for each sort field, there is an associated order | ||
68 | + for i, v := range sortby { | ||
69 | + orderby := "" | ||
70 | + if order[i] == "desc" { | ||
71 | + orderby = "-" + v | ||
72 | + } else if order[i] == "asc" { | ||
73 | + orderby = v | ||
74 | + } else { | ||
75 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
76 | + } | ||
77 | + sortFields = append(sortFields, orderby) | ||
78 | + } | ||
79 | + qs = qs.OrderBy(sortFields...) | ||
80 | + } else if len(sortby) != len(order) && len(order) == 1 { | ||
81 | + // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
82 | + for _, v := range sortby { | ||
83 | + orderby := "" | ||
84 | + if order[0] == "desc" { | ||
85 | + orderby = "-" + v | ||
86 | + } else if order[0] == "asc" { | ||
87 | + orderby = v | ||
88 | + } else { | ||
89 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
90 | + } | ||
91 | + sortFields = append(sortFields, orderby) | ||
92 | + } | ||
93 | + } else if len(sortby) != len(order) && len(order) != 1 { | ||
94 | + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
95 | + } | ||
96 | + } else { | ||
97 | + if len(order) != 0 { | ||
98 | + return nil, errors.New("Error: unused 'order' fields") | ||
99 | + } | ||
100 | + } | ||
101 | + | ||
102 | + var l []QuestionDepartment | ||
103 | + qs = qs.OrderBy(sortFields...) | ||
104 | + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
105 | + if len(fields) == 0 { | ||
106 | + for _, v := range l { | ||
107 | + ml = append(ml, v) | ||
108 | + } | ||
109 | + } else { | ||
110 | + // trim unused fields | ||
111 | + for _, v := range l { | ||
112 | + m := make(map[string]interface{}) | ||
113 | + val := reflect.ValueOf(v) | ||
114 | + for _, fname := range fields { | ||
115 | + m[fname] = val.FieldByName(fname).Interface() | ||
116 | + } | ||
117 | + ml = append(ml, m) | ||
118 | + } | ||
119 | + } | ||
120 | + return ml, nil | ||
121 | + } | ||
122 | + return nil, err | ||
123 | +} | ||
124 | + | ||
125 | +// UpdateQuestionDepartment updates QuestionDepartment by Id and returns error if | ||
126 | +// the record to be updated doesn't exist | ||
127 | +func UpdateQuestionDepartmentById(m *QuestionDepartment) (err error) { | ||
128 | + o := orm.NewOrm() | ||
129 | + v := QuestionDepartment{Id: m.Id} | ||
130 | + // ascertain id exists in the database | ||
131 | + if err = o.Read(&v); err == nil { | ||
132 | + var num int64 | ||
133 | + if num, err = o.Update(m); err == nil { | ||
134 | + fmt.Println("Number of records updated in database:", num) | ||
135 | + } | ||
136 | + } | ||
137 | + return | ||
138 | +} | ||
139 | + | ||
140 | +// DeleteQuestionDepartment deletes QuestionDepartment by Id and returns error if | ||
141 | +// the record to be deleted doesn't exist | ||
142 | +func DeleteQuestionDepartment(id int) (err error) { | ||
143 | + o := orm.NewOrm() | ||
144 | + v := QuestionDepartment{Id: id} | ||
145 | + // ascertain id exists in the database | ||
146 | + if err = o.Read(&v); err == nil { | ||
147 | + var num int64 | ||
148 | + if num, err = o.Delete(&QuestionDepartment{Id: id}); err == nil { | ||
149 | + fmt.Println("Number of records deleted in database:", num) | ||
150 | + } | ||
151 | + } | ||
152 | + return | ||
153 | +} |
models/question_department_log.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "errors" | ||
5 | + "fmt" | ||
6 | + "reflect" | ||
7 | + "strings" | ||
8 | + "time" | ||
9 | + | ||
10 | + "github.com/astaxie/beego/orm" | ||
11 | +) | ||
12 | + | ||
13 | +type QuestionDepartmentLog struct { | ||
14 | + Id int `orm:"column(id);pk"` | ||
15 | + Qid int64 `orm:"column(qid)" description:"所属的问题ID"` | ||
16 | + DepartmentId int `orm:"column(department_id)" description:"相关部门id"` | ||
17 | + OperatorId int64 `orm:"column(operator_id)" description:"操作者id"` | ||
18 | + CreateTime time.Time `orm:"column(createTime);type(timestamp);auto_now_add"` | ||
19 | +} | ||
20 | + | ||
21 | +func (t *QuestionDepartmentLog) TableName() string { | ||
22 | + return "question_department_log" | ||
23 | +} | ||
24 | + | ||
25 | +func init() { | ||
26 | + orm.RegisterModel(new(QuestionDepartmentLog)) | ||
27 | +} | ||
28 | + | ||
29 | +// AddQuestionDepartmentLog insert a new QuestionDepartmentLog into database and returns | ||
30 | +// last inserted Id on success. | ||
31 | +func AddQuestionDepartmentLog(m *QuestionDepartmentLog) (id int64, err error) { | ||
32 | + o := orm.NewOrm() | ||
33 | + id, err = o.Insert(m) | ||
34 | + return | ||
35 | +} | ||
36 | + | ||
37 | +// GetQuestionDepartmentLogById retrieves QuestionDepartmentLog by Id. Returns error if | ||
38 | +// Id doesn't exist | ||
39 | +func GetQuestionDepartmentLogById(id int) (v *QuestionDepartmentLog, err error) { | ||
40 | + o := orm.NewOrm() | ||
41 | + v = &QuestionDepartmentLog{Id: id} | ||
42 | + if err = o.Read(v); err == nil { | ||
43 | + return v, nil | ||
44 | + } | ||
45 | + return nil, err | ||
46 | +} | ||
47 | + | ||
48 | +// GetAllQuestionDepartmentLog retrieves all QuestionDepartmentLog matches certain condition. Returns empty list if | ||
49 | +// no records exist | ||
50 | +func GetAllQuestionDepartmentLog(query map[string]string, fields []string, sortby []string, order []string, | ||
51 | + offset int64, limit int64) (ml []interface{}, err error) { | ||
52 | + o := orm.NewOrm() | ||
53 | + qs := o.QueryTable(new(QuestionDepartmentLog)) | ||
54 | + // query k=v | ||
55 | + for k, v := range query { | ||
56 | + // rewrite dot-notation to Object__Attribute | ||
57 | + k = strings.Replace(k, ".", "__", -1) | ||
58 | + if strings.Contains(k, "isnull") { | ||
59 | + qs = qs.Filter(k, (v == "true" || v == "1")) | ||
60 | + } else { | ||
61 | + qs = qs.Filter(k, v) | ||
62 | + } | ||
63 | + } | ||
64 | + // order by: | ||
65 | + var sortFields []string | ||
66 | + if len(sortby) != 0 { | ||
67 | + if len(sortby) == len(order) { | ||
68 | + // 1) for each sort field, there is an associated order | ||
69 | + for i, v := range sortby { | ||
70 | + orderby := "" | ||
71 | + if order[i] == "desc" { | ||
72 | + orderby = "-" + v | ||
73 | + } else if order[i] == "asc" { | ||
74 | + orderby = v | ||
75 | + } else { | ||
76 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
77 | + } | ||
78 | + sortFields = append(sortFields, orderby) | ||
79 | + } | ||
80 | + qs = qs.OrderBy(sortFields...) | ||
81 | + } else if len(sortby) != len(order) && len(order) == 1 { | ||
82 | + // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
83 | + for _, v := range sortby { | ||
84 | + orderby := "" | ||
85 | + if order[0] == "desc" { | ||
86 | + orderby = "-" + v | ||
87 | + } else if order[0] == "asc" { | ||
88 | + orderby = v | ||
89 | + } else { | ||
90 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
91 | + } | ||
92 | + sortFields = append(sortFields, orderby) | ||
93 | + } | ||
94 | + } else if len(sortby) != len(order) && len(order) != 1 { | ||
95 | + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
96 | + } | ||
97 | + } else { | ||
98 | + if len(order) != 0 { | ||
99 | + return nil, errors.New("Error: unused 'order' fields") | ||
100 | + } | ||
101 | + } | ||
102 | + | ||
103 | + var l []QuestionDepartmentLog | ||
104 | + qs = qs.OrderBy(sortFields...) | ||
105 | + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
106 | + if len(fields) == 0 { | ||
107 | + for _, v := range l { | ||
108 | + ml = append(ml, v) | ||
109 | + } | ||
110 | + } else { | ||
111 | + // trim unused fields | ||
112 | + for _, v := range l { | ||
113 | + m := make(map[string]interface{}) | ||
114 | + val := reflect.ValueOf(v) | ||
115 | + for _, fname := range fields { | ||
116 | + m[fname] = val.FieldByName(fname).Interface() | ||
117 | + } | ||
118 | + ml = append(ml, m) | ||
119 | + } | ||
120 | + } | ||
121 | + return ml, nil | ||
122 | + } | ||
123 | + return nil, err | ||
124 | +} | ||
125 | + | ||
126 | +// UpdateQuestionDepartmentLog updates QuestionDepartmentLog by Id and returns error if | ||
127 | +// the record to be updated doesn't exist | ||
128 | +func UpdateQuestionDepartmentLogById(m *QuestionDepartmentLog) (err error) { | ||
129 | + o := orm.NewOrm() | ||
130 | + v := QuestionDepartmentLog{Id: m.Id} | ||
131 | + // ascertain id exists in the database | ||
132 | + if err = o.Read(&v); err == nil { | ||
133 | + var num int64 | ||
134 | + if num, err = o.Update(m); err == nil { | ||
135 | + fmt.Println("Number of records updated in database:", num) | ||
136 | + } | ||
137 | + } | ||
138 | + return | ||
139 | +} | ||
140 | + | ||
141 | +// DeleteQuestionDepartmentLog deletes QuestionDepartmentLog by Id and returns error if | ||
142 | +// the record to be deleted doesn't exist | ||
143 | +func DeleteQuestionDepartmentLog(id int) (err error) { | ||
144 | + o := orm.NewOrm() | ||
145 | + v := QuestionDepartmentLog{Id: id} | ||
146 | + // ascertain id exists in the database | ||
147 | + if err = o.Read(&v); err == nil { | ||
148 | + var num int64 | ||
149 | + if num, err = o.Delete(&QuestionDepartmentLog{Id: id}); err == nil { | ||
150 | + fmt.Println("Number of records deleted in database:", num) | ||
151 | + } | ||
152 | + } | ||
153 | + return | ||
154 | +} |
models/question_image.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "errors" | ||
5 | + "fmt" | ||
6 | + "reflect" | ||
7 | + "strings" | ||
8 | + | ||
9 | + "github.com/astaxie/beego/orm" | ||
10 | +) | ||
11 | + | ||
12 | +type QuestionImage struct { | ||
13 | + Id int `orm:"column(id);pk"` | ||
14 | + Qid int64 `orm:"column(qid);null" description:"所属的问题ID"` | ||
15 | + Path string `orm:"column(path);size(500);null" description:"语音路径"` | ||
16 | + W int `orm:"column(w)"` | ||
17 | + H int `orm:"column(h)"` | ||
18 | +} | ||
19 | + | ||
20 | +func (t *QuestionImage) TableName() string { | ||
21 | + return "question_image" | ||
22 | +} | ||
23 | + | ||
24 | +func init() { | ||
25 | + orm.RegisterModel(new(QuestionImage)) | ||
26 | +} | ||
27 | + | ||
28 | +// AddQuestionImage insert a new QuestionImage into database and returns | ||
29 | +// last inserted Id on success. | ||
30 | +func AddQuestionImage(m *QuestionImage) (id int64, err error) { | ||
31 | + o := orm.NewOrm() | ||
32 | + id, err = o.Insert(m) | ||
33 | + return | ||
34 | +} | ||
35 | + | ||
36 | +// GetQuestionImageById retrieves QuestionImage by Id. Returns error if | ||
37 | +// Id doesn't exist | ||
38 | +func GetQuestionImageById(id int) (v *QuestionImage, err error) { | ||
39 | + o := orm.NewOrm() | ||
40 | + v = &QuestionImage{Id: id} | ||
41 | + if err = o.Read(v); err == nil { | ||
42 | + return v, nil | ||
43 | + } | ||
44 | + return nil, err | ||
45 | +} | ||
46 | + | ||
47 | +// GetAllQuestionImage retrieves all QuestionImage matches certain condition. Returns empty list if | ||
48 | +// no records exist | ||
49 | +func GetAllQuestionImage(query map[string]string, fields []string, sortby []string, order []string, | ||
50 | + offset int64, limit int64) (ml []interface{}, err error) { | ||
51 | + o := orm.NewOrm() | ||
52 | + qs := o.QueryTable(new(QuestionImage)) | ||
53 | + // query k=v | ||
54 | + for k, v := range query { | ||
55 | + // rewrite dot-notation to Object__Attribute | ||
56 | + k = strings.Replace(k, ".", "__", -1) | ||
57 | + if strings.Contains(k, "isnull") { | ||
58 | + qs = qs.Filter(k, (v == "true" || v == "1")) | ||
59 | + } else { | ||
60 | + qs = qs.Filter(k, v) | ||
61 | + } | ||
62 | + } | ||
63 | + // order by: | ||
64 | + var sortFields []string | ||
65 | + if len(sortby) != 0 { | ||
66 | + if len(sortby) == len(order) { | ||
67 | + // 1) for each sort field, there is an associated order | ||
68 | + for i, v := range sortby { | ||
69 | + orderby := "" | ||
70 | + if order[i] == "desc" { | ||
71 | + orderby = "-" + v | ||
72 | + } else if order[i] == "asc" { | ||
73 | + orderby = v | ||
74 | + } else { | ||
75 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
76 | + } | ||
77 | + sortFields = append(sortFields, orderby) | ||
78 | + } | ||
79 | + qs = qs.OrderBy(sortFields...) | ||
80 | + } else if len(sortby) != len(order) && len(order) == 1 { | ||
81 | + // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
82 | + for _, v := range sortby { | ||
83 | + orderby := "" | ||
84 | + if order[0] == "desc" { | ||
85 | + orderby = "-" + v | ||
86 | + } else if order[0] == "asc" { | ||
87 | + orderby = v | ||
88 | + } else { | ||
89 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
90 | + } | ||
91 | + sortFields = append(sortFields, orderby) | ||
92 | + } | ||
93 | + } else if len(sortby) != len(order) && len(order) != 1 { | ||
94 | + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
95 | + } | ||
96 | + } else { | ||
97 | + if len(order) != 0 { | ||
98 | + return nil, errors.New("Error: unused 'order' fields") | ||
99 | + } | ||
100 | + } | ||
101 | + | ||
102 | + var l []QuestionImage | ||
103 | + qs = qs.OrderBy(sortFields...) | ||
104 | + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
105 | + if len(fields) == 0 { | ||
106 | + for _, v := range l { | ||
107 | + ml = append(ml, v) | ||
108 | + } | ||
109 | + } else { | ||
110 | + // trim unused fields | ||
111 | + for _, v := range l { | ||
112 | + m := make(map[string]interface{}) | ||
113 | + val := reflect.ValueOf(v) | ||
114 | + for _, fname := range fields { | ||
115 | + m[fname] = val.FieldByName(fname).Interface() | ||
116 | + } | ||
117 | + ml = append(ml, m) | ||
118 | + } | ||
119 | + } | ||
120 | + return ml, nil | ||
121 | + } | ||
122 | + return nil, err | ||
123 | +} | ||
124 | + | ||
125 | +// UpdateQuestionImage updates QuestionImage by Id and returns error if | ||
126 | +// the record to be updated doesn't exist | ||
127 | +func UpdateQuestionImageById(m *QuestionImage) (err error) { | ||
128 | + o := orm.NewOrm() | ||
129 | + v := QuestionImage{Id: m.Id} | ||
130 | + // ascertain id exists in the database | ||
131 | + if err = o.Read(&v); err == nil { | ||
132 | + var num int64 | ||
133 | + if num, err = o.Update(m); err == nil { | ||
134 | + fmt.Println("Number of records updated in database:", num) | ||
135 | + } | ||
136 | + } | ||
137 | + return | ||
138 | +} | ||
139 | + | ||
140 | +// DeleteQuestionImage deletes QuestionImage by Id and returns error if | ||
141 | +// the record to be deleted doesn't exist | ||
142 | +func DeleteQuestionImage(id int) (err error) { | ||
143 | + o := orm.NewOrm() | ||
144 | + v := QuestionImage{Id: id} | ||
145 | + // ascertain id exists in the database | ||
146 | + if err = o.Read(&v); err == nil { | ||
147 | + var num int64 | ||
148 | + if num, err = o.Delete(&QuestionImage{Id: id}); err == nil { | ||
149 | + fmt.Println("Number of records deleted in database:", num) | ||
150 | + } | ||
151 | + } | ||
152 | + return | ||
153 | +} |
models/question_score.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "errors" | ||
5 | + "fmt" | ||
6 | + "reflect" | ||
7 | + "strings" | ||
8 | + "time" | ||
9 | + | ||
10 | + "github.com/astaxie/beego/orm" | ||
11 | +) | ||
12 | + | ||
13 | +type QuestionScore struct { | ||
14 | + Id int `orm:"column(id);pk"` | ||
15 | + Uid int64 `orm:"column(uid);null" description:"评分用户ID"` | ||
16 | + Qid int64 `orm:"column(qid);null" description:"所属的问题ID"` | ||
17 | + ScoreAnalyze int `orm:"column(scoreAnalyze);null"` | ||
18 | + ScoreAsk int `orm:"column(scoreAsk);null"` | ||
19 | + ScoreScheme int `orm:"column(scoreScheme);null"` | ||
20 | + CreateTime time.Time `orm:"column(createTime);type(timestamp);null;auto_now_add" description:"评分时间"` | ||
21 | +} | ||
22 | + | ||
23 | +func (t *QuestionScore) TableName() string { | ||
24 | + return "question_score" | ||
25 | +} | ||
26 | + | ||
27 | +func init() { | ||
28 | + orm.RegisterModel(new(QuestionScore)) | ||
29 | +} | ||
30 | + | ||
31 | +// AddQuestionScore insert a new QuestionScore into database and returns | ||
32 | +// last inserted Id on success. | ||
33 | +func AddQuestionScore(m *QuestionScore) (id int64, err error) { | ||
34 | + o := orm.NewOrm() | ||
35 | + id, err = o.Insert(m) | ||
36 | + return | ||
37 | +} | ||
38 | + | ||
39 | +// GetQuestionScoreById retrieves QuestionScore by Id. Returns error if | ||
40 | +// Id doesn't exist | ||
41 | +func GetQuestionScoreById(id int) (v *QuestionScore, err error) { | ||
42 | + o := orm.NewOrm() | ||
43 | + v = &QuestionScore{Id: id} | ||
44 | + if err = o.Read(v); err == nil { | ||
45 | + return v, nil | ||
46 | + } | ||
47 | + return nil, err | ||
48 | +} | ||
49 | + | ||
50 | +// GetAllQuestionScore retrieves all QuestionScore matches certain condition. Returns empty list if | ||
51 | +// no records exist | ||
52 | +func GetAllQuestionScore(query map[string]string, fields []string, sortby []string, order []string, | ||
53 | + offset int64, limit int64) (ml []interface{}, err error) { | ||
54 | + o := orm.NewOrm() | ||
55 | + qs := o.QueryTable(new(QuestionScore)) | ||
56 | + // query k=v | ||
57 | + for k, v := range query { | ||
58 | + // rewrite dot-notation to Object__Attribute | ||
59 | + k = strings.Replace(k, ".", "__", -1) | ||
60 | + if strings.Contains(k, "isnull") { | ||
61 | + qs = qs.Filter(k, (v == "true" || v == "1")) | ||
62 | + } else { | ||
63 | + qs = qs.Filter(k, v) | ||
64 | + } | ||
65 | + } | ||
66 | + // order by: | ||
67 | + var sortFields []string | ||
68 | + if len(sortby) != 0 { | ||
69 | + if len(sortby) == len(order) { | ||
70 | + // 1) for each sort field, there is an associated order | ||
71 | + for i, v := range sortby { | ||
72 | + orderby := "" | ||
73 | + if order[i] == "desc" { | ||
74 | + orderby = "-" + v | ||
75 | + } else if order[i] == "asc" { | ||
76 | + orderby = v | ||
77 | + } else { | ||
78 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
79 | + } | ||
80 | + sortFields = append(sortFields, orderby) | ||
81 | + } | ||
82 | + qs = qs.OrderBy(sortFields...) | ||
83 | + } else if len(sortby) != len(order) && len(order) == 1 { | ||
84 | + // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
85 | + for _, v := range sortby { | ||
86 | + orderby := "" | ||
87 | + if order[0] == "desc" { | ||
88 | + orderby = "-" + v | ||
89 | + } else if order[0] == "asc" { | ||
90 | + orderby = v | ||
91 | + } else { | ||
92 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
93 | + } | ||
94 | + sortFields = append(sortFields, orderby) | ||
95 | + } | ||
96 | + } else if len(sortby) != len(order) && len(order) != 1 { | ||
97 | + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
98 | + } | ||
99 | + } else { | ||
100 | + if len(order) != 0 { | ||
101 | + return nil, errors.New("Error: unused 'order' fields") | ||
102 | + } | ||
103 | + } | ||
104 | + | ||
105 | + var l []QuestionScore | ||
106 | + qs = qs.OrderBy(sortFields...) | ||
107 | + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
108 | + if len(fields) == 0 { | ||
109 | + for _, v := range l { | ||
110 | + ml = append(ml, v) | ||
111 | + } | ||
112 | + } else { | ||
113 | + // trim unused fields | ||
114 | + for _, v := range l { | ||
115 | + m := make(map[string]interface{}) | ||
116 | + val := reflect.ValueOf(v) | ||
117 | + for _, fname := range fields { | ||
118 | + m[fname] = val.FieldByName(fname).Interface() | ||
119 | + } | ||
120 | + ml = append(ml, m) | ||
121 | + } | ||
122 | + } | ||
123 | + return ml, nil | ||
124 | + } | ||
125 | + return nil, err | ||
126 | +} | ||
127 | + | ||
128 | +// UpdateQuestionScore updates QuestionScore by Id and returns error if | ||
129 | +// the record to be updated doesn't exist | ||
130 | +func UpdateQuestionScoreById(m *QuestionScore) (err error) { | ||
131 | + o := orm.NewOrm() | ||
132 | + v := QuestionScore{Id: m.Id} | ||
133 | + // ascertain id exists in the database | ||
134 | + if err = o.Read(&v); err == nil { | ||
135 | + var num int64 | ||
136 | + if num, err = o.Update(m); err == nil { | ||
137 | + fmt.Println("Number of records updated in database:", num) | ||
138 | + } | ||
139 | + } | ||
140 | + return | ||
141 | +} | ||
142 | + | ||
143 | +// DeleteQuestionScore deletes QuestionScore by Id and returns error if | ||
144 | +// the record to be deleted doesn't exist | ||
145 | +func DeleteQuestionScore(id int) (err error) { | ||
146 | + o := orm.NewOrm() | ||
147 | + v := QuestionScore{Id: id} | ||
148 | + // ascertain id exists in the database | ||
149 | + if err = o.Read(&v); err == nil { | ||
150 | + var num int64 | ||
151 | + if num, err = o.Delete(&QuestionScore{Id: id}); err == nil { | ||
152 | + fmt.Println("Number of records deleted in database:", num) | ||
153 | + } | ||
154 | + } | ||
155 | + return | ||
156 | +} |
models/question_speech.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "errors" | ||
5 | + "fmt" | ||
6 | + "reflect" | ||
7 | + "strings" | ||
8 | + | ||
9 | + "github.com/astaxie/beego/orm" | ||
10 | +) | ||
11 | + | ||
12 | +type QuestionSpeech struct { | ||
13 | + Id int `orm:"column(id);pk"` | ||
14 | + Duration int `orm:"column(duration);null" description:"秒数"` | ||
15 | + Qid int64 `orm:"column(qid);null" description:"所属的问题ID"` | ||
16 | + Path string `orm:"column(path);size(500);null" description:"语音路径"` | ||
17 | +} | ||
18 | + | ||
19 | +func (t *QuestionSpeech) TableName() string { | ||
20 | + return "question_speech" | ||
21 | +} | ||
22 | + | ||
23 | +func init() { | ||
24 | + orm.RegisterModel(new(QuestionSpeech)) | ||
25 | +} | ||
26 | + | ||
27 | +// AddQuestionSpeech insert a new QuestionSpeech into database and returns | ||
28 | +// last inserted Id on success. | ||
29 | +func AddQuestionSpeech(m *QuestionSpeech) (id int64, err error) { | ||
30 | + o := orm.NewOrm() | ||
31 | + id, err = o.Insert(m) | ||
32 | + return | ||
33 | +} | ||
34 | + | ||
35 | +// GetQuestionSpeechById retrieves QuestionSpeech by Id. Returns error if | ||
36 | +// Id doesn't exist | ||
37 | +func GetQuestionSpeechById(id int) (v *QuestionSpeech, err error) { | ||
38 | + o := orm.NewOrm() | ||
39 | + v = &QuestionSpeech{Id: id} | ||
40 | + if err = o.Read(v); err == nil { | ||
41 | + return v, nil | ||
42 | + } | ||
43 | + return nil, err | ||
44 | +} | ||
45 | + | ||
46 | +// GetAllQuestionSpeech retrieves all QuestionSpeech matches certain condition. Returns empty list if | ||
47 | +// no records exist | ||
48 | +func GetAllQuestionSpeech(query map[string]string, fields []string, sortby []string, order []string, | ||
49 | + offset int64, limit int64) (ml []interface{}, err error) { | ||
50 | + o := orm.NewOrm() | ||
51 | + qs := o.QueryTable(new(QuestionSpeech)) | ||
52 | + // query k=v | ||
53 | + for k, v := range query { | ||
54 | + // rewrite dot-notation to Object__Attribute | ||
55 | + k = strings.Replace(k, ".", "__", -1) | ||
56 | + if strings.Contains(k, "isnull") { | ||
57 | + qs = qs.Filter(k, (v == "true" || v == "1")) | ||
58 | + } else { | ||
59 | + qs = qs.Filter(k, v) | ||
60 | + } | ||
61 | + } | ||
62 | + // order by: | ||
63 | + var sortFields []string | ||
64 | + if len(sortby) != 0 { | ||
65 | + if len(sortby) == len(order) { | ||
66 | + // 1) for each sort field, there is an associated order | ||
67 | + for i, v := range sortby { | ||
68 | + orderby := "" | ||
69 | + if order[i] == "desc" { | ||
70 | + orderby = "-" + v | ||
71 | + } else if order[i] == "asc" { | ||
72 | + orderby = v | ||
73 | + } else { | ||
74 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
75 | + } | ||
76 | + sortFields = append(sortFields, orderby) | ||
77 | + } | ||
78 | + qs = qs.OrderBy(sortFields...) | ||
79 | + } else if len(sortby) != len(order) && len(order) == 1 { | ||
80 | + // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
81 | + for _, v := range sortby { | ||
82 | + orderby := "" | ||
83 | + if order[0] == "desc" { | ||
84 | + orderby = "-" + v | ||
85 | + } else if order[0] == "asc" { | ||
86 | + orderby = v | ||
87 | + } else { | ||
88 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
89 | + } | ||
90 | + sortFields = append(sortFields, orderby) | ||
91 | + } | ||
92 | + } else if len(sortby) != len(order) && len(order) != 1 { | ||
93 | + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
94 | + } | ||
95 | + } else { | ||
96 | + if len(order) != 0 { | ||
97 | + return nil, errors.New("Error: unused 'order' fields") | ||
98 | + } | ||
99 | + } | ||
100 | + | ||
101 | + var l []QuestionSpeech | ||
102 | + qs = qs.OrderBy(sortFields...) | ||
103 | + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
104 | + if len(fields) == 0 { | ||
105 | + for _, v := range l { | ||
106 | + ml = append(ml, v) | ||
107 | + } | ||
108 | + } else { | ||
109 | + // trim unused fields | ||
110 | + for _, v := range l { | ||
111 | + m := make(map[string]interface{}) | ||
112 | + val := reflect.ValueOf(v) | ||
113 | + for _, fname := range fields { | ||
114 | + m[fname] = val.FieldByName(fname).Interface() | ||
115 | + } | ||
116 | + ml = append(ml, m) | ||
117 | + } | ||
118 | + } | ||
119 | + return ml, nil | ||
120 | + } | ||
121 | + return nil, err | ||
122 | +} | ||
123 | + | ||
124 | +// UpdateQuestionSpeech updates QuestionSpeech by Id and returns error if | ||
125 | +// the record to be updated doesn't exist | ||
126 | +func UpdateQuestionSpeechById(m *QuestionSpeech) (err error) { | ||
127 | + o := orm.NewOrm() | ||
128 | + v := QuestionSpeech{Id: m.Id} | ||
129 | + // ascertain id exists in the database | ||
130 | + if err = o.Read(&v); err == nil { | ||
131 | + var num int64 | ||
132 | + if num, err = o.Update(m); err == nil { | ||
133 | + fmt.Println("Number of records updated in database:", num) | ||
134 | + } | ||
135 | + } | ||
136 | + return | ||
137 | +} | ||
138 | + | ||
139 | +// DeleteQuestionSpeech deletes QuestionSpeech by Id and returns error if | ||
140 | +// the record to be deleted doesn't exist | ||
141 | +func DeleteQuestionSpeech(id int) (err error) { | ||
142 | + o := orm.NewOrm() | ||
143 | + v := QuestionSpeech{Id: id} | ||
144 | + // ascertain id exists in the database | ||
145 | + if err = o.Read(&v); err == nil { | ||
146 | + var num int64 | ||
147 | + if num, err = o.Delete(&QuestionSpeech{Id: id}); err == nil { | ||
148 | + fmt.Println("Number of records deleted in database:", num) | ||
149 | + } | ||
150 | + } | ||
151 | + return | ||
152 | +} |
models/roles.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "errors" | ||
5 | + "fmt" | ||
6 | + "reflect" | ||
7 | + "strings" | ||
8 | + "time" | ||
9 | + | ||
10 | + "github.com/astaxie/beego/orm" | ||
11 | +) | ||
12 | + | ||
13 | +type Roles struct { | ||
14 | + Id int `orm:"column(id);auto"` | ||
15 | + Name string `orm:"column(name);size(191)"` | ||
16 | + GuardName string `orm:"column(guard_name);size(191)"` | ||
17 | + CreatedAt time.Time `orm:"column(created_at);type(timestamp);null"` | ||
18 | + UpdatedAt time.Time `orm:"column(updated_at);type(timestamp);null"` | ||
19 | + ShowName string `orm:"column(show_name);size(191)"` | ||
20 | + Description string `orm:"column(description);size(191);null"` | ||
21 | +} | ||
22 | + | ||
23 | +func (t *Roles) TableName() string { | ||
24 | + return "roles" | ||
25 | +} | ||
26 | + | ||
27 | +func init() { | ||
28 | + orm.RegisterModel(new(Roles)) | ||
29 | +} | ||
30 | + | ||
31 | +// AddRoles insert a new Roles into database and returns | ||
32 | +// last inserted Id on success. | ||
33 | +func AddRoles(m *Roles) (id int64, err error) { | ||
34 | + o := orm.NewOrm() | ||
35 | + id, err = o.Insert(m) | ||
36 | + return | ||
37 | +} | ||
38 | + | ||
39 | +// GetRolesById retrieves Roles by Id. Returns error if | ||
40 | +// Id doesn't exist | ||
41 | +func GetRolesById(id int) (v *Roles, err error) { | ||
42 | + o := orm.NewOrm() | ||
43 | + v = &Roles{Id: id} | ||
44 | + if err = o.Read(v); err == nil { | ||
45 | + return v, nil | ||
46 | + } | ||
47 | + return nil, err | ||
48 | +} | ||
49 | + | ||
50 | +// GetAllRoles retrieves all Roles matches certain condition. Returns empty list if | ||
51 | +// no records exist | ||
52 | +func GetAllRoles(query map[string]string, fields []string, sortby []string, order []string, | ||
53 | + offset int64, limit int64) (ml []interface{}, err error) { | ||
54 | + o := orm.NewOrm() | ||
55 | + qs := o.QueryTable(new(Roles)) | ||
56 | + // query k=v | ||
57 | + for k, v := range query { | ||
58 | + // rewrite dot-notation to Object__Attribute | ||
59 | + k = strings.Replace(k, ".", "__", -1) | ||
60 | + if strings.Contains(k, "isnull") { | ||
61 | + qs = qs.Filter(k, (v == "true" || v == "1")) | ||
62 | + } else { | ||
63 | + qs = qs.Filter(k, v) | ||
64 | + } | ||
65 | + } | ||
66 | + // order by: | ||
67 | + var sortFields []string | ||
68 | + if len(sortby) != 0 { | ||
69 | + if len(sortby) == len(order) { | ||
70 | + // 1) for each sort field, there is an associated order | ||
71 | + for i, v := range sortby { | ||
72 | + orderby := "" | ||
73 | + if order[i] == "desc" { | ||
74 | + orderby = "-" + v | ||
75 | + } else if order[i] == "asc" { | ||
76 | + orderby = v | ||
77 | + } else { | ||
78 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
79 | + } | ||
80 | + sortFields = append(sortFields, orderby) | ||
81 | + } | ||
82 | + qs = qs.OrderBy(sortFields...) | ||
83 | + } else if len(sortby) != len(order) && len(order) == 1 { | ||
84 | + // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
85 | + for _, v := range sortby { | ||
86 | + orderby := "" | ||
87 | + if order[0] == "desc" { | ||
88 | + orderby = "-" + v | ||
89 | + } else if order[0] == "asc" { | ||
90 | + orderby = v | ||
91 | + } else { | ||
92 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
93 | + } | ||
94 | + sortFields = append(sortFields, orderby) | ||
95 | + } | ||
96 | + } else if len(sortby) != len(order) && len(order) != 1 { | ||
97 | + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
98 | + } | ||
99 | + } else { | ||
100 | + if len(order) != 0 { | ||
101 | + return nil, errors.New("Error: unused 'order' fields") | ||
102 | + } | ||
103 | + } | ||
104 | + | ||
105 | + var l []Roles | ||
106 | + qs = qs.OrderBy(sortFields...) | ||
107 | + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
108 | + if len(fields) == 0 { | ||
109 | + for _, v := range l { | ||
110 | + ml = append(ml, v) | ||
111 | + } | ||
112 | + } else { | ||
113 | + // trim unused fields | ||
114 | + for _, v := range l { | ||
115 | + m := make(map[string]interface{}) | ||
116 | + val := reflect.ValueOf(v) | ||
117 | + for _, fname := range fields { | ||
118 | + m[fname] = val.FieldByName(fname).Interface() | ||
119 | + } | ||
120 | + ml = append(ml, m) | ||
121 | + } | ||
122 | + } | ||
123 | + return ml, nil | ||
124 | + } | ||
125 | + return nil, err | ||
126 | +} | ||
127 | + | ||
128 | +// UpdateRoles updates Roles by Id and returns error if | ||
129 | +// the record to be updated doesn't exist | ||
130 | +func UpdateRolesById(m *Roles) (err error) { | ||
131 | + o := orm.NewOrm() | ||
132 | + v := Roles{Id: m.Id} | ||
133 | + // ascertain id exists in the database | ||
134 | + if err = o.Read(&v); err == nil { | ||
135 | + var num int64 | ||
136 | + if num, err = o.Update(m); err == nil { | ||
137 | + fmt.Println("Number of records updated in database:", num) | ||
138 | + } | ||
139 | + } | ||
140 | + return | ||
141 | +} | ||
142 | + | ||
143 | +// DeleteRoles deletes Roles by Id and returns error if | ||
144 | +// the record to be deleted doesn't exist | ||
145 | +func DeleteRoles(id int) (err error) { | ||
146 | + o := orm.NewOrm() | ||
147 | + v := Roles{Id: id} | ||
148 | + // ascertain id exists in the database | ||
149 | + if err = o.Read(&v); err == nil { | ||
150 | + var num int64 | ||
151 | + if num, err = o.Delete(&Roles{Id: id}); err == nil { | ||
152 | + fmt.Println("Number of records deleted in database:", num) | ||
153 | + } | ||
154 | + } | ||
155 | + return | ||
156 | +} |
models/solution.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import "time" | ||
4 | + | ||
5 | +type Solution struct { | ||
6 | + Id_RENAME int64 `orm:"column(id)" description:"方案ID"` | ||
7 | + QuestionTitle string `orm:"column(questionTitle);size(500);null" description:"问题标题"` | ||
8 | + Uid int64 `orm:"column(uid)" description:"方案提供者"` | ||
9 | + CreateTime time.Time `orm:"column(createTime);type(timestamp);null" description:"方案创建时间"` | ||
10 | + Content string `orm:"column(content);null" description:"方案内容"` | ||
11 | + ScoreAnalyze int `orm:"column(scoreAnalyze);null" description:"分析评分(0-5对应分数)"` | ||
12 | + ScoreSolution int `orm:"column(scoreSolution);null" description:"解决评分(0-5对应分数)"` | ||
13 | + ScoreScheme int `orm:"column(scoreScheme);null" description:"方案评分(0-5对应分数)"` | ||
14 | + PageView int `orm:"column(pageView);null" description:"浏览总数"` | ||
15 | + CommentTotal int `orm:"column(commentTotal);null" description:"评论总数"` | ||
16 | + SympathyTotal int `orm:"column(sympathyTotal);null" description:"同感总数"` | ||
17 | + Qid int64 `orm:"column(qid);null" description:"问题ID"` | ||
18 | + Plevel int `orm:"column(plevel);null" description:"最新评分人等级"` | ||
19 | + Stype int `orm:"column(stype);null" description:"0备选方案 1解决方案"` | ||
20 | + SpfUid int64 `orm:"column(spfUid)"` | ||
21 | + UpdateTime time.Time `orm:"column(updateTime);type(timestamp);auto_now_add" description:"方案编辑更新时间"` | ||
22 | +} |
models/solution_image.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "errors" | ||
5 | + "fmt" | ||
6 | + "reflect" | ||
7 | + "strings" | ||
8 | + | ||
9 | + "github.com/astaxie/beego/orm" | ||
10 | +) | ||
11 | + | ||
12 | +type SolutionImage struct { | ||
13 | + Id int `orm:"column(id);auto" description:"方案ID"` | ||
14 | + SolutionId int64 `orm:"column(solution_id)" description:"解决方案ID"` | ||
15 | + Path string `orm:"column(path);size(255)" description:"图片路径"` | ||
16 | + H int `orm:"column(h)"` | ||
17 | + W int `orm:"column(w)"` | ||
18 | +} | ||
19 | + | ||
20 | +func (t *SolutionImage) TableName() string { | ||
21 | + return "solution_image" | ||
22 | +} | ||
23 | + | ||
24 | +func init() { | ||
25 | + orm.RegisterModel(new(SolutionImage)) | ||
26 | +} | ||
27 | + | ||
28 | +// AddSolutionImage insert a new SolutionImage into database and returns | ||
29 | +// last inserted Id on success. | ||
30 | +func AddSolutionImage(m *SolutionImage) (id int64, err error) { | ||
31 | + o := orm.NewOrm() | ||
32 | + id, err = o.Insert(m) | ||
33 | + return | ||
34 | +} | ||
35 | + | ||
36 | +// GetSolutionImageById retrieves SolutionImage by Id. Returns error if | ||
37 | +// Id doesn't exist | ||
38 | +func GetSolutionImageById(id int) (v *SolutionImage, err error) { | ||
39 | + o := orm.NewOrm() | ||
40 | + v = &SolutionImage{Id: id} | ||
41 | + if err = o.Read(v); err == nil { | ||
42 | + return v, nil | ||
43 | + } | ||
44 | + return nil, err | ||
45 | +} | ||
46 | + | ||
47 | +// GetAllSolutionImage retrieves all SolutionImage matches certain condition. Returns empty list if | ||
48 | +// no records exist | ||
49 | +func GetAllSolutionImage(query map[string]string, fields []string, sortby []string, order []string, | ||
50 | + offset int64, limit int64) (ml []interface{}, err error) { | ||
51 | + o := orm.NewOrm() | ||
52 | + qs := o.QueryTable(new(SolutionImage)) | ||
53 | + // query k=v | ||
54 | + for k, v := range query { | ||
55 | + // rewrite dot-notation to Object__Attribute | ||
56 | + k = strings.Replace(k, ".", "__", -1) | ||
57 | + if strings.Contains(k, "isnull") { | ||
58 | + qs = qs.Filter(k, (v == "true" || v == "1")) | ||
59 | + } else { | ||
60 | + qs = qs.Filter(k, v) | ||
61 | + } | ||
62 | + } | ||
63 | + // order by: | ||
64 | + var sortFields []string | ||
65 | + if len(sortby) != 0 { | ||
66 | + if len(sortby) == len(order) { | ||
67 | + // 1) for each sort field, there is an associated order | ||
68 | + for i, v := range sortby { | ||
69 | + orderby := "" | ||
70 | + if order[i] == "desc" { | ||
71 | + orderby = "-" + v | ||
72 | + } else if order[i] == "asc" { | ||
73 | + orderby = v | ||
74 | + } else { | ||
75 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
76 | + } | ||
77 | + sortFields = append(sortFields, orderby) | ||
78 | + } | ||
79 | + qs = qs.OrderBy(sortFields...) | ||
80 | + } else if len(sortby) != len(order) && len(order) == 1 { | ||
81 | + // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
82 | + for _, v := range sortby { | ||
83 | + orderby := "" | ||
84 | + if order[0] == "desc" { | ||
85 | + orderby = "-" + v | ||
86 | + } else if order[0] == "asc" { | ||
87 | + orderby = v | ||
88 | + } else { | ||
89 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
90 | + } | ||
91 | + sortFields = append(sortFields, orderby) | ||
92 | + } | ||
93 | + } else if len(sortby) != len(order) && len(order) != 1 { | ||
94 | + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
95 | + } | ||
96 | + } else { | ||
97 | + if len(order) != 0 { | ||
98 | + return nil, errors.New("Error: unused 'order' fields") | ||
99 | + } | ||
100 | + } | ||
101 | + | ||
102 | + var l []SolutionImage | ||
103 | + qs = qs.OrderBy(sortFields...) | ||
104 | + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
105 | + if len(fields) == 0 { | ||
106 | + for _, v := range l { | ||
107 | + ml = append(ml, v) | ||
108 | + } | ||
109 | + } else { | ||
110 | + // trim unused fields | ||
111 | + for _, v := range l { | ||
112 | + m := make(map[string]interface{}) | ||
113 | + val := reflect.ValueOf(v) | ||
114 | + for _, fname := range fields { | ||
115 | + m[fname] = val.FieldByName(fname).Interface() | ||
116 | + } | ||
117 | + ml = append(ml, m) | ||
118 | + } | ||
119 | + } | ||
120 | + return ml, nil | ||
121 | + } | ||
122 | + return nil, err | ||
123 | +} | ||
124 | + | ||
125 | +// UpdateSolutionImage updates SolutionImage by Id and returns error if | ||
126 | +// the record to be updated doesn't exist | ||
127 | +func UpdateSolutionImageById(m *SolutionImage) (err error) { | ||
128 | + o := orm.NewOrm() | ||
129 | + v := SolutionImage{Id: m.Id} | ||
130 | + // ascertain id exists in the database | ||
131 | + if err = o.Read(&v); err == nil { | ||
132 | + var num int64 | ||
133 | + if num, err = o.Update(m); err == nil { | ||
134 | + fmt.Println("Number of records updated in database:", num) | ||
135 | + } | ||
136 | + } | ||
137 | + return | ||
138 | +} | ||
139 | + | ||
140 | +// DeleteSolutionImage deletes SolutionImage by Id and returns error if | ||
141 | +// the record to be deleted doesn't exist | ||
142 | +func DeleteSolutionImage(id int) (err error) { | ||
143 | + o := orm.NewOrm() | ||
144 | + v := SolutionImage{Id: id} | ||
145 | + // ascertain id exists in the database | ||
146 | + if err = o.Read(&v); err == nil { | ||
147 | + var num int64 | ||
148 | + if num, err = o.Delete(&SolutionImage{Id: id}); err == nil { | ||
149 | + fmt.Println("Number of records deleted in database:", num) | ||
150 | + } | ||
151 | + } | ||
152 | + return | ||
153 | +} |
models/solution_partner.go
0 → 100644
1 | +package models | ||
2 | + | ||
3 | +import ( | ||
4 | + "errors" | ||
5 | + "fmt" | ||
6 | + "reflect" | ||
7 | + "strings" | ||
8 | + "time" | ||
9 | + | ||
10 | + "github.com/astaxie/beego/orm" | ||
11 | +) | ||
12 | + | ||
13 | +type SolutionPartner struct { | ||
14 | + Id int `orm:"column(id);auto"` | ||
15 | + Uid int64 `orm:"column(uid);null" description:"参与者用户ID"` | ||
16 | + Sid int64 `orm:"column(sid);null" description:"解决方案ID"` | ||
17 | + ScoreSolution int `orm:"column(scoreSolution);null"` | ||
18 | + CreateTime time.Time `orm:"column(createTime);type(timestamp);auto_now_add" description:"评分时间"` | ||
19 | + Puid int64 `orm:"column(puid);null" description:"评分人用户ID"` | ||
20 | + Enabled int `orm:"column(enabled);null" description:"有效1 失效0"` | ||
21 | + Sort int `orm:"column(sort)" description:"排序字段"` | ||
22 | +} | ||
23 | + | ||
24 | +func (t *SolutionPartner) TableName() string { | ||
25 | + return "solution_partner" | ||
26 | +} | ||
27 | + | ||
28 | +func init() { | ||
29 | + orm.RegisterModel(new(SolutionPartner)) | ||
30 | +} | ||
31 | + | ||
32 | +// AddSolutionPartner insert a new SolutionPartner into database and returns | ||
33 | +// last inserted Id on success. | ||
34 | +func AddSolutionPartner(m *SolutionPartner) (id int64, err error) { | ||
35 | + o := orm.NewOrm() | ||
36 | + id, err = o.Insert(m) | ||
37 | + return | ||
38 | +} | ||
39 | + | ||
40 | +// GetSolutionPartnerById retrieves SolutionPartner by Id. Returns error if | ||
41 | +// Id doesn't exist | ||
42 | +func GetSolutionPartnerById(id int) (v *SolutionPartner, err error) { | ||
43 | + o := orm.NewOrm() | ||
44 | + v = &SolutionPartner{Id: id} | ||
45 | + if err = o.Read(v); err == nil { | ||
46 | + return v, nil | ||
47 | + } | ||
48 | + return nil, err | ||
49 | +} | ||
50 | + | ||
51 | +// GetAllSolutionPartner retrieves all SolutionPartner matches certain condition. Returns empty list if | ||
52 | +// no records exist | ||
53 | +func GetAllSolutionPartner(query map[string]string, fields []string, sortby []string, order []string, | ||
54 | + offset int64, limit int64) (ml []interface{}, err error) { | ||
55 | + o := orm.NewOrm() | ||
56 | + qs := o.QueryTable(new(SolutionPartner)) | ||
57 | + // query k=v | ||
58 | + for k, v := range query { | ||
59 | + // rewrite dot-notation to Object__Attribute | ||
60 | + k = strings.Replace(k, ".", "__", -1) | ||
61 | + if strings.Contains(k, "isnull") { | ||
62 | + qs = qs.Filter(k, (v == "true" || v == "1")) | ||
63 | + } else { | ||
64 | + qs = qs.Filter(k, v) | ||
65 | + } | ||
66 | + } | ||
67 | + // order by: | ||
68 | + var sortFields []string | ||
69 | + if len(sortby) != 0 { | ||
70 | + if len(sortby) == len(order) { | ||
71 | + // 1) for each sort field, there is an associated order | ||
72 | + for i, v := range sortby { | ||
73 | + orderby := "" | ||
74 | + if order[i] == "desc" { | ||
75 | + orderby = "-" + v | ||
76 | + } else if order[i] == "asc" { | ||
77 | + orderby = v | ||
78 | + } else { | ||
79 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
80 | + } | ||
81 | + sortFields = append(sortFields, orderby) | ||
82 | + } | ||
83 | + qs = qs.OrderBy(sortFields...) | ||
84 | + } else if len(sortby) != len(order) && len(order) == 1 { | ||
85 | + // 2) there is exactly one order, all the sorted fields will be sorted by this order | ||
86 | + for _, v := range sortby { | ||
87 | + orderby := "" | ||
88 | + if order[0] == "desc" { | ||
89 | + orderby = "-" + v | ||
90 | + } else if order[0] == "asc" { | ||
91 | + orderby = v | ||
92 | + } else { | ||
93 | + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]") | ||
94 | + } | ||
95 | + sortFields = append(sortFields, orderby) | ||
96 | + } | ||
97 | + } else if len(sortby) != len(order) && len(order) != 1 { | ||
98 | + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1") | ||
99 | + } | ||
100 | + } else { | ||
101 | + if len(order) != 0 { | ||
102 | + return nil, errors.New("Error: unused 'order' fields") | ||
103 | + } | ||
104 | + } | ||
105 | + | ||
106 | + var l []SolutionPartner | ||
107 | + qs = qs.OrderBy(sortFields...) | ||
108 | + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil { | ||
109 | + if len(fields) == 0 { | ||
110 | + for _, v := range l { | ||
111 | + ml = append(ml, v) | ||
112 | + } | ||
113 | + } else { | ||
114 | + // trim unused fields | ||
115 | + for _, v := range l { | ||
116 | + m := make(map[string]interface{}) | ||
117 | + val := reflect.ValueOf(v) | ||
118 | + for _, fname := range fields { | ||
119 | + m[fname] = val.FieldByName(fname).Interface() | ||
120 | + } | ||
121 | + ml = append(ml, m) | ||
122 | + } | ||
123 | + } | ||
124 | + return ml, nil | ||
125 | + } | ||
126 | + return nil, err | ||
127 | +} | ||
128 | + | ||
129 | +// UpdateSolutionPartner updates SolutionPartner by Id and returns error if | ||
130 | +// the record to be updated doesn't exist | ||
131 | +func UpdateSolutionPartnerById(m *SolutionPartner) (err error) { | ||
132 | + o := orm.NewOrm() | ||
133 | + v := SolutionPartner{Id: m.Id} | ||
134 | + // ascertain id exists in the database | ||
135 | + if err = o.Read(&v); err == nil { | ||
136 | + var num int64 | ||
137 | + if num, err = o.Update(m); err == nil { | ||
138 | + fmt.Println("Number of records updated in database:", num) | ||
139 | + } | ||
140 | + } | ||
141 | + return | ||
142 | +} | ||
143 | + | ||
144 | +// DeleteSolutionPartner deletes SolutionPartner by Id and returns error if | ||
145 | +// the record to be deleted doesn't exist | ||
146 | +func DeleteSolutionPartner(id int) (err error) { | ||
147 | + o := orm.NewOrm() | ||
148 | + v := SolutionPartner{Id: id} | ||
149 | + // ascertain id exists in the database | ||
150 | + if err = o.Read(&v); err == nil { | ||
151 | + var num int64 | ||
152 | + if num, err = o.Delete(&SolutionPartner{Id: id}); err == nil { | ||
153 | + fmt.Println("Number of records deleted in database:", num) | ||
154 | + } | ||
155 | + } | ||
156 | + return | ||
157 | +} |
-
请 注册 或 登录 后发表评论