package com.shkj.wms.controller.base;

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

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.shkj.common.annotation.Log;
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.BusinessType;
import com.shkj.common.enums.IsDelEnum;
import com.shkj.common.utils.SecurityUtils;
import com.shkj.wms.bo.BaseLogicAreaQueryListBo;
import com.shkj.wms.bo.BaseLogicAreaSaveOrUpdateBo;
import com.shkj.wms.common.SwitchStatusEntity;
import com.shkj.wms.config.ValidList;
import com.shkj.wms.domain.BaseLogicArea;
import com.shkj.wms.service.IBaseLogicAreaService;
import com.shkj.wms.vo.BaseLogicAreaVo;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 逻辑区域Controller
 *
 * @author zjx
 * @date 2023-04-18
 */

@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/wms/logicarea")
public class BaseLogicAreaController extends BaseController
{
    @Autowired
    private IBaseLogicAreaService baseLogicAreaService;


    /**
     * 查询逻辑区域列表
     */
    @GetMapping("/list")
    public TableDataInfo<BaseLogicArea> list() {
        startPage();
        List<BaseLogicArea> list =baseLogicAreaService.list(new LambdaQueryWrapper<BaseLogicArea>()
                .eq(BaseLogicArea::getIsDel, IsDelEnum.NORMAL.getValue())
                .eq(BaseLogicArea::getBranchId, SecurityUtils.getCurrentBranchId())
                .orderByDesc(BaseLogicArea::getCreateTime));
        return getDataTable(list);
    }

    /**
     * 保存或者修改逻辑区域
     */
    @PostMapping("/saveOrUpdateBaseLogicAreas")
    @RepeatSubmit
    public Result<Boolean> saveOrUpdateBaseStorage(@Valid @RequestBody ValidList<BaseLogicAreaSaveOrUpdateBo> list){
        return baseLogicAreaService.saveOrUpdateBaseLogicArea(list);
    }

    /**
     * 查询单个逻辑区域
     */
    @GetMapping("/id")
    @RepeatSubmit
    public Result<BaseLogicAreaVo> queryById(@RequestBody Long id){
        return baseLogicAreaService.queryById(id);
    }

    /**
     * 查询单个逻辑区域
     */
    @PostMapping("/deleteWithValidById")
    @RepeatSubmit
    public Result<Boolean> deleteWithValidById(@RequestParam Long id){
        return baseLogicAreaService.deleteWithValidById(id);
    }

    /**
     * 查看逻辑区域列表
     * @param bo
     * @return
     */
    @GetMapping("/queryBaseLogicAreaList")
    public TableDataInfo<BaseLogicArea> queryBaseLogicalAreaList(BaseLogicAreaQueryListBo bo) {
        bo.setBranchId(SecurityUtils.getCurrentBranchId());
        startPage();
        List<BaseLogicArea> list =baseLogicAreaService.queryBaseLogicAreaList(bo);
        return getDataTable(list);
    }


    /**
     * 切换状态
     */
    @Log(title = "切换状态" , businessType = BusinessType.UPDATE)
    @PostMapping("/switchStatus")
    public Result<Boolean> switchStatus(@Valid @RequestBody SwitchStatusEntity switchStatusEntity) {
        return baseLogicAreaService.switchStatus(switchStatusEntity.getId(), switchStatusEntity.getIsuse());
    }


}
