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

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.unis.crk.business.qcrk.entity.DataCrkywJyxxDefault">
        <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="jydh" property="jydh" />
        <result column="lspz" property="lspz" />
        <result column="mxpz" property="mxpz" />
        <result column="scnf" property="scnf" />
        <result column="cd" property="cd" />
        <result column="lsdj" property="lsdj" />
        <result column="dj" property="dj" />
        <result column="jyr" property="jyr" />
        <result column="jysj" property="jysj" />
        <result column="ypdbsl" property="ypdbsl" />
        <result column="zxbz" property="zxbz" />
        <result column="jyjg" property="jyjg" />
        <result column="jylb" property="jylb" />
        <result column="jyyj" property="jyyj" />
        <result column="zblb" property="zblb" />
        <result column="jdrxm" property="jdrxm" />
        <result column="ypbh" property="ypbh" />
        <result column="spzcccnx" property="spzcccnx" />
        <result column="jybz" property="jybz" />
        <result column="isaudited" property="isaudited" />
        <result column="fjy" property="fjy" />
        <result column="bz" property="bz" />
        <result column="zzyy" property="zzyy" />
    </resultMap>
    <select id="getPerData" resultType="java.util.Map">
SELECT DISTINCT
	DATA_CRKYW_QYXX_DEFAULT.ModifyDate AS "ModifyDate",
	DATA_CRKYW_QYXX_DEFAULT.qysj AS "qysj",
	DATA_CRKYW_QYXX_DEFAULT.qyr AS "qyr",
	DATA_CRKYW_QYXX_DEFAULT.qydw AS "qydw",
	DATA_CRKYW_QYXX_DEFAULT.qydh AS "qydh",
	DATA_CRKYW_RMDJ_DEFAULT.BizNo AS "BizNo",
	DATA_CRKYW_RMDJ_DEFAULT.lspz AS "lspz",
	b_5.enumName AS "lspz_value",
	data_crkyw_tzdxx_flt_001.price as "dj",
	x.*
FROM
	DATA_CRKYW_QYXX_DEFAULT
LEFT JOIN DATA_CRKYW_RMDJ_DEFAULT ON DATA_CRKYW_RMDJ_DEFAULT.BizNo = DATA_CRKYW_QYXX_DEFAULT.BizNo
LEFT JOIN basic_enum b_5 ON  DATA_CRKYW_RMDJ_DEFAULT.lspz = b_5.enumId
LEFT JOIN data_crkyw_tzdxx_flt_001  ON  data_crkyw_tzdxx_flt_001.DataID = DATA_CRKYW_RMDJ_DEFAULT.tzdcbid
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 = '3'
	AND d.FLOWTYPE = '01'
	AND a.UnitID = #{ew.unitId}
) x ON x.BillNo = DATA_CRKYW_QYXX_DEFAULT.BizNo
WHERE
	1 = 1
AND DATA_CRKYW_QYXX_DEFAULT.PeriodID = '11'
AND DATA_CRKYW_QYXX_DEFAULT.UnitId = #{ew.unitId}
AND DATA_CRKYW_QYXX_DEFAULT.RoundId = 0
ORDER BY
	DATA_CRKYW_QYXX_DEFAULT.ModifyDate DESC
    </select>
    <select id="selectMyMapsPage" resultType="java.util.Map">
        SELECT DISTINCT
        DATA_CRKYW_JYXX_DEFAULT.ModifyDate AS "ModifyDate",
        DATA_CRKYW_RMDJ_DEFAULT.lsxz AS "lsxz",
        b_0.enumName AS "lsxz_value",
        DATA_CRKYW_RMDJ_DEFAULT.cph AS "cph",
        DATA_CRKYW_RMDJ_DEFAULT.lspz AS "lspz",
        b_2.enumName AS "lspz_value",
        DATA_CRKYW_JYXX_DEFAULT.jydh AS "jydh",
        DATA_CRKYW_JYXX_DEFAULT.jyr AS "jyr",
        DATA_CRKYW_JYXX_DEFAULT.jyjg AS "jyjg",
        b_5.enumName AS "jyjg_value",
        DATA_CRKYW_JYXX_DEFAULT.lsdj AS "lsdj",
        b_6.enumName AS "lsdj_value",
        DATA_CRKYW_JYXX_DEFAULT.jysj AS "jysj",
        DATA_CRKYW_JYXX_DEFAULT.BizNo AS "BizNo",
        DATA_CRKYW_JYXX_DEFAULT.DataID AS DataID
        FROM
        DATA_CRKYW_RMDJ_DEFAULT
        LEFT JOIN DATA_CRKYW_JYXX_DEFAULT ON DATA_CRKYW_RMDJ_DEFAULT.BizNo = DATA_CRKYW_JYXX_DEFAULT.BizNo
        LEFT JOIN basic_enum b_0 ON DATA_CRKYW_RMDJ_DEFAULT.lsxz = b_0.enumId
        LEFT JOIN basic_enum b_2 ON DATA_CRKYW_RMDJ_DEFAULT.lspz = b_2.enumId
        LEFT JOIN basic_enum b_5 ON DATA_CRKYW_JYXX_DEFAULT.jyjg = b_5.enumId
        LEFT JOIN basic_enum b_6 ON DATA_CRKYW_JYXX_DEFAULT.lsdj = b_6.enumId
        WHERE
        1 = 1
        AND ifnull(
        DATA_CRKYW_JYXX_DEFAULT.SytelInfoID,
        ''
        ) = '402881476395411d0163964a2b57000b'
        AND DATA_CRKYW_JYXX_DEFAULT.PeriodID = '11'
        AND DATA_CRKYW_JYXX_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.lsxz AS "lsxz",
        a.lspz AS "lspz",
        mxpz_enum.enumName as "mxpzValue",
        a.tzdbh AS "tzdbh",
        a.mxpz AS "mxpz",
        b.jysj AS "jysj",
        b.BizNo AS "BizNo",
        b.spzcccnx AS "spzcccnx",
        b.fjy AS "fjy",
        b.jdrxm AS "jdrxm",
        b.ypbh AS "ypbh",
        b.jydh AS "jydh",
        b.zblb AS "zblb",
        b.jylb AS "jylb",
        b.jyyj AS "jyyj",
        b.jyr AS "jyr",
        b.IsAudited AS "IsAudited",
        b.jyjg AS "jyjg",
        b.lsdj AS "lsdj",
        b.dj AS "dj",
        b.jybz AS "jybz",
        b.DataID AS "DataID"
        FROM
        DATA_CRKYW_RMDJ_DEFAULT a
        LEFT JOIN DATA_CRKYW_JYXX_DEFAULT b ON a.BizNo = b.BizNo
        LEFT JOIN basic_enum mxpz_enum on mxpz_enum.enumId = a.mxpz
        <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>
    <select id="getYjSumByBizNo" resultType="java.util.Map">
        SELECT
        ifnull(SUM(jykl),0) AS "jykl"
        FROM
        DATA_CRKYW_JYXX_FLT_001 a
        INNER JOIN DATA_CRKYW_JYXX_DEFAULT b ON a.MainDataID = b.DataID
        WHERE
        BizNo = #{bizNo}
    </select>
</mapper>