package com.bweb.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hfkj.common.exception.ErrorCode;
import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode;
import com.hfkj.common.security.UserCenter;
import com.hfkj.common.utils.ResponseMsgUtil;
import com.hfkj.entity.*;
import com.hfkj.model.ResponseData;
import com.hfkj.model.SecUserSessionObject;
import com.hfkj.service.agent.BsAgentService;
import com.hfkj.service.merchant.BsMerchantService;
import com.hfkj.service.agent.BsAgentMerService;
import com.hfkj.service.agent.BsAgentPriceService;
import com.hfkj.service.gas.BsGasOilPriceService;
import com.hfkj.sysenum.SecUserObjectTypeEnum;
import com.hfkj.sysenum.agent.AgentPriceTypeEnum;
import com.hfkj.sysenum.agent.AgentTypeEnum;
import com.hfkj.sysenum.gas.GasOilNoEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

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

/**
 * @className: BsAgentPriceController
 * @author: HuRui
 * @date: 2024/6/19
 **/
@Controller
@RequestMapping(value = "/agentPrice")
@Api(value = "代理商商户")
public class BsAgentPriceController {

    private static Logger log = LoggerFactory.getLogger(BsAgentPriceController.class);
    @Resource
    private BsAgentService agentService;
    @Resource
    private BsAgentPriceService agentPriceService;
    @Resource
    private BsAgentMerService agentMerService;
    @Resource
    private BsMerchantService merchantService;
    @Resource
    private BsGasOilPriceService gasOilPriceService;
    @Resource
    private UserCenter userCenter;

