返回调整为ServerResponseEntity

This commit is contained in:
chendt 2023-03-13 10:04:30 +08:00
parent b99b6464fa
commit 59eea4169a
71 changed files with 970 additions and 733 deletions

View File

@ -92,12 +92,12 @@ public class FileController {
private AttachFileService attachFileService;
@PostMapping("/upload/element")
public ResponseEntity<String> uploadElementFile(@RequestParam("file") MultipartFile file) throws IOException{
public ServerResponseEntity<String> uploadElementFile(@RequestParam("file") MultipartFile file) throws IOException{
if(file.isEmpty()){
return ResponseEntity.noContent().build();
return ServerResponseEntity.success();
}
String fileName = attachFileService.uploadFile(file.getBytes(),file.getOriginalFilename());
return ResponseEntity.ok(fileName);
return ServerResponseEntity.success(fileName);
}

View File

@ -5,95 +5,160 @@
我们先来看下 `YamiShopBindException`的代码
```java
public class YamiShopBindException extends RuntimeException {
@Getter
public class YamiShopBindException extends RuntimeException{
/**
*
*/
private static final long serialVersionUID = -4137688758944857209L;
/**
* http状态码
*/
private Integer httpStatusCode;
private String code;
/**
* @param httpStatus http状态码
*/
public YamiShopBindException(YamiHttpStatus httpStatus) {
super(httpStatus.getMsg());
this.httpStatusCode = httpStatus.value();
private Object object;
private ServerResponseEntity<?> serverResponseEntity;
public YamiShopBindException(ResponseEnum responseEnum) {
super(responseEnum.getMsg());
this.code = responseEnum.value();
}
/**
* @param httpStatus http状态码
* @param responseEnum
*/
public YamiShopBindException(YamiHttpStatus httpStatus, String msg) {
public YamiShopBindException(ResponseEnum responseEnum, String msg) {
super(msg);
this.httpStatusCode = httpStatus.value();
this.code = responseEnum.value();
}
public YamiShopBindException(ServerResponseEntity<?> serverResponseEntity) {
this.serverResponseEntity = serverResponseEntity;
}
public YamiShopBindException(String msg) {
super(msg);
this.httpStatusCode = HttpStatus.BAD_REQUEST.value();
this.code = ResponseEnum.SHOW_FAIL.value();
}
public Integer getHttpStatusCode() {
return httpStatusCode;
public YamiShopBindException(String msg, Object object) {
super(msg);
this.code = ResponseEnum.SHOW_FAIL.value();
this.object = object;
}
}
```
`YamiHttpStatus`为我们自定义的返回状态码的枚举类,定义为一个枚举类,更直观处理异常返回的状态码及异常内容,以后每增加一种异常情况,只需增加一个枚举实例即可,不用每一种异常都定义一个异常类。
`ResponseEnum`为我们自定义的返回状态码的枚举类,定义为一个枚举类,更直观处理异常返回的状态码及异常内容,以后每增加一种异常情况,只需增加一个枚举实例即可,不用每一种异常都定义一个异常类。
```java
public enum YamiHttpStatus {
public enum ResponseEnum {
/**
* 客户端看到401状态码时应该重新登陆
* ok
*/
UNAUTHORIZED(401, "未授权"),
OK("00000", "ok"),
SHOW_FAIL("A00001", ""),
COUPONCANNOTUSETOGETHER(601, "优惠券不能共用"),
;
/**
* 用于直接显示提示用户的错误,内容由输入内容决定
*/
private final int value;
/**
* 用于直接显示提示系统的成功,内容由输入内容决定
*/
SHOW_SUCCESS("A00002", ""),
/**
* 未授权
*/
UNAUTHORIZED("A00004", "Unauthorized"),
/**
* 服务器出了点小差
*/
EXCEPTION("A00005", "服务器出了点小差"),
/**
* 方法参数没有校验,内容由输入内容决定
*/
METHOD_ARGUMENT_NOT_VALID("A00014", "方法参数没有校验");
private final String code;
private final String msg;
YamiHttpStatus(int value, String msg) {
this.value = value;
this.msg = msg;
}
public int value() {
return this.value;
public String value() {
return code;
}
public String getMsg() {
return msg;
}
public static YamiHttpStatus resolve(int statusCode) {
for (YamiHttpStatus status : values()) {
if (status.value == statusCode) {
return status;
}
}
return null;
ResponseEnum(String code, String msg) {
this.code = code;
this.msg = msg;
}
@Override
public String toString() {
return "ResponseEnum{" + "code='" + code + '\'' + ", msg='" + msg + '\'' + "} " + super.toString();
}
}
```
再来看看 `DefaultExceptionHandlerConfig`
```java
@Controller
@Slf4j
@RestController
@RestControllerAdvice
public class DefaultExceptionHandlerConfig {
@ExceptionHandler({ MethodArgumentNotValidException.class, BindException.class })
public ResponseEntity<ServerResponseEntity<List<String>>> methodArgumentNotValidExceptionHandler(Exception e) {
log.error("methodArgumentNotValidExceptionHandler", e);
List<FieldError> fieldErrors = null;
if (e instanceof MethodArgumentNotValidException) {
fieldErrors = ((MethodArgumentNotValidException) e).getBindingResult().getFieldErrors();
}
if (e instanceof BindException) {
fieldErrors = ((BindException) e).getBindingResult().getFieldErrors();
}
if (fieldErrors == null) {
return ResponseEntity.status(HttpStatus.OK)
.body(ServerResponseEntity.fail(ResponseEnum.METHOD_ARGUMENT_NOT_VALID));
}
List<String> defaultMessages = new ArrayList<>(fieldErrors.size());
for (FieldError fieldError : fieldErrors) {
defaultMessages.add(fieldError.getField() + ":" + fieldError.getDefaultMessage());
}
return ResponseEntity.status(HttpStatus.OK)
.body(ServerResponseEntity.fail(ResponseEnum.METHOD_ARGUMENT_NOT_VALID, defaultMessages));
}
@ExceptionHandler(YamiShopBindException.class)
public ResponseEntity<String> unauthorizedExceptionHandler(YamiShopBindException e){
e.printStackTrace();
return ResponseEntity.status(e.getHttpStatusCode()).body(e.getMessage());
public ResponseEntity<ServerResponseEntity<?>> unauthorizedExceptionHandler(YamiShopBindException e){
log.error("mall4jExceptionHandler", e);
ServerResponseEntity<?> serverResponseEntity = e.getServerResponseEntity();
if (serverResponseEntity!=null) {
return ResponseEntity.status(HttpStatus.OK).body(serverResponseEntity);
}
// 失败返回消息 状态码固定为直接显示消息的状态码
return ResponseEntity.status(HttpStatus.OK).body(ServerResponseEntity.fail(e.getCode(),e.getMessage()));
}
@ExceptionHandler(Exception.class)
public ResponseEntity<ServerResponseEntity<Object>> exceptionHandler(Exception e){
log.error("exceptionHandler", e);
return ResponseEntity.status(HttpStatus.OK).body(ServerResponseEntity.fail(ResponseEnum.EXCEPTION));
}
}
```

View File

@ -80,9 +80,9 @@ public class SysLogAspect {
@SysLog("修改角色")
@PutMapping
@PreAuthorize("@pms.hasPermission('sys:role:update')")
public ResponseEntity<Void> update(@RequestBody SysRole role){
public ServerResponseEntity<Void> update(@RequestBody SysRole role){
sysRoleService.updateRoleAndRoleMenu(role);
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
```

View File

@ -98,17 +98,17 @@ public class SysUserController {
@SysLog("保存用户")
@PostMapping
@PreAuthorize("@pms.hasPermission('sys:user:save')")
public ResponseEntity<String> save(@Valid @RequestBody SysUser user){
public ServerResponseEntity<String> save(@Valid @RequestBody SysUser user){
String username = user.getUsername();
SysUser dbUser = sysUserService.getOne(new LambdaQueryWrapper<SysUser>()
.eq(SysUser::getUsername, username));
if (dbUser!=null) {
return ResponseEntity.badRequest().body("该用户已存在");
return ServerResponseEntity.showFailMsg("该用户已存在");
}
user.setShopId(SecurityUtils.getSysUser().getShopId());
user.setPassword(passwordEncoder.encode(user.getPassword()));
sysUserService.saveUserAndUserRole(user);
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
}
```
@ -118,19 +118,19 @@ public class SysUserController {
并且在`DefaultExceptionHandlerConfig` 拦截由`@Valid` 触发的异常信息并返回:
```java
@Controller
@RestController
@RestControllerAdvice
public class DefaultExceptionHandlerConfig {
@ExceptionHandler(BindException.class)
public ResponseEntity<String> bindExceptionHandler(BindException e){
public ServerResponseEntity<String> bindExceptionHandler(BindException e){
e.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getBindingResult().getFieldErrors().get(0).getDefaultMessage());
}
@ExceptionHandler(MethodArgumentNotValidException.class)
public ResponseEntity<String> methodArgumentNotValidExceptionHandler(MethodArgumentNotValidException e){
public ServerResponseEntity<String> methodArgumentNotValidExceptionHandler(MethodArgumentNotValidException e){
e.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getBindingResult().getFieldErrors().get(0).getDefaultMessage());
}

View File

@ -143,12 +143,12 @@ public class SysUserController {
*/
@GetMapping("/page")
@PreAuthorize("@pms.hasPermission('sys:user:page')")
public ResponseEntity<IPage<SysUser>> page(String username,PageParam<SysUser> page){
public ServerResponseEntity<IPage<SysUser>> page(String username,PageParam<SysUser> page){
IPage<SysUser> sysUserPage = sysUserService.page(page, new LambdaQueryWrapper<SysUser>()
.eq(SysUser::getShopId, SecurityUtils.getSysUser().getShopId())
.like(StrUtil.isNotBlank(username), SysUser::getUsername, username));
return ResponseEntity.ok(sysUserPage);
return ServerResponseEntity.success(sysUserPage);
}
}
```

View File

@ -16,7 +16,7 @@
```java
@PostMapping("/info")
@Operation(summary = "获取用户购物车信息" , description = "获取用户购物车信息,参数为用户选中的活动项数组,以购物车id为key")
public ResponseEntity<List<ShopCartDto>> info(@RequestBody Map<Long, ShopCartParam> basketIdShopCartParamMap) {
public ServerResponseEntity<List<ShopCartDto>> info(@RequestBody Map<Long, ShopCartParam> basketIdShopCartParamMap) {
String userId = SecurityUtils.getUser().getUserId();
// 更新购物车信息,
@ -26,7 +26,7 @@
// 拿到购物车的所有item
List<ShopCartItemDto> shopCartItems = basketService.getShopCartItems(userId);
return ResponseEntity.ok(basketService.getShopCarts(shopCartItems));
return ServerResponseEntity.success(basketService.getShopCarts(shopCartItems));
}
```
@ -41,7 +41,7 @@
我们现在看看购物车返回的数据`ResponseEntity<List<ShopCartDto>>`,我们清楚一个购物车是分多个店铺的,每一个店铺就是一个`ShopCartDto`,我们看下这个`bean`
我们现在看看购物车返回的数据`ServerResponseEntity<List<ShopCartDto>>`,我们清楚一个购物车是分多个店铺的,每一个店铺就是一个`ShopCartDto`,我们看下这个`bean`
```java
@Data

View File

@ -39,7 +39,7 @@ public class OrderParam {
```java
@PostMapping("/confirm")
@Operation(summary = "结算,生成订单信息" , description = "传入下单所需要的参数进行下单")
public ResponseEntity<ShopCartOrderMergerDto> confirm(@Valid @RequestBody OrderParam orderParam) {
public ServerResponseEntity<ShopCartOrderMergerDto> confirm(@Valid @RequestBody OrderParam orderParam) {
// 根据店铺组装购车中的商品信息,返回每个店铺中的购物车商品信息
List<ShopCartDto> shopCarts = basketService.getShopCarts(shopCartItems);
}
@ -82,7 +82,7 @@ public class OrderParam {
```java
@PostMapping("/confirm")
@Operation(summary = "结算,生成订单信息" , description = "传入下单所需要的参数进行下单")
public ResponseEntity<ShopCartOrderMergerDto> confirm(@Valid @RequestBody OrderParam orderParam) {
public ServerResponseEntity<ShopCartOrderMergerDto> confirm(@Valid @RequestBody OrderParam orderParam) {
for (ShopCartDto shopCart : shopCarts) {
applicationContext.publishEvent(new ConfirmOrderEvent(shopCartOrder,orderParam,shopAllShopCartItems));

View File

@ -10,7 +10,7 @@
```java
@Operation(summary = "结算,生成订单信息" , description = "传入下单所需要的参数进行下单")
public ResponseEntity<ShopCartOrderMergerDto> confirm(@Valid @RequestBody OrderParam orderParam) {
public ServerResponseEntity<ShopCartOrderMergerDto> confirm(@Valid @RequestBody OrderParam orderParam) {
orderService.putConfirmOrderCache(userId,shopCartOrderMergerDto);
}
```
@ -22,7 +22,7 @@
```java
@PostMapping("/submit")
@Operation(summary = "提交订单,返回支付流水号" , description = "根据传入的参数判断是否为购物车提交订单,同时对购物车进行删除,用户开始进行支付")
public ResponseEntity<OrderNumbersDto> submitOrders(@Valid @RequestBody SubmitOrderParam submitOrderParam) {
public ServerResponseEntity<OrderNumbersDto> submitOrders(@Valid @RequestBody SubmitOrderParam submitOrderParam) {
ShopCartOrderMergerDto mergerOrder = orderService.getConfirmOrderCache(userId);
if (mergerOrder == null) {
throw new YamiShopBindException("订单已过期,请重新下单");
@ -140,7 +140,7 @@ update tz_sku set stocks = stocks - #{sku.stocks}, version = version + 1,update_
最后我们回到`controller`
```java
return ResponseEntity.ok(new OrderNumbersDto(orderNumbers.toString()));
return ServerResponseEntity.success(new OrderNumbersDto(orderNumbers.toString()));
```
这里面返回了多个订单项,这里就变成了并单支付咯,在多个店铺一起进行支付的时候需要进行并单支付的操作,一个店铺的时候,又要变成一个订单支付的操作,可是我们只希望有一个统一支付的接口进行调用,所以我们的支付接口要进行一点点的设计咯。

View File

@ -233,7 +233,7 @@ ClientCredentialsTokenEndpointFilter.doFilter()
@FrameworkEndpoint
public class TokenEndpoint extends AbstractEndpoint{
@RequestMapping(value = "/oauth/token", method=RequestMethod.POST)
public ResponseEntity<OAuth2AccessToken> postAccessToken(Principal principal, @RequestParam
public ServerResponseEntity<OAuth2AccessToken> postAccessToken(Principal principal, @RequestParam
Map<String, String> parameters) throws HttpRequestMethodNotSupportedException {

View File

@ -28,8 +28,7 @@ public class SwaggerConfiguration {
public GroupedOpenApi baseRestApi() {
return GroupedOpenApi.builder()
.group("接口文档")
.packagesToScan("com.yami")
.build();
.packagesToScan("com.yami").build();
}

View File

@ -15,6 +15,7 @@ import com.anji.captcha.model.vo.CaptchaVO;
import com.anji.captcha.service.CaptchaService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.yami.shop.common.exception.YamiShopBindException;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.security.admin.dto.CaptchaAuthenticationDTO;
import com.yami.shop.security.common.bo.UserInfoInTokenBO;
import com.yami.shop.security.common.enums.SysTypeEnum;
@ -27,10 +28,10 @@ import com.yami.shop.sys.model.SysMenu;
import com.yami.shop.sys.model.SysUser;
import com.yami.shop.sys.service.SysMenuService;
import com.yami.shop.sys.service.SysUserService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
@ -70,14 +71,14 @@ public class AdminLoginController {
@PostMapping("/adminLogin")
@Operation(summary = "账号密码 + 验证码登录(用于后台登录)" , description = "通过账号/手机号/用户名密码登录")
public ResponseEntity<?> login(
public ServerResponseEntity<?> login(
@Valid @RequestBody CaptchaAuthenticationDTO captchaAuthenticationDTO) {
// 登陆后台登录需要再校验一遍验证码
CaptchaVO captchaVO = new CaptchaVO();
captchaVO.setCaptchaVerification(captchaAuthenticationDTO.getCaptchaVerification());
ResponseModel response = captchaService.verification(captchaVO);
if (!response.isSuccess()) {
return ResponseEntity.badRequest().body("验证码有误或已过期");
return ServerResponseEntity.showFailMsg("验证码有误或已过期");
}
SysUser sysUser = sysUserService.getByUserName(captchaAuthenticationDTO.getUserName());
@ -104,7 +105,7 @@ public class AdminLoginController {
userInfoInToken.setShopId(sysUser.getShopId());
// 存储token返回vo
TokenInfoVO tokenInfoVO = tokenStore.storeAndGetVo(userInfoInToken);
return ResponseEntity.ok(tokenInfoVO);
return ServerResponseEntity.success(tokenInfoVO);
}

View File

@ -18,7 +18,7 @@ import com.yami.shop.common.exception.YamiShopBindException;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
@ -41,9 +41,9 @@ public class AreaController {
*/
@GetMapping("/page")
@PreAuthorize("@pms.hasPermission('admin:area:page')")
public ResponseEntity<IPage<Area>> page(Area area,PageParam<Area> page) {
public ServerResponseEntity<IPage<Area>> page(Area area,PageParam<Area> page) {
IPage<Area> sysUserPage = areaService.page(page, new LambdaQueryWrapper<Area>());
return ResponseEntity.ok(sysUserPage);
return ServerResponseEntity.success(sysUserPage);
}
/**
@ -51,19 +51,19 @@ public class AreaController {
*/
@GetMapping("/list")
@PreAuthorize("@pms.hasPermission('admin:area:list')")
public ResponseEntity<List<Area>> list(Area area) {
public ServerResponseEntity<List<Area>> list(Area area) {
List<Area> areas = areaService.list(new LambdaQueryWrapper<Area>()
.like(area.getAreaName() != null, Area::getAreaName, area.getAreaName()));
return ResponseEntity.ok(areas);
return ServerResponseEntity.success(areas);
}
/**
* 通过父级id获取区域列表
*/
@GetMapping("/listByPid")
public ResponseEntity<List<Area>> listByPid(Long pid) {
public ServerResponseEntity<List<Area>> listByPid(Long pid) {
List<Area> list = areaService.listByPid(pid);
return ResponseEntity.ok(list);
return ServerResponseEntity.success(list);
}
/**
@ -71,9 +71,9 @@ public class AreaController {
*/
@GetMapping("/info/{id}")
@PreAuthorize("@pms.hasPermission('admin:area:info')")
public ResponseEntity<Area> info(@PathVariable("id") Long id) {
public ServerResponseEntity<Area> info(@PathVariable("id") Long id) {
Area area = areaService.getById(id);
return ResponseEntity.ok(area);
return ServerResponseEntity.success(area);
}
/**
@ -81,14 +81,14 @@ public class AreaController {
*/
@PostMapping
@PreAuthorize("@pms.hasPermission('admin:area:save')")
public ResponseEntity<Void> save(@Valid @RequestBody Area area) {
public ServerResponseEntity<Void> save(@Valid @RequestBody Area area) {
if (area.getParentId() != null) {
Area parentArea = areaService.getById(area.getParentId());
area.setLevel(parentArea.getLevel() + 1);
areaService.removeAreaCacheByParentId(area.getParentId());
}
areaService.save(area);
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
/**
@ -96,7 +96,7 @@ public class AreaController {
*/
@PutMapping
@PreAuthorize("@pms.hasPermission('admin:area:update')")
public ResponseEntity<Void> update(@Valid @RequestBody Area area) {
public ServerResponseEntity<Void> update(@Valid @RequestBody Area area) {
Area areaDb = areaService.getById(area.getAreaId());
// 判断当前省市区级别如果是1级2级则不能修改级别不能修改成别人的下级
if(Objects.equals(areaDb.getLevel(), AreaLevelEnum.FIRST_LEVEL.value()) && !Objects.equals(area.getLevel(),AreaLevelEnum.FIRST_LEVEL.value())){
@ -108,7 +108,7 @@ public class AreaController {
hasSameName(area);
areaService.updateById(area);
areaService.removeAreaCacheByParentId(area.getParentId());
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
/**
@ -116,11 +116,11 @@ public class AreaController {
*/
@DeleteMapping("/{id}")
@PreAuthorize("@pms.hasPermission('admin:area:delete')")
public ResponseEntity<Void> delete(@PathVariable Long id) {
public ServerResponseEntity<Void> delete(@PathVariable Long id) {
Area area = areaService.getById(id);
areaService.removeById(id);
areaService.removeAreaCacheByParentId(area.getParentId());
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
private void hasSameName(Area area) {

View File

@ -18,7 +18,7 @@ import com.yami.shop.common.util.PageParam;
import com.yami.shop.security.admin.util.SecurityUtils;
import com.yami.shop.service.ProdPropService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
@ -41,11 +41,11 @@ public class AttributeController {
*/
@GetMapping("/page")
@PreAuthorize("@pms.hasPermission('admin:attribute:page')")
public ResponseEntity<IPage<ProdProp>> page(ProdProp prodProp,PageParam<ProdProp> page){
public ServerResponseEntity<IPage<ProdProp>> page(ProdProp prodProp,PageParam<ProdProp> page){
prodProp.setRule(ProdPropRule.ATTRIBUTE.value());
prodProp.setShopId(SecurityUtils.getSysUser().getShopId());
IPage<ProdProp> prodPropPage = prodPropService.pagePropAndValue(prodProp,page);
return ResponseEntity.ok(prodPropPage);
return ServerResponseEntity.success(prodPropPage);
}
/**
@ -53,9 +53,9 @@ public class AttributeController {
*/
@GetMapping("/info/{id}")
@PreAuthorize("@pms.hasPermission('admin:attribute:info')")
public ResponseEntity<ProdProp> info(@PathVariable("id") Long id){
public ServerResponseEntity<ProdProp> info(@PathVariable("id") Long id){
ProdProp prodProp = prodPropService.getById(id);
return ResponseEntity.ok(prodProp);
return ServerResponseEntity.success(prodProp);
}
/**
@ -63,11 +63,11 @@ public class AttributeController {
*/
@PostMapping
@PreAuthorize("@pms.hasPermission('admin:attribute:save')")
public ResponseEntity<Void> save(@Valid ProdProp prodProp){
public ServerResponseEntity<Void> save(@Valid ProdProp prodProp){
prodProp.setRule(ProdPropRule.ATTRIBUTE.value());
prodProp.setShopId(SecurityUtils.getSysUser().getShopId());
prodPropService.saveProdPropAndValues(prodProp);
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
/**
@ -75,7 +75,7 @@ public class AttributeController {
*/
@PutMapping
@PreAuthorize("@pms.hasPermission('admin:attribute:update')")
public ResponseEntity<Void> update(@Valid ProdProp prodProp){
public ServerResponseEntity<Void> update(@Valid ProdProp prodProp){
ProdProp dbProdProp = prodPropService.getById(prodProp.getPropId());
if (!Objects.equals(dbProdProp.getShopId(), SecurityUtils.getSysUser().getShopId())) {
throw new YamiShopBindException("没有权限获取该商品规格信息");
@ -83,7 +83,7 @@ public class AttributeController {
prodProp.setRule(ProdPropRule.ATTRIBUTE.value());
prodProp.setShopId(SecurityUtils.getSysUser().getShopId());
prodPropService.updateProdPropAndValues(prodProp);
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
/**
@ -91,8 +91,8 @@ public class AttributeController {
*/
@DeleteMapping("/{id}")
@PreAuthorize("@pms.hasPermission('admin:attribute:delete')")
public ResponseEntity<Void> delete(@PathVariable Long id){
public ServerResponseEntity<Void> delete(@PathVariable Long id){
prodPropService.deleteProdPropAndValues(id,ProdPropRule.ATTRIBUTE.value(),SecurityUtils.getSysUser().getShopId());
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
}

View File

@ -18,7 +18,7 @@ import com.yami.shop.common.exception.YamiShopBindException;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
@ -43,12 +43,12 @@ public class BrandController {
*/
@GetMapping("/page")
@PreAuthorize("@pms.hasPermission('admin:brand:page')")
public ResponseEntity<IPage<Brand>> page(Brand brand,PageParam<Brand> page) {
public ServerResponseEntity<IPage<Brand>> page(Brand brand,PageParam<Brand> page) {
page.setAsc("first_char");
IPage<Brand> brands = brandService.page(page,
new LambdaQueryWrapper<Brand>()
.like(StrUtil.isNotBlank(brand.getBrandName()), Brand::getBrandName, brand.getBrandName()));
return ResponseEntity.ok(brands);
return ServerResponseEntity.success(brands);
}
/**
@ -56,9 +56,9 @@ public class BrandController {
*/
@GetMapping("/info/{id}")
@PreAuthorize("@pms.hasPermission('admin:brand:info')")
public ResponseEntity<Brand> info(@PathVariable("id") Long id) {
public ServerResponseEntity<Brand> info(@PathVariable("id") Long id) {
Brand brand = brandService.getById(id);
return ResponseEntity.ok(brand);
return ServerResponseEntity.success(brand);
}
/**
@ -66,13 +66,13 @@ public class BrandController {
*/
@PostMapping
@PreAuthorize("@pms.hasPermission('admin:brand:save')")
public ResponseEntity<Void> save(@Valid Brand brand) {
public ServerResponseEntity<Void> save(@Valid Brand brand) {
Brand dbBrand = brandService.getByBrandName(brand.getBrandName());
if (dbBrand != null) {
throw new YamiShopBindException("该品牌名称已存在");
}
brandService.save(brand);
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
/**
@ -80,13 +80,13 @@ public class BrandController {
*/
@PutMapping
@PreAuthorize("@pms.hasPermission('admin:brand:update')")
public ResponseEntity<Void> update(@Valid Brand brand) {
public ServerResponseEntity<Void> update(@Valid Brand brand) {
Brand dbBrand = brandService.getByBrandName(brand.getBrandName());
if (dbBrand != null && !Objects.equals(dbBrand.getBrandId(), brand.getBrandId())) {
throw new YamiShopBindException("该品牌名称已存在");
}
brandService.updateById(brand);
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
/**
@ -94,9 +94,9 @@ public class BrandController {
*/
@DeleteMapping("/{id}")
@PreAuthorize("@pms.hasPermission('admin:brand:delete')")
public ResponseEntity<Void> delete(@PathVariable Long id) {
public ServerResponseEntity<Void> delete(@PathVariable Long id) {
brandService.deleteByBrand(id);
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
}

View File

@ -17,7 +17,7 @@ import com.yami.shop.common.exception.YamiShopBindException;
import com.yami.shop.security.admin.util.SecurityUtils;
import com.yami.shop.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
@ -45,18 +45,18 @@ public class CategoryController {
*/
@GetMapping("/table")
@PreAuthorize("@pms.hasPermission('prod:category:page')")
public ResponseEntity<List<Category>> table(){
public ServerResponseEntity<List<Category>> table(){
List<Category> categoryMenuList = categoryService.tableCategory(SecurityUtils.getSysUser().getShopId());
return ResponseEntity.ok(categoryMenuList);
return ServerResponseEntity.success(categoryMenuList);
}
/**
* 获取分类信息
*/
@GetMapping("/info/{categoryId}")
public ResponseEntity<Category> info(@PathVariable("categoryId") Long categoryId){
public ServerResponseEntity<Category> info(@PathVariable("categoryId") Long categoryId){
Category category = categoryService.getById(categoryId);
return ResponseEntity.ok(category);
return ServerResponseEntity.success(category);
}
@ -67,7 +67,7 @@ public class CategoryController {
@SysLog("保存分类")
@PostMapping
@PreAuthorize("@pms.hasPermission('prod:category:save')")
public ResponseEntity<Void> save(@RequestBody Category category){
public ServerResponseEntity<Void> save(@RequestBody Category category){
category.setShopId(SecurityUtils.getSysUser().getShopId());
category.setRecTime(new Date());
Category categoryName = categoryService.getOne(new LambdaQueryWrapper<Category>().eq(Category::getCategoryName,category.getCategoryName())
@ -76,7 +76,7 @@ public class CategoryController {
throw new YamiShopBindException("类目名称已存在!");
}
categoryService.saveCategory(category);
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
/**
@ -85,10 +85,10 @@ public class CategoryController {
@SysLog("更新分类")
@PutMapping
@PreAuthorize("@pms.hasPermission('prod:category:update')")
public ResponseEntity<String> update(@RequestBody Category category){
public ServerResponseEntity<String> update(@RequestBody Category category){
category.setShopId(SecurityUtils.getSysUser().getShopId());
if (Objects.equals(category.getParentId(),category.getCategoryId())) {
return ResponseEntity.badRequest().body("分类的上级不能是自己本身");
return ServerResponseEntity.showFailMsg("分类的上级不能是自己本身");
}
Category categoryName = categoryService.getOne(new LambdaQueryWrapper<Category>().eq(Category::getCategoryName,category.getCategoryName())
.eq(Category::getShopId,category.getShopId()).ne(Category::getCategoryId,category.getCategoryId()));
@ -105,7 +105,7 @@ public class CategoryController {
}
}
categoryService.updateCategory(category);
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
/**
@ -114,21 +114,21 @@ public class CategoryController {
@SysLog("删除分类")
@DeleteMapping("/{categoryId}")
@PreAuthorize("@pms.hasPermission('prod:category:delete')")
public ResponseEntity<String> delete(@PathVariable("categoryId") Long categoryId){
public ServerResponseEntity<String> delete(@PathVariable("categoryId") Long categoryId){
if (categoryService.count(new LambdaQueryWrapper<Category>().eq(Category::getParentId,categoryId)) >0) {
return ResponseEntity.badRequest().body("请删除子分类,再删除该分类");
return ServerResponseEntity.showFailMsg("请删除子分类,再删除该分类");
}
categoryService.deleteCategory(categoryId);
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
/**
* 所有的
*/
@GetMapping("/listCategory")
public ResponseEntity<List<Category>> listCategory(){
public ServerResponseEntity<List<Category>> listCategory(){
return ResponseEntity.ok(categoryService.list(new LambdaQueryWrapper<Category>()
return ServerResponseEntity.success(categoryService.list(new LambdaQueryWrapper<Category>()
.le(Category::getGrade, 2)
.eq(Category::getShopId, SecurityUtils.getSysUser().getShopId())
.orderByAsc(Category::getSeq)));
@ -138,8 +138,8 @@ public class CategoryController {
* 所有的产品分类
*/
@GetMapping("/listProdCategory")
public ResponseEntity<List<Category>> listProdCategory(){
public ServerResponseEntity<List<Category>> listProdCategory(){
List<Category> categories = categoryService.treeSelect(SecurityUtils.getSysUser().getShopId(),2);
return ResponseEntity.ok(categories);
return ServerResponseEntity.success(categories);
}
}

View File

@ -13,7 +13,7 @@ package com.yami.shop.admin.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@ -36,10 +36,10 @@ public class DeliveryController {
* 分页获取
*/
@GetMapping("/list")
public ResponseEntity<List<Delivery>> page(){
public ServerResponseEntity<List<Delivery>> page(){
List<Delivery> list = deliveryService.list();
return ResponseEntity.ok(list);
return ServerResponseEntity.success(list);
}
}

View File

@ -10,19 +10,17 @@
package com.yami.shop.admin.controller;
import java.io.IOException;
import com.yami.shop.common.bean.Qiniu;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.service.AttachFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import com.yami.shop.bean.dto.TinymceEditorDto;
import com.yami.shop.common.bean.Qiniu;
import com.yami.shop.service.AttachFileService;
import java.io.IOException;
/**
* 文件上传 controller
@ -39,18 +37,18 @@ public class FileController {
private Qiniu qiniu;
@PostMapping("/upload/element")
public ResponseEntity<String> uploadElementFile(@RequestParam("file") MultipartFile file) throws IOException{
public ServerResponseEntity<String> uploadElementFile(@RequestParam("file") MultipartFile file) throws IOException{
if(file.isEmpty()){
return ResponseEntity.noContent().build();
return ServerResponseEntity.success();
}
String fileName = attachFileService.uploadFile(file.getBytes(),file.getOriginalFilename());
return ResponseEntity.ok(fileName);
return ServerResponseEntity.success(fileName);
}
@PostMapping("/upload/tinymceEditor")
public ResponseEntity<String> uploadTinymceEditorImages(@RequestParam("editorFile") MultipartFile editorFile) throws IOException{
public ServerResponseEntity<String> uploadTinymceEditorImages(@RequestParam("editorFile") MultipartFile editorFile) throws IOException{
String fileName = attachFileService.uploadFile(editorFile.getBytes(),editorFile.getOriginalFilename());
return ResponseEntity.ok(qiniu.getResourcesUrl() + fileName);
return ServerResponseEntity.success(qiniu.getResourcesUrl() + fileName);
}
}

View File

@ -18,7 +18,7 @@ import com.yami.shop.common.util.PageParam;
import com.yami.shop.security.admin.util.SecurityUtils;
import com.yami.shop.service.HotSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
@ -42,7 +42,7 @@ public class HotSearchController {
*/
@GetMapping("/page")
@PreAuthorize("@pms.hasPermission('admin:hotSearch:page')")
public ResponseEntity<IPage<HotSearch>> page(HotSearch hotSearch,PageParam<HotSearch> page){
public ServerResponseEntity<IPage<HotSearch>> page(HotSearch hotSearch,PageParam<HotSearch> page){
IPage<HotSearch> hotSearchs = hotSearchService.page(page,new LambdaQueryWrapper<HotSearch>()
.eq(HotSearch::getShopId, SecurityUtils.getSysUser().getShopId())
.like(StrUtil.isNotBlank(hotSearch.getContent()), HotSearch::getContent,hotSearch.getContent())
@ -50,16 +50,16 @@ public class HotSearchController {
.eq(hotSearch.getStatus()!=null, HotSearch::getStatus,hotSearch.getStatus())
.orderByAsc(HotSearch::getSeq)
);
return ResponseEntity.ok(hotSearchs);
return ServerResponseEntity.success(hotSearchs);
}
/**
* 获取信息
*/
@GetMapping("/info/{id}")
public ResponseEntity<HotSearch> info(@PathVariable("id") Long id){
public ServerResponseEntity<HotSearch> info(@PathVariable("id") Long id){
HotSearch hotSearch = hotSearchService.getById(id);
return ResponseEntity.ok(hotSearch);
return ServerResponseEntity.success(hotSearch);
}
/**
@ -67,13 +67,13 @@ public class HotSearchController {
*/
@PostMapping
@PreAuthorize("@pms.hasPermission('admin:hotSearch:save')")
public ResponseEntity<Void> save(@RequestBody @Valid HotSearch hotSearch){
public ServerResponseEntity<Void> save(@RequestBody @Valid HotSearch hotSearch){
hotSearch.setRecDate(new Date());
hotSearch.setShopId(SecurityUtils.getSysUser().getShopId());
hotSearchService.save(hotSearch);
//清除缓存
hotSearchService.removeHotSearchDtoCacheByShopId(SecurityUtils.getSysUser().getShopId());
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
/**
@ -81,11 +81,11 @@ public class HotSearchController {
*/
@PutMapping
@PreAuthorize("@pms.hasPermission('admin:hotSearch:update')")
public ResponseEntity<Void> update(@RequestBody @Valid HotSearch hotSearch){
public ServerResponseEntity<Void> update(@RequestBody @Valid HotSearch hotSearch){
hotSearchService.updateById(hotSearch);
//清除缓存
hotSearchService.removeHotSearchDtoCacheByShopId(SecurityUtils.getSysUser().getShopId());
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
/**
@ -93,10 +93,10 @@ public class HotSearchController {
*/
@DeleteMapping
@PreAuthorize("@pms.hasPermission('admin:hotSearch:delete')")
public ResponseEntity<Void> delete(@RequestBody List<Long> ids){
public ServerResponseEntity<Void> delete(@RequestBody List<Long> ids){
hotSearchService.removeByIds(ids);
//清除缓存
hotSearchService.removeHotSearchDtoCacheByShopId(SecurityUtils.getSysUser().getShopId());
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
}

View File

@ -20,7 +20,7 @@ import com.yami.shop.security.admin.util.SecurityUtils;
import com.yami.shop.service.IndexImgService;
import com.yami.shop.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
@ -47,12 +47,12 @@ public class IndexImgController {
*/
@GetMapping("/page")
@PreAuthorize("@pms.hasPermission('admin:indexImg:page')")
public ResponseEntity<IPage<IndexImg>> page(IndexImg indexImg, PageParam<IndexImg> page) {
public ServerResponseEntity<IPage<IndexImg>> page(IndexImg indexImg, PageParam<IndexImg> page) {
IPage<IndexImg> indexImgPage = indexImgService.page(page,
new LambdaQueryWrapper<IndexImg>()
.eq(indexImg.getStatus() != null, IndexImg::getStatus, indexImg.getStatus())
.orderByAsc(IndexImg::getSeq));
return ResponseEntity.ok(indexImgPage);
return ServerResponseEntity.success(indexImgPage);
}
/**
@ -60,7 +60,7 @@ public class IndexImgController {
*/
@GetMapping("/info/{imgId}")
@PreAuthorize("@pms.hasPermission('admin:indexImg:info')")
public ResponseEntity<IndexImg> info(@PathVariable("imgId") Long imgId) {
public ServerResponseEntity<IndexImg> info(@PathVariable("imgId") Long imgId) {
Long shopId = SecurityUtils.getSysUser().getShopId();
IndexImg indexImg = indexImgService.getOne(new LambdaQueryWrapper<IndexImg>().eq(IndexImg::getShopId, shopId).eq(IndexImg::getImgId, imgId));
if (Objects.nonNull(indexImg.getRelation())) {
@ -68,7 +68,7 @@ public class IndexImgController {
indexImg.setPic(product.getPic());
indexImg.setProdName(product.getProdName());
}
return ResponseEntity.ok(indexImg);
return ServerResponseEntity.success(indexImg);
}
/**
@ -76,14 +76,14 @@ public class IndexImgController {
*/
@PostMapping
@PreAuthorize("@pms.hasPermission('admin:indexImg:save')")
public ResponseEntity<Void> save(@RequestBody @Valid IndexImg indexImg) {
public ServerResponseEntity<Void> save(@RequestBody @Valid IndexImg indexImg) {
Long shopId = SecurityUtils.getSysUser().getShopId();
indexImg.setShopId(shopId);
indexImg.setUploadTime(new Date());
checkProdStatus(indexImg);
indexImgService.save(indexImg);
indexImgService.removeIndexImgCache();
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
/**
@ -91,11 +91,11 @@ public class IndexImgController {
*/
@PutMapping
@PreAuthorize("@pms.hasPermission('admin:indexImg:update')")
public ResponseEntity<Void> update(@RequestBody @Valid IndexImg indexImg) {
public ServerResponseEntity<Void> update(@RequestBody @Valid IndexImg indexImg) {
checkProdStatus(indexImg);
indexImgService.saveOrUpdate(indexImg);
indexImgService.removeIndexImgCache();
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
/**
@ -103,10 +103,10 @@ public class IndexImgController {
*/
@DeleteMapping
@PreAuthorize("@pms.hasPermission('admin:indexImg:delete')")
public ResponseEntity<Void> delete(@RequestBody Long[] ids) {
public ServerResponseEntity<Void> delete(@RequestBody Long[] ids) {
indexImgService.deleteIndexImgByIds(ids);
indexImgService.removeIndexImgCache();
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
private void checkProdStatus(IndexImg indexImg) {

View File

@ -16,7 +16,7 @@ import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
@ -52,11 +52,11 @@ public class MessageController {
*/
@GetMapping("/page")
@PreAuthorize("@pms.hasPermission('admin:message:page')")
public ResponseEntity<IPage<Message>> page(Message message,PageParam<Message> page) {
public ServerResponseEntity<IPage<Message>> page(Message message,PageParam<Message> page) {
IPage<Message> messages = messageService.page(page, new LambdaQueryWrapper<Message>()
.like(StrUtil.isNotBlank(message.getUserName()), Message::getUserName, message.getUserName())
.eq(message.getStatus() != null, Message::getStatus, message.getStatus()));
return ResponseEntity.ok(messages);
return ServerResponseEntity.success(messages);
}
/**
@ -64,9 +64,9 @@ public class MessageController {
*/
@GetMapping("/info/{id}")
@PreAuthorize("@pms.hasPermission('admin:message:info')")
public ResponseEntity<Message> info(@PathVariable("id") Long id) {
public ServerResponseEntity<Message> info(@PathVariable("id") Long id) {
Message message = messageService.getById(id);
return ResponseEntity.ok(message);
return ServerResponseEntity.success(message);
}
/**
@ -74,9 +74,9 @@ public class MessageController {
*/
@PostMapping
@PreAuthorize("@pms.hasPermission('admin:message:save')")
public ResponseEntity<Void> save(@RequestBody Message message) {
public ServerResponseEntity<Void> save(@RequestBody Message message) {
messageService.save(message);
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
/**
@ -84,9 +84,9 @@ public class MessageController {
*/
@PutMapping
@PreAuthorize("@pms.hasPermission('admin:message:update')")
public ResponseEntity<Void> update(@RequestBody Message message) {
public ServerResponseEntity<Void> update(@RequestBody Message message) {
messageService.updateById(message);
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
/**
@ -94,12 +94,12 @@ public class MessageController {
*/
@PutMapping("/release/{id}")
@PreAuthorize("@pms.hasPermission('admin:message:release')")
public ResponseEntity<Void> release(@PathVariable("id") Long id) {
public ServerResponseEntity<Void> release(@PathVariable("id") Long id) {
Message message = new Message();
message.setId(id);
message.setStatus(MessageStatus.RELEASE.value());
messageService.updateById(message);
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
/**
@ -107,12 +107,12 @@ public class MessageController {
*/
@PutMapping("/cancel/{id}")
@PreAuthorize("@pms.hasPermission('admin:message:cancel')")
public ResponseEntity<Void> cancel(@PathVariable("id") Long id) {
public ServerResponseEntity<Void> cancel(@PathVariable("id") Long id) {
Message message = new Message();
message.setId(id);
message.setStatus(MessageStatus.CANCEL.value());
messageService.updateById(message);
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
/**
@ -120,8 +120,8 @@ public class MessageController {
*/
@DeleteMapping("/{ids}")
@PreAuthorize("@pms.hasPermission('admin:message:delete')")
public ResponseEntity<Void> delete(@PathVariable Long[] ids) {
public ServerResponseEntity<Void> delete(@PathVariable Long[] ids) {
messageService.removeByIds(Arrays.asList(ids));
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
}

View File

@ -18,7 +18,7 @@ import com.yami.shop.common.util.PageParam;
import com.yami.shop.security.admin.util.SecurityUtils;
import com.yami.shop.service.NoticeService;
import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
@ -46,12 +46,12 @@ public class NoticeController {
* @return 分页数据
*/
@GetMapping("/page")
public ResponseEntity<IPage<Notice>> getNoticePage(PageParam<Notice> page, Notice notice) {
public ServerResponseEntity<IPage<Notice>> getNoticePage(PageParam<Notice> page, Notice notice) {
IPage<Notice> noticePage = noticeService.page(page, new LambdaQueryWrapper<Notice>()
.eq(notice.getStatus() != null, Notice::getStatus, notice.getStatus())
.eq(notice.getIsTop()!=null,Notice::getIsTop,notice.getIsTop())
.like(notice.getTitle() != null, Notice::getTitle, notice.getTitle()).orderByDesc(Notice::getUpdateTime));
return ResponseEntity.ok(noticePage);
return ServerResponseEntity.success(noticePage);
}
@ -62,8 +62,8 @@ public class NoticeController {
* @return 单个数据
*/
@GetMapping("/info/{id}")
public ResponseEntity<Notice> getById(@PathVariable("id") Long id) {
return ResponseEntity.ok(noticeService.getById(id));
public ServerResponseEntity<Notice> getById(@PathVariable("id") Long id) {
return ServerResponseEntity.success(noticeService.getById(id));
}
/**
@ -75,14 +75,14 @@ public class NoticeController {
@SysLog("新增公告管理")
@PostMapping
@PreAuthorize("@pms.hasPermission('shop:notice:save')")
public ResponseEntity<Boolean> save(@RequestBody @Valid Notice notice) {
public ServerResponseEntity<Boolean> save(@RequestBody @Valid Notice notice) {
notice.setShopId(SecurityUtils.getSysUser().getShopId());
if (notice.getStatus() == 1) {
notice.setPublishTime(new Date());
}
notice.setUpdateTime(new Date());
noticeService.removeNoticeList();
return ResponseEntity.ok(noticeService.save(notice));
return ServerResponseEntity.success(noticeService.save(notice));
}
/**
@ -94,7 +94,7 @@ public class NoticeController {
@SysLog("修改公告管理")
@PutMapping
@PreAuthorize("@pms.hasPermission('shop:notice:update')")
public ResponseEntity<Boolean> updateById(@RequestBody @Valid Notice notice) {
public ServerResponseEntity<Boolean> updateById(@RequestBody @Valid Notice notice) {
Notice oldNotice = noticeService.getById(notice.getId());
if (oldNotice.getStatus() == 0 && notice.getStatus() == 1) {
notice.setPublishTime(new Date());
@ -102,7 +102,7 @@ public class NoticeController {
notice.setUpdateTime(new Date());
noticeService.removeNoticeList();
noticeService.removeNoticeById(notice.getId());
return ResponseEntity.ok(noticeService.updateById(notice));
return ServerResponseEntity.success(noticeService.updateById(notice));
}
/**
@ -114,10 +114,10 @@ public class NoticeController {
@SysLog("删除公告管理")
@DeleteMapping("/{id}")
@PreAuthorize("@pms.hasPermission('shop:notice:delete')")
public ResponseEntity<Boolean> removeById(@PathVariable Long id) {
public ServerResponseEntity<Boolean> removeById(@PathVariable Long id) {
noticeService.removeNoticeList();
noticeService.removeNoticeById(id);
return ResponseEntity.ok(noticeService.removeById(id));
return ServerResponseEntity.success(noticeService.removeById(id));
}
}

View File

@ -32,7 +32,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.Sheet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.ResponseEntity;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
@ -48,7 +48,7 @@ import java.util.List;
* @author lgh on 2018/09/15.
*/
@Slf4j
@Controller
@RestController
@RequestMapping("/order/order")
public class OrderController {
@ -72,11 +72,11 @@ public class OrderController {
*/
@GetMapping("/page")
@PreAuthorize("@pms.hasPermission('order:order:page')")
public ResponseEntity<IPage<Order>> page(OrderParam orderParam,PageParam<Order> page) {
public ServerResponseEntity<IPage<Order>> page(OrderParam orderParam,PageParam<Order> page) {
Long shopId = SecurityUtils.getSysUser().getShopId();
orderParam.setShopId(shopId);
IPage<Order> orderPage = orderService.pageOrdersDetailByOrderParam(page, orderParam);
return ResponseEntity.ok(orderPage);
return ServerResponseEntity.success(orderPage);
}
@ -86,7 +86,7 @@ public class OrderController {
*/
@GetMapping("/orderInfo/{orderNumber}")
@PreAuthorize("@pms.hasPermission('order:order:info')")
public ResponseEntity<Order> info(@PathVariable("orderNumber") String orderNumber) {
public ServerResponseEntity<Order> info(@PathVariable("orderNumber") String orderNumber) {
Long shopId = SecurityUtils.getSysUser().getShopId();
Order order = orderService.getOrderByOrderNumber(orderNumber);
if (!Objects.equal(shopId, order.getShopId())) {
@ -96,7 +96,7 @@ public class OrderController {
order.setOrderItems(orderItems);
UserAddrOrder userAddrOrder = userAddrOrderService.getById(order.getAddrOrderId());
order.setUserAddrOrder(userAddrOrder);
return ResponseEntity.ok(order);
return ServerResponseEntity.success(order);
}
/**
@ -104,7 +104,7 @@ public class OrderController {
*/
@PutMapping("/delivery")
@PreAuthorize("@pms.hasPermission('order:order:delivery')")
public ResponseEntity<Void> delivery(@RequestBody DeliveryOrderParam deliveryOrderParam) {
public ServerResponseEntity<Void> delivery(@RequestBody DeliveryOrderParam deliveryOrderParam) {
Long shopId = SecurityUtils.getSysUser().getShopId();
Order order = orderService.getOrderByOrderNumber(deliveryOrderParam.getOrderNumber());
if (!Objects.equal(shopId, order.getShopId())) {
@ -126,7 +126,7 @@ public class OrderController {
productService.removeProductCacheByProdId(orderItem.getProdId());
skuService.removeSkuCacheBySkuId(orderItem.getSkuId(),orderItem.getProdId());
}
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
/**

View File

@ -14,13 +14,13 @@ import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.bean.model.PickAddr;
import com.yami.shop.common.enums.YamiHttpStatus;
import com.yami.shop.common.exception.YamiShopBindException;
import com.yami.shop.common.response.ResponseEnum;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.security.admin.util.SecurityUtils;
import com.yami.shop.service.PickAddrService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
@ -46,11 +46,11 @@ public class PickAddrController {
*/
@GetMapping("/page")
@PreAuthorize("@pms.hasPermission('shop:pickAddr:page')")
public ResponseEntity<IPage<PickAddr>> page(PickAddr pickAddr,PageParam<PickAddr> page){
public ServerResponseEntity<IPage<PickAddr>> page(PickAddr pickAddr,PageParam<PickAddr> page){
IPage<PickAddr> pickAddrs = pickAddrService.page(page,new LambdaQueryWrapper<PickAddr>()
.like(StrUtil.isNotBlank(pickAddr.getAddrName()),PickAddr::getAddrName,pickAddr.getAddrName())
.orderByDesc(PickAddr::getAddrId));
return ResponseEntity.ok(pickAddrs);
return ServerResponseEntity.success(pickAddrs);
}
/**
@ -58,9 +58,9 @@ public class PickAddrController {
*/
@GetMapping("/info/{id}")
@PreAuthorize("@pms.hasPermission('shop:pickAddr:info')")
public ResponseEntity<PickAddr> info(@PathVariable("id") Long id){
public ServerResponseEntity<PickAddr> info(@PathVariable("id") Long id){
PickAddr pickAddr = pickAddrService.getById(id);
return ResponseEntity.ok(pickAddr);
return ServerResponseEntity.success(pickAddr);
}
/**
@ -68,10 +68,10 @@ public class PickAddrController {
*/
@PostMapping
@PreAuthorize("@pms.hasPermission('shop:pickAddr:save')")
public ResponseEntity<Void> save(@Valid @RequestBody PickAddr pickAddr){
public ServerResponseEntity<Void> save(@Valid @RequestBody PickAddr pickAddr){
pickAddr.setShopId(SecurityUtils.getSysUser().getShopId());
pickAddrService.save(pickAddr);
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
/**
@ -79,14 +79,14 @@ public class PickAddrController {
*/
@PutMapping
@PreAuthorize("@pms.hasPermission('shop:pickAddr:update')")
public ResponseEntity<Void> update(@Valid @RequestBody PickAddr pickAddr){
public ServerResponseEntity<Void> update(@Valid @RequestBody PickAddr pickAddr){
PickAddr dbPickAddr = pickAddrService.getById(pickAddr.getAddrId());
if (!Objects.equals(dbPickAddr.getShopId(),SecurityUtils.getSysUser().getShopId())) {
throw new YamiShopBindException(YamiHttpStatus.UNAUTHORIZED);
throw new YamiShopBindException(ResponseEnum.UNAUTHORIZED);
}
pickAddrService.updateById(pickAddr);
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
/**
@ -94,8 +94,8 @@ public class PickAddrController {
*/
@DeleteMapping
@PreAuthorize("@pms.hasPermission('shop:pickAddr:delete')")
public ResponseEntity<Void> delete(@RequestBody Long[] ids){
public ServerResponseEntity<Void> delete(@RequestBody Long[] ids){
pickAddrService.removeByIds(Arrays.asList(ids));
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
}

View File

@ -22,7 +22,7 @@ import javax.validation.Valid;
import lombok.SneakyThrows;
import org.apache.commons.lang3.StringUtils;
import org.springframework.http.ResponseEntity;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
@ -54,8 +54,8 @@ public class ProdCommController {
*/
@GetMapping("/page" )
@PreAuthorize("@pms.hasPermission('prod:prodComm:page')" )
public ResponseEntity<IPage<ProdComm>> getProdCommPage(PageParam page, ProdComm prodComm) {
return ResponseEntity.ok(prodCommService.getProdCommPage(page,prodComm));
public ServerResponseEntity<IPage<ProdComm>> getProdCommPage(PageParam page, ProdComm prodComm) {
return ServerResponseEntity.success(prodCommService.getProdCommPage(page,prodComm));
}
@ -66,8 +66,8 @@ public class ProdCommController {
*/
@GetMapping("/info/{prodCommId}" )
@PreAuthorize("@pms.hasPermission('prod:prodComm:info')" )
public ResponseEntity<ProdComm> getById(@PathVariable("prodCommId" ) Long prodCommId) {
return ResponseEntity.ok(prodCommService.getById(prodCommId));
public ServerResponseEntity<ProdComm> getById(@PathVariable("prodCommId" ) Long prodCommId) {
return ServerResponseEntity.success(prodCommService.getById(prodCommId));
}
/**
@ -78,8 +78,8 @@ public class ProdCommController {
@SysLog("新增商品评论" )
@PostMapping
@PreAuthorize("@pms.hasPermission('prod:prodComm:save')" )
public ResponseEntity<Boolean> save(@RequestBody @Valid ProdComm prodComm) {
return ResponseEntity.ok(prodCommService.save(prodComm));
public ServerResponseEntity<Boolean> save(@RequestBody @Valid ProdComm prodComm) {
return ServerResponseEntity.success(prodCommService.save(prodComm));
}
/**
@ -90,9 +90,9 @@ public class ProdCommController {
@SysLog("修改商品评论" )
@PutMapping
@PreAuthorize("@pms.hasPermission('prod:prodComm:update')" )
public ResponseEntity<Boolean> updateById(@RequestBody @Valid ProdComm prodComm) {
public ServerResponseEntity<Boolean> updateById(@RequestBody @Valid ProdComm prodComm) {
prodComm.setReplyTime(new Date());
return ResponseEntity.ok(prodCommService.updateById(prodComm));
return ServerResponseEntity.success(prodCommService.updateById(prodComm));
}
/**
@ -103,8 +103,8 @@ public class ProdCommController {
@SysLog("删除商品评论" )
@DeleteMapping("/{prodCommId}" )
@PreAuthorize("@pms.hasPermission('prod:prodComm:delete')" )
public ResponseEntity<Boolean> removeById(@PathVariable Long prodCommId) {
return ResponseEntity.ok(prodCommService.removeById(prodCommId));
public ServerResponseEntity<Boolean> removeById(@PathVariable Long prodCommId) {
return ServerResponseEntity.success(prodCommService.removeById(prodCommId));
}
}

View File

@ -21,7 +21,7 @@ import com.yami.shop.common.util.PageParam;
import com.yami.shop.security.admin.util.SecurityUtils;
import com.yami.shop.service.ProdTagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
@ -50,13 +50,13 @@ public class ProdTagController {
* @return 分页数据
*/
@GetMapping("/page")
public ResponseEntity<IPage<ProdTag>> getProdTagPage(PageParam<ProdTag> page, ProdTag prodTag) {
public ServerResponseEntity<IPage<ProdTag>> getProdTagPage(PageParam<ProdTag> page, ProdTag prodTag) {
IPage<ProdTag> tagPage = prodTagService.page(
page, new LambdaQueryWrapper<ProdTag>()
.eq(prodTag.getStatus() != null, ProdTag::getStatus, prodTag.getStatus())
.like(prodTag.getTitle() != null, ProdTag::getTitle, prodTag.getTitle())
.orderByDesc(ProdTag::getSeq, ProdTag::getCreateTime));
return ResponseEntity.ok(tagPage);
return ServerResponseEntity.success(tagPage);
}
@ -68,8 +68,8 @@ public class ProdTagController {
* @return 单个数据
*/
@GetMapping("/info/{id}")
public ResponseEntity<ProdTag> getById(@PathVariable("id") Long id) {
return ResponseEntity.ok(prodTagService.getById(id));
public ServerResponseEntity<ProdTag> getById(@PathVariable("id") Long id) {
return ServerResponseEntity.success(prodTagService.getById(id));
}
/**
@ -81,7 +81,7 @@ public class ProdTagController {
@SysLog("新增商品分组标签")
@PostMapping
@PreAuthorize("@pms.hasPermission('prod:prodTag:save')")
public ResponseEntity<Boolean> save(@RequestBody @Valid ProdTag prodTag) {
public ServerResponseEntity<Boolean> save(@RequestBody @Valid ProdTag prodTag) {
// 查看是否相同的标签
List<ProdTag> list = prodTagService.list(new LambdaQueryWrapper<ProdTag>().like(ProdTag::getTitle, prodTag.getTitle()));
if (CollectionUtil.isNotEmpty(list)) {
@ -93,7 +93,7 @@ public class ProdTagController {
prodTag.setUpdateTime(new Date());
prodTag.setShopId(SecurityUtils.getSysUser().getShopId());
prodTagService.removeProdTag();
return ResponseEntity.ok(prodTagService.save(prodTag));
return ServerResponseEntity.success(prodTagService.save(prodTag));
}
/**
@ -105,10 +105,10 @@ public class ProdTagController {
@SysLog("修改商品分组标签")
@PutMapping
@PreAuthorize("@pms.hasPermission('prod:prodTag:update')")
public ResponseEntity<Boolean> updateById(@RequestBody @Valid ProdTag prodTag) {
public ServerResponseEntity<Boolean> updateById(@RequestBody @Valid ProdTag prodTag) {
prodTag.setUpdateTime(new Date());
prodTagService.removeProdTag();
return ResponseEntity.ok(prodTagService.updateById(prodTag));
return ServerResponseEntity.success(prodTagService.updateById(prodTag));
}
/**
@ -120,18 +120,18 @@ public class ProdTagController {
@SysLog("删除商品分组标签")
@DeleteMapping("/{id}")
@PreAuthorize("@pms.hasPermission('prod:prodTag:delete')")
public ResponseEntity<Boolean> removeById(@PathVariable Long id) {
public ServerResponseEntity<Boolean> removeById(@PathVariable Long id) {
ProdTag prodTag = prodTagService.getById(id);
if (prodTag.getIsDefault() != 0) {
throw new YamiShopBindException("默认标签不能删除");
}
prodTagService.removeProdTag();
return ResponseEntity.ok(prodTagService.removeById(id));
return ServerResponseEntity.success(prodTagService.removeById(id));
}
@GetMapping("/listTagList")
public ResponseEntity<List<ProdTag>> listTagList() {
return ResponseEntity.ok(prodTagService.listProdTag());
public ServerResponseEntity<List<ProdTag>> listTagList() {
return ServerResponseEntity.success(prodTagService.listProdTag());
}

View File

@ -18,7 +18,7 @@ import com.yami.shop.bean.model.ProdTagReference;
import com.yami.shop.common.annotation.SysLog;
import com.yami.shop.service.ProdTagReferenceService;
import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
@ -44,8 +44,8 @@ public class ProdTagReferenceController {
* @return 分页数据
*/
@GetMapping("/page" )
public ResponseEntity<IPage<ProdTagReference>> getProdTagReferencePage(PageParam page, ProdTagReference prodTagReference) {
return ResponseEntity.ok(prodTagReferenceService.page(page, new LambdaQueryWrapper<ProdTagReference>()));
public ServerResponseEntity<IPage<ProdTagReference>> getProdTagReferencePage(PageParam page, ProdTagReference prodTagReference) {
return ServerResponseEntity.success(prodTagReferenceService.page(page, new LambdaQueryWrapper<ProdTagReference>()));
}
@ -55,8 +55,8 @@ public class ProdTagReferenceController {
* @return 单个数据
*/
@GetMapping("/info/{referenceId}" )
public ResponseEntity<ProdTagReference> getById(@PathVariable("referenceId" ) Long referenceId) {
return ResponseEntity.ok(prodTagReferenceService.getById(referenceId));
public ServerResponseEntity<ProdTagReference> getById(@PathVariable("referenceId" ) Long referenceId) {
return ServerResponseEntity.success(prodTagReferenceService.getById(referenceId));
}
/**
@ -67,8 +67,8 @@ public class ProdTagReferenceController {
@SysLog("新增分组标签引用" )
@PostMapping
@PreAuthorize("@pms.hasPermission('generator:prodTagReference:save')" )
public ResponseEntity<Boolean> save(@RequestBody @Valid ProdTagReference prodTagReference) {
return ResponseEntity.ok(prodTagReferenceService.save(prodTagReference));
public ServerResponseEntity<Boolean> save(@RequestBody @Valid ProdTagReference prodTagReference) {
return ServerResponseEntity.success(prodTagReferenceService.save(prodTagReference));
}
/**
@ -79,8 +79,8 @@ public class ProdTagReferenceController {
@SysLog("修改分组标签引用" )
@PutMapping
@PreAuthorize("@pms.hasPermission('generator:prodTagReference:update')" )
public ResponseEntity<Boolean> updateById(@RequestBody @Valid ProdTagReference prodTagReference) {
return ResponseEntity.ok(prodTagReferenceService.updateById(prodTagReference));
public ServerResponseEntity<Boolean> updateById(@RequestBody @Valid ProdTagReference prodTagReference) {
return ServerResponseEntity.success(prodTagReferenceService.updateById(prodTagReference));
}
/**
@ -91,8 +91,8 @@ public class ProdTagReferenceController {
@SysLog("删除分组标签引用" )
@DeleteMapping("/{referenceId}" )
@PreAuthorize("@pms.hasPermission('generator:prodTagReference:delete')" )
public ResponseEntity<Boolean> removeById(@PathVariable Long referenceId) {
return ResponseEntity.ok(prodTagReferenceService.removeById(referenceId));
public ServerResponseEntity<Boolean> removeById(@PathVariable Long referenceId) {
return ServerResponseEntity.success(prodTagReferenceService.removeById(referenceId));
}
}

View File

@ -18,6 +18,7 @@ import com.yami.shop.bean.model.Product;
import com.yami.shop.bean.model.Sku;
import com.yami.shop.bean.param.ProductParam;
import com.yami.shop.common.exception.YamiShopBindException;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.common.util.Json;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.security.admin.util.SecurityUtils;
@ -27,9 +28,7 @@ import com.yami.shop.service.ProductService;
import com.yami.shop.service.SkuService;
import ma.glasnost.orika.MapperFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
@ -43,7 +42,7 @@ import java.util.Objects;
*
* @author lgh
*/
@Controller
@RestController
@RequestMapping("/prod/prod")
public class ProductController {
@ -67,14 +66,14 @@ public class ProductController {
*/
@GetMapping("/page")
@PreAuthorize("@pms.hasPermission('prod:prod:page')")
public ResponseEntity<IPage<Product>> page(ProductParam product, PageParam<Product> page) {
public ServerResponseEntity<IPage<Product>> page(ProductParam product, PageParam<Product> page) {
IPage<Product> products = productService.page(page,
new LambdaQueryWrapper<Product>()
.like(StrUtil.isNotBlank(product.getProdName()), Product::getProdName, product.getProdName())
.eq(Product::getShopId, SecurityUtils.getSysUser().getShopId())
.eq(product.getStatus() != null, Product::getStatus, product.getStatus())
.orderByDesc(Product::getPutawayTime));
return ResponseEntity.ok(products);
return ServerResponseEntity.success(products);
}
/**
@ -82,7 +81,7 @@ public class ProductController {
*/
@GetMapping("/info/{prodId}")
@PreAuthorize("@pms.hasPermission('prod:prod:info')")
public ResponseEntity<Product> info(@PathVariable("prodId") Long prodId) {
public ServerResponseEntity<Product> info(@PathVariable("prodId") Long prodId) {
Product prod = productService.getProductByProdId(prodId);
if (!Objects.equals(prod.getShopId(), SecurityUtils.getSysUser().getShopId())) {
throw new YamiShopBindException("没有权限获取该商品规格信息");
@ -93,7 +92,7 @@ public class ProductController {
//获取分组标签
List<Long> listTagId = prodTagReferenceService.listTagIdByProdId(prodId);
prod.setTagList(listTagId);
return ResponseEntity.ok(prod);
return ServerResponseEntity.success(prod);
}
/**
@ -101,7 +100,7 @@ public class ProductController {
*/
@PostMapping
@PreAuthorize("@pms.hasPermission('prod:prod:save')")
public ResponseEntity<String> save(@Valid @RequestBody ProductParam productParam) {
public ServerResponseEntity<String> save(@Valid @RequestBody ProductParam productParam) {
checkParam(productParam);
Product product = mapperFacade.map(productParam, Product.class);
@ -113,7 +112,7 @@ public class ProductController {
}
product.setCreateTime(new Date());
productService.saveProduct(product);
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
/**
@ -121,11 +120,11 @@ public class ProductController {
*/
@PutMapping
@PreAuthorize("@pms.hasPermission('prod:prod:update')")
public ResponseEntity<String> update(@Valid @RequestBody ProductParam productParam) {
public ServerResponseEntity<String> update(@Valid @RequestBody ProductParam productParam) {
checkParam(productParam);
Product dbProduct = productService.getProductByProdId(productParam.getProdId());
if (!Objects.equals(dbProduct.getShopId(), SecurityUtils.getSysUser().getShopId())) {
return ResponseEntity.badRequest().body("无法修改非本店铺商品信息");
return ServerResponseEntity.showFailMsg("无法修改非本店铺商品信息");
}
List<Sku> dbSkus = skuService.listByProdId(dbProduct.getProdId());
@ -150,13 +149,13 @@ public class ProductController {
for (Sku sku : dbSkus) {
skuService.removeSkuCacheBySkuId(sku.getSkuId(), sku.getProdId());
}
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
/**
* 删除
*/
public ResponseEntity<Void> delete(Long prodId) {
public ServerResponseEntity<Void> delete(Long prodId) {
Product dbProduct = productService.getProductByProdId(prodId);
if (!Objects.equals(dbProduct.getShopId(), SecurityUtils.getSysUser().getShopId())) {
throw new YamiShopBindException("无法获取非本店铺商品信息");
@ -176,7 +175,7 @@ public class ProductController {
basketService.removeShopCartItemsCacheByUserId(userId);
}
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
/**
@ -184,11 +183,11 @@ public class ProductController {
*/
@DeleteMapping
@PreAuthorize("@pms.hasPermission('prod:prod:delete')")
public ResponseEntity<Void> batchDelete(@RequestBody Long[] prodIds) {
public ServerResponseEntity<Void> batchDelete(@RequestBody Long[] prodIds) {
for (Long prodId : prodIds) {
delete(prodId);
}
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
/**
@ -196,7 +195,7 @@ public class ProductController {
*/
@PutMapping("/prodStatus")
@PreAuthorize("@pms.hasPermission('prod:prod:status')")
public ResponseEntity<Void> shopStatus(@RequestParam Long prodId, @RequestParam Integer prodStatus) {
public ServerResponseEntity<Void> shopStatus(@RequestParam Long prodId, @RequestParam Integer prodStatus) {
Product product = new Product();
product.setProdId(prodId);
product.setStatus(prodStatus);
@ -210,7 +209,7 @@ public class ProductController {
for (String userId : userIds) {
basketService.removeShopCartItemsCacheByUserId(userId);
}
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
private void checkParam(ProductParam productParam) {

View File

@ -20,7 +20,7 @@ import com.yami.shop.security.admin.util.SecurityUtils;
import com.yami.shop.service.ShopDetailService;
import ma.glasnost.orika.MapperFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
@ -36,7 +36,7 @@ import java.util.stream.Collectors;
*
* @author lgh on 2018/08/29.
*/
@Controller
@RestController
@RequestMapping("/shop/shopDetail")
public class ShopDetailController {
@ -51,23 +51,23 @@ public class ShopDetailController {
* 修改分销开关
*/
@PutMapping("/isDistribution")
public ResponseEntity<Void> updateIsDistribution(@RequestParam Integer isDistribution){
public ServerResponseEntity<Void> updateIsDistribution(@RequestParam Integer isDistribution){
ShopDetail shopDetail=new ShopDetail();
shopDetail.setShopId(SecurityUtils.getSysUser().getShopId());
shopDetail.setIsDistribution(isDistribution);
shopDetailService.updateById(shopDetail);
// 更新完成后删除缓存
shopDetailService.removeShopDetailCacheByShopId(shopDetail.getShopId());
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
/**
* 获取信息
*/
@GetMapping("/info")
@PreAuthorize("@pms.hasPermission('shop:shopDetail:info')")
public ResponseEntity<ShopDetail> info(){
public ServerResponseEntity<ShopDetail> info(){
ShopDetail shopDetail = shopDetailService.getShopDetailByShopId(SecurityUtils.getSysUser().getShopId());
return ResponseEntity.ok(shopDetail);
return ServerResponseEntity.success(shopDetail);
}
@ -76,12 +76,12 @@ public class ShopDetailController {
*/
@GetMapping("/page")
@PreAuthorize("@pms.hasPermission('shop:shopDetail:page')")
public ResponseEntity<IPage<ShopDetail>> page(ShopDetail shopDetail,PageParam<ShopDetail> page){
public ServerResponseEntity<IPage<ShopDetail>> page(ShopDetail shopDetail,PageParam<ShopDetail> page){
IPage<ShopDetail> shopDetails = shopDetailService.page(page,
new LambdaQueryWrapper<ShopDetail>()
.like(StrUtil.isNotBlank(shopDetail.getShopName()),ShopDetail::getShopName,shopDetail.getShopName())
.orderByDesc(ShopDetail::getShopId));
return ResponseEntity.ok(shopDetails);
return ServerResponseEntity.success(shopDetails);
}
/**
@ -89,10 +89,10 @@ public class ShopDetailController {
*/
@GetMapping("/info/{shopId}")
@PreAuthorize("@pms.hasPermission('shop:shopDetail:info')")
public ResponseEntity<ShopDetail> info(@PathVariable("shopId") Long shopId){
public ServerResponseEntity<ShopDetail> info(@PathVariable("shopId") Long shopId){
ShopDetail shopDetail = shopDetailService.getShopDetailByShopId(shopId);
// 店铺图片
return ResponseEntity.ok(shopDetail);
return ServerResponseEntity.success(shopDetail);
}
/**
@ -100,12 +100,12 @@ public class ShopDetailController {
*/
@PostMapping
@PreAuthorize("@pms.hasPermission('shop:shopDetail:save')")
public ResponseEntity<Void> save(@Valid ShopDetailParam shopDetailParam){
public ServerResponseEntity<Void> save(@Valid ShopDetailParam shopDetailParam){
ShopDetail shopDetail = mapperFacade.map(shopDetailParam, ShopDetail.class);
shopDetail.setCreateTime(new Date());
shopDetail.setShopStatus(1);
shopDetailService.save(shopDetail);
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
/**
@ -113,12 +113,12 @@ public class ShopDetailController {
*/
@PutMapping
@PreAuthorize("@pms.hasPermission('shop:shopDetail:update')")
public ResponseEntity<Void> update(@Valid ShopDetailParam shopDetailParam){
public ServerResponseEntity<Void> update(@Valid ShopDetailParam shopDetailParam){
ShopDetail daShopDetail = shopDetailService.getShopDetailByShopId(shopDetailParam.getShopId());
ShopDetail shopDetail = mapperFacade.map(shopDetailParam, ShopDetail.class);
shopDetail.setUpdateTime(new Date());
shopDetailService.updateShopDetail(shopDetail,daShopDetail);
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
/**
@ -126,9 +126,9 @@ public class ShopDetailController {
*/
@DeleteMapping("/{id}")
@PreAuthorize("@pms.hasPermission('shop:shopDetail:delete')")
public ResponseEntity<Void> delete(@PathVariable Long id){
public ServerResponseEntity<Void> delete(@PathVariable Long id){
shopDetailService.deleteShopDetailByShopId(id);
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
/**
@ -136,14 +136,14 @@ public class ShopDetailController {
*/
@PutMapping("/shopStatus")
@PreAuthorize("@pms.hasPermission('shop:shopDetail:shopStatus')")
public ResponseEntity<Void> shopStatus(@RequestParam Long shopId,@RequestParam Integer shopStatus){
public ServerResponseEntity<Void> shopStatus(@RequestParam Long shopId,@RequestParam Integer shopStatus){
ShopDetail shopDetail = new ShopDetail();
shopDetail.setShopId(shopId);
shopDetail.setShopStatus(shopStatus);
shopDetailService.updateById(shopDetail);
// 更新完成后删除缓存
shopDetailService.removeShopDetailCacheByShopId(shopDetail.getShopId());
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
@ -151,13 +151,13 @@ public class ShopDetailController {
* 获取所有的店铺名称
*/
@GetMapping("/listShopName")
public ResponseEntity<List<ShopDetail>> listShopName(){
public ServerResponseEntity<List<ShopDetail>> listShopName(){
List<ShopDetail> list = shopDetailService.list().stream().map((dbShopDetail) ->{
ShopDetail shopDetail = new ShopDetail();
shopDetail.setShopId(dbShopDetail.getShopId());
shopDetail.setShopName(dbShopDetail.getShopName());
return shopDetail;
}).collect(Collectors.toList());
return ResponseEntity.ok(list);
return ServerResponseEntity.success(list);
}
}

View File

@ -21,7 +21,7 @@ import com.yami.shop.security.admin.util.SecurityUtils;
import com.yami.shop.service.ProdPropService;
import com.yami.shop.service.ProdPropValueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
@ -48,11 +48,11 @@ public class SpecController {
*/
@GetMapping("/page")
@PreAuthorize("@pms.hasPermission('prod:spec:page')")
public ResponseEntity<IPage<ProdProp>> page(ProdProp prodProp,PageParam<ProdProp> page) {
public ServerResponseEntity<IPage<ProdProp>> page(ProdProp prodProp,PageParam<ProdProp> page) {
prodProp.setRule(ProdPropRule.SPEC.value());
prodProp.setShopId(SecurityUtils.getSysUser().getShopId());
IPage<ProdProp> list = prodPropService.pagePropAndValue(prodProp, page);
return ResponseEntity.ok(list);
return ServerResponseEntity.success(list);
}
@ -60,18 +60,18 @@ public class SpecController {
* 获取所有的规格
*/
@GetMapping("/list")
public ResponseEntity<List<ProdProp>> list() {
public ServerResponseEntity<List<ProdProp>> list() {
List<ProdProp> list = prodPropService.list(new LambdaQueryWrapper<ProdProp>().eq(ProdProp::getRule, ProdPropRule.SPEC.value()).eq(ProdProp::getShopId, SecurityUtils.getSysUser().getShopId()));
return ResponseEntity.ok(list);
return ServerResponseEntity.success(list);
}
/**
* 根据规格id获取规格值
*/
@GetMapping("/listSpecValue/{specId}")
public ResponseEntity<List<ProdPropValue>> listSpecValue(@PathVariable("specId") Long specId) {
public ServerResponseEntity<List<ProdPropValue>> listSpecValue(@PathVariable("specId") Long specId) {
List<ProdPropValue> list = prodPropValueService.list(new LambdaQueryWrapper<ProdPropValue>().eq(ProdPropValue::getPropId, specId));
return ResponseEntity.ok(list);
return ServerResponseEntity.success(list);
}
/**
@ -79,11 +79,11 @@ public class SpecController {
*/
@PostMapping
@PreAuthorize("@pms.hasPermission('prod:spec:save')")
public ResponseEntity<Void> save(@Valid @RequestBody ProdProp prodProp) {
public ServerResponseEntity<Void> save(@Valid @RequestBody ProdProp prodProp) {
prodProp.setRule(ProdPropRule.SPEC.value());
prodProp.setShopId(SecurityUtils.getSysUser().getShopId());
prodPropService.saveProdPropAndValues(prodProp);
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
/**
@ -91,7 +91,7 @@ public class SpecController {
*/
@PutMapping
@PreAuthorize("@pms.hasPermission('prod:spec:update')")
public ResponseEntity<Void> update(@Valid @RequestBody ProdProp prodProp) {
public ServerResponseEntity<Void> update(@Valid @RequestBody ProdProp prodProp) {
ProdProp dbProdProp = prodPropService.getById(prodProp.getPropId());
if (!Objects.equals(dbProdProp.getShopId(), SecurityUtils.getSysUser().getShopId())) {
throw new YamiShopBindException("没有权限获取该商品规格信息");
@ -99,7 +99,7 @@ public class SpecController {
prodProp.setRule(ProdPropRule.SPEC.value());
prodProp.setShopId(SecurityUtils.getSysUser().getShopId());
prodPropService.updateProdPropAndValues(prodProp);
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
/**
@ -107,19 +107,19 @@ public class SpecController {
*/
@DeleteMapping("/{id}")
@PreAuthorize("@pms.hasPermission('prod:spec:delete')")
public ResponseEntity<Void> delete(@PathVariable Long id) {
public ServerResponseEntity<Void> delete(@PathVariable Long id) {
prodPropService.deleteProdPropAndValues(id, ProdPropRule.SPEC.value(), SecurityUtils.getSysUser().getShopId());
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
/**
* 根据获取规格值最大的自增id
*/
@GetMapping("/listSpecMaxValueId")
public ResponseEntity<Long> listSpecMaxValueId() {
public ServerResponseEntity<Long> listSpecMaxValueId() {
ProdPropValue propValue = prodPropValueService.getOne(new LambdaQueryWrapper<ProdPropValue>()
.orderByDesc(ProdPropValue::getValueId).last("limit 1"));
return ResponseEntity.ok(Objects.isNull(propValue) ? 0L : propValue.getValueId());
return ServerResponseEntity.success(Objects.isNull(propValue) ? 0L : propValue.getValueId());
}
}

View File

@ -18,7 +18,7 @@ import com.yami.shop.security.admin.util.SecurityUtils;
import com.yami.shop.service.TransportService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
@ -41,13 +41,13 @@ public class TransportController {
*/
@GetMapping("/page")
@PreAuthorize("@pms.hasPermission('shop:transport:page')")
public ResponseEntity<IPage<Transport>> page(Transport transport,PageParam<Transport> page) {
public ServerResponseEntity<IPage<Transport>> page(Transport transport,PageParam<Transport> page) {
Long shopId = SecurityUtils.getSysUser().getShopId();
IPage<Transport> transports = transportService.page(page,
new LambdaQueryWrapper<Transport>()
.eq(Transport::getShopId, shopId)
.like(StringUtils.isNotBlank(transport.getTransName()), Transport::getTransName, transport.getTransName()));
return ResponseEntity.ok(transports);
return ServerResponseEntity.success(transports);
}
/**
@ -55,9 +55,9 @@ public class TransportController {
*/
@GetMapping("/info/{id}")
@PreAuthorize("@pms.hasPermission('shop:transport:info')")
public ResponseEntity<Transport> info(@PathVariable("id") Long id) {
public ServerResponseEntity<Transport> info(@PathVariable("id") Long id) {
Transport transport = transportService.getTransportAndAllItems(id);
return ResponseEntity.ok(transport);
return ServerResponseEntity.success(transport);
}
/**
@ -65,13 +65,13 @@ public class TransportController {
*/
@PostMapping
@PreAuthorize("@pms.hasPermission('shop:transport:save')")
public ResponseEntity<Void> save(@RequestBody Transport transport) {
public ServerResponseEntity<Void> save(@RequestBody Transport transport) {
Long shopId = SecurityUtils.getSysUser().getShopId();
transport.setShopId(shopId);
Date createTime = new Date();
transport.setCreateTime(createTime);
transportService.insertTransportAndTransfee(transport);
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
/**
@ -79,9 +79,9 @@ public class TransportController {
*/
@PutMapping
@PreAuthorize("@pms.hasPermission('shop:transport:update')")
public ResponseEntity<Void> update(@RequestBody Transport transport) {
public ServerResponseEntity<Void> update(@RequestBody Transport transport) {
transportService.updateTransportAndTransfee(transport);
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
/**
@ -89,13 +89,13 @@ public class TransportController {
*/
@DeleteMapping
@PreAuthorize("@pms.hasPermission('shop:transport:delete')")
public ResponseEntity<Void> delete(@RequestBody Long[] ids) {
public ServerResponseEntity<Void> delete(@RequestBody Long[] ids) {
transportService.deleteTransportAndTransfeeAndTranscity(ids);
// 删除运费模板的缓存
for (Long id : ids) {
transportService.removeTransportAndAllItemsCache(id);
}
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
@ -103,10 +103,10 @@ public class TransportController {
* 获取运费模板列表
*/
@GetMapping("/list")
public ResponseEntity<List<Transport>> list() {
public ServerResponseEntity<List<Transport>> list() {
Long shopId = SecurityUtils.getSysUser().getShopId();
List<Transport> list = transportService.list(new LambdaQueryWrapper<Transport>().eq(Transport::getShopId, shopId));
return ResponseEntity.ok(list);
return ServerResponseEntity.success(list);
}
}

View File

@ -17,7 +17,7 @@ import com.yami.shop.bean.model.UserAddr;
import com.yami.shop.common.annotation.SysLog;
import com.yami.shop.service.UserAddrService;
import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
@ -44,8 +44,8 @@ public class UserAddrController {
* @return 分页数据
*/
@GetMapping("/page")
public ResponseEntity<IPage<UserAddr>> getUserAddrPage(PageParam page, UserAddr userAddr) {
return ResponseEntity.ok(userAddrService.page(page, new LambdaQueryWrapper<UserAddr>()));
public ServerResponseEntity<IPage<UserAddr>> getUserAddrPage(PageParam page, UserAddr userAddr) {
return ServerResponseEntity.success(userAddrService.page(page, new LambdaQueryWrapper<UserAddr>()));
}
@ -56,8 +56,8 @@ public class UserAddrController {
* @return 单个数据
*/
@GetMapping("/info/{addrId}")
public ResponseEntity<UserAddr> getById(@PathVariable("addrId") Long addrId) {
return ResponseEntity.ok(userAddrService.getById(addrId));
public ServerResponseEntity<UserAddr> getById(@PathVariable("addrId") Long addrId) {
return ServerResponseEntity.success(userAddrService.getById(addrId));
}
/**
@ -69,8 +69,8 @@ public class UserAddrController {
@SysLog("新增用户地址管理")
@PostMapping
@PreAuthorize("@pms.hasPermission('user:addr:save')")
public ResponseEntity<Boolean> save(@RequestBody @Valid UserAddr userAddr) {
return ResponseEntity.ok(userAddrService.save(userAddr));
public ServerResponseEntity<Boolean> save(@RequestBody @Valid UserAddr userAddr) {
return ServerResponseEntity.success(userAddrService.save(userAddr));
}
/**
@ -82,8 +82,8 @@ public class UserAddrController {
@SysLog("修改用户地址管理")
@PutMapping
@PreAuthorize("@pms.hasPermission('user:addr:update')")
public ResponseEntity<Boolean> updateById(@RequestBody @Valid UserAddr userAddr) {
return ResponseEntity.ok(userAddrService.updateById(userAddr));
public ServerResponseEntity<Boolean> updateById(@RequestBody @Valid UserAddr userAddr) {
return ServerResponseEntity.success(userAddrService.updateById(userAddr));
}
/**
@ -95,8 +95,8 @@ public class UserAddrController {
@SysLog("删除用户地址管理")
@DeleteMapping("/{addrId}")
@PreAuthorize("@pms.hasPermission('user:addr:delete')")
public ResponseEntity<Boolean> removeById(@PathVariable Long addrId) {
return ResponseEntity.ok(userAddrService.removeById(addrId));
public ServerResponseEntity<Boolean> removeById(@PathVariable Long addrId) {
return ServerResponseEntity.success(userAddrService.removeById(addrId));
}
}

View File

@ -17,7 +17,7 @@ import com.yami.shop.bean.model.User;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
@ -40,14 +40,14 @@ public class UserController {
*/
@GetMapping("/page")
@PreAuthorize("@pms.hasPermission('admin:user:page')")
public ResponseEntity<IPage<User>> page(User user,PageParam<User> page) {
public ServerResponseEntity<IPage<User>> page(User user,PageParam<User> page) {
IPage<User> userPage = userService.page(page, new LambdaQueryWrapper<User>()
.like(StrUtil.isNotBlank(user.getNickName()), User::getNickName, user.getNickName())
.eq(user.getStatus() != null, User::getStatus, user.getStatus()));
for (User userResult : userPage.getRecords()) {
userResult.setNickName(userResult.getNickName() == null ? "" : userResult.getNickName());
}
return ResponseEntity.ok(userPage);
return ServerResponseEntity.success(userPage);
}
/**
@ -55,10 +55,10 @@ public class UserController {
*/
@GetMapping("/info/{userId}")
@PreAuthorize("@pms.hasPermission('admin:user:info')")
public ResponseEntity<User> info(@PathVariable("userId") String userId) {
public ServerResponseEntity<User> info(@PathVariable("userId") String userId) {
User user = userService.getById(userId);
user.setNickName(user.getNickName() == null ? "" : user.getNickName());
return ResponseEntity.ok(user);
return ServerResponseEntity.success(user);
}
/**
@ -66,11 +66,11 @@ public class UserController {
*/
@PutMapping
@PreAuthorize("@pms.hasPermission('admin:user:update')")
public ResponseEntity<Void> update(@RequestBody User user) {
public ServerResponseEntity<Void> update(@RequestBody User user) {
user.setModifyTime(new Date());
user.setNickName(user.getNickName() == null ? "" : user.getNickName());
userService.updateById(user);
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
/**
@ -78,8 +78,8 @@ public class UserController {
*/
@DeleteMapping
@PreAuthorize("@pms.hasPermission('admin:user:delete')")
public ResponseEntity<Void> delete(@RequestBody String[] userIds) {
public ServerResponseEntity<Void> delete(@RequestBody String[] userIds) {
userService.removeByIds(Arrays.asList(userIds));
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
}

View File

@ -28,8 +28,7 @@ public class SwaggerConfiguration {
public GroupedOpenApi createRestApi() {
return GroupedOpenApi.builder()
.group("接口文档")
.packagesToScan("com.yami.shop.api")
.build();
.packagesToScan("com.yami.shop.api").build();
}

View File

@ -15,15 +15,15 @@ import com.yami.shop.bean.app.dto.UserAddrDto;
import com.yami.shop.bean.app.param.AddrParam;
import com.yami.shop.bean.model.UserAddr;
import com.yami.shop.common.exception.YamiShopBindException;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.security.api.util.SecurityUtils;
import com.yami.shop.service.UserAddrService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import ma.glasnost.orika.MapperFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
@ -49,19 +49,19 @@ public class AddrController {
*/
@GetMapping("/list")
@Operation(summary = "用户地址列表" , description = "获取用户的所有地址信息")
public ResponseEntity<List<UserAddrDto>> dvyList() {
public ServerResponseEntity<List<UserAddrDto>> dvyList() {
String userId = SecurityUtils.getUser().getUserId();
List<UserAddr> userAddrs = userAddrService.list(new LambdaQueryWrapper<UserAddr>().eq(UserAddr::getUserId, userId).orderByDesc(UserAddr::getCommonAddr).orderByDesc(UserAddr::getUpdateTime));
return ResponseEntity.ok(mapperFacade.mapAsList(userAddrs, UserAddrDto.class));
return ServerResponseEntity.success(mapperFacade.mapAsList(userAddrs, UserAddrDto.class));
}
@PostMapping("/addAddr")
@Operation(summary = "新增用户地址" , description = "新增用户地址")
public ResponseEntity<String> addAddr(@Valid @RequestBody AddrParam addrParam) {
public ServerResponseEntity<String> addAddr(@Valid @RequestBody AddrParam addrParam) {
String userId = SecurityUtils.getUser().getUserId();
if (addrParam.getAddrId() != null && addrParam.getAddrId() != 0) {
return ResponseEntity.badRequest().body("该地址已存在");
return ServerResponseEntity.showFailMsg("该地址已存在");
}
int addrCount = userAddrService.count(new LambdaQueryWrapper<UserAddr>().eq(UserAddr::getUserId, userId));
UserAddr userAddr = mapperFacade.map(addrParam, UserAddr.class);
@ -80,7 +80,7 @@ public class AddrController {
// 清除默认地址缓存
userAddrService.removeUserAddrByUserId(0L, userId);
}
return ResponseEntity.ok("添加地址成功");
return ServerResponseEntity.success("添加地址成功");
}
/**
@ -88,12 +88,12 @@ public class AddrController {
*/
@PutMapping("/updateAddr")
@Operation(summary = "修改订单用户地址" , description = "修改用户地址")
public ResponseEntity<String> updateAddr(@Valid @RequestBody AddrParam addrParam) {
public ServerResponseEntity<String> updateAddr(@Valid @RequestBody AddrParam addrParam) {
String userId = SecurityUtils.getUser().getUserId();
UserAddr dbUserAddr = userAddrService.getUserAddrByUserId(addrParam.getAddrId(), userId);
if (dbUserAddr == null) {
return ResponseEntity.badRequest().body("该地址已被删除");
return ServerResponseEntity.showFailMsg("该地址已被删除");
}
UserAddr userAddr = mapperFacade.map(addrParam, UserAddr.class);
@ -104,7 +104,7 @@ public class AddrController {
userAddrService.removeUserAddrByUserId(addrParam.getAddrId(), userId);
// 清除默认地址缓存
userAddrService.removeUserAddrByUserId(0L, userId);
return ResponseEntity.ok("修改地址成功");
return ServerResponseEntity.success("修改地址成功");
}
/**
@ -113,18 +113,18 @@ public class AddrController {
@DeleteMapping("/deleteAddr/{addrId}")
@Operation(summary = "删除订单用户地址" , description = "根据地址id删除用户地址")
@Parameter(name = "addrId", description = "地址ID" , required = true)
public ResponseEntity<String> deleteDvy(@PathVariable("addrId") Long addrId) {
public ServerResponseEntity<String> deleteDvy(@PathVariable("addrId") Long addrId) {
String userId = SecurityUtils.getUser().getUserId();
UserAddr userAddr = userAddrService.getUserAddrByUserId(addrId, userId);
if (userAddr == null) {
return ResponseEntity.badRequest().body("该地址已被删除");
return ServerResponseEntity.showFailMsg("该地址已被删除");
}
if (userAddr.getCommonAddr() == 1) {
return ResponseEntity.badRequest().body("默认地址无法删除");
return ServerResponseEntity.showFailMsg("默认地址无法删除");
}
userAddrService.removeById(addrId);
userAddrService.removeUserAddrByUserId(addrId, userId);
return ResponseEntity.ok("删除地址成功");
return ServerResponseEntity.success("删除地址成功");
}
/**
@ -132,14 +132,14 @@ public class AddrController {
*/
@PutMapping("/defaultAddr/{addrId}")
@Operation(summary = "设置默认地址" , description = "根据地址id设置默认地址")
public ResponseEntity<String> defaultAddr(@PathVariable("addrId") Long addrId) {
public ServerResponseEntity<String> defaultAddr(@PathVariable("addrId") Long addrId) {
String userId = SecurityUtils.getUser().getUserId();
userAddrService.updateDefaultUserAddr(addrId, userId);
userAddrService.removeUserAddrByUserId(0L, userId);
userAddrService.removeUserAddrByUserId(addrId, userId);
return ResponseEntity.ok("修改地址成功");
return ServerResponseEntity.success("修改地址成功");
}
/**
@ -148,13 +148,13 @@ public class AddrController {
@GetMapping("/addrInfo/{addrId}")
@Operation(summary = "获取地址信息" , description = "根据地址id获取地址信息")
@Parameter(name = "addrId", description = "地址ID" , required = true)
public ResponseEntity<UserAddrDto> addrInfo(@PathVariable("addrId") Long addrId) {
public ServerResponseEntity<UserAddrDto> addrInfo(@PathVariable("addrId") Long addrId) {
String userId = SecurityUtils.getUser().getUserId();
UserAddr userAddr = userAddrService.getUserAddrByUserId(addrId, userId);
if (userAddr == null) {
throw new YamiShopBindException("该地址已被删除");
}
return ResponseEntity.ok(mapperFacade.map(userAddr, UserAddrDto.class));
return ServerResponseEntity.success(mapperFacade.map(userAddr, UserAddrDto.class));
}
}

View File

@ -14,7 +14,7 @@ import java.util.List;
import com.yami.shop.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@ -43,9 +43,9 @@ public class AreaController {
@GetMapping("/listByPid")
@Operation(summary = "获取省市区信息" , description = "根据省市区的pid获取地址信息")
@Parameter(name = "pid", description = "省市区的pid(pid为0获取所有省份)" , required = true)
public ResponseEntity<List<Area>> listByPid(Long pid){
public ServerResponseEntity<List<Area>> listByPid(Long pid){
List<Area> list = areaService.listByPid(pid);
return ResponseEntity.ok(list);
return ServerResponseEntity.success(list);
}
}

View File

@ -13,7 +13,7 @@ package com.yami.shop.api.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@ -48,10 +48,10 @@ public class CategoryController {
@GetMapping("/categoryInfo")
@Operation(summary = "分类信息列表" , description = "获取所有的产品分类信息顶级分类的parentId为0,默认为顶级分类")
@Parameter(name = "parentId", description = "分类ID", required = false)
public ResponseEntity<List<CategoryDto>> categoryInfo(@RequestParam(value = "parentId", defaultValue = "0") Long parentId) {
public ServerResponseEntity<List<CategoryDto>> categoryInfo(@RequestParam(value = "parentId", defaultValue = "0") Long parentId) {
List<Category> categories = categoryService.listByParentId(parentId);
List<CategoryDto> categoryDtos = mapperFacade.mapAsList(categories, CategoryDto.class);
return ResponseEntity.ok(categoryDtos);
return ServerResponseEntity.success(categoryDtos);
}

View File

@ -12,7 +12,7 @@ package com.yami.shop.api.controller;
import com.yami.shop.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@ -47,7 +47,7 @@ public class DeliveryController {
@GetMapping("/check")
@Operation(summary = "查看物流" , description = "根据订单号查看物流")
@Parameter(name = "orderNumber", description = "订单号" , required = true)
public ResponseEntity<DeliveryDto> checkDelivery(String orderNumber) {
public ServerResponseEntity<DeliveryDto> checkDelivery(String orderNumber) {
Order order = orderService.getOrderByOrderNumber(orderNumber);
Delivery delivery = deliveryService.getById(order.getDvyId());
@ -58,6 +58,6 @@ public class DeliveryController {
deliveryDto.setDvyFlowId(order.getDvyFlowId());
deliveryDto.setCompanyHomeUrl(delivery.getCompanyHomeUrl());
deliveryDto.setCompanyName(delivery.getDvyName());
return ResponseEntity.ok(deliveryDto);
return ServerResponseEntity.success(deliveryDto);
}
}

View File

@ -17,7 +17,7 @@ import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import ma.glasnost.orika.MapperFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@ -40,9 +40,9 @@ public class IndexImgController {
*/
@GetMapping("/indexImgs")
@Operation(summary = "首页轮播图" , description = "获取首页轮播图列表信息")
public ResponseEntity<List<IndexImgDto>> indexImgs() {
public ServerResponseEntity<List<IndexImgDto>> indexImgs() {
List<IndexImg> indexImgList = indexImgService.listIndexImg();
List<IndexImgDto> indexImgDtos = mapperFacade.mapAsList(indexImgList, IndexImgDto.class);
return ResponseEntity.ok(indexImgDtos);
return ServerResponseEntity.success(indexImgDtos);
}
}

View File

@ -28,7 +28,7 @@ import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.Operation;
import lombok.AllArgsConstructor;
import ma.glasnost.orika.MapperFacade;
import org.springframework.http.ResponseEntity;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
@ -67,7 +67,7 @@ public class MyOrderController {
@GetMapping("/orderDetail")
@Operation(summary = "订单详情信息" , description = "根据订单号获取订单详情信息")
@Parameter(name = "orderNumber", description = "订单号" , required = true)
public ResponseEntity<OrderShopDto> orderDetail(@RequestParam(value = "orderNumber", required = true) String orderNumber) {
public ServerResponseEntity<OrderShopDto> orderDetail(@RequestParam(value = "orderNumber", required = true) String orderNumber) {
String userId = SecurityUtils.getUser().getUserId();
OrderShopDto orderShopDto = new OrderShopDto();
@ -107,7 +107,7 @@ public class MyOrderController {
orderShopDto.setTotal(total);
orderShopDto.setTotalNum(totalNum);
return ResponseEntity.ok(orderShopDto);
return ServerResponseEntity.success(orderShopDto);
}
@ -119,11 +119,11 @@ public class MyOrderController {
@Parameters({
@Parameter(name = "status", description = "订单状态 1:待付款 2:待发货 3:待收货 4:待评价 5:成功 6:失败")
})
public ResponseEntity<IPage<MyOrderDto>> myOrder(@RequestParam(value = "status") Integer status,PageParam<MyOrderDto> page) {
public ServerResponseEntity<IPage<MyOrderDto>> myOrder(@RequestParam(value = "status") Integer status,PageParam<MyOrderDto> page) {
String userId = SecurityUtils.getUser().getUserId();
IPage<MyOrderDto> myOrderDtoIpage = myOrderService.pageMyOrderByUserIdAndStatus(page, userId, status);
return ResponseEntity.ok(myOrderDtoIpage);
return ServerResponseEntity.success(myOrderDtoIpage);
}
/**
@ -132,7 +132,7 @@ public class MyOrderController {
@PutMapping("/cancel/{orderNumber}")
@Operation(summary = "根据订单号取消订单" , description = "根据订单号取消订单")
@Parameter(name = "orderNumber", description = "订单号" , required = true)
public ResponseEntity<String> cancel(@PathVariable("orderNumber") String orderNumber) {
public ServerResponseEntity<String> cancel(@PathVariable("orderNumber") String orderNumber) {
String userId = SecurityUtils.getUser().getUserId();
Order order = orderService.getOrderByOrderNumber(orderNumber);
if (!Objects.equals(order.getUserId(), userId)) {
@ -151,7 +151,7 @@ public class MyOrderController {
productService.removeProductCacheByProdId(orderItem.getProdId());
skuService.removeSkuCacheBySkuId(orderItem.getSkuId(),orderItem.getProdId());
}
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
@ -160,7 +160,7 @@ public class MyOrderController {
*/
@PutMapping("/receipt/{orderNumber}")
@Operation(summary = "根据订单号确认收货" , description = "根据订单号确认收货")
public ResponseEntity<String> receipt(@PathVariable("orderNumber") String orderNumber) {
public ServerResponseEntity<String> receipt(@PathVariable("orderNumber") String orderNumber) {
String userId = SecurityUtils.getUser().getUserId();
Order order = orderService.getOrderByOrderNumber(orderNumber);
if (!Objects.equals(order.getUserId(), userId)) {
@ -178,7 +178,7 @@ public class MyOrderController {
productService.removeProductCacheByProdId(orderItem.getProdId());
skuService.removeSkuCacheBySkuId(orderItem.getSkuId(),orderItem.getProdId());
}
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
/**
@ -187,7 +187,7 @@ public class MyOrderController {
@DeleteMapping("/{orderNumber}")
@Operation(summary = "根据订单号删除订单" , description = "根据订单号删除订单")
@Parameter(name = "orderNumber", description = "订单号" , required = true)
public ResponseEntity<String> delete(@PathVariable("orderNumber") String orderNumber) {
public ServerResponseEntity<String> delete(@PathVariable("orderNumber") String orderNumber) {
String userId = SecurityUtils.getUser().getUserId();
Order order = orderService.getOrderByOrderNumber(orderNumber);
@ -204,7 +204,7 @@ public class MyOrderController {
// 删除订单
orderService.deleteOrders(Arrays.asList(order));
return ResponseEntity.ok("删除成功");
return ServerResponseEntity.success("删除成功");
}
/**
@ -212,10 +212,10 @@ public class MyOrderController {
*/
@GetMapping("/orderCount")
@Operation(summary = "获取我的订单订单数量" , description = "获取我的订单订单数量")
public ResponseEntity<OrderCountData> getOrderCount() {
public ServerResponseEntity<OrderCountData> getOrderCount() {
String userId = SecurityUtils.getUser().getUserId();
OrderCountData orderCountMap = orderService.getOrderCount(userId);
return ResponseEntity.ok(orderCountMap);
return ServerResponseEntity.success(orderCountMap);
}

View File

@ -21,7 +21,7 @@ import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.Operation;
import lombok.AllArgsConstructor;
import ma.glasnost.orika.MapperFacade;
import org.springframework.http.ResponseEntity;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
@ -48,10 +48,10 @@ public class NoticeController {
@GetMapping("/topNoticeList")
@Operation(summary = "置顶公告列表信息" , description = "获取所有置顶公告列表信息")
@JsonView(NoticeDto.NoContent.class)
public ResponseEntity<List<NoticeDto>> getTopNoticeList() {
public ServerResponseEntity<List<NoticeDto>> getTopNoticeList() {
List<Notice> noticeList = noticeService.listNotice();
List<NoticeDto> noticeDtoList = mapperFacade.mapAsList(noticeList, NoticeDto.class);
return ResponseEntity.ok(noticeDtoList);
return ServerResponseEntity.success(noticeDtoList);
}
/**
@ -60,10 +60,10 @@ public class NoticeController {
@GetMapping("/info/{id}")
@Operation(summary = "公告详情" , description = "获取公告id公告详情")
@JsonView(NoticeDto.WithContent.class)
public ResponseEntity<NoticeDto> getNoticeById(@PathVariable("id") Long id) {
public ServerResponseEntity<NoticeDto> getNoticeById(@PathVariable("id") Long id) {
Notice notice = noticeService.getNoticeById(id);
NoticeDto noticeDto = mapperFacade.map(notice, NoticeDto.class);
return ResponseEntity.ok(noticeDto);
return ServerResponseEntity.success(noticeDto);
}
/**
@ -73,8 +73,8 @@ public class NoticeController {
@Operation(summary = "公告列表信息" , description = "获取所有公告列表信息")
@Parameters({
})
public ResponseEntity<IPage<NoticeDto>> pageNotice(PageParam<NoticeDto> page) {
public ServerResponseEntity<IPage<NoticeDto>> pageNotice(PageParam<NoticeDto> page) {
return ResponseEntity.ok(noticeService.pageNotice(page));
return ServerResponseEntity.success(noticeService.pageNotice(page));
}
}

View File

@ -27,7 +27,7 @@ import io.swagger.v3.oas.annotations.Operation;
import ma.glasnost.orika.MapperFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.http.ResponseEntity;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
@ -67,7 +67,7 @@ public class OrderController {
*/
@PostMapping("/confirm")
@Operation(summary = "结算,生成订单信息" , description = "传入下单所需要的参数进行下单")
public ResponseEntity<ShopCartOrderMergerDto> confirm(@Valid @RequestBody OrderParam orderParam) {
public ServerResponseEntity<ShopCartOrderMergerDto> confirm(@Valid @RequestBody OrderParam orderParam) {
String userId = SecurityUtils.getUser().getUserId();
// 订单的地址信息
@ -135,7 +135,7 @@ public class OrderController {
shopCartOrderMergerDto = orderService.putConfirmOrderCache(userId, shopCartOrderMergerDto);
return ResponseEntity.ok(shopCartOrderMergerDto);
return ServerResponseEntity.success(shopCartOrderMergerDto);
}
/**
@ -143,7 +143,7 @@ public class OrderController {
*/
@PostMapping("/submit")
@Operation(summary = "提交订单,返回支付流水号" , description = "根据传入的参数判断是否为购物车提交订单,同时对购物车进行删除,用户开始进行支付")
public ResponseEntity<OrderNumbersDto> submitOrders(@Valid @RequestBody SubmitOrderParam submitOrderParam) {
public ServerResponseEntity<OrderNumbersDto> submitOrders(@Valid @RequestBody SubmitOrderParam submitOrderParam) {
String userId = SecurityUtils.getUser().getUserId();
ShopCartOrderMergerDto mergerOrder = orderService.getConfirmOrderCache(userId);
if (mergerOrder == null) {
@ -193,7 +193,7 @@ public class OrderController {
basketService.removeShopCartItemsCacheByUserId(userId);
}
orderService.removeConfirmOrderCache(userId);
return ResponseEntity.ok(new OrderNumbersDto(orderNumbers.toString()));
return ServerResponseEntity.success(new OrderNumbersDto(orderNumbers.toString()));
}
}

View File

@ -20,7 +20,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.AllArgsConstructor;
import lombok.SneakyThrows;
import org.springframework.http.ResponseEntity;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
@ -42,14 +42,14 @@ public class PayController {
*/
@PostMapping("/pay")
@Operation(summary = "根据订单号进行支付" , description = "根据订单号进行支付")
public ResponseEntity<WxPayMpOrderResult> pay(@RequestBody PayParam payParam) {
public ServerResponseEntity<WxPayMpOrderResult> pay(@RequestBody PayParam payParam) {
YamiUser user = SecurityUtils.getUser();
String userId = user.getUserId();
PayInfoDto payInfo = payService.pay(userId, payParam);
payService.paySuccess(payInfo.getPayNo(), "");
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
/**
@ -57,7 +57,7 @@ public class PayController {
*/
@PostMapping("/normalPay")
@Operation(summary = "根据订单号进行支付" , description = "根据订单号进行支付")
public ResponseEntity<Boolean> normalPay(@RequestBody PayParam payParam) {
public ServerResponseEntity<Boolean> normalPay(@RequestBody PayParam payParam) {
YamiUser user = SecurityUtils.getUser();
String userId = user.getUserId();
@ -66,6 +66,6 @@ public class PayController {
// 根据内部订单号更新order settlement
payService.paySuccess(pay.getPayNo(), "");
return ResponseEntity.ok(true);
return ServerResponseEntity.success(true);
}
}

View File

@ -33,7 +33,7 @@ public class PayNoticeController {
//
//
// @RequestMapping("/order")
// public ResponseEntity<Void> submit(@RequestBody String xmlData) throws WxPayException {
// public ServerResponseEntity<Void> submit(@RequestBody String xmlData) throws WxPayException {
// WxPayOrderNotifyResult parseOrderNotifyResult = wxMiniPayService.parseOrderNotifyResult(xmlData);
//
// String payNo = parseOrderNotifyResult.getOutTradeNo();
@ -43,6 +43,6 @@ public class PayNoticeController {
// payService.paySuccess(payNo, bizPayNo);
//
//
// return ResponseEntity.ok().build();
// return ServerResponseEntity.success();
// }
}

View File

@ -24,7 +24,7 @@ import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.Operation;
import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
@ -43,14 +43,14 @@ public class ProdCommController {
@GetMapping("/prodCommData")
@Operation(summary = "返回商品评论数据(好评率 好评数量 中评数 差评数)" , description = "根据商品id获取")
public ResponseEntity<ProdCommDataDto> getProdCommData(Long prodId) {
return ResponseEntity.ok(prodCommService.getProdCommDataByProdId(prodId));
public ServerResponseEntity<ProdCommDataDto> getProdCommData(Long prodId) {
return ServerResponseEntity.success(prodCommService.getProdCommDataByProdId(prodId));
}
@GetMapping("/prodCommPageByUser")
@Operation(summary = "根据用户返回评论分页数据" , description = "传入页码")
public ResponseEntity<IPage<ProdCommDto>> getProdCommPage(PageParam page) {
return ResponseEntity.ok(prodCommService.getProdCommDtoPageByUserId(page, SecurityUtils.getUser().getUserId()));
public ServerResponseEntity<IPage<ProdCommDto>> getProdCommPage(PageParam page) {
return ServerResponseEntity.success(prodCommService.getProdCommDtoPageByUserId(page, SecurityUtils.getUser().getUserId()));
}
@GetMapping("/prodCommPageByProd")
@ -59,13 +59,13 @@ public class ProdCommController {
@Parameter(name = "prodId", description = "商品id" , required = true),
@Parameter(name = "evaluate", description = "-1或null 全部0好评 1中评 2差评 3有图" , required = true),
})
public ResponseEntity<IPage<ProdCommDto>> getProdCommPageByProdId(PageParam page, Long prodId, Integer evaluate) {
return ResponseEntity.ok(prodCommService.getProdCommDtoPageByProdId(page, prodId, evaluate));
public ServerResponseEntity<IPage<ProdCommDto>> getProdCommPageByProdId(PageParam page, Long prodId, Integer evaluate) {
return ServerResponseEntity.success(prodCommService.getProdCommDtoPageByProdId(page, prodId, evaluate));
}
@PostMapping
@Operation(summary = "添加评论")
public ResponseEntity<Void> saveProdCommPage(ProdCommParam prodCommParam) {
public ServerResponseEntity<Void> saveProdCommPage(ProdCommParam prodCommParam) {
ProdComm prodComm = new ProdComm();
prodComm.setProdId(prodCommParam.getProdId());
prodComm.setOrderItemId(prodCommParam.getOrderItemId());
@ -78,13 +78,13 @@ public class ProdCommController {
prodComm.setStatus(0);
prodComm.setEvaluate(prodCommParam.getEvaluate());
prodCommService.save(prodComm);
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
@DeleteMapping
@Operation(summary = "删除评论" , description = "根据id删除")
public ResponseEntity<Void> deleteProdComm(Long prodCommId) {
public ServerResponseEntity<Void> deleteProdComm(Long prodCommId) {
prodCommService.removeById(prodCommId);
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
}

View File

@ -16,18 +16,18 @@ import com.yami.shop.bean.app.dto.TagProductDto;
import com.yami.shop.bean.model.Product;
import com.yami.shop.bean.model.Sku;
import com.yami.shop.bean.model.Transport;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.common.util.Json;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.service.ProductService;
import com.yami.shop.service.SkuService;
import com.yami.shop.service.TransportService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import ma.glasnost.orika.MapperFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
@ -62,20 +62,20 @@ public class ProdController {
@Parameters({
@Parameter(name = "categoryId", description = "分类ID" , required = true),
})
public ResponseEntity<IPage<ProductDto>> prodList(
public ServerResponseEntity<IPage<ProductDto>> prodList(
@RequestParam(value = "categoryId") Long categoryId,PageParam<ProductDto> page) {
IPage<ProductDto> productPage = prodService.pageByCategoryId(page, categoryId);
return ResponseEntity.ok(productPage);
return ServerResponseEntity.success(productPage);
}
@GetMapping("/prodInfo")
@Operation(summary = "商品详情信息" , description = "根据商品IDprodId获取商品信息")
@Parameter(name = "prodId", description = "商品ID" , required = true)
public ResponseEntity<ProductDto> prodInfo(Long prodId) {
public ServerResponseEntity<ProductDto> prodInfo(Long prodId) {
Product product = prodService.getProductByProdId(prodId);
if (product == null) {
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
List<Sku> skuList = skuService.listByProdId(prodId);
@ -93,16 +93,16 @@ public class ProdController {
productDto.setTransport(transportAndAllItems);
}
return ResponseEntity.ok(productDto);
return ServerResponseEntity.success(productDto);
}
@GetMapping("/lastedProdPage")
@Operation(summary = "新品推荐" , description = "获取新品推荐商品列表")
@Parameters({
})
public ResponseEntity<IPage<ProductDto>> lastedProdPage(PageParam<ProductDto> page) {
public ServerResponseEntity<IPage<ProductDto>> lastedProdPage(PageParam<ProductDto> page) {
IPage<ProductDto> productPage = prodService.pageByPutAwayTime(page);
return ResponseEntity.ok(productPage);
return ServerResponseEntity.success(productPage);
}
@GetMapping("/prodListByTagId")
@ -110,27 +110,24 @@ public class ProdController {
@Parameters({
@Parameter(name = "tagId", description = "当前页默认为1" , required = true),
})
public ResponseEntity<IPage<ProductDto>> prodListByTagId(
public ServerResponseEntity<IPage<ProductDto>> prodListByTagId(
@RequestParam(value = "tagId") Long tagId,PageParam<ProductDto> page) {
IPage<ProductDto> productPage = prodService.pageByTagId(page, tagId);
return ResponseEntity.ok(productPage);
return ServerResponseEntity.success(productPage);
}
@GetMapping("/moreBuyProdList")
@Operation(summary = "每日疯抢" , description = "获取销量最多的商品列表")
@Parameters({})
public ResponseEntity<IPage<ProductDto>> moreBuyProdList(PageParam<ProductDto> page) {
public ServerResponseEntity<IPage<ProductDto>> moreBuyProdList(PageParam<ProductDto> page) {
IPage<ProductDto> productPage = prodService.moreBuyProdList(page);
return ResponseEntity.ok(productPage);
return ServerResponseEntity.success(productPage);
}
@GetMapping("/tagProdList")
@Operation(summary = "首页所有标签商品接口" , description = "获取首页所有标签商品接口")
public ResponseEntity<List<TagProductDto>> getTagProdList() {
public ServerResponseEntity<List<TagProductDto>> getTagProdList() {
List<TagProductDto> productDtoList = prodService.tagProdList();
return ResponseEntity.ok(productDtoList);
return ServerResponseEntity.success(productDtoList);
}
}

View File

@ -17,7 +17,7 @@ import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import ma.glasnost.orika.MapperFacade;
import org.springframework.http.ResponseEntity;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@ -42,10 +42,10 @@ public class ProdTagController {
*/
@GetMapping("/prodTagList")
@Operation(summary = "商品分组标签列表" , description = "获取所有的商品分组列表")
public ResponseEntity<List<ProdTagDto>> getProdTagList() {
public ServerResponseEntity<List<ProdTagDto>> getProdTagList() {
List<ProdTag> prodTagList = prodTagService.listProdTag();
List<ProdTagDto> prodTagDtoList = mapperFacade.mapAsList(prodTagList, ProdTagDto.class);
return ResponseEntity.ok(prodTagDtoList);
return ServerResponseEntity.success(prodTagDtoList);
}
}

View File

@ -23,7 +23,7 @@ import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.Operation;
import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@ -51,7 +51,7 @@ public class SearchController {
@Parameter(name = "number", description = "取数" , required = true),
@Parameter(name = "sort", description = "是否按照顺序(0 否 1是)"),
})
public ResponseEntity<List<HotSearchDto>> hotSearchByShopId(Long shopId,Integer number,Integer sort) {
public ServerResponseEntity<List<HotSearchDto>> hotSearchByShopId(Long shopId,Integer number,Integer sort) {
List<HotSearchDto> list = hotSearchService.getHotSearchDtoByShopId(shopId);
return getListResponseEntity(number, sort, list);
@ -63,19 +63,19 @@ public class SearchController {
@Parameter(name = "number", description = "取数" , required = true),
@Parameter(name = "sort", description = "是否按照顺序(0 否 1是)", required = false ),
})
public ResponseEntity<List<HotSearchDto>> hotSearch(Integer number,Integer sort) {
public ServerResponseEntity<List<HotSearchDto>> hotSearch(Integer number,Integer sort) {
List<HotSearchDto> list = hotSearchService.getHotSearchDtoByShopId(0L);
return getListResponseEntity(number, sort, list);
}
private ResponseEntity<List<HotSearchDto>> getListResponseEntity(Integer number, Integer sort, List<HotSearchDto> list) {
private ServerResponseEntity<List<HotSearchDto>> getListResponseEntity(Integer number, Integer sort, List<HotSearchDto> list) {
if(sort == null || sort == 0){
Collections.shuffle(list);
}
if(!CollectionUtil.isNotEmpty(list) || list.size()< number){
return ResponseEntity.ok(list);
return ServerResponseEntity.success(list);
}
return ResponseEntity.ok(list.subList(0, number));
return ServerResponseEntity.success(list.subList(0, number));
}
@GetMapping("/searchProdPage")
@ -86,9 +86,9 @@ public class SearchController {
@Parameter(name = "orderBy", description = "排序(0升序 1降序)"),
@Parameter(name = "shopId", description = "店铺id" , required = true),
})
public ResponseEntity<IPage<SearchProdDto>> searchProdPage(PageParam page, String prodName, Integer sort, Integer orderBy, Long shopId) {
public ServerResponseEntity<IPage<SearchProdDto>> searchProdPage(PageParam page, String prodName, Integer sort, Integer orderBy, Long shopId) {
return ResponseEntity.ok(productService.getSearchProdDtoPageByProdName(page,prodName,sort,orderBy));
return ServerResponseEntity.success(productService.getSearchProdDtoPageByProdName(page,prodName,sort,orderBy));
}

View File

@ -29,7 +29,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.AllArgsConstructor;
import org.springframework.context.ApplicationContext;
import org.springframework.http.ResponseEntity;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
@ -64,7 +64,7 @@ public class ShopCartController {
*/
@PostMapping("/info")
@Operation(summary = "获取用户购物车信息" , description = "获取用户购物车信息,参数为用户选中的活动项数组,以购物车id为key")
public ResponseEntity<List<ShopCartDto>> info(@RequestBody Map<Long, ShopCartParam> basketIdShopCartParamMap) {
public ServerResponseEntity<List<ShopCartDto>> info(@RequestBody Map<Long, ShopCartParam> basketIdShopCartParamMap) {
String userId = SecurityUtils.getUser().getUserId();
// 更新购物车信息
@ -74,33 +74,33 @@ public class ShopCartController {
// 拿到购物车的所有item
List<ShopCartItemDto> shopCartItems = basketService.getShopCartItems(userId);
return ResponseEntity.ok(basketService.getShopCarts(shopCartItems));
return ServerResponseEntity.success(basketService.getShopCarts(shopCartItems));
}
@DeleteMapping("/deleteItem")
@Operation(summary = "删除用户购物车物品" , description = "通过购物车id删除用户购物车物品")
public ResponseEntity<Void> deleteItem(@RequestBody List<Long> basketIds) {
public ServerResponseEntity<Void> deleteItem(@RequestBody List<Long> basketIds) {
String userId = SecurityUtils.getUser().getUserId();
basketService.deleteShopCartItemsByBasketIds(userId, basketIds);
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
@DeleteMapping("/deleteAll")
@Operation(summary = "清空用户购物车所有物品" , description = "清空用户购物车所有物品")
public ResponseEntity<String> deleteAll() {
public ServerResponseEntity<String> deleteAll() {
String userId = SecurityUtils.getUser().getUserId();
basketService.deleteAllShopCartItems(userId);
return ResponseEntity.ok("删除成功");
return ServerResponseEntity.success("删除成功");
}
@PostMapping("/changeItem")
@Operation(summary = "添加、修改用户购物车物品", description = "通过商品id(prodId)、skuId、店铺Id(shopId),添加/修改用户购物车商品,并传入改变的商品个数(count)" +
"当count为正值时增加商品数量当count为负值时将减去商品的数量当最终count值小于0时会将商品从购物车里面删除")
public ResponseEntity<String> addItem(@Valid @RequestBody ChangeShopCartParam param) {
public ServerResponseEntity<String> addItem(@Valid @RequestBody ChangeShopCartParam param) {
if (param.getCount() == 0) {
return ResponseEntity.badRequest().body("输入更改数量");
return ServerResponseEntity.showFailMsg("输入更改数量");
}
String userId = SecurityUtils.getUser().getUserId();
@ -110,7 +110,7 @@ public class ShopCartController {
// 当商品状态不正常时不能添加到购物车
if (prodParam.getStatus() != 1 || skuParam.getStatus() != 1) {
return ResponseEntity.badRequest().body("当前商品已下架");
return ServerResponseEntity.showFailMsg("当前商品已下架");
}
for (ShopCartItemDto shopCartItemDto : shopCartItems) {
if (Objects.equals(param.getSkuId(), shopCartItemDto.getSkuId())) {
@ -122,46 +122,46 @@ public class ShopCartController {
// 防止购物车变成负数
if (basket.getBasketCount() <= 0) {
basketService.deleteShopCartItemsByBasketIds(userId, Collections.singletonList(basket.getBasketId()));
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
// 当sku实际库存不足时不能添加到购物车
if (skuParam.getStocks() < basket.getBasketCount() && shopCartItemDto.getProdCount() > 0) {
return ResponseEntity.badRequest().body("库存不足");
return ServerResponseEntity.showFailMsg("库存不足");
}
basketService.updateShopCartItem(basket);
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
}
// 防止购物车已被删除的情况下,添加了负数的商品
if (param.getCount() < 0) {
return ResponseEntity.badRequest().body("商品已从购物车移除");
return ServerResponseEntity.showFailMsg("商品已从购物车移除");
}
// 当sku实际库存不足时不能添加到购物车
if (skuParam.getStocks() < param.getCount()) {
return ResponseEntity.badRequest().body("库存不足");
return ServerResponseEntity.showFailMsg("库存不足");
}
// 所有都正常时
basketService.addShopCartItem(param,userId);
return ResponseEntity.ok("添加成功");
return ServerResponseEntity.success("添加成功");
}
@GetMapping("/prodCount")
@Operation(summary = "获取购物车商品数量" , description = "获取所有购物车商品数量")
public ResponseEntity<Integer> prodCount() {
public ServerResponseEntity<Integer> prodCount() {
String userId = SecurityUtils.getUser().getUserId();
List<ShopCartItemDto> shopCartItems = basketService.getShopCartItems(userId);
if (CollectionUtil.isEmpty(shopCartItems)) {
return ResponseEntity.ok(0);
return ServerResponseEntity.success(0);
}
Integer totalCount = shopCartItems.stream().map(ShopCartItemDto::getProdCount).reduce(0, Integer::sum);
return ResponseEntity.ok(totalCount);
return ServerResponseEntity.success(totalCount);
}
@GetMapping("/expiryProdList")
@Operation(summary = "获取购物车失效商品信息" , description = "获取购物车失效商品列表")
public ResponseEntity<List<ShopCartExpiryItemDto>> expiryProdList() {
public ServerResponseEntity<List<ShopCartExpiryItemDto>> expiryProdList() {
String userId = SecurityUtils.getUser().getUserId();
List<ShopCartItemDto> shopCartItems = basketService.getShopCartExpiryItems(userId);
//根据店铺ID划分item
@ -182,20 +182,20 @@ public class ShopCartController {
shopcartExpiryitems.add(shopCartExpiryItemDto);
}
return ResponseEntity.ok(shopcartExpiryitems);
return ServerResponseEntity.success(shopcartExpiryitems);
}
@DeleteMapping("/cleanExpiryProdList")
@Operation(summary = "清空用户失效商品" , description = "清空用户失效商品")
public ResponseEntity<Void> cleanExpiryProdList() {
public ServerResponseEntity<Void> cleanExpiryProdList() {
String userId = SecurityUtils.getUser().getUserId();
basketService.cleanExpiryProdList(userId);
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
@PostMapping("/totalPay")
@Operation(summary = "获取选中购物项总计、选中的商品数量" , description = "获取选中购物项总计、选中的商品数量,参数为购物车id数组")
public ResponseEntity<ShopCartAmountDto> getTotalPay(@RequestBody List<Long> basketIds) {
public ServerResponseEntity<ShopCartAmountDto> getTotalPay(@RequestBody List<Long> basketIds) {
// 拿到购物车的所有item
List<ShopCartItemDto> dbShopCartItems = basketService.getShopCartItems(SecurityUtils.getUser().getUserId());
@ -244,7 +244,7 @@ public class ShopCartController {
shopCartAmountDto.setSubtractMoney(reduce);
shopCartAmountDto.setFinalMoney(Arith.sub(shopCartAmountDto.getTotalMoney(), shopCartAmountDto.getSubtractMoney()));
return ResponseEntity.ok(shopCartAmountDto);
return ServerResponseEntity.success(shopCartAmountDto);
}
}

View File

@ -19,7 +19,7 @@ import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import lombok.AllArgsConstructor;
import ma.glasnost.orika.MapperFacade;
import org.springframework.http.ResponseEntity;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@ -42,13 +42,13 @@ public class SkuController {
@GetMapping("/getSkuList")
@Operation(summary = "通过prodId获取商品全部规格列表" , description = "通过prodId获取商品全部规格列表")
@Parameter(name = "prodId", description = "商品id" )
public ResponseEntity<List<SkuDto>> getSkuListByProdId(Long prodId) {
public ServerResponseEntity<List<SkuDto>> getSkuListByProdId(Long prodId) {
List<Sku> skus = skuService.list(new LambdaQueryWrapper<Sku>()
.eq(Sku::getStatus, 1)
.eq(Sku::getIsDelete, 0)
.eq(Sku::getProdId, prodId)
);
List<SkuDto> skuDtoList = mapperFacade.mapAsList(skus, SkuDto.class);
return ResponseEntity.ok(skuDtoList);
return ServerResponseEntity.success(skuDtoList);
}
}

View File

@ -18,7 +18,7 @@ import com.yami.shop.service.SmsLogService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
@ -39,10 +39,10 @@ public class SmsController {
*/
@PostMapping("/send")
@Operation(summary = "发送验证码" , description = "用户的发送验证码")
public ResponseEntity<Void> audit(@RequestBody SendSmsParam sendSmsParam) {
public ServerResponseEntity<Void> audit(@RequestBody SendSmsParam sendSmsParam) {
String userId = SecurityUtils.getUser().getUserId();
smsLogService.sendSms(SmsType.VALID, userId, sendSmsParam.getMobile(),Maps.newHashMap());
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
}

View File

@ -26,7 +26,7 @@ import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
@ -46,18 +46,18 @@ public class UserCollectionController {
@GetMapping("/page")
@Operation(summary = "分页返回收藏数据" , description = "根据用户id获取")
public ResponseEntity<IPage<UserCollectionDto>> getUserCollectionDtoPageByUserId(PageParam page) {
return ResponseEntity.ok(userCollectionService.getUserCollectionDtoPageByUserId(page, SecurityUtils.getUser().getUserId()));
public ServerResponseEntity<IPage<UserCollectionDto>> getUserCollectionDtoPageByUserId(PageParam page) {
return ServerResponseEntity.success(userCollectionService.getUserCollectionDtoPageByUserId(page, SecurityUtils.getUser().getUserId()));
}
@GetMapping("isCollection")
@Operation(summary = "根据商品id获取该商品是否在收藏夹中" , description = "传入收藏商品id")
public ResponseEntity<Boolean> isCollection(Long prodId) {
public ServerResponseEntity<Boolean> isCollection(Long prodId) {
if (productService.count(new LambdaQueryWrapper<Product>()
.eq(Product::getProdId, prodId)) < 1) {
throw new YamiShopBindException("该商品不存在");
}
return ResponseEntity.ok(userCollectionService.count(new LambdaQueryWrapper<UserCollection>()
return ServerResponseEntity.success(userCollectionService.count(new LambdaQueryWrapper<UserCollection>()
.eq(UserCollection::getProdId, prodId)
.eq(UserCollection::getUserId, SecurityUtils.getUser().getUserId())) > 0);
}
@ -65,7 +65,7 @@ public class UserCollectionController {
@PostMapping("/addOrCancel")
@Operation(summary = "添加/取消收藏" , description = "传入收藏商品id,如果商品未收藏则收藏商品,已收藏则取消收藏")
@Parameter(name = "prodId", description = "商品id" , required = true)
public ResponseEntity<Void> addOrCancel(@RequestBody Long prodId) {
public ServerResponseEntity<Void> addOrCancel(@RequestBody Long prodId) {
if (Objects.isNull(productService.getProductByProdId(prodId))) {
throw new YamiShopBindException("该商品不存在");
}
@ -83,7 +83,7 @@ public class UserCollectionController {
userCollection.setProdId(prodId);
userCollectionService.save(userCollection);
}
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
/**
@ -98,10 +98,10 @@ public class UserCollectionController {
@GetMapping("/prods")
@Operation(summary = "获取用户收藏商品列表" , description = "获取用户收藏商品列表")
public ResponseEntity<IPage<ProductDto>> collectionProds(PageParam page) {
public ServerResponseEntity<IPage<ProductDto>> collectionProds(PageParam page) {
String userId = SecurityUtils.getUser().getUserId();
IPage<ProductDto> productDtoPage = productService.collectionProds(page, userId);
return ResponseEntity.ok(productDtoPage);
return ServerResponseEntity.success(productDtoPage);
}
}

View File

@ -19,7 +19,7 @@ import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import ma.glasnost.orika.MapperFacade;
import org.springframework.http.ResponseEntity;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.web.bind.annotation.*;
/**
* @author lanhai
@ -38,22 +38,22 @@ public class UserController {
*/
@GetMapping("/userInfo")
@Operation(summary = "查看用户信息" , description = "根据用户IDuserId获取用户信息")
public ResponseEntity<UserDto> userInfo() {
public ServerResponseEntity<UserDto> userInfo() {
String userId = SecurityUtils.getUser().getUserId();
User user = userService.getById(userId);
UserDto userDto = mapperFacade.map(user, UserDto.class);
return ResponseEntity.ok(userDto);
return ServerResponseEntity.success(userDto);
}
@PutMapping("/setUserInfo")
@Operation(summary = "设置用户信息" , description = "设置用户信息")
public ResponseEntity<Void> setUserInfo(@RequestBody UserInfoParam userInfoParam) {
public ServerResponseEntity<Void> setUserInfo(@RequestBody UserInfoParam userInfoParam) {
String userId = SecurityUtils.getUser().getUserId();
User user = new User();
user.setUserId(userId);
user.setPic(userInfoParam.getAvatarUrl());
user.setNickName(userInfoParam.getNickName());
userService.updateById(user);
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
}

View File

@ -16,7 +16,7 @@ import com.yami.shop.service.UserService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.*;
@ -44,7 +44,7 @@ public class UserRegisterController {
@PostMapping("/register")
@Operation(summary = "注册" , description = "用户注册或绑定手机号接口")
public ResponseEntity<TokenInfoVO> register(@Valid @RequestBody UserRegisterParam userRegisterParam) {
public ServerResponseEntity<TokenInfoVO> register(@Valid @RequestBody UserRegisterParam userRegisterParam) {
if (StrUtil.isBlank(userRegisterParam.getNickName())) {
userRegisterParam.setNickName(userRegisterParam.getUserName());
}
@ -71,13 +71,13 @@ public class UserRegisterController {
userInfoInTokenBO.setSysType(SysTypeEnum.ORDINARY.value());
userInfoInTokenBO.setIsAdmin(0);
userInfoInTokenBO.setEnabled(true);
return ResponseEntity.ok(tokenStore.storeAndGetVo(userInfoInTokenBO));
return ServerResponseEntity.success(tokenStore.storeAndGetVo(userInfoInTokenBO));
}
@PutMapping("/updatePwd")
@Operation(summary = "修改密码" , description = "修改密码")
public ResponseEntity<Void> updatePwd(@Valid @RequestBody UserRegisterParam userPwdUpdateParam) {
public ServerResponseEntity<Void> updatePwd(@Valid @RequestBody UserRegisterParam userPwdUpdateParam) {
User user = userService.getOne(new LambdaQueryWrapper<User>().eq(User::getNickName, userPwdUpdateParam.getNickName()));
if (user == null) {
// 无法获取用户信息
@ -96,6 +96,6 @@ public class UserRegisterController {
user.setModifyTime(new Date());
user.setLoginPassword(password);
userService.updateById(user);
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
}

View File

@ -11,15 +11,21 @@
package com.yami.shop.common.config;
import com.yami.shop.common.exception.YamiShopBindException;
import com.yami.shop.common.response.ResponseEnum;
import com.yami.shop.common.response.ServerResponseEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindException;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import java.util.ArrayList;
import java.util.List;
/**
* 自定义错误处理器
* @author LGH
@ -29,23 +35,44 @@ import org.springframework.web.bind.annotation.RestControllerAdvice;
@RestControllerAdvice
public class DefaultExceptionHandlerConfig {
@ExceptionHandler({ MethodArgumentNotValidException.class, BindException.class })
public ResponseEntity<ServerResponseEntity<List<String>>> methodArgumentNotValidExceptionHandler(Exception e) {
log.error("methodArgumentNotValidExceptionHandler", e);
List<FieldError> fieldErrors = null;
if (e instanceof MethodArgumentNotValidException) {
fieldErrors = ((MethodArgumentNotValidException) e).getBindingResult().getFieldErrors();
}
if (e instanceof BindException) {
fieldErrors = ((BindException) e).getBindingResult().getFieldErrors();
}
if (fieldErrors == null) {
return ResponseEntity.status(HttpStatus.OK)
.body(ServerResponseEntity.fail(ResponseEnum.METHOD_ARGUMENT_NOT_VALID));
}
@ExceptionHandler(BindException.class)
public ResponseEntity<String> bindExceptionHandler(BindException e){
log.error("BindException:", e);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getBindingResult().getFieldErrors().get(0).getDefaultMessage());
}
@ExceptionHandler(MethodArgumentNotValidException.class)
public ResponseEntity<String> methodArgumentNotValidExceptionHandler(MethodArgumentNotValidException e){
log.error("MethodArgumentNotValidException:", e);
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(e.getBindingResult().getFieldErrors().get(0).getDefaultMessage());
List<String> defaultMessages = new ArrayList<>(fieldErrors.size());
for (FieldError fieldError : fieldErrors) {
defaultMessages.add(fieldError.getField() + ":" + fieldError.getDefaultMessage());
}
return ResponseEntity.status(HttpStatus.OK)
.body(ServerResponseEntity.fail(ResponseEnum.METHOD_ARGUMENT_NOT_VALID, defaultMessages));
}
@ExceptionHandler(YamiShopBindException.class)
public ResponseEntity<String> unauthorizedExceptionHandler(YamiShopBindException e){
log.error("YamiShopBindException Message :{}",e.getMessage());
return ResponseEntity.status(e.getHttpStatusCode()).body(e.getMessage());
public ResponseEntity<ServerResponseEntity<?>> unauthorizedExceptionHandler(YamiShopBindException e){
log.error("mall4jExceptionHandler", e);
ServerResponseEntity<?> serverResponseEntity = e.getServerResponseEntity();
if (serverResponseEntity!=null) {
return ResponseEntity.status(HttpStatus.OK).body(serverResponseEntity);
}
// 失败返回消息 状态码固定为直接显示消息的状态码
return ResponseEntity.status(HttpStatus.OK).body(ServerResponseEntity.fail(e.getCode(),e.getMessage()));
}
@ExceptionHandler(Exception.class)
public ResponseEntity<ServerResponseEntity<Object>> exceptionHandler(Exception e){
log.error("exceptionHandler", e);
return ResponseEntity.status(HttpStatus.OK).body(ServerResponseEntity.fail(ResponseEnum.EXCEPTION));
}
}

View File

@ -1,82 +0,0 @@
/*
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
*
* https://www.mall4j.com/
*
* 未经允许不可做商业用途
*
* 版权所有侵权必究
*/
package com.yami.shop.common.enums;
/**
* 与前端进行特殊交互需要使用的状态码由于小程序需要所以状态码只能为3位数字并且不能与正常的http状态码冲突
* @author LGH
*/
public enum YamiHttpStatus {
/**
* 客户端看到401状态码时应该重新登陆
*/
UNAUTHORIZED(401, "未授权"),
COUPONCANNOTUSETOGETHER(601, "优惠券不能共用"),
SOCIAL_ACCOUNT_NOT_BIND(475, "social account not bind"),
ACCOUNT_NOT_REGISTER(476, "account not register"),
;
private final int value;
private final String msg;
YamiHttpStatus(int value, String msg) {
this.value = value;
this.msg = msg;
}
/**
* Return the integer value of this status code.
*/
public int value() {
return this.value;
}
/**
* Return the msg of this status code.
*/
public String getMsg() {
return msg;
}
/**
* Return a string representation of this status code.
*/
@Override
public String toString() {
return this.value + " " + name();
}
public static YamiHttpStatus valueOf(int statusCode) {
YamiHttpStatus status = resolve(statusCode);
if (status == null) {
throw new IllegalArgumentException("没有找到该Http状态码包含状态 [" + statusCode + "]");
}
return status;
}
public static YamiHttpStatus resolve(int statusCode) {
for (YamiHttpStatus status : values()) {
if (status.value == statusCode) {
return status;
}
}
return null;
}
}

View File

@ -10,11 +10,14 @@
package com.yami.shop.common.exception;
import com.yami.shop.common.enums.YamiHttpStatus;
import org.springframework.http.HttpStatus;
import com.yami.shop.common.response.ResponseEnum;
import com.yami.shop.common.response.ServerResponseEntity;
import lombok.Getter;
/**
* @author lanhai
*/
@Getter
public class YamiShopBindException extends RuntimeException{
/**
@ -25,41 +28,38 @@ public class YamiShopBindException extends RuntimeException{
/**
* http状态码
*/
private Integer httpStatusCode;
private String code;
private Object object;
private ServerResponseEntity<?> serverResponseEntity;
public YamiShopBindException(ResponseEnum responseEnum) {
super(responseEnum.getMsg());
this.code = responseEnum.value();
}
/**
* @param httpStatus http状态码
* @param responseEnum
*/
public YamiShopBindException(YamiHttpStatus httpStatus) {
super(httpStatus.getMsg());
this.httpStatusCode = httpStatus.value();
public YamiShopBindException(ResponseEnum responseEnum, String msg) {
super(msg);
this.code = responseEnum.value();
}
/**
* @param httpStatus http状态码
*/
public YamiShopBindException(YamiHttpStatus httpStatus, String msg) {
super(msg);
this.httpStatusCode = httpStatus.value();
public YamiShopBindException(ServerResponseEntity<?> serverResponseEntity) {
this.serverResponseEntity = serverResponseEntity;
}
public YamiShopBindException(String msg) {
super(msg);
this.httpStatusCode = HttpStatus.BAD_REQUEST.value();
this.code = ResponseEnum.SHOW_FAIL.value();
}
public YamiShopBindException(String msg, Object object) {
super(msg);
this.httpStatusCode = HttpStatus.BAD_REQUEST.value();
this.code = ResponseEnum.SHOW_FAIL.value();
this.object = object;
}
public Integer getHttpStatusCode() {
return httpStatusCode;
}
}

View File

@ -1,9 +1,12 @@
package com.yami.shop.common.handler;
import cn.hutool.core.util.CharsetUtil;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yami.shop.common.exception.YamiShopBindException;
import com.yami.shop.common.response.ServerResponseEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
@ -12,6 +15,7 @@ import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Objects;
/**
* @author 菠萝凤梨
@ -22,7 +26,14 @@ public class HttpHandler {
private static final Logger logger = LoggerFactory.getLogger(HttpHandler.class);
public <T> void printServerResponseToWeb(String str, int status) {
@Autowired
private ObjectMapper objectMapper;
public <T> void printServerResponseToWeb(ServerResponseEntity<T> serverResponseEntity) {
if (serverResponseEntity == null) {
logger.info("print obj is null");
return;
}
ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder
.getRequestAttributes();
@ -35,17 +46,33 @@ public class HttpHandler {
logger.error("httpServletResponse is null, can not print to web");
return;
}
logger.error("response error: " + str);
logger.error("response error: " + serverResponseEntity.getMsg());
response.setCharacterEncoding(CharsetUtil.UTF_8);
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
response.setStatus(status);
PrintWriter printWriter = null;
try {
printWriter = response.getWriter();
printWriter.write(str);
printWriter.write(objectMapper.writeValueAsString(serverResponseEntity));
}
catch (IOException e) {
throw new YamiShopBindException("io 异常", e);
}
}
public <T> void printServerResponseToWeb(YamiShopBindException yamiShopBindException) {
if (yamiShopBindException == null) {
logger.info("print obj is null");
return;
}
if (Objects.nonNull(yamiShopBindException.getServerResponseEntity())) {
printServerResponseToWeb(yamiShopBindException.getServerResponseEntity());
return;
}
ServerResponseEntity<T> serverResponseEntity = new ServerResponseEntity<>();
serverResponseEntity.setCode(yamiShopBindException.getCode());
serverResponseEntity.setMsg(yamiShopBindException.getMessage());
printServerResponseToWeb(serverResponseEntity);
}
}

View File

@ -7,7 +7,6 @@
*
* 版权所有侵权必究
*/
package com.yami.shop.common.response;
/**
@ -16,6 +15,5 @@ package com.yami.shop.common.response;
public interface ResponseCode {
int SUCCESS = 1;
int FAIL = -1;
}

View File

@ -0,0 +1,69 @@
/*
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
*
* https://www.mall4j.com/
*
* 未经允许不可做商业用途
*
* 版权所有侵权必究
*/
package com.yami.shop.common.response;
/**
* @author FrozenWatermelon
* @date 2020/7/9
*/
public enum ResponseEnum {
/**
* ok
*/
OK("00000", "ok"),
SHOW_FAIL("A00001", ""),
/**
* 用于直接显示提示用户的错误内容由输入内容决定
*/
/**
* 用于直接显示提示系统的成功内容由输入内容决定
*/
SHOW_SUCCESS("A00002", ""),
/**
* 未授权
*/
UNAUTHORIZED("A00004", "Unauthorized"),
/**
* 服务器出了点小差
*/
EXCEPTION("A00005", "服务器出了点小差"),
/**
* 方法参数没有校验内容由输入内容决定
*/
METHOD_ARGUMENT_NOT_VALID("A00014", "方法参数没有校验");
private final String code;
private final String msg;
public String value() {
return code;
}
public String getMsg() {
return msg;
}
ResponseEnum(String code, String msg) {
this.code = code;
this.msg = msg;
}
@Override
public String toString() {
return "ResponseEnum{" + "code='" + code + '\'' + ", msg='" + msg + '\'' + "} " + super.toString();
}
}

View File

@ -12,48 +12,187 @@ package com.yami.shop.common.response;
import lombok.extern.slf4j.Slf4j;
import java.io.Serializable;
import java.util.Objects;
/**
* @author lanhai
*/
@Slf4j
public class ServerResponseEntity {
public class ServerResponseEntity<T> implements Serializable {
public static <T> ServerResponse<T> success(T data) {
ServerResponse<T> serverResponse = new ServerResponse<>();
serverResponse.setObj(data);
serverResponse.setCode(ResponseCode.SUCCESS);
return serverResponse;
/**
* 状态码
*/
private String code;
/**
* 信息
*/
private String msg;
/**
* 数据
*/
private T data;
/**
* 版本
*/
private String version;
/**
* 时间
*/
private Long timestamp;
private String sign;
public String getSign() {
return sign;
}
public static <T> ServerResponse<T> success() {
ServerResponse<T> serverResponse = new ServerResponse<>();
serverResponse.setCode(ResponseCode.SUCCESS);
return serverResponse;
public void setSign(String sign) {
this.sign = sign;
}
public static <T> ServerResponse<T> fail(String msg) {
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public T getData() {
return data;
}
public ServerResponseEntity setData(T data) {
this.data = data;
return this;
}
public String getVersion() {
return version;
}
public void setVersion(String version) {
this.version = version;
}
public Long getTimestamp() {
return timestamp;
}
public void setTimestamp(Long timestamp) {
this.timestamp = timestamp;
}
public boolean isSuccess() {
return Objects.equals(ResponseEnum.OK.value(), this.code);
}
public boolean isFail() {
return !Objects.equals(ResponseEnum.OK.value(), this.code);
}
public ServerResponseEntity() {
// 版本号
this.version = "mall4j.v230313";
}
public static <T> ServerResponseEntity<T> success(T data) {
ServerResponseEntity<T> serverResponseEntity = new ServerResponseEntity<>();
serverResponseEntity.setData(data);
serverResponseEntity.setCode(ResponseEnum.OK.value());
return serverResponseEntity;
}
public static <T> ServerResponseEntity<T> success() {
ServerResponseEntity<T> serverResponseEntity = new ServerResponseEntity<>();
serverResponseEntity.setCode(ResponseEnum.OK.value());
serverResponseEntity.setMsg(ResponseEnum.OK.getMsg());
return serverResponseEntity;
}
public static <T> ServerResponseEntity<T> success(Integer code, T data) {
return success(String.valueOf(code), data);
}
public static <T> ServerResponseEntity<T> success(String code, T data) {
ServerResponseEntity<T> serverResponseEntity = new ServerResponseEntity<>();
serverResponseEntity.setCode(code);
serverResponseEntity.setData(data);
return serverResponseEntity;
}
/**
* 前端显示失败消息
* @param msg 失败消息
* @return
*/
public static <T> ServerResponseEntity<T> showFailMsg(String msg) {
log.error(msg);
ServerResponse<T> serverResponse = new ServerResponse<>();
serverResponse.setMsg(msg);
serverResponse.setCode(ResponseCode.FAIL);
return serverResponse;
ServerResponseEntity<T> serverResponseEntity = new ServerResponseEntity<>();
serverResponseEntity.setMsg(msg);
serverResponseEntity.setCode(ResponseEnum.SHOW_FAIL.value());
return serverResponseEntity;
}
public static <T> ServerResponse<T> fail(String msg, T data) {
log.error(msg);
ServerResponse<T> serverResponse = new ServerResponse<>();
serverResponse.setMsg(msg);
serverResponse.setCode(ResponseCode.FAIL);
serverResponse.setObj(data);
return serverResponse;
public static <T> ServerResponseEntity<T> fail(ResponseEnum responseEnum) {
log.error(responseEnum.toString());
ServerResponseEntity<T> serverResponseEntity = new ServerResponseEntity<>();
serverResponseEntity.setMsg(responseEnum.getMsg());
serverResponseEntity.setCode(responseEnum.value());
return serverResponseEntity;
}
public static <T> ServerResponse<T> fail(int code ,String msg, T data) {
public static <T> ServerResponseEntity<T> fail(ResponseEnum responseEnum, T data) {
log.error(responseEnum.toString());
ServerResponseEntity<T> serverResponseEntity = new ServerResponseEntity<>();
serverResponseEntity.setMsg(responseEnum.getMsg());
serverResponseEntity.setCode(responseEnum.value());
serverResponseEntity.setData(data);
return serverResponseEntity;
}
public static <T> ServerResponseEntity<T> fail(String code, String msg, T data) {
log.error(msg);
ServerResponse<T> serverResponse = new ServerResponse<>();
serverResponse.setMsg(msg);
serverResponse.setCode(code);
serverResponse.setObj(data);
return serverResponse;
ServerResponseEntity<T> serverResponseEntity = new ServerResponseEntity<>();
serverResponseEntity.setMsg(msg);
serverResponseEntity.setCode(code);
serverResponseEntity.setData(data);
return serverResponseEntity;
}
public static <T> ServerResponseEntity<T> fail(String code, String msg) {
return fail(code, msg, null);
}
public static <T> ServerResponseEntity<T> fail(Integer code, T data) {
ServerResponseEntity<T> serverResponseEntity = new ServerResponseEntity<>();
serverResponseEntity.setCode(String.valueOf(code));
serverResponseEntity.setData(data);
return serverResponseEntity;
}
@Override
public String toString() {
return "ServerResponseEntity{" +
"code='" + code + '\'' +
", msg='" + msg + '\'' +
", data=" + data +
", version='" + version + '\'' +
", timestamp=" + timestamp +
", sign='" + sign + '\'' +
'}';
}
}

View File

@ -15,7 +15,7 @@ import com.yami.shop.security.common.vo.TokenInfoVO;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
@ -43,7 +43,7 @@ public class LoginController {
@PostMapping("/login")
@Operation(summary = "账号密码(用于前端登录)" , description = "通过账号/手机号/用户名密码登录,还要携带用户的类型,也就是用户所在的系统")
public ResponseEntity<TokenInfoVO> login(
public ServerResponseEntity<TokenInfoVO> login(
@Valid @RequestBody AuthenticationDTO authenticationDTO) {
String mobileOrUserName = authenticationDTO.getUserName();
User user = getUser(mobileOrUserName);
@ -59,7 +59,7 @@ public class LoginController {
userInfoInToken.setEnabled(user.getStatus() == 1);
// 存储token返回vo
TokenInfoVO tokenInfoVO = tokenStore.storeAndGetVo(userInfoInToken);
return ResponseEntity.ok(tokenInfoVO);
return ServerResponseEntity.success(tokenInfoVO);
}
private User getUser(String mobileOrUserName) {

View File

@ -14,7 +14,7 @@ import com.anji.captcha.model.common.ResponseModel;
import com.anji.captcha.model.vo.CaptchaVO;
import com.anji.captcha.service.CaptchaService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.ResponseEntity;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
@ -36,19 +36,19 @@ public class CaptchaController {
}
@PostMapping({ "/get" })
public ResponseEntity<ResponseModel> get(@RequestBody CaptchaVO captchaVO) {
return ResponseEntity.ok(captchaService.get(captchaVO));
public ServerResponseEntity<ResponseModel> get(@RequestBody CaptchaVO captchaVO) {
return ServerResponseEntity.success(captchaService.get(captchaVO));
}
@PostMapping({ "/check" })
public ResponseEntity<ResponseModel> check(@RequestBody CaptchaVO captchaVO) {
public ServerResponseEntity<ResponseModel> check(@RequestBody CaptchaVO captchaVO) {
ResponseModel responseModel;
try {
responseModel = captchaService.check(captchaVO);
}catch (Exception e) {
return ResponseEntity.ok(ResponseModel.errorMsg(RepCodeEnum.API_CAPTCHA_COORDINATE_ERROR));
return ServerResponseEntity.success(ResponseModel.errorMsg(RepCodeEnum.API_CAPTCHA_COORDINATE_ERROR));
}
return ResponseEntity.ok(responseModel);
return ServerResponseEntity.success(responseModel);
}
}

View File

@ -10,11 +10,11 @@
package com.yami.shop.security.common.controller;
import cn.hutool.core.util.StrUtil;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.security.common.manager.TokenStore;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
@ -33,13 +33,13 @@ public class LogoutController {
@PostMapping("/logOut")
@Operation(summary = "退出登陆" , description = "点击退出登陆清除token清除菜单缓存")
public ResponseEntity<Void> logOut(HttpServletRequest request) {
public ServerResponseEntity<Void> logOut(HttpServletRequest request) {
String accessToken = request.getHeader("Authorization");
if (StrUtil.isBlank(accessToken)) {
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
// 删除该用户在该系统当前的token
tokenStore.deleteCurrentToken(accessToken);
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
}

View File

@ -9,6 +9,7 @@
*/
package com.yami.shop.security.common.controller;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.security.common.bo.TokenInfoBO;
import com.yami.shop.security.common.dto.RefreshTokenDTO;
import com.yami.shop.security.common.manager.TokenStore;
@ -16,7 +17,6 @@ import com.yami.shop.security.common.vo.TokenInfoVO;
import io.swagger.v3.oas.annotations.tags.Tag;
import ma.glasnost.orika.MapperFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
@ -38,11 +38,11 @@ public class TokenController {
private MapperFacade mapperFacade;
@PostMapping("/token/refresh")
public ResponseEntity<TokenInfoVO> refreshToken(@Valid @RequestBody RefreshTokenDTO refreshTokenDTO) {
public ServerResponseEntity<TokenInfoVO> refreshToken(@Valid @RequestBody RefreshTokenDTO refreshTokenDTO) {
TokenInfoBO tokenInfoServerResponseEntity = tokenStore
.refreshToken(refreshTokenDTO.getRefreshToken());
return ResponseEntity
.ok(mapperFacade.map(tokenInfoServerResponseEntity, TokenInfoVO.class));
return ServerResponseEntity
.success(mapperFacade.map(tokenInfoServerResponseEntity, TokenInfoVO.class));
}
}

View File

@ -13,6 +13,8 @@ import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import com.yami.shop.common.exception.YamiShopBindException;
import com.yami.shop.common.handler.HttpHandler;
import com.yami.shop.common.response.ResponseEnum;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.security.common.adapter.AuthConfigAdapter;
import com.yami.shop.security.common.bo.UserInfoInTokenBO;
import com.yami.shop.security.common.manager.TokenStore;
@ -20,7 +22,6 @@ import com.yami.shop.security.common.util.AuthUserContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.util.AntPathMatcher;
@ -85,7 +86,7 @@ public class AuthFilter implements Filter {
}
else if (!mayAuth) {
// 返回前端401
httpHandler.printServerResponseToWeb(HttpStatus.UNAUTHORIZED.getReasonPhrase(), HttpStatus.UNAUTHORIZED.value());
httpHandler.printServerResponseToWeb(ServerResponseEntity.fail(ResponseEnum.UNAUTHORIZED));
return;
}
// 保存上下文
@ -96,7 +97,7 @@ public class AuthFilter implements Filter {
}catch (Exception e) {
// 手动捕获下非controller异常
if (e instanceof YamiShopBindException) {
httpHandler.printServerResponseToWeb(e.getMessage(), ((YamiShopBindException) e).getHttpStatusCode());
httpHandler.printServerResponseToWeb((YamiShopBindException) e);
} else {
throw e;
}

View File

@ -16,7 +16,7 @@ import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.symmetric.AES;
import com.yami.shop.common.constants.OauthCacheNames;
import com.yami.shop.common.enums.YamiHttpStatus;
import com.yami.shop.common.response.ResponseEnum;
import com.yami.shop.common.exception.YamiShopBindException;
import com.yami.shop.common.util.PrincipalUtil;
import com.yami.shop.security.common.bo.TokenInfoBO;
@ -158,7 +158,7 @@ public class TokenStore {
*/
public UserInfoInTokenBO getUserInfoByAccessToken(String accessToken, boolean needDecrypt) {
if (StrUtil.isBlank(accessToken)) {
throw new YamiShopBindException(YamiHttpStatus.UNAUTHORIZED,"accessToken is blank");
throw new YamiShopBindException(ResponseEnum.UNAUTHORIZED,"accessToken is blank");
}
String realAccessToken;
if (needDecrypt) {
@ -171,7 +171,7 @@ public class TokenStore {
.get(getAccessKey(realAccessToken));
if (userInfoInTokenBO == null) {
throw new YamiShopBindException(YamiHttpStatus.UNAUTHORIZED,"accessToken 已过期");
throw new YamiShopBindException(ResponseEnum.UNAUTHORIZED,"accessToken 已过期");
}
return userInfoInTokenBO;
}
@ -183,13 +183,13 @@ public class TokenStore {
*/
public TokenInfoBO refreshToken(String refreshToken) {
if (StrUtil.isBlank(refreshToken)) {
throw new YamiShopBindException(YamiHttpStatus.UNAUTHORIZED,"refreshToken is blank");
throw new YamiShopBindException(ResponseEnum.UNAUTHORIZED,"refreshToken is blank");
}
String realRefreshToken = decryptToken(refreshToken);
String accessToken = stringRedisTemplate.opsForValue().get(getRefreshToAccessKey(realRefreshToken));
if (StrUtil.isBlank(accessToken)) {
throw new YamiShopBindException(YamiHttpStatus.UNAUTHORIZED,"refreshToken 已过期");
throw new YamiShopBindException(ResponseEnum.UNAUTHORIZED,"refreshToken 已过期");
}
UserInfoInTokenBO userInfoInTokenBO = getUserInfoByAccessToken(accessToken,
false);
@ -256,16 +256,16 @@ public class TokenStore {
int expiresIn = getExpiresIn(sysType);
long second = 1000L;
if (System.currentTimeMillis() - createTokenTime > expiresIn * second) {
throw new YamiShopBindException(YamiHttpStatus.UNAUTHORIZED,"token error");
throw new YamiShopBindException(ResponseEnum.UNAUTHORIZED,"token error");
}
}
catch (Exception e) {
throw new YamiShopBindException(YamiHttpStatus.UNAUTHORIZED,"token error");
throw new YamiShopBindException(ResponseEnum.UNAUTHORIZED,"token error");
}
// 防止解密后的token是脚本从而对redis进行攻击uuid只能是数字和小写字母
if (!PrincipalUtil.isSimpleChar(decryptToken)) {
throw new YamiShopBindException(YamiHttpStatus.UNAUTHORIZED,"token error");
throw new YamiShopBindException(ResponseEnum.UNAUTHORIZED,"token error");
}
return decryptToken;
}

View File

@ -17,7 +17,7 @@ import javax.validation.Valid;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yami.shop.sys.model.SysConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
@ -53,9 +53,9 @@ public class SysConfigController{
*/
@GetMapping("/page")
@PreAuthorize("@pms.hasPermission('sys:config:page')")
public ResponseEntity<IPage<SysConfig>> page(String paramKey,PageParam<SysConfig> page){
public ServerResponseEntity<IPage<SysConfig>> page(String paramKey,PageParam<SysConfig> page){
IPage<SysConfig> sysConfigs = sysConfigService.page(page, new LambdaQueryWrapper<SysConfig>().like(StrUtil.isNotBlank(paramKey),SysConfig::getParamKey,paramKey));
return ResponseEntity.ok(sysConfigs);
return ServerResponseEntity.success(sysConfigs);
}
@ -64,9 +64,9 @@ public class SysConfigController{
*/
@GetMapping("/info/{id}")
@PreAuthorize("@pms.hasPermission('sys:config:info')")
public ResponseEntity<SysConfig> info(@PathVariable("id") Long id){
public ServerResponseEntity<SysConfig> info(@PathVariable("id") Long id){
SysConfig config = sysConfigService.getById(id);
return ResponseEntity.ok(config);
return ServerResponseEntity.success(config);
}
/**
@ -75,9 +75,9 @@ public class SysConfigController{
@SysLog("保存配置")
@PostMapping
@PreAuthorize("@pms.hasPermission('sys:config:save')")
public ResponseEntity<Void> save(@RequestBody @Valid SysConfig config){
public ServerResponseEntity<Void> save(@RequestBody @Valid SysConfig config){
sysConfigService.save(config);
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
/**
@ -86,9 +86,9 @@ public class SysConfigController{
@SysLog("修改配置")
@PutMapping
@PreAuthorize("@pms.hasPermission('sys:config:update')")
public ResponseEntity<Void> update(@RequestBody @Valid SysConfig config){
public ServerResponseEntity<Void> update(@RequestBody @Valid SysConfig config){
sysConfigService.updateById(config);
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
/**
@ -97,9 +97,9 @@ public class SysConfigController{
@SysLog("删除配置")
@DeleteMapping
@PreAuthorize("@pms.hasPermission('sys:config:delete')")
public ResponseEntity<Void> delete(@RequestBody Long[] configIds){
public ServerResponseEntity<Void> delete(@RequestBody Long[] configIds){
sysConfigService.deleteBatch(configIds);
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
}

View File

@ -14,7 +14,7 @@ package com.yami.shop.sys.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yami.shop.sys.model.SysLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@ -45,12 +45,12 @@ public class SysLogController {
*/
@GetMapping("/page")
@PreAuthorize("@pms.hasPermission('sys:log:page')")
public ResponseEntity<IPage<SysLog>> page(SysLog sysLog,PageParam<SysLog> page){
public ServerResponseEntity<IPage<SysLog>> page(SysLog sysLog,PageParam<SysLog> page){
IPage<SysLog> sysLogs = sysLogService.page(page,
new LambdaQueryWrapper<SysLog>()
.like(StrUtil.isNotBlank(sysLog.getUsername()),SysLog::getUsername, sysLog.getUsername())
.like(StrUtil.isNotBlank(sysLog.getOperation()), SysLog::getOperation,sysLog.getOperation()));
return ResponseEntity.ok(sysLogs);
return ServerResponseEntity.success(sysLogs);
}
}

View File

@ -21,7 +21,7 @@ import com.yami.shop.sys.model.SysMenu;
import com.yami.shop.sys.service.SysMenuService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
@ -44,10 +44,10 @@ public class SysMenuController{
@GetMapping("/nav")
@Operation(summary = "获取用户所拥有的菜单和权限" , description = "通过登陆用户的userId获取用户所拥有的菜单和权限")
public ResponseEntity<Map<Object, Object>> nav(){
public ServerResponseEntity<Map<Object, Object>> nav(){
List<SysMenu> menuList = sysMenuService.listMenuByUserId(SecurityUtils.getSysUser().getUserId());
return ResponseEntity.ok(MapUtil.builder().put("menuList", menuList).put("authorities", SecurityUtils.getSysUser().getAuthorities()).build());
return ServerResponseEntity.success(MapUtil.builder().put("menuList", menuList).put("authorities", SecurityUtils.getSysUser().getAuthorities()).build());
}
/**
@ -55,9 +55,9 @@ public class SysMenuController{
* @return
*/
@GetMapping("/table")
public ResponseEntity<List<SysMenu>> table(){
public ServerResponseEntity<List<SysMenu>> table(){
List<SysMenu> sysMenuList = sysMenuService.listMenuAndBtn();
return ResponseEntity.ok(sysMenuList);
return ServerResponseEntity.success(sysMenuList);
}
/**
@ -65,31 +65,31 @@ public class SysMenuController{
*/
@GetMapping("/list")
@Operation(summary = "获取用户所拥有的菜单(不包括按钮)" , description = "通过登陆用户的userId获取用户所拥有的菜单和权限")
public ResponseEntity<List<SysMenu>> list(){
public ServerResponseEntity<List<SysMenu>> list(){
List<SysMenu> sysMenuList= sysMenuService.listSimpleMenuNoButton();
return ResponseEntity.ok(sysMenuList);
return ServerResponseEntity.success(sysMenuList);
}
/**
* 选择菜单
*/
@GetMapping("/listRootMenu")
public ResponseEntity<List<SysMenu>> listRootMenu(){
public ServerResponseEntity<List<SysMenu>> listRootMenu(){
//查询列表数据
List<SysMenu> menuList = sysMenuService.listRootMenu();
return ResponseEntity.ok(menuList);
return ServerResponseEntity.success(menuList);
}
/**
* 选择子菜单
*/
@GetMapping("/listChildrenMenu")
public ResponseEntity<List<SysMenu>> listChildrenMenu(Long parentId){
public ServerResponseEntity<List<SysMenu>> listChildrenMenu(Long parentId){
//查询列表数据
List<SysMenu> menuList = sysMenuService.listChildrenMenuByParentId(parentId);
return ResponseEntity.ok(menuList);
return ServerResponseEntity.success(menuList);
}
/**
@ -97,9 +97,9 @@ public class SysMenuController{
*/
@GetMapping("/info/{menuId}")
@PreAuthorize("@pms.hasPermission('sys:menu:info')")
public ResponseEntity<SysMenu> info(@PathVariable("menuId") Long menuId){
public ServerResponseEntity<SysMenu> info(@PathVariable("menuId") Long menuId){
SysMenu menu = sysMenuService.getById(menuId);
return ResponseEntity.ok(menu);
return ServerResponseEntity.success(menu);
}
/**
@ -108,11 +108,11 @@ public class SysMenuController{
@SysLog("保存菜单")
@PostMapping
@PreAuthorize("@pms.hasPermission('sys:menu:save')")
public ResponseEntity<Void> save(@Valid @RequestBody SysMenu menu){
public ServerResponseEntity<Void> save(@Valid @RequestBody SysMenu menu){
//数据校验
verifyForm(menu);
sysMenuService.save(menu);
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
/**
@ -121,18 +121,18 @@ public class SysMenuController{
@SysLog("修改菜单")
@PutMapping
@PreAuthorize("@pms.hasPermission('sys:menu:update')")
public ResponseEntity<String> update(@Valid @RequestBody SysMenu menu){
public ServerResponseEntity<String> update(@Valid @RequestBody SysMenu menu){
//数据校验
verifyForm(menu);
if(menu.getType() == MenuType.MENU.getValue()){
if(StrUtil.isBlank(menu.getUrl())){
return ResponseEntity.badRequest().body("菜单URL不能为空");
return ServerResponseEntity.showFailMsg("菜单URL不能为空");
}
}
sysMenuService.updateById(menu);
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
/**
@ -141,19 +141,19 @@ public class SysMenuController{
@SysLog("删除菜单")
@DeleteMapping("/{menuId}")
@PreAuthorize("@pms.hasPermission('sys:menu:delete')")
public ResponseEntity<String> delete(@PathVariable Long menuId){
public ServerResponseEntity<String> delete(@PathVariable Long menuId){
if(menuId <= Constant.SYS_MENU_MAX_ID){
return ResponseEntity.badRequest().body("系统菜单,不能删除");
return ServerResponseEntity.showFailMsg("系统菜单,不能删除");
}
//判断是否有子菜单或按钮
List<SysMenu> menuList = sysMenuService.listChildrenMenuByParentId(menuId);
if(menuList.size() > 0){
return ResponseEntity.badRequest().body("请先删除子菜单或按钮");
return ServerResponseEntity.showFailMsg("请先删除子菜单或按钮");
}
sysMenuService.deleteMenuAndRoleMenu(menuId);
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
/**

View File

@ -16,7 +16,7 @@ import java.util.List;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yami.shop.sys.model.SysRole;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
@ -56,9 +56,9 @@ public class SysRoleController{
*/
@GetMapping("/page")
@PreAuthorize("@pms.hasPermission('sys:role:page')")
public ResponseEntity<IPage<SysRole>> page(String roleName,PageParam<SysRole> page){
public ServerResponseEntity<IPage<SysRole>> page(String roleName,PageParam<SysRole> page){
IPage<SysRole> sysRoles = sysRoleService.page(page,new LambdaQueryWrapper<SysRole>().like(StrUtil.isNotBlank(roleName),SysRole::getRoleName,roleName));
return ResponseEntity.ok(sysRoles);
return ServerResponseEntity.success(sysRoles);
}
/**
@ -66,9 +66,9 @@ public class SysRoleController{
*/
@GetMapping("/list")
@PreAuthorize("@pms.hasPermission('sys:role:list')")
public ResponseEntity<List<SysRole>> list(){
public ServerResponseEntity<List<SysRole>> list(){
List<SysRole> list = sysRoleService.list();
return ResponseEntity.ok(list);
return ServerResponseEntity.success(list);
}
/**
@ -76,14 +76,14 @@ public class SysRoleController{
*/
@GetMapping("/info/{roleId}")
@PreAuthorize("@pms.hasPermission('sys:role:info')")
public ResponseEntity<SysRole> info(@PathVariable("roleId") Long roleId){
public ServerResponseEntity<SysRole> info(@PathVariable("roleId") Long roleId){
SysRole role = sysRoleService.getById(roleId);
//查询角色对应的菜单
List<Long> menuList = sysMenuService.listMenuIdByRoleId(roleId);
role.setMenuIdList(menuList);
return ResponseEntity.ok(role);
return ServerResponseEntity.success(role);
}
/**
@ -92,9 +92,9 @@ public class SysRoleController{
@SysLog("保存角色")
@PostMapping
@PreAuthorize("@pms.hasPermission('sys:role:save')")
public ResponseEntity<Void> save(@RequestBody SysRole role){
public ServerResponseEntity<Void> save(@RequestBody SysRole role){
sysRoleService.saveRoleAndRoleMenu(role);
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
/**
@ -103,9 +103,9 @@ public class SysRoleController{
@SysLog("修改角色")
@PutMapping
@PreAuthorize("@pms.hasPermission('sys:role:update')")
public ResponseEntity<Void> update(@RequestBody SysRole role){
public ServerResponseEntity<Void> update(@RequestBody SysRole role){
sysRoleService.updateRoleAndRoleMenu(role);
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
/**
@ -114,8 +114,8 @@ public class SysRoleController{
@SysLog("删除角色")
@DeleteMapping
@PreAuthorize("@pms.hasPermission('sys:role:delete')")
public ResponseEntity<Void> delete(@RequestBody Long[] roleIds){
public ServerResponseEntity<Void> delete(@RequestBody Long[] roleIds){
sysRoleService.deleteBatch(roleIds);
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
}

View File

@ -29,7 +29,7 @@ import com.yami.shop.sys.service.SysRoleService;
import com.yami.shop.sys.service.SysUserService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import com.yami.shop.common.response.ServerResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.*;
@ -61,19 +61,19 @@ public class SysUserController {
*/
@GetMapping("/page")
@PreAuthorize("@pms.hasPermission('sys:user:page')")
public ResponseEntity<IPage<SysUser>> page(String username,PageParam<SysUser> page){
public ServerResponseEntity<IPage<SysUser>> page(String username,PageParam<SysUser> page){
IPage<SysUser> sysUserPage = sysUserService.page(page, new LambdaQueryWrapper<SysUser>()
.eq(SysUser::getShopId, SecurityUtils.getSysUser().getShopId())
.like(StrUtil.isNotBlank(username), SysUser::getUsername, username));
return ResponseEntity.ok(sysUserPage);
return ServerResponseEntity.success(sysUserPage);
}
/**
* 获取登录的用户信息
*/
@GetMapping("/info")
public ResponseEntity<SysUser> info(){
return ResponseEntity.ok(sysUserService.getSysUserById(SecurityUtils.getSysUser().getUserId()));
public ServerResponseEntity<SysUser> info(){
return ServerResponseEntity.success(sysUserService.getSysUserById(SecurityUtils.getSysUser().getUserId()));
}
/**
@ -82,7 +82,7 @@ public class SysUserController {
@SysLog("修改密码")
@PostMapping("/password")
@Operation(summary = "修改密码" , description = "修改当前登陆用户的密码")
public ResponseEntity<String> password(@RequestBody @Valid UpdatePasswordDto param){
public ServerResponseEntity<String> password(@RequestBody @Valid UpdatePasswordDto param){
Long userId = SecurityUtils.getSysUser().getUserId();
// 开源版代码禁止用户修改admin 的账号密码
@ -93,14 +93,14 @@ public class SysUserController {
SysUser dbUser = sysUserService.getSysUserById(userId);
String password = passwordManager.decryptPassword(param.getPassword());
if (!passwordEncoder.matches(password, dbUser.getPassword())) {
return ResponseEntity.badRequest().body("原密码不正确");
return ServerResponseEntity.showFailMsg("原密码不正确");
}
//新密码
String newPassword = passwordEncoder.encode(passwordManager.decryptPassword(param.getNewPassword()));
// 更新密码
sysUserService.updatePasswordByUserId(userId, newPassword);
tokenStore.deleteAllToken(String.valueOf(SysTypeEnum.ADMIN.value()),String.valueOf(userId));
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
/**
@ -108,7 +108,7 @@ public class SysUserController {
*/
@GetMapping("/info/{userId}")
@PreAuthorize("@pms.hasPermission('sys:user:info')")
public ResponseEntity<SysUser> info(@PathVariable("userId") Long userId){
public ServerResponseEntity<SysUser> info(@PathVariable("userId") Long userId){
SysUser user = sysUserService.getSysUserById(userId);
user.setUserId(null);
if (!Objects.equals(user.getShopId(), SecurityUtils.getSysUser().getShopId())) {
@ -117,7 +117,7 @@ public class SysUserController {
//获取用户所属的角色列表
List<Long> roleIdList = sysRoleService.listRoleIdByUserId(userId);
user.setRoleIdList(roleIdList);
return ResponseEntity.ok(user);
return ServerResponseEntity.success(user);
}
/**
@ -126,17 +126,17 @@ public class SysUserController {
@SysLog("保存用户")
@PostMapping
@PreAuthorize("@pms.hasPermission('sys:user:save')")
public ResponseEntity<String> save(@Valid @RequestBody SysUser user){
public ServerResponseEntity<String> save(@Valid @RequestBody SysUser user){
String username = user.getUsername();
SysUser dbUser = sysUserService.getOne(new LambdaQueryWrapper<SysUser>()
.eq(SysUser::getUsername, username));
if (dbUser!=null) {
return ResponseEntity.badRequest().body("该用户已存在");
return ServerResponseEntity.showFailMsg("该用户已存在");
}
user.setShopId(SecurityUtils.getSysUser().getShopId());
user.setPassword(passwordEncoder.encode(passwordManager.decryptPassword(user.getPassword())));
sysUserService.saveUserAndUserRole(user);
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
/**
@ -145,7 +145,7 @@ public class SysUserController {
@SysLog("修改用户")
@PutMapping
@PreAuthorize("@pms.hasPermission('sys:user:update')")
public ResponseEntity<String> update(@Valid @RequestBody SysUser user){
public ServerResponseEntity<String> update(@Valid @RequestBody SysUser user){
String password = passwordManager.decryptPassword(user.getPassword());
SysUser dbUser = sysUserService.getSysUserById(user.getUserId());
@ -155,7 +155,7 @@ public class SysUserController {
SysUser dbUserNameInfo = sysUserService.getByUserName(user.getUsername());
if (dbUserNameInfo != null && !Objects.equals(dbUserNameInfo.getUserId(),user.getUserId())) {
return ResponseEntity.badRequest().body("该用户已存在");
return ServerResponseEntity.showFailMsg("该用户已存在");
}
if (StrUtil.isBlank(password)) {
user.setPassword(null);
@ -173,7 +173,7 @@ public class SysUserController {
throw new YamiShopBindException("admin用户不可以被禁用");
}
sysUserService.updateUserAndUserRole(user);
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
/**
@ -182,17 +182,17 @@ public class SysUserController {
@SysLog("删除用户")
@DeleteMapping
@PreAuthorize("@pms.hasPermission('sys:user:delete')")
public ResponseEntity<String> delete(@RequestBody Long[] userIds){
public ServerResponseEntity<String> delete(@RequestBody Long[] userIds){
if (userIds.length == 0) {
return ResponseEntity.badRequest().body("请选择需要删除的用户");
return ServerResponseEntity.showFailMsg("请选择需要删除的用户");
}
if(ArrayUtil.contains(userIds, Constant.SUPER_ADMIN_ID)){
return ResponseEntity.badRequest().body("系统管理员不能删除");
return ServerResponseEntity.showFailMsg("系统管理员不能删除");
}
if(ArrayUtil.contains(userIds, SecurityUtils.getSysUser().getUserId())){
return ResponseEntity.badRequest().body("当前用户不能删除");
return ServerResponseEntity.showFailMsg("当前用户不能删除");
}
sysUserService.deleteBatch(userIds,SecurityUtils.getSysUser().getShopId());
return ResponseEntity.ok().build();
return ServerResponseEntity.success();
}
}