package net.vtstar.zhongtong.avi.monitoring.controller;

import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import net.vtstar.user.search.controller.vo.SearchVo;
import net.vtstar.utils.domain.Return;
import net.vtstar.zhongtong.avi.monitoring.domain.StationPassInfo;
import net.vtstar.zhongtong.avi.monitoring.service.StationPassInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: xiadongwei
 * @Date: 2020/3/5 14:10
 */
@Slf4j
@Api(description = "过站信息模块")
@RestController
@RequestMapping("/pass")
public class StationPassInfoController {

    @Autowired
    private StationPassInfoService passInfoService;

    @ApiOperation(value = "报工点补扫--查询所有待补扫的过站记录", notes =
            "字段含义：\n{\n" +
            "  \"VIN\": \"工单号, 字符串类型\",\n" +
            "  \"stationName\": \"报工点，字符串类型\",\n" +
            "  \"stationNo\": \"工位编码，字符串类型\",\n" +
            "  \"passTime\": \"过站时间，时间类型\"\n" +
            "  \"createBy\": \"操作人，字符串类型\"\n" +
            "}")
    @PostMapping("/findPassInfoByNoFind")
    public Return findPassInfoByNoFind(){
        List<StationPassInfo> list = passInfoService.findPassInfoByNoFind();
        return Return.success(list);
    }

    @ApiOperation(value = "查询过站记录", notes = "使用通用搜索组件，searchCode：PASS_INFO\n" +
            "字段含义：\n{\n" +
            "  \"VIN\": \"工单号, 字符串类型\",\n" +
            "  \"stationName\": \"报工点，字符串类型\",\n" +
            "  \"stationNo\": \"工位编码，字符串类型\",\n" +
            "  \"passTime\": \"过站时间，时间类型\"\n" +
            "  \"createBy\": \"操作人，字符串类型\"\n" +
            "}")
    @PostMapping("/findPassInfoBySearchCode")
    public Return findPassInfoBySearchCode(@RequestBody SearchVo searchVo){
        List<StationPassInfo> list = passInfoService.findPassInfoBySearchCode(searchVo.toJSONObject());
        return Return.success(new PageInfo<>(list));
    }

    @ApiOperation(value = "根据报工点获取工位编码")
    @GetMapping("/getStationNo/{stationName}")
    public Return getStationNoByName(@PathVariable("stationName") String stationName){
        String[] stationNo = passInfoService.getStationNoByName(stationName);
        return Return.success(stationNo);
    }

    @ApiOperation(value = "保存缺失的过站记录", notes = "字段含义：\n{\n" +
            "  \"VIN\": \"工单号, 字符串类型\",\n" +
            "  \"stationName\": \"报工点，字符串类型\",\n" +
            "  \"stationNo\": \"工位编码，字符串类型\",\n" +
            "  \"createTime\": \"过站时间，字符串类型\"\n" +
            "  \"createBy\": \"操作人，字符串类型\"\n" +
            "}")
    @PostMapping("/savePassInfo")
    public Return savePassInfo(@RequestBody StationPassInfo stationPassInfo){
        passInfoService.savePassInfo(stationPassInfo);
        return Return.success();
    }

    @ApiOperation(value = "自动补扫开启")
    @GetMapping("/startReplenishScan")
    public Return startReplenishScan(@RequestParam Integer beginTimeInt,
                                     @RequestParam Integer endTimeInt){
        passInfoService.startReplenishScan(beginTimeInt, endTimeInt);
        return Return.success();
    }

    @ApiOperation(value = "自动补扫关闭")
    @GetMapping("/stopReplenishScan")
    public Return stopReplenishScan(){
        passInfoService.stopReplenishScan();
        return Return.success();
    }
}
