基于mall4j产品的二开项目后端
lee
2024-12-18 efdb99f8cecc4afb592afad79c761081d5d5cf22
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
/*
 * Copyright (c) 2018-2999 广州市蓝海创新科技有限公司 All rights reserved.
 *
 * https://www.mall4j.com/
 *
 * 未经允许,不可做商业用途!
 *
 * 版权所有,侵权必究!
 */
package com.yami.shop.api.controller;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yami.shop.bean.enums.AuditStatus;
import com.yami.shop.bean.model.CompanyAuditing;
import com.yami.shop.bean.model.ShopCompany;
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.security.api.util.SecurityUtils;
import com.yami.shop.service.CompanyAuditingService;
import com.yami.shop.service.ShopDetailService;
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.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
 
import javax.validation.Valid;
import java.util.Objects;
 
/**
 * @author chiley
 * @date 2022/9/21 10:22
 */
 
@RestController
@RequestMapping("/p/shop/companyAuditing")
@Tag(name = "变更工商信息接口")
public class CompanyAuditingController {
 
    @Autowired
    private CompanyAuditingService companyAuditingService;
    @Autowired
    private ShopDetailService shopDetailService;
 
    @PostMapping("/applyChangeCompanyInfo")
    @Operation(summary = "申请变更工商信息" , description = "申请变更工商信息")
    @PreAuthorize("@pms.hasPermission('shop:shopCompany:applyChange')")
    public ServerResponseEntity<Void> applyChangeCompanyInfo(@RequestBody @Valid ShopCompany shopCompany) {
        Long shopId = shopDetailService.getShopDetailByUserId(SecurityUtils.getUser().getUserId()).getShopId();
        String userId = SecurityUtils.getUser().getUserId();
        // 校验是否已经存在申请中记录
        CompanyAuditing latestCompanyAuditing = companyAuditingService.getOne(new LambdaQueryWrapper<CompanyAuditing>().eq(CompanyAuditing::getShopId, shopId).orderByDesc(CompanyAuditing::getCreateTime), false);
        if (Objects.nonNull(latestCompanyAuditing) && Objects.equals(latestCompanyAuditing.getStatus(), AuditStatus.WAITAUDIT.value())) {
            throw new YamiShopBindException("yami.shop.company.repeat.application");
        }
        shopCompany.setShopId(shopId);
        companyAuditingService.applyChangeCompanyInfo(shopCompany, userId);
        return ServerResponseEntity.success();
    }
 
    @PutMapping("/revoke")
    @Operation(summary = "撤销申请" , description = "撤销申请")
    @PreAuthorize("@pms.hasPermission('shop:shopCompany:revoke')")
    public ServerResponseEntity<Void> revoke(@RequestBody Long companyAuditingId) {
        CompanyAuditing companyAuditing = companyAuditingService.getById(companyAuditingId);
        if (Objects.isNull(companyAuditing)) {
            return ServerResponseEntity.success();
        }
        if (!Objects.equals(companyAuditing.getShopId(), shopDetailService.getShopDetailByUserId(SecurityUtils.getUser().getUserId()).getShopId())) {
            return ServerResponseEntity.fail(ResponseEnum.UNAUTHORIZED);
        }
        companyAuditingService.revoke(companyAuditing);
        return ServerResponseEntity.success();
    }
 
 
    @GetMapping("/auditInfo")
    @Operation(summary = "查看申请审核情况" , description = "查看申请审核情况")
    public ServerResponseEntity<CompanyAuditing> auditInfo() {
        Long shopId = shopDetailService.getShopDetailByUserId(SecurityUtils.getUser().getUserId()).getShopId();
        return ServerResponseEntity.success(companyAuditingService.getAuditInfo(shopId));
    }
}