<?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.yeejoin.amos.fas.business.dao.mapper.AccidentTypeMapper">
	<!--统计-->
	<select id="countPageData" resultType="long">
		SELECT
		count(1) AS total_num
		FROM
		f_accident_type a
		<trim prefix="WHERE" prefixOverrides="AND ">
			<if test="name!=null"> and a.name like concat(concat("%",#{name}),"%") </if>
			<if test="orgCode!=null"> and (a.org_code like concat(#{orgCode},'%') OR a.org_code = #{orgCode})</if>
		</trim>
	</select>
	<!--分页查询 -->
	<select id="queryAccidentTypePage" resultType="java.util.HashMap">
		SELECT
		a.id,
		a.name,
		a.influence,
		a.severity,
		a.dept_id as deptId ,
		a.create_by as createBy ,
		a.create_date as createDate,
		a.remark
		FROM
		f_accident_type a
		<trim prefix="WHERE" prefixOverrides="AND ">
			<if test="name!=null"> and a.name like concat(concat("%",#{name}),"%") </if>
		</trim>
		order by a.id
		<choose>
	     <when test="pageSize==-1"></when>
	     <when test="pageSize!=-1">limit #{offset},#{pageSize}</when>  
	    </choose>
	</select>
	
	<select id="findAccidentTypePage" resultType="java.util.HashMap">
		SELECT
		a.id,
		a.name,
		CONCAT(fem.influence,'-',fem.`describe`) as influence,
		fem.coefficient as severity,
		a.dept_id as deptId ,
		a.create_by as createBy ,
		a.create_date as createDate,
		a.evaluation_sid as evaluationSid,
		a.remark
		FROM
		f_accident_type a
		left join f_evaluation_model fem on fem.id = a.evaluation_sid
		<trim prefix="WHERE" prefixOverrides="AND ">
			<if test="name!=null"> and a.name like concat(concat("%",#{name}),"%") </if>
			<if test="orgCode!=null"> and (a.org_code like concat(#{orgCode},'%') OR a.org_code = #{orgCode})</if>
		</trim>
		order by a.id
		<choose>
	     <when test="pageSize==-1"></when>
	     <when test="pageSize!=-1">limit #{offset},#{pageSize}</when>  
	    </choose>
	</select>
	
	<select id="findAccidentTypeListByOrgCode" resultType="java.util.HashMap">
		SELECT
			a.id,
			a.name,
			CONCAT(
				fem.influence,
				'-',
				fem.`describe`
			) AS influence,
			fem.coefficient AS severity,
			a.remark,
			fem.id evaluationSid
		FROM
			f_accident_type a
		LEFT JOIN f_evaluation_model fem ON fem.id = a.evaluation_sid
		WHERE 1=1
		<if test="orgCode !=null">
			and a.org_code = #{orgCode}
		</if>
			
	</select>
</mapper>