心跳数据推送 #66

Merged
root merged 1 commits from zzw-one into master 2024-08-30 17:27:03 +08:00
12 changed files with 168 additions and 0 deletions

View File

@ -116,6 +116,12 @@
<artifactId>yudao-spring-boot-starter-monitor</artifactId>
</dependency>
<!-- feign客户端 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
</dependencies>
<build>
<!-- 设置构建的 jar 包名 -->

View File

@ -2,11 +2,13 @@ package cn.iocoder.yudao.module.datacenter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
/**
* @Description 大屏服务启动类
*/
@SpringBootApplication
@EnableFeignClients
public class DatacenterServerApplication {
public static void main(String[] args) {
SpringApplication.run(DatacenterServerApplication.class, args);

View File

@ -1,5 +1,7 @@
package cn.iocoder.yudao.module.datacenter.controller.app.checkticket;
import cn.iocoder.yudao.module.datacenter.controller.app.clients.LoginClient;
import cn.iocoder.yudao.module.datacenter.controller.app.clients.vo.AuthLoginReqVO;
import cn.iocoder.yudao.module.datacenter.service.checkticket.CheckTicketService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
@ -20,6 +22,10 @@ import java.util.Map;
public class CheckTicketApi {
@Resource
private CheckTicketService checkTicketService;
@Resource
private LoginClient loginClient;
@GetMapping()
@Operation(summary = "获得日期当天的检票人数")
public Long checkTicketTotal(String starTime, String endTime) {
@ -35,4 +41,13 @@ public class CheckTicketApi {
String replace1 = endTime.replace("-", "");
return checkTicketService.findbytimetemp(replace,replace1);
}
@GetMapping("/getToken")
public Map<Object, Object> test(){
AuthLoginReqVO loginReqVO = new AuthLoginReqVO();
loginReqVO.setPassword("admin123");
loginReqVO.setUsername("admin");
Map<Object, Object> token = loginClient.getToken(loginReqVO,"1");
return token;
}
}

View File

@ -0,0 +1,16 @@
package cn.iocoder.yudao.module.datacenter.controller.app.clients;
import cn.iocoder.yudao.module.datacenter.controller.app.clients.vo.AuthLoginReqVO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import java.util.Map;
@FeignClient("system-server")
public interface LoginClient {
@PostMapping("/admin-api/system/auth/login")
Map<Object,Object> getToken(@RequestBody AuthLoginReqVO reqVO, @RequestHeader("Tenant-Id") String tenantId);
}

View File

@ -0,0 +1,69 @@
package cn.iocoder.yudao.module.datacenter.controller.app.clients.vo;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.validation.InEnum;
import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Length;
import javax.validation.constraints.AssertTrue;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Pattern;
@Schema(description = "管理后台 - 账号密码登录 Request VO如果登录并绑定社交用户需要传递 social 开头的参数")
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class AuthLoginReqVO {
@Schema(description = "账号", requiredMode = Schema.RequiredMode.REQUIRED, example = "yudaoyuanma")
@NotEmpty(message = "登录账号不能为空")
@Length(min = 4, max = 16, message = "账号长度为 4-16 位")
@Pattern(regexp = "^[A-Za-z0-9]+$", message = "账号格式为数字以及字母")
private String username;
@Schema(description = "密码", requiredMode = Schema.RequiredMode.REQUIRED, example = "buzhidao")
@NotEmpty(message = "密码不能为空")
@Length(min = 4, max = 16, message = "密码长度为 4-16 位")
private String password;
// ========== 图片验证码相关 ==========
@Schema(description = "验证码,验证码开启时,需要传递", requiredMode = Schema.RequiredMode.REQUIRED,
example = "PfcH6mgr8tpXuMWFjvW6YVaqrswIuwmWI5dsVZSg7sGpWtDCUbHuDEXl3cFB1+VvCC/rAkSwK8Fad52FSuncVg==")
@NotEmpty(message = "验证码不能为空", groups = CodeEnableGroup.class)
private String captchaVerification;
// ========== 绑定社交登录时需要传递如下参数 ==========
@Schema(description = "社交平台的类型,参见 SocialTypeEnum 枚举值", requiredMode = Schema.RequiredMode.REQUIRED, example = "10")
@InEnum(SocialTypeEnum.class)
private Integer socialType;
@Schema(description = "授权码", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private String socialCode;
@Schema(description = "state", requiredMode = Schema.RequiredMode.REQUIRED, example = "9b2ffbc1-7425-4155-9894-9d5c08541d62")
private String socialState;
/**
* 开启验证码的 Group
*/
public interface CodeEnableGroup {}
@AssertTrue(message = "授权码不能为空")
public boolean isSocialCodeValid() {
return socialType == null || StrUtil.isNotEmpty(socialCode);
}
@AssertTrue(message = "授权 state 不能为空")
public boolean isSocialState() {
return socialType == null || StrUtil.isNotEmpty(socialState);
}
}

View File

@ -57,14 +57,20 @@ public class CheckTicketServiceImpl implements CheckTicketService {
countMap.put("map"+String.format("%02d", Integer.parseInt(i+"")),0);
}
//查询该时间区域的所有数据
long s1 = System.currentTimeMillis();
List<CheckTicket> allByCheckticketdateBetween = checkTicketRepository.findAllByCheckticketdateBetween(starTime, this.publicMethod(endTime));
long s2 = System.currentTimeMillis();
System.out.println("1-------------------------"+(s2-s1));
//分析数据
long s3 = System.currentTimeMillis();
for (CheckTicket checkTicket : allByCheckticketdateBetween) {
String checktickettime = checkTicket.getChecktickettime();
String result = checktickettime.substring(0, 2);
Integer numberCount = countMap.get("map" + result);
countMap.put("map" + result, numberCount+1);
}
long s4 = System.currentTimeMillis();
System.out.println("2--------------------------"+(s4-s3));
//构造数据结构
LocalDateTime startTime = LocalDateTime.now();

View File

@ -164,6 +164,12 @@
<artifactId>tika-core</artifactId> <!-- 文件客户端:文件类型的识别 -->
</dependency>
<!-- feign客户端 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
</dependencies>
<build>
<!-- 设置构建的 jar 包名 -->

View File

@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.infra;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
/**
* 项目的启动类
@ -13,6 +14,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
* @author 芋道源码
*/
@SpringBootApplication
@EnableFeignClients
public class InfraServerApplication {
public static void main(String[] args) {

View File

@ -0,0 +1,13 @@
package cn.iocoder.yudao.module.infra.clients;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import java.util.List;
import java.util.Map;
@FeignClient("datacenter-server")
public interface LargeScreenClient {
@GetMapping("/api/asset/type")
List<Object> assetMethod1();
}

View File

@ -0,0 +1,28 @@
package cn.iocoder.yudao.module.infra.job.largeScreenHeartbeat;
import cn.iocoder.yudao.module.infra.api.websocket.WebSocketSenderApi;
import cn.iocoder.yudao.module.infra.clients.LargeScreenClient;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
@Component
public class LargeScreenHeartbeat {
@Resource
private WebSocketSenderApi webSocketSenderApi;
@Resource
private LargeScreenClient largeScreenClient;
@XxlJob("largeScreen")
public void largeScreenToWebSocket(){
List<Object> maps = largeScreenClient.assetMethod1();
webSocketSenderApi.sendObject(1,"1",maps);
}
}

View File

@ -67,6 +67,9 @@ public class AuthController {
@PermitAll
@Operation(summary = "使用账号密码登录")
public CommonResult<AuthLoginRespVO> login(@RequestBody @Valid AuthLoginReqVO reqVO) {
// AuthLoginReqVO loginReqVO = new AuthLoginReqVO();
// loginReqVO.setPassword("admin123");
// loginReqVO.setUsername("admin");
return success(authService.login(reqVO));
}

View File

@ -30,6 +30,8 @@ public class SecurityConfiguration {
.antMatchers("/actuator/**").anonymous();
// RPC 服务的安全配置
registry.antMatchers(ApiConstants.PREFIX + "/**").permitAll();
//登录接口
registry.antMatchers("/system/auth/login").permitAll();
}
};