Commit dbabcfe1 authored by jiaorz's avatar jiaorz

点赞评论排序

parent 0b4aee0c
package com.xxfc.platform.activity.constant;
public enum IntegralRulePeriod {
DAY(0, "天"),
WEEK(1, "周"),
MONTH(2, "月"),
QUARTER(3,"季度"),
YEAR(4,"年");
Integer code;
String msg;
IntegralRulePeriod(Integer code, String msg) {
this.code = code;
this.msg = msg;
}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
}
......@@ -3,8 +3,6 @@ package com.xxfc.platform.activity.vo;
import com.github.wxiaoqi.security.common.vo.PageParam;
import lombok.Data;
import java.math.BigDecimal;
@Data
public class IntegralRuleDto extends PageParam {
/**
......@@ -13,4 +11,7 @@ public class IntegralRuleDto extends PageParam {
Integer id;
String code;
Integer userId;
}
......@@ -97,9 +97,6 @@ public class IntegralRuleBiz extends BaseBiz<IntegralRuleMapper, IntegralRule> {
Query query = new Query(integralRule);
PageDataVO<IntegralRule> pageDataVO = PageDataVO.pageInfo(query, () -> mapper.selectAllByParam(integralRule));
//添加个人积分状态
for(IntegralRule value : pageDataVO.getData()) {
value.setIntegralStatus(getIntegralStatus(appUserDTO, value));
}
return ObjectRestResponse.succ(pageDataVO);
}
......
......@@ -7,11 +7,14 @@ import com.github.wxiaoqi.security.common.constant.RestCode;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.github.wxiaoqi.security.common.util.Query;
import com.github.wxiaoqi.security.common.vo.PageDataVO;
import com.xxfc.platform.activity.constant.IntegralRulePeriod;
import com.xxfc.platform.activity.entity.IntegralRule;
import com.xxfc.platform.activity.entity.IntegralUserRecord;
import com.xxfc.platform.activity.entity.IntegralUserStatus;
import com.xxfc.platform.activity.entity.IntegralUserTotal;
import com.xxfc.platform.activity.mapper.IntegralUserRecordMapper;
import com.xxfc.platform.activity.user.UserInfoBiz;
import com.xxfc.platform.activity.util.IntegralToolsUtils;
import com.xxfc.platform.activity.vo.IntegralRuleDto;
import com.xxfc.platform.activity.vo.IntegralUserRecordDto;
import com.xxfc.platform.activity.vo.IntegralUserTotalDto;
......@@ -37,6 +40,9 @@ public class IntegralUserRecordBiz extends BaseBiz<IntegralUserRecordMapper, Int
@Autowired
IntegralRuleBiz integralRuleBiz;
@Autowired
IntegralUserStatusBiz integralUserStatusBiz;
/**
* 添加用户积分记录
*
......@@ -49,15 +55,15 @@ public class IntegralUserRecordBiz extends BaseBiz<IntegralUserRecordMapper, Int
return ObjectRestResponse.paramIsEmpty();
}
//如果参数没有积分,说明是消息队列过来的参数,需要查询规则表获取积分数
IntegralRuleDto integralRule = new IntegralRuleDto();
integralRule.setCode(integralUserRecord.getIntegralRuleCode());
ObjectRestResponse<IntegralRule> ruleObjectRestResponse = integralRuleBiz.getOne(integralRule);
if (ruleObjectRestResponse.getData() == null) {
return ObjectRestResponse.createFailedResult(1202, "积分规则不存在");
}
IntegralRule oldValue = ruleObjectRestResponse.getData();
if (integralUserRecord.getPoint() == null) {
IntegralRuleDto integralRule = new IntegralRuleDto();
integralRule.setCode(integralUserRecord.getIntegralRuleCode());
ObjectRestResponse<IntegralRule> ruleObjectRestResponse = integralRuleBiz.getOne(integralRule);
if (ruleObjectRestResponse.getData() == null) {
return ObjectRestResponse.createFailedResult(1202, "积分规则不存在");
}
Integer point = 0;
IntegralRule oldValue = ruleObjectRestResponse.getData();
if(oldValue.getPoint() == 0) {//没有基础分需要计算分数
//Integer amount = Integer.parseInt(new BigDecimal(integralUserRecord.getAmount()).divide(new BigDecimal("100"), 0, BigDecimal.ROUND_DOWN).toString());
Integer amount = Integer.parseInt(integralUserRecord.getAmount());
......@@ -95,6 +101,9 @@ public class IntegralUserRecordBiz extends BaseBiz<IntegralUserRecordMapper, Int
}
}
insertSelective(integralUserRecord.getIntegralUserRecord());
if(oldValue != null) {
getUserRecordStatus(integralUserRecord, oldValue.getPeriod(), oldValue.getNumber());
}
return ObjectRestResponse.succ();
}
......@@ -149,4 +158,32 @@ public class IntegralUserRecordBiz extends BaseBiz<IntegralUserRecordMapper, Int
List<IntegralUserRecord> integralUserRecordList = mapper.selectByUserAndTime(integralUserRecordDto);
return ObjectRestResponse.succ(integralUserRecordList);
}
/**
* //判断用户获取积分是否达标
* @param integralUserRecordDto 积分记录实体
* @param period 周期
* number 周期内可获得积分的次数
*/
public void getUserRecordStatus(IntegralUserRecordDto integralUserRecordDto, Integer period, Integer number) {
IntegralUserStatus integralUserStatus = new IntegralUserStatus();
integralUserStatus.setUserId(integralUserRecordDto.getUserId());
integralUserStatus.setIntegralRuleCode(integralUserRecordDto.getIntegralRuleCode());
if(period == IntegralRulePeriod.DAY.getCode()) {//按天
integralUserRecordDto.setStartTime(IntegralToolsUtils.getDayStart());
integralUserRecordDto.setEndTime(IntegralToolsUtils.getDayStart() + 24 * 60 * 60 * 1000);
Integer count = mapper.countByUserAndCode(integralUserRecordDto);
integralUserStatus.setIntegralStatus(count == number);
} else {
integralUserRecordDto.setStartTime(null);
Integer count = mapper.countByUserAndCode(integralUserRecordDto);
integralUserStatus.setIntegralStatus(count == number);
}
integralUserStatusBiz.save(integralUserStatus);
}
}
package com.xxfc.platform.activity.biz;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import com.github.wxiaoqi.security.common.biz.BaseBiz;
import com.github.wxiaoqi.security.common.msg.ObjectRestResponse;
import com.xxfc.platform.activity.entity.IntegralUserStatus;
import com.xxfc.platform.activity.mapper.IntegralUserStatusMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@Service
@Transactional
public class IntegralUserStatusBiz extends BaseBiz<IntegralUserStatusMapper, IntegralUserStatus> {
public ObjectRestResponse save(IntegralUserStatus integralUserStatus) {
if(integralUserStatus != null) {
IntegralUserStatus oldValue = mapper.selectByUserAndCode(integralUserStatus);
if(oldValue != null) {
BeanUtil.copyProperties(integralUserStatus, oldValue, CopyOptions.create().setIgnoreNullValue(true).setIgnoreError(true));
updateSelectiveById(oldValue);
}
insertSelective(integralUserStatus);
}
return ObjectRestResponse.succ();
}
public IntegralUserStatus selectByUserAndCode(String code, Integer userId) {
if(!StringUtils.isAllBlank(code, userId + "")) {
IntegralUserStatus integralUserStatus = new IntegralUserStatus();
integralUserStatus.setIntegralRuleCode(code);
integralUserStatus.setUserId(userId);
return mapper.selectByUserAndCode(integralUserStatus);
}
return null;
}
}
......@@ -12,4 +12,6 @@ public interface IntegralUserRecordMapper extends Mapper<IntegralUserRecord> {
List<IntegralUserRecord> selectByUserAndTime(IntegralUserRecordDto integralUserRecordDto);
Integer countByUserAndCode(IntegralUserRecordDto integralUserRecordDto);
}
\ No newline at end of file
......@@ -15,9 +15,9 @@
</plugin>
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/vehicle?useUnicode=true&amp;characterEncoding=UTF8"
connectionURL="jdbc:mysql://10.5.52.4:3307/xxfc_activity?useUnicode=true&amp;characterEncoding=UTF8"
userId="root"
password="xx2019fc">
password="sslcloud123*()">
</jdbcConnection>
<javaModelGenerator targetPackage="${targetModelPackage}" targetProject="${targetJavaProject}"/>
......@@ -26,18 +26,6 @@
<javaClientGenerator targetPackage="${targetMapperPackage}" targetProject="${targetJavaProject}"
type="XMLMAPPER"/>
<!-- <table tableName="vehicle" domainObjectName="Vehicle">-->
<!-- </table>-->
<!-- <table tableName="vehicle_book_info" domainObjectName="VehicleBookInfo">-->
<!-- </table>-->
<!-- <table tableName="vehicle_book_record" domainObjectName="VehicleBookRecord">-->
<!-- </table>-->
<!-- <table tableName="branch_company" domainObjectName="BranchCompany">-->
<!-- </table>-->
<!-- <table tableName="branch_company_stock_info" domainObjectName="BranchCompanyStockInfo"></table>-->
<!-- <table tableName="branch_company_stock_apply_info" domainObjectName="BranchCompanyStockApplyInfo"></table>-->
<table tableName="vehicle_upkeep_item" domainObjectName="VehicleUpkeepItem"></table>
<table tableName="vehicle_upkeep_log" domainObjectName="VehicleUpkeepLog"></table>
<table tableName="integral_user_status" domainObjectName="IntegralUserStatus"></table>
</context>
</generatorConfiguration>
\ No newline at end of file
......@@ -31,17 +31,21 @@
<select id="selectAllByParam" resultType="com.xxfc.platform.activity.entity.IntegralRule" parameterType="com.xxfc.platform.activity.vo.IntegralRuleDto">
select * from integral_rule
select i1.*, i2.integral_status from integral_rule i1
left join integral_user_status i2 on i1.code = i2.integral_rule_code
<where>
<if test="id != null">
and id = #{id}
and i1.id = #{id}
</if>
<if test="userId != null">
and i2.user_id = #{userId}
</if>
<if test="code != null">
and code = #{code}
and i1.code = #{code}
</if>
and isdel = 0 and status = 1
and i1.isdel = 0 and status = 1
</where>
order by order_id DESC ,crt_time DESC
order by i1.order_id DESC ,i1.crt_time DESC
</select>
</mapper>
\ No newline at end of file
......@@ -29,4 +29,13 @@
select * from integral_user_record
where user_id = #{userId} and crt_time between #{startTime} and #{endTime} and integral_rule_code = #{integralRuleCode}
</select>
<select id="countByUserAndCode" resultType="java.lang.Integer" parameterType="com.xxfc.platform.activity.vo.IntegralUserRecordDto">
select count(*) from integral_user_record
where user_id = #{userId} and integral_rule_code = #{integralRuleCode}
<if test="startTime != null">
and crt_time between #{startTime} and #{endTime}
</if>
</select>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment