package com.rongwei.controller;

import com.rongwei.bscommon.sys.service.impl.MesEQUDataSyncServiceImpl;
import com.rongwei.bscommon.sys.service.impl.MesOPRDataSyncServiceImpl;
import com.rongwei.bscommon.sys.service.impl.MesQUADataSyncServiceImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * MesDataSyncController class
 *
 * @author XH
 * @date 2023/03/25
 */
@RestController
@RequestMapping("/mes-sync")
@RefreshScope
public class MesDataSyncController {
    private final Logger log = LoggerFactory.getLogger(this.getClass().getName());
    @Autowired
    private MesQUADataSyncServiceImpl mesQUADataSyncService;
    @Autowired
    private MesOPRDataSyncServiceImpl mesOPRDataSyncService;
    @Autowired
    private MesEQUDataSyncServiceImpl mesEQUDataSyncService;
    /**
     * 质量报废
     *
     * @param startDate
     * @param endDate
     * @return
     */
    @PostMapping("/qua")
    public void syncQUAData(@RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date startDate,
                            @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date endDate) {
        log.info("质量报废接口入参：开始时间:{}, 结束时间:{}", startDate, endDate);
        mesQUADataSyncService.syncMesData(startDate, endDate);
    }
    /**
     * 生产损失
     *
     * @param startDate
     * @param endDate
     * @return
     */
    @PostMapping("/opr")
    public void syncOPRData(@RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date startDate,
                            @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date endDate) {
        log.info("生产损失接口入参：开始时间:{}, 结束时间:{}", startDate, endDate);
        mesOPRDataSyncService.syncMesData(startDate, endDate);
    }
    /**
     * 设备故障
     *
     * @param startDate
     * @param endDate
     * @return
     */
    @PostMapping("/equ")
    public void syncEQUData(@RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date startDate,
                            @RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date endDate) {
        log.info("设备故障接口入参：开始时间:{}, 结束时间:{}", startDate, endDate);
        mesEQUDataSyncService.syncMesData(startDate, endDate);
    }
}
