package com.fs.hisStore.service.impl;

import com.fs.common.exception.ServiceException;
import com.fs.common.utils.DateUtils;
import com.fs.hisStore.domain.FsStoreProductTagScrm;
import com.fs.hisStore.mapper.FsStoreProductTagRelationScrmMapper;
import com.fs.hisStore.mapper.FsStoreProductTagScrmMapper;
import com.fs.hisStore.service.IFsStoreProductTagScrmService;
import com.fs.hisStore.vo.FsStoreProductTagListVO;
import com.fs.hisStore.vo.FsStoreTagProductVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Service
 */
@Service
public class FsStoreProductTagScrmServiceImpl implements IFsStoreProductTagScrmService {

    @Autowired
    private FsStoreProductTagScrmMapper mapper;

    @Autowired
    private FsStoreProductTagRelationScrmMapper productTagRelationMapper;

    @Override
    public FsStoreProductTagScrm selectById(Long id) {
        return mapper.selectById(id);
    }

    @Override
    public List<FsStoreProductTagListVO> selectListVO(FsStoreProductTagScrm query) {
        return mapper.selectListVO(query);
    }

    @Override
    public List<FsStoreProductTagListVO> selectListVOPage(FsStoreProductTagScrm query) {
        return mapper.selectListVO(query);
    }

    @Override
    public List<FsStoreTagProductVO> selectProductsByTagId(Long tagId) {
        return mapper.selectProductsByTagId(tagId);
    }

    @Override
    public int insert(FsStoreProductTagScrm entity) {
        if (entity.getTagName() != null && entity.getTagName().length() > 4) {
            throw new ServiceException("��ǩ�������4����");
        }
        entity.setCreateTime(DateUtils.getNowDate());
        entity.setUpdateTime(DateUtils.getNowDate());
        return mapper.insert(entity);
    }

    @Override
    public int update(FsStoreProductTagScrm entity) {
        if (entity.getTagName() != null && entity.getTagName().length() > 4) {
            throw new ServiceException("��ǩ�������4����");
        }
        entity.setUpdateTime(DateUtils.getNowDate());
        return mapper.update(entity);
    }

    @Override
    public int deleteById(Long id) {
        productTagRelationMapper.deleteByTagIds(new Long[]{id});
        return mapper.deleteById(id);
    }

    @Override
    public int deleteByIds(Long[] ids) {
        if (ids == null || ids.length == 0) {
            return 0;
        }
        productTagRelationMapper.deleteByTagIds(ids);
        return mapper.deleteByIds(ids);
    }
}
