package com.zcxk.rmcp.core.dao;


import com.zcxk.core.common.pojo.UserCondition;
import com.zcxk.rmcp.api.dto.device.DeviceQueryDto;
import com.zcxk.rmcp.api.dto.readmeter.WaterMeterDto;
import com.zcxk.rmcp.api.dto.install.InstallDeviceDto;
import com.zcxk.rmcp.api.dto.measurementsettlement.MeasurementSettlementDto;
import com.zcxk.rmcp.api.vo.*;
import com.zcxk.rmcp.core.entity.Device;
import com.zcxk.rmcp.core.entity.InstallList;
import org.apache.ibatis.annotations.Param;
import org.mapstruct.Mapper;

import java.util.List;

/**
 * @author linqingwei
 * @date 2021-07-19 9:44
 */
@Mapper
public interface DeviceMapper {
    /*
     * @description 新增设备
     * @param record
     * @return int
     * @author linqingwei
     **/
    int insertSelective(Device record);

    /*
     * @description 更新设备
     * @param record
     * @return int
     * @author linqingwei
     **/
    int updateByPrimaryKeySelective(Device record);


    /*
     * @description 批量插入
     * @param list
     * @return
     * @author linqingwei
     **/
    int batchInsert(@Param("list") List<Device> list);

    /*
     * @description 通过ID获取设备
     * @param id
     * @return com.zcxk.rmcp.core.entity.Device
     * @author linqingwei
     **/
    Device findById(@Param("id") Long id);

    /*
     * @description 查询设备详情
     * @param id
     * @return com.zcxk.rmcp.api.vo.DeviceDetailVo
     * @author linqingwei
     **/
    DeviceDetailVo findDetail(@Param("id") Long id);

    /*
     * @description 查询设备列表
     * @param dto
     * @param userCondition
     * @return java.util.List<com.zcxk.rmcp.api.vo.DeviceVo>
     * @author linqingwei
     **/
    List<DeviceVo> findList(@Param("dto") DeviceQueryDto dto, @Param("userCondition") UserCondition userCondition);

    /*
     * @description
     * @param ids
     * @return int
     * @author linqingwei
     **/
    int delByIds(@Param("ids") List<Long> ids);

    /*
     * @description
     * @param id
     * @param deviceNo
     * @return int
     * @author linqingwei
     **/
    int findByDeviceNoUnique(@Param("id") Long id, @Param("deviceNo") String deviceNo);

    /*
     * @description
     * @param id
     * @param meterNo
     * @return int
     * @author linqingwei
     **/
    int findByMeterNoUnique(@Param("id") Long id, @Param("meterNo") String meterNo);


    /**
     * 统计设备状态数
     *
     * @param userCondition:
     * @return java.util.List<com.zcxk.rmcp.api.vo.DeviceStatusVo>
     * @author Andy
     * @date 14:52 2021/8/3
     **/
    List<DeviceStatusVo> totalDeviceStatus(@Param("userCondition") UserCondition userCondition);

    /**
     * 获取小区设备数据
     *
     * @param categoryId:
     * @param userCondition:
     * @return java.util.List<com.zcxk.rmcp.api.vo.DeviceCategoryCommunityVo>
     * @author Andy
     * @date 14:52 2021/8/3
     **/
    List<DeviceCategoryCommunityVo> listCommunityDevice(@Param("categoryId") Integer categoryId, @Param("userCondition") UserCondition userCondition);

    /**
     * 获取没有绑定小区的设备信息
     *
     * @param categoryId:
     * @param userCondition:
     * @return java.util.List<com.zcxk.rmcp.api.vo.DeviceNoCellVo>
     * @author Andy
     * @date 14:53 2021/8/3
     **/
    List<DeviceNoCellVo> listNoCellDevice(@Param("categoryId") Integer categoryId, @Param("userCondition") UserCondition userCondition);


    List<Device> findMeasurementDevice(MeasurementSettlementDto measurementSettlement);

    /*
     * @description 获取未安装设备列表
     * @param tenantId
     * @param companyOrgId
     * @param deptOrgId
     * @param productId
     * @param listId
     * @return java.util.List<com.zcxk.rmcp.api.dto.install.InstallDeviceDto>
     * @author linqingwei
     **/
    List<InstallDeviceDto> getUnInstallDeviceList(@Param("tenantId") String tenantId, @Param("companyOrgId") Integer companyOrgId, @Param("deptOrgId") Integer deptOrgId, @Param("productId") Integer productId, @Param("listId") Integer listId);

    /*
     * @description deviceNo获取设备
     * @param deviceNo
     * @return com.zcxk.rmcp.core.entity.Device
     * @author linqingwei
     **/
    Device findByDeviceNo(String deviceNo);

    /*
     * @description 告警更新
     * @param device
     * @return
     * @author linqingwei
     **/
    int updateByAlarm(Device device);

    /*
     * @description 上报设备数据更新
     * @param device
     * @return
     * @author linqingwei
     **/
    int updateByDeviceData(Device device);

    /*
     * @description 计算水表总数
     * @param
     * @return
     * @author linqingwei
     **/
    int countWaterMeter();

    /**
     * @param startIndex
     * @param pageSize
     * @return
     * @description 全部设备分页
     * @author linqingwei
     **/
    List<WaterMeterDto> findWaterMeterListWithPage(@Param("startIndex") int startIndex, @Param("pageSize") int pageSize);

    List<DeviceVo> queryDeviceInfoList(@Param("deviceNo") String deviceNo, @Param("meterNo") String meterNo, @Param("userCondition") UserCondition userCondition);
}