package com.bofeng.service;

import com.bofeng.dao.SubUserMapper;
import com.bofeng.entity.SubUser;
import com.yvan.platform.Conv;
import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(readOnly = true)
public class SubUserService {

    @Autowired
    private SubUserMapper subUserMapper;

    public List<SubUser> getSubUserByCurrentUserId(Long userId) {

        //获取人员信息
        List<SubUser> subUserList = subUserMapper.getSubUserByCurrentUserId(userId);

        //获取未结算订单佣金
        val cmsList = subUserMapper.getSubUserCms(userId);

        //填充数据
        for (val cms : cmsList) {
            val id = Conv.NL(cms.get("sale_user_id"));
            for (val subUser : subUserList) {
                if (subUser.getUserId().equals(id)) {
                    subUser.setOrderCount(Conv.NI(cms.get("orderCount")));
                    subUser.setTotalCommission(Conv.NDec(cms.get("totalCommission")));
                }
            }
        }

        return subUserList;
    }
}
