Commit 20a0c831 authored by huangjiamin's avatar huangjiamin

【Shop模块】处理UA BUG:选择UA后依然出现随机UA的BUG,并重构addShop部分代码

parent df6eef1c
......@@ -2,7 +2,6 @@ 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.ShopPageResultDto;
import com.edgec.browserbackend.browser.dto.ShopRequestDto;
import com.edgec.browserbackend.browser.dto.ShopResultDto;
......@@ -10,74 +9,83 @@ 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;
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 org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.security.Principal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
/**
* 商铺操作
*/
@RequestMapping("/shop")
@RestController
public class ShopController {
private final Logger log = LoggerFactory.getLogger(ShopController.class);
private ShopService shopService;
private IpAndShopService ipAndShopService;
@Autowired
private ShopService shopService;
public void setShopService(ShopService shopService) {
this.shopService = shopService;
}
@Autowired
private IpAndShopService ipAndShopService;
public void setIpAndShopService(IpAndShopService ipAndShopService) {
this.ipAndShopService = ipAndShopService;
}
private final Logger log = LoggerFactory.getLogger(ShopController.class);
/**
* 新增店铺操作
*
* @param principal principal
* @param shopResultDto shopResultDto
* @return resultDto
*/
@PostMapping("/add")
public ResultDto addShop(Principal principal, @RequestBody ShopResultDto shopResultDto) {
ResultDto resultDto = new ResultDto();
String logs = "【addShop】 ";
log.info("{}, params : {}", logs, principal.getName());
try {
ShopStringResultDto shopStringResultDto = new ShopStringResultDto();
shopStringResultDto.setId(shopService.addShop(principal.getName(), shopResultDto));
resultDto.setData(shopStringResultDto);
resultDto.setStatus(0);
return ResponseUtil.success(shopService.addShop(principal.getName(), shopResultDto));
} 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);
dealClientRequestException(resultDto, e);
return ResponseUtil.error(e.getMessage());
}
return resultDto;
}
/**
* 批量新增店铺
*
* @param principal principal
* @param file file
* @return resultDto
*/
@PostMapping("/multiadd")
public ResultDto addShops(Principal principal, @RequestParam("file") MultipartFile file) {
ResultDto resultDto = new ResultDto();
String logs = "【addShops】 ";
log.info("{}, params : {}", logs, principal.getName());
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);
resultDto.setStatus(0);
} catch (ClientRequestException | IOException e) {
return ResponseUtil.success(shopService.addShops(principal.getName(), file));
} 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);
resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", 40102);
statusInfo.put("message", e.getMessage());
resultDto.setStatusInfo(statusInfo);
return ResponseUtil.error(e.getMessage());
}
return resultDto;
}
@RequestMapping(value = "/update", method = RequestMethod.POST)
......
......@@ -10,10 +10,30 @@ import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.List;
/**
* 商铺操作
*
* @author JMW
*/
public interface ShopService {
String addShop(String useranme, ShopResultDto shopResultDto);
/**
* 新增店铺操作
*
* @param username username
* @param shopResultDto shopResultDto
* @return id
*/
String addShop(String username, ShopResultDto shopResultDto);
/**
* 批量新增店铺
*
* @param username username
* @param file file
* @return IDS
* @throws IOException IOException
*/
List<String> addShops(String username, MultipartFile file) throws IOException;
String updateShop(String username, ShopResultDto shopResultDto);
......
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