作者 Administrator

合并分支 'test' 到 'master'

Test



查看合并请求 !3
正在显示 80 个修改的文件 包含 2938 行增加602 行删除

要显示太多修改。

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

... ... @@ -3,10 +3,12 @@ module gitlab.fjmaimaimai.com/allied-creation/performance
go 1.16
require (
github.com/Andrew-M-C/go.timeconv v0.4.0
github.com/Shopify/sarama v1.25.0
github.com/beego/beego/v2 v2.0.5
github.com/bwmarrin/snowflake v0.3.0
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/go-pg/pg/v10 v10.10.7
github.com/linmadan/egglib-go v0.0.0-20210827085852-177fa745932d
github.com/xuri/excelize/v2 v2.6.1
)
... ...
... ... @@ -31,6 +31,8 @@ cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohl
cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs=
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/Andrew-M-C/go.timeconv v0.4.0 h1:jwSSP1Nru7Hh+XDxIy8Bt/a2kdjqW/xIKkLFhBc/bmA=
github.com/Andrew-M-C/go.timeconv v0.4.0/go.mod h1:qKsoTE6tDyot1aOcAESJA5GBDxl3sns9YesrA8gBLVo=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/Knetic/govaluate v3.0.0+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
... ... @@ -344,6 +346,7 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
... ... @@ -439,7 +442,11 @@ github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a h1:9ZKAASQSHhDYGoxY8uLVpewe1GDZ2vu2Tr/vTdVAkFQ=
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/richardlehane/mscfb v1.0.3/go.mod h1:YzVpcZg9czvAuhk9T+a3avCpcFPMUWm7gK3DypaEsUk=
github.com/richardlehane/mscfb v1.0.4 h1:WULscsljNPConisD5hR0+OyZjwK46Pfyr6mPu5ZawpM=
github.com/richardlehane/mscfb v1.0.4/go.mod h1:YzVpcZg9czvAuhk9T+a3avCpcFPMUWm7gK3DypaEsUk=
github.com/richardlehane/msoleps v1.0.1/go.mod h1:BWev5JBpU9Ko2WAgmZEuiz4/u3ZYTKbjLycmwiWUfWg=
github.com/richardlehane/msoleps v1.0.3 h1:aznSZzrwYRl3rLKRT3gUk9am7T/mLNSnJINvN0AQoVM=
github.com/richardlehane/msoleps v1.0.3/go.mod h1:BWev5JBpU9Ko2WAgmZEuiz4/u3ZYTKbjLycmwiWUfWg=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
... ... @@ -502,7 +509,13 @@ github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c/go.mod h1:lB8K/P019DLNhe
github.com/xdg/stringprep v1.0.0/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xuri/efp v0.0.0-20210322160811-ab561f5b45e3/go.mod h1:ybY/Jr0T0GTCnYjKqmdwxyxn2BQf2RcQIIvex5QldPI=
github.com/xuri/efp v0.0.0-20220603152613-6918739fd470 h1:6932x8ltq1w4utjmfMPVj09jdMlkY0aiA6+Skbtl3/c=
github.com/xuri/efp v0.0.0-20220603152613-6918739fd470/go.mod h1:ybY/Jr0T0GTCnYjKqmdwxyxn2BQf2RcQIIvex5QldPI=
github.com/xuri/excelize/v2 v2.4.1/go.mod h1:rSu0C3papjzxQA3sdK8cU544TebhrPUoTOaGPIh0Q1A=
github.com/xuri/excelize/v2 v2.6.1 h1:ICBdtw803rmhLN3zfvyEGH3cwSmZv+kde7LhTDT659k=
github.com/xuri/excelize/v2 v2.6.1/go.mod h1:tL+0m6DNwSXj/sILHbQTYsLi9IF4TW59H2EF3Yrx1AU=
github.com/xuri/nfp v0.0.0-20220409054826-5e722a1d9e22 h1:OAmKAfT06//esDdpi/DZ8Qsdt4+M5+ltca05dA5bG2M=
github.com/xuri/nfp v0.0.0-20220409054826-5e722a1d9e22/go.mod h1:WwHg+CVyzlv/TX9xqBFXEZAuxOPxn2k1GNHwG41IIUQ=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
... ... @@ -556,8 +569,9 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh
golang.org/x/crypto v0.0.0-20210218145215-b8e89b74b9df/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 h1:7I4JAnoQBe7ZtJcBaYHi5UtiO8tQHbUSXxL+pnGRANg=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.0.0-20220817201139-bc19a97f63c8 h1:GIAS/yBem/gq2MUqgNIzUHW7cJMmx3TGZOrnyYaNQ6c=
golang.org/x/crypto v0.0.0-20220817201139-bc19a97f63c8/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
... ... @@ -571,6 +585,8 @@ golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMk
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20220413100746-70e8d0d3baa9 h1:LRtI4W37N+KFebI/qV0OFiLUv4GLOWeEW5hn/KEJvxE=
golang.org/x/image v0.0.0-20220413100746-70e8d0d3baa9/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
... ... @@ -634,8 +650,10 @@ golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwY
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985 h1:4CSI6oo7cOjJKajidEljs9h+uP0rRZBPPPhcCbj5mw8=
golang.org/x/net v0.0.0-20210726213435-c6fcb2dbf985/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220812174116-3211cb980234 h1:RDqmgfe7SvlMWoqC3xwQ2blLO3fcWcxMa3eBLRdRW7E=
golang.org/x/net v0.0.0-20220812174116-3211cb980234/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
... ... @@ -710,18 +728,21 @@ golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210923061019-b8560ed6a9b7/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9 h1:XfKQ4OlFl8okEOr5UvAqFRVj8pY/4yfcXrddB8qAbU0=
golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 h1:WIoqL4EROvwiPdUtaip4VcDdpZ4kha7wBWZrbVKCIZg=
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
... ... @@ -907,6 +928,7 @@ gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
... ...
不能预览此文件类型
package main
import (
"fmt"
"github.com/beego/beego/v2/server/web"
service "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/node_task"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
_ "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/consumer"
"time"
)
func main() {
tree := web.PrintTree()
methods := tree["Data"].(web.M)
for k, v := range methods {
fmt.Printf("%s => %v \n", k, v)
}
startNodeTask()
// tree := web.PrintTree()
// methods := tree["Data"].(web.M)
// for k, v := range methods {
// fmt.Printf("%s => %v \n", k, v)
// }
go consumer.Run()
web.Run()
}
// 定时任务-间隔发送评估环节
func startNodeTask() {
go func() {
nodeTaskService := service.NewNodeTaskService()
for {
timer := time.NewTimer(time.Second * 60)
<-timer.C
if err := nodeTaskService.SendEvaluationNode(); err != nil {
log.Logger.Error(err.Error())
}
}
}()
}
... ...
... ... @@ -142,6 +142,8 @@ func (srv SyncDataDepartmentService) editDepartment(param *command.EditDepartmen
}
if len(param.ChargeUserIds) > 0 {
departmentList[i].ChargeUserIds = param.ChargeUserIds
} else {
departmentList[i].ChargeUserIds = make([]int64, 0)
}
continue
}
... ...
... ... @@ -2,17 +2,16 @@ package command
import (
"github.com/beego/beego/v2/core/validation"
"time"
)
type CreateCycleCommand struct {
CompanyId int64 `cname:"公司ID" json:"companyId"`
CreatorId int64 `cname:"创建人ID" json:"creatorId"`
Name string `cname:"周期名称" json:"name" valid:"Required"`
TimeStart *time.Time `cname:"起始时间" json:"timeStart"`
TimeEnd *time.Time `cname:"截至时间" json:"timeEnd"`
KpiCycle int `cname:"考核周期(0日、1周、2月)" json:"kpiCycle" valid:"Required"`
TemplateIds []string `cname:"周期使用模板ID" json:"templateIds"`
CompanyId int64 `cname:"公司ID" json:"companyId"`
CreatorId int64 `cname:"创建人ID" json:"creatorId"`
Name string `cname:"周期名称" json:"name" valid:"Required"`
TimeStart string `cname:"起始时间" json:"timeStart"`
TimeEnd string `cname:"截至时间" json:"timeEnd"`
KpiCycle int `cname:"考核周期" json:"kpiCycle" valid:"Required"`
TemplateIds []string `cname:"周期使用模板ID" json:"templateIds"`
}
func (in *CreateCycleCommand) Valid(validation *validation.Validation) {
... ... @@ -25,19 +24,24 @@ func (in *CreateCycleCommand) Valid(validation *validation.Validation) {
return
}
if len(in.Name) > 40 {
validation.SetError("name", "角色名称最大长度40个字符")
validation.SetError("name", "名称最大长度40个字符")
return
}
if in.TimeStart == nil {
if in.KpiCycle == 0 {
validation.SetError("kpiCycle", "请选择考核周期")
return
}
if len(in.TimeStart) == 0 {
validation.SetError("timeStart", "请选择考核周期的开始时间")
return
}
if in.TimeEnd == nil {
if len(in.TimeEnd) == 0 {
validation.SetError("timeEnd", "请选择考核周期的结束时间")
return
}
if len(in.TemplateIds) == 0 {
validation.SetError("templates", "请选择周期内使用的评估模板")
validation.SetError("templates", "请添加评估模板")
return
}
}
... ...
... ... @@ -5,8 +5,21 @@ import "github.com/beego/beego/v2/core/validation"
type QueryCycleCommand struct {
CompanyId int64 `cname:"公司ID" json:"companyId"`
Name string `cname:"周期名称" json:"name"`
PageNumber int `cname:"分页页码" json:"pageNumber" valid:"Required"`
PageSize int `cname:"分页数量" json:"pageSize" valid:"Required"`
PageNumber int64 `cname:"分页页码" json:"pageNumber" valid:"Required"`
PageSize int64 `cname:"分页数量" json:"pageSize" valid:"Required"`
}
type StatisticCycleProjectUserCommand struct {
CompanyId int64 `cname:"公司ID" json:"companyId"`
CycleId int64 `cname:"周期ID" json:"cycleId,string"`
}
type CycleTemplateListCommand struct {
CycleId int64 `cname:"周期ID" json:"cycleId,string" valid:"Required"`
}
type CycleTemplateCommand struct {
Id int64 `cname:"模板ID" json:"id,string" valid:"Required"`
}
func (in *QueryCycleCommand) Valid(validation *validation.Validation) {
... ... @@ -15,3 +28,15 @@ func (in *QueryCycleCommand) Valid(validation *validation.Validation) {
return
}
}
func (in *StatisticCycleProjectUserCommand) Valid(*validation.Validation) {
}
func (in *CycleTemplateListCommand) Valid(*validation.Validation) {
}
func (in *CycleTemplateCommand) Valid(*validation.Validation) {
}
... ...
... ... @@ -2,17 +2,16 @@ package command
import (
"github.com/beego/beego/v2/core/validation"
"time"
)
type UpdateCycleCommand struct {
CompanyId int64 `cname:"公司ID" json:"companyId"`
Id int64 `cname:"周期ID" json:"id,string" valid:"Required"`
Name string `cname:"周期名称" json:"name" valid:"Required"`
TimeStart *time.Time `cname:"起始时间" json:"timeStart"`
TimeEnd *time.Time `cname:"截至时间" json:"timeEnd"`
KpiCycle int `cname:"考核周期(0日、1周、2月)" json:"kpiCycle" valid:"Required"`
TemplateIds []string `cname:"周期使用模板ID" json:"templateIds"`
CompanyId int64 `cname:"公司ID" json:"companyId"`
Id int64 `cname:"周期ID" json:"id,string" valid:"Required"`
Name string `cname:"周期名称" json:"name" valid:"Required"`
TimeStart string `cname:"起始时间" json:"timeStart"`
TimeEnd string `cname:"截至时间" json:"timeEnd"`
KpiCycle int `cname:"考核周期(0日、1周、2月)" json:"kpiCycle" valid:"Required"`
TemplateIds []string `cname:"周期使用模板ID" json:"templateIds"`
}
func (in *UpdateCycleCommand) Valid(validation *validation.Validation) {
... ... @@ -20,11 +19,11 @@ func (in *UpdateCycleCommand) Valid(validation *validation.Validation) {
validation.SetError("name", "角色名称最大长度40个字符")
return
}
if in.TimeStart == nil {
if len(in.TimeStart) == 0 {
validation.SetError("timeStart", "请选择考核周期的开始时间")
return
}
if in.TimeEnd == nil {
if len(in.TimeEnd) == 0 {
validation.SetError("timeEnd", "请选择考核周期的结束时间")
return
}
... ...
... ... @@ -8,6 +8,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"strconv"
"time"
)
type EvaluationCycleService struct {
... ... @@ -30,6 +31,7 @@ func (rs *EvaluationCycleService) Create(in *command.CreateCycleCommand) (interf
cycleRepository := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext})
cycleTemplateRepository := factory.CreateEvaluationCycleTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
templateRepository := factory.CreateEvaluationTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
ruleRepository := factory.CreateEvaluationRuleRepository(map[string]interface{}{"transactionContext": transactionContext})
// 检测名称重复
count, err := cycleRepository.Count(map[string]interface{}{"name": in.Name, "companyId": in.CompanyId})
... ... @@ -37,7 +39,7 @@ func (rs *EvaluationCycleService) Create(in *command.CreateCycleCommand) (interf
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if count > 0 {
return nil, application.ThrowError(application.BUSINESS_ERROR, "名称已存在")
return nil, application.ThrowError(application.BUSINESS_ERROR, "已存在相同名称的周期")
}
_, templates, err := templateRepository.Find(map[string]interface{}{"companyId": in.CompanyId, "ids": in.TemplateIds})
... ... @@ -48,11 +50,21 @@ func (rs *EvaluationCycleService) Create(in *command.CreateCycleCommand) (interf
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "模板不存在, 请重新选择")
}
start, err := time.ParseInLocation("2006-01-02 15:04:05", in.TimeStart, time.Local)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
end, err := time.ParseInLocation("2006-01-02 15:04:05", in.TimeEnd, time.Local)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 生成新周期数据
newCycle := &domain.EvaluationCycle{
Id: 0,
Name: in.Name,
TimeStart: in.TimeStart,
TimeEnd: in.TimeEnd,
TimeStart: &start,
TimeEnd: &end,
CompanyId: in.CompanyId,
CreatorId: in.CreatorId,
KpiCycle: in.KpiCycle,
... ... @@ -62,24 +74,73 @@ func (rs *EvaluationCycleService) Create(in *command.CreateCycleCommand) (interf
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 获取所有模板中的规则对象数据
ruleIdsMap := map[int64]int64{}
for i := range templates {
v := templates[i]
for j := range v.LinkNodes {
node := v.LinkNodes[j]
for k := range node.NodeContents {
nodeContent := node.NodeContents[k]
if nodeContent.RuleId != 0 {
ruleIdsMap[nodeContent.RuleId] = nodeContent.RuleId
}
}
}
}
ruleIds := make([]int64, 0)
for k := range ruleIdsMap {
ruleIds = append(ruleIds, k)
}
_, rules, err := ruleRepository.Find(map[string]interface{}{"ids": ruleIds, "companyId": in.CompanyId})
ruleMap := map[int64]*domain.EvaluationRule{}
for i := range rules {
ruleMap[rules[i].Id] = rules[i]
}
ctAdapter := &adapter.CycleTemplateAdapter{}
ctAdapter.EvaluationCycle = cycle
for i := range templates {
v := templates[i]
// 对评估模板中的评估规则进行数据赋值
for j := range v.LinkNodes {
node := v.LinkNodes[j]
for k := range node.NodeContents {
nodeContent := node.NodeContents[k]
if rule, ok := ruleMap[nodeContent.RuleId]; ok {
nodeContent.Rule = rule
}
}
}
// 周期模板数据表中插入数据
cycleTemplate := &domain.EvaluationCycleTemplate{
Id: 0,
Name: v.Name,
Template: v,
CycleId: cycle.Id,
Id: 0,
Name: v.Name,
TemplateCreatedAt: v.CreatedAt,
Template: v,
CycleId: cycle.Id,
}
_, err := cycleTemplateRepository.Insert(cycleTemplate)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 输出模板简单信息
ctAdapter.TemplateSimples = append(ctAdapter.TemplateSimples, &domain.TemplateSimple{
Id: cycleTemplate.Id,
Name: cycleTemplate.Name,
CreatedAt: cycleTemplate.TemplateCreatedAt, // 模板创建时间
})
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return cycle, nil
return ctAdapter, nil
}
... ... @@ -146,10 +207,11 @@ func (rs *EvaluationCycleService) Update(in *command.UpdateCycleCommand) (interf
for i := range templates {
v := templates[i]
cycleTemplate := &domain.EvaluationCycleTemplate{
Id: 0,
Name: v.Name,
Template: v,
CycleId: cycle.Id,
Id: 0,
Name: v.Name,
TemplateCreatedAt: v.CreatedAt,
Template: v,
CycleId: cycle.Id,
}
_, err := cycleTemplateRepository.Insert(cycleTemplate)
if err != nil {
... ... @@ -158,18 +220,43 @@ func (rs *EvaluationCycleService) Update(in *command.UpdateCycleCommand) (interf
}
}
start, err := time.ParseInLocation("2006-01-02 15:04:05", in.TimeStart, time.Local)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
end, err := time.ParseInLocation("2006-01-02 15:04:05", in.TimeEnd, time.Local)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
cycle.Name = in.Name
cycle.TimeStart = in.TimeStart
cycle.TimeEnd = in.TimeEnd
cycle.TimeStart = &start
cycle.TimeEnd = &end
cycle.KpiCycle = in.KpiCycle
cycle, err = cycleRepository.Insert(cycle)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
_, cycleTemplates, err := cycleTemplateRepository.Find(map[string]interface{}{"cycleId": cycle.Id}, "template")
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
ctAdapter := &adapter.CycleTemplateAdapter{}
ctAdapter.EvaluationCycle = cycle
for i := range cycleTemplates {
ctAdapter.TemplateSimples = append(ctAdapter.TemplateSimples, &domain.TemplateSimple{
Id: cycleTemplates[i].Id,
Name: cycleTemplates[i].Name,
CreatedAt: cycleTemplates[i].TemplateCreatedAt,
})
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return cycle, nil
return ctAdapter, nil
}
func (rs *EvaluationCycleService) Get(in *command.GetCycleCommand) (interface{}, error) {
... ... @@ -199,7 +286,7 @@ func (rs *EvaluationCycleService) Get(in *command.GetCycleCommand) (interface{},
ctAdapter.TemplateSimples = append(ctAdapter.TemplateSimples, &domain.TemplateSimple{
Id: cycleTemplates[i].Id,
Name: cycleTemplates[i].Name,
CreatedAt: cycleTemplates[i].CreatedAt,
CreatedAt: cycleTemplates[i].TemplateCreatedAt,
})
}
... ... @@ -253,5 +340,107 @@ func (rs *EvaluationCycleService) List(in *command.QueryCycleCommand) (interface
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return tool_funs.SimpleWrapGridMap(total, cycles), nil
}
func (rs *EvaluationCycleService) StatisticCycleUser(in *command.StatisticCycleProjectUserCommand) (interface{}, error) {
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext})
_, projects, err := projectRepository.Find(tool_funs.SimpleStructToMap(in), "template")
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
userIds := make([]int64, 0)
userIdMap := map[int64]int64{}
for i := range projects {
project := projects[i]
for j := range project.Recipients {
userId, _ := strconv.ParseInt(project.Recipients[j], 10, 64)
userIdMap[userId] = userId
}
}
for k := range userIdMap {
userIds = append(userIds, k)
}
userTotal := 0
departmentTotal := 0
if len(userIds) > 0 {
userRepository := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
_, users, _ := userRepository.Find(map[string]interface{}{"ids": userIds, "limit": len(userIds)})
departmentIdMap := map[int]int{}
for i := range users {
for _, v := range users[i].DepartmentId {
departmentIdMap[v] = v
}
}
userTotal = len(users)
departmentTotal = len(departmentIdMap)
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return map[string]interface{}{"userTotal": userTotal, "departmentTotal": departmentTotal}, nil
}
func (rs *EvaluationCycleService) CycleTemplateList(in *command.CycleTemplateListCommand) (interface{}, error) {
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
cycleTemplateRepository := factory.CreateEvaluationCycleTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
_, cycleTemplates, err := cycleTemplateRepository.Find(map[string]interface{}{"cycleId": in.CycleId}, "template")
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
list := make([]*domain.TemplateSimple, 0)
for i := range cycleTemplates {
list = append(list, &domain.TemplateSimple{
Id: cycleTemplates[i].Id,
Name: cycleTemplates[i].Name,
CreatedAt: cycleTemplates[i].TemplateCreatedAt,
})
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return map[string]interface{}{"list": list}, nil
}
func (rs *EvaluationCycleService) CycleTemplate(in *command.CycleTemplateCommand) (interface{}, error) {
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
cycleTemplateRepository := factory.CreateEvaluationCycleTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
cycleTemplate, err := cycleTemplateRepository.FindOne(map[string]interface{}{"id": in.Id})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return cycleTemplate.Template, nil
}
... ...
... ... @@ -9,7 +9,7 @@ type CreateProjectCommand struct {
CreatorId int64 `cname:"创建人ID" json:"creatorId"`
CycleId int64 `cname:"周期ID" json:"cycleId,string" valid:"Required"`
Name string `cname:"项目名称" json:"name" valid:"Required"`
Describe string `cname:"项目描述" json:"describe" valid:"Required"`
Describe string `cname:"项目描述" json:"describe"`
HrBp int `cname:"HR角色权限" json:"hrBp"`
Pmp int `cname:"PM角色权限" json:"pmp"`
PmpIds []string `cname:"项目管理员ID" json:"pmpIds"`
... ...
... ... @@ -2,25 +2,19 @@ package command
import (
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
type StateProjectCommand struct {
Id int64 `cname:"项目ID" json:"id,string" valid:"Required"`
State int `cname:"项目状态" json:"state"`
type ActivateProjectCommand struct {
Id int64 `cname:"项目ID" json:"id,string" valid:"Required"`
}
type CopyProjectCommand struct {
Id int64 `cname:"模板ID" json:"id,string" valid:"Required"`
CreatorId int64 `cname:"创建人ID" json:"creatorId"`
Id int64 `cname:"模板ID" json:"id,string" valid:"Required"`
}
func (in *StateProjectCommand) Valid(validation *validation.Validation) {
switch in.State {
case domain.ProjectStateWaitConfig, domain.ProjectStateWaitActive, domain.ProjectStateEnable, domain.ProjectStateDisable:
default:
validation.SetError("state", "状态设置错误")
return
}
func (in *ActivateProjectCommand) Valid(validation *validation.Validation) {
}
func (in *CopyProjectCommand) Valid(*validation.Validation) {
... ...
... ... @@ -8,8 +8,8 @@ type QueryProjectCommand struct {
Name string `cname:"项目名称" json:"name"`
State int `cname:"项目状态" json:"state"`
PmpIds []string `cname:"项目管理员ID" json:"pmpIds"`
PageNumber int `cname:"分页页码" json:"pageNumber" valid:"Required"`
PageSize int `cname:"分页数量" json:"pageSize" valid:"Required"`
PageNumber int64 `cname:"分页页码" json:"pageNumber" valid:"Required"`
PageSize int64 `cname:"分页数量" json:"pageSize" valid:"Required"`
}
func (in *QueryProjectCommand) Valid(validation *validation.Validation) {
... ... @@ -18,12 +18,3 @@ func (in *QueryProjectCommand) Valid(validation *validation.Validation) {
return
}
}
type StatisticCycleProjectUserCommand struct {
CompanyId int64 `cname:"公司ID" json:"companyId"`
CycleId int64 `cname:"周期ID" json:"cycleId,string"`
}
func (in *StatisticCycleProjectUserCommand) Valid(*validation.Validation) {
}
... ...
... ... @@ -2,7 +2,6 @@ package command
import (
"github.com/beego/beego/v2/core/validation"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
type UpdateProjectCommand struct {
... ... @@ -17,22 +16,25 @@ type UpdateProjectCommand struct {
}
type UpdateProjectTemplateCommand struct {
CompanyId int64 `cname:"公司ID" json:"companyId"`
CycleId int64 `cname:"周期ID" json:"cycleId,string" valid:"Required"`
Id int64 `cname:"项目ID" json:"id,string" valid:"Required"`
TemplateId int64 `cname:"模板ID" json:"templateId,string"`
Recipients []string `cname:"被评估人ID" json:"recipients"`
TimeStart string `cname:"自评起始时间" json:"timeStart" valid:"Required"`
TimeEnd string `cname:"自评截止时间" json:"timeEnd" valid:"Required"`
KpiCycle int `cname:"评估周期" json:"kpiCycle" valid:"Required"`
KpiResultStart string `cname:"绩效结果开始查看时间" json:"kpiResultStart"`
Activate int `cname:"启动项目" json:"activate"`
}
type CheckRecipientCommand struct {
CompanyId int64 `cname:"公司ID" json:"companyId"`
CycleId int64 `cname:"周期ID" json:"cycleId,string" valid:"Required"`
Id int64 `cname:"项目ID" json:"id,string" valid:"Required"`
TemplateId int64 `cname:"模板ID" json:"templateId,string"`
Recipients []string `cname:"被评估人ID" json:"recipients"`
}
type UpdateProjectTemplateNodeCommand struct {
CompanyId int64 `cname:"公司ID" json:"companyId"`
CycleId int64 `cname:"周期ID" json:"cycleId,string" valid:"Required"`
Id int64 `cname:"项目ID" json:"id,string" valid:"Required"`
TemplateId int64 `cname:"模板ID" json:"templateId,string" valid:"Required"`
LinkNodes []*domain.LinkNode `cname:"评估流程" json:"linkNodes"`
Activate int `cname:"启动项目" json:"activate"`
}
func (in *UpdateProjectCommand) Valid(validation *validation.Validation) {
if len(in.Name) > 40 {
validation.SetError("name", "项目名称最大长度40个字符")
... ... @@ -45,11 +47,13 @@ func (in *UpdateProjectTemplateCommand) Valid(validation *validation.Validation)
validation.SetError("recipients", "请添加被评估人")
return
}
}
func (in *UpdateProjectTemplateNodeCommand) Valid(validation *validation.Validation) {
if len(in.LinkNodes) == 0 {
validation.SetError("linkNodes", "请添加评估流程")
if len(in.TimeStart) == 0 {
validation.SetError("timeEnd", "请选择开始时间")
return
}
if len(in.TimeEnd) == 0 {
validation.SetError("timeEnd", "请选择结束时间")
return
}
}
... ...
... ... @@ -8,7 +8,9 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/evaluation_project/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/utils"
"strconv"
"time"
)
type EvaluationProjectService struct {
... ... @@ -55,10 +57,19 @@ func (rs *EvaluationProjectService) Create(in *command.CreateProjectCommand) (in
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
projectAdapter := &adapter.EvaluationProjectAdapter{}
projectAdapter.EvaluationProject = project
if len(project.PmpIds) > 0 {
userRepository := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
_, users, _ := userRepository.Find(map[string]interface{}{"ids": project.PmpIds, "limit": len(project.PmpIds)})
projectAdapter.TransformPmpAdapter(users)
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return project, nil
return projectAdapter, nil
}
... ... @@ -96,10 +107,19 @@ func (rs *EvaluationProjectService) Update(in *command.UpdateProjectCommand) (in
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
projectAdapter := &adapter.EvaluationProjectAdapter{}
projectAdapter.EvaluationProject = project
if len(project.PmpIds) > 0 {
userRepository := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
_, users, _ := userRepository.Find(map[string]interface{}{"ids": project.PmpIds, "limit": len(project.PmpIds)})
projectAdapter.TransformPmpAdapter(users)
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return project, nil
return projectAdapter, nil
}
func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemplateCommand) (interface{}, error) {
... ... @@ -112,9 +132,15 @@ func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemp
}()
projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext})
cycleRepository := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext})
cycleTemplateRepository := factory.CreateEvaluationCycleTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
_, projects, err := projectRepository.Find(map[string]interface{}{"companyId": in.CompanyId, "cycleId": in.CycleId}, "linkNodes")
_, projects, err := projectRepository.Find(map[string]interface{}{"companyId": in.CompanyId, "cycleId": in.CycleId}, "template")
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
cycle, err := cycleRepository.FindOne(map[string]interface{}{"id": in.CycleId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ... @@ -145,48 +171,64 @@ func (rs *EvaluationProjectService) UpdateTemplate(in *command.UpdateProjectTemp
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
cycleTemplate, err := cycleTemplateRepository.FindOne(map[string]interface{}{"id": in.TemplateId, "includeDeleted": true})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
project.Recipients = in.Recipients
project.Template = cycleTemplate.Template
if cycleTemplate == nil || cycleTemplate.Template == nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, "请添加模板")
}
project, err = projectRepository.Insert(project)
if len(in.Recipients) == 0 {
return nil, application.ThrowError(application.BUSINESS_ERROR, "请添加被评估人")
}
start, err := time.ParseInLocation("2006-01-02 15:04:05", in.TimeStart, time.Local)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
end, err := time.ParseInLocation("2006-01-02 15:04:05", in.TimeEnd, time.Local)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return project, nil
}
func (rs *EvaluationProjectService) UpdateTemplateNode(in *command.UpdateProjectTemplateNodeCommand) (interface{}, error) {
transactionContext, err := factory.ValidateStartTransaction(in)
kpiStart, err := time.ParseInLocation("2006-01-02 15:04:05", in.KpiResultStart, time.Local)
if err != nil {
return nil, err
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
defer func() {
transactionContext.RollbackTransaction()
}()
projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext})
minTime := cycle.TimeStart.Local()
maxTime := cycle.TimeEnd.Local()
project, err := projectRepository.FindOne(map[string]interface{}{"id": in.Id})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
if start.Before(minTime) {
return nil, application.ThrowError(application.BUSINESS_ERROR, "评估起始时间不能超出周期起始时间")
}
// FIXME 启动时,需要激活定时任务
if in.Activate == 1 {
project.State = domain.ProjectStateEnable
if end.After(maxTime) {
return nil, application.ThrowError(application.BUSINESS_ERROR, "评估截至时间不能超出周期截至时间")
}
for i := range in.LinkNodes {
project.Template.LinkNodes[i].TimeStart = in.LinkNodes[i].TimeStart
project.Template.LinkNodes[i].TimeEnd = in.LinkNodes[i].TimeEnd
project.Template.LinkNodes[i].KpiCycle = in.LinkNodes[i].KpiCycle
//// FIXME 启动时,需要激活定时任务
//if in.Activate == 1 {
// project.State = domain.ProjectStateEnable
//} else {
// project.State = domain.ProjectStateWaitActive
//}
project.State = domain.ProjectStateWaitActive
project.Recipients = in.Recipients
project.Template = cycleTemplate.Template
for i := range project.Template.LinkNodes {
node := project.Template.LinkNodes[i]
node.KpiCycle = in.KpiCycle // 设置周期
if node.Type == domain.LinkNodeViewResult {
node.TimeStart = &kpiStart
node.TimeEnd = &maxTime // 绩效查看时间跟随周期截止时间
} else {
node.TimeStart = &start
node.TimeEnd = &end
}
}
project, err = projectRepository.Insert(project)
... ... @@ -268,7 +310,7 @@ func (rs *EvaluationProjectService) List(in *command.QueryProjectCommand) (inter
}()
projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext})
total, projects, err := projectRepository.Find(tool_funs.SimpleStructToMap(in), "linkNodes")
total, projects, err := projectRepository.Find(tool_funs.SimpleStructToMap(in), "template")
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ... @@ -290,7 +332,7 @@ func (rs *EvaluationProjectService) List(in *command.QueryProjectCommand) (inter
return tool_funs.SimpleWrapGridMap(total, projectAdapters), nil
}
func (rs *EvaluationProjectService) State(in *command.StateProjectCommand) (interface{}, error) {
func (rs *EvaluationProjectService) Activate(in *command.ActivateProjectCommand) (interface{}, error) {
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, err
... ... @@ -300,23 +342,122 @@ func (rs *EvaluationProjectService) State(in *command.StateProjectCommand) (inte
}()
projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext})
//cycleRepository := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext})
project, err := projectRepository.FindOne(map[string]interface{}{"id": in.Id})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
project.State = in.State
if project.Template == nil {
return nil, application.ThrowError(application.BUSINESS_ERROR, "请添加评估模板")
}
if len(project.Recipients) == 0 {
return nil, application.ThrowError(application.BUSINESS_ERROR, "请添加被评估人")
}
if project.State == domain.TemplateStateEnable {
return nil, application.ThrowError(application.BUSINESS_ERROR, "项目已启动")
}
//cycle, err := cycleRepository.FindOne(map[string]interface{}{"id": project.CycleId})
//if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
//}
//startMin := cycle.TimeStart
//maxTime := cycle.TimeEnd
project.State = domain.TemplateStateEnable
project, err = projectRepository.Insert(project)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
taskRepository := factory.CreateNodeTaskRepository(map[string]interface{}{"transactionContext": transactionContext})
now := time.Now().Local()
nowO := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.Local) // 当前时间0点0分0秒时刻
for i := range project.Template.LinkNodes {
node := project.Template.LinkNodes[i]
task := &domain.NodeTask{
Id: 0,
CompanyId: project.CompanyId,
CycleId: project.CycleId,
ProjectId: project.Id,
NodeId: node.Id,
NodeType: node.Type,
NodeName: node.Name,
NodeDescribe: node.Describe,
NodeSort: i + 1,
TimeStart: node.TimeStart,
TimeEnd: node.TimeEnd,
KpiCycle: node.KpiCycle,
}
// 环节起始和截止本地时间
startLocal := node.TimeStart.Local()
endLocal := node.TimeEnd.Local()
// 在当前时间之前,则计算下一个周期时间
if startLocal.Before(now) {
nextTime := utils.NextTime(nowO, startLocal, node.KpiCycle)
task.NextSentAt = &nextTime
} else {
task.NextSentAt = &startLocal
}
// 如果超出截至时间,则周期置空
if task.NextSentAt.After(endLocal) {
task.NextSentAt = nil
}
task, err := taskRepository.Insert(task)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return project, nil
}
//
//// 0点时刻为标准计算
//func (rs *EvaluationProjectService) nextTime(now0 time.Time, start *time.Time, kpiCycle int) time.Time {
// // 起始时间0点时刻
// start0 := time.Date(start.Year(), start.Month(), start.Day(), 0, 0, 0, 0, time.Local)
//
// var nextTime time.Time
// switch kpiCycle {
// case domain.KpiCycleDay:
// nextTime = timeconv.AddDate(now0, 0, 0, 1) // 当前时间的下一天开始发送
// break
// case domain.KpiCycleWeek:
// offsetSeconds := int64(now0.Sub(start0).Seconds())
// offsetDay := offsetSeconds / (24 * 60 * 60)
// cycleCount := int(offsetDay)/7 + 1
// nextTime = timeconv.AddDate(start0, 0, 0, cycleCount*7)
// break
// case domain.KpiCycleOneMonth:
// nextTime = timeconv.AddDate(start0, 0, 1, 0)
// break
// case domain.KpiCycleTwoMonth:
// nextTime = timeconv.AddDate(start0, 0, 2, 0)
// break
// case domain.KpiCycleThreeMonth:
// nextTime = timeconv.AddDate(start0, 0, 3, 0)
// break
// case domain.KpiCycleSixMonth:
// nextTime = timeconv.AddDate(start0, 0, 6, 0)
// break
// case domain.KpiCycleYear:
// nextTime = timeconv.AddDate(start0, 1, 0, 0)
// break
// }
// return nextTime
//}
func (rs *EvaluationProjectService) Copy(in *command.CopyProjectCommand) (interface{}, error) {
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
... ... @@ -332,6 +473,10 @@ func (rs *EvaluationProjectService) Copy(in *command.CopyProjectCommand) (interf
}
// ID重置
project.Id = 0
project.Name = project.Name + " 副本"
project.CreatorId = in.CreatorId
project.Recipients = make([]string, 0) // 重置被评估人
// 如果拷贝已经启用的模板,默认先设置为待启用
if project.State == domain.ProjectStateEnable {
project.State = domain.ProjectStateWaitActive
... ... @@ -346,7 +491,7 @@ func (rs *EvaluationProjectService) Copy(in *command.CopyProjectCommand) (interf
return project, nil
}
func (rs *EvaluationProjectService) StatisticCycleUser(in *command.StatisticCycleProjectUserCommand) (interface{}, error) {
func (rs *EvaluationProjectService) CheckRecipients(in *command.CheckRecipientCommand) (interface{}, error) {
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, err
... ... @@ -354,42 +499,41 @@ func (rs *EvaluationProjectService) StatisticCycleUser(in *command.StatisticCycl
defer func() {
transactionContext.RollbackTransaction()
}()
projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext})
_, projects, err := projectRepository.Find(tool_funs.SimpleStructToMap(in), "linkNodes")
_, projects, err := projectRepository.Find(map[string]interface{}{"companyId": in.CompanyId, "cycleId": in.CycleId}, "template")
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
userIds := make([]int64, 0)
userIdMap := map[int64]int64{}
// 周期内的所有项目,员工不能重复被评估
rids := map[string]bool{}
for i := range projects {
project := projects[i]
for j := range project.Recipients {
userId, _ := strconv.ParseInt(project.Recipients[j], 10, 64)
userIdMap[userId] = userId
// 排除当前项目
if in.Id != projects[i].Id {
ids := projects[i].Recipients
for j := range ids {
rids[ids[j]] = true
}
}
}
for _, v := range userIdMap {
userIds = append(userIds, v)
}
userTotal := 0
departmentTotal := 0
if len(userIds) > 0 {
userRepository := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
_, users, _ := userRepository.Find(map[string]interface{}{"ids": userIds, "limit": len(userIds)})
departmentIdMap := map[int]int{}
for i := range users {
for _, v := range users[i].DepartmentId {
departmentIdMap[v] = v
}
repeatNum := 0
for i := range in.Recipients {
id := in.Recipients[i]
if _, ok := rids[id]; ok {
repeatNum++
}
userTotal = len(users)
departmentTotal = len(departmentIdMap)
}
//if repeatNum > 0 {
// return nil, application.ThrowError(application.BUSINESS_ERROR, fmt.Sprintf("有%d人已经在本周期其他项目内,需要将他们移除", repeatNum))
//}
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return map[string]interface{}{"userTotal": userTotal, "departmentTotal": departmentTotal}, nil
return map[string]interface{}{"repeatNum": repeatNum}, nil
}
... ...
... ... @@ -8,3 +8,8 @@ type RuleAdapter struct {
*domain.EvaluationRule
CreatorName string `json:"creatorName" comment:"创建人名称"`
}
type CreatorAdapter struct {
Id int64 `json:"id,string" comment:"创建人ID"`
Name string `json:"name" comment:"创建人名称"`
}
... ...
... ... @@ -7,8 +7,12 @@ type QueryRuleCommand struct {
NameOrRemark string `cname:"规则名称或备注" json:"nameOrRemark"`
Type int `cname:"评估方式(0评级、1评分)" json:"type"`
CreatorId int64 `cname:"创建人ID" json:"creatorId,string"`
PageNumber int `cname:"分页页码" json:"pageNumber" valid:"Required"`
PageSize int `cname:"分页数量" json:"pageSize" valid:"Required"`
PageNumber int64 `cname:"分页页码" json:"pageNumber" valid:"Required"`
PageSize int64 `cname:"分页数量" json:"pageSize" valid:"Required"`
}
type QueryCreatorCommand struct {
CompanyId int64 `cname:"公司ID" json:"companyId"`
}
func (in *QueryRuleCommand) Valid(validation *validation.Validation) {
... ... @@ -17,3 +21,10 @@ func (in *QueryRuleCommand) Valid(validation *validation.Validation) {
return
}
}
func (in *QueryCreatorCommand) Valid(validation *validation.Validation) {
if in.CompanyId == 0 {
validation.SetError("companyId", "公司ID无效")
return
}
}
... ...
... ... @@ -8,7 +8,6 @@ import (
type UpdateRuleCommand struct {
Id int64 `cname:"规则ID" json:"id,string" valid:"Required"`
CompanyId int64 `cname:"公司ID" json:"companyId"`
CreatorId int64 `cname:"创建人ID" json:"creatorId"`
Name string `cname:"规则名称" json:"name" valid:"Required"`
Remark string `cname:"规则备注" json:"remark"`
Type int `cname:"评估方式" json:"type"`
... ... @@ -21,10 +20,6 @@ func (in *UpdateRuleCommand) Valid(validation *validation.Validation) {
validation.SetError("companyId", "公司ID无效")
return
}
if in.CreatorId == 0 {
validation.SetError("creatorId", "创建人ID无效")
return
}
if len(in.Name) > 40 {
validation.SetError("name", "名称最大长度40个字符")
... ...
... ... @@ -35,7 +35,7 @@ func (rs *EvaluationRuleService) Create(in *command.CreateRuleCommand) (interfac
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if count > 0 {
return nil, application.ThrowError(application.BUSINESS_ERROR, "名称已存在")
return nil, application.ThrowError(application.BUSINESS_ERROR, "已存在相同名称的评估规则")
}
if in.Type == domain.EvaluationTypeRating { // 按等级量化值排序
... ... @@ -82,7 +82,7 @@ func (rs *EvaluationRuleService) Update(in *command.UpdateRuleCommand) (interfac
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if count > 0 {
return nil, application.ThrowError(application.BUSINESS_ERROR, "名称已存在")
return nil, application.ThrowError(application.BUSINESS_ERROR, "已存在相同名称的评估规则")
}
rule, err := ruleRepository.FindOne(map[string]interface{}{"id": in.Id})
... ... @@ -212,3 +212,40 @@ func (rs *EvaluationRuleService) ListRelCreator(in *command.QueryRuleCommand) (i
}
return tool_funs.SimpleWrapGridMap(total, ras), nil
}
func (rs *EvaluationRuleService) ListCreator(in *command.QueryCreatorCommand) (interface{}, error) {
transactionContext, err := factory.StartTransaction()
if err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
ruleRepository := factory.CreateEvaluationRuleRepository(map[string]interface{}{"transactionContext": transactionContext})
userRepository := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
_, rules, err := ruleRepository.Find(tool_funs.SimpleStructToMap(in))
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 获取所有创建人ID
creatorMap := map[int64]int64{}
for i := range rules {
creatorMap[rules[i].CreatorId] = rules[i].CreatorId
}
creatorIds := make([]int64, 0)
for k := range creatorMap {
creatorIds = append(creatorIds, k)
}
_, users, _ := userRepository.Find(map[string]interface{}{"ids": creatorIds, "limit": len(creatorIds)})
cas := make([]*adapter.CreatorAdapter, 0)
for i := range users {
ca := &adapter.CreatorAdapter{
Id: users[i].Id,
Name: users[i].Name,
}
cas = append(cas, ca)
}
return map[string]interface{}{"list": cas}, nil
}
... ...
... ... @@ -2,16 +2,15 @@ package command
import (
"github.com/beego/beego/v2/core/validation"
"time"
)
type QueryTemplateCommand struct {
CompanyId int64 `cname:"公司ID" json:"companyId"`
Name string `cname:"模板名称" json:"name"`
State int `cname:"模板状态" json:"state"`
CreatedAt *time.Time `cname:"创建时间" json:"createdAt"`
PageNumber int `cname:"分页页码" json:"pageNumber" valid:"Required"`
PageSize int `cname:"分页数量" json:"pageSize" valid:"Required"`
CompanyId int64 `cname:"公司ID" json:"companyId"`
Name string `cname:"模板名称" json:"name"`
State int `cname:"模板状态" json:"state"`
CreatedAt string `cname:"创建时间" json:"createdAt"`
PageNumber int64 `cname:"分页页码" json:"pageNumber" valid:"Required"`
PageSize int64 `cname:"分页数量" json:"pageSize" valid:"Required"`
}
func (in *QueryTemplateCommand) Valid(validation *validation.Validation) {
... ... @@ -20,15 +19,3 @@ func (in *QueryTemplateCommand) Valid(validation *validation.Validation) {
return
}
}
//// AllEnableTemplateCommand 查询所有已启用的模板
//type AllEnableTemplateCommand struct {
// CompanyId int64 `cname:"公司ID" json:"companyId"`
//}
//
//func (in *AllEnableTemplateCommand) Valid(validation *validation.Validation) {
// if in.CompanyId == 0 {
// validation.SetError("companyId", "公司ID无效")
// return
// }
//}
... ...
... ... @@ -6,11 +6,12 @@ import (
)
type UpdateTemplateCommand struct {
Id int64 `cname:"模板ID" json:"id,string" valid:"Required"`
CompanyId int64 `cname:"公司ID" json:"companyId"`
Name string `cname:"模板名称" json:"name" valid:"Required"`
Describe string `cname:"模板描述" json:"describe"`
LinkNodes []*domain.LinkNode `cname:"评估流程" json:"linkNodes"`
Id int64 `cname:"模板ID" json:"id,string" valid:"Required"`
CompanyId int64 `cname:"公司ID" json:"companyId"`
Name string `cname:"模板名称" json:"name" valid:"Required"`
Describe string `cname:"模板描述" json:"describe"`
LinkNodes []*domain.LinkNode `cname:"评估流程" json:"linkNodes"`
FinishConfig int `cname:"配置" json:"finishConfig"`
}
func (in *UpdateTemplateCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -34,41 +34,46 @@ func (rs *EvaluationTemplateService) Create(in *command.CreateTemplateCommand) (
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if count > 0 {
return nil, application.ThrowError(application.BUSINESS_ERROR, "名称已存在")
return nil, application.ThrowError(application.BUSINESS_ERROR, "已存在相同名称的评估模板")
}
linkNodes := make([]*domain.LinkNode, 0)
sid, _ := utils.NewSnowflakeId()
linkNodes = append(linkNodes, &domain.LinkNode{
Id: sid + 1,
Type: domain.LinkNodeSelfAssessment,
Name: "填写自评反馈",
KpiCycle: domain.KpiCycleDay,
Id: sid + 1,
Type: domain.LinkNodeSelfAssessment,
Name: "填写自评反馈",
NodeContents: make([]*domain.NodeContent, 0),
KpiCycle: domain.KpiCycleDay,
})
linkNodes = append(linkNodes, &domain.LinkNode{
Id: sid + 2,
Type: domain.LinkNodeAllInvite,
Name: "360°邀请",
KpiCycle: domain.KpiCycleDay,
Id: sid + 2,
Type: domain.LinkNodeAllInvite,
Name: "360°邀请",
NodeContents: make([]*domain.NodeContent, 0),
KpiCycle: domain.KpiCycleDay,
})
linkNodes = append(linkNodes, &domain.LinkNode{
Id: sid + 3,
Type: domain.LinkNodeAllAssessment,
Name: "360°评估",
KpiCycle: domain.KpiCycleDay,
Id: sid + 3,
Type: domain.LinkNodeAllAssessment,
Name: "360°评估",
NodeContents: make([]*domain.NodeContent, 0),
KpiCycle: domain.KpiCycleDay,
})
linkNodes = append(linkNodes, &domain.LinkNode{
Id: sid + 4,
Type: domain.LinkNodeSuperiorAssessment,
Name: "上级评估",
KpiCycle: domain.KpiCycleDay,
Id: sid + 4,
Type: domain.LinkNodeSuperiorAssessment,
Name: "上级评估",
NodeContents: make([]*domain.NodeContent, 0),
KpiCycle: domain.KpiCycleDay,
})
linkNodes = append(linkNodes, &domain.LinkNode{
Id: sid + 5,
Type: domain.LinkNodeViewResult,
Name: "绩效结果查看",
KpiCycle: domain.KpiCycleDay,
Id: sid + 5,
Type: domain.LinkNodeViewResult,
Name: "绩效结果查看",
NodeContents: make([]*domain.NodeContent, 0),
KpiCycle: domain.KpiCycleDay,
})
newTemplate := &domain.EvaluationTemplate{
... ... @@ -120,6 +125,11 @@ func (rs *EvaluationTemplateService) Update(in *command.UpdateTemplateCommand) (
template.Describe = in.Describe
template.LinkNodes = in.LinkNodes
// 完成配置保存,更新状态
if in.FinishConfig == 1 && template.State == domain.TemplateStateWaitConfig {
template.State = domain.TemplateStateWaitActive
}
template, err = templateRepository.Insert(template)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ... @@ -183,8 +193,14 @@ func (rs *EvaluationTemplateService) List(in *command.QueryTemplateCommand) (int
defer func() {
transactionContext.RollbackTransaction()
}()
queryOptions := tool_funs.SimpleStructToMap(in)
if len(in.CreatedAt) == 0 {
delete(queryOptions, "createdAt") // 删除创建时间
}
templateRepository := factory.CreateEvaluationTemplateRepository(map[string]interface{}{"transactionContext": transactionContext})
total, templates, err := templateRepository.Find(tool_funs.SimpleStructToMap(in), "linkNodes")
total, templates, err := templateRepository.Find(queryOptions, "link_nodes")
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ...
... ... @@ -129,6 +129,14 @@ func CreateEvaluationProjectRepository(options map[string]interface{}) domain.Ev
return repository.NewEvaluationProjectRepository(transactionContext)
}
func CreateNodeTaskRepository(options map[string]interface{}) domain.NodeTaskRepository {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewNodeTaskRepository(transactionContext)
}
func CreateStaffAssessRepository(options map[string]interface{}) domain.StaffAssessRepository {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
... ...
package service
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
"strconv"
"time"
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/service"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/utils"
)
type NodeTaskService struct {
}
func NewNodeTaskService() *NodeTaskService {
newRoleService := &NodeTaskService{}
return newRoleService
}
// SendEvaluationNode 发送评估环节
func (rs *NodeTaskService) SendEvaluationNode() error {
transactionContext, err := factory.StartTransaction()
if err != nil {
return err
}
defer func() {
transactionContext.RollbackTransaction()
if err := recover(); err != nil {
log.Logger.Error(application.ThrowError(application.BUSINESS_ERROR, fmt.Sprintf("定时发送评估任务异常:%s", err)).Error())
}
}()
taskRepository := factory.CreateNodeTaskRepository(map[string]interface{}{"transactionContext": transactionContext})
tasks, err := taskRepository.Find(map[string]interface{}{"now": time.Now().Local()})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if len(tasks) == 0 {
return nil
}
projectRepository := factory.CreateEvaluationProjectRepository(map[string]interface{}{"transactionContext": transactionContext})
cycleRepository := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext})
projectIdsMap := map[int64]*domain.EvaluationProject{}
cycleIdsMap := map[int64]*domain.EvaluationCycle{}
for i := range tasks {
task := tasks[i]
projectIdsMap[task.ProjectId] = nil
cycleIdsMap[task.CycleId] = nil
}
projectIds := make([]int64, 0)
cycleIds := make([]int64, 0)
for k := range projectIdsMap {
projectIds = append(projectIds, k)
}
for k := range cycleIdsMap {
cycleIds = append(cycleIds, k)
}
_, projects, err := projectRepository.Find(map[string]interface{}{"ids": projectIds}, "template")
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
_, cycles, err := cycleRepository.Find(map[string]interface{}{"ids": cycleIds})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
for i := range projects {
projectIdsMap[projects[i].Id] = projects[i]
}
for i := range cycles {
cycleIdsMap[cycles[i].Id] = cycles[i]
}
staffAssessService := service.NewStaffAssessServeice()
for i := range tasks {
task := tasks[i]
project, ok := projectIdsMap[task.ProjectId] // 项目
if ok && project != nil {
// 环节截止时间
maxTime := task.TimeEnd.Local()
// 当前周起始时间和截止时间
var cycleTimeStart = task.NextSentAt.Local()
var cycleTimeEnd time.Time
// 下个周期起始时间
nextTime := utils.NextTimeInc(cycleTimeStart, task.KpiCycle)
// 超过截止时间
if nextTime.After(maxTime) {
task.NextSentAt = nil
} else {
task.NextSentAt = &nextTime
}
// 下个周期的起始时间=当前周期的截止时间
if task.NextSentAt == nil {
cycleTimeEnd = maxTime
} else {
cycleTimeEnd = task.NextSentAt.Local()
}
// 格式化周期的起始和截止时间
fmCycleStartTime := cycleTimeStart.Format("2006-1-2 15:04:05")
fmCycleTimeEnd := cycleTimeEnd.Format("2006-1-2 15:04:05")
csat := &command.CreateStaffAssessTask{
CompanyId: int(project.CompanyId),
EvaluationProjectId: int(project.Id),
EvaluationProjectName: project.Name,
CycleId: project.CycleId,
StepList: make([]command.AssessTaskStep, 0),
}
// 周期名称
if cycle, ok := cycleIdsMap[project.CycleId]; ok {
csat.CycleName = cycle.Name
}
// 接收人
csat.ExecutorId = make([]int, 0)
for rIndex := range project.Recipients {
vInt, _ := strconv.Atoi(project.Recipients[rIndex])
csat.ExecutorId = append(csat.ExecutorId, vInt)
}
csat.BeginTime = fmCycleStartTime
csat.EndTime = fmCycleTimeEnd
csat.StepList = append(csat.StepList, command.AssessTaskStep{
SortBy: task.NodeSort,
LinkNodeId: int(task.NodeId),
LinkNodeName: task.NodeName,
LinkNodeType: task.NodeType,
BeginTime: fmCycleStartTime,
EndTime: fmCycleTimeEnd,
})
// 创建发送任务
_, err := staffAssessService.CreateStaffAssessTask(transactionContext, csat)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
} else {
task.NextSentAt = nil // 项目不存在,取消周期任务发送
}
task, err := taskRepository.Insert(task)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return nil
}
... ...
... ... @@ -5,6 +5,6 @@ import (
)
type RoleUserAdapter struct {
domain.Role
*domain.Role
Users []*domain.RoleContainUser `json:"users"`
}
... ...
... ... @@ -5,8 +5,8 @@ import "github.com/beego/beego/v2/core/validation"
// QueryRoleUserCommand 查询角色列表(关联用户)
type QueryRoleUserCommand struct {
CompanyId int64 `cname:"公司ID" json:"companyId"`
PageNumber int `cname:"分页页码" json:"pageNumber" valid:"Required"`
PageSize int `cname:"分页数量" json:"pageSize" valid:"Required"`
PageNumber int64 `cname:"分页页码" json:"pageNumber" valid:"Required"`
PageSize int64 `cname:"分页数量" json:"pageSize" valid:"Required"`
}
func (in *QueryRoleUserCommand) Valid(validation *validation.Validation) {
... ...
... ... @@ -6,6 +6,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/role/adapter"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/role/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
type RoleService struct {
... ... @@ -91,47 +92,53 @@ func NewRoleService() *RoleService {
// return role, nil
//}
//
//func (rs *RoleService) Remove(in *command.DeleteRoleCommand) (interface{}, error) {
// transactionContext, err := factory.ValidateStartTransaction(in)
// if err != nil {
// return nil, err
// }
// defer func() {
// transactionContext.RollbackTransaction()
// }()
//
// roleRepository := factory.CreateRoleRepository(map[string]interface{}{"transactionContext": transactionContext})
// roleUserRepository := factory.CreateRoleUserRepository(map[string]interface{}{"transactionContext": transactionContext})
//
// role, err := roleRepository.FindOne(map[string]interface{}{"id": in.Id})
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// if _, err := roleRepository.Remove(role); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
//
// // 获取角色所有关联的用户,并删除
// _, roleUsers, err := roleUserRepository.Find(map[string]interface{}{"roleId": in.Id, "companyId": in.CompanyId})
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// ids := make([]int64, 0)
// for i := range roleUsers {
// ids = append(ids, roleUsers[i].Id)
// }
// if len(ids) > 0 {
// err := roleUserRepository.BatchDeleteById(ids)
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
// }
//
// if err := transactionContext.CommitTransaction(); err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// }
// return role, nil
//}
func (rs *RoleService) Remove(in *command.DeleteRoleCommand) (interface{}, error) {
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, err
}
defer func() {
transactionContext.RollbackTransaction()
}()
roleRepository := factory.CreateRoleRepository(map[string]interface{}{"transactionContext": transactionContext})
roleUserRepository := factory.CreateRoleUserRepository(map[string]interface{}{"transactionContext": transactionContext})
role, err := roleRepository.FindOne(map[string]interface{}{"id": in.Id})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if role.Type == domain.RoleTypeSystem {
return nil, application.ThrowError(application.BUSINESS_ERROR, "系统预制角色不可删除")
}
if _, err := roleRepository.Remove(role); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 获取角色所有关联的用户,并删除
_, roleUsers, err := roleUserRepository.Find(map[string]interface{}{"roleId": in.Id, "companyId": in.CompanyId})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
ids := make([]int64, 0)
for i := range roleUsers {
ids = append(ids, roleUsers[i].Id)
}
if len(ids) > 0 {
err := roleUserRepository.BatchDeleteById(ids)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return role, nil
}
func (rs *RoleService) ListForUser(in *command.QueryRoleUserCommand) (interface{}, error) {
transactionContext, err := factory.StartTransaction()
... ... @@ -150,11 +157,37 @@ func (rs *RoleService) ListForUser(in *command.QueryRoleUserCommand) (interface{
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if len(roles) == 0 {
return nil, application.ThrowError(application.BUSINESS_ERROR, "未找到角色数据")
}
adapterList := make([]*adapter.RoleUserAdapter, 0)
// 如果不存在系统预支hrbp角色时,插入一条数据
var havaSystemType = false
for i := range roles {
if roles[i].Type == domain.RoleTypeSystem {
havaSystemType = true
break
}
}
if !havaSystemType {
role := &domain.Role{
Id: 0,
Name: "HRBP",
Type: domain.RoleTypeSystem,
Description: "拥有全部权限,预置角色不可删除",
CompanyId: in.CompanyId,
}
role, err = roleRepository.Insert(role)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// 创建HRBP角色
roleUser := &adapter.RoleUserAdapter{}
roleUser.Role = role
roleUser.Users = make([]*domain.RoleContainUser, 0)
adapterList = append(adapterList, roleUser)
}
for i := range roles {
v := roles[i]
tempList, err := ruRepository.FindAllContainUser(1, 10, in.CompanyId, v.Id)
... ... @@ -162,13 +195,14 @@ func (rs *RoleService) ListForUser(in *command.QueryRoleUserCommand) (interface{
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
roleUser := &adapter.RoleUserAdapter{}
roleUser.Id = v.Id
roleUser.Name = v.Name
roleUser.Type = v.Type
roleUser.Description = v.Description
roleUser.CompanyId = v.CompanyId
roleUser.Role = v
roleUser.Users = tempList
adapterList = append(adapterList, roleUser)
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return tool_funs.SimpleWrapGridMap(int64(len(adapterList)), adapterList), nil
}
... ...
... ... @@ -28,8 +28,13 @@ func (rs *RoleUserService) Create(in *command.UserRoleCreateCommand) (interface{
}()
roleUserRepository := factory.CreateRoleUserRepository(map[string]interface{}{"transactionContext": transactionContext})
//int64Array := make([]int64, 0)
//for i := range in.UserIds {
// int64Num, _ := strconv.ParseInt(in.UserIds[i], 10, 64)
// int64Array = append(int64Array, int64Num)
//}
// 检测已存在的关联用户
_, rus, err := roleUserRepository.Find(map[string]interface{}{"roleId": in.RoleId, "companyId": in.CompanyId, "userIds": in.UserIds, "limit": 9999999})
_, rus, err := roleUserRepository.Find(map[string]interface{}{"roleId": in.RoleId, "companyId": in.CompanyId, "userIds": in.UserIds, "limit": int64(9999999)})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ...
... ... @@ -4,22 +4,37 @@ import "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
//评估内容详情
type AssessInfoResp struct {
CycleId int64 `json:"cycleId"` //周期id
CycleName string `json:"cycleName"` //周期名称
EvaluationProjectId int `json:"evaluationProjectId"` //项目id
EvaluationProjectName string `json:"evaluationProjectName"` //项目名称
BeginTime string `json:"beginTime"` //开始时间 2006-01-02 15:04:05
EndTime string `json:"endTime"` //结束时间 2006-01-02 15:04:05
Status string `json:"status"` //完成状态
TargetUserId int `json:"targetUser"` //
TargetUserName string `json:"targetUserName"` //
AssessContent []AssessContent `json:"assessContent"` //评估内容
AssessId int `json:"assessId"`
CycleId int64 `json:"cycleId"` //周期id
CycleName string `json:"cycleName"` //周期名称
EvaluationProjectId int `json:"evaluationProjectId"` //项目id
EvaluationProjectName string `json:"evaluationProjectName"` //项目名称
LinkNodeId int `json:"linkNodeId"`
LinkNodeName string `json:"linkNodeName"`
BeginTime string `json:"beginTime"` //开始时间 2006-01-02 15:04:05
EndTime string `json:"endTime"` //结束时间 2006-01-02 15:04:05
Status string `json:"status"` //完成状态
TargetUserId int `json:"targetUser"` //目标用户
TargetUserName string `json:"targetUserName"` //目标用户名称
CompanyId int `json:"companyId,string,"` //
CompanyName string `json:"companyName"` //公司名称
SupperUser string `json:"superUser"` //目标用户的上级
DutyTime string `json:"dutyTime"` //入职时间 //
AssessContent []*domain.StaffAssessContent `json:"assessContent"` //评估内容
}
type AssessContent struct {
Category string `json:"category" comment:"类别"`
Name string `json:"name" comment:"名称"`
PromptTitle string `json:"promptTitle" comment:"提示项标题"`
PromptText string `json:"promptText" comment:"提示项正文"`
EntryItems []*domain.EntryItem `json:"entryItems" comment:"填写项"`
Category string `json:"category"` //comment:"类别"
Name string `json:"name"` // comment:"名称"
PromptTitle string `json:"promptTitle"` //comment:"提示项标题"
PromptText string `json:"promptText"` // comment:"提示项正文"
Rule AssessContentRule `json:"rules"` //评定规则
Value string `json:"value"` // 实际填写评定值
Remark []domain.AssessContemtRemark `json:"entryItems"` // comment:"填写反馈"
}
type AssessContentRule struct {
Types int `json:"types"` //评估方式(0评级、1评分)
Rating domain.Rating `json:"rating"` //评级
Score domain.Score `json:"score"` //评分
}
... ...
... ... @@ -2,6 +2,7 @@ package adapter
import "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
//获取评估的邀请人
type AssessInviteUserResp struct {
LinkNodeId int `json:"linkNodeId"`
LinkNodeName string `json:"linkNodeName"`
... ...
package adapter
type ListInviteUserAssessResp struct {
LinkNodeName string `json:"linkNodeName"`
LinkNodeId int `json:"linkNodeId"`
LintNodeDesc string `json:"lintNodeDesc"`
TableHeader []ListTableHeader `json:"tableHeader"`
List []map[string]string `json:"list"`
Total int `json:"total"`
}
type ListTableHeader struct {
Key string `json:"key"`
Name string `json:"name"`
}
... ...
package adapter
type ListSupperAssessResp struct {
AssessId int `json:"assessId"` //
UsrId int `json:"userId"`
UserName string `json:"userName"` //用户名称
EndTime string `json:"endTime"` //截止时间
InviteTotal int `json:"inviteTota"` //邀请总数
InviteCompleted int `json:"inviteCompleted"` //邀请未完成
Status string `json:"status"`
Department string `json:"department"` //部门
Position string `json:"position"` //职位
DutyTime string `json:"dutyTime"` //入职时间
}
... ...
package adapter
type SelectInviteUser struct {
UserId int `json:"userId,string"`
UserName string `json:"userName"` //
IsSupper bool `json:"isSupper"` // 是否,是直属上级
Types int `json:"types"` // 1:相同上级的同事 2:不相同上级的同事
}
... ...
... ... @@ -6,8 +6,8 @@ type CreateStaffAssessTask struct {
EvaluationProjectName string `json:"evaluationProjectName"` //项目名称
CycleId int64 `json:"cycleId"` //对应的周期id
CycleName string `json:"cycleName"` //对应周期的名称
BeginTime string `json:"beginTime"` //绩效考核开始时间
EndTime string `json:"endTime"` //绩效考核截止时间
BeginTime string `json:"beginTime"` //绩效考核开始时间 2006-01-02 15:04:05
EndTime string `json:"endTime"` //绩效考核截止时间 2006-01-02 15:04:05
StepList []AssessTaskStep `json:"steps"` //考评的流程
ExecutorId []int `json:"executorId"` //参与此次考评的人
}
... ...
package command
//保存员工填写评估内容
type SaveAssessInfoCommand struct {
AssessId int `json:"assessId"`
AssessContent []AssesssContent `json:"assessContent"`
}
type AssesssContent struct {
Category string `json:"category"`
Name string `json:"name"`
Value string `json:"value"`
Remark []RemarkText `json:"remark"`
}
type RemarkText struct {
Title string `json:"title"`
RemarkText string `json:"remarkText"`
}
... ...
package query
type ListSupperAssessQuery struct {
PageNumber int `json:"pageNumber"`
PageSize int `json:"pageSize"`
UserName string `json:"userName"` //查询条件 员工的名称
CompanyId int `json:"companyId"` //
ExecutorId int `json:"executorId"` //评估的执行人
AssessTaskId int `json:"assessTaskId"` //评估任务id
}
... ...
package query
//获取评估任务详情
type AssessInfoQuery struct {
AssessTaskId int `json:"assessTaskId"` //StaffAssess 的id
TargetUserId int `json:"targetUserId"` //被评估的人id
CompanyId int `json:"companyId"` //公司id
AssessId int `json:"assessId"` //
CompanyId int `json:"companyId"` //
}
... ...
package query
//获取员工自评填写详情
type AssessSelfInfoQuery struct {
AssessTaskId int `json:"assessTaskId"` //assessTaskId 的id
TargetUserId int `json:"targetUserId"` //被评估的人id
CompanyId int `json:"companyId"` //公司id
}
... ...
... ... @@ -2,6 +2,6 @@ package query
type GetAssessInviteUserQuery struct {
CompanyId int `json:"companyId"` //对公司
UsrId int `json:"usrId"` //被评估的员工id
UserId int `json:"userId"` //被评估的员工id
AssessTaskId int `json:"assessTaskId"` //评估任务的id
}
... ...
package query
type ListInviteUserAssessQuery struct {
PageNumber int `json:"pageNumber"`
PageSize int `json:"pageSize"`
UserName string `json:"userName"` //查询条件 员工的名称
CompanyId int `json:"companyId"` //
ExecutorId int `json:"executorId"` //评估的执行人,必填
AssessTaskId int `json:"assessTaskId"` //评估任务id 必填
}
... ...
package query
//获取员工 被评估的列表
type ListTargetUserAssessQuery struct {
AssessTaskId int `json:"assessTaskId"`
TargetUserId int `json:"targetUserId"`
CompanyId int `json:"companyId"`
Types []string `json:"tyspes"`
}
... ...
package query
type SelectAssessInviteUser struct {
TargetUserId int `json:"targetUserId"` //被评估的员工userId
CompanyId int `json:"companyId"`
InviteUserName string `json:"inviteUserName"`
PageSize int `json:"pageSize"`
PageNumber int `json:"pageNumber"`
}
... ...
... ... @@ -12,6 +12,7 @@ import (
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/query"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/dao"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
)
... ... @@ -36,27 +37,40 @@ func (srv StaffAssessServeice) SearchAssessTaskMe(param *query.SearchAssessMeQue
defer func() {
_ = transactionContext.RollbackTransaction()
}()
staffAssessTaskRepo := factory.CreateStaffAssessTaskRepository(map[string]interface{}{
// staffAssessTaskRepo := factory.CreateStaffAssessTaskRepository(map[string]interface{}{
// "transactionContext": transactionContext,
// })
staffAssessTaskRepo := dao.NewStaffAssessDao(map[string]interface{}{
"transactionContext": transactionContext,
})
var limit int = 20
var limit int = 200
var offset int = 0
if param.PageSize > 0 {
limit = param.PageSize
}
offset = (param.PageNumber - 1) * param.PageSize
condition := map[string]interface{}{
"executorId": param.UserId,
"companyId": param.CompanyId,
"limit": limit,
}
if offset > 0 {
condition["offset"] = offset
assessTaskList, err := staffAssessTaskRepo.SearchAssessTaskMe(param.UserId, param.CompanyId, limit, offset)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "查询评估任务"+err.Error())
}
cnt, assessTaskList, err := staffAssessTaskRepo.Find(condition)
cnt, err := staffAssessTaskRepo.CountAssessTaskMe(param.UserId, param.CompanyId)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "查询周期"+err.Error())
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "查询评估任务"+err.Error())
}
// condition := map[string]interface{}{
// "executorId": param.UserId,
// "companyId": param.CompanyId,
// "limit": limit,
// }
// if offset > 0 {
// condition["offset"] = offset
// }
// cnt, assessTaskList, err := staffAssessTaskRepo.Find(condition)
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "查询周期"+err.Error())
// }
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ... @@ -199,6 +213,7 @@ func (srv StaffAssessServeice) AssessTaskDesc(param *query.AssessTaskDescQuery)
}
}
if uncompletedNum > 0 {
stepItem.Status = string(domain.StaffAssessUncompleted)
stepItem.Desc = fmt.Sprintf("截止日期:%s 待评估%d人", stepItem.EndTime, uncompletedNum)
}
}
... ... @@ -321,27 +336,31 @@ func (srv StaffAssessServeice) AssessSelfList(param *query.AssessSelfListQuery)
DutyTime: userData.CreatedAt.Local().Format("2006-01-02 15:04:05"),
}
for _, v := range supperUserList {
userInfo.SupperUserName = userInfo.SupperUserName + v.Name + ";"
userInfo.SupperUserName = userInfo.SupperUserName + v.Name + " "
}
result := tool_funs.SimpleWrapGridMap(int64(cnt), listData)
result["userInfo"] = userInfo
return result, nil
}
// 更具项目评估的配置,创建员工的评估任务
func (srv StaffAssessServeice) CreateStaffAssessTask(param *command.CreateStaffAssessTask) (map[string]interface{}, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
// 根据项目评估的配置,创建员工的评估任务
func (srv StaffAssessServeice) CreateStaffAssessTask(transactionContext application.TransactionContext, param *command.CreateStaffAssessTask) (map[string]interface{}, error) {
// transactionContext, err := factory.CreateTransactionContext(nil)
// if err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// }
// if err := transactionContext.StartTransaction(); err != nil {
// return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
// }
// defer func() {
// _ = transactionContext.RollbackTransaction()
// }()
log.Logger.Debug("CreateStaffAssessTask 获取参数", map[string]interface{}{
"param": param,
})
assessTaskRepo := factory.CreateStaffAssessTaskRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
taskBeginTime, err := time.ParseInLocation("2006-01-02 15:04:05", param.BeginTime, time.Local)
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "任务开始时间填写错误,"+param.BeginTime)
... ... @@ -352,7 +371,7 @@ func (srv StaffAssessServeice) CreateStaffAssessTask(param *command.CreateStaffA
}
nowTime := time.Now()
//建立评估任务
assessTask := domain.StaffAssessTask{
assessTaskData := &domain.StaffAssessTask{
Id: 0,
CompanyId: param.CompanyId,
EvaluationProjectId: param.EvaluationProjectId,
... ... @@ -366,9 +385,17 @@ func (srv StaffAssessServeice) CreateStaffAssessTask(param *command.CreateStaffA
CreatedAt: nowTime,
UpdatedAt: nowTime,
DeletedAt: nil,
BeginDay: taskBeginTime.Local().Format("2006-01-02"),
}
// }
//填充评估环节
for _, v := range param.StepList {
for _, vv := range assessTaskData.StepList {
if vv.LinkNodeType == v.LinkNodeType {
continue
}
}
stepBeginTime, err := time.ParseInLocation("2006-01-02 15:04:05", param.BeginTime, time.Local)
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "评估环节开始时间填写错误,"+param.BeginTime)
... ... @@ -385,41 +412,71 @@ func (srv StaffAssessServeice) CreateStaffAssessTask(param *command.CreateStaffA
BeginTime: stepBeginTime,
EndTime: stepEndTime,
}
assessTask.StepList = append(assessTask.StepList, step)
assessTaskData.StepList = append(assessTaskData.StepList, step)
}
assessTaskRepo := factory.CreateStaffAssessTaskRepository(map[string]interface{}{
"transactionContext": transactionContext,
//评估的参与人
executorIds := []int{}
executorIdMap := map[int]struct{}{} //过滤重复的用户
for _, v := range param.ExecutorId {
if _, ok := executorIdMap[v]; ok {
continue
}
executorIdMap[v] = struct{}{}
executorIds = append(executorIds, v)
}
assessTaskData.ExecutorId = executorIds
assessList, err := srv.createStaffAssess(transactionContext, assessTaskData)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "生成个人评估项"+err.Error())
}
// var assessTaskData *domain.StaffAssessTask
_, assassessTaskList, err := assessTaskRepo.Find(map[string]interface{}{
"evaluationProjectId": param.EvaluationProjectId,
"beginDay": taskBeginTime.Local().Format("2006-01-02"),
})
_, err = assessTaskRepo.Save(&assessTask)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存评估任务"+err.Error())
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "查询同日期已存在评估任务"+err.Error())
}
assessList, err := srv.createStaffAssess(transactionContext, &assessTask)
if len(assassessTaskList) > 0 {
//过滤就数据
assessTaskData.Id = assassessTaskList[0].Id
for _, v := range assassessTaskList[0].ExecutorId {
if _, ok := executorIdMap[v]; ok {
continue
}
executorIdMap[v] = struct{}{}
executorIds = append(executorIds, v)
}
assessTaskData.ExecutorId = executorIds
assessTaskData.StepList = append(assassessTaskList[0].StepList, assessTaskData.StepList...)
}
_, err = assessTaskRepo.Save(assessTaskData)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "生成个人评估项"+err.Error())
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存评估任务"+err.Error())
}
assessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
for i := range assessList {
assessList[i].StaffAssessTaskId = assessTaskData.Id
_, err = assessRepo.Save(&assessList[i])
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存个人评估项"+err.Error())
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
// if err := transactionContext.CommitTransaction(); err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
// }
return map[string]interface{}{
"assessTaskId": assessTask.Id,
"assessTaskId": assessTaskData.Id,
}, nil
}
// 添加自评节点任务
// 添加节点任务
func (srv StaffAssessServeice) createStaffAssess(transactionContext application.TransactionContext, param *domain.StaffAssessTask) ([]domain.StaffAssess, error) {
//评估的参与人
selfUserId := []int{}
... ... @@ -432,6 +489,9 @@ func (srv StaffAssessServeice) createStaffAssess(transactionContext application.
}
// 获取用户的信息
if len(selfUserId) == 0 {
log.Logger.Error("createStaffAssess", map[string]interface{}{
"param": param,
})
return nil, application.ThrowError(application.ARG_ERROR, "未填写评估任务的执行人")
}
userRepo := factory.CreateUserRepository(map[string]interface{}{
... ... @@ -450,6 +510,9 @@ func (srv StaffAssessServeice) createStaffAssess(transactionContext application.
//获取用户的部门
userDepartmentMap := map[int64][]*domain.Department{}
for _, v := range userList {
if len(v.DepartmentId) == 0 {
continue
}
_, departmemtList, err := departmentRepo.Find(map[string]interface{}{
"ids": v.DepartmentId,
})
... ... @@ -471,7 +534,7 @@ func (srv StaffAssessServeice) createStaffAssess(transactionContext application.
// TargetUser: domain.StaffDesc{},
// TargetDepartment: nil,
// Executor: domain.StaffDesc{},
Types: domain.AssessSelf,
Types: "",
// LinkNodeId: v.LinkNodeId,
Status: domain.StaffAssessUncompleted,
// BeginTime: time.Time{},
... ... @@ -487,6 +550,7 @@ func (srv StaffAssessServeice) createStaffAssess(transactionContext application.
stepSelfTemp.EndTime = v.EndTime
stepSelfTemp.LinkNodeId = v.LinkNodeId
stepSelfTemp.LinkNodeName = v.LinkNodeName
stepSelfTemp.Types = domain.AssessSelf
assessListTemp := srv.createStaffAssessSelf(stepSelfTemp, userList, userDepartmentMap)
assessList = append(assessList, assessListTemp...)
}
... ... @@ -496,11 +560,12 @@ func (srv StaffAssessServeice) createStaffAssess(transactionContext application.
stepSelfTemp.EndTime = v.EndTime
stepSelfTemp.LinkNodeId = v.LinkNodeId
stepSelfTemp.LinkNodeName = v.LinkNodeName
assessListTemp, err := srv.createStaffAssessSupper(transactionContext, stepSelfTemp, userList, userDepartmentMap)
stepSelfTemp.Types = domain.AssessSuper
assessListTemp2, err := srv.createStaffAssessSupper(transactionContext, stepSelfTemp, userList, userDepartmentMap)
if err != nil {
return nil, err
}
assessList = append(assessList, assessListTemp...)
assessList = append(assessList, assessListTemp2...)
}
}
return assessList, nil
... ... @@ -511,15 +576,16 @@ func (srv StaffAssessServeice) createStaffAssessSelf(assessTemp domain.StaffAsse
userList []*domain.User, userDepartmentMap map[int64][]*domain.Department) []domain.StaffAssess {
result := []domain.StaffAssess{}
for _, usr := range userList {
assessTemp.TargetUser = domain.StaffDesc{
UserId: int(usr.Id),
Account: usr.Account,
UserName: usr.Account,
UserName: usr.Name,
}
assessTemp.Executor = domain.StaffDesc{
UserId: int(usr.Id),
Account: usr.Account,
UserName: usr.Account,
UserName: usr.Name,
}
if depList, ok := userDepartmentMap[usr.Id]; ok {
for _, dep := range depList {
... ... @@ -540,13 +606,49 @@ func (srv StaffAssessServeice) createStaffAssessSupper(
assessTemp domain.StaffAssess,
userList []*domain.User, userDepartmentMap map[int64][]*domain.Department,
) ([]domain.StaffAssess, error) {
var assessList []domain.StaffAssess
// 获取员工的上级用户
return nil, nil
userRepo := factory.CreateUserRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
for _, v := range userList {
departmentList, ok := userDepartmentMap[v.Id]
if !ok {
continue
}
for _, vv2 := range departmentList {
if len(vv2.ChargeUserIds) == 0 {
continue
}
_, chargeUserList, err := userRepo.Find(map[string]interface{}{
"ids": vv2.ChargeUserIds,
"limit": 40,
})
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "获取部门主管信息"+err.Error())
}
for _, vvv3 := range chargeUserList {
assessTemp.TargetDepartment = []domain.StaffDepartment{
{DepartmentId: int(vv2.Id), DepartmentName: vv2.Name},
}
assessTemp.TargetUser = domain.StaffDesc{
UserId: int(v.Id),
Account: v.Account,
UserName: v.Name,
}
assessTemp.Executor = domain.StaffDesc{
UserId: int(vvv3.Id),
Account: vvv3.Account,
UserName: vvv3.Name,
}
assessList = append(assessList, assessTemp)
}
}
}
return assessList, nil
}
// 获取某个员工360邀请的人员
// 获取某个员工360评估邀请的人员
func (srv StaffAssessServeice) GetAssessInviteUser(param *query.GetAssessInviteUserQuery) (*adapter.AssessInviteUserResp, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
... ... @@ -575,7 +677,7 @@ func (srv StaffAssessServeice) GetAssessInviteUser(param *query.GetAssessInviteU
_, assessList, err := assessReps.Find(map[string]interface{}{
"typesList": []string{string(domain.AssessInviteDiffSuper), string(domain.AssessInviteSameSuper)},
"staffAssessTaskId": param.AssessTaskId,
"targetUserId": param.UsrId,
"targetUserId": param.UserId,
})
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "获取个人评估任务"+err.Error())
... ... @@ -585,7 +687,9 @@ func (srv StaffAssessServeice) GetAssessInviteUser(param *query.GetAssessInviteU
}
result := adapter.AssessInviteUserResp{
AssessTaskId: assessTaskData.Id,
AssessTaskId: assessTaskData.Id,
InviteDiffSuper: []domain.StaffDesc{},
InviteSameSuper: []domain.StaffDesc{},
}
for _, v := range assessTaskData.StepList {
if v.LinkNodeType != domain.LinkNodeAllInvite {
... ... @@ -608,8 +712,8 @@ func (srv StaffAssessServeice) GetAssessInviteUser(param *query.GetAssessInviteU
return &result, nil
}
// 获取某个员工360邀请的人员
func (srv StaffAssessServeice) SaveAssessInviteUser(param *command.SaveAssessInvite) (*adapter.AssessInviteUserResp, error) {
// 保存某个员工360邀请的人员
func (srv StaffAssessServeice) SaveAssessInviteUser(param *command.SaveAssessInvite) (map[string]interface{}, error) {
inviteSameSuperId := []int{}
InviteDiffSuperId := []int{}
for _, v := range param.InviteDiffSuper {
... ... @@ -657,6 +761,19 @@ func (srv StaffAssessServeice) SaveAssessInviteUser(param *command.SaveAssessInv
return nil, application.ThrowError(application.ARG_ERROR, "获取评估任务"+err.Error())
}
//获取邀请评估的节点
var inviteNode *domain.AssessTaskStep
for _, v := range assessTaskData.StepList {
if v.LinkNodeType == domain.LinkNodeAllAssessment {
cp := v
inviteNode = &cp
break
}
}
if inviteNode == nil {
return nil, application.ThrowError(application.ARG_ERROR, "评估任务没有邀请评估的环节")
}
targetUser, err := userRepo.FindOne(map[string]interface{}{
"id": param.TargetUserId,
})
... ... @@ -713,50 +830,108 @@ func (srv StaffAssessServeice) SaveAssessInviteUser(param *command.SaveAssessInv
})
}
}
_ = assessReps
_ = inviteSameSuper
_ = inviteDiffSuper
_ = targetUserDepartment
// _, assessList, err := assessReps.Find(map[string]interface{}{
// "typesList": []string{string(domain.AssessInviteDiffSuper), string(domain.AssessInviteSameSuper)},
// "staffAssessTaskId": param.AssessTaskId,
// "targetUserId": param.TargetUserId,
// })
// if err != nil {
// return nil, application.ThrowError(application.ARG_ERROR, "获取个人评估任务"+err.Error())
// }
// TODO
//获取员工邀请的人
_, assessList, err := assessReps.Find(map[string]interface{}{
"typesList": []string{string(domain.AssessInviteDiffSuper), string(domain.AssessInviteSameSuper)},
"staffAssessTaskId": param.AssessTaskId,
"targetUserId": param.TargetUserId,
})
if err != nil {
return nil, application.ThrowError(application.ARG_ERROR, "获取员工邀请的人"+err.Error())
}
//比对新旧数据
nowTime := time.Now()
assessMap := map[string]*domain.StaffAssess{}
for _, v := range assessList {
//假设为删除
v.DeletedAt = &nowTime
key := fmt.Sprintf("%s%d", string(v.Types), v.Executor.UserId)
assessMap[key] = v
}
newAssessList := []*domain.StaffAssess{}
//邀请同上级的员工
for _, v := range inviteSameSuper {
key := fmt.Sprintf("%s%d", string(domain.AssessInviteSameSuper), v.UserId)
if _, ok := assessMap[key]; ok {
assessMap[key].DeletedAt = nil
} else {
newAssessList = append(newAssessList, &domain.StaffAssess{
Id: 0,
CompanyId: assessTaskData.CompanyId,
EvaluationProjectId: assessTaskData.EvaluationProjectId,
EvaluationProjectName: assessTaskData.EvaluationProjectName,
CycleId: assessTaskData.CycleId,
CycleName: assessTaskData.CycleName,
StaffAssessTaskId: assessTaskData.Id,
TargetUser: domain.StaffDesc{
UserId: int(targetUser.Id),
Account: targetUser.Account,
UserName: targetUser.Name,
},
TargetDepartment: targetUserDepartment,
Executor: v,
Types: domain.AssessInviteSameSuper,
LinkNodeId: inviteNode.LinkNodeId,
LinkNodeName: inviteNode.LinkNodeName,
Status: domain.StaffAssessUncompleted,
BeginTime: inviteNode.BeginTime,
EndTime: inviteNode.EndTime,
CreatedAt: nowTime,
UpdatedAt: nowTime,
DeletedAt: nil,
})
}
}
for _, v := range inviteDiffSuper {
key := fmt.Sprintf("%s%d", string(domain.AssessInviteDiffSuper), v.UserId)
if _, ok := assessMap[key]; ok {
assessMap[key].DeletedAt = nil
} else {
newAssessList = append(newAssessList, &domain.StaffAssess{
Id: 0,
CompanyId: assessTaskData.CompanyId,
EvaluationProjectId: assessTaskData.EvaluationProjectId,
EvaluationProjectName: assessTaskData.EvaluationProjectName,
CycleId: assessTaskData.CycleId,
CycleName: assessTaskData.CycleName,
StaffAssessTaskId: assessTaskData.Id,
TargetUser: domain.StaffDesc{
UserId: int(targetUser.Id),
Account: targetUser.Account,
UserName: targetUser.Name,
},
TargetDepartment: targetUserDepartment,
Executor: v,
Types: domain.AssessInviteDiffSuper,
LinkNodeId: inviteNode.LinkNodeId,
LinkNodeName: inviteNode.LinkNodeName,
Status: domain.StaffAssessUncompleted,
BeginTime: inviteNode.BeginTime,
EndTime: inviteNode.EndTime,
CreatedAt: nowTime,
UpdatedAt: nowTime,
DeletedAt: nil,
})
}
}
assessList = append(assessList, newAssessList...)
for i := range assessList {
_, err = assessReps.Save(assessList[i])
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存员工邀请评估"+err.Error())
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
result := adapter.AssessInviteUserResp{
AssessTaskId: assessTaskData.Id,
}
// for _, v := range assessTaskData.StepList {
// if v.LinkNodeType != domain.LinkNodeAllInvite {
// continue
// }
// result.LinkNodeId = v.LinkNodeId
// result.LinkNodeName = v.LinkNodeName
// result.BeginTime = v.BeginTime.Local().Format("2006-01-02 15:04:05")
// result.EndTime = v.EndTime.Local().Format("2006-01-02 15:04:05")
// break
// }
// for _, v := range assessList {
// if v.Types == domain.AssessInviteDiffSuper {
// result.InviteDiffSuper = append(result.InviteDiffSuper, v.Executor)
// }
// if v.Types == domain.AssessInviteSameSuper {
// result.InviteSameSuper = append(result.InviteDiffSuper, v.Executor)
// }
// }
return &result, nil
result := map[string]interface{}{
"assessTaskId": assessTaskData.Id,
}
return result, nil
}
// 获取员工自评的评估内容详情
func (srv StaffAssessServeice) GetAssessSelfInfo(param *query.AssessInfoQuery) (*adapter.AssessInfoResp, error) {
func (srv StaffAssessServeice) GetAssessSelfInfo(param *query.AssessSelfInfoQuery) (*adapter.AssessInfoResp, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -770,7 +945,6 @@ func (srv StaffAssessServeice) GetAssessSelfInfo(param *query.AssessInfoQuery) (
assessReps := factory.CreateStaffAssessRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
//获取员工的评估
_, assessList, err := assessReps.Find(map[string]interface{}{
"companyId": param.CompanyId,
... ... @@ -785,45 +959,38 @@ func (srv StaffAssessServeice) GetAssessSelfInfo(param *query.AssessInfoQuery) (
return &adapter.AssessInfoResp{}, nil
}
assessData := assessList[0]
projectRepo := factory.CreateEvaluationProjectRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
projectData, err := projectRepo.FindOne(map[string]interface{}{
"id": assessData.EvaluationProjectId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取项目评估配置"+err.Error())
}
if projectData.Template == nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "未获取到项目评估配置模板")
}
var selfLinkNode *domain.LinkNode
for _, v := range projectData.Template.LinkNodes {
if v.Type == domain.LinkNodeSelfAssessment {
selfLinkNode = v
break
assessContentList := []*domain.StaffAssessContent{}
if assessData.Status == domain.StaffAssessCompleted {
//已完成
assessContentRepo := factory.CreateStaffAssessContentRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
_, assessContentList, err = assessContentRepo.Find(map[string]interface{}{
"staffAssessId": assessData.Id,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取项目填写内容"+err.Error())
}
} else if assessData.Status == domain.StaffAssessUncompleted {
//未完成
assessContentList, err = srv.getAssessSelfInfoUncompleted(transactionContext, assessData)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取项目填写内容"+err.Error())
}
}
if selfLinkNode == nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "未获取到项目评估自评配置")
}
//获取员工评估的填写内容
// assessContentReps := factory.CreateStaffAssessContentRepository(map[string]interface{}{
// "transactionContext": transactionContext,
// })
// _, assessContentList, err := assessContentReps.Find(map[string]interface{}{
// "staffAssessId": assessData.Id,
// })
// if err != nil {
// return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取项目评估员工填写的内容"+err.Error())
// }
//获取员工描述
staffDesc, _ := srv.getStaffDescrip(transactionContext, int64(param.TargetUserId))
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
result := adapter.AssessInfoResp{
AssessId: assessData.Id,
CycleId: assessData.CycleId,
CycleName: assessData.CycleName,
LinkNodeId: assessData.LinkNodeId,
LinkNodeName: assessData.LinkNodeName,
EvaluationProjectId: assessData.EvaluationProjectId,
EvaluationProjectName: assessData.EvaluationProjectName,
BeginTime: assessData.BeginTime.Local().Format("2006-01-02 15:04:05"),
... ... @@ -831,18 +998,715 @@ func (srv StaffAssessServeice) GetAssessSelfInfo(param *query.AssessInfoQuery) (
Status: string(assessData.Status),
TargetUserId: assessData.TargetUser.UserId,
TargetUserName: assessData.TargetUser.UserName,
AssessContent: nil,
}
assessContent := make([]adapter.AssessContent, 0)
for _, v := range selfLinkNode.NodeContents {
assessContent = append(assessContent, adapter.AssessContent{
Category: v.Category,
Name: v.Name,
PromptTitle: v.PromptTitle,
PromptText: v.PromptText,
EntryItems: v.EntryItems,
})
CompanyId: assessData.CompanyId,
CompanyName: "",
SupperUser: "",
DutyTime: "",
AssessContent: assessContentList,
}
if staffDesc != nil {
result.CompanyName = staffDesc.CompanyName
result.SupperUser = staffDesc.SupperUserName
result.DutyTime = staffDesc.DutyTime
}
result.AssessContent = assessContent
return &result, nil
}
// 获取未完成的员工评估内容
func (srv StaffAssessServeice) getAssessSelfInfoUncompleted(transactionContext application.TransactionContext,
assess *domain.StaffAssess) ([]*domain.StaffAssessContent, error) {
projectRepo := factory.CreateEvaluationProjectRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
projectData, err := projectRepo.FindOne(map[string]interface{}{
"id": assess.EvaluationProjectId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取项目填写内容"+err.Error())
}
var linkNode *domain.LinkNode
for _, v := range projectData.Template.LinkNodes {
if v.Id == int64(assess.LinkNodeId) {
linkNode = v
break
}
}
if linkNode == nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "未获得评估环节配置"+err.Error())
}
ruleRepo := factory.CreateEvaluationRuleRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
ruleMap := map[int64]*domain.EvaluationRule{}
for _, v := range linkNode.NodeContents {
if _, ok := ruleMap[v.RuleId]; ok {
continue
}
ruleData, err := ruleRepo.FindOne(map[string]interface{}{
"id": v.RuleId,
})
if err == nil {
ruleMap[v.RuleId] = ruleData
}
}
var contentList []*domain.StaffAssessContent
nowTime := time.Now()
for i, v := range linkNode.NodeContents {
item := &domain.StaffAssessContent{
Id: 0,
StaffAssessId: assess.Id,
SortBy: i + 1,
Category: v.Category,
Name: v.Name,
PromptTitle: v.PromptTitle,
PromptText: v.PromptText,
Remark: nil,
Value: "",
ReteResult: "",
CreatedAt: nowTime,
Weight: v.Weight,
UpdatedAt: nowTime,
DeletedAt: nil,
// Rule: ,
}
if ruleVal, ok := ruleMap[v.RuleId]; ok {
item.Rule = *ruleVal
}
var remarks []domain.AssessContemtRemark
for _, vv := range v.EntryItems {
ritem := domain.AssessContemtRemark{
Title: vv.Title,
HintText: vv.HintText,
RemarkText: "",
}
remarks = append(remarks, ritem)
}
item.Remark = remarks
contentList = append(contentList, item)
}
return contentList, nil
}
// 选择员工评估可邀请的用户
func (srv StaffAssessServeice) SelectAssessInviteUser(param *query.SelectAssessInviteUser) (map[string]interface{}, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
//获取被评估的目标用户
userRepo := factory.CreateUserRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
targetUser, err := userRepo.FindOne(map[string]interface{}{
"id": param.TargetUserId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取员工信息"+err.Error())
}
//获取被评估的目标用户的部门
departmentRepo := factory.CreateDepartmentRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
var targetUserDepartment []*domain.Department
if len(targetUser.DepartmentId) > 0 {
_, targetUserDepartment, err = departmentRepo.Find(map[string]interface{}{
"ids": targetUser.DepartmentId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取部门信息"+err.Error())
}
}
//获取部门主管的id
targetUserCharge := map[int64]struct{}{}
for _, v := range targetUserDepartment {
for _, vv := range v.ChargeUserIds {
targetUserCharge[vv] = struct{}{}
}
}
//
targetUserDepartmentMap := map[int64]struct{}{}
for _, v := range targetUserDepartment {
targetUserDepartmentMap[v.Id] = struct{}{}
}
//查询员工数据
condition := map[string]interface{}{
"companyId": param.CompanyId,
"name": param.InviteUserName,
"limit": 20,
}
if param.PageSize > 0 {
condition["limit"] = param.PageSize
}
offset := (param.PageNumber - 1) * param.PageSize
if offset > 0 {
condition["offset"] = offset
}
cnt, userList, err := userRepo.Find(condition)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取员工列表信息"+err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
listData := []adapter.SelectInviteUser{}
for _, v := range userList {
item := adapter.SelectInviteUser{
UserId: int(v.Id),
UserName: v.Name,
IsSupper: false,
Types: 2, //默认是不同上级
}
if _, ok := targetUserCharge[v.Id]; ok {
item.IsSupper = true
}
for _, vv := range v.DepartmentId {
if _, ok := targetUserDepartmentMap[int64(vv)]; ok {
item.Types = 1 //设为相同上级
break
}
}
listData = append(listData, item)
}
return tool_funs.SimpleWrapGridMap(int64(cnt), listData), nil
}
// 获取我要执行的的360评估,用户列表和评估填写的值
func (srv StaffAssessServeice) ListExecutorInviteAssess(param *query.ListInviteUserAssessQuery) (
*adapter.ListInviteUserAssessResp, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
//获取对应的评估任务
assessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
assessTaskRepo := factory.CreateStaffAssessTaskRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
//获取 executorId 对应的360评估任务 用户
condition := map[string]interface{}{
"staffAssessTaskId": param.AssessTaskId,
"executorId": param.ExecutorId,
"typesList": []string{string(domain.AssessInviteDiffSuper), string(domain.AssessInviteSameSuper)},
"limit": 20,
}
if param.PageSize > 0 {
condition["limit"] = param.PageSize
}
offset := (param.PageNumber - 1) * param.PageSize
if offset > 0 {
condition["offset"] = offset
}
cnt, assessList, err := assessRepo.Find(condition)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
var assessContentList []*domain.StaffAssessContent
if len(assessList) > 0 {
//获取评估用的所有评估项
assessContentList, err = srv.getAssessSelfInfoUncompleted(transactionContext, assessList[0])
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取评估任务"+err.Error())
}
}
//可变的表格列
changeableHeader := []adapter.ListTableHeader{}
//列名与字段对应
keyMap := map[string]string{}
for i, v := range assessContentList {
name := fmt.Sprintf("%s-%s", v.Category, v.Name)
key := fmt.Sprintf("k%d", i)
keyMap[name] = key
changeableHeader = append(changeableHeader, adapter.ListTableHeader{
Key: key,
Name: name,
})
}
assessContentRepo := factory.CreateStaffAssessContentRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
// 获取已经填报的内容
changeableRows := map[int]map[string]string{}
for _, v := range assessList {
_, contentList, err := assessContentRepo.Find(map[string]interface{}{
"staffAssessId": v.Id,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取评估内容"+err.Error())
}
row := map[string]string{}
for _, vv := range contentList {
name := fmt.Sprintf("%s-%s", vv.Category, vv.Name)
if kk, ok := keyMap[name]; ok {
row[kk] = vv.Value
}
}
changeableRows[v.TargetUser.UserId] = row
}
//获取360邀请评估完成情况
//我评估别人,被邀请评估
cnnt, _, err := assessRepo.Find(map[string]interface{}{
"staffAssessTaskId": param.AssessTaskId,
"executorId": param.ExecutorId,
"typesList": []string{string(domain.AssessInviteDiffSuper), string(domain.AssessInviteSameSuper)},
"status": domain.StaffAssessUncompleted,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取个人的评估环节"+err.Error())
}
assessTaskData, err := assessTaskRepo.FindOne(map[string]interface{}{
"id": param.AssessTaskId,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取评估任务"+err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
//评估填写数据行转列
tableHeader := []adapter.ListTableHeader{
{Key: "userName", Name: "姓名"},
{Key: "status", Name: "状态"},
{Key: "types", Name: "360°评估关系"},
{Key: "endTime", Name: "360°评估截止日期"},
}
tableHeader = append(tableHeader, changeableHeader...)
listData := []map[string]string{}
for _, v := range assessList {
m := map[string]string{
"userName": v.TargetUser.UserName,
"userId": strconv.Itoa(v.TargetUser.UserId),
"status": string(v.Status),
"types": string(v.Types),
"endTime": v.EndTime.Local().Format("2006-01-02 15:04:05"),
"assessId": strconv.Itoa(v.Id),
}
if row, ok := changeableRows[v.TargetUser.UserId]; ok {
for k, v := range row {
m[k] = v
}
} else {
for _, v := range changeableHeader {
m[v.Key] = ""
}
}
listData = append(listData, m)
}
result := adapter.ListInviteUserAssessResp{
TableHeader: tableHeader,
List: listData,
Total: cnt,
}
for _, v := range assessTaskData.StepList {
if v.LinkNodeType == domain.LinkNodeAllAssessment {
result.LinkNodeId = v.LinkNodeId
result.LinkNodeName = v.LinkNodeName
result.LintNodeDesc = fmt.Sprintf("截止时间 %s 待评估%d人", v.EndTime.Local().Format("2006-01-02 15:04:05"), cnnt)
}
}
return &result, nil
}
// 获取我需要执行的上级评估成员列表
func (srv StaffAssessServeice) ListExecutorSupperAssess(param *query.ListSupperAssessQuery) (map[string]interface{}, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
//获取对应的评估任务
assessRepo := factory.CreateStaffAssessRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
limit := 20
if param.PageSize > 0 {
limit = param.PageSize
}
condition := map[string]interface{}{
"staffAssessTaskId": param.AssessTaskId,
"executorId": param.ExecutorId,
"typesList": []string{string(domain.AssessSuper)},
"limit": limit,
"targetUserName": param.UserName,
}
offset := (param.PageNumber - 1) * param.PageSize
if offset > 0 {
condition["offset"] = offset
}
//获取 executorId 对应的上级评估列表
cnt, assessList, err := assessRepo.Find(condition)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
userIds := []int{}
for _, v := range assessList {
userIds = append(userIds, v.TargetUser.UserId)
}
//获取员工信息
userRepo := factory.CreateUserRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
var targetUserList []*domain.User
if len(userIds) > 0 {
_, targetUserList, _ = userRepo.Find(map[string]interface{}{
"ids": userIds,
})
}
//获取职位信息
positionRepo := factory.CreatePositionRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
//获取员工的职位
userPositionMap := map[int64][]*domain.Position{}
for _, v := range targetUserList {
if len(v.PositionId) == 0 {
continue
}
_, positionList, _ := positionRepo.Find(map[string]interface{}{
"ids": v.PositionId,
})
userPositionMap[v.Id] = positionList
}
//获取员工邀请的人完成360评估的数量
var inviteCompletedCount []dao.CountData
if len(userIds) > 0 {
d := dao.NewStaffAssessDao(map[string]interface{}{
"transactionContext": transactionContext,
})
inviteCompletedCount, err = d.CountInviteAssessByTargetUser(userIds, param.AssessTaskId)
if err != nil {
log.Logger.Error("获取员工邀请的人完成情况" + err.Error())
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
resultList := []adapter.ListSupperAssessResp{}
for _, v := range assessList {
item := adapter.ListSupperAssessResp{
AssessId: v.Id,
UsrId: v.TargetUser.UserId,
UserName: v.TargetUser.UserName,
EndTime: v.EndTime.Local().Format("2006-01-02 15:04:05"),
InviteCompleted: 0,
Status: string(v.Status),
InviteTotal: 5,
Department: "",
Position: "",
DutyTime: "",
}
//填入部门
for _, vv := range v.TargetDepartment {
item.Department += vv.DepartmentName + " "
}
for _, vv := range targetUserList {
if vv.Id != int64(v.TargetUser.UserId) {
continue
}
//填入入职时间
item.DutyTime = vv.CreatedAt.Local().Format("2006-01-02 15:04:05")
//填入职位
for _, vvv := range userPositionMap[vv.Id] {
item.Position += vvv.Name + " "
}
break
}
//
for _, vv := range inviteCompletedCount {
if v.TargetUser.UserId == vv.TargetUserId {
item.InviteCompleted = vv.InviteCompleted
item.InviteTotal = vv.InviteTotal
break
}
}
resultList = append(resultList, item)
}
return tool_funs.SimpleWrapGridMap(int64(cnt), resultList), nil
}
// 根据staffAssessId 获取评估的填写信息
func (srv StaffAssessServeice) GetAssessInfo(param *query.AssessInfoQuery) (*adapter.AssessInfoResp, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
assessReps := factory.CreateStaffAssessRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
//获取员工的评估
_, assessList, err := assessReps.Find(map[string]interface{}{
"companyId": param.CompanyId,
"id": param.AssessId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取员工的评估"+err.Error())
}
if len(assessList) == 0 {
return &adapter.AssessInfoResp{}, nil
}
assessData := assessList[0]
assessContentList := []*domain.StaffAssessContent{}
if assessData.Status == domain.StaffAssessCompleted {
//已完成
assessContentRepo := factory.CreateStaffAssessContentRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
_, assessContentList, err = assessContentRepo.Find(map[string]interface{}{
"staffAssessId": assessData.Id,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取项目填写内容"+err.Error())
}
} else if assessData.Status == domain.StaffAssessUncompleted {
//未完成
assessContentList, err = srv.getAssessSelfInfoUncompleted(transactionContext, assessData)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取项目填写内容"+err.Error())
}
}
targetUserDesc, err := srv.getStaffDescrip(transactionContext, int64(assessData.TargetUser.UserId))
if err != nil {
log.Logger.Error("获取员工描述" + err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
result := adapter.AssessInfoResp{
AssessId: assessData.Id,
CycleId: assessData.CycleId,
CycleName: assessData.CycleName,
LinkNodeId: assessData.LinkNodeId,
LinkNodeName: assessData.LinkNodeName,
EvaluationProjectId: assessData.EvaluationProjectId,
EvaluationProjectName: assessData.EvaluationProjectName,
BeginTime: assessData.BeginTime.Local().Format("2006-01-02 15:04:05"),
EndTime: assessData.EndTime.Local().Format("2006-01-02 15:04:05"),
Status: string(assessData.Status),
TargetUserId: assessData.TargetUser.UserId,
TargetUserName: assessData.TargetUser.UserName,
CompanyId: assessData.CompanyId,
CompanyName: "",
SupperUser: "",
DutyTime: "",
AssessContent: assessContentList,
}
if len(assessContentList) == 0 {
result.AssessContent = []*domain.StaffAssessContent{}
}
if targetUserDesc != nil {
result.CompanyName = targetUserDesc.CompanyName
result.SupperUser = targetUserDesc.SupperUserName
result.DutyTime = targetUserDesc.DutyTime
}
return &result, nil
}
// 获取员工信息描述
func (srv *StaffAssessServeice) getStaffDescrip(transactionContext application.TransactionContext, userid int64) (*adapter.StaffInfo, error) {
//获取用户数据
userRepo := factory.CreateUserRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
userData, err := userRepo.FindOne(map[string]interface{}{
"id": userid,
})
if err != nil {
log.Logger.Error("获取用户信息," + err.Error())
return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取用户信息,"+err.Error())
}
//获取公司数据
companyRep := factory.CreateCompanyRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
companyData, err := companyRep.FindOne(map[string]interface{}{
"id": userData.CompanyId,
})
if err != nil {
log.Logger.Error("获取公司信息," + err.Error())
return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取公司信息,"+err.Error())
}
departmentRepo := factory.CreateDepartmentRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
var supperUserList []*domain.User
if len(userData.DepartmentId) > 0 {
_, departmentList, err := departmentRepo.Find(map[string]interface{}{
"ids": userData.DepartmentId,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取部门信息,"+err.Error())
}
var chargeUserIds []int64
for _, v := range departmentList {
chargeUserIds = append(chargeUserIds, v.ChargeUserIds...)
}
if len(chargeUserIds) > 0 {
_, supperUserList, err = userRepo.Find(map[string]interface{}{
"ids": chargeUserIds,
})
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, "获取员工上级信息,"+err.Error())
}
}
}
userInfo := adapter.StaffInfo{
UserName: userData.Name,
CompanyName: companyData.Name,
SupperUserName: "",
DutyTime: userData.CreatedAt.Local().Format("2006-01-02 15:04:05"),
}
for _, v := range supperUserList {
userInfo.SupperUserName = userInfo.SupperUserName + v.Name + " "
}
return &userInfo, nil
}
// 提交评估数据
func (srv StaffAssessServeice) SaveAssessInfo(param *command.SaveAssessInfoCommand) (map[string]interface{}, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
assessReps := factory.CreateStaffAssessRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
//获取员工的评估
assessData, err := assessReps.FindOne(map[string]interface{}{
"id": param.AssessId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取员工的评估"+err.Error())
}
assessContentRepo := factory.CreateStaffAssessContentRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
//待更新的评估填写信息
assessContentList := []*domain.StaffAssessContent{}
if assessData.Status == domain.StaffAssessCompleted {
//已完成
_, assessContentList, err = assessContentRepo.Find(map[string]interface{}{
"staffAssessId": assessData.Id,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取项目填写内容"+err.Error())
}
} else if assessData.Status == domain.StaffAssessUncompleted {
//未完成
assessContentList, err = srv.getAssessSelfInfoUncompleted(transactionContext, assessData)
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取项目填写内容"+err.Error())
}
}
//处理提交上来的数据
paramContentMap := map[string]command.AssesssContent{}
for i, v := range param.AssessContent {
key := fmt.Sprintf("%s-%s", v.Category, v.Name)
paramContentMap[key] = param.AssessContent[i]
}
//更新的评估填写信息
for _, v := range assessContentList {
key := fmt.Sprintf("%s-%s", v.Category, v.Name)
item, ok := paramContentMap[key]
if !ok {
continue
}
v.Value = item.Value
for ii := range v.Remark {
for _, vvv := range item.Remark {
if v.Remark[ii].Title == vvv.Title {
v.Remark[ii].RemarkText = vvv.RemarkText
break
}
}
}
}
//保存信息
for i := range assessContentList {
_, err = assessContentRepo.Save(assessContentList[i])
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存评估填写内容"+err.Error())
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return map[string]interface{}{
"assessId": assessData.Id,
}, nil
}
// 获取员工被评估的列表
func (srv StaffAssessServeice) ListTargetUserAssess(param *query.ListTargetUserAssessQuery) (map[string]interface{}, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
assessReps := factory.CreateStaffAssessRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
//获取员工的评估
cnt, assessList, err := assessReps.Find(map[string]interface{}{
"assessTaskId": param.AssessTaskId,
"companyId": param.CompanyId,
"targetUserId": param.TargetUserId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "获取员工的评估"+err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return tool_funs.SimpleWrapGridMap(int64(cnt), assessList), nil
}
... ...
package service
import (
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/staff_assess/command"
)
func (srv StaffAssessServeice) InvokCreateStaffAssessTask(param *command.CreateStaffAssessTask) (map[string]interface{}, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
data, err := srv.CreateStaffAssessTask(transactionContext, param)
if err != nil {
return nil, err
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return data, nil
}
... ...
package command
type BatchRemove struct {
CompanyId int64 `json:"company_id"`
UserIds []int64 `json:"user_ids"`
DepartmentIds []int `json:"department_ids"`
}
... ...
... ... @@ -8,6 +8,7 @@ type SaveUserCommand struct {
AdminType int `json:"admin_type"` // 1普通员工 2 主管理员
Name string `json:"name"` // 用户姓名
Status int `json:"status"` // 用户状态(1正常 2禁用)
EntryTime string `json:"entryTime"` //入职日期
Email string `json:"email"` // 邮箱
UserDepartments []struct {
DepartmentId int `json:"department_id" `
... ...
package query
type ListUserQuery struct {
CompanyId int64 `json:"companyId"` // 公司ID
Name string `json:"name"` // 用户姓名
}
... ...
... ... @@ -62,6 +62,13 @@ func (srv SyncDataUserService) FromBusinessAdmin(param *domain.MessageBody) erro
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
err = srv.importUser(&param4)
case "employee/batchRemove":
batchRemove := &command.BatchRemove{}
err = json.Unmarshal(param.Data, batchRemove)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
err = srv.BatchRemove(batchRemove)
default:
log.Logger.Error("action err:" + action)
}
... ... @@ -95,6 +102,7 @@ func (srv SyncDataUserService) AddUser(param *command.SaveUserCommand) error {
Name: param.Name,
Email: param.Email,
Status: param.Status,
EntryTime: param.EntryTime,
UpdatedAt: nowTime,
CreatedAt: nowTime,
}
... ... @@ -153,6 +161,7 @@ func (srv SyncDataUserService) UpdateUser(param *command.SaveUserCommand) error
newUser.AdminType = param.AdminType
newUser.Name = param.Name
newUser.Status = param.Status
newUser.EntryTime = param.EntryTime
newUser.PositionId = param.PositionIds()
newUser.DepartmentId = param.DepartmentIds()
... ... @@ -287,6 +296,7 @@ func (srv SyncDataUserService) importUser(param *command.ImportUserCommand) erro
editUserList[i].Name = mVal.Name
editUserList[i].Status = mVal.Status
editUserList[i].CompanyId = mVal.CompanyId
editUserList[i].EntryTime = mVal.EntryTime
editUserList[i].UpdatedAt = nowTime
_, err = userRepo.Update(editUserList[i])
if err != nil {
... ... @@ -305,6 +315,7 @@ func (srv SyncDataUserService) importUser(param *command.ImportUserCommand) erro
AdminType: param.AddUsers[i].AdminType,
Name: param.AddUsers[i].Name,
Status: param.AddUsers[i].Status,
EntryTime: param.AddUsers[i].EntryTime,
UpdatedAt: nowTime,
DeletedAt: nil,
CreatedAt: nowTime,
... ... @@ -320,3 +331,38 @@ func (srv SyncDataUserService) importUser(param *command.ImportUserCommand) erro
return nil
}
// BatchRemove 调整部门
func (srv SyncDataUserService) BatchRemove(batchRemove *command.BatchRemove) error {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
userRepo := factory.CreateUserRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
if len(batchRemove.UserIds) > 0 {
for _, item := range batchRemove.UserIds {
user, err := userRepo.FindOne(map[string]interface{}{"id": item, "companyId": batchRemove.CompanyId})
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
user.DepartmentId = batchRemove.DepartmentIds
user.UpdatedAt = time.Now()
_, err = userRepo.Update(user)
if err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return nil
}
... ...
package user
import (
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/tool_funs"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/user/query"
)
type UserService struct{}
func (service *UserService) ListUsers(listUserQuery *query.ListUserQuery) (interface{}, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
userRepo := factory.CreateUserRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
count, list, err := userRepo.Find(map[string]interface{}{
"companyId": listUserQuery.CompanyId,
"name": listUserQuery.Name,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
return tool_funs.SimpleWrapGridMap(int64(count), list), nil
}
... ...
... ... @@ -4,10 +4,20 @@ import (
"time"
)
const (
KpiCycleDay int = 1 // 考核周期-日
KpiCycleWeek int = 2 // 考核周期-周
KpiCycleOneMonth int = 3 // 考核周期-月
KpiCycleTwoMonth int = 4 // 考核周期-双月
KpiCycleThreeMonth int = 5 // 考核周期-季度
KpiCycleSixMonth int = 6 // 考核周期-半年
KpiCycleYear int = 7 // 考核周期-年
)
type TemplateSimple struct {
Id int64 `json:"id,string" comment:"模板ID"`
Name string `json:"name" comment:"模板名称"`
CreatedAt time.Time `json:"createdAt" comment:"创建时间"`
CreatedAt time.Time `json:"createdAt" comment:"模板创建时间"`
}
type EvaluationCycle struct {
... ... @@ -17,7 +27,7 @@ type EvaluationCycle struct {
TimeEnd *time.Time `json:"timeEnd" comment:"截至时间"`
CompanyId int64 `json:"companyId,string" comment:"公司ID"`
CreatorId int64 `json:"creatorId,string" comment:"创建人ID"`
KpiCycle int `json:"state" comment:"考核周期(1日、2周、3月)"`
KpiCycle int `json:"kpiCycle" comment:"考核周期(1日、2周、3月)"`
CreatedAt time.Time `json:"createdAt" comment:"创建时间"`
UpdatedAt time.Time `json:"updatedAt" comment:"更新时间"`
DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"`
... ...
... ... @@ -5,13 +5,14 @@ import (
)
type EvaluationCycleTemplate struct {
Id int64 `json:"id,string" comment:"模板ID"`
Name string `json:"name" comment:"模板名称"`
Template *EvaluationTemplate `json:"template" comment:"模板数据"`
CycleId int64 `json:"cycleId,string" comment:"周期ID"`
CreatedAt time.Time `json:"createdAt" comment:"创建时间"`
UpdatedAt time.Time `json:"updatedAt" comment:"更新时间"`
DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"`
Id int64 `json:"id,string" comment:"模板ID"`
Name string `json:"name" comment:"模板名称"`
TemplateCreatedAt time.Time `json:"templateCreatedAt" comment:"模板创建时间"`
Template *EvaluationTemplate `json:"template" comment:"模板数据"`
CycleId int64 `json:"cycleId,string" comment:"周期ID"`
CreatedAt time.Time `json:"createdAt" comment:"创建时间"`
UpdatedAt time.Time `json:"updatedAt" comment:"更新时间"`
DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"`
}
type EvaluationCycleTemplateRepository interface {
... ...
... ... @@ -24,16 +24,6 @@ const (
)
const (
KpiCycleDay int = 1 // 考核周期-日
KpiCycleWeek int = 2 // 考核周期-周
KpiCycleOneMonth int = 3 // 考核周期-月
KpiCycleTwoMonth int = 4 // 考核周期-双月
KpiCycleThreeMonth int = 5 // 考核周期-季度
KpiCycleSixMonth int = 6 // 考核周期-半年
KpiCycleYear int = 7 // 考核周期-年
)
type EntryItem struct {
Title string `json:"title" comment:"填写标题"`
HintText string `json:"hintText" comment:"文本内容提示"`
... ... @@ -41,12 +31,14 @@ type EntryItem struct {
// NodeContent 评估内容
type NodeContent struct {
Category string `json:"category" comment:"类别"`
Name string `json:"name" comment:"名称"`
RuleId string `json:"ruleId" comment:"评估规则ID"`
PromptTitle string `json:"promptTitle" comment:"提示项标题"`
PromptText string `json:"promptText" comment:"提示项正文"`
EntryItems []*EntryItem `json:"entryItems" comment:"填写项"`
Category string `json:"category" comment:"类别"`
Name string `json:"name" comment:"名称"`
RuleId int64 `json:"ruleId,string" comment:"评估规则ID"`
Rule *EvaluationRule `json:"rule" comment:"评估规则对象"`
Weight int `json:"weight" comment:"权重"`
PromptTitle string `json:"promptTitle" comment:"提示项标题"`
PromptText string `json:"promptText" comment:"提示项正文"`
EntryItems []*EntryItem `json:"entryItems" comment:"填写项"`
}
//// NodeAllInvite 360°邀请
... ... @@ -68,9 +60,7 @@ type LinkNode struct {
NodeContents []*NodeContent `json:"nodeContents" comment:"环节-评估内容"`
TimeStart *time.Time `json:"timeStart" comment:"起始时间"`
TimeEnd *time.Time `json:"timeEnd" comment:"截至时间"`
KpiCycle int `json:"state" comment:"考核周期(1日、2周、3月)"`
//NodeAllInvite *NodeAllInvite `json:"nodeAllInvite" comment:"360°邀请人员"`
KpiCycle int `json:"kpiCycle" comment:"考核周期(1日、2周、3月)"`
}
// 评估模板
... ...
package domain
import (
"time"
)
type NodeTask struct {
Id int64 `json:"id,string" comment:"ID"`
CompanyId int64 `json:"companyId,string" comment:"公司ID"`
CycleId int64 `json:"cycleId,string" comment:"周期ID"`
ProjectId int64 `json:"projectId,string" comment:"项目ID"`
NodeId int64 `json:"nodeId,string" comment:"节点ID"`
NodeType int `json:"nodeType" comment:"环节类型"`
NodeName string `json:"nodeName" comment:"环节名称"`
NodeDescribe string `json:"nodeDescribe" comment:"环节描述"`
NodeSort int `json:"nodeSort" comment:"环节顺序"`
TimeStart *time.Time `json:"timeStart" comment:"起始时间"`
TimeEnd *time.Time `json:"timeEnd" comment:"截至时间"`
KpiCycle int `json:"kpiCycle" comment:"考核周期(1日、2周、3月)"`
NextSentAt *time.Time `json:"nextSentAt" comment:"下一次发送时间"`
CreatedAt time.Time `json:"createdAt" comment:"创建时间"`
UpdatedAt time.Time `json:"updatedAt" comment:"更新时间"`
DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"`
}
type NodeTaskRepository interface {
Insert(task *NodeTask) (*NodeTask, error)
Remove(task *NodeTask) (*NodeTask, error)
FindOne(queryOptions map[string]interface{}) (*NodeTask, error)
Find(queryOptions map[string]interface{}) ([]*NodeTask, error)
}
... ...
package domain
import (
"time"
)
type NodeTimerTask struct {
Id int64 `json:"id,string" comment:"ID"`
CompanyId int64 `json:"companyId,string" comment:"公司ID"`
CycleId int64 `json:"cycleId,string" comment:"周期ID"`
ProjectId int64 `json:"projectId,string" comment:"项目ID"`
NodeId int64 `json:"nodeId,string" comment:"节点ID"`
LastSentAt *time.Time `json:"lastSentAt" comment:"最后一次发送时间"`
NextSentAt *time.Time `json:"nextSentAt" comment:"下一次发送时间"`
CreatedAt time.Time `json:"createdAt" comment:"创建时间"`
UpdatedAt time.Time `json:"updatedAt" comment:"更新时间"`
DeletedAt *time.Time `json:"deletedAt" comment:"删除时间"`
}
type NodeTimerTaskRepository interface {
Insert(template *NodeTimerTask) (*NodeTimerTask, error)
Remove(template *NodeTimerTask) (*NodeTimerTask, error)
FindOne(queryOptions map[string]interface{}) (*NodeTimerTask, error)
Find(queryOptions map[string]interface{}, excludeColumns ...string) (int64, []*NodeTimerTask, error)
Count(queryOptions map[string]interface{}) (int64, error)
}
package domain
import (
"errors"
"strings"
)
type PerformanceApplicationForm struct {
DimensionName string //维度名称
ModuleName string //模块名称
Weight string //权重
Standard string //标准
Task string //任务、指标
}
type PerformanceDimension struct {
Name string `json:"name"` //维度名称
PerformanceModule []*PerformanceModule `json:"performanceModule"` //模块
}
type PerformanceModule struct {
ModuleName string `json:"moduleName"` //模块名称
Weight string `json:"weight"` //权重
Standard string `json:"standard"` //标准(结构化的成果描述)
Target []*PerformanceTarget `json:"performanceTarget"` //任务\指标
}
type PerformanceTarget struct {
Task string `json:"task"`
}
func LoadPerformanceDimensions(rows [][]string) ([]*PerformanceDimension, error) {
formRows := make([]*PerformanceApplicationForm, 0)
var dimensionName, moduleName, taskName, weightName, standardName string
for key, item := range rows {
if key < 3 {
continue
}
if len(item) >= 1 {
if item[0] == "部门长审核" || strings.Contains(item[0], "审核") {
break
}
}
form := &PerformanceApplicationForm{}
//维度名称
if len(item) > 1 && item[1] != "" {
dimensionName = item[1]
}
form.DimensionName = dimensionName
//模块名称
if len(item) > 3 && item[3] != "" {
moduleName = item[3]
}
form.ModuleName = moduleName
//指标任务
if len(item) > 4 && item[4] != "" {
taskName = item[4]
}
form.Task = taskName
//权重
if len(item) > 6 && item[6] != "" {
weightName = item[6]
}
form.Weight = weightName
//标准
if len(item) > 7 && item[7] != "" {
standardName = item[7]
}
form.Standard = standardName
formRows = append(formRows, form)
}
dimensions := make([]*PerformanceDimension, 0)
//按维度分
mapData := make(map[string][]*PerformanceApplicationForm)
//维度顺序
sortBy := make([]string, 0)
for _, item := range formRows {
if _, ok := mapData[item.DimensionName]; !ok {
mapData[item.DimensionName] = make([]*PerformanceApplicationForm, 0)
sortBy = append(sortBy, item.DimensionName)
}
mapData[item.DimensionName] = append(mapData[item.DimensionName], item)
}
for dimensionName, item := range mapData {
dimension := &PerformanceDimension{
Name: dimensionName,
}
modules, err := loadPerformanceModule(item)
if err != nil {
return dimensions, err
}
dimension.PerformanceModule = modules
dimensions = append(dimensions, dimension)
}
result := make([]*PerformanceDimension, 0)
for _, name := range sortBy {
for _, item := range dimensions {
if name == item.Name {
result = append(result, item)
}
}
}
return result, nil
}
// 筛选出模块
func loadPerformanceModule(forms []*PerformanceApplicationForm) ([]*PerformanceModule, error) {
mapData := make(map[string][]*PerformanceApplicationForm)
sortBy := make([]string, 0)
for _, item := range forms {
if _, ok := mapData[item.ModuleName]; !ok {
mapData[item.ModuleName] = make([]*PerformanceApplicationForm, 0)
sortBy = append(sortBy, item.ModuleName)
}
mapData[item.ModuleName] = append(mapData[item.ModuleName], item)
}
modules := make([]*PerformanceModule, 0)
for moduleName, item := range mapData {
if moduleName == "" {
return modules, errors.New(item[0].DimensionName + "对应的模块不能为空")
}
weightName, err := getWeight(item)
if err != nil {
return modules, err
}
standardName, err := getStandard(item)
if err != nil {
return modules, err
}
tasks, err := getTasks(item)
if err != nil {
return modules, err
}
module := &PerformanceModule{
ModuleName: moduleName,
Weight: weightName,
Standard: standardName,
Target: tasks,
}
modules = append(modules, module)
}
result := make([]*PerformanceModule, 0)
for _, name := range sortBy {
for _, item := range modules {
if name == item.ModuleName {
result = append(result, item)
}
}
}
return result, nil
}
// 获取权重
func getWeight(items []*PerformanceApplicationForm) (string, error) {
if len(items) <= 0 {
return "", nil
}
var name string
for _, item := range items {
if name == "" {
name = item.Weight
}
if name != item.Weight {
return "", errors.New(item.ModuleName + " 对应的权重值不一致")
}
}
if name == "/" {
name = "0%"
}
return name, nil
}
// 获取标准
func getStandard(items []*PerformanceApplicationForm) (string, error) {
if len(items) <= 0 {
return "", nil
}
var name string
for _, item := range items {
if name == "" {
name = item.Standard
}
if name != item.Standard {
return "", errors.New(item.ModuleName + " 对应的标准值不一致")
}
}
return name, nil
}
// 获取任务
func getTasks(items []*PerformanceApplicationForm) ([]*PerformanceTarget, error) {
tasks := make([]*PerformanceTarget, 0)
for _, item := range items {
target := &PerformanceTarget{Task: item.Task}
tasks = append(tasks, target)
}
return tasks, nil
}
... ...
... ... @@ -20,4 +20,5 @@ type PositionRepository interface {
Update(position *Position) (*Position, error)
Remove(ids []int64) error
FindOne(queryOption map[string]interface{}) (*Position, error)
Find(queryOptions map[string]interface{}) (int, []*Position, error)
}
... ...
... ... @@ -10,7 +10,7 @@ const (
type Role struct {
Id int64 `json:"id,string"`
Name string `json:"name"`
Type int `json:"type"`
Type int `json:"type" pg:",use_zero"`
Description string `json:"description"`
CompanyId int64 `json:"companyId,string"`
CreatedAt time.Time `json:"createdAt"`
... ...
... ... @@ -7,7 +7,7 @@ type StaffAssessType string
const (
AssessSelf StaffAssessType = "self" //自评
AssessSuper StaffAssessType = "super" //上级评估
AssessSuper StaffAssessType = "supper" //上级评估
AssessInviteSameSuper StaffAssessType = "invite_same_super" //360 邀请评估-相同上级的同事
AssessInviteDiffSuper StaffAssessType = "invite_diff_super" //360 邀请评估-不同上级的同事
)
... ...
... ... @@ -4,22 +4,27 @@ import "time"
//填写的评估内容
type StaffAssessContent struct {
Id int `json:"id"` //id
StaffAssessId int `json:"staffAssessId"` //用户需要的评估项id
SortBy int `json:"sortBy"` //排序
Category string `json:"category"` //类别
Title string `json:"title"` //问题标题
Remark string `json:"remark"` //填写的反馈
Rate string `json:"rate"` //评估填写的值
ReteResult string `json:"reteResult"` //评估的结果
CreatedAt time.Time `json:"createdAt"` //数据创建时间
UpdatedAt time.Time `json:"updatedAt"` //数据更新时间
//TODO
Id int `json:"id"` //id
StaffAssessId int `json:"staffAssessId"` //用户需要的评估项id
SortBy int `json:"sortBy"` //排序
Category string `json:"category"` //类别
Name string `json:"name"` //名称
PromptTitle string `json:"promptTitle"` //提示项标题
PromptText string `json:"promptText"` //提示项正文
Remark []AssessContemtRemark `json:"remark"` //填写的反馈
Value string `json:"value"` //评估填写的值
ReteResult string `json:"reteResult"` //评估的结果
Rule EvaluationRule `json:"rule"` //评估的选项规则
Weight int `json:"weight" ` //"权重"
CreatedAt time.Time `json:"createdAt"` //数据创建时间
UpdatedAt time.Time `json:"updatedAt"` //数据更新时间
DeletedAt *time.Time `json:"deletedAt"`
}
type AssessContemtRemark struct {
Title string `json:"title"` //comment:"填写标题"
RemarkText string `json:"hintText"` // comment:"填写文本内容"
Title string `json:"title"` //comment:"填写标题"
HintText string `json:"hintText"` // comment:"文本内容提示"
RemarkText string `json:"remarkText"` // comment:"填写文本内容"
}
type StaffAssessContentRepository interface {
... ...
... ... @@ -2,19 +2,6 @@ package domain
import "time"
//评估任务重复执行的方式
// type AssessTaskRepeatWay string
// const (
// AssessTaskRepeatDay AssessTaskRepeatWay = "day" //按天重复
// AssessTaskRepeatWeek AssessTaskRepeatWay = "week" //按周重复
// AssessTaskRepeatMonth AssessTaskRepeatWay = "month" //按月
// AssessTaskRepeatMonthDouble AssessTaskRepeatWay = "month_double" //按双月
// AssessTaskRepeatQuarter AssessTaskRepeatWay = "quarter" //按季度
// AssessTaskRepeatYearHalf AssessTaskRepeatWay = "year_half" //按半年
// AssessTaskRepeatYear AssessTaskRepeatWay = "year" //按年
// )
// 执行评估的任务列表
type StaffAssessTask struct {
Id int `json:"id"`
... ... @@ -23,6 +10,7 @@ type StaffAssessTask struct {
EvaluationProjectName string `json:"evaluationProjectName"` //项目名称
CycleId int64 `json:"cycleId"` //对应的周期id
CycleName string `json:"cycleName"` //对应周期的名称
BeginDay string `json:"beginDay"` //绩效考核日期
BeginTime time.Time `json:"beginTime"` //绩效考核开始时间
EndTime time.Time `json:"endTime"` //绩效考核截止时间
StepList []AssessTaskStep `json:"stepList"` //考评的流程
... ...
... ... @@ -2,13 +2,18 @@ package domain
//员工基本信息描述
type StaffDesc struct {
UserId int `json:"userId"` //用户id
Account string `json:"account"` //用户的账号
UserName string `json:"userName"` //用户的名称
UserId int `json:"userId,string"` //用户id
Account string `json:"account"` //用户的账号
UserName string `json:"userName"` //用户的名称
}
//员工的部门
type StaffDepartment struct {
DepartmentId int `json:"departmentId"` //部门id
DepartmentName string `json:"departmentName"` //部门名称
DepartmentId int `json:"departmentId,string"` //部门id
DepartmentName string `json:"departmentName"` //部门名称
}
type StaffPosition struct {
PositionId int `json:"positionId,string"`
PositionName string `json:"positionName"`
}
... ...
... ... @@ -3,19 +3,20 @@ package domain
import "time"
type User struct {
Id int64 // 用户Id
Account string // 用户账号
AvatarUrl string // 用户头像URL
CompanyId int64 // 公司编号
AdminType int // 1普通员工 2 主管理员
Name string // 用户姓名
Email string // 邮箱
Status int // 用户状态(1正常 2禁用)
DepartmentId []int // 用户归属的部门
PositionId []int //用户职位
UpdatedAt time.Time // 更新时间
DeletedAt *time.Time
CreatedAt time.Time
Id int64 `json:"id,string"` // 用户Id
Account string `json:"account"` // 用户账号
AvatarUrl string `json:"avatarUrl"` // 用户头像URL
CompanyId int64 `json:"companyId"` // 公司编号
AdminType int `json:"adminType"` // 1普通员工 2 主管理员
Name string `json:"name"` // 用户姓名
Email string `json:"email"` // 邮箱
Status int `json:"status"` // 用户状态(1正常 2禁用)
DepartmentId []int `json:"departmentId"` // 用户归属的部门
PositionId []int `json:"PositionId"` //用户职位
EntryTime string `json:"entryTime"` //入职日期
UpdatedAt time.Time `json:"updatedAt"` // 更新时间
DeletedAt *time.Time `json:"deletedAt"`
CreatedAt time.Time `json:"createdAt"`
}
// 1普通员工 2 主管理员
... ...
package dao
import (
"strconv"
"github.com/go-pg/pg/v10"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
type StaffAssessDao struct {
transactionContext *pgTransaction.TransactionContext
}
func NewStaffAssessDao(options map[string]interface{}) *StaffAssessDao {
var transactionContext *pgTransaction.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pgTransaction.TransactionContext)
}
return &StaffAssessDao{
transactionContext: transactionContext,
}
}
type CountData struct {
TargetUserId int
InviteTotal int
InviteCompleted int
}
// 获取员工邀请的人完成360评估的数量
func (d *StaffAssessDao) CountInviteAssessByTargetUser(userIds []int, assessTaskId int) ([]CountData, error) {
sqlStr := `SELECT staff_assess.target_user->>'userId' as target_user_id,
count(staff_assess."id") AS invite_total,
sum(
case WHEN staff_assess.status='completed' THEN 1
ELSE 0 END
) as invite_completed
FROM staff_assess
WHERE staff_assess.target_user->>'userId' IN(?)
AND staff_assess.types IN ('invite_same_super','invite_diff_super')
AND staff_assess.staff_assess_task_id = ?
GROUP BY userId`
userIdList := []string{}
for _, v := range userIds {
uid := strconv.Itoa(v)
userIdList = append(userIdList, uid)
}
condition := []interface{}{
pg.In(userIdList), assessTaskId,
}
tx := d.transactionContext.PgTx
result := []CountData{}
_, err := tx.Query(&result, sqlStr, condition...)
return result, err
}
// 搜索 executorId 参与的评估任务
func (d *StaffAssessDao) SearchAssessTaskMe(executorId int, companyId int, limit int, offset int) ([]*domain.StaffAssessTask, error) {
if limit < 0 {
limit = 20
}
if offset < 0 {
offset = 0
}
sqlStr := `SELECT DISTINCT staff_assess_task.* FROM staff_assess_task
JOIN staff_assess ON staff_assess_task."id" = staff_assess."staff_assess_task_id"
WHERE staff_assess.company_id=?
and staff_assess.executor->>'userId'='?'
limit ? offset ?
`
tx := d.transactionContext.PgTx
condition := []interface{}{
companyId, executorId, limit, offset,
}
result := []*domain.StaffAssessTask{}
_, err := tx.Query(&result, sqlStr, condition...)
return result, err
}
// 搜索 executorId 参与的评估任务
func (d *StaffAssessDao) CountAssessTaskMe(executorId int, companyId int) (int, error) {
sqlStr := `SELECT count( DISTINCT staff_assess_task."id") FROM staff_assess_task
JOIN staff_assess ON staff_assess_task."id" = staff_assess."staff_assess_task_id"
WHERE staff_assess.company_id=?
and staff_assess.executor->>'userId'='?'
`
tx := d.transactionContext.PgTx
condition := []interface{}{
companyId, executorId,
}
result := 0
_, err := tx.QueryOne(pg.Scan(&result), sqlStr, condition...)
return result, err
}
... ...
... ... @@ -40,8 +40,10 @@ func init() {
&models.EvaluationCycle{},
&models.EvaluationCycleTemplate{},
&models.EvaluationProject{},
&models.NodeTask{},
&models.StaffAssess{},
&models.StaffAssessTask{},
&models.StaffAssessContent{},
}
for _, model := range tables {
err := DB.Model(model).CreateTable(&orm.CreateTableOptions{
... ...
... ... @@ -6,12 +6,13 @@ import (
)
type EvaluationCycleTemplate struct {
tableName struct{} `comment:"评估周期模板" pg:"evaluation_cycle_template"`
Id int64 `comment:"模板ID" pg:"pk:id"`
Name string `comment:"模板名称"`
Template *domain.EvaluationTemplate `comment:"模板数据"`
CycleId int64 `comment:"周期ID"`
CreatedAt time.Time `comment:"创建时间"`
UpdatedAt time.Time `comment:"更新时间"`
DeletedAt *time.Time `comment:"删除时间"`
tableName struct{} `comment:"评估周期模板" pg:"evaluation_cycle_template"`
Id int64 `comment:"模板ID" pg:"pk:id"`
Name string `comment:"模板名称"`
TemplateCreatedAt time.Time `comment:"模板创建时间"`
Template *domain.EvaluationTemplate `comment:"模板数据"`
CycleId int64 `comment:"周期ID"`
CreatedAt time.Time `comment:"创建时间"`
UpdatedAt time.Time `comment:"更新时间"`
DeletedAt *time.Time `comment:"删除时间"`
}
... ...
... ... @@ -17,5 +17,5 @@ type EvaluationRule struct {
Score domain.Score `comment:"评分"`
CreatedAt time.Time `comment:"创建时间"`
UpdatedAt time.Time `comment:"更新时间"`
DeletedAt *time.Time `comment:"删除时间" pg:",soft_delete"`
DeletedAt *time.Time `comment:"删除时间"`
}
... ...
package models
import (
"time"
)
type NodeTask struct {
tableName struct{} `comment:"环节任务" pg:"node_task"`
Id int64 `comment:"ID" pg:"pk:id"`
CompanyId int64 `comment:"公司ID"`
CycleId int64 `comment:"周期ID"`
ProjectId int64 `comment:"项目ID"`
NodeId int64 `comment:"环节ID"`
NodeType int `comment:"环节类型"`
NodeName string `comment:"环节名称"`
NodeDescribe string `comment:"环节描述"`
NodeSort int `comment:"环节顺序"`
TimeStart *time.Time `comment:"起始时间"`
TimeEnd *time.Time `comment:"截至时间"`
KpiCycle int `comment:"考核周期(1日、2周、3月)"`
NextSentAt *time.Time `comment:"下一次发送时间"`
CreatedAt time.Time `comment:"创建时间"`
UpdatedAt time.Time `comment:"更新时间"`
DeletedAt *time.Time `comment:"删除时间"`
}
... ...
... ... @@ -3,13 +3,13 @@ package models
import "time"
type Role struct {
tableName struct{} `pg:"role" comment:"角色"`
Id int64 `pg:"pk:id" comment:"ID"`
tableName struct{} `comment:"角色" pg:"role"`
Id int64 `comment:"ID" pg:"pk:id"`
Name string `comment:"角色名称"`
Type int `comment:"角色类型(0角色可删、1系统预置角色不可删)" pg:",use_zero"`
Description string `comment:"角色描述"`
CompanyId int64 `comment:"公司ID"`
CreatedAt time.Time `comment:"创建时间"`
UpdatedAt time.Time `comment:"更新时间"`
DeletedAt *time.Time `comment:"删除时间" pg:",soft_delete"`
DeletedAt *time.Time `comment:"删除时间"`
}
... ...
... ... @@ -10,5 +10,5 @@ type RoleUser struct {
CompanyId int64 `comment:"公司ID"`
CreatedAt time.Time `comment:"创建时间"`
UpdatedAt time.Time `comment:"更新时间"`
DeletedAt *time.Time `comment:"删除时间" pg:",soft_delete"`
DeletedAt *time.Time `comment:"删除时间"`
}
... ...
package models
import "time"
import (
"time"
//填写的评估内容
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
// 填写的评估内容
type StaffAssessContent struct {
tableName struct{} `pg:"staff_assess_content" comment:"填写的评估项"`
Id int `pg:",pk"` //id
StaffAssessId int //用户需要的评估项id
SortBy int //排序
Category string //类别
Title string //问题标题
Remark string //填写的反馈
Rate string //评估填写的值
ReteResult string //评估的结果
tableName struct{} `pg:"staff_assess_content" comment:"填写的评估项"`
Id int `pg:",pk"` //id
StaffAssessId int //用户需要的评估项id
SortBy int //排序
Category string //类别
Name string //名称
PromptTitle string //问题标题
PromptText string //提示项正文
Value string //评估填写的值
ReteResult string //评估的结果
Rule domain.EvaluationRule
Remark []domain.AssessContemtRemark
Weight int //权重
CreatedAt time.Time //数据创建时间
UpdatedAt time.Time //数据更新时间
DeletedAt *time.Time
}
type StaffAssessContentRepository interface {
... ...
... ... @@ -17,6 +17,7 @@ type StaffAssessTask struct {
CycleName string //对应周期的名称
ExecutorId []int //参与考评的人
StepList []domain.AssessTaskStep `` //考评的流程
BeginDay string //日期 天 2006-01-02
BeginTime time.Time //开始时间
EndTime time.Time //截止时间
CreatedAt time.Time //数据创建时间
... ...
... ... @@ -14,6 +14,7 @@ type User struct {
Status int // 用户状态(1正常 2禁用)
DepartmentId []int // 用户归属的部门
PositionId []int // 用户职位
EntryTime string //入职日期
CreatedAt time.Time // 创建时间
UpdatedAt time.Time // 更新时间
DeletedAt *time.Time `pg:",soft_delete"` // 删除时间
... ...
... ... @@ -92,7 +92,7 @@ func (repo *DepartmentRepository) FindOne(queryOptions map[string]interface{}) (
func (repo *DepartmentRepository) Find(queryOptions map[string]interface{}) (int, []*domain.Department, error) {
tx := repo.transactionContext.PgTx
dparmentModel := []models.Department{}
query := tx.Model(&dparmentModel).Where("delete_at isnull")
query := tx.Model(&dparmentModel)
if v, ok := queryOptions["id"]; ok {
query.Where("id=?", v)
}
... ...
... ... @@ -119,19 +119,23 @@ func (repo *EvaluationCycleRepository) Find(queryOptions map[string]interface{})
query := tx.Model(&m).Where("deleted_at isnull")
if v, ok := queryOptions["name"]; ok && len(v.(string)) > 0 {
if v, ok := queryOptions["name"].(string); ok && len(v) > 0 {
query.Where("name LIKE ?", v)
}
if v, ok := queryOptions["ids"]; ok {
query.Where("id in (?)", pg.In(v))
}
if v, ok := queryOptions["companyId"]; ok {
query.Where("company_id = ?", v)
}
if v, ok := queryOptions["limit"].(int); ok {
query.Limit(v)
if v, ok := queryOptions["limit"].(int64); ok {
query.Limit(int(v))
}
if v, ok := queryOptions["offset"].(int); ok {
query.Offset(v)
if v, ok := queryOptions["offset"].(int64); ok {
query.Offset(int(v))
}
if v, ok := queryOptions["timeStart"]; ok {
... ... @@ -170,7 +174,7 @@ func (repo *EvaluationCycleRepository) Count(queryOptions map[string]interface{}
query.Where("id != ?", notId)
}
if v, ok := queryOptions["name"]; ok {
if v, ok := queryOptions["name"].(string); ok && len(v) > 0 {
query.Where("name = ?", v)
}
... ...
... ... @@ -22,25 +22,27 @@ func NewEvaluationCycleTemplateRepository(transactionContext *pgTransaction.Tran
func (repo *EvaluationCycleTemplateRepository) TransformToDomain(m *models.EvaluationCycleTemplate) domain.EvaluationCycleTemplate {
return domain.EvaluationCycleTemplate{
Id: m.Id,
Name: m.Name,
Template: m.Template,
CycleId: m.CycleId,
CreatedAt: m.CreatedAt,
UpdatedAt: m.UpdatedAt,
DeletedAt: m.DeletedAt,
Id: m.Id,
Name: m.Name,
TemplateCreatedAt: m.TemplateCreatedAt,
Template: m.Template,
CycleId: m.CycleId,
CreatedAt: m.CreatedAt,
UpdatedAt: m.UpdatedAt,
DeletedAt: m.DeletedAt,
}
}
func (repo *EvaluationCycleTemplateRepository) TransformToModel(d *domain.EvaluationCycleTemplate) models.EvaluationCycleTemplate {
return models.EvaluationCycleTemplate{
Id: d.Id,
Name: d.Name,
Template: d.Template,
CycleId: d.CycleId,
CreatedAt: d.CreatedAt,
UpdatedAt: d.UpdatedAt,
DeletedAt: d.DeletedAt,
Id: d.Id,
Name: d.Name,
TemplateCreatedAt: d.TemplateCreatedAt,
Template: d.Template,
CycleId: d.CycleId,
CreatedAt: d.CreatedAt,
UpdatedAt: d.UpdatedAt,
DeletedAt: d.DeletedAt,
}
}
... ... @@ -58,9 +60,14 @@ func (repo *EvaluationCycleTemplateRepository) Insert(d *domain.EvaluationCycleT
d.Id = id
d.CreatedAt = time.Now()
d.UpdatedAt = d.CreatedAt
// 模板对象ID也更新
if d.Template != nil {
d.Template.Id = id
}
} else {
d.UpdatedAt = time.Now()
}
m := repo.TransformToModel(d)
tx := repo.transactionContext.PgTx
var err error
... ... @@ -146,11 +153,11 @@ func (repo *EvaluationCycleTemplateRepository) Find(queryOptions map[string]inte
query.Where("cycle_id = ?", v)
}
if v, ok := queryOptions["limit"].(int); ok {
query.Limit(v)
if v, ok := queryOptions["limit"].(int64); ok {
query.Limit(int(v))
}
if v, ok := queryOptions["offset"].(int); ok {
query.Offset(v)
if v, ok := queryOptions["offset"].(int64); ok {
query.Offset(int(v))
}
count, err := query.SelectAndCount()
... ... @@ -179,7 +186,7 @@ func (repo *EvaluationCycleTemplateRepository) Count(queryOptions map[string]int
query.Where("id != ?", v)
}
if v, ok := queryOptions["name"]; ok {
if v, ok := queryOptions["name"].(string); ok && len(v) > 0 {
query.Where("name = ?", v)
}
... ...
... ... @@ -131,8 +131,12 @@ func (repo *EvaluationProjectRepository) Find(queryOptions map[string]interface{
query.ExcludeColumn(excludeColumns...)
}
if v, ok := queryOptions["name"]; ok {
query.Where("name = ?", v)
if v, ok := queryOptions["ids"]; ok {
query.Where("id in (?)", pg.In(v))
}
if v, ok := queryOptions["name"].(string); ok && len(v) > 0 {
query.Where("name LIKE ?", v)
}
if v, ok := queryOptions["companyId"]; ok {
... ... @@ -147,23 +151,20 @@ func (repo *EvaluationProjectRepository) Find(queryOptions map[string]interface{
query.Where("state = ?", v)
}
if v, ok := queryOptions["pmpIds"]; ok {
pmpIds := v.([]string)
if len(pmpIds) > 0 {
query.WhereGroup(func(query *pg.Query) (*pg.Query, error) {
for i := range pmpIds {
query.WhereOr("pmp_ids @> ?", pmpIds[i])
}
return query, nil
})
}
if v, ok := queryOptions["pmpIds"].([]string); ok && len(v) > 0 {
query.WhereGroup(func(query *pg.Query) (*pg.Query, error) {
for i := range v {
query.WhereOr("pmp_ids @> ?", `"`+v[i]+`"`)
}
return query, nil
})
}
if v, ok := queryOptions["limit"].(int); ok {
query.Limit(v)
if v, ok := queryOptions["limit"].(int64); ok {
query.Limit(int(v))
}
if v, ok := queryOptions["offset"].(int); ok {
query.Offset(v)
if v, ok := queryOptions["offset"].(int64); ok {
query.Offset(int(v))
}
count, err := query.SelectAndCount()
... ... @@ -192,7 +193,7 @@ func (repo *EvaluationProjectRepository) Count(queryOptions map[string]interface
query.Where("id != ?", v)
}
if v, ok := queryOptions["name"]; ok {
if v, ok := queryOptions["name"].(string); ok && len(v) > 0 {
query.Where("name = ?", v)
}
... ...
... ... @@ -123,7 +123,11 @@ func (repo *EvaluationRuleRepository) Find(queryOptions map[string]interface{})
query.Where("name LIKE ? or remark LIKE ?", v, v)
}
if v, ok := queryOptions["name"]; ok {
if v, ok := queryOptions["ids"]; ok {
query.Where("id in(?)", pg.In(v))
}
if v, ok := queryOptions["name"].(string); ok && len(v) > 0 {
query.Where("name = ?", v)
}
... ... @@ -139,13 +143,16 @@ func (repo *EvaluationRuleRepository) Find(queryOptions map[string]interface{})
query.Where("type = ?", v)
}
if v, ok := queryOptions["limit"].(int); ok {
query.Limit(v)
if v, ok := queryOptions["limit"].(int64); ok {
query.Limit(int(v))
}
if v, ok := queryOptions["offset"].(int); ok {
query.Offset(v)
if v, ok := queryOptions["offset"].(int64); ok {
query.Offset(int(v))
}
// 按创建时间降序
query.Order("created_at DESC")
count, err := query.SelectAndCount()
if err != nil {
return 0, nil, err
... ... @@ -172,7 +179,7 @@ func (repo *EvaluationRuleRepository) Count(queryOptions map[string]interface{})
query.Where("id != ?", v)
}
if v, ok := queryOptions["name"]; ok {
if v, ok := queryOptions["name"].(string); ok && len(v) > 0 {
query.Where("name = ?", v)
}
... ...
... ... @@ -129,7 +129,7 @@ func (repo *EvaluationTemplateRepository) Find(queryOptions map[string]interface
query.Where("id != ?", v)
}
if v, ok := queryOptions["name"]; ok && len(v.(string)) > 0 {
if v, ok := queryOptions["name"].(string); ok && len(v) > 0 {
query.Where("name LIKE ?", v)
}
... ... @@ -142,16 +142,27 @@ func (repo *EvaluationTemplateRepository) Find(queryOptions map[string]interface
}
if v, ok := queryOptions["createdAt"]; ok {
query.Where("created_at = ?", v)
ts := v.(string)
t, err := time.ParseInLocation("2006-01-02", ts, time.Local)
if err == nil {
year, month, day := t.Date()
begin := time.Date(year, month, day, 0, 0, 0, 0, time.Local)
end := time.Date(year, month, day, 23, 59, 59, 0, time.Local)
query.Where("created_at >= ?", begin)
query.Where("created_at <= ?", end)
}
}
if v, ok := queryOptions["limit"].(int); ok {
query.Limit(v)
if v, ok := queryOptions["limit"].(int64); ok {
query.Limit(int(v))
}
if v, ok := queryOptions["offset"].(int); ok {
query.Offset(v)
if v, ok := queryOptions["offset"].(int64); ok {
query.Offset(int(v))
}
// 按创建时间降序
query.Order("created_at DESC")
count, err := query.SelectAndCount()
if err != nil {
return 0, nil, err
... ... @@ -178,7 +189,7 @@ func (repo *EvaluationTemplateRepository) Count(queryOptions map[string]interfac
query.Where("id != ?", v)
}
if v, ok := queryOptions["name"]; ok {
if v, ok := queryOptions["name"].(string); ok && len(v) > 0 {
query.Where("name = ?", v)
}
... ...
package repository
import (
"errors"
"fmt"
"time"
"github.com/go-pg/pg/v10"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/utils"
)
type NodeTaskRepository struct {
transactionContext *pgTransaction.TransactionContext
}
func NewNodeTaskRepository(transactionContext *pgTransaction.TransactionContext) *NodeTaskRepository {
return &NodeTaskRepository{transactionContext: transactionContext}
}
func (repo *NodeTaskRepository) TransformToDomain(m *models.NodeTask) domain.NodeTask {
return domain.NodeTask{
Id: m.Id,
CompanyId: m.CompanyId,
CycleId: m.CycleId,
ProjectId: m.ProjectId,
NodeId: m.NodeId,
NodeType: m.NodeType,
NodeName: m.NodeName,
NodeDescribe: m.NodeDescribe,
NodeSort: m.NodeSort,
TimeStart: m.TimeStart,
TimeEnd: m.TimeEnd,
KpiCycle: m.KpiCycle,
NextSentAt: m.NextSentAt,
CreatedAt: m.CreatedAt,
UpdatedAt: m.UpdatedAt,
DeletedAt: m.DeletedAt,
}
}
func (repo *NodeTaskRepository) TransformToModel(d *domain.NodeTask) models.NodeTask {
return models.NodeTask{
Id: d.Id,
CompanyId: d.CompanyId,
CycleId: d.CycleId,
ProjectId: d.ProjectId,
NodeId: d.NodeId,
NodeType: d.NodeType,
NodeName: d.NodeName,
NodeDescribe: d.NodeDescribe,
NodeSort: d.NodeSort,
TimeStart: d.TimeStart,
TimeEnd: d.TimeEnd,
KpiCycle: d.KpiCycle,
NextSentAt: d.NextSentAt,
CreatedAt: d.CreatedAt,
UpdatedAt: d.UpdatedAt,
DeletedAt: d.DeletedAt,
}
}
func (repo *NodeTaskRepository) nextIdentify() (int64, error) {
return utils.NewSnowflakeId()
}
func (repo *NodeTaskRepository) Insert(d *domain.NodeTask) (*domain.NodeTask, error) {
var isCreate = d.Id == 0
if isCreate {
id, err := repo.nextIdentify()
if err != nil {
return d, err
}
d.Id = id
d.CreatedAt = time.Now()
d.UpdatedAt = d.CreatedAt
} else {
d.UpdatedAt = time.Now()
}
m := repo.TransformToModel(d)
tx := repo.transactionContext.PgTx
var err error
if isCreate {
_, err = tx.Model(&m).Returning("id").Insert()
} else {
_, err = tx.Model(&m).Returning("id").WherePK().Update() // 更新和删除必须增加条件
}
if err != nil {
return nil, err
}
d.Id = m.Id
return d, nil
}
func (repo *NodeTaskRepository) Remove(d *domain.NodeTask) (*domain.NodeTask, error) {
tx := repo.transactionContext.PgTx
nowTime := time.Now()
m := repo.TransformToModel(d)
m.DeletedAt = &nowTime
if _, err := tx.Model(&m).WherePK().Update(); err != nil {
return d, err
}
return d, nil
}
func (repo *NodeTaskRepository) FindOne(queryOptions map[string]interface{}) (*domain.NodeTask, error) {
tx := repo.transactionContext.PgTx
m := new(models.NodeTask)
query := tx.Model(m)
query.Where("deleted_at isnull")
if id, ok := queryOptions["id"]; ok {
query.Where("id=?", id)
}
if err := query.First(); err != nil {
if errors.Is(err, pg.ErrNoRows) {
return nil, fmt.Errorf("没有此资源")
} else {
return nil, err
}
}
u := repo.TransformToDomain(m)
return &u, nil
}
func (repo *NodeTaskRepository) Find(queryOptions map[string]interface{}) ([]*domain.NodeTask, error) {
tx := repo.transactionContext.PgTx
var m []*models.NodeTask
query := tx.Model(&m).Where("deleted_at isnull")
if v, ok := queryOptions["now"].(time.Time); ok {
query.Where("next_sent_at <= ?", v)
}
if v, ok := queryOptions["ids"]; ok {
query.Where("id in(?)", pg.In(v))
}
if v, ok := queryOptions["companyId"]; ok {
query.Where("company_id = ?", v)
}
if v, ok := queryOptions["cycleId"]; ok {
query.Where("cycle_id = ?", v)
}
if v, ok := queryOptions["projectId"]; ok {
query.Where("project_id = ?", v)
}
if v, ok := queryOptions["nodeId"]; ok {
query.Where("node_id = ?", v)
}
err := query.Select()
if err != nil {
return nil, err
}
var arrays []*domain.NodeTask
for _, v := range m {
d := repo.TransformToDomain(v)
arrays = append(arrays, &d)
}
return arrays, nil
}
... ...
package repository
import (
"time"
"github.com/go-pg/pg/v10"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models"
"time"
)
type PositionRepository struct {
... ... @@ -66,6 +67,37 @@ func (repository *PositionRepository) FindOne(queryOption map[string]interface{}
return repository.transferToDomain(position), nil
}
func (repo *PositionRepository) Find(queryOptions map[string]interface{}) (int, []*domain.Position, error) {
tx := repo.transactionContext.PgTx
positionModel := []models.Position{}
query := tx.Model(&positionModel)
if v, ok := queryOptions["id"]; ok {
query.Where("id=?", v)
}
if v, ok := queryOptions["ids"]; ok {
query.Where("id in(?)", pg.In(v))
}
if v, ok := queryOptions["companyId"]; ok {
query.Where("company_id=?", v)
}
if v, ok := queryOptions["offset"]; ok {
query.Offset(v.(int))
}
if v, ok := queryOptions["limit"]; ok {
query.Limit(v.(int))
}
cnt, err := query.SelectAndCount()
if err != nil {
return 0, nil, err
}
var resultList []*domain.Position
for i := range positionModel {
result := repo.transferToDomain(&positionModel[i])
resultList = append(resultList, result)
}
return cnt, resultList, nil
}
func (repository *PositionRepository) transferToDomain(model *models.Position) *domain.Position {
return &domain.Position{
Id: model.Id,
... ...
... ... @@ -113,19 +113,19 @@ func (repo *RoleRepository) Find(queryOptions map[string]interface{}) (int64, []
var m []*models.Role
query := tx.Model(&m).Where("deleted_at isnull")
if name, ok := queryOptions["name"]; ok {
query.Where("name = ?", name)
if v, ok := queryOptions["name"].(string); ok && len(v) > 0 {
query.Where("name = ?", v)
}
if companyId, ok := queryOptions["companyId"]; ok {
query.Where("company_id = ?", companyId)
}
if v, ok := queryOptions["limit"].(int); ok {
query.Limit(v)
if v, ok := queryOptions["limit"].(int64); ok {
query.Limit(int(v))
}
if v, ok := queryOptions["offset"].(int); ok {
query.Offset(v)
if v, ok := queryOptions["offset"].(int64); ok {
query.Offset(int(v))
}
count, err := query.SelectAndCount()
... ... @@ -154,8 +154,8 @@ func (repo *RoleRepository) Count(queryOptions map[string]interface{}) (int64, e
query.Where("id != ?", notId)
}
if name, ok := queryOptions["name"]; ok {
query.Where("name = ?", name)
if v, ok := queryOptions["name"].(string); ok && len(v) > 0 {
query.Where("name = ?", v)
}
if companyId, ok := queryOptions["companyId"]; ok {
... ...