package com.newfiber.api.pc.service.impl; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.service.impl.ServiceImpl; import com.newfiber.api.core.commons.CustomException; import com.newfiber.api.core.commons.ResultCode; import com.newfiber.api.pc.dao.PumpOperationLogMapper; import com.newfiber.api.pc.dao.PumpRuntimeDataMapper; import com.newfiber.api.pc.dto.OperationPumpDTO; import com.newfiber.api.pc.dto.PumpRuntimeDTO; import com.newfiber.api.pc.model.zhz.PumpOperationLog; import com.newfiber.api.pc.model.zhz.PumpRuntimeData; import com.newfiber.api.pc.model.zhz.PumpStationInfo; import com.newfiber.api.pc.service.PumpRuntimeDataService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.StringUtils; import javax.servlet.http.HttpServletRequest; import java.util.Date; import java.util.List; /** * @description: 泵机运行数据业务层实现类 * @author: 张鸿志 * @date: 2020/12/14 15:26 * @version: v1.0 */ @Service @Transactional(rollbackFor = Exception.class) public class PumpRuntimeDataServiceImpl extends ServiceImpl<PumpRuntimeDataMapper, PumpRuntimeData> implements PumpRuntimeDataService { @Autowired private PumpOperationLogMapper pumpOperationLogMapper; @Override public List<PumpRuntimeData> selectPumpRuntimeDataByStationNoOrPumpType(PumpRuntimeDTO pumpRuntimeDTO) { if(StringUtils.isEmpty(pumpRuntimeDTO) || StringUtils.isEmpty(pumpRuntimeDTO.getPumpStationNo())){ throw new CustomException(ResultCode.PARAM_NULL); } EntityWrapper<PumpRuntimeData> wrapper = new EntityWrapper<>(); wrapper.eq("pump_station_no",pumpRuntimeDTO.getPumpStationNo()); if(!StringUtils.isEmpty(pumpRuntimeDTO.getPumpName())){ wrapper.like("pump_name",pumpRuntimeDTO.getPumpName()); } return this.selectList(wrapper); } @Override public void operationPumpStateBySanWei(String pumpSiteNo, String pumpNo, String state, HttpServletRequest request) { } @Override public void operationPumpState(OperationPumpDTO operationPumpDTO, HttpServletRequest request) { String userNo = request.getHeader("userNo"); EntityWrapper<PumpRuntimeData> wrapper = new EntityWrapper<>(); if(StringUtils.isEmpty(operationPumpDTO.getPumpStationNo()) && StringUtils.isEmpty(operationPumpDTO.getPumpNo()) &&StringUtils.isEmpty(operationPumpDTO.getState()) ){ throw new CustomException(ResultCode.PARAM_NULL); } wrapper.eq("pump_station_no",operationPumpDTO.getPumpStationNo()); wrapper.eq("pump_no",operationPumpDTO.getPumpNo()); PumpRuntimeData pumpRuntimeData = this.selectOne(wrapper); pumpRuntimeData.setUpdateTime(new Date()); pumpRuntimeData.setPumpState(operationPumpDTO.getState()); boolean update = this.updateById(pumpRuntimeData); //记录操作日志 PumpOperationLog log = new PumpOperationLog(); log.setOperationState(operationPumpDTO.getState()); log.setPumpNo(operationPumpDTO.getPumpNo()); log.setPumpSiteNo(operationPumpDTO.getPumpStationNo()); log.setControlUserNo(userNo); log.setControlTime(new Date()); Integer insert = pumpOperationLogMapper.insert(log); if(!update && insert == 0){ throw new CustomException(ResultCode.UPDATE_ERROR); } } }