Răsfoiți Sursa

增加batch_msg的curd api

DESKTOP-53URE31\USER 8 luni în urmă
părinte
comite
c9e54ad129

+ 2 - 1
desc/all.api

@@ -11,4 +11,5 @@ import "./wechat/sop_stage.api"
 import "./wechat/sop_node.api"
 import "./wechat/message_records.api"
 import "./wechat/chatroom_member.api"
-import "./openapi/contact.api"
+import "./openapi/contact.api"
+import "./wechat/batch_msg.api"

+ 104 - 0
desc/wechat/batch_msg.api

@@ -0,0 +1,104 @@
+import "../base.api"
+
+type (
+    // The data of batch msg information | BatchMsg信息
+    BatchMsgInfo {
+        BaseIDInfo
+
+        // 状态 0 未开始 1 开始发送 2 发送完成 3 发送中止 
+        Status  *uint8 `json:"status,optional"`
+
+        // 批次号 
+        BatchNo  *string `json:"batchNo,optional"`
+
+        // 发送方微信ID 
+        Fromwxid  *string `json:"fromwxid,optional"`
+
+        // 内容 
+        Msg  *string `json:"msg,optional"`
+
+        // 发送规则 all 全部 tag1,tag2 按tag发送 
+        Tag  *string `json:"tag,optional"`
+
+        // 总数 
+        Total  *int32 `json:"total,optional"`
+
+        // 成功数量 
+        Success  *int32 `json:"success,optional"`
+
+        // 失败数量 
+        Fail  *int32 `json:"fail,optional"`
+
+        // 开始时间 
+        StartTime  *int64 `json:"startTime,optional"`
+
+        // 结束时间 
+        StopTime  *int64 `json:"stopTime,optional"`
+    }
+
+    // The response data of batch msg list | BatchMsg列表数据
+    BatchMsgListResp {
+        BaseDataInfo
+
+        // BatchMsg list data | BatchMsg列表数据
+        Data BatchMsgListInfo `json:"data"`
+    }
+
+    // BatchMsg list data | BatchMsg列表数据
+    BatchMsgListInfo {
+        BaseListInfo
+
+        // The API list data | BatchMsg列表数据
+        Data  []BatchMsgInfo  `json:"data"`
+    }
+
+    // Get batch msg list request params | BatchMsg列表请求参数
+    BatchMsgListReq {
+        PageInfo
+
+        // 批次号 
+        BatchNo  *string `json:"batchNo,optional"`
+
+        // 发送方微信ID 
+        Fromwxid  *string `json:"fromwxid,optional"`
+
+        // 内容 
+        Msg  *string `json:"msg,optional"`
+    }
+
+    // BatchMsg information response | BatchMsg信息返回体
+    BatchMsgInfoResp {
+        BaseDataInfo
+
+        // BatchMsg information | BatchMsg数据
+        Data BatchMsgInfo `json:"data"`
+    }
+)
+
+@server(
+    jwt: Auth
+    group: batch_msg
+    middleware: Authority
+)
+
+service Wechat {
+    // Create batch msg information | 创建BatchMsg
+    @handler createBatchMsg
+    post /batch_msg/create (BatchMsgInfo) returns (BaseMsgResp)
+
+    // Update batch msg information | 更新BatchMsg
+    @handler updateBatchMsg
+    post /batch_msg/update (BatchMsgInfo) returns (BaseMsgResp)
+
+    // Delete batch msg information | 删除BatchMsg信息
+    @handler deleteBatchMsg
+    post /batch_msg/delete (IDsReq) returns (BaseMsgResp)
+
+    // Get batch msg list | 获取BatchMsg列表
+    @handler getBatchMsgList
+    post /batch_msg/list (BatchMsgListReq) returns (BatchMsgListResp)
+
+    // Get batch msg by ID | 通过ID获取BatchMsg
+    @handler getBatchMsgById
+    post /batch_msg (IDReq) returns (BatchMsgInfoResp)
+}

+ 44 - 0
internal/handler/batch_msg/create_batch_msg_handler.go

