AccountMapper.xml 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.txz.cif.dao.AccountMapper">
  4. <resultMap id="BaseResultMap" type="com.txz.cif.model.Account">
  5. <!--
  6. WARNING - @mbg.generated
  7. -->
  8. <id column="id" jdbcType="BIGINT" property="id" />
  9. <result column="remark" jdbcType="VARCHAR" property="remark" />
  10. <result column="aliases" jdbcType="VARCHAR" property="aliases" />
  11. <result column="subject_type" jdbcType="INTEGER" property="subjectType" />
  12. <result column="biz_type" jdbcType="INTEGER" property="bizType" />
  13. <result column="user_id" jdbcType="BIGINT" property="userId" />
  14. <result column="name" jdbcType="VARCHAR" property="name" />
  15. <result column="direction" jdbcType="VARCHAR" property="direction" />
  16. <result column="type" jdbcType="INTEGER" property="type" />
  17. <result column="balance" jdbcType="DECIMAL" property="balance" />
  18. <result column="freeze_amount" jdbcType="DECIMAL" property="freezeAmount" />
  19. <result column="before_day_balance" jdbcType="DECIMAL" property="beforeDayBalance" />
  20. <result column="before_day_init_balance" jdbcType="DECIMAL" property="beforeDayInitBalance" />
  21. <result column="total_in_amount" jdbcType="DECIMAL" property="totalInamount" />
  22. <result column="total_out_amount" jdbcType="DECIMAL" property="totalOutAmount" />
  23. <result column="before_day_time" jdbcType="TIMESTAMP" property="beforeDayTime" />
  24. <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
  25. <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
  26. <result column="version" jdbcType="VARCHAR" property="version" />
  27. </resultMap>
  28. <select id="sumTodayInit" resultType="java.math.BigDecimal" >
  29. select sum(before_day_init_balance) from c_account where DATE(before_day_time) = CURDATE() and aliases like #{aliases} ;
  30. </select>
  31. <select id="sumBeforInit" resultType="java.math.BigDecimal" >
  32. select sum(before_day_balance) from c_account where DATE(before_day_time) != CURDATE() and aliases like #{aliases};
  33. </select>
  34. <select id="sumTodayEnd" resultType="java.math.BigDecimal" >
  35. select sum(before_day_balance) from c_account where DATE(before_day_time) = CURDATE() and aliases like #{aliases};
  36. </select>
  37. <select id="sumBeforEnd" resultType="java.math.BigDecimal" >
  38. select sum(balance) from c_account where DATE(before_day_time) != CURDATE() and aliases like #{aliases};
  39. </select>
  40. <update id="dealWithDayCut" >
  41. update c_account
  42. set balance = balance + #{amount}
  43. ,before_day_time = CURRENT_DATE
  44. ,before_day_init_balance = before_day_balance
  45. ,before_day_balance = balance
  46. where id = #{accountId}
  47. <if test="accountId != 5">
  48. and balance + #{amount} >= 0
  49. </if>
  50. and DATE_FORMAT( before_day_time, '%Y-%m-%d' ) != CURRENT_DATE
  51. </update>
  52. <update id="deal">
  53. UPDATE c_account
  54. SET balance = balance + #{amount},
  55. total_in_amount = total_in_amount + CASE
  56. WHEN #{amount} > 0 THEN #{amount}
  57. ELSE 0
  58. END,
  59. total_out_amount = total_out_amount + CASE
  60. WHEN 0 > #{amount} THEN -#{amount}
  61. ELSE 0
  62. END
  63. WHERE id = #{accountId}
  64. <choose>
  65. <when test="accountId != 5">
  66. AND balance + #{amount} >= 0
  67. </when>
  68. <otherwise>
  69. <!-- 账户ID为5时的特殊处理 -->
  70. AND 1=1
  71. </otherwise>
  72. </choose>
  73. </update>
  74. <update id="dealFreeze" >
  75. update c_account set freeze_amount = freeze_amount + #{amount} where id = #{accountId} and freeze_amount + #{amount} >= 0
  76. </update>
  77. </mapper>