<?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.jeeplus.modules.workstaff.dao.WorkStaffAchivesDao">
    
	<sql id="workStaffBasicInfoColumns">
		a.id AS "id",
		a.create_by AS "createBy.id",
		a.create_date AS "createDate",
		a.update_by AS "updateBy.id",
		a.update_date AS "updateDate",
		a.remarks AS "remarks",
		a.del_flag AS "delFlag",
		a.office_id AS "office.id",
		a.company_id AS "company.id",
		a.no AS "no",
		a.dimission_date AS "dimissionDate",
		a.workEnd_date AS "workEndDate",
		a.name AS "name",
		a.gender AS "gender",
		a.nation AS "nation",
		a.id_card AS "idCard",
		a.age AS "age",
		a.birthday AS "birthday",
		a.calendar AS "calendar",
		a.email AS "email",
		a.mobile AS "mobile",
		a.phone AS "phone",
		a.marriage AS "marriage",
		a.politics AS "politics",
		a.ex_soldier AS "exSoldier",
		a.address AS "address",
		a.native_place AS "nativePlace.id",
		a.household AS "household",
		a.duty AS "duty",
		a.job_grade AS "jobGrade.id",
		a.status AS "status",
		a.entry_date AS "entryDate",
		a.work_date AS "workDate",
		a.bank_name AS "bankName",
		a.bank_card AS "bankCard",
		a.industry_date AS "industryDate",
		a.ts AS "ts",
		a.picture AS "picture",
		o.top_company AS "office.name",
		o.top_company AS "office.topCompany",
		a.user_id AS "userId",
		a.branch_office AS "branchOffice.id",
		branch.name AS "branchOffice.name",
		s.name AS "company.name",
		jg.name AS "jobGrade.name",
		jg.pay AS "salary",
		nativePlace.name AS "nativePlace.name",
		a.percent AS "percent",
		a.try_end_time AS "tryEndTime"
	</sql>
	
	<sql id="workStaffBasicInfoJoins">
		LEFT JOIN sys_office o ON o.id = a.office_id
		LEFT JOIN sys_office branch ON branch.id = a.branch_office
		LEFT JOIN sys_office s ON s.id = a.company_id
		LEFT JOIN sys_user u ON u.id = a.create_by
		LEFT JOIN sys_area nativePlace ON nativePlace.id = a.native_place
		LEFT JOIN work_job_grade jg ON jg.id = a.job_grade
	</sql>

	<select id="get" resultType="WorkStaffBasicInfo" >
		SELECT 
			<include refid="workStaffBasicInfoColumns"/>
		FROM work_staff_achives a
		<include refid="workStaffBasicInfoJoins"/>
		WHERE a.id = #{id}
	</select>

	<select id="getByUserId" resultType="WorkStaffBasicInfo" >
		SELECT
		<include refid="workStaffBasicInfoColumns"/>
		FROM work_staff_achives a
		<include refid="workStaffBasicInfoJoins"/>
		WHERE a.user_id = #{id}
	</select>
	
	<select id="findList" resultType="WorkStaffBasicInfo" >
		SELECT 
			<include refid="workStaffBasicInfoColumns"/>
		FROM work_staff_achives a
		<include refid="workStaffBasicInfoJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			<if test="company != null and company.id != null and company.id != ''">
				AND a.company_id = #{company.id}
			</if>
			<if test="office != null and office.id != null and office.id != ''">
				AND a.office_id = #{office.id}
			</if>
			<if test="no != null and no != ''">
				AND a.no = #{no}
			</if>
			<if test="name != null and name != ''">
				AND a.name LIKE 
					<if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
					<if test="dbName == 'mssql'">'%'+#{name}+'%'</if>
					<if test="dbName == 'mysql'">concat('%',#{name},'%')</if>
			</if>
			<if test="idCard != null and idCard != ''">
				AND a.id_card = #{idCard}
			</if>
			<if test="mobile != null and mobile != ''">
				AND a.mobile = #{mobile}
			</if>
			<if test="jobGrade != null and jobGrade.id !=null and jobGrade.id != ''">
				AND a.job_grade = #{jobGrade.id}
			</if>
			<if test="status != null and status != ''">
				AND a.status = #{status}
			</if>
			<if test="beginEntryDate != null">
				AND a.entry_date >= #{beginEntryDate}
			</if>
			<if test="endEntryDate != null">
				AND a.entry_date &lt;= #{endEntryDate}
			</if>
			<if test="minAge != null">
				AND a.age >= #{minAge}
			</if>
			<if test="maxAge != null">
				AND a.age &lt;= #{maxAge}
			</if>
			<if test="nation != null and nation !=''">
				AND a.nation = #{nation}
			</if>
			<if test="calendar != null and calendar !=''">
				AND a.calendar = #{calendar}
			</if>
			<if test="gender != null and gender !=''">
				AND a.gender = #{gender}
			</if>
			<if test="marriage != null and marriage !=''">
				AND a.marriage = #{marriage}
			</if>
			<if test="politics != null and politics !=''">
				AND a.politics = #{politics}
			</if>
			<if test="minSalary != null">
				AND jg.pay >= #{minSalary}
			</if>
			<if test="maxSalary != null">
				AND jg.pay &lt;= #{maxSalary}
			</if>
			<if test="beginWorkDate != null">
				AND a.work_date >= #{beginWorkDate}
			</if>
			<if test="endWorkDate != null">
				AND a.work_date &lt;= #{endWorkDate}
			</if>
			<if test="beginBirthdayDate != null">
				AND a.birthday >= #{beginBirthdayDate}
			</if>
			<if test="endBirthdayDate != null">
				AND a.birthday &lt;= #{endBirthdayDate}
			</if>
			<if test="minPercent != null and minPercent !=''">
				AND a.percent >= #{minPercent}
			</if>
			<if test="maxPercent != null and maxPercent!=''">
				AND a.percent &lt;= #{maxPercent}
			</if>
            <if test="sqlMap.dsf !=null and sqlMap.dsf !=''">
                AND ((a.user_id = #{currentUser.id} AND a.branch_office = #{currentUser.branchOffice.id})${sqlMap.dsf} )
            </if>
		</where>
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.entry_date DESC
			</otherwise>
		</choose>
	</select>

	<select id="findListByRoleList" resultType="WorkStaffBasicInfo">
		select
		<include refid="workStaffBasicInfoColumns"/>
		FROM work_staff_achives a
		<include refid="workStaffBasicInfoJoins"/>
		LEFT JOIN sys_user_role ur ON ur.user_id = a.user_id
		LEFT JOIN sys_role r ON ur.role_id = r.id
		WHERE
		a.del_flag = #{DEL_FLAG_NORMAL} AND r.id = #{roleId} AND `status` IN ('试用','正式','劳务')
		<if test="company != null and company.id != null and company.id != ''">
			AND a.company_id = #{company.id}
		</if>
		<if test="office != null and office.id != null and office.id != ''">
			AND a.office_id = #{office.id}
		</if>
		<if test="no != null and no != ''">
			AND a.no = #{no}
		</if>
		<if test="name != null and name != ''">
			AND a.name LIKE
			<if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
			<if test="dbName == 'mssql'">'%'+#{name}+'%'</if>
			<if test="dbName == 'mysql'">concat('%',#{name},'%')</if>
		</if>
		<if test="idCard != null and idCard != ''">
			AND a.id_card = #{idCard}
		</if>
		<if test="mobile != null and mobile != ''">
			AND a.mobile = #{mobile}
		</if>
		<if test="jobGrade != null and jobGrade.id !=null and jobGrade.id != ''">
			AND a.job_grade = #{jobGrade.id}
		</if>
		<if test="status != null and status != ''">
			AND a.status = #{status}
		</if>
		<if test="beginEntryDate != null">
			AND a.entry_date >= #{beginEntryDate}
		</if>
		<if test="endEntryDate != null">
			AND a.entry_date &lt;= #{endEntryDate}
		</if>
		<if test="achiveId != null and achiveId !=''">
			AND a.achive_id = #{achiveId}
		</if>
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.update_date DESC
			</otherwise>
		</choose>
	</select>
	<select id="getByCompany" resultType="java.lang.Integer" >
		select count(*) FROM work_staff_achives
		where
		user_id = #{userId}
		AND company_id = #{company.id}
		AND `status` IN ('试用','正式','劳务')
		AND del_flag = '0'
	</select>
	<select id="getByBranchCompany" resultType="java.lang.Integer" >
		select count(*) FROM work_staff_achives
		where
		user_id = #{userId}
		AND branch_office = #{branchOffice.id}
		AND `status` IN ('试用','正式','劳务')
		AND del_flag = '0'
	</select>
	<select id="getByCompanyInfo" resultType="WorkStaffBasicInfo" >
		select
		<include refid="workStaffBasicInfoColumns"/>
		FROM work_staff_achives a
		<include refid="workStaffBasicInfoJoins"/>
		where
		a.user_id = #{userId}
		AND a.company_id = #{company.id}
		AND a.`status` IN ('试用','正式','劳务')
		AND a.del_flag = '0'
	</select>
	<select id="getAllListInfo" resultType="WorkStaffBasicInfo" >
		select
		<include refid="workStaffBasicInfoColumns"/>
		FROM work_staff_achives a
		<include refid="workStaffBasicInfoJoins"/>
		where
		a.`status` IN ('试用','正式','劳务')
		AND a.del_flag = '0'
	</select>

	<select id="getByUserOffice" resultType="WorkStaffBasicInfo" >
		select
		<include refid="workStaffBasicInfoColumns"/>
		FROM work_staff_achives a
		<include refid="workStaffBasicInfoJoins"/>
		where
		a.user_id = #{userId}
		AND a.office_id = #{office.id}
		AND a.`status` IN ('试用','正式','劳务')
		AND a.del_flag = '0'
	</select>
	<select id="getByOffice" resultType="WorkStaffBasicInfo" >
		select
		<include refid="workStaffBasicInfoColumns"/>
		FROM work_staff_achives a
		<include refid="workStaffBasicInfoJoins"/>
		where
		AND a.office_id = #{office.id}
		AND a.`status` IN ('试用','正式','劳务')
		AND a.del_flag = '0'
	</select>

	<select id="getByNoName" resultType="WorkStaffBasicInfo" >
		select
		<include refid="workStaffBasicInfoColumns"/>
		FROM work_staff_achives a
		<include refid="workStaffBasicInfoJoins"/>
		where
		a.no = #{no}
		AND a.name = #{name}
		AND a.company_id = #{company.id}
		AND a.`status` IN ('试用','正式','劳务')
		AND a.del_flag = '0'
	</select>

	<select id="findAllList" resultType="WorkStaffBasicInfo" >
		SELECT 
			<include refid="workStaffBasicInfoColumns"/>
		FROM work_staff_achives a
		<include refid="workStaffBasicInfoJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
		</where>		
		<choose>
			<when test="page !=null and page.orderBy != null and page.orderBy != ''">
				ORDER BY ${page.orderBy}
			</when>
			<otherwise>
				ORDER BY a.update_date DESC
			</otherwise>
		</choose>
	</select>

	<select id="findInfoList" resultType="WorkStaffBasicInfo" >
		SELECT
			<include refid="workStaffBasicInfoColumns"/>
		FROM work_staff_achives a
		<include refid="workStaffBasicInfoJoins"/>
		<where>
			a.del_flag = '0'
			AND a.`status` IN ('试用','正式','劳务')
		</where>
	</select>

	<insert id="insert">
		INSERT INTO work_staff_achives(
			id,
			create_by,
			create_date,
			update_by,
			update_date,
			remarks,
			del_flag,
			office_id,
			company_id,
			no,
			name,
			dimission_date,
			workEnd_date,
			gender,
			nation,
			id_card,
			age,
			birthday,
			calendar,
			email,
			mobile,
			phone,
			marriage,
			politics,
			ex_soldier,
			address,
			native_place,
			household,
			duty,
			job_grade,
			status,
			entry_date,
			work_date,
			bank_name,
			bank_card,
			industry_date,
			ts,
			picture,
			user_id,
			branch_office,
			percent,
		    try_end_time
		) VALUES (
			#{id},
			#{createBy.id},
			#{createDate},
			#{updateBy.id},
			#{updateDate},
			#{remarks},
			#{delFlag},
			#{office.id},
			#{company.id},
			#{no},
			#{name},
			#{dimissionDate},
			#{workEndDate},
			#{gender},
			#{nation},
			#{idCard},
			#{age},
			#{birthday},
			#{calendar},
			#{email},
			#{mobile},
			#{phone},
			#{marriage},
			#{politics},
			#{exSoldier},
			#{address},
			#{nativePlace.id},
			#{household},
			#{duty},
			#{jobGrade.id},
			#{status},
			#{entryDate},
			#{workDate},
			#{bankName},
			#{bankCard},
			#{industryDate},
			#{ts},
			#{picture},
			#{userId},
			#{branchOffice.id},
			#{percent},
            #{tryEndTime}
		)
	</insert>
	
	<update id="update">
		UPDATE work_staff_achives SET
			update_by = #{updateBy.id},
			update_date = #{updateDate},
			remarks = #{remarks},
			office_id = #{office.id},
			company_id = #{company.id},
			no = #{no},
			name = #{name},
			dimission_date= #{dimissionDate},
			workEnd_date = #{workEndDate},
			gender = #{gender},
			nation = #{nation},
			id_card = #{idCard},
			age = #{age},
			birthday = #{birthday},
			calendar = #{calendar},
			email = #{email},
			mobile = #{mobile},
			phone = #{phone},
			marriage = #{marriage},
			politics = #{politics},
			ex_soldier = #{exSoldier},
			address = #{address},
			native_place = #{nativePlace.id},
			household = #{household},
			duty = #{duty},
			job_grade = #{jobGrade.id},
			status = #{status},
			entry_date = #{entryDate},
			work_date = #{workDate},
			bank_name = #{bankName},
			bank_card = #{bankCard},
			industry_date = #{industryDate},
			ts = #{ts},
			picture = #{picture},
			user_id = #{userId},
			branch_office = #{branchOffice.id},
			percent = #{percent},
            try_end_time = #{tryEndTime}
		WHERE id = #{id}
	</update>
	
	
	<!--物理删除-->
	<update id="delete">
		DELETE FROM work_staff_achives
		WHERE id = #{id}
	</update>
	
	<!--逻辑删除-->
	<update id="deleteByLogic">
		UPDATE work_staff_achives SET
			del_flag = #{DEL_FLAG_DELETE}
		WHERE id = #{id}
	</update>
	
	<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
	<select id="findUniqueByProperty" resultType="WorkStaffBasicInfo" statementType="STATEMENT">
		select * FROM work_staff_achives  where ${propertyName} = '${value}'
	</select>
    <!--根据userId获取入职信息-->
	<select id="getWorkStaffBasicInfo" resultType="WorkStaffBasicInfo" parameterType="java.lang.String">
		select a.* ,
		o.top_company as "office.name",
		o.id as "office.id",
		jg.name AS "jobGrade.name",
		jg.id AS "jobGrade.id",
		jg.pay AS "salary",
		DATE_FORMAT(a.entry_date, '%Y-%m-%d') as entry_date,
		(select DATE_FORMAT(MAX(r.try_end_time), '%Y-%m-%d') from work_relationship r where r.staff_info_id=#{id}) tryEndTime
		 FROM work_staff_achives  a
		LEFT JOIN sys_office o on o.id=a.office_id
		LEFT JOIN work_job_grade jg ON jg.id = a.job_grade
		where a.id=#{id}
	</select>

    <select id="queryMaxNoWithCompany" resultType="String">
        SELECT max(SUBSTR(no,2)+0) FROM work_staff_achives where branch_office=#{branchOffice.id} and del_flag='0'
    </select>

	<select id="findUserList" resultType="WorkStaffBasicInfo" >
		SELECT
		<include refid="workStaffBasicInfoColumns"/>
		FROM work_staff_achives a
		<include refid="workStaffBasicInfoJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			<if test="name != null and name != ''">
				AND a.name LIKE
				<if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
				<if test="dbName == 'mssql'">'%'+#{name}+'%'</if>
				<if test="dbName == 'mysql'">concat('%',#{name},'%')</if>
			</if>
			<if test="office != null and office.id != null and office.id !=''">
				AND a.office_id= #{office.id}
			</if>
			<if test="no != null and no != ''">
				AND a.no = #{no}
			</if>
			<if test="userId != null and userId != ''">
				AND a.user_id = #{userId}
			</if>
			<if test="gender != null and gender != ''">
				AND a.gender = #{gender}
			</if>
			<if test="jobGrade != null and jobGrade.id != null and jobGrade.id !=''">
				AND a.job_grade = #{jobGrade.id}
			</if>
			<if test="status != null and status != ''">
				AND a.status = #{status}
			</if>
			<if test="branchOffice != null and branchOffice.id != null and branchOffice.id != ''">
				AND a.branch_office = #{branchOffice.id}
			</if>
			<if test="sqlStr != null and sqlStr != ''">
				${sqlStr}
			</if>

		</where>

	</select>

	<select id="findUserApplyList" resultType="WorkStaffBasicInfo" >
		SELECT
		<include refid="workStaffBasicInfoColumns"/>
		FROM work_staff_achives a
		<include refid="workStaffBasicInfoJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			<if test="name != null and name != ''">
				AND a.name LIKE
				<if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
				<if test="dbName == 'mssql'">'%'+#{name}+'%'</if>
				<if test="dbName == 'mysql'">concat('%',#{name},'%')</if>
			</if>
			<if test="office != null and office.id != null and office.id !=''">
				AND a.office_id= #{office.id}
			</if>
			<if test="no != null and no != ''">
				AND a.no = #{no}
			</if>
			<if test="userId != null and userId != ''">
				AND a.user_id = #{userId}
			</if>
			<if test="gender != null and gender != ''">
				AND a.gender = #{gender}
			</if>
			<if test="jobGrade != null and jobGrade.id != null and jobGrade.id !=''">
				AND a.job_grade = #{jobGrade.id}
			</if>
			<if test="status != null and status != ''">
				AND a.status = #{status}
			</if>
			<if test="branchOffice != null and branchOffice.id != null and branchOffice.id != ''">
				AND a.branch_office = #{branchOffice.id}
			</if>
			and a.id not in (select r.basic_info_id from work_regular_apply r where r.state !='5' and r.del_flag !='1')
		</where>

	</select>
	<select id="findUserShipList" resultType="WorkStaffBasicInfo" >
		SELECT
		<include refid="workStaffBasicInfoColumns"/>
		FROM work_staff_achives a
		<include refid="workStaffBasicInfoJoins"/>
		<where>
			a.del_flag = #{DEL_FLAG_NORMAL}
			<if test="name != null and name != ''">
				AND a.name LIKE
				<if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
				<if test="dbName == 'mssql'">'%'+#{name}+'%'</if>
				<if test="dbName == 'mysql'">concat('%',#{name},'%')</if>
			</if>
			<if test="office != null and office.id != null and office.id !=''">
				AND a.office_id= #{office.id}
			</if>
			<if test="no != null and no != ''">
				AND a.no = #{no}
			</if>
			<if test="userId != null and userId != ''">
				AND a.user_id = #{userId}
			</if>
			<if test="gender != null and gender != ''">
				AND a.gender = #{gender}
			</if>
			<if test="jobGrade != null and jobGrade.id != null and jobGrade.id !=''">
				AND a.job_grade = #{jobGrade.id}
			</if>
			<if test="status != null and status != ''">
				AND a.status = #{status}
			</if>
			<if test="branchOffice != null and branchOffice.id != null and branchOffice.id != ''">
				AND a.branch_office = #{branchOffice.id}
			</if>
			and a.id not in (select r.staff_info_id  from work_relationship r where r.status !='5' and r.del_flag !='1')
			AND a.status in ('正式','试用','劳务')
		</where>

	</select>
    <select id="findListByIdCard" resultType="WorkStaffBasicInfo">
        SELECT
        a.*
        FROM work_staff_achives a
        <where>
            a.del_flag = #{DEL_FLAG_NORMAL}
            <if test="company != null and company.id != null and company.id != ''">
                AND a.company_id = #{company.id}
            </if>
            <if test="idCard != null and idCard != ''">
                AND a.id_card = #{idCard}
            </if>
        </where>
        ORDER BY a.entry_date DESC
    </select>

    <update id="updatePercent">
        UPDATE work_staff_achives SET percent=#{percent} WHERE id=#{id}
    </update>

	<select id="findTaskUserList" resultType="WorkStaffBasicInfo" >
	SELECT * FROM
	     work_staff_achives a
    WHERE
        a.del_flag=0
    and a.`status` = '试用'
    and date_add(DATE_FORMAT(now(), '%Y-%m-%d'), interval #{day} day)=DATE_FORMAT(a.try_end_time, '%Y-%m-%d')
    AND a.id NOT IN (SELECT r.basic_info_id FROM work_regular_apply r WHERE r.del_flag = '0')
    and a.branch_office=#{branchOffice}
	</select>

	<select id="findUserInfoExcel" resultType="WorkStaffBasicInfo" >
		SELECT
		<include refid="workStaffBasicInfoColumns"/>
		FROM work_staff_achives a
		<include refid="workStaffBasicInfoJoins"/>
		WHERE a.name=#{name}
		and a.no=#{no}
	</select>
	<select id="findTemplateUser" resultType="WorkStaffBasicInfo" >
		select
		u.id as "userId",
		u.name as "name",
		a.no,
		a.gender,
		o.name as "office.name",
		o.top_company as "office.topCompany",
		jg.name as "jobGrade.name"
		from sys_user u
		left join  work_staff_achives a on u.id=a.user_id
		left join  sys_office o on o.id=u.office_id
		LEFT JOIN work_job_grade jg ON jg.id = a.job_grade
		<where>
			u.del_flag = #{DEL_FLAG_NORMAL}
			<if test="name != null and name != ''">
				AND u.name LIKE
				<if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
				<if test="dbName == 'mssql'">'%'+#{name}+'%'</if>
				<if test="dbName == 'mysql'">concat('%',#{name},'%')</if>
			</if>
			<if test="office != null and office.id != null and office.id !=''">
				AND u.office_id= #{office.id}
			</if>
			<if test="no != null and no != ''">
				AND a.no = #{no}
			</if>
			<if test="gender != null and gender != ''">
				AND a.gender = #{gender}
			</if>
			<if test="jobGrade != null and jobGrade.id != null and jobGrade.id !=''">
				AND a.job_grade = #{jobGrade.id}
			</if>
			<if test="status != null and status != ''">
				AND a.status = #{status}
			</if>
			<choose>
				<when test="branchOffice != null and branchOffice.id != null and branchOffice.id != ''">
					and  u.office_id in (select off.id from sys_office off where off.branch_office=#{branchOffice.id})
				</when>
				<otherwise>
					and  u.office_id in
					(select off.id from sys_office off where off.parent_ids like concat('%',#{company.id},'%') and off.type=2 and (off.branch_office is null or off.branch_office=''))
				</otherwise>
			</choose>
		</where>
	</select>

	<select id="sysWarningUser" resultType="WorkStaffBasicInfo" >
		select
		u.id as "userId",
		u.name as "name",
		a.no,
		a.gender,
		o.name as "office.name",
		o.top_company as "office.topCompany",
		jg.name as "jobGrade.name"
		from sys_user u
		left join  work_staff_achives a on u.id=a.user_id
		left join  sys_office o on o.id=u.office_id
		LEFT JOIN work_job_grade jg ON jg.id = a.job_grade
		<where>
			u.del_flag = #{DEL_FLAG_NORMAL}
			<if test="name != null and name != ''">
				AND u.name LIKE
				<if test="dbName == 'oracle'">'%'||#{name}||'%'</if>
				<if test="dbName == 'mssql'">'%'+#{name}+'%'</if>
				<if test="dbName == 'mysql'">concat('%',#{name},'%')</if>
			</if>
			<if test="office != null and office.id != null and office.id !=''">
				AND u.office_id= #{office.id}
			</if>
			<if test="no != null and no != ''">
				AND a.no = #{no}
			</if>
			<if test="gender != null and gender != ''">
				AND a.gender = #{gender}
			</if>
			<if test="jobGrade != null and jobGrade.id != null and jobGrade.id !=''">
				AND a.job_grade = #{jobGrade.id}
			</if>
			<if test="status != null and status != ''">
				AND a.status = #{status}
			</if>
		  and u.company_id=#{company.id}
		</where>
	</select>
    <select id="countByNo" resultType="int">
        SELECT count(*) from work_staff_achives a WHERE a.no = #{no} and a.company_id = #{company.id} and del_flag = '0'
    </select>



	<select id="findTaskBranchList" resultType="WorkStaffBasicInfo" >
	SELECT
   <include refid="workStaffBasicInfoColumns"/>
		FROM
	     work_staff_achives a
		<include refid="workStaffBasicInfoJoins"/>
    WHERE
        a.del_flag=0
    and a.status = #{status}
	and a.branch_office is not null
    AND a.id NOT IN (SELECT r.basic_info_id FROM work_regular_apply r WHERE  r.del_flag = '0')
    group by a.branch_office
	</select>
<!--当前登录人获取档案-->
	<select id="getBasicInfo" resultType="WorkStaffBasicInfo" >
		SELECT
		<include refid="workStaffBasicInfoColumns"/>
		FROM work_staff_achives a
		<include refid="workStaffBasicInfoJoins"/>
		WHERE a.user_id = #{userId} and a.company_id=#{company.id} and a.status not in ('离职','退休')
	</select>
	<select id="getJob" resultType="WorkStaffBasicInfo" >
		SELECT
		<include refid="workStaffBasicInfoColumns"/>
		FROM work_staff_achives a
		<include refid="workStaffBasicInfoJoins"/>
		WHERE a.user_id = #{userId} limit 1
	</select>

	<update id="updateStatus">
		update work_staff_achives set
		status = #{status}
		where user_id = #{id}
	</update>

<!--	我的信息-修改用户的四个属性，同步到user,achieves,basicInfo-->
	<update id="updateWorkStaffAchieves" parameterType="WorkStaffBasicInfo">
		update work_staff_achives
		<set>
			<if test="name != null and name != ''">
				name = #{name},
			</if>
			<if test="email != null and email != ''">
				email = #{email},
			</if>
			<if test="phone != null and phone != ''">
				phone = #{phone},
			</if>
			<if test="remarks != null and remarks != ''">
				remarks = #{remarks}
			</if>
		</set>
		where user_id = #{userId}
	</update>
</mapper>