@@ -4,8 +4,11 @@ | |||
*/ | |||
package cn.com.taiji.core.entity; | |||
import cn.com.taiji.common.entity.StringPropertyIdEntity; | |||
import cn.com.taiji.common.entity.StringPropertyUUIDEntity; | |||
import cn.com.taiji.common.entity.StringUUIDEntity; | |||
import cn.com.taiji.common.pub.TimeTools; | |||
import lombok.Getter; | |||
import lombok.Setter; | |||
import javax.persistence.Column; | |||
@@ -21,46 +24,23 @@ import java.time.LocalDateTime; | |||
* @version 1.0 | |||
* @since 1.0 | |||
*/ | |||
@Getter | |||
@Setter | |||
@Entity | |||
@Table(name = "common_schedule_log") | |||
public class ScheduleLog extends StringUUIDEntity { | |||
public class ScheduleLog extends StringPropertyUUIDEntity { | |||
@Column(name = "task_name", nullable = false, length = 100) | |||
private String taskName; | |||
@Column(name = "start_time", nullable = false) | |||
private LocalDateTime startTime; | |||
@Column(name = "end_time", nullable = false) | |||
private LocalDateTime endTime; | |||
@Column(name = "by_system", nullable = false) | |||
private boolean bySystem; | |||
@Column(name = "current_cron", nullable = false, length = 50) | |||
private String currentCron; | |||
private long execTime; | |||
@Column(name = "exec_time", nullable = false) | |||
public long getExecTime() { | |||
return execTime; | |||
} | |||
@Column(name = "by_system", nullable = false) | |||
public boolean isBySystem() { | |||
return bySystem; | |||
} | |||
@Column(name = "current_cron", nullable = false, length = 50) | |||
public String getCurrentCron() { | |||
return currentCron; | |||
} | |||
@Column(name = "task_name", nullable = false, length = 100) | |||
public String getTaskName() { | |||
return taskName; | |||
} | |||
@Column(name = "start_time", nullable = false) | |||
public LocalDateTime getStartTime() { | |||
return startTime; | |||
} | |||
@Column(name = "end_time", nullable = false) | |||
public LocalDateTime getEndTime() { | |||
return endTime; | |||
} | |||
private long execTime; | |||
@Transient | |||
public String getTimeStr() { |
@@ -0,0 +1,34 @@ | |||
package cn.com.taiji.core.entity; | |||
import cn.com.taiji.common.entity.StringPropertyUUIDEntity; | |||
import cn.com.taiji.core.entity.dict.SystemLogType; | |||
import lombok.Getter; | |||
import lombok.Setter; | |||
import javax.persistence.*; | |||
import java.time.LocalDateTime; | |||
/** | |||
* @author Peream <br> | |||
* Create Time:2011-5-20 下午02:43:14<br> | |||
* <a href="mailto:peream@gmail.com">peream@gmail.com</a> | |||
* @version 1.0 | |||
* @since 1.0 | |||
*/ | |||
@Getter | |||
@Setter | |||
@Entity | |||
@Table(name = "common_system_log") | |||
public class SystemLog extends StringPropertyUUIDEntity { | |||
@Column(name = "user_id", nullable = false) | |||
private String user; | |||
@Column(nullable = false, name = "op_time") | |||
private LocalDateTime optime; | |||
@Column(nullable = false, length = 50) | |||
private String ip; | |||
@Enumerated(EnumType.STRING) | |||
@Column(name = "log_type", nullable = false, length = 10) | |||
private SystemLogType logType; | |||
@Column(length = 300, nullable = false) | |||
private String info; | |||
} |
@@ -0,0 +1,18 @@ | |||
package cn.com.taiji.core.entity.dict; | |||
/** | |||
* Web系统日志 | |||
*/ | |||
public enum SystemLogType { | |||
SYSTEM("系统管理") {}; | |||
private final String value; | |||
private SystemLogType(String value) { | |||
this.value = value; | |||
} | |||
public String getValue() { | |||
return value; | |||
} | |||
} |
@@ -0,0 +1,9 @@ | |||
package cn.com.taiji.core.repo.jpa; | |||
import cn.com.taiji.common.repo.jpa.AbstractJpaRepo; | |||
import cn.com.taiji.core.entity.SystemLog; | |||
public interface SystemLogRepo extends AbstractJpaRepo<SystemLog, String> { | |||
} |
@@ -0,0 +1,45 @@ | |||
/* | |||
* Date: 2015年11月7日 author: Peream (peream@gmail.com) | |||
* | |||
*/ | |||
package cn.com.taiji.core.repo.request; | |||
import cn.com.taiji.common.pub.dao.HqlBuilder; | |||
import cn.com.taiji.common.repo.request.jpa.JpaDateTimePageableDataRequest; | |||
import cn.com.taiji.core.entity.ScheduleLog; | |||
import lombok.Getter; | |||
import lombok.Setter; | |||
import java.time.LocalDateTime; | |||
/** | |||
* @author Peream <br> | |||
* Create Time:2015年11月7日 下午3:47:24<br> | |||
* 三 <a href="mailto:peream@gmail.com">peream@gmail.com</a> | |||
* @version 1.0 | |||
* @since 1.0 | |||
*/ | |||
@Getter | |||
@Setter | |||
public class ScheduleLogPageRequest extends JpaDateTimePageableDataRequest<ScheduleLog> { | |||
private Boolean bySystem; | |||
private Long execTime; | |||
private String taskName; | |||
public ScheduleLogPageRequest() { | |||
this.orderBy = "startTime"; | |||
this.desc = true; | |||
} | |||
@Override | |||
public HqlBuilder toSelectHql() { | |||
LocalDateTime[] times = toDateTimes(); | |||
HqlBuilder hql = new HqlBuilder("from " + ScheduleLog.class.getName() + " where 1=1"); | |||
hql.append(" and startTime>=:startTime", times[0]).append(" and startTime<=:endTime", times[1]); | |||
hql.append(" and bySystem=:bySystem", bySystem); | |||
hql.append(" and execTime>=:execTime", execTime); | |||
hql.append(" and taskName=:taskName", taskName); | |||
return hql; | |||
} | |||
} |
@@ -0,0 +1,49 @@ | |||
/* | |||
* Date: 2015年11月7日 author: Peream (peream@gmail.com) | |||
* | |||
*/ | |||
package cn.com.taiji.core.repo.request; | |||
import cn.com.taiji.common.pub.dao.HqlBuilder; | |||
import cn.com.taiji.common.repo.request.jpa.JpaDateTimePageableDataRequest; | |||
import cn.com.taiji.core.entity.SystemLog; | |||
import cn.com.taiji.core.entity.dict.SystemLogType; | |||
import lombok.Getter; | |||
import lombok.Setter; | |||
import java.time.LocalDateTime; | |||
/** | |||
* @author Peream <br> | |||
* Create Time:2015年11月7日 下午3:52:49<br> | |||
* <a href="mailto:peream@gmail.com">peream@gmail.com</a> | |||
* @version 1.0 | |||
* @since 1.0 | |||
*/ | |||
@Setter | |||
@Getter | |||
public class SystemLogPageRequest extends JpaDateTimePageableDataRequest<SystemLog> { | |||
private SystemLogType logType; | |||
private String userName; | |||
private String ip; | |||
private String info; | |||
public SystemLogPageRequest() { | |||
this.orderBy = "optime"; | |||
this.desc = true; | |||
} | |||
@Override | |||
public HqlBuilder toSelectHql() { | |||
LocalDateTime[] times = toDateTimes(); | |||
HqlBuilder hql = new HqlBuilder("from " + clazz.getName() + " where 1=1"); | |||
hql.append(" and optime>=:optimeMin", times[0]).append(" and optime<=:optimeMax", times[1]); | |||
hql.append(" and logType=:logType", logType); | |||
hql.append(" and ip=:ip", ip); | |||
hql.append(" and info like :info", like(info)); | |||
hql.append(" and (user.loginName like :loginName or user.name like :name or user.namePy like :namePy)", | |||
like(userName)); | |||
return hql; | |||
} | |||
} |
@@ -1,6 +1,6 @@ | |||
buildscript { | |||
ext { | |||
set('appname', "samplew") | |||
set('appname', "dmq") | |||
} | |||
} | |||
@@ -0,0 +1,15 @@ | |||
package cn.com.taiji.dmq.config; | |||
import lombok.Data; | |||
import org.springframework.boot.context.properties.ConfigurationProperties; | |||
import org.springframework.stereotype.Component; | |||
@Data | |||
@ConfigurationProperties("app.ftp") | |||
@Component | |||
public class FtpConfigProperties { | |||
private String host; | |||
private int port; | |||
private String username; | |||
private String password; | |||
} |
@@ -0,0 +1,20 @@ | |||
/* | |||
* Date: 2012-3-7 author: Peream (peream@gmail.com) | |||
* | |||
*/ | |||
package cn.com.taiji.dmq.manager.system; | |||
import cn.com.taiji.common.model.dao.Pagination; | |||
import cn.com.taiji.core.repo.request.ScheduleLogPageRequest; | |||
/** | |||
* | |||
* @author Peream <br> | |||
* Create Time:2012-3-7 下午3:12:06<br> | |||
* <a href="mailto:peream@gmail.com">peream@gmail.com</a> | |||
* @since 1.0 | |||
* @version 1.0 | |||
*/ | |||
public interface ScheduleLogManager { | |||
public Pagination queryPage(ScheduleLogPageRequest req); | |||
} |
@@ -0,0 +1,32 @@ | |||
/* | |||
* Date: 2012-3-7 author: Peream (peream@gmail.com) | |||
* | |||
*/ | |||
package cn.com.taiji.dmq.manager.system; | |||
import cn.com.taiji.common.manager.AbstractManager; | |||
import cn.com.taiji.common.model.dao.Pagination; | |||
import cn.com.taiji.core.repo.jpa.ScheduleLogRepo; | |||
import cn.com.taiji.core.repo.request.ScheduleLogPageRequest; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
/** | |||
* | |||
* @author Peream <br> | |||
* Create Time:2012-3-7 下午3:12:30<br> | |||
* <a href="mailto:peream@gmail.com">peream@gmail.com</a> | |||
* @since 1.0 | |||
* @version 1.0 | |||
*/ | |||
@Service("scheduleLogManager") | |||
public class ScheduleLogManagerImpl extends AbstractManager implements ScheduleLogManager { | |||
@Autowired | |||
private ScheduleLogRepo logRepo; | |||
@Override | |||
public Pagination queryPage(ScheduleLogPageRequest req) { | |||
return logRepo.page(req); | |||
} | |||
} |
@@ -0,0 +1,21 @@ | |||
package cn.com.taiji.dmq.manager.system; | |||
import cn.com.taiji.common.model.dao.Pagination; | |||
import cn.com.taiji.core.entity.SystemLog; | |||
import cn.com.taiji.core.repo.request.SystemLogPageRequest; | |||
/** | |||
* | |||
* @author Peream <br> | |||
* Create Time:2011-5-20 下午03:04:48<br> | |||
* <a href="mailto:peream@gmail.com">peream@gmail.com</a> | |||
* @since 1.0 | |||
* @version 1.0 | |||
*/ | |||
public interface SystemLogManager { | |||
public String add(SystemLog log); | |||
public Pagination queryPage(SystemLogPageRequest req); | |||
void delete(String id); | |||
} |
@@ -0,0 +1,45 @@ | |||
package cn.com.taiji.dmq.manager.system; | |||
import cn.com.taiji.common.manager.AbstractManager; | |||
import cn.com.taiji.common.model.dao.Pagination; | |||
import cn.com.taiji.core.entity.SystemLog; | |||
import cn.com.taiji.core.repo.jpa.SystemLogRepo; | |||
import cn.com.taiji.core.repo.request.SystemLogPageRequest; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
import org.springframework.transaction.annotation.Transactional; | |||
/** | |||
* | |||
* @author Peream <br> | |||
* Create Time:2011-5-20 下午03:05:30<br> | |||
* <a href="mailto:peream@gmail.com">peream@gmail.com</a> | |||
* @since 1.0 | |||
* @version 1.0 | |||
*/ | |||
@Service("systemLogManager") | |||
public class SystemLogManagerImpl extends AbstractManager implements SystemLogManager { | |||
@Autowired | |||
private SystemLogRepo logRepo; | |||
@Override | |||
@Transactional | |||
public String add(SystemLog log) { | |||
logRepo.persist(log); | |||
return log.getId(); | |||
} | |||
@Override | |||
public Pagination queryPage(SystemLogPageRequest req) { | |||
return logRepo.page(req); | |||
} | |||
@Override | |||
public void delete(String id) { | |||
logRepo.deleteById(id); | |||
} | |||
} |
@@ -14,4 +14,6 @@ public class MyFinals extends SysFinals { | |||
public final static String UNDER_LINE = "_"; | |||
public final static String CRON_TASK_TABLE = "sample_lock"; | |||
public final static String SEQUENCE_NUM_TABLE = "sample_sequence_num"; | |||
public static final String USER_ID_HEADER = "userId"; | |||
} |
@@ -0,0 +1,33 @@ | |||
package cn.com.taiji.dmq.web; | |||
import cn.com.taiji.common.pub.IPTools; | |||
import cn.com.taiji.common.web.ApiValidController; | |||
import cn.com.taiji.core.entity.SystemLog; | |||
import cn.com.taiji.core.entity.dict.SystemLogType; | |||
import cn.com.taiji.dmq.manager.system.SystemLogManager; | |||
import cn.com.taiji.dmq.model.MyFinals; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import javax.servlet.http.HttpServletRequest; | |||
import java.time.LocalDateTime; | |||
import java.util.Objects; | |||
/** | |||
* star 2021/4/20 10:07 | |||
*/ | |||
public class BaseLogController extends ApiValidController { | |||
@Autowired | |||
protected SystemLogManager logManager; | |||
protected void addSystemLog(HttpServletRequest request, String info, Object... args) { | |||
String userId = request.getHeader(MyFinals.USER_ID_HEADER); | |||
String ip = IPTools.getIpAddr(request); | |||
SystemLog log = new SystemLog(); | |||
log.setUser(Objects.requireNonNullElse(userId, "admin")); | |||
log.setIp(ip); | |||
log.setOptime(LocalDateTime.now()); | |||
log.setLogType(SystemLogType.SYSTEM); | |||
log.setInfo(toLogString(info, args)); | |||
logManager.add(log); | |||
} | |||
} |
@@ -0,0 +1,94 @@ | |||
/* | |||
* Date: 2013-5-6 author: Peream (peream@gmail.com) | |||
* | |||
*/ | |||
package cn.com.taiji.dmq.web; | |||
import cn.com.taiji.common.manager.ManagerException; | |||
import cn.com.taiji.common.model.dao.Pagination; | |||
import cn.com.taiji.common.model.quartz.CronTaskQueryModel; | |||
import cn.com.taiji.common.model.quartz.CronTaskView; | |||
import cn.com.taiji.common.web.ApiResponse; | |||
import cn.com.taiji.dmq.manager.quartz.CronTaskManager; | |||
import cn.com.taiji.dmq.model.TaskGroup; | |||
import cn.com.taiji.dmq.model.quartz.MyCronTaskView; | |||
import io.swagger.annotations.Api; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.*; | |||
import javax.servlet.http.HttpServletRequest; | |||
/** | |||
* @author Peream <br> | |||
* Create Time:2013-5-6 下午5:06:44<br> | |||
* <a href="mailto:peream@gmail.com">peream@gmail.com</a> | |||
* @version 1.0 | |||
* @since 1.0 | |||
*/ | |||
@Api(tags = {"031.调度任务管理"}) | |||
@RestController | |||
@RequestMapping("/system/cron") | |||
public class CronTaskController extends BaseLogController { | |||
@Autowired | |||
private CronTaskManager manager; | |||
@PostMapping(value = "/dict") | |||
public ApiResponse<?> manageGet() { | |||
return ApiResponse.of(toStringKeyValueList(TaskGroup.values())); | |||
} | |||
@PostMapping(value = "/manage") | |||
public ApiResponse<Pagination> managePost(@RequestBody CronTaskQueryModel queryModel) { | |||
return ApiResponse.of(manager.queryPage(queryModel)); | |||
} | |||
@PostMapping(value = "/edit") | |||
public ApiResponse<MyCronTaskView> edit(@RequestBody CronTaskView view, HttpServletRequest request) | |||
throws ManagerException { | |||
manager.updateTaskCron(view); | |||
addSystemLog(request, "修改({})任务的cron为:{}", view.getTaskName(), view.getCron()); | |||
return ApiResponse.of(manager.findOne(view.getTaskName())) | |||
.setMessage(toLogString("修改({})任务的cron为:{}", view.getTaskName(), view.getCron())); | |||
} | |||
@PostMapping(value = "/view/{taskName}") | |||
public ApiResponse<MyCronTaskView> view(@PathVariable("taskName") String taskName) { | |||
return ApiResponse.of(manager.findOne(taskName)); | |||
} | |||
@PostMapping(value = "/runner/{taskName}/{type}") | |||
public ApiResponse<MyCronTaskView> runnerManage(@PathVariable("taskName") String taskName, | |||
@PathVariable("type") String type, HttpServletRequest request) throws ManagerException { | |||
if ("stop".equals(type)) { | |||
manager.stop(taskName); | |||
addSystemLog(request, "停止调度器{}", taskName); | |||
} else { | |||
manager.start(taskName); | |||
addSystemLog(request, "启动调度器{}", taskName); | |||
} | |||
return ApiResponse.of(manager.findOne(taskName)) | |||
.setMessage(toLogString("{}调度器{}成功", "stop".equals(type) ? "停止" : "启动", taskName)); | |||
} | |||
@PostMapping(value = "/run/{taskName}") | |||
public ApiResponse<MyCronTaskView> runTaskNow(@PathVariable("taskName") String taskName, HttpServletRequest request) | |||
throws ManagerException { | |||
manager.runTaskNow(taskName); | |||
addSystemLog(request, "执行任务{}", taskName); | |||
return ApiResponse.of(manager.findOne(taskName)).setMessage(toLogString("执行任务{}成功", taskName)); | |||
} | |||
@PostMapping(value = "/startall") | |||
public ApiResponse<Object> startAll(@RequestParam("taskNames") String[] taskNames) throws ManagerException { | |||
manager.startAll(taskNames); | |||
return ApiResponse.success().setMessage("批量启动调度器成功,请刷新后查看状态"); | |||
} | |||
@PostMapping(value = "/stopall") | |||
public ApiResponse<Object> stopAll(@RequestParam("taskNames") String[] taskNames) throws ManagerException { | |||
manager.stopAll(taskNames); | |||
return ApiResponse.success().setMessage("批量停止调度器成功,请刷新后查看状态"); | |||
} | |||
} |
@@ -0,0 +1,30 @@ | |||
/* | |||
* Date: 2012-3-7 | |||
* author: Peream (peream@gmail.com) | |||
* | |||
*/ | |||
package cn.com.taiji.dmq.web; | |||
import cn.com.taiji.common.model.dao.Pagination; | |||
import cn.com.taiji.common.web.ApiResponse; | |||
import cn.com.taiji.core.repo.request.ScheduleLogPageRequest; | |||
import cn.com.taiji.dmq.manager.system.ScheduleLogManager; | |||
import io.swagger.annotations.Api; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
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; | |||
@Api(tags = {"032.调度日志管理"}) | |||
@RestController | |||
@RequestMapping("/system/schedulelog") | |||
public class ScheduleLogController extends BaseLogController { | |||
@Autowired | |||
private ScheduleLogManager scheduleLogManager; | |||
@PostMapping(value = "/manage") | |||
public ApiResponse<Pagination> manageList(@RequestBody ScheduleLogPageRequest queryModel) { | |||
return ApiResponse.of(scheduleLogManager.queryPage(queryModel)); | |||
} | |||
} |
@@ -1,6 +1,6 @@ | |||
spring: | |||
application: | |||
name: sample | |||
name: dmq | |||
mvc: | |||
locale: zh_CN | |||
messages: | |||
@@ -13,7 +13,7 @@ spring: | |||
discovery: | |||
enabled: true | |||
server-addr: 100.64.2.105:8848 | |||
namespace: guizhou-issuer | |||
namespace: zhywpt-new-test | |||
username: nacos | |||
password: 'Pw=j8PKxV7s9' | |||
ip: 127.0.0.1 | |||
@@ -22,7 +22,7 @@ spring: | |||
enabled: true | |||
file-extension: yaml # 必须修改成yaml | |||
server-addr: 100.64.2.105:8848 | |||
namespace: guizhou-issuer | |||
namespace: zhywpt-new-test | |||
username: nacos | |||
password: 'Pw=j8PKxV7s9' | |||
extension-configs: | |||
@@ -33,7 +33,7 @@ spring: | |||
server: | |||
port: 8085 | |||
servlet: | |||
context-path: /sample/ | |||
context-path: /dmq/ | |||
#应用相关配置 | |||
app: | |||
@@ -46,3 +46,8 @@ app: | |||
serviceAddr: | |||
sample: http://127.0.0.1:8086 | |||
issues: http://127.0.0.1:9071 | |||
ftp: | |||
host: 192.168.101.35 | |||
port: 22 | |||
username: ftptjorhlt | |||
password: ftptjorhlt!P |
@@ -0,0 +1,20 @@ | |||
/* | |||
* Date: 2012-3-7 author: Peream (peream@gmail.com) | |||
* | |||
*/ | |||
package cn.com.taiji.iasq.manager.system; | |||
import cn.com.taiji.common.model.dao.Pagination; | |||
import cn.com.taiji.core.repo.request.ScheduleLogPageRequest; | |||
/** | |||
* | |||
* @author Peream <br> | |||
* Create Time:2012-3-7 下午3:12:06<br> | |||
* <a href="mailto:peream@gmail.com">peream@gmail.com</a> | |||
* @since 1.0 | |||
* @version 1.0 | |||
*/ | |||
public interface ScheduleLogManager { | |||
public Pagination queryPage(ScheduleLogPageRequest req); | |||
} |
@@ -0,0 +1,32 @@ | |||
/* | |||
* Date: 2012-3-7 author: Peream (peream@gmail.com) | |||
* | |||
*/ | |||
package cn.com.taiji.iasq.manager.system; | |||
import cn.com.taiji.common.manager.AbstractManager; | |||
import cn.com.taiji.common.model.dao.Pagination; | |||
import cn.com.taiji.core.repo.jpa.ScheduleLogRepo; | |||
import cn.com.taiji.core.repo.request.ScheduleLogPageRequest; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
/** | |||
* | |||
* @author Peream <br> | |||
* Create Time:2012-3-7 下午3:12:30<br> | |||
* <a href="mailto:peream@gmail.com">peream@gmail.com</a> | |||
* @since 1.0 | |||
* @version 1.0 | |||
*/ | |||
@Service("scheduleLogManager") | |||
public class ScheduleLogManagerImpl extends AbstractManager implements ScheduleLogManager { | |||
@Autowired | |||
private ScheduleLogRepo logRepo; | |||
@Override | |||
public Pagination queryPage(ScheduleLogPageRequest req) { | |||
return logRepo.page(req); | |||
} | |||
} |
@@ -0,0 +1,21 @@ | |||
package cn.com.taiji.iasq.manager.system; | |||
import cn.com.taiji.common.model.dao.Pagination; | |||
import cn.com.taiji.core.entity.SystemLog; | |||
import cn.com.taiji.core.repo.request.SystemLogPageRequest; | |||
/** | |||
* | |||
* @author Peream <br> | |||
* Create Time:2011-5-20 下午03:04:48<br> | |||
* <a href="mailto:peream@gmail.com">peream@gmail.com</a> | |||
* @since 1.0 | |||
* @version 1.0 | |||
*/ | |||
public interface SystemLogManager { | |||
public String add(SystemLog log); | |||
public Pagination queryPage(SystemLogPageRequest req); | |||
void delete(String id); | |||
} |
@@ -0,0 +1,45 @@ | |||
package cn.com.taiji.iasq.manager.system; | |||
import cn.com.taiji.common.manager.AbstractManager; | |||
import cn.com.taiji.common.model.dao.Pagination; | |||
import cn.com.taiji.core.entity.SystemLog; | |||
import cn.com.taiji.core.repo.jpa.SystemLogRepo; | |||
import cn.com.taiji.core.repo.request.SystemLogPageRequest; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.stereotype.Service; | |||
import org.springframework.transaction.annotation.Transactional; | |||
/** | |||
* | |||
* @author Peream <br> | |||
* Create Time:2011-5-20 下午03:05:30<br> | |||
* <a href="mailto:peream@gmail.com">peream@gmail.com</a> | |||
* @since 1.0 | |||
* @version 1.0 | |||
*/ | |||
@Service("systemLogManager") | |||
public class SystemLogManagerImpl extends AbstractManager implements SystemLogManager { | |||
@Autowired | |||
private SystemLogRepo logRepo; | |||
@Override | |||
@Transactional | |||
public String add(SystemLog log) { | |||
logRepo.persist(log); | |||
return log.getId(); | |||
} | |||
@Override | |||
public Pagination queryPage(SystemLogPageRequest req) { | |||
return logRepo.page(req); | |||
} | |||
@Override | |||
public void delete(String id) { | |||
logRepo.deleteById(id); | |||
} | |||
} |
@@ -13,4 +13,6 @@ public class MyFinals extends SysFinals { | |||
public final static String CRON_TASK_TABLE = "sample_lock"; | |||
public final static String SEQUENCE_NUM_TABLE = "sample_sequence_num"; | |||
public static final String USER_ID_HEADER = "userId"; | |||
} |
@@ -0,0 +1,33 @@ | |||
package cn.com.taiji.iasq.web; | |||
import cn.com.taiji.common.pub.IPTools; | |||
import cn.com.taiji.common.web.ApiValidController; | |||
import cn.com.taiji.core.entity.SystemLog; | |||
import cn.com.taiji.core.entity.dict.SystemLogType; | |||
import cn.com.taiji.iasq.manager.system.SystemLogManager; | |||
import cn.com.taiji.iasq.model.MyFinals; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import javax.servlet.http.HttpServletRequest; | |||
import java.time.LocalDateTime; | |||
import java.util.Objects; | |||
/** | |||
* star 2021/4/20 10:07 | |||
*/ | |||
public class BaseLogController extends ApiValidController { | |||
@Autowired | |||
protected SystemLogManager logManager; | |||
protected void addSystemLog(HttpServletRequest request, String info, Object... args) { | |||
String userId = request.getHeader(MyFinals.USER_ID_HEADER); | |||
String ip = IPTools.getIpAddr(request); | |||
SystemLog log = new SystemLog(); | |||
log.setUser(Objects.requireNonNullElse(userId, "admin")); | |||
log.setIp(ip); | |||
log.setOptime(LocalDateTime.now()); | |||
log.setLogType(SystemLogType.SYSTEM); | |||
log.setInfo(toLogString(info, args)); | |||
logManager.add(log); | |||
} | |||
} |
@@ -0,0 +1,94 @@ | |||
/* | |||
* Date: 2013-5-6 author: Peream (peream@gmail.com) | |||
* | |||
*/ | |||
package cn.com.taiji.iasq.web; | |||
import cn.com.taiji.common.manager.ManagerException; | |||
import cn.com.taiji.common.model.dao.Pagination; | |||
import cn.com.taiji.common.model.quartz.CronTaskQueryModel; | |||
import cn.com.taiji.common.model.quartz.CronTaskView; | |||
import cn.com.taiji.common.web.ApiResponse; | |||
import cn.com.taiji.iasq.manager.quartz.CronTaskManager; | |||
import cn.com.taiji.iasq.model.TaskGroup; | |||
import cn.com.taiji.iasq.model.quartz.MyCronTaskView; | |||
import io.swagger.annotations.Api; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
import org.springframework.web.bind.annotation.*; | |||
import javax.servlet.http.HttpServletRequest; | |||
/** | |||
* @author Peream <br> | |||
* Create Time:2013-5-6 下午5:06:44<br> | |||
* <a href="mailto:peream@gmail.com">peream@gmail.com</a> | |||
* @version 1.0 | |||
* @since 1.0 | |||
*/ | |||
@Api(tags = {"031.调度任务管理"}) | |||
@RestController | |||
@RequestMapping("/system/cron") | |||
public class CronTaskController extends BaseLogController { | |||
@Autowired | |||
private CronTaskManager manager; | |||
@PostMapping(value = "/dict") | |||
public ApiResponse<?> manageGet() { | |||
return ApiResponse.of(toStringKeyValueList(TaskGroup.values())); | |||
} | |||
@PostMapping(value = "/manage") | |||
public ApiResponse<Pagination> managePost(@RequestBody CronTaskQueryModel queryModel) { | |||
return ApiResponse.of(manager.queryPage(queryModel)); | |||
} | |||
@PostMapping(value = "/edit") | |||
public ApiResponse<MyCronTaskView> edit(@RequestBody CronTaskView view, HttpServletRequest request) | |||
throws ManagerException { | |||
manager.updateTaskCron(view); | |||
addSystemLog(request, "修改({})任务的cron为:{}", view.getTaskName(), view.getCron()); | |||
return ApiResponse.of(manager.findOne(view.getTaskName())) | |||
.setMessage(toLogString("修改({})任务的cron为:{}", view.getTaskName(), view.getCron())); | |||
} | |||
@PostMapping(value = "/view/{taskName}") | |||
public ApiResponse<MyCronTaskView> view(@PathVariable("taskName") String taskName) { | |||
return ApiResponse.of(manager.findOne(taskName)); | |||
} | |||
@PostMapping(value = "/runner/{taskName}/{type}") | |||
public ApiResponse<MyCronTaskView> runnerManage(@PathVariable("taskName") String taskName, | |||
@PathVariable("type") String type, HttpServletRequest request) throws ManagerException { | |||
if ("stop".equals(type)) { | |||
manager.stop(taskName); | |||
addSystemLog(request, "停止调度器{}", taskName); | |||
} else { | |||
manager.start(taskName); | |||
addSystemLog(request, "启动调度器{}", taskName); | |||
} | |||
return ApiResponse.of(manager.findOne(taskName)) | |||
.setMessage(toLogString("{}调度器{}成功", "stop".equals(type) ? "停止" : "启动", taskName)); | |||
} | |||
@PostMapping(value = "/run/{taskName}") | |||
public ApiResponse<MyCronTaskView> runTaskNow(@PathVariable("taskName") String taskName, HttpServletRequest request) | |||
throws ManagerException { | |||
manager.runTaskNow(taskName); | |||
addSystemLog(request, "执行任务{}", taskName); | |||
return ApiResponse.of(manager.findOne(taskName)).setMessage(toLogString("执行任务{}成功", taskName)); | |||
} | |||
@PostMapping(value = "/startall") | |||
public ApiResponse<Object> startAll(@RequestParam("taskNames") String[] taskNames) throws ManagerException { | |||
manager.startAll(taskNames); | |||
return ApiResponse.success().setMessage("批量启动调度器成功,请刷新后查看状态"); | |||
} | |||
@PostMapping(value = "/stopall") | |||
public ApiResponse<Object> stopAll(@RequestParam("taskNames") String[] taskNames) throws ManagerException { | |||
manager.stopAll(taskNames); | |||
return ApiResponse.success().setMessage("批量停止调度器成功,请刷新后查看状态"); | |||
} | |||
} |
@@ -0,0 +1,30 @@ | |||
/* | |||
* Date: 2012-3-7 | |||
* author: Peream (peream@gmail.com) | |||
* | |||
*/ | |||
package cn.com.taiji.iasq.web; | |||
import cn.com.taiji.common.model.dao.Pagination; | |||
import cn.com.taiji.common.web.ApiResponse; | |||
import cn.com.taiji.core.repo.request.ScheduleLogPageRequest; | |||
import cn.com.taiji.iasq.manager.system.ScheduleLogManager; | |||
import io.swagger.annotations.Api; | |||
import org.springframework.beans.factory.annotation.Autowired; | |||
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; | |||
@Api(tags = {"032.调度日志管理"}) | |||
@RestController | |||
@RequestMapping("/system/schedulelog") | |||
public class ScheduleLogController extends BaseLogController { | |||
@Autowired | |||
private ScheduleLogManager scheduleLogManager; | |||
@PostMapping(value = "/manage") | |||
public ApiResponse<Pagination> manageList(@RequestBody ScheduleLogPageRequest queryModel) { | |||
return ApiResponse.of(scheduleLogManager.queryPage(queryModel)); | |||
} | |||
} |