<?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.mofangchuxing.aska.dao.mapper.AskaRetailsMapper">

    <resultMap id="BaseResultMap" type="com.mofangchuxing.aska.dao.domain.AskaRetails">
            <id property="id" column="id" jdbcType="INTEGER"/>
            <result property="name" column="name" jdbcType="CHAR"/>
            <result property="address" column="address" jdbcType="VARCHAR"/>
            <result property="type" column="type" jdbcType="CHAR"/>
            <result property="lat" column="lat" jdbcType="DOUBLE"/>
            <result property="lng" column="lng" jdbcType="DOUBLE"/>
            <result property="ownerId" column="ownerId" jdbcType="INTEGER"/>
            <result property="phone" column="phone" jdbcType="CHAR"/>
            <result property="note" column="note" jdbcType="VARCHAR"/>
            <result property="account" column="account" jdbcType="VARCHAR"/>
            <result property="accountName" column="accountName" jdbcType="VARCHAR"/>
            <result property="accountType" column="accountType" jdbcType="CHAR"/>
            <result property="relation" column="relation" jdbcType="CHAR"/>
            <result property="apiv3" column="apiv3" jdbcType="VARCHAR"/>
            <result property="certPath" column="certPath" jdbcType="VARCHAR"/>
            <result property="tripartite" column="tripartite" jdbcType="CHAR"/>
            <result property="tripvalue" column="tripvalue" jdbcType="INTEGER"/>
            <result property="realtimeSplit" column="realtimeSplit" jdbcType="INTEGER"/>
            <result property="status" column="status" jdbcType="CHAR"/>
            <result property="totalIncome" column="totalIncome" jdbcType="INTEGER"/>
            <result property="totalSplit" column="totalSplit" jdbcType="INTEGER"/>
            <result property="totalCashOut" column="totalCashOut" jdbcType="INTEGER"/>
            <result property="totalRefund" column="totalRefund" jdbcType="INTEGER"/>
            <result property="balance" column="balance" jdbcType="INTEGER"/>
    </resultMap>

    <sql id="Base_Column_List">
        id,name,address,
        type,lat,lng,
        ownerId,phone,note,
        account,accountName,accountType,
        relation,apiv3,certPath,
        tripartite,tripvalue,realtimeSplit,
        status,totalIncome,totalSplit,
        totalCashOut,totalRefund,balance
    </sql>

    <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from aska_retails
        where  id = #{id,jdbcType=INTEGER} 
    </select>

    <select id="listAllRetails" resultType="com.mofangchuxing.aska.domain.vo.AskaRetailsVo">
        select
        ar.*,aa.name as username
        from aska_retails ar left join aska_accounts aa on ar.ownerId = aa.id
        where 1=1
        <if test="name != null and name != ''">
            and ar.name = #{name}
        </if>
        <if test="retailType != null and retailType != ''">
            and ar.retail_type = #{retailType}
        </if>
        <if test="status != null">
            and ar.status = #{status}
        </if>
    </select>
    <select id="listAllRetailsNoLimit" resultType="com.mofangchuxing.aska.domain.vo.AskaRetailsVo">
        select id as retailId,
               name as retailName,
               lat,lng,address,status
        from aska_retails
    </select>
    <select id="selectByOwnerId" resultType="com.mofangchuxing.aska.domain.vo.AskaRetailsVo">
        select id as retailId,name as retailName from aska_retails where ownerId = #{ownerId} limit 1
    </select>

    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
        delete from aska_retails
        where  id = #{id,jdbcType=INTEGER} 
    </delete>
    <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.mofangchuxing.aska.dao.domain.AskaRetails" useGeneratedKeys="true">
        insert into aska_retails
        ( id,name,address
        ,type,lat,lng
        ,ownerId,phone,note
        ,account,accountName,accountType
        ,relation,apiv3,certPath
        ,tripartite,tripvalue,realtimeSplit
        ,status,totalIncome,totalSplit
        ,totalCashOut,totalRefund,balance
        )
        values (#{id,jdbcType=INTEGER},#{name,jdbcType=CHAR},#{address,jdbcType=VARCHAR}
        ,#{type,jdbcType=CHAR},#{lat,jdbcType=DOUBLE},#{lng,jdbcType=DOUBLE}
        ,#{ownerId,jdbcType=INTEGER},#{phone,jdbcType=CHAR},#{note,jdbcType=VARCHAR}
        ,#{account,jdbcType=VARCHAR},#{accountName,jdbcType=VARCHAR},#{accountType,jdbcType=CHAR}
        ,#{relation,jdbcType=CHAR},#{apiv3,jdbcType=VARCHAR},#{certPath,jdbcType=VARCHAR}
        ,#{tripartite,jdbcType=CHAR},#{tripvalue,jdbcType=INTEGER},#{realtimeSplit,jdbcType=INTEGER}
        ,#{status,jdbcType=CHAR},#{totalIncome,jdbcType=INTEGER},#{totalSplit,jdbcType=INTEGER}
        ,#{totalCashOut,jdbcType=INTEGER},#{totalRefund,jdbcType=INTEGER},#{balance,jdbcType=INTEGER}
        )
    </insert>
    <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.mofangchuxing.aska.dao.domain.AskaRetails" useGeneratedKeys="true">
        insert into aska_retails
        <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="id != null">id,</if>
                <if test="name != null">name,</if>
                <if test="address != null">address,</if>
                <if test="type != null">type,</if>
                <if test="lat != null">lat,</if>
                <if test="lng != null">lng,</if>
                <if test="ownerId != null">ownerId,</if>
                <if test="phone != null">phone,</if>
                <if test="note != null">note,</if>
                <if test="account != null">account,</if>
                <if test="accountName != null">accountName,</if>
                <if test="accountType != null">accountType,</if>
                <if test="relation != null">relation,</if>
                <if test="apiv3 != null">apiv3,</if>
                <if test="certPath != null">certPath,</if>
                <if test="tripartite != null">tripartite,</if>
                <if test="tripvalue != null">tripvalue,</if>
                <if test="realtimeSplit != null">realtimeSplit,</if>
                <if test="status != null">status,</if>
                <if test="totalIncome != null">totalIncome,</if>
                <if test="totalSplit != null">totalSplit,</if>
                <if test="totalCashOut != null">totalCashOut,</if>
                <if test="totalRefund != null">totalRefund,</if>
                <if test="balance != null">balance,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                <if test="id != null">#{id,jdbcType=INTEGER},</if>
                <if test="name != null">#{name,jdbcType=CHAR},</if>
                <if test="address != null">#{address,jdbcType=VARCHAR},</if>
                <if test="type != null">#{type,jdbcType=CHAR},</if>
                <if test="lat != null">#{lat,jdbcType=DOUBLE},</if>
                <if test="lng != null">#{lng,jdbcType=DOUBLE},</if>
                <if test="ownerId != null">#{ownerId,jdbcType=INTEGER},</if>
                <if test="phone != null">#{phone,jdbcType=CHAR},</if>
                <if test="note != null">#{note,jdbcType=VARCHAR},</if>
                <if test="account != null">#{account,jdbcType=VARCHAR},</if>
                <if test="accountName != null">#{accountName,jdbcType=VARCHAR},</if>
                <if test="accountType != null">#{accountType,jdbcType=CHAR},</if>
                <if test="relation != null">#{relation,jdbcType=CHAR},</if>
                <if test="apiv3 != null">#{apiv3,jdbcType=VARCHAR},</if>
                <if test="certPath != null">#{certPath,jdbcType=VARCHAR},</if>
                <if test="tripartite != null">#{tripartite,jdbcType=CHAR},</if>
                <if test="tripvalue != null">#{tripvalue,jdbcType=INTEGER},</if>
                <if test="realtimeSplit != null">#{realtimeSplit,jdbcType=INTEGER},</if>
                <if test="status != null">#{status,jdbcType=CHAR},</if>
                <if test="totalIncome != null">#{totalIncome,jdbcType=INTEGER},</if>
                <if test="totalSplit != null">#{totalSplit,jdbcType=INTEGER},</if>
                <if test="totalCashOut != null">#{totalCashOut,jdbcType=INTEGER},</if>
                <if test="totalRefund != null">#{totalRefund,jdbcType=INTEGER},</if>
                <if test="balance != null">#{balance,jdbcType=INTEGER},</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective" parameterType="com.mofangchuxing.aska.dao.domain.AskaRetails">
        update aska_retails
        <set>
                <if test="name != null">
                    name = #{name,jdbcType=CHAR},
                </if>
                <if test="address != null">
                    address = #{address,jdbcType=VARCHAR},
                </if>
                <if test="type != null">
                    type = #{type,jdbcType=CHAR},
                </if>
                <if test="lat != null">
                    lat = #{lat,jdbcType=DOUBLE},
                </if>
                <if test="lng != null">
                    lng = #{lng,jdbcType=DOUBLE},
                </if>
                <if test="ownerId != null">
                    ownerId = #{ownerId,jdbcType=INTEGER},
                </if>
                <if test="phone != null">
                    phone = #{phone,jdbcType=CHAR},
                </if>
                <if test="note != null">
                    note = #{note,jdbcType=VARCHAR},
                </if>
                <if test="account != null">
                    account = #{account,jdbcType=VARCHAR},
                </if>
                <if test="accountName != null">
                    accountName = #{accountName,jdbcType=VARCHAR},
                </if>
                <if test="accountType != null">
                    accountType = #{accountType,jdbcType=CHAR},
                </if>
                <if test="relation != null">
                    relation = #{relation,jdbcType=CHAR},
                </if>
                <if test="apiv3 != null">
                    apiv3 = #{apiv3,jdbcType=VARCHAR},
                </if>
                <if test="certPath != null">
                    certPath = #{certPath,jdbcType=VARCHAR},
                </if>
                <if test="tripartite != null">
                    tripartite = #{tripartite,jdbcType=CHAR},
                </if>
                <if test="tripvalue != null">
                    tripvalue = #{tripvalue,jdbcType=INTEGER},
                </if>
                <if test="realtimeSplit != null">
                    realtimeSplit = #{realtimeSplit,jdbcType=INTEGER},
                </if>
                <if test="status != null">
                    status = #{status,jdbcType=CHAR},
                </if>
                <if test="totalIncome != null">
                    totalIncome = #{totalIncome,jdbcType=INTEGER},
                </if>
                <if test="totalSplit != null">
                    totalSplit = #{totalSplit,jdbcType=INTEGER},
                </if>
                <if test="totalCashOut != null">
                    totalCashOut = #{totalCashOut,jdbcType=INTEGER},
                </if>
                <if test="totalRefund != null">
                    totalRefund = #{totalRefund,jdbcType=INTEGER},
                </if>
                <if test="balance != null">
                    balance = #{balance,jdbcType=INTEGER},
                </if>
        </set>
        where   id = #{id,jdbcType=INTEGER} 
    </update>
    <update id="updateByPrimaryKey" parameterType="com.mofangchuxing.aska.dao.domain.AskaRetails">
        update aska_retails
        set 
            name =  #{name,jdbcType=CHAR},
            address =  #{address,jdbcType=VARCHAR},
            type =  #{type,jdbcType=CHAR},
            lat =  #{lat,jdbcType=DOUBLE},
            lng =  #{lng,jdbcType=DOUBLE},
            ownerId =  #{ownerId,jdbcType=INTEGER},
            phone =  #{phone,jdbcType=CHAR},
            note =  #{note,jdbcType=VARCHAR},
            account =  #{account,jdbcType=VARCHAR},
            accountName =  #{accountName,jdbcType=VARCHAR},
            accountType =  #{accountType,jdbcType=CHAR},
            relation =  #{relation,jdbcType=CHAR},
            apiv3 =  #{apiv3,jdbcType=VARCHAR},
            certPath =  #{certPath,jdbcType=VARCHAR},
            tripartite =  #{tripartite,jdbcType=CHAR},
            tripvalue =  #{tripvalue,jdbcType=INTEGER},
            realtimeSplit =  #{realtimeSplit,jdbcType=INTEGER},
            status =  #{status,jdbcType=CHAR},
            totalIncome =  #{totalIncome,jdbcType=INTEGER},
            totalSplit =  #{totalSplit,jdbcType=INTEGER},
            totalCashOut =  #{totalCashOut,jdbcType=INTEGER},
            totalRefund =  #{totalRefund,jdbcType=INTEGER},
            balance =  #{balance,jdbcType=INTEGER}
        where   id = #{id,jdbcType=INTEGER} 
    </update>
</mapper>