优化项目逻辑

This commit is contained in:
lcj
2025-03-28 18:17:03 +08:00
parent 44b225e7b8
commit 744457179b
7 changed files with 74 additions and 55 deletions

View File

@ -73,12 +73,12 @@ public class BusProject extends BaseEntity {
/**
* 项目类型
*/
private String type;
private String projectType;
/**
* 项目类1光伏 2风电
* 项目类
*/
private String isType;
private String projectCategory;
/**
* 删除时间

View File

@ -53,12 +53,12 @@ public class ProjectCreateReq implements Serializable {
/**
* 项目类型
*/
private String type;
private String projectType;
/**
* 项目类1光伏 2风电
* 项目类
*/
private String isType;
private String projectCategory;
/**
* 项目地址
@ -91,9 +91,14 @@ public class ProjectCreateReq implements Serializable {
private String onStreamTime;
/**
* 打卡范围09:00,18:00
* 打卡时间开始
*/
private String punchRange;
private String playCardStart;
/**
* 打卡时间结束
*/
private String playCardEnd;
/**
* 设计总量

View File

@ -58,12 +58,12 @@ public class ProjectQueryReq implements Serializable {
/**
* 项目类型
*/
private String type;
private String projectType;
/**
* 项目类1光伏 2风电
* 项目类
*/
private String isType;
private String projectCategory;
/**
* 项目地址

View File

@ -63,12 +63,12 @@ public class ProjectUpdateReq implements Serializable {
/**
* 项目类型
*/
private String type;
private String projectType;
/**
* 项目类1光伏 2风电
* 项目类
*/
private String isType;
private String projectCategory;
/**
* 项目地址
@ -101,9 +101,14 @@ public class ProjectUpdateReq implements Serializable {
private String onStreamTime;
/**
* 打卡范围09:00,18:00
* 打卡时间开始
*/
private String punchRange;
private String playCardStart;
/**
* 打卡时间结束
*/
private String playCardEnd;
/**
* 设计总量
@ -119,4 +124,9 @@ public class ProjectUpdateReq implements Serializable {
* 显示隐藏0显示 1隐藏
*/
private String showHidden;
/**
* 排序字段
*/
private Long sort;
}

View File

