SafetyAlertSystem/bonus-modules/bonus-base/src/main/resources/mapper/base/TbPeopleMapper.xml

133 lines
5.3 KiB
XML
Raw Normal View History

2024-09-13 18:06:19 +08:00
<?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.bonus.base.mapper.TbPeopleMapper">
<select id="selectByName" resultType="com.bonus.base.domain.TbPeople">
select
tp.id as id, tp.team_id as teamId, tp.rel_name as relName, tp.rel_phone as relPhone, tp.id_card as idCard,
tp.post_code as postCode, sda
</select>
<select id="queryByPage" resultType="com.bonus.base.domain.TbPeople">
select
tp.id as id, tp.team_id as teamId, tp.rel_name as relName, tp.rel_phone as relPhone, tp.id_card as idCard,
tp.post_code as postCode, tp.sex as sex, td.dev_name as devName, CASE WHEN tp.team_id IS NULL THEN 0 ELSE 1 END as delFlag
from tb_people tp
left join tb_device td on tp.dev_id = td.id and td.del_flag = '0'
where tp.del_flag = '0'
<if test="id != null">
and tp.team_id = #{id}
UNION
select
tp.id as id, tp.team_id as teamId, tp.rel_name as relName, tp.rel_phone as relPhone, tp.id_card as idCard,
tp.post_code as postCode, tp.sex as sex, td.dev_name as devName, CASE WHEN tp.team_id IS NULL THEN 0 ELSE 1 END as delFlag
from tb_people tp
left join tb_team tt on tt.rel_id = tp.id and tt.del_flag = '0'
left join tb_device td on tp.dev_id = td.id and td.del_flag = '0'
WHERE tt.id = #{id}
ORDER BY delFlag
</if>
/**
* 班组长条件筛选,一个班组长只可带领一个组,班组员条件筛选,一个组员只可在一个班组
*/
<if test="isAll != null and isAll == 0">
and (tp.team_id is null and tp.id not in (select rel_id from tb_team where del_flag = '0' and js_time is null))
</if>
</select>
<select id="queryById" resultType="com.bonus.base.domain.TbPeople">
select tp.id as id,
tp.team_id as teamId,
tp.rel_name as relName,
tp.rel_phone as relPhone,
tp.id_card as idCard,
tp.post_code as postCode,
tp.sex as sex
from tb_people tp
where tp.del_flag = '0' and tp.id = #{id}
</select>
<select id="queryByName" resultType="com.bonus.base.domain.TbPeople">
select tp.id as id,
tp.team_id as teamId,
tp.rel_name as relName,
tp.rel_phone as relPhone,
tp.id_card as idCard,
tp.post_code as postCode,
sda.dict_label as postName,
tp.sex as sex
from tb_people tp
left join sys_dict_data sda on tp.post_code = sda.dict_code
where tp.del_flag = '0'
<if test="idCard != null and idCard != ''">
and tp.id_card = #{idCard}
</if>
</select>
<insert id="insert">
INSERT INTO tb_people
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="teamId != null and teamId != ''">team_id,</if>
<if test="relName != null and relName != ''">rel_name,</if>
<if test="relPhone != null and relPhone != ''">rel_phone,</if>
<if test="idCard != null and idCard != ''">id_card,</if>
<if test="postCode != null">post_code,</if>
<if test="sex != null">sex,</if>
<if test="createUser != null">create_user,</if>
create_time,
del_flag
</trim>
<trim prefix="VALUES (" suffix=")" suffixOverrides=",">
<if test="teamId != null and teamId != ''">#{teamId},</if>
<if test="relName != null and relName != ''">#{relName},</if>
<if test="relPhone != null and relPhone != ''">#{relPhone},</if>
<if test="idCard != null and idCard != ''">#{idCard},</if>
<if test="postCode != null">#{postCode},</if>
<if test="sex != null">#{sex},</if>
<if test="createUser != null">#{createUser},</if>
NOW(),
0
</trim>
</insert>
<!--通过主键修改数据-->
<update id="update">
update tb_people
<set>
<if test="teamId != null">
team_id = #{teamId},
</if>
<if test="relName != null and relName != ''">
rel_name = #{relName},
</if>
<if test="relPhone != null and relPhone != ''">
rel_phone = #{relPhone},
</if>
<if test="idCard != null and idCard != ''">
id_card = #{idCard},
</if>
<if test="postCode != null and postCode != ''">
post_code = #{postCode},
</if>
<if test="sex != null">
sex = #{sex},
</if>
update_time = NOW(),
<if test="updateUser != null">
update_user = #{updateUser},
</if>
<if test="delFlag != null">
del_flag = #{delFlag},
</if>
</set>
where id = #{id}
</update>
<!--通过主键删除-->
<delete id="deleteById">
update tb_people set del_flag = '1' where id = #{id}
</delete>
</mapper>