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

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.unis.crk.business.qcck.entity.DataCrkywCkcpzDefault">
        <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="jjdh" property="jjdh" />
        <result column="ycchID" property="ycchID" />
        <result column="ychwID" property="ychwID" />
        <result column="pz" property="pz" />
        <result column="jpsj" property="jpsj" />
        <result column="pjy" property="pjy" />
        <result column="ncchbh" property="ncchbh" />
        <result column="nchwbh" property="nchwbh" />
        <result column="qcph" property="qcph" />
        <result column="rmsj" property="rmsj" />
        <result column="tzdID" property="tzdID" />
        <result column="mlrxm" property="mlrxm" />
        <result column="cllx" property="cllx" />
        <result column="cyrxm" property="cyrxm" />
        <result column="cyrdh" property="cyrdh" />
        <result column="djr" property="djr" />
        <result column="sycksl" property="sycksl" />
        <result column="jhcksl" property="jhcksl" />
        <result column="chID" property="chID" />
        <result column="mxpz" property="mxpz" />
        <result column="chbm" property="chbm" />
        <result column="htID" property="htID" />
        <result column="jhdID" property="jhdID" />
        <result column="hwID" property="hwID" />
        <result column="htbh" property="htbh" />
        <result column="jhdbh" property="jhdbh" />
        <result column="tzdbh" property="tzdbh" />
        <result column="cyr" property="cyr" />
        <result column="cyrsfzhm" property="cyrsfzhm" />
        <result column="djsj" property="djsj" />
        <result column="thdh" property="thdh" />
        <result column="glhcph" property="glhcph" />
        <result column="fyz" property="fyz" />
        <result column="zt" property="zt" />
        <result column="hw" property="hw" />
        <result column="slr" property="slr" />
        <result column="zyd" property="zyd" />
        <result column="zyz" property="zyz" />
        <result column="lypz" property="lypz" />
        <result column="slrdh" property="slrdh" />
        <result column="lyxz" property="lyxz" />
        <result column="sglryy" property="sglryy" />
    </resultMap>

    <select id="getOne" resultType="java.util.Map">
        SELECT
        -- 入门
        a.djr AS "djr",
        a.sycksl AS "sycksl",
        a.cyrdh AS "cyrdh",
        a.ckywlx AS "ckywlx",
        a.tzdcbid AS "tzdcbid",
        a.lyxz AS "lyxz",
        a.jhdID AS "jhdID",
        a.cydw AS "cydw",
        a.cyrdz AS "cyrdz",
        a.cph AS "cph",
        a.chID AS "chID",
        a.cd as "cd",
        a.scnf as "scnf",
        a.jhfl AS "jhfl",
        a.htbh AS "htbh",
        a.htID AS "htID",
        a.tzdID AS "tzdID",
        a.jhdbh AS "jhdbh",
        a.tzdbh AS "tzdbh",
        a.cllx AS "cllx",
        a.jhcksl AS "jhcksl",
        a.slrsfzh AS "slrsfzh",
        a.slr AS "slr",
        a.lspz AS "lspz",
        a.rcsj AS "rcsj",
        a.cchlx AS "cchlx",
        a.cyr AS "cyr",
        a.mxpz AS "mxpz",
        a.slrdh AS "slrdh",
        a.cyrsfzh AS "cyrsfzh",
        a.BizNo AS "BizNo",
        a.shdw AS "shdw",
        a.slrdz AS "slrdz",
        a.lydj AS "lydj",
        a.DataID AS "rmId",
        c.enumName as "lspzValue",
        d.enumName as "lyxzValue",
        e.enumName as "cdValue",
        f.enumName as "scnfValue",
        -- 称皮重
        b.jjdh AS "jjdh",
        b.pz AS "pz",
        b.jpsj AS "jpsj",
        b.sglryy AS "sglryy",
        b.pjy AS "pjy",
        b.nchwbh AS "nchwbh",
        b.ycchID AS "ycchID",
        b.ncchbh AS "ncchbh",
        b.ychwID AS "ychwID",
        b.DataID AS "DataID"
        FROM
        DATA_CRKYW_CKRMDJ_DEFAULT a
        LEFT JOIN DATA_CRKYW_CKCPZ_DEFAULT b ON a.BizNo = b.BizNo
        LEFT JOIN basic_enum c on a.lspz = c.enumId
        LEFT JOIN basic_enum d on a.lyxz = 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 != ""'>
                b.DataID = #{id}
            </if>
            <if test='bizNo != null and bizNo != ""'>
               and a.bizNo = #{bizNo}
            </if>

        </where>
    </select>
    <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.cydw AS "cydw",
	DATA_CRKYW_CKRMDJ_DEFAULT.tzdbh AS "tzdbh",
	DATA_CRKYW_CKRMDJ_DEFAULT.slr AS "slr",
	DATA_CRKYW_CKRMDJ_DEFAULT.cph AS "cph",
	DATA_CRKYW_CKRMDJ_DEFAULT.lspz AS "lspz",
	b_5.enumName AS "lspz_value",
	DATA_CRKYW_CKRMDJ_DEFAULT.BizNo AS "BizNo",
	DATA_CRKYW_CKRMDJ_DEFAULT.cyrdh AS "cyrdh",
	x.*
FROM
	DATA_CRKYW_CKRMDJ_DEFAULT
LEFT JOIN basic_enum b_5 ON DATA_CRKYW_CKRMDJ_DEFAULT.lspz = b_5.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 = '2'
	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_CKCPZ_DEFAULT.ModifyDate AS "ModifyDate",
        DATA_CRKYW_CKRMDJ_DEFAULT.cyr AS "cyr",
        DATA_CRKYW_CKRMDJ_DEFAULT.lspz AS "lspz",
        b_1.enumName AS "lspz_value",
        DATA_CRKYW_CKRMDJ_DEFAULT.cph AS "cph",
        DATA_CRKYW_CKRMDJ_DEFAULT.slr AS "slr",
        DATA_CRKYW_CKRMDJ_DEFAULT.cydw AS "cydw",
        DATA_CRKYW_CKCPZ_DEFAULT.jpsj AS "jpsj",
        DATA_CRKYW_CKCPZ_DEFAULT.pz AS "pz",
        DATA_CRKYW_CKCPZ_DEFAULT.pjy AS "pjy",
        DATA_CRKYW_CKCPZ_DEFAULT.ncchbh AS "ncchbh",
        DATA_CRKYW_CKCPZ_DEFAULT.BizNo AS "BizNo",
        DATA_CRKYW_CKCPZ_DEFAULT.sglryy AS "sglryy",
        DATA_CRKYW_CKCPZ_DEFAULT.nchwbh AS "nchwbh",
        DATA_CRKYW_CKCPZ_DEFAULT.DataID AS DataID
        FROM
        DATA_CRKYW_CKRMDJ_DEFAULT
        LEFT JOIN DATA_CRKYW_CKCPZ_DEFAULT ON DATA_CRKYW_CKRMDJ_DEFAULT.BizNo = DATA_CRKYW_CKCPZ_DEFAULT.BizNo
        LEFT JOIN basic_enum b_1 ON DATA_CRKYW_CKRMDJ_DEFAULT.lspz = b_1.enumId
        WHERE
        ifnull(
        DATA_CRKYW_CKCPZ_DEFAULT.SytelInfoID,
        ''
        ) = '4028814763a546b20163aade294b001d'
        AND DATA_CRKYW_CKCPZ_DEFAULT.PeriodID = '11'
        AND DATA_CRKYW_CKCPZ_DEFAULT.RoundId = 0
        <if test="ew.sqlSegment != null and ew.sqlSegment != ''">
            and ${ew.sqlSegment}
        </if>
    </select>
    <update id="updateCkRmdj"  >
        UPDATE data_crkyw_ckrmdj_default
    SET UPDATE_TIME = NULL,
     tzdID = NULL,
     sycksl = NULL,
     jhcksl = NULL,
     chID = NULL,
     lspz = NULL,
     mxpz = NULL,
     htID = NULL,
     jhdID = NULL,
     hwID = NULL,
     tzdbh = NULL,
     htbh = NULL,
     jhdbh = NULL,
     slrsfzh = NULL,
     slrdz = NULL,
     slr = NULL,
     slrdh = NULL,
     ckywlx = NULL,
     jhfl = NULL,
     tzdcbid = NULL,
     lyxz = NULL,
     rcsj = NULL,
     lydj = NULL,
     cydw = NULL,
     shdw = NULL,
     scnf = NULL,
     cd = NULL
    WHERE
        BizNo = #{bizNo}
    </update>
</mapper>