package com.shkj.wms.controller.business;


import com.shkj.common.core.controller.BaseController;
import com.shkj.common.core.domain.Result;
import com.shkj.wms.bo.SysStockDetailQueryBo;
import com.shkj.wms.domain.BaseGoodsData;
import com.shkj.wms.service.IBaseLocationService;
import com.shkj.wms.service.ISysStockDetailService;
import com.shkj.wms.vo.SysStockDetailVo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.math.BigDecimal;
import java.util.List;

/**
 * 库存明细Controller
 *
 * @menu 库存明细管理
 * @author zyc
 * @date 2023-05-13
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/wms/Detail")
public class SysStockDetailController extends BaseController {
    private final ISysStockDetailService iSysStockDetailService;

    @Autowired
    private IBaseLocationService iBaseLocationService;



    /**
     * 库存明细查询
     * @param bo
     * @return
     */
    @PostMapping("/StockInquiry")
    public Result<SysStockDetailVo> StockInquiry(@RequestBody SysStockDetailQueryBo bo){
        List<SysStockDetailVo> sysStockDetailVoList=iSysStockDetailService.StockInquiry(bo);
        return Result.ok().data(sysStockDetailVoList);
    }

    /**
     * 信息修改
     * @param veicheModel
     * @param color
     * @param location
     * @param isPunching
     * @param locationCode
     * @param id
     * @return
     */

    @PostMapping("/updateStock")
    public Result<Boolean> updateStock(@RequestParam(value = "veicheModel") String veicheModel, @RequestParam(value = "color") String color,
                                       @RequestParam(value = "location") String location, @RequestParam(value = "isPunching") String isPunching,
                                       @RequestParam(value = "locationCode") String locationCode,@RequestParam(value = "isSplit") String isSplit, @RequestParam(value = "id") String id) {
        BaseGoodsData baseGoodsData = new BaseGoodsData();
        baseGoodsData.setVehicheModel(veicheModel);
        baseGoodsData.setColor(color);
        baseGoodsData.setLocation(location);
        baseGoodsData.setIsPunching(isPunching);
        baseGoodsData.setIsSplit(isSplit);
        baseGoodsData.setLocationCode(locationCode);

        return  iSysStockDetailService.updateStock(baseGoodsData,id);
    }

    /**
     * 货位调整
     * @param oldLocation
     * @param newLoaction
     * @param id
     * @return
     */
    @PostMapping("/removeLocation")
    public Result<Boolean> removeLocation(@RequestParam(value = "oldeLocation") String oldLocation,
                                          @RequestParam(value = "newLocation") String newLoaction,@RequestParam(value = "id") String id){
        SysStockDetailQueryBo stockDetailQueryBo =new SysStockDetailQueryBo();
        stockDetailQueryBo.setLocationId(Long.valueOf(newLoaction));
        stockDetailQueryBo.setQty(new BigDecimal("0"));
        List<SysStockDetailVo> stockDetailVoList = iSysStockDetailService.queryList(stockDetailQueryBo);
        if (stockDetailVoList.size()<0){
            return Result.err().msg("当前库位已存在物料,请选择其他库位!");
        }
        return iSysStockDetailService.removeLocation(oldLocation,newLoaction,id,null);
    }
}
