shinnosuke
2026-07-31 82141e1b9e46a154418295aa95b34cb842c001c3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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 ShoppingMerchantPortalService {
    private final JdbcTemplate jdbc;
 
    public ShoppingMerchantPortalService(JdbcTemplate jdbc) {
        this.jdbc = jdbc;
    }
 
    @Transactional(readOnly = true)
    public Map<String, Object> detail(Long merchantId) {
        Map<String, Object> row = one("""
                select m.id, m.merchant_name, m.cover_url, m.service_label, m.address, m.contact_mobile,
                       m.longitude, m.latitude, m.status as merchant_status, mapping.category_key,
                       detail_config.talent_levels, detail_config.benefit_detail, detail_config.advisor_id,
                       detail_config.advisor_name, detail_config.advisor_department, detail_config.advisor_mobile,
                       detail_config.advisor_service_time, detail_config.advisor_available,
                       detail_config.unavailable_reason, detail_config.status as detail_status
                from merchant m
                join shopping_topic_merchant mapping on mapping.merchant_id = m.id and mapping.deleted = 0
                join shopping_service_detail detail_config on detail_config.merchant_id = m.id and detail_config.deleted = 0
                where m.id = ? and m.merchant_type = 'shopping' and m.deleted = 0
                order by detail_config.id asc limit 1
                """, merchantId);
        boolean available = number(row.get("merchantStatus")) == 1 && number(row.get("detailStatus")) == 1;
        Map<String, Object> result = new LinkedHashMap<>();
        result.put("merchantId", row.get("id"));
        result.put("categoryId", row.get("categoryKey"));
        result.put("merchantName", row.get("merchantName"));
        result.put("coverUrl", row.get("coverUrl"));
        result.put("discountText", text(row.get("serviceLabel"), "请咨询服务专员"));
        result.put("applicableCards", text(row.get("talentLevels"), "请咨询服务专员"));
        result.put("address", text(row.get("address"), "请咨询服务专员"));
        result.put("contactMobile", text(row.get("contactMobile"), ""));
        result.put("longitude", row.get("longitude"));
        result.put("latitude", row.get("latitude"));
        result.put("benefitDetail", text(row.get("benefitDetail"), "以服务专员说明为准"));
        result.put("available", available);
        result.put("unavailableReason", available ? "" : text(row.get("unavailableReason"), "该购物服务当前不可用"));
        Map<String, Object> advisor = new LinkedHashMap<>();
        advisor.put("advisorId", row.get("advisorId"));
        advisor.put("name", text(row.get("advisorName"), ""));
        advisor.put("department", text(row.get("advisorDepartment"), ""));
        advisor.put("mobile", text(row.get("advisorMobile"), ""));
        advisor.put("serviceTime", text(row.get("advisorServiceTime"), ""));
        advisor.put("available", number(row.get("advisorAvailable")) == 1 && !text(row.get("advisorMobile"), "").isEmpty());
        result.put("advisor", advisor);
        return result;
    }
 
    private Map<String, Object> one(String sql, Object... args) {
        List<Map<String, Object>> rows = jdbc.queryForList(sql, args).stream().map(DatabaseRows::normalize).toList();
        if (rows.isEmpty()) throw new BusinessException(ErrorCode.NOT_FOUND, "购物服务详情不存在");
        return rows.get(0);
    }
 
    private int number(Object value) {
        return value instanceof Number number ? number.intValue() : 0;
    }
 
    private String text(Object value, String fallback) {
        if (value == null) return fallback;
        String text = String.valueOf(value).trim();
        return text.isEmpty() ? fallback : text;
    }
}