package com.shkj.wms.controller.temp;

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.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));
    }

}
