package com.sw.mes.fb.accessory.dao;


import com.sw.mes.core.base.BaseDao;
import com.sw.mes.fb.accessory.entity.FbEquipmentAccessory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
* @Author
* @Description：
* @Date:
* @Modified By:
*/
public interface FbEquipmentAccessoryDao extends BaseDao<FbEquipmentAccessory, Long> {

    List<FbEquipmentAccessory> findByGoodsCodeAndDeletedOrderByIdDesc(String goodsCode, Integer deleted);

    @Query(value = "SELECT\n" +
            "\t*\n" +
            "FROM\n" +
            "(SELECT\n" +
            "\ta.id\n" +
            "\t,a.materialId\n" +
            "\t,a.deviceNo\n" +
            "\t,a.deviceSeat\n" +
            "\t,a.accessoryType\n" +
            "\t,a.materialCode\n" +
            "\t,a.materialName\n" +
            "\t,a.goodsCode\n" +
            "\t,a.useLife\n" +
            "\t,a.specification\n" +
            "\t,a.unitName\n" +
            "\t,a.factory\n" +
            "\t,a.operateDate\n" +
            "\t,a.useTime\n" +
            "\t,a.useLife - a.useTime remainLife\n" +
            "\t,a.warning\n" +
            "\t,a.warnTime\n" +
            "\t,IF(a.warning, IF(a.warnTime > a.useLife - a.useTime, 1, 0), 0) yujing\n" +
            "\t,a.safeCount\n" +
            "\t,a.singleCount\n" +
            "\t,a.cycleCount\n" +
            "FROM\n" +
            "(select \n" +
            "\tea.id\n" +
            "\t,ea.material_id materialId\n" +
            "\t,ie.`code` deviceNo                      #设备编号\n" +
            "\t,ea.device_seat deviceSeat               #设备位置\n" +
            "\t,am.accessory_type_value accessoryType    #辅料类型\n" +
            "\t,am.`codes` materialCode                 #料号\n" +
            "\t,am.`accessory_type_name` materialName   #料名称\n" +
            "\t,am.safe_count safeCount                 #安全线量\n" +
            "\t,am.single_count singleCount\t\t\t\t\t\t #单轴线量\n" +
            "\t,am.cycle_count cycleCount\t\t\t\t\t\t\t #循环线量\n" +
            "\t,ea.goods_code goodsCode                 #唯一码\n" +
            "\t,am.use_life useLife                     #额定寿命\n" +
            "\t,am.norms specification                  #规格\n" +
            "\t,fu.`name` unitName                      #单位\n" +
            "\t,ea.factory factory                      #厂家\n" +
            "\t,ea.operate_date operateDate              #更换时间\n" +
            "\t,ifnull(ea.use_time,0) + CASE id.`name` + am.accessory_type_value\n" +
            "\t\t\t\t\t\t\t\t\t\tWHEN '截断机切割线' THEN jdjg.count + jdfq.count\n" +
            "\t\t\t\t\t\t\t\t\t\tWHEN '截断机滑轮' THEN jdjg.count + jdfq.count\n" +
            "\t\t\t\t\t\t\t\t\t\tWHEN '切方机切割线' THEN kfjl.count\n" +
            "\t\t\t\t\t\t\t\t\t\tWHEN '切方机滑轮' THEN kfjl.count\n" +
            "\t\t\t\t\t\t\t\t\t\tWHEN '磨削机砂轮' THEN mxjl.count\n" +
            "\t\t\t\t\t\t\t\t\t\tWHEN '磨削机修整砂轮' THEN mxjl.len\n" +
            "\t\t\t\t\t\t\t\t\t\tELSE 0\n" +
            "\t\t\t\t\t\t\t\t\tEND useTime                    #TODO 已使用寿命\n" +
            "\t,am.warning warning                   #是否预警\n" +
            "\t,am.warn_time warnTime               #预警时间\n" +
            "\t## remainLife    #TODO 剩余寿命\n" +
            "\t,jdjg.count count1                            #截断加工\n" +
            "\t,jdfq.count count2                            #截断反切\n" +
            "\t,kfjl.count count3                            #开方记录\n" +
            "\t,mxjl.count count4                            #磨削记录\n" +
            "\t,mxjl.len                                #磨削记录\n" +
            "from zhxx_fb_equipment_accessory ea \n" +
            "LEFT JOIN zhxx_fb_accessory_material am ON am.id = ea.material_id\n" +
            "LEFT JOIN init_equipment ie ON ie.id = ea.equipment_id\n" +
            "LEFT JOIN init_device id ON id.id = ie.device_id\n" +
            "LEFT JOIN factory_unit fu ON fu.id = am.unit_id\n" +
            "LEFT JOIN (SELECT\n" +
            "\t\t\t\t\t\t\tea.id\n" +
            "\t\t\t\t\t\t\t,ie.`code`\n" +
            "\t\t\t\t\t\t\t,SUM(IFNULL(截断加工.normal_num,0)) + SUM(IFNULL(截断加工.reverse_num,0)) count\n" +
            "\t\t\t\t\t\tfrom zhxx_fb_equipment_accessory ea \n" +
            "\t\t\t\t\t\tLEFT JOIN init_equipment ie ON ie.id = ea.equipment_id\n" +
            "\t\t\t\t\t\tLEFT JOIN interface_eap_cut_craft as 截断加工 ON 截断加工.equip_no = ie.`code` AND 截断加工.start_cut > ea.operate_date\n" +
            "\t\t\t\t\t\tGROUP BY ea.id) jdjg ON jdjg.id = ea.id\n" +
            "LEFT JOIN (SELECT\n" +
            "\t\t\t\t\t\t\tea.id\n" +
            "\t\t\t\t\t\t\t,ie.`code`\n" +
            "\t\t\t\t\t\t\t,sum(IFNULL(截断反切.cut_num,0)) count\n" +
            "\t\t\t\t\t\tfrom zhxx_fb_equipment_accessory ea \n" +
            "\t\t\t\t\t\tLEFT JOIN init_equipment ie ON ie.id = ea.equipment_id\n" +
            "\t\t\t\t\t\tLEFT JOIN production_truncation_reccut as 截断反切 ON 截断反切.equipment_code = ie.`code` AND 截断反切.gmt_create > ea.operate_date\n" +
            "\t\t\t\t\t\tGROUP BY ea.id) jdfq ON jdfq.id = ea.id\n" +
            "LEFT JOIN (SELECT\n" +
            "\t\t\t\t\t\t\tea.id\n" +
            "\t\t\t\t\t\t\t,ie.`code`\n" +
            "\t\t\t\t\t\t\t,count(开方记录.id) count\n" +
            "\t\t\t\t\t\tfrom zhxx_fb_equipment_accessory ea \n" +
            "\t\t\t\t\t\tLEFT JOIN init_equipment ie ON ie.id = ea.equipment_id\n" +
            "\t\t\t\t\t\tLEFT JOIN (SELECT\n" +
            "\t\t\t\t\t\t\t\t\t\t\t\t\tr.id, r.equip_no, r.start_trimming\n" +
            "\t\t\t\t\t\t\t\t\t\t\t\tFROM (SELECT * FROM interface_eap_evolution_record GROUP BY sn) r \n" +
            "\t\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN interface_eap_retreat_feedback f ON r.sn = f.lot_no \n" +
            "\t\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN interface_eap_evolution_blanking g on g.sn = r.sn) as 开方记录 ON 开方记录.equip_no = ie.`code` AND 开方记录.start_trimming > ea.operate_date\n" +
            "\t\t\t\t\t\tGROUP BY ea.id) kfjl ON kfjl.id = ea.id\n" +
            "LEFT JOIN (SELECT\n" +
            "\t\t\t\t\t\t\tea.id\n" +
            "\t\t\t\t\t\t\t,ie.`code`\n" +
            "\t\t\t\t\t\t\t,count(磨削记录.id) count\n" +
            "\t\t\t\t\t\t\t,SUM(IFNULL(磨削记录.final_len,0)) len\n" +
            "\t\t\t\t\t\tfrom zhxx_fb_equipment_accessory ea \n" +
            "\t\t\t\t\t\tLEFT JOIN init_equipment ie ON ie.id = ea.equipment_id\n" +
            "\t\t\t\t\t\tLEFT JOIN (SELECT \n" +
            "\t\t\t\t\t\t\t\t\t\t\t\t\tm.id, m.equip_no, h.final_side, h.final_len, m.start_grinding\n" +
            "\t\t\t\t\t\t\t\t\t\t\t\tFROM interface_eap_grinding_machine m \n" +
            "\t\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN (SELECT * FROM interface_eap_grinding_blanking GROUP BY sn) h ON h.sn = m.sn) as 磨削记录 ON 磨削记录.equip_no = ie.`code` AND 磨削记录.start_grinding > ea.operate_date\n" +
            "\t\t\t\t\t\tGROUP BY ea.id) mxjl ON mxjl.id = ea.id\n" +
            "WHERE deleted = 0\n" +
            "\t\t\tAND IF(?1 is not NULL AND ?1 <> '', ie.`code` = ?1, 1=1)\n" +
            "\t\t\tAND IF(?2 is not NULL AND ?2 <> '', am.`accessory_type_name` = ?2, 1=1)\n" +
            "\t\t\tAND IF(?3 is not NULL AND ?3 <> '', am.`codes` = ?3, 1=1)\n" +
            "\t\t\tAND IF(?4 is not NULL AND ?4 <> '', ea.goods_code = ?4, 1=1)\n" +
            "\t\t\tAND IF(?5 is not NULL AND ?5 <> '', ea.factory = ?5, 1=1)\n" +
            "\t\t\tAND IF(?6 is not NULL AND ?6 <> '', ea.operate_date > ?6, 1=1)\n" +
            "\t\t\tAND IF(?7 is not NULL AND ?7 <> '', ea.operate_date <= ?7, 1=1)\n" +
            ") a\n" +
            ") b"
            ,countQuery = "select count(*) from zhxx_fb_equipment_accessory ea " +
            "LEFT JOIN init_equipment ie ON ie.id = ea.equipment_id\n" +
            "LEFT JOIN zhxx_fb_accessory_material am ON am.id = ea.material_id " +
            "where deleted = 0 " +
            "AND IF(?1 is not NULL AND ?1 <> '', ie.`code` = ?1, 1=1)\n" +
            "\t\t\tAND IF(?2 is not NULL AND ?2 <> '', am.`accessory_type_name` = ?2, 1=1)\n" +
            "\t\t\tAND IF(?3 is not NULL AND ?3 <> '', am.`codes` = ?3, 1=1)\n" +
            "\t\t\tAND IF(?4 is not NULL AND ?4 <> '', ea.goods_code = ?4, 1=1)\n" +
            "\t\t\tAND IF(?5 is not NULL AND ?5 <> '', ea.factory = ?5, 1=1)\n" +
            "\t\t\tAND IF(?6 is not NULL AND ?6 <> '', ea.operate_date > ?6, 1=1)\n" +
            "\t\t\tAND IF(?7 is not NULL AND ?7 <> '', ea.operate_date <= ?7, 1=1)",nativeQuery = true)
    Page<Map<String, Object>> newListByPage(String deviceNo, String materialName, String materialCode, String goodsCode, String factory, Date operateTimeStart, Date operateTimeEnd, Pageable pageable);

