|
|
@@ -0,0 +1,181 @@
|
|
|
+package com.jeesite.modules.interceptor;
|
|
|
+
|
|
|
+import javax.annotation.PostConstruct;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.core.NamedThreadLocal;
|
|
|
+import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.web.servlet.HandlerInterceptor;
|
|
|
+
|
|
|
+import com.jeesite.common.idgen.IdGen;
|
|
|
+import com.jeesite.common.lang.StringUtils;
|
|
|
+import com.jeesite.modules.sys.entity.User;
|
|
|
+import com.jeesite.modules.sys.utils.LogUtils;
|
|
|
+import com.jeesite.modules.sys.utils.UserUtils;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 记录工位/客户端等免登录接口访问日志(操作人标记为「未登录客户端」)。
|
|
|
+ */
|
|
|
+@Component
|
|
|
+public class MesClientAccessLogInterceptor implements HandlerInterceptor {
|
|
|
+
|
|
|
+ public static final String LOG_TYPE = "client";
|
|
|
+ public static final String USER_CODE = "client";
|
|
|
+ public static final String USER_NAME = "未登录客户端";
|
|
|
+
|
|
|
+ private static final Logger logger = LoggerFactory.getLogger(MesClientAccessLogInterceptor.class);
|
|
|
+ private static final ThreadLocal<Long> START_TIME = new NamedThreadLocal<Long>("MesClientAccessLog StartTime");
|
|
|
+
|
|
|
+ private static final String[][] TITLE_MAP = {
|
|
|
+ {"/mesLogin/login", "客户端登录"},
|
|
|
+ {"/mesApp/ver", "客户端版本"},
|
|
|
+ {"/mesClientUpgrade/checkUpdate", "客户端升级检查"},
|
|
|
+ {"/mesDeviceState/add", "设备状态上报"},
|
|
|
+ {"/mesProductRecord/submit", "过站提交"},
|
|
|
+ {"/mesProductRecord/result", "过站结果"},
|
|
|
+ {"/mesProductRecord/checkDJ", "点检校验"},
|
|
|
+ {"/mesProductRecord/checkQuality", "质量校验"},
|
|
|
+ {"/mesProductRecord/qmcheck", "气密校验"},
|
|
|
+ {"/mesProductRecord/qmresult", "气密结果"},
|
|
|
+ {"/mesProductRecord/cnccheck", "CNC校验"},
|
|
|
+ {"/mesProductRecord/cncresult", "CNC结果"},
|
|
|
+ {"/mesProductRecord/pccheck", "过程校验"},
|
|
|
+ {"/mesProductRecord/pcresult", "过程结果"},
|
|
|
+ {"/mesProductRecord/pccreate", "过程创建"},
|
|
|
+ {"/mesProductRecord/ccdcheck", "CCD校验"},
|
|
|
+ {"/mesProductRecord/check", "过站校验"},
|
|
|
+ {"/mesProductRecord/select", "扫码查询"},
|
|
|
+ {"/mesProductRecord/ghtime", "过站时间"},
|
|
|
+ {"/mesProductRecord/device", "过站设备"},
|
|
|
+ {"/mesProductRecord/process", "过站工序"},
|
|
|
+ {"/mesProductRecord/yamao", "压铆过站"},
|
|
|
+ {"/mesProductRecord/currentProduct", "当前工件"},
|
|
|
+ {"/mesProductRecord/workData", "工位数据"},
|
|
|
+ {"/mesProductRecord/winfo", "工位信息"},
|
|
|
+ {"/mesProductRecord/work", "工位作业"},
|
|
|
+ {"/mesProductRecord/updateQualityByTiming", "定时质量更新"},
|
|
|
+ {"/mesProductRecord/getConfig", "工位配置"},
|
|
|
+ {"/mesProductRecord/updateOprno", "工位切换"},
|
|
|
+ {"/mesProductRecord/queryProduct", "工件查询"},
|
|
|
+ {"/mesProductRecord/changeLine", "换线"},
|
|
|
+ {"/mesProductFsw/batchsave", "FSW批量上传"},
|
|
|
+ {"/mesProductFsw/add", "FSW上报"},
|
|
|
+ {"/mesProductRivet/batchUpload", "压铆上传"},
|
|
|
+ {"/mesProductGumming/add", "涂胶上报"},
|
|
|
+ {"/mesProductGumming/getSn", "涂胶取码"},
|
|
|
+ {"/mesProductCcd/add", "CCD上报"},
|
|
|
+ {"/mesProductCcd/testDate", "CCD检测"},
|
|
|
+ {"/mesProductProd/batchsave", "过程参数上传"},
|
|
|
+ {"/mesProductBs/batchsave", "BS参数上传"},
|
|
|
+ {"/mesProductCmt/batchsave", "CMT参数上传"},
|
|
|
+ {"/mesProductYgsl/batchsave", "压合参数上传"},
|
|
|
+ {"/mesProductHb/upload", "焊机上传"},
|
|
|
+ {"/mesProductInsulation2/batchUpload", "绝缘测试上传"},
|
|
|
+ {"/mesElectricTorque/batchSave", "电枪扭矩上传"},
|
|
|
+ {"/mesProduct/screen", "生产大屏"},
|
|
|
+ {"/mesProduct/alarmData", "大屏报警数据"},
|
|
|
+ {"/mesProcessAlarm/alarmCount", "报警计数"},
|
|
|
+ {"/mesProcessAlarm/add", "报警上报"},
|
|
|
+ {"/mesProcessCheckRecord/addCheck", "过程点检提交"},
|
|
|
+ {"/mesProcessCheckRecord/checkView", "过程点检查看"},
|
|
|
+ {"/mesProcessCheckRecord/listData", "过程点检查询"},
|
|
|
+ {"/mesProcessCheckRecord/check", "过程点检"},
|
|
|
+ {"/mesProcessCheckGz/submit", "工装点检提交"},
|
|
|
+ {"/mesMaterialPrebind/bind", "物料预绑定"},
|
|
|
+ {"/mesLineProcessMaterial/materials", "工位物料"},
|
|
|
+ {"/mesGp12Record/upload", "GP12上传"},
|
|
|
+ {"/mesProductGp12/saveNg", "GP12不合格"},
|
|
|
+ {"/mesProductGp12/listData", "GP12查询"},
|
|
|
+ {"/mesProductGp12/ulist", "GP12列表"},
|
|
|
+ {"/mesProductWsn/createSn", "生成工件码"},
|
|
|
+ {"/mesProductDbjBind/dbjBind", "挡板筋绑定"},
|
|
|
+ {"/mesProductQm/addItem", "气密项上报"},
|
|
|
+ {"/mesGlueRecord/editSave", "涂胶记录保存"},
|
|
|
+ {"/mesGlueRecord/listData2", "涂胶记录查询"},
|
|
|
+ {"/mesGlueRecord/olist", "涂胶记录列表"},
|
|
|
+ {"/mesGlueRecord/edit", "涂胶记录编辑"},
|
|
|
+ {"/mesDeviceTime/listData2", "设备时间查询"},
|
|
|
+ {"/mesDeviceTime/list2", "设备时间"},
|
|
|
+ {"/mesProductPush/test", "推送测试"},
|
|
|
+ {"/mesGp12Items/items", "GP12项目"}
|
|
|
+ };
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private JdbcTemplate jdbcTemplate;
|
|
|
+
|
|
|
+ @PostConstruct
|
|
|
+ public void ensureLogTypeDict() {
|
|
|
+ try {
|
|
|
+ Integer cnt = jdbcTemplate.queryForObject(
|
|
|
+ "SELECT COUNT(1) FROM js_sys_dict_data WHERE dict_type = 'sys_log_type' AND dict_value = ?",
|
|
|
+ Integer.class, LOG_TYPE);
|
|
|
+ if (cnt != null && cnt > 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String id = IdGen.nextId();
|
|
|
+ jdbcTemplate.update(
|
|
|
+ "INSERT INTO js_sys_dict_data (dict_code, parent_code, parent_codes, tree_sort, tree_sorts, tree_leaf, "
|
|
|
+ + "tree_level, tree_names, dict_label, dict_value, dict_type, is_sys, description, css_style, css_class, "
|
|
|
+ + "status, create_by, create_date, update_by, update_date, corp_code, corp_name) "
|
|
|
+ + "VALUES (?, '0', '0,', 70, '0000000070,', '1', 0, '客户端', '客户端', ?, 'sys_log_type', '0', "
|
|
|
+ + "'工位/客户端免登录接口', '', 'tag green', '0', 'system', NOW(), 'system', NOW(), '0', 'JeeSite')",
|
|
|
+ id, LOG_TYPE);
|
|
|
+ logger.info("已增加访问日志类型:客户端");
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.warn("增加客户端日志类型失败: {}", e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
|
|
|
+ START_TIME.set(System.currentTimeMillis());
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
|
|
|
+ try {
|
|
|
+ User user = UserUtils.getUser();
|
|
|
+ if (user != null && StringUtils.isNotBlank(user.getUserCode())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ long start = 0L;
|
|
|
+ Long startObj = START_TIME.get();
|
|
|
+ if (startObj != null) {
|
|
|
+ start = startObj;
|
|
|
+ }
|
|
|
+ long cost = start > 0 ? (System.currentTimeMillis() - start) : 0L;
|
|
|
+ User client = new User();
|
|
|
+ client.setUserCode(USER_CODE);
|
|
|
+ client.setUserName(USER_NAME);
|
|
|
+ LogUtils.saveLog(client, request, handler, ex, resolveTitle(request), LOG_TYPE, cost);
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.debug("记录客户端访问日志失败: {}", e.getMessage());
|
|
|
+ } finally {
|
|
|
+ START_TIME.remove();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private String resolveTitle(HttpServletRequest request) {
|
|
|
+ String uri = request.getRequestURI();
|
|
|
+ if (uri == null) {
|
|
|
+ uri = "";
|
|
|
+ }
|
|
|
+ for (int i = 0; i < TITLE_MAP.length; i++) {
|
|
|
+ if (uri.contains(TITLE_MAP[i][0])) {
|
|
|
+ return "【客户端】" + TITLE_MAP[i][1];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String shortUri = uri;
|
|
|
+ int mes = uri.lastIndexOf("/mes/");
|
|
|
+ if (mes >= 0) {
|
|
|
+ shortUri = uri.substring(mes);
|
|
|
+ }
|
|
|
+ return "【客户端】" + shortUri;
|
|
|
+ }
|
|
|
+}
|