| <?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.dy.pipIrrGlobal.daoIr.IrIrrigateGroupMapper"> | 
|   <resultMap id="BaseResultMap" type="com.dy.pipIrrGlobal.pojoIr.IrIrrigateGroup"> | 
|     <!--@mbg.generated--> | 
|     <!--@Table ir_irrigate_group--> | 
|     <id column="id" jdbcType="BIGINT" property="id" /> | 
|     <result column="group_code" jdbcType="VARCHAR" property="groupCode" /> | 
|     <result column="default_duration" jdbcType="INTEGER" property="defaultDuration" /> | 
|     <result column="remarks" jdbcType="VARCHAR" property="remarks" /> | 
|     <result column="operator" jdbcType="BIGINT" property="operator" /> | 
|     <result column="operate_time" jdbcType="TIMESTAMP" property="operateTime" /> | 
|     <result column="deleted" jdbcType="TINYINT" property="deleted" /> | 
|   </resultMap> | 
|   <sql id="Base_Column_List"> | 
|     <!--@mbg.generated--> | 
|     id, group_code, default_duration, remarks, `operator`, operate_time, deleted | 
|   </sql> | 
|   <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap"> | 
|     <!--@mbg.generated--> | 
|     select  | 
|     <include refid="Base_Column_List" /> | 
|     from ir_irrigate_group | 
|     where id = #{id,jdbcType=BIGINT} | 
|   </select> | 
|   <delete id="deleteByPrimaryKey" parameterType="java.lang.Long"> | 
|     <!--@mbg.generated--> | 
|     delete from ir_irrigate_group | 
|     where id = #{id,jdbcType=BIGINT} | 
|   </delete> | 
|   <insert id="insert" parameterType="com.dy.pipIrrGlobal.pojoIr.IrIrrigateGroup"> | 
|     <!--@mbg.generated--> | 
|     insert into ir_irrigate_group (id, group_code, default_duration,  | 
|       remarks, `operator`, operate_time,  | 
|       deleted) | 
|     values (#{id,jdbcType=BIGINT}, #{groupCode,jdbcType=VARCHAR}, #{defaultDuration,jdbcType=INTEGER},  | 
|       #{remarks,jdbcType=VARCHAR}, #{operator,jdbcType=BIGINT}, #{operateTime,jdbcType=TIMESTAMP},  | 
|       #{deleted,jdbcType=TINYINT}) | 
|   </insert> | 
|   <insert id="insertSelective" parameterType="com.dy.pipIrrGlobal.pojoIr.IrIrrigateGroup"> | 
|     <!--@mbg.generated--> | 
|     insert into ir_irrigate_group | 
|     <trim prefix="(" suffix=")" suffixOverrides=","> | 
|       <if test="id != null"> | 
|         id, | 
|       </if> | 
|       <if test="groupCode != null"> | 
|         group_code, | 
|       </if> | 
|       <if test="defaultDuration != null"> | 
|         default_duration, | 
|       </if> | 
|       <if test="remarks != null"> | 
|         remarks, | 
|       </if> | 
|       <if test="operator != null"> | 
|         `operator`, | 
|       </if> | 
|       <if test="operateTime != null"> | 
|         operate_time, | 
|       </if> | 
|       <if test="deleted != null"> | 
|         deleted, | 
|       </if> | 
|     </trim> | 
|     <trim prefix="values (" suffix=")" suffixOverrides=","> | 
|       <if test="id != null"> | 
|         #{id,jdbcType=BIGINT}, | 
|       </if> | 
|       <if test="groupCode != null"> | 
|         #{groupCode,jdbcType=VARCHAR}, | 
|       </if> | 
|       <if test="defaultDuration != null"> | 
|         #{defaultDuration,jdbcType=INTEGER}, | 
|       </if> | 
|       <if test="remarks != null"> | 
|         #{remarks,jdbcType=VARCHAR}, | 
|       </if> | 
|       <if test="operator != null"> | 
|         #{operator,jdbcType=BIGINT}, | 
|       </if> | 
|       <if test="operateTime != null"> | 
|         #{operateTime,jdbcType=TIMESTAMP}, | 
|       </if> | 
|       <if test="deleted != null"> | 
|         #{deleted,jdbcType=TINYINT}, | 
|       </if> | 
|     </trim> | 
|   </insert> | 
|   <update id="updateByPrimaryKeySelective" parameterType="com.dy.pipIrrGlobal.pojoIr.IrIrrigateGroup"> | 
|     <!--@mbg.generated--> | 
|     update ir_irrigate_group | 
|     <set> | 
|       <if test="groupCode != null"> | 
|         group_code = #{groupCode,jdbcType=VARCHAR}, | 
|       </if> | 
|       <if test="defaultDuration != null"> | 
|         default_duration = #{defaultDuration,jdbcType=INTEGER}, | 
|       </if> | 
|       <if test="remarks != null"> | 
|         remarks = #{remarks,jdbcType=VARCHAR}, | 
|       </if> | 
|       <if test="operator != null"> | 
|         `operator` = #{operator,jdbcType=BIGINT}, | 
|       </if> | 
|       <if test="operateTime != null"> | 
|         operate_time = #{operateTime,jdbcType=TIMESTAMP}, | 
|       </if> | 
|       <if test="deleted != null"> | 
|         deleted = #{deleted,jdbcType=TINYINT}, | 
|       </if> | 
|     </set> | 
|     where id = #{id,jdbcType=BIGINT} | 
|   </update> | 
|   <update id="updateByPrimaryKey" parameterType="com.dy.pipIrrGlobal.pojoIr.IrIrrigateGroup"> | 
|     <!--@mbg.generated--> | 
|     update ir_irrigate_group | 
|     set group_code = #{groupCode,jdbcType=VARCHAR}, | 
|       default_duration = #{defaultDuration,jdbcType=INTEGER}, | 
|       remarks = #{remarks,jdbcType=VARCHAR}, | 
|       `operator` = #{operator,jdbcType=BIGINT}, | 
|       operate_time = #{operateTime,jdbcType=TIMESTAMP}, | 
|       deleted = #{deleted,jdbcType=TINYINT} | 
|     where id = #{id,jdbcType=BIGINT} | 
|   </update> | 
|   | 
|   <!--逻辑删除--> | 
|   <delete id="deleteLogicById" parameterType="java.lang.Long"> | 
|     <!--@mbg.generated--> | 
|     update ir_irrigate_group | 
|     set deleted = 1 | 
|     where id = #{id,jdbcType=BIGINT} | 
|   </delete> | 
|   | 
|   <!--修改一个轮罐组--> | 
|   <update id="updateByPrimaryKeySelective" parameterType="com.dy.pipIrrGlobal.pojoIr.IrIrrigateGroup"> | 
|     update ir_irrigate_group | 
|     <set> | 
|       <if test="groupCode != null"> | 
|         group_code = #{groupCode,jdbcType=VARCHAR}, | 
|       </if> | 
|       <if test="remarks != null"> | 
|         remarks = #{remarks,jdbcType=VARCHAR}, | 
|       </if> | 
|       <if test="operator != null"> | 
|         operator = #{operator,jdbcType=BIGINT}, | 
|       </if> | 
|       <if test="operateTime != null"> | 
|         operate_time = #{operateTime,jdbcType=TIMESTAMP}, | 
|       </if> | 
|       <if test="deleted != null"> | 
|         deleted = #{deleted,jdbcType=TINYINT}, | 
|       </if> | 
|     </set> | 
|     where id = #{id,jdbcType=BIGINT} | 
|   </update> | 
|   | 
|   <!--查一个轮罐组--> | 
|   <select id="selectById" resultType="com.dy.pipIrrGlobal.voIr.VoGroupOne"> | 
|     select | 
|     CAST(pro.id AS char)AS projectId, | 
|     pro.project_name  AS  projectName, | 
|     CAST(gro.id AS char)AS id, | 
|     CAST(gro.operator AS char)AS operator, | 
|     cli.name         AS operatorName, | 
|     gro.group_code   AS groupCode, | 
|     COUNT(gu.group_id)   AS itemCount, | 
|     gro.remarks, | 
|     gro.operate_time  AS  operateDt | 
|     from ir_irrigate_group gro | 
|     left join ir_project pro on pro.id = gro.project_id | 
|     left join se_client cli on cli.id = gro.operator | 
|     left join ir_group_unit gu on gu.group_id = gro.id | 
|     where gro.id = #{id,jdbcType=BIGINT} and gro.deleted = 0  and pro.deleted != 1 | 
|   </select> | 
|   | 
|   <!--分页查轮灌组--> | 
|   <select id="getIrrigateGroups" resultType="com.dy.pipIrrGlobal.voIr.VoGroup"> | 
|     SELECT | 
|     CAST(pro.id AS char)AS projectId, | 
|     pro.project_name  AS  projectName, | 
|     CAST(gro.id AS char)AS id, | 
|     CAST(gro.operator AS char)AS operator, | 
|     cli.name         AS operatorName, | 
|     gro.group_code   AS groupCode, | 
|     COUNT(gu.group_id)   AS itemCount, | 
|     gro.remarks, | 
|     gro.operate_time  AS  operateDt | 
|     from ir_irrigate_group gro | 
|     left join ir_project pro on pro.id = gro.project_id | 
|     left join se_client cli on cli.id = gro.operator | 
|     left join ir_group_unit gu on gu.group_id = gro.id | 
|     <where> | 
|       gro.deleted = 0  and pro.deleted != 1 | 
|       <if test="projectName != null and projectName != ''"> | 
|         AND pro.project_name LIKE CONCAT('%', #{projectName}, '%') | 
|       </if> | 
|       <if test="groupCode != null and groupCode != ''"> | 
|         AND gro.group_code = #{groupCode} | 
|       </if> | 
|     </where> | 
|     GROUP BY gro.id | 
|     ORDER BY gro.operate_time DESC | 
|     <if test="pageCurr != null and pageSize != null"> | 
|       LIMIT ${(pageCurr-1)*pageSize}, ${pageSize} | 
|     </if> | 
|   </select> | 
|   <!--分页查轮灌组记录数--> | 
|   <select id="getRecordCount" resultType="java.lang.Long"> | 
|     SELECT COUNT(*) FROM( | 
|     SELECT COUNT(*),gro.id AS recordCount | 
|     from ir_irrigate_group gro | 
|     left join ir_project pro on pro.id = gro.project_id | 
|     left join se_client cli on cli.id = gro.operator | 
|     left join ir_group_unit gu on gu.group_id = gro.id | 
|     <where> | 
|       gro.deleted = 0  and pro.deleted != 1 | 
|       <if test="projectName != null and projectName != ''"> | 
|         AND pro.project_name LIKE CONCAT('%', #{projectName}, '%') | 
|       </if> | 
|       <if test="groupCode != null and groupCode != ''"> | 
|         AND gro.group_code = #{groupCode} | 
|       </if> | 
|     </where> | 
|     GROUP BY gro.id | 
|     ) a | 
|   </select> | 
|   | 
|   | 
|   <!--根据指定条件获取轮灌组记录数--> | 
|   <select id="getSimpleGroupCount" resultType="java.lang.Long"> | 
|     SELECT COUNT(*) AS recordCount | 
|     FROM ir_irrigate_group grp | 
|         LEFT JOIN ir_project_group pg ON pg.group_id = grp.id | 
|     <where> | 
|       AND grp.deleted = 0 | 
|       <if test="projectId != null"> | 
|         AND pg.project_id = #{projectId} | 
|       </if> | 
|       <if test="groupCode != null and groupCode != ''"> | 
|         AND grp.group_code LIKE CONCAT('%', #{groupCode}, '%') | 
|       </if> | 
|     </where> | 
|   </select> | 
|   | 
|   <!--根据指定条件获取轮灌组列表--> | 
|   <select id="getSimpleGroups" resultType="com.dy.pipIrrGlobal.voIr.VoGroupSimple"> | 
|     SELECT DISTINCT | 
|         grp.id AS groupId, | 
|         grp.group_code AS groupCode, | 
|         (SELECT COUNT(*) FROM ir_group_intake WHERE group_id = grp.id) AS intakeCount, | 
|         grp.default_duration AS defaultDuration, | 
|         pg.sort, | 
|         grp.operate_time | 
|     FROM ir_irrigate_group grp | 
|         LEFT JOIN ir_project_group pg ON pg.group_id = grp.id | 
|     <where> | 
|       AND grp.deleted = 0 | 
|   | 
|       <if test="projectId != null"> | 
|         AND pg.project_id = #{projectId} | 
|       </if> | 
|   | 
|       <if test="groupCode != null and groupCode != ''"> | 
|         AND grp.group_code LIKE CONCAT('%', #{groupCode}, '%') | 
|       </if> | 
|     </where> | 
|     ORDER BY pg.sort | 
|     <trim prefix="limit "> | 
|       <if test="start != null and count != null"> | 
|         #{start,javaType=Integer,jdbcType=INTEGER}, #{count,javaType=Integer,jdbcType=INTEGER} | 
|       </if> | 
|     </trim> | 
|   </select> | 
|   | 
|   <select id="getGroupDetail" resultType="com.dy.pipIrrGlobal.voIr.VoGroupDetail"> | 
|     SELECT | 
|       groupCode, | 
|       defaultDuration, | 
|       GROUP_CONCAT(intakeId) AS intakes | 
|     FROM | 
|       ( | 
|         SELECT | 
|           grp.group_code AS groupCode, | 
|           grp.default_duration AS defaultDuration, | 
|           inta.id AS intakeId | 
|         FROM ir_irrigate_group grp | 
|                INNER JOIN ir_group_intake gi ON gi.group_id = grp.id | 
|                INNER JOIN pr_intake inta ON inta.id = gi.intake_id | 
|         WHERE grp.deleted = 0 AND grp.id = #{groupId} | 
|       ) irrigateGroup | 
|     GROUP BY groupCode,defaultDuration | 
|   </select> | 
|   | 
|   <select id="getGroupResult" resultType="com.dy.pipIrrGlobal.voIr.VoGroupResult"> | 
|     SELECT | 
|         grp.id AS groupId, | 
|         grp.group_code AS groupCode, | 
|         IF(sche.current_state = 2, 5, | 
|             IF(NOW() < sche.start_time, 2, | 
|                 IF(NOW() > sche.start_time AND NOW() < DATE_ADD(sche.start_time, INTERVAL sche.duration MINUTE), 3, 4))) AS state, | 
|         sche.start_time AS startTime, | 
|         DATE_ADD(sche.start_time, INTERVAL sche.duration MINUTE) AS stopTime, | 
|         sche.duration, | 
|         NULL AS publishResult | 
|     FROM ir_irrigate_group  grp | 
|         INNER JOIN ir_irrigate_schedule sche ON sche.group_id = grp.id | 
|         INNER JOIN ir_plan_schedule ps ON ps.schedule_id = sche.id | 
|     WHERE ps.plan_id = #{planId}; | 
|   | 
|   </select> | 
|   | 
|   <!--根据灌溉计划ID获取轮灌组终止结果--> | 
|   <select id="getGroupResult_terminate" resultType="com.dy.pipIrrGlobal.voIr.VoGroupResult"> | 
|     SELECT | 
|         grp.id AS groupId, | 
|         grp.group_code AS groupCode, | 
|         IF(#{terminateTime} < sche.start_time, 6, | 
|             IF(#{terminateTime} < DATE_ADD(sche.start_time, INTERVAL sche.duration MINUTE), 5, 4)) AS state, | 
|         IF(#{terminateTime} > sche.start_time, sche.start_time, NULL) AS startTime, | 
|         IF(#{terminateTime} > DATE_ADD(sche.start_time, INTERVAL sche.duration MINUTE), DATE_ADD(sche.start_time, INTERVAL sche.duration MINUTE), | 
|             IF(#{terminateTime} > sche.start_time, #{terminateTime}, NULL)) AS stopTime, | 
|         <!--sche.duration,--> | 
|         IF( | 
|             TIMESTAMPDIFF(MINUTE, | 
|             IF(#{terminateTime} > sche.start_time, sche.start_time, NULL), | 
|                 IF(#{terminateTime} > DATE_ADD(sche.start_time, INTERVAL sche.duration MINUTE), DATE_ADD(sche.start_time, INTERVAL sche.duration MINUTE), | 
|                     IF(#{terminateTime} > sche.start_time, #{terminateTime}, NULL)) | 
|             ) = 0, 1, | 
|             TIMESTAMPDIFF(MINUTE, | 
|                 IF(#{terminateTime} > sche.start_time, sche.start_time, NULL), | 
|                 IF(#{terminateTime} > DATE_ADD(sche.start_time, INTERVAL sche.duration MINUTE), DATE_ADD(sche.start_time, INTERVAL sche.duration MINUTE), | 
|                     IF(#{terminateTime} > sche.start_time, #{terminateTime}, NULL)) | 
|         )) AS duration, | 
|         NULL AS publishResult | 
|     FROM ir_irrigate_group  grp | 
|         INNER JOIN ir_irrigate_schedule sche ON sche.group_id = grp.id | 
|         INNER JOIN ir_plan_schedule ps ON ps.schedule_id = sche.id | 
|     WHERE ps.plan_id = #{planId} | 
|   </select> | 
|   | 
|   <!--根据轮灌组ID获取轮灌组详情--> | 
|   <select id="getGroupIntakes" resultType="com.dy.pipIrrGlobal.voIr.VoGroupIntakes"> | 
|     SELECT | 
|       pro.project_name AS projectName, | 
|       gro.group_code AS groupName, | 
|       NULL AS intakes | 
|     FROM ir_irrigate_group gro | 
|            INNER JOIN ir_project_group pg ON pg.group_id = gro.id | 
|            INNER JOIN ir_project pro ON pro.id = pg.project_id | 
|     WHERE gro.deleted = 0 AND gro.id = #{groupId} | 
|   </select> | 
|   | 
|   <!--根据轮灌组ID获取轮灌组详情列表--> | 
|   <select id="getGroupIntakesList" resultType="com.dy.pipIrrGlobal.voIr.VoIntake"> | 
|     SELECT | 
|       con.rtuAddr, | 
|       inta.name AS intakeName, | 
|       NULL AS isOnLine | 
|     FROM ir_group_intake gi | 
|            INNER JOIN pr_intake inta ON inta.id = gi.intake_id | 
|            INNER JOIN pr_controller con ON con.intakeId = gi.intake_id | 
|     WHERE gi.group_id = #{groupId} | 
|   </select> | 
|    | 
|   <!--根据轮灌组名称统计记录数--> | 
|   <select id="countByGroupCode" resultType="java.lang.Integer"> | 
|     SELECT COUNT(*)  | 
|     FROM ir_irrigate_group  | 
|     WHERE group_code = #{groupCode}  | 
|     AND deleted = 0 | 
|   </select> | 
|    | 
|   <!--根据轮灌组名称统计记录数(排除指定ID)--> | 
|   <select id="countByGroupCodeExcludeId" resultType="java.lang.Integer"> | 
|     SELECT COUNT(*)  | 
|     FROM ir_irrigate_group  | 
|     WHERE group_code = #{groupCode}  | 
|     AND id != #{excludeId}  | 
|     AND deleted = 0 | 
|   </select> | 
| </mapper> |