<?xml version="1.0" encoding="UTF-8"?>

<!--
  ~
  ~      Copyright (c) 2018-2025, lengleng All rights reserved.
  ~
  ~  Redistribution and use in source and binary forms, with or without
  ~  modification, are permitted provided that the following conditions are met:
  ~
  ~ Redistributions of source code must retain the above copyright notice,
  ~  this list of conditions and the following disclaimer.
  ~  Redistributions in binary form must reproduce the above copyright
  ~  notice, this list of conditions and the following disclaimer in the
  ~  documentation and/or other materials provided with the distribution.
  ~  Neither the name of the yifu4cloud.com developer nor the names of its
  ~  contributors may be used to endorse or promote products derived from
  ~  this software without specific prior written permission.
  ~  Author: lengleng (wangiegie@gmail.com)
  ~
  -->

<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.yifu.cloud.plus.v1.msg.mapper.MsgMapper">

	<resultMap id="msgInfoMap" type="com.yifu.cloud.plus.v1.msg.entity.MsgInfo">
		<id property="id" column="ID"/>
		<result property="createTime" column="CREATE_TIME"/>
		<result property="orderId" column="ORDER_ID"/>
		<result property="url" column="URL"/>
		<result property="orderNo" column="ORDER_NO"/>
		<result property="alertType" column="ALERT_TYPE"/>
		<result property="read" column="READ"/>
		<result property="alertUser" column="ALERT_USER"/>
	</resultMap>
	<sql id="Base_Column_List">
		a.ID,
		a.CREATE_TIME,
		a.ORDER_ID,
		a.URL,
		a.ORDER_NO,
		a.ALERT_TYPE,
		a.READ,
		a.ALERT_USER
	</sql>
	<sql id="msgInfo_where">
		<if test="msgInfo != null">
			<if test="msgInfo.id != null and msgInfo.id.trim() != ''">
				AND a.ID = #{msgInfo.id}
			</if>
			<if test="msgInfo.orderId != null and msgInfo.orderId.trim() != ''">
				AND a.ORDER_ID = #{msgInfo.orderId}
			</if>
			<if test="msgInfo.alertType != null and msgInfo.alertType.trim() != ''">
				AND a.ALERT_TYPE = #{msgInfo.alertType}
			</if>
			<if test="msgInfo.read != null and msgInfo.read.trim() != ''">
				AND a.READ = #{msgInfo.read}
			</if>
			<if test="msgInfo.alertUser != null and msgInfo.alertUser.trim() != ''">
				AND a.ALERT_USER = #{msgInfo.alertUser}
			</if>

		</if>
	</sql>
	<!--msgInfo简单分页查询-->
	<select id="getmsgInfoPage" resultMap="msgInfoMap">
		SELECT
			<include refid="Base_Column_List"/>
		FROM msg_info a
		<where>
			1=1
			<include refid="msgInfo_where"/>
		</where>
		order by a.CREATE_TIME desc
	</select>
	<select id="getMsgByOrderId" resultType="com.yifu.cloud.plus.v1.msg.entity.MsgInfo">
		SELECT
			p.fd_name alertUser,
			a.fd_3ac901c5184274  orderNo,
			a.fd_id  orderId,
			'0' as alertType
		FROM
			ekp_ea33075576149bb8a4f5 a
				LEFT JOIN sys_org_element p on a.fd_3b0aff6781fa86 = p.fd_id
		WHERE
			a.ORDER_ID = #{orderId} limit 1
	</select>
</mapper>