培训计划管理上传下载修改
parent
f9d0aad3fb
commit
d913852161
|
|
@ -12,7 +12,6 @@ import com.gunshi.project.xyt.service.FileAssociationsService;
|
||||||
import com.gunshi.project.xyt.service.PersonnelPlanService;
|
import com.gunshi.project.xyt.service.PersonnelPlanService;
|
||||||
import com.gunshi.project.xyt.validate.markers.Insert;
|
import com.gunshi.project.xyt.validate.markers.Insert;
|
||||||
import com.gunshi.project.xyt.validate.markers.Update;
|
import com.gunshi.project.xyt.validate.markers.Update;
|
||||||
import com.ruoyi.common.utils.SecurityUtils;
|
|
||||||
import com.ruoyi.common.utils.poi.ExcelUtil;
|
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
|
@ -135,9 +134,9 @@ public class PersonnelPlanController extends AbstractCommonFileController {
|
||||||
Date stm = page.getStm();
|
Date stm = page.getStm();
|
||||||
Date etm = page.getEtm();
|
Date etm = page.getEtm();
|
||||||
|
|
||||||
if (Objects.nonNull(etm) && Objects.nonNull(stm)){
|
if (Objects.nonNull(etm) && Objects.nonNull(stm)) {
|
||||||
query.nested(o -> o.between(PersonnelPlan::getStm, stm, etm).or().between(PersonnelPlan::getEtm, stm, etm));
|
query.nested(o -> o.between(PersonnelPlan::getStm, stm, etm).or().between(PersonnelPlan::getEtm, stm, etm));
|
||||||
}else{
|
} else {
|
||||||
|
|
||||||
if (Objects.nonNull(stm)) {
|
if (Objects.nonNull(stm)) {
|
||||||
query.ge(PersonnelPlan::getStm, stm);
|
query.ge(PersonnelPlan::getStm, stm);
|
||||||
|
|
@ -149,8 +148,6 @@ public class PersonnelPlanController extends AbstractCommonFileController {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
String name = page.getName();
|
String name = page.getName();
|
||||||
if (StringUtils.isNotBlank(name)) {
|
if (StringUtils.isNotBlank(name)) {
|
||||||
query.like(PersonnelPlan::getName, name);
|
query.like(PersonnelPlan::getName, name);
|
||||||
|
|
@ -188,7 +185,8 @@ public class PersonnelPlanController extends AbstractCommonFileController {
|
||||||
plans.forEach(o -> o.setId(IdWorker.getId())
|
plans.forEach(o -> o.setId(IdWorker.getId())
|
||||||
.setRegDate(regDate)
|
.setRegDate(regDate)
|
||||||
.setStatus(1)
|
.setStatus(1)
|
||||||
.setApplicant(SecurityUtils.getUsername()));
|
// .setApplicant(SecurityUtils.getUsername())
|
||||||
|
);
|
||||||
boolean b = service.saveBatch(plans);
|
boolean b = service.saveBatch(plans);
|
||||||
if (!b) {
|
if (!b) {
|
||||||
throw new IllegalArgumentException("上传失败");
|
throw new IllegalArgumentException("上传失败");
|
||||||
|
|
@ -203,43 +201,65 @@ public class PersonnelPlanController extends AbstractCommonFileController {
|
||||||
* name type,stm ,etm , , addr, unit, content,numPeople,scope 不能为空
|
* name type,stm ,etm , , addr, unit, content,numPeople,scope 不能为空
|
||||||
* stm etm 进行时间格式校验
|
* stm etm 进行时间格式校验
|
||||||
*/
|
*/
|
||||||
private void checkData(List<PersonnelPlan> list){
|
private void checkData(List<PersonnelPlan> list) {
|
||||||
if (CollectionUtils.isEmpty(list)){
|
if (CollectionUtils.isEmpty(list)) {
|
||||||
throw new IllegalArgumentException("上传数据为空");
|
throw new IllegalArgumentException("上传数据为空");
|
||||||
}
|
}
|
||||||
|
|
||||||
long count = list.stream().filter(o ->
|
int rowNumber = 1;
|
||||||
StringUtils.isBlank(o.getName())
|
for (PersonnelPlan o : list) {
|
||||||
|| Objects.isNull(o.getType())
|
if (StringUtils.isBlank(o.getName())) {
|
||||||
|| Objects.isNull(o.getStm())
|
throw new IllegalArgumentException("第" + rowNumber + "行的培训班名称不能为空");
|
||||||
|| Objects.isNull(o.getEtm())
|
}
|
||||||
|| Objects.isNull(o.getNumPeople())
|
if (Objects.isNull(o.getType())) {
|
||||||
|| StringUtils.isBlank(o.getAddr())
|
throw new IllegalArgumentException("第" + rowNumber + "行的培训主题不能为空");
|
||||||
|| StringUtils.isBlank(o.getContent())
|
}
|
||||||
|| StringUtils.isBlank(o.getScope())
|
if (Objects.isNull(o.getStm())) {
|
||||||
|
throw new IllegalArgumentException("第" + rowNumber + "行的开始培训时间不能为空");
|
||||||
)
|
}
|
||||||
.count();
|
if (Objects.isNull(o.getEtm())) {
|
||||||
if (count != list.size()){
|
throw new IllegalArgumentException("第" + rowNumber + "行的结束培训时间不能为空");
|
||||||
throw new IllegalArgumentException("数据中存在必传项为空的数据");
|
}
|
||||||
|
if (StringUtils.isBlank(o.getAddr())) {
|
||||||
|
throw new IllegalArgumentException("第" + rowNumber + "行的培训地点不能为空");
|
||||||
|
}
|
||||||
|
if (StringUtils.isBlank(o.getUnit())) {
|
||||||
|
throw new IllegalArgumentException("第" + rowNumber + "行的培训单位不能为空");
|
||||||
|
}
|
||||||
|
if (StringUtils.isBlank(o.getContent())) {
|
||||||
|
throw new IllegalArgumentException("第" + rowNumber + "行的培训内容不能为空");
|
||||||
|
}
|
||||||
|
if (o.getNumPeople() == null || o.getNumPeople() <= 0) {
|
||||||
|
throw new IllegalArgumentException("第" + rowNumber + "行的参训人数必须大于0");
|
||||||
|
}
|
||||||
|
if (StringUtils.isBlank(o.getScope())) {
|
||||||
|
throw new IllegalArgumentException("第" + rowNumber + "行的培训范围不能为空");
|
||||||
|
}
|
||||||
|
rowNumber++;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/download")
|
@PostMapping("/download")
|
||||||
@Operation(summary = "下载")
|
@Operation(summary = "下载")
|
||||||
public void download(@RequestBody PersonnelPlanPage page, HttpServletResponse response) {
|
public void download(@RequestBody PersonnelPlanPage page, HttpServletResponse response) {
|
||||||
LambdaQueryChainWrapper<PersonnelPlan> query = service.lambdaQuery();
|
LambdaQueryWrapper<PersonnelPlan> query = Wrappers.lambdaQuery();
|
||||||
|
|
||||||
Date stm = page.getStm();
|
Date stm = page.getStm();
|
||||||
if (Objects.nonNull(stm)) {
|
Date etm = page.getEtm();
|
||||||
query.ge(PersonnelPlan::getStm, stm);
|
|
||||||
|
if (Objects.nonNull(etm) && Objects.nonNull(stm)) {
|
||||||
|
query.nested(o -> o.between(PersonnelPlan::getStm, stm, etm).or().between(PersonnelPlan::getEtm, stm, etm));
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if (Objects.nonNull(stm)) {
|
||||||
|
query.ge(PersonnelPlan::getStm, stm);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Objects.nonNull(etm)) {
|
||||||
|
query.le(PersonnelPlan::getEtm, etm);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Date etm = page.getEtm();
|
|
||||||
if (Objects.nonNull(etm)) {
|
|
||||||
query.le(PersonnelPlan::getEtm, etm);
|
|
||||||
}
|
|
||||||
|
|
||||||
String name = page.getName();
|
String name = page.getName();
|
||||||
if (StringUtils.isNotBlank(name)) {
|
if (StringUtils.isNotBlank(name)) {
|
||||||
|
|
@ -250,8 +270,10 @@ public class PersonnelPlanController extends AbstractCommonFileController {
|
||||||
if (StringUtils.isNotBlank(applicant)) {
|
if (StringUtils.isNotBlank(applicant)) {
|
||||||
query.like(PersonnelPlan::getApplicant, applicant);
|
query.like(PersonnelPlan::getApplicant, applicant);
|
||||||
}
|
}
|
||||||
|
query.orderByDesc(PersonnelPlan::getStm).orderByDesc(PersonnelPlan::getCreateTime);
|
||||||
|
|
||||||
|
List<PersonnelPlan> list = service.list(query);
|
||||||
|
|
||||||
List<PersonnelPlan> list = query.list();
|
|
||||||
ExcelUtil<PersonnelPlan> util = new ExcelUtil<>(PersonnelPlan.class);
|
ExcelUtil<PersonnelPlan> util = new ExcelUtil<>(PersonnelPlan.class);
|
||||||
|
|
||||||
util.exportExcel(response, list, "培训计划");
|
util.exportExcel(response, list, "培训计划");
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ public class PersonnelPlan extends CommUpdate implements Serializable {
|
||||||
/**
|
/**
|
||||||
* 开始培训时间
|
* 开始培训时间
|
||||||
*/
|
*/
|
||||||
@Excel(name = "开始培训时间",sort = 3)
|
@Excel(name = "开始培训时间",sort = 3,dateFormat = DateFormatString.YYYY_MM_DD)
|
||||||
@Schema(description="开始培训时间 格式:yyyy-MM-dd")
|
@Schema(description="开始培训时间 格式:yyyy-MM-dd")
|
||||||
@NotNull(message = "开始培训时间不能为空")
|
@NotNull(message = "开始培训时间不能为空")
|
||||||
@TableField(value="stm")
|
@TableField(value="stm")
|
||||||
|
|
@ -92,7 +92,7 @@ public class PersonnelPlan extends CommUpdate implements Serializable {
|
||||||
/**
|
/**
|
||||||
* 结束培训时间
|
* 结束培训时间
|
||||||
*/
|
*/
|
||||||
@Excel(name = "结束培训时间",sort = 4)
|
@Excel(name = "结束培训时间",sort = 4,dateFormat = DateFormatString.YYYY_MM_DD)
|
||||||
@Schema(description="结束培训时间 格式:yyyy-MM-dd")
|
@Schema(description="结束培训时间 格式:yyyy-MM-dd")
|
||||||
@NotNull(message = "结束培训时间不能为空")
|
@NotNull(message = "结束培训时间不能为空")
|
||||||
@TableField(value="etm")
|
@TableField(value="etm")
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@ import java.time.LocalDateTime;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.ConcurrentMap;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -19,6 +21,9 @@ import java.util.concurrent.TimeUnit;
|
||||||
*/
|
*/
|
||||||
public class DateUtil {
|
public class DateUtil {
|
||||||
|
|
||||||
|
// 使用 ConcurrentMap 来缓存 SimpleDateFormat 实例
|
||||||
|
private static final ConcurrentMap<String, ThreadLocal<SimpleDateFormat>> DATE_FORMAT_CACHE = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
private static SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
private static SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
|
||||||
private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||||
|
|
@ -227,4 +232,22 @@ public class DateUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static boolean isValidDate(Date date, String format) {
|
||||||
|
if (date == null || format == null || format.isEmpty()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
SimpleDateFormat sdf = getThreadSafeFormatter(format);
|
||||||
|
sdf.setLenient(false); // 设置严格模式
|
||||||
|
sdf.parse(date.toString());
|
||||||
|
return true;
|
||||||
|
} catch (IllegalArgumentException | ParseException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static SimpleDateFormat getThreadSafeFormatter(String format) {
|
||||||
|
return DATE_FORMAT_CACHE.computeIfAbsent(format, key -> ThreadLocal.withInitial(() -> new SimpleDateFormat(key))).get();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue