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

import java.util.List;

/**
 * 停机类型信息Service业务层处理
 *
 * @author Open Platform
 * @date 2024-01-12
 */
@Service
public class DmsBaseShutTypeServiceImpl implements IDmsBaseShutTypeService
{
    @Autowired
    private DmsBaseShutTypeMapper dmsBaseShutTypeMapper;

    /**
     * 查询停机类型信息
     *
     * @param shutTypeId 停机类型信息主键
     * @return 停机类型信息
     */
    @Override
    public DmsBaseShutType selectDmsBaseShutTypeByShutTypeId(Long shutTypeId)
    {
        return dmsBaseShutTypeMapper.selectDmsBaseShutTypeByShutTypeId(shutTypeId);
    }

    /**
     * 查询停机类型信息列表
     *
     * @param dmsBaseShutType 停机类型信息
     * @return 停机类型信息
     */
    @Override
    public List<DmsBaseShutType> selectDmsBaseShutTypeList(DmsBaseShutType dmsBaseShutType)
    {
        return dmsBaseShutTypeMapper.selectDmsBaseShutTypeList(dmsBaseShutType);
    }

    /**
     * 新增停机类型信息
     *
     * @param dmsBaseShutType 停机类型信息
     * @return 结果
     */
    @Override
    public int insertDmsBaseShutType(DmsBaseShutType dmsBaseShutType)
    {
        DmsBaseShutType ShutType = new DmsBaseShutType();
        ShutType.setTypeCode(dmsBaseShutType.getTypeCode());
        List<DmsBaseShutType> DmsBaseShutTypeList = dmsBaseShutTypeMapper
                .selectDmsBaseShutTypeList(ShutType);
        if (DmsBaseShutTypeList.size() > 0){throw new ServiceException("停机类型编码已存在");}
        LoginUser user = SecurityUtils.getLoginUser();
        dmsBaseShutType.setIsFlag("1");
        dmsBaseShutType.setCreateBy(user.getUserId());
        dmsBaseShutType.setCreateTime(DateUtils.getNowDate());
        return dmsBaseShutTypeMapper.insertDmsBaseShutType(dmsBaseShutType);
    }

    /**
     * 修改停机类型信息
     *
     * @param dmsBaseShutType 停机类型信息
     * @return 结果
     */
    @Override
    public int updateDmsBaseShutType(DmsBaseShutType dmsBaseShutType)
    {
        LoginUser user = SecurityUtils.getLoginUser();
        DmsBaseShutType ShutType = new DmsBaseShutType();
        ShutType.setTypeCode(dmsBaseShutType.getTypeCode());
        List<DmsBaseShutType> DmsBaseShutTypeList = dmsBaseShutTypeMapper
                .selectDmsBaseShutTypeList(ShutType);
        if (DmsBaseShutTypeList.size() > 0 && !dmsBaseShutType.getShutTypeId()
                .equals(DmsBaseShutTypeList.get(0).getShutTypeId())){
            throw new ServiceException("停机类型编码已存在");
        }
        dmsBaseShutType.setUpdateBy(user.getUserId());
        dmsBaseShutType.setUpdateTime(DateUtils.getNowDate());
        return dmsBaseShutTypeMapper.updateDmsBaseShutType(dmsBaseShutType);
    }

    /**
     * 批量删除停机类型信息
     *
     * @param shutTypeIds 需要删除的停机类型信息主键
     * @return 结果
     */
    @Override
    public int deleteDmsBaseShutTypeByShutTypeIds(Long[] shutTypeIds)
    {
        return dmsBaseShutTypeMapper.deleteDmsBaseShutTypeByShutTypeIds(shutTypeIds);
    }

    /**
     * 删除停机类型信息信息
     *
     * @param shutTypeId 停机类型信息主键
     * @return 结果
     */
    @Override
    public int deleteDmsBaseShutTypeByShutTypeId(Long shutTypeId)
    {
        return dmsBaseShutTypeMapper.deleteDmsBaseShutTypeByShutTypeId(shutTypeId);
    }
}
