<?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.unis.crk.business.qcrk.mapper.DataCrkywQyxxDefaultMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.unis.crk.business.qcrk.entity.DataCrkywQyxxDefault">
        <id column="DataID" property="DataID" />
        <result column="UnitID" property="UnitID" />
        <result column="PeriodID" property="PeriodID" />
        <result column="RoundID" property="RoundID" />
        <result column="builder" property="builder" />
        <result column="UPDATE_TIME" property="updateTime" />
        <result column="SytelInfoID" property="SytelInfoID" />
        <result column="BuildDate" property="BuildDate" />
        <result column="editor" property="editor" />
        <result column="ModifyDate" property="ModifyDate" />
        <result column="DeptID" property="DeptID" />
        <result column="BizNo" property="BizNo" />
        <result column="PreOrder" property="PreOrder" />
        <result column="ShowOrder" property="ShowOrder" />
        <result column="qydh" property="qydh" />
        <result column="lspz" property="lspz" />
        <result column="qydw" property="qydw" />
        <result column="qyr" property="qyr" />
        <result column="qysj" property="qysj" />
        <result column="qyewm" property="qyewm" />
        <result column="qyzs" property="qyzs" />
        <result column="ypdbsl" property="ypdbsl" />
        <result column="qylb" property="qylb" />
        <result column="qyqy" property="qyqy" />
    </resultMap>
    <select id="getPerData" resultType="java.util.Map">
SELECT DISTINCT
	DATA_CRKYW_RMDJ_DEFAULT.ModifyDate AS "ModifyDate",
	DATA_CRKYW_RMDJ_DEFAULT.cph AS "cph",
	DATA_CRKYW_RMDJ_DEFAULT.cyr AS "cyr",
	DATA_CRKYW_RMDJ_DEFAULT.tzdbh AS "tzdbh",
	DATA_CRKYW_RMDJ_DEFAULT.cyrlxdh AS "cyrlxdh",
	DATA_CRKYW_RMDJ_DEFAULT.slr AS "slr",
	DATA_CRKYW_RMDJ_DEFAULT.lspz AS "lspz",
	b_5.enumName AS "lspz_value",
	DATA_CRKYW_RMDJ_DEFAULT.ywdjsj AS "ywdjsj",
	DATA_CRKYW_RMDJ_DEFAULT.BizNo AS "BizNo",
	x.*
FROM
	DATA_CRKYW_RMDJ_DEFAULT
LEFT JOIN basic_enum b_5 ON  DATA_CRKYW_RMDJ_DEFAULT.lspz = b_5.enumId
RIGHT JOIN (
	SELECT DISTINCT
		a.BuildDate as "BuildDate",
		a.BillNo AS "BillNo",
		a.TrailID "TrailID",
		c.StepID AS "stepidtop",
		a.ShowOrder,
		c.StepName "StepName",
		b.stepid,
		a.Builder "Builder",
		1 AS "operation",
		a.STATUS
	FROM
		bizflowtrail a
	INNER JOIN fl_businessflow d ON a.FlowID = d.FlowID
	LEFT JOIN fl_businessflow_step b ON a.NextBizNodeID = b.StepID
	AND a.FlowID = b.FlowID
	LEFT JOIN fl_businessflow_step c ON a.CurBizNodeID = c.StepID
	AND b.FlowID = c.FlowID
	WHERE
		ifnull(a. STATUS, 0) IN (0, 2)
	AND a.NextBizNodeID = '2'
	AND d.FLOWTYPE = '01'
	AND a.UnitID =  #{ew.unitId}
	ORDER BY
		BuildDate DESC
) x ON x.BillNo = DATA_CRKYW_RMDJ_DEFAULT.BizNo
WHERE
	1 = 1
