package com.miaxis.tms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.miaxis.common.annotation.DataSource;
import com.miaxis.common.core.domain.Response;
import com.miaxis.common.enums.DataSourceTypeEnum;
import com.miaxis.tms.domain.CoachInfo;
import com.miaxis.tms.dto.CoachInfoDTO;
import com.miaxis.tms.dto.CoachInfoIdDTO;
import com.miaxis.tms.dto.CoachInfoPwDTO;
import com.miaxis.tms.mapper.CoachInfoMapper;
import com.miaxis.tms.service.ICoachInfoService;
import com.miaxis.tms.vo.CoachInfoVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * <p>
 * 学员基本信息表 服务实现类
 * </p>
 *
 * @author ${author}
 * @since 2021-03-09
 */
@Service
@DataSource(value = DataSourceTypeEnum.NEWGZPT)
public class CoachInfoServiceImpl extends ServiceImpl<CoachInfoMapper, CoachInfo> implements ICoachInfoService {


    @Resource
    CoachInfoMapper mapper;

    @Override
    public CoachInfoVo getCoachInfoById(CoachInfoIdDTO coaDto) {
        return  mapper.getCoachInfoById(coaDto);
    }

    @Override
    public CoachInfo getCoachBylogin(CoachInfoDTO coaDto) {
        return mapper.getCoachBylogin(coaDto);
    }

    @Override
    public Response updateCoachPassword(CoachInfoPwDTO coaPwDto) {

        CoachInfoDTO coaDto = new CoachInfoDTO();
        BeanUtils.copyProperties(coaPwDto,coaDto);
        CoachInfo coachInfo = this.getCoachBylogin(coaDto);
        if(coachInfo==null) {
            Response response = new Response(502,"用户不存在或用户密码错误");
            return response;
        } else {
            int result = mapper.updateCoachPassword(coaPwDto);
            return Response.success(result);
        }
    }


}