@ -85,15 +85,16 @@ public class BusProjectVo implements Serializable {
/**
* 项目类型
*/
@ExcelProperty(value = "项目类型")
private String type;
@ExcelProperty(value = "项目类型", converter = ExcelDictConvert.class)
@ExcelDictFormat(dictType = "project_type")
private String projectType;
/**
* 项目类1光伏 2风电
* 项目类
*/
@ExcelProperty(value = "项目类型", converter = ExcelDictConvert.class)
@ExcelDictFormat(readConverterExp = "1=光伏,2=风电")
private String isType;
@ExcelDictFormat(dictType = "project_category_type")
private String projectCategory;
/**
* 项目地址
@ -156,6 +157,11 @@ public class BusProjectVo implements Serializable {
@ExcelDictFormat(readConverterExp = "1=显示,2=隐藏")
private String showHidden;
/**
* 排序字段
*/
private Long sort;
/**
* 创建时间
*/

View File

@ -91,15 +91,19 @@ public class BusProjectServiceImpl extends ServiceImpl<BusProjectMapper, BusProj
/**
* 新增项目
*
* @param dto 项目
* @param req 项目
* @return 新项目 id
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Long insertByBo(ProjectCreateReq dto) {
public Long insertByBo(ProjectCreateReq req) {
// 将实体类和 DTO 进行转换
BusProject project = new BusProject();
BeanUtils.copyProperties(dto, project);
BeanUtils.copyProperties(req, project);
String playCardStart = req.getPlayCardStart();
String playCardEnd = req.getPlayCardEnd();
String punchRange = playCardStart + "," + playCardEnd;
project.setPunchRange(punchRange);
// 数据校验
validEntityBeforeSave(project, true);
// 写入数据库
@ -136,10 +140,17 @@ public class BusProjectServiceImpl extends ServiceImpl<BusProjectMapper, BusProj
// 将实体类和 DTO 进行转换
BusProject project = new BusProject();
BeanUtils.copyProperties(req, project);
String playCardStart = req.getPlayCardStart();
String playCardEnd = req.getPlayCardEnd();
if (StringUtils.isNotBlank(playCardStart) && StringUtils.isNotBlank(playCardEnd)){
String punchRange = playCardStart + "," + playCardEnd;
project.setPunchRange(punchRange);
}
// 数据校验
validEntityBeforeSave(project, false);
// 权限校验
validPermission(project);
Long userId = LoginHelper.getUserId();
validAuth(project.getId(), userId);
// 判断是否存在
BusProject oldProject = this.getById(project.getId());
if (oldProject == null) {
@ -163,22 +174,6 @@ public class BusProjectServiceImpl extends ServiceImpl<BusProjectMapper, BusProj
}
}
/**
* 权限判断
*/
private void validPermission(BusProject entity) {
Long entityId = entity.getId();
// 获取当前登录用户
Long userId = LoginHelper.getUserId();
// 判断是否存在项目与登录用户关联
QueryWrapper<BusUserProjectRelevancy> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("project_id", entityId);
queryWrapper.eq("user_id", userId);
if (userProjectRelevancyService.count(queryWrapper) <= 0) {
throw new ServiceException("当前用户无权限操作", HttpStatus.FORBIDDEN);
}
}
/**
* 校验并批量删除项目信息
*
@ -245,8 +240,8 @@ public class BusProjectServiceImpl extends ServiceImpl<BusProjectMapper, BusProj
Long pId = req.getPId();
String status = req.getStatus();
String remark = req.getRemark();
String type = req.getType();
String isType = req.getIsType();
String projectType = req.getProjectType();
String projectCategory = req.getProjectCategory();
String projectSite = req.getProjectSite();
String principal = req.getPrincipal();
String principalPhone = req.getPrincipalPhone();
@ -260,7 +255,6 @@ public class BusProjectServiceImpl extends ServiceImpl<BusProjectMapper, BusProj
lqw.like(StringUtils.isNotBlank(projectName), BusProject::getProjectName, projectName);
lqw.like(StringUtils.isNotBlank(shortName), BusProject::getShortName, shortName);
lqw.like(StringUtils.isNotBlank(remark), BusProject::getRemark, remark);
lqw.like(StringUtils.isNotBlank(type), BusProject::getType, type);
lqw.like(StringUtils.isNotBlank(projectSite), BusProject::getProjectSite, projectSite);
lqw.like(StringUtils.isNotBlank(principal), BusProject::getPrincipal, principal);
lqw.like(StringUtils.isNotBlank(principalPhone), BusProject::getPrincipalPhone, principalPhone);
@ -272,9 +266,11 @@ public class BusProjectServiceImpl extends ServiceImpl<BusProjectMapper, BusProj
lqw.eq(ObjectUtils.isNotEmpty(pId), BusProject::getPId, pId);
lqw.eq(ObjectUtils.isNotEmpty(status), BusProject::getStatus, status);
lqw.eq(ObjectUtils.isNotEmpty(id), BusProject::getId, id);
lqw.eq(ObjectUtils.isNotEmpty(isType), BusProject::getIsType, isType);
lqw.eq(ObjectUtils.isNotEmpty(projectType), BusProject::getProjectType, projectType);
lqw.eq(ObjectUtils.isNotEmpty(projectCategory), BusProject::getProjectCategory, projectCategory);
lqw.eq(ObjectUtils.isNotEmpty(designTotal), BusProject::getDesignTotal, designTotal);
lqw.eq(ObjectUtils.isNotEmpty(showHidden), BusProject::getShowHidden, showHidden);
lqw.orderByAsc(BusProject::getSort);
return lqw;
}
@ -304,7 +300,7 @@ public class BusProjectServiceImpl extends ServiceImpl<BusProjectMapper, BusProj
queryWrapper.eq("project_id", projectId);
queryWrapper.eq("user_id", userId);
if (userProjectRelevancyService.count(queryWrapper) <= 0) {
throw new ServiceException("无该项目权限操作", HttpStatus.FORBIDDEN);
throw new ServiceException("当前用户无该项目权限操作", HttpStatus.FORBIDDEN);
}
}

View File

@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
@ -123,11 +124,12 @@ public class BusProjectTeamMemberServiceImpl extends ServiceImpl<BusProjectTeamM
throw new ServiceException("新增项目班组下的成员失败,数据库异常", HttpStatus.ERROR);
}
// 同步修改用户表的team_id字段并添加入场时间
BusConstructionUser constructionUser = new BusConstructionUser();
constructionUser.setId(projectTeamMember.getMemberId());
constructionUser.setTeamId(projectTeamMember.getTeamId());
constructionUser.setEntryDate(new Date());
constructionUserService.updateById(constructionUser);
LambdaUpdateWrapper<BusConstructionUser> constructionUserLuw = Wrappers.lambdaUpdate(BusConstructionUser.class)
.eq(BusConstructionUser::getId, projectTeamMember.getMemberId())
.set(BusConstructionUser::getTeamId, projectTeamMember.getTeamId())
.set(BusConstructionUser::getEntryDate, new Date())
.set(BusConstructionUser::getLeaveDate, null);
constructionUserService.update(constructionUserLuw);
return projectTeamMember.getId();
}
@ -151,10 +153,10 @@ public class BusProjectTeamMemberServiceImpl extends ServiceImpl<BusProjectTeamM
throw new ServiceException("修改项目班组下的成员,数据不存在", HttpStatus.NOT_FOUND);
}
// 同步修改用户表的team_id字段
BusConstructionUser constructionUser = new BusConstructionUser();
constructionUser.setId(projectTeamMember.getMemberId());
constructionUser.setTeamId(projectTeamMember.getTeamId());
constructionUserService.updateById(constructionUser);
LambdaUpdateWrapper<BusConstructionUser> constructionUserLuw = Wrappers.lambdaUpdate(BusConstructionUser.class)
.eq(BusConstructionUser::getId, projectTeamMember.getMemberId())
.set(BusConstructionUser::getTeamId, projectTeamMember.getTeamId());
constructionUserService.update(constructionUserLuw);
// 操作数据库
return this.updateById(projectTeamMember);
}