package com.zanxiang.game.data.serve.service.impl;

import com.zanxiang.game.data.serve.pojo.dto.ChoiceListDTO;
import com.zanxiang.game.data.serve.pojo.vo.AgentListVO;
import com.zanxiang.game.data.serve.service.IAgentListService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.nutz.dao.Dao;
import org.nutz.dao.Sqls;
import org.nutz.dao.sql.Sql;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author tianhua
 * @version 1.0
 * @description: TODO
 * @date 2023/11/3 16:50
 */
@Service
@Slf4j
public class AgentListServiceImpl implements IAgentListService {

    @Autowired
    private Dao dao;

    /**
     * 所有渠道列表
     * @param dto ChoiceListDTO
     * @return list
     */
    @Override
    public List<AgentListVO> getAgentList(ChoiceListDTO dto) {

        if (StringUtils.isBlank(dto.getSourceSystem())) {
            //默认查询“ZX_ONE”数据
            dto.setSourceSystem("ZX_ONE");
        }

        Sql sql = Sqls.create("""
                SELECT
                	source_system ,
                	id as agent_id,
                	MAX(agent_name) as agent_name
                from dm_game_order.t_pitcher_agent
                where ((account_type in('MP','GDT') and LENGTH(account_id)<= 10) or
                (account_type = 'BYTE' and LENGTH(account_id)<= 17))
                AND source_system = @source_system AND agent_name is not NULL
                GROUP BY id, source_system
                """);
        sql.setParam("source_system", dto.getSourceSystem());
        sql.setCallback(Sqls.callback.entities());
        sql.setEntity(dao.getEntity(AgentListVO.class));
        dao.execute(sql);

        return sql.getList(AgentListVO.class);
    }


}
