add medical_chain and retrospect_chain code

parent edefc740
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/medical_chain.iml" filepath="$PROJECT_DIR$/.idea/medical_chain.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="7b46a258-f19a-4e73-869b-1b6ecc59a654" name="Default Changelist" comment="" />
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="375">
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/medical.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="2592">
<caret line="151" column="36" selection-start-line="134" selection-start-column="4" selection-end-line="151" selection-end-column="36" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/medical_test.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="290">
<caret line="115" column="5" lean-forward="true" selection-start-line="103" selection-start-column="4" selection-end-line="115" selection-end-column="5" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/../hyperledger/fabric/protos/peer/proposal_response.pb.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="2016">
<caret line="115" column="4" selection-start-line="115" selection-start-column="4" selection-end-line="115" selection-end-column="4" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/../hyperledger/fabric/core/chaincode/shim/response.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="558">
<caret line="33" column="5" selection-start-line="33" selection-start-column="5" selection-end-line="33" selection-end-column="5" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/../hyperledger/fabric/core/chaincode/shim/interfaces.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="6606">
<caret line="371" column="4" selection-start-line="371" selection-start-column="4" selection-end-line="371" selection-end-column="4" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/../hyperledger/fabric/core/chaincode/shim/chaincode.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1908">
<caret line="130" column="16" selection-start-line="130" selection-start-column="16" selection-end-line="130" selection-end-column="16" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/../hyperledger/fabric/core/chaincode/shim/mockstub.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="2232">
<caret line="135" column="22" selection-start-line="135" selection-start-column="22" selection-end-line="135" selection-end-column="22" />
</state>
</provider>
</entry>
</file>
</leaf>
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Go File" />
</list>
</option>
</component>
<component name="FindInProjectRecents">
<findStrings>
<find>invoiceNo</find>
<find>The query information is empty</find>
</findStrings>
</component>
<component name="GOROOT" path="/usr/local/go" />
<component name="GoLibraries">
<option name="indexEntireGoPath" value="false" />
</component>
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/medical.go" />
<option value="$PROJECT_DIR$/medical_test.go" />
</list>
</option>
</component>
<component name="ProjectFrameBounds" extendedState="6">
<option name="x" value="120" />
<option name="y" value="33" />
<option name="width" value="1647" />
<option name="height" value="862" />
</component>
<component name="ProjectView">
<navigator proportions="" version="1">
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="ProjectPane">
<subPane>
<expand>
<path>
<item name="medical_chain" type="b2602c69:ProjectViewProjectNode" />
<item name="medical_chain" type="462c0819:PsiDirectoryNode" />
</path>
</expand>
<select />
</subPane>
</pane>
<pane id="Scope" />
</panes>
</component>
<component name="PropertiesComponent">
<property name="DefaultGoTemplateProperty" value="Go File" />
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="go.gopath.indexing.explicitly.defined" value="true" />
<property name="go.import.settings.migrated" value="true" />
<property name="go.sdk.automatically.set" value="true" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
<property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
<property name="nodejs_npm_path_reset_for_default_project" value="true" />
</component>
<component name="RunDashboard">
<option name="ruleStates">
<list>
<RuleState>
<option name="name" value="ConfigurationTypeDashboardGroupingRule" />
</RuleState>
<RuleState>
<option name="name" value="StatusDashboardGroupingRule" />
</RuleState>
</list>
</option>
</component>
<component name="RunManager" selected="Go Test.TestSearchTransferListByInvoiceNo in github.com/medical_chain">
<configuration name="TestJsonByte in github.com/medical_chain" type="GoTestRunConfiguration" factoryName="Go Test" temporary="true" nameIsGenerated="true">
<module name="medical_chain" />
<working_directory value="$PROJECT_DIR$" />
<framework value="gotest" />
<kind value="PACKAGE" />
<package value="github.com/medical_chain" />
<directory value="$PROJECT_DIR$/" />
<filePath value="$PROJECT_DIR$/" />
<pattern value="^TestJsonByte$" />
<method v="2" />
</configuration>
<configuration name="TestSearchTransferListByInvoiceNo in github.com/medical_chain" type="GoTestRunConfiguration" factoryName="Go Test" temporary="true" nameIsGenerated="true">
<module name="medical_chain" />
<working_directory value="$PROJECT_DIR$" />
<framework value="gotest" />
<kind value="PACKAGE" />
<package value="github.com/medical_chain" />
<directory value="$PROJECT_DIR$/" />
<filePath value="$PROJECT_DIR$/" />
<pattern value="^TestSearchTransferListByInvoiceNo$" />
<method v="2" />
</configuration>
<recent_temporary>
<list>
<item itemvalue="Go Test.TestSearchTransferListByInvoiceNo in github.com/medical_chain" />
<item itemvalue="Go Test.TestJsonByte in github.com/medical_chain" />
</list>
</recent_temporary>
</component>
<component name="TestHistory">
<history-entry file="TestSearchTransferListByInvoiceNo_in_github_com_medical_chain - 2020.11.13 at 15h 30m 51s.xml">
<configuration name="TestSearchTransferListByInvoiceNo in github.com/medical_chain" configurationId="GoTestRunConfiguration" />
</history-entry>
<history-entry file="TestSearchTransferListByInvoiceNo_in_github_com_medical_chain - 2020.11.13 at 15h 31m 44s.xml">
<configuration name="TestSearchTransferListByInvoiceNo in github.com/medical_chain" configurationId="GoTestRunConfiguration" />
</history-entry>
<history-entry file="TestSearchTransferListByInvoiceNo_in_github_com_medical_chain - 2020.11.13 at 15h 32m 12s.xml">
<configuration name="TestSearchTransferListByInvoiceNo in github.com/medical_chain" configurationId="GoTestRunConfiguration" />
</history-entry>
<history-entry file="TestSearchTransferListByInvoiceNo_in_github_com_medical_chain - 2020.11.13 at 15h 35m 58s.xml">
<configuration name="TestSearchTransferListByInvoiceNo in github.com/medical_chain" configurationId="GoTestRunConfiguration" />
</history-entry>
<history-entry file="TestJsonByte_in_github_com_medical_chain - 2020.11.13 at 15h 55m 23s.xml">
<configuration name="TestJsonByte in github.com/medical_chain" configurationId="GoTestRunConfiguration" />
</history-entry>
<history-entry file="TestSearchTransferListByInvoiceNo_in_github_com_medical_chain - 2020.11.13 at 15h 56m 07s.xml">
<configuration name="TestSearchTransferListByInvoiceNo in github.com/medical_chain" configurationId="GoTestRunConfiguration" />
</history-entry>
<history-entry file="TestSearchTransferListByInvoiceNo_in_github_com_medical_chain - 2020.11.13 at 15h 56m 40s.xml">
<configuration name="TestSearchTransferListByInvoiceNo in github.com/medical_chain" configurationId="GoTestRunConfiguration" />
</history-entry>
<history-entry file="TestSearchTransferListByInvoiceNo_in_github_com_medical_chain - 2020.11.18 at 11h 07m 11s.xml">
<configuration name="TestSearchTransferListByInvoiceNo in github.com/medical_chain" configurationId="GoTestRunConfiguration" />
</history-entry>
<history-entry file="TestJsonByte_in_github_com_medical_chain - 2020.11.18 at 12h 15m 38s.xml">
<configuration name="TestJsonByte in github.com/medical_chain" configurationId="GoTestRunConfiguration" />
</history-entry>
<history-entry file="TestSearchTransferListByInvoiceNo_in_github_com_medical_chain - 2020.11.20 at 16h 43m 24s.xml">
<configuration name="TestSearchTransferListByInvoiceNo in github.com/medical_chain" configurationId="GoTestRunConfiguration" />
</history-entry>
</component>
<component name="ToolWindowManager">
<frame x="71" y="31" width="2489" height="1279" extended-state="6" />
<editor active="true" />
<layout>
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.13152486" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info id="Favorites" order="2" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" />
<window_info anchor="bottom" id="Run" order="2" weight="0.32919255" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.58670145" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
<window_info anchor="bottom" id="TODO" order="6" />
<window_info anchor="bottom" id="Docker" order="7" show_stripe_button="false" />
<window_info anchor="bottom" id="Version Control" order="8" />
<window_info anchor="bottom" id="Database Changes" order="9" />
<window_info anchor="bottom" id="Statistic" order="10" />
<window_info anchor="bottom" id="Terminal" order="11" weight="0.32919255" />
<window_info anchor="bottom" id="Event Log" order="12" side_tool="true" />
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
<window_info anchor="right" id="PlantUML" order="3" />
<window_info anchor="right" id="Database" order="4" />
</layout>
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="1" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/medical.go</url>
<line>171</line>
<option name="timeStamp" value="1" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/go.mod" />
<entry file="file://$PROJECT_DIR$/go.sum" />
<entry file="file://$PROJECT_DIR$/medical.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="2592">
<caret line="151" column="36" selection-start-line="134" selection-start-column="4" selection-end-line="151" selection-end-column="36" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/../hyperledger/fabric/protos/peer/proposal_response.pb.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="2016">
<caret line="115" column="4" selection-start-line="115" selection-start-column="4" selection-end-line="115" selection-end-column="4" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/../hyperledger/fabric/core/chaincode/shim/response.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="558">
<caret line="33" column="5" selection-start-line="33" selection-start-column="5" selection-end-line="33" selection-end-column="5" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/../hyperledger/fabric/core/chaincode/shim/interfaces.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="6606">
<caret line="371" column="4" selection-start-line="371" selection-start-column="4" selection-end-line="371" selection-end-column="4" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/../hyperledger/fabric/core/chaincode/shim/chaincode.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1908">
<caret line="130" column="16" selection-start-line="130" selection-start-column="16" selection-end-line="130" selection-end-column="16" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/../hyperledger/fabric/core/chaincode/shim/mockstub.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="2232">
<caret line="135" column="22" selection-start-line="135" selection-start-column="22" selection-end-line="135" selection-end-column="22" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/medical_test.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="290">
<caret line="115" column="5" lean-forward="true" selection-start-line="103" selection-start-column="4" selection-end-line="115" selection-end-column="5" />
</state>
</provider>
</entry>
</component>
</project>
\ No newline at end of file
package main
import (
"encoding/json"
"errors"
"fmt"
"github.com/hyperledger/fabric/core/chaincode/shim"
pb "github.com/hyperledger/fabric/protos/peer"
"strconv"
)
const (
CompanyInfoKey = "company_key"
BizInfoDtoKey = "biz_info_dto_key"
//ChipUsedDtoKey = "chip_used_dto_key"
UsedKey = "used_key"
InvoiceInfoDtoKey = "invoice_info_dto"
)
type Medical struct {
}
/*
公司信息
*/
type CompanyInfo struct {
Id uint64`json:"id"`
BusinessLicense string `json:"businessLicense"`
Cname string `json:"cname"`
CmpanyAddress string `json:"cmpanyAddress"`
CompanyDesc string `json:"companyDesc"`
CompanyType string `json:"companyType"`
ContactPhone string `json:"contactPhone"`
Contacts string `json:"contacts"`
LegalPerson string `json:"legalPerson"`
Status int `json:"status"`
}
//业务信息上链
type BizInfoDto struct {
Id uint64 `json:"id"` //业务信息ID.
Cid uint64 `json:"cid"` //公司ID
Cname string `json:"cname"` //公司名称.
UserId uint64 `json:"userId"` //医代Id
UserName string `json:"userName"` //医代名称
IdNo string `json:"idNo"` //身份证号
Mobile string `json:"mobile"` //手机号
Lno string `json:"lno"` //物流单号
TradeDate string `json:"tradeDate"` //交易日期
TradeAddress string `json:"tradeAddress"` //交易地址
Hospital string `json:"hospital"` //供给医院
Amount string `json:"amount"` //交易金额
Remark string `json:"remark"` //备注
CreateTime string `json:"createTime"` //创建时间
UpdateTime string `json:"updateTime"` //更新时间
ImageKeys []string `json:"imageKeys"` //上传图片Key.
FileKeys []string `json:"fileKeys"` //上传文件keys
Chips []ChipPacking `json:"chips"` //芯片包装信息.
}
//芯片包装信息.
type ChipPacking struct {
ChipSno string `json:"chipSno"`//芯片序列号
PackInfo string `json:"packInfo"`// 包装信息
PackCount uint64 `json:"packCount"`//包装数量
}
//前端芯片使用
type ChipUsedDto struct {
Lno string `json:"lno"` //物流单号
ChipSno string `json:"chipSno"` //芯片序列号
ProductNo string `json:"productNo"` //服务产品码
UserId uint64 `json:"userId"` //使用者ID
UsedTime string `json:"usedTime"` //使用时间
ImageKeys []string `json:"imageKeys"` //上传图片Key.
FileKeys []string `json:"fileKeys"` //上传文件keys
VideoKeys []string `json:"videoKeys"` //上传视频Key.
}
type FirstInvoiceInfoDto struct {
Id uint64 `json:"id"` //发票ID.
Cid uint64 `json:"cid"` //公司ID
Cname string `json:"cname"` //公司名称.
InvoiceNo string `json:"invoiceNo"` //发票单号
BillingUnit string `json:"billingUnit"` //开票单位
ReceiveUnit string `json:"receiveUnit"` //接票单位
Amount float64 `json:"amount"` //交易金额
BillingType int `json:"billingType"` //开票类型
Remark string `json:"remark"` //备注
InvoiceType int `json:"invoiceType"` // 发票类型 1公司发票 2技术人员发票
LnoKeys []string `json:"lnoKeys"` //物流单号key
ImageKeys []string `json:"imageKeys"` //上传图片Key.
FileKeys []string `json:"fileKeys"` //上传文件keys
}
type InvoiceInfoDto struct {
Id uint64 `json:"id"` //发票ID.
Cid uint64 `json:"cid"` //公司ID
Cname string `json:"cname"` //公司名称.
Uid uint64 `json:"uid"` //技术人员ID
UserName string `json:"userName"` //医代名称
IdNo string `json:"idNo"` //身份证号
Mobile string `json:"mobile"` //手机号
//TaxId string `json:"taxId"` //税号
InvoiceNo string `json:"invoiceNo"` //发票单号
Lno string `json:"lno"` //物流单号
BillingUnit string `json:"billingUnit"` //开票单位
BillingType int `json:"billingType"` //开票类型
ReceiveUnit string `json:"receiveUnit"` //接票单位
Amount float64 `json:"amount"` //交易金额
Remark string `json:"remark"` //备注
InvoiceType int `json:"invoiceType"` // 发票类型 1公司发票 2技术人员发票
ProductCodes []string `json:"ProductCodes"` //服务产品码
LnoKeys []string `json:"lnoKeys"` //物流单号key
ImageKeys []string `json:"imageKeys"` //上传图片Key.
FileKeys []string `json:"fileKeys"` //上传文件keys
}
type TransferList struct{
InvoiceInfo *InvoiceInfoDto `json:"invoice_info"`
BussinessInfo *BizInfoDto `json:"bussiness_info"`
ChipUsedDtoS map[string]*ChipUsedDto `json:"chip_used_dto_s"`
}
func (med *Medical)Init(stub shim.ChaincodeStubInterface) pb.Response{
return shim.Success([]byte("medical chain init success"))
}
// Invoke is called to update or query the ledger in a proposal transaction.
// Updated state variables are not committed to the ledger until the
// transaction is committed.
func (med *Medical)Invoke(stub shim.ChaincodeStubInterface) pb.Response{
functionName, args := stub.GetFunctionAndParameters()
switch functionName {
case "addCompanyInfo": //增加公司信息
return AddCompanyInfo( args, stub)
case "updateCompanyInfo": //修改公司信息
return AddCompanyInfo( args, stub)
case "addInvoiceInfo": //增加发票信息
return AddInvoiceInfo( args, stub)
case "updateInvoiceInfo": //修改发票信息
return AddInvoiceInfo( args, stub)
case "addBusinessInfo": //增加业务信息
return AddBusinessInfo( args, stub)
case "updateBusinessInfo": //修改业务信息
return AddBusinessInfo( args, stub)
case "addUseInfo": //技术人员增加使用信息
return AddUseInfo(args, stub)
case "searchTransferList":
return SearchTransferListByInvoiceNo(args,stub)
case "testCheck": //测试接口
return TestCheck(args, stub)
default:
return shim.Error(fmt.Sprintf("%s Unsupported function name ", functionName))
}
return pb.Response{}
}
func TestCheck(args []string, stub shim.ChaincodeStubInterface) pb.Response {
if len(args) < 1 {
return shim.Success([]byte("参数内容为空"))
}
return shim.Success([]byte(args[0]))
}
/*
增加/编辑 公司信息
*/
func AddCompanyInfo(args []string,stub shim.ChaincodeStubInterface) pb.Response{
if len(args) > 1 {
return shim.Error("add company info expected 1 parameters! ")
}
comInfo := &CompanyInfo{}
err := json.Unmarshal([]byte(args[0]), comInfo)
if err != nil {
return shim.Error(fmt.Sprintf("Unmarshal CompanyInfo fail,err %s ", err))
}
id:= strconv.FormatUint(comInfo.Id,10)
if comInfo.Id == uint64(0){
return shim.Error("company info id can not is zero")
}
companyKey := CompanyInfoKey+"_"+id
err = putStateStruct(companyKey,comInfo,stub)
if err !=nil{
return shim.Error("put company info err: "+ err.Error())
}
return shim.Success([]byte("put "+comInfo.Cname+" company info successful!"))
}
/*
增加/编辑 发票信息
*/
func AddInvoiceInfo(args []string,stub shim.ChaincodeStubInterface) pb.Response{
if len(args) > 1 {
return shim.Error("add invoice info expected 1 parameters! ")
}
invoiceInfo := &InvoiceInfoDto{}
err := json.Unmarshal([]byte(args[0]), invoiceInfo)
if err != nil {
return shim.Error(fmt.Sprintf("Unmarshal invoice info fail,err %s ", err))
}
if invoiceInfo.InvoiceNo ==" " ||len(invoiceInfo.InvoiceNo) == 0 {
return shim.Error("invoice info InvoiceNo can not is null")
}
companyKey := InvoiceInfoDtoKey+"_"+invoiceInfo.InvoiceNo
err = putStateStruct(companyKey,invoiceInfo,stub)
if err !=nil{
return shim.Error("put invoice info err: "+ err.Error())
}
return shim.Success([]byte("put "+invoiceInfo.InvoiceNo+" invoice info successful!"))
}
/*
增加业务信息
*/
func AddBusinessInfo(args []string,stub shim.ChaincodeStubInterface) pb.Response{
if len(args) > 1 {
return shim.Error("add business info expected 1 parameters! ")
}
bizInfo := &BizInfoDto{}
err := json.Unmarshal([]byte(args[0]), bizInfo)
if err != nil {
return shim.Error(fmt.Sprintf("Unmarshal BizInfoDto fail,err %s ", err))
}
if bizInfo.Lno ==" " ||len(bizInfo.Lno) == 0 {
return shim.Error("business info Lno can not is null")
}
bizInfoKey := BizInfoDtoKey+"_"+bizInfo.Lno
err = putStateStruct(bizInfoKey,bizInfo,stub)
if err !=nil{
return shim.Error("put business info err: "+ err.Error())
}
return shim.Success([]byte("put "+bizInfo.Lno+" business info successful!"))
}
/*
技术人员添加使用信息
*/
func AddUseInfo(args []string,stub shim.ChaincodeStubInterface) pb.Response{
if len(args) > 1 {
return shim.Error("add used info expected 1 parameters! ")
}
usedInfo := &ChipUsedDto{}
err := json.Unmarshal([]byte(args[0]), usedInfo)
if err != nil {
return shim.Error(fmt.Sprintf("Unmarshal used info fail,err %s ", err))
}
if usedInfo.Lno ==" " ||len(usedInfo.Lno) == 0 {
return shim.Error("business info Lno can not is null")
}
usedCompositeKey,err := stub.CreateCompositeKey(UsedKey,[]string{usedInfo.Lno,usedInfo.ChipSno})
if err !=nil{
return shim.Error("create used info composite key err: "+ err.Error())
}
err = putStateStruct(usedCompositeKey,usedInfo,stub)
if err !=nil{
return shim.Error("put used info err: "+ err.Error())
}
return shim.Success([]byte("put "+usedInfo.ChipSno+" used info successful!"))
}
func SearchInvoiceInfoByNo(args []string,stub shim.ChaincodeStubInterface) ([]byte,error){
if len(args) > 1 {
return nil,errors.New("search invoice info expected 1 parameters! ")
}
if args[0] ==" " ||len(args[0]) == 0 {
return nil,errors.New("search key can not is null")
}
invoiceInfoKey := InvoiceInfoDtoKey+"_"+args[0]
return getStateByte(invoiceInfoKey,stub)
}
func SearchBusinessInfoByLno(args []string,stub shim.ChaincodeStubInterface) ([]byte,error){
if len(args) > 1 {
return nil,errors.New("search business info expected 1 parameters! ")
}
if args[0] ==" " ||len(args[0]) == 0 {
return nil,errors.New("search key can not is null")
}
businessInfoKey := BizInfoDtoKey+"_"+args[0]
return getStateByte(businessInfoKey,stub)
}
func SearchUsedInfo(args []string,stub shim.ChaincodeStubInterface) ([]byte,error){
if len(args) < 2 {
return nil,errors.New("search used info expected 2 parameters! ")
}
Lno := args[0]
ChipSno := args[1]
if Lno ==" " ||len(Lno) == 0 {
return nil,errors.New("search key lno can not is null")
}
if ChipSno ==" " ||len(ChipSno) == 0 {
return nil,errors.New("search key chipSno can not is null")
}
usedCompositeKey,err := stub.CreateCompositeKey(UsedKey,[]string{Lno,ChipSno})
if err !=nil{
return nil,errors.New("create used info composite key err: "+ err.Error())
}
return getStateByte(usedCompositeKey,stub)
}
func SearchUseds(args []string,stub shim.ChaincodeStubInterface) (useds [][]byte,err error){
if len(args) < 1 {
return nil,errors.New("search used info expected 1 parameters! ")
}
Lno := args[0]
if Lno ==" " ||len(Lno) == 0 {
return nil,errors.New("search key lno can not is null")
}
iterator,err:= stub.GetStateByPartialCompositeKey(UsedKey,[]string{Lno})
for iterator.HasNext(){
resultKV,err := iterator.Next()
if err!=nil{
return nil,errors.New("iterator query next used info err: "+ err.Error())
}
useds = append(useds,resultKV.Value)
}
return useds,nil
}
/*
根据发票单号查询流转轨迹
*/
func SearchTransferListByInvoiceNo(args []string,stub shim.ChaincodeStubInterface) pb.Response{
var list TransferList
invoiceInfoByte,err := SearchInvoiceInfoByNo(args,stub)
if err != nil {
return shim.Error(err.Error())
}
invoiceInfo := &InvoiceInfoDto{}
err = json.Unmarshal(invoiceInfoByte, invoiceInfo)
if err != nil {
return shim.Error(fmt.Sprintf("Unmarshal invoice info fail,err %s ", err))
}
list.InvoiceInfo = invoiceInfo
businessByte,err := SearchBusinessInfoByLno([]string{invoiceInfo.Lno},stub)
if err != nil {
return shim.Error(err.Error())
}
business := &BizInfoDto{}
err = json.Unmarshal(businessByte, business)
if err != nil {
return shim.Error(fmt.Sprintf("Unmarshal business info fail,err %s ", err))
}
list.BussinessInfo = business
usedsByte,err := SearchUseds([]string{invoiceInfo.Lno},stub)
if err != nil {
return shim.Error(err.Error())
}
list.ChipUsedDtoS = make(map[string]*ChipUsedDto,len(usedsByte))
for _,value :=range usedsByte{
used := &ChipUsedDto{}
err = json.Unmarshal(value, used)
if err != nil {
return shim.Error(fmt.Sprintf("Unmarshal used info fail,err %s ", err))
}
list.ChipUsedDtoS[used.ChipSno] = used
}
listByte,err := json.Marshal(list)
if err!=nil {
shim.Error("marshal transferList err "+err.Error())
}
return shim.Success(listByte)
}
func putStateStruct(key string, value interface{}, stub shim.ChaincodeStubInterface) error {
valueByte, err := json.Marshal(value)
if err != nil {
return fmt.Errorf(" %s json marshal data fail,err: %s", key, err)
}
err = stub.PutState(key, valueByte)
if err != nil {
return fmt.Errorf("putState %s data fail,err: %s", key, err)
}
return nil
}
func getStateByte(key string, stub shim.ChaincodeStubInterface) ([]byte, error) {
byteInfo, err := stub.GetState(key)
if err != nil {
return nil, err
}
if byteInfo == nil {
return nil, fmt.Errorf("The query information is empty ")
}
return byteInfo, nil
}
func main() {
err := shim.Start(&Medical{})
if err != nil {
fmt.Printf("Error starting medical chaincode: %s", err)
}
}
\ No newline at end of file
package main
import (
"encoding/json"
"fmt"
"github.com/hyperledger/fabric/core/chaincode/shim"
"testing"
)
var (
BusinessData = `{"id":100,"cid":101,"cname":"中心","userId":100,"userName":"中心","idNo":"测试数据","mobile":"测试数据","lno":"测试数据","tradeDate":"测试数据","tradeAddress":"测试数据","hospital":"测试数据","amount":"测试数据",
"remark":"测试数据","createTime":"测试数据","updateTime":"测试数据","imageKeys":["测试","ceshi"],"fileKeys":["测试","ceshi"],"chips":[{"chipSno":"","packInfo":"","packCount":0},{"chipSno":"","packInfo":"","packCount":0}]}`
CompanyData =`{"id":100,"businessLicense":"测试数据","cname":"测试数据","cmpanyAddress":"测试数据","companyDesc":"测试数据","companyType":"测试数据","contactPhone":"测试数据","contacts":"测试数据","legalPerson":"测试数据","status":1}`
InvoiceData =`{"id":100,"cid":100,"cname":"测试数据","uid":100,"userName":"测试数据","idNo":"测试数据","mobile":"测试数据","invoiceNo":"发票单号","lno":"测试数据","billingUnit":"测试数据","billingType":100,"receiveUnit":"测试数据",
"amount":100.0099,"remark":"测试数据","invoiceType":1,"ProductCodes":["测试","ceshi"],"lnoKeys":["测试","ceshi"],"imageKeys":["测试","ceshi"],"fileKeys":["测试","ceshi"]}`
UseDate = `{"lno":"测试数据","chipSno":"测试数据1","productNo":"测试数据","userId":100,"usedTime":"测试数据","imageKeys":["测试","ceshi"],"fileKeys":["测试","ceshi"],"videoKeys":["测试","ceshi"]}`
UseDate2 = `{"lno":"测试数据","chipSno":"测试数据2","productNo":"测试数据","userId":100,"usedTime":"测试数据","imageKeys":["测试","ceshi"],"fileKeys":["测试","ceshi"],"videoKeys":["测试","ceshi"]}`
)
func TestJsonByte(t *testing.T){
business := BizInfoDto{
Id :100,
Cid :101,
Cname :"中心",
UserId :100,
UserName :"中心",
IdNo :"测试数据",
Mobile :"测试数据",
Lno :"测试数据",
TradeDate:"测试数据",
TradeAddress :"测试数据",
Hospital :"测试数据",
Amount :"测试数据",
Remark :"测试数据",
CreateTime :"测试数据",
UpdateTime:"测试数据",
ImageKeys :[]string{"测试","ceshi"},
FileKeys :[]string{"测试","ceshi"},
Chips :[]ChipPacking{ChipPacking{},ChipPacking{}},
}
marshalStruct(business)
//company:=&CompanyInfo{
// Id :100,
// BusinessLicense :"测试数据",
// Cname :"测试数据",
// CmpanyAddress :"测试数据",
// CompanyDesc :"测试数据",
// CompanyType :"测试数据",
// ContactPhone :"测试数据",
// Contacts :"测试数据",
// LegalPerson :"测试数据",
// Status :1,
//}
//marshalStruct(company)
//invoiceInfo := &InvoiceInfoDto{
// Id :100,
// Cid :100,
// Cname :"测试数据",
// Uid :100,
// UserName:"测试数据",
// IdNo :"测试数据",
// Mobile :"测试数据",
// //TaxId string `json:"taxId"` //税号
// InvoiceNo :"测试数据",
// Lno :"测试数据",
// BillingUnit :"测试数据",
// BillingType :100,
// ReceiveUnit :"测试数据",
// Amount :100.0099,
// Remark :"测试数据",
// InvoiceType :1,
// ProductCodes :[]string{"测试","ceshi"},
// LnoKeys :[]string{"测试","ceshi"},
// ImageKeys :[]string{"测试","ceshi"},
// FileKeys :[]string{"测试","ceshi"},
//}
// marshalStruct(invoiceInfo)
//usedInfo:= ChipUsedDto{
// Lno :"测试数据",
// ChipSno :"测试数据1",
// ProductNo :"测试数据",
// UserId :100,
// UsedTime :"测试数据",
// ImageKeys :[]string{"测试","ceshi"},
// FileKeys :[]string{"测试","ceshi"},
// VideoKeys :[]string{"测试","ceshi"},
//}
// marshalStruct(usedInfo)
}
func marshalStruct(arg interface{}){
argByte,err := json.Marshal(arg)
if err!=nil{
panic(err)
return
}
fmt.Println(string(argByte))
}
func TestSearchTransferListByInvoiceNo(t *testing.T) {
cc := new(Medical)
stub := shim.NewMockStub("BeanCC",cc)
stub.MockInit("init",nil)
//var testResult bool
print := true
responseByAddBus := stub.MockInvoke("invoke1",[][]byte{[]byte("addBusinessInfo"),[]byte(BusinessData)})
if responseByAddBus.Status != 200{
//testResult = false
t.Error(responseByAddBus.Message)
}else if print{
fmt.Println(string(responseByAddBus.Payload))
}
responseByAddCom := stub.MockInvoke("invoke1",[][]byte{[]byte("addCompanyInfo"),[]byte(CompanyData)})
if responseByAddCom.Status != 200{
//testResult = false
t.Error(responseByAddCom.Message)
}else if print{
fmt.Println(string(responseByAddCom.Payload))
}
responseByAddInvoice := stub.MockInvoke("invoke1",[][]byte{[]byte("addInvoiceInfo"),[]byte(InvoiceData)})
if responseByAddInvoice.Status != 200{
//testResult = false
t.Error(responseByAddInvoice.Message)
}else if print{
fmt.Println(string(responseByAddInvoice.Payload))
}
responseByAddUse := stub.MockInvoke("invoke1",[][]byte{[]byte("addUseInfo"),[]byte(UseDate)})
if responseByAddUse.Status != 200{
//testResult = false
t.Error(responseByAddUse.Message)
}else if print{
fmt.Println(string(responseByAddUse.Payload))
}
responseByAddUse2 := stub.MockInvoke("invoke1",[][]byte{[]byte("addUseInfo"),[]byte(UseDate2)})
if responseByAddUse2.Status != 200{
//testResult = false
t.Error(responseByAddUse2.Message)
}else if print{
fmt.Println(string(responseByAddUse2.Payload))
}
responseBySearchList := stub.MockInvoke("invoke1",[][]byte{[]byte("searchTransferList"),[]byte("发票单号")})
if responseBySearchList.Status != 200{
//testResult = false
t.Error(responseBySearchList.Message)
}else if print{
fmt.Println(string(responseBySearchList.Payload))
}
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/retrospect_chain.iml" filepath="$PROJECT_DIR$/.idea/retrospect_chain.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="Go" enabled="true" />
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="0e32c145-403b-40a5-b720-d9b25be4d700" name="Default Changelist" comment="" />
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="DatabaseView">
<option name="SHOW_INTERMEDIATE" value="true" />
<option name="GROUP_DATA_SOURCES" value="true" />
<option name="GROUP_SCHEMA" value="true" />
<option name="GROUP_CONTENTS" value="false" />
<option name="SORT_POSITIONED" value="false" />
<option name="SHOW_EMPTY_GROUPS" value="false" />
<option name="AUTO_SCROLL_FROM_SOURCE" value="false" />
<option name="HIDDEN_KINDS">
<set />
</option>
<expand />
<select />
</component>
<component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="375">
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/retrospect.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="114">
<caret line="1265" column="27" lean-forward="true" selection-start-line="1265" selection-start-column="27" selection-end-line="1265" selection-end-column="27" />
<folding>
<element signature="e#14#170#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file:///usr/local/go/src/testing/testing.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="214">
<caret line="846" selection-start-line="846" selection-end-line="846" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/../hyperledger/fabric/protos/ledger/queryresult/kv_query_result.pb.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="396">
<caret line="25" column="4" selection-start-line="25" selection-start-column="4" selection-end-line="25" selection-end-column="4" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file:///usr/local/go/src/strconv/atoi.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="3096">
<caret line="172" column="5" selection-start-line="172" selection-start-column="5" selection-end-line="172" selection-end-column="5" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/restropect_test.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="3546">
<caret line="202" column="1" lean-forward="true" selection-start-line="202" selection-start-column="1" selection-end-line="202" selection-end-column="1" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/../hyperledger/fabric/core/chaincode/shim/response.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="558">
<caret line="33" column="5" selection-start-line="33" selection-start-column="5" selection-end-line="33" selection-end-column="5" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file:///usr/local/go/src/encoding/json/decode.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1512">
<caret line="94" column="5" selection-start-line="94" selection-start-column="5" selection-end-line="94" selection-end-column="5" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/../hyperledger/fabric/core/chaincode/shim/mockstub.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="2286">
<caret line="138" selection-start-line="138" selection-end-line="138" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file:///usr/local/go/src/builtin/builtin.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="4680">
<caret line="260" column="4" selection-start-line="260" selection-start-column="4" selection-end-line="260" selection-end-column="4" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/../hyperledger/fabric/core/chaincode/shim/interfaces.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="204">
<caret line="152" column="4" selection-start-line="152" selection-start-column="4" selection-end-line="152" selection-end-column="4" />
</state>
</provider>
</entry>
</file>
</leaf>
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Go File" />
</list>
</option>
</component>
<component name="GOROOT" path="/usr/local/go" />
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/restropect_test.go" />
<option value="$PROJECT_DIR$/retrospect.go" />
</list>
</option>
</component>
<component name="ProjectFrameBounds" extendedState="6">
<option name="x" value="120" />
<option name="y" value="33" />
<option name="width" value="1647" />
<option name="height" value="862" />
</component>
<component name="ProjectView">
<navigator proportions="" version="1">
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="ProjectPane">
<subPane>
<expand>
<path>
<item name="retrospect_chain" type="b2602c69:ProjectViewProjectNode" />
<item name="retrospect_chain" type="462c0819:PsiDirectoryNode" />
</path>
</expand>
<select />
</subPane>
</pane>
<pane id="Scope" />
</panes>
</component>
<component name="PropertiesComponent">
<property name="DefaultGoTemplateProperty" value="Go File" />
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="go.gopath.indexing.explicitly.defined" value="true" />
<property name="go.import.settings.migrated" value="true" />
<property name="last_opened_file_path" value="$USER_HOME$" />
<property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
<property name="nodejs_npm_path_reset_for_default_project" value="true" />
</component>
<component name="RunDashboard">
<option name="ruleStates">
<list>
<RuleState>
<option name="name" value="ConfigurationTypeDashboardGroupingRule" />
</RuleState>
<RuleState>
<option name="name" value="StatusDashboardGroupingRule" />
</RuleState>
</list>
</option>
</component>
<component name="RunManager" selected="Go Test.TestAddActivityInfo in github.com/retrospect_chain">
<configuration name="TestAddActivityInfo in github.com/retrospect_chain" type="GoTestRunConfiguration" factoryName="Go Test" temporary="true" nameIsGenerated="true">
<module name="retrospect_chain" />
<working_directory value="$PROJECT_DIR$" />
<framework value="gotest" />
<kind value="PACKAGE" />
<package value="github.com/retrospect_chain" />
<directory value="$PROJECT_DIR$/" />
<filePath value="$PROJECT_DIR$/" />
<pattern value="^TestAddActivityInfo$" />
<method v="2" />
</configuration>
<configuration name="TestAddEquipmentInfo in github.com/retrospect_chain" type="GoTestRunConfiguration" factoryName="Go Test" temporary="true" nameIsGenerated="true">
<module name="retrospect_chain" />
<working_directory value="$PROJECT_DIR$" />
<framework value="gotest" />
<kind value="PACKAGE" />
<package value="github.com/retrospect_chain" />
<directory value="$PROJECT_DIR$/" />
<filePath value="$PROJECT_DIR$/" />
<pattern value="^TestAddEquipmentInfo$" />
<method v="2" />
</configuration>
<configuration name="TestSearchQrKey in github.com/retrospect_chain" type="GoTestRunConfiguration" factoryName="Go Test" temporary="true" nameIsGenerated="true">
<module name="retrospect_chain" />
<working_directory value="$PROJECT_DIR$" />
<framework value="gotest" />
<kind value="PACKAGE" />
<package value="github.com/retrospect_chain" />
<directory value="$PROJECT_DIR$/" />
<filePath value="$PROJECT_DIR$/" />
<pattern value="^TestSearchQrKey$" />
<method v="2" />
</configuration>
<recent_temporary>
<list>
<item itemvalue="Go Test.TestAddActivityInfo in github.com/retrospect_chain" />
<item itemvalue="Go Test.TestAddEquipmentInfo in github.com/retrospect_chain" />
<item itemvalue="Go Test.TestSearchQrKey in github.com/retrospect_chain" />
</list>
</recent_temporary>
</component>
<component name="TestHistory">
<history-entry file="TestAddActivityInfo_in_github_com_retrospect_chain - 2020.12.02 at 11h 19m 56s.xml">
<configuration name="TestAddActivityInfo in github.com/retrospect_chain" configurationId="GoTestRunConfiguration" />
</history-entry>
<history-entry file="TestAddActivityInfo_in_github_com_retrospect_chain - 2020.12.02 at 11h 21m 22s.xml">
<configuration name="TestAddActivityInfo in github.com/retrospect_chain" configurationId="GoTestRunConfiguration" />
</history-entry>
<history-entry file="TestAddActivityInfo_in_github_com_retrospect_chain - 2020.12.02 at 11h 24m 23s.xml">
<configuration name="TestAddActivityInfo in github.com/retrospect_chain" configurationId="GoTestRunConfiguration" />
</history-entry>
<history-entry file="TestAddActivityInfo_in_github_com_retrospect_chain - 2020.12.02 at 11h 26m 43s.xml">
<configuration name="TestAddActivityInfo in github.com/retrospect_chain" configurationId="GoTestRunConfiguration" />
</history-entry>
<history-entry file="TestAddActivityInfo_in_github_com_retrospect_chain - 2020.12.02 at 11h 34m 22s.xml">
<configuration name="TestAddActivityInfo in github.com/retrospect_chain" configurationId="GoTestRunConfiguration" />
</history-entry>
<history-entry file="TestAddActivityInfo_in_github_com_retrospect_chain - 2020.12.02 at 11h 34m 47s.xml">
<configuration name="TestAddActivityInfo in github.com/retrospect_chain" configurationId="GoTestRunConfiguration" />
</history-entry>
<history-entry file="TestAddActivityInfo_in_github_com_retrospect_chain - 2020.12.02 at 11h 37m 41s.xml">
<configuration name="TestAddActivityInfo in github.com/retrospect_chain" configurationId="GoTestRunConfiguration" />
</history-entry>
<history-entry file="TestAddActivityInfo_in_github_com_retrospect_chain - 2020.12.02 at 11h 40m 22s.xml">
<configuration name="TestAddActivityInfo in github.com/retrospect_chain" configurationId="GoTestRunConfiguration" />
</history-entry>
<history-entry file="TestAddActivityInfo_in_github_com_retrospect_chain - 2020.12.02 at 11h 40m 56s.xml">
<configuration name="TestAddActivityInfo in github.com/retrospect_chain" configurationId="GoTestRunConfiguration" />
</history-entry>
<history-entry file="TestAddActivityInfo_in_github_com_retrospect_chain - 2020.12.02 at 11h 41m 38s.xml">
<configuration name="TestAddActivityInfo in github.com/retrospect_chain" configurationId="GoTestRunConfiguration" />
</history-entry>
</component>
<component name="ToolWindowManager">
<frame x="71" y="31" width="2489" height="1279" extended-state="6" />
<editor active="true" />
<layout>
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.13851212" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info id="Favorites" order="2" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" />
<window_info anchor="bottom" id="Run" order="2" weight="0.32919255" />
<window_info anchor="bottom" id="Debug" order="3" visible="true" weight="0.39929014" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
<window_info anchor="bottom" id="TODO" order="6" />
<window_info anchor="bottom" id="Docker" order="7" show_stripe_button="false" />
<window_info anchor="bottom" id="Version Control" order="8" />
<window_info anchor="bottom" id="Database Changes" order="9" />
<window_info anchor="bottom" id="Statistic" order="10" />
<window_info anchor="bottom" id="Terminal" order="11" />
<window_info anchor="bottom" id="Event Log" order="12" side_tool="true" />
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
<window_info anchor="right" id="PlantUML" order="3" />
<window_info anchor="right" id="Database" order="4" />
</layout>
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="1" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/retrospect.go</url>
<line>1044</line>
<properties />
<option name="timeStamp" value="25" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/retrospect.go</url>
<line>1066</line>
<properties />
<option name="timeStamp" value="26" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/retrospect.go</url>
<line>1248</line>
<properties />
<option name="timeStamp" value="27" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/../hyperledger/fabric/protos/ledger/queryresult/kv_query_result.pb.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="396">
<caret line="25" column="4" selection-start-line="25" selection-start-column="4" selection-end-line="25" selection-end-column="4" />
</state>
</provider>
</entry>
<entry file="file:///usr/local/go/src/strconv/atoi.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="3096">
<caret line="172" column="5" selection-start-line="172" selection-start-column="5" selection-end-line="172" selection-end-column="5" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/../hyperledger/fabric/core/chaincode/shim/response.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="558">
<caret line="33" column="5" selection-start-line="33" selection-start-column="5" selection-end-line="33" selection-end-column="5" />
</state>
</provider>
</entry>
<entry file="file:///usr/local/go/src/encoding/json/decode.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1512">
<caret line="94" column="5" selection-start-line="94" selection-start-column="5" selection-end-line="94" selection-end-column="5" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/../hyperledger/fabric/core/chaincode/shim/mockstub.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="2286">
<caret line="138" selection-start-line="138" selection-end-line="138" />
</state>
</provider>
</entry>
<entry file="file:///usr/local/go/src/builtin/builtin.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="4680">
<caret line="260" column="4" selection-start-line="260" selection-start-column="4" selection-end-line="260" selection-end-column="4" />
</state>
</provider>
</entry>
<entry file="file:///usr/local/go/src/testing/testing.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="214">
<caret line="846" selection-start-line="846" selection-end-line="846" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/../hyperledger/fabric/core/chaincode/shim/interfaces.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="204">
<caret line="152" column="4" selection-start-line="152" selection-start-column="4" selection-end-line="152" selection-end-column="4" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/retrospect.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="114">
<caret line="1265" column="27" lean-forward="true" selection-start-line="1265" selection-start-column="27" selection-end-line="1265" selection-end-column="27" />
<folding>
<element signature="e#14#170#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/restropect_test.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="3546">
<caret line="202" column="1" lean-forward="true" selection-start-line="202" selection-start-column="1" selection-end-line="202" selection-end-column="1" />
</state>
</provider>
</entry>
</component>
</project>
\ No newline at end of file
package main
import (
"encoding/json"
"fmt"
"github.com/hyperledger/fabric/core/chaincode/shim"
"testing"
)
func TestSearchQrKey(t *testing.T) {
s := []int64{19,20,30,40,101,192,200}
num := SearchQrKey(1092,s)
fmt.Println(num)
}
func TestAddEquipmentInfo(t *testing.T) {
info := &QrCode{}
//info.Pics = []string{"speciesDesc","speciesDesc"}
result,_:= json.Marshal(info)
fmt.Println(string(result))
}
var(
companyInfo =`{"cid":"1101","cname":"公司","contacts":"one people","cmpanyAddress":"adress is street","companyDesc":"this is company","companyType":"","businessLicense":"","contactPhone":"12345678765","legalPerson":"one people","status":0}`
dealerInfo = `{"did":"1101","cid":"1101","dealerName":"DealerName","contacts":"contacts","contactPhone":"contacts","salesCount":0,"commissionRatio":0,"status":0}`
detectionInfo = `{"did":"1101","cid":"1101","detectionName":"detectionName","contacts":"contacts","contactPhone":"contactPhone","status":0}`
supplierInfo = `{"sid":"1101","cid":"1101","supplierName":"supplierName","supplierAddress":"supplierName","principal":"principal","phone":"phone","status":0}`
pecies =`{"pid":"1101","cid":"1101","speciesName":"speciesName","mainClass":"mainClass","subClass":"subClass","growingEnv":"growingEnv","growthCycle":0,"pics":["speciesDesc","speciesDesc"],"speciesDesc":"speciesDesc","status":0}`
resumeInfo =`{"rid":"1101","cid":"1101","baseId":"baseId","sid":"1101","bno":"1102","pics":["speciesDesc","speciesDesc"],"tags":"resumeTime","resumeTime":"resumeTime"}`
baseInfo =`{"baseId":"1101","cid":"1101","baseName":"baseName","baseAddress":"baseName","area":0,"principal":"baseName","phone":"baseName","basePics":["speciesDesc","speciesDesc"],"status":0}`
plotInfo =`{"pid":"1101","cid":"1101","baseId":"baseId","plotName":"plotName","plotAddress":"plotName","area":0,"principal":"plotName","phone":"plotName","plotPics":["speciesDesc","speciesDesc"],"status":0}`
equipmentInfo =`{"eid":"1101","cid":"1101","baseId":"baseId","equipName":"equipName","equipModel":"equipModel1","producer":"producer","producedDate":"producedDate","usedDate":"now","status":0}`
equipUsedRecord =`{"eu_id":"1101","eid":"1101","uid":"one people","userName":"userName","duration":0,"usedDate":"now"}`
purchaseInfo =`{"pid":"1101","cid":"1101","baseId":"baseId","purchaseName":"purchaseName","purchaseNo":"purchaseName","purchaseType":0,"producer":"producer","purchaseCount":0,"purchaseDate":"purchaseDate","purchasingAgentId":"purchaseAddress","purchasingAgent":"purchaseAddress","packingSize":"100","businessUnit":"packingSize","purchaseAddress":"purchaseAddress","purchaseBill":["speciesDesc","speciesDesc"],"supplierId":"supplierId"}`
receive =`{"rid":"1101","cid":"1101","baseId":"baseId","areaId":"areaId","supplierId":"supplierId","receiveName":"receiveName","receiveType":"receiveType","producer":"producer","receiveCount":0,"receiveDate":"receiveDate","receiverId":"receiveDate","receiver":"receiveDate"}`
pattern =`{"id":"1101","patternName":"patternName","bizType":"patternName","remark":"patternName","status":0}`
activityInfo =`{"id":"1101","cid":"1101","baseId":"baseId","plotId":"plotId","sid":"sid","bno":"bno","bizType":"bizType"}`
quarantineInfo =`{"id":"1101","cid":"1101","baseId":"baseId","plotId":"plotId","sid":"sid","bno":"bno","quaName":"quaName","bizType":"bizType","qno":"qno","quaDate":"qno","quaReport":["speciesDesc","speciesDesc"],"principalId":"qno","principal":""}`
harvesinfo =`{"id":"1101","cid":"1101","baseId":"baseId","plotId":"baseId","sid":"baseId","bno":"bno","harvestName":"harvestName","bizType":"bizType","hno":"hno","startDate":"hno","endDate":"endDate","principalId":"endDate","principal":"endDate"}`
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"}`
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",
"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,"write_detection_paper":false,"air_detection_paper":false},"company_show":{"cid":"1101","company_name":false,"company_person":false,"company_address":false,"company_intro":false,"business_license":false}}`
)
func TestAddActivityInfo(t *testing.T) {
cc := new(Retrospect)
stub := shim.NewMockStub("RetrospectCC",cc)
stub.MockInit("init",nil)
//var testResult bool
print := true
responseByAddBus := stub.MockInvoke("invoke1",[][]byte{[]byte("addCompanyInfo"),[]byte(companyInfo)})
if responseByAddBus.Status != 200{
//testResult = false
t.Error(responseByAddBus.Message)
}else if print{
fmt.Println(string(responseByAddBus.Payload))
}
responsedealerInfo := stub.MockInvoke("invoke1",[][]byte{[]byte("addDealerInfo"),[]byte(dealerInfo)})
if responsedealerInfo.Status != 200{
//testResult = false
t.Error(responsedealerInfo.Message)
}else if print{
fmt.Println(string(responsedealerInfo.Payload))
}
responsedetectionInfo := stub.MockInvoke("invoke1",[][]byte{[]byte("addDetectionInfo"),[]byte(detectionInfo)})
if responsedetectionInfo.Status != 200{
//testResult = false
t.Error(responsedetectionInfo.Message)
}else if print{
fmt.Println(string(responsedetectionInfo.Payload))
}
responsesupplierInfo := stub.MockInvoke("invoke1",[][]byte{[]byte("addSupplierInfo"),[]byte(supplierInfo)})
if responsesupplierInfo.Status != 200{
//testResult = false
t.Error(responsesupplierInfo.Message)
}else if print{
fmt.Println(string(responsesupplierInfo.Payload))
}
responsepecies := stub.MockInvoke("invoke1",[][]byte{[]byte("addPeciesInfo"),[]byte(pecies)})
if responsepecies.Status != 200{
//testResult = false
t.Error(responsepecies.Message)
}else if print{
fmt.Println(string(responsepecies.Payload))
}
responseresumeInfo := stub.MockInvoke("invoke1",[][]byte{[]byte("addResumeInfo"),[]byte(resumeInfo)})
if responseresumeInfo.Status != 200{
//testResult = false
t.Error(responseresumeInfo.Message)
}else if print{
fmt.Println(string(responseresumeInfo.Payload))
}
responsebaseInfo := stub.MockInvoke("invoke1",[][]byte{[]byte("addBaseInfo"),[]byte(baseInfo)})
if responsebaseInfo.Status != 200{
//testResult = false
t.Error(responsebaseInfo.Message)
}else if print{
fmt.Println(string(responsebaseInfo.Payload))
}
responseplotInfo := stub.MockInvoke("invoke1",[][]byte{[]byte("addPlotInfo"),[]byte(plotInfo)})
if responseplotInfo.Status != 200{
//testResult = false
t.Error(responseplotInfo.Message)
}else if print{
fmt.Println(string(responseplotInfo.Payload))
}
responseequipmentInfo := stub.MockInvoke("invoke1",[][]byte{[]byte("addEquipmentInfo"),[]byte(equipmentInfo)})
if responseequipmentInfo.Status != 200{
//testResult = false
t.Error(responseequipmentInfo.Message)
}else if print{
fmt.Println(string(responseequipmentInfo.Payload))
}
responseequipUsedRecord := stub.MockInvoke("invoke1",[][]byte{[]byte("addEquipUsedRecord"),[]byte(equipUsedRecord)})
if responseequipUsedRecord.Status != 200{
//testResult = false
t.Error(responseequipUsedRecord.Message)
}else if print{
fmt.Println(string(responseequipUsedRecord.Payload))
}
responsepurchaseInfo := stub.MockInvoke("invoke1",[][]byte{[]byte("addPurchaseInfo"),[]byte(purchaseInfo)})
if responsepurchaseInfo.Status != 200{
//testResult = false
t.Error(responsepurchaseInfo.Message)
}else if print{
fmt.Println(string(responsepurchaseInfo.Payload))
}
responsereceive := stub.MockInvoke("invoke1",[][]byte{[]byte("addReceiveInfo"),[]byte(receive)})
if responsereceive.Status != 200{
//testResult = false
t.Error(responsereceive.Message)
}else if print{
fmt.Println(string(responsereceive.Payload))
}
responsepattern := stub.MockInvoke("invoke1",[][]byte{[]byte("addPatternInfo"),[]byte(pattern)})
if responsepattern.Status != 200{
//testResult = false
t.Error(responsepattern.Message)
}else if print{
fmt.Println(string(responsepattern.Payload))
}
resactivityInfo := stub.MockInvoke("invoke1",[][]byte{[]byte("addActivityInfo"),[]byte(activityInfo)})
if resactivityInfo.Status != 200{
//testResult = false
t.Error(resactivityInfo.Message)
}else if print{
fmt.Println(string(resactivityInfo.Payload))
}
resquarantineInfo := stub.MockInvoke("invoke1",[][]byte{[]byte("addPlantingQuarantineInfo"),[]byte(quarantineInfo)})
if resquarantineInfo.Status != 200{
//testResult = false
t.Error(resquarantineInfo.Message)
}else if print{
fmt.Println(string(resquarantineInfo.Payload))
}
resharvesinfo := stub.MockInvoke("invoke1",[][]byte{[]byte("addPlantingHarvesinfo"),[]byte(harvesinfo)})
if resharvesinfo.Status != 200{
//testResult = false
t.Error(resharvesinfo.Message)
}else if print{
fmt.Println(string(resharvesinfo.Payload))
}
resqualityTesting := stub.MockInvoke("invoke1",[][]byte{[]byte("addQualityTestInfo"),[]byte(qualityTesting)})
if resqualityTesting.Status != 200{
//testResult = false
t.Error(resqualityTesting.Message)
}else if print{
fmt.Println(string(resqualityTesting.Payload))
}
respackagingInfo := stub.MockInvoke("invoke1",[][]byte{[]byte("addPackingInfo"),[]byte(packagingInfo)})
if respackagingInfo.Status != 200{
//testResult = false
t.Error(respackagingInfo.Message)
}else if print{
fmt.Println(string(respackagingInfo.Payload))
}
ressalesInfo := stub.MockInvoke("invoke1",[][]byte{[]byte("addsaleInfo"),[]byte(salesInfo)})
if ressalesInfo.Status != 200{
//testResult = false
t.Error(ressalesInfo.Message)
}else if print{
fmt.Println(string(ressalesInfo.Payload))
}
resqrcode := stub.MockInvoke("invoke1",[][]byte{[]byte("addReprospectShowInfo"),[]byte(qrcode)})
if resqrcode.Status != 200{
//testResult = false
t.Error(resqrcode.Message)
}else if print{
fmt.Println(string(resqrcode.Payload))
}
resSearch := stub.MockInvoke("invoke1",[][]byte{[]byte("searchRespectInfo"),[]byte("1102"),[]byte("89")})
if resSearch.Status != 200{
//testResult = false
t.Error(resSearch.Message)
}else if print{
fmt.Println(string(resSearch.Payload))
}
}
\ No newline at end of file
package main
import (
"encoding/json"
"errors"
"fmt"
"github.com/hyperledger/fabric/core/chaincode/shim"
pb "github.com/hyperledger/fabric/protos/peer"
"strconv"
)
const (
CompanyInfoKey = "company_key"
SupplierInfoKey = "supplier_key" //供应商key
DealerInfoKey = "dealer_key" //经销商key
DetectionInfoKey = "detection_key" //检测机构Key
PeciesInfoKey = "pecieso_key" //物种信息key
ResumeInfoKey = "resume_key" //履历key
BaseInfoKey = "base_key" //基地key
PlotInfoKey = "plot_key" //地块key
EquipmentInfoKey = "equipment_key" //农场设备key
EquipmentUseInfoKey = "equipment_use_key" //农场设备使用key
PurchaseInfoKey = "purchase_Key" //化肥进货key
ReceiveInfoKey = "receive_key" //化肥使用key
PatternInfoKey = "pattern_key" //种植方式key
ActivityInfoKey = "activity_key" //种植活动key
QuarantineInfoKey = "quarantine_key" //种植检疫key
PlantingHarvesInfoKey = "planting_harves_key" //种植采收key
QualityTestInfoKey = "quality_test_key" //质量检测信息key
PackingInfoKey = "packing_key" //包装信息key
ReprospectShowInfoKey = "reprospect_show_key" //溯源展示信息key
ReprospectInfoKey = "reprospect_key" //溯源key
SaleInfoKey = "sale_key"
QrInfoKey = "qr_key"
)
type Retrospect struct {
}
/*
公司信息
*/
type CompanyInfo struct {
Cid string `json:"cid"`
Cname string `json:"cname"` //公司名
Contacts string `json:"contacts"` //联系人
CompanyAddress string `json:"cmpanyAddress"` //企业地址
CompanyDesc string `json:"companyDesc"` //企业简介
CompanyType string `json:"companyType"` //企业类型
BusinessLicense string `json:"businessLicense"` //营业执照
ContactPhone string `json:"contactPhone"` //联系电话
LegalPerson string `json:"legalPerson"` //企业法人
Status int `json:"status"` //状态
}
/*
经销商
*/
type DealerInfo struct {
Did string `json:"did"`
Cid string `json:"cid"` //公司Id
DealerName string `json:"dealerName"` //经销商名称
Contacts string `json:"contacts"` //联系人
ContactPhone string `json:"contactPhone"` //联系电话
SalesCount int `json:"salesCount"` //销售批次数量
CommissionRatio float32 `json:"commissionRatio"` //经销商返佣比例
Status int `json:"status"` //状态
}
/*
机构
*/
type DetectionInfo struct {
Did string `json:"did"` //机构ID
Cid string `json:"cid"` //公司Id
DetectionName string `json:"detectionName"` //检测机构名称
Contacts string `json:"contacts"` //联系人
ContactPhone string `json:"contactPhone"` //联系电话
Status int `json:"status"` //状态
}
/*
供应商
*/
type SupplierInfo struct {
Sid string `json:"sid"` //供应商Id
Cid string `json:"cid"` //公司Id
SupplierName string `json:"supplierName"` //供应商名称
SupplierAddress string `json:"supplierAddress"` //
Principal string `json:"principal"` //负责人
Phone string `json:"phone"` //
Status int `json:"status"` //状态
}
/*
物种库
*/
type Pecies struct {
Pid string `json:"pid"`
Cid string `json:"cid"` //公司Id
SpeciesName string `json:"speciesName"` //物种名称
MainClass string `json:"mainClass"` //品种大类
SubClass string `json:"subClass"` //品种小类
GrowingEnv string `json:"growingEnv"` //生长环境
GrowthCycle int `json:"growthCycle"` //生长周期
Pics []string `json:"pics"` //图片
SpeciesDesc string `json:"speciesDesc"` //物种描述
Status int `json:"status"` //状态
}
/*
履历信息
*/
type ResumeInfo struct {
Rid string `json:"rid"`
Cid string `json:"cid"` //公司Id
BaseId string `json:"baseId"` //基地Id
Sid string `json:"sid"` //物种ID
Bno string `json:"bno"` //批次号
Pics []string `json:"pics"` //图片
Tags string `json:"tags"` //标签
ResumeTime string `json:"resumeTime"` //履历时间
}
/*
基地信息
*/
type BaseInfo struct {
BaseId string `json:"baseId"` //基地Id
Cid string `json:"cid"` //公司Id
BaseName string `json:"baseName"` //基地名称
BaseAddress string `json:"baseAddress"` //基地地址
Area int32 `json:"area"` //面积
Principal string `json:"principal"` //负责人
Phone string `json:"phone"` //联系电话
BasePics []string `json:"basePics"` //基地图片
Status int `json:"status"` //状态
}
/*
地块信息
*/
type PlotInfo struct {
Pid string `json:"pid"`
Cid string `json:"cid"` //公司Id
BaseId string `json:"baseId"` //基地Id
PlotName string `json:"plotName"` //地块名称
PlotAddress string `json:"plotAddress"` //地块地址
Area int32 `json:"area"` //面积
Principal string `json:"principal"` //负责人
Phone string `json:"phone"` //联系电话
PlotPics []string `json:"plotPics"` //地块图片
Status int `json:"status"` //状态
}
/*
设备信息
*/
type EquipmentInfo struct {
Eid string `json:"eid"`
Cid string `json:"cid"` //公司Id
BaseId string `json:"baseId"` //基地Id
EquipName string `json:"equipName"` //设备名称
EquipModel string `json:"equipModel"` //设备型号
Producer string `json:"producer"` //设备生产商
ProducedDate string `json:"producedDate"` // 生产日期
UsedDate string `json:"usedDate"` //最近使用日期
Status int `json:"status"` //状态
}
/*
设备使用信息
*/
type EquipUsedRecord struct {
EuId string `json:"eu_id"` //使用Id
Eid string `json:"eid"` //设备ID
Uid string `json:"uid"` //使用人ID
UserName string `json:"userName"` //使用人
Duration float32 `json:"duration"` //使用时长
UsedDate string `json:"usedDate"` //最近使用日期
}
/*
化肥或者农药进货信息
*/
type PurchaseInfo struct {
Pid string `json:"pid"`
Cid string `json:"cid"` //公司Id
BaseId string `json:"baseId"` //基地Id
PurchaseName string `json:"purchaseName"` //进货名称
PurchaseNo string `json:"purchaseNo"` //进货批次号
PurchaseType int `json:"purchaseType"` //进货类型 1化肥 2农药
Producer string `json:"producer"` //生产商
PurchaseCount int64 `json:"purchaseCount"` //进货数量
PurchaseDate string `json:"purchaseDate"` //采购日期
PurchasingAgentId string `json:"purchasingAgentId"` //采购人ID
PurchasingAgent string `json:"purchasingAgent"` //采购人
PackingSize string `json:"packingSize"` //包装规格
BusinessUnit string `json:"businessUnit"` //经营单位
PurchaseAddress string `json:"purchaseAddress"` //购买地点
PurchaseBill []string `json:"purchaseBill"` //进货票据
SupplierId string `json:"supplierId"` //供应商ID
}
/*
化肥或者农药领用信息
*/
type Receive struct {
Rid string `json:"rid"`
Cid string `json:"cid"` //公司Id
BaseId string `json:"baseId"` //基地Id
AreaId string `json:"areaId"` //地块ID
SupplierId string `json:"supplierId"` //供应商ID
ReceiveName string `json:"receiveName"` //领用名称
ReceiveType string `json:"receiveType"` //领用类型 1化肥 2农药
Producer string `json:"producer"` //生产商
ReceiveCount int64 `json:"receiveCount"` //领用数量
ReceiveDate string `json:"receiveDate"` //领用日期
ReceiverId string `json:"receiverId"` //领用人ID
Receiver string `json:"receiver"` //领用人
}
/*
种植方式
*/
type Pattern struct {
Id string `json:"id"`
PatternName string `json:"patternName"` //方式名称
BizType string `json:"bizType"` //业务类型,种植方式
Remark string `json:"remark"` //备注
Status int `json:"status"` //状态
}
/*
种植活动
*/
type ActivityInfo struct {
Id string `json:"id"`
Cid string `json:"cid"` //公司Id
BaseId string `json:"baseId"` //基地Id
PlotId string `json:"plotId"` //地块ID
Sid string `json:"sid"` //物种ID
Bno string `json:"bno"` //批次号
BizType string `json:"bizType"` //业务类型
}
/*
种植检疫
*/
type QuarantineInfo struct {
Id string `json:"id"`
Cid string `json:"cid"` //公司Id
BaseId string `json:"baseId"` //基地Id
PlotId string `json:"plotId"` //地块ID
Sid string `json:"sid"` //物种ID
Bno string `json:"bno"` //批次号
QuaName string `json:"quaName"` //检疫名称
BizType string `json:"bizType"` //业务类型
Qno string `json:"qno"` //编号
QuaDate string `json:"quaDate"` //检疫日期
QuaReport []string `json:"quaReport"` //检测报告
PrincipalId string `json:"principalId"` //负责人ID
Principal string `json:"principal"` //负责人
}
/*
种植采收
*/
type Harvesinfo struct {
Id string `json:"id"`
Cid string `json:"cid"` //公司Id
BaseId string `json:"baseId"` //基地Id
PlotId string `json:"plotId"` //地块ID
Sid string `json:"sid"` //物种ID
Bno string `json:"bno"` //批次号
HarvestName string `json:"harvestName"` //收获名称
BizType string `json:"bizType"` //业务类型
Hno string `json:"hno"` //编号
StartDate string `json:"startDate"` //开始日期
EndDate string `json:"endDate"` //结束日期
PrincipalId string `json:"principalId"` //负责人ID
Principal string `json:"principal"` //负责人
}
/*
质量检测
*/
type QualityTesting struct {
QtId string `json:"qtId"` //
QtOrgName string `json:"qtOrgName"` //检测机构名称
QtMethod string `json:"qtMethod"` //检测方式
QtDate string `json:"qtDate"` //检测时间
QtResult string `json:"qtResult"` //检测结果
QtUser string `json:"qtUser"` //检测人
QtReport string `json:"qtReport"` //质量检测报告
WaterReport []string `json:"waterReport"` //水检测报告
LandReport []string `json:"landReport"` //土地检测报告
AirReport []string `json:"airReport"` //空气检测报告
}
/*
包装信息
*/
type PackagingInfo struct {
Packid string `json:"packid"`
Cid string `json:"cid"` //公司Id
BaseId string `json:"baseId"` //基地Id
PlotId string `json:"plotId"` //地块ID
Sid string `json:"sid"` //物种ID
Bno string `json:"bno"` //批次号
PackInfo string `json:"packInfo"` //包装信息
BizType string `json:"bizType"` //业务类型
Pno string `json:"pno"` //编号
PackCount int64 `json:"packCount"` //包装数量
PackUnit string `json:"packUnit"` //包装单位
PackDate string `json:"packDate"` //包装日期F
PackPics []string `json:"packPics"` //包装图片
PrincipalId string `json:"principalId"` //负责人ID
Principal string `json:"principal"` //负责人
}
/*
销售信息
*/
type SalesInfo struct {
Id string `json:"id"`
Cid string `json:"cid"` //公司Id
BaseId string `json:"baseId"` //基地Id
PlotId string `json:"plotId"` //地块ID
Sid string `json:"sid"` //物种ID
Bno string `json:"bno"` //批次号
SaleInfo string `json:"saleInfo"` //销售信息
BizType string `json:"bizType"` //业务类型
Sno string `json:"sno"` //编号
Customer string `json:"customer"` //客户名称
SaleCount int64 `json:"saleCount"` //销售数量
PackingSize string `json:"packingSize"` //包装规格
SaleDate string `json:"saleDate"` //销售日期
SalePics string `json:"salePics"` //销售图片
TrackingNo string `json:"trackingNo"` //运输单号
LogisticsName string `json:"logisticsName"` //物流信息
Did int32 `json:"did"` //经销商ID
PrincipalId string `json:"principalId"` //负责人ID
Principal string `json:"principal"` //负责人
CommissionRatio float32 `json:"commissionRatio"` //返佣比例
}
/*
二维码展示信息,打印二维码的时候可能还没有销售信息
*/
type QrCode struct {
PNo string `json:"p_no"` //批次号
StartNumber int64 `json:"start_number"` //
Count int32 `json:"count"` //打印数量 是否存在多次进行二维码展示信息
ProductShow ProductShow `json:"product_show"`
RetrospectShow RetrospectShow `json:"retrospect_show"`
QualityTestShow QualityTestShow `json:"quality_test_show"`
CompanyShow CompanyShow `json:"company_show"`
}
/*
产品展示信息
*/
type ProductShow struct {
ProductName bool `json:"product_name"` //产品名称,可以从物种名称
PickDate bool `json:"pick_date"` //采收结束日期,从种植采收获得
ExpirationDate int `json:"expiration_date"` //产品保质期
ProductType bool `json:"product_type"` //产品的包装规格。从包装信息处获得
ProductNo bool `json:"product_no"` //生产批次号
StoageMode string `json:"stoage_mode"` //存储方式
ProductDes bool `json:"product_des"` //产品描述,同样是从物种ID查询获得
ProductFiles []string `json:"product_files"` //产品图片,新增的与默认选择的都一同上传
}
/*
产品展示信息
*/
type SearchProductShow struct {
ProductName string `json:"product_name"` //产品名称,可以从物种名称
PickDate string `json:"pick_date"` //采收结束日期,从种植采收获得
ExpirationDate int `json:"expiration_date"` //产品保质期
ProductType string `json:"product_type"` //产品的包装规格。从包装信息处获得
ProductNo string `json:"product_no"` //生产批次号
StoageMode string `json:"stoage_mode"` //存储方式
ProductDes string `json:"product_des"` //产品描述,同样是从物种ID查询获得
ProductFiles []string `json:"product_files"` //产品图片,新增的与默认选择的都一同上传
}
/*
溯源展示信息
1:展示全部的种植活动,根据批次号进行富查询
2:销售Id,销售ID可能未必是存在
3:包装信息Id
4:质检信息Id
5:物种Id
*/
type RetrospectShow struct {
BaseName string `json:"base_name"` //基地Id
PlotName string `json:"polt_name"` //所属地块Id
SpeciesName string `json:"species_name"` //物种Id
PlantActivity string `json:"plant_activity"` //种植活动
PlantTest string `json:"plant_test"` //种植检疫
PlantPick string `json:"plant_pick"` //种植采收
QualityTest string `json:"quality_test"` //质量检测Id
Packaging string `json:"packaging"` //包装信息Id
SaleInfo string `json:"sale_info"` //销售信息Id or "true" "false"
LogisticsInfo bool `json:"logistics_info"` //物流信息,cc 端不用管
BaseFiles []string `json:"base_files"` //新增的与默认选择的都一同上传
}
/*
溯源展示信息
*/
type SearchRetrospectShow struct {
BaseName string `json:"base_name"` //基地Id
PlotName string `json:"polt_name"` //所属地块Id
SpeciesName string `json:"species_name"` //物种Id
PlantActivity []*ActivityInfo `json:"plant_activity"` //种植活动
PlantTest *QuarantineInfo `json:"plant_test"` //种植检疫
PlantPick *Harvesinfo `json:"plant_pick"` //种植采收
QualityTest *QualityTesting `json:"quality_test"` //质量检测Id
Packaging *PackagingInfo `json:"packaging"` //包装信息Id
SaleInfo *SalesInfo `json:"sale_info"` //销售信息Id or "true" "false"
LogisticsInfo bool `json:"logistics_info"` //物流信息,if true 表示需要进行进行展示
BaseFiles []string `json:"base_files"` //新增的与默认选择的都一同上传
}
/*
质检展示信息
*/
type QualityTestShow struct {
QtId string `json:"qtId"` //质检信息ID 当前这一批次对应的质检信息ID
Detection bool `json:"detection"` //检测机构
DetectionMode bool `json:"detection_mode"` //检测方式
DetectionTiem bool `json:"detection_tiem"` //检测时间
DetectionResult bool `json:"detection_result"` //检测结果
DetectionPeople bool `json:"detection_people"` //检测人
DetectionPaper bool `json:"detection_paper"` //质量检测报告
WaterDetectionPaper bool `json:"write_detection_paper"` //水检测报告
LandDetectionPaper bool `json:"detection_paper"` //土地检测报告
AirDetectionPaper bool `json:"air_detection_paper"` //空气检测报告
}
/*
企业展示信息
*/
type CompanyShow struct {
Cid string `json:"cid"` //企业Id 当前这一批次对应的企业信息ID
CompanyName bool `json:"company_name"`
Principal bool `json:"principal"` //负责人
PrincipalPhone bool `json:"principal"` //负责人联系电话
CompanyPerson bool `json:"company_person"` //公司法人
CompanyAddress bool `json:"company_address"` //公司地址
CompanyIntro bool `json:"company_intro"` //公司简介
BusinessLicense bool `json:"business_license"` //营业执照
}
/*
从链上查询的二维码溯源信息
*/
type SearchQrCode struct {
PNo string `json:"p_no"` //批次号
Count int32 `json:"count"` //打印数量 是否存在多次进行二维码展示信息
ProductShow *SearchProductShow `json:"product_show"`
RetrospectShow *SearchRetrospectShow `json:"retrospect_show"`
QualityTestShow *QualityTesting `json:"quality_test_show"`
CompanyShow *CompanyInfo `json:"company_show"`
}
/*
二维码溯源key
*/
type QrKey struct {
Pno string `json:"pno"` //批次号
StartNumber []int64 `json:"start_number"` //
StartNum int64 `json:"start_num"` //当前批次号的二维码开始number
EndNum int64 `json:"end_num"` //当前批次号的二维码结束number
}
func (ret *Retrospect) Init(stub shim.ChaincodeStubInterface) pb.Response {
return shim.Success([]byte("retrospect chain init success"))
}
// Invoke is called to update or query the ledger in a proposal transaction.
// Updated state variables are not committed to the ledger until the
// transaction is committed.
func (ret *Retrospect) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
functionName, args := stub.GetFunctionAndParameters()
switch functionName {
case "addCompanyInfo": //增加公司信息
return AddCompanyInfo( args, stub)
case "updateCompanyInfo": //修改公司信息
return AddCompanyInfo( args, stub)
case "addSupplierInfo": //添加供应商信息
return AddSupplierInfo( args, stub)
case "addDealerInfo": //添加经销商信息
return AddDealerInfo( args, stub)
case "addDetectionInfo": //增加检测机构信息
return AddDetectionInfo( args, stub)
case "addPeciesInfo": //增加物种信息
return AddPeciesInfo( args, stub)
case "addResumeInfo": //增加履历信息
return AddResumeInfo(args, stub)
case "addBaseInfo": //增加基地信息
return AddBaseInfo(args,stub)
case "addPlotInfo": //增加地块信息
return AddPlotInfo( args, stub)
case "addEquipmentInfo": //增加农场设备信息
return AddEquipmentInfo( args, stub)
case "addEquipUsedRecord": //添加农场设备使用信息
return AddEquipUsedRecord( args, stub)
case "addPurchaseInfo": //添加农药或化肥进货信息
return AddPurchaseInfo( args, stub)
case "addReceiveInfo": //农药或者化肥使用信息
return AddReceiveInfo( args, stub)
case "addPatternInfo": //增加种植方式信息
return AddPatternInfo( args, stub)
case "addActivityInfo": //增加种植活动信息
return AddActivityInfo(args, stub)
case "addPlantingQuarantineInfo": //增加种植检疫信息
return AddPlantingQuarantineInfo(args,stub)
case "addPlantingHarvesinfo": //增加种植采收信息
return AddPlantingHarvesinfo( args, stub)
case "addQualityTestInfo": //添加质量检测信息
return AddQualityTestInfo( args, stub)
case "addPackingInfo": //添加包装信息
return AddPackingInfo( args, stub)
case "addReprospectShowInfo": //添加溯源展示信息
return AddReprospectShowInfo( args, stub)
case "addsaleInfo": //增加销售信息
return AddsaleInfo( args, stub)
case "searchRespectInfo": //查询溯源信息
return SearchRespectInfo( args, stub)
case "testCheck": //测试接口
return TestCheck(args, stub)
default:
return shim.Error(fmt.Sprintf("%s Unsupported function name ", functionName))
}
return pb.Response{}
}
func TestCheck(args []string, stub shim.ChaincodeStubInterface) pb.Response {
if len(args) == 0 {
return shim.Success([]byte("参数内容为空"))
}
return shim.Success([]byte(args[0]))
}
/*
增加/编辑 公司信息
*/
func AddCompanyInfo(args []string, stub shim.ChaincodeStubInterface) pb.Response {
if len(args) > 1 {
return shim.Error("add company info expected 1 parameters! ")
}
comInfo := &CompanyInfo{}
err := json.Unmarshal([]byte(args[0]), comInfo)
if err != nil {
return shim.Error(fmt.Sprintf("Unmarshal CompanyInfo fail,err %s ", err))
}
if comInfo.Cid == " " || len(comInfo.Cid) == 0 {
return shim.Error("company info cid can not is null")
}
companyKey := CompanyInfoKey + "_" + comInfo.Cid
err = putStateStruct(companyKey, comInfo, stub)
if err != nil {
return shim.Error("put company info err: " + err.Error())
}
return shim.Success([]byte("put " + comInfo.Cname + " company info successful!"))
}
/*
添加/编辑 供应商信息
*/
func AddSupplierInfo(args []string, stub shim.ChaincodeStubInterface) pb.Response {
if len(args) > 1 {
return shim.Error("add Supplier info expected 1 parameters! ")
}
suppInfo := &SupplierInfo{}
err := json.Unmarshal([]byte(args[0]), suppInfo)
if err != nil {
return shim.Error(fmt.Sprintf("Unmarshal SupplierInfo fail,err %s ", err))
}
if suppInfo.Sid == " " || len(suppInfo.Sid) == 0 {
return shim.Error("supplier info sid can not is null")
}
companyKey := SupplierInfoKey + "_" + suppInfo.Cid
err = putStateStruct(companyKey, suppInfo, stub)
if err != nil {
return shim.Error("put supplier info err: " + err.Error())
}
return shim.Success([]byte("put " + suppInfo.SupplierName + " supplier info successful!"))
}
/*
添加/编辑 经销商信息
*/
func AddDealerInfo(args []string, stub shim.ChaincodeStubInterface) pb.Response {
if len(args) > 1 {
return shim.Error("add dealer info expected 1 parameters! ")
}
dealerInfo := &DealerInfo{}
err := json.Unmarshal([]byte(args[0]), dealerInfo)
if err != nil {
return shim.Error(fmt.Sprintf("Unmarshal DealerInfo fail,err %s ", err))
}
if dealerInfo.Did == " " || len(dealerInfo.Did) == 0 {
return shim.Error("dealer info did can not is null")
}
companyKey := DealerInfoKey + "_" + dealerInfo.Did
err = putStateStruct(companyKey, dealerInfo, stub)
if err != nil {
return shim.Error("put dealer info err: " + err.Error())
}
return shim.Success([]byte("put " + dealerInfo.DealerName + " dealer info successful!"))
}
/*
添加/编辑 检测机构信息
*/
func AddDetectionInfo(args []string, stub shim.ChaincodeStubInterface) pb.Response {
if len(args) > 1 {
return shim.Error("add detection info expected 1 parameters! ")
}
detectionInfo := &DetectionInfo{}
err := json.Unmarshal([]byte(args[0]), detectionInfo)
if err != nil {
return shim.Error(fmt.Sprintf("Unmarshal DetectionInfo fail,err %s ", err))
}
if detectionInfo.Did == " " || len(detectionInfo.Did) == 0 {
return shim.Error("detection info did can not is null")
}
companyKey := DetectionInfoKey + "_" + detectionInfo.Did
err = putStateStruct(companyKey, detectionInfo, stub)
if err != nil {
return shim.Error("put detection info err: " + err.Error())
}
return shim.Success([]byte("put " + detectionInfo.DetectionName + " detection info successful!"))
}
/*
添加/编辑 物种信息
*/
func AddPeciesInfo(args []string, stub shim.ChaincodeStubInterface) pb.Response {
if len(args) > 1 {
return shim.Error("add pecies info expected 1 parameters! ")
}
pecies := &Pecies{}
err := json.Unmarshal([]byte(args[0]), pecies)
if err != nil {
return shim.Error(fmt.Sprintf("Unmarshal Pecies fail,err %s ", err))
}
if pecies.Pid == " " || len(pecies.Pid) == 0 {
return shim.Error("pecies info pid can not is null")
}
companyKey := PeciesInfoKey + "_" + pecies.Pid
err = putStateStruct(companyKey, pecies, stub)
if err != nil {
return shim.Error("put pecies info err: " + err.Error())
}
return shim.Success([]byte("put " + pecies.SpeciesName + " pecies info successful!"))
}
/*
添加/编辑 履历信息
*/
func AddResumeInfo(args []string, stub shim.ChaincodeStubInterface) pb.Response {
if len(args) > 1 {
return shim.Error("add resume info expected 1 parameters! ")
}
resumeInfo := &ResumeInfo{}
err := json.Unmarshal([]byte(args[0]), resumeInfo)
if err != nil {
return shim.Error(fmt.Sprintf("Unmarshal resumeInfo fail,err %s ", err))
}
if resumeInfo.Rid == " " || len(resumeInfo.Rid) == 0 {
return shim.Error("resume info rid can not is null")
}
companyKey := ResumeInfoKey + "_" + resumeInfo.Rid
err = putStateStruct(companyKey, resumeInfo, stub)
if err != nil {
return shim.Error("put resume info err: " + err.Error())
}
return shim.Success([]byte("put " + resumeInfo.Bno + " resume info successful!"))
}
/*
添加/编辑 基地信息
*/
func AddBaseInfo(args []string, stub shim.ChaincodeStubInterface) pb.Response {
if len(args) > 1 {
return shim.Error("add base info expected 1 parameters! ")
}
baseInfo := &BaseInfo{}
err := json.Unmarshal([]byte(args[0]), baseInfo)
if err != nil {
return shim.Error(fmt.Sprintf("Unmarshal BaseInfo fail,err %s ", err))
}
if baseInfo.BaseId == " " || len(baseInfo.BaseId) == 0 {
return shim.Error("base info baseId can not is null")
}
companyKey := BaseInfoKey + "_" + baseInfo.BaseId
err = putStateStruct(companyKey, baseInfo, stub)
if err != nil {
return shim.Error("put base info err: " + err.Error())
}
return shim.Success([]byte("put " + baseInfo.BaseName + " base info successful!"))
}
/*
添加/编辑 地块信息
*/
func AddPlotInfo(args []string, stub shim.ChaincodeStubInterface) pb.Response {
if len(args) > 1 {
return shim.Error("add plot info expected 1 parameters! ")
}
plotInfo := &PlotInfo{}
err := json.Unmarshal([]byte(args[0]), plotInfo)
if err != nil {
return shim.Error(fmt.Sprintf("Unmarshal PlotInfo fail,err %s ", err))
}
if plotInfo.Pid == " " || len(plotInfo.Pid) == 0 {
return shim.Error("plot info pid can not is null")
}
companyKey := PlotInfoKey + "_" + plotInfo.Pid
err = putStateStruct(companyKey, plotInfo, stub)
if err != nil {
return shim.Error("put plot info err: " + err.Error())
}
return shim.Success([]byte("put " + plotInfo.PlotName + " plot info successful!"))
}
/*
添加/编辑 农场设备信息
*/
func AddEquipmentInfo(args []string, stub shim.ChaincodeStubInterface) pb.Response {
if len(args) > 1 {
return shim.Error("add equipment info expected 1 parameters! ")
}
equipmentInfo := &EquipmentInfo{}
err := json.Unmarshal([]byte(args[0]), equipmentInfo)
if err != nil {
return shim.Error(fmt.Sprintf("Unmarshal EquipmentInfo fail,err %s ", err))
}
if equipmentInfo.Eid == " " || len(equipmentInfo.Eid) == 0 {
return shim.Error("equipment info eid can not is null")
}
companyKey := EquipmentInfoKey + "_" + equipmentInfo.Eid
err = putStateStruct(companyKey, equipmentInfo, stub)
if err != nil {
return shim.Error("put equipment info err: " + err.Error())
}
return shim.Success([]byte("put " + equipmentInfo.EquipName + " equipment info successful!"))
}
/*
添加/编辑 设备使用信息
*/
func AddEquipUsedRecord(args []string, stub shim.ChaincodeStubInterface) pb.Response {
if len(args) > 1 {
return shim.Error("add equipmentuse info expected 1 parameters! ")
}
equipUsedRecord := &EquipUsedRecord{}
err := json.Unmarshal([]byte(args[0]), equipUsedRecord)
if err != nil {
return shim.Error(fmt.Sprintf("Unmarshal EquipUsedRecord fail,err %s ", err))
}
if equipUsedRecord.EuId == " " || len(equipUsedRecord.EuId) == 0 {
return shim.Error("equipmentuse info euid can not is null")
}
companyKey := EquipmentUseInfoKey + "_" + equipUsedRecord.EuId
err = putStateStruct(companyKey, equipUsedRecord, stub)
if err != nil {
return shim.Error("put equipmentuse info err: " + err.Error())
}
return shim.Success([]byte("put " + equipUsedRecord.UserName + " equipmentuse info successful!"))
}
/*
添加/编辑 化肥或者农药进货信息
*/
func AddPurchaseInfo(args []string, stub shim.ChaincodeStubInterface) pb.Response {
if len(args) > 1 {
return shim.Error("add purchase info expected 1 parameters! ")
}
purchaseInfo := &PurchaseInfo{}
err := json.Unmarshal([]byte(args[0]), purchaseInfo)
if err != nil {
return shim.Error(fmt.Sprintf("Unmarshal PurchaseInfo fail,err %s ", err))
}
if purchaseInfo.Pid == " " || len(purchaseInfo.Pid) == 0 {
return shim.Error("purchase info pid can not is null")
}
companyKey := PurchaseInfoKey + "_" + purchaseInfo.Pid
err = putStateStruct(companyKey, purchaseInfo, stub)
if err != nil {
return shim.Error("put purchase info err: " + err.Error())
}
return shim.Success([]byte("put " + purchaseInfo.PurchaseName + " purchase info successful!"))
}
/*
添加/编辑 化肥或者农药使用信息
*/
func AddReceiveInfo(args []string, stub shim.ChaincodeStubInterface) pb.Response {
if len(args) > 1 {
return shim.Error("add receive info expected 1 parameters! ")
}
receive := &Receive{}
err := json.Unmarshal([]byte(args[0]), receive)
if err != nil {
return shim.Error(fmt.Sprintf("Unmarshal PurchaseInfo fail,err %s ", err))
}
if receive.Rid == " " || len(receive.Rid) == 0 {
return shim.Error("receive info rid can not is null")
}
companyKey := ReceiveInfoKey + "_" + receive.Rid
err = putStateStruct(companyKey, receive, stub)
if err != nil {
return shim.Error("put receive info err: " + err.Error())
}
return shim.Success([]byte("put " + receive.ReceiveName + " receive info successful!"))
}
/*
添加/编辑 种植方式信息
*/
func AddPatternInfo(args []string, stub shim.ChaincodeStubInterface) pb.Response {
if len(args) > 1 {
return shim.Error("add pattern info expected 1 parameters! ")
}
pattern := &Pattern{}
err := json.Unmarshal([]byte(args[0]), pattern)
if err != nil {
return shim.Error(fmt.Sprintf("Unmarshal Pattern fail,err %s ", err))
}
if pattern.Id == " " || len(pattern.Id) == 0 {
return shim.Error("pattern info id can not is null")
}
companyKey := PatternInfoKey + "_" + pattern.Id
err = putStateStruct(companyKey, pattern, stub)
if err != nil {
return shim.Error("put pattern info err: " + err.Error())
}
return shim.Success([]byte("put " + pattern.PatternName + " pattern info successful!"))
}
/*
添加/编辑 种植活动信息
*/
func AddActivityInfo(args []string, stub shim.ChaincodeStubInterface) pb.Response {
if len(args) > 1 {
return shim.Error("add activity info expected 1 parameters! ")
}
activity := &ActivityInfo{}
err := json.Unmarshal([]byte(args[0]), activity)
if err != nil {
return shim.Error(fmt.Sprintf("Unmarshal ActivityInfo fail,err %s ", err))
}
if activity.Id == " " || len(activity.Id) == 0 {
return shim.Error("activity info rid can not is null")
}
if activity.Bno == " " || len(activity.Bno) == 0 {
return shim.Error("activity info bno can not is null")
}
activityKey, err := stub.CreateCompositeKey(ActivityInfoKey, []string{activity.Bno, activity.Id})
if err != nil {
return shim.Error("create activity composite key err: " + err.Error())
}
err = putStateStruct(activityKey, activity, stub)
if err != nil {
return shim.Error("put activity info err: " + err.Error())
}
return shim.Success([]byte("put " + activity.BizType + " activity info successful!"))
}
/*
添加/编辑 种植检疫信息
*/
func AddPlantingQuarantineInfo(args []string, stub shim.ChaincodeStubInterface) pb.Response {
if len(args) > 1 {
return shim.Error("add quarantine info expected 1 parameters! ")
}
quarantine := &QuarantineInfo{}
err := json.Unmarshal([]byte(args[0]), quarantine)
if err != nil {
return shim.Error(fmt.Sprintf("Unmarshal QuarantineInfo fail,err %s ", err))
}
if quarantine.Id == " " || len(quarantine.Id) == 0 {
return shim.Error("quarantine info id can not is null")
}
companyKey := QuarantineInfoKey + "_" + quarantine.Id
err = putStateStruct(companyKey, quarantine, stub)
if err != nil {
return shim.Error("put activity info err: " + err.Error())
}
return shim.Success([]byte("put " + quarantine.QuaName + " quarantine info successful!"))
}
/*
添加/编辑 种植采收信息
*/
func AddPlantingHarvesinfo(args []string, stub shim.ChaincodeStubInterface) pb.Response {
if len(args) > 1 {
return shim.Error("add harves info expected 1 parameters! ")
}
harves := &Harvesinfo{}
err := json.Unmarshal([]byte(args[0]), harves)
if err != nil {
return shim.Error(fmt.Sprintf("Unmarshal Harvesinfo fail,err %s ", err))
}
if harves.Id == " " || len(harves.Id) == 0 {
return shim.Error("harves info id can not is null")
}
companyKey := PlantingHarvesInfoKey + "_" + harves.Id
err = putStateStruct(companyKey, harves, stub)
if err != nil {
return shim.Error("put harves info err: " + err.Error())
}
return shim.Success([]byte("put " + harves.HarvestName + " harves info successful!"))
}
/*
添加/编辑 质量检测信息
*/
func AddQualityTestInfo(args []string, stub shim.ChaincodeStubInterface) pb.Response {
if len(args) > 1 {
return shim.Error("add quality test info expected 1 parameters! ")
}
quality := &QualityTesting{}
err := json.Unmarshal([]byte(args[0]), quality)
if err != nil {
return shim.Error(fmt.Sprintf("Unmarshal QualityTesting fail,err %s ", err))
}
if quality.QtId == " " || len(quality.QtId) == 0 {
return shim.Error("quality test info qtid can not is null")
}
companyKey := QualityTestInfoKey + "_" + quality.QtId
err = putStateStruct(companyKey, quality, stub)
if err != nil {
return shim.Error("put quality test info err: " + err.Error())
}
return shim.Success([]byte("put " + quality.QtOrgName + " quality test info successful!"))
}
/*
添加/编辑 包装信息
*/
func AddPackingInfo(args []string, stub shim.ChaincodeStubInterface) pb.Response {
if len(args) > 1 {
return shim.Error("add packaging info expected 1 parameters! ")
}
packaging := &PackagingInfo{}
err := json.Unmarshal([]byte(args[0]), packaging)
if err != nil {
return shim.Error(fmt.Sprintf("Unmarshal PackagingInfo fail,err %s ", err))
}
if packaging.Packid == " " || len(packaging.Packid) == 0 {
return shim.Error("packaging info packid can not is null")
}
companyKey := PackingInfoKey + "_" + packaging.Packid
err = putStateStruct(companyKey, packaging, stub)
if err != nil {
return shim.Error("put packaging info err: " + err.Error())
}
return shim.Success([]byte("put " + packaging.Packid + " packaging info successful!"))
}
/*
添加溯源展示信息
*/
func AddReprospectShowInfo(args []string, stub shim.ChaincodeStubInterface) pb.Response {
if len(args) > 1 {
return shim.Error("add qrcode info expected 1 parameters! ")
}
qrcode := &QrCode{}
err := json.Unmarshal([]byte(args[0]), qrcode)
if err != nil {
return shim.Error(fmt.Sprintf("Unmarshal QrCode fail,err %s ", err))
}
startNum := qrcode.StartNumber+1
startStr := strconv.FormatInt(startNum, 10)
if qrcode.PNo == " " || len(qrcode.PNo) == 0 {
return shim.Error("activity info bno can not is null")
}
qrcodeyKey, err := stub.CreateCompositeKey(ReprospectInfoKey, []string{qrcode.PNo, startStr})
if err != nil {
return shim.Error("create respect composite key err: " + err.Error())
}
resultByte, err := getStateByte(qrcodeyKey, stub)
if resultByte != nil {
return shim.Error(startStr + " qrcode info already exit")
} else if err != nil && err.Error() != "The query information is empty " {
return shim.Error("get qrcode info happen err: " + err.Error())
}
err = putStateStruct(qrcodeyKey, qrcode, stub)
if err != nil {
return shim.Error("put packaging info err: " + err.Error())
}
qr := &QrKey{}
qrKey := QrInfoKey + "_" + qrcode.PNo
qrKeyByte,err := getStateByte(qrKey,stub)
if err != nil{
if err.Error() == "The query information is empty "{
qr.StartNumber = []int64{startNum}
qr.StartNum = startNum
qr.EndNum = startNum + int64(qrcode.Count)
qr.Pno = qrcode.PNo
}else{
return shim.Error("get qrkey info happen err: " + err.Error())
}
}else{
err = json.Unmarshal(qrKeyByte,qr)
if err != nil {
return shim.Error(fmt.Sprintf("Unmarshal QrKey fail,err %s ", err))
}
qrOld := qr.StartNumber[len(qr.StartNumber)-1:]
if startNum <= qrOld[0]{
return shim.Error("StratNumber must be ascending order") //startNumber 必须是有序的
}
qr.StartNumber = append(qr.StartNumber,startNum)
qr.EndNum = startNum + int64(qrcode.Count)
}
err = putStateStruct(qrKey, qr, stub)
if err != nil {
return shim.Error("put QrKey info err: " + err.Error())
}
return shim.Success([]byte(fmt.Sprintf("put qrcode info %s successful!", startStr)))
}
/*
查询溯源信息
返回的溯源信息包括,设计一个统一的结构,如果没有值则设置为空
step:
1; 查询溯源信息是否存在,如果存在则更新,并修改查看次数写入数据库
2: 如果不存在,查询存储的二维码信息
3: 根据二维码信息构建溯源展示信息,返回并写进数据库
*/
func SearchRespectInfo(args []string, stub shim.ChaincodeStubInterface) pb.Response {
if len(args) < 2 {
return shim.Error("search respect info expected 2 parameters! ")
}
if args[0] == " " || len(args[0]) == 0 {
return shim.Error("search key pno can not is null")
}
if args[1] == " " || len(args[1]) == 0 {
return shim.Error("search key number can not is null")
}
showKey, err := stub.CreateCompositeKey(ReprospectShowInfoKey, []string{args[0], args[1]})
if err != nil {
return shim.Error("create respect show composite key err: " + err.Error())
}
showByte, err := getStateByte(showKey, stub)
if showByte != nil{
return shim.Success(showByte)
}
qrcode,err := getQrcode(args,stub)
if err!=nil{
return shim.Error(err.Error())
}
searchShow,err := extractRespectShowInfo(qrcode,stub)
if err != nil{
return shim.Error("extract RespectShow info err: " +err.Error())
}
valueByte, err := json.Marshal(searchShow)
if err != nil {
return shim.Error(fmt.Sprintf("json marshal data fail,err: %s", err))
}
err = stub.PutState(showKey,valueByte)
if err != nil{
return shim.Error(err.Error())
}
return shim.Success(valueByte)
}
/*
添加/编辑 销售信息
*/
func AddsaleInfo(args []string, stub shim.ChaincodeStubInterface) pb.Response {
if len(args) > 1 {
return shim.Error("add sale info expected 1 parameters! ")
}
sale := &SalesInfo{}
err := json.Unmarshal([]byte(args[0]), sale)
if err != nil {
return shim.Error(fmt.Sprintf("Unmarshal SalesInfo fail,err %s ", err))
}
if sale.Id == " " || len(sale.Id) == 0 {
return shim.Error("packaging info id can not is null")
}
companyKey := SaleInfoKey + "_" + sale.Id
err = putStateStruct(companyKey, sale, stub)
if err != nil {
return shim.Error("put sale info err: " + err.Error())
}
return shim.Success([]byte("put " + sale.Id + " sale info successful!"))
}
/*
根据QrCode(溯源展示定义结构)构建当前溯源信息
*/
func extractRespectShowInfo(qrcode *QrCode, stub shim.ChaincodeStubInterface)(qr *SearchQrCode,err error) {
sqrcode := &SearchQrCode{}
sqrcode.PNo = qrcode.PNo
sqrcode.Count = 1
//step1: 查询企业信息
companyKey := CompanyInfoKey + "_" + qrcode.CompanyShow.Cid
compResult,err := getStateByte(companyKey,stub)
if err != nil{
return nil,err
}
company:= &CompanyInfo{}
err = json.Unmarshal(compResult,company)
if err != nil{
return nil,err
}
sqrcode.CompanyShow = company
//step 2: 查询质检信息
qualityKey := QualityTestInfoKey + "_" + qrcode.QualityTestShow.QtId
qualityResult,err := getStateByte(qualityKey,stub)
if err != nil{
return nil,err
}
quality:= &QualityTesting{}
err = json.Unmarshal(qualityResult,quality)
if err != nil{
return nil,err
}
sqrcode.QualityTestShow = quality
//step3: 进行溯源展示信息与产品信息
retrospect:= &SearchRetrospectShow{}
productShow := &SearchProductShow{}
retrospect.BaseFiles = qrcode.RetrospectShow.BaseFiles
retrospect.LogisticsInfo = qrcode.RetrospectShow.LogisticsInfo
productShow.ExpirationDate = qrcode.ProductShow.ExpirationDate
productShow.ProductFiles = qrcode.ProductShow.ProductFiles
productShow.StoageMode = qrcode.ProductShow.StoageMode
productShow.ProductNo = qrcode.PNo
if qrcode.RetrospectShow.BaseName != "false"{
baseKey := BaseInfoKey + "_" + qrcode.RetrospectShow.BaseName
baseResult,err := getStateByte(baseKey,stub)
if err != nil{
return nil,err
}
base:= &BaseInfo{}
err = json.Unmarshal(baseResult,base)
if err != nil{
return nil,err
}
retrospect.BaseName = base.BaseName
}
if qrcode.RetrospectShow.PlotName != "false" {
plotKey := PlotInfoKey + "_" + qrcode.RetrospectShow.PlotName
plotResult,err := getStateByte(plotKey,stub)
if err != nil{
return nil,err
}
plot:= &PlotInfo{}
err = json.Unmarshal(plotResult,plot)
if err != nil{
return nil,err
}
retrospect.PlotName = plot.PlotName
}
if qrcode.RetrospectShow.SpeciesName != "false"{
speciesKey := PeciesInfoKey + "_" + qrcode.RetrospectShow.SpeciesName
speciesResult,err := getStateByte(speciesKey,stub)
if err != nil{
return nil,err
}
pecies:= &Pecies{}
err = json.Unmarshal(speciesResult,pecies)
if err != nil{
return nil,err
}
retrospect.SpeciesName = pecies.SpeciesName
productShow.ProductName = pecies.SpeciesName
productShow.ProductDes = pecies.SpeciesDesc
}
if qrcode.RetrospectShow.PlantTest != "false"{
planttestKey := QuarantineInfoKey + "_" + qrcode.RetrospectShow.PlantTest
planttestResult,err := getStateByte(planttestKey,stub)
if err != nil{
return nil,err
}
quar:= &QuarantineInfo{}
err = json.Unmarshal(planttestResult,quar)
if err != nil{
return nil,err
}
retrospect.PlantTest = quar
}
if qrcode.RetrospectShow.PlantPick != "false"{
pickKey := PlantingHarvesInfoKey + "_" + qrcode.RetrospectShow.PlantPick
planttestResult,err := getStateByte(pickKey,stub)
if err != nil{
return nil,err
}
harves:= &Harvesinfo{}
err = json.Unmarshal(planttestResult,harves)
if err != nil{
return nil,err
}
retrospect.PlantPick = harves
productShow.PickDate =harves.EndDate
}
if qrcode.RetrospectShow.QualityTest != "false"{
retrospect.QualityTest = quality
}
if qrcode.RetrospectShow.Packaging != "false"{
packKey := PackingInfoKey + "_" + qrcode.RetrospectShow.Packaging
packResult,err := getStateByte(packKey,stub)
if err != nil{
return nil,err
}
packing:= &PackagingInfo{}
err = json.Unmarshal(packResult,packing)
if err != nil{
return nil,err
}
retrospect.Packaging = packing
}
if qrcode.RetrospectShow.SaleInfo != "false"{
saleKey := SaleInfoKey + "_" + qrcode.RetrospectShow.SaleInfo
saleResult,err := getStateByte(saleKey,stub)
if saleResult != nil {
sale:= &SalesInfo{}
err = json.Unmarshal(saleResult,sale)
if err != nil{
return nil,err
}
retrospect.SaleInfo = sale
productShow.ProductType = sale.PackingSize
}else if err != nil{
if err.Error() != "The query information is empty "{
return nil,err
}
retrospect.SaleInfo = nil
}
}
if qrcode.RetrospectShow.PlantActivity != "false"{
activityKeys := []string{qrcode.PNo}
activitys ,err := getActivitys(ActivityInfoKey,activityKeys,stub)
if err != nil{
return nil,err
}
retrospect.PlantActivity = activitys
}
sqrcode.ProductShow = productShow
sqrcode.RetrospectShow =retrospect
return sqrcode,nil
}
func getActivitys(objectType string,activityKey []string,stub shim.ChaincodeStubInterface)([]*ActivityInfo,error){
activitys:= make([]*ActivityInfo,1)
queryIterator,err := stub.GetStateByPartialCompositeKey(objectType,activityKey)
if err!= nil{
return nil,err
}
if queryIterator.HasNext(){
kv,err := queryIterator.Next()
if err != nil{
return nil,err
}
activity := &ActivityInfo{}
err = json.Unmarshal(kv.Value,activity)
if err != nil{
return nil,err
}
activitys = append(activitys,activity)
}
return activitys,err
}
func getQrcode(args []string, stub shim.ChaincodeStubInterface)(qrCode *QrCode ,err error) {
startNum,err := strconv.ParseInt(args[1],10,64)
if err!=nil{
return nil, errors.New("ParseInt number err,args[1] must be integer ")
}
qr := &QrKey{}
qrKey := QrInfoKey + "_" + args[0]
qrKeyByte,err := getStateByte(qrKey,stub)
if err!= nil{
return nil, errors.New("get qrkey info happen err: " + err.Error())
}
err = json.Unmarshal(qrKeyByte,qr)
if err != nil {
return nil, errors.New(fmt.Sprintf("Unmarshal QrKey fail,err %s ", err))
}
if startNum > qr.EndNum {
return nil, errors.New("invalid startNum ")
}
result := SearchQrKey(startNum,qr.StartNumber)
if result == -1{
return nil, errors.New(fmt.Sprintf("Unmarshal QrKey fail,err %s ", err))
}
numKey := strconv.FormatInt(result,10)
qrcodeyKey, err := stub.CreateCompositeKey(ReprospectInfoKey, []string{args[0], numKey})
if err != nil {
return nil, errors.New("create respect composite key err: " + err.Error())
}
resultByte, err := getStateByte(qrcodeyKey, stub)
if err != nil {
return nil, errors.New(qrcodeyKey + " qrcode info get err :" + err.Error())
}
qrcode := &QrCode{}
err = json.Unmarshal(resultByte, qrcode)
if err != nil {
return nil, errors.New(fmt.Sprintf("Unmarshal QrCode fail,err %s ", err))
}
return qrcode,nil
}
/*
使用二分法进行查询和检索,找到startNumber区间
*/
func SearchQrKey(startNum int64,s []int64)int64{
if len(s) == 0 {
return -1
}
if len(s) == 1{
return s[0] //最接近starNum 并且小于它
}
middle := len(s)/2
num := s[middle:middle+1]
num1:=make([]int64,1)
if len(s)-1 > middle{
num1 = s[middle+1:middle+2]
}else{
num1[0] = int64(0)
}
if num[0] <= startNum && num1[0] >startNum {
return num[0]
} else if num[0] < startNum {
return SearchQrKey(startNum,s[middle:])
}else {
return SearchQrKey(startNum,s[0:middle])
}
}
func putStateStruct(key string, value interface{}, stub shim.ChaincodeStubInterface) error {
valueByte, err := json.Marshal(value)
if err != nil {
return fmt.Errorf(" %s json marshal data fail,err: %s", key, err)
}
err = stub.PutState(key, valueByte)
if err != nil {
return fmt.Errorf("putState %s data fail,err: %s", key, err)
}
return nil
}
func getStateByte(key string, stub shim.ChaincodeStubInterface) ([]byte, error) {
byteInfo, err := stub.GetState(key)
if err != nil {
return nil, err
}
if byteInfo == nil {
return nil, fmt.Errorf("The query information is empty ")
}
return byteInfo, nil
}
func main() {
err := shim.Start(&Retrospect{})
if err != nil {
fmt.Printf("Error starting medical chaincode: %s", err)
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment