<?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.purchaseAndSalesSupervision.modular.yjbj.mapper.YjbjMapper">
    <select id="selectZqlListPage" resultType="com.unis.purchaseAndSalesSupervision.modular.yjbj.entity.ZqlTable" parameterType="map">
        select
        id,
        publish_time as alarmPublishTime,
        offender as offender,
        library_point_name as involvingLibraryPoints,
        violation_type as violationType,
        detail as violationDetail,
        disposer as disposer,
        dispose_content as disposeContent,
        dispose_time as disposeTime,
        subject_type as violationSubjectType,
        status as currentStatus,
        org_id as orgId,
        create_time as createTime
        from
        storage_pre_violation
        where 1=1
        <if test="record.orgId != null">
            and org_id = #{record.orgId}
        </if>
        <if test="record.startDate != null">
            and publish_time &gt;= #{record.startDate}
        </if>
        <if test="record.endDate != null">
            and publish_time &lt;= #{record.endDate}
        </if>
        order by publish_time desc
    </select>

    <select id="queryZqlById" resultType="com.unis.purchaseAndSalesSupervision.modular.yjbj.entity.ZqlTable">
        select
            id,
            publish_time as alarmPublishTime,
            offender as offender,
            library_point_name as involvingLibraryPoints,
            violation_type as violationType,
            detail as violationDetail,
            disposer as disposer,
            dispose_content as disposeContent,
            dispose_time as disposeTime,
            subject_type as violationSubjectType,
            status as currentStatus,
            org_id as orgId,
            create_time as createTime
        from storage_pre_violation
        where id = #{id,jdbcType=INTEGER}
    </select>

    <select id="selectLhList" resultType="com.unis.purchaseAndSalesSupervision.modular.yjbj.entity.StorageRotationWarning" parameterType="map">
        select
        srw.id, srw.ch, srw.hwh, srw.lspz, srw.lsxz,srw.kcsl, srw.scnf, srw.zhycrq, srw.cbnx, srw.cccxrq, srw.bjrq, srw.bjlx, srw.clzt, srw.clr,
        srw.clsj, srw.org_id, srw.scsj, srw.updatetime, srw.remark, srw.clyj,bs.storehouse_name storehouseName
        from depot_qh.storage_rotation_warning srw
        left join depot_qh.basic_storehouse bs on bs.storehouse_id=srw.ch
        where 1=1
        <if test="record.bjlx != null">
            and srw.bjlx = #{record.bjlx, jdbcType=VARCHAR}
        </if>
        <if test="record.orgId != null">
            and srw.org_id = #{record.orgId, jdbcType=INTEGER}
        </if>
        <if test="record.lspz != null">
            and srw.lspz = #{record.lspz, jdbcType=INTEGER}
        </if>
        <if test="record.ch != null">
            and srw.ch = #{record.ch, jdbcType=INTEGER}
        </if>
        <if test="record.startTime != null">
            and srw.STR_TO_DATE(zhycrq, '%Y-%m-%d %H:%i:%s') >= #{record.startTime, jdbcType=VARCHAR}
        </if>
        <if test="record.endTime != null">
            and srw.STR_TO_DATE(zhycrq, '%Y-%m-%d %H:%i:%s') &lt;= #{record.endTime, jdbcType=VARCHAR}
        </if>
        order by srw.scsj desc
    </select>

    <select id="queryLhById" parameterType="java.lang.String" resultType="com.unis.purchaseAndSalesSupervision.modular.yjbj.entity.StorageRotationWarning">
        select
            id, ch, hwh, lspz, lsxz, kcsl, scnf, zhycrq, cbnx, cccxrq, bjrq, bjlx, clzt, clr,
            clsj, org_id, scsj, updatetime, remark, clyj
        from depot_qh.storage_rotation_warning
        where id = #{id,jdbcType=VARCHAR}
    </select>

    <select id="selectCjkqList" resultType="com.unis.purchaseAndSalesSupervision.modular.yjbj.entity.StorageJkqWarning" parameterType="map">
        select
        srw.id, srw.org_id, srw.ch, srw.hwh, srw.jhwh, srw.lhnd, srw.jkqzt, srw.jkqjzr, srw.jzrqylrsl, srw.jzrqsylrsl, srw.yjrq, srw.clzt,
        srw.clr, srw.clsj, srw.scsj, srw.updatetime, srw.clyj,bs.storehouse_name storehouseName,bw.warehouse_name warehouseName
        from depot_qh.storage_jkq_warning srw
        left join depot_qh.basic_storehouse bs on bs.storehouse_id=srw.ch
        left join depot_qh.basic_warehouse bw on bw.warehouse_id=srw.hwh
        where 1=1
        <if test="record.orgId != null">
            and org_id = #{record.orgId, jdbcType=INTEGER}
        </if>
        <if test="record.lhnd != null">
            and lhnd = #{record.lhnd, jdbcType=VARCHAR}
        </if>
        <if test="record.jkqzt != null">
            and jkqzt = #{record.jkqzt, jdbcType=VARCHAR}
        </if>
        order by scsj desc
    </select>

    <select id="queryCjkqById" resultType="com.unis.purchaseAndSalesSupervision.modular.yjbj.entity.StorageJkqWarning">
        select
            id, org_id, ch, hwh, jhwh, lhnd, jkqzt, jkqjzr, jzrqylrsl, jzrqsylrsl, yjrq, clzt,
            clr, clsj, scsj, updatetime, clyj
        from depot_qh.storage_jkq_warning
        where id = #{id,jdbcType=VARCHAR}
    </select>

    <select id="getXwcjfxList" parameterType="com.unis.purchaseAndSalesSupervision.modular.yjbj.param.XwcjfxPageParam" resultType="java.util.List">
        select * from (
        SELECT
            a.cph,
            a.UnitID,
            d.org_name orgName,
            b.sjchID,
            g.storehouse_name cfmc,
            DATE_FORMAT(a.rcsj, '%Y-%m-%d %H:%i:%s') rcsj,-- 出入库时间
            a.lspz,
            e.enumname lspzmc,
            a.lydj,
            e2.enumname lsdjmc,
            b.xzklhjz jz,
            '入库' ywlx,
            DATE_FORMAT(c.cmsj, '%Y-%m-%d %H:%i:%s') cmsj -- 出门时间
        FROM
            depot_qh.data_crkyw_rmdj_default a
                INNER JOIN depot_qh.data_crkyw_cpz_default b ON a.BizNo = b.BizNo
                INNER JOIN depot_qh.data_crkyw_rkcm_default c ON a.BizNo = c.BizNo
                INNER JOIN depot_qh.data_crkyw_cmz_default f ON a.BizNo = f.BizNo
                INNER JOIN depot_qh.org_info d ON d.org_id = a.UnitID
                INNER JOIN depot_qh.basic_enum e ON e.enumId = a.lspz
                INNER JOIN depot_qh.basic_enum e2 ON e2.enumId = a.lydj
                INNER JOIN depot_qh.basic_storehouse g ON g.storehouse_id = b.sjchID
        UNION
        SELECT
            a.cph,
            a.UnitID,
            d.org_name orgName,
            w.chID,
            g.storehouse_name cfmc,
            DATE_FORMAT(a.rcsj, '%Y-%m-%d %H:%i:%s') rcsj,-- 出入库时间
            a.lspz,
            e.enumname lspzmc,
            a.lydj,
            e2.enumname lsdjmc,
            b.klhjz jz,
            '出库' ywlx,
            DATE_FORMAT(c.cmsj, '%Y-%m-%d %H:%i:%s') cmsj -- 出门时间
        FROM
            depot_qh.data_crkyw_ckrmdj_default a
                INNER JOIN depot_qh.data_crkyw_ckcmz_default b ON a.BizNo = b.BizNo
                INNER JOIN depot_qh.data_crkyw_ckcm_default c ON a.BizNo = c.BizNo
                INNER JOIN depot_qh.data_crkyw_ckcpz_default w ON a.BizNo = w.BizNo
                INNER JOIN depot_qh.org_info d ON d.org_id = a.UnitID
                INNER JOIN depot_qh.basic_enum e ON e.enumId = a.lspz
                INNER JOIN depot_qh.basic_enum e2 ON e2.enumId = a.lydj
                INNER JOIN depot_qh.basic_storehouse g ON g.storehouse_id = w.chID
        )a
         where 1=1
            <if test="xwcjfxPageParam.orgName != null">
                and orgName like concat("%",#{xwcjfxPageParam.orgName},"%")
            </if>
            <if test="xwcjfxPageParam.cph != null">
                and cph like concat("%",#{xwcjfxPageParam.cph},"%")
            </if>
            <if test="xwcjfxPageParam.crksj != null">
                and rcsj = #{xwcjfxPageParam.crksj}
            </if>
        ORDER BY rcsj
    </select>

    <select id="getCkjhzxjgList" parameterType="com.unis.purchaseAndSalesSupervision.modular.yjbj.param.XwcjfxPageParam" resultType="java.util.List">
        SELECT
            -- a.id,
            a.org_id,
            o.org_name orgName,
            a.grain_variety_id,
            e.enumname pzmc,
            a.basic_storehouse_id,
            s.storehouse_name jhcf,
            c.plan_number planNumber,
            d.ycchID,
            s1.storehouse_name zxcf,
            d.BuildDate yjsj,
            u.dwmc qymc
        FROM
            depot_qh.business_rp_outbound a
                INNER JOIN depot_qh.business_rp_report b ON b.id = a.rp_report_id
                INNER JOIN province_all.biz_rp_issuance c ON b.id = c.rp_report_id
                INNER JOIN depot_qh.data_crkyw_ckcpz_default d ON d.jhdbh = c.plan_number
                INNER JOIN depot_qh.org_info o ON o.org_id = a.org_id
                INNER JOIN depot_qh.basic_storehouse s ON s.storehouse_id = a.basic_storehouse_id
                INNER JOIN depot_qh.basic_storehouse s1 ON s1.storehouse_id = d.ycchID
                INNER JOIN depot_qh.basic_enum e ON e.enumId = a.grain_variety_id
                INNER JOIN province_all.biz_unit_info u ON u.id = b.unit_info_id
        WHERE
            a.basic_storehouse_id != d.chID
          <if test="xwcjfxPageParam.qymc != null">
              and u.dwmc like concat("%",#{xwcjfxPageParam.qymc},"%")
          </if>
    </select>

</mapper>