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

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

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.ibs.grid.domain.entity.GridVirtualCountGongsi;
import com.ruoyi.ibs.grid.domain.entity.GridVirtualCountLingshou;
import com.ruoyi.ibs.grid.domain.entity.GridVirtualCustGongsi;
import com.ruoyi.ibs.grid.domain.entity.GridVirtualCustLingshou;
import com.ruoyi.ibs.grid.service.IGridVirtualCountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.ibs.grid.mapper.GridVirtualCountMapper;

/**
 * 虚拟网格汇总统计_零售Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-04-24
 */
@Service
public class GridVirtualCountServiceImpl implements IGridVirtualCountService
{
    @Autowired
    private GridVirtualCountMapper GridVirtualCountMapper;

    /**
     * 查询虚拟网格汇总统计_零售
     * 
     * @param dt 虚拟网格汇总统计_零售主键
     * @return 虚拟网格汇总统计_零售
     */
    @Override
    public GridVirtualCountLingshou selectGridVirtualCountLingshouByDt(String dt)
    {
        return GridVirtualCountMapper.selectGridVirtualCountLingshouByDt(dt);
    }

    /**
     * 查询虚拟网格汇总统计_零售列表
     */
    @Override
    public List<GridVirtualCountLingshou> selectGridVirtualCountLingshouList(String gridName ,String gridType,String dt)
    {
        HashMap<String, Object> paramMap = new HashMap<>();
        if(SecurityUtils.userRole().equals("head") || SecurityUtils.userRole().equals("public") || SecurityUtils.userRole().equals("private") ||SecurityUtils.userRole().equals("ops")){
            paramMap.put("isHead",true);
        }
        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("gridName",gridName);
        paramMap.put("gridType",gridType);
        paramMap.put("dt",dt);

        return GridVirtualCountMapper.selectGridVirtualCountLingshouList(paramMap);
    }

    @Override
    public List<GridVirtualCountGongsi> selectGridVirtualCountGongsiList(String gridName , String gridType,String dt)
    {
        HashMap<String, Object> paramMap = new HashMap<>();
        if(SecurityUtils.userRole().equals("head") || SecurityUtils.userRole().equals("public") || SecurityUtils.userRole().equals("private") ||SecurityUtils.userRole().equals("ops")){
            paramMap.put("isHead",true);
        }
        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("gridName",gridName);
        paramMap.put("gridType",gridType);
        paramMap.put("dt",dt);

        return GridVirtualCountMapper.selectGridVirtualCountGongsiList(paramMap);
    }

    public List<GridVirtualCustGongsi> selectGridVirtualCountgsCustList(String gridId , 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("gridId",gridId);
        paramMap.put("custName",custName);
        paramMap.put("socialCreditCode",socialCreditCode);
        paramMap.put("dt",dt);

        return GridVirtualCountMapper.selectGridVirtualCountgsCustList(paramMap);
    }


    public List<GridVirtualCustLingshou> selectGridVirtualCountlsCustList(String gridId , String custName, String custIdc,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("gridId",gridId);
        paramMap.put("custName",custName);
        paramMap.put("custIdc",custIdc);
        paramMap.put("dt",dt);

        return GridVirtualCountMapper.selectGridVirtualCountlsCustList(paramMap);
    }

    /**
     * 新增虚拟网格汇总统计_零售
     * 
     * @param GridVirtualCountLingshou 虚拟网格汇总统计_零售
     * @return 结果
     */
    @Override
    public int insertGridVirtualCountLingshou(GridVirtualCountLingshou GridVirtualCountLingshou)
    {
        return GridVirtualCountMapper.insertGridVirtualCountLingshou(GridVirtualCountLingshou);
    }

    /**
     * 修改虚拟网格汇总统计_零售
     * 
     * @param GridVirtualCountLingshou 虚拟网格汇总统计_零售
     * @return 结果
     */
    @Override
    public int updateGridVirtualCountLingshou(GridVirtualCountLingshou GridVirtualCountLingshou)
    {
        return GridVirtualCountMapper.updateGridVirtualCountLingshou(GridVirtualCountLingshou);
    }

    /**
     * 批量删除虚拟网格汇总统计_零售
     * 
     * @param dts 需要删除的虚拟网格汇总统计_零售主键
     * @return 结果
     */
    @Override
    public int deleteGridVirtualCountLingshouByDts(String[] dts)
    {
        return GridVirtualCountMapper.deleteGridVirtualCountLingshouByDts(dts);
    }

    /**
     * 删除虚拟网格汇总统计_零售信息
     * 
     * @param dt 虚拟网格汇总统计_零售主键
     * @return 结果
     */
    @Override
    public int deleteGridVirtualCountLingshouByDt(String dt)
    {
        return GridVirtualCountMapper.deleteGridVirtualCountLingshouByDt(dt);
    }
}
