|
@@ -0,0 +1,105 @@
|
|
|
+package com.ym.mec.web.controller;
|
|
|
+
|
|
|
+import com.ym.mec.auth.api.client.SysUserFeignService;
|
|
|
+import com.ym.mec.auth.api.entity.SysUser;
|
|
|
+import com.ym.mec.biz.dal.entity.SysTenantAccountDetail;
|
|
|
+import com.ym.mec.biz.dal.page.TenantAccountDetailQueryInfo;
|
|
|
+import com.ym.mec.biz.service.SysTenantAccountDetailService;
|
|
|
+import com.ym.mec.biz.service.SysTenantAccountService;
|
|
|
+import com.ym.mec.common.controller.BaseController;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.http.HttpStatus;
|
|
|
+import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+
|
|
|
+@RequestMapping("sysTenantAccount")
|
|
|
+@Api(tags = "后台租客账户管理")
|
|
|
+@RestController
|
|
|
+public class SysTenantAccountController extends BaseController {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SysTenantAccountService sysTenantAccountService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SysTenantAccountDetailService sysTenantAccountDetailService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SysUserFeignService sysUserFeignService;
|
|
|
+
|
|
|
+ @ApiOperation(value = "获取账户信息")
|
|
|
+ @GetMapping("/get")
|
|
|
+ @PreAuthorize("@pcs.hasPermissions('userCashAccount/get')")
|
|
|
+ public Object get() {
|
|
|
+ SysUser sysUser = sysUserFeignService.queryUserInfo();
|
|
|
+ if (sysUser == null) {
|
|
|
+ return failed(HttpStatus.FORBIDDEN, "请登录");
|
|
|
+ }
|
|
|
+
|
|
|
+ return succeed(sysTenantAccountService.get(sysUser.getId()));
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "获取账户明细")
|
|
|
+ @GetMapping("/queryTenantAccountDetail")
|
|
|
+ @PreAuthorize("@pcs.hasPermissions('userCashAccount/queryTenantAccountDetail')")
|
|
|
+ public Object queryTenantAccountDetail(TenantAccountDetailQueryInfo queryInfo) {
|
|
|
+ SysUser sysUser = sysUserFeignService.queryUserInfo();
|
|
|
+ if (sysUser == null) {
|
|
|
+ return failed(HttpStatus.FORBIDDEN, "请登录");
|
|
|
+ }
|
|
|
+ queryInfo.setUserId(sysUser.getId());
|
|
|
+
|
|
|
+ return succeed(sysTenantAccountDetailService.getPageList(queryInfo));
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "增加分钟数")
|
|
|
+ @PostMapping("/addMinutes")
|
|
|
+ @PreAuthorize("@pcs.hasPermissions('userCashAccount/addMinutes')")
|
|
|
+ public Object addMinutes(Integer minutes, String memo) {
|
|
|
+ SysUser sysUser = sysUserFeignService.queryUserInfo();
|
|
|
+ if (sysUser == null) {
|
|
|
+ return failed(HttpStatus.FORBIDDEN, "请登录");
|
|
|
+ }
|
|
|
+ if(minutes == null || minutes < 0){
|
|
|
+ return failed("充值分钟数必须大于0");
|
|
|
+ }
|
|
|
+ if(memo == null || memo.isEmpty()){
|
|
|
+ return failed("备注信息不能为空");
|
|
|
+ }
|
|
|
+ Integer userId = sysUser.getId();
|
|
|
+ boolean updateRes = sysTenantAccountService.update(userId, minutes, null, SysTenantAccountDetail.TransType.CONSUME, null, BigDecimal.ZERO, memo);
|
|
|
+ if(!updateRes){
|
|
|
+ return failed("充值失败,请重试");
|
|
|
+ }
|
|
|
+ return succeed("充值成功");
|
|
|
+ }
|
|
|
+
|
|
|
+ @ApiOperation(value = "减分钟数")
|
|
|
+ @PostMapping("/subtractMinutes")
|
|
|
+ @PreAuthorize("@pcs.hasPermissions('userCashAccount/subtractMinutes')")
|
|
|
+ public Object subtractMinutes(Integer minutes, String memo) {
|
|
|
+ SysUser sysUser = sysUserFeignService.queryUserInfo();
|
|
|
+ if (sysUser == null) {
|
|
|
+ return failed(HttpStatus.FORBIDDEN, "请登录");
|
|
|
+ }
|
|
|
+ if(minutes == null || minutes < 0){
|
|
|
+ return failed("扣除分钟数必须大于0");
|
|
|
+ }
|
|
|
+ if(memo == null || memo.isEmpty()){
|
|
|
+ return failed("备注信息不能为空");
|
|
|
+ }
|
|
|
+ Integer userId = sysUser.getId();
|
|
|
+ boolean updateRes = sysTenantAccountService.update(userId, -minutes, null, SysTenantAccountDetail.TransType.CONSUME, null, BigDecimal.ZERO, memo);
|
|
|
+ if(!updateRes){
|
|
|
+ return failed("充值失败,请重试");
|
|
|
+ }
|
|
|
+ return succeed("充值成功");
|
|
|
+ }
|
|
|
+
|
|
|
+}
|