2020-05-22 17:05:52 +08:00

273 lines
13 KiB
XML

<?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.lz.modules.app.dao.StaffDao">
<!-- 可根据自己的需求,是否要使用 -->
<resultMap type="com.lz.modules.app.entity.StaffEntity" id="staffMap">
<result property="id" column="id"/>
<result property="isDelete" column="is_delete"/>
<result property="createTime" column="create_time"/>
<result property="updateTime" column="update_time"/>
<result property="name" column="name"/>
<result property="gender" column="gender"/>
<result property="birthday" column="birthday"/>
<result property="maritalStatus" column="marital_status"/>
<result property="national" column="national"/>
<result property="politicalLandscape" column="political_landscape"/>
<result property="mobile" column="mobile"/>
<result property="province" column="province"/>
<result property="emergencyContact" column="emergency_contact"/>
<result property="emergencyContactRelation" column="emergency_contact_relation"/>
<result property="emergencyContactPhone" column="emergency_contact_phone"/>
<result property="email" column="email"/>
<result property="currentAddress" column="current_address"/>
<result property="openId" column="open_id"/>
<result property="employeeId" column="employee_id"/>
<result property="unionId" column="union_id"/>
</resultMap>
<select id="getStaffInfoByOpenId" resultType="com.lz.modules.app.entity.StaffEntity">
select * from lz_staff where is_delete=0 and open_id = #{openId}
</select>
<update id="updateStaff">
UPDATE lz_staff
<set>
update_time = now(),
<if test="name != null and name != '' ">
name = #{name,jdbcType=VARCHAR},
</if>
<if test="gender != null">
gender = #{gender,jdbcType=INTEGER},
</if>
<if test="birthday != null and birthday != '' ">
birthday = #{birthday,jdbcType=VARCHAR},
</if>
<if test="maritalStatus != null">
marital_status = #{maritalStatus,jdbcType=INTEGER},
</if>
<if test="national != null and national != '' ">
national = #{national,jdbcType=VARCHAR},
</if>
<if test="politicalLandscape != null and politicalLandscape != '' ">
political_landscape = #{politicalLandscape,jdbcType=VARCHAR},
</if>
<if test="mobile != null and mobile != '' ">
mobile = #{mobile,jdbcType=VARCHAR},
</if>
<if test="province != null and province != '' ">
province = #{province,jdbcType=VARCHAR},
</if>
<if test="emergencyContact != null and emergencyContact != '' ">
emergency_contact = #{emergencyContact,jdbcType=VARCHAR},
</if>
<if test="emergencyContactRelation != null and emergencyContactRelation != '' ">
emergency_contact_relation = #{emergencyContactRelation,jdbcType=VARCHAR},
</if>
<if test="emergencyContactPhone != null and emergencyContactPhone != '' ">
emergency_contact_phone = #{emergencyContactPhone,jdbcType=VARCHAR},
</if>
<if test="email != null and email != '' ">
email = #{email,jdbcType=VARCHAR},
</if>
<if test="currentAddress != null and currentAddress != '' ">
current_address = #{currentAddress,jdbcType=VARCHAR},
</if>
<if test="employeeId != null and employeeId != '' ">
employee_id = #{employeeId,jdbcType=VARCHAR},
</if>
<if test="unionId != null and unionId != '' ">
union_id = #{unionId,jdbcType=VARCHAR},
</if>
</set>
WHERE is_delete = 0 AND open_id = #{openId ,jdbcType=BIGINT}
</update>
<insert id="addStaffBatch">
INSERT INTO lz_staff(name,gender,mobile,email,open_id,employee_id,union_id)
VALUES
<foreach collection="staffs" item="staff" separator=",">
(#{staff.name},#{staff.gender},#{staff.mobile},#{staff.email},#{staff.openId},#{staff.employeeId},#{staff.unionId})
</foreach>
</insert>
<select id="getByName" resultType="com.lz.modules.app.entity.StaffEntity">
select * from lz_staff where is_delete=0 and name = #{name}
</select>
<select id="getStaffInfos" resultType="com.lz.modules.app.Dto.StaffDto">
select ls.id staffId,if(lso.employee_no='', lso.staff_no,lso.employee_no) staff_no,ls.name,lso.position,
case lso.staff_status when 0 then '在职' else '离职' end staff_status,
if(ls.employee_id in (select leader_employee_id from lz_departments where is_delete=0
<if test="departmentId != null and departmentId != ''">
and department_id=#{departmentId}
</if>
),1,0) department_leader
from lz_staff ls,lz_staff_occupation lso
where lso.staff_id=ls.id and ls.is_delete=0
and lso.staff_status=#{staffStatus}
<if test="name != null and name != ''">
and ls.name like concat('%',#{name},'%')
</if>
and (ls.id in (
select dsr.staff_id from lz_departments_staff_relate dsr where dsr.is_delete=0
<if test="departmentId != null and departmentId != ''">
and dsr.department_id=#{departmentId}
</if>
)
or ls.employee_id in (
select sr.leader_employee_id from lz_departments sr where sr.is_delete=0
<if test="departmentId != null and departmentId != ''">
and sr.department_id=#{departmentId}
</if>
)) order by department_leader desc
limit #{startIndex}, #{pageLimit}
</select>
<select id="getStaffInfoCount" resultType="java.lang.Integer">
select count(ls.id) count
from lz_staff ls,lz_staff_occupation lso
where lso.staff_id=ls.id and ls.is_delete=0
and lso.staff_status=#{staffStatus}
<if test="name != null and name != ''">
and ls.name like concat('%',#{name},'%')
</if>
and (ls.id in (
select dsr.staff_id from lz_departments_staff_relate dsr where dsr.is_delete=0
<if test="departmentId != null and departmentId != ''">
and dsr.department_id=#{departmentId}
</if>
)
or ls.employee_id in (
select sr.leader_employee_id from lz_departments sr where sr.is_delete=0
<if test="departmentId != null and departmentId != ''">
and sr.department_id=#{departmentId}
</if>
))
</select>
<select id="getBaseInfo" resultType="com.lz.modules.app.Dto.StaffBaseInfoDto">
select name staffName,gender,birthday,marital_status,national,political_landscape,mobile,current_address from lz_staff where id=#{staffId}
</select>
<select id="getStatisticalData" resultType="com.lz.modules.app.Dto.StaffStatisticalDto">
select
count(DISTINCT(ls.nowin_staff)) totalStaffCount,
count(DISTINCT(td.leader_employee_id)) managementCount,
ifnull(round(count(DISTINCT(td.leader_employee_id))/count(DISTINCT(ls.id))*100,2),0) managementRate,
count(DISTINCT(ls.new_staff)) newStaffCount,
count(DISTINCT(ls.leave_staff)) leaveStaffCount,
ifnull(round(count(DISTINCT(ls.leave_staff))/(count(DISTINCT(ls.leave_staff))+count(DISTINCT(ls.nowin_staff)))*100,2),0)
leaveRate
from
(select * from lz_staff ll
left join
(select staff_id as new_staff from lz_staff_occupation where date(entry_time) between #{beginDate} and
#{endDate}) so1
on so1.new_staff=ll.id
left join
(select staff_id as leave_staff from lz_staff_occupation where date(resignation_time) between #{beginDate} and
#{endDate}) so2
on so2.leave_staff=ll.id
left join
(select staff_id as nowin_staff from lz_staff_occupation where date(resignation_time)>=#{endDate} or
resignation_time is null) so3
on so3.nowin_staff=ll.id) ls,
lz_departments_staff_relate dsr,
(select * from lz_departments
<if test="departmentId != null and departmentId != ''">
where find_in_set(department_id, getChildList(#{departmentId}))
</if>
) td
where ls.is_delete=0 and ls.id=dsr.staff_id
and dsr.department_id=td.department_id
</select>
<select id="getGenderData" resultType="com.lz.modules.app.Dto.GraphicsStatisticalDto">
select
case gender when 1 then '男'
when 2 then '女'
else '未知'
end category,
count(gender) number
from lz_staff
where is_delete=0 and id in (select so.staff_id from lz_staff_occupation so where date(so.resignation_time)<![CDATA[ >= ]]>#{endDate} or
so.resignation_time is null)
<if test="departmentId != null and departmentId != ''">
and id in (select dsr.staff_id from lz_departments_staff_relate dsr,lz_departments ld where
dsr.department_id=ld.department_id and find_in_set(ld.department_id, getChildList(#{departmentId})))
</if>
group by gender
</select>
<select id="getAgeData" resultType="com.lz.modules.app.Dto.GraphicsStatisticalDto">
select
if(birthday=0,'未知',concat(birthday,'后')) category,
count(birthday) number
from (
select
id,ifnull(CONCAT(left(date_format(birthday,'%y'),1),'0'),0) birthday
from lz_staff
where is_delete=0 and id in (select so.staff_id from lz_staff_occupation so where date(so.resignation_time)<![CDATA[ >= ]]>#{endDate} or
so.resignation_time is null)
<if test="departmentId != null and departmentId != ''">
and id in (select dsr.staff_id from lz_departments_staff_relate dsr,lz_departments ld where
dsr.department_id=ld.department_id and find_in_set(ld.department_id, getChildList(#{departmentId})))
</if>
) t
group by t.birthday
</select>
<select id="getJobSeniorityData" resultType="com.lz.modules.app.Dto.GraphicsStatisticalDto">
select
t.jobYear category,
count(jobYear) number
from (
select staff_id,
case
when TIMESTAMPDIFF(YEAR,job_begin_time,DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%S')) <![CDATA[ >= ]]> 0 and
TIMESTAMPDIFF(YEAR,job_begin_time,DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%S'))<![CDATA[ < ]]>3
then '0-3年'
when TIMESTAMPDIFF(YEAR,job_begin_time,DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%S')) <![CDATA[ >= ]]> 3 and
TIMESTAMPDIFF(YEAR,job_begin_time,DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%S'))<![CDATA[ < ]]>5
then '3-5年'
when TIMESTAMPDIFF(YEAR,job_begin_time,DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%S')) <![CDATA[ >= ]]> 5 and
TIMESTAMPDIFF(YEAR,job_begin_time,DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%S'))<![CDATA[ < ]]>10
then '5-10年'
when TIMESTAMPDIFF(YEAR,job_begin_time,DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%S')) <![CDATA[ >= ]]> 10
then '10年以上' else '未知' end jobYear from lz_staff_occupation ls
where ls.is_delete=0 and ls.staff_id in (select so.staff_id from lz_staff_occupation so where date(so.resignation_time)<![CDATA[ >= ]]>#{endDate}
or so.resignation_time is null)
<if test="departmentId != null and departmentId != ''">
and ls.staff_id in (select dsr.staff_id from lz_departments_staff_relate dsr,lz_departments ld where
dsr.department_id=ld.department_id and find_in_set(ld.department_id, getChildList(#{departmentId})))
</if>
) t
group by t.jobYear
</select>
<select id="getEducationData" resultType="com.lz.modules.app.Dto.GraphicsStatisticalDto">
select
y.education category,
count(education) number
from (
select t.id,ifnull(se.education,'未知') education from
(select ls.id from lz_staff ls
where ls.is_delete=0 and ls.id in (select so.staff_id from lz_staff_occupation so where date(so.resignation_time)<![CDATA[ >= ]]>#{endDate} or
so.resignation_time is null)
<if test="departmentId != null and departmentId != ''">
and ls.id in (select dsr.staff_id from lz_departments_staff_relate dsr,lz_departments ld where
dsr.department_id=ld.department_id and find_in_set(ld.department_id, getChildList(#{departmentId})))
</if>) t
left join lz_staff_education se on
se.staff_id=t.id
) y
group by y.education
</select>
</mapper>