@@ -0,0 +1,44 @@
+package batch_msg
+
+import (
+	"net/http"
+
+	"github.com/zeromicro/go-zero/rest/httpx"
+
+	"wechat-api/internal/logic/batch_msg"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+)
+
+// swagger:route post /batch_msg/create batch_msg CreateBatchMsg
+//
+// Create batch msg information | 创建BatchMsg
+//
+// Create batch msg information | 创建BatchMsg
+//
+// Parameters:
+//  + name: body
+//    require: true
+//    in: body
+//    type: BatchMsgInfo
+//
+// Responses:
+//  200: BaseMsgResp
+
+func CreateBatchMsgHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.BatchMsgInfo
+		if err := httpx.Parse(r, &req, true); err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+			return
+		}
+
+		l := batch_msg.NewCreateBatchMsgLogic(r.Context(), svcCtx)
+		resp, err := l.CreateBatchMsg(&req)
+		if err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+		} else {
+			httpx.OkJsonCtx(r.Context(), w, resp)
+		}
+	}
+}

+ 44 - 0
internal/handler/batch_msg/delete_batch_msg_handler.go

@@ -0,0 +1,44 @@
+package batch_msg
+
+import (
+	"net/http"
+
+	"github.com/zeromicro/go-zero/rest/httpx"
+
+	"wechat-api/internal/logic/batch_msg"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+)
+
+// swagger:route post /batch_msg/delete batch_msg DeleteBatchMsg
+//
+// Delete batch msg information | 删除BatchMsg信息
+//
+// Delete batch msg information | 删除BatchMsg信息
+//
+// Parameters:
+//  + name: body
+//    require: true
+//    in: body
+//    type: IDsReq
+//
+// Responses:
+//  200: BaseMsgResp
+
+func DeleteBatchMsgHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.IDsReq
+		if err := httpx.Parse(r, &req, true); err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+			return
+		}
+
+		l := batch_msg.NewDeleteBatchMsgLogic(r.Context(), svcCtx)
+		resp, err := l.DeleteBatchMsg(&req)
+		if err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+		} else {
+			httpx.OkJsonCtx(r.Context(), w, resp)
+		}
+	}
+}

+ 44 - 0
internal/handler/batch_msg/get_batch_msg_by_id_handler.go

@@ -0,0 +1,44 @@
+package batch_msg
+
+import (
+	"net/http"
+
+	"github.com/zeromicro/go-zero/rest/httpx"
+
+	"wechat-api/internal/logic/batch_msg"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+)
+
+// swagger:route post /batch_msg batch_msg GetBatchMsgById
+//
+// Get batch msg by ID | 通过ID获取BatchMsg
+//
+// Get batch msg by ID | 通过ID获取BatchMsg
+//
+// Parameters:
+//  + name: body
+//    require: true
+//    in: body
+//    type: IDReq
+//
+// Responses:
+//  200: BatchMsgInfoResp
+
+func GetBatchMsgByIdHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.IDReq
+		if err := httpx.Parse(r, &req, true); err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+			return
+		}
+
+		l := batch_msg.NewGetBatchMsgByIdLogic(r.Context(), svcCtx)
+		resp, err := l.GetBatchMsgById(&req)
+		if err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+		} else {
+			httpx.OkJsonCtx(r.Context(), w, resp)
+		}
+	}
+}

+ 44 - 0
internal/handler/batch_msg/get_batch_msg_list_handler.go

@@ -0,0 +1,44 @@
+package batch_msg
+
+import (
+	"net/http"
+
+	"github.com/zeromicro/go-zero/rest/httpx"
+
+	"wechat-api/internal/logic/batch_msg"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+)
+
+// swagger:route post /batch_msg/list batch_msg GetBatchMsgList
+//
+// Get batch msg list | 获取BatchMsg列表
+//
+// Get batch msg list | 获取BatchMsg列表
+//
+// Parameters:
+//  + name: body
+//    require: true
+//    in: body
+//    type: BatchMsgListReq
+//
+// Responses:
+//  200: BatchMsgListResp
+
+func GetBatchMsgListHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.BatchMsgListReq
+		if err := httpx.Parse(r, &req, true); err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+			return
+		}
+
+		l := batch_msg.NewGetBatchMsgListLogic(r.Context(), svcCtx)
+		resp, err := l.GetBatchMsgList(&req)
+		if err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+		} else {
+			httpx.OkJsonCtx(r.Context(), w, resp)
+		}
+	}
+}

+ 44 - 0
internal/handler/batch_msg/update_batch_msg_handler.go

@@ -0,0 +1,44 @@
+package batch_msg
+
+import (
+	"net/http"
+
+	"github.com/zeromicro/go-zero/rest/httpx"
+
+	"wechat-api/internal/logic/batch_msg"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+)
+
+// swagger:route post /batch_msg/update batch_msg UpdateBatchMsg
+//
+// Update batch msg information | 更新BatchMsg
+//
+// Update batch msg information | 更新BatchMsg
+//
+// Parameters:
+//  + name: body
+//    require: true
+//    in: body
+//    type: BatchMsgInfo
+//
+// Responses:
+//  200: BaseMsgResp
+
+func UpdateBatchMsgHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.BatchMsgInfo
+		if err := httpx.Parse(r, &req, true); err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+			return
+		}
+
+		l := batch_msg.NewUpdateBatchMsgLogic(r.Context(), svcCtx)
+		resp, err := l.UpdateBatchMsg(&req)
+		if err != nil {
+			httpx.ErrorCtx(r.Context(), w, err)
+		} else {
+			httpx.OkJsonCtx(r.Context(), w, resp)
+		}
+	}
+}

+ 35 - 0
internal/handler/routes.go

@@ -10,6 +10,7 @@ import (
 	Wx "wechat-api/internal/handler/Wx"
 	Wxhook "wechat-api/internal/handler/Wxhook"
 	base "wechat-api/internal/handler/base"
+	batch_msg "wechat-api/internal/handler/batch_msg"
 	contact "wechat-api/internal/handler/contact"
 	label "wechat-api/internal/handler/label"
 	label_relationship "wechat-api/internal/handler/label_relationship"
@@ -497,4 +498,38 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 		},
 		rest.WithPrefix("/openapi"),
 	)
+
+	server.AddRoutes(
+		rest.WithMiddlewares(
+			[]rest.Middleware{serverCtx.Authority},
+			[]rest.Route{
+				{
+					Method:  http.MethodPost,
+					Path:    "/batch_msg/create",
+					Handler: batch_msg.CreateBatchMsgHandler(serverCtx),
+				},
+				{
+					Method:  http.MethodPost,
+					Path:    "/batch_msg/update",
+					Handler: batch_msg.UpdateBatchMsgHandler(serverCtx),
+				},
+				{
+					Method:  http.MethodPost,
+					Path:    "/batch_msg/delete",
+					Handler: batch_msg.DeleteBatchMsgHandler(serverCtx),
+				},
+				{
+					Method:  http.MethodPost,
+					Path:    "/batch_msg/list",
+					Handler: batch_msg.GetBatchMsgListHandler(serverCtx),
+				},
+				{
+					Method:  http.MethodPost,
+					Path:    "/batch_msg",
+					Handler: batch_msg.GetBatchMsgByIdHandler(serverCtx),
+				},
+			}...,
+		),
+		rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
+	)
 }

+ 62 - 0
internal/logic/base/init_api_data.go

