package org.gyk.modules.lssj.jldls.mapper;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.gyk.modules.lssj.bjls.entity.CxcSssjLssjBjlsjl;
import org.gyk.modules.lssj.jldls.entity.CxcSssjLssjJldls;
import org.gyk.modules.sssj.entity.JldData;
import org.gyk.modules.sssj.entity.PianyuanZhan;
import org.gyk.modules.sssj.entity.YasuojiBjSj;
import org.gyk.modules.sssj.entity.YasuojiSj;

import java.util.List;

/**
 * @Description: 计量点历史数据-批量存储
 * @Author: liao
 * @Date:   2021-04-05
 * @Version: V1.0
 */
@Mapper
public interface JldlsMapper extends BaseMapper<CxcSssjLssjJldls> {
    //10.75.166.13:3306/jeecg-boot-cxc
    int insertBatch( List<CxcSssjLssjJldls> vips);

    @Insert("<script>" +
            "insert into cxc_sssj_pianyuan (id,jldname,rq,wd,yali,bkss,gkss,bkzl,gkzl,zrbklj,jrlj)" +
            " values" +
            " <foreach collection='list' item='jldls'  separator=','>" +
            "  (#{jldls.id},#{jldls.jldname}, #{jldls.rq}, #{jldls.wd},#{jldls.yali}, #{jldls.bkss}, #{jldls.gkss}, #{jldls.bkzl},#{jldls.gkzl}, #{jldls.zrbklj}, #{jldls.jrlj})" +
            " </foreach>" +
            "</script>"
    )
    @DS("slave")
    void insertPianyuanMaster(@Param("list") List<PianyuanZhan> list);

    //获取偏远站场指定日期8点数据
    @Select(" SELECT * FROM `cxc_sssj_pianyuan` WHERE rq>= #{startTime} and DATE_FORMAT(rq,'%H:%i')='08:00' and jldname in ('白九来气','东明站来气') ")
    @DS("slave")
    public List<PianyuanZhan> listPiany(@Param("startTime") String startTime);

    //修改偏远站场指定日期8点数据
    @Select(" insert into cxc_sssj_pianyuan(id,jldname,rq,bkzl) values (#{id},#{jldname},#{rq}, #{bkzl})")
    @DS("slave")
    public List<PianyuanZhan> editPianyuan8(@Param("id") String id,@Param("jldname") String jldname,@Param("rq") String rq,@Param("bkzl") String bkzl);


    @Insert("<script>" +
            "insert into cxc_sssj_lssj_jldls (id,create_time,jld_id,jld_no,wd,yl,yc,ssll,jrl,syll,byll,zll,jrsj,zt,`zhan`,`jld_name`)" +
            " values" +
            " <foreach collection='list' item='jldls'  separator=','>" +
            "  (#{jldls.id},#{jldls.createTime}, #{jldls.jldId}, #{jldls.jldNo},#{jldls.wd}, #{jldls.yl}, #{jldls.yc},#{jldls.ssll}, #{jldls.jrl}, #{jldls.syll}, #{jldls.byll}, #{jldls.zll}, #{jldls.jrsj}, #{jldls.zt}, #{jldls.zhan}, #{jldls.jldName})" +
            " </foreach>" +
            "</script>"
    )
    @DS("three")
    void insertBatchMaster(@Param("list") List<CxcSssjLssjJldls> list);

    //10.75.166.13:3306/jeecg-boot-jldls
    @Insert("<script>" +
            "insert into cxc_sssj_lssj_jldls (id,create_time,jld_id,jld_no,wd,yl,yc,ssll,jrl,syll,byll,zll,jrsj,zt,`zhan`,`jld_name`)" +
            " values" +
            " <foreach collection='list' item='jldls'  separator=','>" +
            "  (#{jldls.id},#{jldls.createTime}, #{jldls.jldId}, #{jldls.jldNo},#{jldls.wd}, #{jldls.yl}, #{jldls.yc},#{jldls.ssll}, #{jldls.jrl}, #{jldls.syll}, #{jldls.byll}, #{jldls.zll}, #{jldls.jrsj}, #{jldls.zt}, #{jldls.zhan}, #{jldls.jldName})" +
            " </foreach>" +
            "</script>"
    )
    @DS("slave")
    void insertBatchSlave(@Param("list") List<CxcSssjLssjJldls> list);

