DictDataMapper.xml 9.18 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.huaheng.pc.system.dict.mapper.DictDataMapper">

    <resultMap type="com.huaheng.pc.system.dict.domain.DictData" id="DictDataResult">
        <id property="id" column="id"/>
        <result property="dictSort" column="dictSort"/>
        <result property="dictLabel" column="dictLabel"/>
        <result property="dictValue" column="dictValue"/>
        <result property="dictType" column="dictType"/>
        <result property="cssClass" column="cssClass"/>
        <result property="listClass" column="listClass"/>
        <result property="isDefault" column="isDefault"/>
        <result property="enable" column="enable"/>
        <result property="createBy" column="createBy"/>
        <result property="createTime" column="createTime"/>
        <result property="updateBy" column="updateBy"/>
        <result property="updateTime" column="updateTime"/>
    </resultMap>

    <sql id="selectDictDataVo">
        select id,
               dictSort,
               dictLabel,
               dictValue,
               dictType,
               cssClass,
               listClass,
               isDefault,
               enable,
               createBy,
               createTime,
               remark
        from sys_dict_data
    </sql>

    <select id="selectDictDataList" resultMap="DictDataResult">
        <include refid="selectDictDataVo"/>
        <where>
            <if test="warehouseCode != null">
                AND warehouseCode = #{warehouseCode}
            </if>
            <if test="dictType != null and dictType != ''">
                AND dictType = #{dictType}
            </if>
            <if test="dictValue != null and dictValue != ''">
                AND dictValue = #{dictValue}
            </if>
            <if test="dictLabel != null and dictLabel != ''">
                AND dictLabel like concat('%', #{dictLabel}, '%')
            </if>
            <if test="enable != null">
                AND enable = #{enable}
            </if>
            <if test="deleted != null">
                AND deleted = #{deleted}
            </if>
        </where>
    </select>

    <select id="selectDictDataByType" resultMap="DictDataResult">
        <include refid="selectDictDataVo"/>
        where warehouseCode = #{warehouseCode} AND dictType = #{dictType} AND enable=true order by dictSort asc
    </select>

    <select id="selectDictLabel" resultType="String">
        select dictLabel
        from sys_dict_data
        where warehouseCode = #{warehouseCode}
          AND dictType = #{dictType}
          and dictValue = #{dictValue}
    </select>

    <select id="selectDictData" resultMap="DictDataResult">
        select *
        from sys_dict_data
        where dictType = #{dictType}
          and dictValue = #{dictValue}
    </select>

    <select id="selectDictDataById" resultMap="DictDataResult">
        <include refid="selectDictDataVo"/>
        where warehouseCode = #{warehouseCode} AND id = #{id}
    </select>

    <select id="countDictDataByType" resultType="Integer">
        select count(1)
        from sys_dict_data
        where warehouseCode = #{warehouseCode}
          AND dictType = #{dictType}
    </select>

    <select id="checkConfig" resultType="java.lang.Integer">
        select id from sys_dict_data
        <where>
            <if test="warehouseCode != null">
                AND warehouseCode = #{warehouseCode}
            </if>
            <if test="dictType != null">
                AND dictType = #{dictType}
            </if>
            <if test="dictValue != null">
                AND dictValue = #{dictValue}
            </if>
        </where>
    </select>

    <delete id="deleteDictDataById">
        delete
        from sys_dict_data
        where warehouseCode = #{warehouseCode}
          AND id = #{id}
    </delete>

    <delete id="deleteDictDataByIds">
        delete from sys_dict_data where warehouseCode = #{warehouseCode} AND id in
        <foreach collection="ids" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <update id="updateDictData">
        update sys_dict_data
        <set>
            <if test="dictSort != null and dictSort != ''">dictSort = #{dictSort},</if>
            <if test="dictLabel != null and dictLabel != ''">dictLabel = #{dictLabel},</if>
            <if test="dictValue != null and dictValue != ''">dictValue = #{dictValue},</if>
            <if test="dictType != null and dictType != ''">dictType = #{dictType},</if>
            <if test="cssClass != null and cssClass != ''">cssClass = #{cssClass},</if>
            <if test="listClass != null and listClass != ''">listClass = #{listClass},</if>
            <if test="isDefault != null and isDefault != ''">isDefault = #{isDefault},</if>
            <if test="enable != null">enable = #{enable},</if>
            <if test="remark != null and remark != ''">remark = #{remark},</if>
            <if test="updateBy != null and updateBy != ''">updateBy = #{updateBy},</if>
            updateTime = sysdate()
        </set>
        where warehouseCode = #{warehouseCode} AND id = #{id}
    </update>

    <update id="updateDictDataType">
        update sys_dict_data
        set dictType = #{newDictType}
        where dictType = #{oldDictType}
    </update>

    <insert id="insertDictData">
        insert into sys_dict_data(
        <if test="headerId !=null">headerId,</if>
        <if test="warehouseCode != null">warehouseCode,</if>
        <if test="dictSort != null">dictSort,</if>
        <if test="dictLabel != null">dictLabel,</if>
        <if test="dictValue != null">dictValue,</if>
        <if test="dictType != null">dictType,</if>
        <if test="cssClass != null ">cssClass,</if>
        <if test="listClass != null">listClass,</if>
        <if test="isDefault != null">isDefault,</if>
        <if test="enable != null">enable,</if>
        <if test="remark != null">remark,</if>
        <if test="createBy != null">createBy,</if>
        createTime
        )values(
        <if test="headerId !=null">#{headerId},</if>
        <if test="warehouseCode != null">#{warehouseCode},</if>
        <if test="dictSort != null">#{dictSort},</if>
        <if test="dictLabel != null">#{dictLabel},</if>
        <if test="dictValue != null">#{dictValue},</if>
        <if test="dictType != null">#{dictType},</if>
        <if test="cssClass != null">#{cssClass},</if>
        <if test="listClass != null">#{listClass},</if>
        <if test="isDefault != null">#{isDefault},</if>
        <if test="enable != null">#{enable},</if>
        <if test="remark != null">#{remark},</if>
        <if test="createBy != null">#{createBy},</if>
        sysdate()
        )
    </insert>

    <delete id="deleteDictDataByWarehouseCode">
        delete
        from sys_dict_data
        where warehouseCode = #{warehouseCode}
    </delete>

    <insert id="insertDictDatas">
        insert into sys_dict_data(
        headerId,
        warehouseCode,
        dictLabel,
        dictValue,
        dictType,
        cssClass,
        listClass,
        remark,
        createBy,
        createTime
        )values
        <foreach collection="dictDatas" item="item" index="index" separator=",">
            (
            #{item.headerId},
            #{item.warehouseCode},
            #{item.dictLabel},
            #{item.dictValue},
            #{item.dictType},
            #{item.cssClass},
            #{item.listClass},
            #{item.remark},
            #{item.createBy},
            sysdate()
            )
        </foreach>
    </insert>

    <select id="selectModel" resultType="com.huaheng.pc.system.dict.domain.DictData">
        select * from sys_dict_data
        <where>
            <if test="warehouseCode != null">
                AND warehouseCode = #{warehouseCode}
            </if>
            <if test="headerId != null">
                AND headerId = #{headerId}
            </if>
            <if test="dictValue != null">
                AND dictValue = #{dictValue}
            </if>
            <if test="dictLabel != null">
                AND dictLabel = #{dictLabel}
            </if>
            <if test="dictType != null">
                AND dictType = #{dictType}
            </if>
            <if test="remark != null">
                AND remark = #{remark}
            </if>
        </where>
        limit 1
    </select>

    <insert id="dictDateCopy">
        insert into sys_dict_data(warehouseCode, dictSort, dictLabel, dictValue, dictType, cssClass, listClass,
                                  isDefault, enable, deleted, remark)
        SELECT #{newCode},
               dictSort,
               dictLabel,
               dictValue,
               dictType,
               cssClass,
               listClass,
               isDefault,
               enable,
               deleted,
               remark
        from sys_dict_data
        where warehouseCode = #{code}

    </insert>

    <update id="updateHeaderId">
        update sys_dict_data d
            inner join sys_dict_type t
        on t.dictType=d.dictType and d.warehouseCode=t.warehouseCode and d.warehouseCode=#{code}
            set d.headerId=t.id
    </update>

</mapper>