作者 yangfu

init

要显示太多修改。

为保证性能只显示 40 of 40+ 个文件。

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