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.

239 lines
13 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.op.device.mapper.EquSpareApplyMapper">
<resultMap type="EquSpareApply" id="EquSpareApplyResult">
<result property="applyId" column="apply_id"/>
<result property="applyCode" column="apply_code"/>
<result property="workCode" column="work_code"/>
<result property="parentCode" column="parent_code"/>
<result property="spareCode" column="spare_code"/>
<result property="applyType" column="apply_type"/>
<result property="spareName" column="spare_name"/>
<result property="spareModel" column="spare_model"/>
<result property="spareQuantity" column="spare_quantity"/>
<result property="spareGroupLine" column="spare_group_line"/>
<result property="spareUseEquipment" column="spare_use_equipment"/>
<result property="applyTime" column="apply_time"/>
<result property="applyPeople" column="apply_people"/>
<result property="applyApprovePeople" column="apply_approve_people"/>
<result property="attr1" column="attr1"/>
<result property="attr2" column="attr2"/>
<result property="attr3" column="attr3"/>
<result property="delFlag" column="del_flag"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by"/>
<result property="updateTime" column="update_time"/>
<result property="factoryCode" column="factory_code"/>
<result property="unitPrice" column="unit_price"/>
<result property="totalPrice" column="total_price"/>
</resultMap>
<sql id="selectEquSpareApplyVo">
select apply_id, apply_code, work_code,parent_code,apply_type,spare_code, spare_name, spare_model, spare_quantity, spare_group_line, spare_use_equipment, apply_time, apply_people, apply_approve_people, attr1, attr2, attr3, del_flag, create_by, create_time, update_by, update_time, factory_code , unit_price , total_price from equ_spare_apply
</sql>
<select id="selectEquSpareApplyList" parameterType="EquSpareApply" resultMap="EquSpareApplyResult">
<include refid="selectEquSpareApplyVo"/>
<where>
<if test="applyCode != null and applyCode != ''">and apply_code like concat('%', #{applyCode}, '%')</if>
<if test="workCode != null and workCode != ''">and work_code like concat('%', #{workCode}, '%')</if>
<if test="parentCode != null and parentCode != ''">and parent_code like concat('%', #{parentCode}, '%')</if>
<if test="applyType != null and applyType != ''">and apply_type like concat('%', #{applytype}, '%')</if>
<if test="spareCode != null and spareCode != ''">and spare_code like concat('%', #{spareCode}, '%')</if>
<if test="spareName != null and spareName != ''">and spare_name like concat('%', #{spareName}, '%')</if>
<if test="spareModel != null and spareModel != ''">and spare_model like concat('%', #{spareModel}, '%')</if>
<if test="spareQuantity != null ">and spare_quantity like concat('%', #{spareQuantity}, '%')</if>
<if test="spareGroupLine != null and spareGroupLine != ''">and spare_group_line like concat('%',#{spareGroupLine}, '%')</if>
<if test="spareUseEquipment != null and spareUseEquipment != ''">and spare_use_equipment like concat('%',#{spareUseEquipment}, '%')</if>
<if test="applyTimeStart != null ">and CONVERT(date,apply_time) >= #{applyTimeStart}</if>
<if test="applyTimeEnd != null ">and #{applyTimeEnd} >= CONVERT(date,apply_time)</if>
<if test="applyPeople != null and applyPeople != ''">and apply_people like concat('%', #{applyPeople},'%')</if>
<if test="applyApprovePeople != null and applyApprovePeople != ''">and apply_approve_people likeconcat('%', #{applyApprovePeople}, '%')</if>
<if test="attr1 != null and attr1 != ''">and attr1 = #{attr1}</if>
<if test="attr2 != null and attr2 != ''">and attr2 = #{attr2}</if>
<if test="attr3 != null and attr3 != ''">and attr3 = #{attr3}</if>
<if test="factoryCode != null and factoryCode != ''">and factory_code = #{factoryCode}</if>
<if test="unitPrice != null and unitPrice != ''">and unit_price = #{unitPrice}</if>
<if test="totalPrice != null and totalPrice != ''">and total_price = #{totalPrice}</if>
and del_flag = '0'
ORDER BY apply_time DESC
</where>
</select>
<select id="selectEquSpareApplyByApplyId" parameterType="String" resultMap="EquSpareApplyResult">
<include refid="selectEquSpareApplyVo"/>
where apply_id = #{applyId}
and del_flag = '0'
</select>
<insert id="insertEquSpareApply" parameterType="EquSpareApply">
insert into equ_spare_apply
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="applyId != null">apply_id,</if>
<if test="applyCode != null">apply_code,</if>
<if test="workCode != null">work_code,</if>
<if test="parentCode != null">parent_code,</if>
<if test="applyType != null">apply_type,</if>
<if test="spareCode != null">spare_code,</if>
<if test="spareName != null">spare_name,</if>
<if test="spareModel != null">spare_model,</if>
<if test="spareQuantity != null">spare_quantity,</if>
<if test="spareGroupLine != null">spare_group_line,</if>
<if test="spareUseEquipment != null">spare_use_equipment,</if>
<if test="applyTime != null">apply_time,</if>
<if test="applyPeople != null">apply_people,</if>
<if test="applyApprovePeople != null">apply_approve_people,</if>
<if test="attr1 != null">attr1,</if>
<if test="attr2 != null">attr2,</if>
<if test="attr3 != null">attr3,</if>
<if test="delFlag != null">del_flag,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
<if test="factoryCode != null">factory_code,</if>
<if test="unitPrice != null">unit_price,</if>
<if test="totalPrice != null">total_price,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="applyId != null">#{applyId},</if>
<if test="applyCode != null">#{applyCode},</if>
<if test="workCode != null">#{workCode},</if>
<if test="parentCode != null">#{parentCode},</if>
<if test="applyType != null">#{applyType},</if>
<if test="spareCode != null">#{spareCode},</if>
<if test="spareName != null">#{spareName},</if>
<if test="spareModel != null">#{spareModel},</if>
<if test="spareQuantity != null">#{spareQuantity},</if>
<if test="spareGroupLine != null">#{spareGroupLine},</if>
<if test="spareUseEquipment != null">#{spareUseEquipment},</if>
<if test="applyTime != null">#{applyTime},</if>
<if test="applyPeople != null">#{applyPeople},</if>
<if test="applyApprovePeople != null">#{applyApprovePeople},</if>
<if test="attr1 != null">#{attr1},</if>
<if test="attr2 != null">#{attr2},</if>
<if test="attr3 != null">#{attr3},</if>
<if test="delFlag != null">#{delFlag},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="factoryCode != null">#{factoryCode},</if>
<if test="unitPrice != null">#{unitPrice},</if>
<if test="totalPrice != null">#{totalPrice},</if>
</trim>
</insert>
<update id="updateEquSpareApply" parameterType="EquSpareApply">
update equ_spare_apply
<trim prefix="SET" suffixOverrides=",">
<if test="applyCode != null">apply_code = #{applyCode},</if>
<if test="workCode != null">work_code = #{workCode},</if>
<if test="parentCode != null">parent_code = #{parentCode},</if>
<if test="applyType != null">apply_type = #{applyType},</if>
<if test="spareCode != null">spare_code = #{spareCode},</if>
<if test="spareName != null">spare_name = #{spareName},</if>
<if test="spareModel != null">spare_model = #{spareModel},</if>
<if test="spareQuantity != null">spare_quantity = #{spareQuantity},</if>
<if test="spareGroupLine != null">spare_group_line = #{spareGroupLine},</if>
<if test="spareUseEquipment != null">spare_use_equipment = #{spareUseEquipment},</if>
<if test="applyTime != null">apply_time = #{applyTime},</if>
<if test="applyPeople != null">apply_people = #{applyPeople},</if>
<if test="applyApprovePeople != null">apply_approve_people = #{applyApprovePeople},</if>
<if test="attr1 != null">attr1 = #{attr1},</if>
<if test="attr2 != null">attr2 = #{attr2},</if>
<if test="attr3 != null">attr3 = #{attr3},</if>
<if test="delFlag != null">del_flag = #{delFlag},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="factoryCode != null">factory_code = #{factoryCode},</if>
<if test="unitPrice != null">unit_price = #{unitPrice},</if>
<if test="totalPrice != null">total_price = #{totalPrice},</if>
</trim>
where apply_id = #{applyId}
</update>
<!--物理删除改为逻辑删除-->
<delete id="deleteEquSpareApplyByApplyId" parameterType="String">
update equ_spare_apply
set del_flag = '1'
where apply_id = #{applyId}
</delete>
<!--物理删除改为逻辑删除-->
<delete id="deleteEquSpareApplyByApplyIds" parameterType="String">
update equ_spare_apply
set del_flag = '1'
where apply_id in
<foreach item="applyId" collection="array" open="(" separator="," close=")">
#{applyId}
</foreach>
</delete>
<delete id="delEquSpareApplyByorderIds" parameterType="String">
update equ_spare_apply set del_flag = '1' where del_flag = '0' and work_code in ( select order_code from
equ_order where del_flag = '0' and order_id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
)
</delete>
<delete id="delEquSpareApplyByIds" parameterType="String">
update equ_spare_apply set del_flag = '1'
where apply_id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<delete id="delEquSpareApplyByApplyId" parameterType="String">
update equ_spare_apply set del_flag = '1' where apply_id = #{id}
</delete>
<select id="selectRepairSparePartsRecord2" parameterType="EquRepairWorkOrder" resultMap="EquSpareApplyResult">
<include refid="selectEquSpareApplyVo"/>
<where>
<if test="workCode != null and workCode != ''">and work_code = #{workCode}</if>
<if test="equipmentCode != null and equipmentCode != ''">and spare_use_equipment = #{equipmentCode}</if>
and del_flag = '0'
and CONVERT(varchar(10),#{createTime},120) = CONVERT(date,create_time)
</where>
ORDER BY apply_time DESC
</select>
<select id="selectRepairSparePartsRecord" parameterType="EquRepairWorkOrder" resultMap="EquSpareApplyResult">
<include refid="selectEquSpareApplyVo"/>
<where>
<if test="workCode != null and workCode != ''">and work_code = #{workCode}</if>
and del_flag = '0'
</where>
ORDER BY apply_time DESC
</select>
<select id="selectSerialNumber" resultType="java.lang.Integer">
SELECT COUNT(apply_id)+1 AS serialNum
FROM equ_spare_apply
WHERE CONVERT(date, GETDATE()) = CONVERT(date,create_time)
</select>
<select id="selectEquSpareApplyListByWorkCode" parameterType="String" resultMap="EquSpareApplyResult">
<include refid="selectEquSpareApplyVo"/>
where work_code = #{orderCode} and del_flag = '0'
</select>
<select id="getSparePartsCost" resultType="java.math.BigDecimal">
select SUM(a.spare_quantity * w.unit_price)
from equ_spare_apply a
left join wms_ods_mate_storage_news_attached w on a.spare_code = w.primary_code
where a.work_code = #{orderCode}
</select>
</mapper>