package com.cool.store.dao;

import com.cool.store.entity.EmployeeTrainingDO;
import com.cool.store.mapper.EmployeeTrainingMapper;
import com.cool.store.vo.EmployeeTrainingVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;
import tk.mybatis.mapper.entity.Example;

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

/**
 * @author byd
 * @date 2024-04-29 16:06
 */
@Slf4j
@Repository
public class EmployeeTrainingDAO {

    @Resource
    private EmployeeTrainingMapper employeeTrainingMapper;

    public List<EmployeeTrainingVO> employeeTrainingList(String keyWord, List<String> regionIdList,
                                                         List<String> authRegionIdList, Boolean assignFlag,
                                                         String beginTime, String endTime, List<String> storeNumList,
                                                         Integer theoreticalExamStatus,
                                                         Integer practicalExamStatus,
                                                         Integer assessmentStatus,
                                                         Boolean assignStoreFlag) {

        return employeeTrainingMapper.employeeTrainingList(keyWord, regionIdList, authRegionIdList, assignFlag, beginTime, endTime, storeNumList,
                theoreticalExamStatus, practicalExamStatus, assessmentStatus, assignStoreFlag);
    }

    public EmployeeTrainingDO selectById(Long id) {

        return employeeTrainingMapper.selectByPrimaryKey(id);
    }

    public EmployeeTrainingDO selectByUserDetailId(Long userDetailId) {
        return employeeTrainingMapper.selectOne(EmployeeTrainingDO.builder().xfsgUserDetailId(userDetailId).build());
    }

    public int insertSelective(EmployeeTrainingDO employeeTrainingDO) {

        return employeeTrainingMapper.insertSelective(employeeTrainingDO);
    }

    public int updateByPrimaryKeySelective(EmployeeTrainingDO employeeTrainingDO) {

        return employeeTrainingMapper.updateByPrimaryKeySelective(employeeTrainingDO);
    }

    public List<EmployeeTrainingVO> trainingListByShopId(Long shopId, String trainingTeacherUserId, Integer status) {

        return employeeTrainingMapper.trainingListByShopId(shopId, trainingTeacherUserId, status);
    }

    public List<EmployeeTrainingVO> assessmentUserList(String name, String practicalAssessmentUserId,
                                                       Integer assessmentStatus,
                                                       String estimatedAssessmentBeginTime, String estimatedAssessmentEndTime,
                                                       String actualAssessmentBeginTime, String actualAssessmentEndTime, List<String> storeIdList) {
        return employeeTrainingMapper.assessmentUserList(name, practicalAssessmentUserId, assessmentStatus, estimatedAssessmentBeginTime,
                estimatedAssessmentEndTime, actualAssessmentBeginTime, actualAssessmentEndTime, storeIdList);
    }

    public List<EmployeeTrainingDO> theoreticalList() {
        List<Integer> statusList = new ArrayList<>();
        statusList.add(2);
        statusList.add(3);
        Example example = new Example(EmployeeTrainingDO.class);
        example.createCriteria().andCondition("assessment_num = assessment_total_num").andEqualTo("theoreticalExamStatus", 0)
                .andIn("assessmentStatus", statusList);
        return employeeTrainingMapper.selectByExample(example);
    }

    public Integer unCompleteNum(Long shopId) {
        Example example = new Example(EmployeeTrainingDO.class);
        example.createCriteria().andEqualTo("shopId", shopId).andCondition("(practical_exam_status != 1)");
        return employeeTrainingMapper.selectCountByExample(example);
    }
}
