Commit a0be941e authored by Administrator's avatar Administrator

Merge branch 'hotfix-platformoptions' into 'master'

新增修改platformOptions地址接口

See merge request !212
parents 4c5613d3 54d3043d
......@@ -21,4 +21,12 @@ public class LimitedUsers {
}
}
}
private final static String ADMINISTRATORS = "15919921106";
public static void filterIfLimitedAdministrators(Principal principal) {
if (!ADMINISTRATORS.equals(principal.getName())) {
throw new ClientRequestException(AccountErrorCode.UNAUTHORIZED, "Not allowed");
}
}
}
......@@ -6,14 +6,17 @@ 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.dto.TempReportDto;
import com.edgec.browserbackend.browser.service.IpResourceService;
import com.edgec.browserbackend.browser.service.ShopService;
import com.edgec.browserbackend.browser.service.TempService;
import com.edgec.browserbackend.common.commons.error.ClientRequestException;
import com.edgec.browserbackend.common.utils.ResponseUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.security.Principal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -33,6 +36,9 @@ public class TempController {
@Autowired
private ShopService shopService;
@Autowired
private IpResourceService ipResourceService;
/**
* 记住用户明文密码
*/
......@@ -123,4 +129,31 @@ public class TempController {
resultDto.setStatusInfo(statusInfo);
}
/**
* 更换platformOptions地址
*
* @param principal 校验是否是管理员
* @param platform 平台
* @param subPlatform 平台站点
* @param url url
* @return ResultDto
*/
@RequestMapping(value = "/updatePlatformOptions", method = RequestMethod.GET)
public ResultDto updatePlatformOptions(
Principal principal,
@RequestParam String platform,
@RequestParam String subPlatform,
@RequestParam String url) {
String logs = "【updatePlatformOptions】 ";
log.info("{}, params : {}", logs, principal.getName());
try {
return ResponseUtil.success(ipResourceService.updatePlatformOptions(principal, platform, subPlatform, url));
} catch (ClientRequestException e) {
log.warn("{}, ClientRequestException : {}", logs, e.getErrorCode().getReason());
return ResponseUtil.error(e.getErrorCode());
} catch (Exception e) {
log.error("{}, Exception : {}", logs, e.getMessage(), e);
return ResponseUtil.error(e.getMessage());
}
}
}
......@@ -10,7 +10,7 @@ import java.util.List;
* @Author jason
* @CreateTime 2020/3/12 12:02 下午
**/
public interface PlatformOptionsRepository extends MongoRepository<PlatformOptions, String> {
public interface PlatformOptionsRepository extends MongoRepository<PlatformOptions, String>, PlatformOptionsRepositoryCustom {
List<PlatformOptions> findAllByOrderByWeightDesc();
List<PlatformOptions> findAllByDeletedIsNotOrderByWeightDesc(boolean b);
......
package com.edgec.browserbackend.browser.repository;
/**
* @author JMW
*/
public interface PlatformOptionsRepositoryCustom {
/**
* 更新subPlatform url
*
* @param platform 平台
* @param subPlatform 平台站点
* @param url url
* @return boolean
*/
boolean updatePlatformOptions(String platform, String subPlatform, String url);
}
package com.edgec.browserbackend.browser.repository;
import com.edgec.browserbackend.browser.domain.PlatformOptions;
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;
/**
* @author JMW
*/
public class PlatformOptionsRepositoryCustomImpl implements PlatformOptionsRepositoryCustom {
@Autowired
MongoTemplate mongoTemplate;
@Override
public boolean updatePlatformOptions(String platform, String subPlatform, String url) {
Document doc = new Document();
BasicQuery basicQuery = new BasicQuery(doc);
basicQuery.addCriteria(where("platform").is(platform));
Update update = new Update();
update.set("subPlatform." + subPlatform, url);
return mongoTemplate.updateFirst(basicQuery, update, PlatformOptions.class).getMatchedCount() >= 1;
}
}
......@@ -2,6 +2,7 @@ package com.edgec.browserbackend.browser.service.Impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.edgec.browserbackend.account.controller.LimitedUsers;
import com.edgec.browserbackend.account.domain.Account;
import com.edgec.browserbackend.account.domain.IpChargeRequestDto;
import com.edgec.browserbackend.account.domain.IpChargeResultDto;
......@@ -34,6 +35,7 @@ import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import java.io.File;
import java.security.Principal;
import java.time.Instant;
import java.time.ZoneOffset;
import java.util.*;
......@@ -905,6 +907,12 @@ public class IpResourceServiceImpl implements IpResourceService {
}
}
@Override
public boolean updatePlatformOptions(Principal principal, String platform, String subPlatform, String url) {
LimitedUsers.filterIfLimitedAdministrators(principal);
return platformOptionsRepository.updatePlatformOptions(platform, subPlatform, url);
}
private IpChargeRequestDto buildIpChargeRequestDto(IpResourceRequestDto request, int chargeType, int payMethod) {
IpChargeRequestDto ipChargeRequestDto = new IpChargeRequestDto();
......
......@@ -5,6 +5,7 @@ import com.edgec.browserbackend.browser.domain.IpSummary;
import com.edgec.browserbackend.browser.domain.PlatformOptions;
import com.edgec.browserbackend.browser.dto.*;
import java.security.Principal;
import java.util.List;
public interface IpResourceService {
......@@ -38,4 +39,15 @@ public interface IpResourceService {
void releaseDeletedIp();
void transferBindShops();
/**
* 更换platformOptions地址
*
* @param principal 校验是否是管理员
* @param platform 平台
* @param subPlatform 平台站点
* @param url url
* @return boolean
*/
boolean updatePlatformOptions(Principal principal, String platform, String subPlatform, String url);
}
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