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

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.unis.crk.business.qcrk.entity.DataCrkywRkcmDefault">
        <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="cmyy" property="cmyy" />
        <result column="cmbz" property="cmbz" />
        <result column="czr" property="czr" />
        <result column="cmsj" property="cmsj" />
        <result column="cyr" property="cyr" />
        <result column="rmdh" property="rmdh" />
        <result column="qcph" property="qcph" />
        <result column="lxdh" property="lxdh" />
        <result column="cyrszhh" property="cyrszhh" />
        <result column="djr" property="djr" />
        <result column="khmc" property="khmc" />
        <result column="cyrlxdz" property="cyrlxdz" />
        <result column="cllx" property="cllx" />
    </resultMap>

    <select id="getPerData" resultType="java.util.Map">
SELECT DISTINCT
	DATA_CRKYW_RMDJ_DEFAULT.ModifyDate AS "ModifyDate",
	DATA_CRKYW_RMDJ_DEFAULT.cyrlxdh AS "cyrlxdh",
	DATA_CRKYW_RMDJ_DEFAULT.cydw AS "cydw",
	DATA_CRKYW_RMDJ_DEFAULT.tzdbh AS "tzdbh",
	DATA_CRKYW_RMDJ_DEFAULT.cyr AS "cyr",
	DATA_CRKYW_RMDJ_DEFAULT.BizNo AS "BizNo",
	DATA_CRKYW_RMDJ_DEFAULT.cph AS "cph",
	DATA_CRKYW_RMDJ_DEFAULT.lspz AS "lspz",
	b_6.enumName AS "lspz_value",
	DATA_CRKYW_RMDJ_DEFAULT.slr AS "slr",
	x.*
FROM
	DATA_CRKYW_RMDJ_DEFAULT
LEFT JOIN basic_enum b_6 ON DATA_CRKYW_RMDJ_DEFAULT.lspz = b_6.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 = '7'
	AND d.FLOWTYPE = '01'
	AND a.UnitID = #{ew.unitId}
) 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.ModifyDate DESC
    </select>
    <select id="selectMyMapsPage" resultType="java.util.Map">
        SELECT DISTINCT
        DATA_CRKYW_RKCM_DEFAULT.ModifyDate AS "ModifyDate",
        DATA_CRKYW_RMDJ_DEFAULT.cyr AS "cyr",
        DATA_CRKYW_RMDJ_DEFAULT.cydw AS "cydw",
        DATA_CRKYW_RMDJ_DEFAULT.cyrlxdh AS "cyrlxdh",
        DATA_CRKYW_RMDJ_DEFAULT.slr AS "slr",
        DATA_CRKYW_RMDJ_DEFAULT.cph AS "cph",
        DATA_CRKYW_CPZ_DEFAULT.sjcfbh AS "sjcfbh",
        DATA_CRKYW_RKCM_DEFAULT.cmyy AS "cmyy",
        b_6.enumName AS "cmyy_value",
        DATA_CRKYW_RKCM_DEFAULT.cmsj AS "cmsj",
        DATA_CRKYW_RKCM_DEFAULT.czr AS "czr",
        DATA_CRKYW_RKCM_DEFAULT.BizNo AS "BizNo",
        DATA_CRKYW_RKCM_DEFAULT.DataID AS DataID
        FROM
        DATA_CRKYW_RMDJ_DEFAULT
        LEFT JOIN DATA_CRKYW_CPZ_DEFAULT ON DATA_CRKYW_RMDJ_DEFAULT.BizNo = DATA_CRKYW_CPZ_DEFAULT.BizNo
        LEFT JOIN DATA_CRKYW_RKCM_DEFAULT ON DATA_CRKYW_RMDJ_DEFAULT.BizNo = DATA_CRKYW_RKCM_DEFAULT.BizNo
        LEFT JOIN basic_enum b_6 ON DATA_CRKYW_RKCM_DEFAULT.cmyy = b_6.enumId
        WHERE
        1 = 1
        AND ifnull(
        DATA_CRKYW_RKCM_DEFAULT.SytelInfoID,
        ''
        ) = '4028814763a546b20163aa7a7fda0012'
        AND DATA_CRKYW_RKCM_DEFAULT.PeriodID = '11'
        AND DATA_CRKYW_RKCM_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.slr AS "slr",
        a.ywdjsj AS "ywdjsj",
        a.cph AS "cph",
        b.BizNo AS "BizNo",
        b.cmbz AS "cmbz",
        b.czr AS "czr",
        b.cmyy AS "cmyy",
        b.cmsj AS "cmsj",
        b.DataID AS "DataID"
        FROM
        DATA_CRKYW_RMDJ_DEFAULT a
        LEFT JOIN DATA_CRKYW_RKCM_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>