package com.ylx.massage.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.ylx.common.core.domain.model.LoginUser;
import com.ylx.common.utils.DateUtils;
import com.ylx.common.utils.bean.BeanUtils;
import com.ylx.massage.domain.vo.MaCarouselChartVo;
import org.apache.commons.compress.utils.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ylx.massage.mapper.MaCarouselChartMapper;
import com.ylx.massage.domain.MaCarouselChart;
import com.ylx.massage.service.IMaCarouselChartService;

/**
 * 轮播图管理Service业务层处理
 *
 * @author ylx
 * @date 2024-03-21
 */
@Service
public class MaCarouselChartServiceImpl implements IMaCarouselChartService
{
    @Autowired
    private MaCarouselChartMapper maCarouselChartMapper;

    /**
     * 查询轮播图管理
     *
     * @param id 轮播图管理主键
     * @return 轮播图管理
     */
    @Override
    public MaCarouselChart selectMaCarouselChartById(Long id)
    {
        return maCarouselChartMapper.selectMaCarouselChartById(id);
    }

    /**
     * 查询轮播图管理列表
     *
     * @param maCarouselChart 轮播图管理
     * @return 轮播图管理
     */
    @Override
    public List<MaCarouselChartVo> selectMaCarouselChartList(MaCarouselChart maCarouselChart)
    {
        ArrayList<MaCarouselChartVo> vos = Lists.newArrayList();
        List<MaCarouselChart> maCarousel = maCarouselChartMapper.selectMaCarouselChartList(maCarouselChart);
        if (maCarousel.isEmpty()) {
            return vos;
        }
        maCarousel.forEach(project->{
            MaCarouselChartVo vo = new MaCarouselChartVo();
            BeanUtils.copyProperties(project, vo);
            vo.setStringProjectIsEnable(project.getProjectIsEnable() == 1 ? "启用" : "停止");
            vos.add(vo);
        });
        return vos;
    }

    /**
     * 新增轮播图管理
     *
     * @param maCarouselChart 轮播图管理
     * @return 结果
     */
    @Override
    public int insertMaCarouselChart(MaCarouselChartVo maCarouselChartVo, LoginUser loginUser)
    {
        MaCarouselChart maCarouselChart = new MaCarouselChart();
        BeanUtils.copyProperties(maCarouselChartVo, maCarouselChart);

        if (maCarouselChartVo.getId() == null) {
            // 新增
            maCarouselChart.setCreateUser(loginUser.getUser().getUserId());
            maCarouselChart.setUpdateUser(loginUser.getUser().getUserId());
            maCarouselChart.setCreateTime(DateUtils.getNowDate());
            return maCarouselChartMapper.insertMaCarouselChart(maCarouselChart);
        } else {
            // 修改
            maCarouselChart.setUpdateUser(loginUser.getUser().getUserId());
            return maCarouselChartMapper.updateMaCarouselChart(maCarouselChart);
        }
    }

    /**
     * 修改轮播图管理
     *
     * @param maCarouselChart 轮播图管理
     * @return 结果
     */
    @Override
    public int updateMaCarouselChart(MaCarouselChart maCarouselChart)
    {
        maCarouselChart.setUpdateTime(DateUtils.getNowDate());
        return maCarouselChartMapper.updateMaCarouselChart(maCarouselChart);
    }

    /**
     * 批量删除轮播图管理
     *
     * @param ids 需要删除的轮播图管理主键
     * @return 结果
     */
    @Override
    public int deleteMaCarouselChartByIds(Long[] ids)
    {
        return maCarouselChartMapper.deleteMaCarouselChartByIds(ids);
    }

    /**
     * 删除轮播图管理信息
     *
     * @param id 轮播图管理主键
     * @return 结果
     */
    @Override
    public int deleteMaCarouselChartById(Long id)
    {
        return maCarouselChartMapper.deleteMaCarouselChartById(id);
    }
}
