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

import com.zm.order.tool.server.service.ThirdOrderTransfer2Service;
import com.zm.order.tool.server.service.ThirdOrderTransferService;
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;

import com.zm.order.tool.server.request.OrderDataReviseRequest;
import com.zm.order.tool.server.service.ExceptionConstants;
import com.zm.order.tool.server.service.ThirdOrderService;
import com.zm.util.dto.Result;

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

/**
 * 订单脚本
 * @author NianChang
 * @ClassName ScriptController
 * @date 2021/02/20 9:48 上午
 */
@Api(value = "三方订单迁移", tags = "三方订单迁移")
@RestController
@RequestMapping("/qapi/third/order")
public class ThirdOrderController {

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

    @Autowired
    private ThirdOrderService thirdOrderService;

    @Autowired
    private ThirdOrderTransferService transferService;

    @Autowired
    private ThirdOrderTransfer2Service transfer2Service;

    @ApiOperation("新增雪沥订单")
    @RequestMapping(value = "/xueli/insert", method = RequestMethod.POST)
    public Result xueliOrder(@RequestBody OrderDataReviseRequest request) {
        logger.info("xueliOrder start!");
        Result result = new Result<>();
        try {
            result = thirdOrderService.xueliOrder();
        } catch (Exception e) {
            logger.error("TemporaryController[xueliOrder]failed,request:{},cause by: {}", request, e);
            result.setException(ExceptionConstants.SYSTEM_ERROR);
        }
        return result;
    }

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

    @ApiOperation("变更用户id")
    @RequestMapping(value = "/update/user", method = RequestMethod.POST)
    public Result updateUserId(@RequestBody OrderDataReviseRequest request) {
        logger.info("updateUserId start!");
        Result result = new Result<>();
        try {
            result = thirdOrderService.updateUserId();
        } catch (Exception e) {
            logger.error("TemporaryController[updateUserId]failed,request:{},cause by: {}", request, e);
            result.setException(ExceptionConstants.SYSTEM_ERROR);
        }
        return result;
    }

    @ApiOperation("雪沥订单变更门店id")
    @RequestMapping(value = "/update/store", method = RequestMethod.POST)
    public Result updateStore(@RequestBody OrderDataReviseRequest request) {
        logger.info("updateStore start!");
        Result result = new Result<>();
        try {
            result = thirdOrderService.updateStore();
        } catch (Exception e) {
            logger.error("TemporaryController[updateStore]failed,request:{},cause by: {}", request, e);
            result.setException(ExceptionConstants.SYSTEM_ERROR);
        }
        return result;
    }

    @ApiOperation("挪瓦订单迁移")
    @RequestMapping(value = "/muowa/transfer", method = RequestMethod.POST)
    public Result transferNuo(@RequestBody OrderDataReviseRequest request) {
        logger.info("transferNuo start!");
        Result result = new Result<>();
        try {
            transferService.nuowaOrder();
        } catch (Exception e) {
            logger.error("TemporaryController[transferNuo]failed,request:{},cause by: {}", request, e);
            result.setException(ExceptionConstants.SYSTEM_ERROR);
        }
        return result;
    }
    
    @ApiOperation("吾饮订单迁移")
    @RequestMapping(value = "/wuyin/transfer", method = RequestMethod.POST)
    public Result transferWuYin(@RequestBody OrderDataReviseRequest request) {
        logger.info("transferWuYin start!");
        Result result = new Result<>();
        try {
            transferService.wuYinOrder();
        } catch (Exception e) {
            logger.error("TemporaryController[transferNuo]failed,request:{},cause by: {}", request, e);
            result.setException(ExceptionConstants.SYSTEM_ERROR);
        }
        return result;
    }

    @ApiOperation("吾饮订单删除")
    @RequestMapping(value = "/wuyin/del", method = RequestMethod.POST)
    public Result delWuyinOrder(@RequestBody OrderDataReviseRequest request) {
        logger.info("delWuyinOrder start!");
        Result result = new Result<>();
        try {
            transferService.delWuyinOrder();
        } catch (Exception e) {
            logger.error("TemporaryController[delWuyinOrder]failed,request:{},cause by: {}", request, e);
            result.setException(ExceptionConstants.SYSTEM_ERROR);
        }
        return result;
    }
    
