package com.bweb.controller;

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.BsAgentApiAccount;
import com.hfkj.entity.BsAgentApiParam;
import com.hfkj.model.ResponseData;
import com.hfkj.model.SecUserSessionObject;
import com.hfkj.service.agent.BsAgentApiAccountRecordService;
import com.hfkj.service.agent.BsAgentApiAccountService;
import com.hfkj.service.agent.BsAgentApiParamService;
import com.hfkj.sysenum.SecUserObjectTypeEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.HashMap;
import java.util.Map;

@Controller
@RequestMapping(value = "/agentApiParam")
@Api(value = "代理商API参数")
public class BsAgentApiParamController {
    private static Logger log = LoggerFactory.getLogger(BsAgentApiParamController.class);
    @Resource
    private BsAgentApiParamService agentApiParamService;

    @RequestMapping(value = "/getApiParam", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "查询参数")
    public ResponseData getApiParam(@RequestParam(value = "agentId", required = true) Long agentId) {
        try {

            // 查询账户
            return ResponseMsgUtil.success(agentApiParamService.getParam(agentId));

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

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "修改参数")
    public ResponseData update(@RequestBody JSONObject body) {
        try {
            if (body == null || body.getLong("agentId") == null) {
                throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
            }
            // 代理商API参数
            BsAgentApiParam apiParam = agentApiParamService.getParam(body.getLong("agentId"));
            if (apiParam == null) {
                throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到API参数");
            }
            apiParam.setMerInfoNotify(body.getString("merInfoNotify"));
            apiParam.setOrderRefundNotify(body.getString("orderRefundNotify"));
            agentApiParamService.update(apiParam);

            // 查询账户
            return ResponseMsgUtil.success("操作成功");

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


}
