package com.dk.mdm.service.common;

import com.alibaba.fastjson.JSONObject;
import com.dk.common.infrastructure.constant.Constant;
import com.dk.common.infrastructure.enums.ErrorCodeEnum;
import com.dk.common.mapper.BaseMapper;
import com.dk.common.model.pojo.PageList;
import com.dk.common.model.vo.core.StaffEntity;
import com.dk.common.response.ResponseCodeEnum;
import com.dk.common.response.ResponseResultUtil;
import com.dk.common.response.ResponseResultVO;
import com.dk.common.service.BaseService;
import com.dk.mdm.mapper.common.CommonMapper;
import com.dk.mdm.infrastructure.util.AuthUtils;
import com.dk.mdm.mapper.mst.StaffMapper;
import com.dk.common.model.response.mst.StaffResponse;
import com.dk.mdm.model.pojo.mst.Staff;
import lombok.extern.slf4j.Slf4j;
import org.postgresql.util.PGobject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;

/**
 * @author : 周兴
 * @desc : 控件数据源API
 * @date : 2023/1/3 17:21
 */
@Service
@Slf4j
public class CommonService extends BaseService<Map<String, Object>> {
    @Override
    public BaseMapper<Map<String, Object>> getRepository() {
        return commonMapper;
    }

    @Autowired
    private CommonMapper commonMapper;

    @Autowired
    private StaffMapper staffMapper;

    @Autowired
    private AuthUtils authUtils;

    /**
     * @desc : 获取编码/单号
     * @author : 周兴
     * @date : 2024/3/1 11:41
     */
    public Map<String, Object> getUniqueNoteCode(String docName, Boolean codeFlag) {
        Map<String, Object> param = new HashMap<>();
        param.put("docName", docName);
        // 公司Id
        StaffEntity staff = authUtils.getStaff();
        param.put("cpId", staff.getCpId());
        Map<String, Object> map = null;
        // 获取系统基础数据
        if (codeFlag) {
            map = commonMapper.getUniqueCode(param);
        } else {
            map = commonMapper.getUniqueNote(param);
        }
        return map;
    }

    /**
     * @desc : 获取编码/单号
     * @author : 周兴
     * @date : 2024/3/1 11:41
     */
    public Map<String, Object> getUniqueNoteCode(String docName, Integer cpId, Boolean codeFlag) {
        Map<String, Object> param = new HashMap<>();
        param.put("docName", docName);
        // 公司Id
//        StaffEntity staff = authUtils.getStaff();
        param.put("cpId", cpId);
        Map<String, Object> map = null;
        // 获取系统基础数据
        if (codeFlag) {
            map = commonMapper.getUniqueCode(param);
        } else {
            map = commonMapper.getUniqueNote(param);
        }
        return map;
    }

    /**
     * @desc : 获取数据字典项目
     * @author : 王英杰
     * @date : 2023/1/6 11:41
     */
    public ResponseResultVO<List<Map<String, Object>>> getDictionaryItemData(Map<String, Object> param) {
        // 获取系统基础数据
        List<Map<String, Object>> list = commonMapper.getDictionaryItemData(param);
        return ResponseResultUtil.success(list);
    }

    /**
     * @desc : 刷新基础数据
     * @author : 周兴
     * @date : 2023/5/11 10:19
     */
    public ResponseResultVO refreshBasicData(Map<String, Object> param) {
        return null;
//        UserVO user = authUtils.getUser();
//        if (param.get("appCode") != null) {
//            user.setAppCode(param.get("appCode").toString());
//        }
//        Map userMap = new HashMap();
//        userMap.put("userId", user.getUserId());
//        userMap.put("appCode", user.getAppCode());
//        return ResponseResultUtil.success(new HashMap<String, Object>(3) {{
//            put("menu", commonMapper.getMenuByUser(user.getAppCode(), user.getUserId()));
//            put("function", (user.getRoleIds() != null && user.getRoleIds().indexOf(-1) >= 0)
//                    ? commonMapper.getUserFunctionAdmin(userMap) : commonMapper.getUserFunction(userMap));
//            put("userTableSetting", commonMapper.getUserTableInfo(userMap));
//        }});
    }

    /**
     * @desc : 获取序号最大值
     * @author : 周兴
     * @date : 2023/1/6 11:41t_user_right
     */
    public Integer getMaxDisplayNo(Constant.DisplayNoTable displayNoTable, Map<String, Object> param) {
        if (param == null) {
            param = new HashMap<>();
        }
        param.put("cpId", authUtils.getStaff().getCpId());
        String table = displayNoTable.getTable();
        String mode = displayNoTable.getMode();
        if (table != null && mode != null) {
            table = mode + "." + table;
            param.put("table", table);
            // 默认有效标识为true
            if(param.get("noFlgValid") == null && param.get("flgValid") == null ){
                param.put("flgValid",true);
            }
            // 获取最大序号
            Integer maxDisplayNo = commonMapper.getMaxDisplayNo(param);
            return maxDisplayNo == null ? 1 : maxDisplayNo;
        }
        return 0;
    }

    /**
     * @desc : 获取序号最大值
     * @author : 周兴
     * @date : 2023/1/6 11:41t_user_right
     */
    public Integer getMaxDisplayNo(Constant.DisplayNoTable displayNoTable) {
        return getMaxDisplayNo(displayNoTable, null);
    }

    /**
     * @desc : 获取系统表数据种类
     * @author : 周兴
     * @date : 2023/1/6 11:41
     */
    public ResponseResultVO<List<Map<String, Object>>> getDataKind(Map<String, Object> param) {
        // 获取系统基础数据
        List<Map<String, Object>> list = commonMapper.getDataKind(param);
        return ResponseResultUtil.success(list);
    }

    /**
     * @desc : 获取组织部门
     * @author : 姜宁
     * @date : 2023/1/9 13:50
     */
    public ResponseResultVO<List<Map<String, Object>>> getOrg(Map<String, Object> param) {
        // 获取系统基础数据
        List<Map<String, Object>> list = commonMapper.getOrg(param);
        return ResponseResultUtil.success(list);
    }
    /**
     * @desc : 只获取二级部门 按照level_code 排序
     * @author : 王英杰
     * @date : 2023/1/9 13:49
     */
    public ResponseResultVO<List<Map<String, Object>>> getProcureOrg(Map<String, Object> param) {
        // 获取系统基础数据
        List<Map<String, Object>> list = commonMapper.getProcureOrg(param);
        return ResponseResultUtil.success(list);
    }
    /**
     * @desc : 获取部门
     * @author : 姜宁
     * @date : 2023/1/29 17:01
     */
    public ResponseResultVO<PageList<Map<String, Object>>> getOrgByPage(Map<String, Object> param) {
        // 校验分页参数
        if (param.get("pageSize") == null || param.get("currentPage") == null) {
            return ResponseResultUtil.error(ResponseCodeEnum.OPERATE_FAIL, "请检查分页参数!");
        }
        // 分页参数赋值
        param = this.getLimit(param);
        return super.mergeListWithCount(param, commonMapper.getOrg(param),
                commonMapper.getOrgCountByPage(param));
    }

    /**
     * @desc : 获取角色
     * @author : 姜宁
     * @date : 2023/1/29 14:28
     */
    public ResponseResultVO<List<Map<String, Object>>> getRole(Map<String, Object> param) {
        // 获取系统基础数据
        List<Map<String, Object>> list = commonMapper.getRole(param);
        return ResponseResultUtil.success(list);
    }

    /**
     * @desc : 获取员工信息
     * @author : 周兴
     * @date : 2023/2/2 13:11
     */
    public ResponseResultVO<List<Map<String, Object>>> getStaff(Map<String, Object> param) {
        // 获取员工
        List<Map<String, Object>> list = commonMapper.getStaffByPage(param);
        return ResponseResultUtil.success(list);
    }

    /**
     * @desc : 获取员工
     * @author : 姜宁
     * @date : 2023/1/29 17:01
     */
    public ResponseResultVO<PageList<Map<String, Object>>> getStaffByPage(Map<String, Object> param) {
        // 校验分页参数
        if (param.get("pageSize") == null || param.get("currentPage") == null) {
            return ResponseResultUtil.error(ResponseCodeEnum.OPERATE_FAIL, "请检查分页参数!");
        }
        // 分页参数赋值
        param = this.getLimit(param);
        return super.mergeListWithCount(param, commonMapper.getStaffByPage(param),
                commonMapper.getStaffCountByPage(param));
    }

    /**
     * @desc : 查询系统参数
     * @author : 周兴
     * @date : 2023/1/29 17:04
     */
    public ResponseResultVO getSettingValue(Map<String, Object> param) {
        if (param.get("code").getClass().getName() == "java.util.ArrayList") {
            param.put("codes", param.get("code"));
            // 如果是数组，那么调用多个的查询
            Map<String, Map<String, String>> settingMap = commonMapper.getSettingValues(param);
            // 定义返回值
            JSONObject object = JSONObject.parseObject(((PGobject) settingMap.get("f_get_setting_values")).getValue());
            return ResponseResultUtil.success(object);
        } else {
            // 单个
            String setting = commonMapper.getSettingValue(param);
            // 定义返回值
            return ResponseResultUtil.success(setting);
        }
    }

    /**
     * @desc : 查询系统参数分类
     * @author : 夏常明
     * @date : 2023/1/30 16:05
     */
    public ResponseResultVO<List<Map<String, Object>>> getSettingKind(Map<String, Object> param) {
        // 获取系统基础数据
        List<Map<String, Object>> list = commonMapper.getSettingKind(param);
        return ResponseResultUtil.success(list);
    }

