package cn.com.countrygarden.bi.main.controller.dataMigration;

import cn.com.countrygarden.bi.main.model.dataMigration.DispatchRecord;
import cn.com.countrygarden.bi.main.service.dataMigration.*;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by ADMS on 2018/7/17.
 */
@RestController
@RequestMapping("/dataMigration")
public class DataMigrationController {
    @Autowired
    private DataMigrationHandle dataMigrationHandle;
    @Autowired
    private DispatchRecordService dispatchRecordService;
    @Autowired
    private BdPsndocService bdPsndocService;
    @Autowired
    private HiPsnJobService hiPsnJobService;
    @Autowired
    private BdTypeService bdTypeService;
    @Autowired
    private HiPsndocWorkService hiPsndocWorkService;
    @Autowired
    private HiPsndocTrainService hiPsndocTrainService;

    protected final org.slf4j.Logger logger = LoggerFactory.getLogger(DataMigrationController.class);

    //private ExecutorService executorService = Executors.newFixedThreadPool(10);

    @GetMapping("/doc")
    public String getBdPsndocMigration(Integer start, Integer end, Integer pageSize, Integer nThreads) {
        dataMigrationHandle.docHandle(pageSize, nThreads);
        return "success";
    }

    @GetMapping("/job")
    public String getHiPsnJobMigration(Integer start, Integer end, Integer pageSize, Integer nThreads) {
        dataMigrationHandle.jobHandle(pageSize, nThreads);
        return "success";
    }

    @GetMapping("/work")
    public String getWorkMigration(Integer start, Integer end, Integer pageSize, Integer nThreads) {
        dataMigrationHandle.workHandle(pageSize, nThreads);
        return "success";
    }

    @GetMapping("/train")
    public String getTrainMigration(Integer start, Integer end, Integer pageSize, Integer nThreads) {
        dataMigrationHandle.trainHandle(pageSize, nThreads);
        return "success";
    }

    @GetMapping("/type")
    public String getBdPsnjobMigration(Integer start, Integer end, Integer pageSize, Integer nThreads, String all) {
        dataMigrationHandle.typeHandle(pageSize, nThreads);
        return "success";
    }

    /**
     * doc
     * type
     * job
     * <p>
     * work
     * train
     *
     * @param start
     * @param end
     * @param pageSize
     * @param nThreads
     * @return
     */
    @GetMapping("/all")
    public String getAllMigration(String code) {
        if ("doc".equals(code)) {
            return "" + bdPsndocService.getTotal();
        } else if ("job".equals(code)) {
            return "" + hiPsnJobService.getTotal();
        } else if ("work".equals(code)) {
            return "" + hiPsndocWorkService.getTotal();
        } else if ("train".equals(code)) {
            return "" + hiPsndocTrainService.getTotal();
        } else if ("type".equals(code)) {
            return "" + bdTypeService.getTotal();
        } else {
            return "error";
        }
    }

    @GetMapping("/rec")
    private List<DispatchRecord> dispatchRecordList(DispatchRecord rec) {
        List<DispatchRecord> dispatchRecords = dispatchRecordService.select(rec.getStartDate(), rec.getEndDate());
        return dispatchRecords;
    }

}
