/*
|
* Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
|
*
|
* https://www.mall4j.com/
|
*
|
* 未经允许,不可做商业用途!
|
*
|
* 版权所有,侵权必究!
|
*/
|
package com.yami.shop.api.controller;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.yami.shop.bean.enums.AuditStatus;
|
import com.yami.shop.bean.model.ShopCompany;
|
import com.yami.shop.bean.model.ShopDetail;
|
import com.yami.shop.common.response.ServerResponseEntity;
|
import com.yami.shop.security.api.util.SecurityUtils;
|
import com.yami.shop.service.ShopCompanyService;
|
import com.yami.shop.service.ShopDetailService;
|
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
import lombok.AllArgsConstructor;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.validation.Valid;
|
import java.util.Objects;
|
|
/**
|
* @author lth
|
*/
|
@RestController
|
@AllArgsConstructor
|
@RequestMapping("/p/shop/shopCompany")
|
@Tag(name = "店铺工商信息接口")
|
public class ShopCompanyController {
|
private final ShopCompanyService shopCompanyService;
|
private final ShopDetailService shopDetailService;
|
|
@PostMapping
|
@Operation(summary = "新增店铺工商信息" , description = "新增店铺工商信息")
|
public ServerResponseEntity<Void> save(@Valid @RequestBody ShopCompany shopCompany) {
|
ShopDetail shopDetail = shopDetailService.getShopDetailByUserId(SecurityUtils.getUser().getUserId());
|
if (Objects.isNull(shopDetail)){{
|
return ServerResponseEntity.success();
|
}}
|
Long shopId = shopDetail.getShopId();
|
shopCompany.setShopId(shopId);
|
shopCompany.setStatus(AuditStatus.SUCCESSAUDIT.value());
|
shopCompanyService.saveInfo(shopCompany);
|
return ServerResponseEntity.success();
|
}
|
|
@PutMapping
|
@Operation(summary = "更新店铺工商信息" , description = "更新店铺工商信息")
|
public ServerResponseEntity<Void> update(@Valid @RequestBody ShopCompany shopCompany) {
|
ShopDetail shopDetail = shopDetailService.getShopDetailByUserId(SecurityUtils.getUser().getUserId());
|
if (Objects.isNull(shopDetail)){{
|
return ServerResponseEntity.success();
|
}}
|
Long shopId = shopDetail.getShopId();
|
shopCompany.setShopId(shopId);
|
shopCompany.setStatus(AuditStatus.SUCCESSAUDIT.value());
|
shopCompanyService.updateByShopId(shopCompany);
|
return ServerResponseEntity.success();
|
}
|
|
@PostMapping("/storage")
|
@Operation(summary = "存储店铺工商信息" , description = "存储店铺工商信息,已存在则更新,不存在则新增")
|
// @PreAuthorize("@pms.hasPermission('shop:shopCompany:save')")
|
public ServerResponseEntity<Void> storage(@Valid @RequestBody ShopCompany shopCompany) {
|
String id = SecurityUtils.getUser().getUserId();
|
Long shopId = shopDetailService.getShopDetailByUserId(id).getShopId();
|
shopCompany.setShopId(shopId);
|
shopCompany.setStatus(AuditStatus.SUCCESSAUDIT.value());
|
if (shopCompanyService.count(Wrappers.lambdaQuery(ShopCompany.class).eq(ShopCompany::getShopId, shopId)) > 0) {
|
shopCompanyService.updateByShopId(shopCompany);
|
} else {
|
shopCompanyService.saveInfo(shopCompany);
|
}
|
return ServerResponseEntity.success();
|
}
|
|
@GetMapping
|
@Operation(summary = "获取店铺工商信息" , description = "获取店铺工商信息")
|
public ServerResponseEntity<ShopCompany> getShopCompanyByShopId() {
|
ShopDetail shopDetail = shopDetailService.getShopDetailByUserId(SecurityUtils.getUser().getUserId());
|
if (Objects.isNull(shopDetail)){{
|
return ServerResponseEntity.success();
|
}}
|
Long shopId = shopDetail.getShopId();
|
ShopCompany shopCompany = shopCompanyService.getOne(Wrappers.lambdaQuery(ShopCompany.class).eq(ShopCompany::getShopId, shopId).eq(ShopCompany::getStatus, AuditStatus.SUCCESSAUDIT.value()));
|
if (Objects.isNull(shopCompany)) {
|
shopCompany = new ShopCompany();
|
}
|
return ServerResponseEntity.success(shopCompany);
|
}
|
}
|