    @ApiOperation("吾饮积分订单迁移")
    @RequestMapping(value = "/wuyin/transfer/jifeng", method = RequestMethod.POST)
    public Result wuYinOrderJiFeng(@RequestBody OrderDataReviseRequest request) {
        logger.info("transferWuYin start!");
        Result result = new Result<>();
        try {
            transferService.wuYinOrderJiFeng();
        } catch (Exception e) {
            logger.error("TemporaryController[transferNuo]failed,request:{},cause by: {}", request, e);
            result.setException(ExceptionConstants.SYSTEM_ERROR);
        }
        return result;
    }


    @ApiOperation("吾饮积分订单删除")
    @RequestMapping(value = "/wuyin/del/jifeng", method = RequestMethod.POST)
    public Result delWuyinOrderJiFeng(@RequestBody OrderDataReviseRequest request) {
        logger.info("delWuyinOrderJiFeng start!");
        Result result = new Result<>();
        try {
            transferService.delWuyinOrderJiFeng();
        } catch (Exception e) {
            logger.error("TemporaryController[delWuyinOrderJiFeng]failed,request:{},cause by: {}", request, e);
            result.setException(ExceptionConstants.SYSTEM_ERROR);
        }
        return result;
    }

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

    @ApiOperation("犟骨头订单迁移")
    @RequestMapping(value = "/gutou/transfer", method = RequestMethod.POST)
    public Result gutouOrder(@RequestBody OrderDataReviseRequest request) {
        logger.info("gutouOrder start!");
        Result result = new Result<>();
        try {
            transfer2Service.gutouOrder();
        } catch (Exception e) {
            logger.error("TemporaryController[gutouOrder]failed,request:{},cause by: {}", request, e);
            result.setException(ExceptionConstants.SYSTEM_ERROR);
        }
        return result;
    }

    @ApiOperation("犟骨头订单删除")
    @RequestMapping(value = "/gutou/del", method = RequestMethod.POST)
    public Result delGuTouOrder(@RequestBody OrderDataReviseRequest request) {
        logger.info("gutouOrder start!");
        Result result = new Result<>();
        try {
            transfer2Service.delGuTouOrder();
        } catch (Exception e) {
            logger.error("TemporaryController[gutouOrder]failed,request:{},cause by: {}", request, e);
            result.setException(ExceptionConstants.SYSTEM_ERROR);
        }
        return result;
    }

    @ApiOperation("宝珠订单删除")
    @RequestMapping(value = "/baozhu/del", method = RequestMethod.POST)
    public Result baozhuOrderDel(@RequestBody OrderDataReviseRequest request) {
        logger.info("baozhuOrderDel start!");
        Result result = new Result<>();
        try {
            transfer2Service.delBaozhuOrder();
        } catch (Exception e) {
            logger.error("TemporaryController[baozhuOrderDel]failed,request:{},cause by: {}", request, e);
            result.setException(ExceptionConstants.SYSTEM_ERROR);
        }
        return result;
    }

    @ApiOperation("宝珠退款单迁移")
    @RequestMapping(value = "/baozhu/transfer/refund", method = RequestMethod.POST)
    public Result baozhuRefund(@RequestBody OrderDataReviseRequest request) {
        logger.info("baozhuOrder start!");
        Result result = new Result<>();
        try {
            transfer2Service.baozhuRefund();
        } catch (Exception e) {
            logger.error("TemporaryController[baozhuOrder]failed,request:{},cause by: {}", request, e);
            result.setException(ExceptionConstants.SYSTEM_ERROR);
        }
        return result;
    }

    @ApiOperation("吾饮店铺、用户变更")
    @RequestMapping(value = "/update/seller/wuyin", method = RequestMethod.POST)
    public Result wuyinChange(@RequestBody OrderDataReviseRequest request) {
        logger.info("wuyinChange start!");
        Result result = new Result<>();
        try {
            transfer2Service.wuyinChange();
        } catch (Exception e) {
            logger.error("ThirdOrderController[wuyinChange]failed,request:{},cause by: {}", request, e);
            result.setException(ExceptionConstants.SYSTEM_ERROR);
        }
        return result;
    }

}
