From 72b971c98c46531064d74b68fc8fe8864ed0b544 Mon Sep 17 00:00:00 2001
From: guoshilong <123456>
Date: Tue, 08 Nov 2022 09:04:56 +0800
Subject: [PATCH] 大屏溯源统计次数sql修改

---
 src/main/java/org/springblade/modules/stock/controller/StockController.java |  325 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 318 insertions(+), 7 deletions(-)

diff --git a/src/main/java/org/springblade/modules/stock/controller/StockController.java b/src/main/java/org/springblade/modules/stock/controller/StockController.java
index 1398a8a..85c9ab5 100644
--- a/src/main/java/org/springblade/modules/stock/controller/StockController.java
+++ b/src/main/java/org/springblade/modules/stock/controller/StockController.java
@@ -41,7 +41,12 @@
 import org.springblade.modules.stock.service.IStockService;
 import org.springblade.core.boot.ctrl.BladeController;
 
+import java.math.BigDecimal;
+import java.text.DecimalFormat;
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
  * 农资库存表 控制器
@@ -103,6 +108,28 @@
 	}
 
 	/**
+	 * 自定义分页 农资库存表
+	 */
+	@GetMapping("/pages")
+	@ApiOperationSupport(order = 3)
+	@ApiOperation(value = "分页", notes = "传入stock")
+	public R<List<StockVO>> pages(StockVO stock) {
+		List<StockVO> pages = stockService.selectListss(stock);
+		for (int i = 0; i < pages.size(); i++) {
+			String specs = pages.get(i).getSpecs();
+			Integer amount = pages.get(i).getAmount();
+			Integer num = Integer.parseInt(specs);
+			String dic1 = pages.get(i).getDic1();
+			String dic2 = pages.get(i).getDic2();
+			String s = specs + dic1 + "/" + dic2;
+			pages.get(i).setSpn(s);
+			pages.get(i).setCnum(num * amount);
+
+		}
+		return R.data(pages);
+	}
+
+	/**
 	 * 新增 农资库存表
 	 */
 	@PostMapping("/save")
@@ -127,38 +154,41 @@
 		stockrecord.setSpecs1(stock.getSpecs());
 		stockrecord.setSpecsVal1(stock.getSpecsValue1());
 		stockrecord.setSpecsVal2(stock.getSpecsValue2());
+		stockrecord.setDeptId(stock.getDeptId());
 		stockrecord.setSp1("stockSpecs1");
 		stockrecord.setSp2("stockSpecs2");
 		//统计公斤
 		Integer amount = stock.getAmount();
+		String specs = stock.getSpecs();
+		int i = Integer.parseInt(specs);
 		Integer specsValue1 = stock.getSpecsValue1();
 		double v = 0;
 		//克
 		if (specsValue1 == 0) {
-			v = amount * 0.001;
+			v = amount * i * 0.001;
 		}
 		//斤
 		if (specsValue1 == 1) {
-			v = amount * 0.5;
+			v = amount * i * 0.5;
 		}
 		//公斤
 		if (specsValue1 == 2) {
-			v = amount;
+			v = amount * i;
 		}
 		//吨
 		if (specsValue1 == 3) {
-			v = amount * 1000;
+			v = amount * i * 1000;
 		}
 		//毫升
 		if (specsValue1 == 4) {
 			//毫升换成升
-			double s = amount * 0.001;
+			double s = amount * i * 0.001;
 			//升换成公斤
 			v = s;
 		}
 		//升
 		if (specsValue1 == 5) {
-			v = amount;
+			v = amount * i;
 		}
 		stockrecord.setCensus(v);
 		stockrecordService.save(stockrecord);
@@ -217,9 +247,290 @@
 			double v1 = lycknum + dbcknum + bfcknum;
 			pages.getRecords().get(i).setCknum(v1);
 		}
-
 		return R.data(pages);
 	}
 
 
