feat: add dashboard
This commit is contained in:
@@ -27,7 +27,7 @@ import java.util.List;
|
||||
* @since 2024-12-23
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/user/uAccount")
|
||||
@RequestMapping("/account")
|
||||
public class UAccountController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
@@ -51,6 +51,11 @@ public class UAccountController extends BaseController {
|
||||
return success(uAccountService.getById(id));
|
||||
}
|
||||
|
||||
@GetMapping(value = "/dashboard")
|
||||
public AjaxResult dashboard() {
|
||||
return success(uAccountService.getByUser());
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody UAccount uAccount) {
|
||||
return toAjax(uAccountService.save(uAccount));
|
||||
|
||||
@@ -6,6 +6,7 @@ import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -29,7 +30,6 @@ import org.wfc.user.service.IUAccountService;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -40,6 +40,7 @@ import java.util.stream.Collectors;
|
||||
* @author sys
|
||||
* @since 2024-12-23
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class UAccountServiceImpl extends ServiceImpl<UAccountMapper, UAccount> implements IUAccountService {
|
||||
|
||||
@@ -62,14 +63,15 @@ public class UAccountServiceImpl extends ServiceImpl<UAccountMapper, UAccount> i
|
||||
DateTime endTime = DateUtil.offsetSecond(current, -30);
|
||||
List<UAccount> accounts = this.list(Wrappers.<UAccount>lambdaQuery().gt(UAccount::getEndTime, endTime));
|
||||
// 更新账户已使用流量,已使用时长
|
||||
List<UCdrUserVo> statCdr = ucdrMapper.getByUser(null, current.getTime(), endTime.getTime());
|
||||
for (UAccount account : accounts) {
|
||||
for (UCdrUserVo stat : statCdr) {
|
||||
if (Objects.equals(account.getUserId(), stat.getId())) {
|
||||
account.setTrafficUsed(stat.getTrafficUp() + stat.getTrafficDown());
|
||||
account.setDurationUsed(stat.getDuration());
|
||||
}
|
||||
if (ObjectUtil.isNull(account.getUserId())) {
|
||||
continue;
|
||||
}
|
||||
List<UCdrUserVo> statCdr = ucdrMapper.getByUser(account.getUserId(), account.getStartTime().getTime(), account.getEndTime().getTime());
|
||||
statCdr.stream().findFirst().ifPresent(stat -> {
|
||||
account.setTrafficUsed(stat.getTrafficUp() + stat.getTrafficDown());
|
||||
account.setDurationUsed(stat.getDuration());
|
||||
});
|
||||
}
|
||||
this.updateBatchById(accounts);
|
||||
|
||||
@@ -83,7 +85,11 @@ public class UAccountServiceImpl extends ServiceImpl<UAccountMapper, UAccount> i
|
||||
if (CollUtil.isNotEmpty(userIds)) {
|
||||
List<UClient> clients = clientMapper.selectList(Wrappers.<UClient>lambdaQuery().in(UClient::getUserId, userIds));
|
||||
for (UClient client : clients) {
|
||||
omadaAuthorizedClientApi.cancelAuthClient(client.getSiteId(), client.getClientMac());
|
||||
try {
|
||||
omadaAuthorizedClientApi.cancelAuthClient(client.getSiteId(), client.getClientMac());
|
||||
} catch (Exception e) {
|
||||
log.info("unAuth error: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,21 +4,36 @@
|
||||
|
||||
<select id="getByUser" resultType="org.wfc.user.domain.vo.UCdrUserVo">
|
||||
|
||||
SELECT t.* FROM (
|
||||
SELECT
|
||||
cdr.user_id id,
|
||||
min( ch.start_time ) start_time,
|
||||
max( cdr.last_seen_time ) end_time,
|
||||
max( cdr.activity ) activity,
|
||||
sum(
|
||||
ifnull( cdr.up_time, 0 ))+ sum(
|
||||
ifnull( ch.duration, 0 )) duration,
|
||||
sum(
|
||||
ifnull( cdr.traffic_down, 0 )) + sum(
|
||||
ifnull( ch.traffic_down, 0 )) traffic_down,
|
||||
sum(
|
||||
ifnull( cdr.traffic_up, 0 )) + sum(
|
||||
ifnull( ch.traffic_up, 0 )) traffic_up
|
||||
<choose>
|
||||
<when test="endTime != null">
|
||||
sum(
|
||||
if(cdr.last_seen_time <= #{endTime}, ifnull( cdr.up_time, 0 ), 0))+ sum(
|
||||
ifnull( ch.duration, 0 )) duration,
|
||||
sum(
|
||||
if(cdr.last_seen_time <= #{endTime}, ifnull( cdr.traffic_down, 0 ), 0)) + sum(
|
||||
ifnull( ch.traffic_down, 0 )) traffic_down,
|
||||
sum(
|
||||
if(cdr.last_seen_time <= #{endTime}, ifnull( cdr.traffic_up, 0 ), 0)) + sum(
|
||||
ifnull( ch.traffic_up, 0 )) traffic_up
|
||||
</when>
|
||||
<otherwise>
|
||||
sum(
|
||||
ifnull( cdr.up_time, 0 ))+ sum(
|
||||
ifnull( ch.duration, 0 )) duration,
|
||||
sum(
|
||||
ifnull( cdr.traffic_down, 0 )) + sum(
|
||||
ifnull( ch.traffic_down, 0 )) traffic_down,
|
||||
sum(
|
||||
ifnull( cdr.traffic_up, 0 )) + sum(
|
||||
ifnull( ch.traffic_up, 0 )) traffic_up
|
||||
</otherwise>
|
||||
</choose>
|
||||
|
||||
FROM
|
||||
u_cdr cdr
|
||||
LEFT JOIN u_cdr_history ch ON cdr.id = ch.cdr_id
|
||||
@@ -29,17 +44,15 @@
|
||||
<if test="userId != null and userId != ''">
|
||||
AND cdr.user_id = #{userId}
|
||||
</if>
|
||||
GROUP BY
|
||||
cdr.user_id
|
||||
) t
|
||||
<where>
|
||||
<if test="endTime != null">
|
||||
AND t.end_time <= #{endTime}
|
||||
AND ch.start_time <= #{endTime}
|
||||
</if>
|
||||
<if test="startTime != null">
|
||||
AND t.start_time >= #{startTime}
|
||||
AND ch.start_time >= #{startTime}
|
||||
</if>
|
||||
</where>
|
||||
GROUP BY
|
||||
cdr.user_id
|
||||
|
||||
</select>
|
||||
|
||||
<select id="getByClient" resultType="org.wfc.user.domain.vo.UCdrClientVo">
|
||||
|
||||
Reference in New Issue
Block a user