MaterialsMapperEx.xml 7.9 KB
Newer Older
苗卫卫 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
<?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.boco.nbd.wios.manage.mapper.extdb.MaterialsMapperEx" >

  <insert id="insertMaterials" >
    INSERT INTO t_materials (id, appkey, materials_name, materials_code, regular_model, status, unit, type, description,create_time,create_account,modify_account,modify_time)
    values
    <foreach collection="materialsList" item="item" index="index"
             separator=",">
      (#{item.id},#{item.appkey},#{item.materialsName},#{item.materialsCode},#{item.regularModel},#{item.status},#{item.unit},#{item.type},'',#{item.createTime},#{item.createAccount},#{item.modifyAccount},#{item.modifyTime})
    </foreach>
	ON DUPLICATE KEY UPDATE
        materials_name = values(materials_name),materials_code = values(materials_code),regular_model = values(regular_model),unit = values(unit),modify_account = values(modify_account),modify_time = now(),type = values(type)
  </insert>


    <select id="qryMaterialsList" resultType="com.boco.nbd.wios.manage.entity.bo.MaterialsEx">
        SELECT
            tm.id,
            tm.materials_name,
            tm.materials_code,
            tm.regular_model,
            tm.unit,
            tm.type,
            tm.description
    FROM
        t_materials tm
        LEFT JOIN t_warehouse_materials twm ON tm.id = twm.materials_id
        where tm.status = 1
        and tm.appkey = #{appkey}
        <if test="materialsName != null and materialsName != ''">
            and tm.materials_name like CONCAT('%',#{materialsName},'%')
        </if>
        <if test="materialsCode != null and materialsCode != ''">
            and tm.materials_code like CONCAT('%',#{materialsCode},'%')
        </if>
        <if test="regularModel != null and regularModel != '' ">
            and tm.regular_model like CONCAT('%',#{regularModel},'%')
        </if>
        <if test="type != null">
            and tm.type = #{type}
        </if>
        <if test="id != null and id != ''">
            and tm.id = #{id}
        </if>
        <if test="typesList != null and typesList.size() > 0">
            and tm.type in
            <foreach collection="typesList" item="item" index="index"
                     open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="warehouseIds != null and warehouseIds.size() > 0">
            and twm.warehouse_id in
            <foreach collection="warehouseIds" item="item" index="index"
                     open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        group by tm.id order by tm.create_time desc
    </select>



    <select id="qryMaterialsStockList" resultType="com.boco.nbd.wios.manage.entity.bo.MaterialsEx">
        SELECT
        tm.id,
        tm.materials_name,
        tm.materials_code,
        tm.regular_model,
        tm.unit,
        tm.type,
        tm.description,
        twm.warehouse_id,
        tw.name warehouseName,
        twm.total_number totalNumber,
        twm.has_number hasNumber,
        twm.remaining_number remainingNumber,
        twm.stay_with_number stayWithNumber
        FROM
        t_materials tm
        LEFT JOIN t_warehouse_materials twm ON tm.id = twm.materials_id
        LEFT JOIN t_warehouse tw on tw.id = twm.warehouse_id
        where tm.status = 1
        and tm.appkey = #{appkey}
        <if test="materialsName != null and materialsName != ''">
            and tm.materials_name like CONCAT('%',#{materialsName},'%')
        </if>
        <if test="materialsCode != null and materialsCode != ''">
            and tm.materials_code like CONCAT('%',#{materialsCode},'%')
        </if>
        <if test="regularModel != null and regularModel != '' ">
            and tm.regular_model like CONCAT('%',#{regularModel},'%')
        </if>
        <if test="type != null">
            and tm.type = #{type}
        </if>
        <if test="warehouseIds != null and warehouseIds.size() > 0">
            and twm.warehouse_id in
            <foreach collection="warehouseIds" item="item" index="index"
                     open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="id != null and id != ''">
            and tm.id = #{id}
        </if>
        <if test="typesList != null and typesList.size() > 0">
            and tm.type in
            <foreach collection="typesList" item="item" index="index"
                     open="(" close=")" separator=",">
                #{item}
            </foreach>
        </if>
        <if test="isBindWareHouse != null and isBindWareHouse == 1">
            and tw.name is not null
        </if>
        group by tw.id,tm.id order by tm.create_time desc
    </select>


    <select id="qryMaterialsCount" resultType="com.boco.nbd.wios.manage.entity.bo.MaterialsEx">
        SELECT
            tm.id,
            tm.materials_name,
            tm.materials_code,
            tm.regular_model,
            tm.unit,
            tm.type,
            tm.description
        FROM
            t_materials tm
        where tm.status = 1
            and tm.appkey = #{appkey}
        <if test="materialsName != null and materialsName != ''">
            and tm.materials_name = #{materialsName}
        </if>
        <if test="materialsCode != null and materialsCode != ''">
            and tm.materials_code = #{materialsCode}
        </if>
        <if test="regularModel != null and regularModel != '' ">
            and tm.regular_model = #{regularModel}
        </if>
        <if test="type != null">
            and tm.type = #{type}
        </if>
    </select>

  <update id="delMaterialsById">
    update
        t_materials
    set
        status = 0
    where
        id = #{materialsId}
  </update>

    <select id="getWarehouseMaterials" parameterType="string" resultType="com.boco.nbd.wios.manage.entity.bo.WarehouseMaterials">
        SELECT
            warehouse_id,
            materials_id,
            total_number,
            has_number,
            remaining_number,
            stay_with_number
        FROM
            t_warehouse_materials
        WHERE
            1=1
            <if test="materialsId != null and materialsId != ''">
                and warehouse_id = #{warehouseId}
            </if>
            <if test="warehouseId != null and warehouseId != ''">
                AND materials_id = #{materialsId}
            </if>
    </select>

    <update id="updateWarehouseMaterials">
        UPDATE t_warehouse_materials
        SET
            <if test="type != null and type == 3">
                stay_with_number = stay_with_number - #{quantity},
                has_number = has_number + #{quantity}
            </if>
            <if test="type != null and type != 3">
                remaining_number = remaining_number - #{quantity},
                has_number = has_number + #{quantity}
            </if>
        WHERE
            warehouse_id = #{warhouseId}
            AND materials_id = #{materialsId}
    </update>


    <insert id="insertWarehouseMaterials">
        insert into t_warehouse_materials
        ( warehouse_id,materials_id,total_number,has_number,remaining_number)
        values
            (#{warehouseId},#{materialsId},#{totalNumber},#{hasNumber},#{remainingNumber})
        ON DUPLICATE KEY UPDATE total_number = total_number + values(total_number),remaining_number = remaining_number + values(remaining_number)
    </insert>

    <select id="selectMaterialsCode" parameterType="String" resultType="String">
        SELECT
            t_materials.materials_code
        FROM
            t_materials
        WHERE
            t_materials.id=#{id}
    </select>


    <select id="selectIdForPrice" parameterType="String" resultType="String">
        SELECT
            tm.id
        FROM
           t_materials tm
        where tm.status = 1 AND
            tm.materials_code=#{materialsCode}
    </select>



</mapper>