<?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="zoneIndustrySqlMapper">
	<sql id="base_column">
		id,zone_id as zoneId,industry_id as industryId,status,supdated
	</sql>

	<insert id="addZoneIndustry" parameterType="com.cloudcross.ssp.model.ZoneIndustry">
		insert into t_zone_industry (zone_id,industry_id,supdated,status)
		values (#{zoneId},#{industryId},#{supdated},#{status})
	</insert>
	
	<select id="findAll" parameterType="long" resultType="com.cloudcross.ssp.model.ZoneIndustry">
		select t_zone_industry.zone_id as zoneId, t_zone_industry.industry_id as industryId, a.name as industryName, b.name as industryFatherName 
		from t_zone_industry, t_industry a, t_industry b
		where t_zone_industry.industry_id = a.id and (a.father_id = b.id || (a.id = b.id and a.father_id = 0) )
		and t_zone_industry.zone_id = #{zoneId} and t_zone_industry.status = 0
	</select>
	
	<update id="editZoneIndustry" parameterType="com.cloudcross.ssp.model.ZoneIndustry">
		update t_zone_industry
		set  zone_id=#{zoneId},industry_id=#{industryId},status=0,supdated=#{supdated}
		where zone_id = #{zoneId}
			
	</update>
	<update id="deleteZoneIndustry" parameterType="com.cloudcross.ssp.model.Zone">
		
		update t_zone_industry
		set status=-1,supdated=#{supdated} 
		where status=0 and zone_id = #{id}
	</update>	
</mapper>