fanxw лет назад: 5
Родитель
Сommit
a50bb7627a

+ 4 - 37
src/main/java/com/chinaitop/depot/keeperAccount/controller/StorageAccountRecordController.java

@@ -7,7 +7,6 @@ import java.util.Map;
7 7
 import javax.annotation.Resource;
8 8
 import javax.servlet.http.HttpServletRequest;
9 9
 
10
-import org.apache.commons.lang.ObjectUtils;
11 10
 import org.springframework.http.MediaType;
12 11
 import org.springframework.web.bind.annotation.RequestMapping;
13 12
 import org.springframework.web.bind.annotation.RequestMethod;
@@ -44,46 +43,14 @@ public class StorageAccountRecordController {
44 43
     })
45 44
 	public PageInfo<Map<String, Object>> sumAccountList(HttpServletRequest request, Integer pageNum, Integer pageSize, 
46 45
 			Integer lspz, Integer lsxz, String startDate, String endDate) {
47
-		Map<String, Object> map = new HashMap<String, Object>();
48
-		if (lspz != null) {
49
-			map.put("pz", lspz+"");
50
-		}
51
-		if (lsxz != null) {
52
-			map.put("hwxz", lsxz+"");
53
-		}
46
+
54 47
 		if (pageNum!=null && pageSize!=null) {
55 48
 			PageHelper.startPage(pageNum, pageSize);
56 49
 		}
57
-		String orgId = ObjectUtils.toString(request.getSession().getAttribute("orgId"),"");
58
-		List<Map<String, Object>> list = recordService.selectKeepSumAccountData(map);
59
-		if (null != list && list.size() > 0) {
60
-			Map<String, Object> kcsl_map = null;
61
-			List<Map<String, Object>> group_list = null;
62
-			List<Map<String, Object>> kcsl_list = null;
63
-			double kcsl = 0d;
64
-			for (Map<String, Object> obj : list) {
65
-				kcsl_map = new HashMap<String, Object>();
66
-				kcsl_map.put("pz", obj.get("lspz"));
67
-				kcsl_map.put("hwxz", obj.get("hwxz"));
68
-				kcsl_map.put("rq", obj.get("rq"));
69
-				kcsl_map.put("orgId", orgId == "" ? null : Integer.parseInt(orgId));
70
-				//查询这个条件下有多少分组,然后把所有分组的数据相加
71
-				group_list = recordService.selectAccountGroup(kcsl_map);
72
-				if (null != group_list && group_list.size() > 0) {
73
-					for (Map<String, Object> gop : group_list) {
74
-						kcsl_map.put("houseId", gop.get("house_id"));
75
-						kcsl_map.put("wareId", gop.get("ware_id"));
76
-						kcsl_list = recordService.selectKCSL(kcsl_map);
77
-						if (null != kcsl_list && kcsl_list.size() > 0) {
78
-							kcsl = kcsl + Double.parseDouble(kcsl_list.get(0).get("kcsl")+"");
79
-						}
80
-					}
81
-					obj.put("kcsl", kcsl);
82
-					kcsl = 0d;
83
-				}
84
-			}
85
-		}
50
+		List<Map<String, Object>> list = recordService.getGroupByList(request, lspz, lsxz);
86 51
 		PageInfo<Map<String, Object>> pageInfo = new PageInfo<Map<String, Object>>(list);
52
+		pageInfo = recordService.setListData(request, pageInfo);
53
+
87 54
 		return pageInfo;
88 55
 	}
89 56
 

+ 66 - 31
src/main/java/com/chinaitop/depot/keeperAccount/mapper/StorageAccountRecordMapper.xml

@@ -465,40 +465,75 @@
465 465
   <!-- 保管总账查询列表 -->
466 466
   <select id="selectKeepSumAccount" parameterType="java.util.Map" resultType="java.util.Map">
467 467
 	SELECT 
468
-		fcbgz.hwxz, fcbgz.lspz, DATE_FORMAT(fcbgz.rq,'%Y-%m') as rq, sum(fcbgz.srsl) as srsl, 
469
-		sum(fcbgz.zcsl) as zcsl, (sum(fcbgz.srsl)-sum(fcbgz.zcsl)) as kcsl 
470
-	FROM (
471
-		SELECT * FROM storage_account_record where 1=1 AND account_type=0 AND auditor_date IS NOT NULL 
472
-		<if test="pz != null">
473
-	        and lspz = #{pz} 
474
-	    </if>
475
-	    <if test="hwxz != null">
476
-	        and hwxz = #{hwxz} 
477
-	    </if>
478
-	) fcbgz 
479
-	group by fcbgz.hwxz, fcbgz.lspz, DATE_FORMAT(fcbgz.rq,'%Y-%m') 
480
-	order by fcbgz.rq
468
+		hwxz, lspz, DATE_FORMAT(rq,'%Y-%m') as rq, sum(srsl) as srsl, sum(zcsl) as zcsl
469
+	FROM storage_account_record 
470
+	where 1=1 AND account_type=0 AND auditor_date IS NOT NULL 
471
+	<if test="pz != null">
472
+        and lspz = #{pz} 
473
+    </if>
474
+    <if test="hwxz != null">
475
+        and hwxz = #{hwxz} 
476
+    </if>
477
+    <if test="orgId != null">
478
+        and org_id = #{orgId} 
479
+    </if>
480
+	group by hwxz, lspz, DATE_FORMAT(rq,'%Y-%m') 
481
+	order by rq
481 482
   </select>
