diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/SystemLogController.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/SystemLogController.java index aef1ea6..0a1a463 100644 --- a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/SystemLogController.java +++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/controller/SystemLogController.java @@ -2,6 +2,9 @@ package com.hxhq.business.controller; import java.util.Arrays; import java.util.List; + +import com.hxhq.business.form.systemLog.SystemLogSearchForm; +import com.hxhq.common.security.annotation.RequiresPermissions; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import com.hxhq.business.domain.SystemLog; @@ -28,37 +31,11 @@ public class SystemLogController extends BaseController * 查询系统日志列表 */ @GetMapping("/list") - public TableDataInfo list(SystemLog systemLog) + @RequiresPermissions("business:systemLog:operate") + public TableDataInfo list(SystemLogSearchForm form) { startPage(); - List list = systemLogService.queryList(systemLog); + List list = systemLogService.queryList(form); return getDataTable(list); } - - /** - * 获取系统日志详细信息 - */ - @GetMapping(value = "/info") - public AjaxResult getInfo(Long id) - { - return AjaxResult.success(systemLogService.getById(id)); - } - - /** - * 新增系统日志信息 - */ - @PostMapping("/save") - public AjaxResult save(@RequestBody SystemLog systemLog) - { - return toAjax(systemLogService.saveOrUpdate(systemLog)); - } - - /** - * 删除系统日志信息 - */ - @PostMapping("/delete") - public AjaxResult delete(@RequestBody Long[] ids) - { - return toAjax(systemLogService.removeByIds(Arrays.asList(ids))); - } } diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/form/systemLog/SystemLogSearchForm.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/form/systemLog/SystemLogSearchForm.java new file mode 100644 index 0000000..9e37c50 --- /dev/null +++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/form/systemLog/SystemLogSearchForm.java @@ -0,0 +1,61 @@ +package com.hxhq.business.form.systemLog; + +/** + * @author memory + */ +public class SystemLogSearchForm { + /** 操作类型 */ + private String jcmc; + + /** 操作内容 */ + private String jcnr; + + /** 操作人名称 */ + private String qmrMc; + + /** 开始日期 */ + private String startDate; + + /** 结束日期 */ + private String endDate; + + public String getJcmc() { + return jcmc; + } + + public void setJcmc(String jcmc) { + this.jcmc = jcmc; + } + + public String getJcnr() { + return jcnr; + } + + public void setJcnr(String jcnr) { + this.jcnr = jcnr; + } + + public String getQmrMc() { + return qmrMc; + } + + public void setQmrMc(String qmrMc) { + this.qmrMc = qmrMc; + } + + public String getStartDate() { + return startDate; + } + + public void setStartDate(String startDate) { + this.startDate = startDate; + } + + public String getEndDate() { + return endDate; + } + + public void setEndDate(String endDate) { + this.endDate = endDate; + } +} diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/ISystemLogService.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/ISystemLogService.java index a6717f0..17854e6 100644 --- a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/ISystemLogService.java +++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/ISystemLogService.java @@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.extension.service.IService; import com.hxhq.business.enums.zykgl.JcgjlxEnum; import com.hxhq.business.enums.zykgl.JcmcysEnum; import com.hxhq.business.form.common.SignForm; +import com.hxhq.business.form.systemLog.SystemLogSearchForm; /** * 系统日志Service接口 @@ -20,10 +21,10 @@ public interface ISystemLogService extends IService /** * 查询系统日志列表 * - * @param systemLog 系统日志 + * @param form 系统日志 * @return 系统日志集合 */ - public List queryList(SystemLog systemLog); + public List queryList(SystemLogSearchForm form); /** * 试验稽查轨迹 diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/impl/SystemLogServiceImpl.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/impl/SystemLogServiceImpl.java index 5e0ee05..e94ec6a 100644 --- a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/impl/SystemLogServiceImpl.java +++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/service/impl/SystemLogServiceImpl.java @@ -6,7 +6,9 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.hxhq.business.domain.StudyJcgj; import com.hxhq.business.form.common.SignForm; +import com.hxhq.business.form.systemLog.SystemLogSearchForm; import com.hxhq.common.core.utils.DateUtils; +import com.hxhq.common.core.utils.StringUtils; import org.springframework.stereotype.Service; import com.hxhq.business.mapper.SystemLogMapper; import com.hxhq.business.domain.SystemLog; @@ -25,13 +27,31 @@ public class SystemLogServiceImpl extends ServiceImpl queryList(SystemLog systemLog) + public List queryList(SystemLogSearchForm form) { QueryWrapper queryWrapper = Wrappers.query(); + if(StringUtils.isNoneBlank(form.getQmrMc())){ + queryWrapper.like("qmr_mc",form.getQmrMc()); + } + if(StringUtils.isNoneBlank(form.getJcmc())){ + queryWrapper.and(q->q.like("jcmc",form.getJcmc()) + .or().like("jcmc_en",form.getJcmc())); + } + if(StringUtils.isNoneBlank(form.getJcnr())){ + queryWrapper.and(q->q.like("jcnr",form.getJcnr()) + .or().like("jcnr_en",form.getJcnr())); + } + if (StringUtils.isNoneBlank(form.getStartDate())) { + queryWrapper.ge("create_time", form.getStartDate()); + } + if (StringUtils.isNoneBlank(form.getEndDate())) { + queryWrapper.lt("create_time", DateUtils.dateTime(DateUtils.addDays(DateUtils.parseDate(form.getEndDate()),1))); + } + queryWrapper.orderByDesc("id"); return this.list(queryWrapper); } diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/domain/SysMenu.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/domain/SysMenu.java index f65c82f..51dd17f 100644 --- a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/domain/SysMenu.java +++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/domain/SysMenu.java @@ -5,6 +5,8 @@ import java.util.List; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; + +import com.hxhq.common.core.annotation.Compare; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; import com.hxhq.common.core.web.domain.BaseEntity; @@ -22,6 +24,7 @@ public class SysMenu extends BaseEntity private Long menuId; /** 菜单名称 */ + @Compare(name = "菜单名称",nameEn = "Name") private String menuName; /** 父菜单名称 */ @@ -31,12 +34,15 @@ public class SysMenu extends BaseEntity private Long parentId; /** 显示顺序 */ + @Compare(name = "菜单排序",nameEn = "Sort") private Integer orderNum; /** 路由地址 */ + @Compare(name = "路由地址",nameEn = "Router") private String path; /** 组件路径 */ + @Compare(name = "组件路径",nameEn = "Comp") private String component; /** 路由参数 */ @@ -61,9 +67,11 @@ public class SysMenu extends BaseEntity private String status; /** 权限字符串 */ + @Compare(name = "权限字符",nameEn = "Permit") private String perms; /** 菜单图标 */ + @Compare(name = "菜单图标",nameEn = "Icon") private String icon; /** 子菜单 */ diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/service/impl/SysMenuServiceImpl.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/service/impl/SysMenuServiceImpl.java index dd66ad5..45c47c7 100644 --- a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/service/impl/SysMenuServiceImpl.java +++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/system/service/impl/SysMenuServiceImpl.java @@ -9,6 +9,9 @@ import java.util.List; import java.util.Set; import java.util.stream.Collectors; +import com.hxhq.business.domain.SystemLog; +import com.hxhq.business.service.ISystemLogService; +import com.hxhq.business.utils.ObjectCompareUtil; import com.hxhq.system.domain.SysMenu; import com.hxhq.system.domain.vo.MetaVo; import com.hxhq.system.domain.vo.RouterVo; @@ -45,6 +48,9 @@ public class SysMenuServiceImpl implements ISysMenuService @Autowired private SysRoleMenuMapper roleMenuMapper; + @Autowired + private ISystemLogService systemLogService; + /** * 根据用户查询系统菜单列表 * @@ -302,7 +308,9 @@ public class SysMenuServiceImpl implements ISysMenuService @Override public int insertMenu(SysMenu menu) { - return menuMapper.insertMenu(menu); + int row = menuMapper.insertMenu(menu); + systemLogService.saveInfo("新增菜单","Add Menu",menu.getMenuName(),menu.getMenuName(),SecurityUtils.getUserId(),SecurityUtils.getNickName(),SecurityUtils.getUsername(),null); + return row; } /** @@ -314,7 +322,14 @@ public class SysMenuServiceImpl implements ISysMenuService @Override public int updateMenu(SysMenu menu) { - return menuMapper.updateMenu(menu); + SysMenu old = selectMenuById(menu.getMenuId()); + int row = menuMapper.updateMenu(menu); + + List logList = getModifyLogList(menu,old); + if(logList.size()>0){ + systemLogService.saveBatch(logList); + } + return row; } /** @@ -326,7 +341,10 @@ public class SysMenuServiceImpl implements ISysMenuService @Override public int deleteMenuById(Long menuId) { - return menuMapper.deleteMenuById(menuId); + SysMenu menu = selectMenuById(menuId); + int row = menuMapper.deleteMenuById(menuId); + systemLogService.saveInfo("删除菜单","Remove Menu",menu.getMenuName(),menu.getMenuName(),SecurityUtils.getUserId(),SecurityUtils.getNickName(),SecurityUtils.getUsername(),null); + return row; } /** @@ -541,4 +559,61 @@ public class SysMenuServiceImpl implements ISysMenuService return StringUtils.replaceEach(path, new String[] { Constants.HTTP, Constants.HTTPS, Constants.WWW, ".", ":" }, new String[] { "", "", "", "/", "/" }); } + + private List getModifyLogList(SysMenu info,SysMenu old){ + List list = new ArrayList<>(); + + List fieldChanges = ObjectCompareUtil.compareObjects(old, info); + for (ObjectCompareUtil.FieldChange fieldChange : fieldChanges) { + SystemLog log = getLogInfo(); + log.setJcnr(fieldChange.toString()); + log.setJcnrEn(fieldChange.toEnString()); + list.add(log); + } + //特殊字段 + if(!info.getParentId().equals(old.getParentId())){ + String infoParentName = info.getParentId().equals(0L)?"":selectMenuById(info.getParentId()).getMenuName(); + String oldParentName = old.getParentId().equals(0L)?"":selectMenuById(old.getParentId()).getMenuName(); + + SystemLog log = getLogInfo(); + log.setJcnr("[{\"name\":\"字段名\",\"value\":\"上级菜单\"},{\"name\":\"原值\",\"value\":\""+oldParentName+"\"},{\"name\":\"新值\",\"value\":\""+infoParentName+"\"}]"); + log.setJcnrEn("[{\"name\":\"Field\",\"value\":\"Parent Menu\"},{\"name\":\"Old Value\",\"value\":\""+oldParentName+"\"},{\"name\":\"New Value\",\"value\":\""+infoParentName+"\"}]"); + list.add(log); + } + if(!info.getMenuType().equals(old.getMenuType())){ + SystemLog log = getLogInfo(); + log.setJcnr("[{\"name\":\"字段名\",\"value\":\"菜单类型\"},{\"name\":\"原值\",\"value\":\""+(old.getMenuType().equals("M")?"目录":old.getMenuType().equals("C")?"菜单":"按钮")+"\"},{\"name\":\"新值\",\"value\":\""+(info.getMenuType().equals("M")?"目录":info.getMenuType().equals("C")?"菜单":"按钮")+"\"}]"); + log.setJcnrEn("[{\"name\":\"Field\",\"value\":\"Type\"},{\"name\":\"Old Value\",\"value\":\""+(old.getMenuType().equals("M")?"Dir":old.getMenuType().equals("C")?"Menu":"Btn")+"\"},{\"name\":\"New Value\",\"value\":\""+(info.getMenuType().equals("M")?"Dir":info.getMenuType().equals("C")?"Menu":"Btn")+"\"}]"); + list.add(log); + } + if(!info.getStatus().equals(old.getStatus())){ + SystemLog log = getLogInfo(); + log.setJcnr("[{\"name\":\"字段名\",\"value\":\"菜单状态\"},{\"name\":\"原值\",\"value\":\""+(old.getMenuType().equals("0")?"显示":"隐藏")+"\"},{\"name\":\"新值\",\"value\":\""+(info.getMenuType().equals("0")?"显示":"隐藏")+"\"}]"); + log.setJcnrEn("[{\"name\":\"Field\",\"value\":\"Status\"},{\"name\":\"Old Value\",\"value\":\""+(old.getMenuType().equals("0")?"Visible":"Hide")+"\"},{\"name\":\"New Value\",\"value\":\""+(info.getMenuType().equals("0")?"Visible":"Hide")+"\"}]"); + list.add(log); + } + if(!info.getIsCache().equals(old.getIsCache())){ + SystemLog log = getLogInfo(); + log.setJcnr("[{\"name\":\"字段名\",\"value\":\"是否缓存\"},{\"name\":\"原值\",\"value\":\""+(old.getIsCache().equals("0")?"缓存":"不缓存")+"\"},{\"name\":\"新值\",\"value\":\""+(info.getIsCache().equals("0")?"缓存":"不缓存")+"\"}]"); + log.setJcnrEn("[{\"name\":\"Field\",\"value\":\"Cache Or Not\"},{\"name\":\"Old Value\",\"value\":\""+(old.getIsCache().equals("0")?"Cache":"No Cache")+"\"},{\"name\":\"New Value\",\"value\":\""+(info.getIsCache().equals("0")?"Cache":"No Cache")+"\"}]"); + list.add(log); + } + return list; + } + + /** + * 获取日志基础信息 + * @return + */ + private SystemLog getLogInfo(){ + SystemLog log = new SystemLog(); + log.setJcmc("修改菜单"); + log.setJcmcEn("Modify Menu"); + log.setQmrId(SecurityUtils.getUserId()); + log.setQmrMc(SecurityUtils.getNickName()); + log.setQmrMcEn(SecurityUtils.getUsername()); + return log; + } + + }