package com.scm.contract.web.print;

import com.scm.contract.model.print.PrintManagement;
import com.scm.contract.service.apply.LabelApplicationDetailService;
import com.scm.contract.service.print.PrintCodeService;
import com.scm.contract.service.print.PrintManagementService;
import com.set.direwolf.core.mybatis.Page;
import com.set.direwolf.core.web.OperationResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author zuo
 * @date 2024/6/27 18:10
 */
@Controller
@RequestMapping("${adminPath}/print/management")
public class PrintManagementController {
    @Autowired
    private LabelApplicationDetailService labelApplicationDetailService;

    @Autowired
    private PrintManagementService entityService;

    @Autowired
    private PrintCodeService printCodeService;

    @PostMapping("/page")
    public @ResponseBody OperationResult page(@RequestBody PrintManagement entity, HttpServletRequest request, HttpServletResponse response) {
        entity.setIsPrint(1);
        Page<PrintManagement> page = Page.bootstrapPage(request, response);
        return OperationResult.buildSuccessResult("获取分页查询信息成功", entityService.findPage(page, entity));
    }

    @PostMapping("/cancel/{id}")
    public @ResponseBody OperationResult cancelPrint(@PathVariable("id") String id) {
        return OperationResult.buildSuccessResult("取消打印成功", printCodeService.cancelPrint(id));
    }

    @PostMapping("/pause/{id}")
    public @ResponseBody OperationResult pausePrint(@PathVariable("id") String id) {
        return OperationResult.buildSuccessResult("暂停打印成功", printCodeService.changePrintStatus(id,
                "/api/print/pause/", 2));
    }

    @PostMapping("/continue/{id}")
    public @ResponseBody OperationResult continuePrint(@PathVariable("id") String id) {
        return OperationResult.buildSuccessResult("继续打印成功", printCodeService.changePrintStatus(id,
                "/api/print/continue/", 1001));
    }

    @PostMapping("/continue/all")
    public @ResponseBody OperationResult continueALLPrint() {
        return OperationResult.buildSuccessResult("继续打印成功", printCodeService.continueALLPrint());
    }
}
