Browse Source

客户验收单根据日期段过滤,导出。

git-svn-id: svn+ssh://10.10.101.21/source/platform/platform-b2b@7227 f3bf4e98-0cf0-11e4-a00c-a99a8b9d557d
dongbw 9 năm trước cách đây
mục cha
commit
40b87e0ee7

+ 12 - 5
src/main/java/com/uas/platform/b2b/controller/SaleAcceptController.java

@@ -14,6 +14,8 @@ import org.springframework.web.bind.annotation.ResponseBody;
 import org.springframework.web.servlet.ModelAndView;
 
 import com.alibaba.dubbo.common.utils.CollectionUtils;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.uas.platform.b2b.model.PurchaseAccept;
 import com.uas.platform.b2b.model.SearchFilter;
 import com.uas.platform.b2b.search.SearchService;
@@ -25,6 +27,7 @@ import com.uas.platform.b2b.support.UsageBufferedLogger;
 import com.uas.platform.core.logging.BufferedLoggerManager;
 import com.uas.platform.core.model.PageInfo;
 import com.uas.platform.core.model.PageParams;
+import com.uas.platform.core.util.serializer.FlexJsonUtils;
 import com.uas.search.b2b.model.MultiValue;
 import com.uas.search.b2b.model.SPage;
 import com.uas.search.b2b.model.Sort;
