文件上传修改
parent
05a3ac1707
commit
9010e1e205
|
|
@ -17,6 +17,7 @@ import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
|
|
@ -40,8 +41,8 @@ import java.util.Objects;
|
||||||
*/
|
*/
|
||||||
@Tag(name = "培训计划表")
|
@Tag(name = "培训计划表")
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping(value="/personnelPlan")
|
@RequestMapping(value = "/personnelPlan")
|
||||||
public class PersonnelPlanController extends AbstractCommonFileController{
|
public class PersonnelPlanController extends AbstractCommonFileController {
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|
@ -62,18 +63,18 @@ public class PersonnelPlanController extends AbstractCommonFileController{
|
||||||
LambdaQueryChainWrapper<PersonnelPlan> query = service.lambdaQuery()
|
LambdaQueryChainWrapper<PersonnelPlan> query = service.lambdaQuery()
|
||||||
.eq(PersonnelPlan::getType, dto.getType())
|
.eq(PersonnelPlan::getType, dto.getType())
|
||||||
.eq(PersonnelPlan::getName, dto.getName());
|
.eq(PersonnelPlan::getName, dto.getName());
|
||||||
if (query.count() > 0){
|
if (query.count() > 0) {
|
||||||
throw new IllegalArgumentException("当前培训主题培训班名称重复");
|
throw new IllegalArgumentException("当前培训主题培训班名称重复");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Objects.nonNull(dto.getStm()) && Objects.nonNull(dto.getEtm()) && dto.getStm().compareTo(dto.getEtm()) > 0){
|
if (Objects.nonNull(dto.getStm()) && Objects.nonNull(dto.getEtm()) && dto.getStm().compareTo(dto.getEtm()) > 0) {
|
||||||
throw new IllegalArgumentException("开始时间不能大于结束时间");
|
throw new IllegalArgumentException("开始时间不能大于结束时间");
|
||||||
}
|
}
|
||||||
|
|
||||||
dto.setId(IdWorker.getId());
|
dto.setId(IdWorker.getId());
|
||||||
dto.setCreateTime(new Date());
|
dto.setCreateTime(new Date());
|
||||||
boolean result = service.save(dto);
|
boolean result = service.save(dto);
|
||||||
if (result){
|
if (result) {
|
||||||
fileService.saveFile(dto.getFiles(), getGroupId(), dto.getId().toString());
|
fileService.saveFile(dto.getFiles(), getGroupId(), dto.getId().toString());
|
||||||
}
|
}
|
||||||
return R.ok(result ? dto : null);
|
return R.ok(result ? dto : null);
|
||||||
|
|
@ -87,11 +88,11 @@ public class PersonnelPlanController extends AbstractCommonFileController{
|
||||||
.ne(PersonnelPlan::getId, dto.getId())
|
.ne(PersonnelPlan::getId, dto.getId())
|
||||||
.eq(PersonnelPlan::getType, dto.getType())
|
.eq(PersonnelPlan::getType, dto.getType())
|
||||||
.eq(PersonnelPlan::getName, dto.getName());
|
.eq(PersonnelPlan::getName, dto.getName());
|
||||||
if (query.count() > 0){
|
if (query.count() > 0) {
|
||||||
throw new IllegalArgumentException("当前培训主题培训班名称重复");
|
throw new IllegalArgumentException("当前培训主题培训班名称重复");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Objects.nonNull(dto.getStm()) && Objects.nonNull(dto.getEtm()) && dto.getStm().compareTo(dto.getEtm()) > 0){
|
if (Objects.nonNull(dto.getStm()) && Objects.nonNull(dto.getEtm()) && dto.getStm().compareTo(dto.getEtm()) > 0) {
|
||||||
throw new IllegalArgumentException("开始时间不能大于结束时间");
|
throw new IllegalArgumentException("开始时间不能大于结束时间");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -100,7 +101,7 @@ public class PersonnelPlanController extends AbstractCommonFileController{
|
||||||
dto.setCreateName(null);
|
dto.setCreateName(null);
|
||||||
dto.setUpdateTime(new Date());
|
dto.setUpdateTime(new Date());
|
||||||
boolean result = service.updateById(dto);
|
boolean result = service.updateById(dto);
|
||||||
if (result){
|
if (result) {
|
||||||
fileService.saveFile(dto.getFiles(), getGroupId(), dto.getId().toString());
|
fileService.saveFile(dto.getFiles(), getGroupId(), dto.getId().toString());
|
||||||
}
|
}
|
||||||
return R.ok(result ? dto : null);
|
return R.ok(result ? dto : null);
|
||||||
|
|
@ -111,8 +112,8 @@ public class PersonnelPlanController extends AbstractCommonFileController{
|
||||||
@GetMapping("/del/{id}")
|
@GetMapping("/del/{id}")
|
||||||
public R<Boolean> del(@Schema(name = "id") @PathVariable("id") Serializable id) {
|
public R<Boolean> del(@Schema(name = "id") @PathVariable("id") Serializable id) {
|
||||||
boolean data = service.removeById(id);
|
boolean data = service.removeById(id);
|
||||||
if (data){
|
if (data) {
|
||||||
fileService.deleteFile(getGroupId(),id.toString());
|
fileService.deleteFile(getGroupId(), id.toString());
|
||||||
}
|
}
|
||||||
return R.ok(data);
|
return R.ok(data);
|
||||||
}
|
}
|
||||||
|
|
@ -131,28 +132,28 @@ public class PersonnelPlanController extends AbstractCommonFileController{
|
||||||
LambdaQueryWrapper<PersonnelPlan> query = Wrappers.lambdaQuery();
|
LambdaQueryWrapper<PersonnelPlan> query = Wrappers.lambdaQuery();
|
||||||
|
|
||||||
Date stm = page.getStm();
|
Date stm = page.getStm();
|
||||||
if (Objects.nonNull(stm)){
|
if (Objects.nonNull(stm)) {
|
||||||
query.ge(PersonnelPlan::getStm, stm);
|
query.ge(PersonnelPlan::getStm, stm);
|
||||||
}
|
}
|
||||||
|
|
||||||
Date etm = page.getEtm();
|
Date etm = page.getEtm();
|
||||||
if (Objects.nonNull(etm)){
|
if (Objects.nonNull(etm)) {
|
||||||
query.le(PersonnelPlan::getEtm, etm);
|
query.le(PersonnelPlan::getEtm, etm);
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
String applicant = page.getApplicant();
|
String applicant = page.getApplicant();
|
||||||
if (StringUtils.isNotBlank(applicant)){
|
if (StringUtils.isNotBlank(applicant)) {
|
||||||
query.like(PersonnelPlan::getApplicant, applicant);
|
query.like(PersonnelPlan::getApplicant, applicant);
|
||||||
}
|
}
|
||||||
|
|
||||||
Page<PersonnelPlan> data = service.page(page.getPageSo().toPage(), query);
|
Page<PersonnelPlan> data = service.page(page.getPageSo().toPage(), query);
|
||||||
data.getRecords().forEach(item ->
|
data.getRecords().forEach(item ->
|
||||||
item.setFiles(fileService.getFiles(getGroupId(),item.getId().toString()))
|
item.setFiles(fileService.getFiles(getGroupId(), item.getId().toString()))
|
||||||
);
|
);
|
||||||
return R.ok(data);
|
return R.ok(data);
|
||||||
}
|
}
|
||||||
|
|
@ -167,13 +168,19 @@ public class PersonnelPlanController extends AbstractCommonFileController{
|
||||||
throw new IllegalArgumentException("上传文件为空");
|
throw new IllegalArgumentException("上传文件为空");
|
||||||
}
|
}
|
||||||
|
|
||||||
ExcelUtil<PersonnelPlan> util = new ExcelUtil< >(PersonnelPlan.class);
|
ExcelUtil<PersonnelPlan> util = new ExcelUtil<>(PersonnelPlan.class);
|
||||||
|
|
||||||
List<PersonnelPlan> plans = util.importExcel(file.getInputStream());
|
List<PersonnelPlan> plans = util.importExcel(file.getInputStream());
|
||||||
|
|
||||||
return R.ok(plans);
|
if (CollectionUtils.isNotEmpty(plans)) {
|
||||||
|
boolean b = service.saveBatch(plans);
|
||||||
|
if (!b) {
|
||||||
|
throw new IllegalArgumentException("上传失败");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return R.ok(plans);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@PostMapping("/download")
|
@PostMapping("/download")
|
||||||
|
|
@ -182,27 +189,27 @@ public class PersonnelPlanController extends AbstractCommonFileController{
|
||||||
LambdaQueryChainWrapper<PersonnelPlan> query = service.lambdaQuery();
|
LambdaQueryChainWrapper<PersonnelPlan> query = service.lambdaQuery();
|
||||||
|
|
||||||
Date stm = page.getStm();
|
Date stm = page.getStm();
|
||||||
if (Objects.nonNull(stm)){
|
if (Objects.nonNull(stm)) {
|
||||||
query.ge(PersonnelPlan::getStm, stm);
|
query.ge(PersonnelPlan::getStm, stm);
|
||||||
}
|
}
|
||||||
|
|
||||||
Date etm = page.getEtm();
|
Date etm = page.getEtm();
|
||||||
if (Objects.nonNull(etm)){
|
if (Objects.nonNull(etm)) {
|
||||||
query.le(PersonnelPlan::getEtm, etm);
|
query.le(PersonnelPlan::getEtm, etm);
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
String applicant = page.getApplicant();
|
String applicant = page.getApplicant();
|
||||||
if (StringUtils.isNotBlank(applicant)){
|
if (StringUtils.isNotBlank(applicant)) {
|
||||||
query.like(PersonnelPlan::getApplicant, applicant);
|
query.like(PersonnelPlan::getApplicant, applicant);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<PersonnelPlan> list = query.list();
|
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, "培训计划");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,12 +49,12 @@ public interface FileAssociationsMapper extends BaseMapper<FileAssociations> {
|
||||||
fa.del = '1'
|
fa.del = '1'
|
||||||
AND fa.business_id = #{businessId}
|
AND fa.business_id = #{businessId}
|
||||||
AND fa."table_name" = #{tableName}
|
AND fa."table_name" = #{tableName}
|
||||||
|
AND fa.type = #{type}
|
||||||
AND fd.group_id = #{tableName}
|
AND fd.group_id = #{tableName}
|
||||||
AND fd.type = #{type}
|
|
||||||
ORDER BY fa.tm desc
|
ORDER BY fa.tm desc
|
||||||
</script>
|
</script>
|
||||||
""")
|
""")
|
||||||
List<FileAssociations> getFiles(@Param("tableName") String tableName,@Param("businessId") String businessId,@Param("type") String type);
|
List<FileAssociations> getFiles1(@Param("tableName") String tableName,@Param("businessId") String businessId,@Param("type") String type);
|
||||||
|
|
||||||
@Select("""
|
@Select("""
|
||||||
<script>
|
<script>
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import com.gunshi.project.xyt.mapper.FileAssociationsMapper;
|
||||||
import com.gunshi.project.xyt.model.FileAssociations;
|
import com.gunshi.project.xyt.model.FileAssociations;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
|
import org.apache.commons.compress.utils.Lists;
|
||||||
import org.springframework.cache.annotation.CacheEvict;
|
import org.springframework.cache.annotation.CacheEvict;
|
||||||
import org.springframework.cache.annotation.Cacheable;
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
@ -90,6 +91,7 @@ public class FileAssociationsService extends ServiceImpl<FileAssociationsMapper,
|
||||||
public void saveFile(List<FileAssociations> files, String tableName, String businessId, String type) {
|
public void saveFile(List<FileAssociations> files, String tableName, String businessId, String type) {
|
||||||
if (CollectionUtils.isEmpty(files)) {
|
if (CollectionUtils.isEmpty(files)) {
|
||||||
log.info("fileIds is null!");
|
log.info("fileIds is null!");
|
||||||
|
files = Lists.newArrayList();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查询是否添加
|
// 查询是否添加
|
||||||
|
|
@ -210,7 +212,7 @@ public class FileAssociationsService extends ServiceImpl<FileAssociationsMapper,
|
||||||
|
|
||||||
@Cacheable(value = THIS_REDIS_KEY, key = "#p0 +':'+ #p1 +':'+ #p2", unless = "false")
|
@Cacheable(value = THIS_REDIS_KEY, key = "#p0 +':'+ #p1 +':'+ #p2", unless = "false")
|
||||||
public List<FileAssociations> getFiles(String tName, String bId,String num) {
|
public List<FileAssociations> getFiles(String tName, String bId,String num) {
|
||||||
return this.baseMapper.getFiles(tName,bId,num);
|
return this.baseMapper.getFiles1(tName,bId,num);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save(List<FileAssociations> attachList,String businessId, String tableName,String type) {
|
public void save(List<FileAssociations> attachList,String businessId, String tableName,String type) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue