package com.welampiot.service.impl; import com.welampiot.common.BaseResult; import com.welampiot.common.InterfaceResultEnum; import com.welampiot.dao.AirSwitchInfoDao; import com.welampiot.dto.AirSwitchInfoDTO; import com.welampiot.dto.ElectricModuleDTO; import com.welampiot.service.AirSwitchInfoService; import com.welampiot.service.ElectricBoxService; import com.welampiot.service.ElectricModuleService; import com.welampiot.utils.ToolUtils; import com.welampiot.vo.AirSwitchDetailVO; import com.welampiot.vo.AirSwitchInfoReturnVO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; /** * ClassName: AirSwitchInfoServiceImpl * Package: com.welampiot.service.impl * Description: * * @Author: zhj_Start * @Create: 2023/3/28 - 21:27 * @Version: v1.0 */ @Service public class AirSwitchInfoServiceImpl implements AirSwitchInfoService { @Autowired private AirSwitchInfoDao airSwitchInfoDao; @Autowired private ToolUtils toolUtils; @Autowired private ElectricModuleService electricModuleService; @Autowired private ElectricBoxService electricBoxService; @Override public AirSwitchInfoReturnVO getAirSwitchInfo(Integer boxId, Integer online) { AirSwitchInfoReturnVO airSwitchInfoReturnVO = new AirSwitchInfoReturnVO(); airSwitchInfoReturnVO.setTotalDev(airSwitchInfoDao.getCountByBoxId(boxId)); airSwitchInfoReturnVO.setOneDev(airSwitchInfoDao.getCountByBoxIdAndType(boxId,0)); airSwitchInfoReturnVO.setThreeDev(airSwitchInfoDao.getCountByBoxIdAndType(boxId,1)); airSwitchInfoReturnVO.setAlarmCount(airSwitchInfoDao.getCountByBoxIdAndAlarmStatus(boxId)); airSwitchInfoReturnVO.setPolicyId(airSwitchInfoDao.getPolicyIdByBoxId(boxId)); if (airSwitchInfoReturnVO.getPolicyId() != null && airSwitchInfoReturnVO.getPolicyId() != 0){ airSwitchInfoReturnVO.setPolicyName(airSwitchInfoDao.getPolicyNameByPolicyId(airSwitchInfoReturnVO.getPolicyId())); }else { airSwitchInfoReturnVO.setPolicyName(""); } List airSwitchList = airSwitchInfoDao.getAirSwitchInfoByBoxId(boxId, online); List airSwitchInfoDTOS = new ArrayList<>(); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); airSwitchList.forEach(airSwitchInfoDTO -> { if (airSwitchInfoDTO.getPolicyId() == null || airSwitchInfoDTO.getPolicyId() == 0){ airSwitchInfoDTO.setPolicyName(""); } if (airSwitchInfoDTO.getLogTime() != null){ Date cmdTime; try { cmdTime = simpleDateFormat.parse(airSwitchInfoDTO.getLogTime()); } catch (ParseException e) { throw new RuntimeException(e); } //判断时区,为null默认东八区 long timezone = airSwitchInfoDTO.getTimezone() == null ? 8 : airSwitchInfoDTO.getTimezone(); long l = cmdTime.getTime() + timezone * 3600 * 1000; cmdTime = new Date(l); airSwitchInfoDTO.setLogTime(simpleDateFormat.format(cmdTime)); }else { airSwitchInfoDTO.setLogTime(""); } if (airSwitchInfoDTO.getStatus() != null && airSwitchInfoDTO.getStatus() == 1){ airSwitchInfoDTO.setStatus(1); }else { airSwitchInfoDTO.setStatus(0); } if (airSwitchInfoDTO.getType() != null && airSwitchInfoDTO.getType() == 1) { airSwitchInfoDTO.setType(1); }else { airSwitchInfoDTO.setType(0); } airSwitchInfoDTOS.add(airSwitchInfoDTO); }); airSwitchInfoReturnVO.setList(airSwitchInfoDTOS); return airSwitchInfoReturnVO; } @Override public AirSwitchDetailVO getAirSwitchDetail(Integer id) { AirSwitchDetailVO airSwitchDetailVO = new AirSwitchDetailVO(); AirSwitchInfoDTO airSwitchInfoDTO = airSwitchInfoDao.getAirSwitchDetailById(id); if (airSwitchInfoDTO == null) return null; airSwitchDetailVO.setName(airSwitchInfoDTO.getName()); airSwitchDetailVO.setAddress(airSwitchInfoDTO.getAddress()); airSwitchDetailVO.setBoxId(airSwitchInfoDTO.getBoxId().toString()); if (airSwitchInfoDTO.getType() != null && airSwitchInfoDTO.getType() == 1){ airSwitchInfoDTO.setType(1); airSwitchDetailVO.setType(airSwitchInfoDTO.getType().toString()); }else { airSwitchInfoDTO.setType(0); airSwitchDetailVO.setType(airSwitchInfoDTO.getType().toString()); } return airSwitchDetailVO; } @Override public BaseResult add(AirSwitchInfoDTO dto) { ElectricModuleDTO detailsById = electricModuleService.getDetailsById(dto.getModuleId()); dto.setBoxId(detailsById.getBoxId()); dto.setBoxAddress(detailsById.getAddress()); airSwitchInfoDao.add(dto); return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,dto.getVersion()); } @Override public BaseResult update(AirSwitchInfoDTO dto) { ElectricModuleDTO detailsById = electricModuleService.getDetailsById(dto.getModuleId()); dto.setBoxId(detailsById.getBoxId()); dto.setBoxAddress(detailsById.getAddress()); airSwitchInfoDao.update(dto); return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,dto.getVersion()); } @Override public Integer delete(AirSwitchInfoDTO dto) { return airSwitchInfoDao.delete(dto); } @Override public Integer deleteByBoxId(Integer boxId) { return airSwitchInfoDao.deleteByBoxId(boxId); } @Override public AirSwitchInfoDTO getAirSwitchAddressById(Integer id) { return airSwitchInfoDao.getAirSwitchAddressById(id); } @Override public List getAirSwitchAddressByModuleId(Integer moduleId) { return airSwitchInfoDao.getAirSwitchAddressByModuleId(moduleId); } @Override public void updateAirSwitchStatusById(AirSwitchInfoDTO dto) { airSwitchInfoDao.updateAirSwitchStatusById(dto); } }