package com.ym.mec.biz.service.impl;

import com.alibaba.fastjson.JSON;
import com.ym.mec.auth.api.entity.SysUser;
import com.ym.mec.biz.dal.dao.TeacherDao;
import com.ym.mec.common.dal.BaseDAO;
import org.springframework.beans.factory.annotation.Autowired;
import com.ym.mec.common.service.impl.BaseServiceImpl;
import com.ym.mec.biz.dal.entity.SysMusicCompareRecord;
import com.ym.mec.biz.service.SysMusicCompareRecordService;
import com.ym.mec.biz.dal.dao.SysMusicCompareRecordDao;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.Map;
import java.util.Objects;

@Service
public class SysMusicCompareRecordServiceImpl extends BaseServiceImpl<Long, SysMusicCompareRecord>  implements SysMusicCompareRecordService {
	
	@Autowired
	private SysMusicCompareRecordDao sysMusicCompareRecordDao;
	@Autowired
	private TeacherDao teacherDao;

	@Override
	public BaseDAO<Long, SysMusicCompareRecord> getDAO() {
		return sysMusicCompareRecordDao;
	}

	@Override
	public void saveMusicCompareData(String phone, Integer sysMusicScoreId, Map<Integer, Map<String, BigDecimal>> userMeasureScoreMap) {
		SysUser user = teacherDao.getUserWithPhone(phone);
		if(Objects.isNull(user)){
			return;
		}
		SysMusicCompareRecord sysMusicCompareRecord = new SysMusicCompareRecord();
		sysMusicCompareRecord.setUserId(user.getId());
		sysMusicCompareRecord.setSysMusicScoreId(sysMusicScoreId);
		sysMusicCompareRecord.setScoreData(JSON.toJSONString(userMeasureScoreMap));
		sysMusicCompareRecordDao.insert(sysMusicCompareRecord);
	}
}
