gs_sub_evaluate/src/main/resources/mappers/evaluate/TeamGroupMapper.xml

265 lines
10 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.bonus.gs.sub.evaluate.evaluate.dao.TeamGroupDao">
<insert id="addTeamType">
insert into team_group_type(team_group_id,team_type) values(#{id},#{teamType})
</insert>
<insert id="addTeamGroupPerson">
insert into team_person(team_id,name,id_card,phone,sex,work_type,face_url,is_team_leader)
values
(#{id},#{name},#{idCard},#{phone},#{sex},#{workTypeId},#{faceUrl},#{isTeamLeader})
</insert>
<insert id="batchInsert">
INSERT INTO team_person (team_id, name, id_card, phone, sex, work_type, is_team_leader)
VALUES
<foreach collection="list" item="item" separator=",">
(#{item.teamId}, #{item.name}, #{item.idCard}, #{item.phone},
#{item.sex}, #{item.workType}, #{item.isTeamLeader})
</foreach>
</insert>
<update id="updaTeteamType">
update team_group_type set team_type = #{teamType} where team_group_id = #{id}
</update>
<update id="updaTeteamGroup">
UPDATE pm_org_info
SET name = #{teamGroupName}
<if test="parentId != null and parentId != ''">
, parent_id = #{parentId}
</if>
<if test="status != null">
, status = #{status}
</if>
WHERE id = #{id}
</update>
<update id="updateTeamPerson">
update team_person set name = #{name},id_card = #{idCard},phone = #{phone},sex = #{sex},work_type = #{workType},face_url = #{faceUrl}
where id = #{id}
</update>
<update id="auditRegister">
update pm_org_info set audit_status = #{auditStatus} where id = #{id}
</update>
<delete id="delTeamGroup">
delete from pm_org_info where id = #{id}
</delete>
<delete id="delTeamGroupType">
delete from team_group_type where team_group_id = #{id}
</delete>
<delete id="delTeamPerson">
delete from team_person where id = #{id}
</delete>
<delete id="delTeamGroupTypePerson">
delete from team_person where team_id = #{id}
</delete>
<select id="getTeamGroupList" resultType="com.bonus.gs.sub.evaluate.evaluate.beans.TeamGroupBean">
SELECT
poi2.NAME subContractor,
poi3.NAME project,
poi3.user_id as userId,
poi.NAME teamGroupName,
poi.id as id,
poi.parent_id as parentId,
poi.p_parent_id as pParentId,
poi.status as status,
td.id as teamTypeId,
td.val teamType,
count( tp.team_id ) teamPersonNum
FROM
pm_org_info poi
LEFT JOIN pm_org_info poi2 ON poi.parent_id = poi2.id
LEFT JOIN pm_org_info poi3 ON poi2.parent_id = poi3.id
left join team_group_type tgt on poi.id = tgt.team_group_id
left join t_dict td on tgt.team_type = td.id
left join team_person tp on poi.id = tp.team_id
WHERE
poi.`level` = 5
<if test="userId != null ">
and poi3.user_id = #{userId}
</if>
<if test="keyWord != null and keyWord != ''">
AND (
poi2.NAME like concat('%',#{keyWord},'%') or
poi3.NAME like concat('%',#{keyWord},'%') or
poi.NAME like concat('%',#{keyWord},'%')
)
</if>
<if test="status != null ">
and poi.status = #{status}
</if>
group by poi.id
order by poi.id desc
</select>
<select id="selectTeteamType" resultType="java.lang.Integer">
select count(1) from team_group_type where team_group_id = #{id}
</select>
<select id="getTeamGroupPerson" resultType="com.bonus.gs.sub.evaluate.evaluate.beans.TeamGroupBean">
SELECT tp.id,
tp.name,
tp.id_card as idCard,
tp.phone,
case when tp.sex = 1 then '男' else '女' end as sex,
tp.work_type workTypeId,
td.val as workType,
tp.face_url as faceUrl,
case when tp.is_team_leader = 0 then '是' else '否' end as isTeamLeader
FROM
team_person tp
left join t_dict td on tp.work_type = td.id
WHERE
tp.team_id = #{id}
<if test="name != null and name != ''">
and tp.name like concat('%',#{name},'%')
</if>
<if test="sex != null and sex != ''">
and tp.sex = #{sex}
</if>
</select>
<select id="getUserNumByIdCard" resultType="java.lang.Integer">
select count(1) from team_person where id_card = #{idCard}
</select>
<select id="getUserNumByPhone" resultType="java.lang.Integer">
select count(1) from team_person where phone = #{phone}
</select>
<select id="isTeamLeader" resultType="java.lang.Integer">
select is_team_leader from team_person where id = #{id}
</select>
<select id="checkExistIdCards" resultType="java.lang.String">
SELECT id_card FROM team_person WHERE id_card IN
<foreach collection="idCards" item="idCard" open="(" separator="," close=")">
#{idCard}
</foreach>
</select>
<select id="checkExistPhones" resultType="java.lang.String">
SELECT phone FROM team_person WHERE phone IN
<foreach collection="phones" item="phone" open="(" separator="," close=")">
#{phone}
</foreach>
</select>
<select id="getIdByName" resultType="java.lang.Integer">
SELECT id FROM pm_org_info WHERE name = #{name}
</select>
<select id="getWorkTypeId" resultType="java.lang.String">
SELECT id FROM t_dict WHERE val = #{workType} and type = 'workType'
</select>
<select id="getTeamGroupPersons" resultType="com.bonus.gs.sub.evaluate.evaluate.beans.TeamGroupBean">
SELECT tp.id,
tp.name,
poi.name as teamGroupName,
poi2.name as subContractor,
poi3.name as project,
tp.id_card as idCard,
tp.phone,
case when tp.sex = 1 then '男' else '女' end as sex,
tp.work_type workTypeId,
td.val as workType,
tp.face_url as faceUrl,
case when tp.is_team_leader = 0 then '是' else '否' end as isTeamLeader
FROM
team_person tp
left join t_dict td on tp.work_type = td.id
left join pm_org_info poi on tp.team_id = poi.id
left join pm_org_info poi2 on poi2.id = poi.parent_id
left join pm_org_info poi3 on poi3.id = poi2.parent_id
WHERE 1=1
<if test="keyWord != null and keyWord != ''">
AND (
poi2.NAME like concat('%',#{keyWord},'%') or
poi3.NAME like concat('%',#{keyWord},'%') or
poi.NAME like concat('%',#{keyWord},'%')
)
</if>
<if test="name != null and name != ''">
and tp.name like concat('%',#{name},'%')
</if>
<if test="sex != null and sex != ''">
and tp.sex = #{sex}
</if>
<if test="projectId != null and projectId != ''">
and poi3.id = #{projectId}
</if>
<if test="workType != null and workType != ''">
and tp.work_type = #{workType}
</if>
</select>
<select id="selectTeamLeaser" resultType="com.bonus.gs.sub.evaluate.evaluate.beans.TeamGroupBean">
SELECT name,
phone
FROM team_person WHERE team_id = #{id} and is_team_leader = 0
</select>
<select id="getSubContractorName" resultType="java.lang.String">
SELECT pa.enterpriseName FROM pm_org_info poi
left join project_assignment pa on poi.p_parent_id = pa.id
WHERE poi.p_parent_id = #{pParentId} limit 1
</select>
<select id="getRegisterList" resultType="com.bonus.gs.sub.evaluate.evaluate.beans.TeamGroupBean">
SELECT
poi.id,
poi.name teamGroupName,
poi.apply_man applyMan,
poi.create_time createTime,
poi.info_file_url infoFileUrl,
poi.audit_status auditStatus,
su.username applyMan,
CASE
WHEN poi.audit_status = 0 THEN '草稿'
WHEN poi.audit_status = 1 THEN '待事业部审核'
WHEN poi.audit_status = 2 THEN '待专责审核'
WHEN poi.audit_status = 3 THEN '待汇总审核'
WHEN poi.audit_status = 4 THEN '已通过'
WHEN poi.audit_status = 5 THEN '已驳回'
END AS auditStatusName
FROM
pm_org_info poi
left join sys_user su ON su.id = poi.apply_man
WHERE
poi.audit_status IS NOT NULL
AND poi.LEVEL = 5
<if test="keyWord != null and keyWord != ''">
and poi.name like concat('%',#{keyWord},'%')
</if>
<if test="status == 0">
and poi.audit_status = 0
</if>
<if test="status != null">
and poi.audit_status = #{status}
</if>
<if test="startDate!=null and startDate!='' and endDate!=null and endDate!=''">
AND DATE_FORMAT(poi.create_time, '%Y-%m-%d') BETWEEN #{startDate} AND #{endDate}
</if>
</select>
<select id="getTeamLeader" resultType="com.bonus.gs.sub.evaluate.evaluate.beans.TeamGroupBean">
SELECT
tp.name AS name,
tp.phone AS phone,
tp.id_card AS idCard,
team_stats.personNum
FROM
pm_org_info poi
INNER JOIN team_person tp ON poi.id = tp.team_id
INNER JOIN (
SELECT
team_id,
COUNT(*) AS personNum
FROM
team_person
GROUP BY
team_id
) AS team_stats ON poi.id = team_stats.team_id
WHERE
tp.is_team_leader = 0
and poi.id = #{id}
</select>
<select id="getDepartmentName" resultType="java.lang.String">
SELECT DISTINCT
poi2.name
FROM
pm_org_info poi
left join pm_org_info poi2 on poi.parent_id = poi2.id
WHERE
poi.user_id = #{applyMan}
</select>
</mapper>