|
|
package com.yoho.ufo.order.controller;
|
|
|
|
|
|
import com.google.common.base.Splitter;
|
|
|
import com.yoho.order.dal.BlackUserMapper;
|
|
|
import com.yoho.order.model.BlackUser;
|
|
|
import com.yoho.ufo.service.model.ApiResponse;
|
|
|
import com.yoho.ufo.util.DateUtil;
|
|
|
import lombok.val;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import java.util.Objects;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@RestController
|
|
|
@RequestMapping(value = "/blackUser")
|
|
|
public class BlackUserController {
|
|
|
|
|
|
@Autowired
|
|
|
private BlackUserMapper blackUserMapper;
|
|
|
|
|
|
@RequestMapping(value = "/create")
|
|
|
public ApiResponse create(String uids, Integer blackType, String reason) {
|
|
|
if (StringUtils.isBlank(uids)) {
|
|
|
return new ApiResponse.ApiResponseBuilder().code(400).message("用户账户无效").build();
|
|
|
}
|
|
|
if (StringUtils.isBlank(reason)) {
|
|
|
return new ApiResponse.ApiResponseBuilder().code(400).message("请输入拉黑原因").build();
|
|
|
}
|
|
|
if (!BlackUser.ALL_BLACK_TYPE.contains(blackType)) {
|
|
|
return new ApiResponse.ApiResponseBuilder().code(400).message("无效的类型").build();
|
|
|
}
|
|
|
|
|
|
val blackUids = Splitter.on(",").splitToList(uids).stream()
|
|
|
.filter(StringUtils::isNoneBlank)
|
|
|
.map(Integer::valueOf)
|
|
|
.distinct()
|
|
|
.limit(100)
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
if (CollectionUtils.isEmpty(blackUids)) {
|
|
|
return new ApiResponse.ApiResponseBuilder().code(400).message("没有可加的用户").build();
|
|
|
}
|
|
|
blackUserMapper.deleteByUidsAndBlackType(blackUids, blackType);
|
|
|
val blackUsers = blackUids.stream()
|
|
|
.map(uid -> {
|
|
|
BlackUser blackUser = new BlackUser();
|
|
|
blackUser.setUid(uid);
|
|
|
blackUser.setBlackType(blackType);
|
|
|
blackUser.setReason(reason);
|
|
|
blackUser.setCreateTime(DateUtil.getCurrentTimeSeconds());
|
|
|
blackUser.setStatus(BlackUser.STATUS_ENABLE);
|
|
|
blackUser.setUpdateTime(blackUser.getCreateTime());
|
|
|
return blackUser;
|
|
|
})
|
|
|
.collect(Collectors.toList());
|
|
|
blackUserMapper.insert(blackUsers);
|
|
|
return new ApiResponse.ApiResponseBuilder().build();
|
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "/remove")
|
|
|
public ApiResponse remove(Integer uid) {
|
|
|
if (Objects.isNull(uid)) {
|
|
|
return new ApiResponse.ApiResponseBuilder().code(400).message("用户账户无效").build();
|
|
|
}
|
|
|
blackUserMapper.deleteByUid(uid);
|
|
|
return new ApiResponse.ApiResponseBuilder().build();
|
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "/check")
|
|
|
public ApiResponse check(Integer uid) {
|
|
|
if (Objects.isNull(uid)) {
|
|
|
return new ApiResponse.ApiResponseBuilder().code(400).message("用户账户无效").build();
|
|
|
}
|
|
|
String message = blackUserMapper.selectByUid(uid).stream()
|
|
|
.filter(e -> e.getStatus().equals(BlackUser.STATUS_ENABLE))
|
|
|
.map(BlackUser::getBlackType)
|
|
|
.map(blackType -> {
|
|
|
if (BlackUser.BLACK_TYPE_CREATE_BUYER_ORDER.equals(blackType)) {
|
|
|
return "限制购买";
|
|
|
}
|
|
|
if (BlackUser.BLACK_TYPE_CREATE_SELLER_ORDER.equals(blackType)) {
|
|
|
return "限制出售";
|
|
|
}
|
|
|
return null;
|
|
|
})
|
|
|
.filter(Objects::nonNull)
|
|
|
.reduce("", (a, b) -> a + "," + b);
|
|
|
if (StringUtils.isBlank(message)) {
|
|
|
return new ApiResponse.ApiResponseBuilder().code(200).message("无限制").build();
|
|
|
} else {
|
|
|
return new ApiResponse.ApiResponseBuilder().message(message).build();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|