lin
2024-02-26 b9b905a6747ebb6cb50aad43a26610a503416ebb
物业公司居民评价平均分计算
5 files modified
44 ■■■■■ changed files
src/main/java/org/springblade/modules/property/mapper/PropertyCompanyScoreMapper.java 1 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/property/mapper/PropertyCompanyScoreMapper.xml 15 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/property/service/IPropertyCompanyScoreService.java 1 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/property/service/impl/PropertyCompanyCommentServiceImpl.java 22 ●●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/property/service/impl/PropertyCompanyScoreServiceImpl.java 5 ●●●● patch | view | raw | blame | history
src/main/java/org/springblade/modules/property/mapper/PropertyCompanyScoreMapper.java
@@ -40,4 +40,5 @@
    List<PropertyCompanyScoreVO> selectPropertyCompanyScorePage(IPage page, PropertyCompanyScoreVO propertyCompanyScore);
    Integer getScore(Integer propertyCompanyId);
}
src/main/java/org/springblade/modules/property/mapper/PropertyCompanyScoreMapper.xml
@@ -3,7 +3,8 @@
<mapper namespace="org.springblade.modules.property.mapper.PropertyCompanyScoreMapper">
    <!-- 通用查询映射结果 -->
    <resultMap id="propertyCompanyScoreResultMap" type="org.springblade.modules.property.entity.PropertyCompanyScoreEntity">
    <resultMap id="propertyCompanyScoreResultMap"
               type="org.springblade.modules.property.entity.PropertyCompanyScoreEntity">
        <result column="id" property="id"/>
        <result column="property_company_id" property="propertyCompanyId"/>
        <result column="score" property="score"/>
@@ -14,7 +15,17 @@
    <select id="selectPropertyCompanyScorePage" resultMap="propertyCompanyScoreResultMap">
        select * from jczz_property_company_score where is_deleted = 0
        select *
        from jczz_property_company_score
        where is_deleted = 0
    </select>
    <select id="getScore" resultType="java.lang.Integer">
        select sum(score)
        from jczz_property_company_score
        where is_deleted = 0
          and property_company_id = #{propertyCompanyId}
    </select>
src/main/java/org/springblade/modules/property/service/IPropertyCompanyScoreService.java
@@ -40,4 +40,5 @@
    IPage<PropertyCompanyScoreVO> selectPropertyCompanyScorePage(IPage<PropertyCompanyScoreVO> page, PropertyCompanyScoreVO propertyCompanyScore);
    Integer getScore(Integer propertyCompanyId);
}
src/main/java/org/springblade/modules/property/service/impl/PropertyCompanyCommentServiceImpl.java
@@ -17,13 +17,17 @@
package org.springblade.modules.property.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.logging.log4j.util.Strings;
import org.springblade.common.utils.SpringUtils;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.modules.property.entity.PropertyCompanyCommentEntity;
import org.springblade.modules.property.entity.PropertyCompanyEntity;
import org.springblade.modules.property.entity.PropertyCompanyScoreEntity;
import org.springblade.modules.property.service.IPropertyCompanyScoreService;
import org.springblade.modules.property.service.IPropertyCompanyService;
import org.springblade.modules.property.vo.PropertyCompanyCommentVO;
import org.springblade.modules.property.mapper.PropertyCompanyCommentMapper;
import org.springblade.modules.property.service.IPropertyCompanyCommentService;
@@ -34,6 +38,7 @@
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.Map;
/**
@@ -116,7 +121,22 @@
                // 新增
                 propertyCompanyScoreService.save(propertyCompanyScoreEntity);
            }
            // todo 计算物业公司评价平均分
            // t 计算物业公司评价平均分
            QueryWrapper<PropertyCompanyScoreEntity> queryWrapperTwo = new QueryWrapper<>();
            queryWrapperTwo.eq("is_deleted",0).eq("property_company_id",propertyCompanyComment.getPropertyCompanyId());
            // t统计物业公司总评价数
            long count = propertyCompanyScoreService.count(queryWrapperTwo);
            // 统计物业公司总评价分
            Integer score = propertyCompanyScoreService.getScore(propertyCompanyComment.getPropertyCompanyId());
            // 计算评价分
            BigDecimal divide = BigDecimal.valueOf(score).divide(BigDecimal.valueOf(count));
            // 更新物业评价平均分
            PropertyCompanyEntity propertyCompanyEntity = new PropertyCompanyEntity();
            propertyCompanyEntity.setId(propertyCompanyComment.getPropertyCompanyId());
            propertyCompanyEntity.setEvaluateScore(divide);
            IPropertyCompanyService bean = SpringUtils.getBean(IPropertyCompanyService.class);
            bean.updateById(propertyCompanyEntity);
        }
    }
}
src/main/java/org/springblade/modules/property/service/impl/PropertyCompanyScoreServiceImpl.java
@@ -39,5 +39,8 @@
        return page.setRecords(baseMapper.selectPropertyCompanyScorePage(page, propertyCompanyScore));
    }
    @Override
    public Integer getScore(Integer propertyCompanyId) {
        return baseMapper.getScore(propertyCompanyId);
    }
}