<?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.bonus.sgzb.base.mapper.MaMachineMapper">

    <resultMap type="com.bonus.sgzb.base.domain.MaMachine" id="MaMachineResult">
        <id     property="maId"      column="ma_id"      />
        <result property="typeId"    column="type_id"    />
        <result property="maCode"     column="ma_code"     />
        <result property="preCode"   column="pre_code"   />
        <result property="maStatus"    column="ma_status"    />
        <result property="qrCode"      column="qr_code"      />
        <result property="buyPrice"    column="buy_price"    />
        <result property="maVender"      column="ma_vender"      />
        <result property="outFacTime"    column="out_fac_time"    />
        <result property="assetsCode"    column="assets_code"    />
        <result property="checkMan"    column="check_man"    />
        <result property="thisCheckTime"    column="this_check_time"    />
        <result property="nextCheckTime"    column="next_check_time"    />
        <result property="gpsCode"    column="gps_code"    />
        <result property="rfidCode"    column="rfid_code"    />
        <result property="erpCode"    column="erp_code"    />
        <result property="transferCode"    column="transfer_code"    />
        <result property="inOutNum"    column="in_out_num"    />
        <result property="buyTask"    column="buy_task"    />
        <result property="ownHouse"    column="own_house"    />
        <result property="companyId"    column="company_id"    />
    </resultMap>

    <sql id="selectMaMachine">
        select ma_id, type_id, ma_code, pre_code, ma_status, qr_code, buy_price, ma_vender, out_fac_time, out_fac_code,
               assets_code, check_man, this_check_time, next_check_time, gps_code, rfid_code, erp_code, transfer_code,
               in_out_num, buy_task, own_house ,company_id
        from ma_machine
    </sql>


    <select id="getMaMachine" resultType="com.bonus.sgzb.base.domain.MaMachine">

        select ma_id, type_id, ma_code, pre_code, ma_status, qr_code, buy_price, ma_vender, out_fac_time, out_fac_code,
        assets_code, check_man, this_check_time, next_check_time, gps_code, rfid_code, erp_code, transfer_code,
        in_out_num, buy_task, own_house ,company_id
        from ma_machine
        <where>
            <if test="maId != null and maId != ''">
                AND ma_id = #{maId}
            </if>
            <if test="typeId != null and typeId != ''">
                AND type_id = #{typeId}
            </if>
            <if test="maCode != null and maCode != ''">
                AND ma_code = #{maCode}
            </if>
            <if test="preCode != null and preCode != ''">
                AND pre_code = #{preCode}
            </if>
            <if test="maStatus != null and maStatus != ''">
                and ma_status = #{maStatus}
            </if>
            <if test="qrCode != null and qrCode != ''">
                and qr_code = #{qrCode}
            </if>
            <if test="buyPrice != null and buyPrice != ''">
                and buy_price = #{buyPrice}
            </if>
            <if test="maVender != null and maVender != ''">
                and ma_vender = #{maVender}
            </if>
            <if test="outFacTime != null and outFacTime != ''">
                and out_fac_time = #{outFacTime}
            </if>
            <if test="outFacCode != null and outFacCode != ''">
                and out_fac_code = #{outFacCode}
            </if>
            <if test="assetsCode != null and assetsCode != ''">
                and assets_code = #{assetsCode}
            </if>
            <if test="checkMan != null and checkMan != ''">
                and update_time = #{updateTime}
            </if>
            <if test="remark != null and remark != ''">
                and check_man = #{remark}
            </if>
            <if test="thisCheckTime != null and thisCheckTime != ''">
                and this_check_time = #{thisCheckTime}
            </if>
            <if test="nextCheckTime != null and nextCheckTime != ''">
                and next_check_time = #{nextCheckTime}
            </if>
            <if test="gpsCode != null and gpsCode != ''">
                and gps_code = #{gpsCode}
            </if>
            <if test="rfidCode != null and rfidCode != ''">
                and rfid_code = #{rfidCode}
            </if>

            <if test="erpCode != null and erpCode != ''">
                and erp_code = #{erpCode}
            </if>
            <if test="transferCode != null and transferCode != ''">
                and transfer_code = #{transferCode}
            </if>
            <if test="inOutNum != null and inOutNum != ''">
                and in_out_num = #{inOutNum}
            </if>
            <if test="buyTask != null and buyTask != ''">
                and buy_task = #{buyTask}
            </if>
            <if test="ownHouse != null and ownHouse != ''">
                and own_house = #{ownHouse}
            </if>
            <if test="companyId != null and companyId != ''">
                and company_id = #{companyId}
            </if>
        </where>
    </select>

    <insert id="maMachineAdd" parameterType="com.bonus.sgzb.base.domain.MaMachine">
        insert into ma_machine (
        <if test="typeId != null and typeId != '' ">type_id,</if>
        <if test="maCode != null and maCode != '' ">ma_code,</if>
        <if test="preCode != null and preCode != '' ">pre_code,</if>
        <if test="maStatus != null and maStatus != '' ">ma_status,</if>
        <if test="qrCode != null and qrCode != ''">qr_code,</if>
        <if test="buyPrice != null and buyPrice != ''">buy_price,</if>
        <if test="maVender != null and maVender != ''">ma_vender,</if>
        <if test="outFacTime != null and outFacTime != ''">out_fac_time,</if>
        <if test="outFacCode != null and outFacCode != ''">out_fac_code,</if>
        <if test="assetsCode != null and assetsCode != ''">assets_code,</if>
        <if test="checkMan != null and checkMan != ''">check_man,</if>
        <if test="thisCheckTime != null and thisCheckTime != ''">this_check_time,</if>
        <if test="nextCheckTime != null and nextCheckTime != ''">next_check_time,</if>
        <if test="gpsCode != null and gpsCode != ''">gps_code,</if>
        <if test="rfidCode != null and rfidCode != ''">rfid_code,</if>
        <if test="erpCode != null and erpCode != ''">erp_code,</if>
        <if test="transferCode != null and transferCode != ''">erp_code,</if>
        <if test="inOutNum != null and inOutNum != ''">in_out_num,</if>
        <if test="buyTask != null and buyTask != ''">buy_task,</if>
        <if test="ownHouse != null and ownHouse != ''">own_house,</if>
        <if test="companyId != null and companyId != ''">company_id</if>
        )values(
        <if test="typeId != null and typeId != ''">#{typeId},</if>
        <if test="maCode != null and maCode != ''">#{maCode},</if>
        <if test="preCode != null and preCode != ''">#{preCode},</if>
        <if test="maStatus != null and maStatus != ''">#{maStatus},</if>
        <if test="qrCode != null and qrCode != ''">#{telphone},</if>
        <if test="buyPrice != null and buyPrice != ''">#{buyPrice},</if>
        <if test="maVender != null and maVender != ''">#{maVender},</if>
        <if test="outFacTime != null and outFacTime != ''">#{outFacTime},</if>
        <if test="outFacCode != null and outFacCode != ''">#{outFacCode},</if>
        <if test="assetsCode != null and assetsCode != ''">#{assetsCode},</if>
        <if test="checkMan != null and checkMan != ''">#{checkMan},</if>
        <if test="thisCheckTime != null and thisCheckTime != ''">#{thisCheckTime},</if>
        <if test="nextCheckTime != null and nextCheckTime != ''">#{nextCheckTime},</if>
        <if test="gpsCode != null and gpsCode != ''">#{gpsCode},</if>
        <if test="rfidCode != null and rfidCode != ''">#{rfidCode},</if>
        <if test="erpCode != null and erpCode != ''">#{erpCode},</if>
        <if test="transferCode != null and transferCode != ''">#{transferCode},</if>
        <if test="inOutNum != null and inOutNum != ''">#{inOutNum},</if>
        <if test="buyTask != null and buyTask != ''">#{buyTask},</if>
        <if test="ownHouse != null and ownHouse != ''">#{ownHouse},</if>
        <if test="companyId != null and companyId != ''">#{companyId}</if>
        )
    </insert>

    <update id="updateMaMachine" parameterType="com.bonus.sgzb.base.domain.MaMachine">
        update ma_machine
        <set>
            <if test="typeId != null and typeId != ''">type_id = #{typeId},</if>
            <if test="maCode != null and maCode != ''">ma_code = #{maCode},</if>
            <if test="preCode != null and preCode != ''">pre_code = #{preCode},</if>
            <if test="maStatus != null and maStatus != ''">ma_status = #{maStatus},</if>
            <if test="qrCode != null and qrCode != ''">qr_code = #{qrCode},</if>
            <if test="buyPrice != null and buyPrice != ''">buy_price = #{buyPrice},</if>
            <if test="maVender != null and maVender != ''">ma_vender = #{maVender},</if>
            <if test="outFacTime != null and outFacTime != ''">out_fac_time =#{outFacTime},</if>
            <if test="outFacCode != null and outFacCode != ''">out_fac_code = #{outFacCode},</if>
            <if test="assetsCode != null and assetsCode != ''">assets_code =#{assetsCode},</if>
            <if test="checkMan != null and checkMan != ''">check_man = #{checkMan},</if>
            <if test="thisCheckTime != null and thisCheckTime != ''">this_check_time = #{thisCheckTime},</if>
            <if test="nextCheckTime != null and nextCheckTime != ''">next_check_time = #{nextCheckTime},</if>
            <if test="gpsCode != null and gpsCode != ''">gps_code = #{gpsCode},</if>
            <if test="rfidCode != null and rfidCode != ''">rfid_code = #{rfidCode},</if>
            <if test="erpCode != null and erpCode != ''">erp_code = #{erpCode},</if>
            <if test="transferCode != null and transferCode != ''">transfer_code = #{transferCode},</if>
            <if test="inOutNum != null and inOutNum != ''">in_out_num = #{inOutNum},</if>
            <if test="buyTask != null and buyTask != ''">buy_task = #{buyTask},</if>
            <if test="ownHouse != null and ownHouse != ''">own_house = #{ownHouse},</if>
            <if test="companyId != null and companyId != ''">company_id = #{companyId},</if>
        </set>
        where ma_id = #{maId}
    </update>

    <delete id="remove" parameterType="Long">
        delete from ma_machine where ma_id in
        <foreach item="maId" collection="array" open="(" separator="," close=")">
            #{maId}
        </foreach>
    </delete>
</mapper>