package com.rongwei.bsserver.controller;

import com.rongwei.bscommon.sys.service.impl.GanttServiceImpl;
import com.rongwei.bsentity.vo.GanttVos;
import com.rongwei.bsentity.vo.ProcessGanttListVo;
import com.rongwei.rwcommon.base.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * GanttController class
 *
 * @author XH
 * @date 2024/03/25
 */
@RestController
@RequestMapping("/gantt")
public class GanttController {

    private final Logger log = LoggerFactory.getLogger(this.getClass().getName());
    @Autowired
    private GanttServiceImpl ganttService;

    /**
     * 根据条件获取甘特图相关信息
     * @return
     */
    @GetMapping("/list")
    @Deprecated
    public R updateRelevantInformation(@RequestParam(name = "startTime", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date searchDate,
                                       @RequestParam(name = "factoryId") String factoryId,
                                       @RequestParam(name = "workshopId", required = false) String workshopId,
                                       @RequestParam(name = "orderNo",required = false) String orderNo) {
//        return ganttService.getListByCondition(searchDate, factoryId, workshopId,orderNo);
        return R.ok();
    }

    /**
     * 根据条件获取甘特图相关信息
     * @param processGanttListVo
     * @return
     */
    @PostMapping("/processGanttList")
    public R processGanttList(@RequestBody ProcessGanttListVo processGanttListVo) {
        return ganttService.getListByCondition(processGanttListVo.getStartTime(),processGanttListVo.getEndTime(), processGanttListVo.getFactoryId(),
                processGanttListVo.getWorkshopId(), processGanttListVo.getOrderNo(),
                processGanttListVo.getProductionLineId(), processGanttListVo.getEquId(),
                processGanttListVo.getProductionLineName(),processGanttListVo.getEquName());
    }

    /**
     * 获取下个作业（可能有多个）
     * @param ganttVosList
     * @return
     */
    @PostMapping("/getNextProcess")
    public R getNextProcess(@RequestBody List<GanttVos> ganttVosList){
        List<GanttVos> nexts = ganttService.getNextProcess(ganttVosList, "next");
        return R.ok(nexts);
    }

    /**
     * 获取上个作业（可能有多个）
     * @param ganttVosList
     * @return
     */
    @PostMapping("/getPreProcess")
    public R getPreProcess(@RequestBody List<GanttVos> ganttVosList){
        List<GanttVos> pres = ganttService.getNextProcess(ganttVosList, "pre");
        return R.ok(pres);
    }

}
