package com.rongwei.bsserver.controller;


import com.rongwei.bscommon.sys.service.ApsProcessOperationProcessEquService;
import com.rongwei.bsentity.vo.ChangeStartTimeVo;
import com.rongwei.bsentity.vo.ChangingWiresVo;
import com.rongwei.bsentity.vo.CommonUpdateProductionStatusReq;
import com.rongwei.bsentity.vo.JobDetailsVo;
import com.rongwei.rwcommon.base.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
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;

/**
 * <p>
 * 生产订单-坯料计划-工序作业明细 前端控制器
 * </p>
 *
 * @author fpy
 * @since 2024-03-25
 */
@Slf4j
@RestController
@RequestMapping("/apsProcessOperationProcessEqu")
public class ApsProcessOperationProcessEquController {
    @Autowired
    private ApsProcessOperationProcessEquService apsProcessOperationProcessEquService;

    /**
     * 通用更新订单、坯料计划、工序作业的 生产状态 方法（根据传入的指定项目的ID，传入多个ID，根据最小粒度的ID）
     * 粒度划分从小到大：工序作业加工设备（作业明细）->工序作业->坯料计划->订单
     * 注：一切尘埃落定之后调用此接口，防止重复更新遗留在表单上的状态
     */
    @PostMapping("/commonUpdateProductionStatus")
    public R updateProductionStatus(@RequestBody CommonUpdateProductionStatusReq request) {
        try {
            log.info("更新生产状态;参数为：{}", request);
            return apsProcessOperationProcessEquService.updateProductionStatus(request);
        } catch (Exception e) {
            e.printStackTrace();
            return R.error("更新生产状态失败");
        }
    }

    /**
     * 换线作业
     * @param changingWiresVos
     * @return
     */
    @PostMapping("/changing-wires")
    public R changingWires(@RequestBody @Validated List<ChangingWiresVo> changingWiresVos){
        log.info("开始进行换线作业");
        return  apsProcessOperationProcessEquService.changingWires(changingWiresVos);
    }

    /**
     * 换线获取可选设备
     * @param operationJobDetailsId
     * @return
     */
    @PostMapping("/optional/equipment")
    public R getOptionalEquipment(@RequestBody List<String> operationJobDetailsId){
        log.info("换线获取可选设备");
        return  apsProcessOperationProcessEquService.getOptionalEquipment(operationJobDetailsId);
    }

    /**
     * 工序作业修改开始时间
     * @param changeStartTimeVo
     * @return
     */
    @PostMapping("/change/start-time")
    public R changeStartTime(@RequestBody @Validated List<ChangeStartTimeVo> changeStartTimeVo) {
        log.info("开修改工序作业开工时间");
        return  apsProcessOperationProcessEquService.changeStartTime(changeStartTimeVo);
    }

    /**
     * 修改作业详情
     * @return
     */
    @PostMapping("/update")
    public  R updateDetails(@RequestBody JobDetailsVo jobDetailsVo ){
        log.info("开修改作业详情");
        return  apsProcessOperationProcessEquService.updateDetails(jobDetailsVo);
    }
}

