package com.rongwei.bscommon.sys.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.rongwei.bsentity.domain.EquMaintenanceOrderDo;
import com.rongwei.bsentity.dto.EquMaintenanceOrderSumDTO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

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

public interface EquMaintenanceOrderDao extends BaseMapper<EquMaintenanceOrderDo> {
    @Select("SELECT\n" +
            "  d.PLANT,d.DEVICETYPE,d.PROBLEMLOCATION,COUNT(d.ID) 'COUNT',\n" +
            "\tGROUP_CONCAT(d.ID  ) 'IDS' \n" +
            "FROM\n" +
            "\t(\n" +
            "\tSELECT\n" +
            "\t\ta.PLANT,a.PROBLEMLOCATION,a.ID,\n" +
            "\tCASE\n" +
            "\t\t\tWHEN a.MAINTENANCECLASSIFY = '1' THEN\n" +
            "\t\t\tdict1.`NAME` ELSE c.FROCKTYPE \n" +
            "\t\tEND 'DEVICETYPE' \n" +
            "FROM\n" +
            "\tequ_maintenance_order a\n" +
            "\tLEFT JOIN asp_check_items b ON b.ID = a.EQUIPMENTID AND b.DELETED = '0'\n" +
            "\t\tLEFT JOIN sys_dict dict1 ON dict1.DICTTYPE = 'asp_check_item_type' \tAND dict1.`VALUE` = b.CHECKITEMTYPE\n" +
            "\tLEFT JOIN equ_frock_list c ON c.ID = a.EQUIPMENTID AND c.DELETED = '0' \n" +
            "WHERE\n" +
            "\t1 = 1 \n" +
            "\tAND a.DELETED = '0' \n" +
            "\tAND a.REPAIRSTATUS NOT IN (50,120) \n" +
            "\tAND a.MAINTENANCECLASSIFY IN ( 1, 3 ) \n" +
            "\tand a.INCIDENTTIME BETWEEN  #{startDate} and #{endDate} \n" +
            "\t) d \n" +
            "GROUP BY\n" +
            "\td.PLANT,\n" +
            "\td.PROBLEMLOCATION,\n" +
            "\td.DEVICETYPE \n" +
            "HAVING\n" +
            "\tcount( d.ID )> 1")
    List<EquMaintenanceOrderSumDTO> selectOrderSummaryData(@Param("startDate") Date startDate, @Param("endDate") Date endDate);

    @Select("SELECT a.* FROM equ_maintenance_order a\n" +
            " WHERE 1 = 1 and FIND_IN_SET(a.ID,#{ids})" )
    List<EquMaintenanceOrderDo> selectOrderDataByIds( @Param("ids") String ids);

//    @Select("SELECT su.ID\n" +
//            "FROM sys_role sr \n" +
//            "LEFT JOIN sys_user_role sur ON sr.ID = sur.ROLEID and sur.DELETED = 0 \n" +
//            "LEFT JOIN sys_user su ON sur.USERID = su.ID and su.DELETED = 0 \n" +
//            "LEFT JOIN sys_user_org suo ON suo.USERID = su.ID AND suo.DELETED = 0 \n" +
//            "LEFT JOIN sys_organization so ON suo.ORGID = so.ID AND so.DELETED = 0 \n" +
//            "WHERE sr.NAME in('设备部部长','车间维修主管','设备部维修主管') \n")
    List<String> selectRoleList(@Param("roleCodes") List<String> roleCode);

}
