细节优化
This commit is contained in:
parent
68e749834d
commit
2828161cfa
@ -30,6 +30,6 @@ import java.util.List;
|
|||||||
* @since 2024/06/04 17:14
|
* @since 2024/06/04 17:14
|
||||||
*/
|
*/
|
||||||
public interface FinanceMapper extends BaseMapper<FinanceDO> {
|
public interface FinanceMapper extends BaseMapper<FinanceDO> {
|
||||||
@Select("SELECT * FROM agent_finance WHERE DATE(create_time) = #{date}")
|
@Select("SELECT * FROM agent_finance WHERE DATE(create_time) = #{date} AND (agent_name, create_time) IN (SELECT agent_name, MIN(create_time) FROM agent_finance WHERE DATE(create_time) = #{date} GROUP BY agent_name)")
|
||||||
List<FinanceDO> selectFinancesByCreateTime(LocalDate date);
|
List<FinanceDO> selectFinancesByCreateTime(LocalDate date);
|
||||||
}
|
}
|
@ -88,7 +88,7 @@ public class DailyReport {
|
|||||||
private static final String SEO_ROLE_CODE = "seo";
|
private static final String SEO_ROLE_CODE = "seo";
|
||||||
private static final String PLATFORM_HTH = "华体会";
|
private static final String PLATFORM_HTH = "华体会";
|
||||||
|
|
||||||
@Scheduled(cron = "0 40 11,14,17,21,23,1,3,5 * * ?")
|
@Scheduled(cron = "0 40 11,14,17,21,23 * * ?")
|
||||||
public void teamAccountDailyReport() {
|
public void teamAccountDailyReport() {
|
||||||
LocalDateTime nowDateTime = LocalDateTime.now();
|
LocalDateTime nowDateTime = LocalDateTime.now();
|
||||||
log.info("dailySummarize started at {}", nowDateTime);
|
log.info("dailySummarize started at {}", nowDateTime);
|
||||||
@ -128,7 +128,7 @@ public class DailyReport {
|
|||||||
log.info("ScheduledSendTeamDailyReport2 finished at {}", LocalDateTime.now());
|
log.info("ScheduledSendTeamDailyReport2 finished at {}", LocalDateTime.now());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Scheduled(cron = "10 15 0 * * ?")
|
@Scheduled(cron = "0 15 10 * * ?")
|
||||||
public void dailySummarize() {
|
public void dailySummarize() {
|
||||||
|
|
||||||
log.info("dailySummarize started at {}", LocalDateTime.now());
|
log.info("dailySummarize started at {}", LocalDateTime.now());
|
||||||
@ -181,6 +181,55 @@ public class DailyReport {
|
|||||||
log.info("dailySummarize finished at {}", LocalDateTime.now());
|
log.info("dailySummarize finished at {}", LocalDateTime.now());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Scheduled(cron = "1 0 0 * * ?")
|
||||||
|
public void financeTask() {
|
||||||
|
|
||||||
|
log.info("dailySummarize started at {}", LocalDateTime.now());
|
||||||
|
LocalDate yesterday = LocalDate.now().minusDays(1);
|
||||||
|
//查询部门下的所有用户
|
||||||
|
List<DeptUsersResp> deptWithUsersAndAccounts = deptService.getDeptWithUsersAndAccounts(MINISTER_ROLE_CODE);
|
||||||
|
|
||||||
|
deptWithUsersAndAccounts.forEach(dept -> {
|
||||||
|
//根据用户角色对部门用户进行分组
|
||||||
|
Map<String, List<UserWithRolesAndAccountsResp>> usersByRole = dept.getUsers()
|
||||||
|
.stream()
|
||||||
|
.flatMap(user -> user.getRoles()
|
||||||
|
.stream()
|
||||||
|
.map(role -> new AbstractMap.SimpleEntry<>(role.getCode(), user)))
|
||||||
|
.collect(Collectors.groupingByConcurrent(Map.Entry::getKey, Collectors
|
||||||
|
.mapping(Map.Entry::getValue, Collectors.toList())));
|
||||||
|
// 获取所有账号的username与用户的映射
|
||||||
|
Map<String, UserWithRolesAndAccountsResp> accountUsernameToUserMap = dept.getUsers()
|
||||||
|
.stream()
|
||||||
|
.flatMap(user -> user.getAccounts()
|
||||||
|
.stream()
|
||||||
|
.map(account -> new AbstractMap.SimpleEntry<>(account.getUsername(), user)))
|
||||||
|
.collect(Collectors.toConcurrentMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||||
|
|
||||||
|
var ministerUser = usersByRole.get(MINISTER_ROLE_CODE).get(0);
|
||||||
|
//建立团队之间账号的联系
|
||||||
|
Map<String, String> accountNameWithTopAgentName = new HashMap<>();
|
||||||
|
dept.getUsers()
|
||||||
|
.stream()
|
||||||
|
.flatMap(userWithRolesAndAccountsResp -> userWithRolesAndAccountsResp.getAccounts().stream())
|
||||||
|
.forEach(accountResp -> ministerUser.getAccounts()
|
||||||
|
.stream()
|
||||||
|
.filter(ministerAccount -> Objects.equals(accountResp.getPlatformId(), ministerAccount
|
||||||
|
.getPlatformId()))
|
||||||
|
.findFirst()
|
||||||
|
.ifPresent(ministerAccount -> accountNameWithTopAgentName.put(accountResp
|
||||||
|
.getUsername(), ministerAccount.getUsername())));
|
||||||
|
|
||||||
|
//获取账号不为空的用户
|
||||||
|
var deptUsers = dept.getUsers().stream().filter(user -> CollUtil.isNotEmpty(user.getAccounts())).toList();
|
||||||
|
//保存数据
|
||||||
|
saveData(ministerUser, deptUsers, yesterday, accountNameWithTopAgentName);
|
||||||
|
//getPayFailedMember(ministerUser, accountUsernameToUserMap, yesterday);
|
||||||
|
sendFinance(LocalDate.now(), accountUsernameToUserMap, ministerUser);
|
||||||
|
});
|
||||||
|
log.info("dailySummarize finished at {}", LocalDateTime.now());
|
||||||
|
}
|
||||||
|
|
||||||
private void sendTeamDailyReport() {
|
private void sendTeamDailyReport() {
|
||||||
LocalDateTime nowDateTime = LocalDateTime.now();
|
LocalDateTime nowDateTime = LocalDateTime.now();
|
||||||
LocalDate nowDate = LocalDate.now();
|
LocalDate nowDate = LocalDate.now();
|
||||||
|
Loading…
Reference in New Issue
Block a user