123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580 |
- <?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.liang.dao.PrjAnnualbudgetDao">
- <resultMap type="com.liang.entity.PrjAnnualbudget" id="PrjAnnualbudgetMap">
- <result property="id" column="ID" jdbcType="INTEGER"/>
- <result property="rws" column="RWS" jdbcType="INTEGER"/>
- <result property="nf" column="NF" jdbcType="VARCHAR"/>
- <result property="sqr" column="SQR" jdbcType="INTEGER"/>
- <result property="sqsj" column="SQSJ" jdbcType="TIMESTAMP"/>
- <result property="spzt" column="SPZT" jdbcType="VARCHAR"/>
- <result property="kyfyxx" column="KYFYXX" jdbcType="VARCHAR"/>
- <result property="sm" column="SM" jdbcType="VARCHAR"/>
- <result property="rwsmc" column="RWSMC" jdbcType="VARCHAR"/>
- <result property="mc" column="MC" jdbcType="VARCHAR"/>
- <result property="xmmc" column="XMMC" jdbcType="VARCHAR"/>
- <result property="erpbh" column="ERPBH" jdbcType="VARCHAR"/>
- <result property="xmlx" column="XMLX" jdbcType="VARCHAR"/>
- <result property="xmfzr" column="XMFZR" jdbcType="INTEGER"/>
- <result property="ssbm" column="SSBM" jdbcType="INTEGER"/>
- <result property="xmzxq" column="XMZXQ" jdbcType="VARCHAR"/>
- </resultMap>
- <!--查询单个-->
- <select id="queryById" resultMap="PrjAnnualbudgetMap">
- SELECT DISTINCT a.*,
- t.XMLXMC,
- r.XM AS XMFZRXM,
- d.dept_name AS SSBMMC,
- u.name AS SQRXM,
- bd.XMZYS,
- p.DKYFZR,
- bd.YSJE,
- (
- SELECT STUFF(
- (
- SELECT ',' + XM
- FROM (
- SELECT xm
- FROM base_Person
- WHERE id IN (
- SELECT dkyfzrid
- FROM (
- SELECT DISTINCT zwmc,
- SUBSTRING(dkyfzr, number,
- CHARINDEX(',', dkyfzr + ',', number) -
- number) AS dkyfzrid
- FROM prj_Project WITH (nolock),
- master..spt_values
- WITH (nolock)
- WHERE
- number >= 1
- AND len(DKYFZR)
- > number
- AND SUBSTRING (',' + DKYFZR
- , number
- , 1) = ','
- AND ID = p.ID
- ) t
- )
- ) B FOR xml path ('') ),
- 1,
- 1,
- ''
- )
- ) AS DKYFZRXM
- FROM prj_AnnualBudget a
- LEFT JOIN base_ProjectType t ON t.XMLX = a.XMLX
- LEFT JOIN base_Person r ON r.ID = a.XMFZR
- LEFT JOIN sys_dept_info d ON d.dept_id = a.SSBM
- LEFT JOIN sys_user_info u ON u.user_id = a.SQR
- LEFT JOIN prj_Project p ON p.ID = a.RWS
- LEFT JOIN prj_AnnualBudgetDetail bd ON bd.NYS = a.ID AND bd.FJ = ''
- -- LEFT JOIN sta_BudgetApproval b ON b.erpbh = a.erpbh -- 添加 sta_BudgetApproval 表的左关联条件
- WHERE a.ID = #{id}
- -- AND a.nf = b.nf; -- 添加 where 条件,确保 a.nf 和 b.nf 匹配
- </select>
- <select id="getAnnualBudget" resultMap="PrjAnnualbudgetMap">
- select *
- from prj_AnnualBudget
- <where>
- <if test="id != null">
- and ID = #{id}
- </if>
- <if test="rws != null">
- and RWS = #{rws}
- </if>
- <if test="nf != null and nf != ''">
- and NF = #{nf}
- </if>
- </where>
- </select>
- <!--根据rwsID查询记录-->
- <select id="queryByRws" resultMap="PrjAnnualbudgetMap">
- select TOP 1 a.*, u.name as SQRXM
- from prj_AnnualBudget a
- left join
- sys_user_info u on u.user_id = a.SQR
- INNER JOIN sta_BudgetApproval s ON a.RWS = s.XMID
- where RWS = #{rws}
- AND a.NF = s.NF
- </select>
- <!--查询指定行数据-->
- <select id="queryAllByLimit" resultMap="PrjAnnualbudgetMap">
- select
- ID, RWS, NF, SQR, SQSJ, SPZT, KYFYXX, SM, RWSMC, MC, XMMC, ERPBH, XMLX, XMFZR, SSBM, XMZXQ
- from prj_AnnualBudget
- <where>
- <if test="id != null">
- and ID = #{id}
- </if>
- <if test="rws != null">
- and RWS = #{rws}
- </if>
- <if test="nf != null and nf != ''">
- and NF = #{nf}
- </if>
- <if test="sqr != null">
- and SQR = #{sqr}
- </if>
- <if test="sqsj != null">
- and SQSJ = #{sqsj}
- </if>
- <if test="spzt != null and spzt != ''">
- and SPZT = #{spzt}
- </if>
- <if test="kyfyxx != null and kyfyxx != ''">
- and KYFYXX = #{kyfyxx}
- </if>
- <if test="sm != null and sm != ''">
- and SM = #{sm}
- </if>
- <if test="rwsmc != null and rwsmc != ''">
- and RWSMC = #{rwsmc}
- </if>
- <if test="mc != null and mc != ''">
- and MC = #{mc}
- </if>
- <if test="xmmc != null and xmmc != ''">
- and XMMC = #{xmmc}
- </if>
- <if test="erpbh != null and erpbh != ''">
- and ERPBH = #{erpbh}
- </if>
- <if test="xmlx != null and xmlx != ''">
- and XMLX = #{xmlx}
- </if>
- <if test="xmfzr != null">
- and XMFZR = #{xmfzr}
- </if>
- <if test="ssbm != null">
- and SSBM = #{ssbm}
- </if>
- <if test="xmzxq != null and xmzxq != ''">
- and XMZXQ = #{xmzxq}
- </if>
- </where>
- limit #{pageable.offset}, #{pageable.pageSize}
- </select>
- <!--统计总行数-->
- <select id="count" resultType="java.lang.Long">
- select count(1)
- from prj_AnnualBudget
- <where>
- <if test="id != null">
- and ID = #{id}
- </if>
- <if test="rws != null">
- and RWS = #{rws}
- </if>
- <if test="nf != null and nf != ''">
- and NF = #{nf}
- </if>
- <if test="sqr != null">
- and SQR = #{sqr}
- </if>
- <if test="sqsj != null">
- and SQSJ = #{sqsj}
- </if>
- <if test="spzt != null and spzt != ''">
- and SPZT = #{spzt}
- </if>
- <if test="kyfyxx != null and kyfyxx != ''">
- and KYFYXX = #{kyfyxx}
- </if>
- <if test="sm != null and sm != ''">
- and SM = #{sm}
- </if>
- <if test="rwsmc != null and rwsmc != ''">
- and RWSMC = #{rwsmc}
- </if>
- <if test="mc != null and mc != ''">
- and MC = #{mc}
- </if>
- <if test="xmmc != null and xmmc != ''">
- and XMMC = #{xmmc}
- </if>
- <if test="erpbh != null and erpbh != ''">
- and ERPBH = #{erpbh}
- </if>
- <if test="xmlx != null and xmlx != ''">
- and XMLX = #{xmlx}
- </if>
- <if test="xmfzr != null">
- and XMFZR = #{xmfzr}
- </if>
- <if test="ssbm != null">
- and SSBM = #{ssbm}
- </if>
- <if test="xmzxq != null and xmzxq != ''">
- and XMZXQ = #{xmzxq}
- </if>
- </where>
- </select>
- <!--新增所有列-->
- <insert id="insert" keyProperty="id" useGeneratedKeys="true">
- if
- not exists (select ID from prj_AnnualBudget where RWS =
- #{rws}
- and
- NF
- =
- #{nf}
- )
- insert
- into
- prj_AnnualBudget
- (
- RWS,
- NF,
- SQR,
- SQSJ,
- SPZT,
- KYFYXX,
- SM,
- RWSMC,
- MC,
- XMMC,
- ERPBH,
- XMLX,
- XMFZR,
- SSBM,
- XMZXQ
- )
- values
- (
- #{rws},
- #{nf},
- #{sqr},
- #{sqsj},
- #{spzt},
- #{kyfyxx},
- #{sm},
- #{rwsmc},
- #{mc},
- #{xmmc},
- #{erpbh},
- #{xmlx},
- #{xmfzr},
- #{ssbm},
- #{xmzxq}
- )
- </insert>
- <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
- insert into prj_AnnualBudget(RWS, NF, SQR, SQSJ, SPZT, KYFYXX, SM, RWSMC, MC, XMMC, ERPBH, XMLX, XMFZR, SSBM,
- XMZXQ)
- values
- <foreach collection="entities" item="entity" separator=",">
- (#{entity.rws}, #{entity.nf}, #{entity.sqr}, #{entity.sqsj}, #{entity.spzt}, #{entity.kyfyxx}, #{entity.sm},
- #{entity.rwsmc}, #{entity.mc}, #{entity.xmmc}, #{entity.erpbh}, #{entity.xmlx}, #{entity.xmfzr},
- #{entity.ssbm}, #{entity.xmzxq})
- </foreach>
- </insert>
- <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
- insert into prj_AnnualBudget(RWS, NF, SQR, SQSJ, SPZT, KYFYXX, SM, RWSMC, MC, XMMC, ERPBH, XMLX, XMFZR, SSBM,
- XMZXQ)
- values
- <foreach collection="entities" item="entity" separator=",">
- (#{entity.rws}, #{entity.nf}, #{entity.sqr}, #{entity.sqsj}, #{entity.spzt}, #{entity.kyfyxx}, #{entity.sm},
- #{entity.rwsmc}, #{entity.mc}, #{entity.xmmc}, #{entity.erpbh}, #{entity.xmlx}, #{entity.xmfzr},
- #{entity.ssbm}, #{entity.xmzxq})
- </foreach>
- on duplicate key update
- RWS = values(RWS),
- NF = values(NF),
- SQR = values(SQR),
- SQSJ = values(SQSJ),
- SPZT = values(SPZT),
- KYFYXX = values(KYFYXX),
- SM = values(SM),
- RWSMC = values(RWSMC),
- MC = values(MC),
- XMMC = values(XMMC),
- ERPBH = values(ERPBH),
- XMLX = values(XMLX),
- XMFZR = values(XMFZR),
- SSBM = values(SSBM),
- XMZXQ = values(XMZXQ)
- </insert>
- <!--通过主键修改数据-->
- <update id="update">
- if
- not exists (select ID from prj_AnnualBudget where ID !=
- #{id}
- and
- RWS
- =
- #{rws}
- and
- NF
- =
- #{nf}
- )
- update prj_AnnualBudget
- set NF = #{nf},
- SQSJ = #{sqsj},
- SM = #{sm},
- MC = #{mc},
- XMZXQ = #{xmzxq}
- where ID = #{id}
- </update>
- <!--通过主键删除-->
- <delete id="deleteById">
- delete
- from prj_AnnualBudget
- where ID = #{id}
- </delete>
- <!--获取年度预算列表-->
- <select id="getNdysList" resultMap="PrjAnnualbudgetMap" parameterType="map">
- select a.*, t.XMLXMC, r.XM as XMFZRXM, d.dept_name as SSBMMC, u.name as SQRXM, bd.XMZYS
- from prj_AnnualBudget a
- left join base_ProjectType t on t.XMLX = a.XMLX
- left join base_Person r on r.ID = a.XMFZR
- left join sys_user_info u on u.user_id = a.SQR
- left join sys_dept_info d on d.dept_id = a.SSBM
- left join prj_AnnualBudgetDetail bd on bd.NYS = a.ID and bd.FJ = ''
- where 1 = 1
- <if test="userId != null and userId != ''">
- and (a.SQR = #{userId} or #{userId} in (select SHR from prj_ApproveRecord where XMID = a.ID))
- </if>
- <if test="xmmc != null and xmmc != ''">
- and a.XMMC like '%'+#{xmmc}+'%'
- </if>
- <if test="erpbh != null and erpbh != ''">
- and a.ERPBH like '%'+#{erpbh}+'%'
- </if>
- <if test="xmlx != null and xmlx != ''">
- and a.XMLX = #{xmlx}
- </if>
- <if test="ssbmmc != null and ssbmmc != ''">
- and d.dept_name like '%'+#{ssbmmc}+'%'
- </if>
- <if test="spzt != null and spzt != ''">
- and a.SPZT = #{spzt}
- </if>
- <if test="rwsmc != null and rwsmc != ''">
- and a.RWSMC like '%'+#{rwsmc}+'%'
- </if>
- <if test="nf != null and nf != ''">
- and a.NF = #{nf}
- </if>
- <choose>
- <when test="sortName != null and sortName != '' and sortOrder != null and sortOrder != ''">
- order by ${sortName} ${sortOrder}
- </when>
- </choose>
- ORDER BY
- CASE
- WHEN a.SPZT = '部门主任审批' THEN 0
- WHEN a.SPZT = '科技项目管理专责审批' THEN 1
- WHEN a.SPZT = '科技部部门主任审批' THEN 2
- WHEN a.SPZT = '主管院领导审批' THEN 3
- WHEN a.SPZT = '院长审批' THEN 4
- WHEN a.SPZT = '科技项目管理专责确认' THEN 5
- WHEN a.SPZT = '未提交' THEN 996
- WHEN a.SPZT = '未提交(返回)' THEN 997
- WHEN a.SPZT = '审批结束' THEN 998
- WHEN a.SPZT = '作废' THEN 999
- END
- ASC
- </select>
- <!--获取年份-->
- <select id="getYearList" resultMap="PrjAnnualbudgetMap">
- select distinct NF
- from prj_AnnualBudget
- where NF is not NULL
- </select>
- <!--批量删除年度预算-->
- <delete id="batchDelete" parameterType="java.util.ArrayList">
- delete from prj_AnnualBudget
- where ID in
- <foreach item="item" index="index" collection="idList" open="(" separator="," close=")">
- #{item}
- </foreach>
- </delete>
- <!--撤销审核状态任务书-->
- <update id="tjrevokeApprove">
- update prj_AnnualBudget
- set SPZT = '未提交'
- where ID = #{id}
- </update>
- <!--通过主键修改审批状态-->
- <update id="updateSpzt">
- update prj_AnnualBudget
- set SPZT = #{spzt}
- where ID = #{id}
- </update>
- <update id="updateXTJSYZX">
- update A
- set A.XTJSYZX = B.xtjsyzx from prj_AnnualBudgetDetail A
- inner join (SELECT
- fymc, sum(ysje) xtjsyzx
- from prj_AnnualBudgetDetail
- where nys in (SELECT ID from prj_AnnualBudget where RWS = #{rws})
- group by fymc) B
- on A.FYMC = B.fymc
- where
- NYS = ( SELECT top 1 ID from prj_AnnualBudget where RWS = #{rws} order by nf desc)
- </update>
- <update id="updateSJYZX">
- update A
- set A.sjyzx = B.BZJE from prj_AnnualBudgetDetail A
- inner join (SELECT convert(decimal(18,2),(sum(BZJE)/10000)) BZJE ,pa.fymc
- from(SELECT id ,fylb
- from sta_BudgetApproval
- where nys in (
- select id
- from prj_AnnualBudget
- where rws = #{rws})) sb
- left join sta_Reimbursement sa on sa.fysq = sb.id
- LEFT join prj_AnnualBudgetDetail pa on pa.id = sb.fylb
- group by pa.fymc ) B
- on A.FYMC = B.fymc
- where
- NYS = (
- SELECT top 1 ID from
- prj_AnnualBudget
- where RWS = #{rws} order by nf desc )
- </update>
- <update id="updateSJYZXByBZID">
- update A
- set A.sjyzx = (B.BZJE + isnull(A.sjyzx, 0) + isnull(#{nysSum}, 0)) from prj_AnnualBudgetDetail A
- inner join (
- select pa.fymc , sr.bzje, pa.id from sta_Reimbursement sr
- left join sta_BudgetApproval sb on sb.id = sr.FYSQ
- left join prj_AnnualBudgetDetail pa on pa.id = sb.fylb
- where sr.id = #{bzId}
- ) B
- on A.FYMC = B.fymc
- where
- a.id=b.id
- </update>
- <update id="updateSJYZXSum">
- update A
- set A.sjyzx = B.BZJE from prj_AnnualBudgetDetail A
- inner join (SELECT convert(decimal(18,2),(sum(BZJE)/10000)) BZJE ,pa.fymc
- from(SELECT id ,fylb
- from sta_BudgetApproval
- where nys in (
- select id
- from prj_AnnualBudget
- where rws = #{rws})) sb
- left join sta_Reimbursement sa on sa.fysq = sb.id
- LEFT join prj_AnnualBudgetDetail pa on pa.id = sb.fylb
- group by pa.fymc ) B
- on A.FYMC = B.fymc
- where
- NYS = (
- SELECT top 1 ID from
- prj_AnnualBudget
- where RWS = #{rws} order by nf desc )
- </update>
- <update id="updateXTJSYZXByNysId">
- update A
- set A.XTJSYZX = B.xtjsyzx from prj_AnnualBudgetDetail A
- inner join (SELECT
- fymc, sum(ysje) xtjsyzx
- from prj_AnnualBudgetDetail
- where nys in (SELECT ID from prj_AnnualBudget where RWS = #{rwsId} and nf < #{nf} )
- group by fymc) B
- on A.FYMC = B.fymc
- where
- NYS = #{nysId}
- </update>
- <update id="updateSJYZXByNysId">
- update A
- set A.sjyzx = B.BZJE from prj_AnnualBudgetDetail A
- inner join (SELECT convert(decimal(18,2),(sum(BZJE)/10000)) BZJE ,pa.fymc
- from(SELECT id ,fylb
- from sta_BudgetApproval
- where nys in (
- select id
- from prj_AnnualBudget
- where rws = #{rwsId} and nf < #{nf} )) sb
- left join sta_Reimbursement sa on sa.fysq = sb.id
- LEFT join prj_AnnualBudgetDetail pa on pa.id = sb.fylb
- group by pa.fymc ) B
- on A.FYMC = B.fymc
- where
- NYS = #{nysId}
- </update>
- <update id="updateSJYZXSumByNysId">
- update A
- set A.sjyzx = B.BZJE from prj_AnnualBudgetDetail A
- inner join (SELECT sum(BZJE) BZJE ,pa.fymc
- from(SELECT id ,fylb
- from sta_BudgetApproval
- where nys in (
- select id
- from prj_AnnualBudget
- where rws = #{rwsId} and nf < #{nf} )) sb
- left join sta_Reimbursement sa on sa.fysq = sb.id
- LEFT join prj_AnnualBudgetDetail pa on pa.id = sb.fylb
- group by pa.fymc ) B
- on A.FYMC = B.fymc
- where
- NYS = #{nysId}
- </update>
- <!--已申请费用的预算-->
- <select id="getFysqBudgetList">
- select b.*
- from sta_BudgetApproval b
- left join prj_AnnualBudget a on a.ID = b.NYS
- left join prj_AnnualBudgetDetail d on d.NYS = a.ID
- where 1 = 1
- </select>
- <select id="listByRws" resultType="com.liang.entity.PrjAnnualbudget">
- select *
- from prj_AnnualBudget
- where rws = #{rws}
- order by nf asc
- </select>
- <select id="getNYSSum" resultType="java.math.BigDecimal">
- SELECT sum(pan.sjyzx) sjyzx
- FROM (
- select sb.nys,
- pab.fymc
- from sta_Reimbursement sr
- left join sta_BudgetApproval sb on sb.id = sr.FYSQ
- left join prj_AnnualBudgetDetail pab on pab.id = sb.fylb
- where sr.id = #{id}
- ) b
- left join prj_AnnualBudgetDetail pan on b.fymc = pan.fymc
- where pan.nys in (
- SELECT id
- from prj_AnnualBudget pann
- where rws = #{rwsId}
- AND pann.id < (select sb.nys
- from sta_Reimbursement sr
- left join sta_BudgetApproval sb on sb.id = sr.FYSQ
- where sr.id = #{id})
- )
- </select>
- <select id="queryByRws1" resultType="com.liang.entity.PrjAnnualbudget">
- select TOP 1 a.*, u.name as SQRXM
- from prj_AnnualBudget a
- left join
- sys_user_info u on u.user_id = a.SQR
- INNER JOIN sta_BudgetApproval s ON a.RWS = s.XMID
- where RWS = #{rws}
- AND a.NF = #{nf}
- </select>
- </mapper>
|