package com.vincent.rsf.server.api.controller; import com.vincent.rsf.framework.common.R; import com.vincent.rsf.server.manager.service.CusItemSyncViewQueryService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.commons.lang3.StringUtils; 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 java.util.Arrays; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; /** * 鼎捷 查询验证(/test/** 免登录) */ @RestController @RequestMapping("/test/cusItemSyncView") @Api(tags = "鼎捷 测试") public class CusItemSyncViewTestController { @Autowired private CusItemSyncViewQueryService cusItemSyncViewQueryService; @GetMapping("/probe") @ApiOperation("取视图前几条样例,验证副库/主库连通") public R probe(@RequestParam(defaultValue = "5") int limit) { Map body = new LinkedHashMap<>(); body.put("effectiveDataSource", cusItemSyncViewQueryService.effectiveDataSourceLabel()); body.put("rows", cusItemSyncViewQueryService.probeSample(limit)); return R.ok().add(body); } @GetMapping("/byCodes") @ApiOperation("按物料编码查询视图(逗号分隔)") public R byCodes(@RequestParam String codes) { if (StringUtils.isBlank(codes)) { return R.error("codes 不能为空,示例:/test/cusItemSyncView/byCodes?codes=A001,B002"); } List list = Arrays.stream(codes.split(",")) .map(String::trim) .filter(StringUtils::isNotBlank) .collect(Collectors.toList()); if (list.isEmpty()) { return R.error("codes 解析后为空"); } Map body = new LinkedHashMap<>(); body.put("effectiveDataSource", cusItemSyncViewQueryService.effectiveDataSourceLabel()); body.put("rows", cusItemSyncViewQueryService.listByItemNos(list)); return R.ok().add(body); } }