package com.huijy.management.service.impl;

import java.util.List;

import com.huijy.management.domain.MarkerContent;
import com.huijy.management.service.IMarkerContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.huijy.management.mapper.MarkerMapper;
import com.huijy.management.domain.Marker;
import com.huijy.management.service.IMarkerService;

/**
 * 标记物管理Service业务层处理
 *
 * @author luobo
 * @date 2021-09-08
 */
@Service
public class MarkerServiceImpl implements IMarkerService
{
    @Autowired
    private MarkerMapper markerMapper;
    @Autowired
    private IMarkerContentService markerContentService;

    /**
     * 查询标记物管理
     *
     * @param markerId 标记物管理主键
     * @return 标记物管理
     */
    @Override
    public Marker selectMarkerByMarkerId(Long markerId)
    {
        return markerMapper.selectMarkerByMarkerId(markerId);
    }

    /**
     * 查询标记物管理列表
     *
     * @param marker 标记物管理
     * @return 标记物管理
     */
    @Override
    public List<Marker> selectMarkerList(Marker marker)
    {
        return markerMapper.selectMarkerList(marker);
    }

    @Override
    public List<Marker> selectMarkerList(Long contentId) {
        return markerMapper.selectMarkerListByContentId(contentId);
    }



    /**
     * 新增标记物管理
     *
     * @param marker 标记物管理
     * @return 结果
     */
    @Override
    public int insertMarker(Marker marker)
    {
      int row =  markerMapper.insertMarker(marker);
      if (marker.getContentIdsList()!=null && marker.getContentIdsList().size()>0){
          for (Long item:marker.getContentIdsList()){
              MarkerContent markerContent = new MarkerContent();
              markerContent.setMarkerId(marker.getMarkerId());
              markerContent.setContentId(item);
              markerContentService.insertMarkerContent(markerContent);
          }
      }
        return row;
    }

    /**
     * 修改标记物管理
     *
     * @param marker 标记物管理
     * @return 结果
     */
    @Override
    public int updateMarker(Marker marker)
    {
        Integer row = markerMapper.updateMarker(marker);
        //先删除
        markerContentService.deleteMarkerContentByMarkerId(marker.getMarkerId());
        if (marker.getContentIdsList()!=null && marker.getContentIdsList().size()>0){
            for (Long item:marker.getContentIdsList()){
                MarkerContent markerContent = new MarkerContent();
                markerContent.setMarkerId(marker.getMarkerId());
                markerContent.setContentId(item);
                markerContentService.insertMarkerContent(markerContent);
            }
        }

        return row;
    }

    /**
     * 批量删除标记物管理
     *
     * @param markerIds 需要删除的标记物管理主键
     * @return 结果
     */
    @Override
    public int deleteMarkerByMarkerIds(Long[] markerIds)
    {
        return markerMapper.deleteMarkerByMarkerIds(markerIds);
    }

    /**
     * 删除标记物管理信息
     *
     * @param markerId 标记物管理主键
     * @return 结果
     */
    @Override
    public int deleteMarkerByMarkerId(Long markerId)
    {
        return markerMapper.deleteMarkerByMarkerId(markerId);
    }
}
