/*
|
* 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));
|
}
|
}
|