<?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="cn.timer.api.dao.zcgl.ZcglAdminZccrkglMapper">

    <resultMap id="BaseResultMap" type="cn.timer.api.bean.zcgl.ZcglAdminZccrkgl" >
                <id column="id" property="id" />
                <result column="rkpc" property="rkpc" />
                <result column="zcbh" property="zcbh" />
                <result column="zcmc" property="zcmc" />
                <result column="zcggxh" property="zcggxh" />
                <result column="zcsl" property="zcsl" />
                <result column="zcdw" property="zcdw" />
                <result column="jine" property="jine" />
                <result column="cfd" property="cfd" />
                <result column="grsj_time" property="grsjTime" />
                <result column="yxq" property="yxq" />
                <result column="scrq_time" property="scrqTime" />
                <result column="status" property="status" />
                <result column="zhbjr" property="zhbjr" />
                <result column="zhbjsj_time" property="zhbjsjTime" />
                <result column="org_code" property="orgCode" />
                <result column="gly" property="gly" />
                <result column="sybm" property="sybm" />
                <result column="syqx" property="syqx" />
                <result column="zcly_type" property="zclyType" />
                <result column="zcbz" property="zcbz" />
                <result column="zctu" property="zctu" />
                <result column="zcgys" property="zcgys" />
                <result column="lxr" property="lxr" />
                <result column="lxfs_type" property="lxfsType" />
                <result column="fzr" property="fzr" />
                <result column="wbdqr_time" property="wbdqrTime" />
                <result column="wbsm" property="wbsm" />
                <result column="cksj_time" property="cksjTime" />
                <result column="ckyy" property="ckyy" />
                <result column="cksm" property="cksm" />
                <result column="ckryid" property="ckryid" />
    </resultMap>

    <sql id="Base_Column_List">
                id,
                rkpc,
                zcbh,
                zcmc,
                zclb_type,
                zcggxh,
                zcsl,
                zcdw,
                jine,
                cfd,
                grsj_time,
                yxq,
                scrq_time,
                status,
                zhbjr,
                zhbjsj_time,
                org_code,
                gly,
                sybm,
                syrid,
                syqx,
                zcly_type,
                is_sfgk,
                zcbz,
                zctu,
                zcgys,
                lxr,
                lxfs_type,
                fzr,
                wbdqr_time,
                wbsm,
                cksj_time,
                ckyy,
                cksm,
                ckryid
    </sql>
    
    <sql id="Base_Column_List_Alias">
                id ZcglAdminZccrkgl_id,
                rkpc ZcglAdminZccrkgl_rkpc,
                zcbh ZcglAdminZccrkgl_zcbh,
                zcmc ZcglAdminZccrkgl_zcmc,
                zclb_type ZcglAdminZccrkgl_zclb_type,
                zcggxh ZcglAdminZccrkgl_zcggxh,
                zcsl ZcglAdminZccrkgl_zcsl,
                zcdw ZcglAdminZccrkgl_zcdw,
                jine ZcglAdminZccrkgl_jine,
                cfd ZcglAdminZccrkgl_cfd,
                grsj_time ZcglAdminZccrkgl_grsj_time,
                yxq ZcglAdminZccrkgl_yxq,
                scrq_time ZcglAdminZccrkgl_scrq_time,
                status ZcglAdminZccrkgl_status,
                zhbjr ZcglAdminZccrkgl_zhbjr,
                zhbjsj_time ZcglAdminZccrkgl_zhbjsj_time,
                org_code ZcglAdminZccrkgl_org_code,
                gly ZcglAdminZccrkgl_gly,
                sybm ZcglAdminZccrkgl_sybm,
                syrid ZcglAdminZccrkgl_syrid,
                syqx ZcglAdminZccrkgl_syqx,
                zcly_type ZcglAdminZccrkgl_zcly_type,
                is_sfgk ZcglAdminZccrkgl_is_sfgk,
                zcbz ZcglAdminZccrkgl_zcbz,
                zctu ZcglAdminZccrkgl_zctu,
                zcgys ZcglAdminZccrkgl_zcgys,
                lxr ZcglAdminZccrkgl_lxr,
                lxfs_type ZcglAdminZccrkgl_lxfs_type,
                fzr ZcglAdminZccrkgl_fzr,
                wbdqr_time ZcglAdminZccrkgl_wbdqr_time,
                wbsm ZcglAdminZccrkgl_wbsm,
                cksj_time ZcglAdminZccrkgl_cksj_time,
                ckyy ZcglAdminZccrkgl_ckyy,
                cksm ZcglAdminZccrkgl_cksm,
                ckryid ZcglAdminZccrkgl_ckryid
    </sql>

	<!-- 查询出入库数量(按年) -->
	<select id="queryRkByYear" parameterType="java.lang.Integer"  resultType="cn.timer.api.dto.zcgl.ZcglTjtDto">
		SELECT
			YEAR(grsj_time) year,
			SUM(zcsl) sum
		FROM
			zcgl_admin_zccrkgl
		WHERE
			org_code = #{orgCode}
		GROUP BY
			YEAR(grsj_time)
		ORDER BY
			grsj_time
	</select>
	
	<select id="queryCkByYear" parameterType="java.lang.Integer"  resultType="cn.timer.api.dto.zcgl.ZcglTjtDto">
		SELECT
			YEAR(cksj_time) year,
			SUM(zcsl) sum
		FROM
			zcgl_admin_zccrkgl
		WHERE
			org_code = #{orgCode}
		GROUP BY
			YEAR(cksj_time)
		ORDER BY
			cksj_time
	</select>

	<!-- 查询出入库数量(按月份) -->
	<select id="queryRkByMonth" resultType="cn.timer.api.dto.zcgl.ZcglTjtDto">
		SELECT
			EXTRACT(YEAR_MONTH FROM grsj_time) yearMonth,
			SUM(zcsl) sum
		FROM
			zcgl_admin_zccrkgl
		WHERE
			EXTRACT(YEAR_MONTH FROM grsj_time)
		AND org_code = #{orgCode}
		AND YEAR (grsj_time) = #{year}
		GROUP BY
			EXTRACT(YEAR_MONTH FROM grsj_time)
		ORDER BY
			grsj_time
	</select>
	<select id="queryCkByMonth" resultType="cn.timer.api.dto.zcgl.ZcglTjtDto">
		SELECT
			EXTRACT(YEAR_MONTH FROM cksj_time) yearMonth,
			SUM(zcsl) sum
		FROM
			zcgl_admin_zccrkgl
		WHERE
			EXTRACT(YEAR_MONTH FROM cksj_time)
		AND org_code = #{orgCode}
		AND YEAR (cksj_time) = #{year}
		GROUP BY
			EXTRACT(YEAR_MONTH FROM cksj_time)
		ORDER BY
			cksj_time
	</select>
	
	<!-- 查询出入库数量(按日期) -->
	<select id="queryRkByDay" parameterType="java.lang.Integer"  resultType="cn.timer.api.dto.zcgl.ZcglTjtDto">
		SELECT
			EXTRACT(YEAR_MONTH FROM grsj_time) yearMonth,
			EXTRACT(DAY FROM grsj_time) day,
			SUM(zcsl) sum
		FROM
			zcgl_admin_zccrkgl
		WHERE
			org_code = #{orgCode}
		AND 
			EXTRACT(YEAR_MONTH FROM grsj_time) = #{yearMonth}
		GROUP BY
			EXTRACT(DAY FROM grsj_time)
		ORDER BY
			grsj_time
	</select>
	<select id="queryCkByDay" parameterType="java.lang.Integer"  resultType="cn.timer.api.dto.zcgl.ZcglTjtDto">
		SELECT
			EXTRACT(YEAR_MONTH FROM cksj_time) yearMonth,
			EXTRACT(DAY FROM cksj_time) day,
			SUM(zcsl) sum
		FROM
			zcgl_admin_zccrkgl
		WHERE
			org_code = #{orgCode}
		AND 
			EXTRACT(YEAR_MONTH FROM cksj_time) = #{yearMonth}
		GROUP BY
			EXTRACT(DAY FROM cksj_time)
		ORDER BY
			cksj_time
	</select>
	
	
	<!-- 

    <insert id="insert" useGeneratedKeys="true" keyColumn="id" parameterType="cn.timer.api.bean.zcgl.ZcglAdminZccrkgl">
        INSERT INTO zcgl_admin_zccrkgl
        <trim prefix="(" suffix=")" suffixOverrides=",">
                        <if test ='null != rkpc'>
                        rkpc,
                        </if>
                        <if test ='null != zcbh'>
                        zcbh,
                        </if>
                        <if test ='null != zcmc'>
                        zcmc,
                        </if>
                        <if test ='null != zclbType'>
                        zclb_type,
                        </if>
                        <if test ='null != zcggxh'>
                        zcggxh,
                        </if>
                        <if test ='null != zcsl'>
                        zcsl,
                        </if>
                        <if test ='null != zcdw'>
                        zcdw,
                        </if>
                        <if test ='null != jine'>
                        jine,
                        </if>
                        <if test ='null != cfd'>
                        cfd,
                        </if>
                        <if test ='null != grsjTime'>
                        grsj_time,
                        </if>
                        <if test ='null != yxq'>
                        yxq,
                        </if>
                        <if test ='null != scrqTime'>
                        scrq_time,
                        </if>
                        <if test ='null != status'>
                        status,
                        </if>
                        <if test ='null != zhbjr'>
                        zhbjr,
                        </if>
                        <if test ='null != zhbjsjTime'>
                        zhbjsj_time,
                        </if>
                        <if test ='null != orgCode'>
                        org_code,
                        </if>
                        <if test ='null != gly'>
                        gly,
                        </if>
                        <if test ='null != sybm'>
                        sybm,
                        </if>
                        <if test ='null != syrid'>
                        syrid,
                        </if>
                        <if test ='null != syqx'>
                        syqx,
                        </if>
                        <if test ='null != zclyType'>
                        zcly_type,
                        </if>
                        <if test ='null != isSfgk'>
                        is_sfgk,
                        </if>
                        <if test ='null != zcbz'>
                        zcbz,
                        </if>
                        <if test ='null != zctu'>
                        zctu,
                        </if>
                        <if test ='null != zcgys'>
                        zcgys,
                        </if>
                        <if test ='null != lxr'>
                        lxr,
                        </if>
                        <if test ='null != lxfsType'>
                        lxfs_type,
                        </if>
                        <if test ='null != fzr'>
                        fzr,
                        </if>
                        <if test ='null != wbdqrTime'>
                        wbdqr_time,
                        </if>
                        <if test ='null != wbsm'>
                        wbsm,
                        </if>
                        <if test ='null != cksjTime'>
                        cksj_time,
                        </if>
                        <if test ='null != ckyy'>
                        ckyy,
                        </if>
                        <if test ='null != cksm'>
                        cksm,
                        </if>
                        <if test ='null != ckryid'>
                        ckryid
                        </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                        <if test ='null != rkpc'>
                        #{rkpc},
                        </if>
                        <if test ='null != zcbh'>
                        #{zcbh},
                        </if>
                        <if test ='null != zcmc'>
                        #{zcmc},
                        </if>
                        <if test ='null != zclbType'>
                        #{zclbType},
                        </if>
                        <if test ='null != zcggxh'>
                        #{zcggxh},
                        </if>
                        <if test ='null != zcsl'>
                        #{zcsl},
                        </if>
                        <if test ='null != zcdw'>
                        #{zcdw},
                        </if>
                        <if test ='null != jine'>
                        #{jine},
                        </if>
                        <if test ='null != cfd'>
                        #{cfd},
                        </if>
                        <if test ='null != grsjTime'>
                        #{grsjTime},
                        </if>
                        <if test ='null != yxq'>
                        #{yxq},
                        </if>
                        <if test ='null != scrqTime'>
                        #{scrqTime},
                        </if>
                        <if test ='null != status'>
                        #{status},
                        </if>
                        <if test ='null != zhbjr'>
                        #{zhbjr},
                        </if>
                        <if test ='null != zhbjsjTime'>
                        #{zhbjsjTime},
                        </if>
                        <if test ='null != orgCode'>
                        #{orgCode},
                        </if>
                        <if test ='null != gly'>
                        #{gly},
                        </if>
                        <if test ='null != sybm'>
                        #{sybm},
                        </if>
                        <if test ='null != syrid'>
                        #{syrid},
                        </if>
                        <if test ='null != syqx'>
                        #{syqx},
                        </if>
                        <if test ='null != zclyType'>
                        #{zclyType},
                        </if>
                        <if test ='null != isSfgk'>
                        #{isSfgk},
                        </if>
                        <if test ='null != zcbz'>
                        #{zcbz},
                        </if>
                        <if test ='null != zctu'>
                        #{zctu},
                        </if>
                        <if test ='null != zcgys'>
                        #{zcgys},
                        </if>
                        <if test ='null != lxr'>
                        #{lxr},
                        </if>
                        <if test ='null != lxfsType'>
                        #{lxfsType},
                        </if>
                        <if test ='null != fzr'>
                        #{fzr},
                        </if>
                        <if test ='null != wbdqrTime'>
                        #{wbdqrTime},
                        </if>
                        <if test ='null != wbsm'>
                        #{wbsm},
                        </if>
                        <if test ='null != cksjTime'>
                        #{cksjTime},
                        </if>
                        <if test ='null != ckyy'>
                        #{ckyy},
                        </if>
                        <if test ='null != cksm'>
                        #{cksm},
                        </if>
                        <if test ='null != ckryid'>
                        #{ckryid}
                        </if>
        </trim>
    </insert>

    <delete id="delete" >
        DELETE FROM zcgl_admin_zccrkgl
        WHERE id = #{id}
    </delete>

    <update id="update" parameterType="cn.timer.api.bean.zcgl.ZcglAdminZccrkgl">
        UPDATE zcgl_admin_zccrkgl
        <set>
                    <if test ='null != rkpc'>rkpc = #{rkpc},</if>
                    <if test ='null != zcbh'>zcbh = #{zcbh},</if>
                    <if test ='null != zcmc'>zcmc = #{zcmc},</if>
                    <if test ='null != zclbType'>zclb_type = #{zclbType},</if>
                    <if test ='null != zcggxh'>zcggxh = #{zcggxh},</if>
                    <if test ='null != zcsl'>zcsl = #{zcsl},</if>
                    <if test ='null != zcdw'>zcdw = #{zcdw},</if>
                    <if test ='null != jine'>jine = #{jine},</if>
                    <if test ='null != cfd'>cfd = #{cfd},</if>
                    <if test ='null != grsjTime'>grsj_time = #{grsjTime},</if>
                    <if test ='null != yxq'>yxq = #{yxq},</if>
                    <if test ='null != scrqTime'>scrq_time = #{scrqTime},</if>
                    <if test ='null != status'>status = #{status},</if>
                    <if test ='null != zhbjr'>zhbjr = #{zhbjr},</if>
                    <if test ='null != zhbjsjTime'>zhbjsj_time = #{zhbjsjTime},</if>
                    <if test ='null != orgCode'>org_code = #{orgCode},</if>
                    <if test ='null != gly'>gly = #{gly},</if>
                    <if test ='null != sybm'>sybm = #{sybm},</if>
                    <if test ='null != syrid'>syrid = #{syrid},</if>
                    <if test ='null != syqx'>syqx = #{syqx},</if>
                    <if test ='null != zclyType'>zcly_type = #{zclyType},</if>
                    <if test ='null != isSfgk'>is_sfgk = #{isSfgk},</if>
                    <if test ='null != zcbz'>zcbz = #{zcbz},</if>
                    <if test ='null != zctu'>zctu = #{zctu},</if>
                    <if test ='null != zcgys'>zcgys = #{zcgys},</if>
                    <if test ='null != lxr'>lxr = #{lxr},</if>
                    <if test ='null != lxfsType'>lxfs_type = #{lxfsType},</if>
                    <if test ='null != fzr'>fzr = #{fzr},</if>
                    <if test ='null != wbdqrTime'>wbdqr_time = #{wbdqrTime},</if>
                    <if test ='null != wbsm'>wbsm = #{wbsm},</if>
                    <if test ='null != cksjTime'>cksj_time = #{cksjTime},</if>
                    <if test ='null != ckyy'>ckyy = #{ckyy},</if>
                    <if test ='null != cksm'>cksm = #{cksm},</if>
                    <if test ='null != ckryid'>ckryid = #{ckryid}</if>
        </set>
        WHERE id = #{id}
    </update>


    <select id="load" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List" />
        FROM zcgl_admin_zccrkgl
        WHERE id = #{id}
    </select>

    <select id="pageList" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List" />
        FROM zcgl_admin_zccrkgl
        LIMIT #{offset}, #{pageSize}
    </select>

    <select id="pageListCount" resultType="java.lang.Integer">
        SELECT count(1)
        FROM zcgl_admin_zccrkgl
    </select>

	 -->

</mapper>