package com.zy.crm.common.web; import com.core.common.Cools; import com.core.common.R; import com.zy.crm.common.service.DbSqlServer; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.ClassPathResource; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; import java.io.IOException; import java.io.InputStream; import java.util.List; import java.util.Map; /** * Created by vincent on 2023/7/25 */ @RestController @SuppressWarnings("all") public class DatavController { private String 生产订单; private String 销售订单; { try { this.生产订单 = read(new ClassPathResource("datav/sql/生产订单.sql").getInputStream()); this.销售订单 = read(new ClassPathResource("datav/sql/销售订单.sql").getInputStream()); } catch (IOException ignore) {} } @Autowired private DbSqlServer dbSqlServer; @GetMapping("/data1") public R data1() { List> res = dbSqlServer.select(this.生产订单); if (Cools.isEmpty(res)) { return R.ok(); } int limit = 30; if (res.size() > limit) { res = res.subList(0, limit); } return R.ok().add(res); } @GetMapping("/data3") public R data3() { List> res = dbSqlServer.select(this.销售订单); if (Cools.isEmpty(res)) { return R.ok(); } return R.ok().add(res); } private static String read(InputStream inputStream) { StringBuilder stringBuilder = new StringBuilder(); byte[] buffer = new byte[1024]; try { int bytesRead; while ((bytesRead = inputStream.read(buffer)) != -1) { stringBuilder.append(new String(buffer, 0, bytesRead)); } } catch (IOException e) { e.printStackTrace(); } finally { try { inputStream.close(); } catch (IOException e) { e.printStackTrace(); } } return stringBuilder.toString(); } }