<?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.DataCrkywCpzDefaultMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.unis.crk.business.qcrk.entity.DataCrkywCpzDefault">
        <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="ccsslx" property="ccsslx" />
        <result column="zyjssj" property="zyjssj" />
        <result column="zykssj" property="zykssj" />
        <result column="pz" property="pz" />
        <result column="sjchID" property="sjchID" />
        <result column="bzwjs" property="bzwjs" />
        <result column="hykl" property="hykl" />
        <result column="zkj" property="zkj" />
        <result column="zkjyy" property="zkjyy" />
        <result column="xcks" property="xcks" />
        <result column="jjdh" property="jjdh" />
        <result column="bgy" property="bgy" />
        <result column="sjhwID" property="sjhwID" />
        <result column="xckqt" property="xckqt" />
        <result column="cpzsj" property="cpzsj" />
        <result column="zyf" property="zyf" />
        <result column="xzklhjz" property="xzklhjz" />
        <result column="bzwkl" property="bzwkl" />
        <result column="xckz" property="xckz" />
        <result column="xzzl" property="xzzl" />
        <result column="xckbfb" property="xckbfb" />
        <result column="zlfyzkl" property="zlfyzkl" />
        <result column="sjjz" property="sjjz" />
        <result column="pjy" property="pjy" />
        <result column="sjhwbh" property="sjhwbh" />
        <result column="sjcfbh" property="sjcfbh" />
        <result column="zyd" property="zyd" />
        <result column="zyz" property="zyz" />
        <result column="ywdh" property="ywdh" />
        <result column="khmc" property="khmc" />
        <result column="qcph" property="qcph" />
        <result column="lypz" property="lypz" />
        <result column="psjs" property="psjs" />
        <result column="djzl" property="djzl" />
        <result column="cyr" property="cyr" />
        <result column="lxdh" property="lxdh" />
        <result column="cyrsfzh" property="cyrsfzh" />
        <result column="zt" property="zt" />
        <result column="hw" property="hw" />
        <result column="djr" property="djr" />
        <result column="xzrq" property="xzrq" />
        <result column="zycx" property="zycx" />
        <result column="lspz" property="lspz" />
        <result column="lsxz" property="lsxz" />
        <result column="tzdid" property="tzdid" />
        <result column="tzdbh" property="tzdbh" />
        <result column="cllx" property="cllx" />
        <result column="rmdh" property="rmdh" />
        <result column="mzzl" property="mzzl" />
        <result column="sqbh" property="sqbh" />
        <result column="xzjs" property="xzjs" />
        <result column="jjlx" property="jjlx" />
        <result column="klyy" property="klyy" />
        <result column="jhapbh" property="jhapbh" />
        <result column="jpyyj" property="jpyyj" />
        <result column="jpy" property="jpy" />
        <result column="rksxh" property="rksxh" />
        <result column="sglryy" property="sglryy" />
        <result column="bz" property="bz" />
        <result column="sfhz" property="sfhz" />
        <result column="sydw" property="sydw" />
        <result column="dbbzkl" property="dbbzkl" />
        <result column="bzsl" property="bzsl" />
        <result column="jzxh" property="jzxh" />
        <result column="bzfs" property="bzfs" />
    </resultMap>

    <select id="getPerData" resultType="java.util.Map">
SELECT DISTINCT
	DATA_CRKYW_CMZ_DEFAULT.ModifyDate AS "ModifyDate",
	DATA_CRKYW_CMZ_DEFAULT.nrchbh AS "nrchbh",
	DATA_CRKYW_CMZ_DEFAULT.jjdh AS "jjdh",
	DATA_CRKYW_RMDJ_DEFAULT.cyr AS "cyr",
	DATA_CRKYW_RMDJ_DEFAULT.cydw AS "cydw",
	DATA_CRKYW_CMZ_DEFAULT.nrhwbh AS "nrhwbh",
	DATA_CRKYW_CMZ_DEFAULT.BizNo AS "bizNo",
	DATA_CRKYW_CMZ_DEFAULT.cmzsj AS "cmzsj",
	DATA_CRKYW_RMDJ_DEFAULT.cyrlxdh AS "cyrlxdh",
	DATA_CRKYW_RMDJ_DEFAULT.cph AS "cph",
	DATA_CRKYW_RMDJ_DEFAULT.slr AS "slr",
	DATA_CRKYW_RMDJ_DEFAULT.lspz AS "lspz",
	b_4.enumName AS "lspz_value",
	DATA_CRKYW_RMDJ_DEFAULT.tzdbh AS "tzdbh",
	x.*
FROM
	DATA_CRKYW_CMZ_DEFAULT
LEFT JOIN DATA_CRKYW_RMDJ_DEFAULT ON DATA_CRKYW_RMDJ_DEFAULT.BizNo = DATA_CRKYW_CMZ_DEFAULT.BizNo
LEFT JOIN basic_enum b_4 ON  DATA_CRKYW_RMDJ_DEFAULT.lspz = b_4.enumId
RIGHT JOIN (
	SELECT DISTINCT
		a.BillNo,
		a.TrailID AS "TrailID",
		c.StepID AS "StepIDTop",
		a.ShowOrder AS "ShowOrder",
		c.StepName AS "StepName",
		b.StepID AS "StepID",
		a.Builder AS "Builder",
		A.BuildDate AS "buildDate",
		1 AS "operation",
		a.STATUS AS "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) = 0
			OR ifnull(a. STATUS, 0) = 2
		)
	AND a.NextBizNodeID = '5'
	AND a.UnitID = #{ew.unitId}
	AND d.FLOWTYPE = '01'
	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.UnitId =  #{ew.unitId}
