Commit 5a531ac9 authored by renjie's avatar renjie

修改shop接口

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