zouxuan 5 年之前
父節點
當前提交
58e071b987

+ 16 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/PageMonitorDao.java

@@ -0,0 +1,16 @@
+package com.ym.mec.biz.dal.dao;
+
+import com.ym.mec.biz.dal.entity.PageMonitor;
+import com.ym.mec.common.dal.BaseDAO;
+import org.apache.ibatis.annotations.Param;
+
+public interface PageMonitorDao extends BaseDAO<Long, PageMonitor> {
+
+	/**
+	 * 根据事件和用户获取
+	 * @param userId
+	 * @param event
+	 * @return
+	 */
+	PageMonitor findByUserIdAndEvent(@Param("userId") Integer userId, @Param("event") String event);
+}

+ 88 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/PageMonitor.java

@@ -0,0 +1,88 @@
+package com.ym.mec.biz.dal.entity;
+
+import java.util.Date;
+
+/**
+ * 对应数据库表(page_monitor):
+ */
+public class PageMonitor {
+	private Long id;
+
+	private String pageName;
+
+	private String pageUrl;
+
+	private String event;
+
+	private String eventName;
+
+	private Integer userId;
+
+	private Integer times;
+
+	private Date updateTime;
+
+	public Long getId() {
+		return id;
+	}
+
+	public void setId(Long id) {
+		this.id = id;
+	}
+
+	public String getPageName() {
+		return pageName;
+	}
+
+	public void setPageName(String pageName) {
+		this.pageName = pageName;
+	}
+
+	public String getPageUrl() {
+		return pageUrl;
+	}
+
+	public void setPageUrl(String pageUrl) {
+		this.pageUrl = pageUrl;
+	}
+
+	public String getEvent() {
+		return event;
+	}
+
+	public void setEvent(String event) {
+		this.event = event;
+	}
+
+	public String getEventName() {
+		return eventName;
+	}
+
+	public void setEventName(String eventName) {
+		this.eventName = eventName;
+	}
+
+	public Integer getUserId() {
+		return userId;
+	}
+
+	public void setUserId(Integer userId) {
+		this.userId = userId;
+	}
+
+	public Integer getTimes() {
+		return times;
+	}
+
+	public void setTimes(Integer times) {
+		this.times = times;
+	}
+
+	public Date getUpdateTime() {
+		return updateTime;
+	}
+
+	public void setUpdateTime(Date updateTime) {
+		this.updateTime = updateTime;
+	}
+}

+ 12 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/PageMonitorService.java

@@ -0,0 +1,12 @@
+package com.ym.mec.biz.service;
+
+import com.ym.mec.biz.dal.entity.PageMonitor;
+import com.ym.mec.common.service.BaseService;
+
+public interface PageMonitorService extends BaseService<Long, PageMonitor> {
+    /**
+     * 新增页面监控
+     * @param pageMonitor
+     */
+    void add(PageMonitor pageMonitor);
+}

+ 52 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/PageMonitorServiceImpl.java

@@ -0,0 +1,52 @@
+package com.ym.mec.biz.service.impl;
+
+import com.ym.mec.auth.api.client.SysUserFeignService;
+import com.ym.mec.auth.api.entity.SysUser;
+import com.ym.mec.biz.dal.dao.PageMonitorDao;
+import com.ym.mec.biz.dal.entity.PageMonitor;
+import com.ym.mec.biz.service.PageMonitorService;
+import com.ym.mec.common.dal.BaseDAO;
+import com.ym.mec.common.exception.BizException;
+import com.ym.mec.common.service.impl.BaseServiceImpl;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.Date;
+
+@Service
+public class PageMonitorServiceImpl extends BaseServiceImpl<Long, PageMonitor>  implements PageMonitorService {
+	
+	@Autowired
+	private PageMonitorDao pageMonitorDao;
+	@Autowired
+	private SysUserFeignService sysUserFeignService;
+
+	@Override
+	public BaseDAO<Long, PageMonitor> getDAO() {
+		return pageMonitorDao;
+	}
+
+	@Override
+	@Transactional(rollbackFor = Exception.class)
+	public void add(PageMonitor pageMonitor) {
+		if(pageMonitor == null){
+			throw new BizException("参数校验失败");
+		}
+		SysUser sysUser = sysUserFeignService.queryUserInfo();
+		if(sysUser == null){
+			throw new BizException("用户信息获取失败");
+		}
+		Integer userId = sysUser.getId();
+		PageMonitor oldPageMonitor = pageMonitorDao.findByUserIdAndEvent(userId,pageMonitor.getEvent());
+		if(oldPageMonitor == null){
+			pageMonitor.setUserId(userId);
+			pageMonitor.setTimes(1);
+			pageMonitorDao.insert(pageMonitor);
+		}else {
+			oldPageMonitor.setTimes(oldPageMonitor.getTimes() + 1);
+			oldPageMonitor.setUpdateTime(new Date());
+			pageMonitorDao.update(oldPageMonitor);
+		}
+	}
+}

+ 68 - 0
mec-biz/src/main/resources/config/mybatis/PageMonitorMapper.xml

@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<!--
+这个文件是自动生成的。
+不要修改此文件。所有改动将在下次重新自动生成时丢失。
+-->
+<mapper namespace="com.ym.mec.biz.dal.dao.PageMonitorDao">
+
+    <resultMap type="com.ym.mec.biz.dal.entity.PageMonitor" id="PageMonitor">
+        <result column="id_" property="id"/>
+        <result property="updateTime" column="update_time_"/>
+        <result property="userId" column="user_id_"/>
+        <result property="times" column="times_"/>
+        <result property="event" column="event_"/>
+        <result property="eventName" column="event_name_"/>
+        <result property="pageName" column="page_name_"/>
+        <result property="pageUrl" column="page_url_"/>
+    </resultMap>
+
+    <!-- 根据主键查询一条记录 -->
+    <select id="get" resultMap="PageMonitor">
+		SELECT * FROM page_monitor WHERE id_ = #{id} 
+	</select>
+
+    <!-- 全查询 -->
+    <select id="findAll" resultMap="PageMonitor">
+		SELECT * FROM page_monitor ORDER BY id_
+	</select>
+    <select id="findByUserIdAndEvent" resultMap="PageMonitor">
+        SELECT * FROM page_monitor WHERE user_id_ = #{userId} AND event_ = #{event} LIMIT 1 FOR UPDATE
+    </select>
+
+    <!-- 向数据库增加一条记录 -->
+    <insert id="insert" parameterType="com.ym.mec.biz.dal.entity.PageMonitor" useGeneratedKeys="true" keyColumn="id"
+            keyProperty="id">
+        INSERT INTO page_monitor (page_name_,page_url_,event_,event_name_,user_id_,times_,update_time_)
+        VALUES(#{pageName},#{pageUrl},#{event},#{eventName},#{userId},#{times},NOW())
+    </insert>
+
+    <!-- 根据主键查询一条记录 -->
+    <update id="update" parameterType="com.ym.mec.biz.dal.entity.Organization">
+        UPDATE page_monitor
+        <set>
+            <if test="pageName != null">
+                page_name_ = #{pageName},
+            </if>
+            <if test="pageUrl != null">
+                page_url_ = #{pageUrl},
+            </if>
+            <if test="event != null">
+                event_ = #{event},
+            </if>
+            <if test="eventName != null">
+                event_name_ = #{eventName},
+            </if>
+            <if test="userId != null">
+                user_id_ = #{userId},
+            </if>
+            <if test="times != null">
+                times_ = #{times},
+            </if>
+            <if test="updateTime != null">
+                update_time_ = #{updateTime}
+            </if>
+        </set>
+        WHERE id_ = #{id}
+    </update>
+</mapper>

+ 28 - 0
mec-student/src/main/java/com/ym/mec/student/controller/PageMonitorController.java

@@ -0,0 +1,28 @@
+package com.ym.mec.student.controller;
+
+import com.ym.mec.biz.dal.entity.PageMonitor;
+import com.ym.mec.biz.service.PageMonitorService;
+import com.ym.mec.common.controller.BaseController;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RequestMapping("pageMonitor")
+@Api(tags = "页面监控")
+@RestController
+public class PageMonitorController extends BaseController {
+
+    @Autowired
+    private PageMonitorService pageMonitorService;
+
+    @ApiOperation(value = "新增页面监控")
+    @PostMapping("/add")
+    private Object add(PageMonitor pageMonitor){
+        pageMonitorService.add(pageMonitor);
+        return succeed();
+    }
+
+}