【7.6.0】【stat】更新点击次数统计模块

pull/55/head
fengshuonan 2023-05-10 10:43:19 +08:00
parent fee8db5aec
commit a76ce9d7db
29 changed files with 1032 additions and 15 deletions

View File

@ -0,0 +1,57 @@
/*
* Copyright [2020-2030] [https://www.stylefeng.cn]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* GunsAPACHE LICENSE 2.0使
*
* 1.LICENSE
* 2.Guns
* 3.
* 4. https://gitee.com/stylefeng/guns
* 5. https://gitee.com/stylefeng/guns
* 6.
*/
package cn.stylefeng.roses.kernel.stat.api;
import cn.stylefeng.roses.kernel.stat.api.callback.ClickCountCallback;
import java.util.List;
/**
*
*
* @author fengshuonan
* @since 2023/3/28 15:07
*/
public interface ClickCountCalcApi {
/**
*
*
* @param clickCountCallbackList callback
* @author fengshuonan
* @since 2023/3/28 15:03
*/
<T extends ClickCountCallback> void calcClickCount(List<T> clickCountCallbackList);
/**
* +1
*
* @param clickCountCallback
* @author fengshuonan
* @since 2023/3/28 15:39
*/
Long addOneClickCount(ClickCountCallback clickCountCallback);
}

View File

@ -0,0 +1,57 @@
/*
* Copyright [2020-2030] [https://www.stylefeng.cn]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* GunsAPACHE LICENSE 2.0使
*
* 1.LICENSE
* 2.Guns
* 3.
* 4. https://gitee.com/stylefeng/guns
* 5. https://gitee.com/stylefeng/guns
* 6.
*/
package cn.stylefeng.roses.kernel.stat.api;
import cn.stylefeng.roses.kernel.stat.api.callback.ClickStatusCallback;
import java.util.List;
/**
*
*
* @author fengshuonan
* @since 2023/3/28 15:08
*/
public interface ClickStatusCalcApi {
/**
*
*
* @param clickStatusCallbackList callback
* @author fengshuonan
* @since 2023/3/28 15:03
*/
<T extends ClickStatusCallback> void calcClickStatus(List<T> clickStatusCallbackList);
/**
*
*
* @param clickStatusCallback
* @author fengshuonan
* @since 2023/3/28 15:39
*/
void addClickStatus(ClickStatusCallback clickStatusCallback);
}

View File

