作者 tangxvhui

日常保存

package main
import (
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/constant"
"time"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/constant"
"github.com/beego/beego/v2/server/web"
serviceTask "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/node_task"
serviceSummary "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/summary_evaluation/service"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
_ "gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/beego"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/port/consumer"
... ... @@ -13,12 +15,7 @@ import (
func main() {
startNodeTask()
// tree := web.PrintTree()
// methods := tree["Data"].(web.M)
// for k, v := range methods {
// fmt.Printf("%s => %v \n", k, v)
// }
// startSummaryEvaluation()
go consumer.Run()
web.Run()
}
... ... @@ -44,3 +41,22 @@ func startNodeTask() {
}
}()
}
func startSummaryEvaluation() {
go func() {
duration := 10 * time.Minute
if constant.Env != "prd" {
duration = 1 * time.Minute
}
timer := time.NewTimer(duration)
for {
<-timer.C
err := serviceSummary.TaskSendSummaryEvaluation()
if err != nil {
log.Logger.Error(err.Error())
}
timer.Reset(duration) // 重置定时
}
}()
}
... ...
... ... @@ -200,3 +200,11 @@ func CreatePermissionRepository(options map[string]interface{}) domain.Permissio
}
return repository.NewPermissionRepository(transactionContext)
}
func CreateLogSmsRepository(options map[string]interface{}) domain.LogSmsRepository {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewLogSmsRepository(transactionContext)
}
... ...
package adapter
type MenuListAdapter struct {
CycleId int `json:"cycleId,string"`
NodeName string `json:"nodeName"`
StatusName string `json:"statusName"`
Types string `json:"types"`
Child []MenuListAdapter `json:"child"`
CycleId int `json:"cycleId,string"`
NodeName string `json:"nodeName"`
StatusName string `json:"statusName"`
TargetUserId int `json:"targetUserId,string"`
Types string `json:"types"`
Child []MenuListAdapter `json:"child"`
}
... ...
... ... @@ -5,6 +5,10 @@ import (
"strconv"
"time"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/constant"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/serviceGateway"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/log"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
... ... @@ -13,7 +17,7 @@ import (
// project 需要处理的项目
// userList 全体的员工数据 map[id]=>domain.User
// departmetList 全部的部门数据 map[id]=>domain.Department
func sendSummaryEvaluation(project *domain.EvaluationProject, cycleData *domain.EvaluationCycle,
func sendSummaryEvaluation(project *domain.EvaluationProject,
userMap map[int64]*domain.User, departmentMap map[int64]*domain.Department) ([]domain.SummaryEvaluation, error) {
//自评的时间范围
beginTimeSelf := project.EndTime
... ... @@ -35,9 +39,14 @@ func sendSummaryEvaluation(project *domain.EvaluationProject, cycleData *domain.
defer func() {
_ = transactionContext.RollbackTransaction()
}()
cycleRepo := factory.CreateEvaluationCycleRepository(map[string]interface{}{"transactionContext": transactionContext})
evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{"transactionContext": transactionContext})
cycleData, err := cycleRepo.FindOne(map[string]interface{}{"id": project.CycleId})
if err != nil {
return nil, err
}
//确定 被评估的人
targetUserId := []int64{}
for _, v := range project.Recipients {
... ... @@ -209,7 +218,7 @@ func TaskSendSummaryEvaluation() error {
userRepo := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
departmentRepo := factory.CreateUserRepository(map[string]interface{}{"transactionContext": transactionContext})
departmentRepo := factory.CreateDepartmentRepository(map[string]interface{}{"transactionContext": transactionContext})
_, projectList, err := projectRepo.Find(map[string]interface{}{
"endTime": time.Now(),
... ... @@ -223,24 +232,96 @@ func TaskSendSummaryEvaluation() error {
for _, v := range projectList {
companyIdMap[v.CompanyId] = struct{}{}
}
var createdEvalationList []domain.SummaryEvaluation
//获取可执行的项目
for companyId := range companyIdMap {
//获取员工数据,部门数据
_, userList, err := userRepo.Find(map[string]interface{}{"companyId": companyId})
if err != nil {
log.Logger.Error("TaskSendSummaryEvaluation 获取员工数据:" + err.Error())
continue
}
_, departmentList, err := departmentRepo.Find(map[string]interface{}{"companyId": companyId})
if err != nil {
log.Logger.Error("TaskSendSummaryEvaluation 获取部门数据:" + err.Error())
continue
}
//转map
userMap := map[int64]*domain.User{}
for _, v := range userList {
userMap[v.Id] = v
}
departmentMap := map[int64]*domain.Department{}
for _, v := range departmentList {
departmentMap[v.Id] = v
}
for _, v := range projectList {
if v.CompanyId != companyId {
continue
}
evalationList, err := sendSummaryEvaluation(v, userMap, departmentMap)
if err != nil {
log.Logger.Error("TaskSendSummaryEvaluation 下发评估任务:" + err.Error())
continue
}
createdEvalationList = append(createdEvalationList, evalationList...)
}
}
//获取员工数据
if err := transactionContext.CommitTransaction(); err != nil {
return err
}
//发送短信通知
err = sendSmsEvalation(createdEvalationList)
return err
}
//获取部门数据
// 发送短信通知
func sendSmsEvalation(param []domain.SummaryEvaluation) error {
if constant.Env != "prd" {
return nil
}
//处理短信发送
//过滤去重 处理需要发送改执行人的消息 执行人id=>domain.LogSms
noticeMap := map[string]*domain.LogSms{}
for _, v := range param {
phone := v.Executor.Account
name := v.Executor.UserName
if _, ok := noticeMap[phone]; ok {
continue
}
smsMessage := domain.LogSms{}
smsMessage.SummaryEvaluationMessage(phone, name)
noticeMap[phone] = &smsMessage
}
sms := serviceGateway.SmsService{}
for _, v := range noticeMap {
err := sms.SendNoticeSms(v.Phone, v.TemplateId, v.Value)
if err != nil {
v.Result = err.Error()
}
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return err
}
if err := transactionContext.StartTransaction(); err != nil {
return err
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
logSmsRepo := factory.CreateLogSmsRepository(map[string]interface{}{"transactionContext": transactionContext})
for _, v := range noticeMap {
err = logSmsRepo.Insert(v)
if err != nil {
log.Logger.Error("TaskSendSummaryEvaluation 发送短信通知:" + err.Error())
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return err
}
return nil
}
... ...
... ... @@ -132,6 +132,7 @@ func (srv *SummaryEvaluationService) GetMenu(param *command.QueryMenu) (map[stri
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
//查找当前周期,我的考核结果,人资评估
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
... ... @@ -147,16 +148,18 @@ func (srv *SummaryEvaluationService) GetMenu(param *command.QueryMenu) (map[stri
Child: []adapter.MenuListAdapter{},
}
menu1_1 := adapter.MenuListAdapter{
CycleId: param.CycleId,
NodeName: "填写综合自评",
StatusName: "",
Types: "填写综合自评",
CycleId: param.CycleId,
NodeName: "填写综合自评",
StatusName: "",
TargetUserId: param.UserId,
Types: "填写综合自评",
}
menu1_2 := adapter.MenuListAdapter{
CycleId: param.CycleId,
NodeName: "查看综合自评",
StatusName: "",
Types: "查看综合自评",
CycleId: param.CycleId,
NodeName: "查看综合自评",
StatusName: "",
TargetUserId: param.UserId,
Types: "查看综合自评",
}
if len(selfEvaluation) > 0 {
if selfEvaluation[0].Status == domain.EvaluationCompleted {
... ... @@ -277,8 +280,8 @@ func (srv *SummaryEvaluationService) buildSummaryItemValue(itemList []*domain.Ev
return itemValues
}
// 获取综合自评详情
func (srv *SummaryEvaluationService) GetEvaluationSelf(param *command.QueryEvaluation) (*adapter.EvaluationInfoSelfAdapter, error) {
// 根据周期id和被评估人获取综合自评详情
func (srv *SummaryEvaluationService) GetEvaluationSelfByCycle(param *command.QueryEvaluation) (*adapter.EvaluationInfoSelfAdapter, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
... ... @@ -753,28 +756,28 @@ func (srv *SummaryEvaluationService) GetEvaluationSuper(param *command.QueryEval
}
//组合 评估填写的值和评估项
itemValuesAdapter := srv.buildSummaryItemValue(itemList, itemValues)
codeList := []*adapter.LevalCodeCount{}
codeMap := map[string]*adapter.LevalCodeCount{}
for _, v := range itemValuesAdapter {
if v.Weight > 0 {
continue
}
if _, ok := codeMap[v.Value]; !ok {
code := &adapter.LevalCodeCount{
Code: v.Value,
Number: 0,
ItemList: []string{},
}
codeMap[v.Value] = code
codeList = append(codeList, code)
}
codeMap[v.Value].ItemList = append(codeMap[v.Value].ItemList, v.Name)
codeMap[v.Value].Number += 1
}
// codeList := []*adapter.LevalCodeCount{}
// codeMap := map[string]*adapter.LevalCodeCount{}
// for _, v := range itemValuesAdapter {
// if v.Weight > 0 {
// continue
// }
// if _, ok := codeMap[v.Value]; !ok {
// code := &adapter.LevalCodeCount{
// Code: v.Value,
// Number: 0,
// ItemList: []string{},
// }
// codeMap[v.Value] = code
// codeList = append(codeList, code)
// }
// codeMap[v.Value].ItemList = append(codeMap[v.Value].ItemList, v.Name)
// codeMap[v.Value].Number += 1
// }
result := adapter.EvaluationInfoSuperAdapter{
EvaluationBaseAdapter: evaluationBase,
LevelCount: codeList,
EvaluationItems: itemValuesAdapter,
// LevelCount: codeList,
EvaluationItems: itemValuesAdapter,
}
return &result, nil
}
... ... @@ -1184,3 +1187,118 @@ func (srv *SummaryEvaluationService) ConfirmScoreSuperEvaluation(param *command.
}
return nil
}
// 按照周期和被评估的人 获取上级评估详情
func (srv *SummaryEvaluationService) GetTargetUserEvaluationSuper(param *command.QueryEvaluation) (*adapter.EvaluationInfoSuperAdapter, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
evaluationItemRepo := factory.CreateEvaluationItemUsedRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
itemValueRepo := factory.CreateSummaryEvaluationValueRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
_, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
"limit": 1,
"cycleId": param.CycleId,
"executorId": param.UserId,
"types": domain.EvaluationSuper,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if len(evaluationList) == 0 {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "没有找到符合条件的数据")
}
evaluationData := evaluationList[0]
if evaluationData.Types == domain.EvaluationSuper {
return nil, application.ThrowError(application.BUSINESS_ERROR, "没有操作权限")
}
if evaluationData.CompanyId == param.CompanyId {
return nil, application.ThrowError(application.BUSINESS_ERROR, "没有操作权限")
}
_, itemList, err := evaluationItemRepo.Find(map[string]interface{}{
"evaluationProjectId": evaluationData.EvaluationProjectId,
"nodeType": int(domain.LinkNodeSelfAssessment),
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
//获取已填写的评估内容
_, itemValues, err := itemValueRepo.Find(map[string]interface{}{
"summaryEvaluationId": evaluationData.Id,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
if len(itemValues) == 0 {
//上级还未填写评估,获取 360 ,人资评估
_, evaluationListOther, err := evaluationRepo.Find(map[string]interface{}{
"typesList": []int{int(domain.Evaluation360), int(domain.EvaluationHrbp)},
"targetUserId": evaluationData.TargetUser.UserId,
"cycleId": evaluationData.CycleId,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
evaluationIds := []int{}
for _, v := range evaluationListOther {
evaluationIds = append(evaluationIds, v.Id)
}
if len(evaluationIds) > 0 {
_, itemValues, err = itemValueRepo.Find(map[string]interface{}{
"summaryEvaluationIdList": evaluationIds,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
}
}
evaluationBase := srv.getSummaryEvaluation(transactionContext, evaluationData)
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
//组合 评估填写的值和评估项
itemValuesAdapter := srv.buildSummaryItemValue(itemList, itemValues)
codeList := []*adapter.LevalCodeCount{}
codeMap := map[string]*adapter.LevalCodeCount{}
for _, v := range itemValuesAdapter {
if v.Weight > 0 {
continue
}
if _, ok := codeMap[v.Value]; !ok {
code := &adapter.LevalCodeCount{
Code: v.Value,
Number: 0,
ItemList: []string{},
}
codeMap[v.Value] = code
codeList = append(codeList, code)
}
codeMap[v.Value].ItemList = append(codeMap[v.Value].ItemList, v.Name)
codeMap[v.Value].Number += 1
}
result := adapter.EvaluationInfoSuperAdapter{
EvaluationBaseAdapter: evaluationBase,
LevelCount: codeList,
EvaluationItems: itemValuesAdapter,
}
return &result, nil
}
// 获取周期综合评估下,周期评估列表
func (srv *SummaryEvaluationService) ListEvalationSuper() (map[int]interface{}, error) {
return nil, nil
}
... ...
... ... @@ -7,9 +7,10 @@ import "time"
type LogSms struct {
Id int
Phone string
TemplateId string
TemplateId int
Template string
Value map[string]string
Result string
CreatedAt time.Time
}
... ... @@ -18,7 +19,7 @@ func (sms *LogSms) SummaryEvaluationMessage(phone string, name string) {
*sms = LogSms{
Id: 0,
Phone: phone,
TemplateId: "5475050",
TemplateId: 5475050,
Template: "您好,#name#,百忙之中不要忘记填写今天的绩效自评反馈哦",
Value: map[string]string{
"name": name,
... ...
... ... @@ -6,8 +6,9 @@ type LogSms struct {
tableName struct{} `comment:"记录短信消息" pg:"log_sms"`
Id int `pg:",pk"`
Phone string `pg:"phone"`
TemplateId string `pg:"template_id"`
TemplateId int `pg:"template_id"`
Template string `pg:"template"`
Value map[string]string `pg:"value"`
CreatedAt time.Time `pg:"createdAt"`
Result string `pg:"result"`
}
... ...
... ... @@ -105,6 +105,9 @@ func (repo *DepartmentRepository) Find(queryOptions map[string]interface{}) (int
if v, ok := queryOptions["offset"]; ok {
query.Offset(v.(int))
}
if v, ok := queryOptions["companyId"]; ok {
query.Where("company_id = ?", v)
}
cnt, err := query.SelectAndCount()
if err != nil {
return 0, nil, err
... ...
... ... @@ -24,6 +24,7 @@ func (repo *LogSmsRepository) Insert(param *domain.LogSms) error {
Template: param.Template,
Value: param.Value,
CreatedAt: param.CreatedAt,
Result: param.Result,
}
tx := repo.transactionContext.PgTx
_, err := tx.Model(&m).Insert()
... ...
... ... @@ -44,6 +44,7 @@ func (c *SummaryEvaluationController) GetMenu() {
}
// 获取自评详情
func (c *SummaryEvaluationController) GetEvaluationSelf() {
srv := service.NewSummaryEvaluationService()
paramReq := &command.QueryEvaluation{}
... ... @@ -56,7 +57,7 @@ func (c *SummaryEvaluationController) GetEvaluationSelf() {
userReq := middlewares.GetUser(c.Ctx)
paramReq.CompanyId = int(userReq.CompanyId)
paramReq.UserId = int(userReq.UserId)
data, err := srv.GetEvaluationSelf(paramReq)
data, err := srv.GetEvaluationSelfByCycle(paramReq)
c.Response(data, err)
}
... ... @@ -240,3 +241,19 @@ func (c *SummaryEvaluationController) ConfirmScoreSuperEvaluation() {
err = srv.ConfirmScoreSuperEvaluation(param)
c.Response(nil, err)
}
// GetTargetUserEvaluationSuper 根据被评估人和周期获取 上级评估
func (c *SummaryEvaluationController) GetTargetUserEvaluationSuper() {
srv := service.NewSummaryEvaluationService()
paramReq := &command.QueryEvaluation{}
err := c.BindJSON(paramReq)
if err != nil {
e := application.ThrowError(application.ARG_ERROR, "json 解析错误"+err.Error())
c.Response(nil, e)
return
}
userReq := middlewares.GetUser(c.Ctx)
paramReq.UserId = int(userReq.UserId)
data, err := srv.GetTargetUserEvaluationSuper(paramReq)
c.Response(data, err)
}
... ...
... ... @@ -24,6 +24,7 @@ func init() {
web.NSCtrlPost("/evaluation-super/edit", (*controllers.SummaryEvaluationController).EditEvaluationSuper),
web.NSCtrlPost("/evaluation-super/list", (*controllers.SummaryEvaluationController).ListEvaluationSuper),
web.NSCtrlPost("/evaluation-super/confirm", (*controllers.SummaryEvaluationController).ConfirmScoreSuperEvaluation),
web.NSCtrlPost("/target_user/evaluation-super", (*controllers.SummaryEvaluationController).GetTargetUserEvaluationSuper),
//
)
web.AddNamespace(summaryNS)
... ...