Merge remote-tracking branch 'origin/test'
正在显示
57 个修改的文件
包含
3653 行增加
和
83 行删除
| 1 | -FROM 192.168.0.243:5000/mmm/mmm-oppmg:20200110 as builder | 1 | +FROM 192.168.0.243:5000/mmm/mmmopp:20200226 as builder |
| 2 | #FROM golang:1.13 as builder | 2 | #FROM golang:1.13 as builder |
| 3 | ENV GOPROXY https://goproxy.cn | 3 | ENV GOPROXY https://goproxy.cn |
| 4 | ENV GO111MODULE on | 4 | ENV GO111MODULE on |
| 5 | ENV GOPATH /go | 5 | ENV GOPATH /go |
| 6 | -RUN git clone http://gitlab.fjmaimaimai.com/mmm-go/gocomm.git /go/src/gocomm \ | ||
| 7 | - && cd /go/src/gocomm \ | 6 | +#RUN git clone http://gitlab.fjmaimaimai.com/mmm-go/gocomm.git /go/src/gocomm \ |
| 7 | +RUN cd /go/src/gocomm \ | ||
| 8 | && git pull | 8 | && git pull |
| 9 | WORKDIR /go/src/opp | 9 | WORKDIR /go/src/opp |
| 10 | 10 |
| 1 | [dev] | 1 | [dev] |
| 2 | #数据库相关 | 2 | #数据库相关 |
| 3 | mysql_user = "${MYSQL_USER||root}" | 3 | mysql_user = "${MYSQL_USER||root}" |
| 4 | -mysql_password = "${MYSQL_PASSWORD||sutianxia2015}" | ||
| 5 | -mysql_host = "${MYSQL_HOST||115.29.205.99}" | 4 | +mysql_password = "${MYSQL_PASSWORD||sutianxia2018}" |
| 5 | +mysql_host = "${MYSQL_HOST||101.37.68.23}" | ||
| 6 | mysql_port = "${MYSQL_PORT||3306}" | 6 | mysql_port = "${MYSQL_PORT||3306}" |
| 7 | -mysql_db_name = "${MYSQL_DB_NAME||opportunity}" | 7 | +mysql_db_name = "${MYSQL_DB_NAME||opportunity_dev}" |
| 8 | 8 | ||
| 9 | #日志 | 9 | #日志 |
| 10 | log_level = "${LOG_LEVEL||debug}" | 10 | log_level = "${LOG_LEVEL||debug}" |
| @@ -126,3 +126,8 @@ func Test_RedisLock(t *testing.T) { | @@ -126,3 +126,8 @@ func Test_RedisLock(t *testing.T) { | ||
| 126 | //}() | 126 | //}() |
| 127 | //time.Sleep(11*time.Second) | 127 | //time.Sleep(11*time.Second) |
| 128 | } | 128 | } |
| 129 | + | ||
| 130 | +func TestSlice(t *testing.T) { | ||
| 131 | + var array = []int{1, 2, 3, 4, 5} | ||
| 132 | + t.Log(array[0:4]) | ||
| 133 | +} |
controllers/v1/achievement.go
0 → 100644
| 1 | +package v1 | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "encoding/json" | ||
| 5 | + | ||
| 6 | + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" | ||
| 7 | + "opp/controllers" | ||
| 8 | + "opp/protocol" | ||
| 9 | + "opp/services/chance" | ||
| 10 | +) | ||
| 11 | + | ||
| 12 | +//成果 | ||
| 13 | +type AchievementController struct { | ||
| 14 | + controllers.BaseController | ||
| 15 | +} | ||
| 16 | + | ||
| 17 | +//AchievementPool 成果池 | ||
| 18 | +// @router /achievementPool [post] | ||
| 19 | +func (this *AchievementController) AchievementPool() { | ||
| 20 | + var msg *protocol.ResponseMessage | ||
| 21 | + defer func() { | ||
| 22 | + this.Resp(msg) | ||
| 23 | + }() | ||
| 24 | + var request *protocol.AchievementPoolRequest | ||
| 25 | + if err := json.Unmarshal(this.ByteBody, &request); err != nil { | ||
| 26 | + log.Error(err) | ||
| 27 | + msg = protocol.BadRequestParam(1) | ||
| 28 | + return | ||
| 29 | + } | ||
| 30 | + if b, m := this.Valid(request); !b { | ||
| 31 | + msg = m | ||
| 32 | + return | ||
| 33 | + } | ||
| 34 | + header := controllers.GetRequestHeader(this.Ctx) | ||
| 35 | + request.IncludeSubDepartment = false | ||
| 36 | + msg = protocol.NewReturnResponse(chance.AchievementPool(header, request)) | ||
| 37 | +} | ||
| 38 | + | ||
| 39 | +//MyGrasp 我把握的 | ||
| 40 | +// @router /myGrasp [post] | ||
| 41 | +func (this *AchievementController) MyGrasp() { | ||
| 42 | + var msg *protocol.ResponseMessage | ||
| 43 | + defer func() { | ||
| 44 | + this.Resp(msg) | ||
| 45 | + }() | ||
| 46 | + var request *protocol.MyGraspRequest | ||
| 47 | + if err := json.Unmarshal(this.ByteBody, &request); err != nil { | ||
| 48 | + log.Error(err) | ||
| 49 | + msg = protocol.BadRequestParam(1) | ||
| 50 | + return | ||
| 51 | + } | ||
| 52 | + if b, m := this.Valid(request); !b { | ||
| 53 | + msg = m | ||
| 54 | + return | ||
| 55 | + } | ||
| 56 | + header := controllers.GetRequestHeader(this.Ctx) | ||
| 57 | + msg = protocol.NewReturnResponse(chance.MyGrasp(header, request)) | ||
| 58 | +} | ||
| 59 | + | ||
| 60 | +//AchievementDetail 成果详情 | ||
| 61 | +// @router /achievementDetail [post] | ||
| 62 | +func (this *AchievementController) AchievementDetail() { | ||
| 63 | + var msg *protocol.ResponseMessage | ||
| 64 | + defer func() { | ||
| 65 | + this.Resp(msg) | ||
| 66 | + }() | ||
| 67 | + var request *protocol.AchievementDetailRequest | ||
| 68 | + if err := json.Unmarshal(this.ByteBody, &request); err != nil { | ||
| 69 | + log.Error(err) | ||
| 70 | + msg = protocol.BadRequestParam(1) | ||
| 71 | + return | ||
| 72 | + } | ||
| 73 | + if b, m := this.Valid(request); !b { | ||
| 74 | + msg = m | ||
| 75 | + return | ||
| 76 | + } | ||
| 77 | + header := controllers.GetRequestHeader(this.Ctx) | ||
| 78 | + msg = protocol.NewReturnResponse(chance.AchievementDetail(header, request)) | ||
| 79 | +} | ||
| 80 | + | ||
| 81 | +//MyGraspStatistic 我把握的统计(按一级分类类型) | ||
| 82 | +// @router /myGraspStatistic [post] | ||
| 83 | +func (this *AchievementController) MyGraspStatistic() { | ||
| 84 | + var msg *protocol.ResponseMessage | ||
| 85 | + defer func() { | ||
| 86 | + this.Resp(msg) | ||
| 87 | + }() | ||
| 88 | + var request *protocol.MyGraspStatisticRequest | ||
| 89 | + if err := json.Unmarshal(this.ByteBody, &request); err != nil { | ||
| 90 | + log.Error(err) | ||
| 91 | + msg = protocol.BadRequestParam(1) | ||
| 92 | + return | ||
| 93 | + } | ||
| 94 | + if b, m := this.Valid(request); !b { | ||
| 95 | + msg = m | ||
| 96 | + return | ||
| 97 | + } | ||
| 98 | + header := controllers.GetRequestHeader(this.Ctx) | ||
| 99 | + msg = protocol.NewReturnResponse(chance.MyGraspStatistic(header, request)) | ||
| 100 | +} |
| @@ -611,6 +611,28 @@ func (this *ChanceController) ChancePool() { | @@ -611,6 +611,28 @@ func (this *ChanceController) ChancePool() { | ||
| 611 | msg = m | 611 | msg = m |
| 612 | return | 612 | return |
| 613 | } | 613 | } |
| 614 | + request.IncludeSubDepartment = false | ||
| 614 | header := controllers.GetRequestHeader(this.Ctx) | 615 | header := controllers.GetRequestHeader(this.Ctx) |
| 615 | msg = protocol.NewReturnResponse(chance.ChancePool(header, request)) | 616 | msg = protocol.NewReturnResponse(chance.ChancePool(header, request)) |
| 616 | } | 617 | } |
| 618 | + | ||
| 619 | +//ChanceReviseDetail 机会补充详情 | ||
| 620 | +//@router /chanceReviseDetail [post] | ||
| 621 | +func (this *ChanceController) ChanceReviseDetail() { | ||
| 622 | + var msg *protocol.ResponseMessage | ||
| 623 | + defer func() { | ||
| 624 | + this.Resp(msg) | ||
| 625 | + }() | ||
| 626 | + var request *protocol.ChanceReviseDetailRequest | ||
| 627 | + if err := json.Unmarshal(this.ByteBody, &request); err != nil { | ||
| 628 | + log.Error(err) | ||
| 629 | + msg = protocol.BadRequestParam(1) | ||
| 630 | + return | ||
| 631 | + } | ||
| 632 | + if b, m := this.Valid(request); !b { | ||
| 633 | + msg = m | ||
| 634 | + return | ||
| 635 | + } | ||
| 636 | + header := controllers.GetRequestHeader(this.Ctx) | ||
| 637 | + msg = protocol.NewReturnResponse(chance.ChanceReviseDetail(header, request)) | ||
| 638 | +} |
| @@ -33,3 +33,45 @@ func (this *DepartmentController) Departments() { | @@ -33,3 +33,45 @@ func (this *DepartmentController) Departments() { | ||
| 33 | header := controllers.GetRequestHeader(this.Ctx) | 33 | header := controllers.GetRequestHeader(this.Ctx) |
| 34 | msg = protocol.NewReturnResponse(department.Departments(header, request)) | 34 | msg = protocol.NewReturnResponse(department.Departments(header, request)) |
| 35 | } | 35 | } |
| 36 | + | ||
| 37 | +//DepartmentStatistics 多部门统计 | ||
| 38 | +//@router /statistics [post] | ||
| 39 | +func (this *DepartmentController) DepartmentStatistics() { | ||
| 40 | + var msg *protocol.ResponseMessage | ||
| 41 | + defer func() { | ||
| 42 | + this.Resp(msg) | ||
| 43 | + }() | ||
| 44 | + var request *protocol.DepartmentStatisticsRequest | ||
| 45 | + if err := json.Unmarshal(this.ByteBody, &request); err != nil { | ||
| 46 | + log.Error(err) | ||
| 47 | + msg = protocol.BadRequestParam(1) | ||
| 48 | + return | ||
| 49 | + } | ||
| 50 | + if b, m := this.Valid(request); !b { | ||
| 51 | + msg = m | ||
| 52 | + return | ||
| 53 | + } | ||
| 54 | + header := controllers.GetRequestHeader(this.Ctx) | ||
| 55 | + msg = protocol.NewReturnResponse(department.Statistics(header, request)) | ||
| 56 | +} | ||
| 57 | + | ||
| 58 | +//DepartmentStatistic 单部门统计 | ||
| 59 | +//@router /statistic [post] | ||
| 60 | +func (this *DepartmentController) DepartmentStatistic() { | ||
| 61 | + var msg *protocol.ResponseMessage | ||
| 62 | + defer func() { | ||
| 63 | + this.Resp(msg) | ||
| 64 | + }() | ||
| 65 | + var request *protocol.DepartmentStatisticRequest | ||
| 66 | + if err := json.Unmarshal(this.ByteBody, &request); err != nil { | ||
| 67 | + log.Error(err) | ||
| 68 | + msg = protocol.BadRequestParam(1) | ||
| 69 | + return | ||
| 70 | + } | ||
| 71 | + if b, m := this.Valid(request); !b { | ||
| 72 | + msg = m | ||
| 73 | + return | ||
| 74 | + } | ||
| 75 | + header := controllers.GetRequestHeader(this.Ctx) | ||
| 76 | + msg = protocol.NewReturnResponse(department.DepartmentStatistic(header, request)) | ||
| 77 | +} |
| @@ -242,3 +242,24 @@ func (this *MessageController) MsgChanceThumbUp() { | @@ -242,3 +242,24 @@ func (this *MessageController) MsgChanceThumbUp() { | ||
| 242 | header := controllers.GetRequestHeader(this.Ctx) | 242 | header := controllers.GetRequestHeader(this.Ctx) |
| 243 | msg = protocol.NewReturnResponse(message.MsgChanceThumbUp(header, request)) | 243 | msg = protocol.NewReturnResponse(message.MsgChanceThumbUp(header, request)) |
| 244 | } | 244 | } |
| 245 | + | ||
| 246 | +//MsgChanceRevise 消息中心-机会补充 | ||
| 247 | +//@router /msgChanceRevise [post] | ||
| 248 | +func (this *MessageController) MsgChanceRevise() { | ||
| 249 | + var msg *protocol.ResponseMessage | ||
| 250 | + defer func() { | ||
| 251 | + this.Resp(msg) | ||
| 252 | + }() | ||
| 253 | + var request *protocol.MsgChanceReviseRequest | ||
| 254 | + if err := json.Unmarshal(this.ByteBody, &request); err != nil { | ||
| 255 | + log.Error(err) | ||
| 256 | + msg = protocol.BadRequestParam(1) | ||
| 257 | + return | ||
| 258 | + } | ||
| 259 | + if b, m := this.Valid(request); !b { | ||
| 260 | + msg = m | ||
| 261 | + return | ||
| 262 | + } | ||
| 263 | + header := controllers.GetRequestHeader(this.Ctx) | ||
| 264 | + msg = protocol.NewReturnResponse(message.MsgChanceRevise(header, request)) | ||
| 265 | +} |
controllers/v1/rank.go
0 → 100644
| 1 | +package v1 | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "encoding/json" | ||
| 5 | + "opp/controllers" | ||
| 6 | + "opp/protocol" | ||
| 7 | + "opp/services/rank" | ||
| 8 | + | ||
| 9 | + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" | ||
| 10 | +) | ||
| 11 | + | ||
| 12 | +type RankController struct { | ||
| 13 | + controllers.BaseController | ||
| 14 | +} | ||
| 15 | + | ||
| 16 | +//GetRankList 排行榜 | ||
| 17 | +// @router /getRankList [post] | ||
| 18 | +func (this *RankController) GetRankList() { | ||
| 19 | + var msg *protocol.ResponseMessage | ||
| 20 | + defer func() { | ||
| 21 | + this.Resp(msg) | ||
| 22 | + }() | ||
| 23 | + var request *protocol.GetRankListRequest | ||
| 24 | + if err := json.Unmarshal(this.ByteBody, &request); err != nil { | ||
| 25 | + log.Error(err) | ||
| 26 | + msg = protocol.BadRequestParam(1) | ||
| 27 | + return | ||
| 28 | + } | ||
| 29 | + if b, m := this.Valid(request); !b { | ||
| 30 | + msg = m | ||
| 31 | + return | ||
| 32 | + } | ||
| 33 | + header := controllers.GetRequestHeader(this.Ctx) | ||
| 34 | + msg = protocol.NewReturnResponse(rank.GetRankList(header, request)) | ||
| 35 | +} | ||
| 36 | + | ||
| 37 | +//GetRankType 获取榜单类型列表 (年榜/赛季榜) | ||
| 38 | +// @router /getRankTypes [post] | ||
| 39 | +func (this *RankController) GetRankType() { | ||
| 40 | + var msg *protocol.ResponseMessage | ||
| 41 | + defer func() { | ||
| 42 | + this.Resp(msg) | ||
| 43 | + }() | ||
| 44 | + var request *protocol.GetRankTypeRequest | ||
| 45 | + if err := json.Unmarshal(this.ByteBody, &request); err != nil { | ||
| 46 | + log.Error(err) | ||
| 47 | + msg = protocol.BadRequestParam(1) | ||
| 48 | + return | ||
| 49 | + } | ||
| 50 | + if b, m := this.Valid(request); !b { | ||
| 51 | + msg = m | ||
| 52 | + return | ||
| 53 | + } | ||
| 54 | + header := controllers.GetRequestHeader(this.Ctx) | ||
| 55 | + msg = protocol.NewReturnResponse(rank.GetRankType(header, request)) | ||
| 56 | +} | ||
| 57 | + | ||
| 58 | +//GetRankRange 获取榜单竞争范围列表 | ||
| 59 | +//@router /getRankRanges [post] | ||
| 60 | +func (this *RankController) GetRankRange() { | ||
| 61 | + var msg *protocol.ResponseMessage | ||
| 62 | + defer func() { | ||
| 63 | + this.Resp(msg) | ||
| 64 | + }() | ||
| 65 | + var request *protocol.GetRankRangeRequest | ||
| 66 | + if err := json.Unmarshal(this.ByteBody, &request); err != nil { | ||
| 67 | + log.Error(err) | ||
| 68 | + msg = protocol.BadRequestParam(1) | ||
| 69 | + return | ||
| 70 | + } | ||
| 71 | + if b, m := this.Valid(request); !b { | ||
| 72 | + msg = m | ||
| 73 | + return | ||
| 74 | + } | ||
| 75 | + header := controllers.GetRequestHeader(this.Ctx) | ||
| 76 | + msg = protocol.NewReturnResponse(rank.GetRankRange(header, request)) | ||
| 77 | +} | ||
| 78 | + | ||
| 79 | +//GetRankPeriods 获取排行榜周期列表 | ||
| 80 | +//@router /getRankPeriods [post] | ||
| 81 | +func (this *RankController) GetRankPeriods() { | ||
| 82 | + var msg *protocol.ResponseMessage | ||
| 83 | + defer func() { | ||
| 84 | + this.Resp(msg) | ||
| 85 | + }() | ||
| 86 | + var request *protocol.GetRankPeriodsRequest | ||
| 87 | + if err := json.Unmarshal(this.ByteBody, &request); err != nil { | ||
| 88 | + log.Error(err) | ||
| 89 | + msg = protocol.BadRequestParam(1) | ||
| 90 | + return | ||
| 91 | + } | ||
| 92 | + if b, m := this.Valid(request); !b { | ||
| 93 | + msg = m | ||
| 94 | + return | ||
| 95 | + } | ||
| 96 | + header := controllers.GetRequestHeader(this.Ctx) | ||
| 97 | + msg = protocol.NewReturnResponse(rank.GetRankPeriods(header, request)) | ||
| 98 | +} | ||
| 99 | + | ||
| 100 | +//ComputeRankScore 手动计算排行榜 | ||
| 101 | +//@router /computeRankScore [post] | ||
| 102 | +func (this *RankController) ComputeRankScore() { | ||
| 103 | + var msg *protocol.ResponseMessage | ||
| 104 | + defer func() { | ||
| 105 | + this.Resp(msg) | ||
| 106 | + }() | ||
| 107 | + var request *protocol.ComputeRankScoreRequest | ||
| 108 | + if err := json.Unmarshal(this.ByteBody, &request); err != nil { | ||
| 109 | + log.Error(err) | ||
| 110 | + msg = protocol.BadRequestParam(1) | ||
| 111 | + return | ||
| 112 | + } | ||
| 113 | + if b, m := this.Valid(request); !b { | ||
| 114 | + msg = m | ||
| 115 | + return | ||
| 116 | + } | ||
| 117 | + header := controllers.GetRequestHeader(this.Ctx) | ||
| 118 | + msg = protocol.NewReturnResponse(rank.ComputeRankScore(header, request)) | ||
| 119 | +} | ||
| 120 | + | ||
| 121 | +//GetRankSortItems 获取排行榜评比项 | ||
| 122 | +//@router /getRankSortItems [post] | ||
| 123 | +func (this *RankController) GetRankSortItems() { | ||
| 124 | + var msg *protocol.ResponseMessage | ||
| 125 | + defer func() { | ||
| 126 | + this.Resp(msg) | ||
| 127 | + }() | ||
| 128 | + var request *protocol.GetRankSortItemsRequest | ||
| 129 | + if err := json.Unmarshal(this.ByteBody, &request); err != nil { | ||
| 130 | + log.Error(err) | ||
| 131 | + msg = protocol.BadRequestParam(1) | ||
| 132 | + return | ||
| 133 | + } | ||
| 134 | + if b, m := this.Valid(request); !b { | ||
| 135 | + msg = m | ||
| 136 | + return | ||
| 137 | + } | ||
| 138 | + header := controllers.GetRequestHeader(this.Ctx) | ||
| 139 | + msg = protocol.NewReturnResponse(rank.GetRankSortItems(header, request)) | ||
| 140 | +} |
| @@ -6,6 +6,7 @@ require ( | @@ -6,6 +6,7 @@ require ( | ||
| 6 | github.com/aliyun/alibaba-cloud-sdk-go v1.60.348 | 6 | github.com/aliyun/alibaba-cloud-sdk-go v1.60.348 |
| 7 | github.com/astaxie/beego v1.10.0 | 7 | github.com/astaxie/beego v1.10.0 |
| 8 | github.com/disintegration/imaging v1.6.2 | 8 | github.com/disintegration/imaging v1.6.2 |
| 9 | + github.com/gin-gonic/gin v1.4.0 | ||
| 9 | github.com/go-sql-driver/mysql v1.4.1 | 10 | github.com/go-sql-driver/mysql v1.4.1 |
| 10 | github.com/gomodule/redigo v1.7.0 | 11 | github.com/gomodule/redigo v1.7.0 |
| 11 | github.com/gorilla/websocket v1.4.1 | 12 | github.com/gorilla/websocket v1.4.1 |
| @@ -15,3 +15,9 @@ func Decimal(value float64) float64 { | @@ -15,3 +15,9 @@ func Decimal(value float64) float64 { | ||
| 15 | value, _ = strconv.ParseFloat(fmt.Sprintf("%.1f", value), 64) | 15 | value, _ = strconv.ParseFloat(fmt.Sprintf("%.1f", value), 64) |
| 16 | return value | 16 | return value |
| 17 | } | 17 | } |
| 18 | + | ||
| 19 | +func DecimalToNumber(value float64) float64 { | ||
| 20 | + value = decimal(value) | ||
| 21 | + value, _ = strconv.ParseFloat(fmt.Sprintf("%.f", value), 64) | ||
| 22 | + return value | ||
| 23 | +} |
| @@ -8,4 +8,10 @@ func TestDecimal(t *testing.T) { | @@ -8,4 +8,10 @@ func TestDecimal(t *testing.T) { | ||
| 8 | t.Log(Decimal(1.7555555)) | 8 | t.Log(Decimal(1.7555555)) |
| 9 | t.Log(Decimal(1.3555555)) | 9 | t.Log(Decimal(1.3555555)) |
| 10 | t.Log(Decimal(1.3000001)) | 10 | t.Log(Decimal(1.3000001)) |
| 11 | + | ||
| 12 | + t.Log(DecimalToNumber(1.0)) | ||
| 13 | + t.Log(DecimalToNumber(1.4)) | ||
| 14 | + t.Log(DecimalToNumber(1.5)) | ||
| 15 | + t.Log(DecimalToNumber(1.6)) | ||
| 16 | + t.Log(DecimalToNumber(99.0)) | ||
| 11 | } | 17 | } |
| 1 | package utils | 1 | package utils |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | + "bytes" | ||
| 4 | "errors" | 5 | "errors" |
| 5 | "fmt" | 6 | "fmt" |
| 6 | "github.com/astaxie/beego/orm" | 7 | "github.com/astaxie/beego/orm" |
| @@ -130,7 +131,6 @@ func PrintLogSql(sql string, param ...interface{}) { | @@ -130,7 +131,6 @@ func PrintLogSql(sql string, param ...interface{}) { | ||
| 130 | 131 | ||
| 131 | //ExecuteQueryOne 执行原生sql查询单条记录;结果用结构体接收 | 132 | //ExecuteQueryOne 执行原生sql查询单条记录;结果用结构体接收 |
| 132 | func ExecuteQueryOne(result interface{}, sqlstr string, param ...interface{}) error { | 133 | func ExecuteQueryOne(result interface{}, sqlstr string, param ...interface{}) error { |
| 133 | - //PrintLogSql(sqlstr, param...) | ||
| 134 | var err error | 134 | var err error |
| 135 | o := orm.NewOrm() | 135 | o := orm.NewOrm() |
| 136 | err = ExecuteQueryOneWithOrmer(o, result, sqlstr, param) | 136 | err = ExecuteQueryOneWithOrmer(o, result, sqlstr, param) |
| @@ -183,3 +183,62 @@ func ExecuteSQLWithOrmer(o orm.Ormer, sqlstr string, param ...interface{}) error | @@ -183,3 +183,62 @@ func ExecuteSQLWithOrmer(o orm.Ormer, sqlstr string, param ...interface{}) error | ||
| 183 | log.Debug(fmt.Sprintf("RowsAffected:%d", num)) | 183 | log.Debug(fmt.Sprintf("RowsAffected:%d", num)) |
| 184 | return nil | 184 | return nil |
| 185 | } | 185 | } |
| 186 | + | ||
| 187 | +type SqlExcutor struct { | ||
| 188 | + table string | ||
| 189 | + wherestr []string | ||
| 190 | + orderstr []string | ||
| 191 | + islimit bool | ||
| 192 | + offset int | ||
| 193 | + pagenum int | ||
| 194 | +} | ||
| 195 | + | ||
| 196 | +func NewSqlExutor() *SqlExcutor { | ||
| 197 | + return &SqlExcutor{} | ||
| 198 | +} | ||
| 199 | + | ||
| 200 | +func (s *SqlExcutor) Table(str string) *SqlExcutor { | ||
| 201 | + s.table = str | ||
| 202 | + return s | ||
| 203 | +} | ||
| 204 | + | ||
| 205 | +func (s *SqlExcutor) Where(condition ...string) *SqlExcutor { | ||
| 206 | + if len(condition) <= 0 { | ||
| 207 | + return s | ||
| 208 | + } | ||
| 209 | + s.wherestr = append(s.wherestr, condition...) | ||
| 210 | + return s | ||
| 211 | +} | ||
| 212 | + | ||
| 213 | +func (s *SqlExcutor) Order(condition ...string) *SqlExcutor { | ||
| 214 | + if len(condition) <= 0 { | ||
| 215 | + return s | ||
| 216 | + } | ||
| 217 | + s.orderstr = append(s.orderstr, condition...) | ||
| 218 | + return s | ||
| 219 | +} | ||
| 220 | + | ||
| 221 | +func (s *SqlExcutor) Limit(page, pagenum int) *SqlExcutor { | ||
| 222 | + offset := 0 | ||
| 223 | + if page > 0 { | ||
| 224 | + offset = (page - 1) * pagenum | ||
| 225 | + } | ||
| 226 | + s.islimit = true | ||
| 227 | + s.offset = offset | ||
| 228 | + s.pagenum = pagenum | ||
| 229 | + return s | ||
| 230 | +} | ||
| 231 | + | ||
| 232 | +func (s *SqlExcutor) WhereString() string { | ||
| 233 | + sql := bytes.NewBufferString("") | ||
| 234 | + if len(s.wherestr) > 0 { | ||
| 235 | + sql.WriteString(" where ") | ||
| 236 | + for i := range s.wherestr { | ||
| 237 | + if i != 0 { | ||
| 238 | + sql.WriteString(" AND ") | ||
| 239 | + } | ||
| 240 | + sql.WriteString(s.wherestr[i]) | ||
| 241 | + } | ||
| 242 | + } | ||
| 243 | + return sql.String() | ||
| 244 | +} |
| @@ -10,6 +10,7 @@ import ( | @@ -10,6 +10,7 @@ import ( | ||
| 10 | "reflect" | 10 | "reflect" |
| 11 | "strconv" | 11 | "strconv" |
| 12 | "strings" | 12 | "strings" |
| 13 | + "time" | ||
| 13 | ) | 14 | ) |
| 14 | 15 | ||
| 15 | // 此函数将指定的结构体成员值更新到结构体中 | 16 | // 此函数将指定的结构体成员值更新到结构体中 |
| @@ -121,3 +122,32 @@ func ValidVersion(current, compare string) bool { | @@ -121,3 +122,32 @@ func ValidVersion(current, compare string) bool { | ||
| 121 | } | 122 | } |
| 122 | return false | 123 | return false |
| 123 | } | 124 | } |
| 125 | + | ||
| 126 | +// 统计某函数执行时间 | ||
| 127 | +// 使用方式 | ||
| 128 | +// defer utils.Profiling("test")() | ||
| 129 | +func Profiling(msg string) func() { | ||
| 130 | + start := time.Now() | ||
| 131 | + return func() { | ||
| 132 | + log.Info(fmt.Sprintf("%s[%s]:%s", msg, "use", time.Since(start))) | ||
| 133 | + } | ||
| 134 | +} | ||
| 135 | + | ||
| 136 | +//合并字典 | ||
| 137 | +func MergeMap(to map[string]interface{}, from map[string]interface{}) { | ||
| 138 | + for k, v := range from { | ||
| 139 | + to[k] = v | ||
| 140 | + } | ||
| 141 | +} | ||
| 142 | + | ||
| 143 | +func GetPageInfo(pageIndex, pageSize int) (offset, size int) { | ||
| 144 | + if pageSize == 0 { | ||
| 145 | + pageSize = 20 | ||
| 146 | + } | ||
| 147 | + if pageIndex == 0 { | ||
| 148 | + pageIndex = 1 | ||
| 149 | + } | ||
| 150 | + offset = (pageIndex - 1) * pageSize | ||
| 151 | + size = pageSize | ||
| 152 | + return | ||
| 153 | +} |
| 1 | package utils | 1 | package utils |
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | + "encoding/json" | ||
| 4 | "fmt" | 5 | "fmt" |
| 5 | "testing" | 6 | "testing" |
| 6 | ) | 7 | ) |
| @@ -50,3 +51,23 @@ func TestValidVersion(t *testing.T) { | @@ -50,3 +51,23 @@ func TestValidVersion(t *testing.T) { | ||
| 50 | } | 51 | } |
| 51 | } | 52 | } |
| 52 | } | 53 | } |
| 54 | + | ||
| 55 | +func TestMergeMap(t *testing.T) { | ||
| 56 | + to := map[string]interface{}{"1": 1, "2": 2} | ||
| 57 | + from := map[string]interface{}{"3": 3, "4": 4} | ||
| 58 | + t.Log("merge 前:", to) | ||
| 59 | + MergeMap(to, from) | ||
| 60 | + t.Log("merge 后:", to) | ||
| 61 | +} | ||
| 62 | + | ||
| 63 | +func TestIntUnmarsh(t *testing.T) { | ||
| 64 | + jsonString := `{"id":8242051651122944}` | ||
| 65 | + type param struct { | ||
| 66 | + Id int `json:"id"` | ||
| 67 | + } | ||
| 68 | + var p param | ||
| 69 | + json.Unmarshal([]byte(jsonString), &p) | ||
| 70 | + t.Log(p) | ||
| 71 | + jsonByte, _ := json.Marshal(p) | ||
| 72 | + t.Log(string(jsonByte)) | ||
| 73 | +} |
| @@ -13,6 +13,7 @@ import ( | @@ -13,6 +13,7 @@ import ( | ||
| 13 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/websocket" | 13 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/websocket" |
| 14 | "opp/internal/utils" | 14 | "opp/internal/utils" |
| 15 | _ "opp/routers" | 15 | _ "opp/routers" |
| 16 | + "opp/services/contrab" | ||
| 16 | "os" | 17 | "os" |
| 17 | "strings" | 18 | "strings" |
| 18 | "time" | 19 | "time" |
| @@ -91,6 +92,8 @@ func main() { | @@ -91,6 +92,8 @@ func main() { | ||
| 91 | //beego.BConfig.Listen.HTTPSPort = 8089 | 92 | //beego.BConfig.Listen.HTTPSPort = 8089 |
| 92 | //beego.BConfig.Listen.HTTPSCertFile = "conf/server.crt" | 93 | //beego.BConfig.Listen.HTTPSCertFile = "conf/server.crt" |
| 93 | //beego.BConfig.Listen.HTTPSKeyFile = "conf/server.key" | 94 | //beego.BConfig.Listen.HTTPSKeyFile = "conf/server.key" |
| 95 | + contrab.Run() | ||
| 96 | + | ||
| 94 | beego.Run() | 97 | beego.Run() |
| 95 | } | 98 | } |
| 96 | 99 |
models/achievement.go
0 → 100644
| 1 | +package models | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "opp/internal/utils" | ||
| 6 | + "time" | ||
| 7 | + | ||
| 8 | + "github.com/astaxie/beego/orm" | ||
| 9 | +) | ||
| 10 | + | ||
| 11 | +type Achievement struct { | ||
| 12 | + Id int64 `orm:"column(id);pk" description:"id 主键"` | ||
| 13 | + CompanyId int64 `orm:"column(company_id);null" description:"公司编号 表company.id"` | ||
| 14 | + UserCompanyId int64 `orm:"column(user_company_id)" description:"把握人 表user_company.id id"` | ||
| 15 | + ChanceTypeId int `orm:"column(chance_type_id);null" description:"表chance_type.id 机会类型 "` | ||
| 16 | + AuditTemplateId int `orm:"column(audit_template_id);null" description:"表audit_template.id 所属审批模板编号"` | ||
| 17 | + SourceContent string `orm:"column(source_content);null" description:"成果详情文本"` | ||
| 18 | + GraspScore float64 `orm:"column(grasp_score);digits(4);decimals(1)" description:"把握分"` | ||
| 19 | + UserGraspScore float64 `orm:"column(user_grasp_score);digits(4);decimals(1)" description:"把握人得分"` | ||
| 20 | + UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"` | ||
| 21 | + CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"` | ||
| 22 | + ViewTotal int `orm:"column(view_total);null" description:"查看总数"` | ||
| 23 | + CommentTotal int `orm:"column(comment_total);null" description:"评论总数"` | ||
| 24 | + ZanTotal int `orm:"column(zan_total);null" description:"点赞总数"` | ||
| 25 | + Status int8 `orm:"column(status);null" description:"机会状态 1:开启 2:关闭 0:删除"` | ||
| 26 | +} | ||
| 27 | + | ||
| 28 | +func (t *Achievement) TableName() string { | ||
| 29 | + return "achievement" | ||
| 30 | +} | ||
| 31 | + | ||
| 32 | +func init() { | ||
| 33 | + orm.RegisterModel(new(Achievement)) | ||
| 34 | +} | ||
| 35 | + | ||
| 36 | +// GetAchievementById retrieves Achievement by Id. Returns error if | ||
| 37 | +// Id doesn't exist | ||
| 38 | +func GetAchievementById(id int64) (v *Achievement, err error) { | ||
| 39 | + o := orm.NewOrm() | ||
| 40 | + v = &Achievement{Id: id} | ||
| 41 | + if err = o.Read(v); err == nil { | ||
| 42 | + return v, nil | ||
| 43 | + } | ||
| 44 | + return nil, err | ||
| 45 | +} | ||
| 46 | + | ||
| 47 | +// UpdateAchievement updates Achievement by Id and returns error if | ||
| 48 | +// the record to be updated doesn't exist | ||
| 49 | +func UpdateAchievementById(m *Achievement) (err error) { | ||
| 50 | + o := orm.NewOrm() | ||
| 51 | + v := Achievement{Id: m.Id} | ||
| 52 | + // ascertain id exists in the database | ||
| 53 | + if err = o.Read(&v); err == nil { | ||
| 54 | + var num int64 | ||
| 55 | + if num, err = o.Update(m); err == nil { | ||
| 56 | + fmt.Println("Number of records updated in database:", num) | ||
| 57 | + } | ||
| 58 | + } | ||
| 59 | + return | ||
| 60 | +} | ||
| 61 | + | ||
| 62 | +//成果列表 | ||
| 63 | +//@uid 成果把握人 | ||
| 64 | +//@cid 公司编号 | ||
| 65 | +//@lastId 最后编号 | ||
| 66 | +//@chanceTypeId 机会一级分类编号 | ||
| 67 | +//@departmentId 部门编号 | ||
| 68 | +func GetAchievementAll(uid, cid int64, chanceTypeId int, lastId int64, departmentId []int, pageSize int, v interface{}) (total int, err error) { | ||
| 69 | + var filter = utils.NewSqlExutor() | ||
| 70 | + filter.Where(fmt.Sprintf("company_id=%v", cid)) | ||
| 71 | + filter.Where("status=1") | ||
| 72 | + if lastId > 0 { | ||
| 73 | + filter.Where(fmt.Sprintf("id<%v", lastId)) | ||
| 74 | + } | ||
| 75 | + if chanceTypeId > 0 { | ||
| 76 | + filter.Where(fmt.Sprintf("chance_type_id =%v", chanceTypeId)) | ||
| 77 | + } | ||
| 78 | + if len(departmentId) > 0 { | ||
| 79 | + filter.Where(fmt.Sprintf("department_id in (%v)", utils.JoinInts(departmentId, ","))) | ||
| 80 | + } | ||
| 81 | + if uid > 0 { | ||
| 82 | + filter.Where(fmt.Sprintf("user_company_id =%v", uid)) | ||
| 83 | + } | ||
| 84 | + sql := fmt.Sprintf(` | ||
| 85 | +select id,user_company_id,create_at,source_content,audit_template_id,chance_type_id,grasp_score,user_grasp_score,comment_total,zan_total,view_total,images from achievement | ||
| 86 | +%v | ||
| 87 | +order by create_at desc | ||
| 88 | +limit %v | ||
| 89 | +`, filter.WhereString(), pageSize) | ||
| 90 | + | ||
| 91 | + sqlCount := fmt.Sprintf(` | ||
| 92 | +select count(0) from achievement | ||
| 93 | +%v | ||
| 94 | +`, filter.WhereString()) | ||
| 95 | + | ||
| 96 | + if err = utils.ExecuteQueryOne(&total, sqlCount); err != nil { | ||
| 97 | + return | ||
| 98 | + } | ||
| 99 | + if v != nil { | ||
| 100 | + if err = utils.ExecuteQueryAll(v, sql); err != nil { | ||
| 101 | + return | ||
| 102 | + } | ||
| 103 | + } | ||
| 104 | + return | ||
| 105 | +} | ||
| 106 | + | ||
| 107 | +//成果详情 | ||
| 108 | +func GetCommAchievementItemOrmId(id int64, v interface{}) (err error) { | ||
| 109 | + o := orm.NewOrm() | ||
| 110 | + sql := "select * from achievement where id=?" | ||
| 111 | + if _, err = o.Raw(sql, id).QueryRows(v); err == nil { | ||
| 112 | + return nil | ||
| 113 | + } | ||
| 114 | + return err | ||
| 115 | +} | ||
| 116 | + | ||
| 117 | +//获取成果统计 | ||
| 118 | +func GetAchievementStatisticByChanceType(uid int64, v interface{}) (err error) { | ||
| 119 | + o := orm.NewOrm() | ||
| 120 | + sql := `select a.*,b.name from ( | ||
| 121 | + select chance_type_id,count(0) total from achievement where user_company_id =? | ||
| 122 | + group by chance_type_id | ||
| 123 | + )a inner join chance_type b on a.chance_type_id = b.id | ||
| 124 | + order by sort_num` | ||
| 125 | + if _, err = o.Raw(sql, uid).QueryRows(v); err == nil { | ||
| 126 | + return nil | ||
| 127 | + } | ||
| 128 | + return err | ||
| 129 | +} |
models/achievement_chance.go
0 → 100644
| 1 | +package models | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "time" | ||
| 5 | + | ||
| 6 | + "github.com/astaxie/beego/orm" | ||
| 7 | +) | ||
| 8 | + | ||
| 9 | +type AchievementChance struct { | ||
| 10 | + Id int64 `orm:"column(id);pk"` | ||
| 11 | + AchievementId int64 `orm:"column(achievement_id);null" description:"成果编号 表achievement.id"` | ||
| 12 | + ChanceId int64 `orm:"column(chance_id);null" description:"机会编号 表chance.id"` | ||
| 13 | + ChanceCode string `orm:"column(chance_code);size(255);null" description:"机会编号 表chance.code"` | ||
| 14 | + CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"` | ||
| 15 | +} | ||
| 16 | + | ||
| 17 | +func (t *AchievementChance) TableName() string { | ||
| 18 | + return "achievement_chance" | ||
| 19 | +} | ||
| 20 | + | ||
| 21 | +func init() { | ||
| 22 | + orm.RegisterModel(new(AchievementChance)) | ||
| 23 | +} | ||
| 24 | + | ||
| 25 | +// GetAchievementChanceById retrieves AchievementChance by Id. Returns error if | ||
| 26 | +// Id doesn't exist | ||
| 27 | +func GetAchievementChanceById(id int64) (v *AchievementChance, err error) { | ||
| 28 | + o := orm.NewOrm() | ||
| 29 | + v = &AchievementChance{Id: id} | ||
| 30 | + if err = o.Read(v); err == nil { | ||
| 31 | + return v, nil | ||
| 32 | + } | ||
| 33 | + return nil, err | ||
| 34 | +} | ||
| 35 | + | ||
| 36 | +//查询成果提供者列表 | ||
| 37 | +func GetAchievementChances(achievementId int64, v interface{}) (err error) { | ||
| 38 | + o := orm.NewOrm() | ||
| 39 | + sql := `select a.*,b.images,speechs,videos | ||
| 40 | +from ( | ||
| 41 | +select chance_id,b.user_id chance_user_id,approve_time create_at,source_content,enable_status,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total,publish_status,status | ||
| 42 | +from achievement_chance a inner join chance b on a.chance_id=b.id where achievement_id=? and b.review_status=3 | ||
| 43 | +) a left JOIN chance_data b on a.chance_id =b.chance_id | ||
| 44 | +order by a.create_at desc | ||
| 45 | +` | ||
| 46 | + if _, err = o.Raw(sql, achievementId).QueryRows(v); err == nil { | ||
| 47 | + return nil | ||
| 48 | + } | ||
| 49 | + return err | ||
| 50 | +} |
models/achievement_provider.go
0 → 100644
| 1 | +package models | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "time" | ||
| 5 | + | ||
| 6 | + "github.com/astaxie/beego/orm" | ||
| 7 | +) | ||
| 8 | + | ||
| 9 | +type AchievementProvider struct { | ||
| 10 | + Id int64 `orm:"column(id);pk" description:"主键id"` | ||
| 11 | + AchievementId int64 `orm:"column(achievement_id);null" description:"表achievement.id"` | ||
| 12 | + UserCompanyId int64 `orm:"column(user_company_id);null" description:"user_company.id"` | ||
| 13 | + UserGraspScore float64 `orm:"column(user_grasp_score);null;digits(4);decimals(1)" description:"把握人得分"` | ||
| 14 | + CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"` | ||
| 15 | +} | ||
| 16 | + | ||
| 17 | +func (t *AchievementProvider) TableName() string { | ||
| 18 | + return "achievement_provider" | ||
| 19 | +} | ||
| 20 | + | ||
| 21 | +func init() { | ||
| 22 | + orm.RegisterModel(new(AchievementProvider)) | ||
| 23 | +} | ||
| 24 | + | ||
| 25 | +// GetAchievementProviderById retrieves AchievementProvider by Id. Returns error if | ||
| 26 | +// Id doesn't exist | ||
| 27 | +func GetAchievementProviderById(id int64) (v *AchievementProvider, err error) { | ||
| 28 | + o := orm.NewOrm() | ||
| 29 | + v = &AchievementProvider{Id: id} | ||
| 30 | + if err = o.Read(v); err == nil { | ||
| 31 | + return v, nil | ||
| 32 | + } | ||
| 33 | + return nil, err | ||
| 34 | +} | ||
| 35 | + | ||
| 36 | +//查询成果提供者列表 | ||
| 37 | +func GetAchievementProviders(achievementId int64) (v []*AchievementProvider, err error) { | ||
| 38 | + o := orm.NewOrm() | ||
| 39 | + sql := "select * from achievement_provider where achievement_id=?" | ||
| 40 | + if _, err = o.Raw(sql, achievementId).QueryRows(&v); err == nil { | ||
| 41 | + return v, nil | ||
| 42 | + } | ||
| 43 | + return nil, err | ||
| 44 | +} |
| @@ -264,23 +264,23 @@ where user_id =?` | @@ -264,23 +264,23 @@ where user_id =?` | ||
| 264 | } | 264 | } |
| 265 | 265 | ||
| 266 | //type4 查看所有机会 | 266 | //type4 查看所有机会 |
| 267 | -func GetChancePoolAll(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, v interface{}) (total int, err error) { | ||
| 268 | - | ||
| 269 | - sql := `select a.*,b.images,speechs,videos | 267 | +func GetChancePoolAll(uid, cid int64, chanceTypeId int, dIds []int, lastId int64, pageSize int, v interface{}) (total int, err error) { |
| 268 | + var filterDepartment string = getFilterSqlByDIds(dIds) | ||
| 269 | + sql := fmt.Sprintf(`select a.*,b.images,speechs,videos | ||
| 270 | from ( | 270 | from ( |
| 271 | select id,user_id,approve_time create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total from chance | 271 | select id,user_id,approve_time create_at,source_content,review_status,audit_template_id,chance_type_id,comment_total,zan_total,view_total from chance |
| 272 | -where company_id=? and review_status=3 and (?=0 or chance_type_id =?) and (?=0 or unix_timestamp(approve_time)<?) and enable_status=1 and status=1 | 272 | +where company_id=? and review_status=3 and (?=0 or chance_type_id =?) and (?=0 or unix_timestamp(approve_time)<?) and enable_status=1 and status=1 %v |
| 273 | ) a left JOIN chance_data b on a.id =b.chance_id | 273 | ) a left JOIN chance_data b on a.id =b.chance_id |
| 274 | order by create_at desc | 274 | order by create_at desc |
| 275 | limit ? | 275 | limit ? |
| 276 | -` | 276 | +`, filterDepartment) |
| 277 | 277 | ||
| 278 | //if public==protocol.pu | 278 | //if public==protocol.pu |
| 279 | 279 | ||
| 280 | sqlCount := fmt.Sprintf(`select count(0) from ( | 280 | sqlCount := fmt.Sprintf(`select count(0) from ( |
| 281 | select id from chance | 281 | select id from chance |
| 282 | -where company_id=? and review_status=3 and (%v=0 or chance_type_id =%v) and enable_status=1 and status=1 | ||
| 283 | -) a left JOIN chance_data b on a.id =b.chance_id`, chanceTypeId, chanceTypeId) | 282 | +where company_id=? and review_status=3 and (%v=0 or chance_type_id =%v) and enable_status=1 and status=1 %v |
| 283 | +) a left JOIN chance_data b on a.id =b.chance_id`, chanceTypeId, chanceTypeId, filterDepartment) | ||
| 284 | if err = utils.ExecuteQueryOne(&total, sqlCount, cid); err != nil { | 284 | if err = utils.ExecuteQueryOne(&total, sqlCount, cid); err != nil { |
| 285 | return | 285 | return |
| 286 | } | 286 | } |
| @@ -293,8 +293,8 @@ where company_id=? and review_status=3 and (%v=0 or chance_type_id =%v) and ena | @@ -293,8 +293,8 @@ where company_id=? and review_status=3 and (%v=0 or chance_type_id =%v) and ena | ||
| 293 | } | 293 | } |
| 294 | 294 | ||
| 295 | //type3 特定部门机会 | 295 | //type3 特定部门机会 |
| 296 | -func GetChancePoolSpecialDepartment(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, v interface{}, departmentIds []int64) (total int, err error) { | ||
| 297 | - | 296 | +func GetChancePoolSpecialDepartment(uid, cid int64, chanceTypeId int, dIds []int, lastId int64, pageSize int, v interface{}, departmentIds []int64) (total int, err error) { |
| 297 | + var filterDepartment string = getFilterSqlByDIds(dIds) | ||
| 298 | sql := fmt.Sprintf(` | 298 | sql := fmt.Sprintf(` |
| 299 | select a.*,b.images,speechs,videos from ( | 299 | select a.*,b.images,speechs,videos from ( |
| 300 | select * from ( | 300 | select * from ( |
| @@ -318,11 +318,11 @@ select * from ( | @@ -318,11 +318,11 @@ select * from ( | ||
| 318 | select DISTINCT chance_id from audit_flow_process where uid =%v | 318 | select DISTINCT chance_id from audit_flow_process where uid =%v |
| 319 | ) a inner join chance b on a.chance_id = b.id | 319 | ) a inner join chance b on a.chance_id = b.id |
| 320 | 320 | ||
| 321 | -) a where review_status=3 and (0=%v or chance_type_id =%v) and (0=%v or unix_timestamp(create_at)<%v) and a.enable_status=1 and status=1 | 321 | +) a where review_status=3 and (0=%v or chance_type_id =%v) and (0=%v or unix_timestamp(create_at)<%v) and a.enable_status=1 and status=1 %v |
| 322 | ) a left JOIN chance_data b on a.id =b.chance_id | 322 | ) a left JOIN chance_data b on a.id =b.chance_id |
| 323 | order by create_at desc | 323 | order by create_at desc |
| 324 | limit %v | 324 | limit %v |
| 325 | -`, cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId, lastId, lastId, pageSize) | 325 | +`, cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId, lastId, lastId, filterDepartment, pageSize) |
| 326 | 326 | ||
| 327 | sqlCount := fmt.Sprintf(` | 327 | sqlCount := fmt.Sprintf(` |
| 328 | select count(0) from ( | 328 | select count(0) from ( |
| @@ -346,8 +346,8 @@ select count(0) from ( | @@ -346,8 +346,8 @@ select count(0) from ( | ||
| 346 | select DISTINCT chance_id from audit_flow_process where uid =%v | 346 | select DISTINCT chance_id from audit_flow_process where uid =%v |
| 347 | ) a inner join chance b on a.chance_id = b.id | 347 | ) a inner join chance b on a.chance_id = b.id |
| 348 | 348 | ||
| 349 | -) a where review_status=3 and (0=%v or chance_type_id =%v) and a.enable_status=1 and status=1 | ||
| 350 | -`, cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId) | 349 | +) a where review_status=3 and (0=%v or chance_type_id =%v) and a.enable_status=1 and status=1 %v |
| 350 | +`, cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId, filterDepartment) | ||
| 351 | if err = utils.ExecuteQueryOne(&total, sqlCount); err != nil { | 351 | if err = utils.ExecuteQueryOne(&total, sqlCount); err != nil { |
| 352 | return | 352 | return |
| 353 | } | 353 | } |
| @@ -360,8 +360,8 @@ select count(0) from ( | @@ -360,8 +360,8 @@ select count(0) from ( | ||
| 360 | } | 360 | } |
| 361 | 361 | ||
| 362 | //type32 特定部门机会 - 多角色时包含levl2 部门公开 | 362 | //type32 特定部门机会 - 多角色时包含levl2 部门公开 |
| 363 | -func GetChancePoolDepartment(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, v interface{}, departmentIds []int64, userDepartmetIds []int64) (total int, err error) { | ||
| 364 | - | 363 | +func GetChancePoolDepartment(uid, cid int64, chanceTypeId int, dIds []int, lastId int64, pageSize int, v interface{}, departmentIds []int64, userDepartmetIds []int64) (total int, err error) { |
| 364 | + var filterDepartment string = getFilterSqlByDIds(dIds) | ||
| 365 | sql := fmt.Sprintf(` | 365 | sql := fmt.Sprintf(` |
| 366 | select a.*,b.images,speechs,videos from ( | 366 | select a.*,b.images,speechs,videos from ( |
| 367 | select * from ( | 367 | select * from ( |
| @@ -393,11 +393,11 @@ select * from ( | @@ -393,11 +393,11 @@ select * from ( | ||
| 393 | select DISTINCT chance_id from audit_flow_process where uid =%v | 393 | select DISTINCT chance_id from audit_flow_process where uid =%v |
| 394 | ) a inner join chance b on a.chance_id = b.id | 394 | ) a inner join chance b on a.chance_id = b.id |
| 395 | 395 | ||
| 396 | -) a where review_status=3 and (0=%v or chance_type_id =%v) and (0=%v or unix_timestamp(create_at)<%v) and a.enable_status=1 and status=1 | 396 | +) a where review_status=3 and (0=%v or chance_type_id =%v) and (0=%v or unix_timestamp(create_at)<%v) and a.enable_status=1 and status=1 %v |
| 397 | ) a left JOIN chance_data b on a.id =b.chance_id | 397 | ) a left JOIN chance_data b on a.id =b.chance_id |
| 398 | order by create_at desc | 398 | order by create_at desc |
| 399 | limit %v | 399 | limit %v |
| 400 | -`, utils.JoinInt64s(userDepartmetIds, ","), cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId, lastId, lastId, pageSize) | 400 | +`, utils.JoinInt64s(userDepartmetIds, ","), cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId, lastId, lastId, filterDepartment, pageSize) |
| 401 | 401 | ||
| 402 | sqlCount := fmt.Sprintf(` | 402 | sqlCount := fmt.Sprintf(` |
| 403 | select count(0) from ( | 403 | select count(0) from ( |
| @@ -429,8 +429,8 @@ select count(0) from ( | @@ -429,8 +429,8 @@ select count(0) from ( | ||
| 429 | select DISTINCT chance_id from audit_flow_process where uid =%v | 429 | select DISTINCT chance_id from audit_flow_process where uid =%v |
| 430 | ) a inner join chance b on a.chance_id = b.id | 430 | ) a inner join chance b on a.chance_id = b.id |
| 431 | 431 | ||
| 432 | -) a where review_status=3 and (0=%v or chance_type_id =%v) and a.enable_status=1 and status=1 | ||
| 433 | -`, utils.JoinInt64s(userDepartmetIds, ","), cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId) | 432 | +) a where review_status=3 and (0=%v or chance_type_id =%v) and a.enable_status=1 and status=1 %v |
| 433 | +`, utils.JoinInt64s(userDepartmetIds, ","), cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId, filterDepartment) | ||
| 434 | if err = utils.ExecuteQueryOne(&total, sqlCount); err != nil { | 434 | if err = utils.ExecuteQueryOne(&total, sqlCount); err != nil { |
| 435 | return | 435 | return |
| 436 | } | 436 | } |
| @@ -443,7 +443,8 @@ select count(0) from ( | @@ -443,7 +443,8 @@ select count(0) from ( | ||
| 443 | } | 443 | } |
| 444 | 444 | ||
| 445 | //type2 对我所在部门公开的机会 公司公开的机会 | 445 | //type2 对我所在部门公开的机会 公司公开的机会 |
| 446 | -func GetChancePoolPublicCompany(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, v interface{}, departmentIds []int64) (total int, err error) { | 446 | +func GetChancePoolPublicCompany(uid, cid int64, chanceTypeId int, dIds []int, lastId int64, pageSize int, v interface{}, departmentIds []int64) (total int, err error) { |
| 447 | + var filterDepartment string = getFilterSqlByDIds(dIds) | ||
| 447 | sql := fmt.Sprintf(` | 448 | sql := fmt.Sprintf(` |
| 448 | select a.*,b.images,speechs,videos from ( | 449 | select a.*,b.images,speechs,videos from ( |
| 449 | select * from ( | 450 | select * from ( |
| @@ -470,11 +471,11 @@ select * from ( | @@ -470,11 +471,11 @@ select * from ( | ||
| 470 | select DISTINCT chance_id from audit_flow_process where uid =%v | 471 | select DISTINCT chance_id from audit_flow_process where uid =%v |
| 471 | ) a inner join chance b on a.chance_id = b.id | 472 | ) a inner join chance b on a.chance_id = b.id |
| 472 | 473 | ||
| 473 | -) a where review_status=3 and (0=%v or chance_type_id =%v) and (0=%v or unix_timestamp(create_at)<%v) and a.enable_status=1 and status=1 | 474 | +) a where review_status=3 and (0=%v or chance_type_id =%v) and (0=%v or unix_timestamp(create_at)<%v) and a.enable_status=1 and status=1 %v |
| 474 | ) a left JOIN chance_data b on a.id =b.chance_id | 475 | ) a left JOIN chance_data b on a.id =b.chance_id |
| 475 | order by create_at desc | 476 | order by create_at desc |
| 476 | limit %v | 477 | limit %v |
| 477 | -`, cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId, lastId, lastId, pageSize) | 478 | +`, cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId, lastId, lastId, filterDepartment, pageSize) |
| 478 | 479 | ||
| 479 | sqlCount := fmt.Sprintf(` | 480 | sqlCount := fmt.Sprintf(` |
| 480 | select count(0) from ( | 481 | select count(0) from ( |
| @@ -501,8 +502,8 @@ select count(0) from ( | @@ -501,8 +502,8 @@ select count(0) from ( | ||
| 501 | select DISTINCT chance_id from audit_flow_process where uid =%v | 502 | select DISTINCT chance_id from audit_flow_process where uid =%v |
| 502 | ) a inner join chance b on a.chance_id = b.id | 503 | ) a inner join chance b on a.chance_id = b.id |
| 503 | 504 | ||
| 504 | -) a where review_status=3 and (0=%v or chance_type_id =%v) and a.enable_status=1 and status=1 | ||
| 505 | -`, cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId) | 505 | +) a where review_status=3 and (0=%v or chance_type_id =%v) and a.enable_status=1 and status=1 %v |
| 506 | +`, cid, utils.JoinInt64s(departmentIds, ","), uid, uid, chanceTypeId, chanceTypeId, filterDepartment) | ||
| 506 | if err = utils.ExecuteQueryOne(&total, sqlCount); err != nil { | 507 | if err = utils.ExecuteQueryOne(&total, sqlCount); err != nil { |
| 507 | return | 508 | return |
| 508 | } | 509 | } |
| @@ -513,9 +514,16 @@ select count(0) from ( | @@ -513,9 +514,16 @@ select count(0) from ( | ||
| 513 | } | 514 | } |
| 514 | return | 515 | return |
| 515 | } | 516 | } |
| 517 | +func getFilterSqlByDIds(dIds []int) string { | ||
| 518 | + if len(dIds) == 0 { | ||
| 519 | + return "" | ||
| 520 | + } | ||
| 521 | + return fmt.Sprintf(" and department_id in(%v) ", utils.JoinInts(dIds, ",")) | ||
| 522 | +} | ||
| 516 | 523 | ||
| 517 | //type1 禁止查看所有机会 | 524 | //type1 禁止查看所有机会 |
| 518 | -func GetChancePoolMyself(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, v interface{}) (total int, err error) { | 525 | +func GetChancePoolMyself(uid, cid int64, chanceTypeId int, dIds []int, lastId int64, pageSize int, v interface{}) (total int, err error) { |
| 526 | + var filterDepartment string = getFilterSqlByDIds(dIds) | ||
| 519 | sql := fmt.Sprintf(` | 527 | sql := fmt.Sprintf(` |
| 520 | select a.*,b.images,speechs,videos from ( | 528 | select a.*,b.images,speechs,videos from ( |
| 521 | select * from ( | 529 | select * from ( |
| @@ -529,11 +537,11 @@ select * from ( | @@ -529,11 +537,11 @@ select * from ( | ||
| 529 | select DISTINCT chance_id from audit_flow_process where uid =%v | 537 | select DISTINCT chance_id from audit_flow_process where uid =%v |
| 530 | ) a inner join chance b on a.chance_id = b.id | 538 | ) a inner join chance b on a.chance_id = b.id |
| 531 | 539 | ||
| 532 | -) a where review_status=3 and (0=%v or chance_type_id =%v) and (0=%v or unix_timestamp(create_at)<%v) and a.enable_status=1 and status=1 | 540 | +) a where review_status=3 and (0=%v or chance_type_id =%v) and (0=%v or unix_timestamp(create_at)<%v) and a.enable_status=1 and status=1 %v |
| 533 | ) a left JOIN chance_data b on a.id =b.chance_id | 541 | ) a left JOIN chance_data b on a.id =b.chance_id |
| 534 | order by create_at desc | 542 | order by create_at desc |
| 535 | limit %v | 543 | limit %v |
| 536 | -`, uid, uid, chanceTypeId, chanceTypeId, lastId, lastId, pageSize) | 544 | +`, uid, uid, chanceTypeId, chanceTypeId, lastId, lastId, filterDepartment, pageSize) |
| 537 | 545 | ||
| 538 | sqlCount := fmt.Sprintf(` | 546 | sqlCount := fmt.Sprintf(` |
| 539 | select count(0) from ( | 547 | select count(0) from ( |
| @@ -547,8 +555,8 @@ select count(0) from ( | @@ -547,8 +555,8 @@ select count(0) from ( | ||
| 547 | select DISTINCT chance_id from audit_flow_process where uid =%v | 555 | select DISTINCT chance_id from audit_flow_process where uid =%v |
| 548 | ) a inner join chance b on a.chance_id = b.id | 556 | ) a inner join chance b on a.chance_id = b.id |
| 549 | 557 | ||
| 550 | -) a where review_status=3 and (0=%v or chance_type_id =%v) and a.enable_status=1 and status=1 | ||
| 551 | -`, uid, uid, chanceTypeId, chanceTypeId) | 558 | +) a where review_status=3 and (0=%v or chance_type_id =%v) and a.enable_status=1 and status=1 %v |
| 559 | +`, uid, uid, chanceTypeId, chanceTypeId, filterDepartment) | ||
| 552 | if err = utils.ExecuteQueryOne(&total, sqlCount); err != nil { | 560 | if err = utils.ExecuteQueryOne(&total, sqlCount); err != nil { |
| 553 | return | 561 | return |
| 554 | } | 562 | } |
| @@ -648,3 +656,19 @@ func ExitsChanceByAuditUser(chanceId int64, auditUserId int64) (v *Chance, err e | @@ -648,3 +656,19 @@ func ExitsChanceByAuditUser(chanceId int64, auditUserId int64) (v *Chance, err e | ||
| 648 | } | 656 | } |
| 649 | return | 657 | return |
| 650 | } | 658 | } |
| 659 | + | ||
| 660 | +//机会统计-按部门 | ||
| 661 | +//@departmentIds 按部门编号查询 | ||
| 662 | +func GetChanceStatisticByDepartment(companyId int64, departmentIds []int, reviewStatus int) (v int, err error) { | ||
| 663 | + sql := fmt.Sprintf(`select count(0) from chance where company_id=%v | ||
| 664 | +and review_status=%v | ||
| 665 | +and status=1 | ||
| 666 | +and enable_status=1 | ||
| 667 | +and department_id in (%v)`, | ||
| 668 | + companyId, reviewStatus, utils.JoinInts(departmentIds, ",")) | ||
| 669 | + o := orm.NewOrm() | ||
| 670 | + if err = o.Raw(sql).QueryRow(&v); err != nil { | ||
| 671 | + return | ||
| 672 | + } | ||
| 673 | + return | ||
| 674 | +} |
models/chance_revise_log.go
0 → 100644
| 1 | +package models | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "time" | ||
| 5 | + | ||
| 6 | + "github.com/astaxie/beego/orm" | ||
| 7 | +) | ||
| 8 | + | ||
| 9 | +type ChanceReviseLog struct { | ||
| 10 | + Id int64 `orm:"column(id);pk" description:"id 主键"` | ||
| 11 | + ChanceId int64 `orm:"column(chance_id)" description:"机会编号"` | ||
| 12 | + UserCompanyId int64 `orm:"column(user_company_id);null" description:"用户编号 编辑机会的人"` | ||
| 13 | + Data string `orm:"column(data);null" description:"机会数据"` | ||
| 14 | + CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"` | ||
| 15 | + AuditFlowLogId int64 `orm:"column(audit_flow_log_id)" description:"审核流日志表"` | ||
| 16 | +} | ||
| 17 | + | ||
| 18 | +func (t *ChanceReviseLog) TableName() string { | ||
| 19 | + return "chance_revise_log" | ||
| 20 | +} | ||
| 21 | + | ||
| 22 | +func init() { | ||
| 23 | + orm.RegisterModel(new(ChanceReviseLog)) | ||
| 24 | +} | ||
| 25 | + | ||
| 26 | +// AddChanceReviseLog insert a new ChanceReviseLog into database and returns | ||
| 27 | +// last inserted Id on success. | ||
| 28 | +func AddChanceReviseLog(m *ChanceReviseLog) (id int64, err error) { | ||
| 29 | + o := orm.NewOrm() | ||
| 30 | + id, err = o.Insert(m) | ||
| 31 | + return | ||
| 32 | +} | ||
| 33 | + | ||
| 34 | +// GetChanceReviseLogById retrieves ChanceReviseLog by Id. Returns error if | ||
| 35 | +// Id doesn't exist | ||
| 36 | +func GetChanceReviseLogById(id int64) (v *ChanceReviseLog, err error) { | ||
| 37 | + o := orm.NewOrm() | ||
| 38 | + v = &ChanceReviseLog{Id: id} | ||
| 39 | + if err = o.Read(v); err == nil { | ||
| 40 | + return v, nil | ||
| 41 | + } | ||
| 42 | + return nil, err | ||
| 43 | +} |
| @@ -16,6 +16,7 @@ type Company struct { | @@ -16,6 +16,7 @@ type Company struct { | ||
| 16 | UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"` | 16 | UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"` |
| 17 | DeleteAt time.Time `orm:"column(delete_at);type(timestamp)" description:"删除时间"` | 17 | DeleteAt time.Time `orm:"column(delete_at);type(timestamp)" description:"删除时间"` |
| 18 | UserCenterId int64 `orm:"column(user_center_id)" description:"统一用户中心企业id"` | 18 | UserCenterId int64 `orm:"column(user_center_id)" description:"统一用户中心企业id"` |
| 19 | + Enable int8 `orm:"column(enable)" description:"是否有效【1:有效】【2:无效】"` | ||
| 19 | } | 20 | } |
| 20 | 21 | ||
| 21 | func (t *Company) TableName() string { | 22 | func (t *Company) TableName() string { |
| @@ -8,11 +8,11 @@ import ( | @@ -8,11 +8,11 @@ import ( | ||
| 8 | ) | 8 | ) |
| 9 | 9 | ||
| 10 | type Department struct { | 10 | type Department struct { |
| 11 | - Id int `orm:"column(id);auto"` | ||
| 12 | - CompanyId int `orm:"column(company_id)" description:"公司id"` | 11 | + Id int64 `orm:"column(id);auto"` |
| 12 | + CompanyId int64 `orm:"column(company_id)" description:"公司id"` | ||
| 13 | Name string `orm:"column(name);size(30)" description:"部门名称"` | 13 | Name string `orm:"column(name);size(30)" description:"部门名称"` |
| 14 | CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"` | 14 | CreateAt time.Time `orm:"column(create_at);type(timestamp)" description:"创建时间"` |
| 15 | - ParentId int `orm:"column(parent_id)" description:"父级id"` | 15 | + ParentId int64 `orm:"column(parent_id)" description:"父级id"` |
| 16 | Relation string `orm:"column(relation);size(400)" description:"父子级关系树"` | 16 | Relation string `orm:"column(relation);size(400)" description:"父子级关系树"` |
| 17 | DeleteAt time.Time `orm:"column(delete_at);type(timestamp)" description:"删除时间"` | 17 | DeleteAt time.Time `orm:"column(delete_at);type(timestamp)" description:"删除时间"` |
| 18 | UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"` | 18 | UpdateAt time.Time `orm:"column(update_at);type(timestamp)" description:"更新时间"` |
| @@ -37,7 +37,7 @@ func AddDepartment(m *Department) (id int64, err error) { | @@ -37,7 +37,7 @@ func AddDepartment(m *Department) (id int64, err error) { | ||
| 37 | 37 | ||
| 38 | // GetDepartmentById retrieves Department by Id. Returns error if | 38 | // GetDepartmentById retrieves Department by Id. Returns error if |
| 39 | // Id doesn't exist | 39 | // Id doesn't exist |
| 40 | -func GetDepartmentById(id int) (v *Department, err error) { | 40 | +func GetDepartmentById(id int64) (v *Department, err error) { |
| 41 | o := orm.NewOrm() | 41 | o := orm.NewOrm() |
| 42 | v = &Department{Id: id} | 42 | v = &Department{Id: id} |
| 43 | if err = o.Read(v); err == nil { | 43 | if err = o.Read(v); err == nil { |
| @@ -63,7 +63,7 @@ func UpdateDepartmentById(m *Department) (err error) { | @@ -63,7 +63,7 @@ func UpdateDepartmentById(m *Department) (err error) { | ||
| 63 | 63 | ||
| 64 | // DeleteDepartment deletes Department by Id and returns error if | 64 | // DeleteDepartment deletes Department by Id and returns error if |
| 65 | // the record to be deleted doesn't exist | 65 | // the record to be deleted doesn't exist |
| 66 | -func DeleteDepartment(id int) (err error) { | 66 | +func DeleteDepartment(id int64) (err error) { |
| 67 | o := orm.NewOrm() | 67 | o := orm.NewOrm() |
| 68 | v := Department{Id: id} | 68 | v := Department{Id: id} |
| 69 | // ascertain id exists in the database | 69 | // ascertain id exists in the database |
| @@ -90,3 +90,45 @@ order by parent_id,id` | @@ -90,3 +90,45 @@ order by parent_id,id` | ||
| 90 | } | 90 | } |
| 91 | return | 91 | return |
| 92 | } | 92 | } |
| 93 | + | ||
| 94 | +func GetSubDepartmentIds(companyId int64, relation string) (v []int, err error) { | ||
| 95 | + o := orm.NewOrm() | ||
| 96 | + sql := fmt.Sprintf(` | ||
| 97 | +select id from department where company_id=? and relation like '%v%%' and delete_at =0`, relation) | ||
| 98 | + if _, err = o.Raw(sql, companyId).QueryRows(&v); err == nil { | ||
| 99 | + return | ||
| 100 | + } | ||
| 101 | + return | ||
| 102 | +} | ||
| 103 | + | ||
| 104 | +func GetDepartmentIdsByCompanyId(companyId int) (v []int64, err error) { | ||
| 105 | + o := orm.NewOrm() | ||
| 106 | + sql := ` | ||
| 107 | +select id | ||
| 108 | +from department | ||
| 109 | +where company_id =? and delete_at =0 | ||
| 110 | +order by parent_id,id` | ||
| 111 | + if _, err = o.Raw(sql, companyId).QueryRows(&v); err == nil { | ||
| 112 | + return | ||
| 113 | + } | ||
| 114 | + return | ||
| 115 | +} | ||
| 116 | + | ||
| 117 | +//获取用户所有部门 | ||
| 118 | +func GetDepartmentByUser(uid int64) (v []*Department, err error) { | ||
| 119 | + o := orm.NewOrm() | ||
| 120 | + sql := ` | ||
| 121 | +select id from ( | ||
| 122 | +select department_id from user_department where user_company_id=? and enable_status = 1 | ||
| 123 | +)a inner join department b on a.department_id = b.id | ||
| 124 | +where b.delete_at =0 | ||
| 125 | +order by parent_id,id` | ||
| 126 | + if _, err = o.Raw(sql, uid).QueryRows(&v); err == nil { | ||
| 127 | + if err == orm.ErrNoRows { | ||
| 128 | + err = nil | ||
| 129 | + return | ||
| 130 | + } | ||
| 131 | + return | ||
| 132 | + } | ||
| 133 | + return | ||
| 134 | +} |
models/rank.go
0 → 100644
| 1 | +package models | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "opp/internal/utils" | ||
| 6 | + "time" | ||
| 7 | + | ||
| 8 | + "github.com/astaxie/beego/orm" | ||
| 9 | +) | ||
| 10 | + | ||
| 11 | +type Rank struct { | ||
| 12 | + Id int64 `orm:"column(id);auto"` | ||
| 13 | + CompanyId int `orm:"column(company_id)" description:"公司编号 表company.id"` | ||
| 14 | + RankTypeId int `orm:"column(rank_type_id)" description:"榜单类型编号"` | ||
| 15 | + RankRangeId int `orm:"column(rank_range_id)" description:"榜单范围编号"` | ||
| 16 | + RankPeriodId int `orm:"column(rank_period_id)" description:"赛季周期编号"` | ||
| 17 | + RelationId int64 `orm:"column(relation_id)" description:"用户编号/部门编号"` | ||
| 18 | + TotalScore float64 `orm:"column(total_score);null;digits(4);decimals(1)" description:"总分"` | ||
| 19 | + DiscoveryScore float64 `orm:"column(discovery_score);null;digits(4);decimals(1)" description:"发现得分"` | ||
| 20 | + GraspScore float64 `orm:"column(grasp_score);null;digits(4);decimals(1)" description:"把握分"` | ||
| 21 | + DiscoveryTotal int `orm:"column(discovery_total);null" description:"发现数量"` | ||
| 22 | + CommentTotal int `orm:"column(comment_total);null" description:"评论数量"` | ||
| 23 | + CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"` | ||
| 24 | + UpdateAt time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间"` | ||
| 25 | + EnableStatus int8 `orm:"column(enable_status);null" description:"有效状态 0:无效 1:有效 "` | ||
| 26 | + Type int8 `orm:"column(type);null" description:"1:所有员工 2:指定员工 3:所有部门 4:指定部门"` | ||
| 27 | +} | ||
| 28 | + | ||
| 29 | +func (t *Rank) TableName() string { | ||
| 30 | + return "rank" | ||
| 31 | +} | ||
| 32 | + | ||
| 33 | +func init() { | ||
| 34 | + orm.RegisterModel(new(Rank)) | ||
| 35 | +} | ||
| 36 | + | ||
| 37 | +// AddRank insert a new Rank into database and returns | ||
| 38 | +// last inserted Id on success. | ||
| 39 | +func AddRank(m *Rank) (id int64, err error) { | ||
| 40 | + o := orm.NewOrm() | ||
| 41 | + id, err = o.Insert(m) | ||
| 42 | + return | ||
| 43 | +} | ||
| 44 | + | ||
| 45 | +// GetRankById retrieves Rank by Id. Returns error if | ||
| 46 | +// Id doesn't exist | ||
| 47 | +func GetRankById(id int64) (v *Rank, err error) { | ||
| 48 | + o := orm.NewOrm() | ||
| 49 | + v = &Rank{Id: id} | ||
| 50 | + if err = o.Read(v); err == nil { | ||
| 51 | + return v, nil | ||
| 52 | + } | ||
| 53 | + return nil, err | ||
| 54 | +} | ||
| 55 | + | ||
| 56 | +// UpdateRank updates Rank by Id and returns error if | ||
| 57 | +// the record to be updated doesn't exist | ||
| 58 | +func UpdateRankById(m *Rank) (err error) { | ||
| 59 | + o := orm.NewOrm() | ||
| 60 | + v := Rank{Id: m.Id} | ||
| 61 | + // ascertain id exists in the database | ||
| 62 | + if err = o.Read(&v); err == nil { | ||
| 63 | + var num int64 | ||
| 64 | + if num, err = o.Update(m); err == nil { | ||
| 65 | + fmt.Println("Number of records updated in database:", num) | ||
| 66 | + } | ||
| 67 | + } | ||
| 68 | + return | ||
| 69 | +} | ||
| 70 | + | ||
| 71 | +//取用户当前榜单数据 | ||
| 72 | +func GetRank(companyId, rankTypeId, rankRangeId, rankPeriodId int, relationId int64) (v *Rank, err error) { | ||
| 73 | + o := orm.NewOrm() | ||
| 74 | + sql := "select * from rank where company_id=? and rank_type_id=? and rank_range_id=? and rank_period_id=? and relation_id=?" | ||
| 75 | + if err = o.Raw(sql, companyId, rankTypeId, rankRangeId, rankPeriodId, relationId).QueryRow(&v); err == nil { | ||
| 76 | + return v, nil | ||
| 77 | + } | ||
| 78 | + return nil, err | ||
| 79 | +} | ||
| 80 | + | ||
| 81 | +//排行列表-用户 | ||
| 82 | +func GetRanksByUser(companyId int64, rankTypeId, rankRangeId, rankPeriodId int, key string, pageIndex, pageSize int, v interface{}) (total int, err error) { | ||
| 83 | + //var filterDepartment string = getFilterSqlByDIds(dIds) | ||
| 84 | + pageIndex, pageSize = utils.GetPageInfo(pageIndex, pageSize) | ||
| 85 | + sql := fmt.Sprintf(`select (@rowno:=@rowno+1) as ranking,a.*,b.nick_name name from | ||
| 86 | +( | ||
| 87 | +select score,relation_id,user_id from( | ||
| 88 | +select a.%v score,a.relation_id,user_id from rank a inner join user_company c on a.relation_id=c.id | ||
| 89 | +where a.company_id=%v and rank_type_id=%v and rank_range_id=%v and rank_period_id=%v and a.enable_status=1 | ||
| 90 | +order by a.%v desc,c.create_at asc | ||
| 91 | +) a,(select @rowno:=%v) b | ||
| 92 | +limit %v,%v | ||
| 93 | +)a inner join user b on a.user_id = b.id | ||
| 94 | +`, key, companyId, rankTypeId, rankRangeId, rankPeriodId, key, pageIndex, pageIndex, pageSize) | ||
| 95 | + | ||
| 96 | + sqlCount := fmt.Sprintf(` | ||
| 97 | +select count(0) from rank | ||
| 98 | +where company_id=%v and rank_type_id=%v and rank_range_id=%v and rank_period_id=%v | ||
| 99 | +`, companyId, rankTypeId, rankRangeId, rankPeriodId) | ||
| 100 | + if err = utils.ExecuteQueryOne(&total, sqlCount); err != nil { | ||
| 101 | + return | ||
| 102 | + } | ||
| 103 | + if v != nil { | ||
| 104 | + if err = utils.ExecuteQueryAll(v, sql); err != nil { | ||
| 105 | + return | ||
| 106 | + } | ||
| 107 | + } | ||
| 108 | + return | ||
| 109 | +} | ||
| 110 | + | ||
| 111 | +//排行榜列表-用户-自己的排名 | ||
| 112 | +func GetRanksByUserSelf(companyId int64, rankTypeId, rankRangeId, rankPeriodId int, key string, relationId int64, v interface{}) (err error) { | ||
| 113 | + //var filterDepartment string = getFilterSqlByDIds(dIds) | ||
| 114 | + sql := fmt.Sprintf(` | ||
| 115 | + | ||
| 116 | +select a.*,b.nick_name name from | ||
| 117 | +( | ||
| 118 | +select score,relation_id,user_id,(@rowno:=@rowno+1) as ranking from( | ||
| 119 | +select a.%v score,a.relation_id,user_id from rank a inner join user_company c on a.relation_id=c.id | ||
| 120 | +where a.company_id=%v and rank_type_id=%v and rank_range_id=%v and rank_period_id=%v and a.enable_status=1 | ||
| 121 | +order by a.%v desc,c.create_at asc | ||
| 122 | +) a,(select @rowno:=0 ) b | ||
| 123 | +)a inner join user b on a.user_id = b.id | ||
| 124 | +where relation_id=%v | ||
| 125 | + | ||
| 126 | +`, key, companyId, rankTypeId, rankRangeId, rankPeriodId, key, relationId) | ||
| 127 | + | ||
| 128 | + if v != nil { | ||
| 129 | + if err = utils.ExecuteQueryOne(v, sql); err != nil { | ||
| 130 | + if err == orm.ErrNoRows { | ||
| 131 | + err = nil | ||
| 132 | + } | ||
| 133 | + return | ||
| 134 | + } | ||
| 135 | + } | ||
| 136 | + return | ||
| 137 | +} | ||
| 138 | + | ||
| 139 | +//排行榜列表-部门 | ||
| 140 | +func GetRanksByDepartment(companyId int64, rankTypeId, rankRangeId, rankPeriodId int, key string, pageIndex, pageSize int, v interface{}) (total int, err error) { | ||
| 141 | + //var filterDepartment string = getFilterSqlByDIds(dIds) | ||
| 142 | + pageIndex, pageSize = utils.GetPageInfo(pageIndex, pageSize) | ||
| 143 | + sql := fmt.Sprintf(` | ||
| 144 | +select a.*,(@rowno:=@rowno+1) as ranking from | ||
| 145 | +( | ||
| 146 | +select a.%v score,a.relation_id,c.name | ||
| 147 | +from rank a inner join department c on a.relation_id=c.id | ||
| 148 | +where a.company_id=%v and rank_type_id=%v and rank_range_id=%v and rank_period_id=%v and a.enable_status=1 | ||
| 149 | +order by a.%v desc,c.create_at asc | ||
| 150 | +)a,(select (@rowno:=%v)) b | ||
| 151 | +limit %v,%v | ||
| 152 | +`, key, companyId, rankTypeId, rankRangeId, rankPeriodId, key, pageIndex, pageIndex, pageSize) | ||
| 153 | + | ||
| 154 | + sqlCount := fmt.Sprintf(` | ||
| 155 | +select count(0) from rank | ||
| 156 | +where company_id=%v and rank_type_id=%v and rank_range_id=%v and rank_period_id=%v | ||
| 157 | +`, companyId, rankTypeId, rankRangeId, rankPeriodId) | ||
| 158 | + if err = utils.ExecuteQueryOne(&total, sqlCount); err != nil { | ||
| 159 | + return | ||
| 160 | + } | ||
| 161 | + if v != nil { | ||
| 162 | + if err = utils.ExecuteQueryAll(v, sql); err != nil { | ||
| 163 | + if err == orm.ErrNoRows { | ||
| 164 | + err = nil | ||
| 165 | + } | ||
| 166 | + return | ||
| 167 | + } | ||
| 168 | + } | ||
| 169 | + return | ||
| 170 | +} | ||
| 171 | + | ||
| 172 | +//排行榜列表-部门-用户所属部门排名 | ||
| 173 | +func GetRanksByDepartmentSelf(companyId int64, rankTypeId, rankRangeId, rankPeriodId int, key string, relationId int64, v interface{}) (err error) { | ||
| 174 | + sql := fmt.Sprintf(`select * from ( | ||
| 175 | +select a.*,(@rowno:=@rowno+1) as ranking from ( | ||
| 176 | +select a.%v score,a.relation_id,c.name from rank a inner join department c on a.relation_id=c.id | ||
| 177 | +where a.company_id=%v and rank_type_id=%v and rank_range_id=%v and rank_period_id=%v and a.enable_status=1 | ||
| 178 | +order by a.%v desc,c.create_at asc | ||
| 179 | +) a,(select (@rowno:=0)) b | ||
| 180 | +)a | ||
| 181 | +where a.relation_id=%v | ||
| 182 | + | ||
| 183 | +`, key, companyId, rankTypeId, rankRangeId, rankPeriodId, key, relationId) | ||
| 184 | + | ||
| 185 | + if v != nil { | ||
| 186 | + if err = utils.ExecuteQueryOne(v, sql); err != nil { | ||
| 187 | + if err == orm.ErrNoRows { | ||
| 188 | + err = nil | ||
| 189 | + } | ||
| 190 | + return | ||
| 191 | + } | ||
| 192 | + } | ||
| 193 | + return | ||
| 194 | +} |
models/rank_item.go
0 → 100644
| 1 | +package models | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "time" | ||
| 6 | + | ||
| 7 | + "github.com/astaxie/beego/orm" | ||
| 8 | +) | ||
| 9 | + | ||
| 10 | +type RankItem struct { | ||
| 11 | + Id int `orm:"column(id);auto"` | ||
| 12 | + CompanyId int `orm:"column(company_id);null" description:"公司编号 company.id"` | ||
| 13 | + RankTypeId int `orm:"column(rank_type_id)" description:"表rank_type.id 榜单类型编号"` | ||
| 14 | + CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"` | ||
| 15 | + UpdateAt time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间"` | ||
| 16 | + SortNum int `orm:"column(sort_num);null" description:"序号"` | ||
| 17 | + ItemName string `orm:"column(item_name);size(50);null" description:"评比项名称"` | ||
| 18 | + ItemKey string `orm:"column(item_key);size(50);null" description:"评比项键值(排行榜排序使用)"` | ||
| 19 | +} | ||
| 20 | + | ||
| 21 | +func (t *RankItem) TableName() string { | ||
| 22 | + return "rank_item" | ||
| 23 | +} | ||
| 24 | + | ||
| 25 | +func init() { | ||
| 26 | + orm.RegisterModel(new(RankItem)) | ||
| 27 | +} | ||
| 28 | + | ||
| 29 | +// AddRankItem insert a new RankItem into database and returns | ||
| 30 | +// last inserted Id on success. | ||
| 31 | +func AddRankItem(m *RankItem) (id int64, err error) { | ||
| 32 | + o := orm.NewOrm() | ||
| 33 | + id, err = o.Insert(m) | ||
| 34 | + return | ||
| 35 | +} | ||
| 36 | + | ||
| 37 | +// GetRankItemById retrieves RankItem by Id. Returns error if | ||
| 38 | +// Id doesn't exist | ||
| 39 | +func GetRankItemById(id int) (v *RankItem, err error) { | ||
| 40 | + o := orm.NewOrm() | ||
| 41 | + v = &RankItem{Id: id} | ||
| 42 | + if err = o.Read(v); err == nil { | ||
| 43 | + return v, nil | ||
| 44 | + } | ||
| 45 | + return nil, err | ||
| 46 | +} | ||
| 47 | + | ||
| 48 | +// UpdateRankItem updates RankItem by Id and returns error if | ||
| 49 | +// the record to be updated doesn't exist | ||
| 50 | +func UpdateRankItemById(m *RankItem) (err error) { | ||
| 51 | + o := orm.NewOrm() | ||
| 52 | + v := RankItem{Id: m.Id} | ||
| 53 | + // ascertain id exists in the database | ||
| 54 | + if err = o.Read(&v); err == nil { | ||
| 55 | + var num int64 | ||
| 56 | + if num, err = o.Update(m); err == nil { | ||
| 57 | + fmt.Println("Number of records updated in database:", num) | ||
| 58 | + } | ||
| 59 | + } | ||
| 60 | + return | ||
| 61 | +} | ||
| 62 | + | ||
| 63 | +// DeleteRankItem deletes RankItem by Id and returns error if | ||
| 64 | +// the record to be deleted doesn't exist | ||
| 65 | +func DeleteRankItem(id int) (err error) { | ||
| 66 | + o := orm.NewOrm() | ||
| 67 | + v := RankItem{Id: id} | ||
| 68 | + // ascertain id exists in the database | ||
| 69 | + if err = o.Read(&v); err == nil { | ||
| 70 | + var num int64 | ||
| 71 | + if num, err = o.Delete(&RankItem{Id: id}); err == nil { | ||
| 72 | + fmt.Println("Number of records deleted in database:", num) | ||
| 73 | + } | ||
| 74 | + } | ||
| 75 | + return | ||
| 76 | +} | ||
| 77 | + | ||
| 78 | +func GetRankItemKeys(companyId int64, rankTypeId int) (v []string, name []string, err error) { | ||
| 79 | + sql := "select item_key,item_name from rank_item where company_id=? and rank_type_id=? order by sort_num" | ||
| 80 | + o := orm.NewOrm() | ||
| 81 | + if _, err = o.Raw(sql, companyId, rankTypeId).QueryRows(&v, &name); err != nil { | ||
| 82 | + return | ||
| 83 | + } | ||
| 84 | + return | ||
| 85 | +} | ||
| 86 | + | ||
| 87 | +func GetRankItems(companyId int64, rankTypeId int, v interface{}) (err error) { | ||
| 88 | + sql := "select item_key,item_name from rank_item where company_id=? and rank_type_id=? order by sort_num" | ||
| 89 | + o := orm.NewOrm() | ||
| 90 | + if _, err = o.Raw(sql, companyId, rankTypeId).QueryRows(v); err != nil { | ||
| 91 | + return | ||
| 92 | + } | ||
| 93 | + return | ||
| 94 | +} |
models/rank_period.go
0 → 100644
| 1 | +package models | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/mybeego" | ||
| 6 | + "opp/internal/utils" | ||
| 7 | + "time" | ||
| 8 | + | ||
| 9 | + "github.com/astaxie/beego/orm" | ||
| 10 | +) | ||
| 11 | + | ||
| 12 | +type RankPeriod struct { | ||
| 13 | + Id int `orm:"column(id);auto" description:"主键"` | ||
| 14 | + CompanyId int `orm:"column(company_id);null" description:"公司编号 表company.id"` | ||
| 15 | + RankTypeId int `orm:"column(rank_type_id)" description:"表rank_type.id 榜单类型编号"` | ||
| 16 | + SeasonName string `orm:"column(season_name);size(50);null" description:"赛季名称"` | ||
| 17 | + BeginTime time.Time `orm:"column(begin_time);type(timestamp);null" description:"开始时间"` | ||
| 18 | + EndTime time.Time `orm:"column(end_time);type(timestamp);null" description:"结束时间"` | ||
| 19 | + CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"` | ||
| 20 | + UpdateAt time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间"` | ||
| 21 | + Status int8 `orm:"column(status);null" description:"状态 0:未开始 1:开始 2:结束 "` | ||
| 22 | + RankRangeBack string `orm:"column(rank_range_back);null" description:"赛季结束时,备份赛季参与人设置"` | ||
| 23 | + RankItemBack string `orm:"column(rank_item_back);null" description:"赛季结束时,备份赛季评比项设置"` | ||
| 24 | +} | ||
| 25 | + | ||
| 26 | +func (t *RankPeriod) TableName() string { | ||
| 27 | + return "rank_period" | ||
| 28 | +} | ||
| 29 | + | ||
| 30 | +func init() { | ||
| 31 | + orm.RegisterModel(new(RankPeriod)) | ||
| 32 | +} | ||
| 33 | + | ||
| 34 | +// AddRankPeriod insert a new RankPeriod into database and returns | ||
| 35 | +// last inserted Id on success. | ||
| 36 | +func AddRankPeriod(m *RankPeriod) (id int64, err error) { | ||
| 37 | + o := orm.NewOrm() | ||
| 38 | + id, err = o.Insert(m) | ||
| 39 | + return | ||
| 40 | +} | ||
| 41 | + | ||
| 42 | +// GetRankPeriodById retrieves RankPeriod by Id. Returns error if | ||
| 43 | +// Id doesn't exist | ||
| 44 | +func GetRankPeriodById(id int) (v *RankPeriod, err error) { | ||
| 45 | + o := orm.NewOrm() | ||
| 46 | + v = &RankPeriod{Id: id} | ||
| 47 | + if err = o.Read(v); err == nil { | ||
| 48 | + return v, nil | ||
| 49 | + } | ||
| 50 | + return nil, err | ||
| 51 | +} | ||
| 52 | + | ||
| 53 | +// UpdateRankPeriod updates RankPeriod by Id and returns error if | ||
| 54 | +// the record to be updated doesn't exist | ||
| 55 | +func UpdateRankPeriodById(m *RankPeriod) (err error) { | ||
| 56 | + o := orm.NewOrm() | ||
| 57 | + v := RankPeriod{Id: m.Id} | ||
| 58 | + // ascertain id exists in the database | ||
| 59 | + if err = o.Read(&v); err == nil { | ||
| 60 | + var num int64 | ||
| 61 | + if num, err = o.Update(m); err == nil { | ||
| 62 | + fmt.Println("Number of records updated in database:", num) | ||
| 63 | + } | ||
| 64 | + } | ||
| 65 | + return | ||
| 66 | +} | ||
| 67 | + | ||
| 68 | +// DeleteRankPeriod deletes RankPeriod by Id and returns error if | ||
| 69 | +// the record to be deleted doesn't exist | ||
| 70 | +func DeleteRankPeriod(id int) (err error) { | ||
| 71 | + o := orm.NewOrm() | ||
| 72 | + v := RankPeriod{Id: id} | ||
| 73 | + // ascertain id exists in the database | ||
| 74 | + if err = o.Read(&v); err == nil { | ||
| 75 | + var num int64 | ||
| 76 | + if num, err = o.Delete(&RankPeriod{Id: id}); err == nil { | ||
| 77 | + fmt.Println("Number of records deleted in database:", num) | ||
| 78 | + } | ||
| 79 | + } | ||
| 80 | + return | ||
| 81 | +} | ||
| 82 | + | ||
| 83 | +//获取进行中的赛季周期 状态 0:未开始 1:开始 2:结束 | ||
| 84 | +func GetRankPeriods(companyId int, rankTypeId int, status []int) (v []*RankPeriod, err error) { | ||
| 85 | + sql := mybeego.NewSqlExutor() | ||
| 86 | + sql.Table((&RankPeriod{}).TableName()) | ||
| 87 | + if companyId > 0 { | ||
| 88 | + sql.Where(fmt.Sprintf("company_id=%v", companyId)) | ||
| 89 | + } | ||
| 90 | + if rankTypeId > 0 { | ||
| 91 | + sql.Where(fmt.Sprintf("rank_type_id=%v", rankTypeId)) | ||
| 92 | + } | ||
| 93 | + if len(status) > 0 { | ||
| 94 | + sql.Where(fmt.Sprintf("status in (%v)", utils.JoinInts(status, ","))) | ||
| 95 | + } | ||
| 96 | + sql.Order("end_time desc") | ||
| 97 | + _, err = sql.Querys(&v) | ||
| 98 | + return | ||
| 99 | +} |
models/rank_range.go
0 → 100644
| 1 | +package models | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/mybeego" | ||
| 6 | + "time" | ||
| 7 | + | ||
| 8 | + "github.com/astaxie/beego/orm" | ||
| 9 | +) | ||
| 10 | + | ||
| 11 | +type RankRange struct { | ||
| 12 | + Id int `orm:"column(id);auto"` | ||
| 13 | + CompanyId int `orm:"column(company_id);null" description:"公司编号 表company.id"` | ||
| 14 | + RankTypeId int `orm:"column(rank_type_id)" description:"表rank_type.id 榜单类型编号"` | ||
| 15 | + Name string `orm:"column(name);size(50);null" description:"名称"` | ||
| 16 | + Type int8 `orm:"column(type);null" description:"1:所有员工 2:指定员工 3:所有部门 4:指定部门"` | ||
| 17 | + SortNum int `orm:"column(sort_num);null" description:"序号"` | ||
| 18 | + CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间"` | ||
| 19 | + UpdateAt time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间"` | ||
| 20 | + Status int8 `orm:"column(status);null" description:"【0:显示】【1:隐藏】"` | ||
| 21 | + Data string `orm:"column(data);null"` | ||
| 22 | +} | ||
| 23 | + | ||
| 24 | +func (t *RankRange) TableName() string { | ||
| 25 | + return "rank_range" | ||
| 26 | +} | ||
| 27 | + | ||
| 28 | +func init() { | ||
| 29 | + orm.RegisterModel(new(RankRange)) | ||
| 30 | +} | ||
| 31 | + | ||
| 32 | +// AddRankRange insert a new RankRange into database and returns | ||
| 33 | +// last inserted Id on success. | ||
| 34 | +func AddRankRange(m *RankRange) (id int64, err error) { | ||
| 35 | + o := orm.NewOrm() | ||
| 36 | + id, err = o.Insert(m) | ||
| 37 | + return | ||
| 38 | +} | ||
| 39 | + | ||
| 40 | +// GetRankRangeById retrieves RankRange by Id. Returns error if | ||
| 41 | +// Id doesn't exist | ||
| 42 | +func GetRankRangeById(id int) (v *RankRange, err error) { | ||
| 43 | + o := orm.NewOrm() | ||
| 44 | + v = &RankRange{Id: id} | ||
| 45 | + if err = o.Read(v); err == nil { | ||
| 46 | + return v, nil | ||
| 47 | + } | ||
| 48 | + return nil, err | ||
| 49 | +} | ||
| 50 | + | ||
| 51 | +// UpdateRankRange updates RankRange by Id and returns error if | ||
| 52 | +// the record to be updated doesn't exist | ||
| 53 | +func UpdateRankRangeById(m *RankRange) (err error) { | ||
| 54 | + o := orm.NewOrm() | ||
| 55 | + v := RankRange{Id: m.Id} | ||
| 56 | + // ascertain id exists in the database | ||
| 57 | + if err = o.Read(&v); err == nil { | ||
| 58 | + var num int64 | ||
| 59 | + if num, err = o.Update(m); err == nil { | ||
| 60 | + fmt.Println("Number of records updated in database:", num) | ||
| 61 | + } | ||
| 62 | + } | ||
| 63 | + return | ||
| 64 | +} | ||
| 65 | + | ||
| 66 | +// DeleteRankRange deletes RankRange by Id and returns error if | ||
| 67 | +// the record to be deleted doesn't exist | ||
| 68 | +func DeleteRankRange(id int) (err error) { | ||
| 69 | + o := orm.NewOrm() | ||
| 70 | + v := RankRange{Id: id} | ||
| 71 | + // ascertain id exists in the database | ||
| 72 | + if err = o.Read(&v); err == nil { | ||
| 73 | + var num int64 | ||
| 74 | + if num, err = o.Delete(&RankRange{Id: id}); err == nil { | ||
| 75 | + fmt.Println("Number of records deleted in database:", num) | ||
| 76 | + } | ||
| 77 | + } | ||
| 78 | + return | ||
| 79 | +} | ||
| 80 | + | ||
| 81 | +//获取榜单范围数据 | ||
| 82 | +func GetRankRanges(companyId int, rankTypeId int) (v []*RankRange, err error) { | ||
| 83 | + sql := mybeego.NewSqlExutor() | ||
| 84 | + sql.Table((&RankRange{}).TableName()) | ||
| 85 | + if companyId > 0 { | ||
| 86 | + sql.Where(fmt.Sprintf("company_id=%v", companyId)) | ||
| 87 | + } | ||
| 88 | + //if rankTypeId > 0 { | ||
| 89 | + sql.Where(fmt.Sprintf("rank_type_id=%v", rankTypeId)) | ||
| 90 | + //} | ||
| 91 | + sql.Order("sort_num") | ||
| 92 | + _, err = sql.Querys(&v) | ||
| 93 | + return | ||
| 94 | +} |
models/rank_range_data.go
0 → 100644
| 1 | +package models | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "github.com/astaxie/beego/orm" | ||
| 6 | + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/mybeego" | ||
| 7 | +) | ||
| 8 | + | ||
| 9 | +type RankRangeData struct { | ||
| 10 | + Id int `orm:"column(id);auto"` | ||
| 11 | + RankRangeId int `orm:"column(rank_range_id);null"` | ||
| 12 | + RangeType string `orm:"column(range_type);size(255);null" description:"类型"` | ||
| 13 | + RelationId int `orm:"column(relation_id);null"` | ||
| 14 | +} | ||
| 15 | + | ||
| 16 | +func (t *RankRangeData) TableName() string { | ||
| 17 | + return "rank_range_data" | ||
| 18 | +} | ||
| 19 | + | ||
| 20 | +func init() { | ||
| 21 | + orm.RegisterModel(new(RankRangeData)) | ||
| 22 | +} | ||
| 23 | + | ||
| 24 | +// AddRankRangeData insert a new RankRangeData into database and returns | ||
| 25 | +// last inserted Id on success. | ||
| 26 | +func AddRankRangeData(m *RankRangeData) (id int64, err error) { | ||
| 27 | + o := orm.NewOrm() | ||
| 28 | + id, err = o.Insert(m) | ||
| 29 | + return | ||
| 30 | +} | ||
| 31 | + | ||
| 32 | +// GetRankRangeDataById retrieves RankRangeData by Id. Returns error if | ||
| 33 | +// Id doesn't exist | ||
| 34 | +func GetRankRangeDataById(id int) (v *RankRangeData, err error) { | ||
| 35 | + o := orm.NewOrm() | ||
| 36 | + v = &RankRangeData{Id: id} | ||
| 37 | + if err = o.Read(v); err == nil { | ||
| 38 | + return v, nil | ||
| 39 | + } | ||
| 40 | + return nil, err | ||
| 41 | +} | ||
| 42 | + | ||
| 43 | +// UpdateRankRangeData updates RankRangeData by Id and returns error if | ||
| 44 | +// the record to be updated doesn't exist | ||
| 45 | +func UpdateRankRangeDataById(m *RankRangeData) (err error) { | ||
| 46 | + o := orm.NewOrm() | ||
| 47 | + v := RankRangeData{Id: m.Id} | ||
| 48 | + // ascertain id exists in the database | ||
| 49 | + if err = o.Read(&v); err == nil { | ||
| 50 | + var num int64 | ||
| 51 | + if num, err = o.Update(m); err == nil { | ||
| 52 | + fmt.Println("Number of records updated in database:", num) | ||
| 53 | + } | ||
| 54 | + } | ||
| 55 | + return | ||
| 56 | +} | ||
| 57 | + | ||
| 58 | +// DeleteRankRangeData deletes RankRangeData by Id and returns error if | ||
| 59 | +// the record to be deleted doesn't exist | ||
| 60 | +func DeleteRankRangeData(id int) (err error) { | ||
| 61 | + o := orm.NewOrm() | ||
| 62 | + v := RankRangeData{Id: id} | ||
| 63 | + // ascertain id exists in the database | ||
| 64 | + if err = o.Read(&v); err == nil { | ||
| 65 | + var num int64 | ||
| 66 | + if num, err = o.Delete(&RankRangeData{Id: id}); err == nil { | ||
| 67 | + fmt.Println("Number of records deleted in database:", num) | ||
| 68 | + } | ||
| 69 | + } | ||
| 70 | + return | ||
| 71 | +} | ||
| 72 | + | ||
| 73 | +//参榜范围列表 | ||
| 74 | +func GetRankRangeDataList(rankRangeId int) (v []*RankRangeData, err error) { | ||
| 75 | + sql := mybeego.NewSqlExutor() | ||
| 76 | + sql.Table((&RankRangeData{}).TableName()) | ||
| 77 | + if rankRangeId > 0 { | ||
| 78 | + sql.Where(fmt.Sprintf("rank_range_id=%v", rankRangeId)) | ||
| 79 | + } | ||
| 80 | + sql.Order("relation_id") | ||
| 81 | + _, err = sql.Querys(&v) | ||
| 82 | + return | ||
| 83 | +} |
models/rank_type.go
0 → 100644
| 1 | +package models | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/mybeego" | ||
| 6 | + "time" | ||
| 7 | + | ||
| 8 | + "github.com/astaxie/beego/orm" | ||
| 9 | +) | ||
| 10 | + | ||
| 11 | +type RankType struct { | ||
| 12 | + Id int `orm:"column(id);auto" json:"id"` | ||
| 13 | + Name string `orm:"column(name);size(50)" description:"榜单名称" json:"name"` | ||
| 14 | + CompanyId int `orm:"column(company_id)" description:"公司编号 company.id" json:"-"` | ||
| 15 | + CreateAt time.Time `orm:"column(create_at);type(timestamp);null" description:"创建时间" json:"-"` | ||
| 16 | + UpdateAt time.Time `orm:"column(update_at);type(timestamp);null" description:"更新时间" json:"-"` | ||
| 17 | + EnableStatus int8 `orm:"column(enable_status);null" description:"是否有效 【1:禁用】【2:启用】" json:"-"` | ||
| 18 | + Type int8 `orm:"column(type);null" description:"榜单类型(1赛季榜、2年榜) json:"type"` | ||
| 19 | +} | ||
| 20 | + | ||
| 21 | +func (t *RankType) TableName() string { | ||
| 22 | + return "rank_type" | ||
| 23 | +} | ||
| 24 | + | ||
| 25 | +func init() { | ||
| 26 | + orm.RegisterModel(new(RankType)) | ||
| 27 | +} | ||
| 28 | + | ||
| 29 | +// AddRankType insert a new RankType into database and returns | ||
| 30 | +// last inserted Id on success. | ||
| 31 | +func AddRankType(m *RankType) (id int64, err error) { | ||
| 32 | + o := orm.NewOrm() | ||
| 33 | + id, err = o.Insert(m) | ||
| 34 | + return | ||
| 35 | +} | ||
| 36 | + | ||
| 37 | +// GetRankTypeById retrieves RankType by Id. Returns error if | ||
| 38 | +// Id doesn't exist | ||
| 39 | +func GetRankTypeById(id int) (v *RankType, err error) { | ||
| 40 | + o := orm.NewOrm() | ||
| 41 | + v = &RankType{Id: id} | ||
| 42 | + if err = o.Read(v); err == nil { | ||
| 43 | + return v, nil | ||
| 44 | + } | ||
| 45 | + return nil, err | ||
| 46 | +} | ||
| 47 | + | ||
| 48 | +// UpdateRankType updates RankType by Id and returns error if | ||
| 49 | +// the record to be updated doesn't exist | ||
| 50 | +func UpdateRankTypeById(m *RankType) (err error) { | ||
| 51 | + o := orm.NewOrm() | ||
| 52 | + v := RankType{Id: m.Id} | ||
| 53 | + // ascertain id exists in the database | ||
| 54 | + if err = o.Read(&v); err == nil { | ||
| 55 | + var num int64 | ||
| 56 | + if num, err = o.Update(m); err == nil { | ||
| 57 | + fmt.Println("Number of records updated in database:", num) | ||
| 58 | + } | ||
| 59 | + } | ||
| 60 | + return | ||
| 61 | +} | ||
| 62 | + | ||
| 63 | +// DeleteRankType deletes RankType by Id and returns error if | ||
| 64 | +// the record to be deleted doesn't exist | ||
| 65 | +func DeleteRankType(id int) (err error) { | ||
| 66 | + o := orm.NewOrm() | ||
| 67 | + v := RankType{Id: id} | ||
| 68 | + // ascertain id exists in the database | ||
| 69 | + if err = o.Read(&v); err == nil { | ||
| 70 | + var num int64 | ||
| 71 | + if num, err = o.Delete(&RankType{Id: id}); err == nil { | ||
| 72 | + fmt.Println("Number of records deleted in database:", num) | ||
| 73 | + } | ||
| 74 | + } | ||
| 75 | + return | ||
| 76 | +} | ||
| 77 | + | ||
| 78 | +// | ||
| 79 | +func GetRankTypes(companyId int64) (v []*RankType, err error) { | ||
| 80 | + sql := mybeego.NewSqlExutor() | ||
| 81 | + sql.Table((&RankType{}).TableName()) | ||
| 82 | + if companyId > 0 { | ||
| 83 | + sql.Where(fmt.Sprintf("company_id=%v", companyId)) | ||
| 84 | + } | ||
| 85 | + sql.Where(fmt.Sprintf("enable_status=2")) | ||
| 86 | + sql.Order("type") | ||
| 87 | + sql.Limit(0, 2) | ||
| 88 | + _, err = sql.Querys(&v) | ||
| 89 | + return | ||
| 90 | +} |
| @@ -109,3 +109,12 @@ func GetUserCompanysFirst(uid int64) (v *UserCompany, err error) { | @@ -109,3 +109,12 @@ func GetUserCompanysFirst(uid int64) (v *UserCompany, err error) { | ||
| 109 | } | 109 | } |
| 110 | return nil, err | 110 | return nil, err |
| 111 | } | 111 | } |
| 112 | + | ||
| 113 | +func GetUserCompanyIdAll(companyId int) (v []int64, err error) { | ||
| 114 | + o := orm.NewOrm() | ||
| 115 | + sql := "select id from user_company where company_id=? and enable=1" //and enable=1 | ||
| 116 | + if _, err = o.Raw(sql, companyId).QueryRows(&v); err == nil { | ||
| 117 | + return v, nil | ||
| 118 | + } | ||
| 119 | + return nil, err | ||
| 120 | +} |
| @@ -244,3 +244,26 @@ from user_msg where receive_user_id=? and source_type=1 and msg_type=? and send | @@ -244,3 +244,26 @@ from user_msg where receive_user_id=? and source_type=1 and msg_type=? and send | ||
| 244 | } | 244 | } |
| 245 | return | 245 | return |
| 246 | } | 246 | } |
| 247 | + | ||
| 248 | +func GetChanceReviseMsg(uid, lastId int64, pageSize int, msgType int, v interface{}) (total int, err error) { | ||
| 249 | + sql := `select a.*,b.images,b.speechs,b.videos from ( | ||
| 250 | +select a.*,b.source_content,b.enable_status,b.user_id chance_user_id,b.create_at,b.review_status,b.status from ( | ||
| 251 | +select id msg_id,message,source_type,source_id,is_read,create_at msg_time,chance_id,receive_user_id,sender_user_id from user_msg | ||
| 252 | +where receive_user_id =? and (?=0 or id<?) and msg_type=? | ||
| 253 | +)a left outer join chance b on a.chance_id = b.id | ||
| 254 | +)a left outer join chance_data b on a.chance_id = b.chance_id | ||
| 255 | +order by msg_id desc | ||
| 256 | +LIMIT ?` | ||
| 257 | + | ||
| 258 | + sqlCount := `select count(0) | ||
| 259 | +from user_msg where receive_user_id=? and msg_type=?` | ||
| 260 | + if err = utils.ExecuteQueryOne(&total, sqlCount, uid, msgType); err != nil { | ||
| 261 | + return | ||
| 262 | + } | ||
| 263 | + if v != nil { | ||
| 264 | + if err = utils.ExecuteQueryAll(v, sql, uid, lastId, lastId, msgType, pageSize); err != nil { | ||
| 265 | + return | ||
| 266 | + } | ||
| 267 | + } | ||
| 268 | + return | ||
| 269 | +} |
protocol/achievement.go
0 → 100644
| 1 | +package protocol | ||
| 2 | + | ||
| 3 | +import "time" | ||
| 4 | + | ||
| 5 | +const ( | ||
| 6 | + Grasper = 1 //把握人 | ||
| 7 | + Provider = 2 //提供者 | ||
| 8 | +) | ||
| 9 | + | ||
| 10 | +//成果项 | ||
| 11 | +type AchievementItem struct { | ||
| 12 | + Id int64 `json:"id"` | ||
| 13 | + CreateTime int64 `json:"createTime"` | ||
| 14 | + Provider *BaseUserInfo `json:"provider"` | ||
| 15 | + Content string `json:"content"` | ||
| 16 | + Pictures []Picture `json:"pictures"` | ||
| 17 | + //GraspScore float64 `json:"graspScore"` //把握分 | ||
| 18 | + //GraspScorePercent float64 `json:"graspScorePercent"` //把握分百分比 | ||
| 19 | +} | ||
| 20 | + | ||
| 21 | +type GraspScore struct { | ||
| 22 | + GraspScore float64 `json:"graspScore"` //把握分 | ||
| 23 | + GraspScorePercent float64 `json:"graspScorePercent"` //把握分百分比 | ||
| 24 | +} | ||
| 25 | + | ||
| 26 | +//机会列表 通用项 | ||
| 27 | +type AchievementCommonListItem struct { | ||
| 28 | + Achievement AchievementItem `json:"achievement,omitempty"` //成果详情 | ||
| 29 | + StatisticData interface{} `json:"statisticData,omitempty"` //统计数据(是否收藏/点赞 浏览数 点赞总数 评论数)ChanceData | ||
| 30 | + //我审核的-通过 | ||
| 31 | + Score interface{} `json:"score,omitempty"` | ||
| 32 | + GraspScore interface{} `json:"graspScore,omitempty"` //把握分 | ||
| 33 | + //模板 | ||
| 34 | + ChanceType interface{} `json:"chanceType,omitempty"` //机会类型 | ||
| 35 | + ChanceTemplate interface{} `json:"template,omitempty"` //机会模板 | ||
| 36 | + | ||
| 37 | + Message interface{} `json:"message,omitempty"` //消息 | ||
| 38 | + CommentData interface{} `json:"commentData,omitempty"` //评论 | ||
| 39 | + CollectData interface{} `json:"collectData,omitempty"` //收藏数据 | ||
| 40 | + ThumbUpData interface{} `json:"thumbUpData,omitempty"` //点赞数据 | ||
| 41 | + //我评论的 评论数据 | ||
| 42 | + CommentedData interface{} `json:"commentedData,omitempty"` | ||
| 43 | + | ||
| 44 | + SourceType int `json:"sourceType,omitempty"` //类型 1:机会 2:评论 | ||
| 45 | + Status int `json:"-"` //0:删除 1:开启 2:关闭 | ||
| 46 | +} | ||
| 47 | + | ||
| 48 | +/*AchievementPool 成果池*/ | ||
| 49 | +type AchievementPoolRequest struct { | ||
| 50 | + UserId int64 `json:"userId"` | ||
| 51 | + LastId int64 `json:"lastId"` | ||
| 52 | + PageSize int `json:"pageSize" valid:"Required"` | ||
| 53 | + ChanceTypeId int `json:"chanceTypeId"` //0:所有机会 编号:对应机会类型编号的机会 | ||
| 54 | + DepartmentId int `json:"departmentId"` | ||
| 55 | + IncludeSubDepartment bool | ||
| 56 | +} | ||
| 57 | +type AchievementPoolResponse struct { | ||
| 58 | + List []*AchievementCommonListItem `json:"list"` | ||
| 59 | + Total int `json:"total"` | ||
| 60 | +} | ||
| 61 | + | ||
| 62 | +//通用 机会orm对象 | ||
| 63 | +type CommAchievementItemOrm struct { | ||
| 64 | + AchievementItemOrm | ||
| 65 | + StaticDataOrm | ||
| 66 | +} | ||
| 67 | +type AchievementItemOrm struct { | ||
| 68 | + AchievementId int64 `orm:"column(id)"` | ||
| 69 | + UserId int64 `orm:"column(user_company_id)"` | ||
| 70 | + CreateTime time.Time `orm:"column(create_at)"` | ||
| 71 | + SourceContent string `orm:"column(source_content)"` | ||
| 72 | + Images string `orm:"column(images)"` | ||
| 73 | + GraspScore float64 `orm:"column(grasp_score)"` | ||
| 74 | + UserGraspScore float64 `orm:"column(user_grasp_score)"` | ||
| 75 | + | ||
| 76 | + TemplateId int `orm:"column(audit_template_id)"` | ||
| 77 | + ChanceTypeId int `orm:"column(chance_type_id)"` | ||
| 78 | + Status int `orm:"column(status)"` | ||
| 79 | +} | ||
| 80 | + | ||
| 81 | +type StaticDataOrm struct { | ||
| 82 | + CommentTotal int `orm:"column(comment_total)"` | ||
| 83 | + ZanTotal int `orm:"column(zan_total)"` | ||
| 84 | + ViewTotal int `orm:"column(view_total)"` | ||
| 85 | +} | ||
| 86 | + | ||
| 87 | +//机会池收藏列表项 | ||
| 88 | +//type AchievementsOrm struct { | ||
| 89 | +// CommAchievementItemOrm | ||
| 90 | +//} | ||
| 91 | + | ||
| 92 | +/*MyGrasp 我把握的*/ | ||
| 93 | +type MyGraspRequest struct { | ||
| 94 | + AchievementPoolRequest | ||
| 95 | +} | ||
| 96 | +type MyGraspResponse struct { | ||
| 97 | + AchievementPoolResponse | ||
| 98 | +} | ||
| 99 | + | ||
| 100 | +/*AchievementDetail 成果详情*/ | ||
| 101 | +type AchievementDetailRequest struct { | ||
| 102 | + Id int64 `json:"id" valid:"Required"` | ||
| 103 | +} | ||
| 104 | +type AchievementDetailResponse struct { | ||
| 105 | + Achievement AchievementItem `json:"achievement,omitempty"` //成果详情 | ||
| 106 | + GraspScore interface{} `json:"graspScore,omitempty"` //把握分 | ||
| 107 | + StatisticData interface{} `json:"statisticData,omitempty"` //统计数据(是否收藏/点赞 浏览数 点赞总数 评论数 | ||
| 108 | + //模板 | ||
| 109 | + ChanceType interface{} `json:"chanceType,omitempty"` //机会类型 | ||
| 110 | + ChanceTemplate interface{} `json:"template,omitempty"` //机会模板 | ||
| 111 | + Status int `json:"-"` //0:删除 1:开启 2:关闭 | ||
| 112 | + SourceChance []*CommonListItem `json:"sourceChance"` //机会来源 | ||
| 113 | + Participants []UserGraspInfo `json:"participants"` //参与人 | ||
| 114 | +} | ||
| 115 | + | ||
| 116 | +type UserGraspInfo struct { | ||
| 117 | + Provider *BaseUserInfo `json:"provider"` | ||
| 118 | + GraspScore GraspScore `json:"graspScore"` //把握分 | ||
| 119 | + //GraspScorePercent float64 `json:"graspScorePercent"` //把握分百分比 | ||
| 120 | + Type int `json:"type"` //1:把握人 2:提供者 | ||
| 121 | +} | ||
| 122 | + | ||
| 123 | +type SourceChanceItemOrm struct { | ||
| 124 | + CommChanceItemOrm | ||
| 125 | + | ||
| 126 | + TemplateId int `orm:"column(audit_template_id)"` | ||
| 127 | + ChanceTypeId int `orm:"column(chance_type_id)"` | ||
| 128 | +} | ||
| 129 | + | ||
| 130 | +/*MyGraspStatistic */ | ||
| 131 | +type MyGraspStatisticRequest struct { | ||
| 132 | +} | ||
| 133 | +type MyGraspStatisticResponse struct { | ||
| 134 | + GraspStatistic interface{} `json:"list"` | ||
| 135 | +} |
| @@ -168,6 +168,8 @@ type ChancePoolRequest struct { | @@ -168,6 +168,8 @@ type ChancePoolRequest struct { | ||
| 168 | LastId int64 `json:"lastId"` | 168 | LastId int64 `json:"lastId"` |
| 169 | PageSize int `json:"pageSize" valid:"Required"` | 169 | PageSize int `json:"pageSize" valid:"Required"` |
| 170 | ChanceTypeId int `json:"chanceTypeId"` //0:所有机会 编号:对应机会类型编号的机会 | 170 | ChanceTypeId int `json:"chanceTypeId"` //0:所有机会 编号:对应机会类型编号的机会 |
| 171 | + DepartmentId int `json:"departmentId"` //部门编号 | ||
| 172 | + IncludeSubDepartment bool | ||
| 171 | } | 173 | } |
| 172 | type ChancePoolResponse struct { | 174 | type ChancePoolResponse struct { |
| 173 | List []CommonListItem `json:"list"` | 175 | List []CommonListItem `json:"list"` |
| @@ -331,6 +333,25 @@ type ChanceCommentItemOrm struct { | @@ -331,6 +333,25 @@ type ChanceCommentItemOrm struct { | ||
| 331 | SenderUserId int64 `orm:"column(sender_user_id)"` | 333 | SenderUserId int64 `orm:"column(sender_user_id)"` |
| 332 | } | 334 | } |
| 333 | 335 | ||
| 336 | +//我的评论 | ||
| 337 | +type ChanceReviseItemOrm struct { | ||
| 338 | + CommChanceItemOrm | ||
| 339 | + MsgItemOrm | ||
| 340 | +} | ||
| 341 | + | ||
| 342 | +//消息 | ||
| 343 | +type MsgItemOrm struct { | ||
| 344 | + MsgId int64 `orm:"column(msg_id)"` | ||
| 345 | + MsgTime time.Time `orm:"column(msg_time)"` //收藏时间 | ||
| 346 | + Message string `orm:"column(message)"` | ||
| 347 | + //评论对象类型 | ||
| 348 | + SourceType int `orm:"column(source_type)"` | ||
| 349 | + SourceId int64 `orm:"column(source_id)"` | ||
| 350 | + IsRead int64 `orm:"column(is_read)"` | ||
| 351 | + ReceiveUserId int64 `orm:"column(receive_user_id)"` | ||
| 352 | + SenderUserId int64 `orm:"column(sender_user_id)"` | ||
| 353 | +} | ||
| 354 | + | ||
| 334 | //通用 机会orm对象 | 355 | //通用 机会orm对象 |
| 335 | type CommChanceItemOrm struct { | 356 | type CommChanceItemOrm struct { |
| 336 | ChanceId int64 `orm:"column(chance_id)"` | 357 | ChanceId int64 `orm:"column(chance_id)"` |
| @@ -516,9 +537,9 @@ type CommonListItem struct { | @@ -516,9 +537,9 @@ type CommonListItem struct { | ||
| 516 | 537 | ||
| 517 | ChanceStatus int `json:"chanceStatus"` //0:正常 1.删除 2.关闭 | 538 | ChanceStatus int `json:"chanceStatus"` //0:正常 1.删除 2.关闭 |
| 518 | Status int `json:"-"` //1:开启 2:关闭 | 539 | Status int `json:"-"` //1:开启 2:关闭 |
| 519 | - ReviewStatus int `json:"reviewStatus"` //审核状态 | 540 | + ReviewStatus int `json:"reviewStatus,omitempty"` //审核状态 |
| 520 | 541 | ||
| 521 | - ChanceId int64 `json:"chanceId"` //机会编号 | 542 | + ChanceId int64 `json:"chanceId,omitempty"` //机会编号 |
| 522 | } | 543 | } |
| 523 | 544 | ||
| 524 | type MsgCommonListItem struct { | 545 | type MsgCommonListItem struct { |
| @@ -543,11 +564,16 @@ type MsgCommonListItem struct { | @@ -543,11 +564,16 @@ type MsgCommonListItem struct { | ||
| 543 | CommentedData interface{} `json:"commentedData,omitempty"` | 564 | CommentedData interface{} `json:"commentedData,omitempty"` |
| 544 | 565 | ||
| 545 | SourceType int `json:"sourceType,omitempty"` //类型 1:机会 2:评论 | 566 | SourceType int `json:"sourceType,omitempty"` //类型 1:机会 2:评论 |
| 567 | + SourceId int64 `json:"sourceId,omitempty"` //类型 1:机会 2:评论 | ||
| 546 | ChanceStatus int `json:"chanceStatus"` //0:正常 1.删除 2.关闭 | 568 | ChanceStatus int `json:"chanceStatus"` //0:正常 1.删除 2.关闭 |
| 547 | ReviewStatus int `json:"reviewStatus"` //审核状态 | 569 | ReviewStatus int `json:"reviewStatus"` //审核状态 |
| 548 | 570 | ||
| 549 | IsRead bool `json:"isRead"` | 571 | IsRead bool `json:"isRead"` |
| 550 | ChanceId int64 `json:"chanceId"` //机会编号 | 572 | ChanceId int64 `json:"chanceId"` //机会编号 |
| 573 | + ChanceReviseLogId int64 `json:"chanceReviseLogId,omitempty"` //机会补充编号 | ||
| 574 | +} | ||
| 575 | + | ||
| 576 | +type MsgItem struct { | ||
| 551 | } | 577 | } |
| 552 | type ChanceItem struct { | 578 | type ChanceItem struct { |
| 553 | Id int64 `json:"id"` | 579 | Id int64 `json:"id"` |
| @@ -593,3 +619,27 @@ type CommentData struct { | @@ -593,3 +619,27 @@ type CommentData struct { | ||
| 593 | //IsRead bool `json:"isRead"` //是否已读 | 619 | //IsRead bool `json:"isRead"` //是否已读 |
| 594 | Provider interface{} `json:"provider,omitempty"` | 620 | Provider interface{} `json:"provider,omitempty"` |
| 595 | } | 621 | } |
| 622 | + | ||
| 623 | +type ChanceReviseLog struct { | ||
| 624 | + Provider *BaseUserInfo `json:"provider,omitempty"` | ||
| 625 | + CreateTime int64 `json:"createTime"` | ||
| 626 | + DiffContents []ReviseContent `json:"reviseContents"` | ||
| 627 | + Speechs []Speech `json:"speechs"` | ||
| 628 | + Pictures []Picture `json:"pictures"` | ||
| 629 | + Videos []Video `json:"videos"` | ||
| 630 | + RemoveAllPhotoVideo bool `json:"removeAllPhotoVideo"` //是否移除所有图片 视频 | ||
| 631 | + RemoveAllSpeech bool `json:"removeAllSpeech"` //是否移除所有音频 | ||
| 632 | +} | ||
| 633 | + | ||
| 634 | +type ReviseContent struct { | ||
| 635 | + Content string `json:"content"` | ||
| 636 | +} | ||
| 637 | + | ||
| 638 | +/*ChanceReviseDetail 机会补充详情*/ | ||
| 639 | +type ChanceReviseDetailRequest struct { | ||
| 640 | + Id int64 `json:"id"` | ||
| 641 | +} | ||
| 642 | +type ChanceReviseDetailResponse struct { | ||
| 643 | + ChanceReviseData ChanceReviseLog `json:"chanceReviseData"` | ||
| 644 | + ChanceId int64 `json:"chanceId"` //机会编号 | ||
| 645 | +} |
| 1 | package protocol | 1 | package protocol |
| 2 | 2 | ||
| 3 | const ( | 3 | const ( |
| 4 | - SourceTypeChance = 1 | ||
| 5 | - SourceTypeComment = 2 | ||
| 6 | - SourceTypeBulletin = 3 | 4 | + SourceTypeChance = 1 //机会 |
| 5 | + SourceTypeComment = 2 //机会评论 | ||
| 6 | + SourceTypeBulletin = 3 //公告 | ||
| 7 | + SourceTypeAchievement = 4 //成果 | ||
| 8 | + SourceTypeAchievementComment = 5 //成果评论 | ||
| 9 | + SourceTypeChanceReviseLog = 6 //机会变更 | ||
| 7 | ) | 10 | ) |
| 8 | 11 | ||
| 9 | /*IComment */ | 12 | /*IComment */ |
| @@ -9,7 +9,7 @@ type GetConfigScoreResponse struct { | @@ -9,7 +9,7 @@ type GetConfigScoreResponse struct { | ||
| 9 | 9 | ||
| 10 | type ScoreConfig struct { | 10 | type ScoreConfig struct { |
| 11 | DiscoveryScore *DiscoveryScore `json:"discoveryScore"` | 11 | DiscoveryScore *DiscoveryScore `json:"discoveryScore"` |
| 12 | - SumScore *SumScore `json:"-"` //sumScore | 12 | + SumScore *SumScore `json:"sumScore"` //sumScore |
| 13 | BasicScore *ScoreRange `json:"basicScore"` | 13 | BasicScore *ScoreRange `json:"basicScore"` |
| 14 | ExtraScore *ScoreRange `json:"extraScore"` | 14 | ExtraScore *ScoreRange `json:"extraScore"` |
| 15 | ValueScore *ScoreRange `json:"valueScore"` | 15 | ValueScore *ScoreRange `json:"valueScore"` |
| 1 | package protocol | 1 | package protocol |
| 2 | 2 | ||
| 3 | -import "time" | 3 | +import ( |
| 4 | + "time" | ||
| 5 | +) | ||
| 4 | 6 | ||
| 5 | const ( | 7 | const ( |
| 6 | DepartmentUser = iota //用户所有部门 | 8 | DepartmentUser = iota //用户所有部门 |
| 7 | DepartmentAll //公司所有部门 | 9 | DepartmentAll //公司所有部门 |
| 10 | + DepartmentRoot //公司一级部门 | ||
| 11 | +) | ||
| 12 | + | ||
| 13 | +const ( | ||
| 14 | + StatisticApproved = 0 //统计已审核 | ||
| 15 | + StatisticApproving = 0 //统计审核中 | ||
| 8 | ) | 16 | ) |
| 9 | 17 | ||
| 10 | /*Departments */ | 18 | /*Departments */ |
| @@ -16,13 +24,109 @@ type DepartmentsResponse struct { | @@ -16,13 +24,109 @@ type DepartmentsResponse struct { | ||
| 16 | Departments []*Department `json:"departments,omitempty"` | 24 | Departments []*Department `json:"departments,omitempty"` |
| 17 | } | 25 | } |
| 18 | 26 | ||
| 27 | +//获取一级部门列表 | ||
| 28 | +func (this DepartmentsResponse) GetCompanyDepartment() *Department { | ||
| 29 | + if len(this.Departments) == 0 { | ||
| 30 | + return &Department{} | ||
| 31 | + } | ||
| 32 | + if this.Departments[0].PId != 0 { | ||
| 33 | + return &Department{} | ||
| 34 | + } | ||
| 35 | + return this.Departments[0] | ||
| 36 | +} | ||
| 37 | + | ||
| 38 | +//获取一级部门列表 | ||
| 39 | +func (this DepartmentsResponse) GetRootDepartments() []*Department { | ||
| 40 | + if len(this.Departments) == 0 { | ||
| 41 | + return []*Department{} | ||
| 42 | + } | ||
| 43 | + if this.Departments[0].PId != 0 { | ||
| 44 | + return []*Department{} | ||
| 45 | + } | ||
| 46 | + return this.Departments[0].Departments | ||
| 47 | +} | ||
| 48 | + | ||
| 49 | +//获得部门底下子部门的编号列表(包含本身) | ||
| 50 | +func (this DepartmentsResponse) GetChildDepartmentIds(d *Department, isContainSelf bool) []int { | ||
| 51 | + idList := make([]int, 0) | ||
| 52 | + if isContainSelf { | ||
| 53 | + idList = append(idList, d.DepartmentId) | ||
| 54 | + } | ||
| 55 | + idList = append(idList, walkDeparment(d)...) | ||
| 56 | + return idList | ||
| 57 | +} | ||
| 58 | + | ||
| 59 | +//遍历部门 | ||
| 60 | +func walkDeparment(d *Department) []int { | ||
| 61 | + idList := make([]int, 0) | ||
| 62 | + for i := range d.Departments { | ||
| 63 | + d := d.Departments[i] | ||
| 64 | + idList = append(idList, d.DepartmentId) | ||
| 65 | + if len(d.Departments) > 0 { | ||
| 66 | + idList = append(idList, walkDeparment(d)...) | ||
| 67 | + } | ||
| 68 | + } | ||
| 69 | + return idList | ||
| 70 | +} | ||
| 71 | + | ||
| 19 | type Department struct { | 72 | type Department struct { |
| 20 | DepartmentId int `orm:"column(department_id)" json:"id"` | 73 | DepartmentId int `orm:"column(department_id)" json:"id"` |
| 21 | Name string `orm:"column(name)" json:"name"` | 74 | Name string `orm:"column(name)" json:"name"` |
| 22 | PId int `orm:"column(parent_id)" json:"-"` | 75 | PId int `orm:"column(parent_id)" json:"-"` |
| 23 | ManagerString string `orm:"column(managers)" json:"-"` | 76 | ManagerString string `orm:"column(managers)" json:"-"` |
| 24 | - Relation string `orm:"column(relation)"` | ||
| 25 | - CreateTime time.Time `orm:"column(create_time)"` | 77 | + Relation string `orm:"column(relation)" json:"-"` |
| 78 | + CreateTime time.Time `orm:"column(create_time)" json:"-"` | ||
| 26 | Managers []int `json:"-"` | 79 | Managers []int `json:"-"` |
| 27 | Departments []*Department `json:"departments,omitempty"` | 80 | Departments []*Department `json:"departments,omitempty"` |
| 28 | } | 81 | } |
| 82 | + | ||
| 83 | +/*DepartmentStatistics 部门统计*/ | ||
| 84 | +type DepartmentStatisticsRequest struct { | ||
| 85 | + //DId int `json:"did"`//部门编号 //查询所有部门 查询特定部门 | ||
| 86 | + Type int `json:"type"` //0:已审核 0:待审核 | ||
| 87 | +} | ||
| 88 | +type DepartmentStatisticsResponse struct { | ||
| 89 | + Total int `json:"approvedTotal"` | ||
| 90 | + List []*DepartmentStatistics `json:"departmentStatistics"` | ||
| 91 | +} | ||
| 92 | + | ||
| 93 | +func (this *DepartmentStatisticsResponse) Len() int { return len(this.List) } | ||
| 94 | +func (this *DepartmentStatisticsResponse) Less(i, j int) bool { | ||
| 95 | + //已审核 按照总数从大到小排序;若相同,按照已通过数量从大到小排序;若还相同,按照成果数量从大到小排序;*/ | ||
| 96 | + if this.List[i].ACTotal < this.List[j].ACTotal { | ||
| 97 | + return true | ||
| 98 | + } | ||
| 99 | + if this.List[i].ACTotal == this.List[j].ACTotal && this.List[i].ChanceApprovedTotal < this.List[j].ChanceApprovedTotal { | ||
| 100 | + return true | ||
| 101 | + } | ||
| 102 | + if this.List[i].ACTotal == this.List[j].ACTotal && this.List[i].ChanceApprovedTotal == this.List[j].ChanceApprovedTotal && this.List[i].AchievementTotal < this.List[j].AchievementTotal { | ||
| 103 | + return true | ||
| 104 | + } | ||
| 105 | + if this.List[i].ACTotal == this.List[j].ACTotal && this.List[i].ChanceApprovedTotal == this.List[j].ChanceApprovedTotal && this.List[i].AchievementTotal == this.List[j].AchievementTotal { | ||
| 106 | + if this.List[i].Dep.Id > this.List[j].Dep.Id { | ||
| 107 | + return true | ||
| 108 | + } | ||
| 109 | + } | ||
| 110 | + return false | ||
| 111 | +} | ||
| 112 | +func (this *DepartmentStatisticsResponse) Swap(i, j int) { | ||
| 113 | + this.List[i], this.List[j] = this.List[j], this.List[i] | ||
| 114 | +} | ||
| 115 | + | ||
| 116 | +//部门统计项 | ||
| 117 | +type DepartmentStatistics struct { | ||
| 118 | + Dep Dep `json:"dep"` //部门 | ||
| 119 | + ChanceApprovedTotal int `json:"chanceApprovedTotal"` //已审核的机会 | ||
| 120 | + ChanceApprovingTotal int `json:"chanceApprovingTotal"` //待审核的机会 | ||
| 121 | + AchievementTotal int `json:"achievementTotal"` //已创建的成果 (显示) | ||
| 122 | + | ||
| 123 | + ACTotal int `json:"-"` //机会成果总数 (显示) | ||
| 124 | +} | ||
| 125 | + | ||
| 126 | +/*DepartmentStatistic 单部门统计*/ | ||
| 127 | +type DepartmentStatisticRequest struct { | ||
| 128 | + DepartmentId int64 `json:"departmentId"` | ||
| 129 | +} | ||
| 130 | +type DepartmentStatisticResponse struct { | ||
| 131 | + DepartmentStatistic DepartmentStatistics `json:"departmentStatistic"` | ||
| 132 | +} |
| @@ -37,6 +37,8 @@ const ( | @@ -37,6 +37,8 @@ const ( | ||
| 37 | MyAuditChanceWait //我审核的机会-待我审批 | 37 | MyAuditChanceWait //我审核的机会-待我审批 |
| 38 | MyAuditChancePass //我审核的机会-已通过 | 38 | MyAuditChancePass //我审核的机会-已通过 |
| 39 | MyAuditChanceReturn //我审核的机会-已退回 | 39 | MyAuditChanceReturn //我审核的机会-已退回 |
| 40 | + MyAchievements //我的成就 | ||
| 41 | + MyGraspAchievement //我把握的成果 | ||
| 40 | ) | 42 | ) |
| 41 | 43 | ||
| 42 | var MapStaticName map[int64]string | 44 | var MapStaticName map[int64]string |
| @@ -66,6 +68,7 @@ var ApproveLog = map[int]string{ | @@ -66,6 +68,7 @@ var ApproveLog = map[int]string{ | ||
| 66 | 7: "修改了公开状态:公司公开", //审批通过后修改公开状态(公司公开) | 68 | 7: "修改了公开状态:公司公开", //审批通过后修改公开状态(公司公开) |
| 67 | 8: "修改了公开状态:%v", //审批通过后修改公开状态(部门公开) | 69 | 8: "修改了公开状态:%v", //审批通过后修改公开状态(部门公开) |
| 68 | 9: "修改了基础评分:“修改后的基础评分%v分,修改后的附加评分%v分,修改后的价值评分%v分“", //审批通过后修改评分 | 70 | 9: "修改了基础评分:“修改后的基础评分%v分,修改后的附加评分%v分,修改后的价值评分%v分“", //审批通过后修改评分 |
| 71 | + 10: "补充了机会信息", //审批通过后补充机会 | ||
| 69 | } | 72 | } |
| 70 | 73 | ||
| 71 | //用户项 | 74 | //用户项 |
| @@ -72,6 +72,7 @@ const ( | @@ -72,6 +72,7 @@ const ( | ||
| 72 | MsgTypeAuditBy = 16 //机会被审核消息-我提交的 | 72 | MsgTypeAuditBy = 16 //机会被审核消息-我提交的 |
| 73 | MsgTypeComment = 32 //评论 | 73 | MsgTypeComment = 32 //评论 |
| 74 | MsgTypeThumbUp = 64 //点赞 | 74 | MsgTypeThumbUp = 64 //点赞 |
| 75 | + MsgTypeChanceRevise = 128 //补充机会 | ||
| 75 | ) | 76 | ) |
| 76 | 77 | ||
| 77 | var ( | 78 | var ( |
| @@ -81,6 +82,7 @@ var ( | @@ -81,6 +82,7 @@ var ( | ||
| 81 | 82 | ||
| 82 | MessageZanChance = "点赞了您发布的机会" | 83 | MessageZanChance = "点赞了您发布的机会" |
| 83 | MessageZanComment = "点赞了您发布的评论" | 84 | MessageZanComment = "点赞了您发布的评论" |
| 85 | + MessageChanceRevise = "补充了您发布的%v机会信息" | ||
| 84 | ) | 86 | ) |
| 85 | 87 | ||
| 86 | /*MessageCenter */ | 88 | /*MessageCenter */ |
| @@ -258,6 +260,16 @@ type MsgChanceThumbUpResponse struct { | @@ -258,6 +260,16 @@ type MsgChanceThumbUpResponse struct { | ||
| 258 | Total int `json:"total"` | 260 | Total int `json:"total"` |
| 259 | } | 261 | } |
| 260 | 262 | ||
| 263 | +/*MsgChanceRevise 消息中心-机会补充*/ | ||
| 264 | +type MsgChanceReviseRequest struct { | ||
| 265 | + LastId int64 `json:"lastId"` | ||
| 266 | + PageSize int `json:"pageSize" valid:"Required"` | ||
| 267 | +} | ||
| 268 | +type MsgChanceReviseResponse struct { | ||
| 269 | + List []MsgCommonListItem `json:"list"` | ||
| 270 | + Total int `json:"total"` | ||
| 271 | +} | ||
| 272 | + | ||
| 261 | //我的审核机会列表 | 273 | //我的审核机会列表 |
| 262 | type MsgChanceApproveItemOrm struct { | 274 | type MsgChanceApproveItemOrm struct { |
| 263 | ChanceUserId int64 `orm:"column(chance_user_id)"` | 275 | ChanceUserId int64 `orm:"column(chance_user_id)"` |
protocol/rank.go
0 → 100644
| 1 | +package protocol | ||
| 2 | + | ||
| 3 | +const ( | ||
| 4 | + RankRangeTypeAllCompanyUser = 1 | ||
| 5 | + RankRangeTypeSpecifyUser = 2 | ||
| 6 | + RankRangeTypeAllCompanyDepartment = 3 | ||
| 7 | + RankRangeTypeAllSpecifyDepartment = 4 | ||
| 8 | +) | ||
| 9 | + | ||
| 10 | +const ( | ||
| 11 | + RankRangeTypeUser = 1 | ||
| 12 | + RankRangeTypeDepartment = 2 | ||
| 13 | +) | ||
| 14 | + | ||
| 15 | +const ( | ||
| 16 | + RankPeriodWaiting = iota | ||
| 17 | + RankPeriodBegin | ||
| 18 | + RankPeriodEnd | ||
| 19 | +) | ||
| 20 | + | ||
| 21 | +/*GetRankList 排行榜*/ | ||
| 22 | +type GetRankListRequest struct { | ||
| 23 | + RankTypeId int `json:"rankTypeId" valid:"Required"` //榜单类型编号(赛季榜、年榜) | ||
| 24 | + RankRangeId int `json:"rankRangeId" valid:"Required"` //排行榜范围编号(员工/部门) | ||
| 25 | + RankPeriodId int `json:"rankPeriodId" valid:"Required"` //排行榜周期范围编号 (开始结束时间) | ||
| 26 | + SortItemKeys []string `json:"sortItemKeys" ` //排行项键值列表 valid:"Required" | ||
| 27 | + PageIndex int `json:"pageIndex" valid:"Required"` //页码(默认0代表第1页) | ||
| 28 | + PageSize int `json:"pageSize" valid:"Required"` //每页数量 | ||
| 29 | +} | ||
| 30 | +type GetRankListResponse struct { | ||
| 31 | + //SortItems []string `json:"sortItems"` //评比项 | ||
| 32 | + Self []RankItem `json:"self"` //自己或所在部门的排名分数 | ||
| 33 | + Lists [][]RankItem `json:"lists"` //排名列表 | ||
| 34 | + Total int `json:"total"` //总数 | ||
| 35 | +} | ||
| 36 | + | ||
| 37 | +type RankItem struct { | ||
| 38 | + Ranking int `json:"ranking" orm:"column(ranking)"` //排名 | ||
| 39 | + Name string `json:"name,omitempty" orm:"column(name)"` //名称 | ||
| 40 | + Score float64 `json:"score" orm:"column(score)"` //分数 | ||
| 41 | +} | ||
| 42 | + | ||
| 43 | +/*GetRankType */ | ||
| 44 | +type GetRankTypeRequest struct { | ||
| 45 | +} | ||
| 46 | +type GetRankTypeResponse struct { | ||
| 47 | + List []NameItem `json:"rankTypes"` | ||
| 48 | +} | ||
| 49 | +type RankType struct { | ||
| 50 | + Id int `json:"id"` | ||
| 51 | + Name string `json:"name"` | ||
| 52 | +} | ||
| 53 | + | ||
| 54 | +/*GetRankRange */ | ||
| 55 | +type GetRankRangeRequest struct { | ||
| 56 | + RankTypeId int `json:"rankTypeId"` // valid:"Required" | ||
| 57 | +} | ||
| 58 | +type GetRankRangeResponse struct { | ||
| 59 | + List []RankRange `json:"rankRanges"` | ||
| 60 | +} | ||
| 61 | +type RankRange struct { | ||
| 62 | + Id int `json:"id"` | ||
| 63 | + Type int `json:"type"` //1员工 2:部门 | ||
| 64 | + Name string `json:"name"` | ||
| 65 | +} | ||
| 66 | + | ||
| 67 | +/*GetRankPeriods 获取榜单竞争范围列表*/ | ||
| 68 | +type GetRankPeriodsRequest struct { | ||
| 69 | + RankTypeId int `json:"rankTypeId"` | ||
| 70 | +} | ||
| 71 | +type GetRankPeriodsResponse struct { | ||
| 72 | + List []RankPeriod `json:"rankPeriods"` | ||
| 73 | +} | ||
| 74 | + | ||
| 75 | +type RankPeriod struct { | ||
| 76 | + Id int `json:"id"` | ||
| 77 | + SeasonName string `json:"seasonName"` | ||
| 78 | + BeginTime int64 `json:"beginTime"` | ||
| 79 | + EndTime int64 `json:"endTime"` | ||
| 80 | +} | ||
| 81 | + | ||
| 82 | +/*ComputeRankScore */ | ||
| 83 | +type ComputeRankScoreRequest struct { | ||
| 84 | + RankPeriodId int `json:"rankPeriodId"` | ||
| 85 | +} | ||
| 86 | +type ComputeRankScoreResponse struct { | ||
| 87 | +} | ||
| 88 | + | ||
| 89 | +/*GetRankSortItems */ | ||
| 90 | +type GetRankSortItemsRequest struct { | ||
| 91 | + RankTypeId int `json:"rankTypeId"` | ||
| 92 | +} | ||
| 93 | +type GetRankSortItemsResponse struct { | ||
| 94 | + RankSortItems []RankSortItem `json:"rankSortItems"` | ||
| 95 | +} | ||
| 96 | + | ||
| 97 | +type RankSortItem struct { | ||
| 98 | + ItemName string `json:"name" orm:"column(item_name)"` | ||
| 99 | + ItemKey string `json:"key" orm:"column(item_key)"` | ||
| 100 | +} |
| @@ -7,6 +7,38 @@ import ( | @@ -7,6 +7,38 @@ import ( | ||
| 7 | 7 | ||
| 8 | func init() { | 8 | func init() { |
| 9 | 9 | ||
| 10 | + beego.GlobalControllerRouter["opp/controllers/v1:AchievementController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:AchievementController"], | ||
| 11 | + beego.ControllerComments{ | ||
| 12 | + Method: "AchievementDetail", | ||
| 13 | + Router: `/achievementDetail`, | ||
| 14 | + AllowHTTPMethods: []string{"post"}, | ||
| 15 | + MethodParams: param.Make(), | ||
| 16 | + Params: nil}) | ||
| 17 | + | ||
| 18 | + beego.GlobalControllerRouter["opp/controllers/v1:AchievementController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:AchievementController"], | ||
| 19 | + beego.ControllerComments{ | ||
| 20 | + Method: "AchievementPool", | ||
| 21 | + Router: `/achievementPool`, | ||
| 22 | + AllowHTTPMethods: []string{"post"}, | ||
| 23 | + MethodParams: param.Make(), | ||
| 24 | + Params: nil}) | ||
| 25 | + | ||
| 26 | + beego.GlobalControllerRouter["opp/controllers/v1:AchievementController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:AchievementController"], | ||
| 27 | + beego.ControllerComments{ | ||
| 28 | + Method: "MyGrasp", | ||
| 29 | + Router: `/myGrasp`, | ||
| 30 | + AllowHTTPMethods: []string{"post"}, | ||
| 31 | + MethodParams: param.Make(), | ||
| 32 | + Params: nil}) | ||
| 33 | + | ||
| 34 | + beego.GlobalControllerRouter["opp/controllers/v1:AchievementController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:AchievementController"], | ||
| 35 | + beego.ControllerComments{ | ||
| 36 | + Method: "MyGraspStatistic", | ||
| 37 | + Router: `/myGraspStatistic`, | ||
| 38 | + AllowHTTPMethods: []string{"post"}, | ||
| 39 | + MethodParams: param.Make(), | ||
| 40 | + Params: nil}) | ||
| 41 | + | ||
| 10 | beego.GlobalControllerRouter["opp/controllers/v1:AuthController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:AuthController"], | 42 | beego.GlobalControllerRouter["opp/controllers/v1:AuthController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:AuthController"], |
| 11 | beego.ControllerComments{ | 43 | beego.ControllerComments{ |
| 12 | Method: "AccessToken", | 44 | Method: "AccessToken", |
| @@ -89,6 +121,14 @@ func init() { | @@ -89,6 +121,14 @@ func init() { | ||
| 89 | 121 | ||
| 90 | beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"], | 122 | beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"], |
| 91 | beego.ControllerComments{ | 123 | beego.ControllerComments{ |
| 124 | + Method: "ChanceReviseDetail", | ||
| 125 | + Router: `/chanceReviseDetail`, | ||
| 126 | + AllowHTTPMethods: []string{"post"}, | ||
| 127 | + MethodParams: param.Make(), | ||
| 128 | + Params: nil}) | ||
| 129 | + | ||
| 130 | + beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:ChanceController"], | ||
| 131 | + beego.ControllerComments{ | ||
| 92 | Method: "ChanceType", | 132 | Method: "ChanceType", |
| 93 | Router: `/chanceType`, | 133 | Router: `/chanceType`, |
| 94 | AllowHTTPMethods: []string{"post"}, | 134 | AllowHTTPMethods: []string{"post"}, |
| @@ -287,6 +327,22 @@ func init() { | @@ -287,6 +327,22 @@ func init() { | ||
| 287 | MethodParams: param.Make(), | 327 | MethodParams: param.Make(), |
| 288 | Params: nil}) | 328 | Params: nil}) |
| 289 | 329 | ||
| 330 | + beego.GlobalControllerRouter["opp/controllers/v1:DepartmentController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:DepartmentController"], | ||
| 331 | + beego.ControllerComments{ | ||
| 332 | + Method: "DepartmentStatistic", | ||
| 333 | + Router: `/statistic`, | ||
| 334 | + AllowHTTPMethods: []string{"post"}, | ||
| 335 | + MethodParams: param.Make(), | ||
| 336 | + Params: nil}) | ||
| 337 | + | ||
| 338 | + beego.GlobalControllerRouter["opp/controllers/v1:DepartmentController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:DepartmentController"], | ||
| 339 | + beego.ControllerComments{ | ||
| 340 | + Method: "DepartmentStatistics", | ||
| 341 | + Router: `/statistics`, | ||
| 342 | + AllowHTTPMethods: []string{"post"}, | ||
| 343 | + MethodParams: param.Make(), | ||
| 344 | + Params: nil}) | ||
| 345 | + | ||
| 290 | beego.GlobalControllerRouter["opp/controllers/v1:FileController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:FileController"], | 346 | beego.GlobalControllerRouter["opp/controllers/v1:FileController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:FileController"], |
| 291 | beego.ControllerComments{ | 347 | beego.ControllerComments{ |
| 292 | Method: "GetPlayInfo", | 348 | Method: "GetPlayInfo", |
| @@ -361,6 +417,14 @@ func init() { | @@ -361,6 +417,14 @@ func init() { | ||
| 361 | 417 | ||
| 362 | beego.GlobalControllerRouter["opp/controllers/v1:MessageController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:MessageController"], | 418 | beego.GlobalControllerRouter["opp/controllers/v1:MessageController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:MessageController"], |
| 363 | beego.ControllerComments{ | 419 | beego.ControllerComments{ |
| 420 | + Method: "MsgChanceRevise", | ||
| 421 | + Router: `/msgChanceRevise`, | ||
| 422 | + AllowHTTPMethods: []string{"post"}, | ||
| 423 | + MethodParams: param.Make(), | ||
| 424 | + Params: nil}) | ||
| 425 | + | ||
| 426 | + beego.GlobalControllerRouter["opp/controllers/v1:MessageController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:MessageController"], | ||
| 427 | + beego.ControllerComments{ | ||
| 364 | Method: "MsgChanceSubmit", | 428 | Method: "MsgChanceSubmit", |
| 365 | Router: `/msgChanceSubmit`, | 429 | Router: `/msgChanceSubmit`, |
| 366 | AllowHTTPMethods: []string{"post"}, | 430 | AllowHTTPMethods: []string{"post"}, |
| @@ -391,6 +455,54 @@ func init() { | @@ -391,6 +455,54 @@ func init() { | ||
| 391 | MethodParams: param.Make(), | 455 | MethodParams: param.Make(), |
| 392 | Params: nil}) | 456 | Params: nil}) |
| 393 | 457 | ||
| 458 | + beego.GlobalControllerRouter["opp/controllers/v1:RankController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:RankController"], | ||
| 459 | + beego.ControllerComments{ | ||
| 460 | + Method: "ComputeRankScore", | ||
| 461 | + Router: `/computeRankScore`, | ||
| 462 | + AllowHTTPMethods: []string{"post"}, | ||
| 463 | + MethodParams: param.Make(), | ||
| 464 | + Params: nil}) | ||
| 465 | + | ||
| 466 | + beego.GlobalControllerRouter["opp/controllers/v1:RankController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:RankController"], | ||
| 467 | + beego.ControllerComments{ | ||
| 468 | + Method: "GetRankList", | ||
| 469 | + Router: `/getRankList`, | ||
| 470 | + AllowHTTPMethods: []string{"post"}, | ||
| 471 | + MethodParams: param.Make(), | ||
| 472 | + Params: nil}) | ||
| 473 | + | ||
| 474 | + beego.GlobalControllerRouter["opp/controllers/v1:RankController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:RankController"], | ||
| 475 | + beego.ControllerComments{ | ||
| 476 | + Method: "GetRankPeriods", | ||
| 477 | + Router: `/getRankPeriods`, | ||
| 478 | + AllowHTTPMethods: []string{"post"}, | ||
| 479 | + MethodParams: param.Make(), | ||
| 480 | + Params: nil}) | ||
| 481 | + | ||
| 482 | + beego.GlobalControllerRouter["opp/controllers/v1:RankController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:RankController"], | ||
| 483 | + beego.ControllerComments{ | ||
| 484 | + Method: "GetRankRange", | ||
| 485 | + Router: `/getRankRanges`, | ||
| 486 | + AllowHTTPMethods: []string{"post"}, | ||
| 487 | + MethodParams: param.Make(), | ||
| 488 | + Params: nil}) | ||
| 489 | + | ||
| 490 | + beego.GlobalControllerRouter["opp/controllers/v1:RankController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:RankController"], | ||
| 491 | + beego.ControllerComments{ | ||
| 492 | + Method: "GetRankSortItems", | ||
| 493 | + Router: `/getRankSortItems`, | ||
| 494 | + AllowHTTPMethods: []string{"post"}, | ||
| 495 | + MethodParams: param.Make(), | ||
| 496 | + Params: nil}) | ||
| 497 | + | ||
| 498 | + beego.GlobalControllerRouter["opp/controllers/v1:RankController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:RankController"], | ||
| 499 | + beego.ControllerComments{ | ||
| 500 | + Method: "GetRankType", | ||
| 501 | + Router: `/getRankTypes`, | ||
| 502 | + AllowHTTPMethods: []string{"post"}, | ||
| 503 | + MethodParams: param.Make(), | ||
| 504 | + Params: nil}) | ||
| 505 | + | ||
| 394 | beego.GlobalControllerRouter["opp/controllers/v1:UcenterController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:UcenterController"], | 506 | beego.GlobalControllerRouter["opp/controllers/v1:UcenterController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:UcenterController"], |
| 395 | beego.ControllerComments{ | 507 | beego.ControllerComments{ |
| 396 | Method: "UCenterLogin", | 508 | Method: "UCenterLogin", |
| @@ -24,6 +24,8 @@ func init() { | @@ -24,6 +24,8 @@ func init() { | ||
| 24 | beego.NSNamespace("department", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.DepartmentController{})), | 24 | beego.NSNamespace("department", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.DepartmentController{})), |
| 25 | beego.NSNamespace("config", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.ConfigController{})), | 25 | beego.NSNamespace("config", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.ConfigController{})), |
| 26 | beego.NSNamespace("file", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.FileController{})), | 26 | beego.NSNamespace("file", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.FileController{})), |
| 27 | + beego.NSNamespace("achievement", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.AchievementController{})), | ||
| 28 | + beego.NSNamespace("rank", beego.NSBefore(controllers.FilterComm), beego.NSInclude(&v1.RankController{})), | ||
| 27 | ) | 29 | ) |
| 28 | beego.AddNamespace(nsV1) | 30 | beego.AddNamespace(nsV1) |
| 29 | 31 |
| @@ -195,6 +195,21 @@ func GetChanceMarkData(userId, companyId int64, sourceId int64) (flag int, err e | @@ -195,6 +195,21 @@ func GetChanceMarkData(userId, companyId int64, sourceId int64) (flag int, err e | ||
| 195 | return v.MarkFlag, nil | 195 | return v.MarkFlag, nil |
| 196 | } | 196 | } |
| 197 | 197 | ||
| 198 | +//获取机会标记数据 点赞 / 收藏 | ||
| 199 | +func GetMarkData(userId, companyId int64, sourceId int64, sourceType int) (flag int, err error) { | ||
| 200 | + var ( | ||
| 201 | + v *models.ChanceFavorite | ||
| 202 | + ) | ||
| 203 | + if v, err = models.GetChanceFavorite(userId, companyId, sourceId, sourceType); err != nil { | ||
| 204 | + if err == orm.ErrNoRows { | ||
| 205 | + //log.Error(userId, companyId, sourceId, err) | ||
| 206 | + return 0, nil | ||
| 207 | + } | ||
| 208 | + return | ||
| 209 | + } | ||
| 210 | + return v.MarkFlag, nil | ||
| 211 | +} | ||
| 212 | + | ||
| 198 | //构建统计sql语句 | 213 | //构建统计sql语句 |
| 199 | func GetIncrementSql(table string, column string, incre int, id int64) *utils.SqlData { | 214 | func GetIncrementSql(table string, column string, incre int, id int64) *utils.SqlData { |
| 200 | var sql *bytes.Buffer | 215 | var sql *bytes.Buffer |
services/agg/auth.go
0 → 100644
| 1 | +package agg | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "github.com/prometheus/common/log" | ||
| 6 | + "opp/models" | ||
| 7 | +) | ||
| 8 | + | ||
| 9 | +//检查公司权限 | ||
| 10 | +func CheckCompanyPermission(companyId int64) (err error) { | ||
| 11 | + var ( | ||
| 12 | + company *models.Company | ||
| 13 | + ) | ||
| 14 | + if companyId == 0 { | ||
| 15 | + return nil | ||
| 16 | + } | ||
| 17 | + if company, err = models.GetCompanyById(companyId); err != nil { | ||
| 18 | + log.Error("公司不存在:", companyId, err) | ||
| 19 | + return | ||
| 20 | + } | ||
| 21 | + if company.Enable == 1 { | ||
| 22 | + return nil | ||
| 23 | + } | ||
| 24 | + if company.Enable == 2 { | ||
| 25 | + err = fmt.Errorf("公司:%v 无权限,请联系管理员", company.Name) | ||
| 26 | + } | ||
| 27 | + return | ||
| 28 | +} |
| @@ -3,12 +3,14 @@ package agg | @@ -3,12 +3,14 @@ package agg | ||
| 3 | import ( | 3 | import ( |
| 4 | "fmt" | 4 | "fmt" |
| 5 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" | 5 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" |
| 6 | + "opp/internal/utils" | ||
| 6 | "opp/models" | 7 | "opp/models" |
| 7 | "opp/protocol" | 8 | "opp/protocol" |
| 8 | ) | 9 | ) |
| 9 | 10 | ||
| 10 | //机会池 | 11 | //机会池 |
| 11 | -func GetChancePool(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, v interface{}) (total int, err error) { | 12 | +//@isIncludeSubDeps 是否包含子部门编号 |
| 13 | +func GetChancePool(uid, cid int64, chanceTypeId int, departmentId int, isIncludeSubDeps bool, lastId int64, pageSize int, v interface{}) (total int, err error) { | ||
| 12 | var ( | 14 | var ( |
| 13 | check int | 15 | check int |
| 14 | checkMap map[int]int | 16 | checkMap map[int]int |
| @@ -16,6 +18,7 @@ func GetChancePool(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, | @@ -16,6 +18,7 @@ func GetChancePool(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, | ||
| 16 | userDIds []int64 | 18 | userDIds []int64 |
| 17 | user *models.User | 19 | user *models.User |
| 18 | chance *models.Chance | 20 | chance *models.Chance |
| 21 | + dIds []int | ||
| 19 | ) | 22 | ) |
| 20 | if user, err = models.GetUserByCompanyId(cid); err != nil { | 23 | if user, err = models.GetUserByCompanyId(cid); err != nil { |
| 21 | log.Error(err) | 24 | log.Error(err) |
| @@ -43,29 +46,32 @@ func GetChancePool(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, | @@ -43,29 +46,32 @@ func GetChancePool(uid, cid int64, chanceTypeId int, lastId int64, pageSize int, | ||
| 43 | } | 46 | } |
| 44 | lastId = chance.ApproveTime.Unix() | 47 | lastId = chance.ApproveTime.Unix() |
| 45 | } | 48 | } |
| 49 | + if departmentId > 0 { | ||
| 50 | + dIds, _ = GetDepartmentIds(cid, int64(departmentId), isIncludeSubDeps) | ||
| 51 | + } | ||
| 46 | log.Debug(fmt.Sprintf("user:%v check:%v is_amdin:%v", uid, check, user.Id == uid)) | 52 | log.Debug(fmt.Sprintf("user:%v check:%v is_amdin:%v", uid, check, user.Id == uid)) |
| 47 | switch check { | 53 | switch check { |
| 48 | case OpportunityCheckLv1: | 54 | case OpportunityCheckLv1: |
| 49 | - return models.GetChancePoolMyself(uid, cid, chanceTypeId, lastId, pageSize, v) | 55 | + return models.GetChancePoolMyself(uid, cid, chanceTypeId, dIds, lastId, pageSize, v) |
| 50 | case OpportunityCheckLv2: | 56 | case OpportunityCheckLv2: |
| 51 | if err = models.GetUserDepartmentIds(uid, cid, &userDIds); err != nil { | 57 | if err = models.GetUserDepartmentIds(uid, cid, &userDIds); err != nil { |
| 52 | log.Error(err) | 58 | log.Error(err) |
| 53 | return | 59 | return |
| 54 | } | 60 | } |
| 55 | - return models.GetChancePoolPublicCompany(uid, cid, chanceTypeId, lastId, pageSize, v, userDIds) | 61 | + return models.GetChancePoolPublicCompany(uid, cid, chanceTypeId, dIds, lastId, pageSize, v, userDIds) |
| 56 | case OpportunityCheckLv3: | 62 | case OpportunityCheckLv3: |
| 57 | if _, ok := checkMap[OpportunityCheckLv2]; ok { //同时存在对部门公开的机会 | 63 | if _, ok := checkMap[OpportunityCheckLv2]; ok { //同时存在对部门公开的机会 |
| 58 | if err = models.GetUserDepartmentIds(uid, cid, &userDIds); err != nil { | 64 | if err = models.GetUserDepartmentIds(uid, cid, &userDIds); err != nil { |
| 59 | log.Error(err) | 65 | log.Error(err) |
| 60 | return | 66 | return |
| 61 | } | 67 | } |
| 62 | - return models.GetChancePoolDepartment(uid, cid, chanceTypeId, lastId, pageSize, v, specialDIds, userDIds) | 68 | + return models.GetChancePoolDepartment(uid, cid, chanceTypeId, dIds, lastId, pageSize, v, specialDIds, userDIds) |
| 63 | } | 69 | } |
| 64 | - return models.GetChancePoolSpecialDepartment(uid, cid, chanceTypeId, lastId, pageSize, v, specialDIds) | 70 | + return models.GetChancePoolSpecialDepartment(uid, cid, chanceTypeId, dIds, lastId, pageSize, v, specialDIds) |
| 65 | case OpportunityCheckLv4: | 71 | case OpportunityCheckLv4: |
| 66 | - return models.GetChancePoolAll(uid, cid, chanceTypeId, lastId, pageSize, v) | 72 | + return models.GetChancePoolAll(uid, cid, chanceTypeId, dIds, lastId, pageSize, v) |
| 67 | default: | 73 | default: |
| 68 | - return models.GetChancePoolAll(uid, cid, chanceTypeId, lastId, pageSize, v) | 74 | + return models.GetChancePoolAll(uid, cid, chanceTypeId, dIds, lastId, pageSize, v) |
| 69 | } | 75 | } |
| 70 | return | 76 | return |
| 71 | } | 77 | } |
| @@ -101,8 +107,9 @@ func ValidChancePermission(uid, cid int64, items []*protocol.CommonListItem) (er | @@ -101,8 +107,9 @@ func ValidChancePermission(uid, cid int64, items []*protocol.CommonListItem) (er | ||
| 101 | specialDIds = append(specialDIds, 0) | 107 | specialDIds = append(specialDIds, 0) |
| 102 | } | 108 | } |
| 103 | } | 109 | } |
| 104 | - log.Debug(fmt.Sprintf("user:%v check:%v is_admin:%v", uid, check, user.Id == uid)) | 110 | + log.Debug(fmt.Sprintf("user:%v check:%v is_admin:%v ", uid, check, user.Id == uid)) |
| 105 | for i := range items { | 111 | for i := range items { |
| 112 | + //log.Debug("测试:", items[i].ChanceId, items[i].ChanceStatus) | ||
| 106 | if items[i].ChanceStatus != 0 { | 113 | if items[i].ChanceStatus != 0 { |
| 107 | continue | 114 | continue |
| 108 | } | 115 | } |
| @@ -129,9 +136,6 @@ func ValidChancePermission(uid, cid int64, items []*protocol.CommonListItem) (er | @@ -129,9 +136,6 @@ func ValidChancePermission(uid, cid int64, items []*protocol.CommonListItem) (er | ||
| 129 | } | 136 | } |
| 130 | switch check { | 137 | switch check { |
| 131 | case OpportunityCheckLv1: | 138 | case OpportunityCheckLv1: |
| 132 | - //if chanceUserId == uid { | ||
| 133 | - // continue | ||
| 134 | - //} | ||
| 135 | if _, e := models.ExitsChanceByAuditUser(chanceId, uid); e == nil { | 139 | if _, e := models.ExitsChanceByAuditUser(chanceId, uid); e == nil { |
| 136 | continue | 140 | continue |
| 137 | } | 141 | } |
| @@ -159,13 +163,10 @@ func ValidChancePermission(uid, cid int64, items []*protocol.CommonListItem) (er | @@ -159,13 +163,10 @@ func ValidChancePermission(uid, cid int64, items []*protocol.CommonListItem) (er | ||
| 159 | } | 163 | } |
| 160 | items[i].ChanceStatus = protocol.ChanceStatusClose | 164 | items[i].ChanceStatus = protocol.ChanceStatusClose |
| 161 | case OpportunityCheckLv3: | 165 | case OpportunityCheckLv3: |
| 162 | - //if chanceUserId == uid { | ||
| 163 | - // continue | ||
| 164 | - //} | ||
| 165 | - if _, ok := checkMap[OpportunityCheckLv2]; ok { //同时存在对部门公开的机会 | ||
| 166 | if chancePublicStatus == protocol.PublicToCompany { | 166 | if chancePublicStatus == protocol.PublicToCompany { |
| 167 | continue | 167 | continue |
| 168 | } | 168 | } |
| 169 | + if _, ok := checkMap[OpportunityCheckLv2]; ok { //同时存在对部门公开的机会 | ||
| 169 | if chancePublicStatus == protocol.PublicToDepartment { | 170 | if chancePublicStatus == protocol.PublicToDepartment { |
| 170 | if len(userDIds) == 0 { | 171 | if len(userDIds) == 0 { |
| 171 | if e := models.GetUserDepartmentIds(uid, cid, &userDIds); e != nil { | 172 | if e := models.GetUserDepartmentIds(uid, cid, &userDIds); e != nil { |
| @@ -193,3 +194,42 @@ func ValidChancePermission(uid, cid int64, items []*protocol.CommonListItem) (er | @@ -193,3 +194,42 @@ func ValidChancePermission(uid, cid int64, items []*protocol.CommonListItem) (er | ||
| 193 | } | 194 | } |
| 194 | return | 195 | return |
| 195 | } | 196 | } |
| 197 | + | ||
| 198 | +//设置机会详情 | ||
| 199 | +func SetChanceItem(header *protocol.RequestHeader, chance protocol.CommChanceItemOrm) (item protocol.ChanceItem, chanceStatus int) { | ||
| 200 | + var provider *protocol.BaseUserInfo | ||
| 201 | + var err error | ||
| 202 | + if provider, err = GetUserBaseInfo(chance.ChanceUserId, header.CompanyId); err != nil { | ||
| 203 | + chanceStatus = protocol.ChanceStatusDelete | ||
| 204 | + log.Error(err) | ||
| 205 | + return | ||
| 206 | + } | ||
| 207 | + if len(chance.SourceContent) == 0 || chance.ChanceEnableStatus == 0 { //机会删除 | ||
| 208 | + chanceStatus = protocol.ChanceStatusDelete | ||
| 209 | + } | ||
| 210 | + if chance.Status == models.ChanceStatusClose { //机会关闭 | ||
| 211 | + chanceStatus = protocol.ChanceStatusClose | ||
| 212 | + return | ||
| 213 | + } | ||
| 214 | + | ||
| 215 | + item = protocol.ChanceItem{ | ||
| 216 | + Id: chance.ChanceId, | ||
| 217 | + Provider: provider, | ||
| 218 | + CreateTime: chance.CreateTime.Unix() * 1000, | ||
| 219 | + PublicStatus: chance.PublishStatus, | ||
| 220 | + } | ||
| 221 | + utils.JsonUnmarshal(chance.SourceContent, &item.FormList) | ||
| 222 | + item.FormList = ClearEmptyForm(item.FormList) | ||
| 223 | + utils.JsonUnmarshal(chance.Images, &item.Pictures) | ||
| 224 | + utils.JsonUnmarshal(chance.Voices, &item.Speechs) | ||
| 225 | + utils.JsonUnmarshal(chance.Videos, &item.Videos) | ||
| 226 | + return item, chanceStatus | ||
| 227 | +} | ||
| 228 | + | ||
| 229 | +func SetMsgItem(header *protocol.RequestHeader, msg protocol.MsgItemOrm, commItem *protocol.MsgCommonListItem) { | ||
| 230 | + commItem.MsgId = msg.MsgId | ||
| 231 | + commItem.MsgTime = msg.MsgTime.Unix() * 1000 | ||
| 232 | + commItem.IsRead = msg.IsRead == 1 | ||
| 233 | + commItem.SourceId = msg.SourceId | ||
| 234 | + commItem.SourceType = msg.SourceType | ||
| 235 | +} |
| @@ -278,6 +278,12 @@ func logMsgWithHeaer(header *protocol.RequestHeader, msg *models.UserMsg, name s | @@ -278,6 +278,12 @@ func logMsgWithHeaer(header *protocol.RequestHeader, msg *models.UserMsg, name s | ||
| 278 | 278 | ||
| 279 | //保查审核日志 | 279 | //保查审核日志 |
| 280 | func SaveApproveLog(orm orm.Ormer, code int, userId int64, chanceId int64, param ...interface{}) (err error) { | 280 | func SaveApproveLog(orm orm.Ormer, code int, userId int64, chanceId int64, param ...interface{}) (err error) { |
| 281 | + _, err = SaveApproveLogResult(orm, code, userId, chanceId, param...) | ||
| 282 | + return | ||
| 283 | +} | ||
| 284 | + | ||
| 285 | +//保查审核日志 | ||
| 286 | +func SaveApproveLogResult(orm orm.Ormer, code int, userId int64, chanceId int64, param ...interface{}) (id int64, err error) { | ||
| 281 | var ( | 287 | var ( |
| 282 | message string | 288 | message string |
| 283 | ok bool | 289 | ok bool |
| @@ -287,7 +293,7 @@ func SaveApproveLog(orm orm.Ormer, code int, userId int64, chanceId int64, param | @@ -287,7 +293,7 @@ func SaveApproveLog(orm orm.Ormer, code int, userId int64, chanceId int64, param | ||
| 287 | return | 293 | return |
| 288 | } | 294 | } |
| 289 | message = fmt.Sprintf(message, param...) | 295 | message = fmt.Sprintf(message, param...) |
| 290 | - if _, err = orm.Insert(&models.AuditFlowLog{ | 296 | + if id, err = orm.Insert(&models.AuditFlowLog{ |
| 291 | ChanceId: chanceId, | 297 | ChanceId: chanceId, |
| 292 | Content: message, | 298 | Content: message, |
| 293 | ApproveUserId: userId, | 299 | ApproveUserId: userId, |
| @@ -45,3 +45,80 @@ func MyApproveEnableStatic(header *protocol.RequestHeader, reviewStatus ...int8) | @@ -45,3 +45,80 @@ func MyApproveEnableStatic(header *protocol.RequestHeader, reviewStatus ...int8) | ||
| 45 | } | 45 | } |
| 46 | return | 46 | return |
| 47 | } | 47 | } |
| 48 | + | ||
| 49 | +//我把握的统计 | ||
| 50 | +func MyGraspStatic(header *protocol.RequestHeader) (total int, err error) { | ||
| 51 | + var () | ||
| 52 | + if total, err = models.GetAchievementAll(header.UserId, header.CompanyId, 0, 0, []int{}, 0, nil); err != nil { | ||
| 53 | + if err == orm.ErrNoRows { | ||
| 54 | + err = nil | ||
| 55 | + return | ||
| 56 | + } | ||
| 57 | + log.Error(err) | ||
| 58 | + return | ||
| 59 | + } | ||
| 60 | + return | ||
| 61 | +} | ||
| 62 | + | ||
| 63 | +//我把握的统计 | ||
| 64 | +func AchievementDepartmentStatic(header *protocol.RequestHeader, chanceTypeId int, departmentIds []int) (total int, err error) { | ||
| 65 | + //var ( | ||
| 66 | + // departmentIds []int | ||
| 67 | + //) | ||
| 68 | + //if dId>0{ | ||
| 69 | + // departmentIds,_=GetDepartmentIds(header.CompanyId,dId) | ||
| 70 | + //} | ||
| 71 | + if total, err = models.GetAchievementAll(0, header.CompanyId, chanceTypeId, 0, departmentIds, 0, nil); err != nil { | ||
| 72 | + if err == orm.ErrNoRows { | ||
| 73 | + err = nil | ||
| 74 | + return | ||
| 75 | + } | ||
| 76 | + log.Error(err) | ||
| 77 | + return | ||
| 78 | + } | ||
| 79 | + return | ||
| 80 | +} | ||
| 81 | + | ||
| 82 | +//机会待审核统计 | ||
| 83 | +func ChanceApprovingStatistic(header *protocol.RequestHeader, departmentIds []int) (total int, err error) { | ||
| 84 | + //var ( | ||
| 85 | + // departmentIds []int | ||
| 86 | + //) | ||
| 87 | + //if dId>0{ | ||
| 88 | + // departmentIds,_=GetDepartmentIds(header.CompanyId,dId) | ||
| 89 | + //} | ||
| 90 | + //if len(departmentIds)==0{ | ||
| 91 | + // return | ||
| 92 | + //} | ||
| 93 | + if total, err = models.GetChanceStatisticByDepartment(header.CompanyId, departmentIds, protocol.ReviewStatusAuditging); err != nil { | ||
| 94 | + if err == orm.ErrNoRows { | ||
| 95 | + err = nil | ||
| 96 | + return | ||
| 97 | + } | ||
| 98 | + log.Error(err) | ||
| 99 | + return | ||
| 100 | + } | ||
| 101 | + return | ||
| 102 | +} | ||
| 103 | + | ||
| 104 | +//获取部门以及子部门编号 | ||
| 105 | +//@isIncludeSubDeps 是否包含子部门 | ||
| 106 | +func GetDepartmentIds(companyId int64, dId int64, isIncludeSubDeps bool) (departmentIds []int, err error) { | ||
| 107 | + if dId == 0 { | ||
| 108 | + return []int{}, nil | ||
| 109 | + } | ||
| 110 | + if !isIncludeSubDeps { | ||
| 111 | + return []int{int(dId)}, nil | ||
| 112 | + } | ||
| 113 | + if d, e := models.GetDepartmentById(dId); e != nil { | ||
| 114 | + log.Error(err) | ||
| 115 | + err = e | ||
| 116 | + return | ||
| 117 | + } else { | ||
| 118 | + if departmentIds, err = models.GetSubDepartmentIds(companyId, d.Relation); err != nil { | ||
| 119 | + log.Error(err) | ||
| 120 | + return | ||
| 121 | + } | ||
| 122 | + } | ||
| 123 | + return | ||
| 124 | +} |
| @@ -88,8 +88,12 @@ func Login(header *protocol.RequestHeader, request *protocol.LoginRequest) (rsp | @@ -88,8 +88,12 @@ func Login(header *protocol.RequestHeader, request *protocol.LoginRequest) (rsp | ||
| 88 | case 10001: | 88 | case 10001: |
| 89 | err = protocol.NewErrWithMessage(2002, err) //账号不存在 | 89 | err = protocol.NewErrWithMessage(2002, err) //账号不存在 |
| 90 | return | 90 | return |
| 91 | + case 10003: | ||
| 92 | + err = protocol.NewErrWithMessage(4140, err) //账号不存在 | ||
| 93 | + return | ||
| 91 | default: | 94 | default: |
| 92 | - err = fmt.Errorf("error_no:%v msg:%v", message.Errno, message.Errmsg) | 95 | + log.Error("error_no:%v msg:%v", message.Errno, message.Errmsg) |
| 96 | + err = protocol.NewErrWithMessage(4140, err) | ||
| 93 | return | 97 | return |
| 94 | } | 98 | } |
| 95 | 99 | ||
| @@ -257,6 +261,11 @@ func RefreshToken(request *protocol.RefreshTokenRequest) (rsp *protocol.RefreshT | @@ -257,6 +261,11 @@ func RefreshToken(request *protocol.RefreshTokenRequest) (rsp *protocol.RefreshT | ||
| 257 | if err = models.UpdateUserAuthById(userAuth); err != nil { | 261 | if err = models.UpdateUserAuthById(userAuth); err != nil { |
| 258 | return | 262 | return |
| 259 | } | 263 | } |
| 264 | + if err = agg.CheckCompanyPermission(userAuth.CurrentCompanyId); err != nil { | ||
| 265 | + log.Error(err) | ||
| 266 | + err = protocol.NewErrWithMessage(4140, err) | ||
| 267 | + return | ||
| 268 | + } | ||
| 260 | rsp = &protocol.RefreshTokenResponse{ | 269 | rsp = &protocol.RefreshTokenResponse{ |
| 261 | AccessToken: userAuth.AccessToken, | 270 | AccessToken: userAuth.AccessToken, |
| 262 | RefreshToken: userAuth.RefreshToken, | 271 | RefreshToken: userAuth.RefreshToken, |
services/chance/achievement.go
0 → 100644
| 1 | +package chance | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "github.com/astaxie/beego/orm" | ||
| 5 | + "opp/internal/utils" | ||
| 6 | + "opp/models" | ||
| 7 | + "opp/protocol" | ||
| 8 | + "opp/services/agg" | ||
| 9 | + | ||
| 10 | + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" | ||
| 11 | +) | ||
| 12 | + | ||
| 13 | +//成果池 | ||
| 14 | +func AchievementPool(header *protocol.RequestHeader, request *protocol.AchievementPoolRequest) (rsp *protocol.AchievementPoolResponse, err error) { | ||
| 15 | + var ( | ||
| 16 | + ormItems []protocol.CommAchievementItemOrm | ||
| 17 | + total int | ||
| 18 | + departmentIds []int | ||
| 19 | + ) | ||
| 20 | + rsp = &protocol.AchievementPoolResponse{} | ||
| 21 | + rsp.List = make([]*protocol.AchievementCommonListItem, 0) | ||
| 22 | + if request.DepartmentId > 0 && request.IncludeSubDepartment { | ||
| 23 | + if d, e := models.GetDepartmentById(int64(request.DepartmentId)); e != nil { | ||
| 24 | + log.Error(err) | ||
| 25 | + err = e | ||
| 26 | + return | ||
| 27 | + } else { | ||
| 28 | + if departmentIds, err = models.GetSubDepartmentIds(header.CompanyId, d.Relation); err != nil { | ||
| 29 | + log.Error(err) | ||
| 30 | + return | ||
| 31 | + } | ||
| 32 | + } | ||
| 33 | + } else { | ||
| 34 | + if request.DepartmentId > 0 { | ||
| 35 | + departmentIds = []int{request.DepartmentId} | ||
| 36 | + } | ||
| 37 | + } | ||
| 38 | + if total, err = models.GetAchievementAll(request.UserId, header.CompanyId, request.ChanceTypeId, request.LastId, departmentIds, request.PageSize, &ormItems); err != nil { | ||
| 39 | + if err == orm.ErrNoRows { | ||
| 40 | + err = nil | ||
| 41 | + return | ||
| 42 | + } | ||
| 43 | + log.Error(err) | ||
| 44 | + return | ||
| 45 | + } | ||
| 46 | + rsp.Total = total | ||
| 47 | + for i := range ormItems { | ||
| 48 | + item := ormItems[i] | ||
| 49 | + rspItem := &protocol.AchievementCommonListItem{ | ||
| 50 | + Achievement: GetAchievementItem(header, item), | ||
| 51 | + GraspScore: protocol.GraspScore{ | ||
| 52 | + GraspScore: item.UserGraspScore, | ||
| 53 | + GraspScorePercent: utils.DecimalToNumber(item.UserGraspScore), | ||
| 54 | + }, | ||
| 55 | + StatisticData: GetStatisticData(header, item.StaticDataOrm, item.AchievementId), | ||
| 56 | + ChanceTemplate: getTemplate(item.TemplateId), | ||
| 57 | + ChanceType: getChanceType(item.ChanceTypeId), | ||
| 58 | + } | ||
| 59 | + rsp.List = append(rsp.List, rspItem) | ||
| 60 | + } | ||
| 61 | + return | ||
| 62 | +} | ||
| 63 | + | ||
| 64 | +//获取成果项 | ||
| 65 | +func GetAchievementItem(header *protocol.RequestHeader, from protocol.CommAchievementItemOrm) (item protocol.AchievementItem) { | ||
| 66 | + var ( | ||
| 67 | + provider *protocol.BaseUserInfo | ||
| 68 | + err error | ||
| 69 | + ) | ||
| 70 | + if from.UserId > 0 { | ||
| 71 | + if provider, err = agg.GetUserBaseInfo(from.UserId, header.CompanyId); err != nil { | ||
| 72 | + log.Error(err) | ||
| 73 | + return | ||
| 74 | + } else { | ||
| 75 | + item = protocol.AchievementItem{ | ||
| 76 | + Id: from.AchievementId, | ||
| 77 | + Provider: provider, | ||
| 78 | + CreateTime: from.CreateTime.Unix() * 1000, | ||
| 79 | + Content: from.SourceContent, | ||
| 80 | + //GraspScore: from.GraspScore, | ||
| 81 | + //GraspScorePercent: from.GraspScore, | ||
| 82 | + } | ||
| 83 | + jsonUnmarshal(from.Images, &item.Pictures) | ||
| 84 | + } | ||
| 85 | + } | ||
| 86 | + return | ||
| 87 | +} | ||
| 88 | + | ||
| 89 | +//获取统计数据 | ||
| 90 | +func GetStatisticData(header *protocol.RequestHeader, from protocol.StaticDataOrm, sourceId int64) (chanceData protocol.ChanceData) { | ||
| 91 | + chanceData = protocol.ChanceData{ | ||
| 92 | + ThumbsUpTotal: from.ZanTotal, | ||
| 93 | + CommentTotal: from.CommentTotal, | ||
| 94 | + PageViewTotal: from.ViewTotal, | ||
| 95 | + } | ||
| 96 | + chanceData.IsThumbsUp, chanceData.IsCollect, _ = getMarkFlag(header, sourceId, protocol.SourceTypeAchievement) | ||
| 97 | + return | ||
| 98 | +} | ||
| 99 | + | ||
| 100 | +//我把握的 | ||
| 101 | +func MyGrasp(header *protocol.RequestHeader, request *protocol.MyGraspRequest) (rsp *protocol.MyGraspResponse, err error) { | ||
| 102 | + var ( | ||
| 103 | + achievementPool *protocol.AchievementPoolResponse | ||
| 104 | + ) | ||
| 105 | + request.UserId = header.UserId | ||
| 106 | + if achievementPool, err = AchievementPool(header, &request.AchievementPoolRequest); err != nil { | ||
| 107 | + log.Error(err) | ||
| 108 | + return | ||
| 109 | + } | ||
| 110 | + rsp = &protocol.MyGraspResponse{} | ||
| 111 | + rsp.AchievementPoolResponse = *achievementPool | ||
| 112 | + return | ||
| 113 | +} | ||
| 114 | + | ||
| 115 | +//成果详情 | ||
| 116 | +func AchievementDetail(header *protocol.RequestHeader, request *protocol.AchievementDetailRequest) (rsp *protocol.AchievementDetailResponse, err error) { | ||
| 117 | + var ( | ||
| 118 | + items []protocol.CommAchievementItemOrm | ||
| 119 | + participants []*models.AchievementProvider | ||
| 120 | + chances []protocol.SourceChanceItemOrm | ||
| 121 | + ) | ||
| 122 | + if err = models.GetCommAchievementItemOrmId(request.Id, &items); err != nil { | ||
| 123 | + log.Error(err) | ||
| 124 | + return | ||
| 125 | + } | ||
| 126 | + if len(items) == 0 { | ||
| 127 | + err = protocol.NewErrWithMessage(1) | ||
| 128 | + log.Error("items not empty", request.Id) | ||
| 129 | + return | ||
| 130 | + } | ||
| 131 | + item := items[0] | ||
| 132 | + if item.Status != 1 { | ||
| 133 | + //错误 成果删除或关闭 | ||
| 134 | + } | ||
| 135 | + rsp = &protocol.AchievementDetailResponse{} | ||
| 136 | + { | ||
| 137 | + rsp.Achievement = GetAchievementItem(header, item) | ||
| 138 | + rsp.GraspScore = protocol.GraspScore{ | ||
| 139 | + GraspScore: item.UserGraspScore, | ||
| 140 | + GraspScorePercent: utils.DecimalToNumber(item.UserGraspScore), | ||
| 141 | + } | ||
| 142 | + rsp.StatisticData = GetStatisticData(header, item.StaticDataOrm, item.AchievementId) | ||
| 143 | + rsp.ChanceTemplate = getTemplate(item.TemplateId) | ||
| 144 | + rsp.ChanceType = getChanceType(item.ChanceTypeId) | ||
| 145 | + } | ||
| 146 | + | ||
| 147 | + if participants, err = models.GetAchievementProviders(request.Id); err != nil && err != orm.ErrNoRows { | ||
| 148 | + log.Error(err) | ||
| 149 | + return | ||
| 150 | + } | ||
| 151 | + newParticipant := func(user *protocol.BaseUserInfo, score float64, t int) protocol.UserGraspInfo { | ||
| 152 | + return protocol.UserGraspInfo{ | ||
| 153 | + Provider: user, | ||
| 154 | + GraspScore: protocol.GraspScore{ | ||
| 155 | + GraspScore: score, | ||
| 156 | + GraspScorePercent: utils.DecimalToNumber(score), | ||
| 157 | + }, | ||
| 158 | + Type: t, | ||
| 159 | + } | ||
| 160 | + } | ||
| 161 | + addParticipants := func(item protocol.UserGraspInfo) { | ||
| 162 | + rsp.Participants = append(rsp.Participants, item) | ||
| 163 | + } | ||
| 164 | + addParticipants(newParticipant(rsp.Achievement.Provider, item.UserGraspScore, protocol.Grasper)) | ||
| 165 | + for i := range participants { | ||
| 166 | + p := participants[i] | ||
| 167 | + if provider, e := agg.GetUserBaseInfo(p.UserCompanyId, header.CompanyId); e != nil { | ||
| 168 | + log.Error(e) | ||
| 169 | + return | ||
| 170 | + } else { | ||
| 171 | + addParticipants(newParticipant(provider, p.UserGraspScore, protocol.Provider)) | ||
| 172 | + } | ||
| 173 | + } | ||
| 174 | + | ||
| 175 | + //查看数量 | ||
| 176 | + utils.ExecuteSqlByRoll(true, agg.GetIncrementSql((&models.Achievement{}).TableName(), "view_total", 1, request.Id)) | ||
| 177 | + | ||
| 178 | + if err = models.GetAchievementChances(request.Id, &chances); err != nil { | ||
| 179 | + log.Error(err) | ||
| 180 | + return | ||
| 181 | + } | ||
| 182 | + for i := range chances { | ||
| 183 | + chance := chances[i] | ||
| 184 | + commItem := &protocol.CommonListItem{} | ||
| 185 | + commItem.Chance, commItem.ChanceStatus = agg.SetChanceItem(header, chance.CommChanceItemOrm) | ||
| 186 | + //commItem.ChanceTemplate = getTemplate(chance.TemplateId) | ||
| 187 | + //commItem.ChanceType = getChanceType(chance.ChanceTypeId) | ||
| 188 | + //commItem.Score=protocol.GraspScore{ | ||
| 189 | + // GraspScore:chance., | ||
| 190 | + // GraspScorePercent:chance.GraspScore, | ||
| 191 | + //} | ||
| 192 | + commItem.ChanceId = chance.ChanceId | ||
| 193 | + rsp.SourceChance = append(rsp.SourceChance, commItem) | ||
| 194 | + } | ||
| 195 | + agg.ValidChancePermission(header.UserId, header.CompanyId, rsp.SourceChance) | ||
| 196 | + return | ||
| 197 | +} | ||
| 198 | + | ||
| 199 | +//我把握的统计(按一级分类类型) | ||
| 200 | +func MyGraspStatistic(header *protocol.RequestHeader, request *protocol.MyGraspStatisticRequest) (rsp *protocol.MyGraspStatisticResponse, err error) { | ||
| 201 | + type StatisticItemOrm struct { | ||
| 202 | + Id int `json:"id" orm:"column(chance_type_id)"` //类型 | ||
| 203 | + Name string `json:"name" orm:"column(name)"` //总数 | ||
| 204 | + Total int `json:"total" orm:"column(total)"` | ||
| 205 | + } | ||
| 206 | + var ( | ||
| 207 | + items []StatisticItemOrm | ||
| 208 | + ) | ||
| 209 | + if err = models.GetAchievementStatisticByChanceType(header.UserId, &items); err != nil { | ||
| 210 | + log.Error(err) | ||
| 211 | + return | ||
| 212 | + } | ||
| 213 | + rsp = &protocol.MyGraspStatisticResponse{} | ||
| 214 | + rsp.GraspStatistic = items | ||
| 215 | + return | ||
| 216 | +} |
| @@ -12,6 +12,7 @@ import ( | @@ -12,6 +12,7 @@ import ( | ||
| 12 | "opp/models" | 12 | "opp/models" |
| 13 | "opp/protocol" | 13 | "opp/protocol" |
| 14 | "opp/services/agg" | 14 | "opp/services/agg" |
| 15 | + "reflect" | ||
| 15 | "strings" | 16 | "strings" |
| 16 | "time" | 17 | "time" |
| 17 | ) | 18 | ) |
| @@ -576,6 +577,9 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceUpdate | @@ -576,6 +577,9 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceUpdate | ||
| 576 | return | 577 | return |
| 577 | } | 578 | } |
| 578 | auditConfig = &protocol.AuditConfig{NoApprover: template.NoApprover} | 579 | auditConfig = &protocol.AuditConfig{NoApprover: template.NoApprover} |
| 580 | + | ||
| 581 | + CheckChanceDifferent(header, chance, request) | ||
| 582 | + | ||
| 579 | orm := orm.NewOrm() | 583 | orm := orm.NewOrm() |
| 580 | orm.Begin() | 584 | orm.Begin() |
| 581 | //6.更新文件 | 585 | //6.更新文件 |
| @@ -707,6 +711,164 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceUpdate | @@ -707,6 +711,164 @@ func ChanceUpdate(header *protocol.RequestHeader, request *protocol.ChanceUpdate | ||
| 707 | return | 711 | return |
| 708 | } | 712 | } |
| 709 | 713 | ||
| 714 | +//检查机会更新 | ||
| 715 | +func CheckChanceDifferent(header *protocol.RequestHeader, chance *models.Chance, request *protocol.ChanceUpdateRequest) { | ||
| 716 | + var ( | ||
| 717 | + isSaveLog bool = false | ||
| 718 | + chanceReviseLog *models.ChanceReviseLog | ||
| 719 | + message string | ||
| 720 | + ) | ||
| 721 | + defer func() { | ||
| 722 | + if p := recover(); p != nil { | ||
| 723 | + log.Error(p) | ||
| 724 | + } | ||
| 725 | + }() | ||
| 726 | + if header.UserId == chance.UserId { | ||
| 727 | + return | ||
| 728 | + } | ||
| 729 | + if chance.ReviewStatus != protocol.ReviewStatusPass { | ||
| 730 | + return | ||
| 731 | + } | ||
| 732 | + var modifyLog = protocol.ChanceReviseLog{ | ||
| 733 | + RemoveAllPhotoVideo: false, | ||
| 734 | + RemoveAllSpeech: false, | ||
| 735 | + } | ||
| 736 | + checkIsSaveLog := func() { | ||
| 737 | + if !isSaveLog { | ||
| 738 | + isSaveLog = true | ||
| 739 | + } | ||
| 740 | + } | ||
| 741 | + | ||
| 742 | + diffFormList := func(source string, dis []*protocol.Form) { | ||
| 743 | + var ( | ||
| 744 | + src []*protocol.Form | ||
| 745 | + mapForm map[string]*protocol.Form = make(map[string]*protocol.Form) | ||
| 746 | + reviseContents []protocol.ReviseContent | ||
| 747 | + ) | ||
| 748 | + jsonUnmarshal(source, &src) | ||
| 749 | + for i := range src { | ||
| 750 | + mapForm[src[i].Label] = src[i] | ||
| 751 | + } | ||
| 752 | + for i := range dis { | ||
| 753 | + isDiff := false | ||
| 754 | + srcValue := "" | ||
| 755 | + if v, ok := mapForm[dis[i].Label]; ok { | ||
| 756 | + srcValue = v.Value | ||
| 757 | + if dis[i].Value != v.Value { | ||
| 758 | + isDiff = true | ||
| 759 | + } | ||
| 760 | + } else { | ||
| 761 | + isDiff = true | ||
| 762 | + } | ||
| 763 | + if isDiff { | ||
| 764 | + reviseContents = append(reviseContents, protocol.ReviseContent{ | ||
| 765 | + Content: fmt.Sprintf("将“%v”由“%v”改为 “%v”", dis[i].Label, srcValue, dis[i].Value)}) | ||
| 766 | + checkIsSaveLog() | ||
| 767 | + } | ||
| 768 | + } | ||
| 769 | + modifyLog.DiffContents = reviseContents | ||
| 770 | + } | ||
| 771 | + diffChanceData := func() { | ||
| 772 | + var ( | ||
| 773 | + speechs []protocol.Speech | ||
| 774 | + pictures []protocol.Picture | ||
| 775 | + videos []protocol.Video | ||
| 776 | + ) | ||
| 777 | + if chanceData, e := models.GetChanceDataByChanceId(chance.Id); e == nil { | ||
| 778 | + jsonUnmarshal(chanceData.Speechs, &speechs) | ||
| 779 | + jsonUnmarshal(chanceData.Images, &pictures) | ||
| 780 | + jsonUnmarshal(chanceData.Videos, &videos) | ||
| 781 | + if !reflect.DeepEqual(request.Videos, videos) || !reflect.DeepEqual(request.Pictures, pictures) { | ||
| 782 | + checkIsSaveLog() | ||
| 783 | + modifyLog.Videos = request.Videos | ||
| 784 | + modifyLog.Pictures = request.Pictures | ||
| 785 | + } | ||
| 786 | + if !reflect.DeepEqual(request.Speechs, speechs) { | ||
| 787 | + checkIsSaveLog() | ||
| 788 | + modifyLog.Speechs = request.Speechs | ||
| 789 | + } | ||
| 790 | + | ||
| 791 | + if (len(videos) > 0 && len(request.Videos) == 0) && len(pictures) > 0 && len(request.Pictures) == 0 { | ||
| 792 | + modifyLog.RemoveAllPhotoVideo = true | ||
| 793 | + } | ||
| 794 | + if (len(videos) > 0 && len(request.Videos) == 0) && (len(pictures) == len(request.Pictures) && len(pictures) == 0) { | ||
| 795 | + modifyLog.RemoveAllPhotoVideo = true | ||
| 796 | + } | ||
| 797 | + if (len(videos) == len(request.Videos) && len(videos) == 0) && len(pictures) > 0 && len(request.Pictures) == 0 { | ||
| 798 | + modifyLog.RemoveAllPhotoVideo = true | ||
| 799 | + } | ||
| 800 | + if len(speechs) > 0 && len(request.Speechs) == 0 { | ||
| 801 | + modifyLog.RemoveAllSpeech = true | ||
| 802 | + } | ||
| 803 | + } else { | ||
| 804 | + checkIsSaveLog() | ||
| 805 | + modifyLog.Speechs = request.Speechs | ||
| 806 | + modifyLog.Videos = request.Videos | ||
| 807 | + modifyLog.Speechs = request.Speechs | ||
| 808 | + } | ||
| 809 | + } | ||
| 810 | + | ||
| 811 | + diffFormList(chance.SourceContent, request.FormList) | ||
| 812 | + diffChanceData() | ||
| 813 | + checkModifyLog := func() { | ||
| 814 | + if len(modifyLog.Speechs) == 0 { | ||
| 815 | + modifyLog.Speechs = make([]protocol.Speech, 0) | ||
| 816 | + } | ||
| 817 | + if len(modifyLog.Pictures) == 0 { | ||
| 818 | + modifyLog.Pictures = make([]protocol.Picture, 0) | ||
| 819 | + } | ||
| 820 | + if len(modifyLog.Videos) == 0 { | ||
| 821 | + modifyLog.Videos = make([]protocol.Video, 0) | ||
| 822 | + } | ||
| 823 | + if len(modifyLog.DiffContents) == 0 { | ||
| 824 | + modifyLog.DiffContents = make([]protocol.ReviseContent, 0) | ||
| 825 | + } | ||
| 826 | + } | ||
| 827 | + checkModifyLog() | ||
| 828 | + if isSaveLog { //&& changeCount > 0 | ||
| 829 | + orm := orm.NewOrm() | ||
| 830 | + orm.Begin() | ||
| 831 | + var logId int64 | ||
| 832 | + //发送日志 | ||
| 833 | + if id, err := agg.SaveApproveLogResult(orm, 10, header.UserId, chance.Id); err != nil { | ||
| 834 | + log.Error(err) | ||
| 835 | + orm.Rollback() | ||
| 836 | + return | ||
| 837 | + } else { | ||
| 838 | + logId = id | ||
| 839 | + } | ||
| 840 | + //保存修改详情 | ||
| 841 | + chanceReviseLog = &models.ChanceReviseLog{ | ||
| 842 | + Id: idgen.Next(), | ||
| 843 | + ChanceId: chance.Id, | ||
| 844 | + UserCompanyId: header.UserId, | ||
| 845 | + Data: common.AssertJson(modifyLog), | ||
| 846 | + CreateAt: time.Now(), | ||
| 847 | + AuditFlowLogId: logId, | ||
| 848 | + } | ||
| 849 | + if _, e := orm.Insert(chanceReviseLog); e != nil { | ||
| 850 | + log.Error(e) | ||
| 851 | + orm.Rollback() | ||
| 852 | + return | ||
| 853 | + } | ||
| 854 | + if chanceType, err := models.GetChanceTypeById(chance.ChanceTypeId); err != nil { | ||
| 855 | + log.Error(err) | ||
| 856 | + orm.Rollback() | ||
| 857 | + return | ||
| 858 | + } else { | ||
| 859 | + message = fmt.Sprintf(protocol.MessageChanceRevise, chanceType.Name) | ||
| 860 | + } | ||
| 861 | + //发送修改机会消息 | ||
| 862 | + if err := agg.SendMsgWithHeader(header, chance.UserId, "", chanceReviseLog.Id, protocol.SourceTypeChanceReviseLog, message, protocol.MsgTypeChanceRevise, chance.Id); err != nil { | ||
| 863 | + log.Error(err) | ||
| 864 | + orm.Rollback() | ||
| 865 | + return | ||
| 866 | + } | ||
| 867 | + | ||
| 868 | + orm.Commit() | ||
| 869 | + } | ||
| 870 | +} | ||
| 871 | + | ||
| 710 | //修改公开状态 | 872 | //修改公开状态 |
| 711 | func ChanceChangePublish(header *protocol.RequestHeader, request *protocol.ChanceChangePublishRequest) (rsp *protocol.ChanceChangePublishResponse, err error) { | 873 | func ChanceChangePublish(header *protocol.RequestHeader, request *protocol.ChanceChangePublishRequest) (rsp *protocol.ChanceChangePublishResponse, err error) { |
| 712 | var ( | 874 | var ( |
| @@ -1174,13 +1336,13 @@ func resolveActionType(t uint) string { | @@ -1174,13 +1336,13 @@ func resolveActionType(t uint) string { | ||
| 1174 | func getDepartmentors(header *protocol.RequestHeader, relatedDeparmentId int64) (ids []int64, err error) { | 1336 | func getDepartmentors(header *protocol.RequestHeader, relatedDeparmentId int64) (ids []int64, err error) { |
| 1175 | var ( | 1337 | var ( |
| 1176 | departments *models.Department | 1338 | departments *models.Department |
| 1177 | - lastDepartmentId int | 1339 | + lastDepartmentId int64 |
| 1178 | ) | 1340 | ) |
| 1179 | //if err = models.GetUserDepartments(header.UserId, header.CompanyId, &departments); err != nil { | 1341 | //if err = models.GetUserDepartments(header.UserId, header.CompanyId, &departments); err != nil { |
| 1180 | // log.Error(header.UserId,header.CompanyId,err) | 1342 | // log.Error(header.UserId,header.CompanyId,err) |
| 1181 | // return | 1343 | // return |
| 1182 | //} | 1344 | //} |
| 1183 | - if departments, err = models.GetDepartmentById(int(relatedDeparmentId)); err != nil { | 1345 | + if departments, err = models.GetDepartmentById(relatedDeparmentId); err != nil { |
| 1184 | log.Error(relatedDeparmentId, err) | 1346 | log.Error(relatedDeparmentId, err) |
| 1185 | return | 1347 | return |
| 1186 | } | 1348 | } |
| @@ -1208,7 +1370,7 @@ func getDepartmentors(header *protocol.RequestHeader, relatedDeparmentId int64) | @@ -1208,7 +1370,7 @@ func getDepartmentors(header *protocol.RequestHeader, relatedDeparmentId int64) | ||
| 1208 | if departments.ParentId != 0 { | 1370 | if departments.ParentId != 0 { |
| 1209 | //relatedDeparmentId = int64departments.ParentId | 1371 | //relatedDeparmentId = int64departments.ParentId |
| 1210 | lastDepartmentId = departments.ParentId | 1372 | lastDepartmentId = departments.ParentId |
| 1211 | - if departments, err = models.GetDepartmentById(int(departments.ParentId)); err != nil { | 1373 | + if departments, err = models.GetDepartmentById(departments.ParentId); err != nil { |
| 1212 | log.Error(departments.ParentId, err) | 1374 | log.Error(departments.ParentId, err) |
| 1213 | err = nil | 1375 | err = nil |
| 1214 | break | 1376 | break |
| @@ -1247,7 +1409,7 @@ func getRoleUsers(header *protocol.RequestHeader, roleId int) (ids []int64, err | @@ -1247,7 +1409,7 @@ func getRoleUsers(header *protocol.RequestHeader, roleId int) (ids []int64, err | ||
| 1247 | } | 1409 | } |
| 1248 | 1410 | ||
| 1249 | //递归寻找上一级部门长 | 1411 | //递归寻找上一级部门长 |
| 1250 | -func getParentDepartmentors(pid int) (ids []int64) { | 1412 | +func getParentDepartmentors(pid int64) (ids []int64) { |
| 1251 | var ( | 1413 | var ( |
| 1252 | department *models.Department | 1414 | department *models.Department |
| 1253 | err error | 1415 | err error |
| @@ -1281,7 +1443,7 @@ func ChanceStatistics(header *protocol.RequestHeader, request *protocol.ChanceSt | @@ -1281,7 +1443,7 @@ func ChanceStatistics(header *protocol.RequestHeader, request *protocol.ChanceSt | ||
| 1281 | rsp = &protocol.ChanceStatisticsResponse{} | 1443 | rsp = &protocol.ChanceStatisticsResponse{} |
| 1282 | for i := range chanceType { | 1444 | for i := range chanceType { |
| 1283 | item := chanceType[i] | 1445 | item := chanceType[i] |
| 1284 | - if total, err = agg.GetChancePool(header.UserId, header.CompanyId, item.Id, 0, 0, nil); err != nil { | 1446 | + if total, err = agg.GetChancePool(header.UserId, header.CompanyId, item.Id, 0, false, 0, 0, nil); err != nil { |
| 1285 | log.Error(err) | 1447 | log.Error(err) |
| 1286 | return | 1448 | return |
| 1287 | } | 1449 | } |
| @@ -1369,7 +1531,7 @@ func ChancePool(header *protocol.RequestHeader, request *protocol.ChancePoolRequ | @@ -1369,7 +1531,7 @@ func ChancePool(header *protocol.RequestHeader, request *protocol.ChancePoolRequ | ||
| 1369 | provider *protocol.BaseUserInfo | 1531 | provider *protocol.BaseUserInfo |
| 1370 | flag int | 1532 | flag int |
| 1371 | ) | 1533 | ) |
| 1372 | - if total, err = agg.GetChancePool(header.UserId, header.CompanyId, request.ChanceTypeId, request.LastId, request.PageSize, &myChances); err != nil { | 1534 | + if total, err = agg.GetChancePool(header.UserId, header.CompanyId, request.ChanceTypeId, request.DepartmentId, request.IncludeSubDepartment, request.LastId, request.PageSize, &myChances); err != nil { |
| 1373 | if err == orm.ErrNoRows { | 1535 | if err == orm.ErrNoRows { |
| 1374 | err = nil | 1536 | err = nil |
| 1375 | return | 1537 | return |
| @@ -1792,6 +1954,18 @@ func getChanceMarkFlag(header *protocol.RequestHeader, chanceId int64) (isThumbs | @@ -1792,6 +1954,18 @@ func getChanceMarkFlag(header *protocol.RequestHeader, chanceId int64) (isThumbs | ||
| 1792 | return | 1954 | return |
| 1793 | } | 1955 | } |
| 1794 | 1956 | ||
| 1957 | +//获取机会点赞/收藏状态 | ||
| 1958 | +func getMarkFlag(header *protocol.RequestHeader, sourceId int64, sourceType int) (isThumbsUp, isCollect bool, err error) { | ||
| 1959 | + var flag int | ||
| 1960 | + if flag, err = agg.GetMarkData(header.UserId, header.CompanyId, sourceId, sourceType); err != nil { | ||
| 1961 | + log.Error(err) | ||
| 1962 | + return | ||
| 1963 | + } | ||
| 1964 | + isThumbsUp = (flag & protocol.MarkFlagZan) == protocol.MarkFlagZan | ||
| 1965 | + isCollect = (flag & protocol.MarkFlagCollect) == protocol.MarkFlagCollect | ||
| 1966 | + return | ||
| 1967 | +} | ||
| 1968 | + | ||
| 1795 | //获取模板 | 1969 | //获取模板 |
| 1796 | func getTemplate(templateId int) protocol.NameItem { | 1970 | func getTemplate(templateId int) protocol.NameItem { |
| 1797 | if template, e := models.GetAuditTemplateById(int64(templateId)); e == nil { | 1971 | if template, e := models.GetAuditTemplateById(int64(templateId)); e == nil { |
| @@ -2112,3 +2286,25 @@ func Permission(header *protocol.RequestHeader, request *protocol.PermissionRequ | @@ -2112,3 +2286,25 @@ func Permission(header *protocol.RequestHeader, request *protocol.PermissionRequ | ||
| 2112 | } | 2286 | } |
| 2113 | return | 2287 | return |
| 2114 | } | 2288 | } |
| 2289 | + | ||
| 2290 | +//机会补充详情 | ||
| 2291 | +func ChanceReviseDetail(header *protocol.RequestHeader, request *protocol.ChanceReviseDetailRequest) (rsp *protocol.ChanceReviseDetailResponse, err error) { | ||
| 2292 | + var ( | ||
| 2293 | + detail *models.ChanceReviseLog | ||
| 2294 | + provider *protocol.BaseUserInfo | ||
| 2295 | + ) | ||
| 2296 | + if detail, err = models.GetChanceReviseLogById(request.Id); err != nil { | ||
| 2297 | + log.Error(err) | ||
| 2298 | + return | ||
| 2299 | + } | ||
| 2300 | + rsp = &protocol.ChanceReviseDetailResponse{} | ||
| 2301 | + if provider, err = agg.GetUserBaseInfo(detail.UserCompanyId, header.CompanyId); err != nil { | ||
| 2302 | + log.Error(err) | ||
| 2303 | + return | ||
| 2304 | + } | ||
| 2305 | + json.Unmarshal([]byte(detail.Data), &rsp.ChanceReviseData) | ||
| 2306 | + rsp.ChanceReviseData.Provider = provider | ||
| 2307 | + rsp.ChanceReviseData.CreateTime = detail.CreateAt.Unix() * 1000 | ||
| 2308 | + rsp.ChanceId = detail.ChanceId | ||
| 2309 | + return | ||
| 2310 | +} |
| @@ -167,11 +167,11 @@ func Comments(header *protocol.RequestHeader, request *protocol.CommentsRequest) | @@ -167,11 +167,11 @@ func Comments(header *protocol.RequestHeader, request *protocol.CommentsRequest) | ||
| 167 | commentIds = append(commentIds, comment.Id) | 167 | commentIds = append(commentIds, comment.Id) |
| 168 | rsp.Comments = append(rsp.Comments, item) | 168 | rsp.Comments = append(rsp.Comments, item) |
| 169 | } | 169 | } |
| 170 | - if len(commentIds) > 0 { | ||
| 171 | - if !utils.ExecuteSqlByRoll(true, agg.GetIncrementSqlBatch("comment", "view_total", 1, commentIds...)) { | ||
| 172 | - // | ||
| 173 | - } | ||
| 174 | - } | 170 | + //if len(commentIds) > 0 { |
| 171 | + // if !utils.ExecuteSqlByRoll(true, agg.GetIncrementSqlBatch("comment", "view_total", 1, commentIds...)) { | ||
| 172 | + // // | ||
| 173 | + // } | ||
| 174 | + //} | ||
| 175 | return | 175 | return |
| 176 | } | 176 | } |
| 177 | 177 | ||
| @@ -228,7 +228,7 @@ func CommentDetailsSingle(header *protocol.RequestHeader, request *protocol.Comm | @@ -228,7 +228,7 @@ func CommentDetailsSingle(header *protocol.RequestHeader, request *protocol.Comm | ||
| 228 | Id: comment.Id, | 228 | Id: comment.Id, |
| 229 | Provider: baseUserInfo, | 229 | Provider: baseUserInfo, |
| 230 | Content: comment.Content, | 230 | Content: comment.Content, |
| 231 | - CreateTime: comment.CreateAt.Unix(), | 231 | + CreateTime: comment.CreateAt.Unix() * 1000, |
| 232 | ViewTotal: comment.ViewTotal, | 232 | ViewTotal: comment.ViewTotal, |
| 233 | ZanTotal: comment.ZanTotal, | 233 | ZanTotal: comment.ZanTotal, |
| 234 | CommentTotal: comment.CommentTotal, | 234 | CommentTotal: comment.CommentTotal, |
| @@ -237,6 +237,9 @@ func CommentDetailsSingle(header *protocol.RequestHeader, request *protocol.Comm | @@ -237,6 +237,9 @@ func CommentDetailsSingle(header *protocol.RequestHeader, request *protocol.Comm | ||
| 237 | if exists, _ = models.ExitsChanceFavorite(header.UserId, header.CompanyId, comment.Id, protocol.MarkFlagZan); exists { | 237 | if exists, _ = models.ExitsChanceFavorite(header.UserId, header.CompanyId, comment.Id, protocol.MarkFlagZan); exists { |
| 238 | rsp.Comment.IsZan = true | 238 | rsp.Comment.IsZan = true |
| 239 | } | 239 | } |
| 240 | + if !utils.ExecuteSqlByRoll(true, agg.GetIncrementSqlBatch("comment", "view_total", 1, []int64{request.Id}...)) { | ||
| 241 | + // | ||
| 242 | + } | ||
| 240 | return | 243 | return |
| 241 | } | 244 | } |
| 242 | 245 |
services/contrab/contrab.go
0 → 100644
| 1 | +package contrab | ||
| 2 | + | ||
| 3 | +import "github.com/astaxie/beego/toolbox" | ||
| 4 | + | ||
| 5 | +var ( | ||
| 6 | + taskComputeRankScore = "0 10 0 * * *" //每0:5分 计算排行榜分数 | ||
| 7 | +) | ||
| 8 | + | ||
| 9 | +func Run() { | ||
| 10 | + taskRank := toolbox.NewTask("taskComputeRankScore", taskComputeRankScore, ComputeRankScore) | ||
| 11 | + toolbox.AddTask("taskComputeRankScore", taskRank) | ||
| 12 | + | ||
| 13 | + toolbox.StartTask() | ||
| 14 | +} |
services/contrab/rank.go
0 → 100644
| 1 | +package contrab | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "bytes" | ||
| 5 | + "encoding/json" | ||
| 6 | + "fmt" | ||
| 7 | + "github.com/astaxie/beego/orm" | ||
| 8 | + "gitlab.fjmaimaimai.com/mmm-go/gocomm/identity/idgen" | ||
| 9 | + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" | ||
| 10 | + "opp/internal/utils" | ||
| 11 | + "opp/models" | ||
| 12 | + "opp/protocol" | ||
| 13 | + "reflect" | ||
| 14 | + "sync" | ||
| 15 | + "sync/atomic" | ||
| 16 | + "time" | ||
| 17 | +) | ||
| 18 | + | ||
| 19 | +const ( | ||
| 20 | + RankGoroutineNum = 1 | ||
| 21 | +) | ||
| 22 | + | ||
| 23 | +var ComputeRankScoreFlag int32 | ||
| 24 | +var rankList = initRankList() | ||
| 25 | + | ||
| 26 | +func initRankList() []Rank { | ||
| 27 | + var list []Rank | ||
| 28 | + list = append(list, RankDiscovery{}) | ||
| 29 | + list = append(list, RankGrasp{}) | ||
| 30 | + list = append(list, RankComment{}) | ||
| 31 | + return list | ||
| 32 | +} | ||
| 33 | + | ||
| 34 | +type Rank interface { | ||
| 35 | + RankUser(o RankOption) (error, RankResult) | ||
| 36 | + RankDepartment(o RankOption) (error, RankResult) | ||
| 37 | +} | ||
| 38 | + | ||
| 39 | +type RankOption struct { | ||
| 40 | + CompanyId int //公司编号 | ||
| 41 | + RankTypeId int //榜单类型编号 | ||
| 42 | + RankRangeId int //榜单范围编号 | ||
| 43 | + RankPeriodId int //赛季周期编号 | ||
| 44 | + Type int //Relation类型 | ||
| 45 | + RelationId int64 //对象id 用户编号 /部门编号 | ||
| 46 | + BeginTime time.Time | ||
| 47 | + EndTime time.Time | ||
| 48 | + Rank *models.Rank //排行榜 | ||
| 49 | +} | ||
| 50 | +type RankResult struct{} | ||
| 51 | + | ||
| 52 | +//计算排行分 | ||
| 53 | +func ComputeRankScore() (err error) { | ||
| 54 | + var ( | ||
| 55 | + periods []*models.RankPeriod | ||
| 56 | + ) | ||
| 57 | + defer func() { | ||
| 58 | + if p := recover(); p != nil { | ||
| 59 | + log.Error(p) | ||
| 60 | + } | ||
| 61 | + }() | ||
| 62 | + if !atomic.CompareAndSwapInt32(&ComputeRankScoreFlag, 0, 1) { | ||
| 63 | + log.Warn("ComputeRankScore is working", ComputeRankScoreFlag) | ||
| 64 | + return fmt.Errorf("ComputeRankScore is working. try later") | ||
| 65 | + } else { | ||
| 66 | + defer utils.Profiling("【排行榜分数统计】 执行耗时")() | ||
| 67 | + } | ||
| 68 | + defer func() { | ||
| 69 | + atomic.CompareAndSwapInt32(&ComputeRankScoreFlag, 1, 0) | ||
| 70 | + }() | ||
| 71 | + //1.l 查询进行中的赛季 | ||
| 72 | + if periods, err = models.GetRankPeriods(0, 0, []int{protocol.RankPeriodBegin}); err != nil { | ||
| 73 | + return | ||
| 74 | + } | ||
| 75 | + //启用多个协程执行 | ||
| 76 | + var wg sync.WaitGroup | ||
| 77 | + for i := 0; i < RankGoroutineNum; i++ { | ||
| 78 | + index := i | ||
| 79 | + work := func() { | ||
| 80 | + defer func() { | ||
| 81 | + if p := recover(); p != nil { | ||
| 82 | + log.Error(p) | ||
| 83 | + } | ||
| 84 | + }() | ||
| 85 | + if err = computeRankScore(index, wg, RankGoroutineNum, periods); err != nil { | ||
| 86 | + log.Error(err) | ||
| 87 | + } | ||
| 88 | + } | ||
| 89 | + go work() | ||
| 90 | + } | ||
| 91 | + wg.Wait() | ||
| 92 | + | ||
| 93 | + //更新状态 | ||
| 94 | + //结束进行中 已到期的榜单 | ||
| 95 | + updateRankPeriodStatus(protocol.RankPeriodBegin, protocol.RankPeriodEnd) | ||
| 96 | + //开始等待的榜单 | ||
| 97 | + updateRankPeriodStatus(protocol.RankPeriodWaiting, protocol.RankPeriodBegin) | ||
| 98 | + return | ||
| 99 | +} | ||
| 100 | +func updateRankPeriodStatus(fromStatus int, toStatus int) { | ||
| 101 | + var ( | ||
| 102 | + sql = `update rank_period set status=?,update_at=NOW() where status=? and UNIX_TIMESTAMP(end_time)<? ` | ||
| 103 | + ) | ||
| 104 | + if toStatus == protocol.RankPeriodBegin { | ||
| 105 | + sql = `update rank_period set status=?,update_at=NOW() where status=? and ?>UNIX_TIMESTAMP(begin_time) ` | ||
| 106 | + } | ||
| 107 | + orm := orm.NewOrm() | ||
| 108 | + if _, err := orm.Raw(sql, toStatus, fromStatus, time.Now().Unix()).Exec(); err != nil { | ||
| 109 | + log.Error(err) | ||
| 110 | + return | ||
| 111 | + } | ||
| 112 | +} | ||
| 113 | + | ||
| 114 | +func computeRankScore(index int, wg sync.WaitGroup, gNum int, periods []*models.RankPeriod) (err error) { | ||
| 115 | + var ( | ||
| 116 | + rankRanges []*models.RankRange | ||
| 117 | + rankRangeDatas []*models.RankRangeData | ||
| 118 | + ) | ||
| 119 | + wg.Add(1) | ||
| 120 | + defer wg.Done() | ||
| 121 | + | ||
| 122 | + defer func() { | ||
| 123 | + if p := recover(); p != nil { | ||
| 124 | + log.Error(p) | ||
| 125 | + } | ||
| 126 | + }() | ||
| 127 | + //2.查询对应 rank_type_id 的rank_data | ||
| 128 | + for i := range periods { | ||
| 129 | + period := periods[i] | ||
| 130 | + if (period.Id % gNum) != index { | ||
| 131 | + return | ||
| 132 | + } | ||
| 133 | + if rankRanges, err = models.GetRankRanges(period.CompanyId, period.RankTypeId); err == orm.ErrNoRows { | ||
| 134 | + continue | ||
| 135 | + } | ||
| 136 | + //所有部门 | ||
| 137 | + depIdAll, e := models.GetDepartmentIdsByCompanyId(period.CompanyId) | ||
| 138 | + if e != nil { | ||
| 139 | + log.Error(e) | ||
| 140 | + continue | ||
| 141 | + } | ||
| 142 | + //所有用户 | ||
| 143 | + userIdAll, e := models.GetUserCompanyIdAll(period.CompanyId) | ||
| 144 | + if e != nil { | ||
| 145 | + log.Error(e) | ||
| 146 | + continue | ||
| 147 | + } | ||
| 148 | + //按类型 | ||
| 149 | + //3.查询用户列表/部门列表 | ||
| 150 | + logProcessInfo(period) | ||
| 151 | + for j := range rankRanges { | ||
| 152 | + var relationIds []int64 | ||
| 153 | + rankRange := rankRanges[j] | ||
| 154 | + if rankRange.Type == protocol.RankRangeTypeAllCompanyUser { | ||
| 155 | + relationIds = userIdAll | ||
| 156 | + } else if rankRange.Type == protocol.RankRangeTypeAllCompanyDepartment { | ||
| 157 | + relationIds = depIdAll | ||
| 158 | + } else { | ||
| 159 | + if rankRangeDatas, err = models.GetRankRangeDataList(rankRange.Id); err == orm.ErrNoRows { | ||
| 160 | + continue | ||
| 161 | + } | ||
| 162 | + } | ||
| 163 | + for k := range rankRangeDatas { | ||
| 164 | + relationIds = append(relationIds, int64(rankRangeDatas[k].RelationId)) | ||
| 165 | + } | ||
| 166 | + updateRankByRelationIds(relationIds, period, rankRange) | ||
| 167 | + } | ||
| 168 | + } | ||
| 169 | + | ||
| 170 | + //4.调用统计接口列表 | ||
| 171 | + //5.汇聚所有的rankResult | ||
| 172 | + //6.查询当前user_rank是否有这条记录,比较记录里面数据是否有变化 | ||
| 173 | + //7.更新到表/插入 | ||
| 174 | + return nil | ||
| 175 | +} | ||
| 176 | + | ||
| 177 | +func logProcessInfo(period *models.RankPeriod) { | ||
| 178 | + log.Debug(fmt.Sprintf("【排行榜统计】 公司:%v 周期编号:%v 赛季名称:%v (榜单类型:%v) ", period.CompanyId, period.Id, period.SeasonName, period.RankTypeId)) | ||
| 179 | +} | ||
| 180 | + | ||
| 181 | +func logScoreChanceLog(itemName string, old float64, new float64) string { | ||
| 182 | + return fmt.Sprintf(" [%v %v->%v]", itemName, old, new) | ||
| 183 | +} | ||
| 184 | + | ||
| 185 | +//更新排行榜按关联id | ||
| 186 | +func updateRankByRelationIds(relationIds []int64, period *models.RankPeriod, rankRange *models.RankRange) { | ||
| 187 | + var option RankOption | ||
| 188 | + for i := range relationIds { | ||
| 189 | + option = RankOption{ | ||
| 190 | + CompanyId: period.CompanyId, | ||
| 191 | + RankTypeId: period.RankTypeId, | ||
| 192 | + RankRangeId: rankRange.Id, | ||
| 193 | + RankPeriodId: period.Id, | ||
| 194 | + RelationId: relationIds[i], | ||
| 195 | + Type: int(rankRange.Type), | ||
| 196 | + BeginTime: period.BeginTime, | ||
| 197 | + EndTime: period.EndTime, | ||
| 198 | + } | ||
| 199 | + updateRank(option) | ||
| 200 | + } | ||
| 201 | + updateTotalScore(option) | ||
| 202 | +} | ||
| 203 | + | ||
| 204 | +//更新榜单数据 | ||
| 205 | +func updateRank(o RankOption) { | ||
| 206 | + var ( | ||
| 207 | + rank *models.Rank | ||
| 208 | + e error | ||
| 209 | + isNew = false | ||
| 210 | + rankTmp models.Rank | ||
| 211 | + ) | ||
| 212 | + if rank, e = models.GetRank(o.CompanyId, o.RankTypeId, o.RankRangeId, o.RankPeriodId, o.RelationId); e != nil { | ||
| 213 | + isNew = true | ||
| 214 | + rank = &models.Rank{ | ||
| 215 | + Id: idgen.Next(), | ||
| 216 | + CompanyId: o.CompanyId, | ||
| 217 | + RankTypeId: o.RankTypeId, | ||
| 218 | + RankRangeId: o.RankRangeId, | ||
| 219 | + RankPeriodId: o.RankPeriodId, | ||
| 220 | + RelationId: o.RelationId, | ||
| 221 | + UpdateAt: time.Now(), | ||
| 222 | + CreateAt: time.Now(), | ||
| 223 | + EnableStatus: protocol.Valid, | ||
| 224 | + Type: int8(o.Type), | ||
| 225 | + } | ||
| 226 | + } else { | ||
| 227 | + rankTmp = *rank | ||
| 228 | + if rank.EnableStatus == protocol.InValid { | ||
| 229 | + rank.EnableStatus = protocol.Valid | ||
| 230 | + } | ||
| 231 | + } | ||
| 232 | + o.Rank = rank | ||
| 233 | + for i := range rankList { | ||
| 234 | + item := rankList[i] | ||
| 235 | + if o.Type == protocol.RankRangeTypeAllCompanyDepartment || o.Type == protocol.RankRangeTypeAllSpecifyDepartment { | ||
| 236 | + item.RankDepartment(o) | ||
| 237 | + continue | ||
| 238 | + } | ||
| 239 | + item.RankUser(o) | ||
| 240 | + } | ||
| 241 | + if isNew { | ||
| 242 | + if _, e = models.AddRank(rank); e != nil { | ||
| 243 | + log.Error(e) | ||
| 244 | + } | ||
| 245 | + log.Debug(fmt.Sprintf("【排行榜统计】 新增加 周期编号:%v 公司:%v 评分者编号:%v (榜单类型:%v 参与类型:%v) ", rank.RankPeriodId, rank.CompanyId, rank.RelationId, rank.RankTypeId, rank.RankRangeId)) | ||
| 246 | + } else { | ||
| 247 | + //数据有变化的时候才更新到表 | ||
| 248 | + if !reflect.DeepEqual(rankTmp, *rank) { | ||
| 249 | + rank.UpdateAt = time.Now() | ||
| 250 | + if e = models.UpdateRankById(rank); e != nil { | ||
| 251 | + log.Error(e) | ||
| 252 | + } | ||
| 253 | + log.Debug(fmt.Sprintf("【排行榜统计】 更新 周期编号:%v 公司:%v 评分者编号:%v (榜单类型:%v 参与类型:%v) %v", rank.RankPeriodId, rank.CompanyId, rank.RelationId, rank.RankTypeId, rank.RankRangeId, | ||
| 254 | + checkScoreChange(rankTmp, *rank))) | ||
| 255 | + } | ||
| 256 | + } | ||
| 257 | + | ||
| 258 | +} | ||
| 259 | + | ||
| 260 | +func checkScoreChange(old, new models.Rank) string { | ||
| 261 | + changeLog := bytes.NewBuffer(nil) | ||
| 262 | + if old.TotalScore != new.TotalScore { | ||
| 263 | + changeLog.WriteString(logScoreChanceLog("总分", old.TotalScore, new.TotalScore)) | ||
| 264 | + } | ||
| 265 | + if old.DiscoveryScore != new.DiscoveryScore { | ||
| 266 | + changeLog.WriteString(logScoreChanceLog("发现分", old.DiscoveryScore, new.DiscoveryScore)) | ||
| 267 | + } | ||
| 268 | + if old.GraspScore != new.GraspScore { | ||
| 269 | + changeLog.WriteString(logScoreChanceLog("把握分", old.GraspScore, new.GraspScore)) | ||
| 270 | + } | ||
| 271 | + if old.DiscoveryTotal != new.DiscoveryTotal { | ||
| 272 | + changeLog.WriteString(logScoreChanceLog("发现总数", float64(old.DiscoveryTotal), float64(new.DiscoveryTotal))) | ||
| 273 | + } | ||
| 274 | + if old.CommentTotal != new.CommentTotal { | ||
| 275 | + changeLog.WriteString(logScoreChanceLog("评论总数", float64(old.CommentTotal), float64(new.CommentTotal))) | ||
| 276 | + } | ||
| 277 | + if old.EnableStatus != new.EnableStatus { | ||
| 278 | + changeLog.WriteString(logScoreChanceLog("状态", float64(old.EnableStatus), float64(new.EnableStatus))) | ||
| 279 | + } | ||
| 280 | + return changeLog.String() | ||
| 281 | +} | ||
| 282 | + | ||
| 283 | +//更新排行榜总分 //更新总分 系数*发现分 + 系数*把握分 | ||
| 284 | +func updateTotalScore(o RankOption) { | ||
| 285 | + var ( | ||
| 286 | + config *models.SysConfig | ||
| 287 | + err error | ||
| 288 | + scoreConfig protocol.ScoreConfig | ||
| 289 | + sql = `update rank set total_score=discovery_score*%v + grasp_score*%v where | ||
| 290 | +company_id=%v and rank_type_id=%v and rank_period_id=%v` | ||
| 291 | + ) | ||
| 292 | + if config, err = models.GetSysConfigByCompanyId(int(o.CompanyId), models.KeyScore); err != nil { | ||
| 293 | + err = protocol.NewErrWithMessage(5510) | ||
| 294 | + log.Error(err) | ||
| 295 | + return | ||
| 296 | + } | ||
| 297 | + if err = json.Unmarshal([]byte(config.Content), &scoreConfig); err != nil { | ||
| 298 | + //err = protocol.NewErrWithMessage(5510) | ||
| 299 | + log.Error(err) | ||
| 300 | + return | ||
| 301 | + } | ||
| 302 | + if scoreConfig.SumScore == nil { | ||
| 303 | + log.Error(o.CompanyId, config.Content, "未设置总分配置") | ||
| 304 | + return | ||
| 305 | + } | ||
| 306 | + sql = fmt.Sprintf(sql, | ||
| 307 | + scoreConfig.SumScore.DiscoveryFactor, | ||
| 308 | + scoreConfig.SumScore.CatchFactor, o.CompanyId, o.RankTypeId, o.RankPeriodId) | ||
| 309 | + orm := orm.NewOrm() | ||
| 310 | + if _, err := orm.Raw(sql).Exec(); err != nil { | ||
| 311 | + log.Error(err) | ||
| 312 | + return | ||
| 313 | + } | ||
| 314 | +} | ||
| 315 | + | ||
| 316 | +//手动单赛季统计 | ||
| 317 | +func ComputeRankScoreByPeriod(periodId int) (err error) { | ||
| 318 | + //启用多个协程执行 | ||
| 319 | + var ( | ||
| 320 | + wg sync.WaitGroup | ||
| 321 | + period *models.RankPeriod | ||
| 322 | + ) | ||
| 323 | + if period, err = models.GetRankPeriodById(periodId); err != nil { | ||
| 324 | + log.Error(err) | ||
| 325 | + err = protocol.NewCustomMessage(1, "赛季不存在") | ||
| 326 | + return | ||
| 327 | + } | ||
| 328 | + computeRankScore(0, wg, 1, []*models.RankPeriod{period}) | ||
| 329 | + wg.Wait() | ||
| 330 | + return | ||
| 331 | +} | ||
| 332 | + | ||
| 333 | +//发现计算规则 | ||
| 334 | +type RankDiscovery struct{} | ||
| 335 | + | ||
| 336 | +func (rank RankDiscovery) RankUser(o RankOption) (err error, result RankResult) { | ||
| 337 | + var ( | ||
| 338 | + sql = `select sum(discovery_score) score,count(0) total from chance where user_id =? and review_status=3 and status=1 and enable_status=1 | ||
| 339 | + and UNIX_TIMESTAMP(approve_time)>=? and UNIX_TIMESTAMP(approve_time)<?` | ||
| 340 | + score float64 | ||
| 341 | + total int | ||
| 342 | + ) | ||
| 343 | + orm := orm.NewOrm() | ||
| 344 | + if err = orm.Raw(sql, o.RelationId, o.BeginTime.Unix(), o.EndTime.Unix()).QueryRow(&score, &total); err != nil { | ||
| 345 | + log.Error(err) | ||
| 346 | + return | ||
| 347 | + } | ||
| 348 | + o.Rank.DiscoveryScore = score | ||
| 349 | + o.Rank.DiscoveryTotal = total | ||
| 350 | + return | ||
| 351 | +} | ||
| 352 | +func (rank RankDiscovery) RankDepartment(o RankOption) (err error, result RankResult) { | ||
| 353 | + var ( | ||
| 354 | + sql = `select sum(discovery_score) score,count(0) total from chance where department_id =? and review_status=3 and status=1 and enable_status=1 | ||
| 355 | + and UNIX_TIMESTAMP(approve_time)>=? and UNIX_TIMESTAMP(approve_time)<? | ||
| 356 | +` | ||
| 357 | + score float64 | ||
| 358 | + total int | ||
| 359 | + ) | ||
| 360 | + orm := orm.NewOrm() | ||
| 361 | + if err = orm.Raw(sql, o.RelationId, o.BeginTime.Unix(), o.EndTime.Unix()).QueryRow(&score, &total); err != nil { | ||
| 362 | + log.Error(err) | ||
| 363 | + return | ||
| 364 | + } | ||
| 365 | + o.Rank.DiscoveryScore = score | ||
| 366 | + o.Rank.DiscoveryTotal = total | ||
| 367 | + return | ||
| 368 | +} | ||
| 369 | + | ||
| 370 | +//把握分计算规则 | ||
| 371 | +type RankGrasp struct{} | ||
| 372 | + | ||
| 373 | +func (rank RankGrasp) RankUser(o RankOption) (err error, result RankResult) { | ||
| 374 | + var ( | ||
| 375 | + sql = ` | ||
| 376 | +select sum(a.user_grasp_score) score from( | ||
| 377 | +select user_grasp_score from achievement where user_company_id=? and status=1 and UNIX_TIMESTAMP(create_at) >=? and UNIX_TIMESTAMP(create_at)<? | ||
| 378 | +UNION ALL | ||
| 379 | +select b.user_grasp_score from ( | ||
| 380 | +select user_grasp_score,achievement_id from achievement_provider where user_company_id=? and UNIX_TIMESTAMP(create_at) >=? and UNIX_TIMESTAMP(create_at)<? | ||
| 381 | +)b inner join achievement c on b.achievement_id = c.id and status=1 | ||
| 382 | +) a | ||
| 383 | +` | ||
| 384 | + score float64 | ||
| 385 | + ) | ||
| 386 | + orm := orm.NewOrm() | ||
| 387 | + if err = orm.Raw(sql, o.RelationId, o.BeginTime.Unix(), o.EndTime.Unix(), o.RelationId, o.BeginTime.Unix(), o.EndTime.Unix()).QueryRow(&score); err != nil { | ||
| 388 | + log.Error(err) | ||
| 389 | + return | ||
| 390 | + } | ||
| 391 | + o.Rank.GraspScore = score | ||
| 392 | + return | ||
| 393 | +} | ||
| 394 | +func (rank RankGrasp) RankDepartment(o RankOption) (err error, result RankResult) { | ||
| 395 | + var ( | ||
| 396 | + sql = `select sum(a.user_grasp_score) score from( | ||
| 397 | +select user_grasp_score from achievement where department_id=? and status=1 and UNIX_TIMESTAMP(create_at) >=? and UNIX_TIMESTAMP(create_at)<? | ||
| 398 | +UNION ALL | ||
| 399 | +select b.user_grasp_score from ( | ||
| 400 | +select user_grasp_score,achievement_id from achievement_provider where department_id=? and UNIX_TIMESTAMP(create_at) >=? and UNIX_TIMESTAMP(create_at)<? | ||
| 401 | +)b inner join achievement c on b.achievement_id = c.id and status=1 | ||
| 402 | +) a | ||
| 403 | +` | ||
| 404 | + score float64 | ||
| 405 | + ) | ||
| 406 | + orm := orm.NewOrm() | ||
| 407 | + if err = orm.Raw(sql, o.RelationId, o.BeginTime.Unix(), o.EndTime.Unix(), o.RelationId, o.BeginTime.Unix(), o.EndTime.Unix()).QueryRow(&score); err != nil { | ||
| 408 | + log.Error(err) | ||
| 409 | + return | ||
| 410 | + } | ||
| 411 | + o.Rank.GraspScore = score | ||
| 412 | + return | ||
| 413 | +} | ||
| 414 | + | ||
| 415 | +//评论数计算规则 | ||
| 416 | +type RankComment struct{} | ||
| 417 | + | ||
| 418 | +func (rank RankComment) RankUser(o RankOption) (err error, result RankResult) { | ||
| 419 | + var ( | ||
| 420 | + sql = `select count(0) total from comment where user_id=? and UNIX_TIMESTAMP(create_at) >=? and UNIX_TIMESTAMP(create_at)<? | ||
| 421 | +` | ||
| 422 | + total int | ||
| 423 | + ) | ||
| 424 | + orm := orm.NewOrm() | ||
| 425 | + if err = orm.Raw(sql, o.RelationId, o.BeginTime.Unix(), o.EndTime.Unix()).QueryRow(&total); err != nil { | ||
| 426 | + log.Error(err) | ||
| 427 | + return | ||
| 428 | + } | ||
| 429 | + o.Rank.CommentTotal = total | ||
| 430 | + return | ||
| 431 | +} | ||
| 432 | +func (rank RankComment) RankDepartment(o RankOption) (err error, result RankResult) { | ||
| 433 | + var ( | ||
| 434 | + sql = `select count(0) total from comment where user_id in (%v) and UNIX_TIMESTAMP(create_at) >=%v and UNIX_TIMESTAMP(create_at)<%v | ||
| 435 | +` | ||
| 436 | + sqlUserDepartment = `select user_company_id from user_department where department_id=? and enable_status=1` | ||
| 437 | + total int | ||
| 438 | + userIds []int | ||
| 439 | + ) | ||
| 440 | + orm := orm.NewOrm() | ||
| 441 | + if _, err = orm.Raw(sqlUserDepartment, o.RelationId).QueryRows(&userIds); err != nil { | ||
| 442 | + log.Error(err) | ||
| 443 | + return | ||
| 444 | + } | ||
| 445 | + if len(userIds) == 0 { | ||
| 446 | + return | ||
| 447 | + } | ||
| 448 | + sql = fmt.Sprintf(sql, utils.JoinInts(userIds, ","), o.BeginTime.Unix(), o.EndTime.Unix()) | ||
| 449 | + if err = orm.Raw(sql).QueryRow(&total); err != nil { | ||
| 450 | + log.Error(err) | ||
| 451 | + return | ||
| 452 | + } | ||
| 453 | + o.Rank.CommentTotal = total | ||
| 454 | + return | ||
| 455 | +} |
| @@ -2,9 +2,12 @@ package department | @@ -2,9 +2,12 @@ package department | ||
| 2 | 2 | ||
| 3 | import ( | 3 | import ( |
| 4 | "encoding/json" | 4 | "encoding/json" |
| 5 | + "github.com/astaxie/beego/orm" | ||
| 5 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" | 6 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" |
| 6 | "opp/models" | 7 | "opp/models" |
| 7 | "opp/protocol" | 8 | "opp/protocol" |
| 9 | + "opp/services/agg" | ||
| 10 | + "sort" | ||
| 8 | ) | 11 | ) |
| 9 | 12 | ||
| 10 | func Departments(header *protocol.RequestHeader, request *protocol.DepartmentsRequest) (rsp *protocol.DepartmentsResponse, err error) { | 13 | func Departments(header *protocol.RequestHeader, request *protocol.DepartmentsRequest) (rsp *protocol.DepartmentsResponse, err error) { |
| @@ -29,6 +32,17 @@ func Departments(header *protocol.RequestHeader, request *protocol.DepartmentsRe | @@ -29,6 +32,17 @@ func Departments(header *protocol.RequestHeader, request *protocol.DepartmentsRe | ||
| 29 | log.Error(err) | 32 | log.Error(err) |
| 30 | return | 33 | return |
| 31 | } | 34 | } |
| 35 | + case protocol.DepartmentRoot: | ||
| 36 | + if departments, err = models.GetDepartmentByCompanyId(header.CompanyId); err != nil { | ||
| 37 | + log.Error(err) | ||
| 38 | + return | ||
| 39 | + } | ||
| 40 | + for i := range departments { | ||
| 41 | + item := departments[i] | ||
| 42 | + walkDepartment(tmpDepartment, item) | ||
| 43 | + } | ||
| 44 | + rsp.Departments = tmpDepartment.Departments | ||
| 45 | + //rsp.Departments = rsp.GetRootDepartment() | ||
| 32 | default: | 46 | default: |
| 33 | break | 47 | break |
| 34 | } | 48 | } |
| @@ -38,8 +52,9 @@ func Departments(header *protocol.RequestHeader, request *protocol.DepartmentsRe | @@ -38,8 +52,9 @@ func Departments(header *protocol.RequestHeader, request *protocol.DepartmentsRe | ||
| 38 | //遍历部门 | 52 | //遍历部门 |
| 39 | func walkDepartment(to *protocol.Department, dfrom *models.Department) (err error) { | 53 | func walkDepartment(to *protocol.Department, dfrom *models.Department) (err error) { |
| 40 | var newD *protocol.Department = &protocol.Department{ | 54 | var newD *protocol.Department = &protocol.Department{ |
| 41 | - DepartmentId: dfrom.Id, | 55 | + DepartmentId: int(dfrom.Id), |
| 42 | Name: dfrom.Name, | 56 | Name: dfrom.Name, |
| 57 | + CreateTime: dfrom.CreateAt, | ||
| 43 | Departments: []*protocol.Department{}, | 58 | Departments: []*protocol.Department{}, |
| 44 | } | 59 | } |
| 45 | if len(dfrom.Managers) > 0 { | 60 | if len(dfrom.Managers) > 0 { |
| @@ -48,7 +63,7 @@ func walkDepartment(to *protocol.Department, dfrom *models.Department) (err erro | @@ -48,7 +63,7 @@ func walkDepartment(to *protocol.Department, dfrom *models.Department) (err erro | ||
| 48 | return | 63 | return |
| 49 | } | 64 | } |
| 50 | } | 65 | } |
| 51 | - if to.DepartmentId == dfrom.ParentId { | 66 | + if to.DepartmentId == int(dfrom.ParentId) { |
| 52 | to.Departments = append(to.Departments, newD) | 67 | to.Departments = append(to.Departments, newD) |
| 53 | } | 68 | } |
| 54 | for i := range to.Departments { | 69 | for i := range to.Departments { |
| @@ -56,3 +71,101 @@ func walkDepartment(to *protocol.Department, dfrom *models.Department) (err erro | @@ -56,3 +71,101 @@ func walkDepartment(to *protocol.Department, dfrom *models.Department) (err erro | ||
| 56 | } | 71 | } |
| 57 | return nil | 72 | return nil |
| 58 | } | 73 | } |
| 74 | + | ||
| 75 | +//多部门统计 | ||
| 76 | +func Statistics(header *protocol.RequestHeader, request *protocol.DepartmentStatisticsRequest) (rsp *protocol.DepartmentStatisticsResponse, err error) { | ||
| 77 | + var ( | ||
| 78 | + departmentsResponse *protocol.DepartmentsResponse | ||
| 79 | + ) | ||
| 80 | + rsp = &protocol.DepartmentStatisticsResponse{} | ||
| 81 | + if departmentsResponse, err = Departments(header, &protocol.DepartmentsRequest{Type: 1}); err != nil && err != orm.ErrNoRows { | ||
| 82 | + log.Error(err) | ||
| 83 | + return | ||
| 84 | + } | ||
| 85 | + //公司部门统计 | ||
| 86 | + companyDep := departmentsResponse.GetCompanyDepartment() | ||
| 87 | + if companyDep.DepartmentId > 0 { | ||
| 88 | + var companyDepStatistic *protocol.DepartmentStatisticResponse | ||
| 89 | + if companyDepStatistic, err = DepartmentStatistic(header, &protocol.DepartmentStatisticRequest{DepartmentId: int64(companyDep.DepartmentId)}); err != nil { | ||
| 90 | + log.Error(err) | ||
| 91 | + return | ||
| 92 | + } | ||
| 93 | + rsp.List = append(rsp.List, &companyDepStatistic.DepartmentStatistic) | ||
| 94 | + rsp.Total += companyDepStatistic.DepartmentStatistic.ChanceApprovedTotal + companyDepStatistic.DepartmentStatistic.AchievementTotal | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + departments := departmentsResponse.GetRootDepartments() | ||
| 98 | + iterateDepartments := func(call func(d *protocol.Department) *protocol.DepartmentStatistics) { | ||
| 99 | + for i := range departments { | ||
| 100 | + department := departments[i] | ||
| 101 | + item := call(department) | ||
| 102 | + item.Dep = protocol.Dep{ | ||
| 103 | + Id: department.DepartmentId, | ||
| 104 | + Name: department.Name, | ||
| 105 | + Time: department.CreateTime.Unix(), | ||
| 106 | + } | ||
| 107 | + rsp.List = append(rsp.List, item) | ||
| 108 | + rsp.Total += item.ChanceApprovedTotal + item.AchievementTotal | ||
| 109 | + } | ||
| 110 | + } | ||
| 111 | + switch request.Type { | ||
| 112 | + case protocol.StatisticApproved: | ||
| 113 | + callBack := func(d *protocol.Department) *protocol.DepartmentStatistics { | ||
| 114 | + item := &protocol.DepartmentStatistics{} | ||
| 115 | + dIds := departmentsResponse.GetChildDepartmentIds(d, true) | ||
| 116 | + item.AchievementTotal, _ = agg.AchievementDepartmentStatic(header, 0, dIds) | ||
| 117 | + item.ChanceApprovedTotal, _ = agg.GetChancePool(header.UserId, header.CompanyId, 0, d.DepartmentId, true, 0, 0, nil) | ||
| 118 | + item.ACTotal = item.AchievementTotal + item.ChanceApprovedTotal | ||
| 119 | + item.ChanceApprovingTotal, _ = agg.ChanceApprovingStatistic(header, departmentsResponse.GetChildDepartmentIds(d, true)) | ||
| 120 | + return item | ||
| 121 | + } | ||
| 122 | + iterateDepartments(callBack) | ||
| 123 | + break | ||
| 124 | + //case protocol.StatisticApproving: | ||
| 125 | + // iterateDepartments(func(d *protocol.Department) *protocol.DepartmentStatistics { | ||
| 126 | + // rsp := &protocol.DepartmentStatistics{} | ||
| 127 | + // dIds := departmentsResponse.GetChildDepartmentIds(d, true) | ||
| 128 | + // rsp.AchievementTotal, _ = agg.AchievementDepartmentStatic(header, 0, dIds) | ||
| 129 | + // rsp.ChanceApprovedTotal, _ = agg.GetChancePool(header.UserId, header.CompanyId, 0, d.DepartmentId, 0, 0, nil) | ||
| 130 | + // rsp.ACTotal = rsp.AchievementTotal + rsp.ChanceApprovedTotal | ||
| 131 | + // rsp.ChanceApprovingTotal, _ = agg.ChanceApprovingStatistic(header, departmentsResponse.GetChildDepartmentIds(d, true)) | ||
| 132 | + // return rsp | ||
| 133 | + // }) | ||
| 134 | + // break | ||
| 135 | + default: | ||
| 136 | + err = protocol.NewErrWithMessage(2) | ||
| 137 | + return | ||
| 138 | + } | ||
| 139 | + | ||
| 140 | + sort.Stable(rsp) | ||
| 141 | + sort.Stable(sort.Reverse(rsp)) | ||
| 142 | + return | ||
| 143 | +} | ||
| 144 | + | ||
| 145 | +//单部门统计 | ||
| 146 | +func DepartmentStatistic(header *protocol.RequestHeader, request *protocol.DepartmentStatisticRequest) (rsp *protocol.DepartmentStatisticResponse, err error) { | ||
| 147 | + var ( | ||
| 148 | + dIds []int | ||
| 149 | + deparment *models.Department | ||
| 150 | + ) | ||
| 151 | + rsp = &protocol.DepartmentStatisticResponse{} | ||
| 152 | + if deparment, err = models.GetDepartmentById(request.DepartmentId); err != nil { | ||
| 153 | + log.Error(err) | ||
| 154 | + return | ||
| 155 | + } | ||
| 156 | + departmentStatistic := protocol.DepartmentStatistics{} | ||
| 157 | + departmentStatistic.Dep = protocol.Dep{ | ||
| 158 | + Id: int(deparment.Id), | ||
| 159 | + Name: deparment.Name, | ||
| 160 | + } | ||
| 161 | + if dIds, err = agg.GetDepartmentIds(header.CompanyId, request.DepartmentId, false); err != nil { | ||
| 162 | + log.Error(err) | ||
| 163 | + return | ||
| 164 | + } | ||
| 165 | + departmentStatistic.AchievementTotal, _ = agg.AchievementDepartmentStatic(header, 0, dIds) | ||
| 166 | + departmentStatistic.ChanceApprovedTotal, _ = agg.GetChancePool(header.UserId, header.CompanyId, 0, int(request.DepartmentId), false, 0, 0, nil) | ||
| 167 | + departmentStatistic.ACTotal = departmentStatistic.AchievementTotal + departmentStatistic.ChanceApprovedTotal | ||
| 168 | + departmentStatistic.ChanceApprovingTotal, _ = agg.ChanceApprovingStatistic(header, dIds) | ||
| 169 | + rsp.DepartmentStatistic = departmentStatistic | ||
| 170 | + return | ||
| 171 | +} |
services/department/department_test.go
0 → 100644
| 1 | +package department | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "gitlab.fjmaimaimai.com/mmm-go/gocomm/common" | ||
| 5 | + "opp/protocol" | ||
| 6 | + "sort" | ||
| 7 | + "testing" | ||
| 8 | +) | ||
| 9 | + | ||
| 10 | +func TestGetRootDepartment(t *testing.T) { | ||
| 11 | + sub := []*protocol.Department{ | ||
| 12 | + {DepartmentId: 100, Name: "100"}, | ||
| 13 | + {DepartmentId: 200, Name: "200"}, | ||
| 14 | + } | ||
| 15 | + Departments := []*protocol.Department{ | ||
| 16 | + {DepartmentId: 1, Name: "1", Departments: sub}, | ||
| 17 | + {DepartmentId: 2, Name: "2"}, | ||
| 18 | + {DepartmentId: 3, Name: "3", Departments: []*protocol.Department{{DepartmentId: 31, Name: "3-1", Departments: sub}, {DepartmentId: 32, Name: "3-2"}}}, | ||
| 19 | + {DepartmentId: 4, Name: "4", Departments: []*protocol.Department{{DepartmentId: 41, Name: "4-1"}, {DepartmentId: 42, Name: "4-2", Departments: sub}}}, | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | + var deps protocol.DepartmentsResponse = protocol.DepartmentsResponse{ | ||
| 23 | + Departments: []*protocol.Department{ | ||
| 24 | + {DepartmentId: 0, Name: "0", Departments: Departments}, | ||
| 25 | + }, | ||
| 26 | + } | ||
| 27 | + depList := deps.GetRootDepartments() | ||
| 28 | + for i := range depList { | ||
| 29 | + d := depList[i] | ||
| 30 | + t.Log("部门:", d.DepartmentId, deps.GetChildDepartmentIds(d, true)) | ||
| 31 | + } | ||
| 32 | +} | ||
| 33 | + | ||
| 34 | +//排序 | ||
| 35 | +func TestSortDepartmentStastics(t *testing.T) { | ||
| 36 | + s := &protocol.DepartmentStatisticsResponse{ | ||
| 37 | + List: []*protocol.DepartmentStatistics{ | ||
| 38 | + //{ChanceApprovedTotal: 12, AchievementTotal: 8, ACTotal: 20}, | ||
| 39 | + //{ChanceApprovedTotal: 8, AchievementTotal: 12, ACTotal: 20}, | ||
| 40 | + //{ChanceApprovedTotal: 20, AchievementTotal: 20, ACTotal: 40}, | ||
| 41 | + //{ChanceApprovedTotal: 5, AchievementTotal: 10, ACTotal: 15}, | ||
| 42 | + {Dep: protocol.Dep{Id: 3}, ChanceApprovedTotal: 6, AchievementTotal: 10, ACTotal: 16}, | ||
| 43 | + {Dep: protocol.Dep{Id: 2}, ChanceApprovedTotal: 7, AchievementTotal: 9, ACTotal: 16}, | ||
| 44 | + {Dep: protocol.Dep{Id: 1}, ChanceApprovedTotal: 7, AchievementTotal: 10, ACTotal: 17}, | ||
| 45 | + {Dep: protocol.Dep{Id: 0}, ChanceApprovedTotal: 10, AchievementTotal: 10, ACTotal: 20}, | ||
| 46 | + {Dep: protocol.Dep{Id: 4}, ChanceApprovedTotal: 6, AchievementTotal: 10, ACTotal: 16}, | ||
| 47 | + //{ChanceApprovedTotal: 20, AchievementTotal: 30, ACTotal: 50}, | ||
| 48 | + }, | ||
| 49 | + //List: []*protocol.DepartmentStatistics{ | ||
| 50 | + // {ChanceApprovingTotal: 10}, | ||
| 51 | + // {ChanceApprovingTotal: 10}, | ||
| 52 | + // {ChanceApprovingTotal: 30}, | ||
| 53 | + // {ChanceApprovingTotal: 40}, | ||
| 54 | + // {ChanceApprovingTotal: 60}, | ||
| 55 | + // {ChanceApprovingTotal: 50}, | ||
| 56 | + //}, | ||
| 57 | + } | ||
| 58 | + sort.Stable(s) | ||
| 59 | + sort.Stable(sort.Reverse(s)) | ||
| 60 | + t.Log(common.AssertJson(s)) | ||
| 61 | +} |
| @@ -21,6 +21,13 @@ func MessageCenter(header *protocol.RequestHeader, request *protocol.MessageCent | @@ -21,6 +21,13 @@ func MessageCenter(header *protocol.RequestHeader, request *protocol.MessageCent | ||
| 21 | ) | 21 | ) |
| 22 | rsp = &protocol.MessageCenterResponse{} | 22 | rsp = &protocol.MessageCenterResponse{} |
| 23 | rsp.Totals = make([]*protocol.MessageTotal, 0) | 23 | rsp.Totals = make([]*protocol.MessageTotal, 0) |
| 24 | + //注入公司校验 | ||
| 25 | + if err = agg.CheckCompanyPermission(header.CompanyId); err != nil { | ||
| 26 | + log.Error(err) | ||
| 27 | + err = protocol.NewErrWithMessage(4141) | ||
| 28 | + return | ||
| 29 | + } | ||
| 30 | + | ||
| 24 | if request.MsgType&protocol.MsgTypeInteraction > 0 { | 31 | if request.MsgType&protocol.MsgTypeInteraction > 0 { |
| 25 | if request.MsgType&protocol.MsgTypeThumbUp == 0 { | 32 | if request.MsgType&protocol.MsgTypeThumbUp == 0 { |
| 26 | request.MsgType |= protocol.MsgTypeThumbUp | 33 | request.MsgType |= protocol.MsgTypeThumbUp |
| @@ -31,6 +38,9 @@ func MessageCenter(header *protocol.RequestHeader, request *protocol.MessageCent | @@ -31,6 +38,9 @@ func MessageCenter(header *protocol.RequestHeader, request *protocol.MessageCent | ||
| 31 | if request.MsgType&protocol.MsgTypeAuditBy == 0 { | 38 | if request.MsgType&protocol.MsgTypeAuditBy == 0 { |
| 32 | request.MsgType |= protocol.MsgTypeAuditBy | 39 | request.MsgType |= protocol.MsgTypeAuditBy |
| 33 | } | 40 | } |
| 41 | + if request.MsgType&protocol.MsgTypeChanceRevise == 0 { | ||
| 42 | + request.MsgType |= protocol.MsgTypeChanceRevise | ||
| 43 | + } | ||
| 34 | } | 44 | } |
| 35 | err = models.GetUserMsgTotals(header.UserId, header.CompanyId, request.MsgType, &rsp.Totals) | 45 | err = models.GetUserMsgTotals(header.UserId, header.CompanyId, request.MsgType, &rsp.Totals) |
| 36 | if rsp.Totals == nil || len(rsp.Totals) == 0 { | 46 | if rsp.Totals == nil || len(rsp.Totals) == 0 { |
| @@ -51,6 +61,10 @@ func MessageCenter(header *protocol.RequestHeader, request *protocol.MessageCent | @@ -51,6 +61,10 @@ func MessageCenter(header *protocol.RequestHeader, request *protocol.MessageCent | ||
| 51 | interactionCount += item.MsgTotal | 61 | interactionCount += item.MsgTotal |
| 52 | continue | 62 | continue |
| 53 | } | 63 | } |
| 64 | + if item.MsgType == protocol.MsgTypeChanceRevise { | ||
| 65 | + interactionCount += item.MsgTotal | ||
| 66 | + continue | ||
| 67 | + } | ||
| 54 | if item.MsgType == protocol.MsgTypeBulletin { | 68 | if item.MsgType == protocol.MsgTypeBulletin { |
| 55 | var tmpTotal int | 69 | var tmpTotal int |
| 56 | models.GetBulletinUserMsgTotals(header.UserId, header.CompanyId, request.MsgType, &tmpTotal) | 70 | models.GetBulletinUserMsgTotals(header.UserId, header.CompanyId, request.MsgType, &tmpTotal) |
| @@ -586,6 +600,42 @@ func MsgChanceThumbUp(header *protocol.RequestHeader, request *protocol.MsgChanc | @@ -586,6 +600,42 @@ func MsgChanceThumbUp(header *protocol.RequestHeader, request *protocol.MsgChanc | ||
| 586 | return | 600 | return |
| 587 | } | 601 | } |
| 588 | 602 | ||
| 603 | +//消息中心-机会补充 | ||
| 604 | +func MsgChanceRevise(header *protocol.RequestHeader, request *protocol.MsgChanceReviseRequest) (rsp *protocol.MsgChanceReviseResponse, err error) { | ||
| 605 | + var ( | ||
| 606 | + myChances []protocol.ChanceReviseItemOrm | ||
| 607 | + total int | ||
| 608 | + provider *protocol.BaseUserInfo | ||
| 609 | + ) | ||
| 610 | + | ||
| 611 | + if total, err = models.GetChanceReviseMsg(header.UserId, request.LastId, request.PageSize, protocol.MsgTypeChanceRevise, &myChances); err != nil { | ||
| 612 | + if err == orm.ErrNoRows { | ||
| 613 | + err = nil | ||
| 614 | + return | ||
| 615 | + } | ||
| 616 | + log.Error(err) | ||
| 617 | + return | ||
| 618 | + } | ||
| 619 | + rsp = &protocol.MsgChanceReviseResponse{Total: total} | ||
| 620 | + rsp.List = make([]protocol.MsgCommonListItem, 0) | ||
| 621 | + for i := 0; i < len(myChances); i++ { | ||
| 622 | + chance := myChances[i] | ||
| 623 | + commItem := protocol.MsgCommonListItem{} | ||
| 624 | + commItem.Chance, commItem.ChanceStatus = agg.SetChanceItem(header, chance.CommChanceItemOrm) | ||
| 625 | + agg.SetMsgItem(header, chance.MsgItemOrm, &commItem) | ||
| 626 | + if provider, err = agg.GetUserBaseInfo(chance.SenderUserId, header.CompanyId); err != nil { | ||
| 627 | + log.Error(err) | ||
| 628 | + return | ||
| 629 | + } | ||
| 630 | + commItem.Chance.Provider = provider | ||
| 631 | + commItem.ChanceId = chance.ChanceId | ||
| 632 | + commItem.ReviewStatus = chance.ReviewStatus | ||
| 633 | + commItem.Message = chance.Message | ||
| 634 | + rsp.List = append(rsp.List, commItem) | ||
| 635 | + } | ||
| 636 | + return | ||
| 637 | +} | ||
| 638 | + | ||
| 589 | //H5公告详情 | 639 | //H5公告详情 |
| 590 | func H5Announcement(header *protocol.RequestHeader, request *protocol.AnnouncementRequest) (rsp *protocol.AnnouncementResponse, err error) { | 640 | func H5Announcement(header *protocol.RequestHeader, request *protocol.AnnouncementRequest) (rsp *protocol.AnnouncementResponse, err error) { |
| 591 | var ( | 641 | var ( |
services/rank/rank.go
0 → 100644
| 1 | +package rank | ||
| 2 | + | ||
| 3 | +import ( | ||
| 4 | + "fmt" | ||
| 5 | + "github.com/astaxie/beego/orm" | ||
| 6 | + "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" | ||
| 7 | + "opp/models" | ||
| 8 | + "opp/protocol" | ||
| 9 | + "opp/services/contrab" | ||
| 10 | +) | ||
| 11 | + | ||
| 12 | +//排行榜 | ||
| 13 | +func GetRankList(header *protocol.RequestHeader, request *protocol.GetRankListRequest) (rsp *protocol.GetRankListResponse, err error) { | ||
| 14 | + var ( | ||
| 15 | + ranks []protocol.RankItem | ||
| 16 | + selfRank *protocol.RankItem | ||
| 17 | + rankType *models.RankType | ||
| 18 | + rankRange *models.RankRange | ||
| 19 | + rankPeriod *models.RankPeriod | ||
| 20 | + itemKeys []string | ||
| 21 | + //itemNames []string | ||
| 22 | + departments []*models.Department | ||
| 23 | + departmentId int64 | ||
| 24 | + hasDepartmentInRank bool = true | ||
| 25 | + currentTotal int | ||
| 26 | + ) | ||
| 27 | + rsp = &protocol.GetRankListResponse{ | ||
| 28 | + Self: make([]protocol.RankItem, 0), | ||
| 29 | + Lists: make([][]protocol.RankItem, 0), | ||
| 30 | + } | ||
| 31 | + if rankRange, err = models.GetRankRangeById(request.RankRangeId); err != nil { | ||
| 32 | + log.Error(err) | ||
| 33 | + return | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + { | ||
| 37 | + //测试日志 | ||
| 38 | + if rankType, err = models.GetRankTypeById(request.RankTypeId); err != nil { | ||
| 39 | + log.Error(err) | ||
| 40 | + return | ||
| 41 | + } | ||
| 42 | + if rankPeriod, err = models.GetRankPeriodById((request.RankPeriodId)); err != nil { | ||
| 43 | + log.Error(err) | ||
| 44 | + return | ||
| 45 | + } | ||
| 46 | + log.Debug(fmt.Sprintf("用户:%v 获取排行榜 :%v %v %v", header.UserId, rankType.Name, rankRange.Name, rankPeriod.SeasonName)) | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + itemKeys = request.SortItemKeys | ||
| 50 | + if len(itemKeys) == 0 { | ||
| 51 | + if itemKeys, _, err = models.GetRankItemKeys(header.CompanyId, request.RankTypeId); err != nil && err != orm.ErrNoRows { | ||
| 52 | + log.Error(err) | ||
| 53 | + return | ||
| 54 | + } | ||
| 55 | + } | ||
| 56 | + if len(itemKeys) == 0 { | ||
| 57 | + return | ||
| 58 | + } | ||
| 59 | + //rsp.SortItems = itemNames | ||
| 60 | + if rankRange.Type == protocol.RankRangeTypeAllCompanyDepartment || rankRange.Type == protocol.RankRangeTypeAllSpecifyDepartment { | ||
| 61 | + if departments, err = models.GetDepartmentByUser(header.UserId); err != nil { | ||
| 62 | + log.Error(err) | ||
| 63 | + return | ||
| 64 | + } | ||
| 65 | + if len(departments) == 0 { | ||
| 66 | + hasDepartmentInRank = false | ||
| 67 | + } | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + for i := range itemKeys { | ||
| 71 | + key := itemKeys[i] | ||
| 72 | + if rankRange.Type == protocol.RankRangeTypeAllCompanyDepartment || rankRange.Type == protocol.RankRangeTypeAllSpecifyDepartment { | ||
| 73 | + if rsp.Total, err = models.GetRanksByDepartment(header.CompanyId, request.RankTypeId, request.RankRangeId, request.RankPeriodId, key, request.PageIndex, request.PageSize, &ranks); err != nil && err != orm.ErrNoRows { | ||
| 74 | + log.Error(err) | ||
| 75 | + return | ||
| 76 | + } | ||
| 77 | + if hasDepartmentInRank { | ||
| 78 | + if departmentId > 0 { | ||
| 79 | + if err = models.GetRanksByDepartmentSelf(header.CompanyId, request.RankTypeId, request.RankRangeId, request.RankPeriodId, key, departmentId, &selfRank); err != nil { | ||
| 80 | + log.Error(err) | ||
| 81 | + return | ||
| 82 | + } | ||
| 83 | + } else if hasDepartmentInRank { | ||
| 84 | + for i := range departments { | ||
| 85 | + d := departments[i] | ||
| 86 | + if err = models.GetRanksByDepartmentSelf(header.CompanyId, request.RankTypeId, request.RankRangeId, request.RankPeriodId, key, int64(d.Id), &selfRank); err != nil { | ||
| 87 | + log.Error(err) | ||
| 88 | + return | ||
| 89 | + } | ||
| 90 | + if selfRank != nil { | ||
| 91 | + departmentId = int64(d.Id) | ||
| 92 | + break | ||
| 93 | + } | ||
| 94 | + } | ||
| 95 | + if departmentId == 0 { | ||
| 96 | + hasDepartmentInRank = false | ||
| 97 | + } | ||
| 98 | + } | ||
| 99 | + } | ||
| 100 | + } else if rankRange.Type == protocol.RankRangeTypeAllCompanyUser || rankRange.Type == protocol.RankRangeTypeSpecifyUser { | ||
| 101 | + if rsp.Total, err = models.GetRanksByUser(header.CompanyId, request.RankTypeId, request.RankRangeId, request.RankPeriodId, key, request.PageIndex, request.PageSize, &ranks); err != nil && err != orm.ErrNoRows { | ||
| 102 | + log.Error(err) | ||
| 103 | + return | ||
| 104 | + } | ||
| 105 | + if err = models.GetRanksByUserSelf(header.CompanyId, request.RankTypeId, request.RankRangeId, request.RankPeriodId, key, header.UserId, &selfRank); err != nil { | ||
| 106 | + log.Error(err) | ||
| 107 | + return | ||
| 108 | + } | ||
| 109 | + } | ||
| 110 | + if selfRank != nil { | ||
| 111 | + rsp.Self = append(rsp.Self, *selfRank) | ||
| 112 | + } | ||
| 113 | + if len(ranks) > 0 { | ||
| 114 | + currentTotal = len(ranks) | ||
| 115 | + rsp.Lists = append(rsp.Lists, ranks) | ||
| 116 | + } | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + if len(rsp.Lists) > 0 && len(itemKeys) != len(rsp.Lists) { | ||
| 120 | + log.Error("数据项不匹配", itemKeys, len(rsp.Lists)) | ||
| 121 | + err = protocol.NewErrWithMessage(1) | ||
| 122 | + return | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + if len(rsp.Lists) > 0 { | ||
| 126 | + lists := make([][]protocol.RankItem, 0) | ||
| 127 | + for i := 0; i < currentTotal; i++ { | ||
| 128 | + items := make([]protocol.RankItem, 0) | ||
| 129 | + for j := 0; j < len(itemKeys); j++ { | ||
| 130 | + items = append(items, rsp.Lists[j][i]) | ||
| 131 | + } | ||
| 132 | + lists = append(lists, items) | ||
| 133 | + } | ||
| 134 | + rsp.Lists = lists | ||
| 135 | + } | ||
| 136 | + return | ||
| 137 | +} | ||
| 138 | + | ||
| 139 | +//获取榜单类型列表 | ||
| 140 | +func GetRankType(header *protocol.RequestHeader, request *protocol.GetRankTypeRequest) (rsp *protocol.GetRankTypeResponse, err error) { | ||
| 141 | + var ( | ||
| 142 | + lists []*models.RankType | ||
| 143 | + ) | ||
| 144 | + rsp = &protocol.GetRankTypeResponse{ | ||
| 145 | + List: make([]protocol.NameItem, 0), | ||
| 146 | + } | ||
| 147 | + if lists, err = models.GetRankTypes(header.CompanyId); err != nil { | ||
| 148 | + if err == orm.ErrNoRows { | ||
| 149 | + err = nil | ||
| 150 | + return | ||
| 151 | + } | ||
| 152 | + log.Error(err) | ||
| 153 | + return | ||
| 154 | + } | ||
| 155 | + | ||
| 156 | + for i := range lists { | ||
| 157 | + rsp.List = append(rsp.List, protocol.NameItem{Id: lists[i].Id, Name: lists[i].Name}) | ||
| 158 | + } | ||
| 159 | + return | ||
| 160 | +} | ||
| 161 | + | ||
| 162 | +//获取榜单范围列表 | ||
| 163 | +func GetRankRange(header *protocol.RequestHeader, request *protocol.GetRankRangeRequest) (rsp *protocol.GetRankRangeResponse, err error) { | ||
| 164 | + var ( | ||
| 165 | + lists []*models.RankRange | ||
| 166 | + ) | ||
| 167 | + rsp = &protocol.GetRankRangeResponse{ | ||
| 168 | + List: make([]protocol.RankRange, 0), | ||
| 169 | + } | ||
| 170 | + if request.RankTypeId == 0 { | ||
| 171 | + return | ||
| 172 | + } | ||
| 173 | + if lists, err = models.GetRankRanges(int(header.CompanyId), request.RankTypeId); err != nil { | ||
| 174 | + if err == orm.ErrNoRows { | ||
| 175 | + err = nil | ||
| 176 | + return | ||
| 177 | + } | ||
| 178 | + log.Error(err) | ||
| 179 | + return | ||
| 180 | + } | ||
| 181 | + for i := range lists { | ||
| 182 | + if lists[i].Status != 0 { //状态为隐藏的过滤 | ||
| 183 | + continue | ||
| 184 | + } | ||
| 185 | + item := protocol.RankRange{ | ||
| 186 | + Id: lists[i].Id, | ||
| 187 | + Name: lists[i].Name, | ||
| 188 | + } | ||
| 189 | + if lists[i].Type == protocol.RankRangeTypeAllCompanyDepartment || lists[i].Type == protocol.RankRangeTypeAllSpecifyDepartment { | ||
| 190 | + item.Type = protocol.RankRangeTypeDepartment | ||
| 191 | + } else { | ||
| 192 | + item.Type = protocol.RankRangeTypeUser | ||
| 193 | + } | ||
| 194 | + rsp.List = append(rsp.List, item) | ||
| 195 | + } | ||
| 196 | + return | ||
| 197 | +} | ||
| 198 | + | ||
| 199 | +//获取排行榜周期列表 | ||
| 200 | +func GetRankPeriods(header *protocol.RequestHeader, request *protocol.GetRankPeriodsRequest) (rsp *protocol.GetRankPeriodsResponse, err error) { | ||
| 201 | + var ( | ||
| 202 | + lists []*models.RankPeriod | ||
| 203 | + ) | ||
| 204 | + rsp = &protocol.GetRankPeriodsResponse{List: make([]protocol.RankPeriod, 0)} | ||
| 205 | + if request.RankTypeId == 0 { | ||
| 206 | + return | ||
| 207 | + } | ||
| 208 | + if lists, err = models.GetRankPeriods(int(header.CompanyId), request.RankTypeId, []int{protocol.RankPeriodBegin, protocol.RankPeriodEnd}); err != nil { | ||
| 209 | + if err == orm.ErrNoRows { | ||
| 210 | + err = nil | ||
| 211 | + return | ||
| 212 | + } | ||
| 213 | + log.Error(err) | ||
| 214 | + return | ||
| 215 | + } | ||
| 216 | + for i := range lists { | ||
| 217 | + item := lists[i] | ||
| 218 | + rsp.List = append(rsp.List, protocol.RankPeriod{ | ||
| 219 | + Id: item.Id, | ||
| 220 | + SeasonName: item.SeasonName, | ||
| 221 | + BeginTime: item.BeginTime.Unix() * 1000, | ||
| 222 | + EndTime: item.EndTime.Unix() * 1000, | ||
| 223 | + }) | ||
| 224 | + } | ||
| 225 | + return | ||
| 226 | +} | ||
| 227 | + | ||
| 228 | +//获取排行榜评比项 | ||
| 229 | +func GetRankSortItems(header *protocol.RequestHeader, request *protocol.GetRankSortItemsRequest) (rsp *protocol.GetRankSortItemsResponse, err error) { | ||
| 230 | + var ( | ||
| 231 | + sortItems []protocol.RankSortItem | ||
| 232 | + ) | ||
| 233 | + rsp = &protocol.GetRankSortItemsResponse{ | ||
| 234 | + RankSortItems: make([]protocol.RankSortItem, 0), | ||
| 235 | + } | ||
| 236 | + if request.RankTypeId == 0 { | ||
| 237 | + return | ||
| 238 | + } | ||
| 239 | + if err = models.GetRankItems(header.CompanyId, request.RankTypeId, &sortItems); err != nil { | ||
| 240 | + if err == orm.ErrNoRows { | ||
| 241 | + err = nil | ||
| 242 | + return | ||
| 243 | + } | ||
| 244 | + log.Error(err) | ||
| 245 | + return | ||
| 246 | + } | ||
| 247 | + if len(sortItems) > 0 { | ||
| 248 | + rsp.RankSortItems = sortItems | ||
| 249 | + } | ||
| 250 | + if len(sortItems) > 4 { | ||
| 251 | + rsp.RankSortItems = sortItems[0:4] | ||
| 252 | + return | ||
| 253 | + } | ||
| 254 | + return | ||
| 255 | +} | ||
| 256 | + | ||
| 257 | +//手动计算排行榜 | ||
| 258 | +func ComputeRankScore(header *protocol.RequestHeader, request *protocol.ComputeRankScoreRequest) (rsp *protocol.ComputeRankScoreResponse, err error) { | ||
| 259 | + var () | ||
| 260 | + rsp = &protocol.ComputeRankScoreResponse{} | ||
| 261 | + if request.RankPeriodId > 0 { | ||
| 262 | + if err = contrab.ComputeRankScoreByPeriod(request.RankPeriodId); err != nil { | ||
| 263 | + log.Error(err) | ||
| 264 | + err = protocol.NewCustomMessage(1, err.Error()) | ||
| 265 | + return | ||
| 266 | + } | ||
| 267 | + err = protocol.NewSuccessWithMessage("排行榜统计成功") | ||
| 268 | + return | ||
| 269 | + } | ||
| 270 | + if err = contrab.ComputeRankScore(); err != nil { | ||
| 271 | + log.Error(err) | ||
| 272 | + err = protocol.NewCustomMessage(1, err.Error()) | ||
| 273 | + return | ||
| 274 | + } | ||
| 275 | + err = protocol.NewSuccessWithMessage("排行榜统计成功") | ||
| 276 | + return | ||
| 277 | +} |
| @@ -370,8 +370,9 @@ func UserStatistics(header *protocol.RequestHeader, request *protocol.UserStatis | @@ -370,8 +370,9 @@ func UserStatistics(header *protocol.RequestHeader, request *protocol.UserStatis | ||
| 370 | rsp = &protocol.UserStatisticsResponse{} | 370 | rsp = &protocol.UserStatisticsResponse{} |
| 371 | //buf :=bytes.NewBuffer(nil) | 371 | //buf :=bytes.NewBuffer(nil) |
| 372 | //buf.WriteString(fmt.Sprintf("用户中心-统计信息 user:%v type_total:%v \n",header.UserId,request.TypeTotal)) | 372 | //buf.WriteString(fmt.Sprintf("用户中心-统计信息 user:%v type_total:%v \n",header.UserId,request.TypeTotal)) |
| 373 | - for flag = 1; flag <= (protocol.MyAuditChanceReturn); flag = flag << 1 { | 373 | + for flag = 1; flag <= (protocol.MyGraspAchievement); flag = flag << 1 { |
| 374 | total = 0 | 374 | total = 0 |
| 375 | + if flag&request.TypeTotal > 0 { | ||
| 375 | switch flag { | 376 | switch flag { |
| 376 | case protocol.CollectStatic: //收藏 | 377 | case protocol.CollectStatic: //收藏 |
| 377 | if total, err = models.GetChanceCollect(header.UserId, 0, 0, nil); err != nil { | 378 | if total, err = models.GetChanceCollect(header.UserId, 0, 0, nil); err != nil { |
| @@ -433,7 +434,19 @@ func UserStatistics(header *protocol.RequestHeader, request *protocol.UserStatis | @@ -433,7 +434,19 @@ func UserStatistics(header *protocol.RequestHeader, request *protocol.UserStatis | ||
| 433 | log.Error(err) | 434 | log.Error(err) |
| 434 | } | 435 | } |
| 435 | break | 436 | break |
| 436 | - | 437 | + case protocol.MyAchievements: //我提交的 |
| 438 | + if total, err = agg.MyGraspStatic(header); err != nil { | ||
| 439 | + log.Error(err) | ||
| 440 | + } | ||
| 441 | + break | ||
| 442 | + case protocol.MyGraspAchievement: //我把握的成果 | ||
| 443 | + if total, err = agg.MyGraspStatic(header); err != nil { | ||
| 444 | + log.Error(err) | ||
| 445 | + } | ||
| 446 | + break | ||
| 447 | + default: | ||
| 448 | + break | ||
| 449 | + } | ||
| 437 | } | 450 | } |
| 438 | if flag&request.TypeTotal > 0 { | 451 | if flag&request.TypeTotal > 0 { |
| 439 | rsp.Totals = append(rsp.Totals, protocol.TypeTotalItem{ | 452 | rsp.Totals = append(rsp.Totals, protocol.TypeTotalItem{ |
-
请 注册 或 登录 后发表评论