<?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.qcck.mapper.DataCrkywCkcmDefaultMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.unis.crk.business.qcck.entity.DataCrkywCkcmDefault">
        <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="cmsj" property="cmsj" />
        <result column="cmzt" property="cmzt" />
        <result column="cmdjr" property="cmdjr" />
        <result column="bz" property="bz" />
        <result column="rmdh" property="rmdh" />
        <result column="qcph" property="qcph" />
        <result column="cyr" property="cyr" />
        <result column="lxdh" property="lxdh" />
        <result column="cyrsfzh" property="cyrsfzh" />
        <result column="djr" property="djr" />
    </resultMap>

    <select id="getPerData" resultType="java.util.Map">
SELECT DISTINCT
	DATA_CRKYW_CKRMDJ_DEFAULT.ModifyDate AS "ModifyDate",
	DATA_CRKYW_CKRMDJ_DEFAULT.cyr AS "cyr",
	DATA_CRKYW_CKRMDJ_DEFAULT.tzdbh AS "tzdbh",
	DATA_CRKYW_CKRMDJ_DEFAULT.BizNo AS "BizNo",
	DATA_CRKYW_CKRMDJ_DEFAULT.lspz AS "lspz",
	b_3.enumName AS "lspz_value",
	DATA_CRKYW_CKRMDJ_DEFAULT.cydw AS "cydw",
	DATA_CRKYW_CKRMDJ_DEFAULT.slr AS "slr",
	DATA_CRKYW_CKRMDJ_DEFAULT.cyrdh AS "cyrdh",
	DATA_CRKYW_CKRMDJ_DEFAULT.cph AS "cph",
	x.*
FROM
	DATA_CRKYW_CKRMDJ_DEFAULT
LEFT JOIN basic_enum b_3 ON DATA_CRKYW_CKRMDJ_DEFAULT.lspz = b_3.enumId
RIGHT JOIN (
	SELECT DISTINCT
		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,
		a.note
	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
		a. STATUS IN (0, 2)
	AND a.NextBizNodeID = '4'
	AND d.FLOWTYPE = '04'
	AND a.UnitID = #{ew.unitId}
) x ON x.BillNo = DATA_CRKYW_CKRMDJ_DEFAULT.BizNo
WHERE
	1 = 1
AND DATA_CRKYW_CKRMDJ_DEFAULT.PeriodID = '11'
AND DATA_CRKYW_CKRMDJ_DEFAULT.UnitId = #{ew.unitId}
AND DATA_CRKYW_CKRMDJ_DEFAULT.RoundId = 0
ORDER BY
	DATA_CRKYW_CKRMDJ_DEFAULT.ModifyDate DESC
    </select>
    <select id="selectMyMapsPage" resultType="java.util.Map">
        SELECT DISTINCT
        DATA_CRKYW_CKCM_DEFAULT.ModifyDate AS "ModifyDate",
        DATA_CRKYW_CKCMZ_DEFAULT.sjckchmc AS "sjckchmc",
        DATA_CRKYW_CKCM_DEFAULT.cmsj AS "cmsj",
        DATA_CRKYW_CKCM_DEFAULT.cmdjr AS "cmdjr",
        DATA_CRKYW_CKCM_DEFAULT.cmzt AS "cmzt",
        b_3.enumName AS "cmzt_value",
        DATA_CRKYW_CKCM_DEFAULT.BizNo AS "BizNo",
        DATA_CRKYW_CKRMDJ_DEFAULT.cyrdh AS "cyrdh",
        DATA_CRKYW_CKRMDJ_DEFAULT.slr AS "slr",
        DATA_CRKYW_CKRMDJ_DEFAULT.cyr AS "cyr",
        DATA_CRKYW_CKRMDJ_DEFAULT.cph AS "cph",
        DATA_CRKYW_CKRMDJ_DEFAULT.cydw AS "cydw",
        DATA_CRKYW_CKCM_DEFAULT.DataID AS DataID
        FROM
        DATA_CRKYW_CKCMZ_DEFAULT
        LEFT JOIN DATA_CRKYW_CKRMDJ_DEFAULT ON DATA_CRKYW_CKRMDJ_DEFAULT.BizNo = DATA_CRKYW_CKCMZ_DEFAULT.BizNo
        LEFT JOIN DATA_CRKYW_CKCM_DEFAULT ON DATA_CRKYW_CKCMZ_DEFAULT.BizNo = DATA_CRKYW_CKCM_DEFAULT.BizNo
        LEFT JOIN basic_enum b_3 ON DATA_CRKYW_CKCM_DEFAULT.cmzt = b_3.enumId
        WHERE
        ifnull(
        DATA_CRKYW_CKCM_DEFAULT.SytelInfoID,
        ''
        ) = '4028814763a546b20163aea8547e0027'
        AND DATA_CRKYW_CKCM_DEFAULT.PeriodID = '11'
        AND DATA_CRKYW_CKCM_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.cph AS "cph",
        a.rmsj AS "rmsj",
        b.bz AS "bz",
        b.cmzt AS "cmzt",
        b.cmdjr AS "cmdjr",
        b.PreOrder AS "PreOrder",
        b.cmsj AS "cmsj",
        b.BizNo AS "BizNo",
        b.ShowOrder AS "ShowOrder",
        b.DataID AS "DataID"
        FROM
        DATA_CRKYW_CKRMDJ_DEFAULT a
        LEFT JOIN DATA_CRKYW_CKCM_DEFAULT b ON a.BizNo = b.BizNo
        <where>
            <if test='id != null and id != ""'>
                b.DataID = #{id}
            </if>
            <if test='bizNo != null and bizNo != ""'>
               and a.bizNo = #{bizNo}
            </if>

        </where>
    </select>
</mapper>