CollegeFileServiceImpl.java
4.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package com.subsidy.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.subsidy.common.exception.HttpException;
import com.subsidy.dto.college.FileManagementDTO;
import com.subsidy.mapper.MatchDictMapper;
import com.subsidy.model.CollegeFileDO;
import com.subsidy.mapper.CollegeFileMapper;
import com.subsidy.model.CollegesDictDO;
import com.subsidy.model.MatchDictDO;
import com.subsidy.service.CollegeFileService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.subsidy.util.ConstantUtils;
import com.subsidy.vo.college.CollegeInfoVO;
import com.subsidy.vo.college.FileManagementVO;
import com.subsidy.vo.college.RecentFileVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.BeanWrapper;
import org.springframework.beans.BeanWrapperImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* <p>
* 服务实现类
* </p>
*
* @author Tuyp
* @since 2025-01-09
*/
@Service
public class CollegeFileServiceImpl extends ServiceImpl<CollegeFileMapper, CollegeFileDO> implements CollegeFileService {
@Autowired
private MatchDictMapper matchDictMapper;
public String submitFile(CollegeFileDO collegeFileDO) throws Exception {
//时间
MatchDictDO matchDictDO = matchDictMapper.selectById(collegeFileDO.getMatchId());
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
if (null != matchDictDO.getFileStartTime() && new Date().before(simpleDateFormat.parse(matchDictDO.getFileStartTime()))){
throw new HttpException(10007);
}
if ( null != matchDictDO.getFileEndTime() && new Date().after(simpleDateFormat.parse(matchDictDO.getFileEndTime()))) {
throw new HttpException(10007);
}
CollegeFileDO collegeFileDO1 = this.baseMapper.selectOne(new QueryWrapper<CollegeFileDO>()
.lambda()
.eq(CollegeFileDO::getMatchId, collegeFileDO.getMatchId())
.eq(CollegeFileDO::getCollegeId, collegeFileDO.getCollegeId()));
if (null == collegeFileDO1) {
this.baseMapper.insert(collegeFileDO);
} else {
copyPropertiesIgnoreNull(collegeFileDO, collegeFileDO1);
this.baseMapper.updateById(collegeFileDO1);
}
return ConstantUtils.SUBMIT_SUCCESS;
}
public RecentFileVO recentFile(CollegeFileDO collegeFileDO) {
RecentFileVO recentFileVO = this.baseMapper.recentFile(collegeFileDO.getCollegeId(),collegeFileDO.getMatchId());
if (null != recentFileVO) {
return recentFileVO;
} else {
return new RecentFileVO();
}
}
public IPage<FileManagementVO> fileManagement(FileManagementDTO fileManagementDTO) {
Page page = new Page(fileManagementDTO.getPageNum(), fileManagementDTO.getPageSize());
IPage<FileManagementVO> fileManagementVOIPage = this.baseMapper.fileManagement(page, fileManagementDTO.getMatchId(), fileManagementDTO.getProjectGroup(), fileManagementDTO.getName());
List<FileManagementVO> records = fileManagementVOIPage.getRecords();
for (FileManagementVO fileManagementVO : records){
//复赛项目数,决赛项目数,市级铜奖,市级银奖,市级金奖
CollegeInfoVO collegeInfoVO = this.baseMapper.collegeInfo(fileManagementVO.getId(), fileManagementDTO.getMatchId());
BeanUtils.copyProperties(collegeInfoVO,fileManagementVO);
}
return fileManagementVOIPage;
}
public static String[] getNullPropertyNames(Object source) {
final BeanWrapper src = new BeanWrapperImpl(source);
java.beans.PropertyDescriptor[] pds = src.getPropertyDescriptors();
Set<String> emptyNames = new HashSet<>();
for (java.beans.PropertyDescriptor pd : pds) {
Object srcValue = src.getPropertyValue(pd.getName());
if (srcValue == null) emptyNames.add(pd.getName());
}
String[] result = new String[emptyNames.size()];
return emptyNames.toArray(result);
}
public static void copyPropertiesIgnoreNull(Object src, Object target) {
BeanUtils.copyProperties(src, target, getNullPropertyNames(src));
}
}