自动化立体仓库 - WMS系统
#1
lsh
2024-05-31 37f97c17a695aacd4f658eb86483558ba62374cd
src/main/java/com/zy/common/web/BaseController.java
@@ -1,6 +1,5 @@
package com.zy.common.web;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.annotations.TableField;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
@@ -8,9 +7,13 @@
import com.core.common.Cools;
import com.core.controller.AbstractBaseController;
import com.core.exception.CoolException;
import com.zy.asrs.entity.Node;
import com.zy.asrs.entity.Tag;
import com.zy.asrs.service.NodeService;
import com.zy.asrs.service.TagService;
import com.zy.system.entity.User;
import com.zy.system.entity.UserLogin;
import com.zy.system.service.UserLoginService;
import com.zy.system.service.UserService;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.beans.factory.annotation.Autowired;
@@ -33,8 +36,16 @@
    private UserService userService;
    @Autowired
    private TagService tagService;
    @Autowired
    private NodeService nodeService;
    @Autowired
    private UserLoginService userLoginService;
    protected Long getUserId(){
        if(Cools.isEmpty(request.getAttribute("userId"))){
            return 000L;
        }
        return Long.parseLong(String.valueOf(request.getAttribute("userId")));
    }
@@ -58,6 +69,14 @@
    protected Tag getOriginTag(){
        return tagService.getTop();
    }
    protected Node getOriginNode(){
        Node node = nodeService.getTop();
        if (node == null) {
            throw new CoolException("库区数据错误");
        }
        return node;
    }
    /**
@@ -158,4 +177,32 @@
            }
        }
    }
    protected <T> void hostEq(EntityWrapper<T> wrapper){
        Long hostId = getHostId();
        if (hostId != null) {
            wrapper.eq("host_id", hostId);
        }
    }
    protected Long getHostId(){
        if (getUserId() == 9527) {
            return null;
        }
        User user = getUser();
        if (user.getRoleId() == 1) {
            String hostId = String.valueOf(request.getAttribute("hostId"));
            if (Cools.isEmpty(hostId)) {
                UserLogin userLogin = userLoginService.selectOne(new EntityWrapper<UserLogin>().eq("user_id", user.getId()));
                if (userLogin != null) {
                    //return userLogin.getHostId();
                    return 1L;
                }
            }
            return Long.parseLong(hostId);
        } else {
            return user.getHostId();
        }
    }
}