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

import com.zm.order.tool.server.request.OrderDataReviseRequest;
import com.zm.order.tool.server.service.CommentService;
import com.zm.order.tool.server.service.ExceptionConstants;
import com.zm.order.tool.server.service.ThirdOrderService;
import com.zm.order.tool.server.service.TransferService;
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.RequestBody;
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: TransferController
 * @author zhuxiaofeng
 * @date 2023/4/28 15:12
 */
@Api(value = "迁移接口", tags = "迁移接口")
@RestController
@SuppressWarnings("all")
@RequestMapping("/qapi/order/transfer")
public class TransferController {

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

    @Autowired
    private ThirdOrderService thirdOrderService;

    @Autowired
    private TransferService transferService;

    @Autowired
    private CommentService commentService;

    @ApiOperation("订单评分历史数据处理")
    @RequestMapping(value = "/comment/score", method = RequestMethod.POST)
    public Result orderCommentAddScore(@RequestBody OrderDataReviseRequest request) {
        logger.info("orderCommentAddScore start!");
        Result result = new Result<>();
        try {
            commentService.orderCommentAddScore();
        } catch (Exception e) {
            logger.error("TransferController[orderCommentAddScore]failed,request:{},cause by: {}", request, e);
            result.setException(ExceptionConstants.SYSTEM_ERROR);
        }
        return result;
    }

    @ApiOperation("新商城订单迁移")
    @RequestMapping(value = "/mall", method = RequestMethod.POST)
    public Result mallTransfer(@RequestBody OrderDataReviseRequest request) {
        logger.info("mallTransfer start!");
        Result result = new Result<>();
        try {
            result = thirdOrderService.mallTransfer();
        } catch (Exception e) {
            logger.error("TransferController[mallTransfer]failed,request:{},cause by: {}", request, e);
            result.setException(ExceptionConstants.SYSTEM_ERROR);
        }
        return result;
    }


    @ApiOperation("宝珠展示订单迁移")
    @RequestMapping(value = "/baozhu", method = RequestMethod.POST)
    public Result baozhuTransfer(@RequestBody OrderDataReviseRequest request) {
        logger.info("baozhuTransfer start!");
        Result result = new Result<>();
        try {
            result = thirdOrderService.baozhuTransfer();
        } catch (Exception e) {
            logger.error("TransferController[baozhuTransfer]failed,request:{},cause by: {}", request, e);
            result.setException(ExceptionConstants.SYSTEM_ERROR);
        }
        return result;
    }

    @ApiOperation("卤味迁移到烘焙")
    @RequestMapping(value = "/luwei/baking", method = RequestMethod.POST)
    public Result cateringToBaking(@RequestBody OrderDataReviseRequest request) {
        logger.info("cateringToBaking start!");
        Result result = new Result<>();
        try {
            result = thirdOrderService.luWeiTransfer();
        } catch (Exception e) {
            logger.error("TransferController[cateringToBaking]failed,request:{},cause by: {}", request, e);
            result.setException(ExceptionConstants.SYSTEM_ERROR);
        }
        return result;
    }

    @ApiOperation("莫沫南路订单迁移")
    @RequestMapping(value = "/momo", method = RequestMethod.POST)
    public Result momoTransfer(@RequestBody OrderDataReviseRequest request) {
        logger.info("momoTransfer start!");
        Result result = new Result<>();
        try {
            result = transferService.momo();
        } catch (Exception e) {
            logger.error("TransferController[momoTransfer]failed,request:{},cause by: {}", request, e);
            result.setException(ExceptionConstants.SYSTEM_ERROR);
        }
        return result;
    }

    @ApiOperation("哆士屋订单迁移")
    @RequestMapping(value = "/duoshiwu", method = RequestMethod.POST)
    public Result duoshiwu(@RequestBody OrderDataReviseRequest request) {
        logger.info("duoshiwu start!");
        Result result = new Result<>();
        try {
            result = transferService.duoshiwu();
        } catch (Exception e) {
            logger.error("TransferController[duoshiwu]failed,request:{},cause by: {}", request, e);
            result.setException(ExceptionConstants.SYSTEM_ERROR);
        }
        return result;
    }

    @ApiOperation("哆士屋订单删除")
    @RequestMapping(value = "/duoshiwu/del", method = RequestMethod.POST)
    public Result duoshiwuDel(@RequestBody OrderDataReviseRequest request) {
        logger.info("duoshiwuDel start!");
        Result result = new Result<>();
        try {
            transferService.duoshiwuDel();
        } catch (Exception e) {
            logger.error("TransferController[duoshiwu]failed,request:{},cause by: {}", request, e);
            result.setException(ExceptionConstants.SYSTEM_ERROR);
        }
        return result;
    }

    @ApiOperation("业务库查询数据到临时库")
    @RequestMapping(value = "/sync", method = RequestMethod.POST)
    public Result selectOrderToTb(@RequestBody OrderDataReviseRequest request) {
        logger.info("selectOrderToTb start!");
        Result result = new Result<>();
        try {
            transferService.selectOrderToTb();
        } catch (Exception e) {
            logger.error("TransferController[selectOrderToTb]failed,request:{},cause by: {}", request, e);
            result.setException(ExceptionConstants.SYSTEM_ERROR);
        }
        return result;
    }


    @ApiOperation("陈香贵订单迁移")
    @RequestMapping(value = "/chen", method = RequestMethod.POST)
    public Result chenXiangGui(@RequestBody OrderDataReviseRequest request) {
        logger.info("chenXiangGui start!");
        Result result = new Result<>();
        try {
            result = transferService.chen();
        } catch (Exception e) {
            logger.error("TransferController[chenXiangGui]failed,request:{},cause by: {}", request, e);
            result.setException(ExceptionConstants.SYSTEM_ERROR);
        }
        return result;
    }

    @ApiOperation("陈香贵订单迁移删除")
    @RequestMapping(value = "/chen/del", method = RequestMethod.POST)
    public Result chenXiangGuiDel(@RequestBody OrderDataReviseRequest request) {
        logger.info("chenXiangGuiDel start!");
        Result result = new Result<>();
        try {
            result = transferService.chenDel();
        } catch (Exception e) {
            logger.error("TransferController[chenXiangGuiDel]failed,request:{},cause by: {}", request, e);
            result.setException(ExceptionConstants.SYSTEM_ERROR);
        }
        return result;
    }

}
