MachineTranslateServiceDaoImplMapper.xml 12.6 KB
<?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="machineTranslateServiceDaoImpl">


    <!-- 保存设备同步信息 add by wuxw 2018-07-03 -->
    <insert id="saveMachineTranslate" parameterType="Map">
        insert into machine_translate(
        machine_id,machine_code,status_cd,type_cd,machine_translate_id,obj_id,obj_name,state,community_id,b_id,machine_cmd,obj_b_id,remark
        ) values (
        #{machineId},#{machineCode},'0',#{typeCd},#{machineTranslateId},#{objId},#{objName},#{state},#{communityId},#{bId},#{machineCmd},
        #{objBId},#{remark}
        )
    </insert>
    <update id="updateMachineTranslate" parameterType="Map">
        update machine_translate t set
        <if test="statusCd !=null and statusCd != ''">
            t.status_cd= #{statusCd},
        </if>
        <if test="state !=null and state != ''">
            t.state= #{state},
        </if>
        <if test="updateTime !=null ">
            t.update_time= #{updateTime},
        </if>
        <if test="remark !=null and remark != ''">
            t.remark= #{remark}
        </if>

        where 1=1
        <if test="communityId !=null and communityId != ''">
            and t.community_id= #{communityId}
        </if>
        <if test="objId !=null and objId != ''">
            and t.obj_id= #{objId}
        </if>
        <if test="machineId !=null and machineId != ''">
            and t.machine_id= #{machineId}
        </if>
    </update>
    <!-- 保存设备同步信息 add by wuxw 2018-07-03 -->
    <insert id="saveBusinessMachineTranslateInfo" parameterType="Map">
        insert into business_machine_translate(
        machine_id,machine_code,operate,type_cd,machine_translate_id,obj_id,obj_name,state,community_id,b_id,machine_cmd,obj_b_id,remark
        ) values (
        #{machineId},#{machineCode},#{operate},#{typeCd},#{machineTranslateId},#{objId},#{objName},#{state},#{communityId},#{bId},
        #{machineCmd},
        #{objBId},#{remark}
        )
    </insert>


    <!-- 查询设备同步信息(Business) add by wuxw 2018-07-03 -->
    <select id="getBusinessMachineTranslateInfo" parameterType="Map" resultType="Map">
        select t.machine_id,t.machine_id machineId,t.machine_code,t.machine_code
        machineCode,t.operate,t.type_cd,t.type_cd typeCd,t.machine_translate_id,t.machine_translate_id
        machineTranslateId,t.obj_id,t.obj_id objId,t.obj_name,t.obj_name objName,t.state,t.community_id,t.community_id
        communityId,t.b_id,t.b_id bId,t.machine_cmd,t.obj_b_id,t.remark
        from business_machine_translate t
        where 1 =1
        <if test="machineId !=null and machineId != ''">
            and t.machine_id= #{machineId}
        </if>
        <if test="machineCode !=null and machineCode != ''">
            and t.machine_code= #{machineCode}
        </if>
        <if test="operate !=null and operate != ''">
            and t.operate= #{operate}
        </if>
        <if test="typeCd !=null and typeCd != ''">
            and t.type_cd= #{typeCd}
        </if>
        <if test="machineTranslateId !=null and machineTranslateId != ''">
            and t.machine_translate_id= #{machineTranslateId}
        </if>
        <if test="objId !=null and objId != ''">
            and t.obj_id= #{objId}
        </if>
        <if test="objName !=null and objName != ''">
            and t.obj_name= #{objName}
        </if>
        <if test="state !=null and state != ''">
            and t.state= #{state}
        </if>
        <if test="communityId !=null and communityId != ''">
            and t.community_id= #{communityId}
        </if>
        <if test="bId !=null and bId != ''">
            and t.b_id= #{bId}
        </if>


    </select>


    <!-- 保存设备同步信息至 instance表中 add by wuxw 2018-07-03 -->
    <insert id="saveMachineTranslateInfoInstance" parameterType="Map">
        insert into machine_translate(
        machine_id,machine_code,type_cd,machine_translate_id,obj_id,status_cd,obj_name,state,community_id,b_id,
        machine_cmd,obj_b_id,remark
        ) select
        t.machine_id,t.machine_code,t.type_cd,t.machine_translate_id,t.obj_id,'0',t.obj_name,t.state,t.community_id,t.b_id,
        t.machine_cmd,t.obj_b_id,t.remark
        from business_machine_translate t where 1=1
        <if test="machineId !=null and machineId != ''">
            and t.machine_id= #{machineId}
        </if>
        <if test="machineCode !=null and machineCode != ''">
            and t.machine_code= #{machineCode}
        </if>
        and t.operate= 'ADD'
        <if test="typeCd !=null and typeCd != ''">
            and t.type_cd= #{typeCd}
        </if>
        <if test="machineTranslateId !=null and machineTranslateId != ''">
            and t.machine_translate_id= #{machineTranslateId}
        </if>
        <if test="objId !=null and objId != ''">
            and t.obj_id= #{objId}
        </if>
        <if test="objName !=null and objName != ''">
            and t.obj_name= #{objName}
        </if>
        <if test="state !=null and state != ''">
            and t.state= #{state}
        </if>
        <if test="communityId !=null and communityId != ''">
            and t.community_id= #{communityId}
        </if>
        <if test="bId !=null and bId != ''">
            and t.b_id= #{bId}
        </if>

    </insert>


    <!-- 查询设备同步信息 add by wuxw 2018-07-03 -->
    <select id="getMachineTranslateInfo" parameterType="Map" resultType="Map">
        select t.machine_id,t.machine_id machineId,t.machine_code,t.machine_code machineCode,m.machine_name machineName,t.type_cd,t.type_cd
        typeCd,t.machine_translate_id,t.machine_translate_id machineTranslateId,t.obj_id,t.obj_id
        objId,t.status_cd,t.status_cd statusCd,t.obj_name,t.obj_name objName,t.state,t.community_id,t.community_id
        communityId,t.b_id,t.b_id bId,td.name typeCdName,td1.name stateName,t.create_time createTime,t.update_time
        updateTime,t.machine_cmd,t.obj_b_id,t.machine_cmd machineCmd,td2.`name` machineCmdName,t.obj_b_id objBId,t.remark
        from machine_translate t
        inner join t_dict td on t.type_cd=td.status_cd and td.table_name='machine_translate' and td.table_columns='type_cd'
        inner join t_dict td1 on t.state=td1.status_cd and td1.table_name='machine_translate' and td1.table_columns='state'
        inner join t_dict td2 on t.machine_cmd = td2.status_cd and td2.table_name='machine_translate' and td2.table_columns='machine_cmd'
        left join machine m on t.machine_id = m.machine_id and m.status_cd = '0' and t.community_id = m.community_id
        where 1 =1
        <if test="machineId !=null and machineId != ''">
            and t.machine_id= #{machineId}
        </if>
        <if test="machineCode !=null and machineCode != ''">
            and t.machine_code= #{machineCode}
        </if>
        <if test="typeCd !=null and typeCd != ''">
            and t.type_cd= #{typeCd}
        </if>
        <if test="machineTranslateId !=null and machineTranslateId != ''">
            and t.machine_translate_id= #{machineTranslateId}
        </if>
        <if test="objId !=null and objId != ''">
            and t.obj_id= #{objId}
        </if>
        <if test="machineCmd !=null and machineCmd != ''">
            and t.machine_cmd= #{machineCmd}
        </if>
        <if test='isNow !=null and isNow == "Y"'>
            and to_days(t.create_time) = to_days(now())
        </if>
        <if test="statusCd !=null and statusCd != ''">
            and t.status_cd= #{statusCd}
        </if>
        <if test="objName !=null and objName != ''">
            and t.obj_name= #{objName}
        </if>
        <if test="state !=null and state != ''">
            and t.state= #{state}
        </if>
        <if test="communityId !=null and communityId != ''">
            and t.community_id= #{communityId}
        </if>
        <if test="bId !=null and bId != ''">
            and t.b_id= #{bId}
        </if>
        order by t.update_time desc
        <if test="page != -1 and page != null ">
            limit #{page}, #{row}
        </if>

    </select>


    <!-- 修改设备同步信息 add by wuxw 2018-07-03 -->
    <update id="updateMachineTranslateInfoInstance" parameterType="Map">
        update machine_translate t set t.status_cd = #{statusCd}
        <if test="newBId != null and newBId != ''">
            ,t.b_id = #{newBId}
        </if>
        <if test="machineId !=null and machineId != ''">
            , t.machine_id= #{machineId}
        </if>
        <if test="machineCode !=null and machineCode != ''">
            , t.machine_code= #{machineCode}
        </if>

        <if test="typeCd !=null and typeCd != ''">
            , t.type_cd= #{typeCd}
        </if>
        <if test="objId !=null and objId != ''">
            , t.obj_id= #{objId}
        </if>
        <if test="objName !=null and objName != ''">
            , t.obj_name= #{objName}
        </if>
        <if test="state !=null and state != ''">
            , t.state= #{state}
        </if>
        <if test="communityId !=null and communityId != ''">
            , t.community_id= #{communityId}
        </if>
        <if test="remark !=null and remark != ''">
            ,t.remark= #{remark}
        </if>
        where 1=1
        <if test="machineTranslateId !=null and machineTranslateId != ''">
            and t.machine_translate_id= #{machineTranslateId}
        </if>
        <if test="bId !=null and bId != ''">
            and t.b_id= #{bId}
        </if>

    </update>

    <!-- 查询设备同步数量 add by wuxw 2018-07-03 -->
    <select id="queryMachineTranslatesCount" parameterType="Map" resultType="Map">
        select count(1) count
        from machine_translate t
        inner join t_dict td on t.type_cd=td.status_cd and td.table_name='machine_translate' and td.table_columns='type_cd'
        inner join t_dict td1 on t.state=td1.status_cd and td1.table_name='machine_translate' and td1.table_columns='state'
        inner join t_dict td2 on t.machine_cmd = td2.status_cd and td2.table_name='machine_translate' and td2.table_columns='machine_cmd'
        left join machine m on t.machine_id = m.machine_id and m.status_cd = '0' and t.community_id = m.community_id
        where 1 =1
        <if test="machineId !=null and machineId != ''">
            and t.machine_id= #{machineId}
        </if>
        <if test="machineCode !=null and machineCode != ''">
            and t.machine_code= #{machineCode}
        </if>
        <if test="typeCd !=null and typeCd != ''">
            and t.type_cd= #{typeCd}
        </if>
        <if test="machineTranslateId !=null and machineTranslateId != ''">
            and t.machine_translate_id= #{machineTranslateId}
        </if>
        <if test="objId !=null and objId != ''">
            and t.obj_id= #{objId}
        </if>
        <if test="machineCmd !=null and machineCmd != ''">
            and t.machine_cmd= #{machineCmd}
        </if>
        <if test='isNow !=null and isNow == "Y"'>
            and to_days(t.create_time) = to_days(now())
        </if>

        <if test="statusCd !=null and statusCd != ''">
            and t.status_cd= #{statusCd}
        </if>
        <if test="objName !=null and objName != ''">
            and t.obj_name= #{objName}
        </if>
        <if test="state !=null and state != ''">
            and t.state= #{state}
        </if>
        <if test="communityId !=null and communityId != ''">
            and t.community_id= #{communityId}
        </if>
        <if test="bId !=null and bId != ''">
            and t.b_id= #{bId}
        </if>


    </select>

    <update id="updateMachineTranslateState" parameterType="Map">
        update machine_translate t
        <set>
            <if test="statusCd !=null and statusCd != ''">
                t.status_cd= #{statusCd},
            </if>
            <if test="state !=null and state != ''">
                t.state= #{state},
            </if>
            <if test="updateTime !=null ">
                t.update_time= #{updateTime},
            </if>
            <if test="remark !=null and remark != ''">
                t.remark= #{remark}
            </if>
        </set>
        where
        1=1
        <if test="machineCode !=null and machineCode != ''">
            and t.machine_code= #{machineCode}
        </if>
        <if test="communityId !=null and communityId != ''">
            and t.community_id= #{communityId}
        </if>
        <if test="objId !=null and objId != ''">
            and t.obj_id= #{objId}
        </if>
        <if test="machineTranslateId !=null and machineTranslateId != ''">
            and t.machine_translate_id= #{machineTranslateId}
        </if>
    </update>

</mapper>