    @Insert("<script>" +
            "insert into cxc_sssj_yasuoji_bjls (`id`,`bj_id`,`begin_time`,`end_time`,`canshu_zhi`,`bj_ms`,`stationname`,`jizuhao`,`zt`)" +
            " values" +
            " <foreach collection='list' item='jldls'  separator=','>" +
            "  (#{jldls.id},#{jldls.bjId}, #{jldls.beginTime}, #{jldls.endTime},#{jldls.canshuZhi}, #{jldls.bjMs},#{jldls.stationname}, #{jldls.jizuhao}, #{jldls.zt})" +
            " </foreach>" +
            "</script>"
    )
    @DS("slave")
    void YasuojiBj(@Param("list") List<YasuojiBjSj> list);

    @Insert("<script>" +
            "insert into cxc_sssj_yasuoji (`id`,`depart_name`,`station_name`,`jizu_hao`,`ysjxh`,`rq`,`shuju`)" +
            " values" +
            " <foreach collection='list' item='jldls'  separator=','>" +
            "  (#{jldls.id},#{jldls.departName}, #{jldls.stationName}, #{jldls.jizuHao},#{jldls.ysjxh}, #{jldls.rq}, #{jldls.shuju})" +
            " </foreach>" +
            "</script>"
    )
    @DS("slave")
    void YasuojiSssj(@Param("list") List<YasuojiSj> list);

//   @Select(" SELECT * FROM `cxc_sssj_yasuoji_bjls` WHERE end_time>= date_sub(now(),INTERVAL #{sc} HOUR) ORDER BY end_time desc")
   @Select(" SELECT * FROM `cxc_sssj_yasuoji_bjls` where zt='1' ORDER BY end_time desc")
    @DS("slave")
    public List<YasuojiBjSj> getYsjBj();

   //获取压缩机报警历史数据
    @Select(" SELECT * FROM `cxc_sssj_yasuoji_bjls` WHERE begin_time BETWEEN #{startTime} AND #{endTime} ORDER BY begin_time")
    @DS("slave")
    public List<YasuojiBjSj> getYsjBjsj(@Param("startTime") String startTime,@Param("endTime") String endTime);

    //获取压缩机历史数据的表头
    @Select(" SELECT station_name,jizu_hao,rq,shuju FROM `cxc_sssj_yasuoji` WHERE station_name=#{zc} and jizu_hao=#{jzh} limit 1")
    @DS("slave")
    public List<YasuojiSj> getYsjLsBt(@Param("zc") String zc,@Param("jzh") String jzh);

    //获取压缩机历史数据
    @Select(" SELECT station_name,jizu_hao,rq,shuju FROM `cxc_sssj_yasuoji` WHERE rq BETWEEN #{startTime} AND #{endTime} and station_name=#{zc} and jizu_hao=#{jzh} order by rq")
    @DS("slave")
    public List<YasuojiSj> getYsjLssj(@Param("zc") String zc,@Param("jzh") String jzh,@Param("startTime") String startTime,@Param("endTime") String endTime);

//    @Select(" SELECT * FROM `cxc_sssj_lssj_bjlsjl` WHERE end_time>= date_sub(now(),INTERVAL #{sc} HOUR) and jlbz=#{lb} ORDER BY end_time desc")
    //查询报警历史表中未处置的条目
    // 添加了一个条件 zt不为0 jiang.20240321
    @Select(" SELECT * FROM `cxc_sssj_lssj_bjlsjl` WHERE jlbz=#{lb} and zt !='0' ORDER BY end_time desc limit #{sc}")
    public List<CxcSssjLssjBjlsjl> getTrqBjxx(@Param("sc") int sc,@Param("lb") String lb);
}
