修复门禁:统一授权状态机与注销入口

This commit is contained in:
wangzhibiao committed 2026-09-21 12:50:58 +08:00
1 parent ec3a7afe46
commit a83a3a642e
9 files changed
+74 -134

No files matched your search

@@ -38,7 +38,7 @@ public class TrainDormAuthController extends BaseController
/**
* 查询宿舍权限分配列表
*/
@PreAuthorize("@ss.hasPermi('system:auth:list')")
@PreAuthorize("@ss.hasPermi('train:access:query') or @ss.hasPermi('system:auth:list')")
@GetMapping("/list")
public TableDataInfo list(TrainDormAuth trainDormAuth)
{
@@ -80,61 +80,8 @@ public class TrainDormAuthController extends BaseController
return success(trainDormAuthService.selectTrainDormAuthByAccommodationId(accommodationId));
}
/**
* 新增宿舍权限分配
*/
@PreAuthorize("@ss.hasPermi('system:auth:add')")
@Log(title = "宿舍权限分配", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody TrainDormAuth trainDormAuth)
{
trainDormAuth.setCreateBy(getUsernameSafe());
return toAjax(trainDormAuthService.insertTrainDormAuth(trainDormAuth));
}
/**
* 修改宿舍权限分配
*/
@PreAuthorize("@ss.hasPermi('system:auth:edit')")
@Log(title = "宿舍权限分配", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody TrainDormAuth trainDormAuth)
{
trainDormAuth.setUpdateBy(getUsernameSafe());
return toAjax(trainDormAuthService.updateTrainDormAuth(trainDormAuth));
}
/**
* 注销宿舍权限分配
*/
@PreAuthorize("@ss.hasPermi('system:auth:edit')")
@Log(title = "宿舍权限分配-注销", businessType = BusinessType.UPDATE)
@PostMapping("/{authId}/revoke")
public AjaxResult revoke(@PathVariable("authId") Long authId)
{
return toAjax(trainDormAuthService.revokeAuth(authId, getUsernameSafe()));
}
/**
* 删除宿舍权限分配
*/
@PreAuthorize("@ss.hasPermi('system:auth:remove')")
@Log(title = "宿舍权限分配", businessType = BusinessType.DELETE)
@DeleteMapping("/{authIds}")
public AjaxResult remove(@PathVariable Long[] authIds)
{
return toAjax(trainDormAuthService.deleteTrainDormAuthByAuthIds(authIds));
}
private String getUsernameSafe()
{
try
{
return SecurityUtils.getUsername();
}
catch (Exception e)
{
return "admin";
}
}
// 注意:Package A 架构整改:门禁授权的所有写操作(新增、修改、下发凭据、注销、删除)
// 统一收归到 TrainAccessManagementController -> AccessAuthorizationOrchestrator -> DMS 权威调用链。
// TrainDormAuthController 仅保留纯读取端点(list, export, getInfo, getInfoByAccommodationId)。
}
@@ -2,6 +2,7 @@ package com.ruoyi.web.controller.train;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import java.lang.reflect.Method;
import org.junit.Test;
@@ -116,15 +117,26 @@ public class AccommodationAndAuthApiControllerContractTest
assertEquals("/accommodation/{accommodationId}", accInfoMethod.getAnnotation(GetMapping.class).value()[0]);
assertEquals("@ss.hasPermi('system:auth:query')", accInfoMethod.getAnnotation(PreAuthorize.class).value());
// 4. POST /train/auth
Method addMethod = clazz.getMethod("add", TrainDormAuth.class);
assertNotNull(addMethod.getAnnotation(PostMapping.class));
assertEquals("@ss.hasPermi('system:auth:add')", addMethod.getAnnotation(PreAuthorize.class).value());
// 4. 验证 Package A 安全架构:TrainDormAuthController 彻底移除写端点 (add, edit, revoke, remove)
try {
clazz.getMethod("add", TrainDormAuth.class);
fail("TrainDormAuthController 不得存在 POST add 写端点");
} catch (NoSuchMethodException expected) {}
// 5. POST /train/auth/{authId}/revoke
Method revokeMethod = clazz.getMethod("revoke", Long.class);
assertNotNull(revokeMethod.getAnnotation(PostMapping.class));
assertEquals("/{authId}/revoke", revokeMethod.getAnnotation(PostMapping.class).value()[0]);
assertEquals("@ss.hasPermi('system:auth:edit')", revokeMethod.getAnnotation(PreAuthorize.class).value());
try {
clazz.getMethod("edit", TrainDormAuth.class);
fail("TrainDormAuthController 不得存在 PUT edit 写端点");
} catch (NoSuchMethodException expected) {}
try {
clazz.getMethod("revoke", Long.class);
fail("TrainDormAuthController 不得存在 POST revoke 写端点");
} catch (NoSuchMethodException expected) {}
try {
clazz.getMethod("remove", Long[].class);
fail("TrainDormAuthController 不得存在 DELETE remove 写端点");
} catch (NoSuchMethodException expected) {}
}
}
@@ -258,12 +258,12 @@ public class PreCustomerStabilizationFinalFixesContractTest
assertNotNull(accPre);
assertEquals("@ss.hasPermi('train:accommodation:remove')", accPre.value());
// 门禁撤销
Method authRevoke = TrainDormAuthController.class.getMethod("revoke", Long.class);
assertNotNull(authRevoke);
PreAuthorize authRevokePre = authRevoke.getAnnotation(PreAuthorize.class);
assertNotNull(authRevokePre);
assertEquals("@ss.hasPermi('system:auth:edit')", authRevokePre.value());
// 门禁撤销:TrainDormAuthController 彻底移除写接口 revoke,收归至 TrainAccessManagementController
try {
TrainDormAuthController.class.getMethod("revoke", Long.class);
fail("TrainDormAuthController 不得存在 revoke 写接口");
} catch (NoSuchMethodException expected) {}
// 成绩删除
Method scoreRemove = TrainScoreInfoController.class.getMethod("remove", Long[].class);
@@ -103,6 +103,9 @@ public class TrainDormAuth extends BaseEntity
/** 学员姓名 (非物理列,联表自 train_student) */
private String studentName;
/** 学员联系电话 (非物理列,联表自 train_student) */
private String studentPhone;
/** 开班计划ID (非物理列,联表自 train_enrollment) */
private String planId;
@@ -405,6 +408,16 @@ public class TrainDormAuth extends BaseEntity
}
}
public String getStudentPhone()
{
return studentPhone;
}
public void setStudentPhone(String studentPhone)
{
this.studentPhone = studentPhone;
}
@Override
public String toString()
{
@@ -83,6 +83,14 @@ public interface TrainDormAuthMapper
@Param("updateBy") String updateBy,
@Param("updateTime") Date updateTime);
/**
* 成功推进状态后清空历史错误信息
*
* @param authId 授权主键
* @return 影响行数
*/
public int clearLastError(@Param("authId") Long authId);
/**
* 删除宿舍门禁授权
*
@@ -61,14 +61,6 @@ public interface ITrainDormAuthService
*/
public int markSyncFailed(Long authId, String errorMessage, String operator);
/**
* 注销门禁授权
*
* @param authId 授权主键
* @param operator 操作人
* @return 结果
*/
public int revokeAuth(Long authId, String operator);
/**
* 批量删除宿舍门禁授权
@@ -159,23 +159,6 @@ public class TrainDormAuthServiceImpl implements ITrainDormAuthService
return trainDormAuthMapper.increaseRetryCount(authId, errorMessage, operator, DateUtils.getNowDate());
}
/**
* 注销门禁授权
*
* @param authId 授权主键
* @param operator 操作人
* @return 结果
*/
@Override
public int revokeAuth(Long authId, String operator)
{
TrainDormAuth exist = trainDormAuthMapper.selectTrainDormAuthByAuthId(authId);
if (exist == null)
{
throw new ServiceException("门禁授权记录不存在: " + authId);
}
return trainDormAuthMapper.updateSyncStatus(authId, TrainDormAuth.STATUS_REVOKED, null, operator, DateUtils.getNowDate());
}
/**
* 批量删除宿舍门禁授权
@@ -303,7 +286,12 @@ public class TrainDormAuthServiceImpl implements ITrainDormAuthService
exist.setOperationVersion((exist.getOperationVersion() != null ? exist.getOperationVersion() : 1) + 1);
exist.setUpdateBy(operator);
exist.setUpdateTime(DateUtils.getNowDate());
return trainDormAuthMapper.updateTrainDormAuth(exist);
int rows = trainDormAuthMapper.updateTrainDormAuth(exist);
if (rows > 0 && (TrainDormAuth.AUTH_STATUS_ACTIVE.equals(authStatus) || TrainDormAuth.AUTH_STATUS_REVOKED.equals(authStatus)))
{
trainDormAuthMapper.clearLastError(authId);
}
return rows;
}
@Override
@@ -331,6 +319,11 @@ public class TrainDormAuthServiceImpl implements ITrainDormAuthService
}
exist.setUpdateBy(operator != null ? operator : "DmsPoller");
exist.setUpdateTime(DateUtils.getNowDate());
return trainDormAuthMapper.updateTrainDormAuth(exist);
int rows = trainDormAuthMapper.updateTrainDormAuth(exist);
if (rows > 0 && lastError == null && (TrainDormAuth.AUTH_STATUS_ACTIVE.equals(authStatus) || TrainDormAuth.AUTH_STATUS_REVOKED.equals(authStatus)))
{
trainDormAuthMapper.clearLastError(authId);
}
return rows;
}
}
@@ -21,6 +21,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="remark" column="remark" />
<result property="studentId" column="student_id" />
<result property="studentName" column="student_name" />
<result property="studentPhone" column="student_phone" />
<result property="planId" column="plan_id" />
<result property="planName" column="plan_name" />
<result property="dormId" column="dorm_id" />
@@ -60,6 +61,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
acc.bed_no,
e.student_id,
s.s_name AS student_name,
s.s_phone AS student_phone,
e.plan_id,
p.plan_name,
d.dorm_building,
@@ -211,6 +213,13 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
WHERE auth_id = #{authId}
</update>
<update id="clearLastError">
UPDATE train_dorm_auth
SET last_error = NULL,
update_time = CURRENT_TIMESTAMP
WHERE auth_id = #{authId}
</update>
<delete id="deleteTrainDormAuthByAuthId" parameterType="Long">
DELETE FROM train_dorm_auth WHERE auth_id = #{authId}
</delete>
-34
View File
@@ -16,37 +16,3 @@ export function getAuth(authId) {
method: 'get'
})
}
// 新增宿舍权限分配
export function addAuth(data) {
return request({
url: '/train/auth',
method: 'post',
data: data
})
}
// 修改宿舍权限分配
export function updateAuth(data) {
return request({
url: '/train/auth',
method: 'put',
data: data
})
}
// 删除宿舍权限分配
export function delAuth(authId) {
return request({
url: '/train/auth/' + authId,
method: 'delete'
})
}
// 注销门禁授权
export function revokeAuth(authId) {
return request({
url: '/train/auth/' + authId + '/revoke',
method: 'post'
})
}