<?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.workitemcollar.dao.WorkItemCollarItemDao">
    
	<sql id="workItemCollarItemColumns">
		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.work_collar_id AS "workCollarId",
		a.item_id AS "itemId",
		a.item_name AS "itemName",
		a.item_type AS "itemType",
		a.item_catalog_number AS "itemCatalogNumber",
		a.item_model AS "itemModel",
		a.item_primary_unit AS "itemPrimaryUnit",
		a.item_number AS "itemNumber"
	</sql>
	
	<sql id="workItemCollarItemJoins">
	</sql>
	
    
	<select id="get" resultType="WorkItemCollarItem" >
		SELECT 
			<include refid="workItemCollarItemColumns"/>
		FROM work_item_collar_item a
		<include refid="workItemCollarItemJoins"/>
		WHERE a.id = #{id}
	</select>
	
	<select id="findList" resultType="WorkItemCollarItem" >
		SELECT 
			<include refid="workItemCollarItemColumns"/>
		FROM work_item_collar_item a
		<include refid="workItemCollarItemJoins"/>
		<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>
	
	<select id="findAllList" resultType="WorkItemCollarItem" >
		SELECT 
			<include refid="workItemCollarItemColumns"/>
		FROM work_item_collar_item a
		<include refid="workItemCollarItemJoins"/>
		<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_item_collar_item(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			work_collar_id,
			item_id,
			item_name,
			item_type,
			item_catalog_number,
			item_model,
			item_primary_unit,
			item_number
		) VALUES (
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag},
			#{workCollarId},
			#{itemId},
			#{itemName},
			#{itemType},
			#{itemCatalogNumber},
			#{itemModel},
			#{itemPrimaryUnit},
			#{itemNumber}
		)
	</insert>
	
	<update id="update">
		UPDATE work_item_collar_item SET 	
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks},
			work_collar_id = #{workCollarId},
			item_id = #{itemId},
			item_name = #{itemName},
			item_type = #{itemType},
			del_flag=#{delFlag},
			item_catalog_number = #{itemCatalogNumber},
			item_model = #{itemModel},
			item_primary_unit = #{itemPrimaryUnit},
			item_number = #{itemNumber}
		WHERE id = #{id}
	</update>
	
	
	<!--物理删除-->
	<update id="delete">
		UPDATE work_item_collar_item SET
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE work_item_collar_item SET 
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="WorkItemCollarItem" statementType="STATEMENT">
		select * FROM work_item_collar_item  where ${propertyName} = '${value}'
	</select>


	<select id="findAssetsWorkItemCollarId" resultType="WorkItemCollarItem" >
		SELECT
		<include refid="workItemCollarItemColumns"/>
		FROM work_item_collar_item a
		<include refid="workItemCollarItemJoins"/>
		<where>
			a.del_flag = '0'
			and a.work_collar_id=#{id}
		</where>
	</select>
</mapper>