feat: 每日负债统计功能新增。
This commit is contained in:
@@ -0,0 +1,149 @@
|
||||
<?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.intc.invest.mapper.DailyLiabilitiesMapper">
|
||||
|
||||
<resultMap type="DailyLiabilitiesVo" id="DailyLiabilitiesResult">
|
||||
<result property="id" column="id" />
|
||||
<result property="name" column="name" />
|
||||
<result property="totalBalance" column="total_balance" />
|
||||
<result property="creditBalance" column="credit_balance" />
|
||||
<result property="investBalance" column="invest_balance" />
|
||||
<result property="debitBalance" column="debit_balance" />
|
||||
<result property="lendingBalance" column="lending_balance" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateBy" column="update_by" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
<result property="delFlag" column="del_flag" />
|
||||
<result property="remark" column="remark" />
|
||||
<result property="recordDate" column="record_date" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectDailyLiabilitiesVo">
|
||||
select a.id, a.name, a.total_balance, a.credit_balance, a.invest_balance, a.debit_balance, a.lending_balance, a.create_by, a.create_time, a.update_by, a.update_time, a.del_flag, a.remark, a.record_date from daily_liabilities a
|
||||
</sql>
|
||||
|
||||
<select id="selectDailyLiabilitiesList" parameterType="DailyLiabilitiesDto" resultMap="DailyLiabilitiesResult">
|
||||
<include refid="selectDailyLiabilitiesVo"/>
|
||||
<where>
|
||||
a.del_flag='0'
|
||||
<if test="name != null and name != ''"> and a.name like '%'|| #{name}||'%'</if>
|
||||
<if test="recordDate != null "> and a.record_date = #{recordDate}</if>
|
||||
<if test="endTime!=null and endTime !=''">
|
||||
and #{endTime}>=to_char(a.record_date, 'yyyy-MM-dd')
|
||||
</if>
|
||||
<if test="startTime!=null and startTime !=''">
|
||||
and to_char(a.record_date, 'yyyy-MM-dd')>=#{startTime}
|
||||
</if>
|
||||
</where>
|
||||
<!-- 数据范围过滤 -->
|
||||
${params.dataScope}
|
||||
order by a.create_time desc
|
||||
</select>
|
||||
|
||||
<select id="selectDailyLiabilitiesById" parameterType="Long" resultMap="DailyLiabilitiesResult">
|
||||
<include refid="selectDailyLiabilitiesVo"/>
|
||||
where a.id = #{id}
|
||||
</select>
|
||||
|
||||
<insert id="insertDailyLiabilities" parameterType="DailyLiabilities">
|
||||
insert into daily_liabilities
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">id,</if>
|
||||
<if test="name != null">name,</if>
|
||||
<if test="totalBalance != null">total_balance,</if>
|
||||
<if test="creditBalance != null">credit_balance,</if>
|
||||
<if test="investBalance != null">invest_balance,</if>
|
||||
<if test="debitBalance != null">debit_balance,</if>
|
||||
<if test="lendingBalance != null">lending_balance,</if>
|
||||
<if test="createBy != null">create_by,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
<if test="updateBy != null">update_by,</if>
|
||||
<if test="updateTime != null">update_time,</if>
|
||||
<if test="delFlag != null">del_flag,</if>
|
||||
<if test="remark != null">remark,</if>
|
||||
<if test="recordDate != null">record_date,</if>
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="id != null">#{id},</if>
|
||||
<if test="name != null">#{name},</if>
|
||||
<if test="totalBalance != null">#{totalBalance},</if>
|
||||
<if test="creditBalance != null">#{creditBalance},</if>
|
||||
<if test="investBalance != null">#{investBalance},</if>
|
||||
<if test="debitBalance != null">#{debitBalance},</if>
|
||||
<if test="lendingBalance != null">#{lendingBalance},</if>
|
||||
<if test="createBy != null">#{createBy},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
<if test="updateBy != null">#{updateBy},</if>
|
||||
<if test="updateTime != null">#{updateTime},</if>
|
||||
<if test="delFlag != null">#{delFlag},</if>
|
||||
<if test="remark != null">#{remark},</if>
|
||||
<if test="recordDate != null">#{recordDate},</if>
|
||||
</trim>
|
||||
</insert>
|
||||
|
||||
<update id="updateDailyLiabilities" parameterType="DailyLiabilities">
|
||||
update daily_liabilities
|
||||
<trim prefix="SET" suffixOverrides=",">
|
||||
<if test="name != null">name = #{name},</if>
|
||||
<if test="totalBalance != null">total_balance = #{totalBalance},</if>
|
||||
<if test="creditBalance != null">credit_balance = #{creditBalance},</if>
|
||||
<if test="investBalance != null">invest_balance = #{investBalance},</if>
|
||||
<if test="debitBalance != null">debit_balance = #{debitBalance},</if>
|
||||
<if test="lendingBalance != null">lending_balance = #{lendingBalance},</if>
|
||||
<if test="createBy != null">create_by = #{createBy},</if>
|
||||
<if test="createTime != null">create_time = #{createTime},</if>
|
||||
<if test="updateBy != null">update_by = #{updateBy},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
<if test="delFlag != null">del_flag = #{delFlag},</if>
|
||||
<if test="remark != null">remark = #{remark},</if>
|
||||
<if test="recordDate != null">record_date = #{recordDate},</if>
|
||||
</trim>
|
||||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="deleteDailyLiabilitiesById" parameterType="Long">
|
||||
delete from daily_liabilities where id = #{id}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteDailyLiabilitiesByIds" parameterType="String">
|
||||
delete from daily_liabilities where id in
|
||||
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</delete>
|
||||
<update id="removeDailyLiabilitiesById" parameterType="Long">
|
||||
update daily_liabilities set del_flag='1' where id = #{id}
|
||||
</update>
|
||||
|
||||
<update id="removeDailyLiabilitiesByIds" parameterType="String">
|
||||
update daily_liabilities set del_flag='1' where id in
|
||||
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</update>
|
||||
<select id="selectDailyLiabilities" resultMap="DailyLiabilitiesResult">
|
||||
SELECT * FROM crosstab(
|
||||
-- 源数据子查询:按create_by分组,type作为列标识,balance作为值
|
||||
'SELECT
|
||||
create_by,
|
||||
type::text, -- 转换为文本类型,确保与列定义匹配
|
||||
sum(balance)::numeric -- 确保数值类型一致
|
||||
FROM accounts
|
||||
WHERE balance != 0
|
||||
GROUP BY create_by, type
|
||||
ORDER BY 1, 2', -- 必须按create_by和type排序
|
||||
|
||||
-- 指定要转为列的type值(你的场景中是1、23、5)
|
||||
'SELECT unnest(ARRAY[''1'', ''2'', ''3'', ''5''])' -- 显式列出所有type值
|
||||
) AS pivot_result (
|
||||
create_by TEXT, -- 行标识:创建人
|
||||
"debit_balance" NUMERIC, -- type=1对应的余额总和
|
||||
"credit_balance" NUMERIC, -- type=2对应的余额总和
|
||||
"lending_balance" NUMERIC, -- type=3对应的余额总和
|
||||
"invest_balance" NUMERIC -- type=5对应的余额总和
|
||||
);
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user