1.图片集修改信息问题处理、优化

2.我的项目任务增加查询条件
3.项目信息查询sql优化
This commit is contained in:
cuizhibin 2025-07-27 16:21:30 +08:00
parent 1805dfc0d8
commit 0f971f4689
7 changed files with 52 additions and 33 deletions

View File

@ -47,7 +47,7 @@ public class Schedule {
List<ImageEntity> successList = new ArrayList<>();
for (ImageEntity image : list) {
PartResp partResp = partRespMap.get(image.getPartId());
FilePathEnum pathEnum = image.getImagePath().contains("temp") ? FilePathEnum.IMAGE_TEMP : FilePathEnum.IMAGE;
FilePathEnum pathEnum = FilePathEnum.getFilePathEnum(image.getImagePath());
String inputFile = pathEnum.getFileAbsolutePath(image.getImagePath());
String outputDir = FilePathEnum.IMAGE.getFileAbsolutePathPrefix()
.concat("已调整")

View File

@ -55,4 +55,23 @@ public enum FilePathEnum {
return StrUtil.replace(urlPath.concat(relativePath), FileUtil.FILE_SEPARATOR, StrUtil.SLASH);
}
/**
* 功能描述根据文件路径前缀获取文件路径ENUM
*
* @param fileDownPath 文件路径
* @return {@link FilePathEnum }
* @author cuizhibin
* @date 2025/07/27 16:00
**/
public static FilePathEnum getFilePathEnum(String fileDownPath) {
if (StrUtil.startWith(fileDownPath, FilePathEnum.IMAGE_TEMP.getUrlPath())) {
return FilePathEnum.IMAGE_TEMP;
}
for (FilePathEnum pathEnum : FilePathEnum.values()) {
if (StrUtil.startWith(fileDownPath, FilePathEnum.IMAGE_TEMP.getUrlPath())) {
return pathEnum;
}
}
return FilePathEnum.ATTACH;
}
}

View File

@ -198,7 +198,7 @@ public class DefectServiceImpl extends ServiceImpl<DefectMapper, DefectEntity> i
}
image.setImageType(ImageTypeEnum.DEFECT.getCode());
imageService.updateById(image);
FilePathEnum pathEnum = image.getImagePath().contains("temp") ? FilePathEnum.IMAGE_TEMP : FilePathEnum.IMAGE;
FilePathEnum pathEnum = FilePathEnum.getFilePathEnum(image.getImagePath());
String inputPath = pathEnum.getFileAbsolutePath(image.getImagePath());
// 写入attach同层级文件夹下
String attachPath = FilePathEnum.ATTACH.getUrlPath() + StrUtil.removePrefix(image.getImagePath(), pathEnum.getUrlPath());

View File

@ -8,8 +8,8 @@ import com.dite.znpt.converts.Converts;
import com.dite.znpt.domain.entity.ImageCollectEntity;
import com.dite.znpt.domain.entity.ImageEntity;
import com.dite.znpt.domain.vo.ImageCollectReq;
import com.dite.znpt.domain.vo.ImageReq;
import com.dite.znpt.enums.FilePathEnum;
import com.dite.znpt.enums.ImageSourceEnum;
import com.dite.znpt.exception.ServiceException;
import com.dite.znpt.mapper.ImageCollectMapper;
import com.dite.znpt.service.ImageCollectService;
@ -20,9 +20,10 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.io.File;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* @Author: gaoxiong
@ -49,21 +50,21 @@ public class ImageCollectServiceImpl extends ServiceImpl<ImageCollectMapper, Ima
}
ImageCollectEntity imageCollect = Converts.INSTANCE.toImageCollectEntity(req);
this.save(imageCollect);
String dateStr = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
List<ImageEntity> imageList = Converts.INSTANCE.toImageEntity(req.getImageList());
String permPathPrefix = FilePathEnum.IMAGE.getFileAbsolutePathPrefix().concat(ImageSourceEnum.COLLECT.getCode()).concat(FileUtil.FILE_SEPARATOR).concat(partId).concat(FileUtil.FILE_SEPARATOR).concat(dateStr).concat(FileUtil.FILE_SEPARATOR);
Map<String, ImageReq> imageMap = req.getImageList().stream().collect(Collectors.toMap(ImageReq::getImageId, Function.identity(), (a,b) -> b));
List<ImageEntity> imageList = imageService.listByIds(imageMap.keySet());
imageList.forEach(image -> {
image.setPartId(partId);
image.setCollectId(imageCollect.getCollectId());
image.setImageType(req.getImageType());
image.setImageTypeLabel(req.getImageTypeLabel());
String path = permPathPrefix + image.getImageName();
String fileAbsolutePath = FilePathEnum.IMAGE_TEMP.getFileAbsolutePath(image.getImagePath());
File file = FileUtil.file(fileAbsolutePath);
if (file.exists()) {
FileUtil.copy(file, FileUtil.file(path), true);
image.setImagePath(FilePathEnum.IMAGE.getFileDownPath(path));
FileUtil.del(file);
if (FilePathEnum.getFilePathEnum(image.getImagePath()).equals(FilePathEnum.IMAGE_TEMP)) {
String newImagePath = image.getImagePath().replace(FilePathEnum.IMAGE_TEMP.getUrlPath(), FilePathEnum.IMAGE.getUrlPath());
String oldFileAbsolutePath = FilePathEnum.IMAGE_TEMP.getFileAbsolutePath(image.getImagePath());
File oldFile = FileUtil.file(oldFileAbsolutePath);
if (oldFile.exists()) {
FileUtil.move(oldFile, FileUtil.file(newImagePath), true);
image.setImagePath(newImagePath);
}
}
});
imageService.saveOrUpdateBatch(imageList);

View File

@ -296,7 +296,7 @@ public class ImageServiceImpl extends ServiceImpl<ImageMapper, ImageEntity> impl
if(CollUtil.isEmpty(imageList)){
imageCollectService.removeById(image.getCollectId());
}
FilePathEnum pathEnum = image.getImagePath().contains("temp") ? FilePathEnum.IMAGE_TEMP : FilePathEnum.IMAGE;
FilePathEnum pathEnum = FilePathEnum.getFilePathEnum(image.getImagePath());
FileUtil.del(pathEnum.getFileAbsolutePath(image.getImagePath()));
FileUtil.del(FilePathEnum.IMAGE.getFileAbsolutePath(image.getPreImagePath()));
}