    /**
     * @desc : 设置分页参数
     * @author : 姜宁
     * @date : 2023/2/1 14:00
     */
    private Map<String, Object> getLimit(Map<String, Object> param) {
        if (param.get("limit") != null) {
            param.put("currentPage", 1);
            param.put("pageSize", param.get("limit"));
        }
        param.put("start", ((int) param.get("currentPage") - 1) * (int) param.get("pageSize"));
        param.put("end", param.get("pageSize"));
        // 公司Id
        StaffEntity staff = authUtils.getStaff();
        param.put("cpId", staff.getCpId());
        // 选择对象的时候用
        if (param.get("supplier-customerList")!=null
                && param.get("supplier-customerList")!=""
                && !(param.get("supplier-customerList") + "").contains(",") ){
            param.put("objType", Integer.parseInt(param.get("supplier-customerList").toString())   );
        }
        return param;
    }

    /**
     * @desc : 获取数据字典
     * @author : 姜宁
     * @date : 2023/2/7 14:47
     */
    public ResponseResultVO<List<Map<String, Object>>> getDictionaryData(Map<String, Object> param) {
        // 获取数据字典
        List<Map<String, Object>> list = commonMapper.getDictionaryData(param);
        return ResponseResultUtil.success(list);
    }

    /**
     * @desc : 获取用户隐藏列信息
     * @author : 周兴
     * @date : 2023/4/4 15:05
     */
    public ResponseResultVO<List<Map<String, Object>>> getUserTableInfo(Map<String, Object> param) {
        return ResponseResultUtil.success(commonMapper.getUserTableInfo(param));
    }

    /**
     * @desc : 获取用户功能
     * @author : 周兴
     * @date : 2023/4/4 15:05
     */
    public ResponseResultVO<List<Map<String, Object>>> getUserFunction(Map<String, Object> param) {
        return ResponseResultUtil.success(commonMapper.getUserFunction(param));
    }

    /**
     * @desc : 查导航菜单(自定义报表用)
     * @author : 周兴
     * @date : 2023/4/4 15:05
     */
    public ResponseResultVO<List<Map<String, Object>>> getMenuNavigation(Map<String, Object> param) {
        return ResponseResultUtil.success(commonMapper.getMenuNavigation(param));
    }

    /**
     * @desc : 获取数据类型
     * @author : 周兴
     * @date : 2023/6/2 11:01
     */
    public ResponseResultVO<List<Map<String, Object>>> getValueKind(Map<String, Object> param) {
        return ResponseResultUtil.success(commonMapper.getValueKind(param));
    }

    /**
     * @desc : 获取应用
     * @author : 洪旭东
     * @date : 2023-06-30 14:56
     */
    public ResponseResultVO<List<Map<String, String>>> getApplication() {
        return ResponseResultUtil.success(commonMapper.getApplication());
    }

    /**
     * @desc : 获取单据
     * @author : 周兴
     * @date : 2023/9/14 11:06
     */
    public ResponseResultVO<List<Map<String, Object>>> getDoc(Map<String, Object> param) {
        return ResponseResultUtil.success(commonMapper.getDoc(param));
    }

    /**
     * @desc : 获取商品
     * @author : 姜宁
     * @date : 2023/1/9 13:50
     */
    public ResponseResultVO<List<Map<String, Object>>> getGoods(Map<String, Object> param) {
        // 获取系统基础数据
        List<Map<String, Object>> list = commonMapper.getGoods(param);
        return ResponseResultUtil.success(list);
    }

    /**
     * @desc : 获取商品数量
     * @author : 姜宁
     * @date : 2023/1/29 17:01
     */
    public ResponseResultVO<PageList<Map<String, Object>>> getGoodsPage(Map<String, Object> param) {
        // 校验分页参数
        if (param.get("pageSize") == null || param.get("currentPage") == null) {
            return ResponseResultUtil.error(ResponseCodeEnum.OPERATE_FAIL, "请检查分页参数!");
        }
        // 分页参数赋值
        param = this.getLimit(param);
        return super.mergeListWithCount(param, commonMapper.getGoods(param),
                commonMapper.getGoodsCountByPage(param));
    }

    /**
     * @desc   : 获取商品（销售订单开单用）
     * @author : 付斌
     * @date   : 2024-03-09 9:57
     */
    public ResponseResultVO<List<Map<String, Object>>> getGoodsForOrder(Map<String, Object> param) {
        // 获取系统基础数据
        List<Map<String, Object>> list = commonMapper.getGoodsForOrder(param);
        return ResponseResultUtil.success(list);
    }

