|
|
@@ -0,0 +1,227 @@
|
|
|
+package com.template.controller;
|
|
|
+
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
+import com.template.api.UnlockingCustomControllerAPI;
|
|
|
+import com.template.common.utils.PasswordChecker;
|
|
|
+import com.template.model.dto.CustomKeyCardDto;
|
|
|
+import com.template.model.dto.CustomKeyFingerprintDto;
|
|
|
+import com.template.model.dto.CustomKeyPassWordDto;
|
|
|
+import com.template.model.pojo.*;
|
|
|
+import com.template.model.result.CommonResult;
|
|
|
+import com.template.services.*;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 前端控制器
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author ceshi
|
|
|
+ * @since 2024-07-26
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+public class UnlockingCustomController implements UnlockingCustomControllerAPI {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ UnlockingCustomService unlockingCustomService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ PermissionSettingService permissionSettingService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ HouseNumberService houseNumberService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ PasswordIssController passwordIssController;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ AdminService adminService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ OperatingRecordService operatingRecordService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CommonResult saveCustomPassWord(CustomKeyPassWordDto dto) {
|
|
|
+ String permissionSettingId = dto.getPermissionSettingId();
|
|
|
+ PermissionSetting permissionSetting = permissionSettingService.getById(permissionSettingId);
|
|
|
+ if (ObjectUtils.isEmpty(permissionSetting)) {
|
|
|
+ return CommonResult.fail("非法进入");
|
|
|
+ }
|
|
|
+// 判断该用户是否拥有权限
|
|
|
+ String houseTypeManagement = permissionSetting.getDoorLockManagement();
|
|
|
+ if (!"0".equals(houseTypeManagement) && !houseTypeManagement.contains("11")) {
|
|
|
+ return CommonResult.fail("此账号暂无该权限");
|
|
|
+ }
|
|
|
+
|
|
|
+// 监测密码是否符合要求
|
|
|
+ String passWord = dto.getPassWord();
|
|
|
+ if (!PasswordChecker.isValidPassword(passWord)) {
|
|
|
+ return CommonResult.fail("密码长度的一半不能是连续升序、倒序、一样的数字");
|
|
|
+ }
|
|
|
+
|
|
|
+ Admin admin = adminService.getById(dto.getAdminId());
|
|
|
+ if (ObjectUtils.isEmpty(admin)) {
|
|
|
+ return CommonResult.fail("该管理员不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ HouseNumber houseNumber = houseNumberService.getById(dto.getHouseNumberId());
|
|
|
+ if (ObjectUtils.isEmpty(houseNumber)) {
|
|
|
+ return CommonResult.fail("该房间不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ UnlockingCustom unlockingAdmin = null;
|
|
|
+ /**
|
|
|
+ * 缺少人的名字和
|
|
|
+ */
|
|
|
+ try {
|
|
|
+
|
|
|
+ unlockingAdmin = passwordIssController.saveCustomPassWord(dto);
|
|
|
+ if (ObjectUtils.isEmpty(unlockingAdmin)) {
|
|
|
+ return CommonResult.fail("该密码已存在,请更换");
|
|
|
+ }
|
|
|
+
|
|
|
+ unlockingAdmin.setName(dto.getUserName());
|
|
|
+ unlockingAdmin.setPhone(dto.getPhone());
|
|
|
+
|
|
|
+// 添加操作记录
|
|
|
+
|
|
|
+ OperatingRecord operatingRecord = new OperatingRecord();
|
|
|
+ operatingRecord.setRoomNumber(houseNumber.getRoomNumber());
|
|
|
+ operatingRecord.setHouseNumberId(houseNumber.getId());
|
|
|
+ operatingRecord.setOperatorName(admin.getName());
|
|
|
+ DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ operatingRecord.setDataTime(LocalDateTime.now().format(dateTimeFormatter1));
|
|
|
+ operatingRecord.setContent("姓名:" + dto.getUserName());
|
|
|
+ operatingRecord.setType("添加密码钥匙");
|
|
|
+
|
|
|
+
|
|
|
+ unlockingCustomService.save(unlockingAdmin);
|
|
|
+ operatingRecordService.save(operatingRecord);
|
|
|
+ return CommonResult.ok();
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+// 删除锁
|
|
|
+ passwordIssController.deleteLockUser(unlockingAdmin.getLuid(),unlockingAdmin.getLockUserId());
|
|
|
+ return CommonResult.fail();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CommonResult saveCustomCard(CustomKeyCardDto dto) {
|
|
|
+ String permissionSettingId = dto.getPermissionSettingId();
|
|
|
+ PermissionSetting permissionSetting = permissionSettingService.getById(permissionSettingId);
|
|
|
+ if (ObjectUtils.isEmpty(permissionSetting)) {
|
|
|
+ return CommonResult.fail("非法进入");
|
|
|
+ }
|
|
|
+// 判断该用户是否拥有权限
|
|
|
+ String houseTypeManagement = permissionSetting.getDoorLockManagement();
|
|
|
+ if (!"0".equals(houseTypeManagement) && !houseTypeManagement.contains("11")) {
|
|
|
+ return CommonResult.fail("此账号暂无该权限");
|
|
|
+ }
|
|
|
+
|
|
|
+ Admin admin = adminService.getById(dto.getAdminId());
|
|
|
+ if (ObjectUtils.isEmpty(admin)) {
|
|
|
+ return CommonResult.fail("该管理员不存在");
|
|
|
+ }
|
|
|
+ HouseNumber houseNumber = houseNumberService.getById(dto.getHouseNumberId());
|
|
|
+ if (ObjectUtils.isEmpty(houseNumber)) {
|
|
|
+ return CommonResult.fail("该房间不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ UnlockingCustom unlockingAdmin = null;
|
|
|
+
|
|
|
+ try {
|
|
|
+ unlockingAdmin = passwordIssController.addCustomCard(dto);
|
|
|
+
|
|
|
+ unlockingAdmin.setName(dto.getUserName());
|
|
|
+ unlockingAdmin.setPhone(dto.getPhone());
|
|
|
+
|
|
|
+// 添加操作记录
|
|
|
+
|
|
|
+ OperatingRecord operatingRecord = new OperatingRecord();
|
|
|
+
|
|
|
+ operatingRecord.setHouseNumberId(houseNumber.getId());
|
|
|
+ operatingRecord.setRoomNumber(houseNumber.getRoomNumber());
|
|
|
+ operatingRecord.setOperatorName(admin.getName());
|
|
|
+ DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ operatingRecord.setDataTime(LocalDateTime.now().format(dateTimeFormatter1));
|
|
|
+ operatingRecord.setContent("姓名:" + dto.getUserName());
|
|
|
+ operatingRecord.setType("添加卡片钥匙");
|
|
|
+
|
|
|
+
|
|
|
+ unlockingCustomService.save(unlockingAdmin);
|
|
|
+ operatingRecordService.save(operatingRecord);
|
|
|
+ return CommonResult.ok();
|
|
|
+
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+// 删除锁
|
|
|
+ passwordIssController.deleteLockUser(unlockingAdmin.getLuid(),unlockingAdmin.getLockUserId());
|
|
|
+ return CommonResult.fail();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CommonResult saveCustomFingerprint(CustomKeyFingerprintDto dto) {
|
|
|
+ String permissionSettingId = dto.getPermissionSettingId();
|
|
|
+ PermissionSetting permissionSetting = permissionSettingService.getById(permissionSettingId);
|
|
|
+ if (ObjectUtils.isEmpty(permissionSetting)) {
|
|
|
+ return CommonResult.fail("非法进入");
|
|
|
+ }
|
|
|
+// 判断该用户是否拥有权限
|
|
|
+ String houseTypeManagement = permissionSetting.getDoorLockManagement();
|
|
|
+ if (!"0".equals(houseTypeManagement) && !houseTypeManagement.contains("11")) {
|
|
|
+ return CommonResult.fail("此账号暂无该权限");
|
|
|
+ }
|
|
|
+
|
|
|
+ Admin admin = adminService.getById(dto.getAdminId());
|
|
|
+ if (ObjectUtils.isEmpty(admin)) {
|
|
|
+ return CommonResult.fail("该管理员不存在");
|
|
|
+ }
|
|
|
+ HouseNumber houseNumber = houseNumberService.getById(dto.getHouseNumberId());
|
|
|
+ if (ObjectUtils.isEmpty(houseNumber)) {
|
|
|
+ return CommonResult.fail("该房间不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ UnlockingCustom unlockingAdmin = null;
|
|
|
+
|
|
|
+ try {
|
|
|
+ unlockingAdmin = passwordIssController.addCustomFingerprintDto(dto);
|
|
|
+
|
|
|
+ unlockingAdmin.setName(dto.getUserName());
|
|
|
+ unlockingAdmin.setPhone(dto.getPhone());
|
|
|
+
|
|
|
+// 添加操作记录
|
|
|
+
|
|
|
+ OperatingRecord operatingRecord = new OperatingRecord();
|
|
|
+ operatingRecord.setHouseNumberId(houseNumber.getId());
|
|
|
+ operatingRecord.setRoomNumber(houseNumber.getRoomNumber());
|
|
|
+ operatingRecord.setOperatorName(admin.getName());
|
|
|
+ DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ operatingRecord.setDataTime(LocalDateTime.now().format(dateTimeFormatter1));
|
|
|
+ operatingRecord.setContent("姓名:" + dto.getUserName());
|
|
|
+ operatingRecord.setType("添加指纹钥匙");
|
|
|
+
|
|
|
+
|
|
|
+ unlockingCustomService.save(unlockingAdmin);
|
|
|
+ operatingRecordService.save(operatingRecord);
|
|
|
+ return CommonResult.ok();
|
|
|
+
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+// 删除锁
|
|
|
+ passwordIssController.deleteLockUser(unlockingAdmin.getLuid(),unlockingAdmin.getLockUserId());
|
|
|
+ return CommonResult.fail();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|