SpecRuleMaterialMapper.xml 5.8 KB
Newer Older
张新旗 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
<?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.ruoyi.system.mapper.SpecRuleMaterialMapper">
    
    <resultMap type="SpecRuleMaterial" id="SpecRuleMaterialResult">
        <result property="id"    column="id"    />
        <result property="name"    column="name"    />
        <result property="specId"    column="spec_id"    />
        <result property="ruleId"    column="rule_id"    />
        <result property="materialId"    column="material_id"    />
        <result property="materialName"    column="material_name"    />
        <result property="quantity"    column="quantity"    />
        <result property="unit"    column="unit"    />
        <result property="isDeleted"    column="is_deleted"    />
        <result property="createdAt"    column="created_at"    />
        <result property="updatedAt"    column="updated_at"    />
    </resultMap>

    <sql id="selectSpecRuleMaterialVo">
        select id, name, spec_id, rule_id, material_id, material_name, quantity, unit, is_deleted, created_at, updated_at from spec_rule_material
    </sql>

    <select id="selectSpecRuleMaterialList" parameterType="SpecRuleMaterial" resultMap="SpecRuleMaterialResult">
        <include refid="selectSpecRuleMaterialVo"/>
        <where>
            and is_deleted = 0
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="specId != null  and specId != ''"> and spec_id = #{specId}</if>
            <if test="ruleId != null "> and rule_id = #{ruleId}</if>
            <if test="materialId != null  and materialId != ''"> and material_id = #{materialId}</if>
            <if test="materialName != null  and materialName != ''"> and material_name like concat('%', #{materialName}, '%')</if>
            <if test="quantity != null  and quantity != ''"> and quantity = #{quantity}</if>
            <if test="unit != null  and unit != ''"> and unit = #{unit}</if>

            <if test="createdAt != null "> and created_at = #{createdAt}</if>
            <if test="updatedAt != null "> and updated_at = #{updatedAt}</if>
        </where>
    </select>
    
    <select id="selectSpecRuleMaterialById" parameterType="String" resultMap="SpecRuleMaterialResult">
        <include refid="selectSpecRuleMaterialVo"/>
        where id = #{id}
        and is_deleted = 0
    </select>
        
    <insert id="insertSpecRuleMaterial" parameterType="SpecRuleMaterial" useGeneratedKeys="true" keyProperty="id">
        insert into spec_rule_material
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">name,</if>
            <if test="specId != null and specId != ''">spec_id,</if>
            <if test="ruleId != null">rule_id,</if>
            <if test="materialId != null and materialId != ''">material_id,</if>
            <if test="materialName != null and materialName != ''">material_name,</if>
            <if test="quantity != null and quantity != ''">quantity,</if>
            <if test="unit != null and unit != ''">unit,</if>
            <if test="isDeleted != null and isDeleted != ''">is_deleted,</if>
            <if test="createdAt != null">created_at,</if>
            <if test="updatedAt != null">updated_at,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null and name != ''">#{name},</if>
            <if test="specId != null and specId != ''">#{specId},</if>
            <if test="ruleId != null">#{ruleId},</if>
            <if test="materialId != null and materialId != ''">#{materialId},</if>
            <if test="materialName != null and materialName != ''">#{materialName},</if>
            <if test="quantity != null and quantity != ''">#{quantity},</if>
            <if test="unit != null and unit != ''">#{unit},</if>
            <if test="isDeleted != null and isDeleted != ''">#{isDeleted},</if>
            <if test="createdAt != null">#{createdAt},</if>
            <if test="updatedAt != null">#{updatedAt},</if>
         </trim>
    </insert>

    <update id="updateSpecRuleMaterial" parameterType="SpecRuleMaterial">
        update spec_rule_material
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="specId != null and specId != ''">spec_id = #{specId},</if>
            <if test="ruleId != null">rule_id = #{ruleId},</if>
            <if test="materialId != null and materialId != ''">material_id = #{materialId},</if>
            <if test="materialName != null and materialName != ''">material_name = #{materialName},</if>
            <if test="quantity != null and quantity != ''">quantity = #{quantity},</if>
            <if test="unit != null and unit != ''">unit = #{unit},</if>
            <if test="isDeleted != null and isDeleted != ''">is_deleted = #{isDeleted},</if>
            <if test="createdAt != null">created_at = #{createdAt},</if>
            <if test="updatedAt != null">updated_at = #{updatedAt},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSpecRuleMaterialById" parameterType="String">
        delete from spec_rule_material where id = #{id}
    </delete>

    <delete id="deleteSpecRuleMaterialByIds" parameterType="String">
        delete from spec_rule_material where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <delete id="deleteSpecRuleMaterialByMaterialId" parameterType="String">
        update spec_rule_material set is_deleted =1  where material_id = #{id}
    </delete>
    <update id="deleteSpecRuleMaterialBySpecId">
        update spec_rule_material set is_deleted =1,updated_at =now() where spec_id=#{specId}
    </update>
</mapper>