|
|
|
@@ -3,13 +3,12 @@ package com.iformall.controller.sys; |
|
|
|
import com.iformall.common.ErrorCode; |
|
|
|
import com.iformall.common.IdWorker; |
|
|
|
import com.iformall.common.ResultData; |
|
|
|
import com.iformall.domain.po.WxMall; |
|
|
|
import com.iformall.domain.po.WxMsgSignature; |
|
|
|
import com.iformall.domain.po.WxMsgValidationcodeModel; |
|
|
|
import com.iformall.controller.base.BaseController; |
|
|
|
import com.iformall.domain.po.*; |
|
|
|
import com.iformall.enums.EnumMsgModel; |
|
|
|
import com.iformall.mapper.WxMallMapper; |
|
|
|
import com.iformall.mapper.WxMsgSignatureMapper; |
|
|
|
import com.iformall.mapper.WxMsgValidationcodeModelMapper; |
|
|
|
import com.iformall.mapper.*; |
|
|
|
import com.iformall.service.WxCreditHistoryService; |
|
|
|
import com.iformall.utils.DateUtils; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.web.bind.annotation.GetMapping; |
|
|
|
@@ -20,6 +19,7 @@ import javax.annotation.Resource; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Objects; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
/** |
|
|
|
@@ -28,7 +28,7 @@ import java.util.stream.Collectors; |
|
|
|
@Slf4j |
|
|
|
@RestController |
|
|
|
@RequestMapping("sys") |
|
|
|
public class DataInitController { |
|
|
|
public class DataInitController extends BaseController { |
|
|
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
@@ -37,10 +37,23 @@ public class DataInitController { |
|
|
|
private WxMsgSignatureMapper signatureMapper; |
|
|
|
@Resource |
|
|
|
private WxMsgValidationcodeModelMapper modelMapper; |
|
|
|
@Resource |
|
|
|
private WxCreditHistoryMapper creditHistoryMapper; |
|
|
|
@Resource |
|
|
|
private WxCreditHistoryService creditHistoryService; |
|
|
|
|
|
|
|
@Resource |
|
|
|
private WxCUserMapper cUserMapper; |
|
|
|
@Resource |
|
|
|
private WxCUserBasicInfoMapper cUserBasicInfoMapper; |
|
|
|
|
|
|
|
@GetMapping("/init") |
|
|
|
public ResultData init() { |
|
|
|
try { |
|
|
|
MallUserInfo userInfo = getUser(); |
|
|
|
if (userInfo.isFmSuperAdmin()) { |
|
|
|
return new ResultData(); |
|
|
|
} |
|
|
|
addBirthDayMsgModel(); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("DataInitController::init error ", e); |
|
|
|
@@ -50,6 +63,73 @@ public class DataInitController { |
|
|
|
return new ResultData(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 积分数据修复 |
|
|
|
* |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@GetMapping("/fixCredit") |
|
|
|
public ResultData fixCredit() { |
|
|
|
try { |
|
|
|
MallUserInfo userInfo = getUser(); |
|
|
|
if(userInfo.isFmSuperAdmin()) { |
|
|
|
return new ResultData(); |
|
|
|
} |
|
|
|
doFixCredit(); |
|
|
|
} catch (Exception e) { |
|
|
|
log.error("DataInitController::fixCredit error ", e); |
|
|
|
return new ResultData(ErrorCode.MSG_METHOD_REQUEST_ERROR, e.getMessage()); |
|
|
|
} |
|
|
|
|
|
|
|
return new ResultData(); |
|
|
|
} |
|
|
|
|
|
|
|
@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; |
|
|
|
} |
|
|
|
|
|
|
|
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(newCredit); |
|
|
|
creditHistoryMapper.updateByPrimaryKeySelective(toUpdateCreditHistory); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 增加会员生日短信模板 |
|
|
|
*/ |
|
|
|
|