package com.ruoyi.syzy.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.syzy.domain.BBusiWishLocationSubmits;
import com.ruoyi.syzy.dto.ZytbBatch;
import com.ruoyi.syzy.mapper.BBusiWishLocationSubmitsMapper;
import com.ruoyi.syzy.service.IBBusiWishLocationSubmitsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 地区批次录取分数线Service业务层处理
 *
 * @author mingxue
 * @date 2021-08-19
 */
@Service
public class BBusiWishLocationSubmitsServiceImpl implements IBBusiWishLocationSubmitsService {
    @Autowired
    private BBusiWishLocationSubmitsMapper bBusiWishLocationSubmitsMapper;

    @Override
    public List<String> locations() {
        return bBusiWishLocationSubmitsMapper.locations();
    }

    @Override
    public List<String> years(String location) {
        return bBusiWishLocationSubmitsMapper.years(location);
    }

    @Override
    public List<String> yearsNoStatus(String location) {
        return bBusiWishLocationSubmitsMapper.yearsNoStatus(location);
    }

    /**
     * 查询地区批次录取分数线
     *
     * @param id 地区批次录取分数线ID
     * @return 地区批次录取分数线
     */
    @Override
    public BBusiWishLocationSubmits selectBBusiWishLocationSubmitsById(Long id) {
        return bBusiWishLocationSubmitsMapper.selectBBusiWishLocationSubmitsById(id);
    }

    /**
     * 查询地区批次录取分数线列表
     *
     * @param bBusiWishLocationSubmits 地区批次录取分数线
     * @return 地区批次录取分数线
     */
    @Override
    public List<BBusiWishLocationSubmits> selectBBusiWishLocationSubmitsList(BBusiWishLocationSubmits bBusiWishLocationSubmits) {
        List<BBusiWishLocationSubmits> coll = bBusiWishLocationSubmitsMapper.selectBBusiWishLocationSubmitsList(bBusiWishLocationSubmits);
//        coll.forEach(row -> {
//            row.setTypeName(BatchUtil.getLabel(row.getType()));
//        });
        return coll;
    }

    /**
     * 新增地区批次录取分数线
     *
     * @param bBusiWishLocationSubmits 地区批次录取分数线
     * @return 结果
     */
    @Override
    public int insertBBusiWishLocationSubmits(BBusiWishLocationSubmits bBusiWishLocationSubmits) {
        bBusiWishLocationSubmits.setCreateTime(DateUtils.getNowDate());
        return bBusiWishLocationSubmitsMapper.insertBBusiWishLocationSubmits(bBusiWishLocationSubmits);
    }

    /**
     * 修改地区批次录取分数线
     *
     * @param bBusiWishLocationSubmits 地区批次录取分数线
     * @return 结果
     */
    @Override
    public int updateBBusiWishLocationSubmits(BBusiWishLocationSubmits bBusiWishLocationSubmits) {
        return bBusiWishLocationSubmitsMapper.updateBBusiWishLocationSubmits(bBusiWishLocationSubmits);
    }

    /**
     * 批量删除地区批次录取分数线
     *
     * @param ids 需要删除的地区批次录取分数线ID
     * @return 结果
     */
    @Override
    public int deleteBBusiWishLocationSubmitsByIds(Long[] ids) {
        return bBusiWishLocationSubmitsMapper.deleteBBusiWishLocationSubmitsByIds(ids);
    }

    /**
     * 删除地区批次录取分数线信息
     *
     * @param id 地区批次录取分数线ID
     * @return 结果
     */
    @Override
    public int deleteBBusiWishLocationSubmitsById(Long id) {
        return bBusiWishLocationSubmitsMapper.deleteBBusiWishLocationSubmitsById(id);
    }

    @Override
    public List<ZytbBatch> batches(String location, Float score, String mode) {
        List<BBusiWishLocationSubmits> coll = bBusiWishLocationSubmitsMapper.batches(location, mode); // TODO MF

        List<ZytbBatch> list = new java.util.ArrayList<ZytbBatch>(coll.size());
        Boolean recommand = Boolean.FALSE;
        for (BBusiWishLocationSubmits row : coll) {
            ZytbBatch item = new ZytbBatch().setBatch(row.getType()).setName(row.getTypeName());
//                    .setName(BatchUtil.getLabel(row.getType()));
            item.setYear(row.getYear()).setRecommand(false);
            item.setScore1(row.getScore());
            item.setScore2(item.getScore1());
            Integer ts = item.getScore1();
            if (!recommand && null != ts && score >= ts) {
                item.setRecommand(true);
                recommand = true;
            }
            item.setTips(row.getYear() + "年批次线：" + ts);
            list.add(item);
        }
        return list;
    }

    @Override
    public List<BBusiWishLocationSubmits> examMajors(String location) {
        return bBusiWishLocationSubmitsMapper.examMajors(location);
    }

}
