优化
This commit is contained in:
@ -16,6 +16,8 @@ import io.swagger.annotations.ApiOperation;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@ -27,6 +29,7 @@ import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
@ -38,23 +41,18 @@ import java.util.zip.ZipInputStream;
|
||||
@Api(value = "网页模板上传", tags = {"网页模板上传"})
|
||||
@RequiredArgsConstructor(onConstructor_ = @Autowired)
|
||||
@RestController()
|
||||
@EnableAsync
|
||||
public class UploadZipController {
|
||||
|
||||
|
||||
private final IWgzUserService wgzUserService;
|
||||
|
||||
private final IBgtProjectRecruitService recruitService;
|
||||
|
||||
private final IAnnexService annexService;
|
||||
|
||||
private final IAnnexRecordService annexRecordService;
|
||||
|
||||
private static final String TEMP_DIR = "ruoyi/uploadPath/temporaryZip";
|
||||
|
||||
private static final String SAVE_DIR = "ruoyi/uploadPath/recruit";
|
||||
private static final String RECORD_DIR = "ruoyi/uploadPath/record";
|
||||
|
||||
|
||||
@ApiOperation("上传压缩文件")
|
||||
@PostMapping("/upload-zip")
|
||||
public ResponseEntity<String> uploadZipFile(@RequestParam("file") MultipartFile file, @RequestParam("recruitId") Long recruitId) {
|
||||
@ -80,14 +78,11 @@ public class UploadZipController {
|
||||
// 处理解压后的文件夹
|
||||
processExtractedFolder(extractDir, recruitId);
|
||||
|
||||
// 将解压后的文件移动到 SAVE_DIR 和 RECORD_DIR
|
||||
// 将解压后的文件移动到 SAVE_DIR
|
||||
moveFilesToSaveDir(extractDir, recruitId);
|
||||
|
||||
// 删除临时文件和文件夹
|
||||
deleteFolder(extractDir);
|
||||
if (!zipFile.delete()) {
|
||||
System.err.println("无法删除压缩文件: " + zipFile.getAbsolutePath());
|
||||
}
|
||||
// 异步执行 RECORD_DIR 操作和删除临时文件操作
|
||||
asyncProcessRecordAndDeleteTemp(extractDir, zipFile, recruitId,SecurityUtils.getUsername(),SecurityUtils.getAppUserId());
|
||||
|
||||
return ResponseEntity.ok("文件上传并处理成功");
|
||||
} catch (IOException e) {
|
||||
@ -96,6 +91,36 @@ public class UploadZipController {
|
||||
}
|
||||
}
|
||||
|
||||
@Async
|
||||
public CompletableFuture<Void> asyncProcessRecordAndDeleteTemp(File extractDir, File zipFile, Long recruitId,String username,Long userId) {
|
||||
return CompletableFuture.runAsync(() -> {
|
||||
try {
|
||||
// 移动到 RECORD_DIR
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
|
||||
String timeStamp = LocalDateTime.now().format(formatter);
|
||||
BgtProjectRecruit recruit = recruitService.queryById(recruitId);
|
||||
String firstLevelFolderName = recruit.getId() + "_" + recruit.getRecruitName();
|
||||
File recordDestDir = new File(RECORD_DIR, firstLevelFolderName);
|
||||
ensureDirectoryExists(recordDestDir);
|
||||
|
||||
List<AnnexRecord> annexRecordList = new ArrayList<>();
|
||||
moveFilesToRecordDirRecursively(extractDir, recordDestDir, timeStamp, annexRecordList, recruitId,username,userId);
|
||||
|
||||
if (CollectionUtil.isNotEmpty(annexRecordList)) {
|
||||
annexRecordService.saveBatch(annexRecordList);
|
||||
}
|
||||
|
||||
// 删除临时文件和文件夹
|
||||
deleteFolder(extractDir);
|
||||
if (!zipFile.delete()) {
|
||||
System.err.println("无法删除压缩文件: " + zipFile.getAbsolutePath());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void ensureDirectoryExists(File directory) throws IOException {
|
||||
if (!directory.exists()) {
|
||||
if (!directory.mkdirs()) {
|
||||
@ -143,6 +168,13 @@ public class UploadZipController {
|
||||
|
||||
private void processExtractedFolder(File extractDir, Long recruitId) {
|
||||
File[] firstLevelFiles = extractDir.listFiles();
|
||||
|
||||
// 保险 2
|
||||
List<Long> insurance = new ArrayList<>();
|
||||
|
||||
// 劳务合同 1
|
||||
List<Long> contract = new ArrayList<>();
|
||||
|
||||
if (firstLevelFiles != null) {
|
||||
for (File firstLevelFile : firstLevelFiles) {
|
||||
String firstLevelFolderName = firstLevelFile.getName();
|
||||
@ -159,12 +191,12 @@ public class UploadZipController {
|
||||
if (secondLevelFile.isDirectory()) {
|
||||
File[] thirdLevelFiles = secondLevelFile.listFiles();
|
||||
if (thirdLevelFiles != null) {
|
||||
//删除数据库里的附件
|
||||
if("保险".equals(secondLevelFolderName)){
|
||||
annexService.deleteByUserIdAndRecruitIdAndType(wgzUser.getUserId(), recruitId, "2");
|
||||
// 删除数据库里的附件
|
||||
if ("保险".equals(secondLevelFolderName)) {
|
||||
insurance.add(wgzUser.getUserId());
|
||||
}
|
||||
if("劳务合同".equals(secondLevelFolderName)){
|
||||
annexService.deleteByUserIdAndRecruitIdAndType(wgzUser.getUserId(), recruitId, "1");
|
||||
if ("劳务合同".equals(secondLevelFolderName)) {
|
||||
contract.add(wgzUser.getUserId());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -173,6 +205,12 @@ public class UploadZipController {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(insurance)) {
|
||||
annexService.deleteByUserIdAndRecruitIdAndType(insurance, recruitId, "2");
|
||||
}
|
||||
if (CollectionUtil.isNotEmpty(contract)) {
|
||||
annexService.deleteByUserIdAndRecruitIdAndType(contract, recruitId, "1");
|
||||
}
|
||||
}
|
||||
|
||||
private void moveFilesToSaveDir(File sourceDir, Long recruitId) throws IOException {
|
||||
@ -196,36 +234,23 @@ public class UploadZipController {
|
||||
// 删除和解压出来的二级目录同名字的目录
|
||||
deleteFolder(secondLevelDestDir);
|
||||
}
|
||||
moveFilesRecursively(firstLevelFile, firstLevelDestDir,annexList,recruitId);
|
||||
moveFilesRecursively(firstLevelFile, firstLevelDestDir, annexList, recruitId);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(CollectionUtil.isNotEmpty(annexList)){
|
||||
if (CollectionUtil.isNotEmpty(annexList)) {
|
||||
annexService.saveBatch(annexList);
|
||||
}
|
||||
|
||||
// 移动到 RECORD_DIR
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
|
||||
String timeStamp = LocalDateTime.now().format(formatter);
|
||||
File recordDestDir = new File(RECORD_DIR, firstLevelFolderName);
|
||||
ensureDirectoryExists(recordDestDir);
|
||||
|
||||
List<AnnexRecord> annexRecordList = new ArrayList<>();
|
||||
moveFilesToRecordDirRecursively(sourceDir, recordDestDir, timeStamp,annexRecordList,recruitId);
|
||||
|
||||
if(CollectionUtil.isNotEmpty(annexRecordList)){
|
||||
annexRecordService.saveBatch(annexRecordList);
|
||||
}
|
||||
}
|
||||
|
||||
private void moveFilesRecursively(File source, File destination,List<Annex> annexList,Long recruitId) throws IOException {
|
||||
private void moveFilesRecursively(File source, File destination, List<Annex> annexList, Long recruitId) throws IOException {
|
||||
if (source.isDirectory()) {
|
||||
File newDir = new File(destination, source.getName());
|
||||
ensureDirectoryExists(newDir);
|
||||
File[] files = source.listFiles();
|
||||
if (files != null) {
|
||||
for (File file : files) {
|
||||
moveFilesRecursively(file, newDir,annexList,recruitId);
|
||||
moveFilesRecursively(file, newDir, annexList, recruitId);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -242,21 +267,21 @@ public class UploadZipController {
|
||||
String relativePath = SAVE_DIR + File.separator + getRelativePath(source, new File(TEMP_DIR));
|
||||
relativePath = relativePath.replace("\\", "/").replace("ruoyi/uploadPath", "/profile");
|
||||
System.out.println("文件在项目里的相对目录: " + relativePath);
|
||||
//存到数据库
|
||||
String parentName= destination.getParentFile().getName();
|
||||
System.out.println("上上一级文件名: "+parentName);
|
||||
// 存到数据库
|
||||
String parentName = destination.getParentFile().getName();
|
||||
System.out.println("上上一级文件名: " + parentName);
|
||||
String[] split = parentName.split("_");
|
||||
String card = split[1];
|
||||
WgzUser wgzUser = wgzUserService.findByIdentityCard(card);
|
||||
|
||||
String name = destination.getName();
|
||||
System.out.println("上一级文件名: "+name);
|
||||
System.out.println("上一级文件名: " + name);
|
||||
String type = "";
|
||||
if("保险".equals(name)){
|
||||
type= "2";
|
||||
if ("保险".equals(name)) {
|
||||
type = "2";
|
||||
}
|
||||
if("劳务合同".equals(name)){
|
||||
type="1";
|
||||
if ("劳务合同".equals(name)) {
|
||||
type = "1";
|
||||
}
|
||||
Annex annex = new Annex();
|
||||
annex.setAnnexName(destFile.getName());
|
||||
@ -268,20 +293,19 @@ public class UploadZipController {
|
||||
annex.setCreateBy(SecurityUtils.getUsername());
|
||||
annex.setUpdateBy(SecurityUtils.getUsername());
|
||||
annexList.add(annex);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void moveFilesToRecordDirRecursively(File source, File destination, String timeStamp, List<AnnexRecord> annexRecordList, Long recruitId) throws IOException {
|
||||
private void moveFilesToRecordDirRecursively(File source, File destination, String timeStamp, List<AnnexRecord> annexRecordList, Long recruitId,String username,Long userId) throws IOException {
|
||||
if (source.isDirectory()) {
|
||||
String folderName = source.getName();
|
||||
String[] parts = folderName.split("_");
|
||||
if (parts.length > 0 && parts[0].matches("\\d+") && parts.length > 1) {
|
||||
if (parts.length > 0 && parts[0].matches("\\d+") && parts.length > 1 && parts[0].equals(recruitId.toString())) {
|
||||
// 如果parts第一部分是数字并且长度大于1,跳过这一级目录的创建,直接处理下一级目录
|
||||
File[] files = source.listFiles();
|
||||
if (files != null) {
|
||||
for (File file : files) {
|
||||
moveFilesToRecordDirRecursively(file, destination, timeStamp,annexRecordList,recruitId);
|
||||
moveFilesToRecordDirRecursively(file, destination, timeStamp, annexRecordList, recruitId,username,userId);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -293,7 +317,7 @@ public class UploadZipController {
|
||||
File[] files = source.listFiles();
|
||||
if (files != null) {
|
||||
for (File file : files) {
|
||||
moveFilesToRecordDirRecursively(file, newDir, timeStamp,annexRecordList,recruitId);
|
||||
moveFilesToRecordDirRecursively(file, newDir, timeStamp, annexRecordList, recruitId,username,userId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -308,25 +332,25 @@ public class UploadZipController {
|
||||
out.write(buffer, 0, length);
|
||||
}
|
||||
}
|
||||
String relativePath = RECORD_DIR + File.separator + getRelativePath(source, new File(TEMP_DIR));
|
||||
String relativePath = RECORD_DIR + File.separator +timeStamp+ getRelativePath(source, new File(TEMP_DIR));
|
||||
relativePath = relativePath.replace("\\", "/").replace("ruoyi/uploadPath", "/profile");
|
||||
System.out.println("文件在记录目录里的相对目录: " + relativePath);
|
||||
|
||||
//存到数据库作为记录
|
||||
String parentName= destination.getParentFile().getName();
|
||||
System.out.println("上上一级文件名: "+parentName);
|
||||
// 存到数据库作为记录
|
||||
String parentName = destination.getParentFile().getName();
|
||||
System.out.println("上上一级文件名: " + parentName);
|
||||
String[] split = parentName.split("_");
|
||||
String card = split[1];
|
||||
WgzUser wgzUser = wgzUserService.findByIdentityCard(card);
|
||||
|
||||
String name = destination.getName();
|
||||
System.out.println("上一级文件名: "+name);
|
||||
System.out.println("上一级文件名: " + name);
|
||||
String type = "";
|
||||
if("保险".equals(name)){
|
||||
type= "2";
|
||||
if ("保险".equals(name)) {
|
||||
type = "2";
|
||||
}
|
||||
if("劳务合同".equals(name)){
|
||||
type="1";
|
||||
if ("劳务合同".equals(name)) {
|
||||
type = "1";
|
||||
}
|
||||
AnnexRecord annex = new AnnexRecord();
|
||||
annex.setAnnexName(destFile.getName());
|
||||
@ -335,12 +359,11 @@ public class UploadZipController {
|
||||
annex.setUserType(Constants.WGZ);
|
||||
annex.setUserId(wgzUser.getUserId());
|
||||
annex.setRecruitId(recruitId);
|
||||
annex.setCreateBy(SecurityUtils.getUsername());
|
||||
annex.setUpdateBy(SecurityUtils.getUsername());
|
||||
annex.setCreateUserId(SecurityUtils.getAppUserId());
|
||||
annex.setCreateBy(username);
|
||||
annex.setUpdateBy(username);
|
||||
annex.setCreateUserId(userId);
|
||||
annex.setCreateUserType(Constants.BGT);
|
||||
annexRecordList.add(annex);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -180,8 +180,11 @@ public class BgtMessageServiceImpl extends ServicePlusImpl<BgtMessageMapper, Bgt
|
||||
bgtMessageCountVO.setTaskMessageCount(map.getOrDefault(BgtMessageType.TASK.getCode(), 0L).intValue());
|
||||
bgtMessageCountVO.setSettlementMessageCount(map.getOrDefault(BgtMessageType.SETTLEMENT.getCode(), 0L).intValue());
|
||||
bgtMessageCountVO.setOtherMessageCount(map.getOrDefault(BgtMessageType.OTHER.getCode(), 0L).intValue());
|
||||
List<BgtMessage> handleList = bgtMessages.stream().filter(bgtMessage -> OPERATION_NEED.equals(bgtMessage.getIsOperation())).collect(Collectors.toList());
|
||||
bgtMessageCountVO.setHandleMessageCount(handleList.size());
|
||||
|
||||
Integer handle = baseMapper.selectCount(Wrappers.<BgtMessage>lambdaQuery()
|
||||
.eq(BgtMessage::getRecipientId, SecurityUtils.getAppUserId())
|
||||
.eq(BgtMessage::getIsOperation, OPERATION_NEED));
|
||||
bgtMessageCountVO.setHandleMessageCount(handle);
|
||||
return bgtMessageCountVO;
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,7 @@ public interface IAnnexService extends IServicePlus<Annex> {
|
||||
/**
|
||||
* 根据务工者唯一标识+招工标识+附件类型 删除文件
|
||||
*/
|
||||
void deleteByUserIdAndRecruitIdAndType(Long userId,Long recruitId,String type);
|
||||
void deleteByUserIdAndRecruitIdAndType(List<Long> userIds,Long recruitId,String type);
|
||||
|
||||
/**
|
||||
* 检查入场材料
|
||||
|
@ -158,8 +158,8 @@ public class AnnexServiceImpl extends ServicePlusImpl<AnnexMapper, Annex> implem
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteByUserIdAndRecruitIdAndType(Long userId, Long recruitId, String type) {
|
||||
baseMapper.delete(Wrappers.<Annex>lambdaQuery().eq(Annex::getUserId,userId)
|
||||
public void deleteByUserIdAndRecruitIdAndType(List<Long> userIds, Long recruitId, String type) {
|
||||
baseMapper.delete(Wrappers.<Annex>lambdaQuery().in(Annex::getUserId,userIds)
|
||||
.eq(Annex::getRecruitId,recruitId).eq(Annex::getAnnexType,type).eq(Annex::getUserType,WGZ));
|
||||
}
|
||||
|
||||
|
@ -208,6 +208,7 @@ public class FbsProjectTaskServiceImpl extends ServicePlusImpl<FbsProjectTaskMap
|
||||
List<BgtDayAttendanceCountVO> countVOS = attendanceService.countDayByTaskId(id, startTime, date);
|
||||
// 补充缺失的天数
|
||||
List<BgtDayAttendanceCountVO> bgtDayAttendanceCountVOS = DataUtil.fillMissingDates(countVOS, startTime, date);
|
||||
appTaskDetailVO.setCountVOS(bgtDayAttendanceCountVOS);
|
||||
//查询当天的总人数
|
||||
Integer totalNum = attendanceService.dayTotalNum(id, date);
|
||||
appTaskDetailVO.setTotalNum(totalNum);
|
||||
|
@ -42,6 +42,8 @@ import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.text.DecimalFormat;
|
||||
import java.time.*;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
@ -470,6 +472,12 @@ public class WgzAttendanceServiceImpl extends ServicePlusImpl<WgzAttendanceMappe
|
||||
if(CollectionUtil.isNotEmpty(countVOS)){
|
||||
bgtAttendanceVO.setReportToDutyNum(countVOS.get(0).getReportToDutyNum());
|
||||
}
|
||||
//今日到岗率
|
||||
if(bgtAttendanceVO.getReportToDutyNum()!=0){
|
||||
int rate = new BigDecimal(totalNum).divide(new BigDecimal(bgtAttendanceVO.getReportToDutyNum()), 2, RoundingMode.HALF_UP)
|
||||
.multiply(new BigDecimal(100)).intValue();
|
||||
bgtAttendanceVO.setReportToDutyRate(rate);
|
||||
}
|
||||
|
||||
//缺勤人数
|
||||
bgtAttendanceVO.setAbsenceDutyNum(totalNum-bgtAttendanceVO.getReportToDutyNum());
|
||||
@ -738,7 +746,7 @@ public class WgzAttendanceServiceImpl extends ServicePlusImpl<WgzAttendanceMappe
|
||||
} else if (clockInTime == null && clockOutTime == null) {
|
||||
recordVO.setDay(0D);
|
||||
} else {
|
||||
recordVO.setDay(0.5D);
|
||||
recordVO.setDay(1D);
|
||||
records.add(recordVO);
|
||||
}
|
||||
//统计迟到天数
|
||||
|
@ -364,7 +364,7 @@ public class WgzDailyClockServiceImpl extends ServicePlusImpl<WgzDailyClockMappe
|
||||
public Boolean appUpdate(BgtDailyClockUpdateDTO dto) {
|
||||
|
||||
WgzDailyClock dailyClock = getById(dto.getId());
|
||||
if(dailyClock.getAuditorUserId() == null){
|
||||
if(dailyClock == null){
|
||||
throw new RuntimeException("日报数据不存在!");
|
||||
}
|
||||
BeanUtil.copyProperties(dto,dailyClock);
|
||||
@ -372,7 +372,7 @@ public class WgzDailyClockServiceImpl extends ServicePlusImpl<WgzDailyClockMappe
|
||||
dailyClock.setAuditorTime(LocalDateTime.now());
|
||||
|
||||
//补卡需要发消息
|
||||
if("1".equals(dailyClock.getStatus())){
|
||||
if("1".equals(dailyClock.getStatus()) && AuditStatus.getAudit().contains(dto.getAuditorType())){
|
||||
|
||||
BgtProjectRecruit recruit = iBgtProjectRecruitService.getById(dailyClock.getRecruitId());
|
||||
HashMap<String, String> mp = new HashMap<>();
|
||||
|
@ -600,7 +600,7 @@ public class WgzPayCalculationServiceImpl extends ServicePlusImpl<WgzPayCalculat
|
||||
BgtProjectRecruitApply recruitApply = iBgtProjectRecruitApplyService.getOneByUserIdAndRecruitId(userId, recruitId);
|
||||
vo.setEntryTime(recruitApply.getEntryTime());
|
||||
vo.setLeaveTime(recruitApply.getLeaveTime());
|
||||
vo.setWorkingState(recruitApply.getStatus());
|
||||
vo.setWorkingState(recruitApply.getStatus().equals("5")?"1":"2");
|
||||
|
||||
//出勤天数
|
||||
//总天数
|
||||
|
@ -205,7 +205,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
AND bpra.status != '0'
|
||||
</if>
|
||||
</where>
|
||||
order by bpra.create_time desc
|
||||
order by wu.score,bpra.create_time desc
|
||||
</select>
|
||||
|
||||
|
||||
|
@ -51,6 +51,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="bank" column="bank"/>
|
||||
<result property="cardNo" column="card_no"/>
|
||||
<result property="auditorUserId" column="auditor_user_id"/>
|
||||
<result property="auditorUserName" column="auditor_user_name"/>
|
||||
<result property="auditorType" column="auditor_type"/>
|
||||
<result property="auditorOpinion" column="auditor_opinion"/>
|
||||
<result property="auditorTime" column="auditor_time"/>
|
||||
|
Reference in New Issue
Block a user