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.DmsBaseDeviceParam;
//import com.aucma.dms.mapper.DmsBaseDeviceParamMapper;
//import com.aucma.dms.service.IDmsBaseDeviceParamService;
//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.DmsBaseDeviceParam;
import com.aucma.dms.mapper.DmsBaseDeviceParamMapper;
import com.aucma.dms.service.IDmsBaseDeviceParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 设备参数信息Service业务层处理
 *
 * @author xins
 * @date 2024-01-09
 */
@Service
public class DmsBaseDeviceParamServiceImpl implements IDmsBaseDeviceParamService
{
    @Autowired
    private DmsBaseDeviceParamMapper dmsBaseDeviceParamMapper;

    /**
     * 查询设备参数信息
     *
     * @param deviceParamId 设备参数信息主键
     * @return 设备参数信息
     */
    @Override
    public DmsBaseDeviceParam selectDmsBaseDeviceParamByDeviceParamId(Long deviceParamId)
    {
        return dmsBaseDeviceParamMapper.selectDmsBaseDeviceParamByDeviceParamId(deviceParamId);
    }

    /**
     * 查询设备参数信息列表
     *
     * @param dmsBaseDeviceParam 设备参数信息
     * @return 设备参数信息
     */
    @Override
    public List<DmsBaseDeviceParam> selectDmsBaseDeviceParamList(DmsBaseDeviceParam dmsBaseDeviceParam)
    {
        return dmsBaseDeviceParamMapper.selectDmsBaseDeviceParamList(dmsBaseDeviceParam);
    }

    /**
     * 新增设备参数信息
     *
     * @param dmsBaseDeviceParam 设备参数信息
     * @return 结果
     */
    @Override
    public int insertDmsBaseDeviceParam(DmsBaseDeviceParam dmsBaseDeviceParam)
    {
        DmsBaseDeviceParam DeviceParam =new DmsBaseDeviceParam();
        DeviceParam.setParamCode(dmsBaseDeviceParam.getParamCode());
        List<DmsBaseDeviceParam> dmsBaseDeviceParamList = dmsBaseDeviceParamMapper
                .selectDmsBaseDeviceParamList(DeviceParam);
        if (dmsBaseDeviceParamList.size()>0) throw new ServiceException("参数编码重复");
        LoginUser user = SecurityUtils.getLoginUser();
        dmsBaseDeviceParam.setCreateBy(user.getUserId());
        dmsBaseDeviceParam.setIsFlag(1l);
        dmsBaseDeviceParam.setCreateTime(DateUtils.getNowDate());
        return dmsBaseDeviceParamMapper.insertDmsBaseDeviceParam(dmsBaseDeviceParam);
    }

    /**
     * 修改设备参数信息
     *
     * @param dmsBaseDeviceParam 设备参数信息
     * @return 结果
     */
    @Override
    public int updateDmsBaseDeviceParam(DmsBaseDeviceParam dmsBaseDeviceParam)
    {
        DmsBaseDeviceParam DeviceParam =new DmsBaseDeviceParam();
        DeviceParam.setParamCode(dmsBaseDeviceParam.getParamCode());
        List<DmsBaseDeviceParam> dmsBaseDeviceParamList = dmsBaseDeviceParamMapper
                .selectDmsBaseDeviceParamList(DeviceParam);
        if (dmsBaseDeviceParamList.size()>0 && !dmsBaseDeviceParamList.get(0).getDeviceParamId()
                .equals(dmsBaseDeviceParam.getDeviceParamId())) {
            throw new ServiceException("参数编码重复");
        }
        LoginUser user = SecurityUtils.getLoginUser();
        dmsBaseDeviceParam.setUpdateBy(user.getUserId());
        dmsBaseDeviceParam.setIsFlag(1l);
        dmsBaseDeviceParam.setUpdateTime(DateUtils.getNowDate());
        return dmsBaseDeviceParamMapper.updateDmsBaseDeviceParam(dmsBaseDeviceParam);
    }

    /**
     * 批量删除设备参数信息
     *
     * @param deviceParamIds 需要删除的设备参数信息主键
     * @return 结果
     */
    @Override
    public int deleteDmsBaseDeviceParamByDeviceParamIds(Long[] deviceParamIds)
    {
        return dmsBaseDeviceParamMapper.deleteDmsBaseDeviceParamByDeviceParamIds(deviceParamIds);
    }

    /**
     * 删除设备参数信息信息
     *
     * @param deviceParamId 设备参数信息主键
     * @return 结果
     */
    @Override
    public int deleteDmsBaseDeviceParamByDeviceParamId(Long deviceParamId)
    {
        return dmsBaseDeviceParamMapper.deleteDmsBaseDeviceParamByDeviceParamId(deviceParamId);
    }
}
