diff --git a/talkonlineweb/pom.xml b/talkonlineweb/pom.xml index 45ddb21..8feaaf1 100644 --- a/talkonlineweb/pom.xml +++ b/talkonlineweb/pom.xml @@ -76,6 +76,10 @@ lombok true + + org.springframework.boot + spring-boot-starter-aop + diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/annotation/LogAnnotation.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/annotation/LogAnnotation.java new file mode 100644 index 0000000..fddaa1a --- /dev/null +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/annotation/LogAnnotation.java @@ -0,0 +1,10 @@ +package com.lyms.talkonlineweb.annotation; + +import java.lang.annotation.*; + +@Target(ElementType.METHOD) //注解放置的目标位置,METHOD是可注解在方法级别上 +@Retention(RetentionPolicy.RUNTIME) //注解在哪个阶段执行 +@Documented //生成文档 +public @interface LogAnnotation { + String value() default ""; +} diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/aop/CrudCommandAop.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/aop/CrudCommandAop.java new file mode 100644 index 0000000..b8651e6 --- /dev/null +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/aop/CrudCommandAop.java @@ -0,0 +1,72 @@ +package com.lyms.talkonlineweb.aop; + +import com.alibaba.fastjson.JSON; +import com.lyms.talkonlineweb.annotation.LogAnnotation; +import com.lyms.talkonlineweb.domain.LymsLogsCrud; +import com.lyms.talkonlineweb.service.LymsLogsCrudService; +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.annotation.AfterReturning; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Pointcut; +import org.aspectj.lang.reflect.MethodSignature; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import javax.servlet.http.HttpServletRequest; +import javax.xml.ws.spi.http.HttpContext; +import java.lang.reflect.Method; +import java.util.Date; + +@Aspect +@Component +public class CrudCommandAop { + + @Autowired + private LymsLogsCrudService lymsLogsCrudService; + + //定义切点 @Pointcut + //在注解的位置切入代码 + @Pointcut("@annotation( com.lyms.talkonlineweb.annotation.LogAnnotation)") + public void logPoinCut() { + } + + //切面 配置通知 + @AfterReturning("logPoinCut()") + public void saveSysLog(JoinPoint joinPoint) { + System.out.println("切面。。。。。"); + //日志实体 + LymsLogsCrud lymsLogsCrud = new LymsLogsCrud(); + + //从切面织入点处通过反射机制获取织入点处的方法 +// MethodSignature signature = (MethodSignature) joinPoint.getSignature(); + //获取切入点所在的方法 +// Method method = signature.getMethod(); + + //获取操作 +// LogAnnotation logAnnotation =method.getAnnotation(LogAnnotation.class); +// if (logAnnotation != null) { +// String value = logAnnotation.value(); +// lymsLogsCrud.setCrud(value);//保存获取的操作 +// } + + //获取请求的类名 +// String className = joinPoint.getTarget().getClass().getName(); + //获取请求的方法名 +// String methodName = method.getName(); +// lymsLogsCrud.setMethod(className + "." + methodName); + + //请求的参数 +// Object[] args = joinPoint.getArgs(); + //将参数所在的数组转换成json +// String params = JSON.toJSONString(args); +// lymsLogsCrud.setParams(params); + +// lymsLogsCrud.setCreatdata(new Date()); + //获取用户名 +// lymsLogsCrud.setUsername(ShiroUtils.getUserEntity().getUsername()); + + + //调用service保存 LymsLogsCrud实体类到数据库 +// lymsLogsCrudService.save(lymsLogsCrud); + } +} diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/config/DataScopeInterceptor.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/config/DataScopeInterceptor.java index 1496856..7557ce5 100644 --- a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/config/DataScopeInterceptor.java +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/config/DataScopeInterceptor.java @@ -35,15 +35,15 @@ public class DataScopeInterceptor extends AbstractSqlParserHandler implements I if (!SqlCommandType.SELECT.equals(mappedStatement.getSqlCommandType())) { return invocation.proceed(); } - if (!SqlCommandType.INSERT.equals(mappedStatement.getSqlCommandType())) { + if (SqlCommandType.INSERT.equals(mappedStatement.getSqlCommandType())) { System.out.println("新增。。。。。。。。。。。。。。。。。。。。。。。。"); return invocation.proceed(); } - if (!SqlCommandType.UPDATE.equals(mappedStatement.getSqlCommandType())) { + if (SqlCommandType.UPDATE.equals(mappedStatement.getSqlCommandType())) { System.out.println("修改。。。。。。。。。。。。。。。。。。。。。。。。"); return invocation.proceed(); } - if (!SqlCommandType.DELETE.equals(mappedStatement.getSqlCommandType())) { + if (SqlCommandType.DELETE.equals(mappedStatement.getSqlCommandType())) { System.out.println("删除。。。。。。。。。。。。。。。。。。。。。。。。"); return invocation.proceed(); } diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/controller/HospitalController.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/controller/HospitalController.java index 0236edb..a4bf0b9 100644 --- a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/controller/HospitalController.java +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/controller/HospitalController.java @@ -4,10 +4,12 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.lyms.talkonlineweb.domain.LymsDict; import com.lyms.talkonlineweb.domain.LymsHospital; +import com.lyms.talkonlineweb.domain.LymsLogsCrud; import com.lyms.talkonlineweb.domain.LymsRole; import com.lyms.talkonlineweb.result.BaseResponse; import com.lyms.talkonlineweb.service.LymsDictService; import com.lyms.talkonlineweb.service.LymsHospitalService; +import com.lyms.talkonlineweb.service.LymsLogsCrudService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; @@ -27,6 +29,9 @@ public class HospitalController { @Autowired private LymsHospitalService lymsHospitalService; + @Autowired + private LymsLogsCrudService lymsLogsCrudService; + /** * 获取医院列表 * @param hospital @@ -114,6 +119,15 @@ public class HospitalController { hospital.setUpdatedtime(new Date()); } boolean f=lymsHospitalService.saveOrUpdate(hospital); + + //操作记录 + LymsLogsCrud lymsLogsCrud=new LymsLogsCrud(); + lymsLogsCrud.setUname(hospital.getCreator()); + lymsLogsCrud.setCrudtype(hospital.getHid()==null?"新增医院":"编辑医院"); + lymsLogsCrud.setHname(hospital.getHname()); + lymsLogsCrud.setCreatdata(new Date()); + lymsLogsCrudService.save(lymsLogsCrud); + baseResponse.setErrorcode(f==true?0:1); return baseResponse; } @@ -127,6 +141,7 @@ public class HospitalController { public BaseResponse delHosp(int hid){ BaseResponse baseResponse=new BaseResponse(); boolean f=lymsHospitalService.removeById(hid); + baseResponse.setErrorcode(f==true?0:1); return baseResponse; } diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/controller/LymsLogsController.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/controller/LymsLogsController.java new file mode 100644 index 0000000..22c2203 --- /dev/null +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/controller/LymsLogsController.java @@ -0,0 +1,33 @@ +package com.lyms.talkonlineweb.controller; + +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.lyms.talkonlineweb.domain.LymsLogsCrud; +import com.lyms.talkonlineweb.result.BaseResponse; +import com.lyms.talkonlineweb.service.LymsLogsCrudService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +/** + * 医院管理 + */ +@RestController +@RequestMapping("logs") +public class LymsLogsController { + + @Autowired + private LymsLogsCrudService lymsLogsCrudService; + /** + * 获取logscrud记录 + * + * @return + */ + @GetMapping("logscrud") + public BaseResponse logscrud(LymsLogsCrud lymsLogsCrud, int current, int size){ + BaseResponse baseResponse=new BaseResponse(); + Page page=new Page<>(current,size); + Page lymsLogsCrudPage=lymsLogsCrudService.page(page,Wrappers.query(lymsLogsCrud).orderByDesc("creatdata")); + baseResponse.setObject(lymsLogsCrudPage); + return baseResponse; + } +} diff --git a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/LymsLogsCrud.java b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/LymsLogsCrud.java index feac92d..9a293cc 100644 --- a/talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/LymsLogsCrud.java +++ b/talkonlineweb/src/main/java/com/lyms/talkonlineweb/domain/LymsLogsCrud.java @@ -22,28 +22,28 @@ public class LymsLogsCrud implements Serializable { private Integer id; /** - * 操作用户id + * 操作用户名字 */ - @TableField(value = "uid") - private Integer uid; + @TableField(value = "uname") + private String uname; /** - * 1:增,2:删,3:改 + * crud相关操作 */ - @TableField(value = "crud") - private Integer crud; + @TableField(value = "crudtype") + private String crudtype; /** - * 医院id + * 医院名称 */ - @TableField(value = "hoid") - private Integer hoid; + @TableField(value = "hname") + private String hname; /** - * 科室id + * 科室名称 */ - @TableField(value = "hdid") - private Integer hdid; + @TableField(value = "hdname") + private String hdname; /** * 操作时间 @@ -67,10 +67,10 @@ public class LymsLogsCrud implements Serializable { } LymsLogsCrud other = (LymsLogsCrud) that; return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId())) - && (this.getUid() == null ? other.getUid() == null : this.getUid().equals(other.getUid())) - && (this.getCrud() == null ? other.getCrud() == null : this.getCrud().equals(other.getCrud())) - && (this.getHoid() == null ? other.getHoid() == null : this.getHoid().equals(other.getHoid())) - && (this.getHdid() == null ? other.getHdid() == null : this.getHdid().equals(other.getHdid())) + && (this.getUname() == null ? other.getUname() == null : this.getUname().equals(other.getUname())) + && (this.getCrudtype() == null ? other.getCrudtype() == null : this.getCrudtype().equals(other.getCrudtype())) + && (this.getHname() == null ? other.getHname() == null : this.getHname().equals(other.getHname())) + && (this.getHdname() == null ? other.getHdname() == null : this.getHdname().equals(other.getHdname())) && (this.getCreatdata() == null ? other.getCreatdata() == null : this.getCreatdata().equals(other.getCreatdata())); } @@ -79,10 +79,10 @@ public class LymsLogsCrud implements Serializable { final int prime = 31; int result = 1; result = prime * result + ((getId() == null) ? 0 : getId().hashCode()); - result = prime * result + ((getUid() == null) ? 0 : getUid().hashCode()); - result = prime * result + ((getCrud() == null) ? 0 : getCrud().hashCode()); - result = prime * result + ((getHoid() == null) ? 0 : getHoid().hashCode()); - result = prime * result + ((getHdid() == null) ? 0 : getHdid().hashCode()); + result = prime * result + ((getUname() == null) ? 0 : getUname().hashCode()); + result = prime * result + ((getCrudtype() == null) ? 0 : getCrudtype().hashCode()); + result = prime * result + ((getHname() == null) ? 0 : getHname().hashCode()); + result = prime * result + ((getHdname() == null) ? 0 : getHdname().hashCode()); result = prime * result + ((getCreatdata() == null) ? 0 : getCreatdata().hashCode()); return result; } @@ -94,10 +94,10 @@ public class LymsLogsCrud implements Serializable { sb.append(" ["); sb.append("Hash = ").append(hashCode()); sb.append(", id=").append(id); - sb.append(", uid=").append(uid); - sb.append(", crud=").append(crud); - sb.append(", hoid=").append(hoid); - sb.append(", hdid=").append(hdid); + sb.append(", uname=").append(uname); + sb.append(", crudtype=").append(crudtype); + sb.append(", hname=").append(hname); + sb.append(", hdname=").append(hdname); sb.append(", creatdata=").append(creatdata); sb.append(", serialVersionUID=").append(serialVersionUID); sb.append("]"); diff --git a/talkonlineweb/src/main/resources/mapper/LymsLogsCrudMapper.xml b/talkonlineweb/src/main/resources/mapper/LymsLogsCrudMapper.xml index 40b8414..e77b99b 100644 --- a/talkonlineweb/src/main/resources/mapper/LymsLogsCrudMapper.xml +++ b/talkonlineweb/src/main/resources/mapper/LymsLogsCrudMapper.xml @@ -6,15 +6,15 @@ - - - - + + + + - id,uid,crud, - hoid,hdid,creatdata + id,uname,crudtype, + hname,hdname,creatdata