package com.order.controller.business;

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.SecConfig;
import com.hfkj.model.ResponseData;
import com.hfkj.service.SecConfigService;
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.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 java.math.BigDecimal;

@Controller
@RequestMapping(value="/orderMeiTuan")
@Api(value="美团订单管理")
public class BsOrderMeiTuanController {

    @Resource
    private SecConfigService secConfigService;

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

    @RequestMapping(value="/servicePrice",method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "查询服务费")
    public ResponseData servicePrice(@RequestParam(value = "platformCode" , required = true) String platformCode,
                                     @RequestParam(value = "price" , required = true) BigDecimal price
    ) {
        try {
            // 查询配置的平台服务费
            SecConfig config = secConfigService.queryDetail(platformCode);
            BigDecimal servicePrice;

            if (config == null) {
                log.error("orderMeiTuan -> servicePrice() error!");
                throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到相信息");
            }

            servicePrice = price.multiply(new BigDecimal(config.getCodeValue()));

            return ResponseMsgUtil.success(servicePrice);

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