发送消息到钉钉 提醒卖家确认收款
This commit is contained in:
@@ -8,6 +8,7 @@ import com.rj.dto.hxr.HxrOrderSelectResponse;
|
||||
import com.rj.entity.LbDepartmentUser;
|
||||
import com.rj.entity.LbOrderRow;
|
||||
import com.rj.mapper.LbOrderRowMapper;
|
||||
import com.rj.service.DingTalkRobotService;
|
||||
import com.rj.service.HxrAdminOrderSelectService;
|
||||
import com.rj.service.ILbDepartmentUserService;
|
||||
import com.rj.service.ILbOrderRowService;
|
||||
@@ -30,6 +31,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@@ -43,6 +45,11 @@ public class LbOrderRowServiceImpl extends ServiceImpl<LbOrderRowMapper, LbOrder
|
||||
|
||||
private static final String SUM_DATA_TYPE = "sum_data";
|
||||
|
||||
private static final int DINGTALK_SELLER_CONFIRM_BATCH_SIZE = 15;
|
||||
|
||||
private static final String DINGTALK_SELLER_CONFIRM_PREFIX =
|
||||
"买家已支付,不要影响 对方寄卖, 请如下卖家确认:";
|
||||
|
||||
private static final long SUM_PLACEHOLDER_USER_ID = 10000L;
|
||||
|
||||
private static final String SUM_ORDER_SN = "order_sn_10000";
|
||||
@@ -57,6 +64,9 @@ public class LbOrderRowServiceImpl extends ServiceImpl<LbOrderRowMapper, LbOrder
|
||||
@Autowired
|
||||
private ILbDepartmentUserService lbDepartmentUserService;
|
||||
|
||||
@Autowired
|
||||
private DingTalkRobotService dingTalkRobotService;
|
||||
|
||||
@Override
|
||||
public Map<String, Object> add(LbOrderRow entity) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
@@ -375,17 +385,7 @@ public class LbOrderRowServiceImpl extends ServiceImpl<LbOrderRowMapper, LbOrder
|
||||
}
|
||||
String tid = tenantId.trim();
|
||||
|
||||
LambdaQueryWrapper<LbOrderRow> w = new LambdaQueryWrapper<>();
|
||||
w.eq(LbOrderRow::getTenantId, tid);
|
||||
w.eq(LbOrderRow::getDataType, SYNC_DATA_TYPE_DETAIL);
|
||||
if (buyTimeStart != null && !buyTimeStart.trim().isEmpty()) {
|
||||
w.ge(LbOrderRow::getBuyTime, buyTimeStart.trim());
|
||||
}
|
||||
if (buyTimeEnd != null && !buyTimeEnd.trim().isEmpty()) {
|
||||
w.le(LbOrderRow::getBuyTime, buyTimeEnd.trim());
|
||||
}
|
||||
|
||||
List<LbOrderRow> details = this.list(w);
|
||||
List<LbOrderRow> details = listDetailRowsByBuyTimeRange(buyTimeStart, buyTimeEnd, tid);
|
||||
if (details.isEmpty()) {
|
||||
result.put("success", true);
|
||||
result.put("message", "时间范围内无明细数据");
|
||||
@@ -437,6 +437,92 @@ public class LbOrderRowServiceImpl extends ServiceImpl<LbOrderRowMapper, LbOrder
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> sendSellerConfirmToDingTalk(
|
||||
String buyTimeStart, String buyTimeEnd, String tenantId) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
try {
|
||||
if (tenantId == null || tenantId.trim().isEmpty()) {
|
||||
result.put("success", false);
|
||||
result.put("message", "tenantId不能为空");
|
||||
return result;
|
||||
}
|
||||
String tid = tenantId.trim();
|
||||
|
||||
List<LbOrderRow> details = listDetailRowsByBuyTimeRange(buyTimeStart, buyTimeEnd, tid);
|
||||
if (details.isEmpty()) {
|
||||
result.put("success", true);
|
||||
result.put("message", "时间范围内无订单明细");
|
||||
result.put("recordCount", 0);
|
||||
result.put("messageCount", 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
int messageCount = 0;
|
||||
for (int i = 0; i < details.size(); i += DINGTALK_SELLER_CONFIRM_BATCH_SIZE) {
|
||||
int end = Math.min(i + DINGTALK_SELLER_CONFIRM_BATCH_SIZE, details.size());
|
||||
List<LbOrderRow> batch = details.subList(i, end);
|
||||
String sellerNames =
|
||||
batch.stream()
|
||||
.map(this::resolveSellerDisplayName)
|
||||
.collect(Collectors.joining(","));
|
||||
dingTalkRobotService.sendText(DINGTALK_SELLER_CONFIRM_PREFIX + sellerNames);
|
||||
messageCount++;
|
||||
}
|
||||
|
||||
result.put("success", true);
|
||||
result.put("message", "发送成功");
|
||||
result.put("recordCount", details.size());
|
||||
result.put("messageCount", messageCount);
|
||||
return result;
|
||||
} catch (IllegalArgumentException | IllegalStateException e) {
|
||||
log.warn(
|
||||
"发送卖家确认通知到钉钉失败, tenantId={}, buyTime={}~{}, reason={}",
|
||||
tenantId,
|
||||
buyTimeStart,
|
||||
buyTimeEnd,
|
||||
e.getMessage());
|
||||
result.put("success", false);
|
||||
result.put("message", e.getMessage());
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
log.error(
|
||||
"发送卖家确认通知到钉钉异常, tenantId={}, buyTime={}~{}",
|
||||
tenantId,
|
||||
buyTimeStart,
|
||||
buyTimeEnd,
|
||||
e);
|
||||
result.put("success", false);
|
||||
result.put("message", "发送失败:" + e.getMessage());
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private List<LbOrderRow> listDetailRowsByBuyTimeRange(
|
||||
String buyTimeStart, String buyTimeEnd, String tenantId) {
|
||||
LambdaQueryWrapper<LbOrderRow> w = new LambdaQueryWrapper<>();
|
||||
w.eq(LbOrderRow::getTenantId, tenantId);
|
||||
w.eq(LbOrderRow::getDataType, SYNC_DATA_TYPE_DETAIL);
|
||||
if (buyTimeStart != null && !buyTimeStart.trim().isEmpty()) {
|
||||
w.ge(LbOrderRow::getBuyTime, buyTimeStart.trim());
|
||||
}
|
||||
if (buyTimeEnd != null && !buyTimeEnd.trim().isEmpty()) {
|
||||
w.le(LbOrderRow::getBuyTime, buyTimeEnd.trim());
|
||||
}
|
||||
w.orderByAsc(LbOrderRow::getBuyTime).orderByAsc(LbOrderRow::getId);
|
||||
return this.list(w);
|
||||
}
|
||||
|
||||
private String resolveSellerDisplayName(LbOrderRow row) {
|
||||
if (row.getSellerName() != null && !row.getSellerName().trim().isEmpty()) {
|
||||
return row.getSellerName().trim();
|
||||
}
|
||||
if (row.getSellerId() != null) {
|
||||
return String.valueOf(row.getSellerId());
|
||||
}
|
||||
return "未知";
|
||||
}
|
||||
|
||||
private LbOrderRow buildDailySumRow(
|
||||
String tenantId, LocalDate day, List<LbOrderRow> dayRows, String nowStr) {
|
||||
BigDecimal moneySum = BigDecimal.ZERO;
|
||||
@@ -575,11 +661,10 @@ public class LbOrderRowServiceImpl extends ServiceImpl<LbOrderRowMapper, LbOrder
|
||||
for (Long sellerId : sellerIds) {
|
||||
userIdStrs.add(String.valueOf(sellerId));
|
||||
}
|
||||
log.info("sellerIds:{}",userIdStrs.toString());
|
||||
LambdaQueryWrapper<LbDepartmentUser> w = new LambdaQueryWrapper<>();
|
||||
w.eq(LbDepartmentUser::getTenantId, tenantId)
|
||||
.in(LbDepartmentUser::getUserId, userIdStrs)
|
||||
.orderByDesc(LbDepartmentUser::getUpdateTime)
|
||||
.orderByDesc(LbDepartmentUser::getCreateTime);
|
||||
.in(LbDepartmentUser::getUserId, userIdStrs);
|
||||
List<LbDepartmentUser> users = lbDepartmentUserService.list(w);
|
||||
Map<String, LbDepartmentUser> byUserId = new LinkedHashMap<>();
|
||||
for (LbDepartmentUser user : users) {
|
||||
|
||||
Reference in New Issue
Block a user