+	/**
+	 * 首页农资入库数量统计
+	 *
+	 * @return
+	 */
+	@GetMapping("/StockCount")
+	public R StockCount(String deptId) {
+		List<Map<String, Object>> maps = stockService.StockCount(deptId);
+		//化肥0
+		double hf = 0;
+		//有机肥1
+		double yjf = 0;
+		//杀虫剂2
+		double scj = 0;
+		//杀菌剂3
+		double sjj = 0;
+		//饲料4
+		double sl = 0;
+		for (int i = 0; i < maps.size(); i++) {
+			//规格
+			String specs = maps.get(i).get("specs").toString();
+			Integer specs1 = Integer.parseInt(specs);
+			//数量
+			String amount = maps.get(i).get("amount").toString();
+			Integer amount1 = Integer.parseInt(amount);
+			//规格类型
+			String spe = maps.get(i).get("spe").toString();
+			//类型
+			String type = maps.get(i).get("type").toString();
+			if (type.equals("0")) {
+				//克
+				if (spe.equals("0")) {
+					hf += amount1 * specs1 * 0.001;
+				}
+				//斤
+				if (spe.equals("1")) {
+					hf += amount1 * specs1 * 0.5;
+				}
+				//公斤
+				if (spe.equals("2")) {
+					hf += amount1 * specs1;
+				}
+				//吨
+				if (spe.equals("3")) {
+					hf += amount1 * specs1 * 1000;
+				}
+				//毫升
+				if (spe.equals("4")) {
+					//毫升换成升
+					double s = amount1 * specs1 * 0.001;
+					//升换成公斤
+					hf += s;
+				}
+				//升
+				if (spe.equals("5")) {
+					hf += amount1 * specs1;
+				}
+			}
+			if (type.equals("1")) {
+				//克
+				if (spe.equals("0")) {
+					yjf += amount1 * specs1 * 0.001;
+				}
+				//斤
+				if (spe.equals("1")) {
+					yjf += amount1 * specs1 * 0.5;
+				}
+				//公斤
+				if (spe.equals("2")) {
+					yjf += amount1 * specs1;
+				}
+				//吨
+				if (spe.equals("3")) {
+					yjf += amount1 * specs1 * 1000;
+				}
+				//毫升
+				if (spe.equals("4")) {
+					//毫升换成升
+					double s = amount1 * specs1 * 0.001;
+					//升换成公斤
+					yjf += s;
+				}
+				//升
+				if (spe.equals("5")) {
+					yjf += amount1 * specs1;
+				}
+			}
+			if (type.equals("2")) {
+				//克
+				if (spe.equals("0")) {
+					scj += amount1 * specs1 * 0.001;
+				}
+				//斤
+				if (spe.equals("1")) {
+					scj += amount1 * specs1 * 0.5;
+				}
+				//公斤
+				if (spe.equals("2")) {
+					scj += amount1 * specs1;
+				}
+				//吨
+				if (spe.equals("3")) {
+					scj += amount1 * specs1 * 1000;
+				}
+				//毫升
+				if (spe.equals("4")) {
+					//毫升换成升
+					double s = amount1 * specs1 * 0.001;
+					//升换成公斤
+					scj += s;
+				}
+				//升
+				if (spe.equals("5")) {
+					scj += amount1 * specs1;
+				}
+			}
+			if (type.equals("3")) {
+				//克
+				if (spe.equals("0")) {
+					sjj += amount1 * specs1 * 0.001;
+				}
+				//斤
+				if (spe.equals("1")) {
+					sjj += amount1 * specs1 * 0.5;
+				}
+				//公斤
+				if (spe.equals("2")) {
+					sjj += amount1 * specs1;
+				}
+				//吨
+				if (spe.equals("3")) {
+					sjj += amount1 * specs1 * 1000;
+				}
+				//毫升
+				if (spe.equals("4")) {
+					//毫升换成升
+					double s = amount1 * specs1 * 0.001;
+					//升换成公斤
+					sjj += s;
+				}
+				//升
+				if (spe.equals("5")) {
+					sjj += amount1 * specs1;
+				}
+			}
+			if (type.equals("4")) {
+				//克
+				if (spe.equals("0")) {
+					sl += amount1 * specs1 * 0.001;
+				}
+				//斤
+				if (spe.equals("1")) {
+					sl += amount1 * specs1 * 0.5;
+				}
+				//公斤
+				if (spe.equals("2")) {
+					sl += amount1 * specs1;
+				}
+				//吨
+				if (spe.equals("3")) {
+					sl += amount1 * specs1 * 1000;
+				}
+				//毫升
+				if (spe.equals("4")) {
+					//毫升换成升
+					double s = amount1 * specs1 * 0.001;
+					//升换成公斤
+					sl += s;
+				}
+				//升
+				if (spe.equals("5")) {
+					sl += amount1 * specs1;
+				}
+			}
+		}
+		Map map = new HashMap();
+		map.put("name", "化肥");
+		map.put("val", new BigDecimal(hf).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
+		Map map1 = new HashMap();
+		map1.put("name", "有机肥");
+		map1.put("val", new BigDecimal(String.valueOf(yjf)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
+		Map map2 = new HashMap();
+		map2.put("name", "杀虫剂");
+		map2.put("val", new BigDecimal(String.valueOf(scj)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
+		Map map3 = new HashMap();
+		map3.put("name", "杀菌剂");
+		map3.put("val", new BigDecimal(String.valueOf(sjj)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
+		Map map4 = new HashMap();
+		map4.put("name", "饲料");
+		map4.put("val", new BigDecimal(String.valueOf(sl)).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue());
+		List list = new ArrayList();
+		list.add(map);
+		list.add(map1);
+		list.add(map2);
+		list.add(map3);
+		list.add(map4);
+		return R.data(list);
+	}
+
+
+	/**
+	 * 小程序数据统计
+	 *
+	 * @return
+	 */
+	@GetMapping("/pagenumx")
+	public R pagenumx(String deptId, String startTime, String endTime) {
+		Double rknu = 0.0;
+		Double cknu = 0.0;
+		List<StocksVO> pages = stockService.slectNumx(deptId, startTime, endTime);
+		for (int i = 0; i < pages.size(); i++) {
+			Double cgnum = pages.get(i).getCgnum();
+			Double dbrknum = pages.get(i).getDbrknum();
+			double v = cgnum + dbrknum;
+			pages.get(i).setRknum(v);
+			Double lycknum = pages.get(i).getLycknum();
+			Double dbcknum = pages.get(i).getDbcknum();
+			Double bfcknum = pages.get(i).getBfcknum();
+			double v1 = lycknum + dbcknum + bfcknum;
+			pages.get(i).setCknum(v1);
+		}
+		for (int j = 0; j < pages.size(); j++) {
+			Double rknum = pages.get(j).getRknum();
+			Double cknum = pages.get(j).getCknum();
+			rknu += rknum;
+			cknu += cknum;
+		}
+		Map map = new HashMap();
+		DecimalFormat df = new DecimalFormat("#0.000");
+		String format = df.format(rknu);
+		Double a = Double.parseDouble(format);
+		String format1 = df.format(cknu);
+		double b = Double.parseDouble(format1);
+		map.put("rknum", a);
+		map.put("cknum", b);
+		return R.data(map);
+	}
+
+	/**
+	 * 小程序农资数据统计详情
+	 *
+	 * @param stock
+	 * @param query
+	 * @return
+	 */
+	@GetMapping("/pagenums")
+	public R pagenums(StocksVO stock, Query query) {
+		Double rknu = 0.0;
+		Double cknu = 0.0;
+		IPage<StocksVO> pages = stockService.slectNum(Condition.getPage(query), stock);
+		for (int i = 0; i < pages.getRecords().size(); i++) {
+			Double cgnum = pages.getRecords().get(i).getCgnum();
+			Double dbrknum = pages.getRecords().get(i).getDbrknum();
+			double v = cgnum + dbrknum;
+			pages.getRecords().get(i).setRknum(v);
+			Double lycknum = pages.getRecords().get(i).getLycknum();
+			Double dbcknum = pages.getRecords().get(i).getDbcknum();
+			Double bfcknum = pages.getRecords().get(i).getBfcknum();
+			double v1 = lycknum + dbcknum + bfcknum;
+			pages.getRecords().get(i).setCknum(v1);
+		}
+		for (int j = 0; j < pages.getRecords().size(); j++) {
+			Double rknum = pages.getRecords().get(j).getRknum();
+			Double cknum = pages.getRecords().get(j).getCknum();
+			rknu += rknum;
+			cknu += cknum;
+		}
+		Map map = new HashMap();
+		DecimalFormat df = new DecimalFormat("#0.000");
+		String format = df.format(rknu);
+		Double a = Double.parseDouble(format);
+		String format1 = df.format(cknu);
+		double b = Double.parseDouble(format1);
+		map.put("rknum", a);
+		map.put("cknum", b);
+		List list = new ArrayList();
+		list.add(map);
+		list.add(pages);
+		return R.data(list);
+	}
+
+
 }

--
Gitblit v1.9.3