Merge remote-tracking branch 'origin/test' into test
This commit is contained in:
@@ -5,6 +5,7 @@ import cn.hutool.core.date.DateUtil;
|
|||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.alibaba.fastjson2.JSONArray;
|
import com.alibaba.fastjson2.JSONArray;
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
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.entity.ShopConfig;
|
||||||
import com.czg.account.service.ShopConfigService;
|
import com.czg.account.service.ShopConfigService;
|
||||||
import com.czg.market.service.AttendanceService;
|
import com.czg.market.service.AttendanceService;
|
||||||
@@ -52,36 +53,61 @@ public class AttendanceServiceImpl implements AttendanceService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 自定义规则:1-5 → 数字, 6 → 六, 7 → 日
|
// 自定义规则:1-5 → 数字, 6 → 六, 7 → 日
|
||||||
private static String formatWeek(String week) {
|
private static String formatWeek(DateTime dateTime) {
|
||||||
return switch (week) {
|
String chinese = DateUtil.dayOfWeekEnum(dateTime).toChinese();
|
||||||
case "星期一" -> "1";
|
String week = switch (chinese) {
|
||||||
case "星期二" -> "2";
|
|
||||||
case "星期三" -> "3";
|
|
||||||
case "星期四" -> "4";
|
|
||||||
case "星期五" -> "5";
|
|
||||||
case "星期六" -> "六";
|
case "星期六" -> "六";
|
||||||
case "星期日" -> "日";
|
case "星期日" -> "日";
|
||||||
default -> week;
|
default -> null;
|
||||||
};
|
};
|
||||||
|
if (week == null) {
|
||||||
|
week = String.valueOf(DateUtil.dayOfMonth(dateTime));
|
||||||
|
}
|
||||||
|
return week;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> detail(Long shopId, String userId, String startTime, String endTime, Integer weekNum) {
|
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<>();
|
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);
|
DateTime endDate = StrUtil.isBlank(endTime)
|
||||||
String week = formatWeek(DateUtil.dayOfWeekEnum(date).toChinese());
|
? DateUtil.date()
|
||||||
weekList.add(new HashMap<>(){{
|
: DateUtil.parse(endTime);
|
||||||
put("week", week);
|
|
||||||
put("date", date);
|
// 开始时间:默认当月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()) {
|
if (listed.isEmpty()) {
|
||||||
return new HashMap<String, Object>() {{
|
return new HashMap<String, Object>() {{
|
||||||
put("attendanceSummary", null);
|
put("attendanceSummary", null);
|
||||||
put("weekList", weekList);
|
put("weekList", weekList);
|
||||||
put("statusList", null);
|
put("statusList", null);
|
||||||
@@ -89,15 +115,26 @@ public class AttendanceServiceImpl implements AttendanceService {
|
|||||||
}
|
}
|
||||||
ShopConfig config = shopConfigService.getById(shopId);
|
ShopConfig config = shopConfigService.getById(shopId);
|
||||||
if (config == null || StrUtil.isBlank(config.getDingAppSecret())) {
|
if (config == null || StrUtil.isBlank(config.getDingAppSecret())) {
|
||||||
return new HashMap<String, Object>() {{
|
return new HashMap<String, Object>() {{
|
||||||
put("attendanceSummary", null);
|
put("attendanceSummary", null);
|
||||||
put("weekList", weekList);
|
put("weekList", weekList);
|
||||||
put("statusList", null);
|
put("statusList", null);
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
ConcurrentLinkedDeque<String> statusList = new ConcurrentLinkedDeque<>();
|
ConcurrentLinkedDeque<String> statusList = new ConcurrentLinkedDeque<>();
|
||||||
|
RateLimiter rateLimiter = RateLimiter.create(15.0); // 每秒15次
|
||||||
|
|
||||||
weekList.parallelStream().forEach(week -> {
|
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(
|
return Map.of(
|
||||||
|
|||||||
@@ -167,6 +167,7 @@ public class DingService {
|
|||||||
req.setUserid(userId);
|
req.setUserid(userId);
|
||||||
req.setWorkDate(date);
|
req.setWorkDate(date);
|
||||||
OapiAttendanceGetupdatedataResponse rsp = client.execute(req, getToken(key, secret, shopId));
|
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");
|
JSONArray resultList = JSONObject.parseObject(rsp.getBody()).getJSONObject("result").getJSONArray("attendance_result_list");
|
||||||
if (resultList.isEmpty()) {
|
if (resultList.isEmpty()) {
|
||||||
status = "休息日";
|
status = "休息日";
|
||||||
|
|||||||
Reference in New Issue
Block a user