|
@@ -1,11 +1,25 @@
|
1
|
1
|
package com.huiju.estateagents.service.impl;
|
2
|
2
|
|
|
3
|
+import com.alibaba.fastjson.JSONObject;
|
|
4
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
5
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
3
|
6
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
7
|
+import com.huiju.estateagents.common.CommConstant;
|
|
8
|
+import com.huiju.estateagents.entity.TaPerson;
|
4
|
9
|
import com.huiju.estateagents.entity.TaPointsRecords;
|
|
10
|
+import com.huiju.estateagents.entity.TdPointsRules;
|
|
11
|
+import com.huiju.estateagents.event.PointsEvent;
|
|
12
|
+import com.huiju.estateagents.mapper.TaPersonMapper;
|
5
|
13
|
import com.huiju.estateagents.mapper.TaPointsRecordsMapper;
|
|
14
|
+import com.huiju.estateagents.mapper.TdPointsRulesMapper;
|
6
|
15
|
import com.huiju.estateagents.service.ITaPointsRecordsService;
|
|
16
|
+import org.apache.commons.collections.map.HashedMap;
|
|
17
|
+import org.springframework.beans.factory.annotation.Autowired;
|
7
|
18
|
import org.springframework.stereotype.Service;
|
8
|
19
|
|
|
20
|
+import java.time.LocalDateTime;
|
|
21
|
+import java.util.Map;
|
|
22
|
+
|
9
|
23
|
/**
|
10
|
24
|
* <p>
|
11
|
25
|
* 积分消费流水表 服务实现类
|
|
@@ -16,5 +30,52 @@ import org.springframework.stereotype.Service;
|
16
|
30
|
*/
|
17
|
31
|
@Service
|
18
|
32
|
public class TaPointsRecordsServiceImpl extends ServiceImpl<TaPointsRecordsMapper, TaPointsRecords> implements ITaPointsRecordsService {
|
19
|
|
-
|
|
33
|
+ @Autowired
|
|
34
|
+ TaPersonMapper taPersonMapper;
|
|
35
|
+
|
|
36
|
+ @Autowired
|
|
37
|
+ private TdPointsRulesMapper tdPointsRulesMapper;
|
|
38
|
+
|
|
39
|
+ @Autowired
|
|
40
|
+ private TaPointsRecordsMapper taPointsRecordsMapper;
|
|
41
|
+
|
|
42
|
+ @Override
|
|
43
|
+ public void sharePoints(String personId) {
|
|
44
|
+ TaPerson person = taPersonMapper.selectById(personId);
|
|
45
|
+ sendPoints(person,2,CommConstant.POINTS_SHARE);
|
|
46
|
+ }
|
|
47
|
+
|
|
48
|
+ @Override
|
|
49
|
+ public void authPoints(String personId) {
|
|
50
|
+ TaPerson person = taPersonMapper.selectById(personId);
|
|
51
|
+ sendPoints(person,4,CommConstant.POINTS_AUTHORIZE);
|
|
52
|
+ }
|
|
53
|
+
|
|
54
|
+ private void sendPoints(TaPerson person,Integer rulesId,String shareType) {
|
|
55
|
+ //发放积分
|
|
56
|
+ QueryWrapper<TdPointsRules> queryWrapper = new QueryWrapper<>();
|
|
57
|
+ queryWrapper.eq("rule_id",rulesId);
|
|
58
|
+ queryWrapper.eq("status", CommConstant.STATUS_NORMAL);
|
|
59
|
+ TdPointsRules tdPointsRules = tdPointsRulesMapper.selectOne(queryWrapper);
|
|
60
|
+ if (null != tdPointsRules) {
|
|
61
|
+ //插入积分消费流水表
|
|
62
|
+ TaPointsRecords taPointsRecords = new TaPointsRecords();
|
|
63
|
+ taPointsRecords.setPersonId(person.getPersonId());
|
|
64
|
+ taPointsRecords.setPersonName(com.huiju.estateagents.common.StringUtils.ifNull(person.getName(),person.getNickname()));
|
|
65
|
+ taPointsRecords.setPersonType(person.getPersonType());
|
|
66
|
+ taPointsRecords.setPointsAmount(tdPointsRules.getPointsAmount());
|
|
67
|
+ taPointsRecords.setChangeType(shareType);
|
|
68
|
+ JSONObject jsonObject = new JSONObject();
|
|
69
|
+ jsonObject.put("person_id",person.getPersonId());
|
|
70
|
+ taPointsRecords.setChangeParams(jsonObject.toJSONString());
|
|
71
|
+ taPointsRecords.setCreateDate(LocalDateTime.now());
|
|
72
|
+ taPointsRecords.setStatus(CommConstant.STATUS_NORMAL);
|
|
73
|
+ taPointsRecordsMapper.insert(taPointsRecords);
|
|
74
|
+ //添加积分
|
|
75
|
+ UpdateWrapper<TaPerson> taPersonwrapper = new UpdateWrapper<>();
|
|
76
|
+ taPersonwrapper.eq("person_id", person.getPersonId());
|
|
77
|
+ taPersonwrapper.setSql("points = IFNULL(points, 0) + " + String.valueOf(tdPointsRules.getPointsAmount()));
|
|
78
|
+ taPersonMapper.update(new TaPerson(), taPersonwrapper);
|
|
79
|
+ }
|
|
80
|
+ }
|
20
|
81
|
}
|