├── .classpath ├── .project ├── .settings ├── .jsdtscope ├── org.eclipse.core.resources.prefs ├── org.eclipse.jdt.core.prefs ├── org.eclipse.jst.j2ee.ejb.annotations.xdoclet.prefs ├── org.eclipse.wst.common.component ├── org.eclipse.wst.common.project.facet.core.xml ├── org.eclipse.wst.jsdt.ui.superType.container └── org.eclipse.wst.jsdt.ui.superType.name ├── README.md ├── Resources ├── applicationContext.xml ├── ca.crt ├── client.keystore ├── config.properties ├── file │ └── out.txt ├── jdbc.properties ├── log4j2.xml ├── mapper │ ├── IIouLimitEntityDao.xml │ ├── IIouRecordDao.xml │ └── ITransactionDao.xml ├── mybatis-config.xml ├── schema.sql ├── spring │ ├── spring-dao.xml │ ├── spring-service.xml │ └── spring-web.xml ├── wallet.properties └── wallet │ ├── BankWallet.json │ ├── HPCWallet.json │ └── readme.txt ├── WebContent ├── META-INF │ └── MANIFEST.MF ├── WEB-INF │ ├── lib │ │ ├── aopalliance-1.0.jar │ │ ├── asm-5.0.3.jar │ │ ├── asm-analysis-5.0.3.jar │ │ ├── asm-commons-5.0.3.jar │ │ ├── asm-tree-5.0.3.jar │ │ ├── asm-util-5.0.3.jar │ │ ├── bcprov-jdk15on-1.54.jar │ │ ├── c3p0-0.9.1.2.jar │ │ ├── commons-codec-1.10.jar │ │ ├── commons-codec-1.9.jar │ │ ├── commons-collections-3.2.jar │ │ ├── commons-dbcp-1.2.2.jar │ │ ├── commons-fileupload-1.3.jar │ │ ├── commons-io-2.4.jar │ │ ├── commons-logging-1.2.jar │ │ ├── commons-pool2-2.3.jar │ │ ├── fastjson-1.2.41.jar │ │ ├── guava-19.0.jar │ │ ├── hamcrest-core-1.3.jar │ │ ├── httpclient-4.5.2.jar │ │ ├── httpcore-4.4.4.jar │ │ ├── jackson-annotations-2.8.0.jar │ │ ├── jackson-core-2.8.8.jar │ │ ├── jackson-databind-2.8.8.1.jar │ │ ├── javabase64-1.3.1.jar │ │ ├── javapoet-1.7.0.jar │ │ ├── javax.servlet-api-3.1.0.jar │ │ ├── jedis-2.7.3.jar │ │ ├── jffi-1.2.14-native.jar │ │ ├── jffi-1.2.14.jar │ │ ├── jnr-constants-0.9.6.jar │ │ ├── jnr-enxio-0.14.jar │ │ ├── jnr-ffi-2.1.2.jar │ │ ├── jnr-posix-3.0.33.jar │ │ ├── jnr-unixsocket-0.15.jar │ │ ├── jnr-x86asm-1.0.2.jar │ │ ├── jsp-api-2.0.jar │ │ ├── jsqlparser-0.9.1.jar │ │ ├── jstl-1.2.jar │ │ ├── jul-to-slf4j-1.7.10.jar │ │ ├── log4j-api-2.1.jar │ │ ├── log4j-core-2.1.jar │ │ ├── log4j-slf4j-impl-2.1.jar │ │ ├── log4j-web-2.1.jar │ │ ├── logback-classic-1.1.1.jar │ │ ├── logback-core-1.1.1.jar │ │ ├── mybatis-3.2.8.jar │ │ ├── mybatis-spring-1.3.1.jar │ │ ├── mysql-connector-java-5.1.37.jar │ │ ├── netty-all-4.1.15.Final.jar │ │ ├── netty-tcnative-2.0.0.Final.jar │ │ ├── pagehelper-3.7.3.jar │ │ ├── protostuff-api-1.0.8.jar │ │ ├── protostuff-collectionschema-1.0.8.jar │ │ ├── protostuff-core-1.0.8.jar │ │ ├── protostuff-runtime-1.0.8.jar │ │ ├── quartz-2.2.3.jar │ │ ├── quartz-jobs-2.2.3.jar │ │ ├── rxjava-1.2.4.jar │ │ ├── scrypt-1.4.0.jar │ │ ├── servlet-api.jar │ │ ├── slf4j-api-1.7.10.jar │ │ ├── spring-aop-4.3.15.RELEASE.jar │ │ ├── spring-aspects-4.3.15.RELEASE.jar │ │ ├── spring-beans-4.3.15.RELEASE.jar │ │ ├── spring-context-4.3.15.RELEASE.jar │ │ ├── spring-context-support-4.3.15.RELEASE.jar │ │ ├── spring-core-4.3.15.RELEASE.jar │ │ ├── spring-expression-4.3.15.RELEASE.jar │ │ ├── spring-instrument-4.3.15.RELEASE.jar │ │ ├── spring-instrument-tomcat-4.3.15.RELEASE.jar │ │ ├── spring-jdbc-4.3.15.RELEASE.jar │ │ ├── spring-jms-4.3.15.RELEASE.jar │ │ ├── spring-messaging-4.3.15.RELEASE.jar │ │ ├── spring-orm-4.3.15.RELEASE.jar │ │ ├── spring-oxm-4.3.15.RELEASE.jar │ │ ├── spring-test-4.3.15.RELEASE.jar │ │ ├── spring-tx-4.3.15.RELEASE.jar │ │ ├── spring-web-4.3.15.RELEASE.jar │ │ ├── spring-webmvc-4.3.15.RELEASE.jar │ │ ├── spring-webmvc-portlet-4.3.15.RELEASE.jar │ │ ├── spring-websocket-4.3.15.RELEASE.jar │ │ ├── standard-1.1.2.jar │ │ └── web3sdk.jar │ └── web.xml └── file │ └── out.txt ├── build └── .gitignore ├── file └── out.txt └── src ├── com └── formssi │ ├── controller │ └── UserController.java │ ├── dao │ ├── IIouLimitEntityDao.java │ ├── IIouRecordDao.java │ └── ITransactionDao.java │ ├── entity │ ├── IouLimitEntity.java │ ├── IouRecord.java │ ├── ReturnJson.java │ └── Transaction.java │ ├── filter │ └── CorsFilter.java │ ├── init │ └── WebInitializer.java │ ├── interceptor │ └── LoginInterceptor.java │ └── service │ ├── IIouLimitEntityService.java │ ├── IIouRecordService.java │ ├── ITransactionService.java │ └── impl │ ├── IOUService.java │ ├── IouLimitEntityServiceImpl.java │ ├── IouRecordServiceImpl.java │ └── TransactionServiceImpl.java ├── exception └── initConfigException.java ├── test ├── JunitDemo.java ├── KeyPairGenUtilTest.java ├── SHA256File.java ├── TestHash.java └── myTest.java ├── utils ├── Base64Utils.java ├── DowloadFileUtil.java ├── MD5Util.java ├── MoveFile.java ├── MySessionContext.java ├── MySessionListener.java ├── PropertiesUtil.java ├── RSAUtils.java ├── Token.java └── Utils.java └── wrapper └── SuplInfo.java /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | blockchain 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.wst.common.project.facet.core.builder 15 | 16 | 17 | 18 | 19 | org.eclipse.wst.validation.validationbuilder 20 | 21 | 22 | 23 | 24 | 25 | org.eclipse.jem.workbench.JavaEMFNature 26 | org.eclipse.wst.common.modulecore.ModuleCoreNature 27 | org.eclipse.wst.common.project.facet.core.nature 28 | org.eclipse.jdt.core.javanature 29 | org.eclipse.wst.jsdt.core.jsNature 30 | 31 | 32 | -------------------------------------------------------------------------------- /.settings/.jsdtscope: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding/=UTF-8 3 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 4 | org.eclipse.jdt.core.compiler.compliance=1.8 5 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 6 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 7 | org.eclipse.jdt.core.compiler.source=1.8 8 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jst.j2ee.ejb.annotations.xdoclet.prefs: -------------------------------------------------------------------------------- 1 | XDOCLETBUILDERACTIVE=true 2 | XDOCLETHOME= 3 | XDOCLETUSEGLOBAL=true 4 | XDOCLETVERSION=1.2.1 5 | eclipse.preferences.version=1 6 | -------------------------------------------------------------------------------- /.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.settings/org.eclipse.wst.jsdt.ui.superType.container: -------------------------------------------------------------------------------- 1 | org.eclipse.wst.jsdt.launching.baseBrowserLibrary -------------------------------------------------------------------------------- /.settings/org.eclipse.wst.jsdt.ui.superType.name: -------------------------------------------------------------------------------- 1 | Window -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 基于bcos平台搭建供应链 2 | ## 项目背景介绍 3 | 4 | 在我们做的供应链系统中,有上游,核心企业,下游和工厂四种角色,核心企业向上游购买原料,然后把原料销售给下游,下游再将原料销售给工厂,工厂将原料进行加工,生产成产品,将产品销售给下游,下游再将产品销售给核心企业. 5 | 6 | ## 项目架构介绍 7 | 8 | 首先我们在云服务器上搭建bcos区块链环境,部署智能合约,然后在本地搭建java web后端环境,在web后端通过web3sdk接口来操作bcos区块链,后端再和前端界面交互. 9 | 10 | ## 功能展示 11 | 12 | 首先是注册环节,在这里机构可以选择机构类型,输入帐号密码,再次输入密码确认,点击注册就会在区块链和数据库中创建机构,密码属性经过sha256加密后保存在数据库而非区块链中,这样登录的时候只要在数据库中进行查询即可,一定程度上加快访问速度,提升用户体验.注册完之后就跳转到登录界面,用户使用帐号密码和对应的机构类型进行登录,登录成功后会跳转到主界面,在主界面我们可以看到我们提供了修改白条额度,录入交易信息,查看所有的白条列表,同时可以对白条进行回收,查看所有的交易列表,同时对与自己相关的交易进行修改状态,除此以外,我们还提供了合同下载功能和合同验伪功能.合同下载是指将在创建交易时上传到服务器上的合同下载下来,合同验伪是指上传一份本地的合同,将它与区块链中的指定的合同号的合同哈希进行比较,返回比较结果. 13 | 14 | ## 个人工作 15 | 16 | 我负责在本地使用虚拟机搭建bcos,然后部署到云服务器上,然后编译导出web3sdk.jar包,将web3sdk.jar包导入后端java web,将智能合约编译成Supl.java文件,在serviceImpl层调用Supl.java里的函数操作区块链.除此以外,我还负责后端service层和dao层代码的编写,mapper数据库语句的实现,数据库的建表,初始化数据 17 | -------------------------------------------------------------------------------- /Resources/applicationContext.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | node0@47.106.237.105:35500 34 | 35 | 36 | 37 | 38 | 39 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /Resources/ca.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDVzCCAj+gAwIBAgIJALHdvWEHe0ylMA0GCSqGSIb3DQEBCwUAMEIxCzAJBgNV 3 | BAYTAlhYMRUwEwYDVQQHDAxEZWZhdWx0IENpdHkxHDAaBgNVBAoME0RlZmF1bHQg 4 | Q29tcGFueSBMdGQwHhcNMTgwNjMwMDUxNzQ1WhcNMjgwNjI3MDUxNzQ1WjBCMQsw 5 | CQYDVQQGEwJYWDEVMBMGA1UEBwwMRGVmYXVsdCBDaXR5MRwwGgYDVQQKDBNEZWZh 6 | dWx0IENvbXBhbnkgTHRkMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA 7 | zp18I0MPE9uVPehFHZoGabjR60NEvvIoXBZJ0pZeQTPnREmCWU57ydlUcGCyOPlE 8 | DYK0ni6aXhIZ6FKFjkQ2zM94i4eK70npDuJ2medrTugXHXjxYX2mIXHZCWKicr5R 9 | iAUlHwRN9aiZVrVWYOxUOzvbBZaQUc4jjmM8YI37srP+40yvWLpM1qly7huSd7YI 10 | IW3RAtAFPT8dZFSf8elan2qqBuwoRAa1vtaBoUtlUwOSxuvX0LAgO473TQ4BiVRS 11 | zozcm7exTsOy2IzWqhjF3x5ZtffmI1s1gVV3aZwWkbkrzh/x1+xvdiWFznhjrsGL 12 | BUjIO2acvM8Nc8dq9XRGwQIDAQABo1AwTjAdBgNVHQ4EFgQUPtx1+EcawOsJCcdf 13 | TVccJS4Rx6IwHwYDVR0jBBgwFoAUPtx1+EcawOsJCcdfTVccJS4Rx6IwDAYDVR0T 14 | BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAqjHZpN25f2SVcb4PgOcv6DGqrnzT 15 | /UcLzravWFOSEl9D625EDWIXSKfLwyZnW9KIWQGxn5hQFvlkyoyc3zmRe/iGdZTO 16 | iD1edBpfrBtLvGWFexHPBBxrkqZ5FiEugWlDgANYsMQJak71eAXfBAihW1XcTHww 17 | 7mwg69RZ1iLW5qLPTz3EIrgjlMhHfAazfB3yR61AueemazPe8lIJVonzuXTrHxkB 18 | /1iRpgJ4IZ/JA2fPHpk3pIw2Wm2tE+e4FgPMeU45cvS5SX0XvE+RZG6LHP3Pv8e3 19 | 8ZyxtoPjwTGTI9HuHYKVt7qc0o4pv7AF9GVoAaT44LxJl9tonkW21sXygg== 20 | -----END CERTIFICATE----- 21 | -------------------------------------------------------------------------------- /Resources/client.keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/Resources/client.keystore -------------------------------------------------------------------------------- /Resources/config.properties: -------------------------------------------------------------------------------- 1 | contract.address.0=0xb9ec03c3f3cbe60e59d68facd5d4557b799a499c 2 | contract.address.1=0x2a93f418f751c1e6c2681bb11df77ba3276ee46c 3 | contract.address.2=0x23f63bd93f54e5c0f960ab7471374c99fd9c280e 4 | contract.address.3=0x93d1335f1a01c2899aa09d3315e0032fb06d67f2 5 | contract.address.4=0xcb19248c60e975ca9e577acff97e24fa2182f1dc 6 | contract.address.5=0x0c0d4f2b6f79c43d8ade37dd5be1a8aa05aa1b79 7 | contract.address.6=0x823a32ae6932cdce7d3f5c49f7ce025245e185af 8 | contract.address.7=0x5d5a80a49f238c6bad4de2a234cb357b6b609f09 9 | contract.address.8=0x5fc944389fcff1b0f52671499026fd65f1022654 10 | contract.address.9=0x27a206d9d2ebe28bf69200da9d48db4f6f75e8a3 11 | -------------------------------------------------------------------------------- /Resources/file/out.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/Resources/file/out.txt -------------------------------------------------------------------------------- /Resources/jdbc.properties: -------------------------------------------------------------------------------- 1 | jdbc.driver=com.mysql.jdbc.Driver 2 | jdbc.url=jdbc:mysql://127.0.0.1:3306/supply? 3 | jdbc.username=root 4 | jdbc.password=test1234 -------------------------------------------------------------------------------- /Resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | /file/logs/ 5 | 6 | 7 | 8 | 9 | 10 | 11 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 138 | 139 | 140 | 141 | 142 | 143 | -------------------------------------------------------------------------------- /Resources/mapper/IIouLimitEntityDao.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | INSERT INTO `iouLimitEntity` (`orgID`, `orgName`, `password`, `iouLimit`, `createTime`, `updateTime`) VALUES ('${iouLimitEntity.orgID}','${iouLimitEntity.orgName}','${iouLimitEntity.password}',${iouLimitEntity.iouLimit},'${iouLimitEntity.createTime}','${iouLimitEntity.updateTime}'); 11 | 12 | 13 | 14 | UPDATE `iouLimitEntity` SET `orgName`='${iouLimitEntity.orgName}', `iouLimit`=${iouLimitEntity.iouLimit}, `createTime`='${iouLimitEntity.createTime}', `updateTime`='${iouLimitEntity.updateTime}' WHERE `orgID`='${iouLimitEntity.orgID}'; 15 | 16 | 17 | 21 | 22 | 25 | 26 | 27 | UPDATE `iouLimitEntity` SET `iouLimit`=${iouLimit}, `updateTime`='${updateTime}' WHERE `orgID`='${orgID}'; 28 | 29 | 30 | 34 | 38 | 42 | -------------------------------------------------------------------------------- /Resources/mapper/IIouRecordDao.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | INSERT INTO `iouRecord` (`iouId`, `fromOrg`, `recvOrg`, `transTime`, `amount`, `paidAmt`, `iouStatus`, `updateTime`) VALUES ('${iouRecord.iouId}','${iouRecord.fromOrg}','${iouRecord.recvOrg}','${iouRecord.transTime}',${iouRecord.amount},${iouRecord.paidAmt},'${iouRecord.iouStatus}','${iouRecord.updateTime}'); 10 | 11 | 12 | 13 | UPDATE `iouRecord` SET `iouStatus`='${iouStatus}' WHERE `iouId`='${iouId}'; 14 | 15 | 16 | 17 | UPDATE `iouRecord` SET `iouStatus`='${iouRecord.iouStatus}',`paidAmt`='${iouRecord.paidAmt}',`updateTime`='${iouRecord.updateTime}' WHERE `iouId`='${iouId}'; 18 | 19 | 20 | 21 | 25 | 26 | 29 | 30 | 33 | -------------------------------------------------------------------------------- /Resources/mapper/ITransactionDao.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | INSERT INTO `transaction` (`conID`, `saleOrg`, `buyOrg`, `transType`, `amount`, `conHash`, `latestStatus`, `transTime`, `updateTime`) VALUES ('${transaction.conID}','${transaction.saleOrg}','${transaction.buyOrg}','${transaction.transType}',${transaction.amount},'${transaction.conHash}','${transaction.latestStatus}','${transaction.transTime}','${transaction.updateTime}'); 11 | 12 | 13 | 14 | UPDATE `transaction` SET `latestStatus`='${status}',`updateTime`='${updateTime}' WHERE `conID`='${conID}'; 15 | 16 | 17 | 20 | 21 | 24 | -------------------------------------------------------------------------------- /Resources/mybatis-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /Resources/schema.sql: -------------------------------------------------------------------------------- 1 | Create Database If Not Exists supply Character Set UTF8; 2 | Use supply; 3 | Create Table If Not Exists `iouLimitEntity`( 4 | `orgID` varchar(64) NOT NULL COMMENT '机构ID', 5 | `orgName` varchar(100) NOT NULL COMMENT '机构名称', 6 | `password` varchar(300) NOT NULL COMMENT '登录密码', 7 | `iouLimit` int(11) NOT NULL COMMENT '白条额度', 8 | `createTime` varchar(32) NOT NULL COMMENT '创建时间', 9 | `updateTime` varchar(32) NOT NULL COMMENT '更新时间', 10 | PRIMARY KEY (`orgID`) 11 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='机构'; 12 | --主键可以是orgID吗?auto_increatement=1000有影响吗? 13 | 14 | Create Table If Not Exists `iouRecord`( 15 | `iouId` varchar(64) NOT NULL COMMENT '白条ID', 16 | `fromOrg` varchar(64) NOT NULL COMMENT '发行机构', 17 | `recvOrg` varchar(64) NOT NULL COMMENT '接收机构', 18 | `transTime` varchar(32) NOT NULL COMMENT '交易时间', 19 | `amount` int(11) NOT NULL COMMENT '交易金额', 20 | `paidAmt` int(11) NOT NULL COMMENT '已还金额', 21 | `iouStatus` varchar(4) NOT NULL COMMENT '白条状态', 22 | `updateTime` varchar(32) NOT NULL COMMENT '更新时间', 23 | PRIMARY KEY (`iouId`) 24 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='白条记录'; 25 | --主键可以是iouId吗?auto_increatement=1000有影响吗? 26 | 27 | Create Table If Not Exists `transaction`( 28 | `conID` varchar(64) NOT NULL COMMENT '合同ID', 29 | `saleOrg` varchar(64) NOT NULL COMMENT '销售方机构', 30 | `buyOrg` varchar(64) NOT NULL COMMENT '购买方机构', 31 | `transType` varchar(4) NOT NULL COMMENT '交易类型', 32 | `amount` int(11) NOT NULL COMMENT '白条金额', 33 | `conHash` varchar(300) NOT NULL COMMENT '合同hash', 34 | `latestStatus` varchar(4) NOT NULL COMMENT '最新状态', 35 | `transTime` varchar(32) NOT NULL COMMENT '交易时间', 36 | `updateTime` varchar(32) NOT NULL COMMENT '更新时间', 37 | PRIMARY KEY (`conID`) 38 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='交易'; 39 | --主键可以是conID吗?auto_increatement=1000有影响吗? 40 | 41 | 42 | 43 | 44 | -- 初始化图书数据 45 | --INSERT INTO `book` (`book_id`, `bookName`, `bookPrice`) 46 | --VALUES 47 | -- (1000, 'Java程序设计', 10), 48 | -- (1001, '数据结构', 20), 49 | -- (1002, '设计模式', 30), 50 | -- (1003, '编译原理', 40); 51 | -------------------------------------------------------------------------------- /Resources/spring/spring-dao.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | dialect=mysql 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | -------------------------------------------------------------------------------- /Resources/spring/spring-service.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 15 | 16 | 17 | 19 | 20 | 21 | 22 | 23 | 24 | 26 | 27 | -1 28 | 29 | 30 | 10240 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /Resources/spring/spring-web.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | 18 | 19 | 20 | 24 | 25 | 26 | 27 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /Resources/wallet.properties: -------------------------------------------------------------------------------- 1 | wallet.password=123456 2 | wallet.path=wallet/BankWallet.json 3 | #wallet.path=wallet/BankWallet.json 4 | #钱包文件地址需要使用绝对路径 5 | 6 | #HPC:healthPlanningComission 7 | #wallet.password=123456 8 | #wallet.path=Resources/wallet/HPCWallet.json -------------------------------------------------------------------------------- /Resources/wallet/BankWallet.json: -------------------------------------------------------------------------------- 1 | {"address":"483e58985e9a80a215944fdaabe83df8ba90741f","id":"d1f64732-f71e-49fa-9b60-37efcc9d50b2","version":3,"crypto":{"cipher":"aes-128-ctr","ciphertext":"cc58d947efa3d4fcf12557a2aca82c837de4387fb46ebff933fffc9f51eebfd1","cipherparams":{"iv":"f85ac92674edcdc72250328174f79272"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"f3d20d603e65c7ec0589a76b1f4cb483454cf1e6effabe80ebac26eb607ebeb9"},"mac":"36847a9ffb556f3fae844ec1fab7713e2d7c156517110e9188efa83c564e6f95"}} -------------------------------------------------------------------------------- /Resources/wallet/HPCWallet.json: -------------------------------------------------------------------------------- 1 | {"address":"3a4b744aeda1f9961415c9943ac306cbf83093b1","id":"806a649e-5118-4b7e-b045-c8209aea80d7","version":3,"crypto":{"cipher":"aes-128-ctr","ciphertext":"07234baf622294c33fbdbde409997f84be5a6e7177b1fe42fdb89613e8faec9d","cipherparams":{"iv":"19ead7c19a5a22585b65d1bdc3d1994c"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"217f5bb04d2699715b9e38ff9abc5fb9add842f99454000264515e196bf39ba5"},"mac":"3ea742ebe683a324dd66ed09b0115e1426657bc24eb9817c81c32f768c7cab33"}} -------------------------------------------------------------------------------- /Resources/wallet/readme.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/Resources/wallet/readme.txt -------------------------------------------------------------------------------- /WebContent/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Class-Path: 3 | 4 | -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/aopalliance-1.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/aopalliance-1.0.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/asm-5.0.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/asm-5.0.3.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/asm-analysis-5.0.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/asm-analysis-5.0.3.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/asm-commons-5.0.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/asm-commons-5.0.3.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/asm-tree-5.0.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/asm-tree-5.0.3.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/asm-util-5.0.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/asm-util-5.0.3.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/bcprov-jdk15on-1.54.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/bcprov-jdk15on-1.54.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/c3p0-0.9.1.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/c3p0-0.9.1.2.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/commons-codec-1.10.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/commons-codec-1.10.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/commons-codec-1.9.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/commons-codec-1.9.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/commons-collections-3.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/commons-collections-3.2.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/commons-dbcp-1.2.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/commons-dbcp-1.2.2.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/commons-fileupload-1.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/commons-fileupload-1.3.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/commons-io-2.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/commons-io-2.4.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/commons-logging-1.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/commons-logging-1.2.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/commons-pool2-2.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/commons-pool2-2.3.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/fastjson-1.2.41.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/fastjson-1.2.41.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/guava-19.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/guava-19.0.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/hamcrest-core-1.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/hamcrest-core-1.3.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/httpclient-4.5.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/httpclient-4.5.2.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/httpcore-4.4.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/httpcore-4.4.4.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/jackson-annotations-2.8.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/jackson-annotations-2.8.0.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/jackson-core-2.8.8.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/jackson-core-2.8.8.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/jackson-databind-2.8.8.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/jackson-databind-2.8.8.1.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/javabase64-1.3.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/javabase64-1.3.1.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/javapoet-1.7.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/javapoet-1.7.0.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/javax.servlet-api-3.1.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/javax.servlet-api-3.1.0.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/jedis-2.7.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/jedis-2.7.3.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/jffi-1.2.14-native.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/jffi-1.2.14-native.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/jffi-1.2.14.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/jffi-1.2.14.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/jnr-constants-0.9.6.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/jnr-constants-0.9.6.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/jnr-enxio-0.14.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/jnr-enxio-0.14.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/jnr-ffi-2.1.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/jnr-ffi-2.1.2.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/jnr-posix-3.0.33.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/jnr-posix-3.0.33.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/jnr-unixsocket-0.15.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/jnr-unixsocket-0.15.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/jnr-x86asm-1.0.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/jnr-x86asm-1.0.2.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/jsp-api-2.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/jsp-api-2.0.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/jsqlparser-0.9.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/jsqlparser-0.9.1.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/jstl-1.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/jstl-1.2.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/jul-to-slf4j-1.7.10.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/jul-to-slf4j-1.7.10.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/log4j-api-2.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/log4j-api-2.1.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/log4j-core-2.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/log4j-core-2.1.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/log4j-slf4j-impl-2.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/log4j-slf4j-impl-2.1.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/log4j-web-2.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/log4j-web-2.1.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/logback-classic-1.1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/logback-classic-1.1.1.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/logback-core-1.1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/logback-core-1.1.1.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/mybatis-3.2.8.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/mybatis-3.2.8.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/mybatis-spring-1.3.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/mybatis-spring-1.3.1.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/mysql-connector-java-5.1.37.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/mysql-connector-java-5.1.37.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/netty-all-4.1.15.Final.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/netty-all-4.1.15.Final.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/netty-tcnative-2.0.0.Final.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/netty-tcnative-2.0.0.Final.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/pagehelper-3.7.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/pagehelper-3.7.3.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/protostuff-api-1.0.8.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/protostuff-api-1.0.8.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/protostuff-collectionschema-1.0.8.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/protostuff-collectionschema-1.0.8.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/protostuff-core-1.0.8.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/protostuff-core-1.0.8.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/protostuff-runtime-1.0.8.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/protostuff-runtime-1.0.8.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/quartz-2.2.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/quartz-2.2.3.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/quartz-jobs-2.2.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/quartz-jobs-2.2.3.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/rxjava-1.2.4.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/rxjava-1.2.4.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/scrypt-1.4.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/scrypt-1.4.0.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/servlet-api.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/servlet-api.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/slf4j-api-1.7.10.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/slf4j-api-1.7.10.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/spring-aop-4.3.15.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/spring-aop-4.3.15.RELEASE.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/spring-aspects-4.3.15.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/spring-aspects-4.3.15.RELEASE.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/spring-beans-4.3.15.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/spring-beans-4.3.15.RELEASE.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/spring-context-4.3.15.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/spring-context-4.3.15.RELEASE.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/spring-context-support-4.3.15.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/spring-context-support-4.3.15.RELEASE.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/spring-core-4.3.15.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/spring-core-4.3.15.RELEASE.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/spring-expression-4.3.15.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/spring-expression-4.3.15.RELEASE.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/spring-instrument-4.3.15.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/spring-instrument-4.3.15.RELEASE.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/spring-instrument-tomcat-4.3.15.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/spring-instrument-tomcat-4.3.15.RELEASE.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/spring-jdbc-4.3.15.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/spring-jdbc-4.3.15.RELEASE.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/spring-jms-4.3.15.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/spring-jms-4.3.15.RELEASE.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/spring-messaging-4.3.15.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/spring-messaging-4.3.15.RELEASE.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/spring-orm-4.3.15.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/spring-orm-4.3.15.RELEASE.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/spring-oxm-4.3.15.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/spring-oxm-4.3.15.RELEASE.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/spring-test-4.3.15.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/spring-test-4.3.15.RELEASE.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/spring-tx-4.3.15.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/spring-tx-4.3.15.RELEASE.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/spring-web-4.3.15.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/spring-web-4.3.15.RELEASE.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/spring-webmvc-4.3.15.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/spring-webmvc-4.3.15.RELEASE.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/spring-webmvc-portlet-4.3.15.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/spring-webmvc-portlet-4.3.15.RELEASE.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/spring-websocket-4.3.15.RELEASE.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/spring-websocket-4.3.15.RELEASE.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/standard-1.1.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/standard-1.1.2.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/lib/web3sdk.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/WEB-INF/lib/web3sdk.jar -------------------------------------------------------------------------------- /WebContent/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | mvc-dispatcher 5 | org.springframework.web.servlet.DispatcherServlet 6 | 7 | contextConfigLocation 8 | classpath:spring/spring-*.xml 9 | 10 | 11 | 12 | mvc-dispatcher 13 | / 14 | 15 | 16 | utils.MySessionListener 17 | 18 | 19 | cors 20 | com.formssi.filter.CorsFilter 21 | 22 | 23 | cors 24 | /* 25 | 26 | -------------------------------------------------------------------------------- /WebContent/file/out.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/WebContent/file/out.txt -------------------------------------------------------------------------------- /build/.gitignore: -------------------------------------------------------------------------------- 1 | /classes/ 2 | -------------------------------------------------------------------------------- /file/out.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/USER0308/SUPL_DEMO/3251cd12e1f9c0a74daf938b57c66a8095eeabb3/file/out.txt -------------------------------------------------------------------------------- /src/com/formssi/controller/UserController.java: -------------------------------------------------------------------------------- 1 | package com.formssi.controller; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.File; 5 | import java.io.FileOutputStream; 6 | import java.io.IOException; 7 | import java.io.InputStreamReader; 8 | import java.io.PrintWriter; 9 | import java.security.NoSuchAlgorithmException; 10 | import java.util.List; 11 | import java.util.Map; 12 | import java.util.concurrent.ExecutionException; 13 | 14 | import javax.servlet.ServletInputStream; 15 | import javax.servlet.http.HttpServletRequest; 16 | import javax.servlet.http.HttpServletResponse; 17 | import javax.servlet.http.HttpSession; 18 | 19 | import org.apache.commons.fileupload.FileItem; 20 | import org.apache.commons.fileupload.FileUploadException; 21 | import org.apache.commons.fileupload.disk.DiskFileItemFactory; 22 | import org.apache.commons.fileupload.servlet.ServletFileUpload; 23 | import org.apache.commons.io.FileUtils; 24 | import org.bcos.web3j.abi.datatypes.Utf8String; 25 | import org.springframework.beans.factory.annotation.Autowired; 26 | import org.springframework.http.HttpHeaders; 27 | import org.springframework.http.HttpStatus; 28 | import org.springframework.http.MediaType; 29 | import org.springframework.http.ResponseEntity; 30 | import org.springframework.stereotype.Controller; 31 | import org.springframework.ui.Model; 32 | import org.springframework.web.bind.annotation.PathVariable; 33 | import org.springframework.web.bind.annotation.RequestBody; 34 | import org.springframework.web.bind.annotation.RequestMapping; 35 | import org.springframework.web.bind.annotation.RequestMethod; 36 | import org.springframework.web.bind.annotation.RequestParam; 37 | import org.springframework.web.bind.annotation.ResponseBody; 38 | import org.springframework.web.multipart.commons.CommonsMultipartFile; 39 | 40 | import com.alibaba.fastjson.JSON; 41 | import com.alibaba.fastjson.JSONArray; 42 | import com.alibaba.fastjson.JSONObject; 43 | import com.formssi.entity.IouLimitEntity; 44 | import com.formssi.entity.IouRecord; 45 | import com.formssi.entity.Transaction; 46 | import com.formssi.service.IIouLimitEntityService; 47 | import com.formssi.service.IIouRecordService; 48 | import com.formssi.service.ITransactionService; 49 | import com.formssi.service.impl.IOUService; 50 | //import com.formssi.entity.ReturnJson; 51 | //import com.formssi.entity.User; 52 | //import com.formssi.service.UserService; 53 | //import com.github.pagehelper.PageHelper; 54 | //import com.github.pagehelper.PageInfo; 55 | import com.sun.jmx.snmp.Timestamp; 56 | 57 | import utils.Utils; 58 | import utils.MoveFile; 59 | //import utils.MD5Util; 60 | //import utils.MySessionContext; 61 | //import utils.Token; 62 | //import utils.Utils; 63 | 64 | @Controller 65 | //@RequestMapping("/login") 66 | public class UserController { 67 | 68 | @Autowired 69 | private IIouLimitEntityService iouLimitEntityService; 70 | @Autowired 71 | private IIouRecordService iouRecordService; 72 | @Autowired 73 | private ITransactionService transactionService; 74 | 75 | private String basePath="/home/user0308/Tmp/tmp/"; //合同存储的根目录 76 | 77 | 78 | @RequestMapping(value = "/login", produces = "application/json;charset=UTF-8") 79 | @ResponseBody 80 | public String login(@RequestBody Map map, HttpServletRequest request, HttpServletResponse response) { 81 | // response.setHeader("Access-Control-Allow-Origin", "127.0.0.1:3000");//跨域访问 82 | String orgID=map.get("orgID"); 83 | String orgName=map.get("orgName"); 84 | String password=map.get("password"); 85 | 86 | //登录操作checkPasswordByorgID 87 | int isSuccess=iouLimitEntityService.checkPasswordByorgID(password, orgID, orgName); 88 | 89 | JSONObject res=new JSONObject(); 90 | if(isSuccess==1) { 91 | res.put("status", "1"); 92 | HttpSession session=request.getSession(); 93 | session.setAttribute("orgID", orgID); 94 | } 95 | else 96 | res.put("status", isSuccess); 97 | return res.toJSONString(); 98 | } 99 | 100 | @RequestMapping(value = "/register", produces = "application/json;charset=UTF-8") 101 | @ResponseBody 102 | public String register(@RequestBody Map map, HttpServletRequest request, HttpServletResponse response) throws Exception { 103 | // response.setHeader("Access-Control-Allow-Origin", "*");//跨域访问 104 | String orgID=map.get("orgID"); 105 | String orgName=map.get("orgName"); 106 | String password=map.get("password"); 107 | int iouLimit = Integer.parseInt(map.get("iouLimit")); 108 | System.out.println("orgID is:"+orgID); 109 | System.out.println("orgName is:"+orgName); 110 | System.out.println("password is:"+password); 111 | //注册操作 112 | // IOUService.initObj(); 113 | // IOUService.initIouLimitData(orgID, orgName, password, iouLimit); 114 | 115 | boolean isSuccess = iouLimitEntityService.addIouLimitEntity(orgID,orgName,password,iouLimit); 116 | 117 | 118 | HttpSession session=request.getSession(); 119 | session.setAttribute("orgID", orgID); 120 | 121 | JSONObject res=new JSONObject(); 122 | if(isSuccess) 123 | res.put("status", "1"); 124 | else 125 | res.put("status", "0"); 126 | return res.toJSONString(); 127 | } 128 | 129 | 130 | @RequestMapping(value = "/test", produces = "application/json;charset=UTF-8") 131 | @ResponseBody 132 | public String test(HttpServletRequest request, HttpServletResponse response, HttpSession session) { 133 | // response.setHeader("Access-Control-Allow-Origin", "*");//跨域访问 134 | System.out.println(request.getParameter("username")+" @@@@@"); 135 | session = request.getSession(); 136 | String orgID = (String) session.getAttribute("orgID"); 137 | // 138 | System.out.println("orgID is " + orgID); 139 | return "666"; 140 | } 141 | 142 | /* 143 | * 采用file.Transto 来保存上传的文件 144 | */ 145 | @RequestMapping("/fileUpload") 146 | public String fileUpload(@RequestParam("file") CommonsMultipartFile file) throws IOException { 147 | long startTime=System.currentTimeMillis(); 148 | System.out.println("fileName:"+file.getOriginalFilename()); 149 | String path=basePath+file.getOriginalFilename(); 150 | 151 | File newFile=new File(path); 152 | //通过CommonsMultipartFile的方法直接写文件(注意这个时候) 153 | file.transferTo(newFile); 154 | long endTime=System.currentTimeMillis(); 155 | System.out.println("方法二的运行时间:"+String.valueOf(endTime-startTime)+"ms"); 156 | return "/success"; 157 | } 158 | 159 | @RequestMapping(value = "/upload", produces = "application/json;charset=UTF-8") 160 | @ResponseBody 161 | public String upload(@RequestParam("file") CommonsMultipartFile file,HttpServletRequest request, HttpServletResponse response, HttpSession session) throws IOException { 162 | 163 | /* 上传文件到用户的临时存放区,并名为temContract,即basePath/orgID/temContract 164 | * 165 | * */ 166 | 167 | // response.setHeader("Access-Control-Allow-Origin", "*");//跨域访问 168 | //System.out.println(request.getParameter("username")+" @@@@@"); 169 | //System.out.println("file : "+request.getParameter("file")); 170 | session = request.getSession(); 171 | String orgID = (String) session.getAttribute("orgID"); 172 | // String orgID = "user01"; 173 | System.out.println("orgID: "+orgID); 174 | 175 | String temPath = basePath+orgID; 176 | System.out.println("上传文件的文件夹位置为 "+temPath); 177 | File f = new File(temPath); 178 | 179 | if(!f.exists()){ 180 | f.mkdirs();//创建目录 181 | } 182 | 183 | String path=temPath+"/temContract"; 184 | File newFile=new File(path); 185 | //通过CommonsMultipartFile的方法直接写文件(注意这个时候) 186 | file.transferTo(newFile); 187 | 188 | System.out.println("上传文件成功"); 189 | return "666"; 190 | } 191 | 192 | 193 | @RequestMapping(value="/download/{con_id}") 194 | public ResponseEntity download(@PathVariable("con_id") String con_id, HttpServletRequest request, 195 | Model model)throws Exception { 196 | 197 | /* 下载basePath/contract下的con_id文件 198 | * 199 | * */ 200 | 201 | 202 | String filename = con_id; 203 | //下载文件路径 204 | String path = basePath+"contract"; 205 | File file = new File(path + File.separator + filename); 206 | HttpHeaders headers = new HttpHeaders(); 207 | //下载显示的文件名,解决中文名称乱码问题 208 | String downloadFielName = new String(filename.getBytes("UTF-8"),"iso-8859-1"); 209 | //通知浏览器以attachment(下载方式)打开图片 210 | headers.setContentDispositionFormData("attachment", downloadFielName); 211 | //application/octet-stream : 二进制流数据(最常见的文件下载)。 212 | headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); 213 | return new ResponseEntity(FileUtils.readFileToByteArray(file), 214 | headers, HttpStatus.CREATED); 215 | } 216 | 217 | @RequestMapping(value = "/get_entity_iou_limit", produces = "application/json;charset=UTF-8") 218 | @ResponseBody 219 | public String get_entity_iou_limit(@RequestBody Map map,HttpServletRequest request, HttpServletResponse response) { 220 | // response.setHeader("Access-Control-Allow-Origin", "127.0.0.1:3000");//跨域访问 221 | 222 | HttpSession session=request.getSession(); 223 | String orgID=(String) session.getAttribute("orgID"); 224 | if(orgID==null) { 225 | orgID=map.get("orgID"); 226 | } 227 | System.out.println(orgID); 228 | 229 | //获取ioulist数目 230 | int tem =iouLimitEntityService.getIouLimit(orgID); 231 | 232 | JSONObject res=new JSONObject(); 233 | res.put("iouLimit", tem); 234 | res.put("orgID", orgID); 235 | return res.toJSONString(); 236 | } 237 | 238 | @RequestMapping(value = "/logout", produces = "application/json;charset=UTF-8") 239 | @ResponseBody 240 | public String logout(HttpServletRequest request, HttpServletResponse response) { 241 | // response.setHeader("Access-Control-Allow-Origin", "*");//跨域访问 242 | 243 | HttpSession session=request.getSession(); 244 | session.invalidate(); 245 | 246 | JSONObject res=new JSONObject(); 247 | res.put("status", "1"); 248 | return res.toJSONString(); 249 | } 250 | 251 | @RequestMapping(value = "/ioulist", produces = "application/json;charset=UTF-8") 252 | @ResponseBody 253 | public String ioulist(HttpServletRequest request, HttpServletResponse response) { 254 | // response.setHeader("Access-Control-Allow-Origin", "*");//跨域访问 255 | // int pageNum=Integer.parseInt(map.get("pageNum")); 256 | // int pageSize=Integer.parseInt(map.get("pageSize")); 257 | //String pageSize=request.getParameter("pageSize"); 258 | 259 | HttpSession session=request.getSession(); 260 | String orgID=(String) session.getAttribute("orgID"); 261 | 262 | //获取iou列表操作 263 | List tem = iouRecordService.getAllIouRecord(); 264 | 265 | JSONArray res=new JSONArray(); 266 | for (int i=0;i map, HttpServletRequest request, HttpServletResponse response) { 303 | // response.setHeader("Access-Control-Allow-Origin", "*");//跨域访问 304 | String iouId=map.get("iouId"); 305 | //String amount=request.getParameter("amount"); 306 | int amount=Integer.parseInt(map.get("amount")); 307 | System.out.println("iouId is "+iouId); 308 | System.out.println("amount is "+amount); 309 | //HttpSession session=request.getSession(); 310 | //String orgID = (String) session.getAttribute("orgID"); 311 | try { 312 | iouLimitEntityService.recycleIou(iouId, amount); 313 | } catch (InterruptedException e) { 314 | // TODO Auto-generated catch block 315 | e.printStackTrace(); 316 | } catch (ExecutionException e) { 317 | // TODO Auto-generated catch block 318 | e.printStackTrace(); 319 | } 320 | 321 | JSONObject res=new JSONObject(); 322 | res.put("status", "1"); 323 | return res.toJSONString(); 324 | } 325 | 326 | @RequestMapping(value = "/update_iou_limit", produces = "application/json;charset=UTF-8") 327 | @ResponseBody 328 | public String update_iou_limit(@RequestBody Map map, HttpServletRequest request, HttpServletResponse response) { 329 | // response.setHeader("Access-Control-Allow-Origin", "*");//跨域访问 330 | int amount=Integer.parseInt(map.get("amount")); 331 | 332 | HttpSession session=request.getSession(); 333 | String orgID = (String) session.getAttribute("orgID"); 334 | if(orgID==null) { 335 | orgID = map.get("orgID"); 336 | } 337 | //更新白条额度操作 338 | String transTime = Utils.sdf(System.currentTimeMillis()); 339 | boolean isSuccess=false; 340 | try { 341 | isSuccess = iouLimitEntityService.setIouLimit(amount, transTime, orgID); 342 | } catch (InterruptedException e) { 343 | // TODO Auto-generated catch block 344 | e.printStackTrace(); 345 | } catch (ExecutionException e) { 346 | // TODO Auto-generated catch block 347 | e.printStackTrace(); 348 | }//(orgID,orgName,password,iouLimit); 349 | 350 | 351 | 352 | JSONObject res=new JSONObject(); 353 | if(isSuccess) 354 | res.put("status", "1"); 355 | else 356 | res.put("status", "0"); 357 | return res.toJSONString(); 358 | 359 | } 360 | 361 | @RequestMapping(value = "/transactionlist", produces = "application/json;charset=UTF-8") 362 | @ResponseBody 363 | public String transactionlist( HttpServletRequest request, HttpServletResponse response) { 364 | // response.setHeader("Access-Control-Allow-Origin", "*");//跨域访问 365 | // int pageNum=Integer.parseInt(map.get("pageNum")); 366 | // int pageSize=Integer.parseInt(map.get("pageSize")); 367 | 368 | HttpSession session=request.getSession(); 369 | String orgID=(String) session.getAttribute("orgID"); 370 | 371 | //交易列表操作 372 | List tem = transactionService.getAllTransaction(); 373 | 374 | JSONArray res=new JSONArray(); 375 | for (int i=0;i map, HttpServletRequest request, HttpServletResponse response) throws NoSuchAlgorithmException, IOException { 413 | 414 | /* 415 | * 添加交易时 要将用户临时存放区的文件移到basePath/contract下,并名为con_id 416 | * 然后计算合同hash 417 | * */ 418 | // response.setHeader("Access-Control-Allow-Origin", "*");//跨域访问 419 | String saleOrg=map.get("saleOrg"); 420 | String buyOrg=map.get("buyOrg"); 421 | String transType=map.get("transType"); 422 | IouLimitEntity iouLimitEntityBuy = iouLimitEntityService.getIouLimitEntityByConId(buyOrg); 423 | IouLimitEntity iouLimitEntitySale = iouLimitEntityService.getIouLimitEntityByConId(saleOrg); 424 | JSONObject res=new JSONObject(); 425 | if (iouLimitEntitySale == null) { 426 | System.out.println("出售方交易账号输入错误"); 427 | res.put("status", "0"); 428 | res.put("message","出售方交易账号输入错误" ); 429 | return res.toJSONString(); 430 | } 431 | if (iouLimitEntityBuy == null) { 432 | System.out.println("购买方交易账号输入错误"); 433 | res.put("status", "0"); 434 | res.put("message","购买方交易账号输入错误" ); 435 | return res.toJSONString(); 436 | } 437 | if(iouLimitEntityBuy.getOrgName().equals("upstream") == true) { 438 | System.out.println("很抱歉你不能发起购买交易"); 439 | res.put("status", "0"); 440 | res.put("message","很抱歉你不能发起购买交易" ); 441 | return res.toJSONString(); 442 | } 443 | if(iouLimitEntityBuy.getOrgName().equals("core") == true) { 444 | if (transType.equals("U") == true) { 445 | if (iouLimitEntitySale.getOrgName().equals("upstream") == false) { 446 | System.out.println("很抱歉,购买交易的对象错误"); 447 | res.put("status", "0"); 448 | res.put("message","很抱歉,购买交易的对象错误" ); 449 | return res.toJSONString(); 450 | } 451 | } 452 | if (transType.equals("F") == true) { 453 | if (iouLimitEntitySale.getOrgName().equals("downstream") == false) { 454 | System.out.println("很抱歉,购买交易的对象错误"); 455 | res.put("status", "0"); 456 | res.put("message","很抱歉,购买交易的对象错误" ); 457 | return res.toJSONString(); 458 | } 459 | } 460 | } 461 | if(iouLimitEntityBuy.getOrgName().equals("downstream") == true ) { 462 | if (transType.equals("U") == true) { 463 | if (iouLimitEntitySale.getOrgName().equals("core") == false ) { 464 | System.out.println("很抱歉,购买交易的对象错误"); 465 | res.put("status", "0"); 466 | res.put("message","很抱歉,购买交易的对象错误" ); 467 | return res.toJSONString(); 468 | } 469 | } 470 | if (transType.equals("F") == true) { 471 | if (iouLimitEntitySale.getOrgName().equals("factory") == false) { 472 | System.out.println("很抱歉,购买交易的对象错误"); 473 | res.put("status", "0"); 474 | res.put("message","很抱歉,购买交易的对象错误" ); 475 | return res.toJSONString(); 476 | } 477 | } 478 | } 479 | 480 | if(iouLimitEntityBuy.getOrgName().equals("factory") == true ) { 481 | if (transType.equals("U") == true) { 482 | if (iouLimitEntitySale.getOrgName().equals("downstream") == false ) { 483 | System.out.println("很抱歉,购买交易的对象错误"); 484 | res.put("status", "0"); 485 | res.put("message","很抱歉,购买交易的对象错误" ); 486 | return res.toJSONString(); 487 | } 488 | } 489 | else { 490 | System.out.println("很抱歉你不能购买成品"); 491 | res.put("status", "0"); 492 | res.put("message","很抱歉你不能购买成品" ); 493 | return res.toJSONString(); 494 | } 495 | } 496 | 497 | long amount=Integer.parseInt(map.get("amount")); 498 | // String conFile=map.get("conFile"); 499 | 500 | HttpSession session=request.getSession(); 501 | String orgID = (String) session.getAttribute("orgID"); 502 | 503 | //添加交易操作 504 | try { 505 | // get conID,conHash 506 | long now=System.currentTimeMillis(); 507 | String time = Utils.sdf(now); 508 | 509 | String folderUrl = basePath+orgID; 510 | System.out.println("folder is "+folderUrl); 511 | File destFloder = new File(folderUrl); 512 | //检查目标路径是否合法 513 | if(destFloder.exists()) 514 | { 515 | if(destFloder.isFile()) 516 | { 517 | System.out.println("目标路径是个文件,请检查目标路径!"); 518 | return "404"; 519 | } 520 | }else 521 | { 522 | if(!destFloder.mkdirs()) 523 | { 524 | System.out.println("目标文件夹不存在,创建失败!"); 525 | return "404"; 526 | } 527 | } 528 | 529 | String conID = "conID"+time; 530 | String filePath = basePath +orgID+"/" + "temContract"; 531 | String conHash = utils.Utils.getFileSHA256Str(filePath); 532 | System.out.println("conID is:"+conID); 533 | System.out.println("conHash is:"+conHash); 534 | // move file 535 | String destPath = basePath + "contract/"; 536 | String sourceFilePath = basePath + orgID +"/" + "temContract"; 537 | boolean isSuccess = MoveFile.removeFile(sourceFilePath,destPath,conID); 538 | if(!isSuccess) { 539 | System.out.println("移动合同文件失败"); 540 | JSONObject res2=new JSONObject(); 541 | res2.put("status", "0"); 542 | return res2.toJSONString(); 543 | } 544 | 545 | transactionService.addTransactionRecord(saleOrg, buyOrg, transType, amount, "P",conID,conHash); 546 | 547 | } catch (InterruptedException e) { 548 | // TODO Auto-generated catch block 549 | e.printStackTrace(); 550 | } catch (ExecutionException e) { 551 | // TODO Auto-generated catch block 552 | e.printStackTrace(); 553 | } 554 | 555 | JSONObject res3=new JSONObject(); 556 | res3.put("status", "1"); 557 | return res3.toJSONString(); 558 | } 559 | 560 | @RequestMapping(value = "/get_transaction/{con_id}", produces = "application/json;charset=UTF-8") 561 | @ResponseBody 562 | public String get_transaction(@PathVariable("con_id") String con_id, HttpServletRequest request, HttpServletResponse response, HttpSession session) { 563 | // response.setHeader("Access-Control-Allow-Origin", "*");//跨域访问 564 | System.out.println("Product Id ff : " + con_id); 565 | JSONObject res=new JSONObject(); 566 | //根据合同获得交易信息 567 | Transaction tran = transactionService.getTransactionByConId(con_id); 568 | if(tran==null) { 569 | //不存在该交易 570 | res.put("status", "0"); 571 | res.put("message", "不存在该交易"); 572 | return res.toJSONString(); 573 | } 574 | 575 | 576 | res.put("conID", tran.getConID()); 577 | res.put("saleOrg", tran.getSaleOrg()); 578 | res.put("buyOrg", tran.getBuyOrg()); 579 | res.put("transType", tran.getTransType()); 580 | res.put("transTime", tran.getTransTime()); 581 | res.put("updateTime", tran.getUpdateTime()); 582 | res.put("amount", tran.getAmount()); 583 | res.put("conHash", tran.getConHash()); 584 | res.put("latestStatus", tran.getLatestStatus()); 585 | 586 | //te.fluentAdd(zz); 587 | return res.toJSONString(); 588 | } 589 | 590 | @RequestMapping(value = "/checkConId/{con_ID}", produces = "application/json;charset=UTF-8") 591 | @ResponseBody 592 | public String checkConID(HttpServletRequest request, HttpServletResponse response,@PathVariable String con_ID) { 593 | // response.setHeader("Access-Control-Allow-Origin", "*");//跨域访问 594 | HttpSession session=request.getSession(); 595 | String orgID=(String) session.getAttribute("orgID"); 596 | System.out.println("orgID 在文件校验中是:"+orgID); 597 | String filePath = basePath +orgID +"/" + "temContract"; 598 | System.out.println("filePath 是:"+filePath); 599 | JSONObject zz=new JSONObject(); 600 | try { 601 | String conHash = utils.Utils.getFileSHA256Str(filePath); 602 | System.out.println("计算出来的文件哈系是:"+conHash); 603 | Utf8String J_Transaction = IOUService.queryTransactionByConId(con_ID); 604 | String Str = J_Transaction.toString(); 605 | JSONObject jsonObject1=JSON.parseObject(Str); 606 | String conHash_block = jsonObject1.getString("conHash"); 607 | System.out.println("从区块链上读取出来的文件哈系是:"+conHash_block); 608 | if (conHash_block.equals(conHash) ==true) { 609 | System.out.println("合同哈希匹配成功"); 610 | zz.put("status", "1"); 611 | return zz.toJSONString(); 612 | }else { 613 | System.out.println("合同哈希匹配不成功"); 614 | zz.put("status", "0"); 615 | return zz.toJSONString(); 616 | } 617 | } catch (NoSuchAlgorithmException e) { 618 | // TODO Auto-generated catch block 619 | e.printStackTrace(); 620 | } catch (IOException e) { 621 | // TODO Auto-generated catch block 622 | e.printStackTrace(); 623 | } catch (InterruptedException e) { 624 | // TODO Auto-generated catch block 625 | e.printStackTrace(); 626 | } catch (ExecutionException e) { 627 | // TODO Auto-generated catch block 628 | e.printStackTrace(); 629 | } 630 | zz.put("status", "0"); 631 | return zz.toJSONString(); 632 | } 633 | 634 | @RequestMapping(value = "/update_trans_status", produces = "application/json;charset=UTF-8") 635 | @ResponseBody 636 | public String update_transaction_status(@RequestBody Map map, HttpServletRequest request, HttpServletResponse response) { 637 | // response.setHeader("Access-Control-Allow-Origin", "*");//跨域访问 638 | String conId = map.get("conID"); 639 | //更新交易状态操作 640 | String transTime = Utils.sdf(System.currentTimeMillis()); 641 | boolean isSuccess = transactionService.updateTransactionStatusByConId(conId, "C"); 642 | 643 | JSONObject res=new JSONObject(); 644 | if(isSuccess) 645 | res.put("status", "1"); 646 | else 647 | res.put("status", "0"); 648 | return res.toJSONString(); 649 | 650 | } 651 | // @RequestMapping(value="/product/{productId}", produces = "application/json;charset=UTF-8") 652 | // public String getProduct(@PathVariable("productId") String productId, HttpServletResponse response, HttpSession session){ 653 | // System.out.println("Product Id : " + productId); 654 | // return "hello"; 655 | // } 656 | 657 | 658 | 659 | @RequestMapping(value = "/product/{productId}", produces = "application/json;charset=UTF-8") 660 | @ResponseBody 661 | public String test(@PathVariable("productId") String productId, HttpServletRequest request, HttpServletResponse response, HttpSession session) { 662 | // response.setHeader("Access-Control-Allow-Origin", "*");//跨域访问 663 | System.out.println("Product Id ff : " + productId); 664 | JSONObject zz=new JSONObject(); 665 | zz.put("zzz", "xxxx"); 666 | System.out.println(zz.toJSONString()); 667 | JSONArray te=new JSONArray(); 668 | te.add(zz); 669 | for(int i=0;i<2;i++) { 670 | JSONObject zzz =new JSONObject(); 671 | zzz.put("ddd", "ddsss"); 672 | te.add(zzz); 673 | } 674 | //te.fluentAdd(zz); 675 | return te.toJSONString(); 676 | } 677 | 678 | } 679 | -------------------------------------------------------------------------------- /src/com/formssi/dao/IIouLimitEntityDao.java: -------------------------------------------------------------------------------- 1 | package com.formssi.dao; 2 | import java.util.List; 3 | 4 | import org.apache.ibatis.annotations.Param; 5 | 6 | import com.formssi.entity.IouLimitEntity; 7 | 8 | 9 | public interface IIouLimitEntityDao { 10 | public void addIouLimitEntity(IouLimitEntity iouLimitEntity); // 新增机构 11 | public void updateIouLimitEntity(IouLimitEntity iouLimitEntity); // 设置机构额度 12 | public IouLimitEntity queryEntityByOrgName(@Param(value="orgName")String orgName); // 通过机构名查询机构实体 废弃 13 | public Integer getIouLimitByOrgID(@Param(value="orgID")String orgID); 14 | public void updateIouLimitByOrgID(@Param(value="iouLimit")int iouLimit, @Param(value="updateTime")String updateTime, @Param(value="orgID")String orgID); // 更新机构的白条额度 15 | public IouLimitEntity queryIouLimitEntityByOrgID(@Param(value="orgID")String orgID); // 通过orgID查询机构 16 | 17 | public String checkName(@Param(value="orgID")String orgID);//通过ID查询机构类型 18 | public String checkPassword(@Param(value="orgID")String orgID);//检查密码是否正确 19 | } 20 | 21 | -------------------------------------------------------------------------------- /src/com/formssi/dao/IIouRecordDao.java: -------------------------------------------------------------------------------- 1 | package com.formssi.dao; 2 | import java.util.List; 3 | 4 | import org.apache.ibatis.annotations.Param; 5 | 6 | import com.formssi.entity.IouRecord; 7 | 8 | 9 | 10 | public interface IIouRecordDao { 11 | public void addIouRecord(IouRecord iouRecord); // 新增白条记录 12 | public void updateIouStatusByIouId(@Param(value="iouId")String iouId, @Param(value="iouStatus")String iouStatus); // 更新白条状态 --C,已还清--P,未还清 13 | public void updateIouRecord(IouRecord iouRecord); 14 | public IouRecord queryIouRecordByIouId(@Param(value="iouId")String iouId); // 根据白条id查询白条 15 | public List queryAllIouRecordByFromOrg(@Param(value="fromOrg")String fromOrg); //根据发行机构查询所有白条 16 | public List queryAllIouRecord(); // 获取所有 iouRecord 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/com/formssi/dao/ITransactionDao.java: -------------------------------------------------------------------------------- 1 | package com.formssi.dao; 2 | import java.util.List; 3 | 4 | import org.apache.ibatis.annotations.Param; 5 | 6 | import com.formssi.entity.Transaction; 7 | 8 | 9 | 10 | public interface ITransactionDao { 11 | public void addTransaction(Transaction transaction); // 新增交易 12 | public void updateTransactionStatusByConID(@Param(value="conID")String conId,@Param(value="status")String status,@Param(value="updateTime")String updateTime); // 更新交易状态 --U,未发货--A,已发货 13 | public Transaction getTransactionByConID(@Param(value="conID")String conID); // 根据合同号ID查询交易 14 | public List getAllTransaction(); 15 | } 16 | -------------------------------------------------------------------------------- /src/com/formssi/entity/IouLimitEntity.java: -------------------------------------------------------------------------------- 1 | package com.formssi.entity; 2 | 3 | public class IouLimitEntity { 4 | private String orgID; // 机构号 5 | private String orgName; // 机构名称 6 | private String password; // 登录密码 7 | private int iouLimit; // 白条额度 8 | private String createTime; // 创建时间 9 | private String updateTime; // 更新时间 10 | 11 | // getter methods 12 | public String getOrgID() { 13 | return this.orgID; 14 | } 15 | 16 | public String getOrgName() { 17 | return this.orgName; 18 | } 19 | 20 | public String getPassword() { 21 | return this.password; 22 | } 23 | 24 | public int getIouLimit() { 25 | return this.iouLimit; 26 | } 27 | 28 | public String getCreateTime() { 29 | return this.createTime; 30 | } 31 | 32 | public String getUpdateTime() { 33 | return this.updateTime; 34 | } 35 | 36 | public IouLimitEntity getIouLimitEntity() { 37 | return this; 38 | } 39 | // setter methods 40 | public void setOrgID(String _orgID) { 41 | this.orgID = _orgID; 42 | } 43 | 44 | public void setOrgName(String _orgName) { 45 | this.orgName = _orgName; 46 | } 47 | 48 | public void setPassword(String _password) { 49 | this.password = _password; 50 | } 51 | 52 | public void setIouLimit(int _iouLimit) { 53 | this.iouLimit = _iouLimit; 54 | } 55 | 56 | public void setCreateTime(String _createTime) { 57 | this.createTime = _createTime; 58 | } 59 | 60 | public void setUpdateTime(String _updateTime) { 61 | this.updateTime = _updateTime; 62 | } 63 | 64 | public void setIouLimitEntity(IouLimitEntity _iouLimitEntity) { 65 | this.orgID = _iouLimitEntity.orgID; 66 | this.orgName = _iouLimitEntity.orgName; 67 | this.password = _iouLimitEntity.password; 68 | this.iouLimit = _iouLimitEntity.iouLimit; 69 | this.createTime = _iouLimitEntity.createTime; 70 | this.updateTime = _iouLimitEntity.updateTime; 71 | } 72 | // to json 73 | 74 | // from json 75 | } 76 | -------------------------------------------------------------------------------- /src/com/formssi/entity/IouRecord.java: -------------------------------------------------------------------------------- 1 | package com.formssi.entity; 2 | 3 | public class IouRecord { 4 | private String iouId; // 白条ID 5 | private String fromOrg; // 发行机构 6 | private String recvOrg; // 接收机构 7 | private String transTime; // 交易时间 8 | private int amount; // 交易金额 9 | private int paidAmt; // 已还金额 10 | private String iouStatus; // 白条状态 --C,已还清--U,未还清 11 | private String updateTime; // 更新时间 12 | 13 | // getter methods 14 | public String getIouId() { 15 | return this.iouId; 16 | } 17 | 18 | public String getFromOrg() { 19 | return this.fromOrg; 20 | } 21 | 22 | public String getRecvOrg() { 23 | return this.recvOrg; 24 | } 25 | 26 | public String getTransTime() { 27 | return this.transTime; 28 | } 29 | 30 | public int getAmount() { 31 | return this.amount; 32 | } 33 | 34 | public int getPaidAmt() { 35 | return this.paidAmt; 36 | } 37 | 38 | public String getIouStatus() { 39 | return this.iouStatus; 40 | } 41 | 42 | public String getUpdateTime() { 43 | return this.updateTime; 44 | } 45 | 46 | public IouRecord getIouRecord() { 47 | return this; 48 | } 49 | // setter methods 50 | 51 | public void setIouId(String _iouId) { 52 | this.iouId = _iouId; 53 | } 54 | 55 | public void setFromOrg(String _fromOrg) { 56 | this.fromOrg = _fromOrg; 57 | } 58 | 59 | public void setRecvOrg(String _recvOrg) { 60 | this.recvOrg = _recvOrg; 61 | } 62 | 63 | public void setTransTime(String _transTime) { 64 | this.transTime = _transTime; 65 | } 66 | 67 | public void setAmount(int _amount) { 68 | this.amount = _amount; 69 | } 70 | 71 | public void setPaidAmt(int _paidAmt) { 72 | this.paidAmt = _paidAmt; 73 | } 74 | 75 | public void setIouStatus(String _iouStatus) { 76 | this.iouStatus = _iouStatus; 77 | } 78 | 79 | public void setUpdateTime(String _updateTime) { 80 | this.updateTime = _updateTime; 81 | } 82 | 83 | public void setIouRecord(IouRecord iouRecord) { 84 | this.iouId = iouRecord.iouId; 85 | this.fromOrg = iouRecord.fromOrg; 86 | this.recvOrg = iouRecord.recvOrg; 87 | this.transTime = iouRecord.transTime; 88 | this.amount = iouRecord.amount; 89 | this.paidAmt = iouRecord.paidAmt; 90 | this.iouStatus = iouRecord.iouStatus; 91 | this.updateTime = iouRecord.updateTime; 92 | } 93 | // to json 94 | 95 | // from json 96 | 97 | } 98 | -------------------------------------------------------------------------------- /src/com/formssi/entity/ReturnJson.java: -------------------------------------------------------------------------------- 1 | package com.formssi.entity; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.alibaba.fastjson.JSONObject; 5 | import com.alibaba.fastjson.annotation.JSONField; 6 | /** 7 | * 8 | * @author Administrator 9 | * 10 | */ 11 | 12 | public class ReturnJson { 13 | 14 | private boolean success; // 是否成功 15 | private String message; // 成功失败信息 16 | private Object obj; // 返回对象 17 | 18 | @JSONField(name = "success") 19 | public boolean isSuccess() { 20 | return success; 21 | } 22 | 23 | @JSONField(name = "success") 24 | public void setSuccess(boolean success) { 25 | this.success = success; 26 | } 27 | 28 | @JSONField(name = "message") 29 | public String getMessage() { 30 | return message; 31 | } 32 | 33 | @JSONField(name = "message") 34 | public void setMessage(String message) { 35 | this.message = message; 36 | } 37 | 38 | @JSONField(name = "obj") 39 | public Object getObj() { 40 | return obj; 41 | } 42 | 43 | @JSONField(name = "obj") 44 | public void setObj(Object obj) { 45 | this.obj = obj; 46 | } 47 | 48 | public static ReturnJson parse(String json) { 49 | ReturnJson object=JSON.parseObject(json, ReturnJson.class); 50 | return object; 51 | } 52 | 53 | public String toJSON() { 54 | return JSONObject.toJSONString(this); 55 | } 56 | 57 | @Override 58 | public String toString() { 59 | return "User [success=" + success + ", message=" + message + ", obj=" + obj + "]"; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/com/formssi/entity/Transaction.java: -------------------------------------------------------------------------------- 1 | package com.formssi.entity; 2 | 3 | public class Transaction { 4 | private String conID; // 合同号 5 | private String saleOrg; // 销售方机构 6 | private String buyOrg; // 购买方机构 7 | private String transType; // 交易类型 8 | private long amount; // 白条金额 9 | private String conHash; // 合同hash 10 | private String latestStatus; // 最新状态 --U,未发货--A,已发货 11 | private String transTime; // 交易时间 12 | private String updateTime; // 更新时间 13 | 14 | // getter methods 15 | public String getConID() { 16 | return this.conID; 17 | } 18 | 19 | public String getSaleOrg() { 20 | return this.saleOrg; 21 | } 22 | 23 | public String getBuyOrg() { 24 | return this.buyOrg; 25 | } 26 | 27 | public String getTransType() { 28 | return this.transType; 29 | } 30 | 31 | public long getAmount() { 32 | return this.amount; 33 | } 34 | 35 | public String getConHash() { 36 | return this.conHash; 37 | } 38 | 39 | public String getLatestStatus() { 40 | return this.latestStatus; 41 | } 42 | 43 | public String getTransTime() { 44 | return this.transTime; 45 | } 46 | 47 | public String getUpdateTime() { 48 | return this.updateTime; 49 | } 50 | 51 | public Transaction getTransaction() { 52 | return this; 53 | } 54 | // setter methods 55 | 56 | public void setConID(String _conID) { 57 | this.conID = _conID; 58 | } 59 | 60 | public void setSaleOrg(String _saleOrg) { 61 | this.saleOrg = _saleOrg; 62 | } 63 | 64 | public void setBuyOrg(String _buyOrg) { 65 | this.buyOrg = _buyOrg; 66 | } 67 | 68 | public void setTransType(String _transType) { 69 | this.transType = _transType; 70 | } 71 | 72 | public void setAmount(long _amount) { 73 | this.amount = _amount; 74 | } 75 | 76 | public void setConHash(String _conHash) { 77 | this.conHash = _conHash; 78 | } 79 | 80 | public void setLatestStatus(String _latestStatus) { 81 | this.latestStatus = _latestStatus; 82 | } 83 | 84 | public void setTransTime(String _transTime) { 85 | this.transTime = _transTime; 86 | } 87 | 88 | public void setUpdateTime(String _updateTime) { 89 | this.updateTime = _updateTime; 90 | } 91 | 92 | public void setTransaction(Transaction transaction) { 93 | this.conID = transaction.conID; 94 | this.buyOrg = transaction.buyOrg; 95 | this.saleOrg = transaction.saleOrg; 96 | this.transType = transaction.transType; 97 | this.amount = transaction.amount; 98 | this.conHash = transaction.conHash; 99 | this.latestStatus = transaction.latestStatus; 100 | this.transTime = transaction.transTime; 101 | this.updateTime = transaction.updateTime; 102 | } 103 | // to json 104 | 105 | // from json 106 | 107 | } 108 | -------------------------------------------------------------------------------- /src/com/formssi/filter/CorsFilter.java: -------------------------------------------------------------------------------- 1 | package com.formssi.filter; 2 | 3 | /* 4 | import org.springframework.stereotype.Component; 5 | 6 | import javax.servlet.*; 7 | import javax.servlet.http.HttpServletResponse; 8 | import java.io.IOException; 9 | 10 | 11 | /** 12 | * CorsFileter 功能描述:CORS过滤器 13 | * 14 | * @author RickyLee【l**@*.com.cn】 15 | * @date 2017/2/9 11:24 16 | */ 17 | /* 18 | @Component 19 | public class CorsFilter implements Filter { 20 | 21 | @Override 22 | public void init(FilterConfig filterConfig) throws ServletException { 23 | 24 | } 25 | 26 | @Override 27 | public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { 28 | HttpServletResponse response = (HttpServletResponse) servletResponse; 29 | response.setHeader("Access-Control-Allow-Origin", "127.0.0.1:3000"); 30 | //response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE"); 31 | response.setHeader("Access-Control-Allow-Methods", "*"); 32 | response.setHeader("Access-Control-Max-Age", "3600"); 33 | //response.setHeader("Access-Control-Allow-Headers", "x-requested-with,Authorization,Content-Type"); 34 | response.setHeader("Access-Control-Allow-Headers", "*"); 35 | response.setHeader("Access-Control-Allow-Credentials", "true"); 36 | filterChain.doFilter(servletRequest, servletResponse); 37 | } 38 | 39 | @Override 40 | public void destroy() { 41 | 42 | } 43 | } 44 | */ 45 | 46 | import java.io.IOException; 47 | 48 | import javax.servlet.FilterChain; 49 | import javax.servlet.ServletException; 50 | import javax.servlet.http.HttpServletRequest; 51 | import javax.servlet.http.HttpServletResponse; 52 | 53 | import org.springframework.stereotype.Component; 54 | import org.springframework.web.filter.OncePerRequestFilter; 55 | 56 | /** 57 | * 该类用于跨域使用 58 | * @author Parallel 59 | * 60 | */ 61 | @Component 62 | public class CorsFilter extends OncePerRequestFilter{ 63 | 64 | @Override 65 | protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) 66 | throws ServletException, IOException { 67 | // 在服务器响应客户端的时候,带上Access-Control-Allow-Origin信息,允许特定的域名访问 68 | response.addHeader("Access-Control-Allow-Origin", "http://localhost:3000"); 69 | response.addHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE"); 70 | response.addHeader("Access-Control-Allow-Headers", "X-Requested-With, accept, content-type, xxxx"); 71 | response.addHeader("Access-Control-Max-Age", "1800");//30 min 72 | 73 | // 74 | response.setHeader("Access-Control-Allow-Credentials", "true"); 75 | filterChain.doFilter(request, response); 76 | 77 | } 78 | 79 | } -------------------------------------------------------------------------------- /src/com/formssi/init/WebInitializer.java: -------------------------------------------------------------------------------- 1 | package com.formssi.init; 2 | 3 | import javax.servlet.ServletContext; 4 | import javax.servlet.ServletException; 5 | 6 | import org.slf4j.Logger; 7 | import org.slf4j.LoggerFactory; 8 | import org.springframework.web.WebApplicationInitializer; 9 | 10 | import com.formssi.service.impl.IOUService; 11 | 12 | public class WebInitializer implements WebApplicationInitializer { 13 | 14 | private Logger logger = LoggerFactory.getLogger(this.getClass()); 15 | 16 | public void onStartup(ServletContext servletContext) throws ServletException { 17 | logger.info("容器启动初始化start..."); 18 | 19 | try { 20 | IOUService.initObj(); 21 | } catch (Exception e) { 22 | // TODO Auto-generated catch block 23 | e.printStackTrace(); 24 | } 25 | 26 | logger.info("容器启动初始化end..."); 27 | } 28 | } -------------------------------------------------------------------------------- /src/com/formssi/interceptor/LoginInterceptor.java: -------------------------------------------------------------------------------- 1 | package com.formssi.interceptor; 2 | 3 | import java.io.IOException; 4 | import java.io.PrintWriter; 5 | 6 | import javax.servlet.http.HttpServletRequest; 7 | import javax.servlet.http.HttpServletResponse; 8 | import javax.servlet.http.HttpSession; 9 | 10 | import org.slf4j.Logger; 11 | import org.slf4j.LoggerFactory; 12 | import org.springframework.web.servlet.HandlerInterceptor; 13 | import org.springframework.web.servlet.ModelAndView; 14 | 15 | import com.alibaba.fastjson.JSON; 16 | import com.formssi.entity.ReturnJson; 17 | import com.sun.jmx.snmp.Timestamp; 18 | 19 | import utils.MySessionContext; 20 | 21 | /** 22 | * 登录认证的拦截器 23 | */ 24 | public class LoginInterceptor implements HandlerInterceptor{ 25 | 26 | private Logger logger = LoggerFactory.getLogger(this.getClass()); 27 | 28 | /** 29 | * Handler执行完成之后调用这个方法 30 | */ 31 | public void afterCompletion(HttpServletRequest request, 32 | HttpServletResponse response, Object handler, Exception exc) 33 | throws Exception { 34 | 35 | } 36 | 37 | /** 38 | * Handler执行之后,ModelAndView返回之前调用这个方法 39 | */ 40 | public void postHandle(HttpServletRequest request, HttpServletResponse response, 41 | Object handler, ModelAndView modelAndView) throws Exception { 42 | } 43 | 44 | /** 45 | * Handler执行之前调用这个方法 46 | */ 47 | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, 48 | Object handler) throws Exception { 49 | response.setHeader("Access-Control-Allow-Origin", "*");//跨域访问 50 | ReturnJson returnJson = new ReturnJson(); 51 | 52 | //说明是下载请求,无需拦截 53 | if(request.getRequestURI().indexOf("dowloadFile") != -1) { 54 | returnJson.setSuccess(true); 55 | returnJson.setMessage("下载请求成功"); 56 | 57 | return true; 58 | } 59 | 60 | //说明是登录请求,无需拦截 61 | if(request.getRequestURI().indexOf("login") != -1) { 62 | returnJson.setSuccess(true); 63 | returnJson.setMessage("登录请求成功"); 64 | 65 | return true; 66 | } 67 | 68 | //说明是登出请求,无需拦截 69 | if(request.getRequestURI().indexOf("logout") != -1) { 70 | returnJson.setSuccess(true); 71 | returnJson.setMessage("登出请求成功"); 72 | 73 | return true; 74 | } 75 | 76 | String token = request.getParameter("token"); 77 | if(token == null) { 78 | String data = request.getParameter("data"); 79 | token = (String)JSON.parseObject(data).get("token"); 80 | } 81 | 82 | if(token == null){ 83 | 84 | returnJson.setSuccess(false); 85 | returnJson.setMessage("登录验证失败,缺少token"); 86 | 87 | dealJsonReturn(request, response, returnJson.toJSON()); 88 | 89 | return false; 90 | } 91 | 92 | String sessionId = request.getParameter("sessionId"); 93 | if(sessionId == null) { 94 | String data = request.getParameter("data"); 95 | sessionId = (String)JSON.parseObject(data).get("sessionId"); 96 | } 97 | 98 | HttpSession session = MySessionContext.getSession(sessionId); 99 | 100 | if(session == null || session.getAttribute(sessionId) == null) { 101 | returnJson.setSuccess(false); 102 | returnJson.setMessage("登录验证失败,已登出"); 103 | 104 | dealJsonReturn(request, response, returnJson.toJSON()); 105 | 106 | return false; 107 | } 108 | 109 | String tokenAnddateTime = (String)session.getAttribute(sessionId); 110 | 111 | String[] tokenAnddateTimeArray = tokenAnddateTime.split(","); 112 | String tokenStorage = tokenAnddateTimeArray[0]; 113 | 114 | if(tokenStorage == null || token == null || !tokenStorage.equals(token)) { 115 | returnJson.setSuccess(false); 116 | returnJson.setMessage("登录验证失败,token不匹配"); 117 | 118 | dealJsonReturn(request, response, returnJson.toJSON()); 119 | 120 | return false; 121 | } 122 | 123 | String dateTimeStr = tokenAnddateTimeArray[1]; 124 | Long dateTime = Long.parseLong(dateTimeStr); 125 | Long before5 = new Timestamp().getDateTime() - 300000;//5分钟为超时时间 126 | if(dateTime < before5) { 127 | returnJson.setSuccess(false); 128 | returnJson.setMessage("登录验证失败,已超时"); 129 | 130 | dealJsonReturn(request, response, returnJson.toJSON()); 131 | 132 | return false; 133 | } 134 | 135 | //returnJson.setSuccess(true); 136 | //returnJson.setMessage("登录验证成功"); 137 | 138 | //更新token以及token的时间 139 | //String newToken = Token.getToken(); 140 | session.setAttribute(sessionId, token + "," + new Timestamp().getDateTime()); 141 | //更新Token,防止重复提交 142 | //response.setHeader("token", newToken); 143 | 144 | //dealJsonReturn(request, response, returnJson.toJSON()); 145 | 146 | return true; 147 | } 148 | 149 | /** 150 | * 处理json返回 151 | * @param request 152 | * @param response 153 | * @param json 154 | */ 155 | public void dealJsonReturn(HttpServletRequest request, HttpServletResponse response, String json){ 156 | PrintWriter writer = null; 157 | response.setCharacterEncoding("UTF-8"); 158 | response.setContentType("text/html; charset=utf-8"); 159 | try { 160 | writer = response.getWriter(); 161 | writer.print(json); 162 | 163 | } catch (IOException ex) { 164 | logger.error("response error",ex); 165 | } finally { 166 | if (writer != null) 167 | writer.close(); 168 | } 169 | } 170 | 171 | } 172 | -------------------------------------------------------------------------------- /src/com/formssi/service/IIouLimitEntityService.java: -------------------------------------------------------------------------------- 1 | package com.formssi.service; 2 | 3 | import java.util.concurrent.ExecutionException; 4 | 5 | import com.formssi.entity.IouLimitEntity; 6 | 7 | public interface IIouLimitEntityService { 8 | 9 | public boolean addIouLimitEntity(String orgID,String orgName,String password,int iouLimit) throws InterruptedException, ExecutionException; // 新增机构 10 | 11 | public boolean setIouLimit(int amount,String updateTime,String orgID) throws InterruptedException, ExecutionException; // 设定白条额度 12 | 13 | public int getIouLimit(String orgID); // 获取白条额度 14 | 15 | public boolean recycleIou(String iouId,int amount)throws InterruptedException, ExecutionException; // 回收白条 16 | 17 | public int checkPasswordByorgID(String password,String orgID,String Name);//检查password 18 | 19 | public IouLimitEntity getIouLimitEntityByConId(String orgID);//根据企业的ID来返回企业的信息 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/com/formssi/service/IIouRecordService.java: -------------------------------------------------------------------------------- 1 | package com.formssi.service; 2 | import java.util.List; 3 | 4 | import com.formssi.entity.IouRecord; 5 | 6 | 7 | public interface IIouRecordService { 8 | 9 | public void addIouRecord(IouRecord iouRecord); // 添加白条记录 10 | 11 | public IouRecord queryIouRecordByIouId(String iouId); // 通过iouId获取白条交易记录 12 | 13 | public List queryIouRecordByFromOrg(String fromOrg); // 通过发行方id获取白条交易记录 14 | 15 | public List queryIouRecordByRecvOrg(String recvOrg); // 通过接受方id获取白条交易记录 16 | 17 | public List getIouRecordList(int pageNo,int pageSize); //查询所有的白条记录 18 | 19 | public List getAllIouRecord(); //查询所有白条记录 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/com/formssi/service/ITransactionService.java: -------------------------------------------------------------------------------- 1 | package com.formssi.service; 2 | import java.util.List; 3 | import java.util.concurrent.ExecutionException; 4 | 5 | import org.apache.ibatis.annotations.Param; 6 | 7 | import com.formssi.entity.Transaction; 8 | 9 | 10 | public interface ITransactionService { 11 | public boolean addTransactionRecord(String saleOrg,String buyOrg,String transType,long amount,String latestStatus,String conID,String conHash)throws InterruptedException, ExecutionException; // 录入交易 12 | 13 | public boolean updateTransactionStatusByConId(@Param("conId")String conId,@Param("status")String status); // 交易状态修改 14 | 15 | public Transaction getTransactionByConId(@Param("conId")String conId); // 根据合同号ID查询交易 16 | 17 | public List getAllTransaction(); // 查询所有交易信息 18 | 19 | public List queryTransaction(int pageNo,int pageSize); // 查询所有交易信息 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/com/formssi/service/impl/IOUService.java: -------------------------------------------------------------------------------- 1 | package com.formssi.service.impl; 2 | 3 | import java.io.IOException; 4 | import java.math.BigInteger; 5 | import java.util.ArrayList; 6 | import java.util.Arrays; 7 | import java.util.List; 8 | import java.util.concurrent.ExecutionException; 9 | import java.util.concurrent.Future; 10 | 11 | import org.bcos.channel.client.Service; 12 | import org.bcos.channel.handler.ChannelConnections; 13 | import org.bcos.web3j.abi.datatypes.Utf8String; 14 | import org.bcos.web3j.abi.datatypes.generated.Int256; 15 | import org.bcos.web3j.abi.datatypes.generated.Uint256; 16 | import org.bcos.web3j.crypto.Credentials; 17 | import org.bcos.web3j.crypto.WalletUtils; 18 | import org.bcos.web3j.protocol.Web3j; 19 | import org.bcos.web3j.protocol.channel.ChannelEthereumService; 20 | import org.bcos.web3j.protocol.core.methods.response.TransactionReceipt; 21 | import org.bcos.web3j.protocol.http.HttpService; 22 | import org.bcos.web3j.protocol.parity.Parity; 23 | import org.slf4j.Logger; 24 | import org.slf4j.LoggerFactory; 25 | import org.springframework.context.support.AbstractApplicationContext; 26 | import org.springframework.context.support.ClassPathXmlApplicationContext; 27 | import org.springframework.stereotype.Controller; 28 | 29 | import com.formssi.entity.IouLimitEntity; 30 | import com.formssi.entity.IouRecord; 31 | import com.formssi.entity.Transaction; 32 | import com.formssi.service.IIouLimitEntityService; 33 | import com.formssi.service.IIouRecordService; 34 | import com.formssi.service.ITransactionService; 35 | 36 | import exception.initConfigException; 37 | import utils.PropertiesUtil; 38 | import utils.Utils; 39 | 40 | import org.springframework.beans.factory.annotation.Autowired; 41 | import org.springframework.context.ApplicationContext; 42 | 43 | 44 | 45 | import wrapper.SuplInfo; 46 | import wrapper.SuplInfo.AddTransactionEventResponse; 47 | import wrapper.SuplInfo.InitIouLimitDataEventResponse; 48 | import wrapper.SuplInfo.IouRecycleEventResponse; 49 | import wrapper.SuplInfo.SetIouLimitEventResponse; 50 | import wrapper.SuplInfo.UpdateTransStatusResultEventResponse; 51 | 52 | @Controller 53 | public class IOUService { 54 | static Logger logger = LoggerFactory.getLogger(IOUService.class); 55 | static private final List IOU_STATELIST= Arrays.asList("U","C","P"); 56 | static private final List TRAN_LATESTSTATE_LIST= Arrays.asList("U","C"); 57 | // 初始化交易参数 58 | private static BigInteger gasPrice = new BigInteger("99999999999"); 59 | private static BigInteger gasLimit = new BigInteger("9999999999999"); 60 | 61 | private static Web3j web3j = null; 62 | private static AbstractApplicationContext Context = null; 63 | private static Credentials credentials = null; 64 | 65 | @Autowired 66 | private static IIouLimitEntityService iouLimitEntityServiceImpl; 67 | @Autowired 68 | private static IIouRecordService iouRecordServiceImpl; 69 | @Autowired 70 | private static ITransactionService transactionServiceImpl; 71 | @Autowired 72 | private static SuplInfo contractTransaction; 73 | 74 | private static List contractAddressList = new ArrayList<>(); 75 | 76 | private static String subPath = null; 77 | 78 | public static void initObj() throws Exception{ 79 | String path = Thread.currentThread().getContextClassLoader().getResource("").toString(); 80 | subPath = path.substring(5, path.length()); 81 | 82 | logger.info("开始测试..."); 83 | logger.info("==================================================================="); 84 | 85 | // 读取applicationContext.xml里的配置信息 86 | Context = new ClassPathXmlApplicationContext("classpath:applicationContext.xml"); 87 | System.out.println("context is:" + Context); 88 | web3j = buildWeb3jByRPC(Context); 89 | // web3j = buildWeb3j(context); 90 | 91 | try{ 92 | if(web3j == null){ 93 | throw new initConfigException("初始化web3j失败"); 94 | } 95 | } catch(initConfigException e){ 96 | e.printStackTrace(); 97 | } 98 | 99 | // 初始化交易签名私钥 100 | PropertiesUtil.readFile("wallet.properties"); 101 | credentials = WalletUtils.loadCredentials( 102 | PropertiesUtil.readValue("wallet.password"), 103 | subPath+PropertiesUtil.readValue("wallet.path")); 104 | logger.info("credentials address:{}",credentials.getAddress()); 105 | 106 | // 加载已部署的合约 107 | PropertiesUtil.readFile("config.properties"); 108 | 109 | for(int i = 0; i<1; i++){ 110 | String contractAddress = PropertiesUtil.readValue("contract.address."+i); 111 | contractAddressList.add(contractAddress); 112 | contractTransaction=SuplInfo.load(contractAddress, web3j, credentials, gasPrice, gasLimit); 113 | } 114 | logger.info("初始化结束"); 115 | 116 | } 117 | 118 | private static Web3j buildWeb3jByRPC(AbstractApplicationContext context) { 119 | 120 | // 获取一个Service的实例 121 | System.out.println("context is:" + context); 122 | Service service = context.getBean(Service.class); 123 | System.out.println("service is:" + service); 124 | context.close(); 125 | 126 | ChannelConnections fromChannelConnections = service.getAllChannelConnections().get(service.getOrgID()); 127 | List list = fromChannelConnections.getConnectionsStr(); 128 | for(String str:list){ 129 | System.out.println("ConnectionsStr:"+str); 130 | } 131 | String[] split1 = list.get(0).split("@"); 132 | String targetaddress = ""; 133 | if (split1.length > 1) { 134 | targetaddress = split1[1]; 135 | } 136 | 137 | HttpService httpService = new HttpService("http://"+targetaddress); 138 | Web3j Web3 = Parity.build(httpService); 139 | 140 | return Web3; 141 | } 142 | 143 | private static Web3j buildWeb3jByAMOP(AbstractApplicationContext transactionContext) throws InterruptedException { 144 | Service service = transactionContext.getBean(Service.class); 145 | try { 146 | service.run(); 147 | } catch (Exception e) { 148 | // TODO Auto-generated catch block 149 | e.printStackTrace(); 150 | } 151 | Thread.sleep(3000); 152 | ChannelEthereumService channelEthereumService = new ChannelEthereumService(); 153 | channelEthereumService.setChannelService(service); 154 | //使用AMOP消息信道初始化web3j 155 | return Web3j.build(channelEthereumService); 156 | } 157 | 158 | public static Web3j buildWeb3j(AbstractApplicationContext context) throws Exception{ 159 | //初始化 Service 160 | Service service = context.getBean(Service.class); 161 | service.run(); 162 | Thread.sleep(3000); 163 | System.out.println("开始测试..."); 164 | System.out.println("==================================================================="); 165 | System.out.println("初始化 AOMP 的 ChannelEthereumService"); 166 | ChannelEthereumService channelEthereumService = new ChannelEthereumService(); 167 | channelEthereumService.setChannelService(service); 168 | //使用 AMOP 消息信道初始化 web3j 169 | Web3j web3 = Web3j.build(channelEthereumService); 170 | return web3; 171 | } 172 | 173 | public static void queryBlockNumber() throws IOException{ 174 | BigInteger blockNumber = web3j.ethBlockNumber().send().getBlockNumber(); 175 | logger.info("blockNumber:{}",blockNumber.intValue()); 176 | } 177 | 178 | // @Service("addTransaction") 179 | 180 | // public static boolean checkPassword(String orgID,String password) { 181 | // boolean isSuccess = iouLimitEntityServiceImpl.checkPasswordByOrgID(password, orgID); 182 | // if(isSuccess) { 183 | // System.out.println("登录成功"); 184 | // return true; 185 | // }else { 186 | // System.out.println("登录失败"); 187 | // return false; 188 | // } 189 | // } 190 | 191 | public static String initIouLimitData(String orgID,String orgName,String password,int iouLimit) throws InterruptedException, ExecutionException { 192 | // IouLimitEntity iouLimitEntity = new IouLimitEntity(); 193 | long now=System.currentTimeMillis(); 194 | String createTime = Utils.sdf(now); 195 | // iouLimitEntity.setOrgID(orgID); 196 | // iouLimitEntity.setOrgName(orgName); 197 | // iouLimitEntity.setPassword(password); 198 | // iouLimitEntity.setIouLimit(iouLimit); 199 | // iouLimitEntity.setCreateTime(createTime); 200 | // iouLimitEntity.setUpdateTime(createTime); 201 | // //检查一下本地有没有已经注册了的机构 202 | // 203 | // boolean isSuccess = iouLimitEntityServiceImpl.addIouLimitEntity(orgID,orgName,password,iouLimit); 204 | // if(!isSuccess) { 205 | // //创建失败 206 | // return "创建失败,已经有该机构"; 207 | // } 208 | //区块链上新建 209 | TransactionReceipt receipt = contractTransaction.initIouLimitData( new Utf8String(orgID), 210 | new Utf8String(orgName), 211 | new Int256(iouLimit), 212 | new Utf8String(createTime), 213 | new Utf8String(createTime) 214 | ).get(); 215 | List responses = contractTransaction.getInitIouLimitDataEvents(receipt); 216 | String result=responses.get(0)._json.toString(); 217 | return result; 218 | } 219 | public static String setIouLimit(String orgID,int amount) throws InterruptedException, ExecutionException { 220 | //设置数据库的limit 221 | long now=System.currentTimeMillis(); 222 | String updateTime = Utils.sdf(now); // 获取当前时间 223 | //iouLimitEntityServiceImpl.setIouLimit(amount, updateTime, orgID); 224 | //更改区块链上的 225 | TransactionReceipt receipt = contractTransaction.setIouLimit(new Utf8String(orgID), new Int256(amount)).get(); 226 | logger.info("setIouLimit receipt transactionHash:{}",receipt.getTransactionHash()); 227 | List responses = contractTransaction.getSetIouLimitEvents(receipt); 228 | String result=responses.get(0)._json.toString(); 229 | return result; 230 | } 231 | public static String getIouLimit(String orgID) throws InterruptedException, ExecutionException { 232 | // 直接从后端数据库查询 233 | int amount = iouLimitEntityServiceImpl.getIouLimit(orgID); 234 | //应该删掉以下的代码 235 | // String receipt = contractTransaction.getIouLimit(new Utf8String(orgID)).get().getValue(); 236 | // logger.info("getIouLimit receipt transactionHash:{}",receipt); 237 | return ""+amount; 238 | } 239 | public static List getIouList(int pageNo,int pageSize) throws InterruptedException, ExecutionException { 240 | // 直接从后端数据库查询 241 | return iouRecordServiceImpl.getIouRecordList(pageNo,pageSize); 242 | //应该删掉以下的代码 243 | // String receipt = contractTransaction.getIouList(new Uint256(pageNo),new Uint256(pageSize)).get().getValue(); 244 | // logger.info("getIouList receipt transactionHash:{}",receipt); 245 | // return receipt; 246 | } 247 | // public static String addIouRecord(IouRecord iouRecord) { 248 | // TransactionReceipt receipt = contractTransaction.addIou(new Utf8String(iouRecord.getIouId()), 249 | // new Utf8String(iouRecord.getFromOrg()), 250 | // new Utf8String(iouRecord.getRecvOrg()), 251 | // new Utf8String(iouRecord.getTransTime()), 252 | // new Int256(iouRecord.getAmount()), 253 | // new Int256(iouRecord.getPaidAmt()), 254 | // new Utf8String(iouRecord.getIouStatus()), 255 | // new Utf8String(iouRecord.getTransTime()), 256 | // new Utf8String(iouRecord.getUpdateTime())) 257 | // logger.info("iouRecycle receipt transactionHash:{}",receipt); 258 | // List responses = contractTransaction.getAddIouEvents(receipt); 259 | // String result=responses.get(0)._json.toString(); 260 | // return result; 261 | // } 262 | public static String iouRecycle(String iouId,int amount) throws InterruptedException, ExecutionException { 263 | // 修改后端数据库 264 | // boolean isSuccess = iouLimitEntityServiceImpl.recycleIou(iouId,amount); 265 | // if(!isSuccess) { 266 | // System.out.println("回收白条失败"); 267 | // } 268 | //更新区块链 269 | TransactionReceipt receipt = contractTransaction.iouRecycle(new Utf8String(iouId),new Int256(amount)).get(); 270 | logger.info("iouRecycle receipt transactionHash:{}",receipt); 271 | List responses = contractTransaction.getIouRecycleEvents(receipt); 272 | String result=responses.get(0)._json.toString(); 273 | return result; 274 | } 275 | 276 | public static String addTransaction(String saleOrg,String buyOrg,String transType,long amount,String latestStatus,String conID,String conHash) throws InterruptedException, ExecutionException{ 277 | // 合同hash 278 | long now=System.currentTimeMillis(); 279 | String transTime = Utils.sdf(now); 280 | // String conID="conID"+transTime; // 合同号 281 | // String conHash="conHash"; 282 | // Transaction transaction = new Transaction(); 283 | // transaction.setConID(conID); 284 | // transaction.setSaleOrg(saleOrg); 285 | // transaction.setBuyOrg(buyOrg); 286 | // transaction.setTransType(transType); 287 | // transaction.setAmount(amount); 288 | // transaction.setLatestStatus(latestStatus); 289 | // transaction.setConHash(conHash); 290 | // transaction.setTransTime(transTime); 291 | // transaction.setUpdateTime(transTime); 292 | // //修改后端数据库 293 | // boolean isSuccess = transactionServiceImpl.addTransactionRecord(transaction); 294 | // if(!isSuccess) { 295 | // System.out.println("录入出错"); 296 | // return "录入交易出错"; 297 | // } 298 | //更新区块链 299 | logger.info("transaction's conId is "+conID); 300 | TransactionReceipt receipt = contractTransaction.addTransaction(new Utf8String(conID), 301 | new Utf8String(saleOrg), 302 | new Utf8String(buyOrg), 303 | new Utf8String(transType), 304 | new Int256(amount), 305 | new Utf8String(conHash), 306 | new Utf8String(latestStatus), 307 | new Utf8String(transTime), 308 | new Utf8String(transTime)).get(); 309 | logger.info("addTransaction receipt transactionHash:{}",receipt.getTransactionHash()); 310 | logger.info("receipt's contract addr is ?"+receipt.getContractAddress()); 311 | List responses = contractTransaction.getAddTransactionEvents(receipt); 312 | logger.info("responses size is"+responses.size()); 313 | String result=responses.get(0)._json.toString(); 314 | return result; 315 | } 316 | 317 | public static int updateTransStatus(String conId, String status) throws InterruptedException, ExecutionException { 318 | //更新数据库 319 | // boolean isSuccess = transactionServiceImpl.updateTransactionStatusByConId(conId, status); 320 | // if(!isSuccess) { 321 | // System.out.println("更新交易出错"); 322 | // return -1; 323 | // } 324 | System.out.println("更新交易 IOUStatus:"+status); 325 | //更新区块链 326 | if(!TRAN_LATESTSTATE_LIST.contains(status)) { 327 | logger.info("the value of IOU Status must be C or U."); 328 | return -1; 329 | } 330 | TransactionReceipt receipt = contractTransaction.updateTransStatus(new Utf8String(conId), new Utf8String(status)).get(); 331 | logger.info("updateTransStatus receipt transactionHash:{}",receipt.getTransactionHash()); 332 | List responses = contractTransaction.getUpdateTransStatusResultEvents(receipt); 333 | int result = responses.get(0)._code.getValue().intValue(); 334 | return result; 335 | } 336 | 337 | public static Utf8String queryTransactionByConId(String conId) throws InterruptedException, ExecutionException{ 338 | // 直接从后端数据库查询 339 | // Transaction transaction = transactionServiceImpl.getTransactionByConId(conId); 340 | // if(transaction==null) { 341 | // // 不存在该交易的话返回null 342 | // } 343 | // transaction to json 344 | // return transaction; 345 | //应该删掉以下的代码 346 | Future result = contractTransaction.queryTransByConId(new Utf8String(conId)); 347 | logger.info("queryTransaction result is:{}",result.get()); 348 | return result.get(); 349 | } 350 | 351 | public static List queryTransList(int pageNo,int pageSize) throws InterruptedException, ExecutionException { 352 | // 直接从后端数据库查询 353 | List result = transactionServiceImpl.getAllTransaction(); 354 | // transaction to json 355 | return result; 356 | //应该删掉以下的代码 357 | // String receipt = contractTransaction.queryTransList(new Uint256(pageNo),new Uint256(pageSize)).get().getValue(); 358 | // logger.info("queryTransList receipt transactionHash:{}",receipt); 359 | // return receipt; 360 | } 361 | public static int getIouLength() throws InterruptedException, ExecutionException { 362 | // 直接从后端数据库查询 TODO 363 | List result = iouRecordServiceImpl.getAllIouRecord(); 364 | return result.size(); 365 | //应该删掉以下的代码 366 | // Uint256 receipt = contractTransaction.getIouLength().get(); 367 | // logger.info("getIouLength receipt transactionHash:{}",receipt); 368 | // return receipt.getValue().toString(); 369 | } 370 | 371 | public static int getTransLength() throws InterruptedException, ExecutionException { 372 | // 直接从后端数据库查询 TODO 373 | List result = transactionServiceImpl.getAllTransaction(); 374 | return result.size(); 375 | //应该删掉以下的代码 376 | // Uint256 receipt = contractTransaction.getTransLength().get(); 377 | // logger.info("getTransLength receipt transactionHash:{}",receipt); 378 | // return receipt.getValue().toString(); 379 | } 380 | public static Utf8String getVersion() throws InterruptedException, ExecutionException{ 381 | Future result = contractTransaction.getVersion(); 382 | System.out.println("result is null?"); 383 | System.out.println(result==null); 384 | System.out.println("result is "); 385 | System.out.println(result.get().getValue()); 386 | logger.info("version is ",result.get()); 387 | // result. 388 | return result.get(); 389 | } 390 | 391 | public static void checkParam() { 392 | System.out.println("web3j is null?" + web3j==null); 393 | System.out.println("contractTransaction is null?" + contractTransaction==null); 394 | } 395 | } 396 | -------------------------------------------------------------------------------- /src/com/formssi/service/impl/IouLimitEntityServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.formssi.service.impl; 2 | 3 | import java.util.List; 4 | import java.util.concurrent.ExecutionException; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.stereotype.Service; 8 | 9 | import com.formssi.dao.IIouLimitEntityDao; 10 | import com.formssi.dao.IIouRecordDao; 11 | import com.formssi.entity.IouLimitEntity; 12 | import com.formssi.entity.IouRecord; 13 | import com.formssi.service.IIouLimitEntityService; 14 | 15 | import utils.Utils; 16 | 17 | 18 | 19 | @Service 20 | public class IouLimitEntityServiceImpl implements IIouLimitEntityService { 21 | @Autowired 22 | private IIouLimitEntityDao iiouLimitEntityDao; 23 | @Autowired 24 | private IIouRecordDao iiouRecordDao; 25 | 26 | @Override 27 | public boolean setIouLimit(int iouLimit,String updateTime,String orgID) throws InterruptedException, ExecutionException { 28 | // TODO Auto-generated method stub 29 | if(iouLimit<0) { 30 | // 确保数据的合理性 31 | System.out.println("数值小于0"); 32 | return false; 33 | } 34 | //检查数据库是否存在该orgID 35 | IouLimitEntity tmp = iiouLimitEntityDao.queryIouLimitEntityByOrgID(orgID); 36 | if(tmp==null) { 37 | //不存在该机构 38 | System.out.println("机构不存在"); 39 | return false; 40 | }else { 41 | iiouLimitEntityDao.updateIouLimitByOrgID(iouLimit, updateTime, orgID); 42 | IOUService.setIouLimit(orgID, iouLimit); 43 | return true; 44 | } 45 | } 46 | 47 | @Override 48 | public int getIouLimit(String orgID) { 49 | // TODO Auto-generated method stub 50 | return iiouLimitEntityDao.getIouLimitByOrgID(orgID); 51 | } 52 | 53 | @Override 54 | public boolean recycleIou(String iouId,int amount) throws InterruptedException, ExecutionException { 55 | // TODO Auto-generated method stub 56 | //修改两家机构的白条额度 57 | IouRecord iouRecord = iiouRecordDao.queryIouRecordByIouId(iouId); 58 | String fromOrgID = iouRecord.getFromOrg(); 59 | String recvOrgID = iouRecord.getRecvOrg(); 60 | IouLimitEntity fromOrg = iiouLimitEntityDao.queryIouLimitEntityByOrgID(fromOrgID); 61 | IouLimitEntity recvOrg = iiouLimitEntityDao.queryIouLimitEntityByOrgID(recvOrgID); 62 | int fromOrgLimit = fromOrg.getIouLimit(); 63 | int recvOrgLimit = recvOrg.getIouLimit(); 64 | //判断是否足够,有可能吗??? 65 | if(fromOrgLimit-amount<0) { 66 | System.out.println("对方白条数量不够,无法回收"); 67 | return false; 68 | } 69 | long now=System.currentTimeMillis(); 70 | String updateTime = Utils.sdf(now); 71 | fromOrg.setIouLimit(fromOrgLimit+amount); 72 | fromOrg.setUpdateTime(updateTime); 73 | // recvOrg.setIouLimit(recvOrgLimit-amount); 74 | // recvOrg.setUpdateTime(updateTime); 75 | iiouLimitEntityDao.updateIouLimitEntity(fromOrg); 76 | //修改白条交易记录的已还金额 77 | iouRecord.setPaidAmt(iouRecord.getPaidAmt()+amount); 78 | //修改还清状态 79 | if(iouRecord.getAmount() == iouRecord.getPaidAmt()) { 80 | iouRecord.setIouStatus("C"); 81 | } 82 | iouRecord.setUpdateTime(updateTime); 83 | iiouRecordDao.updateIouRecord(iouRecord); 84 | IOUService.iouRecycle(iouId, amount); 85 | return true; 86 | } 87 | 88 | @Override 89 | public boolean addIouLimitEntity(String orgID,String orgName,String password,int iouLimit) throws InterruptedException, ExecutionException { 90 | // TODO Auto-generated method stub 91 | 92 | IouLimitEntity tmp = iiouLimitEntityDao.queryIouLimitEntityByOrgID(orgID); 93 | if(tmp==null) { 94 | // 数据库中不存在,可以新建 95 | System.out.println("iiouLimitEntityDao==null"+iiouLimitEntityDao==null); 96 | System.out.println(iiouLimitEntityDao); 97 | IouLimitEntity iouLimitEntity = new IouLimitEntity(); 98 | iouLimitEntity.setOrgID(orgID); 99 | iouLimitEntity.setOrgName(orgName); 100 | iouLimitEntity.setPassword(Utils.getSHA256Str(password)); 101 | iouLimitEntity.setIouLimit(iouLimit); 102 | long now=System.currentTimeMillis(); 103 | String time = Utils.sdf(now); 104 | iouLimitEntity.setCreateTime(time); 105 | iouLimitEntity.setUpdateTime(time); 106 | iiouLimitEntityDao.addIouLimitEntity(iouLimitEntity); 107 | 108 | // 在区块链中创建 109 | IOUService.initIouLimitData(orgID, orgName, password, iouLimit); 110 | 111 | return true; 112 | }else { 113 | //提示帐号已存在 114 | System.out.println("帐号已存在"); 115 | return false; 116 | } 117 | // return true; 118 | } 119 | 120 | @Override 121 | public int checkPasswordByorgID(String password,String orgID,String orgName) { 122 | IouLimitEntity tmp = iiouLimitEntityDao.queryIouLimitEntityByOrgID(orgID); 123 | if(tmp == null) { 124 | //不存在该机构 125 | System.out.println("机构不存在"); 126 | return -1; 127 | }else { 128 | String name = tmp.getOrgName(); 129 | if(name.equals(orgName)){ 130 | String passwd = tmp.getPassword(); 131 | if (Utils.getSHA256Str(password).equals(passwd)){ 132 | System.out.println("密码正确"); 133 | return 1; 134 | } 135 | else { 136 | System.out.println("密码错误"); 137 | return 0; 138 | } 139 | }else { 140 | System.out.println("机构类型不正确"); 141 | return -2; 142 | } 143 | } 144 | } 145 | 146 | public IouLimitEntity getIouLimitEntityByConId(String orgID) {//根据企业的ID来返回企业的信息 147 | return iiouLimitEntityDao.queryIouLimitEntityByOrgID(orgID); 148 | } 149 | 150 | } 151 | -------------------------------------------------------------------------------- /src/com/formssi/service/impl/IouRecordServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.formssi.service.impl; 2 | import java.util.ArrayList; 3 | import java.util.List; 4 | 5 | import org.springframework.beans.factory.annotation.Autowired; 6 | import org.springframework.stereotype.Service; 7 | 8 | import com.formssi.dao.IIouLimitEntityDao; 9 | import com.formssi.dao.IIouRecordDao; 10 | import com.formssi.dao.ITransactionDao; 11 | import com.formssi.entity.IouLimitEntity; 12 | import com.formssi.entity.IouRecord; 13 | import com.formssi.service.IIouRecordService; 14 | 15 | 16 | 17 | @Service 18 | public class IouRecordServiceImpl implements IIouRecordService{ 19 | 20 | @Autowired(required=false) 21 | private IIouRecordDao iiouRecordDao; 22 | @Autowired(required=false) 23 | private ITransactionDao itransactionDao; 24 | @Autowired(required=false) 25 | private IIouLimitEntityDao iiouLimitEntityDao; 26 | 27 | @Override 28 | public List getIouRecordList(int pageNo,int pageSize) { 29 | // TODO Auto-generated method stub 30 | pageNo--; 31 | List allIouRecord = iiouRecordDao.queryAllIouRecord(); 32 | List result = new ArrayList<>(); 33 | for(int i=pageNo*pageSize;i queryIouRecordByFromOrg(String fromOrg) { 47 | // TODO Auto-generated method stub 48 | return null; 49 | } 50 | 51 | @Override 52 | public List queryIouRecordByRecvOrg(String recvOrg) { 53 | // TODO Auto-generated method stub 54 | return null; 55 | } 56 | 57 | @Override 58 | public void addIouRecord(IouRecord iouRecord) { 59 | // TODO Auto-generated method stub 60 | if(iouRecord.getAmount()<= 0) { 61 | // 确保数据的合理性 62 | System.out.println("白条金额不可小于0"); 63 | return; 64 | } 65 | IouLimitEntity tmpBuy = iiouLimitEntityDao.queryIouLimitEntityByOrgID(iouRecord.getFromOrg()); 66 | IouLimitEntity tmpSale = iiouLimitEntityDao.queryIouLimitEntityByOrgID(iouRecord.getRecvOrg()); 67 | if(tmpBuy==null||tmpSale==null) { 68 | //不存在该机构 69 | System.out.println("机构不存在"); 70 | return; 71 | }else { 72 | iiouRecordDao.addIouRecord(iouRecord); 73 | System.out.println("创建白条"); 74 | return; 75 | } 76 | } 77 | 78 | @Override 79 | public List getAllIouRecord() { 80 | // TODO Auto-generated method stub 81 | return iiouRecordDao.queryAllIouRecord(); 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /src/com/formssi/service/impl/TransactionServiceImpl.java: -------------------------------------------------------------------------------- 1 | package com.formssi.service.impl; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import java.util.concurrent.ExecutionException; 6 | 7 | import org.springframework.beans.factory.annotation.Autowired; 8 | import org.springframework.stereotype.Service; 9 | 10 | import com.formssi.dao.IIouLimitEntityDao; 11 | import com.formssi.dao.IIouRecordDao; 12 | import com.formssi.dao.ITransactionDao; 13 | import com.formssi.entity.IouLimitEntity; 14 | import com.formssi.entity.IouRecord; 15 | import com.formssi.entity.Transaction; 16 | import com.formssi.service.ITransactionService; 17 | 18 | import utils.Utils; 19 | 20 | 21 | @Service 22 | public class TransactionServiceImpl implements ITransactionService { 23 | @Autowired(required=false) 24 | private ITransactionDao itransactionDao; 25 | @Autowired(required=false) 26 | private IIouLimitEntityDao iiouLimitEntityDao; 27 | @Autowired(required=false) 28 | private IIouRecordDao iiouRecordDao; 29 | 30 | 31 | @Override 32 | public boolean addTransactionRecord(String saleOrg,String buyOrg,String transType,long amount,String latestStatus,String conID,String conHash)throws InterruptedException, ExecutionException{ // 录入交易 33 | // TODO Auto-generated method stub 34 | 35 | long now=System.currentTimeMillis(); 36 | String transTime = Utils.sdf(now); 37 | // String conID="conID"+transTime; // 合同号 38 | // String conHash="conHash"; 39 | Transaction transaction = new Transaction(); 40 | transaction.setConID(conID); 41 | transaction.setSaleOrg(saleOrg); 42 | transaction.setBuyOrg(buyOrg); 43 | transaction.setTransType(transType); 44 | transaction.setConID(conID); 45 | transaction.setConHash(conHash); 46 | transaction.setAmount(amount); 47 | transaction.setLatestStatus(latestStatus); 48 | transaction.setConHash(conHash); 49 | transaction.setTransTime(transTime); 50 | transaction.setUpdateTime(transTime); 51 | 52 | if(transaction.getAmount()<= 0) { 53 | // 确保数据的合理性 54 | System.out.println("白条金额不可小于0"); 55 | return false; 56 | } 57 | IouLimitEntity tmpBuy = iiouLimitEntityDao.queryIouLimitEntityByOrgID(transaction.getBuyOrg()); 58 | IouLimitEntity tmpSale = iiouLimitEntityDao.queryIouLimitEntityByOrgID(transaction.getSaleOrg()); 59 | if(tmpBuy==null||tmpSale==null) { 60 | //不存在该机构 61 | System.out.println("机构不存在"); 62 | return false; 63 | }else { 64 | itransactionDao.addTransaction(transaction); 65 | System.out.println("创建交易"); 66 | 67 | 68 | IOUService.addTransaction(saleOrg, buyOrg, transType, amount, latestStatus,conID,conHash); 69 | 70 | IouRecord iouRecord =new IouRecord(); 71 | iouRecord.setAmount((int)amount); 72 | iouRecord.setIouId(conID); 73 | iouRecord.setFromOrg(buyOrg); 74 | iouRecord.setRecvOrg(saleOrg); 75 | iouRecord.setTransTime(transTime); 76 | iouRecord.setPaidAmt(0); 77 | iouRecord.setIouStatus("P"); 78 | iouRecord.setUpdateTime(transTime); 79 | 80 | 81 | 82 | iiouRecordDao.addIouRecord(iouRecord); 83 | 84 | IouLimitEntity iouLimitEntity=iiouLimitEntityDao.queryIouLimitEntityByOrgID(buyOrg);//queryEntityByOrgName(buyOrg); 85 | if(iouLimitEntity != null) { 86 | 87 | int tem = (int) (iouLimitEntity.getIouLimit()-amount); 88 | 89 | iiouLimitEntityDao.updateIouLimitByOrgID(tem, transTime, buyOrg); 90 | } 91 | else { 92 | return false; 93 | } 94 | return true; 95 | } 96 | } 97 | 98 | @Override 99 | public boolean updateTransactionStatusByConId(String conId,String status) { 100 | // TODO Auto-generated method stub 101 | Transaction tmp = itransactionDao.getTransactionByConID(conId); 102 | if(tmp==null) { 103 | //不存在该机构 104 | System.out.println("交易不存在"); 105 | return false; 106 | }else { 107 | tmp.setLatestStatus(status); 108 | long now=System.currentTimeMillis(); 109 | String updateTime = Utils.sdf(now); 110 | tmp.setUpdateTime(updateTime); 111 | itransactionDao.updateTransactionStatusByConID(conId, status, updateTime); 112 | try { 113 | IOUService.updateTransStatus(conId, status); 114 | } catch (InterruptedException e) { 115 | // TODO Auto-generated catch block 116 | e.printStackTrace(); 117 | } catch (ExecutionException e) { 118 | // TODO Auto-generated catch block 119 | e.printStackTrace(); 120 | } 121 | 122 | return true; 123 | } 124 | } 125 | 126 | @Override 127 | public Transaction getTransactionByConId(String conId) { 128 | // TODO Auto-generated method stub 129 | Transaction tmp = itransactionDao.getTransactionByConID(conId); 130 | if(tmp==null) { 131 | System.out.println("不存在该交易"); 132 | return null; 133 | } 134 | return tmp; 135 | } 136 | 137 | @Override 138 | public List getAllTransaction() { 139 | // TODO Auto-generated method stub 140 | return itransactionDao.getAllTransaction(); 141 | } 142 | 143 | @Override 144 | public List queryTransaction(int pageNo, int pageSize) { 145 | // TODO Auto-generated method stub 146 | pageNo--; 147 | List allTransaction = itransactionDao.getAllTransaction(); 148 | // System.out.println("读取所有transaction..."); 149 | List result = new ArrayList<>(); 150 | for(int i=pageNo*pageSize;i TRAN_LATESTSTATE_LIST= Arrays.asList("U","C"); 14 | public static void main(String[] args) throws Exception{ 15 | 16 | 17 | 18 | String basePath=Thread.currentThread().getContextClassLoader().getResource("").getPath()+"files/keys/";//获取要写入的文件路径 19 | System.out.println("basePath==>"+basePath); 20 | File file=new File(basePath); 21 | if(!file.exists() && !file.isDirectory()) { 22 | file.mkdirs(); 23 | } 24 | String pubKeyFileName=basePath+"430224196501014127"+"PUBKEY"; 25 | String priKeyFileName=basePath+"430224196501014127"+"PRIKEY"; 26 | System.out.println("pubKeyFileName==>"+pubKeyFileName); 27 | Map keyMap=RSAUtils.genKeyPair(); 28 | 29 | System.out.println(RSAUtils.getPublicKey(keyMap)); 30 | 31 | RSAUtils.keyFiles(keyMap,pubKeyFileName,priKeyFileName); 32 | String PUBKEY=Utils.fileRead(pubKeyFileName); 33 | System.out.println(PUBKEY); 34 | 35 | String message="my"; 36 | byte[] encryMessage=RSAUtils.encryptByPublicKey(message.getBytes(),PUBKEY); 37 | 38 | 39 | 40 | 41 | 42 | // String sss=new String(Base64.getEncoder().encode(encryMessage)); 43 | String sss=new String(encryMessage); 44 | System.out.println(encryMessage); 45 | 46 | String privateKey = Utils.fileRead(priKeyFileName); 47 | 48 | System.out.println(RSAUtils.getPrivateKey(keyMap)); 49 | // String resultMessage=new String(RSAUtils.decryptByPrivateKey(Base64.getDecoder().decode(sss.getBytes()), privateKey)); 50 | String resultMessage=new String(RSAUtils.decryptByPrivateKey(sss.getBytes(), privateKey)); 51 | 52 | System.out.println(resultMessage); 53 | 54 | 55 | 56 | // String path=Thread.currentThread().getContextClassLoader().getResource("").getPath()+"\\files\\";//获取要写入的文件路径 57 | // String path1=Thread.currentThread().getContextClassLoader().getResource("").getPath()+"\\files\\";//获取要写入的文件路径 58 | // System.out.println(path); 59 | // RSAUtils.keyFiles(RSAUtils.genKeyPair(),path,path1); 60 | 61 | 62 | // FileShareService.initObj(); 63 | // 64 | // User user = new User(); 65 | // user.setUserId("430224196501014127"); 66 | // user.setUserName("test"); 67 | // user.setPassword("123"); 68 | // user.setPubKey("this is a test"); 69 | // user.setRank(6); 70 | // user.setDepartment(3); 71 | // user.setCreateTime("2018-05-04 14:46:33"); 72 | // user.setUpdateTime("2018-05-04 14:46:33"); 73 | // System.out.println(FileShareService.addUser(user)); 74 | 75 | 76 | // ShareFile sFile=new ShareFile(); 77 | // sFile.setFileId("thisIsthefileId"); 78 | // sFile.setFileAddr("addr1"); 79 | // sFile.setPubKeyToSymkey("test"); 80 | // sFile.setAllowRank(10); 81 | // sFile.setAllowDep("1,2,3,4"); 82 | // sFile.setDescription("this is a description"); 83 | // sFile.setUploadTime(new Timestamp(System.currentTimeMillis())); 84 | // sFile.setUserId("430224196501014127"); 85 | // sFile.setDepartment(4); 86 | // System.out.println(FileShareService.UploadFile(sFile)); 87 | 88 | 89 | 90 | 91 | 92 | 93 | // FileReq fReq=new FileReq(); 94 | // fReq.setUserId("430224196501014127"); 95 | // StringBuffer reqId=new StringBuffer("REQ"); 96 | // reqId.append(fReq.getUserId()+System.currentTimeMillis()); 97 | // fReq.setRequestId(reqId.toString()); 98 | // fReq.setFileId("thisIsthefileId"); 99 | // fReq.setRequestTime(Utils.getCurrentDate()); 100 | // System.out.println(fReq.toString()); 101 | // System.out.println(FileShareService.RequestFile(fReq)); 102 | 103 | 104 | // ShareFile sFile=new ShareFile(); 105 | // sFile.setUserId("430224196501014126"); 106 | // sFile.setAllowRank(1); 107 | // sFile.setAllowDep("2,3,4,5"); 108 | // 109 | // FileShareService.UploadFile(sFile); 110 | 111 | 112 | 113 | 114 | 115 | // FileShareService.queryBlockNumber(); 116 | 117 | 118 | // User user = new User(); 119 | // user.setUserId("430224196501014126"); 120 | // user.setUserName("邓杰瑞"); 121 | // user.setPassword("123"); 122 | // user.setPubKey("this is a test"); 123 | // user.setRank(5); 124 | // user.setDepartment(3); 125 | // user.setCreateTime("2018-05-04 06:45:58"); 126 | // user.setUpdateTime("2018-05-04 06:45:58"); 127 | // System.out.println(FileShareService.addUser(user)); 128 | 129 | 130 | 131 | // Map keymap=utils.RSAUtils.genKeyPair(); 132 | 133 | // String path = Thread.currentThread().getContextClassLoader().getResource("").toString(); 134 | // String subPath = path.substring(5, path.length()); 135 | // System.out.println(path+" | "+subPath); 136 | 137 | // IOUService.init(); 138 | // Transaction transaction = new Transaction(); 139 | // transaction.setConID("12354");//从12345开始 140 | // transaction.setSaleOrg("org005"); 141 | // transaction.setBuyOrg("org006"); 142 | // transaction.setTransType("XX"); 143 | // transaction.setAmount(new BigInteger("10")); 144 | // transaction.setConHash("0x483e58985e9a80a215944fdaabe8sdfge23g3df8ba90741f"); 145 | // transaction.setLatestStatus("A"); 146 | // transaction.setTransTime(Utils.getCurrentDate()); 147 | // transaction.setUpdateTime(Utils.getCurrentDate()); 148 | // System.out.println(IOUService.addTransaction(transaction)); 149 | 150 | // IOUService.init(); 151 | // IOU iou=new IOU(); 152 | // iou.setIouId("12345"); 153 | // iou.setIouStatus("P"); 154 | // System.out.println(IOUService.updateTrans(iou)); 155 | 156 | // IOUService.init(); 157 | // Organ org=new Organ(); 158 | // org.setOrgID("org006"); 159 | // org.setOrgName("TestFactory1"); 160 | // org.setIouLimit(new BigInteger("1000001")); 161 | // org.setCreateTime(Utils.getCurrentDate()); 162 | // org.setUpdateTime(""); 163 | // IOUService.initIouLimitData(org); 164 | 165 | // IOUService.init(); 166 | // System.out.println(IOUService.queryTransByConId("12345")); 167 | // 168 | // IOUService.init(); 169 | // IOU iou=new IOU(); 170 | // iou.setFromOrg("org006"); 171 | // System.out.println(IOUService.getIouLimit(iou)); 172 | 173 | 174 | // IOUService.init(); 175 | // Transaction tran=new Transaction(); 176 | // tran.setConID("12346"); 177 | // tran.setLatestStatus("U"); 178 | // System.out.println(IOUService.updateTransStatus(tran)); 179 | 180 | // IOUService.init(); 181 | // Organ organ=new Organ(); 182 | // organ.setOrgID("org005"); 183 | // organ.setIouLimit(new BigInteger("1000001")); 184 | // System.out.println(IOUService.setIouLimit(organ)); 185 | 186 | // IOUService.init(); 187 | // String iouListString=IOUService.getIouList(2, 2); 188 | // JSONArray jsonArray=JSON.parseArray(iouListString); 189 | // for (Object object : jsonArray) { 190 | // IOU iou = (IOU) JSON.parseObject(object.toString(), IOU.class); 191 | // System.out.println(iou.toString()); 192 | // } 193 | 194 | // IOUService.init(); 195 | // String tranListString=IOUService.queryTransList(0, 10); 196 | // JSONArray jsonArray=JSON.parseArray(tranListString); 197 | // for (Object object : jsonArray) { 198 | // Transaction tran = (Transaction) JSON.parseObject(object.toString(), Transaction.class); 199 | // System.out.println(tran.toString()); 200 | // } 201 | 202 | 203 | // IOUService.init(); 204 | // IOU iou = new IOU(); 205 | // iou.setIouId("12347"); 206 | // iou.setFromOrg("org006"); 207 | // iou.setAmount(new BigInteger("5")); 208 | // IOUService.getIouLimit(iou); 209 | // System.out.println(IOUService.iouRecycle(iou)); 210 | // IOUService.getIouLimit(iou); 211 | 212 | // String filename="./src/files/getContractAddress.js"; 213 | // String string="./src/files/getContractAddress111.js"; 214 | // System.out.println(Utils.getFileSHA256Str(string)); 215 | // String path=Thread.currentThread().getContextClassLoader().getResource("").getPath(); 216 | // System.out.println(path); 217 | 218 | // File fileInput=new File("./src/files/mysql.user.txt"); 219 | // BufferedInputStream in = new BufferedInputStream(new FileInputStream(fileInput)); 220 | // String path=Thread.currentThread().getContextClassLoader().getResource("").getPath()+"files/mysql.txt"; 221 | 222 | // String path="C:\\User\\mysql.txt"; 223 | // System.out.println(path); 224 | // File file=new File("./src/files/mysql.txt"); 225 | // file.createNewFile(); 226 | // BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file)); 227 | // byte[] b = new byte[1024*8]; 228 | // int len; 229 | // while((len = in.read(b)) != -1){ 230 | // out.write(b, 0, len); 231 | // } 232 | // out.flush(); 233 | // 234 | // System.out.println("yes"); 235 | 236 | 237 | // Transaction transaction=new Transaction(); 238 | // transaction.setTransType("C"); 239 | // System.out.println(transaction.getTransType()); 240 | // 241 | // if(!TRAN_LATESTSTATE_LIST.contains(transaction.getLatestStatus())) { 242 | // System.out.println("the value of IOU Status must be C or U."); 243 | // } 244 | // 245 | // System.out.println(TRAN_LATESTSTATE_LIST.contains(transaction.getTransType())); 246 | 247 | 248 | } 249 | 250 | } 251 | -------------------------------------------------------------------------------- /src/utils/Base64Utils.java: -------------------------------------------------------------------------------- 1 | package utils; 2 | 3 | import java.io.ByteArrayInputStream; 4 | import java.io.ByteArrayOutputStream; 5 | import java.io.File; 6 | import java.io.FileInputStream; 7 | import java.io.FileOutputStream; 8 | import java.io.InputStream; 9 | import java.io.OutputStream; 10 | 11 | import it.sauronsoftware.base64.Base64; 12 | 13 | 14 | /** 15 | *

