WH01243 4 years ago
parent
commit
c21a58a74a

+ 8 - 0
api/etc/integral-api.yaml

@@ -0,0 +1,8 @@
+Name: integral-api
+Host: 0.0.0.0
+Port: 8888
+resources:
+  Etcd:
+    Hosts:
+      - 127.0.0.1:2379
+    Key: resourcescenter.rpc

+ 45 - 0
api/integral.api

@@ -0,0 +1,45 @@
+syntax = "v1"
+
+type resourcesReq {
+	AccountId      string `json:"accountId"`               //账户标识
+	CompanyId      int64  `json:"companyId,optional"`      //企业标识
+	DepartmentId   int64  `json:"departmentId,optional"`   //组织标识
+	Name           string `json:"name"`                    //资源名称
+	ResourceType   string `json:"resourceType"`            //资源类型
+	Number         int64  `json:"number"`                  //数量
+	Spec           string `json:"spec,optional"`           //规格
+	AppId          string `json:"appId"`                   //标识
+	Model          int64  `json:"model"`                   //操作类型0使用1新增
+	RuleId         string `json:"ruleId,optional"`         //使用规则标识
+	UserId         string `json:"userId"`                  //用户标识
+	Url            string `json:"url,optional"`            //下载地址
+	SearchCriteria string `json:"searchCriteria,optional"` //搜索条件
+	Source         string `json:"source,optional"`         //数据来源
+}
+
+type resourcesRes {
+	// TODO: add members here and delete this comment
+	Code    int64  `form:"code"`
+	Message string `form:"message"`
+}
+type previewReq {
+	InfoId        string `json:"infoId,optional"`        //信息标识
+	AccountId     string `json:"accountId,optional"`     //企业标识
+	DeductionType string `json:"deductionType,optional"` //资源代码
+}
+
+type previewRes {
+	// TODO: add members here and delete this comment
+	Code          int64  `form:"code"`
+	Message       string `form:"message"`
+	RepeatNumb    int64  `form:"repeatNumb"`
+	DeductionNumb int64  `form:"deductionNumb"`
+}
+service integral-api {
+	//资源操作
+	@handler UpdateUserBalanceHandler // TODO: set handler name and delete this comment
+	post /updateUserBalance (resourcesReq) returns(previewRes)
+	//预览信息
+	@handler FindPreviewHandler // TODO: set handler name and delete this comment
+	post /findPreview (previewReq) returns(previewRes)
+}

+ 31 - 0
api/integral.go

@@ -0,0 +1,31 @@
+package main
+
+import (
+	"flag"
+	"fmt"
+
+	"app.yhyue.com/moapp/jyResourcesCenter/api/internal/config"
+	"app.yhyue.com/moapp/jyResourcesCenter/api/internal/handler"
+	"app.yhyue.com/moapp/jyResourcesCenter/api/internal/svc"
+
+	"github.com/tal-tech/go-zero/core/conf"
+	"github.com/tal-tech/go-zero/rest"
+)
+
+var configFile = flag.String("f", "etc/integral-api.yaml", "the config file")
+
+func main() {
+	flag.Parse()
+
+	var c config.Config
+	conf.MustLoad(*configFile, &c)
+
+	ctx := svc.NewServiceContext(c)
+	server := rest.MustNewServer(c.RestConf)
+	defer server.Stop()
+
+	handler.RegisterHandlers(server, ctx)
+
+	fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
+	server.Start()
+}

+ 7 - 0
api/internal/config/config.go

@@ -0,0 +1,7 @@
+package config
+
+import "github.com/tal-tech/go-zero/rest"
+
+type Config struct {
+	rest.RestConf
+}

+ 29 - 0
api/internal/handler/findpreviewhandler.go

@@ -0,0 +1,29 @@
+package handler
+
+import (
+	"net/http"
+
+	"app.yhyue.com/moapp/jyResourcesCenter/api/internal/logic"
+	"app.yhyue.com/moapp/jyResourcesCenter/api/internal/svc"
+	"app.yhyue.com/moapp/jyResourcesCenter/api/internal/types"
+
+	"github.com/tal-tech/go-zero/rest/httpx"
+)
+
+func FindPreviewHandler(ctx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.PreviewReq
+		if err := httpx.Parse(r, &req); err != nil {
+			httpx.Error(w, err)
+			return
+		}
+
+		l := logic.NewFindPreviewLogic(r.Context(), ctx)
+		resp, err := l.FindPreview(req)
+		if err != nil {
+			httpx.Error(w, err)
+		} else {
+			httpx.OkJson(w, resp)
+		}
+	}
+}

+ 27 - 0
api/internal/handler/routes.go

