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

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.cf.imes.framework.mybatis.core.mapper.BaseMapperX;
import com.cf.imes.framework.security.core.util.SecurityFrameworkUtils;
import com.cf.imes.module.executor.controller.admin.order.vo.order.OrderModuleRespVO;
import com.cf.imes.module.executor.controller.admin.order.vo.product.OrderBodyRespVO;
import com.cf.imes.module.executor.dal.dataobject.order.OrderDO;
import com.cf.imes.module.executor.dal.dataobject.orderBody.OrderBodyDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;

/**
 * 生产单柜体 Mapper
 *
 * @author 晨丰科技
 */
@Mapper
public interface OrderBodyMapper extends BaseMapperX<OrderBodyDO> {

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

    int deleteAllByOrderId(@Param("orderId") Long orderId, @Param("bodyId") Long bodyId);

    List<OrderModuleRespVO> selectModuleByOrderId(@Param("orderId") Long orderId,
                                                  @Param("organId") Long organId,
                                                  @Param("deleted") Integer deleted);

    List<OrderBodyDO> getOrderBodyByOrderId(@Param("orderId") Long orderId, @Param("organId") Long organId);

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

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

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

    // 控制是否删除，进行查询
    default List<OrderBodyDO> selectList(Long orderId, Integer deleted, Long organId) {
        return selectList(new LambdaUpdateWrapper<OrderBodyDO>()
                .eq(OrderBodyDO::getOrderId, orderId)
                .eq(OrderBodyDO::getDeleted, deleted)
                .eq(OrderBodyDO::getOrganId, organId));
    }

}