16 | * BASE64编码解码工具包 17 | *

18 | *

19 | * 依赖javabase64-1.3.1.jar 20 | *

21 | * 22 | * @author IceWee 23 | * @date 2012-5-19 24 | * @version 1.0 25 | */ 26 | public class Base64Utils { 27 | 28 | /** 29 | * 文件读取缓冲区大小 30 | */ 31 | private static final int CACHE_SIZE = 1024; 32 | 33 | /** 34 | *

35 | * BASE64字符串解码为二进制数据 36 | *

37 | * 38 | * @param base64 39 | * @return 40 | * @throws Exception 41 | */ 42 | public static byte[] decode(String base64) throws Exception { 43 | return Base64.decode(base64.getBytes()); 44 | } 45 | 46 | /** 47 | *

48 | * 二进制数据编码为BASE64字符串 49 | *

50 | * 51 | * @param bytes 52 | * @return 53 | * @throws Exception 54 | */ 55 | public static String encode(byte[] bytes) throws Exception { 56 | return new String(Base64.encode(bytes)); 57 | } 58 | 59 | /** 60 | *

61 | * 将文件编码为BASE64字符串 62 | *

63 | *

64 | * 大文件慎用,可能会导致内存溢出 65 | *

66 | * 67 | * @param filePath 68 | * 文件绝对路径 69 | * @return 70 | * @throws Exception 71 | */ 72 | public static String encodeFile(String filePath) throws Exception { 73 | byte[] bytes = fileToByte(filePath); 74 | return encode(bytes); 75 | } 76 | 77 | /** 78 | *

79 | * BASE64字符串转回文件 80 | *

81 | * 82 | * @param filePath 83 | * 文件绝对路径 84 | * @param base64 85 | * 编码字符串 86 | * @throws Exception 87 | */ 88 | public static void decodeToFile(String filePath, String base64) throws Exception { 89 | byte[] bytes = decode(base64); 90 | byteArrayToFile(bytes, filePath); 91 | } 92 | 93 | /** 94 | *

95 | * 文件转换为二进制数组 96 | *

97 | * 98 | * @param filePath 99 | * 文件路径 100 | * @return 101 | * @throws Exception 102 | */ 103 | public static byte[] fileToByte(String filePath) throws Exception { 104 | byte[] data = new byte[0]; 105 | File file = new File(filePath); 106 | if (file.exists()) { 107 | FileInputStream in = new FileInputStream(file); 108 | ByteArrayOutputStream out = new ByteArrayOutputStream(2048); 109 | byte[] cache = new byte[CACHE_SIZE]; 110 | int nRead = 0; 111 | while ((nRead = in.read(cache)) != -1) { 112 | out.write(cache, 0, nRead); 113 | out.flush(); 114 | } 115 | out.close(); 116 | in.close(); 117 | data = out.toByteArray(); 118 | } 119 | return data; 120 | } 121 | 122 | /** 123 | *

124 | * 二进制数据写文件 125 | *

126 | * 127 | * @param bytes 128 | * 二进制数据 129 | * @param filePath 130 | * 文件生成目录 131 | */ 132 | public static void byteArrayToFile(byte[] bytes, String filePath) throws Exception { 133 | InputStream in = new ByteArrayInputStream(bytes); 134 | File destFile = new File(filePath); 135 | if (!destFile.getParentFile().exists()) { 136 | destFile.getParentFile().mkdirs(); 137 | } 138 | destFile.createNewFile(); 139 | OutputStream out = new FileOutputStream(destFile); 140 | byte[] cache = new byte[CACHE_SIZE]; 141 | int nRead = 0; 142 | while ((nRead = in.read(cache)) != -1) { 143 | out.write(cache, 0, nRead); 144 | out.flush(); 145 | } 146 | out.close(); 147 | in.close(); 148 | } 149 | 150 | } -------------------------------------------------------------------------------- /src/utils/DowloadFileUtil.java: -------------------------------------------------------------------------------- 1 | package utils; 2 | 3 | import java.io.BufferedInputStream; 4 | import java.io.File; 5 | import java.io.FileInputStream; 6 | import java.io.FileOutputStream; 7 | import java.io.OutputStream; 8 | import java.net.URL; 9 | import java.net.URLConnection; 10 | 11 | import javax.servlet.http.HttpServletRequest; 12 | import javax.servlet.http.HttpServletResponse; 13 | 14 | public class DowloadFileUtil { 15 | 16 | public static void _downLoad(String filePath, HttpServletRequest request, HttpServletResponse response, boolean isOnLine) throws Exception { 17 | BufferedInputStream br = null; 18 | OutputStream out = null; 19 | try { 20 | File f = new File(filePath); 21 | System.out.println("filePath: " + filePath); 22 | if (!f.exists()) { 23 | System.out.println("File not found!"); 24 | response.sendError(404, "File not found!"); 25 | return; 26 | } 27 | br = new BufferedInputStream(new FileInputStream(f)); 28 | byte[] buf = new byte[1024]; 29 | int len = 0; 30 | 31 | String userAgent = request.getHeader("User-Agent"); 32 | String fileName = null; 33 | 34 | // 针对IE或者以IE为内核的浏览器: 35 | if (userAgent.contains("MSIE") || userAgent.contains("Trident")) { 36 | fileName = java.net.URLEncoder.encode(f.getName(), "UTF-8"); 37 | } else { 38 | // 非IE浏览器的处理: 39 | fileName = new String(f.getName().getBytes("UTF-8"), "ISO-8859-1"); 40 | } 41 | 42 | response.reset(); // 非常重要 43 | if (isOnLine) { // 在线打开方式 44 | URL u = new URL("file:///" + filePath); 45 | response.setContentType(u.openConnection().getContentType()); 46 | response.setHeader("Content-Disposition", "inline; filename=" + fileName); 47 | // 文件名应该编码成UTF-8 48 | } else { // 纯下载方式 49 | response.setContentType("application/x-msdownload"); 50 | response.setHeader("Content-Disposition", "attachment; filename=" + fileName); 51 | } 52 | out = response.getOutputStream(); 53 | while ((len = br.read(buf)) > 0) 54 | out.write(buf, 0, len); 55 | }catch(Exception e) { 56 | e.printStackTrace(); 57 | }finally { 58 | if(br != null) { 59 | br.close(); 60 | } 61 | if(out != null) { 62 | out.close(); 63 | } 64 | } 65 | 66 | } 67 | 68 | public static void downloadNet(HttpServletRequest request, HttpServletResponse response, String fileUrl) throws Exception { 69 | // 下载网络文件 70 | int bytesum = 0; 71 | int byteread = 0; 72 | BufferedInputStream br = null; 73 | OutputStream out = null; 74 | 75 | try { 76 | String fName = fileUrl.substring(fileUrl.lastIndexOf("/")+1); 77 | String userAgent = request.getHeader("User-Agent"); 78 | String fileName = null; 79 | // 针对IE或者以IE为内核的浏览器: 80 | if (userAgent.contains("MSIE") || userAgent.contains("Trident")) { 81 | fileName = java.net.URLEncoder.encode(fName, "UTF-8"); 82 | } else { 83 | // 非IE浏览器的处理: 84 | fileName = new String(fName.getBytes("UTF-8"), "ISO-8859-1"); 85 | } 86 | 87 | response.reset(); // 非常重要 88 | response.setContentType("application/x-msdownload"); 89 | response.setHeader("Content-Disposition", "attachment; filename=" + fileName); 90 | 91 | URL url = new URL(fileUrl); 92 | URLConnection conn = url.openConnection(); 93 | br = new BufferedInputStream(conn.getInputStream()); 94 | out = response.getOutputStream(); 95 | 96 | byte[] buffer = new byte[1204]; 97 | while ((byteread = br.read(buffer)) != -1) { 98 | bytesum += byteread; 99 | System.out.println(bytesum); 100 | out.write(buffer, 0, byteread); 101 | } 102 | } catch (Exception e) { 103 | e.printStackTrace(); 104 | } finally { 105 | if(br != null) { 106 | br.close(); 107 | } 108 | if(out != null) { 109 | out.close(); 110 | } 111 | } 112 | } 113 | 114 | public static void downLoad(String filePath) throws Exception { 115 | BufferedInputStream br = null; 116 | OutputStream out = null; 117 | try { 118 | File f = new File(filePath); 119 | if (!f.exists()) { 120 | System.out.println("File not found!"); 121 | return; 122 | } 123 | br = new BufferedInputStream(new FileInputStream(f)); 124 | byte[] buf = new byte[1024]; 125 | int len = 0; 126 | int start = filePath.lastIndexOf("/"); 127 | String fileName = filePath.substring(start); 128 | System.out.println("--------"+fileName); 129 | File FILE_FOR_WRITE = new File("D:/RSE/publickey/"+fileName); 130 | out = new FileOutputStream(FILE_FOR_WRITE); 131 | while ((len = br.read(buf)) > 0) 132 | out.write(buf, 0, len); 133 | }catch(Exception e) { 134 | e.printStackTrace(); 135 | }finally { 136 | if(br != null) { 137 | br.close(); 138 | } 139 | if(out != null) { 140 | out.close(); 141 | } 142 | System.out.println("文件下载成功"); 143 | } 144 | 145 | } 146 | 147 | } 148 | -------------------------------------------------------------------------------- /src/utils/MD5Util.java: -------------------------------------------------------------------------------- 1 | package utils; 2 | 3 | import java.security.MessageDigest; 4 | 5 | public class MD5Util { 6 | 7 | public static void main(String[] args) { 8 | System.out.println(MD5Encode("aaa","UTF-8")); 9 | } 10 | 11 | private static String byteArrayToHexString(byte b[]) { 12 | StringBuffer resultSb = new StringBuffer(); 13 | for (int i = 0; i < b.length; i++) 14 | resultSb.append(byteToHexString(b[i])); 15 | 16 | return resultSb.toString(); 17 | } 18 | 19 | private static String byteToHexString(byte b) { 20 | int n = b; 21 | if (n < 0) 22 | n += 256; 23 | int d1 = n / 16; 24 | int d2 = n % 16; 25 | return hexDigits[d1] + hexDigits[d2]; 26 | } 27 | 28 | public static String MD5Encode(String origin, String charsetname) { 29 | String resultString = null; 30 | try { 31 | resultString = new String(origin); 32 | MessageDigest md = MessageDigest.getInstance("MD5"); 33 | if (charsetname == null || "".equals(charsetname)) 34 | resultString = byteArrayToHexString(md.digest(resultString 35 | .getBytes())); 36 | else 37 | resultString = byteArrayToHexString(md.digest(resultString 38 | .getBytes(charsetname))); 39 | } catch (Exception exception) { 40 | } 41 | return resultString; 42 | } 43 | 44 | private static final String hexDigits[] = { "0", "1", "2", "3", "4", "5", 45 | "6", "7", "8", "9", "a", "b", "c", "d", "e", "f" }; 46 | } 47 | -------------------------------------------------------------------------------- /src/utils/MoveFile.java: -------------------------------------------------------------------------------- 1 | package utils; 2 | 3 | import java.io.File; 4 | 5 | public class MoveFile { 6 | public static boolean removeFile(String fileName,String destinationFloderUrl,String destFileName) 7 | { 8 | File file = new File(fileName); 9 | File destFloder = new File(destinationFloderUrl); 10 | //检查目标路径是否合法 11 | if(destFloder.exists()) 12 | { 13 | if(destFloder.isFile()) 14 | { 15 | System.out.println("目标路径是个文件,请检查目标路径!"); 16 | return false; 17 | } 18 | }else 19 | { 20 | if(!destFloder.mkdirs()) 21 | { 22 | System.out.println("目标文件夹不存在,创建失败!"); 23 | return false; 24 | } 25 | } 26 | //检查源文件是否合法 27 | if(file.isFile() &&file.exists()) 28 | { 29 | // long now=System.currentTimeMillis(); 30 | // String time = Utils.sdf(now); 31 | String destinationFile = destinationFloderUrl+destFileName; 32 | if(!file.renameTo(new File(destinationFile))) 33 | { 34 | System.out.println("移动文件失败!"); 35 | return false; 36 | } 37 | }else 38 | { 39 | System.out.println("要备份的文件路径不正确,移动失败!"); 40 | return false; 41 | } 42 | System.out.println("已成功移动文件"+file.getName()+"到"+destinationFloderUrl); 43 | return true; 44 | } 45 | 46 | public static void main(String[] argv) { 47 | String basePath = "/home/user0308/Tmp/tmp/"; 48 | String destPath = basePath + "contract/"; 49 | String sourceFilePath = basePath + "/orgA/" + "temContract"; 50 | 51 | removeFile(sourceFilePath,destPath,"new_file"); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/utils/MySessionContext.java: -------------------------------------------------------------------------------- 1 | package utils; 2 | 3 | import java.util.HashMap; 4 | 5 | import javax.servlet.http.HttpSession; 6 | 7 | public class MySessionContext { 8 | private static HashMap mymap = new HashMap(); 9 | 10 | public static synchronized void AddSession(HttpSession session) { 11 | if (session != null) { 12 | mymap.put(session.getId(), session); 13 | } 14 | } 15 | 16 | public static synchronized void DelSession(HttpSession session) { 17 | if (session != null) { 18 | mymap.remove(session.getId()); 19 | } 20 | } 21 | 22 | public static synchronized HttpSession getSession(String session_id) { 23 | if (session_id == null) 24 | return null; 25 | return (HttpSession) mymap.get(session_id); 26 | } 27 | } -------------------------------------------------------------------------------- /src/utils/MySessionListener.java: -------------------------------------------------------------------------------- 1 | package utils; 2 | 3 | import javax.servlet.http.HttpSession; 4 | import javax.servlet.http.HttpSessionEvent; 5 | import javax.servlet.http.HttpSessionListener; 6 | 7 | public class MySessionListener implements HttpSessionListener { 8 | public void sessionCreated(HttpSessionEvent httpSessionEvent) { 9 | MySessionContext.AddSession(httpSessionEvent.getSession()); 10 | } 11 | 12 | public void sessionDestroyed(HttpSessionEvent httpSessionEvent) { 13 | HttpSession session = httpSessionEvent.getSession(); 14 | MySessionContext.DelSession(session); 15 | } 16 | 17 | } -------------------------------------------------------------------------------- /src/utils/PropertiesUtil.java: -------------------------------------------------------------------------------- 1 | package utils; 2 | 3 | import java.io.FileNotFoundException; 4 | import java.io.FileOutputStream; 5 | import java.io.IOException; 6 | import java.io.InputStream; 7 | import java.io.OutputStream; 8 | import java.util.ArrayList; 9 | import java.util.Enumeration; 10 | import java.util.HashMap; 11 | import java.util.Map; 12 | import java.util.Properties; 13 | 14 | public class PropertiesUtil { 15 | 16 | 17 | /** 18 | * 配置文件对象 19 | */ 20 | private static Properties props=new Properties(); 21 | 22 | /** 23 | * 默认构造函数,用于sh运行,自动找到classpath下的config.properties。 24 | */ 25 | 26 | public PropertiesUtil(){ 27 | 28 | } 29 | 30 | public static void readFile(String path) throws IOException{ 31 | /*String classPath = Thread.currentThread().getContextClassLoader().getResource("").toString(); 32 | String subClassPath = classPath.substring(5, path.length()); 33 | String os = System.getProperty("os.name"); 34 | if(os.toLowerCase().startsWith("win")){ 35 | } 36 | else { 37 | }*/ 38 | InputStream in = PropertiesUtil.class.getClassLoader().getResourceAsStream(path); 39 | // props = new Properties(); 40 | props.load(in); 41 | //关闭资源 42 | in.close(); 43 | } 44 | 45 | /** 46 | * 根据key值读取配置的值 47 | * @param key key值 48 | * @return key 键对应的值 49 | * @throws IOException 50 | */ 51 | public static String readValue(String key) throws IOException { 52 | 53 | return props.getProperty(key); 54 | } 55 | 56 | 57 | 58 | /** 59 | * 根据key值,value值写入配置 60 | * @param key key值; value value值 61 | * @return void 62 | * @throws IOException 63 | */ 64 | public static void writeValue(String key, String value, String path) throws IOException { 65 | 66 | Properties writeProps = new Properties(); 67 | writeProps.setProperty(key, value); 68 | FileOutputStream out = new FileOutputStream(path); 69 | writeProps.store(out, null); 70 | //关闭资源 71 | out.close(); 72 | } 73 | 74 | public static void writeValues(ArrayList arrayList, String path) throws IOException { 75 | 76 | Properties writeProps = new Properties(); 77 | for(String string[]: arrayList){ 78 | writeProps.setProperty(string[0], string[1]); 79 | } 80 | FileOutputStream out = new FileOutputStream(path); 81 | writeProps.store(out, null); 82 | //关闭资源 83 | out.close(); 84 | } 85 | 86 | public static void setContractAdress(int i, String value){ 87 | 88 | props.setProperty("contract.address."+i, value); 89 | } 90 | 91 | public static void setProperty(String key, String value){ 92 | 93 | props.setProperty(key, value); 94 | } 95 | 96 | 97 | public static void store(String path) throws IOException{ 98 | 99 | OutputStream out = new FileOutputStream(PropertiesUtil.class.getResource(path).getFile()); 100 | props.store(out, null); 101 | //关闭资源 102 | out.close(); 103 | } 104 | 105 | /** 106 | * 读取properties的全部信息 107 | * @throws FileNotFoundException 配置文件没有找到 108 | * @throws IOException 关闭资源文件,或者加载配置文件错误 109 | * 110 | */ 111 | @SuppressWarnings("rawtypes") 112 | public Map readAllProperties() throws FileNotFoundException,IOException { 113 | //保存所有的键值 114 | Map map=new HashMap(); 115 | Enumeration en = props.propertyNames(); 116 | while (en.hasMoreElements()) { 117 | String key = (String) en.nextElement(); 118 | String Property = props.getProperty(key); 119 | map.put(key, Property); 120 | } 121 | return map; 122 | } 123 | 124 | } 125 | 126 | -------------------------------------------------------------------------------- /src/utils/RSAUtils.java: -------------------------------------------------------------------------------- 1 | package utils; 2 | 3 | import java.io.ByteArrayOutputStream; 4 | import java.io.FileWriter; 5 | import java.security.Key; 6 | import java.security.KeyFactory; 7 | import java.security.KeyPair; 8 | import java.security.KeyPairGenerator; 9 | import java.security.PrivateKey; 10 | import java.security.PublicKey; 11 | import java.security.Signature; 12 | import java.security.interfaces.RSAPrivateKey; 13 | import java.security.interfaces.RSAPublicKey; 14 | import java.security.spec.PKCS8EncodedKeySpec; 15 | import java.security.spec.X509EncodedKeySpec; 16 | import java.util.Base64; 17 | import java.util.HashMap; 18 | import java.util.Map; 19 | 20 | import javax.crypto.Cipher; 21 | 22 | /** 23 | *

24 | * RSA公钥/私钥/签名工具包 25 | *

26 | *

27 | * 罗纳德·李维斯特(Ron [R]ivest)、阿迪·萨莫尔(Adi [S]hamir)和伦纳德·阿德曼(Leonard [A]dleman) 28 | *

29 | *

30 | * 字符串格式的密钥在未在特殊说明情况下都为BASE64编码格式
31 | * 由于非对称加密速度极其缓慢,一般文件不使用它来加密而是使用对称加密,
32 | * 非对称加密算法可以用来对对称加密的密钥加密,这样保证密钥的安全也就保证了数据的安全 33 | *

34 | * 35 | * @author IceWee 36 | * @date 2012-4-26 37 | * @version 1.0 38 | */ 39 | public class RSAUtils { 40 | 41 | /** 42 | * 加密算法RSA 43 | */ 44 | public static final String KEY_ALGORITHM = "RSA"; 45 | 46 | /** 47 | * 签名算法 48 | */ 49 | public static final String SIGNATURE_ALGORITHM = "MD5withRSA"; 50 | 51 | /** 52 | * 获取公钥的key 53 | */ 54 | private static final String PUBLIC_KEY = "RSAPublicKey"; 55 | 56 | /** 57 | * 获取私钥的key 58 | */ 59 | private static final String PRIVATE_KEY = "RSAPrivateKey"; 60 | 61 | /** 62 | * RSA最大加密明文大小 63 | */ 64 | private static final int MAX_ENCRYPT_BLOCK = 117; 65 | 66 | /** 67 | * RSA最大解密密文大小 68 | */ 69 | private static final int MAX_DECRYPT_BLOCK = 128; 70 | 71 | /** 72 | *

73 | * 生成密钥对(公钥和私钥) 74 | *

75 | * 76 | * @return 77 | * @throws Exception 78 | */ 79 | public static Map genKeyPair() throws Exception { 80 | KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance(KEY_ALGORITHM); 81 | keyPairGen.initialize(1024); 82 | KeyPair keyPair = keyPairGen.generateKeyPair(); 83 | RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic(); 84 | RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate(); 85 | Map keyMap = new HashMap(2); 86 | keyMap.put(PUBLIC_KEY, publicKey); 87 | keyMap.put(PRIVATE_KEY, privateKey); 88 | return keyMap; 89 | } 90 | 91 | /** 92 | *

93 | * 用私钥对信息生成数字签名 94 | *

95 | * 96 | * @param data 已加密数据 97 | * @param privateKey 私钥(BASE64编码) 98 | * 99 | * @return 100 | * @throws Exception 101 | */ 102 | public static String sign(byte[] data, String privateKey) throws Exception { 103 | byte[] keyBytes = Base64Utils.decode(privateKey); 104 | PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(keyBytes); 105 | KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM); 106 | PrivateKey privateK = keyFactory.generatePrivate(pkcs8KeySpec); 107 | Signature signature = Signature.getInstance(SIGNATURE_ALGORITHM); 108 | signature.initSign(privateK); 109 | signature.update(data); 110 | return Base64Utils.encode(signature.sign()); 111 | } 112 | 113 | /** 114 | *

115 | * 校验数字签名 116 | *

117 | * 118 | * @param data 已加密数据 119 | * @param publicKey 公钥(BASE64编码) 120 | * @param sign 数字签名 121 | * 122 | * @return 123 | * @throws Exception 124 | * 125 | */ 126 | public static boolean verify(byte[] data, String publicKey, String sign) 127 | throws Exception { 128 | byte[] keyBytes = Base64Utils.decode(publicKey); 129 | X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes); 130 | KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM); 131 | PublicKey publicK = keyFactory.generatePublic(keySpec); 132 | Signature signature = Signature.getInstance(SIGNATURE_ALGORITHM); 133 | signature.initVerify(publicK); 134 | signature.update(data); 135 | return signature.verify(Base64Utils.decode(sign)); 136 | } 137 | 138 | /** 139 | *

140 | * 私钥解密 141 | *

142 | * 143 | * @param encryptedData 已加密数据 144 | * @param privateKey 私钥(BASE64编码) 145 | * @return 146 | * @throws Exception 147 | */ 148 | public static byte[] decryptByPrivateKey(byte[] encryptedData, String privateKey) 149 | throws Exception { 150 | encryptedData=Base64.getDecoder().decode(encryptedData); //字符串型密文转码成BASE64字符串 151 | byte[] keyBytes = Base64Utils.decode(privateKey); //BASE64-->二进制 152 | PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(keyBytes); 153 | KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM); 154 | Key privateK = keyFactory.generatePrivate(pkcs8KeySpec); 155 | Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm()); 156 | cipher.init(Cipher.DECRYPT_MODE, privateK); 157 | int inputLen = encryptedData.length; 158 | ByteArrayOutputStream out = new ByteArrayOutputStream(); 159 | int offSet = 0; 160 | byte[] cache; 161 | int i = 0; 162 | // 对数据分段解密 163 | while (inputLen - offSet > 0) { 164 | if (inputLen - offSet > MAX_DECRYPT_BLOCK) { 165 | cache = cipher.doFinal(encryptedData, offSet, MAX_DECRYPT_BLOCK); 166 | } else { 167 | cache = cipher.doFinal(encryptedData, offSet, inputLen - offSet); 168 | } 169 | out.write(cache, 0, cache.length); 170 | i++; 171 | offSet = i * MAX_DECRYPT_BLOCK; 172 | } 173 | byte[] decryptedData = out.toByteArray(); 174 | out.close(); 175 | return decryptedData; 176 | } 177 | 178 | /** 179 | *

180 | * 公钥解密 181 | *

182 | * 183 | * @param encryptedData 已加密数据 184 | * @param publicKey 公钥(BASE64编码) 185 | * @return 186 | * @throws Exception 187 | */ 188 | public static byte[] decryptByPublicKey(byte[] encryptedData, String publicKey) 189 | throws Exception { 190 | byte[] keyBytes = Base64Utils.decode(publicKey); 191 | X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(keyBytes); 192 | KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM); 193 | Key publicK = keyFactory.generatePublic(x509KeySpec); 194 | Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm()); 195 | cipher.init(Cipher.DECRYPT_MODE, publicK); 196 | int inputLen = encryptedData.length; 197 | ByteArrayOutputStream out = new ByteArrayOutputStream(); 198 | int offSet = 0; 199 | byte[] cache; 200 | int i = 0; 201 | // 对数据分段解密 202 | while (inputLen - offSet > 0) { 203 | if (inputLen - offSet > MAX_DECRYPT_BLOCK) { 204 | cache = cipher.doFinal(encryptedData, offSet, MAX_DECRYPT_BLOCK); 205 | } else { 206 | cache = cipher.doFinal(encryptedData, offSet, inputLen - offSet); 207 | } 208 | out.write(cache, 0, cache.length); 209 | i++; 210 | offSet = i * MAX_DECRYPT_BLOCK; 211 | } 212 | byte[] decryptedData = out.toByteArray(); 213 | out.close(); 214 | return decryptedData; 215 | } 216 | 217 | /** 218 | *

219 | * 公钥加密 220 | *

221 | * 222 | * @param data 源数据 223 | * @param publicKey 公钥(BASE64编码) 224 | * @return 225 | * @throws Exception 226 | */ 227 | public static byte[] encryptByPublicKey(byte[] data, String publicKey) 228 | throws Exception { 229 | byte[] keyBytes = Base64Utils.decode(publicKey); 230 | X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(keyBytes); 231 | KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM); 232 | Key publicK = keyFactory.generatePublic(x509KeySpec); 233 | // 对数据加密 234 | Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm()); 235 | cipher.init(Cipher.ENCRYPT_MODE, publicK); 236 | int inputLen = data.length; 237 | ByteArrayOutputStream out = new ByteArrayOutputStream(); 238 | int offSet = 0; 239 | byte[] cache; 240 | int i = 0; 241 | // 对数据分段加密 242 | while (inputLen - offSet > 0) { 243 | if (inputLen - offSet > MAX_ENCRYPT_BLOCK) { 244 | cache = cipher.doFinal(data, offSet, MAX_ENCRYPT_BLOCK); 245 | } else { 246 | cache = cipher.doFinal(data, offSet, inputLen - offSet); 247 | } 248 | out.write(cache, 0, cache.length); 249 | i++; 250 | offSet = i * MAX_ENCRYPT_BLOCK; 251 | } 252 | byte[] encryptedData = out.toByteArray(); 253 | out.close(); 254 | return Base64.getEncoder().encode(encryptedData); //密文转换成base64编码 255 | } 256 | 257 | /** 258 | *

259 | * 私钥加密 260 | *

261 | * 262 | * @param data 源数据 263 | * @param privateKey 私钥(BASE64编码) 264 | * @return 265 | * @throws Exception 266 | */ 267 | public static byte[] encryptByPrivateKey(byte[] data, String privateKey) 268 | throws Exception { 269 | byte[] keyBytes = Base64Utils.decode(privateKey); 270 | PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(keyBytes); 271 | KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM); 272 | Key privateK = keyFactory.generatePrivate(pkcs8KeySpec); 273 | Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm()); 274 | cipher.init(Cipher.ENCRYPT_MODE, privateK); 275 | int inputLen = data.length; 276 | ByteArrayOutputStream out = new ByteArrayOutputStream(); 277 | int offSet = 0; 278 | byte[] cache; 279 | int i = 0; 280 | // 对数据分段加密 281 | while (inputLen - offSet > 0) { 282 | if (inputLen - offSet > MAX_ENCRYPT_BLOCK) { 283 | cache = cipher.doFinal(data, offSet, MAX_ENCRYPT_BLOCK); 284 | } else { 285 | cache = cipher.doFinal(data, offSet, inputLen - offSet); 286 | } 287 | out.write(cache, 0, cache.length); 288 | i++; 289 | offSet = i * MAX_ENCRYPT_BLOCK; 290 | } 291 | byte[] encryptedData = out.toByteArray(); 292 | out.close(); 293 | return encryptedData; 294 | } 295 | 296 | /** 297 | *

298 | * 获取私钥 299 | *

300 | * 301 | * @param keyMap 密钥对 302 | * @return 303 | * @throws Exception 304 | */ 305 | public static String getPrivateKey(Map keyMap) 306 | throws Exception { 307 | Key key = (Key) keyMap.get(PRIVATE_KEY); 308 | return Base64Utils.encode(key.getEncoded()); 309 | } 310 | 311 | /** 312 | *

313 | * 获取公钥 314 | *

315 | * 316 | * @param keyMap 密钥对 317 | * @return 318 | * @throws Exception 319 | */ 320 | public static String getPublicKey(Map keyMap) 321 | throws Exception { 322 | Key key = (Key) keyMap.get(PUBLIC_KEY); 323 | return Base64Utils.encode(key.getEncoded()); 324 | } 325 | 326 | /** 327 | *

328 | * 公私钥对写入文件 329 | *

330 | * 331 | * @param keyMap 密钥对 pubKeyPath 公钥地址 priKeyPath 私钥地址 332 | * @return 333 | * @throws Exception 334 | * @author wangbin 335 | */ 336 | public static String keyFiles(Map keyMap, String pubKeyPath, String priKeyPath) 337 | throws Exception { 338 | String publicKey = getPublicKey(keyMap); 339 | String privateKey = getPrivateKey(keyMap); 340 | 341 | FileWriter pubfw = new FileWriter(pubKeyPath); 342 | pubfw.write(publicKey); 343 | pubfw.close(); 344 | 345 | FileWriter prifw = new FileWriter(priKeyPath); 346 | prifw.write(privateKey); 347 | prifw.close(); 348 | 349 | return "pubKeyPath:"+pubKeyPath+";priKeyPath:"+priKeyPath; 350 | } 351 | 352 | } -------------------------------------------------------------------------------- /src/utils/Token.java: -------------------------------------------------------------------------------- 1 | package utils; 2 | 3 | import java.security.MessageDigest; 4 | import java.security.NoSuchAlgorithmException; 5 | import java.util.UUID; 6 | 7 | public class Token{ 8 | 9 | public static void main(String[] args) { 10 | try { 11 | System.out.println(getToken()); 12 | } catch (Exception e) { 13 | // TODO Auto-generated catch block 14 | e.printStackTrace(); 15 | } 16 | } 17 | 18 | private static final char[] hexCode = "0123456789abcdef".toCharArray(); 19 | 20 | public static String getToken() throws Exception{ 21 | return generateValue(UUID.randomUUID().toString()); 22 | } 23 | 24 | public static String toHexString(byte[] data){ 25 | if (data == null) { 26 | return null; 27 | } 28 | StringBuilder r = new StringBuilder(data.length * 2); 29 | byte[] arrayOfByte = data; int j = data.length; for (int i = 0; i < j; i++) { byte b = arrayOfByte[i]; 30 | r.append(hexCode[(b >> 4 & 0xF)]); 31 | r.append(hexCode[(b & 0xF)]); 32 | } 33 | return r.toString(); 34 | } 35 | 36 | public static String generateValue(String param) throws Exception { 37 | try { 38 | MessageDigest algorithm; 39 | algorithm = MessageDigest.getInstance("MD5"); 40 | algorithm.reset(); 41 | algorithm.update(param.getBytes()); 42 | byte[] messageDigest = algorithm.digest(); 43 | return toHexString(messageDigest); 44 | 45 | } catch (NoSuchAlgorithmException e) { 46 | throw new Exception("generateValue error"); 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /src/utils/Utils.java: -------------------------------------------------------------------------------- 1 | package utils; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.File; 5 | import java.io.FileInputStream; 6 | import java.io.FileReader; 7 | import java.io.IOException; 8 | import java.io.UnsupportedEncodingException; 9 | import java.security.MessageDigest; 10 | import java.security.NoSuchAlgorithmException; 11 | import java.text.SimpleDateFormat; 12 | import java.util.Collection; 13 | import java.util.Date; 14 | import java.util.Map; 15 | 16 | import org.apache.commons.codec.binary.Hex; 17 | 18 | public class Utils { 19 | //获取字符串SHA256值 20 | public static String getSHA256Str(String str){ 21 | MessageDigest messageDigest; 22 | String encdeStr = ""; 23 | try { 24 | messageDigest = MessageDigest.getInstance("SHA-256"); 25 | byte[] hash = messageDigest.digest(str.getBytes("UTF-8")); 26 | encdeStr = Hex.encodeHexString(hash); 27 | } catch (NoSuchAlgorithmException e) { 28 | e.printStackTrace(); 29 | } catch (UnsupportedEncodingException e) { 30 | e.printStackTrace(); 31 | } 32 | return encdeStr; 33 | } 34 | 35 | //获取文件SHA256值 36 | public static String getFileSHA256Str(String file) throws NoSuchAlgorithmException, IOException 37 | { 38 | MessageDigest sha256 = MessageDigest.getInstance("SHA-256"); 39 | FileInputStream fis = new FileInputStream(file); 40 | byte[] data = new byte[1024]; 41 | int read = 0; 42 | while ((read = fis.read(data)) != -1) { 43 | sha256.update(data, 0, read); 44 | }; 45 | byte[] hashBytes = sha256.digest(); 46 | StringBuffer sb = new StringBuffer(); 47 | for (int i = 0; i < hashBytes.length; i++) { 48 | sb.append(Integer.toString((hashBytes[i] & 0xff) + 0x100, 16).substring(1)); 49 | } 50 | String fileHash = sb.toString(); 51 | return fileHash; 52 | } 53 | 54 | //判断非空 55 | public static boolean stringIsNull(String str) { 56 | if (null==str || "".equals(str)) { 57 | return true; 58 | } 59 | return false; 60 | } 61 | 62 | public static boolean isNullOrEmpty(Object obj) { 63 | if (obj == null) 64 | return true; 65 | 66 | if (obj instanceof CharSequence) 67 | return ((CharSequence) obj).length() == 0; 68 | 69 | if (obj instanceof Collection) 70 | return ((Collection) obj).isEmpty(); 71 | 72 | if (obj instanceof Map) 73 | return ((Map) obj).isEmpty(); 74 | 75 | if (obj instanceof Object[]) { 76 | Object[] object = (Object[]) obj; 77 | if (object.length == 0) { 78 | return true; 79 | } 80 | boolean empty = true; 81 | for (int i = 0; i < object.length; i++) { 82 | if (!isNullOrEmpty(object[i])) { 83 | empty = false; 84 | break; 85 | } 86 | } 87 | return empty; 88 | } 89 | return false; 90 | } 91 | 92 | /** 93 | *

94 | * 读取文件 95 | * 读取公私钥文件用于后续的加解密 96 | *

97 | * 98 | * @param filePath文件路径 99 | * @return 100 | * @throws Exception 101 | * @author wangbin 102 | */ 103 | public static String fileRead(String filePath) throws Exception { 104 | File file = new File(filePath); //定义一个file对象,用来初始化FileReader 105 | FileReader reader = new FileReader(file); //定义一个fileReader对象,用来初始化BufferedReader 106 | BufferedReader bReader = new BufferedReader(reader); //new一个BufferedReader对象,将文件内容读取到缓存 107 | StringBuilder sb = new StringBuilder(); //定义一个字符串缓存,将字符串存放缓存中 108 | String s = ""; 109 | while ((s =bReader.readLine()) != null) { //逐行读取文件内容,不读取换行符和末尾的空格 110 | sb.append(s); //将读取的字符串添加换行符后累加存放在缓存中 111 | } 112 | bReader.close(); 113 | String str = sb.toString(); 114 | return str; 115 | } 116 | 117 | 118 | /** 119 | * simpleDateFormat统一格式化时间 120 | */ 121 | public static String sdf(Object object) { 122 | SimpleDateFormat simpleDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 123 | return simpleDateFormat.format(object); 124 | } 125 | 126 | } 127 | --------------------------------------------------------------------------------