    @RequestMapping(value = "/editPrice", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "编辑价格")
    public ResponseData editPrice(@RequestBody JSONArray bodyArray) {
        try {
            SecUserSessionObject userSession = userCenter.getSessionModel(SecUserSessionObject.class);
            if (!userSession.getAccount().getObjectType().equals(SecUserObjectTypeEnum.type1.getCode())
                && !userSession.getAccount().getObjectType().equals(SecUserObjectTypeEnum.type4.getCode())
                && !userSession.getAccount().getObjectType().equals(SecUserObjectTypeEnum.type5.getCode())) {
                throw ErrorHelp.genException(SysCode.System, ErrorCode.ROLE_NOT_PERMISSIONS, "");
            }

            if (bodyArray == null || bodyArray.isEmpty()) {
                throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
            }

            Integer accountObjectType = userSession.getAccount().getObjectType();
            Integer type = null;
            for (Object obj : bodyArray) {
                JSONObject body = (JSONObject)JSONObject.toJSON(obj);
                if (StringUtils.isBlank(body.getString("merNo"))
                        || StringUtils.isBlank(body.getString("oilNo"))
                        || body.getBigDecimal("priceRate") == null
                        || body.getBigDecimal("serviceFeeRate") == null
                ) {
                    throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
                }

                // 查询商户
                BsMerchant merchant = merchantService.getMerchant(body.getString("merNo"));
                if (merchant == null) {
                    throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的商户");
                }

                BsAgentPrice agentPrice = null;
                BsAgentMer agentMer = null;
                if (accountObjectType.equals(SecUserObjectTypeEnum.type1.getCode())) {
                    type = AgentPriceTypeEnum.type1.getCode();
                    agentPrice = agentPriceService.getDetail(AgentPriceTypeEnum.type1,body.getString("merNo"), body.getString("oilNo"));

                } else if (accountObjectType.equals(SecUserObjectTypeEnum.type4.getCode())) {
                    type = AgentPriceTypeEnum.type2.getCode();
                    // 查询代理商
                    BsAgent agent = agentService.getAgentById(userSession.getAccount().getObjectId());
                    if (agent == null) {
                        throw ErrorHelp.genException(SysCode.System, ErrorCode.ROLE_NOT_PERMISSIONS, "");
                    }
                    if (agent.getType().equals(AgentTypeEnum.type1.getCode())) {
                        throw ErrorHelp.genException(SysCode.System, ErrorCode.ROLE_NOT_PERMISSIONS, "");
                    }
                    agentMer = agentMerService.getDetailByAgent(userSession.getAccount().getObjectId(), body.getString("merNo"));
                    if (agentMer != null) {
                        agentPrice = agentPriceService.getDetail(agentMer.getId(), body.getString("oilNo"));
                    }
                } else if (accountObjectType.equals(SecUserObjectTypeEnum.type5.getCode())) {
                    type = AgentPriceTypeEnum.type3.getCode();
                    agentMer = agentMerService.getDetailByAgentStaff(userSession.getAccount().getObjectId(), body.getString("merNo"));
                    if (agentMer != null) {
                        agentPrice = agentPriceService.getDetail(agentMer.getId(), body.getString("oilNo"));
                    }
                } else {
                    throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的角色");
                }

                // 查询油号
                GasOilNoEnum oilNo = GasOilNoEnum.getNameByType(body.getInteger("oilNo"));
                if (oilNo == null) {
                    throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的油号");
                }
                // 查询油站
                if (agentPrice == null) {
                    agentPrice = new BsAgentPrice();
                    agentPrice.setType(type);
                    agentPrice.setMerId(merchant.getId());
                    agentPrice.setMerNo(merchant.getMerNo());
                    agentPrice.setMerName(merchant.getMerName());
                    agentPrice.setOilNo(oilNo.getCode().toString());
                    agentPrice.setOilNoName(oilNo.getName());
                    agentPrice.setAgentId(agentMer!=null?agentMer.getAgentId():null);
                    agentPrice.setAgentMerId(agentMer!=null?agentMer.getId():null);
                    agentPrice.setPriceRate(body.getBigDecimal("priceRate"));
                    agentPrice.setServiceFeeRate(body.getBigDecimal("serviceFeeRate"));
                } else {
                    agentPrice.setPriceRate(body.getBigDecimal("priceRate"));
                    agentPrice.setServiceFeeRate(body.getBigDecimal("serviceFeeRate"));
                }
                agentPriceService.editData(agentPrice);
            }

            return ResponseMsgUtil.success("操作成功");

        } catch (Exception e) {
            log.error("BsAgentPriceController --> editPrice() error!", e);
            return ResponseMsgUtil.exception(e);
        }
    }

    @RequestMapping(value = "/editApiPrice", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "编辑API价格")
    public ResponseData editApiPrice(@RequestBody JSONArray bodyArray) {
        try {
            SecUserSessionObject userSession = userCenter.getSessionModel(SecUserSessionObject.class);
            if (!userSession.getAccount().getObjectType().equals(SecUserObjectTypeEnum.type1.getCode())) {
                throw ErrorHelp.genException(SysCode.System, ErrorCode.ROLE_NOT_PERMISSIONS, "");
            }

            if (bodyArray == null || bodyArray.isEmpty()) {
                throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
            }

            Integer accountObjectType = userSession.getAccount().getObjectType();
            for (Object obj : bodyArray) {
                JSONObject body = (JSONObject)JSONObject.toJSON(obj);
                if (body.getLong("agentId") == null
                        || StringUtils.isBlank(body.getString("merNo"))
                        || StringUtils.isBlank(body.getString("oilNo"))
                        || body.getBigDecimal("priceRate") == null
                        || body.getBigDecimal("serviceFeeRate") == null
                ) {
                    throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
                }

                // 查询商户
                BsMerchant merchant = merchantService.getMerchant(body.getString("merNo"));
                if (merchant == null) {
                    throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的商户");
                }

                BsAgentPrice agentPrice = null;
                BsAgentMer agentMer = null;
                if (accountObjectType.equals(SecUserObjectTypeEnum.type1.getCode())) {
                    agentMer = agentMerService.getDetailByAgent(body.getLong("agentId"), body.getString("merNo"));
                    if (agentMer != null) {
                        agentPrice = agentPriceService.getDetail(agentMer.getId(), body.getString("oilNo"));
                    }
                }  else {
                    throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的角色");
                }

                // 查询油号
                GasOilNoEnum oilNo = GasOilNoEnum.getNameByType(body.getInteger("oilNo"));
                if (oilNo == null) {
                    throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的油号");
                }
                // 查询油站
                if (agentPrice == null) {
                    agentPrice = new BsAgentPrice();
                    agentPrice.setType(AgentPriceTypeEnum.type2.getCode());
                    agentPrice.setMerId(merchant.getId());
                    agentPrice.setMerNo(merchant.getMerNo());
                    agentPrice.setMerName(merchant.getMerName());
                    agentPrice.setOilNo(oilNo.getCode().toString());
                    agentPrice.setOilNoName(oilNo.getName());
                    agentPrice.setAgentId(agentMer!=null?agentMer.getAgentId():null);
                    agentPrice.setAgentMerId(agentMer!=null?agentMer.getId():null);
                    agentPrice.setPriceRate(body.getBigDecimal("priceRate"));
                    agentPrice.setServiceFeeRate(body.getBigDecimal("serviceFeeRate"));
                } else {
                    agentPrice.setPriceRate(body.getBigDecimal("priceRate"));
                    agentPrice.setServiceFeeRate(body.getBigDecimal("serviceFeeRate"));
                }
                agentPriceService.editData(agentPrice);

                // 通知代理
                agentMerService.agentNotify(agentPrice.getAgentId(), merchant.getMerNo());
            }

            return ResponseMsgUtil.success("操作成功");

        } catch (Exception e) {
            log.error("BsAgentPriceController --> editPrice() error!", e);
            return ResponseMsgUtil.exception(e);
        }
    }

    @RequestMapping(value = "/batchConfigApiPrice", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "批量配置API价格")
    public ResponseData batchConfigApiPrice(@RequestBody JSONObject body) {
        try {
            SecUserSessionObject userSession = userCenter.getSessionModel(SecUserSessionObject.class);
            if (!userSession.getAccount().getObjectType().equals(SecUserObjectTypeEnum.type1.getCode())) {
                throw ErrorHelp.genException(SysCode.System, ErrorCode.ROLE_NOT_PERMISSIONS, "");
            }
            if (body.getLong("agentId") == null
                    || body.getString("oilNo") == null
                    || body.getBigDecimal("priceRate") == null
                    || body.getBigDecimal("serviceFeeRate") == null) {
                throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
            }

            // 查询油号
            GasOilNoEnum oilNo = GasOilNoEnum.getNameByType(body.getInteger("oilNo"));
            if (oilNo == null) {
                throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的油号");
            }

            Map<String,Object> param = new HashMap<>();
            param.put("agentId", body.getLong("agentId"));
            param.put("provinceCode", body.getLong("provinceCode"));
            param.put("merSourceType", body.getInteger("sourceType"));
            List<BsAgentMer> list = agentMerService.getList(param);
            for (BsAgentMer agentMer : list) {
                // 查询价格
                BsAgentPrice agentPrice = agentPriceService.getDetail(agentMer.getId(), body.getString("oilNo"));
                // 查询油站
                if (agentPrice == null) {
                    // 查询商户
                    BsMerchant merchant = merchantService.getMerchant(agentMer.getMerNo());
                    if (merchant == null) {
                        throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的商户");
                    }
                    agentPrice = new BsAgentPrice();
                    agentPrice.setType(AgentPriceTypeEnum.type2.getCode());
                    agentPrice.setMerId(merchant.getId());
                    agentPrice.setMerNo(merchant.getMerNo());
                    agentPrice.setMerName(merchant.getMerName());
                    agentPrice.setOilNo(oilNo.getCode().toString());
                    agentPrice.setOilNoName(oilNo.getName());
                    agentPrice.setAgentId(agentMer!=null?agentMer.getAgentId():null);
                    agentPrice.setAgentMerId(agentMer!=null?agentMer.getId():null);
                    agentPrice.setPriceRate(body.getBigDecimal("priceRate"));
                    agentPrice.setServiceFeeRate(body.getBigDecimal("serviceFeeRate"));
                } else {
                    agentPrice.setPriceRate(body.getBigDecimal("priceRate"));
                    agentPrice.setServiceFeeRate(body.getBigDecimal("serviceFeeRate"));
                }
                agentPriceService.editData(agentPrice);

                // 通知代理
                agentMerService.agentNotify(agentPrice.getAgentId(), agentPrice.getMerNo());
            }

            return ResponseMsgUtil.success("操作成功");

        } catch (Exception e) {
            log.error("BsAgentPriceController --> editPrice() error!", e);
            return ResponseMsgUtil.exception(e);
        }
    }

