| | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | |
| | | import com.talentcard.server.business.DatabaseRows; |
| | | import com.talentcard.server.business.merchant.auth.MerchantPasswordHasher; |
| | | import com.talentcard.server.common.BusinessException; |
| | |
| | | public Map<String, Object> login(AdminLoginRequest request, String requestId) { |
| | | String account = request.account().trim(); |
| | | List<Map<String, Object>> rows = rows(""" |
| | | select id operator_id, password_hash, display_name, role_code, status, |
| | | select o.id operator_id, o.password_hash, o.display_name, o.role_code, o.status, |
| | | r.permission_codes, |
| | | login_failed_count, locked_until |
| | | from admin_operator |
| | | where account = ? and deleted = 0 |
| | | from admin_operator o left join admin_role r on r.role_code = o.role_code |
| | | where o.account = ? and o.deleted = 0 |
| | | limit 1 |
| | | """, account); |
| | | if (rows.isEmpty()) { |
| | |
| | | Map<String, Object> result = new LinkedHashMap<>(); |
| | | result.put("accessToken", accessToken); |
| | | result.put("expiresIn", ACCESS_TOKEN_SECONDS); |
| | | result.put("operator", Map.of( |
| | | "id", number(operator.get("operatorId")), |
| | | "name", String.valueOf(operator.get("displayName")), |
| | | "roleCode", String.valueOf(operator.get("roleCode")))); |
| | | Map<String, Object> principal = new LinkedHashMap<>(); |
| | | principal.put("id", number(operator.get("operatorId"))); |
| | | principal.put("name", String.valueOf(operator.get("displayName"))); |
| | | principal.put("roleCode", String.valueOf(operator.get("roleCode"))); |
| | | principal.put("permissionCodes", permissions(operator)); |
| | | result.put("operator", principal); |
| | | return result; |
| | | } |
| | | |
| | | private List<String> permissions(Map<String, Object> operator) { |
| | | if ("platform_admin".equals(String.valueOf(operator.get("roleCode")))) return List.of("*"); |
| | | String raw = String.valueOf(operator.getOrDefault("permissionCodes", "")); |
| | | try { return JSON.parseArray(raw, String.class); } |
| | | catch (Exception ignored) { return List.of(); } |
| | | } |
| | | |
| | | private void audit(Long operatorId, String account, boolean success, String reason, String requestId) { |
| | | jdbc.update("insert into admin_login_audit(operator_id, account, success, failure_reason, request_id) values (?, ?, ?, ?, ?)", |
| | | operatorId, account, success ? 1 : 0, reason, requestId); |