|
|
@@ -1,140 +0,0 @@
|
|
|
-package com.fs.admin.controller;
|
|
|
-
|
|
|
-import java.util.*;
|
|
|
-
|
|
|
-import com.fs.admin.helper.AdminCrossTenantHelper;
|
|
|
-import com.fs.common.annotation.Excel;
|
|
|
-import com.fs.common.annotation.Log;
|
|
|
-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.enums.BusinessType;
|
|
|
-import com.fs.common.utils.poi.ExcelUtil;
|
|
|
-import lombok.Data;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
-import org.springframework.web.bind.annotation.*;
|
|
|
-
|
|
|
-/**
|
|
|
- * 总后台商品审核控制器
|
|
|
- * 遍历所有租户库查询 fs_store_product 数据
|
|
|
- */
|
|
|
-@RestController
|
|
|
-@RequestMapping("/admin/product")
|
|
|
-public class ProductAdminController extends BaseController {
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private AdminCrossTenantHelper crossTenantHelper;
|
|
|
-
|
|
|
- private String str(Object o) { return o == null ? "" : o.toString(); }
|
|
|
-
|
|
|
- @Data
|
|
|
- public static class ProductExportVO {
|
|
|
- @Excel(name = "租户名称") private String companyName;
|
|
|
- @Excel(name = "商品名称") private String productName;
|
|
|
- @Excel(name = "分类") private String categoryName;
|
|
|
- @Excel(name = "价格") private String price;
|
|
|
- @Excel(name = "库存") private String stock;
|
|
|
- @Excel(name = "状态") private String status;
|
|
|
- @Excel(name = "创建时间") private String createTime;
|
|
|
- }
|
|
|
-
|
|
|
- @Log(title = "导出商品", businessType = BusinessType.EXPORT)
|
|
|
- @PreAuthorize("@ss.hasPermi('admin:product:list')")
|
|
|
- @GetMapping("/export")
|
|
|
- public AjaxResult export(@RequestParam(required = false) String productName,
|
|
|
- @RequestParam(required = false) Long companyId,
|
|
|
- @RequestParam(required = false) String companyName) {
|
|
|
- List<Map<String, Object>> allList = crossTenantHelper.queryAcrossTenants(
|
|
|
- companyId, companyName, (tenant, jdbc) -> {
|
|
|
- StringBuilder sql = new StringBuilder(
|
|
|
- "SELECT p.product_id, p.product_name, p.product_image, p.category_name, " +
|
|
|
- "p.price, p.stock, p.create_time, p.status " +
|
|
|
- "FROM fs_store_product p WHERE 1=1");
|
|
|
- List<Object> params = new ArrayList<>();
|
|
|
- if (productName != null && !productName.isEmpty()) {
|
|
|
- sql.append(" AND p.product_name LIKE ?");
|
|
|
- params.add("%" + productName + "%");
|
|
|
- }
|
|
|
- sql.append(" ORDER BY p.create_time DESC");
|
|
|
- return params.isEmpty()
|
|
|
- ? jdbc.queryForList(sql.toString())
|
|
|
- : jdbc.queryForList(sql.toString(), params.toArray());
|
|
|
- });
|
|
|
- List<ProductExportVO> voList = new ArrayList<>();
|
|
|
- for (Map<String, Object> m : allList) {
|
|
|
- ProductExportVO vo = new ProductExportVO();
|
|
|
- vo.setCompanyName(str(m.get("company_name")));
|
|
|
- vo.setProductName(str(m.get("product_name")));
|
|
|
- vo.setCategoryName(str(m.get("category_name")));
|
|
|
- vo.setPrice(str(m.get("price")));
|
|
|
- vo.setStock(str(m.get("stock")));
|
|
|
- vo.setStatus(str(m.get("status")));
|
|
|
- vo.setCreateTime(str(m.get("create_time")));
|
|
|
- voList.add(vo);
|
|
|
- }
|
|
|
- ExcelUtil<ProductExportVO> util = new ExcelUtil<>(ProductExportVO.class);
|
|
|
- return util.exportExcel(voList, "商品数据");
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 查询所有租户的商品列表
|
|
|
- */
|
|
|
- @PreAuthorize("@ss.hasPermi('admin:product:list')")
|
|
|
- @GetMapping("/list")
|
|
|
- public TableDataInfo list(@RequestParam(required = false) String productName,
|
|
|
- @RequestParam(required = false) Long companyId,
|
|
|
- @RequestParam(required = false) String companyName) {
|
|
|
- List<Map<String, Object>> allList = crossTenantHelper.queryAcrossTenants(
|
|
|
- companyId, companyName, (tenant, jdbc) -> {
|
|
|
- StringBuilder sql = new StringBuilder(
|
|
|
- "SELECT p.product_id, p.product_name, p.product_image, p.category_name, " +
|
|
|
- "p.price, p.stock, p.create_time, p.status " +
|
|
|
- "FROM fs_store_product p WHERE 1=1");
|
|
|
- List<Object> params = new ArrayList<>();
|
|
|
- if (productName != null && !productName.isEmpty()) {
|
|
|
- sql.append(" AND p.product_name LIKE ?");
|
|
|
- params.add("%" + productName + "%");
|
|
|
- }
|
|
|
- sql.append(" ORDER BY p.create_time DESC LIMIT 200");
|
|
|
- return params.isEmpty()
|
|
|
- ? jdbc.queryForList(sql.toString())
|
|
|
- : jdbc.queryForList(sql.toString(), params.toArray());
|
|
|
- });
|
|
|
- return getDataTable(allList);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 查询待审核商品列表
|
|
|
- */
|
|
|
- @PreAuthorize("@ss.hasPermi('admin:product:list')")
|
|
|
- @GetMapping("/pending")
|
|
|
- public TableDataInfo pendingList(@RequestParam(required = false) Long companyId,
|
|
|
- @RequestParam(required = false) String companyName) {
|
|
|
- List<Map<String, Object>> allList = crossTenantHelper.queryAcrossTenants(
|
|
|
- companyId, companyName, (tenant, jdbc) ->
|
|
|
- jdbc.queryForList(
|
|
|
- "SELECT p.product_id, p.product_name, p.product_image, p.category_name, " +
|
|
|
- "p.price, p.stock, p.create_time, p.status " +
|
|
|
- "FROM fs_store_product p WHERE p.status = 0 ORDER BY p.create_time DESC LIMIT 200"));
|
|
|
- return getDataTable(allList);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 商品统计信息
|
|
|
- */
|
|
|
- @PreAuthorize("@ss.hasPermi('admin:product:query')")
|
|
|
- @GetMapping("/statistics")
|
|
|
- public AjaxResult statistics(@RequestParam(required = false) Long companyId,
|
|
|
- @RequestParam(required = false) String companyName) {
|
|
|
- List<Map<String, Object>> allList = crossTenantHelper.queryAcrossTenants(
|
|
|
- companyId, companyName, (tenant, jdbc) ->
|
|
|
- jdbc.queryForList("SELECT product_id, status FROM fs_store_product"));
|
|
|
- Map<String, Object> result = new HashMap<>();
|
|
|
- result.put("totalCount", allList.size());
|
|
|
- result.put("pendingCount", allList.stream().filter(r -> "0".equals(String.valueOf(r.get("status")))).count());
|
|
|
- result.put("onlineCount", allList.stream().filter(r -> "1".equals(String.valueOf(r.get("status")))).count());
|
|
|
- result.put("rejectedCount", allList.stream().filter(r -> "2".equals(String.valueOf(r.get("status")))).count());
|
|
|
- return AjaxResult.success(result);
|
|
|
- }
|
|
|
-}
|