    @RequestMapping(value = "/batchConfigPrice", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "批量配置价格")
    public ResponseData batchConfigPrice(@RequestBody JSONObject body) {
        try {
            SecUserSessionObject userSession = userCenter.getSessionModel(SecUserSessionObject.class);
            if (!userSession.getAccount().getObjectType().equals(SecUserObjectTypeEnum.type1.getCode())) {
                throw ErrorHelp.genException(SysCode.System, ErrorCode.ROLE_NOT_PERMISSIONS, "");
            }

            if (body.getLong("agentId") == null
                    || body.getLong("provinceCode") == null
                    || body.getInteger("sourceType") == null
                    || body.getString("oilNo") == null
                    || body.getBigDecimal("priceRate") == null
                    || body.getBigDecimal("serviceFeeRate") == null) {
                throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
            }

            Integer accountObjectType = userSession.getAccount().getObjectType();
            Integer type = null;
            for (Object obj : body.getJSONArray("merNoList")) {
                JSONObject mer = (JSONObject) obj;
                if (StringUtils.isBlank(mer.getString("merNo"))) {
                    throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
                }
                // 查询商户
                BsMerchant merchant = merchantService.getMerchant(mer.getString("merNo"));
                if (merchant == null) {
                    throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的商户");
                }

                BsAgentPrice agentPrice = null;
                BsAgentMer agentMer = null;
                if (accountObjectType.equals(SecUserObjectTypeEnum.type1.getCode())) {
                    type = AgentPriceTypeEnum.type1.getCode();
                    agentPrice = agentPriceService.getDetail(AgentPriceTypeEnum.type1, merchant.getMerNo(), body.getString("oilNo"));

                } else if (accountObjectType.equals(SecUserObjectTypeEnum.type4.getCode())) {
                    type = AgentPriceTypeEnum.type2.getCode();
                    // 查询代理商
                    BsAgent agent = agentService.getAgentById(userSession.getAccount().getObjectId());
                    if (agent == null) {
                        throw ErrorHelp.genException(SysCode.System, ErrorCode.ROLE_NOT_PERMISSIONS, "");
                    }
                    if (agent.getType().equals(AgentTypeEnum.type1.getCode())) {
                        throw ErrorHelp.genException(SysCode.System, ErrorCode.ROLE_NOT_PERMISSIONS, "");
                    }
                    agentMer = agentMerService.getDetailByAgent(userSession.getAccount().getObjectId(), merchant.getMerNo());
                    if (agentMer == null) {
                        throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未分配此油站");
                    }
                    agentPrice = agentPriceService.getDetail(agentMer.getId(), body.getString("oilNo"));

                } else if (accountObjectType.equals(SecUserObjectTypeEnum.type5.getCode())) {
                    type = AgentPriceTypeEnum.type3.getCode();
                    agentMer = agentMerService.getDetailByAgentStaff(userSession.getAccount().getObjectId(), merchant.getMerNo());
                    if (agentMer == null) {
                        throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未分配此油站");
                    }
                    agentPrice = agentPriceService.getDetail(agentMer.getId(), body.getString("oilNo"));

                } else {
                    throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的角色");
                }

                // 查询油号
                GasOilNoEnum oilNo = GasOilNoEnum.getNameByType(body.getInteger("oilNo"));
                if (oilNo == null) {
                    throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的油号");
                }

                // 查询油站
                if (agentPrice == null) {
                    agentPrice = new BsAgentPrice();
                    agentPrice.setType(type);
                    agentPrice.setMerId(merchant.getId());
                    agentPrice.setMerNo(merchant.getMerNo());
                    agentPrice.setMerName(merchant.getMerName());
                    agentPrice.setOilNo(oilNo.getCode().toString());
                    agentPrice.setOilNoName(oilNo.getName());
                    agentPrice.setAgentId(agentMer!=null?agentMer.getAgentId():null);
                    agentPrice.setAgentMerId(agentMer!=null?agentMer.getId():null);
                    agentPrice.setPriceRate(body.getBigDecimal("priceRate"));
                    agentPrice.setServiceFeeRate(body.getBigDecimal("serviceFeeRate"));
                } else {
                    agentPrice.setPriceRate(body.getBigDecimal("priceRate"));
                    agentPrice.setServiceFeeRate(body.getBigDecimal("serviceFeeRate"));
                }
                agentPriceService.editData(agentPrice);
            }

            return ResponseMsgUtil.success("操作成功");

        } catch (Exception e) {
            log.error("BsAgentPriceController --> editPrice() error!", e);
            return ResponseMsgUtil.exception(e);
        }
    }

