parent
2451f7205a
commit
dc0e7f543d
17 changed files with 170 additions and 67 deletions
@ -0,0 +1,15 @@ |
||||
package com.blockchain.server.yyyf.mapper; |
||||
|
||||
import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; |
||||
import org.springframework.stereotype.Repository; |
||||
import tk.mybatis.mapper.common.Mapper; |
||||
|
||||
import java.util.List; |
||||
|
||||
@Repository |
||||
public interface AssetsReporterMapper extends Mapper<AssetsReporter> { |
||||
|
||||
List<AssetsReporter> selectByAssessUserId(String assessUserId); |
||||
|
||||
void insertBatch(List<AssetsReporter> list); |
||||
} |
@ -0,0 +1,26 @@ |
||||
package com.blockchain.server.yyyf.service; |
||||
|
||||
import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; |
||||
|
||||
import java.util.List; |
||||
|
||||
public interface AssetsReporterService { |
||||
/** |
||||
* save assets reporter item |
||||
* |
||||
* @param assetsReporterList assetsReporter list |
||||
* @author fengyu.wang |
||||
* @date 2020-06-05 21:37:21 |
||||
*/ |
||||
void saveList(List<AssetsReporter> assetsReporterList); |
||||
|
||||
/** |
||||
* select assetsReporter list by assessUserId |
||||
* |
||||
* @param assessUserId exam result id |
||||
* @return assetsReporter list |
||||
* @author fengyu.wang |
||||
* @date 2020-06-05 21:38:09 |
||||
*/ |
||||
List<AssetsReporter> selectAssetsReporterListByAssessUserId(String assessUserId); |
||||
} |
@ -0,0 +1,40 @@ |
||||
package com.blockchain.server.yyyf.service.impl; |
||||
|
||||
import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; |
||||
import com.blockchain.server.yyyf.mapper.AssetsReporterMapper; |
||||
import com.blockchain.server.yyyf.service.AssetsReporterService; |
||||
import lombok.AllArgsConstructor; |
||||
import org.springframework.cache.CacheManager; |
||||
import org.springframework.cache.annotation.Cacheable; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.util.List; |
||||
import java.util.Optional; |
||||
|
||||
/** |
||||
* @author fengyu |
||||
*/ |
||||
@Service |
||||
@AllArgsConstructor |
||||
public class AssetsReporterServiceImpl implements AssetsReporterService { |
||||
private final AssetsReporterMapper assetsReporterMapper; |
||||
private final CacheManager cacheManager; |
||||
|
||||
public static final String CACHE_ASSETS_REPORTER = "yyyf_assets_reporter"; |
||||
public static final String CACHE_KEY_ASSETS_REPORTER = "yyyf:assetsReporter:"; |
||||
|
||||
@Override |
||||
public void saveList(List<AssetsReporter> assetsReporterList) { |
||||
assetsReporterList.forEach(assetsReporter -> |
||||
Optional.ofNullable(cacheManager.getCache(CACHE_ASSETS_REPORTER)) |
||||
.ifPresent(cache -> cache.evict(CACHE_KEY_ASSETS_REPORTER.concat(assetsReporter.getAssessUserId())))); |
||||
assetsReporterMapper.insertBatch(assetsReporterList); |
||||
} |
||||
|
||||
@Override |
||||
@Cacheable(cacheNames = CACHE_ASSETS_REPORTER, |
||||
key = "#root.target.CACHE_KEY_ASSETS_REPORTER.concat(#assessUserId)", unless = "#result == null") |
||||
public List<AssetsReporter> selectAssetsReporterListByAssessUserId(String assessUserId) { |
||||
return assetsReporterMapper.selectByAssessUserId(assessUserId); |
||||
} |
||||
} |
@ -0,0 +1,38 @@ |
||||
<?xml version="1.0" encoding="UTF-8" ?> |
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > |
||||
<mapper namespace="com.blockchain.server.yyyf.mapper.AssetsReporterMapper"> |
||||
<resultMap id="BaseResultMap" type="com.blockchain.server.yyyf.indicators.dto.AssetsReporter"> |
||||
<id column="id" property="id" jdbcType="VARCHAR"/> |
||||
<result column="assess_user_id" property="assessUserId" jdbcType="VARCHAR"/> |
||||
<result column="coin_name" property="coinName" jdbcType="VARCHAR"/> |
||||
<result column="days" property="days" jdbcType="INTEGER"/> |
||||
<result column="assets" property="assets" jdbcType="DECIMAL"/> |
||||
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/> |
||||
</resultMap> |
||||
<sql id="Base_Column_List"> |
||||
id, assess_user_id, coin_name, days, assets, create_time |
||||
</sql> |
||||
|
||||
<insert id="insertBatch" parameterType="java.util.List"> |
||||
insert into yyyf_assets_reporter |
||||
(<include refid="Base_Column_List"/>) |
||||
values |
||||
<foreach collection="list" item="assetsReporter" index="index" separator=","> |
||||
( |
||||
#{assetsReporter.id}, |
||||
#{assetsReporter.assess_user_id}, |
||||
#{assetsReporter.coin_name}, |
||||
#{assetsReporter.days}, |
||||
#{assetsReporter.assets}, |
||||
#{assetsReporter.create_time} |
||||
) |
||||
</foreach> |
||||
</insert> |
||||
|
||||
<select id="selectByAssessUserId" resultMap="BaseResultMap" parameterType="java.lang.String"> |
||||
select |
||||
<include refid="Base_Column_List"/> |
||||
from yyyf_assets_reporter |
||||
where assess_user_id = #{assessUserId,jdbcType=VARCHAR} |
||||
</select> |
||||
</mapper> |
Loading…
Reference in new issue