|
|
@@ -0,0 +1,333 @@
|
|
|
+package com.template.controller;
|
|
|
+
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
+import com.template.api.UnlockingEmployeeControllerAPI;
|
|
|
+import com.template.common.utils.PasswordChecker;
|
|
|
+import com.template.common.utils.TimeExchange;
|
|
|
+import com.template.model.dto.*;
|
|
|
+import com.template.model.pojo.*;
|
|
|
+import com.template.model.result.CommonResult;
|
|
|
+import com.template.services.*;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 员工添加钥匙 前端控制器
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author ceshi
|
|
|
+ * @since 2024-08-12
|
|
|
+ */
|
|
|
+@RestController
|
|
|
+public class UnlockingEmployeeController implements UnlockingEmployeeControllerAPI {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ UnlockingEmployeeService unlockingEmployeeService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ PermissionSettingService permissionSettingService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ AdminService adminService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ EmployeeUsersService employeeUsersService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ HouseNumberService houseNumberService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ OperatingRecordService operatingRecordService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ PasswordIssController passwordIssController;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public CommonResult savePassWord(KeyPassWordDto keyPassWordDto) {
|
|
|
+ String permissionSettingId = keyPassWordDto.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 = keyPassWordDto.getPassWord();
|
|
|
+ if (!PasswordChecker.isValidPassword(passWord)) {
|
|
|
+ return CommonResult.fail("密码长度的一半不能是连续升序、倒序、一样的数字");
|
|
|
+ }
|
|
|
+
|
|
|
+ Admin admin = adminService.getById(keyPassWordDto.getAdminId());
|
|
|
+ if (ObjectUtils.isEmpty(admin)) {
|
|
|
+ return CommonResult.fail("该管理员不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ EmployeeUsers byId = employeeUsersService.getById(keyPassWordDto.getUsersId());
|
|
|
+ if (ObjectUtils.isEmpty(admin)) {
|
|
|
+ return CommonResult.fail("添加的用户不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ HouseNumber houseNumber = houseNumberService.getById(keyPassWordDto.getHouseNumberId());
|
|
|
+ if (ObjectUtils.isEmpty(houseNumber)) {
|
|
|
+ return CommonResult.fail("该房间不存在");
|
|
|
+ }
|
|
|
+// String usersId = keyPassWordDto.getUsersId();
|
|
|
+// Users byId = usersService.getById(usersId);
|
|
|
+// if (ObjectUtils.isEmpty(byId)) {
|
|
|
+// return CommonResult.fail("无该用户");
|
|
|
+// }
|
|
|
+ UnlockingAdmin unlockingAdmin = null;
|
|
|
+ UnlockingEmployee unlockingEmployee = new UnlockingEmployee();
|
|
|
+ /**
|
|
|
+ * 缺少人的名字和
|
|
|
+ */
|
|
|
+ try {
|
|
|
+
|
|
|
+ unlockingAdmin = passwordIssController.savePassWord(keyPassWordDto);
|
|
|
+ if (ObjectUtils.isEmpty(unlockingAdmin)) {
|
|
|
+ return CommonResult.fail("该密码已存在,请更换");
|
|
|
+ }
|
|
|
+
|
|
|
+ unlockingAdmin.setName(byId.getUserName());
|
|
|
+ unlockingAdmin.setPhone(byId.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("姓名:" + byId.getUserName());
|
|
|
+ operatingRecord.setType("添加员工密码钥匙");
|
|
|
+
|
|
|
+ BeanUtils.copyProperties(unlockingAdmin,unlockingEmployee);
|
|
|
+ unlockingEmployeeService.save(unlockingEmployee);
|
|
|
+ operatingRecordService.save(operatingRecord);
|
|
|
+ return CommonResult.ok();
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+// 删除锁
|
|
|
+ passwordIssController.deleteLockUser(unlockingAdmin.getLuid(),unlockingAdmin.getLockUserId());
|
|
|
+ return CommonResult.fail();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public CommonResult saveCard(KeyCardEmpDto keyCardDto) {
|
|
|
+ String permissionSettingId = keyCardDto.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(keyCardDto.getAdminId());
|
|
|
+ if (ObjectUtils.isEmpty(admin)) {
|
|
|
+ return CommonResult.fail("该管理员不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ EmployeeUsers byId = employeeUsersService.getById(keyCardDto.getUsersId());
|
|
|
+ if (ObjectUtils.isEmpty(admin)) {
|
|
|
+ return CommonResult.fail("添加的员工不存在");
|
|
|
+ }
|
|
|
+ //没传卡片id则使用用户信息身份证
|
|
|
+ if(!StringUtils.hasText(keyCardDto.getCard())){
|
|
|
+ if (!StringUtils.hasText(byId.getIdCardInformation())){
|
|
|
+ return CommonResult.fail("该员工没有卡片信息");
|
|
|
+ }else{
|
|
|
+ keyCardDto.setCard(byId.getIdCardInformation());
|
|
|
+ keyCardDto.setCardType(1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ HouseNumber houseNumber = houseNumberService.getById(keyCardDto.getHouseNumberId());
|
|
|
+ if (ObjectUtils.isEmpty(houseNumber)) {
|
|
|
+ return CommonResult.fail("该房间不存在");
|
|
|
+ }
|
|
|
+// String usersId = keyCardDto.getUsersId();
|
|
|
+// Users byId = usersService.getById(usersId);
|
|
|
+// if (ObjectUtils.isEmpty(byId)) {
|
|
|
+// return CommonResult.fail("无该用户");
|
|
|
+// }
|
|
|
+
|
|
|
+ UnlockingAdmin unlockingAdmin = null;
|
|
|
+ UnlockingEmployee unlockingEmployee = new UnlockingEmployee();
|
|
|
+
|
|
|
+ try {
|
|
|
+ KeyCardDto keyCardDto1=new KeyCardDto();
|
|
|
+ BeanUtils.copyProperties(keyCardDto,keyCardDto1);
|
|
|
+ unlockingAdmin = passwordIssController.addCard(keyCardDto1);
|
|
|
+
|
|
|
+ unlockingAdmin.setName(byId.getUserName());
|
|
|
+ unlockingAdmin.setPhone(byId.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("姓名:" + byId.getUserName());
|
|
|
+ operatingRecord.setType("添加员工卡片钥匙");
|
|
|
+
|
|
|
+ BeanUtils.copyProperties(unlockingAdmin,unlockingEmployee);
|
|
|
+ unlockingEmployeeService.save(unlockingEmployee);
|
|
|
+ operatingRecordService.save(operatingRecord);
|
|
|
+ return CommonResult.ok();
|
|
|
+
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+// 删除锁
|
|
|
+ passwordIssController.deleteLockUser(unlockingAdmin.getLuid(),unlockingAdmin.getLockUserId());
|
|
|
+ return CommonResult.fail();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public CommonResult saveFingerprint(KeyFingerprintEmpDto keyFingerprintEmpDto) {
|
|
|
+ String permissionSettingId = keyFingerprintEmpDto.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(keyFingerprintEmpDto.getAdminId());
|
|
|
+ if (ObjectUtils.isEmpty(admin)) {
|
|
|
+ return CommonResult.fail("该管理员不存在");
|
|
|
+ }
|
|
|
+ EmployeeUsers byId = employeeUsersService.getById(keyFingerprintEmpDto.getUsersId());
|
|
|
+ if (ObjectUtils.isEmpty(admin)) {
|
|
|
+ return CommonResult.fail("添加的用户不存在");
|
|
|
+ }
|
|
|
+ KeyFingerprintDto keyFingerprintDto = new KeyFingerprintDto();
|
|
|
+ if (!StringUtils.hasText(byId.getFingerprint())){
|
|
|
+ return CommonResult.fail("缺少指纹,请前往员工管理添加该员工指纹");
|
|
|
+ }else{
|
|
|
+ keyFingerprintDto.setFingerprintData(byId.getFingerprint());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ HouseNumber houseNumber = houseNumberService.getById(keyFingerprintEmpDto.getHouseNumberId());
|
|
|
+ if (ObjectUtils.isEmpty(houseNumber)) {
|
|
|
+ return CommonResult.fail("该房间不存在");
|
|
|
+ }
|
|
|
+// String usersId = keyFingerprintDto.getUsersId();
|
|
|
+// Users byId = usersService.getById(usersId);
|
|
|
+// if (ObjectUtils.isEmpty(byId)) {
|
|
|
+// return CommonResult.fail("无该用户");
|
|
|
+// }
|
|
|
+
|
|
|
+ UnlockingAdmin unlockingAdmin = null;
|
|
|
+ UnlockingEmployee unlockingEmployee = new UnlockingEmployee();
|
|
|
+ try {
|
|
|
+
|
|
|
+ BeanUtils.copyProperties(keyFingerprintEmpDto,keyFingerprintDto);
|
|
|
+ unlockingAdmin = passwordIssController.addFingerprintDto(keyFingerprintDto);
|
|
|
+
|
|
|
+ unlockingAdmin.setName(byId.getUserName());
|
|
|
+ unlockingAdmin.setPhone(byId.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("姓名:" + byId.getUserName());
|
|
|
+ operatingRecord.setType("添加员工指纹钥匙");
|
|
|
+
|
|
|
+
|
|
|
+ BeanUtils.copyProperties(unlockingAdmin,unlockingEmployee);
|
|
|
+ unlockingEmployeeService.save(unlockingEmployee);
|
|
|
+ operatingRecordService.save(operatingRecord);
|
|
|
+ return CommonResult.ok();
|
|
|
+
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+// 删除锁
|
|
|
+ passwordIssController.deleteLockUser(unlockingAdmin.getLuid(),unlockingAdmin.getLockUserId());
|
|
|
+ return CommonResult.fail();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CommonResult deleteLock(Integer unlockingEmpId) {
|
|
|
+ UnlockingEmployee byId = unlockingEmployeeService.getById(unlockingEmpId);
|
|
|
+ if (ObjectUtils.isEmpty(byId)) {
|
|
|
+ return CommonResult.fail("不存在该记录");
|
|
|
+ }
|
|
|
+
|
|
|
+ String lockUserId = byId.getLockUserId();
|
|
|
+ String luid = byId.getLuid();
|
|
|
+
|
|
|
+ passwordIssController.deleteLockUser(luid,lockUserId);
|
|
|
+
|
|
|
+ unlockingEmployeeService.removeById(unlockingEmpId);
|
|
|
+
|
|
|
+ return CommonResult.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public CommonResult updateLock(UpdateLockDto updateLockDto) {
|
|
|
+ UnlockingEmployee byId = unlockingEmployeeService.getById(updateLockDto.getUnlockingAdminId());
|
|
|
+ if (ObjectUtils.isEmpty(byId)) {
|
|
|
+ return CommonResult.fail("不存在该记录");
|
|
|
+ }
|
|
|
+
|
|
|
+ String lockStatus = byId.getLockStatus();
|
|
|
+ if (!"1".equals(lockStatus)) {
|
|
|
+ return CommonResult.fail("只有密码用户才能修改时效");
|
|
|
+ }
|
|
|
+ String lockUserId = byId.getLockUserId();
|
|
|
+ String luid = byId.getLuid();
|
|
|
+ String startTime = updateLockDto.getStartTime();
|
|
|
+ String endTime = updateLockDto.getEndTime();
|
|
|
+
|
|
|
+ passwordIssController.updateLock(lockUserId,luid,startTime,endTime);
|
|
|
+
|
|
|
+ byId.setStartTime(startTime);
|
|
|
+ byId.setEndTime(endTime);
|
|
|
+
|
|
|
+ unlockingEmployeeService.updateById(byId);
|
|
|
+
|
|
|
+ return CommonResult.ok();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|