Newer
Older
huludao / src / main / resources / mapper / project / FactoryHistoryDataMapper.xml
<?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.xf.huludao.project.dao.FactoryHistoryDataMapper">

    <!-- 通用映射列 -->
    <resultMap id="BaseResultMap" type="com.xf.huludao.project.entity.FactoryHistoryData">
        <result column="id" property="id"/>
        <result column="factory_id" property="factoryId"/>
        <result column="factroy_name" property="factroyName"/>
        <result column="data_create_time" property="dataCreateTime"/>
        <result column="flow_in" property="flowIn"/>
        <result column="flow_out" property="flowOut"/>
        <result column="cod_in" property="codIn"/>
        <result column="cod_out" property="codOut"/>
        <result column="data_p_in" property="dataPIn"/>
        <result column="data_p_out" property="dataPOut"/>
        <result column="data_n_in" property="dataNIn"/>
        <result column="data_n_out" property="dataNOut"/>
        <result column="nh_in" property="nhIn"/>
        <result column="nh_out" property="nhOut"/>
        <result column="ph_in" property="phIn"/>
        <result column="ph_out" property="phOut"/>
        <result column="description" property="description"/>
        <result column="create_time" property="createTime"/>
        <result column="create_user" property="createUser"/>
        <result column="update_time" property="updateTime"/>
        <result column="update_user" property="updateUser"/>
        <result column="is_deleted" property="isDeleted"/>
        <result column="status" property="status"/>
        <result column="create_dept" property="createDept"/>
        <result column="factory_code" property="factroyCode"/>
    </resultMap>

    <!-- 通用数据库列 -->
    <sql id="Base_Column_List">
              id,
              factory_id,
              factroy_name,
              data_create_time,
              flow_in,
              flow_out,
              cod_in,
              cod_out,
              data_p_in,
              data_p_out,
              data_n_in,
              data_n_out,
              nh_in,
              nh_out,
              ph_in,
              ph_out,
              bod_in,
              bod_out,
              ss_in,
              ss_out,
              description,
              create_time,
              create_user,
              update_time,
              update_user,
              is_deleted,
              status,
              create_dept
          </sql>

    <sql id="Where_Condition">
        <if test="request.id != null and request.id != ''">
            and id = #{request.id}
        </if>
        <if test="request.factoryId != null and request.factoryId != ''">
            and factory_id = #{request.factoryId}
        </if>
        <if test="request.factroyName != null and request.factroyName != ''">
            and factroy_name = #{request.factroyName}
        </if>
        <if test="request.dataCreateTime != null and request.dataCreateTime != ''">
            and data_create_time = #{request.dataCreateTime}
        </if>
        <if test="request.flowIn != null and request.flowIn != ''">
            and flow_in = #{request.flowIn}
        </if>
        <if test="request.flowOut != null and request.flowOut != ''">
            and flow_out = #{request.flowOut}
        </if>
        <if test="request.codIn != null and request.codIn != ''">
            and cod_in = #{request.codIn}
        </if>
        <if test="request.codOut != null and request.codOut != ''">
            and cod_out = #{request.codOut}
        </if>
        <if test="request.dataPIn != null and request.dataPIn != ''">
            and data_p_in = #{request.dataPIn}
        </if>
        <if test="request.dataPOut != null and request.dataPOut != ''">
            and data_p_out = #{request.dataPOut}
        </if>
        <if test="request.dataNOut != null and request.dataNOut != ''">
            and data_n_out = #{request.dataNOut}
        </if>
        <if test="request.dataNIn != null and request.dataNIn != ''">
            and data_n_in = #{request.dataNIn}
        </if>
        <if test="request.nhIn != null and request.nhIn != ''">
            and nh_in = #{request.nhIn}
        </if>
        <if test="request.nhOut != null and request.nhOut != ''">
            and nh_out = #{request.nhOut}
        </if>
        <if test="request.phIn != null and request.phIn != ''">
            and ph_in = #{request.phIn}
        </if>
        <if test="request.phOut != null and request.phOut != ''">
            and ph_out = #{request.phOut}
        </if>

        <if test="request.bodIn != null and request.bodIn != ''">
            and bod_in = #{request.bodIn}
        </if>
        <if test="request.bodOut != null and request.bodOut != ''">
            and bod_out = #{request.bodOut}
        </if>

        <if test="request.ssIn != null and request.ssIn != ''">
            and ss_in = #{request.ssIn}
        </if>
        <if test="request.ssOut != null and request.ssOut != ''">
            and ss_out = #{request.ssOut}
        </if>

        <if test="request.description != null and request.description != ''">
            and description = #{request.description}
        </if>
        <if test="request.createTime != null and request.createTime != ''">
            and create_time = #{request.createTime}
        </if>
        <if test="request.createUser != null and request.createUser != ''">
            and create_user = #{request.createUser}
        </if>
        <if test="request.updateTime != null and request.updateTime != ''">
            and update_time = #{request.updateTime}
        </if>
        <if test="request.updateUser != null and request.updateUser != ''">
            and update_user = #{request.updateUser}
        </if>
        <if test="request.isDeleted != null and request.isDeleted != ''">
            and is_deleted = #{request.isDeleted}
        </if>
        <if test="request.status != null and request.status != ''">
            and status = #{request.status}
        </if>
        <if test="request.createDept != null and request.createDept != ''">
            and create_dept = #{request.createDept}
        </if>
        <if test="request.startTime != null ">
            and data_create_time &gt; #{request.startTime}
        </if>

        <if test="request.endTime != null">
            and data_create_time &lt; #{request.endTime}
        </if>

    </sql>

    <select id="selectByCondition" resultMap="BaseResultMap">
        select
        fhd.id,
        fhd.factory_id,
        fhd.factroy_name,
        fhd.data_create_time,
        fhd.flow_in,
        fhd.flow_out,
        fhd.cod_in,
        fhd.cod_out,
        fhd.data_p_in,
        fhd.data_p_out,
        fhd.data_n_in,
        fhd.data_n_out,
        fhd.nh_in,
        fhd.nh_out,
        fhd.ph_in,
        fhd.ph_out,
        fhd.bod_in,
        fhd.bod_out,
        fhd.ss_in,
        fhd.ss_out,
        fhd.description,
        fhd.create_time,
        fhd.create_user,
        fhd.update_time,
        fhd.update_user,
        fhd.is_deleted,
        fhd.status,
        fhd.create_dept,
        u.user_name as createUserName,
        fbd.factory_code
        from factory_history_data fhd
        left join huludao_main.sys_user_info u ON u.id = fhd.create_user
        left join factory_base_data fbd on fhd.factory_id = fbd.id
        where fhd.is_deleted = 0
        <include refid="Where_Condition"/>
        order by fhd.data_create_time desc
    </select>

    <select id="exportFactoryHistoryData" resultType="com.xf.huludao.project.entity.FactoryHistoryData">
        SELECT * FROM factory_history_data ${ew.customSqlSegment}
    </select>

    <select id="hasData" resultMap="BaseResultMap">
        select * from factory_history_data where to_days(data_create_time) = to_days(#{time})
        and factory_id = #{factoryId}
        <if test="id != null">
            and id != #{id}
        </if>
        limit 1
    </select>
</mapper>