Commit 76110c26 authored by xuxin's avatar xuxin

shopUA相关修改

parent 0cf647dd
......@@ -3,7 +3,10 @@ package com.edgec.browserbackend.browser.controller;
import com.alibaba.fastjson.JSONObject;
import com.edgec.browserbackend.account.dto.ResultDto;
import com.edgec.browserbackend.browser.ErrorCode.BrowserErrorCode;
import com.edgec.browserbackend.browser.dto.*;
import com.edgec.browserbackend.browser.dto.ShopPageResultDto;
import com.edgec.browserbackend.browser.dto.ShopRequestDto;
import com.edgec.browserbackend.browser.dto.ShopResultDto;
import com.edgec.browserbackend.browser.dto.ShopStringResultDto;
import com.edgec.browserbackend.browser.service.IpAndShopService;
import com.edgec.browserbackend.browser.service.ShopService;
import com.edgec.browserbackend.common.commons.error.ClientRequestException;
......@@ -275,52 +278,6 @@ public class ShopController {
}
/**
* 店铺收藏夹
*//*
@GetMapping("/favorites/{shopId}")
public ResultDto getFavoritesByShopId(Principal principal, @PathVariable("shopId") String shopId) {
ResultDto resultDto = new ResultDto();
try {
List<FavoriteUrl> list = shopService.getFavoritesByShopId(principal.getName(), shopId);
resultDto.setData(list);
resultDto.setStatus(0);
} catch (ClientRequestException e) {
dealClientRequestException(resultDto, e);
}
return resultDto;
}
*//**
* 店铺收藏夹 删除收藏
*//*
@DeleteMapping("/favorites/{shopId}")
public ResultDto deleteFavoritesByShopId(Principal principal, @PathVariable("shopId") String shopId, @RequestBody FavoriteUrl favoriteUrl) {
ResultDto resultDto = new ResultDto();
try {
resultDto.setData(shopService.deleteFavoritesByShopId(principal.getName(), shopId, favoriteUrl));
resultDto.setStatus(0);
} catch (ClientRequestException e) {
dealClientRequestException(resultDto, e);
}
return resultDto;
}
*//**
* 店铺收藏夹 新增收藏
*//*
@PostMapping("/favorites/{shopId}")
public ResultDto saveFavoritesByShopId(Principal principal, @PathVariable("shopId") String shopId, @RequestBody FavoriteUrl favoriteUrl) {
ResultDto resultDto = new ResultDto();
try {
resultDto.setData(shopService.saveFavoritesByShopId(principal.getName(), shopId, favoriteUrl));
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<>();
......
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.repository;
import com.edgec.browserbackend.browser.domain.ShopUA;
import org.springframework.data.mongodb.repository.MongoRepository;
/**
* @author xuxin
* @date 2020/9/25 14:56
* @description
*/
public interface ShopUARepository extends MongoRepository<ShopUA, String> {
}
......@@ -59,6 +59,9 @@ public class ShopServiceImpl implements ShopService {
@Autowired
SpecialLineRepository specialLineRepository;
@Autowired
ShopUARepository shopUARepository;
@Override
public String addShop(String username, ShopResultDto shopResultDto) {
// 1. 对商铺的分组信息校验
......@@ -705,6 +708,17 @@ public class ShopServiceImpl implements ShopService {
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;
}
......
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