Files
nanguangszwlback/mhd_wms/src/main/resources/mapper/materialBaseInfo/MaterialBaseInfoMapper.xml
T
2026-08-18 16:35:33 +08:00

338 lines
18 KiB
XML

<?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.mhd.wms.domain.materialBaseInfo.repository.mapper.MaterialBaseInfoMapper">
<resultMap type="com.mhd.wms.domain.materialBaseInfo.repository.po.MaterialBaseInfoPO" id="MaterialBaseInfoResult">
<result property="materialBaseInfoId" column="material_base_info_id" />
<result property="organizationId" column="organization_id" />
<result property="organizationName" column="organization_name" />
<result property="topOrganizationId" column="top_organization_id" />
<result property="shipperId" column="shipper_id" />
<result property="shipperCode" column="shipper_code" />
<result property="shipperName" column="shipper_name" />
<result property="materialCode" column="material_code" />
<result property="materialName" column="material_name" />
<result property="barCode" column="bar_code" />
<result property="materialClassifyCode" column="material_classify_code" typeHandler="com.mhd.common.core.handler.ListTypeHandler" />
<result property="materialClassifyName" column="material_classify_name" typeHandler="com.mhd.common.core.handler.ListTypeHandler" />
<result property="materialType" column="material_type" />
<result property="materialTypeName" column="material_type_name" />
<result property="packId" column="pack_id" />
<result property="packCode" column="pack_code" />
<result property="packName" column="pack_name" />
<result property="unitCode" column="unit_code" />
<result property="unitName" column="unit_name" />
<result property="brandId" column="brand_id" />
<result property="brandCode" column="brand_code" />
<result property="brandName" column="brand_name" />
<result property="shelfLife" column="shelf_life" />
<result property="weightLimit" column="weight_limit" />
<result property="volumeLimit" column="volume_limit" />
<result property="materialShape" column="material_shape" />
<result property="materialShapeName" column="material_shape_name" />
<result property="materialSize" column="material_size" />
<result property="materialLength" column="material_length" />
<result property="materialWidth" column="material_width" />
<result property="materialHeight" column="material_height" />
<result property="remark" column="remark" />
<result property="nullify" column="nullify" />
<result property="createTime" column="create_time" />
<result property="createBy" column="create_by" />
<result property="createByName" column="create_by_name" />
<result property="updateTime" column="update_time" />
<result property="updateBy" column="update_by" />
<result property="updateByName" column="update_by_name" />
<result property="delFlag" column="del_flag" />
<result property="unitNumber" column="unit_number" />
<result property="common" column="common" />
<result property="skuCode" column="SKU_CODE" />
<result property="unitPrice" column="UNIT_PRICE" />
<result property="currency" column="CURRENCY" />
<result property="originCountry" column="ORIGIN_COUNTRY" />
<result property="hsCode" column="HS_CODE" />
<result property="declarationUnit" column="DECLARATION_UNIT" />
<result property="statutoryUnit" column="STATUTORY_UNIT" />
<result property="statutorySecondUnit" column="STATUTORY_SECOND_UNIT" />
<result property="specificationModel" column="SPECIFICATION_MODEL" />
<result property="stockQuantity" column="stock_quantity" />
<result property="copyCode" column="copy_code" />
<result property="goodsType" column="goods_type" />
<result property="pushStatus" column="push_status" />
<result property="pushTime" column="push_time" />
<result property="pushBy" column="push_by" />
<result property="grossWeight" column="gross_weight" />
<result property="pushByName" column="push_by_name" />
<result property="unit" column="unit" />
<result property="insureAmount" column="insure_amount" />
<result property="chargeStandard" column="charge_standard" />
<result property="chargeStandardClass" column="charge_standard_class" />
<result property="isNormalMaterial" column="is_normal_material" />
</resultMap>
<sql id="selectMaterialBaseInfoPo">
select a.material_base_info_id, a.organization_id, a.organization_name, a.top_organization_id, a.shipper_id, a.shipper_code, a.shipper_name, a.material_code, a.material_name, a.bar_code, a.material_classify_code,
material_classify_name, a.material_type, a.material_type_name, a.pack_id, a.pack_code, a.pack_name, a.unit_code, a.unit_name, a.brand_id, a.brand_code, a.brand_name, a.shelf_life, a.weight_limit, a.volume_limit, a.material_shape,
material_shape_name, a.material_size, a.material_length, a.material_width, a.material_height, a.remark, a.nullify, a.create_time, a.create_by, a.create_by_name, a.update_time, a.update_by, a.update_by_name, a.del_flag, a.common,
sku_code, a.unit_price, a.currency, a.origin_country, a.hs_code, a.declaration_unit, a.statutory_unit, a.statutory_second_unit, a.copy_code,
a.push_status,a.push_time,a.push_by,a.goods_type,a.gross_weight,a.push_by_name,a.unit,a.INSURE_AMOUNT,a.CHARGE_STANDARD,
specification_model as specification_model,nvl(b.stock_qty,0) as stock_quantity,c.charge_standard as charge_standard_class,a.is_normal_material
from material_base_info a left join (
select material_base_info_id, sum(INVENTORY_QUANTITY) as stock_qty from MATERIAL_INVENTORY group by material_base_info_id
) b on a.material_base_info_id = b.material_base_info_id left join "NGWL_TEST_SYSTEM"."MATERIAL_CLASSIFY" c on a.MATERIAL_CLASSIFY_CODE = c. CODE
</sql>
<sql id="JoinMaterialBaseInfoPo">
<!-- 注意:物料基础信息表中的货主字段统一使用别名,避免与主表中的 shipper_id/shipper_code/shipper_name 冲突 -->
,b.shipper_id AS base_shipper_id,
b.shipper_code AS base_shipper_code,
b.shipper_name AS base_shipper_name,
b.material_code,
b.material_name,
b.bar_code,
b.material_classify_code,
b.material_classify_name,
b.material_type,
b.material_type_name,
b.common,
b.pack_id,
b.pack_code,
b.SPECIFICATION_MODEL,
b.pack_name
</sql>
<sql id="selectMaterialBaseInfoPo1">
<where>
<if test="organizationId != null ">
and a.organization_id like concat('%', #{organizationId}, '%')
</if>
<if test="orgId != null and orgId != '' ">
and (a.org_id like concat('%', #{orgId}, '%') or a.organization_id like concat('%', #{orgId}, '%'))
</if>
<if test="materialBaseInfoId != null and materialBaseInfoId != ''">
and a.material_base_info_id = #{materialBaseInfoId}
</if>
<if test="organizationName != null and organizationName != ''">
and a.organization_name like concat('%', #{organizationName}, '%')
</if>
<if test="topOrganizationId != null ">
and a.top_organization_id = #{topOrganizationId}
</if>
<if test="shipperId != null ">
and (a.shipper_id = #{shipperId} or a.shipper_id is null or a.shipper_id = 0)
</if>
<if test="shipperCode != null and shipperCode != ''">
and a.shipper_code like concat('%', #{shipperCode}, '%')
</if>
<if test="shipperName != null and shipperName != ''">
and a.shipper_name like concat('%', #{shipperName}, '%')
</if>
<if test="materialCode != null and materialCode != ''">
and a.material_code like concat('%', #{materialCode}, '%')
</if>
<if test="materialName != null and materialName != ''">
and a.material_name like concat('%', #{materialName}, '%')
</if>
<if test="unitName != null and unitName != ''">
and a.unit_name like concat('%', #{unitName}, '%')
</if>
<if test="barCode != null and barCode != ''">
and a.bar_code like concat('%',#{barCode},'%')
</if>
<if test="materialClassifyCode != null and materialClassifyCode.size() > 0">
<foreach collection="materialClassifyCode" item="code" open="and (" separator="or" close=")">
FIND_IN_SET(#{code}, a.material_classify_code) > 0
</foreach>
</if>
<if test="materialClassifyName != null and materialClassifyName.size() > 0">
<foreach collection="materialClassifyName" item="name" open="and (" separator="or" close=")">
a.material_classify_name like concat('%', #{name}, '%')
</foreach>
</if>
<if test="materialType != null and materialType != ''">
and a.material_type = #{materialType}
</if>
<if test="materialTypeName != null and materialTypeName != ''">
and a.material_type_name like concat('%', #{materialTypeName}, '%')
</if>
<if test="packId != null ">
and a.pack_id = #{packId}
</if>
<if test="packCode != null and packCode != ''">
and a.pack_code = #{packCode}
</if>
<if test="packName != null and packName != ''">
and a.pack_name like concat('%', #{packName}, '%')
</if>
<if test="brandId != null ">
and a.brand_id = #{brandId}
</if>
<if test="brandCode != null and brandCode != ''">
and a.brand_code = #{brandCode}
</if>
<if test="brandName != null and brandName != ''">
and a.brand_name like concat('%', #{brandName}, '%')
</if>
<if test="shelfLife != null ">
and a.shelf_life = #{shelfLife}
</if>
<if test="weightLimit != null ">
and a.weight_limit = #{weightLimit}
</if>
<if test="volumeLimit != null ">
and a.volume_limit = #{volumeLimit}
</if>
<if test="materialShape != null and materialShape != ''">
and a.material_shape = #{materialShape}
</if>
<if test="materialShapeName != null and materialShapeName != ''">
and a.material_shape_name like concat('%', #{materialShapeName}, '%')
</if>
<if test="materialSize != null and materialSize != ''">
and a.material_size = #{materialSize}
</if>
<if test="materialLength != null ">
and a.material_length = #{materialLength}
</if>
<if test="materialWidth != null ">
and a.material_width = #{materialWidth}
</if>
<if test="materialHeight != null ">
and a.material_height = #{materialHeight}
</if>
<if test="nullify != null ">
and a.nullify = #{nullify}
</if>
<if test="createByName != null and createByName != ''">
and a.create_by_name like concat('%', #{createByName}, '%')
</if>
<if test="updateByName != null and updateByName != ''">
and a.update_by_name like concat('%', #{updateByName}, '%')
</if>
<if test="compoundOrQuery != null and compoundOrQuery != ''">
and ( instr(a.material_name, #{compoundOrQuery}) > 0
or
instr(a.material_code, #{compoundOrQuery}) > 0
or
instr(a.bar_code, #{compoundOrQuery}) > 0
)
</if>
<if test="batchId != null">
and exists (
select 1 from material_goods_rule mgr
where mgr.material_base_info_id = material_base_info.material_base_info_id
and mgr.batch_id = #{batchId}
and mgr.del_flag = 1
)
</if>
<if test="pushStatus != null">
and a.push_status = #{pushStatus}
</if>
<if test="pushTimeStart != null and pushTimeStart != ''">
and date_format(a.push_time,'%Y-%m-%d') &gt;= #{pushTimeStart}
</if>
<if test="pushTimeEnd != null and pushTimeEnd != ''">
and date_format(a.push_time,'%Y-%m-%d') &lt;= #{pushTimeEnd}
</if>
<if test="createTimeStart != null and createTimeStart != ''">
and date_format(a.create_time,'%Y-%m-%d') &gt;= #{createTimeStart}
</if>
<if test="createTimeEnd != null and createTimeEnd != ''">
and date_format(a.create_time,'%Y-%m-%d') &lt;= #{createTimeEnd}
</if>
<if test="updateTimeStart != null and updateTimeStart != ''">
and date_format(a.update_time,'%Y-%m-%d') &gt;= #{updateTimeStart}
</if>
<if test="updateTimeEnd != null and updateTimeEnd != ''">
and date_format(a.update_time,'%Y-%m-%d') &lt;= #{updateTimeEnd}
</if>
<!-- 传 1:只查公共 , 2:只查自己的 ,3:公共的和自己的 -->
<choose>
<when test="common != null and (common == 1 or common == 2) "> and common = #{common} </when>
<otherwise> and (
1 = 1
or common = 1 )</otherwise>
</choose>
<choose>
<when test="delFlag != null"> and a.del_flag = #{delFlag} </when>
<otherwise> and a.del_flag = 1 </otherwise>
</choose>
</where>
</sql>
<sql id="JoinMaterialBaseInfoPoWhere">
<!-- 该片段总是在物料基础信息表使用别名 b 时被 include,例如:
FROM ... LEFT JOIN material_base_info b ON ...
因此这里所有列名都加上 b. 前缀以避免和主表列名歧义 -->
<if test="shipperId != null ">
and (b.shipper_id = #{shipperId} or b.shipper_id is null or b.shipper_id = 0)
</if>
<if test="shipperCode != null and shipperCode != ''">
and b.shipper_code like concat('%', #{shipperCode}, '%')
</if>
<if test="shipperName != null and shipperName != ''">
and b.shipper_name like concat('%', #{shipperName}, '%')
</if>
<if test="materialCode != null and materialCode != ''">
and b.material_code = #{materialCode}
</if>
<if test="materialName != null and materialName != ''">
and b.material_name like concat('%', #{materialName}, '%')
</if>
<if test="barCode != null and barCode != ''">
and b.bar_code = #{barCode}
</if>
<if test="materialClassifyCode != null and materialClassifyCode.size() > 0">
<foreach collection="materialClassifyCode" item="code" open="and (" separator="or" close=")">
FIND_IN_SET(#{code}, b.material_classify_code) > 0
</foreach>
</if>
<if test="materialClassifyName != null and materialClassifyName.size() > 0">
<foreach collection="materialClassifyName" item="name" open="and (" separator="or" close=")">
b.material_classify_name like concat('%', #{name}, '%')
</foreach>
</if>
<if test="materialType != null and materialType != ''">
and b.material_type = #{materialType}
</if>
<if test="materialTypeName != null and materialTypeName != ''">
and b.material_type_name like concat('%', #{materialTypeName}, '%')
</if>
<if test="shipperInfo != null and shipperInfo != ''">
and (b.shipper_code like concat('%', #{shipperInfo}, '%') or b.shipper_name like concat('%', #{shipperInfo}, '%'))
</if>
<if test="materialInfo != null and materialInfo != ''">
and (b.material_code = #{materialInfo} or b.material_name like concat('%', #{materialInfo}, '%') or b.bar_code = #{materialInfo})
</if>
</sql>
<select id="queryList" parameterType="com.mhd.wms.domain.materialBaseInfo.repository.todo.MaterialBaseInfoDO" resultMap="MaterialBaseInfoResult">
<include refid="selectMaterialBaseInfoPo"/>
<include refid="selectMaterialBaseInfoPo1"/>
order by create_time desc
</select>
<select id="selectOneByID" parameterType="java.lang.Long" resultMap="MaterialBaseInfoResult">
select material_code, material_name, pack_id, pack_code, pack_name, unit_code, unit_name, shipper_id, shipper_name, shipper_code, bar_code, unit_number from material_base_info
where material_base_info_id = #{materialBaseInfoId}
</select>
<select id="selectBatchByIds" resultType="com.mhd.wms.domain.materialBaseInfo.repository.po.MaterialBaseInfoPO">
select * from material_base_info
where material_base_info_id in
<foreach collection="materialBaseInfoIds" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</select>
<select id="getCustomerCodeNcJson" parameterType="java.lang.String" resultType="java.lang.String">
SELECT ORG_CODE FROM NGWL_TEST_USER."USER_SHIPPER" where del_flag = 1 and USER_ID = #{actualInvoiceCustomerId} limit 1
</select>
</mapper>