| | |
| | | import com.dy.pipIrrGlobal.pojoIr.IrIrrigateGroup; |
| | | import com.dy.pipIrrGlobal.voIr.*; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | import org.apache.ibatis.annotations.Param; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | |
| | | * @return |
| | | */ |
| | | List<VoGroupResult> getGroupResult(Long planId); |
| | | |
| | | /** |
| | | * 根据灌溉计划ID获取轮灌组终止结果 |
| | | * @param planId |
| | | * @param terminateTime |
| | | * @return |
| | | */ |
| | | List<VoGroupResult> getGroupResult_terminate(@Param("planId") Long planId, @Param("terminateTime") Date terminateTime); |
| | | } |
| | |
| | | VoPlanDetails getPlanDetails(@Param("planId") Long planId); |
| | | |
| | | /** |
| | | * 根据计划ID获取已终止计划的详情,结束时间为实际终止时间 |
| | | * @param planId |
| | | * @param terminateTime |
| | | * @return |
| | | */ |
| | | VoPlanDetails getPlanDetails_terminate(@Param("planId") Long planId, @Param("terminateTime") Date terminateTime); |
| | | |
| | | /** |
| | | * 根据计划ID获取计划状态,用于判断是否可以删除计划 |
| | | * @param planId |
| | | * @return |
| | |
| | | import com.dy.pipIrrGlobal.pojoIr.IrPlanOperate; |
| | | import org.apache.ibatis.annotations.Mapper; |
| | | |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * @author ZhuBaoMin |
| | | * @date 2025-02-21 11:11 |
| | |
| | | int updateByPrimaryKeySelective(IrPlanOperate record); |
| | | |
| | | int updateByPrimaryKey(IrPlanOperate record); |
| | | |
| | | /** |
| | | * 根据计划ID获取终止时间 |
| | | * @param planId |
| | | * @return |
| | | */ |
| | | Date getTerminateTime(Long planId); |
| | | } |
| | |
| | | */ |
| | | |
| | | @Data |
| | | @JsonPropertyOrder({"planName", "projectName", "state", "planStartTime", "planStopTime", "failureCount", "groups"}) |
| | | @JsonPropertyOrder({"planName", "projectName", "state", "planStartTime", "planStopTime", "realStopTime", "failureCount", "groups"}) |
| | | public class VoPlanDetails { |
| | | private static final long serialVersionUID = 202504091125001L; |
| | | |
| | |
| | | private Date planStopTime; |
| | | |
| | | /** |
| | | * 实际结束时间 |
| | | */ |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8") |
| | | private Date realStopTime; |
| | | |
| | | /** |
| | | * 命令发布失败数量 |
| | | */ |
| | | private Integer failureCount; |
| | |
| | | io.failure_factors AS result |
| | | FROM ir_intake_operate io |
| | | inner JOIN ir_group_intake gi ON gi.intake_id = io.intake_id |
| | | WHERE io.plan_id = #{planId} AND gi.group_id = #{groupId}; |
| | | WHERE io.plan_id = #{planId} AND gi.group_id = #{groupId} AND operate_type = 1; |
| | | </select> |
| | | |
| | | <!--根据计划ID获取取水口命令发布失败数量,灌溉计划详情页使用--> |
| | |
| | | |
| | | <!--根据指定条件获取轮灌组列表--> |
| | | <select id="getSimpleGroups" resultType="com.dy.pipIrrGlobal.voIr.VoGroupSimple"> |
| | | SELECT |
| | | 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, |
| | | 0 as sort |
| | | 0 as sort, |
| | | grp.operate_time |
| | | FROM ir_irrigate_group grp |
| | | LEFT JOIN ir_project_group pg ON pg.group_id = grp.id |
| | | <where> |
| | |
| | | SELECT |
| | | grp.id AS groupId, |
| | | grp.group_code AS groupCode, |
| | | 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, |
| | | 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, |
| | |
| | | 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, |
| | | 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> |
| | | </mapper> |
| | |
| | | AND plan.deleted = 0 |
| | | </select> |
| | | |
| | | <!--根据计划ID获取已终止计划的详情,结束时间为实际终止时间--> |
| | | <select id="getPlanDetails_terminate" resultType="com.dy.pipIrrGlobal.voIr.VoPlanDetails"> |
| | | SELECT |
| | | plan.plan_name AS planName, |
| | | pro.project_name AS projectName, |
| | | IF(#{terminateTime} < plan.plan_start_time, 6, |
| | | IF(#{terminateTime} < plan.plan_stop_time, 5, 4)) AS state, |
| | | plan.plan_start_time AS planStartTime, |
| | | plan.plan_stop_time AS planStopTime, |
| | | #{terminateTime} AS realStopTime, |
| | | NULL AS groupDetails, |
| | | NULL AS failureCount |
| | | FROM ir_irrigate_plan plan |
| | | INNER JOIN ir_project pro ON pro.id = plan.project_id |
| | | WHERE plan.id =2025041515194900009 |
| | | AND plan.deleted = 0 |
| | | </select> |
| | | |
| | | <!--根据计划ID获取计划状态,用于判断是否可以删除计划--> |
| | | <select id="getPlanState" resultType="java.lang.Integer"> |
| | | SELECT |
| | |
| | | operate_time = #{operateTime,jdbcType=TIMESTAMP} |
| | | where id = #{id,jdbcType=BIGINT} |
| | | </update> |
| | | |
| | | <!--根据计划ID获取终止时间--> |
| | | <select id="getTerminateTime" resultType="java.util.Date"> |
| | | SELECT operate_time AS operateTime FROM ir_plan_operate WHERE operate_type = 5 AND plan_id = #{planId} LIMIT 0,1 |
| | | </select> |
| | | </mapper> |
| | |
| | | BaseResponse<Boolean> result = dealWithCommandResult(myParam); |
| | | // 如果命令执行失败,则再次执行命令 |
| | | if(!result.isSuccess()) { |
| | | myParam.setComId(new IDLongGenerator().generate()); |
| | | result = dealWithCommandResult(myParam); |
| | | } |
| | | |
| | |
| | | BaseResponse<Boolean> result = dealWithCommandResult(myParam); |
| | | // 如果命令执行失败,则再次执行命令 |
| | | if(!result.isSuccess()) { |
| | | myParam.setComId(new IDLongGenerator().generate()); |
| | | result = dealWithCommandResult(myParam); |
| | | } |
| | | |
| | |
| | | irIntakeOperate.setOperateType(operatetype); |
| | | irIntakeOperate.setCommandId(comId); |
| | | irIntakeOperate.setIntakeId(intakeId); |
| | | irIntakeOperate.setCommandResult((byte)1); |
| | | |
| | | Long id = addIntakeOperate(irIntakeOperate); |
| | | if(id == null) { |
| | |
| | | BaseResponse<Boolean> result = dealWithCommandResult(myParam); |
| | | // 如果命令执行失败,则再次执行命令 |
| | | if(!result.isSuccess()) { |
| | | myParam.setComId(new IDLongGenerator().generate()); |
| | | result = dealWithCommandResult(myParam); |
| | | } |
| | | |
| | |
| | | BaseResponse<Boolean> result = dealWithCommandResult(myParam); |
| | | // 如果命令执行失败,则再次执行命令 |
| | | if(!result.isSuccess()) { |
| | | myParam.setComId(new IDLongGenerator().generate()); |
| | | result = dealWithCommandResult(myParam); |
| | | } |
| | | return result; |
| | |
| | | BaseResponse<Boolean> result = dealWithCommandResult(myParam); |
| | | // 如果命令执行失败,则再次执行命令 |
| | | if(!result.isSuccess()) { |
| | | myParam.setComId(new IDLongGenerator().generate()); |
| | | result = dealWithCommandResult(myParam); |
| | | } |
| | | return result; |
| | |
| | | BaseResponse<Boolean> result = dealWithCommandResult(myParam); |
| | | // 如果命令执行失败,则再次执行命令 |
| | | if(!result.isSuccess()) { |
| | | myParam.setComId(new IDLongGenerator().generate()); |
| | | result = dealWithCommandResult(myParam); |
| | | } |
| | | return result; |
| | |
| | | return BaseResponseUtils.buildException(e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 根据计划ID获取计划终止操作结果 |
| | | * @param planId |
| | | * @return |
| | | */ |
| | | @GetMapping(path = "/getTerminateResults") |
| | | public BaseResponse<VoPlanDetails> getTerminateResults(@RequestParam Long planId) { |
| | | if(planId == null) { |
| | | return BaseResponseUtils.buildErrorMsg("计划ID不能为空"); |
| | | } |
| | | |
| | | try { |
| | | VoPlanDetails res = irrigatePlanSv.getTerminateResults(planId); |
| | | return BaseResponseUtils.buildSuccess(res); |
| | | } catch (Exception e) { |
| | | log.error("获取计划发布结果异常", e); |
| | | return BaseResponseUtils.buildException(e.getMessage()); |
| | | } |
| | | } |
| | | } |
| | |
| | | if(planDetails == null){ |
| | | return null; |
| | | } |
| | | |
| | | Integer failureCount = Optional.ofNullable(irIntakeOperateMapper.getFailureCount(planId)).orElse(0); |
| | | planDetails.setFailureCount(failureCount); |
| | | |
| | | Date terminateTime = Optional.ofNullable(irPlanOperateMapper.getTerminateTime(planId)).orElse(null); |
| | | |
| | | List<VoGroupResult> groupResults = irIrrigateGroupMapper.getGroupResult(planId); |
| | | if(groupResults == null || groupResults.size() == 0){ |
| | | return null; |
| | |
| | | return planDetails; |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 根据计划ID获取计划终止操作结果 |
| | | * @param planId |
| | | * @return |
| | | */ |
| | | public VoPlanDetails getTerminateResults(Long planId) { |
| | | // 获取计划终止时间 |
| | | Date terminateTime = Optional.ofNullable(irPlanOperateMapper.getTerminateTime(planId)).orElse(null); |
| | | |
| | | VoPlanDetails planDetails = irrigatePlanMapper.getPlanDetails_terminate(planId, terminateTime); |
| | | if(planDetails == null){ |
| | | return null; |
| | | } |
| | | Integer failureCount = Optional.ofNullable(irIntakeOperateMapper.getFailureCount(planId)).orElse(0); |
| | | planDetails.setFailureCount(failureCount); |
| | | |
| | | List<VoGroupResult> groupResults = irIrrigateGroupMapper.getGroupResult_terminate(planId, terminateTime); |
| | | if(groupResults == null || groupResults.size() == 0){ |
| | | return null; |
| | | } |
| | | |
| | | for (VoGroupResult groupResult : groupResults) { |
| | | List<VoIntakeResult> intakeResults = irIntakeOperateMapper.getIntakeResult(planId, groupResult.getGroupId()); |
| | | if(intakeResults != null) { |
| | | groupResult.setPublishResult(intakeResults); |
| | | } |
| | | } |
| | | |
| | | planDetails.setGroups(groupResults); |
| | | return planDetails; |
| | | |
| | | } |
| | | } |