package com.fjhx.mes.controller;

import com.fjhx.mes.entity.work.dto.WorkOrderDto;
import com.fjhx.mes.service.DeviceOpenService;
import com.ruoyi.common.core.domain.AjaxResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@Slf4j
@RestController
@RequestMapping("/open/device")
public class DeviceOpenController {


    @Autowired
    private DeviceOpenService deviceOpenService;

    /**
     * 开始生产
     */
    @PostMapping("/startProduction")
    public AjaxResult startProduction(@RequestBody WorkOrderDto dto) {
        try {
            AjaxResult success = AjaxResult.success("success", deviceOpenService.startProduction(dto));
            success.put("success", true);
            return success;
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            AjaxResult error = AjaxResult.error(e.getMessage(), new HashMap<>());
            error.put("success", false);
            return error;
        }
    }

    /**
     * 结束生产
     */
    @PostMapping("/endProduction")
    public AjaxResult endProduction(@RequestBody WorkOrderDto dto) {
        try {
            deviceOpenService.endProduction(dto);
            AjaxResult success = AjaxResult.success("success", new HashMap<>());
            success.put("success", true);
            return success;
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            AjaxResult error = AjaxResult.error(e.getMessage(), new HashMap<>());
            error.put("success", false);
            return error;
        }
    }
}
