# FileManage **Repository Path**: Hipple/FileManage ## Basic Information - **Project Name**: FileManage - **Description**: 基于区块链的档案分发管理系统 - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 4 - **Created**: 2020-11-18 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 基于区块链的档案分发管理系统 ## 一、涉及技术 Fabric、SpringBoot、Thymeleaf、Redis、Bootstrap、Ajax、JSON、Lombok ## 二、环境说明 -[x] Ubuntu16.04 64位 [需要安装Fabric单机环境](https://blog.csdn.net/qq_36254699/article/details/104459108) -[x] Fabric1.4.0 -[x] SpringBoot2.0.6 -[x] JDK1.8 -[x] Thymeleaf3.0.9.RELEASE -[x] Bootstrap4.0.0 -[x] Redis 3.0.504 64bit ## 三、登录入口 ### 超级管理员 -[x] 登录 http://localhost:8089/FileManage/admin/adminLoginView -[x] 注册 http://localhost:8089/FileManage/admin/insertAdminInfoView -[x] 查看所有档案 http://localhost:8089/FileManage/admin/browseAllRecordInfo -[x] 管理链码 http://localhost:8089/FileManage/admin/chaincodeView ### 档案管理员 -[x] 登录 http://localhost:8089/FileManage/recordAdmin/recordAdminLoginView ### 普通用户 -[x] 登录 http://localhost:8089/FileManage/user/userLoginView ## 四、源码地址 ### GO语言合约开发 git https://gitee.com/hbuzzs/FileManageChainCode.git ### Fabric SDK git https://gitee.com/hbuzzs/FabricSDK.git ### Java SpringBoot+BootStrap档案管理 git https://gitee.com/hbuzzs/FileManage.git ## 五、keyValue存储设计 ### 5.1 查询每个合约的所有记录 key:合约名字 value:对应合约每条记录的的ID ### 5.2 查询用户授权的档案情况 key:档案所属人ID value:档案ID ## 六、命令行安装区块链 ### 1. 智能合约目前版本 ``` adminInfo 1.0 departInfo 1.0 recordAdmin 1.0 recordAuth 1.0 recordInfo 1.1 userInfo 1.0 keyValue 1.4 ``` ### 2. 查看已安装合约 ```$xslt peer chaincode list --installed ``` ### 3. 实例化合约代码(只需要在一个节点实例化就可以) ``` peer chaincode instantiate -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n adminInfo -v 1.0 -c '{"Args":["init"]}' -P "OR ('Org1MSP.peer')" peer chaincode instantiate -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n departInfo -v 1.0 -c '{"Args":["init"]}' -P "OR ('Org1MSP.peer')" peer chaincode instantiate -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n recordAdmin -v 1.0 -c '{"Args":["init"]}' -P "OR ('Org1MSP.peer')" peer chaincode instantiate -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n recordAuth -v 1.0 -c '{"Args":["init"]}' -P "OR ('Org1MSP.peer')" peer chaincode instantiate -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n recordInfo -v 1.0 -c '{"Args":["init"]}' -P "OR ('Org1MSP.peer')" peer chaincode instantiate -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n userInfo -v 1.0 -c '{"Args":["init"]}' -P "OR ('Org1MSP.peer')" peer chaincode instantiate -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n keyValue -v 1.0 -c '{"Args":["init"]}' -P "OR ('Org1MSP.peer')" ``` ### 4. 查看已实例化的合约 ```$xslt peer chaincode list --instantiated -C mychannel ``` ### 5. 触发合约 ``` peer chaincode invoke -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n keyValue --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt -c '{"Args":["save","test","{\"key\":\"recordInfo\",\"valueA\":\"3\",\"valueB\":\"null\"}"]}' ``` ### 6. 查询合约 ``` peer chaincode query -C mychannel -n recordAuth -c '{"Args":["queryHistory","1"]}' ``` ### 7. 升级合约 ```$xslt peer chaincode upgrade -o orderer.example.com:7050 --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n recordAuth -v 1.2 -c '{"Args":["init"]}' -P "OR ('Org1MSP.peer')" ``` ## 七、部署Fabric的坑 ### 1. 提示无法加入区块 原因: 华为云服务器的bug 解决:修改/etc/resolv.conf 注释option一行 ### 2. 查询历史记录为空,但是查询最新记录可以显示 云因:GO开发智能合约 因为要处理成json所以GO结构体字段名必须大写 解决:定义结构体变量这样定义:``` ValueA string `json:"valueA"` ```