    @Query(value = "SELECT\n" +
            "\t*\n" +
            "FROM\n" +
            "(SELECT\n" +
            "\ta.id\n" +
            "\t,a.materialId\n" +
            "\t,a.deviceNo\n" +
            "\t,a.deviceSeat\n" +
            "\t,a.accessoryType\n" +
            "\t,a.materialCode\n" +
            "\t,a.materialName\n" +
            "\t,a.goodsCode\n" +
            "\t,a.useLife\n" +
            "\t,a.specification\n" +
            "\t,a.unitName\n" +
            "\t,a.factory\n" +
            "\t,a.operateDate\n" +
            "\t,a.useTime\n" +
            "\t,a.useLife - a.useTime remainLife\n" +
            "\t,a.warning\n" +
            "\t,a.warnTime\n" +
            "\t,IF(a.warning, IF(a.warnTime > a.useLife - a.useTime, 1, 0), 0) yujing\n" +
            "\t,a.safeCount\n" +
            "\t,a.singleCount\n" +
            "\t,a.cycleCount\n" +
            "FROM\n" +
            "(select \n" +
            "\tea.id\n" +
            "\t,ea.material_id materialId\n" +
            "\t,ie.`code` deviceNo                      #设备编号\n" +
            "\t,ea.device_seat deviceSeat               #设备位置\n" +
            "\t,am.accessory_type_value accessoryType    #辅料类型\n" +
            "\t,am.`codes` materialCode                 #料号\n" +
            "\t,am.`accessory_type_name` materialName   #料名称\n" +
            "\t,am.safe_count safeCount                 #安全线量\n" +
            "\t,am.single_count singleCount\t\t\t\t\t\t #单轴线量\n" +
            "\t,am.cycle_count cycleCount\t\t\t\t\t\t\t #循环线量\n" +
            "\t,ea.goods_code goodsCode                 #唯一码\n" +
            "\t,am.use_life useLife                     #额定寿命\n" +
            "\t,am.norms specification                  #规格\n" +
            "\t,fu.`name` unitName                      #单位\n" +
            "\t,ea.factory factory                      #厂家\n" +
            "\t,ea.operate_date operateDate              #更换时间\n" +
            "\t,ifnull(ea.use_time,0) + CASE id.`name` + am.accessory_type_value\n" +
            "\t\t\t\t\t\t\t\t\t\tWHEN '截断机切割线' THEN jdjg.count + jdfq.count\n" +
            "\t\t\t\t\t\t\t\t\t\tWHEN '截断机滑轮' THEN jdjg.count + jdfq.count\n" +
            "\t\t\t\t\t\t\t\t\t\tWHEN '切方机切割线' THEN kfjl.count\n" +
            "\t\t\t\t\t\t\t\t\t\tWHEN '切方机滑轮' THEN kfjl.count\n" +
            "\t\t\t\t\t\t\t\t\t\tWHEN '磨削机砂轮' THEN mxjl.count\n" +
            "\t\t\t\t\t\t\t\t\t\tWHEN '磨削机修整砂轮' THEN mxjl.len\n" +
            "\t\t\t\t\t\t\t\t\t\tELSE 0\n" +
            "\t\t\t\t\t\t\t\t\tEND useTime                    #TODO 已使用寿命\n" +
            "\t,am.warning warning                   #是否预警\n" +
            "\t,am.warn_time warnTime               #预警时间\n" +
            "\t## remainLife    #TODO 剩余寿命\n" +
            "\t,jdjg.count count1                            #截断加工\n" +
            "\t,jdfq.count count2                            #截断反切\n" +
            "\t,kfjl.count count3                            #开方记录\n" +
            "\t,mxjl.count count4                            #磨削记录\n" +
            "\t,mxjl.len                                #磨削记录\n" +
            "from zhxx_fb_equipment_accessory ea \n" +
            "LEFT JOIN zhxx_fb_accessory_material am ON am.id = ea.material_id\n" +
            "LEFT JOIN init_equipment ie ON ie.id = ea.equipment_id\n" +
            "LEFT JOIN init_device id ON id.id = ie.device_id\n" +
            "LEFT JOIN factory_unit fu ON fu.id = am.unit_id\n" +
            "LEFT JOIN (SELECT\n" +
            "\t\t\t\t\t\t\tea.id\n" +
            "\t\t\t\t\t\t\t,ie.`code`\n" +
            "\t\t\t\t\t\t\t,SUM(IFNULL(截断加工.normal_num,0)) + SUM(IFNULL(截断加工.reverse_num,0)) count\n" +
            "\t\t\t\t\t\tfrom zhxx_fb_equipment_accessory ea \n" +
            "\t\t\t\t\t\tLEFT JOIN init_equipment ie ON ie.id = ea.equipment_id\n" +
            "\t\t\t\t\t\tLEFT JOIN interface_eap_cut_craft as 截断加工 ON 截断加工.equip_no = ie.`code` AND 截断加工.start_cut > ea.operate_date\n" +
            "\t\t\t\t\t\tGROUP BY ea.id) jdjg ON jdjg.id = ea.id\n" +
            "LEFT JOIN (SELECT\n" +
            "\t\t\t\t\t\t\tea.id\n" +
            "\t\t\t\t\t\t\t,ie.`code`\n" +
            "\t\t\t\t\t\t\t,sum(IFNULL(截断反切.cut_num,0)) count\n" +
            "\t\t\t\t\t\tfrom zhxx_fb_equipment_accessory ea \n" +
            "\t\t\t\t\t\tLEFT JOIN init_equipment ie ON ie.id = ea.equipment_id\n" +
            "\t\t\t\t\t\tLEFT JOIN production_truncation_reccut as 截断反切 ON 截断反切.equipment_code = ie.`code` AND 截断反切.gmt_create > ea.operate_date\n" +
            "\t\t\t\t\t\tGROUP BY ea.id) jdfq ON jdfq.id = ea.id\n" +
            "LEFT JOIN (SELECT\n" +
            "\t\t\t\t\t\t\tea.id\n" +
            "\t\t\t\t\t\t\t,ie.`code`\n" +
            "\t\t\t\t\t\t\t,count(开方记录.id) count\n" +
            "\t\t\t\t\t\tfrom zhxx_fb_equipment_accessory ea \n" +
            "\t\t\t\t\t\tLEFT JOIN init_equipment ie ON ie.id = ea.equipment_id\n" +
            "\t\t\t\t\t\tLEFT JOIN (SELECT\n" +
            "\t\t\t\t\t\t\t\t\t\t\t\t\tr.id, r.equip_no, r.start_trimming\n" +
            "\t\t\t\t\t\t\t\t\t\t\t\tFROM (SELECT * FROM interface_eap_evolution_record GROUP BY sn) r \n" +
            "\t\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN interface_eap_retreat_feedback f ON r.sn = f.lot_no \n" +
            "\t\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN interface_eap_evolution_blanking g on g.sn = r.sn) as 开方记录 ON 开方记录.equip_no = ie.`code` AND 开方记录.start_trimming > ea.operate_date\n" +
            "\t\t\t\t\t\tGROUP BY ea.id) kfjl ON kfjl.id = ea.id\n" +
            "LEFT JOIN (SELECT\n" +
            "\t\t\t\t\t\t\tea.id\n" +
            "\t\t\t\t\t\t\t,ie.`code`\n" +
            "\t\t\t\t\t\t\t,count(磨削记录.id) count\n" +
            "\t\t\t\t\t\t\t,SUM(IFNULL(磨削记录.final_len,0)) len\n" +
            "\t\t\t\t\t\tfrom zhxx_fb_equipment_accessory ea \n" +
            "\t\t\t\t\t\tLEFT JOIN init_equipment ie ON ie.id = ea.equipment_id\n" +
            "\t\t\t\t\t\tLEFT JOIN (SELECT \n" +
            "\t\t\t\t\t\t\t\t\t\t\t\t\tm.id, m.equip_no, h.final_side, h.final_len, m.start_grinding\n" +
            "\t\t\t\t\t\t\t\t\t\t\t\tFROM interface_eap_grinding_machine m \n" +
            "\t\t\t\t\t\t\t\t\t\t\t\tLEFT JOIN (SELECT * FROM interface_eap_grinding_blanking GROUP BY sn) h ON h.sn = m.sn) as 磨削记录 ON 磨削记录.equip_no = ie.`code` AND 磨削记录.start_grinding > ea.operate_date\n" +
            "\t\t\t\t\t\tGROUP BY ea.id) mxjl ON mxjl.id = ea.id\n" +
            "WHERE deleted = 0\n" +
            "\t\t\tAND IF(?1 is not NULL AND ?1 <> '', ea.id = ?1, 1=1)\n" +
            ") a\n" +
            ") b",nativeQuery = true)
    Map<String, Object> getById(Long id);

