package com.aucma.dms.service.impl;

//import com.hw.common.core.utils.DateUtils;
//import com.aucma.dms.domain.DmsRealtimeStatus;
//import com.aucma.dms.domain.DmsRealtimeStatusHistory;
//import com.aucma.dms.mapper.DmsRealtimeStatusMapper;
//import com.aucma.dms.service.IDmsRealtimeStatusService;

import com.aucma.common.utils.DateUtils;
import com.aucma.dms.domain.DmsRealtimeStatus;
import com.aucma.dms.domain.DmsRealtimeStatusHistory;
import com.aucma.dms.mapper.DmsRealtimeStatusMapper;
import com.aucma.dms.service.IDmsRealtimeStatusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 * 设备实时状态Service业务层处理
 *
 * @author Yinq
 * @date 2024-09-02
 */
@Service
public class DmsRealtimeStatusServiceImpl implements IDmsRealtimeStatusService {
    @Autowired
    private DmsRealtimeStatusMapper dmsRealtimeStatusMapper;

    /**
     * 查询设备实时状态
     *
     * @param statusId 设备实时状态主键
     * @return 设备实时状态
     */
    @Override
    public DmsRealtimeStatus selectDmsRealtimeStatusByStatusId(Long statusId) {
        return dmsRealtimeStatusMapper.selectDmsRealtimeStatusByStatusId(statusId);
    }

    /**
     * 查询设备实时状态列表
     *
     * @param dmsRealtimeStatus 设备实时状态
     * @return 设备实时状态
     */
    @Override
    public List<DmsRealtimeStatus> selectDmsRealtimeStatusList(DmsRealtimeStatus dmsRealtimeStatus) {
        return dmsRealtimeStatusMapper.selectDmsRealtimeStatusList(dmsRealtimeStatus);
    }

    /**
     * 新增设备实时状态
     *
     * @param dmsRealtimeStatus 设备实时状态
     * @return 结果
     */
    @Override
    public int insertDmsRealtimeStatus(DmsRealtimeStatus dmsRealtimeStatus) {
        return dmsRealtimeStatusMapper.insertDmsRealtimeStatus(dmsRealtimeStatus);
    }

    /**
     * 修改设备实时状态
     *
     * @param dmsRealtimeStatus 设备实时状态
     * @return 结果
     */
    @Override
    public int updateDmsRealtimeStatus(DmsRealtimeStatus dmsRealtimeStatus) {
        dmsRealtimeStatus.setUpdateTime(DateUtils.getNowDate());
        return dmsRealtimeStatusMapper.updateDmsRealtimeStatus(dmsRealtimeStatus);
    }

    /**
     * 批量删除设备实时状态
     *
     * @param statusIds 需要删除的设备实时状态主键
     * @return 结果
     */
    @Override
    public int deleteDmsRealtimeStatusByStatusIds(Long[] statusIds) {
        return dmsRealtimeStatusMapper.deleteDmsRealtimeStatusByStatusIds(statusIds);
    }

    @Override
    public List<DmsRealtimeStatusHistory> history(DmsRealtimeStatusHistory history) {
        List<DmsRealtimeStatusHistory> history1 = dmsRealtimeStatusMapper.history(history);
        for (DmsRealtimeStatusHistory statusHistory : history1) {
            if ("True".equals(statusHistory.getStatusCode())){
                statusHistory.setStatusCode("是");
            }
            if ("False".equals(statusHistory.getStatusCode())){
                statusHistory.setStatusCode("否");
            }
        }
        Long count = dmsRealtimeStatusMapper.historyTimeCount(history);
        long days = TimeUnit.MINUTES.toDays(count);
        long hours = TimeUnit.MINUTES.toHours(count) - TimeUnit.DAYS.toHours(days);
        long mins = TimeUnit.MINUTES.toMinutes(count) - TimeUnit.HOURS.toMinutes(TimeUnit.MINUTES.toHours(count));
        history1.get(0).setTimeCount(days+"  天"+hours+"  小时"+mins+"  分钟");
        return history1;
    }

    /**
     * 删除设备实时状态信息
     *
     * @param statusId 设备实时状态主键
     * @return 结果
     */
    @Override
    public int deleteDmsRealtimeStatusByStatusId(Long statusId) {
        return dmsRealtimeStatusMapper.deleteDmsRealtimeStatusByStatusId(statusId);
    }


}
