package com.hai.service.impl;

import com.hai.dao.SecUserLabelMapper;
import com.hai.entity.SecUserLabel;
import com.hai.entity.SecUserLabelExample;
import com.hai.service.SecUserLabelService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service("userLabelService")
public class SecUserLabelServiceImpl implements SecUserLabelService {

    @Resource
    private SecUserLabelMapper userLabelMapper;

    @Override
    public void edit(SecUserLabel userLabel) {
        if (userLabel.getId() == null) {
            userLabel.setCreateTime(new Date());
            userLabel.setStatus(1);
            userLabelMapper.insert(userLabel);
        } else {
            userLabelMapper.updateByPrimaryKey(userLabel);
        }
    }

    @Override
    public List<SecUserLabel> getLabelByUser(Long userId) {
        SecUserLabelExample example = new SecUserLabelExample();
        example.createCriteria().andUserIdEqualTo(userId).andStatusEqualTo(1);
        return userLabelMapper.selectByExample(example);
    }

    @Override
    public List<Map<String, Object>> getUserByCompanyAndLabel(Long companyId, Long labelId) {
        return userLabelMapper.selectUserByCompanyAndLabel(companyId,labelId);
    }
}
