<?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.zcloud.mapper.dsno1.corp.MaintenanceManagementMapper">

	<!--表名 -->
	<sql id="tableName">
		BUS_MAINTENANCE_MANAGEMENT
	</sql>

	<!--数据字典表名 -->
	<sql id="dicTableName">
		SYS_DICTIONARIES
	</sql>

	<!-- 字段 -->
	<sql id="Field">
		bmm.ID,
		bmm.CORPINFO_ID,
		bmm.ISDELETE,
		bmm.CREATOR,
		bmm.CREATTIME,
		bmm.OPERATOR,
		bmm.OPERATTIME,
		bmm.NOTES,
		bmm.MAINTENANCE_REASON,
		bmm.MAINTENANCE_TIME_START,
		bmm.MAINTENANCE_TIME_END,
		bmm.IS_DEACTIVATE,
		bmm.MAINTENANCE_STATUS
	</sql>

	<!-- 字段用于新增 -->
	<sql id="Field2">
		ID,
		CORPINFO_ID,
		ISDELETE,
		CREATOR,
		CREATTIME,
		OPERATOR,
		OPERATTIME,
		NOTES,
		MAINTENANCE_REASON,
		MAINTENANCE_TIME_START,
		MAINTENANCE_TIME_END,
		IS_DEACTIVATE,
		MAINTENANCE_STATUS
	</sql>

	<!-- 字段值 -->
	<sql id="FieldValue">
		#{ID},
		#{CORPINFO_ID},
		#{ISDELETE},
		#{CREATOR},
		#{CREATTIME},
		#{OPERATOR},
		#{OPERATTIME},
		#{NOTES},
		#{MAINTENANCE_REASON},
		#{MAINTENANCE_TIME_START},
		#{MAINTENANCE_TIME_END},
		#{IS_DEACTIVATE},
		#{MAINTENANCE_STATUS}
	</sql>

	<!-- 新增-->
	<insert id="save" parameterType="pd">
		insert into
	<include refid="tableName"></include>
		(
	<include refid="Field2"></include>
		) values (
	<include refid="FieldValue"></include>
		)
	</insert>

	<update id="update" parameterType="pd">
		update <include refid="tableName"></include> bmm
		set bmm.IS_DEACTIVATE = '1',
		    bmm.MAINTENANCE_REASON = #{STOP_REASON},
			bmm.MAINTENANCE_TIME_START = #{MAINTENANCE_TIME_START},
		    bmm.MAINTENANCE_TIME_END = #{MAINTENANCE_TIME_END}
		where bmm.CORPINFO_ID = #{CORPINFO_ID} and bmm.ISDELETE = '0'
	</update>

	<update id="updateEnable" parameterType="pd">
		update <include refid="tableName"></include> bmm
		set bmm.MAINTENANCE_STATUS = '2',
		    bmm.MAINTENANCE_TIME_END = NOW()
		where bmm.ID = #{MAINTENANCE_ID} and bmm.ISDELETE = '0'
	</update>
	<!-- 获取当前企业维护记录 -->
	<select id="getMaintenanceLogList" resultType="pd" parameterType="pd">
		select
		bmm.ID,
		bmm.CORPINFO_ID,
		bmm.ISDELETE,
		u.NAME CREATOR,
		bmm.CREATTIME,
		bmm.OPERATOR,
		bmm.OPERATTIME,
		bmm.NOTES,
		bmm.MAINTENANCE_REASON,
		bmm.MAINTENANCE_TIME_START,
		bmm.MAINTENANCE_TIME_END,
		if (bmm.IS_DEACTIVATE = '1','是','否') as IS_DEACTIVATE,
		bmm.MAINTENANCE_STATUS,
		bci.CORP_NAME
		from <include refid="tableName"></include> bmm
		left join bus_corp_info bci on bci.CORPINFO_ID = bmm.CORPINFO_ID
		left join sys_user u on u.USERNAME = bmm.CREATOR and u.ISDELETE= '0'
		where bmm.CORPINFO_ID = #{CORPINFO_ID} and bmm.ISDELETE = '0'
		order by bmm.CREATTIME DESC
	</select>
</mapper>
