<?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.persagy.dye.mapper.DyeRuleCustomMapper">

    <resultMap id="BaseResultMap" type="com.persagy.dye.pojo.dto.DyeRuleCustom">
        <result column="id" property="id" jdbcType="VARCHAR" />
        <result column="basic_id" property="basicId" jdbcType="VARCHAR" />
        <result column="group_code" property="groupCode" jdbcType="VARCHAR" />
        <result column="project_id" property="projectId" jdbcType="VARCHAR" />
        <result column="upper_limit" property="upperLimit" jdbcType="INTEGER" />
        <result column="upper_symbol" property="upperSymbol" jdbcType="VARCHAR" />
        <result column="lower_limit" property="lowerLimit" jdbcType="INTEGER" />
        <result column="lower_symbol" property="lowerSymbol" jdbcType="VARCHAR" />
        <result column="name" property="name" jdbcType="VARCHAR" />
        <result column="color_value" property="colorValue" jdbcType="VARCHAR" />
        <result column="create_time" property="createTime" jdbcType="VARCHAR" />
        <result column="update_time" property="updateTime" jdbcType="VARCHAR" />
        <result column="update_user_id" property="updateUserId" jdbcType="VARCHAR" />
        <result column="is_delete" property="isDelete" jdbcType="VARCHAR" />
        <result column="order_num" property="orderNum" jdbcType="INTEGER" />
        <result column="num_symbol" property="numSymbol" jdbcType="VARCHAR" />
    </resultMap>

    <select id="listDyeRuleCustomByType" resultMap="BaseResultMap">
        SELECT *
        FROM `dye_rule_custom`
        WHERE GROUP_CODE = #{groupCode}
          AND PROJECT_ID = #{projectId}
          AND basic_id in
              (SELECT id
               FROM dye_basic
               WHERE type_code = #{typeCode}
                 AND season_code = (SELECT DICT_CODE FROM `work_calendar_label`  WHERE LABEL_DATE = #{queryDate} AND PROJECT_ID = #{projectId})
                 AND is_delete = 0)
          AND is_delete = 0
        ORDER BY order_num
    </select>

    <select id="getDistrictDyeRuleCustom" resultMap="BaseResultMap">
        SELECT *
        FROM `dye_rule_custom`
        WHERE GROUP_CODE = #{dyeScaleplateVO.groupCode}
          AND PROJECT_ID = #{dyeScaleplateVO.projectId}
          AND basic_id IN (SELECT id
                           FROM dye_basic
                           WHERE type_code = #{dyeScaleplateVO.typeCode}
                             AND is_delete = 0
                             AND season_code = (SELECT DICT_CODE FROM `work_calendar_label`  WHERE LABEL_DATE = #{dyeScaleplateVO.queryDate} AND PROJECT_ID = #{dyeScaleplateVO.projectId}))
          AND is_delete = 0
          AND ((upper_symbol = ')' AND upper_limit &gt; #{numValue}) OR (upper_symbol = ']' AND upper_limit &gt;= #{numValue}))
          AND ((lower_symbol = '(' AND lower_limit &lt; #{numValue}) OR (lower_symbol = '[' AND lower_limit &lt;= #{numValue}))
        ORDER BY order_num
    </select>
</mapper>