    /**
     * @desc   : 获取商品（销售订单开单用）（分页）
     * @author : 付斌
     * @date   : 2024-03-09 9:57
     */
    public ResponseResultVO<PageList<Map<String, Object>>> getGoodsForOrderByPage(Map<String, Object> param) {
        // 校验分页参数
        if (param.get("pageSize") == null || param.get("currentPage") == null) {
            return ResponseResultUtil.error(ResponseCodeEnum.OPERATE_FAIL, "请检查分页参数!");
        }
        // 分页参数赋值
        param = this.getLimit(param);
        return super.mergeListWithCount(param, commonMapper.getGoodsForOrder(param),
                commonMapper.getGoodsForOrderCountByPage(param));
    }


    /**
     * @desc   : 获取商品（采购订单开单用）
     * @author : 常皓宁
     * @date   : 2024/3/9 10:08
     */
    public ResponseResultVO<List<Map<String, Object>>> getGoodsForPurchase(Map<String, Object> param) {
        // 获取系统基础数据
        List<Map<String, Object>> list = commonMapper.getGoodsForPurchase(param);
        return ResponseResultUtil.success(list);
    }

    /**
     * @desc   : 获取商品（采购订单开单用）（分页）
     * @author : 常皓宁
     * @date   : 2024/3/9 10:08
     */
    public ResponseResultVO<PageList<Map<String, Object>>> getGoodsForPurchaseByPage(Map<String, Object> param) {
        // 校验分页参数
        if (param.get("pageSize") == null || param.get("currentPage") == null) {
            return ResponseResultUtil.error(ResponseCodeEnum.OPERATE_FAIL, "请检查分页参数!");
        }
        // 分页参数赋值
        param = this.getLimit(param);
        return super.mergeListWithCount(param, commonMapper.getGoodsForPurchase(param),
                commonMapper.getGoodsForPurchaseCountByPage(param));
    }


    /**
     * @desc : 获取客户
     * @author : 付斌
     * @date : 2024-03-09 9:55
     */
    public ResponseResultVO<List<Map<String, Object>>> getCustomer(Map<String, Object> param) {
        // 获取系统基础数据
        List<Map<String, Object>> list = commonMapper.getCustomer(param);
        return ResponseResultUtil.success(list);
    }

    /**
     * @desc : 获取客户（分页）
     * @author : 付斌
     * @date : 2024-03-09 9:55
     */
    public ResponseResultVO<PageList<Map<String, Object>>> GetCustomerByPage(Map<String, Object> param) {
        // 校验分页参数
        if (param.get("pageSize") == null || param.get("currentPage") == null) {
            return ResponseResultUtil.error(ResponseCodeEnum.OPERATE_FAIL, "请检查分页参数!");
        }
        // 分页参数赋值
        param = this.getLimit(param);
        return super.mergeListWithCount(param, commonMapper.getCustomer(param),
                commonMapper.getCustomerCountByPage(param));
    }

    /**
     * @desc : 获取供应商
     * @author : 常皓宁
     * @date : 2024/3/1 9:20
     */
    public ResponseResultVO<List<Map<String, Object>>> getSupplier(Map<String, Object> param) {
        // 获取公司
        List<Map<String, Object>> list = commonMapper.getSupplier(param);
        return ResponseResultUtil.success(list);
    }

    /**
     * @desc : 获取供应商（分页）
     * @author : 常皓宁
     * @date : 2024/3/1 9:20
     */
    public ResponseResultVO<PageList<Map<String, Object>>> getSupplierByPage(Map<String, Object> param) {
        // 校验分页参数
        if (param.get("pageSize") == null || param.get("currentPage") == null) {
            return ResponseResultUtil.error(ResponseCodeEnum.OPERATE_FAIL, "请检查分页参数!");
        }
        // 分页参数赋值
        param = this.getLimit(param);
        // 定义返回值
        PageList data = new PageList<>();
        // 获取供应商
        List<Map<String, Object>> list = commonMapper.getSupplier(param);
        // 获取总数量
        Long total = commonMapper.countSupplier(param);
        // 组装返回值
        data.setPageSize((int) param.get("pageSize")).setCurrentPage((int) param.get("currentPage")).setList(list).setTotal(total);
        return ResponseResultUtil.success(data);
    }

    /**
     * @desc : 获取渠道
     * @author : 付斌
     * @date : 2024-03-02 10:18
     */
    public ResponseResultVO<List<Map<String, Object>>> getChannel(Map<String, Object> param) {
        // 获取公司
        List<Map<String, Object>> list = commonMapper.getChannel(param);
        return ResponseResultUtil.success(list);
    }

