Commit 2d3ef609 authored by renjie's avatar renjie

修改配置

parent 7ff4b187
......@@ -121,7 +121,6 @@ public class AccountController {
@RequestMapping(path = "/authCode", method = RequestMethod.POST)
public ResultDto requestOTP(@RequestBody MobileDto mobile) {
logger.error("mobile" + mobile);
ResultDto resultDto = new ResultDto();
try {
accountService.sendSmsOtp(mobile.getMobile());
......@@ -136,7 +135,7 @@ public class AccountController {
return resultDto;
}
@RequestMapping(path = "/signup", method = RequestMethod.POST)
@RequestMapping(path = "/signUp", method = RequestMethod.POST)
public ResultDto createNewAccount(@Valid @RequestBody User user) {
ResultDto resultDto = new ResultDto();
try {
......
......@@ -8,13 +8,13 @@ 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"),
INFORMATIONNOTCOMPELETE(BROWSER_BASE+100, "The information about shop do not complete"),
SHOPNOTEXIST(BROWSER_BASE+101, "The shop do not exist"),
IPNOTEXIST(BROWSER_BASE+201, "The ip is not exist"),
IPNOTEXIST(BROWSER_BASE+201, "The ip do not exist"),
IPNOTBINDTOSHOP(BROWSER_BASE+202, "The ip do not bind this shop."),
GROUPNOTEXIST(BROWSER_BASE+301, "The group is not exist");
GROUPNOTEXIST(BROWSER_BASE+301, "The group do not exist");
......
package com.edgec.browserbackend.browser.controller;
import com.edgec.browserbackend.account.dto.ResultDto;
import com.edgec.browserbackend.browser.domain.Group;
import com.edgec.browserbackend.browser.dto.GroupDto;
import com.edgec.browserbackend.browser.service.GroupService;
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.RestController;
import java.security.Principal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/group")
public class GroupController {
@Autowired
private GroupService groupService;
@RequestMapping("/add")
public ResultDto addGroup(Principal principal, @RequestBody GroupDto groupDto) {
ResultDto resultDto = new ResultDto();
try {
groupService.addGroup(principal.getName(), groupDto.getGroupName());
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("/update")
public ResultDto updateGroup(Principal principal, @RequestBody Group group) {
ResultDto resultDto = new ResultDto();
try {
groupService.updateGroup(principal.getName(), group);
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("/del")
public ResultDto deleteGroup(Principal principal, @RequestBody GroupDto groupDto) {
ResultDto resultDto = new ResultDto();
try {
groupService.addGroup(principal.getName(), groupDto.getGroupName());
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;
}
List<GroupDto> getGroupList(String username) {
return null;
}
}
......@@ -2,9 +2,12 @@ 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.dto.ShopDto;
import com.edgec.browserbackend.browser.dto.ShopRequestDto;
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.security.core.parameters.P;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
......@@ -44,36 +47,116 @@ public class ShopController {
}
@RequestMapping(value = "/update", method = RequestMethod.POST)
public String updateShop(Principal principal, Shop shop) {
return null;
public ResultDto updateShop(Principal principal, @RequestBody Shop shop) {
ResultDto resultDto = new ResultDto();
try {
resultDto.setData(shopService.updateShop(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 = "/delete", method = RequestMethod.POST)
public void deleteShop(String username, String shopId) {
public ResultDto deleteShop(Principal principal, @RequestBody ShopRequestDto shopRequestDto) {
ResultDto resultDto = new ResultDto();
try {
shopService.deleteShop(principal.getName(), shopRequestDto.getId());
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 = "/bind", method = RequestMethod.POST)
public void bindShop(String username, String shopId, String ipAddr) {
public ResultDto bindShop(Principal principal, @RequestBody ShopRequestDto shopRequestDto) {
ResultDto resultDto = new ResultDto();
try {
shopService.bindShop(principal.getName(), shopRequestDto.getId(), shopRequestDto.getIpAddr());
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 = "/unbind", method = RequestMethod.POST)
public void unBindShop(String username, String shopId) {
public ResultDto unBindShop(Principal principal, @RequestBody ShopRequestDto shopRequestDto) {
ResultDto resultDto = new ResultDto();
try {
shopService.unBindShop(principal.getName(), shopRequestDto.getId(), shopRequestDto.getIpAddr());
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 = "/transfer", method = RequestMethod.POST)
public void transferShop(String useranme, String shopId, String groupId) {
public ResultDto transferShop(Principal principal, @RequestBody ShopRequestDto shopRequestDto) {
ResultDto resultDto = new ResultDto();
try {
shopService.transferShop(principal.getName(), shopRequestDto.getId(), shopRequestDto.getGroupId());
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 = "/assign", method = RequestMethod.POST)
public void assignShop(String username, String shopId, List<String> users) {
public ResultDto assignShop(Principal principal, @RequestBody ShopRequestDto shopRequestDto) {
ResultDto resultDto = new ResultDto();
try {
shopService.assignShops(principal.getName(), shopRequestDto.getShopIds(), shopRequestDto.getUsers());
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 = "/list",method = RequestMethod.POST)
public List<Shop> getShopList(String username, String groupId, int page, int amount, Map<String, String> filter) {
return null;
public ResultDto getShopList(Principal principal, @RequestBody ShopRequestDto shopRequestDto) {
ResultDto resultDto = new ResultDto();
try {
List<ShopDto> shopDtos = shopService.getShopList(principal.getName(), shopRequestDto.getGroupId(), shopRequestDto.getPage(),
shopRequestDto.getAmount(), shopRequestDto.getFilterDto());
resultDto.setData(shopDtos);
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;
}
}
package com.edgec.browserbackend.browser.domain;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
......@@ -13,6 +14,17 @@ public class Group {
private String owner;
private String details;
public void of(Group group){
if (StringUtils.isNotBlank(group.getId()))
this.setId(group.getId());
if (StringUtils.isNotBlank(group.getOwner()))
this.setOwner(group.getOwner());
if (StringUtils.isNotBlank(group.getDetails()))
this.setDetails(group.getDetails());
if (StringUtils.isNotBlank(group.getGroupName()))
this.setGroupName(group.getGroupName());
}
public String getId() {
return id;
}
......
package com.edgec.browserbackend.browser.dto;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.util.List;
@JsonIgnoreProperties(ignoreUnknown = true)
public class ShopRequestDto {
private String id;
private String shopName;
private String owner;
private String ipAddr;
private String groupId;
private List<String> shopIds;
private List<String> users;
private int type;
private int page;
private int amount;
private FilterDto filterDto;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getIpAddr() {
return ipAddr;
}
public void setIpAddr(String ipAddr) {
this.ipAddr = ipAddr;
}
public String getShopName() {
return shopName;
}
public void setShopName(String shopName) {
this.shopName = shopName;
}
public String getOwner() {
return owner;
}
public void setOwner(String owner) {
this.owner = owner;
}
public String getGroupId() {
return groupId;
}
public void setGroupId(String groupId) {
this.groupId = groupId;
}
public FilterDto getFilterDto() {
return filterDto;
}
public void setAmount(int amount) {
this.amount = amount;
}
public int getAmount() {
return amount;
}
public void setFilterDto(FilterDto filterDto) {
this.filterDto = filterDto;
}
public int getPage() {
return page;
}
public void setPage(int page) {
this.page = page;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public List<String> getUsers() {
return users;
}
public void setUsers(List<String> users) {
this.users = users;
}
public List<String> getShopIds() {
return shopIds;
}
public void setShopIds(List<String> shopIds) {
this.shopIds = shopIds;
}
}
......@@ -10,4 +10,5 @@ public interface UserShopRepository extends MongoRepository<UserShop, String>, U
UserShop findByUsernameAndShopId(String username, String shopId);
UserShop findByShopId(String shopId);
List<UserShop> findByUsernameAndGroupId(String username, String groupId);
List<UserShop> findByUsernameAndShopIdIn(String username, List<String> shopIds);
}
......@@ -51,8 +51,12 @@ public class GroupServiceImpl implements GroupService {
public void updateGroup(String username, Group group) {
if (group == null || StringUtils.isBlank(username))
throw new ClientRequestException(BrowserErrorCode.INFORMATIONNOTCOMPELETE);
Group group1 = groupRepository.findById(group.getId()).orElse(null);
if (group1 == null)
throw new ClientRequestException(BrowserErrorCode.GROUPNOTEXIST);
try {
groupRepository.save(group);
group1.of(group);
groupRepository.save(group1);
} catch (Exception e) {
logger.error("fail to update group", e.getMessage());
throw new ClientRequestException(BrowserErrorCode.UNKNOWN);
......
......@@ -32,7 +32,6 @@ public class IpResourceServiceImpl implements IpResourceService {
@Autowired
private IpResourceRepository ipResourceRepository;
@Override
public IpResource getIpResourceByIpAddr(String ipAddr) {
IpResource ipResource = ipResourceRepository.findByIpAddrAndDeleted(ipAddr, false);
......
......@@ -117,7 +117,7 @@ public class ShopServiceImpl implements ShopService {
if (shop == null)
throw new ClientRequestException(BrowserErrorCode.SHOPNOTEXIST);
if (shop.getIpId() != null && shop.getIp() != null) {
unBindShop(username, shopId);
unBindShop(username, shopId, shop.getIp());
}
boolean result = userShopRepository.deleteByUsernameAndShopId(username, shopId);
if (result) {
......@@ -139,7 +139,7 @@ public class ShopServiceImpl implements ShopService {
if (shop == null)
throw new ClientRequestException(BrowserErrorCode.SHOPNOTEXIST);
if (shop.getIpId() != null && shop.getIp() != null) {
unBindShop(username, shopId);
unBindShop(username, shopId, shop.getIp());
}
IpResource ipResource = ipResourceRepository.findByIpAddrAndDeleted(ipAddr, false);
if (ipResource == null)
......@@ -151,6 +151,9 @@ public class ShopServiceImpl implements ShopService {
shopRepository.save(shop);
List<String> history = ipResource.getBindHistory();
history.add(shop.getId());
ipResource.setShopId(shopId);
if (shop.getShopName()!=null)
ipResource.setShopName(shop.getShopName());
ipResourceRepository.save(ipResource);
} catch (Exception e) {
logger.error("fail to bind shop and ip", e.getMessage());
......@@ -159,7 +162,7 @@ public class ShopServiceImpl implements ShopService {
}
@Override
public void unBindShop(String username, String shopId) {
public void unBindShop(String username, String shopId, String ipAddr) {
Account account = accountRepository.findByName(username);
if (account == null) {
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
......@@ -171,13 +174,17 @@ public class ShopServiceImpl implements ShopService {
Shop shop = shopRepository.findById(shopId).orElse(null);
if (shop == null)
throw new ClientRequestException(BrowserErrorCode.SHOPNOTEXIST);
IpResource ipResource = ipResourceRepository.findByIpAddrAndDeleted(shop.getIp(), false);
IpResource ipResource = ipResourceRepository.findByIpAddrAndDeleted(ipAddr, false);
if (ipResource == null)
throw new ClientRequestException(BrowserErrorCode.IPNOTEXIST);
if (!ipAddr.equals(shop.getIp()))
throw new ClientRequestException(BrowserErrorCode.IPNOTBINDTOSHOP);
try {
shop.setIp(null);
shop.setIpId(null);
shop.setIpRegion(null);
ipResource.setShopId(null);
ipResource.setShopName(null);
shopRepository.save(shop);
} catch (Exception e) {
logger.error("fail to unbind", e.getMessage());
......@@ -210,27 +217,29 @@ public class ShopServiceImpl implements ShopService {
}
@Override
public void assignShop(String username, String shopId, List<String> users) {
public void assignShops(String username, List<String> shopIds, List<String> users) {
Account account = accountRepository.findByName(username);
if (account == null) {
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
}
UserShop userShop = userShopRepository.findByUsernameAndShopId(username, shopId);
if (account.getPermission() < 8 || userShop == null) {
List<UserShop> userShops = userShopRepository.findByUsernameAndShopIdIn(username, shopIds);
if (account.getPermission() < 8 || userShops == null || userShops.size() < 1) {
throw new ClientRequestException(AccountErrorCode.NOPERMISSION);
}
Shop shop = shopRepository.findById(shopId).orElse(null);
if (shop == null)
List<Shop> shops = shopRepository.findByIdIn(shopIds);
if (shops == null || shops.size() < 1)
throw new ClientRequestException(BrowserErrorCode.SHOPNOTEXIST);
List<Account> accounts = accountRepository.findByNameIn(users);
if (accounts != null || accounts.size() != users.size())
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
accounts.stream().forEach(x -> {
try {
UserShop userShop1 = userShopRepository.findByUsernameAndShopId(x.getName(), shopId);
if (userShop1 != null)
return;
userShopRepository.save(new UserShop(x.getName(), shopId));
for (Shop shop:shops){
UserShop userShop1 = userShopRepository.findByUsernameAndShopId(x.getName(), shop.getId());
if (userShop1 != null)
return;
userShopRepository.save(new UserShop(x.getName(), shop.getId()));
}
} catch (Exception e) {
logger.error("fail to assign", e.getMessage());
}
......
......@@ -19,11 +19,11 @@ public interface ShopService {
void bindShop(String username, String shopId, String ipAddr);
void unBindShop(String username, String shopId);
void unBindShop(String username, String shopId, String ipAddr);
void transferShop(String username, String shopId, String groupId);
void assignShop(String username, String shopId, List<String> users);
void assignShops(String username, List<String> shopIds, List<String> users);
List<ShopDto> getShopList(String username, String groupId, int page, int amount, FilterDto filterDto);
}
package com.edgec.browserbackend.common.client;
public class HttpClient {
}
......@@ -27,7 +27,7 @@ spring:
security:
oauth2:
resource:
user-info-uri: http://localhost:1729/users/current
user-info-uri: http://localhost:1729/auth/current
server:
port: 1729
......
......@@ -17,4 +17,18 @@
400112=PhoneNumber can not be empty
400113=uuid dose not exists
400114=Can't delete child whose still have scaling group
400120=Wechat payment order generation fails
\ No newline at end of file
400120=Wechat payment order generation fails
400140=You have no right to do this operarion
500100=Authentication fails, please check your username or password.
500200=Authorization fails, you are not allowed to access the resource.
500102=Username does not exist.
500101=Email already exists.
500103=Email does not exist.
500104=Username or Email does not exist.
500105=Wrong verification code.
500106=Username already exists.
500107=Login times exceeded.
600100=The information about shop is not complete.
600101=The shop do not exist.
600201=The ip do not exist.
600301=The group do not exist.
\ No newline at end of file
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