package com.rongwei.bscommon.sys.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.rongwei.bsentity.domain.ApsProductionOrderDo;
import com.rongwei.bsentity.vo.ProductDetailIdAndPlanOutPutRollCountAllVo;
import com.rongwei.bsentity.vo.ProductTypeIdAndPidVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Entity com.rongwei.training.domain.ApsProductionOrder
 */
public interface ApsProductionOrderDao extends BaseMapper<ApsProductionOrderDo> {
    void publish(@Param("ids") List<String> productionOrderIds);

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


    List<String> getStartWorkById(@Param("ids") List<String> ids);

    List<String> getStartWorkByBlankId(@Param("ids") List<String> ids);

    List<ApsProductionOrderDo> getDataByBlankId(@Param("blankIds")List<String> blankids);

    @Select("select apd.ID,SUM(apop.PLANOUTPUTROLLCOUNT) AS 'PLANOUTPUTROLLCOUNTALL' from aps_product_detail apd LEFT JOIN aps_process_output_product apop ON apd.ID = apop.PRODUCTID AND apop.DELETED = 0 where apd.DELETED = 0 AND apd.MAINID = #{mainid} GROUP BY apd.ID")
    List<ProductDetailIdAndPlanOutPutRollCountAllVo> getProductDetailIdAndPlanOutPutRollCountAll(@Param("mainid") String mainid);

    @Select("select b.ID AS 'id',a.PID AS 'pid' from (select * from sys_dict where DICTTYPE = 'productType' AND DELETED = 0) a RIGHT JOIN (select * from sys_dict where DELETED = 0 AND ID in ('${join}')) b ON a.ID = b.PID")
    List<ProductTypeIdAndPidVo> selectProductTypeIdAndPid(@Param("join") String join);

    @Select("select o.ID,o.ORDERNO,o.CREATEUSERID,o.CREATEUSERNAME,u.EMAIL as MODIFYUSERNAME from aps_production_order o\n" +
            "left join sys_user u on o.CREATEUSERID=u.ID and u.DELETED='0'\n" +
            "where o.DELETED='0' and (o.AUDITSTATUS='待计划评审' or o.AUDITSTATUS='待技术评审') and o.ID='2024f94745144c779fcbd3a9f4d89254'\n" +
            "\tand ((IFNULL(o.CHANGEDATE,'')='' and TIMESTAMPDIFF(HOUR,o.ORDERDATE,NOW())>48) or (IFNULL(o.CHANGEDATE,'')!='' and TIMESTAMPDIFF(HOUR,o.CHANGEDATE,NOW())>48))")
    List<ApsProductionOrderDo> getOrderOuttimeAudit();
}




