package com.rongwei.sfcommon.sys.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.rongwe.scentity.domian.*;
import com.rongwe.scentity.vo.AspSafetyEmergencyDrillPlanVo;
import com.rongwe.scentity.vo.AspSafetyTeamMemberVo;
import com.rongwe.scentity.vo.AspSafetyTeamVo;
import org.apache.ibatis.annotations.Select;

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

/**
 * <p>
 * 安全应急-演练方案 Mapper 接口
 * </p>
 *
 * @author wm
 * @since 2023-11-13
 */
public interface AspSafetyDrillProgrammeDao extends BaseMapper<AspSafetyDrillProgrammeDo> {

    @Select("select a.*,b.`NAME` AS 'drillCategoryName' from asp_safety_emergency_drill_plan a LEFT JOIN (select * from sys_dict where DELETED = 0 AND DICTTYPE='satefy_drill_type') b ON a.DRILLCATEGORY = b.`VALUE` where a.DELETED = 0 AND DRILLDATE >= #{startDate} AND DRILLDATE <= #{endDate}")
    List<AspSafetyEmergencyDrillPlanVo> selectSafetyEmergencyDrillPlanByDate(String startDate, String endDate);

    @Select("select * from asp_safety_onsite_disposal_plan where DELETED = 0 order by NO")
    List<AspSafetyOnsiteDisposalPlan> selectOnsiteDisposalPlan();

    @Select("select * from asp_safety_annual_drill_plan where DELETED = 0 AND ID = #{id}")
    AspSafetyAnnualDrillPlan selectAnnualDrillPlanById(String id);

    @Select("select * from asp_safety_annual_drill_plan_month where DELETED = 0 AND ANNUALDRILLPLANID = #{id}")
    List<AspSafetyAnnualDrillPlanMonth> selectAnnualDrillPlanMonthById(String id);

    @Select("select ID,TEAMNAME AS 'teamName',ORGPOSITION AS 'content' from asp_safety_team where DELETED = 0")
    List<AspSafetyTeamVo> selectTeam();

    @Select("select TEAMPOSITION AS 'roleName',GROUP_CONCAT(TEAMMEMBERNAME) AS 'name' from asp_safety_team_member where DELETED = 0 AND TEAMID=#{id} GROUP BY TEAMPOSITION")
    List<AspSafetyTeamMemberVo> selectTeamMemberByTeamId(String id);

    @Select("select GROUP_CONCAT(a.`name`) from (SELECT CONCAT(ITEMNAME,ITEMQTY) as 'name' FROM asp_safety_drill_programme_item where DELETED = 0 AND PROGRAMMEID = #{mainId}) a")
    String selectEquimentByMainId(String mainId);
}
