<?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.goldenwater.hzz.mapper.RiverProjectMapper">
    <select id="getShxmAll" resultType="com.goldenwater.hzz.domain.RiverProjectDTO">
        SELECT GUID AS "guid", S_LINKMAN AS "sLinkman", S_PROJECT_NAME AS "sProjectName",
               S_DEPT AS "sDept", S_LOCATION AS "sLocation", S_TYPE AS "sType",
               S_P_BUILD_STAGE AS "sPBuildStage", S_PHONE AS "sPhone",
               TO_CHAR(S_PGOA_DATE,'YYYY-MM-DD') AS "sPgoaDate", S_URL AS "sUrl"
        FROM GW_RIVER_PROJECT WHERE 1=1
        <if test="searchName != null and searchName != ''">AND S_PROJECT_NAME LIKE '%'||#{searchName}||'%'</if>
    </select>
    <select id="getShxmList" resultType="com.goldenwater.hzz.domain.RiverProjectDTO">
        SELECT * FROM GW_RIVER_PROJECT WHERE 1=1
        <if test="sProjectName != null and sProjectName != ''">AND S_PROJECT_NAME LIKE '%'||#{sProjectName}||'%'</if>
        <if test="sPBuildStage != null and sPBuildStage != ''">AND S_P_BUILD_STAGE LIKE '%'||#{sPBuildStage}||'%'</if>
        ORDER BY S_PGOA_DATE DESC NULLS LAST
    </select>
    <select id="getShxmById" resultType="com.goldenwater.hzz.domain.RiverProjectDTO">SELECT * FROM GW_RIVER_PROJECT WHERE GUID=#{guid}</select>
    <insert id="saveShxm" parameterType="java.util.Map">
        INSERT INTO GW_RIVER_PROJECT(GUID,S_LINKMAN,S_UP_OLD,S_POST,S_PI,S_PN,S_X_BD,S_PS,S_PGOA_NAME,S_Y_BD,S_FAX,S_R_MAN,S_DS,S_DU,N_ID,S_R_DATE,S_DEPT,S_P_BUILD_STAGE,S_PHONE,S_LOCATION,S_UP,S_TYPE,S_PGOA_DATE,S_CODE,S_DESIGN_NAME,S_GC_NAME,S_LIMIT_DATE,S_PBT,S_PLAN_DATE,S_GC_LOCATION,S_PROJECT_NAME,S_URL)
        VALUES(#{guid},#{sLinkman},#{sUpOld},#{sPost},#{sPi},#{sPn},#{sXBd},#{sPs},#{sPGOAName},#{sYBd},#{sFax},#{sRMan},#{sDs},#{sDu},#{nId},TO_DATE(#{sRDate},'YYYY-MM-DD'),#{sDept},#{sPBuildStage},#{sPhone},#{sLocation},#{sUp},#{sType},TO_DATE(#{sPGOADate},'YYYY-MM-DD'),#{sCode},#{sDesignName},#{sGcName},TO_DATE(#{sLimitDate},'YYYY-MM-DD'),#{sPBT},TO_DATE(#{sPlanDate},'YYYY-MM-DD'),#{sGcLocation},#{sProjectName},#{sUrl})
    </insert>
    <update id="editShxm" parameterType="java.util.Map">
        UPDATE GW_RIVER_PROJECT SET S_LINKMAN=#{sLinkman},S_PROJECT_NAME=#{sProjectName},S_DEPT=#{sDept},S_LOCATION=#{sLocation},S_TYPE=#{sType},S_P_BUILD_STAGE=#{sPBuildStage},S_PHONE=#{sPhone},S_PGOA_DATE=TO_DATE(#{sPGOADate},'YYYY-MM-DD'),S_URL=#{sUrl} WHERE GUID=#{guid}
    </update>
    <delete id="deleteShxm">DELETE FROM GW_RIVER_PROJECT WHERE GUID=#{guid}</delete>
    <select id="getFilesById" resultType="com.goldenwater.hzz.domain.RiverProjectDTO">SELECT GUID AS "guid",PRO_ID AS "proId",URL AS "url" FROM GW_RIVER_PROJECT_FILE WHERE PRO_ID=#{guid}</select>
    <insert id="saveShxmFiles" parameterType="java.util.List">
        INSERT ALL
        <foreach collection="list" item="item">INTO GW_RIVER_PROJECT_FILE(GUID,PRO_ID,URL) VALUES(#{item.guid},#{item.proId},#{item.url})</foreach>
        SELECT 1 FROM DUAL
    </insert>
    <delete id="deleteShxmFile">DELETE FROM GW_RIVER_PROJECT_FILE WHERE PRO_ID=#{guid}</delete>
    <select id="selectConstructionList" resultType="com.goldenwater.hzz.domain.RiverConstructionDTO">
        SELECT GUID,PROJECT_NAME AS projectName,ITEM_TYPE AS itemType,PROJECT_APPLICANT_UNIT AS projectApplicantUnit,ITEM_SUBJECT_NAME AS itemSubjectName,PROJECT_APPLICATION_DATE AS projectApplicationDate,ACCEPT_UNITS AS acceptUnits,PROJECT_CONSTRUCTION_SCALE AS projectConstructionScale,PROJECT_LEGAL_PERSON AS projectLegalPerson,PROJECT_LINKMAN AS projectLinkman,PROJECT_LINK_PHONE AS projectLinkPhone,PROJECT_CODE AS projectCode,ITEM_APPLY_NAME AS itemApplyName,ITEM_CODE AS itemCode,CREATE_TIME AS createTime,UPDATE_TIME AS updateTime
        FROM GW_RIVER_COURSE_CONSTRUCTION
        <where><if test="projectName != null and projectName != ''">AND PROJECT_NAME=#{projectName}</if><if test="itemType != null and itemType != ''">AND ITEM_TYPE=#{itemType}</if></where>
    </select>
    <insert id="insertConstruction" parameterType="com.goldenwater.hzz.domain.RiverConstructionDTO">
        INSERT INTO GW_RIVER_COURSE_CONSTRUCTION(GUID,PROJECT_NAME,ITEM_TYPE,PROJECT_APPLICANT_UNIT,ITEM_SUBJECT_NAME,PROJECT_APPLICATION_DATE,ACCEPT_UNITS,PROJECT_CONSTRUCTION_SCALE,PROJECT_LEGAL_PERSON,PROJECT_LINKMAN,PROJECT_LINK_PHONE,PROJECT_CODE,ITEM_APPLY_NAME,ITEM_CODE,CREATE_TIME,UPDATE_TIME)
        VALUES(#{guid},#{projectName},#{itemType},#{projectApplicantUnit},#{itemSubjectName},#{projectApplicationDate},#{acceptUnits},#{projectConstructionScale},#{projectLegalPerson},#{projectLinkman},#{projectLinkPhone},#{projectCode},#{itemApplyName},#{itemCode},#{createTime},#{updateTime})
    </insert>
    <update id="updateConstruction">UPDATE GW_RIVER_COURSE_CONSTRUCTION <set><if test="projectName != null">PROJECT_NAME=#{projectName},</if><if test="itemType != null">ITEM_TYPE=#{itemType},</if><if test="updateTime != null">UPDATE_TIME=#{updateTime},</if></set> WHERE GUID=#{guid}</update>
    <delete id="deleteConstruction">DELETE FROM GW_RIVER_COURSE_CONSTRUCTION WHERE GUID IN <foreach collection="guids" item="g" open="(" separator="," close=")">#{g}</foreach></delete>
</mapper>
