<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTO Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.no1.wms.category.CategoryMapper">
	<!-- insert -->
	
	<insert id="createProcess" parameterType="CategoryDto">
		INSERT INTO product_category (kan_code, cls_nm_1, cls_nm_2, cls_nm_3, cls_nm_4, activation) 
		VALUES (#{kan_code}, #{cls_nm_1},#{cls_nm_2},#{cls_nm_3},#{cls_nm_4},1)
	</insert>
	 
	<!-- update -->
	
	<update id="updateByKanCode" parameterType="CategoryDto">
		UPDATE product_category 
		SET cls_nm_1 = #{cls_nm_1}, cls_nm_2 = #{cls_nm_2},cls_nm_3 = #{cls_nm_3}, cls_nm_4 = #{cls_nm_4}
		WHERE kan_code = #{kan_code}
	</update>
	
	<update id="deactivateByKanCode" parameterType="String">
		UPDATE product_category 
		SET activation = 0
		WHERE kan_code = #{kan_code}
	</update>
	
	<update id="activateByKanCode" parameterType="String">
		UPDATE product_category 
		SET activation = 1
		WHERE kan_code = #{kan_code}
	</update>
	
	
	<!-- delete -->
	
	
	<!-- select -->
	
	
    
    <select id="categoryList" parameterType="map" resultType="CategoryDto">
		select * from product_category where activation != 0
		order by kan_code limit #{start} , #{count}
	</select>
	
	<select id="selectByKanCode" parameterType="String" resultType="CategoryDto">
		select * from product_category where kan_code = #{kan_code}
	</select>
	
	<select id="selectAllCategory" resultType="CategoryDto">
		select * from product_category
	</select>
	
	<select id="kanCheck" parameterType="String" resultType="String">
		select kan_code from product_category where kan_code = #{kan_code}
	</select>
	<!-- 네비게이션바 전용 카운터 -->
	<select id="count" parameterType="map" resultType="int">
        select count(*)

        from  product_category as p

        <where>
            <choose>
                <when test="searchn == 0"> p.activation = 1 and p.kan_code like concat('%',#{search},'%')</when>
                <when test="searchn == 1"> p.activation = 1 and p.cls_nm_1 like concat('%',#{search},'%')</when>
                <when test="searchn == 2"> p.activation = 1 and p.cls_nm_2 like concat('%',#{search},'%')</when>
                <when test="searchn == 3"> p.activation = 1 and p.cls_nm_3 like concat('%',#{search},'%')</when>
                <when test="searchn == 4"> p.activation = 1 and p.cls_nm_4 like concat('%',#{search},'%')</when>
            </choose>
        </where>
    </select>
	<!-- 검색 -->
	<select id="categoryList2" parameterType="map" resultType="CategoryDto">
        select *

        from  product_category as p

        <where>
            <choose>
                <when test="searchn == 0"> p.activation = 1 and p.kan_code like concat('%',#{search},'%')</when>
                <when test="searchn == 1"> p.activation = 1 and p.cls_nm_1 like concat('%',#{search},'%')</when>
                <when test="searchn == 2"> p.activation = 1 and p.cls_nm_2 like concat('%',#{search},'%')</when>
                <when test="searchn == 3"> p.activation = 1 and p.cls_nm_3 like concat('%',#{search},'%')</when>
                <when test="searchn == 4"> p.activation = 1 and p.cls_nm_4 like concat('%',#{search},'%')</when>
            </choose>
        </where>
        order by kan_code limit #{start} , #{perPage}
    </select>
	
	
	
</mapper>