package com.cf.imes.module.executor.dal.mysql.process;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.cf.imes.framework.mybatis.core.mapper.BaseMapperX;
import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.cf.imes.module.executor.dal.dataobject.process.OrderProcessDO;
import com.cf.imes.module.executor.dal.dataobject.rawgoods.RawGoodsDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.Collection;

/**
 * 生产单工序 Mapper
 *
 * @author 晨丰科技
 */
@Mapper
public interface OrderProcessMapper extends BaseMapperX<OrderProcessDO> {

    // 校验是否已经存在该生产单对应工序组
    default Boolean getOrderProcess(Long orderId,Long organId) {
        return selectCount(new LambdaQueryWrapperX<OrderProcessDO>()
                .eq(OrderProcessDO::getOrderId, orderId)
                .eq(OrderProcessDO::getOrganId, organId)
                .eq(OrderProcessDO::getDeleted, 0)) > 0;
    }

    // 批量修改删除状态
    default int updateOrderDeleted(Long id, Integer deleted, Long organId) {
        LambdaUpdateWrapper<OrderProcessDO> wrapper = new LambdaUpdateWrapper<OrderProcessDO>()
                .set(OrderProcessDO::getDeleted, deleted)
                .eq(OrderProcessDO::getOrderId, id)
                .eq(OrderProcessDO::getOrganId, organId);

        if (deleted == 0)
            wrapper.eq(OrderProcessDO::getDeleted, 1);
        return update(wrapper);
    }
}