Преглед изворни кода

[招商]adjust

release_toaliyun_real
Burce пре 6 година
родитељ
комит
858606d945
5 измењених фајлова са 246 додато и 0 уклоњено
  1. +62
    -0
      mallinkService/src/main/java/com/iformall/common/InvestResultData.java
  2. +18
    -0
      mallinkService/src/main/java/com/iformall/domain/vo/invest/InvestDemandVo.java
  3. +31
    -0
      mallinkService/src/main/java/com/iformall/domain/vo/invest/InvestPage.java
  4. +16
    -0
      mallinkService/src/main/java/com/iformall/domain/vo/invest/InvestTaskVo.java
  5. +119
    -0
      mallinkService/src/main/java/com/iformall/service/invest/InvestHelper.java

+ 62
- 0
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<T> 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<String, Object> toHashMap() {
HashMap<String, Object> map = new HashMap<>(3);
map.put("code", this.code);
map.put("message", this.message);
map.put("data", data);
return map;
}

}

+ 18
- 0
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<T> extends InvestDemandEntity {

private InvestCustomerEntity customer;

private WxBrand brand;

private T targetInfo;
}

+ 31
- 0
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<T> {

/**
* 查询数据列表
*/
private List<T> records = Collections.emptyList();
/**
* 总数
*/
private long total = 0;
/**
* 每页显示条数,默认 10
*/
private long size = 10;
/**
* 当前页
*/
private long current = 1;

private boolean hasNextPage = false ;


}

+ 16
- 0
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<T> extends InvestTaskEntity {

/**
* targetInfo
*/
@io.swagger.annotations.ApiModelProperty(value = "targetInfo", name = "targetInfo")
private T targetInfo;
}

+ 119
- 0
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<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;
}
}

Loading…
Откажи
Сачувај