<?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.chinaitop.depot.intelligent.basicdata.mapper.WareHouseBasicInfoMapper" >
    <select id="getStorehouseInfo" parameterType="java.util.Map" resultType="java.util.Map">
      SELECT
        t2.storehouse_type,
        t2.storehouse_code,
        t2.storehouse_name,
        t2.design_capacity,
        t2.house_doot_position,
        t2.storehouse_state,
        t2.dutyStoreman,
        t1.lkmc,
        t1.pz,
        t1.hwxz,
        t1.dj,
        t1.kcsl,
        DATE_FORMAT(t1.rq,'%Y') AS rq,
        DATE_FORMAT(t1.rq,'%Y-%m-%d') AS rcrq,
        DATE_FORMAT(t1.cjsj,'%Y-%m-%d') AS cjsj,
        t1.UnitID
      FROM
        `lsreport_ts`.data_kcgl_kcsw_default AS t1
      LEFT JOIN `depot`.`basic_storehouse` t2 ON t1.UnitID = t2.org_id AND t1.ch = t2.storehouse_id AND del_flag = 1
      <where>
          <if test="org_id != null">
              t2.org_id = #{org_id}
          </if>
          <if test="library_type != null">
              AND t2.library_type = #{library_type}
          </if>
          <if test="cfCdoe != null">
              AND t2.storehouse_code = #{cfCdoe}
          </if>
      </where>
      GROUP BY
        t2.storehouse_code
    </select>

    <select id="getColumn1Max" parameterType="java.util.Map" resultType="java.util.Map">
        SELECT
        <trim suffixOverrides="," >
            <if test="column1 != null" >
                MAX(${column1}) column1,
            </if>
            <if test="column2 != null" >
                MAX(${column2}) column2,
            </if>
            <if test="column3 != null" >
                MAX(${column3}) column3,
            </if>
        </trim>
        FROM ${tableName}
        where ${column1} >= 10000
    </select>

    <select id="getEnum" parameterType="java.lang.String" resultType="java.lang.String">
        SELECT
	      enumName
        FROM
	      basic_enum
        WHERE
	      enumId = ${code} AND delFlag = 1
    </select>

    <select id="getKeeperName" parameterType="java.util.Map" resultType="java.lang.String">
       SELECT
        GROUP_CONCAT(bk.name) keeperName
        FROM
	     basic_keeper_house kh,
	     basic_keeper bk,
	     basic_storehouse bs
        WHERE
	     kh.org_id = bk.org_id
        AND bk.id = kh.keeper_Id
        AND kh.house_Id = bs.storehouse_id
        AND bk.org_id = bs.org_id
        AND bs.storehouse_code = ${storehouse_code}
        AND bs.org_id = ${UnitID}
        AND bs.del_flag = 1
    </select>
</mapper>