package com.yunyan.business.service.impl;

import java.util.List;
import com.yunyan.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yunyan.business.mapper.CourseCodeMapper;
import com.yunyan.business.domain.CourseCode;
import com.yunyan.business.service.ICourseCodeService;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import lombok.Builder;
import com.yunyan.common.core.domain.AjaxResultVo;
import org.springframework.beans.BeanUtils;
import com.yunyan.common.core.domain.model.LoginUser;
import com.yunyan.common.utils.SecurityUtils;
import com.yunyan.common.enums.DataContentType;
import lombok.extern.slf4j.Slf4j;
import java.util.Date;
import com.yunyan.common.annotation.DataScope;

/**
 * 科目编码管理Service业务层处理
 *
 * @author yunyan
 * @date 2023-07-31
 */
@Slf4j
@Service
public class CourseCodeServiceImpl extends ServiceImpl<CourseCodeMapper, CourseCode> implements ICourseCodeService
{
    @Autowired
    private CourseCodeMapper courseCodeMapper;

    /**
     * 查询科目编码管理列表
     *
     * @param courseCode 科目编码管理
     * @return 科目编码管理
     */
     @Override
    public List<CourseCode> selectCourseCodeList(CourseCode courseCode)
    {
        return courseCodeMapper.selectCourseCodeList(courseCode);
    }

    /**
    * 新增
    * @param
    * @return
    */
    @Override
    public AjaxResultVo add(CourseCode dto) {
        CourseCode entity = dto;

        this.save(entity);
        return AjaxResultVo.success();
    }

    /**
     * 编辑
     * @param
     * @return
     */
    @Override
    public AjaxResultVo edit(CourseCode dto) {

        CourseCode entity = this.getById(dto.getId());
        if(null == entity) {
            return AjaxResultVo.error("非法操作");
        }

        entity = new CourseCode();
        BeanUtils.copyProperties(dto, entity);

        this.updateById(entity);
        return AjaxResultVo.success();
    }

    /**
     * 详情
     * @param id
     * @return
     */
    @Override
    public AjaxResultVo info(Long id) {
        CourseCode entity = this.getById(id);
        if(null == entity) {
            return AjaxResultVo.error("数据查询异常~");
        }

        return AjaxResultVo.success(entity);
    }

    @Override
    public List<CourseCode> getCodeListByType(Integer type) {
        List<CourseCode> list = lambdaQuery().eq(CourseCode::getType, type).list();
        return list;
    }
}
