<?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.chaozhanggui.dao.system.dao.TbPlussCashMapper">
  <resultMap id="BaseResultMap" type="com.chaozhanggui.dao.system.entity.TbPlussCash">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="userId" jdbcType="INTEGER" property="userid" />
    <result column="userName" jdbcType="VARCHAR" property="username" />
    <result column="merchantCode" jdbcType="VARCHAR" property="merchantcode" />
    <result column="merchantName" jdbcType="VARCHAR" property="merchantname" />
    <result column="accountNo" jdbcType="VARCHAR" property="accountno" />
    <result column="accountName" jdbcType="VARCHAR" property="accountname" />
    <result column="cashAmt" jdbcType="DECIMAL" property="cashamt" />
    <result column="status" jdbcType="INTEGER" property="status" />
    <result column="reason" jdbcType="VARCHAR" property="reason" />
    <result column="createDt" jdbcType="TIMESTAMP" property="createdt" />
    <result column="updateDt" jdbcType="TIMESTAMP" property="updatedt" />
    <result column="logo" jdbcType="VARCHAR" property="logo" />
    <result column="cashNumber" jdbcType="VARCHAR" property="cashnumber" />
    <result column="backNo" jdbcType="VARCHAR" property="backno" />
    <result column="backDt" jdbcType="TIMESTAMP" property="backdt" />
    <result column="updator" jdbcType="VARCHAR" property="updator" />
    <result column="type" jdbcType="INTEGER" property="type" />
    <result column="baseServiceCharge" jdbcType="DECIMAL" property="baseservicecharge" />
    <result column="ratioCharge" jdbcType="DECIMAL" property="ratiocharge" />
    <result column="virRealCashAmt" jdbcType="DECIMAL" property="virrealcashamt" />
    <result column="virTotalCharge" jdbcType="DECIMAL" property="virtotalcharge" />
    <result column="cashStatus" jdbcType="VARCHAR" property="cashstatus" />
    <result column="cashStatusNow" jdbcType="VARCHAR" property="cashstatusnow" />
  </resultMap>
  <sql id="Base_Column_List">
    id, userId, userName, merchantCode, merchantName, accountNo, accountName, cashAmt, 
    status, reason, createDt, updateDt, logo, cashNumber, backNo, backDt, updator, type, 
    baseServiceCharge, ratioCharge, virRealCashAmt, virTotalCharge, cashStatus, cashStatusNow
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from tb_pluss_cash
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from tb_pluss_cash
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.chaozhanggui.dao.system.entity.TbPlussCash">
    insert into tb_pluss_cash (id, userId, userName, 
      merchantCode, merchantName, accountNo, 
      accountName, cashAmt, status, 
      reason, createDt, updateDt, 
      logo, cashNumber, backNo, 
      backDt, updator, type, 
      baseServiceCharge, ratioCharge, virRealCashAmt, 
      virTotalCharge, cashStatus, cashStatusNow
      )
    values (#{id,jdbcType=INTEGER}, #{userid,jdbcType=INTEGER}, #{username,jdbcType=VARCHAR}, 
      #{merchantcode,jdbcType=VARCHAR}, #{merchantname,jdbcType=VARCHAR}, #{accountno,jdbcType=VARCHAR}, 
      #{accountname,jdbcType=VARCHAR}, #{cashamt,jdbcType=DECIMAL}, #{status,jdbcType=INTEGER}, 
      #{reason,jdbcType=VARCHAR}, #{createdt,jdbcType=TIMESTAMP}, #{updatedt,jdbcType=TIMESTAMP}, 
      #{logo,jdbcType=VARCHAR}, #{cashnumber,jdbcType=VARCHAR}, #{backno,jdbcType=VARCHAR}, 
      #{backdt,jdbcType=TIMESTAMP}, #{updator,jdbcType=VARCHAR}, #{type,jdbcType=INTEGER}, 
      #{baseservicecharge,jdbcType=DECIMAL}, #{ratiocharge,jdbcType=DECIMAL}, #{virrealcashamt,jdbcType=DECIMAL}, 
      #{virtotalcharge,jdbcType=DECIMAL}, #{cashstatus,jdbcType=VARCHAR}, #{cashstatusnow,jdbcType=VARCHAR}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.chaozhanggui.dao.system.entity.TbPlussCash">
    insert into tb_pluss_cash
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="userid != null">
        userId,
      </if>
      <if test="username != null">
        userName,
      </if>
      <if test="merchantcode != null">
        merchantCode,
      </if>
      <if test="merchantname != null">
        merchantName,
      </if>
      <if test="accountno != null">
        accountNo,
      </if>
      <if test="accountname != null">
        accountName,
      </if>
      <if test="cashamt != null">
        cashAmt,
      </if>
      <if test="status != null">
        status,
      </if>
      <if test="reason != null">
        reason,
      </if>
      <if test="createdt != null">
        createDt,
      </if>
      <if test="updatedt != null">
        updateDt,
      </if>
      <if test="logo != null">
        logo,
      </if>
      <if test="cashnumber != null">
        cashNumber,
      </if>
      <if test="backno != null">
        backNo,
      </if>
      <if test="backdt != null">
        backDt,
      </if>
      <if test="updator != null">
        updator,
      </if>
      <if test="type != null">
        type,
      </if>
      <if test="baseservicecharge != null">
        baseServiceCharge,
      </if>
      <if test="ratiocharge != null">
        ratioCharge,
      </if>
      <if test="virrealcashamt != null">
        virRealCashAmt,
      </if>
      <if test="virtotalcharge != null">
        virTotalCharge,
      </if>
      <if test="cashstatus != null">
        cashStatus,
      </if>
      <if test="cashstatusnow != null">
        cashStatusNow,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=INTEGER},
      </if>
      <if test="userid != null">
        #{userid,jdbcType=INTEGER},
      </if>
      <if test="username != null">
        #{username,jdbcType=VARCHAR},
      </if>
      <if test="merchantcode != null">
        #{merchantcode,jdbcType=VARCHAR},
      </if>
      <if test="merchantname != null">
        #{merchantname,jdbcType=VARCHAR},
      </if>
      <if test="accountno != null">
        #{accountno,jdbcType=VARCHAR},
      </if>
      <if test="accountname != null">
        #{accountname,jdbcType=VARCHAR},
      </if>
      <if test="cashamt != null">
        #{cashamt,jdbcType=DECIMAL},
      </if>
      <if test="status != null">
        #{status,jdbcType=INTEGER},
      </if>
      <if test="reason != null">
        #{reason,jdbcType=VARCHAR},
      </if>
      <if test="createdt != null">
        #{createdt,jdbcType=TIMESTAMP},
      </if>
      <if test="updatedt != null">
        #{updatedt,jdbcType=TIMESTAMP},
      </if>
      <if test="logo != null">
        #{logo,jdbcType=VARCHAR},
      </if>
      <if test="cashnumber != null">
        #{cashnumber,jdbcType=VARCHAR},
      </if>
      <if test="backno != null">
        #{backno,jdbcType=VARCHAR},
      </if>
      <if test="backdt != null">
        #{backdt,jdbcType=TIMESTAMP},
      </if>
      <if test="updator != null">
        #{updator,jdbcType=VARCHAR},
      </if>
      <if test="type != null">
        #{type,jdbcType=INTEGER},
      </if>
      <if test="baseservicecharge != null">
        #{baseservicecharge,jdbcType=DECIMAL},
      </if>
      <if test="ratiocharge != null">
        #{ratiocharge,jdbcType=DECIMAL},
      </if>
      <if test="virrealcashamt != null">
        #{virrealcashamt,jdbcType=DECIMAL},
      </if>
      <if test="virtotalcharge != null">
        #{virtotalcharge,jdbcType=DECIMAL},
      </if>
      <if test="cashstatus != null">
        #{cashstatus,jdbcType=VARCHAR},
      </if>
      <if test="cashstatusnow != null">
        #{cashstatusnow,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.chaozhanggui.dao.system.entity.TbPlussCash">
    update tb_pluss_cash
    <set>
      <if test="userid != null">
        userId = #{userid,jdbcType=INTEGER},
      </if>
      <if test="username != null">
        userName = #{username,jdbcType=VARCHAR},
      </if>
      <if test="merchantcode != null">
        merchantCode = #{merchantcode,jdbcType=VARCHAR},
      </if>
      <if test="merchantname != null">
        merchantName = #{merchantname,jdbcType=VARCHAR},
      </if>
      <if test="accountno != null">
        accountNo = #{accountno,jdbcType=VARCHAR},
      </if>
      <if test="accountname != null">
        accountName = #{accountname,jdbcType=VARCHAR},
      </if>
      <if test="cashamt != null">
        cashAmt = #{cashamt,jdbcType=DECIMAL},
      </if>
      <if test="status != null">
        status = #{status,jdbcType=INTEGER},
      </if>
      <if test="reason != null">
        reason = #{reason,jdbcType=VARCHAR},
      </if>
      <if test="createdt != null">
        createDt = #{createdt,jdbcType=TIMESTAMP},
      </if>
      <if test="updatedt != null">
        updateDt = #{updatedt,jdbcType=TIMESTAMP},
      </if>
      <if test="logo != null">
        logo = #{logo,jdbcType=VARCHAR},
      </if>
      <if test="cashnumber != null">
        cashNumber = #{cashnumber,jdbcType=VARCHAR},
      </if>
      <if test="backno != null">
        backNo = #{backno,jdbcType=VARCHAR},
      </if>
      <if test="backdt != null">
        backDt = #{backdt,jdbcType=TIMESTAMP},
      </if>
      <if test="updator != null">
        updator = #{updator,jdbcType=VARCHAR},
      </if>
      <if test="type != null">
        type = #{type,jdbcType=INTEGER},
      </if>
      <if test="baseservicecharge != null">
        baseServiceCharge = #{baseservicecharge,jdbcType=DECIMAL},
      </if>
      <if test="ratiocharge != null">
        ratioCharge = #{ratiocharge,jdbcType=DECIMAL},
      </if>
      <if test="virrealcashamt != null">
        virRealCashAmt = #{virrealcashamt,jdbcType=DECIMAL},
      </if>
      <if test="virtotalcharge != null">
        virTotalCharge = #{virtotalcharge,jdbcType=DECIMAL},
      </if>
      <if test="cashstatus != null">
        cashStatus = #{cashstatus,jdbcType=VARCHAR},
      </if>
      <if test="cashstatusnow != null">
        cashStatusNow = #{cashstatusnow,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.chaozhanggui.dao.system.entity.TbPlussCash">
    update tb_pluss_cash
    set userId = #{userid,jdbcType=INTEGER},
      userName = #{username,jdbcType=VARCHAR},
      merchantCode = #{merchantcode,jdbcType=VARCHAR},
      merchantName = #{merchantname,jdbcType=VARCHAR},
      accountNo = #{accountno,jdbcType=VARCHAR},
      accountName = #{accountname,jdbcType=VARCHAR},
      cashAmt = #{cashamt,jdbcType=DECIMAL},
      status = #{status,jdbcType=INTEGER},
      reason = #{reason,jdbcType=VARCHAR},
      createDt = #{createdt,jdbcType=TIMESTAMP},
      updateDt = #{updatedt,jdbcType=TIMESTAMP},
      logo = #{logo,jdbcType=VARCHAR},
      cashNumber = #{cashnumber,jdbcType=VARCHAR},
      backNo = #{backno,jdbcType=VARCHAR},
      backDt = #{backdt,jdbcType=TIMESTAMP},
      updator = #{updator,jdbcType=VARCHAR},
      type = #{type,jdbcType=INTEGER},
      baseServiceCharge = #{baseservicecharge,jdbcType=DECIMAL},
      ratioCharge = #{ratiocharge,jdbcType=DECIMAL},
      cashStatus = #{cashstatus,jdbcType=VARCHAR},
      cashStatusNow = #{cashstatusnow,jdbcType=VARCHAR}
    where id = #{id,jdbcType=INTEGER}
  </update>

  <select id="selectByUserId" resultType="java.math.BigDecimal">
    select IFNULL(sum(p.price),0) from tb_pluss_merchant_profit p where p.type=5 and p.userId=#{userId}
    </select>

  <select id="selectCashFrozenAmountByUserId" resultType="java.math.BigDecimal">
    select  IFNULL(sum(c.cashAmt),0) from tb_pluss_cash c where c.userId=#{userId} and c.`status`=0;
  </select>

  <select id="selectCashAmt" resultType="java.math.BigDecimal">
    select  IFNULL(sum(c.cashAmt),0) from tb_pluss_cash c where c.userId=#{userId} and c.`status`=1
  </select>

  <select id="selectCashByUserId" resultMap="BaseResultMap">
    SELECT
    c.*,
    o.loginName
    FROM
    tb_pluss_cash c
    LEFT JOIN tb_pluss_user_info o ON c.userId = o.id
    WHERE
      c.userId = #{userId}
      <if test="status !=null and status !=''">
        and c.status=#{status}
      </if>
    ORDER BY
      c.id DESC
  </select>
</mapper>