package com.reptileclient.jlifeapp.web;

import com.reptileclient.jlifeapp.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

@RestController
public class SyncController {

    @Autowired
    private QGOrderSyncService qgOrderSyncService;

    @Autowired
    private HMClueSyncService hmClueSyncService;

    @Autowired
    private DownLoadEmailDataService downLoadEmailDataService;

    @Autowired
    private HmShopAndStationRelationService relationService;

    @Resource
    private HmBookTradeOrderService hmBookTradeOrderService;

    @Autowired
    HmEncryptPhoneRepairService encryptPhoneRepairService;

//    @GetMapping("/syncRunTask")
//    public void test() {
//        new Thread(() -> hmBookTradeOrderService.addHmBookTradeList()).start();
//    }

    @GetMapping("/syncqgOrder")
    public void runTask() {
        System.out.println("开始同步勤鸽订单信息");
        qgOrderSyncService.syncOrder();
    }

    @GetMapping("/syncCityQgOrder")
    public void test(@RequestParam(value = "shopId", defaultValue = "10000257", required = false) String shopId) {
        Runnable a = () -> qgOrderSyncService.recoupQgCityData(shopId);
        new Thread(a).start();
    }

    @GetMapping("/syncCityQg")
    public void syncCityQg() {
        Runnable a = () -> qgOrderSyncService.syncQGSHOrder();
        new Thread(a).start();
    }

    @GetMapping("/syncHMClue")
    public void syncHMClue() {
        Runnable a = () -> hmClueSyncService.syncClue();
        new Thread(a).start();

    }

    @GetMapping("/syncdownLoadEmailData")
    public void syncdownLoadEmailData(@RequestParam(value = "day", required = false) String thisDay) {
        if (null == thisDay) {
            thisDay = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        }
        String x = LocalDateTime.parse(thisDay + "T00:00:00").format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        String y = LocalDateTime.parse(thisDay + "T23:59:59").format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        Runnable a = () -> downLoadEmailDataService.downLoad(x, y);
        new Thread(a).start();
    }

    //手动同步某个订单的最新状态
    @GetMapping("/syncOnePersonOrderStatus")

    public Object syncOnePersonOrderStatus(@RequestParam(value = "orderNo") String orderNo) {
        return relationService.syncOnePersonOrderStatus(orderNo);
    }

    @GetMapping("/syncJxOrder")
    public Object syncJxOrder() {
        relationService.synctagPayOrderInfo();
        return "success";
    }

    @GetMapping("/xiufu")
    public void xiufu() {
        Runnable a = () -> encryptPhoneRepairService.repair();;
        new Thread(a).start();

    }
}