@ -22,15 +22,39 @@
* 5. https://gitee.com/stylefeng/guns
* 6.
*/
package cn.stylefeng.roses.kernel.stat.api;
package cn.stylefeng.roses.kernel.stat.api.callback;
/**
* Api
*
*
* @author fengshuonan
* @date 2023-05-10 10:10:15
* @since 2023/3/28 15:02
*/
public interface StatApi {
public interface ClickCountCallback {
/**
*
*
* @param count
* @author fengshuonan
* @since 2023/3/28 14:43
*/
void addClickCount(Long count);
/**
* id
*
* @author fengshuonan
* @since 2023/3/28 15:05
*/
Long getBusinessId();
/**
*
*
* @author fengshuonan
* @since 2023/3/28 15:05
*/
String getBusinessTypeCode();
}

View File

@ -0,0 +1,67 @@
/*
* Copyright [2020-2030] [https://www.stylefeng.cn]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* GunsAPACHE LICENSE 2.0使
*
* 1.LICENSE
* 2.Guns
* 3.
* 4. https://gitee.com/stylefeng/guns
* 5. https://gitee.com/stylefeng/guns
* 6.
*/
package cn.stylefeng.roses.kernel.stat.api.callback;
/**
*
*
* @author fengshuonan
* @since 2023/3/28 14:42
*/
public interface ClickStatusCallback {
/**
*
*
* @author fengshuonan
* @since 2023/3/28 14:43
*/
void addClickStatus();
/**
* id
*
* @author fengshuonan
* @since 2023/3/28 15:06
*/
Long getUserId();
/**
* id
*
* @author fengshuonan
* @since 2023/3/28 15:05
*/
Long getBusinessId();
/**
*
*
* @author fengshuonan
* @since 2023/3/28 15:05
*/
String getBusinessTypeCode();
}

View File

@ -28,7 +28,7 @@ package cn.stylefeng.roses.kernel.stat.api.constants;
*
*
* @author fengshuonan
* @date 2023-05-10 10:10:15
* @since 2023-05-10 10:10:15
*/
public interface StatConstants {

View File

@ -6,7 +6,7 @@ import lombok.Getter;
*
*
* @author fengshuonan
* @date 2023-05-10 10:10:15
* @since 2023-05-10 10:10:15
*/
@Getter
public enum DemoEnum {

View File

@ -33,7 +33,7 @@ import cn.stylefeng.roses.kernel.stat.api.constants.StatConstants;
*
*
* @author fengshuonan
* @date 2023-05-10 10:10:15
* @since 2023-05-10 10:10:15
*/
public class StatException extends ServiceException {

View File

@ -33,7 +33,7 @@ import lombok.Getter;
*
*
* @author fengshuonan
* @date 2023-05-10 10:10:15
* @since 2023-05-10 10:10:15
*/
@Getter
public enum StatExceptionEnum implements AbstractExceptionEnum {

View File

@ -1 +0,0 @@
package cn.stylefeng.roses.kernel.stat.modular.controller;

View File

@ -0,0 +1,58 @@
package cn.stylefeng.roses.kernel.stat.modular.entity;
import cn.stylefeng.roses.kernel.db.api.pojo.entity.BaseEntity;
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
*
*
* @author fengshuonan
* @since 2023/03/28 14:52
*/
@TableName("portal_click_count")
@Data
@EqualsAndHashCode(callSuper = true)
public class ClickCount extends BaseEntity {
/**
* id
*/
@TableId(value = "click_count_id", type = IdType.ASSIGN_ID)
@ChineseDescription("主键id")
private Long clickCountId;
/**
*
*/
@TableField("business_type")
@ChineseDescription("业务的分类标识")
private String businessType;
/**
* id
*/
@TableField("business_key_id")
@ChineseDescription("业务的主键id")
private Long businessKeyId;
/**
*
*/
@TableField("click_count")
@ChineseDescription("点击次数")
private Long clickCount;
/**
* id
*/
@TableField("tenant_id")
@ChineseDescription("租户id")
private Long tenantId;
}

View File

@ -0,0 +1,58 @@
package cn.stylefeng.roses.kernel.stat.modular.entity;
import cn.stylefeng.roses.kernel.db.api.pojo.entity.BaseEntity;
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
*
*
* @author fengshuonan
* @since 2023/03/28 14:52
*/
@TableName("portal_click_status")
@Data
@EqualsAndHashCode(callSuper = true)
public class ClickStatus extends BaseEntity {
/**
* id
*/
@TableId(value = "click_status_id", type = IdType.ASSIGN_ID)
@ChineseDescription("主键id")
private Long clickStatusId;
/**
* id
*/
@TableField("user_id")
@ChineseDescription("用户id")
private Long userId;
/**
* id
*/
@TableField("business_key_id")
@ChineseDescription("业务的主键id")
private Long businessKeyId;
/**
*
*/
@TableField("business_type")
@ChineseDescription("业务的分类标识")
private String businessType;
/**
* id
*/
@TableField("tenant_id")
@ChineseDescription("租户id")
private Long tenantId;
}

View File

@ -1 +0,0 @@
package cn.stylefeng.roses.kernel.stat.modular.entity;

View File

@ -0,0 +1,36 @@
package cn.stylefeng.roses.kernel.stat.modular.enums;
import cn.stylefeng.roses.kernel.rule.constants.RuleConstants;
import cn.stylefeng.roses.kernel.rule.exception.AbstractExceptionEnum;
import lombok.Getter;
/**
*
*
* @author fengshuonan
* @since 2023/03/28 14:52
*/
@Getter
public enum ClickCountExceptionEnum implements AbstractExceptionEnum {
/**
*
*/
PORTAL_CLICK_COUNT_NOT_EXISTED(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + "10001", "查询结果不存在");
/**
*
*/
private final String errorCode;
/**
*
*/
private final String userTip;
ClickCountExceptionEnum(String errorCode, String userTip) {
this.errorCode = errorCode;
this.userTip = userTip;
}
}

View File

@ -0,0 +1,36 @@
package cn.stylefeng.roses.kernel.stat.modular.enums;
import cn.stylefeng.roses.kernel.rule.constants.RuleConstants;
import cn.stylefeng.roses.kernel.rule.exception.AbstractExceptionEnum;
import lombok.Getter;
/**
*
*
* @author fengshuonan
* @since 2023/03/28 14:52
*/
@Getter
public enum ClickStatusExceptionEnum implements AbstractExceptionEnum {
/**
*
*/
PORTAL_CLICK_STATUS_NOT_EXISTED(RuleConstants.USER_OPERATION_ERROR_TYPE_CODE + "10001", "查询结果不存在");
/**
*
*/
private final String errorCode;
/**
*
*/
private final String userTip;
ClickStatusExceptionEnum(String errorCode, String userTip) {
this.errorCode = errorCode;
this.userTip = userTip;
}
}

View File

@ -1 +0,0 @@
package cn.stylefeng.roses.kernel.stat.modular.enums;

View File

@ -0,0 +1,15 @@
package cn.stylefeng.roses.kernel.stat.modular.mapper;
import cn.stylefeng.roses.kernel.stat.modular.entity.ClickCount;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* Mapper
*
* @author fengshuonan
* @since 2023/03/28 14:52
*/
public interface ClickCountMapper extends BaseMapper<ClickCount> {
}

View File

@ -0,0 +1,14 @@
package cn.stylefeng.roses.kernel.stat.modular.mapper;
import cn.stylefeng.roses.kernel.stat.modular.entity.ClickStatus;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* Mapper
*
* @author fengshuonan
* @since 2023/03/28 14:52
*/
public interface ClickStatusMapper extends BaseMapper<ClickStatus> {
}

View File

@ -0,0 +1,7 @@
<?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="cn.stylefeng.roses.kernel.stat.modular.mapper.ClickCountMapper">
</mapper>

View File

@ -0,0 +1,7 @@
<?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="cn.stylefeng.roses.kernel.stat.modular.mapper.ClickStatusMapper">
</mapper>

View File

@ -1 +0,0 @@
package cn.stylefeng.roses.kernel.stat.modular.mapper;

View File

@ -1 +0,0 @@
package cn.stylefeng.roses.kernel.stat.modular.pojo;

View File

@ -0,0 +1,51 @@
package cn.stylefeng.roses.kernel.stat.modular.request;
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotNull;
/**
*
*
* @author fengshuonan
* @since 2023/03/28 14:52
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class ClickCountRequest extends BaseRequest {
/**
* id
*/
@NotNull(message = "主键id不能为空", groups = {edit.class, delete.class})
@ChineseDescription("主键id")
private Long clickCountId;
/**
*
*/
@ChineseDescription("业务的分类标识")
private String businessType;
/**
* id
*/
@ChineseDescription("业务的主键id")
private Long businessKeyId;
/**
*
*/
@ChineseDescription("点击次数")
private Long clickCount;
/**
* id
*/
@ChineseDescription("租户id")
private Long tenantId;
}

View File

@ -0,0 +1,51 @@
package cn.stylefeng.roses.kernel.stat.modular.request;
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
import cn.stylefeng.roses.kernel.rule.pojo.request.BaseRequest;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.validation.constraints.NotNull;
/**
*
*
* @author fengshuonan
* @since 2023/03/28 14:52
*/
@EqualsAndHashCode(callSuper = true)
@Data
public class ClickStatusRequest extends BaseRequest {
/**
* id
*/
@NotNull(message = "主键id不能为空", groups = {edit.class, delete.class})
@ChineseDescription("主键id")
private Long clickStatusId;
/**
* id
*/
@ChineseDescription("用户id")
private Long userId;
/**
* id
*/
@ChineseDescription("业务的主键id")
private Long businessKeyId;
/**
*
*/
@ChineseDescription("业务的分类标识")
private String businessType;
/**
* id
*/
@ChineseDescription("租户id")
private Long tenantId;
}

View File

@ -0,0 +1,85 @@
package cn.stylefeng.roses.kernel.stat.modular.service;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.stat.api.ClickCountCalcApi;
import cn.stylefeng.roses.kernel.stat.modular.entity.ClickCount;
import cn.stylefeng.roses.kernel.stat.modular.request.ClickCountRequest;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
/**
*
*
* @author fengshuonan
* @since 2023/03/28 14:52
*/
public interface ClickCountService extends IService<ClickCount>, ClickCountCalcApi {
/**
*
*
* @param portalClickCountRequest
* @author fengshuonan
* @since 2023/03/28 14:52
*/
void add(ClickCountRequest portalClickCountRequest);
/**
*
*
* @param portalClickCountRequest
* @author fengshuonan
* @since 2023/03/28 14:52
*/
void del(ClickCountRequest portalClickCountRequest);
/**
*
*
* @param portalClickCountRequest
* @author fengshuonan
* @since 2023/03/28 14:52
*/
void edit(ClickCountRequest portalClickCountRequest);
/**
*
*
* @param portalClickCountRequest
* @author fengshuonan
* @since 2023/03/28 14:52
*/
ClickCount detail(ClickCountRequest portalClickCountRequest);
/**
*
*
* @param portalClickCountRequest
* @return List<PortalClickCount>
* @author fengshuonan
* @since 2023/03/28 14:52
*/
List<ClickCount> findList(ClickCountRequest portalClickCountRequest);
/**
*
*
* @param portalClickCountRequest
* @return PageResult<PortalClickCount>
* @author fengshuonan
* @since 2023/03/28 14:52
*/
PageResult<ClickCount> findPage(ClickCountRequest portalClickCountRequest);
/**
*
*
* @param businessId id
* @return
* @author fengshuonan
* @since 2023/3/28 15:31
*/
Long getBusinessCount(Long businessId);
}

View File

@ -0,0 +1,86 @@
package cn.stylefeng.roses.kernel.stat.modular.service;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.stat.api.ClickStatusCalcApi;
import cn.stylefeng.roses.kernel.stat.modular.entity.ClickStatus;
import cn.stylefeng.roses.kernel.stat.modular.request.ClickStatusRequest;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
/**
*
*
* @author fengshuonan
* @since 2023/03/28 14:52
*/
public interface ClickStatusService extends IService<ClickStatus>, ClickStatusCalcApi {
/**
*
*
* @param portalClickStatusRequest
* @author fengshuonan
* @since 2023/03/28 14:52
*/
void add(ClickStatusRequest portalClickStatusRequest);
/**
*
*
* @param portalClickStatusRequest
* @author fengshuonan
* @since 2023/03/28 14:52
*/
void del(ClickStatusRequest portalClickStatusRequest);
/**
*
*
* @param portalClickStatusRequest
* @author fengshuonan
* @since 2023/03/28 14:52
*/
void edit(ClickStatusRequest portalClickStatusRequest);
/**
*
*
* @param portalClickStatusRequest
* @author fengshuonan
* @since 2023/03/28 14:52
*/
ClickStatus detail(ClickStatusRequest portalClickStatusRequest);
/**
*
*
* @param portalClickStatusRequest
* @return List<PortalClickStatus>
* @author fengshuonan
* @since 2023/03/28 14:52
*/
List<ClickStatus> findList(ClickStatusRequest portalClickStatusRequest);
/**
*
*
* @param portalClickStatusRequest
* @return PageResult<PortalClickStatus>
* @author fengshuonan
* @since 2023/03/28 14:52
*/
PageResult<ClickStatus> findPage(ClickStatusRequest portalClickStatusRequest);
/**
*
*
* @param userId id
* @param businessId id
* @return true-false-
* @author fengshuonan
* @since 2023/3/28 15:31
*/
boolean getUserBusinessClickFlag(Long userId, Long businessId);
}

View File

@ -0,0 +1,156 @@
package cn.stylefeng.roses.kernel.stat.modular.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
import cn.stylefeng.roses.kernel.stat.api.callback.ClickCountCallback;
import cn.stylefeng.roses.kernel.stat.modular.entity.ClickCount;
import cn.stylefeng.roses.kernel.stat.modular.enums.ClickCountExceptionEnum;
import cn.stylefeng.roses.kernel.stat.modular.mapper.ClickCountMapper;
import cn.stylefeng.roses.kernel.stat.modular.request.ClickCountRequest;
import cn.stylefeng.roses.kernel.stat.modular.service.ClickCountService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import java.util.List;
/**
*
*
* @author fengshuonan
* @since 2023/03/28 14:52
*/
@Service
public class ClickCountServiceImpl extends ServiceImpl<ClickCountMapper, ClickCount> implements ClickCountService {
@Override
public void add(ClickCountRequest portalClickCountRequest) {
ClickCount portalClickCount = new ClickCount();
BeanUtil.copyProperties(portalClickCountRequest, portalClickCount);
this.save(portalClickCount);
}
@Override
public void del(ClickCountRequest portalClickCountRequest) {
ClickCount portalClickCount = this.queryPortalClickCount(portalClickCountRequest);
this.removeById(portalClickCount.getClickCountId());
}
@Override
public void edit(ClickCountRequest portalClickCountRequest) {
ClickCount portalClickCount = this.queryPortalClickCount(portalClickCountRequest);
BeanUtil.copyProperties(portalClickCountRequest, portalClickCount);
this.updateById(portalClickCount);
}
@Override
public ClickCount detail(ClickCountRequest portalClickCountRequest) {
return this.queryPortalClickCount(portalClickCountRequest);
}
@Override
public PageResult<ClickCount> findPage(ClickCountRequest portalClickCountRequest) {
LambdaQueryWrapper<ClickCount> wrapper = createWrapper(portalClickCountRequest);
Page<ClickCount> sysRolePage = this.page(PageFactory.defaultPage(), wrapper);
return PageResultFactory.createPageResult(sysRolePage);
}
@Override
public Long getBusinessCount(Long businessId) {
LambdaQueryWrapper<ClickCount> portalClickCountLambdaQueryWrapper = new LambdaQueryWrapper<>();
portalClickCountLambdaQueryWrapper.eq(ClickCount::getBusinessKeyId, businessId);
portalClickCountLambdaQueryWrapper.select(ClickCount::getClickCount);
ClickCount one = this.getOne(portalClickCountLambdaQueryWrapper, false);
if (one != null) {
return one.getClickCount();
} else {
return 0L;
}
}
@Override
public List<ClickCount> findList(ClickCountRequest portalClickCountRequest) {
LambdaQueryWrapper<ClickCount> wrapper = this.createWrapper(portalClickCountRequest);
return this.list(wrapper);
}
@Override
public <T extends ClickCountCallback> void calcClickCount(List<T> clickCountCallbackList) {
if (ObjectUtil.isEmpty(clickCountCallbackList)) {
return;
}
for (T clickCountCallback : clickCountCallbackList) {
Long businessId = clickCountCallback.getBusinessId();
Long clickCount = this.getBusinessCount(businessId);
clickCountCallback.addClickCount(clickCount);
}
}
@Override
public Long addOneClickCount(ClickCountCallback clickCountCallback) {
LambdaQueryWrapper<ClickCount> portalClickCountLambdaQueryWrapper = new LambdaQueryWrapper<>();
portalClickCountLambdaQueryWrapper.eq(ClickCount::getBusinessKeyId, clickCountCallback.getBusinessId());
ClickCount portalClickCount = this.getOne(portalClickCountLambdaQueryWrapper, false);
// 记录不存在,则直接新增一条记录
if (portalClickCount == null) {
portalClickCount = new ClickCount();
portalClickCount.setBusinessType(clickCountCallback.getBusinessTypeCode());
portalClickCount.setBusinessKeyId(clickCountCallback.getBusinessId());
portalClickCount.setClickCount(1L);
this.save(portalClickCount);
} else {
// 如果记录存在则直接加1
portalClickCount.setClickCount(portalClickCount.getClickCount() + 1);
this.updateById(portalClickCount);
}
return portalClickCount.getClickCount();
}
/**
*
*
* @author fengshuonan
* @since 2023/03/28 14:52
*/
private ClickCount queryPortalClickCount(ClickCountRequest portalClickCountRequest) {
ClickCount portalClickCount = this.getById(portalClickCountRequest.getClickCountId());
if (ObjectUtil.isEmpty(portalClickCount)) {
throw new ServiceException(ClickCountExceptionEnum.PORTAL_CLICK_COUNT_NOT_EXISTED);
}
return portalClickCount;
}
/**
* wrapper
*
* @author fengshuonan
* @since 2023/03/28 14:52
*/
private LambdaQueryWrapper<ClickCount> createWrapper(ClickCountRequest portalClickCountRequest) {
LambdaQueryWrapper<ClickCount> queryWrapper = new LambdaQueryWrapper<>();
Long clickCountId = portalClickCountRequest.getClickCountId();
String businessType = portalClickCountRequest.getBusinessType();
Long businessKeyId = portalClickCountRequest.getBusinessKeyId();
Long clickCount = portalClickCountRequest.getClickCount();
Long tenantId = portalClickCountRequest.getTenantId();
queryWrapper.eq(ObjectUtil.isNotNull(clickCountId), ClickCount::getClickCountId, clickCountId);
queryWrapper.like(ObjectUtil.isNotEmpty(businessType), ClickCount::getBusinessType, businessType);
queryWrapper.eq(ObjectUtil.isNotNull(businessKeyId), ClickCount::getBusinessKeyId, businessKeyId);
queryWrapper.eq(ObjectUtil.isNotNull(clickCount), ClickCount::getClickCount, clickCount);
queryWrapper.eq(ObjectUtil.isNotNull(tenantId), ClickCount::getTenantId, tenantId);
return queryWrapper;
}
}

View File

@ -0,0 +1,158 @@
package cn.stylefeng.roses.kernel.stat.modular.service.impl;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.rule.exception.base.ServiceException;
import cn.stylefeng.roses.kernel.stat.api.callback.ClickStatusCallback;
import cn.stylefeng.roses.kernel.stat.modular.entity.ClickStatus;
import cn.stylefeng.roses.kernel.stat.modular.enums.ClickStatusExceptionEnum;
import cn.stylefeng.roses.kernel.stat.modular.mapper.ClickStatusMapper;
import cn.stylefeng.roses.kernel.stat.modular.request.ClickStatusRequest;
import cn.stylefeng.roses.kernel.stat.modular.service.ClickStatusService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import java.util.List;
/**
*
*
* @author fengshuonan
* @since 2023/03/28 14:52
*/
@Service
public class ClickStatusServiceImpl extends ServiceImpl<ClickStatusMapper, ClickStatus> implements ClickStatusService {
@Override
public void add(ClickStatusRequest portalClickStatusRequest) {
ClickStatus portalClickStatus = new ClickStatus();
BeanUtil.copyProperties(portalClickStatusRequest, portalClickStatus);
this.save(portalClickStatus);
}
@Override
public void del(ClickStatusRequest portalClickStatusRequest) {
ClickStatus portalClickStatus = this.queryPortalClickStatus(portalClickStatusRequest);
this.removeById(portalClickStatus.getClickStatusId());
}
@Override
public void edit(ClickStatusRequest portalClickStatusRequest) {
ClickStatus portalClickStatus = this.queryPortalClickStatus(portalClickStatusRequest);
BeanUtil.copyProperties(portalClickStatusRequest, portalClickStatus);
this.updateById(portalClickStatus);
}
@Override
public ClickStatus detail(ClickStatusRequest portalClickStatusRequest) {
return this.queryPortalClickStatus(portalClickStatusRequest);
}
@Override
public PageResult<ClickStatus> findPage(ClickStatusRequest portalClickStatusRequest) {
LambdaQueryWrapper<ClickStatus> wrapper = createWrapper(portalClickStatusRequest);
Page<ClickStatus> sysRolePage = this.page(PageFactory.defaultPage(), wrapper);
return PageResultFactory.createPageResult(sysRolePage);
}
@Override
public boolean getUserBusinessClickFlag(Long userId, Long businessId) {
LambdaQueryWrapper<ClickStatus> portalClickStatusLambdaQueryWrapper = new LambdaQueryWrapper<>();
portalClickStatusLambdaQueryWrapper.eq(ClickStatus::getUserId, userId);
portalClickStatusLambdaQueryWrapper.eq(ClickStatus::getBusinessKeyId, businessId);
long count = this.count(portalClickStatusLambdaQueryWrapper);
return count > 0;
}
@Override
public List<ClickStatus> findList(ClickStatusRequest portalClickStatusRequest) {
LambdaQueryWrapper<ClickStatus> wrapper = this.createWrapper(portalClickStatusRequest);
return this.list(wrapper);
}
@Override
public <T extends ClickStatusCallback> void calcClickStatus(List<T> clickStatusCallbackList) {
if (ObjectUtil.isEmpty(clickStatusCallbackList)) {
return;
}
for (T clickStatusCallback : clickStatusCallbackList) {
// 获取这条记录的用户id
Long userId = clickStatusCallback.getUserId();
// 获取这条记录的业务id
Long businessId = clickStatusCallback.getBusinessId();
// 查询这个用户有没有点击过这个记录
boolean userBusinessClickFlag = this.getUserBusinessClickFlag(userId, businessId);
if (userBusinessClickFlag) {
clickStatusCallback.addClickStatus();
}
}
}
@Override
public void addClickStatus(ClickStatusCallback clickStatusCallback) {
Long userId = clickStatusCallback.getUserId();
Long businessId = clickStatusCallback.getBusinessId();
// 获取是否已经点击过,点击过就不记录了
boolean userBusinessClickFlag = this.getUserBusinessClickFlag(userId, businessId);
if (userBusinessClickFlag) {
return;
}
// 添加点击录
ClickStatus portalClickStatus = new ClickStatus();
portalClickStatus.setUserId(userId);
portalClickStatus.setBusinessType(clickStatusCallback.getBusinessTypeCode());
portalClickStatus.setBusinessKeyId(businessId);
this.save(portalClickStatus);
}
/**
*
*
* @author fengshuonan
* @since 2023/03/28 14:52
*/
private ClickStatus queryPortalClickStatus(ClickStatusRequest portalClickStatusRequest) {
ClickStatus portalClickStatus = this.getById(portalClickStatusRequest.getClickStatusId());
if (ObjectUtil.isEmpty(portalClickStatus)) {
throw new ServiceException(ClickStatusExceptionEnum.PORTAL_CLICK_STATUS_NOT_EXISTED);
}
return portalClickStatus;
}
/**
* wrapper
*
* @author fengshuonan
* @since 2023/03/28 14:52
*/
private LambdaQueryWrapper<ClickStatus> createWrapper(ClickStatusRequest portalClickStatusRequest) {
LambdaQueryWrapper<ClickStatus> queryWrapper = new LambdaQueryWrapper<>();
Long clickStatusId = portalClickStatusRequest.getClickStatusId();
Long userId = portalClickStatusRequest.getUserId();
Long businessKeyId = portalClickStatusRequest.getBusinessKeyId();
String businessType = portalClickStatusRequest.getBusinessType();
Long tenantId = portalClickStatusRequest.getTenantId();
queryWrapper.eq(ObjectUtil.isNotNull(clickStatusId), ClickStatus::getClickStatusId, clickStatusId);
queryWrapper.eq(ObjectUtil.isNotNull(userId), ClickStatus::getUserId, userId);
queryWrapper.eq(ObjectUtil.isNotNull(businessKeyId), ClickStatus::getBusinessKeyId, businessKeyId);
queryWrapper.like(ObjectUtil.isNotEmpty(businessType), ClickStatus::getBusinessType, businessType);
queryWrapper.eq(ObjectUtil.isNotNull(tenantId), ClickStatus::getTenantId, tenantId);
return queryWrapper;
}
}

View File

@ -1 +0,0 @@
package cn.stylefeng.roses.kernel.stat.modular.service;

View File

@ -30,7 +30,7 @@ import org.springframework.context.annotation.Configuration;
*
*
* @author fengshuonan
* @date 2023-05-10 10:10:15
* @since 2023-05-10 10:10:15
*/
@Configuration
public class StatAutoConfiguration {