Commit 45d74932 authored by renjie's avatar renjie

shop接口修改

parent 12d5e24f
......@@ -42,6 +42,12 @@ public class Account {
private List<String> whiteList = new ArrayList<>();
private int childCount = 0;
private int groupCount = 0;
private int shopCount = 0;
public Date getSignupDate() {
return signupDate;
}
......@@ -178,4 +184,28 @@ public class Account {
public void setWhiteList(List<String> whiteList) {
this.whiteList = whiteList;
}
public int getChildCount() {
return childCount;
}
public void setChildCount(int childCount) {
this.childCount = childCount;
}
public int getGroupCount() {
return groupCount;
}
public void setGroupCount(int groupCount) {
this.groupCount = groupCount;
}
public int getShopCount() {
return shopCount;
}
public void setShopCount(int shopCount) {
this.shopCount = shopCount;
}
}
......@@ -51,7 +51,10 @@ public enum AccountErrorCode implements ErrorCode {
/** alipay errors */
ALIPAYERROR(ACCOUNT_BASE+130, "Alipay order generation error"),
NOPERMISSION(ACCOUNT_BASE+140, "You have no right to do this operarion");
NOPERMISSION(ACCOUNT_BASE+140, "You have no right to do this operarion"),
GROUPMAX(ACCOUNT_BASE+141, "You can not have more groups"),
SHOPMAX(ACCOUNT_BASE+141, "You can not have more shops"),
CHILDMAX(ACCOUNT_BASE+141, "You can not have more subUsers");
......
......@@ -2,7 +2,7 @@ package com.edgec.browserbackend.browser.dto;
public class ShopPageInfo {
int currentPage;
int totalPage;
int totalPages;
int totalShops;
public int getCurrentPage() {
......@@ -13,12 +13,12 @@ public class ShopPageInfo {
this.currentPage = currentPage;
}
public int getTotalPage() {
return totalPage;
public int getTotalPages() {
return totalPages;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
public void setTotalPages(int totalPage) {
this.totalPages = totalPage;
}
public int getTotalShops() {
......
......@@ -2,6 +2,7 @@ package com.edgec.browserbackend.browser.service.Impl;
import com.edgec.browserbackend.account.domain.Account;
import com.edgec.browserbackend.account.exception.AccountErrorCode;
import com.edgec.browserbackend.account.repository.AccountRepository;
import com.edgec.browserbackend.browser.ErrorCode.BrowserErrorCode;
import com.edgec.browserbackend.browser.domain.Group;
import com.edgec.browserbackend.browser.dto.GroupDto;
......@@ -23,6 +24,9 @@ public class GroupServiceImpl implements GroupService {
private final Logger logger = LoggerFactory.getLogger(GroupServiceImpl.class);
@Autowired
private AccountRepository accountRepository;
@Autowired
private GroupRepository groupRepository;
......@@ -33,6 +37,11 @@ public class GroupServiceImpl implements GroupService {
public String addGroup(String username, String groupName) {
if (StringUtils.isBlank(username) || StringUtils.isBlank(groupName))
throw new ClientRequestException(BrowserErrorCode.INFORMATIONNOTCOMPELETE);
Account account = accountRepository.findByName(username);
if (account == null)
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
if (account.getGroupCount() >= 100)
throw new ClientRequestException(AccountErrorCode.GROUPMAX);
Group group = new Group();
group.setOwner(username);
group.setName(groupName);
......
......@@ -65,6 +65,9 @@ public class ShopServiceImpl implements ShopService {
if (account.getPermission() < 4) {
throw new ClientRequestException(AccountErrorCode.NOPERMISSION);
}
if (account.getShopCount() >= 10000) {
throw new ClientRequestException(AccountErrorCode.SHOPMAX);
}
UserShop us = userShopRepository.findByUsernameAndShopId(username, shopDto.getShopId());
Group group = groupRepository.findById(shopDto.getGroup()).orElse(null);
if (group == null) {
......@@ -317,7 +320,7 @@ public class ShopServiceImpl implements ShopService {
shopPageResultDto.setShopList(shopDtoPage.getContent());
ShopPageInfo shopPageInfo = new ShopPageInfo();
shopPageInfo.setCurrentPage(shopDtoPage.getPageable().getPageNumber() + 1);
shopPageInfo.setTotalPage(shopDtoPage.getTotalPages());
shopPageInfo.setTotalPages(shopDtoPage.getTotalPages());
shopPageInfo.setTotalShops(shopDtos.size());
shopPageResultDto.setShopPage(shopPageInfo);
return shopPageResultDto;
......
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