文件上传修改
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.tags.Tag;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
|
|
@ -40,8 +41,8 @@ import java.util.Objects;
|
|||
*/
|
||||
@Tag(name = "培训计划表")
|
||||
@RestController
|
||||
@RequestMapping(value="/personnelPlan")
|
||||
public class PersonnelPlanController extends AbstractCommonFileController{
|
||||
@RequestMapping(value = "/personnelPlan")
|
||||
public class PersonnelPlanController extends AbstractCommonFileController {
|
||||
|
||||
|
||||
@Autowired
|
||||
|
|
@ -62,18 +63,18 @@ public class PersonnelPlanController extends AbstractCommonFileController{
|
|||
LambdaQueryChainWrapper<PersonnelPlan> query = service.lambdaQuery()
|
||||
.eq(PersonnelPlan::getType, dto.getType())
|
||||
.eq(PersonnelPlan::getName, dto.getName());
|
||||
if (query.count() > 0){
|
||||
if (query.count() > 0) {
|
||||
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("开始时间不能大于结束时间");
|
||||
}
|
||||
|
||||
dto.setId(IdWorker.getId());
|
||||
dto.setCreateTime(new Date());
|
||||
boolean result = service.save(dto);
|
||||
if (result){
|
||||
if (result) {
|
||||
fileService.saveFile(dto.getFiles(), getGroupId(), dto.getId().toString());
|
||||
}
|
||||
return R.ok(result ? dto : null);
|
||||
|
|
@ -87,11 +88,11 @@ public class PersonnelPlanController extends AbstractCommonFileController{
|
|||
.ne(PersonnelPlan::getId, dto.getId())
|
||||
.eq(PersonnelPlan::getType, dto.getType())
|
||||
.eq(PersonnelPlan::getName, dto.getName());
|
||||
if (query.count() > 0){
|
||||
if (query.count() > 0) {
|
||||
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("开始时间不能大于结束时间");
|
||||
}
|
||||
|
||||
|
|
@ -100,7 +101,7 @@ public class PersonnelPlanController extends AbstractCommonFileController{
|
|||
dto.setCreateName(null);
|
||||
dto.setUpdateTime(new Date());
|
||||
boolean result = service.updateById(dto);
|
||||
if (result){
|
||||
if (result) {
|
||||
fileService.saveFile(dto.getFiles(), getGroupId(), dto.getId().toString());
|
||||
}
|
||||
return R.ok(result ? dto : null);
|
||||
|
|
@ -111,8 +112,8 @@ public class PersonnelPlanController extends AbstractCommonFileController{
|
|||
@GetMapping("/del/{id}")
|
||||
public R<Boolean> del(@Schema(name = "id") @PathVariable("id") Serializable id) {
|
||||
boolean data = service.removeById(id);
|
||||
if (data){
|
||||
fileService.deleteFile(getGroupId(),id.toString());
|
||||
if (data) {
|
||||
fileService.deleteFile(getGroupId(), id.toString());
|
||||
}
|
||||
return R.ok(data);
|
||||
}
|
||||
|
|
@ -121,7 +122,7 @@ public class PersonnelPlanController extends AbstractCommonFileController{
|
|||
@PostMapping("/list")
|
||||
public R<List<PersonnelPlan>> list() {
|
||||
return R.ok(service.lambdaQuery()
|
||||
.eq(PersonnelPlan::getStatus, 1)
|
||||
.eq(PersonnelPlan::getStatus, 1)
|
||||
.list());
|
||||
}
|
||||
|
||||
|
|
@ -131,28 +132,28 @@ public class PersonnelPlanController extends AbstractCommonFileController{
|
|||
LambdaQueryWrapper<PersonnelPlan> query = Wrappers.lambdaQuery();
|
||||
|
||||
Date stm = page.getStm();
|
||||
if (Objects.nonNull(stm)){
|
||||
if (Objects.nonNull(stm)) {
|
||||
query.ge(PersonnelPlan::getStm, stm);
|
||||
}
|
||||
|
||||
Date etm = page.getEtm();
|
||||
if (Objects.nonNull(etm)){
|
||||
if (Objects.nonNull(etm)) {
|
||||
query.le(PersonnelPlan::getEtm, etm);
|
||||
}
|
||||
|
||||
String name = page.getName();
|
||||
if (StringUtils.isNotBlank(name)){
|
||||
if (StringUtils.isNotBlank(name)) {
|
||||
query.like(PersonnelPlan::getName, name);
|
||||
}
|
||||
|
||||
String applicant = page.getApplicant();
|
||||
if (StringUtils.isNotBlank(applicant)){
|
||||
if (StringUtils.isNotBlank(applicant)) {
|
||||
query.like(PersonnelPlan::getApplicant, applicant);
|
||||
}
|
||||
|
||||
Page<PersonnelPlan> data = service.page(page.getPageSo().toPage(), query);
|
||||
data.getRecords().forEach(item ->
|
||||
item.setFiles(fileService.getFiles(getGroupId(),item.getId().toString()))
|
||||
item.setFiles(fileService.getFiles(getGroupId(), item.getId().toString()))
|
||||
);
|
||||
return R.ok(data);
|
||||
}
|
||||
|
|
@ -167,42 +168,48 @@ public class PersonnelPlanController extends AbstractCommonFileController{
|
|||
throw new IllegalArgumentException("上传文件为空");
|
||||
}
|
||||
|
||||
ExcelUtil<PersonnelPlan> util = new ExcelUtil< >(PersonnelPlan.class);
|
||||
ExcelUtil<PersonnelPlan> util = new ExcelUtil<>(PersonnelPlan.class);
|
||||
|
||||
List<PersonnelPlan> plans = util.importExcel(file.getInputStream());
|
||||
|
||||
if (CollectionUtils.isNotEmpty(plans)) {
|
||||
boolean b = service.saveBatch(plans);
|
||||
if (!b) {
|
||||
throw new IllegalArgumentException("上传失败");
|
||||
}
|
||||
}
|
||||
|
||||
return R.ok(plans);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@PostMapping("/download")
|
||||
@Operation(summary = "下载")
|
||||
public void download(@RequestBody PersonnelPlanPage page, HttpServletResponse response) {
|
||||
LambdaQueryChainWrapper<PersonnelPlan> query = service.lambdaQuery();
|
||||
|
||||
Date stm = page.getStm();
|
||||
if (Objects.nonNull(stm)){
|
||||
if (Objects.nonNull(stm)) {
|
||||
query.ge(PersonnelPlan::getStm, stm);
|
||||
}
|
||||
|
||||
Date etm = page.getEtm();
|
||||
if (Objects.nonNull(etm)){
|
||||
if (Objects.nonNull(etm)) {
|
||||
query.le(PersonnelPlan::getEtm, etm);
|
||||
}
|
||||
|
||||
String name = page.getName();
|
||||
if (StringUtils.isNotBlank(name)){
|
||||
if (StringUtils.isNotBlank(name)) {
|
||||
query.like(PersonnelPlan::getName, name);
|
||||
}
|
||||
|
||||
String applicant = page.getApplicant();
|
||||
if (StringUtils.isNotBlank(applicant)){
|
||||
if (StringUtils.isNotBlank(applicant)) {
|
||||
query.like(PersonnelPlan::getApplicant, applicant);
|
||||
}
|
||||
|
||||
List<PersonnelPlan> list = query.list();
|
||||
ExcelUtil<PersonnelPlan> util = new ExcelUtil< >(PersonnelPlan.class);
|
||||
ExcelUtil<PersonnelPlan> util = new ExcelUtil<>(PersonnelPlan.class);
|
||||
|
||||
util.exportExcel(response, list, "培训计划");
|
||||
|
||||
|
|
|
|||
|
|
@ -49,12 +49,12 @@ public interface FileAssociationsMapper extends BaseMapper<FileAssociations> {
|
|||
fa.del = '1'
|
||||
AND fa.business_id = #{businessId}
|
||||
AND fa."table_name" = #{tableName}
|
||||
AND fa.type = #{type}
|
||||
AND fd.group_id = #{tableName}
|
||||
AND fd.type = #{type}
|
||||
ORDER BY fa.tm desc
|
||||
</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("""
|
||||
<script>
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import com.gunshi.project.xyt.mapper.FileAssociationsMapper;
|
|||
import com.gunshi.project.xyt.model.FileAssociations;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.compress.utils.Lists;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
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) {
|
||||
if (CollectionUtils.isEmpty(files)) {
|
||||
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")
|
||||
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) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue