package com.bweb.controller;

import com.hfkj.common.exception.ErrorCode;
import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode;
import com.hfkj.common.utils.ResponseMsgUtil;
import com.hfkj.entity.BsGasChannelPriceWeek;
import com.hfkj.entity.BsGasOilPriceWeek;
import com.hfkj.model.ResponseData;
import com.hfkj.service.gas.BsGasChannelPriceWeekService;
import com.hfkj.service.order.BsGasChannelConfigService;
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;

/**
 * @className: BsGasChannelPriceWeekController
 * @author: HuRui
 * @date: 2025/3/11
 **/
@Controller
@RequestMapping(value = "/gasChannelPriceWeek")
@Api(value = "加油渠道配置")
public class BsGasChannelPriceWeekController {

    private static Logger log = LoggerFactory.getLogger(BsGasChannelConfigController.class);
    @Resource
    private BsGasChannelPriceWeekService gasChannelPriceWeekService;

    @RequestMapping(value = "/updatePrice", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "修改价格")
    public ResponseData updatePrice(@RequestBody BsGasChannelPriceWeek body) {
        try {
            if (body.getId() == null
                    || body.getPriceRate() == null
                    || body.getServiceFeeRate() == null
            ) {
                throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
            }
            // 查询价格
            BsGasChannelPriceWeek oilPrice = gasChannelPriceWeekService.getDetail(body.getId());
            if (oilPrice == null) {
                throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未知的数据");
            }
            oilPrice.setPriceRate(body.getPriceRate());
            oilPrice.setServiceFeeRate(body.getServiceFeeRate());
            gasChannelPriceWeekService.editData(oilPrice);

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

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

    @RequestMapping(value = "/getPriceList", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "查询价格列表")
    public ResponseData getPriceList(@RequestParam(name = "gasChannelType", required = true) Integer gasChannelType,
                                     @RequestParam(name = "oilNo", required = true) String oilNo) {
        try {

            Map<String,Object> param = new HashMap<>();
            param.put("gasChannelType", gasChannelType);
            param.put("oilNo", oilNo);
            return ResponseMsgUtil.success(gasChannelPriceWeekService.getList(param));

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