package com.miaxis.school.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.miaxis.common.annotation.DataScope;
import com.miaxis.common.utils.DateUtils;
import com.miaxis.school.domain.SchoolInfo;
import com.miaxis.school.dto.SchoolInfoDTO;
import com.miaxis.school.dto.SchoolInfoEvalDTO;
import com.miaxis.school.dto.SchoolInfoPcDTO;
import com.miaxis.school.mapper.SchoolInfoMapper;
import com.miaxis.school.service.ISchoolInfoService;
import com.miaxis.school.vo.SchoolInfoDetailPcVO;
import com.miaxis.school.vo.SchoolInfoEvalVO;
import com.miaxis.school.vo.SchoolInfoPcVO;
import com.miaxis.school.vo.SchoolInfoVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

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

/**
 * 驾校Service业务层处理
 *
 * @author miaxis
 * @date 2020-12-24
 */
@Service
public class SchoolInfoServiceImpl extends ServiceImpl<SchoolInfoMapper, SchoolInfo> implements ISchoolInfoService {

    @Resource
    private SchoolInfoMapper schoolInfoMapper;

    /**
     * 查询驾校
     *
     * @param inscode 驾校ID
     * @return 驾校
     */
    @Override
    public SchoolInfo selectSchoolInfoById(String inscode){
        return schoolInfoMapper.selectSchoolInfoById(inscode);
    }

    /**
     * 查询驾校列表
     *
     * @param schoolInfo 驾校
     * @return 驾校
     */
    @Override
    public List<SchoolInfo> selectSchoolInfoList(SchoolInfo schoolInfo){
        return schoolInfoMapper.selectSchoolInfoList(schoolInfo);
    }


    /**
     * 查询驾校列表
     *
     * @param schoolInfoDTO 驾校
     * @return 驾校
     */
    @Override
    public List<SchoolInfoVO> selectSchoolInfoUrlList(SchoolInfoDTO schoolInfoDTO){
        return schoolInfoMapper.selectSchoolInfoUrlList(schoolInfoDTO);
    }

    /**
     * 查询驾校列表
     *
     * @param schoolInfoEvalDTO 驾校
     * @return 驾校
     */
    @Override
    public List<SchoolInfoEvalVO> selectSchoolInfoEvalList(SchoolInfoEvalDTO schoolInfoEvalDTO) {
        return schoolInfoMapper.selectSchoolInfoEvalList(schoolInfoEvalDTO);
    }


    /**
     * 新增驾校
     *
     * @param schoolInfo 驾校
     * @return 结果
     */
    @Override
    public int insertSchoolInfo(SchoolInfo schoolInfo){
        schoolInfo.setCreateTime(DateUtils.getNowDate());
        return schoolInfoMapper.insertSchoolInfo(schoolInfo);
    }

    /**
     * 修改驾校
     *
     * @param schoolInfo 驾校
     * @return 结果
     */
    @Override
    public int updateSchoolInfo(SchoolInfo schoolInfo){
        schoolInfo.setUpdateTime(DateUtils.getNowDate());
        return schoolInfoMapper.updateSchoolInfo(schoolInfo);
    }

    /**
     * 批量删除驾校
     *
     * @param inscodes 需要删除的驾校ID
     * @return 结果
     */
    @Override
    public int deleteSchoolInfoByIds(String[] inscodes){
        return schoolInfoMapper.deleteSchoolInfoByIds(inscodes);
    }

    /**
     * 删除驾校信息
     *
     * @param inscode 驾校ID
     * @return 结果
     */
    @Override
    public int deleteSchoolInfoById(String inscode){
        return schoolInfoMapper.deleteSchoolInfoById(inscode);
    }

    /**
     * pc查询列表
     */
    @Override
    public List<SchoolInfoPcVO> queryList(SchoolInfoPcDTO schoolInfoPcDTO) {

        return schoolInfoMapper.queryList(schoolInfoPcDTO);
    }

    /**
     * pc查询驾校详情
     * @param id
     * @return
     */
    @Override
    public SchoolInfoDetailPcVO getSchoolInfoDetail(Long id) {
        return schoolInfoMapper.getSchoolInfoDetail(id);
    }

    /**
     * pc删除驾校(逻辑删除)
     * @param inscodes
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateByInscode(String[] inscodes) {
        try {
            schoolInfoMapper.updateByInscode(inscodes);
            return true;
        }catch (Exception e){
            throw new RuntimeException(e);
        }
    }


}
