package com.junmp.jyzb.controller;


import cn.hutool.core.util.ObjectUtil;
import com.junmp.jyzb.api.bean.dto.*;
import com.junmp.jyzb.api.bean.query.BussinessInventoryReq;
import com.junmp.jyzb.api.bean.req.DetailInvReq;
import com.junmp.jyzb.api.bean.req.UpdateDetailReq;
import com.junmp.jyzb.api.bean.req.UpdateInventoryReq;
import com.junmp.jyzb.api.bean.req.UploadInventoryReq;
import com.junmp.jyzb.entity.BussinessInventory;
import com.junmp.jyzb.service.BussinessInventoryService;
import com.junmp.v2.common.bean.request.ValidationApi;
import com.junmp.v2.common.bean.response.ApiRes;
import com.junmp.v2.db.api.page.PageResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
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 javax.annotation.Resource;
import java.util.List;

@RestController
@Slf4j
@RequestMapping("/BussinessInventory")
@Api(tags = "[盘点]盘点管理模块")
public class
BussinessInventoryController {
    @Resource
    private BussinessInventoryService BussinessInventoryService;

    //盘库申请

    @PostMapping(path="/AddStocktake",name="盘库申请#logType=30")
    @ApiOperation("盘库申请")
    public ApiRes<String> AddStocktake (@RequestBody @Validated(ValidationApi.add.class) UpdateInventoryReq req){
        //判断是否有工作流id，如果有则将状态进行修改
        if (ObjectUtil.isEmpty(req.getProcessDefinitionId()))
        {
            req.setExamineState("none");
        }
        else
        {
            req.setExamineState("working");
        }
        return ApiRes.success(BussinessInventoryService.AddInvOrder(req));
    }
    @PostMapping(path="/DeleteStocktake",name="删除盘库#logType=30")
    @ApiOperation("删除盘库")
    public ApiRes<String> DeleteStocktake (@RequestBody @Validated(ValidationApi.add.class) UpdateInventoryReq req){
        //判断是否有工作流id，如果有则将状态进行修改
        return ApiRes.success(BussinessInventoryService.DeleteOrder(req));
    }
    //盘库申请

    @PostMapping(path="/Check",name="预览盘点单#enable")
    @ApiOperation("预览盘点单")
    public ApiRes<BussinessInventoryDto> Check (@RequestBody @Validated(ValidationApi.detail.class) BussinessInventoryReq req){
        //判断是否有工作流id，如果有则将状态进行修改

        return ApiRes.success(BussinessInventoryService.Check(req));
    }
    //开始盘点，已废弃
    @PostMapping(path="/Start",name="开始盘点#logType=30")
    @ApiOperation("开始盘点")
    public ApiRes<Boolean> Start (@RequestBody  UploadInventoryReq req){
        //判断是否有工作流id，如果有则将状态进行修改
        return ApiRes.success(BussinessInventoryService.Start(req));
    }
    //查询列表
    @PostMapping(path="/GetPage",name="查询列表#enable")
    @ApiOperation("查询列表")
    public ApiRes<PageResult<BussinessInventory>> GetPage (@RequestBody  BussinessInventoryReq req){
        //判断是否有工作流id，如果有则将状态进行修改
        return ApiRes.success(BussinessInventoryService.GetPage(req));
    }
    //盘库申请
    @PostMapping(path="/GetDetailById",name="查询详情#enable")
    @ApiOperation("查询详情")
    public ApiRes<BussinessInventoryDto> GetDetailById (@RequestBody  BussinessInventoryReq req){
        //判断是否有工作流id，如果有则将状态进行修改
        return ApiRes.success(BussinessInventoryService.GetDetailById(req));
    }
    @PostMapping(path="/GetDetailChild",name="查询盘点子表详情#enable")
    @ApiOperation("查询盘点子表详情")
    public ApiRes<List<BussinessDetailChildDto>> GetDetailChild (@RequestBody DetailInvReq req){
        //判断是否有工作流id，如果有则将状态进行修改
        return ApiRes.success(BussinessInventoryService.GetDetailChild(req));
    }

    //盘库申请
    @PostMapping(path="/UploadStock",name="上传盘点记录#logType=30")
    @ApiOperation("上传盘点记录")
    public ApiRes<Boolean> UploadStock (@RequestBody UploadInventoryReq req){
        //判断是否有工作流id，如果有则将状态进行修改
        return ApiRes.success(BussinessInventoryService.UploadStock(req));
    }
    @PostMapping(path="/UpdateDetail",name="修改盘点单人工明细信息#logType=30")
    @ApiOperation("修改盘点单人工明细信息")
    public ApiRes<Boolean> UpdateDetail (@RequestBody UpdateDetailReq req){
        //判断是否有工作流id，如果有则将状态进行修改
        return ApiRes.success(BussinessInventoryService.UpdateDetail(req));
    }
    //盘库申请
    @PostMapping(path="/UseOrFinished",name="确认结果/结束盘点#logType=30")
    @ApiOperation("确认结果/结束盘点")
    public ApiRes<Boolean> UseOrFinished (@RequestBody UploadInventoryReq req){
        //判断是否有工作流id，如果有则将状态进行修改
//        return ApiRes.success(BussinessInventoryService.UseOrFinished(req));
        return ApiRes.success(BussinessInventoryService.UseOrFinishedRebuild(req));
    }

    @PostMapping(path="/GetInfoByEpcs",name="根据EPC列表换取详细信息#logType=30")
    @ApiOperation("根据EPC列表换取详细信息")
    public ApiRes<ViewCountDto> GetInfoByEpcs (@RequestBody UploadInventoryReq req){
        return ApiRes.success(BussinessInventoryService.GetInfoByEpcs(req));
    }
}
