大屏接口
This commit is contained in:
@@ -0,0 +1,31 @@
|
|||||||
|
package com.ruoyi.api.controller;
|
||||||
|
|
||||||
|
import com.ruoyi.api.service.IStockScreenService;
|
||||||
|
import com.ruoyi.common.core.domain.AjaxResult;
|
||||||
|
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.RestController;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/stock")
|
||||||
|
public class StockScreenController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IStockScreenService stockScreenService;
|
||||||
|
|
||||||
|
@GetMapping("/all")
|
||||||
|
public AjaxResult getAllStocks() {
|
||||||
|
return AjaxResult.success(stockScreenService.getAllStocksWithTotal());
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/cargoSpace/pie")
|
||||||
|
public AjaxResult getCargoSpacePie() {
|
||||||
|
return AjaxResult.success(stockScreenService.getCargoSpacePie());
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/inout/stat")
|
||||||
|
public AjaxResult getInOutStat() {
|
||||||
|
return AjaxResult.success(stockScreenService.getInOutSummary());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.ruoyi.api.service;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public interface IStockScreenService {
|
||||||
|
Map<String, Object> getAllStocksWithTotal();
|
||||||
|
Map<String, Object> getCargoSpacePie();
|
||||||
|
Map<String, Object> getInOutSummary();
|
||||||
|
}
|
||||||
@@ -0,0 +1,137 @@
|
|||||||
|
package com.ruoyi.api.service.impl;
|
||||||
|
|
||||||
|
import com.ruoyi.api.service.IStockScreenService;
|
||||||
|
import com.ruoyi.stock.stock.domain.BasStock;
|
||||||
|
import com.ruoyi.stock.stock.service.IBasStockService;
|
||||||
|
import com.ruoyi.bas.cargoSpace.mapper.BasCargoSpaceMapper;
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class StockScreenServiceImpl implements IStockScreenService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IBasStockService basStockService;
|
||||||
|
@Autowired
|
||||||
|
private BasCargoSpaceMapper basCargoSpaceMapper;
|
||||||
|
@Autowired
|
||||||
|
private JdbcTemplate jdbcTemplate;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> getAllStocksWithTotal() {
|
||||||
|
List<BasStock> list = basStockService.selectBasStockListApi(new BasStock());
|
||||||
|
BigDecimal total = BigDecimal.ZERO;
|
||||||
|
for (BasStock s : list) {
|
||||||
|
String q = s.getQuantity();
|
||||||
|
if (q != null && !q.trim().isEmpty()) {
|
||||||
|
try {
|
||||||
|
total = total.add(new BigDecimal(q.trim()));
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
List<BasStock> topList = list.size() > 50 ? list.subList(0, 50) : list;
|
||||||
|
result.put("stockMsg", topList);
|
||||||
|
result.put("totalQuantity", total);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> getCargoSpacePie() {
|
||||||
|
List<Map<String, Object>> statusCounts = basCargoSpaceMapper.selectStatusCount();
|
||||||
|
Map<String, Integer> countMap = new HashMap<>();
|
||||||
|
for (Map<String, Object> m : statusCounts) {
|
||||||
|
Object status = m.get("status");
|
||||||
|
Object count = m.get("count");
|
||||||
|
if (status != null && count != null) {
|
||||||
|
try {
|
||||||
|
countMap.put(String.valueOf(status), Integer.parseInt(String.valueOf(count)));
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int totalCount = 0;
|
||||||
|
for (Integer v : countMap.values()) {
|
||||||
|
totalCount += v != null ? v : 0;
|
||||||
|
}
|
||||||
|
List<Map<String, Object>> pie = new ArrayList<>();
|
||||||
|
Map<String, Object> i1 = new HashMap<>(); i1.put("value", countMap.getOrDefault("1", 0)); i1.put("name", "空货位"); pie.add(i1);
|
||||||
|
Map<String, Object> i2 = new HashMap<>(); i2.put("value", countMap.getOrDefault("2", 0)); i2.put("name", "满货位"); pie.add(i2);
|
||||||
|
Map<String, Object> i3 = new HashMap<>(); i3.put("value", countMap.getOrDefault("3", 0)); i3.put("name", "入库已分配"); pie.add(i3);
|
||||||
|
Map<String, Object> i4 = new HashMap<>(); i4.put("value", countMap.getOrDefault("4", 0)); i4.put("name", "出库已分配"); pie.add(i4);
|
||||||
|
Map<String, Object> i5 = new HashMap<>(); i5.put("value", countMap.getOrDefault("5", 0)); i5.put("name", "入库需盘点"); pie.add(i5);
|
||||||
|
Map<String, Object> i6 = new HashMap<>(); i6.put("value", countMap.getOrDefault("6", 0)); i6.put("name", "出库需盘点"); pie.add(i6);
|
||||||
|
Map<String, Object> result = new HashMap<>();
|
||||||
|
result.put("pie", pie);
|
||||||
|
result.put("totalCargoSpace", totalCount);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> getInOutSummary() {
|
||||||
|
java.time.LocalDate now = java.time.LocalDate.now();
|
||||||
|
java.time.format.DateTimeFormatter dFmt = java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||||
|
java.time.format.DateTimeFormatter mFmt = java.time.format.DateTimeFormatter.ofPattern("yyyy-MM");
|
||||||
|
String todayPrefix = now.format(dFmt);
|
||||||
|
int dIn = countLike("in_stockin_finish", todayPrefix);
|
||||||
|
int dOut = countLike("out_stockout_finish", todayPrefix);
|
||||||
|
|
||||||
|
java.time.LocalDate monday = now.with(java.time.DayOfWeek.MONDAY);
|
||||||
|
java.util.List<Integer> wkIn = new java.util.ArrayList<>();
|
||||||
|
java.util.List<Integer> wkOut = new java.util.ArrayList<>();
|
||||||
|
for (int i = 0; i < 7; i++) {
|
||||||
|
java.time.LocalDate day = monday.plusDays(i);
|
||||||
|
String p = day.format(dFmt);
|
||||||
|
wkIn.add(countLike("in_stockin_finish", p));
|
||||||
|
wkOut.add(countLike("out_stockout_finish", p));
|
||||||
|
}
|
||||||
|
|
||||||
|
int year = now.getYear();
|
||||||
|
java.util.List<java.util.Map<String, Object>> monthStat = new java.util.ArrayList<>();
|
||||||
|
for (int m = 1; m <= 12; m++) {
|
||||||
|
java.time.LocalDate mm = java.time.LocalDate.of(year, m, 1);
|
||||||
|
String mp = mm.format(mFmt);
|
||||||
|
int mi = countLikeMonth("in_stockin_finish", mp);
|
||||||
|
int mo = countLikeMonth("out_stockout_finish", mp);
|
||||||
|
java.util.Map<String, Object> item = new java.util.HashMap<>();
|
||||||
|
item.put("mouth", String.valueOf(m));
|
||||||
|
item.put("入库", mi);
|
||||||
|
item.put("出库", mo);
|
||||||
|
monthStat.add(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
java.util.Map<String, Object> res = new java.util.HashMap<>();
|
||||||
|
res.put("drrk", String.valueOf(dIn));
|
||||||
|
res.put("drck", String.valueOf(dOut));
|
||||||
|
res.put("bzrk", wkIn);
|
||||||
|
res.put("bzck", wkOut);
|
||||||
|
res.put("statistic", monthStat);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int countLike(String table, String dayPrefix) {
|
||||||
|
try {
|
||||||
|
Integer c = jdbcTemplate.queryForObject("SELECT COUNT(1) FROM " + table + " WHERE create_date LIKE ?", Integer.class, dayPrefix + "%");
|
||||||
|
return c == null ? 0 : c;
|
||||||
|
} catch (Exception e) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int countLikeMonth(String table, String monthPrefix) {
|
||||||
|
try {
|
||||||
|
Integer c = jdbcTemplate.queryForObject("SELECT COUNT(1) FROM " + table + " WHERE create_date LIKE ?", Integer.class, monthPrefix + "%");
|
||||||
|
return c == null ? 0 : c;
|
||||||
|
} catch (Exception e) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user