@@ -62,9 +65,12 @@ public class SaleAcceptController {
 	 */
 	@RequestMapping(method = RequestMethod.GET)
 	@ResponseBody
-	public SPage<PurchaseAccept> getReceivedPurchaseAccepts(PageParams params, String keyword) {
+	public SPage<PurchaseAccept> getReceivedPurchaseAccepts(PageParams params, String searchFilter) {
+		System.out.println("controller的searchFilter" + JSON.toJSONString(searchFilter));
+		JSONObject jsonObject = JSONObject.parseObject(searchFilter);
+		String keyword = jsonObject.getString("keyword");
 		logger.log("客户验收单", "获取全部客户验收单");
-		com.uas.search.b2b.model.PageParams pageParams = searchService.convertPageParams(params, null);
+		com.uas.search.b2b.model.PageParams pageParams = searchService.convertPageParams(params, searchFilter);
 		// 当前登录企业作为供应商
 		pageParams.getFilters().put("pa_venduu", SystemSession.getUser().getEnterprise().getUu());
 		SearchFilter filter = userService.distribute();
@@ -104,16 +110,17 @@ public class SaleAcceptController {
 	 * @return
 	 */
 	@RequestMapping(value = "/xls", method = RequestMethod.GET)
-	public ModelAndView export(String keyword) {
+	public ModelAndView export(String searchFilter) {
+		SearchFilter filter = FlexJsonUtils.fromJson(searchFilter, SearchFilter.class);
 		PageInfo pageInfo = new PageInfo(1, JxlsExcelView.MAX_SIZE, 0);
 		pageInfo.sorting("date", Direction.DESC);
 		pageInfo.filter("vendUU", SystemSession.getUser().getEnterprise().getUu());
 		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy年MM月dd日");
 		ModelAndView modelAndView = new ModelAndView();
 		modelAndView.addObject("dateFormat", dateFormat);
-		modelAndView.addObject("data", purchaseAcceptService.findAllByPageInfo(pageInfo, keyword, null).getContent());
+		modelAndView.addObject("data", purchaseAcceptService.findAllByPageInfo(pageInfo, filter).getContent());
 		modelAndView.setView(new JxlsExcelView("classpath:jxls-tpl/sale/saleAccept", "客户验收单列表"));
-		logger.log("客户验收单", "导出Excel列表", "导出全部Excel列表");
+		logger.log("客户验收单", "导出Excel列表", "导出Excel列表");
 		return modelAndView;
 	}
 

+ 1 - 1
src/main/java/com/uas/platform/b2b/service/PurchaseAcceptService.java

@@ -59,7 +59,7 @@ public interface PurchaseAcceptService {
 	 * @param keyword 查找关键字
 	 * @return
 	 */
-	public Page<PurchaseAccept> findAllByPageInfo(PageInfo pageInfo, String keyword, SearchFilter filter);
+	public Page<PurchaseAccept> findAllByPageInfo(PageInfo pageInfo, SearchFilter filter);
 	
 	/**
 	 * 用客户采购验收单ID查找客户采购验收

+ 33 - 17
src/main/java/com/uas/platform/b2b/service/impl/PurchaseAcceptServiceImpl.java

@@ -1,12 +1,16 @@
 package com.uas.platform.b2b.service.impl;
 
 import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
 import java.util.List;
 
 import javax.persistence.criteria.CriteriaBuilder;
 import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.JoinType;
 import javax.persistence.criteria.Predicate;
 import javax.persistence.criteria.Root;
+import javax.persistence.criteria.SetJoin;
 
 import org.apache.commons.collections.CollectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -121,27 +125,39 @@ public class PurchaseAcceptServiceImpl implements PurchaseAcceptService {
 	}
 
 	@Override
-	public Page<PurchaseAccept> findAllByPageInfo(final PageInfo pageInfo, final String keyword,
-			final SearchFilter filter) {
-		return purchaseAcceptDao.findAll(new Specification<PurchaseAccept>() {
-
-			public Predicate toPredicate(Root<PurchaseAccept> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
-				if (filter != null) {
-					if (!CollectionUtils.isEmpty(filter.getDistribute()))
-						pageInfo.expression(PredicateUtils.in("enUU", filter.getDistribute(), false));
+	public Page<PurchaseAccept> findAllByPageInfo(final PageInfo pageInfo, final SearchFilter filter) {
+		if (filter != null) {
+			if (StringUtils.hasText(filter.getKeyword())) {
+				List<Object> lists = new ArrayList<>();
+				List<PurchaseAccept> listss = searchService.searchPurchaseAcceptIds(filter.getKeyword(), null).getContent();
+				for (PurchaseAccept list : listss) {
+					lists.add(list.getId());
 				}
-				if (StringUtils.hasText(keyword)) {
-					List<Object> lists = new ArrayList<>();
-					List<PurchaseAccept> listss = searchService.searchPurchaseAcceptIds(keyword, null).getContent();
-					for (PurchaseAccept list : listss) {
-						lists.add(list.getId());
-					}
-					pageInfo.expression(PredicateUtils.in("id", lists, false));
+				pageInfo.expression(PredicateUtils.in("id", lists, false));
+			}
+			if (filter.getFromDate() != null)
+				pageInfo.expression(PredicateUtils.gte("date", new Date(filter.getFromDate()), false));
+			if (filter.getEndDate() != null)
+				pageInfo.expression(PredicateUtils.lte("date", new Date(filter.getEndDate()), false));
+			if (!CollectionUtils.isEmpty(filter.getDistribute()))
+				pageInfo.expression(PredicateUtils.in("enUU", filter.getDistribute(), false));
+		}
+		Page<PurchaseAccept> pageAccept = purchaseAcceptDao.findAll(new Specification<PurchaseAccept>() {
+			@Override
+			public Predicate toPredicate(Root<PurchaseAccept> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
+				Predicate[] predicates = pageInfo.getPredicates(root, query, builder);
+				if (filter != null && filter.getFromDelivery() != null) {
+					predicates = Arrays.copyOf(predicates, predicates.length + 1);
+					SetJoin<PurchaseAccept, PurchaseAcceptItem> join = root
+							.join(root.getModel().getSet("acceprItems", PurchaseAcceptItem.class), JoinType.INNER);
+					Predicate p = builder.greaterThanOrEqualTo(join.get("delivery").as(Date.class),
+							new Date(filter.getFromDelivery()));
+					predicates[predicates.length - 1] = p;
 				}
-				query.where(pageInfo.getPredicates(root, query, builder));
-				return null;
+				return query.where(predicates).getRestriction();
 			}
 		}, pageInfo);
+		return pageAccept;
 	}
 
 	@Override

+ 36 - 18
src/main/webapp/resources/js/index/app.js

@@ -3916,20 +3916,24 @@ app.controller('SaleSendCtrl', ['$scope', '$filter', 'SaleSend', 'ngTableParams'
 	 */
 	app.controller('SaleAcceptCtrl', ['$scope', '$filter', 'PurcAccept', 'ngTableParams', 'toaster', 'BaseService', 'Symbol', function($scope, $filter, PurcAccept, ngTableParams, toaster, BaseService, Symbol){
 		$scope.active = 'all';
-		$scope.agreedText = '全部';
-		$scope.dateZoneText = '一个月内';
-		$scope.condition = {dateZone: 1};
-		$scope.currency = Symbol.currency;//将币别转化为对应的符号
-		$scope.changeAgreed = function(agreed) {
-			$scope.condition.agreed = agreed;
-			$scope.agreedText = typeof agreed == 'undefined' ? '全部' : (agreed == 1 ? '已同意' : '不同意');
-			$scope.condition.$agreedOpen = false;
-		};
-		$scope.changeDateZone = function(zone) {
-			$scope.condition.dateZone = zone;
-			$scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == 1 ? '一个月内' : '半年内');
-			$scope.condition.$dateZoneOpen = false;
-		};
+		$scope.dateZoneText = '不限';
+  		$scope.deliveryZoneText = '不限';
+  		$scope.condition = {dateZone: -1, deliveryZone: -1};
+  		$scope.changeDateZone = function(zone) {
+  			$scope.condition.dateZone = zone;
+  			$scope.dateZoneText = typeof zone == 'undefined' ? '半年前' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '半年内'));
+  			$scope.condition.$dateZoneOpen = false;
+  			getDateCondition(zone, $scope.condition);
+  			$scope.tableParams.reload();
+  		};
+  		$scope.changeDeliveryZone = function(zone) {
+  			$scope.condition.deliveryZoneText = zone;
+  			$scope.deliveryZoneText = typeof zone == 'undefined' ? '不限' : (zone == -1 ? '不限' : (zone == 1 ? '一个月内' : '两个月内'));
+  			$scope.condition.$delievryZoneOpen = false;
+  			getDelveryCondition(zone, $scope.condition);
+  			$scope.tableParams.reload();
+  		};
+  		
 		$scope.setActive = function(state) {
 			if($scope.active != state) {
 				$scope.active = state;
@@ -3955,13 +3959,18 @@ app.controller('SaleSendCtrl', ['$scope', '$filter', 'SaleSend', 'ngTableParams'
 			getData : function($defer, params) {
 				$scope.loading = true;
 				var pageParams = params.url();
-				pageParams.keyword = $scope.keyword;
+				pageParams.searchFilter = { // 筛选条件
+  						keyword: $scope.keyword,
+  						fromDate: getDateTime($scope.condition.dateFrom),
+  						endDate: getDateTime($scope.condition.dateTo)
+  				};
 				getService()[getState($scope.active)].call(null, BaseService.parseParams(pageParams), function(page){
 					$scope.loading = false;
 					if(page) {
+						console.log(pageParams.searchFilter);
 						params.total(page.totalElement);
 						$defer.resolve(page.content);
-						$scope.keywordXls = angular.copy($scope.keyword);//保存当前取值的关键词
+						$scope.searchFilterXls = angular.copy(pageParams.searchFilter);//保存当前取值的关键词
 					}
 				}, function(response){
 					$scope.loading = false;
@@ -3976,6 +3985,17 @@ app.controller('SaleSendCtrl', ['$scope', '$filter', 'SaleSend', 'ngTableParams'
 		    item[openParam] = !item[openParam];
 		};
 		
+  		$scope.parseDate = function(dateStr) {
+  			if(dateStr)
+  				return Date.parse(dateStr, 'yyyy-MM-dd');
+  			return new Date();
+  		};
+		// 选择查找日期
+  		$scope.onDateCondition = function(){
+  			$scope.tableParams.page(1);
+  			$scope.tableParams.reload();
+  		};
+		
 		// 搜索框回车
 		$scope.onSearch = function() {
 			$scope.tableParams.page(1);
@@ -5665,7 +5685,6 @@ app.controller('SaleSendCtrl', ['$scope', '$filter', 'SaleSend', 'ngTableParams'
 		$scope.master = [];
 		AccountRole.query({}, function(data){
 			if(user && data) {
-				console.log(user);
 				var rs = [], checked = [];
 				angular.forEach(user.roles, function(r){
 					rs.push(r.id);
@@ -5698,7 +5717,6 @@ app.controller('SaleSendCtrl', ['$scope', '$filter', 'SaleSend', 'ngTableParams'
 		$scope.close = function(save) {
 			if(save) {
 				if(user.userUU) {
-					console.log(user);
 					user.roles = $scope.checked;
 					AccountUser.update({}, user, function(){
 						toaster.pop('success', '提示', '保存成功');

+ 32 - 27
src/main/webapp/resources/tpl/index/sale/accept.html

@@ -123,58 +123,63 @@
 					共 <span ng-bind="tableParams.total()" class="text-num"></span>
 				</div>
 			</div>
-<!-- 			<div class="col-xs-2 toggle">
+			<div class="col-xs-2 toggle">
 				<a ng-click="condition.$open=!condition.$open" class="text-simple">
 					<span ng-bind="condition.$open ? '简化筛选条件' : '更多筛选条件'"></span>
 					<i class="fa fa-fw" ng-class="{'fa-angle-up': condition.$open, 'fa-angle-down': !condition.$open}"></i>
 				</a>
-			</div> -->
+			</div>
 		</div>
 		<div class="more" ng-class="{'open': condition.$open}">
 			<form class="form-inline">
-			  <div class="form-group ">
-			    <label>日期:</label>
-			    <div class="btn-group btn-menu" dropdown is-open="condition.$dateZoneOpen">
-				  <button type="button" dropdown-toggle style="width: 85px;" class="btn btn-default btn-xs dropdown-toggle">
-				    	{{dateZoneText}}<i class="fa fa-fw fa-angle-down icon-right"></i></span>
-				  </button>
-				  <ul class="dropdown-menu">
-					<li><a ng-click="changeDateZone(1)">一个月内</a></li>
-				    <li><a ng-click="changeDateZone(6)">半年内</a></li>
-				    <li><a ng-click="changeDateZone()">半年前</a></li>
-				  </ul>
-				</div>
-			    <div class="form-group input-group input-group-xs input-trigger">
+				<div class="form-group ">
+					<label>单据日期:</label>
+					<div class="btn-group btn-menu" dropdown
+						is-open="condition.$dateZoneOpen">
+						<button type="button" dropdown-toggle style="width: 85px;"
+							class="btn btn-default btn-xs dropdown-toggle">
+							{{dateZoneText}}<i class="fa fa-fw fa-angle-down icon-right"></i></span>
+						</button>
+						<ul class="dropdown-menu">
+							<li><a ng-click="changeDateZone(-1)">不限</a></li>
+							<li><a ng-click="changeDateZone(1)">一个月内</a></li>
+							<li><a ng-click="changeDateZone(6)">半年内</a></li>
+							<li><a ng-click="changeDateZone()">半年前</a></li>
+						</ul>
+					</div>
+					<div class="input-group input-group-xs input-trigger">
 						<input type="text" ng-model="condition.dateFrom"
-							class="form-control" placeholder="从"
+							class="form-control" placeholder="点击选择起始日期" readonly="readonly"
 							datepicker-popup="yyyy-MM-dd" is-open="condition.$fromOpened"
-							ng-required="true"
-							current-text="今天" clear-text="清除" close-text="关闭"
+							ng-required="true" max-date="condition.dateTo" current-text="今天"
+							clear-text="清除" close-text="关闭"
 							datepicker-options="{formatDayTitle: 'yyyy年M月', formatMonth: 'M月', showWeeks: false}"
-							ng-focus="openDatePicker($event, condition, '$fromOpened')">
-						<span class="input-group-btn">
+							ng-click="openDatePicker($event, condition, '$fromOpened')"
+							ng-change="onDateCondition()"> <span
+							class="input-group-btn">
 							<button type="button" class="btn btn-default"
 								ng-click="openDatePicker($event, condition, '$fromOpened')">
 								<i class="fa fa-calendar"></i>
 							</button>
 						</span>
 					</div>
-					<div class="form-group input-group input-group-xs input-trigger">
+					<div class="input-group input-group-xs input-trigger">
 						<input type="text" ng-model="condition.dateTo"
-							class="form-control" placeholder=""
+							class="form-control" placeholder="点击选择截止日期" readonly="readonly"
 							datepicker-popup="yyyy-MM-dd" is-open="condition.$toOpened"
-							ng-required="true"
+							ng-required="true" min-date="condition.dateFrom"
 							current-text="今天" clear-text="清除" close-text="关闭"
 							datepicker-options="{formatDayTitle: 'yyyy年M月', formatMonth: 'M月', showWeeks: false}"
-							ng-focus="openDatePicker($event, condition, '$toOpened')">
-						<span class="input-group-btn">
+							ng-focus="openDatePicker($event, condition, '$toOpened')"
+							ng-change="onDateCondition()"> <span
+							class="input-group-btn">
 							<button type="button" class="btn btn-default"
 								ng-click="openDatePicker($event, condition, '$toOpened')">
 								<i class="fa fa-calendar"></i>
 							</button>
 						</span>
 					</div>
-			  </div>
+				</div>
 			</form>
 		</div>
 	</div>
@@ -200,7 +205,7 @@
 				</div> <!-- 分页 -->
 			</td>
 			<td class="text-center">
-				<a href="sale/accept/xls?keyword={{keywordXls}}" target="_self" class="text-simple" title="导出Excel表格"><i class="fa fa-file-excel-o fa-fw"></i>导出</a>
+				<a href="sale/accept/xls?searchFilter={{searchFilterXls}}" target="_self" class="text-simple" title="导出Excel表格"><i class="fa fa-file-excel-o fa-fw"></i>导出</a>
 			</td>
 		</tr>
 		<tr class="sep-row">