package com.malk.jianhui.controller;

import com.malk.jianhui.config.KDWebApiConf;
import com.malk.jianhui.service.JianhuiService;
import com.malk.server.common.McR;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
public class JianhuiController {

    @Autowired
    private JianhuiService jianhuiService;

    @GetMapping("/test")
    public McR test(){
        return McR.success();
    }

    //新增销售订单
    @PostMapping("/saveSaleOrder")
    public McR saveSaleOrder(@RequestBody Map map) {
        return jianhuiService.saveSaleOrder(map);
    }

    //新增预测单
    @PostMapping("/saveForecastOrder")
    public McR saveForecastOrder(@RequestBody Map map) {
        return jianhuiService.saveForecastOrder(map);
    }

    //新增不良品处理单
    @PostMapping("/saveDefectiveOrder")
    public McR saveDefectiveOrder(@RequestBody Map map) {
        return jianhuiService.saveDefectiveOrder(map);
    }

    //定时同步客户
    @GetMapping("/syncCustomers")
    public McR syncCustomers(){
        return jianhuiService.syncCustomers();
    }

    //定时同步业务员
    @GetMapping("/syncSalesman")
    public McR syncSalesman(){
        return jianhuiService.syncSalesman();
    }

    //定时同步物料
    @GetMapping("/syncMaterial")
    public McR syncMaterial(){
        return jianhuiService.syncMaterial();
    }

    //定时同步供应商
    @GetMapping("/syncSupplier")
    public McR syncSupplier(){
        return jianhuiService.syncSupplier();
    }

    //定时同步销售价目表
    @GetMapping("/syncSalePrice")
    public McR syncSalePrice(){
        return jianhuiService.syncSalePrice();
    }

    //金蝶同步采购订单 每半小时同步一次
    @Scheduled(cron = "0 0/30 * * * ?")
    @GetMapping("/syncPurchaseOrder")
    public McR syncPurchaseOrder() {
        return jianhuiService.syncPurchaseOrder();
    }

    //审核采购订单
    @PostMapping("/auditPurchaseOrder")
    public McR auditPurchaseOrder(@RequestBody Map map) {
        return jianhuiService.auditPurchaseOrder(map);
    }

    //金蝶同步检验单
    @Scheduled(cron = "0 0/30 * * * ?")
    @GetMapping("/syncInspectionOrder")
    public McR syncInspectionOrder() {
        return jianhuiService.syncInspectionOrder();
    }

    //每天1点同步所有数据
    @Scheduled(cron = "0 0 1 * * ?")
    @GetMapping("/syncData")
    public McR syncData(){
        return jianhuiService.syncData();
    }

    @GetMapping("/manualSyncData")
    public McR manualSyncData(String userId){
        jianhuiService.manualSyncData(userId);
        return McR.success();
    }

    @GetMapping("/manualSyncMaterialData")
    public McR manualSyncMaterialData(String userId,String startTime,String endTime){
        jianhuiService.manualSyncMaterialData(userId,startTime,endTime);
        return McR.success();
    }



}
