ganzi-api/inventory-dao/src/main/resources/mapper/NoticeMapper.xml

360 lines
13 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.rzyc.mapper.NoticeMapper">
<resultMap id="BaseResultMap" type="com.rzyc.model.Notice">
<id column="id" jdbcType="VARCHAR" property="id" />
<result column="title" jdbcType="VARCHAR" property="title" />
<result column="checkUserId" jdbcType="VARCHAR" property="checkuserid" />
<result column="sendId" jdbcType="VARCHAR" property="sendId" />
<result column="sendName" jdbcType="VARCHAR" property="sendId" />
<result column="companyId" jdbcType="VARCHAR" property="companyid" />
<result column="targetName" jdbcType="VARCHAR" property="targetName" />
<result column="content" jdbcType="VARCHAR" property="content" />
<result column="read_state" jdbcType="VARCHAR" property="readState" />
<result column="type" jdbcType="INTEGER" property="type" />
<result column="download_num" jdbcType="INTEGER" property="downloadNum" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
</resultMap>
<sql id="Example_Where_Clause">
<where>
<foreach collection="oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Update_By_Example_Where_Clause">
<where>
<foreach collection="example.oredCriteria" item="criteria" separator="or">
<if test="criteria.valid">
<trim prefix="(" prefixOverrides="and" suffix=")">
<foreach collection="criteria.criteria" item="criterion">
<choose>
<when test="criterion.noValue">
and ${criterion.condition}
</when>
<when test="criterion.singleValue">
and ${criterion.condition} #{criterion.value}
</when>
<when test="criterion.betweenValue">
and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
</when>
<when test="criterion.listValue">
and ${criterion.condition}
<foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
#{listItem}
</foreach>
</when>
</choose>
</foreach>
</trim>
</if>
</foreach>
</where>
</sql>
<sql id="Base_Column_List">
id, title, checkUserId, companyId, content, read_state, type, create_time
</sql>
<select id="selectByExample" parameterType="com.rzyc.model.NoticeExample" resultMap="BaseResultMap">
select
<if test="distinct">
distinct
</if>
<include refid="Base_Column_List" />
from notice
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
<if test="limit != null">
<if test="offset != null">
limit ${offset}, ${limit}
</if>
<if test="offset == null">
limit ${limit}
</if>
</if>
</select>
<select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from notice
where id = #{id,jdbcType=VARCHAR}
</select>
<delete id="deleteByPrimaryKey" parameterType="java.lang.String">
delete from notice
where id = #{id,jdbcType=VARCHAR}
</delete>
<delete id="deleteByExample" parameterType="com.rzyc.model.NoticeExample">
delete from notice
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</delete>
<insert id="insert" parameterType="com.rzyc.model.Notice">
insert into notice (id, title, checkUserId,sendId,
companyId, content, read_state,
type, create_time)
values (#{id,jdbcType=VARCHAR}, #{title,jdbcType=VARCHAR},
#{checkuserid,jdbcType=VARCHAR},
#{sendId,jdbcType=VARCHAR},
#{companyid,jdbcType=VARCHAR}, #{content,jdbcType=VARCHAR}, #{readState,jdbcType=VARCHAR},
#{type,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP})
</insert>
<insert id="insertSelective" parameterType="com.rzyc.model.Notice">
insert into notice
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">
id,
</if>
<if test="title != null">
title,
</if>
<if test="checkuserid != null">
checkUserId,
</if>
<if test="companyid != null">
companyId,
</if>
<if test="content != null">
content,
</if>
<if test="readState != null">
read_state,
</if>
<if test="type != null">
type,
</if>
<if test="createTime != null">
create_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">
#{id,jdbcType=VARCHAR},
</if>
<if test="title != null">
#{title,jdbcType=VARCHAR},
</if>
<if test="checkuserid != null">
#{checkuserid,jdbcType=VARCHAR},
</if>
<if test="companyid != null">
#{companyid,jdbcType=VARCHAR},
</if>
<if test="content != null">
#{content,jdbcType=VARCHAR},
</if>
<if test="readState != null">
#{readState,jdbcType=VARCHAR},
</if>
<if test="type != null">
#{type,jdbcType=INTEGER},
</if>
<if test="createTime != null">
#{createTime,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
<select id="countByExample" parameterType="com.rzyc.model.NoticeExample" resultType="java.lang.Long">
select count(*) from notice
<if test="_parameter != null">
<include refid="Example_Where_Clause" />
</if>
</select>
<update id="updateByExampleSelective" parameterType="map">
update notice
<set>
<if test="record.id != null">
id = #{record.id,jdbcType=VARCHAR},
</if>
<if test="record.title != null">
title = #{record.title,jdbcType=VARCHAR},
</if>
<if test="record.checkuserid != null">
checkUserId = #{record.checkuserid,jdbcType=VARCHAR},
</if>
<if test="record.companyid != null">
companyId = #{record.companyid,jdbcType=VARCHAR},
</if>
<if test="record.content != null">
content = #{record.content,jdbcType=VARCHAR},
</if>
<if test="record.readState != null">
read_state = #{record.readState,jdbcType=VARCHAR},
</if>
<if test="record.type != null">
type = #{record.type,jdbcType=INTEGER},
</if>
<if test="record.createTime != null">
create_time = #{record.createTime,jdbcType=TIMESTAMP},
</if>
</set>
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByExample" parameterType="map">
update notice
set id = #{record.id,jdbcType=VARCHAR},
title = #{record.title,jdbcType=VARCHAR},
checkUserId = #{record.checkuserid,jdbcType=VARCHAR},
companyId = #{record.companyid,jdbcType=VARCHAR},
content = #{record.content,jdbcType=VARCHAR},
read_state = #{record.readState,jdbcType=VARCHAR},
type = #{record.type,jdbcType=INTEGER},
create_time = #{record.createTime,jdbcType=TIMESTAMP}
<if test="_parameter != null">
<include refid="Update_By_Example_Where_Clause" />
</if>
</update>
<update id="updateByPrimaryKeySelective" parameterType="com.rzyc.model.Notice">
update notice
<set>
<if test="title != null">
title = #{title,jdbcType=VARCHAR},
</if>
<if test="checkuserid != null">
checkUserId = #{checkuserid,jdbcType=VARCHAR},
</if>
<if test="companyid != null">
companyId = #{companyid,jdbcType=VARCHAR},
</if>
<if test="content != null">
content = #{content,jdbcType=VARCHAR},
</if>
<if test="readState != null">
read_state = #{readState,jdbcType=VARCHAR},
</if>
<if test="type != null">
type = #{type,jdbcType=INTEGER},
</if>
<if test="createTime != null">
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
</set>
where id = #{id,jdbcType=VARCHAR}
</update>
<update id="updateByPrimaryKey" parameterType="com.rzyc.model.Notice">
update notice
set title = #{title,jdbcType=VARCHAR},
checkUserId = #{checkuserid,jdbcType=VARCHAR},
companyId = #{companyid,jdbcType=VARCHAR},
content = #{content,jdbcType=VARCHAR},
read_state = #{readState,jdbcType=VARCHAR},
type = #{type,jdbcType=INTEGER},
create_time = #{createTime,jdbcType=TIMESTAMP}
where id = #{id,jdbcType=VARCHAR}
</update>
<!--通知-->
<select id="selectList" resultMap="BaseResultMap">
SELECT * FROM notice nt
WHERE 1 =1
and (nt.`checkUserId` = #{checkUserId} OR nt.`checkUserId` is null or nt.`checkUserId` = '')
<if test="null != types and types.size() > 0">
and nt.type in
<foreach collection="types" open="(" close=")" separator="," item="type">
#{type}
</foreach>
</if>
ORDER BY nt.`create_time` DESC;
</select>
<update id="updateReadState">
update notice set read_state = 1 where checkUserId = #{checkUserId}
</update>
<update id="oneButtonRead">
update notice set read_state = 1 where checkUserId = #{userId}
</update>
<!--批量插入-->
<insert id="insertList" parameterType="com.rzyc.model.Notice">
insert into notice (id, title, checkUserId,
companyId, content, read_state,
type, create_time)
values
<foreach collection="records" item="record" separator=",">
(#{record.id,jdbcType=VARCHAR}, #{record.title,jdbcType=VARCHAR},
#{record.checkuserid,jdbcType=VARCHAR},
#{record.companyid,jdbcType=VARCHAR}, #{record.content,jdbcType=VARCHAR},
#{record.readState,jdbcType=VARCHAR},
#{record.type,jdbcType=INTEGER}, #{record.createTime,jdbcType=TIMESTAMP})
</foreach>
</insert>
<!--文件下达通知-->
<select id="fileList" resultMap="BaseResultMap">
SELECT su.ChinaName sendName, bc.`IndustryClassName` targetName, nt.*
FROM `notice` nt
LEFT JOIN `baseinclass` bc ON nt.`companyId` = bc.`BaseInClassId`
LEFT JOIN sysuser su ON nt.`sendId` = su.SysUserId
WHERE nt.`type` = 7
and nt.title like #{condition}
ORDER BY nt.`create_time` DESC
</select>
<!--文件下达通知-->
<select id="receiveList" resultMap="BaseResultMap">
SELECT su.`ChinaName` sendName, nt.*,nr.`download_num`
FROM `notice` nt
LEFT JOIN SysUser su ON nt.`sendId` = su.`SysUserId`
LEFT JOIN `no_record` nr ON nr.`notice_id` = nt.`id` AND nr.`enterprise_id` = #{entId}
WHERE nt.`companyId` = #{companyId}
AND nt.`type` = 7
ORDER BY nt.`create_time` DESC
</select>
<select id="selectNotices" resultMap="BaseResultMap">
select * from notice where 1=1
<if test="null != type and '' != type">
and `type` = #{type}
</if>
<if test="null != userId and '' != userId">
and checkUserId = #{userId}
</if>
order by read_state
</select>
<resultMap id="numberMap" type="com.rzyc.model.Notice">
<result column="total" jdbcType="BIGINT" property="total" />
<result column="read" jdbcType="BIGINT" property="read" />
<result column="unread" jdbcType="BIGINT" property="unread" />
</resultMap>
<select id="selectEntNoticeNumber" resultMap="numberMap">
select sum(case when read_state = 1 then 1 else 0 end)as `read`,
sum(case when read_state = 2 then 1 else 0 end)as `unread`,
count(id)as total
from notice where checkUserId = #{userId}
</select>
</mapper>