@@ -0,0 +1,27 @@
+// Code generated by goctl. DO NOT EDIT.
+package handler
+
+import (
+	"net/http"
+
+	"app.yhyue.com/moapp/jyResourcesCenter/api/internal/svc"
+
+	"github.com/tal-tech/go-zero/rest"
+)
+
+func RegisterHandlers(engine *rest.Server, serverCtx *svc.ServiceContext) {
+	engine.AddRoutes(
+		[]rest.Route{
+			{
+				Method:  http.MethodPost,
+				Path:    "/updateUserBalance",
+				Handler: UpdateUserBalanceHandler(serverCtx),
+			},
+			{
+				Method:  http.MethodPost,
+				Path:    "/findPreview",
+				Handler: FindPreviewHandler(serverCtx),
+			},
+		},
+	)
+}

+ 29 - 0
api/internal/handler/updateuserbalancehandler.go

@@ -0,0 +1,29 @@
+package handler
+
+import (
+	"net/http"
+
+	"app.yhyue.com/moapp/jyResourcesCenter/api/internal/logic"
+	"app.yhyue.com/moapp/jyResourcesCenter/api/internal/svc"
+	"app.yhyue.com/moapp/jyResourcesCenter/api/internal/types"
+
+	"github.com/tal-tech/go-zero/rest/httpx"
+)
+
+func UpdateUserBalanceHandler(ctx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.ResourcesReq
+		if err := httpx.Parse(r, &req); err != nil {
+			httpx.Error(w, err)
+			return
+		}
+
+		l := logic.NewUpdateUserBalanceLogic(r.Context(), ctx)
+		resp, err := l.UpdateUserBalance(req)
+		if err != nil {
+			httpx.Error(w, err)
+		} else {
+			httpx.OkJson(w, resp)
+		}
+	}
+}

+ 30 - 0
api/internal/logic/findpreviewlogic.go

@@ -0,0 +1,30 @@
+package logic
+
+import (
+	"context"
+
+	"app.yhyue.com/moapp/jyResourcesCenter/api/internal/svc"
+	"app.yhyue.com/moapp/jyResourcesCenter/api/internal/types"
+
+	"github.com/tal-tech/go-zero/core/logx"
+)
+
+type FindPreviewLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewFindPreviewLogic(ctx context.Context, svcCtx *svc.ServiceContext) FindPreviewLogic {
+	return FindPreviewLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx,
+	}
+}
+
+func (l *FindPreviewLogic) FindPreview(req types.PreviewReq) (*types.PreviewRes, error) {
+	// todo: add your logic here and delete this line
+
+	return &types.PreviewRes{}, nil
+}

+ 30 - 0
api/internal/logic/updateuserbalancelogic.go

@@ -0,0 +1,30 @@
+package logic
+
+import (
+	"context"
+
+	"app.yhyue.com/moapp/jyResourcesCenter/api/internal/svc"
+	"app.yhyue.com/moapp/jyResourcesCenter/api/internal/types"
+
+	"github.com/tal-tech/go-zero/core/logx"
+)
+
+type UpdateUserBalanceLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewUpdateUserBalanceLogic(ctx context.Context, svcCtx *svc.ServiceContext) UpdateUserBalanceLogic {
+	return UpdateUserBalanceLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx,
+	}
+}
+
+func (l *UpdateUserBalanceLogic) UpdateUserBalance(req types.ResourcesReq) (*types.PreviewRes, error) {
+	// todo: add your logic here and delete this line
+
+	return &types.PreviewRes{}, nil
+}

+ 15 - 0
api/internal/svc/servicecontext.go

@@ -0,0 +1,15 @@
+package svc
+
+import (
+	"app.yhyue.com/moapp/jyResourcesCenter/api/internal/config"
+)
+
+type ServiceContext struct {
+	Config config.Config
+}
+
+func NewServiceContext(c config.Config) *ServiceContext {
+	return &ServiceContext{
+		Config: c,
+	}
+}

+ 37 - 0
api/internal/types/types.go

@@ -0,0 +1,37 @@
+// Code generated by goctl. DO NOT EDIT.
+package types
+
+type ResourcesReq struct {
+	AccountId      string `json:"accountId"`               //账户标识
+	CompanyId      int64  `json:"companyId,optional"`      //企业标识
+	DepartmentId   int64  `json:"departmentId,optional"`   //组织标识
+	Name           string `json:"name"`                    //资源名称
+	ResourceType   string `json:"resourceType"`            //资源类型
+	Number         int64  `json:"number"`                  //数量
+	Spec           string `json:"spec,optional"`           //规格
+	AppId          string `json:"appId"`                   //标识
+	Model          int64  `json:"model"`                   //操作类型0使用1新增
+	RuleId         string `json:"ruleId,optional"`         //使用规则标识
+	UserId         string `json:"userId"`                  //用户标识
+	Url            string `json:"url,optional"`            //下载地址
+	SearchCriteria string `json:"searchCriteria,optional"` //搜索条件
+	Source         string `json:"source,optional"`         //数据来源
+}
+
+type ResourcesRes struct {
+	Code    int64  `form:"code"`
+	Message string `form:"message"`
+}
+
+type PreviewReq struct {
+	InfoId        string `json:"infoId,optional"`        //信息标识
+	AccountId     string `json:"accountId,optional"`     //企业标识
+	DeductionType string `json:"deductionType,optional"` //资源代码
+}
+
+type PreviewRes struct {
+	Code          int64  `form:"code"`
+	Message       string `form:"message"`
+	RepeatNumb    int64  `form:"repeatNumb"`
+	DeductionNumb int64  `form:"deductionNumb"`
+}

