# SalesKpiConfigInternalController.java

    package cloud.wconnect.workperformance.controller.saleskpi.config;

    import cloud.wconnect.commonlib.controller.BaseInternalController;
    import cloud.wconnect.commonlib.service.PropertyInternalService;
    import cloud.wconnect.commonlib.util.JsonUtils;
    import cloud.wconnect.workperformance.entity.saleskpi.SalesKpiMonthlyConfig;
    import cloud.wconnect.workperformance.pojo.dto.saleskpi.config.SalesConfigCrawlDTO;
    import cloud.wconnect.workperformance.service.saleskpi.ISalesKpiConfigService;
    import cloud.wconnect.workperformance.service.saleskpi.ISalesKpiMonthlyConfigService;
    import com.fasterxml.jackson.databind.ObjectMapper;
    import jakarta.annotation.Resource;
    import org.apache.commons.compress.utils.Lists;
    import org.apache.commons.lang3.StringUtils;
    import org.springframework.beans.factory.annotation.Value;
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.RequestHeader;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RestController;

    import java.util.List;
    import java.util.Map;
    import java.util.Objects;
    import java.util.stream.Collectors;
    import java.util.stream.Stream;

    /**
     * Controller：Sales KPI Config Internal
     *
     * @author zc
     * @date 2023/09/07
     */
    @RestController
    @RequestMapping("/internal/sales-kpi/config")
    public class SalesKpiConfigInternalController extends BaseInternalController {

        @Resource
        private ISalesKpiConfigService salesKpiConfigService;
        @Resource
        private ISalesKpiMonthlyConfigService salesKpiMonthlyConfigService;
        @Resource
        private PropertyInternalService propertyInternalService;
        @Resource
        private ObjectMapper objectMapper;

        @Value("${internal.service.auth-key.basic}")
        private String authKey;

        /**
         * 获取 Sales 配置
         *
         * @param tenant   租户标识
         * @param property 资产标识
         * @param sign     签名
         * @return SalesConfigCrawlDTO 集合
         * @author zc
         * @date 2023/9/7
         */
        @GetMapping
        public List<SalesConfigCrawlDTO> listConfigForCrawl(String tenant, String property, @RequestHeader String sign) {
            // 校验签名
            checkIntranetParams(authKey, sign, tenant, property);

            int propertyId = propertyInternalService.getOne(property, tenant).getId();

            // 获取基本指标配置数据
            Map<Integer, String> itemId2DataSource = salesKpiMonthlyConfigService.getMonthlyConfigs(propertyId,
                            SalesKpiMonthlyConfig.TYPE_GENERAL, Boolean.FALSE).stream()
                    .collect(Collectors.toMap(SalesKpiMonthlyConfig::getId, SalesKpiMonthlyConfig::getDataSource));

            return salesKpiConfigService.listConfigs(propertyId, Boolean.TRUE).stream().map(item -> {
                List<String> hiddenItems = Lists.newArrayList();

                JsonUtils.convertStringToList(objectMapper, item.getHiddenItem(), Integer.class)
                        .forEach(itemId -> {
                            String dataSource = itemId2DataSource.get(itemId);
                            if (Objects.isNull(dataSource)) {
                                return;
                            }
                            hiddenItems.add(dataSource);
                        });
                return SalesConfigCrawlDTO.builder()
                        .salesId(item.getId())
                        .salesAccount(Stream.of(StringUtils.split(item.getSalesAccount(), ",")).toList())
                        .hiddenItems(hiddenItems)
                        .build();
            }).toList();
        }
    }