package com.mh.user.mapper; import com.mh.user.entity.DeviceInstallEntity; import com.mh.user.entity.DeviceInstallTempEntity; import com.mh.user.mapper.provider.DeviceInstallProvider; import com.mh.user.model.DeviceModel; import org.apache.ibatis.annotations.*; import org.apache.ibatis.mapping.StatementType; import tk.mybatis.mapper.common.BaseMapper; import java.util.Date; import java.util.List; @Mapper public interface DeviceInstallMapper extends BaseMapper { /** * 设备安装模块 * 保存设备信息 * @param deviceInstallEntity */ @Insert("insert into device_install(device_addr,device_name,device_type,data_com,ratio,baudrate,brand,model,building_id,building_name,installer,install_date,is_use,parity) values (" + " #{deviceAddr},#{deviceName},#{deviceType},#{dataCom},#{ratio},#{baudRate},#{brand},#{model},#{buildingId},#{buildingName},#{installer},getDate(),#{use},#{parity})") int saveDevice(DeviceInstallEntity deviceInstallEntity); /** * 设备安装模块 * 保存设备信息 * @param deviceInstallEntity */ @Update("") int updateDevice(DeviceInstallEntity deviceInstallEntity); //按id更新水电表读数和采集日期 @Update("update device_install set last_value=#{lastValue},last_date=#{lastDate} where id=#{id}") void updateLastValue(@Param("id") Long id,@Param("lastValue") String lastValue,@Param("lastDate") Date lastDate); /** * 设备管理模块: * 查询设备资料 * @param page * @param limit * @return */ @Results(id="rs", value = { @Result(property="deviceAddr",column="device_addr"), @Result(property="deviceName",column="device_name"), @Result(property="deviceType",column="device_type"), @Result(property="dataCom",column="data_com"), @Result(property ="buildingId",column ="building_id"), @Result(property ="buildingName",column ="building_name"), @Result(property ="ratio",column ="ratio"), @Result(property ="lastValue",column ="last_value"), @Result(property ="lastDate",column ="last_date"), @Result(property="isOnline",column="is_online"), @Result(property="installDate",column="install_date"), @Result(property="baudRate",column="baudrate"), @Result(property="remarks",column="remarks"), @Result(property="use",column="is_use"), @Result(property="fault",column="is_fault"), @Result(property="faultState",column="fault_state") }) @Select("select * from (\n" + "select *,ROW_NUMBER() over(order by id) as rn from device_install \n" + ") t where rn between (#{page}-1)*#{limit} and #{page}*#{limit}") List getAllDevice(@Param("page") int page, @Param("limit") int limit); //查询有多个采集参数的设备 @ResultMap("rs") @Select("select * from device_install where device_type='热泵'") List selectDeviceParams(); @ResultMap("rs") @Select("select * from device_install where device_type='热泵' or device_type='水位开关' ") List selectDeviceParams2(); //查询需要手动开关机的热泵 @ResultMap("rs") @Select("select * from device_install where device_type='热泵' and brand='美的2' ") List selectDevicePump(); //根据类型查询设备通讯号 @Select("select top 1 device_addr from device_install where device_type=#{deviceType} and building_id=#{buildingId} ") String selectDeviceAddr(@Param("deviceType") String deviceType,@Param("buildingId") String buildingId); /** * 设备管理模块: * 根据条件获取设备查询的总条数 * @return */ @Select("select count(*) from device_install where is_use=1 ") int getAllCount(); @SelectProvider(type = DeviceInstallProvider.class,method = "queryDevice") @ResultMap("rs") List queryDevice(@Param("buildingId") String buildingId, @Param("deviceType") String deviceType, @Param("startDate") String startDate, @Param("endDate")String endDate, @Param("isOnline")String isOnline, @Param("isUse")String isUse, @Param("isFault")String isFault, @Param("page") int page, @Param("limit") int limit); /** * 设备管理模块: * 根据条件获取设备查询的总条数 * @return */ @SelectProvider(type = DeviceInstallProvider.class,method = "getCount") int getCount(@Param("buildingId") String buildingId, @Param("deviceType") String deviceType, @Param("startDate") String startDate, @Param("endDate")String endDate, @Param("isOnline")String isOnline, @Param("isUse")String isUse, @Param("isFault")String isFault, @Param("page") int page, @Param("limit") int limit); //查询设备故障情况 @SelectProvider(type = DeviceInstallProvider.class,method = "getIsFaultCount") int getIsFaultCount(@Param("isFault") String isFault,@Param("deviceType") String deviceType); //查询设备在线情况 @SelectProvider(type = DeviceInstallProvider.class,method = "getIsOnlineCount") int getIsOnlineCount(@Param("isOnline") String isOnline,@Param("deviceType") String deviceType); // 修改设备在线情况,在线。 @Update("update device_install set is_online=#{isOnline},last_date=getDate() where device_addr=#{deviceAddr} and device_type=#{deviceType} and building_id=#{buildingId}") // @Update("update device_install set is_online=#{isOnline} where device_addr=#{deviceAddr} and device_type=#{deviceType} and building_id=#{buildingId}") void updateOnline(@Param("deviceAddr") String deviceAddr, @Param("deviceType") String deviceType, @Param("buildingId") String buildingId, @Param("isOnline") String isOnline); // 修改设备在线情况,离线。 @Update("update device_install set is_online=#{isOnline} where device_addr=#{deviceAddr} and device_type=#{deviceType} and building_id=#{buildingId}") void updateNotOnline(@Param("deviceAddr") String deviceAddr, @Param("deviceType") String deviceType, @Param("buildingId") String buildingId, @Param("isOnline") String isOnline); //根据通讯地址和设备类型查询对应的设备信息 @ResultMap("rs") @Select("select top 1 * from device_install where device_addr=#{deviceAddr} and device_type=#{deviceType} and building_id=#{buildingId}") DeviceInstallEntity selectDevice(@Param("deviceAddr") String deviceAddr,@Param("deviceType") String deviceType,@Param("buildingId") String buildingId); //查询通讯编号是否存在 @Select("select count(*) from device_install where device_addr=#{deviceAddr} and device_type=#{deviceType} ") int selectDeviceCount(@Param("deviceAddr") String deviceAddr,@Param("deviceType") String deviceType); /** * 设备管理模块: * 根据通讯地址删除设备信息 * @param id */ @Delete("delete from device_install where id=#{id}") int deleteDevice(String id); //EXCEL导入相关处理函数 // 清临时表 @Delete("DELETE FROM device_install_temp") void deleteDevice_install_temp(); // 保存到临时表 @Insert("insert into device_install_temp(device_addr,device_name,device_type,baudrate,data_com,ratio,building_id,row_id)" + " values(#{deviceAddr},#{deviceName},#{deviceType},#{baudRate},#{dataCom},#{ratio},#{buildingId},#{rowId})") void insertDevice_install_temp(@Param("deviceAddr") String deviceAddr, @Param("deviceName") String deviceName, @Param("deviceType") String deviceType, @Param("baudRate") int baudRate, @Param("dataCom") String dataCom, @Param("ratio") double ratio, @Param("buildingId") String buildingId, @Param("rowId") String rowId ); // EXCEL导入查询EXCEL内容 @Select("SELECT device_addr,device_name,device_type,baudRate,data_com,ratio, " + " building_id,row_id, " + " (CASE " + " when remarks is not null then remarks + ',行号为' + convert(varchar(100),Row_id) " + " else '' " + " end " + " ) as remarks " + " FROM device_install_temp " + " ORDER BY ISNULL(remarks,'') DESC ,row_id ") @Options(statementType = StatementType.CALLABLE) @Results({ @Result(column = "device_addr",property = "deviceAddr" ), @Result(column = "device_name", property = "deviceName"), @Result(column = "device_type", property = "deviceType"), @Result(column = "baudRate", property = "baudRate"), @Result(column = "data_com", property = "dataCom"), @Result(column = "ratio", property = "ratio"), @Result(column = "building_id", property = "buildingId"), @Result(column = "install_date", property = "installDate"), @Result(column = "remarks", property = "remarks"), @Result(column = "row_id", property = "rowId") }) List queryExcelDevices(); //查询Excel导入的数据的记录数 @Select("SELECT COUNT(*) FROM device_install_temp ") int queryExcelDevicesCount(); /** * @author nxr * @title :判断导入资料数据的合法 * @description :在导入中的数据有重复 * @updateTime 2022-06-19 * @throws : */ @Update("update device_install_temp " + " set Remarks = '数据中表号有重复' " + " where Remarks is null " + " and device_addr in ( select ISNULL(device_install_temp.device_addr,'') " + " from device_install_temp " + " group by device_addr " + " having count(*) > 1)") void updateDevice_install_temp__multiple(); //从临时表查询插入 @Insert("insert into device_install(device_addr,device_name,device_type,data_com,baudRate,ratio,building_id) select device_addr,device_name,device_type,data_com,baudRate,ratio,building_id from device_install_temp") void insertFromDevice_install_temp(); //修改启动状态 @Update("update device_install set is_use=#{isUse} where device_addr=#{deviceAddr}") void updateDeviceIsUse(@Param("isUse") String isUse, @Param("deviceAddr") String deviceAddr); //查询设备 @Results({ @Result(column = "device_addr",property = "deviceAddr" ), @Result(column = "device_name", property = "deviceName"), @Result(column = "id", property = "id") }) @Select("select * from device_install where building_id=#{buildingId} and device_type=#{deviceType}") List selectDevices(@Param("buildingId") String buildingId, @Param("deviceType") String deviceType); //修改故障状态 @Update("update device_install set is_fault=#{isFault} where device_addr=#{deviceAddr} and device_type=#{deviceType}") void updateDeviceFault(@Param("isFault") String isFault, @Param("deviceAddr") String deviceAddr, @Param("deviceType") String deviceType); //查询设备品牌 @Select("select brand from device_install where building_id=#{buildingId} and device_addr=#{deviceAddr}") String selectBrand(@Param("buildingId") String buildingId,@Param("deviceAddr") String deviceAddr); //修改使用状态1启用,0停用 @Update("update device_code_param set isUse=#{isUse} where device_addr=#{deviceAddr} and device_type=#{deviceType} and building_id=#{buildingId}") void updateIsUse(@Param("isUse") String isUse, @Param("deviceAddr") String deviceAddr, @Param("deviceType") String deviceType, @Param("buildingId") String buildingId); //修改使用状态1启用,0停用 @Update("update device_code_param2 set isUse=#{isUse} where device_addr=#{deviceAddr} and device_type=#{deviceType} and building_id=#{buildingId}") void updateIsUse2(@Param("isUse") String isUse, @Param("deviceAddr") String deviceAddr, @Param("deviceType") String deviceType, @Param("buildingId") String buildingId); //修改使用状态1启用,0停用 @Update("update device_code_param3 set isUse=#{isUse} where device_addr=#{deviceAddr} and device_type=#{deviceType} and building_id=#{buildingId}") void updateIsUse3(@Param("isUse") String isUse, @Param("deviceAddr") String deviceAddr, @Param("deviceType") String deviceType, @Param("buildingId") String buildingId); //删除监控表停用热泵记录 @Delete("delete * from now_data where device_addr=#{deviceAddr} and device_type=#{deviceType} and building_id=#{buildingId}") void deletePump(@Param("deviceAddr") String deviceAddr, @Param("deviceType") String deviceType, @Param("buildingId") String buildingId); //更新基表初始值 @Update("update device_install set init_value=#{initValue} where device_addr=#{deviceAddr} and device_type=#{deviceType} and building_id=#{buildingId} ") void updateInitValue(@Param("deviceAddr") String deviceAddr, @Param("deviceType") String deviceType, @Param("buildingId") String buildingId, @Param("initValue") String initValue); //查询最后一次采集时间 @Select("select last_date from device_install where device_type=#{deviceType} and device_addr=#{deviceAddr} and building_id=#{buildingId}") String selectLastDate(@Param("deviceType") String deviceType,@Param("deviceAddr") String deviceAddr,@Param("buildingId") String buildingId); //判断某栋楼是否有热泵设备 @Select("select count(*) from device_install where device_type='热泵' and building_id=#{buildingId} ") int judgePump(@Param("buildingId") String buildingId); //查询设备所属位置(低区或高区) @Select("select seat from device_install where device_type=#{deviceType} and device_addr=#{deviceAddr} and building_id=#{buildingId} ") String selectSeat(@Param("deviceType") String deviceType,@Param("deviceAddr") String deviceAddr,@Param("buildingId") String buildingId); @Update("update device_install set deviation_value = #{dataValue} where device_type = #{deviceType} and building_id = #{buildingId}") void updateDeviation(@Param("buildingId") Integer buildingId, @Param("deviceType") String deviceType, @Param("param") Integer param, @Param("dataValue") String dataValue); @Select("select isnull(deviation_value,0) from device_install where device_addr = #{deviceAddr} and device_type = #{deviceType} and building_id = #{buildingId}") Double selectDeviceDeviation(@Param("deviceAddr") String deviceAddr, @Param("deviceType") String deviceType, @Param("buildingId") String buildingId); @ResultMap("rs") @Select("select * from device_install where id = #{id} ") DeviceInstallEntity selectDeviceById(@Param("id") Long id); @Update("update device_install set last_value = #{lastValue}, last_date = getdate() where device_addr = #{deviceAddr} and building_id = #{buildingId} and device_type = #{deviceType} ") void updateLastValueByOther(@Param("deviceAddr") String addr, @Param("lastValue") String strWtLevel, @Param("deviceType") String deviceType, @Param("buildingId") String buildingId); }