| | |
| | | import com.by4cloud.platformx.business.service.ProductService; |
| | | import com.by4cloud.platformx.common.security.annotation.Inner; |
| | | import com.by4cloud.platformx.common.security.util.SecurityUtils; |
| | | import com.github.yulichang.query.MPJLambdaQueryWrapper; |
| | | import com.github.yulichang.query.MPJQueryWrapper; |
| | | import com.github.yulichang.wrapper.MPJLambdaWrapper; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import com.by4cloud.platformx.common.excel.annotation.ResponseExcel; |
| | |
| | | |
| | | private final ProductService productService; |
| | | |
| | | @Value("${dept.smj}") |
| | | private String smj; |
| | | |
| | | @Value("${dept.smjsc}") |
| | | private String smjsc; |
| | | |
| | | @Value("${dept.smjzt}") |
| | | private String smjzt; |
| | | |
| | | /** |
| | | * 分页查询 |
| | | * @param page 分页对象 |
| | |
| | | @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()); |
| | | wrapper.like(StrUtil.isNotEmpty(product.getMainCode()),Product::getMainCode,product.getMainCode()); |
| | | wrapper.like(StrUtil.isNotEmpty(product.getErpCode()),Product::getErpCode,product.getErpCode()); |
| | | wrapper.orderByDesc(Product::getCreateTime); |
| | | Page<Product> page1 = productService.pageByScope(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); |
| | | // if (StrUtil.equals(SecurityUtils.getUser().getCompId() + "", smj) || StrUtil.equals(SecurityUtils.getUser().getCompId() + "", smjhw)) { |
| | | // MPJLambdaWrapper<Product> wrapper =new MPJLambdaWrapper<Product>() |
| | | // .selectAll(Product.class) |
| | | // .selectAs("ifnull((select product_name from product t1 where t1.id = t.parent_id),'根级产品')",Product::getParentName) |
| | | // .eq(product.getParentId()!=null,Product::getParentId,product.getParentId()) |
| | | // .like(StrUtil.isNotEmpty(product.getProductName()),Product::getProductName,product.getProductName()) |
| | | // .like(StrUtil.isNotEmpty(product.getMainCode()),Product::getMainCode,product.getMainCode()) |
| | | // .like(StrUtil.isNotEmpty(product.getErpCode()),Product::getErpCode,product.getErpCode()); |
| | | // List<String> smjList = new ArrayList<>(); |
| | | // smjList.add(smj); |
| | | //// smjList.add(smjsc); |
| | | //// smjList.add(smjzt); |
| | | // smjList.add(smjhw); |
| | | // wrapper.in(Product::getCompId, smjList); |
| | | // wrapper.orderByDesc(Product::getCreateTime); |
| | | // return R.ok(productService.page(page, wrapper)); |
| | | // } |
| | | // MPJLambdaWrapper<Product> wrapper =new MPJLambdaWrapper<Product>() |
| | | // .selectAll(Product.class) |
| | | // .selectAs("ifnull((select product_name from product t1 where t1.id = parent_id),'根级产品')",Product::getParentName) |
| | | // .eq(product.getParentId()!=null,Product::getParentId,product.getParentId()) |
| | | // .like(StrUtil.isNotEmpty(product.getProductName()),Product::getProductName,product.getProductName()) |
| | | // .like(StrUtil.isNotEmpty(product.getMainCode()),Product::getMainCode,product.getMainCode()) |
| | | // .like(StrUtil.isNotEmpty(product.getErpCode()),Product::getErpCode,product.getErpCode()); |
| | | //// .eq(Product::getCompId,SecurityUtils.getUser().getCompId()); |
| | | // return R.ok(productService.pageByScope(page, wrapper)); |
| | | return R.ok(productService.pageScope(page,product)); |
| | | } |
| | | |
| | | /** |