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.PitcherListVO;
import com.zanxiang.game.data.serve.service.IPitcherListService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.dao.Sqls;
import org.nutz.dao.sql.Criteria;
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:51
 */
@Service
@Slf4j
public class PitcherListServiceImpl implements IPitcherListService {

    @Autowired
    private Dao dao;

    /**
     * 所有投手列表
     * @param dto ChoiceListDTO
     * @return list
     */
    @Override
    public List<PitcherListVO> getPitcherList(ChoiceListDTO dto) {

        Criteria cir = Cnd.cri();
        if (StringUtils.isBlank(dto.getSourceSystem())) {
            dto.setSourceSystem("ZX_ONE");
        }
        if (StringUtils.isNotBlank(dto.getSourceSystem())) {
            cir.where().andEquals("source_system", dto.getSourceSystem());
        }
        //投手id、投手名为空排除掉
        cir.where().andNotIsNull("zx_pitcher_id");
        cir.where().andNotIsNull("zx_pitcher_name");
        //查询投手信息
        Sql sql = Sqls.create("""
                SELECT
                    source_system,
                    zx_pitcher_id as pitcher_id,
                    zx_pitcher_name as pitcher_name
                FROM dm_game_order.t_pitcher_map
                """ + cir);
        //设置回传对象
        sql.setCallback(Sqls.callback.entities());
        sql.setEntity(dao.getEntity(PitcherListVO.class));
        //执行sql
        dao.execute(sql);
        //返回结果
        return sql.getList(PitcherListVO.class);
    }

}
