package com.hfkj.service.impl;

import com.hfkj.channel.lakala.LaKaLaMerService;
import com.hfkj.common.utils.RedisUtil;
import com.hfkj.dao.BsLklMccMapper;
import com.hfkj.entity.BsLklMcc;
import com.hfkj.entity.BsLklMccExample;
import com.hfkj.service.BsLklMccService;
import org.springframework.stereotype.Service;

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

@Service("lklMccService")
public class BsLklMccServiceImpl implements BsLklMccService {

    @Resource
    private BsLklMccMapper lklMccMapper;

    @Resource
    private RedisUtil redisUtil;

    @Override
    public List<BsLklMcc> getMccList() {
        Object mccList = redisUtil.get("MCC_DATA");
        if (mccList != null) {
            return (List<BsLklMcc>) mccList;
        }

        // mcc大类
        BsLklMccExample parentMccExample = new BsLklMccExample();
        parentMccExample.createCriteria().andParentIdIsNull().andStatusNotEqualTo(0);
        List<BsLklMcc> parentMccList = lklMccMapper.selectByExample(parentMccExample);
        for (BsLklMcc parentMcc : parentMccList) {
            // mcc小类
            BsLklMccExample childMccExample = new BsLklMccExample();
            childMccExample.createCriteria().andParentIdEqualTo(parentMcc.getId()).andStatusNotEqualTo(0);
            parentMcc.setChildLklMccList(lklMccMapper.selectByExample(childMccExample));
        }
        redisUtil.set("MCC_DATA", parentMccList);
        return parentMccList;
    }

    @Override
    public BsLklMcc getMccByCode(String code) {
        BsLklMccExample example = new BsLklMccExample();
        example.createCriteria().andMaccCodeEqualTo(code).andStatusNotEqualTo(0);
        List<BsLklMcc> list = lklMccMapper.selectByExample(example);
        if (list.size() > 0) {
            return list.get(0);
        }
        return null;
    }

    @Override
    public void insert(BsLklMcc lklMcc) {
        lklMccMapper.insert(lklMcc);
    }
}
