package com.yanzhu.jh.work.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ruoyi.common.enums.WorkJournalismEnum;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yanzhu.jh.work.mapper.WorkJournalismMapper;
import com.yanzhu.jh.work.domain.WorkJournalism;
import com.yanzhu.jh.work.service.IWorkJournalismService;
import com.ruoyi.common.utils.SecurityUtils;
/**
 * 集团新闻Service业务层处理
 * 
 * @author JiangYuQi
 * @date 2023-08-18
 */
@Service
public class WorkJournalismServiceImpl implements IWorkJournalismService 
{
    @Autowired
    private WorkJournalismMapper workJournalismMapper;

    /**
     * 查询集团新闻
     * 
     * @param id 集团新闻主键
     * @return 集团新闻
     */
    @Override
    public WorkJournalism selectWorkJournalismById(Long id)
    {
        return workJournalismMapper.selectWorkJournalismById(id);
    }

    /**
     * 查询集团新闻列表
     * 
     * @param workJournalism 集团新闻
     * @return 集团新闻
     */
    @Override
    public List<WorkJournalism> selectWorkJournalismList(WorkJournalism workJournalism)
    {
        return workJournalismMapper.selectWorkJournalismList(workJournalism);
    }

    /**
     * 查询集团新闻列表
     *
     * @return 集团新闻集合
     */
    @Override
    public List<WorkJournalism> selectBgscreenWorkJournalismList(){
        return workJournalismMapper.selectBgscreenWorkJournalismList();
    }
    /**
     * 查询集团新闻统计
     *
     * @param workJournalism 集团新闻
     * @return 集团新闻集合
     */
    @Override
    public Map<String,Object> findWorkJournalismGroupStatus(WorkJournalism workJournalism){
        List<Map<String, Object>> dataList = workJournalismMapper.findWorkJournalismGroupStatus(workJournalism);
        Map<String, Object> dataMap = new HashMap<>();
        if(dataList!=null && dataList.size()>0){
            for(Map<String, Object> map:dataList){
                dataMap.put("status"+map.get("statusFlag"),map.get("total"));
            }
        }
        return dataMap;
    }
    /**
     * 新增集团新闻
     * 
     * @param workJournalism 集团新闻
     * @return 结果
     */
    @Override
    public int insertWorkJournalism(WorkJournalism workJournalism)
    {
        workJournalism.setStatusFlag(WorkJournalismEnum.DFB.getCode());
        workJournalism.setTopFlag(WorkJournalismEnum.BZD.getCode());
        workJournalism.setCreateBy(SecurityUtils.getUsername());
        workJournalism.setCreateTime(DateUtils.getNowDate());
        return workJournalismMapper.insertWorkJournalism(workJournalism);
    }

    /**
     * 修改集团新闻
     * 
     * @param workJournalism 集团新闻
     * @return 结果
     */
    @Override
    public int updateWorkJournalism(WorkJournalism workJournalism)
    {
        if(WorkJournalismEnum.YFB.getCode().equals(workJournalism.getStatusFlag())){
            workJournalism.setCreateUser(SecurityUtils.getLoginUser().getUser().getNickName());
            workJournalism.setCreateDate(new Date());
        }
        workJournalism.setUpdateBy(SecurityUtils.getUsername());
        workJournalism.setUpdateTime(DateUtils.getNowDate());
        return workJournalismMapper.updateWorkJournalism(workJournalism);
    }

    /**
     * 批量删除集团新闻
     * 
     * @param ids 需要删除的集团新闻主键
     * @return 结果
     */
    @Override
    public int deleteWorkJournalismByIds(Long[] ids)
    {
        return workJournalismMapper.deleteWorkJournalismByIds(ids);
    }

    /**
     * 删除集团新闻信息
     * 
     * @param id 集团新闻主键
     * @return 结果
     */
    @Override
    public int deleteWorkJournalismById(Long id)
    {
        return workJournalismMapper.deleteWorkJournalismById(id);
    }
}
