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

import com.aliyun.openservices.shade.com.google.common.base.Throwables;
import com.zm.order.tool.server.service.ExceptionConstants;
import com.zm.order.tool.server.service.ItemRecommendService;
import com.zm.util.dto.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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;

/**
 *
 * @packageName: com.zm.order.tool.server.controller
 * @className: ItemRecommendController
 * @author zhuxiaofeng
 * @date 2022/8/9 11:27
 */
@Api(value = "订单运维工具", tags = "商品推荐")
@RestController
@RequestMapping("/qapi/order/item")
public class ItemRecommendController {

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

    @Autowired
    private ItemRecommendService recommendService;

    @ApiOperation("新增记录")
    @RequestMapping(value = "/recommend/insert", method = RequestMethod.POST)
    public Result insert() {
        Result result = new Result();
        try {
            recommendService.randomInsert();
        } catch (Throwable throwable) {
            logger.error("ItemRecommendController[insert] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            result.setException(ExceptionConstants.SYSTEM_ERROR);
        }
        return result;
    }

    @ApiOperation("删除商品推荐数据")
    @RequestMapping(value = "/recommend/del", method = RequestMethod.POST)
    public Result del() {
        Result result = new Result();
        try {
            recommendService.realDelete();
        } catch (Throwable throwable) {
            logger.error("ItemRecommendController[del] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            result.setException(ExceptionConstants.SYSTEM_ERROR);
        }
        return result;
    }

    @ApiOperation("删除商品推荐数据")
    @RequestMapping(value = "/detail/fix", method = RequestMethod.POST)
    public Result del11() {
        Result result = new Result();
        try {
            recommendService.orderCenterApi();
        } catch (Throwable throwable) {
            logger.error("ItemRecommendController[del] failed, cause by:{}", Throwables.getStackTraceAsString(throwable));
            result.setException(ExceptionConstants.SYSTEM_ERROR);
        }
        return result;
    }

}
