jiaojiao7 4 سال پیش
والد
کامیت
cbd37aebf8

+ 6 - 6
api/integral.api

@@ -23,8 +23,8 @@ type resourcesReq {
 
 type resourcesRes {
 	// TODO: add members here and delete this comment
-	Code    int64  `form:"code"`
-	Message string `form:"message"`
+	Code    int64  `json:"code"`
+	Message string `json:"message"`
 }
 type previewReq {
 	InfoId       string `form:"infoId,optional"`       //信息标识
@@ -34,10 +34,10 @@ type previewReq {
 
 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"`
+	Code          int64  `json:"code"`
+	Message       string `json:"message"`
+	RepeatNumb    int64  `json:"repeatNumb"`
+	DeductionNumb int64  `json:"deductionNumb"`
 }
 
 //流水账请求参数返回参数

+ 2 - 5
api/internal/logic/updateuserbalancelogic.go

@@ -1,12 +1,10 @@
 package logic
 
 import (
-	"app.yhyue.com/moapp/jyResourcesCenter/rpc/resourcesCenterclient"
-	"context"
-	"fmt"
-
 	"app.yhyue.com/moapp/jyResourcesCenter/api/internal/svc"
 	"app.yhyue.com/moapp/jyResourcesCenter/api/internal/types"
+	"app.yhyue.com/moapp/jyResourcesCenter/rpc/resourcesCenterclient"
+	"context"
 
 	"github.com/tal-tech/go-zero/core/logx"
 )
@@ -28,7 +26,6 @@ func NewUpdateUserBalanceLogic(ctx context.Context, svcCtx *svc.ServiceContext)
 func (l *UpdateUserBalanceLogic) UpdateUserBalance(req types.ResourcesReq) (*types.ResourcesRes, error) {
 	// todo: add your logic here and delete this line
 	result := &types.ResourcesRes{}
-	fmt.Println(req)
 	lsi := l.svcCtx.ResourcesCenter
 	var err error
 	resp := &resourcesCenterclient.Response{}

+ 6 - 6
api/internal/types/types.go

@@ -23,8 +23,8 @@ type ResourcesReq struct {
 }
 
 type ResourcesRes struct {
-	Code    int64  `form:"code"`
-	Message string `form:"message"`
+	Code    int64  `json:"code"`
+	Message string `json:"message"`
 }
 
 type PreviewReq struct {
@@ -34,10 +34,10 @@ type PreviewReq struct {
 }
 
 type PreviewRes struct {
-	Code          int64  `form:"code"`
-	Message       string `form:"message"`
-	RepeatNumb    int64  `form:"repeatNumb"`
-	DeductionNumb int64  `form:"deductionNumb"`
+	Code          int64  `json:"code"`
+	Message       string `json:"message"`
+	RepeatNumb    int64  `json:"repeatNumb"`
+	DeductionNumb int64  `json:"deductionNumb"`
 }
 
 type RecordReq struct {

+ 15 - 8
entity/user.go

@@ -7,13 +7,20 @@ import (
 //定义orm引擎
 var Engine *xorm.Engine
 
-
-
 //定义返回状态
 const (
-	SuccessCode int64 = 1
-	ErrorCode   int64 = 0
-	COMPANYADMINISTRATORS int64=0
-	ORGANADMINISTRATORS int64=1
-	PERSONNEL int64=2
-)
+	SuccessCode           int64 = 1
+	ErrorCode             int64 = 0
+	COMPANYADMINISTRATORS int64 = 0
+	ORGANADMINISTRATORS   int64 = 1
+	PERSONNEL             int64 = 2
+)
+
+type Dedup struct {
+	Code int64
+	Data struct {
+		TotalCount int64
+		ExistCount int64
+		NewCount   int64
+	}
+}

+ 1 - 2
go.mod

@@ -6,10 +6,9 @@ require (
 	github.com/garyburd/redigo v1.6.2
 	github.com/go-sql-driver/mysql v1.5.0
 	github.com/go-xorm/xorm v0.7.9
-	github.com/golang/protobuf v1.5.2 // indirect
+	github.com/golang/protobuf v1.5.2
 	github.com/google/uuid v1.1.2 // indirect
 	github.com/tal-tech/go-zero v1.1.7
-	golang.org/x/tools v0.0.0-20200410132612-ae9902aceb98
 	google.golang.org/grpc v1.29.1
 	google.golang.org/protobuf v1.26.0
 )

+ 7 - 1
rpc/etc/resourcescenter.yaml

@@ -20,4 +20,10 @@ FileSystemConf:
       - 127.0.0.1:2379
     Key: resourcescenter.rpc
 CalleeId: resourcescenter.rpc
-Node: 1
+Deduplication:
+  Etcd:
+    Hosts:
+      - 192.168.20.240:2379
+    Key: deduplication.rpc
+Node: 1
+DedupUrl: http://127.0.0.1:4888

+ 4 - 2
rpc/internal/config/config.go

@@ -9,8 +9,10 @@ type Config struct {
 	CalleeId       string // 服务名字
 	FileSystemConf zrpc.RpcClientConf
 	Redis          Redis
+	DedupUrl       string
 }
-var  ConfigJson Config
+
+var ConfigJson Config
 
 type Redis struct {
 	Addr        string `json:"addr"`
@@ -18,4 +20,4 @@ type Redis struct {
 	PoolMaxSize int    `json:"maxSize"`
 	PoolMaxIdle int    `json:"maxIdle"`
 	IdleTimeout int    `json:"idleTimeOut"`
-}
+}

+ 3 - 2
rpc/internal/logic/useuserdetailedlogic.go

@@ -1,6 +1,7 @@
 package logic
 
 import (
+	"app.yhyue.com/moapp/jyResourcesCenter/rpc/internal/config"
 	"context"
 
 	"app.yhyue.com/moapp/jyResourcesCenter/rpc/internal/svc"
@@ -45,14 +46,14 @@ func (l *UseUserDetailedLogic) UseUserDetailed(in *resourcesCenter.Resources) (*
 		ExportNum:      in.Number,
 		DepartmentId:   in.DepartmentId,
 		Name:           in.Name,
-		UserId:         "",
+		UserId:         in.UserId,
 		UserType:       in.Model,
 		Url:            in.Url,
 		SearchCriteria: in.SearchCriteria,
 		Source:         in.Source,
 		RuleId:         in.RuleId,
 	}
-	code, msg := balanceService.UseUserDetailed(balance, detailed)
+	code, msg := balanceService.UseUserDetailed(in.DuplicateRemoval, balance, detailed, in.InfoId, config.ConfigJson.DedupUrl)
 	return &resourcesCenter.Response{
 		Code:    code,
 		Message: msg,

+ 1 - 77
rpc/test/company_test.go

@@ -11,80 +11,4 @@ var c config.Config
 
 func init() {
 	conf.MustLoad(*configFile, &c)
-}
-
-/*AccountId
-int64  //账户标识
-CompanyId
-int64  //企业标识
-DepartmentId
-int64  //组织标识
-Name
-string //资源名称
-ResourceType
-string //资源代码
-Number
-int64  //数量
-Spec
-string //标识
-AppId
-string //剑鱼标识
-Modelcode
-int64  //操作类型0使用1新增*/
-//修改结存
-/*func Test_UpdateUserBalance(t *testing.T) {
-	ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
-	FileSystem := resourcesCenterclient.NewResourcesCenter(zrpc.MustNewClient(c.FileSystemConf))
-	req := &resourcesCenter.Balance{
-		AccountId:    "111",
-		CompanyId:    0,
-		DepartmentId: 0,
-		Name:         "数据导出",
-		ResourceType:         "001",
-		Number:       1300,
-		Spec:         "021",
-		AppId:        "10000",
-		Model:        0,
-	}
-	res, err := FileSystem.UpdateUserBalance(ctx, req)
-	log.Println("err ", err)
-	log.Println("req ", res)
-}*/
-
-/*AccountId
-int64  //账户标识
-CompanyId
-int64  //企业标识
-ResourceType
-string //资源类型
-ExportNum
-int64  //导出数量
-DeductionType
-string //扣费类型(1高级字段包)
-int64
-ExportTime 导出时间
-RuleId  //使用规则标识
-int64  //
-UserType
-int64  //流水类型0使用1新增
-DepartmentId
-int64  //组织标识*/
-/*func Test_UpdateUserDetailed(t *testing.T) {
-	ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
-	FileSystem := resourcesCenterclient.NewResourcesCenter(zrpc.MustNewClient(c.FileSystemConf))
-	req := &resourcesCenter.Detailed{
-		AccountId:     "111",
-		CompanyId:     0,
-		ResourceType:  "001",
-		ExportNum:     1300,
-		DeductionType: "1",
-		RuleId:        1,
-		UserType:      0,
-		DepartmentId:  0,
-		UserId:"1111111",
-	}
-	res, err := FileSystem.UpdateUserDetailed(ctx, req)
-	log.Println("err ", err)
-	log.Println("req ", res)
-}
-*/
+}

+ 1 - 0
rpc/test/resourcescenter.yaml

@@ -20,4 +20,5 @@ FileSystemConf:
       - 127.0.0.1:2379
     Key: resourcescenter.rpc
 CalleeId: resourcescenter.rpc
+DedupUrl: 127.0.0.1:4888
 Node: 1

+ 20 - 5
service/balanceService.go

@@ -117,22 +117,34 @@ func (service *BalanceService) PurchaseUserBalance(balanceData *resourcesCenter.
 }
 
 //根据账户标识使用资源
-func (service *BalanceService) UseUserDetailed(balanceData *resourcesCenter.Balance, detailedData *resourcesCenter.Detailed) (int64, string) {
+func (service *BalanceService) UseUserDetailed(duplicateRemoval int64, balanceData *resourcesCenter.Balance, detailedData *resourcesCenter.Detailed, infoId, url string) (int64, string) {
 	orm := entity.Engine.NewSession()
 	err := orm.Begin()
 	//去重
-	deductionNumb := int64(0)
-	deductionNumb = detailedData.ExportNum
+	deductionNumb := detailedData.ExportNum
+	if duplicateRemoval == 1 {
+		url=url+"/data/dedupAndSave?personId="+detailedData.UserId+"&infoId="+infoId+"&accountId="+detailedData.AccountId
+		res, urlerr := http.PostForm( url, nil)
+		fmt.Println(url, urlerr)
+		defer res.Body.Close()
+		body, _ := ioutil.ReadAll(res.Body)
+		dat := entity.Dedup{}
+		_ = json.Unmarshal([]byte(body), &dat)
+		fmt.Println(dat)
+		if dat.Code == 0 {
+			deductionNumb = dat.Data.NewCount
+		}
+	}
+
 	//查询结存是否够用
 	type SumStruct struct {
 		Age int `xorm:"age"`
 	}
 	sumStruct := "0"
-	fool, err := orm.Table(AccountResources).
+	_, err = orm.Table(AccountResources).
 		Select("sum(number) as  number").
 		Where("accountId=? and  companyId=? and  departmentId=? and  ResourceType=? and  endTime>=?", balanceData.AccountId, balanceData.CompanyId, balanceData.DepartmentId, balanceData.ResourceType, time.Now().Format("2006-01-02")).
 		Get(&sumStruct)
-	fmt.Println(fool, sumStruct)
 	if err != nil {
 		log.Panicln("结存查询失败:", err)
 		orm.Rollback()
@@ -169,6 +181,9 @@ func (service *BalanceService) UseUserDetailed(balanceData *resourcesCenter.Bala
 		orm.Rollback()
 		return entity.ErrorCode, "新增流水失败"
 	}
+	if deductionNumb==0{
+		return entity.SuccessCode, "修改结存成功"
+	}
 	//修改结存
 	balanceList := []entity.Balance{}
 	err = orm.Table(AccountResources).