39 changed files with 795 additions and 31 deletions
@ -0,0 +1,91 @@ |
|||
package com.epmet.mq.listener.listener; |
|||
|
|||
import com.alibaba.fastjson.JSON; |
|||
import com.epmet.commons.rocketmq.messages.PointRuleChangedMQMsg; |
|||
import com.epmet.commons.tools.distributedlock.DistributedLock; |
|||
import com.epmet.commons.tools.exception.ExceptionUtils; |
|||
import com.epmet.commons.tools.exception.RenException; |
|||
import com.epmet.commons.tools.utils.SpringContextUtils; |
|||
import com.epmet.entity.LogOperationEntity; |
|||
import com.epmet.enums.SystemMessageTypeEnum; |
|||
import com.epmet.mq.listener.bean.log.LogOperationHelper; |
|||
import com.epmet.mq.listener.bean.log.OperatorInfo; |
|||
import com.epmet.service.LogOperationService; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext; |
|||
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; |
|||
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently; |
|||
import org.apache.rocketmq.common.message.MessageExt; |
|||
import org.redisson.api.RLock; |
|||
import org.slf4j.Logger; |
|||
import org.slf4j.LoggerFactory; |
|||
|
|||
import java.util.List; |
|||
import java.util.concurrent.TimeUnit; |
|||
|
|||
/** |
|||
* @author wxz |
|||
* @Description 积分相关日志监听器 |
|||
|
|||
* @return |
|||
* @date 2021.06.21 10:13 |
|||
*/ |
|||
public class PointOperationLogListener implements MessageListenerConcurrently { |
|||
|
|||
private Logger logger = LoggerFactory.getLogger(getClass()); |
|||
|
|||
@Override |
|||
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext context) { |
|||
try { |
|||
msgs.forEach(msg -> consumeMessage(msg)); |
|||
} catch (Exception e) { |
|||
logger.error(ExceptionUtils.getErrorStackTrace(e)); |
|||
return ConsumeConcurrentlyStatus.RECONSUME_LATER; |
|||
} |
|||
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS; |
|||
} |
|||
|
|||
private void consumeMessage(MessageExt messageExt) { |
|||
String opeType = messageExt.getTags(); |
|||
String msg = new String(messageExt.getBody()); |
|||
logger.info("积分操作日志监听器-收到消息内容:{}", msg); |
|||
PointRuleChangedMQMsg msgObj = JSON.parseObject(msg, PointRuleChangedMQMsg.class); |
|||
|
|||
String content = StringUtils.isBlank(msgObj.getOperationBrief()) ? "" : msgObj.getOperationBrief(); |
|||
|
|||
OperatorInfo operatorInfo = LogOperationHelper.getInstance().getOperatorInfo(msgObj.getOperatorId()); |
|||
|
|||
LogOperationEntity logEntity = new LogOperationEntity(); |
|||
logEntity.setCategory(messageExt.getTopic()); |
|||
logEntity.setType(opeType); |
|||
logEntity.setTypeDisplay(SystemMessageTypeEnum.getTypeDisplay(opeType)); |
|||
logEntity.setTargetId(msgObj.getRuleId()); |
|||
logEntity.setIp(msgObj.getIp()); |
|||
logEntity.setFromApp(msgObj.getFromApp()); |
|||
logEntity.setFromClient(msgObj.getFromClient()); |
|||
logEntity.setCustomerId(operatorInfo.getCustomerId()); |
|||
logEntity.setOperatorId(msgObj.getOperatorId()); |
|||
logEntity.setOperatorMobile(operatorInfo.getMobile()); |
|||
logEntity.setOperatorName(operatorInfo.getName()); |
|||
logEntity.setOperatingTime(msgObj.getOperatingTime()); |
|||
logEntity.setContent(content); |
|||
|
|||
DistributedLock distributedLock = null; |
|||
RLock lock = null; |
|||
try { |
|||
distributedLock = SpringContextUtils.getBean(DistributedLock.class); |
|||
lock = distributedLock.getLock(String.format("lock:point_operation_log:%s:%s", logEntity.getType(), logEntity.getTargetId()), |
|||
30L, 30L, TimeUnit.SECONDS); |
|||
SpringContextUtils.getBean(LogOperationService.class).log(logEntity); |
|||
} catch (RenException e) { |
|||
// 如果是我们手动抛出的异常,说明在业务可控范围内。目前不需要MQ重试
|
|||
logger.error("【RocketMQ】添加操作日志失败:".concat(ExceptionUtils.getErrorStackTrace(e))); |
|||
} catch (Exception e) { |
|||
// 不是我们自己抛出的异常,可以让MQ重试
|
|||
logger.error("【RocketMQ】添加操作日志失败:".concat(ExceptionUtils.getErrorStackTrace(e))); |
|||
throw e; |
|||
} finally { |
|||
distributedLock.unLock(lock); |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,33 @@ |
|||
package com.epmet.commons.rocketmq.messages; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.util.Date; |
|||
|
|||
/** |
|||
* 积分规则变动消息体 |
|||
*/ |
|||
@Data |
|||
public class PointRuleChangedMQMsg { |
|||
/** |
|||
* 操作简介 |
|||
*/ |
|||
private String operationBrief; |
|||
|
|||
/** |
|||
* 规则的id |
|||
*/ |
|||
private String ruleId; |
|||
/** |
|||
* 谁操作的 |
|||
*/ |
|||
private String operatorId; |
|||
|
|||
private String ip; |
|||
|
|||
private String fromApp; |
|||
|
|||
private String fromClient; |
|||
|
|||
private Date operatingTime; |
|||
} |
@ -0,0 +1,33 @@ |
|||
package com.epmet.enums; |
|||
|
|||
import com.epmet.constant.SystemMessageType; |
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Getter; |
|||
|
|||
@AllArgsConstructor |
|||
@Getter |
|||
public enum SystemMessageTypeEnum { |
|||
|
|||
POINT_RULE_CHANGED(SystemMessageType.POINT_RULE_CHANGED, "积分规则修改"); |
|||
|
|||
private String type; |
|||
private String typeDisplay; |
|||
|
|||
public static SystemMessageTypeEnum get(String type) { |
|||
for (SystemMessageTypeEnum e : SystemMessageTypeEnum.values()) { |
|||
if (e.type.equals(type)) { |
|||
return e; |
|||
} |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
public static String getTypeDisplay(String type) { |
|||
SystemMessageTypeEnum o = get(type); |
|||
if (o != null) { |
|||
return o.getTypeDisplay(); |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
} |
@ -0,0 +1,36 @@ |
|||
package com.epmet.dto.form; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import javax.validation.constraints.NotBlank; |
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* 积分任务列表查询入参 |
|||
* |
|||
* @author yinzuomei@elink-cn.com |
|||
* @date 2021/6/18 13:56 |
|||
*/ |
|||
@Data |
|||
public class MyPointTaskFormDTO implements Serializable { |
|||
private static final long serialVersionUID = 8274146750217261820L; |
|||
|
|||
/** |
|||
* 当前用户Id |
|||
* */ |
|||
@NotBlank(message = "tokenDto获取userId为空") |
|||
private String userId; |
|||
|
|||
@NotBlank(message = "tokenDto获取customerId为空") |
|||
private String customerId; |
|||
/** |
|||
* 未完成:unfinished;已完成:finished;全部:all |
|||
* */ |
|||
@NotBlank(message = "未完成:unfinished;已完成:finished;全部:all") |
|||
private String type; |
|||
|
|||
/** |
|||
* yyyyMMdd,现在默认是当天,后端代码写死 |
|||
* */ |
|||
private String dateId; |
|||
} |
@ -0,0 +1,94 @@ |
|||
package com.epmet.dto.result; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnore; |
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* 积分任务列表查询返参 |
|||
* |
|||
* @author yinzuomei@elink-cn.com |
|||
* @date 2021/6/18 13:58 |
|||
*/ |
|||
@Data |
|||
public class MyPointTaskResultDTO implements Serializable { |
|||
|
|||
/** |
|||
* 规则名称 |
|||
* */ |
|||
private String ruleName; |
|||
|
|||
/** |
|||
* 规则描述 |
|||
* */ |
|||
private String ruleDesc; |
|||
|
|||
/** |
|||
* 加减积分描述,举例:积分+2 |
|||
* */ |
|||
private String pointDesc; |
|||
|
|||
/** |
|||
* 完成情况描述,举例:完成0/3 |
|||
* */ |
|||
private String finishTotalDesc; |
|||
|
|||
/** |
|||
* 去完成 or 已完成 |
|||
* */ |
|||
private String finishFlag; |
|||
|
|||
/** |
|||
* 楼院小组:group;爱心互助:heart; 前端根据这个key跳转到相应页面 |
|||
* */ |
|||
private String linkPage; |
|||
|
|||
|
|||
|
|||
/** |
|||
* 事件CODE 来自事件表 |
|||
*/ |
|||
@JsonIgnore |
|||
private String eventCode; |
|||
|
|||
/** |
|||
* 操作类型 加积分:add;减积分:subtract |
|||
*/ |
|||
@JsonIgnore |
|||
private String operateType; |
|||
|
|||
/** |
|||
* 积分上限 0表示不涉及积分上限; |
|||
*/ |
|||
@JsonIgnore |
|||
private Integer upLimit; |
|||
|
|||
/** |
|||
* 获得积分值 |
|||
*/ |
|||
@JsonIgnore |
|||
private Integer point; |
|||
/** |
|||
* 已完成次数 |
|||
*/ |
|||
@JsonIgnore |
|||
private Integer finishedCount; |
|||
|
|||
/** |
|||
* 上限次数,0代表没有上限次数 |
|||
*/ |
|||
@JsonIgnore |
|||
private Integer upLimitCount; |
|||
/** |
|||
* 排序 |
|||
*/ |
|||
@JsonIgnore |
|||
private Integer sort; |
|||
|
|||
/** |
|||
* 一次性任务?1:是;0:不是 |
|||
*/ |
|||
@JsonIgnore |
|||
private String disposable; |
|||
} |
@ -0,0 +1,29 @@ |
|||
alter table point_rule_default add COLUMN SORT INT(11) COMMENT '规则显示顺序' AFTER ENABLED_FLAG ; |
|||
alter table point_rule add COLUMN SORT INT(11) COMMENT '规则显示顺序' AFTER ENABLED_FLAG ; |
|||
alter table point_rule_default add COLUMN LINK_PAGE VARCHAR(32) COMMENT '链接页面' AFTER SORT ; |
|||
alter table point_rule add COLUMN LINK_PAGE VARCHAR(32) COMMENT '链接页面' AFTER SORT ; |
|||
alter table point_rule_default add COLUMN DISPOSABLE varchar(1) not null default '0' comment '一次性任务?1:是;0:不是' AFTER LINK_PAGE; |
|||
alter table point_rule add COLUMN DISPOSABLE varchar(1) not null default '0' comment '一次性任务?1:是;0:不是' AFTER LINK_PAGE; |
|||
|
|||
update point_rule_default set sort='1001',LINK_PAGE='group' where EVENT_CODE='participate_one_topic' and DEL_FLAG='0'; |
|||
update point_rule_default set sort='1002',LINK_PAGE='group' where EVENT_CODE='publish_one_topic' and DEL_FLAG='0'; |
|||
update point_rule_default set sort='1003',LINK_PAGE='group' where EVENT_CODE='invite_resi_into_group' and DEL_FLAG='0'; |
|||
update point_rule_default set sort='1004',LINK_PAGE='group' where EVENT_CODE='invite_new_into_group' and DEL_FLAG='0'; |
|||
update point_rule_default set sort='1005',LINK_PAGE='group' where EVENT_CODE='leader_resolve_topic' and DEL_FLAG='0'; |
|||
update point_rule_default set sort='1006',LINK_PAGE='group' where EVENT_CODE='shift_topic_to_issue' and DEL_FLAG='0'; |
|||
update point_rule_default set sort='1007',LINK_PAGE='group' where EVENT_CODE='topic_to_issue' and DEL_FLAG='0'; |
|||
update point_rule_default set sort='1008',LINK_PAGE='group' where EVENT_CODE='topic_to_project' and DEL_FLAG='0'; |
|||
update point_rule_default set sort='2001',LINK_PAGE='heart',DISPOSABLE='1' where EVENT_CODE='register_volunteer' and DEL_FLAG='0'; |
|||
update point_rule_default set sort='2002',LINK_PAGE='heart' where EVENT_CODE='active_insert_live' and DEL_FLAG='0'; |
|||
|
|||
|
|||
update point_rule set sort='1001',LINK_PAGE='group' where EVENT_CODE='participate_one_topic' and DEL_FLAG='0'; |
|||
update point_rule set sort='1002',LINK_PAGE='group' where EVENT_CODE='publish_one_topic' and DEL_FLAG='0'; |
|||
update point_rule set sort='1003',LINK_PAGE='group' where EVENT_CODE='invite_resi_into_group' and DEL_FLAG='0'; |
|||
update point_rule set sort='1004',LINK_PAGE='group' where EVENT_CODE='invite_new_into_group' and DEL_FLAG='0'; |
|||
update point_rule set sort='1005',LINK_PAGE='group' where EVENT_CODE='leader_resolve_topic' and DEL_FLAG='0'; |
|||
update point_rule set sort='1006',LINK_PAGE='group' where EVENT_CODE='shift_topic_to_issue' and DEL_FLAG='0'; |
|||
update point_rule set sort='1007',LINK_PAGE='group' where EVENT_CODE='topic_to_issue' and DEL_FLAG='0'; |
|||
update point_rule set sort='1008',LINK_PAGE='group' where EVENT_CODE='topic_to_project' and DEL_FLAG='0'; |
|||
update point_rule set sort='2001',LINK_PAGE='heart' ,DISPOSABLE='1' where EVENT_CODE='register_volunteer' and DEL_FLAG='0'; |
|||
update point_rule set sort='2002',LINK_PAGE='heart' where EVENT_CODE='active_insert_live' and DEL_FLAG='0'; |
Loading…
Reference in new issue