package com.op.mes.mapper;

import java.util.List;

import com.op.mes.domain.Convert;
import com.op.mes.domain.ProLine;
import com.op.mes.domain.ProOrder;
import com.op.mes.domain.ProShift;
import org.apache.ibatis.annotations.Select;

/**
 * 订单Mapper接口
 *
 * @author Open Platform
 * @date 2023-07-13
 */
public interface ProOrderMapper {

    /**
     * 更新订单表（拆分模块）
     *
     * @param proOrder
     * @return
     */
    public int updateOrder(ProOrder proOrder);

    /**
     * 查询订单
     *
     * @param id 订单主键
     * @return 订单
     */
    public ProOrder selectProOrderById(String id);

    /**
     * 查询订单列表
     *
     * @param proOrder 订单
     * @return 订单集合
     */
    public List<ProOrder> selectProOrderList(ProOrder proOrder);

    /**
     * 新增订单
     *
     * @param proOrder 订单
     * @return 结果
     */
    public int insertProOrder(ProOrder proOrder);

    /**
     * 修改订单
     *
     * @param proOrder 订单
     * @return 结果
     */
    public int updateProOrder(ProOrder proOrder);

    /**
     * 删除订单
     *
     * @param id 订单主键
     * @return 结果
     */
    public int deleteProOrderById(String id);

    /**
     * 批量删除订单
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteProOrderByIds(String[] ids);

    /**
     * 获取线体
     *
     * @return
     */
    @Select(" SELECT sf.f_code [key],sf.factory_name label FROM sys_factory sf WHERE sf.f_type='l' AND sf.status = '1' AND sf.del_flag = '0' ")
    public List<ProLine> selectProdLine();

    /**
     * 获取班次
     *
     * @return
     */
    @Select("SELECT bst.Shift_Id shiftId,bst.Shift_Desc_Global shiftDesc FROM base_shifts_t bst")
    public List<ProShift> selectProShift();

    /**
     * 获取换算值
     *
     * @return
     */
    public List<Convert> selectConvert();

    /**
     * 根据code查询产线名称
     *
     * @return
     */
    @Select("SELECT sf.factory_name name FROM sys_factory sf WHERE sf.f_type='l' AND sf.status = '1' AND sf.del_flag = '0' AND sf.f_code = #{prodLineCode}")
    String selectProdLineName(String prodLineCode);

    /**
     * 查询所有batchCode
     *
     * @return
     */
    @Select("SELECT batch_code FROM pro_order_workorder_batch WHERE status = '1' GROUP BY batch_code")
    List<String> selectBatchCodes();


    /**
     * 通过parent_order查询订单信息
     *
     * @param orderCode
     * @return
     */
    List<ProOrder> selectChildProOrderByCode(String orderCode);

    /**
     * 通过code获取产线名称
     * @param prodLineCode
     * @return
     */
    @Select("SELECT sf.factory_name FROM sys_factory sf WHERE sf.f_code = #{prodLineCode}")
    String selectBatchNameByCode(String prodLineCode);

    /**
     * 通过工单id查询批次号list
     * @param workorderId
     * @return
     */
    @Select("SELECT powb.batch_code FROM pro_order_workorder_batch powb LEFT JOIN pro_order_workorder pow ON powb.workorder_id = pow.workorder_id WHERE pow.workorder_id = #{workorderId}")
    List<String> selectBatchCodesById(String workorderId);
}