    @Query(value = "SELECT * FROM production_equipment_extend_state pees WHERE pees.equipment_code = ?1", nativeQuery = true)
    Map<String, Object> getByCode(String equipmentCode); //获取当前设备的班次班组等信息

    @Query(value = "SELECT \n" +
            "\tao.id\n" +
            "\t,ao.material_code_before \tmaterialCode #物料编号\n" +
            "\t,sum(IFNULL(截断加工.round_length,0)) + sum(IFNULL(截断反切.cut_lenght,0)) sumCrystalLength #单晶累计长度\n" +
            "\t,ao.device_no deviceNo #设备号\n" +
            "\t,ao.device_seat deviceSeat #设备位置\n" +
            "\t,ao.goods_code_before goodsCode #唯一码\n" +
            "\t,ao.up_date `upDate` #换上时间\n" +
            "\t,(SELECT work_no from auth_user WHERE id = ao.up_user_id) upWorkNo #换上人工号\n" +
            "\t,ao.up_user upUser #换上人\n" +
            "\t,ao.up_class_no upClassNo #换上人班次\n" +
            "\t,ao.up_team_group upTeamGroup #换上人班组\n" +
            "\t,ao.specification_before specification #规格\n" +
            "\t,SUM(IFNULL(截断加工.normal_num,0)) + SUM(IFNULL(截断加工.reverse_num,0)) + sum(IFNULL(截断反切.cut_num,0)) sumCut #切割刀数\n" +
            "\t,ao.factory_before factory #厂家\n" +
            "\t,ao.remark remark #更换原因\n" +
            "\t,ao.use_time_before useTime #已使用寿命\n" +
            "\t,ao.down_date `downDate` #换下时间\n" +
            "\t,(SELECT work_no from auth_user WHERE id = ao.down_user_id) downWorkNo #换下人工号\n" +
            "\t,ao.down_user downUser #换下人\n" +
            "\t,ao.down_class_no downClassNo #换下人班次\n" +
            "\t,ao.down_team_group downTeamGroup #换下人班组\n" +
            "\t,ao.user_life_before useLife #额定寿命\n" +
            "\t,ao.remain_life_before remainLife #剩余寿命\n" +
            "\t,ROUND( (SUM(IFNULL(截断加工.normal_num,0)) + SUM(IFNULL(截断加工.reverse_num,0)) + sum(IFNULL(截断反切.cut_num,0)))/ao.user_life_before ,4) useRate #利用率\n" +
            "FROM zhxx_fb_accessory_order ao\n" +
            "LEFT JOIN interface_eap_cut_craft as 截断加工 ON 截断加工.equip_no = ao.device_no AND 截断加工.start_cut >= ao.up_date AND 截断加工.start_cut <= ao.down_date\n" +
            "LEFT JOIN production_truncation_reccut as 截断反切 ON 截断反切.equipment_code = ao.device_no AND 截断反切.gmt_create >= ao.up_date AND 截断反切.gmt_create <= ao.down_date\n" +
            "WHERE CONCAT(ao.device_type, ao.material_type_before) = '截断机滑轮'\n" +
            "\t\t\tAND IF(?1 is not NULL AND ?1 <> '', ao.goods_code_before = ?1, 1=1)\n" +
            "\t\t\tAND IF(?2 is not NULL AND ?2 <> '', ao.material_code_before = ?2, 1=1)\n" +
            "\t\t\tAND IF(?3 is not NULL AND ?3 <> '', ao.device_no = ?3, 1=1)\n" +
            "\t\t\tAND IF(?4 is not NULL AND ?4 <> '', ao.up_date >= ?4, 1=1)\n" +
            "\t\t\tAND IF(?5 is not NULL AND ?5 <> '', ao.up_date <= ?5, 1=1)\n" +
            "\t\t\tAND IF(?6 is not NULL AND ?6 <> '', ao.down_date >= ?6, 1=1)\n" +
            "\t\t\tAND IF(?7 is not NULL AND ?7 <> '', ao.down_date <= ?7, 1=1)\n" +
            "GROUP BY ao.id,ao.device_no"
            ,countQuery = "SELECT \n" +
            "\tcount(*)\n" +
            "FROM zhxx_fb_accessory_order ao\n" +
            "LEFT JOIN interface_eap_cut_craft as 截断加工 ON 截断加工.equip_no = ao.device_no AND 截断加工.start_cut >= ao.up_date AND 截断加工.start_cut <= ao.down_date\n" +
            "LEFT JOIN production_truncation_reccut as 截断反切 ON 截断反切.equipment_code = ao.device_no AND 截断反切.gmt_create >= ao.up_date AND 截断反切.gmt_create <= ao.down_date\n" +
            "WHERE CONCAT(ao.device_type, ao.material_type_before) = '截断机滑轮'\n" +
            "\t\t\tAND IF(?1 is not NULL AND ?1 <> '', ao.goods_code_before = ?1, 1=1)\n" +
            "\t\t\tAND IF(?2 is not NULL AND ?2 <> '', ao.material_code_before = ?2, 1=1)\n" +
            "\t\t\tAND IF(?3 is not NULL AND ?3 <> '', ao.device_no = ?3, 1=1)\n" +
            "\t\t\tAND IF(?4 is not NULL AND ?4 <> '', ao.up_date >= ?4, 1=1)\n" +
            "\t\t\tAND IF(?5 is not NULL AND ?5 <> '', ao.up_date <= ?5, 1=1)\n" +
            "\t\t\tAND IF(?6 is not NULL AND ?6 <> '', ao.down_date >= ?6, 1=1)\n" +
            "\t\t\tAND IF(?7 is not NULL AND ?7 <> '', ao.down_date <= ?7, 1=1)\n" +
            "GROUP BY ao.id,ao.device_no",nativeQuery = true)
    Page<Map<String, Object>> jdjhl(String goodsCode, String materialCode, String deviceNo, Date startUpDate, Date endUpDate, Date startDownDate, Date endDownDate, Pageable pageable);

