Commit 5a531ac9 authored by renjie's avatar renjie

修改shop接口

parent 2b78184d
......@@ -10,7 +10,7 @@ import org.springframework.data.mongodb.core.mapping.Document;
public class Shop {
@Id
private String id;
private String shopId;
private String shopName;
......@@ -95,8 +95,8 @@ public class Shop {
return ip;
}
public String getId() {
return id;
public String getShopId() {
return shopId;
}
public String getIpId() {
......@@ -131,8 +131,8 @@ public class Shop {
this.ip = ip;
}
public void setId(String id) {
this.id = id;
public void setShopId(String shopId) {
this.shopId = shopId;
}
public void setIpId(String ipId) {
......
......@@ -10,7 +10,7 @@ import java.util.List;
@JsonIgnoreProperties(ignoreUnknown = true)
public class ShopDto {
private String id;
private String shopId;
private String shopName;
......@@ -36,7 +36,7 @@ public class ShopDto {
public static ShopDto of(Shop shop, IpResource ipResources) {
ShopDto shopDto = new ShopDto();
shopDto.setId(shop.getId());
shopDto.setShopId(shop.getShopId());
if (shop.getShopName() != null)
shopDto.setShopName(shop.getShopName());
if (shop.getShopPlatform() != null)
......@@ -97,12 +97,12 @@ public class ShopDto {
this.shopName = shopName;
}
public String getId() {
return id;
public String getShopId() {
return shopId;
}
public void setId(String id) {
this.id = id;
public void setShopId(String shopId) {
this.shopId = shopId;
}
public String getOwner() {
......
......@@ -8,8 +8,8 @@ import org.springframework.data.mongodb.repository.MongoRepository;
import java.util.List;
public interface ShopRepository extends MongoRepository<Shop, String> {
Page<Shop> findByIdInAndIpRegionLike(List<String> shopIds, String ipRegion, Pageable pageable);
Page<Shop> findByIdInAndShopAccountLike(List<String> shopIds, String shopAccount, Pageable pageable);
Page<Shop> findByIdInAndShopNameLike(List<String> shopIds, String shopName, Pageable pageable);
Page<Shop> findByIdIn(List<String> shopIds, Pageable pageable);
Page<Shop> findByShopIdInAndIpRegionLike(List<String> shopIds, String ipRegion, Pageable pageable);
Page<Shop> findByShopIdInAndShopAccountLike(List<String> shopIds, String shopAccount, Pageable pageable);
Page<Shop> findByShopIdInAndShopNameLike(List<String> shopIds, String shopName, Pageable pageable);
Page<Shop> findByShopIdIn(List<String> shopIds, Pageable pageable);
}
......@@ -22,6 +22,7 @@ import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import java.util.HashMap;
import java.util.List;
@Service
......@@ -38,19 +39,13 @@ public class IpResourceServiceImpl implements IpResourceService {
@Autowired
private IpResourceRepository ipResourceRepository;
public HttpHeaders buildHeader(String token) {
public HttpHeaders buildHeader() {
HttpHeaders header = new HttpHeaders();
header.setContentType(MediaType.APPLICATION_JSON);
header.setBearerAuth(token);
header.setBearerAuth("5aFM6ntBcLDD8e8PGMXBybx1UsWYYWvQ0jKOal28XoMhaz7gJyxX5GtayPcY6vec");
return header;
}
public MultiValueMap<String, String> buildBody() {
MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
return map;
}
@Override
public IpResource getIpResourceByIpAddr(String ipAddr) {
IpResource ipResource = ipResourceRepository.findByAddrAndIsDeleted(ipAddr, false);
......@@ -62,11 +57,17 @@ public class IpResourceServiceImpl implements IpResourceService {
@Override
public IpBuyResultDto buyIp(String username, IpResourceRequestDto ipResourceRequestDto) {
RestTemplate restTemplate = new RestTemplate();
HttpHeaders header = buildHeader("Basic YnJvd3Nlcjo=");
MultiValueMap<String, String> map = buildBody();
HttpHeaders header = buildHeader();
MultiValueMap<String, String> map = new LinkedMultiValueMap<>();
map.add("username", username);
map.add("name", ipResourceRequestDto.getName());
map.add("region", ipResourceRequestDto.getRegion());
map.add("vendor", ipResourceRequestDto.getVendor());
map.add("unit", ipResourceRequestDto.getUnit());
map.add("amount", String.valueOf(ipResourceRequestDto.getAmount()));
HttpEntity<MultiValueMap<String, String>> httpEntity = new HttpEntity<>(map, header);
IpBuyResultDto ipBuyResultDto = restTemplate.postForObject(TESTURL + "/intelligroup/ipresources", httpEntity, IpBuyResultDto.class);
return null;
IpBuyResultDto ipBuyResultDto = restTemplate.postForObject(TESTURL + "/intelligroup/ipresources?accountId={username}", httpEntity, IpBuyResultDto.class);
return ipBuyResultDto;
}
@Override
......
......@@ -64,7 +64,7 @@ public class ShopServiceImpl implements ShopService {
if (account.getPermission() < 4) {
throw new ClientRequestException(AccountErrorCode.NOPERMISSION);
}
UserShop us = userShopRepository.findByUsernameAndShopId(username, shopDto.getId());
UserShop us = userShopRepository.findByUsernameAndShopId(username, shopDto.getShopId());
Group group = groupRepository.findById(shopDto.getGroup()).orElse(null);
if (group == null) {
throw new ClientRequestException(BrowserErrorCode.GROUPNOTEXIST);
......@@ -73,7 +73,7 @@ public class ShopServiceImpl implements ShopService {
shopDto.setOwner(username);
Shop shop = new Shop();
shop.of(shopDto);
id = shopRepository.save(shop).getId();
id = shopRepository.save(shop).getShopId();
UserShop userShop = new UserShop();
userShop.setUsername(username);
userShop.setShopId(id);
......@@ -98,11 +98,11 @@ public class ShopServiceImpl implements ShopService {
if (account == null) {
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
}
UserShop userShop = userShopRepository.findByUsernameAndShopId(username, shopDto.getId());
UserShop userShop = userShopRepository.findByUsernameAndShopId(username, shopDto.getShopId());
if (account.getPermission() < 4 || userShop == null) {
throw new ClientRequestException(AccountErrorCode.NOPERMISSION);
}
Shop shop_old = shopRepository.findById(shopDto.getId()).orElseGet(null);
Shop shop_old = shopRepository.findById(shopDto.getShopId()).orElseGet(null);
if (shop_old == null)
throw new ClientRequestException(BrowserErrorCode.SHOPNOTEXIST);
try {
......@@ -112,7 +112,7 @@ public class ShopServiceImpl implements ShopService {
logger.error("fail to update", e.getMessage());
throw new ClientRequestException(BrowserErrorCode.INFORMATIONNOTCOMPELETE);
}
return shop_old.getId();
return shop_old.getShopId();
}
@Override
......@@ -162,7 +162,7 @@ public class ShopServiceImpl implements ShopService {
shop.setIpRegion(ipResource.getIpRegion());
shopRepository.save(shop);
List<String> history = ipResource.getBindHistory();
history.add(shop.getId());
history.add(shop.getShopId());
ipResource.setShopId(shopId);
if (shop.getShopName()!=null)
ipResource.setShopName(shop.getShopName());
......@@ -239,7 +239,7 @@ public class ShopServiceImpl implements ShopService {
throw new ClientRequestException(AccountErrorCode.NOPERMISSION);
}
Pageable pageable = PageRequest.of(0, 100);
List<Shop> shops = shopRepository.findByIdIn(shopIds, pageable).getContent();
List<Shop> shops = shopRepository.findByShopIdIn(shopIds, pageable).getContent();
if (shops == null || shops.size() < 1)
throw new ClientRequestException(BrowserErrorCode.SHOPNOTEXIST);
List<Account> accounts = accountRepository.findByNameIn(users);
......@@ -248,10 +248,10 @@ public class ShopServiceImpl implements ShopService {
accounts.stream().forEach(x -> {
try {
for (Shop shop:shops){
UserShop userShop1 = userShopRepository.findByUsernameAndShopId(x.getName(), shop.getId());
UserShop userShop1 = userShopRepository.findByUsernameAndShopId(x.getName(), shop.getShopId());
if (userShop1 != null)
return;
userShopRepository.save(new UserShop(x.getName(), shop.getId()));
userShopRepository.save(new UserShop(x.getName(), shop.getShopId()));
}
} catch (Exception e) {
logger.error("fail to assign", e.getMessage());
......@@ -282,13 +282,13 @@ public class ShopServiceImpl implements ShopService {
map(x -> x.getShopId()).collect(Collectors.toList());
Page<Shop> shops;
if (filterDto != null && StringUtils.isNotBlank(filterDto.getIpRegion()))
shops = shopRepository.findByIdInAndIpRegionLike(shopIds, filterDto.getIpRegion(), pageable);
shops = shopRepository.findByShopIdInAndIpRegionLike(shopIds, filterDto.getIpRegion(), pageable);
else if (filterDto != null && StringUtils.isNotBlank(filterDto.getShopAccount()))
shops = shopRepository.findByIdInAndShopAccountLike(shopIds, filterDto.getShopAccount(), pageable);
shops = shopRepository.findByShopIdInAndShopAccountLike(shopIds, filterDto.getShopAccount(), pageable);
else if (filterDto != null && StringUtils.isNotBlank(filterDto.getShopName()))
shops = shopRepository.findByIdInAndShopNameLike(shopIds, filterDto.getShopName(), pageable);
shops = shopRepository.findByShopIdInAndShopNameLike(shopIds, filterDto.getShopName(), pageable);
else
shops = shopRepository.findByIdIn(shopIds, pageable);
shops = shopRepository.findByShopIdIn(shopIds, pageable);
if (shops == null || shops.getNumberOfElements() < 1)
return new ShopPageResultDto();
List<ShopDto> shopDtos = new ArrayList<>();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment