diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/controller/PlantsOrderMaintainController.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/controller/PlantsOrderMaintainController.java index 0f0239a..115e5e3 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/controller/PlantsOrderMaintainController.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/controller/PlantsOrderMaintainController.java @@ -1,6 +1,7 @@ package org.dromara.property.controller; import java.util.List; +import java.util.Map; import lombok.RequiredArgsConstructor; import jakarta.servlet.http.HttpServletResponse; @@ -103,4 +104,35 @@ public class PlantsOrderMaintainController extends BaseController { @PathVariable("ids") Long[] ids) { return toAjax(plantsOrderMaintainService.deleteWithValidByIds(List.of(ids), true)); } + + + /** + * 按用户评分统计养护 + * @return + */ + @GetMapping("/countByCusScore") + public R countByCusScore(){ + return R.ok(plantsOrderMaintainService.countByCusScore()); + } + + /** + * 统计养护完成情况 + * @return + */ + @GetMapping("/countAchieved") + public R countAchieved(){ + return R.ok(plantsOrderMaintainService.countAchieved()); + } + + /** + * 计算绿植养护完成率 + * @return + */ + @GetMapping("/countAchievedRate") + public R countAchievedRate(){ + return R.ok(plantsOrderMaintainService.countAchievedRate()); + } + + + } 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 112f5ea..25ff229 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 @@ -117,11 +117,42 @@ public class PlantsRentalOrderController extends BaseController { } /** - *按用户类型统计 + *按用户类型统计订单数 * @return */ @GetMapping("/countByCusType") public R countByCusType(){ return R.ok(plantsRentalOrderService.countByCusType()); } + + /** + * 客户续租率统计 + * @return + */ + @GetMapping("/countRenewRate") + public R countRenewRate(){ + return R.ok(plantsRentalOrderService.countRenewRate()); + } + + /** + * 按租赁方式统计租赁金额 + * @return + */ + @GetMapping("/countByRentalType") + public R countByRentalType(){ + return R.ok(plantsRentalOrderService.countByRentalType()); + } + + + /** + * 统计订单总数和租赁金额总数 + * @return + */ + @GetMapping("/countOrderAndAmount") + public R countOrderAndAmount(){ + return R.ok(plantsRentalOrderService.countOrderAndAmount()); + } + + + } diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/PlantsOrderCharge.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/PlantsOrderCharge.java index 1da70d9..1630f16 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/PlantsOrderCharge.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/PlantsOrderCharge.java @@ -4,6 +4,8 @@ import org.dromara.common.mybatis.core.domain.BaseEntity; import com.baomidou.mybatisplus.annotation.*; import lombok.Data; import lombok.EqualsAndHashCode; + +import java.math.BigDecimal; import java.util.Date; import com.fasterxml.jackson.annotation.JsonFormat; @@ -47,22 +49,22 @@ public class PlantsOrderCharge extends BaseEntity { /** * 租金 */ - private Long rent; + private BigDecimal rent; /** * 押金 */ - private Long deposit; + private BigDecimal deposit; /** * 违约金 */ - private Long penalty; + private BigDecimal penalty; /** * 总金额 */ - private Long totalAmount; + private BigDecimal totalAmount; /** * 收费日期 diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/PlantsPlanProduct.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/PlantsPlanProduct.java index 6a76f24..d4734c3 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/PlantsPlanProduct.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/PlantsPlanProduct.java @@ -37,5 +37,10 @@ public class PlantsPlanProduct extends BaseEntity { */ private Long productId; + /** + * 绿植产品数量 + */ + private Integer productNum; + } diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/PlantsProduct.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/PlantsProduct.java index 31afe5b..0df44cd 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/PlantsProduct.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/PlantsProduct.java @@ -74,3 +74,5 @@ public class PlantsProduct extends BaseEntity { } + + diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/bo/PlantsOrderChargeBo.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/bo/PlantsOrderChargeBo.java index 4bcf0a0..119a8cd 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/bo/PlantsOrderChargeBo.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/bo/PlantsOrderChargeBo.java @@ -8,6 +8,8 @@ import io.github.linpeilie.annotations.AutoMapper; import lombok.Data; import lombok.EqualsAndHashCode; import jakarta.validation.constraints.*; + +import java.math.BigDecimal; import java.util.Date; import com.fasterxml.jackson.annotation.JsonFormat; @@ -49,25 +51,24 @@ public class PlantsOrderChargeBo extends BaseEntity { * 租金 */ @NotNull(message = "租金不能为空", groups = { AddGroup.class, EditGroup.class }) - private Long rent; + private BigDecimal rent; /** * 押金 */ @NotNull(message = "押金不能为空", groups = { AddGroup.class, EditGroup.class }) - private Long deposit; + private BigDecimal deposit; /** * 违约金 */ @NotNull(message = "违约金不能为空", groups = { AddGroup.class, EditGroup.class }) - private Long penalty; + private BigDecimal penalty; /** * 总金额 */ - @NotNull(message = "总金额不能为空", groups = { AddGroup.class, EditGroup.class }) - private Long totalAmount; + private BigDecimal totalAmount; /** * 收费日期 diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/bo/PlantsOrderMaintainBo.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/bo/PlantsOrderMaintainBo.java index a187755..98fb3a8 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/bo/PlantsOrderMaintainBo.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/bo/PlantsOrderMaintainBo.java @@ -36,19 +36,19 @@ public class PlantsOrderMaintainBo extends BaseEntity { /** * 小区id */ - @NotNull(message = "小区id不能为空", groups = { AddGroup.class, EditGroup.class }) + private Long communityId; /** * 建筑id */ - @NotNull(message = "建筑id不能为空", groups = { AddGroup.class, EditGroup.class }) + private Long buildingId; /** * 楼层id */ - @NotNull(message = "楼层id不能为空", groups = { AddGroup.class, EditGroup.class }) + private Long floorId; /** 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 bfc3236..0590e09 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 @@ -23,7 +23,6 @@ public class PlantsPlanProductBo extends BaseEntity { /** * 主键 */ - @NotNull(message = "主键不能为空", groups = { EditGroup.class }) private Long id; /** @@ -38,5 +37,11 @@ public class PlantsPlanProductBo extends BaseEntity { @NotNull(message = "绿植产品id不能为空", groups = { AddGroup.class, EditGroup.class }) private Long productId; + /** + * 绿植产品数量 + */ + @NotNull(message = "产品数量不能为空", groups = { AddGroup.class, EditGroup.class }) + private Integer productNum; + } diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/bo/PlantsProductBo.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/bo/PlantsProductBo.java index 491ef00..e9b5c54 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/bo/PlantsProductBo.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/bo/PlantsProductBo.java @@ -1,5 +1,7 @@ package org.dromara.property.domain.bo; +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; import org.dromara.property.domain.PlantsProduct; import org.dromara.common.mybatis.core.domain.BaseEntity; import org.dromara.common.core.validate.AddGroup; @@ -15,6 +17,8 @@ import jakarta.validation.constraints.*; * @author mocheng * @date 2025-06-25 */ +@AllArgsConstructor +@NoArgsConstructor @Data @EqualsAndHashCode(callSuper = true) @AutoMapper(target = PlantsProduct.class, reverseConvertGenerate = false) @@ -29,7 +33,6 @@ public class PlantsProductBo extends BaseEntity { /** * 产品编号 */ - @NotBlank(message = "产品编号不能为空", groups = { AddGroup.class, EditGroup.class }) private String plantCode; /** @@ -78,5 +81,9 @@ public class PlantsProductBo extends BaseEntity { */ private String remark; + public PlantsProductBo(Long id, Long inventory) { + this.id = id; + this.inventory = inventory; + } } 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 e5cb20c..573018f 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 @@ -1,5 +1,7 @@ package org.dromara.property.domain.bo; +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; import org.dromara.property.domain.PlantsRentalOrder; import org.dromara.common.mybatis.core.domain.BaseEntity; import org.dromara.common.core.validate.AddGroup; @@ -9,6 +11,8 @@ import lombok.Data; import lombok.EqualsAndHashCode; import jakarta.validation.constraints.*; import java.util.Date; +import java.util.List; + import com.fasterxml.jackson.annotation.JsonFormat; /** @@ -17,6 +21,8 @@ import com.fasterxml.jackson.annotation.JsonFormat; * @author mocheng * @date 2025-06-30 */ +@AllArgsConstructor +@NoArgsConstructor @Data @EqualsAndHashCode(callSuper = true) @AutoMapper(target = PlantsRentalOrder.class, reverseConvertGenerate = false) @@ -114,7 +120,9 @@ public class PlantsRentalOrderBo extends BaseEntity { */ private Date signTime; - - + /** + * 产品 + */ + private List productList; } diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/bo/PlantsRentalPlanBo.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/bo/PlantsRentalPlanBo.java index 6b046f4..7256061 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/bo/PlantsRentalPlanBo.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/bo/PlantsRentalPlanBo.java @@ -63,10 +63,10 @@ public class PlantsRentalPlanBo extends BaseEntity { private String remarks; /** - * 产品id + * 绿植产品 */ @NotNull(message = "绿植产品不能为空", groups = { AddGroup.class, EditGroup.class }) - private List productIds; + private List productList; } diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/vo/PlantsOrderChargeVo.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/vo/PlantsOrderChargeVo.java index 61e18d8..8d2da1a 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/vo/PlantsOrderChargeVo.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/vo/PlantsOrderChargeVo.java @@ -1,6 +1,10 @@ package org.dromara.property.domain.vo; +import java.math.BigDecimal; import java.util.Date; + +import com.baomidou.mybatisplus.annotation.FieldFill; +import com.baomidou.mybatisplus.annotation.TableField; import com.fasterxml.jackson.annotation.JsonFormat; import org.dromara.property.domain.PlantsOrderCharge; import cn.idev.excel.annotation.ExcelIgnoreUnannotated; @@ -59,25 +63,25 @@ public class PlantsOrderChargeVo implements Serializable { * 租金 */ @ExcelProperty(value = "租金") - private Long rent; + private BigDecimal rent; /** * 押金 */ @ExcelProperty(value = "押金") - private Long deposit; + private BigDecimal deposit; /** * 违约金 */ @ExcelProperty(value = "违约金") - private Long penalty; + private BigDecimal penalty; /** * 总金额 */ @ExcelProperty(value = "总金额") - private Long totalAmount; + private BigDecimal totalAmount; /** * 收费日期 @@ -112,5 +116,15 @@ public class PlantsOrderChargeVo implements Serializable { @ExcelDictFormat(dictType = "pro_charging_status") private Long chargeStatus; + /** + * 创建时间 + */ + private Date createTime; + + /** + * 租赁订单 + */ + private PlantsRentalOrderVo rentalOrder; + } diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/vo/PlantsPlanProductVo.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/vo/PlantsPlanProductVo.java index 46f1ea7..2986c90 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/vo/PlantsPlanProductVo.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/domain/vo/PlantsPlanProductVo.java @@ -46,6 +46,11 @@ public class PlantsPlanProductVo implements Serializable { @ExcelProperty(value = "绿植产品id") private Long productId; + /** + * 绿植产品数量 + */ + private Integer productNum; + /** * 创建时间 */ diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/mapper/PlantsOrderMaintainMapper.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/mapper/PlantsOrderMaintainMapper.java index 4ab6ad0..b5d968d 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/mapper/PlantsOrderMaintainMapper.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/mapper/PlantsOrderMaintainMapper.java @@ -1,9 +1,13 @@ package org.dromara.property.mapper; +import org.apache.ibatis.annotations.Select; import org.dromara.property.domain.PlantsOrderMaintain; import org.dromara.property.domain.vo.PlantsOrderMaintainVo; import org.dromara.common.mybatis.core.mapper.BaseMapperPlus; +import java.util.List; +import java.util.Map; + /** * 绿植租赁-订单养护管理Mapper接口 * @@ -12,4 +16,27 @@ import org.dromara.common.mybatis.core.mapper.BaseMapperPlus; */ public interface PlantsOrderMaintainMapper extends BaseMapperPlus { + @Select("SELECT " + + "(CASE WHEN 1 THEN '一星'" + + "WHEN 2 THEN '二星'" + + "WHEN 3 THEN '三星'" + + "WHEN 4 THEN '四星'" + + "WHEN 5 THEN '五星' END) AS score, " + + "COUNT(*) AS count " + + "FROM plants_order_maintain " + + "GROUP BY customer_score ORDER BY customer_score") + List> countByCusScore(); + + + @Select("SELECT serve_type AS type," + + "COUNT(*) AS total," + + "SUM(CASE WHEN state ='2' THEN 1 ELSE 0 END) AS finish," + + "ROUND(SUM(CASE WHEN state ='2' THEN 1 ELSE 0 END) * 100/NULLIF(COUNT(*),0),0) AS rate " + + "FROM plants_order_maintain" + + "GROUP BY serve_type") + List> countAchieved(); + + @Select("SELECT ROUND(SUM(CASE WHEN state ='2' THEN 1 ELSE 0 END) * 100/NULLIF(COUNT(*),0),1) AS rate " + + "FROM plants_order_maintain") + Double countAchievedRate(); } diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/mapper/PlantsRentalOrderMapper.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/mapper/PlantsRentalOrderMapper.java index b456d18..ee69c39 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/mapper/PlantsRentalOrderMapper.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/mapper/PlantsRentalOrderMapper.java @@ -22,14 +22,11 @@ public interface PlantsRentalOrderMapper extends BaseMapperPlus> countByDay(); - @Select("SELECT " + - "CASE DAYOFWEEK(create_time) AS week," + - "COUNT(*) AS count" + + @Select("SELECT DAYOFWEEK(create_time) AS week, COUNT(*) AS count " + "FROM plants_rental_order " + - "WHERE create_time >= DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) DAY) " + - "AND create_time < DATE_ADD(DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) DAY), INTERVAL 7 DAY) " + - "GROUP BY DATE(create_time) " + - "ORDER BY day") + "WHERE create_time >= DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) DAY)" + + "AND create_time < DATE_ADD(DATE_SUB(CURDATE(), INTERVAL WEEKDAY(CURDATE()) DAY), INTERVAL 7 DAY)" + + "GROUP BY week ORDER BY week") List> countByWeek(); @Select("SELECT DAY(create_time) AS day, COUNT(*) AS count " + @@ -40,4 +37,28 @@ public interface PlantsRentalOrderMapper extends BaseMapperPlus> countByMonth(); + @Select("SELECT customer_type AS type, COUNT(*) AS count " + + "FROM plants_rental_order " + + "GROUP BY customer_type") + List> countByCusType(); + + @Select("SELECT MONTH(create_time) AS month," + + "ROUND(SUM(CASE WHEN is_relet = 1 THEN 1 ELSE 0 END) * 100/NULLIF(COUNT(*),0),0) AS rate " + + "FROM plants_rental_order WHERE YEAR(create_time) = YEAR(CURDATE())"+ + "GROUP BY MONTH(create_time)" + + "ORDER BY month") + List> countRenewRate(); + + + @Select("SELECT (CASE WHEN rental_type=1 THEN '单点' ELSE '套餐' END) AS type, " + + "COUNT(total_amount) AS amount " + + "FROM plants_rental_order " + + "GROUP BY rental_type") + List> countByRentalType(); + + @Select("SELECT COUNT(*) AS num, " + + "COUNT(total_amount) AS amount " + + "FROM plants_rental_order") + Map countOrderAndAmount(); + } diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/service/IPlantsOrderMaintainService.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/service/IPlantsOrderMaintainService.java index 18ac94d..6b83220 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/service/IPlantsOrderMaintainService.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/service/IPlantsOrderMaintainService.java @@ -8,6 +8,7 @@ import org.dromara.common.mybatis.core.page.PageQuery; import java.util.Collection; import java.util.List; +import java.util.Map; /** * 绿植租赁-订单养护管理Service接口 @@ -66,4 +67,22 @@ public interface IPlantsOrderMaintainService { * @return 是否删除成功 */ Boolean deleteWithValidByIds(Collection ids, Boolean isValid); + + /** + * 按用户评分统计 + * @return + */ + List> countByCusScore(); + + /** + * 统计养护完成情况 + * @return + */ + Map countAchieved(); + + /** + * 计算绿植养护完成率 + * @return + */ + String countAchievedRate(); } diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/service/IPlantsProductService.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/service/IPlantsProductService.java index 7a75030..77a1a08 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/service/IPlantsProductService.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/service/IPlantsProductService.java @@ -66,4 +66,11 @@ public interface IPlantsProductService { * @return 是否删除成功 */ Boolean deleteWithValidByIds(Collection ids, Boolean isValid); + + /** + * 扣除商品库存 + * @param products 商品 + * @return 是否扣除成功 + */ + Boolean deductStock(List products); } 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 2a30378..bcf3c48 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 @@ -80,4 +80,26 @@ public interface IPlantsRentalOrderService { * @return */ Map countByCusType(); + + + /** + * 客户续租率统计 + * @return + */ + Map countRenewRate(); + + /** + * 按租赁方式统计订单数 + * @return + */ + List> countByRentalType(); + + + /** + * 统计订单总数和租赁金额总数 + * @return + */ + Map countOrderAndAmount(); + + } diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/PlantsOrderChargeServiceImpl.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/PlantsOrderChargeServiceImpl.java index 7105a3b..c948108 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/PlantsOrderChargeServiceImpl.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/PlantsOrderChargeServiceImpl.java @@ -9,6 +9,8 @@ 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.vo.PlantsRentalOrderVo; +import org.dromara.property.service.IPlantsRentalOrderService; import org.springframework.stereotype.Service; import org.dromara.property.domain.bo.PlantsOrderChargeBo; import org.dromara.property.domain.vo.PlantsOrderChargeVo; @@ -33,6 +35,7 @@ public class PlantsOrderChargeServiceImpl implements IPlantsOrderChargeService { private final PlantsOrderChargeMapper baseMapper; + private final IPlantsRentalOrderService plantsRentalOrderService; /** * 查询绿植租赁-订单收费 * @@ -41,7 +44,12 @@ public class PlantsOrderChargeServiceImpl implements IPlantsOrderChargeService { */ @Override public PlantsOrderChargeVo queryById(Long id){ - return baseMapper.selectVoById(id); + PlantsOrderChargeVo orderChargeVo = baseMapper.selectVoById(id); + if(orderChargeVo!=null&&orderChargeVo.getOrderId()!=null){ + PlantsRentalOrderVo orderVo = plantsRentalOrderService.queryById(orderChargeVo.getOrderId()); + orderChargeVo.setRentalOrder(orderVo); + } + return orderChargeVo; } /** @@ -123,7 +131,9 @@ public class PlantsOrderChargeServiceImpl implements IPlantsOrderChargeService { * 保存前的数据校验 */ private void validEntityBeforeSave(PlantsOrderCharge entity){ - //TODO 做一些数据校验,如唯一约束 + if(entity.getRent()!=null&&entity.getDeposit()!=null&&entity.getPenalty()!=null){ + entity.setTotalAmount(entity.getRent().add(entity.getDeposit()).add(entity.getPenalty())); + } } /** diff --git a/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/PlantsOrderMaintainServiceImpl.java b/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/PlantsOrderMaintainServiceImpl.java index fc46218..e75082c 100644 --- a/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/PlantsOrderMaintainServiceImpl.java +++ b/ruoyi-modules/Property/src/main/java/org/dromara/property/service/impl/PlantsOrderMaintainServiceImpl.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; @@ -9,6 +10,8 @@ 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.system.api.RemoteDictService; +import org.dromara.system.api.domain.vo.RemoteDictDataVo; import org.springframework.stereotype.Service; import org.dromara.property.domain.bo.PlantsOrderMaintainBo; import org.dromara.property.domain.vo.PlantsOrderMaintainVo; @@ -16,9 +19,7 @@ import org.dromara.property.domain.PlantsOrderMaintain; import org.dromara.property.mapper.PlantsOrderMaintainMapper; import org.dromara.property.service.IPlantsOrderMaintainService; -import java.util.List; -import java.util.Map; -import java.util.Collection; +import java.util.*; /** * 绿植租赁-订单养护管理Service业务层处理 @@ -33,6 +34,8 @@ public class PlantsOrderMaintainServiceImpl implements IPlantsOrderMaintainServi private final PlantsOrderMaintainMapper baseMapper; + private final RemoteDictService dictService; + /** * 查询绿植租赁-订单养护管理 * @@ -40,7 +43,7 @@ public class PlantsOrderMaintainServiceImpl implements IPlantsOrderMaintainServi * @return 绿植租赁-订单养护管理 */ @Override - public PlantsOrderMaintainVo queryById(Long id){ + public PlantsOrderMaintainVo queryById(Long id) { return baseMapper.selectVoById(id); } @@ -125,7 +128,7 @@ public class PlantsOrderMaintainServiceImpl implements IPlantsOrderMaintainServi /** * 保存前的数据校验 */ - private void validEntityBeforeSave(PlantsOrderMaintain entity){ + private void validEntityBeforeSave(PlantsOrderMaintain entity) { //TODO 做一些数据校验,如唯一约束 } @@ -138,9 +141,73 @@ public class PlantsOrderMaintainServiceImpl implements IPlantsOrderMaintainServi */ @Override public Boolean deleteWithValidByIds(Collection ids, Boolean isValid) { - if(isValid){ + if (isValid) { //TODO 做一些业务上的校验,判断是否需要校验 } return baseMapper.deleteByIds(ids) > 0; } + + /** + * 按用户评分统计 + * + * @return + */ + @Override + public List> countByCusScore() { + List> maps = baseMapper.countByCusScore(); + return maps; + } + + /** + * 统计养护完成情况 + * + * @return + */ + @Override + public Map countAchieved() { + List type = new ArrayList<>(); + List total = new ArrayList<>(); + List finish = new ArrayList<>(); + List rate = new ArrayList<>(); + List typeList = dictService.selectDictDataByType(""); + if (CollectionUtils.isNotEmpty(typeList)) { + typeList.forEach(item -> { + type.add(item.getDictValue()); + }); + total.addAll(Collections.nCopies(typeList.size(), 0)); + finish.addAll(Collections.nCopies(typeList.size(), 0)); + rate.addAll(Collections.nCopies(typeList.size(), 0)); + List> maps = baseMapper.countAchieved(); + maps.forEach(item -> { + String typeVal = item.get("type").toString(); + int index = type.indexOf(typeVal); + int totalVal = Integer.valueOf(item.get("total").toString()); + int finishVal = Integer.valueOf(item.get("finish").toString()); + int rateVal = Integer.valueOf(item.get("rate").toString()); + total.set(index, totalVal); + finish.set(index, finishVal); + rate.set(index, rateVal); + }); + } + Map map = new HashMap<>(); + map.put("type", type); + map.put("total", total); + map.put("finish", finish); + map.put("rate", rate); + return map; + } + + /** + * 计算绿植养护完成率 + * + * @return 绿植养护完成率 + */ + @Override + public String countAchievedRate() { + Double rate = baseMapper.countAchievedRate(); + if (rate != null) { + return rate + "%"; + } + return "0%"; + } } 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 dca59e3..ae4f92c 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 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; @@ -15,6 +16,7 @@ import org.dromara.property.domain.vo.PlantsProductVo; import org.dromara.property.domain.PlantsProduct; import org.dromara.property.mapper.PlantsProductMapper; import org.dromara.property.service.IPlantsProductService; +import org.springframework.transaction.annotation.Transactional; import java.util.List; import java.util.Map; @@ -40,7 +42,7 @@ public class PlantsProductServiceImpl implements IPlantsProductService { * @return 绿植租赁-绿植产品 */ @Override - public PlantsProductVo queryById(Long id){ + public PlantsProductVo queryById(Long id) { return baseMapper.selectVoById(id); } @@ -81,7 +83,7 @@ public class PlantsProductServiceImpl implements IPlantsProductService { lqw.eq(StringUtils.isNotBlank(bo.getSpecification()), PlantsProduct::getSpecification, bo.getSpecification()); lqw.eq(bo.getRent() != null, PlantsProduct::getRent, bo.getRent()); lqw.eq(bo.getState() != null, PlantsProduct::getState, bo.getState()); - lqw.gt(bo.getInventory()!=null,PlantsProduct::getInventory, bo.getInventory()); + lqw.gt(bo.getInventory() != null, PlantsProduct::getInventory, bo.getInventory()); return lqw; } @@ -98,7 +100,7 @@ public class PlantsProductServiceImpl implements IPlantsProductService { boolean flag = baseMapper.insert(add) > 0; if (flag) { bo.setId(add.getId()); - add.setPlantCode("LZ"+add.getId()); + add.setPlantCode("LZ" + add.getId()); baseMapper.updateById(add); } return flag; @@ -120,7 +122,7 @@ public class PlantsProductServiceImpl implements IPlantsProductService { /** * 保存前的数据校验 */ - private void validEntityBeforeSave(PlantsProduct entity){ + private void validEntityBeforeSave(PlantsProduct entity) { //TODO 做一些数据校验,如唯一约束 } @@ -133,9 +135,31 @@ public class PlantsProductServiceImpl implements IPlantsProductService { */ @Override public Boolean deleteWithValidByIds(Collection ids, Boolean isValid) { - if(isValid){ + if (isValid) { //TODO 做一些业务上的校验,判断是否需要校验 } return baseMapper.deleteByIds(ids) > 0; } + + /** + * 扣除商品库存 + * + * @param products 商品 + * @return 是否扣除成功 + */ + @Transactional(rollbackFor = Exception.class) + @Override + public Boolean deductStock(List products) { + Boolean flag = false; + for (PlantsProductBo product : products) { + PlantsProduct p = baseMapper.selectById(product.getId()); + if (p.getInventory() >= product.getInventory()) { + p.setInventory(p.getInventory() - product.getInventory()); + flag = baseMapper.updateById(p) > 0; + } else { + throw new ServiceException("绿植产品" + p.getPlantName() + "库存不足,无法租赁。"); + } + } + return flag; + } } 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 434e151..5ee1f4c 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 @@ -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; @@ -10,6 +11,11 @@ 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.PlantsProductBo; +import org.dromara.property.service.IPlantsProductService; +import org.dromara.system.api.RemoteDictService; +import org.dromara.system.api.domain.vo.RemoteDictDataVo; import org.springframework.stereotype.Service; import org.dromara.property.domain.bo.PlantsRentalOrderBo; import org.dromara.property.domain.vo.PlantsRentalOrderVo; @@ -33,6 +39,10 @@ public class PlantsRentalOrderServiceImpl implements IPlantsRentalOrderService { private final PlantsRentalOrderMapper baseMapper; + private final RemoteDictService dictService; + + private final IPlantsProductService productService; + /** * 查询绿植租赁-订单管理 * @@ -101,7 +111,7 @@ public class PlantsRentalOrderServiceImpl implements IPlantsRentalOrderService { @Override public Boolean insertByBo(PlantsRentalOrderBo bo) { PlantsRentalOrder add = MapstructUtils.convert(bo, PlantsRentalOrder.class); - validEntityBeforeSave(add); + validEntityBeforeSave(bo); boolean flag = baseMapper.insert(add) > 0; if (flag) { bo.setId(add.getId()); @@ -120,15 +130,32 @@ public class PlantsRentalOrderServiceImpl implements IPlantsRentalOrderService { @Override public Boolean updateByBo(PlantsRentalOrderBo bo) { PlantsRentalOrder update = MapstructUtils.convert(bo, PlantsRentalOrder.class); - validEntityBeforeSave(update); return baseMapper.updateById(update) > 0; } /** * 保存前的数据校验 */ - private void validEntityBeforeSave(PlantsRentalOrder entity) { - //TODO 做一些数据校验,如唯一约束 + private void validEntityBeforeSave(PlantsRentalOrderBo bo) { + //租赁方式 1单点 2套餐 + if ("1".equals(bo.getRentalType())) { + if (bo.getProductId() != null&&bo.getProductNum()!=null) { + ArrayList products = new ArrayList<>(); + PlantsProductBo plantsProduct = new PlantsProductBo(bo.getProductId(),bo.getProductNum()); + products.add(plantsProduct); + productService.deductStock(products); + }else { + throw new ServiceException("租赁产品不能为空"); + } + } else { + List productList = bo.getProductList(); + if(CollectionUtils.isNotEmpty(productList)){ + productService.deductStock(productList); + }else { + throw new ServiceException("租赁套餐不能为空"); + } + } + } /** @@ -197,17 +224,15 @@ public class PlantsRentalOrderServiceImpl implements IPlantsRentalOrderService { List> maps = baseMapper.countByWeek(); String[] time = new String[]{"周一", "周二", "周三", "周四", "周五", "周六", "周日"}; List counts = new ArrayList<>(Collections.nCopies(7, 0)); - for (int i = 0; i < maps.size(); i++) { - if (i == 0) { - int count = Integer.valueOf(maps.get(i).get("count").toString()); - counts.set(6, count); - } else if (i + 1 < maps.size()) { - int week = Integer.valueOf(maps.get(i + 1).get("week").toString()); - int count = Integer.valueOf(maps.get(i + 1).get("count").toString()); - counts.set(week, count); + maps.forEach(item -> { + int week = Integer.valueOf(item.get("week").toString()); + int count = Integer.valueOf(item.get("count").toString()); + if (week == 1) { + counts.set(7, count); + } else if (week > 1 && week < 7) { + counts.set(week - 2, count); } - - } + }); Map map = new HashMap<>(); map.put("time", Arrays.asList(time)); map.put("counts", counts); @@ -216,14 +241,15 @@ public class PlantsRentalOrderServiceImpl implements IPlantsRentalOrderService { /** * 统计月订单数 + * * @return */ public Map countByMonth() { List> maps = baseMapper.countByMonth(); int days = YearMonth.now().lengthOfMonth(); List time = new ArrayList<>(); - for (int i = 1; i <=days; i++) { - time.add(i); + for (int i = 1; i <= days; i++) { + time.add(i); } List counts = new ArrayList<>(Collections.nCopies(days, 0)); maps.forEach(item -> { @@ -239,8 +265,78 @@ public class PlantsRentalOrderServiceImpl implements IPlantsRentalOrderService { return map; } + /** + * 按客户类型统计订单数 + * + * @return + */ @Override public Map countByCusType() { - return Map.of(); + List type = new ArrayList<>(); + List counts = new ArrayList<>(); + List typeList = dictService.selectDictDataByType("wy_khlx"); + if (CollectionUtils.isNotEmpty(typeList)) { + counts.addAll(Collections.nCopies(typeList.size(), 0)); + typeList.forEach(item -> { + type.add(item.getDictValue()); + }); + List> maps = baseMapper.countByCusType(); + maps.forEach(item -> { + String typeVal = item.get("type").toString(); + int index = type.indexOf(typeVal); + int count = Integer.valueOf(item.get("count").toString()); + counts.set(index, count); + }); + } + Map map = new HashMap<>(); + map.put("type", type); + map.put("counts", counts); + return map; + } + + /** + * 客户续租率统计 + * + * @return + */ + @Override + public Map countRenewRate() { + List monthList = new ArrayList<>(); + for (int i = 1; i <= 12; i++) { + monthList.add(i + "月"); + } + List rateList = new ArrayList<>(Collections.nCopies(12, 0)); + List> maps = baseMapper.countRenewRate(); + maps.forEach(item -> { + int month = Integer.valueOf(item.get("month").toString()); + int index = monthList.indexOf(month + "月"); + int rate = Integer.valueOf(item.get("rate").toString()); + rateList.set(index, rate); + }); + Map map = new HashMap<>(); + map.put("month", monthList); + map.put("rate", rateList); + return map; + } + + /** + * 按租赁方式统计订单数 + * + * @return + */ + @Override + public List> countByRentalType() { + List> maps = baseMapper.countByRentalType(); + return maps; + } + + /** + * 统计订单总数和租赁金额总数 + * + * @return + */ + @Override + public Map countOrderAndAmount() { + return baseMapper.countOrderAndAmount(); } } 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 2018b0d..9cddaa3 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 @@ -11,6 +11,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers; 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.vo.PlantsPlanProductVo; import org.dromara.property.service.IPlantsPlanProductService; import org.dromara.property.service.IPlantsProductService; @@ -105,12 +106,13 @@ public class PlantsRentalPlanServiceImpl implements IPlantsRentalPlanService { if (flag) { Long planId = add.getId(); bo.setId(planId); - if(CollectionUtils.isNotEmpty(bo.getProductIds())){ + if(CollectionUtils.isNotEmpty(bo.getProductList())){ List list = new ArrayList<>(); - for (Long productId : bo.getProductIds()) { + for (PlantsPlanProductBo planProductBo : bo.getProductList()) { PlantsPlanProduct planProduct = new PlantsPlanProduct(); planProduct.setPlanId(planId); - planProduct.setProductId(productId); + planProduct.setProductId(planProductBo.getProductId()); + planProduct.setProductNum(planProductBo.getProductNum()); list.add(planProduct); } planProductService.saveBatch(list); @@ -129,12 +131,13 @@ public class PlantsRentalPlanServiceImpl implements IPlantsRentalPlanService { public Boolean updateByBo(PlantsRentalPlanBo bo) { PlantsRentalPlan update = MapstructUtils.convert(bo, PlantsRentalPlan.class); validEntityBeforeSave(update); - if(CollectionUtils.isNotEmpty(bo.getProductIds())){ + if(CollectionUtils.isNotEmpty(bo.getProductList())){ List list = new ArrayList<>(); - for (Long productId : bo.getProductIds()) { + for (PlantsPlanProductBo planProductBo : bo.getProductList()) { PlantsPlanProduct planProduct = new PlantsPlanProduct(); planProduct.setPlanId(update.getId()); - planProduct.setProductId(productId); + planProduct.setProductId(planProductBo.getProductId()); + planProduct.setProductNum(planProductBo.getProductNum()); list.add(planProduct); } planProductService.updateByPlanId(list,update.getId());