    @RequestMapping(value = "/getOilNoPrice", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "油站价格")
    public ResponseData getOilNoPrice( @RequestParam(name = "merNo", required = true) String merNo) {
        try {
            SecUserSessionObject userSession = userCenter.getSessionModel(SecUserSessionObject.class);
            if (!userSession.getAccount().getObjectType().equals(SecUserObjectTypeEnum.type1.getCode())
                    && !userSession.getAccount().getObjectType().equals(SecUserObjectTypeEnum.type4.getCode())
                    && !userSession.getAccount().getObjectType().equals(SecUserObjectTypeEnum.type5.getCode())) {
                throw ErrorHelp.genException(SysCode.System, ErrorCode.ROLE_NOT_PERMISSIONS, "");
            }

            Integer accountObjectType = userSession.getAccount().getObjectType();

            // 查询商户
            BsMerchant merchant = merchantService.getMerchant(merNo);
            if (merchant == null) {
                throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的商户");
            }

            BsAgentMer agentMer = null;
            if (accountObjectType.equals(SecUserObjectTypeEnum.type4.getCode())) {
                agentMer = agentMerService.getDetailByAgent(userSession.getAccount().getObjectId(), merNo);
            } else if (accountObjectType.equals(SecUserObjectTypeEnum.type5.getCode())) {
                agentMer = agentMerService.getDetailByAgentStaff(userSession.getAccount().getObjectId(), merNo);
            }

            List<Map<String, Object>> oilPriceMapList = new ArrayList<>();
            Map<String, Object> oilPriceMap;

            // 查询商户油品
            List<BsGasOilPrice> oilPriceList = gasOilPriceService.getGasOilPriceList(merchant.getId());
            for (BsGasOilPrice price : oilPriceList) {
                oilPriceMap = new HashMap<>();
                oilPriceMap.put("merId", merchant.getId());
                oilPriceMap.put("merNo", merchant.getMerNo());
                oilPriceMap.put("merName", merchant.getMerName());
                oilPriceMap.put("oilNo", price.getOilNo());
                oilPriceMap.put("oilNoName", price.getOilNoName());
                oilPriceMap.put("status", price.getStatus());
                oilPriceMap.put("priceRate", 100L);
                oilPriceMap.put("serviceFeeRate", 0L);

                if (accountObjectType.equals(SecUserObjectTypeEnum.type1.getCode())) {
                    // 价格
                    BsAgentPrice priceRate = agentPriceService.getDetail(AgentPriceTypeEnum.type1, merchant.getMerNo(), price.getOilNo());
                    if (priceRate != null) {
                        oilPriceMap.put("priceRate", priceRate.getPriceRate());
                        oilPriceMap.put("serviceFeeRate", priceRate.getServiceFeeRate());
                    }
                } else {
                    if (agentMer != null) {
                        // 价格
                        BsAgentPrice priceRate = agentPriceService.getDetail(agentMer.getId(), price.getOilNo());
                        if (priceRate != null) {
                            oilPriceMap.put("priceRate", priceRate.getPriceRate());
                            oilPriceMap.put("serviceFeeRate", priceRate.getServiceFeeRate());
                        }
                    }
                }
                oilPriceMapList.add(oilPriceMap);
            }
            return ResponseMsgUtil.success(oilPriceMapList);

        } catch (Exception e) {
            return ResponseMsgUtil.exception(e);
        }
    }



