Просмотр исходного кода

[修复][数据]增加积分接口异常数据修复

release_toaliyun_real
Burce 6 лет назад
Родитель
Сommit
d5726805a9
3 измененных файлов: 93 добавлений и 10 удалений
  1. +2
    -3
      mallinkService/src/main/java/com/iformall/mapper/WxCreditHistoryMapper.java
  2. +4
    -0
      mallinkService/src/main/resources/mapper/WxCreditHistoryMapper.xml
  3. +87
    -7
      mallinkSysAdmin/src/main/java/com/iformall/controller/sys/DataInitController.java

+ 2
- 3
mallinkService/src/main/java/com/iformall/mapper/WxCreditHistoryMapper.java Просмотреть файл

@@ -5,6 +5,7 @@ import com.iformall.domain.po.WxCreditHistory;
import com.iformall.domain.vo.WxCreditHistoryNewIdVo; import com.iformall.domain.vo.WxCreditHistoryNewIdVo;
import com.iformall.domain.vo.WxCreditHistoryVo; import com.iformall.domain.vo.WxCreditHistoryVo;


import java.util.Date;
import java.util.List; import java.util.List;


public interface WxCreditHistoryMapper extends CommonMapper<WxCreditHistory, Long> { public interface WxCreditHistoryMapper extends CommonMapper<WxCreditHistory, Long> {
@@ -29,7 +30,5 @@ public interface WxCreditHistoryMapper extends CommonMapper<WxCreditHistory, Lon


long getPeopleCount(WxCreditHistory wxCreditHistory); long getPeopleCount(WxCreditHistory wxCreditHistory);





List<WxCreditHistory> findListAfter(Integer creditType, String dateTime);
} }

+ 4
- 0
mallinkService/src/main/resources/mapper/WxCreditHistoryMapper.xml Просмотреть файл

@@ -249,4 +249,8 @@
) credit ) credit
</select> </select>


<select id="findListAfter" resultMap="BaseResultMap">
select <include refid="allColumns" /> from wx_credit_history where create_date > #{dateTime} and credit_type = #{creditType}
</select>

</mapper> </mapper>

+ 87
- 7
mallinkSysAdmin/src/main/java/com/iformall/controller/sys/DataInitController.java Просмотреть файл

@@ -3,13 +3,12 @@ package com.iformall.controller.sys;
import com.iformall.common.ErrorCode; import com.iformall.common.ErrorCode;
import com.iformall.common.IdWorker; import com.iformall.common.IdWorker;
import com.iformall.common.ResultData; 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.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 lombok.extern.slf4j.Slf4j;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
@@ -20,6 +19,7 @@ import javax.annotation.Resource;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;


/** /**
@@ -28,7 +28,7 @@ import java.util.stream.Collectors;
@Slf4j @Slf4j
@RestController @RestController
@RequestMapping("sys") @RequestMapping("sys")
public class DataInitController {
public class DataInitController extends BaseController {




@Resource @Resource
@@ -37,10 +37,23 @@ public class DataInitController {
private WxMsgSignatureMapper signatureMapper; private WxMsgSignatureMapper signatureMapper;
@Resource @Resource
private WxMsgValidationcodeModelMapper modelMapper; private WxMsgValidationcodeModelMapper modelMapper;
@Resource
private WxCreditHistoryMapper creditHistoryMapper;
@Resource
private WxCreditHistoryService creditHistoryService;

@Resource
private WxCUserMapper cUserMapper;
@Resource
private WxCUserBasicInfoMapper cUserBasicInfoMapper;


@GetMapping("/init") @GetMapping("/init")
public ResultData init() { public ResultData init() {
try { try {
MallUserInfo userInfo = getUser();
if (userInfo.isFmSuperAdmin()) {
return new ResultData();
}
addBirthDayMsgModel(); addBirthDayMsgModel();
} catch (Exception e) { } catch (Exception e) {
log.error("DataInitController::init error ", e); log.error("DataInitController::init error ", e);
@@ -50,6 +63,73 @@ public class DataInitController {
return new ResultData(); 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);
}
});
}

/** /**
* 增加会员生日短信模板 * 增加会员生日短信模板
*/ */


Загрузка…
Отмена
Сохранить