<?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.css.simulation.resource.server.infra.db.mysql.mapper.DictMapper" >


    <select id="getDicts" parameterType="java.util.ArrayList" resultType="api.common.pojo.vo.system.DictVO">
        select
          id,
          pid,
          dict_type,
          dict_name,
          dict_code,
          dict_order,
          remark
        from system_dict d
        where d.is_deleted = '0'
        <foreach collection="list" item="item" index="index" open=" and d.dict_type in (" separator="," close=")">
            <if test="item != null and item != ''">
                #{item,jdbcType=VARCHAR}
            </if>
        </foreach>
        order by d.dict_order
    </select>



    <insert id="saveSystemDict" parameterType="api.common.pojo.po.system.DictPO">
        INSERT INTO system_dict(
            id,
            dict_comment,
            dict_type,
            dict_name,
            dict_code,
            dict_order,
            create_time,
            modify_time,
            create_user_id,
            modify_user_id,
            is_deleted
        )
        VALUES(
            #{id,jdbcType=VARCHAR},
            '三维视频车辆类型',
            #{dictType,jdbcType=VARCHAR},
            #{dictName,jdbcType=VARCHAR},
            #{dictCode,jdbcType=VARCHAR},
            #{dictOrder,jdbcType=VARCHAR},
            #{createTime,jdbcType=TIMESTAMP},
            #{modifyTime,jdbcType=TIMESTAMP},
            #{createUserId,jdbcType=VARCHAR},
            #{modifyUserId,jdbcType=VARCHAR},
            #{isDeleted,jdbcType=VARCHAR}
        )
    </insert>

    <insert id="createSystemDict" parameterType="api.common.pojo.po.system.DictPO">
        INSERT INTO system_dict(
            id,
            dict_comment,
            dict_type,
            dict_name,
            dict_code,
            dict_order,
            create_time,
            modify_time,
            create_user_id,
            modify_user_id,
            is_deleted
        )
        VALUES(
                  #{id,jdbcType=VARCHAR},
                  #{dictComment,jdbcType=VARCHAR},
                  #{dictType,jdbcType=VARCHAR},
                  #{dictName,jdbcType=VARCHAR},
                  #{dictCode,jdbcType=VARCHAR},
                  #{dictOrder,jdbcType=VARCHAR},
                  #{createTime,jdbcType=TIMESTAMP},
                  #{modifyTime,jdbcType=TIMESTAMP},
                  #{createUserId,jdbcType=VARCHAR},
                  #{modifyUserId,jdbcType=VARCHAR},
                  #{isDeleted,jdbcType=VARCHAR}
              )
    </insert>

    <update id="updateSystemDict" parameterType="api.common.pojo.po.system.DictPO">
        update system_dict set
        dict_name = #{dictName,jdbcType=VARCHAR},
        modify_time = #{modifyTime,jdbcType=TIMESTAMP},
        modify_user_id = #{modifyUserId,jdbcType=VARCHAR}
        where dict_code = #{dictCode,jdbcType=VARCHAR}
        and dict_type='carType'
        and is_deleted='0'
    </update>
    <update id="deleteSystemDict" parameterType="api.common.pojo.po.system.DictPO">
        update system_dict set
        is_deleted ='1',
        modify_time = #{modifyTime,jdbcType=TIMESTAMP},
        modify_user_id = #{modifyUserId,jdbcType=VARCHAR}
        where dict_code = #{dictCode,jdbcType=VARCHAR}
        and dict_type='carType'
        and is_deleted='0'
    </update>

    <update id="deleteSystemDictByCodeAndType" parameterType="api.common.pojo.po.system.DictPO">
        update system_dict set
                               is_deleted ='1',
                               modify_time = #{modifyTime,jdbcType=TIMESTAMP},
                               modify_user_id = #{modifyUserId,jdbcType=VARCHAR}
        where dict_code = #{dictCode,jdbcType=VARCHAR}
          and dict_type = #{dictType,jdbcType=VARCHAR}
          and is_deleted='0'
    </update>

    <select id="getDictByDictCode"  resultType="java.lang.String" parameterType="api.common.pojo.po.system.DictPO" >
        select
        id
        from system_dict
        where is_deleted = '0'
        and dict_code = #{dictCode,jdbcType=VARCHAR}
        and dict_type='carType'
    </select>
</mapper>
