package com.talentcard.server.business.portal;
|
|
import java.util.LinkedHashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
import com.talentcard.server.business.DatabaseRows;
|
import com.talentcard.server.common.BusinessException;
|
import com.talentcard.server.common.ErrorCode;
|
import org.springframework.jdbc.core.JdbcTemplate;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
@Service
|
public class ProcessingApplicationPortalService {
|
private final JdbcTemplate jdbc;
|
public ProcessingApplicationPortalService(JdbcTemplate jdbc) { this.jdbc = jdbc; }
|
|
@Transactional(readOnly = true)
|
public Map<String, Object> detail(String applicationNo, Long talentId) {
|
List<Map<String, Object>> rows = jdbc.queryForList("""
|
select s.application_no, s.application_type, s.status, s.submitted_at, s.expected_time,
|
s.merchant_name, s.hospital_name, s.parking_lot, s.product_name, s.package_name,
|
s.contact_mobile, s.reject_reason,
|
m.address as institution_address_snapshot, m.latitude as institution_latitude_snapshot,
|
m.longitude as institution_longitude_snapshot, (
|
select c.card_level from talent_card c
|
where c.talent_id = ? and c.card_no = s.card_no and c.deleted = 0
|
order by c.id desc limit 1
|
) as card_level_snapshot
|
from service_application s
|
left join merchant m on m.merchant_name = s.merchant_name and m.deleted = 0
|
where s.deleted = 0 and s.application_no = ?
|
and exists (select 1 from talent_card c where c.talent_id = ? and c.card_no = s.card_no and c.deleted = 0)
|
""", talentId, applicationNo, talentId).stream().map(DatabaseRows::normalize).toList();
|
if (rows.isEmpty()) throw new BusinessException(ErrorCode.NOT_FOUND, "预约记录不存在或无权查看");
|
Map<String, Object> row = rows.get(0);
|
Map<String, Object> result = new LinkedHashMap<>(row);
|
String status = string(row.get("status"));
|
String nextAction = nextAction(status);
|
result.put("nextAction", nextAction);
|
result.put("statusTitle", switch (nextAction) { case "completed" -> "已处理"; case "cancelled" -> "已取消"; default -> "待处理"; });
|
result.put("statusDescription", switch (nextAction) { case "completed" -> "专员已完成处理"; case "cancelled" -> string(row.get("rejectReason")).isBlank() ? "该预约已取消" : string(row.get("rejectReason")); default -> "等待专员处理"; });
|
result.put("institutionName", first(row.get("hospitalName"), row.get("merchantName"), row.get("parkingLot"), "人才服务机构"));
|
result.put("appointmentContent", first(row.get("productName"), row.get("packageName"), row.get("applicationType"), "服务预约"));
|
result.put("appointmentTime", first(row.get("expectedTime"), "以专员通知为准"));
|
result.put("advisor", advisor(talentId, string(row.get("cardLevelSnapshot"))));
|
return result;
|
}
|
|
private Map<String, Object> advisor(Long talentId, String cardLevel) {
|
List<Map<String, Object>> assignedStaff = jdbc.queryForList("""
|
select operator.display_name, operator.position_name, operator.mobile
|
from talent_user talent
|
join admin_operator operator on operator.id = talent.service_staff_id
|
and operator.deleted = 0 and operator.status = 1
|
where talent.id = ? and talent.deleted = 0
|
limit 1
|
""", talentId).stream().map(DatabaseRows::normalize).toList();
|
if (!assignedStaff.isEmpty()) {
|
Map<String, Object> row = assignedStaff.get(0);
|
Map<String, Object> result = new LinkedHashMap<>();
|
result.put("name", row.get("displayName"));
|
result.put("department", row.get("positionName"));
|
result.put("mobile", row.get("mobile"));
|
result.put("consultUrl", "");
|
return result;
|
}
|
|
List<Map<String, Object>> rows = jdbc.queryForList("""
|
select advisor_name, department, mobile, consult_url
|
from talent_card_advisor where card_level = ? and status = 1 limit 1
|
""", cardLevel).stream().map(DatabaseRows::normalize).toList();
|
if (rows.isEmpty()) return Map.of();
|
Map<String, Object> row = rows.get(0);
|
Map<String, Object> result = new LinkedHashMap<>();
|
result.put("name", row.get("advisorName"));
|
result.put("department", row.get("department"));
|
result.put("mobile", row.get("mobile"));
|
result.put("consultUrl", row.get("consultUrl"));
|
return result;
|
}
|
|
private String nextAction(String status) {
|
if ("已处理".equals(status) || "已完成".equals(status)) return "completed";
|
if ("已驳回".equals(status) || "已取消".equals(status)) return "cancelled";
|
return "processing";
|
}
|
private String first(Object... values) { for (Object value : values) { String text = string(value); if (!text.isBlank()) return text; } return ""; }
|
private String string(Object value) { return value == null ? "" : String.valueOf(value); }
|
}
|