package com.sifang.modules.account.service;

import com.jfinal.plugin.activerecord.Record;
import com.sifang.modules.account.dao.TraderAccountSettleDetailDao;
import com.sifang.modules.sunshine.SystemSetting.entity.CrmTrader;
import com.sifang.modules.sunshine.SystemSetting.service.TraderService;
import com.sifang.modules.sys.common.UserUtils;
import com.sifang.modules.sys.common.entity.User;
import com.sifang.modules.sys.common.utils.StringUtil;
import com.sifang.modules.sys.util.CrmUtils;
import com.sifang.modules.sys.util.LayuiPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

@Service
public class TraderAccountSettleDetailService {

    @Autowired
    private TraderAccountSettleDetailDao settleDetailDao;

    @Autowired
    TraderService traderService;

    public void listSettleDetail(Map<String, String> queryParams, LayuiPage page){
        User user= UserUtils.getUser();
        String traderId="";
        if(User.USER_TYPE_KJ.equals(user.getUserType())){  //代理商
            traderId = CrmUtils.getUserRelId(user);
        }else if(User.USER_TYPE_ADVISOR.equals(user.getUserType())){  //代理商人员
            traderId = CrmUtils.getUserRelId(user);
        }if(User.USER_TYPE_WXG.equals(user.getUserType())){
            //平台人员
            //获取当前人员所负责代理商
            Record rd = CrmUtils.getByUserId(user);
            String trader_id=rd.getStr("trader_id");
            if(StringUtil.isNotBlank(trader_id)){
               traderId=trader_id;
            }
        }
        queryParams.put("traderIds",traderId);
        List<Record> list = settleDetailDao.listSettleDetails(queryParams, page);
        Long count = settleDetailDao.countSettleDetails(queryParams);
        page.setData(list);
        page.setCount(count);
    }

}
