<?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.huimv.getdata.mapper.ErpBdDepartmentMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.huimv.getdata.entity.ErpBdDepartment">
        <id column="id" property="id" />
        <result column="fcreateorgid" property="fcreateorgid" />
        <result column="fcreatedate" property="fcreatedate" />
        <result column="fdeptid" property="fdeptid" />
        <result column="flocaleid" property="flocaleid" />
        <result column="fname" property="fname" />
        <result column="fdescription" property="fdescription" />
        <result column="ffullname" property="ffullname" />
        <result column="ffullnamehr" property="ffullnamehr" />
    </resultMap>
    <select id="getDep" resultType="com.huimv.getdata.entity.ErpBdDepartment">
        SELECT A.fcreateorgid , A.fcreatedate , A.fdeptid ,B.flocaleid
     ,B.flocaleid ,B.fname ,B.fdescription  ,B.ffullname,B.ffullnamehr
     FROM T_BD_DEPARTMENT  A
     INNER JOIN  T_BD_DEPARTMENT_L B ON A.FDEPTID = B.FDEPTID
    </select>
    <select id="getMaterial" resultType="com.huimv.getdata.entity.ErpBdMaterial">

        SELECT
    SUBSTRING(a.fnumber, 1, 6) AS fnumber
FROM
    [dbo].[T_BD_MATERIAL] a
WHERE
    a.fnumber LIKE '01%'
    AND a.FFORBIDSTATUS = 'A'
GROUP BY
    SUBSTRING(a.fnumber, 1, 6);
    </select>
    <select id="getMaterialDetail" resultType="com.huimv.getdata.entity.ErpMaterial"
            parameterType="java.lang.String">

        SELECT a.fnumber  , b.fuseorgid  facctorgid, b.FNAME fname ,b.FSPECIFICATION fspecification   FROM [dbo].[T_BD_MATERIAL]  a
inner join   T_BD_MATERIAL_L b on a.fmaterialid = b.fmaterialid
 where a.FFORBIDSTATUS = 'A'
 and  a.fnumber like #{fnumber}
    </select>
    <select id="getReagent" resultType="com.huimv.getdata.entity.ErpMaterial">
        SELECT a.fnumber  fnumber   , b.fuseorgid  facctorgid, b.FNAME fname ,b.FSPECIFICATION fspecification   FROM [dbo].[T_BD_MATERIAL]  a
inner join   T_BD_MATERIAL_L b on a.fmaterialid = b.fmaterialid
 where a.FFORBIDSTATUS = 'A'
 and  a.fnumber like '1003%'
    </select>
    <select id="getQuail" resultType="com.huimv.getdata.entity.ErpQuali">
        select a.FIncQcSchemeId  incQcSchemeId ,a.fmaterialid ,b.fname ,c.f_bgl_remark , c.f_bgl_text,c.f_bgl_text1  , e.fnumber,b.fuseorgid ,
        d.ftargetval ,d.fuplimit ,d.fdownlimit
        from T_BD_MATERIALQUALITY a
        inner join  T_BD_MATERIAL_L b on   a.fmaterialid = b.fmaterialid
        inner join T_BD_MATERIAL e on e.fmaterialid = b.fmaterialid
        right join  T_QM_QCSCHEMEENTRY c on  a.FIncQcSchemeId = c.fid
        inner join  T_QM_QCSCHEMEENTRY_A d  on  c.fentryid = d.fentryid

        where   a.FIncQcSchemeId is not null
        order by  a.FIncQcSchemeId  desc

    </select>
    <select id="getQuailIbit" resultType="com.huimv.getdata.entity.ErpQualiQm">

        select a.FBILLNO  FBILLNO,  a.FCREATEDATE  FCREATEDATE, a.FINSPECTORGID  FINSPECTORGID, b.fInspectStartDate  inspectStartDate, b.FLOT  FLOT,b.FWORKSHOPID FWORKSHOPID ,
         b.fInspectEndDate inspectEndDate, a.FINSPECTDEPID  FINSPECTDEPID, b.FQCSCHEMEID  FQCSCHEMEID,b.FINSPECTQTY FINSPECTQTY,
         b.fentryid fentryid,
         e.f_BGL_TEXT20 fbgltext20
         , e.f_BGL_REMARKS fbglremarks
         , e.F_BGL_TEXT16 fbgltext16,
        c.FMATERIALID  FMATERIALID
        ,c.FINSPECTRESULT  FINSPECTRESULT
        ,d.fname fname


         from T_QM_INSPECTBILL a
        inner join  T_QM_INSPECTBILLENTRY b on a.fid = b.fid
        inner  join T_QM_INSPECTBILLENTRY_A  c on a.fid = c.fid
        inner join T_BD_MATERIAL_L d on c.FMATERIALID = d.FMATERIALID
        right  join T_QM_IBITEMDETAIL e on e.fentryid = b.fentryid

    </select>
    <select id="getMaterialRaw" resultType="com.huimv.getdata.entity.ErpBdMaterial">
     SELECT a.fnumber  fnumber   , b.fuseorgid  facctorgid, b.FNAME fname ,b.FSPECIFICATION fspecification   FROM [dbo].[T_BD_MATERIAL]  a
    inner join   T_BD_MATERIAL_L b on a.fmaterialid = b.fmaterialid
     where a.FFORBIDSTATUS = 'A'
    --and  a.fnumber like '10%'
    </select>

</mapper>
