package com.xhpc.user.service.impl;

import com.xhpc.common.core.constant.StatusConstants;
import com.xhpc.common.core.utils.StringUtils;
import com.xhpc.user.domain.XhpcOperatorInternetBlacklist;
import com.xhpc.user.mapper.XhpcInternetUserMapper;
import com.xhpc.user.mapper.XhpcOperatorInternetBlacklistMapper;
import com.xhpc.user.service.IXhpcOperatorInternetBlacklistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * 流量用户信息 服务层
 *
 * @author ruoyi
 */
@Service
public class XhpcOperatorInternetBlacklistServiceImpl implements IXhpcOperatorInternetBlacklistService {

    @Autowired
    private XhpcOperatorInternetBlacklistMapper xhpcOperatorInternetBlacklistMapper;

    @Autowired
    private XhpcInternetUserMapper xhpcInternetUserMapper;

    /**
     * 新增任务
     *
     * @param xhpcOperatorInternetBlacklist 流量用户信息
     */
    @Override
    @Transactional
    public int insert(XhpcOperatorInternetBlacklist xhpcOperatorInternetBlacklist) {
        return xhpcOperatorInternetBlacklistMapper.insert(xhpcOperatorInternetBlacklist);
    }


    /**
     * 批量删除流量用户信息
     *
     * @param operatorId 需要删除的运营商ID
     * @return 结果
     */
    @Override
    @Transactional
    public void deleteByIds(Long operatorId) {
        xhpcOperatorInternetBlacklistMapper.deleteByIds(operatorId);
    }


    /**
     * 流量用户列表
     *
     * @param operatorId 运营商ID
     * @return 结果
     */
    @Override
    public List<Map<String, Object>> list(String operatorId) {
        List<Map<String, Object>> list = xhpcInternetUserMapper.list(null);
        if (null != list && list.size() > 0) {
            List<Map<String, Object>> blacklist = xhpcOperatorInternetBlacklistMapper.list(Long.parseLong(operatorId));
            boolean bool = false;
            if (null != blacklist && blacklist.size() > 0) {
                bool = true;
            }
            for (Map<String, Object> map : list) {
                map.put("isBlack", StatusConstants.IS_BLACK);
                if (bool) {
                    for (Map<String, Object> map1 : blacklist) {
                        String internetUserId = StringUtils.valueOf(map.get("internetUserId"));
                        String internetUserId1 = StringUtils.valueOf(map1.get("internetUserId"));
                        if (internetUserId.equals(internetUserId1)) {
                            map.put("isBlack", StatusConstants.BLACK);
                        }
                    }
                }
            }
        }
        return list;
    }
}
