作者 yangfu

机会初始化

要显示太多修改。

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

  1 +# Binaries for programs and plugins
  2 +*.exe
  3 +*.dll
  4 +*.so
  5 +*.dylib
  6 +*.vscode
  7 +
  8 +# Test binary, build with `go test -c`
  9 +*.test
  10 +
  11 +# Output of the go coverage tool, specifically when used with LiteIDE
  12 +*.out
  13 +
  14 +*.log
  15 +*debug
  16 +*wasm
  17 +
  18 +*.idea
  19 +
  20 +*.tmp
  21 +
  22 +*.sum
  23 +
  24 +opp
  25 +/vendor
  1 +FROM golang:1.13 as builder
  2 +
  3 +ENV GOPROXY https://goproxy.cn
  4 +ENV GO111MODULE on
  5 +
  6 +RUN git clone http://gitlab.fjmaimaimai.com/mmm-go/gocomm.git /app/gocomm
  7 +
  8 +WORKDIR /app/ability
  9 +
  10 +COPY go.mod .
  11 +COPY go.sum .
  12 +RUN go mod download
  13 +
  14 +COPY . .
  15 +
  16 +RUN GOOS=linux CGO_ENABLED=0 go build -ldflags="-s -w" -installsuffix cgo -o ability main.go
  17 +
  18 +#FROM scratch
  19 +FROM alpine:latest
  20 +RUN apk add --no-cache tzdata \
  21 + && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
  22 + && echo "Asia/Shanghai" > /etc/timezone \
  23 + && rm -rf /var/cache/apk/* /tmp/* /var/tmp/* $HOME/.cache ## 清除缓存
  24 +WORKDIR /root/
  25 +COPY --from=builder /app/ability .
  26 +#RUN ls -l
  27 +EXPOSE 8080
  28 +CMD ["./ability"]
  1 +## 目录
  2 +
  3 +- [项目说明](#项目说明)
  4 +- [代码声明](#代码声明)
  5 + - [命名规范](#命名规范)
  6 + - [项目约定](#项目约定)
  7 + - [注意事项](#注意事项)
  8 +
  9 +### 项目说明
  10 +
  11 +opp (opportunity) : 机会app服务端项目; 企业员工可以主动的把机会展示出来,另外有员工能把展示的机会抓 住、变现,从而形成自主的供需循环。使企业的运转正向向前进
  12 +
  13 +### 代码声明
  14 +
  15 +#### 命名规范
  16 +
  17 +1.包名
  18 +
  19 +```
  20 +*
  21 +package名和目录保持一致,需避免和标准库冲突
  22 +小写
  23 +*
  24 +package comm
  25 +```
  26 +
  27 +2.命名
  28 +
  29 +```
  30 +package pkg
  31 +
  32 +*1.错误*
  33 +/*
  34 +定义在包的首部,所有错误都定义在一起,
  35 +并且以Err开头
  36 +*/
  37 +var ErrFooBar = fmt.Errorf("pkg: ...")
  38 +
  39 +*2.变量*
  40 +/*
  41 +采用驼峰命名
  42 +*/
  43 +var fooBar int
  44 +
  45 +*3.常量*
  46 +/*
  47 +大写+下划线
  48 +*/
  49 +var(
  50 + FOO = 1
  51 + BAR = 2
  52 + FOO_BAR = 3
  53 +)
  54 +
  55 +*4.结构*
  56 +/*
  57 +采用驼峰命名法
  58 +*/
  59 +type FooBar struct{
  60 + foo int
  61 + Bar string
  62 +}
  63 +
  64 +
  65 +*5.方法接口*
  66 +/*
  67 +采用驼峰命名法
  68 +非对外方法,首字母需为小写
  69 +*/
  70 +func foo(){}
  71 +func Foo(){}
  72 +```
  73 +
  74 +3.目录结构
  75 +
  76 +```
  77 +* conf //配置
  78 + * dev.conf
  79 + * prod.conf
  80 +* controller //控制器
  81 + * v1
  82 + * auth.go
  83 +* internal
  84 + * repository //存储层
  85 + * user.go
  86 + * *_mock.go
  87 +* model //模型
  88 +* protocol //协议层
  89 +* routers //路由
  90 +* service //逻辑层
  91 + * auth
  92 +* static //静态数据
  93 +* views //视图
  94 +
  95 +* main.go
  96 +* Dockerfile
  97 +* README.md
  98 +* *.sh //脚本
  99 +```
  100 +
  101 +#### 项目约定
  102 +
  103 +1. 入参跟返回值都要定义一个协议结构 protocol.XxxRequest \*protocol.XxxResponse,方便扩展
  104 +2. 函数方法的变量都定义在函数的头几行 var( ... )
  105 +3. 服务调用尽量封装成接口,方便测试扩展 比如:ISmsServe{ Send() error }
  106 +4. 公用的基础代码库,需要做一下封装放在 [gocomm](http://gitlab.fjmaimaimai.com/mmm-go/gocomm) ,方便在其他项目中调用
  107 +5. 可以使用代码生成固定格式, [项目地址](http://gitlab.fjmaimaimai.com/mmm-go/gencode) 脚本:.\gencode.exe new -c Auth -m Login
  108 +
  109 +```
  110 +package pkg
  111 +//Login
  112 +func(this *AuthController)Login(){
  113 + var msg *protocol.ResponseMessage
  114 + defer func(){
  115 + this.Resp(msg)
  116 + }()
  117 + var request *protocol.LoginRequest
  118 + if err:=json.Unmarshal(this.ByteBody,&request);err!=nil{
  119 + log.Error(err)
  120 + msg = protocol.ReturnResponse(1)
  121 + return
  122 + }
  123 + if b,m :=this.Valid(request);!b{
  124 + msg = m
  125 + return
  126 + }
  127 + msg = this.GenMessage(auth.Login(request))
  128 +}
  129 +
  130 +/*Login */
  131 +type LoginRequest struct {
  132 + Xxx string`json:"xxx" valid:"Required"`
  133 +}
  134 +type LoginResponse struct {
  135 +}
  136 +
  137 +func Login(request *protocol.LoginRequest)(rsp *protocol.LoginResponse,err error){
  138 + var (
  139 +
  140 + )
  141 + rsp =&protocol.LoginResponse{}
  142 + return
  143 +}
  144 +```
  145 +
  146 +#### 注意事项
  147 +
  148 +1. 启动一个 groutine(eg:go func(){}()),需要在函数内进行 recover,不然 groutine 里面 panic,会导致外部程序一起崩溃掉;
  149 +2. 当接受者是 map, chan, func, 不要使用指针传递,因为它们本身就是引用类型
  150 +3. 当接受者类型是一个结构体并且很庞大,或者是一个大数组,建议使用指针传递来提高性能,其他场景使用值传递即可
  151 +4. 当接受者是一个结构体,并且包含了 sync.Mutex 或者类似的用于同步的成员。必须使用指针传递,避免成员拷贝
  152 +5. 当函数内部需要修改接受者,必须使用指针传递
  153 +6. 声明空的 slice 应该使用下面的格式: var t []string 不要使用 t := []string{} ,前者声明了一个 nil slice 而后者是一个长度为 0 的非 nil 的 slice。
  1 +#!/usr/bin/env bash
  2 +
  3 +##部署脚本/文件路径
  4 +#deploy_shell_path="/home/tiptok/test/ability.tar"
  5 +deploy_shell_path="/home/tiptok/test/ability.zip"
  6 +
  7 +go build -o ability main.go
  8 +chmod +x ability
  9 +#tar -zcvf ${deploy_shell_path} ability conf deploy.sh run.sh start.sh stop.sh
  10 +zip -r ${deploy_shell_path} ability conf deploy.sh run.sh start.sh stop.sh
  1 +appname = opportunity
  2 +httpport = 8080
  3 +runmode = dev
  4 +
  5 +#没设置的话 this.Ctx.Input.RequestBody 没有值
  6 +copyrequestbody = true
  7 +
  8 +#enablexsrf = true
  9 +
  10 +#开启应用内文档开关
  11 +EnableDocs = true
  12 +
  13 +include "dev.conf"
  14 +include "prod.conf"
  1 +[dev]
  2 +#数据库相关
  3 +data_source = "root:123456@tcp(192.168.100.102:3306)/opportunity?loc=Local"
  4 +#data_source = "root:sutianxia2015@tcp(115.29.205.99:3306)/ability_display"
  5 +#data_source = "root:root@tcp(localhost:3306)/ability_display?loc=Local"
  6 +
  7 +#redis相关配置
  8 +redis_add_port = "192.168.100.102:6379"
  9 +redis_auth = "123456"
  10 +
  11 +#sms相关配置
  12 +yunpian_sms_sdk_url ="https://sms.yunpian.com/v2/sms/single_send.json"
  13 +yunpian_app_key ="0bf6fb10a11a68a95dee80901eb545b5"
  14 +
  15 +#存储 http://ability.fjmaimaimai.com:8080/
  16 +source_host ="http://192.168.139.131:8080/"
  17 +source_virtual_path=file/ab
  18 +source_path =/home/tiptok/www/ab
  19 +
  20 +#网易云信 IM
  21 +net_im_base_url ="https://api.netease.im/nimserver"
  22 +net_im_app_secret ="a8d231f5c13a"
  23 +net_im_app_key ="9c5410602597a7fe367aeeebd8210262"
  1 +[prod]
  2 +#数据库相关
  3 +data_source = "root:123456@tcp(192.168.100.102:3306)/ability_display?loc=Local"
  4 +
  5 +
  6 +#redis相关配置
  7 +redis_add_port = "192.168.100.102:6379"
  8 +redis_auth = "123456"
  9 +
  10 +#sms相关配置
  11 +yunpian_sms_sdk_url ="https://sms.yunpian.com/v2/sms/single_send.json"
  12 +yunpian_app_key ="0bf6fb10a11a68a95dee80901eb545b5"
  13 +
  14 +#存储 http://ability.fjmaimaimai.com:8080/
  15 +source_host ="http://192.168.139.131:8080/"
  16 +source_virtual_path=file/ab
  17 +source_path =/home/tiptok/www/ab
  18 +
  19 +#网易云信 IM
  20 +net_im_base_url ="https://api.netease.im/nimserver"
  21 +net_im_app_secret ="a8d231f5c13a"
  22 +net_im_app_key ="9c5410602597a7fe367aeeebd8210262"
  1 +package controllers
  2 +
  3 +import (
  4 + "crypto/sha256"
  5 + "encoding/hex"
  6 + "fmt"
  7 + "strconv"
  8 + "strings"
  9 +
  10 + "opp/protocol"
  11 + s_auth "opp/services/auth"
  12 +
  13 + "github.com/astaxie/beego"
  14 + "github.com/astaxie/beego/context"
  15 + "github.com/astaxie/beego/validation"
  16 + "github.com/prometheus/client_golang/prometheus"
  17 + "gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
  18 + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
  19 + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/mybeego"
  20 +)
  21 +
  22 +var (
  23 + //prometheus 监控endpoint
  24 + HTTPReqTotal *prometheus.CounterVec
  25 + auth s_auth.IAuthService = &s_auth.AuthService{}
  26 +)
  27 +
  28 +type BaseController struct {
  29 + mybeego.BaseController
  30 +}
  31 +
  32 +func init() {
  33 + // HistogramVec 是一组Histogram
  34 + HTTPReqTotal = prometheus.NewCounterVec(prometheus.CounterOpts{
  35 + Name: "request_count_vec", //http_requests_total
  36 + Help: "total number of http requests made.",
  37 + }, []string{"method", "path"})
  38 + // 这里的"method"、"path"、"status" 都是label , "status"
  39 + prometheus.MustRegister(
  40 + HTTPReqTotal,
  41 + )
  42 + //if err:=prometheus.Register(HTTPReqTotal);err!=nil{
  43 + // log.Error(err)
  44 + //}
  45 +}
  46 +
  47 +var DefaultController *BaseController = &BaseController{}
  48 +
  49 +//Valid valid struct
  50 +func (this *BaseController) Valid(obj interface{}) (result bool, msg *protocol.ResponseMessage) {
  51 + /*校验*/
  52 + var err error
  53 + valid := validation.Validation{}
  54 + result, err = valid.Valid(obj)
  55 + if err != nil {
  56 + msg = protocol.BadRequestParam(1)
  57 + return
  58 + }
  59 + if !result {
  60 + for _, err := range valid.Errors {
  61 + log.Error(err.Key, err.Message)
  62 + }
  63 + msg = protocol.BadRequestParam(2)
  64 + return
  65 + }
  66 + return
  67 +}
  68 +
  69 +func (this *BaseController) Resp(msg *protocol.ResponseMessage) {
  70 +
  71 + this.Data["json"] = msg
  72 + this.ServeJSON()
  73 +}
  74 +
  75 +//GenMessage genarate a response message
  76 +// func (this *BaseController) GenMessage(rsp interface{}, err error) *protocol.ResponseMessage {
  77 +// var msg *protocol.ResponseMessage
  78 +// if err == nil {
  79 +// msg = protocol.ReturnResponse(0)
  80 +// msg.Data = rsp
  81 +// return msg
  82 +// }
  83 +// //log.Error(err)
  84 +// if e, ok := err.(common.Error); ok {
  85 +// msg = protocol.ReturnResponse(e.Code)
  86 +// msg.Data = rsp
  87 +// return msg
  88 +// }
  89 +// msg = protocol.ReturnResponse(1)
  90 +// return msg
  91 +// }
  92 +
  93 +//获取请求头信息
  94 +func GetRequestHeader(ctx *context.Context) *protocol.RequestHeader {
  95 + h := &protocol.RequestHeader{}
  96 + h.AccessToken = ctx.Input.Header("x-mmm-accesstoken")
  97 + h.AppProject = ctx.Input.Header("x-mmm-appproject")
  98 + h.DeviceType = ctx.Input.Header("x-mmm-devicetype")
  99 + h.Sign = ctx.Input.Header("x-mmm-sign")
  100 + h.Uuid = ctx.Input.Header("x-mmm-uuid")
  101 + h.TimeStamp = ctx.Input.Header("x-mmm-timestamp")
  102 + h.Uid, _ = strconv.ParseInt(ctx.Input.Header("uid"), 10, 64) //需要uid写入到header里面
  103 + return h
  104 +}
  105 +
  106 +//过滤器
  107 +func FilterComm(ctx *context.Context) {
  108 + //if strings.HasSuffix(ctx.Request.RequestURI,"login"){
  109 + // return
  110 + //}
  111 +
  112 + //统计
  113 + MetricCounter(ctx)
  114 +
  115 + if beego.BConfig.RunMode != "prod" {
  116 + return
  117 + }
  118 +
  119 + //1.检查签名
  120 + if !CheckSign(ctx) {
  121 + return
  122 + }
  123 + //2.检查token是否有效
  124 + if !CheckToken(ctx) {
  125 + return
  126 + }
  127 + //3.查重uuid
  128 + if !CheckUuid(ctx) {
  129 + return
  130 + }
  131 + return
  132 +}
  133 +
  134 +func MetricCounter(ctx *context.Context) {
  135 + // 请求数加1
  136 + HTTPReqTotal.With(prometheus.Labels{
  137 + "method": ctx.Request.Method,
  138 + "path": ctx.Request.RequestURI,
  139 + //"status": strconv.Itoa(c.Writer.Status()),
  140 + }).Inc()
  141 +}
  142 +
  143 +//检查签名
  144 +func CheckSign(ctx *context.Context) (result bool) {
  145 + var (
  146 + h *protocol.RequestHeader
  147 + sign string
  148 + signHex string
  149 + )
  150 + result = true
  151 + h = GetRequestHeader(ctx)
  152 + //1.检查签名
  153 + sign = fmt.Sprintf("v!(MmM%v%v%vMmM)i^", h.TimeStamp, h.Uuid, h.AccessToken)
  154 + sha256 := sha256.New()
  155 + sha256.Write([]byte(sign))
  156 + signHex = hex.EncodeToString(sha256.Sum(nil))
  157 + if strings.Compare(signHex, h.Sign) != 0 {
  158 + msg := protocol.BadRequestParam(113)
  159 + log.Error(fmt.Sprintf("%v req:%v resp:%v %v", ctx.Request.RequestURI, common.AssertJson(h), common.AssertJson(msg), signHex))
  160 + ctx.Output.JSON(msg, false, false)
  161 + result = false
  162 + return
  163 + }
  164 + return
  165 +}
  166 +
  167 +//检查access_token
  168 +func CheckToken(ctx *context.Context) (result bool) {
  169 + var (
  170 + msg *protocol.ResponseMessage
  171 + )
  172 + result = true
  173 + defer func() {
  174 + if msg != nil {
  175 + result = false
  176 + ctx.Output.JSON(msg, false, false)
  177 + }
  178 + }()
  179 + token := ctx.Input.Header("x-mmm-accesstoken")
  180 + if rsp, err := auth.CheckToken(&protocol.CheckTokenRequest{Token: token}); err != nil || rsp.UserInfo == nil {
  181 + msg = protocol.NewReturnResponse(rsp, err)
  182 + log.Error(fmt.Sprintf("%v req:%v resp:%v", ctx.Request.RequestURI, token, common.AssertJson(msg)))
  183 + return
  184 + } else {
  185 + if rsp.UserInfo != nil {
  186 + //设置附加数据
  187 + ctx.Request.Header.Add("uid", fmt.Sprintf("%v", rsp.UserInfo.Uuid))
  188 + }
  189 + }
  190 + return
  191 +}
  192 +
  193 +//检查Uuid
  194 +func CheckUuid(ctx *context.Context) (result bool) {
  195 + var (
  196 + msg *protocol.ResponseMessage
  197 + )
  198 + result = true
  199 + defer func() {
  200 + if msg != nil {
  201 + result = false
  202 + ctx.Output.JSON(msg, false, false)
  203 + }
  204 + }()
  205 + uuid := ctx.Input.Header("x-mmm-uuid")
  206 + msg = protocol.NewReturnResponse(auth.CheckUuid(&protocol.CheckUuidRequest{Uuid: uuid}))
  207 + if msg != nil {
  208 + log.Error(fmt.Sprintf("%v req:%v resp:%v", ctx.Request.RequestURI, uuid, common.AssertJson(msg)))
  209 + }
  210 + return
  211 +}
  1 +package controllers
  2 +
  3 +import (
  4 + "fmt"
  5 + "log"
  6 + "reflect"
  7 + "testing"
  8 + "time"
  9 +
  10 + "gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
  11 + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/mybeego"
  12 +)
  13 +
  14 +func Test_GenMessage(t *testing.T) {
  15 + input := []struct {
  16 + Rsp interface{}
  17 + Error error
  18 + Exceprt *mybeego.Message
  19 + }{
  20 + {Rsp: "test", Error: fmt.Errorf("test"), Exceprt: mybeego.NewMessage(1)},
  21 + {Rsp: "test-A", Error: common.NewErrorWithMsg(100, "test-A"), Exceprt: mybeego.NewErrMessage(100, "test-A")},
  22 + }
  23 +
  24 + for i := range input {
  25 + o := input[i]
  26 + out := DefaultController.GenMessage(o.Rsp, o.Error)
  27 + if !reflect.DeepEqual(out, o.Exceprt) {
  28 + log.Fatal("not equal ", out, o.Exceprt)
  29 + }
  30 + }
  31 +}
  32 +
  33 +func Benchmark_GenMessage(b *testing.B) {
  34 + o := struct {
  35 + Rsp interface{}
  36 + Error error
  37 + Exceprt *mybeego.Message
  38 + }{Rsp: "test", Error: fmt.Errorf("test"), Exceprt: mybeego.NewMessage(1)}
  39 + for i := 0; i < b.N; i++ {
  40 + out := DefaultController.GenMessage(o.Rsp, o.Error)
  41 + if out.Errmsg != o.Exceprt.Errmsg || out.Errno != o.Exceprt.Errno {
  42 + log.Fatal("not equal ", out, o.Exceprt)
  43 + }
  44 + }
  45 +}
  46 +
  47 +func TestXXX(t *testing.T) {
  48 + t.Log(time.Now())
  49 +}
  1 +package v1
  2 +
  3 +import (
  4 + "encoding/json"
  5 +
  6 + "opp/controllers"
  7 + "opp/protocol"
  8 + s_auth "opp/services/auth"
  9 +
  10 + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
  11 +)
  12 +
  13 +var (
  14 + auth s_auth.IAuthService = &s_auth.AuthService{}
  15 +)
  16 +
  17 +type AuthController struct {
  18 + controllers.BaseController
  19 +}
  20 +
  21 +// Login
  22 +// @router /login [post]
  23 +func (this *AuthController) Login() {
  24 + var msg *protocol.ResponseMessage
  25 + defer func() {
  26 + this.Resp(msg)
  27 + }()
  28 + var request *protocol.LoginRequest
  29 + if err := json.Unmarshal(this.ByteBody, &request); err != nil {
  30 + log.Error(err)
  31 + msg = protocol.BadRequestParam(1)
  32 + return
  33 + }
  34 + if b, m := this.Valid(request); !b {
  35 + msg = m
  36 + return
  37 + }
  38 + msg = protocol.NewReturnResponse(auth.Login(request))
  39 +}
  40 +
  41 +//SmsCode
  42 +// @router /smsCode [post]
  43 +func (this *AuthController) SmsCode() {
  44 + var msg *protocol.ResponseMessage
  45 + defer func() {
  46 + this.Resp(msg)
  47 + }()
  48 + var request *protocol.SmsCodeRequest
  49 + if err := json.Unmarshal(this.ByteBody, &request); err != nil {
  50 + log.Error(err)
  51 + msg = protocol.BadRequestParam(1)
  52 + return
  53 + }
  54 + if b, m := this.Valid(request); !b {
  55 + msg = m
  56 + return
  57 + }
  58 + msg = protocol.NewReturnResponse(auth.SmsCode(request))
  59 +}
  60 +
  61 +//UpdateDevice
  62 +// @router /updateDevice [post]
  63 +func (this *AuthController) UpdateDevice() {
  64 + var msg *protocol.ResponseMessage
  65 + defer func() {
  66 + this.Resp(msg)
  67 + }()
  68 + var request *protocol.UpdateDeviceRequest
  69 + if err := json.Unmarshal(this.ByteBody, &request); err != nil {
  70 + log.Error(err)
  71 + msg = protocol.BadRequestParam(1)
  72 + return
  73 + }
  74 + if b, m := this.Valid(request); !b {
  75 + msg = m
  76 + return
  77 + }
  78 + msg = protocol.NewReturnResponse(auth.UpdateDevice(request))
  79 +}
  80 +
  81 +//AccessToken
  82 +// @router /accessToken [post]
  83 +func (this *AuthController) AccessToken() {
  84 + var msg *protocol.ResponseMessage
  85 + defer func() {
  86 + this.Resp(msg)
  87 + }()
  88 + var request *protocol.AccessTokenRequest
  89 + if err := json.Unmarshal(this.ByteBody, &request); err != nil {
  90 + log.Error(err)
  91 + msg = protocol.BadRequestParam(1)
  92 + return
  93 + }
  94 + if b, m := this.Valid(request); !b {
  95 + msg = m
  96 + return
  97 + }
  98 + msg = protocol.NewReturnResponse(auth.AccessToken(request))
  99 +}
  100 +
  101 +//RefreshToken
  102 +// @router /refreshToken [post]
  103 +func (this *AuthController) RefreshToken() {
  104 + var msg *protocol.ResponseMessage
  105 + defer func() {
  106 + this.Resp(msg)
  107 + }()
  108 + var request *protocol.RefreshTokenRequest
  109 + if err := json.Unmarshal(this.ByteBody, &request); err != nil {
  110 + log.Error(err)
  111 + msg = protocol.BadRequestParam(1)
  112 + return
  113 + }
  114 + if b, m := this.Valid(request); !b {
  115 + msg = m
  116 + return
  117 + }
  118 + msg = protocol.NewReturnResponse(auth.RefreshToken(request))
  119 +}
  1 +package v1
  2 +
  3 +import (
  4 + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/mybeego"
  5 +)
  6 +
  7 +type MainController struct {
  8 + mybeego.BaseController
  9 +}
  10 +
  11 +// URLMapping ...
  12 +func (this *MainController) URLMapping() {
  13 + //this.Mapping("Get", this.Get)
  14 + //this.Mapping("Hello", this.Hello)
  15 +}
  16 +
  17 +func (c *MainController) Get() {
  18 + c.Data["Website"] = "beego.me"
  19 + c.Data["Email"] = "astaxie@gmail.com"
  20 + c.TplName = "index.tpl"
  21 +}
  1 +package v1
  2 +
  3 +import (
  4 + "opp/controllers"
  5 + "opp/protocol"
  6 + "opp/services/upload"
  7 +
  8 + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
  9 +)
  10 +
  11 +type UploadController struct {
  12 + controllers.BaseController
  13 +}
  14 +
  15 +// Image
  16 +// @router /image [post]
  17 +func (this *UploadController) Image() {
  18 + var (
  19 + msg *protocol.ResponseMessage
  20 + err error
  21 + )
  22 + defer func() {
  23 + this.Resp(msg)
  24 + }()
  25 + var request = &protocol.FileRequest{}
  26 + //if err:=json.Unmarshal(this.ByteBody,&request);err!=nil{
  27 + // log.Error(err)
  28 + // msg = protocol.ReturnResponse(1)
  29 + // return
  30 + //}
  31 + //if b,m :=this.Valid(request);!b{
  32 + // msg = m
  33 + // return
  34 + //}
  35 + if request.Files, err = this.GetFiles("file"); err != nil {
  36 + log.Error(err)
  37 + return
  38 + }
  39 + msg = protocol.NewReturnResponse(upload.Image(request))
  40 +}
  41 +
  42 +// Image
  43 +// @router /voice [post]
  44 +func (this *UploadController) Voice() {
  45 + var (
  46 + msg *protocol.ResponseMessage
  47 + err error
  48 + )
  49 + defer func() {
  50 + this.Resp(msg)
  51 + }()
  52 + var request = &protocol.FileRequest{}
  53 + //if err:=json.Unmarshal(this.ByteBody,&request);err!=nil{
  54 + // log.Error(err)
  55 + // msg = protocol.ReturnResponse(1)
  56 + // return
  57 + //}
  58 + //if b,m :=this.Valid(request);!b{
  59 + // msg = m
  60 + // return
  61 + //}
  62 + if request.Files, err = this.GetFiles("file"); err != nil {
  63 + log.Error(err)
  64 + return
  65 + }
  66 + msg = protocol.NewReturnResponse(upload.Voice(request))
  67 +}
  1 +package v1
  2 +
  3 +import (
  4 + "encoding/json"
  5 +
  6 + "opp/controllers"
  7 + "opp/protocol"
  8 + "opp/services/version"
  9 +
  10 + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
  11 +)
  12 +
  13 +type VersionController struct {
  14 + controllers.BaseController
  15 +}
  16 +
  17 +//GetLatestVersionInfo
  18 +func (this *VersionController) GetLatestVersionInfo() {
  19 + var msg *protocol.ResponseMessage
  20 + defer func() {
  21 + this.Resp(msg)
  22 + }()
  23 + var request *protocol.GetLatestVersionInfoRequest
  24 + if err := json.Unmarshal(this.ByteBody, &request); err != nil {
  25 + log.Error(err)
  26 + msg = protocol.BadRequestParam(1)
  27 + return
  28 + }
  29 + if b, m := this.Valid(request); !b {
  30 + msg = m
  31 + return
  32 + }
  33 + msg = protocol.NewReturnResponse(version.GetLatestVersionInfo(request))
  34 +}
  1 +package v1
  2 +
  3 +import (
  4 + "opp/controllers"
  5 +)
  6 +
  7 +type WebSocketController struct {
  8 + controllers.BaseController
  9 +}
  1 +#!/bin/bash
  2 +
  3 +time=$(date +%Y%m%d_%H%m%s)
  4 +project_name="ability"
  5 +##部署脚本/文件路径
  6 +deploy_shell_path="/home/tiptok/test"
  7 +##部署路径
  8 +project_root_path="/home/tiptok/www"
  9 +project_path="${project_root_path}/${project_name}"
  10 +##备份路径
  11 +project_bak_path="/home/tiptok/www/bin_bak"
  12 +
  13 +projcet_bak_file="${project_bak_path}/${time}_${project_name}.tar"
  14 +
  15 +## 看压缩文件的格式 tar / zip
  16 +#project_gzip_file="${deploy_shell_path}/${project_name}.tar"
  17 +project_gzip_file="${deploy_shell_path}/${project_name}.zip"
  18 +
  19 +conpress_type="${project_gzip_file##*.}"
  20 +
  21 +echo "------begin deploy-------"
  22 +echo "ProjectName: ${project_name}"
  23 +echo "ProjectPath: ${project_path}"
  24 +echo "ProjectBakFile : ${projcet_bak_file}"
  25 +echo "ProjectGzipFile : ${project_gzip_file}"
  26 +echo "ConpressType : ${conpress_type}"
  27 +
  28 +
  29 +if [ ! -d ${project_bak_path} ];then
  30 + mkdir -p ${project_bak_path}
  31 + echo "mkdir ${project_bak_path}"
  32 +fi
  33 +
  34 +if [ ! -d ${project_path} ];then
  35 + mkdir -p ${project_path}
  36 + echo "mkdir ${project_path}"
  37 +else
  38 + echo "backup : ${projcet_bak_file}"
  39 + cd $project_path && tar -zcf ${projcet_bak_file} * ||(echo "backup failed"; exit 1)
  40 + rm -fr "${project_path}/" *
  41 +fi
  42 +
  43 +echo "------begin tar-------"
  44 +if [ ! -e ${project_path} ];then
  45 + mkdir -p ${project_path}
  46 + echo "mkdir ${project_path}"
  47 +fi
  48 +
  49 +if [ -f ${project_gzip_file} ];then
  50 + if [ ${conpress_type} == "tar" ];then
  51 + tar -xzf ${project_gzip_file} -C "${project_root_path}/${project_name}"||(echo "tar -x failed"; exit 1)
  52 + elif [ ${conpress_type} == "zip" ];then
  53 + unzip -o ${project_gzip_file} -d "${project_root_path}/${project_name}"||(echo "tar -x failed"; exit 1)
  54 + fi
  55 + rm -fr ${project_gzip_file}
  56 +else
  57 + echo "project_gzip_file not exists! please upload zip file ..."
  58 + exit 0
  59 +fi
  60 +
  61 +echo "------begin start-------"
  62 +cd ${project_path} && ./start.sh ${project_name}
  63 +
  64 +
  1 +version: '3.1' #指定docker-compose 版本
  2 +
  3 +services:
  4 + redis:
  5 + image: redis #使用 镜像
  6 + container_name: gocomm_redis
  7 + command: redis-server /usr/local/etc/redis/redis.conf
  8 + ports: #
  9 + - 6379:6379
  10 + volumes:
  11 + - ./data:/data
  12 + - ./redis.conf:/usr/local/etc/redis/redis.conf
  13 + db:
  14 + #构建mysql镜像
  15 + image: mysql
  16 + container_name: gocomm-mysql # 容器名
  17 + command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci #设置utf8字符集
  18 + restart: always
  19 + environment:
  20 + MYSQL_ROOT_PASSWORD: 123456 #root管理员用户密码
  21 + MYSQL_USER: test #创建test用户
  22 + MYSQL_PASSWORD: 123456 #设置test用户的密码
  23 + ports:
  24 + - 3306:3306 #host物理直接映射端口为6606
  25 + volumes:
  26 + #mysql数据库挂载到host物理机目录/e/docker/mysql/data/db
  27 + - "/docker/mysql/data/db:/var/lib/mysql"
  28 + #容器的配置目录挂载到host物理机目录/e/docker/mysql/data/conf
  29 + - "/docker/mysql/data/conf:/etc/mysql/conf.d"
  30 + ability: #定义服务名称
  31 + build: ./ #引入了 build 的路径,它指向一个存有 Dockerfile 的目录
  32 + ports: #
  33 + - 8081:8081
  34 + environment:
  35 + RUNMODULE: "PROD"
  1 +module opp
  2 +
  3 +go 1.12
  4 +
  5 +require (
  6 + github.com/astaxie/beego v1.10.0
  7 + github.com/go-sql-driver/mysql v1.4.1
  8 + github.com/gorilla/websocket v1.4.1
  9 + github.com/prometheus/client_golang v1.1.0
  10 + github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337 // indirect
  11 + gitlab.fjmaimaimai.com/mmm-go/gocomm v0.0.1
  12 + google.golang.org/appengine v1.6.2 // indirect
  13 +)
  14 +
  15 +replace gitlab.fjmaimaimai.com/mmm-go/gocomm => ../gocomm
  1 +package repository
  2 +
  3 +import "opp/models"
  4 +
  5 +type IConfigRepository interface {
  6 + GetCfgClient(clintId, clientSecret string) (v *models.CfgClient, err error)
  7 +}
  8 +
  9 +type ConfigRepository struct{}
  10 +
  11 +func (r *ConfigRepository) GetCfgClient(clintId, clientSecret string) (v *models.CfgClient, err error) {
  12 + return models.GetCfgClient(clintId, clientSecret)
  13 +}
  1 +package repository
  2 +
  3 +import "opp/models"
  4 +
  5 +type ConfigMockeRepository struct{}
  6 +
  7 +func (r *ConfigMockeRepository) GetCfgClient(clintId, clientSecret string) (v *models.CfgClient, err error) {
  8 + return
  9 +}
  1 +package repository
  2 +
  3 +import "opp/models"
  4 +
  5 +type IUserRepository interface {
  6 + GetUsersByMobile(mobile string) (v *models.Users, err error)
  7 + GetUserInfoByMobile(mobile string) (v *models.UserInfo, err error)
  8 + UpdateUserInfoById(m *models.UserInfo) (err error)
  9 + GetUserInfoByAuthCode(authCode string) (v *models.UserInfo, err error)
  10 + GetUserInfoByRefreshToken(refreshToken string) (v *models.UserInfo, err error)
  11 +}
  12 +
  13 +func assertImplement() {
  14 + var _ IUserRepository = (*UserRepository)(nil)
  15 +}
  16 +
  17 +type UserRepository struct{}
  18 +
  19 +func (r *UserRepository) GetUsersByMobile(mobile string) (v *models.Users, err error) {
  20 + return models.GetUsersByMobile(mobile)
  21 +}
  22 +
  23 +func (r *UserRepository) GetUserInfoByMobile(mobile string) (v *models.UserInfo, err error) {
  24 + return models.GetUserInfoByMobile(mobile)
  25 +}
  26 +
  27 +func (r *UserRepository) UpdateUserInfoById(m *models.UserInfo) (err error) {
  28 + return models.UpdateUserInfoById(m)
  29 +}
  30 +
  31 +func (r *UserRepository) GetUserInfoByAuthCode(authCode string) (v *models.UserInfo, err error) {
  32 + return models.GetUserInfoByAuthCode(authCode)
  33 +}
  34 +
  35 +func (r *UserRepository) GetUserInfoByRefreshToken(refreshToken string) (v *models.UserInfo, err error) {
  36 + return models.GetUserInfoByRefreshToken(refreshToken)
  37 +}
  1 +package repository
  2 +
  3 +import "opp/models"
  4 +
  5 +type UserMockRepository struct{}
  6 +
  7 +var userInfo = &models.UserInfo{
  8 + Auth: "897ca746f46b11e98771000c29ad8d6d",
  9 + AccessToken: "897ca746f46b11e98771000c29ad8d7d",
  10 + RefreshToken: "897ca746f46b11e98771000c29ad8d8d",
  11 +}
  12 +
  13 +func (r *UserMockRepository) GetUsersByMobile(mobile string) (v *models.Users, err error) {
  14 + v = &models.Users{
  15 + Username: "18065048389",
  16 + Password: "$2y$10$YWg7jPRVLBzc3kevokMkW.boswtCvhToqC.TappIwfqwJ.cI0efvy",
  17 + }
  18 + return
  19 +}
  20 +
  21 +func (r *UserMockRepository) GetUserInfoByMobile(mobile string) (v *models.UserInfo, err error) {
  22 + v = userInfo
  23 + return
  24 +}
  25 +
  26 +func (r *UserMockRepository) UpdateUserInfoById(m *models.UserInfo) (err error) {
  27 + return
  28 +}
  29 +
  30 +func (r *UserMockRepository) GetUserInfoByAuthCode(authCode string) (v *models.UserInfo, err error) {
  31 + v = userInfo
  32 + return
  33 +}
  34 +
  35 +func (r *UserMockRepository) GetUserInfoByRefreshToken(refreshToken string) (v *models.UserInfo, err error) {
  36 + v = userInfo
  37 + return
  38 +}
  1 +package main
  2 +
  3 +import (
  4 + "github.com/astaxie/beego"
  5 + _ "github.com/go-sql-driver/mysql"
  6 + "gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
  7 + "gitlab.fjmaimaimai.com/mmm-go/gocomm/config"
  8 + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
  9 + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/orm"
  10 + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/redis"
  11 + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/websocket"
  12 + "opp/controllers"
  13 + "opp/protocol"
  14 + _ "opp/routers"
  15 + "opp/services/im"
  16 + "time"
  17 +)
  18 +
  19 +func init() {
  20 + time.Local = time.FixedZone("CST", 3600*8)
  21 + log.InitLog(config.Logger{
  22 + Filename: "app.log",
  23 + Level: "7",
  24 + })
  25 + //TODO:kafka配置
  26 + log.InitKafkaLogger(log.KafkaConfig{
  27 + Topic: "ability",
  28 + Addrs: []string{"127.0.0.1:9092"},
  29 + Level: 6,
  30 + })
  31 + err := redis.InitWithDb(100, beego.AppConfig.String("redis_add_port"), beego.AppConfig.String("redis_auth"), "0")
  32 + if err != nil {
  33 + log.Fatal(err, beego.AppConfig.String("redis_add_port"), beego.AppConfig.String("redis_auth"))
  34 + //panic(err)
  35 + }
  36 + orm.NewBeeormEngine(config.Mysql{
  37 + AliasName: "default",
  38 + DataSource: beego.AppConfig.String("data_source"),
  39 + MaxIdle: 100,
  40 + MaxOpen: 100,
  41 + })
  42 + //TODO:邮件服务配置
  43 + common.InitMailService(&common.MailConfig{
  44 + //Host:"smtp.qq.com",
  45 + //Port:465,
  46 + //From:"785410885@qq.com",
  47 + //Password:"ibfduqhfmgypbffe", //授权码
  48 + //IsUseSsl:true,
  49 + })
  50 + im.InitImClient(beego.AppConfig.String("net_im_base_url"), beego.AppConfig.String("net_im_app_key"), beego.AppConfig.String("net_im_app_secret"))
  51 + websocket.InitWebsocketConnmgrs(10)
  52 +}
  53 +
  54 +func main() {
  55 + defer func() {
  56 + log.Info("app on stop!")
  57 + }()
  58 + beego.InsertFilter("/*", beego.BeforeRouter, controllers.FilterComm)
  59 + protocol.InitMessageCode()
  60 + log.Info("app on start!")
  61 + log.Info("Beego Run Mode:", beego.BConfig.RunMode)
  62 +
  63 + beego.Run()
  64 +}
  1 +package models
  2 +
  3 +import (
  4 + "errors"
  5 + "fmt"
  6 + "reflect"
  7 + "strings"
  8 + "time"
  9 +
  10 + "github.com/astaxie/beego/orm"
  11 +)
  12 +
  13 +type Announcement struct {
  14 + Id int `orm:"column(id);pk" description:"主键ID"`
  15 + CreateTime time.Time `orm:"column(createTime);type(timestamp);auto_now_add" description:"创建时间"`
  16 + Content string `orm:"column(content);size(500)" description:"消息标题"`
  17 + CompanyId int64 `orm:"column(company_id);null"`
  18 + Day string `orm:"column(day);size(20)" description:"日期"`
  19 +}
  20 +
  21 +func (t *Announcement) TableName() string {
  22 + return "announcement"
  23 +}
  24 +
  25 +func init() {
  26 + orm.RegisterModel(new(Announcement))
  27 +}
  28 +
  29 +// AddAnnouncement insert a new Announcement into database and returns
  30 +// last inserted Id on success.
  31 +func AddAnnouncement(m *Announcement) (id int64, err error) {
  32 + o := orm.NewOrm()
  33 + id, err = o.Insert(m)
  34 + return
  35 +}
  36 +
  37 +// GetAnnouncementById retrieves Announcement by Id. Returns error if
  38 +// Id doesn't exist
  39 +func GetAnnouncementById(id int) (v *Announcement, err error) {
  40 + o := orm.NewOrm()
  41 + v = &Announcement{Id: id}
  42 + if err = o.Read(v); err == nil {
  43 + return v, nil
  44 + }
  45 + return nil, err
  46 +}
  47 +
  48 +// GetAllAnnouncement retrieves all Announcement matches certain condition. Returns empty list if
  49 +// no records exist
  50 +func GetAllAnnouncement(query map[string]string, fields []string, sortby []string, order []string,
  51 + offset int64, limit int64) (ml []interface{}, err error) {
  52 + o := orm.NewOrm()
  53 + qs := o.QueryTable(new(Announcement))
  54 + // query k=v
  55 + for k, v := range query {
  56 + // rewrite dot-notation to Object__Attribute
  57 + k = strings.Replace(k, ".", "__", -1)
  58 + if strings.Contains(k, "isnull") {
  59 + qs = qs.Filter(k, (v == "true" || v == "1"))
  60 + } else {
  61 + qs = qs.Filter(k, v)
  62 + }
  63 + }
  64 + // order by:
  65 + var sortFields []string
  66 + if len(sortby) != 0 {
  67 + if len(sortby) == len(order) {
  68 + // 1) for each sort field, there is an associated order
  69 + for i, v := range sortby {
  70 + orderby := ""
  71 + if order[i] == "desc" {
  72 + orderby = "-" + v
  73 + } else if order[i] == "asc" {
  74 + orderby = v
  75 + } else {
  76 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  77 + }
  78 + sortFields = append(sortFields, orderby)
  79 + }
  80 + qs = qs.OrderBy(sortFields...)
  81 + } else if len(sortby) != len(order) && len(order) == 1 {
  82 + // 2) there is exactly one order, all the sorted fields will be sorted by this order
  83 + for _, v := range sortby {
  84 + orderby := ""
  85 + if order[0] == "desc" {
  86 + orderby = "-" + v
  87 + } else if order[0] == "asc" {
  88 + orderby = v
  89 + } else {
  90 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  91 + }
  92 + sortFields = append(sortFields, orderby)
  93 + }
  94 + } else if len(sortby) != len(order) && len(order) != 1 {
  95 + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
  96 + }
  97 + } else {
  98 + if len(order) != 0 {
  99 + return nil, errors.New("Error: unused 'order' fields")
  100 + }
  101 + }
  102 +
  103 + var l []Announcement
  104 + qs = qs.OrderBy(sortFields...)
  105 + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
  106 + if len(fields) == 0 {
  107 + for _, v := range l {
  108 + ml = append(ml, v)
  109 + }
  110 + } else {
  111 + // trim unused fields
  112 + for _, v := range l {
  113 + m := make(map[string]interface{})
  114 + val := reflect.ValueOf(v)
  115 + for _, fname := range fields {
  116 + m[fname] = val.FieldByName(fname).Interface()
  117 + }
  118 + ml = append(ml, m)
  119 + }
  120 + }
  121 + return ml, nil
  122 + }
  123 + return nil, err
  124 +}
  125 +
  126 +// UpdateAnnouncement updates Announcement by Id and returns error if
  127 +// the record to be updated doesn't exist
  128 +func UpdateAnnouncementById(m *Announcement) (err error) {
  129 + o := orm.NewOrm()
  130 + v := Announcement{Id: m.Id}
  131 + // ascertain id exists in the database
  132 + if err = o.Read(&v); err == nil {
  133 + var num int64
  134 + if num, err = o.Update(m); err == nil {
  135 + fmt.Println("Number of records updated in database:", num)
  136 + }
  137 + }
  138 + return
  139 +}
  140 +
  141 +// DeleteAnnouncement deletes Announcement by Id and returns error if
  142 +// the record to be deleted doesn't exist
  143 +func DeleteAnnouncement(id int) (err error) {
  144 + o := orm.NewOrm()
  145 + v := Announcement{Id: id}
  146 + // ascertain id exists in the database
  147 + if err = o.Read(&v); err == nil {
  148 + var num int64
  149 + if num, err = o.Delete(&Announcement{Id: id}); err == nil {
  150 + fmt.Println("Number of records deleted in database:", num)
  151 + }
  152 + }
  153 + return
  154 +}
  1 +package models
  2 +
  3 +import (
  4 + "errors"
  5 + "fmt"
  6 + "reflect"
  7 + "strings"
  8 + "time"
  9 +
  10 + "github.com/astaxie/beego/orm"
  11 +)
  12 +
  13 +type BonusPoint struct {
  14 + Id int `orm:"column(id);pk"`
  15 + CompanyId int `orm:"column(company_id)" description:"公司ID"`
  16 + Type int8 `orm:"column(type)" description:"加分类型 0发现 1分析 2解决"`
  17 + Uid int64 `orm:"column(uid)" description:"被加分人"`
  18 + Score int `orm:"column(score)" description:"加分数值"`
  19 + JoinDate time.Time `orm:"column(join_date);type(date)" description:"加入年月"`
  20 + OperatorId int64 `orm:"column(operator_id)" description:"加分人(操作者id)"`
  21 + Reason string `orm:"column(reason);size(500);null" description:"加分理由"`
  22 + CreateTime time.Time `orm:"column(createTime);type(timestamp);auto_now_add"`
  23 + UpdateTime time.Time `orm:"column(updateTime);type(timestamp);auto_now_add"`
  24 +}
  25 +
  26 +func (t *BonusPoint) TableName() string {
  27 + return "bonus_point"
  28 +}
  29 +
  30 +func init() {
  31 + orm.RegisterModel(new(BonusPoint))
  32 +}
  33 +
  34 +// AddBonusPoint insert a new BonusPoint into database and returns
  35 +// last inserted Id on success.
  36 +func AddBonusPoint(m *BonusPoint) (id int64, err error) {
  37 + o := orm.NewOrm()
  38 + id, err = o.Insert(m)
  39 + return
  40 +}
  41 +
  42 +// GetBonusPointById retrieves BonusPoint by Id. Returns error if
  43 +// Id doesn't exist
  44 +func GetBonusPointById(id int) (v *BonusPoint, err error) {
  45 + o := orm.NewOrm()
  46 + v = &BonusPoint{Id: id}
  47 + if err = o.Read(v); err == nil {
  48 + return v, nil
  49 + }
  50 + return nil, err
  51 +}
  52 +
  53 +// GetAllBonusPoint retrieves all BonusPoint matches certain condition. Returns empty list if
  54 +// no records exist
  55 +func GetAllBonusPoint(query map[string]string, fields []string, sortby []string, order []string,
  56 + offset int64, limit int64) (ml []interface{}, err error) {
  57 + o := orm.NewOrm()
  58 + qs := o.QueryTable(new(BonusPoint))
  59 + // query k=v
  60 + for k, v := range query {
  61 + // rewrite dot-notation to Object__Attribute
  62 + k = strings.Replace(k, ".", "__", -1)
  63 + if strings.Contains(k, "isnull") {
  64 + qs = qs.Filter(k, (v == "true" || v == "1"))
  65 + } else {
  66 + qs = qs.Filter(k, v)
  67 + }
  68 + }
  69 + // order by:
  70 + var sortFields []string
  71 + if len(sortby) != 0 {
  72 + if len(sortby) == len(order) {
  73 + // 1) for each sort field, there is an associated order
  74 + for i, v := range sortby {
  75 + orderby := ""
  76 + if order[i] == "desc" {
  77 + orderby = "-" + v
  78 + } else if order[i] == "asc" {
  79 + orderby = v
  80 + } else {
  81 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  82 + }
  83 + sortFields = append(sortFields, orderby)
  84 + }
  85 + qs = qs.OrderBy(sortFields...)
  86 + } else if len(sortby) != len(order) && len(order) == 1 {
  87 + // 2) there is exactly one order, all the sorted fields will be sorted by this order
  88 + for _, v := range sortby {
  89 + orderby := ""
  90 + if order[0] == "desc" {
  91 + orderby = "-" + v
  92 + } else if order[0] == "asc" {
  93 + orderby = v
  94 + } else {
  95 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  96 + }
  97 + sortFields = append(sortFields, orderby)
  98 + }
  99 + } else if len(sortby) != len(order) && len(order) != 1 {
  100 + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
  101 + }
  102 + } else {
  103 + if len(order) != 0 {
  104 + return nil, errors.New("Error: unused 'order' fields")
  105 + }
  106 + }
  107 +
  108 + var l []BonusPoint
  109 + qs = qs.OrderBy(sortFields...)
  110 + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
  111 + if len(fields) == 0 {
  112 + for _, v := range l {
  113 + ml = append(ml, v)
  114 + }
  115 + } else {
  116 + // trim unused fields
  117 + for _, v := range l {
  118 + m := make(map[string]interface{})
  119 + val := reflect.ValueOf(v)
  120 + for _, fname := range fields {
  121 + m[fname] = val.FieldByName(fname).Interface()
  122 + }
  123 + ml = append(ml, m)
  124 + }
  125 + }
  126 + return ml, nil
  127 + }
  128 + return nil, err
  129 +}
  130 +
  131 +// UpdateBonusPoint updates BonusPoint by Id and returns error if
  132 +// the record to be updated doesn't exist
  133 +func UpdateBonusPointById(m *BonusPoint) (err error) {
  134 + o := orm.NewOrm()
  135 + v := BonusPoint{Id: m.Id}
  136 + // ascertain id exists in the database
  137 + if err = o.Read(&v); err == nil {
  138 + var num int64
  139 + if num, err = o.Update(m); err == nil {
  140 + fmt.Println("Number of records updated in database:", num)
  141 + }
  142 + }
  143 + return
  144 +}
  145 +
  146 +// DeleteBonusPoint deletes BonusPoint by Id and returns error if
  147 +// the record to be deleted doesn't exist
  148 +func DeleteBonusPoint(id int) (err error) {
  149 + o := orm.NewOrm()
  150 + v := BonusPoint{Id: id}
  151 + // ascertain id exists in the database
  152 + if err = o.Read(&v); err == nil {
  153 + var num int64
  154 + if num, err = o.Delete(&BonusPoint{Id: id}); err == nil {
  155 + fmt.Println("Number of records deleted in database:", num)
  156 + }
  157 + }
  158 + return
  159 +}
  1 +package models
  2 +
  3 +import (
  4 + "errors"
  5 + "fmt"
  6 + "reflect"
  7 + "strings"
  8 + "time"
  9 +
  10 + "github.com/astaxie/beego/orm"
  11 +)
  12 +
  13 +type Bulletin struct {
  14 + Id int `orm:"column(id);auto"`
  15 + Title string `orm:"column(title);size(2000);null" description:"标题"`
  16 + Content string `orm:"column(content);null" description:"内容"`
  17 + Cover string `orm:"column(cover);size(255);null" description:"封面地址"`
  18 + W int `orm:"column(w);null" description:"宽"`
  19 + H int `orm:"column(h);null" description:"高"`
  20 + Type int8 `orm:"column(type);null" description:"公告类型(0图+跳转链接、1链接)"`
  21 + Receiver string `orm:"column(receiver);null" description:"接收者"`
  22 + QuestionSwitch int8 `orm:"column(question_switch);null" description:"设置问题开关"`
  23 + CreateTime time.Time `orm:"column(createTime);type(timestamp);null" description:"创建时间"`
  24 + UpdateTime time.Time `orm:"column(updateTime);type(timestamp);null" description:"更新时间"`
  25 + AllowClose int8 `orm:"column(allowClose);null" description:"允许关闭公告(0允许,1禁止)"`
  26 + CompanyId int `orm:"column(company_id);null" description:"公司Id"`
  27 + Status uint8 `orm:"column(status)" description:"状态 0-下架 1- 上架"`
  28 +}
  29 +
  30 +func (t *Bulletin) TableName() string {
  31 + return "bulletin"
  32 +}
  33 +
  34 +func init() {
  35 + orm.RegisterModel(new(Bulletin))
  36 +}
  37 +
  38 +// AddBulletin insert a new Bulletin into database and returns
  39 +// last inserted Id on success.
  40 +func AddBulletin(m *Bulletin) (id int64, err error) {
  41 + o := orm.NewOrm()
  42 + id, err = o.Insert(m)
  43 + return
  44 +}
  45 +
  46 +// GetBulletinById retrieves Bulletin by Id. Returns error if
  47 +// Id doesn't exist
  48 +func GetBulletinById(id int) (v *Bulletin, err error) {
  49 + o := orm.NewOrm()
  50 + v = &Bulletin{Id: id}
  51 + if err = o.Read(v); err == nil {
  52 + return v, nil
  53 + }
  54 + return nil, err
  55 +}
  56 +
  57 +// GetAllBulletin retrieves all Bulletin matches certain condition. Returns empty list if
  58 +// no records exist
  59 +func GetAllBulletin(query map[string]string, fields []string, sortby []string, order []string,
  60 + offset int64, limit int64) (ml []interface{}, err error) {
  61 + o := orm.NewOrm()
  62 + qs := o.QueryTable(new(Bulletin))
  63 + // query k=v
  64 + for k, v := range query {
  65 + // rewrite dot-notation to Object__Attribute
  66 + k = strings.Replace(k, ".", "__", -1)
  67 + if strings.Contains(k, "isnull") {
  68 + qs = qs.Filter(k, (v == "true" || v == "1"))
  69 + } else {
  70 + qs = qs.Filter(k, v)
  71 + }
  72 + }
  73 + // order by:
  74 + var sortFields []string
  75 + if len(sortby) != 0 {
  76 + if len(sortby) == len(order) {
  77 + // 1) for each sort field, there is an associated order
  78 + for i, v := range sortby {
  79 + orderby := ""
  80 + if order[i] == "desc" {
  81 + orderby = "-" + v
  82 + } else if order[i] == "asc" {
  83 + orderby = v
  84 + } else {
  85 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  86 + }
  87 + sortFields = append(sortFields, orderby)
  88 + }
  89 + qs = qs.OrderBy(sortFields...)
  90 + } else if len(sortby) != len(order) && len(order) == 1 {
  91 + // 2) there is exactly one order, all the sorted fields will be sorted by this order
  92 + for _, v := range sortby {
  93 + orderby := ""
  94 + if order[0] == "desc" {
  95 + orderby = "-" + v
  96 + } else if order[0] == "asc" {
  97 + orderby = v
  98 + } else {
  99 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  100 + }
  101 + sortFields = append(sortFields, orderby)
  102 + }
  103 + } else if len(sortby) != len(order) && len(order) != 1 {
  104 + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
  105 + }
  106 + } else {
  107 + if len(order) != 0 {
  108 + return nil, errors.New("Error: unused 'order' fields")
  109 + }
  110 + }
  111 +
  112 + var l []Bulletin
  113 + qs = qs.OrderBy(sortFields...)
  114 + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
  115 + if len(fields) == 0 {
  116 + for _, v := range l {
  117 + ml = append(ml, v)
  118 + }
  119 + } else {
  120 + // trim unused fields
  121 + for _, v := range l {
  122 + m := make(map[string]interface{})
  123 + val := reflect.ValueOf(v)
  124 + for _, fname := range fields {
  125 + m[fname] = val.FieldByName(fname).Interface()
  126 + }
  127 + ml = append(ml, m)
  128 + }
  129 + }
  130 + return ml, nil
  131 + }
  132 + return nil, err
  133 +}
  134 +
  135 +// UpdateBulletin updates Bulletin by Id and returns error if
  136 +// the record to be updated doesn't exist
  137 +func UpdateBulletinById(m *Bulletin) (err error) {
  138 + o := orm.NewOrm()
  139 + v := Bulletin{Id: m.Id}
  140 + // ascertain id exists in the database
  141 + if err = o.Read(&v); err == nil {
  142 + var num int64
  143 + if num, err = o.Update(m); err == nil {
  144 + fmt.Println("Number of records updated in database:", num)
  145 + }
  146 + }
  147 + return
  148 +}
  149 +
  150 +// DeleteBulletin deletes Bulletin by Id and returns error if
  151 +// the record to be deleted doesn't exist
  152 +func DeleteBulletin(id int) (err error) {
  153 + o := orm.NewOrm()
  154 + v := Bulletin{Id: id}
  155 + // ascertain id exists in the database
  156 + if err = o.Read(&v); err == nil {
  157 + var num int64
  158 + if num, err = o.Delete(&Bulletin{Id: id}); err == nil {
  159 + fmt.Println("Number of records deleted in database:", num)
  160 + }
  161 + }
  162 + return
  163 +}
  1 +package models
  2 +
  3 +import (
  4 + "errors"
  5 + "fmt"
  6 + "reflect"
  7 + "strings"
  8 + "time"
  9 +
  10 + "github.com/astaxie/beego/orm"
  11 +)
  12 +
  13 +type BulletinQuestion struct {
  14 + Id int `orm:"column(id);auto"`
  15 + BulletinId int `orm:"column(bulletin_id);null" description:"公告id"`
  16 + Type int8 `orm:"column(type);null" description:"类型:0-单选,1-多选"`
  17 + Title string `orm:"column(title);size(2000);null" description:"标题"`
  18 + Content string `orm:"column(content);size(2000);null" description:"内容"`
  19 + CreateTime time.Time `orm:"column(createTime);type(timestamp);null" description:"创建时间"`
  20 + UpdateTime time.Time `orm:"column(updateTime);type(timestamp);null" description:"更新时间"`
  21 +}
  22 +
  23 +func (t *BulletinQuestion) TableName() string {
  24 + return "bulletin_question"
  25 +}
  26 +
  27 +func init() {
  28 + orm.RegisterModel(new(BulletinQuestion))
  29 +}
  30 +
  31 +// AddBulletinQuestion insert a new BulletinQuestion into database and returns
  32 +// last inserted Id on success.
  33 +func AddBulletinQuestion(m *BulletinQuestion) (id int64, err error) {
  34 + o := orm.NewOrm()
  35 + id, err = o.Insert(m)
  36 + return
  37 +}
  38 +
  39 +// GetBulletinQuestionById retrieves BulletinQuestion by Id. Returns error if
  40 +// Id doesn't exist
  41 +func GetBulletinQuestionById(id int) (v *BulletinQuestion, err error) {
  42 + o := orm.NewOrm()
  43 + v = &BulletinQuestion{Id: id}
  44 + if err = o.Read(v); err == nil {
  45 + return v, nil
  46 + }
  47 + return nil, err
  48 +}
  49 +
  50 +// GetAllBulletinQuestion retrieves all BulletinQuestion matches certain condition. Returns empty list if
  51 +// no records exist
  52 +func GetAllBulletinQuestion(query map[string]string, fields []string, sortby []string, order []string,
  53 + offset int64, limit int64) (ml []interface{}, err error) {
  54 + o := orm.NewOrm()
  55 + qs := o.QueryTable(new(BulletinQuestion))
  56 + // query k=v
  57 + for k, v := range query {
  58 + // rewrite dot-notation to Object__Attribute
  59 + k = strings.Replace(k, ".", "__", -1)
  60 + if strings.Contains(k, "isnull") {
  61 + qs = qs.Filter(k, (v == "true" || v == "1"))
  62 + } else {
  63 + qs = qs.Filter(k, v)
  64 + }
  65 + }
  66 + // order by:
  67 + var sortFields []string
  68 + if len(sortby) != 0 {
  69 + if len(sortby) == len(order) {
  70 + // 1) for each sort field, there is an associated order
  71 + for i, v := range sortby {
  72 + orderby := ""
  73 + if order[i] == "desc" {
  74 + orderby = "-" + v
  75 + } else if order[i] == "asc" {
  76 + orderby = v
  77 + } else {
  78 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  79 + }
  80 + sortFields = append(sortFields, orderby)
  81 + }
  82 + qs = qs.OrderBy(sortFields...)
  83 + } else if len(sortby) != len(order) && len(order) == 1 {
  84 + // 2) there is exactly one order, all the sorted fields will be sorted by this order
  85 + for _, v := range sortby {
  86 + orderby := ""
  87 + if order[0] == "desc" {
  88 + orderby = "-" + v
  89 + } else if order[0] == "asc" {
  90 + orderby = v
  91 + } else {
  92 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  93 + }
  94 + sortFields = append(sortFields, orderby)
  95 + }
  96 + } else if len(sortby) != len(order) && len(order) != 1 {
  97 + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
  98 + }
  99 + } else {
  100 + if len(order) != 0 {
  101 + return nil, errors.New("Error: unused 'order' fields")
  102 + }
  103 + }
  104 +
  105 + var l []BulletinQuestion
  106 + qs = qs.OrderBy(sortFields...)
  107 + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
  108 + if len(fields) == 0 {
  109 + for _, v := range l {
  110 + ml = append(ml, v)
  111 + }
  112 + } else {
  113 + // trim unused fields
  114 + for _, v := range l {
  115 + m := make(map[string]interface{})
  116 + val := reflect.ValueOf(v)
  117 + for _, fname := range fields {
  118 + m[fname] = val.FieldByName(fname).Interface()
  119 + }
  120 + ml = append(ml, m)
  121 + }
  122 + }
  123 + return ml, nil
  124 + }
  125 + return nil, err
  126 +}
  127 +
  128 +// UpdateBulletinQuestion updates BulletinQuestion by Id and returns error if
  129 +// the record to be updated doesn't exist
  130 +func UpdateBulletinQuestionById(m *BulletinQuestion) (err error) {
  131 + o := orm.NewOrm()
  132 + v := BulletinQuestion{Id: m.Id}
  133 + // ascertain id exists in the database
  134 + if err = o.Read(&v); err == nil {
  135 + var num int64
  136 + if num, err = o.Update(m); err == nil {
  137 + fmt.Println("Number of records updated in database:", num)
  138 + }
  139 + }
  140 + return
  141 +}
  142 +
  143 +// DeleteBulletinQuestion deletes BulletinQuestion by Id and returns error if
  144 +// the record to be deleted doesn't exist
  145 +func DeleteBulletinQuestion(id int) (err error) {
  146 + o := orm.NewOrm()
  147 + v := BulletinQuestion{Id: id}
  148 + // ascertain id exists in the database
  149 + if err = o.Read(&v); err == nil {
  150 + var num int64
  151 + if num, err = o.Delete(&BulletinQuestion{Id: id}); err == nil {
  152 + fmt.Println("Number of records deleted in database:", num)
  153 + }
  154 + }
  155 + return
  156 +}
  1 +package models
  2 +
  3 +import (
  4 + "errors"
  5 + "fmt"
  6 + "reflect"
  7 + "strings"
  8 + "time"
  9 +
  10 + "github.com/astaxie/beego/orm"
  11 +)
  12 +
  13 +type BulletinQuestionAnswer struct {
  14 + Id int `orm:"column(id);auto"`
  15 + Answer string `orm:"column(answer);null" description:"答案"`
  16 + BulletinId int `orm:"column(bulletin_id);null" description:"公告id"`
  17 + BulletinQuestionId int `orm:"column(bulletin_question_id);null" description:"公告问题id"`
  18 + Uid int64 `orm:"column(uid);null" description:"用户id"`
  19 + CreateTime time.Time `orm:"column(createTime);type(timestamp);null" description:"创建时间"`
  20 + UpdateTime time.Time `orm:"column(updateTime);type(timestamp);null" description:"更新时间"`
  21 +}
  22 +
  23 +func (t *BulletinQuestionAnswer) TableName() string {
  24 + return "bulletin_question_answer"
  25 +}
  26 +
  27 +func init() {
  28 + orm.RegisterModel(new(BulletinQuestionAnswer))
  29 +}
  30 +
  31 +// AddBulletinQuestionAnswer insert a new BulletinQuestionAnswer into database and returns
  32 +// last inserted Id on success.
  33 +func AddBulletinQuestionAnswer(m *BulletinQuestionAnswer) (id int64, err error) {
  34 + o := orm.NewOrm()
  35 + id, err = o.Insert(m)
  36 + return
  37 +}
  38 +
  39 +// GetBulletinQuestionAnswerById retrieves BulletinQuestionAnswer by Id. Returns error if
  40 +// Id doesn't exist
  41 +func GetBulletinQuestionAnswerById(id int) (v *BulletinQuestionAnswer, err error) {
  42 + o := orm.NewOrm()
  43 + v = &BulletinQuestionAnswer{Id: id}
  44 + if err = o.Read(v); err == nil {
  45 + return v, nil
  46 + }
  47 + return nil, err
  48 +}
  49 +
  50 +// GetAllBulletinQuestionAnswer retrieves all BulletinQuestionAnswer matches certain condition. Returns empty list if
  51 +// no records exist
  52 +func GetAllBulletinQuestionAnswer(query map[string]string, fields []string, sortby []string, order []string,
  53 + offset int64, limit int64) (ml []interface{}, err error) {
  54 + o := orm.NewOrm()
  55 + qs := o.QueryTable(new(BulletinQuestionAnswer))
  56 + // query k=v
  57 + for k, v := range query {
  58 + // rewrite dot-notation to Object__Attribute
  59 + k = strings.Replace(k, ".", "__", -1)
  60 + if strings.Contains(k, "isnull") {
  61 + qs = qs.Filter(k, (v == "true" || v == "1"))
  62 + } else {
  63 + qs = qs.Filter(k, v)
  64 + }
  65 + }
  66 + // order by:
  67 + var sortFields []string
  68 + if len(sortby) != 0 {
  69 + if len(sortby) == len(order) {
  70 + // 1) for each sort field, there is an associated order
  71 + for i, v := range sortby {
  72 + orderby := ""
  73 + if order[i] == "desc" {
  74 + orderby = "-" + v
  75 + } else if order[i] == "asc" {
  76 + orderby = v
  77 + } else {
  78 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  79 + }
  80 + sortFields = append(sortFields, orderby)
  81 + }
  82 + qs = qs.OrderBy(sortFields...)
  83 + } else if len(sortby) != len(order) && len(order) == 1 {
  84 + // 2) there is exactly one order, all the sorted fields will be sorted by this order
  85 + for _, v := range sortby {
  86 + orderby := ""
  87 + if order[0] == "desc" {
  88 + orderby = "-" + v
  89 + } else if order[0] == "asc" {
  90 + orderby = v
  91 + } else {
  92 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  93 + }
  94 + sortFields = append(sortFields, orderby)
  95 + }
  96 + } else if len(sortby) != len(order) && len(order) != 1 {
  97 + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
  98 + }
  99 + } else {
  100 + if len(order) != 0 {
  101 + return nil, errors.New("Error: unused 'order' fields")
  102 + }
  103 + }
  104 +
  105 + var l []BulletinQuestionAnswer
  106 + qs = qs.OrderBy(sortFields...)
  107 + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
  108 + if len(fields) == 0 {
  109 + for _, v := range l {
  110 + ml = append(ml, v)
  111 + }
  112 + } else {
  113 + // trim unused fields
  114 + for _, v := range l {
  115 + m := make(map[string]interface{})
  116 + val := reflect.ValueOf(v)
  117 + for _, fname := range fields {
  118 + m[fname] = val.FieldByName(fname).Interface()
  119 + }
  120 + ml = append(ml, m)
  121 + }
  122 + }
  123 + return ml, nil
  124 + }
  125 + return nil, err
  126 +}
  127 +
  128 +// UpdateBulletinQuestionAnswer updates BulletinQuestionAnswer by Id and returns error if
  129 +// the record to be updated doesn't exist
  130 +func UpdateBulletinQuestionAnswerById(m *BulletinQuestionAnswer) (err error) {
  131 + o := orm.NewOrm()
  132 + v := BulletinQuestionAnswer{Id: m.Id}
  133 + // ascertain id exists in the database
  134 + if err = o.Read(&v); err == nil {
  135 + var num int64
  136 + if num, err = o.Update(m); err == nil {
  137 + fmt.Println("Number of records updated in database:", num)
  138 + }
  139 + }
  140 + return
  141 +}
  142 +
  143 +// DeleteBulletinQuestionAnswer deletes BulletinQuestionAnswer by Id and returns error if
  144 +// the record to be deleted doesn't exist
  145 +func DeleteBulletinQuestionAnswer(id int) (err error) {
  146 + o := orm.NewOrm()
  147 + v := BulletinQuestionAnswer{Id: id}
  148 + // ascertain id exists in the database
  149 + if err = o.Read(&v); err == nil {
  150 + var num int64
  151 + if num, err = o.Delete(&BulletinQuestionAnswer{Id: id}); err == nil {
  152 + fmt.Println("Number of records deleted in database:", num)
  153 + }
  154 + }
  155 + return
  156 +}
  1 +package models
  2 +
  3 +import (
  4 + "errors"
  5 + "fmt"
  6 + "reflect"
  7 + "strings"
  8 + "time"
  9 +
  10 + "github.com/astaxie/beego/orm"
  11 +)
  12 +
  13 +type CfgAppVersion struct {
  14 + Id int `orm:"column(id);auto"`
  15 + DeviceType int8 `orm:"column(device_type);null" description:"设备类型 (0 ios 1android)"`
  16 + VersionName string `orm:"column(version_name);size(255)" description:"版本名"`
  17 + VersionNo int `orm:"column(version_no)" description:"版本号"`
  18 + VersionState int8 `orm:"column(version_state)" description:"版本状态(0正常 1危险)"`
  19 + Title string `orm:"column(title);size(255)" description:"版本标题"`
  20 + Content string `orm:"column(content);size(500)" description:"更新的内容"`
  21 + DownloadPage string `orm:"column(download_page);size(255);null" description:"下载页"`
  22 + DownloadFile string `orm:"column(download_file);size(255)" description:"文件下载页"`
  23 + CreateTime time.Time `orm:"column(create_time);type(timestamp);null;auto_now"`
  24 + Enabled int8 `orm:"column(enabled);null" description:"是否有效"`
  25 + AdminId int `orm:"column(admin_id)" description:"操作人员"`
  26 + UpdateTime time.Time `orm:"column(update_time);type(timestamp);auto_now_add" description:"更新时间"`
  27 + Channel string `orm:"column(channel);size(255)" description:"当前渠道 0_AppStore、1_fir平台、2_华为、3_小米、4_魅族、5_oppo、6_vivo、7_360、8_百度、9_应用宝、10_其他(使用应用宝地址)"`
  28 + Type int8 `orm:"column(type);null" description:"0为手机 1为平板 终端类型"`
  29 +}
  30 +
  31 +func (t *CfgAppVersion) TableName() string {
  32 + return "cfg_app_version"
  33 +}
  34 +
  35 +func init() {
  36 + orm.RegisterModel(new(CfgAppVersion))
  37 +}
  38 +
  39 +// AddCfgAppVersion insert a new CfgAppVersion into database and returns
  40 +// last inserted Id on success.
  41 +func AddCfgAppVersion(m *CfgAppVersion) (id int64, err error) {
  42 + o := orm.NewOrm()
  43 + id, err = o.Insert(m)
  44 + return
  45 +}
  46 +
  47 +// GetCfgAppVersionById retrieves CfgAppVersion by Id. Returns error if
  48 +// Id doesn't exist
  49 +func GetCfgAppVersionById(id int) (v *CfgAppVersion, err error) {
  50 + o := orm.NewOrm()
  51 + v = &CfgAppVersion{Id: id}
  52 + if err = o.Read(v); err == nil {
  53 + return v, nil
  54 + }
  55 + return nil, err
  56 +}
  57 +
  58 +// GetAllCfgAppVersion retrieves all CfgAppVersion matches certain condition. Returns empty list if
  59 +// no records exist
  60 +func GetAllCfgAppVersion(query map[string]string, fields []string, sortby []string, order []string,
  61 + offset int64, limit int64) (ml []interface{}, err error) {
  62 + o := orm.NewOrm()
  63 + qs := o.QueryTable(new(CfgAppVersion))
  64 + // query k=v
  65 + for k, v := range query {
  66 + // rewrite dot-notation to Object__Attribute
  67 + k = strings.Replace(k, ".", "__", -1)
  68 + if strings.Contains(k, "isnull") {
  69 + qs = qs.Filter(k, (v == "true" || v == "1"))
  70 + } else {
  71 + qs = qs.Filter(k, v)
  72 + }
  73 + }
  74 + // order by:
  75 + var sortFields []string
  76 + if len(sortby) != 0 {
  77 + if len(sortby) == len(order) {
  78 + // 1) for each sort field, there is an associated order
  79 + for i, v := range sortby {
  80 + orderby := ""
  81 + if order[i] == "desc" {
  82 + orderby = "-" + v
  83 + } else if order[i] == "asc" {
  84 + orderby = v
  85 + } else {
  86 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  87 + }
  88 + sortFields = append(sortFields, orderby)
  89 + }
  90 + qs = qs.OrderBy(sortFields...)
  91 + } else if len(sortby) != len(order) && len(order) == 1 {
  92 + // 2) there is exactly one order, all the sorted fields will be sorted by this order
  93 + for _, v := range sortby {
  94 + orderby := ""
  95 + if order[0] == "desc" {
  96 + orderby = "-" + v
  97 + } else if order[0] == "asc" {
  98 + orderby = v
  99 + } else {
  100 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  101 + }
  102 + sortFields = append(sortFields, orderby)
  103 + }
  104 + } else if len(sortby) != len(order) && len(order) != 1 {
  105 + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
  106 + }
  107 + } else {
  108 + if len(order) != 0 {
  109 + return nil, errors.New("Error: unused 'order' fields")
  110 + }
  111 + }
  112 +
  113 + var l []CfgAppVersion
  114 + qs = qs.OrderBy(sortFields...)
  115 + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
  116 + if len(fields) == 0 {
  117 + for _, v := range l {
  118 + ml = append(ml, v)
  119 + }
  120 + } else {
  121 + // trim unused fields
  122 + for _, v := range l {
  123 + m := make(map[string]interface{})
  124 + val := reflect.ValueOf(v)
  125 + for _, fname := range fields {
  126 + m[fname] = val.FieldByName(fname).Interface()
  127 + }
  128 + ml = append(ml, m)
  129 + }
  130 + }
  131 + return ml, nil
  132 + }
  133 + return nil, err
  134 +}
  135 +
  136 +// UpdateCfgAppVersion updates CfgAppVersion by Id and returns error if
  137 +// the record to be updated doesn't exist
  138 +func UpdateCfgAppVersionById(m *CfgAppVersion) (err error) {
  139 + o := orm.NewOrm()
  140 + v := CfgAppVersion{Id: m.Id}
  141 + // ascertain id exists in the database
  142 + if err = o.Read(&v); err == nil {
  143 + var num int64
  144 + if num, err = o.Update(m); err == nil {
  145 + fmt.Println("Number of records updated in database:", num)
  146 + }
  147 + }
  148 + return
  149 +}
  150 +
  151 +// DeleteCfgAppVersion deletes CfgAppVersion by Id and returns error if
  152 +// the record to be deleted doesn't exist
  153 +func DeleteCfgAppVersion(id int) (err error) {
  154 + o := orm.NewOrm()
  155 + v := CfgAppVersion{Id: id}
  156 + // ascertain id exists in the database
  157 + if err = o.Read(&v); err == nil {
  158 + var num int64
  159 + if num, err = o.Delete(&CfgAppVersion{Id: id}); err == nil {
  160 + fmt.Println("Number of records deleted in database:", num)
  161 + }
  162 + }
  163 + return
  164 +}
  165 +
  166 +func GetCfgAppVersion(versionNo, channel int) (v *CfgAppVersion, err error) {
  167 + o := orm.NewOrm()
  168 + sql := `select * from cfg_app_version where version_no =? and channel =? and enabled=1`
  169 + if err = o.Raw(sql, versionNo, channel).QueryRow(&v); err == nil {
  170 + return v, nil
  171 + }
  172 + return nil, err
  173 +}
  1 +package models
  2 +
  3 +import (
  4 + "errors"
  5 + "fmt"
  6 + "reflect"
  7 + "strings"
  8 + "time"
  9 +
  10 + "github.com/astaxie/beego/orm"
  11 +)
  12 +
  13 +type CfgAttr struct {
  14 + Id int `orm:"column(id);auto" description:"主键ID"`
  15 + CompanyId int `orm:"column(company_id)" description:"公司Id"`
  16 + Name string `orm:"column(name);size(200)" description:"名称"`
  17 + Sort uint `orm:"column(sort)" description:"排序"`
  18 + CreateTime time.Time `orm:"column(createTime);type(timestamp);auto_now_add" description:"创建时间"`
  19 + Enabled int `orm:"column(enabled)"`
  20 +}
  21 +
  22 +func (t *CfgAttr) TableName() string {
  23 + return "cfg_attr"
  24 +}
  25 +
  26 +func init() {
  27 + orm.RegisterModel(new(CfgAttr))
  28 +}
  29 +
  30 +// AddCfgAttr insert a new CfgAttr into database and returns
  31 +// last inserted Id on success.
  32 +func AddCfgAttr(m *CfgAttr) (id int64, err error) {
  33 + o := orm.NewOrm()
  34 + id, err = o.Insert(m)
  35 + return
  36 +}
  37 +
  38 +// GetCfgAttrById retrieves CfgAttr by Id. Returns error if
  39 +// Id doesn't exist
  40 +func GetCfgAttrById(id int) (v *CfgAttr, err error) {
  41 + o := orm.NewOrm()
  42 + v = &CfgAttr{Id: id}
  43 + if err = o.Read(v); err == nil {
  44 + return v, nil
  45 + }
  46 + return nil, err
  47 +}
  48 +
  49 +// GetAllCfgAttr retrieves all CfgAttr matches certain condition. Returns empty list if
  50 +// no records exist
  51 +func GetAllCfgAttr(query map[string]string, fields []string, sortby []string, order []string,
  52 + offset int64, limit int64) (ml []interface{}, err error) {
  53 + o := orm.NewOrm()
  54 + qs := o.QueryTable(new(CfgAttr))
  55 + // query k=v
  56 + for k, v := range query {
  57 + // rewrite dot-notation to Object__Attribute
  58 + k = strings.Replace(k, ".", "__", -1)
  59 + if strings.Contains(k, "isnull") {
  60 + qs = qs.Filter(k, (v == "true" || v == "1"))
  61 + } else {
  62 + qs = qs.Filter(k, v)
  63 + }
  64 + }
  65 + // order by:
  66 + var sortFields []string
  67 + if len(sortby) != 0 {
  68 + if len(sortby) == len(order) {
  69 + // 1) for each sort field, there is an associated order
  70 + for i, v := range sortby {
  71 + orderby := ""
  72 + if order[i] == "desc" {
  73 + orderby = "-" + v
  74 + } else if order[i] == "asc" {
  75 + orderby = v
  76 + } else {
  77 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  78 + }
  79 + sortFields = append(sortFields, orderby)
  80 + }
  81 + qs = qs.OrderBy(sortFields...)
  82 + } else if len(sortby) != len(order) && len(order) == 1 {
  83 + // 2) there is exactly one order, all the sorted fields will be sorted by this order
  84 + for _, v := range sortby {
  85 + orderby := ""
  86 + if order[0] == "desc" {
  87 + orderby = "-" + v
  88 + } else if order[0] == "asc" {
  89 + orderby = v
  90 + } else {
  91 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  92 + }
  93 + sortFields = append(sortFields, orderby)
  94 + }
  95 + } else if len(sortby) != len(order) && len(order) != 1 {
  96 + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
  97 + }
  98 + } else {
  99 + if len(order) != 0 {
  100 + return nil, errors.New("Error: unused 'order' fields")
  101 + }
  102 + }
  103 +
  104 + var l []CfgAttr
  105 + qs = qs.OrderBy(sortFields...)
  106 + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
  107 + if len(fields) == 0 {
  108 + for _, v := range l {
  109 + ml = append(ml, v)
  110 + }
  111 + } else {
  112 + // trim unused fields
  113 + for _, v := range l {
  114 + m := make(map[string]interface{})
  115 + val := reflect.ValueOf(v)
  116 + for _, fname := range fields {
  117 + m[fname] = val.FieldByName(fname).Interface()
  118 + }
  119 + ml = append(ml, m)
  120 + }
  121 + }
  122 + return ml, nil
  123 + }
  124 + return nil, err
  125 +}
  126 +
  127 +// UpdateCfgAttr updates CfgAttr by Id and returns error if
  128 +// the record to be updated doesn't exist
  129 +func UpdateCfgAttrById(m *CfgAttr) (err error) {
  130 + o := orm.NewOrm()
  131 + v := CfgAttr{Id: m.Id}
  132 + // ascertain id exists in the database
  133 + if err = o.Read(&v); err == nil {
  134 + var num int64
  135 + if num, err = o.Update(m); err == nil {
  136 + fmt.Println("Number of records updated in database:", num)
  137 + }
  138 + }
  139 + return
  140 +}
  141 +
  142 +// DeleteCfgAttr deletes CfgAttr by Id and returns error if
  143 +// the record to be deleted doesn't exist
  144 +func DeleteCfgAttr(id int) (err error) {
  145 + o := orm.NewOrm()
  146 + v := CfgAttr{Id: id}
  147 + // ascertain id exists in the database
  148 + if err = o.Read(&v); err == nil {
  149 + var num int64
  150 + if num, err = o.Delete(&CfgAttr{Id: id}); err == nil {
  151 + fmt.Println("Number of records deleted in database:", num)
  152 + }
  153 + }
  154 + return
  155 +}
  1 +package models
  2 +
  3 +import (
  4 + "errors"
  5 + "fmt"
  6 + "reflect"
  7 + "strings"
  8 + "time"
  9 +
  10 + "github.com/astaxie/beego/orm"
  11 +)
  12 +
  13 +type CfgClient struct {
  14 + Id int `orm:"column(id);auto" description:"主键ID"`
  15 + ClientId string `orm:"column(client_id);size(32)" description:"客户端ID"`
  16 + ClientSecret string `orm:"column(client_secret);size(128);null" description:"客户端密钥"`
  17 + CreateTime time.Time `orm:"column(create_time);type(timestamp);auto_now" description:"创建时间"`
  18 + Enabled int8 `orm:"column(enabled)" description:"是否有效"`
  19 +}
  20 +
  21 +func (t *CfgClient) TableName() string {
  22 + return "cfg_client"
  23 +}
  24 +
  25 +func init() {
  26 + orm.RegisterModel(new(CfgClient))
  27 +}
  28 +
  29 +// AddCfgClient insert a new CfgClient into database and returns
  30 +// last inserted Id on success.
  31 +func AddCfgClient(m *CfgClient) (id int64, err error) {
  32 + o := orm.NewOrm()
  33 + id, err = o.Insert(m)
  34 + return
  35 +}
  36 +
  37 +// GetCfgClientById retrieves CfgClient by Id. Returns error if
  38 +// Id doesn't exist
  39 +func GetCfgClientById(id int) (v *CfgClient, err error) {
  40 + o := orm.NewOrm()
  41 + v = &CfgClient{Id: id}
  42 + if err = o.Read(v); err == nil {
  43 + return v, nil
  44 + }
  45 + return nil, err
  46 +}
  47 +
  48 +// GetAllCfgClient retrieves all CfgClient matches certain condition. Returns empty list if
  49 +// no records exist
  50 +func GetAllCfgClient(query map[string]string, fields []string, sortby []string, order []string,
  51 + offset int64, limit int64) (ml []interface{}, err error) {
  52 + o := orm.NewOrm()
  53 + qs := o.QueryTable(new(CfgClient))
  54 + // query k=v
  55 + for k, v := range query {
  56 + // rewrite dot-notation to Object__Attribute
  57 + k = strings.Replace(k, ".", "__", -1)
  58 + if strings.Contains(k, "isnull") {
  59 + qs = qs.Filter(k, (v == "true" || v == "1"))
  60 + } else {
  61 + qs = qs.Filter(k, v)
  62 + }
  63 + }
  64 + // order by:
  65 + var sortFields []string
  66 + if len(sortby) != 0 {
  67 + if len(sortby) == len(order) {
  68 + // 1) for each sort field, there is an associated order
  69 + for i, v := range sortby {
  70 + orderby := ""
  71 + if order[i] == "desc" {
  72 + orderby = "-" + v
  73 + } else if order[i] == "asc" {
  74 + orderby = v
  75 + } else {
  76 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  77 + }
  78 + sortFields = append(sortFields, orderby)
  79 + }
  80 + qs = qs.OrderBy(sortFields...)
  81 + } else if len(sortby) != len(order) && len(order) == 1 {
  82 + // 2) there is exactly one order, all the sorted fields will be sorted by this order
  83 + for _, v := range sortby {
  84 + orderby := ""
  85 + if order[0] == "desc" {
  86 + orderby = "-" + v
  87 + } else if order[0] == "asc" {
  88 + orderby = v
  89 + } else {
  90 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  91 + }
  92 + sortFields = append(sortFields, orderby)
  93 + }
  94 + } else if len(sortby) != len(order) && len(order) != 1 {
  95 + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
  96 + }
  97 + } else {
  98 + if len(order) != 0 {
  99 + return nil, errors.New("Error: unused 'order' fields")
  100 + }
  101 + }
  102 +
  103 + var l []CfgClient
  104 + qs = qs.OrderBy(sortFields...)
  105 + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
  106 + if len(fields) == 0 {
  107 + for _, v := range l {
  108 + ml = append(ml, v)
  109 + }
  110 + } else {
  111 + // trim unused fields
  112 + for _, v := range l {
  113 + m := make(map[string]interface{})
  114 + val := reflect.ValueOf(v)
  115 + for _, fname := range fields {
  116 + m[fname] = val.FieldByName(fname).Interface()
  117 + }
  118 + ml = append(ml, m)
  119 + }
  120 + }
  121 + return ml, nil
  122 + }
  123 + return nil, err
  124 +}
  125 +
  126 +// UpdateCfgClient updates CfgClient by Id and returns error if
  127 +// the record to be updated doesn't exist
  128 +func UpdateCfgClientById(m *CfgClient) (err error) {
  129 + o := orm.NewOrm()
  130 + v := CfgClient{Id: m.Id}
  131 + // ascertain id exists in the database
  132 + if err = o.Read(&v); err == nil {
  133 + var num int64
  134 + if num, err = o.Update(m); err == nil {
  135 + fmt.Println("Number of records updated in database:", num)
  136 + }
  137 + }
  138 + return
  139 +}
  140 +
  141 +// DeleteCfgClient deletes CfgClient by Id and returns error if
  142 +// the record to be deleted doesn't exist
  143 +func DeleteCfgClient(id int) (err error) {
  144 + o := orm.NewOrm()
  145 + v := CfgClient{Id: id}
  146 + // ascertain id exists in the database
  147 + if err = o.Read(&v); err == nil {
  148 + var num int64
  149 + if num, err = o.Delete(&CfgClient{Id: id}); err == nil {
  150 + fmt.Println("Number of records deleted in database:", num)
  151 + }
  152 + }
  153 + return
  154 +}
  155 +
  156 +func GetCfgClient(clintId, clientSecret string) (v *CfgClient, err error) {
  157 + o := orm.NewOrm()
  158 + sql := "select * from cfg_client where enabled=1 and client_id=? and client_secret=?"
  159 + if err = o.Raw(sql, clintId, clientSecret).QueryRow(&v); err == nil {
  160 + return v, nil
  161 + }
  162 + return nil, err
  163 +}
  1 +package models
  2 +
  3 +import (
  4 + "errors"
  5 + "fmt"
  6 + "reflect"
  7 + "strings"
  8 + "time"
  9 +
  10 + "github.com/astaxie/beego/orm"
  11 +)
  12 +
  13 +type CfgMsg struct {
  14 + Id int `orm:"column(id);pk" description:"主键ID"`
  15 + CreateTime time.Time `orm:"column(createTime);type(timestamp);auto_now_add" description:"创建时间"`
  16 + Title string `orm:"column(title);size(100)" description:"消息标题"`
  17 + Type int `orm:"column(type)" description:"1为某某某代表解决 2为某某某提出 3为某某某申请解决"`
  18 +}
  19 +
  20 +func (t *CfgMsg) TableName() string {
  21 + return "cfg_msg"
  22 +}
  23 +
  24 +func init() {
  25 + orm.RegisterModel(new(CfgMsg))
  26 +}
  27 +
  28 +// AddCfgMsg insert a new CfgMsg into database and returns
  29 +// last inserted Id on success.
  30 +func AddCfgMsg(m *CfgMsg) (id int64, err error) {
  31 + o := orm.NewOrm()
  32 + id, err = o.Insert(m)
  33 + return
  34 +}
  35 +
  36 +// GetCfgMsgById retrieves CfgMsg by Id. Returns error if
  37 +// Id doesn't exist
  38 +func GetCfgMsgById(id int) (v *CfgMsg, err error) {
  39 + o := orm.NewOrm()
  40 + v = &CfgMsg{Id: id}
  41 + if err = o.Read(v); err == nil {
  42 + return v, nil
  43 + }
  44 + return nil, err
  45 +}
  46 +
  47 +// GetAllCfgMsg retrieves all CfgMsg matches certain condition. Returns empty list if
  48 +// no records exist
  49 +func GetAllCfgMsg(query map[string]string, fields []string, sortby []string, order []string,
  50 + offset int64, limit int64) (ml []interface{}, err error) {
  51 + o := orm.NewOrm()
  52 + qs := o.QueryTable(new(CfgMsg))
  53 + // query k=v
  54 + for k, v := range query {
  55 + // rewrite dot-notation to Object__Attribute
  56 + k = strings.Replace(k, ".", "__", -1)
  57 + if strings.Contains(k, "isnull") {
  58 + qs = qs.Filter(k, (v == "true" || v == "1"))
  59 + } else {
  60 + qs = qs.Filter(k, v)
  61 + }
  62 + }
  63 + // order by:
  64 + var sortFields []string
  65 + if len(sortby) != 0 {
  66 + if len(sortby) == len(order) {
  67 + // 1) for each sort field, there is an associated order
  68 + for i, v := range sortby {
  69 + orderby := ""
  70 + if order[i] == "desc" {
  71 + orderby = "-" + v
  72 + } else if order[i] == "asc" {
  73 + orderby = v
  74 + } else {
  75 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  76 + }
  77 + sortFields = append(sortFields, orderby)
  78 + }
  79 + qs = qs.OrderBy(sortFields...)
  80 + } else if len(sortby) != len(order) && len(order) == 1 {
  81 + // 2) there is exactly one order, all the sorted fields will be sorted by this order
  82 + for _, v := range sortby {
  83 + orderby := ""
  84 + if order[0] == "desc" {
  85 + orderby = "-" + v
  86 + } else if order[0] == "asc" {
  87 + orderby = v
  88 + } else {
  89 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  90 + }
  91 + sortFields = append(sortFields, orderby)
  92 + }
  93 + } else if len(sortby) != len(order) && len(order) != 1 {
  94 + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
  95 + }
  96 + } else {
  97 + if len(order) != 0 {
  98 + return nil, errors.New("Error: unused 'order' fields")
  99 + }
  100 + }
  101 +
  102 + var l []CfgMsg
  103 + qs = qs.OrderBy(sortFields...)
  104 + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
  105 + if len(fields) == 0 {
  106 + for _, v := range l {
  107 + ml = append(ml, v)
  108 + }
  109 + } else {
  110 + // trim unused fields
  111 + for _, v := range l {
  112 + m := make(map[string]interface{})
  113 + val := reflect.ValueOf(v)
  114 + for _, fname := range fields {
  115 + m[fname] = val.FieldByName(fname).Interface()
  116 + }
  117 + ml = append(ml, m)
  118 + }
  119 + }
  120 + return ml, nil
  121 + }
  122 + return nil, err
  123 +}
  124 +
  125 +// UpdateCfgMsg updates CfgMsg by Id and returns error if
  126 +// the record to be updated doesn't exist
  127 +func UpdateCfgMsgById(m *CfgMsg) (err error) {
  128 + o := orm.NewOrm()
  129 + v := CfgMsg{Id: m.Id}
  130 + // ascertain id exists in the database
  131 + if err = o.Read(&v); err == nil {
  132 + var num int64
  133 + if num, err = o.Update(m); err == nil {
  134 + fmt.Println("Number of records updated in database:", num)
  135 + }
  136 + }
  137 + return
  138 +}
  139 +
  140 +// DeleteCfgMsg deletes CfgMsg by Id and returns error if
  141 +// the record to be deleted doesn't exist
  142 +func DeleteCfgMsg(id int) (err error) {
  143 + o := orm.NewOrm()
  144 + v := CfgMsg{Id: id}
  145 + // ascertain id exists in the database
  146 + if err = o.Read(&v); err == nil {
  147 + var num int64
  148 + if num, err = o.Delete(&CfgMsg{Id: id}); err == nil {
  149 + fmt.Println("Number of records deleted in database:", num)
  150 + }
  151 + }
  152 + return
  153 +}
  1 +package models
  2 +
  3 +import (
  4 + "errors"
  5 + "fmt"
  6 + "reflect"
  7 + "strings"
  8 + "time"
  9 +
  10 + "github.com/astaxie/beego/orm"
  11 +)
  12 +
  13 +type CfgQtype struct {
  14 + Id int `orm:"column(id);auto" description:"主键ID"`
  15 + CompanyId int `orm:"column(company_id)" description:"公司Id"`
  16 + Name string `orm:"column(name);size(200)" description:"消息标题"`
  17 + CreateTime time.Time `orm:"column(createTime);type(timestamp);auto_now_add" description:"创建时间"`
  18 + Enabled int `orm:"column(enabled)"`
  19 +}
  20 +
  21 +func (t *CfgQtype) TableName() string {
  22 + return "cfg_qtype"
  23 +}
  24 +
  25 +func init() {
  26 + orm.RegisterModel(new(CfgQtype))
  27 +}
  28 +
  29 +// AddCfgQtype insert a new CfgQtype into database and returns
  30 +// last inserted Id on success.
  31 +func AddCfgQtype(m *CfgQtype) (id int64, err error) {
  32 + o := orm.NewOrm()
  33 + id, err = o.Insert(m)
  34 + return
  35 +}
  36 +
  37 +// GetCfgQtypeById retrieves CfgQtype by Id. Returns error if
  38 +// Id doesn't exist
  39 +func GetCfgQtypeById(id int) (v *CfgQtype, err error) {
  40 + o := orm.NewOrm()
  41 + v = &CfgQtype{Id: id}
  42 + if err = o.Read(v); err == nil {
  43 + return v, nil
  44 + }
  45 + return nil, err
  46 +}
  47 +
  48 +// GetAllCfgQtype retrieves all CfgQtype matches certain condition. Returns empty list if
  49 +// no records exist
  50 +func GetAllCfgQtype(query map[string]string, fields []string, sortby []string, order []string,
  51 + offset int64, limit int64) (ml []interface{}, err error) {
  52 + o := orm.NewOrm()
  53 + qs := o.QueryTable(new(CfgQtype))
  54 + // query k=v
  55 + for k, v := range query {
  56 + // rewrite dot-notation to Object__Attribute
  57 + k = strings.Replace(k, ".", "__", -1)
  58 + if strings.Contains(k, "isnull") {
  59 + qs = qs.Filter(k, (v == "true" || v == "1"))
  60 + } else {
  61 + qs = qs.Filter(k, v)
  62 + }
  63 + }
  64 + // order by:
  65 + var sortFields []string
  66 + if len(sortby) != 0 {
  67 + if len(sortby) == len(order) {
  68 + // 1) for each sort field, there is an associated order
  69 + for i, v := range sortby {
  70 + orderby := ""
  71 + if order[i] == "desc" {
  72 + orderby = "-" + v
  73 + } else if order[i] == "asc" {
  74 + orderby = v
  75 + } else {
  76 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  77 + }
  78 + sortFields = append(sortFields, orderby)
  79 + }
  80 + qs = qs.OrderBy(sortFields...)
  81 + } else if len(sortby) != len(order) && len(order) == 1 {
  82 + // 2) there is exactly one order, all the sorted fields will be sorted by this order
  83 + for _, v := range sortby {
  84 + orderby := ""
  85 + if order[0] == "desc" {
  86 + orderby = "-" + v
  87 + } else if order[0] == "asc" {
  88 + orderby = v
  89 + } else {
  90 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  91 + }
  92 + sortFields = append(sortFields, orderby)
  93 + }
  94 + } else if len(sortby) != len(order) && len(order) != 1 {
  95 + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
  96 + }
  97 + } else {
  98 + if len(order) != 0 {
  99 + return nil, errors.New("Error: unused 'order' fields")
  100 + }
  101 + }
  102 +
  103 + var l []CfgQtype
  104 + qs = qs.OrderBy(sortFields...)
  105 + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
  106 + if len(fields) == 0 {
  107 + for _, v := range l {
  108 + ml = append(ml, v)
  109 + }
  110 + } else {
  111 + // trim unused fields
  112 + for _, v := range l {
  113 + m := make(map[string]interface{})
  114 + val := reflect.ValueOf(v)
  115 + for _, fname := range fields {
  116 + m[fname] = val.FieldByName(fname).Interface()
  117 + }
  118 + ml = append(ml, m)
  119 + }
  120 + }
  121 + return ml, nil
  122 + }
  123 + return nil, err
  124 +}
  125 +
  126 +// UpdateCfgQtype updates CfgQtype by Id and returns error if
  127 +// the record to be updated doesn't exist
  128 +func UpdateCfgQtypeById(m *CfgQtype) (err error) {
  129 + o := orm.NewOrm()
  130 + v := CfgQtype{Id: m.Id}
  131 + // ascertain id exists in the database
  132 + if err = o.Read(&v); err == nil {
  133 + var num int64
  134 + if num, err = o.Update(m); err == nil {
  135 + fmt.Println("Number of records updated in database:", num)
  136 + }
  137 + }
  138 + return
  139 +}
  140 +
  141 +// DeleteCfgQtype deletes CfgQtype by Id and returns error if
  142 +// the record to be deleted doesn't exist
  143 +func DeleteCfgQtype(id int) (err error) {
  144 + o := orm.NewOrm()
  145 + v := CfgQtype{Id: id}
  146 + // ascertain id exists in the database
  147 + if err = o.Read(&v); err == nil {
  148 + var num int64
  149 + if num, err = o.Delete(&CfgQtype{Id: id}); err == nil {
  150 + fmt.Println("Number of records deleted in database:", num)
  151 + }
  152 + }
  153 + return
  154 +}
  1 +package models
  2 +
  3 +import (
  4 + "errors"
  5 + "fmt"
  6 + "reflect"
  7 + "strings"
  8 + "time"
  9 +
  10 + "github.com/astaxie/beego/orm"
  11 +)
  12 +
  13 +type Commend struct {
  14 + Id int `orm:"column(cid);pk" description:"主键ID"`
  15 + Uid int64 `orm:"column(uid)" description:"用户ID"`
  16 + Username string `orm:"column(username);size(255)" description:"用户名"`
  17 + CreateTime time.Time `orm:"column(createTime);type(timestamp);auto_now_add" description:"创建时间"`
  18 + QuestionTitle string `orm:"column(questionTitle);size(100)" description:"标题"`
  19 + QuestionId int64 `orm:"column(questionId);null"`
  20 + Way int `orm:"column(way)" description:"0提出问题、1参与解决问题"`
  21 + Company string `orm:"column(company);size(50)" description:"是否已读 0未读,1已读"`
  22 + CompanyId int `orm:"column(company_id)" description:"公司id"`
  23 + Status int8 `orm:"column(status)" description:"状态 1可见 2不可见"`
  24 + CommendationTime time.Time `orm:"column(commendation_time);type(date)" description:"表彰时间"`
  25 +}
  26 +
  27 +func (t *Commend) TableName() string {
  28 + return "commend"
  29 +}
  30 +
  31 +func init() {
  32 + orm.RegisterModel(new(Commend))
  33 +}
  34 +
  35 +// AddCommend insert a new Commend into database and returns
  36 +// last inserted Id on success.
  37 +func AddCommend(m *Commend) (id int64, err error) {
  38 + o := orm.NewOrm()
  39 + id, err = o.Insert(m)
  40 + return
  41 +}
  42 +
  43 +// GetCommendById retrieves Commend by Id. Returns error if
  44 +// Id doesn't exist
  45 +func GetCommendById(id int) (v *Commend, err error) {
  46 + o := orm.NewOrm()
  47 + v = &Commend{Id: id}
  48 + if err = o.Read(v); err == nil {
  49 + return v, nil
  50 + }
  51 + return nil, err
  52 +}
  53 +
  54 +// GetAllCommend retrieves all Commend matches certain condition. Returns empty list if
  55 +// no records exist
  56 +func GetAllCommend(query map[string]string, fields []string, sortby []string, order []string,
  57 + offset int64, limit int64) (ml []interface{}, err error) {
  58 + o := orm.NewOrm()
  59 + qs := o.QueryTable(new(Commend))
  60 + // query k=v
  61 + for k, v := range query {
  62 + // rewrite dot-notation to Object__Attribute
  63 + k = strings.Replace(k, ".", "__", -1)
  64 + if strings.Contains(k, "isnull") {
  65 + qs = qs.Filter(k, (v == "true" || v == "1"))
  66 + } else {
  67 + qs = qs.Filter(k, v)
  68 + }
  69 + }
  70 + // order by:
  71 + var sortFields []string
  72 + if len(sortby) != 0 {
  73 + if len(sortby) == len(order) {
  74 + // 1) for each sort field, there is an associated order
  75 + for i, v := range sortby {
  76 + orderby := ""
  77 + if order[i] == "desc" {
  78 + orderby = "-" + v
  79 + } else if order[i] == "asc" {
  80 + orderby = v
  81 + } else {
  82 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  83 + }
  84 + sortFields = append(sortFields, orderby)
  85 + }
  86 + qs = qs.OrderBy(sortFields...)
  87 + } else if len(sortby) != len(order) && len(order) == 1 {
  88 + // 2) there is exactly one order, all the sorted fields will be sorted by this order
  89 + for _, v := range sortby {
  90 + orderby := ""
  91 + if order[0] == "desc" {
  92 + orderby = "-" + v
  93 + } else if order[0] == "asc" {
  94 + orderby = v
  95 + } else {
  96 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  97 + }
  98 + sortFields = append(sortFields, orderby)
  99 + }
  100 + } else if len(sortby) != len(order) && len(order) != 1 {
  101 + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
  102 + }
  103 + } else {
  104 + if len(order) != 0 {
  105 + return nil, errors.New("Error: unused 'order' fields")
  106 + }
  107 + }
  108 +
  109 + var l []Commend
  110 + qs = qs.OrderBy(sortFields...)
  111 + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
  112 + if len(fields) == 0 {
  113 + for _, v := range l {
  114 + ml = append(ml, v)
  115 + }
  116 + } else {
  117 + // trim unused fields
  118 + for _, v := range l {
  119 + m := make(map[string]interface{})
  120 + val := reflect.ValueOf(v)
  121 + for _, fname := range fields {
  122 + m[fname] = val.FieldByName(fname).Interface()
  123 + }
  124 + ml = append(ml, m)
  125 + }
  126 + }
  127 + return ml, nil
  128 + }
  129 + return nil, err
  130 +}
  131 +
  132 +// UpdateCommend updates Commend by Id and returns error if
  133 +// the record to be updated doesn't exist
  134 +func UpdateCommendById(m *Commend) (err error) {
  135 + o := orm.NewOrm()
  136 + v := Commend{Id: m.Id}
  137 + // ascertain id exists in the database
  138 + if err = o.Read(&v); err == nil {
  139 + var num int64
  140 + if num, err = o.Update(m); err == nil {
  141 + fmt.Println("Number of records updated in database:", num)
  142 + }
  143 + }
  144 + return
  145 +}
  146 +
  147 +// DeleteCommend deletes Commend by Id and returns error if
  148 +// the record to be deleted doesn't exist
  149 +func DeleteCommend(id int) (err error) {
  150 + o := orm.NewOrm()
  151 + v := Commend{Id: id}
  152 + // ascertain id exists in the database
  153 + if err = o.Read(&v); err == nil {
  154 + var num int64
  155 + if num, err = o.Delete(&Commend{Id: id}); err == nil {
  156 + fmt.Println("Number of records deleted in database:", num)
  157 + }
  158 + }
  159 + return
  160 +}
  1 +package models
  2 +
  3 +import (
  4 + "errors"
  5 + "fmt"
  6 + "reflect"
  7 + "strings"
  8 + "time"
  9 +
  10 + "github.com/astaxie/beego/orm"
  11 +)
  12 +
  13 +type Comment struct {
  14 + Id int `orm:"column(cid);pk"`
  15 + Uid int64 `orm:"column(uid);null"`
  16 + CreateTime time.Time `orm:"column(createTime);type(timestamp);auto_now_add"`
  17 + Content string `orm:"column(content)"`
  18 + PageView int `orm:"column(pageView);null" description:"浏览总数"`
  19 + CommentTotal int `orm:"column(commentTotal);null" description:"评论总数"`
  20 + SympathyTotal int `orm:"column(sympathyTotal)" description:"同感总数"`
  21 + Type int `orm:"column(type);null" description:"0问题、1评论、2方案"`
  22 + Id_RENAME int64 `orm:"column(id);null" description:"对应的ID"`
  23 +}
  24 +
  25 +func (t *Comment) TableName() string {
  26 + return "comment"
  27 +}
  28 +
  29 +func init() {
  30 + orm.RegisterModel(new(Comment))
  31 +}
  32 +
  33 +// AddComment insert a new Comment into database and returns
  34 +// last inserted Id on success.
  35 +func AddComment(m *Comment) (id int64, err error) {
  36 + o := orm.NewOrm()
  37 + id, err = o.Insert(m)
  38 + return
  39 +}
  40 +
  41 +// GetCommentById retrieves Comment by Id. Returns error if
  42 +// Id doesn't exist
  43 +func GetCommentById(id int) (v *Comment, err error) {
  44 + o := orm.NewOrm()
  45 + v = &Comment{Id: id}
  46 + if err = o.Read(v); err == nil {
  47 + return v, nil
  48 + }
  49 + return nil, err
  50 +}
  51 +
  52 +// GetAllComment retrieves all Comment matches certain condition. Returns empty list if
  53 +// no records exist
  54 +func GetAllComment(query map[string]string, fields []string, sortby []string, order []string,
  55 + offset int64, limit int64) (ml []interface{}, err error) {
  56 + o := orm.NewOrm()
  57 + qs := o.QueryTable(new(Comment))
  58 + // query k=v
  59 + for k, v := range query {
  60 + // rewrite dot-notation to Object__Attribute
  61 + k = strings.Replace(k, ".", "__", -1)
  62 + if strings.Contains(k, "isnull") {
  63 + qs = qs.Filter(k, (v == "true" || v == "1"))
  64 + } else {
  65 + qs = qs.Filter(k, v)
  66 + }
  67 + }
  68 + // order by:
  69 + var sortFields []string
  70 + if len(sortby) != 0 {
  71 + if len(sortby) == len(order) {
  72 + // 1) for each sort field, there is an associated order
  73 + for i, v := range sortby {
  74 + orderby := ""
  75 + if order[i] == "desc" {
  76 + orderby = "-" + v
  77 + } else if order[i] == "asc" {
  78 + orderby = v
  79 + } else {
  80 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  81 + }
  82 + sortFields = append(sortFields, orderby)
  83 + }
  84 + qs = qs.OrderBy(sortFields...)
  85 + } else if len(sortby) != len(order) && len(order) == 1 {
  86 + // 2) there is exactly one order, all the sorted fields will be sorted by this order
  87 + for _, v := range sortby {
  88 + orderby := ""
  89 + if order[0] == "desc" {
  90 + orderby = "-" + v
  91 + } else if order[0] == "asc" {
  92 + orderby = v
  93 + } else {
  94 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  95 + }
  96 + sortFields = append(sortFields, orderby)
  97 + }
  98 + } else if len(sortby) != len(order) && len(order) != 1 {
  99 + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
  100 + }
  101 + } else {
  102 + if len(order) != 0 {
  103 + return nil, errors.New("Error: unused 'order' fields")
  104 + }
  105 + }
  106 +
  107 + var l []Comment
  108 + qs = qs.OrderBy(sortFields...)
  109 + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
  110 + if len(fields) == 0 {
  111 + for _, v := range l {
  112 + ml = append(ml, v)
  113 + }
  114 + } else {
  115 + // trim unused fields
  116 + for _, v := range l {
  117 + m := make(map[string]interface{})
  118 + val := reflect.ValueOf(v)
  119 + for _, fname := range fields {
  120 + m[fname] = val.FieldByName(fname).Interface()
  121 + }
  122 + ml = append(ml, m)
  123 + }
  124 + }
  125 + return ml, nil
  126 + }
  127 + return nil, err
  128 +}
  129 +
  130 +// UpdateComment updates Comment by Id and returns error if
  131 +// the record to be updated doesn't exist
  132 +func UpdateCommentById(m *Comment) (err error) {
  133 + o := orm.NewOrm()
  134 + v := Comment{Id: m.Id}
  135 + // ascertain id exists in the database
  136 + if err = o.Read(&v); err == nil {
  137 + var num int64
  138 + if num, err = o.Update(m); err == nil {
  139 + fmt.Println("Number of records updated in database:", num)
  140 + }
  141 + }
  142 + return
  143 +}
  144 +
  145 +// DeleteComment deletes Comment by Id and returns error if
  146 +// the record to be deleted doesn't exist
  147 +func DeleteComment(id int) (err error) {
  148 + o := orm.NewOrm()
  149 + v := Comment{Id: id}
  150 + // ascertain id exists in the database
  151 + if err = o.Read(&v); err == nil {
  152 + var num int64
  153 + if num, err = o.Delete(&Comment{Id: id}); err == nil {
  154 + fmt.Println("Number of records deleted in database:", num)
  155 + }
  156 + }
  157 + return
  158 +}
  1 +package models
  2 +
  3 +import (
  4 + "errors"
  5 + "fmt"
  6 + "reflect"
  7 + "strings"
  8 + "time"
  9 +
  10 + "github.com/astaxie/beego/orm"
  11 +)
  12 +
  13 +type Companies struct {
  14 + Id int `orm:"column(id);auto"`
  15 + Name string `orm:"column(name);size(255)"`
  16 + Username string `orm:"column(username);size(255)"`
  17 + Phone string `orm:"column(phone);size(255)"`
  18 + Status uint8 `orm:"column(status)" description:"状态 1启用 2禁用"`
  19 + CreateTime time.Time `orm:"column(create_time);type(timestamp);auto_now"`
  20 +}
  21 +
  22 +func (t *Companies) TableName() string {
  23 + return "companies"
  24 +}
  25 +
  26 +func init() {
  27 + orm.RegisterModel(new(Companies))
  28 +}
  29 +
  30 +// AddCompanies insert a new Companies into database and returns
  31 +// last inserted Id on success.
  32 +func AddCompanies(m *Companies) (id int64, err error) {
  33 + o := orm.NewOrm()
  34 + id, err = o.Insert(m)
  35 + return
  36 +}
  37 +
  38 +// GetCompaniesById retrieves Companies by Id. Returns error if
  39 +// Id doesn't exist
  40 +func GetCompaniesById(id int) (v *Companies, err error) {
  41 + o := orm.NewOrm()
  42 + v = &Companies{Id: id}
  43 + if err = o.Read(v); err == nil {
  44 + return v, nil
  45 + }
  46 + return nil, err
  47 +}
  48 +
  49 +// GetAllCompanies retrieves all Companies matches certain condition. Returns empty list if
  50 +// no records exist
  51 +func GetAllCompanies(query map[string]string, fields []string, sortby []string, order []string,
  52 + offset int64, limit int64) (ml []interface{}, err error) {
  53 + o := orm.NewOrm()
  54 + qs := o.QueryTable(new(Companies))
  55 + // query k=v
  56 + for k, v := range query {
  57 + // rewrite dot-notation to Object__Attribute
  58 + k = strings.Replace(k, ".", "__", -1)
  59 + if strings.Contains(k, "isnull") {
  60 + qs = qs.Filter(k, (v == "true" || v == "1"))
  61 + } else {
  62 + qs = qs.Filter(k, v)
  63 + }
  64 + }
  65 + // order by:
  66 + var sortFields []string
  67 + if len(sortby) != 0 {
  68 + if len(sortby) == len(order) {
  69 + // 1) for each sort field, there is an associated order
  70 + for i, v := range sortby {
  71 + orderby := ""
  72 + if order[i] == "desc" {
  73 + orderby = "-" + v
  74 + } else if order[i] == "asc" {
  75 + orderby = v
  76 + } else {
  77 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  78 + }
  79 + sortFields = append(sortFields, orderby)
  80 + }
  81 + qs = qs.OrderBy(sortFields...)
  82 + } else if len(sortby) != len(order) && len(order) == 1 {
  83 + // 2) there is exactly one order, all the sorted fields will be sorted by this order
  84 + for _, v := range sortby {
  85 + orderby := ""
  86 + if order[0] == "desc" {
  87 + orderby = "-" + v
  88 + } else if order[0] == "asc" {
  89 + orderby = v
  90 + } else {
  91 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  92 + }
  93 + sortFields = append(sortFields, orderby)
  94 + }
  95 + } else if len(sortby) != len(order) && len(order) != 1 {
  96 + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
  97 + }
  98 + } else {
  99 + if len(order) != 0 {
  100 + return nil, errors.New("Error: unused 'order' fields")
  101 + }
  102 + }
  103 +
  104 + var l []Companies
  105 + qs = qs.OrderBy(sortFields...)
  106 + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
  107 + if len(fields) == 0 {
  108 + for _, v := range l {
  109 + ml = append(ml, v)
  110 + }
  111 + } else {
  112 + // trim unused fields
  113 + for _, v := range l {
  114 + m := make(map[string]interface{})
  115 + val := reflect.ValueOf(v)
  116 + for _, fname := range fields {
  117 + m[fname] = val.FieldByName(fname).Interface()
  118 + }
  119 + ml = append(ml, m)
  120 + }
  121 + }
  122 + return ml, nil
  123 + }
  124 + return nil, err
  125 +}
  126 +
  127 +// UpdateCompanies updates Companies by Id and returns error if
  128 +// the record to be updated doesn't exist
  129 +func UpdateCompaniesById(m *Companies) (err error) {
  130 + o := orm.NewOrm()
  131 + v := Companies{Id: m.Id}
  132 + // ascertain id exists in the database
  133 + if err = o.Read(&v); err == nil {
  134 + var num int64
  135 + if num, err = o.Update(m); err == nil {
  136 + fmt.Println("Number of records updated in database:", num)
  137 + }
  138 + }
  139 + return
  140 +}
  141 +
  142 +// DeleteCompanies deletes Companies by Id and returns error if
  143 +// the record to be deleted doesn't exist
  144 +func DeleteCompanies(id int) (err error) {
  145 + o := orm.NewOrm()
  146 + v := Companies{Id: id}
  147 + // ascertain id exists in the database
  148 + if err = o.Read(&v); err == nil {
  149 + var num int64
  150 + if num, err = o.Delete(&Companies{Id: id}); err == nil {
  151 + fmt.Println("Number of records deleted in database:", num)
  152 + }
  153 + }
  154 + return
  155 +}
  1 +package models
  2 +
  3 +import (
  4 + "errors"
  5 + "fmt"
  6 + "reflect"
  7 + "strings"
  8 + "time"
  9 +
  10 + "github.com/astaxie/beego/orm"
  11 +)
  12 +
  13 +type Departments struct {
  14 + Id int `orm:"column(id);auto"`
  15 + CompanyId int `orm:"column(company_id)"`
  16 + Name string `orm:"column(name);size(255)"`
  17 + Username string `orm:"column(username);size(255)"`
  18 + Number int `orm:"column(number)"`
  19 + CreateTime time.Time `orm:"column(create_time);type(timestamp);auto_now"`
  20 + Enabled uint8 `orm:"column(enabled)" description:"状态 1启用 0禁用"`
  21 +}
  22 +
  23 +func (t *Departments) TableName() string {
  24 + return "departments"
  25 +}
  26 +
  27 +func init() {
  28 + orm.RegisterModel(new(Departments))
  29 +}
  30 +
  31 +// AddDepartments insert a new Departments into database and returns
  32 +// last inserted Id on success.
  33 +func AddDepartments(m *Departments) (id int64, err error) {
  34 + o := orm.NewOrm()
  35 + id, err = o.Insert(m)
  36 + return
  37 +}
  38 +
  39 +// GetDepartmentsById retrieves Departments by Id. Returns error if
  40 +// Id doesn't exist
  41 +func GetDepartmentsById(id int) (v *Departments, err error) {
  42 + o := orm.NewOrm()
  43 + v = &Departments{Id: id}
  44 + if err = o.Read(v); err == nil {
  45 + return v, nil
  46 + }
  47 + return nil, err
  48 +}
  49 +
  50 +// GetAllDepartments retrieves all Departments matches certain condition. Returns empty list if
  51 +// no records exist
  52 +func GetAllDepartments(query map[string]string, fields []string, sortby []string, order []string,
  53 + offset int64, limit int64) (ml []interface{}, err error) {
  54 + o := orm.NewOrm()
  55 + qs := o.QueryTable(new(Departments))
  56 + // query k=v
  57 + for k, v := range query {
  58 + // rewrite dot-notation to Object__Attribute
  59 + k = strings.Replace(k, ".", "__", -1)
  60 + if strings.Contains(k, "isnull") {
  61 + qs = qs.Filter(k, (v == "true" || v == "1"))
  62 + } else {
  63 + qs = qs.Filter(k, v)
  64 + }
  65 + }
  66 + // order by:
  67 + var sortFields []string
  68 + if len(sortby) != 0 {
  69 + if len(sortby) == len(order) {
  70 + // 1) for each sort field, there is an associated order
  71 + for i, v := range sortby {
  72 + orderby := ""
  73 + if order[i] == "desc" {
  74 + orderby = "-" + v
  75 + } else if order[i] == "asc" {
  76 + orderby = v
  77 + } else {
  78 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  79 + }
  80 + sortFields = append(sortFields, orderby)
  81 + }
  82 + qs = qs.OrderBy(sortFields...)
  83 + } else if len(sortby) != len(order) && len(order) == 1 {
  84 + // 2) there is exactly one order, all the sorted fields will be sorted by this order
  85 + for _, v := range sortby {
  86 + orderby := ""
  87 + if order[0] == "desc" {
  88 + orderby = "-" + v
  89 + } else if order[0] == "asc" {
  90 + orderby = v
  91 + } else {
  92 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  93 + }
  94 + sortFields = append(sortFields, orderby)
  95 + }
  96 + } else if len(sortby) != len(order) && len(order) != 1 {
  97 + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
  98 + }
  99 + } else {
  100 + if len(order) != 0 {
  101 + return nil, errors.New("Error: unused 'order' fields")
  102 + }
  103 + }
  104 +
  105 + var l []Departments
  106 + qs = qs.OrderBy(sortFields...)
  107 + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
  108 + if len(fields) == 0 {
  109 + for _, v := range l {
  110 + ml = append(ml, v)
  111 + }
  112 + } else {
  113 + // trim unused fields
  114 + for _, v := range l {
  115 + m := make(map[string]interface{})
  116 + val := reflect.ValueOf(v)
  117 + for _, fname := range fields {
  118 + m[fname] = val.FieldByName(fname).Interface()
  119 + }
  120 + ml = append(ml, m)
  121 + }
  122 + }
  123 + return ml, nil
  124 + }
  125 + return nil, err
  126 +}
  127 +
  128 +// UpdateDepartments updates Departments by Id and returns error if
  129 +// the record to be updated doesn't exist
  130 +func UpdateDepartmentsById(m *Departments) (err error) {
  131 + o := orm.NewOrm()
  132 + v := Departments{Id: m.Id}
  133 + // ascertain id exists in the database
  134 + if err = o.Read(&v); err == nil {
  135 + var num int64
  136 + if num, err = o.Update(m); err == nil {
  137 + fmt.Println("Number of records updated in database:", num)
  138 + }
  139 + }
  140 + return
  141 +}
  142 +
  143 +// DeleteDepartments deletes Departments by Id and returns error if
  144 +// the record to be deleted doesn't exist
  145 +func DeleteDepartments(id int) (err error) {
  146 + o := orm.NewOrm()
  147 + v := Departments{Id: id}
  148 + // ascertain id exists in the database
  149 + if err = o.Read(&v); err == nil {
  150 + var num int64
  151 + if num, err = o.Delete(&Departments{Id: id}); err == nil {
  152 + fmt.Println("Number of records deleted in database:", num)
  153 + }
  154 + }
  155 + return
  156 +}
  1 +package models
  2 +
  3 +import (
  4 + "errors"
  5 + "fmt"
  6 + "reflect"
  7 + "strings"
  8 +
  9 + "github.com/astaxie/beego/orm"
  10 +)
  11 +
  12 +type LogUuid struct {
  13 + Id int64 `orm:"column(id);auto" description:"主键ID"`
  14 + Uuid string `orm:"column(uuid);size(128)"`
  15 +}
  16 +
  17 +func (t *LogUuid) TableName() string {
  18 + return "log_uuid"
  19 +}
  20 +
  21 +func init() {
  22 + orm.RegisterModel(new(LogUuid))
  23 +}
  24 +
  25 +// AddLogUuid insert a new LogUuid into database and returns
  26 +// last inserted Id on success.
  27 +func AddLogUuid(m *LogUuid) (id int64, err error) {
  28 + o := orm.NewOrm()
  29 + id, err = o.Insert(m)
  30 + return
  31 +}
  32 +
  33 +// GetLogUuidById retrieves LogUuid by Id. Returns error if
  34 +// Id doesn't exist
  35 +func GetLogUuidById(id int64) (v *LogUuid, err error) {
  36 + o := orm.NewOrm()
  37 + v = &LogUuid{Id: id}
  38 + if err = o.Read(v); err == nil {
  39 + return v, nil
  40 + }
  41 + return nil, err
  42 +}
  43 +
  44 +// GetAllLogUuid retrieves all LogUuid matches certain condition. Returns empty list if
  45 +// no records exist
  46 +func GetAllLogUuid(query map[string]string, fields []string, sortby []string, order []string,
  47 + offset int64, limit int64) (ml []interface{}, err error) {
  48 + o := orm.NewOrm()
  49 + qs := o.QueryTable(new(LogUuid))
  50 + // query k=v
  51 + for k, v := range query {
  52 + // rewrite dot-notation to Object__Attribute
  53 + k = strings.Replace(k, ".", "__", -1)
  54 + if strings.Contains(k, "isnull") {
  55 + qs = qs.Filter(k, (v == "true" || v == "1"))
  56 + } else {
  57 + qs = qs.Filter(k, v)
  58 + }
  59 + }
  60 + // order by:
  61 + var sortFields []string
  62 + if len(sortby) != 0 {
  63 + if len(sortby) == len(order) {
  64 + // 1) for each sort field, there is an associated order
  65 + for i, v := range sortby {
  66 + orderby := ""
  67 + if order[i] == "desc" {
  68 + orderby = "-" + v
  69 + } else if order[i] == "asc" {
  70 + orderby = v
  71 + } else {
  72 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  73 + }
  74 + sortFields = append(sortFields, orderby)
  75 + }
  76 + qs = qs.OrderBy(sortFields...)
  77 + } else if len(sortby) != len(order) && len(order) == 1 {
  78 + // 2) there is exactly one order, all the sorted fields will be sorted by this order
  79 + for _, v := range sortby {
  80 + orderby := ""
  81 + if order[0] == "desc" {
  82 + orderby = "-" + v
  83 + } else if order[0] == "asc" {
  84 + orderby = v
  85 + } else {
  86 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  87 + }
  88 + sortFields = append(sortFields, orderby)
  89 + }
  90 + } else if len(sortby) != len(order) && len(order) != 1 {
  91 + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
  92 + }
  93 + } else {
  94 + if len(order) != 0 {
  95 + return nil, errors.New("Error: unused 'order' fields")
  96 + }
  97 + }
  98 +
  99 + var l []LogUuid
  100 + qs = qs.OrderBy(sortFields...)
  101 + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
  102 + if len(fields) == 0 {
  103 + for _, v := range l {
  104 + ml = append(ml, v)
  105 + }
  106 + } else {
  107 + // trim unused fields
  108 + for _, v := range l {
  109 + m := make(map[string]interface{})
  110 + val := reflect.ValueOf(v)
  111 + for _, fname := range fields {
  112 + m[fname] = val.FieldByName(fname).Interface()
  113 + }
  114 + ml = append(ml, m)
  115 + }
  116 + }
  117 + return ml, nil
  118 + }
  119 + return nil, err
  120 +}
  121 +
  122 +// UpdateLogUuid updates LogUuid by Id and returns error if
  123 +// the record to be updated doesn't exist
  124 +func UpdateLogUuidById(m *LogUuid) (err error) {
  125 + o := orm.NewOrm()
  126 + v := LogUuid{Id: m.Id}
  127 + // ascertain id exists in the database
  128 + if err = o.Read(&v); err == nil {
  129 + var num int64
  130 + if num, err = o.Update(m); err == nil {
  131 + fmt.Println("Number of records updated in database:", num)
  132 + }
  133 + }
  134 + return
  135 +}
  136 +
  137 +// DeleteLogUuid deletes LogUuid by Id and returns error if
  138 +// the record to be deleted doesn't exist
  139 +func DeleteLogUuid(id int64) (err error) {
  140 + o := orm.NewOrm()
  141 + v := LogUuid{Id: id}
  142 + // ascertain id exists in the database
  143 + if err = o.Read(&v); err == nil {
  144 + var num int64
  145 + if num, err = o.Delete(&LogUuid{Id: id}); err == nil {
  146 + fmt.Println("Number of records deleted in database:", num)
  147 + }
  148 + }
  149 + return
  150 +}
  151 +
  152 +func GetLogUuidByUuid(uuid string) (v *LogUuid, err error) {
  153 + o := orm.NewOrm()
  154 + sql := "select * from log_uuid where uuid=?"
  155 + if err = o.Raw(sql, uuid).QueryRow(&v); err == nil {
  156 + return v, nil
  157 + }
  158 + return nil, err
  159 +}
  1 +package models
  2 +
  3 +import (
  4 + "errors"
  5 + "fmt"
  6 + "reflect"
  7 + "strings"
  8 +
  9 + "github.com/astaxie/beego/orm"
  10 +)
  11 +
  12 +type Logic struct {
  13 + Id int `orm:"column(id);auto"`
  14 + Data string `orm:"column(data);null"`
  15 + Db string `orm:"column(db);size(50);null"`
  16 + Datatype string `orm:"column(datatype);size(50);null"`
  17 + Type string `orm:"column(type);size(100);null"`
  18 + Defaultparam string `orm:"column(defaultparam);size(200);null"`
  19 +}
  20 +
  21 +func (t *Logic) TableName() string {
  22 + return "logic"
  23 +}
  24 +
  25 +func init() {
  26 + orm.RegisterModel(new(Logic))
  27 +}
  28 +
  29 +// AddLogic insert a new Logic into database and returns
  30 +// last inserted Id on success.
  31 +func AddLogic(m *Logic) (id int64, err error) {
  32 + o := orm.NewOrm()
  33 + id, err = o.Insert(m)
  34 + return
  35 +}
  36 +
  37 +// GetLogicById retrieves Logic by Id. Returns error if
  38 +// Id doesn't exist
  39 +func GetLogicById(id int) (v *Logic, err error) {
  40 + o := orm.NewOrm()
  41 + v = &Logic{Id: id}
  42 + if err = o.Read(v); err == nil {
  43 + return v, nil
  44 + }
  45 + return nil, err
  46 +}
  47 +
  48 +// GetAllLogic retrieves all Logic matches certain condition. Returns empty list if
  49 +// no records exist
  50 +func GetAllLogic(query map[string]string, fields []string, sortby []string, order []string,
  51 + offset int64, limit int64) (ml []interface{}, err error) {
  52 + o := orm.NewOrm()
  53 + qs := o.QueryTable(new(Logic))
  54 + // query k=v
  55 + for k, v := range query {
  56 + // rewrite dot-notation to Object__Attribute
  57 + k = strings.Replace(k, ".", "__", -1)
  58 + if strings.Contains(k, "isnull") {
  59 + qs = qs.Filter(k, (v == "true" || v == "1"))
  60 + } else {
  61 + qs = qs.Filter(k, v)
  62 + }
  63 + }
  64 + // order by:
  65 + var sortFields []string
  66 + if len(sortby) != 0 {
  67 + if len(sortby) == len(order) {
  68 + // 1) for each sort field, there is an associated order
  69 + for i, v := range sortby {
  70 + orderby := ""
  71 + if order[i] == "desc" {
  72 + orderby = "-" + v
  73 + } else if order[i] == "asc" {
  74 + orderby = v
  75 + } else {
  76 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  77 + }
  78 + sortFields = append(sortFields, orderby)
  79 + }
  80 + qs = qs.OrderBy(sortFields...)
  81 + } else if len(sortby) != len(order) && len(order) == 1 {
  82 + // 2) there is exactly one order, all the sorted fields will be sorted by this order
  83 + for _, v := range sortby {
  84 + orderby := ""
  85 + if order[0] == "desc" {
  86 + orderby = "-" + v
  87 + } else if order[0] == "asc" {
  88 + orderby = v
  89 + } else {
  90 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  91 + }
  92 + sortFields = append(sortFields, orderby)
  93 + }
  94 + } else if len(sortby) != len(order) && len(order) != 1 {
  95 + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
  96 + }
  97 + } else {
  98 + if len(order) != 0 {
  99 + return nil, errors.New("Error: unused 'order' fields")
  100 + }
  101 + }
  102 +
  103 + var l []Logic
  104 + qs = qs.OrderBy(sortFields...)
  105 + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
  106 + if len(fields) == 0 {
  107 + for _, v := range l {
  108 + ml = append(ml, v)
  109 + }
  110 + } else {
  111 + // trim unused fields
  112 + for _, v := range l {
  113 + m := make(map[string]interface{})
  114 + val := reflect.ValueOf(v)
  115 + for _, fname := range fields {
  116 + m[fname] = val.FieldByName(fname).Interface()
  117 + }
  118 + ml = append(ml, m)
  119 + }
  120 + }
  121 + return ml, nil
  122 + }
  123 + return nil, err
  124 +}
  125 +
  126 +// UpdateLogic updates Logic by Id and returns error if
  127 +// the record to be updated doesn't exist
  128 +func UpdateLogicById(m *Logic) (err error) {
  129 + o := orm.NewOrm()
  130 + v := Logic{Id: m.Id}
  131 + // ascertain id exists in the database
  132 + if err = o.Read(&v); err == nil {
  133 + var num int64
  134 + if num, err = o.Update(m); err == nil {
  135 + fmt.Println("Number of records updated in database:", num)
  136 + }
  137 + }
  138 + return
  139 +}
  140 +
  141 +// DeleteLogic deletes Logic by Id and returns error if
  142 +// the record to be deleted doesn't exist
  143 +func DeleteLogic(id int) (err error) {
  144 + o := orm.NewOrm()
  145 + v := Logic{Id: id}
  146 + // ascertain id exists in the database
  147 + if err = o.Read(&v); err == nil {
  148 + var num int64
  149 + if num, err = o.Delete(&Logic{Id: id}); err == nil {
  150 + fmt.Println("Number of records deleted in database:", num)
  151 + }
  152 + }
  153 + return
  154 +}
  1 +package models
  2 +
  3 +import (
  4 + "errors"
  5 + "fmt"
  6 + "reflect"
  7 + "strings"
  8 +
  9 + "github.com/astaxie/beego/orm"
  10 +)
  11 +
  12 +type Permissions struct {
  13 + Id int `orm:"column(id);auto"`
  14 + Name string `orm:"column(name);size(255)"`
  15 + Value int8 `orm:"column(value)"`
  16 +}
  17 +
  18 +func (t *Permissions) TableName() string {
  19 + return "permissions"
  20 +}
  21 +
  22 +func init() {
  23 + orm.RegisterModel(new(Permissions))
  24 +}
  25 +
  26 +// AddPermissions insert a new Permissions into database and returns
  27 +// last inserted Id on success.
  28 +func AddPermissions(m *Permissions) (id int64, err error) {
  29 + o := orm.NewOrm()
  30 + id, err = o.Insert(m)
  31 + return
  32 +}
  33 +
  34 +// GetPermissionsById retrieves Permissions by Id. Returns error if
  35 +// Id doesn't exist
  36 +func GetPermissionsById(id int) (v *Permissions, err error) {
  37 + o := orm.NewOrm()
  38 + v = &Permissions{Id: id}
  39 + if err = o.Read(v); err == nil {
  40 + return v, nil
  41 + }
  42 + return nil, err
  43 +}
  44 +
  45 +// GetAllPermissions retrieves all Permissions matches certain condition. Returns empty list if
  46 +// no records exist
  47 +func GetAllPermissions(query map[string]string, fields []string, sortby []string, order []string,
  48 + offset int64, limit int64) (ml []interface{}, err error) {
  49 + o := orm.NewOrm()
  50 + qs := o.QueryTable(new(Permissions))
  51 + // query k=v
  52 + for k, v := range query {
  53 + // rewrite dot-notation to Object__Attribute
  54 + k = strings.Replace(k, ".", "__", -1)
  55 + if strings.Contains(k, "isnull") {
  56 + qs = qs.Filter(k, (v == "true" || v == "1"))
  57 + } else {
  58 + qs = qs.Filter(k, v)
  59 + }
  60 + }
  61 + // order by:
  62 + var sortFields []string
  63 + if len(sortby) != 0 {
  64 + if len(sortby) == len(order) {
  65 + // 1) for each sort field, there is an associated order
  66 + for i, v := range sortby {
  67 + orderby := ""
  68 + if order[i] == "desc" {
  69 + orderby = "-" + v
  70 + } else if order[i] == "asc" {
  71 + orderby = v
  72 + } else {
  73 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  74 + }
  75 + sortFields = append(sortFields, orderby)
  76 + }
  77 + qs = qs.OrderBy(sortFields...)
  78 + } else if len(sortby) != len(order) && len(order) == 1 {
  79 + // 2) there is exactly one order, all the sorted fields will be sorted by this order
  80 + for _, v := range sortby {
  81 + orderby := ""
  82 + if order[0] == "desc" {
  83 + orderby = "-" + v
  84 + } else if order[0] == "asc" {
  85 + orderby = v
  86 + } else {
  87 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  88 + }
  89 + sortFields = append(sortFields, orderby)
  90 + }
  91 + } else if len(sortby) != len(order) && len(order) != 1 {
  92 + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
  93 + }
  94 + } else {
  95 + if len(order) != 0 {
  96 + return nil, errors.New("Error: unused 'order' fields")
  97 + }
  98 + }
  99 +
  100 + var l []Permissions
  101 + qs = qs.OrderBy(sortFields...)
  102 + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
  103 + if len(fields) == 0 {
  104 + for _, v := range l {
  105 + ml = append(ml, v)
  106 + }
  107 + } else {
  108 + // trim unused fields
  109 + for _, v := range l {
  110 + m := make(map[string]interface{})
  111 + val := reflect.ValueOf(v)
  112 + for _, fname := range fields {
  113 + m[fname] = val.FieldByName(fname).Interface()
  114 + }
  115 + ml = append(ml, m)
  116 + }
  117 + }
  118 + return ml, nil
  119 + }
  120 + return nil, err
  121 +}
  122 +
  123 +// UpdatePermissions updates Permissions by Id and returns error if
  124 +// the record to be updated doesn't exist
  125 +func UpdatePermissionsById(m *Permissions) (err error) {
  126 + o := orm.NewOrm()
  127 + v := Permissions{Id: m.Id}
  128 + // ascertain id exists in the database
  129 + if err = o.Read(&v); err == nil {
  130 + var num int64
  131 + if num, err = o.Update(m); err == nil {
  132 + fmt.Println("Number of records updated in database:", num)
  133 + }
  134 + }
  135 + return
  136 +}
  137 +
  138 +// DeletePermissions deletes Permissions by Id and returns error if
  139 +// the record to be deleted doesn't exist
  140 +func DeletePermissions(id int) (err error) {
  141 + o := orm.NewOrm()
  142 + v := Permissions{Id: id}
  143 + // ascertain id exists in the database
  144 + if err = o.Read(&v); err == nil {
  145 + var num int64
  146 + if num, err = o.Delete(&Permissions{Id: id}); err == nil {
  147 + fmt.Println("Number of records deleted in database:", num)
  148 + }
  149 + }
  150 + return
  151 +}
  1 +package models
  2 +
  3 +import (
  4 + "errors"
  5 + "fmt"
  6 + "reflect"
  7 + "strings"
  8 +
  9 + "github.com/astaxie/beego/orm"
  10 +)
  11 +
  12 +type PicsLog struct {
  13 + Id int `orm:"column(id);auto" description:"主键ID"`
  14 + Url string `orm:"column(url);size(128)"`
  15 + Thumbnail string `orm:"column(thumbnail);size(128)" description:"缩略图"`
  16 + Width int `orm:"column(width)" description:"宽度"`
  17 + Length int `orm:"column(length)" description:"长度"`
  18 +}
  19 +
  20 +func (t *PicsLog) TableName() string {
  21 + return "pics_log"
  22 +}
  23 +
  24 +func init() {
  25 + orm.RegisterModel(new(PicsLog))
  26 +}
  27 +
  28 +// AddPicsLog insert a new PicsLog into database and returns
  29 +// last inserted Id on success.
  30 +func AddPicsLog(m *PicsLog) (id int64, err error) {
  31 + o := orm.NewOrm()
  32 + id, err = o.Insert(m)
  33 + return
  34 +}
  35 +
  36 +// GetPicsLogById retrieves PicsLog by Id. Returns error if
  37 +// Id doesn't exist
  38 +func GetPicsLogById(id int) (v *PicsLog, err error) {
  39 + o := orm.NewOrm()
  40 + v = &PicsLog{Id: id}
  41 + if err = o.Read(v); err == nil {
  42 + return v, nil
  43 + }
  44 + return nil, err
  45 +}
  46 +
  47 +// GetAllPicsLog retrieves all PicsLog matches certain condition. Returns empty list if
  48 +// no records exist
  49 +func GetAllPicsLog(query map[string]string, fields []string, sortby []string, order []string,
  50 + offset int64, limit int64) (ml []interface{}, err error) {
  51 + o := orm.NewOrm()
  52 + qs := o.QueryTable(new(PicsLog))
  53 + // query k=v
  54 + for k, v := range query {
  55 + // rewrite dot-notation to Object__Attribute
  56 + k = strings.Replace(k, ".", "__", -1)
  57 + if strings.Contains(k, "isnull") {
  58 + qs = qs.Filter(k, (v == "true" || v == "1"))
  59 + } else {
  60 + qs = qs.Filter(k, v)
  61 + }
  62 + }
  63 + // order by:
  64 + var sortFields []string
  65 + if len(sortby) != 0 {
  66 + if len(sortby) == len(order) {
  67 + // 1) for each sort field, there is an associated order
  68 + for i, v := range sortby {
  69 + orderby := ""
  70 + if order[i] == "desc" {
  71 + orderby = "-" + v
  72 + } else if order[i] == "asc" {
  73 + orderby = v
  74 + } else {
  75 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  76 + }
  77 + sortFields = append(sortFields, orderby)
  78 + }
  79 + qs = qs.OrderBy(sortFields...)
  80 + } else if len(sortby) != len(order) && len(order) == 1 {
  81 + // 2) there is exactly one order, all the sorted fields will be sorted by this order
  82 + for _, v := range sortby {
  83 + orderby := ""
  84 + if order[0] == "desc" {
  85 + orderby = "-" + v
  86 + } else if order[0] == "asc" {
  87 + orderby = v
  88 + } else {
  89 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  90 + }
  91 + sortFields = append(sortFields, orderby)
  92 + }
  93 + } else if len(sortby) != len(order) && len(order) != 1 {
  94 + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
  95 + }
  96 + } else {
  97 + if len(order) != 0 {
  98 + return nil, errors.New("Error: unused 'order' fields")
  99 + }
  100 + }
  101 +
  102 + var l []PicsLog
  103 + qs = qs.OrderBy(sortFields...)
  104 + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
  105 + if len(fields) == 0 {
  106 + for _, v := range l {
  107 + ml = append(ml, v)
  108 + }
  109 + } else {
  110 + // trim unused fields
  111 + for _, v := range l {
  112 + m := make(map[string]interface{})
  113 + val := reflect.ValueOf(v)
  114 + for _, fname := range fields {
  115 + m[fname] = val.FieldByName(fname).Interface()
  116 + }
  117 + ml = append(ml, m)
  118 + }
  119 + }
  120 + return ml, nil
  121 + }
  122 + return nil, err
  123 +}
  124 +
  125 +// UpdatePicsLog updates PicsLog by Id and returns error if
  126 +// the record to be updated doesn't exist
  127 +func UpdatePicsLogById(m *PicsLog) (err error) {
  128 + o := orm.NewOrm()
  129 + v := PicsLog{Id: m.Id}
  130 + // ascertain id exists in the database
  131 + if err = o.Read(&v); err == nil {
  132 + var num int64
  133 + if num, err = o.Update(m); err == nil {
  134 + fmt.Println("Number of records updated in database:", num)
  135 + }
  136 + }
  137 + return
  138 +}
  139 +
  140 +// DeletePicsLog deletes PicsLog by Id and returns error if
  141 +// the record to be deleted doesn't exist
  142 +func DeletePicsLog(id int) (err error) {
  143 + o := orm.NewOrm()
  144 + v := PicsLog{Id: id}
  145 + // ascertain id exists in the database
  146 + if err = o.Read(&v); err == nil {
  147 + var num int64
  148 + if num, err = o.Delete(&PicsLog{Id: id}); err == nil {
  149 + fmt.Println("Number of records deleted in database:", num)
  150 + }
  151 + }
  152 + return
  153 +}
  1 +package models
  2 +
  3 +import (
  4 + "errors"
  5 + "fmt"
  6 + "reflect"
  7 + "strings"
  8 + "time"
  9 +
  10 + "github.com/astaxie/beego/orm"
  11 +)
  12 +
  13 +type Positions struct {
  14 + Id int `orm:"column(id);auto"`
  15 + CompanyId int `orm:"column(company_id)"`
  16 + Name string `orm:"column(name);size(255)"`
  17 + Pid string `orm:"column(pid);size(255)"`
  18 + Path string `orm:"column(path);size(1000)"`
  19 + Level int8 `orm:"column(level)" description:"级别"`
  20 + CreateTime time.Time `orm:"column(create_time);type(timestamp);auto_now"`
  21 + Enabled int8 `orm:"column(enabled)"`
  22 +}
  23 +
  24 +func (t *Positions) TableName() string {
  25 + return "positions"
  26 +}
  27 +
  28 +func init() {
  29 + orm.RegisterModel(new(Positions))
  30 +}
  31 +
  32 +// AddPositions insert a new Positions into database and returns
  33 +// last inserted Id on success.
  34 +func AddPositions(m *Positions) (id int64, err error) {
  35 + o := orm.NewOrm()
  36 + id, err = o.Insert(m)
  37 + return
  38 +}
  39 +
  40 +// GetPositionsById retrieves Positions by Id. Returns error if
  41 +// Id doesn't exist
  42 +func GetPositionsById(id int) (v *Positions, err error) {
  43 + o := orm.NewOrm()
  44 + v = &Positions{Id: id}
  45 + if err = o.Read(v); err == nil {
  46 + return v, nil
  47 + }
  48 + return nil, err
  49 +}
  50 +
  51 +// GetAllPositions retrieves all Positions matches certain condition. Returns empty list if
  52 +// no records exist
  53 +func GetAllPositions(query map[string]string, fields []string, sortby []string, order []string,
  54 + offset int64, limit int64) (ml []interface{}, err error) {
  55 + o := orm.NewOrm()
  56 + qs := o.QueryTable(new(Positions))
  57 + // query k=v
  58 + for k, v := range query {
  59 + // rewrite dot-notation to Object__Attribute
  60 + k = strings.Replace(k, ".", "__", -1)
  61 + if strings.Contains(k, "isnull") {
  62 + qs = qs.Filter(k, (v == "true" || v == "1"))
  63 + } else {
  64 + qs = qs.Filter(k, v)
  65 + }
  66 + }
  67 + // order by:
  68 + var sortFields []string
  69 + if len(sortby) != 0 {
  70 + if len(sortby) == len(order) {
  71 + // 1) for each sort field, there is an associated order
  72 + for i, v := range sortby {
  73 + orderby := ""
  74 + if order[i] == "desc" {
  75 + orderby = "-" + v
  76 + } else if order[i] == "asc" {
  77 + orderby = v
  78 + } else {
  79 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  80 + }
  81 + sortFields = append(sortFields, orderby)
  82 + }
  83 + qs = qs.OrderBy(sortFields...)
  84 + } else if len(sortby) != len(order) && len(order) == 1 {
  85 + // 2) there is exactly one order, all the sorted fields will be sorted by this order
  86 + for _, v := range sortby {
  87 + orderby := ""
  88 + if order[0] == "desc" {
  89 + orderby = "-" + v
  90 + } else if order[0] == "asc" {
  91 + orderby = v
  92 + } else {
  93 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  94 + }
  95 + sortFields = append(sortFields, orderby)
  96 + }
  97 + } else if len(sortby) != len(order) && len(order) != 1 {
  98 + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
  99 + }
  100 + } else {
  101 + if len(order) != 0 {
  102 + return nil, errors.New("Error: unused 'order' fields")
  103 + }
  104 + }
  105 +
  106 + var l []Positions
  107 + qs = qs.OrderBy(sortFields...)
  108 + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
  109 + if len(fields) == 0 {
  110 + for _, v := range l {
  111 + ml = append(ml, v)
  112 + }
  113 + } else {
  114 + // trim unused fields
  115 + for _, v := range l {
  116 + m := make(map[string]interface{})
  117 + val := reflect.ValueOf(v)
  118 + for _, fname := range fields {
  119 + m[fname] = val.FieldByName(fname).Interface()
  120 + }
  121 + ml = append(ml, m)
  122 + }
  123 + }
  124 + return ml, nil
  125 + }
  126 + return nil, err
  127 +}
  128 +
  129 +// UpdatePositions updates Positions by Id and returns error if
  130 +// the record to be updated doesn't exist
  131 +func UpdatePositionsById(m *Positions) (err error) {
  132 + o := orm.NewOrm()
  133 + v := Positions{Id: m.Id}
  134 + // ascertain id exists in the database
  135 + if err = o.Read(&v); err == nil {
  136 + var num int64
  137 + if num, err = o.Update(m); err == nil {
  138 + fmt.Println("Number of records updated in database:", num)
  139 + }
  140 + }
  141 + return
  142 +}
  143 +
  144 +// DeletePositions deletes Positions by Id and returns error if
  145 +// the record to be deleted doesn't exist
  146 +func DeletePositions(id int) (err error) {
  147 + o := orm.NewOrm()
  148 + v := Positions{Id: id}
  149 + // ascertain id exists in the database
  150 + if err = o.Read(&v); err == nil {
  151 + var num int64
  152 + if num, err = o.Delete(&Positions{Id: id}); err == nil {
  153 + fmt.Println("Number of records deleted in database:", num)
  154 + }
  155 + }
  156 + return
  157 +}
  1 +package models
  2 +
  3 +import (
  4 + "errors"
  5 + "fmt"
  6 + "reflect"
  7 + "strings"
  8 + "time"
  9 +
  10 + "github.com/astaxie/beego/orm"
  11 +)
  12 +
  13 +type Question struct {
  14 + Id int `orm:"column(id);pk"`
  15 + Title string `orm:"column(title);size(30)" description:"标题"`
  16 + Content string `orm:"column(content)" description:"内容"`
  17 + Uid int64 `orm:"column(uid)" description:"用户ID"`
  18 + CreateTime time.Time `orm:"column(createTime);type(timestamp);auto_now_add"`
  19 + Way int `orm:"column(way)" description:"提问方式(0语音,1图文)"`
  20 + PageView int `orm:"column(pageView)" description:"浏览总数"`
  21 + CommentTotal int `orm:"column(commentTotal)" description:"评论总数"`
  22 + SympathyTotal int `orm:"column(sympathyTotal)" description:"同感总数"`
  23 + Review int `orm:"column(review)" description:"0 待审核 1已审核"`
  24 + Status int `orm:"column(status);null" description:"状态 0 未解决 1已解决"`
  25 + UpdateTime time.Time `orm:"column(updateTime);type(timestamp);null"`
  26 + ScoreAnalyze int `orm:"column(scoreAnalyze);null" description:"分析评分"`
  27 + ScoreAsk int `orm:"column(scoreAsk);null" description:"提问评分"`
  28 + ScoreScheme int `orm:"column(scoreScheme);null" description:"方案评分"`
  29 + Published int `orm:"column(published);null" description:"公开状态 0未公开、1本部门公开、2本公司公开"`
  30 + Level int `orm:"column(level)" description:"最后评分或审核人的级别"`
  31 + CheckUid int64 `orm:"column(checkUid);null" description:"审核人ID"`
  32 + Enabled int `orm:"column(enabled);null" description:"1有效 0删除"`
  33 + Tlevel int `orm:"column(tlevel)" description:"公开操作权限"`
  34 + PfUid int64 `orm:"column(pfUid)"`
  35 + QType int `orm:"column(qType)"`
  36 + SoluteTime time.Time `orm:"column(soluteTime);type(timestamp);auto_now_add"`
  37 + ResolverTime time.Time `orm:"column(resolverTime);type(timestamp);auto_now_add"`
  38 + Resolver int64 `orm:"column(resolver)"`
  39 + RelevantDepartmentId int `orm:"column(relevantDepartmentId)" description:"相关部门id"`
  40 + ReceiveStatus int8 `orm:"column(receiveStatus)" description:"领取状态 0未领取 1已领取"`
  41 +}
  42 +
  43 +func (t *Question) TableName() string {
  44 + return "question"
  45 +}
  46 +
  47 +func init() {
  48 + orm.RegisterModel(new(Question))
  49 +}
  50 +
  51 +// AddQuestion insert a new Question into database and returns
  52 +// last inserted Id on success.
  53 +func AddQuestion(m *Question) (id int64, err error) {
  54 + o := orm.NewOrm()
  55 + id, err = o.Insert(m)
  56 + return
  57 +}
  58 +
  59 +// GetQuestionById retrieves Question by Id. Returns error if
  60 +// Id doesn't exist
  61 +func GetQuestionById(id int) (v *Question, err error) {
  62 + o := orm.NewOrm()
  63 + v = &Question{Id: id}
  64 + if err = o.Read(v); err == nil {
  65 + return v, nil
  66 + }
  67 + return nil, err
  68 +}
  69 +
  70 +// GetAllQuestion retrieves all Question matches certain condition. Returns empty list if
  71 +// no records exist
  72 +func GetAllQuestion(query map[string]string, fields []string, sortby []string, order []string,
  73 + offset int64, limit int64) (ml []interface{}, err error) {
  74 + o := orm.NewOrm()
  75 + qs := o.QueryTable(new(Question))
  76 + // query k=v
  77 + for k, v := range query {
  78 + // rewrite dot-notation to Object__Attribute
  79 + k = strings.Replace(k, ".", "__", -1)
  80 + if strings.Contains(k, "isnull") {
  81 + qs = qs.Filter(k, (v == "true" || v == "1"))
  82 + } else {
  83 + qs = qs.Filter(k, v)
  84 + }
  85 + }
  86 + // order by:
  87 + var sortFields []string
  88 + if len(sortby) != 0 {
  89 + if len(sortby) == len(order) {
  90 + // 1) for each sort field, there is an associated order
  91 + for i, v := range sortby {
  92 + orderby := ""
  93 + if order[i] == "desc" {
  94 + orderby = "-" + v
  95 + } else if order[i] == "asc" {
  96 + orderby = v
  97 + } else {
  98 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  99 + }
  100 + sortFields = append(sortFields, orderby)
  101 + }
  102 + qs = qs.OrderBy(sortFields...)
  103 + } else if len(sortby) != len(order) && len(order) == 1 {
  104 + // 2) there is exactly one order, all the sorted fields will be sorted by this order
  105 + for _, v := range sortby {
  106 + orderby := ""
  107 + if order[0] == "desc" {
  108 + orderby = "-" + v
  109 + } else if order[0] == "asc" {
  110 + orderby = v
  111 + } else {
  112 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  113 + }
  114 + sortFields = append(sortFields, orderby)
  115 + }
  116 + } else if len(sortby) != len(order) && len(order) != 1 {
  117 + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
  118 + }
  119 + } else {
  120 + if len(order) != 0 {
  121 + return nil, errors.New("Error: unused 'order' fields")
  122 + }
  123 + }
  124 +
  125 + var l []Question
  126 + qs = qs.OrderBy(sortFields...)
  127 + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
  128 + if len(fields) == 0 {
  129 + for _, v := range l {
  130 + ml = append(ml, v)
  131 + }
  132 + } else {
  133 + // trim unused fields
  134 + for _, v := range l {
  135 + m := make(map[string]interface{})
  136 + val := reflect.ValueOf(v)
  137 + for _, fname := range fields {
  138 + m[fname] = val.FieldByName(fname).Interface()
  139 + }
  140 + ml = append(ml, m)
  141 + }
  142 + }
  143 + return ml, nil
  144 + }
  145 + return nil, err
  146 +}
  147 +
  148 +// UpdateQuestion updates Question by Id and returns error if
  149 +// the record to be updated doesn't exist
  150 +func UpdateQuestionById(m *Question) (err error) {
  151 + o := orm.NewOrm()
  152 + v := Question{Id: m.Id}
  153 + // ascertain id exists in the database
  154 + if err = o.Read(&v); err == nil {
  155 + var num int64
  156 + if num, err = o.Update(m); err == nil {
  157 + fmt.Println("Number of records updated in database:", num)
  158 + }
  159 + }
  160 + return
  161 +}
  162 +
  163 +// DeleteQuestion deletes Question by Id and returns error if
  164 +// the record to be deleted doesn't exist
  165 +func DeleteQuestion(id int) (err error) {
  166 + o := orm.NewOrm()
  167 + v := Question{Id: id}
  168 + // ascertain id exists in the database
  169 + if err = o.Read(&v); err == nil {
  170 + var num int64
  171 + if num, err = o.Delete(&Question{Id: id}); err == nil {
  172 + fmt.Println("Number of records deleted in database:", num)
  173 + }
  174 + }
  175 + return
  176 +}
  1 +package models
  2 +
  3 +import (
  4 + "errors"
  5 + "fmt"
  6 + "reflect"
  7 + "strings"
  8 + "time"
  9 +
  10 + "github.com/astaxie/beego/orm"
  11 +)
  12 +
  13 +type QuestionDepartment struct {
  14 + Id int `orm:"column(id);pk"`
  15 + Qid int64 `orm:"column(qid)" description:"所属的问题ID"`
  16 + DepartmentId int `orm:"column(department_id)" description:"语音路径"`
  17 + CreateTime time.Time `orm:"column(createTime);type(timestamp);auto_now_add"`
  18 +}
  19 +
  20 +func (t *QuestionDepartment) TableName() string {
  21 + return "question_department"
  22 +}
  23 +
  24 +func init() {
  25 + orm.RegisterModel(new(QuestionDepartment))
  26 +}
  27 +
  28 +// AddQuestionDepartment insert a new QuestionDepartment into database and returns
  29 +// last inserted Id on success.
  30 +func AddQuestionDepartment(m *QuestionDepartment) (id int64, err error) {
  31 + o := orm.NewOrm()
  32 + id, err = o.Insert(m)
  33 + return
  34 +}
  35 +
  36 +// GetQuestionDepartmentById retrieves QuestionDepartment by Id. Returns error if
  37 +// Id doesn't exist
  38 +func GetQuestionDepartmentById(id int) (v *QuestionDepartment, err error) {
  39 + o := orm.NewOrm()
  40 + v = &QuestionDepartment{Id: id}
  41 + if err = o.Read(v); err == nil {
  42 + return v, nil
  43 + }
  44 + return nil, err
  45 +}
  46 +
  47 +// GetAllQuestionDepartment retrieves all QuestionDepartment matches certain condition. Returns empty list if
  48 +// no records exist
  49 +func GetAllQuestionDepartment(query map[string]string, fields []string, sortby []string, order []string,
  50 + offset int64, limit int64) (ml []interface{}, err error) {
  51 + o := orm.NewOrm()
  52 + qs := o.QueryTable(new(QuestionDepartment))
  53 + // query k=v
  54 + for k, v := range query {
  55 + // rewrite dot-notation to Object__Attribute
  56 + k = strings.Replace(k, ".", "__", -1)
  57 + if strings.Contains(k, "isnull") {
  58 + qs = qs.Filter(k, (v == "true" || v == "1"))
  59 + } else {
  60 + qs = qs.Filter(k, v)
  61 + }
  62 + }
  63 + // order by:
  64 + var sortFields []string
  65 + if len(sortby) != 0 {
  66 + if len(sortby) == len(order) {
  67 + // 1) for each sort field, there is an associated order
  68 + for i, v := range sortby {
  69 + orderby := ""
  70 + if order[i] == "desc" {
  71 + orderby = "-" + v
  72 + } else if order[i] == "asc" {
  73 + orderby = v
  74 + } else {
  75 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  76 + }
  77 + sortFields = append(sortFields, orderby)
  78 + }
  79 + qs = qs.OrderBy(sortFields...)
  80 + } else if len(sortby) != len(order) && len(order) == 1 {
  81 + // 2) there is exactly one order, all the sorted fields will be sorted by this order
  82 + for _, v := range sortby {
  83 + orderby := ""
  84 + if order[0] == "desc" {
  85 + orderby = "-" + v
  86 + } else if order[0] == "asc" {
  87 + orderby = v
  88 + } else {
  89 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  90 + }
  91 + sortFields = append(sortFields, orderby)
  92 + }
  93 + } else if len(sortby) != len(order) && len(order) != 1 {
  94 + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
  95 + }
  96 + } else {
  97 + if len(order) != 0 {
  98 + return nil, errors.New("Error: unused 'order' fields")
  99 + }
  100 + }
  101 +
  102 + var l []QuestionDepartment
  103 + qs = qs.OrderBy(sortFields...)
  104 + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
  105 + if len(fields) == 0 {
  106 + for _, v := range l {
  107 + ml = append(ml, v)
  108 + }
  109 + } else {
  110 + // trim unused fields
  111 + for _, v := range l {
  112 + m := make(map[string]interface{})
  113 + val := reflect.ValueOf(v)
  114 + for _, fname := range fields {
  115 + m[fname] = val.FieldByName(fname).Interface()
  116 + }
  117 + ml = append(ml, m)
  118 + }
  119 + }
  120 + return ml, nil
  121 + }
  122 + return nil, err
  123 +}
  124 +
  125 +// UpdateQuestionDepartment updates QuestionDepartment by Id and returns error if
  126 +// the record to be updated doesn't exist
  127 +func UpdateQuestionDepartmentById(m *QuestionDepartment) (err error) {
  128 + o := orm.NewOrm()
  129 + v := QuestionDepartment{Id: m.Id}
  130 + // ascertain id exists in the database
  131 + if err = o.Read(&v); err == nil {
  132 + var num int64
  133 + if num, err = o.Update(m); err == nil {
  134 + fmt.Println("Number of records updated in database:", num)
  135 + }
  136 + }
  137 + return
  138 +}
  139 +
  140 +// DeleteQuestionDepartment deletes QuestionDepartment by Id and returns error if
  141 +// the record to be deleted doesn't exist
  142 +func DeleteQuestionDepartment(id int) (err error) {
  143 + o := orm.NewOrm()
  144 + v := QuestionDepartment{Id: id}
  145 + // ascertain id exists in the database
  146 + if err = o.Read(&v); err == nil {
  147 + var num int64
  148 + if num, err = o.Delete(&QuestionDepartment{Id: id}); err == nil {
  149 + fmt.Println("Number of records deleted in database:", num)
  150 + }
  151 + }
  152 + return
  153 +}
  1 +package models
  2 +
  3 +import (
  4 + "errors"
  5 + "fmt"
  6 + "reflect"
  7 + "strings"
  8 + "time"
  9 +
  10 + "github.com/astaxie/beego/orm"
  11 +)
  12 +
  13 +type QuestionDepartmentLog struct {
  14 + Id int `orm:"column(id);pk"`
  15 + Qid int64 `orm:"column(qid)" description:"所属的问题ID"`
  16 + DepartmentId int `orm:"column(department_id)" description:"相关部门id"`
  17 + OperatorId int64 `orm:"column(operator_id)" description:"操作者id"`
  18 + CreateTime time.Time `orm:"column(createTime);type(timestamp);auto_now_add"`
  19 +}
  20 +
  21 +func (t *QuestionDepartmentLog) TableName() string {
  22 + return "question_department_log"
  23 +}
  24 +
  25 +func init() {
  26 + orm.RegisterModel(new(QuestionDepartmentLog))
  27 +}
  28 +
  29 +// AddQuestionDepartmentLog insert a new QuestionDepartmentLog into database and returns
  30 +// last inserted Id on success.
  31 +func AddQuestionDepartmentLog(m *QuestionDepartmentLog) (id int64, err error) {
  32 + o := orm.NewOrm()
  33 + id, err = o.Insert(m)
  34 + return
  35 +}
  36 +
  37 +// GetQuestionDepartmentLogById retrieves QuestionDepartmentLog by Id. Returns error if
  38 +// Id doesn't exist
  39 +func GetQuestionDepartmentLogById(id int) (v *QuestionDepartmentLog, err error) {
  40 + o := orm.NewOrm()
  41 + v = &QuestionDepartmentLog{Id: id}
  42 + if err = o.Read(v); err == nil {
  43 + return v, nil
  44 + }
  45 + return nil, err
  46 +}
  47 +
  48 +// GetAllQuestionDepartmentLog retrieves all QuestionDepartmentLog matches certain condition. Returns empty list if
  49 +// no records exist
  50 +func GetAllQuestionDepartmentLog(query map[string]string, fields []string, sortby []string, order []string,
  51 + offset int64, limit int64) (ml []interface{}, err error) {
  52 + o := orm.NewOrm()
  53 + qs := o.QueryTable(new(QuestionDepartmentLog))
  54 + // query k=v
  55 + for k, v := range query {
  56 + // rewrite dot-notation to Object__Attribute
  57 + k = strings.Replace(k, ".", "__", -1)
  58 + if strings.Contains(k, "isnull") {
  59 + qs = qs.Filter(k, (v == "true" || v == "1"))
  60 + } else {
  61 + qs = qs.Filter(k, v)
  62 + }
  63 + }
  64 + // order by:
  65 + var sortFields []string
  66 + if len(sortby) != 0 {
  67 + if len(sortby) == len(order) {
  68 + // 1) for each sort field, there is an associated order
  69 + for i, v := range sortby {
  70 + orderby := ""
  71 + if order[i] == "desc" {
  72 + orderby = "-" + v
  73 + } else if order[i] == "asc" {
  74 + orderby = v
  75 + } else {
  76 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  77 + }
  78 + sortFields = append(sortFields, orderby)
  79 + }
  80 + qs = qs.OrderBy(sortFields...)
  81 + } else if len(sortby) != len(order) && len(order) == 1 {
  82 + // 2) there is exactly one order, all the sorted fields will be sorted by this order
  83 + for _, v := range sortby {
  84 + orderby := ""
  85 + if order[0] == "desc" {
  86 + orderby = "-" + v
  87 + } else if order[0] == "asc" {
  88 + orderby = v
  89 + } else {
  90 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  91 + }
  92 + sortFields = append(sortFields, orderby)
  93 + }
  94 + } else if len(sortby) != len(order) && len(order) != 1 {
  95 + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
  96 + }
  97 + } else {
  98 + if len(order) != 0 {
  99 + return nil, errors.New("Error: unused 'order' fields")
  100 + }
  101 + }
  102 +
  103 + var l []QuestionDepartmentLog
  104 + qs = qs.OrderBy(sortFields...)
  105 + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
  106 + if len(fields) == 0 {
  107 + for _, v := range l {
  108 + ml = append(ml, v)
  109 + }
  110 + } else {
  111 + // trim unused fields
  112 + for _, v := range l {
  113 + m := make(map[string]interface{})
  114 + val := reflect.ValueOf(v)
  115 + for _, fname := range fields {
  116 + m[fname] = val.FieldByName(fname).Interface()
  117 + }
  118 + ml = append(ml, m)
  119 + }
  120 + }
  121 + return ml, nil
  122 + }
  123 + return nil, err
  124 +}
  125 +
  126 +// UpdateQuestionDepartmentLog updates QuestionDepartmentLog by Id and returns error if
  127 +// the record to be updated doesn't exist
  128 +func UpdateQuestionDepartmentLogById(m *QuestionDepartmentLog) (err error) {
  129 + o := orm.NewOrm()
  130 + v := QuestionDepartmentLog{Id: m.Id}
  131 + // ascertain id exists in the database
  132 + if err = o.Read(&v); err == nil {
  133 + var num int64
  134 + if num, err = o.Update(m); err == nil {
  135 + fmt.Println("Number of records updated in database:", num)
  136 + }
  137 + }
  138 + return
  139 +}
  140 +
  141 +// DeleteQuestionDepartmentLog deletes QuestionDepartmentLog by Id and returns error if
  142 +// the record to be deleted doesn't exist
  143 +func DeleteQuestionDepartmentLog(id int) (err error) {
  144 + o := orm.NewOrm()
  145 + v := QuestionDepartmentLog{Id: id}
  146 + // ascertain id exists in the database
  147 + if err = o.Read(&v); err == nil {
  148 + var num int64
  149 + if num, err = o.Delete(&QuestionDepartmentLog{Id: id}); err == nil {
  150 + fmt.Println("Number of records deleted in database:", num)
  151 + }
  152 + }
  153 + return
  154 +}
  1 +package models
  2 +
  3 +import (
  4 + "errors"
  5 + "fmt"
  6 + "reflect"
  7 + "strings"
  8 +
  9 + "github.com/astaxie/beego/orm"
  10 +)
  11 +
  12 +type QuestionImage struct {
  13 + Id int `orm:"column(id);pk"`
  14 + Qid int64 `orm:"column(qid);null" description:"所属的问题ID"`
  15 + Path string `orm:"column(path);size(500);null" description:"语音路径"`
  16 + W int `orm:"column(w)"`
  17 + H int `orm:"column(h)"`
  18 +}
  19 +
  20 +func (t *QuestionImage) TableName() string {
  21 + return "question_image"
  22 +}
  23 +
  24 +func init() {
  25 + orm.RegisterModel(new(QuestionImage))
  26 +}
  27 +
  28 +// AddQuestionImage insert a new QuestionImage into database and returns
  29 +// last inserted Id on success.
  30 +func AddQuestionImage(m *QuestionImage) (id int64, err error) {
  31 + o := orm.NewOrm()
  32 + id, err = o.Insert(m)
  33 + return
  34 +}
  35 +
  36 +// GetQuestionImageById retrieves QuestionImage by Id. Returns error if
  37 +// Id doesn't exist
  38 +func GetQuestionImageById(id int) (v *QuestionImage, err error) {
  39 + o := orm.NewOrm()
  40 + v = &QuestionImage{Id: id}
  41 + if err = o.Read(v); err == nil {
  42 + return v, nil
  43 + }
  44 + return nil, err
  45 +}
  46 +
  47 +// GetAllQuestionImage retrieves all QuestionImage matches certain condition. Returns empty list if
  48 +// no records exist
  49 +func GetAllQuestionImage(query map[string]string, fields []string, sortby []string, order []string,
  50 + offset int64, limit int64) (ml []interface{}, err error) {
  51 + o := orm.NewOrm()
  52 + qs := o.QueryTable(new(QuestionImage))
  53 + // query k=v
  54 + for k, v := range query {
  55 + // rewrite dot-notation to Object__Attribute
  56 + k = strings.Replace(k, ".", "__", -1)
  57 + if strings.Contains(k, "isnull") {
  58 + qs = qs.Filter(k, (v == "true" || v == "1"))
  59 + } else {
  60 + qs = qs.Filter(k, v)
  61 + }
  62 + }
  63 + // order by:
  64 + var sortFields []string
  65 + if len(sortby) != 0 {
  66 + if len(sortby) == len(order) {
  67 + // 1) for each sort field, there is an associated order
  68 + for i, v := range sortby {
  69 + orderby := ""
  70 + if order[i] == "desc" {
  71 + orderby = "-" + v
  72 + } else if order[i] == "asc" {
  73 + orderby = v
  74 + } else {
  75 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  76 + }
  77 + sortFields = append(sortFields, orderby)
  78 + }
  79 + qs = qs.OrderBy(sortFields...)
  80 + } else if len(sortby) != len(order) && len(order) == 1 {
  81 + // 2) there is exactly one order, all the sorted fields will be sorted by this order
  82 + for _, v := range sortby {
  83 + orderby := ""
  84 + if order[0] == "desc" {
  85 + orderby = "-" + v
  86 + } else if order[0] == "asc" {
  87 + orderby = v
  88 + } else {
  89 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  90 + }
  91 + sortFields = append(sortFields, orderby)
  92 + }
  93 + } else if len(sortby) != len(order) && len(order) != 1 {
  94 + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
  95 + }
  96 + } else {
  97 + if len(order) != 0 {
  98 + return nil, errors.New("Error: unused 'order' fields")
  99 + }
  100 + }
  101 +
  102 + var l []QuestionImage
  103 + qs = qs.OrderBy(sortFields...)
  104 + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
  105 + if len(fields) == 0 {
  106 + for _, v := range l {
  107 + ml = append(ml, v)
  108 + }
  109 + } else {
  110 + // trim unused fields
  111 + for _, v := range l {
  112 + m := make(map[string]interface{})
  113 + val := reflect.ValueOf(v)
  114 + for _, fname := range fields {
  115 + m[fname] = val.FieldByName(fname).Interface()
  116 + }
  117 + ml = append(ml, m)
  118 + }
  119 + }
  120 + return ml, nil
  121 + }
  122 + return nil, err
  123 +}
  124 +
  125 +// UpdateQuestionImage updates QuestionImage by Id and returns error if
  126 +// the record to be updated doesn't exist
  127 +func UpdateQuestionImageById(m *QuestionImage) (err error) {
  128 + o := orm.NewOrm()
  129 + v := QuestionImage{Id: m.Id}
  130 + // ascertain id exists in the database
  131 + if err = o.Read(&v); err == nil {
  132 + var num int64
  133 + if num, err = o.Update(m); err == nil {
  134 + fmt.Println("Number of records updated in database:", num)
  135 + }
  136 + }
  137 + return
  138 +}
  139 +
  140 +// DeleteQuestionImage deletes QuestionImage by Id and returns error if
  141 +// the record to be deleted doesn't exist
  142 +func DeleteQuestionImage(id int) (err error) {
  143 + o := orm.NewOrm()
  144 + v := QuestionImage{Id: id}
  145 + // ascertain id exists in the database
  146 + if err = o.Read(&v); err == nil {
  147 + var num int64
  148 + if num, err = o.Delete(&QuestionImage{Id: id}); err == nil {
  149 + fmt.Println("Number of records deleted in database:", num)
  150 + }
  151 + }
  152 + return
  153 +}
  1 +package models
  2 +
  3 +import (
  4 + "errors"
  5 + "fmt"
  6 + "reflect"
  7 + "strings"
  8 + "time"
  9 +
  10 + "github.com/astaxie/beego/orm"
  11 +)
  12 +
  13 +type QuestionScore struct {
  14 + Id int `orm:"column(id);pk"`
  15 + Uid int64 `orm:"column(uid);null" description:"评分用户ID"`
  16 + Qid int64 `orm:"column(qid);null" description:"所属的问题ID"`
  17 + ScoreAnalyze int `orm:"column(scoreAnalyze);null"`
  18 + ScoreAsk int `orm:"column(scoreAsk);null"`
  19 + ScoreScheme int `orm:"column(scoreScheme);null"`
  20 + CreateTime time.Time `orm:"column(createTime);type(timestamp);null;auto_now_add" description:"评分时间"`
  21 +}
  22 +
  23 +func (t *QuestionScore) TableName() string {
  24 + return "question_score"
  25 +}
  26 +
  27 +func init() {
  28 + orm.RegisterModel(new(QuestionScore))
  29 +}
  30 +
  31 +// AddQuestionScore insert a new QuestionScore into database and returns
  32 +// last inserted Id on success.
  33 +func AddQuestionScore(m *QuestionScore) (id int64, err error) {
  34 + o := orm.NewOrm()
  35 + id, err = o.Insert(m)
  36 + return
  37 +}
  38 +
  39 +// GetQuestionScoreById retrieves QuestionScore by Id. Returns error if
  40 +// Id doesn't exist
  41 +func GetQuestionScoreById(id int) (v *QuestionScore, err error) {
  42 + o := orm.NewOrm()
  43 + v = &QuestionScore{Id: id}
  44 + if err = o.Read(v); err == nil {
  45 + return v, nil
  46 + }
  47 + return nil, err
  48 +}
  49 +
  50 +// GetAllQuestionScore retrieves all QuestionScore matches certain condition. Returns empty list if
  51 +// no records exist
  52 +func GetAllQuestionScore(query map[string]string, fields []string, sortby []string, order []string,
  53 + offset int64, limit int64) (ml []interface{}, err error) {
  54 + o := orm.NewOrm()
  55 + qs := o.QueryTable(new(QuestionScore))
  56 + // query k=v
  57 + for k, v := range query {
  58 + // rewrite dot-notation to Object__Attribute
  59 + k = strings.Replace(k, ".", "__", -1)
  60 + if strings.Contains(k, "isnull") {
  61 + qs = qs.Filter(k, (v == "true" || v == "1"))
  62 + } else {
  63 + qs = qs.Filter(k, v)
  64 + }
  65 + }
  66 + // order by:
  67 + var sortFields []string
  68 + if len(sortby) != 0 {
  69 + if len(sortby) == len(order) {
  70 + // 1) for each sort field, there is an associated order
  71 + for i, v := range sortby {
  72 + orderby := ""
  73 + if order[i] == "desc" {
  74 + orderby = "-" + v
  75 + } else if order[i] == "asc" {
  76 + orderby = v
  77 + } else {
  78 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  79 + }
  80 + sortFields = append(sortFields, orderby)
  81 + }
  82 + qs = qs.OrderBy(sortFields...)
  83 + } else if len(sortby) != len(order) && len(order) == 1 {
  84 + // 2) there is exactly one order, all the sorted fields will be sorted by this order
  85 + for _, v := range sortby {
  86 + orderby := ""
  87 + if order[0] == "desc" {
  88 + orderby = "-" + v
  89 + } else if order[0] == "asc" {
  90 + orderby = v
  91 + } else {
  92 + return nil, errors.New("Error: Invalid order. Must be either [asc|desc]")
  93 + }
  94 + sortFields = append(sortFields, orderby)
  95 + }
  96 + } else if len(sortby) != len(order) && len(order) != 1 {
  97 + return nil, errors.New("Error: 'sortby', 'order' sizes mismatch or 'order' size is not 1")
  98 + }
  99 + } else {
  100 + if len(order) != 0 {
  101 + return nil, errors.New("Error: unused 'order' fields")
  102 + }
  103 + }
  104 +
  105 + var l []QuestionScore
  106 + qs = qs.OrderBy(sortFields...)
  107 + if _, err = qs.Limit(limit, offset).All(&l, fields...); err == nil {
  108 + if len(fields) == 0 {
  109 + for _, v := range l {
  110 + ml = append(ml, v)
  111 + }
  112 + } else {
  113 + // trim unused fields
  114 + for _, v := range l {
  115 + m := make(map[string]interface{})
  116 + val := reflect.ValueOf(v)
  117 + for _, fname := range fields {
  118 + m[fname] = val.FieldByName(fname).Interface()
  119 + }
  120 + ml = append(ml, m)
  121 + }
  122 + }
  123 + return ml, nil
  124 + }
  125 + return nil, err
  126 +}
  127 +
  128 +// UpdateQuestionScore updates QuestionScore by Id and returns error if
  129 +// the record to be updated doesn't exist
  130 +func UpdateQuestionScoreById(m *QuestionScore) (err error) {
  131 + o := orm.NewOrm()
  132 + v := QuestionScore{Id: m.Id}
  133 + // ascertain id exists in the database
  134 + if err = o.Read(&v); err == nil {
  135 + var num int64
  136 + if num, err = o.Update(m); err == nil {
  137 + fmt.Println("Number of records updated in database:", num)
  138 + }
  139 + }
  140 + return
  141 +}
  142 +
  143 +// DeleteQuestionScore deletes QuestionScore by Id and returns error if
  144 +// the record to be deleted doesn't exist
  145 +func DeleteQuestionScore(id int) (err error) {
  146 + o := orm.NewOrm()
  147 + v := QuestionScore{Id: id}
  148 + // ascertain id exists in the database
  149 + if err = o.Read(&v); err == nil {
  150 + var num int64
  151 + if num, err = o.Delete(&QuestionScore{Id: id}); err == nil {
  152 + fmt.Println("Number of records deleted in database:", num)
  153 + }
  154 + }
  155 + return
  156 +}