You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

210 lines
11 KiB
XML

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?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.aucma.base.mapper.OrderBomInfoMapper">
<resultMap type="OrderBomInfo" id="OrderBomInfoResult">
<result property="objId" column="obj_id"/>
<result property="bomCode" column="bom_code"/>
<result property="materialCode" column="material_code"/>
<result property="materialName" column="material_name"/>
<result property="materialType" column="material_type"/>
<result property="standardAmount" column="standard_amount"/>
<result property="parentId" column="parent_id"/>
<result property="parentObjId" column="parent_obj_id"/>
<result property="isFlag" column="is_flag"/>
<result property="createdBy" column="created_by"/>
<result property="createdTime" column="created_time"/>
<result property="updatedBy" column="updated_by"/>
<result property="updatedTime" column="updated_time"/>
<result property="factoryCode" column="factory_code"/>
<result property="sort" column="sort"/>
<result property="vbeln" column="vbeln"/>
<result property="vbpos" column="vbpos"/>
<result property="ancestors" column="ancestors" />
<result property="parentName" column="parentName" />
<result property="parentMaterialType" column="parentMaterialType" />
</resultMap>
<sql id="selectOrderBomInfoVo">
select ob.obj_id,
ob.bom_code,
ob.material_code,
bm.material_name,
bm.MATERIAL_SUBCLASS material_type,
ob.standard_amount,
ob.parent_id,
ob.parent_obj_id,
mp.MATERIAL_NAME parentName,
mp.MATERIAL_SUBCLASS parentMaterialType,
ob.is_flag,
ob.created_by,
ob.created_time,
ob.updated_by,
ob.updated_time,
ob.factory_code,
ob.sort,
ob.ancestors,
ob.vbeln,
ob.vbpos
from order_bominfo ob
LEFT JOIN BASE_MATERIALINFO bm ON bm.MATERIAL_CODE = ob.material_code
LEFT JOIN BASE_MATERIALINFO mp ON mp.MATERIAL_CODE = ob.PARENT_ID
</sql>
<select id="selectOrderBomInfoList" parameterType="OrderBomInfo" resultMap="OrderBomInfoResult">
<include refid="selectOrderBomInfoVo"/>
<where>
<if test="bomCode != null and bomCode != ''">and ob.bom_code = #{bomCode}</if>
<if test="materialCode != null and materialCode != ''">and ob.material_code like concat(#{materialCode}, '%')</if>
<if test="materialName != null and materialName != ''">and bm.material_name like concat(concat('%',#{materialName}), '%')
</if>
<if test="materialType != null and materialType != ''">and bm.MATERIAL_SUBCLASS = #{materialType}</if>
<if test="standardAmount != null ">and ob.standard_amount = #{standardAmount}</if>
<if test="parentId != null and parentId != ''">and ob.parent_id like concat(#{parentId}, '%')</if>
<if test="parentName != null and parentName != ''">and mp.MATERIAL_NAME like concat(concat('%',#{parentName}), '%')
</if>
<if test="isFlag != null ">and ob.is_flag = #{isFlag}</if>
<if test="createdBy != null and createdBy != ''">and ob.created_by = #{createdBy}</if>
<if test="createdTime != null ">and ob.created_time = #{createdTime}</if>
<if test="updatedBy != null and updatedBy != ''">and ob.updated_by = #{updatedBy}</if>
<if test="updatedTime != null ">and ob.updated_time = #{updatedTime}</if>
<if test="factoryCode != null and factoryCode != ''">and ob.factory_code = #{factoryCode}</if>
<if test="sort != null and sort != ''">and ob.sort = #{sort}</if>
<if test="vbeln != null and vbeln != ''">and ob.vbeln = #{vbeln}</if>
<if test="vbpos != null and vbpos != ''">and ob.vbpos = #{vbpos}</if>
<if test="ancestors != null and ancestors != ''">and ob.ancestors like concat(concat('%', #{ancestors}), '%')</if>
</where>
order by ob.parent_id, ob.sort
</select>
<select id="selectOrderBomInfoByObjId" parameterType="Long" resultMap="OrderBomInfoResult">
<include refid="selectOrderBomInfoVo"/>
where ob.obj_id = #{objId}
</select>
<select id="selectOrderBomInfoByMaterialCode" resultMap="OrderBomInfoResult">
<include refid="selectOrderBomInfoVo"/>
<!-- Oracle 11 在字符串参数为空时不能按 JdbcType.OTHER 绑定,显式声明 VARCHAR 避免 1111 异常 -->
where ob.material_code = #{materialCode,jdbcType=VARCHAR}
</select>
<insert id="insertOrderBomInfo" parameterType="OrderBomInfo">
<selectKey keyProperty="objId" resultType="long" order="BEFORE">
SELECT seq_order_bominfo.NEXTVAL as objId FROM DUAL
</selectKey>
insert into order_bominfo
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="objId != null">obj_id,</if>
<if test="bomCode != null">bom_code,</if>
<if test="materialCode != null">material_code,</if>
<if test="materialName != null">material_name,</if>
<if test="materialType != null">material_type,</if>
<if test="standardAmount != null">standard_amount,</if>
<if test="parentId != null">parent_id,</if>
<if test="parentObjId != null">parent_obj_id,</if>
<if test="isFlag != null">is_flag,</if>
<if test="createdBy != null">created_by,</if>
<if test="createdTime != null">created_time,</if>
<if test="updatedBy != null">updated_by,</if>
<if test="updatedTime != null">updated_time,</if>
<if test="factoryCode != null">factory_code,</if>
<if test="sort != null">sort,</if>
<if test="vbeln != null">vbeln,</if>
<if test="vbpos != null">vbpos,</if>
<if test="ancestors != null">ancestors,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="objId != null">#{objId},</if>
<if test="bomCode != null">#{bomCode},</if>
<if test="materialCode != null">#{materialCode},</if>
<if test="materialName != null">#{materialName,jdbcType=NVARCHAR},</if>
<if test="materialType != null">#{materialType},</if>
<if test="standardAmount != null">#{standardAmount},</if>
<if test="parentId != null">#{parentId},</if>
<if test="parentObjId != null">#{parentObjId},</if>
<if test="isFlag != null">#{isFlag},</if>
<if test="createdBy != null">#{createdBy},</if>
<if test="createdTime != null">#{createdTime},</if>
<if test="updatedBy != null">#{updatedBy},</if>
<if test="updatedTime != null">#{updatedTime},</if>
<if test="factoryCode != null">#{factoryCode},</if>
<if test="sort != null">#{sort},</if>
<if test="vbeln != null">#{vbeln},</if>
<if test="vbpos != null">#{vbpos},</if>
<if test="ancestors != null">#{ancestors},</if>
</trim>
</insert>
<update id="updateOrderBomInfo" parameterType="OrderBomInfo">
update order_bominfo
<trim prefix="SET" suffixOverrides=",">
<if test="bomCode != null">bom_code = #{bomCode},</if>
<if test="materialCode != null">material_code = #{materialCode},</if>
<if test="materialName != null">material_name = #{materialName,jdbcType=NVARCHAR},</if>
<if test="materialType != null">material_type = #{materialType},</if>
<if test="standardAmount != null">standard_amount = #{standardAmount},</if>
<if test="parentId != null">parent_id = #{parentId},</if>
<if test="parentObjId != null">parent_obj_id = #{parentObjId},</if>
<if test="isFlag != null">is_flag = #{isFlag},</if>
<if test="createdBy != null">created_by = #{createdBy},</if>
<if test="createdTime != null">created_time = #{createdTime},</if>
<if test="updatedBy != null">updated_by = #{updatedBy},</if>
<if test="updatedTime != null">updated_time = #{updatedTime},</if>
<if test="factoryCode != null">factory_code = #{factoryCode},</if>
<if test="sort != null">sort = #{sort},</if>
<if test="vbeln != null">vbeln = #{vbeln},</if>
<if test="vbpos != null">vbpos = #{vbpos},</if>
<if test="ancestors != null">ancestors = #{ancestors},</if>
</trim>
where obj_id = #{objId}
</update>
<delete id="deleteOrderBomInfoByObjId" parameterType="Long">
delete
from order_bominfo
where obj_id = #{objId}
</delete>
<delete id="deleteOrderBomInfoByObjIds" parameterType="String">
delete from order_bominfo where obj_id in
<foreach item="objId" collection="array" open="(" separator="," close=")">
#{objId}
</foreach>
</delete>
<select id="selectChildrenBomById" parameterType="String" resultMap="OrderBomInfoResult">
<!-- 这里依赖 materialCode 命名参数;同时显式指定 VARCHAR避免空值传参落到 Oracle OTHER 类型 -->
select * from order_bominfo where INSTR(',' || ancestors || ',', ',' || #{materialCode,jdbcType=VARCHAR} || ',') <![CDATA[ > ]]> 0
</select>
<select id="selectFinishedProductBomInfoList" parameterType="OrderBomInfo" resultMap="OrderBomInfoResult">
select bm.MATERIAL_CODE,
bm.material_name,
bm.MATERIAL_SUBCLASS material_type,
ob.parent_id,
ob.factory_code plant_code
from order_bominfo ob
left join BASE_MATERIALINFO bm ON bm.MATERIAL_CODE = ob.parent_id
<where>
<if test="materialCode != null and materialCode != ''">and ob.parent_id like concat(#{materialCode}, '%')</if>
</where>
group by bm.MATERIAL_CODE,bm.material_name,bm.MATERIAL_SUBCLASS,ob.parent_id,ob.factory_code
</select>
<update id="updateBomChildren" parameterType="java.util.List">
update order_bominfo set ancestors =
<foreach collection="depts" item="item" index="index"
separator=" " open="case material_code" close="end">
when #{item.materialCode} then #{item.ancestors}
</foreach>
where material_code in
<foreach collection="depts" item="item" index="index"
separator="," open="(" close=")">
#{item.materialCode}
</foreach>
</update>
</mapper>