    @Query(value = "SELECT \n" +
            "\t 截断加工.round_sn `no` #编号\n" +
            "\t ,截断加工.round_length length #长度\n" +
            "\t ,IFNULL(截断加工.normal_num, 0) + IFNULL(截断加工.reverse_num, 0) cut #刀数\n" +
            "FROM interface_eap_cut_craft as 截断加工\n" +
            "WHERE 1=1\n" +
            "\t\t\tAND IF(?1 is not NULL AND ?1 <> '', 截断加工.equip_no = ?1, 1=1)\n" +
            "\t\t\tAND IF(?2 is not NULL AND ?2 <> '', 截断加工.start_cut >= ?2, 1=1)\n" +
            "\t\t\tAND IF(?3 is not NULL AND ?3 <> '', 截断加工.start_cut <= ?3, 1=1)\n" +
            "\n" +
            "UNION ALL\n" +
            "\t\t\t\n" +
            "SELECT \n" +
            "\t 截断反切.crystal_no `no` #编号\n" +
            "\t ,截断反切.cut_lenght length #长度\n" +
            "\t ,IFNULL(截断反切.cut_num, 0) cut #刀数\n" +
            "FROM production_truncation_reccut as 截断反切\n" +
            "WHERE 1=1\n" +
            "\t\t\tAND IF(?1 is not NULL AND ?1 <> '', 截断反切.equipment_code = ?1, 1=1)\n" +
            "\t\t\tAND IF(?2 is not NULL AND ?2 <> '', 截断反切.gmt_create >= ?2, 1=1)\n" +
            "\t\t\tAND IF(?3 is not NULL AND ?3 <> '', 截断反切.gmt_create <= ?3, 1=1)", nativeQuery = true)
    List<Map<String, Object>> jdjhlDetail(String deviceNo, Date upDate, Date downDate);

    @Query(value = "SELECT \n" +
            "\tao.id\n" +
            "\t,ao.material_code_before \tmaterialCode #物料编号\n" +
            "\t,sum(IFNULL(截断加工.round_length,0)) + sum(IFNULL(截断反切.cut_lenght,0)) sumCrystalLength #单晶累计长度\n" +
            "\t,ao.device_no deviceNo #设备号\n" +
            "\t,ao.device_seat deviceSeat #设备位置\n" +
            "\t,ao.goods_code_before goodsCode #唯一码\n" +
            "\t,ao.up_date `upDate` #换上时间\n" +
            "\t,(SELECT work_no from auth_user WHERE id = ao.up_user_id) upWorkNo #换上人工号\n" +
            "\t,ao.up_user upUser #换上人\n" +
            "\t,ao.up_class_no upClassNo #换上人班次\n" +
            "\t,ao.up_team_group upTeamGroup #换上人班组\n" +
            "\t,ao.specification_before specification #规格\n" +
            "\t,SUM(IFNULL(截断加工.normal_num,0)) + SUM(IFNULL(截断加工.reverse_num,0)) + sum(IFNULL(截断反切.cut_num,0)) sumCut #切割刀数\n" +
            "\t,ao.factory_before factory #厂家\n" +
            "\t,ao.remark remark #更换原因\n" +
            "\t,ao.use_time_before useTime #已使用寿命\n" +
            "\t,ao.down_date `downDate` #换下时间\n" +
            "\t,(SELECT work_no from auth_user WHERE id = ao.down_user_id) downWorkNo #换下人工号\n" +
            "\t,ao.down_user downUser #换下人\n" +
            "\t,ao.down_class_no downClassNo #换下人班次\n" +
            "\t,ao.down_team_group downTeamGroup #换下人班组\n" +
            "\t,ao.user_life_before useLife #额定寿命\n" +
            "\t,ao.remain_life_before remainLife #剩余寿命\n" +
            "\t,ROUND( (SUM(IFNULL(截断加工.normal_num,0)) + SUM(IFNULL(截断加工.reverse_num,0)) + sum(IFNULL(截断反切.cut_num,0)))/ao.user_life_before ,4) useRate #利用率\n" +
            "FROM zhxx_fb_accessory_order ao\n" +
            "LEFT JOIN interface_eap_cut_craft as 截断加工 ON 截断加工.equip_no = ao.device_no AND 截断加工.start_cut >= ao.up_date AND 截断加工.start_cut <= ao.down_date\n" +
            "LEFT JOIN production_truncation_reccut as 截断反切 ON 截断反切.equipment_code = ao.device_no AND 截断反切.gmt_create >= ao.up_date AND 截断反切.gmt_create <= ao.down_date\n" +
            "WHERE CONCAT(ao.device_type, ao.material_type_before) = '截断机切割线'\n" +
            "\t\t\tAND IF(?1 is not NULL AND ?1 <> '', ao.goods_code_before = ?1, 1=1)\n" +
            "\t\t\tAND IF(?2 is not NULL AND ?2 <> '', ao.material_code_before = ?2, 1=1)\n" +
            "\t\t\tAND IF(?3 is not NULL AND ?3 <> '', ao.device_no = ?3, 1=1)\n" +
            "\t\t\tAND IF(?4 is not NULL AND ?4 <> '', ao.up_date >= ?4, 1=1)\n" +
            "\t\t\tAND IF(?5 is not NULL AND ?5 <> '', ao.up_date <= ?5, 1=1)\n" +
            "\t\t\tAND IF(?6 is not NULL AND ?6 <> '', ao.down_date >= ?6, 1=1)\n" +
            "\t\t\tAND IF(?7 is not NULL AND ?7 <> '', ao.down_date <= ?7, 1=1)\n" +
            "GROUP BY ao.id,ao.device_no"
            ,countQuery = "SELECT \n" +
            "\tcount(*)\n" +
            "FROM zhxx_fb_accessory_order ao\n" +
            "LEFT JOIN interface_eap_cut_craft as 截断加工 ON 截断加工.equip_no = ao.device_no AND 截断加工.start_cut >= ao.up_date AND 截断加工.start_cut <= ao.down_date\n" +
            "LEFT JOIN production_truncation_reccut as 截断反切 ON 截断反切.equipment_code = ao.device_no AND 截断反切.gmt_create >= ao.up_date AND 截断反切.gmt_create <= ao.down_date\n" +
            "WHERE CONCAT(ao.device_type, ao.material_type_before) = '截断机切割线'\n" +
            "\t\t\tAND IF(?1 is not NULL AND ?1 <> '', ao.goods_code_before = ?1, 1=1)\n" +
            "\t\t\tAND IF(?2 is not NULL AND ?2 <> '', ao.material_code_before = ?2, 1=1)\n" +
            "\t\t\tAND IF(?3 is not NULL AND ?3 <> '', ao.device_no = ?3, 1=1)\n" +
            "\t\t\tAND IF(?4 is not NULL AND ?4 <> '', ao.up_date >= ?4, 1=1)\n" +
            "\t\t\tAND IF(?5 is not NULL AND ?5 <> '', ao.up_date <= ?5, 1=1)\n" +
            "\t\t\tAND IF(?6 is not NULL AND ?6 <> '', ao.down_date >= ?6, 1=1)\n" +
            "\t\t\tAND IF(?7 is not NULL AND ?7 <> '', ao.down_date <= ?7, 1=1)\n" +
            "GROUP BY ao.id,ao.device_no",nativeQuery = true)
    Page<Map<String, Object>> jdjqgx(String goodsCode, String materialCode, String deviceNo, Date startUpDate, Date endUpStart, Date startDownDate, Date endDownDate, Pageable pageable);

