1、绿植租赁统计
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled

This commit is contained in:
dev_ljl 2025-07-04 17:59:19 +08:00
parent f9a7990de9
commit 014a157921
23 changed files with 474 additions and 66 deletions

View File

@ -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<List> countByCusScore(){
return R.ok(plantsOrderMaintainService.countByCusScore());
}
/**
* 统计养护完成情况
* @return
*/
@GetMapping("/countAchieved")
public R<Map> countAchieved(){
return R.ok(plantsOrderMaintainService.countAchieved());
}
/**
* 计算绿植养护完成率
* @return
*/
@GetMapping("/countAchievedRate")
public R<String> countAchievedRate(){
return R.ok(plantsOrderMaintainService.countAchievedRate());
}
}

View File

@ -117,11 +117,42 @@ public class PlantsRentalOrderController extends BaseController {
}
/**
*按用户类型统计
*按用户类型统计订单数
* @return
*/
@GetMapping("/countByCusType")
public R<Map> countByCusType(){
return R.ok(plantsRentalOrderService.countByCusType());
}
/**
* 客户续租率统计
* @return
*/
@GetMapping("/countRenewRate")
public R<Map> countRenewRate(){
return R.ok(plantsRentalOrderService.countRenewRate());
}
/**
* 按租赁方式统计租赁金额
* @return
*/
@GetMapping("/countByRentalType")
public R<List> countByRentalType(){
return R.ok(plantsRentalOrderService.countByRentalType());
}
/**
* 统计订单总数和租赁金额总数
* @return
*/
@GetMapping("/countOrderAndAmount")
public R<Map> countOrderAndAmount(){
return R.ok(plantsRentalOrderService.countOrderAndAmount());
}
}

View File

@ -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;
/**
* 收费日期

View File

@ -37,5 +37,10 @@ public class PlantsPlanProduct extends BaseEntity {
*/
private Long productId;
/**
* 绿植产品数量
*/
private Integer productNum;
}

View File

@ -74,3 +74,5 @@ public class PlantsProduct extends BaseEntity {
}

View File

@ -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;
/**
* 收费日期

View File

@ -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;
/**

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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<PlantsProductBo> productList;
}

View File

@ -63,10 +63,10 @@ public class PlantsRentalPlanBo extends BaseEntity {
private String remarks;
/**
* 产品id
* 绿植产品
*/
@NotNull(message = "绿植产品不能为空", groups = { AddGroup.class, EditGroup.class })
private List<Long> productIds;
private List<PlantsPlanProductBo> productList;
}

View File

@ -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;
}

View File

@ -46,6 +46,11 @@ public class PlantsPlanProductVo implements Serializable {
@ExcelProperty(value = "绿植产品id")
private Long productId;
/**
* 绿植产品数量
*/
private Integer productNum;
/**
* 创建时间
*/

View File

@ -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<PlantsOrderMaintain, PlantsOrderMaintainVo> {
@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<Map<String, Object>> 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<Map<String, Object>> 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();
}

View File

@ -22,14 +22,11 @@ public interface PlantsRentalOrderMapper extends BaseMapperPlus<PlantsRentalOrde
"GROUP BY HOUR(create_time)")
List<Map<String, Object>> 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<Map<String, Object>> countByWeek();
@Select("SELECT DAY(create_time) AS day, COUNT(*) AS count " +
@ -40,4 +37,28 @@ public interface PlantsRentalOrderMapper extends BaseMapperPlus<PlantsRentalOrde
"ORDER BY day")
List<Map<String, Object>> countByMonth();
@Select("SELECT customer_type AS type, COUNT(*) AS count " +
"FROM plants_rental_order " +
"GROUP BY customer_type")
List<Map<String, Object>> 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<Map<String, Object>> 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<Map<String, Object>> countByRentalType();
@Select("SELECT COUNT(*) AS num, " +
"COUNT(total_amount) AS amount " +
"FROM plants_rental_order")
Map<String, Object> countOrderAndAmount();
}

View File

@ -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<Long> ids, Boolean isValid);
/**
* 按用户评分统计
* @return
*/
List<Map<String,Object>> countByCusScore();
/**
* 统计养护完成情况
* @return
*/
Map<String,List> countAchieved();
/**
* 计算绿植养护完成率
* @return
*/
String countAchievedRate();
}

View File

