Merge remote-tracking branch 'origin/test' into test

This commit is contained in:
2025-12-03 10:34:08 +08:00
2 changed files with 58 additions and 20 deletions

View File

@@ -5,6 +5,7 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.alibaba.nacos.shaded.com.google.common.util.concurrent.RateLimiter;
import com.czg.account.entity.ShopConfig;
import com.czg.account.service.ShopConfigService;
import com.czg.market.service.AttendanceService;
@@ -52,36 +53,61 @@ public class AttendanceServiceImpl implements AttendanceService {
}
// 自定义规则1-5 → 数字, 6 → 六, 7 → 日
private static String formatWeek(String week) {
return switch (week) {
case "星期一" -> "1";
case "星期二" -> "2";
case "星期三" -> "3";
case "星期四" -> "4";
case "星期五" -> "5";
private static String formatWeek(DateTime dateTime) {
String chinese = DateUtil.dayOfWeekEnum(dateTime).toChinese();
String week = switch (chinese) {
case "星期六" -> "";
case "星期日" -> "";
default -> week;
default -> null;
};
if (week == null) {
week = String.valueOf(DateUtil.dayOfMonth(dateTime));
}
return week;
}
@Override
public Map<String, Object> detail(Long shopId, String userId, String startTime, String endTime, Integer weekNum) {
ArrayList<DingAttendanceStatsVO> listed = list(shopId, null, startTime, endTime, userId);
ArrayList<DingAttendanceStatsVO> listed = list(shopId, null, startTime, endTime, userId);
ArrayList<Map<String, Object>> weekList = new ArrayList<>();
DateTime dateTime = StrUtil.isBlank(endTime) ? DateUtil.date() : DateUtil.parse(endTime);
for (int i = 7 * weekNum; i < 15 + 7 * weekNum; i++) {
DateTime date = DateUtil.offsetDay(dateTime, (15 - i + 1) * -1);
String week = formatWeek(DateUtil.dayOfWeekEnum(date).toChinese());
weekList.add(new HashMap<>(){{
put("week", week);
put("date", date);
}});
// 结束时间:默认今天
DateTime endDate = StrUtil.isBlank(endTime)
? DateUtil.date()
: DateUtil.parse(endTime);
// 开始时间默认当月1号
DateTime startDate = StrUtil.isBlank(startTime)
? DateUtil.beginOfMonth(endDate)
: DateUtil.parse(startTime);
// 若开始时间 > 结束时间,交换,避免死循环
if (startDate.after(endDate)) {
DateTime temp = startDate;
startDate = endDate;
endDate = temp;
}
// 按天递增循环(跨月完全没问题)
DateTime current = startDate;
while (!current.after(endDate)) {
String week = formatWeek(current);
Map<String, Object> map = new HashMap<>();
map.put("week", week);
map.put("date", current);
weekList.add(map);
// 下一天
current = DateUtil.offsetDay(current, 1);
}
if (listed.isEmpty()) {
return new HashMap<String, Object>() {{
return new HashMap<String, Object>() {{
put("attendanceSummary", null);
put("weekList", weekList);
put("statusList", null);
@@ -89,15 +115,26 @@ public class AttendanceServiceImpl implements AttendanceService {
}
ShopConfig config = shopConfigService.getById(shopId);
if (config == null || StrUtil.isBlank(config.getDingAppSecret())) {
return new HashMap<String, Object>() {{
return new HashMap<String, Object>() {{
put("attendanceSummary", null);
put("weekList", weekList);
put("statusList", null);
}};
}
ConcurrentLinkedDeque<String> statusList = new ConcurrentLinkedDeque<>();
RateLimiter rateLimiter = RateLimiter.create(15.0); // 每秒15次
weekList.parallelStream().forEach(week -> {
statusList.add(dingService.getAttendanceStatus(config.getDingAppKey(), config.getDingAppSecret(), shopId, (Date) week.get("date"), userId));
rateLimiter.acquire(); // 阻塞直到获取令牌(保证限流)
statusList.add(
dingService.getAttendanceStatus(
config.getDingAppKey(),
config.getDingAppSecret(),
shopId,
(Date) week.get("date"),
userId
)
);
});
return Map.of(

View File

@@ -167,6 +167,7 @@ public class DingService {
req.setUserid(userId);
req.setWorkDate(date);
OapiAttendanceGetupdatedataResponse rsp = client.execute(req, getToken(key, secret, shopId));
System.out.println(rsp.getBody());
JSONArray resultList = JSONObject.parseObject(rsp.getBody()).getJSONObject("result").getJSONArray("attendance_result_list");
if (resultList.isEmpty()) {
status = "休息日";