123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- package com.welampiot.service.impl;
- import com.welampiot.dao.AirSwitchInfoDao;
- import com.welampiot.dto.AirSwitchInfoDTO;
- import com.welampiot.service.AirSwitchInfoService;
- 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;
- @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<AirSwitchInfoDTO> airSwitchList = airSwitchInfoDao.getAirSwitchInfoByBoxId(boxId, online);
- List<AirSwitchInfoDTO> 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);
- 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;
- }
- }
|