fuliqi
2024-08-21 31d3591b34d4f26ad2ab207ca3044048d9adb9df
ycl-server/src/main/resources/mapper/zgyw/TContractMapper.xml
@@ -1,86 +1,54 @@
<?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">
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ycl.platform.mapper.TContractMapper">
    <resultMap type="com.ycl.platform.domain.entity.TContract" id="TContractResult">
        <result property="id"    column="id"    />
        <result property="companyId"    column="company_id"    />
        <result property="companyName"    column="company_name"    />
        <result property="deptId"    column="dept_id"    />
        <result property="deptName"    column="dept_name"    />
        <result property="detail"    column="detail"    />
        <result property="startTime"    column="start_time"    />
        <result property="endTime"    column="end_time"    />
    </resultMap>
    <sql id="selectTContractVo">
        select id, company_id, company_name, dept_id, dept_name, detail ,start_time,end_time from t_contract
    </sql>
    <select id="selectAll" resultType="com.ycl.platform.domain.entity.TContract">
        select a.*, b.unit_name
        from t_contract a
                 left join t_yw_unit b on a.unit_id = b.id and b.deleted = 0
        where a.deleted = 0
        order by create_time desc
    </select>
    <select id="selectTContractList" parameterType="com.ycl.platform.domain.entity.TContract" resultMap="TContractResult">
        <include refid="selectTContractVo"/>
        <where>
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="companyName != null  and companyName != ''"> and company_name like concat('%', #{companyName}, '%')</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="deptName != null  and deptName != ''"> and dept_name like concat('%', #{deptName}, '%')</if>
            <if test="detail != null  and detail != ''"> and detail = #{detail}</if>
            <if test="startTime != null"> and start_time = #{startTime}</if>
            <if test="endTime != null"> and end_time = #{endTime}</if>
    <select id="getPage" resultType="com.ycl.platform.domain.vo.ContractVO">
        select a.*, b.unit_name
        from t_contract a
        left join t_yw_unit b on a.unit_id = b.id and b.deleted = 0
        where a.deleted = 0
        <if test="query.name != null and query.name != ''">
            and a.name like concat('%', #{query.name}, '%')
        </if>
        <if test="query.status != null and query.status != ''">
            <choose>
                <when test="query.status == 'ACTIVE'">
                    and a.start_time &lt; sysdate() and a.end_time > sysdate()
                </when>
                <when test="query.status == 'NOT_START'">
                    and a.start_time > sysdate()
                </when>
                <when test="query.status == 'FINISHED'">
                    and a.end_time &lt; sysdate()
                </when>
            </choose>
        </if>
        order by create_time desc
    </select>
    <select id="selectByRuleName" resultType="com.ycl.platform.domain.vo.CalculateRuleVO">
        select tc.unit_id ,tcr.*
        from t_contract tc
        left join t_calculate_rule tcr on tc.id = tcr.contract_id
        <where>
            tc.deleted =0 and #{date} between tc.start_time and tc.end_time
            <if test="ruleName !=null and ruleName!=''">
                and tcr.rule_name = #{ruleName}
            </if>
            <if test="ruleCondition !=null and ruleCondition!=''">
                and tcr.rule_condition = #{ruleCondition}
            </if>
        </where>
    </select>
    <select id="selectTContractById" parameterType="Long" resultMap="TContractResult">
        <include refid="selectTContractVo"/>
        where id = #{id}
    </select>
    <insert id="insertTContract" parameterType="com.ycl.platform.domain.entity.TContract" useGeneratedKeys="true" keyProperty="id">
        insert into t_contract
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="companyId != null">company_id,</if>
            <if test="companyName != null">company_name,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="deptName != null">dept_name,</if>
            <if test="detail != null">detail,</if>
            <if test="startTime != null">start_time,</if>
            <if test="endTime != null">end_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="companyId != null">#{companyId},</if>
            <if test="companyName != null">#{companyName},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="deptName != null">#{deptName},</if>
            <if test="detail != null">#{detail},</if>
            <if test="startTime != null">#{startTime},</if>
            <if test="endTime != null">#{endTime},</if>
         </trim>
    </insert>
    <update id="updateTContract" parameterType="com.ycl.platform.domain.entity.TContract">
        update t_contract
        <trim prefix="SET" suffixOverrides=",">
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="companyName != null">company_name = #{companyName},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="deptName != null">dept_name = #{deptName},</if>
            <if test="detail != null">detail = #{detail},</if>
            <if test="startTime != null">start_time = #{startTime},</if>
            <if test="endTime != null">end_time = #{endTime},</if>
        </trim>
        where id = #{id}
    </update>
    <delete id="deleteTContractById" parameterType="Long">
        delete from t_contract where id = #{id}
    </delete>
    <delete id="deleteTContractByIds" parameterType="String">
        delete from t_contract where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
</mapper>