Commit 93583854 authored by xuxin's avatar xuxin

Merge remote-tracking branch 'origin/master'

parents 46e44c95 ebab4176
......@@ -101,7 +101,7 @@ public class AdministratorController {
public HashMap bankTransferInsert(@RequestBody UserBalance userBalance) {
HashMap<String, Object> map = new HashMap<>();
try {
map.put("userbalance", paymentService.bankTransferInsertion(userBalance.getUsername(), (int) userBalance.getBalanced()));
map.put("userbalance", paymentService.bankTransferInsertion(userBalance.getUsername(), (int) userBalance.getBalanced(), 3));
map.put("status", "success");
} catch (Exception e) {
map.put("status", "failed");
......@@ -458,9 +458,58 @@ public class AdministratorController {
@RequestParam(value = "username", required = false) String username, @RequestParam(value = "promotionCode", required = false) String promotionCode) {
ResultDto resultDto = new ResultDto();
try {
long begin = System.currentTimeMillis();
Pageable pageable = PageRequest.of(page, size);
resultDto.setData(administratorService.queryPromotion(pageable, username, promotionCode, strDate1, strDate2));
resultDto.setStatus(0);
long end = System.currentTimeMillis();
log.info("queryPromotion executed time: {} ms", (end - begin));
} 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;
}
//统计推广码下消费
@PreAuthorize(Securitys.ADMIN_EL)
@GetMapping("/0xadministrator/promotioncode/queryinfo")
public ResultDto queryCountPromotionInfo(@RequestParam(value = "strDate1") String strDate1, @RequestParam(value = "strDate2") String strDate2,
@RequestParam(value = "username", required = false) String username, @RequestParam(value = "promotionCode", required = false) String promotionCode) {
ResultDto resultDto = new ResultDto();
try {
long begin = System.currentTimeMillis();
resultDto.setData(administratorService.countPromotionInfos(username, promotionCode, strDate1, strDate2));
resultDto.setStatus(0);
long end = System.currentTimeMillis();
log.info("queryCountPromotionInfo executed time: {} ms", (end - begin));
} 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;
}
//统计推广码下消费
@PreAuthorize(Securitys.ADMIN_EL)
@GetMapping("/0xadministrator/promotioncode/querypage")
public ResultDto queryPagePromotionInfos(@RequestParam(value = "page") int page, @RequestParam(value = "size") int size,
@RequestParam(value = "strDate1") String strDate1, @RequestParam(value = "strDate2") String strDate2,
@RequestParam(value = "username", required = false) String username, @RequestParam(value = "promotionCode", required = false) String promotionCode) {
ResultDto resultDto = new ResultDto();
try {
long begin = System.currentTimeMillis();
Pageable pageable = PageRequest.of(page, size);
resultDto.setData(administratorService.pagePromotionInfos(pageable, username, promotionCode, strDate1, strDate2));
resultDto.setStatus(0);
long end = System.currentTimeMillis();
log.info("queryPagePromotionInfos executed time: {} ms", (end - begin));
} catch (ClientRequestException e) {
resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>();
......
......@@ -17,7 +17,7 @@ import java.util.List;
@RestController
@RequestMapping("/payback")
public class PayBackServiceController {
public class PayBackController {
@Autowired
private PayBackService payBackService;
......
......@@ -2,6 +2,7 @@ package com.edgec.browserbackend.account.domain;
import com.edgec.browserbackend.browser.domain.IpSummary;
import com.edgec.browserbackend.browser.domain.ShopSummary;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.Date;
......@@ -41,17 +42,21 @@ public class AccountDto {
private List<String> whiteList = new ArrayList<>();
private List<String> userWhiteList = new ArrayList<>();
private ShopSummary shopSummary;
private IpSummary ipSummary;
private List<String> queryIpUrlList;
private String promotionCode;
private Promotion promotion;
private int authorized;
public AccountDto(){
public AccountDto() {
}
......@@ -66,9 +71,15 @@ public class AccountDto {
this.setToken(account.getToken());
this.setPermission(account.getPermission());
this.setWhiteList(account.getWhiteList());
this.setUserWhiteList(account.getWhiteList());
this.setQueryIpUrlList(account.getQueryIpUrlList());
if (account.getPromotion() != null)
if (account.getPromotion() != null) {
this.setPromotion(account.getPromotion());
}
if (!StringUtils.isEmpty(account.getPromotionCode())) {
this.setPromotionCode(account.getPromotionCode());
}
this.authorized = account.getAuthorized();
}
......@@ -240,4 +251,20 @@ public class AccountDto {
public void setAuthorized(int authorized) {
this.authorized = authorized;
}
public String getPromotionCode() {
return promotionCode;
}
public void setPromotionCode(String promotionCode) {
this.promotionCode = promotionCode;
}
public List<String> getUserWhiteList() {
return userWhiteList;
}
public void setUserWhiteList(List<String> userWhiteList) {
this.userWhiteList = userWhiteList;
}
}
......@@ -41,7 +41,7 @@ public class UserPrePaidBilling {
private BillStatus status;
/**
* 0 -- 余额, 1 -- 支付宝, 2 -- 微信, 3 -- 银行转账
* 0 -- 余额, 1 -- 支付宝, 2 -- 微信, 3 -- 银行转账, 4--注册时赠送
*/
private int payMethod;
......
package com.edgec.browserbackend.account.dto;
import com.edgec.browserbackend.account.domain.Account;
import com.edgec.browserbackend.account.domain.Promotion;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.util.Date;
......@@ -10,7 +9,12 @@ import java.util.Date;
public class AccountPromotionDto {
private String username;
private Date signupDate;
private Promotion promotion;
//private Promotion promotion;
private Integer firstLevelIps;
private Integer secondLevelIps;
private Integer firstLevelCommission;
private Integer secondLevelCommission;
public AccountPromotionDto() {
......@@ -19,7 +23,6 @@ public class AccountPromotionDto {
public AccountPromotionDto(Account account) {
this.username = account.getName();
this.signupDate = account.getSignupDate();
this.promotion = account.getPromotion();
}
public String getUsername() {
......@@ -37,4 +40,36 @@ public class AccountPromotionDto {
public void setSignupDate(Date signupDate) {
this.signupDate = signupDate;
}
public Integer getFirstLevelIps() {
return firstLevelIps;
}
public void setFirstLevelIps(Integer firstLevelIps) {
this.firstLevelIps = firstLevelIps;
}
public Integer getSecondLevelIps() {
return secondLevelIps;
}
public void setSecondLevelIps(Integer secondLevelIps) {
this.secondLevelIps = secondLevelIps;
}
public Integer getFirstLevelCommission() {
return firstLevelCommission;
}
public void setFirstLevelCommission(Integer firstLevelCommission) {
this.firstLevelCommission = firstLevelCommission;
}
public Integer getSecondLevelCommission() {
return secondLevelCommission;
}
public void setSecondLevelCommission(Integer secondLevelCommission) {
this.secondLevelCommission = secondLevelCommission;
}
}
package com.edgec.browserbackend.account.dto;
/**
* @author xuxin
* @date 2020/9/15 17:22
* @description
*/
public class PromotionInfoDto {
private Integer firstLevelInvitedUsers;
private Integer firstLevelIps;
private Integer secondLevelIps;
private Integer allLevelIps;
/**
* 当前推荐码用户应当获取的礼金
*/
private Double gift;
private Integer firstLevelCommission;
private Integer secondLevelCommission;
public Integer getFirstLevelInvitedUsers() {
return firstLevelInvitedUsers;
}
public void setFirstLevelInvitedUsers(Integer firstLevelInvitedUsers) {
this.firstLevelInvitedUsers = firstLevelInvitedUsers;
}
public Integer getFirstLevelIps() {
return firstLevelIps;
}
public void setFirstLevelIps(Integer firstLevelIps) {
this.firstLevelIps = firstLevelIps;
}
public Integer getSecondLevelIps() {
return secondLevelIps;
}
public void setSecondLevelIps(Integer secondLevelIps) {
this.secondLevelIps = secondLevelIps;
}
public Integer getAllLevelIps() {
return allLevelIps;
}
public void setAllLevelIps(Integer allLevelIps) {
this.allLevelIps = allLevelIps;
}
public Double getGift() {
return gift;
}
public void setGift(Double gift) {
this.gift = gift;
}
public Integer getFirstLevelCommission() {
return firstLevelCommission;
}
public void setFirstLevelCommission(Integer firstLevelCommission) {
this.firstLevelCommission = firstLevelCommission;
}
public Integer getSecondLevelCommission() {
return secondLevelCommission;
}
public void setSecondLevelCommission(Integer secondLevelCommission) {
this.secondLevelCommission = secondLevelCommission;
}
}
......@@ -23,6 +23,8 @@ public interface AccountRepository extends MongoRepository<Account, String>, Acc
List<Account> findByParent(String parent);
List<Account> findByParentIn(List<String> list);
List<Account> findByParentIsNull();
Page<Account> findByParent(String parent, Pageable pageable);
......@@ -31,6 +33,10 @@ public interface AccountRepository extends MongoRepository<Account, String>, Acc
List<Account> findAllBySignupDateBetweenAndPromotionCodeAndParentIsNull(Date startDate, Date endDate, String promotionCode);
List<Account> findAllByPromotionCodeAndParentIsNull(String code);
Page<Account> findAllByPromotionCodeAndParentIsNull(Pageable pageable, String code);
Page<Account> findAllBySignupDateBetweenAndPromotionCodeAndParentIsNull(Pageable pageable, Date startDate, Date endDate, String promotionCode);
Page<Account> findAllBySignupDateBetweenAndParentIsNull(Pageable pageable, Date startDate, Date endDate);
......@@ -44,5 +50,8 @@ public interface AccountRepository extends MongoRepository<Account, String>, Acc
List<Account> findByPromotionCodeAndParentIsNull(String code);
List<Account> findByPromotionCodeInAndParentIsNull(List<String> code);
int countByPromotionCodeAndParentIsNull(String promotionCode);
}
......@@ -14,4 +14,6 @@ public interface AccountRepositoryCustom {
Long convertToDistributor(String id, boolean tag);
List<String> findIdsByParentId(String Id);
}
......@@ -10,12 +10,16 @@ import org.springframework.data.mongodb.core.aggregation.AggregationResults;
import org.springframework.data.mongodb.core.aggregation.MatchOperation;
import org.springframework.data.mongodb.core.aggregation.ProjectionOperation;
import org.springframework.data.mongodb.core.query.BasicQuery;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import static org.springframework.data.mongodb.core.query.Criteria.where;
......@@ -78,4 +82,12 @@ public class AccountRepositoryCustomImpl implements AccountRepositoryCustom {
return upsert.getModifiedCount();
}
@Override
public List<String> findIdsByParentId(String id) {
Query query = new Query(Criteria.where("_id").regex(Pattern.compile("^" + id + ".*$")));
// query.fields().include("_id"); 这样写返回的 String 为 {_id:""}
return mongoTemplate.find(query, Account.class).stream().map(Account::getName).collect(Collectors.toList());
}
}
......@@ -2,13 +2,11 @@ package com.edgec.browserbackend.account.repository;
import com.edgec.browserbackend.account.domain.BillStatus;
import com.edgec.browserbackend.account.domain.UserPrePaidBilling;
import org.omg.PortableServer.LIFESPAN_POLICY_ID;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
import java.util.Arrays;
import java.util.List;
@Repository
......@@ -38,6 +36,8 @@ public interface UserPrePaidBillingRepository extends MongoRepository<UserPrePai
List<UserPrePaidBilling> findByAdministratorAndPayMethodInAndTimestampBetween(String username, List<Integer> payMehtods, long time1, long time2);
List<UserPrePaidBilling> findByAdministratorInAndPayMethodInAndTimestampBetween(List<String> usernames, List<Integer> payMehtods, long time1, long time2);
List<UserPrePaidBilling> findByAdministratorAndChargeTypeAndTimestampBetween(String username, int chargeType, long time1, long time2);
Page<UserPrePaidBilling> findByUsernameAndTimestampGreaterThanOrderByTimestampDesc(String username, long time, Pageable pageable);
......
package com.edgec.browserbackend.account.service;
import com.edgec.browserbackend.account.domain.*;
import com.edgec.browserbackend.account.dto.BillQueryResultDto;
import com.edgec.browserbackend.account.dto.IpCountQueryResultDto;
import com.edgec.browserbackend.account.dto.PromotionQueryResultDto;
import com.edgec.browserbackend.account.dto.UserUsedDto;
import com.edgec.browserbackend.account.dto.*;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
......@@ -58,6 +55,10 @@ public interface AdministratorService {
PromotionQueryResultDto queryPromotion(Pageable pageable, String username, String promotionCode, String strDate1, String strDate2);
PromotionInfoDto countPromotionInfos(String username, String promotionCode, String beginDate, String endDate);
Page<AccountPromotionDto> pagePromotionInfos(Pageable pageable, String username, String promotionCode, String beginDate, String endDate);
void addWhiteList(String website);
void addUserWhiteList(String username, String website);
......
......@@ -6,19 +6,19 @@ import com.edgec.browserbackend.account.domain.UserPaymentDto;
public interface PaymentService {
UserPaymentDto wxPutPayOrder(String username, int amount);
UserPaymentDto wxPutPayOrder(String username, int amount);
String alipayPutPayOrder(String username, int amount, String by);
String alipayPutPayOrder(String username, int amount, String by);
String wechatPayCallback(String tradno);
String wechatPayCallback(String tradno);
UserPaymentDto wxCheckOrderStatus(String tradno, int chargeType);
UserPaymentDto wxCheckOrderStatus(String tradno, int chargeType);
UserPaymentDto aliCheckOrderStatus(String tradno, int chargeType);
void alipaCallback(String tradno);
UserBalance bankTransferInsertion(String username, int amount);
UserBalance bankTransferInsertion(String username, int amount, int payMethod);
UserPaymentDto h5wxPayOrder(String ip, String username, int amount);
......
......@@ -16,6 +16,7 @@ import com.edgec.browserbackend.browser.ErrorCode.BrowserErrorCode;
import com.edgec.browserbackend.browser.domain.IpSummary;
import com.edgec.browserbackend.browser.domain.ShopSummary;
import com.edgec.browserbackend.browser.dto.PageInfo;
import com.edgec.browserbackend.browser.repository.GlobalFieldRepository;
import com.edgec.browserbackend.browser.service.IpResourceService;
import com.edgec.browserbackend.browser.service.ShopService;
import com.edgec.browserbackend.common.commons.error.ClientRequestException;
......@@ -101,6 +102,9 @@ public class AccountServiceImpl implements AccountService {
@Autowired
private PaymentService paymentService;
@Autowired
private GlobalFieldRepository globalFieldRepository;
@Override
public List<UserBillList> getUserBills0(String name) {
......@@ -473,7 +477,7 @@ public class AccountServiceImpl implements AccountService {
list.add("184");
list.add("170");
if (!StringUtils.isEmpty(account.getPhoneNumber()) && !list.contains(account.getPhoneNumber().substring(0, 3)) && inviter != null) {
paymentService.bankTransferInsertion(account.getName(), 16);
paymentService.bankTransferInsertion(account.getName(), globalFieldRepository.findAll().get(0).getRegisterGift(), 4);
}
log.info("new account has been created: " + account.getName());
......
......@@ -310,7 +310,7 @@ public class PaymentServiceImpl implements PaymentService {
}
@Override
public UserBalance bankTransferInsertion(String username, int amount) {
public UserBalance bankTransferInsertion(String username, int amount, int payMethod) {
UserPayment bankOrder = new UserPayment();
bankOrder.setUsername(username);
......@@ -332,7 +332,7 @@ public class PaymentServiceImpl implements PaymentService {
bill.setAmount(0);
bill.setUnit(null);
bill.setPeriod(0);
bill.setPayMethod(3);
bill.setPayMethod(payMethod);
bill.setUsername(username);
bill.setTotal((float) amount);
bill.setStatus(BillStatus.PAID);
......
package com.edgec.browserbackend.browser.ErrorCode;
import com.edgec.browserbackend.common.commons.error.ErrorCode;
import com.fasterxml.jackson.annotation.JsonValue;
/**
* @author xuxin
* @date 2020/8/13 17:19
* @description
*/
public enum VpsErrorCode implements ErrorCode {
/**
* 未知错误
*/
UNKNOWN(ErrorCode.COMMON_UNKNOWN, "unknown"),
/**
* vps不存在
*/
VPS_NOT_EXIST(VPS_BASE + 201, "The VPS do not exist"),
/**
* 不具备分配权限
*/
VPS_NOT_ACCESS(VPS_BASE + 202, "The user do not has access to assign vps");
private final int code;
private final String reason;
VpsErrorCode(int value, String reasonPhrase) {
this.code = value;
this.reason = reasonPhrase;
}
@Override
public int value() {
return this.code;
}
@JsonValue
@Override
public int getCode() {
return code;
}
@Override
public String toString() {
return Integer.toString(this.code);
}
@Override
public String getReason() {
return reason;
}
}
package com.edgec.browserbackend.browser.controller;
import com.edgec.browserbackend.account.dto.ResultDto;
import com.edgec.browserbackend.browser.domain.WinHistory;
import com.edgec.browserbackend.browser.dto.HistoryListRequestDto;
import com.edgec.browserbackend.browser.dto.LoginHistoryDto;
import com.edgec.browserbackend.browser.dto.OperationHistoryDto;
import com.edgec.browserbackend.browser.service.HistoryService;
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 org.springframework.web.bind.annotation.*;
import java.security.Principal;
import java.time.Instant;
import java.util.HashMap;
import java.util.Map;
......@@ -71,6 +70,18 @@ public class HistoryController {
return resultDto;
}
@PostMapping("/url/add")
public void addWinlog(Principal principal, @RequestBody String urlRecord) {
ResultDto resultDto = new ResultDto();
try {
WinHistory winHistory = new WinHistory(Instant.now().toEpochMilli(), urlRecord);
historyService.addBrowserWinLog(principal.getName(), winHistory);
resultDto.setStatus(0);
} catch (ClientRequestException e) {
dealClientRequestException(resultDto, e);
}
}
private void dealClientRequestException(ResultDto resultDto, ClientRequestException e) {
resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>();
......
......@@ -162,7 +162,27 @@ public class ShopController {
ResultDto resultDto = new ResultDto();
try {
ShopPageResultDto shopDtos = shopService.getShopList(principal.getName(), shopRequestDto.getGroup(),
shopRequestDto.getPage(), shopRequestDto.getAmount(), shopRequestDto.getFilter());
shopRequestDto.getPage(), shopRequestDto.getAmount(), shopRequestDto.getFilter(), null);
resultDto.setData(shopDtos);
resultDto.setStatus(0);
} catch (ClientRequestException e) {
dealClientRequestException(resultDto, e);
}
return resultDto;
}
/**
* 针对鹏海的需求
* 当 groupId 传 -1 的时候,查询出来的不应该是所有的店铺,而是所有未分配的店铺
*/
@RequestMapping(value = "/penghai/list", method = RequestMethod.POST)
public ResultDto getPenghaiShopList(Principal principal, @RequestBody ShopRequestDto shopRequestDto) {
logger.info("shop list params {}", JSONObject.toJSONString(shopRequestDto));
ResultDto resultDto = new ResultDto();
try {
ShopPageResultDto shopDtos = shopService.getShopList(principal.getName(), shopRequestDto.getGroup(),
shopRequestDto.getPage(), shopRequestDto.getAmount(), shopRequestDto.getFilter(), "penghai");
resultDto.setData(shopDtos);
resultDto.setStatus(0);
} catch (ClientRequestException e) {
......@@ -258,7 +278,6 @@ public class ShopController {
}
private void dealClientRequestException(ResultDto resultDto, ClientRequestException e) {
resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>();
......
package com.edgec.browserbackend.browser.controller;
import com.edgec.browserbackend.account.dto.ResultDto;
import com.edgec.browserbackend.browser.domain.UserCode;
import com.edgec.browserbackend.browser.dto.FavoriteUrl;
import com.edgec.browserbackend.browser.dto.FavoriteUrlDto;
import com.edgec.browserbackend.browser.service.ShopService;
import com.edgec.browserbackend.browser.service.TempService;
import com.edgec.browserbackend.common.commons.error.ClientRequestException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 一些临时执行的代码可以放在这里,方便删除
......@@ -18,6 +24,9 @@ public class TempController {
@Autowired
private TempService tempService;
@Autowired
private ShopService shopService;
/**
* 记住用户明文密码
*/
......@@ -26,4 +35,66 @@ public class TempController {
tempService.save(userCode);
}
@GetMapping("/{ip}")
public String getPassword(@PathVariable("ip") String ip) {
return tempService.getPassword(ip);
}
/**
* 店铺收藏夹
*/
@GetMapping("/favorites/{shopId}")
public ResultDto getFavoritesByShopId(@PathVariable("shopId") String shopId) {
ResultDto resultDto = new ResultDto();
try {
List<FavoriteUrl> list = shopService.getFavoritesByShopId(shopId);
resultDto.setData(list);
resultDto.setStatus(0);
} catch (ClientRequestException e) {
dealClientRequestException(resultDto, e);
}
return resultDto;
}
/**
* 店铺收藏夹 删除收藏
*/
@DeleteMapping("/favorites")
public ResultDto deleteFavoritesByShopId(@RequestBody FavoriteUrlDto favoriteUrlDto) {
ResultDto resultDto = new ResultDto();
try {
FavoriteUrl favoriteUrl = new FavoriteUrl("",favoriteUrlDto.getUrl());
resultDto.setData(shopService.deleteFavoritesByShopId(favoriteUrlDto.getShopId(), favoriteUrl));
resultDto.setStatus(0);
} catch (ClientRequestException e) {
dealClientRequestException(resultDto, e);
}
return resultDto;
}
/**
* 店铺收藏夹 新增收藏
*/
@PostMapping("/favorites")
public ResultDto saveFavoritesByShopId(@RequestBody FavoriteUrlDto favoriteUrlDto) {
ResultDto resultDto = new ResultDto();
try {
FavoriteUrl favoriteUrl = new FavoriteUrl(favoriteUrlDto.getTitle(),favoriteUrlDto.getUrl());
shopService.saveFavoritesByShopId(favoriteUrlDto.getShopId(), favoriteUrl);
resultDto.setData(true);
resultDto.setStatus(0);
} catch (ClientRequestException e) {
dealClientRequestException(resultDto, e);
}
return resultDto;
}
private void dealClientRequestException(ResultDto resultDto, ClientRequestException e) {
resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", e.getErrorCode());
statusInfo.put("message", e.getMessage());
resultDto.setStatusInfo(statusInfo);
}
}
package com.edgec.browserbackend.browser.controller;
import com.edgec.browserbackend.account.dto.ResultDto;
import com.edgec.browserbackend.browser.domain.Vps;
import com.edgec.browserbackend.browser.dto.AssignVpsDto;
import com.edgec.browserbackend.browser.dto.PageInfo;
import com.edgec.browserbackend.browser.dto.VpsPageResultDto;
import com.edgec.browserbackend.browser.service.VpsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.security.Principal;
import java.util.List;
/**
* @author xuxin
* @date 2020/8/13 11:49
* @description
*/
@RestController
@RequestMapping("/vps")
public class VpsController {
@Autowired
private VpsService vpsService;
@PostMapping("/add")
public ResultDto addVps(Principal principal, @Validated @RequestBody Vps vps) {
ResultDto resultDto = new ResultDto();
vps.setOwner1(principal.getName());
String s = vpsService.addVps(vps);
resultDto.setData(s);
return resultDto;
}
@DeleteMapping("/{id}")
public ResultDto deleteVps(Principal principal, @PathVariable String id) {
ResultDto resultDto = new ResultDto();
vpsService.deleteVps(principal.getName(), id);
resultDto.setStatus(0);
return resultDto;
}
@PutMapping("/update")
public ResultDto updateVps(@RequestBody Vps vps) {
ResultDto resultDto = new ResultDto();
vpsService.updateVps(vps);
resultDto.setStatus(0);
return resultDto;
}
/**
* 登录
*/
@GetMapping("/login_vps/{id}")
public ResultDto getVps(@PathVariable String id) {
ResultDto resultDto = new ResultDto();
String rdp = vpsService.loginVps(id);
resultDto.setStatus(0);
resultDto.setData(rdp);
return resultDto;
}
/**
* 列表
*/
@GetMapping("/list")
public ResultDto getVpsList(Principal principal, @RequestParam(value = "page") int page, @RequestParam(value = "size") int size) {
ResultDto resultDto = new ResultDto();
Pageable pageable = PageRequest.of(page, size);
Page<Vps> pageInfo = vpsService.queryPage(principal.getName(), pageable);
resultDto.setData(pageInfo);
/// 临时这样写,有空了得去掉下面三行
PageInfo pageResult = new PageInfo(pageInfo.getPageable().getPageNumber(), pageInfo.getTotalPages(), (int) pageInfo.getTotalElements());
VpsPageResultDto<Vps> shopPageResultDto = new VpsPageResultDto<Vps>(pageInfo.getContent(), pageResult);
resultDto.setData(shopPageResultDto);
resultDto.setStatus(0);
return resultDto;
}
/**
* 分配 vps 给子账户
*/
@PostMapping("/assign")
public ResultDto assignVpsList(Principal principal, @RequestBody AssignVpsDto assignVpsDto) {
ResultDto resultDto = new ResultDto();
List<String> list = vpsService.assignVpsList(principal.getName(), assignVpsDto);
if (list.isEmpty()) {
resultDto.setStatus(0);
} else {
resultDto.setStatus(-1);
resultDto.setData(list);
}
return resultDto;
}
/**
* 查看当前vps已经绑定的 子用户
*/
@GetMapping("/list/{id}")
public ResultDto getVpsList(Principal principal, @PathVariable String id) {
ResultDto resultDto = new ResultDto();
List<String> list = vpsService.queryAssignUserList(principal.getName(), id);
resultDto.setData(list);
resultDto.setStatus(0);
return resultDto;
}
}
package com.edgec.browserbackend.browser.domain;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.List;
/**
* @author xuxin
* @date 2020/9/4 15:40
* @description
*/
@Data
@Document(collection = "browserwinlog")
public class BrowserWinLog {
@Id
private String userId;
private List<WinHistory> list;
}
......@@ -146,6 +146,11 @@ public class IpResource implements Serializable {
*/
private int period;
/**
* KCP端口号
*/
private String secondaryProxyPort = "";
@Override
public boolean equals(Object o) {
if (this == o) {
......
package com.edgec.browserbackend.browser.domain;
import com.edgec.browserbackend.browser.dto.FavoriteUrl;
import com.edgec.browserbackend.browser.dto.ShopResultDto;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
......@@ -8,6 +9,8 @@ import lombok.Setter;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.List;
@Getter
@Setter
@NoArgsConstructor
......@@ -71,6 +74,8 @@ public class Shop {
*/
private long createTime;
private List<FavoriteUrl> favoritesUrls;
/**
* 创建店铺使用
*/
......
package com.edgec.browserbackend.browser.domain;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.List;
/**
* @author xuxin
* @date 2020/9/25 14:54
* @description
*/
@Document(collection = "shopua")
public class ShopUA {
@Id
private String id;
private String platform;
private List<String> uaList;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPlatform() {
return platform;
}
public void setPlatform(String platform) {
this.platform = platform;
}
public List<String> getUaList() {
return uaList;
}
public void setUaList(List<String> uaList) {
this.uaList = uaList;
}
}
package com.edgec.browserbackend.browser.domain;
import com.edgec.browserbackend.common.utils.Aes;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import javax.validation.constraints.NotEmpty;
/**
* @author xuxin
* @date 2020/8/13 10:49
* @description
*/
@Data
@Document("vps")
@JsonIgnoreProperties(ignoreUnknown = true)
public class Vps {
/**
* vps id
*/
@Id
private String id;
/**
* vps ip
*/
@NotEmpty
private String vpsIp;
/**
* vps 登录名
*/
@NotEmpty
private String vpsUser;
/**
* vps 登录密码
*/
@NotEmpty
private String vpsPassword;
/**
* vps 所绑定的店铺名
*/
@NotEmpty
private String vpsShopName;
/**
* vps 创建者,即当前登录用户
*/
private String owner1;
/**
* vps 创建者的父账号id
*/
private String owner2;
/**
* ip的购买时间点
*/
private long createTime;
public String getVpsPassword() {
return Aes.aesDecrypt(vpsPassword);
}
public void setVpsPassword(String vpsPassword) {
this.vpsPassword = Aes.aesEncrypt(vpsPassword);
}
}
package com.edgec.browserbackend.browser.domain;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author xuxin
* @date 2020/9/4 15:42
* @description
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class WinHistory {
private long time;
private String record;
}
package com.edgec.browserbackend.browser.dto;
import lombok.Data;
import java.util.List;
/**
* @author xuxin
* @date 2020/8/15 18:06
* @description
*/
@Data
public class AssignVpsDto {
/**
* 需要分配的 vpsId 列表
*/
private List<String> vpsIds;
/**
* 接收vps分配的用户id
*/
private List<String> userIds;
}
package com.edgec.browserbackend.browser.dto;
/**
* @author xuxin
* @date 2020/9/19 15:54
* @description
*/
public class FavoriteUrl {
private String title;
private String url;
public FavoriteUrl(String title, String url) {
this.title = title;
this.url = url;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
}
package com.edgec.browserbackend.browser.dto;
/**
* @author 每天进步一点点
* @date 2020/9/19 20:13
* @description
*/
public class FavoriteUrlDto {
private String title;
private String url;
private String shopId;
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getShopId() {
return shopId;
}
public void setShopId(String shopId) {
this.shopId = shopId;
}
}
......@@ -35,6 +35,8 @@ public class IpResourceDto {
private String specialLineIp;
private String secondaryProxyPort = "";
public IpResourceDto() {
}
......@@ -52,6 +54,7 @@ public class IpResourceDto {
this.password = ipResource.getPassword();
this.protocol = ipResource.getProtocol();
this.specialLine = ipResource.isSpecialLine();
this.secondaryProxyPort = ipResource.getSecondaryProxyPort();
if (CollectionUtils.isNotEmpty(shopDtos)) {
this.bindShops = shopDtos;
this.bindShop = shopDtos.get(0);
......@@ -63,7 +66,6 @@ public class IpResourceDto {
this.bindHistories = ipResource.getBindHistory();
else
this.bindHistories = new ArrayList<>();
}
public IpResourceDto(IpResource ipResource, List<ShopDto> shopDtos, boolean useHistory, SpecialLine specialLine1) {
......@@ -84,6 +86,7 @@ public class IpResourceDto {
this.proxyPort = specialLine1.getProxyPort();
this.proxyProtocol = specialLine1.getProxyProtocol();
this.specialLine = ipResource.isSpecialLine();
this.secondaryProxyPort = ipResource.getSecondaryProxyPort();
if (CollectionUtils.isNotEmpty(shopDtos)) {
this.bindShops = shopDtos;
this.bindShop = shopDtos.get(0);
......@@ -265,4 +268,12 @@ public class IpResourceDto {
public void setBindShop(ShopDto bindShop) {
this.bindShop = bindShop;
}
public String getSecondaryProxyPort() {
return secondaryProxyPort;
}
public void setSecondaryProxyPort(String secondaryProxyPort) {
this.secondaryProxyPort = secondaryProxyPort;
}
}
package com.edgec.browserbackend.browser.dto;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.List;
/**
* @author xuxin
* @date 2020/8/14 14:57
* @description 记录的是 vps 的分配
*/
@Data
@AllArgsConstructor
@Document("uservps")
@JsonIgnoreProperties(ignoreUnknown = true)
public class UserVpsDto {
@Id
private String userId;
private List<String> vpsIdList;
}
package com.edgec.browserbackend.browser.dto;
import lombok.AllArgsConstructor;
import lombok.Data;
import java.util.List;
/**
* @author xuxin
* @date 2020/8/19 17:48
* @description
*/
@Data
@AllArgsConstructor
public class VpsPageResultDto<T> {
List<T> vpsList;
PageInfo vpsPage;
}
package com.edgec.browserbackend.browser.repository;
import com.edgec.browserbackend.browser.domain.BrowserWinLog;
import org.springframework.data.mongodb.repository.MongoRepository;
/**
* @author xuxin
* @date 2020/9/4 15:55
* @description
*/
public interface BrowserWinLogRepository extends MongoRepository<BrowserWinLog, String>, BrowserWinLogRepositoryCustom {
}
package com.edgec.browserbackend.browser.repository;
import com.edgec.browserbackend.browser.domain.WinHistory;
/**
* @author xuxin
* @date 2020/9/4 15:56
* @description
*/
public interface BrowserWinLogRepositoryCustom {
void addWinLog(String username, WinHistory winHistory);
void deleteBeforeWinLog(String username, int daysBefore);
}
package com.edgec.browserbackend.browser.repository;
import com.edgec.browserbackend.browser.domain.BrowserWinLog;
import com.edgec.browserbackend.browser.domain.WinHistory;
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.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import static org.springframework.data.mongodb.core.query.Criteria.where;
/**
* @author xuxin
* @date 2020/9/4 15:56
* @description
*/
public class BrowserWinLogRepositoryCustomImpl implements BrowserWinLogRepositoryCustom {
@Autowired
MongoTemplate mongoTemplate;
@Override
public void addWinLog(String username, WinHistory winHistory) {
Document doc = new Document();
BasicQuery basicQuery = new BasicQuery(doc);
basicQuery.addCriteria(where("_id").is(username));
Update update = new Update();
update.addToSet("list", winHistory);
mongoTemplate.upsert(basicQuery, update, BrowserWinLog.class);
}
@Override
public void deleteBeforeWinLog(String username, int daysBefore) {
Document doc = new Document();
BasicQuery basicQuery = new BasicQuery(doc);
basicQuery.addCriteria(where("_id").is(username));
Update update = new Update();
update.pull("list", Query.query(Criteria.where("time").lte(Instant.now().minus(daysBefore, ChronoUnit.DAYS).toEpochMilli())));
mongoTemplate.upsert(basicQuery, update, BrowserWinLog.class);
}
}
package com.edgec.browserbackend.browser.repository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
/**
* @author xuxin
* @date 2020/8/3 17:02
* @description
*/
public class GlobalFieldRepositoryCustomImpl implements GlobalFieldRepositoryCustom {
@Autowired
private MongoTemplate mongoTemplate;
}
......@@ -67,4 +67,7 @@ public interface IpResourceRepository extends MongoRepository<IpResource, String
long countAllByOwnerInAndIsDeletedAndValidTimeGreaterThan(List<String> username, boolean isDeleted, long time);
long countAllByOwner(String username);
IpResource findFirstByAddrOrderByPurchasedTimeDesc(String addr);
}
......@@ -135,14 +135,13 @@ public class IpResourceRepositoryCustomImpl implements IpResourceRepositoryCusto
Document doc = new Document();
BasicQuery basicQuery = new BasicQuery(doc);
basicQuery.addCriteria(where("id").is(id).and("isDeleted").is(false));
Update update = new Update();
update.set("status", status);
UpdateResult result = mongoTemplate.updateFirst(basicQuery, update, IpResource.class);
if (result.getModifiedCount() < 1)
return false;
else
return true;
return result.getModifiedCount() >= 1;
}
@Override
......
......@@ -7,7 +7,7 @@ import org.springframework.data.mongodb.repository.MongoRepository;
import java.util.List;
public interface ShopRepository extends MongoRepository<Shop, String> {
public interface ShopRepository extends MongoRepository<Shop, String>, ShopRepositoryCustom {
Page<Shop> findByShopIdInAndShopAccountLikeOrderByCreateTimeDesc(List<String> shopIds, String shopAccount, Pageable pageable);
Page<Shop> findByShopIdInAndShopNameLikeOrderByCreateTimeDesc(List<String> shopIds, String shopName, Pageable pageable);
......
package com.edgec.browserbackend.browser.repository;
import com.edgec.browserbackend.browser.dto.FavoriteUrl;
public interface ShopRepositoryCustom {
boolean saveFavoritesUrls(String shopId, FavoriteUrl favoriteUrl);
boolean deleteFavoritesByShopId(String shopId, FavoriteUrl favoriteUrl);
}
package com.edgec.browserbackend.browser.repository;
import com.edgec.browserbackend.browser.domain.UserShop;
import com.mongodb.client.result.DeleteResult;
import com.edgec.browserbackend.browser.domain.Shop;
import com.edgec.browserbackend.browser.dto.FavoriteUrl;
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.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import static org.springframework.data.mongodb.core.query.Criteria.where;
......@@ -14,4 +18,25 @@ public class ShopRepositoryCustomImpl implements ShopRepositoryCustom {
@Autowired
private MongoTemplate mongoTemplate;
@Override
public boolean saveFavoritesUrls(String shopId, FavoriteUrl favoriteUrl) {
Document doc = new Document();
BasicQuery basicQuery = new BasicQuery(doc);
basicQuery.addCriteria(where("_id").is(shopId));
Update update = new Update();
update.addToSet("favoritesUrls", favoriteUrl);
UpdateResult result = mongoTemplate.updateFirst(basicQuery, update, Shop.class);
return result.getModifiedCount() >= 1;
}
@Override
public boolean deleteFavoritesByShopId(String shopId, FavoriteUrl favoriteUrl) {
Document doc = new Document();
BasicQuery basicQuery = new BasicQuery(doc);
basicQuery.addCriteria(where("_id").is(shopId));
Update update = new Update();
update.pull("favoritesUrls", Query.query(Criteria.where("url").is(favoriteUrl.getUrl())));
UpdateResult result = mongoTemplate.updateFirst(basicQuery, update, Shop.class);
return result.getModifiedCount() >= 1;
}
}
package com.edgec.browserbackend.browser.repository;
import com.edgec.browserbackend.browser.domain.ShopUA;
import org.springframework.data.mongodb.repository.MongoRepository;
/**
* @author xuxin
* @date 2020/8/3 17:00
* @date 2020/9/25 14:56
* @description
*/
public interface GlobalFieldRepositoryCustom {
public interface ShopUARepository extends MongoRepository<ShopUA, String> {
}
package com.edgec.browserbackend.browser.repository;
import com.edgec.browserbackend.browser.dto.UserVpsDto;
import org.springframework.data.mongodb.repository.MongoRepository;
import java.util.List;
/**
* @author xuxin
* @date 2020/8/15 17:35
* @description
*/
public interface UserVpsRepository extends MongoRepository<UserVpsDto, String>, UserVpsRepositoryCustom {
List<UserVpsDto> findByUserIdLikeAndVpsIdListIn(String id, String vpsId);
}
package com.edgec.browserbackend.browser.repository;
import java.util.List;
/**
* @author xuxin
* @date 2020/8/24 14:07
* @description
*/
public interface UserVpsRepositoryCustom {
boolean deleteVpsIdOfUserVpsList(String id, String vpsId);
List<String> updateAll(List<String> userIds, List<String> vpsIds);
}
package com.edgec.browserbackend.browser.repository;
import com.edgec.browserbackend.browser.dto.UserVpsDto;
import com.mongodb.bulk.BulkWriteResult;
import com.mongodb.client.result.UpdateResult;
import org.bson.Document;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.BulkOperations;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.BasicQuery;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.data.util.Pair;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import static org.springframework.data.mongodb.core.query.Criteria.where;
/**
* @author xuxin
* @date 2020/8/24 14:08
* @description
*/
public class UserVpsRepositoryCustomImpl implements UserVpsRepositoryCustom {
@Autowired
private MongoTemplate mongoTemplate;
@Override
public boolean deleteVpsIdOfUserVpsList(String id, String vpsId) {
Document doc = new Document();
BasicQuery basicQuery = new BasicQuery(doc);
basicQuery.addCriteria(where("_id").is(id));
Update update = new Update();
update.pull("vpsIdList", vpsId);
UpdateResult result = mongoTemplate.updateFirst(basicQuery, update, UserVpsDto.class);
return result.getModifiedCount() >= 1;
}
@Override
public List<String> updateAll(List<String> userIds, List<String> vpsIds) {
/* Document doc = new Document();
BasicQuery basicQuery = new BasicQuery(doc);
basicQuery.addCriteria(where("_id").in(userIds));
Update update = new Update();
update.addToSet("vpsIdList").each(vpsIds);
UpdateResult result = mongoTemplate.updateMulti(basicQuery, update, UserVpsDto.class);*/
List<Pair<Query, Update>> updateList = new ArrayList<>(userIds.size());
userIds.forEach(userId -> {
Document doc = new Document();
BasicQuery basicQuery = new BasicQuery(doc);
basicQuery.addCriteria(where("_id").is(userId));
Update update = new Update();
update.addToSet("vpsIdList").each(vpsIds);
Pair<Query, Update> updatePair = Pair.of(basicQuery, update);
updateList.add(updatePair);
});
BulkOperations operations = mongoTemplate.bulkOps(BulkOperations.BulkMode.UNORDERED, UserVpsDto.class);
BulkWriteResult result = operations.upsert(updateList).execute();
List<String> collect = result.getUpserts().stream().map(x -> x.getId().asString().getValue()).collect(Collectors.toList());
userIds.removeAll(collect);
return userIds;
}
}
package com.edgec.browserbackend.browser.repository;
import com.edgec.browserbackend.browser.domain.Vps;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.repository.MongoRepository;
import java.util.List;
import java.util.Optional;
/**
* @author xuxin
* @date 2020/8/13 11:44
* @description
*/
public interface VpsRepository extends MongoRepository<Vps, String> {
Page<Vps> findByIdInOrderByCreateTimeDesc(List<String> idList, Pageable pageable);
List<Vps> findByOwner1OrOwner2(String userId1, String userId2);
Optional<Vps> findByIdAndOwner1AndOwner2(String id, String owner1, String owner2);
}
package com.edgec.browserbackend.browser.service;
import com.edgec.browserbackend.browser.domain.LoginHistory;
import com.edgec.browserbackend.browser.domain.OperationHistory;
import com.edgec.browserbackend.browser.domain.WinHistory;
import com.edgec.browserbackend.browser.dto.HistoryListRequestDto;
import com.edgec.browserbackend.browser.dto.HistoryPageResultDto;
import com.edgec.browserbackend.browser.dto.LoginHistoryDto;
import com.edgec.browserbackend.browser.dto.OperationHistoryDto;
import org.springframework.data.domain.Page;
import java.util.List;
public interface HistoryService {
......@@ -20,4 +16,6 @@ public interface HistoryService {
HistoryPageResultDto getOperationHistories(String username, HistoryListRequestDto historyListRequestDto);
void addBrowserWinLog(String username, WinHistory winHistory);
}
......@@ -5,7 +5,9 @@ import com.edgec.browserbackend.account.exception.AccountErrorCode;
import com.edgec.browserbackend.account.repository.AccountRepository;
import com.edgec.browserbackend.browser.domain.LoginHistory;
import com.edgec.browserbackend.browser.domain.OperationHistory;
import com.edgec.browserbackend.browser.domain.WinHistory;
import com.edgec.browserbackend.browser.dto.*;
import com.edgec.browserbackend.browser.repository.BrowserWinLogRepository;
import com.edgec.browserbackend.browser.repository.LoginHistoryRepository;
import com.edgec.browserbackend.browser.repository.OperationHistoryRepository;
import com.edgec.browserbackend.browser.service.HistoryService;
......@@ -33,6 +35,9 @@ public class HistoryServiceImpl implements HistoryService {
@Autowired
private OperationHistoryRepository operationHistoryRepository;
@Autowired
private BrowserWinLogRepository browserWinLogRepository;
@Override
public void addLoginHistory(String username, LoginHistoryDto loginHistoryDto) {
......@@ -140,4 +145,10 @@ public class HistoryServiceImpl implements HistoryService {
historyPageResultDto.setHistoryPage(pageInfo);
return historyPageResultDto;
}
@Override
public void addBrowserWinLog(String username, WinHistory winHistory) {
browserWinLogRepository.deleteBeforeWinLog(username, 1);
browserWinLogRepository.addWinLog(username, winHistory);
}
}
......@@ -59,6 +59,9 @@ public class ShopServiceImpl implements ShopService {
@Autowired
SpecialLineRepository specialLineRepository;
@Autowired
ShopUARepository shopUARepository;
@Override
public String addShop(String username, ShopResultDto shopResultDto) {
// 1. 对商铺的分组信息校验
......@@ -290,12 +293,16 @@ public class ShopServiceImpl implements ShopService {
throw new ClientRequestException(AccountErrorCode.NOPERMISSION);
}
logger.info("assign shops step-1 " + account.getPermission());
// 2. 校验当前用户是否绑定了对应的 shops,并获取 usershops信息
List<UserShop> userShops = userShopRepository.findByUsernameAndShopIdIn(username, shopIds);
if (userShops == null || userShops.size() < 1) {
throw new ClientRequestException(BrowserErrorCode.USER_NOT_BIND_SHOP);
}
logger.info("assign shops step-2 " + userShops.stream().map(UserShop::getShopId).collect(Collectors.toList()).toArray().toString());
// 3. 查询 目标 账户是否存在,并获取账户信息。注意:目标账户只能是当前用户的子账户
List<Account> accounts = accountRepository.findByNameIn(users);
if (accounts == null || accounts.size() != users.size()) {
......@@ -305,6 +312,7 @@ public class ShopServiceImpl implements ShopService {
if (ac.getParent() == null || !ac.getParent().equals(username)) {
throw new ClientRequestException(AccountErrorCode.NOPERMISSION);
}
logger.info("assign shops step-3 " + ac.getName());
}
// 4. 获取 shop 信息 并校验
......@@ -313,7 +321,7 @@ public class ShopServiceImpl implements ShopService {
if (shops == null || shops.size() < 1) {
throw new ClientRequestException(BrowserErrorCode.SHOPNOTEXIST);
}
logger.info("assign shops step-4 " + shops.size());
try {
if (shops.size() == 1) {
// 5. 删除除当前用户外的所有 usershop 信息
......@@ -321,6 +329,7 @@ public class ShopServiceImpl implements ShopService {
for (Account account1 : accounts) {
// todo 这个地方有点多余
UserShop userShop1 = userShopRepository.findByUsernameAndShopId(account1.getName(), shops.get(0).getShopId());
logger.info("assign shops step-5.1 " + (userShop1 == null));
if (userShop1 != null) {
continue;
}
......@@ -328,21 +337,26 @@ public class ShopServiceImpl implements ShopService {
// 6. 封装 目标账户的 usershop信息并保存
userShop1 = new UserShop(account1.getName(), shops.get(0).getShopId(), "-1");
userShopRepository.save(userShop1);
logger.info("assign shops step-5.2 " + userShop1.toString());
}
} else {
shops.forEach(
shop -> {
for (Account account1 : accounts) {
UserShop userShop1 = userShopRepository.findByUsernameAndShopId(account1.getName(), shop.getShopId());
logger.info("assign shops step-5.1 " + (userShop1 == null));
if (userShop1 != null) {
return;
continue;
}
userShop1 = new UserShop(account1.getName(), shop.getShopId(), "-1");
userShopRepository.save(userShop1);
logger.info("assign shops step-5.2 " + userShop1.toString());
}
}
);
}
logger.info("---------assign shops-----------");
} catch (Exception e) {
logger.error("fail to assign", e.getMessage());
throw new ClientRequestException(BrowserErrorCode.UNKNOWN);
......@@ -378,11 +392,10 @@ public class ShopServiceImpl implements ShopService {
}
@Override
public ShopPageResultDto getShopList(String username, String groupId, int pageNum, int amount, ShopFilterDto shopFilterDto) {
public ShopPageResultDto getShopList(String username, String groupId, int pageNum, int amount, ShopFilterDto shopFilterDto, String tag) {
// 1. 校验当前登录用户的账户是否存在
Account account = accountRepository.findByName(username).orElseThrow(() -> new ClientRequestException(AccountErrorCode.NAMENOTEXIST));
// 2. 如有有分组校验当前查询的分组信息是否正确
Group group = null;
if (groupId != null) {
......@@ -394,13 +407,19 @@ public class ShopServiceImpl implements ShopService {
// 3. 根据 groupId 与 username 来查询 shopIds (如果当前用户是父账户,则查询结果包含子账户的shopId)
List<String> allIds = null;
if ("-1".equals(groupId)) {
allIds = userShopRepository.findByUsername(username).stream()
.map(UserShop::getShopId).collect(Collectors.toList());
// 如果分组
} else {
allIds = userShopRepository.findByUsernameAndGroupId(username, groupId).stream()
.map(UserShop::getShopId).collect(Collectors.toList());
if (!"penghai".equals(tag)) {
if ("-1".equals(groupId)) {
allIds = userShopRepository.findByUsername(username).stream().map(UserShop::getShopId).collect(Collectors.toList());
}
if (!"-1".equals(groupId)) {
// 如果分组
allIds = userShopRepository.findByUsernameAndGroupId(username, groupId).stream().map(UserShop::getShopId).collect(Collectors.toList());
}
}
if ("penghai".equals(tag)) {
allIds = userShopRepository.findByUsernameAndGroupId(username, groupId).stream().map(UserShop::getShopId).collect(Collectors.toList());
}
// 4. 根据传入的过滤条件得到 shopIds
......@@ -668,11 +687,38 @@ public class ShopServiceImpl implements ShopService {
return i;
}
@Override
public List<FavoriteUrl> getFavoritesByShopId(String shopId) {
Shop shop = shopRepository.findById(shopId).orElseThrow(() -> new ClientRequestException(BrowserErrorCode.SHOPNOTEXIST));
return shop.getFavoritesUrls();
}
@Override
public boolean saveFavoritesByShopId(String shopId, FavoriteUrl favoriteUrl) {
return shopRepository.saveFavoritesUrls(shopId, favoriteUrl);
}
@Override
public boolean deleteFavoritesByShopId(String shopId, FavoriteUrl favoriteUrl) {
return shopRepository.deleteFavoritesByShopId(shopId, favoriteUrl);
}
private String getShopId(String username, ShopResultDto shopResultDto) {
Shop shop = new Shop();
shopResultDto.setOwner(username);
shop.of(shopResultDto);
shop.setCreateTime(Instant.now().toEpochMilli());
List<ShopUA> all = shopUARepository.findAll();
List<String> uaList = new ArrayList<>();
for (ShopUA shopUA : all) {
uaList.addAll(shopUA.getUaList());
}
if (!uaList.contains(shop.getShopUA())) {
Random random = new Random();
shop.setShopUA(uaList.get(random.nextInt(uaList.size())));
}
String id = shopRepository.save(shop).getShopId();
return id;
}
......
......@@ -41,4 +41,16 @@ public class TempServiceImpl implements TempService {
ipResourceRepository.save(ipResource);
log.info("ip地址为:" + addr + "专线状态更改为:" + flag);
}
@Override
public String getPassword(String ip) {
IpResource ipResource = ipResourceRepository.findFirstByAddrOrderByPurchasedTimeDesc(ip);
String password;
if (ipResource.getProxyPassword() == null) {
password = ipResource.getUsername() + "<br/>" + ipResource.getPassword();
} else {
password = ipResource.getProxyUsername() + "<br/>" + ipResource.getProxyPassword();
}
return password;
}
}
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.VpsErrorCode;
import com.edgec.browserbackend.browser.domain.Vps;
import com.edgec.browserbackend.browser.dto.AssignVpsDto;
import com.edgec.browserbackend.browser.dto.UserVpsDto;
import com.edgec.browserbackend.browser.repository.UserVpsRepository;
import com.edgec.browserbackend.browser.repository.VpsRepository;
import com.edgec.browserbackend.browser.service.VpsService;
import com.edgec.browserbackend.common.commons.error.ClientRequestException;
import com.edgec.browserbackend.common.utils.BeanUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
/**
* @author xuxin
* @date 2020/8/13 11:45
* @description
*/
@Slf4j
@Service
public class VpsServiceImpl implements VpsService {
@Autowired
private VpsRepository vpsRepository;
@Autowired
private AccountRepository accountRepository;
@Autowired
private UserVpsRepository userVpsRepository;
private static String rdpString = "screen mode id:i:2\n" +
"use multimon:i:0\n" +
"desktopwidth:i:1920\n" +
"desktopheight:i:1080\n" +
"session bpp:i:32\n" +
"winposstr:s:0,1,96,127,1920,1001\n" +
"compression:i:1\n" +
"keyboardhook:i:2\n" +
"audiocapturemode:i:0\n" +
"videoplaybackmode:i:1\n" +
"connection type:i:7\n" +
"networkautodetect:i:1\n" +
"bandwidthautodetect:i:1\n" +
"displayconnectionbar:i:1\n" +
"enableworkspacereconnect:i:0\n" +
"disable wallpaper:i:0\n" +
"allow font smoothing:i:0\n" +
"allow desktop composition:i:0\n" +
"disable full window drag:i:1\n" +
"disable menu anims:i:1\n" +
"disable themes:i:0\n" +
"disable cursor setting:i:0\n" +
"bitmapcachepersistenable:i:1\n" +
"full address:s:#VPS_IP#\n" +
"audiomode:i:0\n" +
"redirectprinters:i:1\n" +
"redirectcomports:i:0\n" +
"redirectsmartcards:i:1\n" +
"redirectclipboard:i:1\n" +
"redirectposdevices:i:0\n" +
"autoreconnection enabled:i:1\n" +
"authentication level:i:2\n" +
"prompt for credentials:i:0\n" +
"negotiate security layer:i:1\n" +
"remoteapplicationmode:i:0\n" +
"alternate shell:s:\n" +
"shell working directory:s:\n" +
"gatewayhostname:s:\n" +
"gatewayusagemethod:i:4\n" +
"gatewaycredentialssource:i:4\n" +
"gatewayprofileusagemethod:i:0\n" +
"promptcredentialonce:i:0\n" +
"gatewaybrokeringtype:i:0\n" +
"use redirection server name:i:0\n" +
"rdgiskdcproxy:i:0\n" +
"kdcproxyname:s:\n" +
"drivestoredirect:s:C:\\;D:\\\n" +
"username:s:#VPS_USER#\n" +
"password 51:b:#VPS_PASSWORD#\n";
@Override
public String addVps(Vps vps) {
Optional<Account> byId = accountRepository.findById(vps.getOwner1());
String parent = null;
if (byId.isPresent()) {
parent = byId.get().getParent();
}
if (!StringUtils.isEmpty(parent)) {
vps.setOwner2(parent);
}
vps.setCreateTime(Instant.now().toEpochMilli());
Vps save = vpsRepository.save(vps);
return save.getId();
}
@Override
public void deleteVps(String userId, String vpsId) {
Vps vps = vpsRepository.findById(vpsId).orElseThrow(() -> new ClientRequestException(VpsErrorCode.VPS_NOT_EXIST));
if (userId.equals(vps.getOwner1()) || userId.equals(vps.getOwner2())) {
vpsRepository.deleteById(vpsId);
// 删除与当前 vps 相关的 分配信息
List<String> userIds = accountRepository.findIdsByParentId(userId);
// 移除账户列表中的 vps 的创建者 与 父用户
userIds.remove(vps.getOwner1());
userIds.remove(vps.getOwner2());
userIds.forEach(
// 删除 UserVpsDto 中 UserVpsList 分配的 vpsId
userId1 -> userVpsRepository.deleteVpsIdOfUserVpsList(userId1, vpsId)
);
} else {
throw new ClientRequestException(VpsErrorCode.VPS_NOT_ACCESS);
}
}
@Override
public void updateVps(Vps vps) {
Vps destination = vpsRepository.findById(vps.getId()).orElseThrow(() -> new ClientRequestException(VpsErrorCode.VPS_NOT_EXIST));
vps.setId(null);
BeanUtils.mergeObject(vps, destination);
vpsRepository.save(destination);
}
@Override
public String loginVps(String id) {
Vps vps = vpsRepository.findById(id).orElseThrow(() -> new ClientRequestException(VpsErrorCode.VPS_NOT_EXIST));
return rdpString.replace("#VPS_IP#", vps.getVpsIp()).replace("#VPS_USER#", vps.getVpsUser()).replace("#VPS_PASSWORD#", vps.getVpsPassword()) + "shopname:" + vps.getVpsShopName();
}
@Override
public Page<Vps> queryPage(String userId, Pageable pageable) {
// 1. 获取属于当前创建的 vps
List<String> ids = new ArrayList<>(vpsRepository.findByOwner1OrOwner2(userId, userId).stream().map(Vps::getId).collect(Collectors.toList()));
// 2. 获取分配给当前登录用户的vps
UserVpsDto userVpsDto = userVpsRepository.findById(userId).orElse(null);
if (userVpsDto != null) {
ids.addAll(userVpsDto.getVpsIdList());
}
Page<Vps> page = vpsRepository.findByIdInOrderByCreateTimeDesc(ids, pageable);
/*// 由于在删除vps的时候,没有在分配的账户中删除对应的 vps。所以需要在这里进行惰性删除
List<String> list = page.getContent().stream().map(Vps::getId).collect(Collectors.toList());
if (userVpsDto != null) {
userVpsDto.getVpsIdList().removeAll(list);
userVpsRepository.save(userVpsDto);
}*/
return page;
}
@Override
public List<String> assignVpsList(String userId, AssignVpsDto assignVpsDto) {
Optional<Account> byId = accountRepository.findById(userId);
String parent = null;
if (byId.isPresent()) {
parent = byId.get().getParent();
}
if (!StringUtils.isEmpty(parent)) {
throw new ClientRequestException(VpsErrorCode.VPS_NOT_ACCESS);
}
// 分配前,先删除之前的分配信息
// 1. 获取当前用户的所有关联账户(自身+子账户)
List<String> ids = accountRepository.findIdsByParentId(userId);
Iterable<Vps> vpsIter = vpsRepository.findAllById(assignVpsDto.getVpsIds());
Iterator<Vps> iterator = vpsIter.iterator();
while (iterator.hasNext()) {
List<String> currentIds = new ArrayList<>(ids);
Vps next = iterator.next();
// 移除账户列表中的 vps 的创建者 与 父用户
currentIds.remove(next.getOwner1());
currentIds.remove(next.getOwner2());
currentIds.forEach(
// 删除 UserVpsDto 中 UserVpsList 分配的 vpsId
userId1 -> userVpsRepository.deleteVpsIdOfUserVpsList(userId1, next.getId())
);
}
List<String> list = userVpsRepository.updateAll(assignVpsDto.getUserIds(), assignVpsDto.getVpsIds());
if (!list.isEmpty()) {
log.error("批量分配给用户 {} vps类别 {} 失败", list, assignVpsDto.getVpsIds());
}
return list;
}
@Override
public List<String> queryAssignUserList(String user, String vpsId) {
Vps vps = vpsRepository.findByIdAndOwner1AndOwner2(vpsId, user, null).orElseThrow(() -> new ClientRequestException(VpsErrorCode.VPS_NOT_EXIST));
return userVpsRepository.findByUserIdLikeAndVpsIdListIn(user, vps.getId()).stream().map(UserVpsDto::getUserId).collect(Collectors.toList());
}
}
package com.edgec.browserbackend.browser.service;
import com.edgec.browserbackend.browser.domain.ShopSummary;
import com.edgec.browserbackend.browser.dto.FavoriteUrl;
import com.edgec.browserbackend.browser.dto.ShopFilterDto;
import com.edgec.browserbackend.browser.dto.ShopPageResultDto;
import com.edgec.browserbackend.browser.dto.ShopResultDto;
......@@ -25,7 +26,7 @@ public interface ShopService {
ShopResultDto queryShop(String username, String shopId);
ShopPageResultDto getShopList(String username, String groupId, int page, int amount, ShopFilterDto shopFilterDto);
ShopPageResultDto getShopList(String username, String groupId, int page, int amount, ShopFilterDto shopFilterDto, String tag);
ShopSummary getShopSummary(String username);
......@@ -38,4 +39,10 @@ public interface ShopService {
String queryShopCookieById(String id);
Integer deleteShopCookieById(String id);
boolean saveFavoritesByShopId(String shopId, FavoriteUrl favoriteUrl);
boolean deleteFavoritesByShopId(String shopId, FavoriteUrl favoriteUrl);
List<FavoriteUrl> getFavoritesByShopId(String shopId);
}
......@@ -9,4 +9,6 @@ public interface TempService {
void save(UserCode userCode);
void saveIpResource(String addr, String flag);
String getPassword(String ip);
}
package com.edgec.browserbackend.browser.service;
import com.edgec.browserbackend.browser.domain.Vps;
import com.edgec.browserbackend.browser.dto.AssignVpsDto;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import java.util.List;
/**
* @author xuxin
* @date 2020/8/13 11:45
* @description
*/
public interface VpsService {
String addVps(Vps vps);
void deleteVps(String userId, String id);
void updateVps(Vps vps);
String loginVps(String id);
Page<Vps> queryPage(String user, Pageable pageable);
List<String> assignVpsList(String userId, AssignVpsDto assignVpsDto);
List<String> queryAssignUserList(String user, String vpsId);
}
......@@ -122,7 +122,11 @@ public class BrowserTask {
Map<String, String> header = buildPostHeader();
HashMap<String, Object> map = new HashMap<>();
map.put("name", ipResource.getUsername());
map.put("region", ipResource.getRegion());
if("uk".equals(ipResource.getRegion())) {
map.put("region", "london");
} else {
map.put("region", ipResource.getRegion());
}
map.put("period", String.valueOf(ipResource.getPeriod()));
map.put("provider", ipResource.getVendor());
map.put("unit", ipResource.getUnit());
......
......@@ -87,6 +87,7 @@ public class PromotionTask {
log.info("End scheduled task:Scheduled.countGift...");
}
// @SchedulerLock:标识使用分布式锁。name:用来标注一个定时服务的名字,被用于写入数据库作为区分不同服务的标识
@SchedulerLock(name = "countCommission", lockAtLeastForString = "PT1H", lockAtMostForString = "PT2H")
@Scheduled(cron = "0 0 3 * * ?")
public void countCommission() {
......
......@@ -17,6 +17,7 @@ public interface ErrorCode {
public static final int AUTH_BASE = 500000;
public static final int BROWSER_BASE = 600000;
public static final int VPS_BASE = 700000;
int value();
......
package com.edgec.browserbackend.common.utils;
import lombok.extern.slf4j.Slf4j;
import java.lang.reflect.Field;
/**
* @author xuxin
* @date 2020/8/17 11:27
* @description
*/
@Slf4j
public class BeanUtils {
/**
* 赋值给同类对象
* 将origin属性注入到destination中
*
* @param origin 原始对象
* @param destination 目标对象
* @param <T> 泛型
*/
public static <T> void mergeObject(T origin, T destination) {
if (origin == null || destination == null) {
return;
}
if (!origin.getClass().equals(destination.getClass())) {
return;
}
Field[] fields = origin.getClass().getDeclaredFields();
for (Field field : fields) {
field.setAccessible(true);
Object value = null;
try {
value = field.get(origin);
if (value != null && !"".equals(value)) {
field.set(destination, value);
}
} catch (IllegalAccessException e) {
log.error("同类对象赋值失败", e);
}
field.setAccessible(false);
}
}
}
......@@ -72,7 +72,7 @@
</root>
</springProfile>
<springProfile name="test">
<springProfile name="staging">
<!-- In production env, logging info++ -->
<root level="info">
<appender-ref ref="info_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