mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
岗位添加人数
This commit is contained in:
@@ -4,8 +4,10 @@ import cn.lihongjie.coal.base.dto.OrgCommonDto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class JobPostDto extends OrgCommonDto {
|
||||
|
||||
private Integer empCount;
|
||||
private List<String> selfEmpIds;
|
||||
}
|
||||
|
||||
@@ -2,16 +2,25 @@ package cn.lihongjie.coal.jobPost.entity;
|
||||
|
||||
import cn.lihongjie.coal.base.entity.OrgCommonEntity;
|
||||
|
||||
import io.hypersistence.utils.hibernate.type.array.ListArrayType;
|
||||
|
||||
import jakarta.persistence.Entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.hibernate.annotations.Formula;
|
||||
import org.hibernate.annotations.Type;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
public class JobPostEntity extends OrgCommonEntity {
|
||||
|
||||
@Formula("(select count(*) from t_employee e where e.job_post_id = id)")
|
||||
private Integer empCount;
|
||||
|
||||
|
||||
|
||||
@Type(ListArrayType.class)
|
||||
@Formula("(select array_agg(e.id) from t_employee e where e.job_post_id = id)")
|
||||
private List<String> selfEmpIds;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ import cn.lihongjie.coal.script.mapper.ScriptMapper;
|
||||
import cn.lihongjie.coal.script.repository.ScriptRepository;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
|
||||
import groovy.lang.GroovyClassLoader;
|
||||
import groovy.lang.Script;
|
||||
@@ -26,6 +28,7 @@ import lombok.Cleanup;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
@@ -43,6 +46,7 @@ import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StopWatch;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
@@ -199,21 +203,35 @@ class ScriptService extends BaseService<ScriptEntity, ScriptRepository> {
|
||||
|
||||
@Autowired
|
||||
ObjectMapper objectMapper;
|
||||
|
||||
private final Cache<String, Class<?>> scriptCache = CacheBuilder.newBuilder().maximumSize(10000).build();
|
||||
|
||||
@SneakyThrows
|
||||
public ScriptExecResultDto exec(ScriptExecResultDto json) throws ScriptException {
|
||||
|
||||
StopWatch stopWatch = new StopWatch("script");
|
||||
stopWatch
|
||||
.start("get");
|
||||
// 执行groovy脚本
|
||||
// 1. 从数据库中获取脚本
|
||||
ScriptEntity scriptEntity = this.get(json.getId());
|
||||
|
||||
stopWatch.stop();
|
||||
|
||||
// 2. 执行脚本
|
||||
|
||||
stopWatch.start("parseClass");
|
||||
Class parsedClass =
|
||||
groovyClassLoader.parseClass(scriptEntity.getContent(), scriptEntity.getId());
|
||||
scriptCache.get(scriptEntity.getId() + DigestUtils.md5Hex(scriptEntity.getContent()), () ->groovyClassLoader.parseClass(scriptEntity.getContent(), scriptEntity.getId()));
|
||||
|
||||
stopWatch.stop();
|
||||
|
||||
stopWatch.start("newInstance");
|
||||
Script script = (Script) parsedClass.newInstance();
|
||||
|
||||
stopWatch.stop();
|
||||
stopWatch.start("prepare");
|
||||
|
||||
Logger scriptLogger = LoggerFactory.getLogger("scriptLogger");
|
||||
ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger) scriptLogger;
|
||||
|
||||
@@ -237,6 +255,9 @@ class ScriptService extends BaseService<ScriptEntity, ScriptRepository> {
|
||||
script.setProperty("params", ObjectUtils.defaultIfNull(json.getParams(), objectMapper.createObjectNode()));
|
||||
script.setProperty("ioc", applicationContext);
|
||||
|
||||
stopWatch.stop();
|
||||
|
||||
stopWatch.start("run");
|
||||
long start = System.currentTimeMillis();
|
||||
try {
|
||||
|
||||
@@ -245,11 +266,11 @@ class ScriptService extends BaseService<ScriptEntity, ScriptRepository> {
|
||||
json.setStackTrace(ExceptionUtils.getStackTrace(e));
|
||||
}
|
||||
long end = System.currentTimeMillis();
|
||||
|
||||
stopWatch.stop();
|
||||
// 3. 返回结果
|
||||
json.setLogs(appender.list.stream().map(x -> x.getFormattedMessage()).toList());
|
||||
json.setTime(end - start);
|
||||
|
||||
// logger.info("{}", stopWatch.prettyPrint());
|
||||
return json;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user