| | |
| | | package com.zy.asrs.wms.system.controller; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.zy.asrs.framework.common.Cools; |
| | | import com.zy.asrs.framework.common.R; |
| | | import com.zy.asrs.framework.exception.CoolException; |
| | | import com.zy.asrs.wms.common.annotation.CacheData; |
| | | import com.zy.asrs.wms.common.annotation.OperationLog; |
| | | import com.zy.asrs.wms.common.domain.BaseParam; |
| | | import com.zy.asrs.wms.common.domain.KeyValVo; |
| | | import com.zy.asrs.wms.common.domain.PageParam; |
| | | import com.zy.asrs.wms.system.entity.Host; |
| | | import com.zy.asrs.wms.system.entity.Menu; |
| | | import com.zy.asrs.wms.system.entity.RoleMenu; |
| | | import com.zy.asrs.wms.system.service.*; |
| | | import com.zy.asrs.wms.utils.ExcelUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.util.*; |
| | | |
| | | @RestController |
| | | @RequestMapping("/api") |
| | | public class HostController extends BaseController { |
| | | |
| | | @Autowired |
| | | private HostService hostService; |
| | | @Autowired |
| | | private MenuService menuService; |
| | | @Autowired |
| | | private RoleMenuService roleMenuService; |
| | | @Autowired |
| | | private RoleService roleService; |
| | | @Autowired |
| | | private UserService userService; |
| | | |
| | | @PreAuthorize("hasAuthority('system:host:list')") |
| | | @PostMapping("/host/page") |
| | | @CacheData(tableName = {"sys_host"}) |
| | | public R page(@RequestBody Map<String, Object> map) { |
| | | BaseParam baseParam = buildParam(map, BaseParam.class); |
| | | PageParam<Host, BaseParam> pageParam = new PageParam<>(baseParam, Host.class); |
| | | return R.ok().add(hostService.page(pageParam, pageParam.buildWrapper(true))); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('system:host:list')") |
| | | @PostMapping("/host/list") |
| | | @CacheData(tableName = {"sys_host"}) |
| | | public R list(@RequestBody Map<String, Object> map) { |
| | | return R.ok().add(hostService.list()); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('system:host:list')") |
| | | @GetMapping("/host/{id}") |
| | | @CacheData(tableName = {"sys_host"}) |
| | | public R get(@PathVariable("id") Long id) { |
| | | return R.ok().add(hostService.getById(id)); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('system:host:save')") |
| | | @OperationLog("添加机构") |
| | | @PostMapping("/host/save") |
| | | @Transactional |
| | | public R save(@RequestBody Host host) { |
| | | host.setCreateTime(new Date()); |
| | | host.setUpdateTime(new Date()); |
| | | if (!hostService.save(host)) { |
| | | return R.error("添加失败"); |
| | | } |
| | | |
| | | List<Menu> parentMenus = menuService.selectByParentId(0L, 0, 1L); |
| | | for (Menu parentMenu : parentMenus) { |
| | | List<Menu> menuList = menuService.selectByParentId(parentMenu.getId(), 0, parentMenu.getHostId()); |
| | | |
| | | parentMenu.setId(null); |
| | | parentMenu.setHostId(host.getId()); |
| | | boolean save1 = menuService.save(parentMenu); |
| | | if (!save1) { |
| | | throw new CoolException("添加失败"); |
| | | } |
| | | |
| | | for (Menu menu1 : menuList) { |
| | | List<Menu> menuList2 = menuService.selectByParentId(menu1.getId(), 1, menu1.getHostId()); |
| | | |
| | | menu1.setId(null); |
| | | menu1.setHostId(host.getId()); |
| | | menu1.setParentId(parentMenu.getId()); |
| | | boolean save2 = menuService.save(menu1); |
| | | if (!save2) { |
| | | throw new CoolException("添加失败"); |
| | | } |
| | | |
| | | for (Menu menu2 : menuList2) { |
| | | menu2.setId(null); |
| | | menu2.setHostId(host.getId()); |
| | | menu2.setParentId(menu1.getId()); |
| | | boolean save3 = menuService.save(menu2); |
| | | if (!save3) { |
| | | throw new CoolException("添加失败"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | //创建默认权限 |
| | | for (Menu menu1 : menuList) { |
| | | RoleMenu roleMenu = new RoleMenu(); |
| | | roleMenu.setRoleId(1L); |
| | | roleMenu.setMenuId(menu1.getId()); |
| | | boolean save4 = roleMenuService.save(roleMenu); |
| | | if (!save4) { |
| | | throw new CoolException("添加失败"); |
| | | } |
| | | } |
| | | RoleMenu roleMenu = new RoleMenu(); |
| | | roleMenu.setRoleId(1L); |
| | | roleMenu.setMenuId(parentMenu.getId()); |
| | | boolean save5 = roleMenuService.save(roleMenu); |
| | | if (!save5) { |
| | | throw new CoolException("添加失败"); |
| | | } |
| | | |
| | | } |
| | | |
| | | // //创建系统默认菜单 |
| | | // Menu menu = new Menu(); |
| | | // menu.setName("系统管理"); |
| | | // menu.setParentId(0L); |
| | | // menu.setRoute("/system"); |
| | | // menu.setType(0); |
| | | // menu.setIcon("UserOutlined"); |
| | | // menu.setSort(1); |
| | | // menu.setLanguageId("system.system"); |
| | | // menu.setHostId(host.getId()); |
| | | // boolean save = menuService.save(menu); |
| | | // if (!save) { |
| | | // throw new CoolException("添加失败"); |
| | | // } |
| | | // List<Menu> menuList = menuService.selectByPathName("系统管理", 0); |
| | | // for (Menu menu1 : menuList) { |
| | | // menu1.setId(null); |
| | | // menu1.setHostId(host.getId()); |
| | | // menu1.setParentId(menu.getId()); |
| | | // boolean save1 = menuService.save(menu1); |
| | | // if (!save1) { |
| | | // throw new CoolException("添加失败"); |
| | | // } |
| | | // |
| | | // List<Menu> menuList2 = menuService.selectByPathName(menu1.getName(), 1); |
| | | // for (Menu menu2 : menuList2) { |
| | | // menu2.setId(null); |
| | | // menu2.setHostId(host.getId()); |
| | | // menu2.setParentId(menu1.getId()); |
| | | // boolean save2 = menuService.save(menu2); |
| | | // if (!save2) { |
| | | // throw new CoolException("添加失败"); |
| | | // } |
| | | // } |
| | | // } |
| | | // |
| | | // //创建默认权限 |
| | | // for (Menu menu1 : menuList) { |
| | | // RoleMenu roleMenu = new RoleMenu(); |
| | | // roleMenu.setRoleId(1L); |
| | | // roleMenu.setMenuId(menu1.getId()); |
| | | // boolean save1 = roleMenuService.save(roleMenu); |
| | | // if (!save1) { |
| | | // throw new CoolException("添加失败"); |
| | | // } |
| | | // } |
| | | // RoleMenu roleMenu = new RoleMenu(); |
| | | // roleMenu.setRoleId(1L); |
| | | // roleMenu.setMenuId(menu.getId()); |
| | | // boolean save1 = roleMenuService.save(roleMenu); |
| | | // if (!save1) { |
| | | // throw new CoolException("添加失败"); |
| | | // } |
| | | |
| | | return R.ok("添加成功"); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('system:host:update')") |
| | | @OperationLog("修改机构") |
| | | @PostMapping("/host/update") |
| | | public R update(@RequestBody Host host) { |
| | | host.setUpdateTime(new Date()); |
| | | if (!hostService.updateById(host)) { |
| | | return R.error("修改失败"); |
| | | } |
| | | return R.ok("修改成功"); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('system:host:remove')") |
| | | @OperationLog("删除机构") |
| | | @PostMapping("/host/remove/{ids}") |
| | | @Transactional |
| | | public R remove(@PathVariable Long[] ids) { |
| | | List<Host> list = hostService.list(new LambdaQueryWrapper<Host>().in(Host::getId, ids)); |
| | | for (Host host : list) { |
| | | if (host.getId() == 1) { |
| | | throw new CoolException("根节点不可被删除"); |
| | | } |
| | | |
| | | ArrayList<Long> menuIds = new ArrayList<>(); |
| | | for (Menu menu : menuService.selectByHostId(host.getId())) { |
| | | menuIds.add(menu.getId()); |
| | | } |
| | | |
| | | if (!menuIds.isEmpty()) { |
| | | roleMenuService.remove(new LambdaQueryWrapper<RoleMenu>().in(RoleMenu::getMenuId, menuIds)); |
| | | menuService.removeByHostId(host.getId()); |
| | | roleService.removeByHostId(host.getId()); |
| | | userService.removeByHostId(host.getId()); |
| | | } |
| | | } |
| | | |
| | | if (!hostService.removeByIds(Arrays.asList(ids))) { |
| | | return R.error("删除失败"); |
| | | } |
| | | return R.ok("删除成功"); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('system:host:list')") |
| | | @PostMapping("/host/query") |
| | | public R query(@RequestParam(required = false) String condition) { |
| | | List<KeyValVo> vos = new ArrayList<>(); |
| | | LambdaQueryWrapper<Host> wrapper = new LambdaQueryWrapper<>(); |
| | | if (!Cools.isEmpty(condition)) { |
| | | wrapper.like(Host::getName, condition); |
| | | } |
| | | hostService.page(new Page<>(1, 30), wrapper).getRecords().forEach( |
| | | item -> vos.add(new KeyValVo(item.getId(), item.getName())) |
| | | ); |
| | | return R.ok().add(vos); |
| | | } |
| | | |
| | | @PreAuthorize("hasAuthority('system:host:list')") |
| | | @PostMapping("/host/export") |
| | | public void export(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception { |
| | | ExcelUtil.build(ExcelUtil.create(hostService.list(), Host.class), response); |
| | | } |
| | | |
| | | } |
| | | package com.zy.asrs.wms.system.controller;
|
| | |
|
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
| | | import com.zy.asrs.framework.common.Cools;
|
| | | import com.zy.asrs.framework.common.R;
|
| | | import com.zy.asrs.framework.exception.CoolException;
|
| | | import com.zy.asrs.wms.common.annotation.CacheData;
|
| | | import com.zy.asrs.wms.common.annotation.OperationLog;
|
| | | import com.zy.asrs.wms.common.domain.BaseParam;
|
| | | import com.zy.asrs.wms.common.domain.KeyValVo;
|
| | | import com.zy.asrs.wms.common.domain.PageParam;
|
| | | import com.zy.asrs.wms.system.entity.Host;
|
| | | import com.zy.asrs.wms.system.entity.Menu;
|
| | | import com.zy.asrs.wms.system.entity.RoleMenu;
|
| | | import com.zy.asrs.wms.system.service.*;
|
| | | import com.zy.asrs.wms.utils.ExcelUtil;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | | import org.springframework.security.access.prepost.PreAuthorize;
|
| | | import org.springframework.transaction.annotation.Transactional;
|
| | | import org.springframework.web.bind.annotation.*;
|
| | |
|
| | | import javax.servlet.http.HttpServletResponse;
|
| | | import java.util.*;
|
| | |
|
| | | @RestController
|
| | | @RequestMapping("/api")
|
| | | public class HostController extends BaseController {
|
| | |
|
| | | @Autowired
|
| | | private HostService hostService;
|
| | | @Autowired
|
| | | private MenuService menuService;
|
| | | @Autowired
|
| | | private RoleMenuService roleMenuService;
|
| | | @Autowired
|
| | | private RoleService roleService;
|
| | | @Autowired
|
| | | private UserService userService;
|
| | |
|
| | | @PreAuthorize("hasAuthority('system:host:list')")
|
| | | @PostMapping("/host/page")
|
| | | @CacheData(tableName = {"sys_host"})
|
| | | public R page(@RequestBody Map<String, Object> map) {
|
| | | BaseParam baseParam = buildParam(map, BaseParam.class);
|
| | | PageParam<Host, BaseParam> pageParam = new PageParam<>(baseParam, Host.class);
|
| | | return R.ok().add(hostService.page(pageParam, pageParam.buildWrapper(true)));
|
| | | }
|
| | |
|
| | | @PreAuthorize("hasAuthority('system:host:list')")
|
| | | @PostMapping("/host/list")
|
| | | @CacheData(tableName = {"sys_host"})
|
| | | public R list(@RequestBody Map<String, Object> map) {
|
| | | return R.ok().add(hostService.list());
|
| | | }
|
| | |
|
| | | @PreAuthorize("hasAuthority('system:host:list')")
|
| | | @GetMapping("/host/{id}")
|
| | | @CacheData(tableName = {"sys_host"})
|
| | | public R get(@PathVariable("id") Long id) {
|
| | | return R.ok().add(hostService.getById(id));
|
| | | }
|
| | |
|
| | | @PreAuthorize("hasAuthority('system:host:save')")
|
| | | @OperationLog("添加机构")
|
| | | @PostMapping("/host/save")
|
| | | @Transactional
|
| | | public R save(@RequestBody Host host) {
|
| | | host.setCreateTime(new Date());
|
| | | host.setUpdateTime(new Date());
|
| | | if (!hostService.save(host)) {
|
| | | return R.error("添加失败");
|
| | | }
|
| | |
|
| | | List<Menu> parentMenus = menuService.selectByParentId(0L, 0, 1L);
|
| | | for (Menu parentMenu : parentMenus) {
|
| | | List<Menu> menuList = menuService.selectByParentId(parentMenu.getId(), 0, parentMenu.getHostId());
|
| | |
|
| | | parentMenu.setId(null);
|
| | | parentMenu.setHostId(host.getId());
|
| | | boolean save1 = menuService.save(parentMenu);
|
| | | if (!save1) {
|
| | | throw new CoolException("添加失败");
|
| | | }
|
| | |
|
| | | for (Menu menu1 : menuList) {
|
| | | List<Menu> menuList2 = menuService.selectByParentId(menu1.getId(), 1, menu1.getHostId());
|
| | |
|
| | | menu1.setId(null);
|
| | | menu1.setHostId(host.getId());
|
| | | menu1.setParentId(parentMenu.getId());
|
| | | boolean save2 = menuService.save(menu1);
|
| | | if (!save2) {
|
| | | throw new CoolException("添加失败");
|
| | | }
|
| | |
|
| | | for (Menu menu2 : menuList2) {
|
| | | menu2.setId(null);
|
| | | menu2.setHostId(host.getId());
|
| | | menu2.setParentId(menu1.getId());
|
| | | boolean save3 = menuService.save(menu2);
|
| | | if (!save3) {
|
| | | throw new CoolException("添加失败");
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | //创建默认权限
|
| | | for (Menu menu1 : menuList) {
|
| | | RoleMenu roleMenu = new RoleMenu();
|
| | | roleMenu.setRoleId(1L);
|
| | | roleMenu.setMenuId(menu1.getId());
|
| | | boolean save4 = roleMenuService.save(roleMenu);
|
| | | if (!save4) {
|
| | | throw new CoolException("添加失败");
|
| | | }
|
| | | }
|
| | | RoleMenu roleMenu = new RoleMenu();
|
| | | roleMenu.setRoleId(1L);
|
| | | roleMenu.setMenuId(parentMenu.getId());
|
| | | boolean save5 = roleMenuService.save(roleMenu);
|
| | | if (!save5) {
|
| | | throw new CoolException("添加失败");
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | // //创建系统默认菜单
|
| | | // Menu menu = new Menu();
|
| | | // menu.setName("系统管理");
|
| | | // menu.setParentId(0L);
|
| | | // menu.setRoute("/system");
|
| | | // menu.setType(0);
|
| | | // menu.setIcon("UserOutlined");
|
| | | // menu.setSort(1);
|
| | | // menu.setLanguageId("system.system");
|
| | | // menu.setHostId(host.getId());
|
| | | // boolean save = menuService.save(menu);
|
| | | // if (!save) {
|
| | | // throw new CoolException("添加失败");
|
| | | // }
|
| | | // List<Menu> menuList = menuService.selectByPathName("系统管理", 0);
|
| | | // for (Menu menu1 : menuList) {
|
| | | // menu1.setId(null);
|
| | | // menu1.setHostId(host.getId());
|
| | | // menu1.setParentId(menu.getId());
|
| | | // boolean save1 = menuService.save(menu1);
|
| | | // if (!save1) {
|
| | | // throw new CoolException("添加失败");
|
| | | // }
|
| | | //
|
| | | // List<Menu> menuList2 = menuService.selectByPathName(menu1.getName(), 1);
|
| | | // for (Menu menu2 : menuList2) {
|
| | | // menu2.setId(null);
|
| | | // menu2.setHostId(host.getId());
|
| | | // menu2.setParentId(menu1.getId());
|
| | | // boolean save2 = menuService.save(menu2);
|
| | | // if (!save2) {
|
| | | // throw new CoolException("添加失败");
|
| | | // }
|
| | | // }
|
| | | // }
|
| | | //
|
| | | // //创建默认权限
|
| | | // for (Menu menu1 : menuList) {
|
| | | // RoleMenu roleMenu = new RoleMenu();
|
| | | // roleMenu.setRoleId(1L);
|
| | | // roleMenu.setMenuId(menu1.getId());
|
| | | // boolean save1 = roleMenuService.save(roleMenu);
|
| | | // if (!save1) {
|
| | | // throw new CoolException("添加失败");
|
| | | // }
|
| | | // }
|
| | | // RoleMenu roleMenu = new RoleMenu();
|
| | | // roleMenu.setRoleId(1L);
|
| | | // roleMenu.setMenuId(menu.getId());
|
| | | // boolean save1 = roleMenuService.save(roleMenu);
|
| | | // if (!save1) {
|
| | | // throw new CoolException("添加失败");
|
| | | // }
|
| | |
|
| | | return R.ok("添加成功");
|
| | | }
|
| | |
|
| | | @PreAuthorize("hasAuthority('system:host:update')")
|
| | | @OperationLog("修改机构")
|
| | | @PostMapping("/host/update")
|
| | | public R update(@RequestBody Host host) {
|
| | | host.setUpdateTime(new Date());
|
| | | if (!hostService.updateById(host)) {
|
| | | return R.error("修改失败");
|
| | | }
|
| | | return R.ok("修改成功");
|
| | | }
|
| | |
|
| | | @PreAuthorize("hasAuthority('system:host:remove')")
|
| | | @OperationLog("删除机构")
|
| | | @PostMapping("/host/remove/{ids}")
|
| | | @Transactional
|
| | | public R remove(@PathVariable Long[] ids) {
|
| | | List<Host> list = hostService.list(new LambdaQueryWrapper<Host>().in(Host::getId, ids));
|
| | | for (Host host : list) {
|
| | | if (host.getId() == 1) {
|
| | | throw new CoolException("根节点不可被删除");
|
| | | }
|
| | |
|
| | | ArrayList<Long> menuIds = new ArrayList<>();
|
| | | for (Menu menu : menuService.selectByHostId(host.getId())) {
|
| | | menuIds.add(menu.getId());
|
| | | }
|
| | |
|
| | | if (!menuIds.isEmpty()) {
|
| | | roleMenuService.remove(new LambdaQueryWrapper<RoleMenu>().in(RoleMenu::getMenuId, menuIds));
|
| | | menuService.removeByHostId(host.getId());
|
| | | roleService.removeByHostId(host.getId());
|
| | | userService.removeByHostId(host.getId());
|
| | | }
|
| | | }
|
| | |
|
| | | if (!hostService.removeByIds(Arrays.asList(ids))) {
|
| | | return R.error("删除失败");
|
| | | }
|
| | | return R.ok("删除成功");
|
| | | }
|
| | |
|
| | | @PreAuthorize("hasAuthority('system:host:list')")
|
| | | @PostMapping("/host/query")
|
| | | public R query(@RequestParam(required = false) String condition) {
|
| | | List<KeyValVo> vos = new ArrayList<>();
|
| | | LambdaQueryWrapper<Host> wrapper = new LambdaQueryWrapper<>();
|
| | | if (!Cools.isEmpty(condition)) {
|
| | | wrapper.like(Host::getName, condition);
|
| | | }
|
| | | hostService.page(new Page<>(1, 30), wrapper).getRecords().forEach(
|
| | | item -> vos.add(new KeyValVo(item.getId(), item.getName()))
|
| | | );
|
| | | return R.ok().add(vos);
|
| | | }
|
| | |
|
| | | @PreAuthorize("hasAuthority('system:host:list')")
|
| | | @PostMapping("/host/export")
|
| | | public void export(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception {
|
| | | ExcelUtil.build(ExcelUtil.create(hostService.list(), Host.class), response);
|
| | | }
|
| | |
|
| | | }
|