package com.fizz.business.controller;

import cn.hutool.core.util.ObjectUtil;
import com.fizz.business.domain.CrmPdiPlan;
import com.fizz.business.domain.RollData;
import com.fizz.business.domain.RollHistory;
import com.fizz.business.form.RollHistoryForm;
import com.fizz.business.service.RollDataService;
import com.fizz.business.service.RollHistoryService;
import com.fizz.business.vo.OnlineRollDataVO;
import com.fizz.business.vo.ReadyRollDataVO;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.domain.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/roller")
@Tag(name="轧辊管理")
@Anonymous
public class RollerController {
    @Resource
    RollHistoryService rollHistoryService;

    @Resource
    RollDataService rollDataService;

    @GetMapping("/data/standby")
    @Operation(summary = "轧辊数据-获取当前备辊信息")
    public R<Map<String,ReadyRollDataVO>> getReadyRollList() {
        return R.ok(rollDataService.getAllReadyRollList());
    }

    @GetMapping("/data/ready/{position}/{type}")
    @Operation(summary = "轧辊数据-获取离线辊信息")
    public R<List<ReadyRollDataVO> > getOfflineRollList(@PathVariable String position, @PathVariable String type) {
        return R.ok(rollDataService.getReadyRollList(position,type,"OFFLINE"));
    }

    @GetMapping("/data/online")
    @Operation(summary = "轧辊数据-获取在线辊信息")
    public R<List<OnlineRollDataVO>> getOnlineRollList() {
        return R.ok(rollDataService.getOnlineRollList());
    }

    @PostMapping("/change/standby")
    @Operation(summary = "轧辊操作-备辊")
    public R<String> backupRoll(@RequestBody List<ReadyRollDataVO> rollList) {
        String msg = rollDataService.BackupRoll(rollList);
        if(ObjectUtil.isEmpty(msg)){
            return R.ok("处理成功");
        }
        else{
            return R.fail(msg);
        }
    }

    @PostMapping("/change/online")
    @Operation(summary = "轧辊操作-上线")
    public R<List<OnlineRollDataVO>> onlineRoll() {
        return R.ok(rollDataService.onlineRoll());
    }

    @GetMapping("/history/changeid")
    @Operation(summary = "轧辊历史-获取所有换辊号")
    public R<List<String>> getChangeIdList() {
        return R.ok(rollHistoryService.getChangeIdList());
    }

    @GetMapping("/history/rollid")
    @Operation(summary = "轧辊历史-获取所有轧辊号")
    public R<List<String>> getRollIdList() {
        return R.ok(rollHistoryService.getRollIdList());
    }

    @PostMapping("/history/list")
    @Operation(summary = "轧辊历史-获取换辊记录")
    public R<PageInfo<RollHistory>> getRollHistorytList(@RequestBody RollHistoryForm rollHistoryForm) {
        return R.ok(rollHistoryService.getRollHistory(rollHistoryForm));
    }
}
