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.
HwMes/hw-modules/hw-mes/src/main/resources/mapper/mes/MesMaterialCheckResultMappe...

137 lines
7.4 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.hw.mes.mapper.MesMaterialCheckResultMapper">
<resultMap type="MesMaterialCheckResult" id="MesMaterialCheckResultResult">
<result property="materialCheckResultId" column="material_check_result_id" />
<result property="planId" column="plan_id" />
<result property="planDetailId" column="plan_detail_id" />
<result property="materialId" column="material_id" />
<result property="standardAmount" column="standard_amount" />
<result property="checkAmount" column="check_amount" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="checkType" column="check_type" />
</resultMap>
<sql id="selectMesMaterialCheckResultVo">
select material_check_result_id, plan_id, plan_detail_id, material_id, standard_amount, check_amount, update_by, update_time from mes_material_check_result
</sql>
<select id="selectMesMaterialCheckResultList" parameterType="MesMaterialCheckResult" resultMap="MesMaterialCheckResultResult">
<include refid="selectMesMaterialCheckResultVo"/>
<where>
<if test="planId != null "> and plan_id = #{planId}</if>
<if test="planDetailId != null "> and plan_detail_id = #{planDetailId}</if>
<if test="materialId != null "> and material_id = #{materialId}</if>
<if test="standardAmount != null "> and standard_amount = #{standardAmount}</if>
<if test="checkAmount != null "> and check_amount = #{checkAmount}</if>
</where>
</select>
<select id="selectMesMaterialCheckResultByMaterialCheckResultId" parameterType="Long" resultMap="MesMaterialCheckResultResult">
<include refid="selectMesMaterialCheckResultVo"/>
where material_check_result_id = #{materialCheckResultId}
</select>
<insert id="insertMesMaterialCheckResult" parameterType="MesMaterialCheckResult" useGeneratedKeys="true" keyProperty="materialCheckResultId">
insert into mes_material_check_result
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="planId != null">plan_id,</if>
<if test="planDetailId != null">plan_detail_id,</if>
<if test="materialId != null">material_id,</if>
<if test="standardAmount != null">standard_amount,</if>
<if test="checkAmount != null">check_amount,</if>
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="planId != null">#{planId},</if>
<if test="planDetailId != null">#{planDetailId},</if>
<if test="materialId != null">#{materialId},</if>
<if test="standardAmount != null">#{standardAmount},</if>
<if test="checkAmount != null">#{checkAmount},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
</trim>
</insert>
<update id="updateMesMaterialCheckResult" parameterType="MesMaterialCheckResult">
update mes_material_check_result
<trim prefix="SET" suffixOverrides=",">
<if test="planId != null">plan_id = #{planId},</if>
<if test="planDetailId != null">plan_detail_id = #{planDetailId},</if>
<if test="materialId != null">material_id = #{materialId},</if>
<if test="standardAmount != null">standard_amount = #{standardAmount},</if>
<if test="checkAmount != null">check_amount = #{checkAmount},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
</trim>
where material_check_result_id = #{materialCheckResultId}
</update>
<delete id="deleteMesMaterialCheckResultByMaterialCheckResultId" parameterType="Long">
delete from mes_material_check_result where material_check_result_id = #{materialCheckResultId}
</delete>
<delete id="deleteMesMaterialCheckResultByMaterialCheckResultIds" parameterType="String">
delete from mes_material_check_result where material_check_result_id in
<foreach item="materialCheckResultId" collection="array" open="(" separator="," close=")">
#{materialCheckResultId}
</foreach>
</delete>
<select id="selectMesMaterialCheckResultByUI" resultMap="MesMaterialCheckResultResult">
<include refid="selectMesMaterialCheckResultVo"/>
where plan_id = #{planId} and plan_detail_id = #{planDetailId} and material_id = #{materialId} limit 1
</select>
<select id="selectMesMaterialCheckResult" resultMap="MesMaterialCheckResultResult">
SELECT mmb.standard_amount,mmcr.check_amount,mmb.check_type FROM `mes_material_check_result` mmcr
right join mes_material_bom mmb on mmb.material_id=mmcr.material_id
where mmb.ancestors like concat(#{ancestors}, '%') and mmcr.plan_id = #{planId} and mmcr.plan_detail_id = #{planDetailId}
</select>
<select id="selectMaterialInstallationCircumstance" resultType="java.util.HashMap" parameterType="java.util.HashMap">
select mmcr.material_check_result_id materialCheckResultId,
mmcr.plan_id planId,
mmcr.plan_detail_id planDetailId,
mmcr.material_id materialId,
mmcr.standard_amount standardAmount,
mmcr.check_amount checkAmount,
mbmi.material_code materialCode,
mbmi.material_name materialName
from mes_material_check_result mmcr
left join mes_product_plan mpp on mpp.plan_id = mmcr.plan_id
left join mes_product_plan_detail mppd on mppd.plan_detail_id = mmcr.plan_detail_id
left join mes_base_material_info mbmi on mbmi.material_id = mmcr.material_id
<where>
<if test="planId != null "> and mmcr.plan_id = #{planId}</if>
<if test="planDetailId != null "> and mmcr.plan_detail_id = #{planDetailId}</if>
</where>
</select>
<select id="selectMaterialUnInstallationCircumstance" resultType="java.util.HashMap" parameterType="java.util.HashMap">
select sd.materialId, sd.materialCode, sd.materialName, needAmount
from (
select mbmi.material_id materialId,
mbmi.material_code materialCode,
mbmi.material_name materialName,
mmb.standard_amount standardAmount,
ifnull(mmcr.check_amount, 0) checkAmount,
mmb.standard_amount - ifnull(mmcr.check_amount, 0) needAmount
from mes_material_bom mmb
left join mes_base_material_info mbmi on mmb.material_id = mbmi.material_id
left join mes_material_check_result mmcr on plan_detail_id = #{planDetailId} and mbmi.material_id = mmcr.material_id
where mmb.ancestors like concat('%', concat(#{materialBomId}, '%'))
) sd
where sd.needAmount > 0
</select>
</mapper>