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

import com.fjhx.mes.entity.assembly.po.AssemblyLine;
import com.fjhx.mes.entity.workshop.vo.WorkshopVo;
import com.fjhx.mes.mapper.assembly.AssemblyLineMapper;
import com.fjhx.mes.service.assembly.AssemblyLineService;
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.assembly.vo.AssemblyLineVo;
import com.fjhx.mes.entity.assembly.dto.AssemblyLineSelectDto;
import com.ruoyi.common.utils.wrapper.IWrapper;
import com.fjhx.mes.entity.assembly.dto.AssemblyLineDto;
import cn.hutool.core.bean.BeanUtil;

import java.util.Arrays;


/**
 * <p>
 * 产线 服务实现类
 * </p>
 *
 * @author 
 * @since 2023-03-23
 */
@Service
public class AssemblyLineServiceImpl extends ServiceImpl<AssemblyLineMapper, AssemblyLine> implements AssemblyLineService {

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

    @Override
    public AssemblyLineVo detail(Long id) {
        AssemblyLine AssemblyLine = this.getById(id);
        AssemblyLineVo result = BeanUtil.toBean(AssemblyLine, AssemblyLineVo.class);
        //根据id赋值操作人名称
        UserUtil.assignmentNickName(Arrays.asList(result), AssemblyLineVo::getPersonLiableId, AssemblyLineVo::setPersonLiableName);
        return result;
    }

    @Override
    public void add(AssemblyLineDto assemblyLineDto) {
        this.save(assemblyLineDto);
    }

    @Override
    public void edit(AssemblyLineDto assemblyLineDto) {
        this.updateById(assemblyLineDto);
    }

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

}
