diff --git a/src/main/java/link/at17/mid/tushare/api/common/StockInfoController.java b/src/main/java/link/at17/mid/tushare/api/common/StockInfoController.java index 1586499..a54ddd4 100644 --- a/src/main/java/link/at17/mid/tushare/api/common/StockInfoController.java +++ b/src/main/java/link/at17/mid/tushare/api/common/StockInfoController.java @@ -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 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 ew = new MPJLambdaQueryWrapper(); - 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); } } diff --git a/src/main/java/link/at17/mid/tushare/dao/StockInfoDao.java b/src/main/java/link/at17/mid/tushare/dao/StockInfoDao.java index 3ca7d01..1fc57e8 100644 --- a/src/main/java/link/at17/mid/tushare/dao/StockInfoDao.java +++ b/src/main/java/link/at17/mid/tushare/dao/StockInfoDao.java @@ -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 { void insertOrUpdateList(@BatchList List list); StockInfo getStockInfoByStockCode(@Param("stockCode") String stockCode); List getStockListByListStatus(ListStatus listStatus); + List selectListWithoutThs(@Param("ew") Wrapper ew); } diff --git a/src/main/java/link/at17/mid/tushare/data/service/StockInfoService.java b/src/main/java/link/at17/mid/tushare/data/service/StockInfoService.java index 66eced8..3c0b256 100644 --- a/src/main/java/link/at17/mid/tushare/data/service/StockInfoService.java +++ b/src/main/java/link/at17/mid/tushare/data/service/StockInfoService.java @@ -30,21 +30,22 @@ public class StockInfoService extends BaseServiceImpl { } /** - * 用这个方法的话,传入的 Wrapper 需要设置别名 i - *

- * 如果用 QueryWrapper:  - *

- *  {@code ew.eq("i.ts_code", "000001.SZ")} - *

- * 如果用 MPJLambdaQueryWrapper: - *

- *  {@code ew.setAlias("i").eq(StockInfo::getTsCode, "000001.SZ")} + * 该方法涉及到 ThsBelongins 联查 */ @Override public List list(Wrapper ew) { return baseMapper.selectList(ew); } + /** + * 该方法为单表查询,不涉及 ThsBelongins 联查 + * @param ew + * @return + */ + public List listWithoutThs(Wrapper ew) { + return baseMapper.selectListWithoutThs(ew); + } + /** * 用于插入从 Tushare 获取的内容 * @param list diff --git a/src/main/resources/mappers/StockInfo.xml b/src/main/resources/mappers/StockInfo.xml index cdcf1dc..e7f21dd 100644 --- a/src/main/resources/mappers/StockInfo.xml +++ b/src/main/resources/mappers/StockInfo.xml @@ -68,33 +68,31 @@ ORDER BY i.ts_code ASC - - + + +