Commit 48a64faf by 吴博

Merge branch 'fixbug/timeout' into 'master'

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

See merge request rays/pcloud-book!1666
parents 171f1ed2 132908f6
...@@ -168,10 +168,15 @@ public class BookAuthCodeBizImpl implements BookAuthCodeBiz { ...@@ -168,10 +168,15 @@ public class BookAuthCodeBizImpl implements BookAuthCodeBiz {
return BookStatusEnum.CodeUseTypeEnum.RIGHT.value; return BookStatusEnum.CodeUseTypeEnum.RIGHT.value;
} }
Long authCodeId = bookAuthCodeDao.getBookAuthCodeId(bookId, channelId, adviserId, code, authBookType); Long authCodeId = bookAuthCodeDao.getBookAuthCodeId(bookId, channelId, adviserId, code, authBookType);
Integer count = bookAuthCodeDao.updateUseCount(bookId, channelId, adviserId, code, authBookInfo.getCodeUseCount(), authBookType); // Integer count = bookAuthCodeDao.updateUseCount(bookId, channelId, adviserId, code, authBookInfo.getCodeUseCount(), authBookType);
if (count < 1 && authCodeId != null && authCodeId > 0) { 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; return BookStatusEnum.CodeUseTypeEnum.HAVE_USE.value;
} else if (count < 1 && (authCodeId == null || authCodeId == 0)) { } else if (count < 1) {
return BookStatusEnum.CodeUseTypeEnum.NOT_RIGHT.value; return BookStatusEnum.CodeUseTypeEnum.NOT_RIGHT.value;
} else { } else {
//新增一条校验成功记录 //新增一条校验成功记录
......
...@@ -67,4 +67,6 @@ public interface BookAuthCodeDao extends BaseDao<BookAuthCode> { ...@@ -67,4 +67,6 @@ public interface BookAuthCodeDao extends BaseDao<BookAuthCode> {
void clearUseCount(Long id); void clearUseCount(Long id);
void deleteCode(Long id); void deleteCode(Long id);
Integer updateUseCountById(Long authCodeId, Integer codeUseCount, Long adviserId);
} }
package com.pcloud.book.copyright.dao.impl; package com.pcloud.book.copyright.dao.impl;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.pcloud.book.copyright.dao.BookAuthCodeDao; import com.pcloud.book.copyright.dao.BookAuthCodeDao;
import com.pcloud.book.copyright.dto.BookAuthCodeDTO; import com.pcloud.book.copyright.dto.BookAuthCodeDTO;
import com.pcloud.book.copyright.entity.BookAuthCode; import com.pcloud.book.copyright.entity.BookAuthCode;
...@@ -12,6 +13,7 @@ import org.springframework.stereotype.Component; ...@@ -12,6 +13,7 @@ import org.springframework.stereotype.Component;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional;
/** /**
* @author lily * @author lily
...@@ -133,4 +135,13 @@ public class BookAuthCodeDaoImpl extends BaseDaoImpl<BookAuthCode> implements Bo ...@@ -133,4 +135,13 @@ public class BookAuthCodeDaoImpl extends BaseDaoImpl<BookAuthCode> implements Bo
public void deleteCode(Long id) { public void deleteCode(Long id) {
getSqlSession().delete(getStatement("deleteCode"), ImmutableMap.of("id", 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 @@ ...@@ -274,4 +274,14 @@
where id = #{id} where id = #{id}
</update> </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> </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