<?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.jeeplus.modules.worksalaryitem.dao.WorkSalaryItemDao">
    
	<sql id="workSalaryItemColumns">
		a.id AS "id",
		a.create_by AS "createBy.id",
		a.create_date AS "createDate",
		a.update_by AS "updateBy.id",
		a.update_date AS "updateDate",
		a.remarks AS "remarks",
		a.del_flag AS "delFlag",
		a.company_id AS "companyId",
		a.office_id AS "officeId",
		a.name AS "name",
		a.num AS "num",
		a.type AS "type",
		a.set_method AS "setMethod",
		a.state AS "state",
		a.formula AS "formula",
		a.explanation 	 AS "explanation",
		a.ids AS "ids"
	</sql>
	
	<sql id="workSalaryItemJoins">
		LEFT JOIN sys_office o ON o.id = a.office_id
		LEFT JOIN sys_office s ON s.id = a.company_id
	</sql>
	
    
	<select id="get" resultType="WorkSalaryItem" >
		SELECT 
			<include refid="workSalaryItemColumns"/>
		FROM work_salary_item a
		<include refid="workSalaryItemJoins"/>
		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="WorkSalaryItem" >
		SELECT 
			<include refid="workSalaryItemColumns"/>
		FROM work_salary_item a
		<include refid="workSalaryItemJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			<if test="name != null and name != ''">
				AND a.name LIKE 
					<if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
					<if test="dbName == 'mssql'">'%'+#{name}+'%'</if>
					<if test="dbName == 'mysql'">concat('%',#{name},'%')</if>
			</if>
			<if test="num != null and num != ''">
				AND a.num = #{num}
			</if>
			<if test="type != null and type != ''">
				AND a.type = #{type}
			</if>
			<if test="setMethod != null and setMethod != ''">
				AND a.set_method = #{setMethod}
			</if>
			<if test="state != null and state != ''">
				AND a.state = #{state}
			</if>
			${sqlMap.dsf}
		</where>
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.update_date DESC
			</otherwise>
		</choose>
	</select>
	
	<select id="findAllList" resultType="WorkSalaryItem" >
		SELECT 
			<include refid="workSalaryItemColumns"/>
		FROM work_salary_item a
		<include refid="workSalaryItemJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
		</where>		
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.update_date DESC
			</otherwise>
		</choose>
	</select>
	
	<insert id="insert">
		INSERT INTO work_salary_item(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			company_id,
			office_id,
			name,
			num,
			type,
			set_method,
			state,
			formula,
			explanation 	,
			ids
		) VALUES (
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag},
			#{companyId},
			#{officeId},
			#{name},
			#{num},
			#{type},
			#{setMethod},
			#{state},
			#{formula},
			#{explanation},
			#{ids}
		)
	</insert>
	
	<update id="update">
		UPDATE work_salary_item SET 	
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks},
			company_id = #{companyId},
			office_id = #{officeId},
			name = #{name},
			num = #{num},
			type = #{type},
			set_method = #{setMethod},
			state = #{state},
			formula = #{formula},
			explanation 	 = #{explanation},
			ids = #{ids}
		WHERE id = #{id}
	</update>
	
	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM work_salary_item
		WHERE id = #{id}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE work_salary_item SET 
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="WorkSalaryItem" statementType="STATEMENT">
		select * FROM work_salary_item  where ${propertyName} = '${value}'
	</select>
	
</mapper>