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.GridShapeCountLingshou;
import com.ruoyi.ibs.grid.domain.entity.GridShapeCustGongsi;
import com.ruoyi.ibs.grid.domain.entity.GridShapeCustLingshou;
import com.ruoyi.ibs.grid.domain.entity.GridVirtualCustGongsi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.ibs.grid.mapper.GridShapeCountMapper;
import com.ruoyi.ibs.grid.domain.entity.GridShapeCountGongsi;
import com.ruoyi.ibs.grid.service.IGridShapeCountService;

/**
 * 自定义地图网格汇总统计_公司Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-05-08
 */
@Service
public class GridShapeCountServiceImpl implements IGridShapeCountService
{
    @Autowired
    private GridShapeCountMapper gridShapeCountGongsiMapper;

    /**
     * 查询自定义地图网格汇总统计_公司
     * 
     * @param dt 自定义地图网格汇总统计_公司主键
     * @return 自定义地图网格汇总统计_公司
     */
    @Override
    public GridShapeCountGongsi selectGridShapeCountGongsiByDt(String dt)
    {
        return gridShapeCountGongsiMapper.selectGridShapeCountGongsiByDt(dt);
    }

    /**
     * 查询自定义地图网格汇总统计_公司列表
     * @return 自定义地图网格汇总统计_公司
     */
    @Override
    public List<GridShapeCountGongsi> selectGridShapeCountGongsiList(String shapeType ,String shapeName, String gridName,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("shapeType",shapeType);
        paramMap.put("shapeName",shapeName);
        paramMap.put("dt",dt);

//        return GridVirtualCountMapper.selectGridVirtualCountLingshouList(paramMap);
        return gridShapeCountGongsiMapper.selectGridShapeCountGongsiList(paramMap);
    }


    @Override
    public List<GridShapeCountLingshou> selectGridShapeCountLingshouList(String shapeType , String shapeName, String gridName,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("shapeType",shapeType);
        paramMap.put("shapeName",shapeName);
        paramMap.put("dt",dt);

//        return GridVirtualCountMapper.selectGridVirtualCountLingshouList(paramMap);
        return gridShapeCountGongsiMapper.selectGridShapeCountLingshouList(paramMap);
    }

    public List<GridShapeCustGongsi> selectGridShapeCountgsCustList(String shapeId , String custName, String socialCreditCode,String dt){
        HashMap<String, Object> paramMap = new HashMap<>();
        paramMap.put("deptId",SecurityUtils.getDeptId());
        paramMap.put("userName",SecurityUtils.getUsername());
        paramMap.put("shapeId",shapeId);
        paramMap.put("custName",custName);
        paramMap.put("socialCreditCode",socialCreditCode);
        paramMap.put("dt",dt);

        return gridShapeCountGongsiMapper.selectGridShapeCountgsCustList(paramMap);
    }

    public List<GridShapeCustLingshou> selectGridShapeCountlsCustList(String shapeId , String custName, String custIdc,String dt){
        HashMap<String, Object> paramMap = new HashMap<>();
        paramMap.put("deptId",SecurityUtils.getDeptId());
        paramMap.put("userName",SecurityUtils.getUsername());
        paramMap.put("shapeId",shapeId);
        paramMap.put("custName",custName);
        paramMap.put("custIdc",custIdc);
        paramMap.put("dt",dt);

        return gridShapeCountGongsiMapper.selectGridShapeCountlsCustList(paramMap);
    }

    /**
     * 新增自定义地图网格汇总统计_公司
     * 
     * @param gridShapeCountGongsi 自定义地图网格汇总统计_公司
     * @return 结果
     */
    @Override
    public int insertGridShapeCountGongsi(GridShapeCountGongsi gridShapeCountGongsi)
    {
        return gridShapeCountGongsiMapper.insertGridShapeCountGongsi(gridShapeCountGongsi);
    }

    /**
     * 修改自定义地图网格汇总统计_公司
     * 
     * @param gridShapeCountGongsi 自定义地图网格汇总统计_公司
     * @return 结果
     */
    @Override
    public int updateGridShapeCountGongsi(GridShapeCountGongsi gridShapeCountGongsi)
    {
        return gridShapeCountGongsiMapper.updateGridShapeCountGongsi(gridShapeCountGongsi);
    }

    /**
     * 批量删除自定义地图网格汇总统计_公司
     * 
     * @param dts 需要删除的自定义地图网格汇总统计_公司主键
     * @return 结果
     */
    @Override
    public int deleteGridShapeCountGongsiByDts(String[] dts)
    {
        return gridShapeCountGongsiMapper.deleteGridShapeCountGongsiByDts(dts);
    }

    /**
     * 删除自定义地图网格汇总统计_公司信息
     * 
     * @param dt 自定义地图网格汇总统计_公司主键
     * @return 结果
     */
    @Override
    public int deleteGridShapeCountGongsiByDt(String dt)
    {
        return gridShapeCountGongsiMapper.deleteGridShapeCountGongsiByDt(dt);
    }
}
