package com.cool.store.dao;

import com.cool.store.entity.AssessmentDataDO;
import com.cool.store.mapper.AssessmentDataMapper;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Auther: WangShuo
 * @Date: 2024/04/29/下午10:38
 * @Version 1.0
 * @注释: AssessmentDataDO
 */
@Repository
public class AssessmentDataDAO {
    @Resource
    private AssessmentDataMapper assessmentDataMapper;

    public Boolean batchInsert(List<AssessmentDataDO> assessmentDataDOS) {
        if (CollectionUtils.isNotEmpty(assessmentDataDOS)) {
            for (AssessmentDataDO assessmentDataDO : assessmentDataDOS) {
                assessmentDataMapper.insertSelective(assessmentDataDO);
            }
            return Boolean.TRUE;
        }
        return Boolean.FALSE;
    }

    public Integer batchUpdate(List<AssessmentDataDO> assessmentDataDOS) {
        if (CollectionUtils.isNotEmpty(assessmentDataDOS)) {
            return assessmentDataMapper.batchUpdate(assessmentDataDOS);
        }
        return 0;
    }

    public List<AssessmentDataDO> selectList(String userId, List<Long> templateIdList) {
        Example example = new Example(AssessmentDataDO.class);
        example.createCriteria().andEqualTo("assessmentUserId", userId).andIn("templateId", templateIdList);
        return assessmentDataMapper.selectByExample(example);
    }

    public AssessmentDataDO selectByTemplateId(Long templateId, String userId, Long shopId) {
        return assessmentDataMapper.selectOne(AssessmentDataDO.builder().shopId(shopId).templateId(templateId).assessmentUserId(userId).build());
    }

    public Integer updateByPrimaryKeySelective(AssessmentDataDO assessmentDataDO) {
        return assessmentDataMapper.updateByPrimaryKeySelective(assessmentDataDO);
    }

    public Integer insertSelective(AssessmentDataDO assessmentDataDO) {
        return assessmentDataMapper.insertSelective(assessmentDataDO);
    }

    public Integer selectCount(String userId, Long shopId) {
        Example example = new Example(AssessmentDataDO.class);
        example.createCriteria().andEqualTo("assessmentUserId", userId).andEqualTo("shopId", shopId)
                .andEqualTo("qualified", Boolean.TRUE);
        return assessmentDataMapper.selectCountByExample(example);
    }

    public AssessmentDataDO selectByPrimaryKey(Long id) {
        return assessmentDataMapper.selectByPrimaryKey(id);
    }

    public List<AssessmentDataDO> selectListByShopId(Long shopId,Long templateIdMin, Long templateIdMax) {
        if (shopId == null || templateIdMin == 0L || templateIdMax == 0L) {
            return null;
        }
        return assessmentDataMapper.selectListByShopId(shopId,templateIdMin,templateIdMax);
    }

    public void batchInsertDO(List<AssessmentDataDO> assessmentDataDOList) {
        assessmentDataMapper.batchInsert(assessmentDataDOList);
    }

    public void batchInsertOrUpdate(List<AssessmentDataDO> assessmentDataDOList) {
        assessmentDataMapper.batchInsertOrUpdate(assessmentDataDOList);
    }


}
