|
@@ -11,7 +11,6 @@ import cn.com.ctop.kuaishou.modules.batch.service.IAccountWarningService;
|
|
|
import cn.com.ctop.kuaishou.modules.report.mapper.KuaishouReportHourlyAccountMapper;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
-import org.jeecg.common.util.DateUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@@ -35,39 +34,55 @@ public class AccountWarningServiceImpl implements IAccountWarningService {
|
|
|
* @param accountId
|
|
|
*/
|
|
|
@Override
|
|
|
- public void accountWarning(Long accountId) {
|
|
|
+ public void accountWarning(Long accountId, String statDate, String anotherDay) {
|
|
|
try {
|
|
|
- String statDate = DateUtils.getDate("yyyy-MM-dd");
|
|
|
+
|
|
|
|
|
|
Integer maxHour = hourlyAccountMapper.selectMaxHour(accountId, statDate);
|
|
|
- if (Check.isNull(maxHour) || maxHour == 0) {
|
|
|
+ if (Check.isNull(maxHour)) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- BigDecimal nowCost = hourlyAccountMapper.getNowCost(accountId, maxHour, statDate);
|
|
|
- if (!Check.isNull(nowCost) && nowCost.compareTo(new BigDecimal(0)) != 0) {
|
|
|
- BigDecimal lastHourCost = hourlyAccountMapper.getNowCost(accountId, maxHour - 1, statDate);
|
|
|
-
|
|
|
- if (!Check.isNull(lastHourCost) && lastHourCost.compareTo(new BigDecimal(0)) != 0) {
|
|
|
- QueryWrapper<UserAllocation> userAllocationQueryWrapper = new QueryWrapper<>();
|
|
|
- userAllocationQueryWrapper.eq("account_id", accountId);
|
|
|
- userAllocationQueryWrapper.orderByDesc("create_time");
|
|
|
- userAllocationQueryWrapper.last("limit 1");
|
|
|
- UserAllocation userAllocation = userAllocationMapper.selectOne(userAllocationQueryWrapper);
|
|
|
- if (!Check.isNull(userAllocation)) {
|
|
|
- BigDecimal warningAmount = userAllocation.getWarningAmount();
|
|
|
- BigDecimal warningProportion = userAllocation.getWarningProportion();
|
|
|
-
|
|
|
- BigDecimal subtract = nowCost.subtract(lastHourCost);
|
|
|
- BigDecimal divide = nowCost.divide(lastHourCost, 2, RoundingMode.HALF_UP);
|
|
|
- if (subtract.compareTo(warningAmount) > -1 && divide.compareTo(warningProportion) > -1) {
|
|
|
+ QueryWrapper<UserAllocation> userAllocationQueryWrapper = new QueryWrapper<>();
|
|
|
+ userAllocationQueryWrapper.eq("account_id", accountId);
|
|
|
+ userAllocationQueryWrapper.eq("media_id", 2);
|
|
|
+ userAllocationQueryWrapper.orderByDesc("create_time");
|
|
|
+ userAllocationQueryWrapper.last("limit 1");
|
|
|
+ UserAllocation userAllocation = userAllocationMapper.selectOne(userAllocationQueryWrapper);
|
|
|
+ if (Check.isNull(userAllocation)) {
|
|
|
+ return;
|
|
|
|
|
|
+ }
|
|
|
+ BigDecimal warningAmount = userAllocation.getWarningAmount();
|
|
|
+ BigDecimal warningProportion = userAllocation.getWarningProportion();
|
|
|
+ BigDecimal nowCost = hourlyAccountMapper.getCost(accountId, maxHour, statDate);
|
|
|
+ if (maxHour != 0) {
|
|
|
+ if (!Check.isNull(nowCost) && nowCost.compareTo(new BigDecimal(0)) != 0) {
|
|
|
+ BigDecimal lastHourCost = hourlyAccountMapper.getCost(accountId, maxHour - 1, statDate);
|
|
|
+ if (!Check.isNull(lastHourCost) && lastHourCost.compareTo(new BigDecimal(0)) != 0) {
|
|
|
+ if (!Check.isNull(userAllocation)) {
|
|
|
+ BigDecimal subtract = nowCost.subtract(lastHourCost);
|
|
|
+ BigDecimal divide = nowCost.divide(lastHourCost, 2, RoundingMode.HALF_UP);
|
|
|
+ if (subtract.compareTo(warningAmount) > -1 && divide.compareTo(warningProportion) > -1) {
|
|
|
+ sendMessage(accountId, userAllocation.getAuthName(), maxHour, nowCost, userAllocation.getProjectId());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-
|
|
|
}
|
|
|
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (!Check.isNull(nowCost) && nowCost.compareTo(new BigDecimal(0)) != 0) {
|
|
|
+ BigDecimal yesterdayHourCost = hourlyAccountMapper.getCost(accountId, maxHour, anotherDay);
|
|
|
+ if (!Check.isNull(yesterdayHourCost) && yesterdayHourCost.compareTo(new BigDecimal(0)) != 0) {
|
|
|
+ BigDecimal subtract = nowCost.subtract(yesterdayHourCost);
|
|
|
+ BigDecimal divide = nowCost.divide(yesterdayHourCost, 2, RoundingMode.HALF_UP);
|
|
|
+ if (subtract.compareTo(warningAmount) > -1 && divide.compareTo(warningProportion) > -1) {
|
|
|
+ sendYesterdayMessage(accountId, userAllocation.getAuthName(), maxHour, nowCost, userAllocation.getProjectId());
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
@@ -75,32 +90,73 @@ public class AccountWarningServiceImpl implements IAccountWarningService {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
|
|
|
-
|
|
|
}
|
|
|
|
|
|
+ private void sendYesterdayMessage(Long accountId, String authName, Integer maxHour, BigDecimal nowCost, Long projectId) {
|
|
|
|
|
|
- private void sendMessage(Long accountId, Long projectId, String projectName, String authName, List<String> unitWarning, Long maxBid) {
|
|
|
-
|
|
|
- String createTime = DateUtils.getNowDate("yyyy-MM-dd");
|
|
|
- Integer count = mailLogMapper.selectCountByAccountIdAndDate(accountId, createTime);
|
|
|
StringBuilder text = new StringBuilder();
|
|
|
+ text.append("较昨日同时段消耗预警").append("<br/>").append("您的账号:").append(accountId + ",").append("<br/>")
|
|
|
+ .append("授权名称为:" + authName + "相较于昨日").append(maxHour + "时").append("<br/>")
|
|
|
+ .append("出现消耗暴涨,").append("消耗金额为:" + nowCost).append("<br/>")
|
|
|
+ .append("请您及时查看!");
|
|
|
+
|
|
|
+
|
|
|
+ QueryWrapper<MailLog> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("account_id", accountId);
|
|
|
+ queryWrapper.eq("hour", maxHour);
|
|
|
+ queryWrapper.eq("mail_type", 3);
|
|
|
+ queryWrapper.orderByDesc("create_time");
|
|
|
+ queryWrapper.last("limit 1");
|
|
|
+ MailLog checkMailLog = mailLogMapper.selectOne(queryWrapper);
|
|
|
+ if (Check.isNull(checkMailLog)) {
|
|
|
+ List<String> mailList = mailLogMapper.selectMailList(projectId);
|
|
|
+ String subject = "较昨日同时段账户消耗预警";
|
|
|
+ try {
|
|
|
+ SendMailUtil.sendMail(mailList, subject, text.toString());
|
|
|
+ MailLog mailLog = new MailLog();
|
|
|
+ mailLog.setAccountId(accountId);
|
|
|
+ mailLog.setMailType(3);
|
|
|
+ mailLog.setHour(maxHour);
|
|
|
+ mailLog.setContent(text.toString());
|
|
|
+ mailLog.setSendEmil(JSON.toJSONString(mailList));
|
|
|
+ mailLog.setSubject(subject);
|
|
|
+ mailLogMapper.insert(mailLog);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ List<String> wexinIds = mailLogMapper.selectWeiXinIdList(projectId);
|
|
|
+ CorpWexinUtils.sendMessage(wexinIds, text.toString());
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- String s = "";
|
|
|
- for (int i = 0; i < unitWarning.size(); i++) {
|
|
|
- s += unitWarning.get(i) + "," + "<br/>";
|
|
|
|
|
|
- }
|
|
|
- text.append("您的项目:").append(projectName + ",").append("<br/>")
|
|
|
- .append("授权名称为:" + authName + " 下的,").append("<br/>").append(s)
|
|
|
- .append("大于项目设置的最高出价:").append(maxBid / 1000).append(" 元! 请您及时调整。");
|
|
|
- if (count < 3) {
|
|
|
+ private void sendMessage(Long accountId, String authName, Integer hour, BigDecimal amount, Long projectId) {
|
|
|
+
|
|
|
+ StringBuilder text = new StringBuilder();
|
|
|
+ text.append("较上时段消耗预警").append("<br/>").append("您的账号:").append(accountId + ",").append("<br/>")
|
|
|
+ .append("授权名称为:" + authName + ",").append(hour + " 时").append("相较于 " + (hour - 1) + " 时").append("<br/>")
|
|
|
+ .append("出现消耗暴涨,").append("消耗金额为:" + amount).append("<br/>")
|
|
|
+ .append("请您及时查看!");
|
|
|
+
|
|
|
+
|
|
|
+ QueryWrapper<MailLog> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("account_id", accountId);
|
|
|
+ queryWrapper.eq("hour", hour);
|
|
|
+ queryWrapper.eq("mail_type", 2);
|
|
|
+ queryWrapper.orderByDesc("create_time");
|
|
|
+ queryWrapper.last("limit 1");
|
|
|
+ MailLog checkMailLog = mailLogMapper.selectOne(queryWrapper);
|
|
|
+ if (Check.isNull(checkMailLog)) {
|
|
|
List<String> mailList = mailLogMapper.selectMailList(projectId);
|
|
|
- String subject = "广告组出价预警";
|
|
|
+ String subject = "账户消耗预警";
|
|
|
try {
|
|
|
SendMailUtil.sendMail(mailList, subject, text.toString());
|
|
|
MailLog mailLog = new MailLog();
|
|
|
mailLog.setAccountId(accountId);
|
|
|
+ mailLog.setMailType(2);
|
|
|
+ mailLog.setHour(hour);
|
|
|
mailLog.setContent(text.toString());
|
|
|
mailLog.setSendEmil(JSON.toJSONString(mailList));
|
|
|
mailLog.setSubject(subject);
|
|
@@ -109,11 +165,9 @@ public class AccountWarningServiceImpl implements IAccountWarningService {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
List<String> wexinIds = mailLogMapper.selectWeiXinIdList(projectId);
|
|
|
CorpWexinUtils.sendMessage(wexinIds, text.toString());
|
|
|
|
|
|
-
|
|
|
}
|
|
|
|
|
|
|