添加行为记录表
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
package com.ruoyi.cms.controller.app;
|
||||
|
||||
import com.ruoyi.cms.domain.msg.HrUserBehaviorRecord;
|
||||
import com.ruoyi.cms.service.msg.HrUserBehaviorRecordService;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.page.TableDataInfo;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.utils.SiteSecurityUtils;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/app/behavior")
|
||||
@Api(tags = "移动端:行为记录")
|
||||
public class HrUserBehaviorRecordController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private HrUserBehaviorRecordService hrUserBehaviorRecordService;
|
||||
|
||||
/**
|
||||
* 查询行为记录列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@ApiOperation("查询行为记录列表")
|
||||
public TableDataInfo list(HrUserBehaviorRecord hrUserBehaviorRecord) {
|
||||
if (!SiteSecurityUtils.isLogin()) {
|
||||
throw new ServiceException("用户未登录");
|
||||
}
|
||||
Long userId = SiteSecurityUtils.getUserId();
|
||||
boolean admin = SiteSecurityUtils.isAdmin(userId);
|
||||
if (!admin) {
|
||||
hrUserBehaviorRecord.setActorId(userId);
|
||||
} else {
|
||||
hrUserBehaviorRecord.setActorId(null);
|
||||
}
|
||||
startPage();
|
||||
List<HrUserBehaviorRecord> list = hrUserBehaviorRecordService.selectBehaviorRecordList(hrUserBehaviorRecord);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 上报浏览行为/投递行为
|
||||
*/
|
||||
@ApiOperation("上报浏览行为/投递行为")
|
||||
@PostMapping("/report")
|
||||
public AjaxResult reportBehavior(@RequestBody HrUserBehaviorRecord record) {
|
||||
HrUserBehaviorRecord exist = hrUserBehaviorRecordService.getExistViewRecord(
|
||||
record.getActorType(),
|
||||
record.getActorId(),
|
||||
record.getTargetType(),
|
||||
record.getTargetId()
|
||||
);
|
||||
if (exist == null) {
|
||||
record.setViewNum(1);
|
||||
hrUserBehaviorRecordService.save(record);
|
||||
} else {
|
||||
if (record.getViewDuration() > 0) {
|
||||
// 页面离开上报:累加时长
|
||||
exist.setViewDuration(exist.getViewDuration() + record.getViewDuration());
|
||||
} else {
|
||||
// 页面进入上报:次数+1
|
||||
exist.setViewNum(exist.getViewNum() + 1);
|
||||
}
|
||||
hrUserBehaviorRecordService.updateById(exist);
|
||||
}
|
||||
return success();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.ruoyi.cms.domain.msg;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.ruoyi.common.core.domain.BaseEntity;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@ApiModel("求职招聘双方行为记录表")
|
||||
@TableName("hr_user_behavior_record")
|
||||
public class HrUserBehaviorRecord extends BaseEntity {
|
||||
|
||||
@TableField(exist = false)
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/** 操作人类型:1求职者 2招聘方 */
|
||||
@ApiModelProperty("操作人类型:1求职者 2招聘方")
|
||||
private Integer actorType;
|
||||
|
||||
/** 操作人ID(求职者ID/企业用户ID) */
|
||||
@ApiModelProperty("操作人ID(求职者ID/企业用户ID) ")
|
||||
private Long actorId;
|
||||
|
||||
/** 浏览目标类型:1简历 2岗位 */
|
||||
@ApiModelProperty("浏览目标类型:1简历 2岗位")
|
||||
private Integer targetType;
|
||||
|
||||
/** 目标ID(简历ID/岗位ID) */
|
||||
@ApiModelProperty("目标ID(简历ID/岗位ID)")
|
||||
private Long targetId;
|
||||
|
||||
/** 行为类型:1阅览 2投递简历 */
|
||||
@ApiModelProperty("行为类型:1阅览 2投递简历")
|
||||
private Integer behaviorType;
|
||||
|
||||
/** 阅览时长(单位:秒) */
|
||||
@ApiModelProperty("阅览时长(单位:秒)")
|
||||
private Integer viewDuration;
|
||||
|
||||
/** 阅览次数,多次打开累加 */
|
||||
@ApiModelProperty("阅览次数,多次打开累加")
|
||||
private Integer viewNum;
|
||||
|
||||
/** 状态:1正常 */
|
||||
@ApiModelProperty("状态:1正常")
|
||||
private Integer behaviorStatus;
|
||||
|
||||
/**开始时间*/
|
||||
@TableField(exist = false)
|
||||
private String beginTime;
|
||||
|
||||
/**截至时间*/
|
||||
@TableField(exist = false)
|
||||
private String endTime;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.ruoyi.cms.mapper.msg;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.ruoyi.cms.domain.msg.HrUserBehaviorRecord;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface HrUserBehaviorRecordMapper extends BaseMapper<HrUserBehaviorRecord> {
|
||||
|
||||
List<HrUserBehaviorRecord> selectBehaviorRecordList(HrUserBehaviorRecord hrUserBehaviorRecord);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.ruoyi.cms.service.msg;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.ruoyi.cms.domain.msg.HrUserBehaviorRecord;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface HrUserBehaviorRecordService extends IService<HrUserBehaviorRecord> {
|
||||
|
||||
/**
|
||||
* 查询行为记录列表
|
||||
*/
|
||||
List<HrUserBehaviorRecord> selectBehaviorRecordList(HrUserBehaviorRecord queryVo);
|
||||
|
||||
/**
|
||||
* 新增行为记录
|
||||
*/
|
||||
int insertBehaviorRecord(HrUserBehaviorRecord record);
|
||||
|
||||
/**
|
||||
* 修改行为记录
|
||||
*/
|
||||
int updateBehaviorRecord(HrUserBehaviorRecord record);
|
||||
|
||||
/**
|
||||
* 批量删除
|
||||
*/
|
||||
int deleteBehaviorRecordByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 根据ID查询
|
||||
*/
|
||||
HrUserBehaviorRecord selectBehaviorRecordById(Long id);
|
||||
|
||||
/**
|
||||
* 【业务埋点】查找同一主体同一目标当天浏览记录(用于累加次数、时长)
|
||||
*/
|
||||
HrUserBehaviorRecord getExistViewRecord(Integer actorType, Long actorId, Integer targetType, Long targetId);
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package com.ruoyi.cms.service.msg.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.ruoyi.cms.domain.msg.HrUserBehaviorRecord;
|
||||
import com.ruoyi.cms.mapper.msg.HrUserBehaviorRecordMapper;
|
||||
import com.ruoyi.cms.service.msg.HrUserBehaviorRecordService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class HrUserBehaviorRecordServiceImpl extends ServiceImpl<HrUserBehaviorRecordMapper, HrUserBehaviorRecord>
|
||||
implements HrUserBehaviorRecordService {
|
||||
|
||||
@Autowired
|
||||
private HrUserBehaviorRecordMapper hrUserBehaviorRecordMapper;
|
||||
|
||||
@Override
|
||||
public List<HrUserBehaviorRecord> selectBehaviorRecordList(HrUserBehaviorRecord hrUserBehaviorRecord) {
|
||||
return hrUserBehaviorRecordMapper.selectBehaviorRecordList(hrUserBehaviorRecord);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int insertBehaviorRecord(HrUserBehaviorRecord record) {
|
||||
return hrUserBehaviorRecordMapper.insert(record);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateBehaviorRecord(HrUserBehaviorRecord record) {
|
||||
return hrUserBehaviorRecordMapper.updateById(record);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int deleteBehaviorRecordByIds(Long[] ids) {
|
||||
return hrUserBehaviorRecordMapper.deleteBatchIds(Arrays.asList(ids));
|
||||
}
|
||||
|
||||
@Override
|
||||
public HrUserBehaviorRecord selectBehaviorRecordById(Long id) {
|
||||
return hrUserBehaviorRecordMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HrUserBehaviorRecord getExistViewRecord(Integer actorType, Long actorId, Integer targetType, Long targetId) {
|
||||
LambdaQueryWrapper<HrUserBehaviorRecord> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(HrUserBehaviorRecord::getActorType, actorType);
|
||||
wrapper.eq(HrUserBehaviorRecord::getActorId, actorId);
|
||||
wrapper.eq(HrUserBehaviorRecord::getTargetType, targetType);
|
||||
wrapper.eq(HrUserBehaviorRecord::getTargetId, targetId);
|
||||
LocalDate today = LocalDate.now();
|
||||
wrapper.ge(HrUserBehaviorRecord::getCreateTime, today.atStartOfDay());
|
||||
wrapper.le(HrUserBehaviorRecord::getCreateTime, today.atTime(23,59,59));
|
||||
wrapper.last("limit 1");
|
||||
return baseMapper.selectOne(wrapper);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?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.ruoyi.cms.mapper.msg.HrUserBehaviorRecordMapper">
|
||||
|
||||
<resultMap type="com.ruoyi.cms.domain.msg.HrUserBehaviorRecord" id="HrUserBehaviorRecordResult">
|
||||
<id column="id" property="id"/>
|
||||
<result column="actor_type" property="actorType"/>
|
||||
<result column="actor_id" property="actorId"/>
|
||||
<result column="target_type" property="targetType"/>
|
||||
<result column="target_id" property="targetId"/>
|
||||
<result column="behavior_type" property="behaviorType"/>
|
||||
<result column="view_duration" property="viewDuration"/>
|
||||
<result column="view_times" property="viewTimes"/>
|
||||
<result column="behavior_status" property="behaviorStatus"/>
|
||||
<result column="del_flag" property="delFlag"/>
|
||||
<result column="create_by" property="createBy"/>
|
||||
<result column="create_time" property="createTime"/>
|
||||
<result column="update_by" property="updateBy"/>
|
||||
<result column="update_time" property="updateTime"/>
|
||||
<result column="remark" property="remark"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectHrUserBehaviorRecordVo">
|
||||
SELECT id, actor_type, actor_id, target_type, target_id, behavior_type,
|
||||
view_duration, view_times, behavior_status, del_flag,
|
||||
create_by, create_time, update_by, update_time, remark
|
||||
FROM hr_user_behavior_record
|
||||
</sql>
|
||||
|
||||
<!-- 查询列表 -->
|
||||
<select id="selectBehaviorRecordList" resultMap="HrUserBehaviorRecordResult">
|
||||
<include refid="selectHrUserBehaviorRecordVo"/>
|
||||
<where> del_flag = '0'
|
||||
<if test="actorType != null">
|
||||
AND actor_type = #{actorType}
|
||||
</if>
|
||||
<if test="actorId != null">
|
||||
AND actor_id = #{actorId}
|
||||
</if>
|
||||
<if test="targetType != null">
|
||||
AND target_type = #{targetType}
|
||||
</if>
|
||||
<if test="targetId != null">
|
||||
AND target_id = #{targetId}
|
||||
</if>
|
||||
<if test="behaviorType != null">
|
||||
AND behavior_type = #{behaviorType}
|
||||
</if>
|
||||
<if test="behaviorStatus != null">
|
||||
AND behavior_status = #{behaviorStatus}
|
||||
</if>
|
||||
<if test="beginTime != null">
|
||||
AND create_time >= #{beginTime}
|
||||
</if>
|
||||
<if test="endTime != null">
|
||||
AND create_time <= #{endTime}
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user