Commit 569a504f authored by renjie's avatar renjie

shop

parent fadeaf0d
package com.edgec.browserbackend.account.dto;
public class MobileDto {
String mobile;
String sign;
String sign_time;
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getSign() {
return sign;
}
public void setSign(String sign) {
this.sign = sign;
}
public String getSign_time() {
return sign_time;
}
public void setSign_time(String sign_time) {
this.sign_time = sign_time;
}
}
......@@ -2,7 +2,7 @@ package com.edgec.browserbackend.account.dto;
import java.util.Map;
public class AccountResultDto {
public class ResultDto {
private int status;
private Map<String, Object> statusInfo;
private Object data;
......
......@@ -49,7 +49,9 @@ public enum AccountErrorCode implements ErrorCode {
WECHATERROR(ACCOUNT_BASE+120, "Wechat order generation error"),
/** alipay errors */
ALIPAYERROR(ACCOUNT_BASE+130, "Alipay order generation error");
ALIPAYERROR(ACCOUNT_BASE+130, "Alipay order generation error"),
NOPERMISSION(SHOP_BASE+200, "You have no right to do this operarion");
......
package com.edgec.browserbackend.account.service;
import com.edgec.browserbackend.account.domain.*;
import com.edgec.browserbackend.account.dto.AccountResultDto;
import com.edgec.browserbackend.account.dto.ResultDto;
import com.edgec.browserbackend.account.dto.BillQueryCriteriaDto;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
......@@ -19,7 +19,7 @@ public interface AccountService {
*/
Account findByName(String accountName);
AccountResultDto getAccountByName(String name);
ResultDto getAccountByName(String name);
/**
* Checks if account with the same name already exists
......@@ -75,7 +75,7 @@ public interface AccountService {
Page<UserPayment> getUserPayment(Pageable pageable, String username);
void sendSmsOtp(String phone, String by);
void sendSmsOtp(String phone);
AccountDto getAccountByCellphone(String cellphone);
......
......@@ -23,7 +23,7 @@ public class SmsUtils {
* Generate and send the SMS one time password to user's phone with SMS.
* @param phone
*/
public static String sendSmsOTP(String phone, String by) {
public static String sendSmsOTP(String phone) {
String randomCode = createRandom(true,6);
DefaultProfile profile = DefaultProfile.getProfile("default", "LTAIODPWRh6stFca", "0SBDR59HsquSDEj9CFXNt9njTs2cCv");
IAcsClient client = new DefaultAcsClient(profile);
......@@ -34,11 +34,7 @@ public class SmsUtils {
request.setDomain("dysmsapi.aliyuncs.com");
request.setVersion("2017-05-25");
request.setAction("SendSms");
if ("1".equals(by)) {
request.putQueryParameter("SignName", "防关联VPS");
} else {
request.putQueryParameter("SignName", "深圳云端CLOUDAM");
}
request.putQueryParameter("SignName", "深圳云端CLOUDAM");
request.putQueryParameter("PhoneNumbers", phone);
request.putQueryParameter("TemplateCode", "SMS_163437667");
request.putQueryParameter("TemplateParam", "{\"code\":\""+randomCode+"\"}");
......
package com.edgec.browserbackend.account.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.edgec.browserbackend.account.dto.AccountResultDto;
import com.edgec.browserbackend.account.dto.ResultDto;
import com.edgec.browserbackend.account.dto.CvmChargeRegion;
import com.edgec.browserbackend.account.service.AccountService;
import com.edgec.browserbackend.account.service.PaymentService;
......@@ -11,6 +11,7 @@ import com.edgec.browserbackend.account.exception.AccountErrorCode;
import com.edgec.browserbackend.account.repository.*;
import com.edgec.browserbackend.account.service.EmailService;
import com.edgec.browserbackend.account.utils.AccountServicePool;
import com.edgec.browserbackend.auth.exception.AuthErrorCode;
import com.edgec.browserbackend.auth.service.UserAuthService;
import com.edgec.browserbackend.common.charge.ChargeType;
import com.edgec.browserbackend.common.commons.error.ClientRequestException;
......@@ -501,34 +502,38 @@ public class AccountServiceImpl implements AccountService {
}
@Override
public AccountResultDto getAccountByName(String name) {
public ResultDto getAccountByName(String name) {
Assert.hasLength(name);
AccountResultDto accountResultDto = new AccountResultDto();
ResultDto resultDto = new ResultDto();
try {
Account account = repository.findByName(name);
if (account == null) {
accountResultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", AccountErrorCode.NAMENOTEXIST);
statusInfo.put("message", (new ClientRequestException(AccountErrorCode.NAMENOTEXIST)).getMessage());
accountResultDto.setStatusInfo(statusInfo);
}
Account account = this.findByName(name);
AccountDto current = new AccountDto(account);
UserBalance userBalance = userBalanceRepository.findById(name).orElse(null);
if (userBalance != null)
current.setBalance(Math.round(userBalance.getBalanced()));
else
current.setBalance(0);
if (StringUtils.isEmpty(account.getParent())) {
account.setAllowedToCreateSubUser(true);
current.setPermission(15);
current.setAllowedToCreateSubUser(true);
}
Optional<UserBalance> userBalance = userBalanceRepository.findById(name);
AccountDto accountDto = new AccountDto(account);
accountDto.setBalance((int)userBalance.get().getBalanced());
accountResultDto.setStatus(0);
accountResultDto.setData(accountDto);
List<AccountDto> child = repository.findByParent(name).stream().map(item -> new AccountDto(item)).collect(Collectors.toList());
current.setChild(child);
resultDto.setStatus(0);
resultDto.setData(current);
} catch (Exception e) {
accountResultDto.setStatus(-1);
resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", AccountErrorCode.NAMENOTEXIST);
statusInfo.put("message", (new ClientRequestException(AccountErrorCode.NAMENOTEXIST)).getMessage());
accountResultDto.setStatusInfo(statusInfo);
statusInfo.put("message", (AuthErrorCode.NAMENOTEXIST.getReason()));
resultDto.setStatusInfo(statusInfo);
}
return accountResultDto;
return resultDto;
}
public void deleteByName(String name) {
......@@ -871,8 +876,8 @@ public class AccountServiceImpl implements AccountService {
}
@Override
public void sendSmsOtp(String phone, String by) {
String code = com.edgec.browserbackend.account.service.SmsUtils.sendSmsOTP(phone, by);
public void sendSmsOtp(String phone) {
String code = com.edgec.browserbackend.account.service.SmsUtils.sendSmsOTP(phone);
Otp otp = new Otp();
otp.setPhone(phone);
otp.setOtp(code);
......
......@@ -15,7 +15,7 @@ import javax.validation.Valid;
import java.security.Principal;
@RestController
@RequestMapping("/users")
@RequestMapping("/auth")
public class UserController {
@Autowired
......
package com.edgec.browserbackend.browser.ErrorCode;
import com.edgec.browserbackend.common.commons.error.ErrorCode;
import com.fasterxml.jackson.annotation.JsonValue;
public enum BrowserErrorCode implements ErrorCode {
/* client errors */
UNKNOWN(ErrorCode.COMMON_UNKNOWN,"unknown"),
INFORMATIONNOTCOMPELETE(BROWSER_BASE+100, "The information about shop is not complete"),
SHOPNOTEXIST(BROWSER_BASE+101, "The shop is not exist"),
IPNOTEXIST(BROWSER_BASE+201, "The ip is not exist"),
GROUPNOTEXIST(BROWSER_BASE+301, "The group is not exist");
private final int code;
private final String reason;
private BrowserErrorCode(int value, String reasonPhrase) {
this.code = value;
this.reason = reasonPhrase;
}
public int value() {
return this.code;
}
@JsonValue
public int getCode() {
return code;
}
@Override
public String toString() {
return Integer.toString(this.code);
}
public String getReason() {
return reason;
}
}
package com.edgec.browserbackend.browser.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/group")
public class GroupController {
}
package com.edgec.browserbackend.browser.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/ip")
public class IpControlloer {
}
package com.edgec.browserbackend.browser.controller;
import com.edgec.browserbackend.account.dto.ResultDto;
import com.edgec.browserbackend.browser.domain.Shop;
import com.edgec.browserbackend.browser.service.ShopService;
import com.edgec.browserbackend.common.commons.error.ClientRequestException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.security.Principal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/shop")
public class ShopController {
@Autowired
private ShopService shopService;
@RequestMapping(value = "/add", method = RequestMethod.POST)
public ResultDto addShop(Principal principal, @RequestBody Shop shop) {
ResultDto resultDto = new ResultDto();
try {
shopService.addShop(principal.getName(), shop);
resultDto.setStatus(0);
}catch (ClientRequestException e) {
resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", e.getErrorCode());
statusInfo.put("message", e.getMessage());
resultDto.setStatusInfo(statusInfo);
}
return resultDto;
}
@RequestMapping(value = "/multiadd", method = RequestMethod.POST)
public List<String> addShops(Principal principal, @RequestBody List<Shop> shops) {
return null;
}
@RequestMapping(value = "/update", method = RequestMethod.POST)
public String updateShop(Principal principal, Shop shop) {
return null;
}
@RequestMapping(value = "/delete", method = RequestMethod.POST)
public void deleteShop(String username, String shopId) {
}
@RequestMapping(value = "/bind", method = RequestMethod.POST)
public void bindShop(String username, String shopId, String ipAddr) {
}
@RequestMapping(value = "/unbind", method = RequestMethod.POST)
public void unBindShop(String username, String shopId) {
}
@RequestMapping(value = "/transfer", method = RequestMethod.POST)
public void transferShop(String useranme, String shopId, String groupId) {
}
@RequestMapping(value = "/assign", method = RequestMethod.POST)
public void assignShop(String username, String shopId, List<String> users) {
}
@RequestMapping(value = "/list",method = RequestMethod.POST)
public List<Shop> getShopList(String username, String groupId, int page, int amount, Map<String, String> filter) {
return null;
}
}
......@@ -11,5 +11,37 @@ public class Group {
private String id;
private String groupName;
private String owner;
private List<String> shops;
private String details;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getOwner() {
return owner;
}
public void setOwner(String owner) {
this.owner = owner;
}
public String getGroupName() {
return groupName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
public String getDetails() {
return details;
}
public void setDetails(String details) {
this.details = details;
}
}
......@@ -21,4 +21,99 @@ public class IpResource {
List<Long> bindHistory;
private boolean isDeleted;
public String getDetails() {
return details;
}
public void setDetails(String details) {
this.details = details;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getIpRegion() {
return ipRegion;
}
public void setIpRegion(String ipRegion) {
this.ipRegion = ipRegion;
}
public IpStatus getIpStatus() {
return ipStatus;
}
public void setIpStatus(IpStatus ipStatus) {
this.ipStatus = ipStatus;
}
public IpType getIpType() {
return ipType;
}
public void setIpType(IpType ipType) {
this.ipType = ipType;
}
public List<Long> getBindHistory() {
return bindHistory;
}
public void setBindHistory(List<Long> bindHistory) {
this.bindHistory = bindHistory;
}
public long getCreatedAt() {
return createdAt;
}
public void setCreatedAt(long createdAt) {
this.createdAt = createdAt;
}
public long getLeftTime() {
return leftTime;
}
public void setLeftTime(long leftTime) {
this.leftTime = leftTime;
}
public long getValidTime() {
return validTime;
}
public void setValidTime(long validTime) {
this.validTime = validTime;
}
public String getIpAddr() {
return ipAddr;
}
public void setIpAddr(String ipAddr) {
this.ipAddr = ipAddr;
}
public String getIpProvider() {
return ipProvider;
}
public void setIpProvider(String ipProvider) {
this.ipProvider = ipProvider;
}
public boolean isDeleted() {
return isDeleted;
}
public void setDeleted(boolean deleted) {
isDeleted = deleted;
}
}
package com.edgec.browserbackend.browser.domain;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
@Document(collection = "shop")
@JsonIgnoreProperties(ignoreUnknown = true)
public class Shop {
@Id
......@@ -29,4 +31,119 @@ public class Shop {
private String ipId;
public Shop(){
}
public Shop of(Shop shop) {
if (shop.getGroupId() != null)
this.setGroupId(shop.getGroupId());
if (shop.getGroupName() != null)
this.setGroupName(shop.getGroupName());
if (shop.getIp() != null)
this.setIp(shop.getIp());
if (shop.getIpId() != null)
this.setIpId(shop.getIpId());
if (shop.getIpRegion() != null)
this.setIpRegion(shop.getIpRegion());
if (shop.getLink() != null)
this.setLink(shop.getLink());
if (shop.getOwner() != null)
this.setOwner(shop.getOwner());
if (shop.getPlatform() != null)
this.setPlatform(shop.getPlatform());
if (shop.getShopName() != null)
this.setShopName(shop.getShopName());
if (shop.getTransferStatus() != null)
this.setTransferStatus(shop.getTransferStatus());
return this;
}
public String getIp() {
return ip;
}
public String getId() {
return id;
}
public String getGroupId() {
return groupId;
}
public String getGroupName() {
return groupName;
}
public String getIpId() {
return ipId;
}
public String getIpRegion() {
return ipRegion;
}
public String getLink() {
return link;
}
public String getOwner() {
return owner;
}
public String getPlatform() {
return platform;
}
public String getShopName() {
return shopName;
}
public TransferStatus getTransferStatus() {
return transferStatus;
}
public void setIp(String ip) {
this.ip = ip;
}
public void setId(String id) {
this.id = id;
}
public void setGroupId(String groupId) {
this.groupId = groupId;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
public void setIpId(String ipId) {
this.ipId = ipId;
}
public void setIpRegion(String ipRegion) {
this.ipRegion = ipRegion;
}
public void setLink(String link) {
this.link = link;
}
public void setOwner(String owner) {
this.owner = owner;
}
public void setPlatform(String platform) {
this.platform = platform;
}
public void setShopName(String shopName) {
this.shopName = shopName;
}
public void setTransferStatus(TransferStatus transferStatus) {
this.transferStatus = transferStatus;
}
}
package com.edgec.browserbackend.browser.domain;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.List;
@Document("usershops")
public class UserShop {
@Id
private String id;
private String username;
private String shopId;
private String groupId;
public UserShop(){
}
public UserShop(String username, String shopId) {
this.username = username;
this.shopId = shopId;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getShopId() {
return shopId;
}
public void setShopId(String shopId) {
this.shopId = shopId;
}
public String getGroupId() {
return groupId;
}
public void setGroupId(String groupId) {
this.groupId = groupId;
}
}
package com.edgec.browserbackend.browser.domain;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.List;
@Document("usershops")
public class UserShops {
@Id
private String username;
private List<String> shopIds;
}
package com.edgec.browserbackend.browser.dto;
import com.edgec.browserbackend.browser.domain.Shop;
public class ShopDtoMap {
private Shop shop;
private String shopId;
public Shop getShop() {
return shop;
}
public void setShop(Shop shop) {
this.shop = shop;
}
public String getShopId() {
return shopId;
}
public void setShopId(String shopId) {
this.shopId = shopId;
}
}
......@@ -4,4 +4,5 @@ import com.edgec.browserbackend.browser.domain.IpResource;
import org.springframework.data.mongodb.repository.MongoRepository;
public interface IpResourceRepository extends MongoRepository<IpResource, String> {
IpResource findByIpAddr(String ipAddr);
}
......@@ -4,4 +4,5 @@ import com.edgec.browserbackend.browser.domain.Shop;
import org.springframework.data.mongodb.repository.MongoRepository;
public interface ShopRepository extends MongoRepository<Shop, String> {
}
package com.edgec.browserbackend.browser.repository;
public interface ShopRepositoryCustom {
}
package com.edgec.browserbackend.browser.repository;
import com.edgec.browserbackend.browser.domain.UserShop;
import com.mongodb.client.result.DeleteResult;
import org.bson.Document;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.BasicQuery;
import static org.springframework.data.mongodb.core.query.Criteria.where;
public class ShopRepositoryCustomImpl implements ShopRepositoryCustom {
@Autowired
private MongoTemplate mongoTemplate;
}
package com.edgec.browserbackend.browser.repository;
import com.edgec.browserbackend.browser.domain.UserShop;
import org.springframework.data.mongodb.repository.MongoRepository;
import java.util.List;
public interface UserShopRepository extends MongoRepository<UserShop, String>, UserShopRepositoryCustom {
List<UserShop> findByUsername(String username);
UserShop findByUsernameAndShopId(String username, String shopId);
UserShop findByShopId(String shopId);
}
package com.edgec.browserbackend.browser.repository;
public interface UserShopRepositoryCustom {
boolean deleteByUsernameAndShopId(String username, String shopId);
}
package com.edgec.browserbackend.browser.repository;
import com.edgec.browserbackend.account.domain.User;
import com.edgec.browserbackend.account.domain.UserPayment;
import com.edgec.browserbackend.browser.domain.UserShop;
import com.mongodb.client.result.DeleteResult;
import com.mongodb.client.result.UpdateResult;
import org.bson.Document;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.BasicQuery;
import org.springframework.data.mongodb.core.query.Update;
import static org.springframework.data.mongodb.core.query.Criteria.where;
public class UserShopRepositoryCustomImpl implements UserShopRepositoryCustom {
@Autowired
private MongoTemplate mongoTemplate;
@Override
public boolean deleteByUsernameAndShopId(String username, String shopId) {
Document doc = new Document();
BasicQuery basicQuery = new BasicQuery(doc);
basicQuery.addCriteria(where("username").is(username).and("shopId").is(shopId));
DeleteResult operation = mongoTemplate.remove(basicQuery, UserShop.class);
if (operation.getDeletedCount() < 1)
return false;
else
return true;
}
}
package com.edgec.browserbackend.browser.repository;
import org.springframework.data.mongodb.repository.MongoRepository;
public interface UserShops extends MongoRepository<UserShops, String> {
public UserShops findByUsername(String username);
}
package com.edgec.browserbackend.browser.service;
public interface GroupService {
}
package com.edgec.browserbackend.browser.service.Impl;
import com.edgec.browserbackend.browser.service.GroupService;
import org.springframework.stereotype.Service;
@Service
public class GroupServiceImpl implements GroupService {
}
package com.edgec.browserbackend.browser.service.Impl;
import com.edgec.browserbackend.account.domain.Account;
import com.edgec.browserbackend.account.repository.AccountRepository;
import com.edgec.browserbackend.browser.ErrorCode.BrowserErrorCode;
import com.edgec.browserbackend.browser.domain.IpResource;
import com.edgec.browserbackend.browser.repository.IpResourceRepository;
import com.edgec.browserbackend.browser.service.IpResourceService;
import com.edgec.browserbackend.common.commons.error.ClientRequestException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class IpResourceServiceImpl implements IpResourceService {
@Autowired
private AccountRepository accountRepository;
@Autowired
private IpResourceRepository ipResourceRepository;
@Override
public IpResource getIpResourceByIpAddr(String ipAddr) {
IpResource ipResource = ipResourceRepository.findByIpAddr(ipAddr);
if (ipResource == null)
throw new ClientRequestException(BrowserErrorCode.IPNOTEXIST);
return ipResource;
}
}
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.domain.IpResource;
import com.edgec.browserbackend.browser.domain.Shop;
import com.edgec.browserbackend.browser.domain.UserShop;
import com.edgec.browserbackend.browser.repository.GroupRepository;
import com.edgec.browserbackend.browser.repository.IpResourceRepository;
import com.edgec.browserbackend.browser.repository.ShopRepository;
import com.edgec.browserbackend.browser.repository.UserShopRepository;
import com.edgec.browserbackend.browser.service.ShopService;
import com.edgec.browserbackend.common.commons.error.ClientRequestException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Service
@Transactional
public class ShopServiceImpl implements ShopService {
@Autowired
ShopRepository shopRepository;
@Autowired
AccountRepository accountRepository;
@Autowired
UserShopRepository userShopRepository;
@Autowired
GroupRepository groupRepository;
@Autowired
IpResourceRepository ipResourceRepository;
@Override
public String addShop(String username, Shop shop) {
Account account = accountRepository.findByName(username);
String id = null;
if (account == null) {
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
}
if (account.getPermission() < 4) {
throw new ClientRequestException(AccountErrorCode.NOPERMISSION);
}
if (shop.getGroupId() != null) {
transferShop(username, shop.getId(), shop.getGroupId());
}
try {
shop.setOwner(username);
id = shopRepository.save(shop).getId();
userShopRepository.save(new UserShop(username, id));
}catch (Exception e) {
throw new ClientRequestException(BrowserErrorCode.INFORMATIONNOTCOMPELETE);
}
return id;
}
@Override
public List<String> addShops(String username, List<Shop> shops) {
return null;
}
@Override
public String updateShop(String username, Shop shop) {
Account account = accountRepository.findByName(username);
if (account == null) {
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
}
if (account.getPermission() < 4) {
throw new ClientRequestException(AccountErrorCode.NOPERMISSION);
}
if (shop.getGroupId() != null) {
transferShop(username, shop.getId(), shop.getGroupId());
}
Shop shop_old = shopRepository.findById(shop.getId()).orElseGet(null);
if (shop_old == null)
throw new ClientRequestException(BrowserErrorCode.SHOPNOTEXIST);
try {
shop_old = shop_old.of(shop);
shopRepository.save(shop_old);
}catch (Exception e) {
throw new ClientRequestException(BrowserErrorCode.INFORMATIONNOTCOMPELETE);
}
return null;
}
@Override
public void deleteShop(String username, String shopId) {
Account account = accountRepository.findByName(username);
if (account == null) {
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
}
if (account.getPermission() < 4) {
throw new ClientRequestException(AccountErrorCode.NOPERMISSION);
}
Shop shop = shopRepository.findById(shopId).orElse(null);
if (shop == null)
throw new ClientRequestException(BrowserErrorCode.SHOPNOTEXIST);
if (shop.getIpId() != null && shop.getIp() != null) {
unBindShop(username, shopId);
}
boolean result = userShopRepository.deleteByUsernameAndShopId(username, shopId);
if (result) {
shopRepository.deleteById(shopId);
} else throw new ClientRequestException(AccountErrorCode.NOPERMISSION);
}
@Override
public void bindShop(String username, String shopId, String ipAddr) {
Account account = accountRepository.findByName(username);
if (account == null) {
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
}
if (account.getPermission() < 4) {
throw new ClientRequestException(AccountErrorCode.NOPERMISSION);
}
Shop shop = shopRepository.findById(shopId).orElse(null);
if (shop == null)
throw new ClientRequestException(BrowserErrorCode.SHOPNOTEXIST);
if (shop.getIpId() != null && shop.getIp() != null) {
unBindShop(username, shopId);
}
IpResource ipResource = ipResourceRepository.findByIpAddr(ipAddr);
if (ipResource == null)
throw new ClientRequestException(BrowserErrorCode.IPNOTEXIST);
UserShop userShop = userShopRepository.findByShopId(shopId);
if (userShop == null)
throw new ClientRequestException(AccountErrorCode.NOPERMISSION);
try {
shop.setIp(ipAddr);
shop.setIpId(ipResource.getId());
shop.setIpRegion(ipResource.getIpRegion());
shopRepository.save(shop);
} catch (Exception e) {
}
}
@Override
public void unBindShop(String username, String shopId) {
}
@Override
public void transferShop(String useranme, String shopId, String groupId) {
}
@Override
public void assignShop(String username, String shopId, List<String> users) {
}
@Override
public List<Shop> getShopList(String username, String groupId) {
return null;
}
}
package com.edgec.browserbackend.browser.service;
import com.edgec.browserbackend.browser.domain.IpResource;
public interface IpResourceService {
IpResource getIpResourceByIpAddr(String ipAddr);
}
package com.edgec.browserbackend.browser.service;
import com.edgec.browserbackend.browser.domain.Shop;
import org.springframework.stereotype.Service;
import java.util.List;
public interface ShopService {
String addShop(String useranme, Shop shop);
List<String> addShops(String username, List<Shop> shops);
String updateShop(String username, Shop shop);
void deleteShop(String username, String shopId);
void bindShop(String username, String shopId, String ipAddr);
void unBindShop(String username, String shopId);
void transferShop(String useranme, String shopId, String groupId);
void assignShop(String username, String shopId, List<String> users);
List<Shop> getShopList(String username, String groupId);
}
......@@ -17,11 +17,7 @@ public interface ErrorCode {
public static final int AUTH_BASE = 500000;
public static final int INTELLIGROUP_BASE = 600000;
public static final int VPS_BASE = 700000;
public static final int C3_BASE = 800000;
public static final int BROWSER_BASE = 600000;
int value() ;
......
......@@ -26,8 +26,6 @@ security:
user-info-uri: http://localhost:6000/browser/users/current
server:
servlet:
context-path: /browser
port: 6000
---
......
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