package com.zm.order.tool.server.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.zm.order.tool.server.service.impl.*;
import com.zm.util.dto.Result;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * <p>
 *
 * </p>
 *
 * @author nianchang
 * @date 2023/12/08 1:54 下午
 */
@Api(value = "扫描扩展字段脚本", tags = "扫描扩展字段脚本")
@RestController
@SuppressWarnings("all")
@RequestMapping("/qapi/scan")
public class ScanExtController {

    private static final Logger logger = LoggerFactory.getLogger(ScanExtController.class);

    @Autowired
    private OrderScanExtServiceImpl order;
    @Autowired
    private ItemScanExtServiceImpl item;
    @Autowired
    private DiscountScanExtServiceImpl discount;
    @Autowired
    private PayDetailScanExtServiceImpl payDetail;
    @Autowired
    private RefundScanExtServiceImpl refund;
    @Autowired
    private RefundItemScanExtServiceImpl refundItem;
    @Autowired
    private RefundDetailScanExtServiceImpl refundDetail;
    @Autowired
    private SelfTakeScanExtServiceImpl selfTake;



    @ApiOperation("扫描订单")
    @RequestMapping(value = "/order", method = RequestMethod.POST)
    public Result order() {
        logger.info("scanOrderController start!");
        try {
            order.scan();
        } catch (Exception e) {
            logger.error("[scanOrderController]failed, cause by: {}", e);
        }
        return Result.successNullData();
    }

    @ApiOperation("扫描商品")
    @RequestMapping(value = "/item", method = RequestMethod.POST)
    public Result item() {
        logger.info("scanItemController start!");
        try {
            item.scan();
        } catch (Exception e) {
            logger.error("[scanItemController]failed, cause by: {}", e);
        }
        return Result.successNullData();
    }

    @ApiOperation("扫描优惠")
    @RequestMapping(value = "/discount", method = RequestMethod.POST)
    public Result discount() {
        logger.info("scanDiscountController start!");
        try {
            discount.scan();
        } catch (Exception e) {
            logger.error("[scanDiscountController]failed, cause by: {}", e);
        }
        return Result.successNullData();
    }

    @ApiOperation("扫描支付明细")
    @RequestMapping(value = "/pay-detail", method = RequestMethod.POST)
    public Result payDetail() {
        logger.info("scanPayDetailController start!");
        try {
            payDetail.scan();
        } catch (Exception e) {
            logger.error("[scanPayDetailController]failed, cause by: {}", e);
        }
        return Result.successNullData();
    }

    @ApiOperation("扫描退款单")
    @RequestMapping(value = "/refund", method = RequestMethod.POST)
    public Result refund() {
        logger.info("scanRefundController start!");
        try {
            refund.scan();
        } catch (Exception e) {
            logger.error("[scanRefundController]failed, cause by: {}", e);
        }
        return Result.successNullData();
    }

    @ApiOperation("扫描退款商品")
    @RequestMapping(value = "/refund-item", method = RequestMethod.POST)
    public Result refundItem() {
        logger.info("scanRefundItemController start!");
        try {
            refundItem.scan();
        } catch (Exception e) {
            logger.error("[scanRefundItemController]failed, cause by: {}", e);
        }
        return Result.successNullData();
    }

    @ApiOperation("扫描退款明细")
    @RequestMapping(value = "/refund-detail", method = RequestMethod.POST)
    public Result refundDetail() {
        logger.info("scanRefundDetailController start!");
        try {
            refundDetail.scan();
        } catch (Exception e) {
            logger.error("[scanRefundDetailController]failed, cause by: {}", e);
        }
        return Result.successNullData();
    }

    @ApiOperation("扫描自提")
    @RequestMapping(value = "/self-take", method = RequestMethod.POST)
    public Result selfTake() {
        logger.info("scanSelfTakeController start!");
        try {
            selfTake.scan();
        } catch (Exception e) {
            logger.error("[scanSelfTakeController]failed, cause by: {}", e);
        }
        return Result.successNullData();
    }
}