    /**
     * @desc : 获取商品品牌（分页）
     * @author : 王英杰
     * @date : 2024/3/1 9:20
     */
    public ResponseResultVO<PageList<Map<String, Object>>> goodsBrandListBy(Map<String, Object> param) {
        // 校验分页参数
        if (param.get("pageSize") == null || param.get("currentPage") == null) {
            return ResponseResultUtil.error(ResponseCodeEnum.OPERATE_FAIL, "请检查分页参数!");
        }
        // 分页参数赋值
        param = this.getLimit(param);
        // 定义返回值
        PageList data = new PageList<>();
        // 获取公司
        List<Map<String, Object>> list = commonMapper.getGoodsBrand(param);
        // 获取总数量
        Long total = commonMapper.countGoodsBrand(param);
        // 组装返回值
        data.setPageSize((int) param.get("pageSize")).setCurrentPage((int) param.get("currentPage")).setList(list).setTotal(total);
        return ResponseResultUtil.success(data);
    }

    /**
     * @desc : 获取商品种类（分页）
     * @author : 王英杰
     * @date : 2024/3/1 9:20
     */
    public ResponseResultVO<PageList<Map<String, Object>>> goodsCategoryListBy(Map<String, Object> param) {
        // 校验分页参数
        if (param.get("pageSize") == null || param.get("currentPage") == null) {
            return ResponseResultUtil.error(ResponseCodeEnum.OPERATE_FAIL, "请检查分页参数!");
        }
        // 分页参数赋值
        param = this.getLimit(param);
        // 定义返回值
        PageList data = new PageList<>();
        // 获取公司
        List<Map<String, Object>> list = commonMapper.getGoodsCategory(param);
        // 获取总数量
        Long total = commonMapper.countGoodsCategory(param);
        // 组装返回值
        data.setPageSize((int) param.get("pageSize")).setCurrentPage((int) param.get("currentPage")).setList(list).setTotal(total);
        return ResponseResultUtil.success(data);
    }

    /**
     * @desc : 获取商品系列（分页）
     * @author : 王英杰
     * @date : 2024/3/1 9:20
     */
    public ResponseResultVO<PageList<Map<String, Object>>> goodsSeriesListBy(Map<String, Object> param) {
        // 校验分页参数
        if (param.get("pageSize") == null || param.get("currentPage") == null) {
            return ResponseResultUtil.error(ResponseCodeEnum.OPERATE_FAIL, "请检查分页参数!");
        }
        // 分页参数赋值
        param = this.getLimit(param);
        // 定义返回值
        PageList data = new PageList<>();
        // 获取公司
        List<Map<String, Object>> list = commonMapper.getGoodsSeries(param);
        // 获取总数量
        Long total = commonMapper.countGoodsSeries(param);
        // 组装返回值
        data.setPageSize((int) param.get("pageSize")).setCurrentPage((int) param.get("currentPage")).setList(list).setTotal(total);
        return ResponseResultUtil.success(data);
    }

    /**
     * @desc : 计量单位查询（分页）
     * @author : 王英杰
     * @date : 2024/3/1 9:20
     */
    public ResponseResultVO<PageList<Map<String, Object>>> unitListBy(Map<String, Object> param) {
        // 校验分页参数
        if (param.get("pageSize") == null || param.get("currentPage") == null) {
            return ResponseResultUtil.error(ResponseCodeEnum.OPERATE_FAIL, "请检查分页参数!");
        }
        // 分页参数赋值
        param = this.getLimit(param);
        // 定义返回值
        PageList data = new PageList<>();
        // 获取公司
        List<Map<String, Object>> list = commonMapper.getUnit(param);
        // 获取总数量
        Long total = commonMapper.countUnit(param);
        // 组装返回值
        data.setPageSize((int) param.get("pageSize")).setCurrentPage((int) param.get("currentPage")).setList(list).setTotal(total);
        return ResponseResultUtil.success(data);
    }

    /**
     * @desc : 获取仓库档案
     * @author : 王英杰
     * @date :2024/3/1 9:20
     */
    public ResponseResultVO<PageList<Map<String, Object>>> getWarehouseByPage(Map<String, Object> param) {
        this.getLimit(param);
        return super.mergeListWithCount(param, commonMapper.getWarehouseByPage(param),
                commonMapper.countWarehouseByPage(param));
    }

    /**
     * @desc : 获取仓库
     * @author : 常皓宁
     * @date : 2024/3/4 10:50
     */
    public ResponseResultVO<List<Map<String, Object>>> getWarehouse(Map<String, Object> param) {
        // 获取仓库
        List<Map<String, Object>> list = commonMapper.getWarehouse(param);
        return ResponseResultUtil.success(list);
    }

    /**
     * @desc : 查询库存
     * @author : 付斌
     * @date : 2024-03-05 10:52
     */
    public ResponseResultVO<List<Map<String, Object>>> getInventory(Map<String, Object> param) {
        // 获取系统基础数据
        List<Map<String, Object>> list = commonMapper.getInventory(param);
        return ResponseResultUtil.success(list);
    }

