<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.hssx.pcbms.mapper.GoodsMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.hssx.pcbms.entity.Goods">
        <id column="id" property="id" />
        <result column="name" property="name" />
        <result column="tag_id" property="tagId" />
        <result column="model_number" property="modelNumber" />
        <result column="unit" property="unit" />
        <result column="address" property="address" />
        <result column="factory" property="factory" />
        <result column="pic" property="pic" />
        <result column="service_life" property="serviceLife" />
        <result column="next_indate" property="nextIndate" />
        <result column="is_delete" property="isDelete" />
        <result column="creator_id" property="creatorId" />
        <result column="division_code" property="divisionCode" />
        <result column="suffix_code" property="suffixCode" />
        <result column="good_type" property="goodType" />
        <result column="rack_id" property="rackId" />
        <result column="rack_ip" property="rackIp" />
        <result column="rack_port" property="rackPort" />
        <result column="indate" property="indate" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, name, tag_id, model_number, unit, address, factory, pic, service_life, next_indate, is_delete, creator_id, division_code, suffix_code, good_type,rack_ip, rack_port, indate
    </sql>
    <resultMap id="BaseResultMapVO" type="com.hssx.pcbms.entity.vo.GoodsVO">
        <id column="id" property="id"/>
        <result column="name" property="name"/>
        <result column="temp" property="temp"/>
        <result column="hum" property="hum"/>
        <result column="door_status" property="doorStatus"/>
        <result column="tag_id" property="tagId"/>
        <result column="model_number" property="modelNumber"/>
        <result column="unit" property="unit"/>
        <result column="address" property="address"/>
        <result column="factory" property="factory"/>
        <result column="pic" property="pic"/>
        <result column="service_life" property="serviceLife"/>
        <result column="next_indate" property="nextIndate"/>
        <collection property="goodsNos" select="selectGoodsNoByGoodsId" javaType="java.util.List" column="{goodId = id}"
                    ofType="com.hssx.pcbms.entity.GoodsNo">
        </collection>
    </resultMap>
    <!-- 我的资产查询映射结果 -->
    <resultMap id="BaseResultMapMyList" type="com.hssx.pcbms.entity.vo.GoodsVO">
        <id column="id" property="id"/>
        <result column="name" property="name"/>
        <result column="tag_id" property="tagId"/>
        <result column="model_number" property="modelNumber"/>
        <result column="unit" property="unit"/>
        <result column="address" property="address"/>
        <result column="factory" property="factory"/>
        <result column="pic" property="pic"/>
        <result column="service_life" property="serviceLife"/>
        <result column="next_indate" property="nextIndate"/>
        <result column="divisioncode" property="divisionCode"/>
        <result column="suffixcode" property="suffixCode"/>
        <collection property="goodsNos" ofType="com.hssx.pcbms.entity.GoodsNo">
            <id column="nid" property="id"/>
            <result column="model_no" property="modelNo"/>
            <result column="division_code" property="divisionCode"/>
            <result column="suffix_code" property="suffixCode"/>
            <result column="state" property="state"/>
            <result column="indate" property="indate"/>
            <result column="goods_id" property="goodsId"/>
            <result column="user_id" property="userId"/>
            <result column="is_maintain" property="isMaintain" />
        </collection>
    </resultMap>

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMapDetail" type="com.hssx.pcbms.entity.vo.GoodsVO">
        <id column="id" property="id"/>
        <result column="name" property="name"/>
        <result column="temp" property="temp"/>
        <result column="hum" property="hum"/>
        <result column="door_status" property="doorStatus"/>
        <result column="tag_id" property="tagId"/>
        <result column="model_number" property="modelNumber"/>
        <result column="unit" property="unit"/>
        <result column="address" property="address"/>
        <result column="factory" property="factory"/>
        <result column="pic" property="pic"/>
        <result column="service_life" property="serviceLife"/>
        <result column="next_indate" property="nextIndate"/>
        <result column="divisioncode" property="divisionCode"/>
        <result column="suffixcode" property="suffixCode"/>
        <result column="good_type" property="goodType" />
        <result column="rack_id" property="rackId" />
        <result column="tag_name" property="tagName" />
        <collection property="goodsNosVO" ofType="com.hssx.pcbms.entity.vo.GoodsNoVO">
            <id column="nid" property="id"/>
            <result column="model_no" property="modelNo" />
            <result column="division_code" property="divisionCode" />
            <result column="suffix_code" property="suffixCode" />
            <result column="state" property="state" />
            <result column="indate" property="indate" />
            <result column="goods_id" property="goodsId" />
            <result column="user_id" property="userId" />
            <result column="update_indate" property="updateIndate" />
            <result column="is_maintain" property="isMaintain" />
            <result column="good_sn_no" property="goodSnNo" />
            <result column="label_id" property="labelId" />
            <result column="model_id" property="modelId" />
            <result column="u_bit_num" property="uBitNum" />
            <result column="power" property="power" />
            <result column="rated_current" property="ratedCurrent" />
            <result column="rated_voltage" property="ratedVoltage" />
            <result column="serial_number" property="serialNumber" />
            <result column="affiliate" property="affiliate" />
            <result column="device_category" property="deviceCategory" />
            <result column="stock" property="stock" />
            <result column="server_weight" property="serverWeight" />
            <result column="manufacturer" property="manufacturer" />
            <result column="supplier" property="supplier" />
            <result column="charger_id" property="chargerId" />
            <result column="charger_name" property="chargerName" />
            <result column="maintain_clc" property="maintainClc" />
            <result column="maintenance_phone" property="maintenancePhone" />
            <result column="last_maintainer_id" property="lastMaintainerId" />
            <result column="last_maintainer_name" property="lastMaintainerName" />
            <result column="next_maintainer_id" property="nextMaintainerId" />
            <result column="next_maintainer_name" property="nextMaintainerName" />
            <result column="last_update_time" property="lastUpdateTime" />
            <result column="next_update_time" property="nextUpdateTime" />
            <result column="grounding_time" property="groundingTime" />
            <result column="undercarriage_time" property="undercarriageTime" />
            <result column="first_use_time" property="firstUseTime" />
            <result column="current_state" property="currentState" />
            <result column="alarm_level" property="alarmLevel" />
            <result column="subordinate_user_id" property="subordinateUserId" />
            <result column="subordinate_user" property="subordinateUser" />
            <result column="floor" property="floor" />
            <result column="room" property="room" />
            <result column="column_place" property="columnPlace" />
            <result column="region" property="region" />
            <result column="is_rack" property="isRack" />
        </collection>
    </resultMap>
    <select id="getListBycondition" resultMap="BaseResultMapVO">
        select
        id, name, tag_id, model_number, unit, address,
        factory, pic, service_life, next_indate
        from
        goods
        <where>
            is_delete = 0 and good_type = 0
            <if test="keyName != null and keyName != ''">
                and name like concat('%',#{keyName},'%')
            </if>
            <if test="tagId != null">
                and tag_id = #{tagId}
            </if>
        </where>
        order by id desc
    </select>
    <resultMap id="GoodsNoMap" type="com.hssx.pcbms.entity.GoodsNo">
        <id column="id" property="id" />
        <result column="model_no" property="modelNo" />
        <result column="division_code" property="divisionCode" />
        <result column="suffix_code" property="suffixCode" />
        <result column="state" property="state" />
        <result column="indate" property="indate" />
        <result column="goods_id" property="goodsId" />
        <result column="user_id" property="userId" />
        <result column="update_indate" property="updateIndate" />
        <result column="is_maintain" property="isMaintain" />
        <result column="good_sn_no" property="goodSnNo" />
        <result column="label_id" property="labelId" />
        <result column="model_id" property="modelId" />
        <result column="u_bit_num" property="uBitNum" />
        <result column="power" property="power" />
        <result column="rated_current" property="ratedCurrent" />
        <result column="rated_voltage" property="ratedVoltage" />
        <result column="serial_number" property="serialNumber" />
        <result column="affiliate" property="affiliate" />
        <result column="device_category" property="deviceCategory" />
        <result column="stock" property="stock" />
        <result column="server_weight" property="serverWeight" />
        <result column="manufacturer" property="manufacturer" />
        <result column="supplier" property="supplier" />
        <result column="charger_id" property="chargerId" />
        <result column="charger_name" property="chargerName" />
        <result column="maintain_clc" property="maintainClc" />
        <result column="maintenance_phone" property="maintenancePhone" />
        <result column="last_maintainer_id" property="lastMaintainerId" />
        <result column="last_maintainer_name" property="lastMaintainerName" />
        <result column="next_maintainer_id" property="nextMaintainerId" />
        <result column="next_maintainer_name" property="nextMaintainerName" />
        <result column="last_update_time" property="lastUpdateTime" />
        <result column="next_update_time" property="nextUpdateTime" />
        <result column="grounding_time" property="groundingTime" />
        <result column="undercarriage_time" property="undercarriageTime" />
        <result column="first_use_time" property="firstUseTime" />
        <result column="current_state" property="currentState" />
        <result column="alarm_level" property="alarmLevel" />
        <result column="subordinate_user_id" property="subordinateUserId" />
        <result column="subordinate_user" property="subordinateUser" />
        <result column="floor" property="floor" />
        <result column="room" property="room" />
        <result column="column_place" property="columnPlace" />
        <result column="region" property="region" />
        <result column="is_rack" property="isRack" />
    </resultMap>
    <select id="selectGoodsNoByGoodsId" resultMap="GoodsNoMap">
        select
            id, model_no, state,indate, goods_id,user_id, update_indate,
            is_maintain, good_sn_no,
            label_id,model_id, u_bit_num, current_state, alarm_level,is_rack
        from
            goods_no
        where
            goods_id = #{goodId}
    </select>
    <select id="getDetail" resultMap="BaseResultMapDetail">
        select
        g.id, g.name, g.tag_id,gt.name tag_name, g.model_number, g.unit,g.address, g.factory, g.pic, g.service_life, g.next_indate,g.division_code divisioncode,g.suffix_code suffixcode,
        g.is_delete,gn.id nid,g.good_type,rd.hum,rd.door_status,rd.temp,
        gn.model_no, gn.division_code, gn.suffix_code, gn.state, gn.indate, gn.goods_id, gn.user_id,u.name username,gn.is_maintain,u.phone
        from
        goods g
        left join
        goods_no gn
        on g.id = gn.goods_id
        left join user u
        on u.id = gn.user_id
        left join rack_data rd
        on g.id = rd.goods_id
        left join goods_tags gt
        on gt.id = g.tag_id
        <where>
            g.id = #{id}
        </where>
    </select>
    <select id="getEuipmentList" resultMap="BaseResultMapDetail">
        select
        g.id, g.name, g.tag_id,gt.name tag_name, g.model_number, g.unit,g.address, g.factory, g.pic, g.service_life, g.next_indate,g.division_code divisioncode,g.suffix_code suffixcode,
        g.is_delete,gn.id nid,g.good_type,rd.hum,rd.door_status,rd.temp,gn.is_rack,
        gn.model_no, gn.division_code, gn.suffix_code, gn.state, gn.indate, gn.goods_id, gn.user_id,u.name username,gn.is_maintain,u.phone
        from
        goods g
        left join
        goods_no gn
        on g.id = gn.goods_id
        left join user u
        on u.id = gn.user_id
        left join rack_data rd
        on g.id = rd.goods_id
        left join goods_tags gt
        on gt.id = g.tag_id
        <where>
            g.id in <foreach collection="ids" index="index" open="(" item="item" close=")" separator=",">
            #{item}
        </foreach>
        </where>
    </select>

    <select id="selectMyList" resultMap="BaseResultMapMyList">
        select
        g.id, g.name, g.tag_id, g.model_number, g.unit,g.address,
        g.factory, g.pic, g.service_life, g.next_indate,g.division_code divisioncode,
        g.suffix_code suffixcode,g.is_delete,gn.id nid,g.indate,gn.model_no,
        gn.division_code, gn.suffix_code, gn.state, gn.indate, gn.goods_id,
        gn.user_id,u.name username,gn.is_maintain,u.phone
        from
        goods g
        left join
        goods_no gn
        on g.id = gn.goods_id
        left join user u
        on u.id = gn.user_id
        <where>
            AND gn.user_id = #{uid,jdbcType=INTEGER}
        </where>
        order by g.indate desc
        <if test="start != null and pageSize != null">
            limit #{start,jdbcType=INTEGER} ,#{pageSize,jdbcType=INTEGER}
        </if>
    </select>

    <select id="getRackListBycondition" resultMap="BaseResultMapVO">
        select
        g.id, g.name, g.tag_id,rd.hum,rd.door_status,rd.temp,g.indate,
        g.model_number, g.unit, g.address, g.factory, g.pic,
        g.service_life, g.next_indate
        from
        goods g
        left join rack_data rd
        on g.id = rd.goods_id
        <where>
            is_delete = 0 and good_type = #{goodType}
            <if test="keyName != null and keyName != ''">
                and g.name like concat('%',#{keyName},'%')
            </if>
            <if test="tagId != null">
                and g.tag_id = #{tagId}
            </if>
        </where>
        order by g.indate desc
    </select>
</mapper>
