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.DmsBaseSpecialdeviceParam;
//import com.aucma.dms.mapper.DmsBaseSpecialdeviceParamMapper;
//import com.aucma.dms.service.IDmsBaseSpecialdeviceParamService;
//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.DmsBaseSpecialdeviceParam;
import com.aucma.dms.mapper.DmsBaseSpecialdeviceParamMapper;
import com.aucma.dms.service.IDmsBaseSpecialdeviceParamService;
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 DmsBaseSpecialdeviceParamServiceImpl implements IDmsBaseSpecialdeviceParamService
{
    @Autowired
    private DmsBaseSpecialdeviceParamMapper dmsBaseSpecialdeviceParamMapper;

    /**
     * 查询特种设备参数信息
     *
     * @param specialdeviceParamId 特种设备参数信息主键
     * @return 特种设备参数信息
     */
    @Override
    public DmsBaseSpecialdeviceParam selectDmsBaseSpecialdeviceParamBySpecialdeviceParamId(Long specialdeviceParamId)
    {
        return dmsBaseSpecialdeviceParamMapper.selectDmsBaseSpecialdeviceParamBySpecialdeviceParamId(specialdeviceParamId);
    }

    /**
     * 查询特种设备参数信息列表
     *
     * @param dmsBaseSpecialdeviceParam 特种设备参数信息
     * @return 特种设备参数信息
     */
    @Override
    public List<DmsBaseSpecialdeviceParam> selectDmsBaseSpecialdeviceParamList(DmsBaseSpecialdeviceParam dmsBaseSpecialdeviceParam)
    {
        return dmsBaseSpecialdeviceParamMapper.selectDmsBaseSpecialdeviceParamList(dmsBaseSpecialdeviceParam);
    }

    /**
     * 新增特种设备参数信息
     *
     * @param dmsBaseSpecialdeviceParam 特种设备参数信息
     * @return 结果
     */
    @Override
    public int insertDmsBaseSpecialdeviceParam(DmsBaseSpecialdeviceParam dmsBaseSpecialdeviceParam)
    {
        DmsBaseSpecialdeviceParam DeviceParam =new DmsBaseSpecialdeviceParam();
        DeviceParam.setParamCode(dmsBaseSpecialdeviceParam.getParamCode());
        List<DmsBaseSpecialdeviceParam> dmsBaseDeviceParamList = dmsBaseSpecialdeviceParamMapper
                .selectDmsBaseSpecialdeviceParamList(DeviceParam);
        if (dmsBaseDeviceParamList.size()>0 ) {
            throw new ServiceException("参数编号重复");
        }
        LoginUser user = SecurityUtils.getLoginUser();
        dmsBaseSpecialdeviceParam.setCreateBy(user.getUserId());
        dmsBaseSpecialdeviceParam.setIsFlag(1l);
        dmsBaseSpecialdeviceParam.setCreateTime(DateUtils.getNowDate());
        return dmsBaseSpecialdeviceParamMapper.insertDmsBaseSpecialdeviceParam(dmsBaseSpecialdeviceParam);
    }

    /**
     * 修改特种设备参数信息
     *
     * @param dmsBaseSpecialdeviceParam 特种设备参数信息
     * @return 结果
     */
    @Override
    public int updateDmsBaseSpecialdeviceParam(DmsBaseSpecialdeviceParam dmsBaseSpecialdeviceParam)
    {
        DmsBaseSpecialdeviceParam DeviceParam =new DmsBaseSpecialdeviceParam();
        DeviceParam.setParamCode(dmsBaseSpecialdeviceParam.getParamCode());
        List<DmsBaseSpecialdeviceParam> dmsBaseDeviceParamList = dmsBaseSpecialdeviceParamMapper
                .selectDmsBaseSpecialdeviceParamList(DeviceParam);
        if (dmsBaseDeviceParamList.size()>0 && !dmsBaseDeviceParamList.get(0).getSpecialdeviceParamId()
                .equals(dmsBaseSpecialdeviceParam.getSpecialdeviceParamId())) {
            throw new ServiceException("参数编号重复");
        }
        LoginUser user = SecurityUtils.getLoginUser();
        dmsBaseSpecialdeviceParam.setUpdateBy(user.getUserId());
        dmsBaseSpecialdeviceParam.setUpdateTime(DateUtils.getNowDate());
        return dmsBaseSpecialdeviceParamMapper.updateDmsBaseSpecialdeviceParam(dmsBaseSpecialdeviceParam);
    }

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

    /**
     * 删除特种设备参数信息信息
     *
     * @param specialdeviceParamId 特种设备参数信息主键
     * @return 结果
     */
    @Override
    public int deleteDmsBaseSpecialdeviceParamBySpecialdeviceParamId(Long specialdeviceParamId)
    {
        return dmsBaseSpecialdeviceParamMapper.deleteDmsBaseSpecialdeviceParamBySpecialdeviceParamId(specialdeviceParamId);
    }
}
