package com.sw.mes.yb.pc.dao;

import com.sw.mes.core.base.BaseDao;
import com.sw.mes.inspect.entity.YbInspectData;
import com.sw.mes.yb.pc.entity.DataInspectLog;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;

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

/**
* @Author
* @Description：
* @Date:
* @Modified By:
*/
public interface DataInspectLogDao extends BaseDao<DataInspectLog, Long> {
    @Query(value = "select * from " +
            "(select zdi.crystal_no,zdi.section_no,zdi.section_type,zdi.again_num,zdi.again_piece,zdi.dopant,zdi.pull_type,zdi.kube,zdi.is_cut_back,zdi.checkout_name,zdi.re_check_type,zdi.product_type_second,zdi.is_change_specs,zdi.ware_house_length,zdi.actual_length,zdi.actual_weight,zdi.theory_weight,zdi.head_tail_recognition,zdi.diameter_min,zdi.diameter_max,zdi.diam_decide,zdi.fine_diameter,zdi.fine_cut_length,zdi.edge_bark,zdi.collapse_line,zdi.is_bevel,zdi.is_fork,zdi.colorful,zdi.crack,zdi.is_twin_crystal,zdi.twin_length,zdi.head_slope,zdi.tail_slope,zdi.distortion_big,zdi.distortion,zdi.product_level,zdi.product_level_experiment,zdi.level_time,zdi.remark,zdi.level,zdi.experi_level,zdi.conductive_type,zdi.resistivity_min,zdi.resistivity_max,zdi.t_life_min,zdi.w_life_min,zdi.t_radial_centre,zdi.t_radial_edge1,zdi.t_radial_edge2,zdi.t_radial_edge3,zdi.t_radial_edge4,zdi.t_radial_edge5,zdi.t_radial_edge6,zdi.t_radial_edge7,zdi.t_radial_edge8,zdi.w_radial_centre,zdi.w_radial_edge1,zdi.w_radial_edge2,zdi.w_radial_edge3,zdi.w_radial_edge4,zdi.w_radial_edge5,zdi.w_radial_edge6,zdi.w_radial_edge7,zdi.w_radial_edge8,zdi.end_centre_edge_avg4,zdi.top_centre_edge_avg,zdi.end_centre_edge_avg,zdi.resistivity_top_avg,zdi.resistivity_end_avg,zdi.sell_resistivity,zdi.resistivity_conclusion,zdi.is_see_bottom,zdi.resistivity_warping,zdi.t_centre_life,zdi.t_life_edge1,zdi.t_life_edge2,zdi.t_life_edge3,zdi.t_life_edge4,zdi.w_centre_life,zdi.w_life_edge1,zdi.w_life_edge2,zdi.w_life_edge3,zdi.w_life_edge4,zdi.reduce_crystal_length,zdi.crystal_workshop,zdi.oxygen_content_head,zdi.oxygen_content_border,zdi.carbon_content_head,zdi.carbon_content_border,zdi.oxygen_content_tail,zdi.oxygen_content_border_tail,zdi.carbon_content_tail,zdi.carbon_content_border_tail,zdi.head_defect_grade,zdi.tail_defect,zdi.is_malposition_head,zdi.is_malposition_tail,zdi.t_center_anneal,zdi.wcenter_anneal,zdi.t_border_anneal,zdi.w_border_anneal,zdi.anomaly,zdi.inspector,zdi.has_gone,zdi.order_no,zdi.plan_specs,zdi.plan_material_code,zdi.order_type,zdi.furnace_type,zdi.device_no,zdi.series,zdi.lot_no,zdi.material_count,zdi.sinton_center,zdi.sinton_tail,zdi.life_spanw1,zdi.resistivityw1,zdi.life_spant2,zdi.resistivityt2,zdi.piecewise_num,zdi.create_time,zdi.update_time,zdi.draw_line,zdi.crystal_abnormal,zdi.section_compose,zdi.sticks_count,zdi.factory,zdi.head_level,zdi.tail_level,zdi.grade_name,zdi.grade_version,zdi.plan_grade_name,zdi.plan_grade_version,zdi.check_reback,zdi.check_line_no,zdi.t_temp_radial_centre,zdi.t_temp_radial_edge1,zdi.t_temp_radial_edge2,zdi.t_temp_radial_edge3,zdi.t_temp_radial_edge4,zdi.t_temp_radial_edge5,zdi.t_temp_radial_edge6,zdi.t_temp_radial_edge7,zdi.t_temp_radial_edge8,zdi.w_temp_radial_centre,zdi.w_temp_radial_edge1,zdi.w_temp_radial_edge2,zdi.w_temp_radial_edge3,zdi.w_temp_radial_edge4,zdi.w_temp_radial_edge5,zdi.w_temp_radial_edge6,zdi.w_temp_radial_edge7,zdi.w_temp_radial_edge8,zdi.crystal_direction,zdi.grade_data,zdi.plan_order_no,zdi.material_code,zdi.temperature,zdi.temperature_end,zdi.demc_max,zdi.diameter_minus_big,zdi.plan_order_type,zdi.plan_stick_count,zdi.plan_len_range,zdi.plan_dopant,zdi.plan_conductive_type,zdi.plan_grade,zdi.spell_bar_length,zdi.avg_diameter,zdi.all_avg_diameter,zdi.line_marking,zdi.grade_type,zdi.update_user " +
            "from zhxx_data_inspect zdi " +
            "where  (zdi.inspector = ?3 or ?3 is null) and (zdi.section_no = ?1 or ?1 is null) and (zdi.crystal_no = ?2 or ?2 is null) and (zdi.level_time >=?4 or ?4 is null) and  (zdi.level_time <=?5 or ?5 is null) " +
            "union " +
            "select zdil.crystal_no,zdil.section_no,zdil.section_type,zdil.again_num,zdil.again_piece,zdil.dopant,zdil.pull_type,zdil.kube,zdil.is_cut_back,zdil.checkout_name,zdil.re_check_type,zdil.product_type_second,zdil.is_change_specs,zdil.ware_house_length,zdil.actual_length,zdil.actual_weight,zdil.theory_weight,zdil.head_tail_recognition,zdil.diameter_min,zdil.diameter_max,zdil.diam_decide,zdil.fine_diameter,zdil.fine_cut_length,zdil.edge_bark,zdil.collapse_line,zdil.is_bevel,zdil.is_fork,zdil.colorful,zdil.crack,zdil.is_twin_crystal,zdil.twin_length,zdil.head_slope,zdil.tail_slope,zdil.distortion_big,zdil.distortion,zdil.product_level,zdil.product_level_experiment,zdil.level_time,zdil.remark,zdil.level,zdil.experi_level,zdil.conductive_type,zdil.resistivity_min,zdil.resistivity_max,zdil.t_life_min,zdil.w_life_min,zdil.t_radial_centre,zdil.t_radial_edge1,zdil.t_radial_edge2,zdil.t_radial_edge3,zdil.t_radial_edge4,zdil.t_radial_edge5,zdil.t_radial_edge6,zdil.t_radial_edge7,zdil.t_radial_edge8,zdil.w_radial_centre,zdil.w_radial_edge1,zdil.w_radial_edge2,zdil.w_radial_edge3,zdil.w_radial_edge4,zdil.w_radial_edge5,zdil.w_radial_edge6,zdil.w_radial_edge7,zdil.w_radial_edge8,zdil.end_centre_edge_avg4,zdil.top_centre_edge_avg,zdil.end_centre_edge_avg,zdil.resistivity_top_avg,zdil.resistivity_end_avg,zdil.sell_resistivity,zdil.resistivity_conclusion,zdil.is_see_bottom,zdil.resistivity_warping,zdil.t_centre_life,zdil.t_life_edge1,zdil.t_life_edge2,zdil.t_life_edge3,zdil.t_life_edge4,zdil.w_centre_life,zdil.w_life_edge1,zdil.w_life_edge2,zdil.w_life_edge3,zdil.w_life_edge4,zdil.reduce_crystal_length,zdil.crystal_workshop,zdil.oxygen_content_head,zdil.oxygen_content_border,zdil.carbon_content_head,zdil.carbon_content_border,zdil.oxygen_content_tail,zdil.oxygen_content_border_tail,zdil.carbon_content_tail,zdil.carbon_content_border_tail,zdil.head_defect_grade,zdil.tail_defect,zdil.is_malposition_head,zdil.is_malposition_tail,zdil.t_center_anneal,zdil.wcenter_anneal,zdil.t_border_anneal,zdil.w_border_anneal,zdil.anomaly,zdil.inspector,zdil.has_gone,zdil.order_no,zdil.plan_specs,zdil.plan_material_code,zdil.order_type,zdil.furnace_type,zdil.device_no,zdil.series,zdil.lot_no,zdil.material_count,zdil.sinton_center,zdil.sinton_tail,zdil.life_spanw1,zdil.resistivityw1,zdil.life_spant2,zdil.resistivityt2,zdil.piecewise_num,zdil.create_time,zdil.update_time,zdil.draw_line,zdil.crystal_abnormal,zdil.section_compose,zdil.sticks_count,zdil.factory,zdil.head_level,zdil.tail_level,zdil.grade_name,zdil.grade_version,zdil.plan_grade_name,zdil.plan_grade_version,zdil.check_reback,zdil.check_line_no,zdil.t_temp_radial_centre,zdil.t_temp_radial_edge1,zdil.t_temp_radial_edge2,zdil.t_temp_radial_edge3,zdil.t_temp_radial_edge4,zdil.t_temp_radial_edge5,zdil.t_temp_radial_edge6,zdil.t_temp_radial_edge7,zdil.t_temp_radial_edge8,zdil.w_temp_radial_centre,zdil.w_temp_radial_edge1,zdil.w_temp_radial_edge2,zdil.w_temp_radial_edge3,zdil.w_temp_radial_edge4,zdil.w_temp_radial_edge5,zdil.w_temp_radial_edge6,zdil.w_temp_radial_edge7,zdil.w_temp_radial_edge8,zdil.crystal_direction,zdil.grade_data,zdil.plan_order_no,zdil.material_code,zdil.temperature,zdil.temperature_end,zdil.demc_max,zdil.diameter_minus_big,zdil.plan_order_type,zdil.plan_stick_count,zdil.plan_len_range,zdil.plan_dopant,zdil.plan_conductive_type,zdil.plan_grade,zdil.spell_bar_length,zdil.avg_diameter,zdil.all_avg_diameter,zdil.line_marking,zdil.grade_type,zdil.operator as update_user " +
            "from zhxx_data_inspect_log zdil " +
            "where (zdil.operate_type = 0) and (zdil.inspector = ?3 or ?3 is null) and (zdil.section_no = ?1 or ?1 is null) and (zdil.crystal_no = ?2 or ?2 is null) and (zdil.level_time >=?4 or ?4 is null) and  (zdil.level_time <=?5 or ?5 is null)) zdinew " +
            "order by zdinew.level_time desc",
            countQuery = "select count(1) " +
                    "from (select zdi.section_no,zdi.level_time from zhxx_data_inspect zdi " +
                    "where  (zdi.inspector = ?3 or ?3 is null) and (zdi.section_no = ?1 or ?1 is null) and (zdi.crystal_no = ?2 or ?2 is null) and (zdi.level_time >=?4 or ?4 is null) and  (zdi.level_time <=?5 or ?5 is null) " +
                    "union " +
                    "select zdil.section_no,zdil.level_time " +
                    "from zhxx_data_inspect_log zdil " +
                    "where (zdil.operate_type = 0) and (zdil.inspector = ?3 or ?3 is null) and (zdil.section_no = ?1 or ?1 is null) and (zdil.crystal_no = ?2 or ?2 is null) and (zdil.level_time >=?4 or ?4 is null) and  (zdil.level_time <=?5 or ?5 is null)) zdinew order by zdinew.level_time desc", nativeQuery = true)
    Page<Map<String, Object>> getPageListInfo(String search_EQ_sectionNo, String search_EQ_crystalNo, String search_EQ_inspector,
                                              String search_GTE_levelTime, String search_LT_levelTime, Pageable pageable);

    List<DataInspectLog> findBySectionNoAndIsCutBack(String sectionNo, Integer i);

    @Query(value = "select * from zhxx_data_inspect_log where section_no like ?1 order by id desc", nativeQuery = true)
    List<DataInspectLog> getDataInspectLog(String sectionNo);

}
