AccountMapper.xml 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. ,total_in_amount = total_in_amount + CASE
  47. WHEN #{amount} > 0 THEN #{amount}
  48. ELSE 0
  49. END,
  50. total_out_amount = total_out_amount + CASE
  51. WHEN 0 > #{amount} THEN -#{amount}
  52. ELSE 0
  53. END
  54. where id = #{accountId}
  55. <if test="accountId != 5">
  56. and balance + #{amount} >= 0
  57. </if>
  58. and DATE_FORMAT( before_day_time, '%Y-%m-%d' ) != CURRENT_DATE
  59. </update>
  60. <update id="deal">
  61. UPDATE c_account
  62. SET balance = balance + #{amount},
  63. total_in_amount = total_in_amount + CASE
  64. WHEN #{amount} > 0 THEN #{amount}
  65. ELSE 0
  66. END,
  67. total_out_amount = total_out_amount + CASE
  68. WHEN 0 > #{amount} THEN -#{amount}
  69. ELSE 0
  70. END
  71. WHERE id = #{accountId}
  72. <choose>
  73. <when test="accountId != 5">
  74. AND balance + #{amount} >= 0
  75. </when>
  76. <otherwise>
  77. <!-- 账户ID为5时的特殊处理 -->
  78. AND 1=1
  79. </otherwise>
  80. </choose>
  81. </update>
  82. <update id="dealFreeze" >
  83. update c_account set freeze_amount = freeze_amount + #{amount} where id = #{accountId} and freeze_amount + #{amount} >= 0
  84. </update>
  85. </mapper>