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

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.cf.imes.framework.mybatis.core.mapper.BaseMapperX;

import com.cf.imes.module.executor.dal.dataobject.orderBody.OrderBodyDO;
import com.cf.imes.module.executor.dal.dataobject.orderGroup.OrderGroupDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.Collection;
import java.util.List;

/**
 * 生产单加工组 Mapper
 *
 * @author 晨丰科技
 */
@Mapper
public interface OrderGroupMapper extends BaseMapperX<OrderGroupDO> {

    int updatePlateNumById(@Param("orderId") Long orderId, @Param("plateNum") Double plateNum);

    // 生产单中包含的加工组
    List<OrderGroupDO> getOrderGroupByOrderId(@Param("orderId") Long orderId, @Param("organId") Long organId);

    // 单个修改删除状态
    default int updateOrderDeleted(Long id, Integer deleted, Long organId) {
        LambdaUpdateWrapper<OrderGroupDO> wrapper = new LambdaUpdateWrapper<OrderGroupDO>()
                .set(OrderGroupDO::getDeleted, deleted)
                .eq(OrderGroupDO::getId, id)
                .eq(OrderGroupDO::getOrganId, organId);
        if (deleted == 0)
            wrapper.eq(OrderGroupDO::getDeleted, 1);
        return update(wrapper);
    }

    // 单个修改删除状态 by bodyId
    default int updateDeletedById(Long id, Integer deleted, Long organId) {
        return update(new LambdaUpdateWrapper<OrderGroupDO>()
                .set(OrderGroupDO::getDeleted, deleted)
                .eq(OrderGroupDO::getBodyId, id)
                .eq(OrderGroupDO::getOrganId, organId));
    }
}