|
|
@@ -2,13 +2,19 @@ package com.fs.web.controller.system;
|
|
|
|
|
|
import com.fs.common.core.controller.BaseController;
|
|
|
import com.fs.common.core.domain.AjaxResult;
|
|
|
+import com.fs.common.core.page.TableDataInfo;
|
|
|
+import com.fs.common.utils.StringUtils;
|
|
|
import com.fs.proxy.domain.CompanySmsApiTenant;
|
|
|
+import com.fs.proxy.domain.SmsApiTenantBatchAddResult;
|
|
|
import com.fs.proxy.service.ICompanySmsApiTenantService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* 短信接口-租户绑定Controller (adminUI)
|
|
|
@@ -20,12 +26,13 @@ public class CompanySmsApiTenantController extends BaseController {
|
|
|
@Autowired
|
|
|
private ICompanySmsApiTenantService smsApiTenantService;
|
|
|
|
|
|
- /** 查询绑定列表 */
|
|
|
+ /** 分页查询绑定列表 */
|
|
|
@PreAuthorize("@ss.hasPermi('platform:smsApiTenant:list')")
|
|
|
@GetMapping("/list")
|
|
|
- public AjaxResult list(CompanySmsApiTenant query) {
|
|
|
+ public TableDataInfo list(CompanySmsApiTenant query) {
|
|
|
+ startPage();
|
|
|
List<CompanySmsApiTenant> list = smsApiTenantService.selectSmsApiTenantList(query);
|
|
|
- return AjaxResult.success(list);
|
|
|
+ return getDataTable(list);
|
|
|
}
|
|
|
|
|
|
/** 获取绑定详情 */
|
|
|
@@ -49,6 +56,38 @@ public class CompanySmsApiTenantController extends BaseController {
|
|
|
return toAjax(smsApiTenantService.insertSmsApiTenant(tenant));
|
|
|
}
|
|
|
|
|
|
+ /** 批量新增绑定 */
|
|
|
+ @PreAuthorize("@ss.hasPermi('platform:smsApiTenant:add')")
|
|
|
+ @PostMapping("/batch")
|
|
|
+ public AjaxResult batchAdd(@RequestBody Map<String, Object> body) {
|
|
|
+ List<Long> apiIds = parseIdList(body.get("apiIds"));
|
|
|
+ List<Long> tenantIds = parseIdList(body.get("tenantIds"));
|
|
|
+ if (apiIds.isEmpty()) {
|
|
|
+ apiIds = parseIdList(body.get("apiId"));
|
|
|
+ }
|
|
|
+ if (tenantIds.isEmpty()) {
|
|
|
+ tenantIds = parseIdList(body.get("tenantId"));
|
|
|
+ }
|
|
|
+ CompanySmsApiTenant template = new CompanySmsApiTenant();
|
|
|
+ if (body.get("price") != null && StringUtils.isNotEmpty(body.get("price").toString())) {
|
|
|
+ template.setPrice(new BigDecimal(body.get("price").toString()));
|
|
|
+ }
|
|
|
+ if (body.get("priority") != null && StringUtils.isNotEmpty(body.get("priority").toString())) {
|
|
|
+ template.setPriority(Integer.valueOf(body.get("priority").toString()));
|
|
|
+ }
|
|
|
+ if (body.get("allowManual") != null && StringUtils.isNotEmpty(body.get("allowManual").toString())) {
|
|
|
+ template.setAllowManual(Integer.valueOf(body.get("allowManual").toString()));
|
|
|
+ }
|
|
|
+ if (body.get("status") != null && StringUtils.isNotEmpty(body.get("status").toString())) {
|
|
|
+ template.setStatus(Integer.valueOf(body.get("status").toString()));
|
|
|
+ } else {
|
|
|
+ template.setStatus(1);
|
|
|
+ }
|
|
|
+ SmsApiTenantBatchAddResult result = smsApiTenantService.batchInsertSmsApiTenant(apiIds, tenantIds, template);
|
|
|
+ String msg = String.format("成功 %d 条,失败 %d 条", result.getSuccessCount(), result.getFailCount());
|
|
|
+ return AjaxResult.success(msg, result);
|
|
|
+ }
|
|
|
+
|
|
|
/** 修改绑定(调价/启停) */
|
|
|
@PreAuthorize("@ss.hasPermi('platform:smsApiTenant:edit')")
|
|
|
@PutMapping
|
|
|
@@ -56,10 +95,73 @@ public class CompanySmsApiTenantController extends BaseController {
|
|
|
return toAjax(smsApiTenantService.updateSmsApiTenant(tenant));
|
|
|
}
|
|
|
|
|
|
+ /** 批量更新租户定价/绑定配置 */
|
|
|
+ @PreAuthorize("@ss.hasPermi('platform:smsApiTenant:edit')")
|
|
|
+ @PutMapping("/batchPricing")
|
|
|
+ public AjaxResult batchPricing(@RequestBody Map<String, Object> body) {
|
|
|
+ List<Long> ids = parseIdList(body.get("ids"));
|
|
|
+ if (ids.isEmpty()) {
|
|
|
+ return AjaxResult.error("请选择要更新的记录");
|
|
|
+ }
|
|
|
+ CompanySmsApiTenant pricing = parsePricingFields(body);
|
|
|
+ if (pricing.getPrice() == null && pricing.getPriority() == null && pricing.getAllowManual() == null) {
|
|
|
+ return AjaxResult.error("请至少填写一项要批量更新的配置");
|
|
|
+ }
|
|
|
+ return toAjax(smsApiTenantService.batchUpdatePricing(ids, pricing));
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 批量更新状态 */
|
|
|
+ @PreAuthorize("@ss.hasPermi('platform:smsApiTenant:edit')")
|
|
|
+ @PutMapping("/batchStatus")
|
|
|
+ public AjaxResult batchStatus(@RequestBody Map<String, Object> body) {
|
|
|
+ List<Long> ids = parseIdList(body.get("ids"));
|
|
|
+ if (ids.isEmpty()) {
|
|
|
+ return AjaxResult.error("请选择要更新的记录");
|
|
|
+ }
|
|
|
+ if (body.get("status") == null) {
|
|
|
+ return AjaxResult.error("请指定状态");
|
|
|
+ }
|
|
|
+ Integer status = Integer.valueOf(body.get("status").toString());
|
|
|
+ if (status != 0 && status != 1) {
|
|
|
+ return AjaxResult.error("状态值无效");
|
|
|
+ }
|
|
|
+ return toAjax(smsApiTenantService.batchUpdateStatus(ids, status));
|
|
|
+ }
|
|
|
+
|
|
|
/** 解除绑定 */
|
|
|
@PreAuthorize("@ss.hasPermi('platform:smsApiTenant:remove')")
|
|
|
@DeleteMapping("/{id}")
|
|
|
public AjaxResult remove(@PathVariable Long id) {
|
|
|
return toAjax(smsApiTenantService.deleteSmsApiTenantById(id));
|
|
|
}
|
|
|
+
|
|
|
+ private CompanySmsApiTenant parsePricingFields(Map<String, Object> body) {
|
|
|
+ CompanySmsApiTenant pricing = new CompanySmsApiTenant();
|
|
|
+ if (body.get("price") != null && StringUtils.isNotEmpty(body.get("price").toString())) {
|
|
|
+ pricing.setPrice(new BigDecimal(body.get("price").toString()));
|
|
|
+ }
|
|
|
+ if (body.get("priority") != null && StringUtils.isNotEmpty(body.get("priority").toString())) {
|
|
|
+ pricing.setPriority(Integer.valueOf(body.get("priority").toString()));
|
|
|
+ }
|
|
|
+ if (body.get("allowManual") != null && StringUtils.isNotEmpty(body.get("allowManual").toString())) {
|
|
|
+ pricing.setAllowManual(Integer.valueOf(body.get("allowManual").toString()));
|
|
|
+ }
|
|
|
+ return pricing;
|
|
|
+ }
|
|
|
+
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ private List<Long> parseIdList(Object raw) {
|
|
|
+ List<Long> ids = new ArrayList<>();
|
|
|
+ if (raw == null) {
|
|
|
+ return ids;
|
|
|
+ }
|
|
|
+ if (raw instanceof List) {
|
|
|
+ for (Object item : (List<?>) raw) {
|
|
|
+ if (item != null) {
|
|
|
+ ids.add(Long.valueOf(item.toString()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ids;
|
|
|
+ }
|
|
|
}
|