Commit 1a0b79dc authored by renjie's avatar renjie
parents 17aa7972 3f870445
FROM java:8-jre
ADD ./target/browser-backend-0.0.1-SNAPSHOT.jar /app/
ADD ./target/classes/logback-spring.xml /app/config/
CMD ["java", "-Xmx500m", "-Dlogging.config=file:/app/config/logback-spring.xml", "-jar", "/app/browser-backend-0.0.1-SNAPSHOT.jar"]
EXPOSE 1729
#!/bin/bash
git pull
mvn package spring-boot:repackage -Dmaven.test.skip=true
export DOCKER_HOST=registry.cn-shenzhen.aliyuncs.com
export DOCKER_USER=liqingsong@1616554330968404
export DOCKER_PASS=Edgec2018
export COMMIT=`date +%s | md5sum | head -c 10 ; echo`
export TAG="latest"
export BROWSER=cloudam/browser
sudo docker build -t $BROWSER:$COMMIT .
sudo docker tag $BROWSER:$COMMIT $DOCKER_HOST/$BROWSER:$TAG
sudo docker push $DOCKER_HOST/$BROWSER
......@@ -93,11 +93,6 @@
<artifactId>aliyun-java-sdk-core</artifactId>
<version>4.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.3</version>
</dependency>
<dependency>
<groupId>com.alipay.sdk</groupId>
<artifactId>alipay-sdk-java</artifactId>
......@@ -157,6 +152,17 @@
<artifactId>shedlock-spring</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.16</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.16</version>
</dependency>
</dependencies>
<build>
......
......@@ -249,14 +249,14 @@ public class AccountController {
return paymentService.wechatPayCallback(tradno);
}
@RequestMapping(path = "/0xwxcheckorderstatus/{tradno}", method = RequestMethod.GET)
public UserPaymentDto wechatCheckOrderStatus(Principal principal, @PathVariable String tradno) {
return paymentService.wxCheckOrderStatus(tradno);
@RequestMapping(path = "/0xwxcheckorderstatus/{tradno}/{more}", method = RequestMethod.GET)
public UserPaymentDto wechatCheckOrderStatus(Principal principal, @PathVariable String tradno, @PathVariable int more) {
return paymentService.wxCheckOrderStatus(tradno, more);
}
@RequestMapping(path = "/wxpay/checkstatus/{tradno}", method = RequestMethod.GET)
public UserPaymentDto wechatPayCheckStatus(@PathVariable String tradno) {
return paymentService.wxCheckOrderStatus(tradno);
@RequestMapping(path = "/wxpay/checkstatus/{tradno}/{more}", method = RequestMethod.GET)
public UserPaymentDto wechatPayCheckStatus(@PathVariable String tradno, @PathVariable int more) {
return paymentService.wxCheckOrderStatus(tradno, more);
}
@RequestMapping(path = "/0xalipaycallback/{tradno}", method = RequestMethod.GET)
......@@ -264,15 +264,15 @@ public class AccountController {
paymentService.alipaCallback(tradno);
}
@RequestMapping(path = "/0xalicheckorderstatus/{tradno}", method = RequestMethod.GET)
public UserPaymentDto alipayCheckOrderStatus(Principal principal, @PathVariable String tradno) {
return paymentService.aliCheckOrderStatus(tradno);
@RequestMapping(path = "/0xalicheckorderstatus/{tradno}/{more}", method = RequestMethod.GET)
public UserPaymentDto alipayCheckOrderStatus(Principal principal, @PathVariable String tradno, @PathVariable int more) {
return paymentService.aliCheckOrderStatus(tradno, more);
}
@RequestMapping(path = "/alipay/checkstatus/{tradno}", method = RequestMethod.GET)
@RequestMapping(path = "/alipay/checkstatus/{tradno}/{more}", method = RequestMethod.GET)
@PreAuthorize("#oauth2.hasScope('server')")
public UserPaymentDto alipayCheckStatus(@PathVariable String tradno) {
return paymentService.aliCheckOrderStatus(tradno);
public UserPaymentDto alipayCheckStatus(@PathVariable String tradno, @PathVariable int more) {
return paymentService.aliCheckOrderStatus(tradno, more);
}
@RequestMapping(path = "/0xalipay/{amount}", method = RequestMethod.GET)
......
......@@ -12,9 +12,9 @@ public interface PaymentService {
String wechatPayCallback(String tradno);
UserPaymentDto wxCheckOrderStatus(String tradno);
UserPaymentDto wxCheckOrderStatus(String tradno, int more);
UserPaymentDto aliCheckOrderStatus(String tradno);
UserPaymentDto aliCheckOrderStatus(String tradno, int more);
void alipaCallback(String tradno);
......
......@@ -34,9 +34,9 @@ public class SmsUtils {
request.setDomain("dysmsapi.aliyuncs.com");
request.setVersion("2017-05-25");
request.setAction("SendSms");
request.putQueryParameter("SignName", "深圳云端CLOUDAM");
request.putQueryParameter("SignName", "防关联浏览器");
request.putQueryParameter("PhoneNumbers", phone);
request.putQueryParameter("TemplateCode", "SMS_163437667");
request.putQueryParameter("TemplateCode", "SMS_185841618");
request.putQueryParameter("TemplateParam", "{\"code\":\""+randomCode+"\"}");
try {
CommonResponse response = client.getCommonResponse(request);
......
......@@ -56,7 +56,7 @@ public class PaymentServiceImpl implements PaymentService {
UserPayment byTradeNo = userPaymentRepository.findByTradeNo(tradno);
if (byTradeNo != null && !byTradeNo.isSucceed()) {
wxCheckOrderStatus(byTradeNo.getTradeNo());
wxCheckOrderStatus(byTradeNo.getTradeNo(), 0);
}
return "<xml>\n" +
"\n" +
......@@ -70,12 +70,12 @@ public class PaymentServiceImpl implements PaymentService {
UserPayment byTradeNo = userPaymentRepository.findByTradeNo(tradno);
if (byTradeNo != null && !byTradeNo.isSucceed()) {
aliCheckOrderStatus(byTradeNo.getTradeNo());
aliCheckOrderStatus(byTradeNo.getTradeNo(), 0);
}
}
@Override
public UserPaymentDto wxCheckOrderStatus(String tradeno) {
public UserPaymentDto wxCheckOrderStatus(String tradeno, int more) {
UserPaymentDto result = new UserPaymentDto();
result.setPaid(false);
......@@ -84,7 +84,7 @@ public class PaymentServiceImpl implements PaymentService {
UserPayment byTradeNo = userPaymentRepository.findByTradeNo(tradeno);
if (PaymentMethod.ALIPAY.equals(byTradeNo.getPaymentMethod()))
return aliCheckOrderStatus(tradeno);
return aliCheckOrderStatus(tradeno, more);
UserBalance balance = userBalanceRepository.findById(byTradeNo.getUsername()).orElse(null);
......@@ -169,7 +169,7 @@ public class PaymentServiceImpl implements PaymentService {
userPrePaidBillingRepository.save(bill);
balance.setBalanced(balance.getBalanced() + byTradeNo.getAmount());
balance.setBalanced(balance.getBalanced() + byTradeNo.getAmount() + more);
userBalanceRepository.save(balance);
}
......@@ -201,7 +201,7 @@ public class PaymentServiceImpl implements PaymentService {
}
@Override
public UserPaymentDto aliCheckOrderStatus(String tradno) {
public UserPaymentDto aliCheckOrderStatus(String tradno, int more) {
UserPaymentDto result = new UserPaymentDto();
result.setPaid(false);
try {
......@@ -271,7 +271,19 @@ public class PaymentServiceImpl implements PaymentService {
bill.setYear(year);
bill.setMonth(monthValue);
balance.setBalanced(balance.getBalanced() + byTradeNo.getAmount());
if (more != 20 || more != 45 || more != 125 || more != 300)
more = 0;
if ((more == 20 && byTradeNo.getAmount() != 100) || (more != 20 && byTradeNo.getAmount() == 100))
more = 0;
if ((more == 45 && byTradeNo.getAmount() != 200) || (more != 45 && byTradeNo.getAmount() == 200))
more = 0;
if ((more == 125 && byTradeNo.getAmount() != 500) || (more != 125 && byTradeNo.getAmount() == 500))
more = 0;
if ((more == 300 && byTradeNo.getAmount() != 1000) || (more != 300 && byTradeNo.getAmount() == 1000))
more = 0;
balance.setBalanced(balance.getBalanced() + byTradeNo.getAmount() + more);
userBalanceRepository.save(balance);
}
......
......@@ -26,6 +26,8 @@ public abstract class AlipayConfig {
public static String RETURN_URL_ORDER = "https://www.cloudam.cn/v2/console/orderDetail?alipayreturn=";
public static String RETURN_URL_BROWSER = "https://www.fangguanlian.cn/home/paySuccess.html?alipayreturn=";
public abstract String getSIGN_TYPE();
......
......@@ -74,6 +74,8 @@ public class VpsAlipayConfig extends AlipayConfig{
return RETURN_URL_VPS_FRONT; // vps购买
case "2":
return RETURN_URL_CVM; // 云主机购买
case "10":
return RETURN_URL_BROWSER;
}
}
......
......@@ -32,7 +32,7 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
public void configure(WebSecurity web) throws Exception {
web.ignoring()
.antMatchers( "/user/authCode", "/user/signUp",
.antMatchers( "/user/authCode", "/user/signUp", "/shop/multiadd",
"/user/reset*");
}
......
package com.edgec.browserbackend.browser.controller;
import com.edgec.browserbackend.account.dto.ResultDto;
import com.edgec.browserbackend.browser.ErrorCode.BrowserErrorCode;
import com.edgec.browserbackend.browser.domain.Shop;
import com.edgec.browserbackend.browser.dto.ShopPageResultDto;
import com.edgec.browserbackend.browser.dto.ShopResultDto;
......@@ -8,13 +9,14 @@ import com.edgec.browserbackend.browser.dto.ShopRequestDto;
import com.edgec.browserbackend.browser.dto.ShopStringResultDto;
import com.edgec.browserbackend.browser.service.ShopService;
import com.edgec.browserbackend.common.commons.error.ClientRequestException;
import com.edgec.browserbackend.common.utils.FileUtil;
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 org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.security.Principal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
......@@ -45,8 +47,30 @@ public class ShopController {
}
@RequestMapping(value = "/multiadd", method = RequestMethod.POST)
public List<String> addShops(Principal principal, @RequestBody List<Shop> shops) {
@ResponseBody
public List<String> addShops(Principal principal, @RequestParam("file") MultipartFile file) {
ResultDto resultDto = new ResultDto();
String name = file.getOriginalFilename();
if(name.length()<6 || !name.substring(name.length()-5).equals(".xlsx")){
resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", BrowserErrorCode.INFORMATIONNOTCOMPELETE.getCode());
statusInfo.put("message", "文件格式错误");
resultDto.setStatusInfo(statusInfo);
}
try {
shopService.addShops(principal.getName(), file);
} catch (ClientRequestException | IOException e) {
resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", 40102);
statusInfo.put("message", e.getMessage());
resultDto.setStatusInfo(statusInfo);
}
return null;
}
@RequestMapping(value = "/update", method = RequestMethod.POST)
......
......@@ -23,6 +23,9 @@ import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.couchbase.CouchbaseProperties;
import org.springframework.core.env.Environment;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
......@@ -55,6 +58,9 @@ public class IpResourceServiceImpl implements IpResourceService {
private static String startscript = "";
@Value("${spring.profiles.active}")
private String profiles;
@Autowired
private AccountRepository accountRepository;
......@@ -79,24 +85,65 @@ public class IpResourceServiceImpl implements IpResourceService {
public HttpHeaders buildPostHeader() {
HttpHeaders header = new HttpHeaders();
header.setContentType(MediaType.APPLICATION_JSON);
header.setBearerAuth("oq5tg3gMsflHcK5iZ2741G5R30XYd9blyOqH9qeBItKtrzfTsGIoy8AsxqqNXdcm");
if (profiles.equals("dev"))
header.setBearerAuth("oq5tg3gMsflHcK5iZ2741G5R30XYd9blyOqH9qeBItKtrzfTsGIoy8AsxqqNXdcm");
else if (profiles.equals("prod"))
header.setBearerAuth("tKWsuHzcngf0RQPMss70f9jgymDIwgQ9zbLfESJdcou3pZSNWl7lNTzto8VQgwaO");
return header;
}
public HttpHeaders buildGetHeader() {
HttpHeaders headers = new HttpHeaders();
headers.setBearerAuth("oq5tg3gMsflHcK5iZ2741G5R30XYd9blyOqH9qeBItKtrzfTsGIoy8AsxqqNXdcm");
if (profiles.equals("dev"))
headers.setBearerAuth("oq5tg3gMsflHcK5iZ2741G5R30XYd9blyOqH9qeBItKtrzfTsGIoy8AsxqqNXdcm");
else if (profiles.equals("prod"))
headers.setBearerAuth("tKWsuHzcngf0RQPMss70f9jgymDIwgQ9zbLfESJdcou3pZSNWl7lNTzto8VQgwaO");
return headers;
}
public static String makeRandomPassword(int len){
char charr[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890".toCharArray();
StringBuilder sb = new StringBuilder();
Random r = new Random();
for (int x = 0; x < len; ++x) {
sb.append(charr[r.nextInt(charr.length)]);
public static String genRandom(int srcFlag, int length) {
String retStr = "";
String strTable = "";
switch (srcFlag) {
case 1:
strTable = "1234567890";
break;
case 2:
strTable = "1234567890abcdefghijklmnopqrstuvwxyz";
break;
case 3:
strTable = "12345678901234567890abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
break;
case 4:
strTable = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
break;
case 5:
strTable = "abcdefghijklmnopqrstuvwxyz";
break;
default:
strTable = "1234567890abcdefghijkmnpqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
break;
}
return sb.toString();
int len = strTable.length();
boolean bDone = true;
do {
retStr = "";
int count = 0;
for (int i = 0; i < length; i++) {
double dblR = Math.random() * len;
int intR = (int) Math.floor(dblR);
char c = strTable.charAt(intR);
if (('0' <= c) && (c <= '9')) {
count++;
}
retStr += strTable.charAt(intR);
}
if (count >= 2) {
bDone = false;
}
} while (bDone);
return retStr;
}
private IpChargeRequestDto buildIpChargeRequestDto(IpResourceRequestDto request, int chargeType) {
......@@ -112,6 +159,7 @@ public class IpResourceServiceImpl implements IpResourceService {
@Override
public List<IpResourceDto> buyIp(String username, IpResourceRequestDto ipResourceRequestDto) throws Exception {
String URL = (profiles.equals("dev") || profiles.equals("staging"))? TESTURL : CLOUDAMURL;
Account account = accountRepository.findByName(username);
if (account == null)
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
......@@ -137,6 +185,10 @@ public class IpResourceServiceImpl implements IpResourceService {
HashMap<String, Object> map = new HashMap<>();
map.put("name", ipResourceRequestDto.getName());
map.put("region", ipResourceRequestDto.getRegion());
if (ipResourceRequestDto.getUnit().equals("month") && ipResourceRequestDto.getPeriod() == 6)
ipResourceRequestDto.setPeriod(7);
else if (ipResourceRequestDto.getUnit().equals("month") && ipResourceRequestDto.getPeriod() == 12)
ipResourceRequestDto.setPeriod(14);
map.put("period", String.valueOf(ipResourceRequestDto.getPeriod()));
map.put("provider", ipResourceRequestDto.getVendor());
map.put("unit", ipResourceRequestDto.getUnit());
......@@ -145,14 +197,14 @@ public class IpResourceServiceImpl implements IpResourceService {
if (StringUtils.isNotBlank(ipResourceRequestDto.getPassword()))
password = ipResourceRequestDto.getPassword();
else
password = makeRandomPassword(16);
password = genRandom(3, 12);
map.put("loginPassword", password);
map.put("startscript", startscript);
map.put("ipkeptperiod", ipResourceRequestDto.getIpkeptperiod());
HttpEntity<Map<String, Object>> httpEntity = new HttpEntity<>(map, header);
IpBuyResultDto ipBuyResultDto = null;
try {
ipBuyResultDto = restTemplate.postForObject(TESTURL + "/intelligroup/ipresources?accountId=browser", httpEntity, IpBuyResultDto.class);
ipBuyResultDto = restTemplate.postForObject(URL + "/intelligroup/ipresources?accountId=browser", httpEntity, IpBuyResultDto.class);
if (StringUtils.isNotBlank(ipBuyResultDto.getErrorCode()))
throw new Exception(ipBuyResultDto.getErrorCode());
} catch (Throwable e) {
......@@ -209,6 +261,7 @@ public class IpResourceServiceImpl implements IpResourceService {
@Override
public IpOperationResultDto renewIp(String username, IpResourceRequestDto ipResourceRequestDto) {
String URL = (profiles.equals("dev") || profiles.equals("staging"))? TESTURL : CLOUDAMURL;
Account account = accountRepository.findByName(username);
if (account == null)
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
......@@ -229,10 +282,14 @@ public class IpResourceServiceImpl implements IpResourceService {
RestTemplate restTemplate = new RestTemplate();
HashMap<String, Object> map = new HashMap<>();
map.put("iplist", ipResourceRequestDto.getAddr());
if (ipResourceRequestDto.getUnit().equals("month") && ipResourceRequestDto.getPeriod() == 6)
ipResourceRequestDto.setPeriod(7);
else if (ipResourceRequestDto.getUnit().equals("month") && ipResourceRequestDto.getPeriod() == 12)
ipResourceRequestDto.setPeriod(14);
map.put("period", ipResourceRequestDto.getPeriod());
HttpHeaders headers = buildPostHeader();
HttpEntity<Map<String, Object>> entity = new HttpEntity<>(map, headers);
ResponseEntity<String> result = restTemplate.exchange(TESTURL + "/intelligroup/renewip?accountId=browser", HttpMethod.PUT, entity, String.class);
ResponseEntity<String> result = restTemplate.exchange(URL + "/intelligroup/renewip?accountId=browser", HttpMethod.PUT, entity, String.class);
RenewIpResultDto renewIpResultDto = JSON.parseObject(result.getBody(), RenewIpResultDto.class);
if (StringUtils.isNotBlank(renewIpResultDto.getErrorCode())) {
logger.error(renewIpResultDto.getErrorCode());
......@@ -264,6 +321,7 @@ public class IpResourceServiceImpl implements IpResourceService {
@Override
public IpOperationResultDto deleteIp(String username, List<String> ipAddrs) {
String URL = (profiles.equals("dev") || profiles.equals("staging"))? TESTURL : CLOUDAMURL;
Account account = accountRepository.findByName(username);
if (account == null)
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
......@@ -290,7 +348,7 @@ public class IpResourceServiceImpl implements IpResourceService {
Map<String, String> params = new HashMap<String, String>();
HttpEntity<Map<String, String>> httpEntity = new HttpEntity<>(params, headers);
try {
ResponseEntity<String> result = restTemplate.exchange(TESTURL + "/intelligroup/ipresources?accountId=browser&ip={ip}", HttpMethod.DELETE, httpEntity, String.class, ipAddr);
ResponseEntity<String> result = restTemplate.exchange(URL + "/intelligroup/ipresources?accountId=browser&ip={ip}", HttpMethod.DELETE, httpEntity, String.class, ipAddr);
DeleteIpResultDto deleteIpResultDto = JSON.parseObject(result.getBody(), DeleteIpResultDto.class);
if (StringUtils.isNotBlank(deleteIpResultDto.getErrorCode()))
throw new Exception(deleteIpResultDto.getErrorCode());
......
......@@ -6,17 +6,16 @@ import com.edgec.browserbackend.account.exception.AccountErrorCode;
import com.edgec.browserbackend.account.repository.AccountRepository;
import com.edgec.browserbackend.browser.ErrorCode.BrowserErrorCode;
import com.edgec.browserbackend.browser.domain.*;
import com.edgec.browserbackend.browser.dto.ShopFilterDto;
import com.edgec.browserbackend.browser.dto.ShopResultDto;
import com.edgec.browserbackend.browser.dto.PageInfo;
import com.edgec.browserbackend.browser.dto.ShopPageResultDto;
import com.edgec.browserbackend.browser.dto.*;
import com.edgec.browserbackend.browser.repository.GroupRepository;
import com.edgec.browserbackend.browser.repository.IpResourceRepository;
import com.edgec.browserbackend.browser.repository.ShopRepository;
import com.edgec.browserbackend.browser.repository.UserShopRepository;
import com.edgec.browserbackend.browser.service.ShopService;
import com.edgec.browserbackend.common.commons.error.ClientRequestException;
import com.edgec.browserbackend.common.utils.FileUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.Workbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -26,7 +25,9 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
......@@ -96,8 +97,61 @@ public class ShopServiceImpl implements ShopService {
}
@Override
public List<String> addShops(String username, List<Shop> shops) {
return null;
public List<String> addShops(String username, MultipartFile file) throws IOException {
List<String> ids = new ArrayList<>();
List<List<Object>> list = FileUtil.readExcel(file.getInputStream());
Account account = accountRepository.findByName(username);
if (account == null) {
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
}
if (account.getPermission() < 4) {
throw new ClientRequestException(AccountErrorCode.NOPERMISSION);
}
if (account.getShopCount() >= 10000) {
throw new ClientRequestException(AccountErrorCode.SHOPMAX);
}
for (List<Object> l : list) {
ShopResultDto shopResultDto = new ShopResultDto();
shopResultDto.setOwner(username);
shopResultDto.setShopName(l.get(0).toString());
shopResultDto.setShopPlatform(l.get(1).toString());
shopResultDto.setGroup("-1");
if (StringUtils.isNotBlank(l.get(2).toString()))
shopResultDto.setShopAccount(l.get(2).toString());
if (StringUtils.isNotBlank(l.get(3).toString()))
shopResultDto.setShopPassword(l.get(3).toString());
String id = null;
UserShop us = null;
if (shopResultDto.getShopId() != null)
us = userShopRepository.findByUsernameAndShopId(username, shopResultDto.getShopId());
if (shopResultDto.getGroup() == null)
throw new ClientRequestException(BrowserErrorCode.INFORMATIONNOTCOMPELETE);
Group group = groupRepository.findById(shopResultDto.getGroup()).orElse(null);
if (group == null) {
throw new ClientRequestException(BrowserErrorCode.GROUPNOTEXIST);
}
try {
shopResultDto.setOwner(username);
Shop shop = new Shop();
shop.of(shopResultDto);
id = shopRepository.save(shop).getShopId();
UserShop userShop = new UserShop();
userShop.setUsername(username);
userShop.setShopId(id);
if (shopResultDto.getGroup() != null && us == null) {
userShop.setGroupId(shopResultDto.getGroup());
}
userShopRepository.save(userShop);
//可以优化
account.setShopCount(account.getShopCount() + 1);
accountRepository.save(account);
ids.add(id);
}catch (Exception e) {
logger.error("fail to add shops", e.getMessage());
throw new ClientRequestException(BrowserErrorCode.INFORMATIONNOTCOMPELETE);
}
}
return ids;
}
@Override
......@@ -234,7 +288,7 @@ public class ShopServiceImpl implements ShopService {
}
UserShop userShop = userShopRepository.findByUsernameAndShopId(username, shopId);
Group group = groupRepository.findById(groupId).orElse(null);
if (account.getPermission() < 4 || userShop == null || !group.getOwner().equals(username)) {
if (userShop == null || (!group.getId().equals("-1") && group.getOwner() != null && !group.getOwner().equals(username))) {
throw new ClientRequestException(AccountErrorCode.NOPERMISSION);
}
Shop shop = shopRepository.findById(shopId).orElse(null);
......
......@@ -5,14 +5,16 @@ import com.edgec.browserbackend.browser.domain.ShopSummary;
import com.edgec.browserbackend.browser.dto.ShopFilterDto;
import com.edgec.browserbackend.browser.dto.ShopPageResultDto;
import com.edgec.browserbackend.browser.dto.ShopResultDto;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.List;
public interface ShopService {
String addShop(String useranme, ShopResultDto shopResultDto);
List<String> addShops(String username, List<Shop> shops);
List<String> addShops(String username, MultipartFile file) throws IOException;
String updateShop(String username, ShopResultDto shopResultDto);
......
......@@ -56,8 +56,10 @@ public class ExpireSoonWarn {
JSONObject param = new JSONObject();
param.put("day", day);
param.put("amount", amount);
param.put("ips", ips);
SmsUtils.sendIpSms(account.getPhoneNumber(), SmsUtils.SmsTemplateCode.VPS_EXPIRE, param);
if (day == 0)
SmsUtils.sendIpSms(account.getPhoneNumber(), SmsUtils.SmsTemplateCode.IPEXPIRED, param);
else
SmsUtils.sendIpSms(account.getPhoneNumber(), SmsUtils.SmsTemplateCode.IPWILLEXPIRE_EXPIRE, param);
}
}
......@@ -24,10 +24,10 @@ public class SmsUtils {
public enum SmsTemplateCode {
VPS_INVITE("SMS_171856442"),
VPS_EXPIRE("SMS_173341111"),
CLOUDAM_ARREARS("SMS_174805285"),
CVM_EXPIRE("SMS_175572297"),
AUTHCODE("SMS_185841618"),
IPWILLEXPIRE_EXPIRE("SMS_185821567"),
IPEXPIRED("SMS_185841667"),
;
......@@ -99,7 +99,7 @@ public class SmsUtils {
request.setVersion("2017-05-25");
request.setAction("SendSms");
request.putQueryParameter("PhoneNumbers", phoneNum);
request.putQueryParameter("SignName", "防关联VPS");
request.putQueryParameter("SignName", "防关联浏览器");
request.putQueryParameter("TemplateCode", smsTemplateCode.getCode());
request.putQueryParameter("TemplateParam", param.toJSONString());
try {
......@@ -114,7 +114,7 @@ public class SmsUtils {
}
}
public static void sendCloadamSms(String phoneNum, SmsTemplateCode smsTemplateCode, JSONObject param) {
public static void sendWillExipreSms(String phoneNum, SmsTemplateCode smsTemplateCode, JSONObject param) {
CommonRequest request = new CommonRequest();
//request.setProtocol(ProtocolType.HTTPS);
request.setMethod(MethodType.POST);
......
package com.edgec.browserbackend.common.utils;
import com.edgec.browserbackend.browser.ErrorCode.BrowserErrorCode;
import com.edgec.browserbackend.common.commons.error.ClientRequestException;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -61,4 +67,86 @@ public class FileUtil {
log.debug("[" + file.getName() + "]文件写入成功");
return true;
}
//读取excel
public static List<List<Object>> readExcel(InputStream inputStream){
List<List<Object>> list = new ArrayList<>();
Workbook workbook = null;
try {
workbook = WorkbookFactory.create(inputStream);
inputStream.close();
//工作表对象
Sheet sheet = workbook.getSheetAt(0);
//总行数
int rowLength = sheet.getLastRowNum() -1;
//工作表的列
Row row = sheet.getRow(0);
//总列数
int colLength = row.getLastCellNum();
//得到指定的单元格
Cell cell = row.getCell(0);;
int size = 1;
for (int i = 2; i < rowLength; i++) {
row = sheet.getRow(i);
List<Object> rowvalue = new ArrayList<>();
size = 0;
for (int j = 0; j < colLength; j++) {
cell = row.getCell(j);
// System.out.println(cell);
if (cell!=null) {
Object cellValue = getCellFormatValue(cell);
rowvalue.add(cellValue);
if (StringUtils.isNotBlank(cellValue.toString())) {
size++;
}
}
}
if (size == 0)
break;
if (StringUtils.isBlank(rowvalue.get(0).toString()) || StringUtils.isBlank(rowvalue.get(1).toString()))
throw new ClientRequestException(BrowserErrorCode.INFORMATIONNOTCOMPELETE);
list.add(rowvalue);
}
} catch (Exception e) {
log.error("parse excel file error :", e);
throw new ClientRequestException(BrowserErrorCode.INFORMATIONNOTCOMPELETE);
}
return list ;
}
public static Object getCellFormatValue(Cell cell){
Object cellValue = null;
if(cell!=null){
//判断cell类型
switch(cell.getCellType()){
case Cell.CELL_TYPE_NUMERIC:{
cellValue = String.valueOf((int)cell.getNumericCellValue());
break;
}
case Cell.CELL_TYPE_FORMULA:{
//判断cell是否为日期格式
if(DateUtil.isCellDateFormatted(cell)){
//转换为日期格式YYYY-mm-dd
cellValue = cell.getDateCellValue();
}else{
//数字
cellValue = String.valueOf(cell.getNumericCellValue());
}
break;
}
case Cell.CELL_TYPE_STRING:{
cellValue = cell.getRichStringCellValue().getString();
break;
}
default:
cellValue = "";
}
}else{
cellValue = "";
}
return cellValue;
}
}
......@@ -25,6 +25,12 @@ spring:
enable: true
resources:
static-locations: classpath:/META-INF/resources/,classpath:/resources/,classpath:/static/,classpath:/public/
http:
servlet:
multipart:
max-file-size: 50MB
max-request-size: 50MB
security:
......
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>成功页面。。。</h1>
<form action="/shop/multiadd" method="post" enctype="multipart/form-data">
<p>文件上传</p>
<input type="file" name="file">
<p><input type="submit" value="提交"></p>
</form>
</body>
</html>
\ 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