package com.shkj.wms.controller.base;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.shkj.common.annotation.RepeatSubmit;
import com.shkj.common.core.controller.BaseController;
import com.shkj.common.core.domain.Result;
import com.shkj.common.core.page.TableDataInfo;
import com.shkj.common.enums.IsDelEnum;
import com.shkj.common.utils.SecurityUtils;
import com.shkj.wms.bo.*;
import com.shkj.wms.config.ValidList;
import com.shkj.wms.domain.BaseDerive;
import com.shkj.wms.domain.BaseGoodsData;
import com.shkj.wms.domain.BaseLogicArea;
import com.shkj.wms.service.IBaseDeriveService;
import com.shkj.wms.vo.BaseContainerVo;
import com.shkj.wms.vo.BaseDeriveVo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 派生Controller
 *
 * @author voidlove
 * @menu 容器资料管理
 * @date 2022-05-05
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/wms/derive")
public class BaseDeriveController extends BaseController {

    private final IBaseDeriveService iBaseDeriveService;

    /**
     * 查询派生表
     * @param bo
     * @return
     */
    @GetMapping("/queryBaseDeriveList")
    public TableDataInfo<BaseDerive> queryBaseDeriveList(BaseDerive bo) {
        startPage();
        return getDataTable(iBaseDeriveService.selectBaseDeriveList(bo));
    }

    /**
     * 派生列表
     *
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo<BaseDerive> list() {
        startPage();
        List<BaseDerive> list =iBaseDeriveService.list(new LambdaQueryWrapper<BaseDerive>()
                .eq(BaseDerive::getBranchId, SecurityUtils.getCurrentBranchId())
                .orderByDesc((BaseDerive::getCreateTime)));
        return getDataTable(list);
    }


    /**
     * 新增派生
     */
    @PostMapping("/save")
    @RepeatSubmit
    public Result<Boolean> saveBaseDerive(@Valid @RequestBody BaseDeriveAddBo bo){
        return Result.ok().data(iBaseDeriveService.insertBaseDerive(bo));
    }

    /**
     * 修改派生信息
     */
    @PostMapping("/update")
    @RepeatSubmit
    public Result<Boolean> updateBaseDerive(@Valid @RequestBody BaseDeriveEditBo bo){
        return Result.ok().data(iBaseDeriveService.updateBaseDerive(bo));
    }

    /**
     * 删除派生信息
     */
    @PostMapping("/del")
    @RepeatSubmit
    public Result<Boolean> deleteBaseDeriveById(@Valid @RequestParam Long id){
        return Result.ok().data(iBaseDeriveService.deleteBaseDeriveById(id));
    }

    /**
     * 获取派生
     */
    @GetMapping("/getDeriveInfo")
    @RepeatSubmit
    public Result<String> getDeriveInfo(BaseDeriveQueryBo bo){
        return Result.ok().data(iBaseDeriveService.getDeriveInfo(bo));
    }

    /**
     * 获取颜色
     */
    @GetMapping("/getColorInfo")
    @RepeatSubmit
    public Result<String> getColorInfo( BaseDeriveQueryBo bo ){
        return Result.ok().data(iBaseDeriveService.getColorInfo(bo));
    }

    /**
     * 获取车型代码
     */
    @GetMapping("/getVehicheCodeInfo")
    @RepeatSubmit
    public Result<String> getVehicheCodeInfo(BaseDeriveQueryBo bo ){
        return Result.ok().data(iBaseDeriveService.getVehicheCodeInfo(bo));
    }

    /**
     * 获取车型
     */
    @GetMapping("/getVehicheModelInfo")
    @RepeatSubmit
    public Result<String> getVehicheModelInfo(){
        return Result.ok().data(iBaseDeriveService.getVehicheModelInfo());
    }


    /**
     * 紧急出库，根据派生获取物料信息
     */

    @GetMapping("/getGoodsInfoByDerive")
    @RepeatSubmit
    public Result<List<BaseGoodsData>> getGoodsInfoByDerive(BaseDeriveQueryBo bo){
        return Result.ok().data(iBaseDeriveService.getGoodsInfoByDerive(bo));
    }
}
