package com.xinelu.manage.service.crowdinfo.impl;

import com.xinelu.common.utils.SecurityUtils;
import com.xinelu.manage.domain.crowdinfo.CrowdInfo;
import com.xinelu.manage.mapper.crowdinfo.CrowdInfoMapper;
import com.xinelu.manage.service.crowdinfo.ICrowdInfoService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 人群信息Service业务层处理
 *
 * @author xinelu
 * @date 2024-03-04
 */
@Service
public class CrowdInfoServiceImpl implements ICrowdInfoService {
    @Resource
    private CrowdInfoMapper crowdInfoMapper;

    /**
     * 查询人群信息
     *
     * @param id 人群信息主键
     * @return 人群信息
     */
    @Override
    public CrowdInfo selectCrowdInfoById(Long id) {
        return crowdInfoMapper.selectCrowdInfoById(id);
    }

    /**
     * 查询人群信息列表
     *
     * @param crowdInfo 人群信息
     * @return 人群信息
     */
    @Override
    public List<CrowdInfo> selectCrowdInfoList(CrowdInfo crowdInfo) {
        return crowdInfoMapper.selectCrowdInfoList(crowdInfo);
    }

    /**
     * 新增人群信息
     *
     * @param crowdInfo 人群信息
     * @return 结果
     */
    @Override
    public int insertCrowdInfo(CrowdInfo crowdInfo) {
        crowdInfo.setCreateTime(LocalDateTime.now());
        crowdInfo.setCreateBy(SecurityUtils.getLoginUser().getUser().getNickName());
        return crowdInfoMapper.insertCrowdInfo(crowdInfo);
    }

    /**
     * 修改人群信息
     *
     * @param crowdInfo 人群信息
     * @return 结果
     */
    @Override
    public int updateCrowdInfo(CrowdInfo crowdInfo) {
        crowdInfo.setUpdateTime(LocalDateTime.now());
        crowdInfo.setUpdateBy(SecurityUtils.getLoginUser().getUser().getNickName());
        return crowdInfoMapper.updateCrowdInfo(crowdInfo);
    }

    /**
     * 批量删除人群信息
     *
     * @param ids 需要删除的人群信息主键
     * @return 结果
     */
    @Override
    public int deleteCrowdInfoByIds(Long[] ids) {
        return crowdInfoMapper.deleteCrowdInfoByIds(ids);
    }

    /**
     * 删除人群信息信息
     *
     * @param id 人群信息主键
     * @return 结果
     */
    @Override
    public int deleteCrowdInfoById(Long id) {
        return crowdInfoMapper.deleteCrowdInfoById(id);
    }
}
