作者 linmadan

首次提交,完成员工CURD接口

正在显示 43 个修改的文件 包含 1808 行增加0 行删除
  1 +# Compiled Object codefiles, Static and Dynamic libs (Shared Objects)
  2 +*.o
  3 +*.a
  4 +*.so
  5 +
  6 +# Folders
  7 +_obj
  8 +_test
  9 +
  10 +# Architecture specific extensions/prefixes
  11 +*.[568vq]
  12 +[568vq].out
  13 +
  14 +*.cgo1.go
  15 +*.cgo2.c
  16 +_cgo_defun.c
  17 +_cgo_gotypes.go
  18 +_cgo_export.*
  19 +
  20 +_testmain.go
  21 +
  22 +*.exe
  23 +*.test
  24 +.log
  25 +.idea
  1 +FROM golang:latest
  2 +MAINTAINER linmadan <772181827@qq.com>
  3 +ENV APP_DIR $GOPATH/src/mmm-worth
  4 +RUN mkdir -p $APP_DIR
  5 +WORKDIR $APP_DIR/
  6 +COPY ./pkg pkg
  7 +COPY ./conf conf
  8 +COPY ./go.mod go.mod
  9 +COPY ./go.sum go.sum
  10 +COPY ./main.go main.go
  11 +RUN ["ln","-sf","/usr/share/zoneinfo/Asia/Shanghai","/etc/localtime"]
  12 +ENV GO111MODULE on
  13 +ENV GOPROXY https://goproxy.io
  14 +RUN ["go","mod","tidy"]
  15 +RUN ["ls"]
  16 +RUN ["go","build"]
  17 +ENTRYPOINT ["./mmm-worth"]
  1 +#mmm-worth
  1 +appname = mmm-worth
  2 +runmode = "${RUN_MODE||dev}"
  3 +httpport = "${HTTP_PORT||8082}"
  4 +
  5 +#开启监控
  6 +EnableAdmin = false
  7 +#开启JSON请求
  8 +copyrequestbody = true
  9 +#防止跨站请求伪造 未启用
  10 +enablexsrf = false
  11 +xsrfkey = asdfioerjlasdfmFADFOEJF2323SDFF
  12 +xsrfexpire = 3600
  13 +[lang]
  14 +types = en-US|zh-CN
  15 +names = English|简体中文
  1 +#!/bin/bash
  2 +export PATH=/root/local/bin:$PATH
  3 +kubectl -n <replace-your-k8s-namespace> get pods | grep -q mmm-worth
  4 +if [ "$?" == "1" ];then
  5 + kubectl create -f /tmp/dev/mmm-worth/mmm-worth.yaml --record
  6 + kubectl -n <replace-your-k8s-namespace> get svc | grep -q mmm-worth
  7 + if [ "$?" == "0" ];then
  8 + echo "mmm-worth service install success!"
  9 + else
  10 + echo "mmm-worth service install fail!"
  11 + fi
  12 + kubectl -n <replace-your-k8s-namespace> get pods | grep -q mmm-worth
  13 + if [ "$?" == "0" ];then
  14 + echo "mmm-worth deployment install success!"
  15 + else
  16 + echo "mmm-worth deployment install fail!"
  17 + fi
  18 +else
  19 + kubectl delete -f /tmp/dev/mmm-worth/mmm-worth.yaml
  20 + kubectl -n <replace-your-k8s-namespace> get svc | grep -q mmm-worth
  21 + while [ "$?" == "0" ]
  22 + do
  23 + kubectl -n <replace-your-k8s-namespace> get svc | grep -q mmm-worth
  24 + done
  25 + kubectl -n <replace-your-k8s-namespace> get pods | grep -q mmm-worth
  26 + while [ "$?" == "0" ]
  27 + do
  28 + kubectl -n <replace-your-k8s-namespace> get pods | grep -q mmm-worth
  29 + done
  30 + kubectl create -f /tmp/dev/mmm-worth/mmm-worth.yaml --record
  31 + kubectl -n <replace-your-k8s-namespace> get svc | grep -q mmm-worth
  32 + if [ "$?" == "0" ];then
  33 + echo "mmm-worth service update success!"
  34 + else
  35 + echo "mmm-worth service update fail!"
  36 + fi
  37 + kubectl -n <replace-your-k8s-namespace> get pods | grep -q mmm-worth
  38 + if [ "$?" == "0" ];then
  39 + echo "mmm-worth deployment update success!"
  40 + else
  41 + echo "mmm-worth deployment update fail!"
  42 + fi
  43 +fi
  1 +apiVersion: v1
  2 +kind: Service
  3 +metadata:
  4 + name: mmm-worth
  5 + namespace: <replace-your-k8s-namespace>
  6 + labels:
  7 + k8s-app: mmm-worth
  8 +spec:
  9 + ports:
  10 + - name: "http"
  11 + port: 80
  12 + targetPort: 8082
  13 + selector:
  14 + k8s-app: mmm-worth
  15 +---
  16 +apiVersion: extensions/v1beta1
  17 +kind: Deployment
  18 +metadata:
  19 + name: mmm-worth
  20 + namespace: <replace-your-k8s-namespace>
  21 + labels:
  22 + k8s-app: mmm-worth
  23 +spec:
  24 + replicas: 1
  25 + template:
  26 + metadata:
  27 + labels:
  28 + k8s-app: mmm-worth
  29 + spec:
  30 + affinity:
  31 + nodeAffinity:
  32 + preferredDuringSchedulingIgnoredDuringExecution:
  33 + - preference: {}
  34 + weight: 100
  35 + requiredDuringSchedulingIgnoredDuringExecution:
  36 + nodeSelectorTerms:
  37 + - matchExpressions:
  38 + - key: kubernetes.io/hostname
  39 + operator: In
  40 + values:
  41 + - cn-hangzhou.i-bp1djh1xn7taumbue1ze
  42 + - cn-hangzhou.i-bp1djh1xn7taumbue1zd
  43 + - cn-hangzhou.i-bp1euf5u1ph9kbhtndhb
  44 + - cn-hangzhou.i-bp1hyp5oips9cdwxxgxy
  45 + containers:
  46 + - name: mmm-worth
  47 + image: 192.168.0.243:5000/mmm/mmm-worth:dev
  48 + imagePullPolicy: Always
  49 + ports:
  50 + - containerPort: 8082
  51 + volumeMounts:
  52 + - mountPath: /opt/logs
  53 + name: accesslogs
  54 + env:
  55 + - name: LOG_LEVEL
  56 + value: "debug"
  57 + - name: ERROR_BASE_CODE
  58 + value: "1"
  59 + - name: ERROR_BASE_CODE_MULTIPLE
  60 + value: "1000"
  61 + volumes:
  62 + - name: accesslogs
  63 + emptyDir: {}
  1 +module gitlab.fjmaimaimai.com/linmadan/mmm-worth
  2 +
  3 +go 1.14
  4 +
  5 +require (
  6 + github.com/ajg/form v1.5.1 // indirect
  7 + github.com/astaxie/beego v1.12.1
  8 + github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072 // indirect
  9 + github.com/fatih/structs v1.1.0 // indirect
  10 + github.com/gavv/httpexpect v2.0.0+incompatible
  11 + github.com/go-pg/pg v8.0.6+incompatible
  12 + github.com/google/go-querystring v1.0.0 // indirect
  13 + github.com/gorilla/websocket v1.4.2 // indirect
  14 + github.com/imkira/go-interpol v1.1.0 // indirect
  15 + github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 // indirect
  16 + github.com/linmadan/egglib-go v0.0.0-20191217144343-ca4539f95bf9
  17 + github.com/mattn/go-colorable v0.1.6 // indirect
  18 + github.com/moul/http2curl v1.0.0 // indirect
  19 + github.com/onsi/ginkgo v1.10.3
  20 + github.com/onsi/gomega v1.7.1
  21 + github.com/sergi/go-diff v1.1.0 // indirect
  22 + github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 // indirect
  23 + github.com/smartystreets/goconvey v1.6.4 // indirect
  24 + github.com/valyala/fasthttp v1.9.0 // indirect
  25 + github.com/xeipuuv/gojsonschema v1.2.0 // indirect
  26 + github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0 // indirect
  27 + github.com/yudai/gojsondiff v1.0.0 // indirect
  28 + github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect
  29 + github.com/yudai/pp v2.0.1+incompatible // indirect
  30 +)
  31 +
  32 +replace gitlab.fjmaimaimai.com/linmadan/mmm-worth => ../mmm-worth
  1 +github.com/DataDog/zstd v1.3.6-0.20190409195224-796139022798/go.mod h1:1jcaCB/ufaK+sKp1NBhlGmpz41jOoPQ35bpF36t7BBo=
  2 +github.com/Knetic/govaluate v3.0.0+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
  3 +github.com/OwnLocal/goes v1.0.0/go.mod h1:8rIFjBGTue3lCU0wplczcUgt9Gxgrkkrw7etMIcn8TM=
  4 +github.com/Shopify/sarama v1.23.1/go.mod h1:XLH1GYJnLVE0XCr6KdJGVJRTwY30moWNJ4sERjXX6fs=
  5 +github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
  6 +github.com/ajg/form v1.5.1 h1:t9c7v8JUKu/XxOGBU0yjNpaMloxGEJhUkqFRq0ibGeU=
  7 +github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY=
  8 +github.com/astaxie/beego v1.12.0/go.mod h1:fysx+LZNZKnvh4GED/xND7jWtjCR6HzydR2Hh2Im57o=
  9 +github.com/astaxie/beego v1.12.1 h1:dfpuoxpzLVgclveAXe4PyNKqkzgm5zF4tgF2B3kkM2I=
  10 +github.com/astaxie/beego v1.12.1/go.mod h1:kPBWpSANNbSdIqOc8SUL9h+1oyBMZhROeYsXQDbidWQ=
  11 +github.com/beego/goyaml2 v0.0.0-20130207012346-5545475820dd/go.mod h1:1b+Y/CofkYwXMUU0OhQqGvsY2Bvgr4j6jfT699wyZKQ=
  12 +github.com/beego/x2j v0.0.0-20131220205130-a0352aadc542/go.mod h1:kSeGC/p1AbBiEp5kat81+DSQrZenVBZXklMLaELspWU=
  13 +github.com/bradfitz/gomemcache v0.0.0-20180710155616-bc664df96737/go.mod h1:PmM6Mmwb0LSuEubjR8N7PtNe1KxZLtOUHtbeikc5h60=
  14 +github.com/casbin/casbin v1.7.0/go.mod h1:c67qKN6Oum3UF5Q1+BByfFxkwKvhwW57ITjqwtzR1KE=
  15 +github.com/cloudflare/golz4 v0.0.0-20150217214814-ef862a3cdc58/go.mod h1:EOBUe0h4xcZ5GoxqC5SDxFQ8gwyZPKQoEzownBlhI80=
  16 +github.com/couchbase/go-couchbase v0.0.0-20181122212707-3e9b6e1258bb/go.mod h1:TWI8EKQMs5u5jLKW/tsb9VwauIrMIxQG1r5fMsswK5U=
  17 +github.com/couchbase/gomemcached v0.0.0-20181122193126-5125a94a666c/go.mod h1:srVSlQLB8iXBVXHgnqemxUXqN6FCvClgCMPCsjBDR7c=
  18 +github.com/couchbase/goutils v0.0.0-20180530154633-e865a1461c8a/go.mod h1:BQwMFlJzDjFDG3DJUdU0KORxn88UlsOULuxLExMh3Hs=
  19 +github.com/cupcake/rdb v0.0.0-20161107195141-43ba34106c76/go.mod h1:vYwsqCOLxGiisLwp9rITslkFNpZD5rz43tf41QFkTWY=
  20 +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
  21 +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
  22 +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
  23 +github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
  24 +github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
  25 +github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
  26 +github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
  27 +github.com/edsrzf/mmap-go v0.0.0-20170320065105-0bce6a688712/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M=
  28 +github.com/elazarl/go-bindata-assetfs v1.0.0 h1:G/bYguwHIzWq9ZoyUQqrjTmJbbYn3j3CKKpKinvZLFk=
  29 +github.com/elazarl/go-bindata-assetfs v1.0.0/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4=
  30 +github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072 h1:DddqAaWDpywytcG8w/qoQ5sAN8X12d3Z3koB0C3Rxsc=
  31 +github.com/fasthttp-contrib/websocket v0.0.0-20160511215533-1f3b11f56072/go.mod h1:duJ4Jxv5lDcvg4QuQr0oowTf7dz4/CR8NtyCooz9HL8=
  32 +github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
  33 +github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
  34 +github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
  35 +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
  36 +github.com/gavv/httpexpect v2.0.0+incompatible h1:1X9kcRshkSKEjNJJxX9Y9mQ5BRfbxU5kORdjhlA1yX8=
  37 +github.com/gavv/httpexpect v2.0.0+incompatible/go.mod h1:x+9tiU1YnrOvnB725RkpoLv1M62hOWzwo5OXotisrKc=
  38 +github.com/go-pg/pg v8.0.6+incompatible h1:Hi7yUJ2zwmHFq1Mar5XqhCe3NJ7j9r+BaiNmd+vqf+A=
  39 +github.com/go-pg/pg v8.0.6+incompatible/go.mod h1:a2oXow+aFOrvwcKs3eIA0lNFmMilrxK2sOkB5NWe0vA=
  40 +github.com/go-redis/redis v6.14.2+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA=
  41 +github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
  42 +github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
  43 +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
  44 +github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
  45 +github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
  46 +github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
  47 +github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
  48 +github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
  49 +github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4=
  50 +github.com/google/go-querystring v1.0.0 h1:Xkwi/a1rcvNg1PPYe5vI8GbeBY/jrVuDX5ASuANWTrk=
  51 +github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
  52 +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
  53 +github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
  54 +github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
  55 +github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
  56 +github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
  57 +github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
  58 +github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
  59 +github.com/imkira/go-interpol v1.1.0 h1:KIiKr0VSG2CUW1hl1jpiyuzuJeKUUpC8iM1AIE7N1Vk=
  60 +github.com/imkira/go-interpol v1.1.0/go.mod h1:z0h2/2T3XF8kyEPpRgJ3kmNv+C43p+I/CoI+jC3w2iA=
  61 +github.com/jcmturner/gofork v0.0.0-20190328161633-dc7c13fece03/go.mod h1:MK8+TM0La+2rjBD4jE12Kj1pCCxK7d2LK/UM3ncEo0o=
  62 +github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
  63 +github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
  64 +github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
  65 +github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
  66 +github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88 h1:uC1QfSlInpQF+M0ao65imhwqKnz3Q2z/d8PWZRMQvDM=
  67 +github.com/k0kubun/colorstring v0.0.0-20150214042306-9440f1994b88/go.mod h1:3w7q1U84EfirKl04SVQ/s7nPm1ZPhiXd34z40TNz36k=
  68 +github.com/klauspost/compress v1.8.2 h1:Bx0qjetmNjdFXASH02NSAREKpiaDwkO1DRZ3dV2KCcs=
  69 +github.com/klauspost/compress v1.8.2/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
  70 +github.com/klauspost/cpuid v1.2.1 h1:vJi+O/nMdFt0vqm8NZBI6wzALWdA2X+egi0ogNyrC/w=
  71 +github.com/klauspost/cpuid v1.2.1/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
  72 +github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
  73 +github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
  74 +github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
  75 +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
  76 +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
  77 +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
  78 +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
  79 +github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
  80 +github.com/linmadan/egglib-go v0.0.0-20191217144343-ca4539f95bf9 h1:zJZsqJ1wFMYb2yrja5S3OZ+oASx4irRksZ8+emFs56M=
  81 +github.com/linmadan/egglib-go v0.0.0-20191217144343-ca4539f95bf9/go.mod h1:S1zYn9bb6h+Qzu1aOO8raFhHniewOBaif3YvA9qA6lk=
  82 +github.com/mattn/go-colorable v0.1.6 h1:6Su7aK7lXmJ/U79bYtBjLNaha4Fs1Rg9plHpcH+vvnE=
  83 +github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
  84 +github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
  85 +github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
  86 +github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
  87 +github.com/moul/http2curl v1.0.0 h1:dRMWoAtb+ePxMlLkrCbAqh4TlPHXvoGUSQ323/9Zahs=
  88 +github.com/moul/http2curl v1.0.0/go.mod h1:8UbvGypXm98wA/IqH45anm5Y2Z6ep6O31QGOAZ3H0fQ=
  89 +github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
  90 +github.com/onsi/ginkgo v1.10.3 h1:OoxbjfXVZyod1fmWYhI7SEyaD8B00ynP3T+D5GiyHOY=
  91 +github.com/onsi/ginkgo v1.10.3/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
  92 +github.com/onsi/gomega v1.7.1 h1:K0jcRCwNQM3vFGh1ppMtDh/+7ApJrjldlX8fA0jDTLQ=
  93 +github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
  94 +github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
  95 +github.com/pierrec/lz4 v0.0.0-20190327172049-315a67e90e41/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc=
  96 +github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
  97 +github.com/pkg/profile v1.2.1/go.mod h1:hJw3o1OdXxsrSjjVksARp5W95eeEaEfptyVZyv6JUPA=
  98 +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
  99 +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
  100 +github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
  101 +github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
  102 +github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
  103 +github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 h1:X+yvsM2yrEktyI+b2qND5gpH8YhURn0k8OCaeRnkINo=
  104 +github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644/go.mod h1:nkxAfR/5quYxwPZhyDxgasBMnRtBZd0FCEpawpjMUFg=
  105 +github.com/siddontang/go v0.0.0-20180604090527-bdc77568d726/go.mod h1:3yhqj7WBBfRhbBlzyOC3gUxftwsU0u8gqevxwIHQpMw=
  106 +github.com/siddontang/ledisdb v0.0.0-20181029004158-becf5f38d373/go.mod h1:mF1DpOSOUiJRMR+FDqaqu3EBqrybQtrDDszLUZ6oxPg=
  107 +github.com/siddontang/rdb v0.0.0-20150307021120-fc89ed2e418d/go.mod h1:AMEsy7v5z92TR1JKMkLLoaOQk++LVnOKL3ScbJ8GNGA=
  108 +github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
  109 +github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
  110 +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
  111 +github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
  112 +github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
  113 +github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
  114 +github.com/ssdb/gossdb v0.0.0-20180723034631-88f6b59b84ec/go.mod h1:QBvMkMya+gXctz3kmljlUCu/yB3GZ6oee+dUozsezQE=
  115 +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
  116 +github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
  117 +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
  118 +github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
  119 +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
  120 +github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
  121 +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
  122 +github.com/syndtr/goleveldb v0.0.0-20181127023241-353a9fca669c/go.mod h1:Z4AUp2Km+PwemOoO/VB5AOx9XSsIItzFjoJlOSiYmn0=
  123 +github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
  124 +github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
  125 +github.com/valyala/fasthttp v1.9.0 h1:hNpmUdy/+ZXYpGy0OBfm7K0UQTzb73W0T0U4iJIVrMw=
  126 +github.com/valyala/fasthttp v1.9.0/go.mod h1:FstJa9V+Pj9vQ7OJie2qMHdwemEDaDiSdBnvPM1Su9w=
  127 +github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio=
  128 +github.com/wendal/errors v0.0.0-20130201093226-f66c77a7882b/go.mod h1:Q12BUT7DqIlHRmgv3RskH+UCM/4eqVMgI0EMmlSpAXc=
  129 +github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c/go.mod h1:lB8K/P019DLNhemzwFU4jHLhdvlE6uDZjXFejJXr49I=
  130 +github.com/xdg/stringprep v1.0.0/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y=
  131 +github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f h1:J9EGpcZtP0E/raorCMxlFGSTBrsSlaDGf3jU/qvAE2c=
  132 +github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
  133 +github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHovont7NscjpAxXsDA8S8BMYve8Y5+7cuRE7R0=
  134 +github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
  135 +github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74=
  136 +github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
  137 +github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0 h1:6fRhSjgLCkTD3JnJxvaJ4Sj+TYblw757bqYgZaOq5ZY=
  138 +github.com/yalp/jsonpath v0.0.0-20180802001716-5cc68e5049a0/go.mod h1:/LWChgwKmvncFJFHJ7Gvn9wZArjbV5/FppcK2fKk/tI=
  139 +github.com/yudai/gojsondiff v1.0.0 h1:27cbfqXLVEJ1o8I6v3y9lg8Ydm53EKqHXAOMxEGlCOA=
  140 +github.com/yudai/gojsondiff v1.0.0/go.mod h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FBNExI05xg=
  141 +github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 h1:BHyfKlQyqbsFN5p3IfnEUduWvb9is428/nNb5L3U01M=
  142 +github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM=
  143 +github.com/yudai/pp v2.0.1+incompatible h1:Q4//iY4pNF6yPLZIigmvcl7k/bPgrcTPIFIcmawg5bI=
  144 +github.com/yudai/pp v2.0.1+incompatible/go.mod h1:PuxR/8QJ7cyCkFp/aUDS+JY727OFEZkTdatxwunjIkc=
  145 +golang.org/x/crypto v0.0.0-20180910181607-0e37d006457b/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
  146 +golang.org/x/crypto v0.0.0-20181127143415-eb0de9b17e85/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
  147 +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
  148 +golang.org/x/crypto v0.0.0-20190404164418-38d8ce5564a5/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE=
  149 +golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
  150 +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
  151 +golang.org/x/crypto v0.0.0-20191029031824-8986dd9e96cf h1:fnPsqIDRbCSgumaMCRpoIoF2s4qxv0xSSS0BVZUE/ss=
  152 +golang.org/x/crypto v0.0.0-20191029031824-8986dd9e96cf/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
  153 +golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
  154 +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
  155 +golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
  156 +golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
  157 +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
  158 +golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
  159 +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
  160 +golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
  161 +golang.org/x/net v0.0.0-20190923162816-aa69164e4478 h1:l5EDrHhldLYb3ZRHDUhXF7Om7MvYXnkV9/iQNo1lX6g=
  162 +golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
  163 +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
  164 +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
  165 +golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
  166 +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
  167 +golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
  168 +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
  169 +golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
  170 +golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
  171 +golang.org/x/sys v0.0.0-20191010194322-b09406accb47 h1:/XfQ9z7ib8eEJX2hdgFTZJ/ntt0swNk5oYBziWeTCvY=
  172 +golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
  173 +golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
  174 +golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8=
  175 +golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
  176 +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
  177 +golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
  178 +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
  179 +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
  180 +golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
  181 +golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
  182 +golang.org/x/tools v0.0.0-20200117065230-39095c1d176c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
  183 +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
  184 +google.golang.org/appengine v1.6.2/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0=
  185 +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
  186 +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
  187 +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
  188 +gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
  189 +gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
  190 +gopkg.in/jcmturner/aescts.v1 v1.0.1/go.mod h1:nsR8qBOg+OucoIW+WMhB3GspUQXq9XorLnQb9XtvcOo=
  191 +gopkg.in/jcmturner/dnsutils.v1 v1.0.1/go.mod h1:m3v+5svpVOhtFAP/wSz+yzh4Mc0Fg7eRhxkJMWSIz9Q=
  192 +gopkg.in/jcmturner/goidentity.v3 v3.0.0/go.mod h1:oG2kH0IvSYNIu80dVAyu/yoefjq1mNfM5bm88whjWx4=
  193 +gopkg.in/jcmturner/gokrb5.v7 v7.2.3/go.mod h1:l8VISx+WGYp+Fp7KRbsiUuXTTOnxIc3Tuvyavf11/WM=
  194 +gopkg.in/jcmturner/rpc.v1 v1.1.0/go.mod h1:YIdkC4XfD6GXbzje11McwsDuOlZQSb9W4vfLvuNnlv8=
  195 +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
  196 +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
  197 +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
  198 +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
  199 +gopkg.in/yaml.v2 v2.2.4 h1:/eiJrUcujPVeJ3xlSWaiNi3uSVmDGBK1pDHUHAnao1I=
  200 +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
  201 +mellium.im/sasl v0.2.1 h1:nspKSRg7/SyO0cRGY71OkfHab8tf9kCts6a6oTDut0w=
  202 +mellium.im/sasl v0.2.1/go.mod h1:ROaEDLQNuf9vjKqE1SrAfnsobm2YKXT1gnN1uDp1PjQ=
  1 +package main
  2 +
  3 +import "fmt"
  4 +
  5 +func main() {
  6 + fmt.Print("")
  7 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/astaxie/beego/validation"
  6 +)
  7 +
  8 +type CreateEmployeeCommand struct {
  9 + Uid int64 `json:"uid" valid:"Required"`
  10 + // 员工姓名
  11 + EmployeeName string `json:"employeeName" valid:"Required"`
  12 + // 员工账号
  13 + EmployeeAccount string `json:"employeeAccount" valid:"Required"`
  14 +}
  15 +
  16 +func (createEmployeeCommand *CreateEmployeeCommand) ValidateCommand() error {
  17 + valid := validation.Validation{}
  18 + b, err := valid.Valid(createEmployeeCommand)
  19 + if err != nil {
  20 + return err
  21 + }
  22 + if !b {
  23 + for _, validErr := range valid.Errors {
  24 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  25 + }
  26 + }
  27 + return nil
  28 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/astaxie/beego/validation"
  6 +)
  7 +
  8 +type RemoveEmployeeCommand struct {
  9 + // 统一用户UID
  10 + Uid int64 `json:"uid" valid:"Required"`
  11 +}
  12 +
  13 +func (removeEmployeeCommand *RemoveEmployeeCommand) ValidateCommand() error {
  14 + valid := validation.Validation{}
  15 + b, err := valid.Valid(removeEmployeeCommand)
  16 + if err != nil {
  17 + return err
  18 + }
  19 + if !b {
  20 + for _, validErr := range valid.Errors {
  21 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  22 + }
  23 + }
  24 + return nil
  25 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/astaxie/beego/validation"
  6 +)
  7 +
  8 +type UpdateEmployeeCommand struct {
  9 + // 统一用户UID
  10 + Uid int64 `json:"uid" valid:"Required"`
  11 + // 员工姓名
  12 + EmployeeName string `json:"employeeName,omitempty"`
  13 + // 员工账号
  14 + EmployeeAccount string `json:"employeeAccount,omitempty"`
  15 +}
  16 +
  17 +func (updateEmployeeCommand *UpdateEmployeeCommand) ValidateCommand() error {
  18 + valid := validation.Validation{}
  19 + b, err := valid.Valid(updateEmployeeCommand)
  20 + if err != nil {
  21 + return err
  22 + }
  23 + if !b {
  24 + for _, validErr := range valid.Errors {
  25 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  26 + }
  27 + }
  28 + return nil
  29 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/astaxie/beego/validation"
  6 +)
  7 +
  8 +type GetEmployeeQuery struct {
  9 + // 统一用户UID
  10 + Uid int64 `json:"uid" valid:"Required"`
  11 +}
  12 +
  13 +func (getEmployeeQuery *GetEmployeeQuery) ValidateQuery() error {
  14 + valid := validation.Validation{}
  15 + b, err := valid.Valid(getEmployeeQuery)
  16 + if err != nil {
  17 + return err
  18 + }
  19 + if !b {
  20 + for _, validErr := range valid.Errors {
  21 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  22 + }
  23 + }
  24 + return nil
  25 +}
  1 +package query
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/astaxie/beego/validation"
  6 +)
  7 +
  8 +type ListEmployeeQuery struct {
  9 + // 查询偏离量
  10 + Offset int `json:"offset,omitempty"`
  11 + // 查询限制
  12 + Limit int `json:"limit,omitempty"`
  13 +}
  14 +
  15 +func (listEmployeeQuery *ListEmployeeQuery) ValidateQuery() error {
  16 + valid := validation.Validation{}
  17 + b, err := valid.Valid(listEmployeeQuery)
  18 + if err != nil {
  19 + return err
  20 + }
  21 + if !b {
  22 + for _, validErr := range valid.Errors {
  23 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  24 + }
  25 + }
  26 + return nil
  27 +}
  1 +package service
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/linmadan/egglib-go/core/application"
  6 + "github.com/linmadan/egglib-go/utils/tool_funs"
  7 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/employee/command"
  8 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/employee/query"
  9 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/factory"
  10 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
  11 +)
  12 +
  13 +// 员工服务
  14 +type EmployeeService struct {
  15 +}
  16 +
  17 +// 创建新员工
  18 +func (employeeService *EmployeeService) CreateEmployee(createEmployeeCommand *command.CreateEmployeeCommand) (interface{}, error) {
  19 + if err := createEmployeeCommand.ValidateCommand(); err != nil {
  20 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  21 + }
  22 + transactionContext, err := factory.CreateTransactionContext(nil)
  23 + if err != nil {
  24 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  25 + }
  26 + if err := transactionContext.StartTransaction(); err != nil {
  27 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  28 + }
  29 + defer func() {
  30 + transactionContext.RollbackTransaction()
  31 + }()
  32 + newEmployee := &domain.Employee{
  33 + EmployeeInfo: &domain.EmployeeInfo{
  34 + Uid: createEmployeeCommand.Uid,
  35 + EmployeeName: createEmployeeCommand.EmployeeName,
  36 + EmployeeAccount: createEmployeeCommand.EmployeeAccount,
  37 + },
  38 + SuMoney: 0,
  39 + }
  40 + var employeeRepository domain.EmployeeRepository
  41 + if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
  42 + "transactionContext": transactionContext,
  43 + }); err != nil {
  44 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  45 + } else {
  46 + employeeRepository = value
  47 + }
  48 + if employee, err := employeeRepository.Save(newEmployee); err != nil {
  49 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  50 + } else {
  51 + if err := transactionContext.CommitTransaction(); err != nil {
  52 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  53 + }
  54 + return employee, nil
  55 + }
  56 +}
  57 +
  58 +// 返回员工
  59 +func (employeeService *EmployeeService) GetEmployee(getEmployeeQuery *query.GetEmployeeQuery) (interface{}, error) {
  60 + if err := getEmployeeQuery.ValidateQuery(); err != nil {
  61 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  62 + }
  63 + transactionContext, err := factory.CreateTransactionContext(nil)
  64 + if err != nil {
  65 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  66 + }
  67 + if err := transactionContext.StartTransaction(); err != nil {
  68 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  69 + }
  70 + defer func() {
  71 + transactionContext.RollbackTransaction()
  72 + }()
  73 + var employeeRepository domain.EmployeeRepository
  74 + if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
  75 + "transactionContext": transactionContext,
  76 + }); err != nil {
  77 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  78 + } else {
  79 + employeeRepository = value
  80 + }
  81 + employee, err := employeeRepository.FindOne(map[string]interface{}{"uid": getEmployeeQuery.Uid})
  82 + if err != nil {
  83 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  84 + }
  85 + if employee == nil {
  86 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(getEmployeeQuery.Uid)))
  87 + } else {
  88 + if err := transactionContext.CommitTransaction(); err != nil {
  89 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  90 + }
  91 + return employee, nil
  92 + }
  93 +}
  94 +
  95 +// 更新员工
  96 +func (employeeService *EmployeeService) UpdateEmployee(updateEmployeeCommand *command.UpdateEmployeeCommand) (interface{}, error) {
  97 + if err := updateEmployeeCommand.ValidateCommand(); err != nil {
  98 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  99 + }
  100 + transactionContext, err := factory.CreateTransactionContext(nil)
  101 + if err != nil {
  102 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  103 + }
  104 + if err := transactionContext.StartTransaction(); err != nil {
  105 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  106 + }
  107 + defer func() {
  108 + transactionContext.RollbackTransaction()
  109 + }()
  110 + var employeeRepository domain.EmployeeRepository
  111 + if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
  112 + "transactionContext": transactionContext,
  113 + }); err != nil {
  114 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  115 + } else {
  116 + employeeRepository = value
  117 + }
  118 + employee, err := employeeRepository.FindOne(map[string]interface{}{"uid": updateEmployeeCommand.Uid})
  119 + if err != nil {
  120 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  121 + }
  122 + if employee == nil {
  123 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(updateEmployeeCommand.Uid)))
  124 + }
  125 + if err := employee.Update(tool_funs.SimpleStructToMap(updateEmployeeCommand)); err != nil {
  126 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  127 + }
  128 + if employee, err := employeeRepository.Save(employee); err != nil {
  129 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  130 + } else {
  131 + if err := transactionContext.CommitTransaction(); err != nil {
  132 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  133 + }
  134 + return employee, nil
  135 + }
  136 +}
  137 +
  138 +// 移除员工
  139 +func (employeeService *EmployeeService) RemoveEmployee(removeEmployeeCommand *command.RemoveEmployeeCommand) (interface{}, error) {
  140 + if err := removeEmployeeCommand.ValidateCommand(); err != nil {
  141 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  142 + }
  143 + transactionContext, err := factory.CreateTransactionContext(nil)
  144 + if err != nil {
  145 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  146 + }
  147 + if err := transactionContext.StartTransaction(); err != nil {
  148 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  149 + }
  150 + defer func() {
  151 + transactionContext.RollbackTransaction()
  152 + }()
  153 + var employeeRepository domain.EmployeeRepository
  154 + if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
  155 + "transactionContext": transactionContext,
  156 + }); err != nil {
  157 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  158 + } else {
  159 + employeeRepository = value
  160 + }
  161 + employee, err := employeeRepository.FindOne(map[string]interface{}{"uid": removeEmployeeCommand.Uid})
  162 + if err != nil {
  163 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  164 + }
  165 + if employee == nil {
  166 + return nil, application.ThrowError(application.RES_NO_FIND_ERROR, fmt.Sprintf("%s", string(removeEmployeeCommand.Uid)))
  167 + }
  168 + if employee, err := employeeRepository.Remove(employee); err != nil {
  169 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  170 + } else {
  171 + if err := transactionContext.CommitTransaction(); err != nil {
  172 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  173 + }
  174 + return employee, nil
  175 + }
  176 +}
  177 +
  178 +// 返回员工列表
  179 +func (employeeService *EmployeeService) ListEmployee(listEmployeeQuery *query.ListEmployeeQuery) (interface{}, error) {
  180 + if err := listEmployeeQuery.ValidateQuery(); err != nil {
  181 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  182 + }
  183 + transactionContext, err := factory.CreateTransactionContext(nil)
  184 + if err != nil {
  185 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  186 + }
  187 + if err := transactionContext.StartTransaction(); err != nil {
  188 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  189 + }
  190 + defer func() {
  191 + transactionContext.RollbackTransaction()
  192 + }()
  193 + var employeeRepository domain.EmployeeRepository
  194 + if value, err := factory.CreateEmployeeRepository(map[string]interface{}{
  195 + "transactionContext": transactionContext,
  196 + }); err != nil {
  197 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  198 + } else {
  199 + employeeRepository = value
  200 + }
  201 + if count, employees, err := employeeRepository.Find(tool_funs.SimpleStructToMap(listEmployeeQuery)); err != nil {
  202 + return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
  203 + } else {
  204 + if err := transactionContext.CommitTransaction(); err != nil {
  205 + return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  206 + }
  207 + return map[string]interface{}{
  208 + "count": count,
  209 + "employees": employees,
  210 + }, nil
  211 + }
  212 +}
  213 +
  214 +func NewEmployeeService(options map[string]interface{}) *EmployeeService {
  215 + newEmployeeService := &EmployeeService{}
  216 + return newEmployeeService
  217 +}
  1 +package factory
  2 +
  3 +import (
  4 + "github.com/linmadan/egglib-go/transaction/pg"
  5 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
  6 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/repository"
  7 +)
  8 +
  9 +func CreateEmployeeRepository(options map[string]interface{}) (domain.EmployeeRepository, error) {
  10 + var transactionContext *pg.TransactionContext
  11 + if value, ok := options["transactionContext"]; ok {
  12 + transactionContext = value.(*pg.TransactionContext)
  13 + }
  14 + return repository.NewEmployeeRepository(transactionContext)
  15 +}
  16 +
  17 +func CreateTaskRepository(options map[string]interface{}) (domain.TaskRepository, error) {
  18 + var transactionContext *pg.TransactionContext
  19 + if value, ok := options["transactionContext"]; ok {
  20 + transactionContext = value.(*pg.TransactionContext)
  21 + }
  22 + return repository.NewTaskRepository(transactionContext)
  23 +}
  1 +package factory
  2 +
  3 +import (
  4 + "github.com/linmadan/egglib-go/core/application"
  5 + pG "github.com/linmadan/egglib-go/transaction/pg"
  6 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
  7 +)
  8 +
  9 +func CreateTransactionContext(options map[string]interface{}) (application.TransactionContext, error) {
  10 + return pG.NewPGTransactionContext(pg.DB), nil
  11 +}
  1 +package constant
  2 +
  3 +import "os"
  4 +
  5 +const SERVICE_NAME = "mmm-worth"
  6 +
  7 +var LOG_LEVEL = "debug"
  8 +
  9 +func init() {
  10 + if os.Getenv("LOG_LEVEL") != "" {
  11 + LOG_LEVEL = os.Getenv("LOG_LEVEL")
  12 + }
  13 +}
  1 +package constant
  2 +
  3 +import "os"
  4 +
  5 +var POSTGRESQL_DB_NAME = "mmm-worth"
  6 +var POSTGRESQL_USER = "postgres"
  7 +var POSTGRESQL_PASSWORD = "abc123456"
  8 +var POSTGRESQL_HOST = "127.0.0.1"
  9 +var POSTGRESQL_PORT = "32432"
  10 +var DISABLE_CREATE_TABLE = false
  11 +var DISABLE_SQL_GENERATE_PRINT = false
  12 +
  13 +func init() {
  14 + if os.Getenv("POSTGRESQL_DB_NAME") != "" {
  15 + POSTGRESQL_DB_NAME = os.Getenv("POSTGRESQL_DB_NAME")
  16 + }
  17 + if os.Getenv("POSTGRESQL_USER") != "" {
  18 + POSTGRESQL_USER = os.Getenv("POSTGRESQL_USER")
  19 + }
  20 + if os.Getenv("POSTGRESQL_PASSWORD") != "" {
  21 + POSTGRESQL_PASSWORD = os.Getenv("POSTGRESQL_PASSWORD")
  22 + }
  23 + if os.Getenv("POSTGRESQL_HOST") != "" {
  24 + POSTGRESQL_HOST = os.Getenv("POSTGRESQL_HOST")
  25 + }
  26 + if os.Getenv("POSTGRESQL_PORT") != "" {
  27 + POSTGRESQL_PORT = os.Getenv("POSTGRESQL_PORT")
  28 + }
  29 + if os.Getenv("DISABLE_CREATE_TABLE") != "" {
  30 + DISABLE_CREATE_TABLE = true
  31 + }
  32 + if os.Getenv("DISABLE_SQL_GENERATE_PRINT") != "" {
  33 + DISABLE_SQL_GENERATE_PRINT = true
  34 + }
  35 +}
  1 +package domain
  2 +
  3 +import "time"
  4 +
  5 +// 竞标任务信息
  6 +type BidInfo struct {
  7 + // 竞标人员列表
  8 + Bidders []*EmployeeInfo `json:"bidders"`
  9 + // 中标人
  10 + SuccessfulBidder *EmployeeInfo `json:"successfulBidder"`
  11 + // 竞标开始时间
  12 + BidStartTime time.Time `json:"bidStartTime"`
  13 + // 竞标结束时间
  14 + BidEndTime time.Time `json:"bidEndTime"`
  15 + // 中标时间
  16 + WinBidTime time.Time `json:"winBidTime"`
  17 +}
  1 +package domain
  2 +
  3 +// 员工
  4 +type Employee struct {
  5 + // 员工ID
  6 + EmployeeId int64 `json:"employeeId"`
  7 + // 员工信息
  8 + EmployeeInfo *EmployeeInfo `json:"employeeInfo"`
  9 + // 当前素币
  10 + SuMoney float64 `json:"suMoney"`
  11 +}
  12 +
  13 +type EmployeeRepository interface {
  14 + Save(employee *Employee) (*Employee, error)
  15 + Remove(employee *Employee) (*Employee, error)
  16 + FindOne(queryOptions map[string]interface{}) (*Employee, error)
  17 + Find(queryOptions map[string]interface{}) (int64, []*Employee, error)
  18 +}
  19 +
  20 +func (employee *Employee) Identify() interface{} {
  21 + if employee.EmployeeId == 0 {
  22 + return nil
  23 + }
  24 + return employee.EmployeeId
  25 +}
  26 +
  27 +func (employee *Employee) Update(data map[string]interface{}) error {
  28 + if employeeName, ok := data["employeeName"]; ok {
  29 + employee.EmployeeInfo.EmployeeName = employeeName.(string)
  30 + }
  31 + if employeeAccount, ok := data["employeeAccount"]; ok {
  32 + employee.EmployeeInfo.EmployeeAccount = employeeAccount.(string)
  33 + }
  34 + return nil
  35 +}
  36 +
  37 +func (employee *Employee) TransitionSuMoney(suMoney float64) error {
  38 + employee.SuMoney = employee.SuMoney + suMoney
  39 + return nil
  40 +}
  1 +package domain
  2 +
  3 +// 员工信息
  4 +type EmployeeInfo struct {
  5 + // 统一用户UID
  6 + Uid int64 `json:"uid"`
  7 + // 员工姓名
  8 + EmployeeName string `json:"employeeName"`
  9 + // 员工账号
  10 + EmployeeAccount string `json:"employeeAccount"`
  11 +}
  1 +package domain
  2 +
  3 +// 引用资源
  4 +type ReferenceResource struct {
  5 + // 引用类型
  6 + ReferenceResourceType int `json:"referenceResourceType"`
  7 + // 引用资源项列表
  8 + ReferenceResourceItems []*ReferenceResourceItem `json:"referenceResourceItems"`
  9 +}
  1 +package domain
  2 +
  3 +// 引用资源项
  4 +type ReferenceResourceItem struct {
  5 + // 编号
  6 + SerialNumber int64 `json:"serialNumber"`
  7 + // 标题
  8 + Title string `json:"title"`
  9 +}
  1 +package domain
  2 +
  3 +import "time"
  4 +
  5 +// 抢单任务信息
  6 +type RobInfo struct {
  7 + // 领取人
  8 + Receiver *EmployeeInfo `json:"receiver"`
  9 + // 领取时间
  10 + ReceiveTime time.Time `json:"receiveTime"`
  11 +}
  1 +package domain
  2 +
  3 +import "time"
  4 +
  5 +const (
  6 + TASK_TYPE_TO_BE_RELEASED = iota + 1 //待发布
  7 +)
  8 +
  9 +// 任务
  10 +type Task struct {
  11 + // 任务ID
  12 + TakeId int64 `json:"takeId"`
  13 + // 任务名称
  14 + TaskName string `json:"taskName"`
  15 + // 任务类型Type
  16 + TaskType int `json:"taskType"`
  17 + // 任务发起者
  18 + Sponsor *EmployeeInfo `json:"sponsor"`
  19 + // 任务状态
  20 + TaskStatus int `json:"taskStatus"`
  21 + // 引用资源
  22 + ReferenceResource *ReferenceResource `json:"referenceResource"`
  23 + // 客户价值列表
  24 + CustomerValue []string `json:"customerValue"`
  25 + // 任务性质
  26 + TaskNature string `json:"taskNature"`
  27 + // 奖励素币
  28 + SuMoney float64 `json:"suMoney"`
  29 + // 验收标准
  30 + AcceptanceStandard string `json:"acceptanceStandard"`
  31 + // 任务描述
  32 + TaskDescription string `json:"taskDescription"`
  33 + // 任务图片URL列表
  34 + TaskPictureUrls []string `json:"taskPictureUrls"`
  35 + // 是否悬赏任务
  36 + IsRewardTake bool `json:"isRewardTake"`
  37 + // 创建时间
  38 + CreateTime time.Time `json:"createTime"`
  39 + // 抢单任务信息
  40 + RobInfo *RobInfo `json:"robInfo"`
  41 + // 竞标任务信息
  42 + BidInfo *BidInfo `json:"bidInfo"`
  43 + // 任务参与者列表
  44 + Participants []*EmployeeInfo `json:"participants"`
  45 + // 任务贡献占比
  46 + TaskPercentage []*TaskPercentageItem `json:"taskPercentage"`
  47 + // 解决报告
  48 + SolveReport string `json:"solveReport"`
  49 + // 解决图片URL列表
  50 + SolvePictureUrls []string `json:"solvePictureUrls"`
  51 +}
  52 +
  53 +type TaskRepository interface {
  54 + Save(task *Task) (*Task, error)
  55 + Remove(task *Task) (*Task, error)
  56 + FindOne(queryOptions map[string]interface{}) (*Task, error)
  57 + Find(queryOptions map[string]interface{}) (int64, []*Task, error)
  58 +}
  59 +
  60 +func (task *Task) Identify() interface{} {
  61 + if task.TakeId == 0 {
  62 + return nil
  63 + }
  64 + return task.TakeId
  65 +}
  66 +
  67 +func (task *Task) Update(data map[string]interface{}) error {
  68 + if taskName, ok := data["taskName"]; ok {
  69 + task.TaskName = taskName.(string)
  70 + }
  71 + if taskType, ok := data["taskType"]; ok {
  72 + task.TaskType = taskType.(int)
  73 + }
  74 + if customerValue, ok := data["customerValue"]; ok {
  75 + task.CustomerValue = customerValue.([]string)
  76 + }
  77 + if taskNature, ok := data["taskNature"]; ok {
  78 + task.TaskNature = taskNature.(string)
  79 + }
  80 + if suMoney, ok := data["suMoney"]; ok {
  81 + task.SuMoney = suMoney.(float64)
  82 + }
  83 + if acceptanceStandard, ok := data["acceptanceStandard"]; ok {
  84 + task.AcceptanceStandard = acceptanceStandard.(string)
  85 + }
  86 + if taskDescription, ok := data["taskDescription"]; ok {
  87 + task.TaskDescription = taskDescription.(string)
  88 + }
  89 + if taskPictureUrls, ok := data["taskPictureUrls"]; ok {
  90 + task.TaskPictureUrls = taskPictureUrls.([]string)
  91 + }
  92 + if isRewardTake, ok := data["isRewardTake"]; ok {
  93 + task.IsRewardTake = isRewardTake.(bool)
  94 + }
  95 + return nil
  96 +}
  1 +package domain
  2 +
  3 +// 任务贡献占比项
  4 +type TaskPercentageItem struct {
  5 + // 贡献者
  6 + Contributor *EmployeeInfo `json:"contributor"`
  7 + // 任务贡献占比
  8 + Percentage int `json:"percentage"`
  9 +}
  1 +package pg
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/go-pg/pg"
  6 + "github.com/go-pg/pg/orm"
  7 + "github.com/linmadan/egglib-go/persistent/pg/hooks"
  8 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/constant"
  9 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg/models"
  10 +)
  11 +
  12 +var DB *pg.DB
  13 +
  14 +func init() {
  15 + DB = pg.Connect(&pg.Options{
  16 + User: constant.POSTGRESQL_USER,
  17 + Password: constant.POSTGRESQL_PASSWORD,
  18 + Database: constant.POSTGRESQL_DB_NAME,
  19 + Addr: fmt.Sprintf("%s:%s", constant.POSTGRESQL_HOST, constant.POSTGRESQL_PORT),
  20 + })
  21 + if !constant.DISABLE_SQL_GENERATE_PRINT {
  22 + DB.AddQueryHook(hooks.SqlGeneratePrintHook{})
  23 + }
  24 + if !constant.DISABLE_CREATE_TABLE {
  25 + for _, model := range []interface{}{
  26 + (*models.Employee)(nil),
  27 + (*models.Task)(nil),
  28 + } {
  29 + err := DB.CreateTable(model, &orm.CreateTableOptions{
  30 + Temp: false,
  31 + IfNotExists: true,
  32 + FKConstraints: true,
  33 + })
  34 + if err != nil {
  35 + panic(err)
  36 + }
  37 + }
  38 + }
  39 +}
  1 +package models
  2 +
  3 +type Employee struct {
  4 + TableName string `pg:"employees,alias:employee"`
  5 + // 员工ID
  6 + Id int64 `pg:",pk"`
  7 + // 统一用户UID
  8 + Uid int64
  9 + // 员工姓名
  10 + EmployeeName string
  11 + // 员工账号
  12 + EmployeeAccount string
  13 + // 当前素币
  14 + SuMoney float64
  15 +}
  1 +package models
  2 +
  3 +import (
  4 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
  5 + "time"
  6 +)
  7 +
  8 +type Task struct {
  9 + TableName string `pg:"tasks,alias:task"`
  10 + // 任务ID
  11 + Id int64 `pg:",pk"`
  12 + // 任务名称
  13 + TaskName string
  14 + // 任务类型
  15 + TaskType int
  16 + // 任务发起者
  17 + Sponsor *domain.EmployeeInfo
  18 + // 任务状态
  19 + TaskStatus int
  20 + // 引用资源
  21 + ReferenceResource *domain.ReferenceResource
  22 + // 客户价值列表
  23 + CustomerValue []string `pg:",array"`
  24 + // 任务性质
  25 + TaskNature string
  26 + // 奖励素币
  27 + SuMoney float64
  28 + // 验收标准
  29 + AcceptanceStandard string
  30 + // 任务描述
  31 + TaskDescription string
  32 + // 任务图片URL列表
  33 + TaskPictureUrls []string `pg:",array"`
  34 + // 是否悬赏任务
  35 + IsRewardTake bool
  36 + // 创建时间
  37 + CreateTime time.Time
  38 + // 抢单任务信息
  39 + RobInfo *domain.RobInfo
  40 + // 竞标任务信息
  41 + BidInfo *domain.BidInfo
  42 + // 任务参与者列表
  43 + Participants []*domain.EmployeeInfo
  44 + // 任务贡献占比
  45 + TaskPercentage []*domain.TaskPercentageItem
  46 + // 解决报告
  47 + SolveReport string
  48 + // 解决图片URL列表
  49 + SolvePictureUrls []string `pg:",array"`
  50 + RemoveTime time.Time `pg:",soft_delete"`
  51 +}
  1 +package repository
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/go-pg/pg"
  6 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  7 + "github.com/linmadan/egglib-go/utils/snowflake"
  8 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
  9 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg/models"
  10 +)
  11 +
  12 +type EmployeeRepository struct {
  13 + transactionContext *pgTransaction.TransactionContext
  14 +}
  15 +
  16 +func (repository *EmployeeRepository) nextIdentify() (int64, error) {
  17 + IdWorker, err := snowflake.NewIdWorker(1)
  18 + if err != nil {
  19 + return 0, err
  20 + }
  21 + id, err := IdWorker.NextId()
  22 + return id, err
  23 +}
  24 +
  25 +func (repository *EmployeeRepository) Save(employee *domain.Employee) (*domain.Employee, error) {
  26 + tx := repository.transactionContext.PgTx
  27 + if employee.Identify() == nil {
  28 + _, err := repository.nextIdentify()
  29 + if err != nil {
  30 + return employee, err
  31 + }
  32 + if _, err := tx.QueryOne(
  33 + pg.Scan(&employee.EmployeeId, &employee.EmployeeInfo.Uid, &employee.EmployeeInfo.EmployeeName, &employee.EmployeeInfo.EmployeeAccount, &employee.SuMoney),
  34 + "INSERT INTO employees (id, uid, employee_name, employee_account, su_money) VALUES (?, ?, ?, ?, ?) RETURNING id, uid, employee_name, employee_account, su_money",
  35 + employee.EmployeeId, employee.EmployeeInfo.Uid, employee.EmployeeInfo.EmployeeName, employee.EmployeeInfo.EmployeeAccount, employee.SuMoney); err != nil {
  36 + return employee, err
  37 + }
  38 + } else {
  39 + if _, err := tx.QueryOne(
  40 + pg.Scan(&employee.EmployeeId, &employee.EmployeeInfo.Uid, &employee.EmployeeInfo.EmployeeName, &employee.EmployeeInfo.EmployeeAccount, &employee.SuMoney),
  41 + "UPDATE employees SET employee_name=?, employee_account=?, su_money=? WHERE uid=? RETURNING id, uid, employee_name, employee_account, su_money",
  42 + employee.EmployeeInfo.EmployeeName, employee.EmployeeInfo.EmployeeAccount, employee.SuMoney, employee.EmployeeInfo.Uid); err != nil {
  43 + return employee, err
  44 + }
  45 + }
  46 + return employee, nil
  47 +}
  48 +
  49 +func (repository *EmployeeRepository) Remove(employee *domain.Employee) (*domain.Employee, error) {
  50 + tx := repository.transactionContext.PgTx
  51 + employeeModel := new(models.Employee)
  52 + employeeModel.Id = employee.Identify().(int64)
  53 + if _, err := tx.Model(employeeModel).Where("uid = ?", employee.EmployeeInfo.Uid).Delete(); err != nil {
  54 + return employee, err
  55 + }
  56 + return employee, nil
  57 +}
  58 +
  59 +func (repository *EmployeeRepository) FindOne(queryOptions map[string]interface{}) (*domain.Employee, error) {
  60 + tx := repository.transactionContext.PgTx
  61 + employeeModel := new(models.Employee)
  62 + query := tx.Model(employeeModel)
  63 + if uid, ok := queryOptions["uid"]; ok {
  64 + query = query.Where("employee.uid = ?", uid)
  65 + }
  66 + if err := query.Limit(1).Select(); err != nil {
  67 + return nil, err
  68 + }
  69 + if employeeModel.Id == 0 {
  70 + return nil, nil
  71 + } else {
  72 + return &domain.Employee{
  73 + EmployeeId: employeeModel.Id,
  74 + EmployeeInfo: &domain.EmployeeInfo{
  75 + Uid: employeeModel.Uid,
  76 + EmployeeName: employeeModel.EmployeeName,
  77 + EmployeeAccount: employeeModel.EmployeeAccount,
  78 + },
  79 + SuMoney: employeeModel.SuMoney,
  80 + }, nil
  81 + }
  82 +}
  83 +
  84 +func (repository *EmployeeRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Employee, error) {
  85 + tx := repository.transactionContext.PgTx
  86 + var employeeModels []*models.Employee
  87 + var employees []*domain.Employee
  88 + query := tx.Model(&employeeModels)
  89 + if offset, ok := queryOptions["offset"]; ok {
  90 + offset := offset.(int)
  91 + if offset > -1 {
  92 + query = query.Offset(offset)
  93 + }
  94 + } else {
  95 + query = query.Offset(0)
  96 + }
  97 + if limit, ok := queryOptions["limit"]; ok {
  98 + limit := limit.(int)
  99 + if limit > -1 {
  100 + query = query.Limit(limit)
  101 + }
  102 + } else {
  103 + query = query.Limit(20)
  104 + }
  105 + if count, err := query.Order("uid DESC").SelectAndCount(); err != nil {
  106 + return 0, nil, err
  107 + } else {
  108 + for _, employeeModel := range employeeModels {
  109 + employees = append(employees, &domain.Employee{
  110 + EmployeeId: employeeModel.Id,
  111 + EmployeeInfo: &domain.EmployeeInfo{
  112 + Uid: employeeModel.Uid,
  113 + EmployeeName: employeeModel.EmployeeName,
  114 + EmployeeAccount: employeeModel.EmployeeAccount,
  115 + },
  116 + SuMoney: employeeModel.SuMoney,
  117 + })
  118 + }
  119 + return int64(count), employees, nil
  120 + }
  121 +}
  122 +
  123 +func NewEmployeeRepository(transactionContext *pgTransaction.TransactionContext) (*EmployeeRepository, error) {
  124 + if transactionContext == nil {
  125 + return nil, fmt.Errorf("transactionContext参数不能为nil")
  126 + } else {
  127 + return &EmployeeRepository{
  128 + transactionContext: transactionContext,
  129 + }, nil
  130 + }
  131 +}
  1 +package repository
  2 +
  3 +import (
  4 + "fmt"
  5 + "github.com/go-pg/pg"
  6 + pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
  7 + "github.com/linmadan/egglib-go/utils/snowflake"
  8 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/domain"
  9 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg/models"
  10 +)
  11 +
  12 +type TaskRepository struct {
  13 + transactionContext *pgTransaction.TransactionContext
  14 +}
  15 +
  16 +func (repository *TaskRepository) nextIdentify() (int64, error) {
  17 + IdWorker, err := snowflake.NewIdWorker(1)
  18 + if err != nil {
  19 + return 0, err
  20 + }
  21 + id, err := IdWorker.NextId()
  22 + return id, err
  23 +}
  24 +func (repository *TaskRepository) Save(task *domain.Task) (*domain.Task, error) {
  25 + tx := repository.transactionContext.PgTx
  26 + if task.Identify() == nil {
  27 + _, err := repository.nextIdentify()
  28 + if err != nil {
  29 + return task, err
  30 + }
  31 + if _, err := tx.QueryOne(
  32 + pg.Scan(&task.TakeId, &task.TaskName, &task.TaskType, &task.Sponsor, &task.TaskStatus, &task.ReferenceResource, pg.Array(&task.CustomerValue), &task.TaskNature, &task.SuMoney, &task.AcceptanceStandard, &task.TaskDescription, pg.Array(&task.TaskPictureUrls), &task.IsRewardTake, &task.CreateTime, &task.RobInfo, &task.BidInfo, pg.Array(&task.Participants), pg.Array(&task.TaskPercentage), &task.SolveReport, pg.Array(&task.SolvePictureUrls)),
  33 + "INSERT INTO tasks (id, task_name, task_type, sponsor, task_status, reference_resource, customer_value, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, create_time, rob_info, bid_info, participants, task_percentage, solve_report, solve_picture_urls) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id, task_name, task_type, sponsor, task_status, reference_resource, customer_value, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, create_time, rob_info, bid_info, participants, task_percentage, solve_report, solve_picture_urls",
  34 + task.TakeId, task.TaskName, task.TaskType, task.Sponsor, task.TaskStatus, task.ReferenceResource, pg.Array(task.CustomerValue), task.TaskNature, task.SuMoney, task.AcceptanceStandard, task.TaskDescription, pg.Array(task.TaskPictureUrls), task.IsRewardTake, task.CreateTime, task.RobInfo, task.BidInfo, pg.Array(task.Participants), pg.Array(task.TaskPercentage), task.SolveReport, pg.Array(task.SolvePictureUrls)); err != nil {
  35 + return task, err
  36 + }
  37 + } else {
  38 + if _, err := tx.QueryOne(
  39 + pg.Scan(&task.TakeId, &task.TaskName, &task.TaskType, &task.Sponsor, &task.TaskStatus, &task.ReferenceResource, pg.Array(&task.CustomerValue), &task.TaskNature, &task.SuMoney, &task.AcceptanceStandard, &task.TaskDescription, pg.Array(&task.TaskPictureUrls), &task.IsRewardTake, &task.CreateTime, &task.RobInfo, &task.BidInfo, pg.Array(&task.Participants), pg.Array(&task.TaskPercentage), &task.SolveReport, pg.Array(&task.SolvePictureUrls)),
  40 + "UPDATE tasks SET task_name=?, task_type=?, sponsor=?, task_status=?, reference_resource=?, customer_value=?, task_nature=?, su_money=?, acceptance_standard=?, task_description=?, task_picture_urls=?, is_reward_take=?, create_time=?, rob_info=?, bid_info=?, participants=?, task_percentage=?, solve_report=?, solve_picture_urls=? WHERE id=? RETURNING id, task_name, task_type, sponsor, task_status, reference_resource, customer_value, task_nature, su_money, acceptance_standard, task_description, task_picture_urls, is_reward_take, create_time, rob_info, bid_info, participants, task_percentage, solve_report, solve_picture_urls",
  41 + task.TaskName, task.TaskType, task.Sponsor, task.TaskStatus, task.ReferenceResource, pg.Array(task.CustomerValue), task.TaskNature, task.SuMoney, task.AcceptanceStandard, task.TaskDescription, pg.Array(task.TaskPictureUrls), task.IsRewardTake, task.CreateTime, task.RobInfo, task.BidInfo, pg.Array(task.Participants), pg.Array(task.TaskPercentage), task.SolveReport, pg.Array(task.SolvePictureUrls), task.Identify()); err != nil {
  42 + return task, err
  43 + }
  44 + }
  45 + return task, nil
  46 +}
  47 +func (repository *TaskRepository) Remove(task *domain.Task) (*domain.Task, error) {
  48 + tx := repository.transactionContext.PgTx
  49 + taskModel := new(models.Task)
  50 + taskModel.Id = task.Identify().(int64)
  51 + if _, err := tx.Model(taskModel).WherePK().Delete(); err != nil {
  52 + return task, err
  53 + }
  54 + return task, nil
  55 +}
  56 +func (repository *TaskRepository) FindOne(queryOptions map[string]interface{}) (*domain.Task, error) {
  57 + tx := repository.transactionContext.PgTx
  58 + taskModel := new(models.Task)
  59 + query := tx.Model(taskModel)
  60 + if taskId, ok := queryOptions["taskId"]; ok {
  61 + query = query.Where("task.id = ?", taskId)
  62 + }
  63 + if err := query.Limit(1).Select(); err != nil {
  64 + return nil, err
  65 + }
  66 + if taskModel.Id == 0 {
  67 + return nil, nil
  68 + } else {
  69 + return &domain.Task{
  70 + TakeId: taskModel.Id,
  71 + TaskName: taskModel.TaskName,
  72 + TaskType: taskModel.TaskType,
  73 + Sponsor: taskModel.Sponsor,
  74 + TaskStatus: taskModel.TaskStatus,
  75 + ReferenceResource: taskModel.ReferenceResource,
  76 + CustomerValue: taskModel.CustomerValue,
  77 + TaskNature: taskModel.TaskNature,
  78 + SuMoney: taskModel.SuMoney,
  79 + AcceptanceStandard: taskModel.AcceptanceStandard,
  80 + TaskDescription: taskModel.TaskDescription,
  81 + TaskPictureUrls: taskModel.TaskPictureUrls,
  82 + IsRewardTake: taskModel.IsRewardTake,
  83 + CreateTime: taskModel.CreateTime,
  84 + RobInfo: taskModel.RobInfo,
  85 + BidInfo: taskModel.BidInfo,
  86 + Participants: taskModel.Participants,
  87 + TaskPercentage: taskModel.TaskPercentage,
  88 + SolveReport: taskModel.SolveReport,
  89 + SolvePictureUrls: taskModel.SolvePictureUrls,
  90 + }, nil
  91 + }
  92 +}
  93 +func (repository *TaskRepository) Find(queryOptions map[string]interface{}) (int64, []*domain.Task, error) {
  94 + tx := repository.transactionContext.PgTx
  95 + var taskModels []*models.Task
  96 + var tasks []*domain.Task
  97 + query := tx.Model(&taskModels)
  98 + if offset, ok := queryOptions["offset"]; ok {
  99 + offset := offset.(int)
  100 + if offset > -1 {
  101 + query = query.Offset(offset)
  102 + }
  103 + } else {
  104 + query = query.Offset(0)
  105 + }
  106 + if limit, ok := queryOptions["limit"]; ok {
  107 + limit := limit.(int)
  108 + if limit > -1 {
  109 + query = query.Limit(limit)
  110 + }
  111 + } else {
  112 + query = query.Limit(20)
  113 + }
  114 + if count, err := query.Order("id DESC").SelectAndCount(); err != nil {
  115 + return 0, nil, err
  116 + } else {
  117 + for _, taskModel := range taskModels {
  118 + tasks = append(tasks, &domain.Task{
  119 + TakeId: taskModel.Id,
  120 + TaskName: taskModel.TaskName,
  121 + TaskType: taskModel.TaskType,
  122 + Sponsor: taskModel.Sponsor,
  123 + TaskStatus: taskModel.TaskStatus,
  124 + ReferenceResource: taskModel.ReferenceResource,
  125 + CustomerValue: taskModel.CustomerValue,
  126 + TaskNature: taskModel.TaskNature,
  127 + SuMoney: taskModel.SuMoney,
  128 + AcceptanceStandard: taskModel.AcceptanceStandard,
  129 + TaskDescription: taskModel.TaskDescription,
  130 + TaskPictureUrls: taskModel.TaskPictureUrls,
  131 + IsRewardTake: taskModel.IsRewardTake,
  132 + CreateTime: taskModel.CreateTime,
  133 + RobInfo: taskModel.RobInfo,
  134 + BidInfo: taskModel.BidInfo,
  135 + Participants: taskModel.Participants,
  136 + TaskPercentage: taskModel.TaskPercentage,
  137 + SolveReport: taskModel.SolveReport,
  138 + SolvePictureUrls: taskModel.SolvePictureUrls,
  139 + })
  140 + }
  141 + return int64(count), tasks, nil
  142 + }
  143 +}
  144 +func NewTaskRepository(transactionContext *pgTransaction.TransactionContext) (*TaskRepository, error) {
  145 + if transactionContext == nil {
  146 + return nil, fmt.Errorf("transactionContext参数不能为nil")
  147 + } else {
  148 + return &TaskRepository{
  149 + transactionContext: transactionContext,
  150 + }, nil
  151 + }
  152 +}
  1 +package constant
  2 +
  3 +import (
  4 + "github.com/linmadan/egglib-go/log"
  5 + "github.com/linmadan/egglib-go/log/logrus"
  6 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/constant"
  7 +)
  8 +
  9 +var Logger log.Logger
  10 +
  11 +func init() {
  12 + Logger = logrus.NewLogrusLogger()
  13 + Logger.SetServiceName(constant.SERVICE_NAME)
  14 + Logger.SetLevel(constant.LOG_LEVEL)
  15 +}
  1 +package beego
  2 +
  3 +import (
  4 + "github.com/astaxie/beego"
  5 + "github.com/linmadan/egglib-go/web/beego/filters"
  6 + . "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/log"
  7 + _ "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/port/beego/routers"
  8 +)
  9 +
  10 +func init() {
  11 + beego.InsertFilter("/*", beego.BeforeExec, filters.CreateRequestBodyFilter())
  12 + beego.InsertFilter("/*", beego.BeforeExec, filters.CreateRequstLogFilter(Logger))
  13 + beego.InsertFilter("/*", beego.AfterExec, filters.CreateResponseLogFilter(Logger), false)
  14 +}
  1 +package controllers
  2 +
  3 +import (
  4 + "encoding/json"
  5 + "github.com/astaxie/beego"
  6 + "github.com/linmadan/egglib-go/web/beego/utils"
  7 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/employee/command"
  8 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/employee/query"
  9 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/application/employee/service"
  10 +)
  11 +
  12 +type EmployeeController struct {
  13 + beego.Controller
  14 +}
  15 +
  16 +func (controller *EmployeeController) CreateEmployee() {
  17 + employeeService := service.NewEmployeeService(nil)
  18 + createEmployeeCommand := &command.CreateEmployeeCommand{}
  19 + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), createEmployeeCommand)
  20 + data, err := employeeService.CreateEmployee(createEmployeeCommand)
  21 + var response utils.JsonResponse
  22 + if err != nil {
  23 + response = utils.ResponseError(controller.Ctx, err)
  24 + } else {
  25 + response = utils.ResponseData(controller.Ctx, data)
  26 + }
  27 + controller.Data["json"] = response
  28 + controller.ServeJSON()
  29 +}
  30 +
  31 +func (controller *EmployeeController) UpdateEmployee() {
  32 + employeeService := service.NewEmployeeService(nil)
  33 + updateEmployeeCommand := &command.UpdateEmployeeCommand{}
  34 + json.Unmarshal(controller.Ctx.Input.GetData("requestBody").([]byte), updateEmployeeCommand)
  35 + uid, _ := controller.GetInt64(":uid")
  36 + updateEmployeeCommand.Uid = uid
  37 + data, err := employeeService.UpdateEmployee(updateEmployeeCommand)
  38 + var response utils.JsonResponse
  39 + if err != nil {
  40 + response = utils.ResponseError(controller.Ctx, err)
  41 + } else {
  42 + response = utils.ResponseData(controller.Ctx, data)
  43 + }
  44 + controller.Data["json"] = response
  45 + controller.ServeJSON()
  46 +}
  47 +
  48 +func (controller *EmployeeController) GetEmployee() {
  49 + employeeService := service.NewEmployeeService(nil)
  50 + getEmployeeQuery := &query.GetEmployeeQuery{}
  51 + uid, _ := controller.GetInt64(":uid")
  52 + getEmployeeQuery.Uid = uid
  53 + data, err := employeeService.GetEmployee(getEmployeeQuery)
  54 + var response utils.JsonResponse
  55 + if err != nil {
  56 + response = utils.ResponseError(controller.Ctx, err)
  57 + } else {
  58 + response = utils.ResponseData(controller.Ctx, data)
  59 + }
  60 + controller.Data["json"] = response
  61 + controller.ServeJSON()
  62 +}
  63 +
  64 +func (controller *EmployeeController) RemoveEmployee() {
  65 + employeeService := service.NewEmployeeService(nil)
  66 + removeEmployeeCommand := &command.RemoveEmployeeCommand{}
  67 + uid, _ := controller.GetInt64(":uid")
  68 + removeEmployeeCommand.Uid = uid
  69 + data, err := employeeService.RemoveEmployee(removeEmployeeCommand)
  70 + var response utils.JsonResponse
  71 + if err != nil {
  72 + response = utils.ResponseError(controller.Ctx, err)
  73 + } else {
  74 + response = utils.ResponseData(controller.Ctx, data)
  75 + }
  76 + controller.Data["json"] = response
  77 + controller.ServeJSON()
  78 +}
  79 +
  80 +func (controller *EmployeeController) ListEmployee() {
  81 + employeeService := service.NewEmployeeService(nil)
  82 + listEmployeeQuery := &query.ListEmployeeQuery{}
  83 + offset, _ := controller.GetInt("offset")
  84 + listEmployeeQuery.Offset = offset
  85 + limit, _ := controller.GetInt("limit")
  86 + listEmployeeQuery.Limit = limit
  87 + data, err := employeeService.ListEmployee(listEmployeeQuery)
  88 + var response utils.JsonResponse
  89 + if err != nil {
  90 + response = utils.ResponseError(controller.Ctx, err)
  91 + } else {
  92 + response = utils.ResponseData(controller.Ctx, data)
  93 + }
  94 + controller.Data["json"] = response
  95 + controller.ServeJSON()
  96 +}
  1 +package routers
  2 +
  3 +import (
  4 + "github.com/astaxie/beego"
  5 + "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/port/beego/controllers"
  6 +)
  7 +
  8 +func init() {
  9 + beego.Router("/employees/", &controllers.EmployeeController{}, "Post:CreateEmployee")
  10 + beego.Router("/employees/:uid", &controllers.EmployeeController{}, "Put:UpdateEmployee")
  11 + beego.Router("/employees/:uid", &controllers.EmployeeController{}, "Get:GetEmployee")
  12 + beego.Router("/employees/:uid", &controllers.EmployeeController{}, "Delete:RemoveEmployee")
  13 + beego.Router("/employees/", &controllers.EmployeeController{}, "Get:ListEmployee")
  14 +}
  1 +package employee
  2 +
  3 +import (
  4 + "github.com/gavv/httpexpect"
  5 + . "github.com/onsi/ginkgo"
  6 + . "github.com/onsi/gomega"
  7 + pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
  8 + "net/http"
  9 +)
  10 +
  11 +var _ = Describe("创建新员工", func() {
  12 + Describe("提交数据创建新员工", func() {
  13 + Context("提交正确的新员工数据", func() {
  14 + It("返回员工数据", func() {
  15 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  16 + body := map[string]interface{}{
  17 + "uid": 123456,
  18 + "employeeName": "蔡晓生",
  19 + "employeeAccount": "13799999999",
  20 + }
  21 + httpExpect.POST("/employees/").
  22 + WithJSON(body).
  23 + Expect().
  24 + Status(http.StatusOK).
  25 + JSON().
  26 + Object().
  27 + ContainsKey("code").ValueEqual("code", 0).
  28 + ContainsKey("msg").ValueEqual("msg", "ok").
  29 + ContainsKey("data").Value("data").Object().
  30 + ContainsKey("employeeId").ValueNotEqual("employeeId", BeZero())
  31 + })
  32 + })
  33 + })
  34 + AfterEach(func() {
  35 + _, err := pG.DB.Exec("DELETE FROM employees WHERE true")
  36 + Expect(err).NotTo(HaveOccurred())
  37 + })
  38 +})
  1 +package employee
  2 +
  3 +import (
  4 + "net/http"
  5 + "net/http/httptest"
  6 + "testing"
  7 +
  8 + "github.com/astaxie/beego"
  9 + . "github.com/onsi/ginkgo"
  10 + . "github.com/onsi/gomega"
  11 + _ "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
  12 + _ "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/port/beego"
  13 +)
  14 +
  15 +func TestEmployee(t *testing.T) {
  16 + RegisterFailHandler(Fail)
  17 + RunSpecs(t, "Beego Port Employee Correlations Test Case Suite")
  18 +}
  19 +
  20 +var handler http.Handler
  21 +var server *httptest.Server
  22 +
  23 +var _ = BeforeSuite(func() {
  24 + handler = beego.BeeApp.Handlers
  25 + server = httptest.NewServer(handler)
  26 +})
  27 +
  28 +var _ = AfterSuite(func() {
  29 + server.Close()
  30 +})
  1 +package employee
  2 +
  3 +import (
  4 + "github.com/gavv/httpexpect"
  5 + "github.com/go-pg/pg"
  6 + . "github.com/onsi/ginkgo"
  7 + . "github.com/onsi/gomega"
  8 + pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
  9 + "net/http"
  10 +)
  11 +
  12 +var _ = Describe("返回员工", func() {
  13 + var employeeId int64
  14 + BeforeEach(func() {
  15 + _, err := pG.DB.QueryOne(
  16 + pg.Scan(&employeeId),
  17 + "INSERT INTO employees (id, uid, employee_name, employee_account, su_money) VALUES (?, ?, ?, ?, ?) RETURNING id",
  18 + 1, 123456, "testEmployeeName", "testEmployeeAccount", 0)
  19 + Expect(err).NotTo(HaveOccurred())
  20 + })
  21 + Describe("根据uid参数返回员工", func() {
  22 + Context("传入有效的uid", func() {
  23 + It("返回员工数据", func() {
  24 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  25 + httpExpect.GET("/employees/123456").
  26 + Expect().
  27 + Status(http.StatusOK).
  28 + JSON().
  29 + Object().
  30 + ContainsKey("code").ValueEqual("code", 0).
  31 + ContainsKey("msg").ValueEqual("msg", "ok").
  32 + ContainsKey("data").Value("data").Object()
  33 + })
  34 + })
  35 + })
  36 + AfterEach(func() {
  37 + _, err := pG.DB.Exec("DELETE FROM employees WHERE true")
  38 + Expect(err).NotTo(HaveOccurred())
  39 + })
  40 +})
  1 +package employee
  2 +
  3 +import (
  4 + "github.com/gavv/httpexpect"
  5 + "github.com/go-pg/pg"
  6 + . "github.com/onsi/ginkgo"
  7 + . "github.com/onsi/gomega"
  8 + pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
  9 + "net/http"
  10 +)
  11 +
  12 +var _ = Describe("返回员工列表", func() {
  13 + var employeeId int64
  14 + BeforeEach(func() {
  15 + _, err := pG.DB.QueryOne(
  16 + pg.Scan(&employeeId),
  17 + "INSERT INTO employees (id, uid, employee_name, employee_account, su_money) VALUES (?, ?, ?, ?, ?) RETURNING id",
  18 + 1, 123456, "testEmployeeName", "testEmployeeAccount", 0)
  19 + Expect(err).NotTo(HaveOccurred())
  20 + })
  21 + Describe("根据参数返回员工列表", func() {
  22 + Context("传入有效的参数", func() {
  23 + It("返回员工数据列表", func() {
  24 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  25 + httpExpect.GET("/employees/").
  26 + WithQuery("offset", 0).
  27 + WithQuery("limit", 20).
  28 + Expect().
  29 + Status(http.StatusOK).
  30 + JSON().
  31 + Object().
  32 + ContainsKey("code").ValueEqual("code", 0).
  33 + ContainsKey("msg").ValueEqual("msg", "ok").
  34 + ContainsKey("data").Value("data").Object().
  35 + ContainsKey("count").ValueEqual("count", 1).
  36 + ContainsKey("employees").Value("employees").Array()
  37 + })
  38 + })
  39 + })
  40 + AfterEach(func() {
  41 + _, err := pG.DB.Exec("DELETE FROM employees WHERE true")
  42 + Expect(err).NotTo(HaveOccurred())
  43 + })
  44 +})
  1 +package employee
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/gavv/httpexpect"
  7 + "github.com/go-pg/pg"
  8 + . "github.com/onsi/ginkgo"
  9 + . "github.com/onsi/gomega"
  10 + pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
  11 +)
  12 +
  13 +var _ = Describe("移除员工", func() {
  14 + var employeeId int64
  15 + BeforeEach(func() {
  16 + _, err := pG.DB.QueryOne(
  17 + pg.Scan(&employeeId),
  18 + "INSERT INTO employees (id, uid, employee_name, employee_account, su_money) VALUES (?, ?, ?, ?, ?) RETURNING id",
  19 + 1, 123456, "testEmployeeName", "testEmployeeAccount", 0)
  20 + Expect(err).NotTo(HaveOccurred())
  21 + })
  22 + Describe("根据参数移除员工", func() {
  23 + Context("传入有效的uid", func() {
  24 + It("返回被移除员工的数据", func() {
  25 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  26 + httpExpect.DELETE("/employees/123456").
  27 + Expect().
  28 + Status(http.StatusOK).
  29 + JSON().
  30 + Object().
  31 + ContainsKey("code").ValueEqual("code", 0).
  32 + ContainsKey("msg").ValueEqual("msg", "ok").
  33 + ContainsKey("data").Value("data").Object()
  34 + })
  35 + })
  36 + })
  37 + AfterEach(func() {
  38 + _, err := pG.DB.Exec("DELETE FROM employees WHERE true")
  39 + Expect(err).NotTo(HaveOccurred())
  40 + })
  41 +})
  1 +package employee
  2 +
  3 +import (
  4 + "net/http"
  5 +
  6 + "github.com/gavv/httpexpect"
  7 + "github.com/go-pg/pg"
  8 + . "github.com/onsi/ginkgo"
  9 + . "github.com/onsi/gomega"
  10 + pG "gitlab.fjmaimaimai.com/linmadan/mmm-worth/pkg/infrastructure/pg"
  11 +)
  12 +
  13 +var _ = Describe("更新员工", func() {
  14 + var employeeId int64
  15 + BeforeEach(func() {
  16 + _, err := pG.DB.QueryOne(
  17 + pg.Scan(&employeeId),
  18 + "INSERT INTO employees (id, uid, employee_name, employee_account, su_money) VALUES (?, ?, ?, ?, ?) RETURNING id",
  19 + 1, 123456, "testEmployeeName", "testEmployeeAccount", 0)
  20 + Expect(err).NotTo(HaveOccurred())
  21 + })
  22 + Describe("提交数据更新员工", func() {
  23 + Context("提交正确的员工数据", func() {
  24 + It("返回更新后的员工数据", func() {
  25 + httpExpect := httpexpect.New(GinkgoT(), server.URL)
  26 + body := map[string]interface{}{
  27 + "employeeName": "updateEmployeeName",
  28 + "employeeAccount": "updateEmployeeAccount",
  29 + }
  30 + httpExpect.PUT("/employees/123456").
  31 + WithJSON(body).
  32 + Expect().
  33 + Status(http.StatusOK).
  34 + JSON().
  35 + Object().
  36 + ContainsKey("code").ValueEqual("code", 0).
  37 + ContainsKey("msg").ValueEqual("msg", "ok").
  38 + ContainsKey("data").Value("data").Object().
  39 + ContainsKey("employeeId").ValueEqual("employeeId", employeeId)
  40 + })
  41 + })
  42 + })
  43 + AfterEach(func() {
  44 + _, err := pG.DB.Exec("DELETE FROM employees WHERE true")
  45 + Expect(err).NotTo(HaveOccurred())
  46 + })
  47 +})