package com.doumee.service.business.impl; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.doumee.core.constants.ResponseStatus; import com.doumee.core.exception.BusinessException; import com.doumee.core.model.PageData; import com.doumee.core.model.PageWrap; import com.doumee.core.utils.Constants; import com.doumee.core.utils.Utils; import com.doumee.dao.business.YwElectricalActionsMapper; import com.doumee.dao.business.model.YwElectrical; import com.doumee.dao.business.model.YwElectricalActions; import com.doumee.service.business.YwElectricalActionsService; import com.doumee.service.business.YwElectricalBizService; import com.github.yulichang.wrapper.MPJLambdaWrapper; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.util.Objects; /** * 电表远程操作记录 Service 实现 */ @Service public class YwElectricalActionsServiceImpl implements YwElectricalActionsService { @Autowired private YwElectricalActionsMapper ywElectricalActionsMapper; @Autowired private YwElectricalBizService ywElectricalBizService; @Override public PageData findPage(PageWrap pageWrap) { IPage page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); YwElectricalActions model = pageWrap.getModel() == null ? new YwElectricalActions() : pageWrap.getModel(); Utils.MP.blankToNull(model); MPJLambdaWrapper queryWrapper = new MPJLambdaWrapper<>(); queryWrapper.selectAll(YwElectricalActions.class) .selectAs(YwElectrical::getName, YwElectricalActions::getElectricalName) .selectAs(YwElectrical::getAddress, YwElectricalActions::getElectricalAddress) .leftJoin(YwElectrical.class, YwElectrical::getId, YwElectricalActions::getElectricalId) .eq(YwElectricalActions::getIsdeleted, Constants.ZERO); if (model.getActionType() != null) { queryWrapper.eq(YwElectricalActions::getActionType, model.getActionType()); } if (model.getOperateTimeBegin() != null) { queryWrapper.ge(YwElectricalActions::getCreateDate, Utils.Date.getStart(model.getOperateTimeBegin())); } if (model.getOperateTimeEnd() != null) { queryWrapper.le(YwElectricalActions::getCreateDate, Utils.Date.getEnd(model.getOperateTimeEnd())); } queryWrapper.orderByDesc(YwElectricalActions::getId); IPage result = ywElectricalActionsMapper.selectJoinPage(page, YwElectricalActions.class, queryWrapper); return PageData.from(result); } @Override public String queryAsyncResult(Integer id) { if (id == null) { throw new BusinessException(ResponseStatus.BAD_REQUEST); } YwElectricalActions act = ywElectricalActionsMapper.selectById(id); if (act == null || Objects.equals(act.getIsdeleted(), Constants.ONE)) { throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(), "操作记录不存在"); } if (!Objects.equals(act.getStatus(), Constants.ZERO)) { throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "仅处理中记录可查询"); } if (StringUtils.isBlank(act.getOprId())) { throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(), "缺少任务 ID"); } return ywElectricalBizService.syncAsyncActionStatus(act.getOprId().trim()); } }