jhprjv2/yanzhu-jh/src/main/resources/mapper/work/WorkTrainMapper.xml

187 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.yanzhu.jh.work.mapper.WorkTrainMapper">
<resultMap type="WorkTrain" id="WorkTrainResult">
<result property="id" column="id" />
<result property="projectId" column="project_id" />
<result property="projectName" column="project_name" />
<result property="mainImage" column="main_image" />
<result property="trainType" column="train_type" />
<result property="trainNature" column="train_nature" />
<result property="trainParticipants" column="train_participants" />
<result property="beginDate" column="begin_date" />
<result property="endDate" column="end_date" />
<result property="trainContent" column="train_content" />
<result property="isDel" column="is_del" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="remark" column="remark" />
<result property="vDel" column="v_del" />
<result property="trainNatureName" column="train_nature_name" />
</resultMap>
<resultMap id="WorkTrainWorkTrainDeptResult" type="WorkTrain" extends="WorkTrainResult">
<collection property="workTrainDeptList" notNullColumn="sub_train_id" javaType="java.util.List" resultMap="WorkTrainDeptResult" />
</resultMap>
<resultMap type="WorkTrainDept" id="WorkTrainDeptResult">
<result property="trainId" column="sub_train_id" />
<result property="deptId" column="sub_dept_id" />
<result property="deptName" column="sub_dept_name" />
<result property="isMain" column="sub_is_main" />
</resultMap>
<sql id="selectWorkTrainVo">
select id, project_id, project_name, main_image, train_type, train_nature, train_participants, begin_date, end_date, train_content, is_del, create_by, create_time, update_by, update_time, remark from work_train
</sql>
<select id="selectWorkTrainList" parameterType="WorkTrain" resultMap="WorkTrainResult">
select wt.id, wt.project_id, wt.project_name, wt.main_image, wt.train_type, wt.train_nature, wt.train_participants, wt.begin_date, wt.end_date, wt.train_content, wt.is_del, wt.create_by, wt.create_time, wt.update_by, wt.update_time, wt.remark, group_concat(sd.dept_id) as trainDeptIds, group_concat(sd.dept_name) as trainDeptNames,
CASE
WHEN (
wt.create_by = #{nowUserName}
OR #{nowRole} IN ('1', '2', '3', '4')
)
AND end_date > NOW() THEN
0
ELSE
1
END v_del
from work_train wt
left join work_train_dept wtd on wtd.train_id = wt.id
left join sys_dept sd on sd.dept_id = wtd.dept_id
<where>
<if test="projectId != null"> and wt.project_id = #{projectId}</if>
<if test="projectName != null and projectName != ''"> and wt.project_name like concat('%', #{projectName}, '%')</if>
<if test="trainType != null and trainType != ''"> and train_type = #{trainType}</if>
<if test="trainNature != null and trainNature != ''"> and wt.train_nature = #{trainNature}</if>
<if test="isDel != null "> and wt.is_del = #{isDel}</if>
<if test="params.beginMarksTime != null and params.beginMarksTime != '' and params.endMarksTime != null and params.endMarksTime != ''"> and ((wt.begin_date between #{params.beginMarksTime} and #{params.endMarksTime}) or (wt.end_date between #{params.beginMarksTime} and #{params.endMarksTime}) )</if>
</where>
group by wt.id
order by wt.create_time desc
</select>
<select id="selectBgscreenWorkTrainList" parameterType="WorkTrain" resultMap="WorkTrainResult">
select wt.id, wt.project_id, wt.project_name, wt.main_image, wt.train_type, wt.train_nature, sdd.dict_label as train_nature_name, wt.train_participants, wt.begin_date, wt.end_date, wt.train_content, wt.is_del, wt.create_by, wt.create_time, wt.update_by, wt.update_time, wt.remark, group_concat(sd.dept_id) as trainDeptIds, group_concat(sd.dept_name) as trainDeptNames
from work_train wt
left join work_train_dept wtd on wtd.train_id = wt.id
left join sys_dept sd on sd.dept_id = wtd.dept_id
<if test='trainType != null and trainType == "0"'> left join sys_dict_data sdd on sdd.dict_type = 'train_nature_zxpx' and wt.train_nature = sdd.dict_value</if>
<if test='trainType != null and trainType == "1"'> left join sys_dict_data sdd on sdd.dict_type = 'train_nature_yjyl' and wt.train_nature = sdd.dict_value</if>
RIGHT JOIN (
select gr.train_nature as gr_type ,max(gr.id) as maxid from work_train gr
left join sur_project sp on sp.id = gr.project_id
<where>
and gr.is_del=0
<if test="deptId != null"> and sp.deptId = #{deptId}</if>
<if test="trainType != null and trainType != ''"> and gr.train_type = #{trainType}</if>
</where>
group by gr.train_nature) as group_train on group_train.maxid = wt.id
where wt.is_del=0
group by wt.id
order by wt.create_time desc
</select>
<select id="selectWorkTrainById" parameterType="Long" resultMap="WorkTrainWorkTrainDeptResult">
select a.id, a.project_id, a.project_name, a.main_image, a.train_type, a.train_nature, a.train_participants, a.begin_date, a.end_date, a.train_content, a.is_del, a.create_by, a.create_time, a.update_by, a.update_time, a.remark,
b.train_id as sub_train_id, b.dept_id as sub_dept_id, b.is_main as sub_is_main
from work_train a
left join work_train_dept b on b.train_id = a.id
where a.id = #{id}
</select>
<insert id="insertWorkTrain" parameterType="WorkTrain" useGeneratedKeys="true" keyProperty="id">
insert into work_train
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="projectId != null">project_id,</if>
<if test="projectName != null">project_name,</if>
<if test="mainImage != null">main_image,</if>
<if test="trainType != null">train_type,</if>
<if test="trainNature != null">train_nature,</if>
<if test="trainParticipants != null">train_participants,</if>
<if test="beginDate != null">begin_date,</if>
<if test="endDate != null">end_date,</if>
<if test="trainContent != null">train_content,</if>
<if test="isDel != null">is_del,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
<if test="remark != null">remark,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="projectId != null">#{projectId},</if>
<if test="projectName != null">#{projectName},</if>
<if test="mainImage != null">#{mainImage},</if>
<if test="trainType != null">#{trainType},</if>
<if test="trainNature != null">#{trainNature},</if>
<if test="trainParticipants != null">#{trainParticipants},</if>
<if test="beginDate != null">#{beginDate},</if>
<if test="endDate != null">#{endDate},</if>
<if test="trainContent != null">#{trainContent},</if>
<if test="isDel != null">#{isDel},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="remark != null">#{remark},</if>
</trim>
</insert>
<update id="updateWorkTrain" parameterType="WorkTrain">
update work_train
<trim prefix="SET" suffixOverrides=",">
<if test="projectId != null">project_id = #{projectId},</if>
<if test="projectName != null">project_name = #{projectName},</if>
<if test="mainImage != null">main_image = #{mainImage},</if>
<if test="trainType != null">train_type = #{trainType},</if>
<if test="trainNature != null">train_nature = #{trainNature},</if>
<if test="trainParticipants != null">train_participants = #{trainParticipants},</if>
<if test="beginDate != null">begin_date = #{beginDate},</if>
<if test="endDate != null">end_date = #{endDate},</if>
<if test="trainContent != null">train_content = #{trainContent},</if>
<if test="isDel != null">is_del = #{isDel},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="remark != null">remark = #{remark},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteWorkTrainById" parameterType="Long">
delete from work_train where id = #{id}
</delete>
<delete id="deleteWorkTrainByIds" parameterType="String">
delete from work_train where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
<delete id="deleteWorkTrainDeptByTrainIds" parameterType="String">
delete from work_train_dept where train_id in
<foreach item="trainId" collection="array" open="(" separator="," close=")">
#{trainId}
</foreach>
</delete>
<delete id="deleteWorkTrainDeptByTrainId" parameterType="Long">
delete from work_train_dept where train_id = #{trainId}
</delete>
<insert id="batchWorkTrainDept">
insert into work_train_dept( train_id, dept_id, is_main) values
<foreach item="item" index="index" collection="list" separator=",">
( #{item.trainId}, #{item.deptId}, #{item.isMain})
</foreach>
</insert>
</mapper>