作者 yangfu

表彰

[dev]
#数据库相关
mysql_user = "${MYSQL_USER||root}"
mysql_password = "${MYSQL_PASSWORD||123456}"
mysql_host = "${MYSQL_HOST||192.168.100.102}"
mysql_password = "${MYSQL_PASSWORD||sutianxia2015}"
mysql_host = "${MYSQL_HOST||115.29.205.99}"
mysql_port = "${MYSQL_PORT||3306}"
mysql_db_name = "${MYSQL_DB_NAME||opportunity}"
... ...
package v1
import (
"encoding/json"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"opp/controllers"
"opp/protocol"
"opp/services/commend"
)
type CommendController struct {
controllers.BaseController
}
//Commend
// @router /company [post]
func (this *CommendController) Company() {
var msg *protocol.ResponseMessage
defer func() {
this.Resp(msg)
}()
var request *protocol.CommendRequest
if err := json.Unmarshal(this.ByteBody, &request); err != nil {
log.Error(err)
msg = protocol.BadRequestParam(1)
return
}
if b, m := this.Valid(request); !b {
msg = m
return
}
header := controllers.GetRequestHeader(this.Ctx)
msg = protocol.NewReturnResponse(commend.Commend(header, request))
}
... ...
... ... @@ -7,6 +7,7 @@ require (
github.com/go-sql-driver/mysql v1.4.1
github.com/gorilla/websocket v1.4.1
github.com/prometheus/client_golang v1.1.0
github.com/prometheus/common v0.6.0
github.com/smartystreets/goconvey v0.0.0-20190731233626-505e41936337 // indirect
gitlab.fjmaimaimai.com/mmm-go/gocomm v0.0.1
google.golang.org/appengine v1.6.2 // indirect
... ...
package repository
import "opp/models"
type ICommendRepository interface {
GetCommends(companyId int, llastId int, pageSize int) (v []*models.Commend, total int, err error)
}
var _ ICommendRepository = (*CommendRepository)(nil)
type CommendRepository struct{}
func (r *CommendRepository) GetCommends(companyId int, lastId int, pageSize int) (v []*models.Commend, total int, err error) {
return models.GetCommends(companyId, lastId, pageSize)
}
... ...
package repository
import "opp/models"
type ICompanyRepository interface {
GetCompanyById(companyId int64) (v *models.Company, err error)
}
var _ ICompanyRepository = (*CompanyRepository)(nil)
type CompanyRepository struct{}
func (r *CompanyRepository) GetCompanyById(companyId int64) (v *models.Company, err error) {
return models.GetCompanyById(companyId)
}
... ...
package repository
import "opp/models"
type IDepartmentRepository interface {
GetDepartmentById(companyId int) (v *models.Department, err error)
}
var _ IDepartmentRepository = (*DepartmentRepository)(nil)
type DepartmentRepository struct{}
func (r *DepartmentRepository) GetDepartmentById(id int) (v *models.Department, err error) {
return models.GetDepartmentById(id)
}
... ...
package repository
import "opp/models"
type IPositionRepository interface {
GetPositionById(companyId int) (v *models.Position, err error)
}
var _ IPositionRepository = (*PositionRepository)(nil)
type PositionRepository struct{}
func (r *PositionRepository) GetPositionById(id int) (v *models.Position, err error) {
return models.GetPositionById(id)
}
... ...
... ... @@ -4,9 +4,13 @@ import "sync"
//全局
var (
once sync.Once
User IUserRepository
UserAuth IUserAuthRepository
once sync.Once
User IUserRepository
UserAuth IUserAuthRepository
Commend ICommendRepository
Company ICompanyRepository
Department IDepartmentRepository
Position IPositionRepository
)
func init() {
... ... @@ -16,6 +20,10 @@ func init() {
func InitRepository() {
User = &UserRepository{}
UserAuth = &UserAuthRepository{}
Commend = &CommendRepository{}
Company = &CompanyRepository{}
Department = &DepartmentRepository{}
Position = &PositionRepository{}
}
func InitRepositoryMock() {
... ...
... ... @@ -28,7 +28,7 @@ type User struct {
}
func (t *User) TableName() string {
return "users"
return "user"
}
func init() {
... ...
package protocol
import "opp/models"
//聚合数据
//用户基础聚合
type UserBaseInfoAggregation struct {
User *models.User
Company *models.Company
Department *models.Department
Position *models.Position
}
... ...
package protocol
/*公司表彰*/
type CommendRequest struct {
LastId int `json:"lastId"`
PageSize int `json:"pageSize" valid:"Required"`
}
type CommendResponse struct {
Lists []CommendInfo `json:"lists"`
Total int `json:"total"`
}
type CommendInfo struct {
Id int64 `json:"cid"` //表彰编号
Content string `json:"content"` //表彰内容
Company string `json:"company"` //公司名
CommendAt int64 `json:"getTime"` //表彰时间
Honored HonoredUserInfo `json:"honored"` //证书获得者 信息
}
type HonoredUserInfo struct {
UserId int64 `json:"uid"` //用户id
NickName string `json:"uname"` //用户名
Department string `json:"department"` //部门
Position string `json:"position"` //岗位
}
... ...
package protocol
import "github.com/prometheus/common/log"
var errmessge ErrorMap = map[int]string{
1: "系统异常",
101: "clientId或clientSecret无效",
... ... @@ -29,6 +31,8 @@ func NewReturnResponse(data interface{}, eRR error) *ResponseMessage {
msg = NewMesage(0)
msg.Data = data
return msg
} else {
log.Error("sys error:", eRR)
}
// fmt.Println("日志:" + eRR.Error())
if x, ok := eRR.(CustomErrParse); ok {
... ...
... ... @@ -47,6 +47,14 @@ func init() {
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:CommendController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:CommendController"],
beego.ControllerComments{
Method: "Company",
Router: `/company`,
AllowHTTPMethods: []string{"post"},
MethodParams: param.Make(),
Params: nil})
beego.GlobalControllerRouter["opp/controllers/v1:UploadController"] = append(beego.GlobalControllerRouter["opp/controllers/v1:UploadController"],
beego.ControllerComments{
Method: "Image",
... ...
... ... @@ -15,6 +15,7 @@ func init() {
beego.NSNamespace("auth", beego.NSInclude(&v1.AuthController{})),
beego.NSNamespace("upload", beego.NSInclude(&v1.UploadController{})),
beego.NSNamespace("version", beego.NSInclude(&v1.VersionController{})),
beego.NSNamespace("commend", beego.NSInclude(&v1.CommendController{})),
)
beego.AddNamespace(nsV1)
beego.SetStaticPath("/file/ab", beego.AppConfig.String("source_path"))
... ...
package agg
import (
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"opp/internal/repository"
"opp/protocol"
"sync"
)
func GetUserBaseInfo(uid int64) (v *protocol.UserBaseInfoAggregation, err error) {
v = &protocol.UserBaseInfoAggregation{}
var wg sync.WaitGroup
if v.User, err = repository.User.GetUsersById(uid); err != nil {
log.Error(err)
return
}
wg.Add(3)
go func() {
defer wg.Done()
if v.Company, err = repository.Company.GetCompanyById(int64(v.User.CompanyId)); err != nil {
log.Error(err)
return
}
}()
go func() {
defer wg.Done()
if v.Department, err = repository.Department.GetDepartmentById(v.User.DepartmentId); err != nil {
log.Error(err)
return
}
}()
go func() {
defer wg.Done()
if v.Position, err = repository.Position.GetPositionById(v.User.PositionId); err != nil {
log.Error(err)
return
}
}()
wg.Wait()
return
}
... ...
package commend
import (
"gitlab.fjmaimaimai.com/mmm-go/gocomm/time"
"opp/internal/repository"
"opp/models"
"opp/protocol"
"opp/services/agg"
)
func Commend(header *protocol.RequestHeader, request *protocol.CommendRequest) (rsp *protocol.CommendResponse, err error) {
var (
userBaseInfo *protocol.UserBaseInfoAggregation
user *models.User
commends []*models.Commend
)
rsp = &protocol.CommendResponse{}
user, err = repository.User.GetUsersById(header.Uid)
if err != nil {
return
}
if commends, rsp.Total, err = repository.Commend.GetCommends(user.CompanyId, request.LastId, request.PageSize); err != nil {
return
}
for i := 0; i < len(commends); i++ {
c := commends[i]
userBaseInfo, err = agg.GetUserBaseInfo(c.UserId)
if err != nil {
continue
}
user = userBaseInfo.User
cInfo := protocol.CommendInfo{
Id: c.Id,
Content: c.Content,
Company: userBaseInfo.Company.Name,
CommendAt: time.GetUnixTimeByNDayUnix(c.CommendAt.Unix(), 0),
Honored: protocol.HonoredUserInfo{
UserId: c.UserId,
NickName: user.NickName,
Department: userBaseInfo.Department.Name,
Position: userBaseInfo.Position.Name,
},
}
rsp.Lists = append(rsp.Lists, cInfo)
}
return
}
... ...