| | |
| | | package com.by4cloud.platformx.business.controller; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.util.ArrayUtil; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.by4cloud.platformx.business.dto.ProductQueryDTO; |
| | | import com.by4cloud.platformx.business.vo.ProductTreeVo; |
| | | import com.by4cloud.platformx.common.core.util.R; |
| | | import com.by4cloud.platformx.common.log.annotation.SysLog; |
| | | import com.by4cloud.platformx.business.entity.Product; |
| | |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | |
| | | 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()); |
| | | return R.ok(productService.page(page, wrapper)); |
| | | 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); |
| | | } |
| | | |
| | | /** |
| | |
| | | @Operation(summary = "分页查询" , description = "分页查询" ) |
| | | @GetMapping("/list" ) |
| | | @PreAuthorize("@pms.hasPermission('business_product_view')" ) |
| | | @Inner(value = false) |
| | | public R getProductList(@ParameterObject Product product) { |
| | | LambdaQueryWrapper<Product> wrapper = Wrappers.lambdaQuery(); |
| | | return R.ok(productService.list(wrapper)); |
| | | return R.ok(productService.getProductList(product)); |
| | | } |
| | | |
| | | /** |
| | | * 分页查询 |
| | | * @param queryDTO 产品信息 |
| | | * @return |
| | | */ |
| | | @Operation(summary = "分页查询" , description = "分页查询" ) |
| | | @GetMapping("/listByParentId" ) |
| | | public R getProductListByParentId(@ParameterObject ProductQueryDTO queryDTO) { |
| | | // LambdaQueryWrapper<Product> wrapper = Wrappers.lambdaQuery(); |
| | | // wrapper.like(StrUtil.isNotEmpty(queryDTO.getProductName()),Product::getProductName,queryDTO.getProductName()); |
| | | // wrapper.eq(StrUtil.isNotEmpty(queryDTO.getParentId()),Product::getParentId,queryDTO.getParentId()); |
| | | // if (StrUtil.isNotEmpty(queryDTO.getContractCategory())&&StrUtil.equals(queryDTO.getContractCategory(), "water_house")){ |
| | | // String[] erpCodes = new String[]{"房租租赁","dianli","water"}; |
| | | // wrapper.in(Product::getErpCode,erpCodes); |
| | | // return R.ok(BeanUtil.copyToList(productService.listByScope(wrapper), ProductTreeVo.class)); |
| | | // } |
| | | // return R.ok(BeanUtil.copyToList(productService.listByScope(wrapper), ProductTreeVo.class)); |
| | | return productService.getProductListByParentId(queryDTO); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Operation(summary = "层级查询" , description = "层级查询" ) |
| | | @GetMapping("/treeList" ) |
| | | //@PreAuthorize("@pms.hasPermission('business_product_view')" ) |
| | | @Inner(value = false) |
| | | public R getNewsCategoryTree(@ParameterObject Product product) { |
| | | return R.ok(productService.treeList(product.getParentId(), product.getProductName())); |
| | | return R.ok(productService.treeList()); |
| | | } |
| | | |
| | | |
| | |
| | | @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())){ |
| | | return R.failed("产品Erp编码已存在"); |
| | | } |
| | | return R.ok(productService.save(product)); |
| | | } |
| | | |