View File

@ -2,23 +2,27 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.dite.znpt.mapper.ProjectMapper">
<select id="queryBySelective" resultType="com.dite.znpt.domain.vo.ProjectListResp">
with taskProgress as (
SELECT
count(1) task_count,
sum(status=0) taskPendingCount,
sum(status=1) task_progress_count,
sum(status=2) task_complete_count,
project_id
FROM project_task
group by project_id
with taskProgress as (SELECT count(1) task_count,
sum(status = 0) taskPendingCount,
sum(status = 1) task_progress_count,
sum(status = 2) task_complete_count,
project_id
FROM project_task
group by project_id),
constructor as (
select project_id, GROUP_CONCAT(DISTINCT con.name) AS constructor_name
FROM project prj
LEFT JOIN user con ON FIND_IN_SET(con.user_id,prj.constructor_ids) > 0 AND con.del_flag = '0'
GROUP BY prj.project_id
)
SELECT
prj.project_id, prj.project_name, prj.farm_name, prj.status, prj.cover_url, prj.farm_address, prj.client, prj.client_contact, prj.client_phone, prj.inspection_unit,
prj.inspection_contact, prj.inspection_phone, prj.scale, prj.turbine_model, prj.project_manager_id, pm.name AS project_manager_name, prj.constructor_ids,
GROUP_CONCAT(DISTINCT con.name) AS constructor_name, prj.start_date, prj.end_date, tp.taskPendingCount, tp.task_progress_count, tp.task_complete_count, tp.task_count
prj.start_date, prj.end_date, con.constructor_name, tp.taskPendingCount, tp.task_progress_count, tp.task_complete_count, tp.task_count, prj.auditor_id,
prj.construct_team_leader_id, prj.quality_officer_id
FROM project prj
LEFT JOIN user pm ON pm.user_id = prj.project_manager_id
LEFT JOIN user con ON FIND_IN_SET(con.user_id,prj.constructor_ids) > 0 AND con.del_flag = '0'
LEFT JOIN constructor con on prj.project_id = con.project_id
left join taskProgress tp on prj.project_id = tp.project_id
<where>
<if test="projectName != null and projectName != ''">
@ -48,9 +52,6 @@
or prj.constructor_ids like concat('%', #{userId},'%'))
</if>
</where>
GROUP BY prj.project_id, prj.project_name, prj.farm_name, prj.status, prj.cover_url, prj.farm_address, prj.client, prj.client_contact, prj.client_phone, prj.inspection_unit,
prj.inspection_contact, prj.inspection_phone, prj.scale, prj.turbine_model, prj.project_manager_id, pm.name, prj.constructor_ids,
prj.start_date, prj.end_date, tp.taskPendingCount, tp.task_progress_count, tp.task_complete_count, tp.task_count
</select>
</mapper>

View File

@ -5,7 +5,6 @@ import cn.dev33.satoken.stp.StpUtil;
import com.dite.znpt.constant.Constants;
import com.dite.znpt.domain.PageResult;
import com.dite.znpt.domain.Result;
import com.dite.znpt.domain.entity.ProjectTaskEntity;
import com.dite.znpt.domain.vo.*;
import com.dite.znpt.service.ProjectTaskService;
import com.dite.znpt.util.PageUtil;
@ -102,8 +101,7 @@ public class ProjectTaskController {
@ApiOperation(value = "查询我的任务", httpMethod = "GET")
@GetMapping("/my")
public Result<List<ProjectTaskResp>> my() {
ProjectTaskListReq req = new ProjectTaskListReq();
public Result<List<ProjectTaskResp>> my(ProjectTaskListReq req) {
req.setUserId(StpUtil.getLoginIdAsString());
return Result.ok(projectTaskService.selectList(req));
}