Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 22735aeaae | |||
| dd6eeb5dfe | |||
| ac6409f3e2 | |||
| 36a6932056 |
+6
-33
@@ -1,43 +1,16 @@
|
||||
FROM golang:latest AS backend-builder
|
||||
RUN apt update
|
||||
RUN apt install -y build-essential
|
||||
|
||||
# 安装 OpenCV 开发库和依赖
|
||||
RUN apt install -y \
|
||||
libopencv-dev \
|
||||
libopencv-core-dev \
|
||||
libopencv-imgproc-dev \
|
||||
libopencv-imgcodecs-dev \
|
||||
libopencv-videoio-dev \
|
||||
pkg-config
|
||||
FROM gocv/opencv:latest AS backend-builder
|
||||
RUN echo "开始安装依赖包..."
|
||||
RUN apt update && apt install -y upx-ucl
|
||||
|
||||
WORKDIR /build
|
||||
COPY . .
|
||||
ENV CGO_ENABLED=1
|
||||
RUN echo "开始打包二进制文件"
|
||||
RUN go build -ldflags="-s -w" -o bin/server
|
||||
|
||||
RUN apt install -y upx-ucl
|
||||
|
||||
RUN echo "开始压缩二进制文件"
|
||||
RUN upx --best --lzma bin/server
|
||||
|
||||
# 收集所有 OpenCV 运行时需要的 .so 文件
|
||||
RUN mkdir -p /opencv-libs && \
|
||||
cp -P /usr/lib/x86_64-linux-gnu/libopencv*.so* /opencv-libs/ 2>/dev/null || true
|
||||
|
||||
FROM golang:latest
|
||||
|
||||
# 安装 OpenCV 运行时依赖
|
||||
RUN apt update && apt install -y \
|
||||
libgl1 \
|
||||
libglvnd0 \
|
||||
libopengl0 \
|
||||
libgomp1 \
|
||||
libglib2.0-0 \
|
||||
libglx0 \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# 复制 OpenCV .so 文件到运行环境
|
||||
COPY --from=backend-builder /opencv-libs/* /usr/lib/x86_64-linux-gnu/
|
||||
FROM gocv/opencv:latest
|
||||
|
||||
COPY --from=backend-builder /build/bin/server /app/server
|
||||
#COPY static /app/static
|
||||
|
||||
@@ -354,7 +354,7 @@ func (c *CpdailyCollectionTask) ParseFormJson(ctx context.Context, rawJson map[s
|
||||
return list
|
||||
}
|
||||
|
||||
func (c *CpdailyCollectionTask) FillCustomForm(ctx context.Context, form map[string]*gvar.Var, paramList []*formtype.CpTaskFormItem, deviceId, username string) map[string]*gvar.Var {
|
||||
func (c *CpdailyCollectionTask) FillCustomForm(ctx context.Context, form map[string]*gvar.Var, paramList []*formtype.CpTaskFormItem, deviceId, imgId string) map[string]*gvar.Var {
|
||||
taskInfo := form["taskInfo"].MapStrVar()
|
||||
rows := form["rows"].Array()
|
||||
filledForm := make([]map[string]*gvar.Var, 0)
|
||||
|
||||
@@ -12,6 +12,6 @@ type CpdailyTask interface {
|
||||
QueryFormByTitle(ctx context.Context, titleGlob string) map[string]*gvar.Var
|
||||
QueryFormByYearMonth(ctx context.Context, titleGlob string, year, month string) map[string]*gvar.Var
|
||||
ParseFormJson(ctx context.Context, rawJson map[string]*gvar.Var) []*formtype.CpTaskFormItem
|
||||
FillCustomForm(ctx context.Context, form map[string]*gvar.Var, paramList []*formtype.CpTaskFormItem, deviceId, username string) map[string]*gvar.Var
|
||||
FillCustomForm(ctx context.Context, form map[string]*gvar.Var, paramList []*formtype.CpTaskFormItem, deviceId, imgId string) map[string]*gvar.Var
|
||||
Submit(ctx context.Context, form map[string]*gvar.Var, username, deviceId string)
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
"likedream-goframe/internal/application/cpdaily/types"
|
||||
"likedream-goframe/internal/common/errors"
|
||||
"likedream-goframe/internal/utils"
|
||||
"math/rand/v2"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -467,7 +466,7 @@ func (c *CpdailyAutoSignTask) ParseFormJson(ctx context.Context, rawJson map[str
|
||||
return list
|
||||
}
|
||||
|
||||
func (c *CpdailyAutoSignTask) FillCustomForm(ctx context.Context, form map[string]*gvar.Var, paramList []*formtype.CpTaskFormItem, deviceId, username string) map[string]*gvar.Var {
|
||||
func (c *CpdailyAutoSignTask) FillCustomForm(ctx context.Context, form map[string]*gvar.Var, paramList []*formtype.CpTaskFormItem, deviceId, imgId string) map[string]*gvar.Var {
|
||||
var resultForm map[string]*gvar.Var
|
||||
|
||||
// 填充必要变量
|
||||
@@ -508,27 +507,11 @@ func (c *CpdailyAutoSignTask) FillCustomForm(ctx context.Context, form map[strin
|
||||
utils.OkOrPanic(errors.NewBusinessError(400, "签到需要图片,但是当前图片为空"), oops.WithContext(ctx).Wrap)
|
||||
}
|
||||
|
||||
imageUuidSeq := strings.SplitSeq(targetParam.Content, ",")
|
||||
|
||||
var imageUuids []string
|
||||
|
||||
for imageUuid := range imageUuidSeq {
|
||||
imageUuid = strings.TrimSpace(imageUuid)
|
||||
if imageUuid == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
imageUuids = append(imageUuids, imageUuid)
|
||||
}
|
||||
|
||||
if len(imageUuids) == 0 {
|
||||
if imgId == "" {
|
||||
utils.OkOrPanic(errors.NewBusinessError(400, "签到照片未上传"), oops.WithContext(ctx).Wrap)
|
||||
}
|
||||
|
||||
// 随机选择一张照片
|
||||
imageUuid := imageUuids[rand.IntN(len(imageUuids))]
|
||||
|
||||
imageId, e := uuid.Parse(imageUuid)
|
||||
imageId, e := uuid.Parse(imgId)
|
||||
utils.OkOrPanic(e, oops.WithContext(ctx).Wrap)
|
||||
|
||||
previewUrl := imageuploader.UploadImageFromStorage(ctx, c.host, imageId, types.TaskTypeSign, c.client)
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
"likedream-goframe/internal/common/cst"
|
||||
"likedream-goframe/internal/common/errors"
|
||||
"likedream-goframe/internal/utils"
|
||||
"math/rand/v2"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -501,7 +500,7 @@ func (c *CpdailySleepCheckTask) ParseFormJson(ctx context.Context, rawJson map[s
|
||||
return list
|
||||
}
|
||||
|
||||
func (c *CpdailySleepCheckTask) FillCustomForm(ctx context.Context, form map[string]*gvar.Var, paramList []*formtype.CpTaskFormItem, deviceId, username string) map[string]*gvar.Var {
|
||||
func (c *CpdailySleepCheckTask) FillCustomForm(ctx context.Context, form map[string]*gvar.Var, paramList []*formtype.CpTaskFormItem, deviceId, imgId string) map[string]*gvar.Var {
|
||||
var resultForm map[string]*gvar.Var
|
||||
|
||||
// 填充必要变量
|
||||
@@ -561,27 +560,11 @@ func (c *CpdailySleepCheckTask) FillCustomForm(ctx context.Context, form map[str
|
||||
utils.OkOrPanic(errors.NewBusinessError(503, "未找到查寝照片参数,请上传照片"), oops.WithContext(ctx).Wrap)
|
||||
}
|
||||
|
||||
imageUuidSeq := strings.SplitSeq(targetParam.Content, ",")
|
||||
|
||||
var imageUuids []string
|
||||
|
||||
for imageUuid := range imageUuidSeq {
|
||||
imageUuid = strings.TrimSpace(imageUuid)
|
||||
if imageUuid == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
imageUuids = append(imageUuids, imageUuid)
|
||||
}
|
||||
|
||||
if len(imageUuids) == 0 {
|
||||
if imgId == "" {
|
||||
utils.OkOrPanic(errors.NewBusinessError(503, "未找到查寝照片参数,请上传照片"), oops.WithContext(ctx).Wrap)
|
||||
}
|
||||
|
||||
// 随机选择一张照片
|
||||
imageUuid := imageUuids[rand.IntN(len(imageUuids))]
|
||||
|
||||
imageId, e := uuid.Parse(imageUuid)
|
||||
imageId, e := uuid.Parse(imgId)
|
||||
utils.OkOrPanic(e, oops.WithContext(ctx).Wrap)
|
||||
|
||||
previewUrl := imageuploader.UploadImageFromStorage(ctx, c.host, imageId, types.TaskTypeSleepCheck, c.client)
|
||||
|
||||
+12
-1
@@ -39,6 +39,8 @@ type CpTask struct {
|
||||
SuccessCount int `json:"success_count,omitempty"`
|
||||
// FormData holds the value of the "form_data" field.
|
||||
FormData string `json:"form_data,omitempty"`
|
||||
// UsedImg holds the value of the "used_img" field.
|
||||
UsedImg string `json:"used_img,omitempty"`
|
||||
// Step holds the value of the "step" field.
|
||||
Step cptask.Step `json:"step,omitempty"`
|
||||
// NotificationType holds the value of the "notification_type" field.
|
||||
@@ -109,7 +111,7 @@ func (*CpTask) scanValues(columns []string) ([]any, error) {
|
||||
values[i] = new(ent2.CustomTime)
|
||||
case cptask.FieldID, cptask.FieldCpUserID, cptask.FieldUserID, cptask.FieldFrequency, cptask.FieldSuccessCount, cptask.FieldExecuteHour, cptask.FieldExecuteMinute, cptask.FieldNextExecuteTime:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case cptask.FieldTaskType, cptask.FieldTitle, cptask.FieldTaskStatus, cptask.FieldFormData, cptask.FieldStep, cptask.FieldNotificationType:
|
||||
case cptask.FieldTaskType, cptask.FieldTitle, cptask.FieldTaskStatus, cptask.FieldFormData, cptask.FieldUsedImg, cptask.FieldStep, cptask.FieldNotificationType:
|
||||
values[i] = new(sql.NullString)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
@@ -192,6 +194,12 @@ func (_m *CpTask) assignValues(columns []string, values []any) error {
|
||||
} else if value.Valid {
|
||||
_m.FormData = value.String
|
||||
}
|
||||
case cptask.FieldUsedImg:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field used_img", values[i])
|
||||
} else if value.Valid {
|
||||
_m.UsedImg = value.String
|
||||
}
|
||||
case cptask.FieldStep:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field step", values[i])
|
||||
@@ -306,6 +314,9 @@ func (_m *CpTask) String() string {
|
||||
builder.WriteString("form_data=")
|
||||
builder.WriteString(_m.FormData)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("used_img=")
|
||||
builder.WriteString(_m.UsedImg)
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("step=")
|
||||
builder.WriteString(fmt.Sprintf("%v", _m.Step))
|
||||
builder.WriteString(", ")
|
||||
|
||||
@@ -36,6 +36,8 @@ const (
|
||||
FieldSuccessCount = "success_count"
|
||||
// FieldFormData holds the string denoting the form_data field in the database.
|
||||
FieldFormData = "form_data"
|
||||
// FieldUsedImg holds the string denoting the used_img field in the database.
|
||||
FieldUsedImg = "used_img"
|
||||
// FieldStep holds the string denoting the step field in the database.
|
||||
FieldStep = "step"
|
||||
// FieldNotificationType holds the string denoting the notification_type field in the database.
|
||||
@@ -90,6 +92,7 @@ var Columns = []string{
|
||||
FieldTaskStatus,
|
||||
FieldSuccessCount,
|
||||
FieldFormData,
|
||||
FieldUsedImg,
|
||||
FieldStep,
|
||||
FieldNotificationType,
|
||||
FieldExecuteHour,
|
||||
@@ -284,6 +287,11 @@ func ByFormData(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldFormData, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByUsedImg orders the results by the used_img field.
|
||||
func ByUsedImg(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldUsedImg, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByStep orders the results by the step field.
|
||||
func ByStep(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldStep, opts...).ToFunc()
|
||||
|
||||
@@ -96,6 +96,11 @@ func FormData(v string) predicate.CpTask {
|
||||
return predicate.CpTask(sql.FieldEQ(FieldFormData, v))
|
||||
}
|
||||
|
||||
// UsedImg applies equality check predicate on the "used_img" field. It's identical to UsedImgEQ.
|
||||
func UsedImg(v string) predicate.CpTask {
|
||||
return predicate.CpTask(sql.FieldEQ(FieldUsedImg, v))
|
||||
}
|
||||
|
||||
// ExecuteHour applies equality check predicate on the "execute_hour" field. It's identical to ExecuteHourEQ.
|
||||
func ExecuteHour(v int) predicate.CpTask {
|
||||
return predicate.CpTask(sql.FieldEQ(FieldExecuteHour, v))
|
||||
@@ -551,6 +556,81 @@ func FormDataContainsFold(v string) predicate.CpTask {
|
||||
return predicate.CpTask(sql.FieldContainsFold(FieldFormData, v))
|
||||
}
|
||||
|
||||
// UsedImgEQ applies the EQ predicate on the "used_img" field.
|
||||
func UsedImgEQ(v string) predicate.CpTask {
|
||||
return predicate.CpTask(sql.FieldEQ(FieldUsedImg, v))
|
||||
}
|
||||
|
||||
// UsedImgNEQ applies the NEQ predicate on the "used_img" field.
|
||||
func UsedImgNEQ(v string) predicate.CpTask {
|
||||
return predicate.CpTask(sql.FieldNEQ(FieldUsedImg, v))
|
||||
}
|
||||
|
||||
// UsedImgIn applies the In predicate on the "used_img" field.
|
||||
func UsedImgIn(vs ...string) predicate.CpTask {
|
||||
return predicate.CpTask(sql.FieldIn(FieldUsedImg, vs...))
|
||||
}
|
||||
|
||||
// UsedImgNotIn applies the NotIn predicate on the "used_img" field.
|
||||
func UsedImgNotIn(vs ...string) predicate.CpTask {
|
||||
return predicate.CpTask(sql.FieldNotIn(FieldUsedImg, vs...))
|
||||
}
|
||||
|
||||
// UsedImgGT applies the GT predicate on the "used_img" field.
|
||||
func UsedImgGT(v string) predicate.CpTask {
|
||||
return predicate.CpTask(sql.FieldGT(FieldUsedImg, v))
|
||||
}
|
||||
|
||||
// UsedImgGTE applies the GTE predicate on the "used_img" field.
|
||||
func UsedImgGTE(v string) predicate.CpTask {
|
||||
return predicate.CpTask(sql.FieldGTE(FieldUsedImg, v))
|
||||
}
|
||||
|
||||
// UsedImgLT applies the LT predicate on the "used_img" field.
|
||||
func UsedImgLT(v string) predicate.CpTask {
|
||||
return predicate.CpTask(sql.FieldLT(FieldUsedImg, v))
|
||||
}
|
||||
|
||||
// UsedImgLTE applies the LTE predicate on the "used_img" field.
|
||||
func UsedImgLTE(v string) predicate.CpTask {
|
||||
return predicate.CpTask(sql.FieldLTE(FieldUsedImg, v))
|
||||
}
|
||||
|
||||
// UsedImgContains applies the Contains predicate on the "used_img" field.
|
||||
func UsedImgContains(v string) predicate.CpTask {
|
||||
return predicate.CpTask(sql.FieldContains(FieldUsedImg, v))
|
||||
}
|
||||
|
||||
// UsedImgHasPrefix applies the HasPrefix predicate on the "used_img" field.
|
||||
func UsedImgHasPrefix(v string) predicate.CpTask {
|
||||
return predicate.CpTask(sql.FieldHasPrefix(FieldUsedImg, v))
|
||||
}
|
||||
|
||||
// UsedImgHasSuffix applies the HasSuffix predicate on the "used_img" field.
|
||||
func UsedImgHasSuffix(v string) predicate.CpTask {
|
||||
return predicate.CpTask(sql.FieldHasSuffix(FieldUsedImg, v))
|
||||
}
|
||||
|
||||
// UsedImgIsNil applies the IsNil predicate on the "used_img" field.
|
||||
func UsedImgIsNil() predicate.CpTask {
|
||||
return predicate.CpTask(sql.FieldIsNull(FieldUsedImg))
|
||||
}
|
||||
|
||||
// UsedImgNotNil applies the NotNil predicate on the "used_img" field.
|
||||
func UsedImgNotNil() predicate.CpTask {
|
||||
return predicate.CpTask(sql.FieldNotNull(FieldUsedImg))
|
||||
}
|
||||
|
||||
// UsedImgEqualFold applies the EqualFold predicate on the "used_img" field.
|
||||
func UsedImgEqualFold(v string) predicate.CpTask {
|
||||
return predicate.CpTask(sql.FieldEqualFold(FieldUsedImg, v))
|
||||
}
|
||||
|
||||
// UsedImgContainsFold applies the ContainsFold predicate on the "used_img" field.
|
||||
func UsedImgContainsFold(v string) predicate.CpTask {
|
||||
return predicate.CpTask(sql.FieldContainsFold(FieldUsedImg, v))
|
||||
}
|
||||
|
||||
// StepEQ applies the EQ predicate on the "step" field.
|
||||
func StepEQ(v Step) predicate.CpTask {
|
||||
return predicate.CpTask(sql.FieldEQ(FieldStep, v))
|
||||
|
||||
@@ -109,6 +109,20 @@ func (_c *CpTaskCreate) SetNillableFormData(v *string) *CpTaskCreate {
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetUsedImg sets the "used_img" field.
|
||||
func (_c *CpTaskCreate) SetUsedImg(v string) *CpTaskCreate {
|
||||
_c.mutation.SetUsedImg(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableUsedImg sets the "used_img" field if the given value is not nil.
|
||||
func (_c *CpTaskCreate) SetNillableUsedImg(v *string) *CpTaskCreate {
|
||||
if v != nil {
|
||||
_c.SetUsedImg(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetStep sets the "step" field.
|
||||
func (_c *CpTaskCreate) SetStep(v cptask.Step) *CpTaskCreate {
|
||||
_c.mutation.SetStep(v)
|
||||
@@ -382,6 +396,10 @@ func (_c *CpTaskCreate) createSpec() (*CpTask, *sqlgraph.CreateSpec) {
|
||||
_spec.SetField(cptask.FieldFormData, field.TypeString, value)
|
||||
_node.FormData = value
|
||||
}
|
||||
if value, ok := _c.mutation.UsedImg(); ok {
|
||||
_spec.SetField(cptask.FieldUsedImg, field.TypeString, value)
|
||||
_node.UsedImg = value
|
||||
}
|
||||
if value, ok := _c.mutation.Step(); ok {
|
||||
_spec.SetField(cptask.FieldStep, field.TypeEnum, value)
|
||||
_node.Step = value
|
||||
@@ -633,6 +651,24 @@ func (u *CpTaskUpsert) ClearFormData() *CpTaskUpsert {
|
||||
return u
|
||||
}
|
||||
|
||||
// SetUsedImg sets the "used_img" field.
|
||||
func (u *CpTaskUpsert) SetUsedImg(v string) *CpTaskUpsert {
|
||||
u.Set(cptask.FieldUsedImg, v)
|
||||
return u
|
||||
}
|
||||
|
||||
// UpdateUsedImg sets the "used_img" field to the value that was provided on create.
|
||||
func (u *CpTaskUpsert) UpdateUsedImg() *CpTaskUpsert {
|
||||
u.SetExcluded(cptask.FieldUsedImg)
|
||||
return u
|
||||
}
|
||||
|
||||
// ClearUsedImg clears the value of the "used_img" field.
|
||||
func (u *CpTaskUpsert) ClearUsedImg() *CpTaskUpsert {
|
||||
u.SetNull(cptask.FieldUsedImg)
|
||||
return u
|
||||
}
|
||||
|
||||
// SetStep sets the "step" field.
|
||||
func (u *CpTaskUpsert) SetStep(v cptask.Step) *CpTaskUpsert {
|
||||
u.Set(cptask.FieldStep, v)
|
||||
@@ -921,6 +957,27 @@ func (u *CpTaskUpsertOne) ClearFormData() *CpTaskUpsertOne {
|
||||
})
|
||||
}
|
||||
|
||||
// SetUsedImg sets the "used_img" field.
|
||||
func (u *CpTaskUpsertOne) SetUsedImg(v string) *CpTaskUpsertOne {
|
||||
return u.Update(func(s *CpTaskUpsert) {
|
||||
s.SetUsedImg(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateUsedImg sets the "used_img" field to the value that was provided on create.
|
||||
func (u *CpTaskUpsertOne) UpdateUsedImg() *CpTaskUpsertOne {
|
||||
return u.Update(func(s *CpTaskUpsert) {
|
||||
s.UpdateUsedImg()
|
||||
})
|
||||
}
|
||||
|
||||
// ClearUsedImg clears the value of the "used_img" field.
|
||||
func (u *CpTaskUpsertOne) ClearUsedImg() *CpTaskUpsertOne {
|
||||
return u.Update(func(s *CpTaskUpsert) {
|
||||
s.ClearUsedImg()
|
||||
})
|
||||
}
|
||||
|
||||
// SetStep sets the "step" field.
|
||||
func (u *CpTaskUpsertOne) SetStep(v cptask.Step) *CpTaskUpsertOne {
|
||||
return u.Update(func(s *CpTaskUpsert) {
|
||||
@@ -1391,6 +1448,27 @@ func (u *CpTaskUpsertBulk) ClearFormData() *CpTaskUpsertBulk {
|
||||
})
|
||||
}
|
||||
|
||||
// SetUsedImg sets the "used_img" field.
|
||||
func (u *CpTaskUpsertBulk) SetUsedImg(v string) *CpTaskUpsertBulk {
|
||||
return u.Update(func(s *CpTaskUpsert) {
|
||||
s.SetUsedImg(v)
|
||||
})
|
||||
}
|
||||
|
||||
// UpdateUsedImg sets the "used_img" field to the value that was provided on create.
|
||||
func (u *CpTaskUpsertBulk) UpdateUsedImg() *CpTaskUpsertBulk {
|
||||
return u.Update(func(s *CpTaskUpsert) {
|
||||
s.UpdateUsedImg()
|
||||
})
|
||||
}
|
||||
|
||||
// ClearUsedImg clears the value of the "used_img" field.
|
||||
func (u *CpTaskUpsertBulk) ClearUsedImg() *CpTaskUpsertBulk {
|
||||
return u.Update(func(s *CpTaskUpsert) {
|
||||
s.ClearUsedImg()
|
||||
})
|
||||
}
|
||||
|
||||
// SetStep sets the "step" field.
|
||||
func (u *CpTaskUpsertBulk) SetStep(v cptask.Step) *CpTaskUpsertBulk {
|
||||
return u.Update(func(s *CpTaskUpsert) {
|
||||
|
||||
@@ -171,6 +171,26 @@ func (_u *CpTaskUpdate) ClearFormData() *CpTaskUpdate {
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUsedImg sets the "used_img" field.
|
||||
func (_u *CpTaskUpdate) SetUsedImg(v string) *CpTaskUpdate {
|
||||
_u.mutation.SetUsedImg(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableUsedImg sets the "used_img" field if the given value is not nil.
|
||||
func (_u *CpTaskUpdate) SetNillableUsedImg(v *string) *CpTaskUpdate {
|
||||
if v != nil {
|
||||
_u.SetUsedImg(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearUsedImg clears the value of the "used_img" field.
|
||||
func (_u *CpTaskUpdate) ClearUsedImg() *CpTaskUpdate {
|
||||
_u.mutation.ClearUsedImg()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetStep sets the "step" field.
|
||||
func (_u *CpTaskUpdate) SetStep(v cptask.Step) *CpTaskUpdate {
|
||||
_u.mutation.SetStep(v)
|
||||
@@ -460,6 +480,12 @@ func (_u *CpTaskUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
if _u.mutation.FormDataCleared() {
|
||||
_spec.ClearField(cptask.FieldFormData, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.UsedImg(); ok {
|
||||
_spec.SetField(cptask.FieldUsedImg, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.UsedImgCleared() {
|
||||
_spec.ClearField(cptask.FieldUsedImg, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.Step(); ok {
|
||||
_spec.SetField(cptask.FieldStep, field.TypeEnum, value)
|
||||
}
|
||||
@@ -765,6 +791,26 @@ func (_u *CpTaskUpdateOne) ClearFormData() *CpTaskUpdateOne {
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUsedImg sets the "used_img" field.
|
||||
func (_u *CpTaskUpdateOne) SetUsedImg(v string) *CpTaskUpdateOne {
|
||||
_u.mutation.SetUsedImg(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableUsedImg sets the "used_img" field if the given value is not nil.
|
||||
func (_u *CpTaskUpdateOne) SetNillableUsedImg(v *string) *CpTaskUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetUsedImg(*v)
|
||||
}
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearUsedImg clears the value of the "used_img" field.
|
||||
func (_u *CpTaskUpdateOne) ClearUsedImg() *CpTaskUpdateOne {
|
||||
_u.mutation.ClearUsedImg()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetStep sets the "step" field.
|
||||
func (_u *CpTaskUpdateOne) SetStep(v cptask.Step) *CpTaskUpdateOne {
|
||||
_u.mutation.SetStep(v)
|
||||
@@ -1084,6 +1130,12 @@ func (_u *CpTaskUpdateOne) sqlSave(ctx context.Context) (_node *CpTask, err erro
|
||||
if _u.mutation.FormDataCleared() {
|
||||
_spec.ClearField(cptask.FieldFormData, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.UsedImg(); ok {
|
||||
_spec.SetField(cptask.FieldUsedImg, field.TypeString, value)
|
||||
}
|
||||
if _u.mutation.UsedImgCleared() {
|
||||
_spec.ClearField(cptask.FieldUsedImg, field.TypeString)
|
||||
}
|
||||
if value, ok := _u.mutation.Step(); ok {
|
||||
_spec.SetField(cptask.FieldStep, field.TypeEnum, value)
|
||||
}
|
||||
|
||||
@@ -84,6 +84,7 @@ var schemaGraph = func() *sqlgraph.Schema {
|
||||
cptask.FieldTaskStatus: {Type: field.TypeEnum, Column: cptask.FieldTaskStatus},
|
||||
cptask.FieldSuccessCount: {Type: field.TypeInt, Column: cptask.FieldSuccessCount},
|
||||
cptask.FieldFormData: {Type: field.TypeString, Column: cptask.FieldFormData},
|
||||
cptask.FieldUsedImg: {Type: field.TypeString, Column: cptask.FieldUsedImg},
|
||||
cptask.FieldStep: {Type: field.TypeEnum, Column: cptask.FieldStep},
|
||||
cptask.FieldNotificationType: {Type: field.TypeEnum, Column: cptask.FieldNotificationType},
|
||||
cptask.FieldExecuteHour: {Type: field.TypeInt, Column: cptask.FieldExecuteHour},
|
||||
@@ -905,6 +906,11 @@ func (f *CpTaskFilter) WhereFormData(p entql.StringP) {
|
||||
f.Where(p.Field(cptask.FieldFormData))
|
||||
}
|
||||
|
||||
// WhereUsedImg applies the entql string predicate on the used_img field.
|
||||
func (f *CpTaskFilter) WhereUsedImg(p entql.StringP) {
|
||||
f.Where(p.Field(cptask.FieldUsedImg))
|
||||
}
|
||||
|
||||
// WhereStep applies the entql string predicate on the step field.
|
||||
func (f *CpTaskFilter) WhereStep(p entql.StringP) {
|
||||
f.Where(p.Field(cptask.FieldStep))
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -60,6 +60,7 @@ var (
|
||||
{Name: "task_status", Type: field.TypeEnum, Enums: []string{"not_start", "doing", "done", "fail", "pause", "queue", "unknown"}},
|
||||
{Name: "success_count", Type: field.TypeInt, Default: 0},
|
||||
{Name: "form_data", Type: field.TypeString, Nullable: true, Size: 2147483647},
|
||||
{Name: "used_img", Type: field.TypeString, Nullable: true},
|
||||
{Name: "step", Type: field.TypeEnum, Enums: []string{"form", "execute", "complete"}},
|
||||
{Name: "notification_type", Type: field.TypeEnum, Enums: []string{"none", "cp_user_email", "system_user_email"}},
|
||||
{Name: "execute_hour", Type: field.TypeInt, Nullable: true},
|
||||
@@ -76,13 +77,13 @@ var (
|
||||
ForeignKeys: []*schema.ForeignKey{
|
||||
{
|
||||
Symbol: "cp_tasks_cp_users_cptasks",
|
||||
Columns: []*schema.Column{CpTasksColumns[14]},
|
||||
Columns: []*schema.Column{CpTasksColumns[15]},
|
||||
RefColumns: []*schema.Column{CpUsersColumns[0]},
|
||||
OnDelete: schema.NoAction,
|
||||
},
|
||||
{
|
||||
Symbol: "cp_tasks_sys_user_cp_task",
|
||||
Columns: []*schema.Column{CpTasksColumns[15]},
|
||||
Columns: []*schema.Column{CpTasksColumns[16]},
|
||||
RefColumns: []*schema.Column{SysUserColumns[0]},
|
||||
OnDelete: schema.Cascade,
|
||||
},
|
||||
|
||||
@@ -1467,6 +1467,7 @@ type CpTaskMutation struct {
|
||||
success_count *int
|
||||
addsuccess_count *int
|
||||
form_data *string
|
||||
used_img *string
|
||||
step *cptask.Step
|
||||
notification_type *cptask.NotificationType
|
||||
execute_hour *int
|
||||
@@ -1999,6 +2000,55 @@ func (m *CpTaskMutation) ResetFormData() {
|
||||
delete(m.clearedFields, cptask.FieldFormData)
|
||||
}
|
||||
|
||||
// SetUsedImg sets the "used_img" field.
|
||||
func (m *CpTaskMutation) SetUsedImg(s string) {
|
||||
m.used_img = &s
|
||||
}
|
||||
|
||||
// UsedImg returns the value of the "used_img" field in the mutation.
|
||||
func (m *CpTaskMutation) UsedImg() (r string, exists bool) {
|
||||
v := m.used_img
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldUsedImg returns the old "used_img" field's value of the CpTask entity.
|
||||
// If the CpTask object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *CpTaskMutation) OldUsedImg(ctx context.Context) (v string, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldUsedImg is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldUsedImg requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldUsedImg: %w", err)
|
||||
}
|
||||
return oldValue.UsedImg, nil
|
||||
}
|
||||
|
||||
// ClearUsedImg clears the value of the "used_img" field.
|
||||
func (m *CpTaskMutation) ClearUsedImg() {
|
||||
m.used_img = nil
|
||||
m.clearedFields[cptask.FieldUsedImg] = struct{}{}
|
||||
}
|
||||
|
||||
// UsedImgCleared returns if the "used_img" field was cleared in this mutation.
|
||||
func (m *CpTaskMutation) UsedImgCleared() bool {
|
||||
_, ok := m.clearedFields[cptask.FieldUsedImg]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ResetUsedImg resets all changes to the "used_img" field.
|
||||
func (m *CpTaskMutation) ResetUsedImg() {
|
||||
m.used_img = nil
|
||||
delete(m.clearedFields, cptask.FieldUsedImg)
|
||||
}
|
||||
|
||||
// SetStep sets the "step" field.
|
||||
func (m *CpTaskMutation) SetStep(c cptask.Step) {
|
||||
m.step = &c
|
||||
@@ -2436,7 +2486,7 @@ func (m *CpTaskMutation) Type() string {
|
||||
// order to get all numeric fields that were incremented/decremented, call
|
||||
// AddedFields().
|
||||
func (m *CpTaskMutation) Fields() []string {
|
||||
fields := make([]string, 0, 15)
|
||||
fields := make([]string, 0, 16)
|
||||
if m.create_time != nil {
|
||||
fields = append(fields, cptask.FieldCreateTime)
|
||||
}
|
||||
@@ -2467,6 +2517,9 @@ func (m *CpTaskMutation) Fields() []string {
|
||||
if m.form_data != nil {
|
||||
fields = append(fields, cptask.FieldFormData)
|
||||
}
|
||||
if m.used_img != nil {
|
||||
fields = append(fields, cptask.FieldUsedImg)
|
||||
}
|
||||
if m.step != nil {
|
||||
fields = append(fields, cptask.FieldStep)
|
||||
}
|
||||
@@ -2510,6 +2563,8 @@ func (m *CpTaskMutation) Field(name string) (ent.Value, bool) {
|
||||
return m.SuccessCount()
|
||||
case cptask.FieldFormData:
|
||||
return m.FormData()
|
||||
case cptask.FieldUsedImg:
|
||||
return m.UsedImg()
|
||||
case cptask.FieldStep:
|
||||
return m.Step()
|
||||
case cptask.FieldNotificationType:
|
||||
@@ -2549,6 +2604,8 @@ func (m *CpTaskMutation) OldField(ctx context.Context, name string) (ent.Value,
|
||||
return m.OldSuccessCount(ctx)
|
||||
case cptask.FieldFormData:
|
||||
return m.OldFormData(ctx)
|
||||
case cptask.FieldUsedImg:
|
||||
return m.OldUsedImg(ctx)
|
||||
case cptask.FieldStep:
|
||||
return m.OldStep(ctx)
|
||||
case cptask.FieldNotificationType:
|
||||
@@ -2638,6 +2695,13 @@ func (m *CpTaskMutation) SetField(name string, value ent.Value) error {
|
||||
}
|
||||
m.SetFormData(v)
|
||||
return nil
|
||||
case cptask.FieldUsedImg:
|
||||
v, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetUsedImg(v)
|
||||
return nil
|
||||
case cptask.FieldStep:
|
||||
v, ok := value.(cptask.Step)
|
||||
if !ok {
|
||||
@@ -2769,6 +2833,9 @@ func (m *CpTaskMutation) ClearedFields() []string {
|
||||
if m.FieldCleared(cptask.FieldFormData) {
|
||||
fields = append(fields, cptask.FieldFormData)
|
||||
}
|
||||
if m.FieldCleared(cptask.FieldUsedImg) {
|
||||
fields = append(fields, cptask.FieldUsedImg)
|
||||
}
|
||||
if m.FieldCleared(cptask.FieldExecuteHour) {
|
||||
fields = append(fields, cptask.FieldExecuteHour)
|
||||
}
|
||||
@@ -2795,6 +2862,9 @@ func (m *CpTaskMutation) ClearField(name string) error {
|
||||
case cptask.FieldFormData:
|
||||
m.ClearFormData()
|
||||
return nil
|
||||
case cptask.FieldUsedImg:
|
||||
m.ClearUsedImg()
|
||||
return nil
|
||||
case cptask.FieldExecuteHour:
|
||||
m.ClearExecuteHour()
|
||||
return nil
|
||||
@@ -2842,6 +2912,9 @@ func (m *CpTaskMutation) ResetField(name string) error {
|
||||
case cptask.FieldFormData:
|
||||
m.ResetFormData()
|
||||
return nil
|
||||
case cptask.FieldUsedImg:
|
||||
m.ResetUsedImg()
|
||||
return nil
|
||||
case cptask.FieldStep:
|
||||
m.ResetStep()
|
||||
return nil
|
||||
|
||||
@@ -25,6 +25,7 @@ func (CpTask) Fields() []ent.Field {
|
||||
field.Enum("task_status").Values("not_start", "doing", "done", "fail", "pause", "queue", "unknown"),
|
||||
field.Int("success_count").Default(0),
|
||||
field.Text("form_data").Optional(),
|
||||
field.String("used_img").Optional(),
|
||||
field.Enum("step").Values("form", "execute", "complete"),
|
||||
field.Enum("notification_type").Values("none", "cp_user_email", "system_user_email"),
|
||||
field.Int("execute_hour").Optional().Nillable(),
|
||||
|
||||
@@ -18,6 +18,8 @@ import (
|
||||
"likedream-goframe/internal/framework/model/email"
|
||||
email2 "likedream-goframe/internal/service/email"
|
||||
"likedream-goframe/internal/utils"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/bytedance/sonic"
|
||||
@@ -131,13 +133,14 @@ func (c *CpdailyTaskHandler) ProcessTask(ctx context.Context, task *asynq.Task)
|
||||
default:
|
||||
utils.OkOrPanic(errors.NewBusinessErrorWithDetail(503, "不支持的设备类型", targetTask.Edges.CpUser.MobileType))
|
||||
}
|
||||
|
||||
submitForm := taskExecutor.FillCustomForm(ctx, cpdailyRealTask, customFormItems, deviceID, targetTask.Edges.CpUser.Username)
|
||||
// 固定获取图片id
|
||||
imgId := GetNextImgId(customFormItems, targetTask.UsedImg)
|
||||
submitForm := taskExecutor.FillCustomForm(ctx, cpdailyRealTask, customFormItems, deviceID, imgId)
|
||||
taskExecutor.Submit(ctx, submitForm, targetTask.Edges.CpUser.Username, deviceID)
|
||||
|
||||
// 任务完成后重置状态为 TaskStatusDone,更新下次执行时间 以便下次继续执行
|
||||
executeTime := utils.GetCpdailyNextExecuteTime(targetTask)
|
||||
db.Global.CpTask.UpdateOneID(taskPayload.CpTaskID).SetTaskStatus(cptask.TaskStatusDone).SetNextExecuteTime(executeTime).AddSuccessCount(1).ExecX(ctx)
|
||||
db.Global.CpTask.UpdateOneID(taskPayload.CpTaskID).SetTaskStatus(cptask.TaskStatusDone).SetUsedImg(imgId).SetNextExecuteTime(executeTime).AddSuccessCount(1).ExecX(ctx)
|
||||
|
||||
// 创建日志
|
||||
db.Global.CpTaskLog.Create().
|
||||
@@ -157,6 +160,26 @@ func (c *CpdailyTaskHandler) ProcessTask(ctx context.Context, task *asynq.Task)
|
||||
|
||||
return
|
||||
}
|
||||
func GetNextImgId(forms []*formtype.CpTaskFormItem, imgId string) string {
|
||||
var allImgIds []string
|
||||
for _, item := range forms {
|
||||
if item.ColName == "signImg" {
|
||||
allImgIds = strings.Split(item.Content, ",")
|
||||
break
|
||||
}
|
||||
}
|
||||
if len(allImgIds) == 0 {
|
||||
return ""
|
||||
}
|
||||
if imgId == "" {
|
||||
return allImgIds[0]
|
||||
}
|
||||
index := slices.Index(allImgIds, imgId)
|
||||
if index == -1 || index == len(allImgIds)-1 {
|
||||
return allImgIds[0]
|
||||
}
|
||||
return allImgIds[index+1]
|
||||
}
|
||||
|
||||
// sendTaskNotificationEmail 发送任务通知邮件
|
||||
func (c *CpdailyTaskHandler) sendTaskNotificationEmail(ctx context.Context, task *ent.CpTask, status email.TaskStatus, details map[string]string) {
|
||||
|
||||
Reference in New Issue
Block a user