package com.gree.mall.miniapp.controller.material.parts;

import com.gree.mall.miniapp.bean.material.parts.PartsWorkerStockBean;
import com.gree.mall.miniapp.bean.material.parts.WorkerStockCensusBean;
import com.gree.mall.miniapp.exception.RemoteServiceException;
import com.gree.mall.miniapp.helper.ResponseHelper;
import com.gree.mall.miniapp.logic.material.parts.WorkerPartsStockLogic;
import com.gree.mall.miniapp.plus.entity.AdminWebsit;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

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

@Slf4j
@RestController()
@Api(value = "配件库存查询", tags ={"配件库存查询"} )
@RequestMapping(value = "/app/parts/stock", produces = "application/json; charset=utf-8")
public class WorkerPartsStockController {

    @Resource
    WorkerPartsStockLogic workerPartsStockLogic;
    
    @ApiOperation(value = "查询师傅库存网点")
    @PostMapping("/exist/websit/list")
    public ResponseHelper<List<AdminWebsit>> existWebsitList (
            @ApiParam(value = "师傅身份证",required = true) @RequestParam String identity
    ) throws RemoteServiceException {
        return ResponseHelper.success(workerPartsStockLogic.existWebsitList(identity));
    }

    @ApiOperation(value = "查询师傅库存物料分组")
    @PostMapping("/exist/websit/group/list")
    public ResponseHelper<List<String>> existWebsitGroupList (
            @ApiParam(value = "师傅身份证",required = true) @RequestParam String identity,
            @ApiParam(value = "网点编号",required = true) @RequestParam String websitId,
            @ApiParam(value = "配件网点编号",required = true) @RequestParam String partsWebsitId,
            @ApiParam(value = "配件属性 NEW=新件 OLD=旧件 WAY=在途 TEMPNEW=临占新件 TEMPOLD=临占旧件",required = true) @RequestParam String partsAttr
    ) throws RemoteServiceException {
        return ResponseHelper.success(workerPartsStockLogic.existWebsitGroupList(identity, websitId, partsWebsitId, partsAttr));
    }
   
    @ApiOperation(value = "查询师傅库存")
    @PostMapping("/exist/worker/stock/list")
    public ResponseHelper<List<PartsWorkerStockBean>> existWorkerStockList (
            @ApiParam(value = "师傅身份证",required = true) @RequestParam String identity,
            @ApiParam(value = "网点编号",required = true) @RequestParam String websitId,
            @ApiParam(value = "配件网点编号",required = true) @RequestParam String partsWebsitId,
            @ApiParam(value = "配件属性 NEW=新件 OLD=旧件 WAY=在途 OLD=旧件 WAY=在途 TEMPNEW=临占新件 TEMPOLD=临占旧件",required = true) @RequestParam String partsAttr,
            @ApiParam(value = "配件编码") @RequestParam(required = false) String partsNumber,
            @ApiParam(value = "配件名称") @RequestParam(required = false) String partsName,
            @ApiParam(value = "物料组id") @RequestParam(required = false) String materialGroupName
    ) throws RemoteServiceException {
        return ResponseHelper.success(workerPartsStockLogic.existWorkerStockList(identity, websitId, partsWebsitId, partsAttr, partsNumber, partsName, materialGroupName));
    }
    
    @ApiOperation(value = "统计查询师傅库存相关")
    @PostMapping("/query/worker-stock")
    public ResponseHelper<WorkerStockCensusBean> queryWorkerStock (
            @ApiParam(value = "师傅身份证",required = true) @RequestParam String identity,
            @ApiParam(value = "网点编码") @RequestParam(required = false) String websitId
    ) throws RemoteServiceException {
        return ResponseHelper.success(workerPartsStockLogic.queryWorkerStock(identity, websitId));
    }
}
