Commit 38acd057 authored by xuxin's avatar xuxin

注册bug修复以及店铺列表部分业务修改

parent 81554bc8
......@@ -17,7 +17,7 @@ public interface AccountRepository extends MongoRepository<Account, String>, Acc
Account findByEmail(String email);
Account findByPhoneNumber(String phone);
Account findOneByPhoneNumber(String phone);
Account findByPhoneNumberAndParentIsNull(String phone);
......
......@@ -426,8 +426,8 @@ public class AccountServiceImpl implements AccountService {
public Account createWithSms(User user) {
// 1. 校验注册用户是否已存在
Account existing1 = accountRepository.findByName(user.getUsername()).orElse(null);
Account existing2 = accountRepository.findByPhoneNumber(user.getUsername());
Account existing3 = accountRepository.findByPhoneNumber(user.getPhone());
Account existing2 = accountRepository.findOneByPhoneNumber(user.getUsername());
Account existing3 = accountRepository.findOneByPhoneNumber(user.getPhone());
Account existing4 = accountRepository.findByName(user.getPhone()).orElse(null);
if (existing1 != null || existing2 != null || existing3 != null || existing4 != null) {
throw new ClientRequestException(AccountErrorCode.NAMEEXIST, "account already exists: " + user.getUsername());
......@@ -492,7 +492,7 @@ public class AccountServiceImpl implements AccountService {
if (existing != null) {
throw new ClientRequestException(AccountErrorCode.NAMEEXIST, "account already exists: " + user.getUsername());
}
existing = accountRepository.findByPhoneNumber(user.getUsername());
existing = accountRepository.findOneByPhoneNumber(user.getUsername());
if (existing != null) {
throw new ClientRequestException(AccountErrorCode.NAMEEXIST, "account already exists: " + user.getUsername());
}
......@@ -617,12 +617,12 @@ public class AccountServiceImpl implements AccountService {
}
if (!StringUtils.isEmpty(user.getPhoneNumber())) {
existing = accountRepository.findByPhoneNumber(user.getPhoneNumber());
existing = accountRepository.findOneByPhoneNumber(user.getPhoneNumber());
if (existing != null)
throw new ClientRequestException(AccountErrorCode.PHONEEXIST, "phone number already exists: " + user.getEmail());
}
existing = accountRepository.findByPhoneNumber(user.getName());
existing = accountRepository.findOneByPhoneNumber(user.getName());
if (existing != null) {
throw new ClientRequestException(AccountErrorCode.PHONEEXIST, "phone number already exists: " + user.getEmail());
}
......@@ -918,7 +918,7 @@ public class AccountServiceImpl implements AccountService {
@Override
public AccountDto getAccountByCellphone(String cellphone) {
Account account = accountRepository.findByPhoneNumber(cellphone);
Account account = accountRepository.findOneByPhoneNumber(cellphone);
if (account == null) {
return null;
}
......
......@@ -169,7 +169,7 @@ public class ShopController {
} catch (ClientRequestException e) {
dealClientRequestException(resultDto, e);
}
logger.info("getshoplist totalTime:{}, {}", principal.getName(), System.currentTimeMillis() - start);
logger.info("getshoplist totalTime:{}, {},{}", principal.getName(), System.currentTimeMillis() - start, Thread.currentThread().getName());
return resultDto;
}
......@@ -180,6 +180,7 @@ public class ShopController {
@RequestMapping(value = "/penghai/list", method = RequestMethod.POST)
public ResultDto getPenghaiShopList(Principal principal, @RequestBody ShopRequestDto shopRequestDto) {
logger.info("shop list params {}", JSONObject.toJSONString(shopRequestDto));
long start = System.currentTimeMillis();
ResultDto resultDto = new ResultDto();
try {
......@@ -190,6 +191,7 @@ public class ShopController {
} catch (ClientRequestException e) {
dealClientRequestException(resultDto, e);
}
logger.info("getshoplist totalTime:{},{}, {},{}", "penghai", principal.getName(), System.currentTimeMillis() - start, Thread.currentThread().getName());
return resultDto;
}
......
......@@ -470,6 +470,10 @@ public class ShopServiceImpl implements ShopService {
ShopPageResultDto<ShopResultDto> shopPageResultDto = new ShopPageResultDto<>();
if (shops != null && shops.getNumberOfElements() >= 1) {
List<ShopResultDto> shopResultDtos = new ArrayList<>();
SpecialLine specialLine = specialLineRepository.findAll().get(0);
List<IpResource> pageIpResourceListToSave = new ArrayList<>();
shops.getContent().stream().forEach(
// 设置ip资源状态 并 封装 shopResultDto信息
x -> {
......@@ -481,34 +485,32 @@ public class ShopServiceImpl implements ShopService {
if (ipResource.getValidTime() <= Instant.now().plusSeconds(60 * 60 * 24 * 7).toEpochMilli() && ipResource.getValidTime() > Instant.now().toEpochMilli()) {
if (ipResource.getStatus() != 5 && ipResource.getStatus() != 3 && ipResource.getStatus() != 6) {
ipResource.setStatus(2);
ipResourceRepository.save(ipResource);
//ipResourceRepository.save(ipResource);
pageIpResourceListToSave.add(ipResource);
}
// 2. ip资源在七天前到期,且 ip 资源的状态不是 3(正在分配)、6(未分配),则删除 ip 资源
} else if (ipResource.getValidTime() <= Instant.now().minusSeconds(60 * 60 * 24 * 7).toEpochMilli() && ipResource.getStatus() != 3 && ipResource.getStatus() != 6) {
if (ipResource.getIpType() == IpType.VENDOR) {
IpResourceRequestDto ipResourceRequestDto1 = new IpResourceRequestDto();
if (ipResource.getIpType() == IpType.VENDOR) {
ipResourceRequestDto1.setAddr(Arrays.asList(ipResource.getAddr()));
try {
ipResourceService.deleteExpiredIp(username, ipResourceRequestDto1);
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
} else {
IpResourceRequestDto ipResourceRequestDto1 = new IpResourceRequestDto();
ipResourceRequestDto1.setIpId(Arrays.asList(ipResource.getId()));
}
try {
ipResourceService.deleteExpiredIp(username, ipResourceRequestDto1);
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
return;
// 3. ip资源到期,且 ip 资源的状态不是 3(正在分配)、6(未分配),则设置 ip 资源的状态为 1(已过期)
} else if (ipResource.getValidTime() <= Instant.now().toEpochMilli() && ipResource.getStatus() != 3 && ipResource.getStatus() != 6) {
ipResource.setStatus(1);
ipResourceRepository.save(ipResource);
//ipResourceRepository.save(ipResource);
pageIpResourceListToSave.add(ipResource);
// 4. 其他,将ip资源状态设置为 未使用
} else {
......@@ -517,16 +519,19 @@ public class ShopServiceImpl implements ShopService {
} else if (ipResource.getIpType().equals(IpType.LOCAL) && (ipResource.getStatus() == 1 || ipResource.getStatus() == 2) && ipResource.getAddr().equals("本地Ip未使用")) {
ipResource.setStatus(4);
}
ipResourceRepository.save(ipResource);
// ipResourceRepository.save(ipResource);
pageIpResourceListToSave.add(ipResource);
}
}
ShopResultDto shopResultDto = getShopResultDto(username, x, ipResource);
//ShopResultDto shopResultDto = getShopResultDto(username, x, ipResource, specialLine);
ShopResultDto shopResultDto = getShopResultDto(groupId, x, ipResource, specialLine);
shopResultDtos.add(shopResultDto);
logger.info("getshoplist step-6.x:{},{}", username, System.currentTimeMillis() - start1);
logger.info("getshoplist step-6.x:{},{},{}", username, System.currentTimeMillis() - start1, Thread.currentThread().getName());
}
);
ipResourceRepository.saveAll(pageIpResourceListToSave);
Page<ShopResultDto> shopDtoPage = new PageImpl<>(shopResultDtos, pageable, shopIds.size());
shopPageResultDto.setShopList(shopDtoPage.getContent());
......@@ -754,18 +759,31 @@ public class ShopServiceImpl implements ShopService {
return shops;
}
private ShopResultDto getShopResultDto(String username, Shop x, IpResource ipResource) {
/*private ShopResultDto getShopResultDto(String username, Shop x, IpResource ipResource, SpecialLine specialLine) {
if (ipResource == null) {
ipResource = new IpResource();
}
String group1 = userShopRepository.findByUsernameAndShopId(username, x.getShopId()).getGroupId();
ShopResultDto shopResultDto = null;
if (ipResource.isSpecialLine()) {
SpecialLine specialLine = specialLineRepository.findAll().get(0);
shopResultDto = ShopResultDto.of(x, group1, new IpResourceDto(ipResource, null, false, specialLine));
} else {
shopResultDto = ShopResultDto.of(x, group1, new IpResourceDto(ipResource, null, false));
}
return shopResultDto;
}*/
private ShopResultDto getShopResultDto(String groupId, Shop x, IpResource ipResource, SpecialLine specialLine) {
if (ipResource == null) {
ipResource = new IpResource();
}
ShopResultDto shopResultDto = null;
if (ipResource.isSpecialLine()) {
shopResultDto = ShopResultDto.of(x, groupId, new IpResourceDto(ipResource, null, false, specialLine));
} else {
shopResultDto = ShopResultDto.of(x, groupId, new IpResourceDto(ipResource, null, false));
}
return shopResultDto;
}
}
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