|
|
|
@@ -0,0 +1,119 @@ |
|
|
|
package com.iformall.service.invest; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
|
|
|
import com.iformall.common.ErrorCode; |
|
|
|
import com.iformall.domain.po.*; |
|
|
|
import com.iformall.enums.EnumInvestType; |
|
|
|
import com.iformall.enums.EnumShopStatus; |
|
|
|
import com.iformall.exception.MallinkException; |
|
|
|
import com.iformall.service.MallUserInfoService; |
|
|
|
import com.iformall.service.WxShopService; |
|
|
|
import org.apache.commons.collections.CollectionUtils; |
|
|
|
import org.apache.commons.lang3.ObjectUtils; |
|
|
|
|
|
|
|
import java.lang.reflect.Field; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Objects; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
public class InvestHelper { |
|
|
|
|
|
|
|
/** |
|
|
|
* 校验商铺 |
|
|
|
* |
|
|
|
* @param shopService |
|
|
|
* @param inputEntity |
|
|
|
*/ |
|
|
|
public static void checkShop(WxShopService shopService, BaseInvestEntity inputEntity) { |
|
|
|
Long targetId = null; |
|
|
|
EnumInvestType investType = null; |
|
|
|
if (inputEntity instanceof InvestDemandEntity) { |
|
|
|
InvestDemandEntity entity = (InvestDemandEntity) inputEntity; |
|
|
|
targetId = entity.getTargetId(); |
|
|
|
investType = entity.getTargetType(); |
|
|
|
} else if (inputEntity instanceof InvestTaskEntity) { |
|
|
|
InvestTaskEntity entity = (InvestTaskEntity) inputEntity; |
|
|
|
targetId = entity.getTargetId(); |
|
|
|
investType = entity.getTargetType(); |
|
|
|
} |
|
|
|
if (EnumInvestType.SHOP.equals(investType)) { |
|
|
|
WxShop shop = shopService.getById(targetId); |
|
|
|
checkShopNotNull(shop); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 校验参数是否为空 |
|
|
|
* |
|
|
|
* @param shop |
|
|
|
*/ |
|
|
|
public static void checkShopNotNull(WxShop shop) { |
|
|
|
if (Objects.isNull(shop)) { |
|
|
|
throw new MallinkException(ErrorCode.SHOP_IS_NOT_FOUND); |
|
|
|
} |
|
|
|
|
|
|
|
if (Objects.equals(shop.getStatus(), EnumShopStatus.RENT.getCode())) { |
|
|
|
throw new MallinkException(ErrorCode.SHOP_IS_RENT); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 校验用户是否存在 |
|
|
|
* |
|
|
|
* @param userInfoService |
|
|
|
* @param userIdJson |
|
|
|
*/ |
|
|
|
public static void checkUserExit(MallUserInfoService userInfoService, String userIdJson) { |
|
|
|
if (Objects.nonNull(userIdJson)) { |
|
|
|
List<Long> ids = JSONArray.parseArray(userIdJson, Long.class); |
|
|
|
if (CollectionUtils.isNotEmpty(ids)) { |
|
|
|
List<Long> usersFromDb = userInfoService.getByIds(ids).stream().map(MallUserInfo::getId).collect(Collectors.toList()); |
|
|
|
List<Long> notExsitIds = ids.stream().filter(uid -> !usersFromDb.contains(uid)).collect(Collectors.toList()); |
|
|
|
if (CollectionUtils.isNotEmpty(notExsitIds)) { |
|
|
|
throw new MallinkException(ErrorCode.USER_IS_EMPTY.getCode(), notExsitIds + ErrorCode.USER_IS_EMPTY.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public static void checkUserExit(MallUserInfoService userInfoService, Long id) { |
|
|
|
if (Objects.nonNull(id)) { |
|
|
|
MallUserInfo userInfo = userInfoService.getById(id); |
|
|
|
if (Objects.isNull(userInfo)) |
|
|
|
throw new MallinkException(ErrorCode.USER_IS_EMPTY.getCode(), id + ErrorCode.USER_IS_EMPTY.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public static void checkCustomerExit(InvestCustomerService customerService, Long id) { |
|
|
|
InvestCustomerEntity customerEntity = customerService.getById(id); |
|
|
|
if (Objects.isNull(customerEntity)) { |
|
|
|
throw new MallinkException(ErrorCode.CUSTOMER_NOT_FOUND.getCode(), id + ErrorCode.CUSTOMER_NOT_FOUND.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 校验参数是否为空 |
|
|
|
* |
|
|
|
* @param values |
|
|
|
*/ |
|
|
|
public static void checkAllNotNull(final Object... values) { |
|
|
|
if (!ObjectUtils.allNotNull(values)) { |
|
|
|
throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public static Page buildQueryPage(BaseInvestEntity entity) { |
|
|
|
Page page = new Page(); |
|
|
|
page.setCurrent(entity.getPageIndex()); |
|
|
|
page.setSize(entity.getPageSize()); |
|
|
|
page.setAscs(entity.getAscs()); |
|
|
|
page.setDescs(entity.getDescs()); |
|
|
|
page.setOptimizeCountSql(true); |
|
|
|
page.setSearchCount(true); |
|
|
|
return page; |
|
|
|
} |
|
|
|
} |