package com.koobietech.eas.service.impl;

import com.koobietech.eas.common.result.PageData;
import com.koobietech.eas.mbg.mapper.EasEduClassMapper;
import com.koobietech.eas.mbg.model.EasEduCategory;
import com.koobietech.eas.mbg.model.EasEduCategoryExample;
import com.koobietech.eas.mbg.model.EasEduClass;
import com.koobietech.eas.mbg.model.EasEduClassExample;
import com.koobietech.eas.service.EasEduClassService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import javax.imageio.metadata.IIOMetadataFormat;
import java.util.Date;
import java.util.List;
import java.util.Objects;

@Service
public class EasEduClassServiceImpl implements EasEduClassService {

    @Resource
    EasEduClassMapper easEduClassMapper;
    @Override
    public int addClass(EasEduClass easEduClass) {
        easEduClass.setCreateTime(new Date());
        easEduClass.setModifyTime(new Date());
        return easEduClassMapper.insert(easEduClass);
    }

    @Override
    public int updateClass(EasEduClass easEduClass) {
        return easEduClassMapper.updateByPrimaryKey( easEduClass );
    }

    @Override
    public int deleteClass(Long id) {
        return  easEduClassMapper.deleteByPrimaryKey( id );
    }

    @Override
    public EasEduClass selectId(Long id) {
        System.out.println("Id" + id);
        return easEduClassMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<EasEduClass> selectTotal() {
        return easEduClassMapper.selectByExample(null);
    }

    @Override
    public PageData selectCondition(EasEduClass easEduClass) {
        EasEduClassExample easEduClassExample = new EasEduClassExample();
        EasEduClassExample.Criteria criteria = easEduClassExample.createCriteria();
        if ( Objects.nonNull(easEduClass) ) {
            if (Objects.nonNull(easEduClass.getId())) {
                criteria.andIdEqualTo(easEduClass.getId());
            }
            if (StringUtils.hasText(easEduClass.getName())) {
                criteria.andNameLike("%" + easEduClass.getName() + "%");
            }
            if (Objects.nonNull(easEduClass.getManageId()) && easEduClass.getManageId() > 0){
                criteria.andManageIdEqualTo(easEduClass.getManageId());
            }
            if (Objects.nonNull(easEduClass.getAssistantId()) && easEduClass.getAssistantId() > 0){
                criteria.andAssistantIdEqualTo(easEduClass.getAssistantId());
            }
            if (Objects.nonNull(easEduClass.getCreateTime())) {
                criteria.andCreateTimeGreaterThan(easEduClass.getCreateTime());
            }
            if (Objects.nonNull(easEduClass.getModifyTime())) {
                criteria.andCreateTimeGreaterThan(easEduClass.getModifyTime());
            }
            if (Objects.nonNull(easEduClass.getCreateUid()) && easEduClass.getCreateUid() > 0) {
                criteria.andCreateUidEqualTo(easEduClass.getCreateUid());
            }
            if (StringUtils.hasText(easEduClass.getDisabled())) {
                criteria.andDisabledEqualTo(easEduClass.getDisabled());
            }
        }
        List<EasEduClass> easEduClasses = easEduClassMapper.selectByExample(easEduClassExample);
        long l = easEduClassMapper.countByExample(easEduClassExample);
        return PageData.init(easEduClasses,l);
    }

//    @Override
//    public PageData selectCondition(EasEduClass easEduClass) {
//        EasEduClassExample easEduClassExample = new EasEduClassExample();
//        EasEduClassExample.Criteria criteria = easEduClassExample.createCriteria();
//        if (Objects.nonNull(easEduClass)){
//            if (Objects.nonNull(easEduClass.getId())){
//                criteria.andIdEqualTo(easEduClass.getId());
//            }
//            if (StringUtils.hasText((easEduClass.getName()))){
//                criteria.andNameLike("%" + easEduClass.getName() + "%");
//            }
//            if (Objects.nonNull(easEduClass.getManageId())){
//                criteria.andManageIdEqualTo(easEduClass.getManageId());
//            }
//            if (Objects.nonNull(easEduClass.getAssistantId())){
//                criteria.andManageIdEqualTo(easEduClass.getManageId());
//            }
//            if (Objects.nonNull(easEduClass.getCreateTime())){
//                criteria.andCreateTimeGreaterThan(easEduClass.getCreateTime());
//            }
//            if (Objects.nonNull(easEduClass.getModifyTime())){
//                criteria.andModifyTimeGreaterThan(easEduClass.getModifyTime());
//            }
//            if (Objects.nonNull(easEduClass.getCreateUid())){
//                criteria.andCreateUidEqualTo(easEduClass.getCreateUid());
//            }
//            if (StringUtils.hasText(easEduClass.getDisabled())){
//                criteria.andDisabledEqualTo(easEduClass.getDisabled());
//            }
//        }
//        List<EasEduClass> easEduClasses = easEduClassMapper.selectByExample(easEduClassExample);
//        long l = easEduClassMapper.countByExample(easEduClassExample);
//        PageData ret = new PageData();
//        ret.setData(easEduClasses);
//        ret.setTotal(l);
//        return ret;
//    }

}
