commit
This commit is contained in:
@@ -3,10 +3,11 @@ package link.at17.mid.tushare.api.common;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.github.yulichang.query.MPJLambdaQueryWrapper;
|
||||
@@ -27,12 +28,21 @@ public class StockInfoController {
|
||||
|
||||
@GetMapping("list")
|
||||
private List<StockInfo> list(
|
||||
@Param("listStatus") ListStatus listStatus,
|
||||
@Param("stockMarket") StockMarket stockMarket) {
|
||||
@RequestParam(name="listStatus", required=false) ListStatus listStatus,
|
||||
@RequestParam(name="stockMarket", required=false) StockMarket[] stockMarket,
|
||||
@RequestParam(name="ths", required=false, defaultValue="false") Boolean ths) {
|
||||
MPJLambdaQueryWrapper<StockInfo> ew = new MPJLambdaQueryWrapper<StockInfo>();
|
||||
ew.setAlias("i");
|
||||
ew.eq(Objects.nonNull(listStatus), StockInfo::getListStatus, listStatus);
|
||||
ew.likeLeft(Objects.nonNull(stockMarket), StockInfo::getTsCode, stockMarket);
|
||||
return stockInfoService.list(ew);
|
||||
if (ArrayUtils.isNotEmpty(stockMarket)) {
|
||||
ew.and(w -> {
|
||||
for (int i = 0; i < stockMarket.length; i++) {
|
||||
w.likeLeft(StockInfo::getTsCode, stockMarket[i]);
|
||||
if (i != stockMarket.length - 1) {
|
||||
w.or();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return ths ? stockInfoService.list(ew) : stockInfoService.listWithoutThs(ew);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package link.at17.mid.tushare.dao;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.github.yulichang.base.MPJBaseMapper;
|
||||
|
||||
import link.at17.mid.tushare.annotation.BatchInsert;
|
||||
@@ -21,4 +22,5 @@ public interface StockInfoDao extends MPJBaseMapper<StockInfo> {
|
||||
void insertOrUpdateList(@BatchList List<JSONObject> list);
|
||||
StockInfo getStockInfoByStockCode(@Param("stockCode") String stockCode);
|
||||
List<StockInfo> getStockListByListStatus(ListStatus listStatus);
|
||||
List<StockInfo> selectListWithoutThs(@Param("ew") Wrapper<StockInfo> ew);
|
||||
}
|
||||
|
||||
@@ -30,21 +30,22 @@ public class StockInfoService extends BaseServiceImpl<StockInfoDao, StockInfo> {
|
||||
}
|
||||
|
||||
/**
|
||||
* 用这个方法的话,传入的 Wrapper 需要设置别名 i
|
||||
* <p>
|
||||
* 如果用 QueryWrapper:
|
||||
* <p>
|
||||
* {@code ew.eq("i.ts_code", "000001.SZ")}
|
||||
* <p>
|
||||
* 如果用 MPJLambdaQueryWrapper:
|
||||
* <p>
|
||||
* {@code ew.setAlias("i").eq(StockInfo::getTsCode, "000001.SZ")}
|
||||
* 该方法涉及到 ThsBelongins 联查
|
||||
*/
|
||||
@Override
|
||||
public List<StockInfo> list(Wrapper<StockInfo> ew) {
|
||||
return baseMapper.selectList(ew);
|
||||
}
|
||||
|
||||
/**
|
||||
* 该方法为单表查询,不涉及 ThsBelongins 联查
|
||||
* @param ew
|
||||
* @return
|
||||
*/
|
||||
public List<StockInfo> listWithoutThs(Wrapper<StockInfo> ew) {
|
||||
return baseMapper.selectListWithoutThs(ew);
|
||||
}
|
||||
|
||||
/**
|
||||
* 用于插入从 Tushare 获取的内容
|
||||
* @param list
|
||||
|
||||
@@ -68,33 +68,31 @@
|
||||
ORDER BY i.ts_code ASC
|
||||
</select>
|
||||
|
||||
<select id="list" resultType="link.at17.mid.tushare.data.models.StockInfo">
|
||||
SELECT
|
||||
i.*,
|
||||
STRING_AGG(l."name", ', ' ORDER BY l.list_date DESC) AS ths_belongings
|
||||
FROM
|
||||
stock_info i
|
||||
LEFT JOIN stock_ths_member m ON m.con_code = i.ts_code
|
||||
LEFT JOIN stock_ths_list l ON l.ts_code = m.ts_code
|
||||
<if test="ew != null">
|
||||
${ew.customSqlSegment}
|
||||
</if>
|
||||
GROUP BY i.ts_code
|
||||
ORDER BY i.ts_code ASC
|
||||
</select>
|
||||
|
||||
<!-- 用到 MPJLambdaQuery 的,其自身会包含表别名 t,所以直接拼接 -->
|
||||
<select id="selectList" resultType="link.at17.mid.tushare.data.models.StockInfo">
|
||||
SELECT
|
||||
i.*,
|
||||
${ew.alias}.*,
|
||||
STRING_AGG(l."name", ', ' ORDER BY l.list_date DESC) AS ths_belongings
|
||||
FROM
|
||||
stock_info i
|
||||
LEFT JOIN stock_ths_member m ON m.con_code = i.ts_code
|
||||
stock_info ${ew.alias}
|
||||
LEFT JOIN stock_ths_member m ON m.con_code = ${ew.alias}.ts_code
|
||||
LEFT JOIN stock_ths_list l ON l.ts_code = m.ts_code
|
||||
<if test="ew != null">
|
||||
${ew.customSqlSegment}
|
||||
</if>
|
||||
GROUP BY i.ts_code
|
||||
ORDER BY i.ts_code ASC
|
||||
GROUP BY ${ew.alias}.ts_code
|
||||
ORDER BY ${ew.alias}.ts_code ASC
|
||||
</select>
|
||||
|
||||
<select id="selectListWithoutThs" resultType="link.at17.mid.tushare.data.models.StockInfo">
|
||||
SELECT
|
||||
${ew.alias}.*
|
||||
FROM
|
||||
stock_info ${ew.alias}
|
||||
<if test="ew != null">
|
||||
${ew.customSqlSegment}
|
||||
</if>
|
||||
GROUP BY ${ew.alias}.ts_code
|
||||
ORDER BY ${ew.alias}.ts_code ASC
|
||||
</select>
|
||||
</mapper>
|
||||
|
||||
Reference in New Issue
Block a user