package com.zy.common.utils;
|
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.core.common.Cools;
|
import com.core.common.SpringUtils;
|
import com.zy.system.entity.User;
|
import com.zy.system.service.UserService;
|
import org.springframework.stereotype.Component;
|
|
/**
|
* @author pang.jiabao
|
* @description 根据角色区分不同库显示不同库存
|
* @createDate 2024/11/3 14:11
|
*/
|
@Component
|
public class RoleUtils {
|
/**
|
* 以角色继承角色显示出指定库信息按堆垛机限制
|
*/
|
public static <T> String outRole(Long userId) {
|
// super账号
|
if (userId == 9527) {
|
return "all";
|
}
|
|
UserService userService = SpringUtils.getBean(UserService.class);
|
User user = userService.selectById(userId);
|
String roleName = user.getRoleName();
|
|
// 管理员角色
|
if (Cools.isEmpty(roleName)) {
|
|
} else if (roleName.equals("管理员")) {
|
return "all";
|
}
|
|
// 其他角色看继承角色
|
String roleLeaderCode = user.getRoleLeaderCode();
|
if (Cools.isEmpty(roleLeaderCode)) {
|
|
} else if (roleLeaderCode.equals("stacker_hangar")) { // 堆垛机库
|
return "stacker_hangar";
|
} else if (roleLeaderCode.equals("four_directional_library")) { // 四向库
|
return "four_directional_library";
|
} else if (roleLeaderCode.equals("ctu_library")) { // ctu库
|
return "ctu_library";
|
|
}
|
return "all";
|
|
}
|
|
|
/**
|
* 以角色继承角色显示出指定库信息按堆垛机限制
|
*/
|
public static <T> void addRoleWrapperByCrn(Long userId, EntityWrapper<T> wrapper) {
|
// super账号
|
if (userId == 9527) {
|
return;
|
}
|
|
UserService userService = SpringUtils.getBean(UserService.class);
|
User user = userService.selectById(userId);
|
String roleName = user.getRoleName();
|
|
// 管理员角色
|
if (Cools.isEmpty(roleName)) {
|
wrapper.eq("1", 0);
|
} else if (roleName.equals("管理员")) {
|
return;
|
}
|
|
// 其他角色看继承角色
|
String roleLeaderCode = user.getRoleLeaderCode();
|
if (Cools.isEmpty(roleLeaderCode)) {
|
wrapper.eq("1", 0);
|
} else if (roleLeaderCode.equals("stacker_hangar")) { // 堆垛机库
|
wrapper.le("crn_no", 4); // 限制1~4号堆垛机
|
} else if (roleLeaderCode.equals("four_directional_library")) { // 四向库
|
wrapper.eq("crn_no", 7); // 限制7号堆垛机
|
} else if (roleLeaderCode.equals("ctu_library")) { // ctu库
|
wrapper.in("crn_no", 8, 9); //限制8,9号堆垛机
|
}
|
|
}
|
|
/**
|
* 以角色继承角色显示出指定库信息按库位限制
|
*/
|
public static <T> void addRoleWrapperByLocNo(Long userId, EntityWrapper<T> wrapper) {
|
// super账号
|
if (userId == 9527) {
|
return;
|
}
|
|
UserService userService = SpringUtils.getBean(UserService.class);
|
User user = userService.selectById(userId);
|
String roleName = user.getRoleName();
|
|
// 管理员角色
|
if (Cools.isEmpty(roleName)) {
|
wrapper.eq("1", 0);
|
return;
|
} else if (roleName.equals("管理员")) {
|
return;
|
}
|
|
// 其他角色看继承角色
|
String roleLeaderCode = user.getRoleLeaderCode();
|
if (Cools.isEmpty(roleLeaderCode)) {
|
wrapper.eq("1", 0);
|
} else if (roleLeaderCode.equals("stacker_hangar")) { // 堆垛机库
|
wrapper.addFilter("LEFT(loc_no,2)<=16"); // 限制1~16排
|
} else if (roleLeaderCode.equals("four_directional_library")) { // 四向库
|
wrapper.addFilter("LEFT(loc_no,2)>=17 and LEFT(loc_no,2)<=37"); // 限制17~37排
|
} else if (roleLeaderCode.equals("ctu_library")) { // ctu库
|
wrapper.addFilter("LEFT(loc_no,2)>=38"); //限制38~53排
|
}
|
}
|
|
|
/**
|
* 以角色继承角色显示出指定库信息按托盘码限制
|
*/
|
public static <T> void addRoleWrapperByBarcode(Long userId, EntityWrapper<T> wrapper) {
|
// super账号
|
if (userId == 9527) {
|
return;
|
}
|
|
UserService userService = SpringUtils.getBean(UserService.class);
|
User user = userService.selectById(userId);
|
String roleName = user.getRoleName();
|
|
// 管理员角色
|
if (Cools.isEmpty(roleName)) {
|
wrapper.eq("1", 0);
|
return;
|
} else if (roleName.equals("管理员")) {
|
return;
|
}
|
|
// 其他角色看继承角色
|
String roleLeaderCode = user.getRoleLeaderCode();
|
if (Cools.isEmpty(roleLeaderCode)) {
|
wrapper.eq("1", 0);
|
} else if (roleLeaderCode.equals("stacker_hangar")) { // 堆垛机库
|
// TODO 堆垛机开头未确认
|
// wrapper.addFilter("LEFT(zpallet,3) =''"); // 限制
|
} else if (roleLeaderCode.equals("four_directional_library")) { // 四向库
|
wrapper.addFilter("LEFT(zpallet,3) ='SXK'"); // 限制SXK
|
} else if (roleLeaderCode.equals("ctu_library")) { // ctu库
|
wrapper.addFilter("LEFT(zpallet,3) ='CTU'"); //限制CTU
|
}
|
}
|
|
}
|