日志记录
This commit is contained in:
@@ -56,6 +56,9 @@ public class Dict extends BaseEntity implements Serializable {
|
||||
@ApiModelProperty(value = "描述")
|
||||
private String description;
|
||||
|
||||
@ApiModelProperty(value = "类型:通用-common;首页-home;热销-hot;")
|
||||
private String type;
|
||||
|
||||
@Column(name = "is_child")
|
||||
@ApiModelProperty(value = "描述 是否有子类0否1是")
|
||||
private Integer isChild;
|
||||
|
||||
@@ -93,6 +93,11 @@ public class Menu extends BaseEntity implements Serializable {
|
||||
|
||||
@ApiModelProperty(value = "是否选中父级菜单")
|
||||
private String activeMenu;
|
||||
|
||||
@Column(name = "is_shop")
|
||||
@ApiModelProperty(value = "商户使用 0:否;1:是;")
|
||||
private Integer isShop;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
|
||||
@@ -80,6 +80,10 @@ public class Role extends BaseEntity implements Serializable {
|
||||
@ApiModelProperty(value = "描述")
|
||||
private String description;
|
||||
|
||||
@Column(name = "shop_id")
|
||||
@ApiModelProperty(value = "商户Id")
|
||||
private Integer shopId;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
|
||||
@@ -51,12 +51,16 @@ public interface MenuRepository extends JpaRepository<Menu, Long>, JpaSpecificat
|
||||
*/
|
||||
List<Menu> findByPidOrderByMenuSort(long pid);
|
||||
|
||||
List<Menu> findByPidAndIsShopOrderByMenuSort(long pid,Integer isShop);
|
||||
|
||||
/**
|
||||
* 查询顶级菜单
|
||||
* @return /
|
||||
*/
|
||||
List<Menu> findByPidIsNullOrderByMenuSort();
|
||||
|
||||
List<Menu> findByPidIsNullAndIsShopOrderByMenuSort(Integer isShop);
|
||||
|
||||
/**
|
||||
* 根据角色ID与菜单类型查询菜单
|
||||
* @param roleIds roleIDs
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* Copyright 2019-2020 Zheng Jie
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package cn.ysk.cashier.system.rest;
|
||||
|
||||
import cn.ysk.cashier.annotation.Log;
|
||||
import cn.ysk.cashier.config.security.security.TokenProvider;
|
||||
import cn.ysk.cashier.exception.BadRequestException;
|
||||
import cn.ysk.cashier.service.LogService;
|
||||
import cn.ysk.cashier.service.dto.LogQueryCriteria;
|
||||
import cn.ysk.cashier.service.dto.LogQueryCriteriaExt;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import cn.ysk.cashier.utils.SecurityUtils;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Zheng Jie
|
||||
* @date 2018-11-24
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/logs")
|
||||
@Api(tags = "系统:日志管理")
|
||||
public class LogController {
|
||||
|
||||
private final LogService logService;
|
||||
private final TokenProvider tokenProvider;
|
||||
|
||||
@Log("导出数据")
|
||||
@ApiOperation("导出数据")
|
||||
@GetMapping(value = "/download")
|
||||
public void exportLog(HttpServletResponse response, LogQueryCriteria criteria) throws IOException {
|
||||
criteria.setLogType("INFO");
|
||||
logService.download(logService.queryAll(criteria), response);
|
||||
}
|
||||
|
||||
@Log("导出错误数据")
|
||||
@ApiOperation("导出错误数据")
|
||||
@GetMapping(value = "/error/download")
|
||||
@PreAuthorize("@el.check()")
|
||||
public void exportErrorLog(HttpServletResponse response, LogQueryCriteria criteria) throws IOException {
|
||||
criteria.setLogType("ERROR");
|
||||
logService.download(logService.queryAll(criteria), response);
|
||||
}
|
||||
@GetMapping
|
||||
@ApiOperation("日志查询")
|
||||
public ResponseEntity<Object> queryLog(LogQueryCriteria criteria, Pageable pageable){
|
||||
String shopId = tokenProvider.getShopId();
|
||||
if (!shopId.equals("1")) {
|
||||
criteria.setShopId(Integer.valueOf(shopId));
|
||||
}
|
||||
criteria.setLogType("INFO");
|
||||
return new ResponseEntity<>(logService.queryAll(criteria,pageable), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/user")
|
||||
@ApiOperation("用户日志查询")
|
||||
public ResponseEntity<Object> queryUserLog(LogQueryCriteria criteria, Pageable pageable){
|
||||
criteria.setLogType("INFO");
|
||||
criteria.setUsername(SecurityUtils.getCurrentUsername());
|
||||
return new ResponseEntity<>(logService.queryAllByUser(criteria,pageable), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/error")
|
||||
@ApiOperation("错误日志查询")
|
||||
@PreAuthorize("@el.check()")
|
||||
public ResponseEntity<Object> queryErrorLog(LogQueryCriteria criteria, Pageable pageable){
|
||||
criteria.setLogType("ERROR");
|
||||
return new ResponseEntity<>(logService.queryAll(criteria,pageable), HttpStatus.OK);
|
||||
}
|
||||
|
||||
@GetMapping(value = "/error/{id}")
|
||||
@ApiOperation("日志异常详情查询")
|
||||
public ResponseEntity<Object> queryErrorLogDetail(@PathVariable Long id){
|
||||
return new ResponseEntity<>(logService.findByErrDetail(id), HttpStatus.OK);
|
||||
}
|
||||
@DeleteMapping(value = "/del/error")
|
||||
@Log("删除所有ERROR日志")
|
||||
@ApiOperation("删除所有ERROR日志")
|
||||
public ResponseEntity<Object> delAllErrorLog(){
|
||||
logService.delAllByError();
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@DeleteMapping(value = "/del/info")
|
||||
@Log("删除所有INFO日志")
|
||||
@ApiOperation("删除所有INFO日志")
|
||||
public ResponseEntity<Object> delAllInfoLog(){
|
||||
String shopId = tokenProvider.getShopId();
|
||||
if (!shopId.equals("1")) {
|
||||
throw new BadRequestException("无操作权限");
|
||||
}
|
||||
logService.delAllByInfo();
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param criteria
|
||||
* @param pageable
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/shopInfo")
|
||||
public ResponseEntity<Object> queryShopInfoLog(LogQueryCriteriaExt criteria, Pageable pageable){
|
||||
return new ResponseEntity<>(logService.shopInfoLog(criteria, pageable),HttpStatus.OK);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@
|
||||
package cn.ysk.cashier.system.rest;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.ysk.cashier.config.security.security.TokenProvider;
|
||||
import cn.ysk.cashier.system.domain.Menu;
|
||||
import cn.ysk.cashier.system.service.dto.MenuDto;
|
||||
import cn.ysk.cashier.system.service.dto.MenuQueryCriteria;
|
||||
@@ -50,12 +51,16 @@ public class MenuController {
|
||||
|
||||
private final MenuService menuService;
|
||||
private final MenuMapper menuMapper;
|
||||
private final TokenProvider tokenProvider;
|
||||
private static final String ENTITY_NAME = "menu";
|
||||
|
||||
@ApiOperation("导出菜单数据")
|
||||
@GetMapping(value = "/download")
|
||||
@PreAuthorize("@el.check('menu:list')")
|
||||
public void exportMenu(HttpServletResponse response, MenuQueryCriteria criteria) throws Exception {
|
||||
if (!tokenProvider.getShopId().equals("1")) {
|
||||
criteria.setIsShop(1);
|
||||
}
|
||||
menuService.download(menuService.queryAll(criteria, false), response);
|
||||
}
|
||||
|
||||
@@ -71,7 +76,10 @@ public class MenuController {
|
||||
@GetMapping(value = "/lazy")
|
||||
@PreAuthorize("@el.check('menu:list','roles:list')")
|
||||
public ResponseEntity<Object> queryAllMenu(@RequestParam Long pid){
|
||||
return new ResponseEntity<>(menuService.getMenus(pid),HttpStatus.OK);
|
||||
if (!tokenProvider.getShopId().equals("1")) {
|
||||
return new ResponseEntity<>(menuService.getMenus(pid,1),HttpStatus.OK);
|
||||
}
|
||||
return new ResponseEntity<>(menuService.getMenus(pid,null),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation("根据菜单ID返回所有子节点ID,包含自身ID")
|
||||
@@ -79,7 +87,12 @@ public class MenuController {
|
||||
@PreAuthorize("@el.check('menu:list','roles:list')")
|
||||
public ResponseEntity<Object> childMenu(@RequestParam Long id){
|
||||
Set<Menu> menuSet = new HashSet<>();
|
||||
List<MenuDto> menuList = menuService.getMenus(id);
|
||||
List<MenuDto> menuList=new ArrayList<>();
|
||||
if (!tokenProvider.getShopId().equals("1")) {
|
||||
menuList = menuService.getMenus(id,1);
|
||||
}else {
|
||||
menuList = menuService.getMenus(id,null);
|
||||
}
|
||||
menuSet.add(menuService.findOne(id));
|
||||
menuSet = menuService.getChildMenus(menuMapper.toEntity(menuList), menuSet);
|
||||
Set<Long> ids = menuSet.stream().map(Menu::getId).collect(Collectors.toSet());
|
||||
@@ -106,7 +119,11 @@ public class MenuController {
|
||||
}
|
||||
return new ResponseEntity<>(menuService.buildTree(new ArrayList<>(menuDtos)),HttpStatus.OK);
|
||||
}
|
||||
return new ResponseEntity<>(menuService.getMenus(null),HttpStatus.OK);
|
||||
if (!tokenProvider.getShopId().equals("1")) {
|
||||
return new ResponseEntity<>(menuService.getMenus(null,1),HttpStatus.OK);
|
||||
}else {
|
||||
return new ResponseEntity<>(menuService.getMenus(null,null),HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
||||
@Log("新增菜单")
|
||||
@@ -137,7 +154,7 @@ public class MenuController {
|
||||
public ResponseEntity<Object> deleteMenu(@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,null);
|
||||
menuSet.add(menuService.findOne(id));
|
||||
menuSet = menuService.getChildMenus(menuMapper.toEntity(menuList), menuSet);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package cn.ysk.cashier.system.rest;
|
||||
|
||||
import cn.hutool.core.lang.Dict;
|
||||
import cn.ysk.cashier.config.security.security.TokenProvider;
|
||||
import cn.ysk.cashier.system.domain.Role;
|
||||
import cn.ysk.cashier.system.service.dto.RoleDto;
|
||||
import cn.ysk.cashier.system.service.dto.RoleQueryCriteria;
|
||||
@@ -27,6 +28,7 @@ import cn.ysk.cashier.exception.BadRequestException;
|
||||
import cn.ysk.cashier.system.service.RoleService;
|
||||
import cn.ysk.cashier.system.service.dto.RoleSmallDto;
|
||||
import cn.ysk.cashier.utils.SecurityUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -48,9 +50,11 @@ import java.util.stream.Collectors;
|
||||
@RequiredArgsConstructor
|
||||
@Api(tags = "系统:角色管理")
|
||||
@RequestMapping("/api/roles")
|
||||
@Slf4j
|
||||
public class RoleController {
|
||||
|
||||
private final RoleService roleService;
|
||||
private final TokenProvider tokenProvider;
|
||||
|
||||
private static final String ENTITY_NAME = "role";
|
||||
|
||||
@@ -65,20 +69,32 @@ public class RoleController {
|
||||
@GetMapping(value = "/download")
|
||||
@PreAuthorize("@el.check('role:list')")
|
||||
public void exportRole(HttpServletResponse response, RoleQueryCriteria criteria) throws IOException {
|
||||
String shopId = tokenProvider.getShopId();
|
||||
if (!shopId.equals("1")) {
|
||||
criteria.setShopId(Integer.valueOf(shopId));
|
||||
}
|
||||
roleService.download(roleService.queryAll(criteria), response);
|
||||
}
|
||||
|
||||
@ApiOperation("返回全部的角色")
|
||||
@GetMapping(value = "/all")
|
||||
@PreAuthorize("@el.check('roles:list','user:add','user:edit')")
|
||||
public ResponseEntity<Object> queryAllRole(){
|
||||
return new ResponseEntity<>(roleService.queryAll(),HttpStatus.OK);
|
||||
public ResponseEntity<Object> queryAllRole(RoleQueryCriteria criteria){
|
||||
String shopId = tokenProvider.getShopId();
|
||||
if (!shopId.equals("1")) {
|
||||
criteria.setShopId(Integer.valueOf(shopId));
|
||||
}
|
||||
return new ResponseEntity<>(roleService.queryAll(criteria),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@ApiOperation("查询角色")
|
||||
@GetMapping
|
||||
@PreAuthorize("@el.check('roles:list')")
|
||||
public ResponseEntity<Object> queryRole(RoleQueryCriteria criteria, Pageable pageable){
|
||||
String shopId = tokenProvider.getShopId();
|
||||
if (!shopId.equals("1")) {
|
||||
criteria.setShopId(Integer.valueOf(shopId));
|
||||
}
|
||||
return new ResponseEntity<>(roleService.queryAll(criteria,pageable),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@@ -88,11 +104,15 @@ public class RoleController {
|
||||
return new ResponseEntity<>(Dict.create().set("level", getLevels(null)),HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Log("新增角色")
|
||||
@Log("新增角色:#resources.getName()")
|
||||
@ApiOperation("新增角色")
|
||||
@PostMapping
|
||||
@PreAuthorize("@el.check('roles:add')")
|
||||
public ResponseEntity<Object> createRole(@Validated @RequestBody Role resources){
|
||||
String shopId = tokenProvider.getShopId();
|
||||
if (!shopId.equals("1")) {
|
||||
resources.setShopId(Integer.valueOf(shopId));
|
||||
}
|
||||
if (resources.getId() != null) {
|
||||
throw new BadRequestException("A new "+ ENTITY_NAME +" cannot already have an ID");
|
||||
}
|
||||
@@ -101,7 +121,7 @@ public class RoleController {
|
||||
return new ResponseEntity<>(HttpStatus.CREATED);
|
||||
}
|
||||
|
||||
@Log("修改角色")
|
||||
@Log("修改角色:#resources.getName()")
|
||||
@ApiOperation("修改角色")
|
||||
@PutMapping
|
||||
@PreAuthorize("@el.check('roles:edit')")
|
||||
@@ -111,7 +131,7 @@ public class RoleController {
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@Log("修改角色菜单")
|
||||
@Log("修改角色菜单:#resources.getName()")
|
||||
@ApiOperation("修改角色菜单")
|
||||
@PutMapping(value = "/menu")
|
||||
@PreAuthorize("@el.check('roles:edit')")
|
||||
@@ -122,7 +142,7 @@ public class RoleController {
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
}
|
||||
|
||||
@Log("删除角色")
|
||||
@Log("删除角色:#ids")
|
||||
@ApiOperation("删除角色")
|
||||
@DeleteMapping
|
||||
@PreAuthorize("@el.check('roles:del')")
|
||||
|
||||
@@ -106,7 +106,7 @@ public interface MenuService {
|
||||
* @param pid /
|
||||
* @return /
|
||||
*/
|
||||
List<MenuDto> getMenus(Long pid);
|
||||
List<MenuDto> getMenus(Long pid,Integer isShop);
|
||||
|
||||
/**
|
||||
* 根据ID获取同级与上级数据
|
||||
|
||||
@@ -62,6 +62,9 @@ public class MenuDto extends BaseDTO implements Serializable {
|
||||
|
||||
private String activeMenu;
|
||||
|
||||
private Integer isShop;
|
||||
|
||||
|
||||
public Boolean getHasChildren() {
|
||||
return subCount > 0;
|
||||
}
|
||||
|
||||
@@ -38,4 +38,7 @@ public class MenuQueryCriteria {
|
||||
|
||||
@Query
|
||||
private Long pid;
|
||||
|
||||
@Query
|
||||
private Integer isShop;
|
||||
}
|
||||
|
||||
@@ -44,6 +44,8 @@ public class RoleDto extends BaseDTO implements Serializable {
|
||||
|
||||
private String description;
|
||||
|
||||
private Integer shopId;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
|
||||
@@ -33,4 +33,7 @@ public class RoleQueryCriteria {
|
||||
|
||||
@Query(type = Query.Type.BETWEEN)
|
||||
private List<Timestamp> createTime;
|
||||
|
||||
@Query
|
||||
private Integer shopId;
|
||||
}
|
||||
|
||||
@@ -182,6 +182,7 @@ public class MenuServiceImpl implements MenuService {
|
||||
menu.setPermission(resources.getPermission());
|
||||
menu.setType(resources.getType());
|
||||
menu.setActiveMenu(resources.getActiveMenu());
|
||||
menu.setIsShop(resources.getIsShop());
|
||||
menuRepository.save(menu);
|
||||
// 计算父级菜单节点数目
|
||||
updateSubCnt(oldPid);
|
||||
@@ -215,12 +216,20 @@ public class MenuServiceImpl implements MenuService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MenuDto> getMenus(Long pid) {
|
||||
public List<MenuDto> getMenus(Long pid,Integer isShop) {
|
||||
List<Menu> menus;
|
||||
if(pid != null && !pid.equals(0L)){
|
||||
menus = menuRepository.findByPidOrderByMenuSort(pid);
|
||||
if(isShop!=null){
|
||||
menus = menuRepository.findByPidAndIsShopOrderByMenuSort(pid,isShop);
|
||||
}else {
|
||||
menus = menuRepository.findByPidOrderByMenuSort(pid);
|
||||
}
|
||||
} else {
|
||||
menus = menuRepository.findByPidIsNullOrderByMenuSort();
|
||||
if(isShop!=null){
|
||||
menus = menuRepository.findByPidIsNullAndIsShopOrderByMenuSort(isShop);
|
||||
}else {
|
||||
menus = menuRepository.findByPidIsNullOrderByMenuSort();
|
||||
}
|
||||
}
|
||||
return menuMapper.toDto(menus);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user