提交代码实现v1.0

This commit is contained in:
wh
2026-04-27 10:27:57 +08:00
parent 849e78658d
commit 5662c1fda9
67 changed files with 2343 additions and 5 deletions

View File

@@ -1,15 +1,21 @@
package com.labelsys.backend.service;
import com.labelsys.backend.context.LoginUser;
import com.labelsys.backend.entity.BizDataRecord;
import com.labelsys.backend.enums.UserRole;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.jdbc.core.JdbcTemplate;
@Service
@RequiredArgsConstructor
public class DataPermissionService {
private final JdbcTemplate jdbcTemplate;
public boolean canAccessCreator(LoginUser currentUser, Long creatorId, UserRole creatorRole) {
return switch (currentUser.role()) {
case EMPLOYEE -> currentUser.userId().equals(creatorId);
@@ -65,4 +71,25 @@ public class DataPermissionService {
public boolean shouldFilterByUserId(LoginUser currentUser) {
return currentUser.role() == UserRole.EMPLOYEE;
}
public List<BizDataRecord> listVisibleRecords(LoginUser currentUser) {
List<BizDataRecord> allRecords = jdbcTemplate.query("""
select id, company_id, creator_id, creator_role, record_name, created_at, updated_at
from biz_data_record
where company_id = ?
order by id
""",
(rs, rowNum) -> BizDataRecord.builder()
.id(rs.getLong("id"))
.companyId(rs.getLong("company_id"))
.creatorId(rs.getLong("creator_id"))
.creatorRole(UserRole.valueOf(rs.getString("creator_role")))
.recordName(rs.getString("record_name"))
.createdAt(rs.getTimestamp("created_at") == null ? null : rs.getTimestamp("created_at").toLocalDateTime())
.updatedAt(rs.getTimestamp("updated_at") == null ? null : rs.getTimestamp("updated_at").toLocalDateTime())
.build(),
currentUser.companyId());
return filterByRole(currentUser, allRecords, BizDataRecord::getCreatorRole, BizDataRecord::getCreatorId);
}
}