diff --git a/mallinkService/src/main/java/com/iformall/common/InvestResultData.java b/mallinkService/src/main/java/com/iformall/common/InvestResultData.java new file mode 100644 index 000000000..5e8c06f16 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/common/InvestResultData.java @@ -0,0 +1,62 @@ +package com.iformall.common; + +import java.util.HashMap; + +/** + * @author chenkx + * @date 2018-01-05. + */ +public class InvestResultData extends Result { + + public T data; + + public InvestResultData() { + super(); + } + + public InvestResultData(T data) { + this(); + this.data = data; + } + + + public static InvestResultData returnResultObject(int code) { + String value = ErrorCode.getByCode(code).getMessage(); + return new InvestResultData(code, value); + } + + public InvestResultData(int code, Exception e) { + super(code, e.toString()); + } + + + public InvestResultData(int code, String message) { + super(code, message); + } + + public InvestResultData(int code, String message, T data) { + this.code = code; + this.message = message; + this.data = data; + } + + public InvestResultData(ErrorCode errorCode, T data) { + this.code = errorCode.getCode(); + this.message = errorCode.getMessage(); + this.data = data; + } + + public InvestResultData(ErrorCode errorCode) { + this.code = errorCode.getCode(); + this.message = errorCode.getMessage(); + } + + public HashMap toHashMap() { + HashMap map = new HashMap<>(3); + map.put("code", this.code); + map.put("message", this.message); + map.put("data", data); + return map; + } + +} diff --git a/mallinkService/src/main/java/com/iformall/domain/vo/invest/InvestDemandVo.java b/mallinkService/src/main/java/com/iformall/domain/vo/invest/InvestDemandVo.java new file mode 100644 index 000000000..cd157bd98 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/domain/vo/invest/InvestDemandVo.java @@ -0,0 +1,18 @@ +package com.iformall.domain.vo.invest; + +import com.iformall.domain.po.InvestCustomerEntity; +import com.iformall.domain.po.InvestDemandEntity; +import com.iformall.domain.po.WxBrand; +import lombok.Builder; +import lombok.Data; + +@Data +@Builder +public class InvestDemandVo extends InvestDemandEntity { + + private InvestCustomerEntity customer; + + private WxBrand brand; + + private T targetInfo; +} diff --git a/mallinkService/src/main/java/com/iformall/domain/vo/invest/InvestPage.java b/mallinkService/src/main/java/com/iformall/domain/vo/invest/InvestPage.java new file mode 100644 index 000000000..41509be48 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/domain/vo/invest/InvestPage.java @@ -0,0 +1,31 @@ +package com.iformall.domain.vo.invest; + +import lombok.Data; + +import java.util.Collections; +import java.util.List; + +@Data +public class InvestPage { + + /** + * 查询数据列表 + */ + private List records = Collections.emptyList(); + /** + * 总数 + */ + private long total = 0; + /** + * 每页显示条数,默认 10 + */ + private long size = 10; + /** + * 当前页 + */ + private long current = 1; + + private boolean hasNextPage = false ; + + +} diff --git a/mallinkService/src/main/java/com/iformall/domain/vo/invest/InvestTaskVo.java b/mallinkService/src/main/java/com/iformall/domain/vo/invest/InvestTaskVo.java new file mode 100644 index 000000000..b17d7b0d9 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/domain/vo/invest/InvestTaskVo.java @@ -0,0 +1,16 @@ +package com.iformall.domain.vo.invest; + +import com.iformall.domain.po.InvestTaskEntity; +import lombok.Builder; +import lombok.Data; + +@Data +@Builder +public class InvestTaskVo extends InvestTaskEntity { + + /** + * targetInfo + */ + @io.swagger.annotations.ApiModelProperty(value = "targetInfo", name = "targetInfo") + private T targetInfo; +} diff --git a/mallinkService/src/main/java/com/iformall/service/invest/InvestHelper.java b/mallinkService/src/main/java/com/iformall/service/invest/InvestHelper.java new file mode 100644 index 000000000..edfd9ff56 --- /dev/null +++ b/mallinkService/src/main/java/com/iformall/service/invest/InvestHelper.java @@ -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 ids = JSONArray.parseArray(userIdJson, Long.class); + if (CollectionUtils.isNotEmpty(ids)) { + List usersFromDb = userInfoService.getByIds(ids).stream().map(MallUserInfo::getId).collect(Collectors.toList()); + List 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; + } +}