shiyunteng
2026-09-18 c5c284896ce6428cffc5092e9cdef4fefc23409f
platformx-business-finance-biz/src/main/java/com/by4cloud/platformx/business/controller/ProductController.java
@@ -11,6 +11,8 @@
import com.by4cloud.platformx.admin.api.vo.DeptExcelVO;
import com.by4cloud.platformx.business.dto.ProductAddDTO;
import com.by4cloud.platformx.business.dto.ProductQueryDTO;
import com.by4cloud.platformx.business.dto.SyncProductDTO;
import com.by4cloud.platformx.business.entity.BusinessCustomer;
import com.by4cloud.platformx.business.vo.ProductExcelVO;
import com.by4cloud.platformx.business.vo.ProductTreeVo;
import com.by4cloud.platformx.common.core.util.R;
@@ -19,6 +21,8 @@
import com.by4cloud.platformx.business.entity.Product;
import com.by4cloud.platformx.business.service.ProductService;
import com.by4cloud.platformx.common.security.annotation.Inner;
import com.by4cloud.platformx.common.security.util.SecurityUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.access.prepost.PreAuthorize;
import com.by4cloud.platformx.common.excel.annotation.ResponseExcel;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
@@ -49,6 +53,15 @@
    private final  ProductService productService;
   @Value("${dept.smj}")
   private String smj;
   @Value("${dept.smjsc}")
   private String smjsc;
   @Value("${dept.smjzt}")
   private String smjzt;
    /**
     * 分页查询
     * @param page 分页对象
@@ -59,6 +72,32 @@
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('business_product_view')" )
    public R getProductPage(@ParameterObject Page page, @ParameterObject Product product) {
      if (StrUtil.equals(SecurityUtils.getUser().getCompId() + "", smj) || StrUtil.equals(SecurityUtils.getUser().getCompId() + "", smjsc) ||
            StrUtil.equals(SecurityUtils.getUser().getCompId() + "", smjzt)) {
         LambdaQueryWrapper<Product> wrapper = Wrappers.lambdaQuery();
         wrapper.eq(product.getParentId()!=null,Product::getParentId,product.getParentId());
         wrapper.like(StrUtil.isNotEmpty(product.getProductName()),Product::getProductName,product.getProductName());
         wrapper.like(StrUtil.isNotEmpty(product.getMainCode()),Product::getMainCode,product.getMainCode());
         wrapper.like(StrUtil.isNotEmpty(product.getErpCode()),Product::getErpCode,product.getErpCode());
         List<String> smjList = new ArrayList<>();
         smjList.add(smj);
         smjList.add(smjsc);
         smjList.add(smjzt);
         wrapper.in(Product::getCompId, smjList);
         wrapper.orderByDesc(Product::getCreateTime);
         Page<Product> page1 = productService.page(page, wrapper);
         List<Product> list = page1.getRecords();
         for(Product product1 : list){
            Product  parent = productService.getById(product1.getParentId());
            if(parent==null){
               product1.setParentName("根级产品");
            }else {
               product1.setParentName(parent.getProductName());
            }
         }
         page1.setRecords(list);
         return R.ok(page1);
      }
        LambdaQueryWrapper<Product> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(product.getParentId()!=null,Product::getParentId,product.getParentId());
        wrapper.like(StrUtil.isNotEmpty(product.getProductName()),Product::getProductName,product.getProductName());
@@ -146,7 +185,7 @@
    @PostMapping
    @PreAuthorize("@pms.hasPermission('business_product_add')" )
    public R save(@RequestBody Product product) {
      if (ArrayUtil.isNotEmpty(productService.listByScope(Wrappers.lambdaQuery(product).eq(Product::getErpCode,product.getErpCode())).toArray())){
      if (CollUtil.isNotEmpty(productService.listByScope(Wrappers.lambdaQuery(product).eq(Product::getErpCode,product.getErpCode())))){
         return R.failed("产品Erp编码已存在");
      }
        return R.ok(productService.save(product));
@@ -214,4 +253,14 @@
   public R importProduct(@RequestExcel List<ProductExcelVO> excelVOList, BindingResult bindingResult) {
      return productService.importProduct(excelVOList, bindingResult);
   }
   /**
    * 石煤机产品同步
    * @return
    */
   @Inner(value = false)
   @GetMapping("/syncSMJByDate")
   public R syncSMJByDate(@ParameterObject SyncProductDTO dto) {
      return productService.syncSMJByDate(dto);
   }
}