123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- package com.welampiot.service.impl;
- import com.welampiot.dao.SmartLockDevInfoDao;
- import com.welampiot.dto.SmartLockDevInfoDTO;
- import com.welampiot.service.SmartLockDevInfoService;
- import com.welampiot.vo.SmartLockDevInfoVO;
- 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: SmartLockDevInfoServiceImpl
- * Package: com.welampiot.service.impl
- * Description:
- *
- * @Author: zhj_Start
- * @Create: 2023/4/28 - 12:42
- * @Version: v1.0
- */
- @Service
- public class SmartLockDevInfoServiceImpl implements SmartLockDevInfoService {
- @Autowired
- private SmartLockDevInfoDao smartLockDevInfoDao;
- @Override
- public SmartLockDevInfoVO getListBySmartLockDevInfoDTO(SmartLockDevInfoDTO dto) {
- SmartLockDevInfoVO vo = new SmartLockDevInfoVO();
- vo.setTotal(smartLockDevInfoDao.getSmartLockTotalByDTO(dto));
- List<SmartLockDevInfoDTO> listDTO = smartLockDevInfoDao.getListBySmartLockDevInfoDTO(dto);
- List<SmartLockDevInfoDTO> list = new ArrayList<>();
- SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- listDTO.forEach(devInfoDTO ->{
- if (devInfoDTO.getLampPoleName() == null){
- devInfoDTO.setLampPoleName("");
- }
- if (devInfoDTO.getArea() == null){
- devInfoDTO.setArea("");
- }
- if (devInfoDTO.getSection() == null){
- devInfoDTO.setSection("");
- }
- if (devInfoDTO.getModel() != null && devInfoDTO.getModel() == 2){
- devInfoDTO.setModel(2);
- }else if (devInfoDTO.getModel() != null && devInfoDTO.getModel() == 1){
- devInfoDTO.setModel(1);
- }else {
- devInfoDTO.setModel(0);
- }
- if (devInfoDTO.getOnline() != null && devInfoDTO.getOnline() == 1){
- devInfoDTO.setOnline(1);
- }else {
- devInfoDTO.setOnline(0);
- }
- if (devInfoDTO.getStatus() != null && devInfoDTO.getStatus() == 1){
- devInfoDTO.setStatus(1);
- }else {
- devInfoDTO.setStatus(0);
- }
- if (devInfoDTO.getCloudBoxModel() != null && devInfoDTO.getCloudBoxModel() == 3){
- devInfoDTO.setCloudBoxModel(3);
- }else if (devInfoDTO.getCloudBoxModel() != null && devInfoDTO.getCloudBoxModel() == 2){
- devInfoDTO.setCloudBoxModel(2);
- }else if (devInfoDTO.getCloudBoxModel() != null && devInfoDTO.getCloudBoxModel() == 1){
- devInfoDTO.setCloudBoxModel(1);
- }else {
- devInfoDTO.setCloudBoxModel(0);
- }
- if (devInfoDTO.getCreateTime() != null && !devInfoDTO.getCreateTime().equals("")){
- try {
- devInfoDTO.setCreateTime(simpleDateFormat.format(simpleDateFormat.parse(devInfoDTO.getCreateTime())));
- } catch (ParseException e) {
- throw new RuntimeException(e);
- }
- }else {
- devInfoDTO.setCreateTime("");
- }
- if (devInfoDTO.getInstallDate() != null && !devInfoDTO.getInstallDate().equals("")){
- try {
- devInfoDTO.setInstallDate(simpleDateFormat.format(simpleDateFormat.parse(devInfoDTO.getInstallDate())));
- } catch (ParseException e) {
- throw new RuntimeException(e);
- }
- }else {
- devInfoDTO.setInstallDate("");
- }
- if (devInfoDTO.getExpirationDate() != null && !devInfoDTO.getExpirationDate().equals("")){
- try {
- devInfoDTO.setExpirationDate(simpleDateFormat.format(simpleDateFormat.parse(devInfoDTO.getExpirationDate())));
- } catch (ParseException e) {
- throw new RuntimeException(e);
- }
- }else {
- devInfoDTO.setExpirationDate("");
- }
- if (devInfoDTO.getUpdateTime() != null && !devInfoDTO.getUpdateTime().equals("")){
- Date cmdTime;
- try {
- cmdTime = simpleDateFormat.parse(devInfoDTO.getUpdateTime());
- } catch (ParseException e) {
- throw new RuntimeException(e);
- }
- //判断时区,为null默认东八区
- long timezone = devInfoDTO.getTimezone() == null ? 8 : devInfoDTO.getTimezone();
- long l = cmdTime.getTime() + timezone * 3600 * 1000;
- cmdTime = new Date(l);
- devInfoDTO.setUpdateTime(simpleDateFormat.format(cmdTime));
- }else {
- devInfoDTO.setUpdateTime("");
- }
- list.add(devInfoDTO);
- });
- vo.setList(list);
- return vo;
- }
- }
|