浏览代码

wip:调整认领返回值

fuwencai 3 年之前
父节点
当前提交
8f0e290bf0

+ 7 - 1
api/medical/internal/logic/public/distributorclaimlogic.go

@@ -34,8 +34,14 @@ func (l *DistributorClaimLogic) DistributorClaim(req *types.ClaimReq) (resp *typ
 		AppId:  req.AppId,
 	})
 	if err != nil || rs == nil {
+		errMsg := ""
+		if err == entity.RepeatErr || err == entity.OperateErr || err == entity.EntNoFoundErr {
+			errMsg = err.Error()
+		} else {
+			errMsg = entity.OperateErr.Error()
+		}
 		return &types.ClaimResp{
-			Error_msg:   "操作失败",
+			Error_msg:   errMsg,
 			Error_code:  entity.ERRORCODE,
 			ResourceNum: 0,
 			ResourceIds: 0,

+ 7 - 1
api/medical/internal/logic/public/distributorunclaimedlogic.go

@@ -34,8 +34,14 @@ func (l *DistributorUnclaimedLogic) DistributorUnclaimed(req *types.ClaimReq) (r
 		AppId:  req.AppId,
 	})
 	if err != nil || rs == nil {
+		errMsg := ""
+		if err == entity.RepeatErr || err == entity.OperateErr || err == entity.EntNoFoundErr {
+			errMsg = err.Error()
+		} else {
+			errMsg = entity.OperateErr.Error()
+		}
 		return &types.ClaimResp{
-			Error_msg:   "操作失败",
+			Error_msg:   errMsg,
 			Error_code:  entity.ERRORCODE,
 			ResourceNum: 0,
 			ResourceIds: 0,

+ 7 - 1
api/medical/internal/logic/public/institutionclaimlogic.go

@@ -34,8 +34,14 @@ func (l *InstitutionclaimLogic) Institutionclaim(req *types.ClaimReq) (resp *typ
 		AppId:  req.AppId,
 	})
 	if err != nil || rs == nil {
+		errMsg := ""
+		if err == entity.RepeatErr || err == entity.OperateErr || err == entity.EntNoFoundErr {
+			errMsg = err.Error()
+		} else {
+			errMsg = entity.OperateErr.Error()
+		}
 		return &types.ClaimResp{
-			Error_msg:   "操作失败",
+			Error_msg:   errMsg,
 			Error_code:  entity.ERRORCODE,
 			ResourceNum: 0,
 			ResourceIds: 0,

+ 7 - 1
api/medical/internal/logic/public/institutionunclaimedlogic.go

@@ -34,8 +34,14 @@ func (l *InstitutionUnclaimedLogic) InstitutionUnclaimed(req *types.ClaimReq) (r
 		AppId:  req.AppId,
 	})
 	if err != nil || rs == nil {
+		errMsg := ""
+		if err == entity.RepeatErr || err == entity.OperateErr || err == entity.EntNoFoundErr {
+			errMsg = err.Error()
+		} else {
+			errMsg = entity.OperateErr.Error()
+		}
 		return &types.ClaimResp{
-			Error_msg:   "操作失败",
+			Error_msg:   errMsg,
 			Error_code:  entity.ERRORCODE,
 			ResourceNum: 0,
 			ResourceIds: 0,

+ 8 - 0
entity/code.go

@@ -1,5 +1,7 @@
 package entity
 
+import "errors"
+
 //表代码
 const (
 	CODE_MEDICAL_INSTITUTION_LEVEL = "code_level"
@@ -32,3 +34,9 @@ const (
 	StatusClaimed   = 1  // 认领
 	StatusUnClaimed = -1 // 取消认领
 )
+
+var (
+	RepeatErr     = errors.New("重复操作")
+	OperateErr    = errors.New("操作失败")
+	EntNoFoundErr = errors.New("未查询到该企业详细信息")
+)

+ 7 - 13
rpc/medical/internal/logic/claimlogic.go

@@ -29,14 +29,9 @@ func (l *ClaimLogic) Claim(in *medical.ClaimReq) (*medical.ClaimResp, error) {
 	// 查询基本信息
 	baseInfo := l.svcCtx.EntClaimSrv.GetInstitution(in.EntId)
 	if baseInfo == nil || len(*baseInfo) == 0 {
-		return &medical.ClaimResp{
-			ErrorMsg:    "无效的企业id",
-			ErrorCode:   entity.ERRORCODE,
-			ResourceNum: 0,
-			ResourceIds: 0,
-		}, nil
+		return nil, entity.EntNoFoundErr
 	}
-	rs := l.svcCtx.EntClaimSrv.Claim(&entity.EntClaim{
+	rs, err := l.svcCtx.EntClaimSrv.Claim(&entity.EntClaim{
 		AppId:      in.AppId,
 		UserId:     int(in.UserId),
 		EntId:      in.EntId,
@@ -46,12 +41,11 @@ func (l *ClaimLogic) Claim(in *medical.ClaimReq) (*medical.ClaimResp, error) {
 		CreateTime: date.NowFormat(date.Date_Full_Layout),
 	})
 	if rs < 0 {
-		return &medical.ClaimResp{
-			ErrorMsg:    "操作失败",
-			ErrorCode:   entity.ERRORCODE,
-			ResourceNum: 0,
-			ResourceIds: 0,
-		}, nil
+		return nil, entity.OperateErr
+	}
+	if err != nil {
+		return nil, entity.RepeatErr
+
 	}
 	return &medical.ClaimResp{
 		ErrorMsg:    "",

+ 1 - 7
rpc/medical/internal/logic/unclaimedlogic.go

@@ -5,7 +5,6 @@ import (
 	"bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/rpc/medical/internal/svc"
 	"bp.jydev.jianyu360.cn/ApplicationCenter/medicalField/rpc/medical/medical"
 	"context"
-
 	"github.com/zeromicro/go-zero/core/logx"
 )
 
@@ -27,12 +26,7 @@ func NewUnClaimedLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UnClaim
 func (l *UnClaimedLogic) UnClaimed(in *medical.ClaimReq) (*medical.ClaimResp, error) {
 	rs, id := l.svcCtx.EntClaimSrv.UnclaimedByEnt(int(in.UserId), in.EntId, int(in.Type))
 	if !rs {
-		return &medical.ClaimResp{
-			ErrorMsg:    "操作失败",
-			ErrorCode:   entity.ERRORCODE,
-			ResourceNum: 0,
-			ResourceIds: 0,
-		}, nil
+		return nil, entity.OperateErr
 	}
 	return &medical.ClaimResp{
 		ErrorMsg:    "",

+ 3 - 3
service/claim.go

@@ -22,11 +22,11 @@ func NewEntClaimSrv(conn *entity.Conn) *EntClaimService {
 }
 
 // Claim 认领
-func (e *EntClaimService) Claim(data *entity.EntClaim) int64 {
+func (e *EntClaimService) Claim(data *entity.EntClaim) (int64, error) {
 	if e.IsClaimed(data.UserId, data.AppId, data.EntId, data.Type) {
-		return 0
+		return 0, entity.RepeatErr
 	}
-	return e.BaseMysql.Insert(entity.TableDomainEntClaim, common.StructToMapMore(data))
+	return e.BaseMysql.Insert(entity.TableDomainEntClaim, common.StructToMapMore(data)), nil
 }
 
 // Unclaimed // 取消认领

+ 31 - 33
service/claim_test.go

@@ -117,36 +117,6 @@ func TestEntClaimService_IsClaimed(t *testing.T) {
 	}
 }
 
-// 取消认领
-func TestEntClaimService_Unclaimed(t *testing.T) {
-	type args struct {
-		id     int
-		userId int
-	}
-	tests := []struct {
-		name string
-		args args
-		want bool
-	}{
-		{
-			"取消认领", args{userId: 1, id: 2}, true,
-		},
-		{
-			"取消认领-2", args{userId: 100, id: 2}, false,
-		},
-		{
-			"取消认领-3", args{userId: 100, id: 900009}, false,
-		},
-	}
-	for _, tt := range tests {
-		t.Run(tt.name, func(t *testing.T) {
-			if got := EntClaimSrv.Unclaimed(tt.args.id, tt.args.userId); got != tt.want {
-				t.Errorf("Unclaimed() = %v, want %v", got, tt.want)
-			}
-		})
-	}
-}
-
 // 获取企业基本信息
 func TestEntClaimService_GetInstitution(t *testing.T) {
 	type args struct {
@@ -171,8 +141,9 @@ func TestEntClaimService_GetInstitution(t *testing.T) {
 }
 func TestName(t *testing.T) {
 	s := encrypt.SE.DecodeString("QgpHCARNUAdXBRVXSF9URFMIAwIRVxIPVExUVlMEQV0=")
-	//s1 := encrypt.SE.Encode2Hex(common.ObjToString("001d050b"))
-	fmt.Print(s, 2)
+	s1 := encrypt.SE.EncodeString("90058")
+	fmt.Println(s)
+	fmt.Println(s1)
 }
 
 func TestEntClaimService_GetInstitutionByIds(t *testing.T) {
@@ -185,7 +156,7 @@ func TestEntClaimService_GetInstitutionByIds(t *testing.T) {
 		args args
 	}{
 		{
-			"获取企业基本信息", args{ids: []string{"6e7fa9b7f0a88110a827e8ba18ffb1522"}},
+			"获取企业基本信息", args{ids: []string{"6e7fa9b7f0a88110a827e8ba18ffb152"}},
 		},
 	}
 	for _, tt := range tests {
@@ -195,3 +166,30 @@ func TestEntClaimService_GetInstitutionByIds(t *testing.T) {
 		})
 	}
 }
+
+func TestEntClaimService_UnclaimedByEnt(t *testing.T) {
+
+	type args struct {
+		userId int
+		entId  string
+		type_  int
+	}
+	tests := []struct {
+		name  string
+		args  args
+		want  bool
+		want1 int
+	}{}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+
+			got, got1 := EntClaimSrv.UnclaimedByEnt(tt.args.userId, tt.args.entId, tt.args.type_)
+			if got != tt.want {
+				t.Errorf("UnclaimedByEnt() got = %v, want %v", got, tt.want)
+			}
+			if got1 != tt.want1 {
+				t.Errorf("UnclaimedByEnt() got1 = %v, want %v", got1, tt.want1)
+			}
+		})
+	}
+}

+ 39 - 10
test/api_test.http

@@ -1,29 +1,58 @@
-### 认领
-POST http://{{host}}/domain/claim
+### 机构认领
+POST http://{{host}}/domain/institution/claim
 Content-Type: application/json
-Cookie: SESSIONID=16240cfcc75bc0fb879bc9ea90e44d06c158b7d8
-newUserId:68819
+Cookie: SESSIONID=8699c0583e3caa719ac2da5a85c560852ff7da33
+newUserId:72896
 appId:10000
 
 {
-"ent_id": "1057165a5d1556510256475a470a554c030255534557480d0645065555004658",
-"type": 1
+"ent_id": "F1tGCFAQAQIFDEMKRA8ETQAJCVESWRJYBxdXVVcEEV0"
 }
+
 > {%
 client.test("Request executed successfully", function() {
   client.assert(response.status === 200, "Response status is not 200");
 });
 %}
+### 经销商认领
+POST http://{{host}}/domain/distributor/claim
+Content-Type: application/json
+Cookie: SESSIONID=8699c0583e3caa719ac2da5a85c560852ff7da33
+newUserId:2022
+appId:10000
 
-### 取消认领
-POST http://{{host}}/domain/unclaimed
+{
+  "ent_id": "EV4WD1AVBANQUxVcQ1lWEVYFAA1GXEBZXRFRUQJTQF4="
+}
+> {%
+client.test("Request executed successfully", function() {
+  client.assert(response.status === 200, "Response status is not 200");
+});
+%}
+### 机构取消认领
+POST http://{{host}}/domain/institution/unclaimed
 Content-Type: application/json
 Cookie:
-newUserId:22
+newUserId:2022
+appId:10000
+
+{
+  "ent_id":"F1tGCFAQAQIFDEMKRA8ETQAJCVESWRJYBxdXVVcEEV0="
+}
+> {%
+client.test("Request executed successfully", function() {
+  client.assert(response.status === 200, "Response status is not 200");
+});
+%}
+### 经销商取消认领
+POST http://{{host}}/domain/distributor/unclaimed
+Content-Type: application/json
+Cookie:
+newUserId:2022
 appId:10000
 
 {
-  "id":"4d5f405f52"
+  "ent_id":"F1tGCFAQAQIFDEMKRA8ETQAJCVESWRJYBxdXVVcEEV0="
 }
 > {%
 client.test("Request executed successfully", function() {

+ 1 - 1
test/http-client.env.json

@@ -1,6 +1,6 @@
 {
   "dev": {
-    "host": "127.0.0.1:8881"
+    "host": "192.168.150.47:8881"
   },
   "proxy240": {
     "host": "192.168.3.240:8077"