package com.rf.psychological.scale.service.impl;

import com.rf.psychological.dao.model.AnswerEntity;
import com.rf.psychological.scale.dao.repository.AnswerRepository;
import com.rf.psychological.scale.service.AnswerService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * @author zsy
 * @description:
 * @date 2021/5/14 10:51
 */
@Service
@Slf4j
public class AnswerServiceImpl implements AnswerService {
    @Autowired
    private AnswerRepository answerRepository;


    /**
     * 根据flag获取全部答案
     *
     * @param flag
     */
    @Override
    public List<AnswerEntity> getAnswerByFlag(String flag) {
        return this.answerRepository.getAnswerByFlag(flag);
    }


    /**
     * 保存
     *
     * @param answerEntity
     */
    @Override
    public void saveAnswer(AnswerEntity answerEntity) {
        //数据加密
        //answerEntity.encrypt();
        this.answerRepository.save(answerEntity);
    }

    @Override
    public void saveBatchAnswer(List<AnswerEntity> answerEntity) {

        this.answerRepository.saveAll(answerEntity);
    }

    @Override
    public List<AnswerEntity> findAll() {
        return answerRepository.findAll();
    }

    @Override
    public void updateAnswer(AnswerEntity answerEntity) {
        answerRepository.updateAnswer(answerEntity.getName(),answerEntity.getScore(),answerEntity.getId());
    }

    @Override
    public void deleteAnswerByFlag(String flag) {
        this.answerRepository.deleteAnswerByFlag(flag);
    }

}
