WH01243 преди 4 години
родител
ревизия
016d06ffde

+ 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,

+ 22 - 10
rpc/test/company_test.go

@@ -2,15 +2,13 @@ package test
 
 import (
 	"app.yhyue.com/moapp/jyResourcesCenter/rpc/internal/config"
-	"app.yhyue.com/moapp/jyResourcesCenter/rpc/resourcesCenter"
-	"app.yhyue.com/moapp/jyResourcesCenter/rpc/resourcesCenterclient"
-	"context"
 	"flag"
+	"fmt"
 	"github.com/tal-tech/go-zero/core/conf"
-	"github.com/tal-tech/go-zero/zrpc"
-	"log"
+	"io/ioutil"
+	"net/http"
+	"strings"
 	"testing"
-	"time"
 )
 
 var configFile = flag.String("f", "resourcescenter.yaml", "the config file")
@@ -39,7 +37,7 @@ string //剑鱼标识
 Modelcode
 int64  //操作类型0使用1新增*/
 //修改结存
-func Test_UpdateUserBalance(t *testing.T) {
+/*func Test_UpdateUserBalance(t *testing.T) {
 	ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
 	FileSystem := resourcesCenterclient.NewResourcesCenter(zrpc.MustNewClient(c.FileSystemConf))
 	req := &resourcesCenter.Balance{
@@ -57,7 +55,7 @@ func Test_UpdateUserBalance(t *testing.T) {
 	log.Println("err ", err)
 	log.Println("req ", res)
 }
-
+*/
 /*AccountId
 int64  //账户标识
 CompanyId
@@ -77,7 +75,7 @@ int64  //流水类型0使用1新增
 DepartmentId
 int64  //组织标识*/
 func Test_UpdateUserDetailed(t *testing.T) {
-	ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
+	/*ctx, _ := context.WithTimeout(context.Background(), 5*time.Second)
 	FileSystem := resourcesCenterclient.NewResourcesCenter(zrpc.MustNewClient(c.FileSystemConf))
 	req := &resourcesCenter.Detailed{
 		AccountId:     "111",
@@ -92,5 +90,19 @@ func Test_UpdateUserDetailed(t *testing.T) {
 	}
 	res, err := FileSystem.UpdateUserDetailed(ctx, req)
 	log.Println("err ", err)
-	log.Println("req ", res)
+	log.Println("req ", res)*/
+	url:="http://127.0.0.1:4888/data/dedupAndSave"
+	contentType := "application/json"
+	//参数,多个用&隔开
+	data := strings.NewReader("personId=123&&infoId=1,2,3&&accountId=12")
+	resp, err := http.Post(url, contentType, data)
+	if err != nil {
+		fmt.Println(err)
+	}
+	defer resp.Body.Close()
+	body, err := ioutil.ReadAll(resp.Body)
+	if err != nil {
+		fmt.Println(err)
+	}
+	fmt.Println(string(body))
 }

+ 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

+ 23 - 5
service/balanceService.go

@@ -3,8 +3,11 @@ package service
 import (
 	"app.yhyue.com/moapp/jyResourcesCenter/entity"
 	"app.yhyue.com/moapp/jyResourcesCenter/rpc/resourcesCenter"
+	"encoding/json"
 	"fmt"
+	"io/ioutil"
 	"log"
+	"net/http"
 	"strconv"
 	"time"
 )
@@ -113,22 +116,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()
@@ -165,6 +180,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).