AND DATA_CRKYW_RMDJ_DEFAULT.RoundId = 0
ORDER BY
	DATA_CRKYW_RMDJ_DEFAULT.buildDate DESC
    </select>
    <select id="selectMyMapsPage" resultType="java.util.Map">
        SELECT DISTINCT
        DATA_CRKYW_CPZ_DEFAULT.ModifyDate AS "ModifyDate",
        DATA_CRKYW_RMDJ_DEFAULT.slr AS "slr",
        DATA_CRKYW_RMDJ_DEFAULT.cydw AS "cydw",
        DATA_CRKYW_RMDJ_DEFAULT.cph AS "cph",
        DATA_CRKYW_RMDJ_DEFAULT.cyr AS "cyr",
        DATA_CRKYW_RMDJ_DEFAULT.lspz AS "lspz",
        b_4.enumName AS "lspz_value",
        DATA_CRKYW_CMZ_DEFAULT.mz AS "mz",
        DATA_CRKYW_CMZ_DEFAULT.jjdh AS "jjdh",
        DATA_CRKYW_CPZ_DEFAULT.xzklhjz AS "xzklhjz",
        DATA_CRKYW_CPZ_DEFAULT.sjcfbh AS "sjcfbh",
        DATA_CRKYW_CPZ_DEFAULT.sjhwbh AS "sjhwbh",
        DATA_CRKYW_CPZ_DEFAULT.cpzsj AS "cpzsj",
        DATA_CRKYW_CPZ_DEFAULT.sglryy AS "sglryy",
        DATA_CRKYW_CPZ_DEFAULT.pz AS "pz",
        DATA_CRKYW_CPZ_DEFAULT.BizNo AS "BizNo",
        DATA_CRKYW_CPZ_DEFAULT.pjy AS "pjy",
        DATA_CRKYW_CPZ_DEFAULT.DataID AS DataID
        FROM
        DATA_CRKYW_RMDJ_DEFAULT
        LEFT JOIN DATA_CRKYW_CMZ_DEFAULT ON DATA_CRKYW_RMDJ_DEFAULT.BizNo = DATA_CRKYW_CMZ_DEFAULT.BizNo
        LEFT JOIN DATA_CRKYW_CPZ_DEFAULT ON DATA_CRKYW_RMDJ_DEFAULT.BizNo = DATA_CRKYW_CPZ_DEFAULT.BizNo
        LEFT JOIN basic_enum b_4 ON DATA_CRKYW_RMDJ_DEFAULT.lspz = b_4.enumId
        WHERE
        ifnull(
        DATA_CRKYW_CPZ_DEFAULT.SytelInfoID,
        ''
        ) = '4028814763a546b20163a9f469950006'
        AND DATA_CRKYW_CPZ_DEFAULT.PeriodID = '11'
        AND DATA_CRKYW_CPZ_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.lspz AS "lspz",
        a.slr AS "slr",
        a.mxpz AS "mxpz",
        a.cydw AS "cydw",
        a.cph AS "cph",
        a.slrdh AS "slrdh",
        a.cllx AS "cllx",
        b.jybz AS "jybz",
        b.dj AS "dj",
        c.mz AS "mz",
        c.jjdh AS "jjdh",
        d.zykssj AS "zykssj",
        d.bz AS "bz",
        d.cpzsj AS "cpzsj",
        d.sjcfbh AS "sjcfbh",
        d.djzl AS "djzl",
        d.bzfs AS "bzfs",
        d.sjhwID AS "sjhwID",
        d.zyf AS "zyf",
        d.sglryy AS "sglryy",
        d.klyy AS "klyy",
        d.BizNo AS "BizNo",
        d.jpyyj AS "jpyyj",
        d.xzjs AS "xzjs",
        d.jjlx AS "jjlx",
        d.zyz AS "zyz",
        d.bgy AS "bgy",
        d.xckbfb AS "xckbfb",
        d.jhapbh AS "jhapbh",
        d.xckz AS "xckz",
        d.xzklhjz AS "xzklhjz",
        d.pjy AS "pjy",
        d.xckqt AS "xckqt",
        d.rksxh AS "rksxh",
        d.jpy AS "jpy",
        d.xzzl AS "xzzl",
        d.bzwkl AS "bzwkl",
        d.hykl AS "hykl",
        d.pz AS "pz",
        d.sjjz AS "sjjz",
        d.jzxh AS "jzxh",
        d.sjhwbh AS "sjhwbh",
        d.sjchID AS "sjchID",
        d.zyjssj AS "zyjssj",
        d.xcks AS "xcks",
        d.zyd AS "zyd",
        d.bzwjs AS "bzwjs",
        d.DataID AS "DataID"
        FROM
        DATA_CRKYW_RMDJ_DEFAULT a
        LEFT JOIN DATA_CRKYW_JYXX_DEFAULT b ON a.BizNo = b.BizNo
        LEFT JOIN DATA_CRKYW_CMZ_DEFAULT c ON a.BizNo = c.BizNo
        LEFT JOIN DATA_CRKYW_CPZ_DEFAULT d ON a.BizNo = d.BizNo
        <where>
            <if test='id != null and id != ""'>
                d.DataID = #{id}
            </if>
            <if test='bizNo != null and bizNo != ""'>
               and a.bizNo = #{bizNo}
            </if>
        </where>
    </select>
</mapper>