package org.jeecg.modules.api.workorderController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.apiBean.PageBean;
import org.jeecg.modules.apiBean.QueryTemplateBean;
import org.jeecg.modules.apiBean.UpdateTemplateBean;
import org.jeecg.modules.apiService.TemplateService;
import org.jeecg.modules.workorderGeneralStepfour.entity.WorkorderGeneralStepfour;
import org.jeecg.modules.workorderGeneralStepone.entity.WorkorderGeneralStepone;
import org.jeecg.modules.workorderGeneralStepthree.entity.WorkorderGeneralStepthree;
import org.jeecg.modules.workorderGeneralSteptwo.entity.WorkorderGeneralSteptwo;
import org.jeecg.modules.workorderParamStepfour.entity.WorkorderParamStepfour;
import org.jeecg.modules.workorderParamStepone.entity.WorkorderParamStepone;
import org.jeecg.modules.workorderParamStepthree.entity.WorkorderParamStepthree;
import org.jeecg.modules.workorderParamSteptwo.entity.WorkorderParamSteptwo;
import org.jeecg.modules.workorderStepfour.entity.WorkorderStepfour;
import org.jeecg.modules.workorderStepone.entity.WorkorderStepone;
import org.jeecg.modules.workorderStepthree.entity.WorkorderStepthree;
import org.jeecg.modules.workorderSteptwo.entity.WorkorderSteptwo;
import org.jeecg.modules.workorderTemplate.entity.WorkorderTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

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

@Api(tags="工单信息相关接口")
@RestController
@RequestMapping("/workorder/template")
@Slf4j
public class TemplateController {

    //工单信息
    @Resource
    private TemplateService templateService;
    /****************************************************************************************************/

    /**************************************工单**********************************************************/
    @ApiOperation(value="工单信息-查询工单列表", notes="工单信息-查询工单列表")
    @RequestMapping(value = "/queryTemplateList", method = {RequestMethod.GET})
    public Result<?> queryTemplateList(QueryTemplateBean templateBean, PageBean pageBean){
        return templateService.queryTemplateList(templateBean, pageBean);
    }

    @ApiOperation(value="工单信息-根据id查询工单详情", notes="工单信息-根据id查询工单详情")
    @RequestMapping(value = "/queryTemplateById", method = {RequestMethod.GET})
    public Result<?> queryTemplateById(String templateId){
        return templateService.queryTemplateById(templateId);
    }

    @ApiOperation(value="工单信息-修改工单", notes="工单信息-修改工单")
    @RequestMapping(value = "/updateTemplate", method = {RequestMethod.POST})
    public Result<?> updateTemplate(UpdateTemplateBean templateBean){

        //返回信息
        String message = "";

        //将注册信息注入到实体bean中
        WorkorderTemplate workorderTemplate = new WorkorderTemplate();
        workorderTemplate.setId(templateBean.getId());
        workorderTemplate.setNumber(templateBean.getNumber());
        workorderTemplate.setRemark(templateBean.getRemark());
        workorderTemplate.setStatusId(templateBean.getStatusId());

        if(StringUtils.isEmpty(templateBean.getId())){
            message = "工单id未填写，请填写工单id!";
        }else if(StringUtils.isEmpty(templateBean.getNumber().toString())){
            message = "数量未填写，请填写数量";
        }else if(StringUtils.isEmpty(templateBean.getStatusId())){
            message = "状态id未填写，请填写状态id";
        }else {
            return templateService.updateTemplate(workorderTemplate);
        }

        return Result.error(message);
    }

    /**************************************工序**********************************************************/
    @ApiOperation(value="工单信息-工序卡1(选配)详情", notes="工单信息-工序卡1(选配)详情")
    @RequestMapping(value = "/queryStepOne", method = {RequestMethod.GET})
    public Result<?> queryStepOne(String templateId){
        return templateService.queryStepOne(templateId);
    }