    @Query(value = "SELECT \n" +
            "\t 截断加工.round_sn `no` #编号\n" +
            "\t ,截断加工.round_length length #长度\n" +
            "\t ,IFNULL(截断加工.normal_num, 0) + IFNULL(截断加工.reverse_num, 0) cut #刀数\n" +
            "FROM interface_eap_cut_craft as 截断加工\n" +
            "WHERE 1=1\n" +
            "\t\t\tAND IF(?1 is not NULL AND ?1 <> '', 截断加工.equip_no = ?1, 1=1)\n" +
            "\t\t\tAND IF(?2 is not NULL AND ?2 <> '', 截断加工.start_cut >= ?2, 1=1)\n" +
            "\t\t\tAND IF(?3 is not NULL AND ?3 <> '', 截断加工.start_cut <= ?3, 1=1)\n" +
            "\n" +
            "UNION ALL\n" +
            "\t\t\t\n" +
            "SELECT \n" +
            "\t 截断反切.crystal_no `no` #编号\n" +
            "\t ,截断反切.cut_lenght length #长度\n" +
            "\t ,IFNULL(截断反切.cut_num, 0) cut #刀数\n" +
            "FROM production_truncation_reccut as 截断反切\n" +
            "WHERE 1=1\n" +
            "\t\t\tAND IF(?1 is not NULL AND ?1 <> '', 截断反切.equipment_code = ?1, 1=1)\n" +
            "\t\t\tAND IF(?2 is not NULL AND ?2 <> '', 截断反切.gmt_create >= ?2, 1=1)\n" +
            "\t\t\tAND IF(?3 is not NULL AND ?3 <> '', 截断反切.gmt_create <= ?3, 1=1)",nativeQuery = true)
    List<Map<String, Object>> jdjqgxDetail(String deviceNo, Date upDate, Date downDate);

    @Query(value = "SELECT \n" +
            "\tao.id\n" +
            "\t,ao.material_code_before \tmaterialCode #物料编号\n" +
            "\t,SUM(IFNULL(磨削记录.final_len,0)) sumCrystalLength #单晶累计长度\n" +
            "\t,ao.device_no deviceNo #设备号\n" +
            "\t,ao.device_seat deviceSeat #设备位置\n" +
            "\t,ao.goods_code_before goodsCode #唯一码\n" +
            "\t,ao.up_date `upDate` #换上时间\n" +
            "\t,(SELECT work_no from auth_user WHERE id = ao.up_user_id) upWorkNo #换上人工号\n" +
            "\t,ao.up_user upUser #换上人\n" +
            "\t,ao.up_class_no upClassNo #换上人班次\n" +
            "\t,ao.up_team_group upTeamGroup #换上人班组\n" +
            "\t,ao.specification_before specification #规格\n" +
            "\t,COUNT(磨削记录.id) sumCount #加工颗数\n" +
            "\t,ao.factory_before factory #厂家\n" +
            "\t,ao.remark remark #更换原因\n" +
            "\t,ao.use_time_before useTime #已使用寿命\n" +
            "\t,ao.down_date `downDate` #换下时间\n" +
            "\t,(SELECT work_no from auth_user WHERE id = ao.down_user_id) downWorkNo #换下人工号\n" +
            "\t,ao.down_user downUser #换下人\n" +
            "\t,ao.down_class_no downClassNo #换下人班次\n" +
            "\t,ao.down_team_group downTeamGroup #换下人班组\n" +
            "\t,ao.user_life_before useLife #额定寿命\n" +
            "\t,ao.remain_life_before remainLife #剩余寿命\n" +
            "\t,ROUND( (COUNT(磨削记录.id))/ao.user_life_before ,4) useRate #利用率\n" +
            "FROM zhxx_fb_accessory_order ao\n" +
            "LEFT JOIN (SELECT \n" +
            "\t\t\t\t\t\t\tm.id, m.equip_no, h.final_side, h.final_len, m.start_grinding\n" +
            "\t\t\t\t\t\tFROM interface_eap_grinding_machine m \n" +
            "\t\t\t\t\t\tLEFT JOIN (SELECT * FROM interface_eap_grinding_blanking GROUP BY sn) h ON h.sn = m.sn) as 磨削记录 \n" +
            "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tON 磨削记录.equip_no = ao.device_no AND 磨削记录.start_grinding >= ao.up_date AND 磨削记录.start_grinding <= ao.down_date\n" +
            "WHERE CONCAT(ao.device_type, ao.material_type_before) = '磨削机砂轮'\n" +
            "\t\t\tAND IF(?1 is not NULL AND ?1 <> '', ao.goods_code_before = ?1, 1=1)\n" +
            "\t\t\tAND IF(?2 is not NULL AND ?2 <> '', ao.material_code_before = ?2, 1=1)\n" +
            "\t\t\tAND IF(?3 is not NULL AND ?3 <> '', ao.device_no = ?3, 1=1)\n" +
            "\t\t\tAND IF(?4 is not NULL AND ?4 <> '', ao.up_date >= ?4, 1=1)\n" +
            "\t\t\tAND IF(?5 is not NULL AND ?5 <> '', ao.up_date <= ?5, 1=1)\n" +
            "\t\t\tAND IF(?6 is not NULL AND ?6 <> '', ao.down_date >= ?6, 1=1)\n" +
            "\t\t\tAND IF(?7 is not NULL AND ?7 <> '', ao.down_date <= ?7, 1=1)\n" +
            "GROUP BY ao.id,ao.device_no"
            ,countQuery = "SELECT \n" +
            "\tcount(*)\n" +
            "FROM zhxx_fb_accessory_order ao\n" +
            "LEFT JOIN (SELECT \n" +
            "\t\t\t\t\t\t\tm.id, m.equip_no, h.final_side, h.final_len, m.start_grinding\n" +
            "\t\t\t\t\t\tFROM interface_eap_grinding_machine m \n" +
            "\t\t\t\t\t\tLEFT JOIN (SELECT * FROM interface_eap_grinding_blanking GROUP BY sn) h ON h.sn = m.sn) as 磨削记录 \n" +
            "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tON 磨削记录.equip_no = ao.device_no AND 磨削记录.start_grinding >= ao.up_date AND 磨削记录.start_grinding <= ao.down_date\n" +
            "WHERE CONCAT(ao.device_type, ao.material_type_before) = '磨削机砂轮'\n" +
            "\t\t\tAND IF(?1 is not NULL AND ?1 <> '', ao.goods_code_before = ?1, 1=1)\n" +
            "\t\t\tAND IF(?2 is not NULL AND ?2 <> '', ao.material_code_before = ?2, 1=1)\n" +
            "\t\t\tAND IF(?3 is not NULL AND ?3 <> '', ao.device_no = ?3, 1=1)\n" +
            "\t\t\tAND IF(?4 is not NULL AND ?4 <> '', ao.up_date >= ?4, 1=1)\n" +
            "\t\t\tAND IF(?5 is not NULL AND ?5 <> '', ao.up_date <= ?5, 1=1)\n" +
            "\t\t\tAND IF(?6 is not NULL AND ?6 <> '', ao.down_date >= ?6, 1=1)\n" +
            "\t\t\tAND IF(?7 is not NULL AND ?7 <> '', ao.down_date <= ?7, 1=1)\n" +
            "GROUP BY ao.id,ao.device_no",nativeQuery = true)
    Page<Map<String, Object>> mxjsl(String goodsCode, String materialCode, String deviceNo, Date startUpDate, Date endUpDate, Date startDownDate, Date endDownDate, Pageable pageable);

