diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/controller/PlantsRentalOrderController.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/controller/PlantsRentalOrderController.java index 25ff229..ed12bc2 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/controller/PlantsRentalOrderController.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/controller/PlantsRentalOrderController.java @@ -153,6 +153,15 @@ public class PlantsRentalOrderController extends BaseController { return R.ok(plantsRentalOrderService.countOrderAndAmount()); } + /** + * 统计下单客户总数 + * @return + */ + @GetMapping("/countCustomers") + public R countCustomers(){ + return R.ok(plantsRentalOrderService.countCustomers()); + } + } diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/bo/PlantsPlanProductBo.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/bo/PlantsPlanProductBo.java index 0590e09..9c23f0c 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/bo/PlantsPlanProductBo.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/bo/PlantsPlanProductBo.java @@ -9,6 +9,8 @@ import lombok.Data; import lombok.EqualsAndHashCode; import jakarta.validation.constraints.*; +import java.util.List; + /** * 绿植租赁-租赁方案-绿植业务对象 plants_plan_product * @@ -44,4 +46,10 @@ public class PlantsPlanProductBo extends BaseEntity { private Integer productNum; + /** + * 产品id + */ + private List productIds; + + } diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/bo/PlantsRentalOrderBo.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/bo/PlantsRentalOrderBo.java index b0b95ff..c9f4514 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/bo/PlantsRentalOrderBo.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/bo/PlantsRentalOrderBo.java @@ -127,4 +127,14 @@ public class PlantsRentalOrderBo extends BaseEntity { */ private List productList; + /** + * 产品id + */ + private List productIds; + + /** + * 方案id + */ + private List planIds; + } diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/service/IPlantsRentalOrderService.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/service/IPlantsRentalOrderService.java index bcf3c48..b59bfd4 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/service/IPlantsRentalOrderService.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/service/IPlantsRentalOrderService.java @@ -101,5 +101,11 @@ public interface IPlantsRentalOrderService { */ Map countOrderAndAmount(); + /** + * 统计下单客户总数 + * @return + */ + Map countCustomers(); + } diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/PlantsPlanProductServiceImpl.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/PlantsPlanProductServiceImpl.java index d464937..0ea6d4b 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/PlantsPlanProductServiceImpl.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/PlantsPlanProductServiceImpl.java @@ -1,5 +1,6 @@ package org.dromara.property.service.impl; +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import org.dromara.common.core.utils.MapstructUtils; import org.dromara.common.core.utils.StringUtils; import org.dromara.common.mybatis.core.page.TableDataInfo; @@ -76,6 +77,7 @@ public class PlantsPlanProductServiceImpl implements IPlantsPlanProductService { lqw.orderByAsc(PlantsPlanProduct::getId); lqw.eq(bo.getPlanId() != null, PlantsPlanProduct::getPlanId, bo.getPlanId()); lqw.eq(bo.getProductId() != null, PlantsPlanProduct::getProductId, bo.getProductId()); + lqw.in(CollectionUtils.isNotEmpty(bo.getProductIds()), PlantsPlanProduct::getProductId, bo.getProductIds()); return lqw; } diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/PlantsProductServiceImpl.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/PlantsProductServiceImpl.java index 07ed5f5..ce43976 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/PlantsProductServiceImpl.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/PlantsProductServiceImpl.java @@ -1,5 +1,6 @@ package org.dromara.property.service.impl; +import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import org.dromara.common.core.exception.ServiceException; import org.dromara.common.core.utils.MapstructUtils; import org.dromara.common.core.utils.StringUtils; @@ -10,6 +11,14 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.dromara.property.domain.bo.PlantsPlanProductBo; +import org.dromara.property.domain.bo.PlantsRentalOrderBo; +import org.dromara.property.domain.vo.PlantsPlanProductVo; +import org.dromara.property.domain.vo.PlantsRentalOrderVo; +import org.dromara.property.service.IPlantsPlanProductService; +import org.dromara.property.service.IPlantsRentalOrderService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.dromara.property.domain.bo.PlantsProductBo; import org.dromara.property.domain.vo.PlantsProductVo; @@ -29,11 +38,17 @@ import java.util.Collection; * @date 2025-06-25 */ @Slf4j -@RequiredArgsConstructor @Service public class PlantsProductServiceImpl implements IPlantsProductService { - private final PlantsProductMapper baseMapper; + @Autowired + private PlantsProductMapper baseMapper; + @Autowired + @Lazy + private IPlantsRentalOrderService rentalOrderService; + @Autowired + @Lazy + private IPlantsPlanProductService planProductService; /** * 查询绿植租赁-绿植产品 @@ -123,7 +138,7 @@ public class PlantsProductServiceImpl implements IPlantsProductService { * 保存前的数据校验 */ private void validEntityBeforeSave(PlantsProduct entity) { - //TODO 做一些数据校验,如唯一约束 + } /** @@ -136,7 +151,15 @@ public class PlantsProductServiceImpl implements IPlantsProductService { @Override public Boolean deleteWithValidByIds(Collection ids, Boolean isValid) { if (isValid) { - //TODO 做一些业务上的校验,判断是否需要校验 + PlantsRentalOrderBo order = new PlantsRentalOrderBo(); + order.setProductIds(ids.stream().toList()); + List orderVos = rentalOrderService.queryList(order); + PlantsPlanProductBo plantsPlanProductBo = new PlantsPlanProductBo(); + plantsPlanProductBo.setProductIds(ids.stream().toList()); + List planProductVos = planProductService.queryList(plantsPlanProductBo); + if(CollectionUtils.isNotEmpty(orderVos)||CollectionUtils.isNotEmpty(planProductVos)){ + throw new ServiceException("当前选中绿植产品不可删除。"); + } } return baseMapper.deleteByIds(ids) > 0; } diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/PlantsRentalOrderServiceImpl.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/PlantsRentalOrderServiceImpl.java index 136bfc1..dd287c4 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/PlantsRentalOrderServiceImpl.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/PlantsRentalOrderServiceImpl.java @@ -9,9 +9,7 @@ import org.dromara.common.mybatis.core.page.PageQuery; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; -import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.dromara.property.domain.PlantsProduct; import org.dromara.property.domain.bo.PlantsOrderChargeBo; import org.dromara.property.domain.bo.PlantsOrderMaintainBo; import org.dromara.property.domain.bo.PlantsProductBo; @@ -19,6 +17,8 @@ import org.dromara.property.domain.vo.*; import org.dromara.property.service.*; import org.dromara.system.api.RemoteDictService; import org.dromara.system.api.domain.vo.RemoteDictDataVo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.dromara.property.domain.bo.PlantsRentalOrderBo; import org.dromara.property.domain.PlantsRentalOrder; @@ -34,21 +34,24 @@ import java.util.*; * @date 2025-06-30 */ @Slf4j -@RequiredArgsConstructor @Service public class PlantsRentalOrderServiceImpl implements IPlantsRentalOrderService { - private final PlantsRentalOrderMapper baseMapper; - - private final RemoteDictService dictService; - - private final IPlantsProductService productService; - - private final IPlantsPlanProductService planProductService; - -// private final IPlantsOrderMaintainService maintainService; -// -// private final IPlantsOrderChargeService chargeService; + @Autowired + private PlantsRentalOrderMapper baseMapper; + @Autowired + private RemoteDictService dictService; + @Autowired + private IPlantsProductService productService; + @Autowired + @Lazy + private IPlantsPlanProductService planProductService; + @Autowired + @Lazy + private IPlantsOrderMaintainService maintainService; + @Autowired + @Lazy + private IPlantsOrderChargeService chargeService; /** * 查询绿植租赁-订单管理 @@ -121,6 +124,8 @@ public class PlantsRentalOrderServiceImpl implements IPlantsRentalOrderService { lqw.eq(bo.getIsRelet() != null, PlantsRentalOrder::getIsRelet, bo.getIsRelet()); lqw.eq(bo.getContractStatus() != null, PlantsRentalOrder::getContractStatus, bo.getContractStatus()); lqw.eq(bo.getSignTime() != null, PlantsRentalOrder::getSignTime, bo.getSignTime()); + lqw.in(CollectionUtils.isNotEmpty(bo.getProductIds()),PlantsRentalOrder::getProductId,bo.getProductIds()); + lqw.in(CollectionUtils.isNotEmpty(bo.getPlanIds()),PlantsRentalOrder::getPlanId,bo.getPlanIds()); return lqw; } @@ -191,38 +196,38 @@ public class PlantsRentalOrderServiceImpl implements IPlantsRentalOrderService { public Boolean deleteWithValidByIds(Collection ids, Boolean isValid) { if (isValid) { //有订单收费或订单维护数据不可删除 -// PlantsOrderChargeBo chargeBo = new PlantsOrderChargeBo(); -// chargeBo.setOrderIds(ids.stream().toList()); -// List chargeList = chargeService.queryList(chargeBo); -// PlantsOrderMaintainBo maintainBo = new PlantsOrderMaintainBo(); -// maintainBo.setOrderIds(ids.stream().toList()); -// List maintainList = maintainService.queryList(maintainBo); -// if(CollectionUtils.isNotEmpty(maintainList)||CollectionUtils.isNotEmpty(chargeList)){ -// throw new ServiceException("所选订单不可删除"); -// }else { -// //恢复产品库存 -// ArrayList productList = new ArrayList<>(); -// for (Long id : ids) { -// PlantsRentalOrder order = baseMapper.selectById(id); -// if("1".equals(order.getRentalType())){ -// Long productId = order.getProductId(); -// Integer productNum = order.getProductNum(); -// productList.add(new PlantsProductBo(productId,productNum)); -// }else { -// Long planId = order.getPlanId(); -// List planProductVos = planProductService.queryPlanProductsInfo(planId); -// for (PlantsPlanProductVo planProductVo : planProductVos) { -// productList.add(new PlantsProductBo(planProductVo.getProductId(),planProductVo.getProductNum())); -// } -// } -// } -// if(CollectionUtils.isNotEmpty(productList)){ -// Boolean b = productService.addStock(productList); -// if(!b){ -// throw new ServiceException("删除订单失败。"); -// } -// } -// } + PlantsOrderChargeBo chargeBo = new PlantsOrderChargeBo(); + chargeBo.setOrderIds(ids.stream().toList()); + List chargeList = chargeService.queryList(chargeBo); + PlantsOrderMaintainBo maintainBo = new PlantsOrderMaintainBo(); + maintainBo.setOrderIds(ids.stream().toList()); + List maintainList = maintainService.queryList(maintainBo); + if(CollectionUtils.isNotEmpty(maintainList)||CollectionUtils.isNotEmpty(chargeList)){ + throw new ServiceException("所选订单不可删除"); + }else { + //恢复产品库存 + ArrayList productList = new ArrayList<>(); + for (Long id : ids) { + PlantsRentalOrder order = baseMapper.selectById(id); + if("1".equals(order.getRentalType())){ + Long productId = order.getProductId(); + Integer productNum = order.getProductNum(); + productList.add(new PlantsProductBo(productId,productNum)); + }else { + Long planId = order.getPlanId(); + List planProductVos = planProductService.queryPlanProductsInfo(planId); + for (PlantsPlanProductVo planProductVo : planProductVos) { + productList.add(new PlantsProductBo(planProductVo.getProductId(),planProductVo.getProductNum())); + } + } + } + if(CollectionUtils.isNotEmpty(productList)){ + Boolean b = productService.addStock(productList); + if(!b){ + throw new ServiceException("删除订单失败。"); + } + } + } } return baseMapper.deleteByIds(ids) > 0; } @@ -393,4 +398,18 @@ public class PlantsRentalOrderServiceImpl implements IPlantsRentalOrderService { public Map countOrderAndAmount() { return baseMapper.countOrderAndAmount(); } + + + /** + * 统计下单客户总数 + * @return + */ + @Override + public Map countCustomers() { + LambdaQueryWrapper lqw = Wrappers.lambdaQuery(); + lqw.groupBy(PlantsRentalOrder::getCustomerName); + Map map = new HashMap<>(); + map.put("count",baseMapper.selectVoList(lqw).size()); + return map; + } } diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/PlantsRentalPlanServiceImpl.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/PlantsRentalPlanServiceImpl.java index 9cddaa3..d63c627 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/PlantsRentalPlanServiceImpl.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/PlantsRentalPlanServiceImpl.java @@ -1,6 +1,7 @@ package org.dromara.property.service.impl; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; +import org.dromara.common.core.exception.ServiceException; import org.dromara.common.core.utils.MapstructUtils; import org.dromara.common.core.utils.StringUtils; import org.dromara.common.mybatis.core.page.TableDataInfo; @@ -12,9 +13,12 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.dromara.property.domain.PlantsPlanProduct; import org.dromara.property.domain.bo.PlantsPlanProductBo; +import org.dromara.property.domain.bo.PlantsRentalOrderBo; import org.dromara.property.domain.vo.PlantsPlanProductVo; +import org.dromara.property.domain.vo.PlantsRentalOrderVo; import org.dromara.property.service.IPlantsPlanProductService; import org.dromara.property.service.IPlantsProductService; +import org.dromara.property.service.IPlantsRentalOrderService; import org.springframework.stereotype.Service; import org.dromara.property.domain.bo.PlantsRentalPlanBo; import org.dromara.property.domain.vo.PlantsRentalPlanVo; @@ -39,6 +43,8 @@ public class PlantsRentalPlanServiceImpl implements IPlantsRentalPlanService { private final IPlantsPlanProductService planProductService; + private final IPlantsRentalOrderService rentalOrderService; + /** * 查询绿植租赁-租赁方案 * @@ -162,7 +168,12 @@ public class PlantsRentalPlanServiceImpl implements IPlantsRentalPlanService { @Override public Boolean deleteWithValidByIds(Collection ids, Boolean isValid) { if(isValid){ - //TODO 做一些业务上的校验,判断是否需要校验 + PlantsRentalOrderBo plantsRentalOrderBo = new PlantsRentalOrderBo(); + plantsRentalOrderBo.setPlanIds(ids.stream().toList()); + List plantsRentalOrderVos = rentalOrderService.queryList(plantsRentalOrderBo); + if(CollectionUtils.isNotEmpty(plantsRentalOrderVos)){ + throw new ServiceException("当前选中租赁方案不可删除"); + } } return baseMapper.deleteByIds(ids) > 0; }