package com.ruoyi.system.service.impl;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.assets.CommunityAssets;
import com.ruoyi.system.mapper.CommunityAssetsMapper;
import com.ruoyi.system.service.ICommunityAssetsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 社区资产Service业务层处理
 * 
 * @author boman
 * @date 2025-02-24
 */
@Service
public class CommunityAssetsServiceImpl implements ICommunityAssetsService 
{
    @Autowired
    private CommunityAssetsMapper communityAssetsMapper;

    /**
     * 查询社区资产
     * 
     * @param communityAssetId 社区资产主键
     * @return 社区资产
     */
    @Override
    public CommunityAssets selectCommunityAssetsByCommunityAssetId(Long communityAssetId)
    {
        return communityAssetsMapper.selectCommunityAssetsByCommunityAssetId(communityAssetId);
    }

    /**
     * 查询社区资产列表
     * 
     * @param communityAssets 社区资产
     * @return 社区资产
     */
    @Override
    public List<CommunityAssets> selectCommunityAssetsList(CommunityAssets communityAssets)
    {
        return communityAssetsMapper.selectCommunityAssetsList(communityAssets);
    }

    /**
     * 新增社区资产
     * 
     * @param communityAssets 社区资产
     * @return 结果
     */
    @Override
    public int insertCommunityAssets(CommunityAssets communityAssets)
    {
        communityAssets.setCreateTime(DateUtils.getNowDate());
        return communityAssetsMapper.insertCommunityAssets(communityAssets);
    }

    /**
     * 修改社区资产
     * 
     * @param communityAssets 社区资产
     * @return 结果
     */
    @Override
    public int updateCommunityAssets(CommunityAssets communityAssets)
    {
        communityAssets.setUpdateTime(DateUtils.getNowDate());
        return communityAssetsMapper.updateCommunityAssets(communityAssets);
    }

    /**
     * 批量删除社区资产
     * 
     * @param communityAssetIds 需要删除的社区资产主键
     * @return 结果
     */
    @Override
    public int deleteCommunityAssetsByCommunityAssetIds(Long[] communityAssetIds)
    {
        return communityAssetsMapper.deleteCommunityAssetsByCommunityAssetIds(communityAssetIds);
    }

    /**
     * 删除社区资产信息
     * 
     * @param communityAssetId 社区资产主键
     * @return 结果
     */
    @Override
    public int deleteCommunityAssetsByCommunityAssetId(Long communityAssetId)
    {
        return communityAssetsMapper.deleteCommunityAssetsByCommunityAssetId(communityAssetId);
    }

    /**
     * 校验资产编号的唯一性
     * @param communityAssets
     * @return
     */
    @Override
    public boolean checkEquipmentNumberUnique(CommunityAssets communityAssets) {
        Long communityAssetId = StringUtils.isNull(communityAssets.getCommunityAssetId()) ? -1L : communityAssets.getCommunityAssetId();
        CommunityAssets info = communityAssetsMapper.checkEquipmentNumberUnique(communityAssets.getEquipmentNumber());
        if (StringUtils.isNotNull(info) && info.getCommunityAssetId().longValue() != communityAssetId.longValue())
        {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }
}
