mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-06-14 04:09:50 +08:00
Merge branch 'feature-coupon' of https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web into feature-coupon
This commit is contained in:
@@ -4,11 +4,11 @@ import com.github.pagehelper.PageHelper;
|
||||
import com.jsowell.common.core.controller.BaseController;
|
||||
import com.jsowell.common.core.domain.AjaxResult;
|
||||
import com.jsowell.common.core.page.TableDataInfo;
|
||||
import com.jsowell.common.util.SecurityUtils;
|
||||
import com.jsowell.pile.domain.CouponTemplate;
|
||||
import com.jsowell.pile.service.CouponTemplateService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -27,23 +27,38 @@ public class CouponTemplateController extends BaseController {
|
||||
private CouponTemplateService couponTemplateService;
|
||||
|
||||
/**
|
||||
* 列表查询
|
||||
* 运营商管理员调用时,由前端传入 creatorMerchantId(后端也应从登录上下文二次校验)
|
||||
* 判断当前登录人是否为平台管理员(userId=1 视为超级管理员)
|
||||
*/
|
||||
private boolean isPlatformAdmin() {
|
||||
return SecurityUtils.isAdmin(SecurityUtils.getUserId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前登录人所属运营商 ID(平台管理员返回 null)
|
||||
*/
|
||||
private Long loginMerchantId() {
|
||||
if (isPlatformAdmin()) {
|
||||
return null;
|
||||
}
|
||||
// 部门 ID 即运营商 ID,与现有体系保持一致
|
||||
return SecurityUtils.getDeptId();
|
||||
}
|
||||
|
||||
@ApiOperation("券模板列表")
|
||||
@PreAuthorize("@ss.hasPermi('coupon:template:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo list(CouponTemplate query,
|
||||
@RequestParam(defaultValue = "1") int pageNum,
|
||||
@RequestParam(defaultValue = "10") int pageSize) {
|
||||
// 运营商管理员只能看本运营商的券
|
||||
if (!isPlatformAdmin()) {
|
||||
query.setCreatorMerchantId(loginMerchantId());
|
||||
}
|
||||
PageHelper.startPage(pageNum, pageSize);
|
||||
List<CouponTemplate> list = couponTemplateService.listForAdmin(query);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 详情
|
||||
*/
|
||||
@ApiOperation("券模板详情")
|
||||
@PreAuthorize("@ss.hasPermi('coupon:template:query')")
|
||||
@GetMapping("/{id}")
|
||||
@@ -51,18 +66,12 @@ public class CouponTemplateController extends BaseController {
|
||||
return AjaxResult.success(couponTemplateService.getById(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增券模板
|
||||
* isPlatformAdmin / loginMerchantId 从登录上下文获取(此处简化演示,实际需从 SecurityUtils 取)
|
||||
*/
|
||||
@ApiOperation("新增券模板")
|
||||
@PreAuthorize("@ss.hasPermi('coupon:template:add')")
|
||||
@PostMapping("/add")
|
||||
public AjaxResult add(@RequestBody CouponTemplate template,
|
||||
@ApiParam("是否平台管理员") @RequestParam(defaultValue = "false") boolean isPlatformAdmin,
|
||||
@ApiParam("登录运营商ID(运营商管理员必传)") @RequestParam(required = false) Long loginMerchantId) {
|
||||
public AjaxResult add(@RequestBody CouponTemplate template) {
|
||||
try {
|
||||
couponTemplateService.add(template, loginMerchantId, isPlatformAdmin);
|
||||
couponTemplateService.add(template, loginMerchantId(), isPlatformAdmin());
|
||||
return AjaxResult.success("新增成功");
|
||||
} catch (Exception e) {
|
||||
logger.error("新增券模板失败", e);
|
||||
@@ -70,17 +79,12 @@ public class CouponTemplateController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑券模板
|
||||
*/
|
||||
@ApiOperation("编辑券模板")
|
||||
@PreAuthorize("@ss.hasPermi('coupon:template:edit')")
|
||||
@PutMapping("/edit")
|
||||
public AjaxResult edit(@RequestBody CouponTemplate template,
|
||||
@RequestParam(defaultValue = "false") boolean isPlatformAdmin,
|
||||
@RequestParam(required = false) Long loginMerchantId) {
|
||||
public AjaxResult edit(@RequestBody CouponTemplate template) {
|
||||
try {
|
||||
couponTemplateService.edit(template, loginMerchantId, isPlatformAdmin);
|
||||
couponTemplateService.edit(template, loginMerchantId(), isPlatformAdmin());
|
||||
return AjaxResult.success("编辑成功");
|
||||
} catch (Exception e) {
|
||||
logger.error("编辑券模板失败", e);
|
||||
@@ -88,18 +92,13 @@ public class CouponTemplateController extends BaseController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 上下架
|
||||
*/
|
||||
@ApiOperation("上下架券模板")
|
||||
@PreAuthorize("@ss.hasPermi('coupon:template:edit')")
|
||||
@PutMapping("/changeStatus")
|
||||
public AjaxResult changeStatus(@RequestParam Long id,
|
||||
@ApiParam("0=下架 1=上架") @RequestParam Integer status,
|
||||
@RequestParam(defaultValue = "false") boolean isPlatformAdmin,
|
||||
@RequestParam(required = false) Long loginMerchantId) {
|
||||
@RequestParam Integer status) {
|
||||
try {
|
||||
couponTemplateService.changeStatus(id, status, loginMerchantId, isPlatformAdmin);
|
||||
couponTemplateService.changeStatus(id, status, loginMerchantId(), isPlatformAdmin());
|
||||
return AjaxResult.success();
|
||||
} catch (Exception e) {
|
||||
logger.error("修改券模板状态失败", e);
|
||||
@@ -107,3 +106,4 @@ public class CouponTemplateController extends BaseController {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user