From 77c72dae9d34092a432ea91e6492176b7b0a5007 Mon Sep 17 00:00:00 2001 From: PoffyZhang <99775271@qq.com> Date: Thu, 20 Apr 2023 10:26:20 +0800 Subject: [PATCH] debug --- .../pmapi/projectlib/manage/ProjectLibManage.java | 34 ++++++++++++++-------- .../pmapi/statemachine/StateMachineTest.java | 12 +++++++- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/manage/ProjectLibManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/manage/ProjectLibManage.java index 356ea3c..006964d 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/manage/ProjectLibManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/projectlib/manage/ProjectLibManage.java @@ -1,5 +1,7 @@ package com.ningdatech.pmapi.projectlib.manage; +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.bean.copier.CopyOptions; import cn.hutool.core.collection.CollUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; @@ -260,13 +262,15 @@ public class ProjectLibManage { * 新增一个新的项目 新的版本号 */ public Project newProjectWithVersion(ProjectDTO projecDto){ - Project project = projectService.getById(projecDto.getId()); - - VUtils.isTrue(Objects.isNull(project)) + Project oldProject = projectService.getById(projecDto.getId()); + Project project = new Project(); + VUtils.isTrue(Objects.isNull(oldProject)) .throwMessage("项目不存在!"); - - project.setVersion(project.getVersion() + 1); - BeanUtils.copyProperties(projecDto,project); + BeanUtil.copyProperties(oldProject,project, CopyOptions.create() + .setIgnoreError(Boolean.TRUE).setIgnoreNullValue(Boolean.TRUE)); + BeanUtil.copyProperties(projecDto,project, CopyOptions.create() + .setIgnoreError(Boolean.TRUE).setIgnoreNullValue(Boolean.TRUE)); + project.setVersion(oldProject.getVersion() + 1); project.setId(null); project.setCreateOn(LocalDateTime.now()); project.setUpdateOn(LocalDateTime.now()); @@ -282,13 +286,15 @@ public class ProjectLibManage { } public Project saveProjectWithVersionAndStatus(ProjectDTO projecDto,Integer stageCode,Integer statusCode){ - Project project = projectService.getById(projecDto.getId()); - - VUtils.isTrue(Objects.isNull(project)) + Project oldProject = projectService.getById(projecDto.getId()); + Project project = new Project(); + VUtils.isTrue(Objects.isNull(oldProject)) .throwMessage("项目不存在!"); - - project.setVersion(project.getVersion() + 1); - BeanUtils.copyProperties(projecDto,project); + BeanUtil.copyProperties(oldProject,project, CopyOptions.create() + .setIgnoreError(Boolean.TRUE).setIgnoreNullValue(Boolean.TRUE)); + BeanUtil.copyProperties(projecDto,project, CopyOptions.create() + .setIgnoreError(Boolean.TRUE).setIgnoreNullValue(Boolean.TRUE)); + project.setVersion(oldProject.getVersion() + 1); project.setId(null); project.setCreateOn(LocalDateTime.now()); project.setUpdateOn(LocalDateTime.now()); @@ -448,4 +454,8 @@ public class ProjectLibManage { } return user; } + + private void copyProperties(ProjectDTO projecDto, Project project) { + + } } diff --git a/pmapi/src/test/java/com/ningdatech/pmapi/statemachine/StateMachineTest.java b/pmapi/src/test/java/com/ningdatech/pmapi/statemachine/StateMachineTest.java index abecf42..8c374bd 100644 --- a/pmapi/src/test/java/com/ningdatech/pmapi/statemachine/StateMachineTest.java +++ b/pmapi/src/test/java/com/ningdatech/pmapi/statemachine/StateMachineTest.java @@ -1,9 +1,9 @@ package com.ningdatech.pmapi.statemachine; import com.alibaba.fastjson.JSON; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.ningdatech.pmapi.AppTests; import com.ningdatech.pmapi.common.statemachine.util.StateMachineUtils; -import com.ningdatech.pmapi.projectlib.enumeration.ProjectStatusEnum; import com.ningdatech.pmapi.projectlib.model.entity.Project; import com.ningdatech.pmapi.projectlib.service.IProjectService; import org.junit.jupiter.api.Test; @@ -32,4 +32,14 @@ public class StateMachineTest extends AppTests { System.out.println(String.format("project:%s", JSON.toJSONString(project))); projectService.updateById(project); } + + @Test + public void yyyyyy(){ + Project project = projectService.getById(400); + projectService.update(Wrappers.lambdaUpdate(Project.class) + .set(Project::getNewest,Boolean.FALSE) + .ne(Project::getId,project.getId()) + .eq(Project::getProjectCode,project.getProjectCode())); + System.out.println(project); + } }