| @@ -10,15 +10,13 @@ import java.util.List; | |||||
| public interface WxMerchantRelationMapper extends CommonMapper<WxMerchantRelation, Long> { | public interface WxMerchantRelationMapper extends CommonMapper<WxMerchantRelation, Long> { | ||||
| Integer selectByIds(@Param("ids") List<Long> ids); | |||||
| void updateByReginId(@Param("regionId") Long regionId); | void updateByReginId(@Param("regionId") Long regionId); | ||||
| void insertBatch(List<WxMerchantRelation> list); | void insertBatch(List<WxMerchantRelation> list); | ||||
| List<WxMerchantRelation> selectByReginId(@Param("regionId") Long regionId, @Param("ids") List<Long> ids); | List<WxMerchantRelation> selectByReginId(@Param("regionId") Long regionId, @Param("ids") List<Long> ids); | ||||
| void updateByMerchantIds(@Param("merchantIds") List<Long> merchantIds); | |||||
| void updateByMerchantIds(@Param("merchantIds") List<Long> merchantIds,@Param("regionId") Long regionId); | |||||
| void deleteByMerchantId(@Param("merchantId") Long merchantId); | void deleteByMerchantId(@Param("merchantId") Long merchantId); | ||||
| @@ -43,25 +43,27 @@ public class WxMerchantRelationServiceImpl implements WxMerchantRelationService | |||||
| //先去查询是否存在,如果存在再去排除这个id去进行查询是否存在 | //先去查询是否存在,如果存在再去排除这个id去进行查询是否存在 | ||||
| List<WxMerchantRelation> infByIds = wxMerchantRelationMapper.getInfByIds(ids); | List<WxMerchantRelation> infByIds = wxMerchantRelationMapper.getInfByIds(ids); | ||||
| List<Long> list = new ArrayList<>(); | |||||
| List<Long> updateList = new ArrayList<>(); | |||||
| if (!CollectionUtils.isEmpty(infByIds)) { | if (!CollectionUtils.isEmpty(infByIds)) { | ||||
| list = infByIds.parallelStream().map(WxMerchantRelation::getMerchantId).collect(Collectors.toList()); | |||||
| //判断子商户是否已经被选了 | |||||
| Integer integer = wxMerchantRelationMapper.selectByIds(list); | |||||
| if (integer > 0) { | |||||
| List<Long> alreadyList = infByIds.parallelStream().filter(x -> x.getIsDel() == 0).map(WxMerchantRelation::getMerchantId).collect(Collectors.toList()); | |||||
| //如果已经存在就返回 | |||||
| if (!CollectionUtils.isEmpty(alreadyList)){ | |||||
| return new ResultData(Result.ERROR, "存在子商户在其他区域商户下"); | return new ResultData(Result.ERROR, "存在子商户在其他区域商户下"); | ||||
| } | } | ||||
| //如果存在且是同一个区域商户下就 修改 是否删除字段 | |||||
| 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> finalList = list; | |||||
| List<Long> collected = ids.parallelStream().filter(x -> !finalList.contains(x)).collect(Collectors.toList()); | |||||
| if (!CollectionUtils.isEmpty(list)) { | |||||
| wxMerchantRelationMapper.updateByMerchantIds(list); | |||||
| List<Long> finalList = updateList; | |||||
| List<Long> 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); | return new ResultData(Result.SUCCESS, "编辑成功", null); | ||||
| } | } | ||||
| @@ -17,16 +17,6 @@ | |||||
| `id`,`tenant_id`,`parent_tenant_id`,`merchant_id`,`region_merchant_id`,`is_del`,`create_date`,`update_date` | `id`,`tenant_id`,`parent_tenant_id`,`merchant_id`,`region_merchant_id`,`is_del`,`create_date`,`update_date` | ||||
| </sql> | </sql> | ||||
| <select id="selectByIds" resultType="java.lang.Integer"> | |||||
| select | |||||
| count(1) | |||||
| from wx_merchant_relation | |||||
| where is_del = 0 and merchant_id not in | |||||
| <foreach collection="ids" index="index" item="id" open="(" separator="," close=")"> | |||||
| #{id} | |||||
| </foreach> | |||||
| </select> | |||||
| <update id="updateByReginId"> | <update id="updateByReginId"> | ||||
| update wx_merchant_relation | update wx_merchant_relation | ||||
| set is_del = 1, update_date = now() | set is_del = 1, update_date = now() | ||||
| @@ -58,7 +48,7 @@ | |||||
| update wx_merchant_relation | update wx_merchant_relation | ||||
| set is_del = 0, | set is_del = 0, | ||||
| update_date = now() | update_date = now() | ||||
| where merchant_id in | |||||
| where region_merchant_id = #{regionId} and merchant_id in | |||||
| <foreach collection="merchantIds" index="index" item="id" open="(" separator="," close=")"> | <foreach collection="merchantIds" index="index" item="id" open="(" separator="," close=")"> | ||||
| #{id} | #{id} | ||||
| </foreach> | </foreach> | ||||