PurchaseMapper.xml 14 KB
<?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.chinagas.modules.zjwjsb.mapper.PurchaseMapper">
    <resultMap id="purchaseResult" type="Purchase">
        <id property="bizId" column="biz_id"/>
        <result property="headId"  column="head_id"/>
        <result property="id"  column="id"/>
        <result property="payNo"  column="pay_no"/>
        <result property="title"  column="title"/>
        <result property="classFullName"  column="class_full_name"/>
        <result property="chargeDeptName"  column="charge_dept_name"/>
        <result property="apply"  column="apply"/>
        <result property="approval" column="approval"/>
        <result property="hasPay" column="has_pay"/>
        <result property="waitForPay"  column="wait_for_pay"/>
        <result property="status"  column="status"/>
        <result property="statusName" column="status_name"/>
        <result property="itemClass" column="item_class"/>
        <result property="itemClassName" column="item_class_name" />
        <result property="deptId" column="dept_id"/>
        <result property="deptName" column="dept_name"/>
        <result property="areaName" column="area_name"/>
        <result property="applyDate" column="apply_date"/>
        <result property="applyBy" column="apply_by"/>
        <result property="approvalDate" column="approval_date"/>
        <result property="isFromOld" column="is_from_old"/>
        <result property="explain" column="explain"/>
        <result property="detail" column="detail"/>
        <result property="remark" column="remark"/>
        <collection property="fundMainList" column="biz_id"   javaType="java.util.List"   ofType="FundMain" select="selectFundMain" />
        <collection property="fundDetailList" column="biz_id"   javaType="java.util.List"   ofType="FundDetail" select="selectFundDetail" />
        <collection  property="attachmentList" column="biz_id"   javaType="java.util.List"   ofType="Attachment" select="selectAttachmentByBizId" />
    </resultMap>

    <resultMap id="fundMainResult" type="FundMain">
        <id property="mainId" column="main_id"/>
        <id property="headId" column="head_id"/>
        <id property="title" column="title"/>
        <id property="status" column="status"/>
        <id property="statusName" column="status_name"/>
        <id property="bizId" column="biz_id"/>
        <id property="paySum" column="pay_sum"/>
        <id property="deptId" column="dept_id"/>
        <id property="deptName" column="dept_name"/>
        <id property="applyDate" column="apply_date"/>
        <id property="applyBy" column="apply_by"/>
        <id property="approvalDate" column="approval_date"/>
        <id property="remark" column="remark"/>
    </resultMap>

    <resultMap id="fundDetailResult" type="FundDetail">
        <id property="id" column="id"/>
        <id property="mainId" column="main_id"/>
        <id property="bizId" column="biz_id"/>
        <id property="payNo" column="pay_no"/>
        <id property="title" column="title"/>
        <id property="approval" column="approval"/>
        <id property="hasPay" column="has_pay"/>
        <id property="waitForPay" column="wait_for_pay"/>
        <id property="approvalForPay" column="approval_for_pay"/>
        <id property="itemClass" column="item_class"/>
        <id property="itemClassName" column="item_class_name"/>
        <id property="applyDate" column="apply_date"/>
        <id property="delFlag" column="del_flag"/>
        <id property="status" column="status"/>
        <id property="statusName" column="status_name"/>
        <result property="createTime" column="create_time"/>
        <result property="createBy" column="create_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="updateBy" column="update_by"/>
    </resultMap>

    <sql id="selectPurchaseVo" >
        select
            p.biz_id,
            p.head_id,
            p.id,
            p.pay_no,
            p.title,
            p.class_full_name,
            p.charge_dept_name,
            p.apply,
            p.approval,
            p.has_pay,
            p.wait_for_pay,
            p.status,
            p.status_name,
            p.item_class,
            p.item_class_name,
            p.dept_id,
            p.dept_name,
            p.area_name,
            p.apply_date,
            p.apply_by,
            p.approval_date,
            p.is_from_old,
            p.explain,
            p.detail,
            p.remark
        from ta_purchase_pay p
    </sql>

    <!--    <sql id="selectNodeVo">-->
    <!--        select n. from node n-->
    <!--    </sql>-->

    <select id="selectFundMain" resultMap="fundMainResult">
        select m.main_id,m.head_id,m.title,m.status,m.status_name,m.biz_id,m.pay_sum,m.dept_id,m.dept_name,m.apply_date,m.apply_by,m.approval_date,m.remark
               from ta_purchase_pay p join ta_fund_main m on p.biz_id = m.biz_id where p.biz_id = #{bizId}
    </select>

    <select id="selectFundDetail" resultMap="fundDetailResult">
        select d.id,d.main_id,d.biz_id,d.pay_no,d.title,d.approval,d.has_pay,d.wait_for_pay,d.approval_for_pay,d.item_class,d.item_class_name,
               d.apply_date,d.status,d.status_name,d.del_flag,d.create_time,d.create_by,d.update_time,d.update_by
        from ta_purchase_pay p join ta_fund_detail d on p.biz_id = d.biz_id left join ta_fund_main m on d.main_id = m.main_id where p.biz_id = #{bizId} and d.del_flag = '0'
    </select>

    <select id="selectAttachmentByBizId" resultType="Attachment">
        select attachment_id,attachment_name,url,create_by,create_time,update_by,update_time,process_id,path,final_path,attachment_type from zjwjsb_attachment where process_id = #{bizId}
    </select>

    <select id="ifPurchaseExist" resultType="int" parameterType="String">
        select count(1) from ta_purchase_pay where biz_id = #{bizId}
    </select>

    <update id="updatePurchase" parameterType="Purchase">
        update ta_purchase_pay
        <set>
            <if test="headId != null and headId != ''">head_id = #{headId},</if>
            <if test="id != null and id!= ''">id = #{id},</if>
            <if test="payNo  != null and payNo  != ''">pay_no = #{payNo}, </if>
            <if test="title  != null and title  != ''">title = #{title}, </if>
            <if test="classFullName   != null and classFullName   != ''">class_full_name = #{classFullName},  </if>
            <if test="chargeDeptName       != null and chargeDeptName       != ''">charge_dept_name = #{chargeDeptName},       </if>
            <if test="apply    != null">apply = #{apply},    </if>
            <if test="approval    != null">approval = #{approval},    </if>
            <if test="hasPay    != null">has_pay = #{hasPay},    </if>
            <if test="waitForPay != null">wait_for_pay = #{waitForPay},</if>
            <if test="status != null">`status` = #{status},</if>
            <if test="statusName != null and statusName != ''">status_name = #{statusName},</if>
            <if test="itemClass    != null">item_class = #{itemClass},    </if>
            <if test="itemClassName    != null and itemClassName    != ''">item_class_name = #{itemClassName},    </if>
            <if test="deptId    != null and deptId    != ''">dept_id = #{deptId},    </if>
            <if test="deptName    != null and deptName    != ''">dept_name = #{deptName},    </if>
            <if test="areaName    != null and areaName    != ''">area_name = #{areaName},    </if>
            <if test="applyDate    != null">apply_date = #{applyDate, jdbcType=TIMESTAMP},    </if>
            <if test="applyBy    != null and applyBy    != ''">apply_by = #{applyBy},    </if>
            <if test="approvalDate    != null">approval_date = #{approvalDate, jdbcType=TIMESTAMP},    </if>
            <if test="isFromOld    != null and isFromOld    != ''">is_from_old = #{isFromOld},    </if>
            <if test="explain    != null and explain    != ''">`explain` = #{explain},    </if>
            <if test="detail    != null and detail    != ''">detail = #{detail},    </if>
            <if test="remark    != null and remark    != ''">remark = #{remark},    </if>
        </set>
        where biz_id = #{bizId}
    </update>


    <insert id="insertPurchase" parameterType="Purchase">
        insert into ta_purchase_pay(
        <trim suffix="" suffixOverrides=",">
            <if test="bizId != null and bizId != ''">biz_id,</if>
            <if test="headId != null and headId != ''">head_id,</if>
            <if test="id != null and id!= ''">id,</if>
            <if test="payNo  != null and payNo  != ''">pay_no, </if>
            <if test="title  != null and title  != ''">title, </if>
            <if test="classFullName   != null and classFullName   != ''">class_full_name,  </if>
            <if test="chargeDeptName       != null and chargeDeptName       != ''">charge_dept_name,       </if>
            <if test="apply    != null">apply,    </if>
            <if test="approval    != null">approval,    </if>
            <if test="hasPay    != null">has_pay,    </if>
            <if test="waitForPay != null">wait_for_pay,</if>
            <if test="status != null">`status`,</if>
            <if test="statusName != null and statusName != ''">status_name,</if>
            <if test="itemClass    != null">item_class,    </if>
            <if test="itemClassName    != null and itemClassName    != ''">item_class_name,    </if>
            <if test="deptId    != null and deptId    != ''">dept_id,    </if>
            <if test="deptName    != null and deptName    != ''">dept_name,    </if>
            <if test="areaName    != null and areaName    != ''">area_name,    </if>
            <if test="applyDate    != null">apply_date,    </if>
            <if test="applyBy    != null and applyBy    != ''">apply_by,    </if>
            <if test="approvalDate    != null">approval_date,    </if>
            <if test="isFromOld    != null">is_from_old,    </if>
            <if test="explain    != null and explain    != ''">`explain`,    </if>
            <if test="detail    != null and detail    != ''">detail,    </if>
            <if test="remark    != null and remark    != ''">remark,    </if>
        </trim>

        )  values(
        <trim suffix="" suffixOverrides=",">
            <if test="bizId != null and bizId != ''">#{bizId},</if>
            <if test="headId != null and headId != ''">#{headId},</if>
            <if test="id != null and id!= ''">#{id},</if>
            <if test="payNo  != null and payNo  != ''">#{payNo}, </if>
            <if test="title  != null and title  != ''">#{title}, </if>
            <if test="classFullName   != null and classFullName   != ''">#{classFullName},  </if>
            <if test="chargeDeptName       != null and chargeDeptName       != ''">#{chargeDeptName},       </if>
            <if test="apply    != null">#{apply},    </if>
            <if test="approval    != null">#{approval},    </if>
            <if test="hasPay    != null">#{hasPay},    </if>
            <if test="waitForPay != null">#{waitForPay},</if>
            <if test="status != null">#{status},</if>
            <if test="statusName != null and statusName != ''">#{statusName},</if>
            <if test="itemClass    != null">#{itemClass},    </if>
            <if test="itemClassName    != null and itemClassName    != ''">#{itemClassName},    </if>
            <if test="deptId    != null and deptId    != ''">#{deptId},    </if>
            <if test="deptName    != null and deptName    != ''">#{deptName},    </if>
            <if test="areaName    != null and areaName    != ''">#{areaName},    </if>
            <if test="applyDate    != null">#{applyDate, jdbcType=TIMESTAMP},    </if>
            <if test="applyBy    != null and applyBy    != ''">#{applyBy},    </if>
            <if test="approvalDate    != null"> #{approvalDate, jdbcType=TIMESTAMP},    </if>
            <if test="isFromOld    != null">#{isFromOld},    </if>
            <if test="explain    != null and explain    != ''">#{explain},    </if>
            <if test="detail    != null and detail    != ''">#{detail},    </if>
            <if test="remark    != null and remark    != ''">#{remark},    </if>
        </trim>
        )
    </insert>

    <select id="selectPurchaseList" parameterType="Purchase" resultMap="purchaseResult">
        <include refid="selectPurchaseVo"/>
        where p.del_flag = '0'
        <if test="itemClass != null">
            and p.item_class = #{itemClass}
        </if>
        <if test="bizId != null and bizId != ''">
            and p.biz_id = #{bizId}
        </if>
        <if test="headId != null and headId != ''">
            and p.head_id like concat('%',#{headId},'%')
        </if>
        <if test="title != null and title != ''">
            and p.title like concat('%',#{title},'%')
        </if>
        <if test="deptName != null and deptName != ''">
            and p.dept_name like concat('%',#{deptName},'%')
        </if>
        <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
            AND date_format(p.apply_date,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
        </if>
        <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
            AND date_format(p.apply_date,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
        </if>
        ${params.dataScope}
        order by p.apply_date desc
    </select>

    <update id="changePurchaseStatusByHeadId" parameterType="Purchase">
        update ta_purchase_pay set status = #{status} where head_id = #{headId}
    </update>

    <update id="deletePurchaseById" parameterType="String">
        update ta_purchase_pay set del_flag = '1' where biz_id = #{bizId}
    </update>

    <select id="selectPurchaseByHeadId" parameterType="String" resultMap="purchaseResult">
        <include refid="selectPurchaseVo"/> where head_id = #{headId}
    </select>

    <select id="selectPurchaseByBizId" parameterType="String" resultMap="purchaseResult">
        <include refid="selectPurchaseVo"/> where biz_id = #{bizId}
    </select>

</mapper>