    /**
     * @desc : 查询库存 返回数组 条件数组
     * @author : 付斌
     * @date : 2024-03-05 10:52
     */
    public ResponseResultVO<List<Map<String, Object>>> getInventoryByList(Map<String, Object> param) {
        // 获取系统基础数据
        List<Map<String, Object>> list = commonMapper.getInventoryByList(param);
        return ResponseResultUtil.success(list);
    }

    /**
     * @desc : 查询库存（分页）
     * @author : 付斌
     * @date : 2024-03-05 10:52
     */
    public ResponseResultVO<PageList<Map<String, Object>>> getInventoryByPage(Map<String, Object> param) {
        // 校验分页参数
        if (param.get("pageSize") == null || param.get("currentPage") == null) {
            return ResponseResultUtil.error(ResponseCodeEnum.OPERATE_FAIL, "请检查分页参数!");
        }
        // 分页参数赋值
        param = this.getLimit(param);
        return super.mergeListWithCount(param, commonMapper.getInventory(param),
                commonMapper.getInventoryCountByPage(param));
    }

    /**
     * @desc :  商品种类查询
     * @author : 于继渤
     * @date : 2024/2/26 10:36
     */
    public ResponseResultVO<List<Map<String, Object>>> getGoodsCategoryNoPage(Map<String, Object> param) {
        List<Map<String, Object>> list = commonMapper.getGoodsCategory(param);
        return ResponseResultUtil.success(list);
    }    /**
     * @desc :  商品种类查询  树形
     * @author : 王英杰
     * @date : 2024/2/26 10:36
     */
    public ResponseResultVO<List<Map<String, Object>>> getGoodsCategoryTree(Map<String, Object> param) {
        List<Map<String, Object>> list = commonMapper.getGoodsCategoryTree(param);
        return ResponseResultUtil.success(list);
    }

    /**
     * @desc : 获取页面数据源集合 (小程序用)
     * @author : 于继渤
     * @date : 2024/2/26 10:36
     */
    public ResponseResultVO<List<Map<String, Object>>> getInitData(Map<String, Object> param) {
        //判断前台是否传 dataSourceCode
        if (!param.containsKey("dataSourceCode") &&  param.get("dataSourceCode") == null) {
            return ResponseResultUtil.error(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.DATASOURCECODE_NOT.getMessage());
        }
        String dataSourceCode = param.get("dataSourceCode").toString();
        //查询到的结果集
        List<Map<String, Object>> list = null;
        Map<String, Object> map = new HashMap<>();
        //客户来源
        if (dataSourceCode.equals("customerFrom")) {
            map.put("dictCode","基础资料-来源");
            list = commonMapper.getDictionaryData(map);
        }
        // 基础资料的信息  入库原因
        if (dataSourceCode.equals("baseData")) {
            map.put("dictCode",param.get("dictCode").toString()); // 需要前台传过dictCode
            if (!param.containsKey("dictCode") &&  param.get("dictCode") == null) {
                return ResponseResultUtil.error(ResponseCodeEnum.OPERATE_FAIL.getCode(), ErrorCodeEnum.DATASOURCECODE_NOT.getMessage());
            }
            list = commonMapper.getDictionaryData(map);
        }
        //销售渠道
        if (dataSourceCode.equals("saleChannel")) {
            list = commonMapper.getSaleChannel(map);
        }
        //结算方式
        if (dataSourceCode.equals("settlement")) {
            list = commonMapper.getSettlement(map);
        }
        //销售渠道
        if (dataSourceCode.equals("saleChannelPurviewType")) {
            list = commonMapper.getSaleChannelPurviewType(param);
        }
        //部门
        if (dataSourceCode.equals("org")) {
            list = commonMapper.getOrg(map);
        }
        //品牌
        if (dataSourceCode.equals("brand")) {
            list = commonMapper.getGoodsBrand(map);
        }
        //员工
        if (dataSourceCode.equals("staff")) {
            list = commonMapper.getStaff(map);
        }
        //员工
        if (dataSourceCode.equals("staffPurviewType")) {
            list = commonMapper.getStaffPurviewType(param);
        }
        //仓库
        if (dataSourceCode.equals("warehouse")) {
            list = commonMapper.getWarehouse(map);
        }
        //角色
        if (dataSourceCode.equals("role")) {
            list = commonMapper.getRole(map);
        }
        //客户意向
        if (dataSourceCode.equals("customerIntention")) {
            map.put("kindType","客户意向");
            list = commonMapper.getDataKind(map);
        }
        //留店时长
        if (dataSourceCode.equals("storeRetentionTime")) {
            map.put("kindType","留店时长");
            list = commonMapper.getDataKind(map);
        }
        //邀约结果
        if (dataSourceCode.equals("inviteResult")) {
            map.put("kindType","邀约结果");
            list = commonMapper.getDataKind(map);
        }
        //量尺状态
        if (dataSourceCode.equals("scaleStatus")) {
            map.put("kindType","量尺状态");
            list = commonMapper.getDataKind(map);
        }
        //跟进方式
        if (dataSourceCode.equals("followType")) {
            map.put("kindType","跟进方式");
            list = commonMapper.getDataKind(map);
        }
        return ResponseResultUtil.success(list);
    }