    @ApiOperation(value="工单信息-工序卡2详情", notes="工单信息-工序卡2详情")
    @RequestMapping(value = "/queryStepTwo", method = {RequestMethod.GET})
    public Result<?> queryStepTwo(String templateId){
        return templateService.queryStepTwo(templateId);
    }

    @ApiOperation(value="工单信息-工序卡3详情", notes="工单信息-工序卡3详情")
    @RequestMapping(value = "/queryStepThree", method = {RequestMethod.GET})
    public Result<?> queryStepThree(String templateId){
        return templateService.queryStepThree(templateId);
    }

    @ApiOperation(value="工单信息-工序卡4(总成)详情", notes="工单信息-工序卡4(总成)详情")
    @RequestMapping(value = "/queryStepFour", method = {RequestMethod.GET})
    public Result<?> queryStepFour(String templateId){
        return templateService.queryStepFour(templateId);
    }

    @ApiOperation(value="工单信息-修改常规参数-工序卡1(选配)", notes="工单信息-修改常规参数-修改工序卡1(选配)")
    @RequestMapping(value = "/updateGeneralStepOne", method = {RequestMethod.POST})
    public Result<?> updateGeneralStepOne(WorkorderGeneralStepone generalStepone){
        return templateService.updateGeneralStepOne(generalStepone);
    }

    @ApiOperation(value="工单信息-修改常规参数-工序卡2", notes="工单信息-修改常规参数-修改工序卡2")
    @RequestMapping(value = "/updateGeneralStepTwo", method = {RequestMethod.POST})
    public Result<?> updateGeneralStepTwo(WorkorderGeneralSteptwo generalSteptwo){
        return templateService.updateGeneralStepTwo(generalSteptwo);
    }

    @ApiOperation(value="工单信息-修改常规参数-工序卡3", notes="工单信息-修改常规参数-修改工序卡3")
    @RequestMapping(value = "/updateGeneralStepThree", method = {RequestMethod.POST})
    public Result<?> updateGeneralStepThree(WorkorderGeneralStepthree generalStepthree){
        return templateService.updateGeneralStepThree(generalStepthree);
    }

    @ApiOperation(value="工单信息-修改常规参数-工序卡4(总成)", notes="工单信息-修改常规参数-修改工序卡4(总成)")
    @RequestMapping(value = "/updateGeneralStepFour", method = {RequestMethod.POST})
    public Result<?> updateGeneralStepFour(WorkorderGeneralStepfour generalStepfour){
        return templateService.updateGeneralStepFour(generalStepfour);
    }

    @ApiOperation(value="工单信息-修改工序参数-工序卡1(选配)", notes="工单信息-修改常规参数-修改工序卡1(选配)")
    @RequestMapping(value = "/updateParamStepOne", method = {RequestMethod.POST})
    public Result<?> updateParamStepOne(WorkorderParamStepone paramStepone){
        return templateService.updateParamStepOne(paramStepone);
    }

    @ApiOperation(value="工单信息-修改工序参数-工序卡2", notes="工单信息-修改常规参数-修改工序卡2")
    @RequestMapping(value = "/updateParamStepTwo", method = {RequestMethod.POST})
    public Result<?> updateParamStepTwo(WorkorderParamSteptwo paramSteptwo){
        return templateService.updateParamStepTwo(paramSteptwo);
    }

    @ApiOperation(value="工单信息-修改工序参数-工序卡3", notes="工单信息-修改常规参数-修改工序卡3")
    @RequestMapping(value = "/updateParamStepThree", method = {RequestMethod.POST})
    public Result<?> updateParamStepThree(WorkorderParamStepthree paramStepthree){
        return templateService.updateParamStepThree(paramStepthree);
    }

    @ApiOperation(value="工单信息-修改工序参数-工序卡4(总成)", notes="工单信息-修改常规参数-修改工序卡4(总成)")
    @RequestMapping(value = "/updateParamStepFour", method = {RequestMethod.POST})
    public Result<?> updateParamStepFour(WorkorderParamStepfour paramStepfour){
        return templateService.updateParamStepFour(paramStepfour);
    }

}
