package com.ho.business.mapper;

import com.ho.business.entity.IndustrialElecRegion;
import com.ho.business.vo.req.industrialElec.IndustrialElecRegionReqVo;
import org.apache.ibatis.annotations.*;
import java.util.List;


@Mapper
public interface IndustrialElecRegionMapper {


    @SelectProvider(type = IndustrialElecDaoProvider.class, method = "pageList")
    List<IndustrialElecRegion> selectIndustElecRegion(IndustrialElecRegionReqVo industrialElecRegionReqVo);

    @Delete("delete from industrial_elec_region where id=#{id}")
    int deleteById(@Param("id") Integer id);

    @Select("select * from industrial_elec_region where id=#{id}")
    IndustrialElecRegion findById(@Param("id")Integer id);

    @Update("update industrial_elec_region set region_name=#{regionName},`interval`=#{interval},type=#{type},voltage_level=#{voltageLevel},customer_type=#{customerType},electricity_type=#{electricityType},update_time=#{updateTime}  where id=#{id}")
    int updateById(IndustrialElecRegion industrialElecRegion);

    class IndustrialElecDaoProvider {
        public String pageList(IndustrialElecRegionReqVo industrialElecRegionReqVo) {
            String sql = "SELECT * FROM industrial_elec_region where 1=1";
            if (industrialElecRegionReqVo.getRegionName() != null) {
                sql += " and region_name like CONCAT('%',#{regionName},'%')";
            }
            return sql;
        }
    }

    @Insert("insert into industrial_elec_region(region_name,`interval`,type,voltage_level,customer_type,electricity_type,create_time) values(#{regionName},#{interval},#{type},#{voltageLevel},#{customerType},#{electricityType},#{createTime})")
    int insert(IndustrialElecRegion industrialElecRegion);

    @Select("select * from industrial_elec_region")
    List<IndustrialElecRegion> findAllList();

    @Select("select * from industrial_elec_region where region_name=#{regionName}")
    IndustrialElecRegion findByRegionName(@Param("regionName")String regionName);
}
