自动化立体仓库 - WMS系统
#
lsh
2024-06-11 8270ea505cb234a1d0b79e3a0f1e1f376b240046
#
8个文件已修改
1个文件已添加
146 ■■■■■ 已修改文件
pom.xml 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/common/config/AdminInterceptor.java 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/common/config/AspectConfig.java 110 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/common/web/AuthController.java 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/system/entity/OperateLog.java 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/zy/system/entity/UserLogin.java 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/application.yml 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/UserLoginMapper.xml 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/webapp/static/js/userLogin/userLogin.js 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pom.xml
@@ -37,6 +37,10 @@
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-aop</artifactId>
        </dependency>
        <dependency>
            <groupId>cn.cool</groupId>
            <artifactId>framework</artifactId>
            <version>${cool.version}</version>
src/main/java/com/zy/common/config/AdminInterceptor.java
@@ -106,7 +106,11 @@
    private boolean check(HttpServletRequest request, HttpServletResponse response, String memo) {
        try {
            String token = request.getHeader("token");
            String token = new String();
            token = request.getHeader("token");
            if (Cools.isEmpty(token)){
                return true;
            }
            UserLogin userLogin = userLoginService.selectOne(new EntityWrapper<UserLogin>().eq("token", token));
            if (null == userLogin){
                Http.response(response, BaseRes.DENIED);
src/main/java/com/zy/common/config/AspectConfig.java
New file
@@ -0,0 +1,110 @@
package com.zy.common.config;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.annotations.ManagerAuth;
import com.core.common.Cools;
import com.zy.system.entity.OperateLog;
import com.zy.system.entity.User;
import com.zy.system.entity.UserLogin;
import com.zy.system.service.OperateLogService;
import com.zy.system.service.UserLoginService;
import com.zy.system.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
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 org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
@Component
@Aspect
@Slf4j
public class AspectConfig {
    @Autowired
    private UserLoginService userLoginService;
    @Autowired
    private UserService userService;
    @Autowired
    private OperateLogService operateLogService;
    @Pointcut("execution(* com.zy.asrs.controller.*(..))")
    private void webLog() {
    }
    @Around("@within(org.springframework.web.bind.annotation.RestController)" +
            "||@within(org.springframework.stereotype.Controller)")
    public Object after(ProceedingJoinPoint joinPoint) throws Throwable{
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        //if(requestAttributes != null){
        //    return joinPoint.proceed();
        //}
        HttpServletRequest request = requestAttributes.getRequest();
        long start = System.currentTimeMillis();
        Object result = joinPoint.proceed(joinPoint.getArgs());
        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
        Method method = signature.getMethod();
        if (method.isAnnotationPresent(ManagerAuth.class)){
            ManagerAuth annotation = method.getAnnotation(ManagerAuth.class);
            if (annotation.value().equals(ManagerAuth.Auth.CHECK)){
                if (!Cools.isEmpty(annotation.memo())) {
                    saveLog(joinPoint, request, result,annotation.memo());
                }
            }
        }
        long end = System.currentTimeMillis();
//        log.info("请求日志的打印");
//        log.info("请求地址:{}", Optional.ofNullable(request.getRequestURI().toString()).orElse(null));
//        log.info("请求方式:{}",request.getMethod());
//        log.info("请求类方法:{}",joinPoint.getSignature());
//        log.info("请求类方法参数:{}", JSONObject.toJSONString(filterArgs(joinPoint.getArgs())));
//        log.info("请求响应参数{}", JSONObject.toJSONString(result));
//        log.info("执行耗时:{}", end - start);
        return result;
    }
    private List<Object> filterArgs(Object[] objects) {
        return Arrays.stream(objects).filter(obj -> !(obj instanceof MultipartFile)
                && !(obj instanceof HttpServletResponse)
                && !(obj instanceof HttpServletRequest)).collect(Collectors.toList());
    }
    private void saveLog(ProceedingJoinPoint joinPoint, HttpServletRequest request, Object result,String memo) {
        Long userId = 9527L;
        String token = request.getHeader("token");
        UserLogin userLogin = userLoginService.selectOne(new EntityWrapper<UserLogin>().eq("token", token).eq("system", "WMS"));
        if (userLogin != null) {
            User user = userService.selectById(userLogin.getUserId());
            if (user != null) {
                userId = user.getId();
            }
        }
        // 记录操作日志
        OperateLog operateLog = new OperateLog();
        operateLog.setAction(Cools.isEmpty(memo)?request.getRequestURI():memo);
        operateLog.setIp(request.getRemoteAddr());
        operateLog.setUserId(userId);
        operateLog.setRequest(JSONObject.toJSONString(filterArgs(joinPoint.getArgs())));
        operateLog.setResponse(JSONObject.toJSONString(result));
        operateLogService.insert(operateLog);
    }
}
src/main/java/com/zy/common/web/AuthController.java
@@ -80,6 +80,7 @@
        userLogin.setUserId(user.getId());
        userLogin.setToken(token);
        userLogin.setCreateTime(new Date());
        userLogin.setSystem("WMS");
        userLoginService.insert(userLogin);
        Map<String, Object> res = new HashMap<>();
        res.put("username", user.getUsername());
src/main/java/com/zy/system/entity/OperateLog.java
@@ -80,8 +80,10 @@
        User user = service.selectById(this.userId);
        if (!Cools.isEmpty(user)){
            return user.getUsername();
        } else if (this.userId==9527L){
            return "未知";
        }
        return null;
        return "未知";
    }
    public void setUserId(Long userId) {
        this.userId = userId;
src/main/java/com/zy/system/entity/UserLogin.java
@@ -8,12 +8,14 @@
import com.core.common.Cools;
import com.core.common.SpringUtils;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
@TableName("sys_user_login")
@Data
public class UserLogin implements Serializable {
    private static final long serialVersionUID = 1L;
@@ -30,6 +32,7 @@
    @ApiModelProperty(value= "所属项目")
    @TableField("host_id")
    private Long hostId;
    /**
     * 员工
     */
@@ -47,6 +50,12 @@
    @TableField("create_time")
    private Date createTime;
    /**
     * 登录系统
     */
    @TableField("system")
    private String system;
    public Long getId() {
        return id;
    }
@@ -62,6 +71,7 @@
    public void setHostId(Long hostId) {
        this.hostId = hostId;
    }
    public Long getUserId() {
        return userId;
    }
@@ -101,5 +111,11 @@
        this.createTime = createTime;
    }
    public String getSystem() {
        return system;
    }
    public void setSystem(String system) {
        this.system = system;
    }
}
src/main/resources/application.yml
@@ -10,7 +10,7 @@
    enabled: false
  datasource:
    driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
    url: jdbc:sqlserver://127.0.0.1:1433;databasename=ahyxasrs
    url: jdbc:sqlserver://192.168.4.15:1433;databasename=source
    username: sa
    password: sa@123
  mvc:
src/main/resources/mapper/UserLoginMapper.xml
@@ -5,9 +5,11 @@
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.zy.system.entity.UserLogin">
        <id column="id" property="id" />
        <result column="host_id" property="hostId" />
        <result column="user_id" property="userId" />
        <result column="token" property="token" />
        <result column="create_time" property="createTime" />
        <result column="system" property="system" />
    </resultMap>
src/main/webapp/static/js/userLogin/userLogin.js
@@ -21,6 +21,7 @@
            ,{field: 'id', title: 'ID', sort: true,align: 'center', fixed: 'left', width: 80}
            ,{field: 'userUsername', align: 'center',title: '员工',event: 'User', style: 'text-decoration: underline;cursor:pointer'}
            ,{field: 'token', align: 'center',title: '凭证值'}
            ,{field: 'memo', align: 'center',title: '记录'}
            ,{field: 'createTime$', align: 'center',title: '添加时间'}
            ,{fixed: 'right', title:'操作', align: 'center', toolbar: '#operate', width:150}