LocationMapper.xml 9.03 KB
<?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.huaheng.pc.config.location.mapper.LocationMapper">
  <resultMap id="BaseResultMap" type="com.huaheng.pc.config.location.domain.Location">
    <!--@mbg.generated-->
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="code" jdbcType="VARCHAR" property="code" />
    <result column="warehouseCode" jdbcType="VARCHAR" property="warehouseCode" />
    <result column="zoneCode" jdbcType="VARCHAR" property="zoneCode" />
    <result column="locationType" jdbcType="VARCHAR" property="locationType" />
    <result column="containerCode" jdbcType="VARCHAR" property="containerCode" />
    <result column="iRow" jdbcType="INTEGER" property="iRow" />
    <result column="iColumn" jdbcType="INTEGER" property="iColumn" />
    <result column="iLayer" jdbcType="INTEGER" property="iLayer" />
    <result column="iGrid" jdbcType="INTEGER" property="iGrid" />
    <result column="roadway" jdbcType="VARCHAR" property="roadway" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="lastCycleCountDate" jdbcType="TIMESTAMP" property="lastCycleCountDate" />
    <result column="created" jdbcType="TIMESTAMP" property="created" />
    <result column="createdBy" jdbcType="VARCHAR" property="createdBy" />
    <result column="lastUpdated" jdbcType="TIMESTAMP" property="lastUpdated" />
    <result column="lastUpdatedBy" jdbcType="VARCHAR" property="lastUpdatedBy" />
    <result column="version" jdbcType="INTEGER" property="version" />
    <result column="userDef1" jdbcType="VARCHAR" property="userDef1" />
    <result column="userDef2" jdbcType="VARCHAR" property="userDef2" />
    <result column="userDef3" jdbcType="VARCHAR" property="userDef3" />
    <result column="userDef4" jdbcType="VARCHAR" property="userDef4" />
    <result column="userDef5" jdbcType="VARCHAR" property="userDef5" />
    <result column="userDef6" jdbcType="VARCHAR" property="userDef6" />
    <result column="userDef7" jdbcType="VARCHAR" property="userDef7" />
    <result column="userDef8" jdbcType="VARCHAR" property="userDef8" />
    <result column="systemCreated" jdbcType="INTEGER" property="systemCreated" />
      <result column="deleted" jdbcType="BIT" property="deleted" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    id, code, warehouseCode, zoneCode, locationType, containerCode, iRow, iColumn, iLayer,
    iGrid, roadway, status, `name`, lastCycleCountDate, created, createdBy, lastUpdated, lastUpdatedBy,
    version, userDef1, userDef2, userDef3, userDef4, userDef5, userDef6, userDef7, userDef8,
    systemCreated
  </sql>

  <update id="updateStatus">
        UPDATE location set `status`=#{status} WHERE warehouseCode=#{warehouseCode} AND `code`=#{code}
    </update>

    <update id="updateStatusNew">
        UPDATE location
        SET `status`= #{status}
        WHERE warehouseCode = #{warehouseCode}
          AND `code`= #{code}
          AND `status` = #{oldStatus}
    </update>
  <select id="position" resultMap="BaseResultMap">
    select code from location where #{locatingRule}
  </select>

  <insert id="addList" parameterType="com.huaheng.pc.config.location.domain.Location" keyProperty="id" useGeneratedKeys="true" >
    INSERT INTO location(
    code,
    warehouseCode,
    zoneCode,
    locationType,
    iRow,
    iColumn,
    iLayer,
    iGrid,
    roadway,
    area,
    createdBy,
    lastUpdatedBy,
    status,
    high
    )values
    <foreach collection="locations" item="item" index="index" separator=",">
      (
      #{item.code},
      #{item.warehouseCode},
      #{item.zoneCode},
      #{item.locationType},
      #{item.iRow},
      #{item.iColumn},
      #{item.iLayer},
      #{item.iGrid},
      #{item.roadway},
      #{item.area},
      #{item.createdBy},
      #{item.lastUpdatedBy},
      #{item.status},
      #{item.high}
      )
    </foreach>
  </insert>

    <update id="updateList" parameterType="com.huaheng.pc.config.location.domain.Location" keyProperty="id" useGeneratedKeys="true" >
        replace INTO location(
        code,
        warehouseCode,
        zoneCode,
        locationType,
        iRow,
        iColumn,
        iLayer,
        iGrid,
        rowFlag,
        roadway,
        area,
        createdBy,
        lastUpdatedBy,
        status
        )values
        <foreach collection="locations" item="item" index="index" separator=",">
            (
            #{item.code},
            #{item.warehouseCode},
            #{item.zoneCode},
            #{item.locationType},
            #{item.iRow},
            #{item.iColumn},
            #{item.iLayer},
            #{item.iGrid},
            #{item.rowFlag},
            #{item.roadway},
            #{item.area},
            #{item.createdBy},
            #{item.lastUpdatedBy},
            #{item.status}
            )
        </foreach>
    </update>

  <select id="getAllLocation" resultType="com.huaheng.pc.config.location.domain.Location">
    select  max(iRow) as iRow,max(iColumn) as iColumn,max(iLayer) as iLayer,max(iGrid) as iGrid from location l where l.warehouseCode=#{warehouseCode} AND l.locationType=#{type}
  </select>

  <select id="getLocationProp"  resultType="java.util.LinkedHashMap">
      SELECT w.name warehouseName,ifnull(convert(a.num1/(b.num2+a.num1),decimal(15,2)),0) '有货',ifnull(convert(b.num2/(b.num2+a.num1),decimal(15,2)),0) '无货'  from warehouse w
      left join
      (SELECT count(1) num1,warehouseCode FROM location WHERE containerCode!='' GROUP BY warehouseCode) a on a.warehouseCode=w.code
      LEFT JOIN
      (SELECT count(1) num2,warehouseCode FROM location WHERE containerCode ='' GROUP BY warehouseCode) b on b.warehouseCode=w.code
    </select>

  <select id="pickLocation" resultType="com.huaheng.pc.config.location.domain.Location">
        select * from location
        where containerCode != '' and status = 'empty'
    </select>

    <select id="selectContainerEmpty" resultType="com.huaheng.pc.config.location.domain.Location">
        SELECT id, code, warehouseCode, zoneCode, locationType, containerCode, iRow, iColumn, iLayer,
        iGrid, roadway, `name`, `enable`, lastCycleCountDate, created, createdBy, lastUpdated, lastUpdatedBy,
        version, userDef1, userDef2, userDef3, userDef4, userDef5, userDef6, userDef7, userDef8,
        systemCreated
        FROM location t
        <where>
            t.warehouseCode = #{warehouseCode}
            AND t.status='empty'
            AND t.containerCode !=''
            AND t.containerCode is not NULL
            AND t.`code` NOT in
            (SELECT b.locationCode FROM inventory_detail WHERE b.warehouseCode = #{warehouseCode})
            ORDER BY t.lastUpdated ASC
        </where>
    </select>
    <select id="getFirstRowOfZone" resultType="java.lang.Integer">
        select min(iRow) from location where warehouseCode=#{warehouseCode} and  locationType = #{locationType}
    </select>
    <select id="getLastRowOfZone" resultType="java.lang.Integer">
        select max(iRow) from location where warehouseCode=#{warehouseCode} and locationType = #{locationType}
    </select>

    <select id="selectlistEnpty" resultType="java.lang.String">
        SELECT a.code from (SELECT * from location where rowFlag=1 and containerCode='' and zoneCode='L' and roadWay =#{roadWay} and high=#{high}) a
                               INNER JOIN (SELECT * from location where rowFlag=0 and (containerCode != '' or `status`='lock') and zoneCode='L' and roadWay =#{roadWay} and high=#{high}) b on a.iColumn=b.iColumn and a.iLayer=b.iLayer
            AND (
                   IF
                       (
                           a.roadway = 1,
                           ( a.IROW = 1 AND b.IROW = 2 )
                               OR ( a.IROW = 4 AND b.IROW = 3 ),
                           ( a.IROW = 5 AND b.IROW = 6 )
                               OR ( a.IROW = 8 AND b.IROW = 7 )
                       )
                   )
    </select>


    <select id="selectCode" resultType="com.huaheng.pc.config.location.domain.Location">
        select l.* from location l inner join task_header t on t.status !=100 and l.roadWay=#{roadWay} and high=#{high} and l.zoneCode='L' and l.rowFlag=1 and (t.fromLocation = l.code or t.toLocation =l.code)
    </select>

    <select id="selectModelByHg" resultType="com.huaheng.pc.config.location.domain.Location">
        select * from location where locationType='L' and containerCode ='' and status='empty'
        and roadWay = #{roadWay} and high=#{heght}
        order by rowFlag desc,iLayer asc,iColumn asc limit 1

    </select>


    <select id="selectModelByOld" resultType="com.huaheng.pc.config.location.domain.Location">
        select * from location where locationType='L' and containerCode ='' and status='empty'
        and roadWay = #{roadWay} and high=#{heght}
        and code not in
        <foreach item="item" index="index" collection="codes" open="(" separator="," close=")">
            #{item}
        </foreach>
        order by rowFlag desc,iLayer asc,iColumn asc limit 1
    </select>

</mapper>