jhprjv2/yanzhu-jh/src/main/resources/mapper/project/SurProjectCostOutputMapper.xml

146 lines
7.0 KiB
XML
Raw Normal View History

2023-08-27 13:50:15 +08:00
<?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.yanzhu.jh.project.mapper.SurProjectCostOutputMapper">
<resultMap type="SurProjectCostOutput" id="SurProjectCostOutputResult">
<result property="id" column="id" />
<result property="projectId" column="project_id" />
<result property="money" column="money" />
<result property="year" column="year" />
<result property="month" column="month" />
<result property="costType" column="cost_type" />
<result property="remark" column="remark" />
<result property="isDel" column="is_del" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
</resultMap>
<sql id="selectSurProjectCostOutputVo">
select id, project_id, money, year, month, cost_type, remark, is_del, create_by, create_time, update_by, update_time from sur_project_cost_output
</sql>
<select id="selectSurProjectCostOutputList" parameterType="SurProjectCostOutput" resultMap="SurProjectCostOutputResult">
<include refid="selectSurProjectCostOutputVo"/>
<where>
<if test="projectId != null "> and project_id = #{projectId}</if>
<if test="money != null "> and money = #{money}</if>
<if test="year != null "> and year = #{year}</if>
<if test="month != null "> and month = #{month}</if>
<if test="costType != null "> and cost_type = #{costType}</if>
<if test="isDel != null "> and is_del = #{isDel}</if>
</where>
</select>
<select id="selectSurProjectCostOutputById" parameterType="Long" resultMap="SurProjectCostOutputResult">
<include refid="selectSurProjectCostOutputVo"/>
where id = #{id}
</select>
<insert id="insertSurProjectCostOutput" parameterType="SurProjectCostOutput" useGeneratedKeys="true" keyProperty="id">
insert into sur_project_cost_output
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="projectId != null">project_id,</if>
<if test="money != null">money,</if>
<if test="year != null">year,</if>
<if test="month != null">month,</if>
<if test="costType != null">cost_type,</if>
<if test="remark != null">remark,</if>
<if test="isDel != null">is_del,</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>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="projectId != null">#{projectId},</if>
<if test="money != null">#{money},</if>
<if test="year != null">#{year},</if>
<if test="month != null">#{month},</if>
<if test="costType != null">#{costType},</if>
<if test="remark != null">#{remark},</if>
<if test="isDel != null">#{isDel},</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>
</trim>
</insert>
<update id="updateSurProjectCostOutput" parameterType="SurProjectCostOutput">
update sur_project_cost_output
<trim prefix="SET" suffixOverrides=",">
<if test="projectId != null">project_id = #{projectId},</if>
<if test="money != null">money = #{money},</if>
<if test="year != null">year = #{year},</if>
<if test="month != null">month = #{month},</if>
<if test="costType != null">cost_type = #{costType},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="isDel != null">is_del = #{isDel},</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>
</trim>
where id = #{id}
</update>
<delete id="deleteSurProjectCostOutputById" parameterType="Long">
delete from sur_project_cost_output where id = #{id}
</delete>
<delete id="deleteSurProjectCostOutputByIds" parameterType="String">
delete from sur_project_cost_output where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
2023-08-31 23:57:18 +08:00
<select id="selectYearAndMonth" parameterType="SurProjectCostOutput" resultMap="SurProjectCostOutputResult">
SELECT *
FROM sur_project_cost_output
WHERE project_id = #{projectId}
and (
(YEAR=#{year} AND cost_type=2) OR cost_type NOT IN (2, 9)
OR (cost_type = 9 AND YEAR = #{year} AND MONTH &lt;= #{month})
OR (cost_type = 9 AND YEAR &lt; #{year})
)
</select>
2023-09-04 01:00:54 +08:00
2023-12-13 22:14:10 +08:00
<select id="sumByDeptId" parameterType="SurProjectCostOutput" resultMap="SurProjectCostOutputResult">
2024-04-06 01:31:05 +08:00
SELECT 10 cost_type , SUM(spco.money) money FROM sur_project_cost_output spco
left join sur_project sp on sp.id = spco.project_id
WHERE (spco.cost_type=2 AND spco.YEAR &lt;=#{year} )
<if test="id!=null and id>0"> and sp.deptId = #{id}</if>
<if test="proType != null and proType != ''"> and sp.projectType = #{proType}</if>
2023-09-04 01:00:54 +08:00
<if test="projectId!=null and projectId>0">
2024-04-06 01:31:05 +08:00
and spco.project_id=#{projectId}
2023-09-04 01:00:54 +08:00
</if>
UNION
2024-04-06 01:31:05 +08:00
SELECT 2 cost_type , SUM(spco.money) money FROM sur_project_cost_output spco
left join sur_project sp on sp.id = spco.project_id
WHERE (spco.cost_type=9 AND spco.YEAR=#{year} AND spco.MONTH &lt;= #{month} )
<if test="id!=null and id>0"> and sp.deptId = #{id}</if>
<if test="proType != null and proType != ''"> and sp.projectType = #{proType}</if>
2023-09-04 01:00:54 +08:00
<if test="projectId!=null and projectId>0">
2024-04-06 01:31:05 +08:00
and spco.project_id=#{projectId}
2023-09-04 01:00:54 +08:00
</if>
UNION
2024-04-06 01:31:05 +08:00
SELECT 9 cost_type , SUM(spco.money) money FROM sur_project_cost_output spco
left join sur_project sp on sp.id = spco.project_id
WHERE (spco.cost_type=9 AND spco.YEAR=#{year} AND spco.MONTH= #{month} )
<if test="id!=null and id>0"> and sp.deptId = #{id}</if>
<if test="proType != null and proType != ''"> and sp.projectType = #{proType}</if>
2023-09-04 01:00:54 +08:00
<if test="projectId!=null and projectId>0">
2024-04-06 01:31:05 +08:00
and spco.project_id=#{projectId}
2023-09-04 01:00:54 +08:00
</if>
</select>
2023-08-27 13:50:15 +08:00
</mapper>