482 483
   <!-- 查询当前条件下的总账分组类别 -->
483 484
   <select id="selectAccountGroup" parameterType="java.util.Map" resultType="java.util.Map">
484
-  	SELECT house_id,ware_id,lspz,hwxz,DATE_FORMAT(rq, '%Y-%m') rq FROM storage_account_record 
485
-	WHERE 1=1 
486
-	AND account_type = 0 
487
-	AND auditor_date IS NOT NULL
488
-	<if test="rq != null">
489
-	AND DATE_FORMAT(rq, '%Y-%m') = #{rq}
490
-	</if>
491
-	<if test="orgId != null">
492
-	AND org_id=#{orgId}
493
-	</if>
494
-	<if test="pz != null">
495
-	and lspz = #{pz}
496
-	</if>
497
-	<if test="hwxz != null">
498
-    and hwxz = #{hwxz} 
499
-	</if>
500
-	GROUP BY house_id, ware_id, lspz, hwxz 
501
-	ORDER BY house_id, ware_id 
485
+<!--   	SELECT house_id,ware_id,lspz,hwxz,DATE_FORMAT(rq, '%Y-%m') rq FROM storage_account_record  -->
486
+<!-- 	WHERE 1=1  -->
487
+<!-- 	AND account_type = 0  -->
488
+<!-- 	AND auditor_date IS NOT NULL -->
489
+<!-- 	<if test="rq != null"> -->
490
+<!-- 	AND DATE_FORMAT(rq, '%Y-%m') = #{rq} -->
491
+<!-- 	</if> -->
492
+<!-- 	<if test="orgId != null"> -->
493
+<!-- 	AND org_id=#{orgId} -->
494
+<!-- 	</if> -->
495
+<!-- 	<if test="pz != null"> -->
496
+<!-- 	and lspz = #{pz} -->
497
+<!-- 	</if> -->
498
+<!-- 	<if test="hwxz != null"> -->
499
+<!--     and hwxz = #{hwxz}  -->
500
+<!-- 	</if> -->
501
+<!-- 	GROUP BY house_id, ware_id, lspz, hwxz  -->
502
+<!-- 	ORDER BY house_id, ware_id  -->
503
+    SELECT org_id,lspz,hwxz, rq, SUM(kcsl) kcsl 
504
+    FROM (
505
+		SELECT a.org_id,a.house_id,a.ware_id,a.lspz,a.hwxz,DATE_FORMAT(a.rq, '%Y-%m') rq,b.kcsl 
506
+		FROM (
507
+			SELECT org_id,house_id,ware_id,lspz,hwxz,DATE_FORMAT(rq, '%Y-%m'),MAX(rq) rq 
508
+			from storage_account_record
509
+			WHERE 1=1 
510
+			AND account_type = 0 
511
+			AND auditor_date IS NOT NULL
512
+			<if test="rq != null">
513
+			AND DATE_FORMAT(rq, '%Y-%m') = #{rq}
514
+			</if>
515
+			<if test="orgId != null">
516
+			AND org_id=#{orgId}
517
+			</if>
518
+			<if test="pz != null">
519
+			and lspz = #{pz}
520
+			</if>
521
+			<if test="hwxz != null">
522
+		    and hwxz = #{hwxz} 
523
+			</if>
524
+			GROUP BY org_id,house_id,ware_id,lspz,hwxz,DATE_FORMAT(rq, '%Y-%m')
525
+		) a
526
+		LEFT JOIN storage_account_record b on 
527
+			b.rq = a.rq 
528
+			AND b.org_id=a.org_id 
529
+			AND b.house_id=a.house_id 
530
+			AND b.ware_id=a.ware_id 
531
+			AND b.lspz=a.lspz 
532
+			AND b.hwxz=a.hwxz 
533
+			and b.rq=a.rq
534
+		WHERE b.auditor_date IS NOT NULL and b.account_type = 0 
535
+	) q 
536
+	GROUP BY q.lspz,q.hwxz,q.rq
502 537
   </select>
503 538
   <!-- 查询保管总账查询列表的库存数量 -->
504 539
   <select id="selectKCSL" parameterType="java.util.Map" resultType="java.util.Map">

+ 20 - 0
src/main/java/com/chinaitop/depot/keeperAccount/service/StorageAccountRecordService.java

@@ -3,8 +3,11 @@ package com.chinaitop.depot.keeperAccount.service;
3 3
 import java.util.List;
