| | |
| | | package com.dy.pipIrrWechat.irrigatePlan; |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.alibaba.fastjson2.JSONArray; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.dy.common.webUtil.BaseResponseUtils; |
| | | import com.dy.common.webUtil.QueryConditionVo; |
| | | import com.dy.common.webUtil.QueryResultVo; |
| | | import com.dy.pipIrrGlobal.daoIr.*; |
| | | import com.dy.pipIrrGlobal.daoRm.RmCommandHistoryMapper; |
| | | import com.dy.pipIrrGlobal.pojoIr.IrIrrigatePlan; |
| | | import com.dy.pipIrrGlobal.pojoIr.IrIrrigateSchedule; |
| | | import com.dy.pipIrrGlobal.pojoIr.IrPlanOperate; |
| | | import com.dy.pipIrrGlobal.pojoIr.IrPlanSchedule; |
| | | import com.dy.pipIrrGlobal.voIr.VoIrrigateSchedule; |
| | | import com.dy.pipIrrGlobal.voIr.VoPlanSimple; |
| | | import com.dy.pipIrrGlobal.voIr.VoPlans; |
| | | import com.dy.pipIrrGlobal.voIr.*; |
| | | import com.dy.pipIrrGlobal.voRm.VoIntakeVc; |
| | | import com.dy.pipIrrGlobal.voSe.VoClient; |
| | | import com.dy.pipIrrWechat.irrigatePlan.dto.PlanSimple; |
| | | import com.dy.pipIrrWechat.irrigatePlan.enums.OperateTypeENUM; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.dubbo.common.utils.PojoUtils; |
| | | import org.apache.ibatis.annotations.Param; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.*; |
| | | |
| | | /** |
| | | * @author ZhuBaoMin |
| | |
| | | @Autowired |
| | | private IrGroupIntakeMapper irGroupIntakeMapper; |
| | | |
| | | @Autowired |
| | | private IrIntakeOperateMapper irIntakeOperateMapper; |
| | | |
| | | @Autowired |
| | | private RmCommandHistoryMapper rmdCommandHistoryMapper; |
| | | |
| | | /** |
| | | * 添加灌溉计划 |
| | | * @param po |
| | |
| | | public Long addIrrigatePlan(IrIrrigatePlan po) { |
| | | irrigatePlanMapper.insert(po); |
| | | return po.getId(); |
| | | } |
| | | |
| | | /** |
| | | * 删除灌溉计划 |
| | | * @param planSimple |
| | | * @return |
| | | */ |
| | | public Map deletePlan(PlanSimple planSimple) { |
| | | Long planId = planSimple.getPlanId(); |
| | | Long operatorId = planSimple.getOperatorId(); |
| | | |
| | | Integer planState = irrigatePlanMapper.getPlanState(planId); |
| | | if(planState == null) { |
| | | Map map = new HashMap<>(); |
| | | map.put("success", false); |
| | | map.put("msg", "灌溉计划不存在"); |
| | | map.put("content", null); |
| | | return map; |
| | | } |
| | | if(planState != 1) { |
| | | Map map = new HashMap<>(); |
| | | map.put("success", false); |
| | | map.put("msg", "灌溉计划非草稿状态,不允许删除"); |
| | | map.put("content", null); |
| | | return map; |
| | | } |
| | | |
| | | try { |
| | | irrigatePlanMapper.deleteByPrimaryKey(planId); |
| | | // 添加灌溉计划操作记录 |
| | | IrPlanOperate planOperate = new IrPlanOperate(); |
| | | planOperate.setPlanId(planId); |
| | | planOperate.setOperator(operatorId); |
| | | planOperate.setOperateType(OperateTypeENUM.DELETE.getCode()); |
| | | planOperate.setOperateTime(new Date()); |
| | | addPlanOperate(planOperate); |
| | | |
| | | Map map = new HashMap<>(); |
| | | map.put("success", true); |
| | | map.put("msg", "灌溉项目删除成功"); |
| | | map.put("content", null); |
| | | return map; |
| | | } catch (Exception e) { |
| | | Map map = new HashMap<>(); |
| | | map.put("success", false); |
| | | map.put("msg", "灌溉项目删除失败"); |
| | | map.put("content", null); |
| | | return map; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 根据计划ID获取待终止计划的结束时间:未删除、未终止、已发布、当前时间小于计划结束时间 |
| | | * @param planId |
| | | * @return |
| | | */ |
| | | public Date getToTerminatePlan(Long planId) { |
| | | return irrigatePlanMapper.getToTerminatePlan(planId); |
| | | } |
| | | |
| | | /** |
| | | * 根据计划ID获取待终止的取水口ID(已发布开发命令,无论是否成功) |
| | | * @param planId |
| | | * @return |
| | | */ |
| | | public List<Long> getToTerminateIntakeIds(Long planId) { |
| | | return irIntakeOperateMapper.getToTerminateIntakeIds(planId); |
| | | } |
| | | |
| | | /** |
| | | * 根据计划ID获取待终止的命令ID列表 |
| | | * @param planId |
| | | * @return |
| | | */ |
| | | public List<Long> getTerminateCommandIds(Long planId) { |
| | | return irIntakeOperateMapper.getTerminateCommandIds(planId); |
| | | } |
| | | |
| | | /** |
| | | * 根据计划ID获取待终止的取水口列表(开阀成功的) |
| | | * @param planId |
| | | * @return |
| | | */ |
| | | public List<VoToTerminateIntakes> getToTerminateIntakes(Long planId) { |
| | | return irIntakeOperateMapper.getToTerminateIntakes(planId); |
| | | } |
| | | |
| | | /** |
| | | * 根据命令日志ID获取取水口及虚拟卡信息,终止灌溉计划时使用,用来执行远程关阀 |
| | | * @param commandId |
| | | * @return |
| | | */ |
| | | public VoIntakeVc getValveOpen(Long commandId) { |
| | | return rmdCommandHistoryMapper.getValveOpen(commandId); |
| | | } |
| | | |
| | | /** |
| | |
| | | * 获取已完成的计划列表,小程序计划列表页使用 |
| | | * @return |
| | | */ |
| | | public List<VoPlans> getCompletedPlans() { |
| | | return irrigatePlanMapper.getCompletedPlans(); |
| | | public QueryResultVo<List<VoPlans>> getCompletedPlans(QueryConditionVo queryVo) { |
| | | Map<String, Object> params = (Map<String, Object>) PojoUtils.generalize(queryVo) ; |
| | | |
| | | Long itemTotal = (long)irrigatePlanMapper.getCompletedPlansCount(params); |
| | | QueryResultVo<List<VoPlans>> rsVo = new QueryResultVo<>() ; |
| | | rsVo.pageSize = queryVo.pageSize ; |
| | | rsVo.pageCurr = queryVo.pageCurr ; |
| | | |
| | | rsVo.calculateAndSet(itemTotal, params); |
| | | rsVo.obj = irrigatePlanMapper.getCompletedPlans(params); |
| | | |
| | | return rsVo ; |
| | | } |
| | | |
| | | /** |
| | |
| | | public Long addIrrigateSchedule(IrIrrigateSchedule po) { |
| | | irIrrigateScheduleMapper.insert(po); |
| | | return po.getId(); |
| | | } |
| | | |
| | | /** |
| | | * 根据计划ID终止灌溉次序,将灌溉次序的当前状态改为已终止 |
| | | * @param planId |
| | | * @return |
| | | */ |
| | | public Integer terminateSchedule(Long planId) { |
| | | return irIrrigateScheduleMapper.terminateSchedule(planId); |
| | | } |
| | | |
| | | /** |
| | |
| | | public Long getIntakeIdByUnitId(Long unitId) { |
| | | return irIrrigateUnitMapper.getIntakeIdByUnitId(unitId); |
| | | } |
| | | |
| | | /** |
| | | * 根据计划ID获取计划发布结果 |
| | | * @param planId |
| | | * @return |
| | | */ |
| | | public VoPlanDetails getPublishResults(Long planId) { |
| | | VoPlanDetails planDetails = irrigatePlanMapper.getPlanDetails(planId); |
| | | if(planDetails == null){ |
| | | return null; |
| | | } |
| | | |
| | | Integer failureCount = Optional.ofNullable(irIntakeOperateMapper.getFailureCount(planId)).orElse(0); |
| | | planDetails.setFailureCount(failureCount); |
| | | |
| | | List<VoGroupResult> groupResults = irIrrigateGroupMapper.getGroupResult(planId); |
| | | 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; |
| | | |
| | | } |
| | | } |