    @RequestMapping(value = "/getPriceList", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "获取价格列表")
    public ResponseData getPriceList(@RequestParam(name = "agentId", required = true) Long agentId,
                                     @RequestParam(name = "agentStaffId", required = true) Long agentStaffId,
                                     @RequestParam(name = "provinceCode", required = false) String provinceCode,
                                     @RequestParam(name = "merNo", required = false) String merNo,
                                     @RequestParam(name = "merName", required = false) String merName,
                                     @RequestParam(name = "oilNo", required = false) String oilNo,
                                     @RequestParam(name = "sourceType", required = false) Integer sourceType,
                                     @RequestParam(name = "pageNum", required = true) Integer pageNum,
                                     @RequestParam(name = "pageSize", required = true) Integer pageSize

    ) {
        try {
            Map<String,Object> param = new HashMap<>();
            param.put("agentId", agentId);
            param.put("agentStaffId", agentStaffId);
            param.put("provinceCode", provinceCode);
            param.put("merNo", merNo);
            param.put("merName", merName);
            param.put("sourceType", sourceType);
            param.put("oilNo", oilNo);

            PageHelper.startPage(pageNum,pageSize);
            return ResponseMsgUtil.success(new PageInfo<>(agentPriceService.getAgentPriceList(param)));

        } catch (Exception e) {
            return ResponseMsgUtil.exception(e);
        }
    }

    @RequestMapping(value = "/getApiDiscountList", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "获取APi代理优惠价格列表")
    public ResponseData getApiDiscountList(@RequestParam(name = "agentId", required = true) Long agentId,
                                     @RequestParam(name = "provinceCode", required = false) String provinceCode,
                                     @RequestParam(name = "merNo", required = false) String merNo,
                                     @RequestParam(name = "merName", required = false) String merName,
                                     @RequestParam(name = "oilNo", required = false) String oilNo,
                                     @RequestParam(name = "sourceType", required = false) Integer sourceType,
                                     @RequestParam(name = "pageNum", required = true) Integer pageNum,
                                     @RequestParam(name = "pageSize", required = true) Integer pageSize
    ) {
        try {
            Map<String,Object> param = new HashMap<>();
            param.put("agentId", agentId);
            param.put("provinceCode", provinceCode);
            param.put("merNo", merNo);
            param.put("merName", merName);
            param.put("sourceType", sourceType);
            param.put("oilNo", oilNo);

            PageHelper.startPage(pageNum,pageSize);
            return ResponseMsgUtil.success(new PageInfo<>(agentPriceService.getApiAgentDiscountList(param)));

        } catch (Exception e) {
            return ResponseMsgUtil.exception(e);
        }
    }

}
