This commit is contained in:
2026-10-20 13:39:27 +08:00
parent cb5644d1f7
commit f327fd44ac
16 changed files with 748 additions and 114 deletions
+34 -1
View File
@@ -1,5 +1,5 @@
// Code generated by goctl. DO NOT EDIT.
// goctl 1.10.1
// goctl 1.10.2
// Source: chore.proto
package choreClient
@@ -14,6 +14,7 @@ import (
)
type (
ApiSystemReq = chore.ApiSystemReq
DecryptMobileReq = chore.DecryptMobileReq
DocumentReq = chore.DocumentReq
EditReq = chore.EditReq
@@ -44,6 +45,12 @@ type (
DecryptMobile(ctx context.Context, in *DecryptMobileReq, opts ...grpc.CallOption) (*Response, error)
Regions(ctx context.Context, in *RegionsReq, opts ...grpc.CallOption) (*Response, error)
SendSms(ctx context.Context, in *SendSmsReq, opts ...grpc.CallOption) (*Response, error)
ApiSystemItems(ctx context.Context, in *ApiSystemReq, opts ...grpc.CallOption) (*Response, error)
ApiSystemInfo(ctx context.Context, in *ApiSystemReq, opts ...grpc.CallOption) (*Response, error)
ApiAnswerItems(ctx context.Context, in *EmptyReq, opts ...grpc.CallOption) (*Response, error)
ApiAnswerIProgress(ctx context.Context, in *EmptyReq, opts ...grpc.CallOption) (*Response, error)
ApiAnswerSave(ctx context.Context, in *EmptyReq, opts ...grpc.CallOption) (*Response, error)
// 管理员接口
AnswerItems(ctx context.Context, in *EmptyReq, opts ...grpc.CallOption) (*Response, error)
AnswerStatus(ctx context.Context, in *StatusReq, opts ...grpc.CallOption) (*Response, error)
AnswerInfo(ctx context.Context, in *IdReq, opts ...grpc.CallOption) (*Response, error)
@@ -100,6 +107,32 @@ func (m *defaultChore) SendSms(ctx context.Context, in *SendSmsReq, opts ...grpc
return client.SendSms(ctx, in, opts...)
}
func (m *defaultChore) ApiSystemItems(ctx context.Context, in *ApiSystemReq, opts ...grpc.CallOption) (*Response, error) {
client := chore.NewChoreClient(m.cli.Conn())
return client.ApiSystemItems(ctx, in, opts...)
}
func (m *defaultChore) ApiSystemInfo(ctx context.Context, in *ApiSystemReq, opts ...grpc.CallOption) (*Response, error) {
client := chore.NewChoreClient(m.cli.Conn())
return client.ApiSystemInfo(ctx, in, opts...)
}
func (m *defaultChore) ApiAnswerItems(ctx context.Context, in *EmptyReq, opts ...grpc.CallOption) (*Response, error) {
client := chore.NewChoreClient(m.cli.Conn())
return client.ApiAnswerItems(ctx, in, opts...)
}
func (m *defaultChore) ApiAnswerIProgress(ctx context.Context, in *EmptyReq, opts ...grpc.CallOption) (*Response, error) {
client := chore.NewChoreClient(m.cli.Conn())
return client.ApiAnswerIProgress(ctx, in, opts...)
}
func (m *defaultChore) ApiAnswerSave(ctx context.Context, in *EmptyReq, opts ...grpc.CallOption) (*Response, error) {
client := chore.NewChoreClient(m.cli.Conn())
return client.ApiAnswerSave(ctx, in, opts...)
}
// 管理员接口
func (m *defaultChore) AnswerItems(ctx context.Context, in *EmptyReq, opts ...grpc.CallOption) (*Response, error) {
client := chore.NewChoreClient(m.cli.Conn())
return client.AnswerItems(ctx, in, opts...)
@@ -0,0 +1,6 @@
package dao
type UserAnswer struct {
Id int `gorm:"column:id;type:int(11);primary_key;AUTO_INCREMENT" json:"id"`
Answer uint8 `gorm:"column:answer;type:tinyint(1);default:2;comment:答题状态,1为答完, 2为未答" json:"answer"`
}
+5
View File
@@ -16,3 +16,8 @@ type SystemStatus struct {
AdminId int64 `gorm:"column:admin_id;type:int(11)" json:"admin_id"`
AdminName string `gorm:"column:admin_name;type:varchar(255)" json:"admin_name"`
}
type ApiSystemInfo struct {
Type int32 `gorm:"column:type;type:tinyint(1);default:0;NOT NULL" json:"type"`
Content string `gorm:"column:content;type:text;default:'';NOT NULL" json:"content"`
}
@@ -0,0 +1,46 @@
package logic
import (
"context"
"lone-services/pkg/modelbase"
"lone-services/pkg/utils"
"lone-services/rpc/chore/pb"
"lone-services/services/chore/internal/dao"
"lone-services/services/chore/internal/model"
"lone-services/services/chore/internal/svc"
"strconv"
"github.com/zeromicro/go-zero/core/logx"
)
type ApiAnswerIProgressLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
BaseLogic
}
func NewApiAnswerIProgressLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ApiAnswerIProgressLogic {
return &ApiAnswerIProgressLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *ApiAnswerIProgressLogic) ApiAnswerIProgress(in *chore.EmptyReq) (*chore.Response, error) {
adminInfo := utils.GetUserFromCtx(l.ctx)
if adminInfo.ID < utils.NumberOne {
return l.fail(utils.ErrorNoLoginInfo)
}
var info dao.UserAnswer
w := modelbase.Params{Eq: map[string]string{"id": strconv.FormatInt(adminInfo.ID, utils.NumberTen)}}
err := model.AnswerUserModel{}.Init().GetOne(w, &info)
if err != nil {
l.Logger.Error(err)
return l.fail(utils.Fail)
}
return l.ok(info)
}
@@ -0,0 +1,46 @@
package logic
import (
"context"
"lone-services/pkg/modelbase"
"lone-services/pkg/utils"
"lone-services/services/chore/internal/dao"
"lone-services/services/chore/internal/model"
"lone-services/rpc/chore/pb"
"lone-services/services/chore/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type ApiAnswerItemsLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
BaseLogic
}
func NewApiAnswerItemsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ApiAnswerItemsLogic {
return &ApiAnswerItemsLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *ApiAnswerItemsLogic) ApiAnswerItems(in *chore.EmptyReq) (*chore.Response, error) {
adminInfo := utils.GetUserFromCtx(l.ctx)
if adminInfo.ID < utils.NumberOne {
return l.fail(utils.ErrorNoLoginInfo)
}
var info []dao.AnswerInfo
w := modelbase.Params{Eq: map[string]string{"status": utils.StringStatusOk}}
err := model.AnswerModel{}.Init().Items(w, &info)
if err != nil {
l.Logger.Error(err)
return l.fail(utils.Fail)
}
return l.ok(info)
}
@@ -0,0 +1,56 @@
package logic
import (
"context"
"lone-services/pkg/modelbase"
"lone-services/pkg/utils"
"lone-services/services/chore/internal/dao"
"lone-services/services/chore/internal/model"
"strconv"
"lone-services/rpc/chore/pb"
"lone-services/services/chore/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type ApiAnswerSaveLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
BaseLogic
}
func NewApiAnswerSaveLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ApiAnswerSaveLogic {
return &ApiAnswerSaveLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *ApiAnswerSaveLogic) ApiAnswerSave(in *chore.EmptyReq) (*chore.Response, error) {
adminInfo := utils.GetUserFromCtx(l.ctx)
if adminInfo.ID < utils.NumberOne {
return l.fail(utils.ErrorNoLoginInfo)
}
var info dao.UserAnswer
w := modelbase.Params{Eq: map[string]string{"user_id": strconv.FormatInt(adminInfo.ID, utils.NumberTen)}}
err := model.AnswerUserModel{}.Init().GetOne(w, &info)
if err != nil {
l.Logger.Error(err)
return l.fail(utils.Fail)
}
if info.Id < utils.NumberOne {
return l.fail(utils.SetError(utils.ErrorNotFund, "用户不存在"))
}
info.Answer = utils.StatusOk
_, err = model.AnswerUserModel{}.Init().Edit(w, &info)
if err != nil {
l.Logger.Error(err)
return l.fail(utils.Fail)
}
return l.ok(info.Id)
}
@@ -0,0 +1,47 @@
package logic
import (
"context"
"lone-services/pkg/modelbase"
"lone-services/pkg/utils"
"lone-services/services/chore/internal/dao"
"lone-services/services/chore/internal/model"
"lone-services/services/chore/validator"
"strconv"
"lone-services/rpc/chore/pb"
"lone-services/services/chore/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type ApiSystemInfoLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
BaseLogic
}
func NewApiSystemInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ApiSystemInfoLogic {
return &ApiSystemInfoLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *ApiSystemInfoLogic) ApiSystemInfo(in *chore.ApiSystemReq) (*chore.Response, error) {
var v validator.ApiSystemInfoValidator
if fail := l.checkParams(in, &v); fail != nil {
return fail, nil
}
var info []dao.ApiSystemInfo
w := modelbase.Params{Eq: map[string]string{"type": strconv.Itoa(int(in.Type))}}
err := model.SystemModel{}.Init().GetOne(w, &info)
if err != nil {
return l.fail(utils.ErrorNotFund)
}
return l.ok(info)
}
@@ -0,0 +1,45 @@
package logic
import (
"context"
"lone-services/pkg/modelbase"
"lone-services/pkg/utils"
"lone-services/services/chore/internal/dao"
"lone-services/services/chore/internal/model"
"strconv"
"lone-services/rpc/chore/pb"
"lone-services/services/chore/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type ApiSystemItemsLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
BaseLogic
}
func NewApiSystemItemsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ApiSystemItemsLogic {
return &ApiSystemItemsLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
func (l *ApiSystemItemsLogic) ApiSystemItems(in *chore.ApiSystemReq) (*chore.Response, error) {
var info []dao.ApiSystemInfo
w := modelbase.Params{}
if in.Type > utils.NumberZero {
w.Eq = make(map[string]string)
w.Eq["type"] = strconv.Itoa(int(in.Type))
}
err := model.SystemModel{}.Init().Items(w, &info)
if err != nil {
return l.fail(utils.ErrorNotFund)
}
return l.ok(info)
}
@@ -0,0 +1,18 @@
package model
import (
"lone-services/pkg/modelbase"
)
type AnswerUserModel struct {
modelbase.Base
}
func (m AnswerUserModel) TableName() string {
return modelbase.Prefix() + "answer_user"
}
func (m AnswerUserModel) Init() AnswerUserModel {
m.Table = m.TableName()
return m
}
+27 -1
View File
@@ -1,5 +1,5 @@
// Code generated by goctl. DO NOT EDIT.
// goctl 1.10.1
// goctl 1.10.2
// Source: chore.proto
package server
@@ -53,6 +53,32 @@ func (s *ChoreServer) SendSms(ctx context.Context, in *chore.SendSmsReq) (*chore
return l.SendSms(in)
}
func (s *ChoreServer) ApiSystemItems(ctx context.Context, in *chore.ApiSystemReq) (*chore.Response, error) {
l := logic.NewApiSystemItemsLogic(ctx, s.svcCtx)
return l.ApiSystemItems(in)
}
func (s *ChoreServer) ApiSystemInfo(ctx context.Context, in *chore.ApiSystemReq) (*chore.Response, error) {
l := logic.NewApiSystemInfoLogic(ctx, s.svcCtx)
return l.ApiSystemInfo(in)
}
func (s *ChoreServer) ApiAnswerItems(ctx context.Context, in *chore.EmptyReq) (*chore.Response, error) {
l := logic.NewApiAnswerItemsLogic(ctx, s.svcCtx)
return l.ApiAnswerItems(in)
}
func (s *ChoreServer) ApiAnswerIProgress(ctx context.Context, in *chore.EmptyReq) (*chore.Response, error) {
l := logic.NewApiAnswerIProgressLogic(ctx, s.svcCtx)
return l.ApiAnswerIProgress(in)
}
func (s *ChoreServer) ApiAnswerSave(ctx context.Context, in *chore.EmptyReq) (*chore.Response, error) {
l := logic.NewApiAnswerSaveLogic(ctx, s.svcCtx)
return l.ApiAnswerSave(in)
}
// 管理员接口
func (s *ChoreServer) AnswerItems(ctx context.Context, in *chore.EmptyReq) (*chore.Response, error) {
l := logic.NewAnswerItemsLogic(ctx, s.svcCtx)
return l.AnswerItems(in)
+10
View File
@@ -13,3 +13,13 @@ func (p SystemEditValidator) GetMessage() validate.ValidatorMessages {
"Content.required": "Content 必传",
}
}
type ApiSystemInfoValidator struct {
Type int32 `form:"type" json:"type" validate:"required"`
}
func (p ApiSystemInfoValidator) GetMessage() validate.ValidatorMessages {
return validate.ValidatorMessages{
"Type.required": "Type 必传",
}
}