发送消息到钉钉 提醒卖家确认收款
This commit is contained in:
@@ -128,4 +128,25 @@ public class LbOrderRowController {
|
|||||||
}
|
}
|
||||||
return ResponseEntity.badRequest().body(result);
|
return ResponseEntity.badRequest().body(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/send-seller-confirm-to-dingtalk")
|
||||||
|
@Operation(
|
||||||
|
summary = "发送卖家确认通知到钉钉",
|
||||||
|
description =
|
||||||
|
"按购买时间区间、租户 id 查询 lb_order_row 明细,将卖家姓名以「买家已支付,不要影响 对方寄卖,"
|
||||||
|
+ "请如下卖家确认:」为前缀发送至钉钉,每批最多 15 条记录")
|
||||||
|
public ResponseEntity<Map<String, Object>> sendSellerConfirmToDingTalk(
|
||||||
|
@Parameter(description = "查询与发送条件", required = true) @RequestBody
|
||||||
|
LbOrderRowGenerateSumRequest request) {
|
||||||
|
Map<String, Object> result =
|
||||||
|
lbOrderRowService.sendSellerConfirmToDingTalk(
|
||||||
|
request.getBuyTimeStart(),
|
||||||
|
request.getBuyTimeEnd(),
|
||||||
|
request.getTenantId());
|
||||||
|
Boolean success = (Boolean) result.get("success");
|
||||||
|
if (success != null && success) {
|
||||||
|
return ResponseEntity.ok(result);
|
||||||
|
}
|
||||||
|
return ResponseEntity.badRequest().body(result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,4 +49,9 @@ public interface ILbOrderRowService extends IService<LbOrderRow> {
|
|||||||
* 按购买时间区间与租户查询明细,按天汇总为 {@code sum_data} 写入 {@code lb_order_row}。
|
* 按购买时间区间与租户查询明细,按天汇总为 {@code sum_data} 写入 {@code lb_order_row}。
|
||||||
*/
|
*/
|
||||||
Map<String, Object> generateDailySumData(String buyTimeStart, String buyTimeEnd, String tenantId);
|
Map<String, Object> generateDailySumData(String buyTimeStart, String buyTimeEnd, String tenantId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 按购买时间区间与租户查询 {@code lb_order_row} 明细,将卖家姓名分批发送至钉钉(每批最多 15 条记录)。
|
||||||
|
*/
|
||||||
|
Map<String, Object> sendSellerConfirmToDingTalk(String buyTimeStart, String buyTimeEnd, String tenantId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import com.rj.dto.hxr.HxrOrderSelectResponse;
|
|||||||
import com.rj.entity.LbDepartmentUser;
|
import com.rj.entity.LbDepartmentUser;
|
||||||
import com.rj.entity.LbOrderRow;
|
import com.rj.entity.LbOrderRow;
|
||||||
import com.rj.mapper.LbOrderRowMapper;
|
import com.rj.mapper.LbOrderRowMapper;
|
||||||
|
import com.rj.service.DingTalkRobotService;
|
||||||
import com.rj.service.HxrAdminOrderSelectService;
|
import com.rj.service.HxrAdminOrderSelectService;
|
||||||
import com.rj.service.ILbDepartmentUserService;
|
import com.rj.service.ILbDepartmentUserService;
|
||||||
import com.rj.service.ILbOrderRowService;
|
import com.rj.service.ILbOrderRowService;
|
||||||
@@ -30,6 +31,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
@@ -43,6 +45,11 @@ public class LbOrderRowServiceImpl extends ServiceImpl<LbOrderRowMapper, LbOrder
|
|||||||
|
|
||||||
private static final String SUM_DATA_TYPE = "sum_data";
|
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 long SUM_PLACEHOLDER_USER_ID = 10000L;
|
||||||
|
|
||||||
private static final String SUM_ORDER_SN = "order_sn_10000";
|
private static final String SUM_ORDER_SN = "order_sn_10000";
|
||||||
@@ -57,6 +64,9 @@ public class LbOrderRowServiceImpl extends ServiceImpl<LbOrderRowMapper, LbOrder
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ILbDepartmentUserService lbDepartmentUserService;
|
private ILbDepartmentUserService lbDepartmentUserService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private DingTalkRobotService dingTalkRobotService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> add(LbOrderRow entity) {
|
public Map<String, Object> add(LbOrderRow entity) {
|
||||||
Map<String, Object> result = new HashMap<>();
|
Map<String, Object> result = new HashMap<>();
|
||||||
@@ -375,17 +385,7 @@ public class LbOrderRowServiceImpl extends ServiceImpl<LbOrderRowMapper, LbOrder
|
|||||||
}
|
}
|
||||||
String tid = tenantId.trim();
|
String tid = tenantId.trim();
|
||||||
|
|
||||||
LambdaQueryWrapper<LbOrderRow> w = new LambdaQueryWrapper<>();
|
List<LbOrderRow> details = listDetailRowsByBuyTimeRange(buyTimeStart, buyTimeEnd, tid);
|
||||||
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);
|
|
||||||
if (details.isEmpty()) {
|
if (details.isEmpty()) {
|
||||||
result.put("success", true);
|
result.put("success", true);
|
||||||
result.put("message", "时间范围内无明细数据");
|
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(
|
private LbOrderRow buildDailySumRow(
|
||||||
String tenantId, LocalDate day, List<LbOrderRow> dayRows, String nowStr) {
|
String tenantId, LocalDate day, List<LbOrderRow> dayRows, String nowStr) {
|
||||||
BigDecimal moneySum = BigDecimal.ZERO;
|
BigDecimal moneySum = BigDecimal.ZERO;
|
||||||
@@ -575,11 +661,10 @@ public class LbOrderRowServiceImpl extends ServiceImpl<LbOrderRowMapper, LbOrder
|
|||||||
for (Long sellerId : sellerIds) {
|
for (Long sellerId : sellerIds) {
|
||||||
userIdStrs.add(String.valueOf(sellerId));
|
userIdStrs.add(String.valueOf(sellerId));
|
||||||
}
|
}
|
||||||
|
log.info("sellerIds:{}",userIdStrs.toString());
|
||||||
LambdaQueryWrapper<LbDepartmentUser> w = new LambdaQueryWrapper<>();
|
LambdaQueryWrapper<LbDepartmentUser> w = new LambdaQueryWrapper<>();
|
||||||
w.eq(LbDepartmentUser::getTenantId, tenantId)
|
w.eq(LbDepartmentUser::getTenantId, tenantId)
|
||||||
.in(LbDepartmentUser::getUserId, userIdStrs)
|
.in(LbDepartmentUser::getUserId, userIdStrs);
|
||||||
.orderByDesc(LbDepartmentUser::getUpdateTime)
|
|
||||||
.orderByDesc(LbDepartmentUser::getCreateTime);
|
|
||||||
List<LbDepartmentUser> users = lbDepartmentUserService.list(w);
|
List<LbDepartmentUser> users = lbDepartmentUserService.list(w);
|
||||||
Map<String, LbDepartmentUser> byUserId = new LinkedHashMap<>();
|
Map<String, LbDepartmentUser> byUserId = new LinkedHashMap<>();
|
||||||
for (LbDepartmentUser user : users) {
|
for (LbDepartmentUser user : users) {
|
||||||
|
|||||||
Reference in New Issue
Block a user