    @Query(value = "SELECT \n" +
            "\tm.id\n" +
            "\t, m.equip_no\n" +
            "\t, h.final_side\n" +
            "\t, h.final_len length\n" +
            "\t, m.sn `no`\n" +
            "\t, m.start_grinding\n" +
            "FROM interface_eap_grinding_machine m \n" +
            "LEFT JOIN (SELECT * FROM interface_eap_grinding_blanking GROUP BY sn) h ON h.sn = m.sn\n" +
            "WHERE 1=1\n" +
            "\t\t\tAND IF(?1 is not NULL AND ?1 <> '', m.equip_no = ?1, 1=1)\n" +
            "\t\t\tAND IF(?2 is not NULL AND ?2 <> '', m.start_grinding >= ?2, 1=1)\n" +
            "\t\t\tAND IF(?3 is not NULL AND ?3 <> '', m.start_grinding <= ?3, 1=1)",nativeQuery = true)
    List<Map<String, Object>> mxjslDetail(String deviceNo, Date upDate, Date downDate);

    @Query(value = "SELECT \n" +
            "\tao.id\n" +
            "\t,ao.material_code_before \tmaterialCode #物料编号\n" +
            "\t,SUM(IFNULL(磨削记录.final_len,0)) sumCrystalLength #单晶累计长度\n" +
            "\t,ao.device_no deviceNo #设备号\n" +
            "\t,ao.device_seat deviceSeat #设备位置\n" +
            "\t,ao.goods_code_before goodsCode #唯一码\n" +
            "\t,ao.up_date `upDate` #换上时间\n" +
            "\t,(SELECT work_no from auth_user WHERE id = ao.up_user_id) upWorkNo #换上人工号\n" +
            "\t,ao.up_user upUser #换上人\n" +
            "\t,ao.up_class_no upClassNo #换上人班次\n" +
            "\t,ao.up_team_group upTeamGroup #换上人班组\n" +
            "\t,ao.specification_before specification #规格\n" +
            "\t,COUNT(磨削记录.id) sumCount #加工颗数\n" +
            "\t,ao.factory_before factory #厂家\n" +
            "\t,ao.remark remark #更换原因\n" +
            "\t,ao.use_time_before useTime #已使用寿命\n" +
            "\t,ao.down_date `downDate` #换下时间\n" +
            "\t,(SELECT work_no from auth_user WHERE id = ao.down_user_id) downWorkNo #换下人工号\n" +
            "\t,ao.down_user downUser #换下人\n" +
            "\t,ao.down_class_no downClassNo #换下人班次\n" +
            "\t,ao.down_team_group downTeamGroup #换下人班组\n" +
            "\t,ao.user_life_before useLife #额定寿命\n" +
            "\t,ao.remain_life_before remainLife #剩余寿命\n" +
            "\t,ROUND( (COUNT(磨削记录.id))/ao.user_life_before ,4) useRate #利用率\n" +
            "FROM zhxx_fb_accessory_order ao\n" +
            "LEFT JOIN (SELECT \n" +
            "\t\t\t\t\t\t\tm.id, m.equip_no, h.final_side, h.final_len, m.start_grinding\n" +
            "\t\t\t\t\t\tFROM interface_eap_grinding_machine m \n" +
            "\t\t\t\t\t\tLEFT JOIN (SELECT * FROM interface_eap_grinding_blanking GROUP BY sn) h ON h.sn = m.sn) as 磨削记录 \n" +
            "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tON 磨削记录.equip_no = ao.device_no AND 磨削记录.start_grinding >= ao.up_date AND 磨削记录.start_grinding <= ao.down_date\n" +
            "WHERE CONCAT(ao.device_type, ao.material_type_before) = '磨削机修整砂轮'\n" +
            "\t\t\tAND IF(?1 is not NULL AND ?1 <> '', ao.goods_code_before = ?1, 1=1)\n" +
            "\t\t\tAND IF(?2 is not NULL AND ?2 <> '', ao.material_code_before = ?2, 1=1)\n" +
            "\t\t\tAND IF(?3 is not NULL AND ?3 <> '', ao.device_no = ?3, 1=1)\n" +
            "\t\t\tAND IF(?4 is not NULL AND ?4 <> '', ao.up_date >= ?4, 1=1)\n" +
            "\t\t\tAND IF(?5 is not NULL AND ?5 <> '', ao.up_date <= ?5, 1=1)\n" +
            "\t\t\tAND IF(?6 is not NULL AND ?6 <> '', ao.down_date >= ?6, 1=1)\n" +
            "\t\t\tAND IF(?7 is not NULL AND ?7 <> '', ao.down_date <= ?7, 1=1)\n" +
            "GROUP BY ao.id,ao.device_no"
            ,countQuery = "SELECT \n" +
            "\tcount(*)\n" +
            "WHERE CONCAT(ao.device_type, ao.material_type_before) = '磨削机修整砂轮'\n" +
            "\t\t\tAND IF(?1 is not NULL AND ?1 <> '', ao.goods_code_before = ?1, 1=1)\n" +
            "\t\t\tAND IF(?2 is not NULL AND ?2 <> '', ao.material_code_before = ?2, 1=1)\n" +
            "\t\t\tAND IF(?3 is not NULL AND ?3 <> '', ao.device_no = ?3, 1=1)\n" +
            "\t\t\tAND IF(?4 is not NULL AND ?4 <> '', ao.up_date >= ?4, 1=1)\n" +
            "\t\t\tAND IF(?5 is not NULL AND ?5 <> '', ao.up_date <= ?5, 1=1)\n" +
            "\t\t\tAND IF(?6 is not NULL AND ?6 <> '', ao.down_date >= ?6, 1=1)\n" +
            "\t\t\tAND IF(?7 is not NULL AND ?7 <> '', ao.down_date <= ?7, 1=1)\n" +
            "GROUP BY ao.id,ao.device_no",nativeQuery = true)
    Page<Map<String, Object>> mxjxzsl(String goodsCode, String materialCode, String deviceNo, Date startUpDate, Date endUpDate, Date startDownDate, Date endDownDate, Pageable pageable);

    @Query(value = "SELECT \n" +
            "\tm.id\n" +
            "\t, m.equip_no\n" +
            "\t, h.final_side\n" +
            "\t, h.final_len length\n" +
            "\t, m.sn `no`\n" +
            "\t, m.start_grinding\n" +
            "FROM interface_eap_grinding_machine m \n" +
            "LEFT JOIN (SELECT * FROM interface_eap_grinding_blanking GROUP BY sn) h ON h.sn = m.sn\n" +
            "WHERE 1=1\n" +
            "\t\t\tAND IF(?1 is not NULL AND ?1 <> '', m.equip_no = ?1, 1=1)\n" +
            "\t\t\tAND IF(?2 is not NULL AND ?2 <> '', m.start_grinding >= ?2, 1=1)\n" +
            "\t\t\tAND IF(?3 is not NULL AND ?3 <> '', m.start_grinding <= ?3, 1=1)",nativeQuery = true)
    List<Map<String, Object>> mxjxzslDetail(String deviceNo, Date upDate, Date downDate);

    @Query(value = "SELECT \n" +
            "\tao.id\n" +
            "\t,ao.material_code_before \tmaterialCode #物料编号\n" +
            "\t,SUM(IFNULL(开方记录.ware_house_length,0)) sumCrystalLength #单晶累计长度\n" +
            "\t,ao.device_no deviceNo #设备号\n" +
            "\t,ao.device_seat deviceSeat #设备位置\n" +
            "\t,ao.goods_code_before goodsCode #唯一码\n" +
            "\t,ao.up_date `upDate` #换上时间\n" +
            "\t,(SELECT work_no from auth_user WHERE id = ao.up_user_id) upWorkNo #换上人工号\n" +
            "\t,ao.up_user upUser #换上人\n" +
            "\t,ao.up_class_no upClassNo #换上人班次\n" +
            "\t,ao.up_team_group upTeamGroup #换上人班组\n" +
            "\t,ao.specification_before specification #规格\n" +
            "\t,COUNT(开方记录.id) sumCount #加工颗数\n" +
            "\t,ao.factory_before factory #厂家\n" +
            "\t,ao.remark remark #更换原因\n" +
            "\t,ao.use_time_before useTime #已使用寿命\n" +
            "\t,ao.down_date `downDate` #换下时间\n" +
            "\t,(SELECT work_no from auth_user WHERE id = ao.down_user_id) downWorkNo #换下人工号\n" +
            "\t,ao.down_user downUser #换下人\n" +
            "\t,ao.down_class_no downClassNo #换下人班次\n" +
            "\t,ao.down_team_group downTeamGroup #换下人班组\n" +
            "\t,ao.user_life_before useLife #额定寿命\n" +
            "\t,ao.remain_life_before remainLife #剩余寿命\n" +
            "\t,ROUND( (COUNT(开方记录.id))/ao.user_life_before ,4) useRate #利用率\n" +
            "FROM zhxx_fb_accessory_order ao\n" +
            "LEFT JOIN (SELECT\n" +
            "\t\t\t\t\t\t\tr.id\n" +
            "\t\t\t\t\t\t\t, r.equip_no\n" +
            "\t\t\t\t\t\t\t, r.start_trimming\n" +
            "\t\t\t\t\t\t\t, yb.ware_house_length#长度\n" +
            "\t\t\t\t\t\t\t, r.sn\n" +
            "\t\t\t\t\t\tFROM (SELECT * FROM interface_eap_evolution_record GROUP BY sn) r \n" +
            "\t\t\t\t\t\tLEFT JOIN interface_eap_retreat_feedback f ON r.sn = f.lot_no \n" +
            "\t\t\t\t\t\tLEFT JOIN interface_eap_evolution_blanking g on g.sn = r.sn\n" +
            "\t\t\t\t\t\tLEFT JOIN warehousing_statistics_info_yb yb ON yb.section_no = r.sn) as 开方记录 \n" +
            "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tON 开方记录.equip_no = ao.device_no AND 开方记录.start_trimming >= ao.up_date AND 开方记录.start_trimming <= ao.down_date\n" +
            "WHERE CONCAT(ao.device_type, ao.material_type_before) = '切方机滑轮'\n" +
            "\t\t\tAND IF(?1 is not NULL AND ?1 <> '', ao.goods_code_before = ?1, 1=1)\n" +
            "\t\t\tAND IF(?2 is not NULL AND ?2 <> '', ao.material_code_before = ?2, 1=1)\n" +
            "\t\t\tAND IF(?3 is not NULL AND ?3 <> '', ao.device_no = ?3, 1=1)\n" +
            "\t\t\tAND IF(?4 is not NULL AND ?4 <> '', ao.up_date >= ?4, 1=1)\n" +
            "\t\t\tAND IF(?5 is not NULL AND ?5 <> '', ao.up_date <= ?5, 1=1)\n" +
            "\t\t\tAND IF(?6 is not NULL AND ?6 <> '', ao.down_date >= ?6, 1=1)\n" +
            "\t\t\tAND IF(?7 is not NULL AND ?7 <> '', ao.down_date <= ?7, 1=1)\n" +
            "GROUP BY ao.id,ao.device_no"
            ,countQuery = "SELECT \n" +
            "\tcount(*)\n" +
            "FROM zhxx_fb_accessory_order ao\n" +
            "LEFT JOIN (SELECT\n" +
            "\t\t\t\t\t\t\tr.id\n" +
            "\t\t\t\t\t\t\t, r.equip_no\n" +
            "\t\t\t\t\t\t\t, r.start_trimming\n" +
            "\t\t\t\t\t\t\t, yb.ware_house_length#长度\n" +
            "\t\t\t\t\t\t\t, r.sn\n" +
            "\t\t\t\t\t\tFROM (SELECT * FROM interface_eap_evolution_record GROUP BY sn) r \n" +
            "\t\t\t\t\t\tLEFT JOIN interface_eap_retreat_feedback f ON r.sn = f.lot_no \n" +
            "\t\t\t\t\t\tLEFT JOIN interface_eap_evolution_blanking g on g.sn = r.sn\n" +
            "\t\t\t\t\t\tLEFT JOIN warehousing_statistics_info_yb yb ON yb.section_no = r.sn) as 开方记录 \n" +
            "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tON 开方记录.equip_no = ao.device_no AND 开方记录.start_trimming >= ao.up_date AND 开方记录.start_trimming <= ao.down_date\n" +
            "WHERE CONCAT(ao.device_type, ao.material_type_before) = '切方机滑轮'\n" +
            "\t\t\tAND IF(?1 is not NULL AND ?1 <> '', ao.goods_code_before = ?1, 1=1)\n" +
            "\t\t\tAND IF(?2 is not NULL AND ?2 <> '', ao.material_code_before = ?2, 1=1)\n" +
            "\t\t\tAND IF(?3 is not NULL AND ?3 <> '', ao.device_no = ?3, 1=1)\n" +
            "\t\t\tAND IF(?4 is not NULL AND ?4 <> '', ao.up_date >= ?4, 1=1)\n" +
            "\t\t\tAND IF(?5 is not NULL AND ?5 <> '', ao.up_date <= ?5, 1=1)\n" +
            "\t\t\tAND IF(?6 is not NULL AND ?6 <> '', ao.down_date >= ?6, 1=1)\n" +
            "\t\t\tAND IF(?7 is not NULL AND ?7 <> '', ao.down_date <= ?7, 1=1)\n" +
            "GROUP BY ao.id,ao.device_no",nativeQuery = true)
    Page<Map<String, Object>> qfjhl(String goodsCode, String materialCode, String deviceNo, Date startUpDate, Date endUpDate, Date startDownDate, Date endDownDate, Pageable pageable);

    @Query(value = "SELECT\n" +
            "\tr.id\n" +
            "\t, r.equip_no\n" +
            "\t, r.start_trimming\n" +
            "\t, yb.ware_house_length length#长度\n" +
            "\t, r.sn `no`\n" +
            "FROM (SELECT * FROM interface_eap_evolution_record GROUP BY sn) r \n" +
            "LEFT JOIN interface_eap_retreat_feedback f ON r.sn = f.lot_no \n" +
            "LEFT JOIN interface_eap_evolution_blanking g on g.sn = r.sn\n" +
            "LEFT JOIN warehousing_statistics_info_yb yb ON yb.section_no = r.sn\n" +
            "WHERE 1=1\n" +
            "\t\t\tAND IF(?1 is not NULL AND ?1 <> '', r.equip_no = ?1, 1=1)\n" +
            "\t\t\tAND IF(?2 is not NULL AND ?2 <> '', r.start_trimming >= ?2, 1=1)\n" +
            "\t\t\tAND IF(?3 is not NULL AND ?3 <> '', r.start_trimming <= ?3, 1=1)",nativeQuery = true)
    List<Map<String, Object>> qfjhlDetail(String deviceNo, Date upDate, Date downDate);

