package com.vote.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.vote.system.domain.VoteHistoryScore;
import com.vote.system.domain.VoteSubmission;
import com.vote.system.domain.vo.VoteHistoryScoreVo;
import com.vote.system.mapper.VoteSubmissionMapper;
import com.vote.system.service.VoteHistoryScoreService;
import com.vote.system.mapper.VoteHistoryScoreMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * @author Administrator
 * @description 针对表【vote_history_score】的数据库操作Service实现
 * @createDate 2024-09-29 18:03:15
 */
@Service
public class VoteHistoryScoreServiceImpl extends ServiceImpl<VoteHistoryScoreMapper, VoteHistoryScore>
        implements VoteHistoryScoreService {

    @Autowired
    private VoteHistoryScoreMapper voteHistoryScoreMapper;

    @Autowired
    private VoteSubmissionMapper voteSubmissionMapper;

    @Override
    public VoteHistoryScoreVo getHistoryScore(Long submissionId) {
        VoteSubmission submission = voteSubmissionMapper.selectById(submissionId);
        VoteHistoryScoreVo historyScoreVo = new VoteHistoryScoreVo();
        historyScoreVo.setSubmissionName(submission.getName());
        LambdaQueryWrapper<VoteHistoryScore> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(VoteHistoryScore::getSubmissionId, submissionId);
        historyScoreVo.setVoteHistoryScores(voteHistoryScoreMapper.selectList(wrapper));
        return historyScoreVo;
    }
}




