package com.ruoyi.group.service.impl;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.group.domain.entity.GroupCmpmCountGongsi825;
import com.ruoyi.group.domain.entity.GroupCmpmCountLingshou825;
import com.ruoyi.group.domain.entity.GroupCustCountGongsi825;
import com.ruoyi.group.domain.entity.GroupCustCountLingshou825;
import com.ruoyi.group.mapper.GroupPerformanceMapper;
import com.ruoyi.group.service.IGroupPerformanceService;
import org.springframework.stereotype.Service;

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

@Service
public class GroupPerformanceServiceImpl implements IGroupPerformanceService {

    @Resource
    private GroupPerformanceMapper groupPerformanceMapper;

    @Override
    public List<GroupCmpmCountLingshou825> selectLsCountList(String dt, String groupName) {
        return groupPerformanceMapper.selectLsCountList(buildLsCountParams(dt, groupName));
    }

    private HashMap<String, Object> buildLsCountParams(String dt, String groupName) {
        HashMap<String, Object> paramMap = new HashMap<>();
        if (SecurityUtils.userRole().equals("branch")) {
            paramMap.put("isBranch", true);
        }
        if (SecurityUtils.userRole().equals("outlet")) {
            paramMap.put("isOutlet", true);
        }
        if (SecurityUtils.userRole().equals("manager")) {
            paramMap.put("isManager", true);
        }
        paramMap.put("deptId", SecurityUtils.getDeptId());
        paramMap.put("userName", SecurityUtils.getUsername());
        paramMap.put("dt", dt);
        paramMap.put("groupName", groupName);
        return paramMap;
    }

    @Override
    public List<GroupCmpmCountGongsi825> selectGsCountList(String dt, String groupName) {
        HashMap<String, Object> paramMap = new HashMap<>();
        paramMap.put("userRole", "head");
        if (SecurityUtils.userRole().equals("branch")) {
            paramMap.put("userRole", "branch");
            paramMap.put("isBranch", true);
        }
        if (SecurityUtils.userRole().equals("outlet")) {
            paramMap.put("userRole", "outlet");
            paramMap.put("isOutlet", true);
        }
        if (SecurityUtils.userRole().equals("manager")) {
            paramMap.put("userRole", "manager");
            paramMap.put("isManager", true);
        }
        paramMap.put("deptId", SecurityUtils.getDeptId());
        paramMap.put("userName", SecurityUtils.getUsername());
        paramMap.put("dt", dt);
        paramMap.put("groupName", groupName);
        return groupPerformanceMapper.selectGsCountList(paramMap);
    }

    @Override
    public List<GroupCustCountLingshou825> selectLsCustList(String groupId, String custName, String custIdc, String dt) {
        return groupPerformanceMapper.selectLsCustList(buildLsCustParams(groupId, custName, custIdc, dt));
    }

    private HashMap<String, Object> buildLsCustParams(String groupId, String custName, String custIdc, String dt) {
        HashMap<String, Object> paramMap = new HashMap<>();
        paramMap.put("deptId", SecurityUtils.getDeptId());
        paramMap.put("userName", SecurityUtils.getUsername());
        paramMap.put("groupId", groupId);
        paramMap.put("custName", custName);
        paramMap.put("custIdc", custIdc);
        paramMap.put("dt", dt);
        return paramMap;
    }

    @Override
    public List<GroupCustCountGongsi825> selectGsCustList(String groupId, String custName, String socialCreditCode, String dt) {
        HashMap<String, Object> paramMap = new HashMap<>();
        if (SecurityUtils.userRole().equals("branch")) {
            paramMap.put("isBranch", true);
        }
        if (SecurityUtils.userRole().equals("outlet")) {
            paramMap.put("isOutlet", true);
        }
        if (SecurityUtils.userRole().equals("manager")) {
            paramMap.put("isManager", true);
        }
        paramMap.put("deptId", SecurityUtils.getDeptId());
        paramMap.put("userName", SecurityUtils.getUsername());
        paramMap.put("groupId", groupId);
        paramMap.put("custName", custName);
        paramMap.put("socialCreditCode", socialCreditCode);
        paramMap.put("dt", dt);
        return groupPerformanceMapper.selectGsCustList(paramMap);
    }
}
