CompanyMapper.xml 6.67 KB
<?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="cn.runsa.portal.base.dao.CompanyMapper">
	<resultMap id="BaseResultMap" type="cn.runsa.portal.base.entity.Company">
		<id column="coId" property="id" jdbcType="INTEGER" />
		<result column="coCode" property="code" jdbcType="VARCHAR" />
		<result column="coName" property="name" jdbcType="VARCHAR" />
		<result column="coDesc" property="desc" jdbcType="VARCHAR" />
		<result column="ptValid" property="valid" jdbcType="SMALLINT" />
		<result column="plId" property="plId" jdbcType="INTEGER" />
		<result column="coCorpman" property="corpman" jdbcType="VARCHAR" />
		<result column="ptChief" property="chief" jdbcType="VARCHAR" />
		<result column="ptPhone" property="phone" jdbcType="VARCHAR" />
		<result column="ptTelphone" property="telphone" jdbcType="VARCHAR" />
		<result column="ptEmail" property="email" jdbcType="VARCHAR" />
		<result column="ptPost" property="post" jdbcType="VARCHAR" />
		<result column="ptUrl" property="url" jdbcType="VARCHAR" />
		<result column="diId" property="diId" jdbcType="INTEGER" />
		<result column="ptAddr" property="addr" jdbcType="VARCHAR" />
		<result column="coTaxId" property="taxId" jdbcType="VARCHAR" />
		<result column="coLicense" property="license" jdbcType="VARCHAR" />
		<result column="coOrgCode" property="orgCode" jdbcType="VARCHAR" />
		<result column="ptRemark1" property="remark1" jdbcType="VARCHAR" />
		<result column="ptRemark2" property="remark2" jdbcType="VARCHAR" />
		<result column="ptRemark3" property="remark3" jdbcType="VARCHAR" />
		<result column="ptUpTime" property="upTime" jdbcType="TIMESTAMP" />
		<result column="ptUpdater" property="updater" jdbcType="INTEGER" />

		<collection property="corpBizList" javaType="ArrayList"
			ofType="cn.runsa.portal.base.entity.CorpBizEntity">
			<id column="coId" property="coId" jdbcType="INTEGER" />
			<result column="beId" property="beId" jdbcType="INTEGER" />
		</collection>

		<collection property="bizList" javaType="ArrayList"
			ofType="cn.runsa.portal.base.entity.BizEntity">
			<id column="beId" property="id" jdbcType="INTEGER" />
			<result column="beName" property="name" jdbcType="VARCHAR" />
		</collection>
	</resultMap>

	<insert id="insertCompany" parameterType="cn.runsa.portal.base.entity.Company">
		<selectKey resultType="java.lang.Integer" keyProperty="id"
			order="AFTER">
			SELECT LAST_INSERT_ID()
		</selectKey>
		insert into mtcorp(coCode,coName,coDesc,ptValid
		,coCorpman,ptChief,ptPhone,ptTelphone,ptEmail
		,ptPost,ptUrl,diId,ptAddr,coTaxId,coLicense,coOrgCode,ptRemark1
		,ptRemark2,ptRemark3,ptUpTime,ptUpdater,plId)
		values(#{code},#{name},#{desc},#{valid},#{corpman},#{chief},#{phone},
		#{telphone},#{email},#{post},#{url},#{diId},#{addr},
		#{taxId},#{license},#{orgCode},#{remark1},#{remark2},#{remark3},now(),#{updater},#{plId})
	</insert>

	<select id="existsCoName" resultType="Boolean"
		parameterType="cn.runsa.portal.base.entity.Company">
		SELECT
		COUNT(*)
		FROM
		mtCorp t1
		LEFT JOIN mtCorpBizEntity t2 ON t2.coId = t1.coId
		LEFT JOIN mtBizEntity t3 ON t3.beId = t2.beId
		WHERE t1.coName = #{name}
		AND t2.beId IN
		<foreach item="item" collection="corpBizList" separator=","
			open="(" close=")" index="">
			#{item.beId, jdbcType=NUMERIC}
		</foreach>
		<if test="id!=null and id!=''">
			AND t1.coId != #{id}
		</if>
	</select>

	<!-- 税务登记号可为空 -->
	<select id="existsTaxId" resultType="Boolean"
		parameterType="cn.runsa.portal.base.entity.Company">
		SELECT COUNT(*) FROM mtcorp WHERE 1=1 
		<if test="taxId!=null and taxId!=''">
			AND coTaxId = #{taxId}
		</if>
		<if test="taxId==null or taxId==''">
			AND 1=0
		</if>
		<if test="id!=null and id!=''">
			AND coId != #{id}
		</if>
	</select>

	<insert id="insertCorpBiz" parameterType="cn.runsa.portal.base.entity.Company">
		insert into mtCorpBizEntity (coId,beId) values
		<foreach collection="corpBizList" item="item" separator=",">
			(#{id},#{item.beId})
		</foreach>
	</insert>

	<select id="selectById" parameterType="java.lang.Integer"
		resultMap="BaseResultMap">
		SELECT
		t1.coId,
		t1.coCode,
		t1.coName,
		t1.coDesc,
		t1.ptValid,
		t1.plId,
		t1.coCorpman,
		t1.ptChief,
		t1.ptPhone,
		t1.ptTelphone,
		t1.ptEmail,
		t1.ptPost,
		t1.ptUrl,
		t1.diId,
		t1.ptAddr,
		t1.coTaxId,
		t1.coLicense,
		t1.coOrgCode,
		t1.ptRemark1,
		t1.ptRemark2,
		t1.ptRemark3,
		t1.ptUpTime,
		t1.ptUpdater,
		t3.beId,
		t3.beName
		FROM mtCorp t1
		LEFT JOIN mtCorpBizEntity t2 ON t2.coId = t1.coId
		LEFT JOIN mtBizEntity t3 ON t3.beId = t2.beId
		WHERE t1.coId = #{id}
	</select>

	<update id="updateCompany" parameterType="cn.runsa.portal.base.entity.Company">
		update mtcorp set
		coCode=#{code},coName=#{name},ptValid=#{valid},ptUpTime=now(),ptUpdater=#{updater}
		<if test="desc!=null and desc!=''">
			,coDesc = #{desc,jdbcType=VARCHAR}
		</if>
		<if test="corpman!=null and corpman!=''">
			,coCorpman = #{corpman,jdbcType=VARCHAR}
		</if>
		<if test="chief!=null and chief!=''">
			,ptChief = #{chief,jdbcType=VARCHAR}
		</if>
		<if test="phone!=null and phone!=''">
			,ptPhone = #{phone,jdbcType=VARCHAR}
		</if>
		<if test="telphone!=null and telphone!=''">
			,ptTelphone = #{telphone,jdbcType=VARCHAR}
		</if>
		<if test="email!=null and email!=''">
			,ptEmail = #{email,jdbcType=VARCHAR}
		</if>
		<if test="post!=null and post!=''">
			,ptPost = #{post,jdbcType=VARCHAR}
		</if>
		<if test="url!=null and url!=''">
			,ptUrl = #{url,jdbcType=VARCHAR}
		</if>
		<if test="diId!=null and diId!=''">
			,diId = #{diId,jdbcType=INTEGER}
		</if>
		<if test="addr!=null and addr!=''">
			,ptAddr = #{addr,jdbcType=VARCHAR}
		</if>
		<if test="taxId!=null and taxId!=''">
			,coTaxId = #{taxId,jdbcType=VARCHAR}
		</if>
		<if test="license!=null and license!=''">
			,coLicense = #{license,jdbcType=VARCHAR}
		</if>
		<if test="orgCode!=null and orgCode!=''">
			,coOrgCode = #{orgCode,jdbcType=VARCHAR}
		</if>
		<if test="remark1!=null and remark1!=''">
			,ptRemark1 = #{remark1,jdbcType=VARCHAR}
		</if>
		<if test="remark2!=null and remark2!=''">
			,ptRemark2 = #{remark2,jdbcType=VARCHAR}
		</if>
		<if test="remark3!=null and remark3!=''">
			,ptRemark3 = #{remark3,jdbcType=VARCHAR}
		</if>
		where coId = #{id,jdbcType=INTEGER}
	</update>

	<delete id="deleteCorpBiz" parameterType="java.lang.Integer">
		delete from mtCorpBizEntity where coId = #{coId,jdbcType=INTEGER}
	</delete>
	
	<delete id="deleteCompany" parameterType="java.lang.Integer">
		delete from mtcorp where coId = #{coId,jdbcType=INTEGER}
	</delete>
	
	<select id="existsEmployee" resultType="Boolean" parameterType="java.lang.Integer">
		SELECT COUNT(*) FROM mtemployee WHERE coId = #{coId,jdbcType=INTEGER}
	</select>
</mapper>