package com.cweb.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hai.common.exception.ErrorCode;
import com.hai.common.exception.ErrorHelp;
import com.hai.common.exception.SysCode;
import com.hai.common.security.SessionObject;
import com.hai.common.security.UserCenter;
import com.hai.common.utils.ResponseMsgUtil;
import com.hai.entity.BsCompany;
import com.hai.entity.HighAgent;
import com.hai.entity.OutRechargePrice;
import com.hai.entity.SecRegion;
import com.hai.model.OutRechargePriceModel;
import com.hai.model.ResponseData;
import com.hai.model.UserInfoModel;
import com.hai.service.BsCompanyService;
import com.hai.service.CommonService;
import com.hai.service.OutRechargePriceService;
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.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping(value = "/outRechargePrice")
@Api(value = "查询充值金额接口")
public class OutRechargePriceController {

    private static Logger log = LoggerFactory.getLogger(HighMerchantStoreController.class);

    @Autowired
    private UserCenter userCenter;

    @Resource
    private OutRechargePriceService outRechargePriceService;

    @Resource
    private BsCompanyService bsCompanyService;

    @Resource
    private CommonService commonService;

    @RequestMapping(value = "/getRechargePriceByList", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "查询充值金额列表")
    public ResponseData getRechargePriceByList(
            @RequestParam(name = "platformId", required = true) Integer platformId,
            @RequestParam(name = "regionId", required = true) String regionId,
            @RequestParam(name = "operatorType", required = true) Integer operatorType
    ) {
        try {

            Map<String, Object> map = new HashMap<>();

            SecRegion region = commonService.getParentByRegion(Long.parseLong(regionId));
            if (region != null) {
                BsCompany bsCompany = bsCompanyService.selectCompanyByRegion(region.getRegionId().toString());
                map.put("companyId", String.valueOf(bsCompany.getId()));
            }
            map.put("platformId", platformId);
            map.put("operatorType", operatorType);


            return   ResponseMsgUtil.success( outRechargePriceService.getRechargePriceByList(map));
        } catch (Exception e) {
            log.error("OutRechargePriceController --> getListUser() error!", e);
            return ResponseMsgUtil.exception(e);
        }
    }

    @RequestMapping(value = "/findById", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "根据id查询详情")
    public ResponseData findById(
            @RequestParam(value = "id", required = true) Long id ,
            @RequestParam(value = "platformId", required = true) Integer platformId
    ) {
        try {

            OutRechargePriceModel outRechargePriceModel = outRechargePriceService.findById(id , platformId);
            return ResponseMsgUtil.success(outRechargePriceModel);

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


}
