package com.ruoyi.ibs.cmpm.service;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.ibs.cmpm.mapper.GridCmpmMapper;
import com.ruoyi.ibs.customerselect.domain.ContinuousParam;
import com.ruoyi.ibs.customerselect.domain.CustBaseInfo;
import com.ruoyi.ibs.customerselect.domain.DiscreteParam;
import com.ruoyi.ibs.customerselect.mapper.GridSummarCountMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author 吴凯程
 * @Date 2025/11/21
 **/
@Service
public class GridCmpmCustService {

    @Resource
    private GridCmpmMapper gridCmpmMapper;


    @Autowired
    private GridSummarCountMapper gridSummarCountMapper;

    public List<CustBaseInfo> selectCustInfoRetailList(CustBaseInfo custBaseInfoParam) {
        custBaseInfoParam.setCmpmUserName(SecurityUtils.getUsername());
        custBaseInfoParam.setDeptCode(SecurityUtils.getHeadId());

        //分页参数
        custBaseInfoParam.setStart((custBaseInfoParam.getNum() - 1) * custBaseInfoParam.getSize());
        custBaseInfoParam.setEnd(custBaseInfoParam.getNum() * custBaseInfoParam.getSize());

        StringBuilder metricStrBuilder = new StringBuilder();
        if (custBaseInfoParam.getContinuousParams() != null && custBaseInfoParam.getContinuousParams().size() > 0){
            for (ContinuousParam info : custBaseInfoParam.getContinuousParams()){
                if (metricStrBuilder.length() > 0) {
                    metricStrBuilder.append(",");
                }
                metricStrBuilder.append(gridSummarCountMapper.selectDictLabelByDictValue(info.getKey()));
            }
        }
        if (custBaseInfoParam.getDiscreteParams() != null && custBaseInfoParam.getDiscreteParams().size() > 0){
            for (DiscreteParam info:custBaseInfoParam.getDiscreteParams()){
                if (metricStrBuilder.length() > 0) {
                    metricStrBuilder.append(",");
                }
                metricStrBuilder.append(gridSummarCountMapper.selectDictLabelByDictValue(info.getKey()));
            }
        }
        return gridCmpmMapper.selectCustInfoFromGridCmpm(custBaseInfoParam);
    }
}
