作者 tangxvhui

Merge branch 'dev-tangxvhui' into test

... ... @@ -208,3 +208,11 @@ func CreateLogSmsRepository(options map[string]interface{}) domain.LogSmsReposit
}
return repository.NewLogSmsRepository(transactionContext)
}
func CreateMessagePersonalRepository(options map[string]interface{}) domain.MessagePersonalRepository {
var transactionContext *pg.TransactionContext
if value, ok := options["transactionContext"]; ok {
transactionContext = value.(*pg.TransactionContext)
}
return repository.NewMessagePersonalRepository(transactionContext)
}
... ...
package notify
import (
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/notify/command"
)
// 个人信息提示
type MessagePersonalService struct {
}
func NewMessagePersonalService() *MessagePersonalService {
newService := &MessagePersonalService{}
return newService
}
// 获取今天的周期综合自评消息提示
func (srv *MessagePersonalService) TodayMessageSummaryEvaluationSelf(param *command.GetUserMessageCommand) (interface{}, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
// nowTime := time.Now()
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return nil, nil
}
package notify
import (
"encoding/json"
"fmt"
"strconv"
"time"
"github.com/linmadan/egglib-go/core/application"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/application/notify/command"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
)
// 个人信息提示
type MessagePersonalService struct {
}
func NewMessagePersonalService() *MessagePersonalService {
newService := &MessagePersonalService{}
return newService
}
// 获取今天的周期综合自评消息提示
func (srv *MessagePersonalService) TodayMessageSummaryEvaluationSelf(param *command.GetUserMessageCommand) (map[string]interface{}, error) {
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
if err := transactionContext.StartTransaction(); err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
defer func() {
_ = transactionContext.RollbackTransaction()
}()
nowTime := time.Now()
evaluationRepo := factory.CreateSummaryEvaluationRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
_, evaluationList, err := evaluationRepo.Find(map[string]interface{}{
"targetUserId": param.UserId,
"types": domain.EvaluationSelf,
"beginTime": nowTime,
"endTime": nowTime,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "周期综合自评"+err.Error())
}
resp := map[string]interface{}{
"needNotify": false,
"content": "",
}
if len(evaluationList) == 0 {
return resp, nil
}
messageRepo := factory.CreateMessagePersonalRepository(map[string]interface{}{
"transactionContext": transactionContext,
})
newMessageList := []domain.MessagePersonal{}
for _, val := range evaluationList {
payload := map[string]string{
"id": strconv.Itoa(val.Id),
}
payloadStr, _ := json.Marshal(payload)
cnt, _, err := messageRepo.Find(map[string]interface{}{
"types": domain.MessageTypesOther,
"targetUserId": param.UserId,
"playload": string(payloadStr),
"limit": 1,
})
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "检查自评消息记录"+err.Error())
}
if cnt == 0 {
newMessageList = append(newMessageList, domain.MessagePersonal{
Id: 0,
Types: domain.MessageTypesOther,
TargetUserId: val.TargetUser.UserId,
ReadFlag: domain.MessageIsRead,
Title: fmt.Sprintf("%s综合自评已开启,请前往进行评估.", val.CycleName),
Content: fmt.Sprintf("%s综合自评已开启,请前往进行评估.", val.CycleName),
CreatedAt: time.Time{},
UpdatedAt: time.Time{},
Payload: string(payloadStr),
})
resp["needNotify"] = true
resp["content"] = fmt.Sprintf("%s综合自评已开启,请前往进行评估.", val.CycleName)
break
}
}
for i := range newMessageList {
err = messageRepo.Save(&newMessageList[i])
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, "保存自评消息记录"+err.Error())
}
}
if err := transactionContext.CommitTransaction(); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
return resp, nil
}
... ...
... ... @@ -4,15 +4,15 @@ import "time"
// MessagePersonal 个人的消息提示
type MessagePersonal struct {
Id int //
Types string //消息类型
TargetUserId int //消息指向的用户
ReadFlag MessageReadFlag //1:已读、2:未读
Title string //消息的标题
Content string //消息的内容
CreatedAt time.Time
UpdatedAt time.Time
Payload string //消息的额外承载的数据
Id int `json:"id"` //
Types MessageTypes `json:"types"` //消息类型
TargetUserId int `json:"targetUserId"` //消息指向的用户
ReadFlag MessageReadFlag `json:"readFlag"` //1:已读、2:未读
Title string `json:"title"` //消息的标题
Content string `json:"content"` //消息的内容
CreatedAt time.Time `json:"createdAt"`
UpdatedAt time.Time `json:"updatedAt"`
Payload string `json:"payload"` //消息的额外承载的数据
}
type MessageTypes string
... ... @@ -27,3 +27,8 @@ const (
MessageIsRead MessageReadFlag = "read"
MessageUnread MessageReadFlag = "unread"
)
type MessagePersonalRepository interface {
Save(param *MessagePersonal) error
Find(queryOptions map[string]interface{}) (int, []*MessagePersonal, error)
}
... ...
... ... @@ -9,8 +9,8 @@ import (
func TestGenerateToken(t *testing.T) {
ut := UserAuth{
CompanyId: 8,
UserId: 3435675157551872,
Phone: "18060823798",
UserId: 3422181461696000,
Phone: "13066667702",
PlatformId: 29,
AdminType: 1,
}
... ...
... ... @@ -51,6 +51,7 @@ func init() {
&models.SummaryEvaluationValue{},
&models.Permission{},
&models.LogSms{},
&models.MessagePersonal{},
}
for _, model := range tables {
err := DB.Model(model).CreateTable(&orm.CreateTableOptions{
... ...
package models
import "time"
// MessagePersonal 记录个人的提示消息
type MessagePersonal struct {
tableName struct{} `comment:"记录个人的提示消息" pg:"message_personal"`
Id int `pg:"id,pk"` //
Types string `pg:"types"` //消息类型
TargetUserId int `pg:"target_user_id"` //消息指向的用户
ReadFlag string `pg:"read_flag"` //1:已读、2:未读
Title string `pg:"title"` //消息的标题
Content string `pg:"content"` //消息的内容
CreatedAt time.Time `pg:"created_at"`
UpdatedAt time.Time `pg:"updated_at"`
Payload string `pg:"payload,type:jsonb"` //消息的额外承载的数据
}
... ...
package repository
import (
"time"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/pg/models"
)
type MessagePersonalRepository struct {
transactionContext *pgTransaction.TransactionContext
}
var _ domain.MessagePersonalRepository = (*MessagePersonalRepository)(nil)
func NewMessagePersonalRepository(tx *pgTransaction.TransactionContext) *MessagePersonalRepository {
return &MessagePersonalRepository{
transactionContext: tx,
}
}
func (repo *MessagePersonalRepository) TransformToDomain(param *models.MessagePersonal) *domain.MessagePersonal {
return &domain.MessagePersonal{
Id: param.Id,
Types: domain.MessageTypes(param.Types),
TargetUserId: param.TargetUserId,
ReadFlag: domain.MessageReadFlag(param.ReadFlag),
Title: param.Title,
Content: param.Content,
Payload: param.Payload,
UpdatedAt: param.UpdatedAt,
CreatedAt: param.CreatedAt,
}
}
func (repo *MessagePersonalRepository) Save(param *domain.MessagePersonal) error {
message := &models.MessagePersonal{
Id: param.Id,
Types: string(param.Types),
TargetUserId: param.TargetUserId,
ReadFlag: string(param.ReadFlag),
Title: param.Title,
Content: param.Content,
Payload: param.Payload,
UpdatedAt: time.Now(),
CreatedAt: param.CreatedAt,
}
tx := repo.transactionContext.PgTx
if message.Id == 0 {
message.CreatedAt = time.Now()
_, err := tx.Model(message).Insert()
return err
}
_, err := tx.Model(message).WherePK().Update()
return err
}
func (repo *MessagePersonalRepository) Find(param map[string]interface{}) (int, []*domain.MessagePersonal, error) {
tx := repo.transactionContext.PgTx
var m []*models.MessagePersonal
query := tx.Model(&m).Limit(20)
if v, ok := param["targetUserId"]; ok {
query.Where("target_user_id=?", v)
}
if v, ok := param["types"]; ok {
query.Where("types=?", v)
}
if v, ok := param["playload"]; ok {
query.Where("playload @>?", v)
}
query.Order("id desc")
count, err := query.SelectAndCount()
if err != nil {
return 0, nil, err
}
var datas []*domain.MessagePersonal
for _, v := range m {
d := repo.TransformToDomain(v)
datas = append(datas, d)
}
return count, datas, nil
}
... ...
-- summary_evaluation_value表添加字段
ALTER TABLE public.summary_evaluation_value
ADD executor jsonb NULL;
-- 初始化旧数据的summary_evaluation_value.executor
UPDATE
public.summary_evaluation_value
SET
executor = public.summary_evaluation.executor
FROM
public.summary_evaluation
WHERE
public.summary_evaluation_value.summary_evaluation_id = public.summary_evaluation.id;
... ...