<?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.landtool.lanbase.modules.org.dao.OrgUnitDao">
|
|
<!-- 可根据自己的需求,是否要使用 -->
|
<resultMap type="com.landtool.lanbase.modules.org.entity.OrgUnit" id="unitMap">
|
<result property="unitid" column="UNITID"/>
|
<result property="parentid" column="PARENTID"/>
|
<result property="unitname" column="UNITNAME"/>
|
<result property="unidcode" column="UNIDCODE"/>
|
<result property="unidorgcode" column="UNIDORGCODE"/>
|
<result property="spellfirst" column="SPELLFIRST"/>
|
<result property="unitshort" column="UNITSHORT"/>
|
<result property="unittype" column="UNITTYPE"/>
|
<result property="rorder" column="RORDER"/>
|
<result property="contactnumber" column="CONTACTNUMBER"/>
|
<result property="faxnumber" column="FAXNUMBER"/>
|
<result property="email" column="EMAIL"/>
|
<result property="address" column="ADDRESS"/>
|
<result property="postalcode" column="POSTALCODE"/>
|
<result property="photourl" column="PHOTOURL"/>
|
<result property="websiteurl" column="WEBSITEURL"/>
|
<result property="status" column="STATUS"/>
|
<result property="rcreatedate" column="RCREATEDATE"/>
|
<result property="rcreateuser" column="RCREATEUSER"/>
|
<result property="rlasteditdate" column="RLASTEDITDATE"/>
|
<result property="remark" column="REMARK"/>
|
<result property="isdept" column="ISDEPT"/>
|
</resultMap>
|
|
<resultMap type="com.landtool.lanbase.modules.org.entity.OrgUnitJoinRegion" id="UnitJoinRegion">
|
<result property="unitid" column="UNITID"/>
|
<result property="parentid" column="PARENTID"/>
|
<result property="unitname" column="UNITNAME"/>
|
<result property="unidcode" column="UNIDCODE"/>
|
<result property="unidorgcode" column="UNIDORGCODE"/>
|
<result property="spellfirst" column="SPELLFIRST"/>
|
<result property="unitshort" column="UNITSHORT"/>
|
<result property="unittype" column="UNITTYPE"/>
|
<result property="rorder" column="RORDER"/>
|
<result property="contactnumber" column="CONTACTNUMBER"/>
|
<result property="faxnumber" column="FAXNUMBER"/>
|
<result property="email" column="EMAIL"/>
|
<result property="address" column="ADDRESS"/>
|
<result property="postalcode" column="POSTALCODE"/>
|
<result property="photourl" column="PHOTOURL"/>
|
<result property="websiteurl" column="WEBSITEURL"/>
|
<result property="status" column="STATUS"/>
|
<result property="rcreatedate" column="RCREATEDATE"/>
|
<result property="rcreateuser" column="RCREATEUSER"/>
|
<result property="rlasteditdate" column="RLASTEDITDATE"/>
|
<result property="remark" column="REMARK"/>
|
<result property="isdept" column="ISDEPT"/>
|
<collection property="orgunitregion" ofType="com.landtool.lanbase.modules.org.entity.OrgRegion" resultMap="com.landtool.lanbase.modules.org.dao.OrgUnitRegionDao.unitregionMap"/>
|
</resultMap>
|
|
<resultMap type="com.landtool.lanbase.common.utils.NameBindId" id="NameBindIdMap">
|
<result property="name" column="NAME"/>
|
<result property="id" column="ID"/>
|
</resultMap>
|
|
<sql id="unitColumns">
|
un.UNITID,un.PARENTID,un.UNITNAME,un.UNIDCODE,un.UNIDORGCODE,un.SPELLFIRST,un.UNITSHORT,un.UNITTYPE,un.RORDER,
|
un.CONTACTNUMBER,un.FAXNUMBER,un.EMAIL,un.ADDRESS,un.POSTALCODE,un.PHOTOURL,un.WEBSITEURL,un.STATUS,
|
un.RCREATEDATE,un.RCREATEUSER,un.RLASTEDITDATE,
|
un.REMARK,un.ISDEPT
|
</sql>
|
|
<sql id="unitRegionColumns">
|
ux.regionid,ux.unitid,ux.rcreatedate,ux.rcreateuser,ux.rlasteditdate
|
</sql>
|
|
<select id="queryObject" resultType="com.landtool.lanbase.modules.org.entity.OrgUnit">
|
select un.*,ux.regionid,ux.regionname,ur.managerids,ur.managernames from ORG_UNIT un
|
LEFT JOIN (
|
SELECT distinct A.unitid,
|
(SELECT STRING_AGG(cast(B.regionid as varchar),',') FROM (
|
SELECT ou.unitid,qh.regionid,qh.regionname
|
FROM ORG_UNIT ou
|
INNER JOIN ORG_UNITREGION ux ON ou.unitid = ux.unitid
|
left join ORG_REGION qh on qh.regionid = replace(ux.regionid,' ','')
|
) B WHERE B.unitid = A.unitid group by A.unitid order by A.unitid) as regionid,
|
(SELECT STRING_AGG(cast(C.regionname as varchar),',') FROM (
|
SELECT ou.unitid,qh.regionid,qh.regionname
|
FROM ORG_UNIT ou
|
INNER JOIN ORG_UNITREGION ux ON ou.unitid = ux.unitid
|
left join ORG_REGION qh on qh.regionid = replace(ux.regionid,' ','')
|
) C WHERE C.unitid = A.unitid group by A.unitid order by A.unitid) as regionname
|
FROM (
|
SELECT ou.unitid,qh.regionid,qh.regionname
|
FROM ORG_UNIT ou
|
INNER JOIN ORG_UNITREGION ux ON ou.unitid = ux.unitid
|
left join ORG_REGION qh on qh.regionid = replace(ux.regionid,' ','')
|
)A GROUP BY A.unitid
|
)ux on ux.unitid=un.unitid
|
LEFT JOIN (
|
SELECT distinct A.unitid,
|
(SELECT STRING_AGG(cast(B.userid as varchar),',') FROM (
|
SELECT ui.unitid,um.userid,gu.chinesename
|
from ORG_UNIT ui
|
inner join ORG_UNITMANAGER um on ui.unitid = um.unitid
|
left join ORG_USER gu on gu.userid = um.userid
|
) B WHERE B.unitid = A.unitid group by A.unitid order by A.unitid) as managerids,
|
(SELECT STRING_AGG(cast(C.chinesename as varchar),',') FROM (
|
SELECT ui.unitid,um.userid,gu.chinesename
|
from ORG_UNIT ui
|
inner join ORG_UNITMANAGER um on ui.unitid = um.unitid
|
left join ORG_USER gu on gu.userid = um.userid
|
) C WHERE C.unitid = A.unitid group by chinesename order by chinesename) as managernames
|
FROM (
|
SELECT ui.unitid,um.userid,gu.chinesename
|
from ORG_UNIT ui
|
inner join ORG_UNITMANAGER um on ui.unitid = um.unitid
|
left join ORG_USER gu on gu.userid = um.userid
|
)A
|
)ur on ur.unitid = un.unitid
|
where un.UNITID = #{value}
|
</select>
|
|
<select id="queryList" resultType="com.landtool.lanbase.modules.org.entity.OrgUnit">
|
select * from (
|
SELECT *
|
FROM(
|
SELECT ROW_NUMBER() OVER(ORDER BY B.unitid) AS rownumber,B.*
|
FROM(
|
select un.*,f.vtext unittypetext from ORG_UNIT un
|
LEFT join SYS_FIELDVALUE f on f.vcode = un.unittype and f.fkey ='UnitType'
|
<where>
|
<if test="unitname != null and unitname != ''">
|
AND (un.unitname LIKE ('%' || #{unitname} || '%') or LOWER(un.spellfirst) LIKE ('%' || LOWER(#{unitname}) || '%'))
|
</if>
|
<if test="unittype != null and unittype != ''">
|
AND un.unittype LIKE ('%' || #{unittype} || '%')
|
</if>
|
<if test="parentid != null and parentid != 0">
|
AND un.parentid = #{parentid}
|
</if>
|
<if test="isdept != null">
|
AND un.isdept = #{isdept}
|
</if>
|
<if test="isdept == null">
|
AND un.isdept != 1
|
</if>
|
and un.status = 1
|
</where>
|
) B
|
) A
|
WHERE rownumber > #{lowerOffset} AND <![CDATA[ rownumber <= ${upperOffset} ]]>
|
)a order by
|
<choose>
|
<when test="sidx != null and sidx != ''">
|
${sidx} ${order}
|
</when>
|
<otherwise>
|
unitid
|
</otherwise>
|
</choose>
|
</select>
|
|
<select id="queryTotal" resultType="int">
|
select count(*) from ORG_UNIT un
|
<where>
|
<if test="unitname != null and unitname != ''">
|
AND (un.unitname LIKE ('%' || #{unitname} || '%') or LOWER(un.spellfirst) LIKE ('%' || LOWER(#{unitname}) || '%') )
|
</if>
|
<if test="unittype != null and unittype != ''">
|
AND un.unittype LIKE ('%' || #{unittype} || '%')
|
</if>
|
<if test="parentid != null and parentid != 0">
|
AND un.parentid = #{parentid}
|
</if>
|
<if test="isdept != null">
|
AND un.isdept = #{isdept}
|
</if>
|
<if test="isdept == null">
|
AND un.isdept != 1
|
</if>
|
and un.status = 1
|
</where>
|
</select>
|
|
<insert id="save" parameterType="com.landtool.lanbase.modules.org.entity.OrgUnit">
|
insert into ORG_UNIT
|
(
|
PARENTID,
|
UNITNAME,
|
UNIDCODE,
|
UNIDORGCODE,
|
SPELLFIRST,
|
UNITSHORT,
|
UNITTYPE,
|
RORDER,
|
CONTACTNUMBER,
|
FAXNUMBER,
|
EMAIL,
|
ADDRESS,
|
POSTALCODE,
|
PHOTOURL,
|
WEBSITEURL,
|
STATUS,
|
RCREATEDATE,
|
RCREATEUSER,
|
RLASTEDITDATE,
|
REMARK,
|
ISDEPT
|
)
|
values
|
(
|
#{parentid},
|
#{unitname},
|
#{unidcode,jdbcType=VARCHAR},
|
#{unidorgcode,jdbcType=VARCHAR},
|
#{spellfirst,jdbcType=VARCHAR},
|
#{unitshort,jdbcType=VARCHAR},
|
#{unittype},
|
#{rorder},
|
#{contactnumber,jdbcType=VARCHAR},
|
#{faxnumber,jdbcType=VARCHAR},
|
#{email,jdbcType=VARCHAR},
|
#{address,jdbcType=VARCHAR},
|
#{postalcode,jdbcType=VARCHAR},
|
#{photourl,jdbcType=VARCHAR},
|
#{websiteurl,jdbcType=VARCHAR},
|
#{status},
|
#{rcreatedate},
|
#{rcreateuser},
|
#{rlasteditdate},
|
#{remark,jdbcType=VARCHAR},
|
#{isdept}
|
)
|
</insert>
|
|
<update id="update" parameterType="com.landtool.lanbase.modules.org.entity.OrgUnit">
|
update ORG_UNIT
|
<set>
|
<if test="parentid != null">PARENTID = #{parentid}, </if>
|
<if test="unitname != null">UNITNAME = #{unitname}, </if>
|
<if test="unidcode != null">UNIDCODE = #{unidcode}, </if>
|
<if test="unidorgcode != null">UNIDORGCODE = #{unidorgcode}, </if>
|
<if test="spellfirst != null">SPELLFIRST = #{spellfirst}, </if>
|
<if test="unitshort != null">UNITSHORT = #{unitshort}, </if>
|
<if test="unittype != null">UNITTYPE = #{unittype}, </if>
|
<if test="rorder != null">RORDER = #{rorder}, </if>
|
<if test="contactnumber != null">CONTACTNUMBER = #{contactnumber}, </if>
|
<if test="faxnumber != null">FAXNUMBER = #{faxnumber}, </if>
|
<if test="email != null">EMAIL = #{email}, </if>
|
<if test="address != null">ADDRESS = #{address}, </if>
|
<if test="postalcode != null">POSTALCODE = #{postalcode}, </if>
|
<if test="photourl != null">PHOTOURL = #{photourl}, </if>
|
<if test="websiteurl != null">WEBSITEURL = #{websiteurl}, </if>
|
<if test="status != null">STATUS = #{status}, </if>
|
<if test="rcreatedate != null">RCREATEDATE = #{rcreatedate}, </if>
|
<if test="rcreateuser != null">RCREATEUSER = #{rcreateuser}, </if>
|
<if test="rlasteditdate != null">RLASTEDITDATE = #{rlasteditdate}, </if>
|
<if test="remark != null">REMARK = #{remark}, </if>
|
<if test="isdept != null">ISDEPT = #{isdept}</if>
|
</set>
|
where UNITID = #{unitid}
|
</update>
|
|
<delete id="delete">
|
delete from ORG_UNIT where UNITID = #{value}
|
</delete>
|
|
<delete id="deleteBatch">
|
delete from ORG_UNIT where UNITID in
|
<foreach item="unitid" collection="array" open="(" separator="," close=")">
|
#{unitid}
|
</foreach>
|
</delete>
|
|
<select id="queryObjectJoinRegion" resultMap="UnitJoinRegion">
|
SELECT
|
<include refid="unitColumns"/>,
|
<include refid="unitRegionColumns"/>
|
FROM ORG_UNIT un
|
LEFT JOIN ORG_UNITREGION ux ON un.UNITID=ux.UNITID
|
WHERE un.UNITID = #{unitid} and isdept != 1 and STATUS = 1
|
</select>
|
|
<select id="queryListByTime" resultType="com.landtool.lanbase.modules.org.entity.OrgUnit">
|
SELECT
|
<include refid="unitColumns"/>
|
FROM ORG_UNIT un
|
WHERE un.RLASTEDITDATE > #{time} and isdept != 1 and STATUS = 1
|
</select>
|
|
<select id="findUnitNames" resultType="com.landtool.lanbase.common.utils.NameBindId">
|
select
|
un.UNITNAME AS NAME,un.UNITID AS ID
|
FROM ORG_UNIT un
|
<where>
|
<!-- 查询状态为正常的机构 alert ykm 2019/03/19 -->
|
STATUS = 1
|
and isdept != 1
|
<if test="keyWord != null and keyWord != ''">
|
AND un.UNITNAME LIKE ('%' || #{keyWord} || '%')
|
</if>
|
</where>
|
</select>
|
|
<select id="findPinyin" resultType="java.lang.String">
|
select
|
un.UNITNAME
|
from ORG_UNIT un
|
<where>
|
<!-- 查询状态为正常的机构 alert ykm 2019/03/19 -->
|
STATUS = 1
|
and isdept != 1
|
<if test="keyWord != null and keyWord != ''">
|
and (LOWER(un.SPELLFIRST) LIKE ('%' || LOWER(#{keyWord}) || '%')
|
or un.unitname LIKE ('%' || #{keyWord} || '%'))
|
</if>
|
</where>
|
</select>
|
|
<select id="findPinyinList" resultType="com.landtool.lanbase.modules.org.entity.OrgUnit">
|
select *
|
from ORG_UNIT un
|
<where>
|
and isdept != 1
|
<if test="keyWord != null and keyWord != ''">
|
AND LOWER(un.SPELLFIRST) LIKE ('%' || LOWER(#{keyWord}) || '%')
|
</if>
|
</where>
|
</select>
|
|
<select id="queryObjectByFullName" resultType="com.landtool.lanbase.modules.org.entity.OrgUnit">
|
select * from ORG_UNIT un where un.UNITNAME = #{unitname} and isdept != 1
|
</select>
|
|
<select id="queryUnitWithSEQ" resultType="Long">
|
SELECT currval('ORG_UNIT_SEQ') FROM DUAL
|
</select>
|
|
<select id="queryUnitTreeList" resultType="com.landtool.lanbase.modules.org.entity.OrgUnit">
|
select * from ORG_UNIT where status = 1 and isdept != 1 order by rorder
|
</select>
|
|
<select id="queryTreeChildList" resultType="com.landtool.lanbase.modules.org.entity.OrgUnit">
|
with RECURSIVE tab(UNITID,PARENTID,
|
UNITNAME,
|
UNIDCODE,
|
UNIDORGCODE,
|
SPELLFIRST,
|
UNITSHORT,
|
UNITTYPE,
|
RORDER,
|
CONTACTNUMBER,
|
FAXNUMBER,
|
EMAIL,
|
ADDRESS,
|
POSTALCODE,
|
PHOTOURL,
|
WEBSITEURL,
|
STATUS,
|
RCREATEDATE,
|
RCREATEUSER,
|
RLASTEDITDATE,
|
REMARK,
|
ISDEPT) as (
|
select UNITID,PARENTID,
|
UNITNAME,
|
UNIDCODE,
|
UNIDORGCODE,
|
SPELLFIRST,
|
UNITSHORT,
|
UNITTYPE,
|
RORDER,
|
CONTACTNUMBER,
|
FAXNUMBER,
|
EMAIL,
|
ADDRESS,
|
POSTALCODE,
|
PHOTOURL,
|
WEBSITEURL,
|
STATUS,
|
RCREATEDATE,
|
RCREATEUSER,
|
RLASTEDITDATE,
|
REMARK,
|
ISDEPT from ORG_UNIT
|
where cast(unitid as varchar) = #{unitid} and isdept != 1
|
union all
|
select b.UNITID,b.PARENTID,
|
b.UNITNAME,
|
b.UNIDCODE,
|
b.UNIDORGCODE,
|
b.SPELLFIRST,
|
b.UNITSHORT,
|
b.UNITTYPE,
|
b.RORDER,
|
b.CONTACTNUMBER,
|
b.FAXNUMBER,
|
b.EMAIL,
|
b.ADDRESS,
|
b.POSTALCODE,
|
b.PHOTOURL,
|
b.WEBSITEURL,
|
b.STATUS,
|
b.RCREATEDATE,
|
b.RCREATEUSER,
|
b.RLASTEDITDATE,
|
b.REMARK,
|
b.ISDEPT from tab a,
|
ORG_UNIT b
|
where b.parentid = a.unitid
|
)
|
SELECT *
|
FROM(
|
SELECT ROW_NUMBER() OVER(ORDER BY C.parentid,C.rorder) AS rownumber,C.*,f.vtext unittypetext
|
FROM
|
tab
|
C LEFT join SYS_FIELDVALUE f on f.vcode = C.unittype and f.fkey ='UnitType' where C.status = 1 and C.isdept != 1
|
) D
|
WHERE rownumber > #{lowerOffset} AND <![CDATA[ rownumber <= ${upperOffset} ]]>
|
</select>
|
|
<select id="queryTreeChildTotal" resultType="int">
|
with RECURSIVE tab(UNITID,PARENTID,
|
UNITNAME,
|
UNIDCODE,
|
UNIDORGCODE,
|
SPELLFIRST,
|
UNITSHORT,
|
UNITTYPE,
|
RORDER,
|
CONTACTNUMBER,
|
FAXNUMBER,
|
EMAIL,
|
ADDRESS,
|
POSTALCODE,
|
PHOTOURL,
|
WEBSITEURL,
|
STATUS,
|
RCREATEDATE,
|
RCREATEUSER,
|
RLASTEDITDATE,
|
REMARK,
|
ISDEPT) as (
|
select UNITID,PARENTID,
|
UNITNAME,
|
UNIDCODE,
|
UNIDORGCODE,
|
SPELLFIRST,
|
UNITSHORT,
|
UNITTYPE,
|
RORDER,
|
CONTACTNUMBER,
|
FAXNUMBER,
|
EMAIL,
|
ADDRESS,
|
POSTALCODE,
|
PHOTOURL,
|
WEBSITEURL,
|
STATUS,
|
RCREATEDATE,
|
RCREATEUSER,
|
RLASTEDITDATE,
|
REMARK,
|
ISDEPT from ORG_UNIT
|
where cast(unitid as varchar) = #{unitid}
|
union all
|
select b.UNITID,b.PARENTID,
|
b.UNITNAME,
|
b.UNIDCODE,
|
b.UNIDORGCODE,
|
b.SPELLFIRST,
|
b.UNITSHORT,
|
b.UNITTYPE,
|
b.RORDER,
|
b.CONTACTNUMBER,
|
b.FAXNUMBER,
|
b.EMAIL,
|
b.ADDRESS,
|
b.POSTALCODE,
|
b.PHOTOURL,
|
b.WEBSITEURL,
|
b.STATUS,
|
b.RCREATEDATE,
|
b.RCREATEUSER,
|
b.RLASTEDITDATE,
|
b.REMARK,
|
b.ISDEPT from tab a,
|
ORG_UNIT b
|
where b.parentid = a.unitid
|
)
|
select Count(*) from tab where status = 1 and isdept != 1
|
</select>
|
|
<update id="queryUnitById" >
|
update ORG_UNIT
|
set STATUS = 2, RLASTEDITDATE = now() where UNITID in
|
<foreach item="id" collection="unitid" open="(" separator="," close=")">
|
#{id}
|
</foreach>
|
</update>
|
|
<select id="queryListByParentid" resultType="com.landtool.lanbase.modules.org.entity.OrgUnit">
|
select * from ORG_UNIT where parentid = #{parentid} and status = 1 and isdept != 1 order by rorder
|
</select>
|
|
<update id="updateRorder" parameterType="com.landtool.lanbase.modules.org.entity.OrgUnit">
|
update ORG_UNIT
|
<set>
|
RLASTEDITDATE=now(),
|
<if test="rorder != null">RORDER = #{rorder}</if>
|
</set>
|
where unitid = #{unitid}
|
</update>
|
|
<select id="queryMaxRorder" resultType="int">
|
select case when max(rorder) > 0 then max(rorder) else 0 end as rorder from ORG_UNIT where parentid=#{parentid} and isdept != 1
|
</select>
|
|
<select id="queryAllList" resultType="com.landtool.lanbase.modules.org.entity.OrgUnit">
|
SELECT
|
*
|
FROM ORG_UNIT un where status = 1 and isdept != 1
|
</select>
|
|
<select id="queryDeptList" resultType="com.landtool.lanbase.modules.org.entity.OrgUnit">
|
select * from ORG_UNIT where status = 1 and isdept = 1 and parentid = (select unitid from ORG_UNIT where unitname = #{unitname})
|
</select>
|
</mapper>
|