package com.attendance.service;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import com.attendance.blockchain.block.Block;
import com.attendance.blockchain.block.BlockBody;
import com.attendance.blockchain.block.body.Attendance;
import com.attendance.blockchain.block.pair.PairKey;
import com.attendance.blockchain.block.pair.PrivateKey;
import com.attendance.blockchain.common.Sha256;
import com.attendance.blockchain.common.TrustSDK;
import com.attendance.blockchain.core.block.body.Place;
import com.attendance.blockchain.core.block.db.DbBlockRead;
import com.attendance.blockchain.core.block.service.BlockService;
import com.attendance.entity.UserEntity;
import com.attendance.service.exception.MsgException;
import com.jfinal.aop.Aop;
import com.jfinal.kit.StrKit;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import cn.hutool.core.date.DateUtil;
public class UserService {
private BlockService blockService = Aop.get(BlockService.class);
/**
* 保存用户信息
* @Author: zhangwei
* @Date: 2022年5月7日 下午3:00:49
*/
public void saveUser(String userName, String password) {
Record userRecord = Db.findById("USER", "USER_NAME", userName);
if(userRecord != null) {
throw new MsgException("该用户名已被注册!");
}
PairKey pairKey = TrustSDK.generatePairKey();
UserEntity userEntity = new UserEntity();
userEntity.setUsername(userName).setPassword(password);
userEntity.setPublicKey(pairKey.getPublicKey().toString());
userEntity.setPrivatekey(pairKey.getPrivateKey().toString());
userEntity.save();
}
/**
* 保存用户信息
* @Author: zhangwei
* @Date: 2022年5月7日 下午3:00:49
*/
public void login(String userName, String password) {
Record userRecord = Db.findById("USER", "USER_NAME", userName);
if(userRecord == null) {
throw new MsgException("该用户名不存在!");
}
String userPwd = userRecord.getStr("PASSWORD");
if(!userPwd.equals(password)) {
throw new MsgException("密码错误!");
}
}
/**
* 打卡
* @Author: zhangwei
* @Date: 2022年5月7日 下午3:00:49
*/
public void clockIn(String userName, String placeStr) {
Record userRecord = Db.findById("USER", "USER_NAME", userName);
if(userRecord == null) {
throw new MsgException("该用户名不存在!");
}
Place place = Place.toPlace(placeStr);
Attendance attendance = new Attendance();
attendance.setTimeStamp(System.currentTimeMillis());
attendance.setPlace(place);
attendance.setPublicKey(userRecord.getStr("PUBLIC_KEY"));
String buildStr = attendance.getTimeStamp() + attendance.getPlace().toString() + attendance.getPublicKey().toString();
attendance.setSign(TrustSDK.signString(PrivateKey.create(userRecord.getStr("PRIVATE_KEY")), buildStr));
attendance.setHash(Sha256.digestHex(buildStr));
blockService.recordBody(attendance);
}
/**
* 获取所有打卡信息
*
* @Author: zhangwei
* @Date: 2022年5月7日 下午3:00:49
*/
public List<Record> getAllClockInData(String searchPublicKey) {
DbBlockRead readDbBlock = blockService.getReadDbBlock();
List<Block> blockList = readDbBlock.getBlockAll();
List<Record> attendanceList = new ArrayList<Record>();
for(Block block : blockList) {
if(block == null) continue;
BlockBody blockBody = block.getBlockBody();
Collection<Attendance> bodyList = blockBody.getBodyList();
for(Attendance body : bodyList) {
String publicKey = body.getPublicKey();
if(StrKit.notBlank(searchPublicKey) && StrKit.notBlank(publicKey) && !searchPublicKey.equals(publicKey)) {
continue;
}
Record record = new Record().set("place", body.getPlace().getDescribe());
record.set("publicKey", publicKey).set("time", DateUtil.formatDateTime(DateUtil.date(body.getTimeStamp())));
record.set("contractBody", body.getContractBody());
Record userRecord = Db.findById("USER", "PUBLIC_KEY", publicKey);
attendanceList.add(record.set("userName", userRecord.getStr("USER_NAME")));
}
}
return attendanceList;
}
/**
* 获取所有打卡信息
*
* @Author: zhangwei
* @Date: 2022年5月7日 下午3:00:49
*/
public List<UserEntity> getAllUserData() {
return UserEntity.dao.findAll();
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
毕业设计—基于java区块链技术开发考勤管理系统,已获导师指导的高分项目。 毕业设计—基于java区块链技术开发考勤管理系统,已获导师指导的高分项目。毕业设计—基于java区块链技术开发考勤管理系统,已获导师指导的高分项目。毕业设计—基于java区块链技术开发考勤管理系统,已获导师指导的高分项目。毕业设计—基于java区块链技术开发考勤管理系统,已获导师指导的高分项目。毕业设计—基于java区块链技术开发考勤管理系统,已获导师指导的高分项目。毕业设计—基于java区块链技术开发考勤管理系统,已获导师指导的高分项目。毕业设计—基于java区块链技术开发考勤管理系统,已获导师指导的高分项目。毕业设计—基于java区块链技术开发考勤管理系统,已获导师指导的高分项目。毕业设计—基于java区块链技术开发考勤系统,已获导师指导的高分项目。毕业设计—基于java区块链技术开发考勤系统,已获导师指导的高分项目。毕业设计—基于java区块链技术开发考勤系统,已获导师指导的高分项目。毕业设计—基于java区块链技术开发考勤系统,已获导师指导的高分项目。
资源推荐
资源详情
资源评论
收起资源包目录
基于区块链技术开发考勤系统.zip (58个子文件)
1
attendance-master
.gitignore 278B
.project 539B
.factorypath 2KB
pom.xml 4KB
target
classes
config.properties 0B
log4j.properties 540B
META-INF
maven
com.blockchain
attendance
pom.xml 4KB
pom.properties 236B
MANIFEST.MF 113B
db
attendance.db 24KB
undertow.properties 646B
.DS_Store 6KB
.settings
org.eclipse.jdt.apt.core.prefs 214B
org.eclipse.jdt.core.prefs 542B
org.eclipse.m2e.core.prefs 86B
LICENSE 9KB
package.xml 2KB
src
main
resources
config.properties 0B
log4j.properties 540B
db
.DS_Store 6KB
attendance.db 24KB
undertow.properties 646B
.DS_Store 6KB
java
com
attendance
controller
UserController.java 3KB
config
db
SqliteTool.java 401B
MainConfig.java 2KB
service
UserService.java 4KB
exception
MsgException.java 368B
entity
UserEntity.java 1KB
init
UserInit.java 1KB
blockchain
block
body
Attendance.java 632B
db
DbStore.java 561B
contract
Contract.java 234B
Block.java 366B
BlockBody.java 458B
pair
PublicKey.java 287B
PairKey.java 215B
PrivateKey.java 293B
BlockHeader.java 463B
PackBlock.java 3KB
common
Constants.java 806B
TrustSDK.java 2KB
algorithm
RSAAlgorithm.java 706B
Sha256.java 491B
core
request
body
BlockRequestBody.java 287B
block
body
Place.java 520B
db
LevelDbStoreImpl.java 608B
DbBlockOperate.java 2KB
DbBlockRead.java 4KB
service
BlockService.java 2KB
contract
AttendanceContract.java 921B
AttendanceStart.java 269B
.DS_Store 6KB
webapp
.DS_Store 14KB
.DS_Store 6KB
.DS_Store 6KB
.classpath 2KB
.DS_Store 6KB
共 58 条
- 1
资源评论
程序员张小妍
- 粉丝: 1w+
- 资源: 2463
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 高分课程设计作业-基于QT的模仿宝石迷阵游戏C++源码+文档说明+界面截图
- 基于Apache Spark的Spark DistCP重实现设计源码
- 粤港澳大湾区(黄埔)算法算例大赛-工业表面缺陷检测源码+超详细注释
- 在 KolektorSDD 数据上使用分割决策网络进行表面缺陷检测python源码+文档说明
- 操作系统作业:时间片轮转算法的模拟实现C++源码+文档说明
- 基于改进yolov5的金属曲面缺陷检测,使用pyqt5实习了实时视频检测的功能python源码+文档说明
- 基于Qt及OpenCv设计了一个视觉检测系统,实现了米粒的计数、缺陷分析功能+源码+文档说明+效果图
- 基于STM32F1和TB6612芯片的电机驱动板,可以驱动两个电机正反转,具有比L298N更小的体积源码+文档说明
- 基于Javascript的CNN卷积交互式播放器设计源码
- 基于Layui的树表格(treeGrid)前端设计源码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功