package com.rongwei.bsserver.controller;

import com.rongwei.bscommon.sys.service.ApsProductionOrderService;
import com.rongwei.bsentity.domain.ApsProductionOrderDo;
import com.rongwei.bsentity.domain.ApsProductionTechnicalRequirementDo;
import com.rongwei.bsentity.vo.CheckAndSaveOrUpdateOrderReq;
import com.rongwei.bsentity.vo.DeleteOrderVo;
import com.rongwei.rwcommon.base.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
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.List;

/**
 * ApsProductionOrderController class
 *
 * @author XH
 * @date 2024/04/18
 */
@RestController
@RequestMapping("/product-order")
public class ApsProductionOrderController {
    private final Logger log = LoggerFactory.getLogger(this.getClass().getName());

    @Autowired
    private ApsProductionOrderService apsProductionOrderService;

    /**
     * 发布
     *
     * @param productionOrderIds
     * @return
     */
    @PostMapping("/publish")
    public R publish(@RequestBody List<String> productionOrderIds) {
        return apsProductionOrderService.publish(productionOrderIds);
    }

    /**
     * 取消发布
     *
     * @param productionOrderIds
     * @return
     */
    @PostMapping("/publish/cancel")
    public R publishCancel(@RequestBody List<String> productionOrderIds) {
        return apsProductionOrderService.publishCancel(productionOrderIds);
    }

    /**
     * 订单评审，提交计划评审（校验和保存）
     */
    @PostMapping("/checkAndSaveOrUpdateOrder")
    public R checkAndSaveOrUpdateOrder(@RequestBody CheckAndSaveOrUpdateOrderReq req) {

        log.info("订单评审，提交计划评审（校验和保存），入参为:{}", req);
        return apsProductionOrderService.checkAndSaveOrUpdateOrder(req);
    }

    /*
    订单未及时评审提醒
     */
    @PostMapping("/orderOuttimeAudit")
    public void orderOuttimeAudit() {
        apsProductionOrderService.orderOuttimeAudit();
    }

    /**
     * 调整订单时打开编辑页之前的操作（废弃）
     */
    @PostMapping("/changeOrder")
    public R changeOrder(@RequestBody ApsProductionOrderDo req) {
        return apsProductionOrderService.changeOrder(req);
    }

    /*
    辅料申购提醒
     */
    @PostMapping("/auxiliaryMaterial")
    public void auxiliaryMaterial() {
        apsProductionOrderService.auxiliaryMaterial();
    }

    /*
    作业延期提醒
     */
    @PostMapping("/processDelay")
    public void processDelay() {
        apsProductionOrderService.processDelay();
    }

    /**
     * 删除订单评审
     */
    @PostMapping("/deleteOrder")
    public R deleteOrder(@RequestBody DeleteOrderVo req) {
        return apsProductionOrderService.deleteOrder(req);
    }

    /*
    报工不合格提醒
     */
    @PostMapping("/reportUnqualify")
    public void reportUnqualify() {
        apsProductionOrderService.reportUnqualify();
    }


    /**
     * 撤回成功后保存历史数据
     */
    @PostMapping("/saveHistoryInfo")
    public R saveHistoryInfo(@RequestBody String id) {
        try {
            return apsProductionOrderService.saveHistoryInfo(id);
        } catch (Exception e) {
            e.printStackTrace();
            return R.error("保存历史版本失败");
        }
    }
}
