WareHouseController.java 3.4 KB
package com.huaheng.system.controller;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.huaheng.common.core.web.controller.BaseController;
import com.huaheng.common.core.web.domain.AjaxResult;
import com.huaheng.common.core.web.page.PageDomain;
import com.huaheng.common.core.web.page.TableDataInfo;
import com.huaheng.common.core.web.page.TableSupport;
import com.huaheng.system.api.domain.Warehouse;
import com.huaheng.system.service.ISysUserService;
import com.huaheng.system.service.WarehouseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

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

@Controller
@RequestMapping("/warehouse")
@Api(value = "仓库", tags = "仓库")
public class WareHouseController extends BaseController {

    @Resource
    private WarehouseService warehouseService;
    @Resource
    private ISysUserService userService;

    /**
     * 查询仓库列表
     */
    @GetMapping("/list")
    @ResponseBody
    @ApiOperation(value = "查询仓库", notes = "查询仓库")
    public TableDataInfo list(Warehouse warehouse,
                              String createdBegin,
                              String createdEnd) {
        LambdaQueryWrapper<Warehouse> lambdaQueryWrapper = Wrappers.lambdaQuery();
        PageDomain pageDomain = TableSupport.buildPageRequest();
        Integer pageNum = pageDomain.getPageNum();
        Integer pageSize = pageDomain.getPageSize();
        lambdaQueryWrapper.gt(StrUtil.isNotEmpty(createdBegin), Warehouse::getCreated, createdBegin)
                .lt(StrUtil.isNotEmpty(createdEnd), Warehouse::getCreated, createdEnd)
                .eq(StrUtil.isNotEmpty(warehouse.getCode()), Warehouse::getCode, warehouse.getCode())
                .like(StrUtil.isNotEmpty(warehouse.getName()), Warehouse::getName, warehouse.getName())
                .eq(Warehouse::getDeleted, false)
                .orderByDesc(Warehouse::getCreated);
        /**
         * 使用分页查询
         */
        if (ObjectUtil.isNotNull(pageNum) && ObjectUtil.isNotNull(pageSize)) {
            Page<Warehouse> page = new Page<>(pageNum, pageSize);
            IPage<Warehouse> iPage = warehouseService.page(page, lambdaQueryWrapper);
            return getMpDataTable(iPage.getRecords(), iPage.getTotal());
        } else {
            List<Warehouse> list = warehouseService.list(lambdaQueryWrapper);
            return getDataTable(list);
        }
    }

    /**
     * 通过用户名获取可以登陆的仓库列表
     */
    @GetMapping("/getWarehouseByUserCode")
    @ResponseBody
    @ApiOperation(value = "通过用户名获取可以用的仓库列表 ", notes = "通过用户名获取可以用的仓库列表")
    public AjaxResult getWarehouseByUserCode(String username) {
        if (StrUtil.isNotEmpty(username)) {
            List<Map<String, Object>> list = userService.getWarehouseByUserCode(username);
            return AjaxResult.success(list);
        } else {
            return AjaxResult.error("用户名不能为空");
        }
    }
}