Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
chaincode
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
刘星星@五瓣科技
chaincode
Commits
e42f3037
Commit
e42f3037
authored
Mar 09, 2021
by
刘星星@五瓣科技
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add retrospect chaincode error info
parent
7900ce74
Changes
3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
107 additions
and
86 deletions
+107
-86
workspace.xml
.idea/workspace.xml
+84
-69
restropect_test.go
src/retrospect_chain/restropect_test.go
+2
-2
retrospect.go
src/retrospect_chain/retrospect.go
+21
-15
No files found.
.idea/workspace.xml
View file @
e42f3037
This diff is collapsed.
Click to expand it.
src/retrospect_chain/restropect_test.go
View file @
e42f3037
...
@@ -42,7 +42,7 @@ var(
...
@@ -42,7 +42,7 @@ var(
qualityTesting
=
`{"qtId":"1101","qtOrgName":"qtOrgName","qtMethod":"qtOrgName","qtDate":"qtOrgName","qtResult":"qtOrgName","qtUser":"qtUser","qtReport":"qtUser","waterReport":["speciesDesc","speciesDesc"],"landReport":["speciesDesc","speciesDesc"],"airReport":["speciesDesc","speciesDesc"]}`
qualityTesting
=
`{"qtId":"1101","qtOrgName":"qtOrgName","qtMethod":"qtOrgName","qtDate":"qtOrgName","qtResult":"qtOrgName","qtUser":"qtUser","qtReport":"qtUser","waterReport":["speciesDesc","speciesDesc"],"landReport":["speciesDesc","speciesDesc"],"airReport":["speciesDesc","speciesDesc"]}`
packagingInfo
=
`{"packid":"1101","cid":"1101","baseId":"baseId","plotId":"plotId","sid":"1101","bno":"1102","packInfo":"packInfo","bizType":"bizType","pno":"bizType","packCount":0,"packUnit":"packUnit","packDate":"packUnit","packPics":["speciesDesc","speciesDesc"],"principalId":"packUnit","principal":"packUnit"}`
packagingInfo
=
`{"packid":"1101","cid":"1101","baseId":"baseId","plotId":"plotId","sid":"1101","bno":"1102","packInfo":"packInfo","bizType":"bizType","pno":"bizType","packCount":0,"packUnit":"packUnit","packDate":"packUnit","packPics":["speciesDesc","speciesDesc"],"principalId":"packUnit","principal":"packUnit"}`
salesInfo
=
`{"id":"1101","cid":"1101","baseId":"baseId","plotId":"plotId","sid":"sid","bno":"1101","saleInfo":"saleInfo","bizType":"bizType","sno":"1101","customer":"customer","saleCount":0,"packingSize":"customer","saleDate":"saleDate","salePics":"salePics","trackingNo":"trackingNo","logisticsName":"logisticsName","did":0,"principalId":"principalId","principal":"principalId","commissionRatio":0}`
salesInfo
=
`{"id":"1101","cid":"1101","baseId":"baseId","plotId":"plotId","sid":"sid","bno":"1101","saleInfo":"saleInfo","bizType":"bizType","sno":"1101","customer":"customer","saleCount":0,"packingSize":"customer","saleDate":"saleDate","salePics":"salePics","trackingNo":"trackingNo","logisticsName":"logisticsName","did":0,"principalId":"principalId","principal":"principalId","commissionRatio":0}`
qrcode
=
`{"p_no":"1102","start_number":0,"count":100,"product_show":{"product_name":true,"pick_date":true,"expiration_date":10,"product_type":true,"product_no":true,"stoage_mode":"低温保存","product_des":true,"product_files":["speciesDesc","speciesDesc"]},"retrospect_show":{"base_name":"1101","polt_name":"1101","species_name":"1101","plant_activity":"1101","plant_test":"1101","plant_pick":"1101",
qrcode
=
`{"p_no":"1102","start_number":
10
0,"count":100,"product_show":{"product_name":true,"pick_date":true,"expiration_date":10,"product_type":true,"product_no":true,"stoage_mode":"低温保存","product_des":true,"product_files":["speciesDesc","speciesDesc"]},"retrospect_show":{"base_name":"1101","polt_name":"1101","species_name":"1101","plant_activity":"1101","plant_test":"1101","plant_pick":"1101",
"quality_test":"1101","packaging":"1101","sale_info":"1101","logistics_info":false,"base_files":["speciesDesc","speciesDesc"]},"quality_test_show":{"qtId":"1101","detection":false,"detection_mode":false,"detection_tiem":false,"detection_result":false,"detection_people":false,"detection_paper":false,"land_detection_paper":false,"write_detection_paper":false,"air_detection_paper":false},"company_show":
"quality_test":"1101","packaging":"1101","sale_info":"1101","logistics_info":false,"base_files":["speciesDesc","speciesDesc"]},"quality_test_show":{"qtId":"1101","detection":false,"detection_mode":false,"detection_tiem":false,"detection_result":false,"detection_people":false,"detection_paper":false,"land_detection_paper":false,"write_detection_paper":false,"air_detection_paper":false},"company_show":
{"cid":"1101","principal":false,"principal_phone":false,"company_name":false,"company_person":false,"company_address":false,"company_intro":false,"business_license":false}}`
{"cid":"1101","principal":false,"principal_phone":false,"company_name":false,"company_person":false,"company_address":false,"company_intro":false,"business_license":false}}`
)
)
...
@@ -201,7 +201,7 @@ func TestAddActivityInfo(t *testing.T) {
...
@@ -201,7 +201,7 @@ func TestAddActivityInfo(t *testing.T) {
}
else
if
print
{
}
else
if
print
{
fmt
.
Println
(
string
(
resSearch
.
Payload
))
fmt
.
Println
(
string
(
resSearch
.
Payload
))
}
}
resSearch1
:=
stub
.
MockInvoke
(
"invoke1"
,[][]
byte
{[]
byte
(
"searchRespectInfo"
),[]
byte
(
"1102"
),[]
byte
(
"
8
9"
)})
resSearch1
:=
stub
.
MockInvoke
(
"invoke1"
,[][]
byte
{[]
byte
(
"searchRespectInfo"
),[]
byte
(
"1102"
),[]
byte
(
"
10
9"
)})
if
resSearch1
.
Status
!=
200
{
if
resSearch1
.
Status
!=
200
{
//testResult = false
//testResult = false
t
.
Error
(
resSearch1
.
Message
)
t
.
Error
(
resSearch1
.
Message
)
...
...
src/retrospect_chain/retrospect.go
View file @
e42f3037
...
@@ -546,7 +546,11 @@ func TestCheck(args []string, stub shim.ChaincodeStubInterface) pb.Response {
...
@@ -546,7 +546,11 @@ func TestCheck(args []string, stub shim.ChaincodeStubInterface) pb.Response {
if
len
(
args
)
==
0
{
if
len
(
args
)
==
0
{
return
shim
.
Success
([]
byte
(
"参数内容为空"
))
return
shim
.
Success
([]
byte
(
"参数内容为空"
))
}
}
return
shim
.
Success
([]
byte
(
args
[
0
]))
str
:=
""
for
_
,
arg
:=
range
args
{
str
+=
arg
}
return
shim
.
Success
([]
byte
(
str
))
}
}
/*
/*
...
@@ -1057,10 +1061,9 @@ func SearchRespectInfo(args []string, stub shim.ChaincodeStubInterface) pb.Respo
...
@@ -1057,10 +1061,9 @@ func SearchRespectInfo(args []string, stub shim.ChaincodeStubInterface) pb.Respo
showByte
,
err
:=
getStateByte
(
showKey
,
stub
)
showByte
,
err
:=
getStateByte
(
showKey
,
stub
)
qr
:=
&
SearchQrCode
{}
qr
:=
&
SearchQrCode
{}
if
showByte
!=
nil
{
if
showByte
!=
nil
{
err
=
json
.
Unmarshal
(
showByte
,
qr
)
err
=
json
.
Unmarshal
(
showByte
,
qr
)
if
err
!=
nil
{
if
err
!=
nil
{
return
shim
.
Error
(
err
.
Error
())
return
shim
.
Error
(
"unmarshal happen error"
+
err
.
Error
())
}
}
qr
.
Count
+=
1
qr
.
Count
+=
1
}
else
{
}
else
{
...
@@ -1119,19 +1122,19 @@ func extractRespectShowInfo(qrcode *QrCode, stub shim.ChaincodeStubInterface)(qr
...
@@ -1119,19 +1122,19 @@ func extractRespectShowInfo(qrcode *QrCode, stub shim.ChaincodeStubInterface)(qr
companyKey
:=
CompanyInfoKey
+
"_"
+
qrcode
.
CompanyShow
.
Cid
companyKey
:=
CompanyInfoKey
+
"_"
+
qrcode
.
CompanyShow
.
Cid
compResult
,
err
:=
getStateByte
(
companyKey
,
stub
)
compResult
,
err
:=
getStateByte
(
companyKey
,
stub
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
ors
.
New
(
"get company "
+
companyKey
+
" happen err"
+
err
.
Error
())
}
}
company
:=
&
CompanyInfo
{}
company
:=
&
CompanyInfo
{}
err
=
json
.
Unmarshal
(
compResult
,
company
)
err
=
json
.
Unmarshal
(
compResult
,
company
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
ors
.
New
(
"unmarshal company "
+
companyKey
+
" happen err"
+
err
.
Error
())
}
}
sqrcode
.
CompanyShow
=
company
sqrcode
.
CompanyShow
=
company
//step 2: 查询质检信息
//step 2: 查询质检信息
qualityKey
:=
QualityTestInfoKey
+
"_"
+
qrcode
.
QualityTestShow
.
QtId
qualityKey
:=
QualityTestInfoKey
+
"_"
+
qrcode
.
QualityTestShow
.
QtId
qualityResult
,
err
:=
getStateByte
(
qualityKey
,
stub
)
qualityResult
,
err
:=
getStateByte
(
qualityKey
,
stub
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
ors
.
New
(
"get qualityTest "
+
qualityKey
+
" happen err"
+
err
.
Error
())
}
}
quality
:=
&
QualityTesting
{}
quality
:=
&
QualityTesting
{}
err
=
json
.
Unmarshal
(
qualityResult
,
quality
)
err
=
json
.
Unmarshal
(
qualityResult
,
quality
)
...
@@ -1153,7 +1156,7 @@ func extractRespectShowInfo(qrcode *QrCode, stub shim.ChaincodeStubInterface)(qr
...
@@ -1153,7 +1156,7 @@ func extractRespectShowInfo(qrcode *QrCode, stub shim.ChaincodeStubInterface)(qr
baseKey
:=
BaseInfoKey
+
"_"
+
qrcode
.
RetrospectShow
.
BaseName
baseKey
:=
BaseInfoKey
+
"_"
+
qrcode
.
RetrospectShow
.
BaseName
baseResult
,
err
:=
getStateByte
(
baseKey
,
stub
)
baseResult
,
err
:=
getStateByte
(
baseKey
,
stub
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
ors
.
New
(
"get baseInfo "
+
baseKey
+
" happen err"
+
err
.
Error
())
}
}
base
:=
&
BaseInfo
{}
base
:=
&
BaseInfo
{}
err
=
json
.
Unmarshal
(
baseResult
,
base
)
err
=
json
.
Unmarshal
(
baseResult
,
base
)
...
@@ -1166,7 +1169,7 @@ func extractRespectShowInfo(qrcode *QrCode, stub shim.ChaincodeStubInterface)(qr
...
@@ -1166,7 +1169,7 @@ func extractRespectShowInfo(qrcode *QrCode, stub shim.ChaincodeStubInterface)(qr
plotKey
:=
PlotInfoKey
+
"_"
+
qrcode
.
RetrospectShow
.
PlotName
plotKey
:=
PlotInfoKey
+
"_"
+
qrcode
.
RetrospectShow
.
PlotName
plotResult
,
err
:=
getStateByte
(
plotKey
,
stub
)
plotResult
,
err
:=
getStateByte
(
plotKey
,
stub
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
ors
.
New
(
"get plotInfo "
+
plotKey
+
" happen err"
+
err
.
Error
())
}
}
plot
:=
&
PlotInfo
{}
plot
:=
&
PlotInfo
{}
err
=
json
.
Unmarshal
(
plotResult
,
plot
)
err
=
json
.
Unmarshal
(
plotResult
,
plot
)
...
@@ -1180,7 +1183,7 @@ func extractRespectShowInfo(qrcode *QrCode, stub shim.ChaincodeStubInterface)(qr
...
@@ -1180,7 +1183,7 @@ func extractRespectShowInfo(qrcode *QrCode, stub shim.ChaincodeStubInterface)(qr
speciesKey
:=
PeciesInfoKey
+
"_"
+
qrcode
.
RetrospectShow
.
SpeciesName
speciesKey
:=
PeciesInfoKey
+
"_"
+
qrcode
.
RetrospectShow
.
SpeciesName
speciesResult
,
err
:=
getStateByte
(
speciesKey
,
stub
)
speciesResult
,
err
:=
getStateByte
(
speciesKey
,
stub
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
ors
.
New
(
"get peciesInfo "
+
speciesKey
+
" happen err"
+
err
.
Error
())
}
}
pecies
:=
&
Pecies
{}
pecies
:=
&
Pecies
{}
err
=
json
.
Unmarshal
(
speciesResult
,
pecies
)
err
=
json
.
Unmarshal
(
speciesResult
,
pecies
)
...
@@ -1195,7 +1198,7 @@ func extractRespectShowInfo(qrcode *QrCode, stub shim.ChaincodeStubInterface)(qr
...
@@ -1195,7 +1198,7 @@ func extractRespectShowInfo(qrcode *QrCode, stub shim.ChaincodeStubInterface)(qr
planttestKey
:=
QuarantineInfoKey
+
"_"
+
qrcode
.
RetrospectShow
.
PlantTest
planttestKey
:=
QuarantineInfoKey
+
"_"
+
qrcode
.
RetrospectShow
.
PlantTest
planttestResult
,
err
:=
getStateByte
(
planttestKey
,
stub
)
planttestResult
,
err
:=
getStateByte
(
planttestKey
,
stub
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
ors
.
New
(
"get quarantineInfo "
+
planttestKey
+
" happen err"
+
err
.
Error
())
}
}
quar
:=
&
QuarantineInfo
{}
quar
:=
&
QuarantineInfo
{}
err
=
json
.
Unmarshal
(
planttestResult
,
quar
)
err
=
json
.
Unmarshal
(
planttestResult
,
quar
)
...
@@ -1208,7 +1211,7 @@ func extractRespectShowInfo(qrcode *QrCode, stub shim.ChaincodeStubInterface)(qr
...
@@ -1208,7 +1211,7 @@ func extractRespectShowInfo(qrcode *QrCode, stub shim.ChaincodeStubInterface)(qr
pickKey
:=
PlantingHarvesInfoKey
+
"_"
+
qrcode
.
RetrospectShow
.
PlantPick
pickKey
:=
PlantingHarvesInfoKey
+
"_"
+
qrcode
.
RetrospectShow
.
PlantPick
planttestResult
,
err
:=
getStateByte
(
pickKey
,
stub
)
planttestResult
,
err
:=
getStateByte
(
pickKey
,
stub
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
ors
.
New
(
"get plantingHarvesInfo "
+
pickKey
+
" happen err"
+
err
.
Error
())
}
}
harves
:=
&
Harvesinfo
{}
harves
:=
&
Harvesinfo
{}
err
=
json
.
Unmarshal
(
planttestResult
,
harves
)
err
=
json
.
Unmarshal
(
planttestResult
,
harves
)
...
@@ -1225,7 +1228,7 @@ func extractRespectShowInfo(qrcode *QrCode, stub shim.ChaincodeStubInterface)(qr
...
@@ -1225,7 +1228,7 @@ func extractRespectShowInfo(qrcode *QrCode, stub shim.ChaincodeStubInterface)(qr
packKey
:=
PackingInfoKey
+
"_"
+
qrcode
.
RetrospectShow
.
Packaging
packKey
:=
PackingInfoKey
+
"_"
+
qrcode
.
RetrospectShow
.
Packaging
packResult
,
err
:=
getStateByte
(
packKey
,
stub
)
packResult
,
err
:=
getStateByte
(
packKey
,
stub
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
ors
.
New
(
"get packingInfo "
+
packKey
+
" happen err"
+
err
.
Error
())
}
}
packing
:=
&
PackagingInfo
{}
packing
:=
&
PackagingInfo
{}
err
=
json
.
Unmarshal
(
packResult
,
packing
)
err
=
json
.
Unmarshal
(
packResult
,
packing
)
...
@@ -1269,7 +1272,7 @@ func getActivitys(objectType string,activityKey []string,stub shim.ChaincodeStub
...
@@ -1269,7 +1272,7 @@ func getActivitys(objectType string,activityKey []string,stub shim.ChaincodeStub
activitys
:=
make
([]
*
ActivityInfo
,
1
)
activitys
:=
make
([]
*
ActivityInfo
,
1
)
queryIterator
,
err
:=
stub
.
GetStateByPartialCompositeKey
(
objectType
,
activityKey
)
queryIterator
,
err
:=
stub
.
GetStateByPartialCompositeKey
(
objectType
,
activityKey
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
ors
.
New
(
"get activitys happen err"
+
err
.
Error
())
}
}
if
queryIterator
.
HasNext
(){
if
queryIterator
.
HasNext
(){
kv
,
err
:=
queryIterator
.
Next
()
kv
,
err
:=
queryIterator
.
Next
()
...
@@ -1283,7 +1286,7 @@ func getActivitys(objectType string,activityKey []string,stub shim.ChaincodeStub
...
@@ -1283,7 +1286,7 @@ func getActivitys(objectType string,activityKey []string,stub shim.ChaincodeStub
}
}
activitys
=
append
(
activitys
,
activity
)
activitys
=
append
(
activitys
,
activity
)
}
}
return
activitys
,
err
return
activitys
,
nil
}
}
func
getQrcode
(
args
[]
string
,
stub
shim
.
ChaincodeStubInterface
)(
qrCode
*
QrCode
,
err
error
)
{
func
getQrcode
(
args
[]
string
,
stub
shim
.
ChaincodeStubInterface
)(
qrCode
*
QrCode
,
err
error
)
{
...
@@ -1306,7 +1309,7 @@ func getQrcode(args []string, stub shim.ChaincodeStubInterface)(qrCode *QrCode ,
...
@@ -1306,7 +1309,7 @@ func getQrcode(args []string, stub shim.ChaincodeStubInterface)(qrCode *QrCode ,
}
}
result
:=
SearchQrKey
(
startNum
,
qr
.
StartNumber
)
result
:=
SearchQrKey
(
startNum
,
qr
.
StartNumber
)
if
result
==
-
1
{
if
result
==
-
1
{
return
nil
,
errors
.
New
(
fmt
.
Sprintf
(
"
Unmarshal QrKey fail,err %s "
,
err
))
return
nil
,
errors
.
New
(
fmt
.
Sprintf
(
"
invalid start-number,please redo "
))
}
}
numKey
:=
strconv
.
FormatInt
(
result
,
10
)
numKey
:=
strconv
.
FormatInt
(
result
,
10
)
qrcodeyKey
,
err
:=
stub
.
CreateCompositeKey
(
ReprospectInfoKey
,
[]
string
{
args
[
0
],
numKey
})
qrcodeyKey
,
err
:=
stub
.
CreateCompositeKey
(
ReprospectInfoKey
,
[]
string
{
args
[
0
],
numKey
})
...
@@ -1332,6 +1335,9 @@ func SearchQrKey(startNum int64,s []int64)int64{
...
@@ -1332,6 +1335,9 @@ func SearchQrKey(startNum int64,s []int64)int64{
return
-
1
return
-
1
}
}
if
len
(
s
)
==
1
{
if
len
(
s
)
==
1
{
if
startNum
<
s
[
0
]{
return
-
1
}
return
s
[
0
]
//最接近starNum 并且小于它
return
s
[
0
]
//最接近starNum 并且小于它
}
}
middle
:=
len
(
s
)
/
2
middle
:=
len
(
s
)
/
2
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment