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

import java.util.List;

/**
 * 设备折旧信息Service业务层处理
 *
 * @author xins
 * @date 2023-12-27
 */
@Service
public class DmsBaseDeviceDepreciationServiceImpl implements IDmsBaseDeviceDepreciationService
{
    @Autowired
    private DmsBaseDeviceDepreciationMapper dmsBaseDeviceDepreciationMapper;

    /**
     * 查询设备折旧信息
     *
     * @param deviceDepreciationId 设备折旧信息主键
     * @return 设备折旧信息
     */
    @Override
    public DmsBaseDeviceDepreciation selectDmsBaseDeviceDepreciationByDeviceDepreciationId(Long deviceDepreciationId)
    {
        return dmsBaseDeviceDepreciationMapper.selectDmsBaseDeviceDepreciationByDeviceDepreciationId(deviceDepreciationId);
    }

    /**
     * 查询设备折旧信息列表
     *
     * @param dmsBaseDeviceDepreciation 设备折旧信息
     * @return 设备折旧信息
     */
    @Override
    public List<DmsBaseDeviceDepreciation> selectDmsBaseDeviceDepreciationList(DmsBaseDeviceDepreciation dmsBaseDeviceDepreciation)
    {
        return dmsBaseDeviceDepreciationMapper.selectDmsBaseDeviceDepreciationList(dmsBaseDeviceDepreciation);
    }

    /**
     * 新增设备折旧信息
     *
     * @param dmsBaseDeviceDepreciation 设备折旧信息
     * @return 结果
     */
    @Override
    public int insertDmsBaseDeviceDepreciation(DmsBaseDeviceDepreciation dmsBaseDeviceDepreciation)
    {
        DmsBaseDeviceDepreciation DeviceDepreciation = new  DmsBaseDeviceDepreciation();
        DeviceDepreciation.setDeviceId(dmsBaseDeviceDepreciation.getDeviceId());
        List<DmsBaseDeviceDepreciation> list = dmsBaseDeviceDepreciationMapper
                .selectDmsBaseDeviceDepreciationList(DeviceDepreciation);
        if (list.size()>0)throw new ServiceException("该设备折旧记录已存在");
        LoginUser user = SecurityUtils.getLoginUser();
        dmsBaseDeviceDepreciation.setCreateBy(user.getUserId());
        dmsBaseDeviceDepreciation.setIsFlag(1l);
        dmsBaseDeviceDepreciation.setCreateTime(DateUtils.getNowDate());
        return dmsBaseDeviceDepreciationMapper.insertDmsBaseDeviceDepreciation(dmsBaseDeviceDepreciation);
    }

    /**
     * 修改设备折旧信息
     *
     * @param dmsBaseDeviceDepreciation 设备折旧信息
     * @return 结果
     */
    @Override
    public int updateDmsBaseDeviceDepreciation(DmsBaseDeviceDepreciation dmsBaseDeviceDepreciation)
    {
        DmsBaseDeviceDepreciation DeviceDepreciation = new  DmsBaseDeviceDepreciation();
        DeviceDepreciation.setDeviceId(dmsBaseDeviceDepreciation.getDeviceId());
        List<DmsBaseDeviceDepreciation> DeviceDepreciationlist = dmsBaseDeviceDepreciationMapper
                .selectDmsBaseDeviceDepreciationList(DeviceDepreciation);
        if (DeviceDepreciationlist.size()>0&& ! DeviceDepreciationlist.get(0).getDeviceDepreciationId()
                .equals(dmsBaseDeviceDepreciation.getDeviceDepreciationId())){
            throw new ServiceException("该设备折旧记录已存在");
        }
        LoginUser user = SecurityUtils.getLoginUser();
        dmsBaseDeviceDepreciation.setUpdateBy(user.getUserId());
        dmsBaseDeviceDepreciation.setUpdateTime(DateUtils.getNowDate());
        return dmsBaseDeviceDepreciationMapper.updateDmsBaseDeviceDepreciation(dmsBaseDeviceDepreciation);
    }

    /**
     * 批量删除设备折旧信息
     *
     * @param deviceDepreciationIds 需要删除的设备折旧信息主键
     * @return 结果
     */
    @Override
    public int deleteDmsBaseDeviceDepreciationByDeviceDepreciationIds(Long[] deviceDepreciationIds)
    {
        return dmsBaseDeviceDepreciationMapper.deleteDmsBaseDeviceDepreciationByDeviceDepreciationIds(deviceDepreciationIds);
    }

    /**
     * 删除设备折旧信息信息
     *
     * @param deviceDepreciationId 设备折旧信息主键
     * @return 结果
     */
    @Override
    public int deleteDmsBaseDeviceDepreciationByDeviceDepreciationId(Long deviceDepreciationId)
    {
        return dmsBaseDeviceDepreciationMapper.deleteDmsBaseDeviceDepreciationByDeviceDepreciationId(deviceDepreciationId);
    }
}
