<?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.uml.tech.njMapper.FarmWorkNjMapper">

    <insert id="insertWorkInfo">
        replace
        into
        ${tbName}
        (
        unitPrice,
        GPSDateTime,
        serialNumber,
        jobArea,
        jobStartLat,
        TIME,
        jobStartTime,
        DATE_TYPE,
        jobWidth,
        unit,
        currentBlockNumber,
        isData,
        jobStartLon,
        createTime,
        vehicleTypeCode,
        jobType,
        brand,
        farmDataType,
        jobEquipment,
        did,
        jobEndTime,
        insertTime,
        GPSLat,
        GPSLon,
        jobTime,
        id,
        lk,
        positionsSum,
        centerLat,
        centerLon,
        avgDepth,
        avgPercentOfPass,
        standardDepth,
        averageSprayDose,
        totalDose,
        flowCoefficient,
        avgFertilizationRate,
        fertilizationTotal,
        fertilizerDischargeCoefficient,
        averageYieldPerMu,
        totalPlotYield,
        province,
        city,
        district,
        sematicDescription,
        totalPoints,
        wkt_poly,
        dryingWeight ,
        absoluteJobTime ,
        bundleWeight,
        bundles,
        jobMileage,
        avgStubbleHeight,
        standardStubbleHeight,
        jobMileageType
        )
        values
        (
        #{wi.unitPrice,jdbcType=DOUBLE},
        #{wi.GPSDateTime,jdbcType=TIMESTAMP},
        #{wi.serialNumber,jdbcType=VARCHAR},
        #{wi.jobArea,jdbcType=DOUBLE},
        #{wi.jobStartLat,jdbcType=DOUBLE},
        #{wi.TIME,jdbcType=TIMESTAMP},
        #{wi.jobStartTime,jdbcType=TIMESTAMP},
        #{wi.DATE_TYPE,jdbcType=VARCHAR},
        #{wi.jobWidth,jdbcType=DOUBLE},
        #{wi.unit,jdbcType=VARCHAR},
        #{wi.currentBlockNumber,jdbcType=VARCHAR},
        #{wi.isData,jdbcType=VARCHAR},
        #{wi.jobStartLon,jdbcType=DOUBLE},
        #{wi.createTime,jdbcType=TIMESTAMP},
        #{wi.vehicleTypeCode,jdbcType=VARCHAR},
        #{wi.jobType,jdbcType=INTEGER},
        #{wi.brand,jdbcType=INTEGER},
        #{wi.farmDataType,jdbcType=VARCHAR},
        #{wi.jobEquipment,jdbcType=INTEGER},
        #{wi.did,jdbcType=VARCHAR},
        #{wi.jobEndTime,jdbcType=TIMESTAMP},
        DATE_FORMAT( NOW(),'%Y%m%d%H%i%s'),
        #{wi.GPSLat,jdbcType=DOUBLE},
        #{wi.GPSLon,jdbcType=DOUBLE},
        #{wi.jobTime,jdbcType=INTEGER},
        #{wi.uuid,jdbcType=VARCHAR},
        #{wi.lk,jdbcType=LONGVARBINARY},
        #{wi.positionsSum,jdbcType=INTEGER},
        #{wi.centerLat,jdbcType=DOUBLE},
        #{wi.centerLon,jdbcType=DOUBLE},
        #{wi.avgDepth,jdbcType=DOUBLE},
        #{wi.avgPercentOfPass,jdbcType=DOUBLE},
        #{wi.standardDepth,jdbcType=DOUBLE},
        #{wi.averageSprayDose,jdbcType=DOUBLE},
        #{wi.totalDose,jdbcType=DOUBLE},
        #{wi.flowCoefficient,jdbcType=VARCHAR},
        #{wi.avgFertilizationRate,jdbcType=DOUBLE},
        #{wi.fertilizationTotal,jdbcType=DOUBLE},
        #{wi.fertilizerDischargeCoefficient,jdbcType=VARCHAR},
        #{wi.averageYieldPerMu,jdbcType=DOUBLE},
        #{wi.totalPlotYield,jdbcType=DOUBLE},
        #{wi.province,jdbcType=VARCHAR},
        #{wi.city,jdbcType=VARCHAR},
        #{wi.district,jdbcType=VARCHAR},
        #{wi.sematicDescription,jdbcType=VARCHAR},
        #{wi.totalPoints,jdbcType=INTEGER},
        #{wi.wktPoly,jdbcType=LONGVARBINARY},
        #{wi.dryingWeight,jdbcType=DOUBLE},
        #{wi.absoluteJobTime,jdbcType=INTEGER},
        #{wi.bundleWeight,jdbcType=DOUBLE},
        #{wi.bundles,jdbcType=INTEGER},
        #{wi.jobMileage,jdbcType=DOUBLE},
        #{wi.avgStubbleHeight,jdbcType=DOUBLE},
        #{wi.standardStubbleHeight,jdbcType=DOUBLE},
        #{wi.jobMileageType,jdbcType=TINYINT}
        )
    </insert>

    <update id="updateWorkInfo" parameterType="com.uml.tech.bean.FarmWork">
        update farm_work
        <set>
            <if test="jobArea !=null">
                jobArea = #{jobArea},
            </if>
            <if test="jobType !=null">
                jobType = #{jobType},
            </if>
            <if test="jobWidth !=null">
                jobWidth = #{jobWidth},
            </if>
            <if test="jobEquipment !=null">
                jobEquipment = #{jobEquipment},
            </if>
            <!-- 修改平均深度，平均合格率 -->
            <if test="avgDepth !=null">
                avgDepth = #{avgDepth},
            </if>
            <if test="avgPercentOfPass !=null">
                avgPercentOfPass = #{avgPercentOfPass},
            </if>
            <if test="lk !=null">
                lk = #{lk},
            </if>
            <if test="id !=null">
                id = #{id},
            </if>
            <if test="centerLat !=null">
                centerLat = #{centerLat},
            </if>
            <if test="centerLon !=null">
                centerLon = #{centerLon},
            </if>
            <if test="totalPoints !=null">
                totalPoints = #{totalPoints},
            </if>
            <if test="wkt !=null">
                wkt_poly = #{wkt},
            </if>
            <!-- 修改烘干重量 -->
            <if test="dryingWeight !=null">
                dryingWeight = #{dryingWeight},
            </if>
            <!-- 修改打捆重量 -->
            <if test="bundleWeight !=null">
                bundleWeight = #{bundleWeight},
            </if>
            <!-- 修改打捆个数 -->
            <if test="bundles !=null">
                bundles = #{bundles},
            </if>
            <!-- 修改绝对作业时间 -->
            <if test="absoluteJobTime !=null">
                absoluteJobTime = #{absoluteJobTime},
            </if>
            <!-- 修改作业里程 -->
            <if test="jobMileage !=null">
                jobMileage = #{jobMileage},
            </if>
            <!-- 平均留茬高度 -->
            <if test="avgStubbleHeight !=null">
                avgStubbleHeight = #{avgStubbleHeight},
            </if>
            <!-- 标准留茬高度 -->
            <if test="standardStubbleHeight !=null">
                standardStubbleHeight = #{standardStubbleHeight},
            </if>
        </set>
        <where>
            did = #{did} and jobEndTime = #{jobEndTime} and jobStartTime = #{jobStartTime}
        </where>
    </update>



    <delete id="delNjWork">
    	delete from farm_work where did = #{did} and jobEndTime = #{jobEndTime} and jobStartTime = #{jobStartTime}
    </delete>
    <delete id="deleteOldSplitData">
        delete from farm_work_split where parentRowKey = #{parentRowKey}
    </delete>
    <select id="selectEntity" resultType="com.uml.tech.bean.NjWorkInfo">
		select did, jobEndTime, jobStartTime, totalPoints from farm_work where did = #{did} and jobEndTime = #{jobEndTime} and jobStartTime = #{jobStartTime};
	</select>
    <select id="selectTotalStatus" resultType="com.uml.tech.bean.UpdateBean">
        SELECT did, sum(jobArea) jobArea, sum(if(absoluteJobTime is null, jobTime, absoluteJobTime)) jobTime,
        sum(avgDepth * if(positionsSum is null, jobTime, positionsSum)) totalDepth,
        sum(avgPercentOfPass * if(positionsSum is null, jobTime, positionsSum)) totalPercentOfPass, sum(positionsSum)
        totalPositionsSum,
        sum(dryingWeight) totalDryingWeight,sum(bundleWeight) totalBundleWeight, sum(bundles) totalBundles,
        sum(totalDose) totalDose,
        sum(fertilizationTotal) totalFertilization,sum(totalPlotYield) totalPlotYield,sum(jobMileage) totalJobMileage
        from farm_work
        WHERE did = #{did}
        <if test="startDay !=null">
            and <![CDATA[ jobEndTime > ${startDay} ]]>
        </if>
        <if test="endDay !=null">
            and <![CDATA[ jobEndTime < ${endDay} ]]>
        </if>
    </select>
    <select id="selectHistoryData" resultType="com.uml.tech.bean.FarmWork">
        SELECT did,
               jobStartTime,
               jobEndTime
        FROM farm_work
        WHERE did = #{did}
          AND
		<![CDATA[((jobStartTime >= #{jobStartTime} AND jobStartTime <= #{jobEndTime})
            OR (jobEndTime >= #{jobStartTime} AND jobEndTime <= #{jobEndTime})
            OR (jobStartTime <= #{jobStartTime} and jobEndTime >= #{jobEndTime})
            )
        ]]>
    </select>

</mapper>
