package com.hfkj.service.spread.impl;

import com.hfkj.dao.BsUserSpreadRelMapper;
import com.hfkj.entity.BsUserSpreadRel;
import com.hfkj.entity.BsUserSpreadRelExample;
import com.hfkj.service.spread.BsUserSpreadRelService;
import org.springframework.stereotype.Service;

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

/**
 * @className: BsUserSpreadRelServiceImpl
 * @author: HuRui
 * @date: 2025/3/31
 **/
@Service("userSpreadRelService")
public class BsUserSpreadRelServiceImpl implements BsUserSpreadRelService {
    @Resource
    private BsUserSpreadRelMapper userSpreadRelMapper;

    @Override
    public void editData(BsUserSpreadRel data) {
        data.setUpdateTime(new Date());
        if (data.getId() == null) {
            data.setCreateTime(new Date());
            data.setStatus(1);
            userSpreadRelMapper.insert(data);
        } else {
            userSpreadRelMapper.updateByPrimaryKey(data);
        }
    }

    @Override
    public BsUserSpreadRel getDetailByUser(Long userId) {
        BsUserSpreadRelExample example = new BsUserSpreadRelExample();
        example.createCriteria().andUserIdEqualTo(userId).andStatusNotEqualTo(0);
        List<BsUserSpreadRel> list = userSpreadRelMapper.selectByExample(example);
        if (!list.isEmpty()) {
            return list.get(0);
        }
        return null;
    }

    @Override
    public List<HashMap<String,Object>> getTeamList(Map<String, Object> param) {
        return userSpreadRelMapper.getTeamList(param);
    }

    @Override
    public List<HashMap<String, Object>> getUserSpreadList(Map<String, Object> param) {
        return userSpreadRelMapper.getUserSpreadList(param);
    }
}
