|
|
@@ -1,18 +1,28 @@
|
|
|
package com.zhongshu.card.server.core.service.devices;
|
|
|
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
+import com.github.microservice.components.data.base.util.PageEntityUtil;
|
|
|
+import com.github.microservice.models.gateDoor.gateDoor.GateDoorIotParam;
|
|
|
+import com.github.microservice.models.gateDoor.use.GateDoorInfoParam;
|
|
|
import com.github.microservice.models.gateDoor.use.GateDoorUseParam;
|
|
|
import com.github.microservice.models.gateDoor.use.GateDoorUseResult;
|
|
|
import com.github.microservice.net.ResultContent;
|
|
|
+import com.github.microservice.types.deviceUse.OperateState;
|
|
|
+import com.github.microservice.types.deviceUse.OperateType;
|
|
|
+import com.zhongshu.card.client.model.devices.DeviceInfoModel;
|
|
|
+import com.zhongshu.card.client.model.devices.DeviceInfoSearch;
|
|
|
import com.zhongshu.card.client.model.devices.DeviceUseRecordModel;
|
|
|
+import com.zhongshu.card.client.model.devices.DeviceUseRecordSearch;
|
|
|
import com.zhongshu.card.client.utils.DateUtils;
|
|
|
import com.zhongshu.card.server.core.dao.devices.DeviceInfoDao;
|
|
|
import com.zhongshu.card.server.core.dao.devices.DevicePermissDao;
|
|
|
import com.zhongshu.card.server.core.dao.devices.DeviceUseRecordDao;
|
|
|
+import com.zhongshu.card.server.core.dao.org.OrganizationDao;
|
|
|
import com.zhongshu.card.server.core.dao.org.UserCountDao;
|
|
|
import com.zhongshu.card.server.core.dao.school.CardInfoDao;
|
|
|
import com.zhongshu.card.server.core.domain.devices.DeviceInfo;
|
|
|
import com.zhongshu.card.server.core.domain.devices.DeviceUseRecords;
|
|
|
+import com.zhongshu.card.server.core.domain.org.Organization;
|
|
|
import com.zhongshu.card.server.core.domain.org.UserAccount;
|
|
|
import com.zhongshu.card.server.core.domain.school.CardInfo;
|
|
|
import com.zhongshu.card.server.core.service.base.SuperService;
|
|
|
@@ -24,8 +34,12 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.domain.Page;
|
|
|
+import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.util.Date;
|
|
|
+
|
|
|
/**
|
|
|
* @author TRX
|
|
|
* @date 2024/10/21
|
|
|
@@ -58,25 +72,92 @@ public class DeviceUseRecordService extends SuperService {
|
|
|
@Autowired
|
|
|
private DeviceInfoServiceImpl deviceInfoService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private OrganizationDao organizationDao;
|
|
|
+
|
|
|
+ private static Long ttlTime = 60 * 24 * 60 * 60 * 1000L;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 门闸的开门使用的 参数
|
|
|
+ *
|
|
|
+ * @param param
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ResultContent gateDoorUseRecord(GateDoorIotParam param) {
|
|
|
+ GateDoorUseResult result = new GateDoorUseResult();
|
|
|
+ GateDoorInfoParam info = param.getInfo();
|
|
|
+ log.info("闸机使用记录 gateDoorUseRecord...");
|
|
|
+ if (ObjectUtils.isNotEmpty(info)) {
|
|
|
+ // 封装记录日志参数
|
|
|
+ GateDoorUseParam useParam = new GateDoorUseParam();
|
|
|
+ useParam.setMqttDataId(param.getMqttDataId());
|
|
|
+ useParam.setDeviceId(param.getDeviceId());
|
|
|
+ useParam.setGateWayId(param.getGateWayId());
|
|
|
+
|
|
|
+ String VerifyStatus = info.getVerifyStatus();
|
|
|
+ if (StringUtils.isNotEmpty(VerifyStatus)) {
|
|
|
+ if ("1".equals(VerifyStatus)) {
|
|
|
+ // 成功
|
|
|
+ useParam.setOperateState(OperateState.Success);
|
|
|
+ } else if ("2".equals(VerifyStatus)) {
|
|
|
+ // 失败
|
|
|
+ useParam.setOperateState(OperateState.Failed);
|
|
|
+ } else {
|
|
|
+ // 未知
|
|
|
+ useParam.setOperateState(OperateState.Unknown);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 未知
|
|
|
+ useParam.setOperateState(OperateState.Unknown);
|
|
|
+ }
|
|
|
+ // 使用操作方式
|
|
|
+ if (StringUtils.isNotEmpty(info.getPic())) {
|
|
|
+ // 人脸形式
|
|
|
+ useParam.setOperateType(OperateType.Face);
|
|
|
+ } else {
|
|
|
+ String cardNum2 = info.getCardNum2();
|
|
|
+ if (StringUtils.isNotEmpty(cardNum2)) {
|
|
|
+ useParam.setOperateType(OperateType.Card);
|
|
|
+ useParam.setCardNo(cardNum2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (useParam.getOperateType() == null) {
|
|
|
+ useParam.setOperateType(OperateType.Unknown);
|
|
|
+ }
|
|
|
+ useParam.setTime(info.getTime());
|
|
|
+ useParam.setUserId(info.getCustomId());
|
|
|
+ useParam.setIsOffLine(param.getIsOffLine());
|
|
|
+ useParam.setData(param);
|
|
|
+ ResultContent<DeviceUseRecords> resultContent = saveDeviceLogs(useParam);
|
|
|
+ if (resultContent.isSuccess()) {
|
|
|
+ result.setSuccess("成功");
|
|
|
+ } else {
|
|
|
+ result.setFailed(resultContent.getMsg());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ result.setFailed("数据为空");
|
|
|
+ }
|
|
|
+ return ResultContent.buildSuccess(JSONUtil.toJsonStr(result));
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 设备使用日志 (物联网来的数据)
|
|
|
*
|
|
|
* @param param
|
|
|
* @return
|
|
|
*/
|
|
|
- public ResultContent saveDeviceLogs(GateDoorUseParam param) {
|
|
|
+ public ResultContent<DeviceUseRecords> saveDeviceLogs(GateDoorUseParam param) {
|
|
|
// 返回数据
|
|
|
- GateDoorUseResult result = new GateDoorUseResult();
|
|
|
String mqttDataId = param.getMqttDataId();
|
|
|
+ DeviceUseRecords deviceUseRecord = null;
|
|
|
log.info("saveDeviceUseRecord mqttDataId: {}", mqttDataId);
|
|
|
if (StringUtils.isNotEmpty(mqttDataId)) {
|
|
|
- DeviceUseRecords deviceUseRecord = init(mqttDataId);
|
|
|
+ deviceUseRecord = init(mqttDataId);
|
|
|
if (ObjectUtils.isNotEmpty(deviceUseRecord)) {
|
|
|
BeanUtils.copyProperties(param, deviceUseRecord);
|
|
|
String deviceId = param.getDeviceId();
|
|
|
String cardNo = param.getCardNo();
|
|
|
String userId = param.getUserId();
|
|
|
-
|
|
|
String projectOid = "";
|
|
|
DeviceInfo deviceInfo = null;
|
|
|
if (StringUtils.isNotEmpty(deviceId)) {
|
|
|
@@ -100,7 +181,7 @@ public class DeviceUseRecordService extends SuperService {
|
|
|
CardInfo cardInfo = null;
|
|
|
if (StringUtils.isNotEmpty(cardNo)) {
|
|
|
cardInfo = cardInfoDao.findByCode(cardNo);
|
|
|
- if (ObjectUtils.isNotEmpty(cardInfo)) {
|
|
|
+ if (StringUtils.isEmpty(userId) && ObjectUtils.isNotEmpty(cardInfo)) {
|
|
|
userId = cardInfo.getUserId();
|
|
|
}
|
|
|
}
|
|
|
@@ -116,51 +197,23 @@ public class DeviceUseRecordService extends SuperService {
|
|
|
}
|
|
|
deviceUseRecord.setUserId(userId);
|
|
|
deviceUseRecord.setUserAccount(userAccountService.toSimpleModel(userAccount));
|
|
|
-
|
|
|
if (StringUtils.isNotEmpty(param.getTime())) {
|
|
|
deviceUseRecord.setTimestamp(DateUtils.timeToLong(param.getTime(), DateUtils.FORMAT_LONG));
|
|
|
}
|
|
|
deviceUseRecord.setProjectOid(projectOid);
|
|
|
- // 是否是离线的日志(离线的话已经操作了,不能验证数据)
|
|
|
- Boolean isOffLine = param.getIsOffLine();
|
|
|
- if (isOffLine == null) {
|
|
|
- isOffLine = Boolean.FALSE;
|
|
|
- }
|
|
|
- deviceUseRecord.setIsOffLine(isOffLine);
|
|
|
- if (isOffLine != null && isOffLine) {
|
|
|
- Boolean isPassed = param.getIsPassed();
|
|
|
- if (isPassed == null) {
|
|
|
- isPassed = Boolean.FALSE;
|
|
|
- }
|
|
|
- // 离线的数据
|
|
|
- deviceUseRecord.setIsPassed(isPassed);
|
|
|
- if (isPassed) {
|
|
|
- deviceUseRecord.setMsg("操作成功");
|
|
|
- } else {
|
|
|
- deviceUseRecord.setMsg("验证失败");
|
|
|
- }
|
|
|
- } else {
|
|
|
- // 在线验证
|
|
|
- checkUseDeviceData(deviceUseRecord);
|
|
|
- }
|
|
|
-
|
|
|
- // 最后的返回判断
|
|
|
- if (deviceUseRecord.getIsPassed() != null && deviceUseRecord.getIsPassed()) {
|
|
|
- // 成功
|
|
|
- result.setSuccess();
|
|
|
- } else {
|
|
|
- // 失败
|
|
|
- result.setFailed(deviceUseRecord.getMsg());
|
|
|
+ Organization organization = organizationDao.findTopByOid(projectOid);
|
|
|
+ if (ObjectUtils.isNotEmpty(organization)) {
|
|
|
+ deviceUseRecord.setProjectName(organization.getName());
|
|
|
}
|
|
|
+ deviceUseRecord.setTtl(new Date(System.currentTimeMillis() + ttlTime));
|
|
|
deviceUseRecordDao.save(deviceUseRecord);
|
|
|
} else {
|
|
|
- result.setFailed("数据已处理");
|
|
|
+ return ResultContent.buildFail("数据初始失败");
|
|
|
}
|
|
|
} else {
|
|
|
- result.setFailed("mqttDataId为空");
|
|
|
+ return ResultContent.buildFail("mqttDataId为空");
|
|
|
}
|
|
|
- result.setMqttDataId(mqttDataId);
|
|
|
- return ResultContent.buildSuccess(JSONUtil.toJsonStr(result));
|
|
|
+ return ResultContent.buildSuccess(deviceUseRecord);
|
|
|
}
|
|
|
|
|
|
public DeviceUseRecords init(String mqttDataId) {
|
|
|
@@ -248,6 +301,28 @@ public class DeviceUseRecordService extends SuperService {
|
|
|
// }
|
|
|
}
|
|
|
|
|
|
+ public ResultContent<Page<DeviceUseRecordModel>> page(DeviceUseRecordSearch param, Pageable pageable) {
|
|
|
+ Page<DeviceUseRecords> page = deviceUseRecordDao.page(pageable, param);
|
|
|
+ return ResultContent.buildSuccess(PageEntityUtil.concurrent2PageModel(page, this::toModel));
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultContent getDetail(String id) {
|
|
|
+ DeviceUseRecords entity = deviceUseRecordDao.findTopById(id);
|
|
|
+ if (ObjectUtils.isEmpty(entity)) {
|
|
|
+ return ResultContent.buildFail(String.format("数据不存在"));
|
|
|
+ }
|
|
|
+ return ResultContent.buildSuccess(toModel(entity));
|
|
|
+ }
|
|
|
+
|
|
|
+ public ResultContent deleteById(String id) {
|
|
|
+ DeviceUseRecords entity = deviceUseRecordDao.findTopById(id);
|
|
|
+ if (ObjectUtils.isEmpty(entity)) {
|
|
|
+ return ResultContent.buildFail(String.format("数据不存在"));
|
|
|
+ }
|
|
|
+ deviceUseRecordDao.delete(entity);
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 模型转换
|
|
|
*
|