|
|
|
@@ -156,7 +156,15 @@ public class WxCouponServiceImpl implements WxCouponService { |
|
|
|
return merchantParam.getString("parameter"); |
|
|
|
} |
|
|
|
private Integer parseBusiness(JSONObject merchantParam){ |
|
|
|
return Integer.valueOf(merchantParam.getString("businessId")); |
|
|
|
String businessIdStr = merchantParam.getString("businessId"); |
|
|
|
return Integer.valueOf(businessIdStr); |
|
|
|
|
|
|
|
} |
|
|
|
private Integer parseSubBusiness(JSONObject merchantParam){ |
|
|
|
String subBusinessIdStr = merchantParam.getString("subBusinessId"); |
|
|
|
if (subBusinessIdStr != null) |
|
|
|
return Integer.valueOf(subBusinessIdStr); |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
private WxCouponMerchantDto parseMerchantParam(JSONObject merchantParam){ |
|
|
|
@@ -165,6 +173,7 @@ public class WxCouponServiceImpl implements WxCouponService { |
|
|
|
wxCouponMerchantDto.setMerchantId(parseMerchantId(merchantParam)); |
|
|
|
wxCouponMerchantDto.setParameter(parseParameter(merchantParam)); |
|
|
|
wxCouponMerchantDto.setBusiness(parseBusiness(merchantParam)); |
|
|
|
wxCouponMerchantDto.setSubBusiness(parseSubBusiness(merchantParam)); |
|
|
|
}catch (Exception e) { |
|
|
|
throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR); |
|
|
|
} |
|
|
|
@@ -204,7 +213,7 @@ public class WxCouponServiceImpl implements WxCouponService { |
|
|
|
} |
|
|
|
|
|
|
|
final IdWorker idWorker = IdWorker.get(); |
|
|
|
|
|
|
|
List<JSONObject> merchantParamList = JSONObject.parseArray(record.getMerchantParams(), JSONObject.class); |
|
|
|
if (record.getId() == null) { |
|
|
|
|
|
|
|
// check 卡券补贴设置 |
|
|
|
@@ -232,9 +241,9 @@ public class WxCouponServiceImpl implements WxCouponService { |
|
|
|
} |
|
|
|
|
|
|
|
record.setId(idWorker.nextId()); |
|
|
|
List<JSONObject> merchantParamList = JSONObject.parseArray(record.getMerchantParams(), JSONObject.class); |
|
|
|
if (merchantParamList != null) { |
|
|
|
List<Integer> businessList= new ArrayList<>(); |
|
|
|
|
|
|
|
if (merchantParamList != null && merchantParamList.size() > 0) { |
|
|
|
List<WxCouponMerchantDto> wxCouponMerchantDtoList = new ArrayList<>(); |
|
|
|
merchantParamList.forEach(merchantParam -> { |
|
|
|
WxCouponMerchant cm = new WxCouponMerchant(); |
|
|
|
WxCouponMerchantDto wxCouponMerchantDto = parseMerchantParam(merchantParam); |
|
|
|
@@ -245,13 +254,17 @@ public class WxCouponServiceImpl implements WxCouponService { |
|
|
|
cm.setCreateDate(new Date()); |
|
|
|
cm.setUpdateDate(new Date()); |
|
|
|
cm.setStatus(EnumCouponMerchantStatus.COUPON_MERCHANT_STATUS_VALID.getCode()); |
|
|
|
businessList.add(wxCouponMerchantDto.getBusiness()); |
|
|
|
wxCouponMerchantDtoList.add(wxCouponMerchantDto); |
|
|
|
wxCouponMerchantMapper.insertSelective(cm); |
|
|
|
}); |
|
|
|
if (businessList.stream().distinct().count() > 1) { |
|
|
|
if (wxCouponMerchantDtoList.stream() |
|
|
|
.mapToInt(WxCouponMerchantDto::getBusiness).distinct().count() > 1) { |
|
|
|
record.setBusiness(EnumBusiness.BUSINESS_ID6.getCode()); |
|
|
|
} else if (wxCouponMerchantDtoList.size() > 1){ |
|
|
|
record.setBusiness(wxCouponMerchantDtoList.get(0).getBusiness()); |
|
|
|
} else { |
|
|
|
record.setBusiness(businessList.get(0)); |
|
|
|
record.setBusiness(wxCouponMerchantDtoList.get(0).getBusiness()); |
|
|
|
record.setSubBusiness(wxCouponMerchantDtoList.get(0).getSubBusiness()); |
|
|
|
} |
|
|
|
|
|
|
|
} else{ |
|
|
|
@@ -263,13 +276,11 @@ public class WxCouponServiceImpl implements WxCouponService { |
|
|
|
wxCouponMapper.insertSelective(record); |
|
|
|
|
|
|
|
} else { |
|
|
|
if (record.getMerchantParams() != null) { |
|
|
|
List<JSONObject> merchantParamList = JSONObject.parseArray(record.getMerchantParams(), JSONObject.class); |
|
|
|
|
|
|
|
if (merchantParamList != null && merchantParamList.size() > 0) { |
|
|
|
WxCouponMerchant cmParam = new WxCouponMerchant(); |
|
|
|
cmParam.setProductId(record.getId()); |
|
|
|
List<WxCouponMerchant> oldList = wxCouponMerchantMapper.findList(cmParam); |
|
|
|
List<Integer> businessList= new ArrayList<>(); |
|
|
|
List<WxCouponMerchantDto> wxCouponMerchantDtoList = new ArrayList<>(); |
|
|
|
merchantParamList.stream().forEach(merchantParam -> { |
|
|
|
WxCouponMerchant cm = new WxCouponMerchant(); |
|
|
|
WxCouponMerchantDto wxCouponMerchantDto = parseMerchantParam(merchantParam); |
|
|
|
@@ -289,7 +300,7 @@ public class WxCouponServiceImpl implements WxCouponService { |
|
|
|
cm.setUpdateDate(new Date()); |
|
|
|
wxCouponMerchantMapper.insertSelective(cm); |
|
|
|
} |
|
|
|
businessList.add(Integer.valueOf(wxCouponMerchantDto.getBusiness())); |
|
|
|
wxCouponMerchantDtoList.add(wxCouponMerchantDto); |
|
|
|
oldList.removeIf( |
|
|
|
old->old.getProductId().equals(record.getId()) && |
|
|
|
old.getMerchantId().equals(wxCouponMerchantDto.getMerchantId())); |
|
|
|
@@ -301,10 +312,14 @@ public class WxCouponServiceImpl implements WxCouponService { |
|
|
|
wxCouponMerchantMapper.updateByPrimaryKeySelective(old); |
|
|
|
}); |
|
|
|
|
|
|
|
if (businessList.stream().distinct().count() > 1) { |
|
|
|
if (wxCouponMerchantDtoList.stream() |
|
|
|
.mapToInt(WxCouponMerchantDto::getBusiness).distinct().count() > 1) { |
|
|
|
record.setBusiness(EnumBusiness.BUSINESS_ID6.getCode()); |
|
|
|
} else if (wxCouponMerchantDtoList.size() > 1){ |
|
|
|
record.setBusiness(wxCouponMerchantDtoList.get(0).getBusiness()); |
|
|
|
} else { |
|
|
|
record.setBusiness(businessList.get(0)); |
|
|
|
record.setBusiness(wxCouponMerchantDtoList.get(0).getBusiness()); |
|
|
|
record.setSubBusiness(wxCouponMerchantDtoList.get(0).getSubBusiness()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|