Przeglądaj źródła

渠道佣金汇总按天入账

chunping 3 lat temu
rodzic
commit
126a84e49e

+ 58 - 0
mp-quartz/src/main/java/com/qs/mp/quartz/task/ChannelCommTask.java

@@ -0,0 +1,58 @@
+package com.qs.mp.quartz.task;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.qs.mp.channel.domain.ChannelCommission;
+import com.qs.mp.channel.service.IChannelCommissionService;
+import com.qs.mp.common.utils.DateUtils;
+import com.qs.mp.common.utils.LogUtil;
+import com.qs.mp.common.utils.StringUtils;
+import java.util.Date;
+import java.util.List;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+/**
+ * 渠道佣金按天汇总入账
+ *
+ * @author zhongcp
+ * @Date 2022/3/17
+ */
+@Component("channelCommTask")
+public class ChannelCommTask {
+
+  protected final Logger logger = LoggerFactory.getLogger(this.getClass().getSimpleName());
+
+  @Autowired
+  private IChannelCommissionService channelCommissionService;
+
+  /**
+   * 渠道佣金汇总记账任务
+   */
+  public void sumComm(String executeDay) {
+    LogUtil.info(logger, "...渠道佣金汇总入账定时任务开始...");
+    Date bizDay;
+    if (StringUtils.isNotBlank(executeDay)) {
+      bizDay = DateUtils.parseStrToDate(executeDay, DateUtils.YYYYMMDD);
+    } else {
+      bizDay = DateUtils.addDays(DateUtils.getToday(), -1);
+    }
+
+    // 捞取前一天有分佣的渠道ID
+    List<ChannelCommission> channelList = channelCommissionService.getChannelList(
+        new QueryWrapper<ChannelCommission>()
+            .gt("t2.level", 0)
+            .ge("t1.created_time", bizDay)
+            .lt("t1.created_time", DateUtils.addDays(bizDay, 1)));
+    for (ChannelCommission channelCommission : channelList) {
+      try {
+        channelCommissionService.commEntry(channelCommission.getChannelId(), bizDay);
+      } catch (Exception e) {
+        LogUtil.error(logger, e, "渠道佣金汇总入账异常。channelId:{0}", channelCommission.getChannelId());
+      }
+    }
+
+    LogUtil.info(logger, "...渠道佣金汇总入账定时任务结束...");
+  }
+}

+ 19 - 8
mp-service/src/main/java/com/qs/mp/channel/mapper/ChannelCommissionMapper.java

@@ -1,7 +1,12 @@
 package com.qs.mp.channel.mapper;
 
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
+import com.baomidou.mybatisplus.core.toolkit.Constants;
+import com.qs.mp.channel.domain.Channel;
 import com.qs.mp.channel.domain.ChannelCommission;
 
+import com.qs.mp.channel.domain.vo.ChannelVO;
+import java.util.List;
 import org.apache.ibatis.annotations.Param;
 
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
@@ -20,8 +25,8 @@ public interface ChannelCommissionMapper extends BaseMapper<ChannelCommission> {
 	 * @return
 	 */
 	public int getChannelCommAmtCnt(@Param("channelNo") String channelNo,@Param("days") int days);
-	
-	
+
+
 	/**
 	 * 查询子渠道一定时间范围内的销售金额
 	 * @param channelNo
@@ -29,8 +34,8 @@ public interface ChannelCommissionMapper extends BaseMapper<ChannelCommission> {
 	 * @return
 	 */
 	public int getChannelSaleAmtCnt(@Param("channelNo") String channelNo,@Param("days") int days);
-	
-	
+
+
 	/**
 	 * 查询子渠道全部佣金金额 -
 	 * @param channelNo
@@ -38,14 +43,20 @@ public interface ChannelCommissionMapper extends BaseMapper<ChannelCommission> {
 	 * @return
 	 */
 	public int getChannelTotalCommAmtCnt(@Param("channelNo") String channelNo);
-	
-	
+
+
 	/**
 	 * 查询子渠道全部的销售金额
 	 * @param channelNo
-	 * @param days
 	 * @return
 	 */
 	public int getChannelTotalSaleAmtCnt(@Param("channelNo") String channelNo);
-	
+
+	/**
+	 * 查询渠道ID列表
+	 * @param wrapper
+	 * @return
+	 */
+	List<ChannelCommission> getChannelList(@Param(Constants.WRAPPER) Wrapper<ChannelCommission> wrapper);
+
 }

+ 25 - 9
mp-service/src/main/java/com/qs/mp/channel/service/IChannelCommissionService.java

@@ -1,8 +1,13 @@
 package com.qs.mp.channel.service;
 
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
+import com.baomidou.mybatisplus.core.toolkit.Constants;
 import com.qs.mp.channel.domain.ChannelCommission;
 
 import com.baomidou.mybatisplus.extension.service.IService;
+import java.util.Date;
+import java.util.List;
+import org.apache.ibatis.annotations.Param;
 
 /**
  * <p>
@@ -21,8 +26,8 @@ public interface IChannelCommissionService extends IService<ChannelCommission> {
 	 * @return
 	 */
 	public int getChannelCommAmtCnt(String channelNo, int days);