    /**
     * @desc   : 获取供应商和客户数据
     * @date   : 2024/3/13 15:09
     * @author : 寇珊珊
     */
    public ResponseResultVO<List<Map<String, Object>>> getSupplierAndCustomer(Map<String, Object> param) {
        // 获取供应商和客户
        List<Map<String, Object>> list = commonMapper.getSupplierAndCustomer(param);
        return ResponseResultUtil.success(list);

    }
    
    
    /**
     * @desc   : 获取供应商和客户数据(分页)
     * @date   : 2024/3/13 14:02
     * @author : 寇珊珊
     */
    public ResponseResultVO<PageList<Map<String, Object>>> getSupplierAndCustomerByPage(Map<String, Object> param) {
        // 校验分页参数
        if (param.get("pageSize") == null || param.get("currentPage") == null) {
            return ResponseResultUtil.error(ResponseCodeEnum.OPERATE_FAIL, "请检查分页参数!");
        }
        // 定义返回值
        PageList<Map<String, Object>> data = new PageList<>();
        // 分页参数赋值
        param = this.getLimit(param);

        // 获取客户
        List<Map<String, Object>> list = commonMapper.getSupplierAndCustomerByPage(param);
        // 获取总数量
        Long total = commonMapper.getSupplierAndCustomerByPageCount(param);
        // 组装返回值
        data.setPageSize((int) param.get("pageSize")).setCurrentPage((int) param.get("currentPage")).setList(list).setTotal(total);
        return ResponseResultUtil.success(data);
    }


    /**
     * @desc   : 获取组织机构
     * @date   : 2024/3/13 17:01
     * @author : 寇珊珊
     */
    public ResponseResultVO<List<Map<String, Object>>> getOrganization(Map<String, Object> param) {
        // 获取组织机构
        List<Map<String, Object>> list = commonMapper.getOrganization(param);
        return ResponseResultUtil.success(list);
    }


    /**
     * @desc   : 获取组织机构（分页）
     * @date   : 2024/3/13 17:01
     * @author : 寇珊珊
     */
    public ResponseResultVO<PageList<Map<String, Object>>> getOrganizationByPage(Map<String, Object> param) {
        // 校验分页参数
        if (param.get("pageSize") == null || param.get("currentPage") == null) {
            return ResponseResultUtil.error(ResponseCodeEnum.OPERATE_FAIL, "请检查分页参数!");
        }
        // 定义返回值
        PageList<Map<String, Object>> data = new PageList<>();
        // 分页参数赋值
        param = this.getLimit(param);
        // 获取组织机构
        List<Map<String, Object>> list = commonMapper.getOrganizationByPage(param);
        // 获取总数量
        Long total = commonMapper.getOrganizationCount(param);
        // 组装返回值
        data.setPageSize((int) param.get("pageSize")).setCurrentPage((int) param.get("currentPage")).setList(list).setTotal(total);
        return ResponseResultUtil.success(data);
    }

    /**
     * @desc   : 获取资金账户（下拉）
     * @author : 付斌
     * @date   : 2024-03-14 11:34
     */
    public ResponseResultVO<List<Map<String, Object>>> getMac(Map<String, Object> param) {
        // 获取组织机构
        List<Map<String, Object>> list = commonMapper.getMac(param);
        return ResponseResultUtil.success(list);
    }

    /**
     * @desc : 获取资金账户（放大镜）
     * @author : 付斌
     * @date : 2024-03-05 10:50
     */
    public ResponseResultVO<List<Map<String, Object>>> getMoneyAccount(Map<String, Object> param) {
        // 获取系统基础数据
        List<Map<String, Object>> list = commonMapper.getMoneyAccount(param);
        return ResponseResultUtil.success(list);
    }

    /**
     * @desc : 获取资金账户（放大镜分页）
     * @author : 付斌
     * @date : 2024-03-05 10:50
     */
    public ResponseResultVO<PageList<Map<String, Object>>> getMoneyAccountByPage(Map<String, Object> param) {
        // 校验分页参数
        if (param.get("pageSize") == null || param.get("currentPage") == null) {
            return ResponseResultUtil.error(ResponseCodeEnum.OPERATE_FAIL, "请检查分页参数!");
        }
        // 分页参数赋值
        param = this.getLimit(param);
        return super.mergeListWithCount(param, commonMapper.getMoneyAccount(param),
                commonMapper.getMoneyAccountCountByPage(param));
    }

    /**
     * @desc   : 获取多业务部门
     * @author : 付斌
     * @date   : 2024-03-20 16:54
     */
    public ResponseResultVO<List<Map<String, Object>>> selectMultiOrg(Map<String, Object> param) {
        List<Map<String, Object>> list = commonMapper.selectMultiOrg(param);
        return ResponseResultUtil.success(list);
    }

    /**
     * @desc   : 获取多业务员
     * @author : 付斌
     * @date   : 2024-03-20 16:54
     */
    public ResponseResultVO<List<Map<String, Object>>> selectMultiStaff(Map<String, Object> param) {
        List<Map<String, Object>> list = commonMapper.selectMultiStaff(param);
        return ResponseResultUtil.success(list);
    }

    /**
     * @desc   : 组织仓库
     * @author : 宋扬
     * @date   : 2024/3/22 15:47
     */
    public ResponseResultVO<List<Map<String, Object>>> selectMultiWarehouse(Map<String, Object> param) {
        List<Map<String, Object>> list = commonMapper.selectMultiWarehouse(param);
        return ResponseResultUtil.success(list);
    }

    /**
     * @desc   : 组织资金账户
     * @author : 宋扬
     * @date   : 2024/3/22 15:54
     */
    public ResponseResultVO<List<Map<String, Object>>> selectMultiMoneyAccount(Map<String, Object> param) {
        List<Map<String, Object>> list = commonMapper.selectMultiMoneyAccount(param);
        return ResponseResultUtil.success(list);
    }

    /**
     * @desc   : 获取商品（采购订单开单用）
     * @author : 常皓宁
     * @date   : 2024/3/9 10:08
     */
    public ResponseResultVO<List<Map<String, Object>>> getGoodsForPurchaseReturn(Map<String, Object> param) {
        // 获取系统基础数据
        List<Map<String, Object>> list = commonMapper.getGoodsForPurchaseReturn(param);
        return ResponseResultUtil.success(list);
    }

    /**
     * @desc   : 获取商品（采购订单开单用）（分页）
     * @author : 常皓宁
     * @date   : 2024/3/9 10:08
     */
    public ResponseResultVO<PageList<Map<String, Object>>> getGoodsForPurchaseReturnByPage(Map<String, Object> param) {
        // 校验分页参数
        if (param.get("pageSize") == null || param.get("currentPage") == null) {
            return ResponseResultUtil.error(ResponseCodeEnum.OPERATE_FAIL, "请检查分页参数!");
        }
        // 分页参数赋值
        param = this.getLimit(param);
        return super.mergeListWithCount(param, commonMapper.getGoodsForPurchaseReturn(param),
                commonMapper.getGoodsForPurchaseReturnByPage(param));
    }

    /**
     * @desc   : 获取员工的范围权限类型
     * @author : 常皓宁
     * @date   : 2024/4/2 10:06
     */
    public ResponseResultVO<List<Map<String, Object>>> getPurviewType(Map<String, Object> param) {
        // 获取供应商和客户
        List<Map<String, Object>> list = commonMapper.getPurviewType(param);
        return ResponseResultUtil.success(list);
    }

    /**
     * @desc   : 获取组织仓库
     * @author : 付斌
     * @date   : 2024-04-10 13:30
     */
    public ResponseResultVO<List<Map<String, Object>>> getOrgWh(Map<String, Object> param) {
        List<Map<String, Object>> list = commonMapper.getOrgWh(param);
        return ResponseResultUtil.success(list);
    }

    public ResponseResultVO<List<Map<String, Object>>> getLabelPrintItem(Map<String, Object> param) {
        return ResponseResultUtil.success(commonMapper.getLabelPrintItem(param));
    }


    /**
     * @desc   : 获取商品（其他入库开单用）
     * @date   : 2024/4/20 11:21
     * @author : 寇珊珊
     */
    public ResponseResultVO<List<Map<String, Object>>> getGoodsForInto(Map<String, Object> param) {
        // 获取系统基础数据
        List<Map<String, Object>> list = commonMapper.getGoodsForInto(param);
        return ResponseResultUtil.success(list);
    }

    /**
     * @desc   : 获取商品（其他入库开单用）（分页）
     * @date   : 2024/4/20 11:21
     * @author : 寇珊珊
     */
    public ResponseResultVO<PageList<Map<String, Object>>> getGoodsForIntoByPage(Map<String, Object> param) {
        // 校验分页参数
        if (param.get("pageSize") == null || param.get("currentPage") == null) {
            return ResponseResultUtil.error(ResponseCodeEnum.OPERATE_FAIL, "请检查分页参数!");
        }
        // 分页参数赋值
        param = this.getLimit(param);
        return super.mergeListWithCount(param, commonMapper.getGoodsForInto(param),
                commonMapper.getGoodsForIntoCountByPage(param));
    }


}
