Browse Source

新增功能,平台新增采购订单时带出最近采纳的价格信息

hejq 7 years ago
parent
commit
691d08dc99

+ 12 - 0
src/main/java/com/uas/platform/b2b/controller/SaleInquiryController.java

@@ -888,4 +888,16 @@ public class SaleInquiryController {
         modelMap.putAll(map);
 		return modelMap;
 	}
+
+    /**
+     * 通过物料id查询该条物料最新的采纳价格
+     *
+     * @param prid 物料id
+     * @return
+     */
+	@RequestMapping(value = "/recentPrice/{prId}", method = RequestMethod.GET)
+    @ResponseBody
+    public ModelMap getRecentPrice(@PathVariable("prId") Long prid) {
+        return purchaseInquiryService.getRecentPrice(prid);
+    }
 }

+ 8 - 0
src/main/java/com/uas/platform/b2b/dao/ProductDao.java

@@ -232,4 +232,12 @@ public interface ProductDao extends JpaSpecificationExecutor<Product>, JpaReposi
 	 * @return
 	 */
 	Long countByEnUU(Long enUU);
+
+	/**
+	 * 通过
+	 * @param enUU
+	 * @param cmpCode
+	 * @return
+	 */
+	List<Product> findByEnUUAndCmpCode(Long enUU, String cmpCode);
 }

+ 8 - 0
src/main/java/com/uas/platform/b2b/service/PurchaseInquiryService.java

@@ -304,4 +304,12 @@ public interface PurchaseInquiryService {
     void coverInquiryItemProdToUser(Long enUU) throws Exception;
 
     void saveList(List<PurchaseInquiryItemTemp> purchaseInquiryItemTemps);
+
+	/**
+	 * 根据供应商物料id获取最新采纳的价格信息
+	 *
+	 * @param prid 供应商物料id
+	 * @return
+	 */
+	ModelMap getRecentPrice(Long prid);
 }

+ 34 - 7
src/main/java/com/uas/platform/b2b/service/impl/PurchaseInquiryServiceImpl.java

@@ -1,5 +1,6 @@
 package com.uas.platform.b2b.service.impl;
 
+import com.google.common.collect.Lists;
 import com.uas.message.mail.service.MailService;
 import com.uas.platform.b2b.core.util.*;
 import com.uas.platform.b2b.dao.*;
@@ -18,6 +19,7 @@ import com.uas.platform.b2b.search.SearchService;
 import com.uas.platform.b2b.service.AttachService;
 import com.uas.platform.b2b.service.PurchaseInquiryService;
 import com.uas.platform.b2b.support.MessageConf;
+import com.uas.platform.b2b.support.SPageUtils;
 import com.uas.platform.b2b.support.SystemSession;
 import com.uas.platform.b2b.support.XingePusher;
 import com.uas.platform.b2b.temporary.model.InquiryMessage;
@@ -172,6 +174,37 @@ public class PurchaseInquiryServiceImpl implements PurchaseInquiryService {
 		}
     }
 
+	/**
+	 * 根据供应商物料id获取最新采纳的价格信息
+	 *
+	 * @param prid 供应商物料id
+	 * @return
+	 */
+	@Override
+	public ModelMap getRecentPrice(Long prid) {
+		// 先找到对应的当前企业的物料信息
+		Product originProduct = productDao.findOne(prid);
+		if (null != originProduct && null != originProduct.getCode()) {
+		    Long enUU = SystemSession.getUser().getEnterprise().getUu();
+			List<Product> productList = productDao.findByEnUUAndCode(enUU, originProduct.getCode());
+			if (!CollectionUtils.isEmpty(productList)) {
+                PageInfo pageInfo = new PageInfo(1, 1);
+                pageInfo.filter("inquiry.enUU", enUU);
+                pageInfo.filter("productId", productList.get(0).getId());
+                pageInfo.filter("agreed", Constant.YES);
+                pageInfo.setSort(new org.springframework.data.domain.Sort(org.springframework.data.domain.Sort.Direction.DESC, "id"));
+                SPage<PurchaseInquiryItem> itemSPage = findByPageInfo(pageInfo, null, null);
+                if (!CollectionUtils.isEmpty(itemSPage.getContent())) {
+                    Set<PurchaseInquiryReply> replySet = itemSPage.getContent().get(0).getReplies();
+                    List<PurchaseInquiryReply> replyList = Lists.newArrayList(replySet);
+                    PurchaseInquiryReply reply = replyList.get(0);
+                    return new ModelMap("price", reply.getPrice());
+                }
+            }
+		}
+		return null;
+	}
+
 	/**
 	 * 保存至用户单据表
 	 *
@@ -587,7 +620,6 @@ public class PurchaseInquiryServiceImpl implements PurchaseInquiryService {
     @Override
 	public SPage<PurchaseInquiryItem> findByPageInfo(final PageInfo pageInfo, final String keyword,
 			final SearchFilter filter) {
-		SPage<PurchaseInquiryItem> items = new SPage<PurchaseInquiryItem>();
 		Page<PurchaseInquiryItem> inquiryitems = purchaseInquiryItemDao
 				.findAll(new Specification<PurchaseInquiryItem>() {
 			public Predicate toPredicate(Root<PurchaseInquiryItem> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
@@ -613,12 +645,7 @@ public class PurchaseInquiryServiceImpl implements PurchaseInquiryService {
 				return query.where(pageInfo.getPredicates(root, query, builder)).getRestriction();
 			}
 		}, pageInfo);
-		items.setContent(inquiryitems.getContent());
-		items.setPage(inquiryitems.getNumber());
-		items.setSize(inquiryitems.getSize());
-		items.setTotalElement(inquiryitems.getTotalElements());
-		items.setTotalPage(inquiryitems.getTotalPages());
-		return items;
+		return SPageUtils.covertSPage(inquiryitems);
 	}
 
 	@Override

+ 42 - 27
src/main/webapp/resources/js/index/app.js

@@ -14394,7 +14394,8 @@ define(['toaster', 'charts', 'ngTable', 'common/services', 'common/directives',
     /**
      * 新增采购单
      */
