1.插入后select是干啥呢?
/**
* Insert server crash alert
* <p>This method will ensure that there is at most one unsent alert which has the same content in the database.
*/
void insertAlertWhenServerCrash(@Param("alert") Alert alert);
<insert id="insertAlertWhenServerCrash">
insert into t_ds_alert(title, content, alert_status, log, alertgroup_id, create_time, update_time)
SELECT #{alert.title}, #{alert.content}, #{alert.alertStatus.code}, #{alert.log}, #{alert.alertGroupId},
#{alert.createTime}, #{alert.updateTime}
from t_ds_alert
where content = #{alert.content} and alert_status = #{alert.alertStatus.code}
having count(*) = 0
</insert>
2.where 1=1是干啥呢?
List<AlertPluginInstance> queryAllAlertPluginInstanceList();
<select id="queryAllAlertPluginInstanceList"
resultType="org.apache.dolphinscheduler.dao.entity.AlertPluginInstance">
select *
from t_ds_alert_plugin_instance
where 1 = 1
</select>
3.foreach是干啥呢?
List<AlertPluginInstance> queryByIds(@Param("ids") List<Integer> ids);
<select id="queryByIds" resultType="org.apache.dolphinscheduler.dao.entity.AlertPluginInstance">
select *
from t_ds_alert_plugin_instance
where id in
<foreach item="item" index="index" collection="ids"
open="(" separator="," close=")">
#{item}
</foreach>
</select>
4.if这个怎么用?
IPage<AlertPluginInstance> queryByInstanceNamePage(Page page, @Param("instanceName") String instanceName);
<select id="queryByInstanceNamePage" resultType="org.apache.dolphinscheduler.dao.entity.AlertPluginInstance">
select
*
from t_ds_alert_plugin_instance
where 1 = 1
<if test="instanceName != null and instanceName != ''">
and instance_name like concat('%', #{instanceName}, '%')
</if>
</select>
5.这个select 1是啥意思?
Boolean existInstanceName(@Param("instanceName") String instanceName);
<select id="existInstanceName" resultType="java.lang.Boolean">
select 1
from t_ds_alert_plugin_instance
where instance_name = #{instanceName} limit 1
</select>
6.这个比较复杂
List<CommandCount> countCommandState(
@Param("userId") int userId,
@Param("startTime") Date startTime,
@Param("endTime") Date endTime,
@Param("projectCodeArray") Long[] projectCodeArray);
<select id="countCommandState" resultType="org.apache.dolphinscheduler.dao.entity.CommandCount">
select cmd.command_type as command_type, count(1) as count
from t_ds_command cmd, t_ds_process_definition process
where cmd.process_definition_code = process.code
<if test="projectCodeArray != null and projectCodeArray.length != 0">
and process.project_code in
<foreach collection="projectCodeArray" index="index" item="i" open="(" close=")" separator=",">
#{i}
</foreach>
</if>
<if test="startTime != null and endTime != null">
and cmd.start_time <![CDATA[ >= ]]> #{startTime} and cmd.update_time <![CDATA[ <= ]]> #{endTime}
</if>
group by cmd.command_type
</select>