package com.ruoyi.ibs.grid.service.impl;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.ibs.grid.domain.entity.GridCmpmCountGongsi;
import com.ruoyi.ibs.grid.domain.entity.GridCmpmCountLingshou;
import com.ruoyi.ibs.grid.domain.entity.GridCustCountGongsi;
import com.ruoyi.ibs.grid.domain.entity.GridCustCountLingshou;
import com.ruoyi.ibs.grid.mapper.GridCountMapper;
import com.ruoyi.ibs.grid.service.GridCountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

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

@Service
public class GridCountServiceimpl implements GridCountService {

    @Autowired
    private GridCountMapper mapper;

    @Override
    public List<GridCmpmCountLingshou> selectLsCountList(String town,String village,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("town",town);
        paramMap.put("village",village);
        paramMap.put("dt",dt);
        return mapper.selectLsCountList(paramMap);
    }

    @Override
    public List<GridCmpmCountGongsi> selectGsCountList(String town, String village,String dt) {
        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("town",town);
        paramMap.put("village",village);
        paramMap.put("dt",dt);
        return mapper.selectGsCountList(paramMap);
    }

    @Override
    public List<GridCustCountLingshou> selectLsCustList(String regionCode, String custName, String custIdc,String dt) {
        HashMap<String, Object> paramMap = new HashMap<>();
        paramMap.put("deptId",SecurityUtils.getDeptId());
        paramMap.put("userName",SecurityUtils.getUsername());
        paramMap.put("regionCode",regionCode);
        paramMap.put("custName",custName);
        paramMap.put("custIdc",custIdc);
        paramMap.put("dt",dt);
        return mapper.selectLsCustList(paramMap);
    }

    @Override
    public List<GridCustCountGongsi> selectGsCustList(String regionCode, 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("regionCode",regionCode);
        paramMap.put("custName",custName);
        paramMap.put("socialCreditCode",socialCreditCode);
        paramMap.put("dt",dt);
        return mapper.selectGsCustList(paramMap);
    }
}
