初始
This commit is contained in:
110
third/reminders/reminder.go
Normal file
110
third/reminders/reminder.go
Normal file
@ -0,0 +1,110 @@
|
||||
package reminders
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/samber/lo"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/dao"
|
||||
"github.com/tiger1103/gfast/v3/internal/app/system/model/do"
|
||||
)
|
||||
|
||||
type Reminder struct {
|
||||
Content string `copier:"ViolationType"` // 内容
|
||||
Title string // 标题
|
||||
ReceiverID string `copier:"UserId"` // 消息接收者的 User_id
|
||||
Type int `copier:"ReminderType"` // 类型
|
||||
Status int // 状态
|
||||
ProjectID int `copier:"ProjectId"` // 项目 ID
|
||||
TargetID int `copier:"OrderId"` // 对应跳转的主键ID
|
||||
|
||||
//TargetID int `copier:"OrderId"` // 是否需要转换
|
||||
}
|
||||
|
||||
// UserIDOrderIDDel 根据userID与orderID 删除提醒
|
||||
func UserIDOrderIDDel(userId string, orderID int64) error {
|
||||
columns := dao.Reminders.Columns()
|
||||
_, err := dao.Reminders.Ctx(context.Background()).Where(columns.UserId, userId).Where(columns.OrderId, orderID).Delete()
|
||||
return err
|
||||
}
|
||||
|
||||
// PublishReminder 发布提醒
|
||||
func PublishReminder(message Reminder, convertOpenID bool) error {
|
||||
if convertOpenID && HasLetter(message.ReceiverID) {
|
||||
message.ReceiverID = GetUserIDByOpenID(message.ReceiverID)
|
||||
if message.ReceiverID == "" {
|
||||
return fmt.Errorf("未找到对应的用户")
|
||||
}
|
||||
}
|
||||
|
||||
var reminder do.Reminders
|
||||
copier.Copy(&reminder, &message)
|
||||
|
||||
// 保存到数据库
|
||||
_, err := dao.Reminders.Ctx(context.Background()).Insert(&reminder)
|
||||
return err
|
||||
}
|
||||
|
||||
// CheckInReminder 打卡提醒
|
||||
// Reminders.CheckIn 表示上班打卡
|
||||
// Reminders.CheckOut 表示下班打卡
|
||||
func CheckInReminder(checkType ReminderType, projectID int, userID, time string) error {
|
||||
// 1. 构建消息模板
|
||||
message := Reminder{
|
||||
Type: checkType, // 打卡类型
|
||||
ProjectID: projectID, // 项目 ID
|
||||
ReceiverID: userID, // 消息接收者的 sys_user.Id
|
||||
Title: time, // 时间,只需要多少分钟,如 "10","20"
|
||||
}
|
||||
|
||||
return PublishReminder(message, false)
|
||||
}
|
||||
|
||||
// hasLetter 判断字符串中是否包含字母
|
||||
func HasLetter(s string) bool {
|
||||
for _, c := range s {
|
||||
if (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// GetUserIDByOpenID 通过 OpenID 获取用户对应的 sys_user.Id
|
||||
func GetUserIDByOpenID(openID string) string {
|
||||
openid, err := dao.BusConstructionUser.Ctx(context.Background()).As("bu").
|
||||
Fields("su.id").
|
||||
InnerJoin("sys_user AS su", "bu.phone = su.mobile").
|
||||
Where("bu.openid", openID).Value()
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
return openid.String()
|
||||
}
|
||||
|
||||
type userOpenID struct {
|
||||
OpenID string
|
||||
ID int
|
||||
}
|
||||
|
||||
// GetUserIDByOpenIDs 传入多个 OpenID,返回对应的 User.ID
|
||||
func GetUserIDByOpenIDs(openIDs []string) map[string]string {
|
||||
// SELECT su.id,bu.openid
|
||||
// FROM bus_construction_user AS bu
|
||||
// INNER JOIN sys_user AS su ON bu.phone = su.mobile
|
||||
// WHERE bu.openid in ("oLYsI4x-L6ZVKCinQ4Rw1D9XtFZ0","oLYsI49aMJHTYorhmvVuRrasPTbU")
|
||||
|
||||
var userOpenIDList []userOpenID
|
||||
err := dao.BusConstructionUser.Ctx(context.Background()).As("bu").
|
||||
Fields("su.id", "bu.openid").
|
||||
InnerJoin("sys_user AS su", "bu.phone = su.mobile").
|
||||
WhereIn("bu.openid", openIDs).Scan(&userOpenIDList)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
return lo.SliceToMap(userOpenIDList, func(item userOpenID) (string, string) {
|
||||
return item.OpenID, fmt.Sprintf("%d", item.ID)
|
||||
})
|
||||
}
|
20
third/reminders/reminder_var.go
Normal file
20
third/reminders/reminder_var.go
Normal file
@ -0,0 +1,20 @@
|
||||
package reminders
|
||||
|
||||
type ReminderType = int
|
||||
|
||||
// 提醒类型
|
||||
const (
|
||||
Security ReminderType = iota // 安全
|
||||
Quality // 质量
|
||||
AI // AI
|
||||
CheckIn // 上班打卡
|
||||
CheckOut // 下班打卡
|
||||
)
|
||||
|
||||
// 提醒状态
|
||||
|
||||
const (
|
||||
Remind = iota // 提醒
|
||||
Reform // 整改
|
||||
Recheck // 复检
|
||||
)
|
Reference in New Issue
Block a user