Skip to content

Commit

Permalink
后台提交
Browse files Browse the repository at this point in the history
  • Loading branch information
aiwenmo committed May 28, 2021
1 parent 3da48e7 commit ef0bce0
Show file tree
Hide file tree
Showing 50 changed files with 1,558 additions and 103 deletions.
28 changes: 28 additions & 0 deletions dlink-admin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,33 @@
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>com.nepxion</groupId>
<artifactId>banner</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>com.dlink</groupId>
<artifactId>dlink-core</artifactId>
</dependency>
</dependencies>
</project>
19 changes: 19 additions & 0 deletions dlink-admin/src/main/java/com/dlink/Dlink.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.dlink;


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
* Dlink 启动器
* @author wenmo
* @since 2021/5/28
*/
@EnableTransactionManagement
@SpringBootApplication
public class Dlink {
public static void main(String[] args) {
SpringApplication.run(Dlink.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.dlink.common.banner;

import com.dlink.constant.CommonConstant;
import com.dlink.utils.CustomBanner;
import com.nepxion.banner.BannerConstant;
import com.nepxion.banner.Description;
import com.nepxion.banner.LogoBanner;
import com.taobao.text.Color;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
* BannerInitializer
*
* @author wenmo
* @since 2021/5/10 21:40
*/
public class BannerInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
if (!(applicationContext instanceof AnnotationConfigApplicationContext)) {
LogoBanner logoBanner = new LogoBanner(BannerInitializer.class, "/dlink/logo.txt", "Welcome to Dlink", 5, 6, new Color[5], true);
CustomBanner.show(logoBanner, new Description(BannerConstant.VERSION + ":", CommonConstant.PROJECT_VERSION, 0, 1)
, new Description("Github:", "https://github.com/aiwenmo/dlink", 0, 1)
, new Description("公众号:", "DataLink数据中台", 0, 1)
);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dlink.common.result;

import com.dlink.model.CodeEnum;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
Expand Down
14 changes: 14 additions & 0 deletions dlink-admin/src/main/java/com/dlink/constant/CommonConstant.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.dlink.constant;

/**
* CommonConstant
*
* @author wenmo
* @since 2021/5/28 9:35
**/
public interface CommonConstant {
/**
* 项目版本号(banner使用)
*/
String PROJECT_VERSION = "0.1.0";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.dlink.controller;

import com.dlink.common.result.Result;
import com.dlink.model.Task;
import com.dlink.model.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
* AdminController
*
* @author wenmo
* @since 2021/5/28 15:52
**/
@Slf4j
@RestController
@RequestMapping("/user")
public class AdminController {

@Value("${dlink.login.username}")
private String username;
@Value("${dlink.login.password}")
private String password;
/**
* 获取指定ID的信息
*/
@PostMapping("/login")
public Result getOneById(@RequestBody User user) throws Exception {
if(username.equals(user.getUsername())&&password.equals(user.getPassword())) {
return Result.succeed(username, "登录成功");
}else{
return Result.failed("验证失败");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package com.dlink.controller;

import com.dlink.common.result.ProTableResult;
import com.dlink.common.result.Result;
import com.dlink.model.Catalogue;
import com.dlink.service.CatalogueService;
import com.fasterxml.jackson.databind.JsonNode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
* CatalogueController
*
* @author wenmo
* @since 2021/5/28 14:03
**/
@Slf4j
@RestController
@RequestMapping("/catalogue")
public class CatalogueController {
@Autowired
private CatalogueService catalogueService;

/**
* 新增或者更新
*/
@PutMapping
public Result saveOrUpdate(@RequestBody Catalogue catalogue) throws Exception {
if(catalogueService.saveOrUpdate(catalogue)){
return Result.succeed("新增成功");
}else {
return Result.failed("新增失败");
}
}

/**
* 动态查询列表
*/
@PostMapping
public ProTableResult<Catalogue> listCatalogues(@RequestBody JsonNode para) {
return catalogueService.selectForProTable(para);
}

/**
* 批量删除
*/
@DeleteMapping
public Result deleteMul(@RequestBody JsonNode para) {
if (para.size()>0){
boolean isAdmin = false;
List<Integer> error = new ArrayList<>();
for (final JsonNode item : para){
Integer id = item.asInt();
if(!catalogueService.removeById(id)){
error.add(id);
}
}
if(error.size()==0&&!isAdmin) {
return Result.succeed("删除成功");
}else {
return Result.succeed("删除部分成功,但"+error.toString()+"删除失败,共"+error.size()+"次失败。");
}
}else{
return Result.failed("请选择要删除的记录");
}
}

/**
* 获取指定ID的信息
*/
@PostMapping("/getOneById")
public Result getOneById(@RequestBody Catalogue catalogue) throws Exception {
catalogue = catalogueService.getById(catalogue.getId());
return Result.succeed(catalogue,"获取成功");
}
}
107 changes: 107 additions & 0 deletions dlink-admin/src/main/java/com/dlink/controller/ClusterController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package com.dlink.controller;

import com.dlink.common.result.ProTableResult;
import com.dlink.common.result.Result;
import com.dlink.model.Cluster;
import com.dlink.result.SubmitResult;
import com.dlink.service.ClusterService;
import com.fasterxml.jackson.databind.JsonNode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
* ClusterController
*
* @author wenmo
* @since 2021/5/28 14:03
**/
@Slf4j
@RestController
@RequestMapping("/cluster")
public class ClusterController {
@Autowired
private ClusterService clusterService;

/**
* 新增或者更新
*/
@PutMapping
public Result saveOrUpdate(@RequestBody Cluster cluster) throws Exception {
if(clusterService.saveOrUpdate(cluster)){
return Result.succeed("新增成功");
}else {
return Result.failed("新增失败");
}
}

/**
* 动态查询列表
*/
@PostMapping
public ProTableResult<Cluster> listClusters(@RequestBody JsonNode para) {
return clusterService.selectForProTable(para);
}

/**
* 批量删除
*/
@DeleteMapping
public Result deleteMul(@RequestBody JsonNode para) {
if (para.size()>0){
boolean isAdmin = false;
List<Integer> error = new ArrayList<>();
for (final JsonNode item : para){
Integer id = item.asInt();
if(!clusterService.removeById(id)){
error.add(id);
}
}
if(error.size()==0&&!isAdmin) {
return Result.succeed("删除成功");
}else {
return Result.succeed("删除部分成功,但"+error.toString()+"删除失败,共"+error.size()+"次失败。");
}
}else{
return Result.failed("请选择要删除的记录");
}
}

/**
* 获取指定ID的信息
*/
@PostMapping("/getOneById")
public Result getOneById(@RequestBody Cluster cluster) throws Exception {
cluster = clusterService.getById(cluster.getId());
return Result.succeed(cluster,"获取成功");
}

/**
* 全部心跳监测
*/
@PostMapping("/heartbeats")
public Result heartbeat(@RequestBody JsonNode para) {
List<Cluster> clusters = clusterService.listEnabledAll();
for (int i = 0; i < clusters.size(); i++) {
Cluster cluster = clusters.get(i);
String jobManagerHost = clusterService.checkHeartBeat(cluster.getHosts(), cluster.getJobManagerHost());
if(jobManagerHost==null){
cluster.setJobManagerHost("");
cluster.setStatus(0);
}else{
cluster.setJobManagerHost(jobManagerHost);
cluster.setStatus(1);
}
clusterService.updateById(cluster);
}
return Result.succeed("状态刷新完成");
}
}
Loading

0 comments on commit ef0bce0

Please sign in to comment.