package cn.ezhizao.project.business.controller;

import cn.ezhizao.framework.web.controller.BaseController;
import cn.ezhizao.framework.web.page.TableDataInfo;
import cn.ezhizao.project.business.domain.*;
import cn.ezhizao.project.business.service.IBizDayworkService;
import cn.ezhizao.project.business.service.IBizLotTechnologicalProcessDetailService;
import cn.ezhizao.project.business.service.IBizTechnologicalProcessDetailService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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

@RestController
@RequestMapping("/business/technologicalProcess")
public class BizProcessController extends BaseController {
    @Resource
    IBizTechnologicalProcessDetailService bizTechnologicalProcessDetailService;
    @Resource
    IBizLotTechnologicalProcessDetailService bizLotTechnologicalProcessDetailService;
    @Resource
    IBizDayworkService bizDayworkService;

    @GetMapping("/list")
    public TableDataInfo list(BizDayworkItem bizDayworkItem) throws NoSuchFieldException, IllegalAccessException {
        BizDaywork bizDaywork = bizDayworkService.getById(bizDayworkItem.getDayworkId());
        if (bizDayworkItem.getIsAmend().equals(1) || bizDayworkItem.getIsWasteRecycling().equals(1L)) {
            // 是否是特殊批次
            List<BizLotTechnologicalProcessDetail> list = bizLotTechnologicalProcessDetailService.query().eq("lot_technological_process_id", bizDaywork.getTechnologicalProcessId()).orderByAsc("process_step_number").list();

            return getDataTable(list);
        } else {
            // 普通批次
            List<BizTechnologicalProcessDetail> list = bizTechnologicalProcessDetailService.query().eq("technological_process_id", bizDaywork.getTechnologicalProcessId()).ne("tenant_id", 9).orderByAsc("process_step_number").list();
            return getDataTable(list);
        }
    }

}
