2020-05-19 18:04:42 +08:00

172 lines
8.0 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,lso.employee_no staff_no,ls.name,lso.position,
case lso.staff_status when 0 then '在职' else '离职' end staff_status,
if(ls.employee_id=ld.leader_employee_id,1,0) department_leader
from lz_staff ls,lz_staff_occupation lso,lz_departments_staff_relate dsr,lz_departments ld
where lso.staff_id=ls.id and ls.is_delete=0 and dsr.staff_id = ls.id and ld.department_id=dsr.department_id
and lso.staff_status=#{staffStatus}
<if test="departmentId != null and departmentId != ''">
and dsr.department_id=#{departmentId}
</if>
<if test="name != null and name != ''">
and ls.name=#{name}
</if>
limit #{startIndex}, #{pageLimit}
</select>
<select id="getStaffInfoCount" resultType="java.lang.Integer">
select count(1)
from lz_staff ls,lz_staff_occupation lso,lz_departments_staff_relate dsr,lz_departments ld
where lso.staff_id=ls.id and ls.is_delete=0 and dsr.staff_id = ls.id and ld.department_id=dsr.department_id
and lso.staff_status=#{staffStatus}
<if test="departmentId != null and departmentId != ''">
and dsr.department_id=#{departmentId}
</if>
<if test="name != null and name != ''">
and ls.name=#{name}
</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.id)) 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.id)))*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) ls,
lz_departments_staff_relate dsr,lz_staff_occupation so,
(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 so.staff_id=ls.id
and dsr.department_id=td.department_id
and (date(so.resignation_time)>=#{endDate} or so.resignation_time is null )
</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 group by gender
</select>
</mapper>