@@ -6,6 +6,68 @@ import (
 )
 
 func (l *InitDatabaseLogic) insertApiData() (err error) {
+	// BatchMsg
+
+	_, err = l.svcCtx.CoreRpc.CreateApi(l.ctx, &core.ApiInfo{
+		ServiceName: pointy.GetPointer("Wechat"),
+		Path:        pointy.GetPointer("/batch_msg/create"),
+		Description: pointy.GetPointer("apiDesc.createBatchMsg"),
+		ApiGroup:    pointy.GetPointer("batch_msg"),
+		Method:      pointy.GetPointer("POST"),
+	})
+
+	if err != nil {
+		return err
+	}
+
+	_, err = l.svcCtx.CoreRpc.CreateApi(l.ctx, &core.ApiInfo{
+		ServiceName: pointy.GetPointer("Wechat"),
+		Path:        pointy.GetPointer("/batch_msg/update"),
+		Description: pointy.GetPointer("apiDesc.updateBatchMsg"),
+		ApiGroup:    pointy.GetPointer("batch_msg"),
+		Method:      pointy.GetPointer("POST"),
+	})
+
+	if err != nil {
+		return err
+	}
+
+	_, err = l.svcCtx.CoreRpc.CreateApi(l.ctx, &core.ApiInfo{
+		ServiceName: pointy.GetPointer("Wechat"),
+		Path:        pointy.GetPointer("/batch_msg/delete"),
+		Description: pointy.GetPointer("apiDesc.deleteBatchMsg"),
+		ApiGroup:    pointy.GetPointer("batch_msg"),
+		Method:      pointy.GetPointer("POST"),
+	})
+
+	if err != nil {
+		return err
+	}
+
+	_, err = l.svcCtx.CoreRpc.CreateApi(l.ctx, &core.ApiInfo{
+		ServiceName: pointy.GetPointer("Wechat"),
+		Path:        pointy.GetPointer("/batch_msg/list"),
+		Description: pointy.GetPointer("apiDesc.getBatchMsgList"),
+		ApiGroup:    pointy.GetPointer("batch_msg"),
+		Method:      pointy.GetPointer("POST"),
+	})
+
+	if err != nil {
+		return err
+	}
+
+	_, err = l.svcCtx.CoreRpc.CreateApi(l.ctx, &core.ApiInfo{
+		ServiceName: pointy.GetPointer("Wechat"),
+		Path:        pointy.GetPointer("/batch_msg"),
+		Description: pointy.GetPointer("apiDesc.getBatchMsgById"),
+		ApiGroup:    pointy.GetPointer("batch_msg"),
+		Method:      pointy.GetPointer("POST"),
+	})
+
+	if err != nil {
+		return err
+	}
+
 	// MessageRecords
 
 	_, err = l.svcCtx.CoreRpc.CreateApi(l.ctx, &core.ApiInfo{

+ 48 - 0
internal/logic/batch_msg/create_batch_msg_logic.go

@@ -0,0 +1,48 @@
+package batch_msg
+
+import (
+	"context"
+
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+	"wechat-api/internal/utils/dberrorhandler"
+
+    "github.com/suyuan32/simple-admin-common/msg/errormsg"
+    "github.com/suyuan32/simple-admin-common/utils/pointy"
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type CreateBatchMsgLogic struct {
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+	logx.Logger
+}
+
+func NewCreateBatchMsgLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateBatchMsgLogic {
+	return &CreateBatchMsgLogic{
+		ctx:    ctx,
+		svcCtx: svcCtx,
+		Logger: logx.WithContext(ctx),
+	}
+}
+
+func (l *CreateBatchMsgLogic) CreateBatchMsg(req *types.BatchMsgInfo) (*types.BaseMsgResp, error) {
+    _, err := l.svcCtx.DB.BatchMsg.Create().
+			SetNotNilStatus(req.Status).
+			SetNotNilBatchNo(req.BatchNo).
+			SetNotNilFromwxid(req.Fromwxid).
+			SetNotNilMsg(req.Msg).
+			SetNotNilTag(req.Tag).
+			SetNotNilTotal(req.Total).
+			SetNotNilSuccess(req.Success).
+			SetNotNilFail(req.Fail).
+			SetNotNilStartTime(pointy.GetTimeMilliPointer(req.StartTime)).
+			SetNotNilStopTime(pointy.GetTimeMilliPointer(req.StopTime)).
+			Save(l.ctx)
+
+    if err != nil {
+		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
+	}
+
+    return &types.BaseMsgResp{Msg: errormsg.CreateSuccess}, nil
+}

+ 37 - 0
internal/logic/batch_msg/delete_batch_msg_logic.go

@@ -0,0 +1,37 @@
+package batch_msg
+
+import (
+	"context"
+
+    "wechat-api/ent/batchmsg"
+    "wechat-api/internal/svc"
+    "wechat-api/internal/types"
+    "wechat-api/internal/utils/dberrorhandler"
+
+    "github.com/suyuan32/simple-admin-common/msg/errormsg"
+    "github.com/zeromicro/go-zero/core/logx"
+)
+
+type DeleteBatchMsgLogic struct {
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+	logx.Logger
+}
+
+func NewDeleteBatchMsgLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteBatchMsgLogic {
+	return &DeleteBatchMsgLogic{
+		ctx:    ctx,
+		svcCtx: svcCtx,
+		Logger: logx.WithContext(ctx),
+	}
+}
+
+func (l *DeleteBatchMsgLogic) DeleteBatchMsg(req *types.IDsReq) (*types.BaseMsgResp, error) {
+	_, err := l.svcCtx.DB.BatchMsg.Delete().Where(batchmsg.IDIn(req.Ids...)).Exec(l.ctx)
+
+    if err != nil {
+		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
+	}
+
+    return &types.BaseMsgResp{Msg: errormsg.DeleteSuccess}, nil
+}

+ 60 - 0
internal/logic/batch_msg/get_batch_msg_by_id_logic.go

@@ -0,0 +1,60 @@
+package batch_msg
+
+import (
+	"context"
+
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+	"wechat-api/internal/utils/dberrorhandler"
+
+    "github.com/suyuan32/simple-admin-common/msg/errormsg"
+
+	"github.com/suyuan32/simple-admin-common/utils/pointy"
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type GetBatchMsgByIdLogic struct {
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+	logx.Logger
+}
+
+func NewGetBatchMsgByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetBatchMsgByIdLogic {
+	return &GetBatchMsgByIdLogic{
+		ctx:    ctx,
+		svcCtx: svcCtx,
+		Logger: logx.WithContext(ctx),
+	}
+}
+
+func (l *GetBatchMsgByIdLogic) GetBatchMsgById(req *types.IDReq) (*types.BatchMsgInfoResp, error) {
+	data, err := l.svcCtx.DB.BatchMsg.Get(l.ctx, req.Id)
+	if err != nil {
+		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
+	}
+
+	return &types.BatchMsgInfoResp{
+	    BaseDataInfo: types.BaseDataInfo{
+            Code: 0,
+            Msg:  errormsg.Success,
+        },
+        Data: types.BatchMsgInfo{
+            BaseIDInfo:    types.BaseIDInfo{
+				Id:          &data.ID,
+				CreatedAt:    pointy.GetPointer(data.CreatedAt.UnixMilli()),
+				UpdatedAt:    pointy.GetPointer(data.UpdatedAt.UnixMilli()),
+            },
+			Status:	&data.Status,
+			BatchNo:	&data.BatchNo,
+			Fromwxid:	&data.Fromwxid,
+			Msg:	&data.Msg,
+			Tag:	&data.Tag,
+			Total:	&data.Total,
+			Success:	&data.Success,
+			Fail:	&data.Fail,
+			StartTime:	pointy.GetUnixMilliPointer(data.StartTime.UnixMilli()),
+			StopTime:	pointy.GetUnixMilliPointer(data.StopTime.UnixMilli()),
+        },
+	}, nil
+}
+

+ 75 - 0
internal/logic/batch_msg/get_batch_msg_list_logic.go

@@ -0,0 +1,75 @@
+package batch_msg
+
+import (
+	"context"
+
+	"wechat-api/ent/batchmsg"
+	"wechat-api/ent/predicate"
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+	"wechat-api/internal/utils/dberrorhandler"
+
+    "github.com/suyuan32/simple-admin-common/msg/errormsg"
+
+	"github.com/suyuan32/simple-admin-common/utils/pointy"
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type GetBatchMsgListLogic struct {
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+	logx.Logger
+}
+
+func NewGetBatchMsgListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetBatchMsgListLogic {
+	return &GetBatchMsgListLogic{
+		ctx:    ctx,
+		svcCtx: svcCtx,
+		Logger: logx.WithContext(ctx),
+	}
+}
+
+func (l *GetBatchMsgListLogic) GetBatchMsgList(req *types.BatchMsgListReq) (*types.BatchMsgListResp, error) {
+	var predicates []predicate.BatchMsg
+	if req.BatchNo != nil {
+		predicates = append(predicates, batchmsg.BatchNoContains(*req.BatchNo))
+	}
+	if req.Fromwxid != nil {
+		predicates = append(predicates, batchmsg.FromwxidContains(*req.Fromwxid))
+	}
+	if req.Msg != nil {
+		predicates = append(predicates, batchmsg.MsgContains(*req.Msg))
+	}
+	data, err := l.svcCtx.DB.BatchMsg.Query().Where(predicates...).Page(l.ctx, req.Page, req.PageSize)
+
+	if err != nil {
+		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
+	}
+
+	resp := &types.BatchMsgListResp{}
+	resp.Msg = errormsg.Success
+	resp.Data.Total = data.PageDetails.Total
+
+	for _, v := range data.List {
+		resp.Data.Data = append(resp.Data.Data,
+		types.BatchMsgInfo{
+			BaseIDInfo:    types.BaseIDInfo{
+				Id:          &v.ID,
+				CreatedAt:    pointy.GetPointer(v.CreatedAt.UnixMilli()),
+				UpdatedAt:    pointy.GetPointer(v.UpdatedAt.UnixMilli()),
+            },
+			Status:	&v.Status,
+			BatchNo:	&v.BatchNo,
+			Fromwxid:	&v.Fromwxid,
+			Msg:	&v.Msg,
+			Tag:	&v.Tag,
+			Total:	&v.Total,
+			Success:	&v.Success,
+			Fail:	&v.Fail,
+			StartTime:	pointy.GetUnixMilliPointer(v.StartTime.UnixMilli()),
+			StopTime:	pointy.GetUnixMilliPointer(v.StopTime.UnixMilli()),
+		})
+	}
+
+	return resp, nil
+}

+ 49 - 0
internal/logic/batch_msg/update_batch_msg_logic.go

@@ -0,0 +1,49 @@
+package batch_msg
+
+import (
+	"context"
+
+	"wechat-api/internal/svc"
+	"wechat-api/internal/types"
+	"wechat-api/internal/utils/dberrorhandler"
+
+
+	"github.com/suyuan32/simple-admin-common/msg/errormsg"
+	"github.com/suyuan32/simple-admin-common/utils/pointy"
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type UpdateBatchMsgLogic struct {
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+	logx.Logger
+}
+
+func NewUpdateBatchMsgLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateBatchMsgLogic {
+	return &UpdateBatchMsgLogic{
+		ctx:    ctx,
+		svcCtx: svcCtx,
+		Logger: logx.WithContext(ctx),
+	}
+}
+
+func (l *UpdateBatchMsgLogic) UpdateBatchMsg(req *types.BatchMsgInfo) (*types.BaseMsgResp, error) {
+    err := l.svcCtx.DB.BatchMsg.UpdateOneID(*req.Id).
+			SetNotNilStatus(req.Status).
+			SetNotNilBatchNo(req.BatchNo).
+			SetNotNilFromwxid(req.Fromwxid).
+			SetNotNilMsg(req.Msg).
+			SetNotNilTag(req.Tag).
+			SetNotNilTotal(req.Total).
+			SetNotNilSuccess(req.Success).
+			SetNotNilFail(req.Fail).
+			SetNotNilStartTime(pointy.GetTimeMilliPointer(req.StartTime)).
+			SetNotNilStopTime(pointy.GetTimeMilliPointer(req.StopTime)).
+			Exec(l.ctx)
+
+    if err != nil {
+		return nil, dberrorhandler.DefaultEntError(l.Logger, err, req)
+	}
+
+    return &types.BaseMsgResp{Msg: errormsg.UpdateSuccess}, nil
+}

+ 62 - 0
internal/types/types.go

@@ -1020,3 +1020,65 @@ type ChatroomMemberInfoResp struct {
 type WxidReq struct {
 	Wxid string `json:"wxid"`
 }
+
+// The data of batch msg information | BatchMsg信息
+// swagger:model BatchMsgInfo
+type BatchMsgInfo struct {
+	BaseIDInfo
+	// 状态 0 未开始 1 开始发送 2 发送完成 3 发送中止
+	Status *uint8 `json:"status,optional"`
+	// 批次号
+	BatchNo *string `json:"batchNo,optional"`
+	// 发送方微信ID
+	Fromwxid *string `json:"fromwxid,optional"`
+	// 内容
+	Msg *string `json:"msg,optional"`
+	// 发送规则 all 全部 tag1,tag2 按tag发送
+	Tag *string `json:"tag,optional"`
+	// 总数
+	Total *int32 `json:"total,optional"`
+	// 成功数量
+	Success *int32 `json:"success,optional"`
+	// 失败数量
+	Fail *int32 `json:"fail,optional"`
+	// 开始时间
+	StartTime *int64 `json:"startTime,optional"`
+	// 结束时间
+	StopTime *int64 `json:"stopTime,optional"`
+}
+
+// The response data of batch msg list | BatchMsg列表数据
+// swagger:model BatchMsgListResp
+type BatchMsgListResp struct {
+	BaseDataInfo
+	// BatchMsg list data | BatchMsg列表数据
+	Data BatchMsgListInfo `json:"data"`
+}
+
+// BatchMsg list data | BatchMsg列表数据
+// swagger:model BatchMsgListInfo
+type BatchMsgListInfo struct {
+	BaseListInfo
+	// The API list data | BatchMsg列表数据
+	Data []BatchMsgInfo `json:"data"`
+}
+
+// Get batch msg list request params | BatchMsg列表请求参数
+// swagger:model BatchMsgListReq
+type BatchMsgListReq struct {
+	PageInfo
+	// 批次号
+	BatchNo *string `json:"batchNo,optional"`
+	// 发送方微信ID
+	Fromwxid *string `json:"fromwxid,optional"`
+	// 内容
+	Msg *string `json:"msg,optional"`
+}
+
+// BatchMsg information response | BatchMsg信息返回体
+// swagger:model BatchMsgInfoResp
+type BatchMsgInfoResp struct {
+	BaseDataInfo
+	// BatchMsg information | BatchMsg数据
+	Data BatchMsgInfo `json:"data"`
+}