基于mall4j产品的二开项目后端
lee
2024-12-18 921461a3f906d74403aeb6a27051deb77eca10fc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
 * 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);
    }
}