Просмотр исходного кода

Merge branch 'release_toaliyun_real_20230605' of https://git.malls.iformall.com/server/formallProject into release_toaliyun_real_20230605

release_toaliyun_real
xhxu 2 лет назад
Родитель
Сommit
957e67fd11
3 измененных файлов: 43 добавлений и 20 удалений
  1. +3
    -1
      mallinkService/src/main/java/com/iformall/mapper/WxMerchantRelationMapper.java
  2. +28
    -14
      mallinkService/src/main/java/com/iformall/service/impl/WxMerchantRelationServiceImpl.java
  3. +12
    -5
      mallinkService/src/main/resources/mapper/WxMerchantRelationMapper.xml

+ 3
- 1
mallinkService/src/main/java/com/iformall/mapper/WxMerchantRelationMapper.java Просмотреть файл

@@ -18,9 +18,11 @@ public interface WxMerchantRelationMapper extends CommonMapper<WxMerchantRelatio

void updateByMerchantIds(@Param("merchantIds") List<Long> merchantIds,@Param("regionId") Long regionId);

void deleteByMerchantIds(@Param("merchantIds") List<Long> merchantIds,@Param("regionId") Long regionId);

void deleteByMerchantId(@Param("merchantId") Long merchantId);

List<Long> getRelationByRegionId(@Param("regionId") Long regionId);

List<WxMerchantRelation> getInfByIds(@Param("ids") List<Long> ids);
List<WxMerchantRelation> getInfByRegionId(@Param("id") Long id);
}

+ 28
- 14
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<Long> 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<WxMerchantRelation> infByIds = wxMerchantRelationMapper.getInfByIds(ids);
List<WxMerchantRelation> infByIds = wxMerchantRelationMapper.getInfByRegionId(regionId);
List<Long> updateList = new ArrayList<>();
List<Long> deleteList = new ArrayList<>();
List<Long> insertList = new ArrayList<>();
if (!CollectionUtils.isEmpty(infByIds)) {
List<Long> 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<Long> alreadyList = infByIds.parallelStream().map(WxMerchantRelation::getMerchantId).collect(Collectors.toList());
List<Long> list = ids.parallelStream().filter(x -> !alreadyList.contains(x)).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(list)){
insertList = list;
}

//如果存在且是同一个区域商户下就 修改 是否删除字段
List<Long> 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<Long> 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<Long> 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<Long> finalList = updateList;
List<Long> alreadyList = infByIds.parallelStream().filter(x -> x.getIsDel() == 0).map(WxMerchantRelation::getMerchantId).collect(Collectors.toList());
List<Long> 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<WxMerchantRelation> list = new ArrayList<>();
for (Long id : ids) {
for (Long id : insertList) {
WxMerchantRelation relation = new WxMerchantRelation();
relation.setId(IdWorker.get().nextId());
relation.setMerchantId(id);


+ 12
- 5
mallinkService/src/main/resources/mapper/WxMerchantRelationMapper.xml Просмотреть файл

@@ -55,6 +55,16 @@
</foreach>
</update>

<update id="deleteByMerchantIds">
update wx_merchant_relation
set is_del = 1,
update_date = now()
where region_merchant_id = #{regionId} and merchant_id in
<foreach collection="merchantIds" index="index" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</update>

<update id="deleteByMerchantId">
update wx_merchant_relation
set is_del = 1, update_date = now()
@@ -71,14 +81,11 @@
</if>
</select>

<select id="getInfByIds" resultType="com.iformall.domain.po.WxMerchantRelation">
<select id="getInfByRegionId" resultType="com.iformall.domain.po.WxMerchantRelation">
select
<include refid="allColumns"/>
from wx_merchant_relation
where merchant_id in
<foreach collection="ids" index="index" item="id" open="(" separator="," close=")">
#{id}
</foreach>
where region_merchant_id = #{id}
</select>

</mapper>

Загрузка…
Отмена
Сохранить