package cn.iocoder.yudao.module.smartfactory.service.worktype;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.smartfactory.controller.admin.worktype.vo.WorkTypePageReqVO;
import cn.iocoder.yudao.module.smartfactory.controller.admin.worktype.vo.WorkTypeSaveReqVO;
import cn.iocoder.yudao.module.smartfactory.dal.dataobject.worktype.WorkTypeDO;
import cn.iocoder.yudao.module.smartfactory.dal.mysql.worktype.WorkTypeMapper;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

import javax.annotation.Resource;


/**
 * 工种 Service 实现类
 *
 * @author 艾楷
 */
@Service
@Validated
public class WorkTypeServiceImpl implements WorkTypeService {

    @Resource
    private WorkTypeMapper workTypeMapper;

    @Override
    public Long createWorkType(WorkTypeSaveReqVO createReqVO) {
        // 插入
        WorkTypeDO workType = BeanUtils.toBean(createReqVO, WorkTypeDO.class);
        workTypeMapper.insert(workType);
        // 返回
        return workType.getId();
    }

    @Override
    public void updateWorkType(WorkTypeSaveReqVO updateReqVO) {
        // 更新
        WorkTypeDO updateObj = BeanUtils.toBean(updateReqVO, WorkTypeDO.class);
        workTypeMapper.updateById(updateObj);
    }

    @Override
    public void deleteWorkType(Long id) {
        // 删除
        workTypeMapper.deleteById(id);
    }

    @Override
    public WorkTypeDO getWorkType(Long id) {
        return workTypeMapper.selectById(id);
    }

    @Override
    public PageResult<WorkTypeDO> getWorkTypePage(WorkTypePageReqVO pageReqVO) {
        return workTypeMapper.selectPage(pageReqVO);
    }

}