|
|
|
@@ -1,5 +1,8 @@ |
|
|
|
package com.iformall.controller.sys; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.google.common.base.Function; |
|
|
|
import com.google.common.collect.*; |
|
|
|
import com.iformall.common.ErrorCode; |
|
|
|
import com.iformall.common.IdWorker; |
|
|
|
import com.iformall.common.ResultData; |
|
|
|
@@ -8,12 +11,12 @@ import com.iformall.domain.po.*; |
|
|
|
import com.iformall.enums.EnumMsgModel; |
|
|
|
import com.iformall.enums.EnumScoreType; |
|
|
|
import com.iformall.enums.EnumUserType; |
|
|
|
import com.iformall.exception.MallinkException; |
|
|
|
import com.iformall.mapper.*; |
|
|
|
import com.iformall.service.WxCreditHistoryService; |
|
|
|
import com.iformall.utils.DateUtils; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.apache.commons.collections.CollectionUtils; |
|
|
|
import org.checkerframework.checker.nullness.qual.Nullable; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.web.bind.annotation.GetMapping; |
|
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
|
@@ -22,6 +25,7 @@ import org.springframework.web.bind.annotation.RestController; |
|
|
|
import javax.annotation.Resource; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.util.*; |
|
|
|
import java.util.concurrent.atomic.AtomicInteger; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
|
@@ -100,6 +104,28 @@ public class DataInitController extends BaseController { |
|
|
|
return new ResultData(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* 修复wx_c_user_basic_info积分数据 |
|
|
|
* |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@GetMapping("/fixCredit4CUserBasic") |
|
|
|
public ResultData fixCredit4CUserBasic() { |
|
|
|
try { |
|
|
|
MallUserInfo userInfo = getUser(); |
|
|
|
if (userInfo.isFmSuperAdmin()) { |
|
|
|
doFixCredit4CUserBasic(); |
|
|
|
return new ResultData(); |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("DataInitController::fixCredit4CUserBasic error ", e); |
|
|
|
return new ResultData(ErrorCode.MSG_METHOD_REQUEST_ERROR, e.getMessage()); |
|
|
|
} |
|
|
|
|
|
|
|
return new ResultData(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 核销积分数据修复 |
|
|
|
* |
|
|
|
@@ -121,6 +147,47 @@ public class DataInitController extends BaseController { |
|
|
|
return new ResultData(); |
|
|
|
} |
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void doFixCredit4CUserBasic() { |
|
|
|
log.debug("cUserBasic积分更新, begin --------------》"); |
|
|
|
// 1 查找c_user_basic中c_user不存在且积分为null的用户用户 |
|
|
|
List<WxCUserBasicInfo> userBasicInfoList = cUserBasicInfoMapper.selectNotCUserList(); |
|
|
|
List<Long> ids = userBasicInfoList.stream().map(WxCUserBasicInfo::getId).collect(Collectors.toList()); |
|
|
|
//log.debug("ids {}", JSON.toJSONString(ids)); |
|
|
|
|
|
|
|
// 2 获取对应用户的积分记录 |
|
|
|
List<WxCreditHistory> creditList = creditHistoryMapper.findListByIds(ids); |
|
|
|
ImmutableListMultimap<Long, WxCreditHistory> userCreditHistory = Multimaps.index(creditList, new Function<WxCreditHistory, Long>() { |
|
|
|
@Nullable |
|
|
|
@Override |
|
|
|
public Long apply(@Nullable WxCreditHistory input) { |
|
|
|
return input.getCUserId(); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
//3 将历史记录最好积分重设积分 |
|
|
|
AtomicInteger count = new AtomicInteger(0); |
|
|
|
userBasicInfoList.forEach(wxCUserBasicInfo -> { |
|
|
|
ImmutableList<WxCreditHistory> historyList = userCreditHistory.get(wxCUserBasicInfo.getId()); |
|
|
|
WxCUserBasicInfo toUpdateUser = new WxCUserBasicInfo(); |
|
|
|
toUpdateUser.setId(wxCUserBasicInfo.getId()); |
|
|
|
//用户积分不存在,跳过 |
|
|
|
if (CollectionUtils.isEmpty(historyList)) { |
|
|
|
//log.debug("cUserBasic积分更新,id: {} 积分记录不存在", wxCUserBasicInfo.getId()); |
|
|
|
return; |
|
|
|
} |
|
|
|
//积分记录存在,使用最新的总积分重新赋值 |
|
|
|
WxCreditHistory wxCreditHistory = historyList.get(0); |
|
|
|
toUpdateUser.setCredit(wxCreditHistory.getCreditAmount()); |
|
|
|
cUserBasicInfoMapper.updateByPrimaryKeySelective(toUpdateUser); |
|
|
|
log.debug("cUserBasic积分更新,id: {},原积分: {},新积分: {}, 积分时间: {}", wxCUserBasicInfo.getId(), wxCUserBasicInfo.getCredit(), toUpdateUser.getCredit(), DateUtils.format(wxCreditHistory.getCreateDate())); |
|
|
|
count.getAndIncrement(); |
|
|
|
}); |
|
|
|
|
|
|
|
log.debug("cUserBasic积分更新,更新用户 {}", count.intValue()); |
|
|
|
log.debug("cUserBasic积分更新, end --------------》"); |
|
|
|
} |
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
|
public void doFixCredit() { |
|
|
|
// 1 获取积分记录 |
|
|
|
|