Commit bccea27d by songyinghui

feat 好办导购佣金消息通知

parent 8756caf0
......@@ -75,9 +75,9 @@ public enum NoticeMessageTypeEnum {
//
MATERIAL_NEW_NOTIFY(6001, "素材上新通知", NoticeMessageCategoryTypeEnum.MATERIAL.getType(), "material_new_notify", "/pages/route/index?pageType=", "hbapp_material_center", "materialsNotice", "clerkMaterialsNotice"),
MATERIAL_REPORT_NOTIFY_WEEK(6002, "素材周报通知", NoticeMessageCategoryTypeEnum.MATERIAL.getType(), "material_week_notify", "/pages/route/index?pageType=", "hbapp_mate_report", "materialWeek", "clerkMaterialsReport"),
POTENTIAL_CUSTOMER_NOTIFY(6003, "销售线索通知", NoticeMessageCategoryTypeEnum.POTENTIAL_CUSTOMER.getType(), "potential_customer_notify", "/pages/route/index?pageType=", "hbapp_sales_clue_center", "salesLeadNotice", "haobanNotice"),
MATERIAL_REPORT_NOTIFY_MONTH(6004, "素材月报通知", NoticeMessageCategoryTypeEnum.MATERIAL.getType(), "material_month_notify", "/pages/route/index?pageType=", "hbapp_mate_report", "materialMonth", "clerkMaterialsReport"),
POTENTIAL_CUSTOMER_NOTIFY(6003, "销售线索通知", NoticeMessageCategoryTypeEnum.POTENTIAL_CUSTOMER.getType(), "potential_customer_notify", "/pages/route/index?pageType=", "hbapp_sales_clue_center", "salesLeadNotice", "haobanNotice");
CLERK_COMMISSION_NOTIFY(6005, "客户下单通知", NoticeMessageCategoryTypeEnum.CUSTOMER.getType(), "clerk_commission_notify", "/pages/route/index?pageType=", "hbapp_withdraw_list", "clerkCommissionNotify", "haobanNotice");
/**
......
package com.gic.haoban.manage.api.service.content.task;
import com.gic.api.base.commons.ServiceResponse;
/**
* @Author MUSI
* @Date 2023/6/7 2:15 PM
* @Description
* @Version
* 佣金统计接口
**/
public interface CommissionTaskApiService {
/**
* 处理佣金消息通知
* @param prams
*/
ServiceResponse<Void> handlerCommissionNotify(String prams);
}
package com.gic.haoban.manage.service.pojo.bo.commission;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
/**
* @Author MUSI
* @Date 2023/6/7 2:26 PM
* @Description
* @Version
**/
@Data
public class ClerkCommissionStaticsBO implements Serializable {
/**
* 企业id
*/
private String enterpriseId;
/**
* 导购id
*/
private String clerkId;
/**
* 数量
*/
private Integer num;
/**
* 佣金金额
*/
private BigDecimal commissionAmount;
}
package com.gic.haoban.manage.service.service.commission;
import com.alibaba.fastjson.JSONObject;
import com.gic.haoban.manage.api.dto.StaffClerkRelationDTO;
import com.gic.haoban.manage.api.enums.NoticeMessageTypeEnum;
import com.gic.haoban.manage.api.util.notify.NoticeMessageUtil;
import com.gic.haoban.manage.service.pojo.bo.commission.ClerkCommissionStaticsBO;
import com.gic.haoban.manage.service.service.StaffClerkRelationService;
import com.gic.haoban.manage.service.service.message.NoticeMessageHandler;
import com.gic.message.center.api.subscribe.model.NoticeMessageForm;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
/**
* @Author MUSI
* @Date 2023/6/7 2:31 PM
* @Description
* @Version
* 佣金服务内部服务
**/
@Slf4j
@Component
public class CommissionNotifyInnerService {
@Autowired
private StaffClerkRelationService staffClerkRelationService;
@Autowired
private NoticeMessageHandler noticeMessageHandler;
/**
* 处理导购佣金
* @param commissionStaticsBo
*/
public void handlerCommissionNotify(ClerkCommissionStaticsBO commissionStaticsBo) {
// 处理导购佣金通知
// 查询导购关联关系
String clerkId = commissionStaticsBo.getClerkId();
StaffClerkRelationDTO staffClerkRelationDTO = staffClerkRelationService.getByClerkId(clerkId);
if (staffClerkRelationDTO == null) {
log.info("handlerCommissionNotify 处理导购佣金消息,导购不存在 {}", clerkId);
return;
}
String staffId = staffClerkRelationDTO.getStaffId();
String uniqueKey = UUID.randomUUID().toString().replaceAll("-", "");
Map<String, String> params = new HashMap<>();
params.put("currentTab", "0");
params.put("commissAmount", commissionStaticsBo.getCommissionAmount().toPlainString());
params.put("memberNum", commissionStaticsBo.getNum() + "");
JSONObject innerParams = new JSONObject();
innerParams.put("currentTab", "0");
String pageUrl = NoticeMessageUtil.buildMiniAppUrl(NoticeMessageTypeEnum.CLERK_COMMISSION_NOTIFY, innerParams.toJSONString());
params.put("page", pageUrl);
params.put("pageParams", innerParams.toJSONString());
NoticeMessageForm noticeMessageForm = NoticeMessageForm
.builder()
.businessId(clerkId)
.messageCode(NoticeMessageTypeEnum.CLERK_COMMISSION_NOTIFY.getMessageCode())
.mqRouterCode(NoticeMessageTypeEnum.CLERK_COMMISSION_NOTIFY.getRouterCode())
.enterpriseId(commissionStaticsBo.getEnterpriseId())
.uniqueKey(uniqueKey)
.createTime(new Date())
.userIdList(Collections.singletonList(clerkId))
.variableMap(params)
.build();
noticeMessageForm.setStaffIdList(Collections.singletonList(staffId));
noticeMessageHandler.sendMessage(noticeMessageForm);
}
}
package com.gic.haoban.manage.service.service.out.impl.content.task;
import cn.hutool.core.date.DateTime;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.haoban.manage.api.service.content.task.CommissionTaskApiService;
import com.gic.haoban.manage.service.pojo.bo.commission.ClerkCommissionStaticsBO;
import com.gic.haoban.manage.service.service.commission.CommissionNotifyInnerService;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
/**
* @Author MUSI
* @Date 2023/6/7 2:16 PM
* @Description
* @Version
**/
@Component("commissionTaskApiService")
public class CommissionTaskApiServiceImpl implements CommissionTaskApiService {
@Autowired
private CommissionNotifyInnerService commissionNotifyInnerService;
private static final Logger log = LoggerFactory.getLogger(CommissionTaskApiService.class);
/**
* 判断是否是当天第一次
* 执行时间处于 8:00 ~ 8:30
*
* @param now
* @return
*/
int hour_sec = 30 * 60;
private boolean checkIsTodayFirst(Date now) {
DateTime temp = cn.hutool.core.date.DateUtil.offsetSecond(now, -(hour_sec));
return cn.hutool.core.date.DateUtil.hour(temp, true) < 8;
}
/**
* 处理佣金消息通知
*
* @param prams
*/
@Override
public ServiceResponse<Void> handlerCommissionNotify(String prams) {
Date now = new Date();
log.info("handlerCommissionNotify 执行佣金统计通知 {}", cn.hutool.core.date.DateUtil.format(now, "yyyy-MM-dd HH:mm:ss"));
int currentHour = cn.hutool.core.date.DateUtil.hour(now, true);
if (currentHour >= 23 || currentHour < 8) {
log.info("当前时间处于消息禁发时间, 忽略{}", cn.hutool.core.date.DateUtil.format(now, "yyyy-MM-dd HH:mm:ss"));
return ServiceResponse.success();
}
Date startTime = cn.hutool.core.date.DateUtil.offsetMinute(now, -30).toJdkDate();
// 如果是8点那次的执行 需要获取 23 ~ 8点的数据
if (checkIsTodayFirst(now)) {
log.info("本次执行为当天第一次执行 {}", cn.hutool.core.date.DateUtil.format(now, "yyyy-MM-dd HH:mm:ss"));
Date yesterday = cn.hutool.core.date.DateUtil.yesterday().toJdkDate();
Calendar calendar = Calendar.getInstance();
calendar.clear();
calendar.setTime(yesterday);
calendar.set(Calendar.HOUR_OF_DAY, 23);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
startTime = calendar.getTime();
}
// enterpriseId, clerkId, memberNum, commissionAmount
List<ClerkCommissionStaticsBO> needHandlerClerkInfos = new ArrayList<>();
needHandlerClerkInfos.add(buildDemo());
if (CollectionUtils.isEmpty(needHandlerClerkInfos)) {
return ServiceResponse.success();
}
for (ClerkCommissionStaticsBO clerkCommissionStaticsBO : needHandlerClerkInfos) {
commissionNotifyInnerService.handlerCommissionNotify(clerkCommissionStaticsBO);
}
return ServiceResponse.success();
}
private ClerkCommissionStaticsBO buildDemo() {
ClerkCommissionStaticsBO clerkCommissionStatics = new ClerkCommissionStaticsBO();
clerkCommissionStatics.setEnterpriseId("ff8080815dacd3a2015dacd3ef5c0000");
clerkCommissionStatics.setClerkId("279871592fcd49659ad5f348039dba3f");
clerkCommissionStatics.setNum(10);
clerkCommissionStatics.setCommissionAmount(BigDecimal.valueOf(10000));
return clerkCommissionStatics;
}
}
......@@ -225,4 +225,7 @@
<dubbo:reference interface="com.gic.order.api.service.sharding.OrderApiService" id="orderApiService" timeout="10000" retries="0" check="false"/>
<dubbo:reference interface="com.gic.member.api.service.MemberOutApiService" id="memberOutApiService" timeout="10000" retries="0" check="false"/>
<dubbo:service interface="com.gic.haoban.manage.api.service.content.task.CommissionTaskApiService"
ref="commissionTaskApiService" timeout="10000" />
</beans>
\ No newline at end of file
import com.alibaba.fastjson.JSON;
import com.gic.api.base.commons.ServiceResponse;
import com.gic.haoban.manage.api.service.content.task.CommissionTaskApiService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @Author MUSI
* @Date 2023/6/7 4:34 PM
* @Description
* @Version
**/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:applicationContext-conf.xml"})
public class CommissionClerkTest {
@Autowired
private CommissionTaskApiService commissionTaskApiService;
@Test
public void clerkCommission() {
ServiceResponse<Void> serviceResponse = commissionTaskApiService.handlerCommissionNotify("");
System.out.println(JSON.toJSONString(serviceResponse));
}
}
......@@ -66,7 +66,7 @@ public class HmLinkTest {
HmBatchModifyQDTO qdto = new HmBatchModifyQDTO();
qdto.setHmIdList(Arrays.asList(517064205447217236L,457922550308036636L));
qdto.setWxEnterpriseId("ca66a01b79474c40b3e7c7f93daf1a3b");
qdto.setOptStaffId("fefd1c81641711e69d0818c58a146fd2");
//qdto.setOptStaffId("fefd1c81641711e69d0818c58a146fd2");
qdto.setOptName("达摩管理员");
qdto.setOptType(1);
qdto.setClerkIdList(Arrays.asList("4a566818111a45bbae9f962580df82c0"));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment