From 329cbcea7c06fc61f9fd187b6c00dc400906afac Mon Sep 17 00:00:00 2001 From: lrh <1585126058@qq.com> Date: Sun, 2 Jul 2023 14:14:57 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AD=90=E5=95=86?= =?UTF-8?q?=E6=88=B7=E7=9A=84=E6=96=B0=E5=A2=9E=E6=88=96=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/WxMerchantRelationServiceImpl.java | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxMerchantRelationServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxMerchantRelationServiceImpl.java index fcc6477f2..b6586ebba 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxMerchantRelationServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxMerchantRelationServiceImpl.java @@ -55,19 +55,15 @@ public class WxMerchantRelationServiceImpl implements WxMerchantRelationService List finalList = list; List collected = ids.parallelStream().filter(x -> !finalList.contains(x)).collect(Collectors.toList()); - //1-新增 2-修改 - if (type == 1) { - //选择就插入 - insertInfo(regionId, ids, tenantId); - return new ResultData(Result.SUCCESS, "新增成功", null); - } else if (type == 2) { + + if (!CollectionUtils.isEmpty(list)) { wxMerchantRelationMapper.updateByMerchantIds(list); - if (!CollectionUtils.isEmpty(collected)){ - insertInfo(regionId, collected, tenantId); - } - return new ResultData(Result.SUCCESS, "编辑成功", null); } - return null; + + if (!CollectionUtils.isEmpty(collected)) { + insertInfo(regionId, collected, tenantId); + } + return new ResultData(Result.SUCCESS, "编辑成功", null); } public void insertInfo(Long regionId, List ids, String tenantId) { @@ -77,7 +73,6 @@ public class WxMerchantRelationServiceImpl implements WxMerchantRelationService relation.setId(IdWorker.get().nextId()); relation.setMerchantId(id); relation.setRegionMerchantId(regionId); - relation.setIsDel(0); relation.setTenantId(tenantId); list.add(relation); } From 5228d8eef57057ebf7d9e6ce173df6ba716bbfa8 Mon Sep 17 00:00:00 2001 From: lrh <1585126058@qq.com> Date: Sun, 2 Jul 2023 14:48:56 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AD=90=E5=95=86?= =?UTF-8?q?=E6=88=B7=E7=9A=84=E6=96=B0=E5=A2=9E=E6=88=96=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapper/WxMerchantRelationMapper.java | 4 +-- .../impl/WxMerchantRelationServiceImpl.java | 28 ++++++++++--------- .../mapper/WxMerchantRelationMapper.xml | 12 +------- 3 files changed, 17 insertions(+), 27 deletions(-) diff --git a/mallinkService/src/main/java/com/iformall/mapper/WxMerchantRelationMapper.java b/mallinkService/src/main/java/com/iformall/mapper/WxMerchantRelationMapper.java index 6c4364378..1dca9602e 100644 --- a/mallinkService/src/main/java/com/iformall/mapper/WxMerchantRelationMapper.java +++ b/mallinkService/src/main/java/com/iformall/mapper/WxMerchantRelationMapper.java @@ -10,15 +10,13 @@ import java.util.List; public interface WxMerchantRelationMapper extends CommonMapper { - Integer selectByIds(@Param("ids") List ids); - void updateByReginId(@Param("regionId") Long regionId); void insertBatch(List list); List selectByReginId(@Param("regionId") Long regionId, @Param("ids") List ids); - void updateByMerchantIds(@Param("merchantIds") List merchantIds); + void updateByMerchantIds(@Param("merchantIds") List merchantIds,@Param("regionId") Long regionId); void deleteByMerchantId(@Param("merchantId") Long merchantId); diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxMerchantRelationServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxMerchantRelationServiceImpl.java index b6586ebba..075d16fca 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxMerchantRelationServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxMerchantRelationServiceImpl.java @@ -43,25 +43,27 @@ public class WxMerchantRelationServiceImpl implements WxMerchantRelationService //先去查询是否存在,如果存在再去排除这个id去进行查询是否存在 List infByIds = wxMerchantRelationMapper.getInfByIds(ids); - List list = new ArrayList<>(); + List updateList = new ArrayList<>(); if (!CollectionUtils.isEmpty(infByIds)) { - list = infByIds.parallelStream().map(WxMerchantRelation::getMerchantId).collect(Collectors.toList()); - //判断子商户是否已经被选了 - Integer integer = wxMerchantRelationMapper.selectByIds(list); - if (integer > 0) { + List alreadyList = infByIds.parallelStream().filter(x -> x.getIsDel() == 0).map(WxMerchantRelation::getMerchantId).collect(Collectors.toList()); + //如果已经存在就返回 + if (!CollectionUtils.isEmpty(alreadyList)){ return new ResultData(Result.ERROR, "存在子商户在其他区域商户下"); } + //如果存在且是同一个区域商户下就 修改 是否删除字段 + List delList = infByIds.parallelStream().filter(x -> x.getIsDel() == 1 && x.getRegionMerchantId().equals(regionId)).map(WxMerchantRelation::getMerchantId).collect(Collectors.toList()); + if (!CollectionUtils.isEmpty(delList)){ + updateList = delList; + } } - List finalList = list; - List collected = ids.parallelStream().filter(x -> !finalList.contains(x)).collect(Collectors.toList()); - - if (!CollectionUtils.isEmpty(list)) { - wxMerchantRelationMapper.updateByMerchantIds(list); + List finalList = updateList; + List insertList = ids.parallelStream().filter(x -> !finalList.contains(x)).collect(Collectors.toList()); + if (!CollectionUtils.isEmpty(updateList)) { + wxMerchantRelationMapper.updateByMerchantIds(updateList,regionId); } - - if (!CollectionUtils.isEmpty(collected)) { - insertInfo(regionId, collected, tenantId); + if (!CollectionUtils.isEmpty(insertList)) { + insertInfo(regionId, insertList, tenantId); } return new ResultData(Result.SUCCESS, "编辑成功", null); } diff --git a/mallinkService/src/main/resources/mapper/WxMerchantRelationMapper.xml b/mallinkService/src/main/resources/mapper/WxMerchantRelationMapper.xml index 07266249f..d8618c157 100644 --- a/mallinkService/src/main/resources/mapper/WxMerchantRelationMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxMerchantRelationMapper.xml @@ -17,16 +17,6 @@ `id`,`tenant_id`,`parent_tenant_id`,`merchant_id`,`region_merchant_id`,`is_del`,`create_date`,`update_date` - - update wx_merchant_relation set is_del = 1, update_date = now() @@ -58,7 +48,7 @@ update wx_merchant_relation set is_del = 0, update_date = now() - where merchant_id in + where region_merchant_id = #{regionId} and merchant_id in #{id}