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

import java.util.List;

import com.ym.mec.common.exception.BizException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ym.mec.biz.dal.dao.ChargeTypeSubjectMapperDao;
import com.ym.mec.biz.dal.entity.ChargeTypeSubjectMapper;
import com.ym.mec.biz.service.ChargeTypeSubjectMapperService;
import com.ym.mec.common.dal.BaseDAO;
import com.ym.mec.common.service.impl.BaseServiceImpl;

@Service
public class ChargeTypeSubjectMapperServiceImpl extends BaseServiceImpl<Long, ChargeTypeSubjectMapper> implements ChargeTypeSubjectMapperService {

    @Autowired
    private ChargeTypeSubjectMapperDao chargeTypeSubjectMapperDao;

    @Override
    public BaseDAO<Long, ChargeTypeSubjectMapper> getDAO() {
        return chargeTypeSubjectMapperDao;
    }

    @Override
    public boolean deleteById(Long id) {
        chargeTypeSubjectMapperDao.delete(id);
        return true;
    }

    @Override
    public boolean batchInsert(List<ChargeTypeSubjectMapper> chargeTypeSubjectMapperList) {
        ChargeTypeSubjectMapper subjectDiscount = chargeTypeSubjectMapperDao.getSubjectDiscount(chargeTypeSubjectMapperList.get(0).getChargeTypeId(), chargeTypeSubjectMapperList.get(0).getSubjectId());
        if (subjectDiscount != null) {
            throw new BizException("此声部商品折扣已添加");
        }

        chargeTypeSubjectMapperDao.batchInsert(chargeTypeSubjectMapperList);
        return true;
    }

    @Override
    public boolean batchUpdate(List<ChargeTypeSubjectMapper> chargeTypeSubjectMapperList) {
        chargeTypeSubjectMapperDao.batchUpdate(chargeTypeSubjectMapperList);
        return true;
    }

}