package cn.com.ctop.common.module.service.impl;

import cn.com.ctop.common.module.entity.RuleDataAccount;
import cn.com.ctop.common.module.entity.RuleDataCreative;
import cn.com.ctop.common.module.entity.RuleDataPlan;
import cn.com.ctop.common.module.entity.RuleDataTarget;
import cn.com.ctop.common.module.mapper.RuleDataAccountMapper;
import cn.com.ctop.common.module.mapper.RuleDataCreativeMapper;
import cn.com.ctop.common.module.mapper.RuleDataPlanMapper;
import cn.com.ctop.common.module.mapper.RuleDataTargetMapper;
import cn.com.ctop.common.module.service.IRuleDataAccountService;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xxl.job.core.enums.NoEn;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

/**
 * 规则账户清洗数据
 *
 * @author jeecg-boot
 * @version V1.0
 * @date 2020-11-16
 */
@Service
public class RuleDataAccountServiceImpl extends ServiceImpl<RuleDataAccountMapper, RuleDataAccount> implements IRuleDataAccountService {

    @Autowired
    private RuleDataAccountMapper ruleDataAccountMapper;

    @Autowired
    private RuleDataPlanMapper ruleDataPlanMapper;

    @Autowired
    private RuleDataTargetMapper ruleDataTargetMapper;

    @Autowired
    private RuleDataCreativeMapper ruleDataCreativeMapper;

    @Override
    public JSONObject getRuleDataByAccountId(Long accountId) {
        JSONObject obj = new JSONObject();
        Map<String, Object> map = new HashMap<>();
        map.put("account_id", accountId);
        map.put("status", NoEn.NO1.valueInt());
        List<RuleDataAccount> ruleDataAccounts = ruleDataAccountMapper.selectByMap(map);
        obj.put("account", ruleDataAccounts);
        List<RuleDataPlan> ruleDataPlans = ruleDataPlanMapper.selectByMap(map);
        obj.put("plan", ruleDataPlans);
        List<RuleDataTarget> ruleDataTargets = ruleDataTargetMapper.selectByMap(map);
        obj.put("target", ruleDataTargets);
        List<RuleDataCreative> ruleDataCreatives = ruleDataCreativeMapper.selectByMap(map);
        obj.put("creative", ruleDataCreatives);
        return obj;
    }
}
