package com.fjhx.mes.service.workshop.impl;

import com.fjhx.mes.entity.workshop.po.Workshop;
import com.fjhx.mes.mapper.workshop.WorkshopMapper;
import com.fjhx.mes.service.workshop.WorkshopService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.system.utils.UserUtil;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjhx.mes.entity.workshop.vo.WorkshopVo;
import com.fjhx.mes.entity.workshop.dto.WorkshopSelectDto;
import com.ruoyi.common.utils.wrapper.IWrapper;
import com.fjhx.mes.entity.workshop.dto.WorkshopDto;
import cn.hutool.core.bean.BeanUtil;

import java.util.List;


/**
 * <p>
 * 车间 服务实现类
 * </p>
 *
 * @author E
 * @since 2023-03-23
 */
@Service
public class WorkshopServiceImpl extends ServiceImpl<WorkshopMapper, Workshop> implements WorkshopService {

    @Override
    public Page<WorkshopVo> getPage(WorkshopSelectDto dto) {
        IWrapper<Workshop> wrapper = getWrapper();
        wrapper.orderByDesc("w", Workshop::getId);
        wrapper.like("w",Workshop::getName,dto.getKeyword());
        wrapper.like("w",Workshop::getType,dto.getType());
        Page<WorkshopVo> page = this.baseMapper.getPage(dto.getPage(), wrapper);
        //根据id赋值操作人名称
        UserUtil.assignmentNickName(page.getRecords(), WorkshopVo::getPersonLiableId, WorkshopVo::setPersonLiableName);
        return page;
    }

    @Override
    public WorkshopVo detail(Long id) {
        Workshop Workshop = this.getById(id);
        WorkshopVo result = BeanUtil.toBean(Workshop, WorkshopVo.class);
        return result;
    }

    @Override
    public void add(WorkshopDto workshopDto) {
        this.save(workshopDto);
    }

    @Override
    public void edit(WorkshopDto workshopDto) {
        this.updateById(workshopDto);
    }

    @Override
    public void delete(Long id) {
        this.removeById(id);
    }

}