-    app.controller('PurcNewOrderCtrl', ['$scope', '$modal', 'toaster', '$filter', 'addtoCart', '$rootScope', 'VendorInfo', 'ngTableParams', 'BaseService', 'Product', 'newPurcOrder', 'cartOperation', 'ShipAddress', 'Vendor', '$http', '$window', 'token', function ($scope, $modal, toaster, $filter, addtoCart, $rootScope, VendorInfo, ngTableParams, BaseService, Product, newPurcOrder, cartOperation, ShipAddress, Vendor, $http, $window, token) {
+    app.controller('PurcNewOrderCtrl', ['$scope', '$modal', 'toaster', '$filter', 'addtoCart', '$rootScope', 'VendorInfo', 'ngTableParams', 'BaseService', 'Product', 'newPurcOrder', 'cartOperation', 'ShipAddress', 'Vendor', '$http', '$window', 'token', 'recentPrice',
+        function ($scope, $modal, toaster, $filter, addtoCart, $rootScope, VendorInfo, ngTableParams, BaseService, Product, newPurcOrder, cartOperation, ShipAddress, Vendor, $http, $window, token, recentPrice) {
         BaseService.scrollBackToTop();
         // 每次进入时先清除掉rootScope下的venduu
         $rootScope.venduu = null;
@@ -14608,19 +14609,25 @@ define(['toaster', 'charts', 'ngTable', 'common/services', 'common/directives',
 
         // 选择
         $scope.check = function (data) {
-            $scope.order.orderItems.push({
-                code: data.code,
-                title: data.title,
-                spec: data.spec,
-                unit: data.unit,
-                qty: null,
-                price: null,
-                remark: null,
-                delivery: null,
-                prid: data.id,
-                taxrate: $scope.order.rate,
-                prodsource: 'seller'
-            });
+            var price = null;
+            if (data.id) {
+                recentPrice.agreed({prId: data.id}, {}, function(response) {
+                    price = response.price;
+                    $scope.order.orderItems.push({
+                        code: data.code,
+                        title: data.title,
+                        spec: data.spec,
+                        unit: data.unit,
+                        qty: null,
+                        price: price,
+                        remark: null,
+                        delivery: null,
+                        prid: data.id,
+                        taxrate: $scope.order.rate,
+                        prodsource: 'seller',
+                    });
+                });
+            }
         };
 
         // 导入商品信息
@@ -16136,7 +16143,8 @@ define(['toaster', 'charts', 'ngTable', 'common/services', 'common/directives',
     /**
      * 购物车详情
      */
-    app.controller('CartDetailController', ['$scope', 'cartOperation', '$stateParams', 'toaster', '$timeout', 'BaseService', 'ngTableParams', '$filter', 'Product', 'Vendor', 'ShipAddress', '$modal', 'newPurcOrder', 'addtoCart', '$http', 'token', function ($scope, cartOperation, $stateParams, toaster, $timeout, BaseService, ngTableParams, $filter, Product, Vendor, ShipAddress, $modal, newPurcOrder, addtoCart, $http, token) {
+    app.controller('CartDetailController', ['$scope', 'cartOperation', '$stateParams', 'toaster', '$timeout', 'BaseService', 'ngTableParams', '$filter', 'Product', 'Vendor', 'ShipAddress', '$modal', 'newPurcOrder', 'addtoCart', '$http', 'token', 'recentPrice',
+        function ($scope, cartOperation, $stateParams, toaster, $timeout, BaseService, ngTableParams, $filter, Product, Vendor, ShipAddress, $modal, newPurcOrder, addtoCart, $http, token, recentPrice) {
         BaseService.scrollBackToTop();
         $scope.loading = true;
         var loadData = function () {
@@ -16254,18 +16262,25 @@ define(['toaster', 'charts', 'ngTable', 'common/services', 'common/directives',
 
         // 选择
         $scope.check = function (data) {
-            $scope.order.orderItems.push({
-                code: data.code,
-                title: data.title,
-                spec: data.spec,
-                unit: data.unit,
-                qty: null,
-                price: null,
-                remark: null,
-                delivery: null,
-                prid: data.id,
-                rate: $scope.order.rate
-            });
+            var price = null;
+            if (data.id) {
+                recentPrice.agreed({prId: data.id}, {}, function(response) {
+                    price = response.price;
+                    $scope.order.orderItems.push({
+                        code: data.code,
+                        title: data.title,
+                        spec: data.spec,
+                        unit: data.unit,
+                        qty: null,
+                        price: price,
+                        remark: null,
+                        delivery: null,
+                        prid: data.id,
+                        taxrate: $scope.order.rate,
+                        prodsource: 'seller',
+                    });
+                });
+            }
         };
 
         // 导入商品信息

+ 9 - 1
src/main/webapp/resources/js/index/services/Purc.js

@@ -1719,5 +1719,13 @@ define([ 'ngResource'], function() {
                 }
 			}
 		});
-	}]);
+	}]).factory('recentPrice', ['$resource', function($resource) {
+        return $resource('sale/inquiry', {}, {
+            // 获取最新的已采纳的价信息
+            agreed: {
+                url: 'sale/inquiry/recentPrice/:prId',
+                method: 'GET'
+            }
+        });
+    }]);
 });