AND DATA_CRKYW_RMDJ_DEFAULT.PeriodID = '11'
AND DATA_CRKYW_RMDJ_DEFAULT.RoundId = 0
AND DATA_CRKYW_RMDJ_DEFAULT.UnitId = #{ew.unitId}
ORDER BY
	DATA_CRKYW_RMDJ_DEFAULT.ModifyDate DESC


    </select>
    <select id="selectMyMapsPage" resultType="java.util.Map">
        SELECT DISTINCT
        DATA_CRKYW_QYXX_DEFAULT.ModifyDate AS "ModifyDate",
        DATA_CRKYW_RMDJ_DEFAULT.cyr AS "cyr",
        DATA_CRKYW_RMDJ_DEFAULT.lspz AS "lspz",
        b_1.enumName AS "lspz_value",
        DATA_CRKYW_RMDJ_DEFAULT.tzdbh AS "tzdbh",
        DATA_CRKYW_RMDJ_DEFAULT.slr AS "slr",
        DATA_CRKYW_RMDJ_DEFAULT.cph AS "cph",
        DATA_CRKYW_QYXX_DEFAULT.BizNo AS "BizNo",
        DATA_CRKYW_QYXX_DEFAULT.qysj AS "qysj",
        DATA_CRKYW_QYXX_DEFAULT.qyr AS "qyr",
        DATA_CRKYW_QYXX_DEFAULT.DataID AS "DataID"
        FROM
        DATA_CRKYW_RMDJ_DEFAULT
        LEFT JOIN DATA_CRKYW_QYXX_DEFAULT ON DATA_CRKYW_RMDJ_DEFAULT.BizNo = DATA_CRKYW_QYXX_DEFAULT.BizNo
        LEFT JOIN basic_enum b_1 ON  DATA_CRKYW_RMDJ_DEFAULT.lspz = b_1.enumId
        WHERE
        1 = 1
        AND ifnull(
        DATA_CRKYW_QYXX_DEFAULT.SytelInfoID,
        ''
        ) = '4028814763915e5c01639501cb320006'
        AND DATA_CRKYW_QYXX_DEFAULT.PeriodID = '11'
       AND DATA_CRKYW_QYXX_DEFAULT.RoundId = 0
        <if test="ew.sqlSegment != null and ew.sqlSegment != ''">
            and ${ew.sqlSegment}
        </if>
    </select>
    <select id="getOne" resultType="java.util.Map">
        SELECT
        -- 入门数据
        a.bizNo as "BizNo",
        a.lspz AS "lspz",
        a.cd AS "cd",
        a.jhdbh AS "jhdbh",
        a.rkywlx AS "rkywlx",
        a.slrsfzh AS "slrsfzh",
        a.mxpz AS "mxpz",
        a.slrdz AS "slrdz",
        a.slrdh AS "slrdh",
        a.htbh AS "htbh",
        a.cph AS "cph",
        a.tzdbh AS "tzdbh",
        a.jhfl AS "jhfl",
        a.nrchID AS "nrchID",
        a.fhdw AS "fhdw",
        a.dataId as "rmId",
        a.nrhwID AS "nrhwID",
        a.tzdID AS "tzdID",
        a.hfyhhb AS "hfyhhb",
        a.rcsj AS "rcsj",
        a.nrchbh AS "nrchbh",
        a.cydw AS "cydw",
        a.lydj AS "lydj",
        a.skr AS "skr",
        a.scnf AS "scnf",
        a.djr AS "djr",
        a.hhyhmc AS "hhyhmc",
        a.clzbzl AS "clzbzl",
        a.tzdcbid AS "tzdcbid",
        a.yhkh AS "yhkh",
        a.lsxz AS "lsxz",
        a.slr AS "slr",
        c.enumName as "lspzValue",
        d.enumName as "lsxzValue",
        e.enumName as "cdValue",
        f.enumName as "scnfValue",
        -- 扦样数据
        b.qyzs AS "qyzs",
        b.qydh AS "qydh",

        b.qydw AS "qydw",
        b.qylb AS "qylb",
        b.qyr AS "qyr",
        b.qysj AS "qysj",
        b.qyewm AS "qyewm",
        b.ypdbsl AS "ypdbsl",
        b.qyqy AS "qyqy",
        b.DataID AS DataID
        FROM
        DATA_CRKYW_RMDJ_DEFAULT a
        LEFT JOIN DATA_CRKYW_QYXX_DEFAULT b ON a.BizNo = b.BizNo
        LEFT JOIN basic_enum c on a.lspz = c.enumId
        LEFT JOIN basic_enum d on a.lsxz = d.enumId
        LEFT JOIN basic_enum e on a.cd = e.enumId
        LEFT JOIN basic_enum f on a.scnf = f.enumId
        <where>
            <if test='id != null and id != ""'>
                and b.DataID = #{id}
            </if>
            <if test='bizNo != null and bizNo != ""'>
                and a.bizNo = #{bizNo}
            </if>
        </where>

    </select>
    <update id="updateRmdj"  >
        UPDATE data_crkyw_rmdj_default
        SET UPDATE_TIME = NULL,
         ModifyDate = NOW(),
         tzdID = NULL,
         slr = NULL,
         slrsfzh = NULL,
         slrdz = NULL,
         slrdh = NULL,
         lspz = NULL,
         cd = NULL,
         lsxz = NULL,
         nrhwID = NULL,
         jhdbh = NULL,
         htbh = NULL,
         tzdbh = NULL,
         mxpz = NULL,
         rkywlx = NULL,
         jhfl = NULL,
         tzdcbid = NULL,
         rcsj = NULL,
         lydj = NULL,
         cydw = NULL,
         fhdw = NULL,
         scnf = NULL,
         clzbzl = NULL
        WHERE
            BizNo = #{bizNo}
    </update>
</mapper>