    @Query(value = "SELECT \n" +
            "\tao.id\n" +
            "\t,ao.material_code_before \tmaterialCode #物料编号\n" +
            "\t,SUM(IFNULL(开方记录.ware_house_length,0)) sumCrystalLength #单晶累计长度\n" +
            "\t,ao.device_no deviceNo #设备号\n" +
            "\t,ao.device_seat deviceSeat #设备位置\n" +
            "\t,ao.goods_code_before goodsCode #唯一码\n" +
            "\t,ao.up_date `upDate` #换上时间\n" +
            "\t,(SELECT work_no from auth_user WHERE id = ao.up_user_id) upWorkNo #换上人工号\n" +
            "\t,ao.up_user upUser #换上人\n" +
            "\t,ao.up_class_no upClassNo #换上人班次\n" +
            "\t,ao.up_team_group upTeamGroup #换上人班组\n" +
            "\t,ao.specification_before specification #规格\n" +
            "\t,COUNT(开方记录.id) sumCount #加工颗数\n" +
            "\t,ao.factory_before factory #厂家\n" +
            "\t,ao.remark remark #更换原因\n" +
            "\t,ao.use_time_before useTime #已使用寿命\n" +
            "\t,ao.down_date `downDate` #换下时间\n" +
            "\t,(SELECT work_no from auth_user WHERE id = ao.down_user_id) downWorkNo #换下人工号\n" +
            "\t,ao.down_user downUser #换下人\n" +
            "\t,ao.down_class_no downClassNo #换下人班次\n" +
            "\t,ao.down_team_group downTeamGroup #换下人班组\n" +
            "\t,ao.user_life_before useLife #额定寿命\n" +
            "\t,ao.remain_life_before remainLife #剩余寿命\n" +
            "\t,ROUND( (COUNT(开方记录.id))/ao.user_life_before ,4) useRate #利用率\n" +
            "FROM zhxx_fb_accessory_order ao\n" +
            "LEFT JOIN (SELECT\n" +
            "\t\t\t\t\t\t\tr.id\n" +
            "\t\t\t\t\t\t\t, r.equip_no\n" +
            "\t\t\t\t\t\t\t, r.start_trimming\n" +
            "\t\t\t\t\t\t\t, yb.ware_house_length#长度\n" +
            "\t\t\t\t\t\t\t, r.sn\n" +
            "\t\t\t\t\t\tFROM (SELECT * FROM interface_eap_evolution_record GROUP BY sn) r \n" +
            "\t\t\t\t\t\tLEFT JOIN interface_eap_retreat_feedback f ON r.sn = f.lot_no \n" +
            "\t\t\t\t\t\tLEFT JOIN interface_eap_evolution_blanking g on g.sn = r.sn\n" +
            "\t\t\t\t\t\tLEFT JOIN warehousing_statistics_info_yb yb ON yb.section_no = r.sn) as 开方记录 \n" +
            "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tON 开方记录.equip_no = ao.device_no AND 开方记录.start_trimming >= ao.up_date AND 开方记录.start_trimming <= ao.down_date\n" +
            "WHERE CONCAT(ao.device_type, ao.material_type_before) = '切方机切割线'\n" +
            "\t\t\tAND IF(?1 is not NULL AND ?1 <> '', ao.goods_code_before = ?1, 1=1)\n" +
            "\t\t\tAND IF(?2 is not NULL AND ?2 <> '', ao.material_code_before = ?2, 1=1)\n" +
            "\t\t\tAND IF(?3 is not NULL AND ?3 <> '', ao.device_no = ?3, 1=1)\n" +
            "\t\t\tAND IF(?4 is not NULL AND ?4 <> '', ao.up_date >= ?4, 1=1)\n" +
            "\t\t\tAND IF(?5 is not NULL AND ?5 <> '', ao.up_date <= ?5, 1=1)\n" +
            "\t\t\tAND IF(?6 is not NULL AND ?6 <> '', ao.down_date >= ?6, 1=1)\n" +
            "\t\t\tAND IF(?7 is not NULL AND ?7 <> '', ao.down_date <= ?7, 1=1)\n" +
            "GROUP BY ao.id,ao.device_no"
            ,countQuery = "SELECT \n" +
            "\tcount(*)\n" +
            "FROM zhxx_fb_accessory_order ao\n" +
            "LEFT JOIN (SELECT\n" +
            "\t\t\t\t\t\t\tr.id\n" +
            "\t\t\t\t\t\t\t, r.equip_no\n" +
            "\t\t\t\t\t\t\t, r.start_trimming\n" +
            "\t\t\t\t\t\t\t, yb.ware_house_length#长度\n" +
            "\t\t\t\t\t\t\t, r.sn\n" +
            "\t\t\t\t\t\tFROM (SELECT * FROM interface_eap_evolution_record GROUP BY sn) r \n" +
            "\t\t\t\t\t\tLEFT JOIN interface_eap_retreat_feedback f ON r.sn = f.lot_no \n" +
            "\t\t\t\t\t\tLEFT JOIN interface_eap_evolution_blanking g on g.sn = r.sn\n" +
            "\t\t\t\t\t\tLEFT JOIN warehousing_statistics_info_yb yb ON yb.section_no = r.sn) as 开方记录 \n" +
            "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tON 开方记录.equip_no = ao.device_no AND 开方记录.start_trimming >= ao.up_date AND 开方记录.start_trimming <= ao.down_date\n" +
            "WHERE CONCAT(ao.device_type, ao.material_type_before) = '切方机切割线'\n" +
            "\t\t\tAND IF(?1 is not NULL AND ?1 <> '', ao.goods_code_before = ?1, 1=1)\n" +
            "\t\t\tAND IF(?2 is not NULL AND ?2 <> '', ao.material_code_before = ?2, 1=1)\n" +
            "\t\t\tAND IF(?3 is not NULL AND ?3 <> '', ao.device_no = ?3, 1=1)\n" +
            "\t\t\tAND IF(?4 is not NULL AND ?4 <> '', ao.up_date >= ?4, 1=1)\n" +
            "\t\t\tAND IF(?5 is not NULL AND ?5 <> '', ao.up_date <= ?5, 1=1)\n" +
            "\t\t\tAND IF(?6 is not NULL AND ?6 <> '', ao.down_date >= ?6, 1=1)\n" +
            "\t\t\tAND IF(?7 is not NULL AND ?7 <> '', ao.down_date <= ?7, 1=1)\n" +
            "GROUP BY ao.id,ao.device_no",nativeQuery = true)
    Page<Map<String, Object>> qfjqgx(String goodsCode, String materialCode, String deviceNo, Date startUpDate, Date endUpDate, Date startDownDate, Date endDownDate, Pageable pageable);

    @Query(value = "SELECT\n" +
            "\tr.id\n" +
            "\t, r.equip_no\n" +
            "\t, r.start_trimming\n" +
            "\t, yb.ware_house_length length#长度\n" +
            "\t, r.sn `no`\n" +
            "FROM (SELECT * FROM interface_eap_evolution_record GROUP BY sn) r \n" +
            "LEFT JOIN interface_eap_retreat_feedback f ON r.sn = f.lot_no \n" +
            "LEFT JOIN interface_eap_evolution_blanking g on g.sn = r.sn\n" +
            "LEFT JOIN warehousing_statistics_info_yb yb ON yb.section_no = r.sn\n" +
            "WHERE 1=1\n" +
            "\t\t\tAND IF(?1 is not NULL AND ?1 <> '', r.equip_no = ?1, 1=1)\n" +
            "\t\t\tAND IF(?2 is not NULL AND ?2 <> '', r.start_trimming >= ?2, 1=1)\n" +
            "\t\t\tAND IF(?3 is not NULL AND ?3 <> '', r.start_trimming <= ?3, 1=1)",nativeQuery = true)
    List<Map<String, Object>> qfjqgxDetail(String deviceNo, Date upDate, Date downDate);
}
