diff --git a/mallinkService/src/main/java/com/iformall/mapper/WxMerchantRelationMapper.java b/mallinkService/src/main/java/com/iformall/mapper/WxMerchantRelationMapper.java index 1dca9602e..44f5004db 100644 --- a/mallinkService/src/main/java/com/iformall/mapper/WxMerchantRelationMapper.java +++ b/mallinkService/src/main/java/com/iformall/mapper/WxMerchantRelationMapper.java @@ -18,9 +18,11 @@ public interface WxMerchantRelationMapper extends CommonMapper merchantIds,@Param("regionId") Long regionId); + void deleteByMerchantIds(@Param("merchantIds") List merchantIds,@Param("regionId") Long regionId); + void deleteByMerchantId(@Param("merchantId") Long merchantId); List getRelationByRegionId(@Param("regionId") Long regionId); - List getInfByIds(@Param("ids") List ids); + List getInfByRegionId(@Param("id") Long id); } 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 91c091862..271ccd8c2 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxMerchantRelationServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxMerchantRelationServiceImpl.java @@ -31,6 +31,7 @@ public class WxMerchantRelationServiceImpl implements WxMerchantRelationService @Transactional(rollbackFor = {Exception.class}) @Override public ResultData saveOrUpdate(Long regionId, List ids, Integer type, TenantEntity tenantEntity) { + tenantEntity.setTenantId("789"); if (regionId == null) { return new ResultData(Result.ERROR, "区域商户id不能为空"); } @@ -38,34 +39,47 @@ public class WxMerchantRelationServiceImpl implements WxMerchantRelationService //如果没选择普通商户,删除所有关系 if (CollectionUtils.isEmpty(ids)) { wxMerchantRelationMapper.updateByReginId(regionId); - return new ResultData(Result.SUCCESS, "编辑成功", null); + return new ResultData(Result.SUCCESS, "成功", null); } //先去查询是否存在,如果存在再去排除这个id去进行查询是否存在 - List infByIds = wxMerchantRelationMapper.getInfByIds(ids); + List infByIds = wxMerchantRelationMapper.getInfByRegionId(regionId); List updateList = new ArrayList<>(); + List deleteList = new ArrayList<>(); + List insertList = new ArrayList<>(); if (!CollectionUtils.isEmpty(infByIds)) { - List alreadyList = infByIds.parallelStream().filter(x -> x.getIsDel() == 0 && !ids.contains(x.getMerchantId())).map(WxMerchantRelation::getMerchantId).collect(Collectors.toList()); - //如果已经存在就返回 - if (!CollectionUtils.isEmpty(alreadyList)){ - return new ResultData(Result.ERROR, "存在子商户在其他区域商户下"); + List alreadyList = infByIds.parallelStream().map(WxMerchantRelation::getMerchantId).collect(Collectors.toList()); + List list = ids.parallelStream().filter(x -> !alreadyList.contains(x)).collect(Collectors.toList()); + if (!CollectionUtils.isEmpty(list)){ + insertList = list; } + //如果存在且是同一个区域商户下就 修改 是否删除字段 - 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 update = infByIds.parallelStream().filter(x -> x.getIsDel() == 1 && x.getRegionMerchantId().equals(regionId) && ids.contains(x.getMerchantId())).map(WxMerchantRelation::getMerchantId).collect(Collectors.toList()); + if (!CollectionUtils.isEmpty(update)) { + updateList = update; + } + + //删除商户 + List del = infByIds.parallelStream().filter(x -> x.getIsDel() == 0 && !ids.contains(x.getMerchantId()) && x.getRegionMerchantId().equals(regionId)).map(WxMerchantRelation::getMerchantId).collect(Collectors.toList()); + if (!CollectionUtils.isEmpty(del)) { + deleteList = del; } + }else { + insertList = ids; } - List finalList = updateList; - List alreadyList = infByIds.parallelStream().filter(x -> x.getIsDel() == 0).map(WxMerchantRelation::getMerchantId).collect(Collectors.toList()); - List insertList = ids.parallelStream().filter(x -> !finalList.contains(x) && !alreadyList.contains(x)).collect(Collectors.toList()); if (!CollectionUtils.isEmpty(updateList)) { - wxMerchantRelationMapper.updateByMerchantIds(updateList,regionId); + wxMerchantRelationMapper.updateByMerchantIds(updateList, regionId); } + + if (!CollectionUtils.isEmpty(deleteList)) { + wxMerchantRelationMapper.deleteByMerchantIds(deleteList, regionId); + } + if (!CollectionUtils.isEmpty(insertList)) { List list = new ArrayList<>(); - for (Long id : ids) { + for (Long id : insertList) { WxMerchantRelation relation = new WxMerchantRelation(); relation.setId(IdWorker.get().nextId()); relation.setMerchantId(id); diff --git a/mallinkService/src/main/resources/mapper/WxMerchantRelationMapper.xml b/mallinkService/src/main/resources/mapper/WxMerchantRelationMapper.xml index 1f8851cb9..ad5e59dfc 100644 --- a/mallinkService/src/main/resources/mapper/WxMerchantRelationMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxMerchantRelationMapper.xml @@ -55,6 +55,16 @@ + + update wx_merchant_relation + set is_del = 1, + update_date = now() + where region_merchant_id = #{regionId} and merchant_id in + + #{id} + + + update wx_merchant_relation set is_del = 1, update_date = now() @@ -71,14 +81,11 @@ - select from wx_merchant_relation - where merchant_id in - - #{id} - + where region_merchant_id = #{id}