package com.ruoyi.ibs.task.service.impl;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.ibs.task.domain.dto.MarketTaskListDTO;
import com.ruoyi.ibs.task.domain.entity.MarketTaskList;
import com.ruoyi.ibs.task.domain.vo.MarketTaskListVO;
import com.ruoyi.ibs.task.mapper.MarketTaskListMapper;
import com.ruoyi.ibs.task.service.MarketTaskListService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 营销任务Service业务层处理
 *
 */
@Service
public class MarketTaskListServiceImpl implements MarketTaskListService {

    @Resource
    private MarketTaskListMapper marketTaskListMapper;

    /**
     * 查询我的营销任务名单列表
     *
     */
    @Override
    public List<MarketTaskListVO> getMarketLists(MarketTaskListDTO marketTaskListDTO) {
        return marketTaskListMapper.selectMarketTaskLists(marketTaskListDTO, SecurityUtils.getUsername(), SecurityUtils.getDeptId());
    }

    /**
     * 编辑营销任务
     */
    @Override
    public int editMarketTaskList(MarketTaskList marketTaskList) {
        marketTaskList.setUpdateBy(SecurityUtils.getUsername());
        marketTaskList.setUpdateTime(new Date());
        return marketTaskListMapper.updateById(marketTaskList);
    }

    /**
     * 设置状态为已读
     */
    @Override
    public int updateReadTime(Long id) {
        return marketTaskListMapper.updateReadTimeById(id, SecurityUtils.getUsername());
    }

}
