TRX vor 1 Jahr
Ursprung
Commit
015d448926
16 geänderte Dateien mit 488 neuen und 32 gelöschten Zeilen
  1. 3 0
      FullCardClient/src/main/java/com/zhongshu/card/client/model/devices/DeviceBindAreaParam.java
  2. 3 3
      FullCardClient/src/main/java/com/zhongshu/card/client/model/devices/DevicePermissParam.java
  3. 42 0
      FullCardClient/src/main/java/com/zhongshu/card/client/model/devices/DeviceUseRecordModel.java
  4. 28 0
      FullCardClient/src/main/java/com/zhongshu/card/client/model/devices/DeviceUseRecordSearch.java
  5. 97 0
      FullCardServer/src/main/java/com/zhongshu/card/server/core/controller/devices/DeviceUseRecordController.java
  6. 2 1
      FullCardServer/src/main/java/com/zhongshu/card/server/core/controller/gateDoor/GateDoorController.java
  7. 2 0
      FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/devices/DevicePermissDao.java
  8. 24 0
      FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/devices/DeviceUseRecordDao.java
  9. 24 0
      FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/devices/extend/DeviceUseRecordDaoExtend.java
  10. 91 0
      FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/devices/impl/DeviceUseRecordDaoImpl.java
  11. 65 0
      FullCardServer/src/main/java/com/zhongshu/card/server/core/domain/devices/DeviceUseRecord.java
  12. 3 2
      FullCardServer/src/main/java/com/zhongshu/card/server/core/service/devices/DeviceInfoServiceImpl.java
  13. 30 25
      FullCardServer/src/main/java/com/zhongshu/card/server/core/service/devices/DevicePermissService.java
  14. 71 0
      FullCardServer/src/main/java/com/zhongshu/card/server/core/service/devices/DeviceUseRecordService.java
  15. 2 0
      FullCardServer/src/main/java/com/zhongshu/card/server/core/service/gateDoor/GateDoorService.java
  16. 1 1
      FullCardServer/src/main/java/com/zhongshu/card/server/core/service/openAPI/OpenApiRequestService.java

+ 3 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/model/devices/DeviceBindAreaParam.java

