|
|
@@ -13,7 +13,15 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.time.LocalDateTime;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Collections;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.Set;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
public class ServiceRoleApplicationServiceImpl
|
|
|
@@ -152,6 +160,98 @@ public class ServiceRoleApplicationServiceImpl
|
|
|
.orderByDesc(ServiceRoleApplication::getCreatedAt));
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<Map<String, Object>> listApplicationsWithUserInfo(Integer status, List<String> roleFilter) {
|
|
|
+ List<ServiceRoleApplication> apps = listApplications(status);
|
|
|
+ List<ServiceRoleApplication> filtered = new ArrayList<>();
|
|
|
+ boolean noFilter = roleFilter == null || roleFilter.isEmpty();
|
|
|
+ for (ServiceRoleApplication app : apps) {
|
|
|
+ if (noFilter || matchesAnyRole(app.getRoles(), roleFilter)) {
|
|
|
+ filtered.add(app);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Set<Long> userIds = filtered.stream()
|
|
|
+ .map(ServiceRoleApplication::getUserId)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+ Map<Long, User> userMap = new HashMap<>();
|
|
|
+ if (!userIds.isEmpty()) {
|
|
|
+ List<User> users = userMapper.selectBatchIds(userIds);
|
|
|
+ if (users != null) {
|
|
|
+ for (User u : users) {
|
|
|
+ userMap.put(u.getId(), u);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Map<String, Object>> result = new ArrayList<>();
|
|
|
+ for (ServiceRoleApplication app : filtered) {
|
|
|
+ Map<String, Object> row = new LinkedHashMap<>();
|
|
|
+ row.put("id", app.getId());
|
|
|
+ row.put("userId", app.getUserId());
|
|
|
+ row.put("roles", app.getRoles());
|
|
|
+ row.put("idCard", app.getIdCard());
|
|
|
+ row.put("idCardImages", app.getIdCardImages());
|
|
|
+ row.put("certificateImages", app.getCertificateImages());
|
|
|
+ row.put("province", app.getProvince());
|
|
|
+ row.put("city", app.getCity());
|
|
|
+ row.put("district", app.getDistrict());
|
|
|
+ row.put("street", app.getStreet());
|
|
|
+ row.put("addressDetail", app.getAddressDetail());
|
|
|
+ row.put("status", app.getStatus());
|
|
|
+ row.put("rejectReason", app.getRejectReason());
|
|
|
+ row.put("createdAt", app.getCreatedAt());
|
|
|
+ row.put("reviewedAt", app.getReviewedAt());
|
|
|
+ User u = userMap.get(app.getUserId());
|
|
|
+ row.put("userName", u != null ? (u.getNickname() != null ? u.getNickname() : u.getRealName()) : null);
|
|
|
+ row.put("realName", u != null ? u.getRealName() : null);
|
|
|
+ row.put("phone", u != null ? u.getPhone() : null);
|
|
|
+ result.add(row);
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解析前端传入的角色过滤参数(逗号分隔),null/空白返回空列表。
|
|
|
+ */
|
|
|
+ public static List<String> parseRoleFilter(String roleParam) {
|
|
|
+ if (roleParam == null || roleParam.trim().isEmpty()) {
|
|
|
+ return Collections.emptyList();
|
|
|
+ }
|
|
|
+ List<String> roles = new ArrayList<>();
|
|
|
+ for (String part : roleParam.split(",")) {
|
|
|
+ String role = part.trim();
|
|
|
+ if (!role.isEmpty() && !roles.contains(role)) {
|
|
|
+ roles.add(role);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return roles;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断申请记录的角色 JSON 数组是否与目标角色有交集;解析失败按不匹配处理。
|
|
|
+ */
|
|
|
+ public static boolean matchesAnyRole(String rolesJson, List<String> targetRoles) {
|
|
|
+ if (rolesJson == null || targetRoles == null || targetRoles.isEmpty()) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ List<String> roles = JSON.parseArray(rolesJson, String.class);
|
|
|
+ if (roles == null) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ for (String role : roles) {
|
|
|
+ if (targetRoles.contains(role)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ } catch (Exception e) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public Result reject(Long id, String reason, Long reviewerId) {
|