Browse Source

一键开启/关闭 接口等待同步修改。

dongbw 8 years ago
parent
commit
6331de65ea

+ 28 - 5
src/main/java/com/uas/ps/product/controller/ProductController.java

@@ -11,7 +11,12 @@ import com.uas.ps.product.service.ProductService;
 import com.uas.ps.product.sync.WaitSyncHelper;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.ui.ModelMap;
-import org.springframework.web.bind.annotation.*;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.RestController;
 
 import java.io.UnsupportedEncodingException;
 import java.net.URLDecoder;
@@ -34,6 +39,17 @@ public class ProductController {
     @Autowired
     private WaitSyncHelper waitSyncHelper;
 
+    /**
+     * 一键开启/关闭 对应的物料采购属性
+     */
+    private static final String PRODUCT_PURCHASE_STATUS = "purc";
+
+    /**
+     * 一键开启/关闭 对应的物料销售属性
+     */
+    private static final String PRODUCT_SALE_STATUS = "sale";
+
+
 //    @Autowired
 //    private UserDao userDao;
 
@@ -322,10 +338,17 @@ public class ProductController {
     public void switchProductByEnUU(@RequestParam("enUU") Long enUU,
                               @RequestParam("switchType") String switchType,
                               @RequestParam("switchStatus") Short switchStatus) {
-        Integer size = productService.getCountByEnUU(enUU);
-        waitSyncHelper.preWait("B2B", size);
-        productService.switchProductByEnuuAndTypeAndStatus(enUU, switchType, switchStatus);
-        waitSyncHelper.waitResponse();
+        Integer size = 0;
+        if (switchType.equals(PRODUCT_PURCHASE_STATUS)) {
+            size = productService.getCountByEnUUAndNotIsPurchase(enUU, switchStatus);
+        } else if (switchType.equals(PRODUCT_SALE_STATUS)){
+            size = productService.getCountByEnUUAndNotIsSale(enUU, switchStatus);
+        }
+        if (size > 0) {
+            waitSyncHelper.preWait("B2B", size);
+            productService.switchProductByEnuuAndTypeAndStatus(enUU, switchType, switchStatus);
+            waitSyncHelper.waitResponse();
+        }
     }
 
     /**

+ 20 - 2
src/main/java/com/uas/ps/product/repository/ProductDao.java

@@ -98,7 +98,7 @@ public interface ProductDao extends JpaSpecificationExecutor<Product>, JpaReposi
      */
     @Transactional
     @Modifying
-    @Query("update Product p set p.isSale = :switchStatus where p.enUU = :enUU and p.isSale <> :switchStatus")
+    @Query("update Product p set p.isSale = :switchStatus where p.enUU = :enUU and (p.isSale <> :switchStatus or p.isSale is null)")
     void updateSaleStatusByEnUU(@Param("enUU") Long enUU, @Param("switchStatus") Short switchStatus);
 
     /**
@@ -107,7 +107,7 @@ public interface ProductDao extends JpaSpecificationExecutor<Product>, JpaReposi
      */
     @Transactional
     @Modifying
-    @Query("update Product p set p.isPurchase = :switchStatus where p.enUU = :enUU and p.isPurchase <> :switchStatus")
+    @Query("update Product p set p.isPurchase = :switchStatus where p.enUU = :enUU and (p.isPurchase <> :switchStatus or p.isPurchase is null)")
     void updatePurchaseStatusByEnUU(@Param("enUU") Long enUU, @Param("switchStatus") Short switchStatus);
 
     /**
@@ -136,6 +136,24 @@ public interface ProductDao extends JpaSpecificationExecutor<Product>, JpaReposi
      */
     List<Product> findByEnUU(Long enUU);
 
+    /**
+     * 根据企业UU和销售状态获取企业物料
+     * @param enUU 企业UU
+     * @param switchStatus 销售状态
+     * @return
+     */
+    @Query("select p from Product p where p.enUU = :enUU and (p.isSale <> :switchStatus or p.isSale is null)")
+    List<Product> findByEnUUAndNotIsSale(@Param("enUU") Long enUU, @Param("switchStatus") Short switchStatus);
+
+    /**
+     * 根据企业UU和采购状态获取企业物料
+     * @param enUU 企业UU
+     * @param switchStatus 采购状态
+     * @return
+     */
+    @Query("select p from Product p where p.enUU = :enUU and (p.isPurchase <> :switchStatus or p.isSale is null)")
+    List<Product> findByEnUUAndNotIsPurchase(@Param("enUU") Long enUU, @Param("switchStatus") Short switchStatus);
+
 //    /**
 //     * 通过uu查询非标准器件进行存储
 //     *

+ 16 - 0
src/main/java/com/uas/ps/product/service/ProductService.java

@@ -172,4 +172,20 @@ public interface ProductService {
      * @return 当前企业物料数量
      */
     Integer getCountByEnUU(Long enUU);
+
+    /**
+     * 根据enUU和采购状态获取物料数目
+     * @param enUU 企业UU
+     * @param switchStatus 采购状态
+     * @return
+     */
+    Integer getCountByEnUUAndNotIsPurchase(Long enUU, Short switchStatus);
+
+    /**
+     * 根据enUU和销售状态获取物料数目
+     * @param enUU 企业UU
+     * @param switchStatus 采购状态
+     * @return
+     */
+    Integer getCountByEnUUAndNotIsSale(Long enUU, Short switchStatus);
 }

+ 24 - 0
src/main/java/com/uas/ps/product/service/impl/ProductServiceImpl.java

@@ -230,6 +230,30 @@ public class ProductServiceImpl implements ProductService {
         return productDao.findByEnUU(enUU).size();
     }
 
+    /**
+     * 根据enUU和采购状态获取物料数目
+     *
+     * @param enUU         企业UU
+     * @param switchStatus 采购状态
+     * @return
+     */
+    @Override
+    public Integer getCountByEnUUAndNotIsPurchase(Long enUU, Short switchStatus) {
+        return productDao.findByEnUUAndNotIsPurchase(enUU, switchStatus).size();
+    }
+
+    /**
+     * 根据enUU和销售状态获取物料数目
+     *
+     * @param enUU         企业UU
+     * @param switchStatus 采购状态
+     * @return
+     */
+    @Override
+    public Integer getCountByEnUUAndNotIsSale(Long enUU, Short switchStatus) {
+        return productDao.findByEnUUAndNotIsSale(enUU, switchStatus).size();
+    }
+
     /**
      * 单个物料匹配
      * @param   product