<?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.mes.mapper.MesUnitpriceReportMapper" >
<resultMap type= "MesUnitpriceReport" id= "MesUnitpriceReportResult" >
<result property= "id" column= "id" />
<result property= "workorderCode" column= "workorder_code" />
<result property= "workorderCodeSap" column= "workorder_code_sap" />
<result property= "productName" column= "product_name" />
<result property= "productCode" column= "product_code" />
<result property= "lineCode" column= "line_code" />
<result property= "sapCode" column= "sap_code," />
<result property= "equipmentName" column= "equipment_name" />
<result property= "userName" column= "user_name" />
<result property= "nickName" column= "nick_name" />
<result property= "childprocessCode" column= "childprocess_code" />
<result property= "childprocessName" column= "childprocess_name" />
<result property= "totalQuantity" column= "total_quantity" />
<result property= "headCount" column= "head_count" />
<result property= "avgResult" column= "avg_result" />
<result property= "result" column= "result" />
<result property= "attr1" column= "attr1" />
<result property= "realWages" column= "real_wages" />
<result property= "attr2" column= "attr2" />
<result property= "attr3" column= "attr3" />
<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= "remark" column= "remark" />
</resultMap>
<sql id= "selectMesUnitpriceReportVo" >
select id, workorder_code, workorder_code_sap, product_name, product_code, user_name, nick_name, childprocess_code, childprocess_name, attr1, attr2, attr3, create_by, create_time, update_by, update_time, remark from mes_unitprice_report
</sql>
<select id= "selectMesUnitpriceReportList" parameterType= "MesUnitpriceReport" resultMap= "MesUnitpriceReportResult" >
SELECT
mur.id,
mur.workorder_code,
mur.workorder_code_sap,
mur.product_code,
mur.product_name,
mur.line_code,
mur.attr1 AS real_wages,
mur.remark,
be.sap_name as equipment_name,
mur.nick_name,
mur.childprocess_code,
mup.childprocess_name,
mrw.total_quantity,
mup.attr1,
CAST(CAST(mrw.total_quantity AS DECIMAL(18,2)) * CAST(mup.attr1 AS DECIMAL(18,5)) AS DECIMAL(18, 6)) AS result,
COUNT(*) OVER (PARTITION BY mur.workorder_code_sap, mur.childprocess_code) AS head_count,
ROUND(
CAST (
CAST(CAST(mrw.total_quantity AS DECIMAL(18,2)) * CAST(mup.attr1 AS DECIMAL(18,5)) AS DECIMAL(18, 6)) / NULLIF ( COUNT ( * ) OVER ( PARTITION BY mur.workorder_code_sap, mur.childprocess_code ), 0 ) AS DECIMAL ( 18, 4 )
),
4
) AS avg_result
FROM
mes_unitprice_report mur
LEFT JOIN
mes_unit_price mup ON RIGHT(mur.product_code, 11) = mup.product_code AND mur.childprocess_code = mup.childprocess_code
LEFT JOIN base_equipment be ON be.sap_code=mur.line_code
LEFT JOIN ( SELECT parent_order, SUM ( quantity ) AS total_quantity FROM mes_report_work GROUP BY parent_order ) mrw ON mur.workorder_code = mrw.parent_order
<where >
<if test= "workorderCode != null and workorderCode != ''" > and workorder_code = #{workorderCode}</if>
<if test= "workorderCodeSap != null and workorderCodeSap != ''" > and mur.workorder_code_sap =
#{workorderCodeSap}
</if>
<if test= "productName != null and productName != ''" > and mur.product_name like concat('%', #{productName},
'%')
</if>
<if test= "productCode != null and productCode != ''" > and mur.product_code like concat('%', #{productCode},
'%')
</if>
<if test= "userName != null and userName != ''" > and user_name like concat('%', #{userName}, '%')</if>
<if test= "nickName != null and nickName != ''" > and nick_name like concat('%', #{nickName}, '%')</if>
<if test= "childprocessCode != null and childprocessCode != ''" > and childprocess_code =
#{childprocessCode}
</if>
<if test= "childprocessName != null and childprocessName != ''" > and childprocess_name like concat('%',
#{childprocessName}, '%')
</if>
<if test= "lineCode != null and lineCode != ''" > and mur.line_code like concat('%',
#{lineCode}, '%')
</if>
<if test= "equipmentName != null and equipmentName != ''" > and be.equipment_name like concat('%',
#{equipmentName}, '%')
</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>
</where>
GROUP BY
mur.id,
mur.workorder_code,
mur.workorder_code_sap,
mur.product_code,
mur.product_name,
mur.attr1,
mur.line_code,
mur.remark,
be.sap_name,
mur.nick_name,
mur.childprocess_code,
mup.childprocess_name,
mrw.total_quantity,
mup.attr1;
</select>
<select id= "selectMesUnitpriceReportById" parameterType= "String" resultMap= "MesUnitpriceReportResult" >
<include refid= "selectMesUnitpriceReportVo" />
where id = #{id}
</select>
<insert id= "insertMesUnitpriceReport" parameterType= "MesUnitpriceReport" >
insert into mes_unitprice_report
<trim prefix= "(" suffix= ")" suffixOverrides= "," >
<if test= "id != null" > id,</if>
<if test= "workorderCode != null" > workorder_code,</if>
<if test= "workorderCodeSap != null" > workorder_code_sap,</if>
<if test= "productName != null" > product_name,</if>
<if test= "productCode != null" > product_code,</if>
<if test= "userName != null and userName != ''" > user_name,</if>
<if test= "nickName != null and nickName != ''" > nick_name,</if>
<if test= "childprocessCode != null" > childprocess_code,</if>
<if test= "childprocessName != null" > childprocess_name,</if>
<if test= "attr1 != null" > attr1,</if>
<if test= "attr2 != null" > attr2,</if>
<if test= "attr3 != null" > attr3,</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= "remark != null" > remark,</if>
</trim>
<trim prefix= "values (" suffix= ")" suffixOverrides= "," >
<if test= "id != null" > #{id},</if>
<if test= "workorderCode != null" > #{workorderCode},</if>
<if test= "workorderCodeSap != null" > #{workorderCodeSap},</if>
<if test= "productName != null" > #{productName},</if>
<if test= "productCode != null" > #{productCode},</if>
<if test= "userName != null and userName != ''" > #{userName},</if>
<if test= "nickName != null and nickName != ''" > #{nickName},</if>
<if test= "childprocessCode != null" > #{childprocessCode},</if>
<if test= "childprocessName != null" > #{childprocessName},</if>
<if test= "attr1 != null" > #{attr1},</if>
<if test= "attr2 != null" > #{attr2},</if>
<if test= "attr3 != null" > #{attr3},</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= "remark != null" > #{remark},</if>
</trim>
</insert>
<update id= "updateMesUnitpriceReport" parameterType= "MesUnitpriceReport" >
update mes_unitprice_report
<trim prefix= "SET" suffixOverrides= "," >
<!-- <if test="workorderCode != null">workorder_code = #{workorderCode},</if> -->
<!-- <if test="workorderCodeSap != null">workorder_code_sap = #{workorderCodeSap},</if> -->
<!-- <if test="productName != null">product_name = #{productName},</if> -->
<!-- <if test="productCode != null">product_code = #{productCode},</if> -->
<!-- <if test="userName != null and userName != ''">user_name = #{userName},</if> -->
<!-- <if test="nickName != null and nickName != ''">nick_name = #{nickName},</if> -->
<if test= "childprocessCode != null" > childprocess_code = #{childprocessCode},</if>
<if test= "childprocessName != null" > childprocess_name = #{childprocessName},</if>
<if test= "attr1 != null" > attr1 = #{attr1},</if>
<if test= "attr2 != null" > attr2 = #{attr2},</if>
<if test= "attr3 != null" > attr3 = #{attr3},</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= "remark != null" > remark = #{remark},</if>
</trim>
where id = #{id}
</update>
<delete id= "deleteMesUnitpriceReportById" parameterType= "String" >
delete from mes_unitprice_report where id = #{id}
</delete>
<delete id= "deleteMesUnitpriceReportByIds" parameterType= "String" >
delete from mes_unitprice_report where id in
<foreach item= "id" collection= "array" open= "(" separator= "," close= ")" >
#{id}
</foreach>
</delete>
</mapper>