@@ -19,6 +19,9 @@ public class DeviceBindAreaParam {
     @Schema(description = "数据id")
     private String id;
 
+    @Schema(description = "设备名称")
+    private String deviceName;
+
     @Schema(description = "区域ID")
     private String areaId;
 

+ 3 - 3
FullCardClient/src/main/java/com/zhongshu/card/client/model/devices/DevicePermissParam.java

@@ -1,5 +1,6 @@
 package com.zhongshu.card.client.model.devices;
 
+import com.zhongshu.card.client.model.base.ProjectOidParam;
 import com.zhongshu.card.client.model.base.SuperParam;
 import io.swagger.v3.oas.annotations.media.Schema;
 import jakarta.validation.constraints.NotEmpty;
@@ -17,11 +18,10 @@ import java.util.List;
 @Data
 @AllArgsConstructor
 @NoArgsConstructor
-public class DevicePermissParam extends SuperParam {
+public class DevicePermissParam extends ProjectOidParam {
 
     @Schema(description = "设备ID")
-    @NotEmpty
-    private String deviceId;
+    private List<String> deviceIds;
 
     @Schema(description = "机构用户id集合")
     private List<String> ids = new ArrayList<>();

+ 42 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/model/devices/DeviceUseRecordModel.java

@@ -0,0 +1,42 @@
+package com.zhongshu.card.client.model.devices;
+
+import com.zhongshu.card.client.model.base.SuperModel;
+import com.zhongshu.card.client.model.school.CardInfoModel;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * @author TRX
+ * @date 2024/10/21
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class DeviceUseRecordModel extends SuperModel {
+
+    @Schema(description = "卡片信息")
+    private CardInfoModel cardInfoModel;
+
+    @Schema(description = "开门模式(0:刷卡 1:人脸认证 2:指纹 3:密码)")
+    private Integer mode;
+
+    private String modeStr;
+
+    public String getModeStr() {
+        if (mode != null) {
+            if (mode == 0) {
+                return "刷卡";
+            } else if (mode == 1) {
+                return "人脸认证";
+            } else if (mode == 2) {
+                return "指纹";
+            } else if (mode == 3) {
+                return "密码";
+            }
+        }
+        return "";
+    }
+
+}

+ 28 - 0
FullCardClient/src/main/java/com/zhongshu/card/client/model/devices/DeviceUseRecordSearch.java

@@ -0,0 +1,28 @@
+package com.zhongshu.card.client.model.devices;
+
+import com.github.microservice.models.type.DeviceType;
+import com.zhongshu.card.client.model.base.SuperSearch;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * 设备使用记录的搜索
+ *
+ * @author TRX
+ * @date 2024/10/21
+ */
+@Data
+@AllArgsConstructor
+@NoArgsConstructor
+public class DeviceUseRecordSearch extends SuperSearch {
+
+    @Schema(description = "设备ID")
+    private String deviceId;
+
+    @Schema(description = "设备类型")
+    private DeviceType deviceType;
+
+
+}

+ 97 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/controller/devices/DeviceUseRecordController.java

@@ -0,0 +1,97 @@
+package com.zhongshu.card.server.core.controller.devices;
+
+import com.github.microservice.auth.security.annotations.ResourceAuth;
+import com.github.microservice.auth.security.type.AuthType;
+import com.github.microservice.models.gateDoor.use.GateDoorUseParam;
+import com.github.microservice.net.ResultContent;
+import com.zhongshu.card.client.model.base.IDParam;
+import com.zhongshu.card.client.model.devices.*;
+import com.zhongshu.card.client.service.school.DeviceInfoService;
+import com.zhongshu.card.server.core.service.devices.DeviceUseRecordService;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.web.PageableDefault;
+import org.springframework.util.Assert;
+import org.springframework.web.bind.annotation.*;
+
+import javax.validation.Valid;
+import java.util.List;
+
+/**
+ * 设备使用日志
+ *
+ * @author TRX
+ * @date 2024/6/5
+ */
+@RestController
+@RequestMapping("/deviceUse")
+@Tag(name = "平台-设备使用日志")
+public class DeviceUseRecordController {
+
+    @Autowired
+    private DeviceInfoService deviceInfoService;
+
+    @Autowired
+    private DeviceUseRecordService deviceUseRecordService;
+
+
+    @Operation(summary = "物联网添加设备使用日志(通用不带复杂的业务)", description = "物联网添加设备使用日志")
+    @RequestMapping(value = "saveDeviceLogs", method = {RequestMethod.POST})
+    public ResultContent saveDeviceLogs(@RequestBody GateDoorUseParam param) {
+        return this.deviceUseRecordService.saveDeviceLogs(param);
+    }
+
+
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @Operation(summary = "根据设备数据ID 设备详情", description = "根据设备数据ID 设备详情")
+    @RequestMapping(value = "getDeviceById", method = {RequestMethod.POST})
+    public ResultContent<DeviceInfoMoreModel> getDeviceById(@RequestBody IDParam param) {
+        return this.deviceInfoService.getDeviceDetail(param.getId());
+    }
+
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @Operation(summary = "根据设备ID 设备详情(精确匹配)", description = "根据设备ID 设备详情(精确匹配)")
+    @RequestMapping(value = "getDeviceByDeviceId", method = {RequestMethod.GET})
+    public ResultContent<DeviceInfoMoreModel> getDeviceByDeviceId(@RequestParam(name = "deviceId") String deviceId) {
+        return this.deviceInfoService.getDeviceDetailByDeviceId(deviceId);
+    }
+
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @Operation(summary = "根据设备ID 设备列表(模糊匹配)", description = "根据设备ID 设备列表(模糊匹配)")
+    @RequestMapping(value = "getDeviceDetailByDeviceIdLike", method = {RequestMethod.GET})
+    public ResultContent<List<DeviceInfoMoreModel>> getDeviceDetailByDeviceIdLike(@RequestParam(name = "deviceId") String deviceId) {
+        return this.deviceInfoService.getDeviceDetailByDeviceIdLike(deviceId);
+    }
+
+
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @Operation(summary = "删除设备", description = "删除设备")
+    @RequestMapping(value = "deleteDeviceInfo", method = {RequestMethod.POST})
+    public ResultContent deleteDeviceInfo(@RequestBody IDParam param) {
+        return this.deviceInfoService.deleteDeviceInfo(param.getId());
+    }
+
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @Operation(summary = "设备列表-分页查询", description = "设备列表-分页查询")
+    @RequestMapping(value = {"page"}, method = {RequestMethod.POST})
+    public ResultContent<Page<DeviceInfoModel>> page(
+            @Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable,
+            @Parameter(required = false) DeviceInfoSearch param) {
+        Assert.hasText(param.getProjectOid(), "projectOid不能为空");
+        return deviceInfoService.page(param, pageable);
+    }
+
+    @ResourceAuth(value = "user", type = AuthType.User)
+    @Operation(summary = "修改设备信息", description = "修改设备信息")
+    @RequestMapping(value = "updateDevice", method = {RequestMethod.POST})
+    public ResultContent updateDevice(@RequestBody @Valid DeviceBindAreaParam param) {
+        return this.deviceInfoService.updateDevice(param);
+    }
+
+    //----------------------------设备基础信息 end--------------------------
+
+}

+ 2 - 1
FullCardServer/src/main/java/com/zhongshu/card/server/core/controller/gateDoor/GateDoorController.java

@@ -2,6 +2,7 @@ package com.zhongshu.card.server.core.controller.gateDoor;
 
 
 import com.github.microservice.models.gateDoor.OnLineParam;
+import com.github.microservice.models.gateDoor.use.GateDoorUseParam;
 import com.github.microservice.models.hxz.*;
 import com.github.microservice.net.ResultContent;
 import com.zhongshu.card.server.core.service.gateDoor.GateDoorService;
@@ -26,7 +27,7 @@ public class GateDoorController {
 
     @Autowired
     GateDoorService gateDoorService;
-
+    
     /**
      * 设备上线通知
      */

+ 2 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/devices/DevicePermissDao.java

@@ -22,6 +22,8 @@ public interface DevicePermissDao extends MongoDao<DevicePermiss>, DevicePermiss
 
     DevicePermiss findTopByDeviceIdAndOrganizationUser(String deviceId, OrganizationUser organizationUser);
 
+    DevicePermiss findTopByUserIdAndDeviceIdAndProjectOid(String userId, String deviceId, String projectOid);
+
     List<DevicePermiss> findByOrganizationUserIn(List<OrganizationUser> organizationUsers);
 
     List<DevicePermiss> findByDeviceIdInAndDataState(List<String> deviceIds, DataState dataState);

+ 24 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/devices/DeviceUseRecordDao.java

@@ -0,0 +1,24 @@
+package com.zhongshu.card.server.core.dao.devices;
+
+import com.github.microservice.components.data.mongo.mongo.dao.MongoDao;
+import com.zhongshu.card.server.core.dao.devices.extend.DeviceInfoDaoExtend;
+import com.zhongshu.card.server.core.dao.devices.extend.DeviceUseRecordDaoExtend;
+import com.zhongshu.card.server.core.domain.devices.DeviceInfo;
+import com.zhongshu.card.server.core.domain.devices.DeviceUseRecord;
+import com.zhongshu.card.server.core.domain.payment.ExpenseFlow;
+
+import java.util.List;
+
+/**
+ * 设备使用记录Dao
+ *
+ * @author TRX
+ * @date 2024/3/21
+ */
+public interface DeviceUseRecordDao extends MongoDao<DeviceUseRecord>, DeviceUseRecordDaoExtend {
+
+    DeviceUseRecord findTopById(String id);
+
+    DeviceUseRecord findTopByMqttDataId(String mqttDataId);
+
+}

+ 24 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/devices/extend/DeviceUseRecordDaoExtend.java

@@ -0,0 +1,24 @@
+package com.zhongshu.card.server.core.dao.devices.extend;
+
+import com.zhongshu.card.client.model.devices.DeviceInfoSearch;
+import com.zhongshu.card.client.model.devices.DeviceUseRecordSearch;
+import com.zhongshu.card.server.core.domain.devices.DeviceInfo;
+import com.zhongshu.card.server.core.domain.devices.DeviceUseRecord;
+import com.zhongshu.card.server.core.domain.payment.ExpenseFlow;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+
+/**
+ * 设备使用记录日志
+ *
+ * @Author TRX
+ * @CreateDate: 2023/7/7
+ * @Version: 1.0
+ */
+public interface DeviceUseRecordDaoExtend {
+
+    Page<DeviceUseRecord> page(Pageable pageable, DeviceUseRecordSearch param);
+
+    DeviceUseRecord init(String mqttDataId, String token);
+
+}

+ 91 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/dao/devices/impl/DeviceUseRecordDaoImpl.java

@@ -0,0 +1,91 @@
+package com.zhongshu.card.server.core.dao.devices.impl;
+
+import com.github.microservice.components.data.mongo.mongo.helper.DBHelper;
+import com.zhongshu.card.client.model.devices.DeviceInfoSearch;
+import com.zhongshu.card.client.model.devices.DeviceUseRecordSearch;
+import com.zhongshu.card.server.core.dao.BaseImpl;
+import com.zhongshu.card.server.core.dao.devices.extend.DeviceInfoDaoExtend;
+import com.zhongshu.card.server.core.dao.devices.extend.DeviceUseRecordDaoExtend;
+import com.zhongshu.card.server.core.domain.devices.DeviceInfo;
+import com.zhongshu.card.server.core.domain.devices.DeviceUseRecord;
+import com.zhongshu.card.server.core.domain.payment.ExpenseFlow;
+import com.zhongshu.card.server.core.domain.school.Area;
+import com.zhongshu.card.server.core.util.CommonUtil;
+import lombok.extern.slf4j.Slf4j;
+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.data.domain.Sort;
+import org.springframework.data.mongodb.core.FindAndModifyOptions;
+import org.springframework.data.mongodb.core.MongoTemplate;
+import org.springframework.data.mongodb.core.query.Criteria;
+import org.springframework.data.mongodb.core.query.Query;
+import org.springframework.data.mongodb.core.query.Update;
+import org.springframework.util.CollectionUtils;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Pattern;
+
+/**
+ * @Author TRX
+ * @CreateDate: 2023/4/12
+ * @Version: 1.0
+ */
+@Slf4j
+public class DeviceUseRecordDaoImpl extends BaseImpl implements DeviceUseRecordDaoExtend {
+
+    @Autowired
+    private MongoTemplate mongoTemplate;
+
+    @Autowired
+    private DBHelper dbHelper;
+
+    @Override
+    public Page<DeviceUseRecord> page(Pageable pageable, DeviceUseRecordSearch param) {
+        Criteria criteria = buildCriteriaNotOid(param);
+
+        // 所属项目
+        if (StringUtils.isNotEmpty(param.getProjectOid())) {
+            criteria.and("projectOid").is(param.getProjectOid());
+        }
+
+        // 设备类型
+        if (param.getDeviceType() != null) {
+            criteria.and("deviceType").is(param.getDeviceType());
+        }
+
+        // 模糊搜索
+        List<Criteria> criterias = new ArrayList<>();
+        if (StringUtils.isNotEmpty(param.getDeviceId())) {
+            Pattern pattern = Pattern.compile("^.*" + param.getDeviceId() + ".*$");
+            criterias.add(Criteria.where("deviceId").is(pattern));
+        }
+        if (!CollectionUtils.isEmpty(criterias)) {
+            criteria.andOperator(criterias.toArray(new Criteria[]{}));
+        }
+        Sort sort = buildSort(param);
+        Query query = Query.query(criteria);
+        query.with(sort);
+        return dbHelper.pages(query, pageable, DeviceUseRecord.class);
+    }
+
+    public DeviceUseRecord init(String mqttDataId, String token) {
+        DeviceUseRecord doc = null;
+        try {
+            Query query = Query.query(Criteria.where("mqttDataId").is(mqttDataId).and("token").isNull());
+            Update update = new Update()
+                    .set("token", token)
+                    .set("createTime", System.currentTimeMillis());
+            FindAndModifyOptions options = new FindAndModifyOptions().upsert(true)
+                    .returnNew(true);
+            doc = mongoTemplate.findAndModify(query, update, options,
+                    DeviceUseRecord.class);
+        } catch (Exception e) {
+            log.error("init {}", e.getMessage());
+        }
+        return doc;
+    }
+
+}

+ 65 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/domain/devices/DeviceUseRecord.java

@@ -0,0 +1,65 @@
+package com.zhongshu.card.server.core.domain.devices;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.github.microservice.components.data.mongo.mongo.domain.SuperEntity;
+import com.github.microservice.models.type.DeviceType;
+import com.zhongshu.card.server.core.domain.base.SuperMain;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import org.springframework.data.mongodb.core.index.Indexed;
+import org.springframework.data.mongodb.core.mapping.Document;
+
+import java.util.Date;
+
+/**
+ * 设备使用日志
+ *
+ * @author TRX
+ * @date 2024/10/21
+ */
+@Data
+@Document
+@NoArgsConstructor
+@AllArgsConstructor
+public class DeviceUseRecord extends SuperMain {
+
+    @Indexed(unique = true, sparse = true)
+    @Schema(description = "mqtt推送生成的业务数据ID")
+    private String mqttDataId;
+
+    //----------------------------设备信息start ---------------------
+    @Schema(description = "设备ID")
+    private String deviceId;
+
+    @Schema(description = "设备类型")
+    private DeviceType deviceType;
+
+    @Schema(description = "10进制卡序列号(实体卡号或虚拟卡号)")
+    private String cardNo;
+
+    @Schema(description = "开门模式(0:刷卡 1:人脸认证 2:指纹 3:密码)")
+    private Integer mode;
+
+    @Schema(description = "用户userId")
+    private String userId;
+
+    @Schema(description = "使用时间 2024-09-12 20:40:00")
+    private String time;
+
+    @Schema(description = "使用是否验证通过")
+    private Boolean isPassed = Boolean.TRUE;
+
+    @JsonProperty("IsOffLine")
+    @Schema(description = "是否是离线使用")
+    private Boolean isOffLine = Boolean.FALSE;
+
+    @Schema(description = "提示信息")
+    private String msg = "";
+
+    @Schema(description = "过期时间")
+    @Indexed(expireAfterSeconds = 0)
+    private Date ttl;
+
+}

+ 3 - 2
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/devices/DeviceInfoServiceImpl.java

@@ -72,13 +72,14 @@ public class DeviceInfoServiceImpl extends SuperService implements DeviceInfoSer
         String deviceId = param.getDeviceId();
         DeviceInfo deviceInfo = deviceInfoDao.findTopByDeviceId(deviceId);
         if (ObjectUtils.isNotEmpty(deviceInfo)) {
-            // 编辑
+            // 编辑 (不能再同步名称了,可能已改了)
+            BeanUtils.copyProperties(param, deviceInfo, "id", "deviceName");
         } else {
             // 新增
             deviceInfo = new DeviceInfo();
             initEntityNoCheckOid(deviceInfo);
+            BeanUtils.copyProperties(param, deviceInfo, "id");
         }
-        BeanUtils.copyProperties(param, deviceInfo, "id");
         deviceInfo.setProjectInfoName(organizationServiceImpl.getOrgNameByCode(param.getProjectInfoCode()));
 
         if (StringUtils.isNotEmpty(param.getProjectInfoCode())) {

+ 30 - 25
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/devices/DevicePermissService.java

@@ -99,39 +99,43 @@ public class DevicePermissService extends SuperService {
         if (ObjectUtils.isEmpty(projectOid)) {
             return ResultContent.buildFail(String.format("projectOid不能为空"));
         }
-
-        String deviceId = param.getDeviceId();
-        DeviceInfo deviceInfo = deviceInfoDao.findTopByDeviceId(deviceId);
-        if (ObjectUtils.isEmpty(deviceInfo)) {
-            return ResultContent.buildFail(String.format("设备信息不存在:%s", deviceId));
+        if (ObjectUtils.isEmpty(param.getDeviceIds())) {
+            return ResultContent.buildFail("deviceIds不能为空");
         }
         List<String> ids = param.getIds();
         if (ObjectUtils.isEmpty(ids)) {
             return ResultContent.buildFail("ids is null");
         }
-
-        if (ObjectUtils.isNotEmpty(ids)) {
-            List<OrganizationUser> list = organizationUserDao.findByIdIn(ids);
-            if (ObjectUtils.isNotEmpty(list)) {
-                List<DevicePermiss> permisses = new ArrayList<DevicePermiss>();
-                for (OrganizationUser organizationUser : list) {
-                    DevicePermiss permiss = devicePermissDao.findTopByDeviceIdAndOrganizationUser(deviceId, organizationUser);
-                    if (ObjectUtils.isEmpty(permiss)) {
-                        permiss = new DevicePermiss();
-                        initEntity(permiss);
-                    } else {
-                        initUpdateEntity(permiss);
+        // 设备数据
+        List<DeviceInfo> deviceInfos = deviceInfoDao.findByDeviceIdIn(param.getDeviceIds());
+        if (ObjectUtils.isNotEmpty(deviceInfos)) {
+            // 机构用户数据
+            List<OrganizationUser> orgUsers = organizationUserDao.findByIdIn(ids);
+            if (ObjectUtils.isNotEmpty(orgUsers)) {
+                for (DeviceInfo deviceInfo : deviceInfos) {
+                    List<DevicePermiss> permisses = new ArrayList<DevicePermiss>();
+                    for (OrganizationUser organizationUser : orgUsers) {
+                        String userId = organizationUser.getUserId();
+                        // 判断是否是编辑
+                        DevicePermiss permiss = devicePermissDao.findTopByUserIdAndDeviceIdAndProjectOid(
+                                deviceInfo.getDeviceId(), userId, projectOid);
+                        if (ObjectUtils.isEmpty(permiss)) {
+                            permiss = new DevicePermiss();
+                            initEntity(permiss);
+                        } else {
+                            initUpdateEntity(permiss);
+                        }
+                        buildDeviceInfo(permiss, deviceInfo);
+                        buildOrgUserInfo(permiss, organizationUser);
+                        permisses.add(permiss);
                     }
-                    buildDeviceInfo(permiss, deviceInfo);
-                    buildOrgUserInfo(permiss, organizationUser);
-                    permisses.add(permiss);
+                    devicePermissDao.saveAll(permisses);
                 }
-                devicePermissDao.saveAll(permisses);
-
-                // 设备权限发生变化
-                DevicePermissChangeEvent event = new DevicePermissChangeEvent(this, List.of(deviceId));
-                applicationContext.publishEvent(event);
             }
+
+            // 设备权限发生变化
+            DevicePermissChangeEvent event = new DevicePermissChangeEvent(this, param.getDeviceIds());
+            applicationContext.publishEvent(event);
         }
         return ResultContent.buildSuccess();
     }
@@ -153,6 +157,7 @@ public class DevicePermissService extends SuperService {
             UserAccount userAccount = organizationUser.getUser();
             permiss.setOrganizationUser(organizationUser);
             permiss.setUserAccount(userAccount);
+
             permiss.setUserId(userAccount.getUserId());
             permiss.setName(userAccount.getName());
             permiss.setDepartment(organizationUser.getDepartment());

+ 71 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/devices/DeviceUseRecordService.java

@@ -0,0 +1,71 @@
+package com.zhongshu.card.server.core.service.devices;
+
+import cn.hutool.json.JSONUtil;
+import com.github.microservice.models.gateDoor.use.GateDoorUseParam;
+import com.github.microservice.models.gateDoor.use.GateDoorUseResult;
+import com.github.microservice.net.ResultContent;
+import com.zhongshu.card.client.model.devices.DeviceUseRecordModel;
+import com.zhongshu.card.server.core.dao.devices.DeviceUseRecordDao;
+import com.zhongshu.card.server.core.domain.devices.DeviceUseRecord;
+import com.zhongshu.card.server.core.domain.payment.ExpenseFlow;
+import com.zhongshu.card.server.core.service.base.SuperService;
+import com.zhongshu.card.server.core.util.BeanUtils;
+import com.zhongshu.card.server.core.util.TokenUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.ObjectUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+/**
+ * @author TRX
+ * @date 2024/10/21
+ */
+@Slf4j
+@Service
+public class DeviceUseRecordService extends SuperService {
+
+    @Autowired
+    private DeviceUseRecordDao deviceUseRecordDao;
+
+    /**
+     * 设备使用日志 (物联网来的数据)
+     *
+     * @param param
+     * @return
+     */
+    public ResultContent saveDeviceLogs(GateDoorUseParam param) {
+        // 返回数据
+        GateDoorUseResult result = new GateDoorUseResult();
+        // 是否是离线的日志(离线的话已经操作了,不能验证数据)
+        Boolean isOffLine = param.getIsOffLine();
+        if (isOffLine != null && isOffLine) {
+            // 离线的数据
+        }
+        String deviceId = param.getDeviceId();
+
+
+        result.setMqttDataId(param.getMqttDataId());
+        return ResultContent.buildSuccess(JSONUtil.toJsonStr(result));
+    }
+
+    public DeviceUseRecord init(String mqttDataId) {
+        DeviceUseRecord expenseFlow = deviceUseRecordDao.init(mqttDataId, TokenUtil.create());
+        return expenseFlow;
+    }
+
+    /**
+     * 模型转换
+     *
+     * @param entity
+     * @return
+     */
+    public DeviceUseRecordModel toModel(DeviceUseRecord entity) {
+        DeviceUseRecordModel model = null;
+        if (ObjectUtils.isNotEmpty(entity)) {
+            model = new DeviceUseRecordModel();
+            BeanUtils.copyProperties(entity, model);
+        }
+        return model;
+    }
+
+}

+ 2 - 0
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/gateDoor/GateDoorService.java

@@ -6,6 +6,8 @@ import com.github.microservice.models.gateDoor.OnLineAckInfoModel;
 import com.github.microservice.models.gateDoor.OnLineInfoParam;
 import com.github.microservice.models.gateDoor.OnLineModel;
 import com.github.microservice.models.gateDoor.OnLineParam;
+import com.github.microservice.models.gateDoor.use.GateDoorUseParam;
+import com.github.microservice.models.gateDoor.use.GateDoorUseResult;
 import com.github.microservice.net.ResultContent;
 import com.zhongshu.card.client.type.payment.RequestType;
 import com.zhongshu.card.server.core.service.base.SuperService;

+ 1 - 1
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/openAPI/OpenApiRequestService.java

@@ -80,7 +80,7 @@ public class OpenApiRequestService extends SuperService {
         APIResponseModel responseModel = requestAPI(projectIotInfo.getUrl(), apiName,
                 projectIotInfo.getAk(), projectIotInfo.getSk(), param);
         if (responseModel.isFailed()) {
-            log.error("{}", responseModel.getMsg());
+            log.error("{} {}", responseModel.getMsg(), projectOid);
             return ResultContent.buildFail(responseModel.getMsg());
         }
         return ResultContent.buildSuccess(responseModel);