4 4
 import java.util.Map;
5 5
 
6
+import javax.servlet.http.HttpServletRequest;
7
+
6 8
 import com.chinaitop.depot.keeperAccount.model.StorageAccountRecord;
7 9
 import com.chinaitop.depot.keeperAccount.model.StorageAccountRecordExample;
10
+import com.github.pagehelper.PageInfo;
8 11
 
9 12
 public interface StorageAccountRecordService {
10 13
 
@@ -69,4 +72,21 @@ public interface StorageAccountRecordService {
69 72
      * @return
70 73
      */
71 74
 	List<Map<String, Object>> selectAccountGroup(Map<String, Object> map);
75
+
76
+	/**
77
+	 * 查询保管总账列表
78
+	 * 
79
+	 * @param lspz 粮食品种
80
+	 * @param lsxz 粮食性质
81
+	 * @return
82
+	 */
83
+	List<Map<String, Object>> getGroupByList(HttpServletRequest request, Integer lspz, Integer lsxz);
84
+
85
+	/**
86
+	 * 给每条数据赋值库存数量
87
+	 * 
88
+	 * @param pageInfo 结果集
89
+	 * @return
90
+	 */
91
+	PageInfo<Map<String, Object>> setListData(HttpServletRequest request, PageInfo<Map<String, Object>> pageInfo);
72 92
 }

+ 43 - 0
src/main/java/com/chinaitop/depot/keeperAccount/service/impl/StorageAccountRecordServiceImpl.java

@@ -1,16 +1,20 @@
1 1
 package com.chinaitop.depot.keeperAccount.service.impl;
2 2
 
3
+import java.util.HashMap;
3 4
 import java.util.List;
4 5
 import java.util.Map;
5 6
 
6 7
 import javax.annotation.Resource;
8
+import javax.servlet.http.HttpServletRequest;
7 9
 
10
+import org.apache.commons.lang.ObjectUtils;
8 11
 import org.springframework.stereotype.Service;
9 12
 
10 13
 import com.chinaitop.depot.keeperAccount.mapper.StorageAccountRecordMapper;
11 14
 import com.chinaitop.depot.keeperAccount.model.StorageAccountRecord;
12 15
 import com.chinaitop.depot.keeperAccount.model.StorageAccountRecordExample;
13 16
 import com.chinaitop.depot.keeperAccount.service.StorageAccountRecordService;
17
+import com.github.pagehelper.PageInfo;
14 18
 
15 19
 @Service
16 20
 public class StorageAccountRecordServiceImpl implements StorageAccountRecordService {
@@ -80,4 +84,43 @@ public class StorageAccountRecordServiceImpl implements StorageAccountRecordServ
80 84
 	public List<Map<String, Object>> selectAccountGroup(Map<String, Object> map) {
81 85
 		return mapper.selectAccountGroup(map);
82 86
 	}
87
+
88
+	@Override
89
+	public List<Map<String, Object>> getGroupByList(HttpServletRequest request, Integer lspz, Integer lsxz) {
90
+		String orgId = ObjectUtils.toString(request.getSession().getAttribute("orgId"),"");
91
+		Map<String, Object> map = new HashMap<String, Object>();
92
+		if (lspz != null) {
93
+			map.put("pz", lspz+"");
94
+		}
95
+		if (lsxz != null) {
96
+			map.put("hwxz", lsxz+"");
97
+		}
98
+		if (orgId != null) {
99
+			map.put("orgId", orgId);
100
+		}
101
+		List<Map<String, Object>> list = mapper.selectKeepSumAccount(map);
102
+		return list;
103
+	}
104
+
105
+	@Override
106
+	public PageInfo<Map<String, Object>> setListData(HttpServletRequest request, PageInfo<Map<String, Object>> pageInfo) {
107
+		String orgId = ObjectUtils.toString(request.getSession().getAttribute("orgId"),"");
108
+		if (null != pageInfo.getList() && pageInfo.getList().size() > 0) {
109
+			Map<String, Object> kcsl_map = null;
110
+			List<Map<String, Object>> group_list = null;
111
+			for (Map<String, Object> obj : pageInfo.getList()) {
112
+				kcsl_map = new HashMap<String, Object>();
113
+				kcsl_map.put("pz", obj.get("lspz"));
114
+				kcsl_map.put("hwxz", obj.get("hwxz"));
115
+				kcsl_map.put("rq", obj.get("rq"));
116
+				kcsl_map.put("orgId", orgId == "" ? null : Integer.parseInt(orgId));
117
+				//查询这个条件下有多少库存数量
118
+				group_list = mapper.selectAccountGroup(kcsl_map);
119
+				if (null != group_list && group_list.size() > 0) {
120
+					obj.put("kcsl", group_list.get(0).get("kcsl"));
121
+				}
122
+			}
123
+		}
124
+		return pageInfo;
125
+	}
83 126
 }