package com.rongwei.bscommon.sys.dao;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.rongwei.bsentity.domain.*;
import com.rongwei.bsentity.vo.ApsProcessOutputProductAndBlankStatusVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface ApsProductDetailDao extends BaseMapper<ApsProductDetailDo> {


    @Select({" <script>",
            "select * from aps_production_order where DELETED='0' and TENANTID=#{curtenantid} and CUSTOMORDERNO in",
            " <foreach collection=\"orderNos\" item=\"orderno\" index=\"index\" open=\"(\" close=\")\" separator=\",\"> ",
            "  #{orderno}",
            "</foreach>",
            "</script>"})
    List<ApsProductionOrderDo> getProductionOrders(@Param("curtenantid") String curtenantid, @Param("orderNos") List<String> orderNos);

    @Select({" <script>",
            "select * from aps_production_merge_order where DELETED='0' and TENANTID=#{curtenantid} and CUSTOMORDERNO in",
            " <foreach collection=\"orderNos\" item=\"orderno\" index=\"index\" open=\"(\" close=\")\" separator=\",\"> ",
            "  #{orderno}",
            "</foreach>",
            "</script>"})
    List<ApsProductionMergeOrderDo> getProductionMergeOrders(@Param("curtenantid") String curtenantid, @Param("orderNos") List<String> orderNos);

    @Select({" <script>",
            "select * from aps_product_detail where DELETED='0' and TENANTID=#{curtenantid} and CUSTOMORDERNO in\n" +
                    " <foreach collection=\"orderNos\" item=\"orderno\" index=\"index\" open=\"(\" close=\")\" separator=\",\"> ",
            "  #{orderno}",
            "</foreach>",
            "</script>"})
    List<ApsProductDetailDo> getProductDetails(@Param("curtenantid") String curtenantid, @Param("orderNos") List<String> orderNos);

    @Select("select ID,CUSTOMERNAME,DELIVERYTIME from aps_customer_management where DELETED='0'")
    List<ApsCustomerManagementDo> getCustomerData();

    void publish(@Param("productionOrderIds") List<String> productionOrderIds);

    void updateProductstatus(@Param("productionOrderIds") List<String> productionOrderIds);

    void updateProductStatusByBlankId(@Param("blankIds") List<String> blankIds,
                                      @Param("productStatus") String productStatus);

    @Select("select ID,MATERIALCODE,MATERIALNAME,MATERIALUNIT from aps_material where DELETED='0'")
    List<ApsProcessMaterialDo> getMaterialData();

    @Select("select VALUE as MATERIALCODE,NAME as MATERIALNAME from sys_dict where DELETED='0' and DICTTYPE='metal' and PID<>'-1'")
    List<ApsProcessMaterialDo> getMetalData();

    @Select("select VALUE as MATERIALCODE,NAME as MATERIALNAME from sys_dict where DELETED='0' and DICTTYPE='metalState' and PID<>'-1'")
    List<ApsProcessMaterialDo> getMetalStateData();

    @Select("select apop.*,abo.ID AS 'blankId',abo.PRODUCTSTATUS AS 'blankStatus' from aps_blank_order abo LEFT JOIN aps_process_output_product apop ON apop.DELETED = 0 AND apop.BLANKID = abo.ID where abo.DELETED = 0 AND apop.PRODUCTID = #{detailId}")
    List<ApsProcessOutputProductAndBlankStatusVo> selectAboutBlankOutputByDetailId(@Param("detailId") String detailId);

    @Select("SELECT * FROM aps_product_detail WHERE DELETED = 0 AND MAINID = #{mainId}")
    List<ApsProductDetailDo> getProductDetailByMainId(@Param("mainId") String mainId);

    void publishCancel(@Param("productionOrderIds") List<String> productionOrderIds);
}
