Commit 479ada9e by 吴博

Merge branch 'fixbug/timeout' into 'release'

bug: [none] 接口超时处理/book/v1.0/bookAuthCode/checkCode

See merge request rays/pcloud-book!1663
parents 42de4c52 132908f6
......@@ -168,10 +168,15 @@ public class BookAuthCodeBizImpl implements BookAuthCodeBiz {
return BookStatusEnum.CodeUseTypeEnum.RIGHT.value;
}
Long authCodeId = bookAuthCodeDao.getBookAuthCodeId(bookId, channelId, adviserId, code, authBookType);
Integer count = bookAuthCodeDao.updateUseCount(bookId, channelId, adviserId, code, authBookInfo.getCodeUseCount(), authBookType);
if (count < 1 && authCodeId != null && authCodeId > 0) {
// Integer count = bookAuthCodeDao.updateUseCount(bookId, channelId, adviserId, code, authBookInfo.getCodeUseCount(), authBookType);
if (authCodeId == null || authCodeId == 0) {
return BookStatusEnum.CodeUseTypeEnum.NOT_RIGHT.value;
}
// 根据ID进行更新,避免死锁
Integer count = bookAuthCodeDao.updateUseCountById(authCodeId, Optional.ofNullable(authBookInfo.getCodeUseCount()).orElse(0), adviserId);
if (count < 1 && authCodeId > 0) {
return BookStatusEnum.CodeUseTypeEnum.HAVE_USE.value;
} else if (count < 1 && (authCodeId == null || authCodeId == 0)) {
} else if (count < 1) {
return BookStatusEnum.CodeUseTypeEnum.NOT_RIGHT.value;
} else {
//新增一条校验成功记录
......
......@@ -67,4 +67,6 @@ public interface BookAuthCodeDao extends BaseDao<BookAuthCode> {
void clearUseCount(Long id);
void deleteCode(Long id);
Integer updateUseCountById(Long authCodeId, Integer codeUseCount, Long adviserId);
}
package com.pcloud.book.copyright.dao.impl;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.pcloud.book.copyright.dao.BookAuthCodeDao;
import com.pcloud.book.copyright.dto.BookAuthCodeDTO;
import com.pcloud.book.copyright.entity.BookAuthCode;
......@@ -12,6 +13,7 @@ import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
/**
* @author lily
......@@ -133,4 +135,13 @@ public class BookAuthCodeDaoImpl extends BaseDaoImpl<BookAuthCode> implements Bo
public void deleteCode(Long id) {
getSqlSession().delete(getStatement("deleteCode"), ImmutableMap.of("id", id));
}
@Override
public Integer updateUseCountById(Long authCodeId, Integer codeUseCount, Long adviserId) {
Map<String, Object> paramMap = new HashMap<>();
paramMap.put("id", authCodeId);
paramMap.put("codeUseCount", codeUseCount);
paramMap.put("adviserId", Optional.ofNullable(adviserId).orElse(0L));
return getSqlSession().update(getStatement("updateUseCountById"), paramMap);
}
}
......@@ -274,4 +274,14 @@
where id = #{id}
</update>
<update id="updateUseCountById" parameterType="map">
UPDATE BOOK_AUTH_CODE
SET
use_count = use_count + 1,
LAST_MODIFIED_DATE = NOW(),
LAST_MODIFIED_USER = #{adviserId}
WHERE
id = #{id, jdbcType=BIGINT}
AND use_count <![CDATA[ < ]]> #{codeUseCount}
</update>
</mapper>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment