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