From ae6c5a1b56ca6fd6c4b7b904d6a5a459216ffbe1 Mon Sep 17 00:00:00 2001 From: huangyawei Date: Thu, 8 Aug 2024 19:47:20 +0800 Subject: [PATCH] =?UTF-8?q?release-=20JPA=E5=AE=9A=E4=B9=89=E5=9F=BA?= =?UTF-8?q?=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- luoo_common/pom.xml | 12 ------------ luoo_user/pom.xml | 17 ----------------- .../luoo/user/listener/JPAEntityListener.java | 13 +++++-------- .../com/luoo/user/mapstruct/StoreMapper.java | 11 ----------- .../com/luoo/user/service/StoreService.java | 9 ++------- 5 files changed, 7 insertions(+), 55 deletions(-) delete mode 100644 luoo_user/src/main/java/com/luoo/user/mapstruct/StoreMapper.java diff --git a/luoo_common/pom.xml b/luoo_common/pom.xml index 5ec1ed9..b947112 100644 --- a/luoo_common/pom.xml +++ b/luoo_common/pom.xml @@ -42,18 +42,6 @@ 3.7.0 - - org.mapstruct - mapstruct - 1.4.2.Final - - - org.mapstruct - mapstruct-processor - 1.4.2.Final - provided - - diff --git a/luoo_user/pom.xml b/luoo_user/pom.xml index 2cfbc1a..3789860 100644 --- a/luoo_user/pom.xml +++ b/luoo_user/pom.xml @@ -203,23 +203,6 @@ - - - org.apache.maven.plugins - maven-compiler-plugin - 3.8.1 - - 1.8 - 1.8 - - - org.mapstruct - mapstruct-processor - 1.4.2.Final - - - - diff --git a/luoo_user/src/main/java/com/luoo/user/listener/JPAEntityListener.java b/luoo_user/src/main/java/com/luoo/user/listener/JPAEntityListener.java index ceb27a4..51b3879 100644 --- a/luoo_user/src/main/java/com/luoo/user/listener/JPAEntityListener.java +++ b/luoo_user/src/main/java/com/luoo/user/listener/JPAEntityListener.java @@ -60,15 +60,12 @@ public class JPAEntityListener { jpaBasePojo.setUpdateUser(getCurrentUser().getUserId()); jpaBasePojo.setUpdateUserName(getCurrentUser().getNickName()); jpaBasePojo.setUpdateTime(LocalDateTime.now()); - } - @PreRemove - public void setDeletedOn(JPABasePojo jpaBasePojo) { - log.info("Setting deleted on {}", jpaBasePojo); - jpaBasePojo.setUpdateUser(getCurrentUser().getUserId()); - jpaBasePojo.setUpdateUserName(getCurrentUser().getNickName()); - jpaBasePojo.setUpdateTime(LocalDateTime.now()); - jpaBasePojo.setDelFlag(2); // 默认已删除 + if(jpaBasePojo.getDelFlag() == 2) { + jpaBasePojo.setDelFlag(2); + } else { + jpaBasePojo.setDelFlag(0); + } } private UserLoginDto getCurrentUser() { diff --git a/luoo_user/src/main/java/com/luoo/user/mapstruct/StoreMapper.java b/luoo_user/src/main/java/com/luoo/user/mapstruct/StoreMapper.java deleted file mode 100644 index 679c504..0000000 --- a/luoo_user/src/main/java/com/luoo/user/mapstruct/StoreMapper.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.luoo.user.mapstruct; - -import com.luoo.user.dto.store.StoreUpdateDto; -import com.luoo.user.pojo.Store; -import org.mapstruct.*; - -@Mapper(componentModel = "spring") -public interface StoreMapper { - - void updateStoreFromDto(StoreUpdateDto dto, @MappingTarget Store entity); -} \ No newline at end of file diff --git a/luoo_user/src/main/java/com/luoo/user/service/StoreService.java b/luoo_user/src/main/java/com/luoo/user/service/StoreService.java index d679858..65caaa1 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/StoreService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/StoreService.java @@ -2,14 +2,11 @@ package com.luoo.user.service; import com.luoo.user.dao.StoreDao; import com.luoo.user.dto.store.StoreUpdateDto; -import com.luoo.user.mapstruct.StoreMapper; import com.luoo.user.pojo.Store; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanUtils; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import util.IdWorker; import java.util.List; @@ -25,11 +22,9 @@ public class StoreService { private final StoreDao storeDao; - private final StoreMapper storeMapper; - public StoreService(StoreDao storeDao, StoreMapper storeMapper) { + public StoreService(StoreDao storeDao) { this.storeDao = storeDao; - this.storeMapper = storeMapper; } // 增删改查 @@ -49,7 +44,7 @@ public class StoreService { @Transactional(rollbackFor = Exception.class) public void update(StoreUpdateDto storeUpdateDto) { Store oldStore = storeDao.findById(storeUpdateDto.getId()).orElseThrow(() -> new RuntimeException("Store not found")); - storeMapper.updateStoreFromDto(storeUpdateDto, oldStore); + BeanUtils.copyProperties(storeUpdateDto, oldStore); storeDao.save(oldStore); } public Store getOne(String id) {