提交 f66d8bf1 authored 作者: 林业通's avatar 林业通

指纹锁修改

上级 2b3ef169
package tech.glinfo.enbao.common.utils;
public enum OpenSmartLockEnventEnum implements IEnventEnum{
FACE("01", "密码开锁成功"),
PWD("02", "卡片开锁成功"),
CARD("03", "指纹开锁成功"),
PALM("04", "手机远程开锁成功");
OpenSmartLockEnventEnum(String code, String description) {
this.code = code;
this.description = description;
}
public static String getName(String code) {
for (OpenSmartLockEnventEnum c : OpenSmartLockEnventEnum.values()) {
if (c.getCode().equals(code)) {
return c.description;
}
}
return null;
}
private String code;
private String description;
@Override
public String getCode() {
return code;
}
@Override
public String getDescription() {
return description;
}
}
......@@ -7,10 +7,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tech.glinfo.enbao.common.utils.ByteUtils;
import tech.glinfo.enbao.common.utils.DateUtils;
import tech.glinfo.enbao.common.utils.RedisUtils;
import tech.glinfo.enbao.common.utils.StringUtils;
import tech.glinfo.enbao.common.utils.*;
import tech.glinfo.enbao.modules.sh.entity.*;
import tech.glinfo.enbao.modules.sh.form.ProtocolContent;
import tech.glinfo.enbao.modules.sh.service.OtherShDeviceRecordService;
......@@ -67,7 +64,7 @@ public class SmartLockParse implements IParse {
//校验设备时钟
new Thread(() -> {
logger.info("start checkDeviceTime");
timeParseUtils.checkDeviceTime1(datas.get("receiveId"), datas.get("content"), "10");
timeParseUtils.checkDeviceTime2(datas.get("receiveId"), datas.get("content"), "10");
}).start();
return datas;
......@@ -87,6 +84,15 @@ public class SmartLockParse implements IParse {
ws.put(cmd.getName(), hex1);
length += cmd.getLength();
}
//更新锁电池
/*String electric = (String) map.get("electric");
if (StringUtils.isNotBlank(electric)) {
ShDeviceEntity deviceEntity = new ShDeviceEntity();
deviceEntity.setId(device.getId());
deviceEntity.setSpareOne(electric);
otherShDeviceService.updateById(deviceEntity);
}*/
otherShDeviceService.updateDeviceData(JSON.toJSONString(map), device.getId());
}
......@@ -153,10 +159,12 @@ public class SmartLockParse implements IParse {
}else if("20".equals(datas.get("cmd")) && datas.get("content").substring(0, 2).equals("01")) {
String content = datas.get("content");
int action = Integer.parseInt(content.substring(2, 4), 16);
String action = content.substring(2, 4);
int action1 = Integer.parseInt(action, 16);
ShDeviceRecordEntity recordEntity = new ShDeviceRecordEntity();
recordEntity.setDeviceId(device.getId());
recordEntity.setAction(action);
recordEntity.setAction(action1);
recordEntity.setRemark(OpenSmartLockEnventEnum.getName(action));
otherShDeviceRecordService.save(recordEntity);
//场景检查
......
......@@ -105,6 +105,45 @@ public class TimeParseUtils {
mqProducer.sendT(JSON.toJSONString(protocol));
}
void checkDeviceTime2(String numbering, String content, String deviceType) {
String hex = content.substring(20, 26);
String year = String.valueOf(Integer.valueOf(hex, 16));
String hex1 = content.substring(26, 28);
String month = StringUtils.appendString(String.valueOf(Integer.valueOf(hex1, 16)),2, true, "0");
String hex2 = content.substring(28, 30);
String day = StringUtils.appendString(String.valueOf(Integer.valueOf(hex2, 16)),2, true, "0");
String hex3 = content.substring(30, 32);
String hour = StringUtils.appendString(String.valueOf(Integer.valueOf(hex3, 16)),2, true, "0");
String hex4 = content.substring(32, 34);
String minute = StringUtils.appendString(String.valueOf(Integer.valueOf(hex4, 16)),2, true, "0");
String hex5 = content.substring(34, 36);
String second = StringUtils.appendString(String.valueOf(Integer.valueOf(hex5, 16)),2, true, "0");
String date = year+"-"+month+"-"+day+" "+hour+":"+minute+":"+second;
logger.info("device-time : " + date);
try {
Date date1 = DateUtils.stringToDate(date, DateUtils.DATE_TIME_PATTERN);
long diff = new Date().getTime() - date1.getTime();//这样得到的差值是毫秒级别
long min = diff / (1000 * 60);
//校验相差20分钟
if(min > 2 || min < -2) {
logger.info("update-time : {}", DateUtils.format(new Date(), DateUtils.DATE_TIME_PATTERN));
sendCmd2(numbering, deviceType);
}
}catch (Exception e) {
sendCmd2(numbering, deviceType);
}
}
private void sendCmd2(String numbering, String deviceType) {
ProtocolContent protocol = new ProtocolContent();
protocol.setCmd("10");
protocol.setDeviceType(deviceType);
protocol.setReceiveId(numbering);
protocol.setContent(getContent((new Date())));
mqProducer.sendT(JSON.toJSONString(protocol));
}
private String getContent(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date); //放入Date类型数据
......
......@@ -22,7 +22,7 @@ public interface OtherShDeviceRecordDao extends BaseMapper<ShDeviceRecordEntity>
@Select("<script>" +
"SELECT a.create_time createTime, a.action, IFNULL(b.user_name, a.id) userName FROM sh_device_record a LEFT JOIN lock_user b ON a.user_id = b.user_id AND b.lock_id = #{params.deviceId} WHERE a.device_id = #{params.deviceId}" +
"SELECT a.create_time createTime, a.action, IFNULL(b.user_name, a.id) userName FROM sh_device_record a LEFT JOIN sh_lock_user b ON a.user_id = b.user_id AND b.lock_id = #{params.deviceId} WHERE a.device_id = #{params.deviceId}" +
" <if test='params.time != null and params.time != \"\"' > "
+ " AND DATE_FORMAT(a.create_time, '%Y-%m') = #{params.time} "
+ " </if>"
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论