+ 1 - 1
entity/detailed.go

@@ -13,7 +13,7 @@ type Detailed struct {
 	RuleId         string    `xorm:"ruleId" form:"ruleId" json:"ruleId"`                         //使用规则标识
 	ExportTime     time.Time `xorm:"exportTime" form:"exportTime" json:"exportTime"`             //导出时间
 	UserType       int64     `xorm:"userType" form:"userType" json:"userType"`                   //流水类型0使用1新增
-	DeductionNumb  string    `xorm:"deductionNumb" form:"deductionNumb" json:"deductionNumb"`    //扣除数量
+	DeductionNumb  int64     `xorm:"deductionNumb" form:"deductionNumb" json:"deductionNumb"`    //扣除数量
 	Url            string    `xorm:"url" form:"url" json:"url"`                                  //下载地址
 	SearchCriteria string    `xorm:"searchCriteria" form:"searchCriteria" json:"searchCriteria"` //搜索条件
 	Source         string    `xorm:"source" form:"source" json:"source"`                         //数据来源

+ 19 - 0
entity/user.go

@@ -0,0 +1,19 @@
+package entity
+
+import (
+	"github.com/go-xorm/xorm"
+)
+
+//定义orm引擎
+var Engine *xorm.Engine
+
+
+
+//定义返回状态
+const (
+	SuccessCode int64 = 1
+	ErrorCode   int64 = 0
+	COMPANYADMINISTRATORS int64=0
+	ORGANADMINISTRATORS int64=1
+	PERSONNEL int64=2
+)

+ 31 - 0
rpc/internal/logic/findpreviewlogic.go

@@ -0,0 +1,31 @@
+package logic
+
+import (
+	"context"
+
+	"app.yhyue.com/moapp/jyResourcesCenter/rpc/internal/svc"
+	"app.yhyue.com/moapp/jyResourcesCenter/rpc/resourcesCenter"
+
+	"github.com/tal-tech/go-zero/core/logx"
+)
+
+type FindPreviewLogic struct {
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+	logx.Logger
+}
+
+func NewFindPreviewLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FindPreviewLogic {
+	return &FindPreviewLogic{
+		ctx:    ctx,
+		svcCtx: svcCtx,
+		Logger: logx.WithContext(ctx),
+	}
+}
+
+// 预览信息
+func (l *FindPreviewLogic) FindPreview(in *resourcesCenter.PreviewReq) (*resourcesCenter.ConsumeRecordRes, error) {
+	// todo: add your logic here and delete this line
+
+	return &resourcesCenter.ConsumeRecordRes{}, nil
+}

+ 13 - 9
service/balanceService.go

@@ -88,15 +88,19 @@ func (service *BalanceService) UpdateUserDetailed(in *resourcesCenter.Detailed)
 	orm := entity.Engine
 	//新增流水记录
 	detailed := entity.Detailed{
-		AccountId:    in.AccountId,
-		CompanyId:    in.CompanyId,
-		DepartmentId: in.DepartmentId,
-		ResourceType: in.ResourceType,
-		ExportNum:    in.ExportNum,
-		RuleId:       in.RuleId,
-		ExportTime:   time.Now().Local(),
-		UserType:     in.UserType,
-		UserId:       in.UserId,
+		AccountId:      in.AccountId,
+		CompanyId:      in.CompanyId,
+		DepartmentId:   in.DepartmentId,
+		ResourceType:   in.ResourceType,
+		ExportNum:      in.ExportNum,
+		RuleId:         in.RuleId,
+		ExportTime:     time.Now().Local(),
+		UserType:       in.UserType,
+		UserId:         in.UserId,
+		Url:            in.Url,
+		Source:         in.Source,
+		SearchCriteria: in.SearchCriteria,
+		DeductionNumb:  in.DeductionNumb,
 	}
 	insertNumb, err := orm.Table(ConsumeRecord).Insert(&detailed)
 	if err != nil {

+ 0 - 32
util/iterator.go

@@ -1,32 +0,0 @@
-package util
-
-import "app.yhyue.com/moapp/jyResourcesCenter/entity"
-
-type Iterator struct {
-	*Iter
-	data []*entity.Employee
-}
-
-func New(data []*entity.Employee) *Iterator {
-	return &Iterator{data: data, Iter: &Iter{len: len(data)}}
-}
-
-func (this *Iterator) Next() *entity.Employee {
-	defer func() {
-		this.index++
-	}()
-	return this.data[this.index]
-}
-
-/*公用*/
-type Iter struct {
-	index int
-	len   int
-}
-
-func (this *Iter) HasNext() bool {
-	if this.len == 0 {
-		return false
-	}
-	return this.index < this.len
-}