代码更新

This commit is contained in:
ludj
2022-11-29 19:01:26 +08:00
parent 9e32b998c0
commit 2aa9f8e495
41 changed files with 1054 additions and 1877 deletions

View File

@@ -68,7 +68,8 @@ public class SecurityUtils {
* @return 系统用户Id
*/
public static Long getDeptId() {
return getCurrentUser().getUser().getDept().getId();
// return getCurrentUser().getUser().getDept().getId();
return 1L;
}
/**

View File

@@ -62,14 +62,14 @@ public class GenUtil {
*/
private static List<String> getAdminTemplateNames() {
List<String> templateNames = new ArrayList<>();
// templateNames.add("Entity");
// templateNames.add("Entity");
templateNames.add("Dto");
// templateNames.add("Mapper");
// templateNames.add("Mapper");
templateNames.add("Controller");
//templateNames.add("QueryCriteria");
templateNames.add("Service");
templateNames.add("ServiceImpl");
// templateNames.add("Repository");
// templateNames.add("Repository");
return templateNames;
}
@@ -399,7 +399,10 @@ public class GenUtil {
private static String getFrontFilePath(String templateName, String apiPath, String path, String apiName) {
if ("api".equals(templateName)) {
return apiPath + File.separator + apiName + ".js";
// return apiPath + File.separator + apiName + ".js";
//和vue同文件夹
return path + File.separator + ".js";
}
if ("index".equals(templateName)) {

View File

@@ -40,6 +40,7 @@ import org.nl.modules.security.service.dto.AuthUserDto;
import org.nl.modules.system.service.RoleService;
import org.nl.modules.system.service.UserService;
import org.nl.modules.system.service.dto.UserDto;
import org.nl.modules.wql.core.bean.WQLObject;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
@@ -88,27 +89,33 @@ public class AuthorizationController {
}
// 校验数据库
// 根据用户名查询,在比对密码
UserDto userDto = userService.findByName(authUser.getUsername()); // 拿不到已经抛出异常
if (!userDto.getPassword().equals(SaSecureUtil.md5BySalt(password, "salt"))) { // 这里需要密码加密
JSONObject userInfo = WQLObject.getWQLObject("sys_user").query("username = '" + authUser.getUsername() + "'").uniqueResult(0);
String password1 = userInfo.getString("password");
if (!password1.equals(SaSecureUtil.md5BySalt(password, "salt"))) { // 这里需要密码加密
throw new BadRequestException("账号或密码错误");
}
// 获取权限列表 - 登录查找权限
List<String> permissionList = roleService.getPermissionList(userDto);
List<String> permissionList = roleService.getPermissionList(userInfo);
// 判断是否被锁
if (!userDto.getEnabled()) throw new BadRequestException("账号未激活");
String is_used = userInfo.getString("is_used");
if (!StrUtil.equals(is_used, "1")) throw new BadRequestException("账号未激活");
// 登录输入,登出删除
CurrentUser user = new CurrentUser();
user.setId(userDto.getId());
user.setUsername(userDto.getUsername());
user.setNickName(userDto.getNickName());
user.setUser(userDto);
user.setId(userInfo.getLong("user_id"));
user.setUsername(userInfo.getString("username"));
user.setNickName(userInfo.getString("person_name"));
user.setUser(this.getById(userInfo.getLong("user_id")));
user.setPermissions(permissionList);
// SaLoginModel 配置登录相关参数
StpUtil.login(userDto.getId(), new SaLoginModel()
StpUtil.login(userInfo.getLong("user_id"), new SaLoginModel()
.setDevice("PC") // 此次登录的客户端设备类型, 用于[同端互斥登录]时指定此次登录的设备类型
.setExtra("loginInfo", user) // Token挂载的扩展参数 此方法只有在集成jwt插件时才会生效
);
@@ -116,17 +123,25 @@ public class AuthorizationController {
// 返回 token 与 用户信息
JSONObject jsonObject = new JSONObject();
jsonObject.put("roles", permissionList);
jsonObject.put("user", userDto);
jsonObject.put("user", userInfo);
Map<String, Object> authInfo = new HashMap<String, Object>(2) {{
put("token", "Bearer "+StpUtil.getTokenValue());
put("user", jsonObject);
put("token", "Bearer " + StpUtil.getTokenValue());
put("user", user);
}};
// 保存在线信息
onlineUserService.save(userDto, StpUtil.getTokenValue(), request);
// onlineUserService.save(userDto, StpUtil.getTokenValue(), request);
return ResponseEntity.ok(authInfo);
}
private UserDto getById(Long user_id) {
WQLObject userTab = WQLObject.getWQLObject("sys_user");
JSONObject user = userTab.query("user_id = '" + user_id + "'").uniqueResult(0);
UserDto userDto = user.toJavaObject(UserDto.class);
return userDto;
}
@ApiOperation("获取用户信息")
@GetMapping(value = "/info")
public ResponseEntity<Object> getUserInfo() {
@@ -161,7 +176,7 @@ public class AuthorizationController {
@ApiOperation("退出登录")
@DeleteMapping(value = "/logout")
public ResponseEntity<Object> logout(HttpServletRequest request) {
if (ObjectUtil.isNotEmpty(StpUtil.getTokenValue())){
if (ObjectUtil.isNotEmpty(StpUtil.getTokenValue())) {
onlineUserService.logout(StpUtil.getTokenValue());
}

View File

@@ -1,87 +0,0 @@
package org.nl.modules.security.rest;
import cn.dev33.satoken.annotation.SaIgnore;
import cn.dev33.satoken.secure.SaSecureUtil;
import cn.dev33.satoken.stp.SaLoginModel;
import cn.dev33.satoken.stp.StpUtil;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.modules.common.config.RsaProperties;
import org.nl.modules.common.exception.BadRequestException;
import org.nl.modules.common.utils.RedisUtils;
import org.nl.modules.common.utils.RsaUtils;
import org.nl.modules.common.utils.dto.CurrentUser;
import org.nl.modules.security.service.dto.AuthUserDto;
import org.nl.modules.system.service.RoleService;
import org.nl.modules.system.service.UserService;
import org.nl.modules.system.service.dto.UserDto;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author: lyd
* @description: 手持登录鉴权
* @Date: 2022/10/10
*/
@Slf4j
@RestController
@RequestMapping("/api/pda")
@RequiredArgsConstructor
@Api(tags = "手持:系统授权接口")
public class MobileAuthorizationController {
private final RedisUtils redisUtils;
private final UserService userService;
private final RoleService roleService;
@ApiOperation("登录授权")
@PostMapping(value = "/login")
@SaIgnore
public ResponseEntity<Object> login(@Validated @RequestBody AuthUserDto authUser, HttpServletRequest request) throws Exception {
// 密码解密 - 前端的加密规则: encrypt根据实际更改
String password = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey, authUser.getPassword());
// 校验数据库
// 根据用户名查询,在比对密码
UserDto userDto = userService.findByName(authUser.getUsername()); // 拿不到已经抛出异常
if (!userDto.getPassword().equals(SaSecureUtil.md5BySalt(password, "salt"))) { // 这里需要密码加密
throw new BadRequestException("账号或密码错误");
}
// 获取权限列表 - 登录查找权限
List<String> permissionList = roleService.getPermissionList(userDto);
// 登录输入,登出删除
CurrentUser user = new CurrentUser();
user.setId(userDto.getId());
user.setUsername(userDto.getUsername());
user.setNickName(userDto.getNickName());
user.setUser(userDto);
user.setPermissions(permissionList);
// SaLoginModel 配置登录相关参数
StpUtil.login(userDto.getId(), new SaLoginModel()
.setDevice("PE") // 此次登录的客户端设备类型, 用于[同端互斥登录]时指定此次登录的设备类型
.setExtra("loginInfo", user) // Token挂载的扩展参数 此方法只有在集成jwt插件时才会生效
);
// 返回 token 与 用户信息
JSONObject jsonObject = new JSONObject();
jsonObject.put("user", userDto);
Map<String, Object> authInfo = new HashMap<String, Object>(2) {{
put("token", "Bearer "+StpUtil.getTokenValue());
put("user", jsonObject);
}};
return ResponseEntity.ok(authInfo);
}
}

View File

@@ -51,14 +51,15 @@ public class OnlineUserService {
* @param request /
*/
public void save(UserDto userDto, String token, HttpServletRequest request){
String dept = userDto.getDept().getName();
// String dept = userDto.getDept().getName();
String dept = "";
String ip = StringUtils.getIp(request);
String browser = StringUtils.getBrowser(request);
// String address = StringUtils.getCityInfo(ip);
String address = "局域网";
OnlineUserDto onlineUserDto = null;
try {
onlineUserDto = new OnlineUserDto(userDto.getUsername(), userDto.getNickName(), dept, browser , ip, address, EncryptUtils.desEncrypt(token), new Date());
// onlineUserDto = new OnlineUserDto(userDto.getUsername(), userDto.getNickName(), dept, browser , ip, address, EncryptUtils.desEncrypt(token), new Date());
} catch (Exception e) {
log.error(e.getMessage(),e);
}

View File

@@ -19,17 +19,23 @@ import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.map.MapUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.nl.modules.common.exception.BadRequestException;
import org.nl.modules.common.utils.PageUtil;
import org.nl.modules.common.utils.SecurityUtils;
import org.nl.modules.logging.annotation.Log;
import org.nl.modules.system.domain.Menu;
import org.nl.modules.system.service.MenuService;
import org.nl.modules.system.service.dto.MenuDto;
import org.nl.modules.system.service.dto.MenuQueryCriteria;
import org.nl.modules.system.service.mapstruct.MenuMapper;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
@@ -54,9 +60,9 @@ public class MenuController {
private static final String ENTITY_NAME = "menu";
@GetMapping(value = "/build")
@ApiOperation("获取前端所需菜单")
public ResponseEntity<Object> buildMenus(){
List<MenuDto> menuDtoList = menuService.findByUser(StpUtil.getLoginIdAsLong());
@ApiOperation("根据用户获取菜单")
public ResponseEntity<Object> buildMenus() {
List<MenuDto> menuDtoList = menuService.findByUser(SecurityUtils.getCurrentUserId());
List<MenuDto> menuDtos = menuService.buildTree(menuDtoList);
return new ResponseEntity<>(menuService.buildMenus(menuDtos),HttpStatus.OK);
}
@@ -64,28 +70,46 @@ public class MenuController {
@ApiOperation("返回全部的菜单")
@GetMapping(value = "/lazy")
@SaCheckPermission(value = {"menu:list", "roles:list"}, mode = SaMode.AND)
public ResponseEntity<Object> query(@RequestParam Long pid){
return new ResponseEntity<>(menuService.getMenus(pid),HttpStatus.OK);
public ResponseEntity<Object> query(@RequestParam Long pid) {
return new ResponseEntity<>(menuService.getMenus(pid), HttpStatus.OK);
}
@ApiOperation("菜单子系统级联选择")
@GetMapping(value = "/getSelectList")
@SaCheckPermission(value = {"menu:list", "roles:list"}, mode = SaMode.AND)
public ResponseEntity<Object> getSelectList() {
return new ResponseEntity<>(menuService.getSelectList(), HttpStatus.OK);
}
@ApiOperation("获取菜单列表")
@PostMapping(value = "/getMenusByRole")
@SaCheckPermission(value = {"menu:list", "roles:list"}, mode = SaMode.AND)
public ResponseEntity<Object> getMenusByRole(@RequestBody JSONObject json) {
String role_id = json.getString("role_id");
String system_type = json.getString("system_type");
String category = json.getString("category");
return new ResponseEntity<>(menuService.getMenusByRole(role_id, system_type, category), HttpStatus.OK);
}
@ApiOperation("根据菜单ID返回所有子节点ID包含自身ID")
@GetMapping(value = "/child")
@SaCheckPermission(value = {"menu:list", "roles:list"}, mode = SaMode.AND)
public ResponseEntity<Object> child(@RequestParam Long id){
Set<Menu> menuSet = new HashSet<>();
public ResponseEntity<Object> child(@RequestParam Long id) {
/* Set<Menu> menuSet = new HashSet<>();
List<MenuDto> menuList = menuService.getMenus(id);
menuSet.add(menuService.findOne(id));
menuSet = menuService.getChildMenus(menuMapper.toEntity(menuList), menuSet);
Set<Long> ids = menuSet.stream().map(Menu::getId).collect(Collectors.toSet());
return new ResponseEntity<>(ids,HttpStatus.OK);
Set<Long> ids = menuSet.stream().map(Menu::getId).collect(Collectors.toSet());*/
return new ResponseEntity<>(id, HttpStatus.OK);
}
@GetMapping
@ApiOperation("查询菜单")
@SaCheckPermission("menu:list")
public ResponseEntity<Object> query(MenuQueryCriteria criteria) throws Exception {
List<MenuDto> menuDtoList = menuService.queryAll(criteria, true);
return new ResponseEntity<>(PageUtil.toPage(menuDtoList, menuDtoList.size()),HttpStatus.OK);
public ResponseEntity<Object> query(@RequestParam Map whereJson, Pageable page) throws Exception {
JSONObject param = JSONObject.parseObject(JSON.toJSONString(whereJson));
JSONObject menuDtoList = menuService.queryAll(param, page);
return new ResponseEntity<>(menuDtoList, HttpStatus.OK);
}
@ApiOperation("查询菜单:根据ID获取同级与上级数据")
@@ -93,25 +117,22 @@ public class MenuController {
@SaCheckPermission("menu:list")
public ResponseEntity<Object> getSuperior(@RequestBody List<Long> ids) {
Set<MenuDto> menuDtos = new LinkedHashSet<>();
if(CollectionUtil.isNotEmpty(ids)){
if (CollectionUtil.isNotEmpty(ids)) {
for (Long id : ids) {
MenuDto menuDto = menuService.findById(id);
menuDtos.addAll(menuService.getSuperior(menuDto, new ArrayList<>()));
}
return new ResponseEntity<>(menuService.buildTree(new ArrayList<>(menuDtos)),HttpStatus.OK);
return new ResponseEntity<>(menuService.buildTree(new ArrayList<>(menuDtos)), HttpStatus.OK);
}
return new ResponseEntity<>(menuService.getMenus(null),HttpStatus.OK);
return new ResponseEntity<>(menuService.getMenus(null), HttpStatus.OK);
}
@Log("新增菜单")
@ApiOperation("新增菜单")
@PostMapping
@SaCheckPermission("menu:add")
public ResponseEntity<Object> create(@Validated @RequestBody Menu resources){
if (resources.getId() != null) {
throw new BadRequestException("A new "+ ENTITY_NAME +" cannot already have an ID");
}
menuService.create(resources);
public ResponseEntity<Object> create(@Validated @RequestBody JSONObject form) {
menuService.create(form);
return new ResponseEntity<>(HttpStatus.CREATED);
}
@@ -119,7 +140,7 @@ public class MenuController {
@ApiOperation("修改菜单")
@PutMapping
@SaCheckPermission("menu:edit")
public ResponseEntity<Object> update(@Validated(Menu.Update.class) @RequestBody Menu resources){
public ResponseEntity<Object> update(@Validated(Menu.Update.class) @RequestBody Menu resources) {
menuService.update(resources);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@@ -128,12 +149,12 @@ public class MenuController {
@ApiOperation("删除菜单")
@DeleteMapping
@SaCheckPermission("menu:del")
public ResponseEntity<Object> delete(@RequestBody Set<Long> ids){
public ResponseEntity<Object> delete(@RequestBody Set<Long> ids) {
Set<Menu> menuSet = new HashSet<>();
for (Long id : ids) {
List<MenuDto> menuList = menuService.getMenus(id);
/* List<MenuDto> menuList = menuService.getMenus(id);*/
menuSet.add(menuService.findOne(id));
menuSet = menuService.getChildMenus(menuMapper.toEntity(menuList), menuSet);
/*menuSet = menuService.getChildMenus(menuMapper.toEntity(menuList), menuSet);*/
}
menuService.delete(menuSet);
return new ResponseEntity<>(HttpStatus.OK);

View File

@@ -19,6 +19,8 @@ import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.lang.Dict;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
@@ -39,6 +41,7 @@ import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
@@ -59,7 +62,7 @@ public class RoleController {
@ApiOperation("获取单个role")
@GetMapping(value = "/{id}")
@SaCheckPermission("roles:list")
public ResponseEntity<Object> query(@PathVariable Long id){
public ResponseEntity<Object> query(@PathVariable Long id) {
return new ResponseEntity<>(roleService.findById(id), HttpStatus.OK);
}
@@ -73,33 +76,30 @@ public class RoleController {
@ApiOperation("返回全部的角色")
@GetMapping(value = "/all")
@SaCheckPermission(value = {"roles:list", "user:add", "user:edit"}, mode = SaMode.AND)
public ResponseEntity<Object> query(){
return new ResponseEntity<>(roleService.queryAll(),HttpStatus.OK);
public ResponseEntity<Object> query() {
return new ResponseEntity<>(roleService.queryAll(), HttpStatus.OK);
}
@ApiOperation("查询角色")
@GetMapping
@SaCheckPermission("roles:list")
public ResponseEntity<Object> query(RoleQueryCriteria criteria, Pageable pageable){
return new ResponseEntity<>(roleService.queryAll(criteria,pageable),HttpStatus.OK);
public ResponseEntity<Object> query(@RequestParam Map whereJson, Pageable page) {
JSONObject param = JSONObject.parseObject(JSON.toJSONString(whereJson));
return new ResponseEntity<>(roleService.queryAll(param, page), HttpStatus.OK);
}
@ApiOperation("获取用户级别")
@GetMapping(value = "/level")
public ResponseEntity<Object> getLevel(){
return new ResponseEntity<>(Dict.create().set("level", getLevels(null)),HttpStatus.OK);
public ResponseEntity<Object> getLevel() {
return new ResponseEntity<>(2, HttpStatus.OK);
}
@Log("新增角色")
@ApiOperation("新增角色")
@PostMapping
@SaCheckPermission("roles:add")
public ResponseEntity<Object> create(@Validated @RequestBody Role resources){
if (resources.getId() != null) {
throw new BadRequestException("A new "+ ENTITY_NAME +" cannot already have an ID");
}
getLevels(resources.getLevel());
roleService.create(resources);
public ResponseEntity<Object> create(@Validated @RequestBody JSONObject form) {
roleService.create(form);
return new ResponseEntity<>(HttpStatus.CREATED);
}
@@ -107,7 +107,7 @@ public class RoleController {
@ApiOperation("修改角色")
@PutMapping
@SaCheckPermission("roles:edit")
public ResponseEntity<Object> update(@Validated(Role.Update.class) @RequestBody Role resources){
public ResponseEntity<Object> update(@Validated(Role.Update.class) @RequestBody Role resources) {
getLevels(resources.getLevel());
roleService.update(resources);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
@@ -117,10 +117,10 @@ public class RoleController {
@ApiOperation("修改角色菜单")
@PutMapping(value = "/menu")
@SaCheckPermission("roles:edit")
public ResponseEntity<Object> updateMenu(@RequestBody Role resources){
public ResponseEntity<Object> updateMenu(@RequestBody Role resources) {
RoleDto role = roleService.findById(resources.getId());
getLevels(role.getLevel());
roleService.updateMenu(resources,role);
roleService.updateMenu(resources, role);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@@ -128,7 +128,7 @@ public class RoleController {
@ApiOperation("删除角色")
@DeleteMapping
@SaCheckPermission("roles:del")
public ResponseEntity<Object> delete(@RequestBody Set<Long> ids){
public ResponseEntity<Object> delete(@RequestBody Set<Long> ids) {
for (Long id : ids) {
RoleDto role = roleService.findById(id);
getLevels(role.getLevel());
@@ -141,13 +141,14 @@ public class RoleController {
/**
* 获取用户的角色级别
*
* @return /
*/
private int getLevels(Integer level){
private int getLevels(Integer level) {
List<Integer> levels = roleService.findByUsersId(StpUtil.getLoginIdAsLong()).stream().map(RoleSmallDto::getLevel).collect(Collectors.toList());
int min = Collections.min(levels);
if(level != null){
if(level < min){
if (level != null) {
if (level < min) {
throw new BadRequestException("权限不足,你的角色级别:" + min + ",低于操作的角色级别:" + level);
}
}

View File

@@ -15,9 +15,12 @@
*/
package org.nl.modules.system.service;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.nl.modules.system.domain.Menu;
import org.nl.modules.system.service.dto.MenuDto;
import org.nl.modules.system.service.dto.MenuQueryCriteria;
import org.springframework.data.domain.Pageable;
import java.util.List;
import java.util.Set;
@@ -29,16 +32,35 @@ import java.util.Set;
public interface MenuService {
/**
* 查询全部数据
* @param criteria 条件
* @param isQuery /
* @throws Exception /
* @return /
* 查询参数
*
* @param param
* @return
* @throws Exception
*/
List<MenuDto> queryAll(MenuQueryCriteria criteria, Boolean isQuery) throws Exception;
JSONObject queryAll(JSONObject param, Pageable page) throws Exception;
/**
* 构建菜单子系统与菜单类类别的级联选择下拉框
*
* @return
*/
JSONArray getSelectList();
/**
* 1、根据子系统、菜单类别获取菜单列表,并判断对应的角色ID是否拥有该菜单
*
* @param role_id 角色ID
* @param system_type 子系统
* @param category 菜单类别
* @return
*/
JSONArray getMenusByRole(String role_id, String system_type, String category);
/**
* 根据ID查询
*
* @param id /
* @return /
*/
@@ -46,26 +68,30 @@ public interface MenuService {
/**
* 创建
* @param resources /
*
* @param form /
*/
void create(Menu resources);
void create(JSONObject form);
/**
* 编辑
*
* @param resources /
*/
void update(Menu resources);
/**
* 获取所有子节点包含自身ID
*
* @param menuList /
* @param menuSet /
* @param menuSet /
* @return /
*/
Set<Menu> getChildMenus(List<Menu> menuList, Set<Menu> menuSet);
/**
* 构建菜单树
*
* @param menuDtos 原始数据
* @return /
*/
@@ -73,6 +99,7 @@ public interface MenuService {
/**
* 构建菜单树
*
* @param menuDtos /
* @return /
*/
@@ -80,6 +107,7 @@ public interface MenuService {
/**
* 根据ID查询
*
* @param id /
* @return /
*/
@@ -87,19 +115,22 @@ public interface MenuService {
/**
* 删除
*
* @param menuSet /
*/
void delete(Set<Menu> menuSet);
/**
* 懒加载菜单数据
*
* @param pid /
* @return /
*/
List<MenuDto> getMenus(Long pid);
JSONArray getMenus(Long pid);
/**
* 根据ID获取同级与上级数据
*
* @param menuDto /
* @param objects /
* @return /
@@ -108,6 +139,7 @@ public interface MenuService {
/**
* 根据当前用户获取菜单
*
* @param currentUserId /
* @return /
*/

View File

@@ -15,6 +15,7 @@
*/
package org.nl.modules.system.service;
import com.alibaba.fastjson.JSONObject;
import org.nl.modules.system.domain.Role;
import org.nl.modules.system.service.dto.RoleDto;
import org.nl.modules.system.service.dto.RoleQueryCriteria;
@@ -25,6 +26,7 @@ import org.springframework.data.domain.Pageable;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
@@ -48,9 +50,9 @@ public interface RoleService {
/**
* 创建
* @param resources /
* @param form /
*/
void create(Role resources);
void create(JSONObject form);
/**
* 编辑
@@ -93,11 +95,11 @@ public interface RoleService {
/**
* 待条件分页查询
* @param criteria 条件
* @param pageable 分页参数
* @param whereJson 条件
* @param page 分页参数
* @return /
*/
Object queryAll(RoleQueryCriteria criteria, Pageable pageable);
Map<String,Object> queryAll(Map whereJson, Pageable page);
/**
* 查询全部
@@ -126,7 +128,7 @@ public interface RoleService {
* @param userDto
* @return
*/
List<String> getPermissionList(UserDto userDto);
List<String> getPermissionList(JSONObject userDto);
/**
* 验证是否被用户关联

View File

@@ -53,7 +53,6 @@ public class MenuDto extends BaseDTO implements Serializable {
private Boolean iFrame;
private Boolean isPc;
private Boolean cache;

View File

@@ -38,13 +38,10 @@ public class UserDto extends BaseDTO implements Serializable {
private Set<RoleSmallDto> roles;
private DeptSmallDto dept;
private Long deptId;
private String username;
private String nickName;
private String personName;
private String email;

View File

@@ -61,9 +61,9 @@ public class DataServiceImpl implements DataService {
DataScopeEnum dataScopeEnum = DataScopeEnum.find(role.getDataScope());
switch (Objects.requireNonNull(dataScopeEnum)) {
case THIS_LEVEL:
if (ObjectUtil.isNotEmpty(user.getDept())){
/*if (ObjectUtil.isNotEmpty(user.getDept())){
deptIds.add(user.getDept().getId());
}
}*/
break;
case CUSTOMIZE:
deptIds.addAll(getCustomize(deptIds, role));

View File

@@ -15,14 +15,15 @@
*/
package org.nl.modules.system.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.RequiredArgsConstructor;
import org.nl.modules.common.exception.BadRequestException;
import org.nl.modules.common.exception.EntityExistException;
import org.nl.modules.common.utils.QueryHelp;
import org.nl.modules.common.utils.RedisUtils;
import org.nl.modules.common.utils.ValidationUtil;
import org.nl.modules.common.utils.*;
import org.nl.modules.system.domain.Menu;
import org.nl.modules.system.domain.Role;
import org.nl.modules.system.domain.User;
@@ -36,8 +37,14 @@ import org.nl.modules.system.service.dto.MenuDto;
import org.nl.modules.system.service.dto.MenuQueryCriteria;
import org.nl.modules.system.service.dto.RoleSmallDto;
import org.nl.modules.system.service.mapstruct.MenuMapper;
import org.nl.modules.wql.WQL;
import org.nl.modules.wql.core.bean.ResultBean;
import org.nl.modules.wql.core.bean.WQLObject;
import org.nl.modules.wql.util.WqlUtil;
import org.nl.wms.util.IdUtil;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -61,25 +68,47 @@ public class MenuServiceImpl implements MenuService {
private final RedisUtils redisUtils;
@Override
public List<MenuDto> queryAll(MenuQueryCriteria criteria, Boolean isQuery) throws Exception {
Sort sort = Sort.by(Sort.Direction.ASC, "menuSort");
if (isQuery) {
criteria.setPidIsNull(true);
List<Field> fields = QueryHelp.getAllFields(criteria.getClass(), new ArrayList<>());
for (Field field : fields) {
//设置对象的访问权限保证对private的属性的访问
field.setAccessible(true);
Object val = field.get(criteria);
if ("pidIsNull".equals(field.getName())) {
continue;
}
if (ObjectUtil.isNotNull(val)) {
criteria.setPidIsNull(null);
break;
public JSONObject queryAll(JSONObject param, Pageable page) throws Exception {
ResultBean rb = WQLObject.getWQLObject("sys_menu2").pagequery(WqlUtil.getHttpContext(page), "", "");
return rb.pageResult();
}
@Override
public JSONArray getSelectList() {
JSONArray arr = WQL.getWO("QSYS_MENU01").addParam("flag", "1").process().getResultJSONArray(0);
JSONArray result = new JSONArray();
for (int i = 0; i < arr.size(); i++) {
JSONObject json = arr.getJSONObject(i);
JSONObject item = new JSONObject();
String system_type = json.getString("system_type");
item.put("label", system_type);
item.put("value", system_type);
//构建字级节点
JSONArray children = WQL.getWO("QSYS_MENU01").addParam("flag", "2").addParam("system_type", system_type).process().getResultJSONArray(0);
if (ObjectUtil.isNotEmpty(children)) {
JSONArray childNodes = new JSONArray();
for (int j = 0; j < children.size(); j++) {
JSONObject childJson = children.getJSONObject(j);
JSONObject childItem = new JSONObject();
String category = childJson.getString("category");
childItem.put("label", category);
childItem.put("value", category);
childNodes.add(childItem);
}
item.put("children", childNodes);
}
result.add(item);
}
return menuMapper.toDto(menuRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), sort));
return result;
}
@Override
public JSONArray getMenusByRole(String role_id, String system_type, String category) {
JSONArray arr = WQL.getWO("QSYS_MENU01").addParam("flag", "3").addParam("system_type", system_type).addParam("category", category).process().getResultJSONArray(0);
return arr;
}
@Override
@@ -97,94 +126,73 @@ public class MenuServiceImpl implements MenuService {
* @return /
*/
@Override
@Cacheable(key = "'user:' + #p0")
// @Cacheable(key = "'user:' + #p0")
public List<MenuDto> findByUser(Long currentUserId) {
List<RoleSmallDto> roles = roleService.findByUsersId(currentUserId);
Set<Long> roleIds = roles.stream().map(RoleSmallDto::getId).collect(Collectors.toSet());
LinkedHashSet<Menu> menus = menuRepository.findByRoleIdsAndTypeNot(roleIds, 2);
return menus.stream().map(menuMapper::toDto).collect(Collectors.toList());
JSONArray arr = WQL.getWO("QSYS_MENU01").addParam("flag", "4").addParam("user_id", String.valueOf(currentUserId)).process().getResultJSONArray(0);
List<MenuDto> list = new ArrayList<>();
for (int i = 0; i < arr.size(); i++) {
JSONObject json = arr.getJSONObject(i);
MenuDto dto = new MenuDto();
dto.setId(json.getLong("menu_id"));
dto.setType(json.getInteger("type"));
dto.setPermission(json.getString("permission"));
dto.setTitle(json.getString("title"));
dto.setPath(json.getString("path"));
dto.setComponentName(json.getString("name"));
dto.setComponent(json.getString("component"));
dto.setIcon(json.getString("icon"));
dto.setMenuSort(json.getInteger("menu_sort"));
dto.setSubCount(json.getInteger("sub_count"));
dto.setPid(json.getLong("pid"));
String cache = json.getString("cache");
String iFrame = json.getString("i_frame");
String hidden = json.getString("hidden");
if (StrUtil.equals(cache, "1")) {
dto.setCache(true);
} else {
dto.setCache(false);
}
if (StrUtil.equals(iFrame, "1")) {
dto.setIFrame(true);
} else {
dto.setIFrame(false);
}
if (StrUtil.equals(hidden, "1")) {
dto.setHidden(true);
} else {
dto.setHidden(false);
}
list.add(dto);
}
return list;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void create(Menu resources) {
if (menuRepository.findByTitle(resources.getTitle()) != null) {
throw new EntityExistException(Menu.class, "title", resources.getTitle());
}
if (StrUtil.isNotEmpty(resources.getComponentName())) {
if (menuRepository.findByComponentName(resources.getComponentName()) != null) {
throw new EntityExistException(Menu.class, "componentName", resources.getComponentName());
}
}
if (resources.getPid().equals(0L)) {
resources.setPid(null);
}
if (resources.getIFrame()) {
String http = "http://", https = "https://";
if (!(resources.getPath().toLowerCase().startsWith(http) || resources.getPath().toLowerCase().startsWith(https))) {
throw new BadRequestException("外链必须以http://或者https://开头");
}
}
menuRepository.save(resources);
// 计算子节点数目
resources.setSubCount(0);
// 更新父节点菜单数目
updateSubCnt(resources.getPid());
public void create(JSONObject form) {
WQLObject menuTab = WQLObject.getWQLObject("sys_menu2");
String menu_id = IdUtil.getStringId();
form.put("menu_id", menu_id);
form.put("create_id", SecurityUtils.getCurrentUserId());
form.put("create_name", SecurityUtils.getCurrentNickName());
form.put("create_time", DateUtil.now());
form.put("update_id", SecurityUtils.getCurrentUserId());
form.put("update_name", SecurityUtils.getCurrentNickName());
form.put("update_time", DateUtil.now());
menuTab.insert(form);
//TODO 更新子节点数量
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(Menu resources) {
if (resources.getId().equals(resources.getPid())) {
throw new BadRequestException("上级不能为自己");
}
Menu menu = menuRepository.findById(resources.getId()).orElseGet(Menu::new);
ValidationUtil.isNull(menu.getId(), "Permission", "id", resources.getId());
if (resources.getIFrame()) {
String http = "http://", https = "https://";
if (!(resources.getPath().toLowerCase().startsWith(http) || resources.getPath().toLowerCase().startsWith(https))) {
throw new BadRequestException("外链必须以http://或者https://开头");
}
}
Menu menu1 = menuRepository.findByTitle(resources.getTitle());
if (menu1 != null && !menu1.getId().equals(menu.getId())) {
throw new EntityExistException(Menu.class, "title", resources.getTitle());
}
if (resources.getPid().equals(0L)) {
resources.setPid(null);
}
// 记录的父节点ID
Long oldPid = menu.getPid();
Long newPid = resources.getPid();
if (StrUtil.isNotEmpty(resources.getComponentName())) {
menu1 = menuRepository.findByComponentName(resources.getComponentName());
if (menu1 != null && !menu1.getId().equals(menu.getId())) {
throw new EntityExistException(Menu.class, "componentName", resources.getComponentName());
}
}
menu.setTitle(resources.getTitle());
menu.setComponent(resources.getComponent());
menu.setPath(resources.getPath());
menu.setIcon(resources.getIcon());
menu.setIFrame(resources.getIFrame());
menu.setPid(resources.getPid());
menu.setMenuSort(resources.getMenuSort());
menu.setCache(resources.getCache());
menu.setHidden(resources.getHidden());
menu.setComponentName(resources.getComponentName());
menu.setPermission(resources.getPermission());
menu.setType(resources.getType());
menuRepository.save(menu);
// 计算父级菜单节点数目
updateSubCnt(oldPid);
updateSubCnt(newPid);
// 清理缓存
delCaches(resources.getId());
}
@Override
@@ -212,14 +220,28 @@ public class MenuServiceImpl implements MenuService {
}
@Override
public List<MenuDto> getMenus(Long pid) {
List<Menu> menus;
public JSONArray getMenus(Long pid) {
// 菜单表【sys_menu2】
WQLObject menuTab = WQLObject.getWQLObject("sys_menu2");
JSONArray menus;
if (pid != null && !pid.equals(0L)) {
menus = menuRepository.findByPid(pid);
menus = menuTab.query("pid = '" + pid + "'").getResultJSONArray(0);
} else {
menus = menuRepository.findByPidIsNull();
menus = menuTab.query("(pid =0 or pid is null)").getResultJSONArray(0);
}
return menuMapper.toDto(menus);
//判断是否叶子节点,用于前端构建树
for (int i = 0; i < menus.size(); i++) {
JSONObject json = menus.getJSONObject(i);
Integer sub_count = json.getInteger("sub_count");
if (sub_count <= 0) {
json.put("leaf", true);
json.put("hasChildren", false);
} else {
json.put("leaf", false);
json.put("hasChildren", true);
}
}
return menus;
}
@Override

View File

@@ -16,6 +16,7 @@
package org.nl.modules.system.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.RequiredArgsConstructor;
@@ -34,6 +35,10 @@ import org.nl.modules.system.service.dto.UserDto;
import org.nl.modules.system.service.mapstruct.RoleMapper;
import org.nl.modules.system.service.mapstruct.RoleSmallMapper;
import org.nl.modules.wql.WQL;
import org.nl.modules.wql.core.bean.ResultBean;
import org.nl.modules.wql.core.bean.WQLObject;
import org.nl.modules.wql.util.WqlUtil;
import org.nl.wms.util.IdUtil;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
@@ -75,9 +80,9 @@ public class RoleServiceImpl implements RoleService {
}
@Override
public Object queryAll(RoleQueryCriteria criteria, Pageable pageable) {
Page<Role> page = roleRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root, criteria, criteriaBuilder), pageable);
return PageUtil.toPage(page.map(roleMapper::toDto));
public Map<String, Object> queryAll(Map whereJson, Pageable page) {
ResultBean rb = WQLObject.getWQLObject("sys_role").pagequery(WqlUtil.getHttpContext(page), "", "");
return rb.pageResult();
}
@Override
@@ -91,11 +96,20 @@ public class RoleServiceImpl implements RoleService {
@Override
@Transactional(rollbackFor = Exception.class)
public void create(Role resources) {
if (roleRepository.findByName(resources.getName()) != null) {
throw new EntityExistException(Role.class, "username", resources.getName());
}
roleRepository.save(resources);
public void create(JSONObject form) {
//角色表【sys_role】
WQLObject roleTab = WQLObject.getWQLObject("sys_role");
String role_id = IdUtil.getStringId();
form.put("role_id", role_id);
form.put("create_id", SecurityUtils.getCurrentUserId());
form.put("create_name", SecurityUtils.getCurrentNickName());
form.put("create_time", cn.hutool.core.date.DateUtil.now());
form.put("update_id", SecurityUtils.getCurrentUserId());
form.put("update_name", SecurityUtils.getCurrentNickName());
form.put("update_time", DateUtil.now());
roleTab.insert(form);
}
@Override
@@ -161,16 +175,14 @@ public class RoleServiceImpl implements RoleService {
}
@Override
@Cacheable(key = "'auth:' + #p0.id")
public List<String> getPermissionList(UserDto userDto) {
// @Cacheable(key = "'auth:' + #p0.id")
public List<String> getPermissionList(JSONObject userDto) {
List<String> permission = new LinkedList<>();
// 查看是否为管理员
if (userDto.getIsAdmin()) { // 是管理员
permission.add("admin");
}
HashMap<String, String> map = new HashMap<>();
map.put("flag", "1");
map.put("user_id", userDto.getId().toString());
map.put("user_id",userDto.getString("user_id"));
JSONArray rows = WQL.getWO("SYS_MENU").addParamMap(map).process().getResultJSONArray(0);
for (int i = 0; i < rows.size(); i++) {
JSONObject jsonObject = rows.getJSONObject(i);
@@ -207,6 +219,7 @@ public class RoleServiceImpl implements RoleService {
/**
* 清理缓存
*
* @param id /
*/
public void delCaches(Long id, List<User> users) {

View File

@@ -206,7 +206,6 @@ public class UserServiceImpl implements UserService {
Map<String, Object> map = new LinkedHashMap<>();
map.put("用户名", userDTO.getUsername());
map.put("角色", roles);
map.put("部门", userDTO.getDept().getName());
map.put("邮箱", userDTO.getEmail());
map.put("状态", userDTO.getEnabled() ? "启用" : "禁用");
map.put("手机号码", userDTO.getPhone());

View File

@@ -0,0 +1,109 @@
[交易说明]
交易名: 菜单数据
所属模块:
功能简述:
版权所有:
表引用:
版本经历:
[数据库]
--指定数据库为空采用默认值默认为db.properties中列出的第一个库
[IO定义]
#################################################
## 表字段对应输入参数
#################################################
输入.flag TYPEAS s_string
输入.system_type TYPEAS s_string
输入.category TYPEAS s_string
输入.user_id TYPEAS s_string
[临时表]
--这边列出来的临时表就会在运行期动态创建
[临时变量]
--所有中间过程变量均可在此处定义
[业务过程]
##########################################
# 1、输入输出检查 #
##########################################
##########################################
# 2、主过程前处理 #
##########################################
##########################################
# 3、业务主过程 #
##########################################
IF 输入.flag = "1"
QUERY
SELECT system_type from sys_menu2 GROUP BY system_type
ENDSELECT
ENDQUERY
ENDIF
IF 输入.flag = "2"
QUERY
SELECT category from sys_menu2
WHERE
1=1
OPTION 输入.system_type <> ""
system_type = 输入.system_type
ENDOPTION
GROUP BY category
ENDSELECT
ENDQUERY
ENDIF
IF 输入.flag = "3"
QUERY
SELECT
m.* ,
(CASE WHEN rm.menu_id IS NULL THEN '0' ELSE '1' END ) AS is_checked ,
(CASE WHEN sub_count<=0 THEN true ELSE false END ) AS leaf
FROM
sys_menu2 m
LEFT JOIN sys_roles_menus rm ON m.menu_id = rm.menu_id
where (pid is null or pid=0)
OPTION 输入.system_type <> ""
system_type = 输入.system_type
ENDOPTION
OPTION 输入.category <> ""
category = 输入.category
ENDOPTION
ENDSELECT
ENDQUERY
ENDIF
IF 输入.flag = "4"
QUERY
SELECT
*
FROM
sys_menu
WHERE
type <> '2'
and
menu_id IN (
SELECT
menu_id
FROM
sys_roles_menus
WHERE
role_id IN ( SELECT role_id FROM sys_users_roles where 1=1
OPTION 输入.user_id <> ""
user_id = 输入.user_id
ENDOPTION
))
ENDSELECT
ENDQUERY
ENDIF

View File

@@ -0,0 +1,66 @@
package org.nl.sso.rest;
import org.nl.sso.service.DataPermissionService;
import org.nl.sso.service.dto.DataPermissionDto;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.nl.modules.logging.annotation.Log;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
/**
* @author 数据权限
* @date 数据权限0数据权限数据权限-11-数据权限8
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "数据管理")
@RequestMapping("/api/dataPermission")
@Slf4j
public class DataPermissionController {
private final DataPermissionService dataPermissionService;
@GetMapping
@Log("查询数据权限")
@ApiOperation("查询数据权限")
//@SaCheckPermission("@el.check('dataPermission:list')")
public ResponseEntity<Object> query(@RequestParam Map whereJson, Pageable page) {
return new ResponseEntity<>(dataPermissionService.queryAll(whereJson, page), HttpStatus.OK);
}
@PostMapping
@Log("新增数据权限")
@ApiOperation("新增数据权限")
//@SaCheckPermission("@el.check('dataPermission:add')")
public ResponseEntity<Object> create(@Validated @RequestBody DataPermissionDto dto) {
dataPermissionService.create(dto);
return new ResponseEntity<>(HttpStatus.CREATED);
}
@PutMapping
@Log("修改数据权限")
@ApiOperation("修改数据权限")
//@SaCheckPermission("@el.check('dataPermission:edit')")
public ResponseEntity<Object> update(@Validated @RequestBody DataPermissionDto dto) {
dataPermissionService.update(dto);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@Log("删除数据权限")
@ApiOperation("删除数据权限")
//@SaCheckPermission("@el.check('dataPermission:del')")
@DeleteMapping
public ResponseEntity<Object> delete(@RequestBody Long[] ids) {
dataPermissionService.deleteAll(ids);
return new ResponseEntity<>(HttpStatus.OK);
}
}

View File

@@ -0,0 +1,71 @@
package org.nl.sso.service;
import org.nl.sso.service.dto.DataPermissionDto;
import org.springframework.data.domain.Pageable;
import java.util.Map;
import java.util.List;
/**
* @author 2
* @description 服务接口
* @date 2022-11-28
**/
public interface DataPermissionService {
/**
* 查询数据分页
*
* @param whereJson 条件
* @param page 分页参数
* @return Map<String, Object>
*/
Map<String, Object> queryAll(Map whereJson, Pageable page);
/**
* 查询所有数据不分页
*
* @param whereJson 条件参数
* @return List<DataPermissionDto>
*/
List<DataPermissionDto> queryAll(Map whereJson);
/**
* 根据ID查询
*
* @param permission_id ID
* @return DataPermission
*/
DataPermissionDto findById(Long permission_id);
/**
* 根据编码查询
*
* @param code code
* @return DataPermission
*/
DataPermissionDto findByCode(String code);
/**
* 创建
*
* @param dto /
*/
void create(DataPermissionDto dto);
/**
* 编辑
*
* @param dto /
*/
void update(DataPermissionDto dto);
/**
* 多选删除
*
* @param ids /
*/
void deleteAll(Long[] ids);
}

View File

@@ -0,0 +1,81 @@
package org.nl.sso.service.dto;
import lombok.Data;
import java.math.BigDecimal;
import java.io.Serializable;
/**
* @author 2
* @description /
* @date 2022-11-28
**/
@Data
public class DataPermissionDto implements Serializable {
/**
* permission_id
*/
private Long permission_id;
/**
* 编码
*/
private String code;
/**
* 名称
*/
private String name;
/**
* 排序
*/
private BigDecimal order_sort;
/**
* 备注
*/
private String remark;
/**
* 是否启用
*/
private String is_used;
/**
* 是否删除
*/
private String is_delete;
/**
* 创建人标识
*/
private Long create_id;
/**
* 创建人
*/
private String create_name;
/**
* 创建时间
*/
private String create_time;
/**
* 修改人标识
*/
private Long update_optid;
/**
* 修改人
*/
private String update_optname;
/**
* 修改时间
*/
private String update_time;
}

View File

@@ -0,0 +1,132 @@
package org.nl.sso.service.impl;
import com.alibaba.fastjson.JSON;
import lombok.RequiredArgsConstructor;
import org.nl.modules.common.exception.BadRequestException;
import org.nl.sso.service.DataPermissionService;
import org.nl.sso.service.dto.DataPermissionDto;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.data.domain.Pageable;
import java.util.List;
import java.util.Map;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.nl.modules.common.utils.SecurityUtils;
import org.nl.modules.wql.core.bean.ResultBean;
import org.nl.modules.wql.core.bean.WQLObject;
import org.nl.modules.wql.util.WqlUtil;
import lombok.extern.slf4j.Slf4j;
import cn.hutool.core.util.ObjectUtil;
/**
* @author 2
* @description 服务实现
* @date 2022-11-28
**/
@Service
@RequiredArgsConstructor
@Slf4j
public class DataPermissionServiceImpl implements DataPermissionService {
@Override
public Map<String, Object> queryAll(Map whereJson, Pageable page) {
WQLObject wo = WQLObject.getWQLObject("sys_data_permission");
ResultBean rb = wo.pagequery(WqlUtil.getHttpContext(page), "1=1", "update_time desc");
final JSONObject json = rb.pageResult();
return json;
}
@Override
public List<DataPermissionDto> queryAll(Map whereJson) {
WQLObject wo = WQLObject.getWQLObject("sys_data_permission");
JSONArray arr = wo.query().getResultJSONArray(0);
if (ObjectUtil.isNotEmpty(arr)) return arr.toJavaList(DataPermissionDto.class);
return null;
}
@Override
public DataPermissionDto findById(Long permission_id) {
WQLObject wo = WQLObject.getWQLObject("sys_data_permission");
JSONObject json = wo.query("permission_id = '" + permission_id + "'").uniqueResult(0);
if (ObjectUtil.isNotEmpty(json)) {
return json.toJavaObject(DataPermissionDto.class);
}
return null;
}
@Override
public DataPermissionDto findByCode(String code) {
WQLObject wo = WQLObject.getWQLObject("sys_data_permission");
JSONObject json = wo.query("code ='" + code + "'").uniqueResult(0);
if (ObjectUtil.isNotEmpty(json)) {
return json.toJavaObject(DataPermissionDto.class);
}
return null;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void create(DataPermissionDto dto) {
Long currentUserId = SecurityUtils.getCurrentUserId();
String nickName = SecurityUtils.getCurrentNickName();
String now = DateUtil.now();
dto.setPermission_id(IdUtil.getSnowflake(1, 1).nextId());
dto.setCreate_id(currentUserId);
dto.setCreate_name(nickName);
dto.setUpdate_optid(currentUserId);
dto.setUpdate_optname(nickName);
dto.setUpdate_time(now);
dto.setCreate_time(now);
WQLObject wo = WQLObject.getWQLObject("sys_data_permission");
JSONObject json = JSONObject.parseObject(JSON.toJSONString(dto));
wo.insert(json);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(DataPermissionDto dto) {
DataPermissionDto entity = this.findById(dto.getPermission_id());
if (entity == null) throw new BadRequestException("被删除或无权限,操作失败!");
Long currentUserId = SecurityUtils.getCurrentUserId();
String nickName = SecurityUtils.getCurrentNickName();
String now = DateUtil.now();
dto.setUpdate_time(now);
dto.setUpdate_optid(currentUserId);
dto.setUpdate_optname(nickName);
WQLObject wo = WQLObject.getWQLObject("sys_data_permission");
JSONObject json = JSONObject.parseObject(JSON.toJSONString(dto));
wo.update(json);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteAll(Long[] ids) {
Long currentUserId = SecurityUtils.getCurrentUserId();
String nickName = SecurityUtils.getCurrentNickName();
String now = DateUtil.now();
WQLObject wo = WQLObject.getWQLObject("sys_data_permission");
for (Long permission_id : ids) {
JSONObject param = new JSONObject();
param.put("permission_id", String.valueOf(permission_id));
param.put("is_delete", "1");
param.put("update_optid", currentUserId);
param.put("update_optname", nickName);
param.put("update_time", now);
wo.update(param);
}
}
}

View File

@@ -1,77 +0,0 @@
package org.nl.wms.pdm.rest;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.modules.logging.annotation.Log;
import org.nl.wms.pdm.service.DeviceService;
import org.nl.wms.pdm.service.dto.DeviceDto;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
/**
* @author geng by
* @date 2022-05-25
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "生产设备管理")
@RequestMapping("/api/device")
@Slf4j
public class DeviceController {
private final DeviceService deviceService;
@GetMapping
@Log("查询生产设备")
@ApiOperation("查询生产设备")
//@SaCheckPermission("device:list")
public ResponseEntity<Object> query(@RequestParam Map whereJson, Pageable page){
return new ResponseEntity<>(deviceService.queryAll(whereJson,page),HttpStatus.OK);
}
@PostMapping
@Log("新增生产设备")
@ApiOperation("新增生产设备")
//@SaCheckPermission("device:add")
public ResponseEntity<Object> create(@Validated @RequestBody DeviceDto dto){
deviceService.create(dto);
return new ResponseEntity<>(HttpStatus.CREATED);
}
@PutMapping
@Log("修改生产设备")
@ApiOperation("修改生产设备")
//@SaCheckPermission("device:edit")
public ResponseEntity<Object> update(@Validated @RequestBody DeviceDto dto){
deviceService.update(dto);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@Log("删除生产设备")
@ApiOperation("删除生产设备")
//@SaCheckPermission("device:del")
@DeleteMapping
public ResponseEntity<Object> delete(@RequestBody Long[] ids) {
deviceService.deleteAll(ids);
return new ResponseEntity<>(HttpStatus.OK);
}
@PutMapping("/changeActive")
@Log("修改点位启用状态")
@ApiOperation("修改点位启用状态")
public ResponseEntity<Object> changeActive(@RequestBody JSONObject json) {
deviceService.changeActive(json);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
}

View File

@@ -1,145 +0,0 @@
package org.nl.wms.pdm.rest;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.modules.logging.annotation.Log;
import org.nl.wms.pdm.service.WorkordeService;
import org.nl.wms.pdm.service.dto.WorkorderDto;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
/**
* @author qinx
* @date 2022-05-24
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "工单管理")
@RequestMapping("/api/workorder")
@Slf4j
public class WorkorderController {
private final WorkordeService workordeService;
@GetMapping
@Log("查询工单")
@ApiOperation("查询工单")
//@SaCheckPermission("produceshiftorder:list")
public ResponseEntity<Object> query(@RequestParam Map whereJson, Pageable page){
return new ResponseEntity<>(workordeService.queryAll(whereJson,page),HttpStatus.OK);
}
@PostMapping
@Log("新增工单")
@ApiOperation("新增工单")
//@SaCheckPermission("produceshiftorder:add")
public ResponseEntity<Object> create(@Validated @RequestBody WorkorderDto dto){
workordeService.create(dto);
return new ResponseEntity<>(HttpStatus.CREATED);
}
@PutMapping
@Log("修改工单")
@ApiOperation("修改工单")
//@SaCheckPermission("produceshiftorder:edit")
public ResponseEntity<Object> update(@Validated @RequestBody WorkorderDto dto){
workordeService.update(dto);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@Log("删除工单")
@ApiOperation("删除工单")
//@SaCheckPermission("produceshiftorder:del")
@DeleteMapping
public ResponseEntity<Object> delete(@RequestBody Long[] ids) {
workordeService.deleteAll(ids);
return new ResponseEntity<>(HttpStatus.OK);
}
@PutMapping("/submits")
@Log("工单下发")
@ApiOperation("工单下发")
//@SaCheckPermission("produceshiftorder:edit")
public ResponseEntity<Object> submits(@RequestBody JSONObject param){
workordeService.submits(param);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@PostMapping("/getDevice")
@Log("根据登录用户设备下拉")
@ApiOperation("根据登录用户设备下拉")
//@SaCheckPermission("produceshiftorder:list")
public ResponseEntity<Object> getDevice(@RequestBody JSONObject param){
return new ResponseEntity<>(workordeService.getDevice(param),HttpStatus.OK);
}
@PostMapping("/getTable")
@Log("获取工单生产记录")
@ApiOperation("获取工单生产记录")
//@SaCheckPermission("produceshiftorder:list")
public ResponseEntity<Object> getTable(@RequestBody JSONObject param){
return new ResponseEntity<>(workordeService.getTable(param),HttpStatus.OK);
}
@PostMapping("/openStart")
@Log("看板开工")
@ApiOperation("看板开工")
//@SaCheckPermission("produceshiftorder:list")
public ResponseEntity<Object> openStart(@RequestBody JSONObject param){
workordeService.openStart(param);
return new ResponseEntity<>(HttpStatus.OK);
}
@PostMapping("/saveReport")
@Log("看板报工")
@ApiOperation("看板报工")
//@SaCheckPermission("produceshiftorder:list")
public ResponseEntity<Object> saveReport(@RequestBody JSONObject param){
workordeService.saveReport(param);
return new ResponseEntity<>(HttpStatus.OK);
}
@PostMapping("/finish")
@Log("看板强制完成")
@ApiOperation("看板强制完成")
//@SaCheckPermission("produceshiftorder:list")
public ResponseEntity<Object> finish(@RequestBody JSONObject param){
workordeService.finish(param);
return new ResponseEntity<>(HttpStatus.OK);
}
@PostMapping("/getReportWork")
@Log("获取当前报工记录")
@ApiOperation("获取当前报工记录")
//@SaCheckPermission("produceshiftorder:list")
public ResponseEntity<Object> getReportWork(@RequestBody JSONObject param){
return new ResponseEntity<>(workordeService.getReportWork(param),HttpStatus.OK);
}
@PostMapping("/forceFinish")
@Log("工单强制完成")
@ApiOperation("工单强制完成")
//@SaCheckPermission("produceshiftorder:list")
public ResponseEntity<Object> forceFinish(@RequestBody JSONObject param){
workordeService.forceFinish(param);
return new ResponseEntity<>(HttpStatus.OK);
}
@PostMapping("/getDtl")
@Log("获取当前工单下的工单生产记录")
@ApiOperation("获取当前工单下的工单生产记录")
//@SaCheckPermission("produceshiftorder:list")
public ResponseEntity<Object> getDtl(@RequestBody JSONObject param){
return new ResponseEntity<>(workordeService.getDtl(param),HttpStatus.OK);
}
}

View File

@@ -1,69 +0,0 @@
package org.nl.wms.pdm.service;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.nl.wms.pdm.service.dto.DeviceDto;
import org.springframework.data.domain.Pageable;
import java.util.List;
import java.util.Map;
/**
* @description 服务接口
* @author geng by
* @date 2022-05-25
**/
public interface DeviceService {
/**
* 查询数据分页
* @param whereJson 条件
* @param page 分页参数
* @return Map<String,Object>
*/
Map<String,Object> queryAll(Map whereJson, Pageable page);
/**
* 查询所有数据不分页
* @param whereJson 条件参数
* @return List<DeviceDto>
*/
List<DeviceDto> queryAll(Map whereJson);
/**
* 根据ID查询
* @param device_id ID
* @return Device
*/
DeviceDto findById(Long device_id);
/**
* 根据编码查询
* @param code code
* @return Device
*/
DeviceDto findByCode(String code);
/**
* 创建
* @param dto /
*/
void create(DeviceDto dto);
/**
* 编辑
* @param dto /
*/
void update(DeviceDto dto);
/**
* 多选删除
* @param ids /
*/
void deleteAll(Long[] ids);
void changeActive(JSONObject json);
}

View File

@@ -1,124 +0,0 @@
package org.nl.wms.pdm.service;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.nl.wms.pdm.service.dto.WorkorderDto;
import org.springframework.data.domain.Pageable;
import java.util.List;
import java.util.Map;
/**
* @description 服务接口
* @author qinx
* @date 2022-05-24
**/
public interface WorkordeService {
/**
* 查询数据分页
* @param whereJson 条件
* @param page 分页参数
* @return Map<String,Object>
*/
Map<String,Object> queryAll(Map whereJson, Pageable page);
/**
* 查询所有数据不分页
* @param whereJson 条件参数
* @return List<WorkorderDto>
*/
List<WorkorderDto> queryAll(Map whereJson);
/**
* 根据ID查询
* @param workorder_id ID
* @return Produceshiftorder
*/
WorkorderDto findById(Long workorder_id);
/**
* 根据编码查询
* @param code code
* @return Produceshiftorder
*/
WorkorderDto findByCode(String code);
/**
* 创建
* @param dto /
*/
void create(WorkorderDto dto);
/**
* 编辑
* @param dto /
*/
void update(WorkorderDto dto);
/**
* 多选删除
* @param ids /
*/
void deleteAll(Long[] ids);
/**
* 工单下发
* @param param
*/
void submits(JSONObject param);
/**
* 根据当前登录用户下拉
* @param param
* @return
*/
JSONArray getDevice(JSONObject param);
/**
* 获取工单生产记录
* @param param
* @return
*/
JSONArray getTable(JSONObject param);
/**
* 看板开工
* @param param
*/
void openStart(JSONObject param);
/**
* 看板报工
* @param param
*/
void saveReport(JSONObject param);
/**
* 看板强制完成
* @param param
*/
void finish(JSONObject param);
/**
* 获取当前报工记录
* @param param
* @return
*/
JSONObject getReportWork(JSONObject param);
/**
* 工单强制完成
* @param param
*/
void forceFinish(JSONObject param);
/**
* 获取当前工单下的工单生产记录
* @param param
* @return
*/
JSONArray getDtl(JSONObject param);
}

View File

@@ -1,79 +0,0 @@
package org.nl.wms.pdm.service.dto;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
/**
* @author geng by
* @description /
* @date 2022-05-25
**/
@Data
public class DeviceDto implements Serializable {
/** 设备标识 */
/**
* 防止精度丢失
*/
@JsonSerialize(using = ToStringSerializer.class)
private Long device_id;
/**
* 设备编码
*/
private String device_code;
/**
* 设备名称
*/
private String device_name;
/**
* 设备型号
*/
private String device_model;
/**
* 外部编码
*/
private String extend_code;
/**
* 备注
*/
private String remark;
/**
* 是否启用
*/
private String is_active;
/**
* 创建人
*/
private Long create_id;
/**
* 创建人姓名
*/
private String create_name;
/**
* 创建时间
*/
private String create_time;
/**
* 是否删除
*/
private String is_delete;
/**
* 设备产能
*/
private BigDecimal productivity;
}

View File

@@ -1,93 +0,0 @@
package org.nl.wms.pdm.service.dto;
import lombok.Data;
import java.math.BigDecimal;
import java.io.Serializable;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
/**
* @description /
* @author 1
* @date 2022-10-18
**/
@Data
public class WorkorderDto implements Serializable {
/** 工单标识 */
/** 防止精度丢失 */
@JsonSerialize(using= ToStringSerializer.class)
private Long workorder_id;
/** 生产日期 */
private String produce_date;
/** 计划数量 */
private BigDecimal plan_qty;
/** 实际数量 */
private BigDecimal real_qty;
/** 物料标识 */
private Long material_id;
/** 载具类型 */
private String vehicle_type;
/** 计划生产开始时间 */
private String planproducestart_date;
/** 计划生产结束时间 */
private String planproduceend_date;
/** 实际生产开始时间 */
private String realproducestart_date;
/** 实际生产结束时间 */
private String realproduceend_date;
/** 设备标识 */
private Long device_id;
/** 所属工序 */
private String workorder_procedure;
/** 工单状态 */
private String order_status;
/** 是否搬运 */
private String is_needmove;
/** 回传MES状态 */
private String passback_status;
/** 设备编码 */
private String device_code;
/** 外部标识 */
private String ext_id;
/** 是否删除 */
private String is_delete;
/** 创建人 */
private Long create_id;
/** 创建人 */
private String create_name;
/** 创建时间 */
private String create_time;
/** 修改人 */
private Long update_optid;
/** 修改人 */
private String update_optname;
/** 工单编号 */
private String workorder_code;
/** 修改时间 */
private String update_time;
}

View File

@@ -1,141 +0,0 @@
package org.nl.wms.pdm.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.modules.common.exception.BadRequestException;
import org.nl.modules.common.utils.SecurityUtils;
import org.nl.modules.wql.WQL;
import org.nl.modules.wql.core.bean.WQLObject;
import org.nl.modules.wql.util.WqlUtil;
import org.nl.wms.pdm.service.DeviceService;
import org.nl.wms.pdm.service.dto.DeviceDto;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Map;
/**
* @author geng by
* @description 服务实现
* @date 2022-05-25
**/
@Service
@RequiredArgsConstructor
@Slf4j
public class DeviceServiceImpl implements DeviceService {
@Override
public Map<String, Object> queryAll(Map whereJson, Pageable page) {
String search = MapUtil.getStr(whereJson, "search");
JSONObject map = new JSONObject();
map.put("flag", "1");
if (!StrUtil.isEmpty(search)) {
map.put("search", "%" + search + "%");
}
JSONObject json = WQL.getWO("PDM_BI_DEVICE01").addParamMap(map).pageQuery(WqlUtil.getHttpContext(page), "device.create_time DESC");
return json;
}
@Override
public List<DeviceDto> queryAll(Map whereJson) {
WQLObject wo = WQLObject.getWQLObject("pdm_bi_device");
JSONArray arr = wo.query().getResultJSONArray(0);
if (ObjectUtil.isNotEmpty(arr)) return arr.toJavaList(DeviceDto.class);
return null;
}
@Override
public DeviceDto findById(Long device_id) {
WQLObject wo = WQLObject.getWQLObject("pdm_bi_device");
JSONObject json = wo.query("device_id = '" + device_id + "'").uniqueResult(0);
if (ObjectUtil.isNotEmpty(json)) {
return json.toJavaObject(DeviceDto.class);
}
return null;
}
@Override
public DeviceDto findByCode(String code) {
WQLObject wo = WQLObject.getWQLObject("pdm_bi_device");
JSONObject json = wo.query("device_code ='" + code + "'").uniqueResult(0);
if (ObjectUtil.isNotEmpty(json)) {
return json.toJavaObject(DeviceDto.class);
}
return null;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void create(DeviceDto dto) {
Long currentUserId = SecurityUtils.getCurrentUserId();
String nickName = SecurityUtils.getCurrentNickName();
String now = DateUtil.now();
//编码唯一性校验
String device_code = dto.getDevice_code();
DeviceDto byCode = this.findByCode(device_code);
if (ObjectUtil.isNotEmpty(byCode)) throw new BadRequestException("编码已存在!");
dto.setDevice_id(IdUtil.getSnowflake(1, 1).nextId());
dto.setCreate_id(currentUserId);
dto.setCreate_name(nickName);
dto.setCreate_time(now);
WQLObject wo = WQLObject.getWQLObject("pdm_bi_device");
JSONObject json = JSONObject.parseObject(JSON.toJSONString(dto));
wo.insert(json);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(DeviceDto dto) {
DeviceDto entity = this.findById(dto.getDevice_id());
if (entity == null) throw new BadRequestException("被删除或无权限,操作失败!");
//编码唯一性校验
WQLObject wo = WQLObject.getWQLObject("pdm_bi_device");
String where = "is_delete = '0' and device_code = '" + dto.getDevice_code() + "' and device_id != '" + dto.getDevice_id() + "'";
JSONObject jsonObject = wo.query(where).uniqueResult(0);
if (ObjectUtil.isNotEmpty(jsonObject)) {
throw new BadRequestException("编码已存在!");
}
JSONObject json = JSONObject.parseObject(JSON.toJSONString(dto));
wo.update(json);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteAll(Long[] ids) {
WQLObject wo = WQLObject.getWQLObject("pdm_bi_device");
for (Long device_id : ids) {
wo.delete("device_id = '" + device_id + "'");
}
}
@Override
public void changeActive(JSONObject json) {
String is_used = "1";
if (StrUtil.equals("1", json.getString("is_used"))) {
is_used = "0";
}
json.put("is_used", is_used);
WQLObject.getWQLObject("PDM_BI_Device").update(json);
}
}

View File

@@ -1,442 +0,0 @@
package org.nl.wms.pdm.service.impl;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nl.modules.common.exception.BadRequestException;
import org.nl.modules.common.utils.SecurityUtils;
import org.nl.modules.common.utils.dto.CurrentUser;
import org.nl.modules.system.util.CodeUtil;
import org.nl.modules.wql.WQL;
import org.nl.modules.wql.core.bean.WQLObject;
import org.nl.modules.wql.util.WqlUtil;
import org.nl.wms.basedata.service.ClassstandardService;
import org.nl.wms.ext.acs.service.WmsToAcsService;
import org.nl.wms.pdm.service.WorkordeService;
import org.nl.wms.pdm.service.dto.WorkorderDto;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Map;
/**
* @author qinx
* @description 服务实现
* @date 2022-05-24
**/
@Service
@RequiredArgsConstructor
@Slf4j
public class WorkorderServiceImpl implements WorkordeService {
private final WmsToAcsService wmsToAcsService;
@Override
public Map<String, Object> queryAll(Map whereJson, Pageable page) {
String produceorder_code = MapUtil.getStr(whereJson, "produceorder_code");
String material = MapUtil.getStr(whereJson, "material");
String begin_time = MapUtil.getStr(whereJson, "begin_time");
String end_time = MapUtil.getStr(whereJson, "end_time");
String order_type_scode = MapUtil.getStr(whereJson, "order_type_scode");
String order_status = MapUtil.getStr(whereJson, "order_status");
String shift_type_scode = MapUtil.getStr(whereJson, "shift_type_scode");
JSONObject map = new JSONObject();
map.put("flag", "1");
map.put("order_type_scode", order_type_scode);
//map.put("order_status", order_status);
map.put("shift_type_scode", shift_type_scode);
map.put("begin_time", begin_time);
map.put("end_time", end_time);
if (StrUtil.isNotEmpty(order_status)) {
order_status = order_status.replace("[\"", "").replace("\"]", "").replace("\"", "");
}
map.put("order_status", order_status);
//处理状态为未完成
if (StrUtil.isNotEmpty(order_status) && order_status.contains("-1")) {
map.put("unFinish", "-1");
map.put("order_status", order_status.replace("-1", ""));
}
if (StrUtil.isNotEmpty(produceorder_code)) {
map.put("produceorder_code", "%" + produceorder_code + "%");
}
if (StrUtil.isNotEmpty(material)) {
map.put("material", "%" + material + "%");
}
// 工序名称
map.put("workorder_procedure", whereJson.get("workorder_procedure"));
JSONObject jsonObject = WQL.getWO("MPS_PRODUCEDURE001").addParamMap(map).pageQuery(WqlUtil.getHttpContext(page), "ShiftOrder.update_time desc");
return jsonObject;
}
@Override
public List<WorkorderDto> queryAll(Map whereJson) {
WQLObject wo = WQLObject.getWQLObject("PDM_BD_WorkOrder");
JSONArray arr = wo.query().getResultJSONArray(0);
if (ObjectUtil.isNotEmpty(arr)) return arr.toJavaList(WorkorderDto.class);
return null;
}
@Override
public WorkorderDto findById(Long workorder_id) {
WQLObject wo = WQLObject.getWQLObject("PDM_BD_WorkOrder");
JSONObject json = wo.query("workorder_id = '" + workorder_id + "'").uniqueResult(0);
if (ObjectUtil.isNotEmpty(json)) {
return json.toJavaObject(WorkorderDto.class);
}
return null;
}
@Override
public WorkorderDto findByCode(String code) {
WQLObject wo = WQLObject.getWQLObject("PDM_BD_WorkOrder");
JSONObject json = wo.query("code ='" + code + "'").uniqueResult(0);
if (ObjectUtil.isNotEmpty(json)) {
return json.toJavaObject(WorkorderDto.class);
}
return null;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void create(WorkorderDto dto) {
Long device_id = dto.getDevice_id();
if (ObjectUtil.isNotEmpty(device_id)) {
WQLObject deviceTab = WQLObject.getWQLObject("PDM_BI_Device");
JSONObject object = deviceTab.query("device_id = '" + device_id + "'").uniqueResult(0);
dto.setDevice_code(object.getString("device_code"));
}
Long currentUserId = SecurityUtils.getCurrentUserId();
String nickName = SecurityUtils.getCurrentNickName();
String now = DateUtil.now();
CurrentUser currentUser = SecurityUtils.getCurrentUser();
Long deptId = currentUser.getUser().getDeptId();
String newCode = CodeUtil.getNewCode("PDM_SHIFTORDER");
dto.setWorkorder_id(IdUtil.getSnowflake(1, 1).nextId());
dto.setWorkorder_code(newCode);
dto.setCreate_id(currentUserId);
dto.setCreate_time(now);
dto.setCreate_name(nickName);
dto.setUpdate_optid(currentUserId);
dto.setUpdate_optname(nickName);
dto.setUpdate_time(now);
WQLObject wo = WQLObject.getWQLObject("PDM_BD_WorkOrder");
JSONObject json = JSONObject.parseObject(JSON.toJSONString(dto));
json.put("sysdeptid", deptId);
json.put("syscompanyid", deptId);
wo.insert(json);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(WorkorderDto dto) {
WorkorderDto entity = this.findById(dto.getWorkorder_id());
if (entity == null) throw new BadRequestException("被删除或无权限,操作失败!");
Long currentUserId = SecurityUtils.getCurrentUserId();
String nickName = SecurityUtils.getCurrentNickName();
String now = DateUtil.now();
dto.setUpdate_time(now);
dto.setUpdate_optid(currentUserId);
dto.setUpdate_optname(nickName);
WQLObject wo = WQLObject.getWQLObject("PDM_BD_WorkOrder");
JSONObject json = JSONObject.parseObject(JSON.toJSONString(dto));
wo.update(json);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteAll(Long[] ids) {
Long currentUserId = SecurityUtils.getCurrentUserId();
String nickName = SecurityUtils.getCurrentNickName();
String now = DateUtil.now();
WQLObject wo = WQLObject.getWQLObject("PDM_BD_WorkOrder");
for (Long workorder_id : ids) {
JSONObject param = new JSONObject();
param.put("workorder_id", String.valueOf(workorder_id));
param.put("is_delete", "1");
param.put("update_optid", currentUserId);
param.put("update_optname", nickName);
param.put("update_time", now);
wo.update(param);
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public void submits(JSONObject param) {
Long currentUserId = SecurityUtils.getCurrentUserId();
String nickName = SecurityUtils.getCurrentNickName();
String now = DateUtil.now();
WQLObject wo = WQLObject.getWQLObject("PDM_BD_WorkOrder");
JSONObject json = wo.query("workorder_id = '" + param.getString("workorder_id") + "'").uniqueResult(0);
if (ObjectUtil.isEmpty(json.getString("device_id"))) throw new BadRequestException("请先绑定设备");
JSONArray orderArr = wo.query("device_id = '" + param.getString("device_id") + "' and order_status = '02'").getResultJSONArray(0);
if (ObjectUtil.isNotEmpty(orderArr)) throw new BadRequestException("当前设备正在生产中");
json.put("order_status", "02");
json.put("update_optid", currentUserId);
json.put("update_optname", nickName);
json.put("update_time", now);
wo.update(json);
}
@Override
public JSONArray getDevice(JSONObject param) {
final String workprocedure_id = param.getString("workprocedure_id");
Long currentUserId = SecurityUtils.getCurrentUserId();
JSONObject map = new JSONObject();
map.put("flag", "4");
map.put("jockey_id", currentUserId + "");
map.put("workprocedure_id", workprocedure_id);
final JSONArray resultJSONArray = WQL.getWO("MPS_PRODUCEDURE001").addParamMap(map).process().getResultJSONArray(0);
return resultJSONArray;
}
@Override
public JSONArray getTable(JSONObject param) {
//获取当前登录用户下的所有设备
Long currentUserId = SecurityUtils.getCurrentUserId();
JSONObject map1 = new JSONObject();
map1.put("flag", "2");
map1.put("jockey_id", currentUserId + "");
JSONArray devices = WQL.getWO("MPS_PRODUCEDURE001").addParamMap(map1).process().getResultJSONArray(0);
//根据当前用户下的所有设备查询所属工序
JSONObject map = new JSONObject();
map.put("flag", "3");
StringBuilder sb = new StringBuilder();
if (ObjectUtil.isNotEmpty(devices)) {
sb.append("(");
for (int i = 0; i < devices.size(); i++) {
JSONObject device = devices.getJSONObject(i);
String workprocedure_id = device.getString("workprocedure_id");
if (devices.size() - 1 == i) {
sb.append("'" + workprocedure_id + "')");
}
if (devices.size() - 1 != i) {
sb.append("'" + workprocedure_id + "',");
}
}
map.put("workprocedure_ids", sb.toString());
} else {
map.put("workprocedure_ids", "('-1')");
}
//根据当前用户的设备所属的工序查询属于自己的工单表
JSONArray resultJSONArray = WQL.getWO("MPS_PRODUCEDURE001").addParamMap(map).process().getResultJSONArray(0);
return resultJSONArray;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void openStart(JSONObject param) {
Long currentUserId = SecurityUtils.getCurrentUserId();
String nickName = SecurityUtils.getCurrentNickName();
String now = DateUtil.now();
String device_id = param.getString("device_id");
WQLObject wo_device = WQLObject.getWQLObject("pdm_bi_device");
JSONObject device = wo_device.query("device_id = '" + device_id + "'").uniqueResult(0);
String device_code = device.getString("device_code");
JSONObject row = param.getJSONObject("row");
String workorder_id = row.getString("workorder_id");
String workprocedure_id = row.getString("workprocedure_id");
String produceorder_code = row.getString("produceorder_code");
String material_id = row.getString("material_id");
String material_code = row.getString("material_code");
String material_name = row.getString("material_name");
String material_spec = row.getString("material_spec");
String is_needmove = row.getString("is_needmove");
String plan_qty = row.getString("plan_qty");
String order_status = row.getString("order_status");
//开工时修改生产班次工单表 生产设备、以及工单状态
WQLObject wo = WQLObject.getWQLObject("PDM_BD_WORKORDER");
JSONObject jsonObject1 = wo.query("workorder_id = '" + workorder_id + "'").uniqueResult(0);
JSONObject produceorderMap = new JSONObject();
produceorderMap.put("workorder_id", workorder_id);
produceorderMap.put("device_id", device_id);
produceorderMap.put("order_status", "02");
produceorderMap.put("update_optid", currentUserId);
produceorderMap.put("update_optname", nickName);
produceorderMap.put("update_time", now);
if (order_status.equals("01")){
produceorderMap.put("realproducestart_date", now);
}
wo.update(produceorderMap);
//同时工单记录表中插入一条数据
WQLObject wo_record = WQLObject.getWQLObject("MPS_BD_MacOperateRecord");
JSONObject recordMap = new JSONObject();
recordMap.put("macoperate_id", IdUtil.getSnowflake(1, 1).nextId());
recordMap.put("device_id", device_id);
recordMap.put("workprocedure_id", workprocedure_id);
recordMap.put("workorder_id", workorder_id);
recordMap.put("produceorder_code", produceorder_code);
recordMap.put("init_qty", jsonObject1.getString("real_qty"));
//填写生产记录表中的生产数量时,先判断是否已经生产过了,如果没有生产过,就将工单记录表中的计划数量付给记录表中的生产数量
final JSONArray alreadyPro = wo_record.query("workorder_id = '" + workorder_id + "'").getResultJSONArray(0);
if (ObjectUtil.isEmpty(alreadyPro)) {
recordMap.put("produce_qty", plan_qty);
//同时向acs系统下发工单 问题是现在一个工单分多次执行现在是每开工一次向acs发送一次工单
//acs那边就会新增多个工单
//如果是第一次开工就向acs下发工单
// TODO
JSONArray array = new JSONArray();
JSONObject acsObj = new JSONObject();
acsObj.put("ext_order_id",workorder_id);
acsObj.put("is_needmove",is_needmove);
acsObj.put("order_code",produceorder_code);
acsObj.put("qty",plan_qty);
acsObj.put("material_uuid",material_id);
acsObj.put("material_code",material_code);
acsObj.put("material_name",material_name);
acsObj.put("material_spec",material_spec);
acsObj.put("device_code",device_code);
array.add(acsObj);
wmsToAcsService.order(array);
} else {
Integer sum = 0;
//如果生产过了,就获取记录表中的报工数量,用计划数量减去生产过的报工数量的和,为这次的生产数量
for (int i = 0; i < alreadyPro.size(); i++) {
JSONObject jsonObject = alreadyPro.getJSONObject(i);
String report_qty = jsonObject.getString("report_qty");
sum += Integer.parseInt(report_qty);
}
Integer produce_qty = Integer.parseInt(plan_qty) - sum;
recordMap.put("produce_qty", produce_qty);
//wms向acs发送请求 工单恢复
//如果不是第一次开工就向acs发送恢复工单状态
// TODO
JSONArray array = new JSONArray();
JSONObject map = new JSONObject();
map.put("ext_order_id",workorder_id);
map.put("type","2");
array.add(map);
wmsToAcsService.orderStatusUpdate(array);
}
recordMap.put("operatetime_start", now);
recordMap.put("jockey_id", currentUserId);
wo_record.insert(recordMap);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void saveReport(JSONObject param) {
Long currentUserId = SecurityUtils.getCurrentUserId();
String nickName = SecurityUtils.getCurrentNickName();
String now = DateUtil.now();
final String report_qty = param.getString("report_qty");
final JSONObject row = param.getJSONObject("row");
final String workorder_id = row.getString("workorder_id");
//报工时工单的工单状态为暂停,报工数量为这条工单上次加这次报工数量的和,也就是这条工单每次记录的和
WQLObject wo = WQLObject.getWQLObject("PDM_BD_WORKORDER");
JSONObject jsonObject = wo.query("workorder_id = '" + workorder_id + "'").uniqueResult(0);
JSONObject produceorderMap = new JSONObject();
produceorderMap.put("workorder_id",workorder_id);
if (row.getString("report_qty").equals("0") || StrUtil.isEmpty(row.getString("report_qty"))){
produceorderMap.put("report_qty",report_qty);
}else {
Integer sum = Integer.parseInt(row.getString("report_qty")) + Integer.parseInt(report_qty);
produceorderMap.put("report_qty",sum);
}
produceorderMap.put("order_status", "03");
produceorderMap.put("update_optid", currentUserId);
produceorderMap.put("update_optname", nickName);
produceorderMap.put("update_time", now);
wo.update(produceorderMap);
//同时修改这条工单对应的记录表中最新的一条数据的报工数量
WQLObject wo_record = WQLObject.getWQLObject("MPS_BD_MacOperateRecord");
//获取最新的工单的对应记录信息
JSONObject newRecord = wo_record.query("workorder_id = '"+workorder_id+"' and (operatetime_end is null or operatetime_end = '')").uniqueResult(0);
newRecord.put("report_qty",report_qty);
newRecord.put("finish_qty",jsonObject.getString("real_qty"));
Integer finishproduct_qty = Integer.parseInt(jsonObject.getString("real_qty")) - Integer.parseInt(newRecord.getString("init_qty"));
newRecord.put("finishproduct_qty",finishproduct_qty);
newRecord.put("operatetime_end",now);
wo_record.update(newRecord);
//wms向acs发送请求 工单暂停
// 报工的时候同时向acs发送工单暂停状态
// TODO
JSONArray array = new JSONArray();
JSONObject map = new JSONObject();
map.put("ext_order_id",workorder_id);
map.put("type","1");
array.add(map);
wmsToAcsService.orderStatusUpdate(array);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void finish(JSONObject param) {
Long currentUserId = SecurityUtils.getCurrentUserId();
String nickName = SecurityUtils.getCurrentNickName();
String now = DateUtil.now();
JSONObject row = param.getJSONObject("row");
String workorder_id = row.getString("workorder_id");
WQLObject wo = WQLObject.getWQLObject("PDM_BD_WORKORDER");
JSONObject produceorderMap = new JSONObject();
produceorderMap.put("workorder_id",workorder_id);
produceorderMap.put("order_status","5");
produceorderMap.put("update_optid", currentUserId);
produceorderMap.put("device_id", null);
produceorderMap.put("update_optname", nickName);
produceorderMap.put("update_time", now);
produceorderMap.put("realproduceend_date", now);
wo.update(produceorderMap);
//wms向acs发送请求 工单强制完成
// TODO
JSONArray array = new JSONArray();
JSONObject map = new JSONObject();
map.put("ext_order_id",workorder_id);
map.put("type","3");
array.add(map);
wmsToAcsService.orderStatusUpdate(array);
}
@Override
public JSONObject getReportWork(JSONObject param) {
String workorder_id = param.getString("workorder_id");
WQLObject wo = WQLObject.getWQLObject("PDM_BD_WORKORDER");
JSONObject jsonProduceShiftOrder = wo.query("workorder_id = '" + workorder_id + "'").uniqueResult(0);
WQLObject wo_record = WQLObject.getWQLObject("MPS_BD_MacOperateRecord");
//获取最新的工单的对应记录信息
JSONObject jsonObject = wo_record.query("workorder_id = '"+workorder_id+"' and (operatetime_end is null or operatetime_end = '')").uniqueResult(0);
String finish_qty = jsonProduceShiftOrder.getString("real_qty");
jsonObject.put("finish_qty",finish_qty);
Integer finishproduct_qty = Integer.parseInt(finish_qty) - Integer.parseInt(jsonObject.getString("init_qty"));
jsonObject.put("finishproduct_qty",finishproduct_qty);
return jsonObject;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void forceFinish(JSONObject param) {
this.finish(param);
}
@Override
public JSONArray getDtl(JSONObject param) {
final String workorder_id = param.getString("workorder_id");
JSONObject map = new JSONObject();
map.put("flag","5");
map.put("workorder_id",workorder_id);
JSONArray resultJSONArray = WQL.getWO("MPS_PRODUCEDURE001").addParamMap(map).process().getResultJSONArray(0);
return resultJSONArray;
}
}

View File

@@ -1,174 +0,0 @@
[交易说明]
交易名: 工单分页查询
所属模块:
功能简述:
版权所有:
表引用:
版本经历:
[数据库]
--指定数据库为空采用默认值默认为db.properties中列出的第一个库
[IO定义]
#################################################
## 表字段对应输入参数
#################################################
输入.flag TYPEAS s_string
输入.jockey_id TYPEAS s_string
输入.workorder_id TYPEAS s_string
输入.workprocedure_id TYPEAS s_string
输入.order_status TYPEAS s_string
输入.workorder_procedure TYPEAS s_string
输入.shift_type_scode TYPEAS s_string
输入.begin_time TYPEAS s_string
输入.end_time TYPEAS s_string
输入.produceorder_code TYPEAS s_string
输入.material TYPEAS s_string
输入.product_series TYPEAS f_string
输入.workprocedure_ids TYPEAS f_string
输入.unFinish TYPEAS s_string
[临时表]
--这边列出来的临时表就会在运行期动态创建
[临时变量]
--所有中间过程变量均可在此处定义
[业务过程]
##########################################
# 1、输入输出检查 #
##########################################
##########################################
# 2、主过程前处理 #
##########################################
##########################################
# 3、业务主过程 #
##########################################
IF 输入.flag = "1"
PAGEQUERY
SELECT
ShiftOrder.*,
material.material_code,
material.material_name,
material.material_spec,
material.product_series,
classstandard.class_id,
classstandard.class_name,
device.device_name
FROM
PDM_BD_WORKORDER ShiftOrder
LEFT JOIN md_me_materialbase material ON material.material_id = ShiftOrder.material_id
LEFT JOIN pdm_bi_device device ON ShiftOrder.device_id = device.device_id
LEFT JOIN md_pb_classstandard classstandard ON classstandard.class_id = material.product_series
WHERE
ShiftOrder.is_delete = '0'
OPTION 输入.unFinish <> ""
ShiftOrder.order_status <> '5'
ENDOPTION
OPTION 输入.order_status <> ""
find_in_set( ShiftOrder.order_status, 输入.order_status)
ENDOPTION
OPTION 输入.shift_type_scode <> ""
ShiftOrder.shift_type_scode = 输入.shift_type_scode
ENDOPTION
OPTION 输入.workorder_procedure <> ""
ShiftOrder.workorder_procedure = 输入.workorder_procedure
ENDOPTION
OPTION 输入.begin_time <> ""
ShiftOrder.produce_date >= 输入.begin_time
ENDOPTION
OPTION 输入.end_time <> ""
ShiftOrder.produce_date <= 输入.end_time
ENDOPTION
OPTION 输入.produceorder_code <> ""
ShiftOrder.produceorder_code like 输入.produceorder_code
ENDOPTION
OPTION 输入.material <> ""
(
material.material_code like 输入.material or
material.material_name like 输入.material or
material.material_spec like 输入.material
)
ENDOPTION
ENDSELECT
ENDPAGEQUERY
ENDIF
IF 输入.flag = "2"
QUERY
SELECT
personDevice.*,
device.device_code,
device.device_name,
device.workprocedure_id
FROM
PDM_BI_PersonCorrDevice personDevice
LEFT JOIN PDM_BI_Device device ON personDevice.device_id = device.device_id
WHERE
device.is_delete = '0' and personDevice.jockey_id = 输入.jockey_id
ENDSELECT
ENDQUERY
ENDIF
IF 输入.flag = "3"
QUERY
SELECT
shiftOrder.*,
workprocedure.workprocedure_name,
material.material_code,
material.material_name,
material.material_spec
FROM
PDM_BD_WORKORDER shiftOrder
left join PDM_BI_WorkProcedure workprocedure on workprocedure.workprocedure_id = shiftOrder.workprocedure_id
left join md_me_materialbase material on material.material_id = shiftOrder.material_id
WHERE
shiftOrder.is_delete = '0' and shiftOrder.order_status in ('01', '02', '03')
and shiftOrder.workprocedure_id in 输入.workprocedure_ids
order by
shiftOrder.update_time desc
ENDSELECT
ENDQUERY
ENDIF
IF 输入.flag = "4"
QUERY
SELECT
personDevice.*,
device.device_code,
device.device_name
FROM
PDM_BI_PersonCorrDevice personDevice
LEFT JOIN PDM_BI_Device device ON personDevice.device_id = device.device_id
WHERE
device.is_delete = '0' and personDevice.jockey_id = 输入.jockey_id and device.workprocedure_id = 输入.workprocedure_id
ENDSELECT
ENDQUERY
ENDIF
IF 输入.flag = "5"
QUERY
SELECT
record.*,
device.device_code,
device.device_name,
user.nick_name
FROM
MPS_BD_MacOperateRecord record
LEFT JOIN PDM_BI_Device device ON record.device_id = device.device_id
LEFT JOIN sys_user user ON user.user_id = record.jockey_id
WHERE
record.workorder_id = 输入.workorder_id
order by
record.operatetime_start
ENDSELECT
ENDQUERY
ENDIF

View File

@@ -1,58 +0,0 @@
[交易说明]
交易名: 设备查询
所属模块:
功能简述:
版权所有:
表引用:
版本经历:
[数据库]
--指定数据库为空采用默认值默认为db.properties中列出的第一个库
[IO定义]
#################################################
## 表字段对应输入参数
#################################################
输入.flag TYPEAS s_string
输入.search TYPEAS s_string
[临时表]
--这边列出来的临时表就会在运行期动态创建
[临时变量]
--所有中间过程变量均可在此处定义
[业务过程]
##########################################
# 1、输入输出检查 #
##########################################
##########################################
# 2、主过程前处理 #
##########################################
##########################################
# 3、业务主过程 #
##########################################
IF 输入.flag = "1"
PAGEQUERY
SELECT
device.*
FROM
PDM_BI_Device device
WHERE
device.is_delete = '0'
OPTION 输入.search <> ""
(device.device_code like 输入.search or
device.device_name like 输入.search)
ENDOPTION
ENDSELECT
ENDPAGEQUERY
ENDIF

View File

@@ -57,7 +57,7 @@ public class ${className}Controller {
@ApiOperation("删除${apiAlias}")
//@SaCheckPermission("@el.check('${changeClassName}:del')")
@DeleteMapping
public ResponseEntity<Object> delete(@RequestBody ${pkColumnType}[] ids) {
public ResponseEntity<Object> delete(@RequestBody Long[] ids) {
${changeClassName}Service.deleteAll(ids);
return new ResponseEntity<>(HttpStatus.OK);
}

View File

@@ -113,6 +113,7 @@
</template>
<script>
import crud${className} from '@/views/${changeClassName}'
import CRUD, {crud, form, header, presenter} from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'