@ -66,4 +66,11 @@ public interface IPlantsProductService {
* @return 是否删除成功
*/
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
/**
* 扣除商品库存
* @param products 商品
* @return 是否扣除成功
*/
Boolean deductStock(List<PlantsProductBo> products);
}

View File

@ -80,4 +80,26 @@ public interface IPlantsRentalOrderService {
* @return
*/
Map<String,List> countByCusType();
/**
* 客户续租率统计
* @return
*/
Map<String,List> countRenewRate();
/**
* 按租赁方式统计订单数
* @return
*/
List<Map<String,Object>> countByRentalType();
/**
* 统计订单总数和租赁金额总数
* @return
*/
Map<String,Object> countOrderAndAmount();
}

View File

@ -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()));
}
}
/**

View File

@ -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<Long> ids, Boolean isValid) {
if(isValid){
if (isValid) {
//TODO 做一些业务上的校验,判断是否需要校验
}
return baseMapper.deleteByIds(ids) > 0;
}
/**
* 按用户评分统计
*
* @return
*/
@Override
public List<Map<String, Object>> countByCusScore() {
List<Map<String, Object>> maps = baseMapper.countByCusScore();
return maps;
}
/**
* 统计养护完成情况
*
* @return
*/
@Override
public Map<String, List> countAchieved() {
List<String> type = new ArrayList<>();
List<Object> total = new ArrayList<>();
List<Object> finish = new ArrayList<>();
List<Object> rate = new ArrayList<>();
List<RemoteDictDataVo> 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<Map<String, Object>> 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<String, List> 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%";
}
}

View File

@ -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<Long> 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<PlantsProductBo> 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;
}
}

View File

@ -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<PlantsProductBo> products = new ArrayList<>();
PlantsProductBo plantsProduct = new PlantsProductBo(bo.getProductId(),bo.getProductNum());
products.add(plantsProduct);
productService.deductStock(products);
}else {
throw new ServiceException("租赁产品不能为空");
}
} else {
List<PlantsProductBo> productList = bo.getProductList();
if(CollectionUtils.isNotEmpty(productList)){
productService.deductStock(productList);
}else {
throw new ServiceException("租赁套餐不能为空");
}
}
}
/**
@ -197,17 +224,15 @@ public class PlantsRentalOrderServiceImpl implements IPlantsRentalOrderService {
List<Map<String, Object>> maps = baseMapper.countByWeek();
String[] time = new String[]{"周一", "周二", "周三", "周四", "周五", "周六", "周日"};
List<Integer> 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<String, List> 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<String, List> countByMonth() {
List<Map<String, Object>> maps = baseMapper.countByMonth();
int days = YearMonth.now().lengthOfMonth();
List<Integer> time = new ArrayList<>();
for (int i = 1; i <=days; i++) {
time.add(i);
for (int i = 1; i <= days; i++) {
time.add(i);
}
List<Integer> 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<String, List> countByCusType() {
return Map.of();
List<String> type = new ArrayList<>();
List<Integer> counts = new ArrayList<>();
List<RemoteDictDataVo> typeList = dictService.selectDictDataByType("wy_khlx");
if (CollectionUtils.isNotEmpty(typeList)) {
counts.addAll(Collections.nCopies(typeList.size(), 0));
typeList.forEach(item -> {
type.add(item.getDictValue());
});
List<Map<String, Object>> 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<String, List> map = new HashMap<>();
map.put("type", type);
map.put("counts", counts);
return map;
}
/**
* 客户续租率统计
*
* @return
*/
@Override
public Map<String, List> countRenewRate() {
List<String> monthList = new ArrayList<>();
for (int i = 1; i <= 12; i++) {
monthList.add(i + "");
}
List<Integer> rateList = new ArrayList<>(Collections.nCopies(12, 0));
List<Map<String, Object>> 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<String, List> map = new HashMap<>();
map.put("month", monthList);
map.put("rate", rateList);
return map;
}
/**
* 按租赁方式统计订单数
*
* @return
*/
@Override
public List<Map<String, Object>> countByRentalType() {
List<Map<String, Object>> maps = baseMapper.countByRentalType();
return maps;
}
/**
* 统计订单总数和租赁金额总数
*
* @return
*/
@Override
public Map<String, Object> countOrderAndAmount() {
return baseMapper.countOrderAndAmount();
}
}

View File

@ -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<PlantsPlanProduct> 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<PlantsPlanProduct> 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());