|
|
@@ -104,49 +104,6 @@ public class DataInitController extends BaseController { |
|
|
return new ResultData(); |
|
|
return new ResultData(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 积分数据修复 |
|
|
|
|
|
* |
|
|
|
|
|
* @return |
|
|
|
|
|
*/ |
|
|
|
|
|
@GetMapping("/fixCredit") |
|
|
|
|
|
public ResultData fixCredit() { |
|
|
|
|
|
try { |
|
|
|
|
|
MallUserInfo userInfo = getUser(); |
|
|
|
|
|
if(userInfo.isFmSuperAdmin()) { |
|
|
|
|
|
doFixCredit(); |
|
|
|
|
|
return new ResultData(); |
|
|
|
|
|
} |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
log.error("DataInitController::fixCredit error ", e); |
|
|
|
|
|
return new ResultData(ErrorCode.MSG_METHOD_REQUEST_ERROR, e.getMessage()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return new ResultData(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 修复wx_c_user_basic_info积分数据 |
|
|
|
|
|
* |
|
|
|
|
|
* @return |
|
|
|
|
|
*/ |
|
|
|
|
|
@GetMapping("/fixCredit4CUserBasic") |
|
|
|
|
|
public ResultData fixCredit4CUserBasic() { |
|
|
|
|
|
try { |
|
|
|
|
|
MallUserInfo userInfo = getUser(); |
|
|
|
|
|
if (userInfo.isFmSuperAdmin()) { |
|
|
|
|
|
doFixCreditHistory(); |
|
|
|
|
|
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(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 核销积分数据修复 |
|
|
* 核销积分数据修复 |
|
|
* |
|
|
* |
|
|
@@ -168,151 +125,6 @@ public class DataInitController extends BaseController { |
|
|
return new ResultData(); |
|
|
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 获取积分记录 |
|
|
|
|
|
List<WxCreditHistory> creditList = creditHistoryMapper.findListAfter(10, "2019-09-16 22:00:00"); |
|
|
|
|
|
// 2 重新计算积分,比较是否需要修复 |
|
|
|
|
|
creditList.forEach(wxCreditHistory -> { |
|
|
|
|
|
WxCUser cUser = cUserMapper.selectByPrimaryKey(wxCreditHistory.getCUserId()); |
|
|
|
|
|
WxCUserBasicInfo userBasicInfo = cUserBasicInfoMapper.selectByPrimaryKey(wxCreditHistory.getCUserId()); |
|
|
|
|
|
//排查不存在的用户 |
|
|
|
|
|
if (Objects.isNull(cUser) && Objects.isNull(userBasicInfo)) { |
|
|
|
|
|
log.debug("用户不存在 id: {}", wxCreditHistory.getId()); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
WxMerchant wxMerchant = new WxMerchant(); |
|
|
|
|
|
wxMerchant.setStatus(1); |
|
|
|
|
|
wxMerchant.setId(wxCreditHistory.getMerchantId()); |
|
|
|
|
|
List<WxMerchant> wxMerchantList = wxMerchantMapper.findList(wxMerchant); |
|
|
|
|
|
if (wxMerchantList == null || wxMerchantList.size() == 0) { |
|
|
|
|
|
log.debug(ErrorCode.MERCHANT_INFO_NOT_FOUND.getMessage()); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
//根据商户id和花费金额计算需要新增的积分 |
|
|
|
|
|
Map<String, Integer> result = creditHistoryService.findByMerchantIdAndSpend(wxCreditHistory.getMerchantId(), String.valueOf(new BigDecimal(wxCreditHistory.getSpend()/100)), wxCreditHistory.getCUserId(),wxCreditHistory.getTenantId()); |
|
|
|
|
|
|
|
|
|
|
|
//Map<String, Integer> result = creditHistoryService.findByMerchantIdAndSpend(wxCreditHistory.getMerchantId(), String.valueOf(wxCreditHistory.getSpend()), wxCreditHistory.getCUserId(), wxCreditHistory.getTenantId()); |
|
|
|
|
|
Integer creditDB = wxCreditHistory.getCreditNum(); |
|
|
|
|
|
Integer credit = result.get("credit"); |
|
|
|
|
|
if (Objects.equals(credit, creditDB)) { |
|
|
|
|
|
log.debug("本次积分计算:正确, id: {},原积分: {},重新计算积分: {}, 积分时间: {}", wxCreditHistory.getId(), creditDB, credit, DateUtils.format(wxCreditHistory.getCreateDate())); |
|
|
|
|
|
} else { |
|
|
|
|
|
log.debug("本次积分计算:错误, id: {},原积分: {},重新计算积分: {}, 积分时间: {}", wxCreditHistory.getId(), creditDB, credit, DateUtils.format(wxCreditHistory.getCreateDate())); |
|
|
|
|
|
// 3 重新计算积分 |
|
|
|
|
|
//用户新积分 |
|
|
|
|
|
Integer newCredit = wxCreditHistory.getCreditAmount() - creditDB + credit; |
|
|
|
|
|
|
|
|
|
|
|
// 4 更新积分 |
|
|
|
|
|
WxCUser toUpdateCUser = new WxCUser(); |
|
|
|
|
|
toUpdateCUser.setId(wxCreditHistory.getCUserId()); |
|
|
|
|
|
toUpdateCUser.setCredit(newCredit); |
|
|
|
|
|
toUpdateCUser.setUpdateDate(new Date()); |
|
|
|
|
|
cUserMapper.updateByPrimaryKeySelective(toUpdateCUser); |
|
|
|
|
|
|
|
|
|
|
|
WxCUserBasicInfo toUpdateBasicInfo = new WxCUserBasicInfo(); |
|
|
|
|
|
toUpdateBasicInfo.setId(wxCreditHistory.getCUserId()); |
|
|
|
|
|
toUpdateBasicInfo.setCredit(newCredit); |
|
|
|
|
|
toUpdateBasicInfo.setUpdateDate(new Date()); |
|
|
|
|
|
cUserBasicInfoMapper.updateByPrimaryKeySelective(toUpdateBasicInfo); |
|
|
|
|
|
|
|
|
|
|
|
WxCreditHistory toUpdateCreditHistory = new WxCreditHistory(); |
|
|
|
|
|
toUpdateCreditHistory.setId(wxCreditHistory.getId()); |
|
|
|
|
|
toUpdateCreditHistory.setCreditNum(credit); |
|
|
|
|
|
toUpdateCreditHistory.setCreditAmount(newCredit); |
|
|
|
|
|
creditHistoryMapper.updateByPrimaryKeySelective(toUpdateCreditHistory); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void doFixCreditHistory() { |
|
|
|
|
|
SimpleDateFormat dataFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
|
|
|
|
|
String dateTime = "2019-09-16 22:00:00"; |
|
|
|
|
|
List<WxCreditHistory> cuUserList = creditHistoryMapper.findListAfter(null, null); // new ArrayList<>(); // |
|
|
|
|
|
//cuUserList.add(new WxCreditHistory(){{ |
|
|
|
|
|
// setCUserId(262738733739016192L); |
|
|
|
|
|
//}}); |
|
|
|
|
|
for (WxCreditHistory cuUser: cuUserList) { |
|
|
|
|
|
//cuUserList.stream().forEach(cuUser->{ |
|
|
|
|
|
WxCreditHistory q = new WxCreditHistory(); |
|
|
|
|
|
q.setCUserId(cuUser.getCUserId()); |
|
|
|
|
|
List<WxCreditHistory> creditHistories = creditHistoryMapper.findList(q); |
|
|
|
|
|
int amount = 0; |
|
|
|
|
|
boolean isError = false; |
|
|
|
|
|
for (WxCreditHistory creditHistory : creditHistories) { |
|
|
|
|
|
int oldamount = amount; |
|
|
|
|
|
if (creditHistory.getCreditType().equals(EnumScoreType.MEM_IMPORT.getCode())) { |
|
|
|
|
|
amount = creditHistory.getCreditNum(); |
|
|
|
|
|
} else { |
|
|
|
|
|
amount = amount + creditHistory.getCreditNum(); |
|
|
|
|
|
} |
|
|
|
|
|
if (!creditHistory.getCreditAmount().equals(amount)) { |
|
|
|
|
|
//log.error("credit hist err: {},{},{},{},{}", creditHistory.getId(), creditHistory.getCUserId(), creditHistory.getCreditAmount(), creditHistory.getCreditNum(), oldamount); |
|
|
|
|
|
WxCreditHistory updateRecord = new WxCreditHistory(); |
|
|
|
|
|
updateRecord.setId(creditHistory.getId()); |
|
|
|
|
|
updateRecord.setCreditAmount(amount); |
|
|
|
|
|
creditHistoryMapper.updateByPrimaryKeySelective(updateRecord); |
|
|
|
|
|
isError = true; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if (isError) { |
|
|
|
|
|
WxCUser cUser = new WxCUser(); |
|
|
|
|
|
cUser.setId(cuUser.getCUserId()); |
|
|
|
|
|
cUser.setCredit(amount); |
|
|
|
|
|
cUserMapper.updateByPrimaryKeySelective(cUser); |
|
|
|
|
|
WxCUserBasicInfo cUserBasicInfo = new WxCUserBasicInfo(); |
|
|
|
|
|
cUserBasicInfo.setId(cuUser.getCUserId()); |
|
|
|
|
|
cUserBasicInfo.setCredit(amount); |
|
|
|
|
|
cUserBasicInfoMapper.updateByPrimaryKeySelective(cUserBasicInfo); |
|
|
|
|
|
log.error("credit hist err: {}", cuUser.getCUserId()); |
|
|
|
|
|
} |
|
|
|
|
|
//}); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
@Transactional(rollbackFor = Exception.class) |
|
|
public void doFixVerifyCredit() { |
|
|
public void doFixVerifyCredit() { |
|
|
// 1 获取券码 |
|
|
// 1 获取券码 |
|
|
|