package com.aucma.dms.service.impl;

//import com.hw.common.core.exception.ServiceException;
//import com.hw.common.core.utils.DateUtils;
//import com.hw.common.security.utils.SecurityUtils;
//import com.aucma.dms.domain.DmsBaseDeviceDebugging;
//import com.aucma.dms.mapper.DmsBaseDeviceDebuggingMapper;
//import com.aucma.dms.service.IDmsBaseDeviceDebuggingService;
//import com.hw.system.api.model.LoginUser;

import com.aucma.common.core.domain.model.LoginUser;
import com.aucma.common.exception.ServiceException;
import com.aucma.common.utils.DateUtils;
import com.aucma.common.utils.SecurityUtils;
import com.aucma.dms.domain.DmsBaseDeviceDebugging;
import com.aucma.dms.mapper.DmsBaseDeviceDebuggingMapper;
import com.aucma.dms.service.IDmsBaseDeviceDebuggingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 设备调试信息Service业务层处理
 *
 * @author xins
 * @date 2024-01-02
 */
@Service
public class DmsBaseDeviceDebuggingServiceImpl implements IDmsBaseDeviceDebuggingService
{
    @Autowired
    private DmsBaseDeviceDebuggingMapper dmsBaseDeviceDebuggingMapper;

    /**
     * 查询设备调试信息
     *
     * @param deviceDebuggingId 设备调试信息主键
     * @return 设备调试信息
     */
    @Override
    public DmsBaseDeviceDebugging selectDmsBaseDeviceDebuggingByDeviceDebuggingId(Long deviceDebuggingId)
    {
        return dmsBaseDeviceDebuggingMapper.selectDmsBaseDeviceDebuggingByDeviceDebuggingId(deviceDebuggingId);
    }

    /**
     * 查询设备调试信息列表
     *
     * @param dmsBaseDeviceDebugging 设备调试信息
     * @return 设备调试信息
     */
    @Override
    public List<DmsBaseDeviceDebugging> selectDmsBaseDeviceDebuggingList(DmsBaseDeviceDebugging dmsBaseDeviceDebugging)
    {
        return dmsBaseDeviceDebuggingMapper.selectDmsBaseDeviceDebuggingList(dmsBaseDeviceDebugging);
    }

    /**
     * 新增设备调试信息
     *
     * @param dmsBaseDeviceDebugging 设备调试信息
     * @return 结果
     */
    @Override
    public int insertDmsBaseDeviceDebugging(DmsBaseDeviceDebugging dmsBaseDeviceDebugging)
    {
        DmsBaseDeviceDebugging DeviceDebugging = new DmsBaseDeviceDebugging();
        DeviceDebugging.setWorkOrder(dmsBaseDeviceDebugging.getWorkOrder());
        List<DmsBaseDeviceDebugging> DmsBaseDeviceDebugginglist = dmsBaseDeviceDebuggingMapper
                .selectDmsBaseDeviceDebuggingList(DeviceDebugging);
        if (DmsBaseDeviceDebugginglist.size() > 0)throw new ServiceException("设备调试信息已存在");
        LoginUser loginUser = SecurityUtils.getLoginUser();
        dmsBaseDeviceDebugging.setCreateBy(loginUser.getUserId());
        dmsBaseDeviceDebugging.setCreateTime(DateUtils.getNowDate());
        return dmsBaseDeviceDebuggingMapper.insertDmsBaseDeviceDebugging(dmsBaseDeviceDebugging);
    }

    /**
     * 修改设备调试信息
     *
     * @param dmsBaseDeviceDebugging 设备调试信息
     * @return 结果
     */
    @Override
    public int updateDmsBaseDeviceDebugging(DmsBaseDeviceDebugging dmsBaseDeviceDebugging)
    { DmsBaseDeviceDebugging DeviceDebugging = new DmsBaseDeviceDebugging();
        DeviceDebugging.setWorkOrder(dmsBaseDeviceDebugging.getWorkOrder());
        List<DmsBaseDeviceDebugging> DeviceDebugginglist = dmsBaseDeviceDebuggingMapper
                .selectDmsBaseDeviceDebuggingList(DeviceDebugging);
        if (DeviceDebugginglist.size() > 0 && !dmsBaseDeviceDebugging.getDeviceDebuggingId()
                .equals(DeviceDebugginglist.get(0).getDeviceDebuggingId())){
            throw new ServiceException("设备调试信息已存在");
        }
        LoginUser loginUser = SecurityUtils.getLoginUser();
        dmsBaseDeviceDebugging.setUpdateBy(loginUser.getUserId());
        dmsBaseDeviceDebugging.setUpdateTime(DateUtils.getNowDate());
        return dmsBaseDeviceDebuggingMapper.updateDmsBaseDeviceDebugging(dmsBaseDeviceDebugging);
    }

    /**
     * 批量删除设备调试信息
     *
     * @param deviceDebuggingIds 需要删除的设备调试信息主键
     * @return 结果
     */
    @Override
    public int deleteDmsBaseDeviceDebuggingByDeviceDebuggingIds(Long[] deviceDebuggingIds)
    {
        return dmsBaseDeviceDebuggingMapper.deleteDmsBaseDeviceDebuggingByDeviceDebuggingIds(deviceDebuggingIds);
    }

    /**
     * 删除设备调试信息信息
     *
     * @param deviceDebuggingId 设备调试信息主键
     * @return 结果
     */
    @Override
    public int deleteDmsBaseDeviceDebuggingByDeviceDebuggingId(Long deviceDebuggingId)
    {
        return dmsBaseDeviceDebuggingMapper.deleteDmsBaseDeviceDebuggingByDeviceDebuggingId(deviceDebuggingId);
    }
}
