定时任务

This commit is contained in:
Administrator 2020-09-21 22:19:19 +08:00
parent 37a1554e7a
commit 4ecf121014
8 changed files with 189 additions and 2 deletions

View File

@ -6,7 +6,7 @@ spring:
druid:
# 主库数据源
master:
url: jdbc:mysql://www.ks1.top:20336/Bizz?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
url: jdbc:mysql://www.ks1.top:20336/Bizz?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&allowMultiQueries=true
username: root
password: 123456
#url: jdbc:mysql://101.200.139.69:3306/majiang?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8

View File

@ -5,6 +5,7 @@ import com.ruoyi.business.domain.BizMember;
import com.ruoyi.business.service.IBizAccountService;
import com.ruoyi.business.service.IBizMemberService;
import com.ruoyi.business.service.IBizProductService;
import com.ruoyi.business.task.BusinessTask;
import com.ruoyi.business.utils.Encrypt;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;

View File

@ -76,4 +76,13 @@ public interface BizAccountMapper
* @return 结果
*/
public int insertBizAccountDetail(BizAccountDetail bizAccountDetail);
/**
* 清空福豆田
*
* @param
* @return
*/
public void clearAllDouField();
}

View File

@ -76,4 +76,12 @@ public interface IBizAccountService
* @return boolean
*/
public boolean accountChange(Long memberID, int accountType, int detailType, Long money, String businessInfo, String desc);
/**
* 清空福豆田
*
* @param
* @return
*/
public void clearAllDouField();
}

View File

@ -12,6 +12,7 @@ import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.common.core.text.Convert;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
@ -158,4 +159,18 @@ public class BizAccountServiceImpl implements IBizAccountService
bizAccountMapper.insertBizAccountDetail(detail);
return true;
}
/**
* 清空福豆田
*
* @param
* @return
*/
@Override
@Transactional
public void clearAllDouField()
{
bizAccountMapper.clearAllDouField();
}
}

View File

@ -0,0 +1,146 @@
package com.ruoyi.business.task;
import com.ruoyi.business.domain.BizAccountDetail;
import com.ruoyi.business.mapper.BizAccountMapper;
import com.ruoyi.business.service.IBizAccountService;
import com.ruoyi.business.service.IBizMemberService;
import com.ruoyi.framework.util.LogUtils;
import com.ruoyi.system.domain.SysDictData;
import com.ruoyi.system.utils.DictUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Calendar;
import java.util.List;
/**
* 定时任务调度
*
* @author ruoyi
*/
@Component("businessTask")
public class BusinessTask {
@Autowired
private IBizMemberService bizMemberService;
@Autowired
private IBizAccountService bizAccountService;
/**
执行每日定时任务
*/
public void doTask()
{
//每日清空福豆田
doClearField();
//判断节假日
if (isInHoliday()) {
LogUtils.getAccessLog().info("======今日休息,不执行福豆相关任务======");
return;
}
LogUtils.getAccessLog().info("======今日非休息日,开始执行福豆相关任务======");
//专项划拨任务
doSpecialTask();
//团队福豆分成任务
doTeamTask();
LogUtils.getAccessLog().info("======今日所有任务执行完成======");
}
//福豆田清零任务
private void doClearField()
{
try {
bizAccountService.clearAllDouField();
LogUtils.getAccessLog().info("======执行福豆田清零任务完成======");
} catch (Exception ex) {
ex.printStackTrace();
LogUtils.getAccessLog().error("======执行福豆田清零任务出错======" + ex.getMessage());
}
}
//专项划拨任务
private void doSpecialTask()
{
try {
int dailyAmount = Integer.parseInt(DictUtils.getDictLabel("busi_award_set", "2"));
LogUtils.getAccessLog().info("======执行专项划拨任务完成======");
} catch (Exception ex) {
ex.printStackTrace();
LogUtils.getAccessLog().error("======执行专项划拨任务出错======" + ex.getMessage());
}
}
//团队福豆分成任务
private void doTeamTask()
{
try {
int numLimit = Integer.parseInt(DictUtils.getDictLabel("busi_award_set", "1"));
LogUtils.getAccessLog().info("======执行团队福豆分成任务完成======");
} catch (Exception ex) {
ex.printStackTrace();
LogUtils.getAccessLog().error("======执行团队福豆分成任务出错======" + ex.getMessage());
}
}
//是否节假日(不结算)
public static boolean isInHoliday(int ... monthDayWeek)
{
Calendar now = Calendar.getInstance();
int month, day, weekday;
if (monthDayWeek.length > 0) {
month = monthDayWeek[0];
} else {
month = now.get(Calendar.MONTH) + 1;
}
if (monthDayWeek.length > 1) {
day = monthDayWeek[1];
} else {
day = now.get(Calendar.DAY_OF_MONTH);
}
if (monthDayWeek.length > 2) {
weekday = monthDayWeek[2];
} else {
weekday = now.get(Calendar.DAY_OF_WEEK);
}
//字典配置
List<SysDictData> holidays = DictUtils.getDictCache("busi_holidays");
List<SysDictData> workdays = DictUtils.getDictCache("busi_workdays");
//节假日
if (holidays != null && isInDictDays(holidays, month, day)) return true;
//工作日
if (workdays != null && isInDictDays(workdays, month, day)) return false;
//普通的周六周日
return weekday == Calendar.SUNDAY || weekday == Calendar.SATURDAY;
}
//是否在设定范围内
public static boolean isInDictDays(List<SysDictData> days, int month, int day) {
for (SysDictData data : days) {
String label = data.getDictLabel();
String[] split = label.split("-");
String begin = split[0];
String end = split.length > 1 ? split[1] : begin;
String[] beginStr = begin.split("[.]");
int beginMonth = Integer.parseInt(beginStr[0]);
int beginDay = Integer.parseInt(beginStr[1]);
String[] endStr = end.split("[.]");
int endMonth = Integer.parseInt(endStr[0]);
int endDay = Integer.parseInt(endStr[1]);
if (month >= beginMonth && month <= endMonth && day >= beginDay && day <= endDay) {
return true;
}
}
return false;
}
}

View File

@ -143,4 +143,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="updateTime != null">#{updateTime},</if>
</trim>
</insert>
<update id="clearAllDouField">
insert into biz_account_detail(member_id,account_id,account_type,change_type,type_detail,amount,before_amount,after_amount,create_time)
select member_id,id,account_type,-1,4,-amount,amount,0,now()
from biz_account
where account_type = 4 and amount > 0;
update biz_account set amount = 0 where account_type = 4 and amount > 0;
</update>
</mapper>

View File

@ -137,7 +137,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
left join biz_order b on a.id = b.member_id and b.order_status > 0 and b.is_team = 1
left join biz_order_detail c on c.order_id = b.id
<if test="productId != null">and c.product_id = #{productId}</if>
where recommend_all_id like concat('%,', #{memberID}, ',%')
where concat(',', recommend_all_id, ',') like concat('%,', #{memberID}, ',%')
group by a.id,a.member_name,a.recommend_id
</select>