<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//oos.juyouhx.com//DTD Mapper 3.0//EN" "http://oss.juyouhx.com/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.scpyun.platform.standard.jilinsscgsdp.keyPersonLevelSet" name="评分等级维护">
  <!-- 列表：固定 type = rating_level -->
  <select id="selectList" parameterType="map" resultType="map">
    SELECT
      id,
      `value`,
      `label`,
      `sort`
    FROM sys_dict
    WHERE del_flag = '0'
      AND `type` = 'rating_level'
    ORDER BY CAST(`sort` AS SIGNED) ASC, `value` ASC
  </select>

  <!-- 检查评分等级是否重复（同 type 下 value 是否已存在） -->
  <select id="existsByValue" parameterType="map" resultType="int">
    SELECT COUNT(1)
    FROM sys_dict
    WHERE del_flag = '0'
      AND `type` = 'rating_level'
      AND `value` = #{value}
      <if test="id != null and id != ''">
        AND id != #{id}
      </if>
  </select>

  <!-- 新增 -->
  <insert id="insert" parameterType="map">
    INSERT INTO sys_dict (
      id,
      `value`,
      `label`,
      `type`,
      `type_category`,
      `description`,
      `sort`,
      `parent_id`,
      `create_by`,
      `create_date`,
      `update_by`,
      `update_date`,
      `remarks`,
      `del_flag`,
      `dict_type`,
      `is_easy`
    ) VALUES (
      REPLACE(UUID(), '-', ''),
      #{value},
      #{label},
      'rating_level',
      NULL,
      '重点人员评分等级',
      #{sort},
      '0',
      #{_user.id},
      NOW(),
      #{_user.id},
      NOW(),
      NULL,
      '0',
      1,
      NULL
    )
  </insert>

  <!-- 更新 -->
  <update id="update" parameterType="map">
    UPDATE sys_dict
    SET
      `value` = #{value},
      `label` = #{label},
      `sort` = #{sort},
      `update_by` = #{_user.id},
      `update_date` = NOW()
    WHERE id = #{id}
      AND `type` = 'rating_level'
  </update>

  <!-- 删除（逻辑删除） -->
  <update id="delete" parameterType="map">
    UPDATE sys_dict
    SET del_flag = '1', update_by = #{_user.id}, update_date = NOW()
    WHERE id = #{id}
      AND `type` = 'rating_level'
  </update>
</mapper>


