<?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.shinsoft.sto.mapper.main.WareMapper" >
  <resultMap id="BaseResultMap" type="com.shinsoft.sto.model.main.Ware" >
    <id column="id" property="id" jdbcType="VARCHAR" />
    <result column="name" property="wareNm" jdbcType="VARCHAR" />
    <result column="code" property="wareCode" jdbcType="VARCHAR" />
    <result column="add_id" property="addId" jdbcType="VARCHAR" />
    <result column="add_time" property="addTime" jdbcType="TIMESTAMP" />
    <result column="modify_id" property="modifyId" jdbcType="VARCHAR" />
    <result column="modify_time" property="modifyTime" jdbcType="TIMESTAMP" />
    <result column="cancel_id" property="cancelId" jdbcType="VARCHAR" />
    <result column="cancel_time" property="cancelTime" jdbcType="TIMESTAMP" />
    <result column="cancel_flag" property="cancelFlag" jdbcType="VARCHAR" />
    <result column="belong_id" property="belongId" jdbcType="VARCHAR" />
    <result column="width" property="wareWidth" jdbcType="INTEGER" />
    <result column="height" property="wareLength" jdbcType="INTEGER" />
  </resultMap>
  <sql id="Base_Column_List" >
    id, name, code, add_id, add_time, modify_id, modify_time, cancel_id, cancel_time, 
    cancel_flag, belong_id, width, height
  </sql>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select 
    <include refid="Base_Column_List" />
    from t_maint_ware
    where id = #{id,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
    delete from t_maint_ware
    where id = #{id,jdbcType=VARCHAR}
  </delete>





  <select id="select" resultMap="BaseResultMap" >
    select *
    from t_maint_ware
    where (name like concat('%',#{param1,jdbcType=VARCHAR},'%') or code like concat('%',#{param1,jdbcType=VARCHAR},'%'))
    and   belong_id = #{param2,jdbcType=VARCHAR}
    and ifnull(cancel_flag,'0') = '0'
  </select>

  <select id="selectAll" resultMap="BaseResultMap" >
    select *
    from t_maint_ware
    where belong_id = #{param1,jdbcType=VARCHAR}
    and ifnull(cancel_flag,'0') = '0'
  </select>

  <select id="selectByUserId" resultMap="BaseResultMap" >
     select t.*  from t_maint_ware t
  where t.id in (
 select  d.ware_id from t_maint_userware d where t.id = d.ware_id and d.user_id = #{param1,jdbcType=VARCHAR}
) and  t.belong_id = #{param2,jdbcType=VARCHAR}
    and ifnull(t.cancel_flag,'0') = '0'
  </select>


  <select id="selectByWareName" resultMap="BaseResultMap" >
     select t.*  from t_maint_ware t
  where t.id in  (
 select  d.ware_id from t_maint_userware d where t.id = d.ware_id and d.user_id = #{param2,jdbcType=VARCHAR}
)
and t.name =   #{param1,jdbcType=VARCHAR}
and  t.belong_id = #{param3,jdbcType=VARCHAR}
    and ifnull(t.cancel_flag,'0') = '0'
  </select>

  <select id="selectByWareId" resultMap="BaseResultMap" >
     select t.*  from t_maint_ware t
  where t.id in  (
 select  d.ware_id from t_maint_userware d where t.id = d.ware_id and d.user_id = #{param2,jdbcType=VARCHAR}
)
and t.id =   #{param1,jdbcType=VARCHAR}
and  t.belong_id = #{param3,jdbcType=VARCHAR}
    and ifnull(t.cancel_flag,'0') = '0'
  </select>
</mapper>