-	
-	
+
+
 	/**
 	 * 查询子渠道一定时间范围内的销售金额
 	 * @param channelNo
@@ -30,23 +35,34 @@ public interface IChannelCommissionService extends IService<ChannelCommission> {
 	 * @return
 	 */
 	public int getChannelSaleAmtCnt(String channelNo, int days);
-	
-	
+
+
 	/**
 	 * 查询子渠道全部佣金金额 -
 	 * @param channelNo
-	 * @param days
 	 * @return
 	 */
 	public int getChannelTotalCommAmtCnt(String channelNo);
-	
-	
+
+
 	/**
 	 * 查询子渠道全部的销售金额
 	 * @param channelNo
-	 * @param days
 	 * @return
 	 */
 	public int getChannelTotalSaleAmtCnt(String channelNo);
-	
+
+	/**
+	 * 查询渠道列表
+	 * @param wrapper
+	 * @return
+	 */
+	List<ChannelCommission> getChannelList(Wrapper<ChannelCommission> wrapper);
+
+	/**
+	 * 渠道佣金收入汇总入账
+	 * @param channelId
+	 */
+	void commEntry(Long channelId, Date bizDay);
+
 }

+ 50 - 2
mp-service/src/main/java/com/qs/mp/channel/service/impl/ChannelCommissionServiceImpl.java

@@ -1,10 +1,24 @@
 package com.qs.mp.channel.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.qs.mp.channel.domain.Channel;
 import com.qs.mp.channel.domain.ChannelCommission;
+import com.qs.mp.channel.domain.ChannelMoneyLog;
 import com.qs.mp.channel.mapper.ChannelCommissionMapper;
 import com.qs.mp.channel.service.IChannelCommissionService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.qs.mp.channel.service.IChannelMoneyLogService;
+import com.qs.mp.channel.service.IChannelService;
+import com.qs.mp.common.enums.ChannelMoneyEnum;
+import com.qs.mp.common.utils.DateUtils;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.util.Assert;
 
 /**
  * <p>
@@ -17,6 +31,12 @@ import org.springframework.stereotype.Service;
 @Service
 public class ChannelCommissionServiceImpl extends ServiceImpl<ChannelCommissionMapper, ChannelCommission> implements IChannelCommissionService {
 
+	@Autowired
+	private IChannelService channelService;
+
+	@Autowired
+	private IChannelMoneyLogService channelMoneyLogService;
+
 	@Override
 	public int getChannelCommAmtCnt(String channelNo, int days) {
 		return getBaseMapper().getChannelCommAmtCnt(channelNo, days == 1?0:days);
@@ -36,6 +56,34 @@ public class ChannelCommissionServiceImpl extends ServiceImpl<ChannelCommissionM
 	public int getChannelTotalSaleAmtCnt(String channelNo) {
 		return getBaseMapper().getChannelTotalSaleAmtCnt(channelNo);
 	}
-	
-	
+
+	@Override
+	public List<ChannelCommission> getChannelList(Wrapper<ChannelCommission> wrapper) {
+		return getBaseMapper().getChannelList(wrapper);
+	}
+
+	@Override
+	public void commEntry(Long channelId, Date bizDay) {
+		Map<String, Object> sumCommMap = getMap(new QueryWrapper<ChannelCommission>()
+				.select("IFNULL(SUM(comm_amt),0) as commAmt")
+				.lambda().eq(ChannelCommission::getChannelId, channelId)
+				.ge(ChannelCommission::getCreatedTime, bizDay)
+				.lt(ChannelCommission::getCreatedTime, DateUtils.addDays(bizDay, 1)));
+		int sumCommAmt = sumCommMap.get("commAmt") == null ? 0 : Integer.valueOf(String.valueOf(sumCommMap.get("commAmt")));
+		Channel channel = channelService.getById(channelId);
+		int cnt = channelMoneyLogService.count(new LambdaQueryWrapper<ChannelMoneyLog>()
+				.eq(ChannelMoneyLog::getChannelId, channelId)
+				.eq(ChannelMoneyLog::getBizTime, bizDay)
+				.eq(ChannelMoneyLog::getType, ChannelMoneyEnum.COMMISSION));
+		String strBizDay = DateUtils.dateTime(bizDay);
+		Assert.isTrue(cnt == 0, "渠道" + channelId + " " + strBizDay + "的佣金收入已入账。此次入账任务忽略");
+		ChannelMoneyLog moneyLog = new ChannelMoneyLog();
+		moneyLog.setChannelId(channelId);
+		moneyLog.setType(ChannelMoneyEnum.COMMISSION);
+		moneyLog.setLogMoney(sumCommAmt);
+		moneyLog.setLogText(strBizDay);
+		moneyLog.setBizTime(bizDay);
+		moneyLog.setRefId(null);
+		channelMoneyLogService.changeMoney(moneyLog);
+	}
 }

+ 8 - 0
mp-service/src/main/resources/mapper/channel/ChannelCommissionMapper.xml

@@ -67,4 +67,12 @@
 		) t3
 	</select>
 
+		<!-- 查询有佣金收入的渠道列表 -->
+		<select id="getChannelList" resultMap="BaseResultMap">
+		select distinct t1.channel_id
+		from mp_channel_commission t1
+					 left join mp_channel t2 on t1.channel_id = t2.channel_id
+			${ew.customSqlSegment}
+	</select>
+
 </mapper>