|
|
@@ -1,13 +1,26 @@
|
|
|
package org.dromara.product.controller;
|
|
|
|
|
|
import java.util.List;
|
|
|
+import java.util.ArrayList;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import jakarta.servlet.http.HttpServletResponse;
|
|
|
import jakarta.validation.constraints.*;
|
|
|
import cn.dev33.satoken.annotation.SaCheckPermission;
|
|
|
+import org.dromara.easyes.core.biz.EsPageInfo;
|
|
|
+import org.dromara.easyes.core.conditions.select.LambdaEsQueryWrapper;
|
|
|
+import org.dromara.product.domain.ClientSiteProduct;
|
|
|
+import org.dromara.product.domain.bo.ProductBaseBo;
|
|
|
+import org.dromara.product.domain.vo.PcProductVo;
|
|
|
+import org.dromara.product.domain.vo.ProductBaseVo;
|
|
|
+import org.dromara.product.esmapper.ProductEsMapper;
|
|
|
+import org.dromara.product.service.IProductBaseService;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
import org.dromara.common.idempotent.annotation.RepeatSubmit;
|
|
|
import org.dromara.common.log.annotation.Log;
|
|
|
import org.dromara.common.web.core.BaseController;
|
|
|
@@ -17,9 +30,13 @@ import org.dromara.common.core.validate.AddGroup;
|
|
|
import org.dromara.common.core.validate.EditGroup;
|
|
|
import org.dromara.common.log.enums.BusinessType;
|
|
|
import org.dromara.common.excel.utils.ExcelUtil;
|
|
|
+import org.dromara.common.excel.core.ExcelResult;
|
|
|
import org.dromara.product.domain.vo.ClientSiteProductVo;
|
|
|
import org.dromara.product.domain.bo.ClientSiteProductBo;
|
|
|
import org.dromara.product.service.IClientSiteProductService;
|
|
|
+import org.dromara.product.domain.vo.ClientSiteProductImportVo;
|
|
|
+import org.dromara.product.domain.vo.ClientSiteProductExportVo;
|
|
|
+import org.dromara.product.listener.ClientSiteProductImportListener;
|
|
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
|
|
|
/**
|
|
|
@@ -27,7 +44,7 @@ import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
* 前端访问路由地址为:/product/siteProduct
|
|
|
*
|
|
|
* @author LionLi
|
|
|
- * @date 2026-03-04
|
|
|
+ * @date 2026-03-06
|
|
|
*/
|
|
|
@Validated
|
|
|
@RequiredArgsConstructor
|
|
|
@@ -37,6 +54,8 @@ public class ClientSiteProductController extends BaseController {
|
|
|
|
|
|
private final IClientSiteProductService clientSiteProductService;
|
|
|
|
|
|
+ private final ProductEsMapper productEsMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 查询客户站点产品配置列表
|
|
|
*/
|
|
|
@@ -65,7 +84,7 @@ public class ClientSiteProductController extends BaseController {
|
|
|
//@SaCheckPermission("product:siteProduct:query")
|
|
|
@GetMapping("/{id}")
|
|
|
public R<ClientSiteProductVo> getInfo(@NotNull(message = "主键不能为空")
|
|
|
- @PathVariable("id") Long id) {
|
|
|
+ @PathVariable("id") Long id) {
|
|
|
return R.ok(clientSiteProductService.queryById(id));
|
|
|
}
|
|
|
|
|
|
@@ -91,6 +110,21 @@ public class ClientSiteProductController extends BaseController {
|
|
|
return toAjax(clientSiteProductService.updateByBo(bo));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 更新协议价
|
|
|
+ * */
|
|
|
+ @Log(title = "客户站点产品配置", businessType = BusinessType.UPDATE)
|
|
|
+ @RepeatSubmit()
|
|
|
+ @PutMapping("/updateAgreementPrice")
|
|
|
+ public R<Void> updateAgreementPrice(@Validated @RequestBody ClientSiteProductBo bo) {
|
|
|
+ clientSiteProductService.update(Wrappers.lambdaUpdate(ClientSiteProduct.class)
|
|
|
+ .set(ClientSiteProduct::getAgreementPrice, bo.getAgreementPrice())
|
|
|
+ .eq(ClientSiteProduct::getSiteId, bo.getSiteId())
|
|
|
+ .eq(ClientSiteProduct::getProductId, bo.getProductId())
|
|
|
+ );
|
|
|
+ return R.ok();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 删除客户站点产品配置
|
|
|
*
|
|
|
@@ -103,4 +137,109 @@ public class ClientSiteProductController extends BaseController {
|
|
|
@PathVariable("ids") Long[] ids) {
|
|
|
return toAjax(clientSiteProductService.deleteWithValidByIds(List.of(ids), true));
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取站点下的产品数据
|
|
|
+ * */
|
|
|
+ @GetMapping("/getSiteProductPage")
|
|
|
+ public TableDataInfo<ProductBaseVo> getSiteProductPage(ProductBaseBo bo, PageQuery pageQuery) {
|
|
|
+ List<ClientSiteProduct> clientSiteProducts = clientSiteProductService.list(Wrappers.lambdaQuery(ClientSiteProduct.class)
|
|
|
+ .eq(ClientSiteProduct::getSiteId, bo.getSiteId()));
|
|
|
+ if (CollUtil.isEmpty(clientSiteProducts)) {
|
|
|
+ return TableDataInfo.build();
|
|
|
+ }
|
|
|
+ EsPageInfo<ProductBaseVo> esPageInfo = productEsMapper.pageQuery(new LambdaEsQueryWrapper<>(ProductBaseVo.class)
|
|
|
+ .in(ProductBaseVo::getId, clientSiteProducts.stream().map(ClientSiteProduct::getProductId).toList())
|
|
|
+ , pageQuery.getPageNum(), pageQuery.getPageSize()
|
|
|
+ );
|
|
|
+ if (CollUtil.isEmpty(esPageInfo.getList())) {
|
|
|
+ return TableDataInfo.build();
|
|
|
+ }
|
|
|
+ esPageInfo.getList().forEach(productBaseVo -> {
|
|
|
+ clientSiteProducts.stream()
|
|
|
+ .filter(clientSiteProduct -> clientSiteProduct.getProductId().equals(productBaseVo.getId()))
|
|
|
+ .findFirst()
|
|
|
+ .ifPresent(clientSiteProduct -> {
|
|
|
+ productBaseVo.setAgreementPrice(clientSiteProduct.getAgreementPrice());
|
|
|
+ });
|
|
|
+ });
|
|
|
+ TableDataInfo tableDataInfo = new TableDataInfo();
|
|
|
+ tableDataInfo.setRows(esPageInfo.getList());
|
|
|
+ tableDataInfo.setTotal(esPageInfo.getTotal());
|
|
|
+ return tableDataInfo;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导出客户站点产品数据
|
|
|
+ */
|
|
|
+ @Log(title = "客户站点产品配置", businessType = BusinessType.EXPORT)
|
|
|
+ @PostMapping("/exportData")
|
|
|
+ public void exportData(ClientSiteProductBo bo, HttpServletResponse response) {
|
|
|
+ // 站点下的产品
|
|
|
+ List<ClientSiteProduct> clientSiteProducts = clientSiteProductService.list(Wrappers.lambdaQuery(ClientSiteProduct.class)
|
|
|
+ .eq(ClientSiteProduct::getSiteId, bo.getSiteId()));
|
|
|
+
|
|
|
+ if (clientSiteProducts.isEmpty()) {
|
|
|
+ ExcelUtil.exportExcel(new ArrayList<>(), "客户站点产品配置", ClientSiteProductExportVo.class, response);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 产品数据
|
|
|
+ List<ProductBaseVo> productBaseVos = productEsMapper.selectList(new LambdaEsQueryWrapper<>(ProductBaseVo.class)
|
|
|
+ .in(ProductBaseVo::getId, clientSiteProducts.stream().map(ClientSiteProduct::getProductId).toList())
|
|
|
+ );
|
|
|
+
|
|
|
+ // 构建导出列表
|
|
|
+ List<ClientSiteProductExportVo> exportList = new ArrayList<>();
|
|
|
+ int serialNumber = 1;
|
|
|
+ for (ClientSiteProduct clientSiteProduct : clientSiteProducts) {
|
|
|
+ ProductBaseVo product = productBaseVos.stream()
|
|
|
+ .filter(p -> p.getId().equals(clientSiteProduct.getProductId()))
|
|
|
+ .findFirst()
|
|
|
+ .orElse(null);
|
|
|
+
|
|
|
+ if (product != null) {
|
|
|
+ ClientSiteProductExportVo exportVo = new ClientSiteProductExportVo();
|
|
|
+ exportVo.setSerialNumber(serialNumber++);
|
|
|
+ exportVo.setProductNo(product.getProductNo());
|
|
|
+ exportVo.setItemName(product.getItemName());
|
|
|
+ exportVo.setCategoryName(product.getCategoryName());
|
|
|
+ exportVo.setBrandName(product.getBrandName());
|
|
|
+ exportVo.setUnitName(product.getUnitName());
|
|
|
+ exportVo.setMarketPrice(product.getMarketPrice());
|
|
|
+ exportVo.setPlatformPrice(product.getMemberPrice());
|
|
|
+ exportVo.setMinSellingPrice(product.getMinSellingPrice());
|
|
|
+ exportVo.setPurchasingPrice(product.getPurchasingPrice());
|
|
|
+ exportVo.setAgreementPrice(clientSiteProduct.getAgreementPrice());
|
|
|
+ exportList.add(exportVo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ ExcelUtil.exportExcel(exportList, "客户站点产品配置", ClientSiteProductExportVo.class, response);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 导入客户站点产品配置数据
|
|
|
+ *
|
|
|
+ * @param file 导入文件
|
|
|
+ */
|
|
|
+ @Log(title = "客户站点产品配置", businessType = BusinessType.IMPORT)
|
|
|
+ @PostMapping(value = "/importData", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
|
|
+ public R<Void> importData(@RequestPart("file") MultipartFile file) throws Exception {
|
|
|
+ ExcelResult<ClientSiteProductImportVo> result = ExcelUtil.importExcel(
|
|
|
+ file.getInputStream(),
|
|
|
+ ClientSiteProductImportVo.class,
|
|
|
+ new ClientSiteProductImportListener(clientSiteProductService)
|
|
|
+ );
|
|
|
+ return R.ok(result.getAnalysis());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取导入模板
|
|
|
+ */
|
|
|
+ @PostMapping("/importTemplate")
|
|
|
+ public void importTemplate(HttpServletResponse response) {
|
|
|
+ ExcelUtil.exportExcel(new ArrayList<>(), "客户站点产品配置模板", ClientSiteProductImportVo.class, response);
|
|
|
+ }
|
|
|
}
|