<?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.qianwen.mdc.mapper.MachineMapper">
|
<resultMap id="BaseResultMap" type="com.qianwen.mdc.domain.Machine">
|
|
<id column="id" jdbcType="INTEGER" property="id" />
|
<result column="ip" jdbcType="VARCHAR" property="ip" />
|
<result column="port" jdbcType="INTEGER" property="port" />
|
<result column="protocol_id" jdbcType="INTEGER" property="typeId" />
|
<result column="workshop_id" jdbcType="INTEGER" property="workshopId" />
|
<result column="section_id" jdbcType="INTEGER" property="sectionId" />
|
<result column="trans_mode" jdbcType="VARCHAR" property="transMode" />
|
|
<result column="is_collect" jdbcType="INTEGER" property="isCollect" />
|
<result column="concern" jdbcType="INTEGER" property="concern" />
|
<result column="dnc_name" jdbcType="VARCHAR" property="dncName" />
|
<result column="shift_type" jdbcType="INTEGER" property="shiftType" />
|
</resultMap>
|
<!--
|
<select id="queryMachineListPortNotNUll" resultType="com.qianwen.mdc.domain.Machine">
|
select
|
a.id,
|
a.name,
|
a.ip,
|
a.port,
|
a.position,
|
a.protocol_id typeId,
|
a.workshop_id workshopId,
|
a.section_id sectionId,
|
a.monitor_port monitorPort,
|
a.is_collect isCollect,
|
a.shift_type shiftType,
|
b.name workshop,
|
c.name section,
|
d.state status,
|
d.var1 cycleCount,
|
d.var2 cycleTime
|
from machine a
|
left join workshop b
|
on a.workshop_id = b.id
|
left join section c
|
on a.section_id = c.id
|
left join (select max(id) as id,machine_id,state,var1,var2 from machine_status group by machine_id) d
|
on a.id = d.machine_id
|
where a.monitor_port is not null
|
<if test="workshopId != null">
|
and a.workshop_id = #{workshopId}
|
</if>
|
<if test="sectionId != null">
|
and a.section_id = #{sectionId}
|
</if>
|
|
<if test="concernFlag != null">
|
and a.concern = #{concernFlag}
|
</if>
|
<if test="id != null">
|
and a.id = #{id}
|
</if>
|
order by a.id
|
</select>
|
-->
|
<!-- 原方法名称:queryMachineList,由新方法listWithStatus替换 -->
|
<select id="listWithStatus" resultType="com.qianwen.mdc.dto.machine.MachineFullDTO">
|
select
|
a.id,
|
acc.machine_name as machineName,
|
a.ip,
|
a.port,
|
a.protocol_id typeId,
|
a.workshop_id workshopId,
|
a.section_id sectionId,
|
a.is_collect isCollect,
|
a.concern concern,
|
a.shift_type shiftType,
|
acc.pic,
|
b.name workshop,
|
c.name section,
|
e.status status,
|
e.cycle_count cycleCount,
|
e.cycle_time cycleTime,
|
e.machine_on_time machineOnTime,
|
e.var4,
|
e.var5
|
from machine a
|
inner join machine_account acc on a.id=acc.machine_id
|
left join workshop b
|
on a.workshop_id = b.id
|
left join section c
|
on a.section_id = c.id
|
left join (select max(id) as id,machine_id from machine_status group by machine_id) d on a.id = d.machine_id
|
left join machine_status e on e.id = d.id
|
<where>
|
<if test="plantId != null">
|
and plant_id=#{plantId}
|
</if>
|
<if test="machineName != null and machineName != ''">
|
<bind name="name" value="'%' + machineName + '%'" />
|
and acc.machine_name like #{machineName}
|
</if>
|
<if test="workshopId != null">
|
and a.workshop_id = #{workshopId}
|
</if>
|
|
<if test="concernFlag != null">
|
and a.concern = #{concernFlag}
|
</if>
|
|
<if test="status != null and status != ''">
|
and e.status = #{status}
|
</if>
|
</where>
|
order by a.id
|
</select>
|
|
<select id="queryPage" resultType="com.qianwen.mdc.dto.machine.MachineFullDTO">
|
select
|
a.id,
|
acc.machine_name machineName,
|
a.ip,
|
a.port,
|
a.dnc_name dncName,
|
acc.type,
|
acc.category,
|
a.protocol_id protocolId,
|
p.name protocolName,
|
p.version protocolVersion,
|
a.workshop_id workshopId,
|
a.section_id sectionId,
|
a.is_collect isCollect,
|
a.concern concern,
|
a.shift_type shiftType,
|
a.trans_mode transMode,
|
b.name workshop,
|
c.name section
|
from machine a
|
inner join machine_account acc on a.id=acc.machine_id
|
left join workshop b on a.workshop_id = b.id
|
left join section c on a.section_id = c.id
|
left join machine_protocol p on a.protocol_id=p.id
|
<where>
|
<if test="dto.plantId != null">
|
a.plant_id=#{dto.plantId}
|
</if>
|
|
<if test="dto.machineName != null and dto.machineName != ''">
|
<bind name="machineName" value="'%' + dto.machineName + '%'" />
|
and acc.machine_name like #{machineName}
|
</if>
|
<if test="dto.ip != null and dto.ip != ''">
|
<bind name="ip" value="'%' + dto.ip + '%'" />
|
and a.ip like #{ip}
|
</if>
|
<if test="dto.type != null and dto.type != ''">
|
and acc.type=#{dto.type}
|
</if>
|
<if test="dto.transMode != null">
|
and a.trans_mode=#{dto.transMode}
|
</if>
|
<if test="dto.category != null and dto.category != ''">
|
and acc.category=#{dto.category}
|
</if>
|
<if test="dto.workshopId != null">
|
and a.workshop_id = #{dto.workshopId}
|
</if>
|
<if test="dto.sectionId != null">
|
and a.section_id = #{dto.sectionId}
|
</if>
|
|
</where>
|
order by a.id
|
</select>
|
|
<update id="clearPlantIdInPlant">
|
update machine
|
set plant_id = null where plant_id=#{plantId,jdbcType=INTEGER}
|
</update>
|
|
<!-- 机床类型查询(查询记录数),计划不用了,注释 -->
|
<!--
|
<select id="selectCountOfMachineAndTypes" resultType="int">
|
select
|
count(*)
|
from machine m
|
left join mdc_machine_account a on a.machine_id = m.id
|
left join mdc_machine_types t on t.id = a.types_id
|
left join workshop w on w.id = m.workshop_id
|
left join section s on s.id = m.section_id
|
<where>
|
<if test="workshop != null and workshop != ''">
|
and w.name = #{workshop}
|
</if>
|
<if test="section != null and section != ''">
|
and s.name = #{section}
|
</if>
|
<if test="list != null and list.size() > 0">
|
and m.name in
|
<foreach collection="list" open="(" separator="," close=")" item="machineName">
|
#{machineName}
|
</foreach>
|
</if>
|
</where>
|
</select>
|
-->
|
<!-- 机床类型查询,计划不用了,注释 -->
|
<!--
|
<select id="selectMachineAndTypes" resultType="java.util.HashMap">
|
select
|
m.id machineId,
|
m.name machineName,
|
w.name workshopName,
|
s.name sectionName,
|
t.id typesId,
|
t.name typesName
|
from machine m
|
left join mdc_machine_account a on a.machine_id = m.id
|
left join mdc_machine_types t on t.id = a.types_id
|
left join workshop w on w.id = m.workshop_id
|
left join section s on s.id = m.section_id
|
<where>
|
<if test="workshop != null and workshop != ''">
|
and w.name = #{workshop}
|
</if>
|
<if test="section != null and section != ''">
|
and s.name = #{section}
|
</if>
|
<if test="list != null and list.size() > 0">
|
and m.name in
|
<foreach collection="list" open="(" separator="," close=")" item="machineName">
|
#{machineName}
|
</foreach>
|
</if>
|
<if test="machineType != null and machineType != ''">
|
and t.name = #{machineType}
|
</if>
|
</where>
|
order by w.id, s.id, m.name
|
<if test="limit != null">
|
limit #{limit}, #{offset}
|
</if>
|
</select>
|
-->
|
<select id="updateMachineAndTypes" resultType="int">
|
update mdc_machine_types t,
|
mdc_machine_account a
|
left join mdc_machine m on m.id = a.machine_id
|
left join mdc_workshop w on w.id = m.workshop_id
|
left join mdc_section s on s.id = m.section_id
|
set a.types_id = t.id
|
<where>
|
t.name = #{machineType}
|
<if test="workshop != null and workshop != ''">
|
and w.name = #{workshop}
|
</if>
|
<if test="section != null and section != ''">
|
and s.name = #{section}
|
</if>
|
<if test="list != null and list.size() > 0">
|
and m.name in
|
<foreach collection="list" open="(" separator="," close=")" item="machineName">
|
#{machineName}
|
</foreach>
|
</if>
|
</where>
|
</select>
|
|
<select id="getByWorkshopSection" resultType="String">
|
select m.name from machine m
|
left join workshop w
|
on m.workshop_id = w.id
|
left join section s
|
on m.section_id = s.id
|
<where>
|
<if test="workshop != null and workshop != ''">
|
and w.name = #{workshop}
|
</if>
|
<if test="section != null and section != ''">
|
and s.name = #{section}
|
</if>
|
</where>
|
order by m.name
|
</select>
|
|
<!--
|
<insert id="addAlarmHistory" parameterType="com.qianwen.mdc.domain.MdcMachineAlarmHistory">
|
insert into mdc_machine_alarm_history
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
<if test="id != null">
|
id,
|
</if>
|
<if test="machineId != null">
|
machine_id,
|
</if>
|
<if test="alarmType != null and alarmType != ''">
|
alarm_type,
|
</if>
|
<if test="alarmHandleResult != null and alarmHandleResult != ''">
|
alarm_handle_result,
|
</if>
|
create_date,
|
<if test="createEmp != null and createEmp != ''">
|
create_emp,
|
</if>
|
</trim>
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
<if test="id != null">
|
#{id,jdbcType=INTEGER},
|
</if>
|
<if test="machineId != null">
|
#{machineId,jdbcType=INTEGER},
|
</if>
|
<if test="alarmType != null and alarmType != ''">
|
#{alarmType,jdbcType=VARCHAR},
|
</if>
|
<if test="alarmHandleResult != null and alarmHandleResult != ''">
|
#{alarmHandleResult,jdbcType=VARCHAR},
|
</if>
|
NOW(),
|
<if test="createEmp != null and createEmp != ''">
|
#{createEmp,jdbcType=VARCHAR},
|
</if>
|
</trim>
|
</insert>
|
-->
|
<update id="updateMachineStatus">
|
update mdc_machine_status
|
set state = #{state,jdbcType=VARCHAR}
|
<where>
|
<if test="machineId != null">
|
AND machine_id = #{machineId,jdbcType=INTEGER}
|
</if>
|
</where>
|
</update>
|
|
|
<select id="selectMachineDetail" resultType="com.qianwen.mdc.domain.MachineStatus">
|
select
|
a.id,
|
a.machine_id machineId,
|
a.time,
|
a.state,
|
a.spindle_speed spindleSpeed,
|
a.spindle_override spindleOverride,
|
a.spindle_load spindleLoad,
|
a.feedrate_override feedrateOverride,
|
a.feed_rate feedRate,
|
a.rapid_feed rapidFeed,
|
a.prog_name progName,
|
a.alarm_no alarmNo,
|
a.alarm_msg alarmMsg,
|
a.mode mode,
|
a.tool_no toolNo,
|
a.tool_name toolName,
|
a.oper_id operId,
|
a.var1 cycleCount,
|
a.var2,
|
a.var3,
|
a.var4,
|
a.var5,
|
a.var6
|
from mdc_machine_status a
|
<where>
|
<if test="machineId != null">
|
and a.machine_id = #{machineId}
|
</if>
|
</where>
|
order by id desc limit 1
|
</select>
|
|
<select id="selectAlarmList" resultType="com.qianwen.mdc.domain.MachineStatus">
|
select
|
a.prog_name progName,
|
a.alarm_no alarmNo,
|
a.alarm_msg alarmMsg
|
from mdc_machine_status a
|
<where>
|
<if test="machineId != null">
|
and a.machine_id = #{machineId}
|
</if>
|
</where>
|
order by id desc
|
</select>
|
|
<select id="selectStatusMonitor" resultType="java.util.HashMap">
|
select
|
m.name,
|
m.first_position position,
|
m.shift_type shiftType,
|
a.cnc_system cncSystem,
|
a.types_id typesId,
|
mt.name mdcType,
|
s.state status,
|
s.prog_name progName,
|
s.var1 cycleCount,
|
s.var2 cycleTime,
|
convert(s.var2, signed)/(36 * 24) mdcRate,
|
s.feed_rate feedRate,
|
s.spindle_speed spindleSpeed,
|
s.spindle_override spindleOverride,
|
concat(w.name, '-', se.name) section,
|
q.mdcTypeRate
|
from
|
machine m
|
left join mdc_machine_account a on m.id = a.machine_id
|
left join mdc_machine_types mt on a.types_id = mt.id
|
left join mdc_machine_status s on m.id = s.machine_id
|
left join mdc_workshop w on m.workshop_id = w.id
|
left join mdc_section se on m.section_id = se.id
|
left join (
|
select
|
a.types_id typesid,
|
avg(convert(s.var2, signed)/(36 * 24)) mdcTypeRate
|
from
|
mdc_machine_account a
|
left join mdc_machine_status s on a.machine_id = s.machine_id
|
where
|
s.id in (select max(id) id from mdc_machine_status group by machine_id)
|
group by
|
a.types_id
|
) q on q.typesid = a.types_id
|
where
|
s.id in (select max(id) id from mdc_machine_status group by machine_id)
|
</select>
|
</mapper>
|